Define canonical session workspace paths

This commit is contained in:
2026-11-29 23:59:15 +00:00
parent 816453b444
commit f923d75562
11 changed files with 110 additions and 64 deletions

View File

@@ -76,12 +76,10 @@ func (s *LocalStore) ensureLayout(paths SessionPaths) (SessionPaths, error) {
paths.AudioDir,
paths.TranscriptsDir,
paths.TranscriptsRawDir,
paths.TranscriptsTrimmedDir,
paths.ArtifactsDir,
paths.ReportsDir,
paths.ConfigDir,
paths.LogsDir,
paths.CurrentDir,
paths.RunsDir,
paths.PreviousDir,
paths.PreviousArtifactsDir,

View File

@@ -23,12 +23,10 @@ func TestEnsureLayoutCreatesExpectedDirectories(t *testing.T) {
checkDirExists(t, paths.AudioDir)
checkDirExists(t, paths.TranscriptsDir)
checkDirExists(t, paths.TranscriptsRawDir)
checkDirExists(t, paths.TranscriptsTrimmedDir)
checkDirExists(t, paths.ArtifactsDir)
checkDirExists(t, paths.ReportsDir)
checkDirExists(t, paths.ConfigDir)
checkDirExists(t, paths.LogsDir)
checkDirExists(t, paths.CurrentDir)
checkDirExists(t, paths.RunsDir)
checkDirExists(t, paths.PreviousDir)
checkDirExists(t, paths.PreviousArtifactsDir)

View File

@@ -14,28 +14,27 @@ const sha256HexLength = 64
// SessionPaths contains canonical local paths for one session work directory.
type SessionPaths struct {
WorkspaceRoot string
CampaignID string
SessionID string
Root string
InputsDir string
AudioDir string
TranscriptsDir string
TranscriptsRawDir string
TranscriptsTrimmedDir string
ArtifactsDir string
ReportsDir string
ConfigDir string
LogsDir string
CurrentDir string
RunsDir string
PreviousDir string
CacheDir string
PreviousManifestPath string
PreviousArtifactsDir string
ManifestPath string
LockPath string
RestoreMarkerPath string
WorkspaceRoot string
CampaignID string
SessionID string
Root string
InputsDir string
AudioDir string
TranscriptsDir string
TranscriptsRawDir string
ArtifactsDir string
ReportsDir string
ConfigDir string
LogsDir string
DebugDir string
ReferencesDir string
RunsDir string
PreviousDir string
PreviousManifestPath string
PreviousArtifactsDir string
ManifestPath string
LockPath string
RestoreMarkerPath string
}
// SessionValidationPolishDir identifies the temporary destination-probe namespace.
@@ -66,7 +65,7 @@ func SessionRunsDirForCampaign(rootDir, campaign, sessionID string) string {
// SessionPreviousDirForCampaign returns the canonical previous-session state directory.
func SessionPreviousDirForCampaign(rootDir, campaign, sessionID string) string {
return filepath.Join(SessionWorkDirForCampaign(rootDir, campaign, sessionID), config.PathPreviousDirSegment)
return filepath.Join(SessionWorkDirForCampaign(rootDir, campaign, sessionID), config.PathInputsDirSegment, config.PathPreviousDirSegment)
}
// SessionPreviousManifestPathForCampaign returns the canonical previous-session manifest cache path.
@@ -101,6 +100,24 @@ func SessionRunStageDirForCampaign(rootDir, campaign, sessionID, runID, stageNam
return filepath.Join(SessionRunRootForCampaign(rootDir, campaign, sessionID, runID), stageName)
}
// SessionRunLogsDir and SessionRunDebugDir locate diagnostics for an attempt.
func SessionRunLogsDir(paths SessionPaths, runID, stageName string) string {
return filepath.Join(paths.RunsDir, runID, stageName, "logs")
}
func SessionRunDebugDir(paths SessionPaths, runID, stageName string) string {
return filepath.Join(paths.RunsDir, runID, stageName, "debug")
}
// SessionLatestLogsPath and SessionLatestDebugPath locate managed navigation views.
func SessionLatestLogsPath(paths SessionPaths, stageName string) string {
return filepath.Join(paths.LogsDir, stageName)
}
func SessionLatestDebugPath(paths SessionPaths, stageName string) string {
return filepath.Join(paths.DebugDir, stageName)
}
// SessionRunExtractDirForCampaign returns the invocation-local extraction directory.
func SessionRunExtractDirForCampaign(rootDir, campaign, sessionID, runID string) string {
return SessionRunStageDirForCampaign(rootDir, campaign, sessionID, runID, "extract")
@@ -124,7 +141,7 @@ func SessionRunNotariusOutputRootForCampaign(rootDir, campaign, sessionID, runID
// SessionNotariusReferenceCacheDir returns the stable cache root for verified
// reference snapshots supplied to Notarius.
func SessionNotariusReferenceCacheDir(paths SessionPaths) string {
return filepath.Join(paths.CacheDir, "notarius", "references")
return paths.ReferencesDir
}
// SessionNotariusReferenceSnapshotPath returns the content-addressed path for
@@ -280,27 +297,26 @@ func buildSessionPaths(workspaceRoot, campaign, sessionID string) SessionPaths {
func buildSessionPathsFromRoot(workspaceRoot, campaign, sessionID, root string) SessionPaths {
return SessionPaths{
WorkspaceRoot: workspaceRoot,
CampaignID: campaign,
SessionID: sessionID,
Root: root,
InputsDir: filepath.Join(root, config.PathInputsDirSegment),
AudioDir: filepath.Join(root, config.PathAudioDirSegment),
TranscriptsDir: filepath.Join(root, config.PathTranscriptsSegment),
TranscriptsRawDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsRaw)),
TranscriptsTrimmedDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsTrimmed)),
ArtifactsDir: filepath.Join(root, config.PathArtifactsDirSegment),
ReportsDir: filepath.Join(root, config.PathReportsDirSegment),
ConfigDir: filepath.Join(root, config.PathConfigDirSegment),
LogsDir: filepath.Join(root, config.PathLogsDirSegment),
CurrentDir: filepath.Join(root, config.PathCurrentDirSegment),
RunsDir: filepath.Join(root, config.PathRunsDirSegment),
PreviousDir: filepath.Join(root, config.PathPreviousDirSegment),
CacheDir: filepath.Join(root, config.PathCacheDirSegment),
PreviousManifestPath: filepath.Join(root, config.PathPreviousDirSegment, config.PathManifestFile),
PreviousArtifactsDir: filepath.Join(root, config.PathPreviousDirSegment, config.PathArtifactsDirSegment),
ManifestPath: filepath.Join(root, config.PathManifestFile),
LockPath: filepath.Join(root, config.PathLockFile),
RestoreMarkerPath: filepath.Join(root, ".restore-incomplete.json"),
WorkspaceRoot: workspaceRoot,
CampaignID: campaign,
SessionID: sessionID,
Root: root,
InputsDir: filepath.Join(root, config.PathInputsDirSegment),
AudioDir: filepath.Join(root, config.PathAudioDirSegment),
TranscriptsDir: filepath.Join(root, config.PathTranscriptsSegment),
TranscriptsRawDir: filepath.Join(root, filepath.FromSlash(config.PathTranscriptsRaw)),
ArtifactsDir: filepath.Join(root, config.PathArtifactsDirSegment),
ReportsDir: filepath.Join(root, config.PathReportsDirSegment),
ConfigDir: filepath.Join(root, config.PathConfigDirSegment),
LogsDir: filepath.Join(root, config.PathLogsDirSegment),
DebugDir: filepath.Join(root, "debug"),
ReferencesDir: filepath.Join(root, config.PathInputsDirSegment, "references"),
RunsDir: filepath.Join(root, config.PathRunsDirSegment),
PreviousDir: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment),
PreviousManifestPath: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment, config.PathManifestFile),
PreviousArtifactsDir: filepath.Join(root, config.PathInputsDirSegment, config.PathPreviousDirSegment, config.PathArtifactsDirSegment),
ManifestPath: filepath.Join(root, config.PathManifestFile),
LockPath: filepath.Join(root, config.PathLockFile),
RestoreMarkerPath: filepath.Join(root, ".restore-incomplete.json"),
}
}

