Commit graph

321 commits

Author SHA1 Message Date
Julian Knutsen
fe6bd6301f
ci: fix red nightly (Bazel-skip allowlist, credential helper init); rerun-safe Bazel artifacts (#7096)
* fix(ci): allowlist the scripts tests that skip under Bazel, and check new ones before merge

nightly.yml's skip-parity check (equivalence.py --go-test-json) went red
on 2026-10-02 (run 36955306415): TestBazelGatedLanesNeverRetryFlakyTests
and TestCheckShardCoverageScript pass under go test and deliberately
t.Skip under Bazel (their inputs are not in //scripts:scripts_test's
runfiles), but had no `skip` allowlist entry. Step 2's
TestShardScriptsListOnlyRealTests and TestShardScriptNarrowingCheck, now
on main, have the same shape and would have turned the next nightly red.

Add the four entries, and TestBazelOnlySkipsAreAllowlisted: it parses
every _test.go file of the module and requires each top-level test whose
t.Skip is guarded by TEST_SRCDIR or bazeltest.IsBazel() (directly or
through a helper) to have an entry, so a new one fails under go test
before the merge instead of in the next nightly. It skips under Bazel
itself and is allowlisted too.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(test): keep cmd/bd's integration init out of the credential-command helper process

nightly.yml's Full Test Suite (go test -tags=integration ./...) failed
TestApplyInitGatewayCredentialAdoptsToken and ...FailsClosed on
2026-10-02 (run 36955306415): credentialcmd re-execs the test binary as
the credential helper, and cli_fast_test.go's integration-tagged init()
runs in that child before TestMain can dispatch it, tries `go build .`
from the helper's working directory and panics, so the helper exits 2.
Add credentialcmd.IsHelperProcess (Dispatch's two gates) and return from
that init early, as it already does for the worktree-remove helper.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): overwrite fixed-name artifacts so "Re-run failed jobs" does not 409

A job re-run is the same workflow run, and upload-artifact v4+ refuses a
second artifact of the same name there (409 Conflict). bazel-test uploads
the bd package even after its tests fail, so re-running a failed Bazel /
test lane, the documented recovery for an eviction or a flake, failed on
the upload even when every test passed. Set overwrite: true on all eight
uploads in bazel.yml (the bd package, BUILD sync patch, every lane's test
logs) and policy-test it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(test): keep skip-scan fixture functions out of line-based test discovery

The fixture source in bazel_skip_allowlist_test.go had top-level
`func TestXxx(t *testing.T)` lines, which equivalence.py (and the CI shard
scripts) count as tests of the scripts package; write them with a FUNC
placeholder and substitute at write time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 05:42:05 -07:00
Julian Knutsen
3789dde785
ci: retire PR Risk's legacy proxied and server-Dolt tiers where the gated Bazel lanes run them (D2 step 2) (#7094)
* ci: retire PR Risk's legacy proxied and server-Dolt tiers where the gated Bazel lanes run them (D2 step 2)

On same-repo, non-Dependabot pull_requests, PR Risk's test-proxied-cmd (15),
test-server-storage and test-server-storage-full (16) jobs stand down while
the committed BAZEL_RETIRES_LEGACY_DOLT_SERVER_TIERS flag is "true" (in both
pr.yml and pr-risk.yml, policy-tested equal); pr.yml's gated Bazel
proxied-server and server-Dolt storage lanes are then the tiers' only
pre-merge run. build-embedded, whose embedded-test-binaries artifact feeds
exactly the six retired legacy test jobs, stands down where both D2 steps
apply.

Generalizes step 1 instead of copying it:
- bazel-embedded-coverage becomes bazel-coverage (identical in both
  workflows): one decision step, outputs embedded and dolt_server, each
  flag && pull_request && !fork && actor != dependabot[bot]; gate id
  BAZEL_COVERAGE.
- PR Risk's gate accepts the retired jobs' skips only when their output is
  true, and BUILD_EMBEDDED's only when both are.
- pr.yml's gate adds BAZEL_DOLT_SERVER_RETIRED: red when dolt_server is true
  and the mode is not remote or BAZEL_PROXIED / BAZEL_SERVER_STORAGE is not
  success (shared helper with BAZEL_EMBEDDED_RETIRED).
- Lane hardening as for embedded: --nocache_test_results for
  doltserver-proxied and doltserver-integration, the flaky-target query,
  check_shard_coverage.py (proxied 15 shards; server full suite 16 shards
  plus --whole conformance), pinned test steps, rc lines and target
  args/env; the shard listings now run concurrently (the server script
  forks per test).
- Policy tests generalized over the retired tiers: decision equivalence
  with bazel.yml's mode across two runs, both gates simulated, flag
  equality, artifact consumers, real shard scripts in list-only mode.

Revert: commit BAZEL_RETIRES_LEGACY_DOLT_SERVER_TIERS: "false" in both
workflows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the retired legacy proxied and server-Dolt tiers in the check topology

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): no whole-invocation retry on remote cache eviction in the retired tiers' lanes

Review F1 (D2 step 2): Bazel 9 re-runs a whole `bazel test` invocation
(--experimental_remote_cache_eviction_retries, default 5) when an input was
evicted from the remote cache, and that exit code outranks a test
failure. With --nocache_test_results every test runs again and only the
retry is reported, so a flaky failure in the embedded, proxied or
server-storage lane (each now its tier's only pre-merge run) could turn
green. Set the retries to 0 in test:embedded, test:doltserver-proxied and
test:doltserver-integration (not remote-exec, which must stay key-neutral),
pin the lines, forbid any other line or the setup-bazel action from
setting the count, and correct the topology doc, which claimed the retry
never re-runs a failed test.

Reproduced against a local HTTP cache emptied mid-build: with the default
the build hit "Lost inputs", retried and exited 0; with 0 it failed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): pin how the retired lanes' shard scripts run their tests

Review F2 (D2 step 2): the narrowing scan covered tools/bazel and the
setup-bazel action but not the four .github/scripts/*-test-shard.sh
scripts the sharded targets execute, so appending -test.short to an exec
line or exporting BEADS_TEST_SKIP there passed the policy tests (and
check_shard_coverage.py only rejects a shard that is entirely skipped).
Pin each script's prebuilt-binary and go test fallback commands exactly
and its RUN_REGEX construction, and forbid anything else in the scripts
from running tests or selecting, skipping or switching them. The scripts
themselves are unchanged (the legacy jobs run them too); a self-test
checks that six narrowing edits are rejected.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): simulate a non-true coverage decision per retired tier

Review F3 (D2 step 2): the "decision succeeded but its output is not
exactly 'true'" gate scenarios set both bazel-coverage outputs bad at
once, so the embedded ids reddened the gate whatever the dolt_server rule
said, and weakening PR Risk's gate to `!= "false"` for one tier passed.
Run them per tier, with the other output a valid "false" and only that
tier's job skipped, and isolate build-embedded's both-true rule the same
way. Failed or cancelled decisions keep the all-skipped scenarios.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): list Bazel tier coverage and the proxied/server-Dolt checks as not directly required

Review F4 (D2 step 2): the topology doc still named the renamed
`Bazel embedded coverage` job, and its list of check names not to require
directly lacked the proxied and server-Dolt test jobs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): skip the real shard-script listing test on bash < 4

The CI shard scripts use associative arrays and only run on Linux runners;
macOS's /bin/bash 3.2 can't execute them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 02:20:30 -07:00
Julian Knutsen
555b01d789
fix(release): name the version-drift remedies that work (#7083)
Post-merge review follow-up to #5614.

#5614 replaced the shell checker's three-way drift remedy with a bare
"Run: scripts/update-versions.sh <canonical>" in both the Go checker
(status 1) and bd preflight's Version sync output, and the release-tag
pre-push hook kept answering status 1 with "Fix with:
scripts/update-versions.sh <version>". update-versions.sh derives the old
version from cmd/bd/version.go and anchors its substitutions on it, so
with version.go already at the canonical version that re-run rewrites
only the .githooks markers and uv.lock and leaves any other drifted file
as it was.

Restore the remedy as versioncheck.Report.MismatchRemedy, shared by the
checker and preflight:
- one file drifted: edit it to the expected value
- several drifted: set version.go to the previous version, then replay
  scripts/update-versions.sh <canonical>
- version.go is wrong: scripts/update-versions.sh <intended-version>

The hook's status-1 text now points at the checker output instead of
prescribing update-versions.sh; status 3 is unchanged. The text is sized
so one drifted file shows in full within preflight's 500-byte human
output, with the several-files case ahead of the version.go one.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 11:34:06 -07:00
Julian Knutsen
6cd1184687
feat(httpapi): opt-in large issues:batchApply envelope (≤1000 items, one transaction) (#7051)
* test(storage): measure ApplyBatchInTx SQL statement counts (B0)

Adds a driver.Connector-level counting/latency-injecting wrapper
(internal/storage/sqlcount) plus shared plan-request fixtures
(internal/storage/batchfixtures: mol-normalized 356/712-item shapes and a
40-item classic shape) and backend-specific pinning tests + benchmarks
(internal/storage/embeddeddolt, internal/storage/dolt) that measure the
ACTUAL number of SQL statements issueops.ApplyBatchInTx issues for each
shape, on both the embedded and Dolt (TCP) backends.

Measured totals (Prepare+Exec+Query+StmtExec+StmtQuery inside one
transaction): 356 items ~7008-7009, 712 items 14014-14015, 40 items 846,
identical on both backends (expected: statement issuance is driven by Go
application logic, not backend-specific SQL planning). Pinned with a small
(+/-2) tolerance to absorb an observed, host-contention-driven +/-1 Query
drift (Exec is deterministic on every run). This is the regression baseline
slice B2 (a later, lighter fast path) must demonstrably lower.

batchfixtures.UncappedPlan bypasses issueops.MaxApplyBatchItems so this
measurement does not depend on slice B1's cap raise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* feat(httpapi,issueops): raise batchApply envelope to 1000 items with bounded large-apply handling

POST /v0/beads/issues:batchApply now accepts up to 1000 items (up from 100);
issueops.MaxApplyBatchItems moves accordingly and the request body cap rises
to 16 MiB. The whole plan still applies in exactly ONE transaction. A request
over 100 items runs under a separate, flat, operator-configured whole-run
budget (`bd serve --large-apply-ceiling`, 5 minutes by default) instead of
the ordinary 60s request deadline; a request at or under 100 items is
unaffected and keeps exactly the 60s deadline and 15s commit-retry ceiling it
always had.

Concurrency and shutdown are bounded, not just documented:
- Oversized requests serialize through a dedicated one-wide semaphore, and at
  most one caller may wait for that semaphore at a time (a CAS-guarded single
  waiter) — a burst of oversized requests is shed with 503 rather than
  queuing and starving ordinary traffic behind the general semaphore.
- The run deadline is stamped only once the slot is actually acquired, not
  at the time the request arrived.
- Graceful shutdown closes new admissions before computing its drain budget,
  then waits out an in-flight large apply up to its own remaining deadline
  (plus a few seconds' grace for the response to write); any large apply
  still queued for the semaphore when shutdown begins is refused rather than
  extending the drain further. A queued caller that disconnects gets a clean
  503, never a misclassified context error. `bd serve`'s orchestrator stop
  grace must be at least `--large-apply-ceiling` — see
  engdocs/SERVE_RUNBOOK.md.
- ApplyBatch's commit-retry budget only extends past the ordinary 15s ceiling
  on this explicit large-apply path (via a context marker), with headroom
  reserved so the final retry attempt can't be killed mid-commit by the
  context's own expiry.

A new `issues.batchApplyLarge` capability token on `GET /v0/beads/context`
lets a client learn whether a given server accepts the raised envelope.

Wall-clock measurement (embedded Dolt, whole-transaction build+commit) backs
the 5-minute ceiling default: 356 items ~12.6s (23.8x headroom), 1000 items
~57.5s (5.2x headroom).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(httpapi,serve): wire the large-apply retry budget; repair stale pins

Review fixes for the large batchApply envelope, on top of the test
repairs the PR needed against main.

The extended commit-retry budget was never switched on.
internal/storage/uow's retryTxBudget lets a large apply keep retrying a
commit-time conflict past the ordinary 15s ceiling only when its context
carries issueops.WithExtendedRetryBudget's marker, and the docs on both
sides say admitLargeApply sets it, but nothing did: the marker's only
callers were the uow tests, which mark their contexts by hand. A
1000-item apply that hit a conflict still gave up after 15s with most of
its 5-minute ceiling unused. admitLargeApply now marks the run context
it builds, and TestApplyBatchMarksOnlyALargeApplyForTheExtendedRetryBudget
pins the seam over HTTP: marked at 101 and 1000 items, unmarked at 100.
Removing the mark fails the 101 and 1000 cases; marking every request in
handleApplyBatch fails the 100 case.

Smaller fixes from the same review:

- `bd serve --large-apply-ceiling` repeated the 5m default as a literal
  of its own, and since bd serve always passes a positive ceiling, that
  literal, not httpapi's, was the default every deployment ran. Export
  httpapi.DefaultLargeApplyCeiling, default the flag to it, and pin the
  flag's 5m0s default in TestServeFlags.
- admitLargeApply's release cancels the run context before clearing
  s.largeApplyDeadline, the order acquireLargeApply's doc states; it
  cleared the deadline first.
- Drop the batchfixtures test's dead t.Skipf, which waited for the cap
  to reach 1000, and correct a graph-counter comment that still cited
  the 100-item cap and the TestServeFlags doc line that called the
  no-argument server unchanged.

The PR raises issueops.MaxApplyBatchItems from 100 to 1000 and adds
`bd serve --large-apply-ceiling`, but two base-owned tests still pinned
the old surface and went red on every lane that runs them (Bazel / test,
Test (macos-latest)):

- TestServeFlags pins the exact `bd serve` flag list; add
  large-apply-ceiling.
- TestPlanApplyBatchRefusesAnUnusableRequest/too_many_items built 101
  items and expected "at most 100 items", a request the 1000 cap now
  plans successfully. Size the over-cap request and its message from
  issueops.MaxApplyBatchItems, as TestPlanApplyBatchAcceptsTheBoundary
  already does for the other side of the cap; the cap's value stays
  pinned by TestCapBatchApplyLargeTiesAllThreeLimits.

The PR's own TestLargeApplyBurstNeverStarvesSmallRequestsForSemTimeout
also went red in PR Core (-race, -p 4 on a 4-vCPU runner): all eight
small requests took 160-165ms against a 100ms bound. The stall it
guards against lasts semTimeout (5s), while a small request can still
queue briefly behind the refused large requests, each holding a general
sem slot while its body decodes. Bound it at a second, the "want well
under a second" its sibling TestLargeApplyQueueDoesNotStarveOrdinaryRequests
already uses. Pinned to four cores beside 24 busy loops, small requests
measured 183ms mean and 338ms max, and the 1s bound passed 80/80 runs;
with the one-waiter gate in acquireLargeApply disabled the test still
fails 3/3, on its 2s never-completed check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(uow): stop a doomed large-apply retry before ctx cuts it off

retryTxBudget sizes maxElapsed once at ApplyBatch entry, but says nothing
about how long an individual attempt takes. A slow first attempt (e.g.
157s of a large apply's commit) left little of the budget for a retry,
which then got killed mid-transaction by ctx's own deadline instead of
finishing and reporting its own outcome -- surfacing as
context.DeadlineExceeded (isUnavailable excludes it -> a generic 500)
instead of the exhausted-write-conflict result this loop already reports
correctly (-> 503 + Retry-After).

RunTxResultWithin now tracks the previous attempt's duration and, before
starting a new one, stops early with the last real serialization error
when time left on ctx is less than that duration plus a fixed headroom --
but only when publicops.HasExtendedRetryBudget(ctx) is set (the same
marker retryTxBudget itself checks). Applying the look-ahead
unconditionally regressed TestApplyBatchHonorsAnExtendedRetryBudgetFromContext's
unmarked case: ordinary requests have cheap attempts and are meant to run
until their own ctx deadline ends the loop, and the large-apply-sized 5s
headroom was tripping that for any short-ctx caller with a near-instant
failing attempt.

Adds TestRunTxResultWithin_SlowAttemptStopsBeforeADoomedRetry (a 1.2s
commit against a 2s marked ctx must stop after one attempt with its own
serialization error, never DeadlineExceeded, and never touch a second
unit of work) and its control, TestRunTxResultWithin_ShortAttemptStillRetries
(a 50ms attempt against the same shape must still retry and succeed).
Both mutation-checked against the look-ahead condition and its gate.

Also updates the stale "items accepts at most 100 entries" prose on the
applyBatch endpoint description (openapi.v0.yaml) to the large-envelope
wording already used elsewhere in the spec: 1000-item cap behind the
issues.batchApplyLarge capability, large-apply-ceiling deadline extension,
<=100 unaffected. dependencies:count's own "at most 100" lines are
unrelated and untouched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix(ci,serve): fit the 1000-item cap's tests in the storage shard budget

Review fixes for the relaunched #7051, iteration 1.

Raising issueops.MaxApplyBatchItems from 100 to 1000 made the base-owned
TestBatchApplyContract take 604s under -race, against 97s at the old cap
(main run 35862663577). It hashed onto the legacy test-embedded-storage
shard 2/5, beside ~5m of other tests, and that shard hit its 15m budget
twice (PR Risk run 36807191489). PR Risk no longer runs the legacy tier
on same-repo PRs (#7071), but Main's push run and fork PRs still do, so
the merge would have carried the timeout to Main.

Raising the jobs' timeout-minutes alone would not fix it: the shard
script passes the binary its own -test.timeout=15m. So:

- embedded-storage-test-shard.sh passes -test.timeout=20m (and its go
  test fallback -timeout 20m), as embedded-test-shard.sh does for
  cmd/bd.
- test-embedded-storage in main.yml and pr-risk.yml: timeout-minutes 15
  -> 25, the script's 20m plus setup.
- embeddeddolt_embedded_test appends -test.timeout=19m, as
  bd_embedded_test does, so Go's timeout, which dumps every goroutine,
  fires before rbe-west's 1200s action kill, which does not.
  TestBazelEmbeddedJobMirrorsEmbeddedTier now checks the override on
  both sharded targets instead of only cmd/bd's, and the PR Risk
  coverage test pins the storage target's new args.
- embedded-storage-test-shards.txt places TestBatchApplyContract on
  shard 4, which has ~3m of other tests, and the PR's two large-batch
  tests, TestLargeBatchApplyStatementCounts_Embedded (247s) and
  TestLargeBatchApplyWallClock_Embedded (261s), on shards 2 and 5. From
  the PR run's per-test times, the heaviest shard projects to ~13m, down
  from shard 2's 15m-plus.

Also correct the stop-grace guidance. For an in-flight large apply,
Serve's drain waits out the apply's remaining deadline plus drainGrace
(5s), so the orchestrator's stop grace must be at least
--large-apply-ceiling plus 5s, as Serve's own doc says. The runbook, the
flag help, the LargeApplyCeiling field doc and the CHANGELOG entry asked
for the ceiling alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-01 08:32:56 -07:00
Julian Knutsen
e87aceedf9
test(init): port gateway credential fixtures onto shared credentialcmd (#7056)
#5725 gave the cmd/bd init gateway credential fixtures a private helper
protocol. While it was queued, #5749 landed internal/testutil/credentialcmd
for the same production shell boundary, leaving two parallel
implementations: the same emit/exit-23/marker operations, the same exit-97
malformed sentinel and the same Windows .cmd trampoline. They had already
drifted. The private copy claims a process on an env var alone, with no
argv sentinel, and its command text is stable rather than unique per call,
although the production credential cache is keyed on that text.

Port cmd/bd onto the shared fixture, as internal/creds and
internal/storage/dolt already use it:

- TestMain claims helper processes with credentialcmd.Dispatch() before
  any suite setup, and calls credentialcmd.Cleanup() after the suite.
- AdoptsToken, SkipsEmbeddedMode, FailsClosed and PresetWins build their
  commands with credentialcmd.Emit/Exit23/Marker and check non-invocation
  with credentialcmd.AssertMarkerAbsent. Their assertions are unchanged.
- The private protocol, its constants and
  TestApplyInitGatewayCredentialHelperProtocol, which tested only that
  protocol, are removed. credentialcmd's own TestProtocol covers the
  shared one and already runs natively on Windows in pr.yml.
- The native driver's fixture list drops the removed test, and bd_test
  gains the //internal/testutil/credentialcmd dep (gazelle agrees).

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR

Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 08:03:19 -07:00
ecuthiell
02a416cc73
fix: make release-version checks shell-free (#5614)
* fix: make release-version checks shell-free (#5533)

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* fix(release): preserve checker status and explain gate failures (saa-cgh.16)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs: retain release-pinned CLI references (saa-cgh.16)

Preserve corrected live preflight help while generated references continue to match docs/cli-docs.pin v1.2.2. Fix the exact two-line hosted docs-policy failure without changing pin authority.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(versioncheck): carry base's release gates into the Go checker

The base branch gained three release-metadata gates in scripts/check-versions.sh
after this PR's merge point (release: prep v1.3.0, b3ef65c854): the Copilot
plugin manifest, the four winres.json Windows PE version fields, and
manifest.xml's assemblyIdentity version. This PR replaces that shell body with
the Go authority, so adopting it as-written would have silently dropped all
three — each one guards a file whose bump is a sed anchored on the old value,
so a drifted copy no-ops and ships advertising the previous version.

Port them into internal/versioncheck so the shell-free checker enforces the
same set:

- source gains an optional expected() so a surface can derive its required
  value; the Windows PE numeric fields must be purely numeric and so carry the
  prerelease-stripped form, and manifest.xml carries the four-part form.
- readWinresVersionField reads the nested RT_VERSION resource path through the
  existing duplicate-key-checked JSON helpers.
- readManifestAssemblyVersion anchors on line start, since the XML declaration
  also carries a version attribute.

Also regenerate the Bazel BUILD files (make bazel-sync). cmd/bd/BUILD.bazel
enumerates srcs explicitly, so the PR's new preflight_versions.go was missing
from it and //cmd/bd:bd_lib failed to compile with `undefined:
runBeadsVersionSyncCheck`; gazelle adds that src, the //internal/versioncheck
dep edge, and BUILD files for the two new packages.

Known follow-up for review: the PR's TestRepositoryReleaseVersionsMatch and
TestPrePushHookOrdinaryPushWorksWithSystemBash read repository files directly,
so they need `data` runfiles to pass under `bazel test` (advisory lane only).

* fix(versioncheck): stop the release gate over-claiming docs coverage; distinguish --expect mismatch

Maintainer review fixup for iteration 1 (both findings minor, non-gating;
scorecard 915/850 approve with Required Changes: None).

Contract & Interface Fidelity (claude + codex): the success line claimed
"Version files and released-docs policy pass" while the checker reads no
documentation surface, and it replaced the shell predecessor's explicit
disclaimer that the docs release line and docs/cli-docs.pin are manual
release steps. Restore the base wording ("Version files in sync at: <v>")
plus the disclaimer, and update the three pins in main_test.go.

This also repairs a consumer neither review lane censused: the tracked
release runbook .beads/formulas/beads-release.formula.toml:475 instructs the
operator that the gate "must print `✓ Version files in sync at: <version>`
before you continue" — the renamed string had silently broken that
acceptance check. Grepping the new spelling finds nothing; the breakage only
shows up when grepping the old one.

Error Handling & Resilience (codex): --expect mismatch reused exit 1, so
.githooks/pre-push answered a tag/checkout mismatch with the version-drift
remedy ("Fix with: scripts/update-versions.sh <version>") — advice that
would rewrite every release surface to the wrong version. Give that case
status 3 and add the matching hook branch pointing at CONTRIBUTING's actual
rule. Only two --expect call sites exist: release.yml:45 (bare non-zero
check, unaffected) and this hook.

Verified at this head: check-versions.sh rc=0 (24 green rows, all three
ported base gates); exit taxonomy 0/2/3 as documented; go test
./internal/versioncheck/ ./scripts/check-versions/ PASS=65 FAIL=0 SKIP=0;
cmd/bd TestTrackedManagedHookSectionsMatchGenerator ok (hook edit sits above
the generator-managed markers); gofmt/vet clean. Both fixes proven
non-vacuous by mutating each back and requiring red.

Declined as out of cleanup scope, recorded for follow-up: making
TestRepositoryReleaseVersionsMatch fixture-based (redesigns the PR's own
test architecture and interacts with the deliberate untracked-discovery pin
at check_test.go:174; harm measured local-only) and declaring bazel data
runfiles (gate impact none — no BAZEL key in either CI_GATE_REQUIRED map at
this base; the remedy needs root filegroups that touch
scripts/bazel_policy_test.go invariants).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(versioncheck): declare the release-gate tests' repo inputs as Bazel data

Base commit e1b2e79484 (#6941) promoted the seven BAZEL* lanes into pr.yml's
CI_GATE_REQUIRED after this branch's merge point, so the two packages this PR
adds are now graded by a required check. Both reach real repository files
through a hand-rolled filepath.Join("..", ".."), which resolves outside the
runfiles tree, and `bazel test //...` failed on them:

  TestRepositoryReleaseVersionsMatch
    open ../../cmd/bd/version.go: no such file or directory
  TestPrePushHookOrdinaryPushWorksWithSystemBash
    runfiles .githooks/pre-push: No such file or directory

Resolve the root through internal/testutil/bazeltest.RepoRoot, the base's
helper for exactly this, which reduces to the previous behavior under plain
`go test`; and declare the inputs as data through a //:release_metadata_files
filegroup aggregating the surfaces versioncheck.releaseSources gates, the
canonical version it compares them against, the uv.lock pin and the tracked
hooks, exported from the packages that own them. The filegroup is hand-listed
because releaseSources is itself a closed list: a newly gated surface must be
added there too, and until it is the test fails under Bazel.

The shell entrypoint's exit-status subtests build the checker from source at
the repository root, which cannot work against a runfiles tree that has no
go.mod, so they skip under Bazel and keep running under `go test`. The guard
sits inside each subtest, not above the loop, so the ordinary-push assertion
still reports as run rather than hiding behind a skip.

Validation: `go test ./internal/versioncheck/ ./scripts/check-versions/` is
unchanged at 65 pass / 0 skip, with all three entrypoint subtests still
executing; both targets pass `bazel test --config=ci`; //scripts:scripts_test
(the tag-taxonomy and Bazel policy tests) passes; `bazel build //...` is clean
across 321 targets; `make bazel-sync` reports no drift and is idempotent.

* test(versioncheck): stop declaring the bazelignored npm manifest as Bazel data

The required `Bazel / test` lane failed on the refreshed head in fork-PR CI:

  TestRepositoryReleaseVersionsMatch
    npm package.json: open .../versioncheck_test.runfiles/_main/
    npm-package/package.json: no such file or directory (expected 1.3.0)

npm-package/ is in .bazelignore (#6798), so Bazel never links it into the
execroot, and a local sandbox cannot stage npm-package/package.json even
though //:release_metadata_files named it and analysis accepted the label.
It resolved only under remote execution, where the client uploads the file
from the workspace. That is how the previous fixup's `bazel test
--config=ci` passed on a host whose bazelrc defaults to remote execution.
Fork PRs get no remote-execution secrets, so CI runs the test in
processwrapper-sandbox, where it fails.

Drop the entry from the filegroup. Under Bazel only, let
TestRepositoryReleaseVersionsMatch tolerate exactly that surface's absence:
the file must be missing, and every other gated surface, the uv.lock pin and
the hook markers must pass. The test logs the gap. This mirrors the base's
skipReleaseFormulaUnderBazel for the bazelignored .beads/. `go test`, which
sees the real checkout, still checks the npm manifest.

Validation: forcing local execution the way fork CI runs (`bazel test
--config=ci --nocache_test_results --remote_executor=
--strategy=TestRunner=processwrapper-sandbox`) reproduced the failure before
the change. After it, //internal/versioncheck:versioncheck_test,
//scripts/check-versions:check-versions_test and //scripts:scripts_test pass
(3 of 3 executed), and both release-gate targets also pass under remote
execution. Drifting a declared surface still fails the sandboxed run. The
tolerance was probed through TEST_SRCDIR and BEADS_TEST_REPO_ROOT: each of
these still fails:
- another drifted surface
- a present but mismatched npm manifest
- an unreadable canonical version
- plain `go test` with the manifest missing

`go test ./internal/versioncheck/ ./scripts/check-versions/`, golangci-lint
and `make bazel-sync-check` are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-10-01 07:46:37 -07:00
Julian Knutsen
291987ea22
ci(bazel): fork PRs use rbe-west's anonymous read-only cache (#7065)
* ci(bazel): fork PRs use rbe-west's anonymous read-only cache (mode cache)

Fork PRs (unless bazel-farm.yml authorized them), rbe=cache dispatches and
secret-less same-repo runs (Dependabot) now run in mode "cache": local
execution on ubuntu-latest as before, plus .bazelrc's new fork-cache config,
rbe-west's credential-free rbe-cache endpoint (instance oss, reads only).
rbe=off keeps the old local mode without the cache.

- .bazelrc: build:fork-cache. Only key-neutral flags (--jobs, --remote_*), so
  fork actions hash like trusted ones. --noremote_upload_local_results, and
  --remote_local_fallback plus
  --incompatible_remote_local_fallback_for_remote_cache: without both, a
  closed endpoint (farm kill switch) fails every action in GetCapabilities.
- setup-bazel: BAZEL_FORK_CACHE=true appends --config=fork-cache; it is
  mutually exclusive with the RBE secrets; new output cache.
- bazel.yml: RBE_INPUT_CACHE, mode cache, dispatch option cache; every
  setup-bazel step gets BAZEL_FORK_CACHE. Remote and fork-farm paths
  unchanged.
- bazel-gate.sh: cache/false is valid and skips what local skips.
- Policy tests: the two public endpoint lines are allowlisted in .bazelrc
  only; TestBazelForkCacheConfig pins the fork-cache contents and checks both
  fork-cache and remote-exec stay key neutral; decision, gate and rc-writer
  tests cover cache mode.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): fork cache gives up on a slow endpoint and uploads no BEP files

Review fixes for the fork read-only cache (mode cache).

- .bazelrc fork-cache: --remote_timeout 60 -> 15 and
  --experimental_circuit_breaker_strategy=failure, so a slow (not closed)
  endpoint stops being called once too many lookups fail instead of
  costing every lookup 60s x retries; --experimental_build_event_upload_strategy=local,
  because bazel.yml's --build_event_json_file and --profile otherwise make
  Bazel upload test logs and the profile over ByteStream. equivalence.py
  and check_testcases.py read test.xml from the local testlogs dir, not
  from BEP URIs, so they are unaffected.
- Policy test: parseBazelrcOptions now scans plain command lines too
  (lane checks still ignore them), so `build|common --config=fork-cache`
  is caught. Outside fork-cache and remote-exec, no line (test: lines
  included) may turn uploads on, turn either fallback off, or set a
  non-local BEP upload strategy. fork-cache must end with the breaker,
  the local BEP strategy and a --remote_timeout of 1-15s; keyNeutralFlag
  accepts the breaker and BEP-strategy flags.
- engdoc: the closed-endpoint fallback sentence now also describes the
  slow-endpoint path (timeout, breaker). bazel-farm.yml and pr.yml
  comments say fork PRs run in mode cache, not plain local.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): reconcile fork cache (mode cache) with the legacy embedded retirement

After the rebase onto D2 step 1 (#7071), two policy tests failed against
mode cache.

- evalRBEExpr learns `inputs.rbe == 'cache'` (bazel.yml's RBE_INPUT_CACHE).
  The decision itself is unchanged and right for mode cache: covered never
  depends on the mode, forks and Dependabot (now mode cache) keep the legacy
  tier, and a covered same-repo PR without the secret (now mode cache, not
  local) still turns pr.yml's gate red. The named cases now pin the mode
  too, and the "mode alone makes it red" check includes cache.
- TestBazelEmbeddedLaneCannotBeNarrowed treats fork-cache like remote-exec:
  a config setup-bazel's rc enables for every command. Its lines (and any
  config they reference) are now in use for the lane, so the rc narrowing
  regex applies to them, including a forbidden nested --config=. The
  setup-bazel scan accepts exactly --config=remote-exec and
  --config=fork-cache.
- Comments in bazel.yml, pr.yml, pr-risk.yml and the engdoc that said
  missing-secret, fork or Dependabot runs take mode local now say cache.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 05:24:06 -07:00
Jim Wordelman
a4bf13f042
Fix: test suites fail closed instead of open on the ambient Dolt port when no test container is started (be-napos) (#5885)
* test(dolt): red — testdb_* leak onto production Dolt port when Docker absent (refs be-h2h25)

* feat: green — Test suites create testdb_* on the PRODUCTION dolt server: harness fails open on the ambient port when Docker is absent (refs be-h2h25)

* docs(release-gate): add be-napos gate — ambient Dolt port fail-open to fail-closed

Deploy bead be-napos (build be-h2h25, review be-7fym1, verdict pass round 2).
7/7 gate criteria PASS; full independent evidence in the gate doc.

refs be-napos, be-h2h25, be-7fym1

* docs(release-gate): record PR link for be-napos gate

refs be-napos

* test(testutil): make the fail-closed gate deterministic, not Docker-conditional

The regression test skipped itself on every host that has Docker, by calling
the real EnsureDoltContainerForTestMain and skipping when it succeeded. That
asserted nothing on CI -- the only lane where it matters -- and on a
Docker-having host it also started the shared singleton container purely to
decide to skip, with no TestMain in internal/testutil to terminate it.

Add checkDoltFn, a package-level seam over checkDolt, so the test can force a
not-ready state without a Docker daemon and without starting a container. Only
EnsureDoltContainerForTestMain routes through it; the neighbouring t.Skip call
sites gate a skip rather than the fail-closed behaviour, so they keep calling
checkDolt directly.

The gate now covers all four not-ready states rather than the one the old test
happened to hit, which also pins the intent that an explicit
BEADS_TEST_SKIP=dolt opt-out must fail closed exactly as a Docker-less host
does. Split into a platform-independent half (the helper's own contract, both
variables cleared, idempotent) and a !windows half (the wiring, via the seam).

Red/green: with the neutralizeAmbientDoltPort call removed from the not-ready
branch, 4 of 4 subtests fail and 0 pass; restored, 4 of 4 pass in 0.06s with
no Docker and no container. (refs be-napos)

* fix(testutil): clear the ambient Dolt port on the Windows stub too

The Windows EnsureDoltContainerForTestMain returned its error without touching
BEADS_DOLT_SERVER_PORT / BEADS_DOLT_PORT, so the fail-open this branch fixes
still shipped there -- unconditionally, since that stub never succeeds. Windows
is a real lane: .github/workflows/pr.yml runs windows-latest on four jobs plus
the cross-platform matrix.

Gating it needed one pre-existing repair. testdoltserver_env_test.go has no
build tag but calls checkDolt, which is !windows-only, so the internal/testutil
test binary has never compiled for Windows -- reproduced identically on
origin/main. Tagging that file !windows fixes the whole package's Windows test
lane; without it a new Windows gate would compile nowhere and assert nothing,
which is the same defect this branch is already correcting.

Verified GOOS=windows go vet ./internal/testutil/ clean (it fails on
origin/main), and GOOS=windows go build clean before and after. The Windows
gate itself is compile-verified only -- no Windows host here to execute it.
(refs be-napos)

* docs(testing): state that ambient BEADS_DOLT_*_PORT is never honored

The guard fires on every not-ready state, not only "Docker unavailable" -- a
missing or wrong-version image and an explicit BEADS_TEST_SKIP=dolt opt-out
clear the ambient port too. That is deliberate: the invariant is the absence of
a test container, not the reason for it. Say so where the next person will look
before investigating, and name the supported way to target a specific server.
(refs be-napos)

* chore: remove leaked internal release-gate doc from PR branch

  release-gates/be-napos-ambient-dolt-port-failclosed-gate.md

Tracked our internal gc-management/beads-rig release-gate checklist and
should never have been committed to this upstream branch -- it's process
residue from our deploy tooling, not part of the change itself.

Per maintainer bee-ghosttrack's request during review of PR #6571. The
root cause (our deploy tooling auto-committing this file) is already fixed
as of gm-qatxl1; this branch predates that fix, so this commit is cleanup
only -- no other content on this branch is touched.

Ref: be-lk7o3

* chore(bazel): enumerate the PR's new test files in BUILD.bazel

Base added BUILD.bazel to internal/testutil and internal/storage/dolt after
this PR was opened (#6881 made the Bazel lane real, and fork PRs always run
it). The four new test files this PR adds were therefore absent from the
go_test srcs lists, which the bazel lane's equivalence check reports as a
missing target.

Generated by 'make bazel-sync' (gazelle), not hand-edited, because the CI
drift step diffs against exactly what gazelle emits.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(testutil): reconcile the shared-server harness with the fail-closed clear

Review iterations 1-2 (adopt-pr, PR #5885): every gating finding from both
review syntheses, plus their minors and nits.

Iteration 1, Major 1 (Change Impact / Blast Radius). scripts/test.sh's
BEADS_TEST_SHARED_SERVER=1 flow starts a dockerless `dolt sql-server` and
exports BEADS_DOLT_PORT for every package to reuse. checkDolt() has no notion
of an already-provisioned shared server, so on that flow's primary audience --
a host without Docker -- all 12 EnsureDoltContainerForTestMain callers erased
the harness's own sanctioned port before m.Run(), turning green dockerless runs
red, while engdocs/CI_TEST_SURFACE_AUDIT.md and the new TESTING.md paragraph
advertised the two mechanisms unreconciled.

Taken: a dedicated marker, BEADS_TEST_SHARED_DOLT_SERVER, exported by
scripts/test.sh beside the port it allocated, which the helper's failure paths
honor. Both docs state the reconciliation, including the precedence: a
container, where one can be started, still overwrites both variables. Not
taken: "skip the clear when BEADS_TEST_SHARED_SERVER=1 and a port var is
already set". That flag is overloaded (cmd/bd/shared_server_integration_test.go
reads it too), and the script starts no server when a port is already set, so
the flag beside a port is exactly the case where the port is ambient.

Iteration 2, blocker (Behavioral Correctness). Iteration 1 shipped that marker
as a boolean ("1") which spared BOTH port variables, while the script vouched
only for the BEADS_DOLT_PORT it exported and its entry guard never looked at
BEADS_DOLT_SERVER_PORT -- the variable applyConfigDefaults resolves first. The
runner's test environment (beads_test_env_enter) unsets both variables before
the flow runs, so the hole needed that isolation skipped, e.g. with the
documented BEADS_TEST_ENV_DISABLE=1; then an inherited BEADS_DOLT_SERVER_PORT
reached `go test` beside the marker and outranked the shared server --
gm-2g3g5r, re-opened by its own fix. Measured with a fake `go` that prints its
environment: SERVER_PORT=59999 PORT=<shared> MARKER=1 under the iteration-1
script. Now:

  - the marker's value is the port it vouches for, and the helper decides per
    variable (neutralizeUnvouchedDoltPorts): only a variable holding exactly
    that port survives, and says so on stderr; every other one is cleared,
    marker or not;
  - the flow starts only when neither port variable is set, and says on stderr
    when BEADS_TEST_SHARED_SERVER=1 is ignored for that reason.

Not taken: also exporting BEADS_DOLT_SERVER_PORT from the flow. The widened
guard means it is always unset there, so the export adds no safety, and five
sites read that variable alone (internal/doltserver/doltserver.go:796,
cmd/bd/init.go:773 and :1351, cmd/bd/bootstrap.go:857,
internal/testutil/testdoltbranch.go:164) -- consumers the flow has never fed.

Iteration 2, minor (Test Evidence Quality). The exception's second arm, a
container that would not start, was reached by no test with its guard live.
Both failure paths now share one clear, and the container start is a seam
(startSharedContainerFn, pinned to startSharedContainer by identity) so tests
reach that path without consuming doltServerOnce.
TestEnsureDoltContainerForTestMain_KeepsHarnessProvisionedPort runs its whole
table, marked_but_divergent_var included, through both paths.

Iteration 2, minor (Contract & Interface Fidelity). The marker prose in
TESTING.md, CI_TEST_SURFACE_AUDIT.md, test.sh and testdoltserver.go describes
the per-port behavior the code now implements.

Iteration 1, Major 2 (Contract & Interface Fidelity). neutralizeAmbientDoltPort's
doc comment claimed "With no port resolvable, applyConfigDefaults'
BEADS_TEST_MODE guard forces port 1". Clearing the env vars is not "no port
resolvable": resolution falls through to the file chain and derives a
directory from filepath.Dir(cfg.Path) when BeadsDir is empty
(store.go:1661-1664), so a reachable .beads/dolt-server.port still yields a
non-zero port and the ServerPort == 0 arm (store.go:1683-1687) never fires;
production-port detection is strictly narrower than resolution. Narrowed to
what the change actually guarantees -- no environment-named port is honored --
at all three sites carrying the claim: the helper doc, the TESTING.md
paragraph, and TestApplyConfigDefaults_NoResolvablePortFailsClosed's own
comment, whose fixture (an empty beadsDir) is what excludes the surviving
path. The residual stays tracked in be-rl6tm. That test's stale
cross-reference to a renamed test is corrected in the same pass.

Iteration 1, minor (Test Evidence Quality). The Windows gate's comment claimed
a CI lane it does not have; it now states the coverage exactly --
compile-checked, not CI-executed -- and lists the four windows-latest jobs'
named selectors.

Iteration 1, nits. doltServerErr is read under doltServerMu via
sharedContainerErr(); TestCheckDoltFn_DefaultsToRealProbe pins function
identity with reflect instead of asserting non-nil, which any leaked stub
satisfied.

Mutation ledger (scoped `go test ./internal/testutil/`, scrubbed env; every
mutant restored from a copy and verified byte-identical):

  a set marker spares every    marked_but_divergent_var, divergent_legacy_var,
  variable (the i2 blocker)    marker_names_neither_var and boolean_marker red
                               on BOTH failure paths
  the marker covers            marked_but_divergent_var, marker_names_neither_var
  BEADS_DOLT_PORT only         and boolean_marker red on both paths
  presence instead of value    the same red set as the first row
  no clear after a failed      the 5 container_start_failed cases that expect
  container start              a clear red; every not_ready case stays green
  start attempted before the   all four incumbent fail-closed subtests and
  probe                        every not_ready case red
  leak a wrapper into          StartSharedContainerFn_DefaultsToRealStart red
  startSharedContainerFn
  delete the hermetic          ClearsAmbientPortWhenNotReady red
  t.Setenv, marker ambient
  at the fixture's port

Full package green with Docker, including the real-container
EnsureDoltContainerForTestMain path (43 test and subtest passes, no skips);
`go test ./scripts/`, which drives test.sh, green; `GOOS=windows go vet
./internal/testutil/` clean; `tools/bazel/go_srcs.py --check` clean, and no
BUILD change is due (no new files, no new non-stdlib imports).

Deferred deliberately: the iteration-1 synthesis's optional windows-latest step
for ./internal/testutil/. It is newly feasible -- this branch is what made the
package's Windows test binary compile -- but it would also newly execute four
pre-existing test functions in this package that have never run on Windows, so
it belongs in its own change. RequireDoltContainer's unsynchronized
doltServerErr read is base-owned and left alone for the same reason.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julian@gastownhall.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-10-01 05:21:49 -07:00
Isis Anisoptera
45a116d1a7
fix(update): fence unforced --notes overwrites behind --force across all surfaces (#5946)
* fix(update): fence unforced --notes overwrites behind --force across all surfaces

bd update --notes silently replaced existing notes, destroying handoff
history. The contract now refuses an unforced overwrite of non-empty
notes with ErrNotesOverwrite (409 notes_overwrite_refused over HTTP,
force_notes_overwrite to override), enforced inside the mutation
transaction on both the dolt and uow backends, for single updates and
batch apply alike. CAS guards keep precedence: a stale
--if-assignee/--if-status still surfaces as the exit-13 mismatch, on
both backends, before the fence speaks.

CLI: --force and --if-assignee are no longer mutually exclusive (that
exclusion made overwriting under a guard impossible); both update
routes translate the fence's sentinel into the same actionable advice
(--force to overwrite, --append-notes to preserve history), and the
post---force warning is worded as an audit statement. The shipped
plugin skill docs and bd note help now prescribe --append-notes for
handoffs instead of the newly fenced bare --notes.

The fence is the single enforcement point: no client-side pre-read
copies of the rule. Conformance contracts, unit tests for
AuthorizeNotesOverwrite, and embedded/proxied/httpapi regression
coverage included.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MAFpn9pUw8WKMfymteZHbh

* fix(update): exempt explicit clears from the notes fence; share its predicate

CI surfaced three gaps in the fence's reach:

- Clearing notes (--notes "" / patch.notes: "") was refused, diverging
  from every sibling text field's clear and from the backend behavior
  contracts. The fence now targets only its actual footgun — replacing
  non-empty notes with different non-empty content — via a single shared
  predicate, issueops.NotesReplacement, used by both the contract's
  AuthorizeNotesOverwrite and the CLI's warning path, so the two can no
  longer drift. Prose updated to match everywhere the rule is stated
  (ErrNotesOverwrite, ForceNotesOverwrite, OpenAPI spec + regenerated
  types).
- The revision-CAS integration tests' incidental concurrent writes now
  patch design instead of notes, so they no longer depend on notes-fence
  semantics at all.
- The historical-upgrade harness deliberately replaces fixture notes and
  asserts the new value; its two bd update --notes calls now pass
  --force.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MAFpn9pUw8WKMfymteZHbh

* fix(update): address review — changelog BREAKING entry, problem.go doc block, close-policy-under-guard test

Review follow-ups on #5946 (bee-ghosttrack, MERGE-AFTER-FIXES):

- CHANGELOG: BREAKING entry under [Unreleased] ### Changed for the notes
  fence on both wires (CLI exit 1, HTTP 409 notes_overwrite_refused), with
  the --force / --append-notes migration line. It also names the two
  deliberate edges: the explicit-clear exemption, and --force widening to
  the close-policy half under --if-assignee now that the flag pair is legal.
- problem.go: CodeNotesOverwrite's comment had landed inside
  CodeDependencyCycle's doc block; each const now sits under its own docs.
- assign_fence_embedded_test.go: pin the previously untested close-policy
  half of --force under --if-assignee (refused unforced, authorized forced).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED

* test(update): align TestWarnNotesReplacement with the post-fence warning copy

The test landed on main after this branch was cut and pins the pre-fence
wording, where the warning fired on any unforced overwrite. Since the fence,
an unforced overwrite is refused outright and warnNotesReplacement fires only
after a forced one — the audit trail for a habitual --force — so the copy it
pins is now '--force replaced existing notes'.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED

* docs(import): record bd import's notes-fence exemption as by-design (GH#6190)

Import consults none of the per-field live-state fences — notes overwrite,
live-claim reassign, close policy — and that is the intended shape, not an
omission: its contract is wholesale row replacement, guarded by its own
staleness check (only strictly-newer rows rewrite local state, --allow-stale
is the single deliberate-overwrite opt-in) and reported field-by-field in
updated_issues. Named in AuthorizeNotesOverwrite's enforcement-boundary
comment and in bd import's help; the published CLI docs pick the help text
up at the next release pin bump.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED

* fix(update): refuse --notes "" and add --clear-notes; stop --notes help reading as additive

GH#6021: an empty --notes wiped the whole notes field at exit 0 behind the
same ✓ Updated receipt as a successful write — and the empty string is
exactly what a dead command substitution collapses to. The empty value is
now refused on both CLI routes (the accident and the deliberate clear are
the same bytes at the flag layer), and the deliberate clear gets its own
verb, --clear-notes, mutually exclusive with --notes/--append-notes. A verb
rather than the proposed --allow-empty-notes opt-in: what needs authorizing
is an intent, not an input path — --allow-empty-description unblocks
stdin/file plumbing, which notes does not have — and an opt-in passed
habitually would silently disarm the guard while a habitual --clear-notes
fails loudly. --force does not bypass the refusal; the fence's clear
exemption stands, so the verb alone authorizes the erase. The HTTP API is
unchanged: patch.notes "" still clears.

GH#6272: bd update --help called --notes "Additional notes" and the prime
text said "Add supplementary notes" — both read as appending, so agents
following the injected guidance faithfully clobbered prior context. The
update help now names the operation with the --append-notes contrast at the
point of use, the shared/create help is field-named like --description and
--design, and the prime line points at bd update --append-notes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JyuQ6Tjv3D7tpNqeb2WDED

* fix(bazel): enumerate the PR-new files in cmd/bd and issueops srcs

The base added cmd/bd/BUILD.bazel and internal/storage/issueops/BUILD.bazel
with EXPLICIT srcs lists after this branch was cut, so the three files this
PR adds were never enumerated:

  cmd/bd/update_notes_guard.go        (go_library bd_lib)
  cmd/bd/update_notes_guard_test.go   (go_test bd_test)
  internal/storage/issueops/aggregate_authorize_notes_test.go (go_test)

The go_library omission is a hard build break, not a silent skip:
update.go:215,220 and update_input.go:106,111 are enumerated and call
validateNotesUpdate / clearNotesRequested, so //cmd/bd:bd_lib compiles the
callers without the callee. bazel.yml arms unconditionally for fork PRs
(head.repo.fork == true) and builds //cmd/bd:bd + //cmd/bd:bd_test, so this
reds the lane. make bazel-sync-check cannot see it -- go_srcs.py only
validates the glob-based go_srcs filegroup, never the rule srcs lists.

Generated by make bazel-sync (gazelle), not hand-edited, so the workflow's
own BUILD-files-in-sync drift step agrees byte-for-byte.

* fix(notes): name --clear-notes in bd note's rm guidance, correct the fence boundary comment, pin both request-shape rules

Takes all three non-gating minors from the review. No behavior change: two
prose fixes and two test cases.

1. cmd/bd/note.go's rm|remove|delete branch advised
   `bd update <id> --notes "text" --force` under "To change or clear notes",
   but clearing through --notes is exactly what this PR made impossible --
   validateNotesUpdate refuses an empty value unconditionally and --force does
   not reach it. The branch now names both verbs separately: --notes --force to
   replace, --clear-notes to clear. The edit and update branches speak only of
   replacing and were already correct, so they are untouched.

2. aggregate.go's enforcement-boundary comment claimed the UpdateIssueInTx
   funnel's "one notes-replacing caller is bd edit". Under this PR's own
   NotesReplacement predicate there are at least four more (bd note's
   read-combine-write, bd defer --reason, bd rename and delete-tombstoning's
   mechanical ID rewrites, bd compact's clears). The exemption is still sound --
   every funnel writer derives its new value from the current notes -- so the
   comment now names those CLASSES instead of a single caller, which is the
   claim that is actually true and that a future fence auditor can check.

3. Both branches this PR adds to ValidateUpdateRequest were uncovered: the
   batch apply leg reaches them here and nowhere else, while the single-issue
   HTTP handler's own pre-check returns before storage. Added a sibling table
   (the existing one varies only the patch; these two rules are properties of
   the REQUEST) with a case each. Mutation-checked, disjoint: neutralizing the
   force-without-notes branch reds only the first case, neutralizing the
   notes+append branch reds only the second, and the pre-existing
   canonical-fields table stays green under both.

Not an amend of 5ffcc9c16c: that commit's message states it was generated by
make bazel-sync and not hand-edited, so folding hand-written Go into it would
falsify the claim its own BUILD-files-in-sync argument rests on. No new files,
so the srcs lists it repaired stay correct.

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-10-01 05:02:40 -07:00
Julian Knutsen
46e670abbf
ci: retire PR Risk's legacy embedded tier where the gated Bazel lane runs it (D2 step 1) (#7071)
* ci(pr-risk): stand down legacy embedded tier where the gated Bazel lane runs it

D2 step 1. A new bazel-embedded-coverage job decides, from the same
expressions as bazel.yml's rbe job, whether pr.yml's Bazel call takes
execution mode remote on a same-repo pull_request (RBE_WEST_WORKERS on,
executor secret present, not a fork). Only then do test-embedded-storage,
test-embedded-conformance and test-embedded-cmd (27 jobs) skip, and PR
Risk's gate accepts those skips only then; a failed or missing decision is
red. Forks, Dependabot, secret-less runs, the farm switch unset and
merge_group keep the legacy tier. build-embedded keeps running: its
artifact feeds the proxied and server Dolt jobs.

The decision job reads no repository code and the secret only as an
emptiness test. scripts/pr_risk_bazel_coverage_test.go runs both actual
decision scripts over every event/var/secret/fork combination and requires
covered <=> (pull_request && Bazel mode remote), pins the shared env
expressions, checks pr.yml still requires BAZEL_EMBEDDED and shares PR
Risk's triggers, and simulates PR Risk's gate over every tier/decision.

Revert: unset RBE_WEST_WORKERS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the retired legacy embedded tier in the check topology

Who keeps the legacy tier, how the decision and gate work, the drift
guard, the residual cross-run race, the conformance.yml duplicate, and
how to revert (unset RBE_WEST_WORKERS).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(pr-risk): retire the embedded tier by committed flag; pr.yml gate fails closed

Review F1. PR Risk's coverage decision read the mutable RBE_WEST_WORKERS
variable in a different run from pr.yml's rbe job, so unsetting it and
re-running one workflow could leave both required checks green with
neither the legacy tier nor the Bazel lane having run the tier.

- Both workflows now commit BAZEL_RETIRES_LEGACY_EMBEDDED (policy-tested
  equal) and run the identical bazel-embedded-coverage job:
  covered = flag && pull_request && !fork && executor secret present.
  RBE_WEST_WORKERS is no longer read by PR Risk at all.
- pr.yml's ci-gate requires the job's result (BAZEL_EMBEDDED_COVERAGE)
  and BAZEL_EMBEDDED_RETIRED, which is red when covered but the Bazel
  embedded lane did not run remotely and pass (mode skip included).
- Revert is a commit of the flag to "false" in both workflows; in-flight
  PRs pick it up on their next push. The kill-switch runbook now flips
  the flag first.

Tests run both decision steps, bazel.yml's rbe step and pr.yml's real
gate step over every event/var/secret/fork/flag combination, with the
variable differing between the two runs, and require no double-green
without the tier.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): never cache embedded-tier test results

Review F2. Since D2 step 1 the Bazel embedded lane is the tier's only
pre-merge run on same-repo PRs, so a cached PASS (stale, or a poisoned
entry in the shared farm action cache) or a cached run that never
re-exercises an intermittent -race finding would stand in for the legacy
jobs' -test.count=1 run. test:embedded now sets --nocache_test_results,
and the policy test requires it and forbids any other rc line that turns
test result caching back on.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): forbid flaky-test retries in the gated Bazel lanes

Review F3. Adding --flaky_test_attempts to a lane's config or
flaky = True to a lane target passed every policy test, and would hide
a flaky failure the legacy jobs (which ran each test once) would have
reported; since D2 step 1 nothing else runs the embedded tier on
same-repo PRs. TestBazelGatedLanesNeverRetryFlakyTests rejects
flaky_test_attempts and runs_per_test_detects_flakes in .bazelrc,
.github (workflows, setup-bazel's generated rc) and tools/bazel, and
flaky = True in every BUILD file and .bzl macro.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): pin the Bazel embedded lane's command line and config

Review F4. An extra --test_arg=-test.short/-test.skip on bazel.yml's
`bazel test //... --config=embedded` line, or a test:embedded
--test_filter in .bazelrc, narrowed the tier while every policy test
passed (check_testcases only rejects a shard with zero tests). Since D2
step 1 this lane is the tier's only pre-merge run on same-repo PRs, so:

- bazel-embedded's test step must be exactly the pinned script;
- the --config=embedded lines must be exactly the pinned list, in order;
- no unconfigured common/build/test line, and nothing setup-bazel's
  generated rc writes, may select or narrow tests (test_filter,
  test_arg, -test.short/run/skip, tag/size/lang/timeout filters).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): add the D2 policy tests to scripts_test

scripts/pr_risk_bazel_coverage_test.go was missing from
//scripts:scripts_test's srcs, so `bazel test //scripts:scripts_test`
(and the BUILD-sync check) did not see it. The repository-walking
flaky-retry test skips under Bazel, whose runfiles hold no other
package's BUILD files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): check every listed embedded test ran in its Bazel shard

Review F5. The shard scripts discover tests from source with grep, but
each Bazel test binary holds only its target's srcs, so a discovered test
the binary lacks matches nothing in the shard's -test.run selector and
passes silently (check_testcases.py only rejects a shard with no tests).

tools/bazel/check_shard_coverage.py runs each shard script in list-only
mode (BEADS_TEST_SHARD_LIST_ONLY=1) and requires every Bazel shard's
test.xml to hold exactly the listed top-level tests: missing, extra,
wrong-shard, shard-count mismatch, missing test.xml and a failing script
are errors. bazel-embedded runs it after the tier for
//cmd/bd:bd_embedded_test (20) and embeddeddolt_embedded_test (5); the
policy test pins the suites to pr-risk.yml's jobs and shard counts, and
a fixture test exercises the script.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): correct the D2 enforcement, re-run and merge-queue claims

Review F6.
- The beads-only ruleset enforces both gates on main only; release/**
  PRs run them but merging does not wait for them, before and after D2.
- There is no merge queue and strict is off: merge_group runs are not a
  pre-merge safety net for the retired tier.
- Spell out "Re-run all/failed jobs" semantics under the committed flag,
  the remaining secret-deletion window, and that the revert needs a new
  push to in-flight PRs.
- Record the lane hardening the retirement relies on (no result caching,
  no retries, pinned selection, per-shard coverage check).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): drop TestMain from the embedded shard-coverage check

Re-review G1 (blocking). embedded-storage-test-shard.sh discovers tests
with `grep '^func Test'`, which also lists TestMain(m *testing.M)
(internal/storage/embeddeddolt/test_fixture_test.go). It is never a
<testcase>, so check_shard_coverage.py reported it missing on every real
remote run, turning bazel-embedded and CI Gate red on every same-repo PR.

The checker now drops NOT_TESTS = {TestMain}. The shard scripts are left
unchanged so the legacy jobs' -test.run selection stays byte-for-byte the
same (dropping TestMain there would be harmless to shard assignment,
which hashes per name, but would touch the legacy CI scripts this step
does not otherwise change).

TestEmbeddedShardScriptsListOnlyRealTests runs both real shard scripts
in list-only mode for every shard and requires each listed name to be a
`func Name(t *testing.T)` in the package, or in NOT_TESTS (which may hold
only TestMain, and only if it is not a test). The fixture shard script
now lists TestMain too, so the filter itself is exercised.

Verified on a real remote run (`bazel test //... --config=embedded
--config=remote-exec`, 4/4 targets, 27 test.xml, 582 top-level tests,
348 s uncached): check_testcases.py and check_shard_coverage.py both
pass (199 cmd + 381 storage tests); the previous checker failed on
TestMain.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(pr-risk): decide embedded coverage by actor, not by the executor secret

Re-review G2. covered still read secrets.RBE_WEST_EXECUTOR, which an admin
can delete between PR Risk's run and a re-run of pr.yml: PR Risk stayed
green with the legacy tier skipped, while the re-run computed covered =
false, took mode local and passed with no embedded lane.

Both workflows' bazel-embedded-coverage now decide
covered = flag && pull_request && !fork && github.actor != dependabot[bot]
and read no secret or variable at all (PR Risk now reads no secret).
Dependabot (no Actions secrets) keeps the legacy tier; github.actor,
unlike triggering_actor, survives a re-run by someone else. A same-repo
PR without the secret is covered, so pr.yml's gate goes red (mode local)
instead of passing.

The two-run test matrix now varies the secret as well as RBE_WEST_WORKERS
between PR Risk's and pr.yml's runs, adds the actor to the facts, and
names the missing-secret case (red). Docs updated: the residual is gone,
the cost of failing closed is recorded.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): close the remaining ways to narrow the Bazel embedded lane

Re-review G3. Skip-inducing edits outside the pinned --config=embedded
lines and command line still passed every policy test (reviewer
survivors m1, m2, m5, m6, m9, m10, m11), and the runtime checks counted
skipped testcases as run.

TestBazelEmbeddedLaneCannotBeNarrowed now rejects:
- any .bazelrc line of a config the lane uses (unconfigured, embedded,
  remote-exec from setup-bazel's rc, and any config they reference) that
  filters, narrows, re-runs or re-routes tests (test_filter, test_arg,
  -test.*, *_filters, test_env=BEADS_TEST*/GO_TEST*/TESTBRIDGE*,
  --config=, cache_test_results, run_under other than test_env, flaky,
  runs_per_test, sharding strategy);
