refactor(T11521): route sqlite.ts tasks.db through openDualScopeDb (E6-L1)#884
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getDb()andgetNativeTasksDb()inpackages/core/src/store/sqlite.tsare now thin facades callingopenDualScopeDb('project', cwd)— the canonical dual-scope chokepoint (ADR-068/069, T11512/T11517)drizzle-tasksmigrations still run against the sharedcleo.dbhandle during the E3→E6 transition, co-creating the oldtaskstable family alongside the newtasks_tasksprefix tablesscripts/lint-no-direct-db-open.mjs) stays at 0 violationsraw new DatabaseSync()was not present insqlite.ts(it usedopenNativeDatabase); the E6-L1 change routes that entire init throughopenDualScopeDbinsteadgetDb()/getNativeDb()/getNativeTasksDb()compile and typecheck unchangedChanges
packages/core/src/store/sqlite.ts— rewrittengetDb()to delegate toopenDualScopeDb('project', cwd), extract$client(native handle), re-wrap with legacy tasks-schema drizzle, and run legacy migrations;getNativeTasksDb()now delegates togetNativeDb()with explicit E6-L1 façade note; removes directopenNativeDatabaseinit fromgetDb()Test plan
pnpm biome check --write— 0 errorspnpm run typecheck(tsc -b) — 0 errorspnpm run build— successnode packages/cleo/dist/cli/index.js version— smoke passesnode scripts/lint-no-direct-db-open.mjs— 0 violationssqlite-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)npx vitest run --project @cleocode/core— running in CIPart of E6 store rewrite (saga T11242, epic T11249).
🤖 Generated with Claude Code