Skip to content

Commit c57656a

Browse files
committed
Enable readonly Local DB inspection in Admin DB Viewer through API - PR_26158_026-local-db-viewer-readonly
1 parent 6f2108f commit c57656a

10 files changed

Lines changed: 319 additions & 119 deletions

admin/db-viewer.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta charset="utf-8">
66
<base href="/">
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8-
<title>Local Mem DB - GameFoundryStudio</title>
9-
<meta name="description" content="Admin-only read-only Local Mem DB viewer for GameFoundryStudio project data diagnostics.">
8+
<title>DB Viewer - GameFoundryStudio</title>
9+
<meta name="description" content="Admin-only read-only DB viewer for GameFoundryStudio project data diagnostics.">
1010
<link rel="icon" href="/favicon.svg">
1111
<link rel="stylesheet" href="assets/theme-v2/css/theme.css">
1212
</head>
@@ -16,23 +16,23 @@
1616
<main data-admin-only="true">
1717
<section class="page-title">
1818
<div class="container">
19-
<div class="kicker">Admin Only / Local Mem DB</div>
20-
<h1>Local Mem DB</h1>
21-
<p class="lede">Read-only Local Mem DB dump for project tables, relationships, and data diagnostics.</p>
19+
<div class="kicker" data-admin-db-mode-kicker>Admin Only / Local Mem DB</div>
20+
<h1 data-admin-db-mode-title>Local Mem DB</h1>
21+
<p class="lede" data-admin-db-mode-description>Read-only Local Mem DB dump for project tables, relationships, and data diagnostics.</p>
2222
</div>
2323
</section>
2424
<section class="section">
2525
<div class="container container--tool-wide">
2626
<div class="tool-workspace tool-workspace--wide">
2727
<aside class="tool-column tool-group-build">
2828
<div class="tool-column-header">
29-
<h2>Local Mem DB</h2>
29+
<h2 data-admin-db-mode-title>Local Mem DB</h2>
3030
</div>
3131
<div class="accordion-stack">
3232
<details class="vertical-accordion" open>
3333
<summary>Scope</summary>
3434
<div class="accordion-body content-stack">
35-
<p>Current tool Local Mem DB records are displayed as a read-only human-readable dump.</p>
35+
<p data-admin-db-scope-description>Current tool Local Mem DB records are displayed as a read-only human-readable dump.</p>
3636
<p>Use the diagnostics panel to confirm table attribution, relationships, and table bleed checks.</p>
3737
<button class="btn btn--compact" type="button" data-admin-db-clear>Clear Local Mem DB</button>
3838
</div>
@@ -43,8 +43,8 @@ <h2>Local Mem DB</h2>
4343
<section class="tool-center-panel content-stack" aria-labelledby="admin-db-viewer-title" data-admin-db-viewer>
4444
<div class="content-cluster">
4545
<div>
46-
<div class="kicker">Local Mem DB</div>
47-
<h2 id="admin-db-viewer-title">Local Mem DB</h2>
46+
<div class="kicker" data-admin-db-mode-kicker>Local Mem DB</div>
47+
<h2 id="admin-db-viewer-title" data-admin-db-mode-title>Local Mem DB</h2>
4848
</div>
4949
<span class="status" role="status" data-admin-db-status>Loading Local Mem DB records.</span>
5050
</div>

admin/db-viewer.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,25 @@ function devRuntimeAllowed() {
66
host === "127.0.0.1";
77
}
88

