notesoup 0.56.0 → 0.57.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 +1 -1
- package/dist/plugins/pi/marker.d.ts +4 -2
- package/dist/plugins/pi/marker.js +18 -8
- package/dist/plugins/pi/reset/lifecycle.js +6 -0
- package/dist/plugins/pi/runtime.js +8 -8
- package/dist/plugins/pi/text.js +1 -1
- package/dist/src/history/claude.d.ts +2 -0
- package/dist/src/history/claude.js +13 -2
- package/dist/src/history/codex-transcript.d.ts +15 -3
- package/dist/src/history/codex-transcript.js +57 -21
- package/dist/src/history/codex.d.ts +4 -2
- package/dist/src/history/codex.js +3 -3
- package/dist/src/history/corpus.d.ts +8 -1
- package/dist/src/history/corpus.js +17 -1
- package/dist/src/history/history.d.ts +16 -10
- package/dist/src/history/history.js +9 -9
- package/dist/src/history/local.d.ts +2 -0
- package/dist/src/history/local.js +35 -38
- package/dist/src/history/prefilter.d.ts +5 -0
- package/dist/src/history/prefilter.js +95 -0
- package/dist/src/history/query.d.ts +29 -27
- package/dist/src/history/query.js +82 -34
- package/dist/src/history/summary-cache.d.ts +10 -0
- package/dist/src/history/summary-cache.js +129 -0
- package/dist/src/tools/history.js +31 -20
- package/dist/test/agent-loop.test.js +62 -27
- package/dist/test/codex-history.test.js +90 -4
- package/dist/test/codex-plugin.test.js +6 -2
- package/dist/test/history-corpus.test.js +221 -33
- package/dist/test/history-prefilter.test.d.ts +1 -0
- package/dist/test/history-prefilter.test.js +174 -0
- package/dist/test/history-summary-cache.test.d.ts +1 -0
- package/dist/test/history-summary-cache.test.js +297 -0
- package/dist/test/history.integration.test.js +87 -52
- package/dist/test/marker.test.js +46 -15
- package/dist/test/model-facing-text.test.js +1 -1
- package/dist/test/reset-lifecycle.test.js +4 -6
- package/docs/architecture.md +1 -1
- package/docs/history-sessions.md +26 -2
- package/docs/reset-lifecycle.md +4 -4
- package/docs/tool-results.md +4 -2
- package/package.json +1 -1
- package/plugins/claude/.claude-plugin/plugin.json +1 -1
- package/plugins/claude/dist/claude/helper.js +425 -122
- package/plugins/codex/dist/codex/notesoup.js +423 -123
- package/plugins/pi/marker.ts +18 -12
- package/plugins/pi/reset/lifecycle.ts +5 -0
- package/plugins/pi/runtime.ts +8 -8
- package/plugins/pi/text.ts +1 -1
- package/src/history/claude.ts +16 -2
- package/src/history/codex-transcript.ts +52 -17
- package/src/history/codex.ts +5 -5
- package/src/history/corpus.ts +19 -2
- package/src/history/history.ts +11 -11
- package/src/history/local.ts +34 -38
- package/src/history/prefilter.ts +86 -0
- package/src/history/query.ts +77 -33
- package/src/history/summary-cache.ts +119 -0
- package/src/tools/history.ts +33 -20
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import { realpathSync } from "node:fs";
|
|
4
|
+
import { syncBuiltinESMExports } from "node:module";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
import { test } from "node:test";
|
|
8
|
+
import { zstdCompressSync } from "node:zlib";
|
|
9
|
+
import { localHistoryCorpus } from "../src/history/local.js";
|
|
10
|
+
import { cachedSessionRepresentative, historySummaryCacheRoot } from "../src/history/summary-cache.js";
|
|
11
|
+
import { projectHistory } from "../src/history/history.js";
|
|
12
|
+
import { historyList, historyRead } from "../src/tools/history.js";
|
|
13
|
+
const AT = "2026-10-06T01:02:03.000Z";
|
|
14
|
+
const ROOT = "019a0000-0000-7000-8000-000000000001";
|
|
15
|
+
const CHILD = "019a0000-0000-7000-8000-000000000002";
|
|
16
|
+
const jsonl = (rows) => rows.map((row) => JSON.stringify(row) + "\n").join("");
|
|
17
|
+
function data(result) { assert.ok(result.ok, JSON.stringify(result)); return result.data; }
|
|
18
|
+
function projection(text) {
|
|
19
|
+
return projectHistory([{ windowId: "w", items: [{ seq: 2, windowId: "w", role: "user", text, createdAt: AT }] }], 2, new Set([2]));
|
|
20
|
+
}
|
|
21
|
+
function piText(text, extra = []) {
|
|
22
|
+
return jsonl([
|
|
23
|
+
{ type: "session", version: 3, id: "offline", cwd: "/workspace", timestamp: AT },
|
|
24
|
+
{ type: "message", id: "u", parentId: null, timestamp: AT, message: { role: "user", content: text } }, ...extra,
|
|
25
|
+
]);
|
|
26
|
+
}
|
|
27
|
+
async function fixture(t) {
|
|
28
|
+
const home = await fs.mkdtemp(join(tmpdir(), "notesoup-history-summary-"));
|
|
29
|
+
t.after(() => fs.rm(home, { recursive: true, force: true }));
|
|
30
|
+
const roots = { pi: join(home, "pi"), claude: join(home, "claude"), codex: join(home, "codex/sessions") };
|
|
31
|
+
const cacheRoot = join(home, "cache");
|
|
32
|
+
async function put(path, content) {
|
|
33
|
+
await fs.mkdir(dirname(path), { recursive: true });
|
|
34
|
+
await fs.writeFile(path, content);
|
|
35
|
+
return path;
|
|
36
|
+
}
|
|
37
|
+
const piPath = join(roots.pi, "workspace", "2026-10-06_offline.jsonl");
|
|
38
|
+
function corpus(root = cacheRoot) {
|
|
39
|
+
return localHistoryCorpus({ roots, home, env: {}, summaryCacheRoot: root, current: { harness: "dsh", id: "live", load: async () => ({ projection: projection("live") }) } });
|
|
40
|
+
}
|
|
41
|
+
function context(root = cacheRoot) { return { current: () => projection("live"), corpus: corpus(root) }; }
|
|
42
|
+
return { home, roots, piPath, cacheRoot, put, corpus, context };
|
|
43
|
+
}
|
|
44
|
+
function transcriptReads(t, paths) {
|
|
45
|
+
const readFile = fs.readFile;
|
|
46
|
+
const watched = new Set(paths.flatMap((path) => [path, realpathSync(path)]));
|
|
47
|
+
const reads = [];
|
|
48
|
+
const spy = t.mock.method(fs, "readFile", (...args) => {
|
|
49
|
+
if (watched.has(String(args[0])))
|
|
50
|
+
reads.push(String(args[0]));
|
|
51
|
+
return readFile(...args);
|
|
52
|
+
});
|
|
53
|
+
syncBuiltinESMExports();
|
|
54
|
+
t.after(() => { spy.mock.restore(); syncBuiltinESMExports(); });
|
|
55
|
+
return reads;
|
|
56
|
+
}
|
|
57
|
+
async function cacheEntries(root) {
|
|
58
|
+
return (await fs.readdir(root).catch(() => [])).filter((name) => name.endsWith(".json"));
|
|
59
|
+
}
|
|
60
|
+
test("cache roots follow platform conventions without adding a public setting", () => {
|
|
61
|
+
assert.equal(historySummaryCacheRoot("/home/u", {}, "darwin"), "/home/u/Library/Caches/notesoup/history");
|
|
62
|
+
assert.equal(historySummaryCacheRoot("/home/u", {}, "linux"), "/home/u/.cache/notesoup/history");
|
|
63
|
+
assert.equal(historySummaryCacheRoot("/home/u", { XDG_CACHE_HOME: "/xdg" }, "linux"), "/xdg/notesoup/history");
|
|
64
|
+
});
|
|
65
|
+
test("a fresh corpus reuses a strict representative without reading the body, preserving caller preview budgets", async (t) => {
|
|
66
|
+
const f = await fixture(t), text = "😀 opening " + "full content ".repeat(600);
|
|
67
|
+
await f.put(f.piPath, piText(text));
|
|
68
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
69
|
+
const before = await fs.stat(f.piPath);
|
|
70
|
+
const cold = data(await historyList.execute({ session: "pi:*", max_chars_per_item: 5 }, f.context()));
|
|
71
|
+
assert.equal(reads.length, 1);
|
|
72
|
+
const warm = data(await historyList.execute({ session: "pi:*", max_chars_per_item: 16000 }, f.context()));
|
|
73
|
+
assert.equal(reads.length, 1, "a new corpus must read only the cache, not the transcript");
|
|
74
|
+
assert.equal(warm.items.length, 1);
|
|
75
|
+
const item = warm.items[0];
|
|
76
|
+
assert.ok(!("folded" in item));
|
|
77
|
+
assert.equal(item.content, text);
|
|
78
|
+
assert.equal(item.session, "pi:offline");
|
|
79
|
+
assert.ok(!("folded" in cold.items[0]));
|
|
80
|
+
assert.equal(cold.items[0].truncated, true);
|
|
81
|
+
const entries = await cacheEntries(f.cacheRoot);
|
|
82
|
+
assert.equal(entries.length, 1);
|
|
83
|
+
const entry = JSON.parse(await fs.readFile(join(f.cacheRoot, entries[0]), "utf8"));
|
|
84
|
+
assert.equal(entry.event.text, text);
|
|
85
|
+
assert.equal(entry.session, "pi:offline");
|
|
86
|
+
assert.equal(entry.fingerprints.length, 1);
|
|
87
|
+
assert.equal("projection" in entry, false);
|
|
88
|
+
assert.equal((await fs.stat(f.piPath)).mtimeMs, before.mtimeMs);
|
|
89
|
+
assert.equal((await fs.stat(f.piPath)).ctimeMs, before.ctimeMs);
|
|
90
|
+
});
|
|
91
|
+
test("empty and tool-only sessions cache strict selection, full documents and nested-call summaries", async (t) => {
|
|
92
|
+
const f = await fixture(t);
|
|
93
|
+
const header = { type: "session", version: 3, id: "offline", cwd: "/workspace", timestamp: AT };
|
|
94
|
+
await f.put(f.piPath, jsonl([header]));
|
|
95
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
96
|
+
const params = { session: "pi:*", max_chars_per_item: 16000 };
|
|
97
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0);
|
|
98
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0);
|
|
99
|
+
assert.equal(reads.length, 1);
|
|
100
|
+
await fs.writeFile(f.piPath, jsonl([header, { type: "message", id: "tool", parentId: null, timestamp: AT, message: { role: "toolResult", toolName: "delegate", content: "😀 full output", nestedCalls: { complete: true, calls: [{ id: "nested", name: "read", status: "ok", arguments: { path: "精确.json" }, durationMs: 7 }] } } }]));
|
|
101
|
+
const cold = await historyList.execute(params, f.context());
|
|
102
|
+
assert.match(historyList.render(cold), /full output/);
|
|
103
|
+
assert.match(historyList.render(cold), /精确.json/);
|
|
104
|
+
assert.deepEqual(await historyList.execute(params, f.context()), cold);
|
|
105
|
+
assert.equal(reads.length, 2);
|
|
106
|
+
});
|
|
107
|
+
test("append, equal-size rewrite with restored mtime, and atomic replacement invalidate summaries", async (t) => {
|
|
108
|
+
const f = await fixture(t);
|
|
109
|
+
await f.put(f.piPath, piText("first"));
|
|
110
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
111
|
+
const params = { session: "pi:*" };
|
|
112
|
+
await historyList.execute(params, f.context());
|
|
113
|
+
await fs.appendFile(f.piPath, jsonl([{ type: "message", id: "a", parentId: "u", timestamp: AT, message: { role: "assistant", content: "tail" } }]));
|
|
114
|
+
await historyList.execute(params, f.context());
|
|
115
|
+
assert.equal(reads.length, 2);
|
|
116
|
+
const before = await fs.stat(f.piPath);
|
|
117
|
+
const old = await fs.readFile(f.piPath, "utf8");
|
|
118
|
+
await fs.writeFile(f.piPath, old.replace("first", "other"));
|
|
119
|
+
await fs.utimes(f.piPath, before.atime, before.mtime);
|
|
120
|
+
const changed = data(await historyList.execute(params, f.context()));
|
|
121
|
+
assert.equal(reads.length, 4); // one explicit fixture read plus the strict rebuild
|
|
122
|
+
assert.ok(!("folded" in changed.items[0]));
|
|
123
|
+
assert.equal(changed.items[0].content, "other");
|
|
124
|
+
await f.put(f.piPath + ".replacement", piText("third"));
|
|
125
|
+
await fs.rename(f.piPath + ".replacement", f.piPath);
|
|
126
|
+
await fs.utimes(f.piPath, before.atime, before.mtime);
|
|
127
|
+
const replaced = data(await historyList.execute(params, f.context()));
|
|
128
|
+
assert.ok(!("folded" in replaced.items[0]));
|
|
129
|
+
assert.equal(replaced.items[0].content, "third");
|
|
130
|
+
assert.equal(reads.length, 5);
|
|
131
|
+
});
|
|
132
|
+
test("search, roles, time filters and explicit sessions bypass the summary while empty queries reuse it", async (t) => {
|
|
133
|
+
const f = await fixture(t);
|
|
134
|
+
await f.put(f.piPath, piText("opening", [{ type: "message", id: "a", parentId: "u", timestamp: "2026-10-07T00:00:00Z", message: { role: "assistant", content: "later" } }]));
|
|
135
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
136
|
+
const ctx = f.context();
|
|
137
|
+
await historyList.execute({ session: "pi:*" }, ctx);
|
|
138
|
+
for (const query of ["", [], ["", ""]])
|
|
139
|
+
await historyList.execute({ session: "pi:*", query }, ctx);
|
|
140
|
+
assert.equal(reads.length, 1);
|
|
141
|
+
for (const filters of [{ roles: ["assistant"] }, { since: "2026-10-07" }, { until: "2026-10-07" }, { query: "later" }, { session: "pi:offline" }]) {
|
|
142
|
+
const before = reads.length;
|
|
143
|
+
const params = { session: "pi:*", ...filters };
|
|
144
|
+
const result = await historyList.execute(params, ctx);
|
|
145
|
+
assert.ok(reads.length > before, JSON.stringify(params));
|
|
146
|
+
const plain = { current: () => projection("live"), corpus: { currentHarness: "dsh", sessions: async (harness) => (await f.corpus().sessions(harness)).map(({ loadRepresentative: _cache, ...session }) => session) } };
|
|
147
|
+
assert.deepEqual(result, await historyList.execute(params, plain));
|
|
148
|
+
}
|
|
149
|
+
assert.equal(data(await historyList.execute({ session: "pi:*", since: "2026-10-07" }, ctx)).items.length, 1);
|
|
150
|
+
assert.equal(data(await historyList.execute({ session: "pi:*", until: AT }, ctx)).items.length, 0, "until is exclusive");
|
|
151
|
+
});
|
|
152
|
+
test("corrupt cache/schema and unwritable roots fall back; a warm cache cannot hide malformed or unsupported transcripts", async (t) => {
|
|
153
|
+
const f = await fixture(t);
|
|
154
|
+
await f.put(f.piPath, piText("opening"));
|
|
155
|
+
const params = { session: "pi:*" };
|
|
156
|
+
const expected = await historyList.execute(params, f.context());
|
|
157
|
+
const [name] = await cacheEntries(f.cacheRoot);
|
|
158
|
+
const path = join(f.cacheRoot, name);
|
|
159
|
+
const valid = JSON.parse(await fs.readFile(path, "utf8"));
|
|
160
|
+
for (const content of ["not json", "{}", JSON.stringify({ version: "old-decoder" }), JSON.stringify({ ...valid, notice: { invalid: true } }), JSON.stringify({ ...valid, event: { ...valid.event, role: "invented" } })]) {
|
|
161
|
+
await fs.writeFile(path, content);
|
|
162
|
+
assert.deepEqual(await historyList.execute(params, f.context()), expected);
|
|
163
|
+
}
|
|
164
|
+
const blockedRoot = await f.put(join(f.home, "cache-is-a-file"), "not a directory");
|
|
165
|
+
assert.deepEqual(await historyList.execute(params, f.context(blockedRoot)), expected);
|
|
166
|
+
await fs.writeFile(f.piPath, piText("opening") + "malformed committed record\n");
|
|
167
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0);
|
|
168
|
+
assert.equal((await historyList.execute({ session: "pi:offline" }, f.context())).ok, false);
|
|
169
|
+
assert.equal((await historyRead.execute({ session: "pi:offline", seq: 2 }, f.context())).ok, false);
|
|
170
|
+
await fs.writeFile(f.piPath, piText("opening").replace('"parentId":null', '"parentId":123'));
|
|
171
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0);
|
|
172
|
+
});
|
|
173
|
+
test("a cache entry growing beyond 8 MiB after its read is a miss, not a transcript refusal", async (t) => {
|
|
174
|
+
const f = await fixture(t);
|
|
175
|
+
await f.put(f.piPath, piText("opening"));
|
|
176
|
+
const params = { session: "pi:*" };
|
|
177
|
+
const expected = await historyList.execute(params, f.context());
|
|
178
|
+
const [name] = await cacheEntries(f.cacheRoot);
|
|
179
|
+
const cachePath = join(f.cacheRoot, name);
|
|
180
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
181
|
+
const open = fs.open;
|
|
182
|
+
const spy = t.mock.method(fs, "open", async (...args) => {
|
|
183
|
+
const file = await open(...args);
|
|
184
|
+
if (String(args[0]) === cachePath) {
|
|
185
|
+
const stat = file.stat.bind(file);
|
|
186
|
+
let calls = 0;
|
|
187
|
+
t.mock.method(file, "stat", async () => {
|
|
188
|
+
if (++calls === 2)
|
|
189
|
+
await fs.appendFile(cachePath, " ".repeat(8 * 1024 * 1024));
|
|
190
|
+
return stat();
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return file;
|
|
194
|
+
});
|
|
195
|
+
syncBuiltinESMExports();
|
|
196
|
+
t.after(() => { spy.mock.restore(); syncBuiltinESMExports(); });
|
|
197
|
+
assert.deepEqual(await historyList.execute(params, f.context()), expected);
|
|
198
|
+
assert.equal(reads.length, 1, "otherwise the valid JSON prefix would have been reused despite oversized disk entry");
|
|
199
|
+
assert.ok((await fs.stat(cachePath)).size <= 8 * 1024 * 1024);
|
|
200
|
+
});
|
|
201
|
+
test("live bindings always replace offline cache descriptors", async (t) => {
|
|
202
|
+
const f = await fixture(t);
|
|
203
|
+
await f.put(f.piPath, piText("offline"));
|
|
204
|
+
await historyList.execute({ session: "pi:*" }, f.context());
|
|
205
|
+
const reads = transcriptReads(t, [f.piPath]);
|
|
206
|
+
let liveReads = 0;
|
|
207
|
+
const current = { harness: "pi", id: "offline", load: async () => { liveReads++; return { projection: projection("live version") }; }, loadRepresentative: async () => { throw new Error("must not use any cached capability for current"); } };
|
|
208
|
+
const corpus = localHistoryCorpus({ roots: f.roots, summaryCacheRoot: f.cacheRoot, current });
|
|
209
|
+
for (let i = 0; i < 2; i++) {
|
|
210
|
+
const page = data(await historyList.execute({ session: "*" }, { current: () => projection("live version"), corpus }));
|
|
211
|
+
assert.ok(!("folded" in page.items[0]));
|
|
212
|
+
assert.equal(page.items[0].content, "live version");
|
|
213
|
+
}
|
|
214
|
+
assert.equal(liveReads, 2);
|
|
215
|
+
assert.equal(reads.length, 0);
|
|
216
|
+
});
|
|
217
|
+
test("strict Claude branch selection and missing-ancestor notices survive cached previews", async (t) => {
|
|
218
|
+
const f = await fixture(t), path = join(f.roots.claude, "workspace", "offline-claude.jsonl");
|
|
219
|
+
const row = (uuid, parentUuid, content) => ({ type: "user", uuid, parentUuid, sessionId: "offline-claude", timestamp: AT, message: { role: "user", content } });
|
|
220
|
+
await f.put(path, jsonl([row("old", null, "excluded branch"), row("selected", "missing", "selected topic")]));
|
|
221
|
+
const reads = transcriptReads(t, [path]);
|
|
222
|
+
const cold = await historyList.execute({ session: "claude:*" }, f.context());
|
|
223
|
+
const warm = await historyList.execute({ session: "claude:*" }, f.context());
|
|
224
|
+
assert.deepEqual(warm, cold);
|
|
225
|
+
assert.equal(reads.length, 1);
|
|
226
|
+
assert.match(data(warm).notice, /missing ancestor/);
|
|
227
|
+
assert.doesNotMatch(historyList.render(warm), /excluded branch/);
|
|
228
|
+
assert.match(historyList.render(warm), /selected topic/);
|
|
229
|
+
});
|
|
230
|
+
test("raced rebuilds and summaries larger than 8 MiB are returned normally but not admitted", async (t) => {
|
|
231
|
+
const f = await fixture(t);
|
|
232
|
+
await f.put(f.piPath, "source");
|
|
233
|
+
let loads = 0;
|
|
234
|
+
const raced = async () => {
|
|
235
|
+
loads++;
|
|
236
|
+
await fs.appendFile(f.piPath, "x");
|
|
237
|
+
return { data: { projection: projection("strict result") } };
|
|
238
|
+
};
|
|
239
|
+
for (let i = 0; i < 2; i++)
|
|
240
|
+
assert.equal((await cachedSessionRepresentative({ harness: "pi", id: "offline" }, f.piPath, f.cacheRoot, raced)).event.text, "strict result");
|
|
241
|
+
assert.equal(loads, 2);
|
|
242
|
+
assert.deepEqual(await cacheEntries(f.cacheRoot), []);
|
|
243
|
+
const huge = "x".repeat(8 * 1024 * 1024);
|
|
244
|
+
await cachedSessionRepresentative({ harness: "pi", id: "offline" }, f.piPath, f.cacheRoot, async () => ({ data: { projection: projection(huge) } }));
|
|
245
|
+
assert.deepEqual(await cacheEntries(f.cacheRoot), []);
|
|
246
|
+
});
|
|
247
|
+
function codexRow(type, payload, ordinal) { return { timestamp: AT, type, payload, ordinal }; }
|
|
248
|
+
function codexMeta(id, extra = {}) { return { id, cwd: "/workspace", cli_version: "0.160.1", history_mode: "paginated", context_window: { window_id: "019a0000-0000-7000-8000-000000000010" }, ...extra }; }
|
|
249
|
+
function codexName(id) { return `rollout-2026-10-06T01-02-03-${id}.jsonl`; }
|
|
250
|
+
function codexMessage(text) { return { type: "message", role: "user", content: [{ type: "input_text", text }] }; }
|
|
251
|
+
test("Codex cache fingerprints actual archived compressed ancestors and revalidates source discovery ambiguity/missing files", async (t) => {
|
|
252
|
+
const f = await fixture(t);
|
|
253
|
+
const ancestor = jsonl([codexRow("session_meta", codexMeta(ROOT), 0), codexRow("response_item", codexMessage("parent topic"), 1)]);
|
|
254
|
+
const ancestorPath = join(f.home, "codex/archived_sessions", codexName(ROOT) + ".zst");
|
|
255
|
+
const ancestorFile = ancestor + jsonl([codexRow("response_item", codexMessage("EXCLUDED PARENT SUFFIX"), 2)]);
|
|
256
|
+
await f.put(ancestorPath, zstdCompressSync(Buffer.from(ancestorFile)));
|
|
257
|
+
const childPath = join(f.roots.codex, "2026/10/06", codexName(CHILD));
|
|
258
|
+
await f.put(childPath, jsonl([
|
|
259
|
+
codexRow("session_meta", codexMeta(CHILD, { history_base: { thread_id: ROOT, end_ordinal_exclusive: 2, end_byte_offset: Buffer.byteLength(ancestor) }, forked_from_id: ROOT, forked_from_ordinal_exclusive: 2 }), 2),
|
|
260
|
+
codexRow("response_item", codexMessage("child topic"), 3),
|
|
261
|
+
]));
|
|
262
|
+
const reads = transcriptReads(t, [childPath, ancestorPath]);
|
|
263
|
+
const params = { session: `codex:${CHILD}*` };
|
|
264
|
+
const cold = await historyList.execute(params, f.context());
|
|
265
|
+
assert.equal(data(cold).items.length, 1);
|
|
266
|
+
assert.match(historyList.render(cold), /parent topic/);
|
|
267
|
+
assert.equal(reads.length, 2);
|
|
268
|
+
assert.deepEqual(await historyList.execute(params, f.context()), cold);
|
|
269
|
+
assert.equal(reads.length, 2, "neither root nor ancestor body is reread on a warm hit");
|
|
270
|
+
assert.doesNotMatch(historyList.render(cold), /EXCLUDED/);
|
|
271
|
+
const [name] = await cacheEntries(f.cacheRoot);
|
|
272
|
+
const cachePath = join(f.cacheRoot, name);
|
|
273
|
+
const entry = JSON.parse(await fs.readFile(cachePath, "utf8"));
|
|
274
|
+
assert.deepEqual(entry.fingerprints.map((source) => source.path), [realpathSync(childPath), realpathSync(ancestorPath)]);
|
|
275
|
+
assert.deepEqual(entry.lineageSources.map((source) => source.path), [realpathSync(ancestorPath)]);
|
|
276
|
+
for (const incomplete of [{ fingerprints: entry.fingerprints.slice(0, 1) }, { lineageSources: [] }, { fingerprints: entry.fingerprints.slice(1) }]) {
|
|
277
|
+
await fs.writeFile(cachePath, JSON.stringify({ ...entry, ...incomplete }));
|
|
278
|
+
const before = reads.length;
|
|
279
|
+
assert.deepEqual(await historyList.execute(params, f.context()), cold);
|
|
280
|
+
assert.equal(reads.length, before + 2, "incomplete root/ancestor fingerprint or lineage witness must miss");
|
|
281
|
+
}
|
|
282
|
+
const beforeEdit = reads.length;
|
|
283
|
+
await fs.writeFile(ancestorPath, zstdCompressSync(Buffer.from(ancestorFile.replace("parent topic", "edited topic"))));
|
|
284
|
+
const updated = await historyList.execute(params, f.context());
|
|
285
|
+
assert.match(historyList.render(updated), /edited topic/);
|
|
286
|
+
assert.equal(reads.length, beforeEdit + 2);
|
|
287
|
+
const duplicatePath = join(f.roots.codex, "2026/10/07", codexName(ROOT));
|
|
288
|
+
await f.put(duplicatePath, ancestor);
|
|
289
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0, "new ambiguous discovery must invalidate a warm child summary");
|
|
290
|
+
const explicit = await historyList.execute({ session: `codex:${CHILD}` }, f.context());
|
|
291
|
+
assert.ok(!explicit.ok);
|
|
292
|
+
assert.match(explicit.error.message, /ambiguous native files/);
|
|
293
|
+
await fs.unlink(duplicatePath);
|
|
294
|
+
assert.match(historyList.render(await historyList.execute(params, f.context())), /edited topic/);
|
|
295
|
+
await fs.unlink(ancestorPath);
|
|
296
|
+
assert.equal(data(await historyList.execute(params, f.context())).items.length, 0);
|
|
297
|
+
});
|
|
@@ -5,7 +5,7 @@ import { TOOL_OUTPUT_MAX_BYTES } from "../src/tools/output.js";
|
|
|
5
5
|
import { earliestMatchOffsetChars } from "../src/text-match.js";
|
|
6
6
|
import { historyList, historyRead } from "../src/tools/history.js";
|
|
7
7
|
import { historyDocument, projectHistory } from "../src/history/history.js";
|
|
8
|
-
import { selectPage } from "../src/history/query.js";
|
|
8
|
+
import { HistoryPageSchema, selectPage } from "../src/history/query.js";
|
|
9
9
|
import { appendText, assertWithinBudget, call, context, makeExtension, manager, resultData, resultError, resultRead, } from "./helpers/extension.js";
|
|
10
10
|
import { installExtensionTestHooks } from "./helpers/extension-test-environment.js";
|
|
11
11
|
import { isolateHistoryRoots, writePiTranscript } from "./helpers/history-corpus.js";
|
|
@@ -60,9 +60,10 @@ test("history_list exposes bounded paging, `from` and a literal query, while not
|
|
|
60
60
|
const listSchema = captured.tools.get("history_list").parameters;
|
|
61
61
|
const properties = listSchema.properties;
|
|
62
62
|
assert.equal(properties.before_seq?.minimum, 1, "bounds are positive seqs");
|
|
63
|
-
assert.equal(properties.after_seq?.minimum,
|
|
63
|
+
assert.equal(properties.after_seq?.minimum, 0);
|
|
64
64
|
assert.equal(Check(listSchema, { before_seq: 0 }), false, "before_seq:0 is refused by the schema, not answered with a silent empty page");
|
|
65
|
-
assert.equal(Check(listSchema, { after_seq: 0 }),
|
|
65
|
+
assert.equal(Check(listSchema, { after_seq: 0 }), true);
|
|
66
|
+
assert.equal(Check(listSchema, { after_seq: -1 }), false);
|
|
66
67
|
assert.deepEqual(properties.from?.anyOf?.map((item) => item.const), ["newest", "oldest"]);
|
|
67
68
|
assert.ok(properties.query);
|
|
68
69
|
assert.equal(properties.around, undefined);
|
|
@@ -169,6 +170,12 @@ test("a result address consumed by a pairing resolves directly to its call event
|
|
|
169
170
|
assert.equal(callSeq.seq, 2);
|
|
170
171
|
assert.equal(callSeq.content, 'edit {"path":"a.md"}\n--- output ---\nedited');
|
|
171
172
|
});
|
|
173
|
+
test("history page schema exposes plain boolean paging flags", () => {
|
|
174
|
+
for (const field of [HistoryPageSchema.properties.has_older, HistoryPageSchema.properties.has_newer]) {
|
|
175
|
+
assert.equal(field.type, "boolean");
|
|
176
|
+
assert.equal("description" in field, false);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
172
179
|
test("history_list pages from the end `from` names and returns bounded ranges", async () => {
|
|
173
180
|
const session = manager();
|
|
174
181
|
const captured = makeExtension(session);
|
|
@@ -180,25 +187,43 @@ test("history_list pages from the end `from` names and returns bounded ranges",
|
|
|
180
187
|
appendText(session, "user", "message-6");
|
|
181
188
|
const older = page(await call(captured, "history_list", { before_seq: 5, limit: 2 }, ctx));
|
|
182
189
|
assert.deepEqual(older.items.map((item) => item.seq), [3, 4]);
|
|
183
|
-
assert.
|
|
184
|
-
assert.equal(older.
|
|
190
|
+
assert.equal(older.has_older, true);
|
|
191
|
+
assert.equal(older.has_newer, false);
|
|
185
192
|
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 5, limit: 2, from: "oldest" }, ctx)), [6]);
|
|
186
193
|
for (let index = 7; index <= 10; index++)
|
|
187
194
|
appendText(session, "user", `message-${index}`);
|
|
188
|
-
|
|
189
|
-
assert.deepEqual(
|
|
190
|
-
assert.
|
|
191
|
-
assert.deepEqual(
|
|
192
|
-
assert.
|
|
193
|
-
assert.deepEqual(seqs(await call(captured, "history_list", {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
195
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 0, limit: 3 }, ctx)), [1, 2, 3]);
|
|
196
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 2, limit: 3 }, ctx)), [3, 4, 5]);
|
|
197
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 2, limit: 3, from: "newest" }, ctx)), [8, 9, 10]);
|
|
198
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 2, before_seq: 10, limit: 3 }, ctx)), [3, 4, 5]);
|
|
199
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { after_seq: 2, before_seq: 10, limit: 3, from: "newest" }, ctx)), [7, 8, 9]);
|
|
200
|
+
assert.deepEqual(seqs(await call(captured, "history_list", { before_seq: 10, limit: 3, from: "oldest" }, ctx)), [1, 2, 3]);
|
|
201
|
+
let forward = { after_seq: 2, before_seq: 10, limit: 3 };
|
|
202
|
+
const forwardSeqs = [];
|
|
203
|
+
while (true) {
|
|
204
|
+
const result = await call(captured, "history_list", forward, ctx);
|
|
205
|
+
const current = page(result);
|
|
206
|
+
forwardSeqs.push(...seqs(result));
|
|
207
|
+
if (!current.has_newer)
|
|
208
|
+
break;
|
|
209
|
+
const footer = /→ newer: (\{[^\n]+\})/.exec(rendered(result));
|
|
210
|
+
assert.ok(footer);
|
|
211
|
+
forward = { ...forward, ...JSON.parse(footer[1]) };
|
|
212
|
+
}
|
|
213
|
+
assert.deepEqual(forwardSeqs, [3, 4, 5, 6, 7, 8, 9]);
|
|
214
|
+
let backward = { after_seq: 2, before_seq: 10, limit: 3, from: "newest" };
|
|
215
|
+
const backwardPages = [];
|
|
216
|
+
while (true) {
|
|
217
|
+
const result = await call(captured, "history_list", backward, ctx);
|
|
218
|
+
const current = page(result);
|
|
219
|
+
backwardPages.unshift(seqs(result));
|
|
220
|
+
if (!current.has_older)
|
|
221
|
+
break;
|
|
222
|
+
const footer = /→ older: (\{[^\n]+\})/.exec(rendered(result));
|
|
223
|
+
assert.ok(footer);
|
|
224
|
+
backward = { ...backward, ...JSON.parse(footer[1]) };
|
|
225
|
+
}
|
|
226
|
+
assert.deepEqual(backwardPages.flat(), [3, 4, 5, 6, 7, 8, 9]);
|
|
202
227
|
});
|
|
203
228
|
test("a one-row page budget admits the newest candidate first", () => {
|
|
204
229
|
const windowId = "w1";
|
|
@@ -207,7 +232,7 @@ test("a one-row page budget admits the newest candidate first", () => {
|
|
|
207
232
|
const keptSeqs = (fitsRows, from) => {
|
|
208
233
|
const outcome = selectPage(projection, { limit: 3, ...(from === undefined ? {} : { from }) }, (candidate) => candidate.items.length <= fitsRows, 200);
|
|
209
234
|
assert.equal(outcome.ok, true);
|
|
210
|
-
return outcome.ok ? outcome.data.items.map((item) =>
|
|
235
|
+
return outcome.ok ? outcome.data.items.map((item) => item.seq) : [];
|
|
211
236
|
};
|
|
212
237
|
assert.deepEqual(keptSeqs(1), [3], "a budget for one row admits the newest candidate, not the oldest");
|
|
213
238
|
assert.deepEqual(keptSeqs(2), [2, 3], "a truncated prefix is the newest rows, delivered in chronological order");
|
|
@@ -234,22 +259,29 @@ test("conversation paging prepares ordered folds once, including during first-ro
|
|
|
234
259
|
assert.equal(full.ok, true);
|
|
235
260
|
if (!full.ok)
|
|
236
261
|
return;
|
|
237
|
-
assert.deepEqual(full.data.items.map((item) =>
|
|
238
|
-
[1, 1, 1, {}],
|
|
262
|
+
assert.deepEqual(full.data.items.map((item) => [item.seq, item.folded_before]), [
|
|
263
|
+
[2, { first_seq: 1, last_seq: 1, count: 1, tools: {} }], [6, { first_seq: 3, last_seq: 5, count: 2, tools: { read: 1 } }], [8, { first_seq: 7, last_seq: 7, count: 1, tools: { bash: 1 } }],
|
|
239
264
|
]);
|
|
265
|
+
assert.deepEqual(full.data.folded_after, { first_seq: 9, last_seq: 9, count: 1, tools: {} });
|
|
240
266
|
assert.equal(traversals, 1, "growing the page never re-traverses the source windows");
|
|
267
|
+
const oldest = selectPage(projection, { limit: 1, from: "oldest" }, () => true, 1000);
|
|
268
|
+
assert.ok(oldest.ok);
|
|
269
|
+
if (oldest.ok)
|
|
270
|
+
assert.deepEqual(oldest.data.items[0].folded_before, { first_seq: 1, last_seq: 1, count: 1, tools: {} });
|
|
241
271
|
traversals = 0;
|
|
242
272
|
let attempts = 0;
|
|
243
273
|
const trimmed = selectPage(projection, { limit: 3 }, (candidate) => {
|
|
244
274
|
attempts++;
|
|
245
|
-
return candidate.items.length <= 2 && candidate.items.every((item) =>
|
|
275
|
+
return candidate.items.length <= 2 && candidate.items.every((item) => item.content.length <= 10);
|
|
246
276
|
}, 1000);
|
|
247
277
|
assert.equal(trimmed.ok, true);
|
|
248
278
|
if (!trimmed.ok)
|
|
249
279
|
return;
|
|
250
|
-
assert.deepEqual(trimmed.data.items.map((item) =>
|
|
251
|
-
assert.
|
|
252
|
-
assert.
|
|
280
|
+
assert.deepEqual(trimmed.data.items.map((item) => item.seq), [8], "a short newest page keeps its tail fold, not the preceding gap");
|
|
281
|
+
assert.equal(trimmed.data.items[0].folded_before, undefined);
|
|
282
|
+
assert.deepEqual(trimmed.data.folded_after, { first_seq: 9, last_seq: 9, count: 1, tools: {} });
|
|
283
|
+
assert.equal(trimmed.data.has_older, true);
|
|
284
|
+
assert.equal(trimmed.data.has_newer, false);
|
|
253
285
|
assert.ok(attempts > 3, "the first preview exercised repeated budget probes");
|
|
254
286
|
assert.equal(traversals, 1, "shortening also reuses the same prepared folds");
|
|
255
287
|
});
|
|
@@ -273,9 +305,9 @@ test("list shortening charges folded rows against both text and JSON budgets", a
|
|
|
273
305
|
assert.equal(row.seq, 2);
|
|
274
306
|
assert.equal(row.truncated, true);
|
|
275
307
|
assert.ok(row.content.length < withoutFold.content.length, "the fold consumes bytes but not the one-event limit");
|
|
276
|
-
assert.deepEqual(folded.data.
|
|
277
|
-
assert.
|
|
278
|
-
assert.equal(folded.data.
|
|
308
|
+
assert.deepEqual(folded.data.folded_after, { first_seq: 3, last_seq: 3, count: 1, tools: { read: 1 } });
|
|
309
|
+
assert.equal(folded.data.has_older, true);
|
|
310
|
+
assert.equal(folded.data.has_newer, false);
|
|
279
311
|
assert.ok(Buffer.byteLength(JSON.stringify(folded.data), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
280
312
|
assert.ok(Buffer.byteLength(historyList.render(folded), "utf8") <= TOOL_OUTPUT_MAX_BYTES);
|
|
281
313
|
});
|
|
@@ -291,7 +323,7 @@ test("since and until select a half-open time range, compose with query and pagi
|
|
|
291
323
|
const selected = async (params) => {
|
|
292
324
|
const outcome = await historyList.execute(params, projection);
|
|
293
325
|
assert.equal(outcome.ok, true, JSON.stringify(outcome));
|
|
294
|
-
return outcome.ok ? outcome.data.items.map((item) =>
|
|
326
|
+
return outcome.ok ? outcome.data.items.map((item) => item.seq) : [];
|
|
295
327
|
};
|
|
296
328
|
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", since: "2026-10-10T06:00:00Z" }), [2, 3, 4], "since keeps later events and drops one with no time");
|
|
297
329
|
assert.deepEqual(await selected({ roles: ["user", "assistant"], from: "oldest", until: "2026-10-10T12:00:00Z" }), [1, 2], "until is exclusive");
|
|
@@ -321,11 +353,11 @@ test("time bounds also keep untimed events out of the folded conversation view",
|
|
|
321
353
|
const bounded = await historyList.execute({ since: "2026-10-10T00:00:00Z" }, projection);
|
|
322
354
|
assert.equal(bounded.ok, true);
|
|
323
355
|
if (bounded.ok)
|
|
324
|
-
assert.deepEqual(bounded.data.items.map((item) =>
|
|
356
|
+
assert.deepEqual(bounded.data.items.map((item) => `seq ${item.seq}`), ["seq 1", "seq 3"], "an untimed tool event is not folded into a bounded selection");
|
|
325
357
|
const unbounded = await historyList.execute({}, projection);
|
|
326
358
|
assert.equal(unbounded.ok, true);
|
|
327
359
|
if (unbounded.ok)
|
|
328
|
-
assert.equal(unbounded.data.items.some((item) =>
|
|
360
|
+
assert.equal(unbounded.data.items.some((item) => item.folded_before !== undefined), true, "without bounds the untimed run still folds");
|
|
329
361
|
});
|
|
330
362
|
test("conversation view folds tools and injected messages, while explicit roles expand them", async () => {
|
|
331
363
|
const session = manager();
|
|
@@ -348,19 +380,22 @@ test("conversation view folds tools and injected messages, while explicit roles
|
|
|
348
380
|
append(session, { role: "assistant", content: [], stopReason: "toolUse", timestamp: Date.now() });
|
|
349
381
|
const conversation = page(await call(captured, "history_list", {}, ctx));
|
|
350
382
|
const legacyItemKey = ["item", "id"].join("_");
|
|
351
|
-
assert.
|
|
383
|
+
assert.ok(conversation.folded_after);
|
|
384
|
+
assert.ok(conversation.items.every((item) => "seq" in item && !("folded" in item)));
|
|
352
385
|
assert.equal(conversation.items.some((item) => item.role === "developer"), false);
|
|
353
386
|
assert.equal(conversation.items.some((item) => item.role === "tool"), false);
|
|
354
387
|
assert.equal(conversation.items.some((item) => item.role === "assistant" && item.content === ""), false);
|
|
355
388
|
assert.equal(conversation.items.every((item) => legacyItemKey in item === false), true);
|
|
356
|
-
const folded = conversation.
|
|
389
|
+
const folded = conversation.folded_after;
|
|
357
390
|
assert.equal(folded.count, 3, "two tool events and one injected context are folded, not the empty assistant message");
|
|
358
391
|
assert.deepEqual(folded.tools, { bash: 1, read: 1 });
|
|
359
392
|
assert.equal("custom_types" in folded, false);
|
|
360
393
|
const empty = page(await call(captured, "history_list", { roles: ["context"], before_seq: 2 }, ctx));
|
|
361
394
|
assert.deepEqual(empty.items, []);
|
|
362
395
|
const hiddenOnly = page(await call(captured, "history_list", { after_seq: 2, before_seq: 6 }, ctx));
|
|
363
|
-
assert.deepEqual(hiddenOnly.items, [
|
|
396
|
+
assert.deepEqual(hiddenOnly.items, []);
|
|
397
|
+
assert.deepEqual(hiddenOnly.folded_after, { first_seq: 3, last_seq: 4, count: 2, tools: { bash: 1, read: 1 } });
|
|
398
|
+
assert.match(rendered(await call(captured, "history_list", { after_seq: 2, before_seq: 6 }, ctx)), /seqs 3-4 \| folded 2 events/);
|
|
364
399
|
const expanded = page(await call(captured, "history_list", { roles: ["tool"] }, ctx));
|
|
365
400
|
assert.deepEqual(expanded.items.map((item) => [item.seq, item.role, item.tool, item.tool_status]), [[3, "tool", "bash", "ok"], [4, "tool", "read", "ok"]]);
|
|
366
401
|
assert.equal(expanded.items[0].content, 'bash {"command":"pwd"}\n--- output ---\nok');
|
|
@@ -539,7 +574,7 @@ test("list renders paging and fold recipes across resets, and read renders a nei
|
|
|
539
574
|
toolResult(session, "t1", "bash", "done");
|
|
540
575
|
appendText(session, "user", "after tools");
|
|
541
576
|
const folded = await call(captured, "history_list", {}, ctx);
|
|
542
|
-
assert.match(rendered(folded), /→ expand: \{"after_seq":\d+,"before_seq":\d+,"
|
|
577
|
+
assert.match(rendered(folded), /→ expand: \{"after_seq":\d+,"before_seq":\d+,"roles":\["tool","context"\]\}/, "a folded row prints its own expand recipe");
|
|
543
578
|
appendText(session, "user", "needle read target");
|
|
544
579
|
const hits = page(await call(captured, "history_list", { query: "needle read target" }, ctx));
|
|
545
580
|
const read = await call(captured, "history_read", { seq: hits.items[0].seq }, ctx);
|
|
@@ -553,8 +588,8 @@ test("compaction summary becomes context and is folded in the default list", asy
|
|
|
553
588
|
session.appendCompaction("summary needle", session.getLeafId(), 100);
|
|
554
589
|
appendText(session, "assistant", "after checkpoint");
|
|
555
590
|
const regular = page(await call(captured, "history_list", {}, ctx));
|
|
556
|
-
assert.deepEqual(regular.items.map((item) => item.
|
|
557
|
-
const folded = regular.items[1];
|
|
591
|
+
assert.deepEqual(regular.items.map((item) => item.role), ["user", "assistant"]);
|
|
592
|
+
const folded = regular.items[1].folded_before;
|
|
558
593
|
assert.equal(folded.count, 1);
|
|
559
594
|
assert.deepEqual(folded.tools, {});
|
|
560
595
|
const contextItems = page(await call(captured, "history_list", { roles: ["context"] }, ctx));
|
|
@@ -575,8 +610,8 @@ test("a query covers every role, carries match offsets and treats empty queries
|
|
|
575
610
|
assert.equal("custom_type" in developers.items[0], false);
|
|
576
611
|
const first = page(await call(captured, "history_list", { query: "needle", after_seq: 1, limit: 1, from: "oldest" }, ctx));
|
|
577
612
|
assert.deepEqual(first.items.map((item) => item.seq), [2]);
|
|
578
|
-
assert.
|
|
579
|
-
const next = page(await call(captured, "history_list", { query: "needle",
|
|
613
|
+
assert.equal(first.has_newer, true);
|
|
614
|
+
const next = page(await call(captured, "history_list", { query: "needle", after_seq: first.items.at(-1).seq, limit: 2 }, ctx));
|
|
580
615
|
assert.deepEqual(next.items.map((item) => item.seq), [3]);
|
|
581
616
|
const absent = await call(captured, "history_list", { query: "absent" }, ctx);
|
|
582
617
|
assert.deepEqual(page(absent).items, []);
|
|
@@ -588,7 +623,7 @@ test("a query covers every role, carries match offsets and treats empty queries
|
|
|
588
623
|
}
|
|
589
624
|
assert.deepEqual(page(await call(captured, "history_list", { query: ["", "needle"] }, ctx)), all, "empty entries do not turn OR into match-all");
|
|
590
625
|
});
|
|
591
|
-
test("
|
|
626
|
+
test("has_older and has_newer round-trip a session with no duplicates and no gaps", async () => {
|
|
592
627
|
const session = manager();
|
|
593
628
|
const captured = makeExtension(session);
|
|
594
629
|
const ctx = context(session);
|
|
@@ -597,27 +632,27 @@ test("page_older and page_newer round-trip a session with no duplicates and no g
|
|
|
597
632
|
const forward = [];
|
|
598
633
|
let current = page(await call(captured, "history_list", { query: "needle", from: "oldest", limit: 3 }, ctx));
|
|
599
634
|
assert.deepEqual(current.items.map((item) => item.seq), [1, 2, 3]);
|
|
600
|
-
assert.equal(current.
|
|
601
|
-
assert.
|
|
635
|
+
assert.equal(current.has_older, false, "the first page in `from` oldest has nothing older");
|
|
636
|
+
assert.equal(current.has_newer, true);
|
|
602
637
|
forward.push(...current.items.map((item) => item.seq));
|
|
603
|
-
while (current.
|
|
604
|
-
const cursor = current.
|
|
638
|
+
while (current.has_newer) {
|
|
639
|
+
const cursor = { after_seq: current.items.at(-1).seq };
|
|
605
640
|
current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
|
|
606
641
|
forward.push(...current.items.map((item) => item.seq));
|
|
607
642
|
}
|
|
608
|
-
assert.deepEqual(forward, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "
|
|
643
|
+
assert.deepEqual(forward, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "has_newer visits every event exactly once, in order");
|
|
609
644
|
const backward = [];
|
|
610
645
|
current = page(await call(captured, "history_list", { query: "needle", limit: 3 }, ctx));
|
|
611
646
|
assert.deepEqual(current.items.map((item) => item.seq), [8, 9, 10]);
|
|
612
|
-
assert.
|
|
647
|
+
assert.equal(current.has_older, true);
|
|
613
648
|
backward.push(...current.items.map((item) => item.seq));
|
|
614
|
-
while (current.
|
|
615
|
-
const cursor = current.
|
|
649
|
+
while (current.has_older) {
|
|
650
|
+
const cursor = { before_seq: current.items[0].seq };
|
|
616
651
|
current = page(await call(captured, "history_list", { query: "needle", ...cursor, limit: 3 }, ctx));
|
|
617
652
|
backward.push(...current.items.map((item) => item.seq));
|
|
618
653
|
}
|
|
619
|
-
assert.deepEqual(backward, [8, 9, 10, 5, 6, 7, 2, 3, 4, 1], "
|
|
620
|
-
assert.equal(current.
|
|
654
|
+
assert.deepEqual(backward, [8, 9, 10, 5, 6, 7, 2, 3, 4, 1], "has_older walks back with no duplicates and no gaps");
|
|
655
|
+
assert.equal(current.has_older, false);
|
|
621
656
|
});
|
|
622
657
|
test("query previews start at case-insensitive literal matches and offsets read the same Unicode document", async () => {
|
|
623
658
|
const session = manager();
|
|
@@ -717,5 +752,5 @@ test("historyDocument is one deterministic projection of the facts, with no UI h
|
|
|
717
752
|
const listed = await historyList.execute({}, projection);
|
|
718
753
|
assert.equal(listed.ok, true);
|
|
719
754
|
if (listed.ok)
|
|
720
|
-
assert.equal(listed.data.items.some((item) =>
|
|
755
|
+
assert.equal(listed.data.items.some((item) => item.folded_before?.count === 1) || listed.data.folded_after?.count === 1, true);
|
|
721
756
|
});
|