- any import other than the two gitignored try-imports, and any
  committed rc file besides .bazelrc (try-import would load it in CI);
- -test.short/run/skip/list, BEADS_TEST_SKIP, BEADS_TEST_EMBEDDED_DOLT,
  TESTBRIDGE_TEST_ONLY and similar in tools/bazel/*.sh (test_env.sh,
  go_test_manifest_shard.sh, ...) and anywhere in the setup-bazel action,
  and any --config= there but remote-exec;
- any change to the set of embedded-tagged targets or their args/env.

At run time check_shard_coverage.py fails a shard whose top-level tests
were all skipped, and its new --whole option applies the same check to
the unsharded conformance core/audit targets (added to bazel-embedded's
step). The real remote run still passes (no shard is all-skipped today;
one cmd shard has 1 of 9 tests skipped).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): ask Bazel for flaky test targets before the embedded tier

Re-review G4. The F3 grep wanted a literal `flaky = True`, so
`flaky = _RETRY` (or a macro default) slipped through (reviewer m3).

- bazel-embedded runs `bazel query 'attr(flaky, 1, tests(//...))'` after
  setup-bazel and before the tier, and fails on any result (loading only;
  about 0.2 s warm). Verified locally: with `_RETRY = True` /
  `flaky = _RETRY` on embeddeddolt_embedded_test the query lists it.
- The policy grep now rejects any `flaky =` whose value is not a literal
  False or 0, and TestBazelEmbeddedQueriesFlakyTargets pins the step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): cover the zero-testcase shard in check_shard_coverage

Re-review G5. Skipping the "listed but did not run" report when a shard's
test.xml has no top-level tests survived the fixture test (reviewer m7);
check_testcases.py catches that shard at run time, but the coverage
check should not depend on it. Two fixture cases: a shard with no
testcases, and one with only a subtest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the G1-G5 embedded-lane hardening in the topology doc

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 02:03:46 -07:00
Jim Wordelman
c39430e3ee
ci: disable Ryuk reaper on Dolt testcontainer steps to fix parallel-binary flake (#5770)
* test(ci): red — pin TESTCONTAINERS_RYUK_DISABLED on Dolt testcontainer steps (refs be-2on)

* feat: green — pin TESTCONTAINERS_RYUK_DISABLED on Dolt testcontainer steps (refs be-2on)

Sets TESTCONTAINERS_RYUK_DISABLED=true on the 5 CI step-instances that start
a Dolt testcontainer from a package TestMain: pr.yml and main.yml's
test-domain-uow job ("Test domain + uow + tracker" and "Test doctor/fix"
steps), plus main.yml's test job "Test (with coverage + JUnit XML)" step,
whose unfiltered ./... sweep runs internal/storage/dolt, internal/molecules,
internal/tracker, and cmd/bd as concurrent Dolt-container-starting binaries.

testcontainers-go shares one Ryuk reaper per host; when a step runs multiple
such packages as concurrent test binaries, they race to attach to that
shared reaper, and a failed handshake from one process reaps a sibling's
live container mid-suite. GitHub Actions runners are destroyed after the
job, so the reaper buys nothing there and only costs this race.

* docs(release-gates): record be-9b8 deploy gate PASS

* chore: remove leaked internal release-gate doc from PR branch

  release-gates/be-9b8-dolt-ryuk-reaper-gate.md

Tracked our internal gc-management/beads-rig release-gate checklist and
should never have been committed to this upstream branch -- it's process
residue from our deploy tooling, not part of the change itself.

Per maintainer bee-ghosttrack's request during review of PR #6571. The
root cause (our deploy tooling auto-committing this file) is already fixed
as of gm-qatxl1; this branch predates that fix, so this commit is cleanup
only -- no other content on this branch is touched.

Ref: be-lk7o3

* fix(ci): drop the inert main.yml test-job Ryuk pin; narrow the guard's universal

Maintainer review fixup for PR #5770 (adopt-pr review iterations 1 and 2).

Iteration 1, Finding 1 (major, correctness) — the main.yml `test` job's
`./...` sweep cannot start a Dolt testcontainer, so the pin there was inert
and its justification comment was false. `checkDolt` (internal/testutil/
testdoltserver.go) reaches `doltReady` only via `isDoltImageCached`
(`docker image inspect`, no auto-pull), and the image's only CI source is
scripts/ci/pull-dolt-image.sh, which in main.yml runs in `test-domain-uow`
and `test-proxied-cmd` — not in `test` (no services: block either). The
base already documents this in pr.yml's contract-corpus header ("every
broad ./... job skips them for want of a Dolt store"). Took the synthesis's
option (a): removed the env pin + its 7-line comment and dropped the fifth
guard row, rather than keeping a dead pin. This also moots the Finding 3
nit, whose four-package list was a sample presented as a census.

Iteration 1, Finding 2 part 1 (major, maintainability) — the guard's doc
comment claimed it pins "every CI step that starts a real Dolt
testcontainer" while the implementation is an allow-list of literal
triples. Narrowed the claim to the enumerated steps, stated the scope as
the `test-domain-uow` job (noting the single-package doctor/fix step is
pinned for in-job consistency, not because it has an in-step sibling), and
recorded the container-capable jobs left unpinned: pr.yml/contract-corpus,
main.yml/test-proxied-cmd, pr-risk.yml/test-proxied-cmd,
pr-risk.yml/test-server-storage(-full), regression.yml/regression, and
bazel.yml's --config=docker lane — the last needing --test_env since bazel
does not forward ambient environment. Part 2 (class detection) is left as
follow-up.

Iteration 2 (two minors, both taken):
- The doctor/fix step's comment in main.yml and pr.yml read "Same
  shared-Ryuk-reaper race as the step above", contradicting the guard's
  own scope note: that step runs a single package, so no sibling test
  binary races it for the reaper. Both copies now say the pin is kept for
  consistency with the step above.
- The guard's census named bazel.yml/bazel-docker, a job current main
  replaced (#6898) with bazel-doltserver, which defaults to
  --config=doltserver and pre-pulls the Dolt image only on a
  dolt-lane=docker dispatch. The census now names the lane by its
  --config=docker selector, which is accurate on this base (the
  bazel-docker job) and on current main (the dispatch-only A/B control),
  and the --test_env remark is scoped to that docker lane.

Validation: git diff --check clean; ./scripts/ package green;
TestDoltTestcontainerStepsDisableRyuk runs 4 subtests, matching the 4 pins
exactly (main.yml x2, pr.yml x2); flipping main.yml's doctor/fix pin to
"false" reds only that subtest with a step-specific message, and the file
restores byte-identical. `git merge-tree --write-tree origin/main HEAD` is
clean and ./scripts/ is green on the merged tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 01:24:46 -07:00
ecuthiell
46f182aa26
fix(ci): require direct workflow build tags (#5679)
* fix(ci): require direct workflow build tags

Parse workflow run scalars structurally and require recognizable direct Go commands to declare the literal gms_pure_go tag. Keep shell and Make checks lightweight and preserve their existing conventions.

Fixes #5527

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* fix(ci): recognize double-dash Go build tag flags

Address PR #5679 review 5191180453. Preserve last-tag precedence and test argument boundaries, including --args.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(ci): bazel-sync the new checker, restore its opt-out and the Bazel census

Maintainer review fixes for PR #5679, adoption iterations 1 and 2. Iteration
1's synthesis is `request_changes` on one major plus three minors; all four
are addressed. Iteration 2 approves with one minor, also addressed.

Major (Release Safety): the PR adds two production Go packages with no
BUILD.bazel, so `bazel build //...` could not see them and the repo's own
"BUILD files in sync" step fails on the resulting gazelle drift. Added the two
generated files via `make bazel-sync`; yaml.v3 is already a direct go.mod
requirement, so no module change is owed.

Minor (Release Safety): the new checker runs in the required pr-policy lane with
no way out, while the shell checker it partly replaces honors
`# build-tags: allow-bare` in a file's first five lines (check-build-tags.sh, and
engdocs/ICU-POLICY.md documents that window). CheckDir now honors the same
marker in the same window -- one convention, not two -- pinned by a table that
includes the fifth line and the sixth, so the two checkers cannot drift apart on
where the window ends.

Minor (Change Impact): dropping the workflow glob from `candidates` moved
workflows to the Go checker but also, silently, out of the `bazel_users` census --
and the Go checker does no Bazel handling at all, so .bazelrc could have lost its
tag with this gate still green. Workflows now feed the census through their own
`git ls-files` list and a separate loop, deliberately not rejoining the `go`-verb
scan. This is not hypothetical: `.github/workflows/bazel.yml` matches the Bazel
invocation regex, so it is exactly the file the census was losing.

Minor (Test Evidence): `Line` is the operator-facing half of a violation -- it is
what the error message points at -- and nothing asserted it, so reporting every
violation at line 1 would have been invisible. Added a `wantLine` column, asserted
on the multi-line "source is not workflow authority" case (line 2), and asserted
`Path`/`Job` where CheckDir fills them in.

One deviation, recorded: the finding also asked for `Line` on the existing
"continuation" case. That case is tagged, so it reports no violation and has no
Line to assert. Added a continuing-but-violating case instead, which makes the
same attribution observable -- a logical line spanning three physical ones is
reported at the first.

Not included: `make bazel-sync` also wants `//internal/debug` in
internal/utils/BUILD.bazel. That is base drift, not PR content -- absent at this
branch's rebase base but already present on origin/main, 24 commits ahead -- so it
heals on the next base refresh, and carrying it would duplicate main's own fix on
a file this PR never touches.

Minor (Test Evidence, iteration 2): the census half of the Change Impact fix
was right in code but pinned by nothing -- turning the workflow `bazel_users`
append into a no-op, or feeding the census-only list into the `go`-verb loop,
left every check_build_tags_test.go case green. Two cases on the existing
fixture harness now pin both directions: a workflow that runs `bazel build`
with an untagged .bazelrc fails and is named as the Bazel user, and a workflow
`run: go test ./...` passes here because scripts/checkworkflowtags owns it.
Each fails under its mutant, as does one more apiece (re-adding the workflow
glob to `candidates`; dropping `*.yml` from the census list), while the three
existing cases stay green under all four.

Validation: ./scripts/workflowtags passes (all four CheckDir tests and the full
CheckRun table), `go vet ./scripts/...` clean, `bash -n` clean, and both checkers
run green against the repository itself -- check-build-tags.sh reports 90 files
scanned all clear, and checkworkflowtags reports all direct commands clear.
For iteration 2, `go test ./scripts/` passes, and on a merge with current main
`bazel test //scripts:scripts_test` passes too; on this branch's own base that
target cannot build, because of the internal/utils drift noted above.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(ci): pin main.yml's bd-cmd-test build to the literal gms_pure_go tag

#6940 pinned main.yml build-artifacts' non-race bd-cmd-test build as
`go test -tags "$BEADS_BUILD_TAGS" -c -o artifacts/bd-cmd-test ./cmd/bd`.
This PR requires a literal gms_pure_go tag on direct workflow Go commands
and rewrites that line to `go test -tags gms_pure_go -c ...`, so on
current main TestBazelDoltServerTiersMirrorPRRisk fails in both
`go test ./scripts` and //scripts:scripts_test. Restoring the pinned
spelling is not an option: checkworkflowtags rejects it ("direct `go test`
must declare literal gms_pure_go in -tags").

Update the pin to the literal spelling. It still pins what #6940 cares
about, a non-race bd-cmd-test built from ./cmd/bd: adding -race to that
line still fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 01:24:03 -07:00
ecuthiell
9eaa4c1aaa
test(ci): make doc-freshness selection fail closed (#5729)
* test(ci): make doc-freshness selection fail closed

Require the protected doc-freshness workflow to select its exact compiled top-level inventory plus the guard that exercises real zero- and partial-selection refusals. Ordinary focused scripts tests remain unchanged unless required-suite mode is explicit.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* test(ci): fail suite self-test on inventory drift (#5726)

Fail the contract's compiled-suite subtest when an unregistered or missing
member would otherwise silently suppress its TestMain selector falsifiers.
Keep the integration-free build usable with an explicit subtest skip and
point doc-freshness test authors to the maintained registry.

The untagged TestMain fronts the entire scripts_test package, including
ordinary tagged and untagged go test ./scripts invocations. Without the
required-suite flag it delegates to m.Run; runtime failures and intentional
skips remain Go's responsibility.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* chore(bazel): enumerate required_suite_test.go in the scripts go_test srcs

gazelle-generated, scoped to this PR only. The file is untagged so the
go_test target owes its enumeration; the in-package census showed the
gap was exactly this file with zero pre-existing untagged gaps.
Note make bazel-sync also wants internal/storage/dolt/BUILD.bazel for
version_staging_completeness_test.go, but that is a BASE-owned gap from
the just-merged #6844 and is deliberately left out of this diff.

* test(ci): register the 11th doc-freshness test and pin real flag reads

Two maintainer review fixes on top of the contributor branch.

Blocker: requiredSuiteDefinitions pinned 10 TestDocFreshness* names while 11
are compiled at this head. The 11th,
TestDocFreshnessRejectsMultipleLastReviewedMarkers, arrived on the base in
0bf13494f0 (#6482) during the 164-commit merge-base advance, so the
contributor's list was correct when written. Left unregistered, the required
check-doc-freshness-platforms step this PR itself edits fails on all three
OSes (pr.yml:476, required via pr.yml:1378 and :1408), and the same drift
independently reds TestRequiredSuiteContract/compiled_suite in every
integration-tagged whole-package lane. Registering the name is the whole fix.

Major (test evidence): the flag table injects synthetic requiredSuiteFlags
literals, so it proved only that the predicates reject narrowing flags, never
that real flag values reach them. currentRequiredSuiteFlags is the sole
production reader of real test flags and went unexercised, so a wrong lookup
key silently reopened the fail-open hole this PR exists to close. skip, cpu,
list and short all compare against zero values and so fail open; run and count
fail closed. The new "real flag reads" arms hand a child real -test.skip,
-test.cpu, -test.list and -test.short alongside a valid -test.run and require
the matching diagnostic rather than the generic prefix, because a wrong key
reads the zero value and falls through to a different failure that the prefix
would accept. Mutating each lookup key in turn reds exactly its own arm and
leaves the other three green, tagged and untagged.

Those arms are the first to hand a child a valid selection, which necessarily
selects this test too, so a child that got past a broken guard re-entered here
and spawned without bound (measured: a monotonically growing child count that
never terminates). BEADS_TEST_REQUIRED_SUITE_CHILD stops that at depth 1, so
the regression surfaces as a failed assertion in seconds instead of a hang.

The arms sit outside "compiled suite" because the flag guards run ahead of the
inventory check, so they also hold in the untagged fast and bazel lanes where
compiled suite self-skips.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-10-01 01:05:12 -07:00
Julian Knutsen
7a21446e6c
ci(bazel): require the integration lane on same-repo PRs (#7069)
pr.yml's bazel.yml call now passes integration: "on", and its ci-gate
requires BAZEL_INTEGRATION (bazel-integration's job.status output, a
missing result reading as skipped). The lane stays remote-only:
bazel-gate.sh allows it to skip in modes local (fork and Dependabot PRs,
until the farm has a read-only cache for them) and skip, never in remote.
bazel-farm.yml's advisory call runs it too.

The integration test step gets 45 minutes (job 55) for cold PR compiles;
the policy test keeps it at or above a 20-minute cold compile plus
.bazelrc's test:integration --test_timeout (the 1200s per-action cap).
The integration input (default "on") stays for callers that want the lane
off; pr.yml's call inputs are pinned, and the gate simulation now covers
the lane skipped, failed and cancelled in each mode.

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 23:56:33 -07:00
ecuthiell
6899813df6
fix(preflight): share checkout lint authority (#5780)
* fix(preflight): share checkout lint authority

Move the Beads repository's native and Windows non-CGO lint policy into a checkout-owned Go driver. The supported Make/Bash wrapper and bd preflight now execute that same authority, while generic Go repositories retain their direct lint contract and formatting is rooted at the detected project.

Fixes #5300.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* docs(lint): clarify shared driver scope and timeout limits

Address PR #5780 review 5191123668. Document existing inherited-tag semantics and distinguish the wrapper/preflight driver from standalone workflow and pre-commit callers.

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(lint): prefer the selected Windows Go toolchain (#6865)

Keep per-pass toolchain requests and deadlines while avoiding the extra auto-selection launcher under the linter. Nonstandard SDKs retain their original PATH.

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* fix(lint): retain PATH for SDK directories containing separators (#6865)

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* test(preflight): declare lint fixture executable for Bazel (#5300)

Agent-Signature: codex-tui-gpt-6-astra-max on behalf of Ewen Cuthiell

* fix(bazel): keep cmd/bd/testdata out of gazelle's package scan

PR #5780 adds the compilable fixture cmd/bd/testdata/preflight-go.go. Left to
itself gazelle generates a BUILD.bazel for cmd/bd/testdata, which makes it its
own package and then (a) empties cmd/bd's data = glob(["testdata/**"]) under the
default allow_empty = False and (b) puts testdata/preflight-go.go across a
package boundary from the preflight_go_fixture target that lists it.

bazel.yml's "BUILD files in sync" step runs `make bazel-sync` and fails on any
resulting drift, and fork PRs always run that job, so this was a live red whose
prescribed remedy ("commit the result") would have broken the build further.
Exclude the directory instead, and take gazelle's ordering for the data list.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* fix(preflight): bound the lint deadline and report each check's scope

Review iteration 1 for PR #5780. Synthesis and scorecard both approve (975/1000,
no blocker or major), so this addresses non-gating findings only.

Finding 4 (Resource Lifecycle) - the 13-minute deadline could not bound the call
it guards. CombinedOutput collects through a pipe every descendant inherits, so
Wait kept blocking on a surviving golangci-lint after the context killed the
direct `go run` child. Measured on the same process shape (direct child killed at
1s, descendant holding the pipe for 8s): without WaitDelay the call returned in
8.00s, with WaitDelay in 1.50s. Sets cmd.WaitDelay so the deadline is a real
bound and the "lint check exceeded" line can actually print.

Also gates that line on err != nil, which retires the claude lane's nit (a): a
child that exits cleanly as the deadline fires is a pass, not a timeout. Measured
at the crossover, 68 of 300 passing runs would have carried a false "exceeded"
line; 0 after the gate.

Finding 1 (Change Impact) and nit 7 (Debuggability), one remedy - the PR re-roots
lint and fmt at preflightProjectRoot() but leaves runTestCheck in the caller's
cwd, so a --check run from a subdirectory mixes a repo-wide verdict with a
subtree-only one "with nothing in the output distinguishing them", and the
reported command is only reproducible from the root. CheckResult now carries the
directory each check resolved to, and the report prints it.

Took the synthesis's second arm (state the scope split) rather than re-rooting
runTestCheck, because re-rooting is a behaviour change neither lane priced: it
widens a subdirectory user's test run from 5 packages to 128, including every
Dolt-dependent package, on a repo whose full test gate the PR body already
discloses as red. The stated hazard is that the scopes are indistinguishable,
which reporting the directory discharges directly.

Finding 2 (Architectural Consistency), second clause - adds
TestBuildFlagsContractMatchesShellSource, which parses .buildflags and pins the
driver constants to it. The existing mirror test asserts today's values from the
Go side only, so the files could drift silently; buildEnvironment overrides
rather than merges -tags, so a tag added to .buildflags alone would be dropped
with every test still green. Each of the three legs was mutation-proved to red.

Declined, with the measurements that decided it:

- Finding 2's first clause (route the key comparisons through
  internal/execenv.KeyEqualForOS). The two are provably equivalent today -
  execenv's keyIdentityForWindows is strings.ToLower for the same documented
  reason - so this is de-duplication, not a defect, and the hazard it closes
  (os/exec key-identity semantics changing) is far less live than the
  .buildflags drift the second clause pins. The faithful swap means threading
  goos through five driver functions and ~27 test call sites in this PR's
  centerpiece file, and it would put a non-stdlib dependency into pr-lint_lib,
  which the binary currently does not have. Worth doing on its own footing, not
  inside a non-gating cleanup.

- Nit 6 (parse GOFLAGS into fields instead of a substring test). .buildflags:22
  guards its own append with `!= *gms_pure_go*`, a substring test, and the Go
  code is a deliberate mirror of it. Making only the Go side stricter would
  manufacture exactly the drift finding 2 warns about: on
  GOFLAGS=-tags=gms_pure_go_x the shell would skip its append while the driver
  performed one. The fix belongs to .buildflags and the driver together, and
  .buildflags is outside this PR. The new mirror test now pins that agreement.

- Nit 5 (probe golangci-lint as well as `go`). The claude lane examined the
  LookPath target change and recorded it as deliberate, with the driver's own
  missing-linter error as the mitigation. The suggested alternative - have the
  driver emit preflight's `--skip-lint` hint - puts a bd-specific flag into a
  driver that CI also invokes, where that advice is wrong.

- Finding 3 (two false PR-body claims). Correcting the body is outward-facing
  and belongs to finalize; stamped for it. Swept the in-tree copies: the PR's own
  LINTING.md sentence "Toolchain requests, formatting, and lint deadlines are
  unchanged" is scoped to the Windows SDK-preference paragraph it sits in and is
  true there, so it is graded rather than repaired. CHANGELOG.md contains no
  pr-lint entry, so the remedy's CHANGELOG half has no target in this PR.

Validation: go build, go vet and gofmt clean on the changed packages;
./scripts/pr-lint/ 12 pass / 2 Windows-only skip; ./scripts/prlintmake/ pass;
cmd/bd preflight selector pass; scripts/check-doc-freshness.sh PASSED;
make bazel-sync idempotent and bazel test //scripts/pr-lint:pr-lint_test PASSED.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(prlintmake): inject the pr-lint wrapper's gofmt shim through GOFMT

The merge with #6294 (be-gx8) left runPRLintWrapper relying on a
code path #6294 made deliberately loud. The helper put its gofmt shim
on PATH. Since #6294, fmt-check.sh resolves gofmt through
scripts/ci/gofmt-bin.sh, which ignores a PATH gofmt by design.

Both TestPRLintWrapper* tests still passed, but only via the
resolver's fallback. The go shim answers `go env GOVERSION` and
`go env GOROOT` with nothing, so gofmt-bin.sh warns "could not resolve
a gofmt from go.mod's go1.26.7 toolchain" and falls back to whatever
gofmt is first on PATH, which happened to be the shim. With GOFMT set
in the environment, which is #6294's documented override, the
resolver uses that value instead. Both tests then fail: exit status
127 from fmt-check.sh, and a missing aggregate failure diagnostic
because pr-lint.sh stops before `go run`. At the pre-merge head
(7f37ba5165) the same ambient GOFMT=/nonexistent run passed all 5
tests.

Pass the shim through GOFMT, as main's runFmtCheck does, and keep it
off PATH so only the go shim is found there. gofmt-bin.sh now returns
the override immediately, and the go shim sees only `version <shim>`
and `run ... ./scripts/pr-lint`. Both wrapper assertions, on the
driver arguments and on the failure diagnostic, are unchanged.

go test ./scripts/prlintmake/: 9/9 pass by default and 9/9 pass with
GOFMT=/nonexistent in the environment. Before this change the second
run was 7/9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 22:41:55 -07:00
Vishnu J
8f195454ef
fix(winget): require PortableCommandAlias for GasTownHall.Beads (#5134)
* fix(winget): require PortableCommandAlias for GasTownHall.Beads

GasTownHall.Beads 1.1.0 on winget-pkgs only sets Commands: (search
metadata) and never creates WinGet\Links\bd.exe, so already-running
shells never see bd after install (GH#4908).

- Add canonical GasTownHall.Beads.installer.yaml with PortableCommandAlias
- update-winget.sh regenerates that package id for new releases
- Document both package ids and the Links requirement in winget/README
- Add check-winget-portable-alias.sh guard

Fixes #4908

* fix(winget): address maphew's PR #5134 review (grep bug, guard, CI wiring)

Maintainer commits requested by the PR author on the reviewer's behalf,
addressing maphew's 2026-07-29 review of PR #5134:

- scripts/update-winget.sh: `grep windows` matched both amd64 and arm64
  checksum lines, corrupting InstallerSha256 into an unparseable
  two-line value. Narrow to `grep windows_amd64` (mirrors the existing
  arm64 grep on the next block).
- scripts/update-winget.sh: quote the arm64 InstallerSha256 placeholder
  so 64 bare zero digits don't parse as a YAML integer, matching the
  quoting already used in the checked-in SteveYegge.beads.installer.yaml.
- scripts/check-winget-portable-alias.sh: replace the bare
  `grep -q PortableCommandAlias:` substring check with a yq-based parse,
  so a corrupted manifest (like the one above) fails the guard instead
  of reporting OK; also fail closed on an empty winget/ glob instead of
  silently exiting 0.
- .github/workflows/pr.yml, main.yml: run the guard in the existing
  check-build-tags job so it executes on every PR instead of only when
  someone remembers to invoke it by hand.

Locally verified: guard passes against the current checked-in
manifests, fails against a reproduction of the exact grep-bug
corruption, fails on an empty winget/ dir, and the generator produces
a yq-parseable manifest against a synthetic checksums.txt. shellcheck
clean; both workflow files parse as valid YAML.

* fix(winget): harden the PortableCommandAlias guard and its release docs

Maintainer review fixups for the adopt-pr review of PR #5134 (iteration 1,
synthesis approve / 0 blockers and 0 majors; all seven items were non-gating).
Scorecard 961/1000, Required Changes: None. Every edit site below is a line
this PR itself added.

Finding 1 (minor, Error Handling) — `yq -e ... >/dev/null 2>&1` collapsed three
distinct failures (yq absent at exit 127, unparseable manifest, alias genuinely
missing) into "missing valid PortableCommandAlias", defeating the script's own
stated rationale and pointing a debugger at manifests that are already correct.
The guard now names a missing yq up front and no longer discards stderr, so
yq's own diagnostic reaches the log of a required-gate job. yq is CI's first and
only yq consumer, running in a bare actions/checkout job, and sits outside the
host-tools inventory declared in scripts/BUILD.bazel; that is now stated where
the dependency lives.

Finding 4 (minor, Change Impact) — the glob is winget/*.installer.yaml but the
assertion was unconditional on installer type, so a future msi/exe/msix
manifest (no NestedInstallerFiles at all) would hard-fail a gate-feeding job
with no opt-out. Non-portable manifests are now classified out with a SKIP line.
The parse check deliberately precedes the class check: without that ordering an
unparseable manifest fails the NestedInstallerType test and is silently skipped
as "not portable", which is strictly worse than the behaviour being fixed.

Finding 2 (minor, Error Handling) — amd64 and arm64 had opposite failure
policies in one script: a missing amd64 checksum hard-fails, while a missing
arm64 checksum substituted 64 zeros and continued to success, disclosed only in
a source comment. The echoed "Next steps" block now ends in a loud
"DO NOT PUBLISH" warning naming the placeholder, emitted only when the fallback
actually fires.

  The finding's second arm — "teach the guard to reject an all-zero
  InstallerSha256" — is implemented as a WARNING rather than a failure, and
  that is a deliberate downgrade. winget/SteveYegge.beads.installer.yaml:15
  already carries exactly that placeholder for its arm64 entry; that file is
  base-owned and is not in this PR's six-file diff, so a fatal tripwire would
  turn a required check red over pre-existing content the PR never touched.
  The legacy heredoc in update-winget.sh emits no arm64 entry at all, so the
  placeholder is stale hand-authored state that the next generator run removes.
  Verified: the guard still exits 0 on the real tree and reports the warning.

Finding 3 (minor, Contract & Interface Fidelity) — a winget-pkgs version
directory needs a version + defaultLocale + installer set, but the repo carries
only GasTownHall.Beads.installer.yaml, so README step 2 as written produced a
set winget-pkgs validation rejects. Took the documentation arm: GasTownHall is
now steered to `wingetcreate update` (which supplies the other two manifests
from the published set) and the hand-copy path is marked as applying only to
the legacy id, which does have a complete three-file set. Generating two more
manifests would have changed the contribution's deliverable scope.

Finding 5 (nit, Architectural Consistency) — the first update-winget.sh run
overwrote the checked-in manifest with a three-line header, deleting this PR's
own GH#4908 rationale from the artifact whose purpose is to carry it. The
heredoc now emits the same header, plus a fresh ReleaseDate. Verified by
generating into a temp tree: the generated header is byte-identical to the
checked-in file's first ten lines.

Finding 6 (nit, Documentation Accuracy) — the README froze SteveYegge.beads at
the "0.30.x era" while the script rewrites all three of its manifests to the
new version. Note that the section already disclosed that both ids are
refreshed, so the residual gap was narrower than the finding stated: what was
missing is that the legacy id's version is bumped out of the era the table
advertises. That clause is now explicit.

Finding 7 (nit, Test Evidence Quality) — the guard's fail-closed behaviour was
pinned by nothing in-repo. Adds scripts/check_winget_portable_alias_test.go
with ten cases: alias present, alias missing, wrong alias, empty winget dir,
unparseable manifest (asserting it is neither skipped nor misreported and that
yq's stderr survives), missing yq, a skipped non-portable manifest, a violating
portable sibling of a skipped manifest, and the advisory placeholder warning.

  Deviates from the prescribed `requireHostTool(t, "yq")` on purpose.
  requireHostTool fails rather than skips under Bazel because
  //scripts:scripts_test is tagged host-tools, and that tag's declared
  inventory is "git, python3, awk, sed, find, grep and timeout" — yq is not in
  it, so the prescription would red the shared target on hosts that keep the
  promise the tag actually makes. A skip-only gate is used and the reason is
  recorded at the helper. Fixtures are synthetic so the target needs no new
  data dependency; the real manifests are covered by the check-build-tags job,
  which runs this script against the actual checkout.

Also fixed, found while editing and not raised by either lane: winget/README.md
told readers to run `grep windows` over checksums.txt, which is the exact
two-line ambiguity this PR fixed in the script (`grep windows` ->
`grep windows_amd64`). Before this PR the script and doc agreed; after it they
diverged, so the PR created the inconsistency. The doc now uses `grep windows_`
and says which line feeds which architecture.

Validation. `git diff --check` clean. The guard runs green on the real tree
(both manifests OK, rc=0) and on a freshly generated tree. go test ./scripts/
ok 21.7s (the package whose tests pin workflow content). Each new pin was
proven non-vacuous by reverting the corresponding fix and confirming the test
reds: dropping the class check reds the non-portable case; dropping the
placeholder tripwire reds the warning case; dropping the parse-before-classify
check reds the unparseable case; dropping the yq preflight reds the missing-yq
case; restoring `2>&1` reds the stderr assertion. All five arms red, and the
guard was restored byte-identical (md5 verified) after each. The arm64 warning
was exercised both ways against a stubbed curl: present arm64 checksum emits no
warning, absent one emits DO NOT PUBLISH.

New yq expressions stay inside the vocabulary shared by mikefarah yq v4 (what
ubuntu-latest ships) and python-yq/jq — identity, `==`, `[]`, `select` and
`-e`'s exit status — because only the pre-existing expression had been proven
green on mikefarah in CI, and this host has python-yq. Builtins the two flavours
spell differently (jq's `any(cond)` vs mikefarah's `any_c`) are avoided, and the
placeholder tripwire uses grep precisely because it looks for a known-bad
literal and so can only miss a bad value, never report OK on a manifest it
failed to parse.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
2026-09-30 20:24:59 -07:00
ecuthiell
61865bb0fe
test(init): make gateway credential fixtures portable across native shells (#5715) (#5725)
* test(init): make gateway credential fixture portable (#5715)

Replace shell-specific fixture commands with an opt-in test helper, exercise exact credential semantics under a restricted shell PATH without copied Windows PE fixtures, and require the focused suite in native Windows PR CI.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* test(init): keep the original shell across native credential fixtures

Use a symlink to the original Unix shell so macOS AMFI does not reject a
copied system executable. Keep Windows cmd.exe and the test image in place,
internalize helper environment names and assert the typed helper exit code.

Run the six fixture cases through one Bash3.2-compatible driver in the
existing required three-host preflight matrix. Preserve the liveness check
name and optional macOS suite policy; reject missing or skipped execution.

Review: https://github.com/gastownhall/beads/pull/5725#pullrequestreview-5096996756
Bead: saa-cgh.47
Agent-Signature: unknown-model/unknown-reasoning

* test(ci): sync-check the native fixture list and stop forcing a second build graph

Maintainer review fixes for PR #5725, adoption iteration 1. The synthesis is
`approve` with no required changes; all findings are minor or nit. The rebase
lane had to repair this branch (`repaired_clean`, and the original head still
conflicts with main), so there is no accepted-as-is path and finalize owes a
push either way — these cost nothing extra.

Test evidence (minor): the `expected` array is, by its own comment, the single
list owning both test selection and required execution evidence -- but nothing
tied it back to the source file. A seventh TestApplyInitGatewayCredential*
fixture added later would fall out of the `-run` selector, lose native
macOS/Windows execution entirely, and still leave the driver exiting 0 with the
required gate green: precisely the "green because nothing ran" mode the per-name
PASS counting exists to prevent. The driver now compares the array against
`grep -Eo '^func TestApplyInitGatewayCredential[A-Za-z0-9_]*'` on
cmd/bd/init_gateway_test.go, by name and by count, before running anything, and
exits non-zero naming the offending fixture. That file is the whole population --
no same-prefix fixture lives in any other cmd/bd test file.

Release safety (minor): the driver sourced .buildflags and then forced
CGO_ENABLED=0, compiling a package graph disjoint from the ./cmd/bd build the
same job performs two steps earlier under the default. Re-measured under the
tags the steps use: `go list -deps -tags=gms_pure_go ./cmd/bd` is 1505 packages
with cgo and 742 without, and the differing cgo users include `net` and
`os/user`, whose build IDs propagate upward -- so nothing was reused and this
blocking, `cache: false` lane paid a second cold compile on macOS and Windows.
The export is dropped. Two consequences beyond the time: the step becomes
incremental, and the natively executed fixtures now exercise the same build of
cmd/bd that actually ships on those platforms rather than a nocgo one. The
comment now explains the build configuration, which is what the old one did not
do -- it explained why no database is needed, a separate question.

Debuggability (nit): the base comment above test-windows-liveness carried three
checkable mechanism clauses (the test is //go:build windows; the Ubuntu job
selects it by name but compiles it out; main.yml's Windows job runs only on
pushes to main). The replacement stated a conclusion a future maintainer cannot
verify, which is how a redundant-looking CI job gets deleted. The mechanisms are
restored and the new pr-preflight-platforms pointer is appended rather than
substituted.

The remaining nit asked for no change in this PR (the credential cache is keyed
by command string, which is harmless as shipped since neither the marker nor the
failure arm populates the cache) and none was made.

Validation: the driver runs green on Linux under the inherited default CGO --
6 of 6 fixtures PASS, exit 0 -- and the sync check was proved by appending an
unwired seventh fixture, which reds it with exit 1 naming that fixture, before
any test runs. `bash -n` clean, no shellcheck SC2086, and ./scripts/ stays green.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 20:10:22 -07:00
mtccressall
1f7a5f1eaf
fix(ci): resolve gofmt from go.mod's toolchain, not PATH (be-gx8) (#6294)
* fix(ci): resolve gofmt from go.mod's toolchain, not PATH (be-gx8)

gofmt's output is not stable across Go releases, so whichever binary runs
decides the formatting verdict. Three sites reached for a bare `gofmt` on
PATH -- scripts/ci/fmt-check.sh, the Makefile fmt target, and
.githooks/pre-commit -- and PATH belongs to whatever Go is installed
locally. CI has no such freedom: actions/setup-go installs exactly the
go.mod version via go-version-file.

GOTOOLCHAIN=auto does not correct for this, which is why `go env GOROOT`
or `go fmt` would not have been a fix either. The toolchain switch only
ever moves UP to satisfy the go directive, never down, so a host running
a newer Go keeps formatting with the newer gofmt. Measured against
go.mod's go 1.26.5 on a go1.27.0 host: 1.27 flags three
role_fixture_kit_test.go files that 1.26.5 calls clean, and no branch
touches them.

The failure ran in the dangerous direction. The required lint gate went
red on untouched code, which reads as "main's lint is broken" and poisons
the pre-existing-on-main judgement every PR author uses to decide whether
a red gate is theirs. Its own advice -- "Run 'make fmt' to fix
formatting" -- then rewrote those files into a form CI's pinned gofmt
rejects. The pre-commit hook did that same rewrite and re-staged it
silently on every Go commit, with nobody choosing it.

Route all three through one resolver rather than patch three sites, so
the next gofmt call site cannot drift. scripts/ci/gofmt-bin.sh names
go.mod's toolchain explicitly and reads GOROOT from it, short-circuiting
to a plain `go env GOROOT` when the host go already is the pinned version
(the CI case, so nothing is fetched where nothing needs fetching). A
fallback to the PATH binary stays available but warns loudly on stderr:
silently falling back is indistinguishable from resolving correctly, and
reintroduces exactly this skew. fmt-check.sh now prints the gofmt version
it used, so a skew presents as a skew instead of as a repo defect.

The new tests pin the resolution, not the reporting, because the
resolution is where the bug lived: every output assertion around the bare
gofmt stayed green. Reverting gofmt-bin.sh to `command -v gofmt` fails
all three. The pre-existing fmt-check tests move their shim from PATH to
GOFMT -- a PATH shim is now correctly ignored, so leaving them there
would have made them grade the real toolchain instead of the case they
name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PoN7f9TMmGTCLRpDPzSH4y

Executed-By: beadsrig/polecats/nux

* fix(ci): resolve gofmt from go.mod's toolchain directive, and declare it to Bazel

Maintainer review fixes for #6294 (adoption iterations 1 and 2, one squashed
commit). Sections 1-6 address all six findings in the attempt-1 synthesis; the
two majors are the substantive ones. Sections 7-8 address the two minors the
attempt-2 synthesis left (it decided approve, 1000/1000, no blocker or major).

1. Contract & Interface Fidelity (major, the scorecard's only Required Change).
   gofmt-bin.sh read the `go` directive (1.26.5) while go.mod also carries
   `toolchain go1.26.7`, and toolchain-first is the repo's own declared
   precedence -- Makefile:85-90 exports GOTOOLCHAIN from the same pair for
   every make target, and scripts/bazel_policy_test.go's goModToolchainVersion
   is the same rule in Go. The consequence was not cosmetic: `go env GOVERSION`
   at the repo root is go1.26.7 (the directive auto-switches), so the fast-path
   test compared go1.26.7 against go1.26.5 and was false by construction on
   every route, sending each required fmt-check run down the elif arm to fetch
   a second, older toolchain. Parse `toolchain go<version>` first, fall back to
   the `go` directive. Measured after the change: pinned=1.26.7, the fast path
   fires (`go env GOVERSION` then `go env GOROOT`, no GOTOOLCHAIN= prefix and
   nothing fetched), and `make fmt-check` now reports
   `Using gofmt go1.26.7 (.../toolchain@v0.0.1-go1.26.7.../bin/gofmt)`.
   .githooks/pre-commit:24's `go`-directive read is deliberately left alone --
   its comment explains it is a golangci-lint pin for a different reason.

   gofmtbin_test.go's helper now implements the same precedence, and
   TestGofmtBinMatchesGoModDirective is renamed TestGofmtBinMatchesGoModToolchain
   so the pinned contract is legible from the test name.

   Deviation from the prescription, recorded deliberately: the review asked for
   a helper "name" change as well. The name goModToolchainVersion already
   described toolchain-first semantics; it was the implementation that did not.
   Correcting the semantics is what removes the collision with
   scripts/bazel_policy_test.go's identically-named, opposite-behaving helper,
   so the name is kept and the doc comment now states the precedence and cites
   both in-repo sources of it.

2. Release Safety (major). fmt-check.sh now execs a sibling script
   unconditionally under `set -euo pipefail`. Live origin/main gives
   //scripts/prlintmake a `data` list containing exactly ci/fmt-check.sh, so on
   merge all three TestFmtCheck* cases would have died at rc 127 in the Bazel
   runfiles sandbox -- the GOFMT short-circuit cannot rescue them because it
   lives inside the missing script. Export ci/gofmt-bin.sh to
   //scripts/prlintmake and put it in the target's `data`, and add
   gofmtbin_test.go to `srcs` (it carries no build tag, so its omission was not
   explained away).

   Only ci/gofmt-bin.sh is exported here, not ci/fmt-check.sh: main already
   exports that one for this same package, and a second exports_files call
   naming the same file in one package is an error. This base predates both of
   main's additions, which is also why editing the three-line go_test rule
   conflicts with main's independent edit of it. Verified by materialising the
   merge: every other file auto-merges and the resolution is the union of the
   two attribute sets (srcs = both test files; data = both scripts plus
   //:go.mod per section 7; keep main's deps on //internal/testutil/bazeltest).
   That deps edge is load-bearing at main even though it was stale at this base:
   main rewrote sourceRepoRoot to bazeltest.CallerDir, so the union must keep it.

3. Test Evidence Quality (minor). environment() starts from os.Environ(), so
   deleting GOFMT from the override map did not unset it. Export it empty
   instead -- gofmt-bin.sh reads `[[ -n "${GOFMT:-}" ]]`, so empty already is
   its "not set" case, and the override test stays distinguishable by setting a
   non-empty value.

4. Architectural Consistency (minor). "Every gofmt invocation in this repo goes
   through here" was false at authoring: cmd/bd/preflight.go's doctor check is
   a fourth front door on bare PATH gofmt. Scope the claim to the repo's
   shell-side call sites (re-censused: fmt-check.sh, the Makefile fmt target,
   and .githooks/pre-commit are the complete set; the two workflow "Check
   gofmt" steps and scripts/ci/pr-lint.sh reach them through make fmt-check),
   and name the in-binary exception with the reason it is one -- bd runs
   against whatever project the user points it at, so it has no scripts/ci/ to
   call. preflight.go is byte-identical at base, at HEAD and at origin/main, so
   nothing in this PR widens it; converting it is a separate change.

5. Test Evidence Quality (minor). describe_gofmt's version-bearing arm had zero
   coverage -- all three existing cases inject a bash script, for which
   `go version` errors and only the bare-path arm can run. Add
   TestFmtCheckReportsGofmtVersion against a real Go-built no-op binary, which
   is the only shim shape `go version` can report on.

6. Error Handling & Resilience (nit). Warn (without refusing) when GOFMT names
   something non-executable, so a typo is reported by the resolver that
   accepted it rather than as a "not found" from whichever call site ran it;
   and guard the fields index in the resolver test.

Mutation proofs, each red isolated to the intended test with the other six
green (7/7 pass unmutated, `go test ./scripts/prlintmake/`):

  - revert the toolchain-first parse -> resolver returns the 1.26.5 gofmt and
    TestGofmtBinMatchesGoModToolchain alone fails.
  - delete describe_gofmt's `if command -v go` block (codex's own mutation,
    previously all-green) -> TestFmtCheckReportsGofmtVersion alone fails, the
    three incumbents stay green. That asymmetry is both the coverage-hole proof
    and the proof the new case is not a duplicate.
  - ambient GOFMT, two values x two arms: with the fix both /nonexistent and a
    correctly-pinned gofmt leave all three resolver tests passing; with the
    delete restored, /nonexistent fails TestGofmtBinMatchesGoModToolchain with a
    message blaming the script, and a correctly-pinned value turns all three
    green vacuously without the resolver ever running.

7. Release Safety (minor, iteration 2). The target now reads go.mod at run
   time -- the resolver opens "$REPO_ROOT/go.mod" and the test helper opens
   filepath.Join(sourceRepoRoot(), "go.mod"), where the base test read it not at
   all -- but go.mod appeared in no `data` list, so the rule declared strictly
   less than it uses. Add //:go.mod to //scripts/prlintmake's `data`. No new
   export is needed: //:BUILD.bazel already exports go.mod publicly, and
   //internal/storage/dolt and //internal/testutil/integration already consume
   it as "//:go.mod" in `data`, so this is the sanctioned shape rather than a
   new one.

8. Contract & Interface Fidelity (minor, iteration 2). `toolchain default` is a
   legal go.mod directive value, and the parse matched on the field name alone,
   so sub(/^go/, "", "default") no-opped and left pinned=default. Because that
   is non-empty, neither the `go`-directive fallback nor the "no toolchain or go
   directive" guard could fire, and the script degraded to the bare PATH gofmt
   it exists to eliminate while a usable `go 1.26.5` sat two lines above. The
   mangled "godefault" in the warning was the tell. Require the literal `go`
   prefix, which is exactly what the repo's two other readers of this pair
   already do (Makefile:85's `s/^toolchain go//p` and bazel_policy_test.go's
   `^toolchain\s+go(\S+)\s*$`), so `default` falls through to the `go`
   directive.

   The same guard is added to gofmtbin_test.go's goModToolchainVersion, and that
   is not redundant: strings.TrimPrefix("default", "go") returns "default"
   unchanged and withPatchComponent leaves a dotless string alone, so the helper
   mirrored the bug exactly and the test could never have caught it. Guarding
   only the script would have left the test agreeing with a buggy resolver.

   Measured on a synthetic tree, five arms (the script resolves REPO_ROOT from
   its own location, so each arm is a copied script beside a written go.mod):

     - `toolchain default` + `go 1.26.5`: before, /usr/local/go/bin/gofmt with
       the "godefault" warning; after, the go1.26.5 toolchain gofmt -- i.e. the
       `go` directive, identical to the arm where no toolchain line exists.
     - `toolchain go1.26.7`: unchanged before and after (no regression).
     - `go 1.26.5` alone: unchanged before and after (no regression).
     - `toolchain default` with no `go` directive: now reaches the previously
       bypassed "no toolchain or go directive" guard and falls back loudly, with
       the correct message rather than the mangled one.
     - `toolchain default` written before `go`: also resolves 1.26.5, so the
       fallthrough is order-independent.

   The Go helper's parse was checked over the same six inputs and now agrees
   with the shell on every one.

   No regression test is added for this case. Doing so would need a new
   synthetic-go.mod fixture -- every existing case runs the real script against
   the real repo go.mod through sourceRepoRoot() -- which is a new test
   instrument rather than the prescribed remedy, on a finding whose gate impact
   is none (go.mod carries `toolchain go1.26.7`, so nothing can fire today).

Iteration 2 validation: go test ./scripts/prlintmake/ -count=1 -v 7/7 PASS
(same roster as iteration 1, no test added or removed), go vet rc 0,
go test ./scripts/ -run 'Bazel|BUILD' 11/11 PASS (the BUILD-policy gate, run
because this touches a BUILD file), python3 tools/bazel/go_srcs.py --check
rc 0 (`srcs` is unchanged; only `data` moved), make fmt-check rc 0 still
reporting go1.26.7, shellcheck clean, git diff --check clean.

Also run: go vet ./scripts/prlintmake, go test ./scripts/... (all packages ok),
make fmt-check (rc 0), python3 tools/bazel/go_srcs.py --check (rc 0),
shellcheck on both changed scripts.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 18:38:46 -07:00
ecuthiell
4e804885dd
test(credentials): make remaining credential-command fixtures native-Windows portable (#5748) (#5749)
* test(credentials): make command fixtures Windows-portable (#5748)

Replace POSIX-only credential test commands with a shared shell-portable protocol, exercise their intended failure and non-invocation semantics on native Windows, and add the focused required CI selector.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* test(ci): require each Windows credential fixture to pass

Include the standalone credentialcmd protocol test in the existing Windows
step. One package/test map drives both selection and exact terminal checks,
so missing, skipped, failed, or duplicate tests cannot report success.
Resolve native Go once and reuse it for the test invocation.

Bead: saa-cgh.66
Agent-Signature: unknown-model/unknown-reasoning

* test(ci): select the first Go application on PATH

Hosted Windows images can expose more than one Go application. Preserve
setup-go's PATH precedence, select one absolute application and reuse it.

Bead: saa-cgh.66
Agent-Signature: unknown-model/unknown-reasoning

* chore(bazel): sync BUILD.bazel srcs for the new credentialcmd test helper

Base landed the Bazel PR gates (#6881/#6887) after this PR was authored, so
the PR's new internal/testutil/credentialcmd package and internal/creds
testmain_test.go were never enumerated in any BUILD.bazel. Two already
enumerated test srcs (internal/creds/command_test.go and
internal/storage/dolt/gateway_credential_test.go) import the new package, so
`bazel build //internal/creds:all` fails GoCompilePkg without this.

Generated by `make bazel-sync` (gazelle); a second sync is a no-op. The
internal/storage/dolt version_staging_completeness_test.go srcs row is
pre-existing base drift that gazelle corrects in the same pass, not PR content.

* test(credentialcmd): pin the Windows gate's assertions and stop claiming foreign helpers

Maintainer review fixes for PR #5749, adoption iteration 1. The synthesis is
`approve` with no required changes; all four findings are minor or nit. A
maintainer bazel commit already exists on this branch, so the push was owed
regardless and none of these cost anything extra. No production code changes.

F1 — the new required Windows gate pinned its own wiring but almost none of its
assertions. The guard checked three package paths and one test name, so it
stayed green if someone dropped six of the nine test names from $expected,
deleted the `Action -in 'fail', 'skip'` throw, or deleted the exactly-one-PASS
loop -- leaving a required gate whose only real guarantee was "go test exited
0", which a fully skipped suite also satisfies. The pinned slice now carries all
nine test names plus both load-bearing guard tokens, keeping the file's existing
substring idiom.

F2 — the property the fixture exists for was unassertable end to end. Emit is
written to produce byte-exact stdout across sh and the Windows .cmd trampoline,
but parseCredential runs bytes.TrimSpace before every comparison, so every
existing assertion is blind to a trailing newline: a trampoline changed to
`echo %OUT%` would keep the whole suite green. TestCommandSourceRealShell now
wraps the existing credRunner package seam to capture the helper's stdout as the
shell produced it, and asserts it byte-exact. The real shell stays in the loop,
so this remains end-to-end rather than becoming a second in-process test.

F3 — Dispatch claimed any process where BEADS_TEST_CREDENTIAL_COMMAND_HELPER=1,
on the env alone and before inspecting argv, exiting 97 when the sentinel was
absent. command() arms that variable in the *parent* process and BEADS_-prefixed
variables reach every re-exec'd child through the integration allowlist, so the
first composition with a package that re-execs its own test binary -- which
internal/storage/dolt already does -- would have died with a wrong-subsystem
"missing protocol sentinel". Both gates are now required, and an env-armed
process without the sentinel falls through to its own TestMain.

The second half of that finding's prescription is deliberately NOT applied.
Adding BEADS_TEST_CREDENTIAL_COMMAND_HELPER to helperSubprocessSentinels reds
TestHelperSubprocessSentinelsAreComplete: that guard has a reverse-direction
control, and its regex looks for a literal os.Getenv("BEADS_..._HELPER") in
internal/storage/dolt's own test sources. This sentinel is read in
internal/testutil/credentialcmd, so the entry registers as a stale one. Measured,
not assumed -- the failure is "helperSubprocessSentinels lists
BEADS_TEST_CREDENTIAL_COMMAND_HELPER, but no test source reads it". With the
Dispatch gate fixed the entry also buys nothing: a dolt helper child already
carries its own sentinel, so isHelperSubprocess is true for it either way.

F4 — the exported constructors documented themselves as "returns a unique shell
command" while replacing PATH for the rest of the calling test, setting env vars
via t.Setenv (which bans t.Parallel), and silently rejecting an empty payload.
The shared contract is now stated once above the three of them, and Emit fails
fast with an explanation instead of letting the shell drop the empty payload
word and the helper exit 97. No caller passes an empty payload today.

Each fix was checked by reverting it and confirming its own pin reddens: the
dropped test name reds the guard by name; the trailing-newline wrong
implementation reds the new raw-stdout assertion while the sibling end-to-end
test stays green, which is the blindness the finding described; and reverting
the Dispatch gate reproduces `(97, true)`. `make bazel-sync` is a no-op -- every
edit landed in a file already enumerated in srcs.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 18:30:25 -07:00
Atirna
9ce991837d
ci: cross-compile release targets on PRs (#5684)
* ci: cross-compile release targets on PRs

Agent-Signature: codex-unknown-model-unknown-reasoning on behalf of Atirna

* ci(pr): pin the release-target cross-compilation gate and disclose its CGO boundary

Maintainer review fixup for #5684.

Disclose the coverage boundary on the new job. All eight legs build
CGO_ENABLED=0, but five of them stand for release binaries built at
CGO_ENABLED=1: bd-linux-amd64, bd-linux-arm64 and bd-windows-amd64 in
.goreleaser.yml, plus the darwin pair built natively by release.yml's
goreleaser-macos job. The cgo half of the tree (beads_cgo.go ->
internal/storage/embeddeddolt) is never compiled by this check, so a
break confined to it still passes green. Only android/arm64,
windows/arm64 and freebsd/amd64 replicate their release configuration
exactly. The comment also records that the ./... build scope is
deliberate extra coverage rather than an oversight, since every
.goreleaser.yml build id declares main: ./cmd/bd.

Pin the gate wiring. Nothing asserted the new job: deleting
CHECK_RELEASE_TARGET_CROSS_COMPILATION from CI_GATE_REQUIRED left
go test ./scripts/ fully green, against a repo convention of pinning
each load-bearing gate token by name.

Guard matrix/.goreleaser.yml drift in both directions, so a future
release target cannot go uncovered behind a green "release target
cross-compilation" check -- a failure mode worse than having no check,
because the check's existence implies the coverage it has lost.

Restore the Go module cache, matching the file's other multi-leg matrix
jobs. This is the largest matrix in the file and the only one building
the entire module.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 15:53:30 -07:00
Jim Wordelman
9d646fc887
fix(dolt): server-mode bd ready never wakes expired defers (re-proposes #6082) (#6424)
* test(dolt): red — defer auto-wake must run for classified-read-only server-mode opens (be-vbhpf)

TestServerModeDeferAutoWake exercises the same defer/wake contract as the
embedded and proxied-server variants, against a real dolt sql-server. Today
the sweep (DoltStore.wakeExpiredDefers) unconditionally skips whenever the
store is opened read-only — including when that read-only-ness comes purely
from command classification (bd ready/bd list are read-only for the CURRENT
project), which is indistinguishable, before the fix, from a strict
--readonly or foreign-project open that must never sweep.

RED: expired_dated_defer_wakes_on_ready and expired_dated_defer_wakes_on_list_ready
fail (issue never returns to open). dateless_defer_never_wakes and
future_dated_defer_stays_hidden pass today too, trivially (no sweep runs at
all pre-fix) — kept as regression guards for the GREEN step, which is where a
unit test proving classifiedRead=false still does NOT sweep belongs, since
that distinction doesn't exist yet at RED.

* feat: green — defer auto-wake runs for classified-read-only server-mode opens (refs be-vbhpf)

bd ready/bd list on a dolt-sql-server-backed store open with the store
classified read-only for command purposes; the lazy defer-wake sweep
silently early-returned before ever running, so expired defers never
woke unless something else opened the store writable first.

Threads a new ClassifiedRead flag through dolt.Config -> DoltStore,
set at the call site to exactly "read-only because of command
classification, not strict --readonly/preview/foreign-project"
(policy.readOnly && !readonlyMode && !previewMode in main.go).
wakeExpiredDefers's guard now delegates to a small extracted
predicate, deferWakeSweepEligible(readOnly, classifiedRead), so the
truth table can be unit-tested without a live store.

* chore: release gate PASS for be-6iglh-gate

* docs(release-gates): record the be-5fjqh rebase onto current main

origin/main advanced 6 commits past this branch's base and PR #6082 went
CONFLICTING; hourly pr-audit filed be-5fjqh. The branch is now rebased onto
0efe0adf5.

The only conflict was cmd/bd/main.go: this branch and e05000d64 (wy-sbgucn)
each append a field to the same dolt.Config literal at the same anchor line.
Resolved keep-both -- PoolReadTimeoutFallback and ClassifiedRead drive
disjoint code paths.

The addendum records the new base and SHAs, patch-id equivalence for the five
files that did not conflict, what was re-verified at the new base (build plus
the diff-owned tests, container-backed), and what was NOT re-run (the
full-suite and ci-pr-policy lanes still refer to the old base).

Agent-Signature: claude-code-claude-opus-5[1m]-unknown-reasoning on behalf of Jim Wordelman

* docs(release-gates): record the be-qjern re-propose rebase and full re-gate

PR #6082 was closed and its branch deleted 2026-09-01 by an unknown actor
under the shared quad341 identity. Operator ruling 2026-09-08: accidental,
not a rejection — re-proposing. This addendum records a second self-rebase
onto current origin/main (zero conflicts this time), the full-suite and
ci-pr-policy re-gate the 09-01 addendum left outstanding (0 FAIL, policy
FAIL attributed to pre-existing be-mrl6j), and re-verification of both
diff-owned container-backed tests at the new HEAD.

refs be-qjern

* test(feat): red — add strict --readonly server-mode subtest to TestServerModeDeferAutoWake (refs be-acsyx)

* docs(release-gates): green — reword container-backed evidence claims, add nit-3 comment (refs be-acsyx)

bee-ghosttrack nit 2: TestDeferWakeSweepEligibleHonorsClassifiedRead is a
pure-function table test, not container-backed like TestServerModeDeferAutoWake
— reworded release-gates/be-6iglh-gate.md criteria 2(4) and 3 accordingly, and
attributed the preview/foreign-project claim to code structure at
cmd/bd/main.go:1485 rather than to that test. PR #6424 body reworded to match
(not part of this commit; edited via gh pr edit).

bee-ghosttrack nit 3 (optional): one-line comment on the unreachable
"classifiedRead without readOnly" table case explaining it documents totality,
not a reachable state.

Full suite: 0 FAIL. Targeted re-verification (TESTCONTAINERS_RYUK_DISABLED=true
to dodge host-load reaper flakiness): TestServerModeDeferAutoWake 5/5 subtests
PASS (12.427s), TestDeferWakeSweepEligibleHonorsClassifiedRead 4/4 subtests
PASS (5.957s).

* chore: remove leaked internal release-gate doc from PR branch

  release-gates/be-6iglh-gate.md

Tracked our internal gc-management/beads-rig release-gate checklist and
should never have been committed to this upstream branch -- it's process
residue from our deploy tooling, not part of the change itself.

Per maintainer bee-ghosttrack's request during review of PR #6571. The
root cause (our deploy tooling auto-committing this file) is already fixed
as of gm-qatxl1; this branch predates that fix, so this commit is cleanup
only -- no other content on this branch is touched.

Ref: be-lk7o3

* ci(proxied-shard): discover TestServerMode* entry points

Review finding (major, Test Evidence Quality): TestServerModeDeferAutoWake —
this PR's only end-to-end guard for the classified-read defer-wake fix — was
selected by no CI lane. The two lanes that set BEADS_TEST_PROXIED_SERVER=1
both shard through proxied-test-shard.sh, whose discovery grep matched only
`^func TestProxiedServer`, so the wiring lines at cmd/bd/main.go:1675 and
internal/storage/dolt/store.go:2136 had zero CI-executed coverage: the one
CI-reachable new test pins the pure predicate and cannot catch a mis-wired
flag.

Widen discovery to `^func Test(ProxiedServer|ServerMode)` in the shard script
and in scripts/ci/gen_proxied_shard_manifest.py so the two discovery patterns
stay in step, and widen the shard script's manifest-name validation to match.
That last part is load-bearing, not cosmetic: without it a regenerated
manifest containing a TestServerMode* row is rejected outright ("Invalid
shard manifest line") and the whole lane exits 1.

This also rescues the two pre-existing TestServerModeServe* suites, which
share the identical requireSharedProxiedServer gate and the same shared dolt
sql-server harness and were equally invisible — the unclosed class this PR
was following.

Verified: discovery goes 151 -> 154; a 15-shard BEADS_TEST_SHARD_LIST_ONLY=1
dry run assigns each of the 154 to exactly one shard with no pre-existing
test moved (the three land on shards 4/13/15 via hash fallback); the
pre-change script selects none of the three.

Also clarifies the reviewers' nit: the "foreign-project" exclusion named in
the new comments is not tested at the guard or in the policy expression —
those opens build their own dolt.Config and leave ClassifiedRead false, so
the guarantee is fail-closed by default.

Iteration-2 review (two minors, both non-gating): the fixup's own new prose
asserted two universals that measurement falsifies — the same class as the
nit above, reintroduced in the CI files this fixup added.

  * proxied-test-shard.sh claimed "Both families gate on
    requireSharedProxiedServer", contradicted two lines earlier by its own
    mention of the TestProxiedServerPathHelpers unit test. Transitive gate
    census over the 154 discovered entry points: 143 reach
    requireSharedProxiedServer, 10 reach the different helper
    requireProxiedServerEnv, and TestProxiedServerPathHelpers
    (cmd/bd/proxied_server_test.go, bare `package main`, three assert.Equal
    calls on path helpers) has no gate and no build tag, so it also runs in
    every ordinary `go test ./cmd/bd/` lane. Now scoped to the
    TestServerMode* family, which does gate uniformly (3/3), and the
    TestProxiedServer* side is described as mixed rather than generalized
    over.

  * main.yml claimed TestServerMode* discovery means "neither family can be
    silently left out of CI". Discovery is a non-recursive cmd/bd/*_test.go
    glob: 154 top-level matches versus 156 recursive, the difference being
    cmd/bd/doctor/database_test.go:60 and cmd/bd/doctor/dolt_test.go:126.
    Now scoped to the top-level entry points, and the comment names the
    residual hazard (a container-gated suite added under cmd/bd/<subpkg>/ is
    still never selected here) instead of implying it cannot happen.

Both edits are comment-only and behaviorally inert: non-comment lines are
byte-identical in both files, and the 15-shard BEADS_TEST_SHARD_LIST_ONLY=1
sweep is byte-identical before and after (154 assignments, 0 duplicates,
assigned set == discovered set, the three TestServerMode* still at 4/13/15).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* ci(bazel): add defer_wake_server_test.go to cmd/bd go_test srcs

Maintainer CI repair, generated by `make bazel-sync` (gazelle).

`cmd/bd/BUILD.bazel`'s `go_test` srcs is an explicit list, not a glob, so the
new `cmd/bd/defer_wake_server_test.go` was never compiled or run by the Bazel
lane. `Bazel / test` failed two required steps on the pushed head
`0a3f5e0047`:

  Go test equivalence:
    go test:  105 packages, 8988 top-level tests
    bazel:    107 go_test targets, 106 tested; 8987 top-level tests seen
    tests go test runs that Bazel did not (1):
      cmd/bd  TestServerModeDeferAutoWake
    EQUIVALENCE: FAIL

  BUILD files in sync (gazelle, go_srcs, MODULE.bazel): out of sync

`BAZEL_TEST` is listed in `CI_GATE_REQUIRED` for `CI Gate / Required`
(.github/workflows/pr.yml), so this is a required-lane red, not advisory.

That the missing test is this PR's own headline guard makes the repair squarely
in scope: the PR exists to close exactly this "no CI lane runs it" gap, and its
review fixup closed it for the proxied shard lane. The Bazel lane had the same
gap for a different reason.

Attribution: main's Bazel run at this PR's exact base 43a526b828 concluded
success, so the red is this branch's, not inherited.

Validation:
- `make bazel-sync` produces exactly this one line; a second run is a no-op
  (gazelle idempotent, md5 7d1d0549fcd466159451c02181661c78).
- Byte-identical to CI's own `bazel-sync-patch` artifact for this head
  (blob pair efec974..6dd76e3).
- srcs-only change: gazelle added no deps entry, so every import the new file
  needs was already declared.
- `bazel build //cmd/bd:bd_test` succeeds, and the generated
  `bd_test_/testmain.go` now enumerates TestServerModeDeferAutoWake, which is
  the row the equivalence check reported missing.
- `tools/bazel/go_srcs.py --check` was already clean, and `bazel mod tidy`
  produced no MODULE.bazel drift, so this single line is the whole repair.

No contributor commit is modified and no Go source changes.

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-30 15:53:22 -07:00
ecuthiell
4183fa0509
test(scripts): resolve Git Bash explicitly on Windows (#5727) (#5730)
* test(scripts): resolve Git Bash explicitly on Windows

Add one test-only resolver that positively identifies Git Bash on Windows and use it in the doc-freshness and PR-preflight fixtures. Preserve ordinary PATH resolution on non-Windows hosts and leave the remaining #5727 callers for follow-up.

Part of #5727.

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* docs(testbash): state exact probe completion requirements

Document that capability scripts must be silent on both streams and reach
the sentinel epilogue without exiting the shell. Remove redundant startup
environment entries already stripped by the shared resolver.

Bead: saa-cgh.13
Agent-Signature: unknown-model/unknown-reasoning

* chore(bazel): sync BUILD files for scripts/internal/testbash

`make bazel-sync` output for the new `scripts/internal/testbash` package,
regenerated with `bazel run //:gazelle`:

- add the generated `scripts/internal/testbash/BUILD.bazel`
  (`go_library testbash` + `go_test testbash_test`)
- add `//scripts/internal/testbash` to `//scripts:scripts_test` deps

Without this, `bazel.yml` fails two ways:

1. `bazel test //... --config=integration` (bazel.yml:592) is a hard compile
   failure — `compilepkg: missing strict dependencies` for the
   `scripts/internal/testbash` import in both `check_doc_freshness_test.go`
   and `pr_preflight_test.go`. The default config builds clean because both
   files are `//go:build integration`, so only the integration lane sees it.
2. The `BUILD files in sync` step (bazel.yml:310) exits 1 on the
   `make bazel-sync` drift.

`make bazel-sync-check` (go_srcs globs only) and the repo's own
`TestBazel*` policy tests are both blind to this and pass either way.

* fix(testbash): pin the sanitization contract and split probe diagnostics

Maintainer review fixups for the adopt-pr review of PR #5730 (iteration 1,
synthesis approve / no blocker or major; all items were non-gating).

Finding 1 (minor, Test Evidence Quality) — the sanitization test's oracle was
the predicate under test. TestSanitizedEnvironmentRemovesBashAuthorityControls
validated the sanitized result by calling isBashAuthorityControl, the very
predicate sanitizedEnvironment filters with, so filter and oracle weakened in
lockstep and the assertion could not fail for any definition of the predicate.
It now asserts against the test's own controls literal and checks the
BASH_FUNC_ prefix class separately, pinning both the filter plumbing and the
key list. Proven with a three-arm control: fixed test + real predicate passes;
fixed test + a full `return false` neuter of isBashAuthorityControl now FAILS
(it previously passed); the original test + the same neuter still passes, so the
new failure is caused by this change and not by the mutation itself.

Finding 4 (nit, Debuggability) — a chatty-but-successful probe reported the
sentinel as unreached while its own quoted payload contained it. runProbe now
branches on strings.HasSuffix and emits a distinct "completed but wrote
unexpected output before the execution sentinel" message quoting only the stray
payload. The three existing assertions on "without the exact execution
sentinel" all cover cases whose output is empty (early exit, noexec), so none
of them can take the new branch; verified by execution.

Finding 3 (nit, Debuggability) — Probe's doc comment named only the three Bash
control classes while the implementation also strips GIT_EXEC_PATH. The comment
now documents Bash and Git authority controls explicitly.

Finding 2 (minor, Test Evidence Quality) is deliberately NOT taken here and
remains a non-gating follow-up. Its primary remedy — adding
./scripts/internal/testbash to the windows-latest leg — would execute four
//go:build windows tests that have never run on any lane, and the synthesis's
own Unresolved Uncertainty concerns MSYS2 PATH handling in exactly this
package's validateCandidate, which is not verifiable from Linux; a first-ever
execution that reds pr-preflight-platforms is not the "nearby, cheap, low-risk"
cleanup the operator contract allows. Its fallback arm only typechecks and
would edit repo-wide CI outside this PR's payload. Note that finding 1 reduces
finding 2's severity: the sanitization contract is now pinned on every Linux
lane instead of only incidentally on Windows.

Validation: go test ./scripts/internal/testbash ok; go test -run
'^TestDocFreshness|^TestPRPreflight' ./scripts ok, and ok again with
-tags=integration,gms_pure_go; gofmt clean; go vet clean; CGO_ENABLED=0
GOOS=windows go vet ./scripts/... and go build ./scripts/... both rc=0;
git diff --check clean. No files added or removed, so the generated
BUILD.bazel srcs are unchanged.

Contributor commits are untouched.

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
2026-09-30 15:50:28 -07:00
Julian Knutsen
a3b6dc9ac5
ci(bazel): remote-execution Bazel lanes for allowlisted fork authors (advisory) (#6994)
* ci(bazel): remote Bazel lanes for allowlisted fork authors (advisory)

Add bazel-farm.yml, a pull_request_target caller of bazel.yml. It gives the
RBE farm to fork PRs to main whose author and triggering user (sender: the
pusher on synchronize) are both on .github/bazel-farm-allowlist.txt, which
is read from the base commit. The list has julianknutsen, quad341, sjarmak
and csells, the same as gascity's blacksmith allowlist.

- authorize job: sparse checkout of github.sha that holds only the
  allowlist and .github/scripts/bazel-farm-authorize.sh; no token on disk,
  no secrets, event facts through env only. The script also checks fork vs
  base repo, the default branch, the action, and a 40-hex head SHA.
- farm job: calls bazel.yml with contents: read, exactly the four RBE
  secrets, checkout-sha pinned to the event's head SHA, and
  fork-farm: authorized.
- bazel.yml: new checkout-sha and fork-farm inputs (no-ops for pr.yml and
  nightly.yml). Every lane checks out inputs.checkout-sha with
  persist-credentials: false. The rbe job runs a fork remotely only for an
  authorized pull_request_target call, and then remote or skip, never
  local. PR concurrency also cancels on pull_request_target. The
  bazel-sync-patch upload is skipped on pull_request_target.

Advisory only: pr.yml is unchanged, so every fork PR still runs the local
Bazel lanes inside the enforced CI Gate / Required.

Policy tests pin the trigger and types, both jobs' conditions, the
allowlist source and contents, the pinned checkout, read-only permissions,
where secrets appear, no expressions in run scripts, per-PR concurrency,
the timeout, and that no workflow_run consumer can pick up a farm run.
TestBazelLaneIsGatedAlongsideLegacy now allows pull_request_target on a
bazel.yml caller for bazel-farm.yml only. 26 mutations were each caught
by these tests (sender check dropped, allowlist read from the PR head,
write permission added, event data interpolated into run, SHA pin dropped,
and others).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): trusted-author fork PR farm design and threat model

Document bazel-farm.yml in the required-check topology:
- the design, and why it is advisory rather than part of the enforced
  gate;
- the gate options considered;
- the threat model: allowlist spoofing, sender vs. author, TOCTOU with the
  pinned SHA, workflow-file edits, script, label and comment injection,
  token scope, artifact poisoning, and farm and Actions cache poisoning;
- what can only be verified on GitHub.

The one capability a listed author gets beyond a same-repo PR is called
out as an accepted risk, with mitigations: pull_request_target runs use
the default branch's Actions cache scope.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): opt the farm's lane checkouts into fork-head checkout (F1)

actions/checkout@3d3c42e5 is v7.0.1, not v6, and v7 refuses to check out
a fork PR's head SHA on pull_request_target unless
allow-unsafe-pr-checkout is true. Every lane of an authorized farm run
therefore failed at checkout.

- Each bazel.yml lane checkout now sets allow-unsafe-pr-checkout to
  inputs.fork-farm == 'authorized' && github.event_name ==
  'pull_request_target'. That is false for every other caller and event.
- TestBazelWorkflowForkFarmInputs pins that exact expression. It also
  fails if the key appears anywhere else in the workflows (so never a
  literal true, and never on the authorize checkout).
- Relabel the checkout pin as # v7.0.1 in bazel.yml and bazel-farm.yml.
- Add the opt-in to the engdoc's design section and to the
  verify-on-GitHub list.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): verify everything restored from caches in Bazel lanes (F3)

A farm run executes PR code in the default branch's cache scope. GitHub's
own cache is read-only for pull_request_target: GitHub issues a read-only
token, and cache-mode defaults to read. Whether Blacksmith's colocated
cache enforces the same is unverified. So trusted runs no longer execute
anything they restore without verifying it first:

- setup-bazel: Bazelisk's home moves out of the runner cache to a fresh
  $RUNNER_TEMP/bazelisk-home, so the Bazel binary is never restored from
  a cache. BAZELISK_VERIFY_SHA256 is set to the release sha256 pinned for
  the .bazelversion version on each arch (9.2.0 amd64 and arm64). The
  wrapper step then re-checks every Bazel binary in that home.
- write-bazelrc.sh: add common --repo_contents_cache=. The repo contents
  cache holds extracted repos that Bazel never re-verifies. The
  content-addressable repository cache stays, since Bazel re-hashes it on
  every hit.
- Runner cache key bumped to bazel-repo-v3 (the content changed).
- bazel-test runs `go mod verify` right after the Go module cache restore.
- Policy tests:
  - cache-mode may only be read or none in bazel-farm.yml, bazel.yml and
    setup-bazel;
  - bazel.yml permissions are exactly contents: read;
  - the Bazel sha pin matches .bazelversion, and Bazelisk's home is
    outside the cache;
  - the binary is verified after download;
  - go mod verify follows every module cache restore;
  - the rc disables the repo contents cache.
- Engdoc and bazel-farm.yml header: corrected about GitHub's read-only
  cache, noted Blacksmith as unknown, and listed the full blast radius
  (release.yml hardening tracked separately). The canary design is in the
  rollout notes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): farm runs only the author's own fork, on opened/synchronize (F4)

"The sender is listed" did not prove that a listed user chose the head
commit:
- A listed author could open a PR whose head is a third party's fork, and
  that fork's owner could push between the author's review and "Create".
- A collaborator on a listed author's fork could push while the PR was
  closed or a draft (that push is skipped), and the author's later
  "Reopen" or "Ready for review" click would run it with secrets.

Changes:
- The authorize script requires the head repository owner's numeric id to
  equal the PR author's (HEAD_OWNER_ID, PR_AUTHOR_ID, passed via env).
- Drop the reopened and ready_for_review triggers, and the script now
  refuses those actions too. Drafts already run on opened and
  synchronize.
- Tests pin the trigger types and the new env, and add script cases:
  - cross-fork head, missing or non-numeric owner id;
  - reopened and ready_for_review refused;
  - unanchored action (xopenedx);
  - base-repo prefix (gastownhall/beads-evil). This covers two mutations
    the reviewer found surviving.
- Engdoc: the new checks, and the residual that stays the listed author's
  responsibility (commits pushed by fork collaborators).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): match the farm allowlist on numeric user ids (F5)

Logins are mutable: after a rename, anyone can register the old login,
and before this change they would then be listed as both author and
sender.

- The allowlist now holds one numeric user id per line, with the login as
  a comment. The ids were looked up with gh api users/<login> --jq .id.
- The authorize script matches PR_AUTHOR_ID and SENDER_ID
  (github.event.pull_request.user.id, github.event.sender.id). Logins are
  now used only in the log. An allowlist entry that is not a numeric id
  fails the job.
- Tests pin the id-to-login table and the SENDER_ID env. Script cases:
  - a renamed login re-registered with a new id (author and sender);
  - id prefix, suffix and leading zero;
  - an id that appears only in a comment;
  - listed ids with unlisted logins;
  - a PR from another listed user's fork;
  - broken allowlists (a login entry, a signed id).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): farm re-run semantics and the add/remove-user procedure (F6)

A re-run replays the original event. It checks out the same pinned head
SHA, which is fine. It also reads the allowlist at the original base
commit, so a user removed from the list still gets the RBE secrets when
one of their old runs is re-run. Only users with write access can
re-run.

- Engdoc: how to add a user.
- Engdoc: how to remove a user. Merge the removal, then cancel and delete
  their farm runs (a gh api query by head-repository owner id). For
  cause, rotate RBE_TLS_CERT/KEY and have the farm revoke the old
  certificate; rotating also closes the re-run window.
- bazel-farm.yml header: points to the procedure.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): name the farm call "Bazel Farm", not "Bazel" (F7)

The farm's check runs were named "Bazel / <lane>", the same as pr.yml's.
Farm results are PR-controlled: PR code runs setup-bazel and can make a
lane exit 0. If a ruleset ever required a "Bazel / ..." check, a farm run
could satisfy it. The farm's checks are now "Bazel Farm / <lane>", and a
test pins the name and requires it to differ from pr.yml's bazel job.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): run the farm authorize script in the C locale (F8)

Bash bracket ranges and ${v,,} depend on the locale. In en_US.UTF-8,
[0-9], [0-9a-f] and [A-Za-z] match some non-ASCII characters, and the
Kelvin sign lowercases to "k". This is not exploitable (GitHub ids,
logins and SHAs are ASCII, and the allowlist is maintainer-controlled),
but the script now exports LC_ALL=C.

The script tests now run under en_US.UTF-8 and add cases with non-ASCII
digits in ids and a non-ASCII character in the SHA. Without the export,
the SHA case fails, so the tests catch its removal.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): farm authorize script runs on bash 3.2 (macOS)

${v,,} is bash >= 4; macOS runners' /bin/bash is 3.2, so the script's
tests failed there. Lowercase with tr under LC_ALL=C (ASCII only, as before).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 14:54:06 -07:00
ecuthiell
448c4b8621
test(prime): use native config root in global fixture (#5778)
* test(prime): use native config root in global fixture

The global PRIME override fixture staged Linux and macOS paths while the Windows child resolved os.UserConfigDir from inherited APPDATA. Build one isolated profile, ask the host for its native config directory, and stage the override only at that path. Production behavior is unchanged.

Related to #4638.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* test(prime): create advertised profiles and exercise Windows fixture

Create each isolated profile directory before exporting its path. Run the
global override through the shared test runner in the existing required
Windows job, rejecting absent, skipped or failed selected coverage.

Agent-Signature: unknown-model/unknown-reasoning

---------

Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 07:26:09 -07:00
Julian Knutsen
2d395d35af
ci(release): never restore Actions caches into release builds (#6966)
setup-go's default cache in release.yml is keyed predictably and falls back
to the default branch's Go module and build caches, which are restored
without re-verification before binaries are built, signed and attested.
Turn it off in every release job and pin that with a policy test.

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 04:39:23 -07:00
Julian Knutsen
e1b2e79484
ci: gate PRs on the Bazel lanes, alongside the legacy jobs (D1) (#6941)
* ci(bazel): gate the Bazel lane alongside the legacy jobs (D1)

pr.yml now calls bazel.yml (workflow_call) as its `bazel` job, and its
CI Gate / Required requires the call's aggregate (BAZEL) plus each gated
lane's result (BAZEL_TEST, BAZEL_PURE, BAZEL_EMBEDDED, BAZEL_DOLTSERVER).
No legacy job is removed: PR Core, build-artifacts, the pure-Go/js-wasm
check, domain+uow, contract corpus and pr-risk.yml's embedded tier stay
required (D2 is separate).

- bazel.yml drops its own pull_request/merge_group triggers, so a PR runs
  the lane once; push to main, workflow_dispatch and workflow_call stay.
- Every lane records job.status in an always() last step and exports it
  as a workflow_call output named after the job, next to the rbe job's
  rbe-mode / rbe-enabled.
- .github/scripts/bazel-gate.sh reads the call's rbe-mode/rbe-enabled and
  never re-derives the variable/fork/secret condition: mode skip allows
  every Bazel id to skip, local only the remote-only BAZEL_EMBEDDED,
  remote none; a missing or inconsistent mode fails the gate.
- bazel-integration runs in the PR call but stays advisory (its legacy
  counterparts in main.yml run only on push to main): no gate id, and the
  gate script excuses the aggregate failure only when that lane reported
  failure or cancelled in remote mode; the gated lanes are still checked
  on their own ids.
- Callers (pr.yml, nightly.yml) pass exactly the four RBE secrets that
  bazel.yml now declares, never `secrets: inherit`.
- Inside pr.yml's run the Bazel bd artifact is bazel-ci-build-artifacts,
  so it cannot collide with build-artifacts' ci-build-artifacts upload.
- bazel-autofix.yml now triggers on workflow "PR": the bazel-sync-patch
  artifact is uploaded inside the PR run, and "Bazel" runs are no longer
  PR events. Its security model is unchanged (base-branch checkout only,
  artifact read from the triggering run id, data-only patch).
- Policy tests (review D1 F3/F4/F7):
  - TestBazelLaneIsGatedAlongsideLegacy: every bazel.yml job is the rbe
    job, a gated lane (bazelLaneGateIDs) or an advisory lane with a
    reason; gate ids, env expressions and outputs are derived from that
    map; no re-derivation in the gate step or script.
  - TestBazelGateSimulation runs pr.yml's actual gate step over mode in
    {remote, local, skip} (pull_request and merge_group): the script's
    skips equal the ids whose job `if:` is false, and for each lane that
    should run, it alone skipped, failed or cancelled turns the gate red
    whatever the aggregate says; advisory, aggregate and invalid-mode
    cases too.
  - TestBazelArtifactNamesUniqueInCallerRuns: no artifact name collides
    within a pr.yml or nightly.yml run, following local workflow calls.
  - Autofix: workflow_run on "PR", which must upload bazel-sync-patch
    itself or through an unconditional local call.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): keep integration out of the PR call; pin the call's inputs (D1 review v2)

- N1: bazel.yml gains a string workflow_call input `integration`
  (default "on"); bazel-integration runs only when remote and
  `inputs.integration != 'off'`. A string, not a boolean: on push and
  dispatch the input is null, and null == false would silently stop the
  lane on main. pr.yml passes integration: "off" (main.yml's integration
  jobs, its legacy counterpart, run only on push to main). The gate no
  longer reads bazel-integration and bazel-gate.sh no longer excuses an
  aggregate failure: BAZEL is the call's result, red on a missing or
  inconsistent rbe mode.
- N3: pr.yml's call passes exactly build-artifact-name and
  integration: "off" (no rbe or other override).
- N4: bazel.yml's concurrency group never uses github.workflow (the
  caller's name in a call) and differs from each caller's group for every
  event, so the call cannot deadlock against pr.yml.
- N5: no caller of bazel.yml (pr.yml, nightly.yml) may have a
  pull_request_target or workflow_run trigger.
- Simulation: lanes' run modes are evaluated with pr.yml's call inputs;
  advisory lanes must not run in the PR call, gated lanes must run when
  remote.
- engdocs: runbook for main BUILD drift, a farm outage or the RBE cert
  expiry (~2027-09-27): fix main / renew, or unset RBE_WEST_WORKERS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the enforced required-gates ruleset and PR Risk's renamed gate

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): gate the proxied-server and server-Dolt storage lanes

bazel-proxied and bazel-server-storage (remote-only, #6940) join the
gated lanes like bazel-embedded: pr.yml's ci-gate requires
BAZEL_PROXIED and BAZEL_SERVER_STORAGE, each read from the lane's
job.status output (always() recorder step, workflow_call output named
after the job). Both run in pr.yml's call (no integration switch).

bazel-gate.sh allows them to skip in mode local (forks, Dependabot:
pr-risk.yml's legacy tiers cover those PRs) and in mode skip, never in
mode remote. The gate simulation derives this from the jobs' ifs, so
each lane skipped, failed or cancelled in remote mode turns the gate
red. Jobs are renamed "proxied-server tier" / "server-Dolt storage tier"
(shown as "Bazel / ..." under pr.yml's call).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 03:33:20 -07:00
Julian Knutsen
e7138e93af
ci(bazel): server-Dolt storage and proxied tiers on remote execution (#6940)
* test(integration): let SubprocessRunner reuse a prebuilt test binary

BEADS_TEST_SUBPROCESS_BINARY hands SubprocessRunner an already-built test
binary of the package instead of running `go test -c`, which no Bazel
action can do offline (it needs the module source tree and module cache).
A Bazel target passes the running go_test itself: the helper tests
(TestHelperSchemaInit, TestHelperMultiStore) live in the same package.
Unset, behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(dolt): keep a lane's REQUIRE switch out of the leak-probe child

TestSuiteFixtureLeakFailsOwningSuite re-runs the suite with
BEADS_TEST_SKIP=dolt on purpose. When the parent runs under
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 (a fail-closed server lane), the child
inherited it and TestMain exited FATAL before the leak sweep the test
checks. Clear it in the child like the other suite-scoped variables.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(bazel): proxied-server and server-Dolt storage tiers (D6d, D6e)

PR Risk's "Test (Proxied Dolt Cmd N/15)" (also main.yml's) and "Test
(Server Dolt Conformance)" / "Test (Server Dolt Full Suite N/16)" as
Bazel variants against local dolt sql-servers (internal/testutil local
backend, pinned dolt from the test wrapper), fail-closed like the
dolt-server lane:

- //cmd/bd:bd_proxied_test: 15 shards; shard k runs the job's
  proxied-test-shard.sh k+1 15 through go_test_manifest_shard.sh over the
  race bd_test, non-race bd_for_tests as the subprocess bd,
  BEADS_TEST_PROXIED_SERVER=1, GOMAXPROCS=4. Tag dolt-server-proxied,
  --config=doltserver-proxied (the doltserver lane's build).
- //internal/storage/dolt:dolt_server_{conformance,full}_test over
  dolt_race_off (go_test_race_off of dolt_test: the jobs' binary is not
  race); the full suite runs server-storage-test-shard.sh k+1 16 with
  BEADS_TEST_ENV_RUN_DOLT=1 and hands SubprocessRunner its own binary.
  Tag dolt-server-integration, --config=doltserver-integration, whose
  build flags are exactly --config=integration's, so the tier shares that
  lane's compile (race-off deps land where bd_for_tests already is)
  instead of compiling the tagged graph a third time.
- dolt_test gains //internal/storage/schema:migrations as data (the
  PR4107/migration replay tests read ../schema/migrations).
- test_env.sh: BEADS_TEST_GIT_IDENTITY=1 writes the jobs' global git
  identity ("Configure Git"); the git-remote tests commit in fresh repos.
- Both tags join the taxonomy and bazelPRCoreExcludedTags, so prcore/ci
  and integration exclude them.

Per-shard names and statuses equal a replay of the jobs' commands
(container backend) for all 32 jobs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run the proxied and server storage tiers remotely (advisory)

bazel-doltserver gains a second, remote-only step, `bazel test //...
--config=doltserver-proxied` (15 shards of ~5-10 min with a busy dolt
sql-server each do not fit a GitHub-hosted runner; forks and rbe=off keep
the local lane unchanged). bazel-integration gains `bazel test //...
--config=doltserver-integration`, which shares its build flags, so the
server storage tier compiles nothing the integration step has not. Both
steps write their own BEP, run check_testcases.py on it, run even when the
job's first test step failed, and upload logs on failure.

Policy (TestBazelDoltServerTiersMirrorPRRisk): each variant runs its jobs'
shard script with their shard total and has script + manifest in data;
the conformance variant passes the job's flags; the jobs' race/non-race
binaries and switches (BEADS_TEST_PROXIED_SERVER, BEADS_TEST_ENV_RUN_DOLT)
match; doltserver-integration's tags and race equal --config=integration's;
the steps are pinned to their jobs. checkDoltServerRules now holds all
three dolt-server lane tags to the local-backend, fail-closed,
remote-capable rules.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run the proxied and server storage tiers in jobs of their own

Review of D6d/e: as steps of bazel-doltserver and bazel-integration the
tiers inherited those jobs' gating (a caller switching the integration
lane off would drop PR Risk's PR-time server tier; a gate requiring the
dolt-server lane would silently require the proxied tier too) and
lengthened their critical paths.

bazel-proxied (--config=doltserver-proxied, 15 shards) and
bazel-server-storage (--config=doltserver-integration: conformance + 16
shards) are remote-only jobs that need only rbe, each with its own BEP,
check_testcases.py step and log upload, 25-minute test step inside a
30-minute job. bazel-doltserver and bazel-integration are back to their
previous content, including the dolt-server step's 80-minute timeout for
local runs. The server tier shares bazel-integration's compiles through
the remote cache (same build flags).

The proxied tier mirrors PR Risk's race bd-cmd-test; main.yml's twin
job runs build-artifacts' non-race one, so Bazel is the stricter of the
two. Comments now say so, and the policy test pins main.yml's build so a
change there is noticed. Policy: the new jobs are pinned (command,
config, remote-only if, BEP + testcase steps, timeouts, log upload), and
no tier step may run in bazel-integration or bazel-doltserver.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 23:01:40 -07:00
Julian Knutsen
9cb22b790c
ci(bazel): decide RBE mode once (fixes Dependabot runs); add advisory integration lane (#6930)
* ci(bazel): decide the RBE execution mode once, in an rbe job

Dependabot PRs are same-repo (fork=false) but receive no Actions secrets,
so the per-job vars/fork conditions sent them down the remote path with
no executor: every lane ran locally on the 2-vCPU Blacksmith runner and
the remote-only embedded tier timed out (review D1 F1). The conditions
were also repeated in every job and re-read at different times (F5/F6).

A new first job, rbe, decides the mode from four booleans (the
RBE_WEST_WORKERS var, rbe input, fork, and whether RBE_WEST_EXECUTOR is
non-empty) and outputs mode=remote|local|skip plus enabled. Every lane
needs it and takes runs-on, if and the setup-bazel env from its outputs
alone; remote-only bazel-embedded skips unless remote, local-capable
lanes run on ubuntu-latest for forks, rbe=off and secret-less runs.
Same-repo runs still skip while the var is unset. The outputs are also
workflow_call outputs (rbe-enabled, rbe-mode) for a future gate.

Policy tests: every lane needs rbe and uses the pinned expressions; no
value outside the decision step mentions the var, inputs.rbe or fork;
the one extra secret reference is pinned to the emptiness test in the
decision step's env; and the step script is run for same-repo, push,
Dependabot, fork, rbe=off, var-unset and mixed-case scenarios.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): add the advisory bazel-integration job

Runs `bazel test //... --config=integration` (#6916, main.yml's
integration jobs) as its own job in bazel.yml: remote-only like
bazel-embedded (skipped unless the rbe job chose remote), 30-minute test
step inside a 40-minute job, BEP plus check_testcases.py, test logs on
failure. A separate job keeps ci's and integration's shared
bazel-testlogs apart (review-integration F3). No equivalence step:
equivalence.py's default mode is the --config=ci selection, and its job
mode needs the integration jobs' go test -json, which no run here has.

check_testcases.py gains --not-go LABEL for a tested non-Go target
(//tools/bazel:dolt_version_test, a plain sh_test the integration tag
filter keeps); an exemption for a target the BEP does not list fails.

Policy test pins the job's command (no extra filter, selector or remote
config), the count step, the log upload, its remote-only if, and that no
other job runs --config=integration (nor this one --config=ci or
equivalence.py); the .bazelrc tag filter stays pinned by
checkBazelrcIntegrationLane.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 19:05:41 -07:00
Julian Knutsen
90b84ea150
ci: auto-push Bazel BUILD sync fixes to PRs; harden docs autofix (#6907)
* ci(bazel): auto-push `make bazel-sync` fixes to PR branches

bazel.yml's BUILD sync step now writes the BUILD.bazel / MODULE.bazel /
MODULE.bazel.lock part of its drift as the bazel-sync-patch artifact
(scripts/ci/bazel-sync-patch.sh) and still fails. The new bazel-autofix.yml
workflow_run job (on "Bazel" and "PR") applies it with
scripts/bazel-autofix-push.sh: a sync commit on same-repo PR branches, an
idempotent apply-recipe comment on fork PRs.

Same security model as docs-autofix: the write-permission side never checks
out or runs PR code, extracts only the two expected regular files, and
refuses any patch naming a path outside an anchored allowlist (no hidden or
`..` segments, nothing under third_party/) or carrying a mode change,
symlink, rename or binary hunk; `git apply --index` and a post-apply check
back that up. Reuses the DOCS_AUTOFIX_TOKEN secret for the push.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): add bazel_autofix_push_test.go to scripts_test

`make bazel-sync` output, produced by scripts/ci/bazel-sync-patch.sh and
applied with scripts/bazel-autofix-push.sh as an end-to-end exercise of the
new autofix path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): harden the bazel and docs autofix push scripts

Addresses the security review of the autofix pipeline, identically in
scripts/bazel-autofix-push.sh and scripts/docs-autofix-push.sh (the
security-critical functions are now shared verbatim):

- validate_patch refuses ANY "rename "/"copy " header (the legacy
  "rename old/new" form slipped past and, on docs-autofix, pushed a
  scripts.sh -> docs/cli-reference/x.md rename), checks every "index "
  line whatever its ids, takes creations/deletions/renames from
  `git apply --summary`, and reads names from `--numstat -z` (which
  names only the NEW path of a rename; the old comment was wrong).
- docs-autofix gains the post-apply staged re-check and a --check mode.
- The patch is applied to an index in a bare clone (read-tree +
  apply --cached + commit-tree): the PR tree never touches the disk.
  All git calls run with core.hooksPath=/dev/null, GIT_LFS_SKIP_SMUDGE=1.
- Push is leased: --force-with-lease=refs/heads/$HEAD_BRANCH:$HEAD_SHA.
- The PR must target this repo, and the head branch must be neither
  protected nor under a ruleset per the GitHub API (fail closed), on top
  of the name list.
- Only a marker comment written by github-actions[bot] is ever edited.
- bazel-autofix only pushes files in packages the PR changed
  (merge-base..head, computed from fetched refs), MODULE files only when
  go.mod/go.sum/MODULE changed; base-branch drift is left alone and
  listed, and a patch with nothing attributable gets a comment only.

Tests cover each reviewer attack for both scripts (--check and the full
flow against a local bare remote and fake gh), the staged check alone
with the validator disabled, spoofed comments, protection/ruleset/API
errors, the lease, main drift, and symlinked PR trees.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): trigger bazel-autofix on Bazel only; share job-level concurrency

- bazel-autofix.yml triggers only on "Bazel": pr.yml never calls
  bazel.yml, so "PR" runs never carry the artifact, and their completions
  cancelled real fixes through the workflow-level group. The policy test
  now requires the triggering workflow to run on pull_request and upload
  the consumed artifact instead of asserting the false claim.
- Both autofix workflows use one job-level concurrency group per head
  branch (autofix-<head repo>-<head branch>) without cancel-in-progress:
  skipped runs take no part, and the two bots queue instead of racing.
- Base checkouts use persist-credentials: false; docs-autofix extracts
  only cli-docs-freshness.patch, as a regular file, outside the workspace.
- Policy tests for the trigger, concurrency scope, checkout, and the
  scripts' shared guards (rename/index checks, comment author, lease,
  protection lookup, index-only apply, hook-free git).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): tighten autofix attribution, circuit breaker and PR selection

Re-review follow-ups for the bazel and docs autofix push scripts:

- Root package: paths outside any Bazel package (docs/, .github/,
  README.md, ...) no longer count as changing //:. Only root-level Go and
  build inputs (*.go, *.s, *.c, *.h, *.bzl, go.mod, go.sum, BUILD.bazel,
  MODULE.bazel*) make root BUILD.bazel drift the PR's, so main's root
  drift is not pushed onto a docs-only PR.
- Circuit breaker: the head subject is read from the fetched commit (no
  API), a failed read counts as non-convergent, and the check runs only
  once the PR's own staged fix is non-empty. A bot head whose remaining
  drift is main's now gets the "files this PR did not change" comment
  instead of a wrong "did not converge" one. Same in docs-autofix.
- PR selection: several open PRs can share one head branch. bazel picks
  the one whose number matches the artifact metadata (among PRs already
  matching head repo/branch/base repo; head sha still verified); without
  a unique match both scripts skip instead of taking .[0].
- The privileged clone fetches only the head (and, for bazel, base)
  branch into an init'ed bare partial repo instead of cloning every
  branch.
- docs-autofix job gets timeout-minutes: 10 (it shares a non-cancelling
  concurrency group with bazel-autofix).

Tests: docs-only/README/workflow/Makefile PRs with root drift get no push,
a root Go change gets root BUILD.bazel; breaker cases (bot head with own
vs main drift, unreadable subject) for both scripts; PR selection by
metadata and ambiguity; HEAD_SHA 40-hex guard; staged-check mode arm; a
--summary-only validator copy; both workflows' download steps run as
written against a fake gh (run-scoped artifact listing, only the named
files extracted, symlinked entries refused); timeout asserted for both
jobs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): bazel-autofix requires bash 4; skip its tests on macOS bash 3.2

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(ci): skip every autofix script test on bash < 4

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): sync internal/utils BUILD with main

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 17:23:27 -07:00
Bùi Phan Viết Cường
5cc896c8f0
fix(lint): suppress two darwin-only gosec findings and cross-lint the darwin build in CI (#6243)
* fix(lint): suppress two darwin-only gosec findings and cross-lint the darwin build in CI

scripts/ci/pr-lint.sh lints natively on the ubuntu runner plus one
GOOS=windows CGO_ENABLED=0 cross-lint, so files behind //go:build darwin
(and the !windows && !linux fallbacks) were never linted in CI. Linting the
darwin build reports two gosec findings that are clean on linux:

- internal/config/permissions_open_nonlinux.go: G304 on os.Open(path). The
  file comment already explains why it is safe (fixBeadsDirPermissions
  re-checks descriptor identity before chmod); it just had no directive.
- internal/utils/path_case_darwin.go: G103 on unsafe.Pointer. A directive
  existed but sat on the first line of a multi-line unix.Syscall call,
  while gosec reports the argument line four lines down, so it never
  covered the finding. It now sits on its own line above the statement,
  the placement cmd/bd/nocow_linux.go already uses.

Add a GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 cross-lint block to
pr-lint.sh mirroring the windows block (same flags, same lane scoping,
skipped when the native target already matches), and update the three
places that described the wrapper as two passes: engdocs/LINTING.md,
engdocs/CI_CLEANUP_PLAN.md and the comment in main.yml.

The darwin pass is compile-only on the Linux runner: no macOS runner, no
change to the pr-lint platform column. Like the windows pass it is
CGO_ENABLED=0, so darwin+cgo code stays outside its reach.

* docs(linting): bump the Last reviewed marker alongside the pr-lint change
2026-09-28 15:44:52 -07:00
Julian Knutsen
6daa06244b
build(bazel): integration-tag lane (--config=integration) matching main.yml (#6916)
* fix(test): keep TestDoltServer_StartStop_UnixSocket's socket path short

t.TempDir() nests the test's name, which alone pushes the socket path past
the 104-byte sun_path guard under any TMPDIR longer than /tmp: the Bazel test
wrapper's per-process TMPDIR (114 bytes) and macOS's /var/folders/... both
silently skipped the test that main.yml's integration job runs. Put the
socket in a short os.MkdirTemp directory instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(testutil): let SubprocessRunner build with a declared go command

SubprocessRunner.Build ran `go` from PATH. Under Bazel there is no Go
toolchain on PATH, so //internal/testutil/integration's
TestBuildErrorIsMaskedByChmod failed there. BEADS_TEST_GO_BINARY, resolved
like any other runfile, now names the go command; unset, it is still `go`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(bazel): integration-tag lane, --config=integration

main.yml's "Main Linux integration packages (N/6)" and "cmd/bd (N/8)" jobs
(and nightly's Full Test Suite) run every package with
-race -tags=integration,gms_pure_go, no -short and BEADS_TEST_SKIP=dolt.
Bazel never built the 55 `//go:build integration` files: gazelle drops a
file whose constraint names a tag it does not know.

- Root `gazelle:build_tags gms_pure_go,integration`: gazelle now lists the
  integration files in srcs and their imports in deps, and generates
  //internal/testutil/integration (integration files only). rules_go filters
  those files out of every other build, so --config=ci runs what it ran.
- --config=integration sets the tag for the whole build, like `go test
  -tags`, plus the jobs' race, BEADS_TEST_SKIP=dolt, -test.parallel=4 and a
  1200s/19m timeout pair (rbe-west's action limit; the jobs pass 30m). The
  same variants as PR core stay out (requires-docker, embedded, manual), so
  `bazel test //... --config=integration` runs the union of the 14 shards.
  A per-target gotags variant would not save the compile (gotags transitions
  the whole dep graph) and would need a second, duplicated target per package
  plus a tag to drop the plain one from this lane.
- //internal/testutil/integration:integration_test gets the pinned SDK's go
  for SubprocessRunner's `go test -c`.
- TestBazelIntegrationLaneMatchesMainWorkflow pins test:integration to
  main.yml's tags/race/BEADS_TEST_SKIP and gazelle's build_tags to a superset
  of the tags; bazel.yml's `make bazel-sync` diff already fails when a file
  gains the integration tag without a BUILD sync.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): sync scripts BUILD for upgrade_smoke_loop_test.go

make bazel-sync on current main adds the test file #6398 added.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): derive the integration lane's tag exclusions from PR core's

After main added the dolt-server tag, test:integration's filter still
selected those targets, and 5 of them fail under BEADS_TEST_SKIP=dolt. The
filter now excludes dolt-server, and the policy test no longer pins one
string: bazelPRCoreExcludedTags (kept equal to the taxonomy entries that say
"excluded from --config=prcore/ci") is the list both lanes check, the
integration lane minus the tags it runs. Every --test_tag_filters in the
lane or a config expanding it must exclude them, and no -test.short,
-test.skip, -test.run or --test_filter may reach it.

New tag integration-only for //internal/testutil/fixtures:fixtures_test and
//internal/testutil/integration:integration_test, whose tests are all
`//go:build integration`: --config=prcore/ci excludes them instead of
running two empty targets; --config=integration runs them. The .bazelrc
notes that ci and integration share bazel-testlogs.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(bazel): note shared testlogs and dolt_test's subprocess build

bazel.yml's equivalence step reads bazel-testlogs, which --config=integration
shares with --config=ci, so a job running both lanes must check each right
after its own run. //internal/storage/dolt:dolt_test's SubprocessRunner tests
need a real `go test -c` with a module cache; they stay skipped under the
lane's BEADS_TEST_SKIP=dolt, so the target gets no go SDK data.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 14:11:34 -07:00
ecuthiell
4dc96f6f21
fix(config): identify native config environment in path errors (#6325)
* fix(config): name the native config environment source in errors

Identify APPDATA on Windows, HOME on Darwin/iOS, home on Plan9, and the
selected XDG_CONFIG_HOME or HOME source on other Unix hosts. Only error
labels change; the standard-library resolver and path precedence remain
the same, and the original wrapped error is retained.

Fixes #6314
Reported-by: bee-ghosttrack
Bead: saa-cgh.95
Agent-Signature: unknown-model/unknown-reasoning

* test(config): exercise native source diagnostics on the required platforms

Select the diagnostic parent and its two XDG states through one Bash3.2
driver in the existing three-host preflight matrix. Bind the declared OS
to Bash and the setup-selected Go host/target, retain child process status,
and reject missing, duplicate, unexpected, failed or skipped execution.

Preserve existing platform steps, job identity and required gate mapping.
Use the existing YAML workflow helpers to pin the new placement.

Follow-up: https://github.com/gastownhall/beads/issues/6314
Bead: saa-cgh.95
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): keep native diagnostics with candidate builder (saa-cgh.95)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell
2026-09-28 12:17:20 -07:00
ecuthiell
90f8e42f15
fix(smoke): clear the version list before child dispatch (#6398)
* fix(smoke): clear multi-version dispatch state in child runs (saa-cgh.108)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(smoke): copy the shared candidate helper when present (saa-cgh.108)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(smoke): observe child arguments after Bash startup (saa-cgh.108)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(smoke): retain child output in dispatch failures (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell
2026-09-28 08:25:22 -07:00
Julian Knutsen
3d76cbd4e9
ci(bazel): dolt-server lane on remote execution (replaces the docker lane) (#6898)
* test(bazel): dolt-server lane for the storage domain + uow job

--config=doltserver runs pr.yml's "Test (storage domain + uow)" job as
remote-executable Bazel tests: each dolt-server target runs an existing
go_test binary with BEADS_TEST_DOLT_SERVER=local, so every Dolt server
is a `dolt sql-server` child of the test process, started from the
pinned dolt the test wrapper already ships. No docker, no
no-remote-exec, and BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 fails a target
whose server cannot start, so cached results are trustworthy.

- db_dolt_test, uow_dolt_test (8 shards), tracker_dolt_test,
  fix_dolt_test (4 shards, BEADS_FIX_REQUIRE_DOLT=1); GOMAXPROCS=4 like
  the job's runner.
- no -short twins of domain, domain/fs, domain/git and
  tracker/conformance, so the lane alone runs every package of the job.
- tag `dolt-server` in the taxonomy; test:prcore (and so test:ci)
  excludes it. The requires-docker variants stay as the A/B control.

Remote (default instance, --nocache_test_results): 9/9 PASS in 113 s
wall; longest shard 111 s (uow). Per-test statuses, subtests included,
equal the job's go test -json on the same tree: 0 differences.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): contract corpus on the dolt-server lane

protocol_dolt_test runs protocol_test as pr.yml's "Contract corpus" job
does (non-race via protocol_race_off, BEADS_PROTOCOL_REQUIRE_DOLT=1) with
the local dolt sql-server backend, in 8 shards, so the corpus golden,
determinism and conformance tests run on remote workers and cannot skip.

Remote: 8 shards, longest 53 s. 153 tests (151 PASS / 2 SKIP, subtests
included) equal the job's go test -json: 0 differences.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run the dolt-server lane in place of the docker lane

bazel.yml's container-lane job becomes bazel-doltserver: `bazel test
//... --config=doltserver`, whose targets start their own dolt
sql-servers and so execute on the remote workers (locally for forks and
rbe=off) instead of against the runner's docker daemon. The docker lane
stays reachable as the A/B control: workflow_dispatch dolt-lane=docker
runs --config=docker in the same job, with the image pull that only it
needs. Still advisory; runner, rbe-west gate and secret handling are
unchanged. Policy test and TESTING.md follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): reap processes left in a test's private root on exit

A Bazel test timeout signals the test's process group, which misses the
detached bd db-proxy-child processes (Setsid) and the dolt sql-servers they
start. A proxy that died without its idle timeout left its server orphaned on
a persistent remote worker. test_env.sh's EXIT trap now kills every process of
the current user whose command line names the action's private mktemp root
(pkill -f, two passes; a /proc scan when pkill is absent) before removing it.
The root is unique per action and never in the wrapper's own argv; cleanup
still cannot change the test's exit status.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): fail closed on every dolt-server target, checked per rule

The no-short twins (domain, domain/fs, domain/git, tracker/conformance) now
pin BEADS_TEST_DOLT_SERVER=local and BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 like
the lane's other targets, so a Dolt-server test added to those packages fails
instead of skipping into a cached pass.

TestBazelDoltJobMirrorsContainerJobs checked the env with a file-wide
substring search, so a docker variant in the same BUILD file covered for a
dolt-server target that lost it. It now parses each rule tagged dolt-server
and requires both variables, BEADS_FIX_REQUIRE_DOLT on fix_dolt_test,
BEADS_PROTOCOL_REQUIRE_DOLT on protocol_dolt_test, and no no-remote-exec.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 05:17:36 -07:00
Julian Knutsen
6dbd9dbf65
ci(bazel): embedded-Dolt tier under Bazel, shard-for-shard with PR Risk (#6896)
* fix(test): find the module root only when the concurrency test builds its binary

TestConcurrencyMultiProcess looked up go.mod before checking
BEADS_TEST_EMBEDDED_TEST_BINARY, so a pre-built binary run outside a
checkout (Bazel's runfiles hold no go.mod) failed before using it. Only
the fallback go test -c build needs the module root.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): job-mode equivalence reports TestEmbedded tests Bazel ran extra

The extra-test check always ignored ^TestEmbedded names, the --config=ci
lane's implicit skip, so a job comparison of the embedded tier could not
see a Bazel variant running more TestEmbedded* tests than the CI job.
Apply the skip only outside --job.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(bazel): embedded-Dolt tier variants and --config=embedded

PR Risk's embedded tier as embedded-tagged variants over the existing
race test binaries (no second compile):

- //cmd/bd:bd_embedded_test (20 shards) and
  //internal/storage/embeddeddolt:embeddeddolt_embedded_test (5 shards)
  run the jobs' own shard scripts through go_test_manifest_shard.sh, which
  maps Bazel shard k to the script's shard k+1 of n and stops the binary
  from sharding again. Each Bazel shard runs exactly the tests of the CI
  job with the same number (same discovery, committed manifest and hash
  fallback, binary flags). A plain -test.run ^TestEmbedded would not: nine
  TestEmbedded* functions outside *_embedded_test.go run in no CI job.
- embeddeddolt_conformance_core_test / _audit_test pass the conformance
  jobs' exact selectors and -test.timeout=30m.
- cmd shards use the race //cmd/bd:bd as BEADS_TEST_BD_BINARY, like the
  jobs' /tmp/bd-embedded-test.

test:embedded: race, tag filter embedded, build_tests_only, the jobs'
-test.parallel (4) and no -short/BEADS_TEST_SKIP; eternal is capped at
1200s, rbe-west's maximum action timeout.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run the embedded-Dolt tier in bazel.yml

New advisory job bazel-embedded (same runner, rbe-west gate and secret
handling as the other Bazel jobs) runs bazel test //... --config=embedded.
It is a job of its own so the tier's long race shards stay off
bazel-test's critical path and budget; it compiles nothing bazel-test does
not.

TestBazelEmbeddedJobMirrorsEmbeddedTier ties the config and variants to
pr-risk.yml: race builds, shard totals and scripts, BEADS_TEST_EMBEDDED_DOLT,
the race subprocess bd, the conformance selectors, and no -short.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(bazel): sync BUILD files after rebase onto main

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): Go timeouts below Bazel's 1200s cap for embedded variants

rbe-west caps actions at 1200s, so the eternal embedded variants are killed
there, and rules_go's wrapper ignores that SIGTERM: a hang ended as a bare
TIMEOUT without the goroutine dump the pr-risk.yml jobs rely on. The cmd
shards (job: -test.timeout=20m) and conformance core/audit (job: 30m) now
pass -test.timeout=19m, a documented deviation, so Go's timeout fires first.
Storage shards keep the job's 15m, which already does.

Correct the .bazelrc and BUILD comments that claimed the variants keep "the
jobs' own" timeouts, and state each target's effective limit. The policy
test now pins the 19m on the cmd shards and in place of the conformance
jobs' 30m (and flags a change of the jobs' value).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): fail bazel-embedded on targets or shards that ran no tests

The embedded variants inherit silent passes from PR Risk's shard scripts:
a shard the manifest assigns nothing exits 0 ("no tests assigned"), and a
manifest missing from the runfiles falls back to hash assignment, so every
shard still passes but no longer runs its job's tests.

- tools/bazel/check_testcases.py reads the run's BEP and fails if any tested
  target's test.xml, or any shard's, is missing or lists no top-level test
  (reusing equivalence.py's BEP and testlogs helpers). bazel-embedded writes
  a BEP and runs it after the tests; test logs now upload on any failure.
- The policy test requires each manifest-sharded variant's data to hold its
  shard script and the script's default manifest, and pins the new step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run bazel-embedded only with remote execution

Fork PRs and rbe=off dispatches ran the embedded-Dolt tier locally: 27 race
test processes (~7-10k test-seconds) plus the race compile of cmd/bd on one
GitHub-hosted runner, est. an hour or more per fork PR against the pool
whose job cap this track exists to relieve, while pr-risk.yml's embedded
jobs already run those tests for forks. bazel-embedded now runs only when
rbe-west is on (RBE_WEST_WORKERS, same repo, rbe != off); its job and step
timeouts shrink to the remote budget (60/50 min).

The policy test pins this job's if and keeps every other job on the shared
fork / rbe=off rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 04:41:10 -07:00
Julian Knutsen
671715bb8b
test(testutil): opt-in local dolt sql-server backend for Dolt-backed tests (#6891)
* test(testutil): local dolt sql-server backend behind the Dolt test server API

Add a second backend to internal/testutil behind the unchanged container
API (EnsureDoltContainerForTestMain, RequireDoltContainer,
StartIsolatedDoltContainer[Handle], NewContainerProvider,
RestartSharedDoltContainer, DoltContainerCrashed, IsolatedDoltContainer
Stop/Start/CurrentPort/Exec): the test process spawns `dolt sql-server`
from the pinned dolt CLI instead of a dolthub/dolt-sql-server container.

- BEADS_TEST_DOLT_SERVER=local|container selects it; unset keeps plain
  `go test` on the container (no behavior change) and makes `bazel test`
  use the local backend. Other values fail instead of guessing.
- The CLI (BEADS_TEST_DOLT_BINARY, else PATH) must be the image's version.
- Provisioned like testcontainers' dolt module: root@% (DOLT_ROOT_HOST=%),
  database beads_test, user test/test. Clean env, TZ=UTC, GOMAXPROCS=4,
  own dolt global config with metrics and the version check disabled.
- Loopback port picked here (dolt rejects -P 0), never 3307, retried when
  another process wins the port; readiness requires the server's own
  "Server ready" line plus a bounded ping, so a foreign listener on a
  contested port cannot pass for it.
- State lives under the TMPDIR captured at package init, outside every
  PinSuiteTempRoot root, so suite leak sweeps never see it. The server
  stays in the test's process group (bazel's group kill reaps it) with
  Pdeathsig on Linux.
- BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 now also makes every TestMain that
  only warned about an unavailable server exit 1
  (DoltUnavailableForTestMain), plus the shared proxied harness.
- dolt_benchmark_purge_test finds .dolt_dropped_databases relative to
  Exec's working directory (the data dir in both backends).
- TestDoltServerFingerprint checks each available backend against one
  checked-in fingerprint (users, grants, databases, server variables);
  local-backend tests cover the bind-race retry, 3307, crash detection,
  Stop/Start, Exec cwd, state outside the suite root, and teardown.
- Bazel: the requires-docker variants pin BEADS_TEST_DOLT_SERVER=container
  so the docker lane stays the container A/B control; the test wrapper's
  dolt global config disables metrics and the version check.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(testutil): select the local Dolt test server only when asked for

Under Bazel an unset BEADS_TEST_DOLT_SERVER used to mean the local
backend, so every non-ci `bazel test` started servers for Dolt suites no
lane runs with one (//internal/storage/dolt:dolt_test went from a 16 s
skip to a timeout). Unset now means container everywhere: in a Bazel
action without docker that is the pre-existing warn+skip, and only a
target's env or --test_env=BEADS_TEST_DOLT_SERVER=local starts local
servers. Plain `go test` is unchanged.

The docker variants keep their container pin: a rule env beats
--test_env, so a local-backend invocation cannot flip the docker lane.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(testutil): harden the local Dolt test server's host footprint

- DOLT_DISABLE_EVENT_FLUSH=1 for every dolt the backend runs (and in the
  Bazel test wrapper): the metrics/versioncheck keys stop network calls
  but not the detached `dolt send-metrics` child each command forks on
  exit, which re-created the version probe's removed HOME (one leaked
  bdt-doltver-* per test process) and raced terminate's RemoveAll.
- Every bdt-dolt-*/bdt-doltver-* root records its owner PID, and the
  first use of the backend in a process removes this user's roots whose
  owner is dead (the SweepDeadSuiteRoots rule; a copy, since doltserver's
  tests import testutil). A panicking, timed-out or killed test binary,
  or a package whose TestMain never terminates the singleton, no longer
  leaks a 40-100 MB state dir per run.
