Reconcile reuse and inspection with native extraction
This commit is contained in:
@@ -60,62 +60,34 @@ func (s assertExtractionSourcesStage) Run(_ context.Context, env *stage.Env, m *
|
||||
return &stage.StageResult{}, nil
|
||||
}
|
||||
|
||||
func (r *materializingNotariusRunner) Run(_ context.Context, req notarius.RunRequest) (notarius.RunResult, error) {
|
||||
func (r *materializingNotariusRunner) Preflight(ctx context.Context, req notarius.ReadinessRequest) (notarius.ReadinessResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return notarius.ReadinessResult{}, err
|
||||
}
|
||||
return notarius.ReadinessResult{Pipeline: req.PipelineID, Lanes: append([]string(nil), req.RequiredLanes...), InspectionComplete: true, AssessmentComplete: true, Ready: true, InputPath: req.InputPath, InputDescription: req.InputDescription}, nil
|
||||
}
|
||||
|
||||
func (r *materializingNotariusRunner) Run(ctx context.Context, req notarius.RunRequest) (notarius.RunResult, error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return notarius.RunResult{}, err
|
||||
}
|
||||
r.requests = append(r.requests, req)
|
||||
if r.failuresRemaining > 0 {
|
||||
r.failuresRemaining--
|
||||
return notarius.RunResult{}, errors.New("notarius execution failed")
|
||||
}
|
||||
externalRunID := fmt.Sprintf("notarius-run-%d", len(r.requests))
|
||||
bundle := filepath.Join(req.OutputRoot, externalRunID)
|
||||
lanesDir := filepath.Join(bundle, "lanes")
|
||||
if err := os.MkdirAll(lanesDir, 0o755); err != nil {
|
||||
bundle := filepath.Join(req.OutputRoot, fmt.Sprintf("notarius-run-%d", len(r.requests)))
|
||||
lanes := filepath.Join(bundle, "lanes")
|
||||
if err := os.MkdirAll(lanes, 0755); err != nil {
|
||||
return notarius.RunResult{}, err
|
||||
}
|
||||
for path, content := range map[string]string{
|
||||
filepath.Join(bundle, "index.json"): `{"manifest_file":"manifest.json"}`,
|
||||
filepath.Join(bundle, "manifest.json"): `{}`,
|
||||
filepath.Join(bundle, "rejected.json"): `{"rejected":[]}`,
|
||||
filepath.Join(bundle, "warnings.json"): `{"schema_version":"notarius.warnings.v2","group_count":0,"occurrence_count":0,"groups":[]}`,
|
||||
filepath.Join(bundle, "diagnostics.json"): `{"schema_version":"notarius.diagnostics.v1","group_count":0,"occurrence_count":0,"truncated":false,"unrepresented_occurrence_count":0,"groups":[]}`,
|
||||
} {
|
||||
if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
|
||||
for _, output := range r.cfg.Outputs {
|
||||
filename := output.LaneID + ".json"
|
||||
if err := os.WriteFile(filepath.Join(lanes, filename), []byte(`{"records":[]}`), 0644); err != nil {
|
||||
return notarius.RunResult{}, err
|
||||
}
|
||||
}
|
||||
keys := make([]string, 0, len(r.cfg.Outputs))
|
||||
for key := range r.cfg.Outputs {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
lanes := make([]notarius.LaneDescriptor, 0, len(keys))
|
||||
for _, key := range keys {
|
||||
output := r.cfg.Outputs[key]
|
||||
filename := key + ".json"
|
||||
path := filepath.Join(lanesDir, filename)
|
||||
if err := os.WriteFile(path, []byte(`{"records":[]}`), 0o644); err != nil {
|
||||
return notarius.RunResult{}, err
|
||||
}
|
||||
lanes = append(lanes, notarius.LaneDescriptor{
|
||||
LaneID: output.LaneID, File: filepath.ToSlash(filepath.Join("lanes", filename)), Path: path,
|
||||
MediaType: output.MediaType, SchemaID: output.SchemaID,
|
||||
SchemaVersion: output.SchemaVersion, ModuleKey: output.ModuleKey,
|
||||
})
|
||||
}
|
||||
return notarius.RunResult{
|
||||
Receipt: notarius.Receipt{
|
||||
SchemaVersion: notarius.ReceiptSchemaVersion, RunID: externalRunID,
|
||||
PipelineID: req.PipelineID, OutputDirectory: bundle, IndexFile: "index.json",
|
||||
NormalizedOutputCount: len(lanes), ValidationStatus: "approved",
|
||||
},
|
||||
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: lanes,
|
||||
},
|
||||
}, nil
|
||||
return notarius.RunResult{BundleRoot: bundle, Report: notarius.CompletionReport{Pipeline: req.PipelineID, ArtifactCount: len(r.cfg.Outputs), OutputDirectory: bundle}}, nil
|
||||
}
|
||||
|
||||
func TestExtractLifecycleDisabledThenEnabled(t *testing.T) {
|
||||
@@ -145,7 +117,7 @@ func TestExtractLifecycleDisabledThenEnabled(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
if loaded.Stages["extract"] == nil || loaded.Stages["extract"].Status != manifest.StatusSucceeded || len(loaded.Stages["extract"].Outputs) != 2 {
|
||||
if loaded.Stages["extract"] == nil || loaded.Stages["extract"].Status != manifest.StatusSucceeded || len(loaded.Stages["extract"].Outputs) != 1 {
|
||||
t.Fatalf("extract record = %#v, want succeeded manifest-ready outputs", loaded.Stages["extract"])
|
||||
}
|
||||
}
|
||||
@@ -170,10 +142,10 @@ func TestExtractLifecyclePrepareBindsVerifiedReferenceSnapshots(t *testing.T) {
|
||||
sourceID string
|
||||
filename string
|
||||
}{
|
||||
{selector: "glossary", sourceID: artifactpolicy.SourceInputGlossaryCampaign, filename: "campaign.yml"},
|
||||
{selector: "glossary", sourceID: artifactpolicy.SourceInputGlossaryCombined, filename: "combined.yml"},
|
||||
{selector: "party", sourceID: artifactpolicy.SourceInputParty, filename: "party.yml"},
|
||||
{selector: "players", sourceID: artifactpolicy.SourceInputPlayers, filename: "players.yml"},
|
||||
{selector: "spells", sourceID: artifactpolicy.SourceInputSpellCatalog, filename: "spell_catalog.json"},
|
||||
{selector: "spells", sourceID: artifactpolicy.SourceInputGlossaryCombined, filename: "combined.yml"},
|
||||
}
|
||||
request := runner.requests[0]
|
||||
if len(request.References) != len(want) {
|
||||
@@ -354,8 +326,8 @@ func TestExtractLifecycleEmptyReferencesPreserveAllDndExtractionSources(t *testi
|
||||
t.Fatalf("summary=%#v requests=%#v analyze=%d", summary, runner.requests, analyzeRuns)
|
||||
}
|
||||
loaded := loadLifecycleManifest(t, cfg)
|
||||
if got := len(loaded.Stages["extract"].Outputs); got != len(keys)+1 {
|
||||
t.Fatalf("extract outputs = %d, want %d lanes plus index", got, len(keys))
|
||||
if got := len(loaded.Stages["extract"].Outputs); got != len(keys) {
|
||||
t.Fatalf("extract outputs = %d, want %d lanes", got, len(keys))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,7 +448,7 @@ characters:
|
||||
t.Fatalf("changed party retained derived players snapshot path %q", thirdPaths["players"])
|
||||
}
|
||||
for selector, firstPath := range firstPaths {
|
||||
if selector != "party" && selector != "players" && thirdPaths[selector] != firstPath {
|
||||
if selector != "party" && selector != "players" && selector != "glossary" && selector != "spells" && thirdPaths[selector] != firstPath {
|
||||
t.Fatalf("unchanged %s snapshot path = %q, want %q", selector, thirdPaths[selector], firstPath)
|
||||
}
|
||||
if _, err := os.Stat(firstPath); err != nil {
|
||||
@@ -496,8 +468,8 @@ func TestExtractLifecycleCacheControlsAndSnapshotLossDoNotInvalidateCompleteResu
|
||||
if err := os.RemoveAll(cacheRoot); err != nil {
|
||||
t.Fatalf("RemoveAll(snapshot cache) error = %v", err)
|
||||
}
|
||||
cfg.Pipeline.Notarius.Resume = true
|
||||
cfg.Pipeline.Notarius.ChunkCache = "bypass"
|
||||
cache := "bypass"
|
||||
cfg.Pipeline.Notarius.Cache = &cache
|
||||
extractPlan, _ := BuildSingleStagePlan("extract")
|
||||
summary, err := executeStages(context.Background(), cfg, extractPlan, RunOptions{Env: env})
|
||||
if err != nil {
|
||||
@@ -537,14 +509,14 @@ func TestAnalyzeOnlyLifecyclePreservesExtractionWithoutInvokingNotarius(t *testi
|
||||
|
||||
func TestForcedArtifactRegenerationUsesOrdinaryExtractAndAnalyzePath(t *testing.T) {
|
||||
cfg, env, runner := extractionLifecycleFixture(t, true)
|
||||
cfg.Pipeline.Notarius.Resume = true
|
||||
cfg.Pipeline.Notarius.ChunkCache = "bypass"
|
||||
cache := "bypass"
|
||||
cfg.Pipeline.Notarius.Cache = &cache
|
||||
analyzeRuns := 0
|
||||
plan := extractionLifecyclePlan(t, &analyzeRuns)
|
||||
if _, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env, Force: true, SelectedArtifacts: []string{"session_recap"}}); err != nil {
|
||||
t.Fatalf("forced artifact regeneration error = %v", err)
|
||||
}
|
||||
if len(runner.requests) != 1 || runner.requests[0].Resume || runner.requests[0].ChunkCache != "refresh" || analyzeRuns != 1 {
|
||||
if len(runner.requests) != 1 || runner.requests[0].Cache == nil || *runner.requests[0].Cache != "refresh" || analyzeRuns != 1 {
|
||||
t.Fatalf("forced path request=%#v analyze=%d", runner.requests, analyzeRuns)
|
||||
}
|
||||
}
|
||||
@@ -821,10 +793,6 @@ func TestExtractLifecycleRealConfigOverlaysSelectNotariusExplicitly(t *testing.T
|
||||
outputs:
|
||||
npc_registry:
|
||||
lane_id: npc-registry
|
||||
media_type: application/json
|
||||
schema_id: notarius.dnd.npc_registry
|
||||
schema_version: v1
|
||||
module_key: dnd/npc-registry
|
||||
`)
|
||||
closeErr := pipelineFile.Close()
|
||||
if writeErr != nil || closeErr != nil {
|
||||
@@ -941,7 +909,7 @@ func TestExtractLifecycleResumesAndRerunsObsoleteResults(t *testing.T) {
|
||||
}{
|
||||
{name: "configuration changed", mutate: func(_ *testing.T, cfg *config.Config, _ *manifest.Manifest) {
|
||||
output := cfg.Pipeline.Notarius.Outputs["npc_registry"]
|
||||
output.SchemaVersion = "v2"
|
||||
output.Filename = "changed.json"
|
||||
cfg.Pipeline.Notarius.Outputs["npc_registry"] = output
|
||||
}},
|
||||
{name: "payload missing", mutate: func(t *testing.T, _ *config.Config, m *manifest.Manifest) {
|
||||
@@ -955,7 +923,7 @@ func TestExtractLifecycleResumesAndRerunsObsoleteResults(t *testing.T) {
|
||||
}
|
||||
}},
|
||||
{name: "record incompatible", mutate: func(_ *testing.T, _ *config.Config, m *manifest.Manifest) {
|
||||
m.Stages["extract"].Outputs[0].Contract.SchemaID = "incompatible"
|
||||
m.Stages["extract"].Outputs[0].ExternalProvenance.ArtifactID = "incompatible"
|
||||
}},
|
||||
} {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -1007,7 +975,7 @@ func TestExtractLifecycleUnsafeResumeErrorPreservesSuccess(t *testing.T) {
|
||||
"analyze": persisted.Stages["analyze"],
|
||||
})
|
||||
|
||||
if _, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env}); err == nil || !strings.Contains(err.Error(), "unsafe") {
|
||||
if _, err := executeStages(context.Background(), cfg, plan, RunOptions{Env: env}); err == nil || !strings.Contains(err.Error(), "canonical destination") {
|
||||
t.Fatalf("executeStages() error = %v, want unsafe resume failure", err)
|
||||
}
|
||||
afterManifest, err := store.Load(context.Background(), first.ManifestPath)
|
||||
@@ -1083,25 +1051,13 @@ func (lifecycleTrimEvidenceStage) Run(_ context.Context, env *stage.Env, m *mani
|
||||
func configureLifecycleReferences(t *testing.T, cfg *config.Config) map[string]string {
|
||||
t.Helper()
|
||||
cfg.Pipeline.Notarius.References = map[string]string{
|
||||
"party": artifactpolicy.SourceInputParty,
|
||||
"players": artifactpolicy.SourceInputPlayers,
|
||||
"glossary": artifactpolicy.SourceInputGlossaryCampaign,
|
||||
"spells": artifactpolicy.SourceInputSpellCatalog,
|
||||
"party": artifactpolicy.SourceInputParty, "players": artifactpolicy.SourceInputPlayers,
|
||||
"glossary": artifactpolicy.SourceInputGlossaryCombined, "spells": artifactpolicy.SourceInputGlossaryCombined,
|
||||
}
|
||||
spellPath := filepath.Join(filepath.Dir(cfg.CampaignPath), "spells.json")
|
||||
if err := os.WriteFile(spellPath, []byte(`{"spells":[]}`+"\n"), 0o644); err != nil {
|
||||
t.Fatalf("WriteFile(spell catalog) error = %v", err)
|
||||
}
|
||||
cfg.StableInputs.SpellCatalogFile = config.ResolvedInputFile{
|
||||
Path: "./spells.json", ConfigPath: cfg.CampaignPath, Source: "campaign_config",
|
||||
}
|
||||
cfg.Session.Inputs.SpellCatalogFile = "./spells.json"
|
||||
|
||||
return map[string]string{
|
||||
artifactpolicy.SourceInputParty: filepath.Join(filepath.Dir(cfg.CampaignPath), "party.yml"),
|
||||
artifactpolicy.SourceInputPlayers: filepath.Join(filepath.Dir(cfg.CampaignPath), "players.yml"),
|
||||
artifactpolicy.SourceInputGlossaryCampaign: filepath.Join(filepath.Dir(cfg.CampaignPath), "glossary.yml"),
|
||||
artifactpolicy.SourceInputSpellCatalog: spellPath,
|
||||
artifactpolicy.SourceInputGlossaryCombined: filepath.Join(filepath.Dir(cfg.CampaignPath), "glossary.yml"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1129,16 +1085,16 @@ func lifecycleReferencePaths(request notarius.RunRequest) map[string]string {
|
||||
|
||||
func lifecycleDndOutputs() map[string]config.NotariusOutputConfig {
|
||||
return 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"},
|
||||
"item_registry": {LaneID: "item-registry"},
|
||||
"npc_registry": {LaneID: "npc-registry"},
|
||||
"location_registry": {LaneID: "location-registry"},
|
||||
"scene_descriptions": {LaneID: "scene-descriptions"},
|
||||
"item_occurrences": {LaneID: "item-occurrences"},
|
||||
"spells": {LaneID: "spells"},
|
||||
"combat_turns": {LaneID: "combat-turns"},
|
||||
"npc_occurrences": {LaneID: "npc-occurrences"},
|
||||
"location_occurrences": {LaneID: "location-occurrences"},
|
||||
"enemy_events": {LaneID: "enemy-events"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1163,8 +1119,7 @@ func extractionLifecycleFixture(t *testing.T, enabled bool) (*config.Config, *st
|
||||
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",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user