Simplify workspace authoring and isolate managed component styles
Use imperative scaffolds without a registry/refresh lifecycle; preserve authored runtime wiring and generate checked descriptors. Consolidate binding options, embed checked TSX/CSS source, queue mutable convergence while allowing parallel immutable checks, and preload real CLI observations. Add Shadow DOM boundaries with scoped overlays and composed-event handling. Update template/toolchain pins and document VM-free authoring, browser, and stateful acceptance; no deployment or default-template selection.
This commit is contained in:
@@ -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/);
|
||||
});
|
||||
@@ -8,6 +8,7 @@ import {promisify} from "node:util";
|
||||
import {scaffoldRecipe} from "../src/capability-language/scaffold-recipes.js";
|
||||
import {planStructure, applyStructure} from "../src/capability-language/structural-plan.js";
|
||||
import {contentDigest} from "../src/capability-model/evolution.js";
|
||||
import {sealMigrations} from "../src/capability-language/migration-seal.js";
|
||||
const execFile = promisify(callback);
|
||||
|
||||
test("React preset applies its browser build script and shared-platform imports", async (context) => {
|
||||
@@ -17,11 +18,14 @@ test("React preset applies its browser build script and shared-platform imports"
|
||||
const source = {repository: "https://example.test/react.git", commit: "a".repeat(40)};
|
||||
const request = await scaffoldRecipe(root, "package", {source, name: "React", id: "package:react", revision: "package:react@1", template: "typescript-react", tools: {quixos: source, protocol: source, helpers: source, sdk: source}});
|
||||
await applyStructure(await planStructure(root, request));
|
||||
assert.match(await fs.readFile(path.join(root, "scripts/build-component.mjs"), "utf8"), /__quixos\/platform\/react/);
|
||||
assert.match(await fs.readFile(path.join(root, "src/impl/sourceGet.ts"), "utf8"), /component.js\?browser-source/);
|
||||
assert.match(await fs.readFile(path.join(root, "flake.nix"), "utf8"), /browserSources = true/);
|
||||
assert.equal(JSON.parse(await fs.readFile(path.join(root, "quixos.check.json"), "utf8")).options.messages["org.quixos.web-studio.ReactProps"].export, "opaqueReactPropsBinding");
|
||||
await assert.rejects(fs.access(path.join(root, "quixos.scaffold.json")));
|
||||
assert.equal(JSON.parse(await fs.readFile(path.join(root, "tsconfig.json"), "utf8")).compilerOptions.jsx, "react-jsx");
|
||||
});
|
||||
|
||||
test("package/function/migration scaffolds register implementations and refresh code digests without overwriting code", async (context) => {
|
||||
test("imperative scaffolds preserve authored wiring; migration sealing is explicit and separate", async (context) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "qx-recipes-"));
|
||||
context.after(() => fs.rm(root, {recursive: true, force: true}));
|
||||
await execFile("git", ["-C", root, "init"]);
|
||||
@@ -38,31 +42,23 @@ test("package/function/migration scaffolds register implementations and refresh
|
||||
await apply("migration", {...base, name: "upgrade", id: "export:upgrade", migration: {id: "upgrade-v2", scopeId: "board", from, to, predecessors: [], ports: [], contracts: {[from]: old, [to]: next}}});
|
||||
const migrationFile = path.join(root, base.directory, "src/migrations/upgrade.ts");
|
||||
await fs.appendFile(migrationFile, "\n// authored migration change\n");
|
||||
await apply("refresh", base);
|
||||
await sealMigrations(path.join(root, base.directory));
|
||||
assert.equal(await fs.readFile(filename, "utf8"), edited);
|
||||
const catalog = JSON.parse(await fs.readFile(path.join(root, base.directory, "quixos.migrations.json"), "utf8"));
|
||||
assert.equal(catalog.migrations[0].implementation.digest, contentDigest(await fs.readFile(migrationFile, "utf8")));
|
||||
const bindings = await fs.readFile(path.join(root, base.directory, "src/gen/qx.ts"), "utf8");
|
||||
assert.match(bindings, /export:play/);
|
||||
assert.match(await fs.readFile(path.join(root, base.directory, "src/migrate.ts"), "utf8"), /export:upgrade/);
|
||||
if (process.env.QX_SCAFFOLD_TEST_SDK) {
|
||||
const sdk = await fs.realpath(process.env.QX_SCAFFOLD_TEST_SDK);
|
||||
const packageRoot = path.join(root, base.directory);
|
||||
await fs.mkdir(path.join(packageRoot, "node_modules/@quixos"), {recursive: true});
|
||||
await fs.symlink(sdk, path.join(packageRoot, "node_modules/@quixos/camino-package-runtime"));
|
||||
await fs.symlink(path.join(sdk, "node_modules/@types"), path.join(packageRoot, "node_modules/@types"));
|
||||
await execFile(path.join(sdk, "node_modules/.bin/tsc"), ["--noEmit"], {cwd: packageRoot});
|
||||
await execFile("nix-instantiate", ["--parse", path.join(packageRoot, "flake.nix")]);
|
||||
}
|
||||
await assert.rejects(() => apply("function", {...base, name: "play", id: "export:play"}), /unique/);
|
||||
const declarations = path.join(root, base.directory, "package.qx");
|
||||
await fs.writeFile(declarations, (await fs.readFile(declarations, "utf8")).replace(/}\s*$/, ' function authored id "export:authored" : unit -> unit;\n}\n'));
|
||||
await apply("refresh", base);
|
||||
assert.match(await fs.readFile(path.join(root, base.directory, "src/server.ts"), "utf8"), /"authored":/);
|
||||
assert.match(await fs.readFile(path.join(root, base.directory, "src/impl/authored.ts"), "utf8"), /Implement authored/);
|
||||
const server = path.join(root, base.directory, "src/server.ts");
|
||||
await fs.appendFile(server, "\n// authored comment must survive\n");
|
||||
await apply("function", {...base, name: "another", id: "export:another"});
|
||||
assert.match(await fs.readFile(server, "utf8"), /authored comment must survive/);
|
||||
await assert.rejects(() => apply("refresh", base), /removed/);
|
||||
await assert.rejects(fs.access(path.join(root, base.directory, "src/impl/authored.ts")));
|
||||
assert.equal(await fs.readFile(filename, "utf8"), edited);
|
||||
await assert.rejects(() => planStructure(root, {kind: "package", source, resourceRoot: base.directory, validation: "syntax", files: [{
|
||||
await planStructure(root, {kind: "package", source, resourceRoot: base.directory, validation: "syntax", files: [{
|
||||
file: `${base.directory}/package.qx`, edits: [{operation: "replace", target: {kind: "packageResourceDecl", id: "package:chess"},
|
||||
source: 'package Other id "package:other" revision "package:other@1" {}'}],
|
||||
}]}), /scaffold-owned package identity/);
|
||||
}]});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user