@seanhogg/builderforce-memory 2026.10.59 → 2026.10.62
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 +3 -3
- package/dist/ingest/docsExtract.d.ts.map +1 -1
- package/dist/ingest/docsExtract.js +8 -4
- package/dist/ingest/docsExtract.js.map +1 -1
- package/dist/ingest/parserSupport.d.ts +2 -2
- package/dist/ingest/parserSupport.js +3 -3
- package/dist/ingest/parserSupport.js.map +1 -1
- package/dist/knowledge/assetFile.d.ts +27 -0
- package/dist/knowledge/assetFile.d.ts.map +1 -0
- package/dist/knowledge/assetFile.js +31 -0
- package/dist/knowledge/assetFile.js.map +1 -0
- package/dist/knowledge/backfillNoExtract.d.ts +11 -13
- package/dist/knowledge/backfillNoExtract.d.ts.map +1 -1
- package/dist/knowledge/backfillNoExtract.js +34 -43
- package/dist/knowledge/backfillNoExtract.js.map +1 -1
- package/dist/knowledge/build.d.ts.map +1 -1
- package/dist/knowledge/build.js +11 -7
- package/dist/knowledge/build.js.map +1 -1
- package/dist/knowledge/extractFile.d.ts +2 -0
- package/dist/knowledge/extractFile.d.ts.map +1 -1
- package/dist/knowledge/extractFile.js +6 -5
- package/dist/knowledge/extractFile.js.map +1 -1
- package/dist/knowledge/extractJob.d.ts +3 -1
- package/dist/knowledge/extractJob.d.ts.map +1 -1
- package/dist/knowledge/extractJob.js +1 -1
- package/dist/knowledge/extractJob.js.map +1 -1
- package/dist/knowledge/findings.js +4 -4
- package/dist/knowledge/findings.js.map +1 -1
- package/dist/knowledge/importance.d.ts +5 -0
- package/dist/knowledge/importance.d.ts.map +1 -1
- package/dist/knowledge/importance.js +7 -0
- package/dist/knowledge/importance.js.map +1 -1
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +2 -2
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/model.d.ts +3 -1
- package/dist/knowledge/model.d.ts.map +1 -1
- package/dist/knowledge/outline.d.ts.map +1 -1
- package/dist/knowledge/outline.js +4 -2
- package/dist/knowledge/outline.js.map +1 -1
- package/dist/knowledge/owedFiles.d.ts +28 -4
- package/dist/knowledge/owedFiles.d.ts.map +1 -1
- package/dist/knowledge/owedFiles.js +60 -8
- package/dist/knowledge/owedFiles.js.map +1 -1
- package/dist/knowledge/plan.d.ts +11 -2
- package/dist/knowledge/plan.d.ts.map +1 -1
- package/dist/knowledge/plan.js +24 -9
- package/dist/knowledge/plan.js.map +1 -1
- package/dist/knowledge/refs.d.ts +2 -0
- package/dist/knowledge/refs.d.ts.map +1 -1
- package/dist/knowledge/refs.js +2 -0
- package/dist/knowledge/refs.js.map +1 -1
- package/dist/knowledge/resolve.d.ts.map +1 -1
- package/dist/knowledge/resolve.js +2 -2
- package/dist/knowledge/resolve.js.map +1 -1
- package/dist/knowledge/review.d.ts.map +1 -1
- package/dist/knowledge/review.js +8 -5
- package/dist/knowledge/review.js.map +1 -1
- package/dist/knowledge/reviewModel.d.ts +17 -2
- package/dist/knowledge/reviewModel.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.d.ts +10 -2
- package/dist/knowledge/reviewPrefetch.d.ts.map +1 -1
- package/dist/knowledge/reviewPrefetch.js +15 -5
- package/dist/knowledge/reviewPrefetch.js.map +1 -1
- package/dist/knowledge/reviewRunModel.d.ts +1 -1
- package/dist/knowledge/sources.d.ts +17 -2
- package/dist/knowledge/sources.d.ts.map +1 -1
- package/dist/knowledge/sources.js +42 -7
- package/dist/knowledge/sources.js.map +1 -1
- package/dist/knowledge/truncate.d.ts.map +1 -1
- package/dist/knowledge/truncate.js +6 -5
- package/dist/knowledge/truncate.js.map +1 -1
- package/package.json +3 -3
- package/src/contract/exports.snapshot.json +2 -0
- package/src/contract/regression.assets.test.ts +246 -0
- package/src/contract/regression.recheck.test.ts +5 -5
- package/src/contract/regression.review.test.ts +185 -5
- package/src/contract/types.contract.test.ts +16 -3
- package/src/ingest/docsExtract.ts +9 -4
- package/src/ingest/parserSupport.ts +3 -3
- package/src/knowledge/assetFile.ts +34 -0
- package/src/knowledge/backfillNoExtract.ts +29 -35
- package/src/knowledge/build.ts +10 -5
- package/src/knowledge/docs.test.ts +5 -2
- package/src/knowledge/extractFile.ts +8 -5
- package/src/knowledge/extractJob.ts +3 -3
- package/src/knowledge/findings.ts +4 -4
- package/src/knowledge/importance.ts +8 -0
- package/src/knowledge/index.ts +2 -2
- package/src/knowledge/model.ts +3 -1
- package/src/knowledge/outline.ts +4 -2
- package/src/knowledge/owedFiles.ts +62 -7
- package/src/knowledge/plan.ts +34 -9
- package/src/knowledge/refs.ts +3 -0
- package/src/knowledge/resolve.ts +2 -2
- package/src/knowledge/review.fixes.test.ts +3 -2
- package/src/knowledge/review.gaps.test.ts +5 -3
- package/src/knowledge/review.test.ts +4 -2
- package/src/knowledge/review.ts +10 -7
- package/src/knowledge/reviewModel.ts +17 -2
- package/src/knowledge/reviewPrefetch.ts +21 -7
- package/src/knowledge/reviewRunModel.ts +1 -1
- package/src/knowledge/sources.ts +46 -8
- package/src/knowledge/truncate.ts +6 -5
|
@@ -287,6 +287,7 @@
|
|
|
287
287
|
"EXTERNAL_SERVICE_IDS",
|
|
288
288
|
"EXTRACTOR_VERSION",
|
|
289
289
|
"ExtractFailed",
|
|
290
|
+
"FALLBACK_PACK_ID",
|
|
290
291
|
"GOD_MODULE_KIND",
|
|
291
292
|
"GOD_MODULE_LIMITS",
|
|
292
293
|
"LocalSnapshotStore",
|
|
@@ -358,6 +359,7 @@
|
|
|
358
359
|
"hashDocText",
|
|
359
360
|
"ignoreMatcher",
|
|
360
361
|
"ignoreSourcesOf",
|
|
362
|
+
"isAssetPath",
|
|
361
363
|
"isBinaryPath",
|
|
362
364
|
"isBinaryText",
|
|
363
365
|
"isDocumentPath",
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/contract/regression.assets.test.ts — assets (binary files stored as a file node, never read): how their asset-ness follows the
|
|
3
|
+
* packs, how a cut treats them, and what the upgrade and the removal of one do. Each bug pinned by one test named `regression: …`.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { hashText } from '../ingest/hash.js';
|
|
7
|
+
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
8
|
+
import { isBinaryDocumentType } from '../ingest/parserSupport.js';
|
|
9
|
+
import { assetExtracted } from '../knowledge/assetFile.js';
|
|
10
|
+
import { buildGraph } from '../knowledge/build.js';
|
|
11
|
+
import type { KnowledgePack, KnowledgeParser } from '../knowledge/model.js';
|
|
12
|
+
import { DOCS_PACK } from '../knowledge/packs/docs.js';
|
|
13
|
+
import { owedCalls } from '../knowledge/owedFiles.js';
|
|
14
|
+
import { planDetail, planReview, refreshPlan } from '../knowledge/plan.js';
|
|
15
|
+
import { srcRef } from '../knowledge/refs.js';
|
|
16
|
+
import { reviewDirectory } from '../knowledge/review.js';
|
|
17
|
+
import { extractJob, type ExtractPool } from '../knowledge/extractJob.js';
|
|
18
|
+
import { EXTRACTOR_VERSION, extractorManifestKey, filesManifestKey, isBinaryText, manifestMap, mediaTypeOfPath, saveManifestMap } from '../knowledge/sources.js';
|
|
19
|
+
import { args, edge, extractedOf, fileNode, memSource, memStore, ROOT, stateOf } from '../knowledge/testkit.test-util.js';
|
|
20
|
+
|
|
21
|
+
const PNG = 'PNGDATA';
|
|
22
|
+
const pdfParser: KnowledgeParser = {
|
|
23
|
+
id: 'pdf-text',
|
|
24
|
+
accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
|
|
25
|
+
parse: (s) => [{ text: s.content.kind === 'text' ? s.content.text : '' }],
|
|
26
|
+
};
|
|
27
|
+
const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdfParser, ...DOCS_PACK.parsers] };
|
|
28
|
+
|
|
29
|
+
describe('regression: asset-ness follows the packs', () => {
|
|
30
|
+
it('regression: a pdf reviewed as an asset is re-processed when a host parser arrives, and an extracted one when it leaves', async () => {
|
|
31
|
+
const source = memSource({ 'a.pdf': 'pdf text', 'b.md': '# B\n' });
|
|
32
|
+
const manifest = new InMemoryIngestManifest();
|
|
33
|
+
const store = memStore();
|
|
34
|
+
const hash = hashText('pdf text');
|
|
35
|
+
await reviewDirectory(args(source, store, manifest)); // no parser: a.pdf is an asset
|
|
36
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
|
|
37
|
+
|
|
38
|
+
// A parser arrives: the bytes did not move, the version did not move — the file is still owed.
|
|
39
|
+
const arrived = await planReview(source, manifest, [withPdf]);
|
|
40
|
+
expect(arrived).toMatchObject({ changed: ['a.pdf'], assets: 0 });
|
|
41
|
+
const report = await reviewDirectory(args(source, store, manifest, { packs: [withPdf] }));
|
|
42
|
+
expect(report.extracted).toBe(1);
|
|
43
|
+
expect((await store.getExtracted(hash))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
|
|
44
|
+
expect((await planReview(source, manifest, [withPdf])).changed).toEqual([]);
|
|
45
|
+
expect((await stateOf(manifest)).owed).toEqual([]);
|
|
46
|
+
|
|
47
|
+
// The parser leaves: the extraction is replaced by the asset node.
|
|
48
|
+
const gone = await planReview(source, manifest, [DOCS_PACK]);
|
|
49
|
+
expect(gone).toMatchObject({ changed: ['a.pdf'], assets: 1 });
|
|
50
|
+
await reviewDirectory(args(source, store, manifest, { packs: [DOCS_PACK] }));
|
|
51
|
+
expect((await store.getExtracted(hash))![0]!.nodes).toMatchObject([{ kind: 'file', badges: { asset: 1, mediaType: 'application/pdf' } }]);
|
|
52
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('regression: a plan handed to Continue keeps the flip, so the files it owes are still re-processed', async () => {
|
|
56
|
+
const source = memSource({ 'a.pdf': 'pdf text' });
|
|
57
|
+
const manifest = new InMemoryIngestManifest();
|
|
58
|
+
const store = memStore(); // ONE store across the runs, so a stale asset entry in the extract cache cannot hide
|
|
59
|
+
await reviewDirectory(args(source, store, manifest));
|
|
60
|
+
const detail = await planDetail(source, manifest, [withPdf]);
|
|
61
|
+
expect(detail.plan.changed).toEqual(['a.pdf']);
|
|
62
|
+
const report = await reviewDirectory(args(source, store, manifest, { packs: [withPdf], plan: detail }));
|
|
63
|
+
expect(report.extracted).toBe(1);
|
|
64
|
+
expect((await store.getExtracted(hashText('pdf text')))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('regression: an aborted run during a documents flip records the new types, and the files it did not finish stay owed for the next run', async () => {
|
|
68
|
+
const files = Object.fromEntries(['a.pdf', 'b.pdf', 'c.pdf'].map((p) => [p, `text of ${p}`]));
|
|
69
|
+
const source = memSource({ ...files });
|
|
70
|
+
const manifest = new InMemoryIngestManifest();
|
|
71
|
+
const store = memStore();
|
|
72
|
+
await reviewDirectory(args(source, store, manifest)); // all three are assets
|
|
73
|
+
const stop = new AbortController();
|
|
74
|
+
const first = await reviewDirectory(args(source, store, manifest, {
|
|
75
|
+
packs: [withPdf], signal: stop.signal, concurrency: 1, onProgress: (p) => { if (p.phase === 'write') stop.abort(); },
|
|
76
|
+
}));
|
|
77
|
+
expect(first.aborted).toBe(true);
|
|
78
|
+
const owed = (await stateOf(manifest)).owed;
|
|
79
|
+
expect(owed.length).toBeGreaterThan(0); // unfinished flipped files stay owed although `documents` is already 'pdf'
|
|
80
|
+
expect(owed.every((p) => p in files)).toBe(true);
|
|
81
|
+
|
|
82
|
+
const next = await reviewDirectory(args(source, store, manifest, { packs: [withPdf] }));
|
|
83
|
+
expect(next.aborted).toBe(false);
|
|
84
|
+
expect((await stateOf(manifest)).owed).toEqual([]);
|
|
85
|
+
for (const text of Object.values(files)) expect((await store.getExtracted(hashText(text)))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
describe('regression: assets in a cut graph', () => {
|
|
90
|
+
it('regression: a truncated graph never fills its slice with assets, nor keeps the ones beside a kept file', () => {
|
|
91
|
+
const docs = ['d0.md', 'd1.md', 'd2.md', 'd3.md'];
|
|
92
|
+
const icons = Array.from({ length: 6 }, (_, i) => `icons/i${i}.png`);
|
|
93
|
+
const extracted = [
|
|
94
|
+
extractedOf(fileNode('d0.md'), icons.map((p) => edge('d0.md', p))),
|
|
95
|
+
...docs.slice(1).map((p) => extractedOf(fileNode(p))),
|
|
96
|
+
...icons.map((p) => assetExtracted(ROOT, { path: p, hash: `h:${p}`, size: 1 })),
|
|
97
|
+
];
|
|
98
|
+
// The control: uncut, the linked assets OUTRANK an isolated doc by importance (computed by PageRank, not the node's stored 0),
|
|
99
|
+
// so only the assets-last order keeps them out of the slice.
|
|
100
|
+
const whole = buildGraph({ rootId: ROOT, extracted, packs: [DOCS_PACK], facts: [], relations: [] });
|
|
101
|
+
const importanceOf = (path: string) => whole.nodes.find((n) => n.ref === srcRef(ROOT, path))!.importance;
|
|
102
|
+
expect(importanceOf('icons/i0.png')).toBeGreaterThan(importanceOf('d1.md'));
|
|
103
|
+
|
|
104
|
+
const g = buildGraph({ rootId: ROOT, extracted, packs: [DOCS_PACK], facts: [], relations: [] }, { maxNodes: 3 });
|
|
105
|
+
expect(g.stats.truncated).toBe(true);
|
|
106
|
+
expect(g.nodes.filter((n) => n.badges?.['asset'] !== undefined)).toEqual([]);
|
|
107
|
+
expect(g.nodes.filter((n) => n.kind === 'file').length).toBeGreaterThan(0);
|
|
108
|
+
// The outline still lists every file, assets included, with their badges.
|
|
109
|
+
expect(g.outline!.files.filter((f) => f.badges?.['asset'] === 1)).toHaveLength(icons.length);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('regression: lockfiles and fonts', () => {
|
|
114
|
+
it('regression: lockfiles are ignored (not assets, not extracted as text); a sqlite db stays an asset', async () => {
|
|
115
|
+
const source = memSource({ 'yarn.lock': 'x', 'crate/Cargo.lock': 'y', 'app.db': 'z', 'a.md': '# A\n' });
|
|
116
|
+
const plan = await planReview(source, new InMemoryIngestManifest(), [DOCS_PACK]);
|
|
117
|
+
expect(plan.skipped).toEqual(expect.arrayContaining([{ path: 'yarn.lock', reason: 'ignored' }, { path: 'crate/Cargo.lock', reason: 'ignored' }]));
|
|
118
|
+
expect(plan).toMatchObject({ files: 2, assets: 1 });
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('regression: a font object is not a binary document type (only pdf and office are), and an .eot is an asset', async () => {
|
|
122
|
+
expect(mediaTypeOfPath('f.eot')).toBe('application/vnd.ms-fontobject');
|
|
123
|
+
expect(isBinaryDocumentType('application/vnd.ms-fontobject')).toBe(false);
|
|
124
|
+
for (const type of ['application/vnd.ms-excel', 'application/vnd.ms-powerpoint', 'application/msword', 'application/pdf']) expect(isBinaryDocumentType(type)).toBe(true);
|
|
125
|
+
expect((await planReview(memSource({ 'f.eot': 'x' }), new InMemoryIngestManifest(), [DOCS_PACK])).assets).toBe(1);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('regression: html references', () => {
|
|
130
|
+
it('regression: img, source, link and svg image references are followed; external and protocol-relative ones are not', async () => {
|
|
131
|
+
const html = [
|
|
132
|
+
'<img src="icons/a.png"><source src="v/b.webm"><link rel="stylesheet" href="css/c.css">',
|
|
133
|
+
'<svg><image xlink:href="icons/d.png"/></svg><a href="//cdn.example.com/x.png">x</a><img src="https://x.test/y.png">',
|
|
134
|
+
].join('\n');
|
|
135
|
+
const source = memSource({ 'page.html': html });
|
|
136
|
+
const store = memStore();
|
|
137
|
+
await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
|
|
138
|
+
const ex = (await store.getExtracted(hashText(html)))!.find((e) => e.sourceRef === srcRef(ROOT, 'page.html'))!;
|
|
139
|
+
expect(ex.edges.filter((e) => e.kind === 'links').map((e) => e.to)).toEqual(['css/c.css', 'icons/a.png', 'icons/d.png', 'v/b.webm'].map((p) => srcRef(ROOT, p)));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('regression: a protocol-relative markdown link is external, not a missing file', async () => {
|
|
143
|
+
const md = '# R\n[cdn](//cdn.example.com/x.png) and [local](icons/a.png)\n';
|
|
144
|
+
const store = memStore();
|
|
145
|
+
await reviewDirectory(args(memSource({ 'README.md': md }), store, new InMemoryIngestManifest()));
|
|
146
|
+
const ex = (await store.getExtracted(hashText(md)))![0]!;
|
|
147
|
+
expect(ex.edges.filter((e) => e.kind === 'links').map((e) => e.to)).toEqual([srcRef(ROOT, 'icons/a.png')]);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('regression: the asset lifecycle', () => {
|
|
152
|
+
it('regression: a manifest at the file\'s current hash with no stored body queues the asset, so its node is written without a read', async () => {
|
|
153
|
+
const source = memSource({ 'icons/a.png': PNG, 'a.md': '# A\n' });
|
|
154
|
+
const manifest = new InMemoryIngestManifest();
|
|
155
|
+
await reviewDirectory(args(source, memStore(), manifest));
|
|
156
|
+
const fresh = memStore(); // the manifest names the files; this store holds no body
|
|
157
|
+
source.reads.length = 0;
|
|
158
|
+
await reviewDirectory(args(source, fresh, manifest));
|
|
159
|
+
expect(source.reads).toEqual([]); // the asset is never read
|
|
160
|
+
expect((await fresh.getExtracted(hashText(PNG)))![0]!.nodes[0]).toMatchObject({ kind: 'file', badges: { asset: 1, mediaType: 'image/png' } });
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('regression: a v3 root whose binary files hold a legacy [] gets their asset nodes at v4', async () => {
|
|
164
|
+
const source = memSource({ 'icons/a.png': PNG, 'a.md': '# A\n' });
|
|
165
|
+
const manifest = new InMemoryIngestManifest();
|
|
166
|
+
await saveManifestMap(manifest, filesManifestKey(ROOT), new Map([['icons/a.png', hashText(PNG)], ['a.md', hashText('# A\n')]]));
|
|
167
|
+
await manifest.set(extractorManifestKey(ROOT), [{ id: 'version', hash: String(EXTRACTOR_VERSION - 1) }]);
|
|
168
|
+
const store = memStore();
|
|
169
|
+
await store.putExtracted(hashText(PNG), []); // what v3 stored for a binary file
|
|
170
|
+
await reviewDirectory(args(source, store, manifest));
|
|
171
|
+
expect((await store.getExtracted(hashText(PNG)))![0]!.nodes[0]).toMatchObject({ kind: 'file', badges: { asset: 1, size: PNG.length } });
|
|
172
|
+
expect((await stateOf(manifest)).version).toBe(EXTRACTOR_VERSION);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('regression: a removed asset is retired like any removed file', async () => {
|
|
176
|
+
const source = memSource({ 'icons/a.png': PNG, 'a.md': '# A\n' });
|
|
177
|
+
const manifest = new InMemoryIngestManifest();
|
|
178
|
+
const store = memStore();
|
|
179
|
+
await reviewDirectory(args(source, store, manifest));
|
|
180
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).has('icons/a.png')).toBe(true);
|
|
181
|
+
|
|
182
|
+
delete source.files['icons/a.png'];
|
|
183
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).removed).toEqual(['icons/a.png']);
|
|
184
|
+
const report = await reviewDirectory(args(source, store, manifest));
|
|
185
|
+
expect(report.staleMarked).toBe(1);
|
|
186
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).has('icons/a.png')).toBe(false);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('regression: with an extractPool that reads (deferRead) an asset is never sent to the pool, and a file the pool finds binary becomes an asset node', async () => {
|
|
190
|
+
const nul = 'bin\u0000ary';
|
|
191
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'icons/a.png': PNG, 'blob.txt': nul });
|
|
192
|
+
const sent: string[] = [];
|
|
193
|
+
const pool: ExtractPool = async (job) => {
|
|
194
|
+
sent.push(job.path);
|
|
195
|
+
const doc = await source.read(job.path);
|
|
196
|
+
if (doc.content.kind === 'text' && isBinaryText(doc.content.text)) return { binary: true, extracted: [] };
|
|
197
|
+
return extractJob({ ...job, doc } as never, [DOCS_PACK]);
|
|
198
|
+
};
|
|
199
|
+
const store = memStore();
|
|
200
|
+
const report = await reviewDirectory(args(source, store, new InMemoryIngestManifest(), { extractPool: pool, deferRead: true }));
|
|
201
|
+
expect(report.failures).toEqual([]);
|
|
202
|
+
expect(sent).not.toContain('icons/a.png');
|
|
203
|
+
expect(sent).toContain('blob.txt');
|
|
204
|
+
expect((await store.getExtracted(hashText(PNG)))![0]!.nodes[0]).toMatchObject({ badges: { asset: 1, mediaType: 'image/png' } });
|
|
205
|
+
expect((await store.getExtracted(hashText(nul)))![0]!.nodes[0]).toMatchObject({ badges: { asset: 1, mediaType: 'text/plain' } });
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
describe('regression: an oversized claimed document stays an asset', () => {
|
|
210
|
+
it('regression: a 3 MB claimed pdf is an asset node, not in skipped, owes no calls, and is extracted once it shrinks below the cap', async () => {
|
|
211
|
+
const big = 'x'.repeat(3 * 1024 * 1024);
|
|
212
|
+
const source = memSource({ 'a.pdf': big });
|
|
213
|
+
const manifest = new InMemoryIngestManifest();
|
|
214
|
+
const store = memStore();
|
|
215
|
+
const plan = await planDetail(source, manifest, [withPdf]);
|
|
216
|
+
expect(plan.plan.skipped).toEqual([]);
|
|
217
|
+
expect(plan.plan.assets).toBe(1);
|
|
218
|
+
expect(plan.files).toMatchObject([{ path: 'a.pdf', asset: true }]);
|
|
219
|
+
expect(owedCalls(plan.extractor, 'a.pdf')).toBe(0);
|
|
220
|
+
const report = await reviewDirectory(args(source, store, manifest, { packs: [withPdf] }));
|
|
221
|
+
expect(report.extracted).toBe(0);
|
|
222
|
+
expect(source.reads).not.toContain('a.pdf');
|
|
223
|
+
expect((await store.getExtracted(hashText(big)))![0]!.nodes[0]).toMatchObject({ kind: 'file', badges: { asset: 1, oversized: 1, mediaType: 'application/pdf' } });
|
|
224
|
+
|
|
225
|
+
// A later shrink below the cap: the content hash moved, so the file is owed and now extracted.
|
|
226
|
+
source.files['a.pdf'] = 'small pdf text';
|
|
227
|
+
const shrunk = await planReview(source, manifest, [withPdf]);
|
|
228
|
+
expect(shrunk).toMatchObject({ changed: ['a.pdf'], assets: 0 });
|
|
229
|
+
const again = await reviewDirectory(args(source, store, manifest, { packs: [withPdf] }));
|
|
230
|
+
expect(again.extracted).toBe(1);
|
|
231
|
+
expect((await store.getExtracted(hashText('small pdf text')))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('regression: an oversized claimed pdf still owes no calls after an aborted run and a refreshed (Continue) plan', async () => {
|
|
235
|
+
const source = memSource({ 'big.pdf': 'x'.repeat(3 * 1024 * 1024) });
|
|
236
|
+
const manifest = new InMemoryIngestManifest();
|
|
237
|
+
const store = memStore();
|
|
238
|
+
const detail = await planDetail(source, manifest, [withPdf]);
|
|
239
|
+
const stop = new AbortController();
|
|
240
|
+
stop.abort();
|
|
241
|
+
await reviewDirectory(args(source, store, manifest, { packs: [withPdf], plan: detail, signal: stop.signal }));
|
|
242
|
+
const refreshed = await refreshPlan(detail, manifest);
|
|
243
|
+
expect(owedCalls(refreshed.extractor, 'big.pdf')).toBe(0);
|
|
244
|
+
expect(refreshed.files).toMatchObject([{ path: 'big.pdf', asset: true, oversized: true }]);
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -26,7 +26,7 @@ describe('regression: a root reviewed before binary files were recorded is settl
|
|
|
26
26
|
expect(source.reads).not.toContain('img.png');
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets
|
|
29
|
+
it('regression: the review reads ONLY the files a replica asked to re-check: a NUL-binary gets its asset node, a text file is extracted, the set is cleared', async () => {
|
|
30
30
|
const binary = 'bin\u0000ary';
|
|
31
31
|
const files = { 'blob.txt': binary, 'a.md': text, 'b.md': '# B\nbeta\n' };
|
|
32
32
|
const manifest = new InMemoryIngestManifest();
|
|
@@ -37,7 +37,7 @@ describe('regression: a root reviewed before binary files were recorded is settl
|
|
|
37
37
|
const source = memSource(files);
|
|
38
38
|
await reviewDirectory(args(source, legacy, manifest));
|
|
39
39
|
expect(new Set(source.reads)).toEqual(new Set(['blob.txt', 'a.md'])); // b.md was never named
|
|
40
|
-
expect(await legacy.getExtracted(hashText(binary)))
|
|
40
|
+
expect((await legacy.getExtracted(hashText(binary)))![0]!.nodes[0]!.badges).toMatchObject({ asset: 1, size: binary.length });
|
|
41
41
|
expect((await legacy.getExtracted(hashText(text)))!.length).toBeGreaterThan(0);
|
|
42
42
|
expect(await legacy.getExtracted(hashText(files['b.md']))).toBeUndefined();
|
|
43
43
|
expect(await legacy.recheckHashes()).toEqual([]);
|
|
@@ -86,12 +86,12 @@ describe('regression: a root reviewed before binary files were recorded is settl
|
|
|
86
86
|
return legacy;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
-
it('regression: a review stopped mid-way (
|
|
89
|
+
it('regression: a review stopped mid-way (on the read of the file the backfill queued) keeps the re-check request and records no terminal [], and a complete one clears it', async () => {
|
|
90
90
|
const manifest = new InMemoryIngestManifest();
|
|
91
91
|
const legacy = await legacyStore(manifest);
|
|
92
92
|
const stop = new AbortController();
|
|
93
|
-
//
|
|
94
|
-
const source = watched((n) => { if (n ===
|
|
93
|
+
// The backfill only queues the file (it reads nothing); read 1 is the review's: the run is stopped there and the read rejects.
|
|
94
|
+
const source = watched((n) => { if (n === 1) { stop.abort(); throw new Error('aborted'); } });
|
|
95
95
|
await reviewDirectory(args(source, legacy, manifest, { signal: stop.signal })).catch(() => undefined);
|
|
96
96
|
expect(await legacy.recheckHashes()).toEqual([hashText(text)]);
|
|
97
97
|
expect(await legacy.getExtracted(hashText(text))).toBeUndefined();
|
|
@@ -5,20 +5,21 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { hashText } from '../ingest/hash.js';
|
|
8
|
+
import { buildGraph } from '../knowledge/build.js';
|
|
8
9
|
import { InMemoryIngestManifest } from '../ingest/IngestionPipeline.js';
|
|
9
10
|
import type { ReviewProgress } from '../knowledge/model.js';
|
|
10
11
|
import type { ReviewStep } from '../knowledge/reviewRunModel.js';
|
|
11
12
|
import { extractJob, type ExtractJob, type ExtractPool } from '../knowledge/extractJob.js';
|
|
12
|
-
import type { JudgementRequest, KnowledgePack, KnowledgeStore } from '../knowledge/model.js';
|
|
13
|
+
import type { JudgementRequest, KnowledgePack, KnowledgeParser, KnowledgeStore } from '../knowledge/model.js';
|
|
13
14
|
import { DOCS_PACK } from '../knowledge/packs/docs.js';
|
|
14
15
|
import { putNoExtract } from '../knowledge/extractFile.js';
|
|
15
16
|
import { planReview } from '../knowledge/plan.js';
|
|
16
17
|
import { srcRef } from '../knowledge/refs.js';
|
|
17
18
|
import { reviewDirectory } from '../knowledge/review.js';
|
|
18
19
|
import { applyRunEvent, failuresOf, failureTotal, REVIEW_RUN_FAILURE_CHUNK, startRun } from '../knowledge/reviewRun.js';
|
|
19
|
-
import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap } from '../knowledge/sources.js';
|
|
20
|
+
import { extractorManifestKey, filesManifestKey, judgedManifestKey, manifestMap, mediaTypeOfPath } from '../knowledge/sources.js';
|
|
20
21
|
import {
|
|
21
|
-
ALL, args, fakeJudge, FILES, memSource, memStore, quietPack, ROOT, stateOf, type SpySource,
|
|
22
|
+
ALL, args, fakeJudge, FILES, graphOf, memSource, memStore, quietPack, ROOT, stateOf, type SpySource,
|
|
22
23
|
} from '../knowledge/testkit.test-util.js';
|
|
23
24
|
|
|
24
25
|
const sixFiles = () => Object.fromEntries(Array.from({ length: 6 }, (_, i) => [`d${i}.md`, `# T${i}\nbody ${i}\n`]));
|
|
@@ -292,11 +293,13 @@ describe('regression: changed since plan', () => {
|
|
|
292
293
|
});
|
|
293
294
|
|
|
294
295
|
describe('regression: a file with nothing to extract is told apart from one not extracted yet', () => {
|
|
295
|
-
it('regression: a file found binary on read has
|
|
296
|
+
it('regression: a file found binary on read has a stored asset node (and a stale mark), never an absent body', async () => {
|
|
296
297
|
const text = 'bin\u0000ary';
|
|
297
298
|
const store = memStore();
|
|
298
299
|
await reviewDirectory(args(memSource({ 'blob.txt': text }), store, new InMemoryIngestManifest()));
|
|
299
|
-
|
|
300
|
+
const stored = await store.getExtracted(hashText(text));
|
|
301
|
+
expect(stored).toHaveLength(1);
|
|
302
|
+
expect(stored![0]!.nodes).toMatchObject([{ kind: 'file', badges: { asset: 1, mediaType: 'text/plain', size: text.length } }]);
|
|
300
303
|
});
|
|
301
304
|
|
|
302
305
|
it('regression: a text file that is not extracted (here: its review failed) has NO stored body, so it is never mistaken for binary', async () => {
|
|
@@ -317,3 +320,180 @@ describe('regression: a file with nothing to extract is told apart from one not
|
|
|
317
320
|
expect(await store.getExtracted(hashText(text))).toEqual(before);
|
|
318
321
|
});
|
|
319
322
|
});
|
|
323
|
+
|
|
324
|
+
describe('regression: a binary file is an asset with a node, not a skipped file', () => {
|
|
325
|
+
const PNG = 'PNGDATA';
|
|
326
|
+
|
|
327
|
+
it('regression: a .png in a reviewed directory has a file node with mediaType, size and asset, is never read, and is not in plan.skipped', async () => {
|
|
328
|
+
const source = memSource({ 'a.md': '# A\nalpha\n', 'icons/icon128.png': PNG });
|
|
329
|
+
const store = memStore();
|
|
330
|
+
const manifest = new InMemoryIngestManifest();
|
|
331
|
+
const plan = await planReview(source, manifest, [DOCS_PACK]);
|
|
332
|
+
expect(plan.skipped.map((s) => s.path)).not.toContain('icons/icon128.png');
|
|
333
|
+
expect(plan).toMatchObject({ files: 2, assets: 1, byPack: { docs: 1 }, changed: ['a.md', 'icons/icon128.png'] });
|
|
334
|
+
|
|
335
|
+
const report = await reviewDirectory(args(source, store, manifest));
|
|
336
|
+
expect(report.failures).toEqual([]);
|
|
337
|
+
expect(source.reads).not.toContain('icons/icon128.png');
|
|
338
|
+
const stored = await store.getExtracted(hashText(PNG));
|
|
339
|
+
expect(stored).toHaveLength(1);
|
|
340
|
+
expect(stored![0]!.nodes).toEqual([expect.objectContaining({
|
|
341
|
+
ref: srcRef(ROOT, 'icons/icon128.png'), kind: 'file', label: 'icon128.png',
|
|
342
|
+
badges: { asset: 1, mediaType: 'image/png', size: PNG.length },
|
|
343
|
+
})]);
|
|
344
|
+
expect((await manifestMap(manifest, filesManifestKey(ROOT))).get('icons/icon128.png')).toBe(hashText(PNG));
|
|
345
|
+
|
|
346
|
+
// Diffed like any file: unchanged is not reviewed again, a new byte string is.
|
|
347
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual([]);
|
|
348
|
+
source.files['icons/icon128.png'] = 'OTHER';
|
|
349
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).changed).toEqual(['icons/icon128.png']);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('regression: an asset over maxFileBytes is still an asset, and costs no model call', async () => {
|
|
353
|
+
const plan = await planReview(memSource({ 'big.zip': 'x'.repeat(50) }), new InMemoryIngestManifest(), [DOCS_PACK], { maxFileBytes: 10 });
|
|
354
|
+
expect(plan).toMatchObject({ files: 1, assets: 1, skipped: [], estimatedModelCalls: 0 });
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('regression: mediaTypeOfPath knows the image, font and archive types; an unknown binary extension is octet-stream; text stays text/plain', () => {
|
|
358
|
+
expect(mediaTypeOfPath('x.png')).toBe('image/png');
|
|
359
|
+
expect(mediaTypeOfPath('a/b/favicon.ICO')).toBe('image/vnd.microsoft.icon');
|
|
360
|
+
expect(mediaTypeOfPath('f.woff2')).toBe('font/woff2');
|
|
361
|
+
expect(mediaTypeOfPath('a.zip')).toBe('application/zip');
|
|
362
|
+
expect(mediaTypeOfPath('lib.so')).toBe('application/octet-stream');
|
|
363
|
+
expect(mediaTypeOfPath('notes.txt')).toBe('text/plain');
|
|
364
|
+
expect(mediaTypeOfPath('Makefile')).toBe('text/plain');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('regression: a document linking to an asset path has a links edge to the asset node, not to a missing placeholder', async () => {
|
|
368
|
+
// The docs pack resolves written links; a host code pack resolves its path references through the same `ctx.resolvePath` and srcRef.
|
|
369
|
+
const source = memSource({ 'README.md': '# R\nSee [the logo](icons/icon128.png).\n', 'icons/icon128.png': PNG, 'other.md': '# O\n[gone](icons/gone.png)\n' });
|
|
370
|
+
const store = memStore();
|
|
371
|
+
await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
|
|
372
|
+
const g = await graphOf(source, store);
|
|
373
|
+
const asset = g.nodes.find((n) => n.ref === srcRef(ROOT, 'icons/icon128.png'));
|
|
374
|
+
expect(asset).toMatchObject({ kind: 'file', badges: { asset: 1, mediaType: 'image/png' } });
|
|
375
|
+
const into = g.edges.filter((e) => e.kind === 'links' && e.to === asset!.ref);
|
|
376
|
+
expect(into).toHaveLength(1);
|
|
377
|
+
expect(into[0]!.from.startsWith(srcRef(ROOT, 'README.md'))).toBe(true); // from the file or the section holding the link
|
|
378
|
+
expect(g.nodes.find((n) => n.ref === srcRef(ROOT, 'icons/gone.png'))?.kind).toBe('missing'); // a truly absent target still is
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('regression: a markdown image  references its target like a link, so it lands on the asset node', async () => {
|
|
382
|
+
const source = memSource({ 'README.md': '# R\n and ![ref][shot]\n\n[shot]: shots/s.png\n', 'icons/icon128.png': PNG, 'shots/s.png': 'SHOT' });
|
|
383
|
+
const store = memStore();
|
|
384
|
+
await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
|
|
385
|
+
const g = await graphOf(source, store);
|
|
386
|
+
for (const p of ['icons/icon128.png', 'shots/s.png']) {
|
|
387
|
+
const to = srcRef(ROOT, p);
|
|
388
|
+
expect(g.nodes.find((n) => n.ref === to)).toMatchObject({ kind: 'file', badges: { asset: 1 } });
|
|
389
|
+
expect(g.edges.filter((e) => e.kind === 'links' && e.to === to)).toHaveLength(1);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('regression: an outlined, truncated graph keeps the asset badges (asset, mediaType, size) of its files', async () => {
|
|
394
|
+
const files: Record<string, string> = { 'icons/icon128.png': PNG };
|
|
395
|
+
for (let i = 0; i < 12; i++) files[`d${i}.md`] = `# T${i}\nbody ${i}\n`;
|
|
396
|
+
const source = memSource(files);
|
|
397
|
+
const store = memStore();
|
|
398
|
+
await reviewDirectory(args(source, store, new InMemoryIngestManifest()));
|
|
399
|
+
const extracted = [];
|
|
400
|
+
for await (const f of source.list()) {
|
|
401
|
+
const hit = (await store.getExtracted(f.hash))?.find((e) => e.sourceRef === srcRef(ROOT, f.path));
|
|
402
|
+
if (hit) extracted.push(hit);
|
|
403
|
+
}
|
|
404
|
+
const g = buildGraph({ rootId: ROOT, extracted, packs: [DOCS_PACK], facts: [], relations: [] }, { maxNodes: 3 });
|
|
405
|
+
expect(g.stats.truncated).toBe(true);
|
|
406
|
+
const png = g.outline!.files.find((f) => f.path === 'icons/icon128.png');
|
|
407
|
+
expect(png?.badges).toEqual({ asset: 1, mediaType: 'image/png', size: PNG.length });
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
it('regression: an .svg stays text: its title and text become a section and its href a link; it is not an asset', async () => {
|
|
411
|
+
const svg = '<svg xmlns="http://www.w3.org/2000/svg"><title>Logo</title><text>Hello brand</text><a href="icons/icon128.png"><rect width="1" height="1"/></a></svg>';
|
|
412
|
+
const source = memSource({ 'logo.svg': svg, 'icons/icon128.png': PNG });
|
|
413
|
+
const store = memStore();
|
|
414
|
+
const manifest = new InMemoryIngestManifest();
|
|
415
|
+
expect((await planReview(source, manifest, [DOCS_PACK])).assets).toBe(1); // only the png
|
|
416
|
+
await reviewDirectory(args(source, store, manifest));
|
|
417
|
+
const ex = (await store.getExtracted(hashText(svg)))!.find((e) => e.sourceRef === srcRef(ROOT, 'logo.svg'))!;
|
|
418
|
+
expect(mediaTypeOfPath('logo.svg')).toBe('image/svg+xml');
|
|
419
|
+
expect(ex.nodes[0]).toMatchObject({ kind: 'file', pack: 'docs' });
|
|
420
|
+
expect(ex.nodes[0]!.badges?.asset).toBeUndefined();
|
|
421
|
+
expect(ex.nodes.some((n) => n.kind === 'section' && String(n.badges?.excerpt).includes('Hello brand'))).toBe(true);
|
|
422
|
+
expect(ex.edges.filter((e) => e.kind === 'links').map((e) => e.to)).toEqual([srcRef(ROOT, 'icons/icon128.png')]);
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('regression: a pdf with no host parser becomes an asset node; with a host parser it is still extracted', async () => {
|
|
426
|
+
const pdf: KnowledgeParser = {
|
|
427
|
+
id: 'pdf-text',
|
|
428
|
+
accepts: (s) => s.content.kind === 'text' && s.content.mediaType === 'application/pdf',
|
|
429
|
+
parse: (s) => [{ text: s.content.kind === 'text' ? s.content.text : '' }],
|
|
430
|
+
};
|
|
431
|
+
const files = { 'doc.pdf': 'pdf text' };
|
|
432
|
+
const bare = memStore();
|
|
433
|
+
const bareReport = await reviewDirectory(args(memSource({ ...files }), bare, new InMemoryIngestManifest()));
|
|
434
|
+
expect(bareReport.extracted).toBe(0);
|
|
435
|
+
expect((await bare.getExtracted(hashText('pdf text')))![0]!.nodes[0]).toMatchObject({ kind: 'file', badges: { asset: 1, mediaType: 'application/pdf' } });
|
|
436
|
+
|
|
437
|
+
const hosted = memStore();
|
|
438
|
+
const withPdf: KnowledgePack = { ...DOCS_PACK, parsers: [pdf, ...DOCS_PACK.parsers] };
|
|
439
|
+
const hostedReport = await reviewDirectory(args(memSource({ ...files }), hosted, new InMemoryIngestManifest(), { packs: [withPdf] }));
|
|
440
|
+
expect(hostedReport.extracted).toBe(1);
|
|
441
|
+
expect((await hosted.getExtracted(hashText('pdf text')))![0]!.nodes[0]!.badges?.asset).toBeUndefined();
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
describe('regression: DirectorySource.hashOf and readTimeoutMs take the path', () => {
|
|
446
|
+
it('regression: hashOf receives the path being checked', async () => {
|
|
447
|
+
const source = memSource({ 'a.md': '# A\nalpha\n' });
|
|
448
|
+
const seen: Array<[string, string]> = [];
|
|
449
|
+
source.hashOf = (text, path) => { seen.push([text, path]); return hashText(text); };
|
|
450
|
+
const report = await reviewDirectory(args(source));
|
|
451
|
+
expect(report.extracted).toBe(1);
|
|
452
|
+
expect(seen).toEqual([['# A\nalpha\n', 'a.md']]);
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('regression: readTimeoutMs overrides the default read timeout for one path, and a slow read past the default succeeds when the override is longer', async () => {
|
|
456
|
+
const slowRead = (source: SpySource) => {
|
|
457
|
+
const read = source.read.bind(source);
|
|
458
|
+
source.read = async (path) => { if (path === 'slow.md') await new Promise((r) => setTimeout(r, 120)); return read(path); };
|
|
459
|
+
return source;
|
|
460
|
+
};
|
|
461
|
+
const files = { 'slow.md': '# S\nslow\n', 'fast.md': '# F\nfast\n' };
|
|
462
|
+
// Default (scaled down from 5 s): the slow read times out.
|
|
463
|
+
const base = await reviewDirectory(args(slowRead(memSource({ ...files })), memStore(), new InMemoryIngestManifest(), { timeouts: { readMs: 40 } }));
|
|
464
|
+
expect(base.failures).toEqual([{ path: 'slow.md', phase: 'extract', reason: 'read: timeout' }]);
|
|
465
|
+
// The override applies to slow.md only: it now succeeds.
|
|
466
|
+
const source = slowRead(memSource({ ...files }));
|
|
467
|
+
source.readTimeoutMs = (path) => (path === 'slow.md' ? 2_000 : undefined);
|
|
468
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), { timeouts: { readMs: 40 } }));
|
|
469
|
+
expect(report.failures).toEqual([]);
|
|
470
|
+
expect(report.extracted).toBe(2);
|
|
471
|
+
// A non-finite or non-positive override keeps the default.
|
|
472
|
+
const bad = slowRead(memSource({ ...files }));
|
|
473
|
+
bad.readTimeoutMs = () => 0;
|
|
474
|
+
const kept = await reviewDirectory(args(bad, memStore(), new InMemoryIngestManifest(), { timeouts: { readMs: 40 } }));
|
|
475
|
+
expect(kept.failures).toEqual([{ path: 'slow.md', phase: 'extract', reason: 'read: timeout' }]);
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it('regression: with a pool and deferRead, readTimeoutMs lets a job run past extractMs, and the worker is told the override', async () => {
|
|
479
|
+
const files = { 'slow.md': '# S\nslow\n', 'fast.md': '# F\nfast\n' };
|
|
480
|
+
const pooled = (source: SpySource, seen: Array<number | undefined> = []): ExtractPool => async (job) => {
|
|
481
|
+
seen.push((job as { readByPool?: { readMs?: number } }).readByPool?.readMs);
|
|
482
|
+
const doc = await source.read(job.path);
|
|
483
|
+
if (job.path === 'slow.md') await new Promise((r) => setTimeout(r, 120));
|
|
484
|
+
return extractJob({ ...job, doc } as ExtractJob, [DOCS_PACK]);
|
|
485
|
+
};
|
|
486
|
+
const timeouts = { readMs: 40, extractMs: 40 };
|
|
487
|
+
const base = memSource({ ...files });
|
|
488
|
+
const baseReport = await reviewDirectory(args(base, memStore(), new InMemoryIngestManifest(), { extractPool: pooled(base), deferRead: true, timeouts }));
|
|
489
|
+
expect(baseReport.failures.map((f) => f.path)).toEqual(['slow.md']);
|
|
490
|
+
|
|
491
|
+
const source = memSource({ ...files });
|
|
492
|
+
source.readTimeoutMs = (path) => (path === 'slow.md' ? 2_000 : undefined);
|
|
493
|
+
const seen: Array<number | undefined> = [];
|
|
494
|
+
const report = await reviewDirectory(args(source, memStore(), new InMemoryIngestManifest(), { extractPool: pooled(source, seen), deferRead: true, timeouts }));
|
|
495
|
+
expect(report.failures).toEqual([]);
|
|
496
|
+
expect(report.extracted).toBe(2);
|
|
497
|
+
expect(seen.filter((x) => x !== undefined)).toEqual([2_000]);
|
|
498
|
+
});
|
|
499
|
+
});
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
|
|
14
14
|
import type { ParsedSection, SourceDocument } from '../ingest/types.js';
|
|
15
15
|
import type {
|
|
16
|
-
Extracted, ExtractJob, ExtractJobResult, GraphApp, GraphOutline, GraphReadSkip, GraphSystem, KEdge, KNode, KnowledgeGraph, KnowledgeStore,
|
|
16
|
+
DirectorySource, Extracted, ExtractJob, ExtractJobResult, GraphApp, GraphOutline, GraphReadSkip, GraphSystem, KEdge, KNode, KnowledgeGraph, KnowledgeStore,
|
|
17
17
|
OutlineFile, OutlineCommunity, NodePlacement, ReviewFailure, ReviewFailureChunks, ReviewPhase, ReviewReport, ReviewRun, ReviewRunPhase, ReviewStep, ScopeRecord,
|
|
18
18
|
StoredFact, StoredRelation, ExtractedLogPersistence, KnowledgeSnapshot, LocalSnapshotStoreOptions, SnapshotPersistence,
|
|
19
19
|
RowChange, RowPersistence,
|
|
20
20
|
} from '../knowledge/index.js';
|
|
21
|
+
import type { PlannedFile } from '../knowledge/index.js';
|
|
21
22
|
import { placementOf } from '../knowledge/index.js';
|
|
22
23
|
import { canonicalDump, ExtractFailed, failuresOf, failureTotal, LocalSnapshotStore, localSnapshotStore, type ExtractorState } from '../knowledge/index.js';
|
|
23
24
|
|
|
@@ -88,7 +89,11 @@ export const jobWithSectionFlags = { ...base, doc: aDocument, needSections: true
|
|
|
88
89
|
export const jobWithBoth: ExtractJob = { ...base, doc: aDocument, readByPool: { path: 'a.md', hash: 'h' } };
|
|
89
90
|
// @ts-expect-error ExtractJob: a job carries one of `doc` / `readByPool`
|
|
90
91
|
export const jobWithNeither: ExtractJob = { ...base };
|
|
91
|
-
|
|
92
|
+
// readByPool gained an OPTIONAL `readMs` (the source's per-path read deadline, for a worker to use instead of its constant); a worker that ignores it is unaffected.
|
|
93
|
+
export type ExtractJob_readByPool_shape = Expect<Equal<NonNullable<Extract<ExtractJob, { readByPool: unknown }>['readByPool']>, { path: string; hash: string; readMs?: number }>>;
|
|
94
|
+
export const jobTheWorkerReadsWithDeadline = { ...base, readByPool: { path: 'a.md', hash: 'h', readMs: 30_000 } } satisfies ExtractJob;
|
|
95
|
+
// PlannedFile.oversized: an asset only because a claimed document is over the size cap; optional, so a hand-built PlannedFile stays valid.
|
|
96
|
+
export type PlannedFile_oversized = Expect<Equal<PlannedFile['oversized'], true | undefined>>;
|
|
92
97
|
export const resultShape = { binary: true, extracted: [anExtract], sections: someSections } satisfies ExtractJobResult;
|
|
93
98
|
export type ExtractJobResult_fields = Expect<Equal<ExtractJobResult, { binary?: true; extracted: Extracted[]; sections?: ParsedSection[] }>>;
|
|
94
99
|
// ExtractFailed: the marker of a PROVEN-final extraction failure (the parser or extractor threw); every other failure is transient.
|
|
@@ -96,6 +101,14 @@ export type ExtractFailed_is_an_Error = Expect<Equal<InstanceType<typeof Extract
|
|
|
96
101
|
export type ExtractFailed_constructor = Expect<Equal<ConstructorParameters<typeof ExtractFailed>, [message: string, options?: { cause?: unknown }]>>;
|
|
97
102
|
// ExtractorState.failures: consecutive transient failures by path at one hash; optional so a hand-built state stays valid.
|
|
98
103
|
export type ExtractorState_failures = Expect<Equal<ExtractorState['failures'], ReadonlyMap<string, { hash: string; count: number }> | undefined>>;
|
|
104
|
+
// ExtractorState.oversized: claimed documents over the size cap, planned as assets; optional so a hand-built state stays valid.
|
|
105
|
+
export type ExtractorState_oversized = Expect<Equal<ExtractorState['oversized'], ReadonlySet<string> | undefined>>;
|
|
106
|
+
|
|
107
|
+
/* ── DirectorySource: optional per-path hooks ──────────────────────────────────────────────────────────────── */
|
|
108
|
+
// hashOf takes the path (a host whose read() transforms bytes returns the listing hash for it); a one-argument hashOf still satisfies it.
|
|
109
|
+
export type DirectorySource_hashOf = Expect<Equal<DirectorySource['hashOf'], ((text: string, path: string) => string) | undefined>>;
|
|
110
|
+
export type DirectorySource_hashOf_legacy_one_arg = Expect<Equal<((text: string) => string) extends NonNullable<DirectorySource['hashOf']> ? true : false, true>>;
|
|
111
|
+
export type DirectorySource_readTimeoutMs = Expect<Equal<DirectorySource['readTimeoutMs'], ((path: string) => number | undefined) | undefined>>;
|
|
99
112
|
|
|
100
113
|
/* ── KnowledgeStore: the port hosts implement ──────────────────────────────────────────────────────────────── */
|
|
101
114
|
export type KnowledgeStore_methods = Expect<Equal<
|
|
@@ -193,7 +206,7 @@ export type KNode_system_fields = Expect<Equal<
|
|
|
193
206
|
export type GraphSystem_fields = Expect<Equal<
|
|
194
207
|
GraphSystem,
|
|
195
208
|
{
|
|
196
|
-
path: string; name: string; files: number; apps: GraphApp[]; truncated?: boolean; copyOf?: string; copySimilarity?: number;
|
|
209
|
+
path: string; name: string; files: number; assets?: number; apps: GraphApp[]; truncated?: boolean; copyOf?: string; copySimilarity?: number;
|
|
197
210
|
copyReason?: 'no-git' | 'name-mismatch' | 'later-name'; graphRead?: { read: number; skipped: GraphReadSkip[] };
|
|
198
211
|
}
|
|
199
212
|
>>;
|
|
@@ -92,7 +92,8 @@ class ExtractBuilder {
|
|
|
92
92
|
/** A `links` edge to the target, unless it is the root itself (or a folder above it). */
|
|
93
93
|
link(from: NodeRef, target: string, byName?: string): void {
|
|
94
94
|
const clean = target.split('#')[0]!.split('?')[0]!.trim();
|
|
95
|
-
|
|
95
|
+
// A scheme (`https:`, `data:`, `mailto:`) or a protocol-relative `//cdn/x.png` is external, never a file of the root.
|
|
96
|
+
if (!clean || clean.startsWith('//') || /^[a-z][a-z0-9+.-]*:/i.test(clean)) return;
|
|
96
97
|
let decoded = clean;
|
|
97
98
|
try { decoded = decodeURI(clean); } catch { /* keep the raw target */ }
|
|
98
99
|
// Written as directory navigation (`.`, `./`, `..`, `/`, `docs/`): a folder, not a file link.
|
|
@@ -234,10 +235,11 @@ export function withoutCode(text: string, opts: { indented?: boolean } = {}): st
|
|
|
234
235
|
return out.join('\n').replace(INLINE_CODE, ' ');
|
|
235
236
|
}
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
/** `[text](target)` and the image form ``: both reference the target (an image file is an asset node). */
|
|
239
|
+
const MD_LINK = /\[[^\]]*\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g;
|
|
238
240
|
/** `[id]: target` definitions (reference-style links); the use is `[text][id]` or `[id][]`. */
|
|
239
241
|
const MD_REF_DEF = /^ {0,3}\[([^\]]+)\]:\s*<?(\S+?)>?(?:\s+["'(].*)?[ \t\r]*$/gm;
|
|
240
|
-
const MD_REF_USE =
|
|
242
|
+
const MD_REF_USE = /\[([^\]]*)\]\[([^\]]*)\]/g;
|
|
241
243
|
|
|
242
244
|
/** Reference-link definitions of a whole markdown text, by lower-cased label. */
|
|
243
245
|
function refDefinitions(text: string): Map<string, string> {
|
|
@@ -308,11 +310,14 @@ export function extractMarkdown(source: SourceDocument, sections: ParsedSection[
|
|
|
308
310
|
return b.build();
|
|
309
311
|
}
|
|
310
312
|
|
|
313
|
+
/** The first `href` / `src` / `xlink:href` of an `<a>`, `<img>`, `<source>`, `<link>` or svg `<image>` tag: a file the page references. */
|
|
314
|
+
const HTML_REF = /<(?:a|img|source|link|image)(?=\s)[^>]*?\s(?:xlink:)?(?:href|src)\s*=\s*["']([^"']+)["']/gi;
|
|
315
|
+
|
|
311
316
|
export function extractHtml(source: SourceDocument, sections: ParsedSection[], ctx: Ctx): Extracted {
|
|
312
317
|
const title = sections[0]?.metadata?.['htmlTitle'];
|
|
313
318
|
const b = new ExtractBuilder(source, ctx, typeof title === 'string' ? title : undefined);
|
|
314
319
|
if (typeof title === 'string' && title) b.key(b.fileRef, normalizeKey(title));
|
|
315
|
-
for (const m of textOf(source).matchAll(
|
|
320
|
+
for (const m of textOf(source).matchAll(HTML_REF)) {
|
|
316
321
|
if (!m[1]!.startsWith('#')) b.link(b.fileRef, m[1]!);
|
|
317
322
|
}
|
|
318
323
|
sections.forEach((section, index) => b.mentions(b.bodySection(index, section.text), section.text));
|
|
@@ -12,13 +12,13 @@ export const mediaTypeOf = (source: SourceDocument): string =>
|
|
|
12
12
|
source.content.kind === 'text' ? (source.content.mediaType ?? 'text/plain').toLowerCase() : '';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Binary documents — pdf, legacy
|
|
16
|
-
* text. The ingest pipeline's builtin parsers are unchanged (the html/xml and plain-text
|
|
15
|
+
* Binary documents — pdf, legacy (`vnd.ms-excel|powerpoint|word`, not other `vnd.ms-*` such as a font object) and OOXML/OpenDocument office
|
|
16
|
+
* files. Their bytes are not text. The ingest pipeline's builtin parsers are unchanged (the html/xml and plain-text
|
|
17
17
|
* matchers still accept these types); the knowledge composition (`composePacks`) is what
|
|
18
18
|
* makes the builtin docs parsers refuse them, so only a host extractor that turns them into
|
|
19
19
|
* text claims them there, in any pack order.
|
|
20
20
|
*/
|
|
21
21
|
export function isBinaryDocumentType(mediaType: string): boolean {
|
|
22
|
-
return /^application\/(?:pdf|msword|vnd\.(?:openxmlformats-officedocument\.|ms
|
|
22
|
+
return /^application\/(?:pdf|msword|vnd\.(?:openxmlformats-officedocument\.|ms-(?:excel|powerpoint|word)|oasis\.opendocument\.))/
|
|
23
23
|
.test(mediaType.trim().toLowerCase());
|
|
24
24
|
}
|