Verify prerequisite history in restore and preflight

This commit is contained in:
2026-12-02 14:34:00 +00:00
parent 76f99184ac
commit 663e02e21e
5 changed files with 142 additions and 19 deletions

View File

@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"io"
"maps"
"os"
"path/filepath"
"strings"
@@ -348,6 +349,9 @@ func TestExecuteRestoreDryRunReportsPreviousCacheWithoutWriting(t *testing.T) {
cfg, _, _, _ := seedRestoreCommittedState(t, fake, pipelinePath, campaignPath, sessionPath)
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)
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())
}
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) {
t.Fatalf("previous artifact should not be written during dry-run; stat err=%v", err)
}
@@ -741,13 +761,26 @@ scriptorium:
binary: scriptorium
artifacts:
session_recap:
enabled: true
enabled: false
prompt_id: dnd.session_recap
output_path: artifacts/session_recap.md
inputs:
previous_recap:
source: narratio.previous_session.artifact.session_recap
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, `
previous_session_id: 2026-04-26
@@ -812,3 +845,27 @@ func fakeDownloadCount(fake *storage.FakeBackend, key string) int {
}
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")
}