The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(build): pin the OS-metadata freshness skip and the ENOTEMPTY rmTree retry
Brooklyn Nicholson6285f09fd614
diff --git a/tests-js/freshness-metadata.test.mjs b/tests-js/freshness-metadata.test.mjsnew file mode 100644index 00000000000..0a870f2fb08--- /dev/null+++ b/tests-js/freshness-metadata.test.mjs@@ -0,0 +1,64 @@+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync } from 'node:fs'+import { tmpdir } from 'node:os'+import path from 'node:path'+import { expect, test } from 'vitest'++// The freshness contract for OS file-manager metadata (#122632, #122803): writing+// .DS_Store / AppleDouble sidecars / .localized / Thumbs.db / Desktop.ini into any+// hashed tree must never flip a recorded product from current to stale. Exercises+// the real buildInputs/recordProduct/productCurrent path against a fixture tree+// instead of a full compiler run, so the regression shows up in seconds.+const fixture = (name) => {+ const dir = mkdtempSync(path.join(tmpdir(), name))+ mkdirSync(path.join(dir, 'web/src'), { recursive: true })+ writeFileSync(path.join(dir, 'package.json'), '{"private":true}')+ writeFileSync(path.join(dir, 'package-lock.json'), '{}')+ writeFileSync(path.join(dir, 'web/src/main.ts'), 'export const answer: string = "prepared web";')+ return dir+}++test('OS file-manager metadata landing in hashed trees never invalidates a recorded product', async () => {+ const { buildInputs, recordProduct, productCurrent } = await import('../scripts/build/freshness.mjs')+ const source = fixture('freshness-metadata-')+ const out = mkdtempSync(path.join(tmpdir(), 'freshness-out-'))+ try {+ mkdirSync(path.join(out, 'dist'), { recursive: true })+ const inputs = buildInputs(source, 'web')+ recordProduct({ source, product: 'web', out, inputs })+ expect(productCurrent({ source, product: 'web', out })).toBe(true)+ // A real source change must still invalidate — the guard stays fail-closed.+ writeFileSync(path.join(source, 'web/src/main.ts'), 'export const answer: string = "changed";')+ expect(productCurrent({ source, product: 'web', out })).toBe(false)+ writeFileSync(path.join(source, 'web/src/main.ts'), 'export const answer: string = "prepared web";')+ expect(productCurrent({ source, product: 'web', out })).toBe(true)+ // macOS Finder noise (#122632) and Windows file-manager noise (#122803) in+ // every hashed tree: source inputs, the output, prepared directories.+ for (const [name, content] of [+ ['.DS_Store', 'finder metadata'],+ ['web/src/._main.ts', 'apple double sidecar'],+ ['web/.localized', ''],+ ['web/Thumbs.db', 'thumb cache'],+ ['web/Desktop.ini', 'folder view settings'],+ ['._.DS_Store', 'double finder metadata'],+ ]) {+ writeFileSync(path.join(source, name), content)+ expect(productCurrent({ source, product: 'web', out }), name).toBe(true)+ }+ // Same noise inside the output tree and a prepared tree must not flip it either.+ writeFileSync(path.join(out, 'dist/.DS_Store'), 'finder metadata')+ expect(productCurrent({ source, product: 'web', out })).toBe(true)+ const prepared = mkdtempSync(path.join(tmpdir(), 'freshness-prepared-'))+ writeFileSync(path.join(prepared, 'icon.ico'), 'icon')+ writeFileSync(path.join(prepared, 'Thumbs.db'), 'thumb cache')+ const withPrepared = buildInputs(source, 'web', { icons: prepared })+ recordProduct({ source, product: 'web', out, inputs: withPrepared })+ writeFileSync(path.join(prepared, '.DS_Store'), 'finder metadata')+ expect(productCurrent({ source, product: 'web', out, prepared: { icons: prepared } })).toBe(true)+ // ...while a genuine prepared-input change still invalidates.+ writeFileSync(path.join(prepared, 'icon.ico'), 'changed icon')+ expect(productCurrent({ source, product: 'web', out, prepared: { icons: prepared } })).toBe(false)+ } finally {+ rmSync(source, { recursive: true, force: true })+ rmSync(out, { recursive: true, force: true })+ }+})diff --git a/tests-js/frontend-common.test.mjs b/tests-js/frontend-common.test.mjsnew file mode 100644index 00000000000..db1b2753cd0--- /dev/null+++ b/tests-js/frontend-common.test.mjs@@ -0,0 +1,39 @@+import { expect, test, vi } from 'vitest'++// rmTree retries ENOTEMPTY from Finder/Spotlight dropping files into a+// directory mid-removal (#122803). Node's rmSync is the only seam that can+// reproduce that race deterministically, so replace it and keep the rest of+// node:fs real.+const { rmSync } = vi.hoisted(() => ({ rmSync: vi.fn() }))++vi.mock('node:fs', async (importOriginal) => {+ const actual = await importOriginal()+ return { ...actual, rmSync }+})++const enotempty = () => { throw Object.assign(new Error('directory not empty'), { code: 'ENOTEMPTY' }) }++test('rmTree retries ENOTEMPTY removals until the directory clears', async () => {+ const { rmTree } = await import('../scripts/build/frontend-common.mjs')+ rmSync.mockReset()+ rmSync.mockImplementationOnce(enotempty).mockImplementationOnce(enotempty).mockImplementationOnce(() => {})+ await expect(rmTree('/tmp/product-scratch')).resolves.toBeUndefined()+ expect(rmSync).toHaveBeenCalledTimes(3)+})++test('rmTree stops retrying after a bounded number of attempts', async () => {+ const { rmTree } = await import('../scripts/build/frontend-common.mjs')+ rmSync.mockReset()+ rmSync.mockImplementation(enotempty)+ await expect(rmTree('/tmp/product-scratch')).rejects.toThrow('directory not empty')+ expect(rmSync.mock.calls.length).toBeGreaterThanOrEqual(3)+ expect(rmSync.mock.calls.length).toBeLessThanOrEqual(5)+})++test('rmTree does not retry unrelated failures like ENOENT or EPERM', async () => {+ const { rmTree } = await import('../scripts/build/frontend-common.mjs')+ rmSync.mockReset()+ rmSync.mockImplementationOnce(() => { throw Object.assign(new Error('no such file'), { code: 'ENOENT' }) })+ await expect(rmTree('/tmp/product-scratch')).rejects.toThrow('no such file')+ expect(rmSync).toHaveBeenCalledTimes(1)+})diff --git a/tests-js/product-builders.test.mjs b/tests-js/product-builders.test.mjsindex 2883b9d1415..beb69fc3ea5 100644--- a/tests-js/product-builders.test.mjs+++ b/tests-js/product-builders.test.mjs@@ -242,6 +242,9 @@ test('built web freshness follows shared sources and build inputs, not mtimes orput(source, 'web/public/.DS_Store', 'finder metadata')put(source, 'apps/shared/src/._client.ts', 'apple double sidecar')put(source, 'assets/.localized', '')+ // Windows file-manager metadata is the same class of noise (#122803).+ put(source, 'web/public/Thumbs.db', 'thumb cache')+ put(source, 'assets/Desktop.ini', 'folder view settings')expect(productCurrent({ source, product: 'web', out })).toBe(true)// Install completion rewrites the runtime identity after building products.put(source, 'install-stamp.json', '{"builtAt": "later"}')