Skip to content

refactor(T11521): route sqlite.ts tasks.db through openDualScopeDb (E6-L1)#884

Merged
kryptobaseddev merged 8 commits into
mainfrom
task/T11521-e6-sqlite
Jun 1, 2026
Merged

refactor(T11521): route sqlite.ts tasks.db through openDualScopeDb (E6-L1)#884
kryptobaseddev merged 8 commits into
mainfrom
task/T11521-e6-sqlite

Conversation

@kryptobaseddev
Copy link
Copy Markdown
Owner

Summary

  • getDb() and getNativeTasksDb() in packages/core/src/store/sqlite.ts are now thin facades calling openDualScopeDb('project', cwd) — the canonical dual-scope chokepoint (ADR-068/069, T11512/T11517)
  • The legacy drizzle-tasks migrations still run against the shared cleo.db handle during the E3→E6 transition, co-creating the old tasks table family alongside the new tasks_tasks prefix tables
  • DB Open Guard Gate 3 (scripts/lint-no-direct-db-open.mjs) stays at 0 violations
  • raw new DatabaseSync() was not present in sqlite.ts (it used openNativeDatabase); the E6-L1 change routes that entire init through openDualScopeDb instead
  • All 60+ existing callers of getDb() / getNativeDb() / getNativeTasksDb() compile and typecheck unchanged

Changes

  • packages/core/src/store/sqlite.ts — rewritten getDb() to delegate to openDualScopeDb('project', cwd), extract $client (native handle), re-wrap with legacy tasks-schema drizzle, and run legacy migrations; getNativeTasksDb() now delegates to getNativeDb() with explicit E6-L1 façade note; removes direct openNativeDatabase init from getDb()

Test plan

  • pnpm biome check --write — 0 errors
  • pnpm run typecheck (tsc -b) — 0 errors
  • pnpm run build — success
  • node packages/cleo/dist/cli/index.js version — smoke passes
  • node scripts/lint-no-direct-db-open.mjs — 0 violations
  • Key store tests: sqlite-lazy-init.test.ts, db-helpers.test.ts, dual-scope-db.test.ts, open-cleo-db.test.ts, task-labels-junction.test.ts, sqlite-backup.test.ts, auto-recovery-chokepoint.test.ts — all pass (39+20 = 59 tests)
  • Full npx vitest run --project @cleocode/core — running in CI

Part of E6 store rewrite (saga T11242, epic T11249).

🤖 Generated with Claude Code

kryptobaseddev and others added 8 commits May 31, 2026 12:08
…6-L1)

getDb() and getNativeTasksDb() are now thin facades calling openDualScopeDb('project', cwd) — the canonical dual-scope chokepoint (ADR-068/069). The legacy drizzle-tasks migrations still run against the cleo.db handle during the E3→E6 transition, co-creating the old 'tasks' table family alongside the new 'tasks_tasks' prefix tables. DB Open Guard Gate 3 stays green (0 violations). All existing callers compile unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…eo.db path corrections

Three issues caused CI test failures after the dual-scope chokepoint migration:

1. **Stale dual-scope cache** — `closeDb()` and `resetDbState()` closed
   `_nativeDb` (the DatabaseSync) but left the dual-scope cache entry intact.
   The next `openDualScopeDb()` call returned the stale cached handle whose
   `DatabaseSync` was already closed, producing "database is not open" in
   `runMigrations → tableExists`. Fix: call `_resetDualScopeDbCache()` in
   both `closeDb` and `resetDbState` so the next `getDb()` opens a fresh
   handle. Also call it in `autoRecoverFromBackup` when the nativeDb is
   closed for restore.

2. **`dbExists()` checked wrong file** — `dbExists()` tested for `tasks.db`
   but `getDb()` now opens `cleo.db` via `openDualScopeDb`. This caused
   `migrateJsonToSqlite` to incorrectly skip the "already migrated" guard.
   Fix: update `dbExists()` to check `resolveDualScopeDbPath('project', cwd)`
   (`cleo.db`) instead of the legacy `tasks.db` path.

3. **Test path references** — `migration-safety.test.ts` and
   `checksum.test.ts` checked for `tasks.db` existence after `getDb()`.
   Updated to check `cleo.db` with E6-L1 annotation comments.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alth probes + test fixtures (recover #884 FAIL5)

E6-L1 routed getDb() through openDualScopeDb('project') which opens cleo.db,
but getDbPath(), system/health.ts + project-health.ts probes, and 5 test
fixtures still hardcoded the legacy tasks.db path — producing 14 new failures
(sqlite/migration-smoke/health/project-health/migrate-containment) and a real
'cleo doctor' regression (tasks_db: not found on healthy projects).

- sqlite.ts getDbPath() now returns resolveDualScopeDbPath('project') (the file
  getDb actually opens); drop unused DB_FILENAME/resolveCleoDir/join.
- system/health.ts: tasks-domain integrity + audit_log + diagnostic probes
  target cleo.db.
- system/project-health.ts: TASKS_DB probe -> cleo.db; expected migration count
  -> drizzle-cleo-project (3). brain/conduit probes unchanged (E6-L2/L3).
- update health/project-health/migration-smoke/migrate-containment fixtures to
  cleo.db.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…haracterization

Second-order regression from the tasks.db→cleo.db move: ensureSqliteDb
checked existsSync(tasks.db) for idempotency, but getDb() now creates cleo.db,
so a repeat 'cleo init'/scaffoldProject re-reported the DB as 'created'
(scaffoldProject idempotency test + a real 'cleo init' twice regression).
Probe cleo.db instead; update the two ensureSqliteDb characterization tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kryptobaseddev kryptobaseddev merged commit 733f12f into main Jun 1, 2026
68 checks passed
@kryptobaseddev kryptobaseddev deleted the task/T11521-e6-sqlite branch June 1, 2026 07:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant