mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-11 12:03:31 +08:00
fix: replace better-sqlite3 with sql.js to eliminate native module CI failures
better-sqlite3 requires native C++ compilation (node-gyp, prebuild-install) which fails in CI across npm/pnpm on all platforms: - npm ci: lock file out of sync with native transitive deps - pnpm: native bindings not found at runtime - Windows: native compilation fails entirely sql.js is a pure JavaScript/WASM SQLite implementation with zero native dependencies. The adapter in index.js wraps the sql.js API to match the better-sqlite3 interface used by migrations.js and queries.js. Key implementation detail: sql.js db.export() implicitly ends active transactions, so the adapter defers disk writes (saveToDisk) until after transaction commit via an inTransaction guard flag. createStateStore is now async (sql.js requires async WASM init). Updated status.js, sessions-cli.js, and tests accordingly.
This commit is contained in:
@@ -17,9 +17,9 @@ const ECC_SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'ecc.js');
|
||||
const STATUS_SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'status.js');
|
||||
const SESSIONS_SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'sessions-cli.js');
|
||||
|
||||
function test(name, fn) {
|
||||
async function test(name, fn) {
|
||||
try {
|
||||
fn();
|
||||
await fn();
|
||||
console.log(` \u2713 ${name}`);
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -52,8 +52,8 @@ function parseJson(stdout) {
|
||||
return JSON.parse(stdout.trim());
|
||||
}
|
||||
|
||||
function seedStore(dbPath) {
|
||||
const store = createStateStore({ dbPath });
|
||||
async function seedStore(dbPath) {
|
||||
const store = await createStateStore({ dbPath });
|
||||
|
||||
store.upsertSession({
|
||||
id: 'session-active',
|
||||
@@ -252,20 +252,20 @@ function seedStore(dbPath) {
|
||||
store.close();
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
async function runTests() {
|
||||
console.log('\n=== Testing state-store ===\n');
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
if (test('creates the default state.db path and applies migrations idempotently', () => {
|
||||
if (await test('creates the default state.db path and applies migrations idempotently', async () => {
|
||||
const homeDir = createTempDir('ecc-state-home-');
|
||||
|
||||
try {
|
||||
const expectedPath = path.join(homeDir, '.claude', 'ecc', 'state.db');
|
||||
assert.strictEqual(resolveStateStorePath({ homeDir }), expectedPath);
|
||||
|
||||
const firstStore = createStateStore({ homeDir });
|
||||
const firstStore = await createStateStore({ homeDir });
|
||||
const firstMigrations = firstStore.getAppliedMigrations();
|
||||
firstStore.close();
|
||||
|
||||
@@ -273,7 +273,7 @@ function runTests() {
|
||||
assert.strictEqual(firstMigrations[0].version, 1);
|
||||
assert.ok(fs.existsSync(expectedPath));
|
||||
|
||||
const secondStore = createStateStore({ homeDir });
|
||||
const secondStore = await createStateStore({ homeDir });
|
||||
const secondMigrations = secondStore.getAppliedMigrations();
|
||||
secondStore.close();
|
||||
|
||||
@@ -284,7 +284,7 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('preserves SQLite special database names like :memory:', () => {
|
||||
if (await test('preserves SQLite special database names like :memory:', async () => {
|
||||
const tempDir = createTempDir('ecc-state-memory-');
|
||||
const previousCwd = process.cwd();
|
||||
|
||||
@@ -292,7 +292,7 @@ function runTests() {
|
||||
process.chdir(tempDir);
|
||||
assert.strictEqual(resolveStateStorePath({ dbPath: ':memory:' }), ':memory:');
|
||||
|
||||
const store = createStateStore({ dbPath: ':memory:' });
|
||||
const store = await createStateStore({ dbPath: ':memory:' });
|
||||
assert.strictEqual(store.dbPath, ':memory:');
|
||||
assert.strictEqual(store.getAppliedMigrations().length, 1);
|
||||
store.close();
|
||||
@@ -304,14 +304,14 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('stores sessions and returns detailed session views with workers, skill runs, and decisions', () => {
|
||||
if (await test('stores sessions and returns detailed session views with workers, skill runs, and decisions', async () => {
|
||||
const testDir = createTempDir('ecc-state-db-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
seedStore(dbPath);
|
||||
await seedStore(dbPath);
|
||||
|
||||
const store = createStateStore({ dbPath });
|
||||
const store = await createStateStore({ dbPath });
|
||||
const listResult = store.listRecentSessions({ limit: 10 });
|
||||
const detail = store.getSessionDetail('session-active');
|
||||
store.close();
|
||||
@@ -328,14 +328,14 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('builds a status snapshot with active sessions, skill rates, install health, and pending governance', () => {
|
||||
if (await test('builds a status snapshot with active sessions, skill rates, install health, and pending governance', async () => {
|
||||
const testDir = createTempDir('ecc-state-db-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
seedStore(dbPath);
|
||||
await seedStore(dbPath);
|
||||
|
||||
const store = createStateStore({ dbPath });
|
||||
const store = await createStateStore({ dbPath });
|
||||
const status = store.getStatus();
|
||||
store.close();
|
||||
|
||||
@@ -354,12 +354,12 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('validates entity payloads before writing to the database', () => {
|
||||
if (await test('validates entity payloads before writing to the database', async () => {
|
||||
const testDir = createTempDir('ecc-state-db-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
const store = createStateStore({ dbPath });
|
||||
const store = await createStateStore({ dbPath });
|
||||
assert.throws(() => {
|
||||
store.upsertSession({
|
||||
id: '',
|
||||
@@ -404,12 +404,12 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('status CLI supports human-readable and --json output', () => {
|
||||
if (await test('status CLI supports human-readable and --json output', async () => {
|
||||
const testDir = createTempDir('ecc-state-cli-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
seedStore(dbPath);
|
||||
await seedStore(dbPath);
|
||||
|
||||
const jsonResult = runNode(STATUS_SCRIPT, ['--db', dbPath, '--json']);
|
||||
assert.strictEqual(jsonResult.status, 0, jsonResult.stderr);
|
||||
@@ -428,12 +428,12 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('sessions CLI supports list and detail views in human-readable and --json output', () => {
|
||||
if (await test('sessions CLI supports list and detail views in human-readable and --json output', async () => {
|
||||
const testDir = createTempDir('ecc-state-cli-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
seedStore(dbPath);
|
||||
await seedStore(dbPath);
|
||||
|
||||
const listJsonResult = runNode(SESSIONS_SCRIPT, ['--db', dbPath, '--json']);
|
||||
assert.strictEqual(listJsonResult.status, 0, listJsonResult.stderr);
|
||||
@@ -460,12 +460,12 @@ function runTests() {
|
||||
}
|
||||
})) passed += 1; else failed += 1;
|
||||
|
||||
if (test('ecc CLI delegates the new status and sessions subcommands', () => {
|
||||
if (await test('ecc CLI delegates the new status and sessions subcommands', async () => {
|
||||
const testDir = createTempDir('ecc-state-cli-');
|
||||
const dbPath = path.join(testDir, 'state.db');
|
||||
|
||||
try {
|
||||
seedStore(dbPath);
|
||||
await seedStore(dbPath);
|
||||
|
||||
const statusResult = runNode(ECC_SCRIPT, ['status', '--db', dbPath, '--json']);
|
||||
assert.strictEqual(statusResult.status, 0, statusResult.stderr);
|
||||
|
||||
Reference in New Issue
Block a user