[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/store/RFC.md fully. Find ONE featur... #99
2 changed files with 34 additions and 3 deletions
14
workspace.go
14
workspace.go
|
|
@ -194,14 +194,21 @@ func discoverOrphanWorkspaces(stateDirectory string, backingStore *Store) []*Wor
|
|||
return orphanWorkspaces
|
||||
}
|
||||
|
||||
func normaliseWorkspaceStateDirectory(stateDirectory string) string {
|
||||
for stateDirectory != "" && core.HasSuffix(stateDirectory, "/") {
|
||||
stateDirectory = core.TrimSuffix(stateDirectory, "/")
|
||||
}
|
||||
return stateDirectory
|
||||
}
|
||||
|
||||
func workspaceNameFromPath(stateDirectory, databasePath string) string {
|
||||
relativePath := core.TrimPrefix(databasePath, joinPath(stateDirectory, ""))
|
||||
return core.TrimSuffix(relativePath, ".duckdb")
|
||||
}
|
||||
|
||||
// RecoverOrphans(".core/state") returns orphaned workspaces such as
|
||||
// RecoverOrphans(".core/state/") returns orphaned workspaces such as
|
||||
// `scroll-session.duckdb` so callers can inspect Aggregate() and then Discard().
|
||||
// Usage example: `orphans := storeInstance.RecoverOrphans(".core/state")`
|
||||
// Usage example: `orphans := storeInstance.RecoverOrphans(".core/state/")`
|
||||
func (storeInstance *Store) RecoverOrphans(stateDirectory string) []*Workspace {
|
||||
if storeInstance == nil {
|
||||
return nil
|
||||
|
|
@ -210,8 +217,9 @@ func (storeInstance *Store) RecoverOrphans(stateDirectory string) []*Workspace {
|
|||
if stateDirectory == "" {
|
||||
stateDirectory = defaultWorkspaceStateDirectory
|
||||
}
|
||||
stateDirectory = normaliseWorkspaceStateDirectory(stateDirectory)
|
||||
|
||||
if stateDirectory == defaultWorkspaceStateDirectory {
|
||||
if stateDirectory == normaliseWorkspaceStateDirectory(defaultWorkspaceStateDirectory) {
|
||||
storeInstance.orphanWorkspacesLock.Lock()
|
||||
cachedWorkspaces := storeInstance.orphanWorkspaces
|
||||
storeInstance.orphanWorkspaces = nil
|
||||
|
|
|
|||
|
|
@ -273,6 +273,29 @@ func TestWorkspace_New_Good_CachesOrphansDuringConstruction(t *testing.T) {
|
|||
orphans[0].Discard()
|
||||
}
|
||||
|
||||
func TestWorkspace_RecoverOrphans_Good_TrailingSlashUsesCache(t *testing.T) {
|
||||
stateDirectory := useWorkspaceStateDirectory(t)
|
||||
requireCoreOK(t, testFilesystem().EnsureDir(stateDirectory))
|
||||
|
||||
orphanDatabasePath := workspaceFilePath(stateDirectory, "orphan-session")
|
||||
orphanDatabase, err := openWorkspaceDatabase(orphanDatabasePath)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, orphanDatabase.Close())
|
||||
assert.True(t, testFilesystem().Exists(orphanDatabasePath))
|
||||
|
||||
storeInstance, err := New(":memory:")
|
||||
require.NoError(t, err)
|
||||
defer storeInstance.Close()
|
||||
|
||||
requireCoreOK(t, testFilesystem().DeleteAll(stateDirectory))
|
||||
assert.False(t, testFilesystem().Exists(orphanDatabasePath))
|
||||
|
||||
orphans := storeInstance.RecoverOrphans(stateDirectory + "/")
|
||||
require.Len(t, orphans, 1)
|
||||
assert.Equal(t, "orphan-session", orphans[0].Name())
|
||||
orphans[0].Discard()
|
||||
}
|
||||
|
||||
func TestWorkspace_Close_Good_PreservesOrphansForRecovery(t *testing.T) {
|
||||
stateDirectory := useWorkspaceStateDirectory(t)
|
||||
requireCoreOK(t, testFilesystem().EnsureDir(stateDirectory))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue