@pbuilder/sdk 0.17.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +69 -3
- package/dist/acl/irwire/stdio-engine-client.d.ts +1 -1
- package/dist/acl/irwire/stdio-engine-client.js +3 -2
- package/dist/bin/pbuilder-codegen.js +59 -1
- package/dist/bin/pbuilder-conformance.d.ts +2 -0
- package/dist/bin/pbuilder-conformance.js +45 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.d.ts +12 -3
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.js +23 -9
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/expander.js +4 -4
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.d.ts +2 -1
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.js +56 -6
- package/dist/bounded-contexts/authoring/domain/entities/dialect-handle.d.ts +2 -1
- package/dist/bounded-contexts/authoring/domain/entities/dialect-handle.js +108 -30
- package/dist/bounded-contexts/authoring/domain/ports/engine-client.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/services/define-dialect.d.ts +48 -10
- package/dist/bounded-contexts/authoring/domain/services/define-dialect.js +37 -9
- package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.d.ts +1 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/input-rejection.js +4 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-parse.d.ts +3 -2
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-parse.js +46 -4
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.d.ts +16 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-validate.js +125 -0
- package/dist/bounded-contexts/authoring/domain/valueobjects/authoring-error.d.ts +3 -2
- package/dist/bounded-contexts/authoring/domain/valueobjects/authoring-error.js +2 -0
- package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.d.ts +17 -0
- package/dist/bounded-contexts/authoring/domain/valueobjects/schema-model.js +1 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +1 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +23 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.d.ts +8 -5
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/index.js +7 -4
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/ops.d.ts +1 -1
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/aspnet/ops.js +20 -7
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.d.ts +20 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/index.js +19 -3
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/ops.d.ts +5 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/msbuild/ops.js +89 -20
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/ast.d.ts +2 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/ast.js +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +3 -3
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/ast.d.ts +2 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/ast.js +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +2 -2
- package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +10 -12
- package/dist/bounded-contexts/authoring/testing/conformance/index.js +17 -2
- package/dist/bounded-contexts/authoring/testing/conformance/run-package.d.ts +37 -0
- package/dist/bounded-contexts/authoring/testing/conformance/run-package.js +209 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +13 -4
- package/dist/bounded-contexts/authoring/testing/harness/index.js +10 -4
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.d.ts +3 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/bootstrap-bridge.js +2 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js +69 -3
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.d.ts +24 -0
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.js +34 -1
- package/dist/conformance/index.d.ts +1 -0
- package/dist/conformance/index.js +1 -0
- package/dist/dialect/index.d.ts +2 -0
- package/dist/dialect/index.js +3 -0
- package/dist/runner-manifest.json +12 -12
- package/package.json +8 -2
|
@@ -26,3 +26,5 @@ export declare function parseJsx(source: string): SourceFile;
|
|
|
26
26
|
* own `getFullText()` does not carry it.
|
|
27
27
|
*/
|
|
28
28
|
export declare function print(ast: SourceFile): string;
|
|
29
|
+
/** Forgets a tree the handle re-parsed away from, so every node kept from it throws when used (A-8). */
|
|
30
|
+
export declare function retire(ast: SourceFile): void;
|
|
@@ -98,3 +98,7 @@ export function print(ast) {
|
|
|
98
98
|
const text = ast.getFullText();
|
|
99
99
|
return hadBom.get(ast) === true ? BOM + text : text;
|
|
100
100
|
}
|
|
101
|
+
/** Forgets a tree the handle re-parsed away from, so every node kept from it throws when used (A-8). */
|
|
102
|
+
export function retire(ast) {
|
|
103
|
+
ast.forget();
|
|
104
|
+
}
|
|
@@ -8,12 +8,12 @@ import { byExtension, defineDialect, defineOpPack, overrideOps, withOps, without
|
|
|
8
8
|
import { dialectError } from "../../../../domain/valueobjects/dialect-error.js";
|
|
9
9
|
import { addClassProperty } from "../typescript/class-property.js";
|
|
10
10
|
import { typescriptOps } from "../typescript/pack.js";
|
|
11
|
-
import { parse, parseJsx, print } from "./ast.js";
|
|
11
|
+
import { parse, parseJsx, print, retire } from "./ast.js";
|
|
12
12
|
import { addComponentProp, addHookCall, addJsxChild, removeJsxProp, renameJsxElement, setJsxProp, wrapJsxElement, } from "./ops.js";
|
|
13
13
|
export * as astLibrary from "ts-morph";
|
|
14
14
|
const jsxOps = defineOpPack({ setJsxProp, removeJsxProp, addJsxChild, wrapJsxElement, addHookCall, addComponentProp, renameJsxElement });
|
|
15
|
-
const tsxDialect = withOps(defineDialect({ extensions: [".tsx"], ast: { parse, print }, ops: {} }), typescriptOps, jsxOps);
|
|
16
|
-
const jsxDialect = overrideOps(withoutOps(defineDialect({ extensions: [".jsx"], ast: { parse: parseJsx, print }, ops: tsxDialect.ops }), ["addTypeImport", "addComponentProp"], "they write TypeScript type syntax, which a .jsx file cannot hold"), {
|
|
15
|
+
const tsxDialect = withOps(defineDialect({ extensions: [".tsx"], ast: { parse, print, retire }, ops: {} }), typescriptOps, jsxOps);
|
|
16
|
+
const jsxDialect = overrideOps(withoutOps(defineDialect({ extensions: [".jsx"], ast: { parse: parseJsx, print, retire }, ops: tsxDialect.ops }), ["addTypeImport", "addComponentProp"], "they write TypeScript type syntax, which a .jsx file cannot hold"), {
|
|
17
17
|
addClassProperty: (ast, className, name, initializer, options) => {
|
|
18
18
|
if (options?.scope !== undefined || options?.readonly !== undefined) {
|
|
19
19
|
throw dialectError("addClassProperty's `scope` and `readonly` are TypeScript modifiers, which a .jsx file cannot hold — " +
|
|
@@ -45,3 +45,5 @@ export declare function parse(source: string, extension?: ".ts" | ".tsx" | ".jsx
|
|
|
45
45
|
*/
|
|
46
46
|
export declare function print(ast: SourceFile): string;
|
|
47
47
|
export declare function omitsSemicolons(ast: SourceFile): boolean;
|
|
48
|
+
/** Forgets a tree the handle re-parsed away from, so every node kept from it throws when used (A-8). */
|
|
49
|
+
export declare function retire(ast: SourceFile): void;
|
|
@@ -121,3 +121,7 @@ export function omitsSemicolons(ast) {
|
|
|
121
121
|
const terminated = terminable.filter((statement) => statement.getText().endsWith(";")).length;
|
|
122
122
|
return terminable.length - terminated > terminated;
|
|
123
123
|
}
|
|
124
|
+
/** Forgets a tree the handle re-parsed away from, so every node kept from it throws when used (A-8). */
|
|
125
|
+
export function retire(ast) {
|
|
126
|
+
ast.forget();
|
|
127
|
+
}
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
// Namespace import surface (ADR-0003): `import * as ts from "@pbuilder/sdk/typescript"`,
|
|
7
7
|
// then `ts.find(path)`.
|
|
8
8
|
import { defineDialect, defineOpPack, withOps } from "../../../../domain/services/define-dialect.js";
|
|
9
|
-
import { parse, print } from "./ast.js";
|
|
9
|
+
import { parse, print, retire } from "./ast.js";
|
|
10
10
|
import { typescriptOps } from "./pack.js";
|
|
11
11
|
export * as astLibrary from "ts-morph";
|
|
12
12
|
const opsPack = defineOpPack(typescriptOps);
|
|
13
13
|
const baseDialect = defineDialect({
|
|
14
14
|
extensions: [".ts"],
|
|
15
|
-
ast: { parse, print },
|
|
15
|
+
ast: { parse, print, retire },
|
|
16
16
|
ops: {},
|
|
17
17
|
});
|
|
18
18
|
const typescriptDialect = withOps(baseDialect, opsPack);
|
|
@@ -59,6 +59,16 @@ export interface DialectFixture<Library extends object = object> {
|
|
|
59
59
|
expect: string;
|
|
60
60
|
modify: (ast: unknown, library: Library) => void;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* A-11 stale nodes, for a dialect whose AST hands out nodes: `keep` takes a node from a tree
|
|
64
|
+
* parsed from `seed`, and `use` edits through it. After the tree is re-parsed and retired,
|
|
65
|
+
* `use` must throw.
|
|
66
|
+
*/
|
|
67
|
+
staleNode?: {
|
|
68
|
+
seed: string;
|
|
69
|
+
keep: (ast: unknown) => unknown;
|
|
70
|
+
use: (node: unknown) => void;
|
|
71
|
+
};
|
|
62
72
|
}
|
|
63
73
|
/**
|
|
64
74
|
* One op-invocation recipe `testOpPack` applies to a seeded target: seed the file, run the
|
|
@@ -117,18 +127,6 @@ export interface OpPackFixture {
|
|
|
117
127
|
/** The op-invocation recipes `testOpPack` applies — REQUIRED (rev 5, ADR-0012 amendment). */
|
|
118
128
|
exercises: readonly OpExercise[];
|
|
119
129
|
}
|
|
120
|
-
/**
|
|
121
|
-
* Runs the conformance suite for a dialect: asserts parse/print no-op round-trip fidelity
|
|
122
|
-
* (REQ-DC-01) — `print(parse(sample)) === sample` BYTE-EXACT, never AST-equal, for every
|
|
123
|
-
* sample in `fixture.samples` PLUS the four mandatory adversarial samples the kit injects on
|
|
124
|
-
* every run (REQ-DC-06 — additive, not opt-out-able). Before each round-trip check, verifies
|
|
125
|
-
* `fixture.dialect.ast.parse` is a REAL parser, not an identity/stub function (REQ-DC-08): a
|
|
126
|
-
* `parse` returning `null`/`undefined`, or the input string unchanged, fails BEFORE the
|
|
127
|
-
* round-trip assertion could vacuously pass.
|
|
128
|
-
*
|
|
129
|
-
* Requires runtime library exports matching independent adapter evidence, then exercises
|
|
130
|
-
* the actual module's `find().modify()` through a real run with byte-exact emitted output.
|
|
131
|
-
*/
|
|
132
130
|
export declare function testDialect<Library extends object>(fixture: DialectFixture<Library>): Promise<void>;
|
|
133
131
|
/**
|
|
134
132
|
* Runs the conformance suite for an op-pack against a REAL base dialect (never a mock,
|
|
@@ -61,7 +61,7 @@ async function runExercise(dialect, exercise, opts) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
await handle;
|
|
64
|
-
});
|
|
64
|
+
}, { declaredDialects: dialect.name === undefined ? [] : [dialect.name] });
|
|
65
65
|
await runner(undefined, { client });
|
|
66
66
|
const directives = emitted.flatMap((b) => b.instructions);
|
|
67
67
|
const modifies = directives
|
|
@@ -150,6 +150,19 @@ function runRoundTripProbe(dialectAst, samples, label) {
|
|
|
150
150
|
* Requires runtime library exports matching independent adapter evidence, then exercises
|
|
151
151
|
* the actual module's `find().modify()` through a real run with byte-exact emitted output.
|
|
152
152
|
*/
|
|
153
|
+
function probeStaleNode(ast, staleNode) {
|
|
154
|
+
const old = ast.parse(staleNode.seed);
|
|
155
|
+
const node = staleNode.keep(old);
|
|
156
|
+
ast.parse(staleNode.seed);
|
|
157
|
+
ast.retire?.(old);
|
|
158
|
+
try {
|
|
159
|
+
staleNode.use(node);
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
throw new Error("testDialect: A-11 stale node — a node kept from before a re-parse is still usable; give the dialect's ast a retire(ast) that makes the old tree's nodes fail");
|
|
165
|
+
}
|
|
153
166
|
export async function testDialect(fixture) {
|
|
154
167
|
const module = fixture.module;
|
|
155
168
|
if (!module || typeof module.find !== "function") {
|
|
@@ -170,6 +183,8 @@ export async function testDialect(fixture) {
|
|
|
170
183
|
}
|
|
171
184
|
const samples = [...fixture.samples, ...mandatoryAdversarialSamples(fixture.libraryExercise.seed)];
|
|
172
185
|
runRoundTripProbe(fixture.dialect.ast, samples, "testDialect");
|
|
186
|
+
if (fixture.staleNode !== undefined)
|
|
187
|
+
probeStaleNode(fixture.dialect.ast, fixture.staleNode);
|
|
173
188
|
const exercise = fixture.libraryExercise;
|
|
174
189
|
const { client, emitted } = createRunVehicle({ [exercise.path]: exercise.seed });
|
|
175
190
|
// A-11: `find` must reject an extension the dialect does not declare. Probed inside the run,
|
|
@@ -184,7 +199,7 @@ export async function testDialect(fixture) {
|
|
|
184
199
|
acceptedUndeclared = false;
|
|
185
200
|
}
|
|
186
201
|
await module.find(exercise.path).modify((ast) => exercise.modify(ast, module.astLibrary));
|
|
187
|
-
});
|
|
202
|
+
}, { declaredDialects: fixture.dialect.name === undefined ? [] : [fixture.dialect.name] });
|
|
188
203
|
await run(undefined, { client });
|
|
189
204
|
if (acceptedUndeclared) {
|
|
190
205
|
throw new Error(`testDialect: find accepted "${undeclaredPath}", an undeclared extension (A-11)`);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface ConformanceFailure {
|
|
2
|
+
case: string;
|
|
3
|
+
reason: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ConformanceReport {
|
|
6
|
+
passed: boolean;
|
|
7
|
+
dialect: string;
|
|
8
|
+
version: string;
|
|
9
|
+
failures: ConformanceFailure[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Loads the fixture of the dialect package in `dir` and runs it. Throws only when the fixture
|
|
13
|
+
* cannot run: the package.json is unreadable or has no name, or a module the fixture imports
|
|
14
|
+
* cannot be resolved. Every finding about the dialect is a failure in the report.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* const report = await checkDialectPackage("/cache/npm/@company/ini-dialect/1.0.0/package");
|
|
18
|
+
* if (!report.passed) console.log(report.failures.map((failure) => failure.case));
|
|
19
|
+
*/
|
|
20
|
+
export declare function checkDialectPackage(dir: string): Promise<ConformanceReport>;
|
|
21
|
+
export interface LocalDialect {
|
|
22
|
+
/** The key of the dialect's declaration in the Manifest. */
|
|
23
|
+
name: string;
|
|
24
|
+
/** The dialect's base file, the module that exports the Dialect. */
|
|
25
|
+
path: string;
|
|
26
|
+
/** The file that exports the dialect's conformance fixture data. */
|
|
27
|
+
conformance: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Runs the conformance fixture of a local dialect (CA-18). The fixture data must test a Dialect
|
|
31
|
+
* named after the declaration's key and exported by the base file, and sit in the base file's
|
|
32
|
+
* folder. Throws only when a module the fixture imports cannot be resolved.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* const report = await checkLocalDialect({ name: "ini", path: "/ws/dialects/ini/index.ts", conformance: "/ws/dialects/ini/conformance.ts" });
|
|
36
|
+
*/
|
|
37
|
+
export declare function checkLocalDialect({ name, path, conformance }: LocalDialect): Promise<ConformanceReport>;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// CA-13 / CA-18 / A-16: runs the conformance fixture of a dialect, published (`<pkg>/conformance`)
|
|
2
|
+
// or local (the file its declaration names). The report names each broken check by a fixed case and reason, never by the fixture's own message,
|
|
3
|
+
// which may carry the author's samples or the text of an error their code threw (A-87).
|
|
4
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
5
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
6
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
7
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
return path;
|
|
11
|
+
};
|
|
12
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
13
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
14
|
+
import { pathToFileURL } from "node:url";
|
|
15
|
+
import { testDialect } from "./index.js";
|
|
16
|
+
const FIXTURE_MISSING = {
|
|
17
|
+
case: "fixture_missing",
|
|
18
|
+
reason: "CA-13: the package exports no ./conformance fixture",
|
|
19
|
+
};
|
|
20
|
+
const FIXTURE_INVALID = {
|
|
21
|
+
case: "fixture_invalid",
|
|
22
|
+
reason: "CA-13: the default export of ./conformance is not a DialectFixture",
|
|
23
|
+
};
|
|
24
|
+
const NAME_MISMATCH = {
|
|
25
|
+
case: "name_mismatch",
|
|
26
|
+
reason: "A-16: the dialect's name is not the name of its package",
|
|
27
|
+
};
|
|
28
|
+
const LOCAL_NAME_MISMATCH = {
|
|
29
|
+
case: "name_mismatch",
|
|
30
|
+
reason: "A-16: the dialect's name is not the key of its declaration",
|
|
31
|
+
};
|
|
32
|
+
const BASE_MISMATCH = {
|
|
33
|
+
case: "base_mismatch",
|
|
34
|
+
reason: "A-16: the fixture data tests a Dialect other than the one its base file exports",
|
|
35
|
+
};
|
|
36
|
+
// Matched against testDialect's own message text, first match wins.
|
|
37
|
+
const CHECKS = [
|
|
38
|
+
["REQ-DC-08", { case: "real_parse", reason: "A-11: parse must return an AST distinct from the source" }],
|
|
39
|
+
["REQ-DC-01", { case: "round_trip", reason: "A-11: print(parse(source)) must give back the source byte for byte" }],
|
|
40
|
+
["stale node", { case: "stale_node", reason: "A-11: a node kept from before a re-parse must fail when used" }],
|
|
41
|
+
["undeclared extension", { case: "undeclared_extension", reason: "A-11: find must reject an extension the dialect does not declare" }],
|
|
42
|
+
["library exercise", { case: "library_exercise", reason: "A-11: the library exercise must emit exactly the expected modify" }],
|
|
43
|
+
["testDialect: module must", { case: "module_shape", reason: "A-11: the module must expose a callable find and its runtime astLibrary" }],
|
|
44
|
+
["expectedAstLibrary", { case: "module_shape", reason: "A-11: the module must expose a callable find and its runtime astLibrary" }],
|
|
45
|
+
["astLibrary runtime library mismatch", { case: "module_shape", reason: "A-11: the module's astLibrary must be the adapter's own library" }],
|
|
46
|
+
];
|
|
47
|
+
const FIXTURE_THREW = { case: "fixture_threw", reason: "A-11: the fixture's own code threw while it ran" };
|
|
48
|
+
const BASE_THREW = { case: "fixture_threw", reason: "A-16: the dialect's base file threw while it loaded" };
|
|
49
|
+
function classify(err) {
|
|
50
|
+
const message = err instanceof Error ? err.message : "";
|
|
51
|
+
return CHECKS.find(([marker]) => message.includes(marker))?.[1] ?? FIXTURE_THREW;
|
|
52
|
+
}
|
|
53
|
+
const CONDITIONS = ["bun", "import", "default"];
|
|
54
|
+
// The engine's pointer dir (pointerdir.go) picks targets the same way, so the base file the fixture
|
|
55
|
+
// checks is the file the Run loads.
|
|
56
|
+
function pick(target) {
|
|
57
|
+
if (typeof target === "string")
|
|
58
|
+
return target;
|
|
59
|
+
if (typeof target !== "object" || target === null || Array.isArray(target))
|
|
60
|
+
return undefined;
|
|
61
|
+
for (const condition of CONDITIONS) {
|
|
62
|
+
const picked = pick(target[condition]);
|
|
63
|
+
if (picked !== undefined)
|
|
64
|
+
return picked;
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
// Only a subpath map can export `./conformance`, so a package with a fixture always picks its base
|
|
69
|
+
// file from `exports["."]`; with nothing there it has none and never falls back to `main`.
|
|
70
|
+
function exportTarget(pkg, subpath) {
|
|
71
|
+
const exports = pkg.exports;
|
|
72
|
+
if (typeof exports !== "object" || exports === null || !Object.keys(exports).some((key) => key.startsWith(".")))
|
|
73
|
+
return undefined;
|
|
74
|
+
return pick(exports[subpath]);
|
|
75
|
+
}
|
|
76
|
+
// A resolution failure says the install is incomplete, not that the dialect is wrong.
|
|
77
|
+
function isUnresolvedModule(err) {
|
|
78
|
+
if (typeof err !== "object" || err === null)
|
|
79
|
+
return false;
|
|
80
|
+
const { code, name, message } = err;
|
|
81
|
+
return (code === "ERR_MODULE_NOT_FOUND" ||
|
|
82
|
+
name === "ResolveMessage" ||
|
|
83
|
+
(typeof message === "string" && /Cannot find (module|package)/.test(message)));
|
|
84
|
+
}
|
|
85
|
+
function isInside(dir, file) {
|
|
86
|
+
const path = relative(dir, file);
|
|
87
|
+
return path !== "" && !path.startsWith("..") && !isAbsolute(path);
|
|
88
|
+
}
|
|
89
|
+
// As the pointer dir: a "./" target whose real path stays inside the package, with no probing.
|
|
90
|
+
function baseFile(dir, target) {
|
|
91
|
+
if (target === undefined || !target.startsWith("./"))
|
|
92
|
+
return undefined;
|
|
93
|
+
try {
|
|
94
|
+
const file = realpathSync(resolve(dir, target));
|
|
95
|
+
return isInside(realpathSync(dir), file) ? file : undefined;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function isFixture(value) {
|
|
102
|
+
if (typeof value !== "object" || value === null)
|
|
103
|
+
return false;
|
|
104
|
+
const fixture = value;
|
|
105
|
+
return typeof fixture.dialect === "object" && fixture.dialect !== null && Array.isArray(fixture.samples);
|
|
106
|
+
}
|
|
107
|
+
async function importModule(file) {
|
|
108
|
+
try {
|
|
109
|
+
return { ok: true, value: (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href))) };
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
if (isUnresolvedModule(err))
|
|
113
|
+
throw new Error("pbuilder-conformance: a module the fixture imports could not be resolved");
|
|
114
|
+
return { ok: false };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async function runFixture({ report, fixture: file, folder, absentFile, base, nameMismatch }) {
|
|
118
|
+
if (file === undefined) {
|
|
119
|
+
report.failures.push(FIXTURE_MISSING);
|
|
120
|
+
return report;
|
|
121
|
+
}
|
|
122
|
+
if (!isInside(folder, file)) {
|
|
123
|
+
report.failures.push(FIXTURE_INVALID);
|
|
124
|
+
return report;
|
|
125
|
+
}
|
|
126
|
+
if (!existsSync(file)) {
|
|
127
|
+
if (absentFile === "unresolved")
|
|
128
|
+
throw new Error("pbuilder-conformance: a module the fixture imports could not be resolved");
|
|
129
|
+
report.failures.push(FIXTURE_MISSING);
|
|
130
|
+
return report;
|
|
131
|
+
}
|
|
132
|
+
// Both checks hold for the file that loads, so a link out of the folder is refused too.
|
|
133
|
+
const real = realpathSync(file);
|
|
134
|
+
if (!isInside(realpathSync(folder), real)) {
|
|
135
|
+
report.failures.push(FIXTURE_INVALID);
|
|
136
|
+
return report;
|
|
137
|
+
}
|
|
138
|
+
// By real path, as the base file: Bun 1.4 can load one file twice under two spellings of its
|
|
139
|
+
// path, and the base check compares the Dialect by reference.
|
|
140
|
+
const loaded = await importModule(real);
|
|
141
|
+
if (!loaded.ok) {
|
|
142
|
+
report.failures.push(FIXTURE_THREW);
|
|
143
|
+
return report;
|
|
144
|
+
}
|
|
145
|
+
const fixture = loaded.value.default;
|
|
146
|
+
if (!isFixture(fixture)) {
|
|
147
|
+
report.failures.push(FIXTURE_INVALID);
|
|
148
|
+
return report;
|
|
149
|
+
}
|
|
150
|
+
if (fixture.dialect.name !== report.dialect)
|
|
151
|
+
report.failures.push(nameMismatch);
|
|
152
|
+
const baseModule = base !== undefined && existsSync(base) ? await importModule(base) : undefined;
|
|
153
|
+
if (baseModule !== undefined && !baseModule.ok) {
|
|
154
|
+
report.failures.push(BASE_THREW);
|
|
155
|
+
return report;
|
|
156
|
+
}
|
|
157
|
+
if (baseModule === undefined || !Object.values(baseModule.value).includes(fixture.dialect))
|
|
158
|
+
report.failures.push(BASE_MISMATCH);
|
|
159
|
+
try {
|
|
160
|
+
await testDialect(fixture);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
report.failures.push(classify(err));
|
|
164
|
+
}
|
|
165
|
+
report.passed = report.failures.length === 0;
|
|
166
|
+
return report;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Loads the fixture of the dialect package in `dir` and runs it. Throws only when the fixture
|
|
170
|
+
* cannot run: the package.json is unreadable or has no name, or a module the fixture imports
|
|
171
|
+
* cannot be resolved. Every finding about the dialect is a failure in the report.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* const report = await checkDialectPackage("/cache/npm/@company/ini-dialect/1.0.0/package");
|
|
175
|
+
* if (!report.passed) console.log(report.failures.map((failure) => failure.case));
|
|
176
|
+
*/
|
|
177
|
+
export async function checkDialectPackage(dir) {
|
|
178
|
+
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
179
|
+
if (typeof pkg.name !== "string" || pkg.name.length === 0) {
|
|
180
|
+
throw new Error(`pbuilder-conformance: the package.json in --dialect has no name`);
|
|
181
|
+
}
|
|
182
|
+
const fixture = exportTarget(pkg, "./conformance");
|
|
183
|
+
return runFixture({
|
|
184
|
+
report: { passed: false, dialect: pkg.name, version: typeof pkg.version === "string" ? pkg.version : "", failures: [] },
|
|
185
|
+
fixture: fixture === undefined ? undefined : resolve(dir, fixture),
|
|
186
|
+
folder: dir,
|
|
187
|
+
absentFile: "unresolved",
|
|
188
|
+
base: baseFile(dir, exportTarget(pkg, ".")),
|
|
189
|
+
nameMismatch: NAME_MISMATCH,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Runs the conformance fixture of a local dialect (CA-18). The fixture data must test a Dialect
|
|
194
|
+
* named after the declaration's key and exported by the base file, and sit in the base file's
|
|
195
|
+
* folder. Throws only when a module the fixture imports cannot be resolved.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* const report = await checkLocalDialect({ name: "ini", path: "/ws/dialects/ini/index.ts", conformance: "/ws/dialects/ini/conformance.ts" });
|
|
199
|
+
*/
|
|
200
|
+
export async function checkLocalDialect({ name, path, conformance }) {
|
|
201
|
+
return runFixture({
|
|
202
|
+
report: { passed: false, dialect: name, version: "", failures: [] },
|
|
203
|
+
fixture: resolve(conformance),
|
|
204
|
+
folder: dirname(resolve(path)),
|
|
205
|
+
absentFile: "missing",
|
|
206
|
+
base: existsSync(path) ? realpathSync(path) : undefined,
|
|
207
|
+
nameMismatch: LOCAL_NAME_MISMATCH,
|
|
208
|
+
});
|
|
209
|
+
}
|
|
@@ -9,7 +9,7 @@ import type { AuthoringError } from "../../domain/valueobjects/authoring-error.t
|
|
|
9
9
|
* console.log(result.tree.get("src/greeting.ts"));
|
|
10
10
|
* }
|
|
11
11
|
*/
|
|
12
|
-
export interface RunResult {
|
|
12
|
+
export interface RunResult<R = unknown> {
|
|
13
13
|
/**
|
|
14
14
|
* The committed tree (`ContractFake.committedTree()`), path → content. Committed writes
|
|
15
15
|
* ONLY — an unmodified seed path is never present here, even if the factory read it.
|
|
@@ -29,6 +29,12 @@ export interface RunResult {
|
|
|
29
29
|
* emit seam. On a factory throw, the original thrown value, unmodified.
|
|
30
30
|
*/
|
|
31
31
|
error: AuthoringError | unknown;
|
|
32
|
+
/**
|
|
33
|
+
* The Result the run committed (A-14): what the factory returned, validated against the
|
|
34
|
+
* `result` its `schema.json` declares. `null` is a Result; `undefined` means the run
|
|
35
|
+
* committed none, because the factory declares none or the run failed.
|
|
36
|
+
*/
|
|
37
|
+
result: R | undefined;
|
|
32
38
|
}
|
|
33
39
|
export type { Batch, Directive };
|
|
34
40
|
/**
|
|
@@ -36,7 +42,7 @@ export type { Batch, Directive };
|
|
|
36
42
|
* actually happened — closing the gap where a write-only factory (one that buffers
|
|
37
43
|
* directives but is never observed to commit them) has no author-facing test to catch it.
|
|
38
44
|
*
|
|
39
|
-
* `fn` is the bare `(input) =>
|
|
45
|
+
* `fn` is the bare `(input) => R | Promise<R>` author function — never a
|
|
40
46
|
* `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
|
|
41
47
|
* `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
|
|
42
48
|
* invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
|
|
@@ -57,6 +63,8 @@ export type { Batch, Directive };
|
|
|
57
63
|
* against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
|
|
58
64
|
* absent the run is the untyped, unvalidated tier, byte-identical to a run with no
|
|
59
65
|
* `packageDir` at all.
|
|
66
|
+
* @param options.declaredDialects - the names of the author-defined dialects the schematic's
|
|
67
|
+
* library declares in its Manifest; a handle of any other named dialect fails the run (A-16).
|
|
60
68
|
*
|
|
61
69
|
* @example
|
|
62
70
|
* import { runFactoryForTest } from "@pbuilder/sdk/testing";
|
|
@@ -83,7 +91,8 @@ export type { Batch, Directive };
|
|
|
83
91
|
* expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
|
|
84
92
|
* });
|
|
85
93
|
*/
|
|
86
|
-
export declare function runFactoryForTest<O>(fn: (input: O) =>
|
|
94
|
+
export declare function runFactoryForTest<O, R = void>(fn: (input: O) => R | Promise<R>, input: O, options?: {
|
|
87
95
|
seed?: Record<string, string>;
|
|
88
96
|
packageDir?: string | URL;
|
|
89
|
-
|
|
97
|
+
declaredDialects?: readonly string[];
|
|
98
|
+
}): Promise<RunResult<R>>;
|
|
@@ -6,7 +6,7 @@ import { nodePackageFiles } from "../../infrastructure/out/fs/package-files.js";
|
|
|
6
6
|
* actually happened — closing the gap where a write-only factory (one that buffers
|
|
7
7
|
* directives but is never observed to commit them) has no author-facing test to catch it.
|
|
8
8
|
*
|
|
9
|
-
* `fn` is the bare `(input) =>
|
|
9
|
+
* `fn` is the bare `(input) => R | Promise<R>` author function — never a
|
|
10
10
|
* `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
|
|
11
11
|
* `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
|
|
12
12
|
* invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
|
|
@@ -27,6 +27,8 @@ import { nodePackageFiles } from "../../infrastructure/out/fs/package-files.js";
|
|
|
27
27
|
* against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
|
|
28
28
|
* absent the run is the untyped, unvalidated tier, byte-identical to a run with no
|
|
29
29
|
* `packageDir` at all.
|
|
30
|
+
* @param options.declaredDialects - the names of the author-defined dialects the schematic's
|
|
31
|
+
* library declares in its Manifest; a handle of any other named dialect fails the run (A-16).
|
|
30
32
|
*
|
|
31
33
|
* @example
|
|
32
34
|
* import { runFactoryForTest } from "@pbuilder/sdk/testing";
|
|
@@ -57,6 +59,7 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
57
59
|
const fake = new ContractFake({ seed: options?.seed ?? {} });
|
|
58
60
|
const emitted = [];
|
|
59
61
|
const reads = new Map();
|
|
62
|
+
let committed;
|
|
60
63
|
const client = {
|
|
61
64
|
emit(batch) {
|
|
62
65
|
emitted.push(batch);
|
|
@@ -66,14 +69,17 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
66
69
|
reads.set(path, (reads.get(path) ?? 0) + 1);
|
|
67
70
|
return fake.read(path);
|
|
68
71
|
},
|
|
69
|
-
commit() {
|
|
72
|
+
commit(result) {
|
|
73
|
+
committed = result;
|
|
70
74
|
return fake.commit();
|
|
71
75
|
},
|
|
72
76
|
discard() {
|
|
73
77
|
return fake.discard();
|
|
74
78
|
},
|
|
75
79
|
};
|
|
76
|
-
const run = defineFactory(fn, options?.packageDir !== undefined
|
|
80
|
+
const run = defineFactory(fn, options?.packageDir !== undefined
|
|
81
|
+
? { packageDir: options.packageDir, packageFiles: nodePackageFiles, declaredDialects: options.declaredDialects }
|
|
82
|
+
: { declaredDialects: options?.declaredDialects });
|
|
77
83
|
let error;
|
|
78
84
|
try {
|
|
79
85
|
await run(input, { client });
|
|
@@ -81,5 +87,5 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
81
87
|
catch (caught) {
|
|
82
88
|
error = caught;
|
|
83
89
|
}
|
|
84
|
-
return { tree: fake.committedTree(), emitted, reads, error };
|
|
90
|
+
return { tree: fake.committedTree(), emitted, reads, error, result: committed };
|
|
85
91
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeclaredDialect } from "./single-instance-probe.ts";
|
|
1
2
|
import { type RunnerIo } from "./runner.ts";
|
|
2
3
|
export declare class BridgeVersionMismatchError extends Error {
|
|
3
4
|
constructor(expected: number, actual: number);
|
|
@@ -12,6 +13,8 @@ export type BridgeInput = {
|
|
|
12
13
|
export interface BridgeParams {
|
|
13
14
|
factory: string;
|
|
14
15
|
input: BridgeInput;
|
|
16
|
+
/** The Frame's declared dialects (A-16, CA-5); absent means none. */
|
|
17
|
+
dialects?: readonly DeclaredDialect[];
|
|
15
18
|
}
|
|
16
19
|
export interface BridgeIo {
|
|
17
20
|
input: RunnerIo["input"];
|
|
@@ -30,7 +30,7 @@ import { WIRE_PROTOCOL_VERSION, isStructurallyValidGreeting, versionMatches } fr
|
|
|
30
30
|
import { StdioEngineClient, TransportFault, IntentRejectedError, OverlappingRunError, } from "../../../../acl/irwire/stdio-engine-client.js";
|
|
31
31
|
import { boundMessage, composeWithToken, scrubAbsolutePaths, toProjectRelativePath } from "../../../../platform/error-text.js";
|
|
32
32
|
import { parseFactoryPointer, validateFactoryUrl, resolveFactoryExport } from "./factory-pointer.js";
|
|
33
|
-
import { probeSingleInstance } from "./single-instance-probe.js";
|
|
33
|
+
import { probeDeclaredDialects, probeSingleInstance } from "./single-instance-probe.js";
|
|
34
34
|
import { classifyExitCode } from "./exit-codes.js";
|
|
35
35
|
import { nodePackageFiles } from "../../../authoring/infrastructure/out/fs/package-files.js";
|
|
36
36
|
/** The greeting's own bound: the client's per-call timeout only exists once the greeting is in. */
|
|
@@ -42,12 +42,62 @@ export const INPUT_FILE_SIZE_CAP_BYTES = 10 * 1024 * 1024; // 10 MiB
|
|
|
42
42
|
function note(io, text) {
|
|
43
43
|
io.writeStderr(`${boundMessage(text)}\n`);
|
|
44
44
|
}
|
|
45
|
+
const DIALECTS_SHAPE = 'pbuilder-runner: --dialects must be a JSON array of {name, version, root} or {kind: "local", name, root, path} strings';
|
|
46
|
+
function fields(entry, keys) {
|
|
47
|
+
if (typeof entry !== "object" || entry === null)
|
|
48
|
+
return undefined;
|
|
49
|
+
const record = entry;
|
|
50
|
+
const picked = {};
|
|
51
|
+
for (const key of keys) {
|
|
52
|
+
const field = record[key];
|
|
53
|
+
if (typeof field !== "string" || field === "")
|
|
54
|
+
return undefined;
|
|
55
|
+
picked[key] = field;
|
|
56
|
+
}
|
|
57
|
+
return picked;
|
|
58
|
+
}
|
|
59
|
+
// A-16 / CA-5 / CA-18: the dialects the Frame's library declares, as the engine read them from the
|
|
60
|
+
// Lock. An entry without `kind` is a published dialect. The value is never echoed: it holds
|
|
61
|
+
// absolute paths.
|
|
62
|
+
function parseDialects(value) {
|
|
63
|
+
let parsed;
|
|
64
|
+
try {
|
|
65
|
+
parsed = JSON.parse(value);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
if (!Array.isArray(parsed))
|
|
71
|
+
return undefined;
|
|
72
|
+
const dialects = [];
|
|
73
|
+
for (const entry of parsed) {
|
|
74
|
+
const kind = typeof entry === "object" && entry !== null ? entry.kind : undefined;
|
|
75
|
+
if (kind === "local") {
|
|
76
|
+
const local = fields(entry, ["name", "root", "path"]);
|
|
77
|
+
if (local === undefined)
|
|
78
|
+
return undefined;
|
|
79
|
+
dialects.push({ kind: "local", name: local.name, root: local.root, path: local.path });
|
|
80
|
+
}
|
|
81
|
+
else if (kind === undefined) {
|
|
82
|
+
const published = fields(entry, ["name", "version", "root"]);
|
|
83
|
+
if (published === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
dialects.push({ name: published.name, version: published.version, root: published.root });
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return dialects;
|
|
92
|
+
}
|
|
45
93
|
// REQ-RUN-01: `--factory <url>#<export>` required; exactly one of `--input <json>` XOR
|
|
46
|
-
// `--input-file <path>`;
|
|
94
|
+
// `--input-file <path>`; `--dialects <json>` optional, absent meaning none declared; any
|
|
95
|
+
// unrecognized flag fails closed.
|
|
47
96
|
function parseArgv(argv) {
|
|
48
97
|
let factory;
|
|
49
98
|
let inputJson;
|
|
50
99
|
let inputFile;
|
|
100
|
+
let dialects = [];
|
|
51
101
|
for (let i = 0; i < argv.length; i += 2) {
|
|
52
102
|
const flag = argv[i];
|
|
53
103
|
const value = argv[i + 1];
|
|
@@ -60,6 +110,12 @@ function parseArgv(argv) {
|
|
|
60
110
|
inputJson = value;
|
|
61
111
|
else if (flag === "--input-file")
|
|
62
112
|
inputFile = value;
|
|
113
|
+
else if (flag === "--dialects") {
|
|
114
|
+
const declared = parseDialects(value);
|
|
115
|
+
if (declared === undefined)
|
|
116
|
+
return { error: DIALECTS_SHAPE };
|
|
117
|
+
dialects = declared;
|
|
118
|
+
}
|
|
63
119
|
else
|
|
64
120
|
return { error: composeWithToken("pbuilder-runner: unrecognized flag ", flag) };
|
|
65
121
|
}
|
|
@@ -73,6 +129,7 @@ function parseArgv(argv) {
|
|
|
73
129
|
}
|
|
74
130
|
return {
|
|
75
131
|
factory,
|
|
132
|
+
dialects,
|
|
76
133
|
input: inputJson !== undefined ? { kind: "inline", json: inputJson } : { kind: "file", path: inputFile },
|
|
77
134
|
};
|
|
78
135
|
}
|
|
@@ -262,6 +319,11 @@ async function runRunnerBody(argv, io, opened) {
|
|
|
262
319
|
note(io, `pbuilder-runner: ${probe.message}`);
|
|
263
320
|
return 1;
|
|
264
321
|
}
|
|
322
|
+
const dialectProbe = probeDeclaredDialects(moduleUrl, parsed.dialects);
|
|
323
|
+
if (!dialectProbe.ok) {
|
|
324
|
+
note(io, `pbuilder-runner: ${dialectProbe.message}`);
|
|
325
|
+
return 1;
|
|
326
|
+
}
|
|
265
327
|
let moduleNamespace;
|
|
266
328
|
try {
|
|
267
329
|
// SANCTIONED-FACTORY-IMPORT — the ONE dynamic import() Constraint 2 permits in the runner
|
|
@@ -299,7 +361,11 @@ async function runRunnerBody(argv, io, opened) {
|
|
|
299
361
|
// the factory's own directory — schema-derived validation and reserved-name checks apply
|
|
300
362
|
// identically on both vehicles.
|
|
301
363
|
const packageDir = dirname(fileURLToPath(new URL(moduleUrl)));
|
|
302
|
-
const run = defineFactory(exportResolution.fn, {
|
|
364
|
+
const run = defineFactory(exportResolution.fn, {
|
|
365
|
+
packageDir,
|
|
366
|
+
packageFiles: nodePackageFiles,
|
|
367
|
+
declaredDialects: parsed.dialects.map(({ name }) => name),
|
|
368
|
+
});
|
|
303
369
|
const channel = {
|
|
304
370
|
write: io.writeFrame,
|
|
305
371
|
writeStderr: io.writeStderr,
|