behavior-contracts 0.10.1 → 0.11.1

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.
Files changed (97) hide show
  1. package/README.md +246 -350
  2. package/cli-contract.yaml +49 -51
  3. package/dist/authoring.d.ts +80 -420
  4. package/dist/authoring.d.ts.map +1 -1
  5. package/dist/authoring.js +53 -1157
  6. package/dist/authoring.js.map +1 -1
  7. package/dist/behavior.d.ts +31 -15
  8. package/dist/behavior.d.ts.map +1 -1
  9. package/dist/behavior.js +55 -0
  10. package/dist/behavior.js.map +1 -1
  11. package/dist/builder.d.ts +4 -4
  12. package/dist/builder.d.ts.map +1 -1
  13. package/dist/builder.js +18 -16
  14. package/dist/builder.js.map +1 -1
  15. package/dist/cli.js +5 -5
  16. package/dist/cli.js.map +1 -1
  17. package/dist/commands/codegen.d.ts.map +1 -1
  18. package/dist/commands/codegen.js +12 -56
  19. package/dist/commands/codegen.js.map +1 -1
  20. package/dist/commands/ts-compile.d.ts +23 -0
  21. package/dist/commands/ts-compile.d.ts.map +1 -0
  22. package/dist/commands/ts-compile.js +693 -0
  23. package/dist/commands/ts-compile.js.map +1 -0
  24. package/dist/commands/ts-extract.d.ts +55 -7
  25. package/dist/commands/ts-extract.d.ts.map +1 -1
  26. package/dist/commands/ts-extract.js +177 -64
  27. package/dist/commands/ts-extract.js.map +1 -1
  28. package/dist/generated/contract.d.ts.map +1 -1
  29. package/dist/generated/contract.js +2 -2
  30. package/dist/generated/contract.js.map +1 -1
  31. package/dist/generated/program.js +4 -4
  32. package/dist/generated/program.js.map +1 -1
  33. package/dist/generator/core.d.ts +11 -1
  34. package/dist/generator/core.d.ts.map +1 -1
  35. package/dist/generator/core.js +5 -4
  36. package/dist/generator/core.js.map +1 -1
  37. package/dist/generator/emit-php.d.ts +0 -17
  38. package/dist/generator/emit-php.d.ts.map +1 -1
  39. package/dist/generator/emit-php.js +25 -1
  40. package/dist/generator/emit-php.js.map +1 -1
  41. package/dist/generator/emit-python.d.ts +0 -7
  42. package/dist/generator/emit-python.d.ts.map +1 -1
  43. package/dist/generator/emit-python.js +34 -1
  44. package/dist/generator/emit-python.js.map +1 -1
  45. package/dist/generator/emit-straightline-typed-typescript.js +1 -1
  46. package/dist/generator/emit-straightline-typed-typescript.js.map +1 -1
  47. package/dist/generator/emit-typed-native-go.d.ts +1 -1
  48. package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
  49. package/dist/generator/emit-typed-native-go.js +122 -112
  50. package/dist/generator/emit-typed-native-go.js.map +1 -1
  51. package/dist/generator/emit-typed-native-rust.d.ts +3 -2
  52. package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
  53. package/dist/generator/emit-typed-native-rust.js +61 -125
  54. package/dist/generator/emit-typed-native-rust.js.map +1 -1
  55. package/dist/generator/emit-typescript-native.js +1 -1
  56. package/dist/generator/emit-typescript-native.js.map +1 -1
  57. package/dist/generator/emit-typescript.js +1 -1
  58. package/dist/generator/emit-typescript.js.map +1 -1
  59. package/dist/generator/typed.d.ts +5 -1
  60. package/dist/generator/typed.d.ts.map +1 -1
  61. package/dist/generator/typed.js +40 -9
  62. package/dist/generator/typed.js.map +1 -1
  63. package/dist/guard.d.ts +11 -0
  64. package/dist/guard.d.ts.map +1 -1
  65. package/dist/guard.js +35 -8
  66. package/dist/guard.js.map +1 -1
  67. package/dist/index.d.ts +20 -57
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +25 -101
  70. package/dist/index.js.map +1 -1
  71. package/dist/lowering.d.ts +251 -0
  72. package/dist/lowering.d.ts.map +1 -0
  73. package/dist/lowering.js +682 -0
  74. package/dist/lowering.js.map +1 -0
  75. package/dist/provenance.js +4 -4
  76. package/dist/provenance.js.map +1 -1
  77. package/dist/runtime.d.ts +52 -0
  78. package/dist/runtime.d.ts.map +1 -0
  79. package/dist/runtime.js +77 -0
  80. package/dist/runtime.js.map +1 -0
  81. package/dist/spec-versions.d.ts +25 -0
  82. package/dist/spec-versions.d.ts.map +1 -0
  83. package/dist/spec-versions.js +26 -0
  84. package/dist/spec-versions.js.map +1 -0
  85. package/dist/type-gate.d.ts +12 -0
  86. package/dist/type-gate.d.ts.map +1 -1
  87. package/dist/type-gate.js +79 -3
  88. package/dist/type-gate.js.map +1 -1
  89. package/package.json +5 -1
  90. package/dist/bind.d.ts +0 -88
  91. package/dist/bind.d.ts.map +0 -1
  92. package/dist/bind.js +0 -155
  93. package/dist/bind.js.map +0 -1
  94. package/dist/lower.d.ts +0 -35
  95. package/dist/lower.d.ts.map +0 -1
  96. package/dist/lower.js +0 -118
  97. package/dist/lower.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { GeneratorFailure } from "./core.js";
