@seanhogg/builderforce-memory 2026.10.79 → 2026.10.81
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/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +45 -5
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/cooperative.d.ts +51 -0
- package/dist/knowledge/cooperative.d.ts.map +1 -0
- package/dist/knowledge/cooperative.js +58 -0
- package/dist/knowledge/cooperative.js.map +1 -0
- package/dist/knowledge/findings.d.ts +7 -1
- package/dist/knowledge/findings.d.ts.map +1 -1
- package/dist/knowledge/findings.js +39 -14
- package/dist/knowledge/findings.js.map +1 -1
- package/dist/knowledge/ignoreMatcher.d.ts +25 -0
- package/dist/knowledge/ignoreMatcher.d.ts.map +1 -0
- package/dist/knowledge/ignoreMatcher.js +121 -0
- package/dist/knowledge/ignoreMatcher.js.map +1 -0
- package/dist/knowledge/index.d.ts +6 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +4 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/model.d.ts +26 -0
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/plan.d.ts +6 -0
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +17 -1
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/reviewAnalyse.d.ts.map +1 -1
- package/dist/knowledge/reviewAnalyse.js +6 -1
- package/dist/knowledge/reviewAnalyse.js.map +1 -1
- package/dist/knowledge/reviewFinish.d.ts.map +1 -1
- package/dist/knowledge/reviewFinish.js +7 -1
- package/dist/knowledge/reviewFinish.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +10 -0
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.d.ts +11 -4
- package/dist/knowledge/rules/factStore.d.ts.map +1 -1
- package/dist/knowledge/rules/factStore.js +57 -25
- package/dist/knowledge/rules/factStore.js.map +1 -1
- package/dist/knowledge/rules/fixpointRules.d.ts +68 -0
- package/dist/knowledge/rules/fixpointRules.d.ts.map +1 -0
- package/dist/knowledge/rules/fixpointRules.js +0 -0
- package/dist/knowledge/rules/fixpointRules.js.map +1 -0
- package/dist/knowledge/sources.d.ts +9 -9
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +11 -50
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/statManifest.d.ts +89 -0
- package/dist/knowledge/statManifest.d.ts.map +1 -0
- package/dist/knowledge/statManifest.js +125 -0
- package/dist/knowledge/statManifest.js.map +1 -0
- package/dist/stats/estimators.d.ts +8 -1
- package/dist/stats/estimators.d.ts.map +1 -1
- package/dist/stats/estimators.js +18 -7
- package/dist/stats/estimators.js.map +1 -1
- package/package.json +1 -1
- package/src/contract/exports.snapshot.json +12 -0
- package/src/contract/regression.assets.test.ts +2 -2
- package/src/contract/regression.factStoreBatchedLoad.test.ts +62 -0
- package/src/contract/regression.factStoreFastPath.test.ts +116 -0
- package/src/contract/regression.findingsProvider.test.ts +80 -0
- package/src/contract/regression.ignoreMatcher.test.ts +116 -0
- package/src/contract/types.contract.test.ts +9 -1
- package/src/knowledge/build.ts +37 -5
- package/src/knowledge/cooperative.test.ts +57 -0
- package/src/knowledge/cooperative.ts +76 -0
- package/src/knowledge/docs.test.ts +30 -0
- package/src/knowledge/findings.ts +55 -14
- package/src/knowledge/ignoreMatcher.ts +143 -0
- package/src/knowledge/index.ts +9 -2
- package/src/knowledge/model.ts +24 -0
- package/src/knowledge/plan.ts +20 -1
- package/src/knowledge/reviewAnalyse.ts +6 -1
- package/src/knowledge/reviewFinish.ts +7 -1
- package/src/knowledge/reviewModel.ts +6 -0
- package/src/knowledge/rules/factStore.ts +59 -21
- package/src/knowledge/rules/fixpointRules.test.ts +94 -0
- package/src/knowledge/rules/fixpointRules.ts +0 -0
- package/src/knowledge/sources.ts +12 -46
- package/src/knowledge/statManifest.test.ts +122 -0
- package/src/knowledge/statManifest.ts +176 -0
- package/src/stats/estimators.ts +18 -7
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/statManifest.ts — the STAT PREFILTER (PRD 41 §B2 steps 1–2): a per-root manifest of
|
|
3
|
+
* `(path, size, mtimeNs, fileId, hash, recordedAtMs)` so a warm plan reuses a stored content hash
|
|
4
|
+
* without reading the file, and only stats — never content — decide it.
|
|
5
|
+
*
|
|
6
|
+
* Rules implemented here, straight from the PRD:
|
|
7
|
+
* 0. Content identity is unchanged by this module: the stored `hash` is the host's content hash
|
|
8
|
+
* (EOL-normalized for text, raw for binary — see contentHash.ts); this manifest only caches it.
|
|
9
|
+
* 1. Stat tuple match → reuse the stored hash. Stats are BigInt (`bigint: true` from fs.stat):
|
|
10
|
+
* Windows file ids and ns mtimes lose precision as JS numbers, so {@link StatRecord} carries
|
|
11
|
+
* them as bigint and the manifest persists them as decimal strings.
|
|
12
|
+
* 2. Racy-file rule (git's index): a file whose mtime is within {@link RACY_WINDOW_MS} of the
|
|
13
|
+
* manifest's write time, or of `now` at plan time, is re-hashed whatever its stat says.
|
|
14
|
+
* 4. Directory Merkle hashes stay the identity of a subtree (merkle.ts) — this manifest never
|
|
15
|
+
* enters a digest, a cache key or the plan output (PRD 41 §B8.3: mtime is only a hint).
|
|
16
|
+
*
|
|
17
|
+
* Determinism (§B8): every output here is sorted by path; the only clock use is the injected
|
|
18
|
+
* `now` (default `Date.now`) stamping `recordedAtMs`, which is persisted metadata, never part of
|
|
19
|
+
* any digest. Hosts that need a deterministic plan inject `now`.
|
|
20
|
+
*
|
|
21
|
+
* The plan itself consumes hashes from `DirectorySource.list()`; this module is the helper a
|
|
22
|
+
* host's listing calls per file ({@link createStatPrefilter}) plus the manifest persistence the
|
|
23
|
+
* plan updates after a successful run ({@link saveStatManifest}).
|
|
24
|
+
*/
|
|
25
|
+
import { canonicalJson, compareStr, normalizePath } from './refs.js';
|
|
26
|
+
import { manifestMap, saveManifestMap } from './sources.js';
|
|
27
|
+
/** git's racy-window: an mtime within this many ms of the index write is re-checked next plan. */
|
|
28
|
+
export const RACY_WINDOW_MS = 2000;
|
|
29
|
+
/** The manifest key under the ingest manifest: one stat manifest per root. */
|
|
30
|
+
export const statManifestKey = (rootId) => `stats:${rootId}`;
|
|
31
|
+
/** Stat-tuple equality: same size, same mtime to the nanosecond, same file id (a null fileId matches only a null fileId). */
|
|
32
|
+
export function statMatches(a, b) {
|
|
33
|
+
return a.size === b.size && a.mtimeNs === b.mtimeNs && a.fileId === b.fileId;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The racy-file rule (§B2 step 2): true when the file may have been written in the same tick as
|
|
37
|
+
* the manifest — its mtime is within {@link RACY_WINDOW_MS} of the manifest's `recordedAtMs`, or
|
|
38
|
+
* of `nowMs` (a file touched just now whose mtime we are about to record). A racy file is
|
|
39
|
+
* re-hashed on the next plan whatever its stat says.
|
|
40
|
+
*/
|
|
41
|
+
export function isRacy(stat, recordedAtMs, nowMs) {
|
|
42
|
+
const mtimeMs = Number(stat.mtimeNs / 1000000n);
|
|
43
|
+
return Math.abs(mtimeMs - recordedAtMs) < RACY_WINDOW_MS || Math.abs(mtimeMs - nowMs) < RACY_WINDOW_MS;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The ONE prefilter decision, pure and order-independent: a path reuses its stored hash only when
|
|
47
|
+
* its prior entry exists, the stat tuple matches, and the racy rule does not fire. Everything else
|
|
48
|
+
* is hashed. `nowMs` is the plan's clock.
|
|
49
|
+
*/
|
|
50
|
+
export function prefilterStats(listed, prior, nowMs) {
|
|
51
|
+
const reused = [];
|
|
52
|
+
const hash = [];
|
|
53
|
+
for (const { path, stat } of listed) {
|
|
54
|
+
const p = normalizePath(path);
|
|
55
|
+
const entry = prior.get(p);
|
|
56
|
+
if (entry && statMatches(entry, stat) && !isRacy(stat, entry.recordedAtMs, nowMs))
|
|
57
|
+
reused.push(p);
|
|
58
|
+
else
|
|
59
|
+
hash.push(p);
|
|
60
|
+
}
|
|
61
|
+
reused.sort(compareStr);
|
|
62
|
+
hash.sort(compareStr);
|
|
63
|
+
return { reused, hash };
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A per-file hash provider for a host's `DirectorySource.list()`: returns the stored hash when
|
|
67
|
+
* {@link prefilterStats} reuses the path, else `hashPath(path)`. `hashPath` reads the file and
|
|
68
|
+
* hashes it (EOL-normalized, per the host's content-hash rule) — the only path that reads bytes.
|
|
69
|
+
* `now` defaults to `Date.now`; inject it for deterministic plans.
|
|
70
|
+
*/
|
|
71
|
+
export function createStatPrefilter(prior, hashPath, now = () => Date.now()) {
|
|
72
|
+
return async ({ path, stat }) => {
|
|
73
|
+
const normalized = normalizePath(path);
|
|
74
|
+
const entry = prior.get(normalized);
|
|
75
|
+
if (entry && statMatches(entry, stat) && !isRacy(stat, entry.recordedAtMs, now())) {
|
|
76
|
+
return { path: normalized, hash: entry.hash };
|
|
77
|
+
}
|
|
78
|
+
return { path: normalized, hash: await hashPath(path) };
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const encode = (entries) => canonicalJson([...entries.entries()].sort((a, b) => compareStr(a[0], b[0])).map(([path, e]) => [path, {
|
|
82
|
+
size: e.size,
|
|
83
|
+
mtimeNs: e.mtimeNs.toString(),
|
|
84
|
+
fileId: e.fileId === null ? null : e.fileId.toString(),
|
|
85
|
+
hash: e.hash,
|
|
86
|
+
recordedAtMs: e.recordedAtMs,
|
|
87
|
+
}]));
|
|
88
|
+
const decode = (json) => {
|
|
89
|
+
const rows = JSON.parse(json);
|
|
90
|
+
const out = new Map();
|
|
91
|
+
for (const [path, r] of rows ?? []) {
|
|
92
|
+
out.set(path, {
|
|
93
|
+
size: r.size,
|
|
94
|
+
mtimeNs: BigInt(r.mtimeNs),
|
|
95
|
+
fileId: r.fileId === null ? null : BigInt(r.fileId),
|
|
96
|
+
hash: r.hash,
|
|
97
|
+
recordedAtMs: r.recordedAtMs,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
};
|
|
102
|
+
/** The stored stat manifest for `rootId` (empty when none — the first run hashes everything, the existing fallback). */
|
|
103
|
+
export async function loadStatManifest(manifest, rootId) {
|
|
104
|
+
const map = await manifestMap(manifest, statManifestKey(rootId));
|
|
105
|
+
const raw = map.get('entries');
|
|
106
|
+
if (raw === undefined)
|
|
107
|
+
return new Map();
|
|
108
|
+
try {
|
|
109
|
+
return decode(raw);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return new Map(); // a corrupt stat cache is a perf fallback only: re-hash, never fail the plan
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Persists the stat manifest for `rootId`: every listed file's hash and the stat tuple it was
|
|
117
|
+
* cached under, stamped with `recordedAtMs` (the manifest write time the racy rule compares to).
|
|
118
|
+
*/
|
|
119
|
+
export async function saveStatManifest(manifest, rootId, files, recordedAtMs) {
|
|
120
|
+
const entries = new Map();
|
|
121
|
+
for (const f of files)
|
|
122
|
+
entries.set(normalizePath(f.path), { ...f.stat, hash: f.hash, recordedAtMs });
|
|
123
|
+
await saveManifestMap(manifest, statManifestKey(rootId), new Map([['entries', encode(entries)]]));
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=statManifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statManifest.js","sourceRoot":"","sources":["../../src/knowledge/statManifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE5D,kGAAkG;AAClG,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC;AAenC,8EAA8E;AAC9E,MAAM,CAAC,MA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D,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,IAAI,GAAG,EAAE,CAAC,CAAC,6EAA6E;IACnG,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAClC,QAAwB,EACxB,MAAc,EACd,KAAsE,EACtE,YAAoB;IAEpB,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IACrD,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC;IACrG,MAAM,eAAe,CAAC,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC"}
|
|
@@ -34,7 +34,14 @@ export declare function kaplanMeier(rows: readonly {
|
|
|
34
34
|
/**
|
|
35
35
|
* Goel–Okumoto NHPP MLE: mean failures μ(t) = a(1 − e^{−bt}). a is solved in
|
|
36
36
|
* closed form given b; b is refined by bisection on the score equation
|
|
37
|
-
* Σ tᵢ = n/b − n·
|
|
37
|
+
* Σ tᵢ = n/b − n·tMax·e^{−b·tMax}/(1 − e^{−b·tMax}). Needs n ≥ 2 distinct times.
|
|
38
|
+
*
|
|
39
|
+
* The score uses tMax (the censoring horizon), not tMean: with likelihood
|
|
40
|
+
* L ∝ aⁿ e^{−a(1−e^{−bT})} · bⁿ e^{−bΣtᵢ} · Πe^{−btᵢ}, the b score after profiling out a
|
|
41
|
+
* substitutes the END time T = tMax in the per-observation exposure term, giving the
|
|
42
|
+
* root-finding target below. An earlier version used tMean, which has no stationary point
|
|
43
|
+
* on the data and drove b to the search bound (a saturated, meaningless fit) for every
|
|
44
|
+
* input.
|
|
38
45
|
*/
|
|
39
46
|
export declare function goelOkumotoMLE(times: readonly number[]): {
|
|
40
47
|
a: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimators.d.ts","sourceRoot":"","sources":["../../src/stats/estimators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EAAE,mBAAmB,CAAA;CAAE,CAAC;AAE/D,sGAAsG;AACtG,wBAAgB,eAAe,CAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACpB;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,gBAAgB,CAGzC;AAED,oFAAoF;AACpF,wBAAgB,uBAAuB,CACnC,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACpB;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,gBAAgB,CAGzC;AAED,MAAM,WAAW,iBAAiB;IAC9B,+EAA+E;IAC/E,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,0DAA0D;IAC1D,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACpD;AAED,gGAAgG;AAChG,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;CAAE,EAAE,GAAG,iBAAiB,CAe9F;AAED
|
|
1
|
+
{"version":3,"file":"estimators.d.ts","sourceRoot":"","sources":["../../src/stats/estimators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,gBAAgB,GAAG;IAAE,MAAM,EA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IjE"}
|
package/dist/stats/estimators.js
CHANGED
|
@@ -37,7 +37,14 @@ export function kaplanMeier(rows) {
|
|
|
37
37
|
/**
|
|
38
38
|
* Goel–Okumoto NHPP MLE: mean failures μ(t) = a(1 − e^{−bt}). a is solved in
|
|
39
39
|
* closed form given b; b is refined by bisection on the score equation
|
|
40
|
-
* Σ tᵢ = n/b − n·
|
|
40
|
+
* Σ tᵢ = n/b − n·tMax·e^{−b·tMax}/(1 − e^{−b·tMax}). Needs n ≥ 2 distinct times.
|
|
41
|
+
*
|
|
42
|
+
* The score uses tMax (the censoring horizon), not tMean: with likelihood
|
|
43
|
+
* L ∝ aⁿ e^{−a(1−e^{−bT})} · bⁿ e^{−bΣtᵢ} · Πe^{−btᵢ}, the b score after profiling out a
|
|
44
|
+
* substitutes the END time T = tMax in the per-observation exposure term, giving the
|
|
45
|
+
* root-finding target below. An earlier version used tMean, which has no stationary point
|
|
46
|
+
* on the data and drove b to the search bound (a saturated, meaningless fit) for every
|
|
47
|
+
* input.
|
|
41
48
|
*/
|
|
42
49
|
export function goelOkumotoMLE(times) {
|
|
43
50
|
const sorted = [...times].sort((a, b) => a - b);
|
|
@@ -45,23 +52,27 @@ export function goelOkumotoMLE(times) {
|
|
|
45
52
|
if (n < 2)
|
|
46
53
|
return { status: "insufficient-data" };
|
|
47
54
|
const tMax = sorted[n - 1];
|
|
48
|
-
const
|
|
55
|
+
const tSum = sorted.reduce((a, b) => a + b, 0);
|
|
56
|
+
// g(b) = n/b − n·tMax·e^{−b·tMax}/(1 − e^{−b·tMax}); the MLE b is the root of tSum = g(b).
|
|
57
|
+
// g is strictly decreasing in b (n/b falls, and the subtracted term grows toward n·tMax),
|
|
58
|
+
// so tSum − g(b) is strictly INCREASING: negative below the root, positive above it.
|
|
49
59
|
const score = (b) => {
|
|
50
60
|
if (b <= 0)
|
|
51
|
-
return Infinity;
|
|
61
|
+
return -Infinity;
|
|
52
62
|
const denom = 1 - Math.exp(-b * tMax);
|
|
53
|
-
return n / b - (n *
|
|
63
|
+
return tSum - (n / b - (n * tMax * Math.exp(-b * tMax)) / denom);
|
|
54
64
|
};
|
|
55
65
|
let lo = 1e-9;
|
|
56
66
|
let hi = 1;
|
|
57
|
-
|
|
67
|
+
// Expand until the score is positive (past the increasing root); cap the search.
|
|
68
|
+
while (score(hi) < 0 && hi < 1e6)
|
|
58
69
|
hi *= 2;
|
|
59
70
|
for (let i = 0; i < 100; i++) {
|
|
60
71
|
const mid = (lo + hi) / 2;
|
|
61
72
|
if (score(mid) > 0)
|
|
62
|
-
lo = mid;
|
|
63
|
-
else
|
|
64
73
|
hi = mid;
|
|
74
|
+
else
|
|
75
|
+
lo = mid;
|
|
65
76
|
}
|
|
66
77
|
const b = (lo + hi) / 2;
|
|
67
78
|
const a = n / (1 - Math.exp(-b * tMax));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"estimators.js","sourceRoot":"","sources":["../../src/stats/estimators.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,sGAAsG;AACtG,MAAM,UAAU,eAAe,CAC3B,SAAiB,EACjB,SAAiB,EACjB,WAAmB;IAEnB,IAAI,WAAW,GAAG,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;AACrF,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,uBAAuB,CACnC,SAAiB,EACjB,SAAiB,EACjB,WAAmB;IAEnB,IAAI,WAAW,GAAG,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC5D,OAAO,EAAE,QAAQ,EAAE,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,WAAW,EAAE,CAAC;AAC/D,CAAC;AAWD,gG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hB,MAAM,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC;IAC7B,MAAM,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC9B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC;AAChF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seanhogg/builderforce-memory",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.81",
|
|
4
4
|
"description": "BuilderForce Agent Memory — runtime layer. SSM execution, Transformer orchestration, online distillation, enterprise RAG (ingestion pipelines, vector-store adapters, tenant/ACL-scoped hybrid retrieval), multi-agent graph orchestration, LLM telemetry and cost accounting, persistent agent memory, and token-saving agent-run memory (code maps, a prompt-cache-safe working memory, chunked transcript windowing) for BuilderForce.ai agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -318,6 +318,7 @@
|
|
|
318
318
|
"MAX_CALL_SITES_PER_EDGE",
|
|
319
319
|
"MAX_CLAIM_TEXT_CHARS",
|
|
320
320
|
"MAX_FINDING_NODES",
|
|
321
|
+
"MAX_FIXPOINT_ITERATIONS",
|
|
321
322
|
"MAX_MOUNT_DEPTH",
|
|
322
323
|
"MAX_NODES_CAP",
|
|
323
324
|
"MAX_QUOTE_CHARS",
|
|
@@ -331,6 +332,7 @@
|
|
|
331
332
|
"OUTLINE_VERDICTS",
|
|
332
333
|
"PAGERANK_DAMPING",
|
|
333
334
|
"PAGERANK_ITERATIONS",
|
|
335
|
+
"RACY_WINDOW_MS",
|
|
334
336
|
"REVIEW_FACT_SOURCE",
|
|
335
337
|
"REVIEW_RUN_FAILURE_CHUNK",
|
|
336
338
|
"REVIEW_RUN_STEP_RING",
|
|
@@ -375,11 +377,13 @@
|
|
|
375
377
|
"composeAnchor",
|
|
376
378
|
"composePacks",
|
|
377
379
|
"computeFindings",
|
|
380
|
+
"computeFindingsWith",
|
|
378
381
|
"contentHash",
|
|
379
382
|
"contentHashRuleOf",
|
|
380
383
|
"contradictionRule",
|
|
381
384
|
"createKnowledgeIndex",
|
|
382
385
|
"createModelLimiter",
|
|
386
|
+
"createStatPrefilter",
|
|
383
387
|
"crossesSystems",
|
|
384
388
|
"decodeCoChange",
|
|
385
389
|
"dedupeSymbolEdges",
|
|
@@ -393,6 +397,7 @@
|
|
|
393
397
|
"entityKey",
|
|
394
398
|
"entityName",
|
|
395
399
|
"evaluateRules",
|
|
400
|
+
"evaluateRulesFixpoint",
|
|
396
401
|
"extractFile",
|
|
397
402
|
"extractFileDetailed",
|
|
398
403
|
"extractJob",
|
|
@@ -431,8 +436,10 @@
|
|
|
431
436
|
"isDocumentPath",
|
|
432
437
|
"isFactsCurrent",
|
|
433
438
|
"isFileFactsV3",
|
|
439
|
+
"isRacy",
|
|
434
440
|
"isRateLimit",
|
|
435
441
|
"isRootFilePath",
|
|
442
|
+
"isRowSourceInput",
|
|
436
443
|
"isSymbolEdgeKind",
|
|
437
444
|
"jobOf",
|
|
438
445
|
"joinRoutePath",
|
|
@@ -445,6 +452,7 @@
|
|
|
445
452
|
"loadFactGraph",
|
|
446
453
|
"loadKnowledgeIndex",
|
|
447
454
|
"loadPartitions",
|
|
455
|
+
"loadStatManifest",
|
|
448
456
|
"localSnapshotStore",
|
|
449
457
|
"matchGlob",
|
|
450
458
|
"matchLineage",
|
|
@@ -474,6 +482,7 @@
|
|
|
474
482
|
"planDetail",
|
|
475
483
|
"planReview",
|
|
476
484
|
"possibleSameFindings",
|
|
485
|
+
"prefilterStats",
|
|
477
486
|
"projectFileFacts",
|
|
478
487
|
"putExtract",
|
|
479
488
|
"putNoExtract",
|
|
@@ -492,6 +501,7 @@
|
|
|
492
501
|
"runKnowledgeRules",
|
|
493
502
|
"runRate",
|
|
494
503
|
"saveFactGraph",
|
|
504
|
+
"saveStatManifest",
|
|
495
505
|
"sha256",
|
|
496
506
|
"sha256Hex",
|
|
497
507
|
"slowestSteps",
|
|
@@ -499,6 +509,8 @@
|
|
|
499
509
|
"splitSourceRef",
|
|
500
510
|
"srcRef",
|
|
501
511
|
"startRun",
|
|
512
|
+
"statManifestKey",
|
|
513
|
+
"statMatches",
|
|
502
514
|
"stationTransitions",
|
|
503
515
|
"sweepFactStore",
|
|
504
516
|
"toCards",
|
|
@@ -172,8 +172,8 @@ describe('regression: the asset lifecycle', () => {
|
|
|
172
172
|
expect((await stateOf(manifest)).version).toBe(EXTRACTOR_VERSION);
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
it('regression: EXTRACTOR_VERSION is
|
|
176
|
-
expect(EXTRACTOR_VERSION).toBe(
|
|
175
|
+
it('regression: EXTRACTOR_VERSION is 7, so cached code extracts re-run after the PRD 43 deploy-unit and concurrency code-pack changes', () => {
|
|
176
|
+
expect(EXTRACTOR_VERSION).toBe(7);
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
it('regression: a removed asset is retired like any removed file', async () => {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.factStoreBatchedLoad.test.ts — `loadFactGraph` reads objects in bounded `getObjects` batches.
|
|
3
|
+
*
|
|
4
|
+
* Before: one `getObjects` call with EVERY referenced hash, which the VS Code host's SQLite port serves as one synchronous
|
|
5
|
+
* transaction on the extension host's main thread (seconds on a large workspace). Now the load asks in bounded batches and
|
|
6
|
+
* yields between them; the loaded graph is exactly what the single call produced.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { FileFacts } from '../knowledge/facts/fileFacts.js';
|
|
10
|
+
import { buildFactGraph, factGraphDump } from '../knowledge/rules/factGraph.js';
|
|
11
|
+
import { loadFactGraph, memoryFactStore, saveFactGraph, type FactStorePort } from '../knowledge/rules/factStore.js';
|
|
12
|
+
import { emptyFacts, FIXTURE_RULES } from '../knowledge/rules/rules.testkit.test-util.js';
|
|
13
|
+
|
|
14
|
+
const FILES = 1300;
|
|
15
|
+
|
|
16
|
+
const tree = (): Array<readonly [string, FileFacts]> =>
|
|
17
|
+
Array.from({ length: FILES }, (_, i) => [
|
|
18
|
+
`src/f${i}.ts`,
|
|
19
|
+
{ ...emptyFacts(`c${i}`), exports: [{ name: `e${i}`, kind: 'function', signatureHash: `s${i}` }] },
|
|
20
|
+
] as const);
|
|
21
|
+
|
|
22
|
+
describe('regression: batched fact store load', () => {
|
|
23
|
+
it('regression: a load asks getObjects in bounded batches covering every hash once, and returns the same graph as one call', async () => {
|
|
24
|
+
const graph = buildFactGraph(tree(), FIXTURE_RULES).graph;
|
|
25
|
+
const store = memoryFactStore();
|
|
26
|
+
await saveFactGraph(store, graph);
|
|
27
|
+
|
|
28
|
+
const calls: string[][] = [];
|
|
29
|
+
const batched: FactStorePort = { ...store, getObjects: (hashes) => { calls.push([...hashes]); return store.getObjects(hashes); } };
|
|
30
|
+
// The reference: a port that answers every hash at once whatever it is asked, as the single call did.
|
|
31
|
+
const all = [...graph.objects.keys()];
|
|
32
|
+
const whole: FactStorePort = { ...store, getObjects: () => store.getObjects(all) };
|
|
33
|
+
|
|
34
|
+
const loaded = await loadFactGraph(batched, { verify: 'manifest' });
|
|
35
|
+
const reference = await loadFactGraph(whole, { verify: 'manifest' });
|
|
36
|
+
expect(factGraphDump(loaded.graph)).toBe(factGraphDump(reference.graph));
|
|
37
|
+
expect(factGraphDump(loaded.graph)).toBe(factGraphDump(graph));
|
|
38
|
+
|
|
39
|
+
expect(calls.length).toBeGreaterThan(1);
|
|
40
|
+
expect(Math.max(...calls.map((c) => c.length))).toBeLessThanOrEqual(512);
|
|
41
|
+
const asked = calls.flat();
|
|
42
|
+
expect(asked.length).toBe(new Set(asked).size);
|
|
43
|
+
expect(new Set(asked)).toEqual(new Set(all));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('regression: an object missing from a later batch is still fact_store_object_missing', async () => {
|
|
47
|
+
const graph = buildFactGraph(tree(), FIXTURE_RULES).graph;
|
|
48
|
+
const store = memoryFactStore();
|
|
49
|
+
await saveFactGraph(store, graph);
|
|
50
|
+
const sorted = [...graph.objects.keys()].sort();
|
|
51
|
+
const gone = sorted[sorted.length - 1]!;
|
|
52
|
+
const port: FactStorePort = {
|
|
53
|
+
...store,
|
|
54
|
+
getObjects: async (hashes) => {
|
|
55
|
+
const got = new Map(await store.getObjects(hashes));
|
|
56
|
+
got.delete(gone);
|
|
57
|
+
return got;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
await expect(loadFactGraph(port, { verify: 'manifest' })).rejects.toThrow(`fact_store_object_missing:${gone}`);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.factStoreFastPath.test.ts — `saveFactGraph` with a current `previous` reads only the version
|
|
3
|
+
* (PRD 41 §B4). Before: every save read the whole stored manifest and every derived row, O(files) per edit, which the
|
|
4
|
+
* VS Code fact index cannot afford on each keystroke-driven save. A stale or foreign `previous` still falls back to the
|
|
5
|
+
* full store diff (the H1 and ABA regressions), and an incremental save still equals a from-scratch save.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { FileFacts } from '../knowledge/facts/fileFacts.js';
|
|
9
|
+
import { buildFactGraph, factGraphDump, updateFactGraph } from '../knowledge/rules/factGraph.js';
|
|
10
|
+
import { derivedRowKey } from '../knowledge/rules/evaluateRules.js';
|
|
11
|
+
import { factStoreDump, memoryFactStore, saveFactGraph, type FactStorePort, type MemoryFactStore } from '../knowledge/rules/factStore.js';
|
|
12
|
+
import { emptyFacts, FIXTURE_RULES } from '../knowledge/rules/rules.testkit.test-util.js';
|
|
13
|
+
|
|
14
|
+
const file = (content: string, over: Partial<FileFacts> = {}): FileFacts => ({ ...emptyFacts(content), ...over });
|
|
15
|
+
|
|
16
|
+
const tree = (): Array<readonly [string, FileFacts]> => [
|
|
17
|
+
['src/a.ts', file('ca', { imports: [{ specifier: './b', resolved: 'src/b.ts', names: [] }], exports: [{ name: 'a', kind: 'function', signatureHash: 'a' }] })],
|
|
18
|
+
['src/b.ts', file('cb', { calls: [{ callee: 'db.get', enclosing: 'b', awaited: true, inLoop: true, count: 1 }] })],
|
|
19
|
+
['src/auth.ts', file('cauth', { exports: [{ name: 'requireAuth', kind: 'function', signatureHash: 'r' }] })],
|
|
20
|
+
['src/routes.ts', file('cr', {
|
|
21
|
+
imports: [{ specifier: './a', resolved: 'src/a.ts', names: [] }],
|
|
22
|
+
entryPoints: [{ kind: 'http-route', key: 'GET /x', symbol: 'h', guards: [], inputs: [], chain: ['src/auth.ts'] }],
|
|
23
|
+
})],
|
|
24
|
+
];
|
|
25
|
+
const built = () => buildFactGraph(tree(), FIXTURE_RULES).graph;
|
|
26
|
+
const bFacts = () => tree()[1]![1];
|
|
27
|
+
|
|
28
|
+
/** Counts the O(files) reads. */
|
|
29
|
+
function counting(store: MemoryFactStore): FactStorePort & { calls: { readManifest: number; derivedRows: number } } {
|
|
30
|
+
const calls = { readManifest: 0, derivedRows: 0 };
|
|
31
|
+
return {
|
|
32
|
+
...store,
|
|
33
|
+
readManifest: () => { calls.readManifest++; return store.readManifest(); },
|
|
34
|
+
derivedRows: () => { calls.derivedRows++; return store.derivedRows(); },
|
|
35
|
+
calls,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
describe('regression: saveFactGraph fast path', () => {
|
|
40
|
+
it('a save with a current previous performs no readManifest and no derivedRows call', async () => {
|
|
41
|
+
const store = memoryFactStore();
|
|
42
|
+
const s0 = await saveFactGraph(store, built());
|
|
43
|
+
const port = counting(store);
|
|
44
|
+
const g1 = updateFactGraph(s0.graph, [{ path: 'src/b.ts', facts: { ...bFacts(), contentHash: 'cb2' } }, { path: 'src/new.ts', facts: file('cn') }], FIXTURE_RULES).graph;
|
|
45
|
+
const s1 = await saveFactGraph(port, g1, s0);
|
|
46
|
+
const g2 = updateFactGraph(g1, [{ path: 'src/a.ts', facts: null }], FIXTURE_RULES).graph;
|
|
47
|
+
const s2 = await saveFactGraph(port, g2, s1);
|
|
48
|
+
expect(port.calls).toEqual({ readManifest: 0, derivedRows: 0 });
|
|
49
|
+
expect([s1.puts, s2.deletes]).toEqual([['src/b.ts', 'src/new.ts'], ['src/a.ts']]);
|
|
50
|
+
expect(await factStoreDump(store)).toBe(factGraphDump(g2));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('incremental fast-path saves equal a from-scratch save', async () => {
|
|
54
|
+
const g0 = built();
|
|
55
|
+
const incremental = memoryFactStore();
|
|
56
|
+
let s = await saveFactGraph(incremental, g0);
|
|
57
|
+
let g = g0;
|
|
58
|
+
for (const change of [
|
|
59
|
+
[{ path: 'src/b.ts', facts: { ...bFacts(), contentHash: 'cb2' } }],
|
|
60
|
+
[{ path: 'src/new.ts', facts: file('cn') }],
|
|
61
|
+
[{ path: 'src/auth.ts', facts: null }],
|
|
62
|
+
]) {
|
|
63
|
+
g = updateFactGraph(g, change, FIXTURE_RULES).graph;
|
|
64
|
+
s = await saveFactGraph(incremental, g, s);
|
|
65
|
+
}
|
|
66
|
+
const scratch = memoryFactStore();
|
|
67
|
+
await saveFactGraph(scratch, g);
|
|
68
|
+
expect(await factStoreDump(incremental)).toBe(await factStoreDump(scratch));
|
|
69
|
+
expect(await factStoreDump(incremental)).toBe(factGraphDump(g));
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('a stale previous (another writer changed only derived rows) falls back to the store diff', async () => {
|
|
73
|
+
const g0 = built();
|
|
74
|
+
const store = memoryFactStore();
|
|
75
|
+
const s0 = await saveFactGraph(store, g0);
|
|
76
|
+
const key = derivedRowKey('export-count', 'src/auth.ts');
|
|
77
|
+
const row = g0.derived.get(key)!;
|
|
78
|
+
await store.writeManifest({ epoch: s0.epoch, generation: 2, puts: new Map(), deletes: [] }, [{ ...row, inputs: 'tampered', findings: [] }], []);
|
|
79
|
+
const port = counting(store);
|
|
80
|
+
const g1 = updateFactGraph(g0, [{ path: 'src/b.ts', facts: { ...bFacts(), contentHash: 'cb2' } }], FIXTURE_RULES).graph;
|
|
81
|
+
await saveFactGraph(port, g1, s0);
|
|
82
|
+
expect(port.calls).toEqual({ readManifest: 1, derivedRows: 1 });
|
|
83
|
+
expect(await factStoreDump(store)).toBe(factGraphDump(g1));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('a previous from before a reset (same generation, other epoch) falls back to the store diff', async () => {
|
|
87
|
+
const g0 = built();
|
|
88
|
+
const store = memoryFactStore();
|
|
89
|
+
const s0 = await saveFactGraph(store, g0);
|
|
90
|
+
await store.reset();
|
|
91
|
+
const other = updateFactGraph(g0, [{ path: 'src/new.ts', facts: file('cn') }], FIXTURE_RULES).graph;
|
|
92
|
+
const s1 = await saveFactGraph(store, other);
|
|
93
|
+
expect(s1.generation).toBe(s0.generation);
|
|
94
|
+
const port = counting(store);
|
|
95
|
+
const g = updateFactGraph(g0, [], FIXTURE_RULES).graph;
|
|
96
|
+
await saveFactGraph(port, g, s0);
|
|
97
|
+
expect(port.calls).toEqual({ readManifest: 1, derivedRows: 1 });
|
|
98
|
+
expect(await factStoreDump(store)).toBe(factGraphDump(g));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('a writer that lands between the version read and the commit makes the fast-path save conflict', async () => {
|
|
102
|
+
const g0 = built();
|
|
103
|
+
const store = memoryFactStore();
|
|
104
|
+
const s0 = await saveFactGraph(store, g0);
|
|
105
|
+
const racing: FactStorePort = {
|
|
106
|
+
...store,
|
|
107
|
+
readVersion: async () => {
|
|
108
|
+
const v = await store.readVersion();
|
|
109
|
+
await store.writeManifest({ epoch: v.epoch, generation: v.generation + 1, puts: new Map(), deletes: [] }, [], []);
|
|
110
|
+
return v;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
const g1 = updateFactGraph(g0, [{ path: 'src/new.ts', facts: file('cn') }], FIXTURE_RULES).graph;
|
|
114
|
+
await expect(saveFactGraph(racing, g1, s0)).rejects.toThrow(/fact_store_generation_conflict/);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.findingsProvider.test.ts — `buildGraph` with a `findings` provider (PRD 41 §B5 host seam). The
|
|
3
|
+
* VS Code fact index serves some finding kinds from its own incremental rule rows; it needs them computed over the WHOLE
|
|
4
|
+
* graph, also when the returned view is truncated. The provider sees the untruncated graph, its findings replace the
|
|
5
|
+
* built-in and pack findings of the kinds it owns, and without a provider the output is byte-identical.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { buildGraph } from '../knowledge/build.js';
|
|
9
|
+
import { brokenLinkRule } from '../knowledge/packs/docs.js';
|
|
10
|
+
import { findingId, requestKeyFor } from '../knowledge/findings.js';
|
|
11
|
+
import type { BuildGraphInput, Finding, FindingsProvider, KnowledgeGraph, KnowledgePack, StoredFact } from '../knowledge/model.js';
|
|
12
|
+
import { edge, extractedOf, fileNode, ref, ROOT } from '../knowledge/testkit.test-util.js';
|
|
13
|
+
|
|
14
|
+
const PACK: KnowledgePack = { id: 'docs', parsers: [], findings: [brokenLinkRule] };
|
|
15
|
+
|
|
16
|
+
/** 40 linked files, a cycle back to the start, and one dangling link (a `broken-link` finding). */
|
|
17
|
+
function chain(): BuildGraphInput {
|
|
18
|
+
const paths = Array.from({ length: 40 }, (_, i) => `d${i % 4}/f${String(i).padStart(2, '0')}.md`);
|
|
19
|
+
const extracted = paths.map((p, i) => extractedOf(fileNode(p), i + 1 < paths.length ? [edge(p, paths[i + 1]!)] : [edge(p, paths[0]!)]));
|
|
20
|
+
extracted[30]!.edges.push(edge(paths[30]!, 'gone/missing.md'));
|
|
21
|
+
return { rootId: ROOT, packs: [PACK], extracted, facts: [] as StoredFact[], relations: [] };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const VIEW = { maxNodes: 8, focus: [ref('d0/f00.md')] };
|
|
25
|
+
|
|
26
|
+
describe('regression: buildGraph findings provider', () => {
|
|
27
|
+
it('without a provider the output is byte-identical, and its findings are the whole graph\'s', () => {
|
|
28
|
+
const plain = buildGraph(chain(), VIEW);
|
|
29
|
+
expect(plain.stats.truncated).toBe(true);
|
|
30
|
+
expect(JSON.stringify(buildGraph(chain(), { ...VIEW, findings: undefined }))).toBe(JSON.stringify(plain));
|
|
31
|
+
// A provider that owns nothing changes nothing either.
|
|
32
|
+
const none: FindingsProvider = { kinds: [], findings: () => [] };
|
|
33
|
+
expect(JSON.stringify(buildGraph(chain(), { ...VIEW, findings: none }))).toBe(JSON.stringify(plain));
|
|
34
|
+
const whole = buildGraph(chain(), { maxNodes: 2000 });
|
|
35
|
+
expect(whole.stats.truncated).toBe(false);
|
|
36
|
+
expect(plain.findings).toEqual(whole.findings);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('a truncated build gets the provider\'s findings for the kinds it owns, computed over the whole graph', () => {
|
|
40
|
+
const plain = buildGraph(chain(), VIEW);
|
|
41
|
+
expect(plain.findings.some((f) => f.kind === 'broken-link')).toBe(true);
|
|
42
|
+
|
|
43
|
+
let seen: KnowledgeGraph | undefined;
|
|
44
|
+
let seenRefs = 0;
|
|
45
|
+
const far = ref('d2/f22.md');
|
|
46
|
+
const provider: FindingsProvider = {
|
|
47
|
+
kinds: ['broken-link', 'cycle'],
|
|
48
|
+
findings: ({ graph, knowledge }) => {
|
|
49
|
+
seen = graph;
|
|
50
|
+
seenRefs = knowledge.byRef.size;
|
|
51
|
+
const mine: Finding = { id: '', kind: 'broken-link', pack: 'docs', nodes: [far, far], severity: 'error', params: { from: 'index' } };
|
|
52
|
+
const notMine: Finding = { id: 'x', kind: 'god-module', pack: 'docs', nodes: [far], severity: 'warn', params: {} };
|
|
53
|
+
return [mine, notMine];
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
const g = buildGraph(chain(), { ...VIEW, findings: provider });
|
|
57
|
+
|
|
58
|
+
// The provider saw the WHOLE graph, not the cut view.
|
|
59
|
+
expect(g.stats.truncated).toBe(true);
|
|
60
|
+
expect(seen!.nodes.length).toBe(buildGraph(chain(), { maxNodes: 2000 }).nodes.length);
|
|
61
|
+
expect(seen!.nodes.length).toBeGreaterThan(g.nodes.length);
|
|
62
|
+
expect(seenRefs).toBe(seen!.nodes.length);
|
|
63
|
+
|
|
64
|
+
// Owned kinds come only from the provider (no built-in cycle, no pack broken-link); other kinds pass through.
|
|
65
|
+
expect(g.findings.filter((f) => f.kind === 'cycle')).toEqual([]);
|
|
66
|
+
const broken = g.findings.filter((f) => f.kind === 'broken-link');
|
|
67
|
+
expect(broken).toEqual([{
|
|
68
|
+
// Normalized exactly like a pack finding: the id hashes the nodes as given, then the nodes are deduped and sorted.
|
|
69
|
+
id: findingId('broken-link', [far, far]), kind: 'broken-link', pack: 'docs', nodes: [far], severity: 'error', params: { from: 'index' },
|
|
70
|
+
requestKey: requestKeyFor('broken-link'),
|
|
71
|
+
}]);
|
|
72
|
+
expect(g.findings.some((f) => f.kind === 'god-module' && f.id === 'x')).toBe(false);
|
|
73
|
+
const others = (fs: readonly Finding[]) => fs.filter((f) => f.kind !== 'broken-link' && f.kind !== 'cycle');
|
|
74
|
+
expect(others(g.findings)).toEqual(others(plain.findings));
|
|
75
|
+
// Sorted like every finding list: severity, then id.
|
|
76
|
+
expect(g.findings[0]!.severity).toBe('error');
|
|
77
|
+
// Truncation keeps the provider's finding nodes, as it keeps any finding's.
|
|
78
|
+
expect(g.nodes.some((n) => n.ref === far)).toBe(true);
|
|
79
|
+
});
|
|
80
|
+
});
|