behavior-contracts 0.10.1 → 0.11.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 +246 -350
- package/cli-contract.yaml +49 -51
- package/dist/authoring.d.ts +61 -424
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +53 -1157
- package/dist/authoring.js.map +1 -1
- package/dist/behavior.d.ts +7 -15
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js.map +1 -1
- package/dist/builder.d.ts +4 -4
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js +9 -11
- package/dist/builder.js.map +1 -1
- package/dist/cli.js +5 -5
- package/dist/cli.js.map +1 -1
- package/dist/commands/codegen.d.ts.map +1 -1
- package/dist/commands/codegen.js +12 -56
- package/dist/commands/codegen.js.map +1 -1
- package/dist/commands/ts-compile.d.ts +23 -0
- package/dist/commands/ts-compile.d.ts.map +1 -0
- package/dist/commands/ts-compile.js +724 -0
- package/dist/commands/ts-compile.js.map +1 -0
- package/dist/commands/ts-extract.d.ts +67 -1
- package/dist/commands/ts-extract.d.ts.map +1 -1
- package/dist/commands/ts-extract.js +162 -31
- package/dist/commands/ts-extract.js.map +1 -1
- package/dist/generated/contract.d.ts.map +1 -1
- package/dist/generated/contract.js +2 -2
- package/dist/generated/contract.js.map +1 -1
- package/dist/generated/program.js +4 -4
- package/dist/generated/program.js.map +1 -1
- package/dist/generator/core.d.ts +11 -1
- package/dist/generator/core.d.ts.map +1 -1
- package/dist/generator/core.js +5 -4
- package/dist/generator/core.js.map +1 -1
- package/dist/generator/emit-php.d.ts +0 -17
- package/dist/generator/emit-php.d.ts.map +1 -1
- package/dist/generator/emit-php.js +25 -1
- package/dist/generator/emit-php.js.map +1 -1
- package/dist/generator/emit-python.d.ts +0 -7
- package/dist/generator/emit-python.d.ts.map +1 -1
- package/dist/generator/emit-python.js +34 -1
- package/dist/generator/emit-python.js.map +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js +1 -1
- package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +110 -107
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +3 -2
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +55 -123
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/emit-typescript-native.js +1 -1
- package/dist/generator/emit-typescript-native.js.map +1 -1
- package/dist/generator/emit-typescript.js +1 -1
- package/dist/generator/emit-typescript.js.map +1 -1
- package/dist/generator/typed.d.ts +5 -1
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +40 -9
- package/dist/generator/typed.js.map +1 -1
- package/dist/guard.d.ts +4 -0
- package/dist/guard.d.ts.map +1 -1
- package/dist/guard.js +26 -8
- package/dist/guard.js.map +1 -1
- package/dist/index.d.ts +19 -57
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -101
- package/dist/index.js.map +1 -1
- package/dist/lowering.d.ts +251 -0
- package/dist/lowering.d.ts.map +1 -0
- package/dist/lowering.js +652 -0
- package/dist/lowering.js.map +1 -0
- package/dist/provenance.js +4 -4
- package/dist/provenance.js.map +1 -1
- package/dist/runtime.d.ts +52 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +77 -0
- package/dist/runtime.js.map +1 -0
- package/dist/spec-versions.d.ts +25 -0
- package/dist/spec-versions.d.ts.map +1 -0
- package/dist/spec-versions.js +26 -0
- package/dist/spec-versions.js.map +1 -0
- package/dist/type-gate.d.ts +12 -0
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +79 -3
- package/dist/type-gate.js.map +1 -1
- package/package.json +5 -1
- package/dist/bind.d.ts +0 -88
- package/dist/bind.d.ts.map +0 -1
- package/dist/bind.js +0 -155
- package/dist/bind.js.map +0 -1
- package/dist/lower.d.ts +0 -35
- package/dist/lower.d.ts.map +0 -1
- package/dist/lower.js +0 -118
- package/dist/lower.js.map +0 -1
|
@@ -211,10 +211,6 @@ function rustPayloadBatch(itemsExpr) {
|
|
|
211
211
|
function rustListItems(wvExpr) {
|
|
212
212
|
return `match ${wvExpr} { WireValue::List(l) => l.items, _ => Vec::new() }`;
|
|
213
213
|
}
|
|
214
|
-
/** InNR<Comp> — the concrete per-component input struct name (fields = inputPorts). */
|
|
215
|
-
function inStructName(compName) {
|
|
216
|
-
return `InNR${pascal(compName)}`;
|
|
217
|
-
}
|
|
218
214
|
// ── strict de-box: the probe/wire seam + generated decode orchestration ───────────────────────
|
|
219
215
|
//
|
|
220
216
|
// A covered record read returns the consumer's WIRE (a value implementing WireRow), and the generated
|
|
@@ -690,7 +686,9 @@ function nativeResolveHead(comp, plan, typedNodes, isPrior, opts) {
|
|
|
690
686
|
const ref = inputPortTypeRef(comp.inputPorts?.[head], plan);
|
|
691
687
|
if (ref === undefined)
|
|
692
688
|
return null;
|
|
693
|
-
|
|
689
|
+
// #192: the input port is a positional PARAMETER of the entry (box removed) — read it by param name
|
|
690
|
+
// (= rustFieldName(port), the single input-ref name source; same owned-value semantics as `in_.field`).
|
|
691
|
+
return { expr: rustFieldName(head), ref, own: rustOwn(false, ownArrays) };
|
|
694
692
|
};
|
|
695
693
|
}
|
|
696
694
|
/** compilePortNode — lower a port expression to its native ports-struct field via the runtime-free
|
|
@@ -1099,8 +1097,10 @@ function rustOverElemInfo(comp, over, typedNodes, plan, nodeId, label) {
|
|
|
1099
1097
|
if (e.kind === "ref" && e.path.length === 1) {
|
|
1100
1098
|
const schema = comp.inputPorts?.[e.path[0]];
|
|
1101
1099
|
const et = schema?.elemType;
|
|
1100
|
+
// #192: read the input array port by its positional PARAM name (= rustFieldName(port), same name
|
|
1101
|
+
// source as the seam) — box removed, no `in_.` prefix; `.clone()` owns the iterated Vec.
|
|
1102
1102
|
if (et !== undefined)
|
|
1103
|
-
return { elemRef: deriveTypeRef(et, plan), overExpr:
|
|
1103
|
+
return { elemRef: deriveTypeRef(et, plan), overExpr: `${rustFieldName(e.path[0])}.clone()`, optArr: inputPortIsOptional(schema) };
|
|
1104
1104
|
}
|
|
1105
1105
|
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `rust ${label}: '${nodeId}' 'over' must be a ref to a prior node's typed arr field OR an input array port with a declared elemType. BC does not infer input-array element types (consumer-interface C3).`);
|
|
1106
1106
|
}
|
|
@@ -1471,38 +1471,6 @@ function inputScalarKind(schema) {
|
|
|
1471
1471
|
return undefined;
|
|
1472
1472
|
}
|
|
1473
1473
|
}
|
|
1474
|
-
/** emitInStruct — the concrete input struct declaration for a covered component (fields = inputPorts).
|
|
1475
|
-
* Empty inputPorts => empty struct. Default lets a consumer/test build it field-by-field: derived when every
|
|
1476
|
-
* field is Defaultable, else a manual `impl Default` (a bare scalar `value` input port is `WireValue`, which
|
|
1477
|
-
* has no derived Default — bc#156/#160). Mirrors the emitTypeDecls/emitDefaults SSoT for the outType decls. */
|
|
1478
|
-
function emitInStruct(comp, plan) {
|
|
1479
|
-
const { isDefaultable, defaultExpr } = rustTypedInternals;
|
|
1480
|
-
const name = inStructName(comp.name);
|
|
1481
|
-
const ports = Object.keys(comp.inputPorts ?? {});
|
|
1482
|
-
if (ports.length === 0) {
|
|
1483
|
-
return `// ${name} — the CONCRETE input for '${comp.name}' (no input ports).\n#[derive(Default)]\npub struct ${name};`;
|
|
1484
|
-
}
|
|
1485
|
-
// #139: inputPortRustType reads the inputPortTypeRef SSoT — an OPTIONAL port is `Option<T>` (absent →
|
|
1486
|
-
// None); an optional whose inner type has no native lowering FAILS CLOSED (never a boxed escape).
|
|
1487
|
-
const fieldRefs = ports.map((p) => inputPortTypeRef(comp.inputPorts[p], plan));
|
|
1488
|
-
const fields = ports
|
|
1489
|
-
.map((p) => ` pub ${rustFieldName(p)}: ${inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}, // ${JSON.stringify(p)}`)
|
|
1490
|
-
.join("\n");
|
|
1491
|
-
// A field whose type has no native lowering (`inputPortTypeRef` undefined) resolves to `Value` — never
|
|
1492
|
-
// Defaultable — so it takes the manual path too. Otherwise defer to the SSoT isDefaultable predicate.
|
|
1493
|
-
const allDefaultable = fieldRefs.every((r) => r !== undefined && isDefaultable(r, plan));
|
|
1494
|
-
const decl = `// ${name} — the CONCRETE input for '${comp.name}' (fields = inputPorts; typed, consumer-built —
|
|
1495
|
-
// NO generic Value slice, NO per-field boxing crosses the covered read boundary).`;
|
|
1496
|
-
if (allDefaultable) {
|
|
1497
|
-
return `${decl}\n#[derive(Default)]\npub struct ${name} {\n${fields}\n}`;
|
|
1498
|
-
}
|
|
1499
|
-
// A bare scalar `value` input port is `WireValue` (no derived Default) — hand-write Default from the SSoT
|
|
1500
|
-
// per-field defaultExpr (the SAME impl emitDefaults writes for a non-Defaultable outType decl).
|
|
1501
|
-
const inits = ports
|
|
1502
|
-
.map((p, i) => ` ${rustFieldName(p)}: ${fieldRefs[i] !== undefined ? defaultExpr(fieldRefs[i]) : "Value::default()"},`)
|
|
1503
|
-
.join("\n");
|
|
1504
|
-
return `${decl}\npub struct ${name} {\n${fields}\n}\nimpl Default for ${name} {\n fn default() -> Self {\n ${name} {\n${inits}\n }\n }\n}`;
|
|
1505
|
-
}
|
|
1506
1474
|
/** A ref resolver for native lowering: given a ref head + remaining field path, return a native scalar
|
|
1507
1475
|
* Rust expression (typed input field / prior-node typed struct scalar / element binding field), or null
|
|
1508
1476
|
* when the ref does not resolve to a REQUIRED (non-opt) native scalar (then the caller falls back to the
|
|
@@ -1570,57 +1538,10 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1570
1538
|
};
|
|
1571
1539
|
const outRef = comp.outputType !== undefined ? deriveTypeRef(comp.outputType, plan) : undefined;
|
|
1572
1540
|
const outTy = outRef ? renderTypeRef(outRef) : "Value";
|
|
1573
|
-
//
|
|
1574
|
-
//
|
|
1575
|
-
// not just ref/concat — a cond `if:{gt:[{add:[{ref:["x"]}…]}]}` reads `in_.x` through nested operators.
|
|
1576
|
-
const readsInput = (() => {
|
|
1577
|
-
// walk any Expression IR node; `bound` = names bound in this scope (a map $as) that are NOT input.
|
|
1578
|
-
const walk = (node, atPos, bound) => {
|
|
1579
|
-
if (node === null || typeof node === "boolean" || typeof node === "string" || typeof node === "number")
|
|
1580
|
-
return false;
|
|
1581
|
-
if (Array.isArray(node))
|
|
1582
|
-
return node.some((el) => walk(el, atPos, bound));
|
|
1583
|
-
const rec = node;
|
|
1584
|
-
const keys = Object.keys(rec);
|
|
1585
|
-
if (keys.length === 1 && (keys[0] === "ref" || keys[0] === "refOpt")) {
|
|
1586
|
-
const path = rec[keys[0]];
|
|
1587
|
-
const head = path[0];
|
|
1588
|
-
return !bound.has(head) && !priorNodeAt(head, atPos);
|
|
1589
|
-
}
|
|
1590
|
-
// any other single-key operator (obj/arr/concat/add/gt/cond/…): recurse into every child value.
|
|
1591
|
-
return keys.some((k) => walk(rec[k], atPos, bound));
|
|
1592
|
-
};
|
|
1593
|
-
return [...order.keys()].some((k) => {
|
|
1594
|
-
const nd = comp.body[order[k]];
|
|
1595
|
-
if ("fanout" in nd) {
|
|
1596
|
-
const fo = nd.fanout;
|
|
1597
|
-
const bound = new Set([fo.as]);
|
|
1598
|
-
// the fanout's OVER is evaluated in the outer scope (may read input); ports in element scope.
|
|
1599
|
-
if (walk(fo.over, k, new Set()))
|
|
1600
|
-
return true;
|
|
1601
|
-
return Object.values(fo.ports).some((pn) => walk(pn, k, bound));
|
|
1602
|
-
}
|
|
1603
|
-
if ("map" in nd) {
|
|
1604
|
-
const m = nd.map;
|
|
1605
|
-
const bound = new Set([m.as]);
|
|
1606
|
-
// the map's OVER is evaluated in the outer scope (may read input); ports + when in element scope.
|
|
1607
|
-
if (walk(m.over, k, new Set()))
|
|
1608
|
-
return true;
|
|
1609
|
-
if (m.when !== undefined && walk(m.when, k, bound))
|
|
1610
|
-
return true;
|
|
1611
|
-
return Object.values(m.ports).some((pn) => walk(pn, k, bound));
|
|
1612
|
-
}
|
|
1613
|
-
if ("cond" in nd) {
|
|
1614
|
-
const c = nd.cond;
|
|
1615
|
-
return walk(c.if, k, new Set()) || walk(c.then, k, new Set()) || walk(c.else, k, new Set());
|
|
1616
|
-
}
|
|
1617
|
-
const cr = nd;
|
|
1618
|
-
return Object.values(cr.ports).some((pn) => walk(pn, k, new Set()));
|
|
1619
|
-
});
|
|
1620
|
-
})();
|
|
1621
|
-
const inParam = readsInput ? "in_" : "_in_";
|
|
1541
|
+
// #192: the entry takes POSITIONAL params (one per input port; box removed). An unused param is allowed
|
|
1542
|
+
// by the module banner's `unused_variables` (added below) — no per-param `_` prefix / usage walk needed.
|
|
1622
1543
|
const lines = [];
|
|
1623
|
-
lines.push(`//
|
|
1544
|
+
lines.push(`// ${rustFieldName(comp.name)} — the STRUCT-RETURNING combined read (bc#77/#87/#94): the fully`);
|
|
1624
1545
|
lines.push(`// de-plumbed CONCRETE path. At each covered node's execution point it calls the op-agnostic leaf`);
|
|
1625
1546
|
lines.push(`// TRANSPORT symbol DIRECTLY (the node's port fields spread — no per-node handler indirection) and`);
|
|
1626
1547
|
lines.push(`// de-boxes the returned wire INLINE (match wire.as_*() { … } fully unrolled — no decode helper) into`);
|
|
@@ -1636,8 +1557,12 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
|
|
|
1636
1557
|
// so the runner is itself `async fn` and returns a future the (already-async) consumer awaits. Sync
|
|
1637
1558
|
// default emits `pub fn` exactly as before (byte-identical).
|
|
1638
1559
|
const fnKw = isAsync ? "pub async fn" : "pub fn";
|
|
1639
|
-
|
|
1640
|
-
|
|
1560
|
+
// #192: 1:1 map of the authored method — the entry is the exported fn `<method>` (rustFieldName; no
|
|
1561
|
+
// `run_native_raw_struct_` prefix) taking POSITIONAL params (one per input port; `In_<comp>` box removed).
|
|
1562
|
+
lines.push(`${fnKw} ${rustFieldName(comp.name)}(`);
|
|
1563
|
+
for (const p of Object.keys(comp.inputPorts ?? {})) {
|
|
1564
|
+
lines.push(` ${rustFieldName(p)}: ${inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)},`);
|
|
1565
|
+
}
|
|
1641
1566
|
lines.push(`) -> Result<${outTy}, BehaviorError> {`);
|
|
1642
1567
|
for (const k of order.keys()) {
|
|
1643
1568
|
const nd = comp.body[order[k]];
|
|
@@ -2405,9 +2330,9 @@ function valueLeafProduced(expr, ref, expected) {
|
|
|
2405
2330
|
// ── struct dispatch surface (STRUCT-only — no Value bind, no serializer) ─────────────────
|
|
2406
2331
|
function emitStructSurface(native) {
|
|
2407
2332
|
const names = native.map((c) => rustStrLit(c.name));
|
|
2408
|
-
return `// COMPONENT_NAMES_NATIVE_RAW — covered reads exposed on the combined struct-native path. Each is
|
|
2409
|
-
//
|
|
2410
|
-
//
|
|
2333
|
+
return `// COMPONENT_NAMES_NATIVE_RAW — covered reads exposed on the combined struct-native path. Each is a
|
|
2334
|
+
// 1:1 entry <method>(<positional params>) -> Result<T, BehaviorError>: a STRUCT return (the consumer calls
|
|
2335
|
+
// it with the authored args + supplies the op-agnostic leaf transport symbols the entry calls).
|
|
2411
2336
|
// See INTEGRATION.md §6.
|
|
2412
2337
|
pub const COMPONENT_NAMES_NATIVE_RAW: [&str; ${names.length}] = [${names.join(", ")}];`;
|
|
2413
2338
|
}
|
|
@@ -2492,7 +2417,6 @@ ${emitStructSurface([])}
|
|
|
2492
2417
|
// #108: reset the native-expr helper-usage accumulator (set by the cond/guard compiler).
|
|
2493
2418
|
rustExprUsed.helpers = false;
|
|
2494
2419
|
const leaf = ctx.leafTransport;
|
|
2495
|
-
const inStructs = [];
|
|
2496
2420
|
const elemMaterializers = [];
|
|
2497
2421
|
// every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
|
|
2498
2422
|
// WireValue/WireRow/WireList traits) is emitted once whenever any handler node exists.
|
|
@@ -2512,7 +2436,7 @@ ${emitStructSurface([])}
|
|
|
2512
2436
|
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
2513
2437
|
// #183: a covered node's ports cross the transport boundary as ONE op-agnostic `WireRow` payload built
|
|
2514
2438
|
// inline at the call site — there are NO per-node ports structs on the covered plane or the shared crate.
|
|
2515
|
-
|
|
2439
|
+
// #192: no `InNR_<comp>` input box — the entry takes positional params.
|
|
2516
2440
|
const mm = emitMapElemMaterializers(c, typedNodes, plan);
|
|
2517
2441
|
if (mm)
|
|
2518
2442
|
elemMaterializers.push(mm);
|
|
@@ -2553,7 +2477,7 @@ ${emitStructSurface([])}
|
|
|
2553
2477
|
// the wire seam is emitted LOCALLY only when NOT cross-package (else it lives in the shared module).
|
|
2554
2478
|
const emitsWireTypes = anyWire && !crossPackage;
|
|
2555
2479
|
// (nonNative.length === 0 is guaranteed here — the fail-closed guard above threw otherwise.)
|
|
2556
|
-
const banner = `#![allow(dead_code, unused_imports, non_snake_case)]
|
|
2480
|
+
const banner = `#![allow(dead_code, unused_imports, unused_variables, non_snake_case)]
|
|
2557
2481
|
// GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
|
|
2558
2482
|
// FULLY-NATIVE). A covered read is a strictly-sequential typed componentRef chain (point reads +
|
|
2559
2483
|
// relationKind:single children), emitted ONLY as a STRUCT-returning runner that calls the op-agnostic leaf
|
|
@@ -2567,8 +2491,9 @@ ${emitStructSurface([])}
|
|
|
2567
2491
|
// codes, byte-equal to run_behavior). INLINE sequential (no plan driver) so a relation child reads the
|
|
2568
2492
|
// parent's REAL struct result via direct field access and the child-present decision is made from the real
|
|
2569
2493
|
// parent value — relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API
|
|
2570
|
-
// is
|
|
2571
|
-
// the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport
|
|
2494
|
+
// is the 1:1 entry <method>(<positional params>) -> Result<T, BehaviorError> (the InNR_<comp> box removed);
|
|
2495
|
+
// the consumer supplies the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport
|
|
2496
|
+
// import). This module
|
|
2572
2497
|
// is FULLY NATIVE: a naive grep for boxing primitives OR for the bc-runtime crate finds nothing, by design.
|
|
2573
2498
|
use std::cell::RefCell;`;
|
|
2574
2499
|
const sections = [
|
|
@@ -2588,7 +2513,7 @@ use std::cell::RefCell;`;
|
|
|
2588
2513
|
rustExprUsed.helpers
|
|
2589
2514
|
? `// #108 native-expr helper library (runtime-free; byte-equal to expr-eval.ts core) — used by\n// cond / map-guard checked arithmetic. NO bc-runtime reference (failures use the LOCAL BehaviorError).\n${emitExprHelpersRust()}`
|
|
2590
2515
|
: undefined,
|
|
2591
|
-
|
|
2516
|
+
// #192: no per-component `InNR_<comp>` input structs — the entry takes positional params (box removed).
|
|
2592
2517
|
emitsWireTypes
|
|
2593
2518
|
? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList): the\n// consumer's single transport takes a WireRow payload + builds + returns a WireValue, implements NOTHING over\n// it. The generated INLINE de-box classifies it against the STATICALLY declared type and owns strictness\n// (required/optional, present/absent, error assembly, fail-closed). Self-contained concrete types.\n${emitRustProbeWireTypes(true)}`
|
|
2594
2519
|
: undefined,
|
|
@@ -2750,9 +2675,14 @@ ${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
|
|
|
2750
2675
|
// bc#97: an async runner returns a Future — drive it to completion with the std-only block-on
|
|
2751
2676
|
// (bc_block_on) so observe_native_raw keeps its SYNC external signature (the harness is unchanged).
|
|
2752
2677
|
// The scripted async node_* return ready values, so the future needs no real executor / no runtime.
|
|
2753
|
-
|
|
2678
|
+
// #192: decode the generic test input into the entry's POSITIONAL args (test glue), then call the
|
|
2679
|
+
// 1:1 entry positionally (box removed). A no-input entry is called with no args (no decoder).
|
|
2680
|
+
const args = Object.keys(c.inputPorts ?? {}).map((p) => rustFieldName(p));
|
|
2681
|
+
const runnerCall = `super::${rustFieldName(c.name)}(${args.join(", ")})`;
|
|
2754
2682
|
const driven = asyncPlans.get(c.name).runnerIsAsync ? `bc_block_on(${runnerCall})` : runnerCall;
|
|
2755
|
-
|
|
2683
|
+
const decode = args.length === 0 ? "" : ` let (${args.join(", ")},) = decode_${sanitize(c.name)}(input).map_err(to_rt_err)?;\n`;
|
|
2684
|
+
const unusedInput = args.length === 0 ? " let _ = input;\n" : "";
|
|
2685
|
+
return ` ${rustStrLit(c.name)} => {\n${decode}${unusedInput} let tv = ${driven}.map_err(to_rt_err)?;\n Ok(${ser})\n }`;
|
|
2756
2686
|
})
|
|
2757
2687
|
.join("\n");
|
|
2758
2688
|
// the scripted-outcome source is a MODULE-LEVEL static (Mutex<Option<HashMap>> + AtomicUsize), NOT a
|
|
@@ -2816,7 +2746,7 @@ fn next_scripted(component: &str) -> Option<(bool, String, Option<Value>, String
|
|
|
2816
2746
|
// static and return the scripted wire (exactly the shape the removed per-node trait method returned). The
|
|
2817
2747
|
// consumer never uses this (it keeps the model native + supplies its own transport fns over its own wire
|
|
2818
2748
|
// payload); it exists only so the test harness can byte-compare the STRUCT-only covered read against
|
|
2819
|
-
// run_behavior. A submodule of the covered module (reads its pub
|
|
2749
|
+
// run_behavior. A submodule of the covered module (reads its pub entry fns + the CONCRETE
|
|
2820
2750
|
// structs — incl. the LOCAL BehaviorError — via super::*, and its \`leaf_<comp>\` fns resolve the covered
|
|
2821
2751
|
// module's transport calls). bc#90 / runtime-free: the covered module's BehaviorError is LOCAL, so this
|
|
2822
2752
|
// test-glue companion refers to it via super::* (as \`BehaviorError\`) and refers to the bc-runtime failure
|
|
@@ -2910,26 +2840,28 @@ ${arms}
|
|
|
2910
2840
|
}
|
|
2911
2841
|
`;
|
|
2912
2842
|
}
|
|
2913
|
-
/** emitInDecoder — a TEST-glue decoder `
|
|
2914
|
-
* Reads each declared input port from the generic &[(String,Value)] into
|
|
2915
|
-
* typed read;
|
|
2916
|
-
*
|
|
2843
|
+
/** emitInDecoder — a TEST-glue decoder `decode_<comp>(input) -> Result<(<positional args...>,), BehaviorError>`.
|
|
2844
|
+
* Reads each declared input port from the generic &[(String,Value)] into a local (= the entry's positional
|
|
2845
|
+
* param; scalar → typed read; value-typed → the raw wire clone), returned as a tuple the observe companion
|
|
2846
|
+
* destructures and passes positionally to the 1:1 entry (#192, box removed). A missing key leaves Default
|
|
2847
|
+
* (every covered input is required + supplied by the corpus). Lives ONLY in the observe companion. */
|
|
2917
2848
|
function emitInDecoder(comp, plan) {
|
|
2918
|
-
const name = inStructName(comp.name);
|
|
2919
2849
|
const ports = Object.keys(comp.inputPorts ?? {});
|
|
2850
|
+
if (ports.length === 0 || comp.inputPorts === undefined)
|
|
2851
|
+
return ""; // no input → observe calls the entry with no args.
|
|
2852
|
+
const args = ports.map((p) => rustFieldName(p));
|
|
2853
|
+
const types = ports.map((p) => inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`));
|
|
2920
2854
|
const lines = [];
|
|
2921
|
-
|
|
2922
|
-
lines.push(`
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
return lines.join("\n");
|
|
2928
|
-
}
|
|
2855
|
+
// trailing comma → always a tuple (never a parenthesized single value).
|
|
2856
|
+
lines.push(`fn decode_${sanitize(comp.name)}(input: &[(String, Value)]) -> Result<(${types.join(", ")},), BehaviorError> {`);
|
|
2857
|
+
// neutral init per port: a SCALAR `value` port renders as bare `WireValue` (no Default) — init it
|
|
2858
|
+
// with `WireValue::Null`, the SAME value-kind neutral the covered emitter uses for value cells (the
|
|
2859
|
+
// cellInit SSoT above). Every other port type (scalar, Vec<WireValue>, Option<…>) has a Default.
|
|
2860
|
+
ports.forEach((p, i) => lines.push(` let mut ${args[i]}: ${types[i]} = ${comp.inputPorts[p]?.type === "value" ? "WireValue::Null" : "Default::default()"};`));
|
|
2929
2861
|
// an if/else-if chain (clippy-clean regardless of port count — a single-arm `match` trips single_match).
|
|
2930
2862
|
lines.push(` for (k, v) in input {`);
|
|
2931
2863
|
ports.forEach((p, i) => {
|
|
2932
|
-
const field =
|
|
2864
|
+
const field = args[i];
|
|
2933
2865
|
const schema = comp.inputPorts[p];
|
|
2934
2866
|
const scalar = inputScalarKind(schema);
|
|
2935
2867
|
const et = schema.elemType;
|
|
@@ -2948,28 +2880,28 @@ function emitInDecoder(comp, plan) {
|
|
|
2948
2880
|
lines.push(` let mut dec: Vec<${elemTy}> = Vec::with_capacity(a.len());`);
|
|
2949
2881
|
lines.push(` for ev in a.iter() { dec.push(${mat}); }`);
|
|
2950
2882
|
// #177 (A): an OPTIONAL array port field is `Option<Vec<E>>` (inputPortTypeRef opt), so wrap in Some.
|
|
2951
|
-
lines.push(`
|
|
2883
|
+
lines.push(` ${field} = ${inputPortIsOptional(schema) ? "Some(dec)" : "dec"};`);
|
|
2952
2884
|
lines.push(` }`);
|
|
2953
2885
|
lines.push(` other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected array, got `)}, other.type_name())),`);
|
|
2954
2886
|
lines.push(` }`);
|
|
2955
2887
|
}
|
|
2956
2888
|
else if (schema?.type === "value") {
|
|
2957
2889
|
// bc#156: a scalar `value` port — the raw bound value as BC's opaque wire (value_to_wire).
|
|
2958
|
-
lines.push(`
|
|
2890
|
+
lines.push(` ${field} = value_to_wire(v);`);
|
|
2959
2891
|
}
|
|
2960
2892
|
else if (schema?.type === "map" && et !== undefined) {
|
|
2961
2893
|
// #108-map: decode the boxed Value::Obj into the native BTreeMap<String, V> (test glue — the input
|
|
2962
2894
|
// map port carries a declared elemType). materializeExpr covers the map de-box (obj → BTreeMap).
|
|
2963
2895
|
const mapRef = { kind: "map", value: deriveTypeRef(et, plan) };
|
|
2964
|
-
lines.push(`
|
|
2896
|
+
lines.push(` ${field} = ${materializeExpr("v", mapRef, plan)};`);
|
|
2965
2897
|
}
|
|
2966
2898
|
else if (inputPortIsOptional(schema)) {
|
|
2967
2899
|
// #139: an OPTIONAL scalar port decodes into Option<T> via the inputPortTypeRef SSoT (a present key
|
|
2968
2900
|
// materializes Some(v); an absent key never enters this block, leaving the Default None).
|
|
2969
|
-
lines.push(`
|
|
2901
|
+
lines.push(` ${field} = ${materializeExpr("v", inputPortTypeRef(schema, plan), plan)};`);
|
|
2970
2902
|
}
|
|
2971
2903
|
else if (scalar === undefined) {
|
|
2972
|
-
lines.push(`
|
|
2904
|
+
lines.push(` ${field} = v.clone();`);
|
|
2973
2905
|
}
|
|
2974
2906
|
else {
|
|
2975
2907
|
const pat = scalar === "String" ? "Value::Str(sv)" : scalar === "i64" ? "Value::Int(sv)" : scalar === "f64" ? "Value::Float(sv)" : "Value::Bool(sv)";
|
|
@@ -2977,12 +2909,12 @@ function emitInDecoder(comp, plan) {
|
|
|
2977
2909
|
const bind = scalar === "String" ? "sv.clone()" : "*sv";
|
|
2978
2910
|
// bc#90 / runtime-free: build the module-LOCAL BehaviorError (TYPE_MISMATCH) via the local
|
|
2979
2911
|
// marshal_type_error helper — decode_* returns the local error, bridged at the observe boundary.
|
|
2980
|
-
lines.push(` match v { ${pat} =>
|
|
2912
|
+
lines.push(` match v { ${pat} => ${field} = ${bind}, other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected ${label}, got `)}, other.type_name())) }`);
|
|
2981
2913
|
}
|
|
2982
2914
|
});
|
|
2983
2915
|
lines.push(` }`);
|
|
2984
2916
|
lines.push(` }`);
|
|
2985
|
-
lines.push(` Ok(
|
|
2917
|
+
lines.push(` Ok((${args.join(", ")},))`);
|
|
2986
2918
|
lines.push(`}`);
|
|
2987
2919
|
return lines.join("\n");
|
|
2988
2920
|
}
|