- secure_file_priv is the state root's sfp/ directory, set through a
  per-launch --config file (dolt ignores other flags with --config): a
  local server runs as the test user on the host with a passwordless
  root@%, so LOAD_FILE / INTO OUTFILE must not reach the user's files.
  The fingerprint treats that path as the container's "".
- Fingerprint: character_set_server, collation_server,
  max_allowed_packet, transaction_isolation, lower_case_table_names,
  lower_case_file_system (compared on Linux only: APFS reports ON),
  wait_timeout, innodb_lock_wait_timeout.
- The local backend's own tests skip off Linux (no Pdeathsig, so a
  killed test binary would orphan servers on the macOS runners) unless
  BEADS_TEST_DOLT_SERVER=local asks for them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci: compare the container and local Dolt test servers in the domain+uow job

TestDoltServerFingerprint's container half never ran in CI: only the
test-domain-uow job has both the pulled image and the pinned dolt CLI,
and it never ran ./internal/testutil. Run the fingerprint there (with
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 so the container half cannot skip)
so an image bump that drifts the container side fails in the PR.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 04:06:49 -07:00
Julian Knutsen
fc4d7d3958
ci(bazel): PR-gate parity lanes (docker, pure-Go, js/wasm) + bd artifact (#6887)
* test(bazel): require exclude read-permission coverage in test:prcore

pr.yml's PR Core step sets BEADS_TEST_REQUIRE_EXCLUDE_PERMISSION=1 so
TestAddExcludePatternsRefusesReadErrors fails, rather than skips, on a root
or non-POSIX executor. test:prcore now sets it too, and a policy test keeps
the two in step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* feat(bazel): compare Bazel runs with one CI job's go test results

equivalence.py --job takes a job's `go test -json` as the complete expected
set, so a Bazel selection can be shown to replace that job: every top-level
test the job ran must run under Bazel, no other test in those packages may,
and nothing the job passed may be skipped. --bep is repeatable (a job can map
to --config=ci plus --config=docker), and go_test_variant.sh sh_tests count,
since their go_test binary writes the same test.xml. In job mode a test seen
in several targets keeps its best status: the prcore run skips what the
docker variant exists to run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): docker-lane variant for internal/tracker

