Verify prerequisite history in restore and preflight
This commit is contained in:
@@ -180,7 +180,7 @@ missing prepared history to bypass the collection/hydration path.
|
|||||||
|
|
||||||
## Stage 4: Verify restore and operator readiness use the same requirements
|
## Stage 4: Verify restore and operator readiness use the same requirements
|
||||||
|
|
||||||
Status: Pending
|
Status: Complete
|
||||||
|
|
||||||
Read `internal/app/restore_plan.go`, `restore_plan_test.go`,
|
Read `internal/app/restore_plan.go`, `restore_plan_test.go`,
|
||||||
`restore_execution_test.go`, `restore_workflow_test.go`,
|
`restore_execution_test.go`, `restore_workflow_test.go`,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -348,6 +349,9 @@ func TestExecuteRestoreDryRunReportsPreviousCacheWithoutWriting(t *testing.T) {
|
|||||||
cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipelinePath, campaignPath, sessionPath)
|
cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipelinePath, campaignPath, sessionPath)
|
||||||
seedRestorePreviousCurrent(t, fake, cfg, "# previous recap\n")
|
seedRestorePreviousCurrent(t, fake, cfg, "# previous recap\n")
|
||||||
|
|
||||||
|
sessionRoot := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
mustWriteTestFile(t, filepath.Join(sessionRoot, "inputs", "existing.txt"), "durable input")
|
||||||
|
before := snapshotSessionTree(t, sessionRoot)
|
||||||
executeRestore := restoreCommandExecutor(fake)
|
executeRestore := restoreCommandExecutor(fake)
|
||||||
|
|
||||||
var stdout bytes.Buffer
|
var stdout bytes.Buffer
|
||||||
@@ -363,7 +367,23 @@ func TestExecuteRestoreDryRunReportsPreviousCacheWithoutWriting(t *testing.T) {
|
|||||||
t.Fatalf("stdout = %q, want dry-run remote-read notice", stdout.String())
|
t.Fatalf("stdout = %q, want dry-run remote-read notice", stdout.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionRoot := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
|
after := snapshotSessionTree(t, sessionRoot)
|
||||||
|
for path, value := range before {
|
||||||
|
if value == "directory" {
|
||||||
|
delete(before, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for path, value := range after {
|
||||||
|
if value == "directory" {
|
||||||
|
delete(after, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !maps.Equal(before, after) {
|
||||||
|
t.Fatalf("dry-run changed durable files: before=%v after=%v", before, after)
|
||||||
|
}
|
||||||
|
if strings.Contains(stdout.String(), "previous/artifacts/unrelated.md") {
|
||||||
|
t.Fatalf("unrelated history included: %s", stdout.String())
|
||||||
|
}
|
||||||
if _, err := os.Stat(filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md")); !os.IsNotExist(err) {
|
if _, err := os.Stat(filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md")); !os.IsNotExist(err) {
|
||||||
t.Fatalf("previous artifact should not be written during dry-run; stat err=%v", err)
|
t.Fatalf("previous artifact should not be written during dry-run; stat err=%v", err)
|
||||||
}
|
}
|
||||||
@@ -741,13 +761,26 @@ scriptorium:
|
|||||||
binary: scriptorium
|
binary: scriptorium
|
||||||
artifacts:
|
artifacts:
|
||||||
session_recap:
|
session_recap:
|
||||||
enabled: true
|
enabled: false
|
||||||
prompt_id: dnd.session_recap
|
prompt_id: dnd.session_recap
|
||||||
output_path: artifacts/session_recap.md
|
output_path: artifacts/session_recap.md
|
||||||
inputs:
|
inputs:
|
||||||
previous_recap:
|
previous_recap:
|
||||||
source: narratio.previous_session.artifact.session_recap
|
source: narratio.previous_session.artifact.session_recap
|
||||||
required: true
|
required: true
|
||||||
|
child:
|
||||||
|
enabled: true
|
||||||
|
prompt_id: dnd.child
|
||||||
|
output_path: artifacts/child.md
|
||||||
|
depends_on: [session_recap]
|
||||||
|
unrelated:
|
||||||
|
enabled: false
|
||||||
|
prompt_id: dnd.other
|
||||||
|
output_path: artifacts/other.md
|
||||||
|
inputs:
|
||||||
|
history:
|
||||||
|
source: narratio.previous_session.artifact.unrelated
|
||||||
|
required: true
|
||||||
`)
|
`)
|
||||||
appendRestoreWorkflowScriptoriumConfig(t, sessionPath, `
|
appendRestoreWorkflowScriptoriumConfig(t, sessionPath, `
|
||||||
previous_session_id: 2026-04-26
|
previous_session_id: 2026-04-26
|
||||||
@@ -812,3 +845,27 @@ func fakeDownloadCount(fake *storage.FakeBackend, key string) int {
|
|||||||
}
|
}
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestExecuteRestoreInstallsOptionalPrerequisiteHistory(t *testing.T) {
|
||||||
|
workspaceRoot := t.TempDir()
|
||||||
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, workspaceRoot)
|
||||||
|
appendRestoreWorkflowPreviousInputConfig(t, pipelinePath, sessionPath)
|
||||||
|
data, err := os.ReadFile(pipelinePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data = bytes.Replace(data, []byte(" required: true\n child:"), []byte(" required: false\n child:"), 1)
|
||||||
|
if err := os.WriteFile(pipelinePath, data, 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
fake := &storage.FakeBackend{}
|
||||||
|
cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipelinePath, campaignPath, sessionPath)
|
||||||
|
seedRestorePreviousCurrent(t, fake, cfg, "optional history\n")
|
||||||
|
var stdout, stderr bytes.Buffer
|
||||||
|
code := restoreCommandExecutor(fake)([]string{"session", "restore", cfg.Session.SessionID, "--config", pipelinePath, "--campaign-file", campaignPath, "--session-file", sessionPath}, &stdout, &stderr)
|
||||||
|
if code != 0 {
|
||||||
|
t.Fatalf("restore exit = %d; stderr = %s", code, stderr.String())
|
||||||
|
}
|
||||||
|
root := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
mustReadEquals(t, filepath.Join(root, "inputs", "previous", "artifacts", "session_recap.md"), "optional history\n")
|
||||||
|
}
|
||||||
|
|||||||
@@ -512,7 +512,7 @@ func configureRestorePlanPreviousRequirement(cfg *config.Config, required bool)
|
|||||||
cfg.Pipeline.Scriptorium = &config.ScriptoriumConfig{
|
cfg.Pipeline.Scriptorium = &config.ScriptoriumConfig{
|
||||||
Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
Artifacts: map[string]config.ScriptoriumArtifactConfig{
|
||||||
"session_recap": {
|
"session_recap": {
|
||||||
Enabled: true,
|
Enabled: false,
|
||||||
PromptID: "dnd.session_recap",
|
PromptID: "dnd.session_recap",
|
||||||
OutputPath: "artifacts/session_recap.md",
|
OutputPath: "artifacts/session_recap.md",
|
||||||
Inputs: map[string]config.ScriptoriumInputConfig{
|
Inputs: map[string]config.ScriptoriumInputConfig{
|
||||||
@@ -522,6 +522,8 @@ func configureRestorePlanPreviousRequirement(cfg *config.Config, required bool)
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"child": {Enabled: true, PromptID: "child", OutputPath: "artifacts/child.md", DependsOn: []string{"session_recap"}},
|
||||||
|
"unrelated": {PromptID: "other", OutputPath: "artifacts/other.md", Inputs: map[string]config.ScriptoriumInputConfig{"history": {Source: "narratio.previous_session.artifact.unrelated", Required: true}}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cfg.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: cfg.Pipeline.Scriptorium.Artifacts}
|
cfg.ArtifactCatalog = &config.ArtifactCatalog{Artifacts: cfg.Pipeline.Scriptorium.Artifacts}
|
||||||
@@ -545,3 +547,20 @@ func restorePlanCurrentState(t *testing.T, cfg *config.Config) *RemoteCurrentSta
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRestorePlanIncludesAvailableOptionalPrerequisiteHistory(t *testing.T) {
|
||||||
|
cfg := restorePlanConfig(t)
|
||||||
|
configureRestorePlanPreviousRequirement(cfg, false)
|
||||||
|
current := restorePlanCurrentState(t, cfg)
|
||||||
|
store := &storage.FakeBackend{}
|
||||||
|
seedCurrentRestoreObject(t, store, current, current.CurrentManifestKey, []byte(`{"session_id":"2026-05-03"}`))
|
||||||
|
seedRestorePreviousCurrent(t, store, cfg, "optional history\n")
|
||||||
|
plan, err := buildRestorePlan(context.Background(), cfg, current, store, RestorePlanOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
want := []string{"inputs/previous/artifacts/session_recap.md", "inputs/previous/manifest.json", "manifest.json"}
|
||||||
|
if got := actionRelPaths(plan.Actions); !slices.Equal(got, want) {
|
||||||
|
t.Fatalf("actions = %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ scriptorium:
|
|||||||
binary: scriptorium
|
binary: scriptorium
|
||||||
artifacts:
|
artifacts:
|
||||||
session_recap:
|
session_recap:
|
||||||
enabled: true
|
enabled: false
|
||||||
prompt_id: dnd.session_recap
|
prompt_id: dnd.session_recap
|
||||||
output_path: artifacts/session_recap.md
|
output_path: artifacts/session_recap.md
|
||||||
inputs:
|
inputs:
|
||||||
@@ -153,6 +153,11 @@ scriptorium:
|
|||||||
previous_recap:
|
previous_recap:
|
||||||
source: narratio.previous_session.artifact.session_recap
|
source: narratio.previous_session.artifact.session_recap
|
||||||
required: true
|
required: true
|
||||||
|
child:
|
||||||
|
enabled: true
|
||||||
|
prompt_id: dnd.child
|
||||||
|
output_path: artifacts/child.md
|
||||||
|
depends_on: [session_recap]
|
||||||
`)
|
`)
|
||||||
appendRestoreWorkflowScriptoriumConfig(t, sessionPath, `
|
appendRestoreWorkflowScriptoriumConfig(t, sessionPath, `
|
||||||
previous_session_id: 2026-04-26
|
previous_session_id: 2026-04-26
|
||||||
@@ -161,7 +166,18 @@ previous_session_id: 2026-04-26
|
|||||||
fakeStore := &storage.FakeBackend{}
|
fakeStore := &storage.FakeBackend{}
|
||||||
cfg, sessionPrefix, manifestKey, runIDKey := seedRestoreCommittedState(t, fakeStore, pipelinePath, campaignPath, sessionPath)
|
cfg, sessionPrefix, manifestKey, runIDKey := seedRestoreCommittedState(t, fakeStore, pipelinePath, campaignPath, sessionPath)
|
||||||
seedRestoreObject(fakeStore, runIDKey, []byte("20260519T010203Z-a1b2c3d4\n"))
|
seedRestoreObject(fakeStore, runIDKey, []byte("20260519T010203Z-a1b2c3d4\n"))
|
||||||
seedRestoreObject(fakeStore, manifestKey, restoreWorkflowManifestJSON(t, cfg.Session.SessionID, cfg.Session.Campaign))
|
sessionRoot := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
var committed manifest.Manifest
|
||||||
|
if err := json.Unmarshal(restoreWorkflowManifestJSON(t, cfg.Session.SessionID, cfg.Session.Campaign), &committed); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
delete(committed.Stages, "analyze")
|
||||||
|
committed.Inputs = append(committed.Inputs, manifest.InputRecord{Kind: "previous_artifact", Source: "narratio.previous_session.artifact.session_recap", Path: "inputs/previous/artifacts/session_recap.md", Checksum: restoreCommitSHA256([]byte("# previous recap\n"))})
|
||||||
|
committedData, err := json.Marshal(&committed)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
seedRestoreObject(fakeStore, manifestKey, committedData)
|
||||||
seedRestoreObject(fakeStore, sessionPrefix+"transcripts/final.trimmed.json", []byte(`{"segments":[]}`+"\n"))
|
seedRestoreObject(fakeStore, sessionPrefix+"transcripts/final.trimmed.json", []byte(`{"segments":[]}`+"\n"))
|
||||||
seedRestorePreviousCurrent(t, fakeStore, cfg, "# previous recap\n")
|
seedRestorePreviousCurrent(t, fakeStore, cfg, "# previous recap\n")
|
||||||
|
|
||||||
@@ -185,17 +201,7 @@ previous_session_id: 2026-04-26
|
|||||||
t.Fatalf("restore stderr = %q, want empty", stderr.String())
|
t.Fatalf("restore stderr = %q, want empty", stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionRoot := artifacts.SessionWorkDirForCampaign(workspaceRoot, cfg.Session.Campaign, cfg.Session.SessionID)
|
|
||||||
mustReadEquals(t, filepath.Join(sessionRoot, "transcripts", "final.trimmed.json"), `{"segments":[]}`+"\n")
|
mustReadEquals(t, filepath.Join(sessionRoot, "transcripts", "final.trimmed.json"), `{"segments":[]}`+"\n")
|
||||||
localManifest, err := (&manifest.LocalStore{}).Load(context.Background(), filepath.Join(sessionRoot, "manifest.json"))
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("load restored manifest: %v", err)
|
|
||||||
}
|
|
||||||
setCurrentBuiltInEvidence(t, localManifest, "trim", artifacts.TranscriptOutputKindFinalTrimmed, artifacts.ArtifactTranscriptFinalTrimmed, filepath.Join(sessionRoot, "transcripts", "final.trimmed.json"))
|
|
||||||
setCurrentPreviousArtifactInput(t, localManifest, filepath.Join(sessionRoot, "inputs", "previous", "artifacts", "session_recap.md"))
|
|
||||||
if err := (&manifest.LocalStore{}).Save(context.Background(), filepath.Join(sessionRoot, "manifest.json"), localManifest); err != nil {
|
|
||||||
t.Fatalf("save manifest evidence: %v", err)
|
|
||||||
}
|
|
||||||
previousManifestBytes, err := os.ReadFile(filepath.Join(sessionRoot, "inputs", "previous", "manifest.json"))
|
previousManifestBytes, err := os.ReadFile(filepath.Join(sessionRoot, "inputs", "previous", "manifest.json"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("read restored previous manifest: %v", err)
|
t.Fatalf("read restored previous manifest: %v", err)
|
||||||
@@ -228,7 +234,7 @@ previous_session_id: 2026-04-26
|
|||||||
"--config", pipelinePath,
|
"--config", pipelinePath,
|
||||||
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
"--campaign-file", campaignPath, "--session-file", sessionPath,
|
||||||
"--force",
|
"--force",
|
||||||
"--artifacts", "session_recap",
|
"--artifacts", "child",
|
||||||
},
|
},
|
||||||
&stdout,
|
&stdout,
|
||||||
&stderr,
|
&stderr,
|
||||||
@@ -243,8 +249,8 @@ previous_session_id: 2026-04-26
|
|||||||
if objectStoreConstructed {
|
if objectStoreConstructed {
|
||||||
t.Fatal("single-stage analysis should not construct object store for previous-session input resolution")
|
t.Fatal("single-stage analysis should not construct object store for previous-session input resolution")
|
||||||
}
|
}
|
||||||
if len(scriptoriumFake.RunRequests) != 1 {
|
if len(scriptoriumFake.RunRequests) != 2 {
|
||||||
t.Fatalf("scriptorium run requests = %d, want 1", len(scriptoriumFake.RunRequests))
|
t.Fatalf("scriptorium run requests = %d, want 2", len(scriptoriumFake.RunRequests))
|
||||||
}
|
}
|
||||||
req := scriptoriumFake.RunRequests[0]
|
req := scriptoriumFake.RunRequests[0]
|
||||||
if got := req.InputPaths["transcript"]; got != filepath.Join(sessionRoot, "transcripts", "final.trimmed.json") {
|
if got := req.InputPaths["transcript"]; got != filepath.Join(sessionRoot, "transcripts", "final.trimmed.json") {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -318,3 +320,42 @@ func TestSessionReadinessChecksS3PreparationEvidence(t *testing.T) {
|
|||||||
t.Fatalf("access failure=%+v error=%v", failed, err)
|
t.Fatalf("access failure=%+v error=%v", failed, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestReadinessHydratesPrerequisiteHistory(t *testing.T) {
|
||||||
|
for _, required := range []bool{true, false} {
|
||||||
|
t.Run(fmt.Sprintf("required=%v", required), func(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
appendRestoreWorkflowPreviousInputConfig(t, pipeline, session)
|
||||||
|
if !required {
|
||||||
|
data, err := os.ReadFile(pipeline)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
data = bytes.Replace(data, []byte(" required: true\n child:"), []byte(" required: false\n child:"), 1)
|
||||||
|
if err := os.WriteFile(pipeline, data, 0600); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
store := &storage.FakeBackend{}
|
||||||
|
seedRestorePreviousCurrent(t, store, cfg, "# previous recap\n")
|
||||||
|
deps := fakeCommandDependencies(store, nil)
|
||||||
|
status, err := inspectSessionState(context.Background(), cfg, true, true, deps)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(status.Previous) != 1 || status.Previous[0].Name != "session_recap" || status.Previous[0].Required != required || status.Previous[0].State != "ready" {
|
||||||
|
t.Fatalf("previous readiness = %#v", status.Previous)
|
||||||
|
}
|
||||||
|
report, err := preflightSelectedSession(context.Background(), readinessInput(pipeline, campaign, session), deps)
|
||||||
|
if err != nil || !report.Ready || report.Preparation.Outcome != "completed" {
|
||||||
|
t.Fatalf("preflight = %+v, error = %v", report, err)
|
||||||
|
}
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
mustReadEquals(t, filepath.Join(paths.PreviousArtifactsDir, "session_recap.md"), "# previous recap\n")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user