mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 00:58:46 +00:00
* fix(verify): bound concurrent file reads in architecture and limit guards `scripts/verify/architecture-guards.mjs` reads every `.ts`, `.mts`, `.mjs`, and `.py` file under `src/`, `tests/`, `scripts/`, and `bridge/` (8,203 files on current `main`) via unbounded `Promise.all(paths.map(readFile))`. On Windows, queuing all `open()` calls at once exceeds the UCRT 8,192 file descriptor ceiling and deterministically fails `npm run verify:architecture-guards`, `npm run check:fast`, and the pre-push hook with `EMFILE: too many open files`. Add a zero-dependency JSDoc-typed `mapWithConcurrency` helper in `scripts/verify/bounded-file-reads.mjs` (default cap 64, registered in `tsconfig.scripts.json` so it runs before `npm ci`), apply it across all four bulk `readFile` loops in `scripts/verify/architecture-guards.mjs` and the sibling `src/` scan in `scripts/verify/rea-numeric-limits.mjs`, and add unit coverage in `tests/evaluation/boundedFileReads.test.ts`. * test(verify): copy bounded-file-reads helper in numericLimitGuardPermission fixture `scripts/verify/rea-numeric-limits.mjs` now imports `./bounded-file-reads.mjs`. Copy both scripts into the temporary checkout in `tests/boundary/process/numericLimitGuardPermission.test.ts` so the copied verifier starts cleanly on non-root Linux/macOS runs instead of failing with `ERR_MODULE_NOT_FOUND`.
91 lines
2.9 KiB
TypeScript
91 lines
2.9 KiB
TypeScript
import {
|
|
chmod,
|
|
copyFile,
|
|
mkdir,
|
|
realpath,
|
|
rename,
|
|
symlink,
|
|
writeFile,
|
|
} from "node:fs/promises";
|
|
import { join, resolve } from "node:path";
|
|
import { expect } from "vitest";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { processTest } from "../../support/process/processFixture.js";
|
|
|
|
processTest.skipIf(
|
|
process.platform === "win32" ||
|
|
(typeof process.getuid === "function" && process.getuid() === 0),
|
|
)(
|
|
"fails the numeric limit guard when a required scan directory is unreadable",
|
|
async ({ processes }) => {
|
|
const root = await realpath(
|
|
await createTestTempDirectory("rea-limit-permission-"),
|
|
);
|
|
const source = join(root, "src");
|
|
const nested = join(source, "nested");
|
|
await mkdir(join(root, "scripts/verify"), { recursive: true });
|
|
await mkdir(join(source, "domain"), { recursive: true });
|
|
await mkdir(join(source, "resources"));
|
|
await mkdir(nested);
|
|
await symlink(resolve("node_modules"), join(root, "node_modules"), "dir");
|
|
await writeFile(
|
|
join(source, "domain/analysisSettingDefinitions.ts"),
|
|
'export const ANALYSIS_SETTINGS = { fixture: { environment: "REA_PERMISSION_LIMIT", updateMode: "runtime" } };',
|
|
);
|
|
await writeFile(
|
|
join(source, "domain/numericLimitRegistry.ts"),
|
|
"export const NUMERIC_LIMIT_REGISTRY = [];",
|
|
);
|
|
await writeFile(
|
|
join(nested, "limit.ts"),
|
|
"export const limit = Number(process.env.REA_PERMISSION_LIMIT);",
|
|
);
|
|
for (const owner of [
|
|
"domain/artifactReaderLimits.ts",
|
|
"domain/webNetworkCapture.ts",
|
|
"resources/ArtifactReaderLimits.ts",
|
|
]) {
|
|
await writeFile(
|
|
join(source, owner),
|
|
'export const limit = { update_mode: "parameter" };',
|
|
);
|
|
}
|
|
for (const script of [
|
|
"scripts/verify/rea-numeric-limits.mjs",
|
|
"scripts/verify/bounded-file-reads.mjs",
|
|
]) {
|
|
await copyFile(script, join(root, script));
|
|
}
|
|
const run = () =>
|
|
processes.run(
|
|
process.execPath,
|
|
["scripts/verify/rea-numeric-limits.mjs"],
|
|
{ cwd: root },
|
|
);
|
|
const healthy = await run();
|
|
expect(healthy.exitCode, healthy.stderr).toBe(0);
|
|
expect(healthy.stdout).toContain("1 discovered.");
|
|
for (const directory of [source, nested]) {
|
|
try {
|
|
await chmod(directory, 0);
|
|
const refused = await run();
|
|
expect(refused.exitCode).not.toBe(0);
|
|
expect(refused.stderr).toContain("EACCES");
|
|
expect(refused.stderr).toContain(directory);
|
|
} finally {
|
|
await chmod(directory, 0o755);
|
|
}
|
|
}
|
|
const saved = join(root, "src-saved");
|
|
await rename(source, saved);
|
|
try {
|
|
const missing = await run();
|
|
expect(missing.exitCode).not.toBe(0);
|
|
expect(missing.stderr).toContain("ENOENT");
|
|
expect(missing.stderr).toContain(source);
|
|
} finally {
|
|
await rename(saved, source);
|
|
}
|
|
},
|
|
);
|