Skip to content

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

TypeScript

fix(release): name every file the cut wrote in the half-cut recovery

Jose Ramirez168fe584aef2
diff --git a/scripts/release/prepare-release.mjs b/scripts/release/prepare-release.mjs
index d41228289..124b47112 100644
--- a/scripts/release/prepare-release.mjs
+++ b/scripts/release/prepare-release.mjs
@@ -7,7 +7,13 @@
// [--minimum-desktop-version 0.6.0]
import { execFileSync, execFileSync as run } from 'node:child_process'
import process from 'node:process'
-import { COORDINATES, SEMVER_RE, argValue, compareVersions } from './release-coordinates.mjs'
+import {
+ COORDINATES,
+ SEMVER_RE,
+ argValue,
+ compareVersions,
+ writtenCoordinatePaths,
+} from './release-coordinates.mjs'
const ROOT = process.cwd()
@@ -69,6 +75,16 @@ if (compareVersions(version, current) <= 0) {
die(`--version ${version} is not greater than the current desktop version ${current}`)
}
+// Resolved BEFORE the first write, so a coordinate table that cannot describe
+// what it is about to touch stops the cut instead of producing a half-cut tree
+// plus a recovery instruction that would not fully undo it.
+let writtenPaths
+try {
+ writtenPaths = writtenCoordinatePaths()
+} catch (error) {
+ die(error.message)
+}
+
for (const coordinate of COORDINATES) {
// Rows without a write are owned by the delegated updater below.
coordinate.write?.(ROOT, version)
@@ -85,14 +101,19 @@ if (minimumDesktopVersion) {
try {
execFileSync('node', manifestArgs, { cwd: ROOT, stdio: 'inherit' })
} catch (error) {
- // The coordinate loop above has already written package.json and the lockfile.
+ // The coordinate loop above has already written every path in writtenPaths.
// Say so, rather than leaving a raw stack trace and a half-written tree.
+ //
+ // The list is DERIVED from the coordinate table, not typed out here. The
+ // hardcoded version named the two desktop files and never learned about the
+ // ghcr pin, so following the discard command reverted the version and left
+ // the pin bumped -- still half-cut, by the command offered to un-cut it.
die(
- `The release cut wrote desktop-app/package.json and package-lock.json to ${version}, ` +
+ `The release cut wrote ${writtenPaths.join(', ')} 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\`.`
+ `or discard with \`git checkout -- ${writtenPaths.join(' ')}\`.`
)
}
diff --git a/scripts/release/release-coordinates.mjs b/scripts/release/release-coordinates.mjs
index 6a8fdb721..97f2858d0 100644
--- a/scripts/release/release-coordinates.mjs
+++ b/scripts/release/release-coordinates.mjs
@@ -95,9 +95,18 @@ function manifestField(root, field) {
// are written by update-desktop-release-manifest.mjs, which prepare-release
// delegates to rather than duplicating its renderer, so those rows declare
// `writtenBy` instead. The writer skips any row without a `write`.
+//
+// Every `write` row also carries `path`: the repo-relative file that write
+// touches. `name` cannot serve -- the ghcr row is named for the FIELD it pins
+// ('deploy/components/ghcr-images newTag'), not for a file. prepare-release.mjs
+// derives its half-cut recovery instruction from these paths, so a new writing
+// coordinate cannot be added without the recovery text learning about it. See
+// writtenCoordinatePaths() below, which fails loudly on a `write` row that
+// forgets its `path` rather than printing a short list that silently omits it.
export const COORDINATES = [
{
name: 'desktop-app/package.json',
+ path: 'desktop-app/package.json',
assert: 'equals',
read: root => readJson(root, 'desktop-app/package.json').version,
write: (root, version) => {
@@ -108,6 +117,7 @@ export const COORDINATES = [
},
{
name: 'desktop-app/package-lock.json',
+ path: 'desktop-app/package-lock.json',
assert: 'equals',
read: root => {
const j = readJson(root, 'desktop-app/package-lock.json')
@@ -157,6 +167,7 @@ export const COORDINATES = [
},
{
name: 'deploy/components/ghcr-images newTag',
+ path: GHCR_COMPONENT,
assert: 'pointer',
// Reads EVERY newTag, not just the first: a half-applied rewrite leaves
// mixed tags, and the puller would then fetch two different releases into
@@ -195,3 +206,26 @@ export const COORDINATES = [
export function readCounterPackage(root, rel) {
return readJson(root, rel).version
}
+
+// Every repo-relative file the coordinate loop in prepare-release.mjs writes.
+//
+// Derived, never listed by hand: the recovery instruction printed after a
+// half-cut release used a hardcoded `desktop-app/package.json
+// desktop-app/package-lock.json`, and when the ghcr pin became the eighth
+// coordinate the instruction kept naming two files out of three. Following it
+// verbatim reverted the version and left the pin bumped -- a tree that is still
+// half-cut, produced by the very command offered to un-cut it.
+//
+// A `write` row with no `path` throws instead of being skipped: a quietly
+// short list is exactly the failure this function exists to end.
+export function writtenCoordinatePaths() {
+ return COORDINATES.filter(c => c.write).map(c => {
+ if (!c.path) {
+ throw new Error(
+ `release-coordinates: coordinate '${c.name}' owns a write but declares no path, ` +
+ `so the half-cut recovery instruction would silently omit the file it wrote`
+ )
+ }
+ return c.path
+ })
+}
diff --git a/scripts/tests/test-release-coordinates.sh b/scripts/tests/test-release-coordinates.sh
index b2fc9a686..98aedbe08 100755
--- a/scripts/tests/test-release-coordinates.sh
+++ b/scripts/tests/test-release-coordinates.sh
@@ -838,6 +838,101 @@ assert_a_half_cut_release_can_be_completed_by_rerunning() {
rm -rf "$d"
}
+# ---------------------------------------------------------------------------
+# The half-cut recovery instruction
+# ---------------------------------------------------------------------------
+#
+# The message printed when the manifest update fails told the operator to
+# `git checkout -- desktop-app/package.json desktop-app/package-lock.json`.
+# The ghcr pin became the eighth coordinate and the writer started touching it,
+# but the instruction kept naming two files out of three: following it verbatim
+# reverted the version and left the pin bumped -- a tree still half-cut,
+# produced by the command offered to un-cut it.
+
+# Mutation coverage: hardcode the old two-file list back (the ghcr path
+# disappears from both the prose and the checkout command), or invert the
+# filter to `c => !c.write` (the checkout command names releaseManifest fields
+# that are not files at all). Both are caught -- the assertion pins the EXACT
+# path set the writer touches, in the checkout command specifically, not merely
+# "the string appears somewhere".
+assert_a_half_cut_release_names_every_file_the_writer_touched() {
+ local d out checkout_cmd problems=""
+ 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 the coordinate loop has written
+ # package.json, the lockfile and the ghcr component.
+ chmod -w "$d/external-rest-api/src/releaseManifest.ts"
+ out="$( cd "$d" && node scripts/release/prepare-release.mjs --version 0.6.0 --release-id t 2>&1 )"
+ chmod +w "$d/external-rest-api/src/releaseManifest.ts"
+
+ # The tree really is half-cut, or this case proves nothing about recovery.
+ local pin; pin="$(component_tags "$d")"
+ [ "$pin" = "v0.6.0 " ] || problems+="the ghcr pin was not written before the failure (tags: '${pin}'); "
+
+ checkout_cmd="$(grep -o 'git checkout -- [^`]*' <<< "$out")"
+ [ -n "$checkout_cmd" ] || problems+="no 'git checkout --' recovery command in the output; "
+ for f in desktop-app/package.json desktop-app/package-lock.json \
+ deploy/components/ghcr-images/kustomization.yaml; do
+ grep -q -- "$f" <<< "$checkout_cmd" || problems+="the discard command omits ${f}; "
+ done
+ # Every path it names must be a file the writer actually touched: a list that
+ # names releaseManifest fields would "contain" nothing useful to checkout.
+ for named in $checkout_cmd; do
+ case "$named" in
+ git | checkout | --) continue ;;
+ esac
+ [ -f "$d/$named" ] || problems+="the discard command names '${named}', which is not a file in the tree; "
+ done
+
+ if [ -z "$problems" ]; then
+ pass "a half-cut release's discard command names every file the writer touched, including the ghcr pin"
+ else
+ fail "$problems out=$out"
+ fi
+ rm -rf "$d"
+}
+
+# The list is derived from the coordinate table, so a future coordinate that
+# owns a write but forgets to declare its path must fail the cut LOUDLY rather
+# than reintroduce a silently short recovery list.
+#
+# Mutation coverage: turn the throw in writtenCoordinatePaths() into a
+# `return ''`/skip and this case sees a successful cut instead of a refusal;
+# move the resolution after the coordinate loop and the tree is half-written
+# when it dies, which the package.json assertion below catches.
+assert_a_write_coordinate_without_a_path_stops_the_cut_before_any_write() {
+ local d out rc pkg problems=""
+ 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"
+
+ # A ninth coordinate that writes a file and never says which one.
+ cat >> "$d/scripts/release/release-coordinates.mjs" <<'EOF'
+
+COORDINATES.push({
+ name: 'test-only/undeclared-path',
+ assert: 'equals',
+ read: () => '',
+ write: () => {},
+})
+EOF
+
+ out="$( cd "$d" && node scripts/release/prepare-release.mjs --version 0.6.0 --release-id t 2>&1 )"; rc=$?
+ pkg="$(node -e 'console.log(require(process.argv[1]).version)' "$d/desktop-app/package.json")"
+ [ "$rc" -ne 0 ] || problems+="the cut succeeded despite a write coordinate with no path; "
+ grep -q 'test-only/undeclared-path' <<< "$out" || problems+="the refusal does not name the offending coordinate: ${out}; "
+ [ "$pkg" = "0.5.0" ] || problems+="desktop-app/package.json was written to ${pkg} before the refusal; "
+
+ if [ -z "$problems" ]; then
+ pass "a write coordinate with no declared path stops the cut, by name, before anything is written"
+ else
+ fail "$problems"
+ 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
@@ -868,6 +963,8 @@ assert_the_pointer_check_does_not_require_the_artifact_to_exist
assert_a_mixed_tag_component_is_rejected
assert_prepare_release_fails_loudly_when_no_row_can_be_written
assert_a_component_with_no_rows_is_rejected
+assert_a_half_cut_release_names_every_file_the_writer_touched
+assert_a_write_coordinate_without_a_path_stops_the_cut_before_any_write
assert_every_coordinate_has_a_case
assert_every_defined_case_is_invoked