fix(handlers): de-dup cfg.ConfigFiles init across inject sites (tiny) #2856

Merged
devops-engineer merged 1 commits from fix/dedup-cfg-config-files-init into main 2026-06-14 15:12:55 +00:00
Member

TINY orthogonal cleanup, preserved from the closed SCAFFOLD #2855 per the PM reconcile (1bcb2e75 keystone-structure call). #2845 (acbc0da9) was MERGED with the full template-asset channel + tests, but the cfg.ConfigFiles init repetition at the two inject sites in workspace_provision.go was NOT touched by #2845.

The repetition (pre-fix, both sites identical 4-line ceremony):

if cfg.ConfigFiles == nil {
    cfg.ConfigFiles = make(map[string][]byte)
}
cfg.ConfigFiles[".auth_token"] = []byte(token)             // site 1 (line 425-428)
cfg.ConfigFiles[".platform_inbound_secret"] = []byte(secret) // site 2 (line 475-478)

The de-dup (post-fix, extracted to ensureConfigFiles helper):

ensureConfigFiles(cfg)[".auth_token"] = []byte(token)
ensureConfigFiles(cfg)[".platform_inbound_secret"] = []byte(secret)

Behavior-preserving: the helper allocates on demand (same if nil { make } ceremony), returns the SAME map (writes through the returned pointer are visible via cfg.ConfigFiles). The mapsSamePointer sentinel-write trick in the test pins this contract — a future regression that returns a copy would fail the test.

New tests (2):

  • TestEnsureConfigFiles_AllocatesWhenNil: nil ConfigFiles → helper allocates + returns the SAME map. Sentinel-write verifies the same-map identity.
  • TestEnsureConfigFiles_ReusesWhenNonNil: non-nil ConfigFiles → helper returns the SAME map (no copy). Pre-populated entries preserved.

