The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(build): keep unrelated edits out of TUI freshness
ethernetea6a71117144
diff --git a/scripts/build/README.md b/scripts/build/README.mdindex 7f5c2fde17a..469c0aba4d1 100644--- a/scripts/build/README.md+++ b/scripts/build/README.md@@ -87,6 +87,10 @@ receipt described below.Each compiler publishes `hermes-build.json` inside its output (inside `dist/`for TUI). `freshness.mjs` owns this receipt and all source input selection.+TUI inputs are its source tree, the Ink source alias, shared sources, their+manifests and TypeScript configuration, dependency locks, and its compiler and+shared compiler helpers. Tests, workspace documentation, dependency-provider+recipes, and other products' compiler recipes do not invalidate the TUI.It records product/host identity, content hashes of workspace/shared sources andbuild inputs, and the exact supplied icon directory, desktop install stamp, andnative-dependency tree. Inputs are checked again before publication: a concurrentdiff --git a/scripts/build/freshness.mjs b/scripts/build/freshness.mjsindex 05a4b392322..50524b539f1 100644--- a/scripts/build/freshness.mjs+++ b/scripts/build/freshness.mjs@@ -9,6 +9,16 @@ const receiptName = 'hermes-build.json'const workspaces = { tui: 'ui-tui', web: 'web', desktop: 'apps/desktop' }const generated = new Set(['node_modules', 'dist', 'build', 'release', '.cache', '.git', 'coverage', 'test-results', 'playwright-report'])+// buildTui bundles these source roots (including the Ink source alias), not+// the workspaces' documentation, test runners or other product recipes.+const tuiInputs = [+ ...['ui-tui', 'ui-tui/packages/hermes-ink', 'apps/shared'].flatMap(root => [+ `${root}/src`, `${root}/package.json`, `${root}/tsconfig.json`,+ ]),+ 'tsconfig.json', 'package.json', 'package-lock.json', '.npmrc', 'pm/lock.json',+ 'scripts/build/tui.mjs', 'scripts/build/frontend-common.mjs', 'scripts/build/freshness.mjs',+]+function treeHash(root, inputs, skip, contents = () => true) {const hash = createHash('sha256')function visit(name) {@@ -30,15 +40,16 @@ function treeHash(root, inputs, skip, contents = () => true) {export function sourceHash(source, product) {const workspace = workspaces[product]if (!workspace) throw new Error(`Unknown frontend product: ${product}`)- return treeHash(source, [+ return treeHash(source, product === 'tui' ? tuiInputs : [workspace, 'apps/shared', 'package.json', 'package-lock.json', '.npmrc', 'pm/lock.json','scripts/build',- ...(product === 'tui' ? [] : ['scripts/generate-icons.mjs', 'scripts/generate_icons.py',- 'assets', 'pyproject.toml', 'uv.lock', 'install-stamp.json']),+ 'scripts/generate-icons.mjs', 'scripts/generate_icons.py',+ 'assets', 'pyproject.toml', 'uv.lock', 'install-stamp.json',], name => {// Build scripts are inputs; workspace build directories are outputs.const parts = name.split('/')return (!name.startsWith('scripts/') && parts.some(part => generated.has(part)))+ || (product === 'tui' && (parts.includes('__tests__') || /\.(test|spec)(-d)?\.[cm]?[jt]sx?$/.test(name)))|| parts.some(part => part.startsWith('.dist-') || part.startsWith('.staging-') || part === '__pycache__')|| name.endsWith('.tsbuildinfo') || name.endsWith('.pyc')})diff --git a/tests-js/product-builders.test.mjs b/tests-js/product-builders.test.mjsindex 1271bad697b..0c01b96fea6 100644--- a/tests-js/product-builders.test.mjs+++ b/tests-js/product-builders.test.mjs@@ -237,6 +237,10 @@ test('built web freshness follows shared sources and build inputs, not mtimes orexpect(productCurrent({ source, product: 'web', out })).toBe(true)put(source, 'web/node_modules/.tmp/tsbuildinfo', 'generated')expect(productCurrent({ source, product: 'web', out })).toBe(true)+ put(icons, 'web/public/favicon.ico', 'changed prepared icon')+ expect(productCurrent({ source, product: 'web', out })).toBe(false)+ await buildWeb({ source, icons, out })+ expect(readFileSync(path.join(out, 'favicon.ico'), 'utf8')).toBe('changed prepared icon')for (const input of ['apps/shared/src/client.ts', 'scripts/build/web.mjs', 'assets/icon.svg', 'package-lock.json']) {put(source, input, 'changed input')expect(productCurrent({ source, product: 'web', out }), input).toBe(false)@@ -247,3 +251,67 @@ test('built web freshness follows shared sources and build inputs, not mtimes orrmSync(path.join(out, 'favicon.ico'))expect(productCurrent({ source, product: 'web', out })).toBe(false)}, 30_000)++test('built TUI stays current after documentation, test and unrelated recipe changes', async () => {+ const { productCurrent } = await import('../scripts/build/freshness.mjs')+ const base = fixture()+ const source = path.join(base, 'source')+ const out = path.join(base, 'tui')+ tuiSource(source)+ dependency(source, '', 'esbuild')+ put(source, 'apps/shared/src/value.ts', 'export const value: string = "shared source";')+ await buildTui({ source, out })+ const entry = path.join(out, 'dist/entry.js')+ const before = readFileSync(entry)+ for (const name of [+ 'ui-tui/README.md', 'ui-tui/src/__tests__/new.test.ts', 'ui-tui/src/value.spec.ts',+ 'ui-tui/packages/hermes-ink/src/value.test.ts', 'apps/shared/src/value.test.ts',+ 'apps/shared/README.md', 'scripts/build/web.mjs', 'scripts/build/desktop.mjs',+ 'scripts/build/README.md', 'scripts/build/node-deps.mjs',+ ]) {+ put(source, name, 'not a compiler input')+ expect(productCurrent({ source, product: 'tui', out: path.join(out, 'dist') }), name).toBe(true)+ }+ await buildTui({ source, out })+ expect(readFileSync(entry)).toEqual(before)+ expect(execFileSync(process.execPath, [entry], { encoding: 'utf8' }).trim()).toBe('prepared source')+})++test('TUI freshness invalidates source, configuration and compiler inputs and damaged outputs', async () => {+ const { productCurrent } = await import('../scripts/build/freshness.mjs')+ const base = fixture()+ const source = path.join(base, 'source')+ const out = path.join(base, 'tui')+ tuiSource(source)+ dependency(source, '', 'esbuild')+ // Include the shared workspace in the real compiler graph, not just the receipt.+ put(source, 'ui-tui/src/value.ts', 'export const value: string = "shared source";')+ put(source, 'apps/shared/src/value.ts', 'export { value } from "../../../ui-tui/src/value";')+ put(source, 'ui-tui/src/entry.tsx', 'import { value } from "../../apps/shared/src/value"; console.log(value);')+ await buildTui({ source, out })+ const current = () => productCurrent({ source, product: 'tui', out: path.join(out, 'dist') })+ expect(current()).toBe(true)+ for (const name of [+ 'ui-tui/src/value.ts', 'apps/shared/src/value.ts',+ 'ui-tui/packages/hermes-ink/src/entry-exports.ts',+ 'ui-tui/tsconfig.json', 'ui-tui/packages/hermes-ink/tsconfig.json', 'apps/shared/tsconfig.json',+ 'ui-tui/package.json', 'ui-tui/packages/hermes-ink/package.json', 'apps/shared/package.json',+ 'tsconfig.json', 'package.json', 'package-lock.json', '.npmrc', 'pm/lock.json',+ 'scripts/build/tui.mjs', 'scripts/build/frontend-common.mjs', 'scripts/build/freshness.mjs',+ ]) {+ const file = path.join(source, name)+ const previous = existsSync(file) ? readFileSync(file) : null+ put(source, name, 'changed input')+ expect(current(), name).toBe(false)+ if (previous) writeFileSync(file, previous)+ else rmSync(file)+ expect(current(), `restored ${name}`).toBe(true)+ }+ put(source, 'ui-tui/src/value.ts', 'export const value: string = "rebuilt source";')+ await buildTui({ source, out })+ expect(current()).toBe(true)+ const entry = path.join(out, 'dist/entry.js')+ expect(execFileSync(process.execPath, [entry], { encoding: 'utf8' }).trim()).toBe('rebuilt source')+ writeFileSync(entry, 'damaged output')+ expect(current()).toBe(false)+})