fix(workspace): close partial workspaces without filesystem
Some checks are pending
Security Scan / security (push) Waiting to run
Test / test (push) Waiting to run

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 19:02:35 +00:00
parent 7ad4dab749
commit 529333c033
2 changed files with 26 additions and 2 deletions

View file

@ -419,7 +419,7 @@ func (workspace *Workspace) closeAndCleanup(removeFiles bool) error {
if workspace == nil {
return nil
}
if workspace.sqliteDatabase == nil || workspace.filesystem == nil {
if workspace.sqliteDatabase == nil {
return nil
}
@ -435,7 +435,7 @@ func (workspace *Workspace) closeAndCleanup(removeFiles bool) error {
return core.E("store.Workspace.closeAndCleanup", "close workspace database", err)
}
}
if !removeFiles {
if !removeFiles || workspace.filesystem == nil {
return nil
}
for _, path := range []string{workspace.databasePath, workspace.databasePath + "-wal", workspace.databasePath + "-shm"} {

View file

@ -226,6 +226,30 @@ func TestWorkspace_Close_Good_PreservesFileForRecovery(t *testing.T) {
assert.False(t, testFilesystem().Exists(workspace.databasePath))
}
func TestWorkspace_Close_Good_ClosesDatabaseWithoutFilesystem(t *testing.T) {
databasePath := testPath(t, "workspace-no-filesystem.duckdb")
sqliteDatabase, err := openWorkspaceDatabase(databasePath)
require.NoError(t, err)
workspace := &Workspace{
name: "partial-workspace",
sqliteDatabase: sqliteDatabase,
databasePath: databasePath,
}
require.NoError(t, workspace.Close())
_, execErr := sqliteDatabase.Exec("SELECT 1")
require.Error(t, execErr)
assert.Contains(t, execErr.Error(), "closed")
assert.True(t, testFilesystem().Exists(databasePath))
requireCoreOK(t, testFilesystem().Delete(databasePath))
_ = testFilesystem().Delete(databasePath + "-wal")
_ = testFilesystem().Delete(databasePath + "-shm")
}
func TestWorkspace_RecoverOrphans_Good(t *testing.T) {
stateDirectory := useWorkspaceStateDirectory(t)