behavior-contracts 0.11.8 → 0.11.10
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/dist/behavior.d.ts +20 -0
- package/dist/behavior.d.ts.map +1 -1
- package/dist/behavior.js +40 -4
- package/dist/behavior.js.map +1 -1
- package/dist/generator/async-plan.js +4 -3
- package/dist/generator/async-plan.js.map +1 -1
- package/dist/generator/emit-shared-go-typed.d.ts +0 -6
- package/dist/generator/emit-shared-go-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-go-typed.js +0 -116
- package/dist/generator/emit-shared-go-typed.js.map +1 -1
- package/dist/generator/emit-shared-rust-typed.d.ts +0 -3
- package/dist/generator/emit-shared-rust-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-rust-typed.js +0 -15
- package/dist/generator/emit-shared-rust-typed.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts +1 -12
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +15 -451
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts +1 -13
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +168 -510
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/index.d.ts +2 -2
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +2 -2
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/typed.d.ts +1 -25
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +0 -31
- package/dist/generator/typed.js.map +1 -1
- package/dist/lowering.d.ts.map +1 -1
- package/dist/lowering.js +10 -3
- package/dist/lowering.js.map +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/spec-versions.d.ts +1 -1
- package/dist/spec-versions.js +1 -1
- package/dist/spec-versions.js.map +1 -1
- package/dist/type-gate.d.ts +13 -1
- package/dist/type-gate.d.ts.map +1 -1
- package/dist/type-gate.js +29 -2
- package/dist/type-gate.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,7 @@ import { entryPortOrder, GeneratorFailure } from "./core.js";
|
|
|
2
2
|
import { isControlGate, mapNodeElemIsOpaqueWire, mapTransformExpr, nodeWirePassthrough } from "../behavior.js";
|
|
3
3
|
import { goStraightlineInternals } from "./emit-shared-go.js";
|
|
4
4
|
import { goTypedInternals } from "./emit-shared-go-typed.js";
|
|
5
|
-
import { buildTypePlan, deriveTypeRef, findDecl,
|
|
5
|
+
import { buildTypePlan, deriveTypeRef, findDecl, inputPortIsOptional, inputPortTypeRef } from "./typed.js";
|
|
6
6
|
import { concurrencyPlan, execPlan, analyzeSequentialOps, classifyExpr, buildComponentPlan, nodeNarrowedPaths, } from "./straightline.js";
|
|
7
7
|
import { NativeExprCompiler } from "./native-expr.js";
|
|
8
8
|
import { buildDeBoxPlan, buildWirePlan, notationOfRef } from "./emit-shared-debox.js";
|
|
@@ -118,7 +118,7 @@ func deMissingField(model, field, expected string) *BehaviorError {
|
|
|
118
118
|
}`;
|
|
119
119
|
}
|
|
120
120
|
const { sanitize, emitExpr } = goStraightlineInternals;
|
|
121
|
-
const { goFieldName, renderTypeRef, goScalar, serializeTyped, emitTypeDecls,
|
|
121
|
+
const { goFieldName, renderTypeRef, goScalar, serializeTyped, emitTypeDecls, emitTypedValue, checkOutputFieldType, } = goTypedInternals;
|
|
122
122
|
/** typed node-result local — MUST match goTypedInternals.typedLocal (`t_<id>`) so the reused
|
|
123
123
|
* emitTypedValue (output assembly via struct field access) reads the same locals. */
|
|
124
124
|
function typedLocal(nodeId) {
|
|
@@ -842,16 +842,13 @@ function coveredMapNode(n, bodyIds, comp) {
|
|
|
842
842
|
return false;
|
|
843
843
|
const m = n.map;
|
|
844
844
|
// #86 pt2: batched map...into. #93 shape 2/3: (non-)batched map...into / connection-collect. #108:
|
|
845
|
-
// a guarded map (`when`) IS covered when it has NO `into`. #177/#182: a
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
//
|
|
849
|
-
//
|
|
850
|
-
//
|
|
851
|
-
//
|
|
852
|
-
// byte-equal. The skip value below (goZero of the into row type) yields nil / connection-struct-zero.
|
|
853
|
-
if (m.when !== undefined && m.into !== undefined && !guardedMapIntoIsCoverable(n, comp))
|
|
854
|
-
return false;
|
|
845
|
+
// a guarded map (`when`) IS covered when it has NO `into`. #177/#182/#232: a `map...into` ALWAYS has a
|
|
846
|
+
// well-defined unproduced value for the into field — the into field is OPT (unproduced → nil, #177) OR
|
|
847
|
+
// relationKind:connection (unproduced → the empty connection {items:[],cursor:null}, #182). The type
|
|
848
|
+
// gate (`mapIntoHoldsUnproduced`, run for every component at the codegen entry) rejects anything else
|
|
849
|
+
// BEFORE any emitter sees it (#232), so the augmented list is homogeneous here by construction (kept
|
|
850
|
+
// element → present into, unproduced → the skip value), EXACTLY run_behavior's applyInto. The skip
|
|
851
|
+
// value below (goZero of the into row type) yields nil / connection-struct-zero.
|
|
855
852
|
if (m.relationKind !== undefined && m.relationKind !== "connection")
|
|
856
853
|
return false;
|
|
857
854
|
// A map node must carry an outType (its ELEMENT type per the recorder SoT — authoring.ts recordMap
|
|
@@ -1071,7 +1068,7 @@ function assertTypedCoverage(comp) {
|
|
|
1071
1068
|
* resolveLeafSymbol — the op-agnostic transport symbol a covered leaf (= catalog component) is called
|
|
1072
1069
|
* through at its execution point. A consumer-supplied override (`leafTransport.symbols[component]`) wins;
|
|
1073
1070
|
* else the in-package DEFAULT convention `Leaf_<sanitizedComponent>`. This is the ONE place leaf→symbol
|
|
1074
|
-
* resolution lives (SSoT) — the runner call sites
|
|
1071
|
+
* resolution lives (SSoT) — the runner call sites and the import block all
|
|
1075
1072
|
* read it. There is no per-node handler indirection: a leaf is ONE transport, not one method per node.
|
|
1076
1073
|
*/
|
|
1077
1074
|
function goLeafSel(leaf) {
|
|
@@ -1080,8 +1077,8 @@ function goLeafSel(leaf) {
|
|
|
1080
1077
|
/** leafSymbolBare — the UNQUALIFIED transport symbol name. Resolution order (#176): the SPEC-fixed
|
|
1081
1078
|
* `node.leafSymbol` (from `defineLeaf` meta.transport, baked per node) FIRST, then the CLI
|
|
1082
1079
|
* `--leaf-transport` override (`leaf.symbols[component]`), then the default `Leaf_<comp>`. The ONE source
|
|
1083
|
-
* for the name: call sites qualify it with the package selector (resolveLeafSymbol); the
|
|
1084
|
-
*
|
|
1080
|
+
* for the name: call sites qualify it with the package selector (resolveLeafSymbol); the consumer DEFINES
|
|
1081
|
+
* the fn under this bare name (a definition carries no selector). */
|
|
1085
1082
|
function leafSymbolBare(component, leaf, specSymbol) {
|
|
1086
1083
|
return specSymbol ?? leaf?.symbols[component] ?? `Leaf_${sanitize(component)}`;
|
|
1087
1084
|
}
|
|
@@ -1122,7 +1119,7 @@ function runnerName(compName) {
|
|
|
1122
1119
|
}
|
|
1123
1120
|
/** #192: the Go package name = the namespace (declaring class), lower-cased (`UserQueries` → `userqueries`);
|
|
1124
1121
|
* default `behaviors` when unset. Physical placement / namespace is set in ONE place (GenerateOptions.namespace).
|
|
1125
|
-
*
|
|
1122
|
+
* An in-package leaf transport (no --leaf-transport-import) MUST live in this package. */
|
|
1126
1123
|
function goPackageName(ns) {
|
|
1127
1124
|
if (ns === undefined)
|
|
1128
1125
|
return "behaviors";
|
|
@@ -1352,115 +1349,6 @@ function inputPortGoType(schema, plan, where = "input port") {
|
|
|
1352
1349
|
throw new GeneratorFailure("UNSUPPORTED_NODE_STRAIGHTLINE", `go typed-native (runtime-free): ${where} is OPTIONAL (declared {opt:…}) but its inner type ${JSON.stringify(schema?.type)} has no native Go lowering, so "absent" has no native representation. Declare an elemType for an array/map, or use a natively-lowerable scalar.`);
|
|
1353
1350
|
return `${PKG}.Value`;
|
|
1354
1351
|
}
|
|
1355
|
-
/** The scalar kind an input port declares, or undefined if it is not a native scalar. */
|
|
1356
|
-
function inputScalarKind(schema) {
|
|
1357
|
-
switch (schema?.type) {
|
|
1358
|
-
case "string":
|
|
1359
|
-
case "literal": // a `"literal"` union is a constrained string (see inputPortGoType).
|
|
1360
|
-
return "string";
|
|
1361
|
-
case "int":
|
|
1362
|
-
return "int64";
|
|
1363
|
-
case "float":
|
|
1364
|
-
case "number": // a `"number"` port is the FLOAT channel (run_behavior: number → float / float64).
|
|
1365
|
-
return "float64";
|
|
1366
|
-
case "bool":
|
|
1367
|
-
return "bool";
|
|
1368
|
-
default:
|
|
1369
|
-
return undefined;
|
|
1370
|
-
}
|
|
1371
|
-
}
|
|
1372
|
-
/**
|
|
1373
|
-
* emitInDecoder — the TEST-glue decoder `decode_<comp>(input *Obj) (<positional args...>, err error)`. It reads
|
|
1374
|
-
* each declared input port from the generic *Obj into the entry's POSITIONAL arg (named return; scalar →
|
|
1375
|
-
* typed read on the SDK/wire Value; value-typed → the raw wire). Lives ONLY in the observe companion (test
|
|
1376
|
-
* harness), never in the covered module — the entry takes positional params (#192, box removed) and the
|
|
1377
|
-
* observe passes these decoded args positionally. A missing key leaves the zero value (every covered input
|
|
1378
|
-
* is required + always supplied by the corpus); a present-but-wrong-scalar is a fail-closed decode error.
|
|
1379
|
-
*/
|
|
1380
|
-
function emitInDecoder(comp, plan, declared) {
|
|
1381
|
-
const ports = entryPortOrder(comp, declared);
|
|
1382
|
-
if (ports.length === 0 || comp.inputPorts === undefined)
|
|
1383
|
-
return ""; // no input → observe calls the entry with no args.
|
|
1384
|
-
// #192: decode the generic *Obj test input into the entry's POSITIONAL args (named returns = the params,
|
|
1385
|
-
// in inputPorts order; a decode mismatch sets `err` and returns). The `In_<comp>` box is gone — this
|
|
1386
|
-
// test-glue decoder produces the values the observe companion passes positionally to the entry.
|
|
1387
|
-
const rets = ports
|
|
1388
|
-
.map((p) => `${goParamName(p)} ${inputPortGoType(comp.inputPorts[p], plan, `input port '${p}' of component '${comp.name}'`)}`)
|
|
1389
|
-
.join(", ");
|
|
1390
|
-
const lines = [];
|
|
1391
|
-
lines.push(`func decode_${sanitize(comp.name)}(input *${PKG}.Obj) (${rets}, err error) {`);
|
|
1392
|
-
lines.push(`\tif input == nil {`);
|
|
1393
|
-
lines.push(`\t\treturn`);
|
|
1394
|
-
lines.push(`\t}`);
|
|
1395
|
-
for (const p of ports) {
|
|
1396
|
-
const arg = goParamName(p);
|
|
1397
|
-
const schema = comp.inputPorts[p];
|
|
1398
|
-
const scalar = inputScalarKind(schema);
|
|
1399
|
-
const et = schema.elemType;
|
|
1400
|
-
lines.push(`\tif v, ok := input.Get(${JSON.stringify(p)}); ok {`);
|
|
1401
|
-
if ((schema?.type === "array" || schema?.type === "arr") && et !== undefined) {
|
|
1402
|
-
// #108: decode the boxed Value array into the native []ElemT (test glue — materialize each element
|
|
1403
|
-
// via the typed materializer; a non-array or non-conforming element is a fail-closed decode error).
|
|
1404
|
-
// bc#156: a `value[]` element is BC's opaque wire — decode it with the BC-owned valueToWire (the SAME
|
|
1405
|
-
// wire the output de-box uses), NOT the typed materializer (WireValue is not a de-box target).
|
|
1406
|
-
const elemRef = deriveTypeRef(et, plan);
|
|
1407
|
-
const elemGo = renderTypeRef(elemRef);
|
|
1408
|
-
const mat = elemRef.kind === "value" ? "valueToWire(ev)" : goTypedInternals.materializeExpr("ev", elemRef, plan);
|
|
1409
|
-
lines.push(`\t\tarr, isArr := v.([]${PKG}.Value)`);
|
|
1410
|
-
lines.push(`\t\tif !isArr {`);
|
|
1411
|
-
lines.push(`\t\t\terr = ${PKG}.NewExprFailure("TYPE_MISMATCH", "input ${p}: expected array, got "+${PKG}.TypeName(v))`);
|
|
1412
|
-
lines.push(`\t\t\treturn`);
|
|
1413
|
-
lines.push(`\t\t}`);
|
|
1414
|
-
lines.push(`\t\tdec := make([]${elemGo}, 0, len(arr))`);
|
|
1415
|
-
lines.push(`\t\tfor _, ev := range arr {`);
|
|
1416
|
-
lines.push(`\t\t\tdec = append(dec, ${mat})`);
|
|
1417
|
-
lines.push(`\t\t}`);
|
|
1418
|
-
// #177 (A): an OPTIONAL array port param is `*[]E` (inputPortTypeRef opt → pointer), so take its address.
|
|
1419
|
-
lines.push(`\t\t${arg} = ${inputPortIsOptional(schema) ? "&dec" : "dec"}`);
|
|
1420
|
-
lines.push(`\t}`);
|
|
1421
|
-
continue;
|
|
1422
|
-
}
|
|
1423
|
-
if (schema?.type === "value") {
|
|
1424
|
-
lines.push(`\t\t${arg} = valueToWire(v)`);
|
|
1425
|
-
lines.push(`\t}`);
|
|
1426
|
-
continue;
|
|
1427
|
-
}
|
|
1428
|
-
if (schema?.type === "map" && et !== undefined) {
|
|
1429
|
-
const valRef = deriveTypeRef(et, plan);
|
|
1430
|
-
// #209: a map port whose VALUE type is the opaque `value` decodes with the BC-owned valueToWire —
|
|
1431
|
-
// the SAME rule the `value[]` array branch above and the scalar `value` branch below already apply
|
|
1432
|
-
// (`value` is input-only, so the typed materializer stays fail-closed for it).
|
|
1433
|
-
if (valRef.kind === "value") {
|
|
1434
|
-
lines.push(`\t\tmv := make(map[string]WireValue)`);
|
|
1435
|
-
lines.push(`\t\tif mo, isObj := v.(*${PKG}.Obj); isObj && mo != nil {`);
|
|
1436
|
-
lines.push(`\t\t\tfor _, mk := range mo.Keys {`);
|
|
1437
|
-
lines.push(`\t\t\t\tmvv, _ := mo.Get(mk)`);
|
|
1438
|
-
lines.push(`\t\t\t\tmv[mk] = valueToWire(mvv)`);
|
|
1439
|
-
lines.push(`\t\t\t}`);
|
|
1440
|
-
lines.push(`\t\t}`);
|
|
1441
|
-
lines.push(`\t\t${arg} = mv`);
|
|
1442
|
-
lines.push(`\t}`);
|
|
1443
|
-
continue;
|
|
1444
|
-
}
|
|
1445
|
-
const mapRef = { kind: "map", value: valRef };
|
|
1446
|
-
lines.push(`\t\t${arg} = ${goTypedInternals.materializeExpr("v", mapRef, plan)}`);
|
|
1447
|
-
lines.push(`\t}`);
|
|
1448
|
-
continue;
|
|
1449
|
-
}
|
|
1450
|
-
if (scalar === undefined) {
|
|
1451
|
-
lines.push(`\t\t${arg} = v`);
|
|
1452
|
-
}
|
|
1453
|
-
else {
|
|
1454
|
-
// #139: materialize via the inputPortTypeRef SSoT so an OPTIONAL scalar reads as *T (present → &v);
|
|
1455
|
-
// an absent optional never enters this block (Get !ok), leaving the param nil (not a required zero).
|
|
1456
|
-
lines.push(`\t\t${arg} = ${goTypedInternals.materializeExpr("v", inputPortTypeRef(schema, plan), plan)}`);
|
|
1457
|
-
}
|
|
1458
|
-
lines.push(`\t}`);
|
|
1459
|
-
}
|
|
1460
|
-
lines.push(`\treturn`);
|
|
1461
|
-
lines.push(`}`);
|
|
1462
|
-
return lines.join("\n");
|
|
1463
|
-
}
|
|
1464
1352
|
/** A ref resolver for native lowering: given a ref head + remaining field path, return a native scalar
|
|
1465
1353
|
* Go expression (typed input field / prior-node typed struct scalar / element binding field), or null
|
|
1466
1354
|
* when the ref does not resolve to a REQUIRED (non-opt) native scalar (then the caller falls back to
|
|
@@ -2819,9 +2707,8 @@ func bcExpr_strGe(a, b string) bool { return bcExpr_cmpCP(a, b) >= 0 }`;
|
|
|
2819
2707
|
* `<Method>(<positional params>) (T, error)`) ARE the exposed API. The consumer calls the entry directly
|
|
2820
2708
|
* (it returns the typed model — NO Value serialization on the read hot path, matching how graphddb reads:
|
|
2821
2709
|
* a model, never a boxed Value). There is deliberately NO Value dispatch map — that would require a Value
|
|
2822
|
-
* serializer (the boxing residue bc#77 eliminates)
|
|
2823
|
-
*
|
|
2824
|
-
* module so the covered module stays literal whole-file zero. */
|
|
2710
|
+
* serializer (the boxing residue bc#77 eliminates), which is what keeps the covered module literal
|
|
2711
|
+
* whole-file zero. */
|
|
2825
2712
|
function emitStructSurface(native) {
|
|
2826
2713
|
return `// ComponentNamesNativeRaw — covered reads exposed on the combined native path (declaration order).
|
|
2827
2714
|
// Each is a 1:1 entry <Method>(<positional params>) -> (T, error): a native return; the consumer keeps the
|
|
@@ -3027,329 +2914,6 @@ ${emitProbeWireTypes({ row: "WireRow", list: "WireList" })}
|
|
|
3027
2914
|
${emitGoWireTypes()}
|
|
3028
2915
|
`;
|
|
3029
2916
|
}
|
|
3030
|
-
/**
|
|
3031
|
-
* goTypedNativeObserve — the TEST-ONLY observe companion (a SEPARATE file in the SAME package as the
|
|
3032
|
-
* covered module). It carries the typed->Value serializers (ser_*) + the SCRIPTED analog of the consumer's
|
|
3033
|
-
* leaf transport symbols: free Leaf_<comp> funcs (same package, so the covered module's transport calls
|
|
3034
|
-
* resolve) that drain a shared package-level scripted queue, + an ObserveNativeRaw dispatch that fills the
|
|
3035
|
-
* queue from the per-case spec, drives the module-private struct runner, and serializes its result to a
|
|
3036
|
-
* canonical Value for the equivalence pin. This lives OUTSIDE the covered module so the module stays literal
|
|
3037
|
-
* whole-file zero (the ser_* NewObj is test glue, never on the consumer's read hot path). Emitted only for
|
|
3038
|
-
* the fully-covered case (the equivalence harness); production consumers never use it.
|
|
3039
|
-
*/
|
|
3040
|
-
export function goTypedNativeObserve(ir, runtimeImport, leaf, namespace, declared) {
|
|
3041
|
-
const components = ir.components;
|
|
3042
|
-
const native = components.filter(isNativeRaw);
|
|
3043
|
-
const plan = buildTypePlan(ir);
|
|
3044
|
-
const serializers = emitSerializers(plan);
|
|
3045
|
-
const marshallers = goTypedInternals.emitMarshallers(plan);
|
|
3046
|
-
const mustHelpers = emitMustHelpers(plan);
|
|
3047
|
-
// arr/opt node materialize helpers (mustArr_*/mustOpt_*) for the concrete-row decode of a node whose
|
|
3048
|
-
// whole outType is a bare arr/opt (materializeExpr emits mustArr_/mustOpt_ for those).
|
|
3049
|
-
const arrOptHelpers = goTypedInternals.emitArrOptNodeHelpers({ ir }, plan);
|
|
3050
|
-
const arms = native
|
|
3051
|
-
.map((c) => {
|
|
3052
|
-
const outRef = c.outputType !== undefined ? deriveTypeRef(c.outputType, plan) : undefined;
|
|
3053
|
-
const ser = outRef ? serializeTyped("tv", outRef, plan) : "tv";
|
|
3054
|
-
// #192: decode the generic *Obj test input into the entry's POSITIONAL args (test glue — ONE decode at
|
|
3055
|
-
// the top; a REQUIRED declared input absent is a fail-closed decode error here, never on the entry path),
|
|
3056
|
-
// then call the 1:1 entry positionally. A no-input entry is called with no args (no decoder).
|
|
3057
|
-
const args = entryPortOrder(c, declared).map((p) => goParamName(p));
|
|
3058
|
-
const decode = args.length === 0
|
|
3059
|
-
? ""
|
|
3060
|
-
: `\t\t${args.join(", ")}, ierr := decode_${sanitize(c.name)}(input)\n\t\tif ierr != nil {\n\t\t\treturn nil, ierr\n\t\t}\n`;
|
|
3061
|
-
const unusedInput = args.length === 0 ? "\t\t_ = input\n" : "";
|
|
3062
|
-
return `\tif name == ${JSON.stringify(c.name)} {\n${decode}${unusedInput}\t\ttv, err := ${runnerName(c.name)}(${args.join(", ")})\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn ${ser}, nil\n\t}`;
|
|
3063
|
-
})
|
|
3064
|
-
.join("\n");
|
|
3065
|
-
// input decoders (TEST glue): generic *Obj -> concrete In_<comp>. Scalar fields read the typed value
|
|
3066
|
-
// (a `.(T)` here is on the SDK/wire Value in the OBSERVE companion, never in the covered module).
|
|
3067
|
-
const inDecoders = native.map((c) => emitInDecoder(c, plan, declared)).join("\n\n");
|
|
3068
|
-
// every covered node returns a WireValue the inline de-box classifies — so the scripted wire adapter is
|
|
3069
|
-
// needed whenever any component has a handler node.
|
|
3070
|
-
const anyDeBox = native.some((c) => c.body.some((n) => !("cond" in n)));
|
|
3071
|
-
// scripted wire adapter (TEST glue): wraps a scripted bc Value as the CONCRETE WireValue / WireRow /
|
|
3072
|
-
// WireList (the in-package default seam types the covered module references) and classifies each datum's
|
|
3073
|
-
// native type into a DynamoDB-flavored wire tag (S/N/BOOL/L/M/NULL). A real consumer supplies its OWN
|
|
3074
|
-
// concrete WireValue over its AttributeValue payload; this exists only so the harness drives the
|
|
3075
|
-
// generated inline de-box from the same scripted vectors run_behavior uses — so actualWireType observed
|
|
3076
|
-
// in a mismatch is the PRODUCER tag (e.g. "N"), not the collapsed native type.
|
|
3077
|
-
const wireAdapter = anyDeBox
|
|
3078
|
-
? `// valueToWire (TEST glue): builds the covered module's BC-OWNED concrete WireValue from a scripted bc
|
|
3079
|
-
// Value — the harness analog of the consumer's real transport (which builds WireValue as it reads the
|
|
3080
|
-
// producer). Numbers ride NATIVE (WireInt / WireFloat), so the scripted value reaches the de-box as the
|
|
3081
|
-
// same int64 / float64 run_behavior holds. The wire tags + classification live ONCE in the covered module's
|
|
3082
|
-
// WireValue (probeStringOf etc.), so this only CONSTRUCTS.
|
|
3083
|
-
func valueToWire(v ${PKG}.Value) WireValue {
|
|
3084
|
-
switch t := v.(type) {
|
|
3085
|
-
case nil:
|
|
3086
|
-
return WireNull()
|
|
3087
|
-
case bool:
|
|
3088
|
-
return WireBool(t)
|
|
3089
|
-
case int64:
|
|
3090
|
-
return WireInt(t)
|
|
3091
|
-
case float64:
|
|
3092
|
-
return WireFloat(t)
|
|
3093
|
-
case string:
|
|
3094
|
-
return WireStr(t)
|
|
3095
|
-
case []${PKG}.Value:
|
|
3096
|
-
items := make([]WireValue, len(t))
|
|
3097
|
-
for i := range t {
|
|
3098
|
-
items[i] = valueToWire(t[i])
|
|
3099
|
-
}
|
|
3100
|
-
return WireListOf(items)
|
|
3101
|
-
case *${PKG}.Obj:
|
|
3102
|
-
fields := make([]WireField, len(t.Keys))
|
|
3103
|
-
for i, k := range t.Keys {
|
|
3104
|
-
vv, _ := t.Get(k)
|
|
3105
|
-
fields[i] = WireField{Key: k, Val: valueToWire(vv)}
|
|
3106
|
-
}
|
|
3107
|
-
return WireRowOf(fields)
|
|
3108
|
-
default:
|
|
3109
|
-
return WireNull()
|
|
3110
|
-
}
|
|
3111
|
-
}
|
|
3112
|
-
|
|
3113
|
-
// FailureDetail exposes the structured Error Value fields WITHOUT naming the local ErrorDetail type, so
|
|
3114
|
-
// the harness can assert the de-box's kind / field / expectedType / actualWireType / rawValue (TEST
|
|
3115
|
-
// glue — same package as the covered module, so it may read the fields directly).
|
|
3116
|
-
func (e *BehaviorError) FailureDetail() (kind, model, field, expectedType, actualWireType, rawValue string, ok bool) {
|
|
3117
|
-
if e.Detail == nil {
|
|
3118
|
-
return "", "", "", "", "", "", false
|
|
3119
|
-
}
|
|
3120
|
-
d := e.Detail
|
|
3121
|
-
return d.Kind, d.Model, d.Field, d.ExpectedType, d.ActualWireType, d.RawValue, true
|
|
3122
|
-
}`
|
|
3123
|
-
: "";
|
|
3124
|
-
// ── op-agnostic leaf TRANSPORT funcs (TEST glue) — the scripted analog of the consumer's transport
|
|
3125
|
-
// symbols. ONE free transport per DISTINCT SPEC-fixed SYMBOL (#176/#183), UNIFORM signature
|
|
3126
|
-
// `<sym>(payload WireRow) (WireValue, error)`: it drains the shared scripted queue (keyed by the catalog
|
|
3127
|
-
// component) and returns the scripted wire — a WireList for a batched/fanout result (`src.ok` = `[]Value`,
|
|
3128
|
-
// a nil element → WireNull, the dangling marker), else a single WireValue. Echo (#129/#141) reads the port
|
|
3129
|
-
// back FROM THE PAYLOAD BY NAME (payload.get("<port>")) — proving the WireRow field-name↔port-name contract.
|
|
3130
|
-
// A single spec-named leaf used in MULTIPLE roles/cardinalities is emitted ONCE (the #183 fix); two nodes
|
|
3131
|
-
// resolving to the SAME symbol but DIFFERENT catalog components is a LOUD collision (never a silent
|
|
3132
|
-
// collapse). bc#87 parallel goroutines share the queue (mutex-guarded). ──
|
|
3133
|
-
const transportFns = [];
|
|
3134
|
-
const bySym = new Map();
|
|
3135
|
-
for (const c of native) {
|
|
3136
|
-
const typedNodes = new Map();
|
|
3137
|
-
for (const n of c.body)
|
|
3138
|
-
if (!isControlGate(n))
|
|
3139
|
-
typedNodes.set(n.id, "map" in n ? mapNodeArrRef(n, plan) : deriveTypeRef(n.outType, plan)); // #125: control-gate typeless; map は produced-array ref に正規化
|
|
3140
|
-
for (const n of c.body) {
|
|
3141
|
-
if ("cond" in n)
|
|
3142
|
-
continue; // #108: cond has no leaf (pure Expression) — no transport fn.
|
|
3143
|
-
// 純式 map(#222)も Component を呼ばないので transport は要らない(cond と同じ扱い)。
|
|
3144
|
-
if ("map" in n && mapTransformExpr(n.map) !== undefined)
|
|
3145
|
-
continue;
|
|
3146
|
-
const catalog = ("fanout" in n ? n.fanout.component : "map" in n ? n.map.component : n.component);
|
|
3147
|
-
const specSym = "fanout" in n ? n.fanout.leafSymbol : "map" in n ? n.map.leafSymbol : n.leafSymbol;
|
|
3148
|
-
const sym = leafSymbolBare(catalog, leaf, specSym);
|
|
3149
|
-
// echo branches (point/componentRef nodes only — a batched/fanout node returns a WireList, not a port).
|
|
3150
|
-
const echo = [];
|
|
3151
|
-
if (!("fanout" in n) && !("map" in n)) {
|
|
3152
|
-
const node = n;
|
|
3153
|
-
const crNarrowed = nodeNarrowedPaths(c, node);
|
|
3154
|
-
const ref = typedNodes.get(n.id);
|
|
3155
|
-
if (ref.kind === "named") {
|
|
3156
|
-
const decl = findDecl(plan, ref.name);
|
|
3157
|
-
const field = decl !== undefined && decl.fields.length === 1 ? decl.fields[0] : undefined;
|
|
3158
|
-
const fieldGo = field !== undefined ? renderTypeRef(field.type) : null;
|
|
3159
|
-
const recordGo = renderTypeRef(ref);
|
|
3160
|
-
for (const pn of Object.keys(node.ports)) {
|
|
3161
|
-
let portGo = null;
|
|
3162
|
-
try {
|
|
3163
|
-
portGo = portFieldGoType(node.ports[pn], c, plan, typedNodes, inputPortTypeRef(node.portSchemas?.[pn], plan), `echo port '${pn}'`, { narrowed: crNarrowed });
|
|
3164
|
-
}
|
|
3165
|
-
catch {
|
|
3166
|
-
portGo = null;
|
|
3167
|
-
}
|
|
3168
|
-
if (portGo === recordGo) {
|
|
3169
|
-
// the port IS the whole record → echo its payload wire DIRECTLY (matching run_behavior's echo:port).
|
|
3170
|
-
echo.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\tif v := payload.get(${JSON.stringify(pn)}); v != nil {\n\t\t\treturn *v, nil\n\t\t}\n\t}`);
|
|
3171
|
-
}
|
|
3172
|
-
else if (fieldGo !== null && field !== undefined && portGo === fieldGo) {
|
|
3173
|
-
// a scalar port wraps into the record's single field ({v: <port wire>}) — mirrors the scripted `wrap`.
|
|
3174
|
-
echo.push(`\tif src.echo == ${JSON.stringify(pn)} {\n\t\tif v := payload.get(${JSON.stringify(pn)}); v != nil {\n\t\t\treturn WireRowOf([]WireField{{Key: ${JSON.stringify(field.name)}, Val: *v}}), nil\n\t\t}\n\t}`);
|
|
3175
|
-
}
|
|
3176
|
-
}
|
|
3177
|
-
}
|
|
3178
|
-
else if (ref.kind === "arr" && Object.prototype.hasOwnProperty.call(node.ports, "items")) {
|
|
3179
|
-
// #129: an arr node with an `items` port echoes the payload's items wire (a WireList) so the
|
|
3180
|
-
// node→leaf array dataflow test is non-vacuous.
|
|
3181
|
-
echo.push(`\tif src.echo == "items" {\n\t\tif v := payload.get("items"); v != nil {\n\t\t\treturn *v, nil\n\t\t}\n\t}`);
|
|
3182
|
-
}
|
|
3183
|
-
}
|
|
3184
|
-
const prev = bySym.get(sym);
|
|
3185
|
-
if (prev !== undefined) {
|
|
3186
|
-
// #176/#183: a spec-fixed symbol MUST map to exactly ONE leaf (catalog component). The same leaf in
|
|
3187
|
-
// multiple roles shares ONE transport (byte-uniform signature) — accumulate its echo branches. Two
|
|
3188
|
-
// DIFFERENT catalog components colliding to the same symbol is a codegen error (never silent).
|
|
3189
|
-
if (prev.catalog !== catalog)
|
|
3190
|
-
throw new GeneratorFailure("DUPLICATE_COMPONENT", `go typed-native observe: leaf transport symbol '${sym}' resolves to TWO different catalog components ('${prev.catalog}' and '${catalog}') — a spec-fixed leaf symbol must map to ONE leaf (collision, fail-closed).`);
|
|
3191
|
-
for (const e of echo)
|
|
3192
|
-
if (!prev.echo.includes(e))
|
|
3193
|
-
prev.echo.push(e);
|
|
3194
|
-
continue;
|
|
3195
|
-
}
|
|
3196
|
-
bySym.set(sym, { catalog, echo });
|
|
3197
|
-
}
|
|
3198
|
-
}
|
|
3199
|
-
for (const [sym, le] of bySym) {
|
|
3200
|
-
const echoBlock = le.echo.length > 0 ? `${le.echo.join("\n")}\n` : "";
|
|
3201
|
-
transportFns.push(`func ${sym}(payload WireRow) (WireValue, error) {
|
|
3202
|
-
_ = payload
|
|
3203
|
-
src, ok := nextScripted(${JSON.stringify(le.catalog)})
|
|
3204
|
-
if !ok {
|
|
3205
|
-
return WireValue{}, unknownComponent(${JSON.stringify(le.catalog)})
|
|
3206
|
-
}
|
|
3207
|
-
if src.isErr {
|
|
3208
|
-
return WireValue{}, leafFailure(src.err)
|
|
3209
|
-
}
|
|
3210
|
-
${echoBlock} // valueToWire is recursive: a batched/fanout []Value result becomes a WireList (a nil element ->
|
|
3211
|
-
// WireNull, the dangling marker), a single result a scalar/row wire -- ONE signature serves every
|
|
3212
|
-
// cardinality (the covered runner reads .Items for batched/fanout, the single wire for a point read).
|
|
3213
|
-
return valueToWire(src.ok), nil
|
|
3214
|
-
}`);
|
|
3215
|
-
}
|
|
3216
|
-
const adapter = `// scriptSrc — a scripted per-component outcome (an ok Value or an error), drained in order.
|
|
3217
|
-
// #129: \`echo\` carries the reference scriptedHandlers' \`echo\` directive (e.g. "items") so a scripted
|
|
3218
|
-
// node can ECHO a named input PORT back as its result — used to make the node→leaf array dataflow test
|
|
3219
|
-
// non-vacuous (the leaf handler returns its \`items\` port, so a dropped/boxed native array diverges).
|
|
3220
|
-
type scriptSrc struct {
|
|
3221
|
-
isErr bool
|
|
3222
|
-
err string
|
|
3223
|
-
echo string
|
|
3224
|
-
ok ${PKG}.Value
|
|
3225
|
-
}
|
|
3226
|
-
|
|
3227
|
-
// the shared scripted-outcome source the free Leaf_<comp> transport funcs drain (TEST glue). A package var
|
|
3228
|
-
// (not a per-call handler object) so the bc#87 parallel goroutines share it (mutex-guarded); reset+filled
|
|
3229
|
-
// per case by ObserveNativeRaw. Cases run sequentially in the harness, so one shared queue per case is fine.
|
|
3230
|
-
var (
|
|
3231
|
-
scriptedMu sync.Mutex
|
|
3232
|
-
scriptedQueues = map[string][]scriptSrc{}
|
|
3233
|
-
scriptedSeen int
|
|
3234
|
-
)
|
|
3235
|
-
|
|
3236
|
-
// fillScripted resets + loads the shared queue from the JSON handlers spec (the SAME shape the reference
|
|
3237
|
-
// scriptedHandlers reads): { "<component>": {ok|error} | [ {ok|error}, … ] }. Each ok Value is
|
|
3238
|
-
// DecodeValue'd once here (test glue). Returns any decode error (surfaced by the runner as a fatal).
|
|
3239
|
-
func fillScripted(spec *${PKG}.JObj) error {
|
|
3240
|
-
scriptedMu.Lock()
|
|
3241
|
-
defer scriptedMu.Unlock()
|
|
3242
|
-
scriptedQueues = map[string][]scriptSrc{}
|
|
3243
|
-
scriptedSeen = 0
|
|
3244
|
-
if spec == nil {
|
|
3245
|
-
return nil
|
|
3246
|
-
}
|
|
3247
|
-
for _, comp := range spec.Keys {
|
|
3248
|
-
var entries []${PKG}.JNode
|
|
3249
|
-
switch t := spec.Vals[comp].(type) {
|
|
3250
|
-
case []${PKG}.JNode:
|
|
3251
|
-
entries = t
|
|
3252
|
-
default:
|
|
3253
|
-
entries = []${PKG}.JNode{t}
|
|
3254
|
-
}
|
|
3255
|
-
for _, e := range entries {
|
|
3256
|
-
eo, _ := e.(*${PKG}.JObj)
|
|
3257
|
-
// #129: an \`echo\` directive names an input port to echo back (mirrors the reference
|
|
3258
|
-
// scriptedHandlers' \`echo === "items"\`). It is drained together with the ok payload.
|
|
3259
|
-
echo := ""
|
|
3260
|
-
if echoNode, has := eo.Get("echo"); has {
|
|
3261
|
-
echo, _ = echoNode.(string)
|
|
3262
|
-
// normalize echo:port to the port NAME X so a de-box handler's echo comparison fires;
|
|
3263
|
-
// echo:items already names the port directly.
|
|
3264
|
-
if echo == "port" {
|
|
3265
|
-
if portNode, hasPort := eo.Get("port"); hasPort {
|
|
3266
|
-
echo, _ = portNode.(string)
|
|
3267
|
-
}
|
|
3268
|
-
}
|
|
3269
|
-
}
|
|
3270
|
-
if okNode, has := eo.Get("ok"); has {
|
|
3271
|
-
val, derr := ${PKG}.DecodeValue(okNode)
|
|
3272
|
-
if derr != nil {
|
|
3273
|
-
return derr
|
|
3274
|
-
}
|
|
3275
|
-
scriptedQueues[comp] = append(scriptedQueues[comp], scriptSrc{ok: val, echo: echo})
|
|
3276
|
-
continue
|
|
3277
|
-
}
|
|
3278
|
-
ev, _ := eo.Get("error")
|
|
3279
|
-
es, _ := ev.(string)
|
|
3280
|
-
scriptedQueues[comp] = append(scriptedQueues[comp], scriptSrc{isErr: true, err: es})
|
|
3281
|
-
}
|
|
3282
|
-
}
|
|
3283
|
-
return nil
|
|
3284
|
-
}
|
|
3285
|
-
|
|
3286
|
-
// nextScripted drains one scripted outcome for a component (last entry repeats — mirrors the reference
|
|
3287
|
-
// scriptedHandlers), returns ok=false when the component has no scripted queue (fail-closed). The bc#87
|
|
3288
|
-
// parallel-stage runner calls the transport funcs from multiple goroutines, so the drain is mutex-guarded.
|
|
3289
|
-
func nextScripted(component string) (scriptSrc, bool) {
|
|
3290
|
-
scriptedMu.Lock()
|
|
3291
|
-
defer scriptedMu.Unlock()
|
|
3292
|
-
scriptedSeen++
|
|
3293
|
-
q, ok := scriptedQueues[component]
|
|
3294
|
-
if !ok || len(q) == 0 {
|
|
3295
|
-
return scriptSrc{}, false
|
|
3296
|
-
}
|
|
3297
|
-
if len(q) > 1 {
|
|
3298
|
-
v := q[0]
|
|
3299
|
-
scriptedQueues[component] = q[1:]
|
|
3300
|
-
return v, true
|
|
3301
|
-
}
|
|
3302
|
-
return q[0], true
|
|
3303
|
-
}`;
|
|
3304
|
-
return `// GENERATED test-only observe companion (bc#77) — NOT part of the covered module. Serializes the
|
|
3305
|
-
// struct-native runner's result to a canonical Value for the equivalence pin, and carries the SCRIPTED
|
|
3306
|
-
// analog of the consumer's leaf transport symbols: free Leaf_<comp> funcs (same package as the covered
|
|
3307
|
-
// module, so its transport calls resolve) that drain a shared package-level scripted queue + the CONCRETE
|
|
3308
|
-
// WireValue/WireRow/WireList seam types. The consumer never uses this (it keeps the model native + supplies
|
|
3309
|
-
// its own concrete WireValue + transport funcs); it exists only so the test harness can byte-compare the
|
|
3310
|
-
// STRUCT-only covered read against run_behavior. Same package as the module (#192: shared namespace).
|
|
3311
|
-
package ${goPackageName(namespace)}
|
|
3312
|
-
|
|
3313
|
-
import (
|
|
3314
|
-
"sync"
|
|
3315
|
-
|
|
3316
|
-
${PKG} "${runtimeImport ?? "github.com/foo-ogawa/behavior-contracts/go"}"
|
|
3317
|
-
)
|
|
3318
|
-
|
|
3319
|
-
// valueToWire (TEST glue) — builds the covered module's BC-owned WireValue from a scripted bc Value.
|
|
3320
|
-
${wireAdapter}
|
|
3321
|
-
|
|
3322
|
-
// typed -> Value serializers (TEST glue only — the covered module has none).
|
|
3323
|
-
${serializers}
|
|
3324
|
-
|
|
3325
|
-
// Value -> typed struct marshallers (+ must* helpers) for the input decoders (TEST glue only).
|
|
3326
|
-
${marshallers}
|
|
3327
|
-
|
|
3328
|
-
${mustHelpers}
|
|
3329
|
-
|
|
3330
|
-
${arrOptHelpers}
|
|
3331
|
-
|
|
3332
|
-
// input decoders (generic *Obj -> concrete In_<comp>; TEST glue, one decode at the observe boundary).
|
|
3333
|
-
${inDecoders}
|
|
3334
|
-
|
|
3335
|
-
${adapter}
|
|
3336
|
-
|
|
3337
|
-
// scripted leaf transport funcs (one per covered leaf — the free op-agnostic transport the covered runner
|
|
3338
|
-
// calls directly; test glue draining the shared package queue).
|
|
3339
|
-
${transportFns.join("\n\n")}
|
|
3340
|
-
|
|
3341
|
-
// ObserveNativeRaw resets+fills the shared scripted queue from the per-case spec, then drives the covered
|
|
3342
|
-
// struct-native runner and serializes to a canonical Value (test only). No handler object is passed — the
|
|
3343
|
-
// runner calls the free Leaf_<comp> transport funcs above directly (same package).
|
|
3344
|
-
func ObserveNativeRaw(name string, spec *${PKG}.JObj, input *${PKG}.Obj) (${PKG}.Value, error) {
|
|
3345
|
-
if ferr := fillScripted(spec); ferr != nil {
|
|
3346
|
-
return nil, ferr
|
|
3347
|
-
}
|
|
3348
|
-
${arms}
|
|
3349
|
-
return nil, ${PKG}.NewBehaviorFailure("UNKNOWN_ENTRY", "component '"+name+"' is not a covered read (fail-closed)")
|
|
3350
|
-
}
|
|
3351
|
-
`;
|
|
3352
|
-
}
|
|
3353
2917
|
/**
|
|
3354
2918
|
* goTypedNativeEmitter — language id `go-typed-native` (bc#77). Emits the generic straight-line
|
|
3355
2919
|
* body (for non-covered components / helpers) plus the COMBINED READ layer (native ports struct
|