pr.yml's "Test (storage domain + uow)" job runs ./internal/tracker/... with
-race and without -short or BEADS_TEST_SKIP=dolt, so tracker's TestMain
starts the shared dolt container and all 112 top-level tests run. Under
--config=prcore they skip. tracker_docker_test reruns tracker_test that way
in the docker lane, and tracker's TestMain now fails instead of skipping when
BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 and the container does not start.

The job's other packages (storage/domain, domain/fs, domain/git,
tracker/conformance) consult neither testing.Short nor the dolt skip, and
pass identically under --config=ci.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): publish the Bazel-built bd as a ci-build-artifacts artifact

pr.yml's build-artifacts job uploads ci-build-artifacts (bd-linux-gms-pure,
SHA256SUMS, build-manifest.txt), which PR Core, the domain+uow job and both
package gates download and check with `sha256sum -c`. The Bazel lane now
uploads the same name and layout from //cmd/bd:bd_for_tests, the non-race
gms_pure_go cgo bd its own tests exec (//cmd/bd:bd is race-built under
--config=ci); test:ci downloads it under --remote_download_minimal. No
consumer is repointed yet.

A rules_go binary has no vcs.* or CGO_ENABLED build settings: `bd version`
shows no commit, and scripts/verify-cgo.sh would pass it vacuously. No
consumer of this artifact reads either; the manifest records the commit.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): pure-Go and js/wasm lane for pr.yml's boundary job

