Add local-first execution authoring support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user