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.
This commit is contained in:
yetone
2026-10-30 17:02:02 +08:00
parent 57f3f90698
commit 3dd0f44c15
2 changed files with 13 additions and 8 deletions
+7 -5
View File
@@ -197,11 +197,11 @@ export function isSecretPath(rel) {
// instead of sweeping a disk into the store. // instead of sweeping a disk into the store.
export const IMPORT_MAX_FILES = 20000 export const IMPORT_MAX_FILES = 20000
export const IMPORT_MAX_BYTES = 512 * 1024 * 1024 export const IMPORT_MAX_BYTES = 512 * 1024 * 1024
function checkImportLimits(files) { function checkImportLimits(files, maxFiles = IMPORT_MAX_FILES) {
let bytes = 0 let bytes = 0
for (const f of files) bytes += f.size for (const f of files) bytes += f.size
if (files.length > IMPORT_MAX_FILES) if (files.length > maxFiles)
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`) 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) 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`) 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 } } // 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. // 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) const { files, skipped } = walkSourceFiles(dir)
checkImportLimits(files) checkImportLimits(files, maxFiles)
const manifest = {} const manifest = {}
for (const f of files) { for (const f of files) {
const buf = readFileSync(f.full) const buf = readFileSync(f.full)
+6 -3
View File
@@ -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", () => { test("item 3: an import over the file limit is refused, not swept in", () => {
const src = mkTmp("layerfs-big-") const src = mkTmp("layerfs-big-")
for (let i = 0; i <= IMPORT_MAX_FILES; i++) writeFileSync(join(src, `f${i}.txt`), "") // a small limit: 20,001 real files outran a 30s budget under load
expect(() => scanImportTree(src)).toThrow("import limit") for (let i = 0; i <= 50; i++) writeFileSync(join(src, `f${i}.txt`), "")
}, 30000) 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 () => { test("item 4: the store is private, and a file's mode survives the store", async () => {
const { call, home, src } = await simTools() const { call, home, src } = await simTools()