pr.yml's "Check pure-Go and js/wasm boundaries (CGO_ENABLED=0)" job builds
bd and three test binaries with CGO off, runs a 16-name -short cmd/bd subset,
and runs the js/wasm hook refusal test under node with an exact count guard.
bazel.yml's new bazel-pure job does the same with Bazel binaries:

- --config=pure (--@rules_go//go/config:pure, -test.short) builds //cmd/bd:bd,
  bd_test, embeddeddolt_test and tracker_test, and runs bd_test unsharded
  with the job's -run selector (policy-tested to stay equal to pr.yml's).
- --config=js-wasm builds //internal/hooks:hooks_test for js/wasm
  (--use_target_platform_for_tests satisfies the test toolchain; nothing is
  tested by Bazel under it); the Go SDK's go_js_wasm_exec runs it under node
  with pr.yml's selector and count guard, verbatim.

rules_go compiles every declared dep, and gazelle's deps ignore the cgo
constraint of beads' embedded-Dolt files, so a pure build compiled dolt's
store/nbs and failed in github.com/dolthub/gozstd (cgo only; go build never
imports it with CGO_ENABLED=0). third_party/patches/gozstd_nocgo.patch adds
panicking !cgo stubs for the API dolt uses.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): run prcore tests with -test.parallel=4 like pr-core.sh

