package config import ( "os" "strings" "testing" ) func TestPipelineMaterializationPreservesFinalValuesWithoutResolvingCredentialsAgain(t *testing.T) { const name = "NARRATIO_SNAPSHOT_TEST_KEY" const secret = "synthetic-snapshot-secret" t.Setenv(name, secret) path := writePipelineFixture(t, t.TempDir(), "pipeline.yml", `audita: credentials: [NARRATIO_SNAPSHOT_TEST_KEY] scriptorium: artifact_families: character_notes: enabled: false for_each: party.characters output_path_pattern: artifacts/{character_id}.md artifacts: recap: vars: exact: 9007199254740993 nothing: null empty: [] `) cfg, err := LoadPipeline(path) if err != nil { t.Fatal(err) } if err := os.Unsetenv(name); err != nil { t.Fatal(err) } if err := recomputePipelineEffectiveDigest(cfg); err != nil { t.Fatalf("snapshot resolved credentials again: %v", err) } data, err := MarshalEffectivePipeline(cfg) if err != nil { t.Fatal(err) } for _, expected := range []string{name, "9007199254740993", "nothing: null", "empty: []", "character_notes:", "artifact_families:"} { if !strings.Contains(string(data), expected) { t.Fatalf("snapshot missing %q: %s", expected, data) } } if strings.Contains(string(data), secret) { t.Fatal("snapshot exposed resolved credential") } } func TestPipelineMaterializationKeepsEmptyCredentialListDistinctFromNull(t *testing.T) { dir := t.TempDir() nullPath := writePipelineFixture(t, dir, "null.yml", "audita: {credentials: null}\n") emptyPath := writePipelineFixture(t, dir, "empty.yml", "audita: {credentials: []}\n") nullConfig, err := LoadPipeline(nullPath) if err != nil { t.Fatal(err) } emptyConfig, err := LoadPipeline(emptyPath) if err != nil { t.Fatal(err) } if EffectivePipelineDigest(nullConfig) == EffectivePipelineDigest(emptyConfig) { t.Fatal("null and empty credentials have the same digest") } }