Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(release): make a failed release cut recoverable, and count deletions

Jose Ramirez9fc5ccc0a18e
diff --git a/scripts/precommit/bump-staged-package-versions.mjs b/scripts/precommit/bump-staged-package-versions.mjs
index 1e3a5695d..b2d3793d9 100644
--- a/scripts/precommit/bump-staged-package-versions.mjs
+++ b/scripts/precommit/bump-staged-package-versions.mjs
@@ -122,7 +122,10 @@ function readIndexedPackageVersion(pkg) {
}
}
-const stagedFilesResult = run('git', ['diff', '--cached', '--name-only', '--diff-filter=ACMR'])
+// D is included deliberately: a commit whose only change is a deletion still
+// changes the package's content, and omitting it let two different trees
+// report the same version with nothing at release time able to notice.
+const stagedFilesResult = run('git', ['diff', '--cached', '--name-only', '--diff-filter=ACDMR'])
if (stagedFilesResult.status !== 0) {
exitWithError(
diff --git a/scripts/release/prepare-release.mjs b/scripts/release/prepare-release.mjs
index 3eb85d845..d41228289 100644
--- a/scripts/release/prepare-release.mjs
+++ b/scripts/release/prepare-release.mjs
@@ -5,12 +5,30 @@
//
// node scripts/release/prepare-release.mjs --version 0.6.0 --release-id <id> \
// [--minimum-desktop-version 0.6.0]
-import { execFileSync } from 'node:child_process'
+import { execFileSync, execFileSync as run } from 'node:child_process'
import process from 'node:process'
import { COORDINATES, SEMVER_RE, argValue, compareVersions } from './release-coordinates.mjs'
const ROOT = process.cwd()
+// The monotonic guard below must compare against the last COMMITTED desktop
+// version, not the working file. A cut that failed after writing package.json
+// leaves the new version on disk; comparing against that makes re-running the
+// very command this script and validate-release-tag.mjs tell you to run fail
+// with "not greater than", which is a dead end.
+function committedDesktopVersion() {
+ try {
+ const raw = run('git', ['show', 'HEAD:desktop-app/package.json'], {
+ cwd: ROOT,
+ encoding: 'utf8',
+ stdio: ['ignore', 'pipe', 'ignore'],
+ })
+ return JSON.parse(raw).version
+ } catch {
+ return null
+ }
+}
+
function die(message) {
console.error(message)
process.exit(1)
@@ -35,7 +53,18 @@ if (minimumDesktopVersion && !SEMVER_RE.test(minimumDesktopVersion)) {
die(`--minimum-desktop-version must be MAJOR.MINOR.PATCH, got: ${minimumDesktopVersion}`)
}
-const current = COORDINATES.find(c => c.name === 'desktop-app/package.json').read(ROOT)
+// Range-check the floor BEFORE writing anything. The delegated updater rejects
+// a floor above desktopVersion, and discovering that after the coordinate loop
+// has already written package.json leaves the tree half-cut.
+if (minimumDesktopVersion && compareVersions(minimumDesktopVersion, version) > 0) {
+ die(
+ `--minimum-desktop-version ${minimumDesktopVersion} is greater than --version ${version}. ` +
+ `The floor is a compatibility minimum; it can never exceed the release itself.`
+ )
+}
+
+const onDisk = COORDINATES.find(c => c.name === 'desktop-app/package.json').read(ROOT)
+const current = committedDesktopVersion() ?? onDisk
if (compareVersions(version, current) <= 0) {
die(`--version ${version} is not greater than the current desktop version ${current}`)
}
@@ -53,6 +82,18 @@ const manifestArgs = [
if (minimumDesktopVersion) {
manifestArgs.push('--minimum-desktop-version', minimumDesktopVersion)
}
-execFileSync('node', manifestArgs, { cwd: ROOT, stdio: 'inherit' })
+try {
+ execFileSync('node', manifestArgs, { cwd: ROOT, stdio: 'inherit' })
+} catch (error) {
+ // The coordinate loop above has already written package.json and the lockfile.
+ // Say so, rather than leaving a raw stack trace and a half-written tree.
+ die(
+ `The release cut wrote desktop-app/package.json and package-lock.json to ${version}, ` +
+ `then the manifest update failed (${error.message}).\n` +
+ `The tree is half-cut. Either re-run this same command once the cause is fixed ` +
+ `(it compares against the last committed version, so re-running is safe), ` +
+ `or discard with \`git checkout -- desktop-app/package.json desktop-app/package-lock.json\`.`
+ )
+}
console.log(`prepared release ${version}`)
diff --git a/scripts/tests/test-precommit-release-manifest-ignore.sh b/scripts/tests/test-precommit-release-manifest-ignore.sh
index 199f952d2..15687a2dd 100755
--- a/scripts/tests/test-precommit-release-manifest-ignore.sh
+++ b/scripts/tests/test-precommit-release-manifest-ignore.sh
@@ -497,6 +497,33 @@ EOF
rm -rf "$d"
}
+assert_a_deletion_only_change_still_bumps_the_counter() {
+ local d; d="$(mktemp -d)"; make_repo "$d"
+ # Add a file and commit the resulting bump, so the deletion below is the only
+ # staged change in its own commit.
+ ( cd "$d" \
+ && echo "export const foo = 1" > external-rest-api/src/foo.ts \
+ && git add external-rest-api/src/foo.ts \
+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 \
+ && git -c user.email=t@t -c user.name=t commit -q --no-verify -m add )
+ local after_add; after_add="$(version_of "$d")"
+
+ ( cd "$d" && git rm -q external-rest-api/src/foo.ts \
+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )
+ local after_del; after_del="$(version_of "$d")"
+
+ # A deletion changes the package's content as surely as an addition does.
+ # With --diff-filter=ACMR (no D) the deletion was invisible, so two different
+ # trees reported the same version and the release-time counter check could
+ # not see it: both sides agreed by construction.
+ if [ "$after_add" = "0.1.61" ] && [ "$after_del" = "0.1.62" ]; then
+ pass "a deletion-only staged change still bumps the counter"
+ else
+ fail "after_add=$after_add after_delete=$after_del; expected 0.1.61 then 0.1.62"
+ fi
+ rm -rf "$d"
+}
+
assert_release_manifest_does_not_bump
assert_other_source_still_bumps
assert_a_counter_bump_resyncs_the_manifest
@@ -510,5 +537,6 @@ assert_unstaged_package_json_drift_is_not_leaked_into_the_manifest
assert_unrelated_unstaged_package_json_blocks_a_real_resync
assert_a_self_concealing_manifest_edit_cannot_suppress_the_resync
assert_a_corrupted_committed_package_json_is_refused_not_crashed
+assert_a_deletion_only_change_still_bumps_the_counter
exit $FAIL
diff --git a/scripts/tests/test-release-coordinates.sh b/scripts/tests/test-release-coordinates.sh
index 4b1843f00..c4b90aa21 100755
--- a/scripts/tests/test-release-coordinates.sh
+++ b/scripts/tests/test-release-coordinates.sh
@@ -590,6 +590,50 @@ assert_every_defined_case_is_invoked() {
fi
}
+assert_floor_above_version_is_rejected_before_any_write() {
+ local d; d="$(mktemp -d)"
+ make_fixture "$d" 0.5.0 0.1.60 0.1.51 0.5.0 0.1.252 0.1.60 0.1.51
+ cp -R "$REPO_ROOT/scripts" "$d/scripts"
+
+ ( cd "$d" && node scripts/release/prepare-release.mjs \
+ --version 0.6.0 --release-id t --minimum-desktop-version 0.7.0 >/dev/null 2>&1 )
+ local pkg; pkg="$(node -e 'console.log(require(process.argv[1]).version)' "$d/desktop-app/package.json")"
+
+ # The delegated updater rejects floor > desktopVersion. Discovering that AFTER
+ # the coordinate loop has written package.json leaves the tree half-cut, so
+ # the range check has to happen up front.
+ if [ "$pkg" = "0.5.0" ]; then
+ pass "a floor above the release version is rejected before any coordinate is written"
+ else
+ fail "desktop-app/package.json was written to $pkg despite an impossible floor"
+ fi
+ rm -rf "$d"
+}
+
+assert_a_half_cut_release_can_be_completed_by_rerunning() {
+ local d; d="$(mktemp -d)"
+ make_fixture "$d" 0.5.0 0.1.60 0.1.51 0.5.0 0.1.252 0.1.60 0.1.51
+ cp -R "$REPO_ROOT/scripts" "$d/scripts"
+
+ # Force the manifest write to fail AFTER package.json has been written.
+ chmod -w "$d/external-rest-api/src/releaseManifest.ts"
+ ( cd "$d" && node scripts/release/prepare-release.mjs --version 0.6.0 --release-id t >/dev/null 2>&1 )
+ chmod +w "$d/external-rest-api/src/releaseManifest.ts"
+
+ # Re-running the SAME command must work. The monotonic guard compares against
+ # the last COMMITTED version, not the value the failed run left on disk --
+ # otherwise the remediation both this script and validate-release-tag.mjs
+ # print is a dead end ("not greater than the current desktop version").
+ ( cd "$d" && node scripts/release/prepare-release.mjs --version 0.6.0 --release-id t >/dev/null 2>&1 )
+ local dv min; dv="$(manifest_field "$d" desktopVersion)"; min="$(manifest_field "$d" minimumDesktopVersion)"
+ if [ "$dv" = "0.6.0" ] && [ "$min" = "0.1.252" ]; then
+ pass "re-running a half-cut release completes it and leaves the floor alone"
+ else
+ fail "after re-run desktopVersion=$dv minimumDesktopVersion=$min; expected 0.6.0 / 0.1.252"
+ fi
+ rm -rf "$d"
+}
+
assert_floor_is_not_dragged_by_a_desktop_bump
assert_floor_above_desktop_is_rejected
assert_explicit_minimum_flag_is_honoured
@@ -610,6 +654,8 @@ assert_floor_non_semver_is_rejected_by_the_checker
assert_explicit_release_id_is_rejected_when_local_or_empty
assert_counter_mismatch_is_rejected_by_the_checker
assert_unhandled_assert_kind_fails_closed
+assert_floor_above_version_is_rejected_before_any_write
+assert_a_half_cut_release_can_be_completed_by_rerunning
assert_every_coordinate_has_a_case
assert_every_defined_case_is_invoked