Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tests/adapters/omp-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ import "../setup-home";
*/

import { describe, it, expect, beforeEach, afterEach } from "vitest";

const activeDBs: Array<{ close?: () => void }> = [];
afterEach(() => {
for (const db of activeDBs) { try { db.close?.(); } catch {} }
activeDBs.length = 0;
});

import { mkdtempSync, rmSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
Expand Down Expand Up @@ -206,6 +213,7 @@ describe("OMP plugin", () => {
sessionsDir: adapter.getSessionDir(),
}),
});
activeDBs.push(db as any);
const latest = db.getLatestSessionId();
expect(latest).not.toBeNull();
const events = db.getEvents(latest as string);
Expand Down Expand Up @@ -252,6 +260,7 @@ describe("OMP plugin", () => {
sessionsDir: adapter.getSessionDir(),
}),
});
activeDBs.push(db as any);
const latest = db.getLatestSessionId();
expect(latest).not.toBeNull();
});
Expand Down Expand Up @@ -309,6 +318,7 @@ describe("OMP plugin", () => {
sessionsDir: adapter.getSessionDir(),
}),
});
activeDBs.push(db as any);
const resume = db.getResume(sid);
expect(resume).not.toBeNull();
expect(resume?.snapshot.length).toBeGreaterThan(0);
Expand Down Expand Up @@ -357,7 +367,10 @@ describe("OMP plugin", () => {
expect(fileExists(canonicalPath)).toBe(true);

// Verify the canonical file is the one with our session_start row.
const db = new SessionDB({ dbPath: canonicalPath });
const db = new SessionDB({ dbPath: canonicalPath });
activeDBs.push(db as any);
activeDBs.push(db as any);
activeDBs.push(db as any);
try {
const latest = db.getLatestSessionId();
expect(latest).not.toBeNull();
Expand Down
20 changes: 17 additions & 3 deletions tests/core/search-project-filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,42 @@
* null (no filter), explicit string → that string.
*/

import { describe, test, expect } from "vitest";
import { describe, test, expect, afterEach } from "vitest";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { randomUUID } from "node:crypto";
import { ContentStore } from "../../src/store.js";
import { SessionDB } from "../../src/session/db.js";
import { searchAllSources } from "../../src/search/unified.js";

const activeDBs: Array<{ close?: () => void, cleanup?: () => void }> = [];

afterEach(() => {
for (const db of activeDBs) {
try { db.cleanup?.(); } catch {}
try { db.close?.(); } catch {}
}
activeDBs.length = 0;
});

function createStore(): ContentStore {
const path = join(
tmpdir(),
`ctx-issue737-store-${Date.now()}-${Math.random().toString(36).slice(2)}.db`,
);
return new ContentStore(path);
const store = new ContentStore(path);
activeDBs.push(store as any);
return store;
}

function createSessionDB(): SessionDB {
const path = join(
tmpdir(),
`ctx-issue737-session-${Date.now()}-${Math.random().toString(36).slice(2)}.db`,
);
return new SessionDB({ dbPath: path });
const db = new SessionDB({ dbPath: path });
activeDBs.push(db as any);
return db;
}

// ═══════════════════════════════════════════════════════════
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/commit-message-symmetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/

import { describe, test, beforeEach, afterEach, expect, vi } from "vitest";

const activeDBs: Array<{ close?: () => void }> = [];
afterEach(() => {
for (const db of activeDBs) { try { db.close?.(); } catch {} }
activeDBs.length = 0;
});

import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
import { join, dirname } from "node:path";
import { tmpdir } from "node:os";
Expand Down Expand Up @@ -78,6 +85,7 @@ describe("session-loaders — Bug 2 repro: commit_message symmetric stamp", () =

test("session with 1 commit + 3 file edits — every body MUST carry commit_message alongside has_commit", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sid = "commit-msg-symmetry-" + Date.now();
db.ensureSession(sid, fakeHome);

Expand Down
22 changes: 17 additions & 5 deletions tests/integration/cross-project-attribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
*/

import { describe, test, beforeEach, afterEach, expect, vi } from "vitest";

const activeDBs: Array<{ close?: () => void }> = [];
afterEach(() => {
for (const db of activeDBs) { try { db.close?.(); } catch {} }
activeDBs.length = 0;
});

import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
import { join, dirname } from "node:path";
import { tmpdir } from "node:os";
Expand Down Expand Up @@ -102,7 +109,8 @@ describe("cross-project attribution — Bug 7 repro", () => {
});

test("tracer: cwd=projA but file_edit on projB/foo.ts → body.project resolves to projB's canonical id", async () => {
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
activeDBs.push(db as any);
const sid = "cross-proj-" + Date.now();
db.ensureSession(sid, projA);

Expand Down Expand Up @@ -145,7 +153,8 @@ describe("cross-project attribution — Bug 7 repro", () => {
});

test("batched events split across projA + projB → each attributes to its own repo", async () => {
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
activeDBs.push(db as any);
const sid = "cross-proj-batch-" + Date.now();
db.ensureSession(sid, projA);

Expand All @@ -172,7 +181,8 @@ describe("cross-project attribution — Bug 7 repro", () => {
});

test("Bug 8 — Bash 'git -C /projB status' via real extractEvents → project=projB", async () => {
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
activeDBs.push(db as any);
const sid = "bash-c-" + Date.now();
db.ensureSession(sid, projA);

Expand Down Expand Up @@ -212,7 +222,8 @@ describe("cross-project attribution — Bug 7 repro", () => {
});

test("Bug 8 — Bash 'cd /projB && npm test' → project=projB", async () => {
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
activeDBs.push(db as any);
const sid = "bash-cd-" + Date.now();
db.ensureSession(sid, projA);

Expand Down Expand Up @@ -242,7 +253,8 @@ describe("cross-project attribution — Bug 7 repro", () => {
});

test("Bash without any path indicator → falls back to cwd (projA) — expected behavior", async () => {
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
const db = new SessionDB({ dbPath: join(fakeHome, "test.db") });
activeDBs.push(db as any);
const sid = "bash-no-path-" + Date.now();
db.ensureSession(sid, projA);

Expand Down
14 changes: 14 additions & 0 deletions tests/integration/seed-parity-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
*/

import { describe, test, beforeEach, afterEach, expect, vi } from "vitest";

const activeDBs: Array<{ close?: () => void }> = [];
afterEach(() => {
for (const db of activeDBs) { try { db.close?.(); } catch {} }
activeDBs.length = 0;
});

import { mkdtempSync, rmSync, writeFileSync, mkdirSync } from "node:fs";
import { dirname, join } from "node:path";
import { tmpdir } from "node:os";
Expand Down Expand Up @@ -132,6 +139,7 @@ describe("seed-parity coverage gate", () => {

test("every outgoing event carries all 21 universal seed-parity columns", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sessionId = "parity-session-" + Date.now();
db.ensureSession(sessionId, fakeHome);

Expand Down Expand Up @@ -181,6 +189,7 @@ describe("seed-parity coverage gate", () => {

test("variant columns populate by category", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sessionId = "parity-variants-" + Date.now();
db.ensureSession(sessionId, fakeHome);

Expand Down Expand Up @@ -224,6 +233,7 @@ describe("seed-parity coverage gate", () => {

test("rollup snapshot reflects session-wide aggregates", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sessionId = "parity-rollup-" + Date.now();
db.ensureSession(sessionId, fakeHome);

Expand Down Expand Up @@ -263,6 +273,7 @@ describe("seed-parity coverage gate", () => {

test("Bash metadata: command_type/command_tool/exit_code derived algorithmically", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sid = "bash-meta-" + Date.now();
db.ensureSession(sid, fakeHome);

Expand Down Expand Up @@ -301,6 +312,7 @@ describe("seed-parity coverage gate", () => {

test("blocker_status: derived from canonical event type, not regex", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sid = "blocker-" + Date.now();
db.ensureSession(sid, fakeHome);

Expand Down Expand Up @@ -328,6 +340,7 @@ describe("seed-parity coverage gate", () => {

test("latency_ms: read from PreToolUse marker, duration_bucket derived", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sid = "latency-" + Date.now();
db.ensureSession(sid, fakeHome);

Expand Down Expand Up @@ -358,6 +371,7 @@ describe("seed-parity coverage gate", () => {

test("variant matrix — coverage report", async () => {
const db = new SessionDB({ dbPath });
activeDBs.push(db as any);
const sessionId = "parity-matrix-" + Date.now();
db.ensureSession(sessionId, fakeHome);

Expand Down
Loading