oc-harness-setup 0.2.0 → 0.3.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/.docs/unwired-routing.md +14 -9
- package/.gitignore +14 -1
- package/AGENTS.md +70 -106
- package/README.md +27 -23
- package/agents/build.md +10 -12
- package/agents/explore.md +14 -8
- package/agents/general.md +7 -9
- package/agents/orchestrator.md +38 -0
- package/agents/plan.md +10 -13
- package/agents/reviewer.md +9 -14
- package/agents/vault.md +44 -35
- package/bin/cli.js +32 -3
- package/commands/build.md +2 -8
- package/commands/checkpoint.md +3 -1
- package/commands/code-simplify.md +3 -9
- package/commands/gauntlet.md +7 -0
- package/commands/handoff.md +3 -1
- package/commands/keeper.md +3 -3
- package/commands/kill.md +11 -0
- package/commands/plan.md +2 -13
- package/commands/retro.md +15 -0
- package/commands/review.md +1 -1
- package/commands/ship.md +3 -27
- package/commands/spec.md +3 -11
- package/commands/test.md +2 -9
- package/commands/webperf.md +7 -0
- package/opencode.jsonc +23 -8
- package/package.json +3 -3
- package/reference/README.md +14 -14
- package/reference/auto-mandate.md +11 -0
- package/reference/backup-convention.md +9 -0
- package/reference/clean-mandate.md +13 -0
- package/reference/editor-parity.md +7 -0
- package/reference/gc-scripts.md +8 -0
- package/reference/intent-routing.md +14 -0
- package/reference/lifecycle.md +15 -0
- package/reference/model-keeper.md +30 -10
- package/reference/model-test.md +11 -6
- package/reference/models.md +25 -14
- package/reference/oc-source-map.md +162 -0
- package/reference/owner-pin.md +31 -0
- package/reference/roster.md +15 -0
- package/reference/session-scope.md +9 -0
- package/reference/session-state.md +13 -0
- package/reference/swarm.md +32 -0
- package/scripts/backup-config.ps1 +42 -0
- package/scripts/gc-branch.ps1 +196 -0
- package/scripts/gc-bump.ps1 +198 -0
- package/scripts/gc-clean.ps1 +648 -0
- package/scripts/gc-commit.ps1 +143 -0
- package/scripts/gc-merge.ps1 +272 -0
- package/scripts/gc-pr.ps1 +190 -0
- package/scripts/gc-push.ps1 +111 -0
- package/scripts/gc-read.ps1 +150 -0
- package/scripts/gc-rebase.ps1 +162 -0
- package/scripts/gc-release.ps1 +225 -0
- package/scripts/gc-stage.ps1 +103 -0
- package/scripts/gc-status.ps1 +127 -0
- package/scripts/gc-sync.ps1 +65 -0
- package/scripts/gc.core.ps1 +715 -0
- package/scripts/gc.smoke.ps1 +779 -0
- package/scripts/harness-doctor.ps1 +11 -9
- package/scripts/interrupt-session.ps1 +65 -0
- package/scripts/logbook/README.md +108 -0
- package/scripts/logbook/logbook.test.ts +440 -0
- package/scripts/logbook/logbook.ts +797 -0
- package/scripts/pirep/README.md +147 -0
- package/scripts/pirep/pirep.test.ts +735 -0
- package/scripts/pirep/pirep.ts +836 -0
- package/scripts/testflight/README.md +112 -0
- package/scripts/testflight/testflight.test.ts +512 -0
- package/scripts/testflight/testflight.ts +806 -0
- package/skills/_shared/SOURCES.md +7 -7
- package/skills/_shared/references/definition-of-done.md +2 -2
- package/skills/_shared/references/orchestration-patterns.md +1 -2
- package/skills/_shared/references/security-checklist.md +2 -2
- package/skills/api-and-interface-design/SKILL.md +7 -360
- package/skills/browser-testing-with-devtools/SKILL.md +303 -0
- package/skills/code-simplification/SKILL.md +7 -364
- package/skills/creative-writing/SKILL.md +1 -1
- package/skills/debugging-and-error-recovery/SKILL.md +8 -309
- package/skills/flight-deck/SKILL.md +17 -0
- package/skills/frontend-ui-engineering/SKILL.md +8 -320
- package/skills/gauntlet/SKILL.md +21 -0
- package/skills/git-ceremony/SKILL.md +16 -318
- package/skills/grilling/SKILL.md +10 -30
- package/skills/observability-and-instrumentation/SKILL.md +9 -229
- package/skills/performance-optimization/SKILL.md +8 -488
- package/skills/pilot-report/SKILL.md +18 -0
- package/skills/planning-and-task-breakdown/SKILL.md +8 -249
- package/skills/security-and-hardening/SKILL.md +9 -490
- package/skills/source-driven-development/SKILL.md +8 -208
- package/skills/spec-driven-development/SKILL.md +15 -234
- package/skills/test-driven-development/SKILL.md +8 -388
- package/skills/test-flight/SKILL.md +14 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +3 -3
- package/skills/writing-for-agents/SKILL.md +7 -1
- package/agents/coder.md +0 -19
- package/agents/documenter.md +0 -28
- package/agents/keeper.md +0 -22
- package/agents/master.md +0 -70
- package/agents/researcher.md +0 -21
- package/agents/security-auditor.md +0 -20
- package/agents/test-engineer.md +0 -20
- package/agents/web-performance-auditor.md +0 -19
- package/commands/council.md +0 -24
- package/commands/doctor.md +0 -19
- package/commands/ponytail-audit.md +0 -7
- package/commands/ponytail-debt.md +0 -14
- package/commands/report.md +0 -13
- package/scripts/harness-report.ps1 +0 -695
- package/scripts/panic/panic.ts +0 -240
- package/skills/code-review-and-quality/SKILL.md +0 -396
- package/skills/incremental-implementation/SKILL.md +0 -249
- package/skills/swarm-orchestration/SKILL.md +0 -54
|
@@ -0,0 +1,735 @@
|
|
|
1
|
+
// Pirep's behaviour, pinned. The two things that could quietly mislead here —
|
|
2
|
+
// a mis-parsed host payload, and a zero-cost subscription model leaking into
|
|
3
|
+
// a cost ranking — both fail loudly here instead.
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from "bun:test";
|
|
6
|
+
import { Database } from "bun:sqlite";
|
|
7
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import {
|
|
11
|
+
aggregate,
|
|
12
|
+
buildPayload,
|
|
13
|
+
cacheHitRate,
|
|
14
|
+
collectTurns,
|
|
15
|
+
fmtCount,
|
|
16
|
+
formatReport,
|
|
17
|
+
median,
|
|
18
|
+
parseArgs,
|
|
19
|
+
parseTurn,
|
|
20
|
+
turnTokPerSec,
|
|
21
|
+
type Turn,
|
|
22
|
+
} from "./pirep.ts";
|
|
23
|
+
|
|
24
|
+
const CLIENT = join(import.meta.dir, "pirep.ts");
|
|
25
|
+
|
|
26
|
+
interface Row {
|
|
27
|
+
id: string;
|
|
28
|
+
session_id: string;
|
|
29
|
+
type: string;
|
|
30
|
+
time_created: number;
|
|
31
|
+
time_updated: number;
|
|
32
|
+
data: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const row = (over: Partial<Row> & { id: string; type: string; data: unknown }): Row => ({
|
|
36
|
+
session_id: "ses_a",
|
|
37
|
+
time_created: 1_783_882_279_705,
|
|
38
|
+
time_updated: 1_783_882_279_705,
|
|
39
|
+
...over,
|
|
40
|
+
session_id: over.session_id ?? "ses_a",
|
|
41
|
+
data: JSON.stringify(over.data),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A v2 assistant payload, shaped exactly like the rows in the real database:
|
|
46
|
+
* model nested under `model`, `agent` at the top level, and a `time` carrying
|
|
47
|
+
* `streamed` alongside `completed`.
|
|
48
|
+
*/
|
|
49
|
+
const v2 = (
|
|
50
|
+
model: string,
|
|
51
|
+
provider: string,
|
|
52
|
+
cost: number,
|
|
53
|
+
input: number,
|
|
54
|
+
output: number,
|
|
55
|
+
extra: Record<string, unknown> = {},
|
|
56
|
+
): Record<string, unknown> => ({
|
|
57
|
+
time: { created: 1_783_882_279_705, streamed: 1_783_882_280_705, completed: 1_783_882_280_905 },
|
|
58
|
+
agent: "build",
|
|
59
|
+
model: { id: model, providerID: provider },
|
|
60
|
+
finish: "stop",
|
|
61
|
+
cost,
|
|
62
|
+
tokens: { input, output, reasoning: 10, cache: { read: 500, write: 50 } },
|
|
63
|
+
...extra,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
/** An older assistant payload: explicit role, flat modelID / providerID. */
|
|
67
|
+
const v1 = (
|
|
68
|
+
model: string,
|
|
69
|
+
provider: string,
|
|
70
|
+
cost: number,
|
|
71
|
+
input: number,
|
|
72
|
+
output: number,
|
|
73
|
+
): Record<string, unknown> => ({
|
|
74
|
+
role: "assistant",
|
|
75
|
+
modelID: model,
|
|
76
|
+
providerID: provider,
|
|
77
|
+
agent: "plan",
|
|
78
|
+
cost,
|
|
79
|
+
tokens: { input, output, reasoning: 0, cache: { read: 0, write: 0 } },
|
|
80
|
+
time: { created: 1_783_882_279_705, streamed: 1_783_882_281_705 },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A miniature of the real host database: the tables pirep reads, and only
|
|
85
|
+
* the columns it reads. If the host schema moves, these tests keep passing
|
|
86
|
+
* while the real run fails loudly — which is the correct asymmetry.
|
|
87
|
+
*/
|
|
88
|
+
function fixtureDb(rows: readonly Row[]): Database {
|
|
89
|
+
const db = new Database(":memory:");
|
|
90
|
+
db.exec("create table session_v2(id text, title text, directory text)");
|
|
91
|
+
db.exec(
|
|
92
|
+
"create table session_message(id text, session_id text, type text, seq integer, time_created integer, time_updated integer, data text)",
|
|
93
|
+
);
|
|
94
|
+
db.exec("insert into session_v2 values('ses_a', 'Flight deck', 'C:/Users/alice/foo')");
|
|
95
|
+
db.exec("insert into session_v2 values('ses_b', 'Planner', 'C:/Users/alice/bar')");
|
|
96
|
+
const insert = db.query(
|
|
97
|
+
"insert into session_message(id, session_id, type, seq, time_created, time_updated, data) values(?, ?, ?, 0, ?, ?, ?)",
|
|
98
|
+
);
|
|
99
|
+
for (const r of rows) {
|
|
100
|
+
insert.run(r.id, r.session_id, r.type, r.time_created, r.time_updated, r.data);
|
|
101
|
+
}
|
|
102
|
+
return db;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function tempDir(): string {
|
|
106
|
+
return mkdtempSync(join(tmpdir(), "pirep-test-"));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
describe("parseTurn", () => {
|
|
110
|
+
test("reads the v2 nested shape: model.id, tokens, cost, time, agent", () => {
|
|
111
|
+
const turn = parseTurn(row({ id: "m1", type: "assistant", data: v2("claude-sonnet-4", "anthropic", 0.0123, 5519, 20) }));
|
|
112
|
+
expect(turn?.model).toBe("anthropic/claude-sonnet-4");
|
|
113
|
+
expect(turn?.provider).toBe("anthropic");
|
|
114
|
+
expect(turn?.input).toBe(5519);
|
|
115
|
+
expect(turn?.output).toBe(20);
|
|
116
|
+
expect(turn?.reasoning).toBe(10);
|
|
117
|
+
expect(turn?.cacheRead).toBe(500);
|
|
118
|
+
expect(turn?.cacheWrite).toBe(50);
|
|
119
|
+
expect(turn?.cost).toBe(0.0123);
|
|
120
|
+
expect(turn?.agent).toBe("build");
|
|
121
|
+
expect(turn?.streamMs).toBe(1000);
|
|
122
|
+
expect(turn?.failed).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("reads the older flat shape", () => {
|
|
126
|
+
const turn = parseTurn(row({ id: "m2", type: "assistant", data: v1("gpt-5", "openai", 0.05, 100, 50) }));
|
|
127
|
+
expect(turn?.model).toBe("openai/gpt-5");
|
|
128
|
+
expect(turn?.agent).toBe("plan");
|
|
129
|
+
expect(turn?.streamMs).toBe(2000);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("the nested model object wins over the flat fields", () => {
|
|
133
|
+
// Verified against the database: every assistant row carries `model`, and
|
|
134
|
+
// the flat `modelID` / `providerID` fields appear on none of them.
|
|
135
|
+
const turn = parseTurn(
|
|
136
|
+
row({
|
|
137
|
+
id: "m3",
|
|
138
|
+
type: "assistant",
|
|
139
|
+
data: {
|
|
140
|
+
...v2("nested-model", "nested-provider", 0.01, 10, 5),
|
|
141
|
+
role: "assistant",
|
|
142
|
+
modelID: "top-level-model",
|
|
143
|
+
providerID: "top-level-provider",
|
|
144
|
+
},
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
expect(turn?.model).toBe("nested-provider/nested-model");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("reads agent and ignores mode, which this host never populates", () => {
|
|
151
|
+
const withMode = parseTurn(
|
|
152
|
+
row({ id: "m4", type: "assistant", data: v2("m", "p", 0, 10, 5, { mode: "general", agent: "build" }) }),
|
|
153
|
+
);
|
|
154
|
+
expect(withMode?.agent).toBe("build");
|
|
155
|
+
const bare = parseTurn(
|
|
156
|
+
row({
|
|
157
|
+
id: "m5",
|
|
158
|
+
type: "assistant",
|
|
159
|
+
data: { model: { id: "m", providerID: "p" }, cost: 0, tokens: { input: 1, output: 1 }, time: { created: 100 } },
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
expect(bare?.agent).toBe("unknown");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("marks a non-null error field as failed, including aborts", () => {
|
|
166
|
+
const failed = parseTurn(
|
|
167
|
+
row({ id: "m6", type: "assistant", data: v2("m", "p", 0, 10, 5, { error: { message: "boom" } }) }),
|
|
168
|
+
);
|
|
169
|
+
expect(failed?.failed).toBe(true);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("skips rows it cannot understand instead of guessing", () => {
|
|
173
|
+
expect(parseTurn(row({ id: "u1", type: "user", data: { text: "hello" } }))).toBeUndefined();
|
|
174
|
+
expect(
|
|
175
|
+
parseTurn(row({ id: "w1", type: "assistant", data: { role: "user", text: "not a turn" } })),
|
|
176
|
+
).toBeUndefined();
|
|
177
|
+
expect(
|
|
178
|
+
parseTurn({ id: "j1", session_id: "s", type: "assistant", time_created: 0, data: "{not json" }),
|
|
179
|
+
).toBeUndefined();
|
|
180
|
+
expect(
|
|
181
|
+
parseTurn(row({ id: "n1", type: "assistant", data: { cost: 1, tokens: { input: 5, output: 5 } } })),
|
|
182
|
+
).toBeUndefined();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("clamps negative tokens and cost to zero rather than propagating them", () => {
|
|
186
|
+
const turn = parseTurn(
|
|
187
|
+
row({
|
|
188
|
+
id: "n2",
|
|
189
|
+
type: "assistant",
|
|
190
|
+
data: {
|
|
191
|
+
model: { id: "m", providerID: "p" },
|
|
192
|
+
cost: -1,
|
|
193
|
+
tokens: { input: -100, output: -50, reasoning: -25, cache: { read: -200, write: -10 } },
|
|
194
|
+
time: { created: 1_783_882_279_705 },
|
|
195
|
+
},
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
expect(turn?.input).toBe(0);
|
|
199
|
+
expect(turn?.output).toBe(0);
|
|
200
|
+
expect(turn?.reasoning).toBe(0);
|
|
201
|
+
expect(turn?.cacheRead).toBe(0);
|
|
202
|
+
expect(turn?.cacheWrite).toBe(0);
|
|
203
|
+
expect(turn?.cost).toBe(0);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
test("leaves the streaming window absent when streamed is missing or not after created", () => {
|
|
207
|
+
const missing = parseTurn(
|
|
208
|
+
row({
|
|
209
|
+
id: "d1",
|
|
210
|
+
type: "assistant",
|
|
211
|
+
data: { model: { id: "m", providerID: "p" }, cost: 0, tokens: { input: 1, output: 5 }, time: { created: 100 } },
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
expect(missing?.streamMs).toBeUndefined();
|
|
215
|
+
const backwards = parseTurn(
|
|
216
|
+
row({
|
|
217
|
+
id: "d2",
|
|
218
|
+
type: "assistant",
|
|
219
|
+
data: {
|
|
220
|
+
model: { id: "m", providerID: "p" },
|
|
221
|
+
cost: 0,
|
|
222
|
+
tokens: { input: 1, output: 5 },
|
|
223
|
+
time: { created: 200, streamed: 100 },
|
|
224
|
+
},
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
expect(backwards?.streamMs).toBeUndefined();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
test("never measures speed from completed, which includes tool execution", () => {
|
|
231
|
+
// `completed` runs long past the last token. Using it would report a model
|
|
232
|
+
// as slower than it is, so a turn with only `completed` gets no speed.
|
|
233
|
+
const turn = parseTurn(
|
|
234
|
+
row({
|
|
235
|
+
id: "d3",
|
|
236
|
+
type: "assistant",
|
|
237
|
+
data: {
|
|
238
|
+
model: { id: "m", providerID: "p" },
|
|
239
|
+
cost: 0,
|
|
240
|
+
tokens: { input: 10, output: 500 },
|
|
241
|
+
time: { created: 1_000, completed: 61_000 },
|
|
242
|
+
},
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
expect(turn?.streamMs).toBeUndefined();
|
|
246
|
+
expect(turn).toBeDefined();
|
|
247
|
+
expect(turnTokPerSec(turn as Turn)).toBeUndefined();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("skips a mid-stream row that has time but no tokens yet", () => {
|
|
251
|
+
// The host writes these while a turn is still streaming. Counting one as a
|
|
252
|
+
// zero-token turn would drag down every average it touches.
|
|
253
|
+
const turn = parseTurn(
|
|
254
|
+
row({
|
|
255
|
+
id: "d4",
|
|
256
|
+
type: "assistant",
|
|
257
|
+
data: { model: { id: "m", providerID: "p" }, agent: "build", time: { created: 1_000, streamed: 2_000 } },
|
|
258
|
+
}),
|
|
259
|
+
);
|
|
260
|
+
expect(turn).toBeUndefined();
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test("falls back to the row timestamp when the payload carries no time", () => {
|
|
264
|
+
const turn = parseTurn(
|
|
265
|
+
row({
|
|
266
|
+
id: "t1",
|
|
267
|
+
type: "assistant",
|
|
268
|
+
time_created: 1_700_000_000_000,
|
|
269
|
+
data: { model: { id: "m", providerID: "p" }, cost: 0, tokens: { input: 1, output: 1 } },
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
expect(turn?.ts).toBe(1_700_000_000_000);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
test("strips C0 control characters from untrusted fields before rendering", () => {
|
|
276
|
+
// A crafted model.id could otherwise carry an OSC-52/clipboard escape into
|
|
277
|
+
// the terminal. Untrusted rows are text, never terminal instructions.
|
|
278
|
+
const turn = parseTurn(
|
|
279
|
+
row({ id: "c1", type: "assistant", data: v2("\u001b]52;c;x", "p", 0.01, 10, 5) }),
|
|
280
|
+
);
|
|
281
|
+
expect(turn).toBeDefined();
|
|
282
|
+
expect(turn?.model ?? "").not.toContain("\u001b");
|
|
283
|
+
expect(turn?.modelId ?? "").not.toContain("\u001b");
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe("maths", () => {
|
|
288
|
+
test("median handles odd, even and empty sets", () => {
|
|
289
|
+
expect(median([100])).toBe(100);
|
|
290
|
+
expect(median([300, 100, 200])).toBe(200);
|
|
291
|
+
expect(median([100, 300])).toBe(200);
|
|
292
|
+
expect(median([])).toBeUndefined();
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
test("cache hit rate is read over read plus input", () => {
|
|
296
|
+
expect(cacheHitRate(2000, 6000)).toBe(0.25);
|
|
297
|
+
expect(cacheHitRate(0, 0)).toBeUndefined();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("turn speed needs output and a real streaming window", () => {
|
|
301
|
+
const base: Turn = {
|
|
302
|
+
model: "p/m",
|
|
303
|
+
provider: "p",
|
|
304
|
+
modelId: "m",
|
|
305
|
+
agent: "build",
|
|
306
|
+
sessionId: "s",
|
|
307
|
+
ts: 1,
|
|
308
|
+
input: 10,
|
|
309
|
+
output: 200,
|
|
310
|
+
reasoning: 0,
|
|
311
|
+
cacheRead: 0,
|
|
312
|
+
cacheWrite: 0,
|
|
313
|
+
cost: 0,
|
|
314
|
+
streamMs: 1000,
|
|
315
|
+
failed: false,
|
|
316
|
+
};
|
|
317
|
+
expect(turnTokPerSec(base)).toBe(200);
|
|
318
|
+
expect(turnTokPerSec({ ...base, streamMs: undefined })).toBeUndefined();
|
|
319
|
+
expect(turnTokPerSec({ ...base, output: 0 })).toBeUndefined();
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
describe("fmtCount", () => {
|
|
324
|
+
test("abbreviates without ever rounding up into the wrong unit", () => {
|
|
325
|
+
expect(fmtCount(0)).toBe("0");
|
|
326
|
+
expect(fmtCount(999)).toBe("999");
|
|
327
|
+
expect(fmtCount(999_999)).toBe("1M");
|
|
328
|
+
expect(fmtCount(1_000_000)).toBe("1M");
|
|
329
|
+
expect(fmtCount(1_000_000_000)).toBe("1B");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("trims the .0 and .00 branches, and keeps real decimals", () => {
|
|
333
|
+
expect(fmtCount(2_000_000)).toBe("2M");
|
|
334
|
+
expect(fmtCount(2_000_000_000)).toBe("2B");
|
|
335
|
+
expect(fmtCount(1_500_000)).toBe("1.5M");
|
|
336
|
+
expect(fmtCount(1_250_000_000)).toBe("1.25B");
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
const METERED = "claude-sonnet-4";
|
|
341
|
+
const UNPRICED = "gpt-5.6-luna";
|
|
342
|
+
|
|
343
|
+
function mixedTurns(): Turn[] {
|
|
344
|
+
const source = fixtureDb([
|
|
345
|
+
row({ id: "a1", type: "assistant", data: v2(METERED, "anthropic", 0.01, 1000, 100) }),
|
|
346
|
+
row({
|
|
347
|
+
id: "a2",
|
|
348
|
+
type: "assistant",
|
|
349
|
+
data: v2(METERED, "anthropic", 0.02, 2000, 200, {
|
|
350
|
+
time: { created: 1_783_882_279_705, streamed: 1_783_882_281_705 },
|
|
351
|
+
tokens: { input: 2000, output: 200, reasoning: 10, cache: { read: 0, write: 0 } },
|
|
352
|
+
}),
|
|
353
|
+
}),
|
|
354
|
+
row({
|
|
355
|
+
id: "a3",
|
|
356
|
+
type: "assistant",
|
|
357
|
+
data: v2(METERED, "anthropic", 0.03, 3000, 300, { error: { message: "overloaded" } }),
|
|
358
|
+
}),
|
|
359
|
+
row({
|
|
360
|
+
id: "b1",
|
|
361
|
+
session_id: "ses_b",
|
|
362
|
+
type: "assistant",
|
|
363
|
+
data: { ...v2(UNPRICED, "openai", 0, 4000, 400, { agent: "plan" }), time: { created: 1_783_882_279_705 } },
|
|
364
|
+
}),
|
|
365
|
+
row({
|
|
366
|
+
id: "b2",
|
|
367
|
+
session_id: "ses_b",
|
|
368
|
+
type: "assistant",
|
|
369
|
+
data: { ...v2(UNPRICED, "openai", 0, 5000, 500, { agent: "plan" }), time: { created: 1_783_882_279_705 } },
|
|
370
|
+
}),
|
|
371
|
+
]);
|
|
372
|
+
const { turns } = collectTurns(source);
|
|
373
|
+
source.close();
|
|
374
|
+
return turns;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
describe("aggregation and the metering split", () => {
|
|
378
|
+
test("collects assistant turns and counts what it skips", () => {
|
|
379
|
+
const source = fixtureDb([
|
|
380
|
+
row({ id: "a1", type: "assistant", data: v2("m", "p", 0.01, 10, 5) }),
|
|
381
|
+
row({ id: "u1", type: "user", data: { text: "hello" } }),
|
|
382
|
+
{ id: "j1", session_id: "ses_a", type: "assistant", time_created: 0, time_updated: 0, data: "{broken" },
|
|
383
|
+
]);
|
|
384
|
+
const { turns, scanned, skipped } = collectTurns(source);
|
|
385
|
+
// The user row never reaches the parser: the SQL already filters to assistant.
|
|
386
|
+
expect(scanned).toBe(2);
|
|
387
|
+
expect(turns).toHaveLength(1);
|
|
388
|
+
expect(skipped).toBe(1);
|
|
389
|
+
source.close();
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
test("a zero-cost model with real tokens is unpriced, labelled, and out of the cost maths", () => {
|
|
393
|
+
const report = aggregate(mixedTurns());
|
|
394
|
+
expect(report.metered.map((s) => s.model)).toEqual(["anthropic/claude-sonnet-4"]);
|
|
395
|
+
expect(report.unpriced.map((s) => s.model)).toEqual(["openai/gpt-5.6-luna"]);
|
|
396
|
+
expect(report.unpriced[0]?.metered).toBe(false);
|
|
397
|
+
expect(report.unpriced[0]?.medianTurnCost).toBeUndefined();
|
|
398
|
+
expect(report.unpriced[0]?.totalCost).toBe(0);
|
|
399
|
+
// The metered side never sees the unpriced turns.
|
|
400
|
+
expect(report.totalMeteredCost).toBeCloseTo(0.06, 10);
|
|
401
|
+
expect(report.unpricedTurns).toBe(2);
|
|
402
|
+
expect(report.metered[0]?.medianTurnCost).toBeCloseTo(0.02, 10);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
test("per-model counts, cache hit rate, failure rate and streaming speed", () => {
|
|
406
|
+
const report = aggregate(mixedTurns());
|
|
407
|
+
const metered = report.metered[0];
|
|
408
|
+
expect(metered?.turns).toBe(3);
|
|
409
|
+
expect(metered?.sessions).toBe(1);
|
|
410
|
+
expect(metered?.input).toBe(6000);
|
|
411
|
+
expect(metered?.output).toBe(600);
|
|
412
|
+
// cache reads: 500 + 0 + 500 over inputs of 6000.
|
|
413
|
+
expect(metered?.cacheHitRate).toBeCloseTo(1000 / 7000, 10);
|
|
414
|
+
expect(metered?.failureRate).toBeCloseTo(1 / 3, 10);
|
|
415
|
+
// Streaming windows: 1s/100, 2s/200, 1s/300 -> 100, 100, 300 tok/s.
|
|
416
|
+
expect(metered?.medianTokPerSec).toBe(100);
|
|
417
|
+
// The unpriced turns record no streamed time, so they get no speed at all
|
|
418
|
+
// rather than one measured against the wrong clock.
|
|
419
|
+
expect(report.unpriced[0]?.medianTokPerSec).toBeUndefined();
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
test("agents aggregate turns but only ever carry a partial metered cost", () => {
|
|
423
|
+
const report = aggregate(mixedTurns());
|
|
424
|
+
const build = report.agents.find((a) => a.agent === "build");
|
|
425
|
+
const plan = report.agents.find((a) => a.agent === "plan");
|
|
426
|
+
expect(build?.turns).toBe(3);
|
|
427
|
+
expect(build?.meteredCostPartial).toBeCloseTo(0.06, 10);
|
|
428
|
+
expect(plan?.turns).toBe(2);
|
|
429
|
+
expect(plan?.meteredCostPartial).toBe(0);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test("the SQL --since boundary is inclusive: a row exactly at the cutoff is kept, one ms under is dropped", () => {
|
|
433
|
+
const sinceMs = Date.parse("2026-06-01T00:00:00Z");
|
|
434
|
+
const source = fixtureDb([
|
|
435
|
+
row({
|
|
436
|
+
id: "at",
|
|
437
|
+
type: "assistant",
|
|
438
|
+
time_created: sinceMs,
|
|
439
|
+
data: v2("m", "p", 0.01, 10, 5, { time: { created: sinceMs } }),
|
|
440
|
+
}),
|
|
441
|
+
row({
|
|
442
|
+
id: "under",
|
|
443
|
+
type: "assistant",
|
|
444
|
+
time_created: sinceMs - 1,
|
|
445
|
+
data: v2("m", "p", 0.01, 10, 5, { time: { created: sinceMs - 1 } }),
|
|
446
|
+
}),
|
|
447
|
+
]);
|
|
448
|
+
const { turns } = collectTurns(source, sinceMs);
|
|
449
|
+
// `time_created >= ?` keeps the equal row and rejects the earlier one.
|
|
450
|
+
expect(turns.map((t) => t.ts)).toEqual([sinceMs]);
|
|
451
|
+
source.close();
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test("pushes --since into SQL so pre-cutoff rows are never scanned", () => {
|
|
455
|
+
const source = fixtureDb([
|
|
456
|
+
row({ id: "new", type: "assistant", time_created: 1_783_882_279_705, data: v2("m", "p", 0.01, 10, 5) }),
|
|
457
|
+
row({ id: "old", type: "assistant", time_created: 1_700_000_000_000, data: v2("m", "p", 0.01, 10, 5) }),
|
|
458
|
+
]);
|
|
459
|
+
const { turns, scanned } = collectTurns(source, Date.parse("2026-06-01T00:00:00Z"));
|
|
460
|
+
// The old row is excluded by the WHERE clause, not read and dropped in JS.
|
|
461
|
+
expect(scanned).toBe(1);
|
|
462
|
+
expect(turns).toHaveLength(1);
|
|
463
|
+
source.close();
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
describe("parseArgs", () => {
|
|
468
|
+
test("empty flags mean the full report", () => {
|
|
469
|
+
const args = parseArgs([]);
|
|
470
|
+
expect(args).toMatchObject({ json: false, modelsOnly: false, agentsOnly: false, help: false });
|
|
471
|
+
expect(args.error).toBeUndefined();
|
|
472
|
+
expect(args.limit).toBeUndefined();
|
|
473
|
+
expect(args.sinceMs).toBeUndefined();
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
test("accepts every documented flag", () => {
|
|
477
|
+
const args = parseArgs(["--json", "--since=2026-06-01", "--limit=5", "--models", "--agents"]);
|
|
478
|
+
expect(args.json).toBe(true);
|
|
479
|
+
expect(args.sinceLabel).toBe("2026-06-01");
|
|
480
|
+
expect(args.sinceMs).toBe(Date.parse("2026-06-01T00:00:00Z"));
|
|
481
|
+
expect(args.limit).toBe(5);
|
|
482
|
+
expect(args.modelsOnly).toBe(true);
|
|
483
|
+
expect(args.agentsOnly).toBe(true);
|
|
484
|
+
expect(args.error).toBeUndefined();
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
test("rejects bad dates, bad limits, unknown flags and positionals", () => {
|
|
488
|
+
expect(parseArgs(["--since=06-01-2026"]).error).toMatch(/since/);
|
|
489
|
+
expect(parseArgs(["--since=2026-13-40"]).error).toMatch(/since/);
|
|
490
|
+
expect(parseArgs(["--limit=0"]).error).toMatch(/limit/);
|
|
491
|
+
expect(parseArgs(["--limit=many"]).error).toMatch(/limit/);
|
|
492
|
+
expect(parseArgs(["--frobnicate"]).error).toMatch(/unknown flag/);
|
|
493
|
+
expect(parseArgs(["claude"]).error).toMatch(/flags only/);
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
describe("payload and text shape", () => {
|
|
498
|
+
test("the JSON shape carries the split, partial totals and the reason why", () => {
|
|
499
|
+
const report = { ...aggregate(mixedTurns()), scanned: 5, skipped: 0 };
|
|
500
|
+
const payload = buildPayload(report, "/fake/opencode.db", undefined, undefined);
|
|
501
|
+
expect(payload.turns).toBe(5);
|
|
502
|
+
expect(payload.sessions).toBe(2);
|
|
503
|
+
expect(payload.metered).toHaveLength(1);
|
|
504
|
+
expect(payload.unpriced).toHaveLength(1);
|
|
505
|
+
expect(payload.unpriced[0]?.medianTurnCost).toBeUndefined();
|
|
506
|
+
expect(payload.totalMeteredCostPartial).toBeCloseTo(0.06, 10);
|
|
507
|
+
expect(payload.unpricedTurns).toBe(2);
|
|
508
|
+
expect(payload.agents.length).toBeGreaterThan(0);
|
|
509
|
+
expect(payload.notes.join(" ")).toMatch(/never summed or averaged together/);
|
|
510
|
+
expect(payload.notes.join(" ")).toMatch(/partial/);
|
|
511
|
+
// Serialises cleanly: no undefined fields, no functions.
|
|
512
|
+
expect(() => JSON.stringify(payload)).not.toThrow();
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
test("a limit caps every section", () => {
|
|
516
|
+
const report = { ...aggregate(mixedTurns()), scanned: 5, skipped: 0 };
|
|
517
|
+
const payload = buildPayload(report, "/fake/opencode.db", undefined, 1);
|
|
518
|
+
expect(payload.limit).toBe(1);
|
|
519
|
+
expect(payload.metered).toHaveLength(1);
|
|
520
|
+
expect(payload.unpriced).toHaveLength(1);
|
|
521
|
+
expect(payload.agents).toHaveLength(1);
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
test("the text report labels the unpriced section and marks every cost partial", () => {
|
|
525
|
+
const report = { ...aggregate(mixedTurns()), scanned: 5, skipped: 0 };
|
|
526
|
+
const out = formatReport(
|
|
527
|
+
report,
|
|
528
|
+
"/fake/opencode.db",
|
|
529
|
+
{ modelsOnly: false, agentsOnly: false, limit: 10, sinceLabel: undefined },
|
|
530
|
+
);
|
|
531
|
+
expect(out).toContain("Metered models");
|
|
532
|
+
expect(out).toContain("Unpriced models");
|
|
533
|
+
expect(out).toContain("no metered cost recorded");
|
|
534
|
+
const unpricedAt = out.indexOf("Unpriced models");
|
|
535
|
+
expect(out.indexOf("openai/gpt-5.6-luna")).toBeGreaterThan(unpricedAt);
|
|
536
|
+
expect(out).toContain("partial");
|
|
537
|
+
expect(out).toContain("streaming window");
|
|
538
|
+
expect(out).toContain("Agents");
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
test("--models and --agents narrow the text report", () => {
|
|
542
|
+
const report = { ...aggregate(mixedTurns()), scanned: 5, skipped: 0 };
|
|
543
|
+
const models = formatReport(
|
|
544
|
+
report,
|
|
545
|
+
"/fake/opencode.db",
|
|
546
|
+
{ modelsOnly: true, agentsOnly: false, limit: 10, sinceLabel: undefined },
|
|
547
|
+
);
|
|
548
|
+
expect(models).toContain("Metered models");
|
|
549
|
+
expect(models).not.toContain("Agents (");
|
|
550
|
+
const agents = formatReport(
|
|
551
|
+
report,
|
|
552
|
+
"/fake/opencode.db",
|
|
553
|
+
{ modelsOnly: false, agentsOnly: true, limit: 10, sinceLabel: undefined },
|
|
554
|
+
);
|
|
555
|
+
expect(agents).toContain("Agents (");
|
|
556
|
+
expect(agents).not.toContain("Metered models");
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
describe("cli", () => {
|
|
561
|
+
function fixtureFile(): { dir: string; sourcePath: string } {
|
|
562
|
+
const dir = tempDir();
|
|
563
|
+
const sourcePath = join(dir, "source.db");
|
|
564
|
+
const source = new Database(sourcePath);
|
|
565
|
+
source.exec("create table session_v2(id text, title text, directory text)");
|
|
566
|
+
source.exec(
|
|
567
|
+
"create table session_message(id text, session_id text, type text, seq integer, time_created integer, time_updated integer, data text)",
|
|
568
|
+
);
|
|
569
|
+
source.exec("insert into session_v2 values('ses_a', 'Flight deck', 'C:/Users/alice/foo')");
|
|
570
|
+
source.exec("insert into session_v2 values('ses_b', 'Planner', 'C:/Users/alice/bar')");
|
|
571
|
+
const insert = source.query(
|
|
572
|
+
"insert into session_message(id, session_id, type, seq, time_created, time_updated, data) values(?, ?, ?, 0, ?, ?, ?)",
|
|
573
|
+
);
|
|
574
|
+
const put = (id: string, session: string, type: string, ts: number, data: unknown): void => {
|
|
575
|
+
insert.run(id, session, type, ts, ts, JSON.stringify(data));
|
|
576
|
+
};
|
|
577
|
+
put("a1", "ses_a", "assistant", 1_783_882_279_705, v2(METERED, "anthropic", 0.01, 1000, 100));
|
|
578
|
+
put("a2", "ses_a", "assistant", 1_783_882_279_705, v2(METERED, "anthropic", 0.02, 2000, 200));
|
|
579
|
+
put(
|
|
580
|
+
"b1",
|
|
581
|
+
"ses_b",
|
|
582
|
+
"assistant",
|
|
583
|
+
1_783_882_279_705,
|
|
584
|
+
{ ...v2(UNPRICED, "openai", 0, 4000, 400, { agent: "plan" }), time: { created: 1_783_882_279_705 } },
|
|
585
|
+
);
|
|
586
|
+
// Predates any plausible --since filter.
|
|
587
|
+
put("old", "ses_a", "assistant", 1_700_000_000_000, {
|
|
588
|
+
...v2(METERED, "anthropic", 0.05, 500, 50),
|
|
589
|
+
time: { created: 1_700_000_000_000, completed: 1_700_000_001_000 },
|
|
590
|
+
});
|
|
591
|
+
source.close();
|
|
592
|
+
return { dir, sourcePath };
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function run(args: readonly string[], sourcePath: string) {
|
|
596
|
+
return Bun.spawnSync({
|
|
597
|
+
cmd: ["bun", CLIENT, ...args],
|
|
598
|
+
env: { ...process.env, PIREP_SOURCE: sourcePath },
|
|
599
|
+
stdout: "pipe",
|
|
600
|
+
stderr: "pipe",
|
|
601
|
+
});
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** A source database with the one table pirep reads and no rows in it yet. */
|
|
605
|
+
function bareDb(sourcePath: string): Database {
|
|
606
|
+
const source = new Database(sourcePath);
|
|
607
|
+
source.exec("create table session_v2(id text, title text, directory text)");
|
|
608
|
+
source.exec(
|
|
609
|
+
"create table session_message(id text, session_id text, type text, seq integer, time_created integer, time_updated integer, data text)",
|
|
610
|
+
);
|
|
611
|
+
return source;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
test("no flags prints the full report with the metering split enforced", () => {
|
|
615
|
+
const { dir, sourcePath } = fixtureFile();
|
|
616
|
+
const ok = run([], sourcePath);
|
|
617
|
+
expect(ok.exitCode).toBe(0);
|
|
618
|
+
const out = ok.stdout.toString();
|
|
619
|
+
expect(out).toContain("pirep");
|
|
620
|
+
expect(out).toContain("Metered models");
|
|
621
|
+
expect(out).toContain("Unpriced models");
|
|
622
|
+
expect(out).toContain("no metered cost recorded");
|
|
623
|
+
expect(out).toContain("anthropic/claude-sonnet-4");
|
|
624
|
+
expect(out).toContain("openai/gpt-5.6-luna");
|
|
625
|
+
expect(out).toContain("partial");
|
|
626
|
+
expect(out).toContain("Agents");
|
|
627
|
+
rmSync(dir, { recursive: true, force: true });
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
test("--json reports the same split in machine-readable shape", () => {
|
|
631
|
+
const { dir, sourcePath } = fixtureFile();
|
|
632
|
+
const ok = run(["--json"], sourcePath);
|
|
633
|
+
expect(ok.exitCode).toBe(0);
|
|
634
|
+
const payload = JSON.parse(ok.stdout.toString());
|
|
635
|
+
expect(payload.turns).toBe(4);
|
|
636
|
+
expect(payload.metered).toHaveLength(1);
|
|
637
|
+
expect(payload.unpriced).toHaveLength(1);
|
|
638
|
+
expect(payload.unpriced[0].model).toBe("openai/gpt-5.6-luna");
|
|
639
|
+
expect(payload.unpriced[0].medianTurnCost).toBeUndefined();
|
|
640
|
+
expect(payload.totalMeteredCostPartial).toBeCloseTo(0.08, 10);
|
|
641
|
+
expect(payload.notes.join(" ")).toMatch(/never summed or averaged together/);
|
|
642
|
+
rmSync(dir, { recursive: true, force: true });
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
test("--since drops the old turn end to end", () => {
|
|
646
|
+
const { dir, sourcePath } = fixtureFile();
|
|
647
|
+
const ok = run(["--json", "--since=2026-06-01"], sourcePath);
|
|
648
|
+
expect(ok.exitCode).toBe(0);
|
|
649
|
+
const payload = JSON.parse(ok.stdout.toString());
|
|
650
|
+
expect(payload.since).toBe("2026-06-01");
|
|
651
|
+
expect(payload.turns).toBe(3);
|
|
652
|
+
expect(payload.totalMeteredCostPartial).toBeCloseTo(0.03, 10);
|
|
653
|
+
rmSync(dir, { recursive: true, force: true });
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
test("--limit caps each section end to end", () => {
|
|
657
|
+
const { dir, sourcePath } = fixtureFile();
|
|
658
|
+
const ok = run(["--json", "--limit=1"], sourcePath);
|
|
659
|
+
expect(ok.exitCode).toBe(0);
|
|
660
|
+
const payload = JSON.parse(ok.stdout.toString());
|
|
661
|
+
expect(payload.metered).toHaveLength(1);
|
|
662
|
+
rmSync(dir, { recursive: true, force: true });
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
test("a bad flag explains itself instead of throwing", () => {
|
|
666
|
+
const { dir, sourcePath } = fixtureFile();
|
|
667
|
+
const bad = run(["--bogus"], sourcePath);
|
|
668
|
+
expect(bad.exitCode).toBe(1);
|
|
669
|
+
expect(bad.stderr.toString()).toContain("unknown flag");
|
|
670
|
+
rmSync(dir, { recursive: true, force: true });
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
test("explains itself instead of throwing when there is no history to read", () => {
|
|
674
|
+
const dir = tempDir();
|
|
675
|
+
const missing = run([], join(dir, "does-not-exist.db"));
|
|
676
|
+
expect(missing.exitCode).toBe(1);
|
|
677
|
+
expect(missing.stderr.toString()).toContain("no history found");
|
|
678
|
+
rmSync(dir, { recursive: true, force: true });
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
test("--help does not touch a database at all", () => {
|
|
682
|
+
const dir = tempDir();
|
|
683
|
+
const help = run(["--help"], join(dir, "nope.db"));
|
|
684
|
+
expect(help.exitCode).toBe(0);
|
|
685
|
+
expect(help.stdout.toString()).toContain("pirep");
|
|
686
|
+
rmSync(dir, { recursive: true, force: true });
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
test("an existing database with only user rows is an empty scope, not an error", () => {
|
|
690
|
+
const dir = tempDir();
|
|
691
|
+
const sourcePath = join(dir, "source.db");
|
|
692
|
+
const source = bareDb(sourcePath);
|
|
693
|
+
source.exec("insert into session_message values('u1', 'ses_a', 'user', 0, 1, 1, '{\"text\":\"hi\"}')");
|
|
694
|
+
source.close();
|
|
695
|
+
const ok = run([], sourcePath);
|
|
696
|
+
expect(ok.exitCode).toBe(0);
|
|
697
|
+
expect(ok.stdout.toString()).toContain("no assistant turns found");
|
|
698
|
+
rmSync(dir, { recursive: true, force: true });
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
test("--json keeps its contract on an empty scope", () => {
|
|
702
|
+
const { dir, sourcePath } = fixtureFile();
|
|
703
|
+
const ok = run(["--json", "--since=2999-01-01"], sourcePath);
|
|
704
|
+
expect(ok.exitCode).toBe(0);
|
|
705
|
+
// stdout must be valid JSON even when there is nothing to report.
|
|
706
|
+
const payload = JSON.parse(ok.stdout.toString());
|
|
707
|
+
expect(payload.turns).toBe(0);
|
|
708
|
+
expect(payload.metered).toEqual([]);
|
|
709
|
+
expect(payload.unpriced).toEqual([]);
|
|
710
|
+
expect(payload.agents).toEqual([]);
|
|
711
|
+
rmSync(dir, { recursive: true, force: true });
|
|
712
|
+
});
|
|
713
|
+
|
|
714
|
+
test("a crafted model id cannot emit terminal escapes", () => {
|
|
715
|
+
const dir = tempDir();
|
|
716
|
+
const sourcePath = join(dir, "source.db");
|
|
717
|
+
const source = bareDb(sourcePath);
|
|
718
|
+
const insert = source.query(
|
|
719
|
+
"insert into session_message(id, session_id, type, seq, time_created, time_updated, data) values(?, ?, ?, 0, ?, ?, ?)",
|
|
720
|
+
);
|
|
721
|
+
insert.run(
|
|
722
|
+
"e1",
|
|
723
|
+
"ses_a",
|
|
724
|
+
"assistant",
|
|
725
|
+
1_783_882_279_705,
|
|
726
|
+
1_783_882_279_705,
|
|
727
|
+
JSON.stringify(v2("\u001b]52;c;x", "evil", 0.01, 10, 5)),
|
|
728
|
+
);
|
|
729
|
+
source.close();
|
|
730
|
+
const ok = run([], sourcePath);
|
|
731
|
+
expect(ok.exitCode).toBe(0);
|
|
732
|
+
expect(ok.stdout.toString()).not.toContain("\u001b");
|
|
733
|
+
rmSync(dir, { recursive: true, force: true });
|
|
734
|
+
});
|
|
735
|
+
});
|