Simplify workspace authoring and isolate managed component styles

This commit is contained in:
Timothy J. Aveni
2026-09-14 20:35:53 -07:00
parent 14b0ef25c3
commit e753ffe601
13 changed files with 278 additions and 95 deletions
+21
View File
@@ -0,0 +1,21 @@
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";
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)'])
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.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 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/);
});