@@ -101,7 +101,7 @@ func TestCloudSmokeGCPApplyRequiresCanonicalRunID(t *testing.T) {
101101 driverPath := filepath .Join (root , "ci/cloud-smoke.sh" )
102102 driver := readRepositoryFile (t , root , "ci/cloud-smoke.sh" )
103103
104- validation := `gcp_run_namespace "$target" "$run_id" >/dev/null `
104+ validation := `run_namespace="$( gcp_run_namespace "$target" "$run_id")" `
105105 validationIndex := strings .Index (driver , validation )
106106 argumentsIndex := strings .Index (driver , `mapfile -d '' -t var_args < <(target_var_args` )
107107 applyIndex := strings .Index (driver , `terraform -chdir="$root" apply` )
@@ -138,6 +138,44 @@ func TestCloudSmokeGCPApplyRequiresCanonicalRunID(t *testing.T) {
138138 }
139139}
140140
141+ func TestCloudSmokeGCPWriterUsesExactRunNamespace (t * testing.T ) {
142+ t .Parallel ()
143+ root := repositoryRoot (t )
144+ driver := readRepositoryFile (t , root , "ci/cloud-smoke.sh" )
145+ gcpVariables := readRepositoryFile (t , root , "tests/smoke/gcp/variables.tf" )
146+ gcpFixture := readRepositoryFile (t , root , "tests/smoke/gcp/main.tf" )
147+ contextVariables := readRepositoryFile (t , root , "tests/smoke/modules/context/variables.tf" )
148+ contextFixture := readRepositoryFile (t , root , "tests/smoke/modules/context/main.tf" )
149+
150+ for label , marker := range map [string ]string {
151+ "compiled namespace command" : `"$runner" gcp namespace --run-id "$run_id"` ,
152+ "captured raw run ID" : `run_id="$(smoke_run_id)"` ,
153+ "captured exact namespace" : `run_namespace="$(gcp_run_namespace "$target" "$run_id")"` ,
154+ "raw Terraform input" : `"smoke_run_id=${run_id}"` ,
155+ "exact Terraform input" : `"smoke_run_namespace=${run_namespace}"` ,
156+ "raw cleanup ownership" : `provider_tag_cleanup "$target" "$run_id"` ,
157+ } {
158+ requireContains (t , driver , marker , label )
159+ }
160+
161+ namespaceIndex := strings .Index (driver , `run_namespace="$(gcp_run_namespace "$target" "$run_id")"` )
162+ argumentsIndex := strings .Index (driver , `mapfile -d '' -t var_args < <(target_var_args` )
163+ if namespaceIndex < 0 || argumentsIndex < 0 || namespaceIndex >= argumentsIndex {
164+ t .Fatal ("fresh GCP smoke does not validate its exact namespace before Terraform argument process substitution" )
165+ }
166+
167+ for label , text := range map [string ]string {
168+ "GCP root variables" : gcpVariables ,
169+ "context variables" : contextVariables ,
170+ "GCP context plumbing" : gcpFixture ,
171+ "context naming decision" : contextFixture ,
172+ } {
173+ requireContains (t , text , "smoke_run_namespace" , label )
174+ }
175+ requireContains (t , contextFixture , `local.cloud_provider == "gcp" ? var.smoke_run_namespace : ""` , "GCP-only exact namespace selection" )
176+ requireContains (t , contextFixture , `local.smoke_run_id != "" ? "gha-run-${local.smoke_run_id}" : ""` , "legacy run-id cleanup tag" )
177+ }
178+
141179func TestCloudSmokeGCPWrapperFailsClosedWithoutRunID (t * testing.T ) {
142180 t .Parallel ()
143181 root := repositoryRoot (t )
0 commit comments