Make workspace authoring transitions and typed invocation coherent

This commit is contained in:
Timothy J. Aveni
2026-09-14 15:24:37 -07:00
parent 01ca965c7f
commit 8aac091f6c
13 changed files with 209 additions and 26 deletions
+1
View File
@@ -68,6 +68,7 @@ test("storage defaults and ownership changes invalidate consumers without requir
if (slot.kind === "state") slot.defaultValue = "Different default";
const report = planEvolution(before, after, { allowLegacy: true });
assert.equal(report.storageChanges.length, 1);
assert.deepEqual(report.migrationRequired, []);
assert.equal(report.runtimeActions[0]!.action, "replace");
assert.deepEqual(report.reviews, []);
assert.notDeepEqual(storageContracts(before), storageContracts(after));
+7 -6
View File
@@ -11,9 +11,14 @@ test("authoring lock excludes concurrent mutations and survives owner death", as
const root = await mkdtemp(path.join(os.tmpdir(), "qx-lock-test-"));
context.after(() => rm(root, {recursive: true, force: true}));
const filename = path.join(root, "lock");
const events: string[] = [];
let queued: Promise<void>;
await withFileLock(filename, async () => {
await assert.rejects(withFileLock(filename, async () => assert.fail("concurrent mutation")), /Another authoring command/);
queued = withFileLock(filename, async () => {events.push("second");});
events.push("first");
});
await queued!;
assert.deepEqual(events, ["first", "second"]);
const module = new URL("../src/capability-language/file-lock.js", import.meta.url).href;
const owner = spawn(process.execPath, ["--input-type=module", "-e",
`import {withFileLock} from ${JSON.stringify(module)}; await withFileLock(${JSON.stringify(filename)}, async () => {process.stdout.write('ready'); await new Promise(() => {});});`],
@@ -23,11 +28,7 @@ test("authoring lock excludes concurrent mutations and survives owner death", as
const exited = once(owner, "exit");
owner.kill("SIGKILL");
await exited;
// EOF release happens in the helper; wait a bounded amount for scheduling.
let acquired = false;
for (let attempt = 0; attempt < 30 && !acquired; attempt++) {
try { await withFileLock(filename, async () => {acquired = true;}); }
catch (error) { if (!/Another authoring command/.test(String(error))) throw error; }
}
await withFileLock(filename, async () => {acquired = true;});
assert.equal(acquired, true);
});
+6
View File
@@ -55,6 +55,12 @@ test("package/function/migration scaffolds register implementations and refresh
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/);
assert.equal(await fs.readFile(filename, "utf8"), edited);
await assert.rejects(() => 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" {}'}],