Skip to content

Commit fd649fd

Browse files
committed
Replace JSON-backed Local DB with SQLite behind API boundary - PR_26158_027-sqlite-local-db
1 parent c57656a commit fd649fd

9 files changed

Lines changed: 292 additions & 83 deletions
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
1-
# PR_26158_026 Browser Mock Remaining Audit
1+
# PR_26158_027 Browser Mock Remaining Audit
22

33
## Scope
44

5-
Focused audit for enabling Local DB read-only inspection through Admin DB Viewer:
5+
Focused audit for replacing Local DB JSON storage with SQLite behind the server API boundary:
66

7-
- `admin/db-viewer.html`
8-
- `admin/db-viewer.js`
9-
- `src/engine/api/mock-db-api-client.js`
10-
- `src/engine/api/mock-db-viewer-ui.js`
7+
- `src/dev-runtime/server/mock-api-router.mjs`
8+
- `src/dev-runtime/persistence/mock-db-store.js`
119
- `tests/playwright/tools/AdminDbViewer.spec.mjs`
10+
- `tests/playwright/tools/LoginSessionMode.spec.mjs`
1211

1312
## Static Import Boundary
1413

1514
| Check | Status | Evidence |
1615
| --- | --- | --- |
17-
| Browser files import `src/dev-runtime` directly. | PASS | `rg -n 'src/dev-runtime' admin assets toolbox src -g '*.js' -g '*.mjs' -g '!src/dev-runtime/**' -g '!**/*-mock-repository.js' ...` returned no matches. |
18-
| Browser files import mock repositories directly. | PASS | `rg -n 'mock-.*repository|LocalDbAdapter|DB implementation' ...` excluding repository implementation files returned no matches. |
19-
| Browser files import `LocalDbAdapter` or DB implementation modules directly. | PASS | Same focused `rg` returned no browser matches. |
16+
| Browser files import `node:sqlite` directly. | PASS | Focused `rg` for `node:sqlite` outside `src/dev-runtime/**` returned no matches. |
17+
| Browser files import `DatabaseSync` directly. | PASS | Focused `rg` for `DatabaseSync` outside `src/dev-runtime/**` returned no matches. |
18+
| Browser files import `LocalDbAdapter` directly. | PASS | Focused `rg` for `LocalDbAdapter` outside `src/dev-runtime/**` returned no matches. |
19+
| Browser files import `src/dev-runtime` directly. | PASS | Focused `rg` excluding dev-runtime and repository implementation files returned no matches. |
20+
| Browser files import mock repositories directly. | PASS | Focused `rg` excluding repository implementation files returned no matches. |
2021

21-
## Local DB Viewer Boundary
22+
## SQLite Boundary
2223

2324
| Check | Status | Evidence |
2425
| --- | --- | --- |
25-
| Browser flow remains Browser -> API client -> server API -> data source. | PASS | DB Viewer still uses `src/engine/api/mock-db-api-client.js` and `/api/mock-db/snapshot`; no browser Local DB imports were added. |
26-
| Local Mem behavior is preserved. | PASS | AdminDbViewer Playwright retained Local Mem clear/seed, filters, diagnostics, and live persisted tool-record coverage. |
27-
| Local DB behavior is read-only. | PASS | AdminDbViewer Playwright asserts no Local DB clear/seed/write controls are visible or available. |
28-
| Local DB renders live server-backed adapter state. | PASS | Playwright and API contract probe mutate/read server state through API routes and verify DB Viewer output. |
29-
| Local DB missing storage fails visibly. | PASS | Playwright and API contract probe assert `Local DB adapter not configured` diagnostics. |
30-
| UAT/Prod are not local login choices. | PASS | `/api/session/modes` probe returned exactly `Local Mem` and `Local DB`; UAT/Prod remain server-side deployment metadata only. |
26+
| Local DB remains behind the server API boundary only. | PASS | SQLite is imported only in `src/dev-runtime/server/mock-api-router.mjs`; browser callers continue through `/api/session/*` and `/api/mock-db/*`. |
27+
| Local Mem behavior is preserved. | PASS | AdminDbViewer Local Mem Playwright coverage passed. |
28+
| Admin DB Viewer Local DB read-only inspection is preserved. | PASS | AdminDbViewer Local DB Playwright coverage passed against SQLite-backed state. |
29+
| Local DB initializes required tables deterministically. | PASS | SQLite contract probe inspected physical SQLite tables and schema columns. |
30+
| Empty tables remain visible with headers. | PASS | SQLite contract probe and AdminDbViewer Playwright verified empty table schemas/headers. |
31+
| SQLite initialization/read/write/snapshot failures fail visibly. | PASS | Contract probe verified disabled snapshot and write diagnostics. |
32+
| UAT/Prod are not local login choices. | PASS | `/api/session/modes` probe in SQLite contract validation returned `Local Mem|Local DB`; UAT/Prod remain server-side deployment metadata only. |
3133

