@hviana/sema 0.8.5 → 0.8.7
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/src/meter.d.ts +21 -6
- package/dist/src/meter.js +21 -6
- package/dist/src/mind/attention.d.ts +5 -0
- package/dist/src/mind/derivation.d.ts +14 -9
- package/dist/src/mind/derivation.js +10 -1
- package/dist/src/mind/pipeline.js +9 -0
- package/dist/src/mind/reasoning.js +95 -5
- package/dist/src/mind/traverse.d.ts +7 -1
- package/dist/src/mind/traverse.js +7 -1
- package/docs/INDEX.md +1 -1
- package/docs/INVARIANTS.md +1 -1
- package/docs/architecture/closure.md +17 -2
- package/docs/harness/gates.md +1 -1
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/meter.ts +21 -6
- package/src/mind/attention.ts +5 -0
- package/src/mind/derivation.ts +28 -10
- package/src/mind/pipeline.ts +9 -0
- package/src/mind/reasoning.ts +145 -5
- package/src/mind/traverse.ts +7 -1
- package/test/121-the-extension-does-not-grow-with-the-corpus.test.mjs +3 -3
- package/test/136-the-two-named-limits.test.mjs +1 -1
- package/test/142-the-layer-offers-only-what-the-law-admits.test.mjs +155 -0
- package/test/143-cycles-terminate-and-are-not-closure.test.mjs +62 -0
- package/test/144-identity-is-content.test.mjs +55 -0
- package/test/145-the-instrument-answers.test.mjs +58 -0
- package/test/146-the-contains-gate.test.mjs +67 -0
- package/test/147-the-witness-ladder.test.mjs +76 -0
- package/test/55-cost-meter.test.mjs +2 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// 147-the-witness-ladder.test.mjs — consumed ⊆ carried ⊆ accounted, non-vacuously.
|
|
2
|
+
//
|
|
3
|
+
// WHY THIS FILE EXISTS. The audit's point 5 (E, partial) asks whether the accounting ever exceeds
|
|
4
|
+
// the window: the consumed window is where the remainder drains, the accounting registers the
|
|
5
|
+
// span, and `span != window` is the established reading. Measured on the real corpus, the three
|
|
6
|
+
// counter families are ZERO on every roteiro question — the answers there come from grounding and
|
|
7
|
+
// derive-through, not from the reasoner's own extensions — and a ladder of zeroes proves nothing.
|
|
8
|
+
// So the ladder is pinned where the values cannot be zero: on a state built for the purpose.
|
|
9
|
+
//
|
|
10
|
+
// WHAT IS PINNED. Given a step whose product carries a window of what is still owed:
|
|
11
|
+
// • the law admits it and the witness carries a SPAN and a WINDOW (the two readings);
|
|
12
|
+
// • the remainder shrinks by AT MOST the window — the consumed set is a subset of the carried one;
|
|
13
|
+
// • and the accounting grows by AT LEAST the window — nothing consumed goes unaccounted.
|
|
14
|
+
// The sanity assertion is part of the pin: the window must be non-zero, or the two inequalities
|
|
15
|
+
// above hold for the wrong reason.
|
|
16
|
+
|
|
17
|
+
import { test } from "node:test";
|
|
18
|
+
import assert from "node:assert/strict";
|
|
19
|
+
import { admissible, advance } from "../dist/src/mind/derivation.js";
|
|
20
|
+
|
|
21
|
+
const QUERY = new TextEncoder().encode("ABCDEFGHIJ"); // W = 4 ⇒ one window is "ABCD"
|
|
22
|
+
const W = 4;
|
|
23
|
+
const bytesOf = (spans) => spans.reduce((n, [a, b]) => n + (b - a), 0);
|
|
24
|
+
const state = () => ({
|
|
25
|
+
product: new Uint8Array(0),
|
|
26
|
+
accounted: [],
|
|
27
|
+
remainder: [[0, 10]],
|
|
28
|
+
cost: 0,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("147.1 consumed ⊆ carried ⊆ accounted, with a window that is not zero", () => {
|
|
32
|
+
const step = {
|
|
33
|
+
product: new TextEncoder().encode("ZZZZABCDZZ"),
|
|
34
|
+
contains: true,
|
|
35
|
+
cost: 1,
|
|
36
|
+
};
|
|
37
|
+
const before = state();
|
|
38
|
+
const witnesses = admissible(before, step, QUERY, W);
|
|
39
|
+
assert.notEqual(
|
|
40
|
+
witnesses,
|
|
41
|
+
null,
|
|
42
|
+
"the law admits a step that carries a window",
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const windows = witnesses.filter((x) => x.window !== undefined);
|
|
46
|
+
assert.ok(
|
|
47
|
+
windows.length > 0,
|
|
48
|
+
"SANITY: at least one witness must carry a window, or the inequalities below are vacuous",
|
|
49
|
+
);
|
|
50
|
+
const windowBytes = windows.reduce(
|
|
51
|
+
(n, x) => n + (x.window[1] - x.window[0]),
|
|
52
|
+
0,
|
|
53
|
+
);
|
|
54
|
+
assert.ok(
|
|
55
|
+
windowBytes > 0,
|
|
56
|
+
`SANITY: the window must be non-zero (got ${windowBytes})`,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const after = advance(before, step, witnesses);
|
|
60
|
+
const spanBytes = bytesOf(witnesses.map((x) => x.span));
|
|
61
|
+
const drained = bytesOf(before.remainder) - bytesOf(after.remainder);
|
|
62
|
+
const accounted = bytesOf(after.accounted) - bytesOf(before.accounted);
|
|
63
|
+
|
|
64
|
+
assert.ok(
|
|
65
|
+
drained <= windowBytes,
|
|
66
|
+
`a step drains AT MOST what it carries: drained ${drained} > window ${windowBytes}`,
|
|
67
|
+
);
|
|
68
|
+
assert.ok(
|
|
69
|
+
accounted >= windowBytes,
|
|
70
|
+
`nothing consumed goes unaccounted: accounted ${accounted} < window ${windowBytes}`,
|
|
71
|
+
);
|
|
72
|
+
assert.ok(
|
|
73
|
+
spanBytes > 0,
|
|
74
|
+
"and the accounting is a span, which is why it may exceed the window",
|
|
75
|
+
);
|
|
76
|
+
});
|
|
@@ -419,7 +419,7 @@ test("12. the extension's cost obeys the ladder's own inequality", async () => {
|
|
|
419
419
|
await store.close();
|
|
420
420
|
|
|
421
421
|
const steps = c.reasonSteps ?? 0;
|
|
422
|
-
const carried = c.
|
|
422
|
+
const carried = c.reasonAccountedBytes ?? 0;
|
|
423
423
|
assert.ok(
|
|
424
424
|
steps >= 1,
|
|
425
425
|
`the extension must run for this to mean anything (got ${steps})`,
|
|
@@ -765,7 +765,7 @@ test("18. the remainder the pipeline decides on is visible", async () => {
|
|
|
765
765
|
};
|
|
766
766
|
|
|
767
767
|
// The pivoting query: the reasoner runs, so the remainder is non-empty
|
|
768
|
-
// (measured: reasonSteps 1,
|
|
768
|
+
// (measured: reasonSteps 1, reasonAccountedBytes 11).
|
|
769
769
|
const pivot = await run("What is the capital of France famous for");
|
|
770
770
|
assert.ok(
|
|
771
771
|
(pivot.steps ?? 0) >= 1,
|