From abaa3c78df38c37c8f461a7d218f9fc6d99bf8bd Mon Sep 17 00:00:00 2001 From: Eric Rakestraw Date: Mon, 23 Nov 2026 17:24:16 +0000 Subject: [PATCH] Make the pure loader regression test detect bootstrap --- docs/roadmap/remediation.md | 20 ++++++++++++++------ internal/config/pipeline_discovery_test.go | 9 ++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 42fcd41..ea3f953 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -5,17 +5,25 @@ Reviewed all ten implementation stages against committed baseline ## 1. Make the pure-loader regression test detect accidental bootstrap -Status: pending. Priority: P2. Implementation stages: 2 and 6. +Status: completed. Priority: P2. Implementation stages: 2 and 6. + +Completion: the test registers restoration of the original environment state, +unsets the variable, and uses `LookupEnv` to verify that pure loading leaves it +absent. Explicit bootstrap provides a positive control before the retained +prepared-source handoff assertions. The focused test passes normally and fails +at the purity assertion with bootstrap inserted through a temporary build +overlay. Full tests and configuration-package race tests pass. Production +loading behavior is unchanged. Location: [pipeline_discovery_test.go](../../internal/config/pipeline_discovery_test.go#L99), `TestPipelineSourceRetainsPreparedMainAndPureLoading`. -The test sets its credential variable to an empty string before calling the -ordinary library loader. ConfigKit's default bootstrap preserves existing +The original test set its credential variable to an empty string before calling +the ordinary library loader. ConfigKit's default bootstrap preserves existing variables, including empty ones. Consequently, the environment assertion still -passes if bootstrap is accidentally introduced into `LoadPipelineWithOptions`. -This is the only configuration-package test declaring a secrets directory, so -the intended guard against library-owned environment mutation is ineffective. +passed with bootstrap accidentally introduced into `LoadPipelineWithOptions`. +This was the only configuration-package test declaring a secrets directory, so +the intended guard against library-owned environment mutation was ineffective. Confirmed with a temporary Go build overlay that inserted an actual `LoadSecretsIntoEnvironmentFromConfig` call into `LoadPipelineWithOptions`: diff --git a/internal/config/pipeline_discovery_test.go b/internal/config/pipeline_discovery_test.go index 431849c..cad11cf 100644 --- a/internal/config/pipeline_discovery_test.go +++ b/internal/config/pipeline_discovery_test.go @@ -96,7 +96,11 @@ func TestPipelineSourceRetainsPreparedMainAndPureLoading(t *testing.T) { t.Fatal(err) } const name = "NARRATIO_SOURCE_HANDOFF_TEST" + // Register cleanup for the original value and presence before unsetting it. t.Setenv(name, "") + if err := os.Unsetenv(name); err != nil { + t.Fatal(err) + } if err := os.WriteFile(filepath.Join(secretDir, name), []byte("synthetic-secret"), 0600); err != nil { t.Fatal(err) } @@ -107,13 +111,16 @@ func TestPipelineSourceRetainsPreparedMainAndPureLoading(t *testing.T) { if _, err := LoadPipelineWithOptions(path, PipelineLoadOptions{}); err != nil { t.Fatal(err) } - if got := os.Getenv(name); got != "" { + if _, present := os.LookupEnv(name); present { t.Fatal("pure loading changed environment") } _, prepared, err := configkit.LoadSecretsIntoEnvironmentFromConfig(PipelineSource(path, PipelineLoadOptions{})) if err != nil { t.Fatal(err) } + if got := os.Getenv(name); got != "synthetic-secret" { + t.Fatal("explicit bootstrap did not populate the test credential") + } if err := os.WriteFile(path, []byte("invalid: ["), 0600); err != nil { t.Fatal(err) }