Skip to content

Commit 42a6251

Browse files
anandgupta42claude
andcommitted
fix: [release] codex-review fixes — fail-closed gates, ordering, PREV_TAG upper bound
Codex review of the release-hardening commit found fail-open paths; all fixed: - skill/RELEASING.md: tag verification now aborts (`|| exit 1`) instead of echo-and-continue; stage-`tag` preflight moved AFTER the release commit (it previously ran against a tree dirtied by the CHANGELOG edit and could never pass); `cd` blocks made subshells so repo-root paths stay valid; smoke test builds with `OPENCODE_VERSION` injected and asserts equality - `release-preflight.ts`: npm publish-check only treats E404 as "not published" (other errors FAIL); `gh` errors FAIL (WARN only when the binary is missing); malformed `gh` JSON FAILs instead of double-reporting; `run()` no longer throws on missing binaries; SemVer prerelease compare is numeric-aware (`beta.10` > `beta.2`); `selectPrevTag` picks the greatest stable tag strictly LOWER than the target (a merged fork-inherited `v1.18.3` must not become PREV_TAG for `v0.9.x`) — same fix applied to `release.yml`'s PREV_TAG loop - `/release-beta`: wires in the preflight (`--allow-prerelease`) and fail-closed tag collision checks before pushing the beta tag - tests: 34 -> 38 (numeric prerelease precedence, prefix ranking, fork-inherited higher-tag exclusion) Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 56fcfb6 commit 42a6251

6 files changed

Lines changed: 169 additions & 67 deletions

File tree

