mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-25 02:35:17 +00:00
844536a4cc
Red commit:cd3bae2(will fail CI — test asserts behavior that doesn't exist yet) Green commit:01e1882(fixes the catch-path) ## Problem Navigating to `/#/nodes/{unknown_pubkey}` returned 404 from `/api/nodes/{pubkey}`, but the back-row title in `public/nodes.js` stayed "Loading…" forever and the body only showed bare "Failed to load node: API 404" text — no link back to the Nodes list, no retry. ## Fix In `loadFullNode`'s catch path: - Update `.node-full-title` to `Node not found — <prefix>…` on 404, or `Failed to load node` on other errors. - Replace the bare body text with a card showing the requested pubkey (mono), a friendly explanation, a `Back to Nodes` link (`href="#/nodes"`), and a `Try again` button that re-invokes `loadFullNode(pubkey)`. ## Tests Added `test-issue-1150-404-state-e2e.js` (Playwright) which: 1. Verifies `/api/nodes/<unknown>` actually 404s (precondition). 2. Navigates to `/#/nodes/<unknown>`. 3. Asserts `.node-full-title` is NOT `"Loading…"` and indicates not-found / contains pubkey prefix. 4. Asserts `#nodeFullBody` text contains `"not found"` or `"unknown"`. 5. Asserts a body `<a href="#/nodes">` exists (Back to Nodes link). Wired into `.github/workflows/deploy.yml` E2E step. Reverting either the title fix or the body fix flips the test red. E2E assertion added: `test-issue-1150-404-state-e2e.js:62` (title), `:79` (body), `:88` (back link) Browser verified: assertion is exercised against the workflow's localhost:13581 server in CI. Fixes #1150 --------- Co-authored-by: meshcore-bot <meshcore-bot@users.noreply.github.com>
103 lines
4.5 KiB
JavaScript
103 lines
4.5 KiB
JavaScript
/**
|
|
* E2E (#1150): Full-page node detail header must NOT remain "Loading…"
|
|
* forever when /api/nodes/{pubkey} returns 404.
|
|
*
|
|
* Repro: navigate to /#/nodes/{unknown_pubkey}. The body shows
|
|
* "Failed to load node: API 404" but the back-row title stays "Loading…"
|
|
* with no link back to the Nodes list.
|
|
*
|
|
* After the fix:
|
|
* 1. Page back-row title is NOT "Loading…" — it should reflect "Node not found"
|
|
* or include the unknown pubkey prefix.
|
|
* 2. Body content surfaces an error state mentioning "not found" / "unknown".
|
|
* 3. There is a link back to /#/nodes (in addition to the existing back arrow).
|
|
*
|
|
* Usage: BASE_URL=http://localhost:13581 node test-issue-1150-404-state-e2e.js
|
|
*/
|
|
'use strict';
|
|
const { chromium } = require('playwright');
|
|
|
|
const BASE = process.env.BASE_URL || 'http://localhost:13581';
|
|
const UNKNOWN_PUBKEY = 'deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef';
|
|
|
|
let passed = 0, failed = 0;
|
|
async function step(name, fn) {
|
|
try { await fn(); passed++; console.log(' \u2713 ' + name); }
|
|
catch (e) { failed++; console.error(' \u2717 ' + name + ': ' + e.message); }
|
|
}
|
|
function assert(c, m) { if (!c) throw new Error(m || 'assertion failed'); }
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: process.env.CHROMIUM_PATH || undefined,
|
|
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
|
});
|
|
const ctx = await browser.newContext({ viewport: { width: 1400, height: 900 } });
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(15000);
|
|
page.on('pageerror', (e) => console.error('[pageerror]', e.message));
|
|
|
|
console.log('\n=== #1150 node-detail 404 state E2E against ' + BASE + ' ===');
|
|
|
|
await step('GET /api/nodes/<unknown> returns 404 (precondition)', async () => {
|
|
const res = await page.request.get(BASE + '/api/nodes/' + UNKNOWN_PUBKEY);
|
|
assert(res.status() === 404, 'expected 404, got ' + res.status());
|
|
});
|
|
|
|
await step('navigate to /#/nodes/{unknown} and let API call settle', async () => {
|
|
await page.goto(BASE + '/#/nodes/' + UNKNOWN_PUBKEY, { waitUntil: 'domcontentloaded' });
|
|
// Wait for the title to NOT be "Loading…" anymore (success or fixed error state).
|
|
await page.waitForFunction(() => {
|
|
const el = document.querySelector('.node-full-title');
|
|
return el && (el.textContent || '').trim() !== 'Loading…';
|
|
}, { timeout: 8000 }).catch(() => {});
|
|
});
|
|
|
|
await step('back-row title is NOT stuck on "Loading…"', async () => {
|
|
const title = await page.evaluate(() => {
|
|
const el = document.querySelector('.node-full-title');
|
|
return el ? (el.textContent || '').trim() : null;
|
|
});
|
|
assert(title !== null, '.node-full-title element missing');
|
|
assert(title !== 'Loading…', '#1150: title still stuck on "Loading…"');
|
|
// Title should mention "not found" or contain the pubkey prefix.
|
|
const lower = title.toLowerCase();
|
|
const hasErrorWord = lower.indexOf('not found') !== -1 || lower.indexOf('unknown') !== -1;
|
|
const hasPubkeyPrefix = title.indexOf(UNKNOWN_PUBKEY.slice(0, 8)) !== -1;
|
|
assert(hasErrorWord || hasPubkeyPrefix,
|
|
'title should indicate "not found"/"unknown" or include pubkey prefix; got: ' + JSON.stringify(title));
|
|
});
|
|
|
|
await step('body surfaces an error state mentioning the missing node', async () => {
|
|
const bodyText = await page.evaluate(() => {
|
|
const el = document.getElementById('nodeFullBody');
|
|
return el ? (el.textContent || '').toLowerCase() : '';
|
|
});
|
|
assert(bodyText.length > 0, '#nodeFullBody empty');
|
|
assert(
|
|
bodyText.indexOf('not found') !== -1 || bodyText.indexOf('unknown') !== -1,
|
|
'body should contain "not found" or "unknown"; got: ' + JSON.stringify(bodyText.slice(0, 200))
|
|
);
|
|
});
|
|
|
|
await step('body contains a link back to /#/nodes', async () => {
|
|
const hasBackLink = await page.evaluate(() => {
|
|
const body = document.getElementById('nodeFullBody');
|
|
if (!body) return false;
|
|
const anchors = body.querySelectorAll('a[href]');
|
|
for (const a of anchors) {
|
|
const href = a.getAttribute('href') || '';
|
|
if (href === '#/nodes' || href.endsWith('#/nodes')) return true;
|
|
}
|
|
return false;
|
|
});
|
|
assert(hasBackLink, 'expected a body anchor with href="#/nodes" (Back to Nodes link)');
|
|
});
|
|
|
|
await browser.close();
|
|
|
|
console.log('\n--- ' + passed + ' passed, ' + failed + ' failed ---\n');
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
})().catch((e) => { console.error(e); process.exit(1); });
|