Reject unsupported session state before execution and restore

This commit is contained in:
2026-11-29 23:57:16 +00:00
parent 8bc3ae56cb
commit 816453b444
16 changed files with 172 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
package app
import (
"bytes"
"context"
"encoding/json"
"errors"
@@ -887,6 +888,43 @@ func TestExecuteStagesFailureUpdatesManifest(t *testing.T) {
}
}
func TestExecuteStagesRejectsUnsupportedSessionWithoutMutation(t *testing.T) {
for _, marker := range []string{"narratio.session-manifest.v1", "", "narratio.session-manifest.v99"} {
t.Run(marker, func(t *testing.T) {
cfg := testConfig(t)
path := manifestPathFor(cfg)
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
t.Fatal(err)
}
data := []byte(fmt.Sprintf(`{"schema_version":%q,"session_id":"%s","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:00:00Z","stages":{}}`, marker, cfg.Session.SessionID))
if marker == "" {
data = bytes.Replace(data, []byte(`"schema_version":"",`), nil, 1)
}
if err := os.WriteFile(path, data, 0o644); err != nil {
t.Fatal(err)
}
_, err := executeStages(context.Background(), cfg, []stage.Stage{BuildFullPlan()[0]}, RunOptions{Force: true})
if err == nil {
t.Fatal("expected unsupported state error")
}
after, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(after, data) {
t.Fatal("manifest changed")
}
entries, err := os.ReadDir(filepath.Dir(path))
if err != nil {
t.Fatal(err)
}
if len(entries) != 1 || entries[0].Name() != "manifest.json" {
t.Fatalf("session files changed: %v", entries)
}
})
}
}
func TestExecuteStagesLoadsExistingManifest(t *testing.T) {
cfg := testConfig(t)
manifestPath := manifestPathFor(cfg)