Files
rea/tests/boundary/filesystem/stableArtifact.test.ts
T
ysopwnable 01be082e9e feat(browser): trace captured website module imports (#879)
* feat(browser): trace captured website module imports

Compose verified exported scripts, inert native import syntax and a narrow
Chromium resolution port. Preserve query/fragment identity, import-map context,
all reported capture candidates and explicit unknown execution. Share named
CLI/MCP contracts and retain native reports, diagnostics and cleanup failures.

Add focused boundary regressions and a real module-loading oracle to the
existing conditional Chrome lane. No captured application code is executed
by module tracing, and no selected website asset is refetched.

Refs #851, #774

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)

* fix(browser): preserve module contexts and source bindings

Keep capture completeness inline, validate actual source text against its
digest, and separate unsupported URL contexts from malformed input.
Use the importer origin for native module resolution and the selected map
base independently, including mixed HTTP/HTTPS and escaped HTML attributes.

Refs #851, #774

Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis)
Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
2026-10-07 14:59:52 +08:00

31 lines
1.2 KiB
TypeScript

import { rename, symlink, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect, it } from "vitest";
import { readStableArtifact } from "../../../src/artifacts/readStableArtifact.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
it("reads exact binary and empty bytes and rejects symlink/size/cancellation boundaries", async () => {
const root = await createTestTempDirectory("rea-stable-artifact-");
const path = join(root, "source.bin");
await writeFile(path, Buffer.from([0, 255, 254]));
expect((await readStableArtifact(path, 3)).bytes).toEqual(
Buffer.from([0, 255, 254]),
);
await expect(readStableArtifact(path, 2)).rejects.toMatchObject({
reason: "limit",
});
await writeFile(path, "");
expect((await readStableArtifact(path, 0)).bytes.length).toBe(0);
const real = join(root, "original.bin");
await rename(path, real);
await symlink(real, path);
await expect(readStableArtifact(path, 3)).rejects.toMatchObject({
reason: "path",
});
const controller = new AbortController();
controller.abort();
await expect(readStableArtifact(real, 3, controller.signal)).rejects.toBe(
controller.signal.reason,
);
});