test: the instance key survives re-render and travels byte for byte through a move (L21)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+96
−0
internal/appconfig/syncexec_instancekey_test.go+36 −0internal/moves/archive/instancekey_test.go+30 −0internal/moves/envreport_instancekey_test.go+30 −0
CI passed — run details
CI log
=== gate ===
cd launchctx && go vet ./... && go test ./... -count=1
ok amadan.net/carlos/platform.git/launchctx 0.011s
? amadan.net/carlos/platform.git/launchctx/controlname [no test files]
? amadan.net/carlos/platform.git/launchctx/wireid [no test files]
go vet ./...
gofmt -l .: clean
go test ./... -count=1 -timeout 30m
ok github.com/carlosframework/platform 314.850s
? github.com/carlosframework/platform/cmd/changelog [no test files]
ok github.com/carlosframework/platform/cmd/console 2.923s
ok github.com/carlosframework/platform/internal/activator 203.865s
ok github.com/carlosframework/platform/internal/agentsock 0.017s
ok github.com/carlosframework/platform/internal/alerting 0.003s
ok github.com/carlosframework/platform/internal/analytics 0.018s
ok github.com/carlosframework/platform/internal/appconfig 2.204s
ok github.com/carlosframework/platform/internal/apperr 0.070s
ok github.com/carlosframework/platform/internal/applog 0.121s
ok github.com/carlosframework/platform/internal/awsinv 0.004s
ok github.com/carlosframework/platform/internal/boxchoice 0.004s
ok github.com/carlosframework/platform/internal/boxid 0.708s
? github.com/carlosframework/platform/internal/boxid/boxidtest [no test files]
? github.com/carlosframework/platform/internal/boxid/internal/signtest [no test files]
ok github.com/carlosframework/platform/internal/boxvolumes 0.008s
ok github.com/carlosframework/platform/internal/caps 0.011s
ok github.com/carlosframework/platform/internal/certwarm 0.002s
ok github.com/carlosframework/platform/internal/cgroup 0.186s
ok github.com/carlosframework/platform/internal/changelog 0.235s
ok github.com/carlosframework/platform/internal/clamd 0.055s
? github.com/carlosframework/platform/internal/cliflag [no test files]
ok github.com/carlosframework/platform/internal/console 318.711s
? github.com/carlosframework/platform/internal/controlname [no test files]
? github.com/carlosframework/platform/internal/controlsock [no test files]
ok github.com/carlosframework/platform/internal/dbdoor 6.170s
ok github.com/carlosframework/platform/internal/dbdoor/dbdoortest 0.011s
ok github.com/carlosframework/platform/internal/dbverify 0.011s
ok github.com/carlosframework/platform/internal/dnsrec 0.011s
ok github.com/carlosframework/platform/internal/docsite 0.012s
ok github.com/carlosframework/platform/internal/domains 1.976s
ok github.com/carlosframework/platform/internal/doorkey 0.011s
ok github.com/carlosframework/platform/internal/economics 0.011s
ok github.com/carlosframework/platform/internal/edge 25.618s
? github.com/carlosframework/platform/internal/edgeproof [no test files]
ok github.com/carlosframework/platform/internal/edgesfile 0.011s
ok github.com/carlosframework/platform/internal/fleetapi 0.136s
ok github.com/carlosframework/platform/internal/gate 1.656s
ok github.com/carlosframework/platform/internal/genselect 0.021s
ok github.com/carlosframework/platform/internal/geo 0.017s
ok github.com/carlosframework/platform/internal/geoip 0.036s
ok github.com/carlosframework/platform/internal/host 45.160s
ok github.com/carlosframework/platform/internal/hostactors 0.521s
ok github.com/carlosframework/platform/internal/hostbox 1.236s
ok github.com/carlosframework/platform/internal/hostclaim 0.226s
ok github.com/carlosframework/platform/internal/hostevidence 0.019s
ok github.com/carlosframework/platform/internal/hostexec 0.322s
ok github.com/carlosframework/platform/internal/hostfence 0.053s
ok github.com/carlosframework/platform/internal/hostfiles 4.184s
ok github.com/carlosframework/platform/internal/hostfloor 0.023s
ok github.com/carlosframework/platform/internal/hostguard 0.148s
ok github.com/carlosframework/platform/internal/hostops 1.265s
ok github.com/carlosframework/platform/internal/hostquarantine 0.015s
ok github.com/carlosframework/platform/internal/hostresolve 0.129s
ok github.com/carlosframework/platform/internal/hostwrite 0.007s
ok github.com/carlosframework/platform/internal/infraview 0.006s
ok github.com/carlosframework/platform/internal/instancectl 1.707s
ok github.com/carlosframework/platform/internal/instanceexec 2.692s
ok github.com/carlosframework/platform/internal/instancefs 0.007s
ok github.com/carlosframework/platform/internal/instancekey 0.003s
ok github.com/carlosframework/platform/internal/layout 1.335s
ok github.com/carlosframework/platform/internal/lease 9.439s
ok github.com/carlosframework/platform/internal/lease/leasetest 0.009s
ok github.com/carlosframework/platform/internal/ledger 0.014s
ok github.com/carlosframework/platform/internal/mail 0.157s
ok github.com/carlosframework/platform/internal/maintenance 0.077s
ok github.com/carlosframework/platform/internal/maintenanceexec 5.526s
ok github.com/carlosframework/platform/internal/maintenanceguard 0.089s
ok github.com/carlosframework/platform/internal/metrics 0.005s
ok github.com/carlosframework/platform/internal/moves 20.985s
ok github.com/carlosframework/platform/internal/moves/archive 0.756s
ok github.com/carlosframework/platform/internal/objstore 0.168s
ok github.com/carlosframework/platform/internal/ops 0.152s
ok github.com/carlosframework/platform/internal/park 0.191s
ok github.com/carlosframework/platform/internal/privatefile 0.003s
ok github.com/carlosframework/platform/internal/provision 3.031s
ok github.com/carlosframework/platform/internal/publicrelease 0.006s
ok github.com/carlosframework/platform/internal/registry 3.511s
ok github.com/carlosframework/platform/internal/relay 7.227s
ok github.com/carlosframework/platform/internal/release 18.103s
ok github.com/carlosframework/platform/internal/rollout 1.477s
ok github.com/carlosframework/platform/internal/rootaws 0.007s
ok github.com/carlosframework/platform/internal/s3compat 0.005s
ok github.com/carlosframework/platform/internal/safefile 0.004s
ok github.com/carlosframework/platform/internal/schedule 2.207s
ok github.com/carlosframework/platform/internal/sim/hostlife 2.402s
ok github.com/carlosframework/platform/internal/sim/litestreamfacts 3.995s
ok github.com/carlosframework/platform/internal/status 0.036s
ok github.com/carlosframework/platform/internal/steering 0.006s
ok github.com/carlosframework/platform/internal/stopevidence 0.134s
ok github.com/carlosframework/platform/internal/svcrole 0.002s
ok github.com/carlosframework/platform/internal/telemetry 0.004s
ok github.com/carlosframework/platform/internal/termfence 0.004s
ok github.com/carlosframework/platform/internal/tunnelclient 0.004s
ok github.com/carlosframework/platform/internal/unixdial 0.003s
ok github.com/carlosframework/platform/internal/updatewords 0.002s
ok github.com/carlosframework/platform/internal/usage 0.005s
ok github.com/carlosframework/platform/internal/version 0.002s
ok github.com/carlosframework/platform/internal/vet 1.545s
=== cross ===
--- shard 0 of 5 ---
cross-compiling darwin/arm64
--- shard 1 of 5 ---
cross-compiling darwin/amd64
--- shard 2 of 5 ---
cross-compiling linux/arm64
--- shard 3 of 5 ---
cross-compiling windows/amd64
--- shard 4 of 5 ---
cross-compiling windows/arm64
=== minio-contract ===
minio contract: arm64, minio RELEASE.2025-09-07T16-13-09Z, mc RELEASE.2025-08-13T08-35-41Z
minio: cached, digest verified
mc: cached, digest verified
minio healthy on 127.0.0.1:20999
Added `local` successfully.
Bucket created successfully `local/contract-bucket`.
Bucket created successfully `local/denied-bucket`.
Created policy `contract-only` successfully.
Added user `scopeduser` successfully.
Attached Policies: [contract-only]
To User: scopeduser
buckets and scoped user ready
=== RUN TestDeliveredContractMinio
=== RUN TestDeliveredContractMinio/put
=== RUN TestDeliveredContractMinio/get_round-trips_the_body
=== RUN TestDeliveredContractMinio/list_shows_the_key
=== RUN TestDeliveredContractMinio/head_and_list_agree_on_the_version
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict
=== RUN TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed
=== RUN TestDeliveredContractMinio/delete_removes_it
=== RUN TestDeliveredContractMinio/cross-bucket_denial
--- PASS: TestDeliveredContractMinio (0.02s)
--- PASS: TestDeliveredContractMinio/put (0.00s)
--- PASS: TestDeliveredContractMinio/get_round-trips_the_body (0.00s)
--- PASS: TestDeliveredContractMinio/list_shows_the_key (0.00s)
--- PASS: TestDeliveredContractMinio/head_and_list_agree_on_the_version (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/not_by_PutObjectTagging (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_its_own_object/and_not_by_x-amz-tagging_on_upload (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route (0.01s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CreateMultipartUpload (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/not_by_CopyObject_with_a_REPLACE_tagging_directive (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/but_multipart_itself_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_copy_itself_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/a_POST-policy_forged_tag_with_a_matching_version_is_still_not_a_verdict (0.00s)
--- PASS: TestDeliveredContractMinio/the_app_cannot_tag_by_any_other_route/and_an_ordinary_tagged-with-something-else_upload_is_allowed (0.00s)
--- PASS: TestDeliveredContractMinio/delete_removes_it (0.00s)
--- PASS: TestDeliveredContractMinio/cross-bucket_denial (0.00s)
PASS
ok github.com/carlosframework/platform/internal/objstore 0.022s
=== RUN TestT4StorageProbeMinio
2026/10/11 17:41:33 moves: T4: STORE: list: operation error S3: ListObjectsV2, https response error StatusCode: 403, RequestID: 18DD8A7C690F9ABF, HostID: 7c420053e0fbcd7f41653fdd92ffa2802c903d05303b1aa15adc2e8bb65d183f, api error SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method.
--- PASS: TestT4StorageProbeMinio (0.01s)
PASS
ok github.com/carlosframework/platform/internal/host 0.015s
minio contract: PASS
diff --git a/internal/appconfig/syncexec_instancekey_test.go b/internal/appconfig/syncexec_instancekey_test.go| new file mode 100644 |
| index 000000000..cabb16f72 |
| --- /dev/null |
| +++ b/internal/appconfig/syncexec_instancekey_test.go |
| @@ -0,0 +1,36 @@ |
| +package appconfig |
| + |
| +import ( |
| + "os" |
| + "path/filepath" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// A re-render never touches the instance's own env file, so the key minted |
| +// there survives every config change, including one that sets the same |
| +// name in the app's configuration (L21, never overwrite: re-render). |
| +func TestSyncExecLeavesTheInstanceKeyAlone(t *testing.T) { |
| + ctx, s, reg, dd, priv, _ := execKit(t) |
| + pk, _ := ParsePrivateKey(priv, "test") |
| + own := filepath.Join(dd, "shop.example.com.env") |
| + body := []byte("CARLOS_ADMIN_TOKEN=tok\nCARLOS_INSTANCE_KEY=q+/Zk3vJ0aW1Yx9sR7tUe2oPl4mN8bC6dF5gH0iJ1kA=\n") |
| + if err := os.WriteFile(own, body, 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.Upsert(registry.Route{Host: "shop.example.com", Kind: "instance", App: "shop", Account: "acct", Status: "ready", Socket: "/run/carlos/shop.sock"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, vars := range []map[string]string{{"A": "1"}, {"A": "2", "CARLOS_INSTANCE_KEY": "from-config"}} { |
| + if err := SetEnv(ctx, s, "acct", "shop", vars); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := SyncExec(ctx, reg, s, pk, dd, func(string) error { return nil }, "", nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got, _ := os.ReadFile(own); string(got) != string(body) { |
| + t.Fatalf("a re-render changed the instance's own env file: %q", got) |
| + } |
| + } |
| +} |
diff --git a/internal/moves/archive/instancekey_test.go b/internal/moves/archive/instancekey_test.go| new file mode 100644 |
| index 000000000..1f7abb192 |
| --- /dev/null |
| +++ b/internal/moves/archive/instancekey_test.go |
| @@ -0,0 +1,30 @@ |
| +package archive |
| + |
| +import ( |
| + "bytes" |
| + "os" |
| + "path/filepath" |
| + "testing" |
| +) |
| + |
| +// The move archive carries <host>.env byte for byte, so the instance key |
| +// lands on the target exactly as the source minted it (L21: the key is the |
| +// exact bytes the env file yields). |
| +func TestArchiveCarriesTheInstanceKeyByteForByte(t *testing.T) { |
| + dir, env := filesFixture(t) |
| + body := []byte("CARLOS_ADMIN_TOKEN=t\nCARLOS_INSTANCE_KEY=q+/Zk3vJ0aW1Yx9sR7tUe2oPl4mN8bC6dF5gH0iJ1kA=\n") |
| + mustWrite(t, env, body, 0o600) |
| + var built bytes.Buffer |
| + if _, _, _, err := Build(dir, env, &built); err != nil { |
| + t.Fatal(err) |
| + } |
| + out := filepath.Join(t.TempDir(), "out") |
| + outEnv := filepath.Join(t.TempDir(), "out.env") |
| + if err := Extract(bytes.NewReader(built.Bytes()), out, outEnv); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, err := os.ReadFile(outEnv) |
| + if err != nil || !bytes.Equal(got, body) { |
| + t.Fatalf("extracted env differs from the source's (err %v)", err) |
| + } |
| +} |
diff --git a/internal/moves/envreport_instancekey_test.go b/internal/moves/envreport_instancekey_test.go| new file mode 100644 |
| index 000000000..141a19e0d |
| --- /dev/null |
| +++ b/internal/moves/envreport_instancekey_test.go |
| @@ -0,0 +1,30 @@ |
| +package moves |
| + |
| +import "testing" |
| + |
| +// A move compares the instance key like any instance variable: a target |
| +// that would start with a different key, or none, is a difference the |
| +// launch check reports, never a note (L21). |
| +func TestEnvReportComparesTheInstanceKey(t *testing.T) { |
| + const name = "CARLOS_INSTANCE_KEY" |
| + if got := Class(name); got != "equal" { |
| + t.Fatalf("Class(%s) = %q, want equal", name, got) |
| + } |
| + key := []byte("0123456789abcdef0123456789abcdef") |
| + src := ReportEnv(key, map[string]string{name: "a2V5LW9uZQ==", "CARLOS_REGION": "ie"}) |
| + for _, tc := range []struct { |
| + target map[string]string |
| + want string |
| + }{ |
| + {map[string]string{name: "a2V5LXR3bw==", "CARLOS_REGION": "uk"}, "differs"}, |
| + {map[string]string{"CARLOS_REGION": "uk"}, "missing"}, |
| + } { |
| + diffs := CompareEnv(src, ReportEnv(key, tc.target), false) |
| + if len(diffs) != 1 || diffs[0].Name != name || diffs[0].Kind != tc.want || diffs[0].Note() { |
| + t.Fatalf("diffs = %+v, want one %s on %s", diffs, tc.want, name) |
| + } |
| + } |
| + if diffs := CompareEnv(src, ReportEnv(key, map[string]string{name: "a2V5LW9uZQ==", "CARLOS_REGION": "uk"}), false); len(diffs) != 0 { |
| + t.Fatalf("the same key reported a difference: %+v", diffs) |
| + } |
| +} |