‎.claude/commands/release-beta.md‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ DIST=$(find packages/opencode/dist -type d -name '*'"$(uname -m | sed s/arm64/ar
9191
# 4. marker guard
9292
bun run script/upstream/analyze.ts --markers --base main --strict
9393

94-
# 5. Local Verdaccio sanity IF docker + a native-platform build are available
94+
# 5. Deterministic preflight (tag collisions, version sanity vs npm, prerelease
95+
# ancestry, release-blocker PRs). For a beta cut from main use it as-is; for a
96+
# branch beta the `base` check will FAIL by design — then rely on the manual
97+
# tag verification in Step 4 instead.
98+
bun script/release-preflight.ts --version X.Y.Z-beta.N --stage tag --allow-prerelease
99+
100+
# 6. Local Verdaccio sanity IF docker + a native-platform build are available
95101
# (the docker image is linux; on a mac you cannot cross-build the linux NAPI dist,
96102
# so this validates the current platform only — CI covers the rest):
97103
# (cd packages/dbt-tools && bun run build) && docker compose \
@@ -108,7 +114,12 @@ The `-beta.N` suffix is what routes to the beta channel. Do NOT omit it.
108114

109115
```bash
110116
BETA_TAG="vX.Y.Z-beta.N"
117+
# Fail closed on collisions — a stale local tag makes `git tag` no-op and the
118+
# push would publish whatever the old tag points at. Never delete-and-recreate.
119+
git rev-parse -q --verify "refs/tags/$BETA_TAG" && { echo "LOCAL TAG EXISTS — STOP"; exit 1; }
120+
git ls-remote origin "refs/tags/$BETA_TAG" | grep -q . && { echo "REMOTE TAG EXISTS — STOP"; exit 1; }
111121
git tag "$BETA_TAG"
122+
test "$(git rev-parse "$BETA_TAG")" = "$(git rev-parse HEAD)" || { echo "TAG MISMATCH — STOP"; exit 1; }
112123
git push origin "$BETA_TAG" # push the TAG (not necessarily main)
113124
```
114125

‎.claude/commands/release.md‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,12 @@ When running the full suite in the background, tee complete output to a file (`b
229229

230230
### 7a: Smoke test the ACTUAL release candidate
231231

232-
Never smoke-test the `$PATH`-resolved `altimate` — in v0.9.2 it silently validated a stale globally-installed 0.7.3. Build and run the real artifact:
232+
Never smoke-test the `$PATH`-resolved `altimate` — in v0.9.2 it silently validated a stale globally-installed 0.7.3. Build with the target version injected (otherwise the binary reports a `0.0.0-…` preview version and no assertion is possible), then assert the exact version. Run from the repo root; use a subshell for the `cd` so later paths still resolve:
233233

234234
```bash
235-
cd packages/opencode && bun run pre-release # builds dist + checks NAPI externals + binary starts
235+
(cd packages/opencode && OPENCODE_VERSION={NEXT_VERSION} bun run pre-release)
236236
BINARY=$(find packages/opencode/dist -path '*bin/altimate*' -type f | head -1)
237-
"$BINARY" --version # MUST print a version consistent with this release, not a stale install
237+
test "$("$BINARY" --version)" = "{NEXT_VERSION}" || { echo "SMOKE VERSION MISMATCH — STOP"; exit 1; }
238238
"$BINARY" --help
239239
```
240240

@@ -276,16 +276,15 @@ Wait for approval.
276276

277277
## Step 9: Pre-Release Checks
278278

279-
Run all mandatory checks:
279+
Run all mandatory checks from the repo root:
280280

281281
```bash
282282
# Pre-release sanity (binary builds and starts) — if not already run in Step 7a
283-
cd packages/opencode && bun run pre-release
284-
285-
# Full preflight again, now tolerating local release commits ahead of origin/main
286-
bun script/release-preflight.ts --version {NEXT_VERSION} --stage tag
283+
(cd packages/opencode && OPENCODE_VERSION={NEXT_VERSION} bun run pre-release)
287284
```
288285

286+
(The stage-`tag` preflight runs in Step 10, AFTER the release commit — running it here would fail its clean-worktree check on the just-edited CHANGELOG.)
287+
289288
**Exit-status integrity rule:** never background a gate command with a trailing status echo (`cmd > log; echo "exit: $?"` — the echo always exits 0 and once turned a FAILED pre-release build into a reported pass). Preserve the real exit code: run in foreground, or `cmd 2>&1 | tee log` and check `$pipestatus[1]`/`PIPESTATUS[0]`, and ALWAYS read the tool's own verdict line from the log.
290289

291290
**Gate: ALL CHECKS MUST PASS.** Stop on failure.
@@ -302,9 +301,9 @@ docker compose -f test/sanity/docker-compose.verdaccio.yml up \
302301

303302
If Docker unavailable, skip — but mark it ⏭️ in the Step 12 summary (it was once skipped silently). CI will catch it.
304303

305-
## Step 10: Commit, Tag, Push — three verified steps, one atomic push
304+
## Step 10: Commit, Preflight, Tag, Push — verified steps, one atomic push
306305

307-
Do NOT chain these with `&&` into one command (a mid-chain tag failure once committed but silently never pushed). Verify each stage:
306+
Do NOT chain these with `&&` into one command (a mid-chain tag failure once committed but silently never pushed). Run each from the repo root and verify each stage:
308307

309308
```bash
310309
# 1. Commit (targeted staging only — never `git add -A`, worktrees carry scratch files)
@@ -313,13 +312,19 @@ echo "release: v{NEXT_VERSION}" > .github/meta/commit.txt
313312
git commit -F .github/meta/commit.txt
314313
git log -1 --oneline # verify the release commit is HEAD
315314

316-
# 2. Tag — then VERIFY before pushing (a silently no-op'd `git tag` once pushed a
315+
# 2. Full preflight — now that the tree is clean again and HEAD carries the
316+
# release commit. Stage `tag` allows local commits ahead of origin/main.
317+
bun script/release-preflight.ts --version {NEXT_VERSION} --stage tag
318+
# MUST print "Preflight PASSED" and exit 0. On FAIL: stop.
319+
320+
# 3. Tag — then VERIFY before pushing (a silently no-op'd `git tag` once pushed a
317321
# stale tag pointing 2641 commits away from main; the push itself triggers publish,
318-
# so post-push verification is too late)
322+
# so post-push verification is too late). The `exit 1` is load-bearing —
323+
# a bare echo would print the warning and keep going.
319324
git tag v{NEXT_VERSION}
320-
test "$(git rev-parse v{NEXT_VERSION})" = "$(git rev-parse HEAD)" || { echo "TAG MISMATCH — STOP"; }
325+
test "$(git rev-parse v{NEXT_VERSION})" = "$(git rev-parse HEAD)" || { echo "TAG MISMATCH — STOP"; exit 1; }
321326

322-
# 3. Push branch + tag atomically — both land or neither does
327+
# 4. Push branch + tag atomically — both land or neither does
323328
git push --atomic origin HEAD:main v{NEXT_VERSION}
324329
```
325330

‎.github/workflows/release.yml‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,18 @@ jobs:
361361
362362
# Get the previous tag.
363363
# altimate_change — pick the newest STABLE tag that is an ANCESTOR of this
364-
# commit, excluding the current tag and any prerelease (-beta etc). Plain
365-
# `--sort=-version:refname | head -2 | tail -1` picked the 2nd-highest tag by
366-
# name, which for a stable release lands on a prerelease or a stray/divergent
367-
# tag (e.g. a dangling v0.9.0), producing a bogus compare range. Restricting to
368-
# `--merged HEAD` non-prerelease tags yields the real previous release.
369-
PREV_TAG=$(git tag --merged HEAD --sort=-version:refname \
370-
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
371-
| grep -vx "$CURRENT_TAG" \
372-
| head -1)
364+
# commit AND strictly LOWER than the current tag. Excluding only equality is
365+
# not enough: if upstream history is ever merged, fork-inherited tags (e.g.
366+
# v1.18.3) would beat the real previous release for a v0.9.x target and the
367+
# compare range would silently omit history.
368+
PREV_TAG=""
369+
for t in $(git tag --merged HEAD --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$'); do
370+
if [ "$t" != "$CURRENT_TAG" ] && \
371+
[ "$(printf '%s\n%s\n' "$t" "$CURRENT_TAG" | sort -V | head -1)" = "$t" ]; then
372+
PREV_TAG="$t"
373+
break
374+
fi
375+
done
373376
374377
# Generate changelog from commits between tags
375378
echo "## What's Changed" > notes.md

‎docs/RELEASING.md‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,22 @@ The version is injected into the binary via esbuild defines at compile time.
3434

3535
## Release Process
3636

37-
### 1. Update CHANGELOG.md
37+
### 1. Run preflight (before touching anything)
38+
39+
**MANDATORY** — the deterministic gate. Run it while the tree is still clean;
40+
it fails on a dirty worktree by design:
41+
42+
```bash
43+
# Checks: clean tree, HEAD == fresh origin/main, no tag collisions (local OR
44+
# remote), version sanity vs npm, prerelease-line ancestry, release-blocker
45+
# PRs, PREV_TAG dry-run, marker guard.
46+
bun script/release-preflight.ts --version 0.5.0 --stage pre
47+
```
48+
49+
Do NOT proceed if any check fails. If it reports a tag collision, resolve it
50+
explicitly — never delete-and-recreate a tag blind.
51+
52+
### 2. Update CHANGELOG.md
3853

3954
Add a new section at the top of `CHANGELOG.md`:
4055

@@ -48,29 +63,22 @@ Add a new section at the top of `CHANGELOG.md`:
4863
- ...
4964
```
5065

51-
### 2. Run pre-release sanity checks
66+
### 3. Run pre-release sanity check
5267

53-
**MANDATORY** — these catch broken releases before they reach users:
68+
**MANDATORY** — this catches broken binaries before they reach users:
5469

5570
```bash
56-
# Deterministic preflight: clean tree, HEAD == fresh origin/main, no tag
57-
# collisions (local OR remote), version sanity vs npm, prerelease-line
58-
# ancestry, release-blocker PRs, PREV_TAG dry-run, marker guard.
59-
bun script/release-preflight.ts --version 0.5.0 --stage pre
60-
61-
cd packages/opencode
62-
bun run pre-release
71+
(cd packages/opencode && OPENCODE_VERSION=0.5.0 bun run pre-release)
6372
```
6473

6574
`pre-release` verifies:
6675
- All required NAPI externals are in `package.json` dependencies
6776
- They're installed in `node_modules`
6877
- A local build produces a binary that actually starts
6978

70-
Do NOT proceed if any check fails. If the preflight reports a tag collision,
71-
resolve it explicitly — never delete-and-recreate a tag blind.
79+
Do NOT proceed if any check fails.
7280

73-
### 3. Commit and tag
81+
### 4. Commit, re-preflight, tag, push
7482

7583
Stage files **individually** — never `git add -A` (release worktrees carry
7684
scratch files that must not ship in the release commit). Releasing does not
@@ -80,15 +88,20 @@ HEAD equals freshly fetched `origin/main` (worktrees push via `HEAD:main`).
8088
```bash
8189
git add CHANGELOG.md <other release files>
8290
git commit -m "release: v0.5.0"
91+
92+
# Re-run preflight now that the release commit exists. Stage `tag` allows
93+
# local commits ahead of origin/main (the tree must be clean again).
94+
bun script/release-preflight.ts --version 0.5.0 --stage tag || exit 1
95+
8396
git tag v0.5.0
8497
# Verify the tag points at HEAD BEFORE pushing — a pre-existing tag makes
85-
# `git tag` fail, and pushing a stale tag triggers a publish of old code.
86-
test "$(git rev-parse v0.5.0)" = "$(git rev-parse HEAD)"
98+
# `git tag` silently fail, and pushing a stale tag publishes old code.
99+
test "$(git rev-parse v0.5.0)" = "$(git rev-parse HEAD)" || exit 1
87100
# Atomic: branch and tag land together or not at all.
88101
git push --atomic origin HEAD:main v0.5.0
89102
```
90103

91-
### 4. What happens automatically
104+
### 5. What happens automatically
92105

93106
The `v*` tag triggers `.github/workflows/release.yml` which:
94107

@@ -100,7 +113,7 @@ The `v*` tag triggers `.github/workflows/release.yml` which:
100113
6. **Publishes Docker image (best-effort)** — to `ghcr.io/altimateai/altimate-code`; failures are logged but do NOT fail the release, so verify manually if you need the image
101114
7. ~~Updates AUR~~ — currently **disabled** (the workflow step is commented out; see `publish.ts` for setup steps to re-enable)
102115

103-
### 5. Verify
116+
### 6. Verify
104117

105118
After the workflow completes:
106119

‎script/release-preflight.test.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,17 @@ describe("compareSemver", () => {
8686
expect(compareSemver(v("0.9.2-beta.1"), v("0.9.2-beta.1"))).toBe(0)
8787
})
8888

89-
test("prerelease strings compare lexically", () => {
90-
expect(compareSemver(v("0.9.2-beta.2"), v("0.9.2-beta.10"))).toBeGreaterThan(0) // "beta.2" > "beta.10" lexically
89+
test("prerelease identifiers compare numerically per SemVer (beta.10 > beta.2)", () => {
90+
expect(compareSemver(v("0.9.2-beta.10"), v("0.9.2-beta.2"))).toBeGreaterThan(0)
91+
expect(compareSemver(v("0.9.2-beta.2"), v("0.9.2-beta.10"))).toBeLessThan(0)
92+
})
93+
94+
test("numeric prerelease identifiers rank below alphanumeric ones", () => {
95+
expect(compareSemver(v("0.9.2-1"), v("0.9.2-alpha"))).toBeLessThan(0)
96+
})
97+
98+
test("a prerelease identifier prefix ranks below its longer form", () => {
99+
expect(compareSemver(v("0.9.2-beta"), v("0.9.2-beta.1"))).toBeLessThan(0)
91100
})
92101

93102
test("major/minor/patch precedence beats prerelease presence", () => {
@@ -151,6 +160,18 @@ describe("selectPrevTag", () => {
151160
const tags = ["v0.9.0", "v0.10.0", "v0.2.0"]
152161
expect(selectPrevTag(tags, "v0.11.0")).toBe("v0.10.0")
153162
})
163+
164+
test("ignores merged tags HIGHER than the target (fork-inherited upstream tags)", () => {
165+
// If upstream history is ever merged, tags like v1.18.3 become ancestors
166+
// of HEAD. They must not become PREV_TAG for a v0.9.x release — the
167+
// compare range would silently omit history.
168+
const tags = ["v1.18.3", "v1.17.13", "v0.9.2", "v0.9.1"]
169+
expect(selectPrevTag(tags, "v0.9.3")).toBe("v0.9.2")
170+
})
171+
172+
test("returns null when only higher tags are merged", () => {
173+
expect(selectPrevTag(["v1.18.3"], "v0.9.3")).toBeNull()
174+
})
154175
})
155176

156177
describe("prereleaseLineTags", () => {

0 commit comments

Comments
 (0)