@pbuilder/sdk 0.18.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 +43 -0
- 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.js +24 -5
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.d.ts +6 -3
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/context.js +21 -8
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/aggregates/session/session.js +2 -2
- package/dist/bounded-contexts/authoring/domain/ports/engine-client.d.ts +1 -1
- 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/testing/conformance/run-package.d.ts +17 -0
- package/dist/bounded-contexts/authoring/testing/conformance/run-package.js +124 -44
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +10 -4
- package/dist/bounded-contexts/authoring/testing/harness/index.js +5 -3
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js +37 -10
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.d.ts +14 -3
- package/dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.js +17 -8
- package/dist/conformance/index.d.ts +1 -1
- package/dist/conformance/index.js +1 -1
- package/dist/runner-manifest.json +12 -12
- package/package.json +1 -1
|
@@ -8,8 +8,25 @@ export interface SchemaProperty {
|
|
|
8
8
|
required?: boolean;
|
|
9
9
|
description?: string;
|
|
10
10
|
}
|
|
11
|
+
export type ResultKind = "string" | "number" | "boolean" | "null" | "object" | "array";
|
|
12
|
+
export declare const RESULT_KINDS: ReadonlySet<string>;
|
|
13
|
+
/**
|
|
14
|
+
* The Result a schematic declares under `result` in `schema.json` (A-14): a subset of JSON
|
|
15
|
+
* Schema. `properties` closes an object to the keys it names; without it any JSON object fits.
|
|
16
|
+
*/
|
|
17
|
+
export interface ResultSchema {
|
|
18
|
+
types: ResultKind[];
|
|
19
|
+
properties?: Array<{
|
|
20
|
+
key: string;
|
|
21
|
+
schema: ResultSchema;
|
|
22
|
+
}>;
|
|
23
|
+
required?: string[];
|
|
24
|
+
items?: ResultSchema;
|
|
25
|
+
}
|
|
11
26
|
export interface Schema {
|
|
12
27
|
properties: SchemaProperty[];
|
|
28
|
+
/** Absent when the schematic declares no Result, so its factory must return nothing. */
|
|
29
|
+
result?: ResultSchema;
|
|
13
30
|
}
|
|
14
31
|
export declare const RESERVED_LIFECYCLE_NAMES: readonly ["pre-execute", "post-execute"];
|
|
15
32
|
export declare const FORBIDDEN_KEYS: Set<string>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// This is a DISTINCT shape from the on-disk wire contract (ADR-0027): the wire form is a
|
|
5
5
|
// wrapped `{ "properties": { "<key>": {...} } }` map (the SDK<->Go-CLI cross-repo contract);
|
|
6
6
|
// schema-parse.ts lifts that map into this array, `key` becoming an explicit field.
|
|
7
|
+
export const RESULT_KINDS = new Set(["string", "number", "boolean", "null", "object", "array"]);
|
|
7
8
|
// Cross-repo lifecycle tokens (2026-07-06 engine handoff) — schematic-level, kebab-case,
|
|
8
9
|
// case-insensitive matching lives in the reserved-name scan (S-004, ADR-0028).
|
|
9
10
|
export const RESERVED_LIFECYCLE_NAMES = ["pre-execute", "post-execute"];
|
|
@@ -4,4 +4,5 @@ export declare class UnrecognizedPropertyTypeError extends Error {
|
|
|
4
4
|
readonly field: string;
|
|
5
5
|
constructor(field: string);
|
|
6
6
|
}
|
|
7
|
+
/** The Input type, and the Result type when the schema declares a Result (A-15). */
|
|
7
8
|
export declare function emitInputType(schema: Schema, digest: string): string;
|
|
@@ -54,6 +54,28 @@ function emitProperty(property) {
|
|
|
54
54
|
: "";
|
|
55
55
|
return `${doc} ${key}${optional}: ${type};`;
|
|
56
56
|
}
|
|
57
|
+
// A-15: the declared Result as a type. Kinds come from the closed set parseSchema checked,
|
|
58
|
+
// and keys go through emitPropertyKey, so no schema text reaches the output unquoted.
|
|
59
|
+
function emitResult(result) {
|
|
60
|
+
return result.types
|
|
61
|
+
.map((kind) => {
|
|
62
|
+
switch (kind) {
|
|
63
|
+
case "array":
|
|
64
|
+
return `Array<${result.items === undefined ? "unknown" : emitResult(result.items)}>`;
|
|
65
|
+
case "object": {
|
|
66
|
+
if (result.properties === undefined)
|
|
67
|
+
return "{ [key: string]: unknown }";
|
|
68
|
+
const required = new Set(result.required);
|
|
69
|
+
const members = result.properties.map(({ key, schema }) => `${emitPropertyKey(key)}${required.has(key) ? "" : "?"}: ${emitResult(schema)}`);
|
|
70
|
+
return members.length === 0 ? "Record<string, never>" : `{ ${members.join("; ")} }`;
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
return kind;
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
.join(" | ");
|
|
77
|
+
}
|
|
78
|
+
/** The Input type, and the Result type when the schema declares a Result (A-15). */
|
|
57
79
|
export function emitInputType(schema, digest) {
|
|
58
80
|
const members = schema.properties.map(emitProperty).join("\n");
|
|
59
81
|
return [
|
|
@@ -63,6 +85,7 @@ export function emitInputType(schema, digest) {
|
|
|
63
85
|
"export type Input = {",
|
|
64
86
|
members,
|
|
65
87
|
"};",
|
|
88
|
+
...(schema.result === undefined ? [] : ["", `export type Result = ${emitResult(schema.result)};`]),
|
|
66
89
|
"",
|
|
67
90
|
].join("\n");
|
|
68
91
|
}
|
|
@@ -18,3 +18,20 @@ export interface ConformanceReport {
|
|
|
18
18
|
* if (!report.passed) console.log(report.failures.map((failure) => failure.case));
|
|
19
19
|
*/
|
|
20
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>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// CA-13 / A-16: runs the conformance fixture a dialect
|
|
2
|
-
// report names each broken check by a fixed case and reason, never by the fixture's own message,
|
|
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
3
|
// which may carry the author's samples or the text of an error their code threw (A-87).
|
|
4
4
|
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
5
5
|
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
@@ -9,8 +9,8 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
9
9
|
}
|
|
10
10
|
return path;
|
|
11
11
|
};
|
|
12
|
-
import { readFileSync } from "node:fs";
|
|
13
|
-
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
12
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
13
|
+
import { dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
14
14
|
import { pathToFileURL } from "node:url";
|
|
15
15
|
import { testDialect } from "./index.js";
|
|
16
16
|
const FIXTURE_MISSING = {
|
|
@@ -25,6 +25,14 @@ const NAME_MISMATCH = {
|
|
|
25
25
|
case: "name_mismatch",
|
|
26
26
|
reason: "A-16: the dialect's name is not the name of its package",
|
|
27
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
|
+
};
|
|
28
36
|
// Matched against testDialect's own message text, first match wins.
|
|
29
37
|
const CHECKS = [
|
|
30
38
|
["REQ-DC-08", { case: "real_parse", reason: "A-11: parse must return an AST distinct from the source" }],
|
|
@@ -37,21 +45,33 @@ const CHECKS = [
|
|
|
37
45
|
["astLibrary runtime library mismatch", { case: "module_shape", reason: "A-11: the module's astLibrary must be the adapter's own library" }],
|
|
38
46
|
];
|
|
39
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" };
|
|
40
49
|
function classify(err) {
|
|
41
50
|
const message = err instanceof Error ? err.message : "";
|
|
42
51
|
return CHECKS.find(([marker]) => message.includes(marker))?.[1] ?? FIXTURE_THREW;
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
|
|
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))
|
|
46
60
|
return undefined;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(".")))
|
|
51
73
|
return undefined;
|
|
52
|
-
|
|
53
|
-
const target = conditions.bun ?? conditions.import ?? conditions.default;
|
|
54
|
-
return typeof target === "string" ? target : undefined;
|
|
74
|
+
return pick(exports[subpath]);
|
|
55
75
|
}
|
|
56
76
|
// A resolution failure says the install is incomplete, not that the dialect is wrong.
|
|
57
77
|
function isUnresolvedModule(err) {
|
|
@@ -66,58 +86,76 @@ function isInside(dir, file) {
|
|
|
66
86
|
const path = relative(dir, file);
|
|
67
87
|
return path !== "" && !path.startsWith("..") && !isAbsolute(path);
|
|
68
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
|
+
}
|
|
69
101
|
function isFixture(value) {
|
|
70
102
|
if (typeof value !== "object" || value === null)
|
|
71
103
|
return false;
|
|
72
104
|
const fixture = value;
|
|
73
105
|
return typeof fixture.dialect === "object" && fixture.dialect !== null && Array.isArray(fixture.samples);
|
|
74
106
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
* cannot be resolved. Every finding about the dialect is a failure in the report.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* const report = await checkDialectPackage("/cache/npm/@company/ini-dialect/1.0.0/package");
|
|
82
|
-
* if (!report.passed) console.log(report.failures.map((failure) => failure.case));
|
|
83
|
-
*/
|
|
84
|
-
export async function checkDialectPackage(dir) {
|
|
85
|
-
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf-8"));
|
|
86
|
-
if (typeof pkg.name !== "string" || pkg.name.length === 0) {
|
|
87
|
-
throw new Error(`pbuilder-conformance: the package.json in --dialect has no name`);
|
|
107
|
+
async function importModule(file) {
|
|
108
|
+
try {
|
|
109
|
+
return { ok: true, value: (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href))) };
|
|
88
110
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (
|
|
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) {
|
|
97
119
|
report.failures.push(FIXTURE_MISSING);
|
|
98
120
|
return report;
|
|
99
121
|
}
|
|
100
|
-
|
|
101
|
-
if (!isInside(dir, file)) {
|
|
122
|
+
if (!isInside(folder, file)) {
|
|
102
123
|
report.failures.push(FIXTURE_INVALID);
|
|
103
124
|
return report;
|
|
104
125
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
fixture = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href))).default;
|
|
108
|
-
}
|
|
109
|
-
catch (err) {
|
|
110
|
-
if (isUnresolvedModule(err))
|
|
126
|
+
if (!existsSync(file)) {
|
|
127
|
+
if (absentFile === "unresolved")
|
|
111
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) {
|
|
112
142
|
report.failures.push(FIXTURE_THREW);
|
|
113
143
|
return report;
|
|
114
144
|
}
|
|
145
|
+
const fixture = loaded.value.default;
|
|
115
146
|
if (!isFixture(fixture)) {
|
|
116
147
|
report.failures.push(FIXTURE_INVALID);
|
|
117
148
|
return report;
|
|
118
149
|
}
|
|
119
|
-
if (fixture.dialect.name !==
|
|
120
|
-
report.failures.push(
|
|
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);
|
|
121
159
|
try {
|
|
122
160
|
await testDialect(fixture);
|
|
123
161
|
}
|
|
@@ -127,3 +165,45 @@ export async function checkDialectPackage(dir) {
|
|
|
127
165
|
report.passed = report.failures.length === 0;
|
|
128
166
|
return report;
|
|
129
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
|
|
@@ -85,8 +91,8 @@ export type { Batch, Directive };
|
|
|
85
91
|
* expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
|
|
86
92
|
* });
|
|
87
93
|
*/
|
|
88
|
-
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?: {
|
|
89
95
|
seed?: Record<string, string>;
|
|
90
96
|
packageDir?: string | URL;
|
|
91
97
|
declaredDialects?: readonly string[];
|
|
92
|
-
}): Promise<RunResult
|
|
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
|
|
@@ -59,6 +59,7 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
59
59
|
const fake = new ContractFake({ seed: options?.seed ?? {} });
|
|
60
60
|
const emitted = [];
|
|
61
61
|
const reads = new Map();
|
|
62
|
+
let committed;
|
|
62
63
|
const client = {
|
|
63
64
|
emit(batch) {
|
|
64
65
|
emitted.push(batch);
|
|
@@ -68,7 +69,8 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
68
69
|
reads.set(path, (reads.get(path) ?? 0) + 1);
|
|
69
70
|
return fake.read(path);
|
|
70
71
|
},
|
|
71
|
-
commit() {
|
|
72
|
+
commit(result) {
|
|
73
|
+
committed = result;
|
|
72
74
|
return fake.commit();
|
|
73
75
|
},
|
|
74
76
|
discard() {
|
|
@@ -85,5 +87,5 @@ export async function runFactoryForTest(fn, input, options) {
|
|
|
85
87
|
catch (caught) {
|
|
86
88
|
error = caught;
|
|
87
89
|
}
|
|
88
|
-
return { tree: fake.committedTree(), emitted, reads, error };
|
|
90
|
+
return { tree: fake.committedTree(), emitted, reads, error, result: committed };
|
|
89
91
|
}
|
|
@@ -42,9 +42,23 @@ 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 =
|
|
46
|
-
|
|
47
|
-
|
|
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.
|
|
48
62
|
function parseDialects(value) {
|
|
49
63
|
let parsed;
|
|
50
64
|
try {
|
|
@@ -55,13 +69,26 @@ function parseDialects(value) {
|
|
|
55
69
|
}
|
|
56
70
|
if (!Array.isArray(parsed))
|
|
57
71
|
return undefined;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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;
|
|
65
92
|
}
|
|
66
93
|
// REQ-RUN-01: `--factory <url>#<export>` required; exactly one of `--input <json>` XOR
|
|
67
94
|
// `--input-file <path>`; `--dialects <json>` optional, absent meaning none declared; any
|
|
@@ -21,16 +21,27 @@ export type SingleInstanceProbeResult = {
|
|
|
21
21
|
* with the REAL default resolver in the split/unresolvable test cases.
|
|
22
22
|
*/
|
|
23
23
|
export declare function probeSingleInstance(factoryUrl: string, resolveSpecifier?: (specifier: string, anchorUrl: string) => string): SingleInstanceProbeResult;
|
|
24
|
-
/**
|
|
25
|
-
export interface
|
|
24
|
+
/** A published dialect, installed into the Cache: `root` is the package the Lock pins. */
|
|
25
|
+
export interface PublishedDialect {
|
|
26
|
+
kind?: undefined;
|
|
26
27
|
name: string;
|
|
27
28
|
version: string;
|
|
28
29
|
root: string;
|
|
29
30
|
}
|
|
31
|
+
/** A local dialect (CA-18): `root` is the folder the engine hashed, `path` its base file. */
|
|
32
|
+
export interface LocalDeclaredDialect {
|
|
33
|
+
kind: "local";
|
|
34
|
+
name: string;
|
|
35
|
+
root: string;
|
|
36
|
+
path: string;
|
|
37
|
+
}
|
|
38
|
+
/** One dialect the Frame's library declares (CA-5): published unless its `kind` is `"local"`. */
|
|
39
|
+
export type DeclaredDialect = PublishedDialect | LocalDeclaredDialect;
|
|
30
40
|
/**
|
|
31
41
|
* A-16 / A-4: before the factory starts, resolves each declared dialect's name from the factory's
|
|
32
42
|
* location, the same resolution its own `import` gets, and requires the real path inside the copy
|
|
33
|
-
* the Lock pins.
|
|
43
|
+
* the Lock pins. A local dialect's name is no specifier, so its base file's real path must sit inside
|
|
44
|
+
* its folder instead (CA-18). It keeps the dialect that runs the pinned one; it is no security boundary.
|
|
34
45
|
* Resolution-only, like `probeSingleInstance`; an unresolvable name fails the same way.
|
|
35
46
|
*/
|
|
36
47
|
export declare function probeDeclaredDialects(factoryUrl: string, dialects: readonly DeclaredDialect[], resolveSpecifier?: (specifier: string, anchorUrl: string) => string): SingleInstanceProbeResult;
|
|
@@ -117,27 +117,36 @@ export function probeSingleInstance(factoryUrl, resolveSpecifier = resolveSpecif
|
|
|
117
117
|
return { ok: true };
|
|
118
118
|
return { ok: false, message: splitMessage(runnerRoot, factoryRoot) };
|
|
119
119
|
}
|
|
120
|
-
function
|
|
120
|
+
function isInside(root, file) {
|
|
121
121
|
try {
|
|
122
|
-
const path = relative(realpathSync(root), realpathSync(
|
|
122
|
+
const path = relative(realpathSync(root), realpathSync(file));
|
|
123
123
|
return path !== "" && !path.startsWith("..") && !isAbsolute(path);
|
|
124
124
|
}
|
|
125
125
|
catch {
|
|
126
126
|
return false;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
+
function resolvesInside(dialect, factoryUrl, resolveSpecifier) {
|
|
130
|
+
if (dialect.kind === "local")
|
|
131
|
+
return isInside(dialect.root, dialect.path);
|
|
132
|
+
try {
|
|
133
|
+
return isInside(dialect.root, resolveSpecifier(dialect.name, factoryUrl));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
129
139
|
/**
|
|
130
140
|
* A-16 / A-4: before the factory starts, resolves each declared dialect's name from the factory's
|
|
131
141
|
* location, the same resolution its own `import` gets, and requires the real path inside the copy
|
|
132
|
-
* the Lock pins.
|
|
142
|
+
* the Lock pins. A local dialect's name is no specifier, so its base file's real path must sit inside
|
|
143
|
+
* its folder instead (CA-18). It keeps the dialect that runs the pinned one; it is no security boundary.
|
|
133
144
|
* Resolution-only, like `probeSingleInstance`; an unresolvable name fails the same way.
|
|
134
145
|
*/
|
|
135
146
|
export function probeDeclaredDialects(factoryUrl, dialects, resolveSpecifier = resolveSpecifierPath) {
|
|
136
|
-
const outside = dialects.find((
|
|
147
|
+
const outside = dialects.find((dialect) => !resolvesInside(dialect, factoryUrl, resolveSpecifier));
|
|
137
148
|
if (outside === undefined)
|
|
138
149
|
return { ok: true };
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
message: `the factory does not start because the dialect "${outside.name}" resolves outside the package the Lock pins`,
|
|
142
|
-
};
|
|
150
|
+
const place = outside.kind === "local" ? "the folder of its base file" : "the package the Lock pins";
|
|
151
|
+
return { ok: false, message: `the factory does not start because the dialect "${outside.name}" resolves outside ${place}` };
|
|
143
152
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../bounded-contexts/authoring/testing/conformance/index.ts";
|
|
2
|
-
export { checkDialectPackage, type ConformanceFailure, type ConformanceReport, } from "../bounded-contexts/authoring/testing/conformance/run-package.ts";
|
|
2
|
+
export { checkDialectPackage, checkLocalDialect, type LocalDialect, type ConformanceFailure, type ConformanceReport, } from "../bounded-contexts/authoring/testing/conformance/run-package.ts";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "../bounded-contexts/authoring/testing/conformance/index.js";
|
|
2
|
-
export { checkDialectPackage, } from "../bounded-contexts/authoring/testing/conformance/run-package.js";
|
|
2
|
+
export { checkDialectPackage, checkLocalDialect, } from "../bounded-contexts/authoring/testing/conformance/run-package.js";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"manifestVersion": 1,
|
|
3
3
|
"algorithm": "sha256",
|
|
4
4
|
"entry": "dist/bin/pbuilder-runner.js",
|
|
5
|
-
"packageVersion": "0.
|
|
5
|
+
"packageVersion": "0.19.0",
|
|
6
6
|
"files": [
|
|
7
7
|
{
|
|
8
8
|
"path": "dist/acl/irwire/frame-reader.js",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
{
|
|
12
12
|
"path": "dist/acl/irwire/stdio-engine-client.js",
|
|
13
|
-
"sha256": "
|
|
13
|
+
"sha256": "a7b8f09a1c2c63c90d605d28f4376a2772504bb7b89b8e2ea46ba5b103ce63fe"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"path": "dist/bin/pbuilder-runner.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
20
|
"path": "dist/bounded-contexts/authoring/application/usecases/run-factory/context.js",
|
|
21
|
-
"sha256": "
|
|
21
|
+
"sha256": "a2521108c576a7b3dfcda1bd05cdd6547f01a53c51b930b3d891d7d36f0ecf07"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
"path": "dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"path": "dist/bounded-contexts/authoring/domain/aggregates/session/session.js",
|
|
29
|
-
"sha256": "
|
|
29
|
+
"sha256": "d766298100d79ee9d3f2486cb36a951d0950a507b87564a48d3f9f17e4624be1"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
"path": "dist/bounded-contexts/authoring/domain/ports/emit-rejection.js",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
"path": "dist/bounded-contexts/authoring/domain/services/schema/input-rejection.js",
|
|
49
|
-
"sha256": "
|
|
49
|
+
"sha256": "31aacefce17622b2b6fd22af8834311c69e6a8c95afdf079bcee04c2a4d06a28"
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
"path": "dist/bounded-contexts/authoring/domain/services/schema/schema-files.js",
|
|
@@ -58,19 +58,19 @@
|
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
60
|
"path": "dist/bounded-contexts/authoring/domain/services/schema/schema-parse.js",
|
|
61
|
-
"sha256": "
|
|
61
|
+
"sha256": "5b356f9778b604bb25540e260fe1b040f8bcf46112418c561f492ea3329973ef"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
"path": "dist/bounded-contexts/authoring/domain/services/schema/schema-validate.js",
|
|
65
|
-
"sha256": "
|
|
65
|
+
"sha256": "ba0da0e1feec8c74a14992ad720e44b53088e5e2c9866e31168ec9dcd492fd6d"
|
|
66
66
|
},
|
|
67
67
|
{
|
|
68
68
|
"path": "dist/bounded-contexts/authoring/domain/valueobjects/authoring-error.js",
|
|
69
|
-
"sha256": "
|
|
69
|
+
"sha256": "12bcb05ddffaade8ba3cadea33c30d469909e9c034415554456a1e4a765bfd19"
|
|
70
70
|
},
|
|
71
71
|
{
|
|
72
72
|
"path": "dist/bounded-contexts/authoring/domain/valueobjects/schema-model.js",
|
|
73
|
-
"sha256": "
|
|
73
|
+
"sha256": "6d015200921c8a72ef27941d287d460275bc944620ee9a7c140ad73354bbfc82"
|
|
74
74
|
},
|
|
75
75
|
{
|
|
76
76
|
"path": "dist/bounded-contexts/authoring/domain/valueobjects/wire.js",
|
|
@@ -94,11 +94,11 @@
|
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
"path": "dist/bounded-contexts/runner-hosting/infrastructure/in/runner.js",
|
|
97
|
-
"sha256": "
|
|
97
|
+
"sha256": "78aee0804a9fe9b110821a41dfb171dab635708c6220ad5aba986e167109ed50"
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
100
|
"path": "dist/bounded-contexts/runner-hosting/infrastructure/in/single-instance-probe.js",
|
|
101
|
-
"sha256": "
|
|
101
|
+
"sha256": "5166df63dd3f9aef16b9d53b788cbdc8f67a0337bf537f2b8e166ff214752a96"
|
|
102
102
|
},
|
|
103
103
|
{
|
|
104
104
|
"path": "dist/platform/error-text.js",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
124
|
"path": "package.json",
|
|
125
|
-
"sha256": "
|
|
125
|
+
"sha256": "19ccb4ace24caa2a75a77a044363d75601cdd64465a66e89601920a45d1bfc88"
|
|
126
126
|
}
|
|
127
127
|
]
|
|
128
128
|
}
|