From 3dd0f44c15f306c98e985f447d6e1b11424712e3 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 30 Oct 2026 17:02:02 +0800 Subject: [PATCH] layerfs: the import-limit test uses a small limit, not 20,001 real files The only red in `HOME=$(mktemp -d) bun test` at the root on mote (57f3f90) was "item 3: an import over the file limit is refused, not swept in". It timed out at 30s (34s) under the full suite. Run by itself it passes in about 10s, which is the time to write 20,001 empty files. CI on ubuntu is green. scanImportTree now takes { maxFiles } (the default is still IMPORT_MAX_FILES), so the test checks 51 files against a limit of 50 and 51. The test also pins the 20000 default. Run on mote: layerfs.test.mjs 38 pass; scripts/check.mjs ok. The full root suite at 57f3f90 had 3769 tests, 1 fail (this one). Broken by hand: checkImportLimits compared against IMPORT_MAX_FILES again, and the test went red. Not tried: running the old test under load again to watch it time out; the full-suite log shows that. No version bump: the default behaviour is unchanged. --- packages/layerfs/layerfs.mjs | 12 +++++++----- packages/layerfs/layerfs.test.mjs | 9 ++++++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/layerfs/layerfs.mjs b/packages/layerfs/layerfs.mjs index c70d0e8..b6009ce 100644 --- a/packages/layerfs/layerfs.mjs +++ b/packages/layerfs/layerfs.mjs @@ -197,11 +197,11 @@ export function isSecretPath(rel) { // instead of sweeping a disk into the store. export const IMPORT_MAX_FILES = 20000 export const IMPORT_MAX_BYTES = 512 * 1024 * 1024 -function checkImportLimits(files) { +function checkImportLimits(files, maxFiles = IMPORT_MAX_FILES) { let bytes = 0 for (const f of files) bytes += f.size - if (files.length > IMPORT_MAX_FILES) - throw new Error(`source holds ${files.length} files, over the import limit of ${IMPORT_MAX_FILES} — pass the project's own directory, not a parent of it`) + if (files.length > maxFiles) + throw new Error(`source holds ${files.length} files, over the import limit of ${maxFiles} — pass the project's own directory, not a parent of it`) if (bytes > IMPORT_MAX_BYTES) throw new Error(`source holds ${bytes} bytes, over the import limit of ${IMPORT_MAX_BYTES} — pass the project's own directory, not a parent of it`) } @@ -233,9 +233,11 @@ function walkSourceFiles(dir) { // The sim backend's import scan: a manifest { rel: { sha, size, mode } } // plus the list of secret-shaped paths left out, reported to the caller. -export function scanImportTree(dir) { +// maxFiles is for tests: 20,001 real files took 10s to write on a quiet +// Mac and 34s under a full suite, past the test's 30s budget. +export function scanImportTree(dir, { maxFiles = IMPORT_MAX_FILES } = {}) { const { files, skipped } = walkSourceFiles(dir) - checkImportLimits(files) + checkImportLimits(files, maxFiles) const manifest = {} for (const f of files) { const buf = readFileSync(f.full) diff --git a/packages/layerfs/layerfs.test.mjs b/packages/layerfs/layerfs.test.mjs index 5e1de85..440bffc 100644 --- a/packages/layerfs/layerfs.test.mjs +++ b/packages/layerfs/layerfs.test.mjs @@ -398,9 +398,12 @@ test("item 3: an import skips secret-shaped files and reports them", async () => test("item 3: an import over the file limit is refused, not swept in", () => { const src = mkTmp("layerfs-big-") - for (let i = 0; i <= IMPORT_MAX_FILES; i++) writeFileSync(join(src, `f${i}.txt`), "") - expect(() => scanImportTree(src)).toThrow("import limit") -}, 30000) + // a small limit: 20,001 real files outran a 30s budget under load + for (let i = 0; i <= 50; i++) writeFileSync(join(src, `f${i}.txt`), "") + expect(() => scanImportTree(src, { maxFiles: 50 })).toThrow("over the import limit of 50") + expect(() => scanImportTree(src, { maxFiles: 51 })).not.toThrow() + expect(IMPORT_MAX_FILES).toBe(20000) // the default the sim backend imports with +}) test("item 4: the store is private, and a file's mode survives the store", async () => { const { call, home, src } = await simTools()