Skip to content

Commit c8d3ef3

Browse files
authored
fix(e2e/helpers): navTo throws when the nav item is absent (TK-012) (#412)
Independent review: APPROVE. # Review #412 r2: TK-012, navTo throws when the menu item is missing Head 8b3cd21 (merges origin/master 90a2d36). Delta against the r1 review (412.md, CHANGES). Read-only detached worktree, no GitHub comment. ## What I ran | Check | Result | |---|---| | `tests/wave2/test-navto-missing-item.sh` on head | 7 of 7 ok, rc 0 | | same test against origin/master's `project-tests/e2e` | 4 FAIL (absent item, message, empty menu, walkthrough nav), rc 1 | | `bin/check-pr-discipline.sh origin/master` | clean | | Mutation: re-indent the closing brace of `case 'nav'` in a copy of the walkthrough | test crashes (SyntaxError, non-zero exit): loud, not green | | Mutation: remove the try/catch (master's walkthrough) | walkthrough case FAIL | ## r1 points | # | Asked | Status | |---|---|---| | 1 | Walkthrough `nav` case catches the throw and returns `step(meta, false, label, e.message)`; stub case | **Fixed.** Lines 208 to 210. The callers at 525/546 still decide on `s.fatal`, so a non-fatal missing item is a recorded failed step and the walk continues. Covered by the test. | | 2 | Message names user and visible items, separates journey fix from grant fix | **Fixed.** Visible `a[title]` values are collected in the same `evaluate`, deduped; empty menu reads `(none)`. Three test cases pin it. | | 3 | CHANGELOG: correct the monkey claim, name full-app-walkthrough | **Fixed.** Monkey "swallows the error and still checks `.mx-page`, so monkey is unchanged" matches `monkey.js:166-168`. Walkthrough named with the `fatal` rule. | | 4 | Impact Process row with the measured result plus the walkthrough change | **Fixed in substance.** Walkthrough change and design-audit `fault` rows are stated. Wording nit below. | ## The walkthrough test that regex-extracts the `nav` case Acceptable, no refactor required for this PR. Reasons: - It fails loud, not green. A layout change that breaks the regex gives `m = null` and an explicit FAIL; a changed brace indentation crashes the AsyncFunction constructor with a non-zero exit; removing the catch FAILs the case. I found no edit that keeps the test green while losing the behaviour. - The clean alternative (export `runStep` and guard the top-level IIFE at line 424 with `require.main === module`) changes how a 680-line entry script starts and pulls module-level state (`stoppedAt`, `cfg`, `PROJ`) into the test. That is wider than a 4-file fix. - The one real gap: a future free variable used on the failure path of the `nav` case (not passed as a parameter) would surface as a ReferenceError, again a loud FAIL. Suggest as a follow-up (not blocking): when the walkthrough is next touched, export `runStep` behind a `require.main` guard and replace the regex with a `require`. ## Nits (body only, no re-review needed) 1. Process row and Field evidence say "0 of 30 turn red, and the 4 broken controls ... now correctly fail". The 4 controls are inside the 30, so the sentence contradicts itself. Measured: 22 real journeys stay green (0 newly red), 4 home-page controls turn red as intended, 3 already red now fail earlier with a clearer cause, 1 placeholder unchanged. 2. Test-tier checkbox: "Run against master ... 2 of 3 pass" is stale. On master the test now prints 2 ok and 4 FAIL. ## Verdict: APPROVE All four r1 points are fixed and the behaviour is tested, including the walkthrough path. Fix the two body nits before marking ready.
1 parent 03d8116 commit c8d3ef3

4 files changed

Lines changed: 71 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Sections dated before 2026-09-19 predate the cycle and stay as they are. Named m
1919

2020
## Unreleased
2121

22+
- fix(e2e/helpers): **`navTo` throws `navigation item "<title>" not found` instead of clicking nothing.** A missing menu item was a silent no-op, so when the target page was also the persona's home page the landing guard stayed green and a broken-control journey (a control that must FAIL) passed. The parent group stays soft (an open flyout needs no click); the item itself must be found. The message names the active user and the visible menu items, so the reader can tell a renamed item (fix the journey) from a role that cannot open the page (fix the grants). Callers: journey steps fail with the message, design-audit rung 7 records a fault, full-app-walkthrough records a failed `nav` step (the walk stops only when the step is `fatal`), monkey's `land` swallows the error and still checks `.mx-page`, so monkey is unchanged. `tests/wave2/test-navto-missing-item.sh` (stub page, no browser) fails on master (absent item resolves) and passes here. Field report: a five-app lab project (Mendix 11.15, mxcli v0.26.0), TK-012 — MendixMau
2223
- learn(rest-between-mendix-apps): **new on-demand skill for two or more Mendix apps you build that read each other over REST (app-to-app, microservices).** The contract decisions to write down before the first script (pull vs push, versioned path, key + version rule, cursor paging, `since` with overlap, error shape incl. the runtime's 560, auth in the operation microflow as of mxcli v0.24 per BUG-152, fixed ports, one owner per fact), 17 publisher and consumer rules for honest "as of"/stale/"never read" states, and a six-rung cross-app test ladder with a per-change/slice/release cadence; a signal-stopped test run is BUG-157. The 26-row failure register behind it is `process/rest-between-mendix-apps-register-2026-10.md`. Routed ondemand for architect, mdl, test and review at stages 3–6. Field evidence: three demo apps, mxcli v0.24–v0.26, Mendix 11.15, 2026-10-07 to 2026-10-12, domain names generalised — MendixMau
2324
- fix(docs-numbering): **the pre-commit doc numbering check no longer fails every merge commit.** A merge stages all the other side's files, so the check examined docs the merge never touched and tripped on the existing "15-step" prose in `skills/source-triage.md:240` (plus two siblings that fail `--all`), which sent agents to `--no-verify`. During a merge it now examines only files that differ from both parents. The doc prose is left alone (an anecdote, not a drift). `tests/wave2/test-docs-numbering.sh` T11 fails on master's script. — agent report of `--no-verify` merges
2425
- fix(journey-runner): **a journey file without a string `id` now warns naming the file and uses its basename as the id, so captures are named `<basename>-stepN.png` instead of `undefined-stepN.png`; two journeys ending up with the same id (explicit, or a basename that collides with an explicit id) are refused with exit 2 before the browser opens, naming both files.** The only new refusal is a duplicate id; existing id-less journey files keep running. `journey-examples.md` field table updated ([#383](https://github.com/MendixMau/mxcli-project-toolkit/issues/383)) — joshuamoesa

‎project-tests/e2e/full-app-walkthrough.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,9 @@ async function runStep(page, meta, s) {
205205

206206
switch (s.do) {
207207
case 'nav': {
208-
await H.navTo(page, s.group ? subst(s.group) : null, subst(s.item));
208+
// A missing menu item is a recorded failed step; `fatal` alone decides whether the walk stops.
209+
try { await H.navTo(page, s.group ? subst(s.group) : null, subst(s.item)); }
210+
catch (e) { return step(meta, false, label, e.message); }
209211
await p(600);
210212
const ok = s.ready ? await vis(s.ready, 12000) : true;
211213
return step(meta, ok, label, ok ? '' : `.mx-name-${s.ready} never rendered after navigating to "${s.item}"`);

‎project-tests/e2e/helpers.js‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,21 @@ async function navTo(page, parentTitle, childTitle) {
487487
// journey died at step 1 (card-disbursement requirements-driven build, 2026-09-25).
488488
const a = [...document.querySelectorAll('.mx-navigationtree a, .mx-navbar a')]
489489
.find((x) => x.getAttribute('title') === title);
490-
if (a) { a.scrollIntoView({ block: 'nearest' }); a.click(); return true; }
491-
return false;
492-
}, t).catch(() => false);
490+
if (a) { a.scrollIntoView({ block: 'nearest' }); a.click(); return { ok: true, visible: [] }; }
491+
const visible = [...document.querySelectorAll('.mx-navigationtree a[title], .mx-navbar a[title]')]
492+
.map((x) => x.getAttribute('title')).filter((x, i, all) => x && all.indexOf(x) === i);
493+
return { ok: false, visible };
494+
}, t).catch(() => ({ ok: false, visible: [] }));
493495
if (parentTitle) { await clickTitle(parentTitle); await page.waitForTimeout(Math.round(500 / cfg.speed)); }
494-
await clickTitle(childTitle);
496+
// A missing target is a failure, not a no-op (TK-012): nothing was clicked, the landing
497+
// guard of a persona home page stays green, and a broken-control journey passes. The
498+
// parent stays soft (an open flyout needs no click); the item itself must be found.
499+
const hit = await clickTitle(childTitle);
500+
if (!hit.ok) {
501+
const seen = hit.visible.length ? hit.visible.join(', ') : '(none)';
502+
throw new Error(`navigation item "${childTitle}" not found for ${cfg.user}; visible: ${seen}. ` +
503+
`Renamed item (fix the journey), or this persona's role cannot open the target page (fix the role grants)`);
504+
}
495505
await page.waitForTimeout(Math.round(1500 / cfg.speed));
496506
await dismissModal(page);
497507
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
# Fixture: helpers.navTo throws when the nav item is absent (TK-012, field report from a
3+
# five-app lab project, Mendix 11.15, mxcli v0.26.0). Before: no item found -> nothing
4+
# clicked -> no error -> a broken-control journey on a home page passed.
5+
# Uses a stub page (evaluate = DOM lookup result), so no browser is needed.
6+
set -uo pipefail
7+
HERE="$(cd "$(dirname "$0")" && pwd)"
8+
E2E="${1:-$HERE/../../project-tests/e2e}"
9+
# config.js needs a project.config.js; the template is the shipped default.
10+
R="$(mktemp -d)"; trap 'rm -rf "$R"' EXIT; T="$R/tests/e2e"; mkdir -p "$T"; : > "$R/App.mpr"
11+
cp -R "$E2E/." "$T/"; [ -f "$T/project.config.js" ] || cp "$T/project.config.template.js" "$T/project.config.js"
12+
ALLOW_UNVERIFIED_APP=1 node - "$T" "$E2E" <<'JS'
13+
const path = require('path'); const fs = require('fs');
14+
const H = require(path.resolve(process.argv[2], 'helpers.js'));
15+
const mk = (found) => ({
16+
evaluate: async (fn, t) => (found.includes(t) ? { ok: true, visible: [] } : { ok: false, visible: found }),
17+
waitForTimeout: async () => {},
18+
locator: () => ({ first: () => ({ isVisible: async () => false }) }),
19+
});
20+
(async () => {
21+
let fail = 0;
22+
const ok = (c, m) => { console.log((c ? 'ok ' : 'FAIL ') + m); if (!c) fail++; };
23+
try { await H.navTo(mk(['Orders']), null, 'Orders'); ok(true, 'present item resolves'); }
24+
catch (e) { ok(false, 'present item resolves: ' + e.message); }
25+
try { await H.navTo(mk(['Orders']), null, 'Gone'); ok(false, 'absent item throws'); }
26+
catch (e) { ok(/navigation item "Gone" not found/.test(e.message), 'absent item throws a named error'); }
27+
try { await H.navTo(mk(['Orders', 'Suppliers']), null, 'Gone'); ok(false, 'message check'); }
28+
catch (e) {
29+
ok(/for \S+; visible: Orders, Suppliers\./.test(e.message), 'message names the user and the visible items');
30+
ok(/fix the journey/.test(e.message) && /role grants/.test(e.message), 'message separates journey fix from role-grant fix');
31+
}
32+
try { await H.navTo(mk([]), null, 'Gone'); ok(false, 'empty menu'); }
33+
catch (e) { ok(/visible: \(none\)/.test(e.message), 'empty menu reads (none)'); }
34+
// full-app-walkthrough: a missing item on a non-fatal step is a recorded failed step, not a throw.
35+
{
36+
const src = fs.readFileSync(path.resolve(process.argv[3], 'full-app-walkthrough.js'), 'utf8');
37+
const m = src.match(/case 'nav': \{([\s\S]*?)\n \}\n/);
38+
const body = m ? m[1] : '';
39+
const recorded = [];
40+
const fn = new (Object.getPrototypeOf(async function () {}).constructor)('H', 'page', 'meta', 's', 'label', 'subst', 'p', 'step', 'vis', body);
41+
let threw = null, rv;
42+
try {
43+
rv = await fn(H, mk(['Orders']), { steps: [] }, { do: 'nav', item: 'Gone' }, 'Open Gone', (x) => x, async () => {},
44+
(meta, okv, label, detail) => { recorded.push({ okv, label, detail }); return okv; }, async () => true);
45+
} catch (e) { threw = e; }
46+
ok(m && !threw && rv === false && recorded.length === 1 && recorded[0].okv === false && /not found/.test(recorded[0].detail),
47+
'walkthrough nav: missing item is a recorded failed step, no throw' + (threw ? ': ' + threw.message : ''));
48+
}
49+
try { await H.navTo(mk(['Orders']), 'Menu', 'Orders'); ok(true, 'absent parent, present item resolves'); }
50+
catch (e) { ok(false, 'absent parent is soft: ' + e.message); }
51+
process.exit(fail ? 1 : 0);
52+
})();
53+
JS

0 commit comments

Comments
 (0)