2
- import { isControlGate, nodeWirePassthrough } from "../behavior.js";
2
+ import { isControlGate, mapNodeElemIsOpaqueWire, nodeWirePassthrough } from "../behavior.js";
3
3
  import { rustStraightlineInternals } from "./emit-shared-rust.js";
4
4
  import { rustTypedInternals } from "./emit-shared-rust-typed.js";
5
5
  import { buildTypePlan, deriveTypeRef, findDecl, guardedMapIntoIsCoverable, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
@@ -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
- return { expr: `in_.${rustFieldName(head)}`, ref, own: rustOwn(false, ownArrays) };
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: `in_.${rustFieldName(e.path[0])}.clone()`, optArr: inputPortIsOptional(schema) };
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
  }
@@ -1254,8 +1254,12 @@ function coveredMapNode(n, bodyIds, comp) {
1254
1254
  // holds `node.outType = mapElem`, the PRE-array-wrap element; the emitter synthesizes the produced
1255
1255
  // `[]element`). A map WITHOUT outType is uncovered. (Legacy hand-built IR that already carries the
1256
1256
  // `{arr:element}` produced form is ALSO accepted — mapNodeElemRef normalizes both to the element.)
1257
+ // bc#164: an OPAQUE ELEMENT (`outType:"value"` on an output-passthrough map — mapNodeElemIsOpaqueWire,
1258
+ // the shared rule) IS covered: each element wire is stored AS-IS in the produced list (no de-box, no
1259
+ // per-op re-box), exactly as the componentRef path treats a passthrough result. Any other non-compound
1260
+ // element type stays uncovered (loud), as before.
1257
1261
  const outT = n.outType;
1258
- if (outT === undefined || typeof outT !== "object")
1262
+ if (outT === undefined || (typeof outT !== "object" && !mapNodeElemIsOpaqueWire(n)))
1259
1263
  return false;
1260
1264
  const overE = classifyExpr(m.over);
1261
1265
  if (overE.kind !== "ref")
@@ -1471,38 +1475,6 @@ function inputScalarKind(schema) {
1471
1475
  return undefined;
1472
1476
  }
1473
1477
  }
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
1478
  /** A ref resolver for native lowering: given a ref head + remaining field path, return a native scalar
1507
1479
  * Rust expression (typed input field / prior-node typed struct scalar / element binding field), or null
1508
1480
  * when the ref does not resolve to a REQUIRED (non-opt) native scalar (then the caller falls back to the
@@ -1570,57 +1542,10 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
1570
1542
  };
1571
1543
  const outRef = comp.outputType !== undefined ? deriveTypeRef(comp.outputType, plan) : undefined;
1572
1544
  const outTy = outRef ? renderTypeRef(outRef) : "Value";
1573
- // Does any expression read an input param? If not, `in_` is unused — bind `_in_` to stay clippy-clean.
1574
- // #108: this must recurse ALL expression operators (cond if/then/else, map when + ports, arith/compare/…),
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_";
1545
+ // #192: the entry takes POSITIONAL params (one per input port; box removed). An unused param is allowed
1546
+ // by the module banner's `unused_variables` (added below) — no per-param `_` prefix / usage walk needed.
1622
1547
  const lines = [];
1623
- lines.push(`// run_native_raw_struct_${fn} — the STRUCT-RETURNING combined read (bc#77/#87/#94): the fully`);
1548
+ lines.push(`// ${rustFieldName(comp.name)} — the STRUCT-RETURNING combined read (bc#77/#87/#94): the fully`);
1624
1549
  lines.push(`// de-plumbed CONCRETE path. At each covered node's execution point it calls the op-agnostic leaf`);
1625
1550
  lines.push(`// TRANSPORT symbol DIRECTLY (the node's port fields spread — no per-node handler indirection) and`);
1626
1551
  lines.push(`// de-boxes the returned wire INLINE (match wire.as_*() { … } fully unrolled — no decode helper) into`);
@@ -1636,8 +1561,12 @@ function emitNativeRawRunner(comp, plan, ap, leaf) {
1636
1561
  // so the runner is itself `async fn` and returns a future the (already-async) consumer awaits. Sync
1637
1562
  // default emits `pub fn` exactly as before (byte-identical).
1638
1563
  const fnKw = isAsync ? "pub async fn" : "pub fn";
1639
- lines.push(`${fnKw} run_native_raw_struct_${fn}(`);
1640
- lines.push(` ${inParam}: ${inStructName(comp.name)},`);
1564
+ // #192: 1:1 map of the authored method — the entry is the exported fn `<method>` (rustFieldName; no
1565
+ // `run_native_raw_struct_` prefix) taking POSITIONAL params (one per input port; `In_<comp>` box removed).
1566
+ lines.push(`${fnKw} ${rustFieldName(comp.name)}(`);
1567
+ for (const p of Object.keys(comp.inputPorts ?? {})) {
1568
+ lines.push(` ${rustFieldName(p)}: ${inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)},`);
1569
+ }
1641
1570
  lines.push(`) -> Result<${outTy}, BehaviorError> {`);
1642
1571
  for (const k of order.keys()) {
1643
1572
  const nd = comp.body[order[k]];
@@ -2405,9 +2334,9 @@ function valueLeafProduced(expr, ref, expected) {
2405
2334
  // ── struct dispatch surface (STRUCT-only — no Value bind, no serializer) ─────────────────
2406
2335
  function emitStructSurface(native) {
2407
2336
  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
- // driven via run_native_raw_struct_<comp>(in_) -> Result<T, BehaviorError>: a STRUCT return (the consumer
2410
- // builds the CONCRETE InNR_<comp> input + supplies the op-agnostic leaf transport symbols the runner calls).
2337
+ return `// COMPONENT_NAMES_NATIVE_RAW — covered reads exposed on the combined struct-native path. Each is a
2338
+ // 1:1 entry <method>(<positional params>) -> Result<T, BehaviorError>: a STRUCT return (the consumer calls
2339
+ // it with the authored args + supplies the op-agnostic leaf transport symbols the entry calls).
2411
2340
  // See INTEGRATION.md §6.
2412
2341
  pub const COMPONENT_NAMES_NATIVE_RAW: [&str; ${names.length}] = [${names.join(", ")}];`;
2413
2342
  }
@@ -2492,7 +2421,6 @@ ${emitStructSurface([])}
2492
2421
  // #108: reset the native-expr helper-usage accumulator (set by the cond/guard compiler).
2493
2422
  rustExprUsed.helpers = false;
2494
2423
  const leaf = ctx.leafTransport;
2495
- const inStructs = [];
2496
2424
  const elemMaterializers = [];
2497
2425
  // every covered node returns a WireValue the inline de-box classifies — the wire seam (probe enums +
2498
2426
  // WireValue/WireRow/WireList traits) is emitted once whenever any handler node exists.
@@ -2512,7 +2440,7 @@ ${emitStructSurface([])}
2512
2440
  typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
2513
2441
  // #183: a covered node's ports cross the transport boundary as ONE op-agnostic `WireRow` payload built
2514
2442
  // inline at the call site — there are NO per-node ports structs on the covered plane or the shared crate.
2515
- inStructs.push(emitInStruct(c, plan));
2443
+ // #192: no `InNR_<comp>` input box — the entry takes positional params.
2516
2444
  const mm = emitMapElemMaterializers(c, typedNodes, plan);
2517
2445
  if (mm)
2518
2446
  elemMaterializers.push(mm);
@@ -2553,7 +2481,7 @@ ${emitStructSurface([])}
2553
2481
  // the wire seam is emitted LOCALLY only when NOT cross-package (else it lives in the shared module).
2554
2482
  const emitsWireTypes = anyWire && !crossPackage;
2555
2483
  // (nonNative.length === 0 is guaranteed here — the fail-closed guard above threw otherwise.)
2556
- const banner = `#![allow(dead_code, unused_imports, non_snake_case)]
2484
+ const banner = `#![allow(dead_code, unused_imports, unused_variables, non_snake_case)]
2557
2485
  // GENERATED by behavior-contracts (bc#90, rust-typed-native — the RUNTIME-FREE read de-box; STRUCT-ONLY,
2558
2486
  // FULLY-NATIVE). A covered read is a strictly-sequential typed componentRef chain (point reads +
2559
2487
  // relationKind:single children), emitted ONLY as a STRUCT-returning runner that calls the op-agnostic leaf
@@ -2567,8 +2495,9 @@ ${emitStructSurface([])}
2567
2495
  // codes, byte-equal to run_behavior). INLINE sequential (no plan driver) so a relation child reads the
2568
2496
  // parent's REAL struct result via direct field access and the child-present decision is made from the real
2569
2497
  // parent value — relationSingle / connection converge with run_behavior (fixes #323/#74). The exposed API
2570
- // is run_native_raw_struct_<comp>(in_) over the CONCRETE InNR_<comp> input struct; the consumer supplies
2571
- // the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport import). This module
2498
+ // is the 1:1 entry <method>(<positional params>) -> Result<T, BehaviorError> (the InNR_<comp> box removed);
2499
+ // the consumer supplies the leaf transport symbols (default in-scope names leaf_<comp>, or a leafTransport
2500
+ // import). This module
2572
2501
  // is FULLY NATIVE: a naive grep for boxing primitives OR for the bc-runtime crate finds nothing, by design.
2573
2502
  use std::cell::RefCell;`;
2574
2503
  const sections = [
@@ -2588,7 +2517,7 @@ use std::cell::RefCell;`;
2588
2517
  rustExprUsed.helpers
2589
2518
  ? `// #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
2519
  : undefined,
2591
- `// CONCRETE per-component input structs (fields = inputPorts).\n${inStructs.join("\n\n")}`,
2520
+ // #192: no per-component `InNR_<comp>` input structs — the entry takes positional params (box removed).
2592
2521
  emitsWireTypes
2593
2522
  ? `// 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
2523
  : undefined,
@@ -2750,9 +2679,14 @@ ${echoBlock} Ok(value_to_wire(&ok.unwrap_or(Value::Null)))
2750
2679
  // bc#97: an async runner returns a Future — drive it to completion with the std-only block-on
2751
2680
  // (bc_block_on) so observe_native_raw keeps its SYNC external signature (the harness is unchanged).
2752
2681
  // The scripted async node_* return ready values, so the future needs no real executor / no runtime.
2753
- const runnerCall = `super::run_native_raw_struct_${sanitize(c.name)}(in_)`;
2682
+ // #192: decode the generic test input into the entry's POSITIONAL args (test glue), then call the
2683
+ // 1:1 entry positionally (box removed). A no-input entry is called with no args (no decoder).
2684
+ const args = Object.keys(c.inputPorts ?? {}).map((p) => rustFieldName(p));
2685
+ const runnerCall = `super::${rustFieldName(c.name)}(${args.join(", ")})`;
2754
2686
  const driven = asyncPlans.get(c.name).runnerIsAsync ? `bc_block_on(${runnerCall})` : runnerCall;
2755
- return ` ${rustStrLit(c.name)} => {\n let in_ = decode_${inStructName(c.name)}(input).map_err(to_rt_err)?;\n let tv = ${driven}.map_err(to_rt_err)?;\n Ok(${ser})\n }`;
2687
+ const decode = args.length === 0 ? "" : ` let (${args.join(", ")},) = decode_${sanitize(c.name)}(input).map_err(to_rt_err)?;\n`;
2688
+ const unusedInput = args.length === 0 ? " let _ = input;\n" : "";
2689
+ return ` ${rustStrLit(c.name)} => {\n${decode}${unusedInput} let tv = ${driven}.map_err(to_rt_err)?;\n Ok(${ser})\n }`;
2756
2690
  })
2757
2691
  .join("\n");
2758
2692
  // the scripted-outcome source is a MODULE-LEVEL static (Mutex<Option<HashMap>> + AtomicUsize), NOT a
@@ -2816,7 +2750,7 @@ fn next_scripted(component: &str) -> Option<(bool, String, Option<Value>, String
2816
2750
  // static and return the scripted wire (exactly the shape the removed per-node trait method returned). The
2817
2751
  // consumer never uses this (it keeps the model native + supplies its own transport fns over its own wire
2818
2752
  // 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 run_native_raw_struct_* + the CONCRETE
2753
+ // run_behavior. A submodule of the covered module (reads its pub entry fns + the CONCRETE
2820
2754
  // structs — incl. the LOCAL BehaviorError — via super::*, and its \`leaf_<comp>\` fns resolve the covered
2821
2755
  // module's transport calls). bc#90 / runtime-free: the covered module's BehaviorError is LOCAL, so this
2822
2756
  // test-glue companion refers to it via super::* (as \`BehaviorError\`) and refers to the bc-runtime failure
@@ -2910,26 +2844,28 @@ ${arms}
2910
2844
  }
2911
2845
  `;
2912
2846
  }
2913
- /** emitInDecoder — a TEST-glue decoder `decode_InNR_<comp>(input) -> Result<InNR_<comp>, BehaviorError>`.
2914
- * Reads each declared input port from the generic &[(String,Value)] into the concrete field (scalar →
2915
- * typed read; Value-typed → the raw Value clone). A missing key leaves Default (every covered input is
2916
- * required + supplied by the corpus). Lives ONLY in the observe companion. */
2847
+ /** emitInDecoder — a TEST-glue decoder `decode_<comp>(input) -> Result<(<positional args...>,), BehaviorError>`.
2848
+ * Reads each declared input port from the generic &[(String,Value)] into a local (= the entry's positional
2849
+ * param; scalar → typed read; value-typed → the raw wire clone), returned as a tuple the observe companion
2850
+ * destructures and passes positionally to the 1:1 entry (#192, box removed). A missing key leaves Default
2851
+ * (every covered input is required + supplied by the corpus). Lives ONLY in the observe companion. */
2917
2852
  function emitInDecoder(comp, plan) {
2918
- const name = inStructName(comp.name);
2919
2853
  const ports = Object.keys(comp.inputPorts ?? {});
2854
+ if (ports.length === 0 || comp.inputPorts === undefined)
2855
+ return ""; // no input → observe calls the entry with no args.
2856
+ const args = ports.map((p) => rustFieldName(p));
2857
+ const types = ports.map((p) => inputPortRustType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`));
2920
2858
  const lines = [];
2921
- lines.push(`fn decode_${name}(input: &[(String, Value)]) -> Result<${name}, BehaviorError> {`);
2922
- lines.push(` let mut in_ = ${name}::default();`);
2923
- if (ports.length === 0 || comp.inputPorts === undefined) {
2924
- lines.push(` let _ = input;`);
2925
- lines.push(` Ok(in_)`);
2926
- lines.push(`}`);
2927
- return lines.join("\n");
2928
- }
2859
+ // trailing comma → always a tuple (never a parenthesized single value).
2860
+ lines.push(`fn decode_${sanitize(comp.name)}(input: &[(String, Value)]) -> Result<(${types.join(", ")},), BehaviorError> {`);
2861
+ // neutral init per port: a SCALAR `value` port renders as bare `WireValue` (no Default) — init it
2862
+ // with `WireValue::Null`, the SAME value-kind neutral the covered emitter uses for value cells (the
2863
+ // cellInit SSoT above). Every other port type (scalar, Vec<WireValue>, Option<…>) has a Default.
2864
+ ports.forEach((p, i) => lines.push(` let mut ${args[i]}: ${types[i]} = ${comp.inputPorts[p]?.type === "value" ? "WireValue::Null" : "Default::default()"};`));
2929
2865
  // an if/else-if chain (clippy-clean regardless of port count — a single-arm `match` trips single_match).
2930
2866
  lines.push(` for (k, v) in input {`);
2931
2867
  ports.forEach((p, i) => {
2932
- const field = rustFieldName(p);
2868
+ const field = args[i];
2933
2869
  const schema = comp.inputPorts[p];
2934
2870
  const scalar = inputScalarKind(schema);
2935
2871
  const et = schema.elemType;
@@ -2948,28 +2884,28 @@ function emitInDecoder(comp, plan) {
2948
2884
  lines.push(` let mut dec: Vec<${elemTy}> = Vec::with_capacity(a.len());`);
2949
2885
  lines.push(` for ev in a.iter() { dec.push(${mat}); }`);
2950
2886
  // #177 (A): an OPTIONAL array port field is `Option<Vec<E>>` (inputPortTypeRef opt), so wrap in Some.
2951
- lines.push(` in_.${field} = ${inputPortIsOptional(schema) ? "Some(dec)" : "dec"};`);
2887
+ lines.push(` ${field} = ${inputPortIsOptional(schema) ? "Some(dec)" : "dec"};`);
2952
2888
  lines.push(` }`);
2953
2889
  lines.push(` other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected array, got `)}, other.type_name())),`);
2954
2890
  lines.push(` }`);
2955
2891
  }
2956
2892
  else if (schema?.type === "value") {
2957
2893
  // bc#156: a scalar `value` port — the raw bound value as BC's opaque wire (value_to_wire).
2958
- lines.push(` in_.${field} = value_to_wire(v);`);
2894
+ lines.push(` ${field} = value_to_wire(v);`);
2959
2895
  }
2960
2896
  else if (schema?.type === "map" && et !== undefined) {
2961
2897
  // #108-map: decode the boxed Value::Obj into the native BTreeMap<String, V> (test glue — the input
2962
2898
  // map port carries a declared elemType). materializeExpr covers the map de-box (obj → BTreeMap).
2963
2899
  const mapRef = { kind: "map", value: deriveTypeRef(et, plan) };
2964
- lines.push(` in_.${field} = ${materializeExpr("v", mapRef, plan)};`);
2900
+ lines.push(` ${field} = ${materializeExpr("v", mapRef, plan)};`);
2965
2901
  }
2966
2902
  else if (inputPortIsOptional(schema)) {
2967
2903
  // #139: an OPTIONAL scalar port decodes into Option<T> via the inputPortTypeRef SSoT (a present key
2968
2904
  // materializes Some(v); an absent key never enters this block, leaving the Default None).
2969
- lines.push(` in_.${field} = ${materializeExpr("v", inputPortTypeRef(schema, plan), plan)};`);
2905
+ lines.push(` ${field} = ${materializeExpr("v", inputPortTypeRef(schema, plan), plan)};`);
2970
2906
  }
2971
2907
  else if (scalar === undefined) {
2972
- lines.push(` in_.${field} = v.clone();`);
2908
+ lines.push(` ${field} = v.clone();`);
2973
2909
  }
2974
2910
  else {
2975
2911
  const pat = scalar === "String" ? "Value::Str(sv)" : scalar === "i64" ? "Value::Int(sv)" : scalar === "f64" ? "Value::Float(sv)" : "Value::Bool(sv)";
@@ -2977,12 +2913,12 @@ function emitInDecoder(comp, plan) {
2977
2913
  const bind = scalar === "String" ? "sv.clone()" : "*sv";
2978
2914
  // bc#90 / runtime-free: build the module-LOCAL BehaviorError (TYPE_MISMATCH) via the local
2979
2915
  // marshal_type_error helper — decode_* returns the local error, bridged at the observe boundary.
2980
- lines.push(` match v { ${pat} => in_.${field} = ${bind}, other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected ${label}, got `)}, other.type_name())) }`);
2916
+ lines.push(` match v { ${pat} => ${field} = ${bind}, other => return Err(marshal_type_error(${rustStrLit(`decode input ${p}: expected ${label}, got `)}, other.type_name())) }`);
2981
2917
  }
2982
2918
  });
2983
2919
  lines.push(` }`);
2984
2920
  lines.push(` }`);
2985
- lines.push(` Ok(in_)`);
2921
+ lines.push(` Ok((${args.join(", ")},))`);
2986
2922
  lines.push(`}`);
2987
2923
  return lines.join("\n");
2988
2924
  }