activator: test that an empty own instance key neither overrides the configured key nor reports it as shadowed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+32
−0
internal/activator/backend_exec_test.go+32 −0
diff --git a/internal/activator/backend_exec_test.go b/internal/activator/backend_exec_test.go| index 8d86084f4..37bd8d8e0 100644 |
| --- a/internal/activator/backend_exec_test.go |
| +++ b/internal/activator/backend_exec_test.go |
| @@ -400,6 +400,38 @@ func TestLaunchEnvironmentComposesTheSpawnEnvironment(t *testing.T) { |
| } |
| } |
| +// An empty CARLOS_INSTANCE_KEY in the instance's own file supplies no key |
| +// (instance-key plan ruling 13): the merge keeps the configured key, and |
| +// the launch report does not list the empty one as shadowing it. A |
| +// non-empty own key still wins and is still reported. |
| +func TestEmptyOwnInstanceKeyShadowsNothing(t *testing.T) { |
| + cfg := map[string]string{"CARLOS_INSTANCE_KEY": "cfg"} |
| + if got := mergeEnv(cfg, map[string]string{"CARLOS_INSTANCE_KEY": ""}); got["CARLOS_INSTANCE_KEY"] != "cfg" { |
| + t.Fatalf("mergeEnv with an empty own key: CARLOS_INSTANCE_KEY = %q, want the configured key", got["CARLOS_INSTANCE_KEY"]) |
| + } |
| + b := &ExecBackend{DataDir: t.TempDir(), Region: "ie"} |
| + rt := registry.Route{Host: "k.go.example.com", Socket: filepath.Join(b.DataDir, "k.sock")} |
| + write := func(name, body string) { |
| + t.Helper() |
| + if err := os.WriteFile(filepath.Join(b.DataDir, rt.Host+name), []byte(body), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + write(".config.env", "CARLOS_INSTANCE_KEY=cfg\nMINE=0\n") |
| + write(".env", "CARLOS_INSTANCE_KEY=\nMINE=1\n") |
| + env, shadowed, err := b.LaunchEnvironment(rt) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if env["CARLOS_INSTANCE_KEY"] != "cfg" || len(shadowed) != 1 || shadowed[0] != "MINE" { |
| + t.Fatalf("empty own key: CARLOS_INSTANCE_KEY is the configured key: %v; shadowed %v, want [MINE]", env["CARLOS_INSTANCE_KEY"] == "cfg", shadowed) |
| + } |
| + write(".env", "CARLOS_INSTANCE_KEY=own\nMINE=1\n") |
| + if env, shadowed, err = b.LaunchEnvironment(rt); err != nil || env["CARLOS_INSTANCE_KEY"] != "own" || len(shadowed) != 2 { |
| + t.Fatalf("non-empty own key: CARLOS_INSTANCE_KEY is the own key: %v; shadowed %v; err %v", env["CARLOS_INSTANCE_KEY"] == "own", shadowed, err) |
| + } |
| +} |
| + |
| // With neither file present the composition is the agent-owned layer over |
| // the agent's own environment, no error and nothing shadowed. |
| func TestLaunchEnvironmentNoFiles(t *testing.T) { |