3234
## Remaining Internal Matches
3335

3436
- UAT/Prod strings remain only in the server adapter contract as deployment-only metadata.
35-
- `toolbox/*/*-mock-repository.js` and `toolbox/colors/palette-workspace-repository.js` remain server/data-source implementation modules, not active browser entry imports.
37+
- `node:sqlite` currently emits a Node experimental warning during validation; no browser bundle or user-facing page imports it.
3638
- `/api/mock-db/*` route names and `mock-db-*` module filenames remain stable internal API contracts.

docs_build/dev/reports/coverage_changed_js_guardrail.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Source: Playwright/Chromium built-in V8 coverage from the active Playwright run.
88
Changed runtime JS files considered:
99
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
1010
(0%) src/dev-runtime/server/mock-api-router.mjs - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
11-
(96%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 92/96
12-
(100%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 5/5
11+
(60%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 3/5
12+
(85%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 82/96
1313

1414
Guardrail warnings:
1515
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file missing from coverage; advisory only

docs_build/dev/reports/playwright_v8_coverage_report.txt

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,27 @@ Note: entry percentages use function coverage when available, otherwise line cov
1212
Note: coverage entries are aggregated across every page/tool where coverageReporter.start(page) and coverageReporter.stop(page) ran.
1313

1414
Exercised tool entry points detected:
15-
(77%) Toolbox Index - exercised 7 runtime JS files
15+
(61%) Toolbox Index - exercised 3 runtime JS files
1616
(0%) Tool Template V2 - not exercised by this Playwright run
17-
(75%) Theme V2 Shared JS - exercised 2 runtime JS files
17+
(84%) Theme V2 Shared JS - exercised 3 runtime JS files
1818

1919
Changed runtime JS files covered:
2020
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
2121
(0%) src/dev-runtime/server/mock-api-router.mjs - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
22-
(96%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 92/96
23-
(100%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 5/5
22+
(60%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 3/5
23+
(85%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 82/96
2424

2525
Files with executed line/function counts where available:
26+
(55%) toolbox/project-journey/project-journey.js - executed lines 1003/1003; executed functions 54/99
27+
(56%) src/engine/api/server-api-client.js - executed lines 154/154; executed functions 10/18
28+
(60%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 3/5
2629
(64%) assets/theme-v2/js/tool-display-mode.js - executed lines 201/201; executed functions 9/14
2730
(67%) admin/db-viewer.js - executed lines 53/53; executed functions 4/6
28-
(67%) src/engine/api/server-api-client.js - executed lines 154/154; executed functions 12/18
29-
(69%) toolbox/colors/colors.js - executed lines 877/877; executed functions 62/90
30-
(75%) toolbox/project-journey/project-journey.js - executed lines 1003/1003; executed functions 74/99
31-
(78%) assets/theme-v2/js/gamefoundry-partials.js - executed lines 415/415; executed functions 29/37
3231
(81%) toolbox/tool-registry-api-client.js - executed lines 148/148; executed functions 22/27
33-
(88%) toolbox/assets/assets.js - executed lines 519/519; executed functions 53/60
34-
(96%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 92/96
35-
(100%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 5/5
36-
(100%) toolbox/assets/assets-api-client.js - executed lines 17/17; executed functions 3/3
37-
(100%) toolbox/colors/palette-api-client.js - executed lines 19/19; executed functions 4/4
32+
(85%) src/engine/api/mock-db-viewer-ui.js - executed lines 510/510; executed functions 82/96
33+
(86%) assets/theme-v2/js/gamefoundry-partials.js - executed lines 415/415; executed functions 32/37
34+
(88%) src/engine/api/session-api-client.js - executed lines 34/34; executed functions 7/8
35+
(94%) assets/theme-v2/js/login-session.js - executed lines 163/163; executed functions 15/16
3836
(100%) toolbox/project-journey/project-journey-api-client.js - executed lines 12/12; executed functions 2/2
3937

4038
Uncovered or low-coverage changed JS files:
@@ -46,6 +44,6 @@ Changed JS files considered:
4644
(0%) src/dev-runtime/server/mock-api-router.mjs - changed JS file not collected as browser runtime coverage
4745
(0%) tests/playwright/tools/AdminDbViewer.spec.mjs - changed JS file not collected as browser runtime coverage
4846
(0%) tests/playwright/tools/LoginSessionMode.spec.mjs - changed JS file not collected as browser runtime coverage
47+
(60%) src/engine/api/mock-db-api-client.js - changed JS file with browser V8 coverage
4948
(67%) admin/db-viewer.js - changed JS file with browser V8 coverage
50-
(96%) src/engine/api/mock-db-viewer-ui.js - changed JS file with browser V8 coverage
51-
(100%) src/engine/api/mock-db-api-client.js - changed JS file with browser V8 coverage
49+
(85%) src/engine/api/mock-db-viewer-ui.js - changed JS file with browser V8 coverage
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# PR_26158_027 SQLite Local DB Report
2+
3+
## Executive Summary
4+
5+
Replaced the server-side JSON-backed Local DB adapter with a real SQLite-backed Local DB adapter using Node's `node:sqlite` runtime. Browser code remains on the existing server API boundary, Local Mem behavior is unchanged, and Admin DB Viewer continues to inspect Local DB in read-only mode through `/api/mock-db/snapshot`.
6+
7+
## Requirement Checklist
8+
9+
| Requirement | Status | Evidence |
10+
| --- | --- | --- |
11+
| Read `docs_build/dev/PROJECT_INSTRUCTIONS.md` first. | PASS | Instructions were read before implementation. |
12+
| Replace JSON-backed Local DB with real SQLite-backed Local DB. | PASS | `src/dev-runtime/server/mock-api-router.mjs` imports `node:sqlite` and persists Local DB state into physical SQLite tables. |
13+
| Keep Local DB behind server API boundary only. | PASS | SQLite implementation lives under `src/dev-runtime/server`; browser files continue to call server API clients/routes only. |
14+
| Browser code must not import SQLite, DB repositories, dev-runtime persistence, or DB implementation modules directly. | PASS | Static boundary checks returned no browser matches for `node:sqlite`, `DatabaseSync`, `LocalDbAdapter`, `src/dev-runtime`, or mock repositories. |
15+
| Preserve Local Mem behavior unchanged. | PASS | AdminDbViewer Local Mem Playwright coverage passed. |
16+
| Preserve Admin DB Viewer read-only Local DB inspection through API. | PASS | AdminDbViewer Local DB Playwright coverage passed with no write controls visible. |
17+
| Local DB initializes required tables/schemas deterministically. | PASS | SQLite contract probe verified physical SQLite tables and schema columns. |
18+
| Empty tables remain visible with headers in Admin DB Viewer. | PASS | SQLite contract probe and AdminDbViewer Playwright verified empty tables and headers. |
19+
| Initialization, read, write, and snapshot failures fail visibly with actionable diagnostics. | PASS | Contract probe verified disabled SQLite snapshot/write diagnostics with `Local DB adapter not configured`, `SQLite`, and `GAMEFOUNDRY_LOCAL_DB_DISABLE`. |
20+
| Do not add UAT/Prod API adapter behavior. | PASS | UAT/Prod remain deployment-only metadata; no UAT/Prod adapter implementation was added. |
21+
| Do not expose UAT or Prod as local login choices. | PASS | `/api/session/modes` validation returned only `Local Mem` and `Local DB`. |
22+
| Do not modify `start_of_day` folders. | PASS | No `start_of_day` files changed. |
23+
24+
## Implementation Notes
25+
26+
| Area | Evidence |
27+
| --- | --- |
28+
| SQLite adapter | `LocalDbAdapter` now opens `DatabaseSync`, initializes `__gf_metadata`, creates one SQLite table per known mock DB table, adds deterministic schema columns, and stores JSON-encoded cell values to preserve booleans/arrays/objects. |
29+
| Default storage | Local DB defaults to `tmp/local-db/local-db-state.sqlite`; `GAMEFOUNDRY_LOCAL_DB_PATH` still overrides it for tests and local diagnostics. |
30+
| Failure diagnostics | `GAMEFOUNDRY_LOCAL_DB_DISABLE=1` blocks initialization/read/write and returns visible server API diagnostics. |
31+
| Session mode copy | Local DB description now says `Uses LocalDbAdapter backed by server SQLite storage.` |
32+
| Tests | AdminDbViewer and LoginSessionMode test storage paths now use `.sqlite` files. |
33+
34+
## Validation Evidence
35+
36+
| Validation | Result |
37+
| --- | --- |
38+
| Changed-file syntax checks | PASS |
39+
| Local DB/API SQLite contract validation | PASS |
40+
| AdminDbViewer Playwright | PASS, 7/7 |
41+
| LoginSessionMode Playwright | PASS, 5/5 |
42+
| Static import boundary audit | PASS |
43+
| Active source/test JSON-backed wording check | PASS |
44+
| `git diff --check` | PASS, Git line-ending warnings only |
45+
46+
## Remaining Migration Notes
47+
48+
- Node emitted its standard experimental warning for `node:sqlite`; the implementation remains server/dev-runtime only and does not affect browser bundles.
49+
- UAT/Prod remain deployment-only adapter contract metadata and were not implemented in this PR.
Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
1-
# PR_26158_026 Testing Lane Execution Report
1+
# PR_26158_027 Testing Lane Execution Report
22

33
## Lanes Run
44

55
| Lane | Command | Result |
66
| --- | --- | --- |
7-
| Changed-file syntax | `node --check admin/db-viewer.js`; `node --check src/engine/api/mock-db-api-client.js`; `node --check src/engine/api/mock-db-viewer-ui.js`; `node --check tests/playwright/tools/AdminDbViewer.spec.mjs` | PASS |
8-
| Local DB/API snapshot contract validation | Custom Node probe using `tests/helpers/playwrightRepoServer.mjs` with isolated `GAMEFOUNDRY_LOCAL_DB_PATH=tmp/local-db/pr_026_snapshot_contract.json` | PASS |
7+
| Changed-file syntax | `node --check src/dev-runtime/server/mock-api-router.mjs`; `node --check src/dev-runtime/persistence/mock-db-store.js`; `node --check tests/playwright/tools/AdminDbViewer.spec.mjs`; `node --check tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS |
8+
| Local DB/API SQLite contract validation | Custom Node probe using `tests/helpers/playwrightRepoServer.mjs`, `node:sqlite`, and isolated `GAMEFOUNDRY_LOCAL_DB_PATH=tmp/local-db/pr_027_sqlite_contract.sqlite` | PASS |
99
| AdminDbViewer Playwright | `npx playwright test tests/playwright/tools/AdminDbViewer.spec.mjs` | PASS, 7/7 |
10-
| Local login mode check | Custom Node probe of `/api/session/modes` | PASS |
11-
| Static import boundary | Focused `rg` checks for forbidden browser imports of `src/dev-runtime`, mock repositories, `LocalDbAdapter`, and DB implementation modules | PASS |
10+
| LoginSessionMode Playwright | `npx playwright test tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS, 5/5 |
11+
| Static import boundary | Focused `rg` checks for forbidden browser imports of `node:sqlite`, `DatabaseSync`, `LocalDbAdapter`, `src/dev-runtime`, and mock repositories | PASS |
12+
| Active source/test JSON-backed Local DB wording check | Focused `rg` for `JSON storage`, `server local JSON`, `local JSON`, and `.json` in active Local DB source/tests | PASS; only normal `response.json()` calls matched |
1213
| Changed-file/static validation | `git diff --check` | PASS, with Git line-ending warnings only |
1314

14-
## Local DB/API Snapshot Contract Probe
15+
## Local DB/API SQLite Contract Probe
1516

1617
| Assertion | Result |
1718
| --- | --- |
18-
| Local Mem snapshot loads through `/api/mock-db/snapshot`. | PASS |
19-
| Local Mem empty tables expose schemas. | PASS |
20-
| Local DB mode selects through `/api/session/mode`. | PASS |
21-
| Local DB Admin resolves through users/roles/user_roles. | PASS |
22-
| Local DB snapshot loads through `/api/mock-db/snapshot`. | PASS |
23-
| Local DB renders live adapter state from the shared server API. | PASS |
24-
| Local DB empty tables expose schemas. | PASS |
25-
| Guest is not stored in Local DB `users`. | PASS |
26-
| Disabled Local DB snapshot fails visibly with `Local DB adapter not configured` and `GAMEFOUNDRY_LOCAL_DB_DISABLE`. | PASS |
19+
| Local login choices remain exactly `Local Mem` and `Local DB`. | PASS |
20+
| Local DB mode description names SQLite storage. | PASS |
21+
| Local DB mode initializes SQLite storage through `/api/session/mode`. | PASS |
22+
| Local DB resolves Admin through SQLite-backed users/roles/user_roles data. | PASS |
23+
| `/api/mock-db/snapshot` reads SQLite-backed Local DB state. | PASS |
24+
| Local DB snapshot includes schemas and empty tables. | PASS |
25+
| Guest is not stored in SQLite `users`. | PASS |
26+
| Physical SQLite tables are initialized for `users`, `roles`, `user_roles`, `palette_colors`, `asset_library_items`, and `project_journey_items`. | PASS |
27+
| SQLite table columns include deterministic schema fields such as `key`, `createdAt`, and `updatedBy`. | PASS |
28+
| SQLite-backed writes through `/api/dev/testing/mock-db-state` persist and appear in snapshots. | PASS |
29+
| SQLite-backed data persists across server restart with the same DB file. | PASS |
30+
| Disabled SQLite snapshot fails visibly with `Local DB adapter not configured`, `SQLite`, and `GAMEFOUNDRY_LOCAL_DB_DISABLE`. | PASS |
31+
| Disabled SQLite write fails visibly with actionable diagnostic text. | PASS |
2732

2833
## Playwright Coverage
2934

30-
AdminDbViewer now covers:
35+
AdminDbViewer covers:
3136

3237
- Existing Local Mem DB Viewer behavior.
33-
- Local DB read-only display with active mode text.
34-
- Local DB empty table schema/header rendering.
38+
- SQLite-backed Local DB read-only display.
39+
- Local DB empty-table schema/header rendering.
3540
- Local DB live adapter state rendering.
3641
- Local DB unavailable diagnostic rendering.
3742
- Absence of Local DB write controls.
3843

39-
`docs_build/dev/reports/playwright_v8_coverage_report.txt` was regenerated by the targeted Playwright run.
44+
LoginSessionMode covers:
45+
46+
- Local DB login mode copy updated to SQLite.
47+
- Local DB session user selection through server API.
48+
- Direct admin DB Viewer URL access in Local DB mode.
49+
50+
`docs_build/dev/reports/playwright_v8_coverage_report.txt` was regenerated by the targeted Playwright runs. Node emitted the standard experimental warning for `node:sqlite`; validation passed.
4051

4152
## Skipped Lanes
4253

4354
| Lane | Decision | Reason |
4455
| --- | --- | --- |
45-
| LoginSessionMode Playwright | SKIP | No login/session mode source files were changed. A focused `/api/session/modes` probe verified Local Mem and Local DB remain the only local choices. |
4656
| Full samples smoke | SKIP | No shared sample loader/framework or sample JSON changed. |
47-
| Full Playwright suite | SKIP | Targeted Admin DB Viewer, server snapshot contract, local mode check, and static import checks cover the changed surfaces. |
57+
| Full Playwright suite | SKIP | Targeted SQLite contract, Admin DB Viewer, LoginSessionMode, and static import checks cover the changed surfaces. |

src/dev-runtime/persistence/mock-db-store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const MOCK_DB_SESSION_MODES = Object.freeze([
5858
adapterId: "local-db",
5959
adapterName: "LocalDbAdapter",
6060
configured: true,
61-
description: "Uses LocalDbAdapter backed by server local JSON storage.",
61+
description: "Uses LocalDbAdapter backed by server SQLite storage.",
6262
environment: "Local DB",
6363
id: "local-db",
6464
label: "Local DB",

0 commit comments

Comments
 (0)