-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathsearchLimitExplanation.test.ts
More file actions
95 lines (88 loc) · 2.62 KB
/
searchLimitExplanation.test.ts
File metadata and controls
95 lines (88 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { expect, test } from 'vitest';
import type { SearchStats } from './types';
import { getSearchLimitExplanation } from './searchLimitExplanation';
function stats(overrides: Partial<SearchStats>): SearchStats {
return {
actualMatchCount: 10,
totalMatchCount: 10,
duration: 0,
fileCount: 1,
filesSkipped: 0,
contentBytesLoaded: 0,
indexBytesLoaded: 0,
crashes: 0,
shardFilesConsidered: 0,
filesConsidered: 0,
filesLoaded: 0,
shardsScanned: 1,
shardsSkipped: 0,
shardsSkippedFilter: 0,
ngramMatches: 0,
ngramLookups: 0,
wait: 0,
matchTreeConstruction: 0,
matchTreeSearch: 0,
regexpsConsidered: 0,
flushReason: 'FLUSH_REASON_UNKNOWN_UNSPECIFIED',
...overrides,
};
}
test('missing stats yields generic incomplete message', () => {
const out = getSearchLimitExplanation(undefined, 100);
expect(out.summary).toContain('incomplete');
});
test('shardsSkipped takes precedence (time limit / partial scan)', () => {
const out = getSearchLimitExplanation(
stats({
shardsSkipped: 2,
totalMatchCount: 500,
filesSkipped: 99,
}),
100,
);
expect(out.summary).toContain('did not scan the entire index');
});
test('totalMatchCount above display cap explains match budget', () => {
const out = getSearchLimitExplanation(
stats({
actualMatchCount: 100,
totalMatchCount: 250,
}),
100,
);
expect(out.summary).toContain('More matches exist');
expect(out.detail).toContain('250');
});
test('filesSkipped without shard skip explains early stop', () => {
const out = getSearchLimitExplanation(
stats({
totalMatchCount: 50,
actualMatchCount: 50,
filesSkipped: 10,
}),
100,
);
expect(out.summary).toContain('candidate files');
});
test('flushReason timer when no higher-priority signal', () => {
const out = getSearchLimitExplanation(
stats({
flushReason: 'FLUSH_REASON_TIMER_EXPIRED',
totalMatchCount: 10,
actualMatchCount: 10,
}),
100,
);
expect(out.summary).toContain('streaming timer');
});
test('flushReason max size when no higher-priority signal', () => {
const out = getSearchLimitExplanation(
stats({
flushReason: 'FLUSH_REASON_MAX_SIZE',
totalMatchCount: 10,
actualMatchCount: 10,
}),
100,
);
expect(out.summary).toContain('size limit');
});