pr-core.sh runs go test -parallel 4. test:prcore passed no -test.parallel,
so Go defaulted to GOMAXPROCS: the executor's core count (192 on a farm
worker) instead of a runner's 4, which let dozens of t.Parallel bd
subprocesses run at once. A policy test keeps the value equal to
pr-core.sh's GO_TEST_PARALLEL default.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): -test.parallel=4 in the pure lane

pr.yml's pure-Go job passes no -parallel, so go test uses GOMAXPROCS, 4 on
ubuntu-latest; under Bazel the default would be the executor's core count.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): run the contract corpus non-race in the docker lane

pr.yml's Contract corpus job runs go test ./cmd/bd/protocol without -race,
but --config=docker races every target. protocol_docker_test now runs
:protocol_race_off, protocol_test built through a race=false transition
(tools/bazel/race.bzl), so no second go_test rule has to track gazelle's
srcs. Tagged manual so other lanes do not build it; the extra non-race work
is protocol_test's link plus ~100 test-only libraries.

The docker lane also mirrors the jobs' concurrency now: they pass no -p or
-parallel, so go test uses GOMAXPROCS, 4 on ubuntu-latest, for both; the
lane runs at most 4 test processes (so at most 4 dolt containers start at
once) with -test.parallel=4. It writes -test.v test.xml like test:ci, for
equivalence.py.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): run the docker lane in bazel.yml

New advisory job bazel-docker runs `bazel test //... --config=docker` on
ubuntu-latest after pre-pulling the dolt image like pr.yml's container jobs.
The requires-docker variants (domain/db, uow, tracker, doctor/fix,
protocol) run on the runner against its docker daemon (no-remote-exec);
their builds use remote execution when setup-bazel configured it. With
bazel-test's --config=ci this covers "Test (storage domain + uow)" and
"Contract corpus". The lane name is one env var, so a hermetic dolt-server
lane can replace it.

Policy tests now cover every bazel.yml job: an exact job list, timeouts, no
continue-on-error, pinned actions (setup-node added), one setup-bazel step
per job as the only secret reader, cache saves only in bazel-test, plus
job-specific mirrors of pr.yml (the docker job's runner, image pull and
lane; a requires-docker target in each container-backed package).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* perf(bazel): build the non-race contract corpus in bd_for_tests' configuration

go_test_race_off only set race=false, while rules_go's go_transition (as
used by //cmd/bd:bd_for_tests, race = "off") also records the overridden
value in original_race. The two non-race configurations differed, so the
docker lane (and --config=ci, which builds protocol_docker_test through
//...) compiled the whole dolt graph twice without race. Record
original_race the same way: aquery GoCompilePkg for
deps(protocol_docker_test) under race drops from ~2630 actions in two
configurations to 1359 in one.

Fix the BUILD comment: manual does not keep protocol_race_off out of other
lanes' builds; protocol_docker_test pulls it in.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): job-mode equivalence fails on any target's failure or missing test.xml

In --job mode a test seen in several targets keeps its best status, so a
failure in one variant was hidden when another target passed the test, and
a go_test_variant.sh sh_test without a test.xml was skipped silently. List
every failed test per target and every target in the job's packages whose
test.xml is missing, and fail on either.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): gate pure-lane contamination, never cache docker-lane results

- gozstd_nocgo.patch: the stubs' package init panics, so a pure binary
  that links gozstd (which CGO_ENABLED=0 go build rejects at compile time)
  fails at startup. bazel-pure starts every pure artifact (bd version, and
  embeddeddolt_test/tracker_test with -test.run=^$; bd_test runs its
  subset) so contamination fails the lane.
- test:docker --nocache_test_results: the requires-docker variants depend on
  host state no action key covers, like the container jobs' -count=1.
  build:remote-exec --noremote_upload_local_results in the committed rc, so
  local runs cannot seed the shared cache with host-dependent results.
- The artifact packaging moves to scripts/ci/package-bazel-bd.sh, which
  sources .buildflags itself; sourcing it in bazel.yml exempted the whole
  workflow from the build-tag scan.
- bazel-pure and bazel-docker use bazel-test's runs-on (Blacksmith when
  remote execution is possible); the policy test pins it for every job.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): put the pure and docker lanes behind the rbe-west gate

Apply bazel-test's rbe-west setup-bazel env (RBE_WEST_EXECUTOR, instance
oss, RBE_WEST_WORKERS) and its job if to bazel-pure and bazel-docker, so
same-repo runs of all three lanes skip together until the variable is set
and forks and rbe=off dispatches still run locally. The policy test pins
runs-on, if and the setup-bazel env for every bazel.yml job.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): run the js/wasm hook test with a minimal environment

wasm_exec.js caps argv+env size, and the Blacksmith runner's environment
exceeds it ("total length of command line and environment variables
exceeds limit").

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-28 02:03:51 -07:00
Julian Knutsen
6da2a43477
ci(bazel): advisory Bazel workflow + go test/Bazel equivalence check (#6881)
* ci(bazel): add advisory Bazel workflow and setup-bazel action

Add .github/workflows/bazel.yml, a side-by-side lane that runs
`bazel test //... --config=ci` (PR Core parity) on pull_request,
merge_group, push to main and workflow_dispatch. It is advisory: not in
ci-gate's CI_GATE_REQUIRED.

.github/actions/setup-bazel installs a sha256-pinned Bazelisk (Bazel from
.bazelversion), restores the runner cache (--disk_cache and
--repository_cache only), and writes a CI bazelrc outside the workspace
and outside the cached directory. Remote execution is enabled only when
BAZEL_REMOTE_EXECUTOR, RBE_TLS_CERT and RBE_TLS_KEY are all set (base64
PEM cert/key; optional RBE_TLS_CA, RBE_INSTANCE); none set (fork PRs, or
workflow_dispatch rbe=off) runs locally; a partial set fails. The endpoint
and its bare host are masked. The rc logic lives in write-bazelrc.sh so it
is testable offline.

The runner cache is saved only by push-to-main runs under a run-unique key
and restored by prefix, so it never freezes at its first save and PRs do
not churn the quota. The job also reports the tier (T1/T2/local) and
wall time in the step summary, runs tools/bazel/critpath.py against the
profile, and checks BUILD drift with make bazel-sync-check plus
make bazel-sync and a clean git status.

tools/bazel/critpath.py reports the critical path as the sum of the
chained "critical path component" events rather than the longest one (a
cold race build: 395s over 75 components, where the single-component
version printed 69s and a false scheduling gap), lists the longest
members and Bazel's processes: cache line, and checks a report-only
budget (warning annotation, exit 0) unless --enforce is given.

scripts/ci_workflow_test.go covers the new lane: not wired into any gate,
every action SHA-pinned to the repo's released SHAs, no monolithic
actions/cache, no unbounded apt-get, the cache topology, secrets only
reaching setup-bazel, --profile after `test`, and the rc writer's
none/partial/full/invalid-PEM/secret-dir-in-workspace behaviour.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): check go test / Bazel test equivalence in the Bazel lane

tools/bazel/equivalence.py compares the Go tests `bazel test //...
--config=ci` ran with the ones pr.yml's go test lanes run, so a tag
filter, a stray manual tag, a package without a go_test target, or a
shard that runs zero tests cannot shrink the Bazel lane while it stays
green:

- package set: every package `go list -race -tags gms_pure_go` reports
  with test files has a go_test target (bazel query);
- test-name set: every top-level TestXxx in the files go list selects
  (minus ^TestEmbedded, as PR Core skips) appears as a testcase in the
  test.xml of a go_test target this invocation tested (from the BEP);
  runtime skips count as run. Tests Bazel ran that go test would not
  are divergences too.

Expected differences go in tools/bazel/equivalence_allowlist.txt, one
justified line each (empty today); unused entries are reported.
Results go to the step summary; the full listing with --details.

.bazelrc test:ci now sets GO_TEST_WRAP_TESTV=1 (rules_go lists passing
tests in test.xml only under -test.v) and downloads test.xml despite
--remote_download_minimal.

The Bazel workflow runs the check after the critical-path report, and
nightly.yml calls the workflow (suite "bazel", and on schedule) with the
full listing.

Verified locally against a remote --config=ci run: 103 packages and
8843 tests on both sides. Tagging //internal/gitignore:gitignore_test
manual keeps `bazel test` green but fails the check, listing its two
tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(fs): run RepoContextAndRole from its own git repo

The test relied on its working directory being inside a git checkout to
make BEADS_DIR external to the CWD repo. Under Bazel the working
directory is the runfiles tree, not a git repository, so RepoContext
failed with "not a git repository" and the test skipped itself.
Create a second temporary repo and chdir into it instead; go test keeps
passing and Bazel now runs the assertions.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): fail equivalence on tests Bazel skips but go test passes

The equivalence docstring claimed runtime skips count as run because go
test skips them the same way. It does not: against PR Core's go test
-json on the same commit, 11 tests passed under go test and skipped
under Bazel while the check printed ok with an empty allowlist.

- equivalence.py --go-test-json compares per-test status with the
  Bazel test.xml: passed under go test and skipped under Bazel is a
  divergence; other status differences are listed, not failed. The
  in-job (PR) run cannot see skip divergences and says so.
- The allowlist gains a `skip` kind (`<pkg> <test> skip  # why`, the
  justification still mandatory) and lists the 10 intentional skips:
  cmd/bd TestGOMODCACHENotUnderTestHome and TestZZStdioNotLeaked, and
  the scripts policy tests that walk the source checkout. The eleventh,
  fs TestContextRepository_RepoContextAndRole, is fixed in the test.
- scripts/ci/pr-core.sh writes `go test -json` to
  BEADS_PR_CORE_GO_TEST_JSON when set (same flags otherwise).
- nightly.yml runs that in a new job, uploads the JSON, and calls
  bazel.yml with go-test-json-artifact, which downloads it and passes
  --go-test-json to the equivalence step.

Verified on a remote `bazel test //... --config=ci` run: ok with the
allowlist; a TEST_SRCDIR-only t.Skip injected into
internal/gitignore TestAppendLines fails the check (and passes the
name-only in-job check, as documented).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): freeze the runner cache per lock, mask key material, tighten policy

Runner cache: every push to main saved ~2.3 GB (repository cache, disk
cache, Bazelisk) under a run-unique key, on a repo already over its
Actions cache quota. The cache now holds only the repository cache and
Bazelisk, whose content is fixed by .bazelversion and MODULE.bazel.lock:
exact key bazel-repo-v2-<os>-<hash>, restore falls back to the previous
lock's entry, and only a push to main that missed the key saves. No
--disk_cache in either mode (remote runs have the remote cache; local
runs never used it). About 2 GB per lock change.

Credentials:
- write-bazelrc.sh masks every non-armor line of each decoded PEM
  (cert, key, CA). GitHub only masks the base64 value as stored. The CA
  used to be decoded inside the rc redirect, so its mask commands would
  have gone into the rc; it is decoded first now.
- The CI rc sets build:remote-exec --noremote_upload_local_results, so
  CI never writes locally executed (PR-code) results into the shared
  action cache. Developer rcs keep Bazel's default.
- RBE_INSTANCE stays optional; an empty one is a ::warning.
- bazel.yml's header states the accepted risk: same-repo PR code runs
  with the RBE client certificate (as in gascity); forks never get it;
  what is in place and what is pending a human decision.

Policy tests (each proved with a scratch mutation that now fails):
triggers must be exactly pull_request, merge_group, push,
workflow_dispatch and workflow_call (no pull_request_target); secrets
may appear only in the setup-bazel step's env, not in workflow or job
env, run, with or if; no continue-on-error anywhere in bazel.yml or
setup-bazel; the cache-save if is matched exactly; the critical-path
and equivalence steps must end with the bare script call and the test
step with exit "$rc", with no exit 0, || true, || :, ; true, set +e or
trap.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(ci): record the same-repo RBE decision in bazel.yml

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): bazel wrapper version check; keep go-test prose out of the build-tag scan

The wrapper prepends --bazelrc, so 'bazel --version' reached the server
as an unknown startup option; ask bazelisk directly. check-build-tags
matched 'go test' in workflow prose and step names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(ci): run the RBE lane on Blacksmith runners; mask the executor's IPs

GitHub-hosted runners are refused by the remote-execution edge; the
Blacksmith pool (as in gascity) is admitted and does not count against
GitHub's concurrent-job cap. Forks and rbe=off keep ubuntu-latest.
Bazel prints the resolved executor address in connection errors, so mask
every address the endpoint host resolves to.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* ci(bazel): target rbe-west (instance oss) behind RBE_WEST_WORKERS

The original edge does not admit CI runners. Mirror gascity: remote
execution uses secrets.RBE_WEST_EXECUTOR and instance oss when the repo
variable RBE_WEST_WORKERS is true; same-repo runs are skipped until then
instead of failing, while forks and rbe=off still run locally.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 23:05:21 -07:00
Julian Knutsen
ae1a493e01
test(bazel): fully green //..., tag taxonomy + docker lane, sharding, test sandbox ceiling (#6871)
* fix(doctor): detect test binaries with testing.Testing(), not the file name

getBdBinary refuses to return a test binary as "bd" so fix tests cannot
fork-bomb by re-running themselves. The guard matched only the `go test`
naming (<pkg>.test). Bazel names test binaries <target>_test, so under
`bazel test` every fix that shells out to bd re-ran the whole fix_test suite,
recursively (~60 levels), until the 300s timeout.

testing.Testing() is true for any binary linked as a test by `go test` or
rules_go (both set testing.testBinary=1), whatever its name. The name check
stays as a fallback. bd already links package testing, so the product binary
gains no dependency. Behavior under `go test` is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): tag taxonomy, docker lane, and green //scripts targets (slice B5)

`bazel test //... --config=ci` is now fully green, locally and with
--config=remote-exec.

- scripts_test declares what it reads and runs: this package's own tree
  (:scripts_files), .github/** (//:workflow_files, widened from the
  workflows), and .buildflags/.test-skip for scripts/test.sh. The complexity
  diff test builds a one-commit git fixture instead of git-archiving the
  real checkout's HEAD. Under Bazel it skips the whole-repo testing.Short()
  scan (it would pass vacuously over the runfiles) and the two release
  formula tests (.beads is in .bazelignore). Tagged host-tools +
  no-remote-exec: it runs the host's git/python3/coreutils and some subtests
  skip without git.
- prlintmake_test resolves fmt-check.sh through bazeltest.CallerDir and
  declares it; it needs only bash (gofmt is shimmed), so it stays untagged
  and runs remotely.
- //cmd/bd/doctor/fix:fix_docker_test reruns the fix_test binary (no second
  compile, tools/bazel/go_test_variant.sh) with BEADS_FIX_REQUIRE_DOLT=1, like
  pr.yml's container-backed doctor/fix job. Tagged requires-docker +
  no-remote-exec; `--config=docker` selects it (race, no -short, no
  BEADS_TEST_SKIP=dolt). fix_test itself stays untagged: under prcore it
  skips the Dolt-backed tests exactly as pr-core's `go test` does.
- scripts/bazel_policy_test.go: every BUILD `tags` value must be in the
  taxonomy, be named in the comment above its rule, and host-bound tags must
  come with no-remote-exec; test:prcore must exclude requires-docker,
  embedded and manual.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bd): reset git's cwd cache in TestContextRoutesNameOneWorkspaceTheSameWay

The test chdirs into a fresh git repo but reset only beads' caches. git
caches the cwd's repository context process-wide, so when an earlier test in
the same process had resolved it from a non-repo directory (for example
TestCollectMetadataEntriesNoBeadsDir), GetMainRepoRoot kept answering "not a
git repository". Test order hid it under `go test ./cmd/bd`; Bazel sharding
reorders tests and exposed it. Reproduces with plain go test:

  go test -run '^(TestCollectMetadataEntriesNoBeadsDir|TestContextRoutesNameOneWorkspaceTheSameWay)$' ./cmd/bd

The cache is reset on entry only. Resetting it again in cleanup changes what
later tests inherit, and TestCreateRemoteRepoSkipsLocalDatabaseGuard (which
never resets it) then fails under the unsharded go test order.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): shard bd_test and embeddeddolt_test; keep test re-execs shard-free (slice B6)

- //cmd/bd:bd_test shard_count = 16, //internal/storage/embeddeddolt:
  embeddeddolt_test shard_count = 8. Remote -race under --config=ci: bd_test
  max shard 61-82s (unsharded 252-264s), embeddeddolt max shard 84-122s
  (unsharded 207-377s). The embeddeddolt max is a single test
  (TestWithPeerAuth, ~93s), so more shards would not lower it. Every shard
  runs tests (bd 161-172 top-level tests each, embeddeddolt 15-20).
  protocol (4s), legacysqlite (4s) and dbproxy/server (22s) stay unsharded.
- Tests that re-exec their own binary now pass bazeltest.ShardFreeEnv
  (a no-op under go test), so a helper child does not inherit
  TEST_SHARD_INDEX/TEST_TOTAL_SHARDS/TEST_SHARD_STATUS_FILE and filter away
  the one test it was asked to run: dolt suite_leak_linux, dbproxy
  force_stop_linux, workspacegate (3 helpers), metrics spawn_reap, bd
  worktree_remove, conformance role_bundle, linear synclock (windows).
  scripts/test_script_test.go (child env built from scratch) and
  repro-dolt-prod-timeouts (copies the binary, never runs it) need nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): keep sharded bd_test off ~/.beads and keep its stdio leak guard

Two things sharding //cmd/bd:bd_test exposed:

- config.Initialize walks up from the test's cwd for .beads/config.yaml and,
  under BEADS_TEST_IGNORE_REPO_CONFIG, stops at the module root (go.mod).
  The runfiles tree had no go.mod, so the walk left it; with the output base
  under $HOME it loaded the developer's ~/.beads/config.yaml (here
  dolt.shared-server: true) and two embedded-mode autocommit tests failed
  locally, though not on remote workers. bd_test now declares //:go.mod, so
  the walk stops at the runfiles root as it stops at the checkout under go
  test. Unsharded runs hid this: an earlier test re-initialized config first.
- TestZZStdioNotLeaked skipped in every shard, because the baseline test is
  always in shard 1 and the guard in another. Without a baseline it now
  checks the descriptors instead (a leaked capture leaves a pipe where fd 1
  or 2 was). Under go test the baseline is always captured, so nothing
  changes there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* chore(bazel): sync BUILD files with test files added on main

Gazelle picks up cmd/bd and internal/notion tests that landed on main after
the last sync (make bazel-sync).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(discovery): add BEADS_CEILING_DIRECTORIES; bound bazel tests' walks

bd finds its workspace by walking up from the working directory for .beads
and .beads/config.yaml. Under `bazel test` the working directory is in the
runfiles tree under the output base, usually below the developer's HOME, so
the walks left the sandbox: tests read the developer's ~/.beads/config.yaml
(results depended on it) and wrote into ~/.beads (interactions.jsonl from the
audit log, .local_version from version tracking).

BEADS_CEILING_DIRECTORIES takes git's GIT_CEILING_DIRECTORIES form (a PATH-
style list of absolute directories): a search starting inside a ceiling never
examines the ceiling or anything above it; the start itself is always
examined. Unset, nothing changes. Honored by every upward .beads/config
search: beads.AncestorDirWalk (all FindBeadsDir walks), config.Initialize
(the go.mod and config.yaml walks, and the worktree-fallback git probe, whose
routing scrub drops GIT_CEILING_DIRECTORIES), findProjectBeadsDir, the legacy
upgrade guard, the --db beads-dir walk, store reopen and findBeadsRepoRoot.
The migration-freeze marker walk is left alone on purpose: it is a write
safety gate, and BD_MIGRATION_FREEZE_FILE is already its explicit override.

tools/bazel/test_env.sh sets BEADS_CEILING_DIRECTORIES and
GIT_CEILING_DIRECTORIES to the runfiles root, TEST_TMPDIR and its own temp
root. It does not fail on an ancestor .beads: a live ~/.beads above the
output base is normal on a developer machine. bd_test no longer needs
//:go.mod as a walk stop.

Canary check: with an invalid-YAML .beads above a scratch --output_base,
compact, issueops, validation and bd_test pass under --config=ci and nothing
is written there; the previous wrapper fails on it and writes
interactions.jsonl into it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bd): check for leaked stdio after m.Run in every process

TestZZStdioNotLeaked only sees the tests that ran before it in the same
process. Under Bazel's 16-way sharding that is ~1/16 of bd_test: the baseline
test is in shard 1, the guard in another shard, and leaks in the other shards
were never checked.

TestMain now compares os.Stdout/os.Stderr after m.Run with the streams from
before it (runTestsAndSweep, so every shard and every go test run) and fails
the process on a leak. The one allowed change is the framework's own
os.Stderr = os.Stdout under -json. TestZZStdioNotLeaked stays for its go test
report and skips when it has no baseline; the descriptor fallback added for
sharding is gone.

Verified: a test that leaks os.Stdout fails `go test -run` for it alone, with
and without -json; a clean -json run passes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): keep host-tools results out of the remote cache; tighten tag policy

- //scripts:scripts_test (host-tools, no-remote-exec) ran locally but its
  result was still uploaded to the remote cache and served to other clients,
  though the action key does not cover the host's git/python3/bash. It is now
  also tagged no-remote-cache (neither read nor uploaded). Checked: after a
  --config=remote-exec run and `bazel clean`, a rerun without the disk cache
  executes the test again instead of taking a remote cache hit.
- Under Bazel a missing git or bash now fails those tests instead of
  skipping (the host-tools tag promises them); under go test they still skip.
- Tag policy: host-tools requires no-remote-exec and no-remote-cache;
  `tags = [...] + X` is rejected as non-literal; every --test_tag_filters set
  by test:prcore or a config that expands it (test:ci, transitively) must
  exclude requires-docker/embedded/manual, not only the first prcore line.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): run go_test variants from their package directory

rules_go gives a go_test GO_TEST_RUN_FROM_BAZEL=1 (and its `env`) through
RunEnvironmentInfo; an sh_test that reruns the binary gets neither, so the
binary skipped its chdir into the package directory and ran from the
runfiles root. go_test_variant.sh now exports GO_TEST_RUN_FROM_BAZEL=1, and
its header says the variant target must repeat the go_test's `env`.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): docker-lane variants for domain/db, uow and protocol

--config=docker only ran doctor/fix. pr.yml's container jobs also run
internal/storage/domain/... + uow/... (race, no -short, Dolt image pulled)
and cmd/bd/protocol (BEADS_PROTOCOL_REQUIRE_DOLT=1). Under --config=ci those
container suites skip (BEADS_TEST_SKIP=dolt), so without variants their
coverage would vanish if Bazel replaced those jobs.

- testutil: BEADS_TEST_REQUIRE_DOLT_CONTAINER=1 makes RequireDoltContainer
  and StartIsolatedDoltContainer(Handle) fail instead of skip when the Dolt
  container is unavailable (the generic form of BEADS_FIX_REQUIRE_DOLT).
- db_docker_test, uow_docker_test (4 shards) and protocol_docker_test
  (8 shards, BEADS_PROTOCOL_REQUIRE_DOLT=1) rerun the go_test binaries via
  go_test_variant.sh, repeating their `env`; tagged requires-docker +
  no-remote-exec. The other domain/tracker packages have no container tests
  and already run under --config=ci.

`bazel test //... --config=docker --test_arg=-test.v`: 4/4 PASS; db 908
PASS / 0 SKIP, uow 985 PASS / 32 SKIP (conformance capabilities the backend
does not implement, as under go test), protocol 151 PASS / 2 SKIP (tracked
known gaps). With --test_env=BEADS_TEST_SKIP=dolt, db_docker_test fails.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test: shard-free env for the embeddeddolt concurrency helper; 2m bd init timeout

- concurrency_test re-execs its test binary with -test.run=^TestHelperProcess$
  inside the now-sharded embeddeddolt_test; pass bazeltest.ShardFreeEnv so a
  child cannot inherit TEST_SHARD_* and filter its one test away (it is
  gated by BEADS_TEST_EMBEDDED_DOLT=1, so dark today).
- initBeadsWorkspace / runBDStdout (TestClose_UpdatesLastTouched and the
  gemini prime hook tests) allowed 30s per bd subprocess. A -race bd on a
  loaded host exceeded that for a single `bd init` (killed at 30.18s in 1 of
  3 sharded remote runs; the whole test otherwise passes in ~21s), so allow
  2 minutes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bd): give TestCreateRemoteRepoSkipsLocalDatabaseGuard its own git state

The test chdirs into a fresh non-repo temp dir but used whatever git/beads
cwd caches earlier tests left. When an earlier test had reset git's cache and
a later one refilled it from the package directory, workspace discovery in
the test returned the checkout's .beads (from a git worktree: the MAIN
checkout's live .beads via the worktree fallback) and `bd create` tried to
open it, so it failed with "could not verify workspace identity" instead of
the expected downstream error. It passed only on stale state (a cache
pointing at a deleted temp repo).

It now resets the git and beads caches after its chdir and again in cleanup,
so it neither depends on nor leaks cwd state. With that fixed,
TestContextRoutesNameOneWorkspaceTheSameWay also resets git's cache in
cleanup. Reproduced with the context-test cleanup reset in place, running
every cmd/bd test declared up to this one (the failing go test order); now
passes there, alone, with the two context tests, and under -shuffle seeds
1-5 (other pre-existing order dependencies show up under shuffle; this test
is not among them).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): re-sync BUILD files with main

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): pin BD_MIGRATION_FREEZE_FILE in test_env

The freeze-marker ancestor walk is intentionally not ceiling-bounded; an
explicit BD_MIGRATION_FREEZE_FILE replaces the walk, so a MIGRATION-FREEZE
above the output base can no longer change test results.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(scripts): give the complexity diff fixture a Go package

complexity.sh expands "${analyzer_paths[@]}" under set -u; with an empty
fixture tree that is an unbound-variable error on bash 3.2 (macOS runners).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 20:19:38 -07:00
ecuthiell
cefcabb1e3
fix(gitenv): retain explicit null config suppression (#6461)
* fix(exec): match Windows environment key identity (#5618)

Centralize os/exec-compatible environment-key comparison and use it for credential, metrics, Git-hook, trace, and repro subprocess filters. Preserve exact Unix semantics and Unicode near-collisions.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* fix(worktree): scrub inherited Git routing state

Establish CWD as the worktree repository boundary before discovery can consume inherited Git routing. Fence the startup config probe, clear routing in-process before root pre-run discovery, and retain command-owned subprocess scrubbing as defense in depth without changing PID or signal semantics.

Fixes #5531

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* refactor(worktree): explain owned filtering and remove an unused shim

Document why filtering the fresh routing slice in place is safe and call
the shared routing-key classifier directly from tests. Retain the two
forwarders used by production worktree subprocess/removal paths.

Review: https://github.com/gastownhall/beads/pull/5623#pullrequestreview-5098421671
Bead: saa-cgh.23
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): isolate identity and tracked-file Git probes from routing

Reuse the worktree routing owner for GetIdentity and isGitTracked so
explicit cwd/path selection is not displaced by inherited repository,
index or injected config state. Preserve identity precedence and the
tracked-secret refusal contract, with real target/decoy regressions.

Follow-up: https://github.com/gastownhall/beads/issues/6222
Dependency: https://github.com/gastownhall/beads/pull/5623
Reported-by: bee-ghosttrack
Bead: saa-cgh.93
Agent-Signature: unknown-model/unknown-reasoning

* test(execenv): exercise every environment operation under both host rules

Thread the host choice through narrow private helpers behind the existing
exported functions. Keep one normalization owner and retain native wrapper
tests; the additional table covers both host branches for equality, prefix
matching, last-wins lookup, filtering and input preservation.

Review: https://github.com/gastownhall/beads/pull/5672#pullrequestreview-5096948965
Bead: saa-cgh.78
Agent-Signature: unknown-model/unknown-reasoning

* docs(worktree): explain startup Git environment scope (saa-cgh.23)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(execenv): exercise exported host policy wiring (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): share subprocess key identity for Git routing (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): isolate role commands from Git routing (saa-cgh.99)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6357.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(env): exercise shared key helpers on native Windows (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitenv): share key parsing and normalize routing membership once (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(config): explain role command routing policy (saa-cgh.99)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): isolate role readers from inherited Git routing (saa-cgh.109.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(doctor): isolate role lookups from inherited Git routing (saa-cgh.109.2)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(git): isolate domain role configuration from inherited routing (saa-cgh.109.5)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(doctor): isolate explicit-path worktree fallback from Git routing (saa-cgh.109.6)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): probe the selected repository before configuring roles (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(beads): cover common-directory role routing (saa-cgh.109.1)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(git): explain system config routing flags (saa-cgh.109.6)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(init): explain role probe discovery ceiling behavior (saa-cgh.109.8)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(beads): scope stable worktree probes to selected path (saa-cgh.109.13)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): bind proxied tail Git operations to selected directory (saa-cgh.109.14)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* Clarify selected discovery probes and cover separate routing vectors (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Keep init role operations on the captured selected Git context (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Observe inline Git configuration directly in linked-worktree fixture (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Align selected-tail fixtures with captured role authority (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(beads): select explicit directory discovery context (GH#6384) (saa-cgh.120.6)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitenv): retain explicit Git config suppression (saa-cgh.120.7)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(config): pin identity under null config suppression (saa-cgh.120.7)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitenv): keep role authority off inherited config suppression

Maintainer review fixes for PR #6461 (adopt-pr iterations 1-2). Addresses the
three major findings raised against the contributor branch, plus the major,
three minors and nit that iteration 2 raised against the first fixup; each fix
is pinned by a test that was mutation-proved against the pre-fix source.

F1 (major, security) — the leaf exempts GIT_CONFIG_GLOBAL=/dev/null,
GIT_CONFIG_SYSTEM=/dev/null and GIT_CONFIG_NOSYSTEM from ScrubRouting. Null
suppression cannot redirect a read, but it can blind one, and DetectUserRole
answers a missed read with detectFromURL, whose no-remote and SSH arms both
return Maintainer. Reproduced on this branch: a global beads.role=contributor
with GIT_CONFIG_GLOBAL=/dev/null resolved to maintainer, where the leaf's
parent fb7a93ad4 scrubbed the entry and read contributor.

Taken the synthesis's alternative arm (a): keep the exemption where the value
has no authority, drop it where it does. New ScrubRoutingAndSuppression
applies at every beads.role reader — internal/routing, doctor/role.go,
config_show.go, RepoContext.Role, bd config get/set/unset/set-many, and the
domain adapter's key-specific arms (see A1: iteration 1 claimed that last site
and did not actually reach it). Arm (b), making roleFromGitConfig's miss
non-permissive, was declined: "no beads.role and no remote implies maintainer"
is documented base behavior for local projects, so closing it there would
reclassify every such user rather than the blinded slice this PR introduced.

F2 (major, blast radius) — the stack hardened every role reader and left four
writer/reader sites fully inherited, a divergence that did not exist at base:
an inherited GIT_DIR sends setBeadsRole's write to another repository while
the scrubbed readers look at the one the user is standing in. All four now
share the same boundary (init.go's getBeadsRole/setBeadsRole,
init_contributor.go, hooks.go's uninstall --get/--unset pair).

The required fix also asked for cmd.Dir = repoRoot on the init.go pair. Still
not taken, but not on the grounds iteration 1 recorded (see A2). What holds is
the measurement against the vector the fix targets: with GIT_DIR, GIT_WORK_TREE
and GIT_COMMON_DIR gone, no production path chdirs away from the invocation
directory — `grep -rn 'os\.Chdir' --include='*.go'` over production cmd/bd
returns nothing and `bd init` takes no path argument — so threading a repoRoot
through both signatures and their eight call sites buys no behavior change
against a redirect.

F3 (major, security) — this PR converted internal/config's isGitTracked probe
from inherited to scrub-only. The guard is fail-open by construction, so in a
legitimately routed checkout (bare repo.git, GIT_DIR/GIT_WORK_TREE exported,
no in-tree .git) the probe stopped answering and `bd config set
linear.api_key` would have written the credential into a tracked file.
Restored the two-probe shape sibling #6464 applied to the structural twin:
scrubbed probe first, inherited second, either "tracked" refuses.

F5 (minor) — disclose that scrubbing GIT_CEILING_DIRECTORIES widens upward
discovery rather than bounding it, in the worktree comment and the docs
paragraph that asserted only the narrowing effect. F2's fix extends that
trade-off to two more sites, so the disclosure is now load-bearing.

F7 (minor) — renamed isConfigSuppression to isConfigSuppressionControl and
documented why the NOSYSTEM arm is deliberately value-blind. Took the
rename/document arm rather than restricting the arm to git-true values, which
would have contradicted the PR's own pinned table.

F10 (nit) — pinned both suppression tables in the windows-latest required
list; verified each name matches the gate's grep exactly once.

--- Iteration 2 ---

The first fixup's F1 census named a site it did not reach, and its cmd.Dir
rationale named a mechanism that does not hold. Both are corrected here.

A1 (major, security) — the domain adapter's key-specific arm was guarded by
`key == "beads.role" && r.env == nil`, which is dead on the only production
role path: runInitProxiedServerTail rebinds the use case to
NewInitGitRepository whenever t.workDir != "" (its sole construction site
passes cwd), and that constructor captures ScrubRouting(os.Environ()) —
non-nil, suppression retained. The nil-env constructor has no
BeadsRole/SetBeadsRole caller, so the arm could only fire from tests, while
`bd init` under an inherited GIT_CONFIG_GLOBAL=/dev/null still missed a global
role, took hasRole=false, and persisted beads.role=maintainer into
repository-local config, where it outranks the global value for every later
read in a clean environment. Iteration 1 therefore left F1's escalation not
just alive but durable, on the one path the fix was supposed to close.

Fixed by keying the strict scrub on the config key alone and applying it to
whichever environment the repository already carries (roleAuthorityEnv). That
preserves capture semantics — NewInitGitRepository keeps its captured HOME,
the property git_test.go's captured_home case pins — and removes only the
suppression entries. Codex's alternative of rebuilding the constructor's whole
env was declined: it moves every key for no gain on this finding.

A2 (minor, contract fidelity) — iteration 1 justified declining cmd.Dir with
"repository selection is left to the working directory — the one input the
scrub keeps". That is false, and false in the file a future reader consults
before deciding whether to bound the pair: GIT_CEILING_DIRECTORIES is a routing
key too, so the scrub removes a bound rather than installing one. Measured from
a non-repository directory nested under a repository: `git config beads.role
<value>` fails "not in a git directory" while a ceiling below that repository is
inherited, and writes that repository's local config once the ceiling is
scrubbed. The decline itself stands, since the measurement behind it was made
against the GIT_DIR vector; getBeadsRole now records selection as the working
directory *or a containing ancestor*, which is also what makes
clearWorktreeGitRoutingEnv's existing cross-reference to "init's role probe"
true.

A3 (minor, consistency) — `bd config unset beads.role` and `bd config set-many
beads.role=` were the two spellings of that mutation still on ScrubRouting, in
the same file as the two that moved. Both measured inert: `git config <key>
<value>` and `--unset <key>` target the repository-local file, which the
suppression variables cannot select. Moved for parity rather than annotated,
because a divergence inside one file is how the next one starts.

Test evidence (minor) — the writer pair's two subtests both pass on the
redirect alone, so downgrading getBeadsRole back to ScrubRouting left them
green even though suppression is the load-bearing half at those sites
(init.go treats a getBeadsRole miss as permission to write a default role).
Added a global_null blinding subtest with the same unblinded fixture guard.

A4 (nit) — doctor/role.go's isGitRepo was the last probe in that file on the
suppression-retaining scrub, and it gates the "beads.role not configured"
warning. rev-parse is config-sensitive through safe.directory, which lives in
global config, so a retained GIT_CONFIG_GLOBAL=/dev/null can downgrade that
warning to "N/A (not a git repository)". Moved onto the same boundary as its
two siblings. As the finding records, the safe.directory precondition was not
reproduced end to end; the change is uniformity within the file.

Tests. Every pin reds only on its own defect:
- routing: reverting to ScrubRouting reds only the blinded-read subtest; the
  unblinded fixture guard and the PR's inject-vector table stay green.
- gitenv: keeping suppression reds 10 of 16 new subtests, none of the PR's.
- cmd/bd: restoring the inherited env reds both redirect subtests and names
  both halves ("the write did not land where bd is standing" / "an inherited
  GIT_DIR captured the write"), while the PR's own role roundtrip stays green
  — it followed the same redirect on both sides, so it never saw this.
- config: the two arms are proved separately. Scrub-only reds only the
  legitimate-routing subtest; inherited-only reds only the poisoned-routing
  subtest, so the new fallback cannot be read as a way around the scrub.
- domain/git (A1): restoring the r.env == nil provenance guard reds
  global_null only; unblinded stays green, and no other test in the package
  moves — which is the same measurement that confirms the arm had no coverage
  before this iteration.

Deferred to follow-up, recorded for the approval summary: F4 (delete
isRoleGitRepo and resolve the dead else-if), F6 (user.name degrading to
hostname, which needs the PR's own subtest re-pointed), F8 (execenv fold
divergence), F9 and F11 (GetIdentity hostname degradation under inherited
suppression). F9's mechanism is confirmed — identity supplied only via
GIT_CONFIG_COUNT is lost when GIT_CONFIG_* is stripped, git reports "Please
tell me who you are", while GIT_AUTHOR_*/GIT_COMMITTER_* survive — but its
"leave artifact commits on the inherited environment" arm would re-open the
GIT_DIR redirect this PR's tail swap closed, and the non-regressing arm
(re-injecting inline identity pre-scrub) is a design change with no observed
victim in this repo.

