eutaxy 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -9
- package/dist/bin.mjs +2 -2
- package/dist/cli-DpeAhtU5.mjs +2 -0
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cloudflare.d.mts +1 -1
- package/dist/cloudflare.mjs +1 -1
- package/dist/{combinators-B7tV5fM_.d.mts → combinators-Bsd9HKtw.d.mts} +8 -2
- package/dist/combinators-Bsd9HKtw.d.mts.map +1 -0
- package/dist/{combinators-N4LmG4p4.mjs → combinators-CVjxodAJ.mjs} +3 -2
- package/dist/combinators-CVjxodAJ.mjs.map +1 -0
- package/dist/{explore-DhfREiX9.d.mts → explore-Rwe1PPqX.d.mts} +8 -1
- package/dist/explore-Rwe1PPqX.d.mts.map +1 -0
- package/dist/index.d.mts +6 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/spec.d.mts +1 -1
- package/dist/spec.mjs +1 -1
- package/dist/{src-DzpZxvQi.mjs → src-BZtuuu_j.mjs} +354 -70
- package/dist/src-BZtuuu_j.mjs.map +1 -0
- package/dist/{src-CMoBPQuE.mjs → src-BzZU6eGF.mjs} +2771 -2471
- package/dist/src-BzZU6eGF.mjs.map +1 -0
- package/package.json +3 -4
- package/dist/cli-CL28yx3H.mjs +0 -2
- package/dist/combinators-B7tV5fM_.d.mts.map +0 -1
- package/dist/combinators-N4LmG4p4.mjs.map +0 -1
- package/dist/explore-DhfREiX9.d.mts.map +0 -1
- package/dist/src-CMoBPQuE.mjs.map +0 -1
- package/dist/src-DzpZxvQi.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { C as nextU32, E as canonicalJson, S as nextInt, w as seedPrng, x as nextFloat } from "./src-BO7I3f-1.mjs";
|
|
2
|
-
import { n as isSpec } from "./combinators-
|
|
2
|
+
import { n as isSpec } from "./combinators-CVjxodAJ.mjs";
|
|
3
3
|
// packages/core/src/verdict.ts
|
|
4
4
|
/** One line per verdict, for error messages; full rendering lives in `report`. */
|
|
5
5
|
function describeVerdict(v) {
|
|
@@ -22,6 +22,7 @@ function describeType(t) {
|
|
|
22
22
|
case "literal": return typeof t.value === "string" ? JSON.stringify(t.value) : String(t.value);
|
|
23
23
|
case "record": return t.name ?? `{ ${t.fields.map((f) => `${f.name}: ${describeType(f.type)}`).join("; ")} }`;
|
|
24
24
|
case "union": return t.members.map(describeType).join(" | ");
|
|
25
|
+
case "array": return t.element.kind === "union" ? `(${describeType(t.element)})[]` : `${describeType(t.element)}[]`;
|
|
25
26
|
case "unknown": return t.text;
|
|
26
27
|
}
|
|
27
28
|
}
|
|
@@ -367,6 +368,23 @@ function renderAt(value, seen) {
|
|
|
367
368
|
function same(a, b) {
|
|
368
369
|
return typeof a === typeof b && render(a) === render(b);
|
|
369
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* A deep copy of plain data: arrays and records (plain objects); anything
|
|
373
|
+
* else (a Date the simulator passed, a class instance) is kept as it is.
|
|
374
|
+
* Each evaluation of a property gets its own, so code under test that
|
|
375
|
+
* mutates an input (`xs.sort()`) changes neither the printed counterexample
|
|
376
|
+
* nor the candidates built from it, and no two places in an input share an
|
|
377
|
+
* object, as their printed literals do not.
|
|
378
|
+
*/
|
|
379
|
+
function copy(v) {
|
|
380
|
+
if (Array.isArray(v)) return v.map(copy);
|
|
381
|
+
if (v !== null && typeof v === "object") {
|
|
382
|
+
const proto = Object.getPrototypeOf(v);
|
|
383
|
+
if (proto !== Object.prototype && proto !== null) return v;
|
|
384
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k, copy(x)]));
|
|
385
|
+
}
|
|
386
|
+
return v;
|
|
387
|
+
}
|
|
370
388
|
// packages/prover/src/generate.ts
|
|
371
389
|
/**
|
|
372
390
|
* Inputs for the `TESTED` rung: values drawn from a binder's type, steered
|
|
@@ -406,6 +424,10 @@ function integerBound(e, side) {
|
|
|
406
424
|
}
|
|
407
425
|
return BigInt(text) + (e.inclusive ? 0n : side === "lower" ? 1n : -1n);
|
|
408
426
|
}
|
|
427
|
+
/** A finite integral endpoint's value, exact: underscores and the `n` suffix dropped. */
|
|
428
|
+
function endpointBigInt(value) {
|
|
429
|
+
return BigInt(value.replace(/_/g, "").replace(/n$/, ""));
|
|
430
|
+
}
|
|
409
431
|
/**
|
|
410
432
|
* The closed integer interval a hint admits: within what a double holds
|
|
411
433
|
* exactly for `number`; for `bigint`, the hint's ends, an unhinted side
|
|
@@ -461,6 +483,18 @@ function pick(items, state) {
|
|
|
461
483
|
* properties fail at boundaries and small cases far more often than deep in
|
|
462
484
|
* the range, some are medium or large, and a few are the range's edges.
|
|
463
485
|
*/
|
|
486
|
+
/** An integer range's edges, as the random draws pick from them (repeats kept, so draws stay as they were). */
|
|
487
|
+
function integerEdgeCandidates(lo, hi) {
|
|
488
|
+
return [
|
|
489
|
+
lo,
|
|
490
|
+
hi,
|
|
491
|
+
0n,
|
|
492
|
+
1n,
|
|
493
|
+
-1n,
|
|
494
|
+
lo + 1n,
|
|
495
|
+
hi - 1n
|
|
496
|
+
].filter((v) => v >= lo && v <= hi);
|
|
497
|
+
}
|
|
464
498
|
function drawInteger(name, kind, hint, state) {
|
|
465
499
|
const range = integerRange(kind, hint);
|
|
466
500
|
if (!range) throw new CannotGenerate("gave_up", kind === "bigint" ? `no integer lies inside the precondition's bounds on ${name}` : `no integer lies inside the precondition's bounds on ${name} within ±2^53, which is as far as draws of number go`);
|
|
@@ -471,15 +505,7 @@ function drawInteger(name, kind, hint, state) {
|
|
|
471
505
|
const h = min(hi, z);
|
|
472
506
|
return l <= h ? [l, h] : void 0;
|
|
473
507
|
};
|
|
474
|
-
if (cls < 5) return pick(
|
|
475
|
-
lo,
|
|
476
|
-
hi,
|
|
477
|
-
0n,
|
|
478
|
-
1n,
|
|
479
|
-
-1n,
|
|
480
|
-
lo + 1n,
|
|
481
|
-
hi - 1n
|
|
482
|
-
].filter((v) => v >= lo && v <= hi), s);
|
|
508
|
+
if (cls < 5) return pick(integerEdgeCandidates(lo, hi), s);
|
|
483
509
|
const [l, h] = (cls < 55 ? within(-16n, 16n) : cls < 80 ? within(-(1n << 16n), 1n << 16n) : cls < 95 ? within(-(1n << 31n), 1n << 31n) : void 0) ?? [lo, hi];
|
|
484
510
|
return uniformBigInt(l, h, s);
|
|
485
511
|
}
|
|
@@ -505,24 +531,29 @@ function withinNumberHint(hint, v) {
|
|
|
505
531
|
}
|
|
506
532
|
return true;
|
|
507
533
|
}
|
|
508
|
-
|
|
534
|
+
/** A double hint's edges, as the random draws pick from them. */
|
|
535
|
+
function doubleEdgeCandidates(hint) {
|
|
509
536
|
const { lo, hi, guarded } = numberRange(hint);
|
|
537
|
+
return [
|
|
538
|
+
0,
|
|
539
|
+
-0,
|
|
540
|
+
1,
|
|
541
|
+
-1,
|
|
542
|
+
.5,
|
|
543
|
+
Number.MIN_VALUE,
|
|
544
|
+
Number.EPSILON,
|
|
545
|
+
Number.MAX_VALUE,
|
|
546
|
+
-Number.MAX_VALUE,
|
|
547
|
+
Number.POSITIVE_INFINITY,
|
|
548
|
+
Number.NEGATIVE_INFINITY,
|
|
549
|
+
...guarded ? [lo, hi] : [NaN]
|
|
550
|
+
].filter((v) => withinNumberHint(hint, v));
|
|
551
|
+
}
|
|
552
|
+
function drawNumber(hint, state) {
|
|
553
|
+
const { lo, hi } = numberRange(hint);
|
|
510
554
|
const [cls, s0] = nextInt(state, 100);
|
|
511
555
|
if (cls < 8) {
|
|
512
|
-
const edges =
|
|
513
|
-
0,
|
|
514
|
-
-0,
|
|
515
|
-
1,
|
|
516
|
-
-1,
|
|
517
|
-
.5,
|
|
518
|
-
Number.MIN_VALUE,
|
|
519
|
-
Number.EPSILON,
|
|
520
|
-
Number.MAX_VALUE,
|
|
521
|
-
-Number.MAX_VALUE,
|
|
522
|
-
Number.POSITIVE_INFINITY,
|
|
523
|
-
Number.NEGATIVE_INFINITY,
|
|
524
|
-
...guarded ? [lo, hi] : [NaN]
|
|
525
|
-
].filter((v) => withinNumberHint(hint, v));
|
|
556
|
+
const edges = doubleEdgeCandidates(hint);
|
|
526
557
|
if (edges.length > 0) return pick(edges, s0);
|
|
527
558
|
}
|
|
528
559
|
if (cls < 35) {
|
|
@@ -564,6 +595,8 @@ const stringEdges = [
|
|
|
564
595
|
"😀",
|
|
565
596
|
"a".repeat(100)
|
|
566
597
|
];
|
|
598
|
+
/** The longest string sampled over a regex's own characters, and the longest edge a regex is tried on. */
|
|
599
|
+
const regexSampleLength = 12;
|
|
567
600
|
/**
|
|
568
601
|
* The characters a regex names: literals, the ranges and escapes of its
|
|
569
602
|
* classes. Strings drawn from them match the pattern far more often than
|
|
@@ -645,6 +678,131 @@ function drawString(hint, state) {
|
|
|
645
678
|
}
|
|
646
679
|
throw new CannotGenerate("gave_up", `no string matching /${g.pattern}/${g.flags} was found in 64 draws over its characters`);
|
|
647
680
|
}
|
|
681
|
+
/** The most shrink candidates one array offers at a step; the shrinker evaluates 500 in all. */
|
|
682
|
+
const shrinkCandidateLimit = 256;
|
|
683
|
+
/** The most edges a record type has; random draws cover its other combinations. */
|
|
684
|
+
const recordEdgeLimit = 64;
|
|
685
|
+
/** Without repeats, in one pass, as `same` compares: 0 and -0 stay apart, two empty arrays do not. */
|
|
686
|
+
function distinct(values) {
|
|
687
|
+
const seen = /* @__PURE__ */ new Set();
|
|
688
|
+
return values.filter((v) => {
|
|
689
|
+
const key = `${typeof v}:${render(v)}`;
|
|
690
|
+
if (seen.has(key)) return false;
|
|
691
|
+
seen.add(key);
|
|
692
|
+
return true;
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
function integerEdges(kind, hint) {
|
|
696
|
+
const range = integerRange(kind, hint);
|
|
697
|
+
return range ? distinct(integerEdgeCandidates(range.lo, range.hi)) : [];
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* How many combinations of these edge lists to take side by side: the
|
|
701
|
+
* longest list's length, twice over when there are two or more lists,
|
|
702
|
+
* since `combined` walks them once in step (equal edges meet, as
|
|
703
|
+
* `Infinity - Infinity` needs) and once rotated (list `k` starting `k`
|
|
704
|
+
* places in, so lists of one type also differ).
|
|
705
|
+
*/
|
|
706
|
+
function combinations(lists) {
|
|
707
|
+
const longest = Math.max(0, ...lists.map((l) => l.length));
|
|
708
|
+
return lists.length > 1 ? 2 * longest : longest;
|
|
709
|
+
}
|
|
710
|
+
/** List `k`'s value in the `i`-th combination. */
|
|
711
|
+
function combined(lists, k, i) {
|
|
712
|
+
const longest = Math.max(...lists.map((l) => l.length));
|
|
713
|
+
const own = lists[k];
|
|
714
|
+
const offset = i < longest ? 0 : k;
|
|
715
|
+
return own[(i % longest + offset) % own.length];
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* The values of a type, within the hint, that properties fail on far more
|
|
719
|
+
* often than elsewhere: the bounds, zero and one, the double specials (NaN,
|
|
720
|
+
* the infinities, -0), the empty string, both booleans, every member of a
|
|
721
|
+
* union, and records built field by field from those. The `TESTED` rung
|
|
722
|
+
* tries every one before any random draw, so a claim false on one value
|
|
723
|
+
* is found under every seed; a claim false only on a combination of edges
|
|
724
|
+
* across binders or fields is found where the rotation below pairs them,
|
|
725
|
+
* and otherwise rests on the random draws. A type with none (a string
|
|
726
|
+
* whose regex no edge matches) gives none.
|
|
727
|
+
*/
|
|
728
|
+
function edgesOf(type, hint) {
|
|
729
|
+
switch (type.kind) {
|
|
730
|
+
case "boolean": return [false, true];
|
|
731
|
+
case "number":
|
|
732
|
+
if (hint?.integer) return integerEdges("number", hint).flatMap((v) => v === 0n ? [0, -0] : [Number(v)]);
|
|
733
|
+
return distinct(doubleEdgeCandidates(hint));
|
|
734
|
+
case "bigint": return integerEdges("bigint", hint);
|
|
735
|
+
case "string": return stringEdges.filter((v) => hint?.regex === void 0 || v.length <= regexSampleLength && matchesRegex(hint, v));
|
|
736
|
+
case "literal": return [type.value];
|
|
737
|
+
case "null": return [null];
|
|
738
|
+
case "undefined": return [void 0];
|
|
739
|
+
case "union": return distinct(type.members.flatMap((m) => edgesOf(m, void 0)));
|
|
740
|
+
case "record": {
|
|
741
|
+
const lists = type.fields.map((f) => edgesOf(f.type, void 0));
|
|
742
|
+
if (lists.some((l) => l.length === 0)) return [];
|
|
743
|
+
const out = [];
|
|
744
|
+
const seen = /* @__PURE__ */ new Set();
|
|
745
|
+
for (let i = 0; i < Math.max(1, combinations(lists)) && out.length < recordEdgeLimit; i++) {
|
|
746
|
+
const r = Object.fromEntries(type.fields.map((f, k) => [f.name, combined(lists, k, i)]));
|
|
747
|
+
const key = render(r);
|
|
748
|
+
if (seen.has(key)) continue;
|
|
749
|
+
seen.add(key);
|
|
750
|
+
out.push(r);
|
|
751
|
+
}
|
|
752
|
+
return out;
|
|
753
|
+
}
|
|
754
|
+
case "array": {
|
|
755
|
+
if (!drawable(type.element)) return [];
|
|
756
|
+
const element = edgesOf(type.element, void 0);
|
|
757
|
+
return [
|
|
758
|
+
[],
|
|
759
|
+
...element.map((e) => [e]),
|
|
760
|
+
...element.length > 0 ? [[element[0], element[0]]] : []
|
|
761
|
+
];
|
|
762
|
+
}
|
|
763
|
+
case "unknown": return [];
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
/** Each binder's edges, computed once for a property's whole edge phase. */
|
|
767
|
+
function edgeLists(binders) {
|
|
768
|
+
return binders.map((b) => edgesOf(b.type, b.hint));
|
|
769
|
+
}
|
|
770
|
+
/** How many edge assignments the binders' `edgeLists` give. */
|
|
771
|
+
function edgeAssignmentCount(edges) {
|
|
772
|
+
return combinations(edges);
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* The `i`-th edge assignment from the binders' `edgeLists`: the lists
|
|
776
|
+
* walked once in step and once rotated (binder `j` starting `j` places
|
|
777
|
+
* in), cycling, so each edge of each binder appears, equal edges meet and
|
|
778
|
+
* binders of one type also differ; a binder with no edges is drawn at
|
|
779
|
+
* random. Undefined from `edgeAssignmentCount` on.
|
|
780
|
+
*/
|
|
781
|
+
function edgeAssignment(binders, edges, i, state) {
|
|
782
|
+
if (i >= combinations(edges)) return void 0;
|
|
783
|
+
const values = [];
|
|
784
|
+
let s = state;
|
|
785
|
+
binders.forEach((b, j) => {
|
|
786
|
+
if (edges[j].length > 0) {
|
|
787
|
+
values.push(copy(combined(edges, j, i)));
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const [v, next] = generate(b, s);
|
|
791
|
+
s = next;
|
|
792
|
+
values.push(v);
|
|
793
|
+
});
|
|
794
|
+
return [values, s];
|
|
795
|
+
}
|
|
796
|
+
/** Whether every part of the type is one the rung draws (no `unknown` anywhere in it). */
|
|
797
|
+
function drawable(type) {
|
|
798
|
+
switch (type.kind) {
|
|
799
|
+
case "unknown": return false;
|
|
800
|
+
case "array": return drawable(type.element);
|
|
801
|
+
case "union": return type.members.every(drawable);
|
|
802
|
+
case "record": return type.fields.every((f) => drawable(f.type));
|
|
803
|
+
default: return true;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
648
806
|
/** A value of the type, within the hint (which applies to a top-level binder only). */
|
|
649
807
|
function generateOf(name, type, hint, state) {
|
|
650
808
|
switch (type.kind) {
|
|
@@ -684,6 +842,29 @@ function generateOf(name, type, hint, state) {
|
|
|
684
842
|
}
|
|
685
843
|
return [out, s];
|
|
686
844
|
}
|
|
845
|
+
case "array": {
|
|
846
|
+
if (!drawable(type.element)) throw new CannotGenerate("unsupported", `${name} has a type the rung cannot draw from: ${describeType(type)}`);
|
|
847
|
+
const [cls, s0] = nextInt(state, 100);
|
|
848
|
+
const [length, s1] = nextInt(s0, cls < 70 ? 5 : 17);
|
|
849
|
+
let s = s1;
|
|
850
|
+
const out = [];
|
|
851
|
+
for (let i = 0; i < length; i++) {
|
|
852
|
+
if (out.length > 0) {
|
|
853
|
+
const [repeat, s2] = nextInt(s, 4);
|
|
854
|
+
s = s2;
|
|
855
|
+
if (repeat === 0) {
|
|
856
|
+
const [v, s3] = pick(out, s);
|
|
857
|
+
s = s3;
|
|
858
|
+
out.push(copy(v));
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
const [v, next] = generateOf(`${name}[${i}]`, type.element, void 0, s);
|
|
863
|
+
s = next;
|
|
864
|
+
out.push(v);
|
|
865
|
+
}
|
|
866
|
+
return [out, s];
|
|
867
|
+
}
|
|
687
868
|
case "unknown": throw new CannotGenerate("unsupported", `${name} has a type the rung cannot draw from: ${describeType(type)}`);
|
|
688
869
|
}
|
|
689
870
|
}
|
|
@@ -740,6 +921,10 @@ function conforms(type, v) {
|
|
|
740
921
|
case "undefined": return v === void 0;
|
|
741
922
|
case "union": return type.members.some((m) => conforms(m, v));
|
|
742
923
|
case "record": return typeof v === "object" && v !== null && type.fields.every((f) => conforms(f.type, v[f.name]));
|
|
924
|
+
case "array":
|
|
925
|
+
if (!Array.isArray(v)) return false;
|
|
926
|
+
for (let i = 0; i < v.length; i++) if (!(i in v) || !conforms(type.element, v[i])) return false;
|
|
927
|
+
return true;
|
|
743
928
|
case "unknown": return true;
|
|
744
929
|
}
|
|
745
930
|
}
|
|
@@ -787,14 +972,19 @@ function shrinkCandidates(b, v) {
|
|
|
787
972
|
}
|
|
788
973
|
function candidatesOf(type, hint, v) {
|
|
789
974
|
const dedupe = (xs) => {
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
|
|
975
|
+
const keys = /* @__PURE__ */ new Set();
|
|
976
|
+
return xs.filter((x) => {
|
|
977
|
+
const key = `${typeof x}:${render(x)}`;
|
|
978
|
+
if (keys.has(key)) return false;
|
|
979
|
+
keys.add(key);
|
|
980
|
+
return true;
|
|
981
|
+
});
|
|
793
982
|
};
|
|
794
983
|
switch (type.kind) {
|
|
795
984
|
case "boolean": return [false];
|
|
796
985
|
case "number": {
|
|
797
986
|
if (typeof v !== "number") return [];
|
|
987
|
+
if (Object.is(v, -0)) return [0];
|
|
798
988
|
if (hint?.integer || Number.isInteger(v)) {
|
|
799
989
|
const range = integerRange("number", hint);
|
|
800
990
|
if (!Number.isInteger(v) || !range) return [];
|
|
@@ -840,6 +1030,23 @@ function candidatesOf(type, hint, v) {
|
|
|
840
1030
|
].join(""));
|
|
841
1031
|
return dedupe(out);
|
|
842
1032
|
}
|
|
1033
|
+
case "array": {
|
|
1034
|
+
if (!Array.isArray(v)) return [];
|
|
1035
|
+
const out = v.length > 0 ? [[]] : [];
|
|
1036
|
+
for (let i = 0; i < v.length; i++) out.push(v.filter((_, j) => j !== i));
|
|
1037
|
+
const keys = v.map((x) => `${typeof x}:${render(x)}`);
|
|
1038
|
+
for (let i = 0; i < v.length && out.length < shrinkCandidateLimit; i++) {
|
|
1039
|
+
const own = keys[i];
|
|
1040
|
+
const repeated = keys.some((k, j) => j !== i && k === own);
|
|
1041
|
+
for (const c of candidatesOf(type.element, void 0, v[i])) {
|
|
1042
|
+
if (out.length >= shrinkCandidateLimit) break;
|
|
1043
|
+
if (`${typeof c}:${render(c)}` === own) continue;
|
|
1044
|
+
out.push(v.map((x, j) => j === i ? c : x));
|
|
1045
|
+
if (repeated) out.push(v.map((x, j) => keys[j] === own ? copy(c) : x));
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return dedupe(out).slice(0, shrinkCandidateLimit);
|
|
1049
|
+
}
|
|
843
1050
|
case "literal":
|
|
844
1051
|
case "null":
|
|
845
1052
|
case "undefined":
|
|
@@ -881,12 +1088,12 @@ function candidatesOf(type, hint, v) {
|
|
|
881
1088
|
* function's own included, means the claim is not true there. A claim
|
|
882
1089
|
* that returns something other than a boolean is malformed.
|
|
883
1090
|
*/
|
|
884
|
-
function evaluate(spec, values) {
|
|
885
|
-
const
|
|
1091
|
+
function evaluate(spec, values, copied = false) {
|
|
1092
|
+
const fresh = () => copied ? copy(values) : values;
|
|
886
1093
|
if (spec.when) {
|
|
887
1094
|
let inside;
|
|
888
1095
|
try {
|
|
889
|
-
inside = spec.when(...
|
|
1096
|
+
inside = spec.when(...fresh());
|
|
890
1097
|
} catch (err) {
|
|
891
1098
|
return { malformed: `the precondition threw ${String(err)}` };
|
|
892
1099
|
}
|
|
@@ -895,7 +1102,7 @@ function evaluate(spec, values) {
|
|
|
895
1102
|
}
|
|
896
1103
|
let claim;
|
|
897
1104
|
try {
|
|
898
|
-
claim = spec.ensures(...
|
|
1105
|
+
claim = spec.ensures(...fresh());
|
|
899
1106
|
} catch (err) {
|
|
900
1107
|
return {
|
|
901
1108
|
outcome: "refuted",
|
|
@@ -987,7 +1194,8 @@ function shrinkRefutation(spec, binders, start, startEvaluation) {
|
|
|
987
1194
|
if (spent >= shrinkBudget) break;
|
|
988
1195
|
spent++;
|
|
989
1196
|
const trial = values.with(i, candidate);
|
|
990
|
-
|
|
1197
|
+
if (spec.sample && !inSample(spec, trial)) continue;
|
|
1198
|
+
const still = refutes(evaluate(spec, trial, true));
|
|
991
1199
|
if (still === void 0) continue;
|
|
992
1200
|
values = trial;
|
|
993
1201
|
error = still;
|
|
@@ -1008,6 +1216,14 @@ function refutes(e) {
|
|
|
1008
1216
|
if ("malformed" in e || e.outcome !== "refuted") return void 0;
|
|
1009
1217
|
return "error" in e && e.error !== void 0 ? { error: e.error } : {};
|
|
1010
1218
|
}
|
|
1219
|
+
/** Whether the spec's sample holds of the values (a sample that throws or answers other than true does not). */
|
|
1220
|
+
function inSample(spec, values) {
|
|
1221
|
+
try {
|
|
1222
|
+
return spec.sample?.(...copy(values)) === true;
|
|
1223
|
+
} catch {
|
|
1224
|
+
return false;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1011
1227
|
// packages/prover/src/tested.ts
|
|
1012
1228
|
/**
|
|
1013
1229
|
* The `TESTED` rung: a property evaluated on assignments drawn from its
|
|
@@ -1043,6 +1259,7 @@ function testedRung(input) {
|
|
|
1043
1259
|
let state = seedPrng(seed);
|
|
1044
1260
|
let held = 0;
|
|
1045
1261
|
let discarded = 0;
|
|
1262
|
+
let sampledOut = 0;
|
|
1046
1263
|
const seen = /* @__PURE__ */ new Set();
|
|
1047
1264
|
const counterexample = (values, error) => ({
|
|
1048
1265
|
binders: binders.map((b, i) => ({
|
|
@@ -1051,10 +1268,14 @@ function testedRung(input) {
|
|
|
1051
1268
|
})),
|
|
1052
1269
|
...error === void 0 ? {} : { error }
|
|
1053
1270
|
});
|
|
1054
|
-
|
|
1271
|
+
const edges = edgeLists(binders);
|
|
1272
|
+
const edgeTotal = edgeAssignmentCount(edges);
|
|
1273
|
+
const randomWanted = Math.ceil(wanted / 2);
|
|
1274
|
+
let randomHeld = 0;
|
|
1275
|
+
for (let draws = 0; draws < edgeTotal || (held < wanted || randomHeld < randomWanted) && draws < edgeTotal + wanted * 20; draws++) {
|
|
1055
1276
|
let values;
|
|
1056
1277
|
try {
|
|
1057
|
-
[values, state] = generateAssignment(binders, state);
|
|
1278
|
+
[values, state] = (draws < edgeTotal ? edgeAssignment(binders, edges, draws, state) : void 0) ?? generateAssignment(binders, state);
|
|
1058
1279
|
} catch (err) {
|
|
1059
1280
|
if (err instanceof CannotGenerate) return unknown(err.why, err.message);
|
|
1060
1281
|
throw err;
|
|
@@ -1062,7 +1283,20 @@ function testedRung(input) {
|
|
|
1062
1283
|
const key = values.map(render).join(", ");
|
|
1063
1284
|
if (seen.has(key)) continue;
|
|
1064
1285
|
seen.add(key);
|
|
1065
|
-
|
|
1286
|
+
if (spec.sample) {
|
|
1287
|
+
let inSample;
|
|
1288
|
+
try {
|
|
1289
|
+
inSample = spec.sample(...copy(values));
|
|
1290
|
+
} catch (err) {
|
|
1291
|
+
return unknown("unsupported", malformedReason(`the sample threw ${String(err)}`));
|
|
1292
|
+
}
|
|
1293
|
+
if (typeof inSample !== "boolean") return unknown("unsupported", malformedReason(`the sample returned ${render(inSample)}, not a boolean`));
|
|
1294
|
+
if (!inSample) {
|
|
1295
|
+
sampledOut++;
|
|
1296
|
+
continue;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
const result = evaluate(spec, values, true);
|
|
1066
1300
|
if ("malformed" in result) return unknown("unsupported", malformedReason(result.malformed));
|
|
1067
1301
|
if (result.outcome === "discarded") {
|
|
1068
1302
|
discarded++;
|
|
@@ -1079,20 +1313,35 @@ function testedRung(input) {
|
|
|
1079
1313
|
};
|
|
1080
1314
|
}
|
|
1081
1315
|
held++;
|
|
1316
|
+
if (draws >= edgeTotal) randomHeld++;
|
|
1082
1317
|
}
|
|
1083
|
-
if (held === 0) return unknown("gave_up", `all ${discarded} distinct generated inputs were outside the claim: its precondition admits too few of the parameter types to sample`);
|
|
1318
|
+
if (held === 0) return unknown("gave_up", sampledOut > 0 && discarded === 0 ? `all ${sampledOut} distinct generated inputs were outside the sample: it admits too few of the parameter types to draw` : `all ${discarded + sampledOut} distinct generated inputs were outside the claim or the sample: its precondition admits too few of the parameter types to sample`);
|
|
1084
1319
|
return {
|
|
1085
1320
|
...base,
|
|
1086
1321
|
kind: "TESTED",
|
|
1087
1322
|
inputs: held,
|
|
1088
1323
|
discarded,
|
|
1089
1324
|
seed: input.seed,
|
|
1090
|
-
assumptions: [
|
|
1325
|
+
assumptions: [
|
|
1326
|
+
`held on ${held} distinct input(s) generated from the parameter types with seed ${input.seed}; inputs never drawn are not covered`,
|
|
1327
|
+
`${fn.name} was called on generated inputs outside the simulator, so it is assumed pure`,
|
|
1328
|
+
...spec.sample ? [`drawn only where the sample holds${property.sample ? ` (${property.sample.body.replace(/\s+/g, " ").trim()})` : ""}; the claim itself is not limited to it`] : []
|
|
1329
|
+
]
|
|
1091
1330
|
};
|
|
1092
1331
|
}
|
|
1093
1332
|
// packages/prover/src/ladder.ts
|
|
1094
1333
|
/** One property through the ladder's rungs. */
|
|
1095
1334
|
function specLadder(input, options = {}) {
|
|
1335
|
+
if (options.checked === false) {
|
|
1336
|
+
if (!options.tested) throw new RangeError("a ladder without CHECKED needs the TESTED rung");
|
|
1337
|
+
return testedRung({
|
|
1338
|
+
module: input.module,
|
|
1339
|
+
fn: input.fn,
|
|
1340
|
+
property: input.property,
|
|
1341
|
+
spec: input.spec,
|
|
1342
|
+
...options.tested
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1096
1345
|
const checked = checkedRung(input);
|
|
1097
1346
|
if (checked.kind === "REFUTED" || options.tested === false || options.tested === void 0) return checked;
|
|
1098
1347
|
if (input.property.kind === "total") return checked;
|
|
@@ -1306,42 +1555,77 @@ function renderJson(verdict, specs = []) {
|
|
|
1306
1555
|
...specs.length > 0 ? { specs } : {}
|
|
1307
1556
|
});
|
|
1308
1557
|
}
|
|
1558
|
+
const specsHeader = "Specs (CHECKED means held on the inputs the simulator passed, TESTED on generated ones too; neither is a proof. PROVEN is one, by the named engine)";
|
|
1309
1559
|
/** Spec verdicts as text: one line each, a counterexample under a refutation. */
|
|
1310
1560
|
function renderSpecs(specs) {
|
|
1311
1561
|
if (specs.length === 0) return "";
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
out.push(` REFUTED ${what}: false ${where}${c.error ? `, which threw ${c.error}` : ""}`);
|
|
1335
|
-
if (c.binders.length > 0) out.push(` ${c.binders.map((b) => `${b.name} = ${b.value}`).join(", ")}`);
|
|
1336
|
-
out.push(` ${v.text.replace(/\s+/g, " ")}`);
|
|
1337
|
-
break;
|
|
1338
|
-
}
|
|
1339
|
-
case "UNKNOWN": out.push(` UNKNOWN ${what}: ${v.cause}: ${v.reason}`);
|
|
1340
|
-
}
|
|
1341
|
-
for (const a of v.assumptions) if (v.kind === "PROVEN" || a.startsWith("not PROVEN by ")) out.push(` ${a}`);
|
|
1562
|
+
return [specsHeader, ...specs.flatMap(specLines)].join("\n");
|
|
1563
|
+
}
|
|
1564
|
+
/** The order a report counts verdicts in: strongest evidence first, then what needs attention. */
|
|
1565
|
+
const verdictOrder = [
|
|
1566
|
+
"PROVEN",
|
|
1567
|
+
"TESTED",
|
|
1568
|
+
"CHECKED",
|
|
1569
|
+
"REFUTED",
|
|
1570
|
+
"CONFLICT",
|
|
1571
|
+
"UNKNOWN"
|
|
1572
|
+
];
|
|
1573
|
+
/**
|
|
1574
|
+
* `eutaxy report` as text: the spec verdicts grouped by module, in the
|
|
1575
|
+
* order given, and one closing line counting them by verdict.
|
|
1576
|
+
*/
|
|
1577
|
+
function renderSpecReport(specs) {
|
|
1578
|
+
if (specs.length === 0) return "No specs found.";
|
|
1579
|
+
const modules = [...new Set(specs.map((v) => v.module))];
|
|
1580
|
+
const out = ["Specs (TESTED means held on inputs generated from the parameter types, which is not a proof; PROVEN is one, by the named engine)"];
|
|
1581
|
+
for (const m of modules) {
|
|
1582
|
+
out.push("", m);
|
|
1583
|
+
for (const v of specs) if (v.module === m) out.push(...specLines(v));
|
|
1342
1584
|
}
|
|
1585
|
+
const counts = verdictOrder.map((k) => [k, specs.filter((v) => v.kind === k).length]).filter(([, n]) => n > 0).map(([k, n]) => `${n} ${k}`);
|
|
1586
|
+
out.push("", `${specs.length} propert${specs.length === 1 ? "y" : "ies"} in ${modules.length} module${modules.length === 1 ? "" : "s"}: ${counts.join(", ")}`);
|
|
1343
1587
|
return out.join("\n");
|
|
1344
1588
|
}
|
|
1589
|
+
/** `eutaxy report --json`: canonical, with the schema version, the spec verdicts and nothing else. */
|
|
1590
|
+
function renderSpecReportJson(specs) {
|
|
1591
|
+
return canonicalJson({
|
|
1592
|
+
schemaVersion: 1,
|
|
1593
|
+
generator: "eutaxy",
|
|
1594
|
+
specs
|
|
1595
|
+
});
|
|
1596
|
+
}
|
|
1597
|
+
function specLines(v) {
|
|
1598
|
+
const out = [];
|
|
1599
|
+
const what = `${v.function} ${v.property}`;
|
|
1600
|
+
switch (v.kind) {
|
|
1601
|
+
case "CHECKED":
|
|
1602
|
+
out.push(` CHECKED ${what}: held on ${v.inputs} input(s)${v.discarded > 0 ? `, ${v.discarded} outside the claim` : ""}`);
|
|
1603
|
+
break;
|
|
1604
|
+
case "TESTED":
|
|
1605
|
+
out.push(` TESTED ${what}: held on ${v.inputs} generated input(s)${v.checked === void 0 ? "" : ` and ${v.checked} the simulator passed`}${v.discarded > 0 ? `, ${v.discarded} outside the claim` : ""}`);
|
|
1606
|
+
break;
|
|
1607
|
+
case "PROVEN": {
|
|
1608
|
+
const beside = [...v.tested === void 0 ? [] : [`${v.tested} generated input(s)`], ...v.checked === void 0 ? [] : [`${v.checked} the simulator passed`]];
|
|
1609
|
+
out.push(` PROVEN ${what}: by ${v.engine.name} ${v.engine.version}${beside.length > 0 ? `; also held on ${beside.join(" and ")}` : ""}`);
|
|
1610
|
+
break;
|
|
1611
|
+
}
|
|
1612
|
+
case "CONFLICT":
|
|
1613
|
+
out.push(` CONFLICT ${what}: ${v.proven.name} ${v.proven.version} proves it, ${v.refuted.name} ${v.refuted.version} refutes it; not resolved automatically`);
|
|
1614
|
+
if (v.refuted.counterexample) out.push(` ${v.refuted.counterexample.binders.map((b) => `${b.name} = ${b.value}`).join(", ")}`);
|
|
1615
|
+
break;
|
|
1616
|
+
case "REFUTED": {
|
|
1617
|
+
const c = v.counterexample;
|
|
1618
|
+
const where = v.rung === "PROVEN" ? `by ${v.engine?.name ?? "an engine"}` : c.call === void 0 ? "on a generated input" : `at ${c.call}`;
|
|
1619
|
+
out.push(` REFUTED ${what}: false ${where}${c.error ? `, which threw ${c.error}` : ""}`);
|
|
1620
|
+
if (c.binders.length > 0) out.push(` ${c.binders.map((b) => `${b.name} = ${b.value}`).join(", ")}`);
|
|
1621
|
+
out.push(` ${v.text.replace(/\s+/g, " ")}`);
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
case "UNKNOWN": out.push(` UNKNOWN ${what}: ${v.cause}: ${v.reason}`);
|
|
1625
|
+
}
|
|
1626
|
+
for (const a of v.assumptions) if (v.kind === "PROVEN" || a.startsWith("not PROVEN by ")) out.push(` ${a}`);
|
|
1627
|
+
return out;
|
|
1628
|
+
}
|
|
1345
1629
|
function clip(s, max) {
|
|
1346
1630
|
return s.length <= max ? s : `${s.slice(0, max - 1)}…`;
|
|
1347
1631
|
}
|
|
@@ -1417,6 +1701,6 @@ function renderText(verdict) {
|
|
|
1417
1701
|
for (const a of verdict.assumptions) out.push(` - ${a}`);
|
|
1418
1702
|
return out.join("\n");
|
|
1419
1703
|
}
|
|
1420
|
-
export {
|
|
1704
|
+
export { endpointNumber as _, renderText as a, describeVerdict as b, aggregate as c, testedRung as d, shrinkRefutation as f, endpointBigInt as g, conforms as h, renderSpecs as i, checkSpecModule as l, evaluate as m, renderSpecReport as n, renderTrace as o, checkedRung as p, renderSpecReportJson as r, emitRegressionTest as s, renderJson as t, specLadder as u, render as v, describeType as y };
|
|
1421
1705
|
|
|
1422
|
-
//# sourceMappingURL=src-
|
|
1706
|
+
//# sourceMappingURL=src-BZtuuu_j.mjs.map
|