@pbuilder/sdk 0.14.0 → 0.15.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 +57 -42
- package/dist/{transport → acl/irwire}/frame-reader.d.ts +2 -0
- package/dist/{transport → acl/irwire}/frame-reader.js +57 -5
- package/dist/{transport → acl/irwire}/stdio-engine-client.d.ts +2 -2
- package/dist/{transport → acl/irwire}/stdio-engine-client.js +4 -4
- package/dist/bin/pbuilder-codegen.js +30 -35
- package/dist/bin/pbuilder-runner.js +6 -6
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.d.ts +106 -0
- package/dist/bounded-contexts/authoring/application/usecases/authoring-verbs/index.js +202 -0
- package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.d.ts +12 -9
- package/dist/{core → bounded-contexts/authoring/application/usecases/run-factory}/context.js +59 -120
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.d.ts +5 -0
- package/dist/bounded-contexts/authoring/application/usecases/run-factory/driving.js +15 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.d.ts +51 -0
- package/dist/bounded-contexts/authoring/application/usecases/scaffold/classify-transport.js +105 -0
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.d.ts +2 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/expander.js +13 -7
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.d.ts +1 -1
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/index.js +7 -6
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.d.ts +11 -10
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/path-guards.js +21 -48
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.d.ts +2 -3
- package/dist/{scaffold → bounded-contexts/authoring/application/usecases/scaffold}/walk.js +37 -56
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/aggregates/session}/session.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/entities}/dialect-handle.js +10 -10
- package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.d.ts +1 -1
- package/dist/bounded-contexts/authoring/domain/ports/package-files.d.ts +53 -0
- package/dist/bounded-contexts/authoring/domain/ports/package-files.js +11 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/define-dialect.js +3 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.d.ts +2 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/directive-factory.js +37 -12
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.d.ts +7 -5
- package/dist/{scaffold → bounded-contexts/authoring/domain/services}/filename-pipeline.js +28 -8
- package/dist/{core/jsx-name-validator.d.ts → bounded-contexts/authoring/domain/services/identifier-names.d.ts} +8 -4
- package/dist/{core/jsx-name-validator.js → bounded-contexts/authoring/domain/services/identifier-names.js} +21 -28
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.d.ts +9 -0
- package/dist/bounded-contexts/authoring/domain/services/reject-tail.js +30 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.d.ts +5 -0
- package/dist/bounded-contexts/authoring/domain/services/run-context.js +70 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/input-rejection.js +1 -1
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.d.ts +2 -0
- package/dist/bounded-contexts/authoring/domain/services/schema/schema-files.js +6 -0
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.d.ts +2 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-locate.js +13 -2
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-parse.js +2 -14
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.d.ts +4 -3
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-sufficiency.js +8 -4
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.d.ts +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-validate.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.js +1 -1
- package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/wire.d.ts +0 -3
- package/dist/bounded-contexts/authoring/domain/valueobjects/wire.js +28 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.d.ts +27 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/cli.js +306 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.d.ts +7 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/emit-type.js +68 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.d.ts +19 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/codegen/project-codegen.js +131 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.d.ts +182 -0
- package/dist/bounded-contexts/authoring/infrastructure/in/commons/index.js +94 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.d.ts +63 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/angular/index.js +68 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.js +9 -9
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.d.ts +40 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/css/index.js +38 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.d.ts +55 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/json/index.js +54 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ops.js +35 -8
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.d.ts +43 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/nestjs/index.js +46 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.js +7 -7
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.d.ts +52 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/index.js +73 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/jsx-names.js +18 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.d.ts +4 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/react/match-tails.js +25 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.js +5 -3
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.d.ts +7 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/array-element.js +29 -15
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.d.ts +5 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ast.js +22 -4
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.js +14 -19
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.d.ts +53 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/typescript/index.js +37 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.d.ts +6 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/ops.js +90 -54
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.d.ts +69 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/dialects/yaml/index.js +70 -0
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.d.ts +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/paths.js +2 -2
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.js +1 -1
- package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.js +2 -2
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.d.ts +8 -0
- package/dist/bounded-contexts/authoring/infrastructure/out/fs/package-files.js +133 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.d.ts +157 -0
- package/dist/bounded-contexts/authoring/testing/conformance/index.js +261 -0
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.d.ts +2 -2
- package/dist/{testing → bounded-contexts/authoring/testing}/contract-fake.js +4 -3
- package/dist/bounded-contexts/authoring/testing/harness/index.d.ts +89 -0
- package/dist/bounded-contexts/authoring/testing/harness/index.js +85 -0
- package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.d.ts +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js +2 -2
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.js +5 -4
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js +1 -1
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.d.ts +4 -0
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/runner.js +49 -23
- package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.js +1 -1
- package/dist/commons/index.d.ts +1 -278
- package/dist/commons/index.js +1 -286
- package/dist/conformance/index.d.ts +1 -157
- package/dist/conformance/index.js +1 -261
- package/dist/dialects/angular/index.d.ts +1 -63
- package/dist/dialects/angular/index.js +1 -68
- package/dist/dialects/css/index.d.ts +1 -40
- package/dist/dialects/css/index.js +1 -38
- package/dist/dialects/json/index.d.ts +1 -55
- package/dist/dialects/json/index.js +1 -54
- package/dist/dialects/nestjs/index.d.ts +1 -43
- package/dist/dialects/nestjs/index.js +1 -46
- package/dist/dialects/react/index.d.ts +1 -52
- package/dist/dialects/react/index.js +1 -73
- package/dist/dialects/typescript/index.d.ts +1 -53
- package/dist/dialects/typescript/index.js +1 -37
- package/dist/dialects/yaml/index.d.ts +1 -69
- package/dist/dialects/yaml/index.js +1 -70
- package/dist/{core → platform}/deep-equal.js +2 -2
- package/dist/{transport → platform}/error-text.js +2 -2
- package/dist/runner-manifest.json +66 -46
- package/dist/shared-kernel/batch-cap.d.ts +4 -0
- package/dist/{core/wire.js → shared-kernel/batch-cap.js} +9 -26
- package/dist/{transport → shared-kernel}/framing.js +2 -2
- package/dist/{transport → shared-kernel}/wire-protocol.js +1 -1
- package/dist/testing/index.d.ts +1 -84
- package/dist/testing/index.js +1 -82
- package/package.json +9 -3
- package/dist/core/index.d.ts +0 -10
- package/dist/core/index.js +0 -6
- package/dist/core/reject-tail.d.ts +0 -13
- package/dist/core/reject-tail.js +0 -52
- package/dist/core/schema/schema-discovery.d.ts +0 -13
- package/dist/core/schema/schema-discovery.js +0 -51
- package/dist/scaffold/classify-transport.d.ts +0 -54
- package/dist/scaffold/classify-transport.js +0 -119
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.d.ts +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/index.js +0 -0
- /package/dist/{pending-directives → bounded-contexts/authoring/application/usecases/pending-directives}/render.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/base-handle.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/entities}/handle-state.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/emit-rejection.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/ports}/engine-client.js +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.d.ts +0 -0
- /package/dist/{commons → bounded-contexts/authoring/domain/services}/classify-content.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/services}/schema/schema-digest.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/authoring-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/dialect-error.js +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.d.ts +0 -0
- /package/dist/{core → bounded-contexts/authoring/domain/valueobjects}/json-value.js +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.d.ts +0 -0
- /package/dist/{core/schema → bounded-contexts/authoring/domain/valueobjects}/schema-model.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/angular/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/css/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/json/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/nestjs/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/react/ops.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/class-property.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/import-order.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/typescript/pack.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/ast.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/documents.js +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/presentation.d.ts +0 -0
- /package/dist/{dialects → bounded-contexts/authoring/infrastructure/out/dialects}/yaml/structural.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.d.ts +0 -0
- /package/dist/{testing → bounded-contexts/authoring/testing}/rejection-messages.js +0 -0
- /package/dist/{conformance → bounded-contexts/authoring/testing}/run-vehicle.js +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/exit-codes.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.d.ts +0 -0
- /package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/single-instance-probe.d.ts +0 -0
- /package/dist/{core → platform}/deep-equal.d.ts +0 -0
- /package/dist/{transport → platform}/error-text.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.d.ts +0 -0
- /package/dist/{core → platform}/fs-errors.js +0 -0
- /package/dist/{transport → shared-kernel}/framing.d.ts +0 -0
- /package/dist/{transport → shared-kernel}/wire-protocol.d.ts +0 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// CONF-01: the conformance kit — testDialect / testOpPack (ADR-0012).
|
|
2
|
+
//
|
|
3
|
+
// S-004 (ADR-0012 amendment): real CORE bodies against the REAL TypeScript dialect — byte-
|
|
4
|
+
// exact round-trip (REQ-DC-01), single-op fidelity + unchanged-elsewhere (REQ-DC-02),
|
|
5
|
+
// coalescing-to-one content-verified (REQ-DC-03), seam-serializability (REQ-DC-04), and the
|
|
6
|
+
// read-boundary-split live counterpart (REQ-DC-05.2). Both functions are now
|
|
7
|
+
// `Promise<void>` (rev 3, Q3): observing DC-03/DC-04 requires awaiting a REAL async
|
|
8
|
+
// coalescing run (the handle's `#tail`, the run-boundary join, and `Session.flush` are all
|
|
9
|
+
// async) — a synchronous body could only inspect the emitted batch via a mock/bypass, which
|
|
10
|
+
// ADR-0012 and REQ-TSD-07 (ContractFake-only) forbid. Every failure REJECTS the returned
|
|
11
|
+
// promise with a descriptive Error (never a sync throw) — planted violations (REQ-DC-05)
|
|
12
|
+
// surface through an expect-reject wrapper at the call site.
|
|
13
|
+
//
|
|
14
|
+
// Drives real runs via `defineFactory` + the kit-internal `run-vehicle.ts` transport —
|
|
15
|
+
// imported for INTERNAL use only, never re-exported (FIT-08 bans re-export of kit symbols
|
|
16
|
+
// from this path, not internal use of them).
|
|
17
|
+
import { defineFactory } from "../../application/usecases/run-factory/context.js";
|
|
18
|
+
import { deepEqual } from "../../../../platform/deep-equal.js";
|
|
19
|
+
import { createRunVehicle } from "../run-vehicle.js";
|
|
20
|
+
// REQ-DC-04 (seam-serializability): `JSON.parse(JSON.stringify(directive))` must deep-equal
|
|
21
|
+
// `directive` for EVERY emitted directive. Two DISTINCT failure modes a planted `.modify()` can
|
|
22
|
+
// trigger (REQ-DC-04.1/.2): a closure attached to directive content is silently DROPPED by
|
|
23
|
+
// JSON.stringify (caught by the deepEqual mismatch below); a live AST node with circular
|
|
24
|
+
// parent pointers makes JSON.stringify itself THROW (caught by the try/catch below).
|
|
25
|
+
function assertSerializable(directives, label) {
|
|
26
|
+
for (const directive of directives) {
|
|
27
|
+
let roundTripped;
|
|
28
|
+
try {
|
|
29
|
+
roundTripped = JSON.parse(JSON.stringify(directive));
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
throw new Error(`testOpPack: REQ-DC-04 seam-serializability (${label}) — a directive failed JSON.stringify, ` +
|
|
33
|
+
`likely a live AST node with circular references attached to directive content: ` +
|
|
34
|
+
`${err instanceof Error ? err.message : String(err)}`);
|
|
35
|
+
}
|
|
36
|
+
if (!deepEqual(directive, roundTripped)) {
|
|
37
|
+
throw new Error(`testOpPack: REQ-DC-04 seam-serializability (${label}) — JSON.parse(JSON.stringify(directive)) ` +
|
|
38
|
+
`did not deep-equal the original directive; a non-serializable value (e.g. a closure) was ` +
|
|
39
|
+
`silently dropped`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Runs ONE exercise through a fresh, isolated run-vehicle (§4.4c): seeds `path` with `seed`,
|
|
44
|
+
// chains the exercise's ops on `baseDialect.find(path)` (`{op,args}` -> `handle[op](...args)`;
|
|
45
|
+
// `{modify}` -> `handle.modify(fn)`), optionally injects `handle.read()` right after the FIRST op
|
|
46
|
+
// (the read-boundary-split re-run), awaits, and returns every modify directive observed
|
|
47
|
+
// across the whole run, in emission order.
|
|
48
|
+
async function runExercise(dialect, exercise, opts) {
|
|
49
|
+
const path = exercise.path ?? `op-exercise${dialect.extensions[0] ?? ""}`;
|
|
50
|
+
const { client, emitted } = createRunVehicle({ [path]: exercise.seed });
|
|
51
|
+
const runner = defineFactory(async () => {
|
|
52
|
+
// `any`: fixtures span arbitrary op-packs, so the exercised handle's op-derived members
|
|
53
|
+
// are not known at this generic boundary (mirrors OpPackFixture's own `unknown`-at-the-
|
|
54
|
+
// boundary posture, design §4.3).
|
|
55
|
+
let handle = dialect.find(path);
|
|
56
|
+
for (const [index, step] of exercise.chain.entries()) {
|
|
57
|
+
handle = "modify" in step ? handle.modify(step.modify) : handle[step.op](...step.args);
|
|
58
|
+
if (opts.injectReadAfterFirstOp && index === 0) {
|
|
59
|
+
await handle.read();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
await handle;
|
|
63
|
+
});
|
|
64
|
+
await runner(undefined, { client });
|
|
65
|
+
const directives = emitted.flatMap((b) => b.instructions);
|
|
66
|
+
const modifies = directives
|
|
67
|
+
.filter((d) => d.op === "modify")
|
|
68
|
+
.map((d) => d.modify);
|
|
69
|
+
return { modifies, directives };
|
|
70
|
+
}
|
|
71
|
+
// REQ-DC-06 (ADR-0012 amendment clause 1): four mandatory adversarial samples, injected
|
|
72
|
+
// ADDITIVELY into every `testDialect`/`testOpPack` run — `DialectFixture` carries no field
|
|
73
|
+
// capable of disabling this (compile-level guarantee, REQ-DC-06.2, see test/conformance/planted/
|
|
74
|
+
// opt-out-attempt.test.ts). No source text is valid in every language, so the samples derive
|
|
75
|
+
// from a source the dialect itself declares valid (the library-exercise seed, or the first
|
|
76
|
+
// op-exercise seed): only the empty file, line endings, the BOM, and size are format-neutral.
|
|
77
|
+
// Language-specific adversarial samples belong in each dialect's own `fixture.samples`.
|
|
78
|
+
const BOM = "\uFEFF";
|
|
79
|
+
const LARGE_SAMPLE_BYTES = 4 * 1024 * 1024;
|
|
80
|
+
function mandatoryAdversarialSamples(validSource) {
|
|
81
|
+
const lf = validSource.replace(/^\uFEFF/, "").replace(/\r\n/g, "\n");
|
|
82
|
+
const terminated = lf.endsWith("\n") ? lf : `${lf}\n`;
|
|
83
|
+
return [
|
|
84
|
+
"", // empty file
|
|
85
|
+
terminated.replace(/\n/g, "\r\n"), // CRLF
|
|
86
|
+
BOM + terminated, // UTF-8 BOM
|
|
87
|
+
terminated + "\n".repeat(LARGE_SAMPLE_BYTES), // 4 MiB serialized-boundary sample (REQ-TSD-03.7 precedent)
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
const UNDECLARED_EXTENSION = ".pbuilder-undeclared";
|
|
91
|
+
// Shared by `testDialect` and `testOpPack` (verify-in-loop-4 Finding #1): the round-trip +
|
|
92
|
+
// real-base-probe loop is ONE mechanism, run against whichever dialect reference the caller
|
|
93
|
+
// holds (`fixture.dialect` for testDialect, `fixture.baseDialect` for testOpPack) — REQ-DC-06's
|
|
94
|
+
// chapeau ("into EVERY testDialect/testOpPack run") and REQ-DC-08 (real-base-dialect rule) both
|
|
95
|
+
// name a dialect's `ast.parse`/`ast.print` pair, not an op-chain, so no per-op synthesis is
|
|
96
|
+
// needed to satisfy either for `testOpPack`. `label` scopes error messages to the caller.
|
|
97
|
+
function runRoundTripProbe(dialectAst, samples, label) {
|
|
98
|
+
for (const sample of samples) {
|
|
99
|
+
const ast = dialectAst.parse(sample);
|
|
100
|
+
// REQ-DC-08 (real-base-dialect rule): a stub/mock parse that returns nothing or hands
|
|
101
|
+
// back the input string unchanged would let an identity round-trip pass vacuously —
|
|
102
|
+
// reject before the round-trip assertion can even run.
|
|
103
|
+
if (ast === null || ast === undefined || ast === sample) {
|
|
104
|
+
throw new Error(`${label}: REQ-DC-08 real-base-dialect rule — dialect.ast.parse(sample) returned a ` +
|
|
105
|
+
"nullish value or the input string unchanged; a real dialect's parse must produce a distinct AST");
|
|
106
|
+
}
|
|
107
|
+
const roundTripped = dialectAst.print(ast);
|
|
108
|
+
if (roundTripped !== sample) {
|
|
109
|
+
const preview = sample.length > 80 ? `${sample.slice(0, 80)}...` : sample;
|
|
110
|
+
throw new Error(`${label}: REQ-DC-01 round-trip fidelity — print(parse(sample)) did not byte-exact match ` +
|
|
111
|
+
`the original sample: ${JSON.stringify(preview)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Runs the conformance suite for a dialect: asserts parse/print no-op round-trip fidelity
|
|
117
|
+
* (REQ-DC-01) — `print(parse(sample)) === sample` BYTE-EXACT, never AST-equal, for every
|
|
118
|
+
* sample in `fixture.samples` PLUS the four mandatory adversarial samples the kit injects on
|
|
119
|
+
* every run (REQ-DC-06 — additive, not opt-out-able). Before each round-trip check, verifies
|
|
120
|
+
* `fixture.dialect.ast.parse` is a REAL parser, not an identity/stub function (REQ-DC-08): a
|
|
121
|
+
* `parse` returning `null`/`undefined`, or the input string unchanged, fails BEFORE the
|
|
122
|
+
* round-trip assertion could vacuously pass.
|
|
123
|
+
*
|
|
124
|
+
* Requires runtime library exports matching independent adapter evidence, then exercises
|
|
125
|
+
* the actual module's `find().modify()` through a real run with byte-exact emitted output.
|
|
126
|
+
*/
|
|
127
|
+
export async function testDialect(fixture) {
|
|
128
|
+
const module = fixture.module;
|
|
129
|
+
if (!module || typeof module.find !== "function") {
|
|
130
|
+
throw new Error("testDialect: module must expose callable find");
|
|
131
|
+
}
|
|
132
|
+
if (!module.astLibrary || typeof module.astLibrary !== "object") {
|
|
133
|
+
throw new Error("testDialect: module must expose runtime astLibrary");
|
|
134
|
+
}
|
|
135
|
+
const expected = fixture.expectedAstLibrary;
|
|
136
|
+
if (!expected || typeof expected !== "object") {
|
|
137
|
+
throw new Error("testDialect: independent expectedAstLibrary evidence is required");
|
|
138
|
+
}
|
|
139
|
+
const keys = Object.keys(expected);
|
|
140
|
+
if (keys.length === 0 || keys.length !== Object.keys(module.astLibrary).length ||
|
|
141
|
+
keys.some((key) => !Object.hasOwn(module.astLibrary, key) ||
|
|
142
|
+
!Object.is(Reflect.get(module.astLibrary, key), Reflect.get(expected, key)))) {
|
|
143
|
+
throw new Error("testDialect: astLibrary runtime library mismatch with adapter evidence");
|
|
144
|
+
}
|
|
145
|
+
const samples = [...fixture.samples, ...mandatoryAdversarialSamples(fixture.libraryExercise.seed)];
|
|
146
|
+
runRoundTripProbe(fixture.dialect.ast, samples, "testDialect");
|
|
147
|
+
const exercise = fixture.libraryExercise;
|
|
148
|
+
const { client, emitted } = createRunVehicle({ [exercise.path]: exercise.seed });
|
|
149
|
+
// A-11: `find` must reject an extension the dialect does not declare. Probed inside the run,
|
|
150
|
+
// because outside a Session a conforming `find` would throw for the wrong reason.
|
|
151
|
+
const undeclaredPath = `conformance-probe${UNDECLARED_EXTENSION}`;
|
|
152
|
+
let acceptedUndeclared = !fixture.dialect.extensions.includes(UNDECLARED_EXTENSION);
|
|
153
|
+
const run = defineFactory(async () => {
|
|
154
|
+
try {
|
|
155
|
+
module.find(undeclaredPath);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
acceptedUndeclared = false;
|
|
159
|
+
}
|
|
160
|
+
await module.find(exercise.path).modify((ast) => exercise.modify(ast, module.astLibrary));
|
|
161
|
+
});
|
|
162
|
+
await run(undefined, { client });
|
|
163
|
+
if (acceptedUndeclared) {
|
|
164
|
+
throw new Error(`testDialect: find accepted "${undeclaredPath}", an undeclared extension (A-11)`);
|
|
165
|
+
}
|
|
166
|
+
const directives = emitted.flatMap((batch) => batch.instructions);
|
|
167
|
+
if (!deepEqual(directives, [{ op: "modify", modify: { path: exercise.path, content: exercise.expect } }])) {
|
|
168
|
+
throw new Error("testDialect: library exercise did not emit the expected byte-exact modify");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Runs the conformance suite for an op-pack against a REAL base dialect (never a mock,
|
|
173
|
+
* ADR-0012): for each of `fixture.exercises`, asserts single-op fidelity +
|
|
174
|
+
* unchanged-elsewhere (REQ-DC-02) / coalescing-to-one content-verified (REQ-DC-03) via a
|
|
175
|
+
* no-read run, seam-serializability (REQ-DC-04) over every emitted directive, and — for
|
|
176
|
+
* every multi-op exercise — the read-boundary split (REQ-DC-05.2's live counterpart): a
|
|
177
|
+
* mid-chain `read()` must force exactly TWO cumulative modify directives, never one. Finally,
|
|
178
|
+
* asserts `fixture.baseDialect` survives the four mandatory adversarial samples' round-trip +
|
|
179
|
+
* real-base probe (REQ-DC-06/REQ-DC-08 — additive, not opt-out-able, same mechanism
|
|
180
|
+
* `testDialect` runs), unconditionally on every call whose exercises pass.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* await testOpPack({
|
|
184
|
+
* opPack: myInsertImportOps,
|
|
185
|
+
* baseDialect: myTypeScriptDialect,
|
|
186
|
+
* exercises: [
|
|
187
|
+
* {
|
|
188
|
+
* seed: "export const x = 1;",
|
|
189
|
+
* chain: [{ op: "addImport", args: ["readFileSync", "node:fs"] }],
|
|
190
|
+
* expect: 'import { readFileSync } from "node:fs";\nexport const x = 1;',
|
|
191
|
+
* },
|
|
192
|
+
* ],
|
|
193
|
+
* });
|
|
194
|
+
*/
|
|
195
|
+
export async function testOpPack(fixture) {
|
|
196
|
+
if (fixture.exercises.length === 0) {
|
|
197
|
+
throw new Error("testOpPack: fixture.exercises must include at least one exercise — REQ-DC-02..04 are untestable without one");
|
|
198
|
+
}
|
|
199
|
+
const hasMultiOpExercise = fixture.exercises.some((exercise) => exercise.chain.length >= 2);
|
|
200
|
+
if (!hasMultiOpExercise) {
|
|
201
|
+
throw new Error("testOpPack: fixture.exercises must include at least one multi-op exercise (>=2 ops) — " +
|
|
202
|
+
"REQ-DC-03 (coalescing-to-one, >=2 distinguishable ops) is mandatory");
|
|
203
|
+
}
|
|
204
|
+
for (const exercise of fixture.exercises) {
|
|
205
|
+
// REQ-DC-02 (single-op exercises) / REQ-DC-03 (multi-op exercises): a no-read run must
|
|
206
|
+
// coalesce to EXACTLY ONE modify for `path`, byte-exact `expect` — a FULL-output
|
|
207
|
+
// comparison proves BOTH the op's intended effect AND that every other region stayed
|
|
208
|
+
// byte-stable (never a `contains` substring, Theatre Criteria).
|
|
209
|
+
const direct = await runExercise(fixture.baseDialect, exercise, { injectReadAfterFirstOp: false });
|
|
210
|
+
// Serializability checked FIRST (REQ-DC-04) — a directive whose content isn't even a
|
|
211
|
+
// proper serializable string makes a byte-exact comparison moot, and ordering it first
|
|
212
|
+
// proves DC-04's own assertion is what fails a closure-/live-node-smuggle fixture,
|
|
213
|
+
// rather than an incidental content mismatch masking it.
|
|
214
|
+
assertSerializable(direct.directives, "no-read exercise");
|
|
215
|
+
if (direct.modifies.length !== 1) {
|
|
216
|
+
throw new Error(`testOpPack: REQ-DC-02/03 — expected exactly ONE modify directive for a no-read chain, got ${direct.modifies.length}`);
|
|
217
|
+
}
|
|
218
|
+
if (direct.modifies[0]?.content !== exercise.expect) {
|
|
219
|
+
throw new Error("testOpPack: REQ-DC-02/03 — the coalesced modify's content did not byte-exact match the fixture's expect value");
|
|
220
|
+
}
|
|
221
|
+
if (exercise.chain.length >= 2) {
|
|
222
|
+
// Read-boundary split (fifth core assertion, self-derived — the live counterpart of
|
|
223
|
+
// the planted REQ-DC-05.2). Re-run injecting `handle.read()` right after the FIRST
|
|
224
|
+
// op: the GLOBAL flush-before-read (ADR-0015) forces exactly TWO modify directives
|
|
225
|
+
// whose cumulative content equals `expect`; directive #1's expected content is
|
|
226
|
+
// SELF-DERIVED by running the first op ALONE — no extra fixture field.
|
|
227
|
+
const firstOpOnly = {
|
|
228
|
+
seed: exercise.seed,
|
|
229
|
+
path: exercise.path,
|
|
230
|
+
chain: exercise.chain.slice(0, 1),
|
|
231
|
+
};
|
|
232
|
+
const firstOnly = await runExercise(fixture.baseDialect, firstOpOnly, { injectReadAfterFirstOp: false });
|
|
233
|
+
const expectedFirst = firstOnly.modifies[0]?.content;
|
|
234
|
+
if (expectedFirst === undefined) {
|
|
235
|
+
throw new Error("testOpPack: REQ-DC-05.2 — could not self-derive directive #1's expected content (the first op alone produced no modify)");
|
|
236
|
+
}
|
|
237
|
+
const split = await runExercise(fixture.baseDialect, exercise, { injectReadAfterFirstOp: true });
|
|
238
|
+
assertSerializable(split.directives, "read-split exercise");
|
|
239
|
+
if (split.modifies.length !== 2) {
|
|
240
|
+
throw new Error(`testOpPack: REQ-DC-05.2 read-boundary split — expected exactly TWO modify directives after a mid-chain read, got ${split.modifies.length}`);
|
|
241
|
+
}
|
|
242
|
+
if (split.modifies[0]?.content !== expectedFirst) {
|
|
243
|
+
throw new Error("testOpPack: REQ-DC-05.2 — the first split directive's content did not match the self-derived first-op-alone content");
|
|
244
|
+
}
|
|
245
|
+
if (split.modifies[1]?.content !== exercise.expect) {
|
|
246
|
+
throw new Error("testOpPack: REQ-DC-05.2 — the cumulative (second) split directive's content did not byte-exact match the fixture's expect value");
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
// REQ-DC-06/REQ-DC-08 (verify-in-loop-4 Finding #1): the four mandatory adversarial
|
|
251
|
+
// samples' round-trip + real-base probe, run against `fixture.baseDialect` — same
|
|
252
|
+
// mechanism `testDialect` runs, independent of `fixture.exercises`. Deliberately LAST
|
|
253
|
+
// (not first, unlike testDialect): a fixture's own exercises target ONE specific
|
|
254
|
+
// REQ-DC-02..05 failure mode against a baseDialect that may be intentionally non-generic
|
|
255
|
+
// (e.g. this repo's own REQ-DC-05 planted-violation fixtures use hand-rolled/identity
|
|
256
|
+
// `ast` pairs to isolate that ONE mode) — ordering the probe last lets that exercise-level
|
|
257
|
+
// failure surface for its own reason first, while still running the probe unconditionally
|
|
258
|
+
// on every call whose exercises pass, exactly as REQ-DC-06's "regardless of what samples
|
|
259
|
+
// the contributor's own fixture supplies" demands.
|
|
260
|
+
runRoundTripProbe(fixture.baseDialect.ast, mandatoryAdversarialSamples(fixture.exercises[0].seed), "testOpPack");
|
|
261
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EngineClient } from "../
|
|
2
|
-
import type { Batch } from "../
|
|
1
|
+
import type { EngineClient } from "../domain/ports/engine-client.ts";
|
|
2
|
+
import type { Batch } from "../domain/valueobjects/wire.ts";
|
|
3
3
|
export type ServedFrom = "tree" | "disk";
|
|
4
4
|
export interface ContractFakeOptions {
|
|
5
5
|
seed: Record<string, string>;
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
// create/rename/copy over an existing target → error unless effective.
|
|
6
6
|
// Idempotent delete (FAKE-05): absent target → succeed (no error).
|
|
7
7
|
import { posix as path } from "node:path";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { exceedsEmitBatchBudget } from "../domain/valueobjects/wire.js";
|
|
9
|
+
import { EMIT_BATCH_BUDGET_BYTES, EMIT_FRAME_ENVELOPE_ALLOWANCE_BYTES } from "../../../shared-kernel/batch-cap.js";
|
|
10
|
+
import { EmitRejection } from "../domain/ports/emit-rejection.js";
|
|
11
|
+
import { deepEqual } from "../../../platform/deep-equal.js";
|
|
11
12
|
import { CONTRACT_FAKE_PREFIX, ALREADY_EXISTS, USE_FORCE_TO_OVERWRITE, NOT_FOUND, EXCEEDS_SIZE_CAP, ROUND_TRIP_FIDELITY_CHECK, JSON_SERIALIZATION, } from "./rejection-messages.js";
|
|
12
13
|
export class ContractFake {
|
|
13
14
|
// Null-prototype + Object.hasOwn everywhere below: a plain-prototype seed object makes
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { Batch, Directive } from "../../domain/valueobjects/wire.ts";
|
|
2
|
+
import type { AuthoringError } from "../../domain/valueobjects/authoring-error.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The outcome of running a factory via `runFactoryForTest`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const result: RunResult = await runFactoryForTest(run, input);
|
|
8
|
+
* if (result.error === undefined) {
|
|
9
|
+
* console.log(result.tree.get("src/greeting.ts"));
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export interface RunResult {
|
|
13
|
+
/**
|
|
14
|
+
* The committed tree (`ContractFake.committedTree()`), path → content. Committed writes
|
|
15
|
+
* ONLY — an unmodified seed path is never present here, even if the factory read it.
|
|
16
|
+
* Content is stored verbatim — `{= ... =}` template placeholders are never rendered here;
|
|
17
|
+
* interpolation is the engine's job, not the harness's.
|
|
18
|
+
*/
|
|
19
|
+
tree: ReadonlyMap<string, string>;
|
|
20
|
+
/** One `Batch` per `emit()` call, in call order. */
|
|
21
|
+
emitted: Batch[];
|
|
22
|
+
/**
|
|
23
|
+
* How many reads of each path the fake engine served, in first-read order. A read of an absent
|
|
24
|
+
* path counts; a path the factory never read is not present.
|
|
25
|
+
*/
|
|
26
|
+
reads: ReadonlyMap<string, number>;
|
|
27
|
+
/**
|
|
28
|
+
* `undefined` on success. On a rejected write, the attributed `AuthoringError` from the
|
|
29
|
+
* emit seam. On a factory throw, the original thrown value, unmodified.
|
|
30
|
+
*/
|
|
31
|
+
error: AuthoringError | unknown;
|
|
32
|
+
}
|
|
33
|
+
export type { Batch, Directive };
|
|
34
|
+
/**
|
|
35
|
+
* Runs a bare author factory in-memory against a normative fake engine and returns what
|
|
36
|
+
* actually happened — closing the gap where a write-only factory (one that buffers
|
|
37
|
+
* directives but is never observed to commit them) has no author-facing test to catch it.
|
|
38
|
+
*
|
|
39
|
+
* `fn` is the bare `(input) => void | Promise<void>` author function — never a
|
|
40
|
+
* `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
|
|
41
|
+
* `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
|
|
42
|
+
* invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
|
|
43
|
+
* and spy client internally — callers never construct or pass a client.
|
|
44
|
+
*
|
|
45
|
+
* 0.x, semver-exempt: this module's result shape may still change before the SDK's first
|
|
46
|
+
* stable release, independent of the kit's own semver policy.
|
|
47
|
+
*
|
|
48
|
+
* `./testing` is the supported author-facing test harness — distinct from `./conformance`,
|
|
49
|
+
* which exercises dialect-authoring conformance, not factory behaviour.
|
|
50
|
+
*
|
|
51
|
+
* @param fn - the bare authoring function; receives the resolved input.
|
|
52
|
+
* @param input - the resolved input passed through to `fn`.
|
|
53
|
+
* @param options.seed - pre-existing tree content visible to the factory's own reads
|
|
54
|
+
* (`Record<string,string>`) — the SOLE seeding channel; never reflected in `result.tree`
|
|
55
|
+
* unless the factory itself modifies the seeded path.
|
|
56
|
+
* @param options.packageDir - opts the run into schema-derived run-boundary validation
|
|
57
|
+
* against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
|
|
58
|
+
* absent the run is the untyped, unvalidated tier, byte-identical to a run with no
|
|
59
|
+
* `packageDir` at all.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* import { runFactoryForTest } from "@pbuilder/sdk/testing";
|
|
63
|
+
* import { create, AuthoringError } from "@pbuilder/sdk/commons";
|
|
64
|
+
* import { expect, test } from "bun:test";
|
|
65
|
+
*
|
|
66
|
+
* test("factory writes a greeting file", async () => {
|
|
67
|
+
* const run = (input: { name: string }) => {
|
|
68
|
+
* create("src/greeting.ts", {
|
|
69
|
+
* template: "export const greeting = '{= .name =}';",
|
|
70
|
+
* options: { name: input.name },
|
|
71
|
+
* });
|
|
72
|
+
* };
|
|
73
|
+
*
|
|
74
|
+
* const result = await runFactoryForTest(run, { name: "hello" });
|
|
75
|
+
*
|
|
76
|
+
* if (result.error !== undefined) {
|
|
77
|
+
* if (result.error instanceof AuthoringError) {
|
|
78
|
+
* throw new Error(`unexpected rejection: ${result.error.reason}`);
|
|
79
|
+
* }
|
|
80
|
+
* throw result.error;
|
|
81
|
+
* }
|
|
82
|
+
*
|
|
83
|
+
* expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
|
|
84
|
+
* });
|
|
85
|
+
*/
|
|
86
|
+
export declare function runFactoryForTest<O>(fn: (input: O) => void | Promise<void>, input: O, options?: {
|
|
87
|
+
seed?: Record<string, string>;
|
|
88
|
+
packageDir?: string | URL;
|
|
89
|
+
}): Promise<RunResult>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { defineFactory } from "../../application/usecases/run-factory/context.js";
|
|
2
|
+
import { ContractFake } from "../contract-fake.js";
|
|
3
|
+
import { nodePackageFiles } from "../../infrastructure/out/fs/package-files.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runs a bare author factory in-memory against a normative fake engine and returns what
|
|
6
|
+
* actually happened — closing the gap where a write-only factory (one that buffers
|
|
7
|
+
* directives but is never observed to commit them) has no author-facing test to catch it.
|
|
8
|
+
*
|
|
9
|
+
* `fn` is the bare `(input) => void | Promise<void>` author function — never a
|
|
10
|
+
* `defineFactory`-wrapped runner. `runFactoryForTest` wraps `fn` internally by delegating to
|
|
11
|
+
* `defineFactory`, the SAME seam a future production runner will call (single-wrap-seam
|
|
12
|
+
* invariant) — it never reimplements the wrap. The harness constructs its own in-memory fake
|
|
13
|
+
* and spy client internally — callers never construct or pass a client.
|
|
14
|
+
*
|
|
15
|
+
* 0.x, semver-exempt: this module's result shape may still change before the SDK's first
|
|
16
|
+
* stable release, independent of the kit's own semver policy.
|
|
17
|
+
*
|
|
18
|
+
* `./testing` is the supported author-facing test harness — distinct from `./conformance`,
|
|
19
|
+
* which exercises dialect-authoring conformance, not factory behaviour.
|
|
20
|
+
*
|
|
21
|
+
* @param fn - the bare authoring function; receives the resolved input.
|
|
22
|
+
* @param input - the resolved input passed through to `fn`.
|
|
23
|
+
* @param options.seed - pre-existing tree content visible to the factory's own reads
|
|
24
|
+
* (`Record<string,string>`) — the SOLE seeding channel; never reflected in `result.tree`
|
|
25
|
+
* unless the factory itself modifies the seeded path.
|
|
26
|
+
* @param options.packageDir - opts the run into schema-derived run-boundary validation
|
|
27
|
+
* against an adjacent `schema.json` (pass `import.meta.dir`, never `import.meta.url`); when
|
|
28
|
+
* absent the run is the untyped, unvalidated tier, byte-identical to a run with no
|
|
29
|
+
* `packageDir` at all.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* import { runFactoryForTest } from "@pbuilder/sdk/testing";
|
|
33
|
+
* import { create, AuthoringError } from "@pbuilder/sdk/commons";
|
|
34
|
+
* import { expect, test } from "bun:test";
|
|
35
|
+
*
|
|
36
|
+
* test("factory writes a greeting file", async () => {
|
|
37
|
+
* const run = (input: { name: string }) => {
|
|
38
|
+
* create("src/greeting.ts", {
|
|
39
|
+
* template: "export const greeting = '{= .name =}';",
|
|
40
|
+
* options: { name: input.name },
|
|
41
|
+
* });
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* const result = await runFactoryForTest(run, { name: "hello" });
|
|
45
|
+
*
|
|
46
|
+
* if (result.error !== undefined) {
|
|
47
|
+
* if (result.error instanceof AuthoringError) {
|
|
48
|
+
* throw new Error(`unexpected rejection: ${result.error.reason}`);
|
|
49
|
+
* }
|
|
50
|
+
* throw result.error;
|
|
51
|
+
* }
|
|
52
|
+
*
|
|
53
|
+
* expect(result.tree.get("src/greeting.ts")).toEqual("export const greeting = '{= .name =}';");
|
|
54
|
+
* });
|
|
55
|
+
*/
|
|
56
|
+
export async function runFactoryForTest(fn, input, options) {
|
|
57
|
+
const fake = new ContractFake({ seed: options?.seed ?? {} });
|
|
58
|
+
const emitted = [];
|
|
59
|
+
const reads = new Map();
|
|
60
|
+
const client = {
|
|
61
|
+
emit(batch) {
|
|
62
|
+
emitted.push(batch);
|
|
63
|
+
return fake.emit(batch);
|
|
64
|
+
},
|
|
65
|
+
read(path) {
|
|
66
|
+
reads.set(path, (reads.get(path) ?? 0) + 1);
|
|
67
|
+
return fake.read(path);
|
|
68
|
+
},
|
|
69
|
+
commit() {
|
|
70
|
+
return fake.commit();
|
|
71
|
+
},
|
|
72
|
+
discard() {
|
|
73
|
+
return fake.discard();
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const run = defineFactory(fn, options?.packageDir !== undefined ? { packageDir: options.packageDir, packageFiles: nodePackageFiles } : undefined);
|
|
77
|
+
let error;
|
|
78
|
+
try {
|
|
79
|
+
await run(input, { client });
|
|
80
|
+
}
|
|
81
|
+
catch (caught) {
|
|
82
|
+
error = caught;
|
|
83
|
+
}
|
|
84
|
+
return { tree: fake.committedTree(), emitted, reads, error };
|
|
85
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Batch } from "../
|
|
1
|
+
import type { Batch } from "../domain/valueobjects/wire.ts";
|
|
2
2
|
/** Local structural mirror of the transport port — never names the port type (see header). */
|
|
3
3
|
interface RunVehicleClient {
|
|
4
4
|
emit(batch: Batch): Promise<void>;
|
package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/bootstrap-bridge.js
RENAMED
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
// REAL default in an isolated spawned child; integration tests inject a no-op stand-in
|
|
24
24
|
// (mirrors single-instance-probe.ts's injectable resolver).
|
|
25
25
|
import { runRunner } from "./runner.js";
|
|
26
|
-
import { captureFd1FrameWriter, redirectConsoleToStderr } from "
|
|
27
|
-
import { BRIDGE_CONTRACT_VERSION } from "
|
|
26
|
+
import { captureFd1FrameWriter, redirectConsoleToStderr } from "../../../../shared-kernel/framing.js";
|
|
27
|
+
import { BRIDGE_CONTRACT_VERSION } from "../../../../shared-kernel/wire-protocol.js";
|
|
28
28
|
export class BridgeVersionMismatchError extends Error {
|
|
29
29
|
constructor(expected, actual) {
|
|
30
30
|
super(`bootstrap-bridge: contract version mismatch — bootstrap expects ${expected}, installed SDK bridge is ${actual}`);
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
// e.g. a failed discard()) as E1's `.cause` and re-throws E1 unchanged; because this
|
|
9
9
|
// classifier never looks past the error it is handed, E2 can never override E1's class —
|
|
10
10
|
// preservation falls out of the classifier's own narrowness, not a special case.
|
|
11
|
-
import {
|
|
12
|
-
import { TransportFault, IntentRejectedError } from "
|
|
11
|
+
import { authoringOrigin } from "../../../authoring/application/usecases/run-factory/driving.js";
|
|
12
|
+
import { TransportFault, IntentRejectedError } from "../../../../acl/irwire/stdio-engine-client.js";
|
|
13
13
|
// REQ-EXC-01 table: 1 validation-failure, 2 emit-rejection, 3 transport-fault,
|
|
14
14
|
// 4 crash (the fallback for anything unclassified, including a non-Error thrown value —
|
|
15
15
|
// never throws while classifying). IntentRejectedError is code 2 by the table's own text:
|
|
16
16
|
// "the host refused a write or an advisory commit/discard intent" — the host-refusal
|
|
17
17
|
// family, distinct from a wire-level fault (3) and from an unclassified crash (4).
|
|
18
18
|
export function classifyExitCode(err) {
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const origin = authoringOrigin(err);
|
|
20
|
+
if (origin !== undefined) {
|
|
21
|
+
return origin === "authoring-rejected" ? 1 : 2;
|
|
21
22
|
}
|
|
22
23
|
if (err instanceof IntentRejectedError) {
|
|
23
24
|
return 2;
|
package/dist/{transport → bounded-contexts/runner-hosting/infrastructure/in}/factory-pointer.js
RENAMED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// empty-host allowlist, RUN-03's 3-form export resolution, and RUN-06's double-wrap check
|
|
5
5
|
// are S-002 additions to this same file. RUN-07's import-failure split lives in runner.ts
|
|
6
6
|
// (it classifies the dynamic `import()` call itself, which this file never performs).
|
|
7
|
-
import { isDefineFactoryWrapped } from "
|
|
7
|
+
import { isDefineFactoryWrapped } from "../../../authoring/application/usecases/run-factory/context.js";
|
|
8
8
|
// Splits on the FIRST '#' only — a url containing a later literal '#' (e.g. percent-encoded
|
|
9
9
|
// as %23 in practice, but defensively handled here regardless) is never mis-split.
|
|
10
10
|
export function parseFactoryPointer(pointer) {
|
|
@@ -5,7 +5,11 @@ export interface RunnerIo {
|
|
|
5
5
|
writeFrame: (value: unknown) => void;
|
|
6
6
|
/** Bounded operator-visible notes (stderr on the spawned path). Never the wire. */
|
|
7
7
|
writeStderr: (text: string) => void;
|
|
8
|
+
/** How long to wait for the host's `ready` frame; `GREETING_TIMEOUT_MS` when absent. */
|
|
9
|
+
greetingTimeoutMs?: number;
|
|
8
10
|
}
|
|
11
|
+
/** The greeting's own bound: the client's per-call timeout only exists once the greeting is in. */
|
|
12
|
+
export declare const GREETING_TIMEOUT_MS = 30000;
|
|
9
13
|
export declare const INPUT_FILE_SIZE_CAP_BYTES: number;
|
|
10
14
|
/**
|
|
11
15
|
* Runs one factory over the framed wire: parses/validates argv and input (RUN-01/04),
|