Acquire installed portable operations with explicit authority and input coverage
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
import {
|
||||
compileCapabilityResourceSource,
|
||||
compileCapabilitySource,
|
||||
formatQx,
|
||||
} from "../src/capability-language/index.js";
|
||||
import type { InterfaceRevision, PackageRevision } from "../src/capability-model/types.js";
|
||||
import { compileQuery } from "../src/query/compile.js";
|
||||
import { readReaderFixture } from "./reader-fixture.js";
|
||||
const directory = resolve("test/fixtures/local-first-composite");
|
||||
export async function loadCompositeWorkspace() {
|
||||
const changed = new Set(["DocumentFactory", "DocumentMetadata", "CommentFactory"]);
|
||||
const read = (name: string) => readFile(resolve(directory, `${name}.qx`), "utf8");
|
||||
const source = { repository: "https://example.test/composite.git", commit: "b".repeat(40) };
|
||||
const interfaces = new Map<string, InterfaceRevision>();
|
||||
for (const name of [
|
||||
"DocumentData",
|
||||
"HighlightData",
|
||||
"CommentData",
|
||||
"DocumentActions",
|
||||
"DocumentFactory",
|
||||
"DocumentMetadata",
|
||||
"CommentFactory",
|
||||
]) {
|
||||
const result = compileCapabilityResourceSource(
|
||||
formatQx(await (changed.has(name) ? read(name) : readReaderFixture(`${name}.qx`))),
|
||||
{ source },
|
||||
);
|
||||
assert.ok(result.ok && result.resource.kind === "interface", JSON.stringify(result.diagnostics));
|
||||
interfaces.set(name, result.resource.revision);
|
||||
}
|
||||
const environment = { interfaces, interfaceClosure: [...interfaces.values()] },
|
||||
packages = new Map<string, PackageRevision>();
|
||||
for (const name of ["ReaderRuntime", "CommentRuntime"]) {
|
||||
const selected =
|
||||
name === "CommentRuntime" ? new Map([["CommentData", interfaces.get("CommentData")!]]) : interfaces;
|
||||
const result = compileCapabilityResourceSource(formatQx(await read(name)), {
|
||||
source,
|
||||
environment: { interfaces: selected, interfaceClosure: [...selected.values()] },
|
||||
});
|
||||
assert.ok(result.ok && result.resource.kind === "package", JSON.stringify(result.diagnostics));
|
||||
const revision = result.resource.revision;
|
||||
revision.checkedQueries = await Promise.all(
|
||||
(revision.queries ?? []).map((query) => compileQuery(query, [...interfaces.values()], readReaderFixture)),
|
||||
);
|
||||
packages.set(name, revision);
|
||||
}
|
||||
const result = compileCapabilitySource(formatQx(await read("workspace")), "workspace.qx", {
|
||||
...environment,
|
||||
packages,
|
||||
packageClosure: [...packages.values()],
|
||||
});
|
||||
assert.ok(result.ok, JSON.stringify(result.diagnostics));
|
||||
return result.workspace;
|
||||
}
|
||||
Reference in New Issue
Block a user