|
|
|
|
@@ -2,8 +2,6 @@ package stage
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"crypto/sha256"
|
|
|
|
|
"encoding/hex"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
@@ -22,8 +20,6 @@ import (
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const extractIndexOutputKind = "notarius_index"
|
|
|
|
|
|
|
|
|
|
func TestExtractStageDisabledReturnsExplicitSkip(t *testing.T) {
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
|
name string
|
|
|
|
|
@@ -88,11 +84,11 @@ notarius:
|
|
|
|
|
if req.InputPath != fixture.inputPath {
|
|
|
|
|
t.Fatalf("input path = %q, want manifest path %q", req.InputPath, fixture.inputPath)
|
|
|
|
|
}
|
|
|
|
|
wantReceipt := artifacts.SessionRunNotariusReceiptPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
wantReport := artifacts.SessionRunNotariusReportPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
wantLog := artifacts.SessionRunNotariusLogPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
wantOutputRoot := artifacts.SessionRunNotariusOutputRootForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
if req.ConfigPath != env.Config.Pipeline.Notarius.ConfigPath || req.PipelineID != "dnd-session" ||
|
|
|
|
|
req.OutputRoot != wantOutputRoot || req.ReceiptPath != wantReceipt || req.LogPath != wantLog ||
|
|
|
|
|
req.OutputRoot != wantOutputRoot || req.ReportPath != wantReport || req.LogPath != wantLog ||
|
|
|
|
|
req.WorkingDirectory != env.Config.Pipeline.Notarius.WorkingDirectory || req.Timeout != 45*time.Minute {
|
|
|
|
|
t.Fatalf("request = %#v", req)
|
|
|
|
|
}
|
|
|
|
|
@@ -102,8 +98,8 @@ notarius:
|
|
|
|
|
if len(req.References) != 0 {
|
|
|
|
|
t.Fatalf("references = %#v, want none", req.References)
|
|
|
|
|
}
|
|
|
|
|
if req.Resume || req.ChunkCache != "" {
|
|
|
|
|
t.Fatalf("default cache controls = resume %v, mode %q", req.Resume, req.ChunkCache)
|
|
|
|
|
if req.Cache != nil {
|
|
|
|
|
t.Fatalf("default cache = %v", req.Cache)
|
|
|
|
|
}
|
|
|
|
|
if len(req.Credentials) != 1 || req.Credentials[0].EnvName() != credentialName || !req.Credentials[0].IsResolved() {
|
|
|
|
|
t.Fatal("request did not retain the loaded Notarius credential reference")
|
|
|
|
|
@@ -121,46 +117,31 @@ notarius:
|
|
|
|
|
if strings.Contains(string(metadata), credentialCanary) || strings.Contains(string(metadata), credentialName) {
|
|
|
|
|
t.Fatal("result metadata contains the Notarius credential")
|
|
|
|
|
}
|
|
|
|
|
if len(result.Outputs) != 2 {
|
|
|
|
|
t.Fatalf("outputs = %#v, want lane and index", result.Outputs)
|
|
|
|
|
if len(result.Outputs) != 1 {
|
|
|
|
|
t.Fatalf("outputs = %#v, want one lane", result.Outputs)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageAppliesNotariusCacheControlsAndForcePrecedence(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
configuredResume bool
|
|
|
|
|
configuredMode string
|
|
|
|
|
force bool
|
|
|
|
|
wantResume bool
|
|
|
|
|
wantMode string
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
|
name, configured, want string
|
|
|
|
|
force bool
|
|
|
|
|
}{
|
|
|
|
|
{name: "ordinary defaults"},
|
|
|
|
|
{name: "ordinary configured", configuredResume: true, configuredMode: "bypass", wantResume: true, wantMode: "bypass"},
|
|
|
|
|
{name: "force overrides configured", configuredResume: true, configuredMode: "bypass", force: true, wantMode: "refresh"},
|
|
|
|
|
{name: "force overrides defaults", force: true, wantMode: "refresh"},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
{name: "defaults"}, {name: "configured", configured: "bypass", want: "bypass"},
|
|
|
|
|
{name: "forced", configured: "bypass", want: "refresh", force: true}, {name: "forced default", want: "refresh", force: true},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
configOverlay := "inexpensive"
|
|
|
|
|
env.Config.Pipeline.Notarius.ConfigOverlay = &configOverlay
|
|
|
|
|
env.Config.Pipeline.Notarius.Resume = test.configuredResume
|
|
|
|
|
env.Config.Pipeline.Notarius.ChunkCache = test.configuredMode
|
|
|
|
|
if test.configured != "" {
|
|
|
|
|
env.Config.Pipeline.Notarius.Cache = &test.configured
|
|
|
|
|
}
|
|
|
|
|
env.Force = test.force
|
|
|
|
|
|
|
|
|
|
if _, err := (extractStage{}).Run(context.Background(), env, m); err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if len(fake.Requests) != 1 {
|
|
|
|
|
t.Fatalf("requests = %d, want 1", len(fake.Requests))
|
|
|
|
|
}
|
|
|
|
|
request := fake.Requests[0]
|
|
|
|
|
if request.Resume != test.wantResume || request.ChunkCache != test.wantMode {
|
|
|
|
|
t.Fatalf("cache controls = resume %v, mode %q; want resume %v, mode %q", request.Resume, request.ChunkCache, test.wantResume, test.wantMode)
|
|
|
|
|
}
|
|
|
|
|
if request.ConfigOverlay == nil || *request.ConfigOverlay != configOverlay {
|
|
|
|
|
t.Fatalf("config overlay = %#v, want %q", request.ConfigOverlay, configOverlay)
|
|
|
|
|
got := fake.Requests[0].Cache
|
|
|
|
|
if (got == nil && test.want != "") || (got != nil && *got != test.want) {
|
|
|
|
|
t.Fatalf("cache = %v, want %q", got, test.want)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
@@ -478,7 +459,7 @@ func TestExtractReferenceSnapshotsWithRelativeWorkspace(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// A controlled executable proves the production adapter accepts the paths.
|
|
|
|
|
// It intentionally produces no receipt; receipt validation is covered elsewhere.
|
|
|
|
|
// It intentionally produces no completion report; report validation is covered elsewhere.
|
|
|
|
|
marker := filepath.Join(t.TempDir(), "started")
|
|
|
|
|
binary := filepath.Join(t.TempDir(), "notarius")
|
|
|
|
|
if err := os.WriteFile(binary, []byte("#!/bin/sh\nprintf started > '"+marker+"'\n"), 0o755); err != nil {
|
|
|
|
|
@@ -488,11 +469,11 @@ func TestExtractReferenceSnapshotsWithRelativeWorkspace(t *testing.T) {
|
|
|
|
|
_, err = notarius.NewSubprocessRunner().Run(context.Background(), notarius.RunRequest{
|
|
|
|
|
Binary: binary, PipelineID: "dnd-session", ConfigPath: env.Config.Pipeline.Notarius.ConfigPath,
|
|
|
|
|
InputPath: prepared, OutputRoot: t.TempDir(), WorkingDirectory: env.Config.Pipeline.Workspace.Root,
|
|
|
|
|
Timeout: time.Second * 10, References: first,
|
|
|
|
|
ReceiptPath: filepath.Join(diagnostics, "receipt.json"), LogPath: filepath.Join(diagnostics, "stderr.log"),
|
|
|
|
|
Timeout: time.Second * 10, References: first, DebugDirectory: filepath.Join(diagnostics, "debug"),
|
|
|
|
|
ReportPath: filepath.Join(diagnostics, "report.json"), LogPath: filepath.Join(diagnostics, "stderr.log"),
|
|
|
|
|
})
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("expected missing receipt error")
|
|
|
|
|
t.Fatal("expected missing completion report error")
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(marker); err != nil {
|
|
|
|
|
t.Fatalf("adapter did not launch with the snapshot bindings: %v", err)
|
|
|
|
|
@@ -582,7 +563,7 @@ func assertFileContents(t *testing.T, path, want string) {
|
|
|
|
|
func TestExtractStageRejectsUnavailableReferenceBeforeInvocationOrRunDirectoryCreation(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
env.Config.Pipeline.Notarius.References = map[string]string{
|
|
|
|
|
"spell_catalog": artifactpolicy.SourceInputSpellCatalog,
|
|
|
|
|
"spell_catalog": "narratio.input.spell_catalog",
|
|
|
|
|
}
|
|
|
|
|
runRoot := artifacts.SessionRunRootForCampaign(
|
|
|
|
|
env.Config.Pipeline.Workspace.Root, m.Campaign, m.SessionID, m.RunID,
|
|
|
|
|
@@ -603,158 +584,6 @@ func TestExtractStageRejectsUnavailableReferenceBeforeInvocationOrRunDirectoryCr
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageProducesImmutableManifestReadyOutputs(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
fixture := extractFixtureFromEnv(t, env, m)
|
|
|
|
|
stagingBundle := fake.Result.BundleRoot
|
|
|
|
|
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
durableBundle := artifacts.SessionNotariusBundleDirForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
if result.Metadata["bundle_root"] != durableBundle || result.Metadata["narratio_run_id"] != fixture.runID {
|
|
|
|
|
t.Fatalf("metadata = %#v", result.Metadata)
|
|
|
|
|
}
|
|
|
|
|
if fingerprint, _ := result.Metadata["configuration_fingerprint"].(string); len(fingerprint) != 64 {
|
|
|
|
|
t.Fatalf("configuration fingerprint = %#v", result.Metadata["configuration_fingerprint"])
|
|
|
|
|
}
|
|
|
|
|
if result.Metadata["receipt_path"] != artifacts.SessionRunNotariusReceiptPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID) ||
|
|
|
|
|
result.Metadata["diagnostic_path"] != artifacts.SessionRunNotariusLogPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID) ||
|
|
|
|
|
result.Metadata["rejections_path"] != filepath.Join(durableBundle, "rejected.json") ||
|
|
|
|
|
result.Metadata["warnings_path"] != filepath.Join(durableBundle, "warnings.json") ||
|
|
|
|
|
result.Metadata["diagnostics_path"] != filepath.Join(durableBundle, "diagnostics.json") {
|
|
|
|
|
t.Fatalf("diagnostic metadata = %#v", result.Metadata)
|
|
|
|
|
}
|
|
|
|
|
if len(result.Outputs) != 2 {
|
|
|
|
|
t.Fatalf("outputs = %#v", result.Outputs)
|
|
|
|
|
}
|
|
|
|
|
lane := result.Outputs[0]
|
|
|
|
|
if lane.Kind != extractLaneOutputKind || lane.SourceID != "narratio.extraction.npc_registry" {
|
|
|
|
|
t.Fatalf("lane identity = %#v", lane)
|
|
|
|
|
}
|
|
|
|
|
if lane.AbsolutePath != filepath.Join(durableBundle, "lanes", "npc.json") || lane.Checksum == "" {
|
|
|
|
|
t.Fatalf("lane path/checksum = %#v", lane)
|
|
|
|
|
}
|
|
|
|
|
wantContract := &artifactmodel.ContractMetadata{
|
|
|
|
|
MediaType: "application/json", SchemaID: "notarius.dnd.npc_registry",
|
|
|
|
|
SchemaVersion: "v1", ModuleKey: "dnd/npc-registry",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(lane.Contract, wantContract) {
|
|
|
|
|
t.Fatalf("lane contract = %#v, want %#v", lane.Contract, wantContract)
|
|
|
|
|
}
|
|
|
|
|
wantProvenance := &artifactmodel.ExternalProvenance{
|
|
|
|
|
System: "notarius", RunID: "notarius-run-1", PipelineID: "dnd-session", ArtifactID: "npc-registry",
|
|
|
|
|
}
|
|
|
|
|
if !reflect.DeepEqual(lane.ExternalProvenance, wantProvenance) {
|
|
|
|
|
t.Fatalf("lane provenance = %#v, want %#v", lane.ExternalProvenance, wantProvenance)
|
|
|
|
|
}
|
|
|
|
|
index := result.Outputs[1]
|
|
|
|
|
if index.Kind != extractIndexOutputKind || index.SourceID != "" || index.AbsolutePath != filepath.Join(durableBundle, "index.json") || index.Checksum == "" {
|
|
|
|
|
t.Fatalf("index output = %#v", index)
|
|
|
|
|
}
|
|
|
|
|
if !strings.HasPrefix(lane.AbsolutePath, durableBundle+string(filepath.Separator)) || strings.HasPrefix(lane.AbsolutePath, stagingBundle+string(filepath.Separator)) {
|
|
|
|
|
t.Fatalf("lane path was not re-resolved after promotion: %q", lane.AbsolutePath)
|
|
|
|
|
}
|
|
|
|
|
for _, relative := range []string{
|
|
|
|
|
"index.json", "manifest.json", "rejected.json", "warnings.json", "diagnostics.json", "lanes/npc.json",
|
|
|
|
|
"lanes/unconfigured.json", "chunk-map.json", "evidence-context.json", "unknown/private-debug.json",
|
|
|
|
|
} {
|
|
|
|
|
if _, err := os.Stat(filepath.Join(durableBundle, filepath.FromSlash(relative))); err != nil {
|
|
|
|
|
t.Fatalf("promoted file %q missing: %v", relative, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(stagingBundle); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("staging bundle still exists after rename: %v", err)
|
|
|
|
|
}
|
|
|
|
|
for _, output := range result.Outputs {
|
|
|
|
|
if strings.Contains(output.AbsolutePath, "unconfigured") || strings.Contains(output.AbsolutePath, "private-debug") {
|
|
|
|
|
t.Fatalf("unknown file registered as output: %#v", output)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rejections, _ := result.Metadata["rejections"].([]map[string]any)
|
|
|
|
|
warnings, _ := result.Metadata["warnings"].([]map[string]any)
|
|
|
|
|
if len(rejections) != 1 || rejections[0]["reason_code"] != "optional_rejected" || len(warnings) != 1 {
|
|
|
|
|
t.Fatalf("diagnostic summaries = rejections %#v warnings %#v", rejections, warnings)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageConsumesAllDefaultDndPipelineArtifacts(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
|
|
|
|
|
contracts := map[string]config.NotariusOutputConfig{
|
|
|
|
|
"item_registry": {LaneID: "item-registry", MediaType: "application/json", SchemaID: "notarius.dnd.item_registry", SchemaVersion: "v1", ModuleKey: "dnd/item-registry"},
|
|
|
|
|
"npc_registry": {LaneID: "npc-registry", MediaType: "application/json", SchemaID: "notarius.dnd.npc_registry", SchemaVersion: "v1", ModuleKey: "dnd/npc-registry"},
|
|
|
|
|
"location_registry": {LaneID: "location-registry", MediaType: "application/json", SchemaID: "notarius.dnd.location_registry", SchemaVersion: "v1", ModuleKey: "dnd/location-registry"},
|
|
|
|
|
"scene_descriptions": {LaneID: "scene-descriptions", MediaType: "application/json", SchemaID: "notarius.dnd.scene_descriptions", SchemaVersion: "v1", ModuleKey: "dnd/scene-descriptions"},
|
|
|
|
|
"item_occurrences": {LaneID: "item-occurrences", MediaType: "application/json", SchemaID: "notarius.dnd.item_occurrences", SchemaVersion: "v1", ModuleKey: "dnd/item-occurrences"},
|
|
|
|
|
"spells": {LaneID: "spells", MediaType: "application/json", SchemaID: "notarius.dnd.spells", SchemaVersion: "v1", ModuleKey: "dnd/spells"},
|
|
|
|
|
"combat_turns": {LaneID: "combat-turns", MediaType: "application/json", SchemaID: "notarius.dnd.combat_turns", SchemaVersion: "v1", ModuleKey: "dnd/combat-turns"},
|
|
|
|
|
"npc_occurrences": {LaneID: "npc-occurrences", MediaType: "application/json", SchemaID: "notarius.dnd.npc_occurrences", SchemaVersion: "v1", ModuleKey: "dnd/npc-occurrences"},
|
|
|
|
|
"location_occurrences": {LaneID: "location-occurrences", MediaType: "application/json", SchemaID: "notarius.dnd.location_occurrences", SchemaVersion: "v1", ModuleKey: "dnd/location-occurrences"},
|
|
|
|
|
"enemy_events": {LaneID: "enemy-events", MediaType: "application/json", SchemaID: "notarius.dnd.enemy_events", SchemaVersion: "v1", ModuleKey: "dnd/enemy-events"},
|
|
|
|
|
}
|
|
|
|
|
env.Config.Pipeline.Notarius.Outputs = contracts
|
|
|
|
|
fake.Result.Index.Lanes = nil
|
|
|
|
|
fake.Result.Rejections = nil
|
|
|
|
|
fake.Result.Warnings = nil
|
|
|
|
|
fake.Result.Diagnostics = nil
|
|
|
|
|
fake.Result.Receipt.NormalizedOutputCount = len(contracts)
|
|
|
|
|
fake.Result.Receipt.RejectedOutputCount = 0
|
|
|
|
|
fake.Result.Receipt.WarningGroupCount = 0
|
|
|
|
|
fake.Result.Receipt.WarningOccurrenceCount = 0
|
|
|
|
|
fake.Result.Receipt.DiagnosticGroupCount = 0
|
|
|
|
|
fake.Result.Receipt.DiagnosticOccurrenceCount = 0
|
|
|
|
|
fake.Result.Receipt.ValidationStatus = "approved"
|
|
|
|
|
indexDescriptors := make([]map[string]any, 0, len(contracts))
|
|
|
|
|
for _, contract := range contracts {
|
|
|
|
|
relative := "lanes/" + contract.LaneID + ".json"
|
|
|
|
|
path := filepath.Join(fake.Result.BundleRoot, filepath.FromSlash(relative))
|
|
|
|
|
if err := os.WriteFile(path, []byte(`{"records":[]}`), 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(%q) error = %v", path, err)
|
|
|
|
|
}
|
|
|
|
|
fake.Result.Index.Lanes = append(fake.Result.Index.Lanes, notarius.LaneDescriptor{
|
|
|
|
|
LaneID: contract.LaneID, File: relative, Path: path, MediaType: contract.MediaType,
|
|
|
|
|
ModuleKey: contract.ModuleKey, SchemaID: contract.SchemaID, SchemaVersion: contract.SchemaVersion,
|
|
|
|
|
})
|
|
|
|
|
indexDescriptors = append(indexDescriptors, map[string]any{
|
|
|
|
|
"lane_id": contract.LaneID, "file": relative, "media_type": contract.MediaType,
|
|
|
|
|
"module_key": contract.ModuleKey, "schema_id": contract.SchemaID,
|
|
|
|
|
"schema_version": contract.SchemaVersion,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if err := writeJSONFile(fake.Result.Index.Path, map[string]any{
|
|
|
|
|
"manifest_file": "manifest.json", "output_files": indexDescriptors,
|
|
|
|
|
"rejected_file": "rejected.json", "warnings_file": "warnings.json",
|
|
|
|
|
"diagnostics_file": "diagnostics.json",
|
|
|
|
|
}); err != nil {
|
|
|
|
|
t.Fatalf("write complete D&D index: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if len(result.Outputs) != len(contracts)+1 {
|
|
|
|
|
t.Fatalf("output count = %d, want %d", len(result.Outputs), len(contracts)+1)
|
|
|
|
|
}
|
|
|
|
|
got := make(map[string]*artifactmodel.ContractMetadata, len(contracts))
|
|
|
|
|
for _, output := range result.Outputs {
|
|
|
|
|
if output.Kind == extractLaneOutputKind {
|
|
|
|
|
got[output.SourceID] = output.Contract
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for key, contract := range contracts {
|
|
|
|
|
sourceID := artifacts.ExtractionArtifactSourceID(key)
|
|
|
|
|
actual := got[sourceID]
|
|
|
|
|
if actual == nil || actual.MediaType != contract.MediaType || actual.SchemaID != contract.SchemaID ||
|
|
|
|
|
actual.SchemaVersion != contract.SchemaVersion || actual.ModuleKey != contract.ModuleKey {
|
|
|
|
|
t.Fatalf("source %q contract = %#v, want %#v", sourceID, actual, contract)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageRejectsMissingOrInvalidFinalTrimmedInputBeforeInvocation(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
@@ -786,131 +615,6 @@ func TestExtractStageRejectsMissingOrInvalidFinalTrimmedInputBeforeInvocation(t
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageEnforcesRequiredLanePolicy(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
mutate func(*notarius.RunResult)
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{name: "missing", mutate: func(result *notarius.RunResult) { result.Index.Lanes = result.Index.Lanes[1:] }, want: "0 descriptors"},
|
|
|
|
|
{name: "rejected", mutate: func(result *notarius.RunResult) {
|
|
|
|
|
result.Rejections = append(result.Rejections, notarius.RejectionSummary{LaneID: "npc-registry", ReasonCode: "invalid_npc"})
|
|
|
|
|
}, want: "was rejected"},
|
|
|
|
|
{name: "incomplete validation", mutate: func(result *notarius.RunResult) {
|
|
|
|
|
result.Receipt.ValidationSummaries = []notarius.ValidationSummary{{LaneID: "npc-registry", Status: "incomplete"}}
|
|
|
|
|
}, want: `validation is "incomplete"`},
|
|
|
|
|
{name: "duplicate", mutate: func(result *notarius.RunResult) {
|
|
|
|
|
result.Index.Lanes = append(result.Index.Lanes, result.Index.Lanes[0])
|
|
|
|
|
}, want: "2 descriptors"},
|
|
|
|
|
{name: "media type", mutate: func(result *notarius.RunResult) { result.Index.Lanes[0].MediaType = "text/plain" }, want: "incompatible"},
|
|
|
|
|
{name: "schema id", mutate: func(result *notarius.RunResult) { result.Index.Lanes[0].SchemaID = "other" }, want: "incompatible"},
|
|
|
|
|
{name: "schema version", mutate: func(result *notarius.RunResult) { result.Index.Lanes[0].SchemaVersion = "v2" }, want: "incompatible"},
|
|
|
|
|
{name: "module key", mutate: func(result *notarius.RunResult) { result.Index.Lanes[0].ModuleKey = "other" }, want: "incompatible"},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
test.mutate(&fake.Result)
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err == nil || !strings.Contains(err.Error(), test.want) {
|
|
|
|
|
t.Fatalf("Run() result = %#v error = %v, want %q", result, err, test.want)
|
|
|
|
|
}
|
|
|
|
|
if result != nil && len(result.Outputs) != 0 {
|
|
|
|
|
t.Fatalf("failure returned outputs: %#v", result.Outputs)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageValidatesSelectedLaneJSON(t *testing.T) {
|
|
|
|
|
for _, test := range []struct {
|
|
|
|
|
name string
|
|
|
|
|
content string
|
|
|
|
|
want string
|
|
|
|
|
}{
|
|
|
|
|
{name: "empty", content: "", want: "non-empty"},
|
|
|
|
|
{name: "invalid", content: "not-json", want: "valid JSON"},
|
|
|
|
|
} {
|
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
if err := os.WriteFile(fake.Result.Index.Lanes[0].Path, []byte(test.content), 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(lane) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := (extractStage{}).Run(context.Background(), env, m); err == nil || !strings.Contains(err.Error(), test.want) {
|
|
|
|
|
t.Fatalf("Run() error = %v, want %q", err, test.want)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageAdapterAndPromotionFailuresReturnNoOutputs(t *testing.T) {
|
|
|
|
|
t.Run("adapter", func(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
fixture := extractFixtureFromEnv(t, env, m)
|
|
|
|
|
receiptPath := artifacts.SessionRunNotariusReceiptPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
logPath := artifacts.SessionRunNotariusLogPathForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
for _, path := range []string{receiptPath, logPath} {
|
|
|
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
|
|
|
t.Fatalf("MkdirAll(diagnostic parent) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(path, []byte("diagnostic"), 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(diagnostic) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fake.Err = errors.New("adapter failed")
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err == nil || !strings.Contains(err.Error(), "adapter failed") || result != nil {
|
|
|
|
|
t.Fatalf("Run() result = %#v error = %v", result, err)
|
|
|
|
|
}
|
|
|
|
|
outputRoot := artifacts.SessionRunNotariusOutputRootForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
if _, err := os.Stat(outputRoot); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("failed adapter output root still exists: %v", err)
|
|
|
|
|
}
|
|
|
|
|
for _, path := range []string{receiptPath, logPath} {
|
|
|
|
|
if _, err := os.Stat(path); err != nil {
|
|
|
|
|
t.Fatalf("diagnostic %q was not retained: %v", path, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("promotion", func(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
fixture := extractFixtureFromEnv(t, env, m)
|
|
|
|
|
destination := artifacts.SessionNotariusBundleDirForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
if err := os.MkdirAll(destination, 0o755); err != nil {
|
|
|
|
|
t.Fatalf("MkdirAll(destination) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err == nil || !strings.Contains(err.Error(), "destination already exists") || result != nil {
|
|
|
|
|
t.Fatalf("Run() result = %#v error = %v", result, err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(fake.Result.BundleRoot); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("failed installation staging bundle still exists: %v", err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("failure after rename", func(t *testing.T) {
|
|
|
|
|
env, m, _ := setupExtractEnv(t)
|
|
|
|
|
fixture := extractFixtureFromEnv(t, env, m)
|
|
|
|
|
outputRoot := artifacts.SessionRunNotariusOutputRootForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
if err := os.WriteFile(filepath.Join(outputRoot, "unexpected-sidecar"), []byte("unexpected"), 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(unexpected sidecar) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
destination := artifacts.SessionNotariusBundleDirForCampaign(fixture.workspace, fixture.campaign, fixture.sessionID, fixture.runID)
|
|
|
|
|
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err == nil || !strings.Contains(err.Error(), "remove empty Notarius output root") || result != nil {
|
|
|
|
|
t.Fatalf("Run() result = %#v error = %v", result, err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(destination); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("failed stage durable bundle still exists: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(outputRoot); !os.IsNotExist(err) {
|
|
|
|
|
t.Fatalf("failed stage output root still exists: %v", err)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractionFingerprintIsIndependentOfOutputMapOrder(t *testing.T) {
|
|
|
|
|
input := artifacts.ExtractionInputIdentity{
|
|
|
|
|
Checksum: "checksum", SourceID: artifacts.ArtifactTranscriptFinalTrimmed,
|
|
|
|
|
@@ -918,8 +622,8 @@ func TestExtractionFingerprintIsIndependentOfOutputMapOrder(t *testing.T) {
|
|
|
|
|
ProducerRunID: "trim-run", Provenance: "manifest.trim.outputs",
|
|
|
|
|
}
|
|
|
|
|
first := &config.NotariusConfig{PipelineID: "pipeline", Outputs: map[string]config.NotariusOutputConfig{
|
|
|
|
|
"zeta": {LaneID: "z", MediaType: "application/json", SchemaID: "z", SchemaVersion: "v1"},
|
|
|
|
|
"alpha": {LaneID: "a", MediaType: "application/json", SchemaID: "a", SchemaVersion: "v1"},
|
|
|
|
|
"zeta": {LaneID: "z"},
|
|
|
|
|
"alpha": {LaneID: "a"},
|
|
|
|
|
}}
|
|
|
|
|
second := &config.NotariusConfig{PipelineID: "pipeline", Outputs: map[string]config.NotariusOutputConfig{
|
|
|
|
|
"alpha": first.Outputs["alpha"], "zeta": first.Outputs["zeta"],
|
|
|
|
|
@@ -987,60 +691,6 @@ func TestExtractionFingerprintIsIndependentOfOutputMapOrder(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractionFingerprintBaseSelectorsPreservePriorPayloadShape(t *testing.T) {
|
|
|
|
|
input := artifacts.ExtractionInputIdentity{
|
|
|
|
|
Checksum: "checksum", SourceID: artifacts.ArtifactTranscriptFinalTrimmed,
|
|
|
|
|
ProducerStage: "trim", OutputKind: artifacts.TranscriptOutputKindFinalTrimmed,
|
|
|
|
|
ProducerRunID: "trim-run", Provenance: "manifest.trim.outputs",
|
|
|
|
|
}
|
|
|
|
|
references := []extractReferenceIdentity{{
|
|
|
|
|
Selector: "party", SourceID: artifactpolicy.SourceInputParty,
|
|
|
|
|
Path: "inputs/party.yml", Checksum: "party-checksum", SizeBytes: 34,
|
|
|
|
|
}}
|
|
|
|
|
cfg := &config.NotariusConfig{
|
|
|
|
|
PipelineID: "pipeline",
|
|
|
|
|
Outputs: map[string]config.NotariusOutputConfig{
|
|
|
|
|
"alpha": {LaneID: "a", MediaType: "application/json", SchemaID: "a", SchemaVersion: "v1"},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
legacyPayload, err := json.Marshal(struct {
|
|
|
|
|
PipelineID string `json:"pipeline_id"`
|
|
|
|
|
Input artifacts.ExtractionInputIdentity `json:"input"`
|
|
|
|
|
References []extractReferenceIdentity `json:"references"`
|
|
|
|
|
Outputs []fingerprintOutput `json:"outputs"`
|
|
|
|
|
}{
|
|
|
|
|
PipelineID: cfg.PipelineID,
|
|
|
|
|
Input: input,
|
|
|
|
|
References: references,
|
|
|
|
|
Outputs: []fingerprintOutput{{
|
|
|
|
|
Key: "alpha", LaneID: "a", MediaType: "application/json", SchemaID: "a", SchemaVersion: "v1",
|
|
|
|
|
}},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
legacyDigest := sha256.Sum256(legacyPayload)
|
|
|
|
|
want := hex.EncodeToString(legacyDigest[:])
|
|
|
|
|
for _, profile := range []*string{nil, stringPointerForExtractTest(""), stringPointerForExtractTest("default")} {
|
|
|
|
|
cfg.ConfigOverlay = profile
|
|
|
|
|
got, err := extractionFingerprint(cfg, input, references)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if got != want {
|
|
|
|
|
t.Fatalf("base selection fingerprint = %q, want prior no-profile payload digest %q", got, want)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
cfg.ConfigOverlay = stringPointerForExtractTest("inexpensive")
|
|
|
|
|
named, err := extractionFingerprint(cfg, input, references)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if named == want {
|
|
|
|
|
t.Fatal("named selection retained prior no-profile fingerprint")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageResumeValidationAcceptsCurrentImmutableResult(t *testing.T) {
|
|
|
|
|
env, m, _ := setupExtractEnv(t)
|
|
|
|
|
env.Config.Pipeline.Notarius.References = map[string]string{
|
|
|
|
|
@@ -1159,7 +809,7 @@ func TestExtractStageResumeValidationDoesNotResolveReferencesWhenDisabled(t *tes
|
|
|
|
|
env, m, _ := setupExtractEnv(t)
|
|
|
|
|
env.Config.Pipeline.Notarius.Enabled = false
|
|
|
|
|
env.Config.Pipeline.Notarius.References = map[string]string{
|
|
|
|
|
"missing": artifactpolicy.SourceInputSpellCatalog,
|
|
|
|
|
"missing": "narratio.input.spell_catalog",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
validation, err := (extractStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
@@ -1171,68 +821,6 @@ func TestExtractStageResumeValidationDoesNotResolveReferencesWhenDisabled(t *tes
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageAdapterResultIsImmediatelyReusableAndCatalogVisible(t *testing.T) {
|
|
|
|
|
env, m, fake := setupExtractEnv(t)
|
|
|
|
|
producerRunID := m.RunID
|
|
|
|
|
receiptFixture := filepath.Join(t.TempDir(), "receipt.json")
|
|
|
|
|
receipt, err := json.Marshal(map[string]any{
|
|
|
|
|
"schema_version": notarius.ReceiptSchemaVersion,
|
|
|
|
|
"run_id": "notarius-run-1", "pipeline_id": "dnd-session",
|
|
|
|
|
"output_directory": fake.Result.BundleRoot, "index_file": "index.json",
|
|
|
|
|
"normalized_output_count": 2, "rejected_output_count": 0,
|
|
|
|
|
"warning_group_count": 0, "warning_occurrence_count": 0,
|
|
|
|
|
"diagnostic_group_count": 0, "diagnostic_occurrence_count": 0,
|
|
|
|
|
"diagnostics_truncated": false,
|
|
|
|
|
"validation_status": "approved", "future_field": true,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("json.Marshal(receipt) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(receiptFixture, receipt, 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(receipt fixture) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.WriteFile(env.Config.Pipeline.Notarius.Binary, []byte(fmt.Sprintf("#!/bin/sh\ncat %q\n", receiptFixture)), 0o755); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(notarius helper) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
env.Notarius = notarius.NewSubprocessRunner()
|
|
|
|
|
|
|
|
|
|
result, err := (extractStage{}).Run(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Run() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
durableIndex := filepath.Join(result.Metadata["bundle_root"].(string), "index.json")
|
|
|
|
|
if len(result.Outputs) != 2 || result.Outputs[1].AbsolutePath != durableIndex {
|
|
|
|
|
t.Fatalf("outputs = %#v, want canonical durable index %q", result.Outputs, durableIndex)
|
|
|
|
|
}
|
|
|
|
|
recordSucceededExtractResult(m, producerRunID, result)
|
|
|
|
|
m.RunID = "20260810T020304Z-fedcba98"
|
|
|
|
|
|
|
|
|
|
validation, err := (extractStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("ValidateResume() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if !validation.Resumable {
|
|
|
|
|
t.Fatalf("validation = %#v, want resumable", validation)
|
|
|
|
|
}
|
|
|
|
|
definition := env.Config.Pipeline.Notarius.Outputs["npc_registry"]
|
|
|
|
|
definitions := map[string]artifacts.ExtractionArtifactDefinition{
|
|
|
|
|
"npc_registry": {
|
|
|
|
|
LaneID: definition.LaneID, PipelineID: env.Config.Pipeline.Notarius.PipelineID,
|
|
|
|
|
MediaType: definition.MediaType, SchemaID: definition.SchemaID,
|
|
|
|
|
SchemaVersion: definition.SchemaVersion, ModuleKey: definition.ModuleKey,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
catalog := artifacts.NewArtifactCatalog()
|
|
|
|
|
if err := catalog.RegisterExtractionArtifacts(definitions); err != nil {
|
|
|
|
|
t.Fatalf("RegisterExtractionArtifacts() error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
catalog.HydrateExtractionArtifacts(sessionPathsForEnv(env, m.SessionID), m, definitions)
|
|
|
|
|
entry, ok := catalog.Lookup(artifacts.ExtractionArtifactSourceID("npc_registry"))
|
|
|
|
|
if !ok || !entry.Available || entry.Path != result.Outputs[0].AbsolutePath || entry.ProducerRunID != producerRunID {
|
|
|
|
|
t.Fatalf("hydrated extraction entry = %#v, %v", entry, ok)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExtractStageResumeValidationRequiresFreshEvidence(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
@@ -1265,8 +853,8 @@ func TestExtractStageResumeValidationRequiresFreshEvidence(t *testing.T) {
|
|
|
|
|
t.Fatalf("WriteFile(lane) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
}},
|
|
|
|
|
{name: "incompatible contract", mutate: func(_ *testing.T, _ *Env, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Contract.SchemaVersion = "v2"
|
|
|
|
|
{name: "incorrect size", mutate: func(_ *testing.T, _ *Env, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].Size++
|
|
|
|
|
}},
|
|
|
|
|
{name: "missing source", mutate: func(_ *testing.T, _ *Env, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs = m.Stages["extract"].Outputs[1:]
|
|
|
|
|
@@ -1275,13 +863,7 @@ func TestExtractStageResumeValidationRequiresFreshEvidence(t *testing.T) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].ProducerRunID = "different-run"
|
|
|
|
|
}},
|
|
|
|
|
{name: "provenance mismatch", mutate: func(_ *testing.T, _ *Env, m *manifest.Manifest) {
|
|
|
|
|
m.Stages["extract"].Outputs[0].ExternalProvenance.RunID = "different-run"
|
|
|
|
|
}},
|
|
|
|
|
{name: "missing index", mutate: func(t *testing.T, _ *Env, m *manifest.Manifest) {
|
|
|
|
|
index := m.Stages["extract"].Outputs[1]
|
|
|
|
|
if err := os.Remove(index.LocalPath); err != nil {
|
|
|
|
|
t.Fatalf("Remove(index) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
m.Stages["extract"].Outputs[0].ExternalProvenance.ArtifactID = "different-lane"
|
|
|
|
|
}},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
@@ -1331,7 +913,7 @@ func TestExtractStageResumeValidationRejectsUnsafePathWithError(t *testing.T) {
|
|
|
|
|
prior := *m.Stages["extract"]
|
|
|
|
|
test.mutate(t, env, m)
|
|
|
|
|
|
|
|
|
|
if _, err := (extractStage{}).ValidateResume(context.Background(), env, m); err == nil || !strings.Contains(err.Error(), "unsafe") {
|
|
|
|
|
if _, err := (extractStage{}).ValidateResume(context.Background(), env, m); err == nil {
|
|
|
|
|
t.Fatalf("ValidateResume() error = %v, want unsafe evidence error", err)
|
|
|
|
|
}
|
|
|
|
|
if m.Stages["extract"].Status != prior.Status || m.Stages["extract"].Error != prior.Error {
|
|
|
|
|
@@ -1357,7 +939,7 @@ func recordSucceededExtractResult(m *manifest.Manifest, producerRunID string, re
|
|
|
|
|
records = append(records, manifest.ArtifactRecord{
|
|
|
|
|
Kind: output.Kind, SourceID: output.SourceID, LocalPath: output.AbsolutePath,
|
|
|
|
|
Contract: output.Contract, ExternalProvenance: output.ExternalProvenance,
|
|
|
|
|
ProducerRunID: producerRunID, Checksum: output.Checksum,
|
|
|
|
|
ProducerRunID: producerRunID, Checksum: output.Checksum, Size: output.Size,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
m.MarkStageSucceeded("extract", time.Now().UTC(), records)
|
|
|
|
|
@@ -1438,8 +1020,7 @@ func setupExtractEnv(t *testing.T) (*Env, *manifest.Manifest, *notarius.FakeRunn
|
|
|
|
|
Timeout: "45m", WorkingDirectory: workingDirectory,
|
|
|
|
|
Outputs: map[string]config.NotariusOutputConfig{
|
|
|
|
|
"npc_registry": {
|
|
|
|
|
LaneID: "npc-registry", MediaType: "application/json",
|
|
|
|
|
SchemaID: "notarius.dnd.npc_registry", SchemaVersion: "v1", ModuleKey: "dnd/npc-registry",
|
|
|
|
|
LaneID: "npc-registry",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
@@ -1460,57 +1041,11 @@ func setupExtractEnv(t *testing.T) (*Env, *manifest.Manifest, *notarius.FakeRunn
|
|
|
|
|
if err := os.MkdirAll(filepath.Join(bundle, "lanes"), 0o755); err != nil {
|
|
|
|
|
t.Fatalf("MkdirAll(bundle lanes) error = %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := os.MkdirAll(filepath.Join(bundle, "unknown"), 0o755); err != nil {
|
|
|
|
|
t.Fatalf("MkdirAll(bundle unknown) error = %v", err)
|
|
|
|
|
if err := os.WriteFile(filepath.Join(bundle, "lanes", "npc-registry.json"), []byte(`{"npcs":[]}`), 0644); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
files := map[string]string{
|
|
|
|
|
"index.json": `{"manifest_file":"manifest.json","output_files":[{"lane_id":"npc-registry","file":"lanes/npc.json","media_type":"application/json","module_key":"dnd/npc-registry","schema_id":"notarius.dnd.npc_registry","schema_version":"v1","future_field":true},{"lane_id":"unconfigured","file":"lanes/unconfigured.json"}],"rejected_file":"rejected.json","warnings_file":"warnings.json","diagnostics_file":"diagnostics.json","future_field":true}`,
|
|
|
|
|
"manifest.json": `{}`,
|
|
|
|
|
"rejected.json": `{"rejected":[]}`,
|
|
|
|
|
"warnings.json": `{"schema_version":"notarius.warnings.v2","group_count":0,"occurrence_count":0,"groups":[]}`,
|
|
|
|
|
"diagnostics.json": `{"schema_version":"notarius.diagnostics.v1","group_count":0,"occurrence_count":0,"truncated":false,"unrepresented_occurrence_count":0,"groups":[]}`,
|
|
|
|
|
"lanes/npc.json": `{"npcs":[]}`,
|
|
|
|
|
"lanes/unconfigured.json": `{"spells":[]}`,
|
|
|
|
|
"chunk-map.json": `{"chunks":[]}`,
|
|
|
|
|
"evidence-context.json": `{"source_units":[]}`,
|
|
|
|
|
"unknown/private-debug.json": `{"private":true}`,
|
|
|
|
|
}
|
|
|
|
|
for relative, content := range files {
|
|
|
|
|
if err := os.WriteFile(filepath.Join(bundle, filepath.FromSlash(relative)), []byte(content), 0o644); err != nil {
|
|
|
|
|
t.Fatalf("WriteFile(%q) error = %v", relative, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fake := ¬arius.FakeRunner{Result: notarius.RunResult{
|
|
|
|
|
Receipt: notarius.Receipt{
|
|
|
|
|
SchemaVersion: notarius.ReceiptSchemaVersion, RunID: "notarius-run-1", PipelineID: "dnd-session",
|
|
|
|
|
OutputDirectory: bundle, IndexFile: "index.json", NormalizedOutputCount: 2,
|
|
|
|
|
RejectedOutputCount: 1, WarningGroupCount: 1, WarningOccurrenceCount: 1,
|
|
|
|
|
DiagnosticGroupCount: 1, DiagnosticOccurrenceCount: 1, ValidationStatus: "rejected",
|
|
|
|
|
},
|
|
|
|
|
BundleRoot: bundle,
|
|
|
|
|
Index: notarius.Index{
|
|
|
|
|
Path: filepath.Join(bundle, "index.json"), RejectedPath: filepath.Join(bundle, "rejected.json"),
|
|
|
|
|
WarningsPath: filepath.Join(bundle, "warnings.json"),
|
|
|
|
|
DiagnosticsPath: filepath.Join(bundle, "diagnostics.json"),
|
|
|
|
|
Lanes: []notarius.LaneDescriptor{
|
|
|
|
|
{
|
|
|
|
|
LaneID: "npc-registry", File: "lanes/npc.json", Path: filepath.Join(bundle, "lanes", "npc.json"),
|
|
|
|
|
MediaType: "application/json", ModuleKey: "dnd/npc-registry",
|
|
|
|
|
SchemaID: "notarius.dnd.npc_registry", SchemaVersion: "v1",
|
|
|
|
|
},
|
|
|
|
|
{LaneID: "unconfigured", File: "lanes/unconfigured.json", Path: filepath.Join(bundle, "lanes", "unconfigured.json")},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Rejections: []notarius.RejectionSummary{{LaneID: "optional", ReasonCode: "optional_rejected"}},
|
|
|
|
|
Warnings: []notarius.WarningSummary{{
|
|
|
|
|
Disposition: "warning", Category: "degradation", ReasonCode: "normalized_name",
|
|
|
|
|
Origin: notarius.DiagnosticOrigin{Stage: "normalize", LaneID: "npc-registry"}, OccurrenceCount: 1,
|
|
|
|
|
}},
|
|
|
|
|
Diagnostics: []notarius.DiagnosticSummary{{
|
|
|
|
|
Disposition: "advisory", Category: "data_quality", ReasonCode: "low_confidence",
|
|
|
|
|
Origin: notarius.DiagnosticOrigin{Stage: "normalize", ValidatorKey: "validator"}, OccurrenceCount: 1,
|
|
|
|
|
}},
|
|
|
|
|
}}
|
|
|
|
|
fake := ¬arius.FakeRunner{Result: notarius.RunResult{BundleRoot: bundle, Report: notarius.CompletionReport{Pipeline: "dnd-session", ArtifactCount: 1, OutputDirectory: bundle}}}
|
|
|
|
|
|
|
|
|
|
env := &Env{
|
|
|
|
|
Config: &config.Config{
|
|
|
|
|
Pipeline: &config.PipelineConfig{Workspace: config.WorkspaceConfig{Root: workspace}, Notarius: notariusConfig},
|
|
|
|
|
|