Use canonical source identities in publication reports
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -224,3 +225,43 @@ func TestSessionStateCommandsLeaveManifestUnchanged(t *testing.T) {
|
||||
t.Fatal("inspection mutated remote state or downloaded payloads")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishedOutputInspectionNormalizesAcceptedSources(t *testing.T) {
|
||||
const canonical = "narratio.transcript.final_trimmed"
|
||||
for _, source := range []string{canonical, " " + canonical + " "} {
|
||||
t.Run(source, func(t *testing.T) {
|
||||
pipeline, campaign, session := writeValidConfigFiles(t, t.TempDir())
|
||||
addPublishOutputsToPipeline(t, pipeline, " outputs:\n - source: \""+source+"\"\n dest: transcripts/full.json\n")
|
||||
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := config.Validate(cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
actions, err := stage.PlanPublicationOutputs(nil, cfg.PublicationOutputs(), nil)
|
||||
if err != nil || len(actions) != 1 || actions[0].Source != canonical {
|
||||
t.Fatalf("publication actions=%#v err=%v", actions, err)
|
||||
}
|
||||
fake := &storage.FakeBackend{}
|
||||
current := seedCommittedRestoreSnapshot(t, cfg, fake, "20260519T010203Z-a1b2c3d4", map[string][]byte{"transcripts/full.json": []byte("published\n")})
|
||||
declaration := ¤t.Commit.Artifacts[1]
|
||||
declaration.Source = canonical
|
||||
current.Manifest.Stages["publish"] = &manifest.StageRecord{
|
||||
Name: "publish", Status: manifest.StatusSucceeded,
|
||||
Metadata: map[string]any{"publish_output_outcomes": []any{map[string]any{"source": canonical, "status": "carried_locked"}}},
|
||||
}
|
||||
outputs, err := inspectPublishedOutputs(context.Background(), cfg, fake, nil, current, []artifacts.RemoteLock{{Source: canonical}}, true, "current")
|
||||
if err != nil || len(outputs) != 1 {
|
||||
t.Fatalf("outputs=%#v err=%v", outputs, err)
|
||||
}
|
||||
output := outputs[0]
|
||||
if output.Source != canonical || output.State != "published" || output.LockState != "locked" || output.Outcome != "carried_locked" || output.DeclaredKey != declaration.DestinationKey || output.OriginRun != current.RunID {
|
||||
t.Fatalf("accepted source lost publication evidence: %#v", output)
|
||||
}
|
||||
if cfg.PublicationOutputs()[0].Source != source {
|
||||
t.Fatal("inspection mutated the source declaration")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,9 +261,10 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor
|
||||
}
|
||||
var resultErr error
|
||||
for _, rule := range rules {
|
||||
destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(strings.TrimSpace(rule.Source), rule.Dest, configuredOutputs, extractionOutputs)
|
||||
_, isLocked := locked[rule.Source]
|
||||
output := sessionPublishedOutput{Source: rule.Source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[rule.Source]}
|
||||
source := strings.TrimSpace(rule.Source)
|
||||
destination, err := artifactpolicy.ResolvePublishedDestinationWithExtractions(source, rule.Dest, configuredOutputs, extractionOutputs)
|
||||
_, isLocked := locked[source]
|
||||
output := sessionPublishedOutput{Source: source, Destination: destination, Required: rule.Required == nil || *rule.Required, LockState: "unknown", State: "missing", Outcome: outcomes[source]}
|
||||
if locksKnown {
|
||||
output.LockState = "unlocked"
|
||||
if isLocked {
|
||||
@@ -274,7 +275,7 @@ func inspectPublishedOutputs(ctx context.Context, cfg *config.Config, store stor
|
||||
output.State = "error"
|
||||
}
|
||||
if err == nil && current != nil && current.Commit != nil {
|
||||
if declaration, ok := declarations[rule.Source]; ok {
|
||||
if declaration, ok := declarations[source]; ok {
|
||||
identity, identityErr := artifacts.ParsePublishedOutputObjectKey(current.SessionPrefix, declaration.DestinationKey)
|
||||
if identityErr != nil {
|
||||
err = identityErr
|
||||
|
||||
Reference in New Issue
Block a user