Skip to content

Commit e200cb1

Browse files
committed
Move mock data behind server API boundary and remove browser mock-data debt - PR_26158_020-server-mock-data-boundary / PR_26158_021-browser-mock-debt-cleanup
1 parent 2adc7c4 commit e200cb1

56 files changed

Lines changed: 1397 additions & 343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

admin/db-viewer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const MOCK_DB_SESSION_MODE_STORAGE_KEY = "gamefoundry.mockDb.sessionMode.v1";
2-
31
function devRuntimeAllowed() {
42
const host = window.location.hostname;
53
return window.GameFoundryDevRuntime?.enabled === true ||
@@ -10,7 +8,12 @@ function devRuntimeAllowed() {
108

119
function localModeSelected() {
1210
try {
13-
return (window.localStorage.getItem(MOCK_DB_SESSION_MODE_STORAGE_KEY) || "local") === "local";
11+
const request = new XMLHttpRequest();
12+
request.open("GET", "/api/session/current", false);
13+
request.setRequestHeader("Accept", "application/json");
14+
request.send(null);
15+
const payload = request.responseText ? JSON.parse(request.responseText) : null;
16+
return request.status >= 200 && request.status < 300 && payload?.data?.mode === "local";
1417
} catch {
1518
return false;
1619
}

assets/theme-v2/js/gamefoundry-partials.js

Lines changed: 22 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@
107107
"account", "company", "community", "legal",
108108
"admin", "docs", "games", "learn", "marketplace", "toolbox"
109109
]);
110-
const mockDbStorageKey = "gamefoundry.mockDb.v1";
111-
const mockDbSessionStorageKey = "gamefoundry.mockDb.sessionUser.v1";
112-
const mockDbSessionModeStorageKey = "gamefoundry.mockDb.sessionMode.v1";
113110

114111
const currentScript = document.currentScript || document.querySelector("script[src*='gamefoundry-partials.js']");
115112
const assetRoot = currentScript ? new URL("../", currentScript.src) : null;
@@ -151,110 +148,33 @@
151148
});
152149
}
153150