View File

@@ -1,11 +1,40 @@
package artifacts
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestCanonicalSessionLayout(t *testing.T) {
root := t.TempDir()
store := NewLocalStore(root)
paths, err := store.EnsureLayoutFor("campaign", "session")
if err != nil {
t.Fatal(err)
}
for name, got := range map[string]string{
"inputs": paths.InputsDir, "audio": paths.AudioDir, "transcripts": paths.TranscriptsDir,
"transcripts/raw": paths.TranscriptsRawDir, "artifacts": paths.ArtifactsDir,
"inputs/previous": paths.PreviousDir, "inputs/references": paths.ReferencesDir,
"logs": paths.LogsDir, "debug": paths.DebugDir, "runs": paths.RunsDir,
"logs/polish": SessionLatestLogsPath(paths, "polish"),
"debug/polish": SessionLatestDebugPath(paths, "polish"),
"runs/run/polish/logs": SessionRunLogsDir(paths, "run", "polish"),
"runs/run/polish/debug": SessionRunDebugDir(paths, "run", "polish"),
} {
if want := filepath.Join(paths.Root, filepath.FromSlash(name)); got != want {
t.Errorf("%s = %q, want %q", name, got, want)
}
}
for _, name := range []string{"transcripts/trimmed", "current", "runs/run", "logs/polish", "debug/polish"} {
if _, err := os.Lstat(filepath.Join(paths.Root, filepath.FromSlash(name))); !os.IsNotExist(err) {
t.Errorf("%s exists or inaccessible: %v", name, err)
}
}
}
func TestSessionWorkDirForCampaign(t *testing.T) {
root := "/tmp/workspace"
got := SessionWorkDirForCampaign(root, "forsaken", "2026-04-19")
@@ -74,7 +103,7 @@ func TestSessionNotariusReferenceSnapshotPath(t *testing.T) {
if err != nil {
t.Fatalf("SessionNotariusReferenceSnapshotPath() error = %v", err)
}
wantRoot := filepath.Join(paths.Root, "cache", "notarius", "references")
wantRoot := filepath.Join(paths.Root, "inputs", "references")
if root := SessionNotariusReferenceCacheDir(paths); root != wantRoot {
t.Fatalf("SessionNotariusReferenceCacheDir() = %q, want %q", root, wantRoot)
}
@@ -107,25 +136,25 @@ func TestSessionNotariusReferenceSnapshotPathRejectsUnsafeIdentity(t *testing.T)
func TestSessionPreviousPathsForCampaign(t *testing.T) {
root := "/tmp/workspace"
previousDir := SessionPreviousDirForCampaign(root, "forsaken", "2026-04-19")
wantPreviousDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous")
wantPreviousDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous")
if previousDir != wantPreviousDir {
t.Fatalf("SessionPreviousDirForCampaign() = %q, want %q", previousDir, wantPreviousDir)
}
manifestPath := SessionPreviousManifestPathForCampaign(root, "forsaken", "2026-04-19")
wantManifestPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "manifest.json")
wantManifestPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "manifest.json")
if manifestPath != wantManifestPath {
t.Fatalf("SessionPreviousManifestPathForCampaign() = %q, want %q", manifestPath, wantManifestPath)
}
artifactsDir := SessionPreviousArtifactsDirForCampaign(root, "forsaken", "2026-04-19")
wantArtifactsDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "artifacts")
wantArtifactsDir := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "artifacts")
if artifactsDir != wantArtifactsDir {
t.Fatalf("SessionPreviousArtifactsDirForCampaign() = %q, want %q", artifactsDir, wantArtifactsDir)
}
artifactPath := mustSessionPreviousArtifactPathForCampaign(t, root, "forsaken", "2026-04-19", "session_recap.md")
wantArtifactPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "previous", "artifacts", "session_recap.md")
wantArtifactPath := filepath.Join(root, "work", "forsaken", "2026-04-19", "inputs", "previous", "artifacts", "session_recap.md")
if artifactPath != wantArtifactPath {
t.Fatalf("mustSessionPreviousArtifactPathForCampaign(t, ) = %q, want %q", artifactPath, wantArtifactPath)
}

