@sublang/slc 0.22.0 → 0.23.0-rc.13
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 +47 -48
- package/dist/app.d.ts +1 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +14 -3
- package/dist/app.js.map +1 -1
- package/dist/check-report.d.ts +4 -0
- package/dist/check-report.d.ts.map +1 -0
- package/dist/check-report.js +35 -0
- package/dist/check-report.js.map +1 -0
- package/dist/cli.js +45 -1
- package/dist/cli.js.map +1 -1
- package/dist/cligent-agent.d.ts.map +1 -1
- package/dist/cligent-agent.js +37 -1
- package/dist/cligent-agent.js.map +1 -1
- package/dist/compilation-audit.d.ts +14 -0
- package/dist/compilation-audit.d.ts.map +1 -0
- package/dist/compilation-audit.js +67 -0
- package/dist/compilation-audit.js.map +1 -0
- package/dist/compiled-executor.js +1 -1
- package/dist/compiled-executor.js.map +1 -1
- package/dist/compiler-identity.d.ts +7 -0
- package/dist/compiler-identity.d.ts.map +1 -0
- package/dist/compiler-identity.js +48 -0
- package/dist/compiler-identity.js.map +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +36 -13
- package/dist/config.js.map +1 -1
- package/dist/entry-module.d.ts.map +1 -1
- package/dist/entry-module.js +72 -3
- package/dist/entry-module.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +6 -0
- package/dist/errors.js.map +1 -1
- package/dist/execution.d.ts +2 -0
- package/dist/execution.d.ts.map +1 -1
- package/dist/execution.js.map +1 -1
- package/dist/interpreter.d.ts +2 -0
- package/dist/interpreter.d.ts.map +1 -1
- package/dist/interpreter.js +1 -1
- package/dist/interpreter.js.map +1 -1
- package/dist/isolated-check.d.ts +3 -0
- package/dist/isolated-check.d.ts.map +1 -0
- package/dist/isolated-check.js +160 -0
- package/dist/isolated-check.js.map +1 -0
- package/dist/managed-compilation.d.ts +4 -0
- package/dist/managed-compilation.d.ts.map +1 -0
- package/dist/managed-compilation.js +385 -0
- package/dist/managed-compilation.js.map +1 -0
- package/dist/runner.d.ts +15 -6
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +105 -46
- package/dist/runner.js.map +1 -1
- package/dist/verification-worker.d.ts +2 -0
- package/dist/verification-worker.d.ts.map +1 -0
- package/dist/verification-worker.js +223 -0
- package/dist/verification-worker.js.map +1 -0
- package/dist/verify-coverage.d.ts +3 -0
- package/dist/verify-coverage.d.ts.map +1 -1
- package/dist/verify-coverage.js +461 -71
- package/dist/verify-coverage.js.map +1 -1
- package/dist/verify-source.d.ts +2 -0
- package/dist/verify-source.d.ts.map +1 -1
- package/dist/verify-source.js +55 -0
- package/dist/verify-source.js.map +1 -1
- package/dist/verify-typescript.js +2 -0
- package/dist/verify-typescript.js.map +1 -1
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +2 -5
- package/dist/verify.js.map +1 -1
- package/package.json +5 -5
package/dist/verify-coverage.js
CHANGED
|
@@ -23,7 +23,7 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
23
23
|
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
26
|
-
import { isDeepStrictEqual } from 'node:util';
|
|
26
|
+
import { isDeepStrictEqual, types as utilTypes } from 'node:util';
|
|
27
27
|
import { createActor, fromPromise } from 'xstate';
|
|
28
28
|
import { AWAIT_BOSS_REPLY_STATE, BOSS_REPLY_EVENT, INTERRUPT_EVENT, NEEDS_BOSS_REPLY, VERIFY_MODULE, controllerDecisionNearMiss, enumerateCaptainStates, enumeratePlaybookStates, enumerateScriptStates, initialStateTarget, isControllerDecisionResult, isControllerMachine, loadFsmModule, normalizeArms, prepareGearsFsmConformance, findConcurrentRoleSets, ReachedLiteralChildChecks, resolveArtifactSchemaForVerification, usesKeyedBossQuestionContext, } from './verify.js';
|
|
29
29
|
/** The `gears2fsm`-mandated captain actor name a machine declares. */
|
|
@@ -256,7 +256,7 @@ const COVERAGE_MACHINE_INPUT = {
|
|
|
256
256
|
function coverageMachineInput(machine) {
|
|
257
257
|
const cached = coverageRuns.getStore()?.machineInputs.get(machine.config);
|
|
258
258
|
if (cached !== undefined)
|
|
259
|
-
return cached;
|
|
259
|
+
return freshMachineInput(cached);
|
|
260
260
|
const enabledPlaybooks = [
|
|
261
261
|
...COVERAGE_ENABLED_PLAYBOOKS,
|
|
262
262
|
];
|
|
@@ -278,7 +278,16 @@ function coverageMachineInput(machine) {
|
|
|
278
278
|
}
|
|
279
279
|
const input = { ...COVERAGE_MACHINE_INPUT, enabledPlaybooks };
|
|
280
280
|
coverageRuns.getStore()?.machineInputs.set(machine.config, input);
|
|
281
|
-
return input;
|
|
281
|
+
return freshMachineInput(input);
|
|
282
|
+
}
|
|
283
|
+
/** Cached templates are never passed to artifact code, including seed actors. */
|
|
284
|
+
function freshMachineInput(template) {
|
|
285
|
+
const caller = coverageRuns.getStore()?.machineInput;
|
|
286
|
+
return {
|
|
287
|
+
...(caller === undefined ? {} : snapshotCallerMachineInput(caller)),
|
|
288
|
+
...template,
|
|
289
|
+
enabledPlaybooks: template.enabledPlaybooks.map((entry) => ({ ...entry })),
|
|
290
|
+
};
|
|
282
291
|
}
|
|
283
292
|
/**
|
|
284
293
|
* A valid Captain context for direct guard evaluation. Dynamic call fields use
|
|
@@ -553,6 +562,12 @@ function playbookRefs(config) {
|
|
|
553
562
|
// so it may not import a sibling module.
|
|
554
563
|
function coverageErrorMessage(error) {
|
|
555
564
|
try {
|
|
565
|
+
if (error instanceof Error &&
|
|
566
|
+
'code' in error &&
|
|
567
|
+
error.code === 'ERR_ACCESS_DENIED') {
|
|
568
|
+
const detail = error;
|
|
569
|
+
return `artifact: forbidden verification side effect (${String(detail.permission)} at ${String(detail.resource)}): ${error.message}`;
|
|
570
|
+
}
|
|
556
571
|
return error instanceof Error ? error.message : String(error);
|
|
557
572
|
}
|
|
558
573
|
catch {
|
|
@@ -653,23 +668,7 @@ function resolvedStateNode(machine, ref) {
|
|
|
653
668
|
}
|
|
654
669
|
return node;
|
|
655
670
|
}
|
|
656
|
-
function
|
|
657
|
-
const seed = trackCoverageActor(createActor(provided, { input: coverageMachineInput(provided) }));
|
|
658
|
-
let completed = false;
|
|
659
|
-
try {
|
|
660
|
-
const snapshot = {
|
|
661
|
-
...seed.getPersistedSnapshot(),
|
|
662
|
-
context: { ...context },
|
|
663
|
-
children: {},
|
|
664
|
-
};
|
|
665
|
-
completed = true;
|
|
666
|
-
return snapshot;
|
|
667
|
-
}
|
|
668
|
-
finally {
|
|
669
|
-
stopCoverageActors([seed], !completed);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
function makeActor(machine, script, playbookScript = () => null, restoredContext, observeTransition) {
|
|
671
|
+
function makeActor(machine, script, playbookScript = () => null, observeTransition, publicInput) {
|
|
673
672
|
coverageCheckpoint();
|
|
674
673
|
const coverageInputs = new Map();
|
|
675
674
|
const coverageErrors = [];
|
|
@@ -704,14 +703,8 @@ function makeActor(machine, script, playbookScript = () => null, restoredContext
|
|
|
704
703
|
}),
|
|
705
704
|
},
|
|
706
705
|
});
|
|
707
|
-
const restoredSnapshot = restoredContext === undefined
|
|
708
|
-
? undefined
|
|
709
|
-
: persistedSnapshotWithContext(provided, restoredContext);
|
|
710
706
|
const actor = trackCoverageActor(createActor(provided, {
|
|
711
|
-
input: coverageMachineInput(machine),
|
|
712
|
-
...(restoredSnapshot === undefined
|
|
713
|
-
? {}
|
|
714
|
-
: { snapshot: restoredSnapshot }),
|
|
707
|
+
input: { ...coverageMachineInput(machine), ...publicInput },
|
|
715
708
|
inspect: (inspection) => {
|
|
716
709
|
if (typeof inspection !== 'object' ||
|
|
717
710
|
inspection === null ||
|
|
@@ -990,7 +983,7 @@ function orderedArmPredicate(machine, arms, selected) {
|
|
|
990
983
|
return undefined;
|
|
991
984
|
}
|
|
992
985
|
/** A bounded satisfying context/event pair for one authored interrupt arm. */
|
|
993
|
-
function interruptDriveForRef(machine, refs, target, targetId, extraValues = [], selectedArmIndex) {
|
|
986
|
+
function interruptDriveForRef(machine, refs, target, targetId, extraValues = [], selectedArmIndex, reachedContext) {
|
|
994
987
|
const arms = transitionArms((machine.config.on ?? {})[INTERRUPT_EVENT]);
|
|
995
988
|
const armIndex = selectedArmIndex ??
|
|
996
989
|
arms.findIndex((arm) => {
|
|
@@ -1009,10 +1002,7 @@ function interruptDriveForRef(machine, refs, target, targetId, extraValues = [],
|
|
|
1009
1002
|
? entryTarget.stableId
|
|
1010
1003
|
: targetId,
|
|
1011
1004
|
};
|
|
1012
|
-
const
|
|
1013
|
-
const initialContext = initializedCoverageContext(machine, targetPlaybook === undefined
|
|
1014
|
-
? undefined
|
|
1015
|
-
: dynamicPlaybookFields(targetPlaybook));
|
|
1005
|
+
const initialContext = reachedContext ?? initializedMachineContext(machine);
|
|
1016
1006
|
if (armIndex < 0 || armIndex >= arms.length) {
|
|
1017
1007
|
return { event: base, context: initialContext, satisfiable: false };
|
|
1018
1008
|
}
|
|
@@ -1030,7 +1020,7 @@ function interruptDriveForRef(machine, refs, target, targetId, extraValues = [],
|
|
|
1030
1020
|
...extraValues,
|
|
1031
1021
|
], {
|
|
1032
1022
|
initialContext,
|
|
1033
|
-
|
|
1023
|
+
assignContext: false,
|
|
1034
1024
|
});
|
|
1035
1025
|
return assignment === undefined
|
|
1036
1026
|
? { event: base, context: initialContext, satisfiable: false }
|
|
@@ -1041,12 +1031,12 @@ function interruptDriveForRef(machine, refs, target, targetId, extraValues = [],
|
|
|
1041
1031
|
};
|
|
1042
1032
|
}
|
|
1043
1033
|
/** The existing first satisfying event remains unchanged for direct callers. */
|
|
1044
|
-
function entryDriveForRef(machine, refs, target, extraValues = [], initialContext =
|
|
1034
|
+
function entryDriveForRef(machine, refs, target, extraValues = [], initialContext = initializedMachineContext(machine)) {
|
|
1045
1035
|
const first = entryDrivesForRef(machine, refs, target, extraValues, initialContext).next();
|
|
1046
1036
|
return first.done ? undefined : first.value;
|
|
1047
1037
|
}
|
|
1048
1038
|
/** Lazy one-field public events, never new context or an unguarded entry. */
|
|
1049
|
-
function* entryDrivesForRef(machine, refs, target, extraValues = [], initialContext =
|
|
1039
|
+
function* entryDrivesForRef(machine, refs, target, extraValues = [], initialContext = initializedMachineContext(machine), allEntrySurfaces = false) {
|
|
1050
1040
|
const initialPath = initialActiveRefs(machine.config, refs);
|
|
1051
1041
|
const surfaces = [
|
|
1052
1042
|
...initialPath
|
|
@@ -1082,13 +1072,45 @@ function* entryDrivesForRef(machine, refs, target, extraValues = [], initialCont
|
|
|
1082
1072
|
const probeBudget = { probes: 0 };
|
|
1083
1073
|
const assignment = probeGuardAssignment(guard.run, {}, [{ tag: 'e:', base }], values, {
|
|
1084
1074
|
initialContext,
|
|
1085
|
-
|
|
1075
|
+
assignContext: false,
|
|
1086
1076
|
probeBudget,
|
|
1087
1077
|
});
|
|
1088
1078
|
if (assignment !== undefined) {
|
|
1089
1079
|
const event = assignedPayload(base, assignment, 'e:');
|
|
1090
1080
|
yield { event, context: assignment.context, satisfiable: true };
|
|
1091
|
-
const
|
|
1081
|
+
const entryFields = Object.keys(assignment.payloads['e:'] ?? {});
|
|
1082
|
+
// A guard-free START may copy its task into context only in an
|
|
1083
|
+
// action. Observe those event reads during a real, stopped entry;
|
|
1084
|
+
// never infer context keys or alter a private actor snapshot.
|
|
1085
|
+
if (entryFields.length === 0 &&
|
|
1086
|
+
armGuard(arm) === undefined &&
|
|
1087
|
+
typeof arm === 'object' &&
|
|
1088
|
+
arm !== null &&
|
|
1089
|
+
'actions' in arm) {
|
|
1090
|
+
const reads = new Set();
|
|
1091
|
+
const observed = new Proxy({ ...event }, {
|
|
1092
|
+
get(value, key, receiver) {
|
|
1093
|
+
if (typeof key === 'string' &&
|
|
1094
|
+
key !== 'type' &&
|
|
1095
|
+
!Reflect.has(value, key) &&
|
|
1096
|
+
reads.size < 5)
|
|
1097
|
+
reads.add(key);
|
|
1098
|
+
return Reflect.get(value, key, receiver);
|
|
1099
|
+
},
|
|
1100
|
+
});
|
|
1101
|
+
const actor = makeActor(machine, () => null, () => null);
|
|
1102
|
+
try {
|
|
1103
|
+
if (++probeBudget.probes > MAX_PROBES)
|
|
1104
|
+
return;
|
|
1105
|
+
actor.send(observed);
|
|
1106
|
+
}
|
|
1107
|
+
finally {
|
|
1108
|
+
actor.stop();
|
|
1109
|
+
}
|
|
1110
|
+
if (reads.size <= 4)
|
|
1111
|
+
entryFields.push(...reads);
|
|
1112
|
+
}
|
|
1113
|
+
const fields = entryFields
|
|
1092
1114
|
.filter((field) => field !== 'type')
|
|
1093
1115
|
.map((field) => ({ field, cursor: 0 }));
|
|
1094
1116
|
const candidates = [
|
|
@@ -1868,9 +1890,7 @@ function callCount(calls, captain) {
|
|
|
1868
1890
|
/** One public drive or the actual initialized state, never a private jump. */
|
|
1869
1891
|
function childCoverageDrive(machine, refs, ref, targetId, candidates) {
|
|
1870
1892
|
const interrupt = interruptDriveForRef(machine, refs, ref, targetId, candidates);
|
|
1871
|
-
const alternatives = entryDrivesForRef(machine, refs, ref, candidates, coverageRuns.getStore()?.literalChecks?.pending()
|
|
1872
|
-
? initializedMachineContext(machine)
|
|
1873
|
-
: initializedCoverageContext(machine), coverageRuns.getStore()?.literalChecks?.pending() ?? false);
|
|
1893
|
+
const alternatives = entryDrivesForRef(machine, refs, ref, candidates, initializedMachineContext(machine), coverageRuns.getStore()?.literalChecks?.pending() ?? false);
|
|
1874
1894
|
// A valid interrupt need not preserve every public entry's reached context.
|
|
1875
1895
|
if (interrupt.satisfiable)
|
|
1876
1896
|
return { drive: interrupt, alternatives };
|
|
@@ -1881,6 +1901,68 @@ function childCoverageDrive(machine, refs, ref, targetId, candidates) {
|
|
|
1881
1901
|
? {}
|
|
1882
1902
|
: undefined;
|
|
1883
1903
|
}
|
|
1904
|
+
/** A scheduling hint only: unsupported data never compares equal or loses a path. */
|
|
1905
|
+
function questionProgressSnapshot(context) {
|
|
1906
|
+
let visits = 0;
|
|
1907
|
+
let textSize = 0;
|
|
1908
|
+
const active = new Set();
|
|
1909
|
+
const copies = new Map();
|
|
1910
|
+
const unsupported = Symbol('unsupported');
|
|
1911
|
+
const copy = (value, depth) => {
|
|
1912
|
+
if (++visits > 128 || depth > 8)
|
|
1913
|
+
throw unsupported;
|
|
1914
|
+
if (typeof value === 'string') {
|
|
1915
|
+
textSize += value.length;
|
|
1916
|
+
if (textSize > 65536)
|
|
1917
|
+
throw unsupported;
|
|
1918
|
+
}
|
|
1919
|
+
if (value === null ||
|
|
1920
|
+
['undefined', 'boolean', 'number', 'string', 'bigint'].includes(typeof value))
|
|
1921
|
+
return value;
|
|
1922
|
+
if (typeof value !== 'object' ||
|
|
1923
|
+
utilTypes.isProxy(value) ||
|
|
1924
|
+
active.has(value))
|
|
1925
|
+
throw unsupported;
|
|
1926
|
+
const previous = copies.get(value);
|
|
1927
|
+
if (previous !== undefined)
|
|
1928
|
+
return previous;
|
|
1929
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1930
|
+
if (prototype !== Object.prototype &&
|
|
1931
|
+
prototype !== null &&
|
|
1932
|
+
prototype !== Array.prototype)
|
|
1933
|
+
throw unsupported;
|
|
1934
|
+
const keys = Reflect.ownKeys(value);
|
|
1935
|
+
if (keys.length > 128)
|
|
1936
|
+
throw unsupported;
|
|
1937
|
+
if (Array.isArray(value) &&
|
|
1938
|
+
(value.length > 127 || keys.length !== value.length + 1))
|
|
1939
|
+
throw unsupported;
|
|
1940
|
+
const result = Array.isArray(value)
|
|
1941
|
+
? []
|
|
1942
|
+
: Object.create(prototype);
|
|
1943
|
+
copies.set(value, result);
|
|
1944
|
+
active.add(value);
|
|
1945
|
+
for (const key of keys) {
|
|
1946
|
+
if (typeof key !== 'string')
|
|
1947
|
+
throw unsupported;
|
|
1948
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
1949
|
+
if (descriptor === undefined || !('value' in descriptor))
|
|
1950
|
+
throw unsupported;
|
|
1951
|
+
Object.defineProperty(result, key, {
|
|
1952
|
+
...descriptor,
|
|
1953
|
+
value: copy(descriptor.value, depth + 1),
|
|
1954
|
+
});
|
|
1955
|
+
}
|
|
1956
|
+
active.delete(value);
|
|
1957
|
+
return result;
|
|
1958
|
+
};
|
|
1959
|
+
try {
|
|
1960
|
+
return { value: copy(context, 0) };
|
|
1961
|
+
}
|
|
1962
|
+
catch {
|
|
1963
|
+
return undefined;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1884
1966
|
function coverageNodeKey(node) {
|
|
1885
1967
|
return `${stateRefKey(node.value.ref)}:${node.value.invocationIndex}`;
|
|
1886
1968
|
}
|
|
@@ -2014,7 +2096,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
2014
2096
|
pending = { node, input, complete };
|
|
2015
2097
|
});
|
|
2016
2098
|
};
|
|
2017
|
-
const actor = makeActor(machine, script, script, path.
|
|
2099
|
+
const actor = makeActor(machine, script, script, undefined, path.witness?.input);
|
|
2018
2100
|
const trustedEntry = path.drive === undefined ||
|
|
2019
2101
|
isDeepStrictEqual(path.drive.context, initializedMachineContext(machine));
|
|
2020
2102
|
const observe = (current) => {
|
|
@@ -2028,6 +2110,12 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
2028
2110
|
gate.armed = true;
|
|
2029
2111
|
if (path.drive !== undefined)
|
|
2030
2112
|
actor.send(path.drive.event);
|
|
2113
|
+
for (const event of path.witness?.events ?? []) {
|
|
2114
|
+
coverageCheckpoint();
|
|
2115
|
+
pending = undefined;
|
|
2116
|
+
actor.send(event);
|
|
2117
|
+
await coverageYield(true);
|
|
2118
|
+
}
|
|
2031
2119
|
const wait = () => settle(actor, (snapshot) => (pending !== undefined && atState(expected.value.ref)(snapshot)) ||
|
|
2032
2120
|
snapshot.status === 'done' ||
|
|
2033
2121
|
snapshot.status === 'error', PARALLEL_SETTLE_MS);
|
|
@@ -2044,7 +2132,21 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
2044
2132
|
observe(current);
|
|
2045
2133
|
pending = undefined;
|
|
2046
2134
|
expected = step.next;
|
|
2047
|
-
|
|
2135
|
+
if (step.interrupt !== undefined) {
|
|
2136
|
+
const before = actor.coverageTransitions.length;
|
|
2137
|
+
actor.send(step.interrupt.event);
|
|
2138
|
+
if (!actor.coverageTransitions
|
|
2139
|
+
.slice(before)
|
|
2140
|
+
.some((transition) => transition.root &&
|
|
2141
|
+
transition.armIndex === step.interrupt.armIndex &&
|
|
2142
|
+
transition.event === step.interrupt.event &&
|
|
2143
|
+
transition.targetIds.includes(step.interrupt.targetId))) {
|
|
2144
|
+
completedPrefix = false;
|
|
2145
|
+
break;
|
|
2146
|
+
}
|
|
2147
|
+
}
|
|
2148
|
+
else
|
|
2149
|
+
current.complete(step.result);
|
|
2048
2150
|
if (step.questionWait !== undefined) {
|
|
2049
2151
|
if (!(await settle(actor, atState(step.questionWait), PARALLEL_SETTLE_MS))) {
|
|
2050
2152
|
completedPrefix = false;
|
|
@@ -2094,7 +2196,12 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2094
2196
|
return nodes.filter((node) => targetEntersRef(refs, targetRef, node.value.ref));
|
|
2095
2197
|
};
|
|
2096
2198
|
const reachable = new Set([coverageNodeKey(target)]);
|
|
2199
|
+
const rootInterruptArms = transitionArms((machine.config.on ?? {})[INTERRUPT_EVENT]);
|
|
2097
2200
|
for (let pass = 0; pass < nodes.length; pass++) {
|
|
2201
|
+
if (rootInterruptArms.some((arm) => nodesForTarget(arm, target.value.ref).some((next) => reachable.has(coverageNodeKey(next))))) {
|
|
2202
|
+
for (const node of nodes)
|
|
2203
|
+
reachable.add(coverageNodeKey(node));
|
|
2204
|
+
}
|
|
2098
2205
|
for (const node of nodes) {
|
|
2099
2206
|
if (['onDone', 'onError'].some((outcome) => transitionArms(node.value.invocation[outcome]).some((arm) => {
|
|
2100
2207
|
return nodesForTarget(arm, node.value.ref).some((next) => reachable.has(coverageNodeKey(next)));
|
|
@@ -2115,6 +2222,14 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2115
2222
|
if (entry !== undefined)
|
|
2116
2223
|
queue.push({ root: node, ...entry, steps: [] });
|
|
2117
2224
|
}
|
|
2225
|
+
for (const node of nodes) {
|
|
2226
|
+
if (!reachable.has(coverageNodeKey(node)))
|
|
2227
|
+
continue;
|
|
2228
|
+
for (const witness of coverageRuns.getStore()?.witnesses ?? []) {
|
|
2229
|
+
if (witness.events.length <= budget.maxInvocations)
|
|
2230
|
+
queue.unshift({ root: node, steps: [], witness });
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2118
2233
|
// Family identity is only the declared root invocation. Keep every actual
|
|
2119
2234
|
// context, prefix and lazy entry alternative distinct within that family.
|
|
2120
2235
|
const rootFamilies = [
|
|
@@ -2174,6 +2289,33 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2174
2289
|
const node = pending.node;
|
|
2175
2290
|
const context = replay.actor.getSnapshot().context;
|
|
2176
2291
|
const nextSteps = [];
|
|
2292
|
+
for (const [armIndex, arm] of rootInterruptArms.entries()) {
|
|
2293
|
+
for (const next of nodesForTarget(arm, node.value.ref)) {
|
|
2294
|
+
if (coverageNodeKey(next) !== coverageNodeKey(target))
|
|
2295
|
+
continue;
|
|
2296
|
+
if (!reachable.has(coverageNodeKey(next)))
|
|
2297
|
+
continue;
|
|
2298
|
+
const drive = interruptDriveForRef(machine, refs, next.value.ref, next.kind === 'acting'
|
|
2299
|
+
? captainInterruptTarget(next.value)
|
|
2300
|
+
: interruptTargetForRef(next.value.ref, next.value.ref.stableId), candidates, armIndex, context);
|
|
2301
|
+
if (!drive.satisfiable)
|
|
2302
|
+
continue;
|
|
2303
|
+
const rawTarget = rawArmTarget(arm);
|
|
2304
|
+
const targetRef = rawTarget === undefined
|
|
2305
|
+
? undefined
|
|
2306
|
+
: stateRefForTarget(refs, rawTarget);
|
|
2307
|
+
const targetId = targetRef === undefined
|
|
2308
|
+
? undefined
|
|
2309
|
+
: resolvedStateNode(machine, targetRef)?.id;
|
|
2310
|
+
if (targetId !== undefined)
|
|
2311
|
+
nextSteps.push({
|
|
2312
|
+
node,
|
|
2313
|
+
result: undefined,
|
|
2314
|
+
next,
|
|
2315
|
+
interrupt: { event: drive.event, armIndex, targetId },
|
|
2316
|
+
});
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2177
2319
|
for (const outcome of ['onDone', 'onError']) {
|
|
2178
2320
|
for (const [index, arm] of transitionArms(node.value.invocation[outcome]).entries()) {
|
|
2179
2321
|
for (const next of nodesForTarget(arm, node.value.ref)) {
|
|
@@ -2206,28 +2348,43 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2206
2348
|
result instanceof Error ||
|
|
2207
2349
|
typeof result.question !== 'string')
|
|
2208
2350
|
continue;
|
|
2209
|
-
|
|
2351
|
+
const questionContext = questionProgressSnapshot(context);
|
|
2352
|
+
nextSteps.push({
|
|
2353
|
+
node,
|
|
2354
|
+
result,
|
|
2355
|
+
next: node,
|
|
2356
|
+
questionWait: waitRef,
|
|
2357
|
+
...(questionContext === undefined ? {} : { questionContext }),
|
|
2358
|
+
});
|
|
2210
2359
|
}
|
|
2211
2360
|
}
|
|
2212
2361
|
}
|
|
2213
2362
|
const continuations = [];
|
|
2214
2363
|
for (const step of nextSteps) {
|
|
2215
|
-
if (path.steps.length +
|
|
2364
|
+
if (path.steps.length + (path.witness?.events.length ?? 0) + 1 >=
|
|
2365
|
+
budget.maxInvocations) {
|
|
2216
2366
|
limitations.add(`exhausted ${budget.maxInvocations}-invocation path depth`);
|
|
2217
2367
|
continue;
|
|
2218
2368
|
}
|
|
2219
|
-
const visited = [path.root, ...path.steps.map((step) => step.next)].map(coverageNodeKey);
|
|
2220
|
-
if (step.questionWait === undefined &&
|
|
2221
|
-
visited.includes(coverageNodeKey(step.next))) {
|
|
2222
|
-
limitations.add('unsupported repeated-invocation path');
|
|
2223
|
-
continue;
|
|
2224
|
-
}
|
|
2225
2369
|
const successor = {
|
|
2226
2370
|
root: path.root,
|
|
2227
2371
|
drive: path.drive,
|
|
2372
|
+
witness: path.witness,
|
|
2228
2373
|
steps: [...path.steps, step],
|
|
2229
2374
|
};
|
|
2230
|
-
|
|
2375
|
+
const previousQuestion = step.questionWait === undefined
|
|
2376
|
+
? undefined
|
|
2377
|
+
: [...path.steps]
|
|
2378
|
+
.reverse()
|
|
2379
|
+
.find((previous) => previous.questionWait !== undefined &&
|
|
2380
|
+
coverageNodeKey(previous.next) ===
|
|
2381
|
+
coverageNodeKey(step.next));
|
|
2382
|
+
const repeatedQuestion = step.questionContext !== undefined &&
|
|
2383
|
+
previousQuestion?.questionContext !== undefined &&
|
|
2384
|
+
isDeepStrictEqual(step.questionContext.value, previousQuestion.questionContext.value);
|
|
2385
|
+
if (coverageNodeKey(step.next) === coverageNodeKey(target) &&
|
|
2386
|
+
step.interrupt === undefined &&
|
|
2387
|
+
!repeatedQuestion)
|
|
2231
2388
|
continuations.push(successor);
|
|
2232
2389
|
else
|
|
2233
2390
|
queue.push(successor);
|
|
@@ -2559,7 +2716,7 @@ function controllerCaptainProbeActor(machine, captain, result, gate, refs, capta
|
|
|
2559
2716
|
}
|
|
2560
2717
|
occurrence += 1;
|
|
2561
2718
|
return planned.output;
|
|
2562
|
-
}, () => null,
|
|
2719
|
+
}, () => null, (transition) => {
|
|
2563
2720
|
if (controllerResultConsumed &&
|
|
2564
2721
|
controllerDirectTransitionTargets === undefined &&
|
|
2565
2722
|
transition.sourceId === resolvedStateNode(machine, captain.ref)?.id) {
|
|
@@ -2596,7 +2753,7 @@ function captainProbeActor(machine, captain, result, gate, refs, captains, playb
|
|
|
2596
2753
|
return {
|
|
2597
2754
|
actor: makeActor(machine, result instanceof Error
|
|
2598
2755
|
? throwingScript(captain.binding.sourceItem, gate)
|
|
2599
|
-
: onceScript(captain.binding.sourceItem, result, gate), () => null
|
|
2756
|
+
: onceScript(captain.binding.sourceItem, result, gate), () => null),
|
|
2600
2757
|
event: drive.event,
|
|
2601
2758
|
};
|
|
2602
2759
|
}
|
|
@@ -2634,7 +2791,7 @@ function captainProbeActor(machine, captain, result, gate, refs, captains, playb
|
|
|
2634
2791
|
}
|
|
2635
2792
|
childUsed = true;
|
|
2636
2793
|
return predecessor.childOutput;
|
|
2637
|
-
}
|
|
2794
|
+
});
|
|
2638
2795
|
return {
|
|
2639
2796
|
actor,
|
|
2640
2797
|
event: drive.event,
|
|
@@ -2703,7 +2860,7 @@ async function probePlaybookOutcome(machine, playbook, refs, captains, outcome,
|
|
|
2703
2860
|
else if (!result.entered)
|
|
2704
2861
|
findings.push(`${label} has no reachable entry under probing (dead or unsupported entry path)`);
|
|
2705
2862
|
else if (result.limitation === undefined && !satisfiable)
|
|
2706
|
-
findings.push(`${label}
|
|
2863
|
+
findings.push(`${label} remains unverified after bounded probing`);
|
|
2707
2864
|
else if (satisfiable)
|
|
2708
2865
|
findings.push(`${label} did not reach ${target.stableId}`);
|
|
2709
2866
|
if (result.limitation !== undefined)
|
|
@@ -2779,10 +2936,25 @@ async function probeNonPreemptiveActor(machine, captain, refs, captains, playboo
|
|
|
2779
2936
|
const target = targetName === undefined
|
|
2780
2937
|
? undefined
|
|
2781
2938
|
: stateRefForTarget(refs, targetName, captain.ref);
|
|
2782
|
-
if (target === undefined ||
|
|
2939
|
+
if (target === undefined ||
|
|
2940
|
+
(sameStateRef(target, captain.ref) &&
|
|
2941
|
+
(typeof arm !== 'object' ||
|
|
2942
|
+
arm === null ||
|
|
2943
|
+
!('reenter' in arm) ||
|
|
2944
|
+
arm.reenter !== true)))
|
|
2783
2945
|
return false;
|
|
2946
|
+
const before = actor.coverageTransitions.length;
|
|
2784
2947
|
pending.complete(outputs[0]);
|
|
2785
|
-
if (!(await settle(actor, atState(target)
|
|
2948
|
+
if (!(await settle(actor, (snapshot) => atState(target)(snapshot) &&
|
|
2949
|
+
(!sameStateRef(target, captain.ref) ||
|
|
2950
|
+
actor.coverageTransitions
|
|
2951
|
+
.slice(before)
|
|
2952
|
+
.some((transition) => transition.sourceId ===
|
|
2953
|
+
resolvedStateNode(machine, captain.ref)?.id &&
|
|
2954
|
+
transition.armIndex === index &&
|
|
2955
|
+
transition.reenter &&
|
|
2956
|
+
transition.event?.type ===
|
|
2957
|
+
invocationEvent(machine, captain, 'done').type)), PARALLEL_SETTLE_MS)))
|
|
2786
2958
|
return false;
|
|
2787
2959
|
if (key !== NEEDS_BOSS_REPLY)
|
|
2788
2960
|
return true;
|
|
@@ -2846,7 +3018,12 @@ async function probeNonPreemptiveActor(machine, captain, refs, captains, playboo
|
|
|
2846
3018
|
const target = targetName === undefined
|
|
2847
3019
|
? undefined
|
|
2848
3020
|
: stateRefForTarget(refs, targetName, captain.ref);
|
|
2849
|
-
if (target === undefined ||
|
|
3021
|
+
if (target === undefined ||
|
|
3022
|
+
(sameStateRef(target, captain.ref) &&
|
|
3023
|
+
(typeof arm !== 'object' ||
|
|
3024
|
+
arm === null ||
|
|
3025
|
+
!('reenter' in arm) ||
|
|
3026
|
+
arm.reenter !== true))) {
|
|
2850
3027
|
findings.push(`${label}: ${outcome} arm ${index} has no distinct observable target`);
|
|
2851
3028
|
continue;
|
|
2852
3029
|
}
|
|
@@ -2854,8 +3031,18 @@ async function probeNonPreemptiveActor(machine, captain, refs, captains, playboo
|
|
|
2854
3031
|
const outputs = coverageArmResults(machine, node, outcome, index, actor.getSnapshot().context, pending.input, candidates, undefined, undefined, true, true);
|
|
2855
3032
|
if (outputs.length === 0)
|
|
2856
3033
|
return false;
|
|
3034
|
+
const before = actor.coverageTransitions.length;
|
|
2857
3035
|
pending.complete(outputs[0]);
|
|
2858
|
-
return await settle(actor, atState(target)
|
|
3036
|
+
return await settle(actor, (snapshot) => atState(target)(snapshot) &&
|
|
3037
|
+
(!sameStateRef(target, captain.ref) ||
|
|
3038
|
+
actor.coverageTransitions
|
|
3039
|
+
.slice(before)
|
|
3040
|
+
.some((transition) => transition.sourceId ===
|
|
3041
|
+
resolvedStateNode(machine, captain.ref)?.id &&
|
|
3042
|
+
transition.armIndex === index &&
|
|
3043
|
+
transition.reenter &&
|
|
3044
|
+
transition.event?.type ===
|
|
3045
|
+
invocationEvent(machine, captain, outcome === 'onDone' ? 'done' : 'error').type)), PARALLEL_SETTLE_MS);
|
|
2859
3046
|
});
|
|
2860
3047
|
if (!result.covered)
|
|
2861
3048
|
findings.push(`${label}: ${outcome} arm ${index} remains unproved: ${detail(result)}`);
|
|
@@ -2887,7 +3074,7 @@ async function probeParallelQuestions(machine, parallel, refs, captains, interru
|
|
|
2887
3074
|
return [];
|
|
2888
3075
|
const drive = interruptDriveForRef(machine, refs, parallel, parallel.stableId, interruptValues);
|
|
2889
3076
|
const { script, calls } = scriptedOutputs(plans);
|
|
2890
|
-
const actor = makeActor(machine, script, () => null
|
|
3077
|
+
const actor = makeActor(machine, script, () => null);
|
|
2891
3078
|
actor.send(drive.event);
|
|
2892
3079
|
const parked = await settle(actor, (snapshot) => plans.every(({ wait }) => atState(wait)(snapshot)), PARALLEL_QUESTION_SETTLE_MS);
|
|
2893
3080
|
if (!parked) {
|
|
@@ -2975,7 +3162,7 @@ async function probeParallelJoins(machine, parallel, refs, captains, interruptVa
|
|
|
2975
3162
|
output: combination[index],
|
|
2976
3163
|
}));
|
|
2977
3164
|
const { script, calls } = scriptedOutputs(entries);
|
|
2978
|
-
const actor = makeActor(machine, script, () => null
|
|
3165
|
+
const actor = makeActor(machine, script, () => null);
|
|
2979
3166
|
actor.send(drive.event);
|
|
2980
3167
|
exercised = await settle(actor, (snapshot) => sameStateRef(target, parallel)
|
|
2981
3168
|
? branches.every((captain) => callCount(calls, captain) >= 2) &&
|
|
@@ -3146,6 +3333,11 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
3146
3333
|
/** Conformance suites replay only pending literal bindings; coverage stays separate. */
|
|
3147
3334
|
export async function checkGearsFsmConformanceAsync(gears, fsmModule, options = {}) {
|
|
3148
3335
|
options = { ...options, coverage: resolveCoverageBudget(options.coverage) };
|
|
3336
|
+
if (options.machineInput !== undefined)
|
|
3337
|
+
options = {
|
|
3338
|
+
...options,
|
|
3339
|
+
machineInput: snapshotCallerMachineInput(options.machineInput),
|
|
3340
|
+
};
|
|
3149
3341
|
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, { concurrentRoleSets: findConcurrentRoleSets(fsmModule), ...options });
|
|
3150
3342
|
options.signal?.throwIfAborted();
|
|
3151
3343
|
return findings.length > 0 || !literalChecks.pending()
|
|
@@ -3155,6 +3347,11 @@ export async function checkGearsFsmConformanceAsync(gears, fsmModule, options =
|
|
|
3155
3347
|
/** One bounded replay owns transition coverage and reached literal-child proof. */
|
|
3156
3348
|
export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
3157
3349
|
options = { ...options, coverage: resolveCoverageBudget(options.coverage) };
|
|
3350
|
+
if (options.machineInput !== undefined)
|
|
3351
|
+
options = {
|
|
3352
|
+
...options,
|
|
3353
|
+
machineInput: snapshotCallerMachineInput(options.machineInput),
|
|
3354
|
+
};
|
|
3158
3355
|
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, {
|
|
3159
3356
|
concurrentRoleSets: findConcurrentRoleSets(fsmModule),
|
|
3160
3357
|
...options,
|
|
@@ -3166,12 +3363,26 @@ export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
|
3166
3363
|
}
|
|
3167
3364
|
async function fsmCoverage(fsmModule, opts = {}, literalChecks, literalOnly = false) {
|
|
3168
3365
|
const coverage = resolveCoverageBudget(opts.coverage);
|
|
3366
|
+
const machineInput = opts.machineInput === undefined
|
|
3367
|
+
? undefined
|
|
3368
|
+
: snapshotCallerMachineInput(opts.machineInput);
|
|
3169
3369
|
opts.signal?.throwIfAborted();
|
|
3170
3370
|
if (opts.timeoutMs !== undefined &&
|
|
3171
3371
|
(!Number.isFinite(opts.timeoutMs) || opts.timeoutMs <= 0))
|
|
3172
3372
|
throw new RangeError('FSM coverage timeout must be a positive finite number');
|
|
3173
3373
|
const started = performance.now();
|
|
3374
|
+
let witnesses;
|
|
3375
|
+
try {
|
|
3376
|
+
witnesses = readCoverageWitnesses(fsmModule);
|
|
3377
|
+
}
|
|
3378
|
+
catch (error) {
|
|
3379
|
+
return [
|
|
3380
|
+
`${error instanceof Error && error.name === 'UnverifiedCoverageWitnessInput' ? 'unverified: public coverageWitnesses' : 'artifact: invalid public coverageWitnesses'}: ${error instanceof Error ? error.message : String(error)}`,
|
|
3381
|
+
];
|
|
3382
|
+
}
|
|
3174
3383
|
const run = {
|
|
3384
|
+
...(machineInput === undefined ? {} : { machineInput }),
|
|
3385
|
+
witnesses,
|
|
3175
3386
|
coverage,
|
|
3176
3387
|
literalChecks,
|
|
3177
3388
|
signal: opts.signal,
|
|
@@ -3217,6 +3428,7 @@ async function reachedLiteralContexts(fsmModule, sourceText, checks) {
|
|
|
3217
3428
|
const refs = stateRefs(machine.config), captains = captainRefs(machine.config), playbooks = playbookRefs(machine.config);
|
|
3218
3429
|
const candidates = [
|
|
3219
3430
|
...identifierLiterals(sourceText),
|
|
3431
|
+
...absolutePathCandidates(sourceText),
|
|
3220
3432
|
...numericLiterals(sourceText),
|
|
3221
3433
|
];
|
|
3222
3434
|
for (const playbook of playbooks) {
|
|
@@ -3238,6 +3450,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3238
3450
|
const captainByRef = new Map(captains.map((captain) => [stateRefKey(captain.ref), captain]));
|
|
3239
3451
|
const sourceCandidates = [
|
|
3240
3452
|
...identifierLiterals(sourceText),
|
|
3453
|
+
...absolutePathCandidates(sourceText),
|
|
3241
3454
|
...numericLiterals(sourceText),
|
|
3242
3455
|
];
|
|
3243
3456
|
const isController = isControllerMachine(config);
|
|
@@ -3338,16 +3551,19 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3338
3551
|
? (target?.stableId ?? arm.target)
|
|
3339
3552
|
: captainPublicStateId(targetCaptain);
|
|
3340
3553
|
if (target === undefined) {
|
|
3341
|
-
findings.push(`${INTERRUPT_EVENT} target ${arm.target}
|
|
3554
|
+
findings.push(`${INTERRUPT_EVENT} target ${arm.target} remains unverified after actual public interrupt replay`);
|
|
3342
3555
|
continue;
|
|
3343
3556
|
}
|
|
3344
3557
|
const drive = interruptDriveForRef(machine, refs, target, targetId, sourceCandidates, armIndex);
|
|
3345
3558
|
if (!drive.satisfiable) {
|
|
3346
3559
|
if (!isController &&
|
|
3347
|
-
targetCaptain !== undefined &&
|
|
3348
|
-
|
|
3560
|
+
((targetCaptain !== undefined &&
|
|
3561
|
+
targetCaptain.binding.actor !== 'script') ||
|
|
3562
|
+
targetPlaybook !== undefined)) {
|
|
3349
3563
|
const guard = orderedArmPredicate(machine, transitionArms((machine.config.on ?? {})[INTERRUPT_EVENT]), armIndex);
|
|
3350
|
-
const reached = await searchCoverageEntry(machine,
|
|
3564
|
+
const reached = await searchCoverageEntry(machine, targetCaptain !== undefined
|
|
3565
|
+
? { kind: 'acting', value: targetCaptain }
|
|
3566
|
+
: { kind: 'child', value: targetPlaybook }, refs, captains, playbooks, sourceCandidates, async (actor) => {
|
|
3351
3567
|
try {
|
|
3352
3568
|
if (guard === undefined ||
|
|
3353
3569
|
!guard.run({
|
|
@@ -3382,15 +3598,22 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3382
3598
|
continue;
|
|
3383
3599
|
}
|
|
3384
3600
|
}
|
|
3385
|
-
findings.push(`${INTERRUPT_EVENT} target ${arm.target}
|
|
3601
|
+
findings.push(`${INTERRUPT_EVENT} target ${arm.target} remains unverified after bounded context/event probing`);
|
|
3386
3602
|
continue;
|
|
3387
3603
|
}
|
|
3388
|
-
const actor = makeActor(machine, () => null, () => null
|
|
3604
|
+
const actor = makeActor(machine, () => null, () => null);
|
|
3605
|
+
const before = actor.coverageTransitions.length;
|
|
3389
3606
|
actor.send(drive.event);
|
|
3390
|
-
const entered = await settle(actor, atState(target))
|
|
3607
|
+
const entered = await settle(actor, (snapshot) => atState(target)(snapshot) &&
|
|
3608
|
+
actor.coverageTransitions
|
|
3609
|
+
.slice(before)
|
|
3610
|
+
.some((transition) => transition.root &&
|
|
3611
|
+
transition.armIndex === armIndex &&
|
|
3612
|
+
transition.event === drive.event &&
|
|
3613
|
+
transition.targetIds.includes(resolvedStateNode(machine, target)?.id ?? '')));
|
|
3391
3614
|
if (!entered &&
|
|
3392
3615
|
!(targetPlaybook !== undefined && actor.coverageErrors.length > 0)) {
|
|
3393
|
-
findings.push(`${INTERRUPT_EVENT} target ${arm.target}
|
|
3616
|
+
findings.push(`${INTERRUPT_EVENT} target ${arm.target} remains unverified after actual public interrupt replay`);
|
|
3394
3617
|
}
|
|
3395
3618
|
actor.stop();
|
|
3396
3619
|
}
|
|
@@ -3780,7 +4003,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3780
4003
|
reached.limitation !== undefined)
|
|
3781
4004
|
continue;
|
|
3782
4005
|
}
|
|
3783
|
-
findings.push(`state ${stateKey}: onDone arm ${index} (target ${onDoneArms[index]?.target ?? 'none'})
|
|
4006
|
+
findings.push(`state ${stateKey}: onDone arm ${index} (target ${onDoneArms[index]?.target ?? 'none'}) remains unverified after bounded probing`);
|
|
3784
4007
|
}
|
|
3785
4008
|
}
|
|
3786
4009
|
// Audit every onError arm under the real error-event identity. Guarded arms
|
|
@@ -3809,7 +4032,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3809
4032
|
if (guard === undefined)
|
|
3810
4033
|
continue;
|
|
3811
4034
|
if (!errorGuardSatisfiable(guard, errorEvent, forcedError, candidates, initialCoverageContext)) {
|
|
3812
|
-
findings.push(`state ${stateKey}: onError arm ${index} (target ${onErrorArms[index]?.target ?? 'none'})
|
|
4035
|
+
findings.push(`state ${stateKey}: onError arm ${index} (target ${onErrorArms[index]?.target ?? 'none'}) remains unverified after bounded probing`);
|
|
3813
4036
|
}
|
|
3814
4037
|
}
|
|
3815
4038
|
if (hasUnresolvableErrorGuard)
|
|
@@ -3956,4 +4179,171 @@ export async function emitFsmCoverageTest(opts) {
|
|
|
3956
4179
|
diagnostics: findings.map((finding) => `fsm coverage: ${finding}`),
|
|
3957
4180
|
};
|
|
3958
4181
|
}
|
|
4182
|
+
/** Filesystem examples are public input candidates, never private state patches. */
|
|
4183
|
+
function absolutePathCandidates(source) {
|
|
4184
|
+
const quoted = source.match(/'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"/g) ?? [];
|
|
4185
|
+
return [
|
|
4186
|
+
...new Set([
|
|
4187
|
+
process.platform === 'win32'
|
|
4188
|
+
? 'C:\\slc-verification\\task.md'
|
|
4189
|
+
: '/tmp/slc-verification/task.md',
|
|
4190
|
+
'/tmp/task.md',
|
|
4191
|
+
'/workspace/task.md',
|
|
4192
|
+
...quoted
|
|
4193
|
+
.map((item) => item.slice(1, -1))
|
|
4194
|
+
.filter((item) => /^(?:\/|[A-Za-z]:[\\/])/.test(item) && item.length < 512),
|
|
4195
|
+
]),
|
|
4196
|
+
];
|
|
4197
|
+
}
|
|
4198
|
+
const RESERVED_MACHINE_INPUT_FIELDS = new Set([
|
|
4199
|
+
'enabledPlaybooks',
|
|
4200
|
+
'stateId',
|
|
4201
|
+
'selfPlaybookId',
|
|
4202
|
+
'bossIntent',
|
|
4203
|
+
'hostCapabilities',
|
|
4204
|
+
'context',
|
|
4205
|
+
'snapshot',
|
|
4206
|
+
'roleBindings',
|
|
4207
|
+
'ports',
|
|
4208
|
+
'repository',
|
|
4209
|
+
'effectLedger',
|
|
4210
|
+
'authority',
|
|
4211
|
+
]);
|
|
4212
|
+
/** Caller-owned input is separate from an artifact's self-declared witnesses. */
|
|
4213
|
+
function snapshotCallerMachineInput(value) {
|
|
4214
|
+
let visits = 0;
|
|
4215
|
+
let bytes = 0;
|
|
4216
|
+
const active = new Set();
|
|
4217
|
+
const fail = () => {
|
|
4218
|
+
throw new TypeError('coverage.machineInput must be bounded plain JSON data without compiler-owned authority fields');
|
|
4219
|
+
};
|
|
4220
|
+
const copy = (item, depth) => {
|
|
4221
|
+
if (++visits > 4096 || depth > 32)
|
|
4222
|
+
return fail();
|
|
4223
|
+
if (typeof item === 'string') {
|
|
4224
|
+
bytes += Buffer.byteLength(item);
|
|
4225
|
+
if (bytes > 1048576)
|
|
4226
|
+
return fail();
|
|
4227
|
+
return item;
|
|
4228
|
+
}
|
|
4229
|
+
if (item === null || typeof item === 'boolean')
|
|
4230
|
+
return item;
|
|
4231
|
+
if (typeof item === 'number')
|
|
4232
|
+
return Number.isFinite(item) ? item : fail();
|
|
4233
|
+
if (typeof item !== 'object' || utilTypes.isProxy(item) || active.has(item))
|
|
4234
|
+
return fail();
|
|
4235
|
+
const array = Array.isArray(item);
|
|
4236
|
+
const prototype = Object.getPrototypeOf(item);
|
|
4237
|
+
if (array
|
|
4238
|
+
? prototype !== Array.prototype
|
|
4239
|
+
: prototype !== Object.prototype && prototype !== null)
|
|
4240
|
+
return fail();
|
|
4241
|
+
const keys = Reflect.ownKeys(item);
|
|
4242
|
+
if (keys.length > 4096 ||
|
|
4243
|
+
(array &&
|
|
4244
|
+
(item.length > 4095 ||
|
|
4245
|
+
keys.length !== item.length + 1)))
|
|
4246
|
+
return fail();
|
|
4247
|
+
const result = array ? [] : Object.create(prototype);
|
|
4248
|
+
active.add(item);
|
|
4249
|
+
for (const key of keys) {
|
|
4250
|
+
if (array && key === 'length')
|
|
4251
|
+
continue;
|
|
4252
|
+
if (typeof key !== 'string' ||
|
|
4253
|
+
(depth === 0 && RESERVED_MACHINE_INPUT_FIELDS.has(key)))
|
|
4254
|
+
return fail();
|
|
4255
|
+
if (array) {
|
|
4256
|
+
const index = Number(key);
|
|
4257
|
+
if (!Number.isSafeInteger(index) ||
|
|
4258
|
+
index < 0 ||
|
|
4259
|
+
String(index) !== key ||
|
|
4260
|
+
index >= item.length)
|
|
4261
|
+
return fail();
|
|
4262
|
+
}
|
|
4263
|
+
bytes += Buffer.byteLength(key);
|
|
4264
|
+
if (bytes > 1048576)
|
|
4265
|
+
return fail();
|
|
4266
|
+
const descriptor = Object.getOwnPropertyDescriptor(item, key);
|
|
4267
|
+
if (descriptor === undefined ||
|
|
4268
|
+
!('value' in descriptor) ||
|
|
4269
|
+
!descriptor.enumerable)
|
|
4270
|
+
return fail();
|
|
4271
|
+
Object.defineProperty(result, key, {
|
|
4272
|
+
value: copy(descriptor.value, depth + 1),
|
|
4273
|
+
enumerable: true,
|
|
4274
|
+
writable: true,
|
|
4275
|
+
configurable: true,
|
|
4276
|
+
});
|
|
4277
|
+
}
|
|
4278
|
+
active.delete(item);
|
|
4279
|
+
return result;
|
|
4280
|
+
};
|
|
4281
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4282
|
+
return fail();
|
|
4283
|
+
return copy(value, 0);
|
|
4284
|
+
}
|
|
4285
|
+
function readCoverageWitnesses(module) {
|
|
4286
|
+
if (!module ||
|
|
4287
|
+
typeof module !== 'object' ||
|
|
4288
|
+
!Object.hasOwn(module, 'coverageWitnesses'))
|
|
4289
|
+
return [];
|
|
4290
|
+
const raw = module.coverageWitnesses;
|
|
4291
|
+
const plain = (value) => !!value &&
|
|
4292
|
+
typeof value === 'object' &&
|
|
4293
|
+
!Array.isArray(value) &&
|
|
4294
|
+
[Object.prototype, null].includes(Object.getPrototypeOf(value));
|
|
4295
|
+
const jsonSafe = (value, seen = new Set()) => {
|
|
4296
|
+
if (value === null ||
|
|
4297
|
+
typeof value === 'string' ||
|
|
4298
|
+
typeof value === 'boolean')
|
|
4299
|
+
return true;
|
|
4300
|
+
if (typeof value === 'number')
|
|
4301
|
+
return Number.isFinite(value);
|
|
4302
|
+
if (!value || typeof value !== 'object' || seen.has(value))
|
|
4303
|
+
return false;
|
|
4304
|
+
if (!Array.isArray(value) && !plain(value))
|
|
4305
|
+
return false;
|
|
4306
|
+
seen.add(value);
|
|
4307
|
+
const valid = Reflect.ownKeys(value).every((key) => {
|
|
4308
|
+
if (Array.isArray(value) && key === 'length')
|
|
4309
|
+
return true;
|
|
4310
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
4311
|
+
return (typeof key === 'string' &&
|
|
4312
|
+
!!descriptor &&
|
|
4313
|
+
'value' in descriptor &&
|
|
4314
|
+
jsonSafe(descriptor.value, seen));
|
|
4315
|
+
});
|
|
4316
|
+
seen.delete(value);
|
|
4317
|
+
return valid;
|
|
4318
|
+
};
|
|
4319
|
+
if (!plain(raw) ||
|
|
4320
|
+
!jsonSafe(raw) ||
|
|
4321
|
+
raw.schema !== 'sublang.slc.coverage-witnesses.v1' ||
|
|
4322
|
+
Object.keys(raw).some((key) => !['schema', 'entries'].includes(key)) ||
|
|
4323
|
+
!Array.isArray(raw.entries) ||
|
|
4324
|
+
raw.entries.length > 64)
|
|
4325
|
+
throw new Error('expected JSON schema and at most 64 entries');
|
|
4326
|
+
for (const entry of raw.entries) {
|
|
4327
|
+
if (plain(entry) &&
|
|
4328
|
+
plain(entry.input) &&
|
|
4329
|
+
Object.keys(entry.input).some((key) => RESERVED_MACHINE_INPUT_FIELDS.has(key)))
|
|
4330
|
+
throw new Error('startup options must not override compiler-owned host authority or private runtime state');
|
|
4331
|
+
if (!plain(entry) ||
|
|
4332
|
+
Object.keys(entry).some((key) => !['input', 'events'].includes(key)) ||
|
|
4333
|
+
(entry.input !== undefined && !plain(entry.input)) ||
|
|
4334
|
+
!Array.isArray(entry.events) ||
|
|
4335
|
+
entry.events.length > 64 ||
|
|
4336
|
+
entry.events.some((event) => !plain(event) ||
|
|
4337
|
+
typeof event.type !== 'string' ||
|
|
4338
|
+
!event.type ||
|
|
4339
|
+
event.type.startsWith('xstate.')))
|
|
4340
|
+
throw new Error('only public input records and public event sequences are allowed');
|
|
4341
|
+
if (plain(entry.input) && Object.keys(entry.input).length) {
|
|
4342
|
+
const error = new Error('nonempty witness startup options require an independent Source-derived validation contract; public events-only replay remains available');
|
|
4343
|
+
error.name = 'UnverifiedCoverageWitnessInput';
|
|
4344
|
+
throw error;
|
|
4345
|
+
}
|
|
4346
|
+
}
|
|
4347
|
+
return raw.entries;
|
|
4348
|
+
}
|
|
3959
4349
|
//# sourceMappingURL=verify-coverage.js.map
|