sandcastle: Go pre-push gate needs a supported per-repo override (layout/toolchain differ downstream) #126

Closed
opened 2026-09-03 21:17:37 +00:00 by ben · 3 comments
Owner

.sandcastle/gate-lib.sh (#198) hard-codes OurCloud's layout in gate_go_default_cmd: nix develop "$root#go-ci", a root-level Go module, and a broker/ module. A downstream repo that vendors the gate (FACTORY_MANIFEST / ADR 0180) but has no flake and a different module layout cannot satisfy it on ANY host, and cannot edit the vendored file without tripping the drift gate. The only escape is the GATE_GO_CMD env var, which the comments describe as a test seam.

Observed in matou-app (Matou/matou-app#346, downstream fix PR + sweep Matou/matou-app#349): its module is backend/, no flake.nix, toolchain pinned in the sandbox Dockerfile (Go 1.25.5 — beyond nixpkgs 24.11's go_1_23 anyway). A completed Go slice (#166) was stranded unpushed until a human recovered it. Interim downstream fix: the Dockerfile sets ENV GATE_GO_CMD="bash .sandcastle/go-gate.sh" (repo-local script) and documents it as the sanctioned gate.

Ask: make the Go stage command a supported per-repo override instead of a test-only seam — e.g. gate_go_stage sources .sandcastle/gate.conf (NOT in FACTORY_MANIFEST) when present, or honours a .sandcastle/go-gate.sh if executable, before falling back to the nix default. Then document GATE_GO_CMD's intended use accordingly and drop the "rebuild the sandbox image" hint from the fail-closed message when the real cause is layout, not toolchain.

`.sandcastle/gate-lib.sh` (#198) hard-codes OurCloud's layout in `gate_go_default_cmd`: `nix develop "$root#go-ci"`, a root-level Go module, and a `broker/` module. A downstream repo that vendors the gate (FACTORY_MANIFEST / ADR 0180) but has no flake and a different module layout cannot satisfy it on ANY host, and cannot edit the vendored file without tripping the drift gate. The only escape is the `GATE_GO_CMD` env var, which the comments describe as a test seam. Observed in matou-app (Matou/matou-app#346, downstream fix PR + sweep Matou/matou-app#349): its module is `backend/`, no `flake.nix`, toolchain pinned in the sandbox Dockerfile (Go 1.25.5 — beyond nixpkgs 24.11's go_1_23 anyway). A completed Go slice (#166) was stranded unpushed until a human recovered it. Interim downstream fix: the Dockerfile sets `ENV GATE_GO_CMD="bash .sandcastle/go-gate.sh"` (repo-local script) and documents it as the sanctioned gate. Ask: make the Go stage command a supported per-repo override instead of a test-only seam — e.g. `gate_go_stage` sources `.sandcastle/gate.conf` (NOT in FACTORY_MANIFEST) when present, or honours a `.sandcastle/go-gate.sh` if executable, before falling back to the nix default. Then document `GATE_GO_CMD`'s intended use accordingly and drop the "rebuild the sandbox image" hint from the fail-closed message when the real cause is layout, not toolchain.

This was generated by AI during triage.

Category: enhancement · State: ready-for-agent

I verified the claim against this repo's code. Confirmed:

  • gate_go_default_cmd hard-codes the OurCloud layout — nix develop "$root#go-ci", a root-level Go module, and a broker/ sub-module.
  • gate_go_stage treats GATE_GO_CMD as a test seam (its comment reads "Uses GATE_GO_CMD when set (tests)"), and its fail-closed branch emits a toolchain-only remedy ("refusing to push un-linted Go … rebuild the sandbox image").
  • gate-lib.sh is vendored (FACTORY_MANIFEST), so a consumer cannot edit the vendored copy without tripping the drift gate. .sandcastle/gate.conf and .sandcastle/go-gate.sh are not in the manifest, so either is a legitimate per-repo layer file.
  • No supported per-repo override exists today; the GATE_GO_CMD env var is the only escape and is documented as test-only. Not already implemented; no .out-of-scope/ prior rejection (the KB does not yet exist here).

Ruled by agent under ADR 0174 — veto anytime

Ruling — the override mechanism. gate_go_stage resolves its Go command with this precedence, first match wins:

  1. an explicit GATE_GO_CMD env var (unchanged behaviour; reclassified from test-only seam to a supported per-repo override that also serves as the test seam);
  2. otherwise, an executable .sandcastle/go-gate.sh at the repo root, run through the same gate_scrub_git_env scrubbed subshell as GATE_GO_CMD;
  3. otherwise, the existing nix develop "$root#go-ci" default.

Fail-closed fires only when none of the three resolve (no GATE_GO_CMD, no executable .sandcastle/go-gate.sh, no nix), and its message names both possible causes — a missing toolchain or a layout that differs from the nix default — and points to the sanctioned override, dropping "rebuild the sandbox image" as the sole remedy.

I chose .sandcastle/go-gate.sh auto-detection over a sourced .sandcastle/gate.conf: it is a single executable, it matches the downstream precedent already in production (matou-app's Dockerfile sets GATE_GO_CMD="bash .sandcastle/go-gate.sh"), it needs no eval-from-conf, and it is not in FACTORY_MANIFEST so it stays per-repo and drift-safe. gate.conf is not adopted.

Why this is a two-way door. Purely revertible by a later commit — no schema, no persisted state, no external surface. It touches personal credentials / security posture / member-facing trust / data / spend not at all. Blast radius (vendored into consumers) is real but reaches a consumer only at a human-driven pin bump (GOTCHAS 4), and any consumer can veto before then.

What proves it. tests/gate-lib-test.sh already stubs the Go stage via GATE_GO_CMD with no toolchain, no docker, no network — the same offline seam covers the new precedence and the fail-closed message.


Agent Brief

Category: enhancement
Summary: Promote the Go pre-push gate command to a supported per-repo override so a downstream repo with a different module layout / no flake can satisfy the gate without editing the vendored file.

Current behavior:
The Go stage of the pre-push gate runs a single hard-coded command: a nix develop "$root#go-ci" dev-shell driving gofmt/build/vet/test/lint over a root module plus a broker/ sub-module. A consumer that vendors the gate but has no flake, a different module directory, and a newer pinned toolchain cannot satisfy this on any host, and cannot edit the vendored gate file without tripping the drift gate. The only escape is the GATE_GO_CMD env var, documented as a test-only seam. When no GATE_GO_CMD and no nix are present the gate fails closed with a toolchain-only message ("rebuild the sandbox image").

Desired behavior:
The Go gate command is resolved from a first-match-wins precedence: (1) an explicit GATE_GO_CMD env var — now a supported per-repo override, not test-only; (2) an executable per-repo .sandcastle/go-gate.sh, run in the same git-env-scrubbed subshell the env override uses; (3) the existing nix dev-shell default. The gate fails closed only when none of the three resolve, and the fail-closed message names both a missing toolchain and a differing layout as causes, points to the supported override, and no longer offers "rebuild the sandbox image" as the sole remedy. The reclassification is reflected in gate-lib.sh's own comments (and any onboarding/gate docs that call GATE_GO_CMD a test seam).

Key interfaces:

  • The Go-stage resolver (currently gate_go_stage) — add the executable-.sandcastle/go-gate.sh branch between the env override and the nix default; run the discovered script through the existing git-env scrub (gate_scrub_git_env) and cd "$root", exactly as the env override is run.
  • The fail-closed message — reworded per Desired behavior; keep the non-zero return so an un-lintable Go change still blocks the push.
  • Comment/doc reclassification of GATE_GO_CMD from "tests" to "supported per-repo override (also the test seam)".
  • .sandcastle/go-gate.sh is a per-repo file and must not be added to FACTORY_MANIFEST.

Acceptance criteria:

  • With no GATE_GO_CMD set and an executable .sandcastle/go-gate.sh present, the Go gate runs that script (proven in tests/gate-lib-test.sh with the offline seam — no docker/nix/network).
  • GATE_GO_CMD takes precedence over an executable .sandcastle/go-gate.sh.
  • A non-executable or absent .sandcastle/go-gate.sh, with no GATE_GO_CMD and no nix, still fails closed (non-zero) — an un-lintable Go change never ships.
  • The .sandcastle/go-gate.sh branch runs under the same git-env scrub as GATE_GO_CMD (the existing GIT_DIR-leak test still passes).
  • The fail-closed message names both toolchain and layout causes and points to the override; no "rebuild the sandbox image" as the sole remedy.
  • gate-lib.sh comments describe GATE_GO_CMD / .sandcastle/go-gate.sh as the supported per-repo override, not a test-only seam.
  • tests/gate-lib-test.sh is updated in the same commit; the full offline suite passes (for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done).
  • STATUS.md updated if this change alters project state per CLAUDE.md.

Out of scope:

  • A sourced .sandcastle/gate.conf mechanism (ruled against above in favour of the executable script).
  • Changing the nix default command or the broker/ sub-module stages for repos that DO use the flake.
  • Any change to the TypeScript stage or the language-detection logic.
  • Editing the vendored self-copy under .sandcastle/ (root gate-lib.sh + tests/gate-lib-test.sh are the surface; the pin bump is a separate, human-driven step).
> *This was generated by AI during triage.* **Category:** enhancement · **State:** ready-for-agent I verified the claim against this repo's code. Confirmed: - `gate_go_default_cmd` hard-codes the OurCloud layout — `nix develop "$root#go-ci"`, a root-level Go module, and a `broker/` sub-module. - `gate_go_stage` treats `GATE_GO_CMD` as a **test seam** (its comment reads "Uses GATE_GO_CMD when set (tests)"), and its fail-closed branch emits a toolchain-only remedy ("refusing to push un-linted Go … rebuild the sandbox image"). - `gate-lib.sh` is vendored (`FACTORY_MANIFEST`), so a consumer cannot edit the vendored copy without tripping the drift gate. `.sandcastle/gate.conf` and `.sandcastle/go-gate.sh` are **not** in the manifest, so either is a legitimate per-repo layer file. - No supported per-repo override exists today; the `GATE_GO_CMD` env var is the only escape and is documented as test-only. Not already implemented; no `.out-of-scope/` prior rejection (the KB does not yet exist here). ## Ruled by agent under ADR 0174 — veto anytime **Ruling — the override mechanism.** `gate_go_stage` resolves its Go command with this precedence, first match wins: 1. an explicit `GATE_GO_CMD` env var (unchanged behaviour; **reclassified** from test-only seam to a *supported per-repo override that also serves as the test seam*); 2. otherwise, an **executable `.sandcastle/go-gate.sh`** at the repo root, run through the same `gate_scrub_git_env` scrubbed subshell as `GATE_GO_CMD`; 3. otherwise, the existing `nix develop "$root#go-ci"` default. Fail-closed fires only when **none** of the three resolve (no `GATE_GO_CMD`, no executable `.sandcastle/go-gate.sh`, no `nix`), and its message names **both** possible causes — a missing toolchain *or* a layout that differs from the nix default — and points to the sanctioned override, dropping "rebuild the sandbox image" as the sole remedy. I chose `.sandcastle/go-gate.sh` auto-detection over a sourced `.sandcastle/gate.conf`: it is a single executable, it matches the downstream precedent already in production (matou-app's Dockerfile sets `GATE_GO_CMD="bash .sandcastle/go-gate.sh"`), it needs no `eval`-from-conf, and it is not in `FACTORY_MANIFEST` so it stays per-repo and drift-safe. `gate.conf` is not adopted. **Why this is a two-way door.** Purely revertible by a later commit — no schema, no persisted state, no external surface. It touches personal credentials / security posture / member-facing trust / data / spend not at all. Blast radius (vendored into consumers) is real but reaches a consumer only at a human-driven pin bump (GOTCHAS 4), and any consumer can veto before then. **What proves it.** `tests/gate-lib-test.sh` already stubs the Go stage via `GATE_GO_CMD` with no toolchain, no docker, no network — the same offline seam covers the new precedence and the fail-closed message. --- ## Agent Brief **Category:** enhancement **Summary:** Promote the Go pre-push gate command to a supported per-repo override so a downstream repo with a different module layout / no flake can satisfy the gate without editing the vendored file. **Current behavior:** The Go stage of the pre-push gate runs a single hard-coded command: a `nix develop "$root#go-ci"` dev-shell driving `gofmt`/`build`/`vet`/`test`/`lint` over a root module plus a `broker/` sub-module. A consumer that vendors the gate but has no flake, a different module directory, and a newer pinned toolchain cannot satisfy this on any host, and cannot edit the vendored gate file without tripping the drift gate. The only escape is the `GATE_GO_CMD` env var, documented as a test-only seam. When no `GATE_GO_CMD` and no `nix` are present the gate fails closed with a toolchain-only message ("rebuild the sandbox image"). **Desired behavior:** The Go gate command is resolved from a first-match-wins precedence: (1) an explicit `GATE_GO_CMD` env var — now a supported per-repo override, not test-only; (2) an executable per-repo `.sandcastle/go-gate.sh`, run in the same git-env-scrubbed subshell the env override uses; (3) the existing nix dev-shell default. The gate fails closed only when none of the three resolve, and the fail-closed message names both a missing toolchain and a differing layout as causes, points to the supported override, and no longer offers "rebuild the sandbox image" as the sole remedy. The reclassification is reflected in `gate-lib.sh`'s own comments (and any onboarding/gate docs that call `GATE_GO_CMD` a test seam). **Key interfaces:** - The Go-stage resolver (currently `gate_go_stage`) — add the executable-`.sandcastle/go-gate.sh` branch between the env override and the nix default; run the discovered script through the existing git-env scrub (`gate_scrub_git_env`) and `cd "$root"`, exactly as the env override is run. - The fail-closed message — reworded per Desired behavior; keep the non-zero return so an un-lintable Go change still blocks the push. - Comment/doc reclassification of `GATE_GO_CMD` from "tests" to "supported per-repo override (also the test seam)". - `.sandcastle/go-gate.sh` is a per-repo file and must **not** be added to `FACTORY_MANIFEST`. **Acceptance criteria:** - [ ] With no `GATE_GO_CMD` set and an executable `.sandcastle/go-gate.sh` present, the Go gate runs that script (proven in `tests/gate-lib-test.sh` with the offline seam — no docker/nix/network). - [ ] `GATE_GO_CMD` takes precedence over an executable `.sandcastle/go-gate.sh`. - [ ] A non-executable or absent `.sandcastle/go-gate.sh`, with no `GATE_GO_CMD` and no `nix`, still fails closed (non-zero) — an un-lintable Go change never ships. - [ ] The `.sandcastle/go-gate.sh` branch runs under the same git-env scrub as `GATE_GO_CMD` (the existing GIT_DIR-leak test still passes). - [ ] The fail-closed message names both toolchain and layout causes and points to the override; no "rebuild the sandbox image" as the sole remedy. - [ ] `gate-lib.sh` comments describe `GATE_GO_CMD` / `.sandcastle/go-gate.sh` as the supported per-repo override, not a test-only seam. - [ ] `tests/gate-lib-test.sh` is updated in the same commit; the full offline suite passes (`for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done`). - [ ] `STATUS.md` updated if this change alters project state per CLAUDE.md. **Out of scope:** - A sourced `.sandcastle/gate.conf` mechanism (ruled against above in favour of the executable script). - Changing the nix default command or the `broker/` sub-module stages for repos that DO use the flake. - Any change to the TypeScript stage or the language-detection logic. - Editing the vendored self-copy under `.sandcastle/` (root `gate-lib.sh` + `tests/gate-lib-test.sh` are the surface; the pin bump is a separate, human-driven step).

swarm-claim host=elitebook-distributed-server-03 run=5671
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=5671 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #126 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 126,
  "status": "success",
  "commits": [
    "a21c6893968b8aa7a214230228031681475afb4c"
  ],
  "changed_files": [
    "gate-lib.sh",
    "tests/gate-lib-test.sh",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/gate-lib-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "With no GATE_GO_CMD and an executable .sandcastle/go-gate.sh present, the Go gate runs that script (offline, no docker/nix/network)": "gate-lib.sh gate_go_stage adds `if [ -x \"$root/.sandcastle/go-gate.sh\" ]` branch; tests/gate-lib-test.sh creates an executable go-gate.sh that touches a marker and asserts it ran with rc 0 — passes",
    "GATE_GO_CMD takes precedence over an executable .sandcastle/go-gate.sh": "gate_go_stage checks GATE_GO_CMD first; test asserts GATE_GO_CMD=true wins and the go-gate.sh marker is NOT created",
    "A non-executable or absent .sandcastle/go-gate.sh, with no GATE_GO_CMD and no nix, still fails closed (non-zero)": "gate_go_stage falls through to `return 3`; test chmod -x go-gate.sh and asserts non-zero, plus the existing $PWD fail-closed test",
    "The .sandcastle/go-gate.sh branch runs under the same git-env scrub as GATE_GO_CMD": "branch is `( cd \"$root\" && gate_scrub_git_env && ./.sandcastle/go-gate.sh )`; test sets GIT_DIR/GIT_INDEX_FILE and asserts the script sees them unset (rc 0)",
    "The fail-closed message names both toolchain and layout causes and points to the override; no 'rebuild the sandbox image' as the sole remedy": "gate-lib.sh fail-closed branch reworded to name a missing toolchain OR a differing layout and point to GATE_GO_CMD / .sandcastle/go-gate.sh; 'rebuild the sandbox image' removed",
    "gate-lib.sh comments describe GATE_GO_CMD / .sandcastle/go-gate.sh as the supported per-repo override, not a test-only seam": "gate_go_stage header, top-of-file comment, and gate_go_default_cmd comment all reclassified to 'supported per-repo override (also the test seam)'",
    "tests/gate-lib-test.sh updated in the same commit; the full offline suite passes": "commit a21c689 includes tests/gate-lib-test.sh (20 checks pass); full suite green except pre-existing unrelated fleet-tui-test.sh failure (fails on clean tree, untouched by this slice)",
    "STATUS.md updated if this change alters project state": "STATUS.md header line + Milestone log entry for #126 added in the same commit"
  },
  "summary": "gate_go_stage resolves the Go pre-push command first-match-wins — GATE_GO_CMD, then an executable .sandcastle/go-gate.sh, then the nix default — failing closed only when none resolve, with a message naming both toolchain and layout causes.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #126 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 126, "status": "success", "commits": [ "a21c6893968b8aa7a214230228031681475afb4c" ], "changed_files": [ "gate-lib.sh", "tests/gate-lib-test.sh", "STATUS.md" ], "tests": [ { "command": "bash tests/gate-lib-test.sh", "exit_code": 0 } ], "criteria": { "With no GATE_GO_CMD and an executable .sandcastle/go-gate.sh present, the Go gate runs that script (offline, no docker/nix/network)": "gate-lib.sh gate_go_stage adds `if [ -x \"$root/.sandcastle/go-gate.sh\" ]` branch; tests/gate-lib-test.sh creates an executable go-gate.sh that touches a marker and asserts it ran with rc 0 — passes", "GATE_GO_CMD takes precedence over an executable .sandcastle/go-gate.sh": "gate_go_stage checks GATE_GO_CMD first; test asserts GATE_GO_CMD=true wins and the go-gate.sh marker is NOT created", "A non-executable or absent .sandcastle/go-gate.sh, with no GATE_GO_CMD and no nix, still fails closed (non-zero)": "gate_go_stage falls through to `return 3`; test chmod -x go-gate.sh and asserts non-zero, plus the existing $PWD fail-closed test", "The .sandcastle/go-gate.sh branch runs under the same git-env scrub as GATE_GO_CMD": "branch is `( cd \"$root\" && gate_scrub_git_env && ./.sandcastle/go-gate.sh )`; test sets GIT_DIR/GIT_INDEX_FILE and asserts the script sees them unset (rc 0)", "The fail-closed message names both toolchain and layout causes and points to the override; no 'rebuild the sandbox image' as the sole remedy": "gate-lib.sh fail-closed branch reworded to name a missing toolchain OR a differing layout and point to GATE_GO_CMD / .sandcastle/go-gate.sh; 'rebuild the sandbox image' removed", "gate-lib.sh comments describe GATE_GO_CMD / .sandcastle/go-gate.sh as the supported per-repo override, not a test-only seam": "gate_go_stage header, top-of-file comment, and gate_go_default_cmd comment all reclassified to 'supported per-repo override (also the test seam)'", "tests/gate-lib-test.sh updated in the same commit; the full offline suite passes": "commit a21c689 includes tests/gate-lib-test.sh (20 checks pass); full suite green except pre-existing unrelated fleet-tui-test.sh failure (fails on clean tree, untouched by this slice)", "STATUS.md updated if this change alters project state": "STATUS.md header line + Milestone log entry for #126 added in the same commit" }, "summary": "gate_go_stage resolves the Go pre-push command first-match-wins — GATE_GO_CMD, then an executable .sandcastle/go-gate.sh, then the nix default — failing closed only when none resolve, with a message naming both toolchain and layout causes.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#126
No description provided.