Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: release check fails closed when the ship policy file is missing or unreadable

garrytan248aeed99f62
diff --git a/scripts/check-behavior-since.ts b/scripts/check-behavior-since.ts
index fb71931f5e..c8a01320f0 100644
--- a/scripts/check-behavior-since.ts
+++ b/scripts/check-behavior-since.ts
@@ -21,7 +21,8 @@
* Under .gstack/ship-policy.json `merge: direct` versions are written at release, which never edits this file, so
* a TBD row is refused on every tree: a plain-text row is a behavior-changes.d/<id>.md fragment and a function row
* is dated `since: releasedIn('<id>')` (behavior-changes.d/README.md). With --stamped (the Release workflow) the
- * release commit must also hold no unfolded changelog.d fragment and a fresh behavior-change table.
+ * release commit must also hold no unfolded changelog.d fragment and a fresh behavior-change table, and a missing or
+ * unparsable .gstack/ship-policy.json is refused rather than read as "not direct".
*
* Base ref: $GBRAIN_RELEASE_BASE_REF, default origin/master. When it is
* unavailable the check fails under CI=true and skips locally.
@@ -33,6 +34,7 @@ import { join } from 'node:path';
import { build, CHANGELOG_FRAGMENT_DIR, OUT } from './build-behavior-changes.ts';
export const NOTICE_FILE = 'src/core/behavior-change-notice.ts';
+const POLICY_FILE = '.gstack/ship-policy.json';
const TBD = /since:\s*'TBD'/;
const SEE = 'See: docs/RELEASING.md#release-restamp';
@@ -62,7 +64,15 @@ export function main(argv: string[], opts: { cwd?: string; env?: Record<string,
log(SEE);
return 1;
}
- const direct = (() => { try { return JSON.parse(read('.gstack/ship-policy.json') || '{}').merge === 'direct'; } catch { return false; } })();
+ const policy = (() => { try { return { merge: JSON.parse(read(POLICY_FILE)).merge }; } catch (e) { return { error: existsSync(join(root, POLICY_FILE)) ? `cannot be parsed (${e instanceof Error ? e.message : String(e)})` : 'is missing' }; } })();
+ if ('error' in policy && argv.includes('--stamped')) {
+ log(`FAIL: ${POLICY_FILE} ${policy.error}, so this check cannot tell whether the release commit must have folded its changelog.d fragments and regenerated its behavior-change table.`);
+ log('Why: --stamped guards a stamp or a release; reading no policy as `merge` unset would skip those checks without saying so.');
+ log(`Fix: restore ${POLICY_FILE} from master (git checkout origin/master -- ${POLICY_FILE}; a sparse checkout must include .gstack), then rerun.`);
+ log(SEE);
+ return 1;
+ }
+ const direct = !('error' in policy) && policy.merge === 'direct';
if (direct && argv.includes('--stamped')) {
const unfolded = existsSync(join(root, CHANGELOG_FRAGMENT_DIR)) ? readdirSync(join(root, CHANGELOG_FRAGMENT_DIR)).filter((f) => f.endsWith('.md') && f !== 'README.md') : [];
const table = build(root);
diff --git a/test/scripts/check-behavior-since.test.ts b/test/scripts/check-behavior-since.test.ts
index bf5083abf1..4526cb33d1 100644
--- a/test/scripts/check-behavior-since.test.ts
+++ b/test/scripts/check-behavior-since.test.ts
@@ -50,7 +50,7 @@ function repo(): string {
git(root, 'init', '-q', '-b', 'master');
git(root, 'config', 'user.email', '[email protected]');
git(root, 'config', 'user.name', 't');
- put(root, { VERSION: '0.60.322.0\n', 'CHANGELOG.md': changelog('0.60.322.0'), [NOTICE_FILE]: notice('0.60.321.0', '0.60.322.0') });
+ put(root, { VERSION: '0.60.322.0\n', 'CHANGELOG.md': changelog('0.60.322.0'), [NOTICE_FILE]: notice('0.60.321.0', '0.60.322.0'), '.gstack/ship-policy.json': '{ "bump": "patch" }\n' });
commit(root, 'master');
git(root, 'update-ref', 'refs/remotes/origin/master', 'HEAD');
git(root, 'checkout', '-q', '-b', 'feature');
@@ -109,6 +109,19 @@ describe('check:behavior-since', () => {
expect(run(root, ['--stamped']).code).toBe(1);
});
+ test('--stamped fails closed when .gstack/ship-policy.json is missing or cannot be parsed', () => {
+ const root = repo();
+ rmSync(join(root, '.gstack/ship-policy.json'));
+ const missing = run(root, ['--stamped']);
+ expect(missing.code).toBe(1);
+ expect(missing.out).toContain('FAIL: .gstack/ship-policy.json is missing');
+ put(root, { '.gstack/ship-policy.json': '{ "merge": "direct",\n' });
+ const broken = run(root, ['--stamped']);
+ expect(broken.code).toBe(1);
+ expect(broken.out).toContain('FAIL: .gstack/ship-policy.json cannot be parsed');
+ expect(run(root).code).toBe(0);
+ });
+
test('master refuses a TBD row: by GITHUB_REF, by HEAD at the base, and when the base itself ships one', () => {
const root = repo();
put(root, { [NOTICE_FILE]: notice('0.60.322.0', 'TBD') });