Skip to content

Commit 6d7cffe

Browse files
Postmodum37claude
andcommitted
fix(ci): create empty test database for server smoke tests
Server smoke tests (routes, sessions, poll) hit endpoints without fixtures and expect a real SQLite DB. Add a setup script that creates an empty DB with the correct schema so these tests get empty results instead of "storage not found" errors in CI. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 683355b commit 6d7cffe

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
- name: Lint client
4242
run: cd src/client && bun run lint
4343

44+
- name: Set up test database
45+
run: bun scripts/ci-setup-db.ts
46+
4447
- name: Test server & shared
4548
run: bun run test
4649

scripts/ci-setup-db.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Creates an empty OpenCode SQLite database for CI.
3+
* Ensures smoke tests that hit endpoints without fixtures
4+
* get empty results instead of "storage not found" errors.
5+
*/
6+
import { Database } from "bun:sqlite";
7+
import { mkdirSync } from "node:fs";
8+
import { join } from "node:path";
9+
import { homedir } from "node:os";
10+
11+
const xdg = process.env.XDG_DATA_HOME ?? join(homedir(), ".local", "share");
12+
const dbDir = join(xdg, "opencode");
13+
mkdirSync(dbDir, { recursive: true });
14+
15+
const dbPath = join(dbDir, "opencode.db");
16+
const db = new Database(dbPath);
17+
18+
db.exec(`
19+
CREATE TABLE IF NOT EXISTS project (
20+
id TEXT PRIMARY KEY, name TEXT, worktree TEXT NOT NULL DEFAULT '',
21+
vcs TEXT, commands TEXT, sandboxes TEXT,
22+
time_created INTEGER NOT NULL DEFAULT 0, time_updated INTEGER NOT NULL DEFAULT 0
23+
);
24+
CREATE TABLE IF NOT EXISTS session (
25+
id TEXT PRIMARY KEY, project_id TEXT NOT NULL, parent_id TEXT, slug TEXT,
26+
directory TEXT NOT NULL DEFAULT '', title TEXT NOT NULL DEFAULT '', version TEXT,
27+
time_created INTEGER NOT NULL DEFAULT 0, time_updated INTEGER NOT NULL DEFAULT 0
28+
);
29+
CREATE TABLE IF NOT EXISTS message (
30+
id TEXT PRIMARY KEY, session_id TEXT NOT NULL,
31+
time_created INTEGER NOT NULL DEFAULT 0, time_updated INTEGER NOT NULL DEFAULT 0,
32+
data TEXT NOT NULL DEFAULT '{}'
33+
);
34+
CREATE TABLE IF NOT EXISTS part (
35+
id TEXT PRIMARY KEY, message_id TEXT NOT NULL, session_id TEXT NOT NULL,
36+
time_created INTEGER NOT NULL DEFAULT 0, time_updated INTEGER NOT NULL DEFAULT 0,
37+
data TEXT NOT NULL DEFAULT '{}'
38+
);
39+
CREATE TABLE IF NOT EXISTS todo (
40+
session_id TEXT NOT NULL, content TEXT NOT NULL DEFAULT '',
41+
status TEXT NOT NULL DEFAULT 'pending', priority TEXT NOT NULL DEFAULT 'medium',
42+
position INTEGER NOT NULL DEFAULT 0,
43+
time_created INTEGER NOT NULL DEFAULT 0, time_updated INTEGER NOT NULL DEFAULT 0
44+
);
45+
`);
46+
47+
db.close();
48+
console.log(`CI test database created at ${dbPath}`);

0 commit comments

Comments
 (0)