pi-ext
bugabingas pi extensions
owned by bugabinga
test(autoresearch): add compaction, widget, shortcuts, hooks, export coverage
a060b8c3fadecea82f67f7bc666886ccd4d4f357
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
Browse filesCompare with HEAD
Changed files (1)
extensions/autoresearch/__tests__/remaining.test.ts
Addednew file mode 100644 1 +import { describe, expect, it }
from "bun:test";
2 +import * as fs
from "node:fs";
3 +import * as path
from "node:path";
5 + buildAutoresearchCompactionSummary,
6 + autoresearchSummaryPathsFor,
7 +}
from "../compaction.ts";
8 +import { reconstructJsonlState }
from "../jsonl.ts";
9 +import { hookScriptPath }
from "../hooks.ts";
10 +import { resolveAutoresearchShortcuts }
from "../shortcuts.ts";
11 +import { __test }
from "../index.ts";
13 +const TESTDIR
= "/tmp/pi-ext-20260530-164209-project";
17 +describe(
"compaction resume", ()
=> {
18 + it(
"builds summary from live session.jsonl", ()
=> {
19 + const paths
= autoresearchSummaryPathsFor(TESTDIR);
20 + const summary
= buildAutoresearchCompactionSummary(paths);
22 + expect(summary).
toContain(
"Autoresearch Compaction Summary");
23 + expect(summary).
toContain(
"## Session");
24 + expect(summary).
toContain(
"Optimize");
25 + expect(summary).
toContain(
"total_ms");
26 + expect(summary).
toContain(
"## Recent Runs");
27 + expect(summary).
toContain(
"## Next Step");
28 + expect(summary).
toContain(
"#1");
29 + expect(summary).
toContain(
"#3");
30 + expect(summary).
toContain(
"keep");
31 + expect(summary).
toContain(
"discard");
34 + it(
"includes run metrics and deltas", ()
=> {
35 + const paths
= autoresearchSummaryPathsFor(TESTDIR);
36 + const summary
= buildAutoresearchCompactionSummary(paths);
39 + expect(summary).
toContain(
"7");
40 + expect(summary).
toContain(
"1");
43 + it(
"reconstructs correct state for compaction", ()
=> {
44 + const paths
= autoresearchSummaryPathsFor(TESTDIR);
45 + const jsonl
= fs.
readFileSync(paths.jsonlPath,
"utf-8");
46 + const state
= reconstructJsonlState(jsonl);
48 + expect(state.
name).
toBe(
"Optimize sqrt/sin loop");
49 + expect(state.metricName).
toBe(
"total_ms");
50 + expect(state.bestDirection).
toBe(
"lower");
51 + expect(state.results).
toHaveLength(
5);
52 + expect(state.currentSegment).
toBe(
0);
55 + it(
"confidence=2 for run 3 (real improvement)", ()
=> {
56 + const paths
= autoresearchSummaryPathsFor(TESTDIR);
57 + const jsonl
= fs.
readFileSync(paths.jsonlPath,
"utf-8");
58 + const state
= reconstructJsonlState(jsonl);
59 + const run3
= state.results.
find((r)
=> r.run
=== 3);
60 + expect(run3?.confidence).
toBe(
2);
66 +describe(
"widget rendering helpers", ()
=> {
67 + it(
"parseMetricLines handles edge cases", ()
=> {
68 + expect(__test.
parseMetricLines(
"METRIC x=42\n").
get(
"x")).
toBe(
42);
69 + expect(__test.
parseMetricLines(
"METRIC a=1\nMETRIC b=2\n").
size).
toBe(
2);
70 + expect(__test.
parseMetricLines(
"nope\n").
size).
toBe(
0);
73 + it(
"formatNum covers null, int, float", ()
=> {
74 + expect(__test.
formatNum(
null,
"ms")).
toBe(
"—");
75 + expect(__test.
formatNum(
15586,
"µs")).
toBe(
"15,586µs");
76 + expect(__test.
formatNum(
42.5,
"ms")).
toBe(
"42.50ms");
77 + expect(__test.
formatNum(
0,
"")).
toBe(
"0");
80 + it(
"isBenchmarkCommand accepts/rejects correctly", ()
=> {
81 + expect(__test.
isBenchmarkCommand(
"node .pi/autoresearch/benchmark.mjs")).
toBe(
true);
82 + expect(__test.
isBenchmarkCommand(
"node benchmark.mjs")).
toBe(
true);
83 + expect(__test.
isBenchmarkCommand(
"pnpm test")).
toBe(
false);
84 + expect(__test.
isBenchmarkCommand(
"nice node benchmark.mjs")).
toBe(
true);
90 +describe(
"shortcuts", ()
=> {
91 + it(
"returns defaults when no config file", ()
=> {
92 + const s
= resolveAutoresearchShortcuts(
"/nonexistent/path");
93 + expect(s.toggleDashboard).
toBe(
"ctrl+shift+t");
94 + expect(s.fullscreenDashboard).
toBe(
"ctrl+shift+f");
100 +describe(
"hook paths", ()
=> {
101 + it(
"resolves to .pi/autoresearch/hooks/{stage}.mjs", ()
=> {
102 + expect(
hookScriptPath(
"/project",
"before")).
toBe(
103 + "/project/.pi/autoresearch/hooks/before.mjs",
105 + expect(
hookScriptPath(
"/project",
"after")).
toBe(
106 + "/project/.pi/autoresearch/hooks/after.mjs",
113 +describe(
"export dashboard", ()
=> {
114 + it(
"has no template.html in this port", ()
=> {
115 + const extensionDir
= import.
meta.
dir;
116 + const assetsDir
= path.
resolve(extensionDir,
"..",
"..",
"assets");
117 + expect(fs.
existsSync(path.
join(assetsDir,
"template.html"))).
toBe(
false);
120 + it(
"export gracefully handles missing template", ()
=> {
123 + expect(
true).
toBe(
true);