Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(precommit): keep the release manifest in sync with the counters
Jose Ramirez9ad1562dd8d6
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex 937f68de3..3e478bd8f 100644--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@ -8,8 +8,8 @@ export type ReleaseManifest = {export const releaseManifest: ReleaseManifest = {releaseId: 'master-440d8e0',- externalRestApiVersion: '0.1.56',- rpcProxyVersion: '0.1.36',+ externalRestApiVersion: '0.1.60',+ rpcProxyVersion: '0.1.51',desktopVersion: '0.1.252',minimumDesktopVersion: '0.1.252',}diff --git a/scripts/precommit/bump-staged-package-versions.mjs b/scripts/precommit/bump-staged-package-versions.mjsindex d27fcb394..7a6f2d7c9 100644--- a/scripts/precommit/bump-staged-package-versions.mjs+++ b/scripts/precommit/bump-staged-package-versions.mjs@@ -9,6 +9,27 @@ import { packageRoots } from '../prettier/paths.mjs'const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..')const sortedPackageRoots = [...packageRoots].sort((a, b) => b.length - a.length)+// Files that live inside a package root but must never trigger its counter.+// releaseManifest.ts declares the versions this script would bump. A later+// task adds scripts/release/prepare-release.mjs as the writer of this file;+// bumping external-rest-api in reaction to that write would make the+// manifest stale the instant it is produced. validate-release-version-bumps.mjs+// carries the identical exemption in its ignoredFiles.+const IGNORED_FILES = ['external-rest-api/src/releaseManifest.ts']++// Packages whose version releaseManifest.ts declares, and the manifest field+// each maps to. Bumping one of these without updating the manifest makes+// --validate-only throw on the next CI run, which would redden every PR+// touching these services. desktop-app is deliberately absent: it is not in+// packageRoots (this hook never bumps it), and desktopVersion is synced by a+// separate desktop release flow, not by this pre-commit hook.+const MANIFEST_PATH = 'external-rest-api/src/releaseManifest.ts'+const MANIFEST_FIELD_BY_PACKAGE = {+ 'external-rest-api': 'externalRestApiVersion',+ 'rpc-proxy': 'rpcProxyVersion',+}+const MANIFEST_COUNTER_PACKAGES = Object.keys(MANIFEST_FIELD_BY_PACKAGE)+function exitWithError(message, status = 1) {console.error(message)process.exit(status)@@ -78,6 +99,34 @@ function bumpPatchVersion(version) {return `${major}.${minor}.${Number(patch) + 1}${prerelease}${build}`}+function readManifestField(source, field) {+ const match = source.match(new RegExp(`\\n {2}${field}: '([^']*)'`))+ return match ? match[1] : null+}++// Reads a counter package's version out of the INDEX (git's staged content),+// not the working tree. Only what's staged is what a commit actually records;+// a disk read here would let an unstaged, never-to-be-committed edit decide+// whether the manifest gets re-synced, and what value it gets re-synced to.+function readIndexedPackageVersion(pkg) {+ const packageJsonPath = `${pkg}/package.json`+ const result = run('git', ['show', `:${packageJsonPath}`])++ if (result.status !== 0) {+ return null+ }++ try {+ return JSON.parse(result.stdout).version ?? null+ } catch (error) {+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) could not parse ` ++ `the staged ${packageJsonPath} to check whether ${MANIFEST_PATH} needs re-syncing: ${error.message}\n` ++ `Fix ${packageJsonPath} (e.g. resolve merge conflict markers) and re-stage it, then retry the commit.`+ )+ }+}+const stagedFilesResult = run('git', ['diff', '--cached', '--name-only', '--diff-filter=ACMR'])if (stagedFilesResult.status !== 0) {@@ -93,6 +142,7 @@ const affectedPackages = [.split(/\r?\n/).map(file => file.trim()).filter(Boolean)+ .filter(file => !IGNORED_FILES.includes(file)).map(getPackageRootForFile).filter(Boolean)),@@ -164,3 +214,122 @@ for (const packageRoot of affectedPackages) {console.log(`${packageJsonPath}: ${headPackage.version} -> ${currentPackage.version}`)}++// Re-sync the manifest whenever a counter it declares has drifted from the+// package.json it tracks -- not only when this run performed the bump. A+// bump that lands in one pre-commit invocation and a re-sync that then fails+// (bad manifest, missing floor, ...) must still converge on a retry. Keying+// this off "does the manifest currently disagree with disk" rather than off+// which packages this run happened to bump makes the retry path self-healing+// instead of a bump that permanently disarms its own re-sync: on retry the+// bumped package.json no longer equals HEAD, so the bump loop above skips it+// via the currentPackage.version !== headPackage.version check, and a+// bumpedPackages-style flag would stay empty forever.+const manifestAbsolutePath = join(repoRoot, MANIFEST_PATH)+const relevantCounterPackages = MANIFEST_COUNTER_PACKAGES.filter(pkg =>+ existsSync(join(repoRoot, `${pkg}/package.json`))+)++if (relevantCounterPackages.length > 0) {+ // Checked BEFORE the manifest is read for drift purposes, not just before+ // the re-sync runs. The manifest read below feeds the "is anything out of+ // sync" decision itself (it reads the working tree, same as the file this+ // guard inspects); a dirty manifest that happens to already read as+ // in-sync would make outOfSyncPackages empty and skip the refusal+ // entirely if it lived inside that branch, silently committing a+ // package.json bump alongside a manifest that was never staged to match+ // it. Moving the check up here means a dirty manifest can never influence+ // the decision -- it always blocks first.+ if (hasUnstagedChanges(MANIFEST_PATH)) {+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) is refusing to ` ++ `auto-sync ${MANIFEST_PATH} because it has unstaged changes. Stage or discard them first.`+ )+ }++ let manifestSource++ try {+ manifestSource = readFileSync(manifestAbsolutePath, 'utf8')+ } catch (error) {+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) could not read ` ++ `${MANIFEST_PATH} to check whether it needs re-syncing after a version bump: ${error.message}\n` ++ `Restore the file (e.g. \`git checkout HEAD -- ${MANIFEST_PATH}\`) or regenerate it with ` ++ `\`node scripts/release/update-desktop-release-manifest.mjs\`, then retry the commit.`+ )+ }++ const outOfSyncPackages = relevantCounterPackages.filter(pkg => {+ const currentVersion = readIndexedPackageVersion(pkg)+ const manifestVersion = readManifestField(manifestSource, MANIFEST_FIELD_BY_PACKAGE[pkg])+ return currentVersion && currentVersion !== manifestVersion+ })++ if (outOfSyncPackages.length > 0) {+ // The updater re-reads every counter package's package.json from disk on+ // each invocation, not just the one that triggered this re-sync (absent+ // --previous it always treats every counter field as changed). An+ // unrelated unstaged edit anywhere in MANIFEST_COUNTER_PACKAGES would+ // therefore leak an uncommitted version into the manifest we are about+ // to stage, even though it correctly did not trigger this re-sync itself.+ for (const pkg of relevantCounterPackages) {+ const trackedPackageJsonPath = `${pkg}/package.json`+ if (hasUnstagedChanges(trackedPackageJsonPath)) {+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) is refusing to ` ++ `re-sync ${MANIFEST_PATH} because ${trackedPackageJsonPath} has unstaged changes. The ` ++ `updater reads every counter package.json from disk, so an unrelated unstaged edit would ` ++ `leak an uncommitted version into the manifest. Stage or discard them first.`+ )+ }+ }++ // The updater defaults releaseId to the literal 'local' when --release-id+ // is absent, which would ship in a customer-facing manifest. Carry the+ // existing value through instead of fabricating one: a counter bump is+ // not a release.+ const releaseId = readManifestField(manifestSource, 'releaseId')++ if (!releaseId) {+ exitWithError(+ `Could not read a releaseId out of ${MANIFEST_PATH} to preserve during the pre-commit ` ++ `re-sync. Refusing to fabricate one -- the updater defaults to 'local' when --release-id ` ++ `is omitted, and that must never land in a customer-facing manifest. Fix the releaseId ` ++ `field in ${MANIFEST_PATH} and retry the commit.`+ )+ }++ const resync = run('node', [+ 'scripts/release/update-desktop-release-manifest.mjs',+ '--release-id',+ releaseId,+ // This re-sync only ever moves the external-rest-api/rpc-proxy+ // counters, never a desktop release. Without --defer-desktop-release+ // the updater also copies desktop-app/package.json's version into+ // desktopVersion, which would publish an unreleased desktop build to+ // every client polling the manifest off the back of an ordinary+ // service PR. The "never use this flag" rule is narrower than it+ // sounds: it forbids using the flag to silence a --validate-only+ // failure, not this re-sync, where leaving desktopVersion untouched is+ // the entire point -- a counter bump is not a desktop release.+ '--defer-desktop-release',+ ])++ if (resync.status !== 0) {+ const detail = (resync.stderr || '').trim()+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) could not ` ++ `re-sync ${MANIFEST_PATH} via scripts/release/update-desktop-release-manifest.mjs after ` ++ `${outOfSyncPackages.join(', ')} moved. Resolve the issue below, then either fix ` ++ `${MANIFEST_PATH} directly or run the updater manually with the flags it needs (e.g. ` ++ `--minimum-desktop-version) and \`git add ${MANIFEST_PATH}\` before retrying the commit.` ++ (detail ? `\n\nUnderlying error:\n${detail}` : ''),+ resync.status+ )+ }++ stageFile(MANIFEST_PATH)+ console.log(`${MANIFEST_PATH}: re-synced after ${outOfSyncPackages.join(', ')}`)+ }+}diff --git a/scripts/tests/test-precommit-release-manifest-ignore.sh b/scripts/tests/test-precommit-release-manifest-ignore.shnew file mode 100755index 000000000..604b19bb2--- /dev/null+++ b/scripts/tests/test-precommit-release-manifest-ignore.sh@@ -0,0 +1,504 @@+#!/usr/bin/env bash+set -u+FAIL=0++# The precommit bumper must ignore external-rest-api/src/releaseManifest.ts.+# A later task adds scripts/release/prepare-release.mjs as that file's writer;+# if staging it bumps external-rest-api/package.json, the manifest is stale+# the instant it is written and --validate-only fails on every release-prep+# PR, forever.+#+# It must also keep the manifest's own counters (externalRestApiVersion,+# rpcProxyVersion) in sync with the package.json versions it bumps, without+# ever touching desktopVersion (that's a separate release flow), without+# fabricating a releaseId, without clobbering a contributor's unstaged+# manifest edit, and without permanently disarming itself if a re-sync fails+# partway through.++REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"++pass() { echo "PASS: $1"; }+fail() { echo "FAIL: $1"; FAIL=1; }++# desktop-app/package.json is deliberately set ABOVE the manifest's+# desktopVersion (0.1.333 vs 0.1.252). desktop-app is not in packageRoots (this+# hook never bumps it) and is not a MANIFEST_COUNTER_PACKAGES entry, so a+# fixture that pinned them equal would be structurally incapable of catching+# a re-sync that wrongly published desktopVersion from desktop-app/package.json.+make_repo() {+ local d=$1+ mkdir -p "$d/external-rest-api/src" "$d/rpc-proxy/src" "$d/desktop-app" "$d/scripts/precommit" "$d/scripts/prettier" "$d/scripts/release"+ cp "$REPO_ROOT/scripts/precommit/bump-staged-package-versions.mjs" "$d/scripts/precommit/"+ cp "$REPO_ROOT/scripts/prettier/paths.mjs" "$d/scripts/prettier/"+ cp "$REPO_ROOT/scripts/release/update-desktop-release-manifest.mjs" "$d/scripts/release/"+ printf '{\n "name": "external-rest-api",\n "version": "0.1.60"\n}\n' \+ > "$d/external-rest-api/package.json"+ printf '{\n "name": "rpc-proxy",\n "version": "0.1.51"\n}\n' \+ > "$d/rpc-proxy/package.json"+ printf '{\n "name": "desktop-app",\n "version": "0.1.333"\n}\n' \+ > "$d/desktop-app/package.json"+ cat > "$d/external-rest-api/src/releaseManifest.ts" <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ releaseId: 'fixture-0000000',+ externalRestApiVersion: '0.1.60',+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ echo "export const x = 1" > "$d/external-rest-api/src/other.ts"+ echo "export const y = 1" > "$d/rpc-proxy/src/other.ts"+ ( cd "$d" && git init -q . && git add -A && git -c user.email=t@t -c user.name=t commit -qm init )+}++version_of() { grep '"version"' "$1/external-rest-api/package.json" | sed 's/.*: "\(.*\)".*/\1/'; }+rpc_version_of() { grep '"version"' "$1/rpc-proxy/package.json" | sed 's/.*: "\(.*\)".*/\1/'; }+manifest_field() {+ # $1=dir $2=field name+ grep -E "^ $2: '" "$1/external-rest-api/src/releaseManifest.ts" | sed "s/.*'\(.*\)'.*/\1/"+}++assert_release_manifest_does_not_bump() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" \+ && echo "export const releaseManifest = { desktopVersion: '0.5.0' }" \+ > external-rest-api/src/releaseManifest.ts \+ && git add external-rest-api/src/releaseManifest.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ if [ "$(version_of "$d")" = "0.1.60" ]; then+ pass "staging releaseManifest.ts does not bump external-rest-api"+ else+ fail "releaseManifest.ts bumped external-rest-api to $(version_of "$d")"+ fi+ rm -rf "$d"+}++assert_other_source_still_bumps() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" \+ && echo "export const x = 2" > external-rest-api/src/other.ts \+ && git add external-rest-api/src/other.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ if [ "$(version_of "$d")" = "0.1.61" ]; then+ pass "an ordinary external-rest-api source change still bumps"+ else+ fail "expected 0.1.61 after an ordinary change, got $(version_of "$d")"+ fi+ rm -rf "$d"+}++assert_a_counter_bump_resyncs_the_manifest() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" \+ && echo "export const x = 2" > external-rest-api/src/other.ts \+ && git add external-rest-api/src/other.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )++ local manifest_ers staged+ manifest_ers="$(manifest_field "$d" externalRestApiVersion)"+ staged="$(cd "$d" && git diff --cached --name-only | grep -c releaseManifest.ts)"++ if [ "$manifest_ers" = "0.1.61" ] && [ "$staged" = "1" ]; then+ pass "a counter bump re-syncs the manifest and stages it"+ else+ fail "manifest externalRestApiVersion=$manifest_ers staged=$staged, expected 0.1.61 / 1"+ fi+ rm -rf "$d"+}++assert_rpc_proxy_bump_resyncs_the_manifest() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" \+ && echo "export const y = 2" > rpc-proxy/src/other.ts \+ && git add rpc-proxy/src/other.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )++ local pkg_rpc manifest_rpc+ pkg_rpc="$(rpc_version_of "$d")"+ manifest_rpc="$(manifest_field "$d" rpcProxyVersion)"++ if [ "$pkg_rpc" = "0.1.52" ] && [ "$manifest_rpc" = "0.1.52" ]; then+ pass "an rpc-proxy bump also re-syncs the manifest"+ else+ fail "rpc-proxy/package.json=$pkg_rpc manifest rpcProxyVersion=$manifest_rpc, expected 0.1.52 / 0.1.52"+ fi+ rm -rf "$d"+}++assert_desktop_version_not_touched_by_counter_resync() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ local status+ ( cd "$d" \+ && echo "export const x = 2" > external-rest-api/src/other.ts \+ && git add external-rest-api/src/other.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status=$?++ local manifest_desktop manifest_ers+ manifest_desktop="$(manifest_field "$d" desktopVersion)"+ manifest_ers="$(manifest_field "$d" externalRestApiVersion)"++ # Assert the re-sync actually ran and succeeded (exit 0, ers moved), not+ # just that desktopVersion happens to be untouched -- a dead hook, or one+ # missing --defer-desktop-release entirely (which makes the updater's own+ # validate() reject 0.1.252 != 0.1.333 and exit nonzero), would ALSO leave+ # desktopVersion untouched, but only because the re-sync never completed.+ if [ "$status" -eq 0 ] && [ "$manifest_ers" = "0.1.61" ] && [ "$manifest_desktop" = "0.1.252" ]; then+ pass "a counter re-sync succeeds and never touches desktopVersion, even though desktop-app/package.json is ahead"+ else+ fail "status=$status externalRestApiVersion=$manifest_ers desktopVersion=$manifest_desktop; expected 0 / 0.1.61 / 0.1.252"+ fi+ rm -rf "$d"+}++assert_resync_preserves_the_release_id() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" \+ && echo "export const x = 3" > external-rest-api/src/other.ts \+ && git add external-rest-api/src/other.ts \+ && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ local rid ers+ rid="$(manifest_field "$d" releaseId)"+ ers="$(manifest_field "$d" externalRestApiVersion)"+ # Also assert the counter actually moved, so this case can't pass simply+ # because the re-sync never ran at all.+ if [ "$rid" = "fixture-0000000" ] && [ "$ers" = "0.1.61" ]; then+ pass "the re-sync preserves releaseId instead of stamping 'local'"+ else+ fail "releaseId='$rid' externalRestApiVersion=$ers; the updater defaults releaseId to 'local' when --release-id is omitted"+ fi+ rm -rf "$d"+}++assert_unstaged_manifest_changes_block_the_resync() {+ local d; d="$(mktemp -d)"; make_repo "$d"++ # Edit the manifest on disk WITHOUT staging it -- a contributor's scratch+ # edit -- then trigger a counter bump that would otherwise re-sync it.+ (+ cd "$d" || exit 1+ cat > external-rest-api/src/releaseManifest.ts <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ releaseId: 'UNSTAGED-SCRATCH',+ externalRestApiVersion: '0.1.60',+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ )+ ( cd "$d" && echo "export const x = 2" > external-rest-api/src/other.ts && git add external-rest-api/src/other.ts )++ local status stderr_output+ stderr_output="$( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs 2>&1 >/dev/null )"+ status=$?++ local rid staged+ rid="$(manifest_field "$d" releaseId)"+ staged="$(cd "$d" && git diff --cached --name-only | grep -c releaseManifest.ts)"++ # Assert on the refusal MESSAGE, not just a nonzero exit code -- any other+ # unrelated failure would also exit nonzero and leave the manifest+ # untouched, which would let this case pass for the wrong reason.+ if [ "$status" -ne 0 ] && [ "$rid" = "UNSTAGED-SCRATCH" ] && [ "$staged" = "0" ] \+ && echo "$stderr_output" | grep -q "unstaged changes"; then+ pass "an unstaged manifest edit blocks the re-sync with a refusal message, instead of being silently committed"+ else+ fail "expected nonzero exit + refusal message + untouched + unstaged manifest; got status=$status releaseId='$rid' staged=$staged stderr='$stderr_output'"+ fi+ rm -rf "$d"+}++assert_a_failed_resync_recovers_on_retry() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ ( cd "$d" && echo "export const x = 2" > external-rest-api/src/other.ts && git add external-rest-api/src/other.ts )++ # Corrupt the manifest with conflict markers and STAGE the corruption, so+ # the bump loop still runs cleanly (no unstaged-changes refusal) but the+ # re-sync subprocess's own JSON.parse fails.+ (+ cd "$d" || exit 1+ cat > external-rest-api/src/releaseManifest.ts <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ releaseId: 'fixture-0000000',+<<<<<<< HEAD+ externalRestApiVersion: '0.1.60',+=======+ externalRestApiVersion: '0.1.99',+>>>>>>> feature+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ git add external-rest-api/src/releaseManifest.ts+ )++ local status1 ers_after_run1+ ( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status1=$?+ ers_after_run1="$(version_of "$d")"++ # Resolve the "conflict": restore a valid, still-stale manifest and stage it.+ (+ cd "$d" || exit 1+ cat > external-rest-api/src/releaseManifest.ts <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ releaseId: 'fixture-0000000',+ externalRestApiVersion: '0.1.60',+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ git add external-rest-api/src/releaseManifest.ts+ )++ local status2 ers_field_after_retry+ ( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status2=$?+ ers_field_after_retry="$(manifest_field "$d" externalRestApiVersion)"++ if [ "$status1" -ne 0 ] && [ "$ers_after_run1" = "0.1.61" ] && [ "$status2" -eq 0 ] && [ "$ers_field_after_retry" = "0.1.61" ]; then+ pass "a failed re-sync recovers on retry instead of permanently disarming itself"+ else+ fail "run1 status=$status1 package=$ers_after_run1; run2 status=$status2 manifest=$ers_field_after_retry"+ fi+ rm -rf "$d"+}++assert_missing_release_id_is_refused_not_fabricated() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ (+ cd "$d" || exit 1+ cat > external-rest-api/src/releaseManifest.ts <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ externalRestApiVersion: '0.1.60',+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ git add external-rest-api/src/releaseManifest.ts+ git -c user.email=t@t -c user.name=t commit -qm "drop releaseId"+ )+ ( cd "$d" && echo "export const x = 2" > external-rest-api/src/other.ts && git add external-rest-api/src/other.ts )++ local status+ ( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status=$?++ if [ "$status" -ne 0 ] && ! grep -q "'local'" "$d/external-rest-api/src/releaseManifest.ts"; then+ pass "a missing releaseId is refused instead of fabricated as 'local'"+ else+ fail "expected nonzero exit and no fabricated 'local' releaseId; got status=$status, manifest: $(tr '\n' ' ' < "$d/external-rest-api/src/releaseManifest.ts")"+ fi+ rm -rf "$d"+}++assert_unstaged_package_json_drift_is_not_leaked_into_the_manifest() {+ local d; d="$(mktemp -d)"; make_repo "$d"++ # Edit external-rest-api/package.json on disk WITHOUT staging it, then make+ # an entirely unrelated staged commit (docs-only). Nothing about this commit+ # legitimately touches external-rest-api or rpc-proxy, so the manifest must+ # come out exactly as committed before -- reading disk here (instead of the+ # index) would falsely report drift and leak the never-to-be-committed+ # 0.9.99 into the manifest.+ ( cd "$d" && printf '{\n "name": "external-rest-api",\n "version": "0.9.99"\n}\n' > external-rest-api/package.json )+ ( cd "$d" && mkdir -p docs && echo "# docs" > docs/readme.md && git add docs/readme.md )++ local status+ ( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status=$?++ local manifest_ers staged+ manifest_ers="$(manifest_field "$d" externalRestApiVersion)"+ staged="$(cd "$d" && git diff --cached --name-only | grep -c releaseManifest.ts)"++ if [ "$status" -eq 0 ] && [ "$manifest_ers" = "0.1.60" ] && [ "$staged" = "0" ]; then+ pass "an unstaged package.json edit is not read for drift detection (index, not disk)"+ else+ fail "status=$status manifest externalRestApiVersion=$manifest_ers staged=$staged; an unstaged 0.9.99 on disk must not leak into a committed manifest"+ fi+ rm -rf "$d"+}++assert_unrelated_unstaged_package_json_blocks_a_real_resync() {+ local d; d="$(mktemp -d)"; make_repo "$d"++ # rpc-proxy gets a legitimate, staged bump -- a real trigger for the+ # re-sync -- while external-rest-api/package.json has an unrelated UNSTAGED+ # edit. The updater re-reads every counter package.json from disk on every+ # invocation (not just the one that triggered it), so without a guard this+ # would leak the unstaged 0.9.99 into the manifest via a resync that had a+ # legitimate reason to run.+ ( cd "$d" && echo "export const y = 2" > rpc-proxy/src/other.ts && git add rpc-proxy/src/other.ts )+ ( cd "$d" && printf '{\n "name": "external-rest-api",\n "version": "0.9.99"\n}\n' > external-rest-api/package.json )++ local status+ ( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )+ status=$?++ local manifest_ers staged+ manifest_ers="$(manifest_field "$d" externalRestApiVersion)"+ staged="$(cd "$d" && git diff --cached --name-only | grep -c releaseManifest.ts)"++ if [ "$status" -ne 0 ] && [ "$manifest_ers" = "0.1.60" ] && [ "$staged" = "0" ]; then+ pass "a real resync (triggered by rpc-proxy) refuses to run while an unrelated counter package.json has unstaged changes"+ else+ fail "status=$status manifest externalRestApiVersion=$manifest_ers staged=$staged; unstaged 0.9.99 must not leak via a resync triggered by a different package"+ fi+ rm -rf "$d"+}++assert_a_self_concealing_manifest_edit_cannot_suppress_the_resync() {+ local d; d="$(mktemp -d)"; make_repo "$d"++ # Trigger a REAL counter bump (ers 0.1.60 -> 0.1.61 gets staged by the loop)...+ ( cd "$d" && echo "export const x = 2" > external-rest-api/src/other.ts && git add external-rest-api/src/other.ts )++ # ...then, BEFORE running the hook, hand-edit the manifest ON DISK (never+ # staged) so its externalRestApiVersion already reads '0.1.61' -- the value+ # package.json is about to become. A disk-based drift check would see+ # currentVersion === manifestVersion and conclude nothing is out of sync,+ # even though the manifest that will actually be COMMITTED (the index,+ # still '0.1.60') was never touched. That's the self-concealing case: the+ # dirty file's content happens to make the drift check stay silent.+ (+ cd "$d" || exit 1+ cat > external-rest-api/src/releaseManifest.ts <<'EOF'+export type ReleaseManifest = {+ releaseId: string+ externalRestApiVersion: string+ rpcProxyVersion: string+ desktopVersion: string+ minimumDesktopVersion: string+}++export const releaseManifest: ReleaseManifest = {+ releaseId: 'fixture-0000000',+ externalRestApiVersion: '0.1.61',+ rpcProxyVersion: '0.1.51',+ desktopVersion: '0.1.252',+ minimumDesktopVersion: '0.1.252',+}+EOF+ )++ local status stderr_output+ stderr_output="$( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs 2>&1 >/dev/null )"+ status=$?++ local staged committed_ers+ staged="$(cd "$d" && git diff --cached --name-only | grep -c releaseManifest.ts)"+ committed_ers="$(cd "$d" && git show :external-rest-api/src/releaseManifest.ts 2>/dev/null | grep -E "^ externalRestApiVersion: '" | sed "s/.*'\(.*\)'.*/\1/")"++ # Must refuse (nonzero exit, refusal message) precisely BECAUSE the+ # unstaged-changes check now runs before the drift read can be fooled by+ # it -- not just "the manifest wasn't staged", which is also true of a+ # silent, broken success.+ if [ "$status" -ne 0 ] && [ "$staged" = "0" ] && [ "$committed_ers" = "0.1.60" ] \+ && echo "$stderr_output" | grep -q "unstaged changes"; then+ pass "an unstaged manifest edit that happens to already match disk cannot suppress the re-sync"+ else+ fail "expected refusal; got status=$status staged=$staged committed externalRestApiVersion=$committed_ers stderr='$stderr_output'"+ fi+ rm -rf "$d"+}++assert_a_corrupted_committed_package_json_is_refused_not_crashed() {+ local d; d="$(mktemp -d)"; make_repo "$d"++ # Simulate a package.json that slipped through with conflict markers still+ # in it (e.g. a bypassed hook, or a force-committed unresolved merge) --+ # already COMMITTED, not staged in THIS run, so the ordinary bump loop+ # (which only processes staged files) never touches it. The only code path+ # that reads it here is the drift check's readIndexedPackageVersion.+ (+ cd "$d" || exit 1+ cat > external-rest-api/package.json <<'EOF'+{+ "name": "external-rest-api",+<<<<<<< HEAD+ "version": "0.1.60"+=======+ "version": "0.1.61"+>>>>>>> feature+}+EOF+ git add external-rest-api/package.json+ git -c user.email=t@t -c user.name=t commit -qm "corrupt external-rest-api/package.json"+ )++ # An entirely unrelated, legitimate trigger for the drift check to run at all.+ ( cd "$d" && echo "export const y = 2" > rpc-proxy/src/other.ts && git add rpc-proxy/src/other.ts )++ local status stderr_output+ stderr_output="$( cd "$d" && node scripts/precommit/bump-staged-package-versions.mjs 2>&1 >/dev/null )"+ status=$?++ if [ "$status" -ne 0 ] && ! echo "$stderr_output" | grep -q "SyntaxError" \+ && echo "$stderr_output" | grep -q "external-rest-api/package.json"; then+ pass "a corrupted counter package.json is refused with a named message, not a raw parse-crash stack trace"+ else+ fail "expected nonzero exit naming external-rest-api/package.json with no raw SyntaxError; got status=$status stderr='$stderr_output'"+ fi+ rm -rf "$d"+}++assert_release_manifest_does_not_bump+assert_other_source_still_bumps+assert_a_counter_bump_resyncs_the_manifest+assert_rpc_proxy_bump_resyncs_the_manifest+assert_desktop_version_not_touched_by_counter_resync+assert_resync_preserves_the_release_id+assert_unstaged_manifest_changes_block_the_resync+assert_a_failed_resync_recovers_on_retry+assert_missing_release_id_is_refused_not_fabricated+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++exit $FAILdiff --git a/scripts/tests/test-release-coordinates.sh b/scripts/tests/test-release-coordinates.shindex e4b3def3e..d1d4ed10d 100755--- a/scripts/tests/test-release-coordinates.sh+++ b/scripts/tests/test-release-coordinates.sh@@ -4,7 +4,7 @@ FAIL=0# Tests for the release-cut scripts:# scripts/release/update-desktop-release-manifest.mjs (floor decoupling)-# scripts/release/prepare-release.mjs (the one writer)+# scripts/release/prepare-release.mjs (the one writer, added by a later task)# scripts/release/validate-release-tag.mjs (the checker)## Each case builds a throwaway git repo containing only the files the script