Build and activate checked component packages through normal source authoring (WI-12)
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { execFile as callback } from "node:child_process";
|
||||
import { promisify } from "node:util";
|
||||
import { scaffoldRecipe } from "../src/capability-language/scaffold-recipes.js";
|
||||
import { planStructure, applyStructure } from "../src/capability-language/structural-plan.js";
|
||||
const execFile = promisify(callback);
|
||||
test("checked component scaffolding composes with execution handlers without replacing authored files", async (context) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "qx-component-scaffold-"));
|
||||
context.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
await execFile("git", ["-C", root, "init"]);
|
||||
const source = { repository: "https://example.test/component.git", commit: "a".repeat(40) };
|
||||
const apply = async (
|
||||
command: Parameters<typeof scaffoldRecipe>[1],
|
||||
spec: Omit<Parameters<typeof scaffoldRecipe>[2], "source">,
|
||||
) => applyStructure(await planStructure(root, await scaffoldRecipe(root, command, { ...spec, source })));
|
||||
await apply("package", {
|
||||
name: "Widgets",
|
||||
id: "package:widgets",
|
||||
revision: "package:widgets@1",
|
||||
template: "typescript-component",
|
||||
tools: { quixos: source, protocol: source, helpers: source, sdk: source },
|
||||
});
|
||||
const packageFile = path.join(root, "package.qx");
|
||||
await fs.writeFile(packageFile, "import interface Data;\n" + (await fs.readFile(packageFile, "utf8")));
|
||||
await apply("component", {
|
||||
name: "Card",
|
||||
id: "component:card",
|
||||
declaration: 'component Card id "component:card" subject Data runtime react;',
|
||||
});
|
||||
assert.deepEqual(JSON.parse(await fs.readFile(path.join(root, "quixos.components.json"), "utf8")), {
|
||||
"component:card": { entry: "src/components/Card.tsx", export: "Card" },
|
||||
});
|
||||
const card = path.join(root, "src/components/Card.tsx");
|
||||
await fs.appendFile(card, "\n// authored extension\n");
|
||||
const retained = await fs.readFile(card, "utf8");
|
||||
await apply("function", {
|
||||
name: "echo",
|
||||
id: "echo",
|
||||
declaration: 'function echo id "echo" : string -> string execution snapshot targets [browser,server];',
|
||||
});
|
||||
await apply("component", {
|
||||
name: "Details",
|
||||
id: "component:details",
|
||||
declaration: 'component Details id "component:details" subject Data runtime react;',
|
||||
});
|
||||
assert.equal(await fs.readFile(card, "utf8"), retained);
|
||||
assert.match(await fs.readFile(path.join(root, "src/server.ts"), "utf8"), /echo/);
|
||||
assert.match(await fs.readFile(path.join(root, "flake.nix"), "utf8"), /react \? null/);
|
||||
await assert.rejects(
|
||||
apply("component", {
|
||||
name: "Card",
|
||||
id: "component:other",
|
||||
declaration: 'component Card id "component:other" subject Data runtime react;',
|
||||
}),
|
||||
/unique/,
|
||||
);
|
||||
await assert.rejects(
|
||||
apply("component", {
|
||||
name: "Injected",
|
||||
id: "component:inject",
|
||||
declaration:
|
||||
'component Injected id "component:inject" subject Data runtime react; function sneak id "sneak" : unit -> unit;',
|
||||
}),
|
||||
/exactly one/,
|
||||
);
|
||||
});
|
||||
|
||||
test("controller scaffolding preserves existing registrations and rejects duplicate identities", async (context) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "qx-controller-scaffold-"));
|
||||
context.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
await execFile("git", ["-C", root, "init"]);
|
||||
const source = { repository: "https://example.test/adapter.git", commit: "a".repeat(40) };
|
||||
const apply = async (
|
||||
command: Parameters<typeof scaffoldRecipe>[1],
|
||||
spec: Omit<Parameters<typeof scaffoldRecipe>[2], "source">,
|
||||
) => applyStructure(await planStructure(root, await scaffoldRecipe(root, command, { ...spec, source })));
|
||||
await apply("package", {
|
||||
name: "Adapter",
|
||||
id: "adapter",
|
||||
revision: "adapter@1",
|
||||
tools: { quixos: source, protocol: source, helpers: source },
|
||||
});
|
||||
const controller = {
|
||||
subject: "display@1",
|
||||
snapshot: "display:requested",
|
||||
remote: "display:apply",
|
||||
input: "value" as const,
|
||||
};
|
||||
await apply("controller", { id: "display:controller", controller });
|
||||
await apply("controller", { id: "display:monitor", controller: { ...controller, snapshot: "display:status" } });
|
||||
const entries = JSON.parse(await fs.readFile(path.join(root, "quixos.controllers.json"), "utf8")).controllers;
|
||||
assert.equal(entries.length, 2);
|
||||
assert.deepEqual(entries[0], { id: "display:controller", ...controller });
|
||||
await assert.rejects(apply("controller", { id: "display:controller", controller }), /duplicate/);
|
||||
});
|
||||
@@ -84,3 +84,21 @@ test("explicit budgets can exceed defaults without exceeding wire bounds", () =>
|
||||
assert.equal(result.resource.revision.queries![0]!.budgets.rows, 5000);
|
||||
assert.equal(compile("4294967296").ok, false);
|
||||
});
|
||||
|
||||
test("query identity follows public contracts, not source retention commits", async () => {
|
||||
const document = async () => "query Rows {root {objects(first:10) {entries {node {range {start}}}}}}";
|
||||
const before = await compileQuery(declaration, [iface], document);
|
||||
const retained = {
|
||||
...iface,
|
||||
source: { ...iface.source, repository: "https://other.test/interfaces.git", commit: "b".repeat(40) },
|
||||
};
|
||||
assert.equal((await compileQuery(declaration, [retained], document)).definitionDigest, before.definitionDigest);
|
||||
const changed = structuredClone(retained);
|
||||
changed.members[0]!.operations[0]!.id = "changed:get" as (typeof changed.members)[0]["operations"][0]["id"];
|
||||
assert.notEqual((await compileQuery(declaration, [changed], document)).definitionDigest, before.definitionDigest);
|
||||
assert.notEqual(
|
||||
(await compileQuery({ ...declaration, budgets: { ...declaration.budgets, rows: 17 } }, [retained], document))
|
||||
.definitionDigest,
|
||||
before.definitionDigest,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -7,122 +7,9 @@ import { execFile as callback } from "node:child_process";
|
||||
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";
|
||||
import { reactPlatformTypes } from "../src/bindings/react-platform.js";
|
||||
const execFile = promisify(callback);
|
||||
|
||||
test("React preset applies its browser build script and shared-platform imports", async (context) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "qx-react-recipe-"));
|
||||
context.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
await execFile("git", ["-C", root, "init"]);
|
||||
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, "src/impl/sourceGet.ts"), "utf8"), /component.js\?browser-source/);
|
||||
assert.match(await fs.readFile(path.join(root, "flake.nix"), "utf8"), /browserSources = true/);
|
||||
assert.equal(await fs.readFile(path.join(root, "src/gen/web-studio-react-runtime.d.ts"), "utf8"), reactPlatformTypes);
|
||||
assert.match(await fs.readFile(path.join(root, "src/browser-assets.d.ts"), "utf8"), /declare module "\*\.css"/);
|
||||
assert.deepEqual(
|
||||
JSON.parse(await fs.readFile(path.join(root, "quixos.check.json"), "utf8")).options.react.propsExports,
|
||||
[],
|
||||
);
|
||||
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("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"]);
|
||||
await fs.writeFile(path.join(root, ".gitignore"), ".quixos/\n");
|
||||
const source = { repository: "https://example.test/chess.git", commit: "a".repeat(40) };
|
||||
const base = { source, directory: "packages/Chess" };
|
||||
const apply = async (command: Parameters<typeof scaffoldRecipe>[1], input: Parameters<typeof scaffoldRecipe>[2]) =>
|
||||
applyStructure(await planStructure(root, await scaffoldRecipe(root, command, input)));
|
||||
await apply("package", {
|
||||
...base,
|
||||
name: "Chess",
|
||||
id: "package:chess",
|
||||
revision: "package:chess@1",
|
||||
tools: { quixos: source, protocol: source, helpers: source, sdk: source },
|
||||
});
|
||||
await apply("function", { ...base, name: "play", id: "export:play" });
|
||||
const filename = path.join(root, base.directory, "src/impl/play.ts");
|
||||
const edited =
|
||||
'import type {Implementation} from "../gen/qx.js";\nexport const handler: Implementation["play"] = async () => null;\n';
|
||||
await fs.writeFile(filename, edited);
|
||||
const old = { version: 1 },
|
||||
next = { version: 2 },
|
||||
from = contentDigest(old),
|
||||
to = contentDigest(next);
|
||||
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 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")));
|
||||
assert.match(await fs.readFile(path.join(root, base.directory, "src/migrate.ts"), "utf8"), /export:upgrade/);
|
||||
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',
|
||||
),
|
||||
);
|
||||
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 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" {}',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("execution scaffolds route typed handlers by declared effect and target without legacy lifecycle files", async (context) => {
|
||||
const root = await fs.mkdtemp(path.join(os.tmpdir(), "qx-execution-recipe-"));
|
||||
context.after(() => fs.rm(root, { recursive: true, force: true }));
|
||||
@@ -164,7 +51,7 @@ test("execution scaffolds route typed handlers by declared effect and target wit
|
||||
await assert.rejects(add("both", "transaction targets [browser, server]"), /unique/);
|
||||
await assert.rejects(add("invalid", "snapshot targets [remote]"), /browser\/server/);
|
||||
await assert.rejects(apply("function", { name: "missing", id: "export:missing" }), /explicit execution/);
|
||||
await assert.rejects(apply("migration", { name: "migration", id: "export:migration" }), /not supported/);
|
||||
await assert.rejects(apply("migration", { name: "migration", id: "export:migration" }), /retired/);
|
||||
});
|
||||
|
||||
test("query scaffold preserves placement and inserts its named GraphQL document atomically", async (context) => {
|
||||
@@ -176,6 +63,7 @@ test("query scaffold preserves placement and inserts its named GraphQL document
|
||||
path.join(root, "package.qx"),
|
||||
'import interface Task;\npackage Tasks id "tasks" revision "tasks@1" {}\n',
|
||||
);
|
||||
await fs.writeFile(path.join(root, "quixos.check.json"), JSON.stringify({ backend: "execution" }));
|
||||
const request = (name: string, placement: string) => ({
|
||||
source,
|
||||
name,
|
||||
|
||||
Reference in New Issue
Block a user