9-
function localModeSelected() {
9+
function currentSession() {
1010
try {
1111
const request = new XMLHttpRequest();
1212
request.open("GET", "/api/session/current", false);
1313
request.setRequestHeader("Accept", "application/json");
1414
request.send(null);
1515
const payload = request.responseText ? JSON.parse(request.responseText) : null;
16-
return request.status >= 200 && request.status < 300 && payload?.data?.mode === "local-mem";
17-
} catch {
18-
return false;
16+
if (request.status >= 200 && request.status < 300 && payload?.data) {
17+
return payload.data;
18+
}
19+
return {
20+
diagnostic: payload?.error || "Unable to read current DB Viewer session from the server API.",
21+
mode: "",
22+
};
23+
} catch (error) {
24+
return {
25+
diagnostic: error instanceof Error ? error.message : String(error || "Unable to read current DB Viewer session."),
26+
mode: "",
27+
};
1928
}
2029
}
2130

@@ -31,17 +40,18 @@ async function loadLocalDbViewer() {
3140
return;
3241
}
3342
if (!devRuntimeAllowed()) {
34-
showGatewayStatus("Local Mem DB is available only in the local dev runtime.");
43+
showGatewayStatus("DB Viewer is available only in the local dev runtime.");
3544
return;
3645
}
37-
if (!localModeSelected()) {
38-
showGatewayStatus("Local Mem DB Viewer is available only in Local Mem mode.");
46+
const session = currentSession();
47+
if (session.mode !== "local-mem" && session.mode !== "local-db") {
48+
showGatewayStatus(session.diagnostic || "DB Viewer is available only in Local Mem or Local DB mode.");
3949
return;
4050
}
4151
const module = await import("../src/engine/api/mock-db-viewer-ui.js");
42-
module.startMockDbViewer(document);
52+
module.startMockDbViewer(document, { session });
4353
}
4454

4555
loadLocalDbViewer().catch((error) => {
46-
console.error("Unable to load Local Mem DB viewer.", error);
56+
console.error("Unable to load DB Viewer.", error);
4757
});
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
# PR_26158_025 Browser Mock Remaining Audit
1+
# PR_26158_026 Browser Mock Remaining Audit
22

33
## Scope
44

5-
Focused audit for the Local DB server adapter step:
5+
Focused audit for enabling Local DB read-only inspection through Admin DB Viewer:
66

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

1213
## Static Import Boundary
1314

1415
| Check | Status | Evidence |
1516
| --- | --- | --- |
16-
| 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' -g '!toolbox/colors/palette-workspace-repository.js' ...` returned no matches. |
17-
| Browser files import mock repositories directly. | PASS | `rg -n 'mock-.*repository' ...` excluding repository implementation files returned no matches. |
18-
| Browser files import static `toolRegistry.js` directly. | PASS | `rg -n 'import .*toolRegistry\\.js|from .*toolRegistry\\.js|import\\(.*toolRegistry\\.js' ...` returned no matches. |
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. |
1920

20-
## Local DB Boundary
21+
## Local DB Viewer Boundary
2122

2223
| Check | Status | Evidence |
2324
| --- | --- | --- |
24-
| Browser flow remains Browser -> API client -> server API -> data source. | PASS | Local DB implementation lives in `src/dev-runtime/server/mock-api-router.mjs`; login and DB Viewer continue to use `/api/session/*` and `/api/mock-db/*`. |
25-
| Browser code does not import Local DB implementation modules. | PASS | No browser import-boundary matches were found. |
26-
| Local Mem behavior remains available. | PASS | LoginSessionMode and AdminDbViewer Playwright lanes passed against Local Mem. |
27-
| Local DB is configured behind the existing server API boundary. | PASS | API contract probe selected `local-db`, resolved users/roles, read snapshots, and verified persisted clear across server restart. |
28-
| Local DB failure is visible and actionable. | PASS | API contract probe with `GAMEFOUNDRY_LOCAL_DB_DISABLE=1` returned a 500 diagnostic naming `Local DB adapter not configured` and the disabled storage cause. |
29-
| UAT/Prod are not local login choices. | PASS | LoginSessionMode Playwright and API contract probe assert only Local Mem and Local DB selector modes. |
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. |
3031

3132
## Remaining Internal Matches
3233

34+
- UAT/Prod strings remain only in the server adapter contract as deployment-only metadata.
3335
- `toolbox/*/*-mock-repository.js` and `toolbox/colors/palette-workspace-repository.js` remain server/data-source implementation modules, not active browser entry imports.
3436
- `/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 & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,9 @@ 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-
(0%) src/shared/toolbox/assetUsageIntegration.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
12-
(0%) src/shared/toolbox/platformShell.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
13-
(0%) src/shared/toolbox/projectSystem.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
14-
(0%) src/shared/toolbox/toolHostManifest.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
15-
(0%) src/shared/toolbox/toolLaunchSSoTData.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
16-
(56%) src/engine/api/server-api-client.js - executed lines 154/154; executed functions 10/18
17-
(60%) src/engine/api/mock-db-api-client.js - executed lines 19/19; executed functions 3/5
18-
(86%) src/engine/api/mock-db-viewer-ui.js - executed lines 478/478; executed functions 78/91
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
1913

2014
Guardrail warnings:
2115
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file missing from coverage; advisory only
2216
(0%) src/dev-runtime/server/mock-api-router.mjs - WARNING: changed runtime JS file missing from coverage; advisory only
23-
(0%) src/shared/toolbox/assetUsageIntegration.js - WARNING: changed runtime JS file missing from coverage; advisory only
24-
(0%) src/shared/toolbox/platformShell.js - WARNING: changed runtime JS file missing from coverage; advisory only
25-
(0%) src/shared/toolbox/projectSystem.js - WARNING: changed runtime JS file missing from coverage; advisory only
26-
(0%) src/shared/toolbox/toolHostManifest.js - WARNING: changed runtime JS file missing from coverage; advisory only
27-
(0%) src/shared/toolbox/toolLaunchSSoTData.js - WARNING: changed runtime JS file missing from coverage; advisory only
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# PR_26158_026 Local DB Viewer Readonly Report
2+
3+
## Executive Summary
4+
5+
Enabled Admin DB Viewer read-only inspection for Local DB through existing server API routes. Local Mem DB Viewer behavior remains intact, while Local DB now clearly identifies the active data source, renders live adapter snapshots and schemas, and hides write controls.
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+
| Enable Admin DB Viewer read-only inspection for Local DB through existing server API routes. | PASS | `admin/db-viewer.js` now allows `local-db`; `src/engine/api/mock-db-viewer-ui.js` reads snapshots via existing API client. |
13+
| Preserve existing Local Mem DB Viewer behavior. | PASS | AdminDbViewer Playwright Local Mem coverage passed, including clear/seed and live persisted tool records. |
14+
| Do not let browser code import dev-runtime, DB repositories, LocalDbAdapter, or DB implementation modules directly. | PASS | Static import-boundary checks returned no browser matches. |
15+
| DB Viewer clearly shows active data source mode. | PASS | `admin/db-viewer.html` and `mock-db-viewer-ui.js` update headings, kicker text, status, labels, and document title to Local Mem DB or Local DB. |
16+
| Local DB Viewer renders live adapter state and schemas, including empty tables with headers. | PASS | API contract probe and Playwright verify Local DB snapshot rendering, live state update, and empty table schema headers. |
17+
| Local DB Viewer fails visibly with actionable diagnostics when Local DB is unavailable. | PASS | Playwright and API contract probe verify `Local DB adapter not configured` plus storage diagnostic text. |
18+
| Do not add edit/write controls for Local DB. | PASS | Local DB mode removes the clear/seed control and Playwright asserts no non-filter buttons or form controls in the viewer. |
19+
| Do not expose UAT or Prod as local login choices. | PASS | `/api/session/modes` probe returned exactly `Local Mem` and `Local DB`. |
20+
| Do not modify `start_of_day` folders. | PASS | No `start_of_day` files changed. |
21+
22+
## Implementation Notes
23+
24+
| Area | Evidence |
25+
| --- | --- |
26+
| Gateway | `admin/db-viewer.js` now reads `/api/session/current`, allows `local-mem` and `local-db`, and passes session mode into the viewer UI. |
27+
| Shell copy | `admin/db-viewer.html` uses mode-aware data attributes so runtime text can show Local Mem DB or Local DB. |
28+
| Viewer UI | `src/engine/api/mock-db-viewer-ui.js` adds mode-aware labels, Local DB read-only behavior, Local DB empty-table messages, and mode-specific error diagnostics. |
29+
| API client | `src/engine/api/mock-db-api-client.js` uses generic DB Viewer snapshot wording while retaining Local Mem clear/seed methods. |
30+
| Validation | `tests/playwright/tools/AdminDbViewer.spec.mjs` adds Local DB read-only and Local DB unavailable tests. |
31+
32+
## Validation Evidence
33+
34+
| Validation | Result |
35+
| --- | --- |
36+
| Changed-file syntax checks | PASS |
37+
| Local DB/API snapshot contract validation | PASS |
38+
| AdminDbViewer Playwright | PASS, 7/7 |
39+
| Local login mode check | PASS |
40+
| Static import boundary audit | PASS |
41+
| `git diff --check` | PASS, Git line-ending warnings only |
42+
43+
## Remaining Migration Notes
44+
45+
- DB Viewer remains Local-only/admin-only; Local DB is read-only in this PR.
46+
- Local Mem clear/seed remains available only for Local Mem mode.
47+
- UAT/Prod remain deployment-only adapter contract metadata, not local login choices.

0 commit comments

Comments
 (0)