pi-odd-worktree 2.1.0 → 3.0.0
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 +54 -319
- package/extensions/odd-worktree-tools.ts +4145 -2529
- package/lib/bash-activity.js +1164 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1416 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +308 -14
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1419 -0
- package/tools/bash-design.test.js +1091 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +610 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1871 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +391 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// S9 (issues-sidebar, T14): lib/related-issues-cache.js — the in-process cache of the
|
|
3
|
+
// three scoped issue views (`mine`, `assigned`, `involved`).
|
|
4
|
+
//
|
|
5
|
+
// Pure by contract: no imports, no child process and no clock but the one
|
|
6
|
+
// injected. Everything below asserts the PUBLIC object only:
|
|
7
|
+
// - `plan(identity)` answers a full read (100 per bucket) with no entry, an
|
|
8
|
+
// entry older than `fullTtlMs` or an entry a previous apply left inconsistent,
|
|
9
|
+
// and an incremental read (20 per bucket) otherwise;
|
|
10
|
+
// - a full apply replaces each bucket, a delta merges by issue number and a
|
|
11
|
+
// newer row wins, and every bucket is sorted by `updatedAt` descending and
|
|
12
|
+
// trimmed to `bucketCap`;
|
|
13
|
+
// - the invariant: a bucket that is not truncated must cache exactly the count
|
|
14
|
+
// the response reported, and a mismatch is what makes the NEXT plan a full
|
|
15
|
+
// read (a closed or unassigned issue simply leaves a delta's result);
|
|
16
|
+
// - a bucket whose `issueCount` exceeds `bucketCap` is `truncated` and skips the
|
|
17
|
+
// invariant;
|
|
18
|
+
// - `get` answers copies, `drop` removes one identity and `clear` removes all.
|
|
19
|
+
|
|
20
|
+
const { test } = require('node:test');
|
|
21
|
+
const assert = require('node:assert/strict');
|
|
22
|
+
const { createIssuesCache } = require('../lib/related-issues-cache.js');
|
|
23
|
+
|
|
24
|
+
const ID = 'github.com/myfork/project';
|
|
25
|
+
const OTHER = 'github.com/myfork/other';
|
|
26
|
+
|
|
27
|
+
function issue(number, updatedAt, extra = {}) {
|
|
28
|
+
return { number, title: `Issue ${number}`, updatedAt, ...extra };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function bucket(rows, issueCount) {
|
|
32
|
+
return {
|
|
33
|
+
issueCount: Number.isInteger(issueCount) ? issueCount : rows.length,
|
|
34
|
+
issues: rows,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function response({ mine = [], assigned = [], involved = [], counts = {} } = {}) {
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
buckets: {
|
|
42
|
+
mine: bucket(mine, counts.mine),
|
|
43
|
+
assigned: bucket(assigned, counts.assigned),
|
|
44
|
+
involved: bucket(involved, counts.involved),
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function numbers(rows) {
|
|
50
|
+
return rows.map((row) => row.number);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
test('a full apply fills every bucket, sorted by updatedAt descending', () => {
|
|
54
|
+
const cache = createIssuesCache();
|
|
55
|
+
assert.equal(cache.get(ID), null, 'nothing is cached before the first read');
|
|
56
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 }, 'no entry means a full read');
|
|
57
|
+
|
|
58
|
+
const outcome = cache.apply(ID, response({
|
|
59
|
+
mine: [issue(1, '2024-01-01T00:00:00Z'), issue(2, '2024-03-01T00:00:00Z')],
|
|
60
|
+
assigned: [issue(3, '2024-02-01T00:00:00Z'), issue(4, '2024-04-01T00:00:00Z')],
|
|
61
|
+
involved: [issue(5, '2024-01-15T00:00:00Z')],
|
|
62
|
+
}), { full: true });
|
|
63
|
+
|
|
64
|
+
assert.deepEqual(outcome, {
|
|
65
|
+
consistent: true,
|
|
66
|
+
truncated: { mine: false, assigned: false, involved: false },
|
|
67
|
+
});
|
|
68
|
+
const got = cache.get(ID);
|
|
69
|
+
assert.deepEqual(numbers(got.buckets.mine), [2, 1]);
|
|
70
|
+
assert.deepEqual(numbers(got.buckets.assigned), [4, 3]);
|
|
71
|
+
assert.deepEqual(numbers(got.buckets.involved), [5]);
|
|
72
|
+
assert.equal(typeof got.syncedAt, 'number');
|
|
73
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 },
|
|
74
|
+
'a fresh, consistent entry reads only the newest 20 per bucket');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('get answers copies: a caller cannot mutate the cache', () => {
|
|
78
|
+
const cache = createIssuesCache();
|
|
79
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z', { labels: [{ name: 'bug' }] })] }), { full: true });
|
|
80
|
+
|
|
81
|
+
const first = cache.get(ID);
|
|
82
|
+
first.buckets.assigned[0].title = 'changed outside';
|
|
83
|
+
first.buckets.assigned[0].labels.push({ name: 'injected' });
|
|
84
|
+
first.buckets.assigned.length = 0;
|
|
85
|
+
first.truncated.assigned = true;
|
|
86
|
+
|
|
87
|
+
const second = cache.get(ID);
|
|
88
|
+
assert.equal(second.buckets.assigned[0].title, 'Issue 1', 'the stored row is untouched');
|
|
89
|
+
assert.deepEqual(second.buckets.assigned[0].labels, [{ name: 'bug' }]);
|
|
90
|
+
assert.equal(second.truncated.assigned, false);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('a delta merges by issue number and a newer row replaces the older one', () => {
|
|
94
|
+
const cache = createIssuesCache();
|
|
95
|
+
cache.apply(ID, response({
|
|
96
|
+
assigned: [issue(1, '2024-01-01T00:00:00Z'), issue(2, '2024-02-01T00:00:00Z')],
|
|
97
|
+
}), { full: true });
|
|
98
|
+
|
|
99
|
+
const outcome = cache.apply(ID, response({
|
|
100
|
+
assigned: [
|
|
101
|
+
issue(2, '2024-05-01T00:00:00Z', { title: 'Issue 2 (updated)' }),
|
|
102
|
+
issue(3, '2024-06-01T00:00:00Z'),
|
|
103
|
+
],
|
|
104
|
+
counts: { assigned: 3 },
|
|
105
|
+
}), { full: false });
|
|
106
|
+
|
|
107
|
+
assert.equal(outcome.consistent, true, 'every delta row merged and the count still matches');
|
|
108
|
+
const got = cache.get(ID);
|
|
109
|
+
assert.deepEqual(numbers(got.buckets.assigned), [3, 2, 1]);
|
|
110
|
+
assert.equal(got.buckets.assigned[1].title, 'Issue 2 (updated)', 'the newer row won');
|
|
111
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('each bucket is sorted by updatedAt and trimmed to bucketCap', () => {
|
|
115
|
+
const cache = createIssuesCache({ bucketCap: 3 });
|
|
116
|
+
const outcome = cache.apply(ID, response({
|
|
117
|
+
assigned: [
|
|
118
|
+
issue(1, '2024-01-01T00:00:00Z'),
|
|
119
|
+
issue(2, '2024-05-01T00:00:00Z'),
|
|
120
|
+
issue(3, '2024-03-01T00:00:00Z'),
|
|
121
|
+
issue(4, '2024-02-01T00:00:00Z'),
|
|
122
|
+
issue(5, '2024-04-01T00:00:00Z'),
|
|
123
|
+
],
|
|
124
|
+
counts: { assigned: 5 },
|
|
125
|
+
}), { full: true });
|
|
126
|
+
|
|
127
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [2, 5, 3], 'the three newest survive');
|
|
128
|
+
assert.equal(outcome.truncated.assigned, true, 'the bucket holds more than the cap');
|
|
129
|
+
assert.equal(outcome.consistent, true, 'a truncated bucket skips the count invariant');
|
|
130
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a delta after an issue left the set breaks the invariant and the next plan is full', () => {
|
|
134
|
+
const cache = createIssuesCache();
|
|
135
|
+
cache.apply(ID, response({
|
|
136
|
+
assigned: [issue(1, '2024-01-01T00:00:00Z'), issue(2, '2024-02-01T00:00:00Z')],
|
|
137
|
+
}), { full: true });
|
|
138
|
+
|
|
139
|
+
// Issue 1 was closed, so the delta (the newest 20) cannot see it: the cached
|
|
140
|
+
// rows still hold two issues while the response reports one.
|
|
141
|
+
const outcome = cache.apply(ID, response({
|
|
142
|
+
assigned: [issue(2, '2024-03-01T00:00:00Z')],
|
|
143
|
+
}), { full: false });
|
|
144
|
+
|
|
145
|
+
assert.equal(outcome.consistent, false, 'the mismatch is detected, never hidden');
|
|
146
|
+
assert.equal(outcome.truncated.assigned, false);
|
|
147
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 },
|
|
148
|
+
'the next sync re-reads every bucket in full');
|
|
149
|
+
|
|
150
|
+
// A full re-read clears the inconsistency.
|
|
151
|
+
const repaired = cache.apply(ID, response({ assigned: [issue(2, '2024-03-01T00:00:00Z')] }), { full: true });
|
|
152
|
+
assert.equal(repaired.consistent, true);
|
|
153
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// T17 (E17b): the inconsistency `plan` acts on is the same fact a CONSUMER needs:
|
|
157
|
+
// a bucket of such an entry cannot report an exact total, because the entry no
|
|
158
|
+
// longer knows how many open issues it holds. `get` reports it; a clean full
|
|
159
|
+
// read clears it.
|
|
160
|
+
test('T17: get reports the entry inconsistency plan acts on', () => {
|
|
161
|
+
const cache = createIssuesCache();
|
|
162
|
+
cache.apply(ID, response({
|
|
163
|
+
assigned: [issue(1, '2024-01-01T00:00:00Z'), issue(2, '2024-02-01T00:00:00Z')],
|
|
164
|
+
}), { full: true });
|
|
165
|
+
assert.equal(cache.get(ID).inconsistent, false, 'a clean full read is consistent');
|
|
166
|
+
|
|
167
|
+
// Issue 1 was closed, so the delta (the newest 20) cannot see it: the cached
|
|
168
|
+
// rows still hold two issues while the response reports one.
|
|
169
|
+
cache.apply(ID, response({
|
|
170
|
+
assigned: [issue(2, '2024-03-01T00:00:00Z')],
|
|
171
|
+
}), { full: false });
|
|
172
|
+
assert.equal(cache.get(ID).inconsistent, true, 'get exposes the mismatch it detected');
|
|
173
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 },
|
|
174
|
+
'and it is the same fact the next sync acts on');
|
|
175
|
+
|
|
176
|
+
cache.apply(ID, response({
|
|
177
|
+
assigned: [issue(2, '2024-03-01T00:00:00Z')],
|
|
178
|
+
}), { full: true });
|
|
179
|
+
assert.equal(cache.get(ID).inconsistent, false, 'a clean full read clears it');
|
|
180
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('a truncated bucket skips the count invariant on a delta too', () => {
|
|
184
|
+
const cache = createIssuesCache({ bucketCap: 2 });
|
|
185
|
+
const first = cache.apply(ID, response({
|
|
186
|
+
assigned: [issue(1, '2024-01-01T00:00:00Z'), issue(2, '2024-02-01T00:00:00Z')],
|
|
187
|
+
counts: { assigned: 50 },
|
|
188
|
+
}), { full: true });
|
|
189
|
+
assert.deepEqual(first.truncated, { mine: false, assigned: true, involved: false });
|
|
190
|
+
assert.equal(first.consistent, true, 'a bucket larger than the cap is never held to a count it cannot store');
|
|
191
|
+
|
|
192
|
+
const delta = cache.apply(ID, response({
|
|
193
|
+
assigned: [issue(1, '2024-03-01T00:00:00Z'), issue(3, '2024-04-01T00:00:00Z')],
|
|
194
|
+
counts: { assigned: 50 },
|
|
195
|
+
}), { full: false });
|
|
196
|
+
assert.equal(delta.consistent, true, 'the invariant stays skipped while the bucket is truncated');
|
|
197
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [3, 1], 'merged, sorted and capped');
|
|
198
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test('fullTtlMs makes an aged entry plan a full read', () => {
|
|
202
|
+
let clock = 1000;
|
|
203
|
+
const cache = createIssuesCache({ now: () => clock, fullTtlMs: 600000 });
|
|
204
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
205
|
+
|
|
206
|
+
clock += 599999;
|
|
207
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
208
|
+
clock += 1;
|
|
209
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 },
|
|
210
|
+
'an entry older than ten minutes re-reads in full');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('entries are keyed by repository identity', () => {
|
|
214
|
+
const cache = createIssuesCache();
|
|
215
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
216
|
+
|
|
217
|
+
assert.equal(cache.get(OTHER), null, 'another repository sees nothing');
|
|
218
|
+
assert.deepEqual(cache.plan(OTHER), { full: true, first: 100 });
|
|
219
|
+
|
|
220
|
+
cache.apply(OTHER, response({ assigned: [issue(9, '2024-02-01T00:00:00Z')] }), { full: true });
|
|
221
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [1]);
|
|
222
|
+
assert.deepEqual(numbers(cache.get(OTHER).buckets.assigned), [9]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('drop removes one identity and clear removes every identity', () => {
|
|
226
|
+
const cache = createIssuesCache();
|
|
227
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
228
|
+
cache.apply(OTHER, response({ assigned: [issue(2, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
229
|
+
|
|
230
|
+
cache.drop(ID);
|
|
231
|
+
assert.equal(cache.get(ID), null);
|
|
232
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 });
|
|
233
|
+
assert.deepEqual(numbers(cache.get(OTHER).buckets.assigned), [2], 'the other identity survives');
|
|
234
|
+
|
|
235
|
+
cache.clear();
|
|
236
|
+
assert.equal(cache.get(OTHER), null);
|
|
237
|
+
assert.deepEqual(cache.plan(OTHER), { full: true, first: 100 });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('apply never throws and a failed answer leaves the cached entry untouched', () => {
|
|
241
|
+
const cache = createIssuesCache();
|
|
242
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
243
|
+
|
|
244
|
+
for (const bad of [null, undefined, {}, { ok: false, error: 'gh failed' }]) {
|
|
245
|
+
const outcome = cache.apply(ID, bad, { full: false });
|
|
246
|
+
assert.equal(outcome.consistent, false);
|
|
247
|
+
assert.ok(outcome.truncated, 'the outcome still reports the three buckets');
|
|
248
|
+
}
|
|
249
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [1],
|
|
250
|
+
'a failed answer never mutates the cache');
|
|
251
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 });
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
// T15 (S9, verify round 3 defect 3): the ten-minute bound is measured from the
|
|
255
|
+
// last FULL read, never from the last delta. A steady stream of deltas used to
|
|
256
|
+
// renew the timestamp `plan` compared against, so the full re-read slid forever.
|
|
257
|
+
test('T15: every delta moves syncedAt but only a full read moves the ten-minute bound', () => {
|
|
258
|
+
let clock = 1000;
|
|
259
|
+
const cache = createIssuesCache({ now: () => clock, fullTtlMs: 600000 });
|
|
260
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
261
|
+
const fullReadAt = cache.get(ID).syncedAt;
|
|
262
|
+
assert.equal(fullReadAt, clock);
|
|
263
|
+
|
|
264
|
+
// One delta a minute, for nine minutes: each one lands and stamps `syncedAt`,
|
|
265
|
+
// and every one of them still plans the next read as a delta.
|
|
266
|
+
for (let minute = 1; minute <= 9; minute += 1) {
|
|
267
|
+
clock = fullReadAt + minute * 60000;
|
|
268
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: false });
|
|
269
|
+
assert.equal(cache.get(ID).syncedAt, clock, `delta at minute ${minute} stamped syncedAt`);
|
|
270
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 },
|
|
271
|
+
`the cache is inside its window at minute ${minute}`);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 600001 ms after the FULL read, however many deltas landed since, the ten
|
|
275
|
+
// minutes are up: a delta never postponed the full re-read.
|
|
276
|
+
clock = fullReadAt + 600001;
|
|
277
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 },
|
|
278
|
+
'the ten-minute bound is measured from the full read, not from the last delta');
|
|
279
|
+
assert.equal(cache.get(ID).syncedAt, fullReadAt + 9 * 60000,
|
|
280
|
+
'syncedAt still reports the last apply, not the full read');
|
|
281
|
+
|
|
282
|
+
// A full read starts the window over.
|
|
283
|
+
cache.apply(ID, response({ assigned: [issue(1, '2024-01-01T00:00:00Z')] }), { full: true });
|
|
284
|
+
assert.deepEqual(cache.plan(ID), { full: false, first: 20 },
|
|
285
|
+
'a full apply renews the ten-minute bound');
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// T15 (S9, verify round 3 defect 5): the wiring numbers a read when it STARTS.
|
|
289
|
+
// An answer whose number is older than the last one applied for that identity is
|
|
290
|
+
// ignored, so a full read that finishes after a newer one can never overwrite it.
|
|
291
|
+
test('T15: an answer older than the last applied sequence is ignored', () => {
|
|
292
|
+
let clock = 2000;
|
|
293
|
+
const cache = createIssuesCache({ now: () => clock, fullTtlMs: 600000 });
|
|
294
|
+
|
|
295
|
+
// Read A starts first (sequence 1); read B starts next (sequence 2) and its
|
|
296
|
+
// full answer lands first.
|
|
297
|
+
cache.apply(ID, response({ assigned: [issue(22, '2024-02-01T00:00:00Z')] }), { full: true, sequence: 2 });
|
|
298
|
+
|
|
299
|
+
// A answers afterwards. It is older by start order, so it changes nothing.
|
|
300
|
+
clock = 3000;
|
|
301
|
+
const late = cache.apply(ID, response({ assigned: [issue(11, '2024-01-01T00:00:00Z')] }), { full: true, sequence: 1 });
|
|
302
|
+
assert.equal(late.consistent, false, 'the older answer reports it was not applied');
|
|
303
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [22], 'the newer full read survives');
|
|
304
|
+
assert.equal(cache.get(ID).syncedAt, 2000, 'the ignored answer did not stamp the entry');
|
|
305
|
+
|
|
306
|
+
// A delta that started after B merges on top of B; the older full answer
|
|
307
|
+
// arriving still later cannot replace that merge either.
|
|
308
|
+
clock = 4000;
|
|
309
|
+
cache.apply(ID, response({
|
|
310
|
+
assigned: [issue(23, '2024-03-01T00:00:00Z')],
|
|
311
|
+
counts: { assigned: 2 },
|
|
312
|
+
}), { full: false, sequence: 3 });
|
|
313
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [23, 22]);
|
|
314
|
+
clock = 5000;
|
|
315
|
+
cache.apply(ID, response({ assigned: [issue(11, '2024-01-01T00:00:00Z')] }), { full: true, sequence: 1 });
|
|
316
|
+
assert.deepEqual(numbers(cache.get(ID).buckets.assigned), [23, 22],
|
|
317
|
+
'the older full answer never overwrites a newer delta');
|
|
318
|
+
|
|
319
|
+
// The ten-minute bound is still the newer full read's: had the older full
|
|
320
|
+
// answer been applied at 3000 or 5000, it would have moved it.
|
|
321
|
+
clock = 2000 + 600001;
|
|
322
|
+
assert.deepEqual(cache.plan(ID), { full: true, first: 100 },
|
|
323
|
+
'the bound counts from the applied full read, never from the ignored older one');
|
|
324
|
+
});
|