View File

@@ -67,15 +67,12 @@ const (
PathAudioDirSegment = "audio"
PathTranscriptsSegment = "transcripts"
PathTranscriptsRaw = "transcripts/raw"
PathTranscriptsTrimmed = "transcripts/trimmed"
PathArtifactsDirSegment = "artifacts"
PathReportsDirSegment = "reports"
PathConfigDirSegment = "config"
PathLogsDirSegment = "logs"
PathCurrentDirSegment = "current"
PathRunsDirSegment = "runs"
PathPreviousDirSegment = "previous"
PathCacheDirSegment = "cache"
PathManifestFile = "manifest.json"
PathLockFile = ".lock"
PathTranscriptBase = artifactmodel.TranscriptPathBase

View File

@@ -147,7 +147,7 @@ func absoluteExtractSnapshotPaths(paths artifacts.SessionPaths) (artifacts.Sessi
if err != nil {
return paths, fmt.Errorf("resolve snapshot session root: %w", err)
}
paths.CacheDir, err = filepath.Abs(paths.CacheDir)
paths.ReferencesDir, err = filepath.Abs(paths.ReferencesDir)
if err != nil {
return paths, fmt.Errorf("resolve snapshot cache root: %w", err)
}

View File

@@ -103,7 +103,8 @@ func runLocalPathForCanonical(layout runStageLayout, sessionPaths artifacts.Sess
if err != nil {
return "", fmt.Errorf("derive session-relative path for %q: %w", cleanCanonical, err)
}
if rel == config.PathPreviousDirSegment || strings.HasPrefix(rel, config.PathPreviousDirSegment+"/") {
previous := config.PathInputsDirSegment + "/" + config.PathPreviousDirSegment
if rel == previous || strings.HasPrefix(rel, previous+"/") {
return cleanCanonical, nil
}
localPath, err := pathsafe.JoinSlashRelativeUnderRoot(layout.OutputsDir, rel)

View File

@@ -45,7 +45,7 @@ func TestRunLocalPathForCanonicalKeepsPreviousStateSessionDurable(t *testing.T)
t.Fatalf("mkdir outputs dir: %v", err)
}
canonical := filepath.Join(sessionRoot, "previous", "artifacts", "session_recap.md")
canonical := filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md")
got, err := runLocalPathForCanonical(layout, artifacts.SessionPaths{Root: sessionRoot}, canonical)
if err != nil {
t.Fatalf("runLocalPathForCanonical() error = %v", err)