Add host activity and DB browser, and keep dialogs, drag-drop, and idle maintenance responsive.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 02:03:52 +02:00
parent b72c375e87
commit b33a78dbbe
45 changed files with 3254 additions and 171 deletions

View File

@@ -0,0 +1,51 @@
using Explorer.Application;
using Explorer.Storage.Sqlite;
using Microsoft.Extensions.Logging.Abstractions;
namespace Explorer.Storage.Tests;
public class SqliteDatabaseSessionTests
{
[Fact]
public async Task Can_browse_and_edit_a_standalone_database()
{
var dir = Path.Combine(Path.GetTempPath(), "ew-sql", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "sample.db");
var indexPath = Path.Combine(dir, "index.db");
await using var writer = new SqliteIndexStore(indexPath, NullLogger<SqliteIndexStore>.Instance);
await writer.OpenAsync();
await writer.CloseAsync();
await using var session = new SqliteDatabaseSession(indexPath);
await session.OpenAsync(path, preferWrite: true);
Assert.True(session.CanWrite);
await session.ExecuteAsync("CREATE TABLE notes (id INTEGER PRIMARY KEY, body TEXT);");
await session.InsertRowAsync("notes", new Dictionary<string, object?> { ["body"] = "hello" });
var page = await session.ReadTableAsync("notes", 0, 50);
Assert.Contains("body", page.Columns);
Assert.Single(page.Rows);
var rowId = Convert.ToInt64(page.Rows[0][0]);
await session.UpdateCellAsync("notes", rowId, "body", "world");
var query = await session.ExecuteAsync("SELECT body FROM notes");
Assert.Equal("world", query.Rows[0][0]?.ToString());
await session.DeleteRowAsync("notes", rowId);
Assert.Equal(0, (await session.ReadTableAsync("notes", 0, 10)).TotalRows);
}
[Fact]
public async Task Index_opens_read_only_while_writer_holds_lock()
{
var dir = Path.Combine(Path.GetTempPath(), "ew-sql", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "index.db");
await using var writer = new SqliteIndexStore(path, NullLogger<SqliteIndexStore>.Instance);
await writer.OpenAsync();
await using var session = new SqliteDatabaseSession(path);
await session.OpenAsync(path, preferWrite: true);
Assert.False(session.CanWrite);
Assert.Contains("Read-only", session.ModeLabel, StringComparison.OrdinalIgnoreCase);
var tables = await session.ListTablesAsync();
Assert.Contains("sources", tables);
}
}