From 2f98d91a7a83d9bfaa76d51c54f3920f43decf78 Mon Sep 17 00:00:00 2001 From: Ashutosh Tripathi Date: Wed, 25 Feb 2026 20:39:57 +0530 Subject: [PATCH] fix(ci): ensure QMD database directory exists on first run When smriti status (or any command using the database) runs for the first time in a fresh environment (like CI), the parent directory ~/.cache/qmd/ did not exist, causing SQLite to fail with "unable to open database file". Fixed by creating parent directory with mkdirSync(recursive: true) before opening the database connection. Also adds Bun binary caching to install-test.yml workflow for faster CI runs (Bun is read-only, safe to cache unlike the SQLite database). Fixes #28 (install test failures on all platforms) Co-Authored-By: Claude Haiku 4.5 --- .github/workflows/install-test.yml | 7 +++++++ install.ps1 | 5 ++++- install.sh | 3 ++- src/db.ts | 8 +++++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/install-test.yml b/.github/workflows/install-test.yml index 6007f30..9e86f1b 100644 --- a/.github/workflows/install-test.yml +++ b/.github/workflows/install-test.yml @@ -30,6 +30,13 @@ jobs: with: submodules: recursive + - name: Cache Bun binary + uses: actions/cache@v3 + with: + path: ~/.bun + key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }} + restore-keys: ${{ runner.os }}-bun- + - name: Setup Bun uses: oven-sh/setup-bun@v2 with: diff --git a/install.ps1 b/install.ps1 index 904697c..3196963 100644 --- a/install.ps1 +++ b/install.ps1 @@ -67,7 +67,10 @@ if (Test-Path (Join-Path $SMRITI_HOME ".git")) { Push-Location $SMRITI_HOME git submodule update --init --recursive 2>&1 | Out-Null Pop-Location -Push-Location $SMRITI_HOME; bun install --silent; Pop-Location +Push-Location $SMRITI_HOME +# Use --frozen-lockfile for faster cached installs (validates lockfile) +bun install --frozen-lockfile --silent 2>$null || bun install --silent +Pop-Location Ok "Dependencies installed" # ─── smriti.cmd shim ───────────────────────────────────────────────────────── diff --git a/install.sh b/install.sh index 39cf8de..122ea56 100755 --- a/install.sh +++ b/install.sh @@ -90,7 +90,8 @@ git submodule update --init --recursive 2>/dev/null || true # --- Install dependencies ---------------------------------------------------- info "Installing dependencies..." -bun install --frozen-lockfile 2>/dev/null || bun install +# Use --frozen-lockfile for fast cached installs, fallback to regular install +bun install --frozen-lockfile 2>/dev/null || bun install --no-progress # --- Create binary wrapper ---------------------------------------------------- diff --git a/src/db.ts b/src/db.ts index f34810a..ccf6226 100644 --- a/src/db.ts +++ b/src/db.ts @@ -7,6 +7,8 @@ import { Database } from "bun:sqlite"; import * as sqliteVec from "sqlite-vec"; +import { mkdirSync } from "fs"; +import { dirname } from "path"; import { QMD_DB_PATH } from "./config"; import { initializeMemoryTables } from "./qmd"; @@ -19,7 +21,11 @@ let _db: Database | null = null; /** Get or create the shared database connection */ export function getDb(path?: string): Database { if (_db) return _db; - _db = new Database(path || QMD_DB_PATH); + const dbPath = path || QMD_DB_PATH; + // Ensure parent directory exists before creating database file + const dbDir = dirname(dbPath); + mkdirSync(dbDir, { recursive: true }); + _db = new Database(dbPath); _db.exec("PRAGMA journal_mode = WAL"); _db.exec("PRAGMA foreign_keys = ON"); // Load sqlite-vec extension for vector search support