Skip to content

Commit e3ccd6b

Browse files
committed
Add local server diagnostics and API status to login page - PR_26158_036-login-local-server-status
1 parent 5fcdf02 commit e3ccd6b

7 files changed

Lines changed: 180 additions & 18 deletions

File tree

assets/theme-v2/js/login-session.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,20 @@ const modeDisabledMessage = document.querySelector("[data-login-mode-disabled-me
1414
const userControls = document.querySelector("[data-login-user-controls]");
1515
const userStatus = document.querySelector("[data-login-user-status]");
1616
const continueLink = document.querySelector("[data-login-continue]");
17-
const apiBackedLoginDiagnostic = "Use the API-backed local server for login. Run npm run dev:local-api and open http://127.0.0.1:5501/login.html.";
18-
const staticModeDisabledMessage = "Use the API-backed local server for login. Run npm run dev:local-api and open http://127.0.0.1:5501/login.html. Local Mem and Local DB are disabled until the local API server is running.";
17+
const localApiStartCommand = "npm run dev:local-api";
18+
const localApiLoginUrl = "http://127.0.0.1:5501/login.html";
19+
const expectedSessionEndpoint = "/api/session/current";
20+
const apiBackedLoginDiagnostic = `Use the API-backed local server for login. Run ${localApiStartCommand} and open ${localApiLoginUrl}.`;
21+
const staticModeDisabledMessage = `Use the API-backed local server for login. Run ${localApiStartCommand} and open ${localApiLoginUrl}. Local Mem and Local DB are disabled until the local API server is running.`;
22+
const localStatusFields = {
23+
api: document.querySelector("[data-login-status-api]"),
24+
apiUrl: document.querySelector("[data-login-status-api-url]"),
25+
command: document.querySelector("[data-login-status-command]"),
26+
currentUrl: document.querySelector("[data-login-status-current-url]"),
27+
disabledReason: document.querySelector("[data-login-status-disabled-reason]"),
28+
endpoint: document.querySelector("[data-login-status-endpoint]"),
29+
serverMode: document.querySelector("[data-login-status-server-mode]"),
30+
};
1931

2032
function currentReturnTo() {
2133
const params = new URLSearchParams(window.location.search);
@@ -32,6 +44,30 @@ function updateContinueLink() {
3244
}
3345
}
3446

47+
function updateLocalDevelopmentStatus({ apiAvailability, disabledReason, serverMode }) {
48+
if (localStatusFields.currentUrl) {
49+
localStatusFields.currentUrl.textContent = window.location.href;
50+
}
51+
if (localStatusFields.serverMode) {
52+
localStatusFields.serverMode.textContent = serverMode;
53+
}
54+
if (localStatusFields.api) {
55+
localStatusFields.api.textContent = apiAvailability;
56+
}
57+
if (localStatusFields.disabledReason) {
58+
localStatusFields.disabledReason.textContent = disabledReason;
59+
}
60+
if (localStatusFields.endpoint) {
61+
localStatusFields.endpoint.textContent = expectedSessionEndpoint;
62+
}
63+
if (localStatusFields.apiUrl) {
64+
localStatusFields.apiUrl.textContent = localApiLoginUrl;
65+
}
66+
if (localStatusFields.command) {
67+
localStatusFields.command.textContent = localApiStartCommand;
68+
}
69+
}
70+
3571
function dispatchSessionChanged() {
3672
window.dispatchEvent(new CustomEvent("gamefoundry:mock-db-session-user-changed", {
3773
detail: getSessionCurrent(),
@@ -105,6 +141,12 @@ function isStaticLocalEntrypoint() {
105141

106142
function renderError(error) {
107143
const message = errorMessage(error);
144+
const serverMode = isStaticLocalEntrypoint()
145+
? "Static-only local server"
146+
: "Local server without session API";
147+
const disabledReason = message === apiBackedLoginDiagnostic
148+
? staticModeDisabledMessage
149+
: `Local Mem and Local DB are disabled because ${message}`;
108150
modeButtons.forEach((button) => {
109151
button.disabled = true;
110152
button.setAttribute("aria-disabled", "true");
@@ -130,6 +172,11 @@ function renderError(error) {
130172
if (userStatus) {
131173
userStatus.textContent = "No local users are available until /api/session responds.";
132174
}
175+
updateLocalDevelopmentStatus({
176+
apiAvailability: `Unavailable: ${message}`,
177+
disabledReason,
178+
serverMode,
179+
});
133180
updateContinueLink();
134181
}
135182

@@ -164,6 +211,11 @@ function render() {
164211
}
165212
modeStatus.textContent = statusParts.join(". ") + ".";
166213
}
214+
updateLocalDevelopmentStatus({
215+
apiAvailability: `Available: ${expectedSessionEndpoint} responded through the local API server.`,
216+
disabledReason: "Local Mem and Local DB are enabled because the Local API is available.",
217+
serverMode: `API-backed local server (${mode.label || session.mode})`,
218+
});
167219
if (modeDisabledMessage) {
168220
modeDisabledMessage.hidden = true;
169221
modeDisabledMessage.textContent = "";
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# PR_26158_036 Login Local Server Status Report
2+
3+
## Executive Summary
4+
5+
Added a Local Development Status section near the bottom of `login.html`, below a new HR, so local developers can see the current URL, detected server mode, Local API availability, disabled reason, expected endpoint, correct API-backed URL, and startup command.
6+
7+
Static-only `127.0.0.1:5500` login remains disabled with no fallback behavior. API-backed Local Mem and Local DB remain enabled when the local API server is available.
8+
9+
## Implementation
10+
11+
| Area | Change | Evidence |
12+
| --- | --- | --- |
13+
| Login page markup | Added one HR and a `Local Development Status` card using existing Theme V2 classes. | `login.html` |
14+
| Login runtime | Populates current URL, detected server mode, API availability, disabled reason, expected endpoint, local URL, and startup command from the existing render/error paths. | `assets/theme-v2/js/login-session.js` |
15+
| Static Playwright | Verifies the diagnostics are visible and explain why Local Mem / Local DB are disabled without API. | `tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs` |
16+
| API-backed Playwright | Verifies Local Mem / Local DB are enabled and diagnostics report API availability. | `tests/playwright/tools/LoginSessionMode.spec.mjs` |
17+
18+
## Requirement Checklist
19+
20+
| Requirement | Evidence | Status |
21+
| --- | --- | --- |
22+
| Read `docs_build/dev/PROJECT_INSTRUCTIONS.md` first. | Read before implementation and validation. | PASS |
23+
| Add an HR near the bottom of `login.html`. | Added `main hr`; both Playwright lanes verify one HR in `main`. | PASS |
24+
| Add a Local Development Status section below the HR. | Added `Local Development Status` H2 and status fields below the HR. | PASS |
25+
| Display current URL. | `[data-login-status-current-url]` is populated from `window.location.href`; both Playwright lanes verify it. | PASS |
26+
| Display detected server mode. | Static lane verifies `Static-only local server`; API-backed lane verifies Local Mem and Local DB server modes. | PASS |
27+
| Display Local API availability status. | Static lane verifies `Unavailable`; API-backed lane verifies `Available` and `/api/session/current`. | PASS |
28+
| Display why Local Mem and Local DB are disabled when API is unavailable. | Static lane verifies disabled reason text, command, and URL. | PASS |
29+
| Display the expected API endpoint. | Both lanes verify `/api/session/current`. | PASS |
30+
| Display the correct local API-backed URL and startup command if discoverable from repo scripts. | Both lanes verify `http://127.0.0.1:5501/login.html` and `npm run dev:local-api`, established by PR_26158_035. | PASS |
31+
| Preserve disabled login behavior when API is unavailable. | Static lane verifies both login mode buttons are disabled and unselected. | PASS |
32+
| Do not add fallback login behavior. | Static lane verifies no `/api/session/current` or `/api/session/` request is made from 5500. | PASS |
33+
| Run changed-file syntax checks. | `node --check` passed for changed JS/spec files. | PASS |
34+
| Run LoginSessionMode Playwright. | `npx playwright test tests/playwright/tools/LoginSessionMode.spec.mjs` passed 5/5. | PASS |
35+
| Run static-only login Playwright proving diagnostics are visible. | `npx playwright test tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs` passed 1/1. | PASS |
36+
| Verify Local Mem and Local DB become enabled when API is available. | LoginSessionMode verifies both `[data-login-mode]` buttons are enabled on API-backed login. | PASS |
37+
| Required reports and review artifacts generated. | This report, `testing_lane_execution_report.md`, V8 coverage report, review diff, changed files, and ZIP artifact generated. | PASS |
38+
39+
## Validation Commands
40+
41+
| Command | Result |
42+
| --- | --- |
43+
| `node --check assets/theme-v2/js/login-session.js` | PASS |
44+
| `node --check tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs` | PASS |
45+
| `node --check tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS |
46+
| `npx playwright test tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS, 5/5 |
47+
| `npx playwright test tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs` | PASS, 1/1 |
48+
| `git diff --check` | PASS, with Git line-ending warnings only |
49+
50+
## Skipped Lanes
51+
52+
| Lane | Decision | Reason |
53+
| --- | --- | --- |
54+
| ToolboxRoutePages Playwright | SKIP | No toolbox route/page rendering files were changed. |
55+
| AdminDbViewer Playwright | SKIP | Admin DB Viewer behavior and DB adapter rendering were not changed. |
56+
| ProjectJourneyTool Playwright | SKIP | Project Journey files and persistence paths were not changed. |
57+
| Full samples smoke | SKIP | No samples, sample loader, or shared sample framework changed. |
58+
59+
## Notes
60+
61+
- No CSS was added.
62+
- No fallback login behavior was added.
63+
- Existing SQLite experimental warnings and seed-only audit diagnostics appeared during API-backed validation; they were existing runtime diagnostics and did not affect the PR requirement results.
64+
- The V8 coverage helper includes HEAD-changed server files as advisory coverage context; this PR's current changed browser runtime file, `assets/theme-v2/js/login-session.js`, was collected by Playwright V8 coverage.

docs_build/dev/reports/playwright_v8_coverage_report.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ Note: coverage entries are aggregated across every page/tool where coverageRepor
1414
Exercised tool entry points detected:
1515
(0%) Toolbox Index - not exercised by this Playwright run
1616
(0%) Tool Template V2 - not exercised by this Playwright run
17-
(70%) Theme V2 Shared JS - exercised 2 runtime JS files
17+
(71%) Theme V2 Shared JS - exercised 2 runtime JS files
1818

1919
Changed runtime JS files covered:
2020
(0%) src/dev-runtime/server/local-api-server.mjs - WARNING: changed runtime JS file was not collected by Playwright V8 coverage; advisory only
2121

2222
Files with executed line/function counts where available:
2323
(7%) src/engine/api/server-api-client.js - executed lines 159/159; executed functions 1/14
2424
(13%) src/engine/api/session-api-client.js - executed lines 34/34; executed functions 1/8
25-
(59%) assets/theme-v2/js/login-session.js - executed lines 192/192; executed functions 10/17
25+
(61%) assets/theme-v2/js/login-session.js - executed lines 243/243; executed functions 11/18
2626
(75%) assets/theme-v2/js/gamefoundry-partials.js - executed lines 442/442; executed functions 30/40
2727

2828
Uncovered or low-coverage changed JS files:
@@ -31,6 +31,7 @@ Uncovered or low-coverage changed JS files:
3131
Changed JS files considered:
3232
(0%) scripts/start-local-api-server.mjs - changed JS file not collected as browser runtime coverage
3333
(0%) src/dev-runtime/server/local-api-server.mjs - changed JS file not collected as browser runtime coverage
34+
(0%) tests/playwright/tools/LoginSessionMode.spec.mjs - changed JS file not collected as browser runtime coverage
3435
(0%) tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs - changed JS file not collected as browser runtime coverage
35-
(59%) assets/theme-v2/js/login-session.js - changed JS file with browser V8 coverage
36+
(61%) assets/theme-v2/js/login-session.js - changed JS file with browser V8 coverage
3637
(75%) assets/theme-v2/js/gamefoundry-partials.js - changed JS file with browser V8 coverage
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
# PR_26158_035 Testing Lane Execution Report
1+
# PR_26158_036 Testing Lane Execution Report
22

33
## Lanes Run
44

55
| Lane | Command | Result |
66
| --- | --- | --- |
7-
| Changed-file syntax | `node --check assets/theme-v2/js/login-session.js`; `node --check assets/theme-v2/js/gamefoundry-partials.js`; `node --check tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs`; `node --check scripts/start-local-api-server.mjs`; `node --check src/dev-runtime/server/local-api-server.mjs`; `node -e "JSON.parse(require('fs').readFileSync('package.json','utf8')); console.log('package.json OK')"` | PASS |
8-
| API-backed local server probe | Inline Node import of `startLocalApiServer({ host: "127.0.0.1", port: 5501 })`; fetched `/login.html` and `/api/session/current` | PASS; both returned 200 |
7+
| Changed-file syntax | `node --check assets/theme-v2/js/login-session.js`; `node --check tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs`; `node --check tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS |
98
| LoginSessionMode Playwright | `npx playwright test tests/playwright/tools/LoginSessionMode.spec.mjs` | PASS, 5/5 |
109
| Static 127.0.0.1:5500 login Playwright | `npx playwright test tests/playwright/tools/StaticOnlyLoginApiRequired.spec.mjs` | PASS, 1/1 |
1110
| Changed-file/static validation | `git diff --check` | PASS, with Git line-ending warnings only |
12-
| Runtime JS V8 coverage | Playwright coverage generated by targeted runs | PASS/WARN; `docs_build/dev/reports/playwright_v8_coverage_report.txt` and `coverage_changed_js_guardrail.txt` generated. |
11+
| Runtime JS V8 coverage | Playwright coverage generated by targeted runs | PASS/WARN; `docs_build/dev/reports/playwright_v8_coverage_report.txt` generated. |
1312

1413
## Validation Notes
1514

1615
| Check | Evidence | Result |
1716
| --- | --- | --- |
18-
| Static `127.0.0.1:5500` login keeps Local Mem and Local DB disabled. | `StaticOnlyLoginApiRequired.spec.mjs` verifies both `[data-login-mode]` buttons are disabled and not selected. | PASS |
19-
| Static login disabled message includes exact start command. | `StaticOnlyLoginApiRequired.spec.mjs` verifies `[data-login-mode-disabled-message]` and `[data-login-mode-status]` include `npm run dev:local-api`. | PASS |
20-
| Static login disabled message includes exact API-backed URL. | `StaticOnlyLoginApiRequired.spec.mjs` verifies `[data-login-mode-disabled-message]` and `[data-login-mode-status]` include `http://127.0.0.1:5501/login.html`. | PASS |
21-
| Static `127.0.0.1:5500` does not call session API routes. | Static lane records all requests and asserts no request URL contains `/api/session/current` or `/api/session/`. | PASS |
22-
| API-backed Local Mem and Local DB behavior is unchanged. | `LoginSessionMode.spec.mjs` passed 5/5, including Local DB session behavior. | PASS |
23-
| Documented API-backed URL is real. | Server probe fetched `http://127.0.0.1:5501/login.html` and `http://127.0.0.1:5501/api/session/current` with 200 responses. | PASS |
17+
| Local Development Status section is visible below an HR. | Both Playwright lanes verify `main hr` count and the `Local Development Status` H2. | PASS |
18+
| Current URL displays. | Static lane verifies `http://127.0.0.1:5500/login.html`; API-backed lane verifies the API-backed server URL for `/login.html`. | PASS |
19+
| Detected server mode displays. | Static lane verifies `Static-only local server`; API-backed lane verifies `API-backed local server (Local Mem)` and `API-backed local server (Local DB)`. | PASS |
20+
| Local API availability displays. | Static lane verifies `Unavailable`; API-backed lane verifies `Available` and `/api/session/current`. | PASS |
21+
| Disabled reason displays when API is unavailable. | Static lane verifies the disabled reason includes Local Mem / Local DB disabled plus the command and URL. | PASS |
22+
| Expected API endpoint displays. | Both lanes verify `/api/session/current`. | PASS |
23+
| Correct API-backed URL and startup command display. | Both lanes verify `http://127.0.0.1:5501/login.html` and `npm run dev:local-api`. | PASS |
24+
| Local Mem and Local DB remain disabled without API. | Static lane verifies both buttons are disabled and unselected. | PASS |
25+
| Local Mem and Local DB become enabled when API is available. | LoginSessionMode verifies both mode buttons are enabled on the API-backed server. | PASS |
26+
| No fallback behavior was added. | Static lane verifies no `/api/session/current` or `/api/session/` requests are made from 5500. | PASS |
2427

2528
## Skipped Lanes
2629

2730
| Lane | Decision | Reason |
2831
| --- | --- | --- |
2932
| ToolboxRoutePages Playwright | SKIP | Tool route rendering was not changed by this PR. |
3033
| AdminDbViewer Playwright | SKIP | DB Viewer routes, DB adapters, and admin DB rendering were not changed. |
31-
| ProjectJourneyTool Playwright | SKIP | Project Journey behavior and persistence paths were not changed. |
34+
| ProjectJourneyTool Playwright | SKIP | Project Journey files and persistence paths were not changed. |
3235
| Full samples smoke | SKIP | No samples, shared sample loader, or sample framework files changed. |
3336
| Full Playwright suite | SKIP | Static 5500 login and API-backed login cover the changed login/session behavior. |
3437

3538
## Notes
3639

37-
- Playwright and the API-backed server probe emitted existing Node SQLite experimental warnings and existing seed-only audit fallback diagnostics; they did not fail validation.
38-
- Playwright impacted: Yes. The changed behavior is login/session UI messaging and enabled/disabled state under static-only and API-backed local serving.
40+
- Playwright impacted: Yes. The changed behavior is login/session diagnostics and enabled/disabled state visibility.
41+
- Playwright and API-backed server startup emitted existing Node SQLite experimental warnings and existing seed-only audit fallback diagnostics; they did not fail validation.
42+
- The V8 coverage helper includes HEAD-changed server files as advisory context; current PR changed browser login runtime plus Playwright specs.

login.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ <h2 id="login-users-title">Session User</h2>
4848
</div>
4949
</div>
5050
</div>
51+
<hr>
52+
<section class="card" aria-labelledby="login-local-status-title">
53+
<div class="card-body content-stack">
54+
<div>
55+
<div class="kicker">Diagnostics</div>
56+
<h2 id="login-local-status-title">Local Development Status</h2>
57+
</div>
58+
<div class="content-stack" data-login-local-status>
59+
<p><strong>Current URL:</strong> <span data-login-status-current-url>Checking...</span></p>
60+
<p><strong>Detected server mode:</strong> <span data-login-status-server-mode>Checking...</span></p>
61+
<p><strong>Local API availability:</strong> <span data-login-status-api>Checking...</span></p>
62+
<p><strong>Disabled reason:</strong> <span data-login-status-disabled-reason>Checking...</span></p>
63+
<p><strong>Expected API endpoint:</strong> <span data-login-status-endpoint>/api/session/current</span></p>
64+
<p><strong>Correct local URL:</strong> <span data-login-status-api-url>http://127.0.0.1:5501/login.html</span></p>
65+
<p><strong>Startup command:</strong> <span data-login-status-command>npm run dev:local-api</span></p>
66+
</div>
67+
</div>
68+
</section>
5169
</div>
5270
</section>
5371
</main>

0 commit comments

Comments
 (0)