@seanhogg/builderforce-memory 2026.10.43 → 2026.10.44
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/extractFile.d.ts +15 -0
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +40 -17
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +64 -0
- package/dist/knowledge/extractJob.d.ts.map +1 -0
- package/dist/knowledge/extractJob.js +47 -0
- package/dist/knowledge/extractJob.js.map +1 -0
- package/dist/knowledge/index.d.ts +10 -1
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +6 -1
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/judge.d.ts +23 -5
- package/dist/knowledge/judge.d.ts.map +1 -1
- package/dist/knowledge/judge.js +14 -76
- package/dist/knowledge/judge.js.map +1 -1
- package/dist/knowledge/judgeCalls.d.ts +52 -0
- package/dist/knowledge/judgeCalls.d.ts.map +1 -0
- package/dist/knowledge/judgeCalls.js +107 -0
- package/dist/knowledge/judgeCalls.js.map +1 -0
- package/dist/knowledge/modelLimiter.d.ts +20 -0
- package/dist/knowledge/modelLimiter.d.ts.map +1 -0
- package/dist/knowledge/modelLimiter.js +63 -0
- package/dist/knowledge/modelLimiter.js.map +1 -0
- package/dist/knowledge/review.d.ts +6 -2
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +108 -112
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewJudge.d.ts +95 -0
- package/dist/knowledge/reviewJudge.d.ts.map +1 -0
- package/dist/knowledge/reviewJudge.js +119 -0
- package/dist/knowledge/reviewJudge.js.map +1 -0
- package/dist/knowledge/reviewModel.d.ts +30 -2
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.d.ts +53 -0
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -0
- package/dist/knowledge/reviewPrefetch.js +65 -0
- package/dist/knowledge/reviewPrefetch.js.map +1 -0
- package/dist/knowledge/reviewRun.d.ts +70 -0
- package/dist/knowledge/reviewRun.d.ts.map +1 -0
- package/dist/knowledge/reviewRun.js +88 -0
- package/dist/knowledge/reviewRun.js.map +1 -0
- package/dist/knowledge/reviewRunModel.d.ts +35 -0
- package/dist/knowledge/reviewRunModel.d.ts.map +1 -0
- package/dist/knowledge/reviewRunModel.js +27 -0
- package/dist/knowledge/reviewRunModel.js.map +1 -0
- package/package.json +3 -3
- package/src/knowledge/extractFile.ts +49 -17
- package/src/knowledge/extractJob.ts +91 -0
- package/src/knowledge/index.ts +10 -1
- package/src/knowledge/judge.ts +24 -70
- package/src/knowledge/judgeCalls.ts +136 -0
- package/src/knowledge/modelLimiter.test.ts +68 -0
- package/src/knowledge/modelLimiter.ts +68 -0
- package/src/knowledge/review.failures.test.ts +277 -0
- package/src/knowledge/review.ordered.test.ts +114 -0
- package/src/knowledge/review.ts +102 -100
- package/src/knowledge/reviewJudge.ts +155 -0
- package/src/knowledge/reviewModel.ts +30 -2
- package/src/knowledge/reviewPrefetch.ts +86 -0
- package/src/knowledge/reviewRun.test.ts +96 -0
- package/src/knowledge/reviewRun.ts +137 -0
- package/src/knowledge/reviewRunModel.ts +53 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/judgeCalls.ts — judging one file's sections, in two stages (PRD 41 A8).
|
|
3
|
+
*
|
|
4
|
+
* • {@link callSections} — the CALL stage: one model call per section within a budget slice, touching
|
|
5
|
+
* no shared state, so several files can be in it at once (optionally under ONE shared
|
|
6
|
+
* {@link ModelLimiter}).
|
|
7
|
+
* • {@link applyAnswers} — the APPLY stage: merges answers into the batch and the shared entity map.
|
|
8
|
+
* Synchronous; the review's one ordered writer calls it in plan order, which keeps the stored
|
|
9
|
+
* bytes independent of how many files were judged at once.
|
|
10
|
+
*
|
|
11
|
+
* {@link judgeSections} is both stages for one file.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { hashText } from '../ingest/hash.js';
|
|
15
|
+
import {
|
|
16
|
+
budgetLeft, call, claimContent, JUDGE_CONCURRENCY, REVIEW_FACT_SOURCE, runPool, validateExtract,
|
|
17
|
+
type ExtractArgs, type JudgeBudget, type SectionToJudge,
|
|
18
|
+
} from './judge.js';
|
|
19
|
+
import type { ModelLimiter } from './modelLimiter.js';
|
|
20
|
+
import type { JudgementPort, NodeRef, StoredFact } from './model.js';
|
|
21
|
+
import { compareStr, factRef } from './refs.js';
|
|
22
|
+
import { entityKey, normalizeKey } from './resolve.js';
|
|
23
|
+
import { reasonOf } from './reviewRunModel.js';
|
|
24
|
+
|
|
25
|
+
/** A section's validated answer: the output of the call stage, applied later by {@link applyAnswers}. */
|
|
26
|
+
export interface SectionAnswer { section: SectionToJudge; v: ReturnType<typeof validateExtract> }
|
|
27
|
+
|
|
28
|
+
export interface CallSectionsArgs {
|
|
29
|
+
port: JudgementPort;
|
|
30
|
+
fileHash: string;
|
|
31
|
+
sections: readonly SectionToJudge[];
|
|
32
|
+
/** This file's slice of the review budget (its own `used`). */
|
|
33
|
+
budget: JudgeBudget;
|
|
34
|
+
/** Shared across the files of a review: caps the calls in flight and adapts to rate limits. */
|
|
35
|
+
limiter?: ModelLimiter;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface CallSectionsResult {
|
|
40
|
+
answers: SectionAnswer[];
|
|
41
|
+
/** Sections cut by the budget or whose call failed. */
|
|
42
|
+
unjudged: number;
|
|
43
|
+
/** Calls the port (or the provider behind it) failed. */
|
|
44
|
+
errors: number;
|
|
45
|
+
/** The first failure's message, single line. */
|
|
46
|
+
firstError?: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/** Answers come back in section order. Throws on abort. */
|
|
51
|
+
export async function callSections(a: CallSectionsArgs): Promise<CallSectionsResult> {
|
|
52
|
+
const slots: Array<SectionAnswer | undefined> = new Array(a.sections.length);
|
|
53
|
+
let unjudged = 0;
|
|
54
|
+
let errors = 0;
|
|
55
|
+
let firstError: string | undefined;
|
|
56
|
+
const hooks = {
|
|
57
|
+
...(a.limiter ? { limiter: a.limiter } : {}),
|
|
58
|
+
onError: (err: unknown) => { errors += 1; firstError ??= reasonOf(err); },
|
|
59
|
+
};
|
|
60
|
+
// The budget check and `call`'s synchronous `used` increment happen on the same tick (no await
|
|
61
|
+
// between), so concurrency cannot overshoot `modelCalls`.
|
|
62
|
+
const abortError = () => a.signal?.reason ?? new Error('aborted');
|
|
63
|
+
await runPool(a.sections.map((section, idx) => ({ section, idx })), JUDGE_CONCURRENCY, async ({ section, idx }) => {
|
|
64
|
+
// Honoured per section, not only when the port throws: the caller drops this file whole.
|
|
65
|
+
if (a.signal?.aborted) throw abortError();
|
|
66
|
+
if (!budgetLeft(a.budget)) { unjudged += 1; return; }
|
|
67
|
+
const answer = await call(a.port, {
|
|
68
|
+
kind: 'extract', items: [{ ref: section.ref, text: section.text, sourceHash: a.fileHash }],
|
|
69
|
+
...(a.signal ? { signal: a.signal } : {}),
|
|
70
|
+
}, a.budget, hooks);
|
|
71
|
+
// A failed call judged nothing: not counted judged, so the file stays changed and is retried.
|
|
72
|
+
if (!answer) { unjudged += 1; return; }
|
|
73
|
+
// The abort can land while a call is in flight (the port sees the signal): a section that
|
|
74
|
+
// finished after the abort must not count as judged, or the caller would not re-judge it.
|
|
75
|
+
if (a.signal?.aborted) throw abortError();
|
|
76
|
+
slots[idx] = { section, v: validateExtract(answer.result, section.ref) };
|
|
77
|
+
});
|
|
78
|
+
return { answers: slots.filter((s): s is SectionAnswer => !!s), unjudged, errors, ...(firstError !== undefined ? { firstError } : {}) };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Judges each section within the budget; the rest — and any whose call failed — are counted `unjudged`. */
|
|
82
|
+
export async function judgeSections(a: ExtractArgs): Promise<Array<{ ref: NodeRef; text: string }>> {
|
|
83
|
+
const { answers, unjudged } = await callSections({
|
|
84
|
+
port: a.port, fileHash: a.fileHash, sections: a.sections, budget: a.budget, ...(a.signal ? { signal: a.signal } : {}),
|
|
85
|
+
});
|
|
86
|
+
a.batch.unjudged += unjudged;
|
|
87
|
+
return applyAnswers(a, answers);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Merges answers into the batch and the shared entities map, in the order given. */
|
|
91
|
+
export function applyAnswers(
|
|
92
|
+
a: Pick<ExtractArgs, 'pack' | 'path' | 'fileHash' | 'batch' | 'entities' | 'onJudged'>,
|
|
93
|
+
answers: readonly SectionAnswer[],
|
|
94
|
+
): Array<{ ref: NodeRef; text: string }> {
|
|
95
|
+
const claims: Array<{ ref: NodeRef; text: string }> = [];
|
|
96
|
+
const anchor = { path: a.path, contentHash: a.fileHash };
|
|
97
|
+
for (const { section, v } of answers) {
|
|
98
|
+
a.batch.invalid += v.invalid;
|
|
99
|
+
a.batch.judged += 1;
|
|
100
|
+
a.onJudged(section.ref);
|
|
101
|
+
const rel = (from: NodeRef, to: NodeRef, kind: string) =>
|
|
102
|
+
a.batch.relation({ from, to, kind, weight: 1, origin: 'model', sourceHash: a.fileHash });
|
|
103
|
+
|
|
104
|
+
const entityRefs = new Map<string, NodeRef>();
|
|
105
|
+
for (const e of v.entities) {
|
|
106
|
+
const key = entityKey(a.pack, e.name);
|
|
107
|
+
const prior = a.entities.get(key);
|
|
108
|
+
const anchors = [...(prior?.fileAnchors ?? []).filter((x) => x.path !== a.path), anchor]
|
|
109
|
+
.sort((x, y) => compareStr(x.path, y.path));
|
|
110
|
+
const fact: StoredFact = {
|
|
111
|
+
key, content: prior?.content ?? `${e.name} (${e.type})`, source: REVIEW_FACT_SOURCE,
|
|
112
|
+
importance: prior?.importance ?? 0.5, origin: prior?.origin ?? 'model', fileAnchors: anchors,
|
|
113
|
+
};
|
|
114
|
+
a.entities.set(key, fact);
|
|
115
|
+
a.batch.fact(fact);
|
|
116
|
+
entityRefs.set(normalizeKey(e.name), key);
|
|
117
|
+
rel(section.ref, key, 'mentions');
|
|
118
|
+
}
|
|
119
|
+
for (const c of v.claims) {
|
|
120
|
+
const key = `claim:${hashText([section.ref, c.subject, c.predicate, c.object].join('\u0000'))}`;
|
|
121
|
+
const text = `${c.subject} ${c.predicate} ${c.object}`;
|
|
122
|
+
a.batch.fact({
|
|
123
|
+
key, content: claimContent(text, c.quote), source: REVIEW_FACT_SOURCE,
|
|
124
|
+
importance: 0.5, origin: 'model', fileAnchors: [anchor],
|
|
125
|
+
});
|
|
126
|
+
const ref = factRef(key);
|
|
127
|
+
rel(ref, section.ref, 'about');
|
|
128
|
+
for (const term of [c.subject, c.object]) {
|
|
129
|
+
const ent = entityRefs.get(normalizeKey(term));
|
|
130
|
+
if (ent) rel(ref, ent, 'mentions');
|
|
131
|
+
}
|
|
132
|
+
claims.push({ ref, text });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return claims;
|
|
136
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/modelLimiter.test.ts
|
|
3
|
+
* The review's ONE cap on model calls in flight (PRD 41 A8): bounded, AIMD on rate limits, and
|
|
4
|
+
* nothing starts once the signal has aborted.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createModelLimiter, isRateLimit } from './modelLimiter.js';
|
|
8
|
+
|
|
9
|
+
const rateLimited = () => Object.assign(new Error('429 rate limited'), { status: 429 });
|
|
10
|
+
const ok = async () => 'ok';
|
|
11
|
+
|
|
12
|
+
describe('createModelLimiter', () => {
|
|
13
|
+
it('never has more calls in flight than its width', async () => {
|
|
14
|
+
const limiter = createModelLimiter(3);
|
|
15
|
+
let live = 0;
|
|
16
|
+
let max = 0;
|
|
17
|
+
await Promise.all(Array.from({ length: 12 }, () => limiter.run(async () => {
|
|
18
|
+
live += 1; max = Math.max(max, live);
|
|
19
|
+
await new Promise((r) => setTimeout(r, 1));
|
|
20
|
+
live -= 1;
|
|
21
|
+
})));
|
|
22
|
+
expect(max).toBe(3);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('halves on a rate limit (minimum 1) and grows back by 1 per growEvery successes', async () => {
|
|
26
|
+
const limiter = createModelLimiter(8, { growEvery: 3 });
|
|
27
|
+
await expect(limiter.run(async () => { throw rateLimited(); })).rejects.toThrow('429');
|
|
28
|
+
expect(limiter.width).toBe(4);
|
|
29
|
+
await expect(limiter.run(async () => { throw rateLimited(); })).rejects.toThrow('429');
|
|
30
|
+
expect(limiter.width).toBe(2);
|
|
31
|
+
await expect(limiter.run(async () => { throw rateLimited(); })).rejects.toThrow('429');
|
|
32
|
+
await expect(limiter.run(async () => { throw rateLimited(); })).rejects.toThrow('429');
|
|
33
|
+
expect(limiter.width).toBe(1);
|
|
34
|
+
|
|
35
|
+
for (let i = 0; i < 3; i++) await limiter.run(ok);
|
|
36
|
+
expect(limiter.width).toBe(2);
|
|
37
|
+
for (let i = 0; i < 3 * 10; i++) await limiter.run(ok);
|
|
38
|
+
expect(limiter.width).toBe(8); // back at the cap, never above
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('a failure that is not a rate limit leaves the width alone', async () => {
|
|
42
|
+
const limiter = createModelLimiter(4);
|
|
43
|
+
await expect(limiter.run(async () => { throw new Error('boom'); })).rejects.toThrow('boom');
|
|
44
|
+
expect(limiter.width).toBe(4);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('rejects a waiting call whose signal aborted instead of starting it', async () => {
|
|
48
|
+
const limiter = createModelLimiter(1);
|
|
49
|
+
const controller = new AbortController();
|
|
50
|
+
let started = 0;
|
|
51
|
+
const first = limiter.run(async () => { started += 1; await new Promise((r) => setTimeout(r, 5)); });
|
|
52
|
+
const waiting = limiter.run(async () => { started += 1; }, controller.signal);
|
|
53
|
+
controller.abort();
|
|
54
|
+
await expect(waiting).rejects.toBeDefined();
|
|
55
|
+
await first;
|
|
56
|
+
expect(started).toBe(1);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('isRateLimit', () => {
|
|
61
|
+
it('recognises a 429 status or the usual wording', () => {
|
|
62
|
+
expect(isRateLimit({ status: 429 })).toBe(true);
|
|
63
|
+
expect(isRateLimit(new Error('Rate limit exceeded'))).toBe(true);
|
|
64
|
+
expect(isRateLimit(new Error('HTTP 429'))).toBe(true);
|
|
65
|
+
expect(isRateLimit(new Error('401 unauthorized'))).toBe(false);
|
|
66
|
+
expect(isRateLimit(null)).toBe(false);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge/modelLimiter.ts — ONE cap on the model calls in flight across every file of a review
|
|
3
|
+
* (PRD 41 A8), so judging N files at once does not multiply the provider's load.
|
|
4
|
+
*
|
|
5
|
+
* AIMD: a rate-limit answer halves the width (minimum 1); every `growEvery` successful calls grow it
|
|
6
|
+
* by 1, back up to the cap. Waiting calls start in order; one whose signal has aborted is rejected
|
|
7
|
+
* instead of started, so nothing starts after an abort.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface ModelLimiter {
|
|
11
|
+
/** Calls allowed in flight right now (1..max). */
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly max: number;
|
|
14
|
+
run<T>(fn: () => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** An error that says the provider is rate limiting us (HTTP 429 or the usual wording). */
|
|
18
|
+
export function isRateLimit(err: unknown): boolean {
|
|
19
|
+
const e = err as { status?: unknown; statusCode?: unknown; message?: unknown } | null;
|
|
20
|
+
if (e?.status === 429 || e?.statusCode === 429) return true;
|
|
21
|
+
return typeof e?.message === 'string' && /\b429\b|rate.?limit|too many requests/i.test(e.message);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface Waiter { start(): void; reject(reason: unknown): void; signal: AbortSignal | undefined }
|
|
25
|
+
|
|
26
|
+
export function createModelLimiter(max: number, opts: { growEvery?: number } = {}): ModelLimiter {
|
|
27
|
+
const cap = Math.max(1, Math.floor(max));
|
|
28
|
+
const growEvery = Math.max(1, Math.floor(opts.growEvery ?? 20));
|
|
29
|
+
let width = cap;
|
|
30
|
+
let active = 0;
|
|
31
|
+
let successes = 0;
|
|
32
|
+
const waiting: Waiter[] = [];
|
|
33
|
+
|
|
34
|
+
const pump = () => {
|
|
35
|
+
while (active < width && waiting.length > 0) {
|
|
36
|
+
const w = waiting.shift()!;
|
|
37
|
+
if (w.signal?.aborted) { w.reject(w.signal.reason ?? new Error('aborted')); continue; }
|
|
38
|
+
active += 1;
|
|
39
|
+
w.start();
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
get width() { return width; },
|
|
45
|
+
max: cap,
|
|
46
|
+
run<T>(fn: () => Promise<T>, signal?: AbortSignal): Promise<T> {
|
|
47
|
+
return new Promise<T>((resolve, reject) => {
|
|
48
|
+
waiting.push({
|
|
49
|
+
signal, reject,
|
|
50
|
+
start: () => {
|
|
51
|
+
(async () => fn())().then(
|
|
52
|
+
(v) => {
|
|
53
|
+
successes += 1;
|
|
54
|
+
if (successes >= growEvery && width < cap) { width += 1; successes = 0; }
|
|
55
|
+
resolve(v);
|
|
56
|
+
},
|
|
57
|
+
(err) => {
|
|
58
|
+
if (isRateLimit(err)) { width = Math.max(1, Math.floor(width / 2)); successes = 0; }
|
|
59
|
+
reject(err);
|
|
60
|
+
},
|
|
61
|
+
).finally(() => { active -= 1; pump(); });
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
pump();
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/review.failures.test.ts
|
|
3
|
+
* PRD 41 A8: no single failure ends a review, every file in every phase is a step event, and a host's
|
|
4
|
+
* extraction pool is a port. A throwing extractor / judge is recorded and skipped; abort still stops.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { hashText } from '../ingest/hash.js';
|
|
8
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
9
|
+
import { htmlParser, markdownParser, plainTextParser } from '../ingest/parsers.js';
|
|
10
|
+
import { extractJob, type ExtractJob, type ExtractPool } from './extractJob.js';
|
|
11
|
+
import type { JudgementPort, KnowledgePack, StoredFact } from './model.js';
|
|
12
|
+
import { LocalSnapshotStore } from './stores/localSnapshotStore.js';
|
|
13
|
+
import type { ReviewStep } from './reviewRunModel.js';
|
|
14
|
+
import { DOCS_PACK } from './packs/docs.js';
|
|
15
|
+
import { reviewDirectory } from './review.js';
|
|
16
|
+
import { filesManifestKey, manifestMap } from './sources.js';
|
|
17
|
+
import { args, fakeJudge, FILES, memPersistence, memSource, memStore, ROOT } from './testkit.test-util.js';
|
|
18
|
+
|
|
19
|
+
/** The docs pack whose markdown extractor throws for `bad.md`. */
|
|
20
|
+
const poisoned: KnowledgePack = {
|
|
21
|
+
...DOCS_PACK,
|
|
22
|
+
parsers: [
|
|
23
|
+
{ ...markdownParser, extract: (s, sec, ctx) => {
|
|
24
|
+
if (s.id === 'bad.md') throw new Error('poisoned extractor');
|
|
25
|
+
return markdownParser.extract!(s, sec, ctx);
|
|
26
|
+
} },
|
|
27
|
+
htmlParser, plainTextParser,
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const anchoredTo = (facts: readonly StoredFact[], path: string) =>
|
|
32
|
+
facts.filter((f) => f.fileAnchors.some((a) => a.path === path));
|
|
33
|
+
|
|
34
|
+
describe('a failing file never ends a review', () => {
|
|
35
|
+
it('a throwing extractor is one failed step; the run completes and the prior knowledge is kept', async () => {
|
|
36
|
+
const source = memSource({ ...FILES, 'bad.md': '# Bad\nversion one\n' });
|
|
37
|
+
const store = memStore();
|
|
38
|
+
const manifest = new InMemoryIngestManifest();
|
|
39
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
40
|
+
const before = anchoredTo(await store.facts({ rootId: ROOT }), 'bad.md');
|
|
41
|
+
const priorHash = (await manifestMap(manifest, filesManifestKey(ROOT))).get('bad.md');
|
|
42
|
+
expect(before.length).toBeGreaterThan(0);
|
|
43
|
+
|
|
44
|
+
source.files['bad.md'] = '# Bad\nversion two\n';
|
|
45
|
+
const steps: ReviewStep[] = [];
|
|
46
|
+
const report = await reviewDirectory(args(source, store, manifest, {
|
|
47
|
+
packs: [poisoned], judgement: fakeJudge(), onStep: (s) => steps.push(s),
|
|
48
|
+
}));
|
|
49
|
+
expect(report.aborted).toBe(false);
|
|
50
|
+
expect(report.extractErrors).toBe(1);
|
|
51
|
+
expect(report.failures).toEqual([{ path: 'bad.md', phase: 'extract', reason: 'poisoned extractor' }]);
|
|
52
|
+
const failed = steps.filter((s) => s.outcome === 'failed');
|
|
53
|
+
expect(failed).toHaveLength(1);
|
|
54
|
+
expect(failed[0]).toMatchObject({ path: 'bad.md', phase: 'extract', reason: 'poisoned extractor' });
|
|
55
|
+
expect(anchoredTo(await store.facts({ rootId: ROOT }), 'bad.md')).toEqual(before);
|
|
56
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('bad.md')).toBe(priorHash);
|
|
57
|
+
|
|
58
|
+
// The next review (extractor fixed) retries it.
|
|
59
|
+
const retry = await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
60
|
+
expect(retry.extractErrors).toBe(0);
|
|
61
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('bad.md')).toBe(hashText(source.files['bad.md']!));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('a judge that throws is recorded; the file stays unjudged and the run goes on', async () => {
|
|
65
|
+
const source = memSource({ ...FILES });
|
|
66
|
+
const judge = fakeJudge();
|
|
67
|
+
const good = judge.judge.bind(judge);
|
|
68
|
+
judge.judge = async (req) => {
|
|
69
|
+
if (req.items[0]!.ref.includes('b.md')) return { get invalid(): number { throw new Error('judge exploded'); } } as never;
|
|
70
|
+
return good(req);
|
|
71
|
+
};
|
|
72
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), { judgement: judge }));
|
|
73
|
+
expect(report.aborted).toBe(false);
|
|
74
|
+
expect(report.failures).toEqual([{ path: 'b.md', phase: 'judge', reason: 'judge: judge exploded' }]);
|
|
75
|
+
expect(report.unjudged).toBeGreaterThan(0);
|
|
76
|
+
expect(report.judged).toBeGreaterThan(0);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('when every call of a file fails, it is a judge failure that leaves the file exactly as it was', async () => {
|
|
80
|
+
const source = memSource({ ...FILES });
|
|
81
|
+
const store = memStore();
|
|
82
|
+
const manifest = new InMemoryIngestManifest();
|
|
83
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
84
|
+
const factsBefore = anchoredTo(await store.facts({ rootId: ROOT }), 'a.md');
|
|
85
|
+
const priorHash = (await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md');
|
|
86
|
+
expect(factsBefore.length).toBeGreaterThan(0);
|
|
87
|
+
|
|
88
|
+
source.files['a.md'] = '# A\nalpha changed\n';
|
|
89
|
+
const steps: ReviewStep[] = [];
|
|
90
|
+
const down = { async judge(): Promise<never> { throw Object.assign(new Error('429 rate limited'), { status: 429 }); } };
|
|
91
|
+
const report = await reviewDirectory(args(source, store, manifest, { judgement: down, onStep: (s) => steps.push(s) }));
|
|
92
|
+
expect(report.aborted).toBe(false);
|
|
93
|
+
expect(report.failures).toEqual([{ path: 'a.md', phase: 'judge', reason: 'judge: 429 rate limited' }]);
|
|
94
|
+
expect(steps.filter((s) => s.path === 'a.md' && s.phase === 'judge')).toEqual([
|
|
95
|
+
expect.objectContaining({ outcome: 'failed', reason: 'judge: 429 rate limited' }),
|
|
96
|
+
]);
|
|
97
|
+
expect(steps.some((s) => s.path === 'a.md' && s.phase === 'write')).toBe(false);
|
|
98
|
+
// Prior knowledge is not stale, the manifest hash is the old one, and the next review retries it.
|
|
99
|
+
expect(anchoredTo(await store.facts({ rootId: ROOT }), 'a.md')).toEqual(factsBefore);
|
|
100
|
+
expect((await store.relations({ rootId: ROOT })).filter((r) => r.kind === 'about').every((r) => !r.staleAt)).toBe(true);
|
|
101
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md')).toBe(priorHash);
|
|
102
|
+
const retry = await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
103
|
+
expect(retry.failures).toEqual([]);
|
|
104
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md')).toBe(hashText(source.files['a.md']!));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('when only some calls fail, the step is ok and says how many were unjudged', async () => {
|
|
108
|
+
const source = memSource({ 'two.md': '# Good\ngood body\n\n## Other\nbad body\n' });
|
|
109
|
+
const base = fakeJudge();
|
|
110
|
+
const flaky: JudgementPort = {
|
|
111
|
+
async judge(req) {
|
|
112
|
+
if (req.items[0]!.text.includes('bad body')) throw new Error('flaky');
|
|
113
|
+
return base.judge(req);
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
const steps: ReviewStep[] = [];
|
|
117
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), { judgement: flaky, onStep: (s) => steps.push(s) }));
|
|
118
|
+
expect(report.failures).toEqual([]);
|
|
119
|
+
expect(steps.find((s) => s.phase === 'judge')).toMatchObject({ outcome: 'ok', reason: '1 unjudged (1 errors)' });
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('extractPool', () => {
|
|
124
|
+
it('is called once per changed file with plain data, and its results are stored', async () => {
|
|
125
|
+
const source = memSource({ ...FILES });
|
|
126
|
+
const store = memStore();
|
|
127
|
+
const jobs: ExtractJob[] = [];
|
|
128
|
+
const steps: ReviewStep[] = [];
|
|
129
|
+
const extractPool: ExtractPool = async (job) => {
|
|
130
|
+
jobs.push(job);
|
|
131
|
+
const copy = JSON.parse(JSON.stringify(job)) as ExtractJob; // crosses a thread boundary: plain data only
|
|
132
|
+
const out = extractJob(copy, [DOCS_PACK]);
|
|
133
|
+
return { ...out, extracted: out.extracted.map((e) => ({
|
|
134
|
+
...e, nodes: e.nodes.map((n) => (n.kind === 'file' ? { ...n, label: `pool:${n.label}` } : n)),
|
|
135
|
+
})) };
|
|
136
|
+
};
|
|
137
|
+
const report = await reviewDirectory(args(source, store, new InMemoryIngestManifest(), {
|
|
138
|
+
extractPool, concurrency: 2, onStep: (s) => steps.push(s),
|
|
139
|
+
}));
|
|
140
|
+
expect(jobs.map((j) => j.path).sort()).toEqual(['a.md', 'b.md', 'c.md']);
|
|
141
|
+
expect(report.extracted).toBe(3);
|
|
142
|
+
const cached = await store.getExtracted!(hashText(FILES['a.md']));
|
|
143
|
+
expect(cached!.flatMap((e) => e.nodes).some((n) => n.label === 'pool:a.md')).toBe(true);
|
|
144
|
+
const extractSteps = steps.filter((s) => s.phase === 'extract');
|
|
145
|
+
expect(extractSteps).toHaveLength(3);
|
|
146
|
+
for (const s of extractSteps) expect([0, 1]).toContain(s.lane);
|
|
147
|
+
|
|
148
|
+
// A second review finds every extract cached: the pool is not asked again.
|
|
149
|
+
jobs.length = 0;
|
|
150
|
+
await reviewDirectory(args(source, store, new InMemoryIngestManifest(), { extractPool, force: true }));
|
|
151
|
+
expect(jobs).toHaveLength(0);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('asks the pool for sections only when the file is judged, and never parses in-thread', async () => {
|
|
155
|
+
const source = memSource({ ...FILES });
|
|
156
|
+
const jobs: ExtractJob[] = [];
|
|
157
|
+
const extractPool: ExtractPool = async (job) => { jobs.push(job); return extractJob(job, [DOCS_PACK]); };
|
|
158
|
+
const store = memStore();
|
|
159
|
+
const manifest = new InMemoryIngestManifest();
|
|
160
|
+
await reviewDirectory(args(source, store, manifest, { extractPool }));
|
|
161
|
+
expect(jobs.every((j) => !j.needSections && !j.sectionsOnly)).toBe(true);
|
|
162
|
+
jobs.length = 0;
|
|
163
|
+
const judge = fakeJudge();
|
|
164
|
+
const report = await reviewDirectory(args(source, store, manifest, { extractPool, judgement: judge, force: true }));
|
|
165
|
+
expect(report.failures).toEqual([]);
|
|
166
|
+
// The extracts are cached, so only the sections are asked for.
|
|
167
|
+
expect(jobs).toHaveLength(3);
|
|
168
|
+
expect(jobs.every((j) => j.sectionsOnly)).toBe(true);
|
|
169
|
+
expect(judge.requests.length).toBeGreaterThan(0);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
const bad: Array<[string, ExtractPool]> = [
|
|
173
|
+
['rejects', async () => { throw new Error('worker crashed'); }],
|
|
174
|
+
['returns nothing although the packs accept the file', async () => ({ extracted: [] })],
|
|
175
|
+
['returns another file\'s extract', async (job) => {
|
|
176
|
+
const other = extractJob({ ...job, path: 'other.md' }, [DOCS_PACK]);
|
|
177
|
+
return other;
|
|
178
|
+
}],
|
|
179
|
+
];
|
|
180
|
+
it.each(bad)('a pool that %s is a failed extract step and the prior knowledge is kept', async (_name, pool) => {
|
|
181
|
+
const source = memSource({ ...FILES });
|
|
182
|
+
const store = memStore();
|
|
183
|
+
const manifest = new InMemoryIngestManifest();
|
|
184
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge() }));
|
|
185
|
+
const before = anchoredTo(await store.facts({ rootId: ROOT }), 'a.md');
|
|
186
|
+
const priorHash = (await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md');
|
|
187
|
+
|
|
188
|
+
source.files['a.md'] = '# A\nalpha edited\n';
|
|
189
|
+
const steps: ReviewStep[] = [];
|
|
190
|
+
const report = await reviewDirectory(args(source, store, manifest, { extractPool: pool, judgement: fakeJudge(), onStep: (s) => steps.push(s) }));
|
|
191
|
+
expect(report.aborted).toBe(false);
|
|
192
|
+
expect(report.extractErrors).toBe(1);
|
|
193
|
+
expect(steps.filter((s) => s.path === 'a.md' && s.outcome === 'failed')).toHaveLength(1);
|
|
194
|
+
expect(anchoredTo(await store.facts({ rootId: ROOT }), 'a.md')).toEqual(before);
|
|
195
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('a.md')).toBe(priorHash);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('abort', () => {
|
|
200
|
+
it('an abort mid-extract stops promptly and keeps the work written before it', async () => {
|
|
201
|
+
const N = 16;
|
|
202
|
+
const text = Object.fromEntries(Array.from({ length: N }, (_, i) => [`d${i}.md`, `# T${i}\nbody ${i}\n`]));
|
|
203
|
+
const source = memSource(text);
|
|
204
|
+
const read = source.read.bind(source);
|
|
205
|
+
const controller = new AbortController();
|
|
206
|
+
source.read = async (path) => {
|
|
207
|
+
if (path === 'd4.md') controller.abort();
|
|
208
|
+
return read(path);
|
|
209
|
+
};
|
|
210
|
+
const store = memStore();
|
|
211
|
+
const manifest = new InMemoryIngestManifest();
|
|
212
|
+
const report = await reviewDirectory(args(source, store, manifest, {
|
|
213
|
+
judgement: fakeJudge(), signal: controller.signal, concurrency: 2,
|
|
214
|
+
}));
|
|
215
|
+
expect(report.aborted).toBe(true);
|
|
216
|
+
expect(source.reads.length).toBeLessThan(N);
|
|
217
|
+
const kept = [...(await manifestMap(manifest, filesManifestKey(ROOT))).keys()];
|
|
218
|
+
expect(kept.length).toBeLessThan(N);
|
|
219
|
+
expect(anchoredTo(await store.facts({ rootId: ROOT }), 'd0.md').length).toBeGreaterThan(0);
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe('abort mid-judge', () => {
|
|
224
|
+
it('starts no model call after the abort, stops promptly and does not stamp the digest', async () => {
|
|
225
|
+
const N = 20;
|
|
226
|
+
const text = Object.fromEntries(Array.from({ length: N }, (_, i) => [`d${i}.md`, `# T${i}\nbody ${i}\n\n## S${i}\nmore ${i}\n`]));
|
|
227
|
+
const source = memSource(text);
|
|
228
|
+
const controller = new AbortController();
|
|
229
|
+
const base = fakeJudge();
|
|
230
|
+
let calls = 0;
|
|
231
|
+
let afterAbort = 0;
|
|
232
|
+
const judgement: JudgementPort = {
|
|
233
|
+
async judge(req) {
|
|
234
|
+
if (controller.signal.aborted) afterAbort += 1;
|
|
235
|
+
calls += 1;
|
|
236
|
+
if (calls === 3) controller.abort();
|
|
237
|
+
await new Promise((r) => setTimeout(r, 2));
|
|
238
|
+
return base.judge(req);
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
const persistence = memPersistence();
|
|
242
|
+
const store = new LocalSnapshotStore(persistence, { now: () => '2026-10-28T00:00:00.000Z' });
|
|
243
|
+
const report = await reviewDirectory(args(source, store, new InMemoryIngestManifest(), {
|
|
244
|
+
judgement, signal: controller.signal, judgeConcurrency: 4, maxModelCalls: 4,
|
|
245
|
+
}));
|
|
246
|
+
expect(report.aborted).toBe(true);
|
|
247
|
+
expect(afterAbort).toBe(0);
|
|
248
|
+
expect(calls).toBeLessThan(N * 2);
|
|
249
|
+
expect((await store.scopes()).every((s) => s.lastDigest === undefined)).toBe(true);
|
|
250
|
+
|
|
251
|
+
// The control: an unaborted review does stamp it.
|
|
252
|
+
const done = new LocalSnapshotStore(memPersistence(), { now: () => '2026-10-28T00:00:00.000Z' });
|
|
253
|
+
await reviewDirectory(args(memSource(text), done, new InMemoryIngestManifest(), { judgement: fakeJudge() }));
|
|
254
|
+
expect((await done.scopes()).some((s) => s.lastDigest !== undefined)).toBe(true);
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
describe('onStep', () => {
|
|
259
|
+
it('reports cached for reused knowledge and extract-cache hits, skipped for a binary file', async () => {
|
|
260
|
+
const source = memSource({ ...FILES, 'blob.md': 'abc\u0000def' });
|
|
261
|
+
const store = memStore();
|
|
262
|
+
const manifest = new InMemoryIngestManifest();
|
|
263
|
+
const first: ReviewStep[] = [];
|
|
264
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), onStep: (s) => first.push(s) }));
|
|
265
|
+
const blob = first.filter((s) => s.path === 'blob.md');
|
|
266
|
+
expect(blob).toEqual([expect.objectContaining({ phase: 'extract', outcome: 'skipped', reason: 'binary' })]);
|
|
267
|
+
for (const p of ['a.md', 'b.md', 'c.md']) {
|
|
268
|
+
const mine = first.filter((s) => s.path === p);
|
|
269
|
+
expect(mine.map((s) => `${s.phase}:${s.outcome}`)).toEqual(['extract:ok', 'judge:ok', 'write:ok']);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const second: ReviewStep[] = [];
|
|
273
|
+
await reviewDirectory(args(source, store, manifest, { judgement: fakeJudge(), force: true, onStep: (s) => second.push(s) }));
|
|
274
|
+
const a = second.filter((s) => s.path === 'a.md');
|
|
275
|
+
expect(a.map((s) => `${s.phase}:${s.outcome}`)).toEqual(['extract:cached', 'judge:cached', 'write:ok']);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/knowledge/review.ordered.test.ts
|
|
3
|
+
* PRD 41 A8: files are read, extracted and judged in parallel, but ONE writer applies them in plan
|
|
4
|
+
* order — the snapshot bytes AND the manifests of `concurrency 8 / judgeConcurrency 4` (in-thread or
|
|
5
|
+
* through an extraction pool) equal those of `1 / 1`, on a first review and on an incremental one, with
|
|
6
|
+
* same-hash files in the fixture and model calls that settle out of order.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
10
|
+
import { extractJob, type ExtractJob, type ExtractPool } from './extractJob.js';
|
|
11
|
+
import type { JudgementPort } from './model.js';
|
|
12
|
+
import { DOCS_PACK } from './packs/docs.js';
|
|
13
|
+
import { reviewDirectory } from './review.js';
|
|
14
|
+
import { compareManifestKey, filesManifestKey, judgedManifestKey, manifestMap } from './sources.js';
|
|
15
|
+
import { LocalSnapshotStore } from './stores/localSnapshotStore.js';
|
|
16
|
+
import { args, fakeJudge, memPersistence, memSource, ROOT, similar } from './testkit.test-util.js';
|
|
17
|
+
|
|
18
|
+
const N = 34;
|
|
19
|
+
const SAME = '# Same\nidentical body\n';
|
|
20
|
+
const files = (): Record<string, string> => ({
|
|
21
|
+
...Object.fromEntries(Array.from({ length: N }, (_, i) => [`d${String(i).padStart(2, '0')}.md`, `# T${i}\nbody ${i} lease ends ${i}\n\n## S${i}\nmore ${i}\n`])),
|
|
22
|
+
'same1.md': SAME, 'same2.md': SAME, 'same3.md': SAME,
|
|
23
|
+
});
|
|
24
|
+
const EDITED = ['d03.md', 'd10.md', 'd20.md'];
|
|
25
|
+
|
|
26
|
+
const tick = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
27
|
+
const weight = (s: string) => [...s].reduce((a, c) => a + c.charCodeAt(0), 0);
|
|
28
|
+
|
|
29
|
+
/** Settles each call after a delay unrelated to plan order, so completion order differs from dispatch order. */
|
|
30
|
+
function scrambled(): JudgementPort {
|
|
31
|
+
const inner = fakeJudge();
|
|
32
|
+
return { async judge(req) { await tick(weight(req.items[0]!.ref) % 6); return inner.judge(req); } };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A pool that clones the job as a thread boundary would and settles out of order. */
|
|
36
|
+
const scrambledPool = (): ExtractPool => async (job: ExtractJob) => {
|
|
37
|
+
await tick(weight(job.path) % 5);
|
|
38
|
+
return extractJob(JSON.parse(JSON.stringify(job)) as ExtractJob, [DOCS_PACK]);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
interface Shape { concurrency: number; judgeConcurrency: number; modelCalls: number; pool?: boolean }
|
|
42
|
+
|
|
43
|
+
async function runTwice(shape: Shape) {
|
|
44
|
+
const persistence = memPersistence();
|
|
45
|
+
const store = new LocalSnapshotStore(persistence, { now: () => '2026-10-28T00:00:00.000Z' });
|
|
46
|
+
const manifest = new InMemoryIngestManifest();
|
|
47
|
+
const source = memSource(files());
|
|
48
|
+
const read = source.read.bind(source);
|
|
49
|
+
let live = 0;
|
|
50
|
+
let max = 0;
|
|
51
|
+
source.read = async (path) => {
|
|
52
|
+
live += 1; max = Math.max(max, live);
|
|
53
|
+
const doc = await read(path);
|
|
54
|
+
await tick(path.length % 3);
|
|
55
|
+
live -= 1;
|
|
56
|
+
return doc;
|
|
57
|
+
};
|
|
58
|
+
const normalize = (s: string) => s.replace(/"lastReviewedAt":\s*"[^"]*"/g, '"lastReviewedAt":"T"'); // the run's wall clock
|
|
59
|
+
const go = async () => {
|
|
60
|
+
const report = await reviewDirectory(args(source, store, manifest, {
|
|
61
|
+
judgement: scrambled(), similar, concurrency: shape.concurrency, judgeConcurrency: shape.judgeConcurrency,
|
|
62
|
+
budget: { modelCalls: shape.modelCalls, ms: 60_000 }, ...(shape.pool ? { extractPool: scrambledPool() } : {}),
|
|
63
|
+
}));
|
|
64
|
+
expect(report.aborted).toBe(false);
|
|
65
|
+
expect(report.failures).toEqual([]);
|
|
66
|
+
return {
|
|
67
|
+
report, bytes: normalize(persistence.value ?? ''),
|
|
68
|
+
manifests: JSON.stringify([
|
|
69
|
+
[...(await manifestMap(manifest, filesManifestKey(ROOT)))],
|
|
70
|
+
[...(await manifestMap(manifest, judgedManifestKey(ROOT)))],
|
|
71
|
+
(await manifest.get(compareManifestKey(ROOT))) ?? [],
|
|
72
|
+
]),
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const first = await go();
|
|
76
|
+
for (const p of EDITED) source.files[p] = `${source.files[p]}\nedited line\n`;
|
|
77
|
+
const second = await go();
|
|
78
|
+
return { first, second, inFlight: max };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
describe('parallel review, ordered writer', () => {
|
|
82
|
+
it('stores the same bytes and manifests at 8/4 as at 1/1, on a first and an incremental review', async () => {
|
|
83
|
+
const wide = await runTwice({ concurrency: 8, judgeConcurrency: 4, modelCalls: 500 });
|
|
84
|
+
const narrow = await runTwice({ concurrency: 1, judgeConcurrency: 1, modelCalls: 500 });
|
|
85
|
+
expect(wide.inFlight).toBeGreaterThan(1);
|
|
86
|
+
expect(narrow.inFlight).toBe(1);
|
|
87
|
+
expect(wide.first.bytes.length).toBeGreaterThan(1000);
|
|
88
|
+
expect(wide.first.bytes).toBe(narrow.first.bytes);
|
|
89
|
+
expect(wide.first.manifests).toBe(narrow.first.manifests);
|
|
90
|
+
expect(wide.second.bytes).not.toBe(wide.first.bytes);
|
|
91
|
+
expect(wide.second.bytes).toBe(narrow.second.bytes);
|
|
92
|
+
expect(wide.second.manifests).toBe(narrow.second.manifests);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('stores the same bytes through an extraction pool at width as in-thread at 1/1', async () => {
|
|
96
|
+
const pooled = await runTwice({ concurrency: 8, judgeConcurrency: 4, modelCalls: 500, pool: true });
|
|
97
|
+
const narrow = await runTwice({ concurrency: 1, judgeConcurrency: 1, modelCalls: 500 });
|
|
98
|
+
expect(pooled.first.bytes).toBe(narrow.first.bytes);
|
|
99
|
+
expect(pooled.second.bytes).toBe(narrow.second.bytes);
|
|
100
|
+
expect(pooled.second.manifests).toBe(narrow.second.manifests);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('spends a short model-call budget in plan order whatever the widths', async () => {
|
|
104
|
+
const wide = await runTwice({ concurrency: 8, judgeConcurrency: 4, modelCalls: 17 });
|
|
105
|
+
const narrow = await runTwice({ concurrency: 1, judgeConcurrency: 1, modelCalls: 17 });
|
|
106
|
+
expect(wide.first.report.judged).toBe(17);
|
|
107
|
+
expect(wide.first.report.unjudged).toBeGreaterThan(0);
|
|
108
|
+
expect({ judged: wide.first.report.judged, unjudged: wide.first.report.unjudged })
|
|
109
|
+
.toEqual({ judged: narrow.first.report.judged, unjudged: narrow.first.report.unjudged });
|
|
110
|
+
expect(wide.first.bytes).toBe(narrow.first.bytes);
|
|
111
|
+
expect(wide.second.bytes).toBe(narrow.second.bytes);
|
|
112
|
+
expect(wide.second.manifests).toBe(narrow.second.manifests);
|
|
113
|
+
});
|
|
114
|
+
});
|