154-
function readMockDbState() {
155-
try {
156-
const raw = window.localStorage.getItem(mockDbStorageKey);
157-
return raw ? JSON.parse(raw) : null;
158-
} catch {
159-
return null;
160-
}
161-
}
162-
163-
function selectedLocalSessionKey() {
164-
try {
165-
return window.localStorage.getItem(mockDbSessionStorageKey) || "";
166-
} catch {
167-
return "";
168-
}
169-
}
170-
171-
function selectedSessionModeId() {
172-
try {
173-
return window.localStorage.getItem(mockDbSessionModeStorageKey) || "local";
174-
} catch {
175-
return "local";
176-
}
177-
}
178-
179-
function rolesForUser(state, userKey) {
180-
const rows = state?.tables?.user_roles || [];
181-
const roles = new Map((state?.tables?.roles || []).map(function (role) {
182-
return [role.key, role.roleSlug || role.name];
183-
}));
184-
return rows
185-
.filter(function (row) {
186-
return row.userKey === userKey && roles.has(row.roleKey);
187-
})
188-
.map(function (row) {
189-
return roles.get(row.roleKey);
190-
})
191-
.filter(Boolean);
192-
}
193-
194151
function localDevLoginState() {
195-
if (selectedSessionModeId() === "dev") {
196-
return {
197-
authenticated: false,
198-
diagnostic: "DEV mode uses read-only/demo JSON access. Switch to Local to use persisted Memory DB sessions.",
199-
displayName: "Login",
200-
mode: "dev",
201-
roleSlugs: []
202-
};
203-
}
204-
205-
const sessionUserKey = selectedLocalSessionKey();
206-
if (!sessionUserKey) {
207-
return {
208-
authenticated: false,
209-
diagnostic: "",
210-
displayName: "Login",
211-
mode: "local",
212-
roleSlugs: []
213-
};
214-
}
215-
216-
const state = readMockDbState();
217-
if (!state) {
218-
return {
219-
authenticated: false,
220-
diagnostic: "Persisted Memory DB users and roles are not seeded. Open Login and choose Local to seed local users.",
221-
displayName: "Login",
222-
mode: "local",
223-
roleSlugs: []
224-
};
225-
}
226-
227-
const user = (state?.tables?.users || []).find(function (record) {
228-
return record.key === sessionUserKey && record.isActive !== false;
229-
});
230-
if (!user) {
152+
try {
153+
const request = new XMLHttpRequest();
154+
request.open("GET", "/api/session/current", false);
155+
request.setRequestHeader("Accept", "application/json");
156+
request.send(null);
157+
const payload = request.responseText ? JSON.parse(request.responseText) : null;
158+
if (request.status < 200 || request.status >= 300 || payload?.ok === false) {
159+
throw new Error(payload?.error || "Session API did not return a valid current session.");
160+
}
161+
const session = payload?.data || {};
231162
return {
232-
authenticated: false,
233-
diagnostic: `Selected Local user key ${sessionUserKey} is missing from persisted Memory DB users.`,
234-
displayName: "Login",
235-
mode: "local",
236-
roleSlugs: []
163+
authenticated: Boolean(session.authenticated),
164+
diagnostic: session.diagnostic || "",
165+
displayName: session.authenticated ? session.displayName || session.label || "Account" : "Login",
166+
mode: session.mode || "local",
167+
roleSlugs: Array.isArray(session.roleSlugs) ? session.roleSlugs : []
237168
};
238-
}
239-
240-
const roleSlugs = rolesForUser(state, sessionUserKey);
241-
if (!roleSlugs.length) {
169+
} catch (error) {
242170
return {
243171
authenticated: false,
244-
diagnostic: `Selected Local user ${user.displayName || sessionUserKey} has no persisted Memory DB roles.`,
172+
diagnostic: "Server session API is unavailable. Start the Local/DEV server API before using protected pages.",
245173
displayName: "Login",
246-
mode: "local",
174+
mode: "missing-api",
247175
roleSlugs: []
248176
};
249177
}
250-
251-
return {
252-
authenticated: true,
253-
diagnostic: "",
254-
displayName: user.displayName || sessionUserKey,
255-
mode: "local",
256-
roleSlugs
257-
};
258178
}
259179

260180
function directSubMenu(navItem) {
@@ -438,7 +358,10 @@
438358
function logoutCurrentSession(event) {
439359
event.preventDefault();
440360
try {
441-
window.localStorage.removeItem(mockDbSessionStorageKey);
361+
const request = new XMLHttpRequest();
362+
request.open("POST", "/api/session/logout", false);
363+
request.setRequestHeader("Accept", "application/json");
364+
request.send(null);
442365
window.dispatchEvent(new CustomEvent("gamefoundry:mock-db-session-user-changed", {
443366
detail: {
444367
authenticated: false,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# API Contract Validation Report
2+
3+
## Summary
4+
5+
Status: PASS
6+
7+
Validation confirmed each touched browser tool can initialize a server repository and call expected methods through the `/api/toolbox/...` contract. Session and Mock DB contracts were also validated.
8+
9+
## Contract Checks
10+
11+
| Contract | Methods/Routes | Result |
12+
| --- | --- | --- |
13+
| Project Workspace | constants, repository init, `getActiveProject`, `getProjectProgress`, `getTables` | PASS |
14+
| Game Design | constants, repository init, `getSnapshot`, `getProjectProgressHandoff`, `getTables` | PASS |
15+
| Game Configuration | constants, repository init, `getSnapshot`, `getProjectProgressHandoff`, `getTables` | PASS |
16+
| Project Journey | constants, repository init, `getSessionUser`, `listNotes`, `getTables` | PASS |
17+
| Palette | constants, repository init, `getSnapshot`, `getTables`, `sourcePaletteOptions` | PASS |
18+
| Asset | constants, repository init, `getSnapshot`, `getTables`, `getProgressHandoff` | PASS |
19+
| Session | `/api/session/current`, `/api/session/users` | PASS |
20+
| Mock DB | `/api/mock-db/snapshot` | PASS |
21+
22+
## Command Evidence
23+
24+
Custom Node validation script using `startRepoServer()` and `fetch()`:
25+
26+
```text
27+
PASS project-workspace.getActiveProject
28+
PASS project-workspace.getProjectProgress
29+
PASS project-workspace.getTables
30+
PASS game-design.getSnapshot
31+
PASS game-design.getProjectProgressHandoff
32+
PASS game-design.getTables
33+
PASS game-configuration.getSnapshot
34+
PASS game-configuration.getProjectProgressHandoff
35+
PASS game-configuration.getTables
36+
PASS project-journey.getSessionUser
37+
PASS project-journey.listNotes
38+
PASS project-journey.getTables
39+
PASS palette.getSnapshot
40+
PASS palette.getTables
41+
PASS palette.sourcePaletteOptions
42+
PASS assets.getSnapshot
43+
PASS assets.getTables
44+
PASS assets.getProgressHandoff
45+
PASS /api/session/current
46+
PASS /api/session/users
47+
PASS /api/mock-db/snapshot
48+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# PR_26158_021 Browser Mock Debt Cleanup Report
2+
3+
## Executive Summary
4+
5+
Status: PASS
6+
7+
Active browser/tool files were audited and moved from direct mock repository imports to server API clients. DB Viewer and login/session now resolve through server APIs. Browser-side fallbacks to mock DB storage were removed from active header/session paths.
8+
9+
## Cleanup Checklist
10+
11+
| Requirement | Status | Evidence |
12+
| --- | --- | --- |
13+
| Audit active browser/tool files for direct mock imports/embedded records | PASS | `rg` audit run against `toolbox`, `admin`, `assets/theme-v2/js`, and `src/engine/api`. |
14+
| Replace browser mock access with API client calls | PASS | Added `*-api-client.js` modules and updated active tool entries. |
15+
| Add smallest server/dev endpoints needed | PASS | Added `/api/toolbox/...`, `/api/session/...`, `/api/mock-db/...`, plus dev/testing state injection for tests only. |
16+
| Stable production-shaped endpoint names | PASS | Endpoints use tool/session/mock-db resources, not page-local snapshots. |
17+
| DB Viewer reads through server boundary | PASS | `src/dev-runtime/admin/db-viewer.js` imports `src/engine/api/mock-db-api-client.js`. |
18+
| Mock login/session resolves through server/dev auth boundary | PASS | `src/dev-runtime/auth/login-session.js` imports `src/engine/api/session-api-client.js`; shared header calls `/api/session/current`. |
19+
| Fail visibly when server data missing | PASS | Header/access guard and DB Viewer gateway expose visible diagnostics when API/session data is unavailable. |
20+
| Preserve behavior | PASS | Runtime/UI lanes listed in `testing_lane_execution_report.md`. |
21+
22+
## Files Moved To API Clients
23+
24+
- Project Workspace: `toolbox/project-workspace/project-workspace-api-client.js`
25+
- Project Journey: `toolbox/project-journey/project-journey-api-client.js`
26+
- Palette: `toolbox/colors/palette-api-client.js`
27+
- Asset: `toolbox/assets/assets-api-client.js`
28+
- Game Design: `toolbox/game-design/game-design-api-client.js`
29+
- Game Configuration: `toolbox/game-configuration/game-configuration-api-client.js`
30+
31+
## Static Audit Result
32+
33+
PASS: no active browser entry file imports mock repositories, dev-runtime persistence, seed data, or mock DB store paths directly. Remaining direct mock repository imports are in server/dev-runtime or repository implementation modules.
34+
35+
## Skipped Lanes
36+
37+
Full samples smoke skipped: no sample loader/framework changed.
38+
39+
Tools Progress broad lane was not used as a required validation lane. It exercises admin progress metadata and planned/hidden Toolbox visibility expectations outside this PR's browser mock-data boundary. Project Workspace Playwright covered the touched Toolbox page helper.

docs_build/dev/reports/coverage_changed_js_guardrail.txt

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,42 @@ Missing changed runtime JS files are WARN, not FAIL.
66
Source: Playwright/Chromium built-in V8 coverage from the active Playwright run.
77

88
Changed runtime JS files considered:
9-
(64%) src/engine/persistence/mock-db-store.js - executed lines 36/36; executed functions 7/11
10-
(70%) toolbox/colors/palette-workspace-repository.js - executed lines 1361/1361; executed functions 92/132
11-
(82%) toolbox/assets/assets-mock-repository.js - executed lines 943/943; executed functions 63/77
9+
(0%) src/dev-runtime/auth/login-session.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
10+
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
11+
(0%) src/dev-runtime/server/mock-api-router.mjs - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
12+
(0%) src/engine/api/session-api-client.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
13+
(0%) src/engine/persistence/mock-db-store.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
14+
(0%) toolbox/assets/assets-mock-repository.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
15+
(0%) toolbox/colors/palette-workspace-repository.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
16+
(0%) toolbox/game-configuration/game-configuration-api-client.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
17+
(0%) toolbox/game-configuration/game-configuration.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
18+
(0%) toolbox/game-design/game-design-api-client.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
19+
(0%) toolbox/game-design/game-design.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
20+
(0%) toolbox/project-workspace/project-workspace-api-client.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
21+
(0%) toolbox/project-workspace/project-workspace.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
22+
(0%) toolbox/tools-page-accordions.js - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
23+
(56%) src/engine/api/server-api-client.js - executed lines 135/135; executed functions 9/16
24+
(69%) toolbox/colors/colors.js - executed lines 877/877; executed functions 62/90
25+
(75%) toolbox/project-journey/project-journey.js - executed lines 991/991; executed functions 74/99
26+
(88%) toolbox/assets/assets.js - executed lines 519/519; executed functions 53/60
1227
(95%) src/dev-runtime/admin/db-viewer.js - executed lines 478/478; executed functions 86/91
13-
(95%) src/dev-runtime/persistence/mock-db-store.js - executed lines 727/727; executed functions 78/82
14-
(100%) src/dev-runtime/auth/login-session.js - executed lines 107/107; executed functions 12/12
28+
(100%) src/engine/api/mock-db-api-client.js - executed lines 22/22; executed functions 5/5
29+
(100%) toolbox/assets/assets-api-client.js - executed lines 16/16; executed functions 3/3
30+
(100%) toolbox/colors/palette-api-client.js - executed lines 18/18; executed functions 4/4
31+
(100%) toolbox/project-journey/project-journey-api-client.js - executed lines 11/11; executed functions 2/2
1532

1633
Guardrail warnings:
17-
(100%) none - no changed runtime JS coverage warnings
34+
(0%) src/dev-runtime/auth/login-session.js - WARNING: changed runtime JS file missing from coverage; advisory only
35+
(0%) src/dev-runtime/persistence/mock-db-store.js - WARNING: changed runtime JS file missing from coverage; advisory only
36+
(0%) src/dev-runtime/server/mock-api-router.mjs - WARNING: changed runtime JS file missing from coverage; advisory only
37+
(0%) src/engine/api/session-api-client.js - WARNING: changed runtime JS file missing from coverage; advisory only
38+
(0%) src/engine/persistence/mock-db-store.js - WARNING: changed runtime JS file missing from coverage; advisory only
39+
(0%) toolbox/assets/assets-mock-repository.js - WARNING: changed runtime JS file missing from coverage; advisory only
40+
(0%) toolbox/colors/palette-workspace-repository.js - WARNING: changed runtime JS file missing from coverage; advisory only
41+
(0%) toolbox/game-configuration/game-configuration-api-client.js - WARNING: changed runtime JS file missing from coverage; advisory only
42+
(0%) toolbox/game-configuration/game-configuration.js - WARNING: changed runtime JS file missing from coverage; advisory only
43+
(0%) toolbox/game-design/game-design-api-client.js - WARNING: changed runtime JS file missing from coverage; advisory only
44+
(0%) toolbox/game-design/game-design.js - WARNING: changed runtime JS file missing from coverage; advisory only
45+
(0%) toolbox/project-workspace/project-workspace-api-client.js - WARNING: changed runtime JS file missing from coverage; advisory only
46+
(0%) toolbox/project-workspace/project-workspace.js - WARNING: changed runtime JS file missing from coverage; advisory only
47+
(0%) toolbox/tools-page-accordions.js - WARNING: changed runtime JS file missing from coverage; advisory only

docs_build/dev/reports/dependency_gating_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dependency Gating Report
22

3-
Generated: 2026-06-07T05:10:39.389Z
3+
Generated: 2026-06-07T13:32:44.758Z
44
Status: PASS
55

66
## Gate Order

docs_build/dev/reports/dependency_hydration_reuse_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dependency Hydration Reuse Report
22

3-
Generated: 2026-06-07T05:10:39.389Z
3+
Generated: 2026-06-07T13:32:44.758Z
44
Status: PASS
55

66
## Summary

docs_build/dev/reports/execution_graph_reuse_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Execution Graph Reuse Report
22

3-
Generated: 2026-06-07T05:10:39.389Z
3+
Generated: 2026-06-07T13:32:44.758Z
44
Status: PASS
55

66
## Summary

docs_build/dev/reports/failure_fingerprint_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Failure Fingerprint Report
22

3-
Generated: 2026-06-07T05:10:39.389Z
3+
Generated: 2026-06-07T13:32:44.758Z
44
Status: PASS
55

66
## Summary

docs_build/dev/reports/incremental_validation_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Incremental Validation Report
22

3-
Generated: 2026-06-07T05:10:39.390Z
3+
Generated: 2026-06-07T13:32:44.759Z
44
Status: PASS
55

66
## Reuse Summary

0 commit comments

Comments
 (0)