Validation (iteration 2): internal/{gitenv,routing,storage/domain/git} full
packages green; cmd/bd/doctor full package run; targeted cmd/bd run over the
role, config and init blast radius green at 54 tests; go build ./... clean; go
vet plus CGO_ENABLED=0 and GOOS=windows CGO_ENABLED=0 vet clean on every
changed package. Remaining local reds are base-parity, each matching the
recorded cause: cmd/bd/doctor's seven (the launcher's global
beads.role=maintainer short-circuits CheckBeadsRole before isGitRepo is
reached, plus Dolt server availability) and
TestInitContributorSetsBeadsRoleContributor ("--contributor requires
interactive prompts", this session's stdin is not a TTY).

--- Iteration 3 ---

Iteration 3 reviewed 0220eed32 and approved it: claude filed no findings,
codex's six fix validations all came back correct, synthesis recorded
Decision: approve, and the scorecard scored 881/1000 with Required Changes:
None. The residual was two minors and a nit, none of them merge gates. All
three are taken here because they are comment-and-constant scope, so nothing
in the approved behavior moves.

B1 (minor, blast radius; codex filed it as major, demoted at synthesis) — the
isGitRepo() gate that decides whether the role pair runs is still fully
inherited while the pair it guards is now strict, so from a non-repository
directory with an inherited GIT_DIR the gate opens, the scrubbed read misses,
and the safety-net write fails "not in a git directory". Recorded at the
GH#2950 safety net rather than restructured, for the three reasons the
demotion rests on. The achievable outcome is base parity: sync_git.go is
byte-identical at base and the pair was inherited there too, so a GIT_DIR
holder already reached Maintainer before this PR — more directly, by pointing
at a repository whose beads.role is maintainer. The failure is not silent:
init prints "Warning: failed to set beads.role" unless --quiet, and every
later detection prints "beads.role not configured (GH#2950)" with two Fix
lines. And the prescribed roleRepoAvailable() gate provably does not close it:
all five gate sites are bare `if isGitRepo()` with no else, so a strict gate
answers false in exactly the described band, nothing is written, the role
stays unset, and detection still falls to detectFromURL. The optional
hardening is therefore declined rather than deferred — it would delete a
warning and change no role — and the comment says so, so the next reader does
not mistake a gate change for closing the fail-open path.

B2 (minor, contract fidelity) — the getBeadsRole rationale iteration 2 wrote
to close A2 introduced a new overstatement in its closing sentence: "bd init
takes no path argument — the residual is upward discovery from an unintended
cwd, not a redirect". `bd -C <dir>` is a redirect and takes no path argument.
Verified in tree rather than from the finding: applyChangeDirSelection
(main.go) resolves the target's .beads dir and sets BEADS_DIR with no chdir,
it runs from the root PersistentPreRunE ahead of every init-related early
return in that hook, and init honors BEADS_DIR for workspace selection — so
`bd -C other init` acts on other/.beads while the pair reads and writes
beads.role in the invocation repository. init.go's own "PersistentPreRun
doesn't run for init command" note is about the later skipsStoreInit return,
not about -C, which is what made this vector easy to miss twice. Reachability
is bounded: -C requires an existing beads project at the target, so the
pairing arises on re-init rather than first init. Comment narrowed to name the
residual; threading init's resolved project root through the pair is the
stronger arm and stays out of scope as a behavior change.

B3 (nit, architectural consistency) — the adapter selected the role-authority
boundary on a bare "beads.role" literal while the use case passed the
unexported beadsRoleConfigKey, two spellings of one contract the compiler
could not couple. Exported it as domain.BeadsRoleConfigKey and compared
against it at both adapter arms; no new import edge, since package git already
imports domain. Mutation-proved rather than asserted: replacing the
comparison with the case-variant "Beads.Role" the finding names reds
TestInitGitRepositoryRoleIgnoresInheritedConfigSuppression/global_null alone
while unblinded stays green, so the drift the nit describes is caught by an
existing pin. The comparison is still exact, not case-folded: git config names
are case-insensitive, so a caller hand-writing a variant spelling would bypass
roleAuthorityEnv, but folding widens which keys take the strict environment
and no production caller passes anything but the const — a behavior change the
nit did not ask for.

Validation (iteration 3): go build ./... clean; go vet plus CGO_ENABLED=0 and
GOOS=windows CGO_ENABLED=0 vet clean on cmd/bd, cmd/bd/doctor,
internal/storage/domain, internal/storage/domain/git and internal/gitenv;
internal/storage/domain/... full packages green (domain, db, fs, git); targeted
cmd/bd role run green at 19 subtests with no skips
(TestBeadsRoleCommandsIgnoreInheritedGitRouting and
TestBeadsRoleWriterIgnoresInheritedGitRouting, including the suppression
subtest added in iteration 2); gofmt and git diff --check clean. Full cmd/bd is
still not run locally: it times out at base as well. The iteration-1 deferrals
are unchanged and still owed follow-up bead ids at finalize (F4, F6/F11, F8,
F9).

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-27 15:59:08 -07:00
Julian Knutsen
469462d56a
test(bazel): run every Bazel test against a hermetic, pinned dolt CLI (#6853)
* test(bazel): run every test against a hermetic, pinned dolt CLI (slice B4)

Tests that shell out to dolt ran whatever /usr/local/bin/dolt the executor
had, a version outside the action key, and skipped (a vacuous, cacheable
PASS) on an executor without one.

- tools/bazel/dolt.bzl: dolt_release repository rule fetching the upstream
  release pinned to scripts/ci/install-dolt.sh (2.2.0), sha256 for
  linux/darwin amd64/arm64; MODULE.bazel declares one repo per platform and
  //tools/bazel:dolt selects the one for the execution platform.
- //tools/bazel:test_env (the --run_under wrapper) carries the pinned dolt
  as data. Bazel merges the run_under runfiles into every test's runfiles, so
  every test action declares dolt as an input; test_env.sh puts it first on
  PATH, exports BEADS_TEST_DOLT_BINARY, and fails the test if it is missing.
  DOLT_ROOT_PATH identity seeding stays in test_env.sh.
- testutil.requireDoltBinaryPresent fails instead of skipping under Bazel.
- TestPinnedDoltCLIMatchesContainerImage also checks tools/bazel/dolt.bzl.
  scripts_test declares the pin files and resolves the repo root through
  bazeltest, so the three dolt pin tests now pass under bazel test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): declare the Go source dolt_test's scope guards scan

TestEveryRawTxJournalScopeIsScopedOrExempt, TestEveryRawTxVersionScopeIsScopedOrExempt,
TestTxMintingWrappersScopeVersionedHistory and TestHelperSubprocessSentinelsAreComplete
parse internal/storage/dolt and internal/storage/issueops at test time; under
bazel test that source was not in the runfiles, so all four failed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(bazel): tie hermetic dolt download to its version; skip on unpinned platforms

- Key DOLT_SHA256 by version and pass canonical_id=url, so bumping
  DOLT_VERSION without new digests fails instead of silently reusing the
  previous release from the sha256-keyed repository cache.
- //tools/bazel:dolt_version_test runs the hermetic dolt and checks it
  reports DOLT_VERSION.
- Unpinned platforms (e.g. windows) resolve to an incompatible target, so
  bazel build //... skips the wrapper there instead of failing analysis.
- test_env.sh also unsets BEADS_DOLT_BIN so it cannot bypass the pin.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 14:29:49 -07:00
Julian Knutsen
f66375459f
test(bazel): runfiles helpers + declared inputs for scan-guard tests (#6828)
* test(bazel): add internal/testutil/bazeltest runfiles helpers

Repository-path resolution for tests that works identically under plain
go test (package cwd, full checkout), bazel test locally, and remote
execution (declared runfiles only):

- IsBazel, RepoRoot (BEADS_TEST_REPO_ROOT, then the runfiles workspace
  root, then a go.mod walk), OverrideRoot (drop-in condition for existing
  helpers; empty under plain go test), CallerDir
- Runfile for $(rlocationpath) values, GOROOT for type-checking tests
- ShardFreeEnv for helpers that re-exec a test binary

Every helper reduces to the pre-Bazel behavior under go test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): declare source/data reads for 14 scan-guard targets

Source-scanning and repo-file tests read files their Bazel targets never
declared, so they failed under `bazel test` (and could not run on remote
workers at all). Declare narrow inputs as `data` and resolve paths through
bazeltest where the test located the tree via runtime.Caller:

- tools/bazel/go_srcs.py (run by `make bazel-sync` after gazelle) keeps a
  managed `go_srcs` filegroup in the packages whose Go source tests scan,
  plus `//internal/storage:tree_go_srcs` for the storage-tree walk. Bazel
  globs stop at package boundaries, so the aggregate needs one filegroup
  per package; the script keeps it in sync and gazelle-stable.
- Hand-written narrow inputs: //internal/storage/schema:migrations,
  //:docsync_files, //plugins/beads:plugin_files, and exports of
  .gitattributes, .claude-plugin/marketplace.json, cmd/bd list.go and
  ready.go, testutil/testdoltcommon.go, scripts README.md and the release
  catalog, each visible only to its consumer.
- runtime.Caller-based roots in backend, backend/conformance,
  internal/storage, internal/formula and test/docsync now go through
  bazeltest.CallerDir / OverrideRoot; relative-path tests need data only.
- integrations/ leaves .bazelignore (it is still gazelle-excluded) so the
  docsync link check can declare integrations/beads-mcp/PYPI.md.

Under --config=prcore every target reports the same PASS/SKIP/FAIL test
set as `go test -race -short` for its package, locally and remotely.
Plain `go test` behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): guard generated go_srcs and harden bazeltest root override

- tools/bazel/go_srcs.py: add --check (print diff, exit 1 on stale blocks);
  new `make bazel-sync-check` target runs it.
