Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(release): fail closed on unhandled assert kinds, dedupe the parser
Jose Ramireza2a6c1e71c53
diff --git a/scripts/precommit/bump-staged-package-versions.mjs b/scripts/precommit/bump-staged-package-versions.mjsindex 7a6f2d7c9..d71a67e08 100644--- a/scripts/precommit/bump-staged-package-versions.mjs+++ b/scripts/precommit/bump-staged-package-versions.mjs@@ -5,6 +5,7 @@ import { dirname, join, resolve } from 'node:path'import process from 'node:process'import { fileURLToPath } from 'node:url'import { packageRoots } from '../prettier/paths.mjs'+import { parseManifest } from '../release/release-coordinates.mjs'const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), '../..')const sortedPackageRoots = [...packageRoots].sort((a, b) => b.length - a.length)@@ -99,11 +100,6 @@ 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@@ -260,9 +256,22 @@ if (relevantCounterPackages.length > 0) {)}+ let manifest++ try {+ manifest = parseManifest(manifestSource)+ } catch (error) {+ exitWithError(+ `The pre-commit hook (scripts/precommit/bump-staged-package-versions.mjs) could not parse ` ++ `${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])+ const manifestVersion = manifest ? manifest[MANIFEST_FIELD_BY_PACKAGE[pkg]] : undefinedreturn currentVersion && currentVersion !== manifestVersion})@@ -289,7 +298,7 @@ if (relevantCounterPackages.length > 0) {// 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')+ const releaseId = manifest ? manifest.releaseId : undefinedif (!releaseId) {exitWithError(diff --git a/scripts/release/release-coordinates.mjs b/scripts/release/release-coordinates.mjsindex 22cca1ae7..b3ad84d37 100644--- a/scripts/release/release-coordinates.mjs+++ b/scripts/release/release-coordinates.mjs@@ -1,4 +1,3 @@-#!/usr/bin/env node// The release coordinates: every place in the tree that must agree with the// release tag. One writer (prepare-release.mjs) and one checker// (validate-release-tag.mjs) both import this list, so a coordinate cannot be@@ -9,10 +8,11 @@// equals - must equal the release version (build inputs, declarations)// floor - a compatibility floor; must be <= the version, moves only on request// counter - a per-service counter; must equal ITS OWN package.json, not the version-// pointer - names an artifact; equality here, existence checked by release-images.yml+// pointer - names an artifact; equality here, plus existence checking once a+// release-images.yml workflow exists (it does not exist in this repo yet)//-// Workstream D appends the ghcr component pointer row. Do not add it before-// deploy/components/ghcr-images/kustomization.yaml exists.+// A future workstream would append the ghcr component pointer row. Do not add+// it before deploy/components/ghcr-images/kustomization.yaml exists.import fs from 'node:fs'import path from 'node:path'diff --git a/scripts/release/update-desktop-release-manifest.mjs b/scripts/release/update-desktop-release-manifest.mjsindex e3c1a1b2b..39ba85e13 100644--- a/scripts/release/update-desktop-release-manifest.mjs+++ b/scripts/release/update-desktop-release-manifest.mjs@@ -74,7 +74,8 @@ function renderManifest(manifest) {export const releaseManifest: ReleaseManifest = ${JSON.stringify(manifest, null, 2).replace(/"([^"]+)":/g, '$1:')- .replace(/: "([^"]*)"/g, ": '$1'")}+ .replace(/: "([^"]*)"/g, ": '$1'")+ .replace(/\n}$/, ',\n}')}`}@@ -99,98 +100,116 @@ function validate(manifest, versions, options = {}) {}}-const previousRef = argValue('--previous')-const releaseId = argValue('--release-id') || 'local'-const minimumDesktopVersion = argValue('--minimum-desktop-version')-const validateOnly = process.argv.includes('--validate-only')-const deferDesktopRelease = process.argv.includes('--defer-desktop-release')--const versions = currentVersions()-const manifestAtHead = currentManifest()-if (validateOnly) {- if (!manifestAtHead) {- throw new Error(`${MANIFEST_PATH} does not contain a releaseManifest export`)+function main() {+ const previousRef = argValue('--previous')+ const releaseId = argValue('--release-id') || 'local'+ const minimumDesktopVersion = argValue('--minimum-desktop-version')+ const validateOnly = process.argv.includes('--validate-only')+ const deferDesktopRelease = process.argv.includes('--defer-desktop-release')++ const versions = currentVersions()+ const manifestAtHead = currentManifest()+ if (validateOnly) {+ if (!manifestAtHead) {+ throw new Error(`${MANIFEST_PATH} does not contain a releaseManifest export`)+ }+ validate(manifestAtHead, versions, { deferDesktopRelease })+ console.log(JSON.stringify(manifestAtHead, null, 2))+ process.exit(0)}- validate(manifestAtHead, versions, { deferDesktopRelease })- console.log(JSON.stringify(manifestAtHead, null, 2))- process.exit(0)-}-let previous = previousManifest(previousRef)+ let previous = previousManifest(previousRef)-// HEAD's floor always outranks one read via --previous: HEAD reflects the-// most recent operator decision. Never synthesize a floor from-// desktopVersion -- if nothing readable carries a floor, the operator must-// say so explicitly.-const inherited = manifestAtHead?.minimumDesktopVersion || previous?.minimumDesktopVersion+ // HEAD's floor always outranks one read via --previous: HEAD reflects the+ // most recent operator decision. Never synthesize a floor from+ // desktopVersion -- if nothing readable carries a floor, the operator must+ // say so explicitly.+ const inherited = manifestAtHead?.minimumDesktopVersion || previous?.minimumDesktopVersion-if (!inherited && !minimumDesktopVersion) {- throw new Error(- 'no minimumDesktopVersion could be read; pass ' +- '--minimum-desktop-version explicitly rather than ' +- 'defaulting it to desktopVersion'- )-}--if (!previous) {- previous = {- releaseId,- externalRestApiVersion: versions.externalRestApiVersion,- rpcProxyVersion: versions.rpcProxyVersion,- desktopVersion: versions.desktopVersion,- minimumDesktopVersion: inherited || minimumDesktopVersion,+ if (!inherited && !minimumDesktopVersion) {+ throw new Error(+ 'no minimumDesktopVersion could be read; pass ' ++ '--minimum-desktop-version explicitly rather than ' ++ 'defaulting it to desktopVersion'+ )}-}-const prevVersions = previousVersions(previousRef)-const next = { ...previous, releaseId }-let changed = false+ if (!previous) {+ previous = {+ releaseId,+ externalRestApiVersion: versions.externalRestApiVersion,+ rpcProxyVersion: versions.rpcProxyVersion,+ desktopVersion: versions.desktopVersion,+ minimumDesktopVersion: inherited || minimumDesktopVersion,+ }+ }+ const prevVersions = previousVersions(previousRef)++ const next = { ...previous, releaseId }+ let changed = false++ for (const field of ['externalRestApiVersion', 'rpcProxyVersion']) {+ if (+ !prevVersions[field] ||+ prevVersions[field] !== versions[field] ||+ next[field] !== versions[field]+ ) {+ next[field] = versions[field]+ changed = true+ }+ }-for (const field of ['externalRestApiVersion', 'rpcProxyVersion']) {if (- !prevVersions[field] ||- prevVersions[field] !== versions[field] ||- next[field] !== versions[field]+ !deferDesktopRelease &&+ (!prevVersions.desktopVersion ||+ prevVersions.desktopVersion !== versions.desktopVersion ||+ next.desktopVersion !== versions.desktopVersion)) {- next[field] = versions[field]+ next.desktopVersion = versions.desktopVersionchanged = true}-}-if (- !deferDesktopRelease &&- (!prevVersions.desktopVersion ||- prevVersions.desktopVersion !== versions.desktopVersion ||- next.desktopVersion !== versions.desktopVersion)-) {- next.desktopVersion = versions.desktopVersion- changed = true-}+ // The floor is a compatibility control, not a version. It moves ONLY when the+ // operator asks. Advancing it with every release would show "update required"+ // to every user of the previous release. See appService.ts:840.+ //+ // `previous` may carry a floor copied from an old --previous ref; always+ // re-apply `inherited` (HEAD-first) before letting an explicit flag win, so+ // a floor already raised on HEAD is never silently reverted.+ if (inherited && next.minimumDesktopVersion !== inherited) {+ next.minimumDesktopVersion = inherited+ changed = true+ }+ if (minimumDesktopVersion) {+ next.minimumDesktopVersion = minimumDesktopVersion+ changed = true+ }-// The floor is a compatibility control, not a version. It moves ONLY when the-// operator asks. Advancing it with every release would show "update required"-// to every user of the previous release. See appService.ts:840.-//-// `previous` may carry a floor copied from an old --previous ref; always-// re-apply `inherited` (HEAD-first) before letting an explicit flag win, so-// a floor already raised on HEAD is never silently reverted.-if (inherited && next.minimumDesktopVersion !== inherited) {- next.minimumDesktopVersion = inherited- changed = true-}-if (minimumDesktopVersion) {- next.minimumDesktopVersion = minimumDesktopVersion- changed = true-}+ if (!changed && manifestAtHead) {+ Object.assign(next, manifestAtHead)+ }-if (!changed && manifestAtHead) {- Object.assign(next, manifestAtHead)-}+ validate(next, versions, { deferDesktopRelease })-validate(next, versions, { deferDesktopRelease })+ if (!validateOnly) {+ fs.writeFileSync(path.join(ROOT, MANIFEST_PATH), renderManifest(next))+ }-if (!validateOnly) {- fs.writeFileSync(path.join(ROOT, MANIFEST_PATH), renderManifest(next))+ console.log(JSON.stringify(next, null, 2))+}++try {+ main()+} catch (error) {+ // Matches validate-release-version-bumps.mjs's ::error:: style so a+ // contributor sees an actionable GitHub annotation instead of a raw stack+ // trace on the ci-public.yml step. The underlying detail is preserved+ // verbatim in the annotation; the remediation line is appended separately.+ console.error(`::error::${error.message}`)+ console.error(+ `Fix ${MANIFEST_PATH} so it agrees with the current package.json versions (or pass the ` ++ `correct --release-id / --minimum-desktop-version flags), then re-run ` ++ '`node scripts/release/update-desktop-release-manifest.mjs`.'+ )+ process.exit(1)}--console.log(JSON.stringify(next, null, 2))diff --git a/scripts/release/validate-release-tag.mjs b/scripts/release/validate-release-tag.mjsindex f376e902d..544fff93b 100755--- a/scripts/release/validate-release-tag.mjs+++ b/scripts/release/validate-release-tag.mjs@@ -3,8 +3,9 @@// runs locally and on the release-prep PR, before any tag exists.//// It deliberately does NOT check that the artifacts exist. The v<version>-// images are created by release-images.yml on the tag, so they cannot-// pre-exist here. Existence is that workflow's job.+// images would be built by a future release-images.yml workflow on the tag+// (not yet added to this repo), so they cannot pre-exist here. Existence+// checking is that future workflow's job, not this one's.//// node scripts/release/validate-release-tag.mjs --version 0.6.0import process from 'node:process'@@ -35,27 +36,49 @@ const failures = []for (const coordinate of COORDINATES) {const actual = coordinate.read(ROOT)- if (coordinate.assert === 'equals' && actual !== version) {- failures.push(`${coordinate.name}=${actual}, expected ${version}`)- }+ // A switch with a default is deliberate: an unrecognized `assert` kind+ // (e.g. a `pointer` row added before its check is implemented) must fail+ // loudly, naming the coordinate and the kind, rather than silently falling+ // through every case the way independent `if`s with no `else` would.+ switch (coordinate.assert) {+ case 'equals': {+ if (actual !== version) {+ failures.push(`${coordinate.name}=${actual}, expected ${version}`)+ }+ break+ }- if (coordinate.assert === 'floor') {- if (!SEMVER_RE.test(actual)) {- failures.push(`${coordinate.name}=${actual} is not MAJOR.MINOR.PATCH`)- } else if (compareVersions(actual, version) > 0) {- failures.push(`${coordinate.name}=${actual} is greater than the release version ${version}`)+ case 'floor': {+ if (!SEMVER_RE.test(actual)) {+ failures.push(`${coordinate.name}=${actual} is not MAJOR.MINOR.PATCH`)+ } else if (compareVersions(actual, version) > 0) {+ failures.push(`${coordinate.name}=${actual} is greater than the release version ${version}`)+ }+ break}- }- if (coordinate.assert === 'explicit' && (!actual || actual === 'local')) {- failures.push(`${coordinate.name}=${actual || '(empty)'} was never set explicitly`)- }+ case 'explicit': {+ if (!actual || actual === 'local') {+ failures.push(`${coordinate.name}=${actual || '(empty)'} was never set explicitly`)+ }+ break+ }++ case 'counter': {+ const expected = readCounterPackage(ROOT, coordinate.counterPackage)+ if (actual !== expected) {+ failures.push(+ `${coordinate.name}=${actual}, expected ${expected} from ${coordinate.counterPackage}`+ )+ }+ break+ }- if (coordinate.assert === 'counter') {- const expected = readCounterPackage(ROOT, coordinate.counterPackage)- if (actual !== expected) {+ default: {failures.push(- `${coordinate.name}=${actual}, expected ${expected} from ${coordinate.counterPackage}`+ `${coordinate.name} has assert kind "${coordinate.assert}", which this checker does not ` ++ `implement -- a coordinate cannot be written without being checked, so add a case for it ` ++ `in scripts/release/validate-release-tag.mjs before using this assert kind`)}}diff --git a/scripts/tests/test-precommit-release-manifest-ignore.sh b/scripts/tests/test-precommit-release-manifest-ignore.shindex aa335ca6e..f21114399 100755--- a/scripts/tests/test-precommit-release-manifest-ignore.sh+++ b/scripts/tests/test-precommit-release-manifest-ignore.sh@@ -143,19 +143,28 @@ assert_desktop_version_not_touched_by_counter_resync() {&& node scripts/precommit/bump-staged-package-versions.mjs >/dev/null 2>&1 )status=$?- local manifest_desktop manifest_ers+ local manifest_desktop manifest_ers manifest_minmanifest_desktop="$(manifest_field "$d" desktopVersion)"manifest_ers="$(manifest_field "$d" externalRestApiVersion)"+ manifest_min="$(manifest_field "$d" minimumDesktopVersion)"# 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"+ #+ # minimumDesktopVersion is asserted explicitly here too, not just implied+ # by desktopVersion staying put: this is the invariant the whole+ # workstream protects (a floor that ever equals desktopVersion force-+ # updates every existing desktop install), and the pre-commit path is the+ # one most likely to run on an ordinary service PR, so it must guard the+ # floor directly rather than by inference.+ if [ "$status" -eq 0 ] && [ "$manifest_ers" = "0.1.61" ] && [ "$manifest_desktop" = "0.1.252" ] \+ && [ "$manifest_min" = "0.1.252" ]; then+ pass "a counter re-sync succeeds and never touches desktopVersion or minimumDesktopVersion, 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"+ fail "status=$status externalRestApiVersion=$manifest_ers desktopVersion=$manifest_desktop minimumDesktopVersion=$manifest_min; expected 0 / 0.1.61 / 0.1.252 / 0.1.252"firm -rf "$d"}diff --git a/scripts/tests/test-release-coordinates.sh b/scripts/tests/test-release-coordinates.shindex c5ea905b7..c9a546b4a 100755--- a/scripts/tests/test-release-coordinates.sh+++ b/scripts/tests/test-release-coordinates.sh@@ -516,6 +516,43 @@ assert_counter_mismatch_is_rejected_by_the_checker() {rm -rf "$d"}+assert_unhandled_assert_kind_fails_closed() {+ local d; d="$(mktemp -d)"+ make_fixture "$d" 0.6.0 0.1.60 0.1.51 0.6.0 0.1.252 0.1.60 0.1.51+ cp -R "$REPO_ROOT/scripts" "$d/scripts"++ # Append an 8th coordinate whose assert kind ('pointer') the checker does+ # not implement, carrying a deliberately garbage value that would never+ # agree with anything. If an unrecognized assert kind falls through every+ # branch instead of failing closed, this coordinate is never actually+ # checked and the tree still reports success -- the exact bug this case+ # guards against.+ node -e '+ const fs = require("fs")+ const p = process.argv[1]+ let s = fs.readFileSync(p, "utf8")+ const marker = "export function readCounterPackage"+ if (!s.includes(marker)) throw new Error("marker not found")+ s = s.replace(+ marker,+ "COORDINATES.push({\n" ++ " name: \"test-only-pointer-coordinate\",\n" ++ " assert: \"pointer\",\n" ++ " read: () => \"garbage-value-that-is-never-checked\",\n" ++ "})\n\n" ++ marker+ )+ fs.writeFileSync(p, s)+ ' "$d/scripts/release/release-coordinates.mjs"++ if ( cd "$d" && node scripts/release/validate-release-tag.mjs --version 0.6.0 >/dev/null 2>&1 ); then+ fail "validate-release-tag passed with an unhandled assert kind ('pointer') on a coordinate"+ else+ pass "validate-release-tag fails closed on an unhandled assert kind instead of skipping it silently"+ fi+ rm -rf "$d"+}+assert_every_coordinate_has_a_case() {local declared casesdeclared="$(node -e '@@ -572,6 +609,7 @@ assert_floor_above_release_version_is_rejected_by_the_checkerassert_floor_non_semver_is_rejected_by_the_checkerassert_explicit_release_id_is_rejected_when_local_or_emptyassert_counter_mismatch_is_rejected_by_the_checker+assert_unhandled_assert_kind_fails_closedassert_every_coordinate_has_a_caseassert_every_defined_case_is_invoked