@unerr-ai/unerr 0.1.6 → 0.1.7
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 +70 -194
- package/dist/cli.js +39149 -36991
- package/package.json +9 -2
- package/dist/__tests__/architecture-guard.test.js +0 -122
- package/dist/__tests__/arg-validator.test.js +0 -205
- package/dist/__tests__/ast-extractor.test.js +0 -203
- package/dist/__tests__/auto-bootstrap.test.js +0 -280
- package/dist/__tests__/background-indexer.test.js +0 -228
- package/dist/__tests__/blast-radius-engine.test.js +0 -200
- package/dist/__tests__/bridge-isolation.test.js +0 -37
- package/dist/__tests__/budget-enforcer.test.js +0 -53
- package/dist/__tests__/cfg-test-detection-perf.test.js +0 -82
- package/dist/__tests__/change-narrative.test.js +0 -190
- package/dist/__tests__/check-commit.test.js +0 -258
- package/dist/__tests__/checksum.test.js +0 -34
- package/dist/__tests__/commit-watcher.test.js +0 -154
- package/dist/__tests__/community-detection.test.js +0 -179
- package/dist/__tests__/community-tools.test.js +0 -299
- package/dist/__tests__/components.test.js +0 -449
- package/dist/__tests__/compression-log.test.js +0 -174
- package/dist/__tests__/compression-quality-monitor.test.js +0 -40
- package/dist/__tests__/config-healer.test.js +0 -165
- package/dist/__tests__/context-ledger.test.js +0 -58
- package/dist/__tests__/convention-detector.test.js +0 -99
- package/dist/__tests__/convention-learner.test.js +0 -86
- package/dist/__tests__/correction-detector.test.js +0 -330
- package/dist/__tests__/daemon-autostart-install.test.js +0 -283
- package/dist/__tests__/daemon-bridge.test.js +0 -222
- package/dist/__tests__/daemon-dashboard.test.js +0 -202
- package/dist/__tests__/daemon-registry.test.js +0 -240
- package/dist/__tests__/daemon-supervisor.test.js +0 -318
- package/dist/__tests__/daemon-version-check.test.js +0 -275
- package/dist/__tests__/decision-point-detector.test.js +0 -98
- package/dist/__tests__/deep-link.test.js +0 -143
- package/dist/__tests__/disallowed-tools.test.js +0 -115
- package/dist/__tests__/drift-tracker.test.js +0 -582
- package/dist/__tests__/durability-scorer.test.js +0 -152
- package/dist/__tests__/efficiency-tracker.test.js +0 -65
- package/dist/__tests__/enrich.test.js +0 -144
- package/dist/__tests__/entity-rewind.test.js +0 -248
- package/dist/__tests__/ephemeral.test.js +0 -111
- package/dist/__tests__/exploration-cost.test.js +0 -93
- package/dist/__tests__/fact-generator.test.js +0 -197
- package/dist/__tests__/file-l0-graph.test.js +0 -244
- package/dist/__tests__/file-logger.test.js +0 -82
- package/dist/__tests__/file-outline.test.js +0 -141
- package/dist/__tests__/file-read-protocol.test.js +0 -188
- package/dist/__tests__/format-encoder.test.js +0 -233
- package/dist/__tests__/git-attribution.test.js +0 -259
- package/dist/__tests__/graph-temporal-joiner.test.js +0 -219
- package/dist/__tests__/health-grade-enhanced.test.js +0 -138
- package/dist/__tests__/health-map-data.test.js +0 -173
- package/dist/__tests__/helpers/mcp-harness.js +0 -45
- package/dist/__tests__/helpers/mcp-harness.test.js +0 -68
- package/dist/__tests__/hook-dedup.test.js +0 -112
- package/dist/__tests__/hook-runner.test.js +0 -253
- package/dist/__tests__/indexer-cfg.test.js +0 -185
- package/dist/__tests__/indexer-cross-file.test.js +0 -172
- package/dist/__tests__/indexer-extraction.test.js +0 -245
- package/dist/__tests__/indexer-incremental.test.js +0 -232
- package/dist/__tests__/indexer-language-expansion.test.js +0 -165
- package/dist/__tests__/init-push.test.js +0 -131
- package/dist/__tests__/instruction-writer.test.js +0 -179
- package/dist/__tests__/intelligence-integration.test.js +0 -217
- package/dist/__tests__/intent-correlator.test.js +0 -175
- package/dist/__tests__/intent-detector.test.js +0 -235
- package/dist/__tests__/intent-encoder.test.js +0 -167
- package/dist/__tests__/java-build-tool-detection.test.js +0 -174
- package/dist/__tests__/layer3-sprint-q.test.js +0 -160
- package/dist/__tests__/layer3-sprint-r.test.js +0 -91
- package/dist/__tests__/layer3-sprint-s.test.js +0 -183
- package/dist/__tests__/layer3-sprint-t.test.js +0 -201
- package/dist/__tests__/layer3-sprint-u.test.js +0 -174
- package/dist/__tests__/layer4-sprint-ba2.test.js +0 -354
- package/dist/__tests__/layer4-sprint-ba4.test.js +0 -84
- package/dist/__tests__/layer4-sprint-vs.test.js +0 -105
- package/dist/__tests__/ledger-chains.test.js +0 -162
- package/dist/__tests__/lifecycle-machine.test.js +0 -226
- package/dist/__tests__/local-chat-provider.test.js +0 -170
- package/dist/__tests__/local-convention-detector.test.js +0 -308
- package/dist/__tests__/local-embeddings.test.js +0 -422
- package/dist/__tests__/local-graph.test.js +0 -540
- package/dist/__tests__/local-indexer.test.js +0 -228
- package/dist/__tests__/local-intelligence-l3.test.js +0 -332
- package/dist/__tests__/local-llm.test.js +0 -253
- package/dist/__tests__/local-mode-offline.test.js +0 -187
- package/dist/__tests__/local-mode-stats.test.js +0 -273
- package/dist/__tests__/local-mode-tui.test.js +0 -343
- package/dist/__tests__/local-parse.test.js +0 -199
- package/dist/__tests__/log-tailer.test.js +0 -208
- package/dist/__tests__/loop-breaker.test.js +0 -276
- package/dist/__tests__/loop-miner.test.js +0 -226
- package/dist/__tests__/mcp-config.test.js +0 -126
- package/dist/__tests__/mcp-content-json.test.js +0 -10
- package/dist/__tests__/mcp-envelope.test.js +0 -124
- package/dist/__tests__/metrics-store.test.js +0 -223
- package/dist/__tests__/native-watcher.test.js +0 -191
- package/dist/__tests__/navigation-hooks-agent-aware.test.js +0 -145
- package/dist/__tests__/negative-knowledge.test.js +0 -116
- package/dist/__tests__/network-boundary.test.js +0 -190
- package/dist/__tests__/network-firewall.test.js +0 -112
- package/dist/__tests__/nudge-invariants.test.js +0 -160
- package/dist/__tests__/nudge-v2.test.js +0 -225
- package/dist/__tests__/offline-rewind.test.js +0 -251
- package/dist/__tests__/open-threads.test.js +0 -89
- package/dist/__tests__/output-compressor.test.js +0 -93
- package/dist/__tests__/pending-violations.test.js +0 -112
- package/dist/__tests__/persistence-effectiveness.test.js +0 -143
- package/dist/__tests__/provider-factory.test.js +0 -42
- package/dist/__tests__/providers.test.js +0 -24
- package/dist/__tests__/proxy.test.js +0 -314
- package/dist/__tests__/query-router.test.js +0 -1018
- package/dist/__tests__/reasoning-quality-route.test.js +0 -138
- package/dist/__tests__/redactor.test.js +0 -120
- package/dist/__tests__/resource-monitor.test.js +0 -57
- package/dist/__tests__/response-envelope.test.js +0 -100
- package/dist/__tests__/risk-classifier.test.js +0 -101
- package/dist/__tests__/risk-signal-scope.test.js +0 -75
- package/dist/__tests__/rule-evaluator.test.js +0 -280
- package/dist/__tests__/scip-decoder.test.js +0 -49
- package/dist/__tests__/scip-downloader.test.js +0 -201
- package/dist/__tests__/scip-merger.test.js +0 -103
- package/dist/__tests__/search-index.test.js +0 -422
- package/dist/__tests__/semantic-enrichment.test.js +0 -360
- package/dist/__tests__/session-brief-builder.test.js +0 -187
- package/dist/__tests__/session-context.test.js +0 -221
- package/dist/__tests__/session-continuity.test.js +0 -144
- package/dist/__tests__/session-dedup.test.js +0 -74
- package/dist/__tests__/session-event-wiring.test.js +0 -206
- package/dist/__tests__/session-events.test.js +0 -149
- package/dist/__tests__/session-legend.test.js +0 -20
- package/dist/__tests__/session-persistence.test.js +0 -131
- package/dist/__tests__/session-resume-block.test.js +0 -107
- package/dist/__tests__/session-resume.test.js +0 -97
- package/dist/__tests__/session-summary-writer.test.js +0 -134
- package/dist/__tests__/shadow-ledger.test.js +0 -203
- package/dist/__tests__/shell-classifier.test.js +0 -151
- package/dist/__tests__/shell-compression-floor.test.js +0 -189
- package/dist/__tests__/shell-compression-v2.test.js +0 -339
- package/dist/__tests__/shell-compressor.test.js +0 -35
- package/dist/__tests__/shell-hooks.test.js +0 -128
- package/dist/__tests__/shell-strategies.test.js +0 -644
- package/dist/__tests__/shell-tee.test.js +0 -133
- package/dist/__tests__/signal-dedup.test.js +0 -158
- package/dist/__tests__/signal-reinforcer.test.js +0 -77
- package/dist/__tests__/signal-scorer.test.js +0 -251
- package/dist/__tests__/signal-show-store.test.js +0 -108
- package/dist/__tests__/smart-truncate.test.js +0 -215
- package/dist/__tests__/snapshot-v2.test.js +0 -113
- package/dist/__tests__/sprint-l1-local-mode.test.js +0 -130
- package/dist/__tests__/sprint-l10-boot.test.js +0 -220
- package/dist/__tests__/sprint-l9-offline-commands.test.js +0 -189
- package/dist/__tests__/sprint-q-persistent-context.test.js +0 -198
- package/dist/__tests__/sprint-s1-wiring.test.js +0 -215
- package/dist/__tests__/sprint-s2-wiring.test.js +0 -256
- package/dist/__tests__/sprint-s3-wiring.test.js +0 -195
- package/dist/__tests__/sprint-s4-wiring.test.js +0 -213
- package/dist/__tests__/sprint-s6-hooks.test.js +0 -222
- package/dist/__tests__/sprint-s7-persistent.test.js +0 -263
- package/dist/__tests__/sprint-s8-value.test.js +0 -167
- package/dist/__tests__/sprint-s9-behavioral.test.js +0 -179
- package/dist/__tests__/sprint3-intelligence.test.js +0 -297
- package/dist/__tests__/sprint5-mcp-server.test.js +0 -136
- package/dist/__tests__/startup-display.test.js +0 -302
- package/dist/__tests__/startup-log-file.test.js +0 -97
- package/dist/__tests__/stash-manager.test.js +0 -229
- package/dist/__tests__/state-detector.test.js +0 -92
- package/dist/__tests__/status-dashboard.test.js +0 -142
- package/dist/__tests__/temporal-facts.test.js +0 -292
- package/dist/__tests__/temporal-routes.test.js +0 -142
- package/dist/__tests__/test-detector.test.js +0 -174
- package/dist/__tests__/theme.test.js +0 -72
- package/dist/__tests__/timeline-agents.test.js +0 -122
- package/dist/__tests__/timeline-bootstrap.test.js +0 -176
- package/dist/__tests__/timeline-filters.test.js +0 -193
- package/dist/__tests__/timeline-markers.test.js +0 -151
- package/dist/__tests__/timeline-routes.test.js +0 -156
- package/dist/__tests__/timeline-store.test.js +0 -171
- package/dist/__tests__/token-counter.test.js +0 -86
- package/dist/__tests__/token-estimator.test.js +0 -96
- package/dist/__tests__/token-flow-api.test.js +0 -239
- package/dist/__tests__/token-flow-instrumentation.test.js +0 -437
- package/dist/__tests__/token-flow-persistence.test.js +0 -356
- package/dist/__tests__/token-flow-routes.test.js +0 -199
- package/dist/__tests__/token-flow.test.js +0 -695
- package/dist/__tests__/tool-clusters.test.js +0 -177
- package/dist/__tests__/transport-mux.test.js +0 -283
- package/dist/__tests__/turn-segmenter.test.js +0 -166
- package/dist/__tests__/uninstall.test.js +0 -141
- package/dist/__tests__/warm-start-policy.test.js +0 -271
- package/dist/__tests__/wire-cap-nudge.test.js +0 -77
- package/dist/__tests__/worker-pool.test.js +0 -101
- package/dist/ui/assets/index-7gl3mIuY.css +0 -1
- package/dist/ui/assets/index-CX4FCWGT.js +0 -10
- package/dist/ui/assets/rolldown-runtime-S-ySWqyJ.js +0 -1
- package/dist/ui/assets/vis-network-NIJHUFI3.js +0 -908
- package/dist/ui/fonts/jetbrains-mono-latin-400-normal.woff +0 -0
- package/dist/ui/icon-wordmark.png +0 -0
- package/dist/ui/icon-wordmark.svg +0 -30
- package/dist/ui/icon.png +0 -0
- package/dist/ui/icon.svg +0 -25
- package/dist/ui/index.html +0 -15
- package/dist/ui/prototype-sandbox/index.html +0 -257
- package/dist/ui/screenshots/activity.png +0 -0
- package/dist/ui/screenshots/code-base-intelligence.png +0 -0
- package/dist/ui/screenshots/dashboard.png +0 -0
- package/dist/ui/screenshots/project-memory.png +0 -0
- package/dist/ui/screenshots/reasoning-quality.png +0 -0
- package/dist/ui/screenshots/reasoning-session.png +0 -0
- package/dist/ui/screenshots/token-session.png +0 -0
- package/dist/ui/screenshots/token-trace-main.png +0 -0
- package/dist/ui/screenshots/token-turn.png +0 -0
- package/dist/ui/unerr-wordmark.png +0 -0
- package/dist/ui/unerr-wordmark.svg +0 -9
- package/dist/ui/unerr.png +0 -0
- package/dist/ui/unerr.svg +0 -25
- package/dist/ui/web-app-manifest-192x192.png +0 -0
- package/dist/ui/web-app-manifest-512x512.png +0 -0
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TR-1 / TR-2: filter + pagination + listSessions + getActivityBuckets store
|
|
3
|
-
* methods, plus the route surface that exposes them.
|
|
4
|
-
*/
|
|
5
|
-
import { mkdirSync, rmSync } from "node:fs";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
-
import { createTimelineRoutes } from "../server/routes/timeline.js";
|
|
10
|
-
import { CozoTimelineStore } from "../timeline/timeline-store.js";
|
|
11
|
-
let tempDir;
|
|
12
|
-
let store;
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
tempDir = join(tmpdir(), `unerr-tf-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
15
|
-
mkdirSync(join(tempDir, ".unerr"), { recursive: true });
|
|
16
|
-
store = await CozoTimelineStore.create(tempDir);
|
|
17
|
-
});
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
try {
|
|
20
|
-
store.close();
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
/* ignore */
|
|
24
|
-
}
|
|
25
|
-
try {
|
|
26
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
/* ignore */
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
function turn(overrides) {
|
|
33
|
-
return {
|
|
34
|
-
session_id: overrides.session_id ?? "s1",
|
|
35
|
-
started_at: overrides.started_at ?? 1_000,
|
|
36
|
-
ended_at: overrides.ended_at ?? 2_000,
|
|
37
|
-
opened_by: overrides.opened_by ?? "first_call",
|
|
38
|
-
closed_reason: overrides.closed_reason ?? "session_end",
|
|
39
|
-
tool_count: overrides.tool_count ?? 3,
|
|
40
|
-
file_count: overrides.file_count ?? 2,
|
|
41
|
-
edit_count: overrides.edit_count ?? 1,
|
|
42
|
-
title: overrides.title ?? "",
|
|
43
|
-
outcome: overrides.outcome ?? "unknown",
|
|
44
|
-
...overrides,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
describe("listTurns — filters + pagination", () => {
|
|
48
|
-
it("paginates via offset + limit", async () => {
|
|
49
|
-
for (let i = 0; i < 7; i++) {
|
|
50
|
-
await store.upsertTurn(turn({ turn_id: `t${i}`, started_at: 1000 + i * 1000 }));
|
|
51
|
-
}
|
|
52
|
-
const page1 = await store.listTurns({ limit: 3, offset: 0 });
|
|
53
|
-
const page2 = await store.listTurns({ limit: 3, offset: 3 });
|
|
54
|
-
const page3 = await store.listTurns({ limit: 3, offset: 6 });
|
|
55
|
-
expect(page1.map((t) => t.turn_id)).toEqual(["t6", "t5", "t4"]);
|
|
56
|
-
expect(page2.map((t) => t.turn_id)).toEqual(["t3", "t2", "t1"]);
|
|
57
|
-
expect(page3.map((t) => t.turn_id)).toEqual(["t0"]);
|
|
58
|
-
});
|
|
59
|
-
it("filters by fromTs / toTs (inclusive)", async () => {
|
|
60
|
-
await store.upsertTurn(turn({ turn_id: "a", started_at: 100 }));
|
|
61
|
-
await store.upsertTurn(turn({ turn_id: "b", started_at: 500 }));
|
|
62
|
-
await store.upsertTurn(turn({ turn_id: "c", started_at: 900 }));
|
|
63
|
-
const within = await store.listTurns({ fromTs: 200, toTs: 800 });
|
|
64
|
-
expect(within.map((t) => t.turn_id)).toEqual(["b"]);
|
|
65
|
-
});
|
|
66
|
-
it("filters by query — case-insensitive substring on title", async () => {
|
|
67
|
-
await store.upsertTurn(turn({ turn_id: "a", title: "Refactor Auth Middleware" }));
|
|
68
|
-
await store.upsertTurn(turn({ turn_id: "b", title: "Payments cleanup" }));
|
|
69
|
-
await store.upsertTurn(turn({ turn_id: "c", title: "auth follow-up" }));
|
|
70
|
-
const hits = await store.listTurns({ query: "auth" });
|
|
71
|
-
expect(hits.map((t) => t.turn_id).sort()).toEqual(["a", "c"]);
|
|
72
|
-
});
|
|
73
|
-
it("query escapes regex metacharacters in the user input", async () => {
|
|
74
|
-
await store.upsertTurn(turn({ turn_id: "a", title: "fix [bug] in handler" }));
|
|
75
|
-
await store.upsertTurn(turn({ turn_id: "b", title: "fix bug" }));
|
|
76
|
-
const hits = await store.listTurns({ query: "[bug]" });
|
|
77
|
-
expect(hits.map((t) => t.turn_id)).toEqual(["a"]);
|
|
78
|
-
});
|
|
79
|
-
it("countTurns mirrors the same filter semantics", async () => {
|
|
80
|
-
await store.upsertTurn(turn({ turn_id: "a", session_id: "s1", started_at: 100 }));
|
|
81
|
-
await store.upsertTurn(turn({ turn_id: "b", session_id: "s1", started_at: 200 }));
|
|
82
|
-
await store.upsertTurn(turn({ turn_id: "c", session_id: "s2", started_at: 150 }));
|
|
83
|
-
expect(await store.countTurns({})).toBe(3);
|
|
84
|
-
expect(await store.countTurns({ sessionId: "s1" })).toBe(2);
|
|
85
|
-
expect(await store.countTurns({ fromTs: 110, toTs: 250 })).toBe(2);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
describe("listSessions", () => {
|
|
89
|
-
it("aggregates per-session stats and orders by last_seen desc", async () => {
|
|
90
|
-
await store.upsertTurn(turn({
|
|
91
|
-
turn_id: "x1",
|
|
92
|
-
session_id: "sa",
|
|
93
|
-
started_at: 100,
|
|
94
|
-
ended_at: 200,
|
|
95
|
-
edit_count: 1,
|
|
96
|
-
file_count: 2,
|
|
97
|
-
}));
|
|
98
|
-
await store.upsertTurn(turn({
|
|
99
|
-
turn_id: "x2",
|
|
100
|
-
session_id: "sa",
|
|
101
|
-
started_at: 300,
|
|
102
|
-
ended_at: 400,
|
|
103
|
-
edit_count: 2,
|
|
104
|
-
file_count: 3,
|
|
105
|
-
}));
|
|
106
|
-
await store.upsertTurn(turn({
|
|
107
|
-
turn_id: "x3",
|
|
108
|
-
session_id: "sb",
|
|
109
|
-
started_at: 500,
|
|
110
|
-
ended_at: 600,
|
|
111
|
-
edit_count: 1,
|
|
112
|
-
file_count: 1,
|
|
113
|
-
}));
|
|
114
|
-
const list = await store.listSessions();
|
|
115
|
-
expect(list.map((s) => s.session_id)).toEqual(["sb", "sa"]);
|
|
116
|
-
const sa = list.find((s) => s.session_id === "sa");
|
|
117
|
-
expect(sa.turn_count).toBe(2);
|
|
118
|
-
expect(sa.edit_count).toBe(3);
|
|
119
|
-
expect(sa.first_seen).toBe(100);
|
|
120
|
-
expect(sa.last_seen).toBe(400);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
describe("getActivityBuckets", () => {
|
|
124
|
-
it("fills the requested range with zero days and counts turns per bucket", async () => {
|
|
125
|
-
const day = 24 * 60 * 60_000;
|
|
126
|
-
const t0 = day; // bucket-aligned for predictability
|
|
127
|
-
await store.upsertTurn(turn({
|
|
128
|
-
turn_id: "a",
|
|
129
|
-
started_at: t0,
|
|
130
|
-
ended_at: t0 + 5_000,
|
|
131
|
-
edit_count: 1,
|
|
132
|
-
tool_count: 4,
|
|
133
|
-
}));
|
|
134
|
-
await store.upsertTurn(turn({
|
|
135
|
-
turn_id: "b",
|
|
136
|
-
started_at: t0 + day + 1_000,
|
|
137
|
-
ended_at: t0 + day + 5_000,
|
|
138
|
-
edit_count: 3,
|
|
139
|
-
tool_count: 7,
|
|
140
|
-
}));
|
|
141
|
-
const buckets = await store.getActivityBuckets({
|
|
142
|
-
fromTs: t0,
|
|
143
|
-
toTs: t0 + 3 * day,
|
|
144
|
-
bucketMs: day,
|
|
145
|
-
});
|
|
146
|
-
expect(buckets).toHaveLength(4);
|
|
147
|
-
expect(buckets[0]?.turns).toBe(1);
|
|
148
|
-
expect(buckets[1]?.turns).toBe(1);
|
|
149
|
-
expect(buckets[1]?.edits).toBe(3);
|
|
150
|
-
expect(buckets[1]?.tools).toBe(7);
|
|
151
|
-
expect(buckets[2]?.turns).toBe(0);
|
|
152
|
-
expect(buckets[3]?.turns).toBe(0);
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe("HTTP routes — pagination + sessions + heatmap", () => {
|
|
156
|
-
it("GET /turns returns paginated envelope (total, returned, offset, limit)", async () => {
|
|
157
|
-
for (let i = 0; i < 5; i++) {
|
|
158
|
-
await store.upsertTurn(turn({ turn_id: `r${i}`, started_at: 1000 + i * 1000 }));
|
|
159
|
-
}
|
|
160
|
-
const app = createTimelineRoutes({ store });
|
|
161
|
-
const res = await app.request("/turns?limit=2&offset=2");
|
|
162
|
-
const body = (await res.json());
|
|
163
|
-
expect(body.total).toBe(5);
|
|
164
|
-
expect(body.returned).toBe(2);
|
|
165
|
-
expect(body.offset).toBe(2);
|
|
166
|
-
expect(body.limit).toBe(2);
|
|
167
|
-
expect(body.data.map((t) => t.turn_id)).toEqual(["r2", "r1"]);
|
|
168
|
-
});
|
|
169
|
-
it("GET /turns?q= performs a substring search", async () => {
|
|
170
|
-
await store.upsertTurn(turn({ turn_id: "a", title: "Auth refactor" }));
|
|
171
|
-
await store.upsertTurn(turn({ turn_id: "b", title: "Payments" }));
|
|
172
|
-
const app = createTimelineRoutes({ store });
|
|
173
|
-
const res = await app.request("/turns?q=auth");
|
|
174
|
-
const body = (await res.json());
|
|
175
|
-
expect(body.total).toBe(1);
|
|
176
|
-
expect(body.data[0]?.turn_id).toBe("a");
|
|
177
|
-
});
|
|
178
|
-
it("GET /sessions returns the aggregated session list", async () => {
|
|
179
|
-
await store.upsertTurn(turn({ turn_id: "x", session_id: "sa", started_at: 100, ended_at: 200 }));
|
|
180
|
-
const app = createTimelineRoutes({ store });
|
|
181
|
-
const res = await app.request("/sessions");
|
|
182
|
-
const body = (await res.json());
|
|
183
|
-
expect(body.data).toHaveLength(1);
|
|
184
|
-
expect(body.data[0]?.session_id).toBe("sa");
|
|
185
|
-
expect(body.data[0]?.turn_count).toBe(1);
|
|
186
|
-
});
|
|
187
|
-
it("GET /heatmap returns the requested number of buckets", async () => {
|
|
188
|
-
const app = createTimelineRoutes({ store });
|
|
189
|
-
const res = await app.request("/heatmap?days=7");
|
|
190
|
-
const body = (await res.json());
|
|
191
|
-
expect(body.data.length).toBe(7);
|
|
192
|
-
});
|
|
193
|
-
});
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ST-2a: timeline marker tool handlers.
|
|
3
|
-
* Verifies dual-write (ledger + timeline.db.markers), validation, and turn
|
|
4
|
-
* stamping inheritance from the segmenter.
|
|
5
|
-
*/
|
|
6
|
-
import { mkdirSync, readFileSync, rmSync } from "node:fs";
|
|
7
|
-
import { tmpdir } from "node:os";
|
|
8
|
-
import { join } from "node:path";
|
|
9
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
10
|
-
import { CozoTimelineStore } from "../timeline/timeline-store.js";
|
|
11
|
-
import { MARKER_TOOLS, handleMarkerCall, isMarkerTool, } from "../tools/intelligence/timeline-markers.js";
|
|
12
|
-
import { ShadowLedger } from "../tracking/shadow-ledger.js";
|
|
13
|
-
let tempDir;
|
|
14
|
-
let unerrDir;
|
|
15
|
-
let ledger;
|
|
16
|
-
let store;
|
|
17
|
-
beforeEach(async () => {
|
|
18
|
-
tempDir = join(tmpdir(), `unerr-mk-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
19
|
-
unerrDir = join(tempDir, ".unerr");
|
|
20
|
-
mkdirSync(unerrDir, { recursive: true });
|
|
21
|
-
ledger = new ShadowLedger(unerrDir);
|
|
22
|
-
store = await CozoTimelineStore.create(tempDir);
|
|
23
|
-
});
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
try {
|
|
26
|
-
store.close();
|
|
27
|
-
}
|
|
28
|
-
catch {
|
|
29
|
-
/* ignore */
|
|
30
|
-
}
|
|
31
|
-
try {
|
|
32
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
/* ignore */
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
describe("isMarkerTool / MARKER_TOOLS", () => {
|
|
39
|
-
it("recognises all four marker names", () => {
|
|
40
|
-
expect(MARKER_TOOLS).toEqual([
|
|
41
|
-
"mark_intent",
|
|
42
|
-
"mark_decision",
|
|
43
|
-
"mark_blocker",
|
|
44
|
-
"mark_resolution",
|
|
45
|
-
]);
|
|
46
|
-
for (const t of MARKER_TOOLS) {
|
|
47
|
-
expect(isMarkerTool(t)).toBe(true);
|
|
48
|
-
}
|
|
49
|
-
expect(isMarkerTool("file_read")).toBe(false);
|
|
50
|
-
expect(isMarkerTool("mark_anything_else")).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe("handleMarkerCall — happy paths", () => {
|
|
54
|
-
it("mark_intent writes a ledger row AND a markers row", async () => {
|
|
55
|
-
const res = await handleMarkerCall("mark_intent", { text: "refactor auth" }, { ledger, store, branch: "main", headSha: "deadbeef" });
|
|
56
|
-
const body = JSON.parse(res.content[0].text);
|
|
57
|
-
expect(body.ok).toBe(true);
|
|
58
|
-
expect(body.type).toBe("mark_intent");
|
|
59
|
-
expect(body.marker_id).toMatch(/^[a-f0-9]{12}$/);
|
|
60
|
-
expect(body.turn_id).toMatch(/^[a-f0-9]{12}$/);
|
|
61
|
-
// Ledger row
|
|
62
|
-
const ledgerLines = readFileSync(join(unerrDir, "ledger", "shadow.jsonl"), "utf-8")
|
|
63
|
-
.trim()
|
|
64
|
-
.split("\n")
|
|
65
|
-
.map((l) => JSON.parse(l));
|
|
66
|
-
expect(ledgerLines).toHaveLength(1);
|
|
67
|
-
expect(ledgerLines[0].tool).toBe("mark_intent");
|
|
68
|
-
expect(ledgerLines[0].args_summary.text).toBe("refactor auth");
|
|
69
|
-
expect(ledgerLines[0].turn_id).toBe(body.turn_id);
|
|
70
|
-
// Timeline.db row
|
|
71
|
-
const markers = await store.listMarkers();
|
|
72
|
-
expect(markers).toHaveLength(1);
|
|
73
|
-
expect(markers[0].marker_id).toBe(body.marker_id);
|
|
74
|
-
expect(markers[0].type).toBe("mark_intent");
|
|
75
|
-
expect(markers[0].text).toBe("refactor auth");
|
|
76
|
-
expect(markers[0].turn_id).toBe(body.turn_id);
|
|
77
|
-
});
|
|
78
|
-
it("mark_decision persists alternatives (capped)", async () => {
|
|
79
|
-
await handleMarkerCall("mark_decision", {
|
|
80
|
-
text: "JWT over session cookies",
|
|
81
|
-
alternatives: ["session cookies", "OAuth proxy", "API tokens"],
|
|
82
|
-
}, { ledger, store, branch: "main", headSha: "x" });
|
|
83
|
-
const lines = readFileSync(join(unerrDir, "ledger", "shadow.jsonl"), "utf-8")
|
|
84
|
-
.trim()
|
|
85
|
-
.split("\n")
|
|
86
|
-
.map((l) => JSON.parse(l));
|
|
87
|
-
expect(lines[0].args_summary.alternatives).toEqual([
|
|
88
|
-
"session cookies",
|
|
89
|
-
"OAuth proxy",
|
|
90
|
-
"API tokens",
|
|
91
|
-
]);
|
|
92
|
-
});
|
|
93
|
-
it("mark_blocker carries file_path through to timeline.db", async () => {
|
|
94
|
-
const res = await handleMarkerCall("mark_blocker", { text: "type error in verify", file_path: "src/auth/token.ts" }, { ledger, store, branch: "main", headSha: "x" });
|
|
95
|
-
const body = JSON.parse(res.content[0].text);
|
|
96
|
-
const markers = await store.listMarkers({ type: "mark_blocker" });
|
|
97
|
-
expect(markers).toHaveLength(1);
|
|
98
|
-
expect(markers[0].marker_id).toBe(body.marker_id);
|
|
99
|
-
expect(markers[0].file_path).toBe("src/auth/token.ts");
|
|
100
|
-
});
|
|
101
|
-
it("redacts secrets in BOTH the ledger row AND the timeline.db markers row", async () => {
|
|
102
|
-
// Regression — live test on 2026-05-12 found the redactor only ran on
|
|
103
|
-
// shadow.jsonl; raw tokens leaked into timeline.db.markers.text.
|
|
104
|
-
const tokenish = "GITHUB_TOKEN=ghp_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
|
105
|
-
const res = await handleMarkerCall("mark_blocker", { text: `auth fails when ${tokenish} is set`, file_path: "src/auth.ts" }, { ledger, store, branch: "main", headSha: "x" });
|
|
106
|
-
const body = JSON.parse(res.content[0].text);
|
|
107
|
-
expect(body.ok).toBe(true);
|
|
108
|
-
// Ledger redacted
|
|
109
|
-
const ledgerLines = readFileSync(join(unerrDir, "ledger", "shadow.jsonl"), "utf-8")
|
|
110
|
-
.trim()
|
|
111
|
-
.split("\n")
|
|
112
|
-
.map((l) => JSON.parse(l));
|
|
113
|
-
const ledgerRow = ledgerLines.find((r) => r.id === body.marker_id);
|
|
114
|
-
expect(ledgerRow.args_summary.text).not.toContain("ghp_");
|
|
115
|
-
expect(ledgerRow.args_summary.text).toContain("<redacted>");
|
|
116
|
-
// Timeline.db markers row also redacted (the bug)
|
|
117
|
-
const markers = await store.listMarkers({ type: "mark_blocker" });
|
|
118
|
-
const row = markers.find((m) => m.marker_id === body.marker_id);
|
|
119
|
-
expect(row).toBeDefined();
|
|
120
|
-
expect(row.text).not.toContain("ghp_");
|
|
121
|
-
expect(row.text).toContain("<redacted>");
|
|
122
|
-
});
|
|
123
|
-
it("mark_resolution links to blocker via blocker_ref", async () => {
|
|
124
|
-
const blocker = await handleMarkerCall("mark_blocker", { text: "type error" }, { ledger, store, branch: "main", headSha: "x" });
|
|
125
|
-
const blockerId = JSON.parse(blocker.content[0].text).marker_id;
|
|
126
|
-
const res = await handleMarkerCall("mark_resolution", { blocker_ref: blockerId, text: "fixed by import bump" }, { ledger, store, branch: "main", headSha: "x" });
|
|
127
|
-
const body = JSON.parse(res.content[0].text);
|
|
128
|
-
expect(body.ok).toBe(true);
|
|
129
|
-
const resolutions = await store.listMarkers({ type: "mark_resolution" });
|
|
130
|
-
expect(resolutions).toHaveLength(1);
|
|
131
|
-
expect(resolutions[0].blocker_ref).toBe(blockerId);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
describe("handleMarkerCall — validation", () => {
|
|
135
|
-
it("rejects empty text", async () => {
|
|
136
|
-
const res = await handleMarkerCall("mark_intent", { text: " " }, { ledger, store, branch: "main", headSha: "x" });
|
|
137
|
-
const body = JSON.parse(res.content[0].text);
|
|
138
|
-
expect(body.error).toMatch(/required/);
|
|
139
|
-
});
|
|
140
|
-
it("rejects over-cap text per tool", async () => {
|
|
141
|
-
const long = "x".repeat(200);
|
|
142
|
-
const res = await handleMarkerCall("mark_intent", { text: long }, { ledger, store, branch: "main", headSha: "x" });
|
|
143
|
-
const body = JSON.parse(res.content[0].text);
|
|
144
|
-
expect(body.error).toMatch(/80/);
|
|
145
|
-
});
|
|
146
|
-
it("mark_resolution requires blocker_ref", async () => {
|
|
147
|
-
const res = await handleMarkerCall("mark_resolution", { text: "fixed" }, { ledger, store, branch: "main", headSha: "x" });
|
|
148
|
-
const body = JSON.parse(res.content[0].text);
|
|
149
|
-
expect(body.error).toMatch(/blocker_ref required/);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ST-3b: Timeline HTTP routes — smoke test against the Hono app.
|
|
3
|
-
*/
|
|
4
|
-
import { mkdirSync, rmSync } from "node:fs";
|
|
5
|
-
import { tmpdir } from "node:os";
|
|
6
|
-
import { join } from "node:path";
|
|
7
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
8
|
-
import { createTimelineRoutes } from "../server/routes/timeline.js";
|
|
9
|
-
import { CozoTimelineStore } from "../timeline/timeline-store.js";
|
|
10
|
-
let tempDir;
|
|
11
|
-
let store;
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
tempDir = join(tmpdir(), `unerr-rt-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
14
|
-
mkdirSync(join(tempDir, ".unerr"), { recursive: true });
|
|
15
|
-
store = await CozoTimelineStore.create(tempDir);
|
|
16
|
-
});
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
try {
|
|
19
|
-
store.close();
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
/* ignore */
|
|
23
|
-
}
|
|
24
|
-
try {
|
|
25
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
/* ignore */
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
async function jsonOf(res) {
|
|
32
|
-
return await res.json();
|
|
33
|
-
}
|
|
34
|
-
describe("Timeline routes", () => {
|
|
35
|
-
it("GET /health reports the db path", async () => {
|
|
36
|
-
const app = createTimelineRoutes({ store });
|
|
37
|
-
const res = await app.request("/health");
|
|
38
|
-
expect(res.status).toBe(200);
|
|
39
|
-
const body = (await jsonOf(res));
|
|
40
|
-
expect(body.data.ok).toBe(true);
|
|
41
|
-
expect(body.data.db_path).toBe(store.dbPath);
|
|
42
|
-
});
|
|
43
|
-
it("GET /turns returns turns in newest-first order", async () => {
|
|
44
|
-
await store.upsertTurn({
|
|
45
|
-
turn_id: "t1",
|
|
46
|
-
session_id: "s1",
|
|
47
|
-
started_at: 100,
|
|
48
|
-
ended_at: 200,
|
|
49
|
-
opened_by: "first_call",
|
|
50
|
-
closed_reason: "session_end",
|
|
51
|
-
tool_count: 2,
|
|
52
|
-
file_count: 1,
|
|
53
|
-
edit_count: 0,
|
|
54
|
-
title: "early",
|
|
55
|
-
outcome: "unknown",
|
|
56
|
-
});
|
|
57
|
-
await store.upsertTurn({
|
|
58
|
-
turn_id: "t2",
|
|
59
|
-
session_id: "s1",
|
|
60
|
-
started_at: 300,
|
|
61
|
-
ended_at: 400,
|
|
62
|
-
opened_by: "idle_gap",
|
|
63
|
-
closed_reason: "idle_gap",
|
|
64
|
-
tool_count: 5,
|
|
65
|
-
file_count: 2,
|
|
66
|
-
edit_count: 1,
|
|
67
|
-
title: "late",
|
|
68
|
-
outcome: "unknown",
|
|
69
|
-
});
|
|
70
|
-
const app = createTimelineRoutes({ store });
|
|
71
|
-
const res = await app.request("/turns");
|
|
72
|
-
const body = (await jsonOf(res));
|
|
73
|
-
expect(body.data.map((t) => t.turn_id)).toEqual(["t2", "t1"]);
|
|
74
|
-
});
|
|
75
|
-
it("GET /loops uses the ledger getter for live detection", async () => {
|
|
76
|
-
const t = (offsetSec) => new Date(Date.parse("2026-05-12T10:00:00Z") + offsetSec * 1000).toISOString();
|
|
77
|
-
let id = 0;
|
|
78
|
-
const make = (tool, file, ts) => {
|
|
79
|
-
id += 1;
|
|
80
|
-
return {
|
|
81
|
-
id: `e${id}`,
|
|
82
|
-
ts,
|
|
83
|
-
tool,
|
|
84
|
-
args_summary: { file_path: file },
|
|
85
|
-
result_summary: {},
|
|
86
|
-
branch: "main",
|
|
87
|
-
head_sha: "x",
|
|
88
|
-
session_id: "s1",
|
|
89
|
-
correlation_id: null,
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
const entries = [
|
|
93
|
-
make("file_read", "a.ts", t(0)),
|
|
94
|
-
make("file_read", "a.ts", t(10)),
|
|
95
|
-
make("file_read", "a.ts", t(20)),
|
|
96
|
-
make("file_read", "a.ts", t(30)),
|
|
97
|
-
make("file_read", "a.ts", t(40)),
|
|
98
|
-
];
|
|
99
|
-
const app = createTimelineRoutes({
|
|
100
|
-
store,
|
|
101
|
-
getRecentLedgerEntries: () => entries,
|
|
102
|
-
});
|
|
103
|
-
const res = await app.request("/loops");
|
|
104
|
-
const body = (await jsonOf(res));
|
|
105
|
-
expect(body.data).toHaveLength(1);
|
|
106
|
-
expect(body.data[0]?.kind).toBe("file_reread");
|
|
107
|
-
});
|
|
108
|
-
it("GET /resume returns null when no recent turn exists", async () => {
|
|
109
|
-
const app = createTimelineRoutes({ store });
|
|
110
|
-
const res = await app.request("/resume");
|
|
111
|
-
const body = (await jsonOf(res));
|
|
112
|
-
expect(body.data).toBeNull();
|
|
113
|
-
});
|
|
114
|
-
it("GET /resume surfaces dominant intent + open blockers for the latest fresh turn", async () => {
|
|
115
|
-
const now = Date.now();
|
|
116
|
-
await store.upsertTurn({
|
|
117
|
-
turn_id: "tx",
|
|
118
|
-
session_id: "sx",
|
|
119
|
-
started_at: now - 60_000,
|
|
120
|
-
ended_at: now - 30_000,
|
|
121
|
-
opened_by: "first_call",
|
|
122
|
-
closed_reason: "session_end",
|
|
123
|
-
tool_count: 3,
|
|
124
|
-
file_count: 1,
|
|
125
|
-
edit_count: 0,
|
|
126
|
-
title: "auth refactor",
|
|
127
|
-
outcome: "unknown",
|
|
128
|
-
});
|
|
129
|
-
await store.insertMarker({
|
|
130
|
-
marker_id: "i1",
|
|
131
|
-
type: "mark_intent",
|
|
132
|
-
text: "harden auth flow",
|
|
133
|
-
session_id: "sx",
|
|
134
|
-
turn_id: "tx",
|
|
135
|
-
ts: now - 50_000,
|
|
136
|
-
blocker_ref: "",
|
|
137
|
-
file_path: "",
|
|
138
|
-
});
|
|
139
|
-
await store.insertMarker({
|
|
140
|
-
marker_id: "b1",
|
|
141
|
-
type: "mark_blocker",
|
|
142
|
-
text: "type error in verify",
|
|
143
|
-
session_id: "sx",
|
|
144
|
-
turn_id: "tx",
|
|
145
|
-
ts: now - 40_000,
|
|
146
|
-
blocker_ref: "",
|
|
147
|
-
file_path: "src/auth.ts",
|
|
148
|
-
});
|
|
149
|
-
const app = createTimelineRoutes({ store });
|
|
150
|
-
const res = await app.request("/resume");
|
|
151
|
-
const body = (await jsonOf(res));
|
|
152
|
-
expect(body.data.intent).toBe("harden auth flow");
|
|
153
|
-
expect(body.data.session_id).toBe("sx");
|
|
154
|
-
expect(body.data.open_threads.map((t) => t.text)).toContain("type error in verify");
|
|
155
|
-
});
|
|
156
|
-
});
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ST-1b: CozoTimelineStore — third CozoDB instance at `.unerr/timeline.db`.
|
|
3
|
-
* Tests cover open/init, idempotence, and round-trip CRUD on turns + markers.
|
|
4
|
-
*/
|
|
5
|
-
import { existsSync, mkdirSync, rmSync } from "node:fs";
|
|
6
|
-
import { tmpdir } from "node:os";
|
|
7
|
-
import { join } from "node:path";
|
|
8
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
-
import { CozoTimelineStore, } from "../timeline/timeline-store.js";
|
|
10
|
-
let tempDir;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
tempDir = join(tmpdir(), `unerr-tl-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
13
|
-
mkdirSync(tempDir, { recursive: true });
|
|
14
|
-
});
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
try {
|
|
17
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
/* ignore */
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
function makeTurn(overrides = {}) {
|
|
24
|
-
return {
|
|
25
|
-
turn_id: overrides.turn_id ?? "t1",
|
|
26
|
-
session_id: overrides.session_id ?? "s1",
|
|
27
|
-
started_at: overrides.started_at ?? 1000,
|
|
28
|
-
ended_at: overrides.ended_at ?? 2000,
|
|
29
|
-
opened_by: overrides.opened_by ?? "first_call",
|
|
30
|
-
closed_reason: overrides.closed_reason ?? "session_end",
|
|
31
|
-
tool_count: overrides.tool_count ?? 3,
|
|
32
|
-
file_count: overrides.file_count ?? 2,
|
|
33
|
-
edit_count: overrides.edit_count ?? 1,
|
|
34
|
-
title: overrides.title ?? "",
|
|
35
|
-
outcome: overrides.outcome ?? "unknown",
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function makeMarker(overrides = {}) {
|
|
39
|
-
return {
|
|
40
|
-
marker_id: overrides.marker_id ?? "m1",
|
|
41
|
-
type: overrides.type ?? "mark_intent",
|
|
42
|
-
text: overrides.text ?? "refactor auth",
|
|
43
|
-
session_id: overrides.session_id ?? "s1",
|
|
44
|
-
turn_id: overrides.turn_id ?? "t1",
|
|
45
|
-
ts: overrides.ts ?? 1500,
|
|
46
|
-
blocker_ref: overrides.blocker_ref ?? "",
|
|
47
|
-
file_path: overrides.file_path ?? "",
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
describe("CozoTimelineStore", () => {
|
|
51
|
-
it("creates .unerr/timeline.db on first call and reports isNew=true", async () => {
|
|
52
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
53
|
-
try {
|
|
54
|
-
expect(store.isNew).toBe(true);
|
|
55
|
-
expect(store.dbPath).toBe(join(tempDir, ".unerr", "timeline.db"));
|
|
56
|
-
expect(existsSync(store.dbPath)).toBe(true);
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
store.close();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
it("second create on the same path reports isNew=false and schema-init is idempotent", async () => {
|
|
63
|
-
const a = await CozoTimelineStore.create(tempDir);
|
|
64
|
-
a.close();
|
|
65
|
-
const b = await CozoTimelineStore.create(tempDir);
|
|
66
|
-
try {
|
|
67
|
-
expect(b.isNew).toBe(false);
|
|
68
|
-
}
|
|
69
|
-
finally {
|
|
70
|
-
b.close();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
it("initialises all six expected relations", async () => {
|
|
74
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
75
|
-
try {
|
|
76
|
-
const rels = await store.getDb().run("::relations");
|
|
77
|
-
const names = new Set(rels.rows.map((r) => r[0]));
|
|
78
|
-
for (const expected of [
|
|
79
|
-
"turns",
|
|
80
|
-
"intents",
|
|
81
|
-
"intent_sessions",
|
|
82
|
-
"markers",
|
|
83
|
-
"derived_signals",
|
|
84
|
-
"signal_reinforcement",
|
|
85
|
-
]) {
|
|
86
|
-
expect(names.has(expected)).toBe(true);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
finally {
|
|
90
|
-
store.close();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
it("round-trips a turn through upsertTurn → listTurns", async () => {
|
|
94
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
95
|
-
try {
|
|
96
|
-
const turn = makeTurn({ title: "auth refactor" });
|
|
97
|
-
await store.upsertTurn(turn);
|
|
98
|
-
const list = await store.listTurns();
|
|
99
|
-
expect(list).toHaveLength(1);
|
|
100
|
-
expect(list[0]?.turn_id).toBe(turn.turn_id);
|
|
101
|
-
expect(list[0]?.title).toBe("auth refactor");
|
|
102
|
-
expect(list[0]?.opened_by).toBe("first_call");
|
|
103
|
-
}
|
|
104
|
-
finally {
|
|
105
|
-
store.close();
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
it("upsertTurn replaces an existing turn with the same id", async () => {
|
|
109
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
110
|
-
try {
|
|
111
|
-
await store.upsertTurn(makeTurn({ title: "v1", tool_count: 1 }));
|
|
112
|
-
await store.upsertTurn(makeTurn({ title: "v2", tool_count: 5 }));
|
|
113
|
-
const list = await store.listTurns();
|
|
114
|
-
expect(list).toHaveLength(1);
|
|
115
|
-
expect(list[0]?.title).toBe("v2");
|
|
116
|
-
expect(list[0]?.tool_count).toBe(5);
|
|
117
|
-
}
|
|
118
|
-
finally {
|
|
119
|
-
store.close();
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
it("listTurns filters by session and orders newest-first", async () => {
|
|
123
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
124
|
-
try {
|
|
125
|
-
await store.upsertTurn(makeTurn({ turn_id: "t1", session_id: "a", started_at: 100 }));
|
|
126
|
-
await store.upsertTurn(makeTurn({ turn_id: "t2", session_id: "a", started_at: 200 }));
|
|
127
|
-
await store.upsertTurn(makeTurn({ turn_id: "t3", session_id: "b", started_at: 150 }));
|
|
128
|
-
const inA = await store.listTurns({ sessionId: "a" });
|
|
129
|
-
expect(inA.map((t) => t.turn_id)).toEqual(["t2", "t1"]);
|
|
130
|
-
const all = await store.listTurns();
|
|
131
|
-
expect(all.map((t) => t.turn_id)).toEqual(["t2", "t3", "t1"]);
|
|
132
|
-
}
|
|
133
|
-
finally {
|
|
134
|
-
store.close();
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
it("round-trips markers through insertMarker → listMarkers with type filter", async () => {
|
|
138
|
-
const store = await CozoTimelineStore.create(tempDir);
|
|
139
|
-
try {
|
|
140
|
-
await store.insertMarker(makeMarker({
|
|
141
|
-
marker_id: "m1",
|
|
142
|
-
type: "mark_intent",
|
|
143
|
-
text: "auth",
|
|
144
|
-
ts: 100,
|
|
145
|
-
}));
|
|
146
|
-
await store.insertMarker(makeMarker({
|
|
147
|
-
marker_id: "m2",
|
|
148
|
-
type: "mark_blocker",
|
|
149
|
-
text: "type error",
|
|
150
|
-
ts: 200,
|
|
151
|
-
}));
|
|
152
|
-
await store.insertMarker(makeMarker({
|
|
153
|
-
marker_id: "m3",
|
|
154
|
-
type: "mark_resolution",
|
|
155
|
-
text: "fixed",
|
|
156
|
-
ts: 300,
|
|
157
|
-
blocker_ref: "m2",
|
|
158
|
-
}));
|
|
159
|
-
const all = await store.listMarkers();
|
|
160
|
-
expect(all.map((m) => m.marker_id)).toEqual(["m3", "m2", "m1"]);
|
|
161
|
-
const blockers = await store.listMarkers({ type: "mark_blocker" });
|
|
162
|
-
expect(blockers).toHaveLength(1);
|
|
163
|
-
expect(blockers[0]?.text).toBe("type error");
|
|
164
|
-
const resolutions = await store.listMarkers({ type: "mark_resolution" });
|
|
165
|
-
expect(resolutions[0]?.blocker_ref).toBe("m2");
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
store.close();
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
});
|