Add local-first execution authoring support
This commit is contained in:
@@ -131,3 +131,7 @@ const compoundCrdt = await compoundCrdtPlan();
|
||||
await mkdir("dist/portable-reader/compound-crdt", { recursive: true });
|
||||
await writeFile("dist/portable-reader/compound-crdt/plan.json", JSON.stringify(compoundCrdt));
|
||||
await writeFile("dist/portable-reader/compound-crdt/kernel.json", JSON.stringify(compileKernelProgram(compoundCrdt)));
|
||||
|
||||
const { emitExecutionScaffold } = await import("./execution-scaffold-fixture.js");
|
||||
const executionScaffold = await emitExecutionScaffold("dist/portable-reader/execution-scaffold/source");
|
||||
await writeFile("dist/portable-reader/execution-scaffold/plan.json", JSON.stringify(executionScaffold));
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { scaffoldRecipe } from "../src/capability-language/scaffold-recipes.js";
|
||||
import { planStructure, applyStructure } from "../src/capability-language/structural-plan.js";
|
||||
import { compileCapabilityResourceSource, compileCapabilitySource } from "../src/capability-language/parser.js";
|
||||
import { compileExecutionPlan } from "../src/execution-world/plan.js";
|
||||
|
||||
/** Exercise the authoring insertion path, then let the Nix gate build its actual flake output. */
|
||||
export async function emitExecutionScaffold(root: string) {
|
||||
await fs.mkdir(root, { recursive: true });
|
||||
execFileSync("git", ["-C", root, "init"], { stdio: "ignore" });
|
||||
const source = { repository: "https://example.test/scaffold.git", commit: "a".repeat(40) };
|
||||
const apply = async (
|
||||
command: Parameters<typeof scaffoldRecipe>[1],
|
||||
spec: Partial<Parameters<typeof scaffoldRecipe>[2]>,
|
||||
) => applyStructure(await planStructure(root, await scaffoldRecipe(root, command, { source, ...spec })));
|
||||
await apply("package", {
|
||||
name: "Scaffold",
|
||||
id: "package:scaffold",
|
||||
revision: "package:scaffold@1",
|
||||
template: "typescript-execution",
|
||||
tools: { quixos: source, protocol: source, helpers: source, sdk: source },
|
||||
});
|
||||
for (const [name, execution] of [
|
||||
["echo", "snapshot targets [browser, server]"],
|
||||
["serverEcho", "snapshot targets [server]"],
|
||||
["remoteEcho", "remote"],
|
||||
]) {
|
||||
await apply("function", {
|
||||
name,
|
||||
id: "scaffold:" + name,
|
||||
declaration: `function ${name} id "scaffold:${name}" : string -> string execution ${execution};`,
|
||||
});
|
||||
const file = path.join(root, `src/impl/${name}.ts`);
|
||||
const placeholder = await fs.readFile(file, "utf8");
|
||||
await fs.writeFile(file, placeholder.replace(/async \(_context\) => \{.*\};/, "async ({ input }) => input;"));
|
||||
}
|
||||
const pkg = compileCapabilityResourceSource(await fs.readFile(path.join(root, "package.qx"), "utf8"), { source });
|
||||
assert.ok(pkg.ok && pkg.resource.kind === "package", JSON.stringify(pkg.diagnostics));
|
||||
const workspace = compileCapabilitySource(
|
||||
`workspace W id "scaffold-workspace" revision "scaffold-workspace@1" commit "${source.commit}" { import package Scaffold; }`,
|
||||
"workspace.qx",
|
||||
{
|
||||
packages: new Map([["Scaffold", pkg.resource.revision]]),
|
||||
},
|
||||
);
|
||||
assert.ok(workspace.ok, JSON.stringify(workspace.diagnostics));
|
||||
await fs.rm(path.join(root, ".quixos"), { recursive: true, force: true });
|
||||
await fs.rm(path.join(root, ".git"), { recursive: true, force: true });
|
||||
return compileExecutionPlan(workspace.workspace);
|
||||
}
|
||||
@@ -122,3 +122,47 @@ test("imperative scaffolds preserve authored wiring; migration sealing is explic
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
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 }));
|
||||
await execFile("git", ["-C", root, "init"]);
|
||||
const source = { repository: "https://example.test/execution.git", commit: "a".repeat(40) };
|
||||
const apply = async (
|
||||
command: Parameters<typeof scaffoldRecipe>[1],
|
||||
spec: Partial<Parameters<typeof scaffoldRecipe>[2]>,
|
||||
) => applyStructure(await planStructure(root, await scaffoldRecipe(root, command, { source, ...spec })));
|
||||
await apply("package", {
|
||||
name: "Execution",
|
||||
id: "package:execution",
|
||||
revision: "package:execution@1",
|
||||
template: "typescript-execution",
|
||||
tools: { quixos: source, protocol: source, helpers: source, sdk: source },
|
||||
});
|
||||
for (const file of ["quixos.migrations.json", "src/migrate.ts", "descriptor.quixos-package.txtpb"])
|
||||
await assert.rejects(fs.access(path.join(root, file)));
|
||||
await fs.appendFile(path.join(root, "src/server.ts"), "\n// Preserve authored code\n");
|
||||
const add = (name: string, execution: string) =>
|
||||
apply("function", {
|
||||
name,
|
||||
id: "export:" + name,
|
||||
declaration: `function ${name} id "export:${name}" : unit -> unit execution ${execution};`,
|
||||
});
|
||||
await add("both", "transaction targets [browser, server]");
|
||||
await add("serverOnly", "snapshot targets [server]");
|
||||
await add("asyncWork", "remote");
|
||||
const read = (file: string) => fs.readFile(path.join(root, file), "utf8");
|
||||
assert.match(await read("src/browser.ts"), /"both":/);
|
||||
assert.doesNotMatch(await read("src/browser.ts"), /serverOnly|asyncWork/);
|
||||
assert.match(await read("src/server.ts"), /"serverOnly":/);
|
||||
assert.match(await read("src/server.ts"), /Preserve authored code/);
|
||||
assert.match(await read("src/remote.ts"), /"asyncWork":/);
|
||||
assert.match(await read("src/impl/asyncWork.ts"), /RemoteImplementation/);
|
||||
assert.match(await read("src/impl/both.ts"), /PortableImplementation/);
|
||||
assert.match(await read("flake.nix"), /checkedArtifacts/);
|
||||
assert.match(await read("flake.nix"), /entries.browser/);
|
||||
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/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user