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

@@ -153,7 +153,7 @@ func TestAnalyzeStageRequiresCurrentPerArtifactAuthority(t *testing.T) {
now := time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC)
store := &LocalStore{}
aggregateOnly := `{
"schema_version": "narratio.session-manifest.v1",
"schema_version": "narratio.session-manifest.v2",
"session_id": "session",
"created_at": "2026-05-03T10:00:00Z",
"updated_at": "2026-05-03T10:01:00Z",

View File

@@ -12,7 +12,7 @@ import (
func TestLocalStoreRejectsUnsafeLegacyIdentity(t *testing.T) {
now := time.Now().UTC()
path := filepath.Join(t.TempDir(), "manifest.json")
data := []byte(`{"schema_version":"narratio.session-manifest.v1","session_id":"../escape","campaign":"campaign","created_at":"` + now.Format(time.RFC3339Nano) + `","updated_at":"` + now.Format(time.RFC3339Nano) + `","stages":{}}`)
data := []byte(`{"schema_version":"narratio.session-manifest.v2","session_id":"../escape","campaign":"campaign","created_at":"` + now.Format(time.RFC3339Nano) + `","updated_at":"` + now.Format(time.RFC3339Nano) + `","stages":{}}`)
if err := os.WriteFile(path, data, 0o600); err != nil {
t.Fatalf("WriteFile() error = %v", err)
}

View File

@@ -10,7 +10,7 @@ import (
const (
// SessionManifestSchemaVersion identifies the only supported durable session
// manifest representation.
SessionManifestSchemaVersion = "narratio.session-manifest.v1"
SessionManifestSchemaVersion = "narratio.session-manifest.v2"
)
// ErrorRecord captures structured error metadata at run or stage scope.

View File

@@ -33,7 +33,7 @@ func TestSemanticConfigFingerprintRoundTripsAndRemainsOptional(t *testing.T) {
}
path := filepath.Join(dir, "without-fingerprint.json")
data := `{"schema_version":"narratio.session-manifest.v1","session_id":"session","created_at":"2026-01-01T00:00:00Z","updated_at":"2026-01-01T00:00:00Z","stages":{"prepare":{"name":"prepare","status":"succeeded","created_at":"2026-01-01T00:00:00Z","updated_at":"2026-01-01T00:00:00Z"}}}`
data := `{"schema_version":"narratio.session-manifest.v2","session_id":"session","created_at":"2026-01-01T00:00:00Z","updated_at":"2026-01-01T00:00:00Z","stages":{"prepare":{"name":"prepare","status":"succeeded","created_at":"2026-01-01T00:00:00Z","updated_at":"2026-01-01T00:00:00Z"}}}`
if err := os.WriteFile(path, []byte(data), 0o644); err != nil {
t.Fatal(err)
}

View File

@@ -82,7 +82,7 @@ func TestLocalStoreRejectsUnknownProvenanceFields(t *testing.T) {
{"unknown selection field", `{"selected_overlay":{"name":"testing","source":"explicit","unexpected":true}}`, "unexpected"},
} {
t.Run(tc.name, func(t *testing.T) {
data := `{"schema_version":"narratio.session-manifest.v1","session_id":"2026-05-03","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:00:00Z","effective_config":` + tc.provenance + `,"stages":{}}`
data := `{"schema_version":"narratio.session-manifest.v2","session_id":"2026-05-03","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:00:00Z","effective_config":` + tc.provenance + `,"stages":{}}`
_, err := (&LocalStore{}).LoadReader(context.Background(), strings.NewReader(data))
if err == nil || !strings.Contains(err.Error(), tc.field) {
t.Fatalf("expected rejection identifying %q, got %v", tc.field, err)
@@ -97,7 +97,7 @@ func TestLocalStorePreservesOptionalArtifactMetadata(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "manifest.json")
data := `{
"schema_version": "narratio.session-manifest.v1",
"schema_version": "narratio.session-manifest.v2",
"session_id": "2026-05-03",
"created_at": "2026-05-03T10:00:00Z",
"updated_at": "2026-05-03T10:01:00Z",
@@ -260,7 +260,7 @@ func TestLoadRejectsInvalidManifest(t *testing.T) {
ctx := context.Background()
path := filepath.Join(t.TempDir(), "manifest.json")
if err := os.WriteFile(path, []byte(`{"schema_version":"narratio.session-manifest.v1","updated_at":"2026-05-03T10:00:00Z","stages":{}}`), 0o644); err != nil {
if err := os.WriteFile(path, []byte(`{"schema_version":"narratio.session-manifest.v2","updated_at":"2026-05-03T10:00:00Z","stages":{}}`), 0o644); err != nil {
t.Fatalf("WriteFile() error = %v", err)
}
@@ -275,7 +275,7 @@ func TestLoadRejectsInvalidManifest(t *testing.T) {
func TestLocalStoreRejectsRetiredCleanupFieldAndRoundTripsCanonicalV1(t *testing.T) {
store := &LocalStore{}
canonical := `{"schema_version":"narratio.session-manifest.v1","session_id":"2026-05-03","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:01:00Z","stages":{}}`
canonical := `{"schema_version":"narratio.session-manifest.v2","session_id":"2026-05-03","created_at":"2026-05-03T10:00:00Z","updated_at":"2026-05-03T10:01:00Z","stages":{}}`
loaded, err := store.LoadReader(context.Background(), strings.NewReader(canonical))
if err != nil {

View File

@@ -65,7 +65,7 @@ func TestTranscribeSpeakerStateRoundTripsPopulatedAndVersionedEmptyCollections(t
func TestTranscribeSpeakerStateAllowsLegacyAggregateOnlyManifest(t *testing.T) {
legacy := `{
"schema_version": "narratio.session-manifest.v1",
"schema_version": "narratio.session-manifest.v2",
"session_id": "session",
"created_at": "2026-09-21T12:00:00Z",
"updated_at": "2026-09-21T12:01:00Z",