- scripts/bazel_policy_test.go: under go test, assert every tree_go_srcs
  (//internal/storage) lists exactly the BUILD.bazel packages below its
  root, run go_srcs.py --check, and forbid BUILD files under docs/ and
  engdocs/ (they would cut subtrees out of //:docsync_files).
- bazeltest: honor BEADS_TEST_REPO_ROOT only when it holds go.mod
  (RepoRoot fails loudly otherwise); drop the unused GOROOT() helper,
  whose compiled-in branch could never fire under rules_go.
- scripts/ci/lib/test-env.sh: unset BEADS_TEST_REPO_ROOT.
- Document the hand-listed out-of-tree link targets in //:docsync_files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* build(bazel): re-sync BUILD files with main

Regenerated with make bazel-sync after commits that landed while the
scaffold PR was in CI (new internal/execenv, gitenv, gitignore packages
and new sources/deps).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): declare init_safety_help.go for docsync

TestInitSafetyCLIHelpCoversReCloneGotchas (#6431) reads
cmd/bd/init_safety_help.go; export it to //test/docsync only.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 08:24:08 -07:00
Jim Wordelman
54dd4da670
docs(recovery): init-safety re-clone playbook covers damaged-store and fresh-clone gotchas (#6431)
* test(docs): red — Docs: init-safety re-clone playbook must say damaged stores go OUTSIDE data_dir and a fresh clone needs bd migrate schema (refs be-wv0d0)

* feat: green — Docs: init-safety re-clone playbook must say damaged stores go OUTSIDE data_dir and a fresh clone needs bd migrate schema (refs be-wv0d0)

- docs/recovery/init-safety.md: new re-clone-gotchas section covering both
  live gotchas from ga-vrq5pu (damaged/set-aside stores must move OUTSIDE
  data_dir; a fresh clone needs `bd migrate schema` for dolt-ignored
  clone-local tables), with cross-reference pointers from the two existing
  bd bootstrap mentions and a pointer (not a duplication) to bd doctor
  --fix's automated corrupt-manifest convention. Freshness markers bumped.
- cmd/bd/init_safety_help.go: RECOVERY section of the init-safety Long help
  gets a brief RE-CLONE GOTCHAS addendum with both symptom signatures and
  the fix command.
- test/docsync/init_safety_recovery_test.go: retargeted
  TestInitSafetyCLIReferenceCoversReCloneGotchas (written during RED) to
  TestInitSafetyCLIHelpCoversReCloneGotchas, asserting on
  cmd/bd/init_safety_help.go's Long field instead of the generated
  docs/cli-reference/init-safety.md. That generated page is pinned to a
  released bd (docs/cli-docs.pin = v1.2.2, built in a detached worktree per
  scripts/resolve-docs-bd.sh) and does not pick up a Long-field edit at
  HEAD until a maintainer bumps the pin at the next release — confirmed
  empirically (`git show v1.2.2:cmd/bd/init_safety_help.go` still points at
  the deprecated docs/RECOVERY.md path, and a full
  ./scripts/generate-cli-docs.sh run here produced zero diff to the
  committed docs/cli-reference/). CI's own drift gate
  (scripts/check-cli-docs-drift.sh) is blame-scoped for exactly this
  reason. The original RED test was asserting on an artifact this PR
  cannot legitimately change without fighting that pin.

* fix(docs): address review feedback on init-safety re-clone playbook

Three fixes per bee-ghosttrack's REQUEST-CHANGES on PR #6431:

- Correct Gotcha 1's "The fix" paragraph: bd doctor --fix's
  corrupt-manifest repair renames the whole data_dir directory to a
  sibling .<ts>.corrupt.backup path, not a backup nested inside the
  database's own directory. Verified against
  cmd/bd/doctor/fix/database_integrity.go and
  cmd/bd/doctor/tracked_runtime.go.

- Replace the hardcoded "Schema already at v64" literal with
  version-agnostic "Schema already at v<N>" in the doc and CLI help
  text, and narrow the docsync test assertion to the prefix "schema
  already at v" so it survives future version bumps instead of
  rotting again.

- Drop the dead GitHub-issue-style link around ga-vrq5pu (a Gas City
  bead id, not a GitHub issue) — keep it as plain text.

Ref: be-hobyw

* review: correct re-clone gotchas and tighten their guards (PR #6431 iters 1-2)

Maintainer review fixup for the adopted PR. This is a docs-only PR whose
entire deliverable is factual accuracy, so every finding here is about a
claim the doc makes rather than about code behaviour.

=== Iteration 1 ===

[major] Gotcha 1's "The fix" paragraph misattributed the automated repair
and pointed an operator mid-crash-loop at a path that cannot run. Verified
first-hand in the worktree:

  - internal/doltserver/manifest_recovery.go:231-235 renames
    <data_dir>/<db>/.dolt -> <db>/.dolt.<ts>.corrupt.backup, i.e. IN PLACE,
    not the whole data_dir to a sibling as the doc claimed. It also only
    fires behind nomsDirLooksCorrupt, whose own comment is "recovery only
    fires when we can prove there is nothing the user would want to keep"
    (:94-100) - so it never touches the superseded-but-populated store the
    gotcha is about.
  - The whole-data_dir -> sibling rename is a different fix:
    cmd/bd/doctor/fix/database_integrity.go:35,43-45 over
    getDatabasePath(beadsDir) (validation.go:15-21).
  - That fix opens with serverModeIntegrityRecoveryGuard, which refuses
    outright in Dolt server mode (:79-96).

Rewritten to state all three facts and to tell the reader plainly that the
move is theirs to make by hand. Kept the correct headline sentence. The
paragraph deliberately does not assert anything about where the in-place
backup lands under the legacy single-database layout (data_dir/.dolt), the
one premise the review left unproven - the wording is scoped to the standard
<data_dir>/<db>/ layout instead of minting a fresh unverified claim.

[minor] Gotcha 2's mechanism sentence ("bd's ordinary open does not recreate
them") is false for embedded mode: newStore -> initSchema (store.go:285,470)
calls schema.MigrateUp (:574), and migrationWorkNeeded returns true whenever
!ignoredSource.atLatest (schema.go:866-867) - and ignored_schema_migrations
is itself in doltIgnorePatterns, so a fresh clone always qualifies. Replaced
the universal with the actual condition. The replacement list of opens that
do NOT self-heal was itself wrong on its first item; see iteration 2 below.
The prescribed remedy was already correct and is unchanged.

[minor] The doc's prose Freshness source list gained cmd/bd/init_safety_help.go
but the enforcing DOCS array did not. Added to both scripts/check-doc-freshness.sh
and the pinned row in scripts/check_doc_freshness_test.go - a coupled pair:
editing only the script reds the pinned test with "Freshness source does not
name cmd/bd/init_safety_help.go" (verified by running exactly that mutation).

[nit] The docsync guard for the headline rule was two independent whole-file
substring checks. Scoped it to Gotcha 1's own section and matched the advice
as a phrase, and pinned both ends of the help text's #re-clone-gotchas
cross-reference, which neither markdown link checker can see because it lives
in a Go string. Five mutation legs, each reddening only its own assertion:
inverting the advice, moving the phrase outside the section, renaming the
heading, breaking the help anchor, and removing the Gotcha 1 heading. The
inversion leg is the one that matters - the file still contained "outside"
(2x) and "data_dir" (13x), so the old form stayed green on inverted advice.

[nit] Bumped Last reviewed: to the revision date.

=== Iteration 2 ===

Both lanes verified all five iteration-1 fixes. Three prose findings remained,
none a merge gate (scorecard: approve, Required Changes: none). All three are
the same defect class - a sentence that quantifies over a set the author did
not census - so each is fixed by removing the quantifier rather than by
restating it more carefully.

[minor] Gotcha 2's replacement enumeration was false on its first item: a
server, shared or proxied open DOES replay the clone-local series in this
doc's own scenario. Re-derived at head, both lanes independently:

  - internal/storage/uow/dolt_sql_provider.go:267-287 calls
    MigrateUpWithLock UNCONDITIONALLY on the non-team-server, non-preview
    arm; p.readOnly is consulted only after a RemoteMigrateGateError comes
    back (:288-296), so it cannot suppress the pass.
  - The gate cannot refuse a main-current clone: PendingVersions is
    mainSource.pendingVersions only (schema.go:525-527) and the gate
    early-returns nil on len(pending)==0 (remote_migrate_gate.go:731-737),
    so the ignored series is invisible to it.
  - migrationWorkNeeded is true whenever !ignoredSource.atLatest
    (schema.go:866-869), so the locked pass runs the full MigrateUp
    including ignoredSource.migrate (schema.go:822). DoltStore.initSchema
    reaches the same call on the writable-open path (dolt/store.go:3076).

So the positive clause is widened to any writable open (embedded, server or
proxied), and the negative clause is rewritten as a tautology plus an open
list: the open that hit the error was not self-healing, and the kinds that
skip or only verify "include" read-only/preview opens, team-server opens
(verifyTeamServerSchema only checks - dolt_sql_provider.go:342-371), the
preview-attach arm, and gate-refused opens. Each named arm was verified
individually; the list deliberately does not claim to be exhaustive, which
is what the previous wording got wrong. Nothing in docsync can enforce this
paragraph, so an open list is also the honest shape.

[minor] Gotcha 1's data_dir locator omitted the mode that overrides both
knobs it names. ResolveDoltDir checks IsSharedServerMode() FIRST and returns
SharedDoltDir() before it ever reaches projectDoltDirPath
(doltserver.go:316-330); the knobs are BEADS_DOLT_SHARED_SERVER=1|true or the
dolt.shared-server config key (:117-122), and the directory is
~/.beads/shared-server/dolt/, overridable via BEADS_SHARED_SERVER_DIR
(:248-257, :275-285). Added as its own paragraph rather than growing the
parenthetical, with the reason it matters most there: one shared data_dir
holds every project's database, so a single stray subdirectory crash-loops
the server for all of them.

[nit] "neither of bd doctor --fix's TWO Dolt-database repairs" made a numeric
claim the sentence does not need, and the count is wrong:
cmd/bd/doctor/fix/repo_fingerprint.go:135-161 os.RemoveAll's
cfg.DatabasePath(beadsDir) behind an interactive "This will DELETE %s. [y/N]",
and cleanCruftBeadsDirFiles (artifacts.go:238) can remove a .beads
subdirectory too when a redirect is expected. Dropping the word "two" would
have left "neither", which is itself a two-quantifier, so the count is
removed instead: "no bd doctor --fix repair performs this move here. The two
that come closest are:" - now a statement about the two bullets that follow,
not a census of the repairs. The operative universal survives the census
(the move-performing rename sites are only database_integrity.go:46,54; the
others delete or rename in place), so the reader's action is unchanged.

Validation (iteration 2): go test -tags=gms_pure_go ./test/docsync (8 tests,
green, zero skips, both InitSafety tests among them); go test -tags=integration
-count=1 -run Freshness ./scripts (33 pass, 1 Windows-only skip);
./scripts/check-doc-freshness.sh PASS with docs/recovery/init-safety.md at 0
days old and all five of its Freshness sources resolving; git diff --check
clean. Prose-only: no code, test or freshness-pair file changed this
iteration.

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
2026-09-27 03:41:05 -07:00
Julian Knutsen
57ef364501
build(bazel): side-by-side Bazel scaffold + policy tests (#6798)
* build(bazel): add side-by-side Bazel scaffold (module + gazelle)

Add a Bzlmod Bazel build alongside the Go toolchain. `go build` and
`go test` are unchanged; nothing in CI invokes Bazel yet.

- MODULE.bazel: rules_go 0.63.0, gazelle 0.53.0, Go SDK 1.26.7 (matches
  the go.mod toolchain directive), go_deps from go.mod.
- ICU policy (engdocs/ICU-POLICY.md): a go-mysql-server gazelle_override
  selects the pure-Go regex backend and excludes regex_cgo.go, and
  .bazelrc builds with --@rules_go//go/config:tags=gms_pure_go, so no
  target depends on go-icu-regex or links libicu.
- third_party/patches: three module_override patches for dolt deps that
  ship WORKSPACE-era BUILD files, adapted from the gascity project.
- .bazelrc: prcore/ci test configs (inert for now; they match pr-core's
  test selection, not yet its environment isolation) and a generic
  remote-exec config with a bounded remote timeout. Executor endpoints and
  TLS credentials come only from a gitignored .bazelrc.local/user.bazelrc
  or a CI rc outside the workspace.
- .bazelversion pins Bazel 9.2.0; .bazelignore skips separate modules,
  non-Go trees, nested agent worktrees (.claude, .worktrees) and local
  data/output dirs (.beads, .dolt, dist, .runtime, tmp), so a primary
  checkout neither builds nor gazelle-rewrites nested worktree copies.
- Gazelle-generated BUILD.bazel files for every Go package.
- Makefile: `make bazel-sync` (gazelle + bazel mod tidy).
- .gitignore: bazel-* output symlinks and machine-local rc files.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(bazel): policy tests for the Bazel configuration

Add scripts/bazel_policy_test.go, plain Go tests that run under both
`go test ./scripts` and `bazel test //scripts:scripts_test`:

- MODULE.bazel go_sdk.download version equals the go.mod toolchain.
- ICU policy: .bazelrc sets gms_pure_go for build, the go-mysql-server
  gazelle_override excludes regex_cgo.go, and the root BUILD.bazel
  carries `# gazelle:build_tags gms_pure_go`.
- .bazelversion pins an exact Bazel release.
- .bazelrc.local and user.bazelrc are gitignored (parsed from .gitignore
  and cross-checked with git check-ignore when in a checkout).
- No remote-execution endpoints or credentials in committed bazelrc-like
  files, Markdown docs or .github/**: remote/BES/TLS flags
  (--remote_executor, --remote_cache, --bes_backend, --remote_header,
  --tls_client_certificate, ...) with a literal value, with or without a
  URL scheme, and non-loopback gRPC URLs in rc/.github files. Placeholders,
  $VARIABLES, and loopback are allowed; Markdown gRPC URLs (OTel exporter
  docs) are not flagged. Skipped outside a git checkout, e.g. in the Bazel
  sandbox.

Each check is a pure function also exercised against fixtures that break
the invariant. The files the tests read are declared as data via
//:bazel_policy_files so they resolve from runfiles under Bazel.

scripts/check-build-tags.sh now treats Bazel invocations as governed by
.bazelrc: the shell command segment that invokes Bazel (split on &&, ||,
;, |, $( and backticks) is exempt from the per-line `go` tag check, while
a bare `go` in another segment of the same line is still flagged. When
any scanned file invokes Bazel (or .bazelrc exists) .bazelrc must set
--@rules_go//go/config:tags=gms_pure_go for build.
scripts/check_build_tags_test.go covers both in a temp repository.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* fix(scripts): split bazel lines in pure bash so check-build-tags works with BSD sed

BSD sed (macOS) does not expand \n in s/// replacements, so the segment
split never happened and the Bazel-exemption tests failed on macos-latest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* test(scripts): skip check-build-tags tests when bash lacks mapfile

macOS runners use /bin/bash 3.2, which has no mapfile; check-build-tags.sh
has always required bash >= 4, so the new tests are skipped there.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 03:41:02 -07:00
ecuthiell
79631656c0
fix(config): pin role writes to a fresh common-config context (#6454)
* fix(exec): match Windows environment key identity (#5618)

Centralize os/exec-compatible environment-key comparison and use it for credential, metrics, Git-hook, trace, and repro subprocess filters. Preserve exact Unix semantics and Unicode near-collisions.

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell
Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>

* fix(worktree): scrub inherited Git routing state

Establish CWD as the worktree repository boundary before discovery can consume inherited Git routing. Fence the startup config probe, clear routing in-process before root pre-run discovery, and retain command-owned subprocess scrubbing as defense in depth without changing PID or signal semantics.

Fixes #5531

Agent-Signature: codex-gpt-5-unknown-reasoning on behalf of Ewen Cuthiell

* refactor(worktree): explain owned filtering and remove an unused shim

Document why filtering the fresh routing slice in place is safe and call
the shared routing-key classifier directly from tests. Retain the two
forwarders used by production worktree subprocess/removal paths.

Review: https://github.com/gastownhall/beads/pull/5623#pullrequestreview-5098421671
Bead: saa-cgh.23
Agent-Signature: unknown-model/unknown-reasoning

* fix(config): isolate identity and tracked-file Git probes from routing

Reuse the worktree routing owner for GetIdentity and isGitTracked so
explicit cwd/path selection is not displaced by inherited repository,
index or injected config state. Preserve identity precedence and the
tracked-secret refusal contract, with real target/decoy regressions.

Follow-up: https://github.com/gastownhall/beads/issues/6222
Dependency: https://github.com/gastownhall/beads/pull/5623
Reported-by: bee-ghosttrack
Bead: saa-cgh.93
Agent-Signature: unknown-model/unknown-reasoning

* test(execenv): exercise every environment operation under both host rules

Thread the host choice through narrow private helpers behind the existing
exported functions. Keep one normalization owner and retain native wrapper
tests; the additional table covers both host branches for equality, prefix
matching, last-wins lookup, filtering and input preservation.

Review: https://github.com/gastownhall/beads/pull/5672#pullrequestreview-5096948965
Bead: saa-cgh.78
Agent-Signature: unknown-model/unknown-reasoning

* docs(worktree): explain startup Git environment scope (saa-cgh.23)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(execenv): exercise exported host policy wiring (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): share subprocess key identity for Git routing (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): isolate tracked-file guard from Git routing (saa-cgh.98)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6356.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): isolate role commands from Git routing (saa-cgh.99)

Follow-up to bee-ghosttrack's review of gastownhall/beads#6322; refs #6357.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(env): exercise shared key helpers on native Windows (saa-cgh.78)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitenv): share key parsing and normalize routing membership once (saa-cgh.93)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(config): explain role command routing policy (saa-cgh.99)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): retain legitimate inherited tracking context (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): isolate trusted global configuration fixture (saa-cgh.98)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): isolate role cleanup in the selected repository (saa-cgh.109.4)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): reset only common local role configuration (saa-cgh.109.10)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): scope hooks-path cleanup to selected common config (saa-cgh.109.11)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(hooks): make worktree role preservation independent (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Report selected config read failures during hook reset (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(hooks): keep successful config stdout separate from diagnostics (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): pin role writes to fresh common context (GH#6384) (saa-cgh.120.3)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config): retain Git diagnostics from role writes (saa-cgh.120.3)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(config): assert the actual Git lock diagnostic (saa-cgh.120.3)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(config,hooks): restore the inherited-tracking fallback in the secret guard

Maintainer review fixes for PR #6454 (adopt-pr iteration 1). The scorecard
approved at 913/1000 with no blocker or major surviving synthesis; these are
the non-gating findings that were cheap to close while the fixup was open.

Finding 1 (minor, security) is the only in-range regression in the report. The
range switched internal/config.isGitTracked from the inherited environment to
gitenv.ScrubRouting only, so a config.yaml tracked solely through legitimate
routing -- a bare repository whose work tree is named by GIT_DIR/GIT_WORK_TREE
-- reported untracked, and a secret-key write that upstream-base refused was
silently allowed. Restores the scrubbed-then-inherited union the same stack
already gave cmd/bd.isGitTrackedFile.

Finding 4 (nit) composes with it rather than conflicting, so both land as one
change: the inherited probe now runs only when the scrubbed probe failed for a
configuration reason. git's exit codes discriminate exactly -- 0 tracked, 1
repository reached but path untracked (final), 128 no reachable repository --
so the ordinary untracked-hook miss no longer spawns a second `git ls-files`
while the bare-work-tree fallback is preserved.

Finding 2 (minor). scrubWorktreeRemovalGitEnvForOS keyed its stricter
no-optional-locks policy on strings.ToUpper while the rest of the PR uses
execenv key identity. The two disagree in both directions on Windows:
GIT_OPTIONAL_LOCKS with a dotted capital I (U+0130) survived the scrub although
Git honors it, and GIT_OPTIONAL_LOCK with a long s (U+017F) was dropped
although os/exec keeps it distinct. normalizeWorktreeGitEnvKey is deleted in
favour of execenv.KeyEqualForOS. Base applied ToUpper on all platforms, so this
is a consistency fix in newly rewritten code, not a regression.

Finding 5 (nit). The comment above resetHooksPathIfBeadsManaged's probe
asserted that repoRoot and commonDir share the cached Git context. Probed
false: with cwd A and GIT_DIR=B/.git, `git rev-parse --git-common-dir
--show-toplevel` prints B/.git and A. Restated as intent.

Finding 3 (scrubGitHookEnv is a fifth, strictly weaker routing scrubber) is
deliberately not taken here: cmd/bd/export_auto.go is untouched by this range,
so the hazard is byte-identical at base, and the synthesis scoped it to a
follow-up bead rather than growing this stack.

Each fix is mutation-proved. Reverting isGitTracked reds only the new
TestSecretGitTrackingHonorsInheritedBareWorkTree -- including "refusal = <nil>",
the actual security consequence -- while the incumbent decoy test stays green,
so the pin adds coverage rather than duplicating it. Restoring ToUpper reds
only the new Windows row, showing both directions at once.
TestGuardHookWritePathHonorsInheritedRepository gains a fixture guard asserting
its scrubbed probe fails for a configuration reason rather than exit 1, so a
future fixture change cannot silently make the fallback unreachable.
scrubWorktreeRemovalGitEnvForOS had no test at all before this.

Green locally: ./internal/config, ./internal/execenv, ./internal/gitenv,
./internal/githooksenv, ./internal/gittraceenv, ./internal/metrics, ./scripts,
./internal/beads (the GIT_CONFIG_GLOBAL blast radius neither reviewer ran), and
a blast-radius cmd/bd run over the hooks, worktree, role and uninstall suites.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Signed-off-by: Ewen Cuthiell <ewencuthiell@gmail.com>
Co-authored-by: Bee <bee@ghosttrack.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-27 02:00:16 -07:00
ecuthiell
5ecc9b0a41
refactor(init): retire the unused global-ignore writer (#6452)
* fix(gitignore): preserve CRLF when appending project rules (saa-cgh.96)

Reported by bee-ghosttrack in gastownhall/beads#6343.

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): pin detector edge cases and clarify append behavior (saa-cgh.96)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): preserve line endings in Git exclude appends (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): share append byte composition (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(gitignore): clarify exclude fixture path variable (saa-cgh.104)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* docs(gitignore): explain append aliasing and trailing CR completion (saa-cgh.105)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): refuse exclude writes after read errors (saa-cgh.110)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* refactor(gitignore): use shared composition for exclude rules (saa-cgh.111)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(gitignore): omit the empty exclude leading separator (saa-cgh.112)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): refuse unreadable global ignore files (saa-cgh.115)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(init): own global ignore fixture working directory (saa-cgh.115)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* fix(init): preserve line endings in global ignore appends (saa-cgh.116)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell

* test(init): cover dangling global ignore symlinks (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* Use a literal CRLF fixture for global ignore composition (saa-cgh.120)

Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Ewen Cuthiell

* refactor(init): retire the unused global-ignore writer (saa-cgh.120.5)

Agent-Signature: unknown-model/unknown-reasoning on behalf of Ewen Cuthiell
2026-09-27 01:34:19 -07:00
Jim Wordelman
0bf13494f0
fix(scripts): check-doc-freshness.sh fails on duplicate Last-reviewed markers (#6482)
* test(feat): red — check-doc-freshness.sh: fail when a file has more than one 'Last reviewed:' marker line (refs be-g7tqg)

* feat: green — check-doc-freshness.sh: fail when a file has more than one 'Last reviewed:' marker line (refs be-g7tqg)
2026-09-26 19:08:55 -07:00
Rome Thorstenson
fd05690bdd
Newsletter dropped every commit made before the hour it ran (#6491)
* The newsletter dropped every commit made before the hour it ran

`--since` takes an APPROXIDATE, so the bare date this built did not mean the
start of that day -- it meant that day at the CURRENT TIME OF DAY.  Measured
on a live tree at 17:02 local:

    git log --since=2026-09-10           ->  0 commits
    git log --since=2026-09-10T00:00:00  -> 60 commits

Sixty commits dropped, silently, in a script whose output is published.  The
same invocation answered differently depending on the hour it ran.

The half-fix is a trap, and it is the one the town-wide description leads to.
The finding has been circulated as "--since is a traversal cutoff"; that is
true and it is not this bug.  Swapping in --since-as-filter while keeping the
bare date keeps the whole defect, because approxidate applies to the VALUE
regardless of which flag reads it:

    git log --since-as-filter=2026-09-10           ->  0 commits
    git log --since-as-filter=2026-09-10T00:00:00  -> 60 commits

So both are fixed here: a full timestamp for the approxidate, and
--since-as-filter (git 2.37+) for the cutoff, with a comment saying not to
simplify either back.

FOUR copies, not the three named, in two versions drifted 184 lines apart --
beads/{mayor,refinery} and gastown/{mayor,refinery}.  The defective block was
byte-identical in both (md5 6fdd32e6 over lines 156-160).  All four working
trees are patched; the 184-line drift is left alone, because converging them
is a decision nobody has made.

Verified through the patched code rather than by exit code: exec'ing the new
get_commits_since for 2026-09-10 returns 60 where the old form returns 0.

igr-9qdx

Executed-By: mayor

* fix(newsletter): fail loudly when git is too old for --since-as-filter

--since-as-filter needs git 2.37 (2022-06). On anything older `git log`
exits 129 with `error: unknown option 'since-as-filter=...'` on stderr,
stdout is empty, and get_commits_since returned [] — reproducing the
silent-and-shorter newsletter this change exists to fix, with a new cause.

Check the return code and raise with the version floor named. An empty
stdout on a zero exit is still a legitimate "no commits in range".

Verified against a shim that rejects the flag the way git < 2.37 does:
with the guard, RuntimeError naming the floor; with it reverted, 0 commits
and no error; on real git 2.43, 40 commits, unchanged.

* docs(newsletter): record the new git >= 2.37 floor

--since-as-filter puts the script's first hard git-version floor on the release
path (beads-release.formula.toml:866/:870 -> release-complete), but nothing
outside get_commits_since()'s docstring said so. On an older runner the release
step aborts and the operator has to trace the cause into a function body.

Add it to the module docstring alongside its existing requirement sections, and
to the README Setup section. No silent fallback to plain --since -- that
reinstates the truncation this PR exists to remove.

Placement is deliberate: the prose does NOT go in the `# /// script` PEP 723
block. That fence is parsed as TOML, so a comment line there is a hard launcher
failure, measured on uv 0.9.5:

    # /// script
    # requires-python = ">=3.10"
    # Requires git >= 2.37 for --since-as-filter
    # ///
    $ uv run probe.py
    error: TOML parse error at line 3, column 10 ... key with no value
    exit 2

The docstring already carries the Usage / Environment Variables / Configuration
File sections, so Requirements belongs beside them. After the edit
`uv run scripts/generate-newsletter.py --help` exits 0, and the error string
quoted in the README is byte-identical to the f-string it documents.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-26 18:56:29 -07:00
Jim Wordelman
6e36c3f19c
ci: raise proxied Dolt cmd test job timeout, add step timeout, refresh shard manifest (#6689)
* ci(proxied-cmd): green — give the proxied-shard job its own step timeout, refresh manifest (refs be-bruke)

The job-level timeout-minutes was the only backstop for the "Test
proxied-server cmd shard" step, and it counts the "Download binaries"
step too — so a slow download alone could exhaust the job budget and
kill an otherwise-healthy shard's test run with no way to tell the two
failure modes apart. Give the test step its own 16m timeout inside the
existing 30m job budget, and regenerate the bin-packed shard manifest
via scripts/ci/gen_proxied_shard_manifest.py so it stays in sync with
the current TestProxiedServer* set (0 drift, all 15 shards fallback:0).

* ci(proxied-cmd): mirror the shard timeouts onto the main lane, regen the manifest at the adoption base

Adoption review of #6689, iteration 1 — three minor findings, applied here
rather than deferred.

main.yml's `test-proxied-cmd` is the same job as pr-risk.yml's twin — same
proxied-test-shard.sh, same manifest, same total 15 — behind a
download/verify step inside a 20m budget with no step timeout, so the exact
ambiguous-timeout failure mode this PR removes from the PR lane survived on
the post-merge lane, which is where triage happens with nobody watching.
Mirror both edits (job 20m -> 30m, step 16m) and record the ordering at the
step, since it is not obvious from the site that 16m is deliberately below
the script's own -test.timeout=15m plus setup.

The manifest's only record of the cost proxy's two known blind spots lived
in a hand-written comment block the regeneration deleted:
TestProxiedServerListSortRetiresTheWalk seeds 1400 rows and walks the
listing three ways off a single init, and TestProxiedServerServeReadParity
is the CLI/HTTP read-parity oracle whose presence in this gate-required lane
is what makes the anti-drift claim enforced. Re-adding prose to a generated
file would just be deleted again, so it moves into the generator's emitted
header.

Base drift since authoring left the refreshed manifest one test stale —
#6584 added TestProxiedServerBackupRefusedOnExternalTopology, which
hash-distributed to shard 14 — so "0 drift, all 15 shards fallback:0" was
already false on the merge base. Benign (unlisted tests hash-distribute and
still run, and drift removed no name, so the strict parser's stale-entry
hard-fail was unreachable), but the stated deliverable did not hold.
Regenerated at the adoption base: 149 of 149 discovered tests listed,
fallback:0 on every shard, peak load unchanged at 39 estimated inits. That
figure is a point-in-time measurement, not an invariant: nothing in CI diffs
the committed manifest against a regeneration, so it re-drifts the moment
the next TestProxiedServer* lands. A freshness step
(`gen_proxied_shard_manifest.py 15 | diff - <manifest>`) on a lane already
triggered by .github/scripts/* would make it one; that is follow-up scope.

Verified: the generator reproduces the committed manifest byte-identically;
BEADS_TEST_SHARD_LIST_ONLY=1 across all 15 shards assigns all 149 discovered
TestProxiedServer* functions exactly once with no duplicates or orphans;
actionlint clean on both workflows.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Julian Knutsen <julianknutsen@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-09-26 07:17:03 -07:00
Bee
4eeb41f7d6
fix(test): reap dolt sql-servers leaked by killed test runs, and fail the suite that leaks (#6441)
* fix(test): reap dolt sql-servers leaked by killed test runs

A `go test -timeout` panic skips every t.Cleanup and TestMain defer, so a
test run killed that way left its `dolt sql-server` running forever. Two
gaps kept anything from ever noticing:

1. On darwin the deleted-cwd signal could not fire. macOS lsof prints the
   bare path of a working directory that has been unlinked — no
   " (deleted)" suffix, unlike Linux's /proc/<pid>/cwd — so readDarwinCwd
   always reported deleted=false and selectOrphanTestServerPIDs' orphan arm
   was dead code on this platform. It now stats the path and treats ENOENT
   (and only ENOENT) as deletion, via a pure parseDarwinCwd that takes the
   stat function so the classification is unit-testable.

2. Nothing ever looked at a DEAD run's temp root again. Each suite swept
   only its own root, after its own m.Run() — the one moment a killed run
   never reaches. New in internal/doltserver: WriteSuiteOwnerMarker claims a
   root with the owning PID, and SweepDeadSuiteRoots globs a suite's prefix
   at the START of the next run and reaps only roots whose recorded owner is
   gone. An unclaimed root and a root whose owner is alive (a parallel
   package, a second `go test`) are both left exactly as they are, so this
   keeps SweepOrphanedTestServers' contract: never a shared temp dir, never
   another suite's live server. decideSuiteRoot holds that judgment alone
   and is table-tested; the liveness probe is build-tagged darwin/linux with
   an always-alive stub elsewhere, making the helper a no-op there.

Wired into the cmd/bd and internal/storage/dolt TestMains, plus a new
TestMain for internal/storage/uow — the package that produced the observed
orphan and had no suite lifecycle at all. It pins TMPDIR under a suite root
so every t.TempDir() is sweepable, and newTestUOWProvider's cleanup now
reads the backend pid file before proxy.Shutdown and fails the test if that
server is still alive five seconds later, so a leak is visible where it is
caused rather than inferred later from a sweep.

Each wired TestMain reports a non-empty post-run sweep loudly, and fails the
run on it only under BEADS_TEST_FAIL_ON_LEAK=1 — opt-in so one flaky test
cannot redden a package for everyone. No workflow sets it yet.

Tests: go test ./internal/doltserver/ -run 'Sweep|Orphan|Suite' -count=1;
go test ./internal/storage/uow/ -run TestUOWDependencyEditorContract -count=1
-timeout 10m (real dolt); go test ./cmd/bd/ -run 'TestMain|TestVersion'
-count=1 -timeout 5m; go build ./...; go vet over the three packages;
gofmt -l . clean; golangci-lint (gosec + misspell) clean over the touched
packages. Verified on a live box: the orphan with the deleted cwd was
reaped, while the production server, an unclaimed suite root's server, and
an unrelated dolt server were all left running.

Refs: wy-j2zc8q

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1sjyiTjodNqNqEzEFbKAE

* fix(test): bound the sweep to temp roots and verify before killing

Round 2 on the leaked-test-server sweep, addressing an adversarial review of
2d9d656b5. Every finding was about the same thing: the first pass reached
further than its own doc comments claimed.

1. selectOrphanTestServerPIDs' deleted-cwd arm was root-independent, and the
   darwin fix had just brought it to life on macOS. A PRODUCTION server is
   spawned with cmd.Dir = <workspace>/.beads/dolt, so a developer who moved
   that workspace — or whose external volume unmounted — would have their
   live server reaped by any test run on the box. The arm now also requires
   the deleted path to have been under a temp root (tempDirRoots: os.TempDir
   plus /tmp, each in both its literal and symlink-resolved form, which is
   what makes macOS's /var/folders vs /private/var/folders pair match). This
   was a live hazard on linux too.

2. SweepDeadSuiteRoots promised it only touched marker-owned dead roots, but
   reached SweepOrphanedTestServers, whose deleted-cwd arm spans the whole
   box — at suite START, with sibling packages mid-run. It now uses a new
   strictly root-scoped entry point, sweepServersUnderRoots, with the shared
   SIGTERM/SIGKILL loop factored out as reapServerPIDs on each platform. The
   end-of-run sweep in the TestMains still uses the broad one, which finding
   1 has now bounded to temp dirs.

3. The uow cleanup's exit check blind-killed a bare PID. The server is not
   this process's child, so its PID is reusable, and proxy.Shutdown
   deliberately REFUSES to signal a record it cannot verify — killing that
   very PID defeated the protection. It now keeps the whole pidfile record,
   runs only when Shutdown returned an error (success already kills and
   confirms), and gates both the liveness check and the kill on
   procid.Verify / procid.Open with the recorded birth token. Timeout raised
   to 30s, since Shutdown's own budget is 5s + 2s.

4. os.RemoveAll deletes the marker early, so a partial failure left an
   unclaimed root that no later run could ever touch. Removal now does a
   chmod u+w walk first (mirroring cmd/bd's forceRemoveAll, which exists
   because that root doubles as an isolated $HOME full of read-only module
   cache entries), and on a still-failing removal it rewrites the marker with
   the same dead PID so the next run retries.

5. internal/storage/dolt created its root and ran the sweep above the
   isHelperSubprocess early return: eight concurrent helpers each swept and
   each claimed a root that os.Exit then abandoned. Moved below it; a helper
   inherits the parent's live BEADS_TEST_CIRCUIT_DIR through the BEADS_
   allowlist in integration.FilterEnv.

6. SweepDeadSuiteRoots globs a world-writable directory, so a planted root
   with a dead-PID marker could aim it at a tree of someone else's choosing.
   It now requires the root's uid to be os.Getuid() (unix-only file, accept-
   all stub elsewhere, where the sweep is inert anyway).

7. The symlink leg of the selection test skips instead of failing where
   os.Symlink is unprivileged. 8. "favour" -> "favor".

Tests: go test ./internal/doltserver/ -run 'Sweep|Orphan|Suite|Darwin'
-count=1 -v (49 cases, incl. new ones for a moved production workspace, an
unmounted volume, the observed orphan in both macOS path forms, the
root-scoped selection, canonicalRoots, tempDirRoots, the marker-restore path
and the read-only-directory removal); gofmt -l . clean; go vet over
doltserver, uow, cmd/bd and storage/dolt; GOOS=windows and GOOS=linux go vet
./internal/doltserver/; golangci-lint clean over all four trees;
scripts/check-build-tags.sh clean; go build ./...; go test -c for uow,
cmd/bd and storage/dolt. The three live dolt sql-servers on the box were
untouched throughout.

Refs: wy-j2zc8q

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1sjyiTjodNqNqEzEFbKAE

* fix(test): isolate helper circuit state, re-verify late exits, bound TMPDIR

Round 3, from the verification pass on efb7a1c39 (PASS-WITH-NITS).

1. internal/storage/dolt: moving the suite root below the isHelperSubprocess
   return also took the per-helper circuit-breaker directory with it, so all
   eight of TestMultiProcessSchemaInit's helpers would have inherited the
   parent's BEADS_TEST_CIRCUIT_DIR and read-modify-written ONE file keyed
   host:port:db, concurrently — a fresh flake risk in the exact test the move
   was meant to protect. The helper branch now makes its own temp directory
   and overrides the variable, as it effectively did before. No sweep and no
   owner marker for helpers: they start no server, and a helper that leaves
   through os.Exit would only abandon a marked root.

2. internal/storage/uow: requireBackendExited could observe the server alive
   and then have it exit before procid.Open/Kill, which report a plain
   "does not match token" that IsProcessGone does not match — so a server
   that stopped a few milliseconds late was reported as one that survived
   Shutdown entirely. Both failure paths now re-verify once and stay silent
   when the process is gone; only a verifiably-live process is a t.Errorf. A
   record with no birth token now logs the skip instead of returning
   silently, so it cannot pass for a clean check.

3. internal/doltserver: tempDirRoots now drops roots too broad to be evidence
   of anything. TMPDIR is an ordinary environment variable, so os.TempDir()
   can hand back "/" or a home directory, and either would put every
   workspace on the box back inside the deleted-cwd arm. isCredibleTempRoot
   rejects the filesystem root, a relative path, and any directory that is or
   contains $HOME, while /tmp, /private/tmp and /var/folders/… survive.

4. The identical SIGTERM/SIGKILL loop in sweep_darwin.go and sweep_linux.go
   is now one reapServerPIDs in sweep_reap_unix.go, taking the platform's
   identity probe as an isServer validator. It sits in a darwin||linux file
   rather than the portable sweep.go because the signaling is POSIX; the
   selection logic that decides which pids reach it stays platform-agnostic
   in sweep.go.

Tests: go test ./internal/doltserver/ -run 'Sweep|Orphan|Suite|Darwin|TempDir'
-count=1 (53 cases; new TestTempDirRootsRejectsOverbroadTMPDIR drives
TMPDIR=/ and TMPDIR=$HOME through the real os.TempDir, and
TestIsCredibleTempRoot tables the predicate); gofmt -l . clean; go vet over
doltserver, uow, storage/dolt and cmd/bd; GOOS=windows and GOOS=linux go vet
./internal/doltserver/; golangci-lint clean over all four trees;
scripts/check-build-tags.sh clean; go build ./...; go test -c for uow,
cmd/bd and storage/dolt.

Refs: wy-j2zc8q

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1sjyiTjodNqNqEzEFbKAE

* fix(sweep): keep /tmp credible when HOME is a sandbox under it (wy-j2zc8q)

PR core went red on every Linux runner: TestTempDirRootsBoundTheOrphanArm
and TestTempDirRootsRejectsOverbroadTMPDIR reported tempDirRoots() empty.
Cause: scripts/ci/lib/test-env.sh exports HOME under a mktemp -d root in
/tmp, and isCredibleTempRoot rejected any root that CONTAINS the home —
so /tmp itself was thrown out and the deleted-cwd arm silently disabled on
exactly the boxes whose killed runs it exists to clean up after. macOS
never showed it: the sandbox home lands under /var/folders, and the
hardcoded /tmp survived.

The carve-out: a home living inside the fixed /tmp fallback is a SANDBOX
home that anchors no workspaces, so a root that merely contains it stays
credible. A root that IS the home is still dropped whatever the home looks
like, and the sandbox test is judged against the hardcoded /tmp, never
os.TempDir(), so TMPDIR=/home with HOME=/home/runner still reads as a real
home under an overbroad root.

Tests: the overbroad-TMPDIR test now pins HOME to a real-shaped
non-temp path (the ambient one is the sandbox on CI, where "a workspace
under HOME" and "a path under /tmp" are the same path), plus two new
subtests for the sandbox shape and a sandbox row set in the predicate
table. Reproduced the red and the fix on Linux in docker with
HOME=/tmp/beads-test-env-abc/home; also green with HOME=/home/runner and
/root, and on macOS.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEmu5ZSFoappn7s9yUQ3aF

* fix(test): stop leaking daemonized shared-server dolt from test fixtures (wy-j2zc8q)

Every uow fixture that provisions a shared-server workspace now registers
ONE cleanup, verifiedShutdownCleanup, which stops the proxy and its
`dolt sql-server` and — when proxy.Shutdown reports an error — asserts the
recorded backend pid is actually gone (procid birth-token gated) instead of
printing a t.Logf line into a passing test. Nine copies of the silent idiom
are gone; an AST guard fails the package if a fixture provisions a workspace
without the cleanup, or calls proxy.Shutdown by hand.

A reaped server now FAILS the suite that leaked it (ApplyLeakPolicy), with
BEADS_TEST_ALLOW_LEAK=1 as the triage-only downgrade. The previous default
warned on stderr and exited 0, which is how all three recurrences rode green
suites and were rediscovered from a dev box's process table.

The dead-run root sweep (owner marker + SweepDeadSuiteRoots) is extended to
the remaining packages that pin a suite temp root and start servers:
cmd/bd/doctor (cgo + !cgo), cmd/bd/doctor/fix (cgo + !cgo), internal/beads.

* test(uow): guard pairs shutdownOnInterrupt with verifiedShutdownCleanup, exempts validation-error fixtures (wy-j2zc8q)

Salvaged from the executor's worktree after the quiet-hours stop: rules A/B/C
over *testing.T functions, non-vacuity counters per rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YWogqyZMByH2fYqUcafXvw

* fix(sweep): treat the per-user temp tree as a sandbox home root (wy-j2zc8q)

isSandboxHome whitelisted only /tmp, so on macOS a suite that pins HOME to a
t.TempDir() (cmd/bd/test_repo_beads_guard_test.go:128,
internal/beads/testmain_test.go:50) put HOME inside os.TempDir() itself
(/var/folders/xx/yy/T). isCredibleTempRoot then dropped os.TempDir() as "a
directory containing the user's home", tempDirRoots() collapsed to
[/tmp /private/tmp], and the deleted-cwd arm of SweepOrphanedTestServers was
inert on every Mac.

Judge sandbox-ness against a FIXED platform table (isUnderFixedTempRoots /
fixedTempRoots): /tmp everywhere, plus /var/folders on darwin,
canonicalRoots-expanded so /private/var/folders matches. TMPDIR still never
votes on its own credibility, so TMPDIR=/home with HOME=/home/runner keeps
reading as a real home under an overbroad root.

goos is a parameter, not a read of runtime.GOOS, so the darwin row is pinned
from Linux too.

Ran: go test -count=1 -run
'TestSandboxHomeUnderPerUserTempRoot|TestTempDirRoots|TestIsCredibleTempRoot|TestCanonicalRoots'
./internal/doltserver/ (ok); the pre-fix repro
HOME=$TMPDIR/fake-home-probe go test -run TestTempDirRootsBoundTheOrphanArm
now passes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVJ7A7qWZYATyg2TsqggSA

* test(uow): exempt rule C by explicit name marker, not an error assertion (wy-j2zc8q)

The old rule-C exemption — "a function calling require.Error/ErrorContains
asserts the constructor rejected its arguments" — inferred intent from the
body, and TestNewExternalDoltServerUOWProvider_PreexistingDirtyDatabaseIsNotHealed
satisfied it by accident: it provisions a REAL external server, require.NoError
on the constructor, then asserts an error from a later query. Deleting BOTH
cleanup helpers from it left the guard green (mutation G).

Exempt only on an explicit, greppable name marker (_ValidationErrors), and
check the marker is not a lie: an exempted function must assert a rejection
(require.Error/ErrorContains) and must assert nothing succeeded (no
require.NoError/assert.NoError) — closing the rename-to-dodge path too. No
non-vacuity floor on the exemption count: if the marker stops matching, rule C
only gets stricter and the validation fixtures fail loudly.

Positive controls (both reverted):
  - mutation G (drop both helpers from PreexistingDirty…) → FAIL:
    "TestNewExternalDoltServerUOWProvider_PreexistingDirtyDatabaseIsNotHealed
    provisions a shared-server workspace but never calls
    verifiedShutdownCleanup(t, storeRootDir)"
  - mutation G renamed to wear the marker → FAIL: "wears the
    \"_ValidationErrors\" exemption but calls require.NoError/assert.NoError"

Ran: go test -count=1 ./internal/storage/uow/ -run
'TestEveryServerFixtureRegistersVerifiedCleanup' (ok; census: rule A paired 9,
rule C checked 8, exempted 2). go vet ./internal/storage/uow/ clean.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVJ7A7qWZYATyg2TsqggSA

* test(doctor): fail the doctor and fix suites on a swept leak (wy-j2zc8q)

ApplyLeakPolicy was wired into 4 of 7 TestMains; the three doctor-side suites
called SweepOrphanedTestServers and discarded its result, so a leaked dolt
sql-server there was reaped silently and the run still went green — the exact
blindness the policy exists to remove.

Four call sites across the three suites, in the pattern
cmd/bd/test_repo_beads_guard_test.go:52-54 and
internal/storage/uow/testmain_test.go:65-66 already use:
  cmd/bd/doctor/testmain_nocgo_test.go     -> "cmd/bd/doctor"
  cmd/bd/doctor/dolt_e2e_test.go (cgo)     -> "cmd/bd/doctor"
  cmd/bd/doctor/fix/testmain_cgo_test.go   -> "cmd/bd/doctor/fix"
  cmd/bd/doctor/fix/testmain_nocgo_test.go -> "cmd/bd/doctor/fix"

Both build-tag variants compile.

Ran: go vet ./cmd/bd/doctor/... (0 issues); CGO_ENABLED=0 go vet
./cmd/bd/doctor/... (0 issues); go build ./... OK; go vet ./internal/doltserver/
./internal/storage/uow/ ./cmd/bd/doctor/... OK; gofmt -l internal cmd empty;
GOOS=linux go build ./... OK; GOOS=windows go build ./... OK.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BVJ7A7qWZYATyg2TsqggSA

* fix(sweep): pin darwin's fixed temp roots to their resolved forms (wy-j2zc8q)

fixedTempRoots("darwin") listed {"/tmp", "/var/folders"} and left the
/private/… forms to canonicalRoots' filepath.EvalSymlinks, which reads the
HOST filesystem: it adds them on a Mac and nothing at all on Linux. The
platform table is a claim ABOUT darwin that TestSandboxHomeUnderPerUserTempRoot
deliberately judges from any platform, so ubuntu CI saw
isUnderFixedTempRoots("/private/var/folders/…/fake-home", "darwin") = false.

Spell the resolved forms out in the table instead — "/private/tmp" and
"/private/var/folders" — so the answer is host-independent. canonicalRoots
dedups, so on a Mac they are exactly what it would have added anyway, and the
darwin lsof cwd form now matches from any judging platform. Linux rows are
unchanged.

The subtest is also given a direct assertion on the table's contents: the
isUnderFixedTempRoots rows alone cannot catch a dropped literal when they run
on a Mac (EvalSymlinks puts it back), so the mutation that started this would
have passed locally forever.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MPryBr9EE2Px9crZ4NrTT

* test(bd): move the darwin sweep guard onto the leak-fails-the-suite contract (wy-j2zc8q)

TestRunTestsAndSweepReapsOrphanedServer predates ApplyLeakPolicy (097757b3e,
wy-s4zdj) and asserted the OLD policy: a swept orphan still exits 0. With the
policy in place it fails on macOS CI with runTestsAndSweep() = 1, want 0 —
the test was pinning exactly the behavior this PR removes.

Restate it as the two-case contract it is now: the existing case expects 1
(a swept leak fails an otherwise-passing suite), and a sibling sets
doltserver.AllowLeakEnv to "1" and expects 0. Both still assert the fake
server was actually reaped; the fake-dolt shape and the reap wait are
unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MPryBr9EE2Px9crZ4NrTT

* fix(sweep): report the leaked server's working directory, not just its PID (wy-j2zc8q)

Both leak lines named PIDs only:

  Info: swept 1 orphaned test dolt sql-server process(es): [21881]
  FAIL: cmd/bd leaked 1 dolt sql-server process(es) [21881]; swept them.

By the time anyone reads that, 21881 has been dead for minutes and identifies
nothing — so a package with hundreds of tests reported a leak with no way to
find which fixture caused it. The sweep already knew the answer: every
candidate carries the cwd it was serving (serverCandidate.cwd), and a leaked
test server's cwd is the .beads/dolt under the suite's temp tree, which Go
names after the test that made it (<root>/TestSomeName1234/001).

Thread it through. selectCandidatePIDs/selectOrphanTestServerPIDs become
selectServers/selectOrphanTestServers returning a new exported SweptServer
{PID, Cwd}, reapServerPIDs becomes reapServers over the same type, and
SweepOrphanedTestServers and ApplyLeakPolicy carry it end to end — every
existing call site is a pass-through from the one to the other, so they are
unchanged. SweptServer.String renders "<pid> cwd=<dir>", which is what the
two stderr lines now print:

  Info: swept 1 ... process(es): [21881 cwd=/tmp/TestFoo123/001/.beads/dolt]

Tests: the darwin ps/lsof selection path now asserts whole SweptServers
(cwd included) rather than PIDs; TestSweptServerNamesItsDirectory pins the
rendering; TestApplyLeakPolicyNamesTheLeakingDirectory captures stderr and
pins the cwd in both the FAIL and the downgraded Warning line; and
TestReapServersReportsTheLeakedDirectory pins the Info line against a real
reaped process. sweep_other.go (non-unix) keeps the same shape.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MPryBr9EE2Px9crZ4NrTT

* fix(test): stop the shared dolt sql-server three init fixtures daemonize (wy-j2zc8q)

The leak the new guard catches. `bd init` in shared-server mode takes the
shouldInitSharedGlobalDB branch (cmd/bd/init.go:1417) and calls
doltserver.Start(sharedDir), which DAEMONIZES — cmd.Process.Release(), no
Wait, cmd.Dir = <sharedDir>/dolt (doltserver.go:1443-1446). Three cmd/bd
fixtures run that as a subprocess with BEADS_DOLT_SHARED_SERVER=1 and never
stop it, so the server outlives the `bd` that started it, the test that ran
it and the suite whose temp HOME it is serving:

  cmd/bd/dolt_worktree_remote_test.go:34  (--prefix remote-sync)
  cmd/bd/init_test.go:2096                (--prefix bare-fallback)
  cmd/bd/init_test.go:2318                (--prefix bare-core)

Evidence: a full local `go test ./cmd/bd/` left
`dolt sql-server --config <suite root>/.beads/shared-server/dolt-server-config.yaml`
running with cwd /private/var/folders/…/beads-bd-tests-1850365081/.beads/
shared-server/dolt and databases beads_global + remote_sync — the remote-sync
prefix names the fixture. All three resolve the SAME $HOME/.beads/shared-server,
so only the last starter leaves a survivor; the process table names one while
three carry the defect.

stopSharedServerCleanup (new cmd/bd/shared_server_cleanup_test.go) is the one
cleanup they now register, before the first subprocess so the t.Fatalf paths
are covered: record the pid from doltserver.IsRunning BEFORE stopping (a clean
Stop deletes the pid file), capture its procid birth token, doltserver.Stop,
then assert the recorded process actually left — t.Errorf and a force-kill if
it did not. Birth-token gated throughout: the server is not this process's
child, so its PID is reusable the moment it exits. Same shape as
verifiedShutdownCleanup in internal/storage/uow (35faf60e5).

Verified both ways on the same two tests:
  before: FAIL: cmd/bd leaked 1 dolt sql-server process(es)
          [4217 cwd=/private/var/folders/…/beads-bd-tests-1902359010/.beads/shared-server/dolt]
  after:  no Info/FAIL leak line, no sql-server left under any suite root
The three assertion failures in those tests (dolt_worktree_remote_test.go
sync.remote, init_test.go DoltMode server/embedded) reproduce identically with
and without this commit — pre-existing, untouched here.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018MPryBr9EE2Px9crZ4NrTT

* fix(test): stop the shared and proxied servers the init-metrics fixture daemonizes (wy-j2zc8q)

The post-run sweep on 164661ce4c named a fourth leaker on both CI runners:
`bd-metrics-home-*/.beads/shared-server/dolt`, TestInitMetricsEmittedPerDoltMode's
shared_server_via_flag case. That fixture runs `bd init --shared-server` with
HOME set only in the subprocess env, so the daemonized shared server lives
under a tree the in-process stopSharedServerCleanup never looks at. The same
table's proxied_server_via_flag case leaves a proxy plus its backend server
under <repo>/.beads/dolt with proxy.pid / proxy-child.pid records that no
dolt-server.pid cleanup can see.

- stopDoltServerCleanup(t, beadsDir): the existing verified stop, now with
  an explicit beads directory; stopSharedServerCleanup keeps its signature.
- stopProxiedServerCleanup(t, proxyRoot): proxy.Shutdown (the verified stop
  `bd dolt stop` performs) when either record exists.
- runBdInitForMetrics registers both before the subprocess runs, and the
  shared case now passes BEADS_DOLT_SERVER_PORT=<free port> so it actually
  starts a server on a box whose 3308 is already taken instead of silently
  skipping the path (the previously unused extraEnv field carries it).

Probe: with the two registrations commented out the sweep reports both
servers (`swept 2 ... bd-metrics-home-*/.beads/shared-server/dolt ...
bd-metrics-repo-*/.beads/dolt`); with them in place the package is ok.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HXZ9wbaFUnzRWcMj7iBxmq

* fix(test): scope suite leak attribution and verify cleanup (bd-154w)

Maintainer fixup for PR #6441, review attempts 1, 2, and 3.

Wire dbproxy/server into the marked suite-root lifecycle and verify the
standard fixture's backend shutdown before its directory is removed.
Capture synthetic leak-policy stderr, share the suite-root guard helper,
and document the manual repro harness's unconditional Kill/Wait cleanup.

Use SweepSuiteTestServers for every failure-producing post-run sweep,
including CGO, non-CGO, and integration callers. It delegates to the
existing strict root selector so a clean suite cannot reap another live
suite's deleted-cwd leak or fail in its place. Keep abandoned-run cleanup
separate through owner-checked SweepDeadSuiteRoots, and deprecate the
legacy global sweep for TestMain use without deleting contributor tests.
Pin and mark the integration suite's temporary root to retain detection.

Add a Linux process regression proving clean B preserves A's deleted-cwd
server and passes, then A reaps its own server and fails. Retain dead-owner
cleanup coverage and guard both integration temporary-directory APIs.

Pin the storage, CLI, and internal/beads suite roots before fixtures run,
with guards for both temporary-directory APIs. Preserve the storage helper
subprocess early return and the original parent for abandoned-root cleanup.
A Linux subprocess regression exercises the real storage TestMain: an
owned deleted-cwd fixture fails its suite while a foreign process survives.
Keep the CLI sandbox HOME beside fixtures so ~/.beads cannot become a
fixture ancestor and interfere with worktree repository discovery.

Keep integration server data owned but allocate its Unix socket in a short,
private directory with explicit cleanup. Exercise a data path exceeding
the Unix socket path budget while retaining the real SQL round trip.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Agent-Signature: Codex-unknown-model-unknown-reasoning on behalf of Julian Knutsen

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <julianknutsen@users.noreply.github.com>
2026-09-22 15:08:40 -07:00