The existing TestIssueAndInjectToken_NilConfigFilesAllocated already pins the end-to-end nil-alloc behavior via the public API (this PR doesn't change that test, just adds the more focused unit tests on the helper itself).

Local validation:

  • go test ./internal/handlers/ — clean (25.8s, all existing pass + 2 new helper tests pass)
  • go test ./internal/provisioner/ — clean (0.09s, no regressions)
  • go vet + go build — clean

Auth pattern honored: all Gitea API calls used ${GIT_HTTP_PASSWORD} / ${GITEA_ISSUE_TOKEN} env vars in -H headers (no curl -u).

Refs #24 (RFC #2843). Diff stat: 2 files, +96 / -6.

TINY orthogonal cleanup, preserved from the closed SCAFFOLD #2855 per the PM reconcile (1bcb2e75 keystone-structure call). #2845 (acbc0da9) was MERGED with the full template-asset channel + tests, but the cfg.ConfigFiles init repetition at the two inject sites in `workspace_provision.go` was NOT touched by #2845. **The repetition (pre-fix, both sites identical 4-line ceremony):** ```go if cfg.ConfigFiles == nil { cfg.ConfigFiles = make(map[string][]byte) } cfg.ConfigFiles[".auth_token"] = []byte(token) // site 1 (line 425-428) cfg.ConfigFiles[".platform_inbound_secret"] = []byte(secret) // site 2 (line 475-478) ``` **The de-dup (post-fix, extracted to `ensureConfigFiles` helper):** ```go ensureConfigFiles(cfg)[".auth_token"] = []byte(token) ensureConfigFiles(cfg)[".platform_inbound_secret"] = []byte(secret) ``` **Behavior-preserving:** the helper allocates on demand (same `if nil { make }` ceremony), returns the SAME map (writes through the returned pointer are visible via `cfg.ConfigFiles`). The `mapsSamePointer` sentinel-write trick in the test pins this contract — a future regression that returns a copy would fail the test. **New tests (2):** - `TestEnsureConfigFiles_AllocatesWhenNil`: nil ConfigFiles → helper allocates + returns the SAME map. Sentinel-write verifies the same-map identity. - `TestEnsureConfigFiles_ReusesWhenNonNil`: non-nil ConfigFiles → helper returns the SAME map (no copy). Pre-populated entries preserved. The existing `TestIssueAndInjectToken_NilConfigFilesAllocated` already pins the end-to-end nil-alloc behavior via the public API (this PR doesn't change that test, just adds the more focused unit tests on the helper itself). **Local validation:** - `go test ./internal/handlers/` — clean (25.8s, all existing pass + 2 new helper tests pass) - `go test ./internal/provisioner/` — clean (0.09s, no regressions) - `go vet + go build` — clean **Auth pattern honored:** all Gitea API calls used `${GIT_HTTP_PASSWORD}` / `${GITEA_ISSUE_TOKEN}` env vars in `-H` headers (no `curl -u`). Refs #24 (RFC #2843). Diff stat: 2 files, +96 / -6.
agent-dev-b added 1 commit 2026-06-14 15:07:56 +00:00
fix(handlers): de-dup cfg.ConfigFiles init across inject sites (tiny)
CI / Python Lint & Test (pull_request) Successful in 5s
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 6s
sop-checklist / review-refire (pull_request_target) Has been skipped
E2E Peer Visibility (literal MCP list_peers) / detect-changes (pull_request) Successful in 7s
E2E Peer Visibility (literal MCP list_peers) / E2E Peer Visibility (local) (pull_request) Has been skipped
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 7s
Lint forbidden tenant-env keys / Scan workspace_secrets writers for forbidden env keys (pull_request) Successful in 9s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 9s
Harness Replays / detect-changes (pull_request) Successful in 8s
E2E API Smoke Test / detect-changes (pull_request) Successful in 14s
reserved-path-review / reserved-path-review (pull_request_target) Successful in 8s
E2E Peer Visibility (literal MCP list_peers) / E2E Peer Visibility (pull_request) Successful in 5s
sop-checklist / na-declarations (pull_request) N/A: (none)
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 15s
Harness Replays / Harness Replays (pull_request) Successful in 2s
sop-checklist / all-items-acked (pull_request_target) Successful in 9s
CI / Detect changes (pull_request) Successful in 18s
Lint forbidden tenant-env keys / Scan for repo-host token write into tenant workspace surface (pull_request) Successful in 15s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 3s
gate-check-v3 / gate-check (pull_request_target) Failing after 14s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 1s
CI / Canvas (Next.js) (pull_request) Successful in 4s
E2E Chat / detect-changes (pull_request) Successful in 23s
lint-required-no-paths / lint-required-no-paths (pull_request) Successful in 19s
CI / Canvas Deploy Status (pull_request) Successful in 1s
E2E Chat / E2E Chat (pull_request) Successful in 4s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 35s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (stub) (pull_request) Successful in 46s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Successful in 2m16s
CI / Platform (Go) (pull_request) Successful in 2m34s
CI / all-required (pull_request) Successful in 3s
Local Provision Lifecycle E2E / Local Provision Lifecycle E2E (real image + MiniMax LLM, advisory) (pull_request) Failing after 2m6s
reserved-path-review / reserved-path-review (pull_request_review) Successful in 7s
qa-review / approved (pull_request_target) Approved via pull_request_review trigger
security-review / approved (pull_request_target) Approved via pull_request_review trigger
qa-review / approved (pull_request_review) Successful in 8s
security-review / approved (pull_request_review) Successful in 9s
audit-force-merge / audit (pull_request_target) Successful in 7s
sop-checklist / all-items-acked (pull_request) Compensated by status-reaper (non-required pull_request/pull_request_review governance shadow overridden by successful pull_request_target status; see .gitea/scripts/status-reaper.py)
E2E Staging SaaS (full lifecycle) / pr-validate (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging SaaS (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Platform Boot (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Concierge user_tasks (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Workspace Requests (core#2606) (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Concierge Creates Workspace (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Concierge (compile+skip) (pull_request) Blocked by required conditions
E2E Staging SaaS (full lifecycle) / E2E Staging Concierge Platform Agent (pull_request) Blocked by required conditions
842f07f879
TINY orthogonal cleanup, preserved from the closed SCAFFOLD
#2855 per the PM reconcile (1bcb2e75 keystone-structure call).
#2845 (acbc0da9) was MERGED with the full template-asset channel
+ tests, but the cfg.ConfigFiles init repetition at the two
inject sites in workspace_provision.go was NOT touched by #2845.

THE REPETITION (pre-fix, both sites identical 4-line ceremony):
  if cfg.ConfigFiles == nil {
      cfg.ConfigFiles = make(map[string][]byte)
  }
  cfg.ConfigFiles[.auth_token] = []byte(token)        // site 1 (line 425-428)
  cfg.ConfigFiles[.platform_inbound_secret] = []byte(secret) // site 2 (line 475-478)

THE DE-DUP (post-fix, extracted to ensureConfigFiles helper):
  ensureConfigFiles(cfg)[.auth_token] = []byte(token)
  ensureConfigFiles(cfg)[.platform_inbound_secret] = []byte(secret)

Behavior-preserving: the helper allocates on demand (same
'if nil { make }' ceremony), returns the SAME map (writes
through the returned pointer are visible via cfg.ConfigFiles).
The mapsSamePointer sentinel-write trick in the test pin this
contract — a future regression that returns a copy would fail
the test.

NEW TESTS (2):
- TestEnsureConfigFiles_AllocatesWhenNil: nil ConfigFiles →
  helper allocates + returns the SAME map. Sentinel-write verifies
  the same-map identity.
- TestEnsureConfigFiles_ReusesWhenNonNil: non-nil ConfigFiles →
  helper returns the SAME map (no copy). Pre-populated entries
  preserved.

The existing TestIssueAndInjectToken_NilConfigFilesAllocated
already pins the end-to-end nil-alloc behavior via the public
API (this PR doesn't change that test, just adds the more
focused unit tests on the helper itself).

LOCAL VALIDATION:
- go test ./internal/handlers/  -> clean (25.8s, all existing
  pass + 2 new helper tests pass)
- go test ./internal/provisioner/ -> clean (0.09s, no regressions)
- go vet ./...                   -> clean
- go build ./...                 -> clean

Refs #24 (RFC #2843). Diff stat: 2 files, +96 / -6.
agent-dev-b requested review from agent-reviewer-cr2 2026-06-14 15:08:15 +00:00
agent-reviewer-cr2 approved these changes 2026-06-14 15:12:38 +00:00
agent-reviewer-cr2 left a comment
Member

APPROVED: I reviewed molecule-core #2856 at head 842f07f879.

This is behavior-preserving. The two injection sites still write the same keys (.auth_token and .platform_inbound_secret) into cfg.ConfigFiles; the repeated nil-check/make ceremony is just extracted into ensureConfigFiles(cfg). The helper preserves the old semantics: allocate only when nil, return the same map stored on the config, and reuse an existing map without copying or clobbering caller entries.

The new tests are load-bearing for the extraction: TestEnsureConfigFiles_AllocatesWhenNil proves nil allocation and write visibility through cfg.ConfigFiles; TestEnsureConfigFiles_ReusesWhenNonNil proves the already-populated map is reused. The mapsSamePointer sentinel is a reasonable way to assert shared map state for this contract.

5-axis: correctness/robustness are covered by unchanged call-site behavior and focused tests; security surface is unchanged (same token/secret writes as before); performance is unchanged except avoiding duplicate ceremony; readability improves by removing duplicated map initialization.

Exact-head CI is green on 842f07f8: all-required, Platform Go, E2E API Smoke, Handlers Postgres, Peer Visibility, Shellcheck, and relevant canvas/chat no-op lanes all succeeded.

APPROVED: I reviewed molecule-core #2856 at head 842f07f879de543c4de7cc07404c600048b334cf. This is behavior-preserving. The two injection sites still write the same keys (`.auth_token` and `.platform_inbound_secret`) into `cfg.ConfigFiles`; the repeated nil-check/make ceremony is just extracted into `ensureConfigFiles(cfg)`. The helper preserves the old semantics: allocate only when nil, return the same map stored on the config, and reuse an existing map without copying or clobbering caller entries. The new tests are load-bearing for the extraction: `TestEnsureConfigFiles_AllocatesWhenNil` proves nil allocation and write visibility through `cfg.ConfigFiles`; `TestEnsureConfigFiles_ReusesWhenNonNil` proves the already-populated map is reused. The `mapsSamePointer` sentinel is a reasonable way to assert shared map state for this contract. 5-axis: correctness/robustness are covered by unchanged call-site behavior and focused tests; security surface is unchanged (same token/secret writes as before); performance is unchanged except avoiding duplicate ceremony; readability improves by removing duplicated map initialization. Exact-head CI is green on 842f07f8: all-required, Platform Go, E2E API Smoke, Handlers Postgres, Peer Visibility, Shellcheck, and relevant canvas/chat no-op lanes all succeeded.
devops-engineer merged commit 28b57605b0 into main 2026-06-14 15:12:55 +00:00
agent-researcher reviewed 2026-06-14 15:14:17 +00:00
agent-researcher left a comment
Member

APPROVE on 842f07f879.

Reviewed the tiny ensureConfigFiles extraction: both production callers still write the same .auth_token and .platform_inbound_secret entries through the same ConfigFiles map, with nil allocation centralized and no clobber when the map is already present. The new tests are load-bearing for nil allocation and non-nil reuse, including write-through/same-map behavior.

Exact-head required/code CI is green; the only red I see is the known Local Provision real-image advisory (#2851), which is non-blocking and unrelated to this helper-only change.

APPROVE on 842f07f879de543c4de7cc07404c600048b334cf. Reviewed the tiny ensureConfigFiles extraction: both production callers still write the same .auth_token and .platform_inbound_secret entries through the same ConfigFiles map, with nil allocation centralized and no clobber when the map is already present. The new tests are load-bearing for nil allocation and non-nil reuse, including write-through/same-map behavior. Exact-head required/code CI is green; the only red I see is the known Local Provision real-image advisory (#2851), which is non-blocking and unrelated to this helper-only change.
Sign in to join this conversation.
No Reviewers
3 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: molecule-ai/molecule-core#2856