Format authored monorepo code with pinned language formatters

This commit is contained in:
Timothy J. Aveni
2026-09-15 15:23:24 -07:00
parent a174faea5c
commit 00fc2b9ff1
69 changed files with 5135 additions and 3306 deletions
+21 -6
View File
@@ -1,21 +1,36 @@
import test from "node:test";
import assert from "node:assert/strict";
import {bundlePolicyErrors} from "../src/bindings/bundle-policy.js";
import {addImplementation} from "../src/capability-language/implementation-edit.js";
import { bundlePolicyErrors } from "../src/bindings/bundle-policy.js";
import { addImplementation } from "../src/capability-language/implementation-edit.js";
test("bundled source policy rejects location and dynamic-loading assumptions, not static assets or runtime I/O", () => {
for (const code of ['new URL("../x", import.meta.url)', '__dirname', '__filename', 'import(name)', 'require(name)', 'eval(code)', 'new Function(code)'])
for (const code of [
'new URL("../x", import.meta.url)',
"__dirname",
"__filename",
"import(name)",
"require(name)",
"eval(code)",
"new Function(code)",
])
assert.ok(bundlePolicyErrors(code, "source.ts").length, code);
assert.deepEqual(bundlePolicyErrors('import source from "./component.js?browser-source"; import fs from "node:fs"; fs.readFile(userSelectedPath);', "source.ts"), []);
assert.deepEqual(
bundlePolicyErrors(
'import source from "./component.js?browser-source"; import fs from "node:fs"; fs.readFile(userSelectedPath);',
"source.ts",
),
[],
);
assert.deepEqual(bundlePolicyErrors('// import.meta.url\nconst text = "__dirname";', "source.ts"), []);
});
test("imperative handler insertion preserves arbitrary existing code and rejects ambiguous targets", () => {
const original = 'const keep = "createRuntime({fake:1})";\nservePackageRuntime(createRuntime({ existing: customHandler }));\n';
const original =
'const keep = "createRuntime({fake:1})";\nservePackageRuntime(createRuntime({ existing: customHandler }));\n';
const edited = addImplementation(original, "createRuntime", "newHandler", "./impl/new.js");
assert.match(edited, /existing: customHandler/);
assert.match(edited, /const keep =/);
assert.match(edited, /"newHandler": qxImplementation/);
assert.throws(() => addImplementation(original, "createRuntime", "existing", "./x.js"), /already exists/);
assert.throws(() => addImplementation('createRuntime(one);', "createRuntime", "x", "./x.js"), /Cannot safely/);
assert.throws(() => addImplementation("createRuntime(one);", "createRuntime", "x", "./x.js"), /Cannot safely/);
});