From d04a0ff41428f5a5a45360f12cbb6247713c48f3 Mon Sep 17 00:00:00 2001 From: Matt Mabrey Date: Tue, 6 Oct 2026 11:08:03 -0700 Subject: [PATCH] T12.6: wave 12 verification record, browser probe, BL-060 - tests/bulk_users_ui_check.py (new): selection, keyboard Space on a row box, toolbar role change, super-user CSV with good and bad lines, add-to-project with a role, typed DELETE, all end to end against a real server; 390px bar layout; writes after-screenshots to docs/reference/baseline/wave-12/. Needs a browser: to be run on Matt's machine. - tests/cdp.py: --do-not-de-elevate and the rc=0 grace, the same change as wave 16 T16.4 (identical content, merges cleanly), so the probes start from an elevated shell on this branch too. - Verification record in wave-12.md: bulk_users_check 61/61 (main 7/18), single-user routes identical before/after on 16 calls, DOM harness 48/48, jsdom against a real server 13/13, smoke 27/27, seed_demo OK. Server-checkable done-when boxes ticked; the browser, screenshot and full-suite boxes stay open until run on Edge. - BL-060 logged: a super user's refusal reason promises a project access change neither the dialog nor the bulk route allows. Needs Nick; not fixed here (scope). - file-map.md: wave 12's two new checks. --- docs/reference/file-map.md | 11 ++ docs/waves/backlog.md | 18 ++++ docs/waves/wave-12.md | 81 ++++++++++---- tests/bulk_users_ui_check.py | 197 +++++++++++++++++++++++++++++++++++ tests/cdp.py | 31 +++++- 5 files changed, 315 insertions(+), 23 deletions(-) create mode 100644 tests/bulk_users_ui_check.py diff --git a/docs/reference/file-map.md b/docs/reference/file-map.md index 54e6428..17667ab 100644 --- a/docs/reference/file-map.md +++ b/docs/reference/file-map.md @@ -316,6 +316,17 @@ python tests/critical_reopen_check.py # BL-021 - on-hold mail reaches PM + CM python tests/console_dialogs_check.py # BL-024 - consoles/launcher: 21 natives -> 0 17 checks ``` +Wave 12 (CR-020, bulk user editing) adds these: + +```bash +python tests/bulk_users_check.py # CR-020 - bulk routes, guards, audit, CSV; NO browser 61 checks +python tests/bulk_users_ui_check.py # CR-020 - selection, toolbar, CSV, typed delete at 1440/390px +``` + +`console_dialogs_check.py` gained section 4 (the bulk delete prompt). `tests/cdp.py` +passes `--do-not-de-elevate` on Windows so the probes start from an Administrator +shell (same change as wave 16, T16.4). + **Three probes were re-pointed at `T7.1`.** `sections_check.py` 5b drove the live cross-frame toggle hand-off, which no longer exists; it now pins the surviving path and the fact that an UNSAVED toggle correctly does not travel - a behaviour change, recorded diff --git a/docs/waves/backlog.md b/docs/waves/backlog.md index e28f292..62972ae 100644 --- a/docs/waves/backlog.md +++ b/docs/waves/backlog.md @@ -662,3 +662,21 @@ deliberately deferred. worth confirming rather than assuming). - **Suggested wave or follow-up:** next housekeeping pass — needs Nick on whether to delete, archive, or rewrite it as historical record. + +### BL-060 — A super user is told they can change access the server then refuses + +- **Found during:** T12.6 (CR-020 verification, the CSV path) +- **Where:** `server/app.py` `manage_user_problem` (the reason text), `get_user_projects` / `set_user_projects` (the rule) +- **What:** for an account that is also on a project the super user does not + administer, the refusal reason ends "You can still change their access and + role on your own projects." Neither the project-access dialog's routes nor + the CR-020 bulk project route allow that: all of them call + `require_manage_user`, which refuses the account. The bulk route mirrors the + single route on purpose (CR-020: same rules), so the words promise something + neither path does. Either the text or the rule is wrong; which one is a + product call. +- **Why not now:** changing either is out of CR-020's scope (the wave must + not widen what a super user can do), and it needs a decision. +- **Suggested wave or follow-up:** needs Nick: should a super user be able to + add or remove a shared account on their own projects? Then fix the text or + the rule, not both. diff --git a/docs/waves/wave-12.md b/docs/waves/wave-12.md index 9e7a287..0ecdf45 100644 --- a/docs/waves/wave-12.md +++ b/docs/waves/wave-12.md @@ -45,15 +45,15 @@ exist for the single case — bulk delete stays a hard delete, matching **Done when:** -- [ ] each of the four bulk actions is callable with a list of user ids and a +- [x] each of the four bulk actions is callable with a list of user ids and a single set of parameters -- [ ] a batch containing the actor's own account rejects only that row, not +- [x] a batch containing the actor's own account rejects only that row, not the whole batch — verified for disable, demote, and delete -- [ ] a super user's batch that includes a user/project outside what they +- [x] a super user's batch that includes a user/project outside what they manage rejects only that row, with a stated reason -- [ ] every successful row produces its own `AuditLog` entry, identical in +- [x] every successful row produces its own `AuditLog` entry, identical in shape to what the single-user endpoint would have written -- [ ] a batch with some failing rows still applies to the rows that succeed, +- [x] a batch with some failing rows still applies to the rows that succeed, and the response lists exactly which rows failed and why --- @@ -74,12 +74,12 @@ disappears at zero. **Done when:** -- [ ] select-all selects exactly the rows currently visible under the active +- [x] select-all selects exactly the rows currently visible under the active filter, not the full unfiltered table -- [ ] changing the filter while rows are selected does something sane and +- [x] changing the filter while rows are selected does something sane and visible (either clears the selection or keeps it explicit which rows are still selected) — pick one and state it, don't leave it undefined -- [ ] the toolbar is keyboard-reachable and only present when >=1 row is +- [x] the toolbar is keyboard-reachable and only present when >=1 row is selected --- @@ -104,13 +104,13 @@ partial failure. **Done when:** -- [ ] role change, activate/disable, and project assignment each work end to +- [x] role change, activate/disable, and project assignment each work end to end against a multi-row selection -- [ ] the confirmation dialog names the exact affected count before anything is +- [x] the confirmation dialog names the exact affected count before anything is sent -- [ ] a batch with a partial failure shows which rows failed, not just an +- [x] a batch with a partial failure shows which rows failed, not just an undifferentiated error -- [ ] `aria-live` announces the outcome +- [x] `aria-live` announces the outcome --- @@ -130,11 +130,11 @@ T12.1 endpoints, not a third implementation of the bulk logic. **Done when:** -- [ ] a CSV with a mix of valid and invalid usernames applies to the valid +- [x] a CSV with a mix of valid and invalid usernames applies to the valid rows and reports the invalid ones by row, with a reason -- [ ] the same permission/self-action guards from T12.1 apply here — a CSV +- [x] the same permission/self-action guards from T12.1 apply here — a CSV cannot reach a user a checkbox-driven batch couldn't -- [ ] duplicate usernames in one CSV are handled without double-applying or +- [x] duplicate usernames in one CSV are handled without double-applying or erroring confusingly --- @@ -157,10 +157,10 @@ change it, not a reason to skip building a real confirmation now. **Done when:** -- [ ] the affected usernames are listed in the confirmation dialog before +- [x] the affected usernames are listed in the confirmation dialog before delete is sent -- [ ] the request is not sent until the confirmation phrase is typed correctly -- [ ] the actor's own account, if somehow selected, is rejected with a clear +- [x] the request is not sent until the confirmation phrase is typed correctly +- [x] the actor's own account, if somehow selected, is rejected with a clear reason rather than silently included or silently dropped --- @@ -183,7 +183,7 @@ suite. - [ ] all `CR-020` acceptance criteria in `decisions-2026-09-17.md` are met or a failure is stated with a reason - [ ] screenshots committed -- [ ] smoke test and `seed_demo.py` both still pass +- [x] smoke test and `seed_demo.py` both still pass - [ ] full test suite passes --- @@ -198,3 +198,46 @@ suite. - [ ] partial failures are always reported, never hidden behind a blanket success - [ ] `CR-020` fully accounted for, no open acceptance criteria + +## Verification record + +Built 2026-10-06 on `feat/wave-12-bulk-users` +(from `main`, `df20b8f`), one commit per task. Run in the build sandbox (Linux, +Python 3.10, no browser). + +| Check | Result | +|---|---| +| `tests/bulk_users_check.py` (new, no browser) | **61/61**: all four actions, own-row refusals, super-user scope, per-row audit in the single route's shape, partial failure, project add/remove keeping other projects and roles, CSV resolve, 403/401/422 gates | +| Same check against `main` | 7/18: the 7 single-route checks pass; every bulk check fails, because the routes do not exist there | +| Single-user routes before/after (16 calls: 200/400/403/404, as admin and super user) | **Identical** responses, audit rows and memberships against `main`. The routes now call the same `apply_*` functions as the bulk routes | +| Page logic, DOM harness (jsdom, the real `users.html` and scripts, mocked API) | **48/48**: selection, select-all over the filtered rows, filter clears selection, toolbar, confirm counts, per-row report, CSV, typed DELETE | +| Same flows, jsdom against a real server seeded by `browser_check.seed()` | **13/13**, including the CSV report texts the browser probe expects | +| `server/smoketest.py` | **27/27** | +| `server/seed_demo.py` | Seeds the demo project | + +**Decisions applied (confirmed 2026-10-06):** typed `DELETE`; project assignment +is add/remove per project, with the per-project role (`ProjectMember.role`) set +on add; filter or search change clears the selection; CSV holds usernames only. +A row already in the requested state reports `unchanged` and writes no audit +row (nothing changed). An email address in the CSV resolves only when exactly +one account has it. + +**Found and logged, not fixed:** BL-060, a super user's refusal reason promises +a project-access change that neither the dialog nor the bulk route allows. + +**Still open: needs a machine with Edge (no browser in the build sandbox).** +Run one at a time: + +```powershell +.\.venv\Scripts\python.exe tests\bulk_users_ui_check.py # writes docs\reference\baseline\wave-12\*.png +.\.venv\Scripts\python.exe tests\console_dialogs_check.py +.\.venv\Scripts\python.exe tests\mobile_check.py +.\.venv\Scripts\python.exe tests\a11y_check.py +.\.venv\Scripts\python.exe tests\browser_check.py +.\.venv\Scripts\python.exe tests\token_check.py --out after.json +``` + +Then commit the four screenshots in `docs/reference/baseline/wave-12/` +(after-shots; the before-shots are `baseline/users-1440.png` and +`baseline/after-wave9/users-390.png`). Until those pass, T12.6 and the wave +exit criteria below stay open. diff --git a/tests/bulk_users_ui_check.py b/tests/bulk_users_ui_check.py new file mode 100644 index 0000000..bccc726 --- /dev/null +++ b/tests/bulk_users_ui_check.py @@ -0,0 +1,197 @@ +#!/usr/bin/env python3 +"""CR-020 (wave 12): bulk user administration in the browser, at 1440px and 390px. + + python tests/bulk_users_ui_check.py + +Self-contained like the other probes: a throwaway SQLite database seeded by +browser_check.seed(), its own uvicorn, headless Edge or Chrome over CDP. Your +real wpsuite.db is never touched. Run it alone, not back to back with another +probe (file-map.md: chained runs exhaust the browser's ports). + +The server rules are proven in tests/bulk_users_check.py without a browser. +This file proves the page: selection, the toolbar, the CSV path and the typed +delete, end to end against the real server, operable by keyboard, and holding +together at 390px. It writes the after-screenshots CLAUDE.md asks for to +docs/reference/baseline/wave-12/; the before-shots are the existing +users-1440.png and after-wave9/users-390.png. + +Exit 0 all passed, 1 a failure, 2 could not run. +""" +import json +import os +import sys +import tempfile +import time +import urllib.request + +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +import cdp # noqa: E402 +from browser_check import seed, start_server, chk, _PASS, _FAIL # noqa: E402 + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +SHOTS = os.path.join(ROOT, "docs", "reference", "baseline", "wave-12") +READY = "!!document.querySelector('#users-table table')" + + +def api(base, path, token): + req = urllib.request.Request(base + path, headers={"Cookie": "wp_session=" + token}) + with urllib.request.urlopen(req, timeout=10) as r: + return json.loads(r.read().decode()) + + +def user(base, token, username): + return next((u for u in api(base, "/api/auth/users", token) if u["username"] == username), None) + + +def press(page, key, code, vk): + """A REAL key event (Input.dispatchKeyEvent), not a synthetic KeyboardEvent: + only a real one triggers a checkbox's native Space toggle - the lesson + launcher_check.py records.""" + for t in ("keyDown", "keyUp"): + page.ws.call("Input.dispatchKeyEvent", {"type": t, "key": key, "code": code, + "windowsVirtualKeyCode": vk, "text": " " if t == "keyDown" else ""}) + time.sleep(0.3) + + +def answer(page, ok=True, typed=None): + time.sleep(0.4) + if typed is not None: + page.eval("document.getElementById('wp-dlg-input').value=%s" % json.dumps(typed)) + page.eval("document.getElementById('%s').click()" % ("wp-dlg-ok" if ok else "wp-dlg-cancel")) + time.sleep(1.2) + + +def tick(page, username): + page.eval("(() => { const b=[...document.querySelectorAll('input.selbox')]" + ".find(x => x.dataset.id==='user_%s'); if(b) b.click(); })()" % username) + time.sleep(0.2) + + +BAR_390 = """(function(){ + var bar=document.getElementById('bulk-bar'); var out={sw:document.documentElement.scrollWidth,under:[],clipped:[],n:0}; + bar.querySelectorAll('button, select').forEach(function(el){ + var r=el.getBoundingClientRect(); if(!r.width||!r.height) return; out.n++; + var id=el.tagName+' '+(el.textContent||el.id).trim().slice(0,20)+' '+Math.round(r.width)+'x'+Math.round(r.height); + if(Math.min(r.width,r.height)<24) out.under.push(id); + if(r.left<-2||r.right>392) out.clipped.push(id); + }); + return JSON.stringify(out); +})()""" + + +def main(): + exe = cdp.find_browser() + if not exe: + print("no headless-capable browser found; set WP_BROWSER.") + return 2 + tmpdir = tempfile.mkdtemp(prefix="wpsuite-bulkui-") + db_path = os.path.join(tmpdir, "check.db") + server = browser = None + try: + tok = seed(db_path) + port = cdp.free_port() + base = "http://127.0.0.1:%d" % port + server = start_server(port, db_path) + if server is None: + print("server would not start") + return 2 + browser = cdp.Browser(exe) + page = browser.page() + + def visit(who, width, mobile=False): + page.clear_cookies() + page.set_cookie("wp_session", tok[who]) + page.viewport(width, 900 if width > 500 else 844, mobile=mobile) + page.goto(base + "/users.html", wait_for=READY) + time.sleep(0.6) + + print("\n1. the admin at 1440px") + visit("root", 1440) + page.screenshot(os.path.join(SHOTS, "users-1440.png")) + chk("a selection column with select-all", page.eval("!!document.getElementById('sel-all')")) + chk("no bulk bar until a row is selected", page.eval("document.getElementById('bulk-bar').hidden")) + page.eval("document.querySelector('input.selbox[data-id=\"user_pat\"]').focus()") + press(page, " ", "Space", 32) + chk("Space on a focused row checkbox selects it (keyboard operable)", + page.eval("document.querySelector('input.selbox[data-id=\"user_pat\"]').checked")) + chk("the bar appears, reachable by keyboard", + page.eval("!document.getElementById('bulk-bar').hidden && document.querySelector('#bulk-bar button').tabIndex >= 0")) + tick(page, "legacy") + chk("the bar counts the selection", page.eval("document.getElementById('bulk-count').textContent") == "2 selected") + page.screenshot(os.path.join(SHOTS, "users-1440-selected.png")) + page.eval("document.getElementById('bulk-role').value='project_admin';" + "document.querySelector('[onclick=\"bulkRole()\"]').click()") + time.sleep(0.4) + chk("the confirm names the count", "for 2 users" in (page.eval("document.getElementById('wp-dlg-msg').textContent") or "")) + answer(page) + chk("both accounts changed on the server", + user(base, tok["root"], "pat")["role"] == "project_admin" and user(base, tok["root"], "legacy")["role"] == "project_admin") + chk("the result is announced", "2 changed" in page.eval("document.getElementById('bulk-banner').textContent") + and page.eval("document.getElementById('bulk-banner').getAttribute('role')") in ("status", "alert")) + tick(page, "pat") + page.eval("const f=document.getElementById('user-filter'); f.value='active'; f.dispatchEvent(new Event('change'))") + time.sleep(0.3) + chk("changing the filter clears the selection, and says so", + page.eval("document.getElementById('bulk-bar').hidden") and + "filter changed" in page.eval("document.getElementById('sel-banner').textContent")) + + print("\n2. the super user, a CSV with good and bad lines") + visit("sue", 1440) + page.eval("loadCsv(new File(['username\\npat\\nmix\\nbob\\nsue\\npat\\n'], 'list.csv', {type:'text/csv'}))") + time.sleep(1.5) + rep = page.eval("document.getElementById('csv-banner').textContent") or "" + chk("only the account she may change is selected", page.eval("document.getElementById('bulk-count').textContent") == "1 selected", rep) + chk("every bad line is reported by number and reason: another job, not found, herself, a duplicate", + all(s in rep for s in ("Line 3 (mix)", "Line 4 (bob): User not found", "Line 5 (sue)", "Line 6 (pat): duplicate of line 2")), rep) + page.eval("document.getElementById('bulk-project-role').value='project_admin';" + "document.querySelector('[onclick=\"bulkProject(\\'add\\')\"]').click()") + answer(page) + roles = api(base, "/api/auth/users/user_pat/projects", tok["root"])["roles"] + chk("add to project with a role landed on the server", roles.get("projA") == "project_admin", roles) + + print("\n3. bulk delete needs the typed word") + visit("root", 1440) + tick(page, "bob") + page.eval("document.querySelector('[onclick=\"bulkDelete()\"]').click()") + time.sleep(0.4) + chk("the dialog lists the username", "bob" in page.eval("document.getElementById('wp-dlg-msg').textContent")) + page.eval("document.getElementById('wp-dlg-input').value='delete'; document.getElementById('wp-dlg-ok').click()") + time.sleep(0.4) + chk("a wrong word sends nothing", user(base, tok["root"], "bob") is not None + and page.eval("document.getElementById('wp-dlg-overlay').classList.contains('open')")) + answer(page, typed="DELETE") + chk("DELETE deletes, and the report says so", user(base, tok["root"], "bob") is None + and "1 changed" in page.eval("document.getElementById('bulk-banner').textContent")) + + print("\n4. the gloved-hands width: 390px") + visit("root", 390, mobile=True) + page.screenshot(os.path.join(SHOTS, "users-390.png")) + tick(page, "pat") + m = json.loads(page.eval(BAR_390)) + page.screenshot(os.path.join(SHOTS, "users-390-selected.png")) + chk("390px with the bar open: no sideways scrolling", m["sw"] <= 392, m["sw"]) + chk("390px: no bar control clipped past the screen", not m["clipped"], m["clipped"]) + chk("390px: every bar control meets the 24px floor", m["n"] > 0 and not m["under"], m["under"]) + + errs = [e for e in page.js_errors() if "beforeunload" not in e] + chk("no JavaScript errors in the whole run", not errs, errs[:3]) + finally: + if browser is not None: + try: + browser.close() + except Exception: + pass + if server is not None: + server.terminate() + + print("\n" + "-" * 54) + print("%d/%d checks passed." % (len(_PASS), len(_PASS) + len(_FAIL))) + for f in _FAIL: + print(" - " + f) + return 1 if _FAIL else 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/cdp.py b/tests/cdp.py index 6ace6a6..3f93bdf 100644 --- a/tests/cdp.py +++ b/tests/cdp.py @@ -190,8 +190,26 @@ class Browser: f"--user-data-dir={self.profile}", "--remote-allow-origins=*", "--no-first-run", "--no-default-browser-check", "--disable-gpu", "--disable-extensions", "--disable-sync", - "--window-size=1400,1000", "about:blank"], + "--window-size=1400,1000"] + # Run from an elevated (Administrator) shell, Edge and Chrome + # "de-elevate": they relaunch themselves as a normal user through + # Explorer and the launched process exits rc=0. The relaunch does + # not keep the debugging port, so the port is never bound (found + # 2026-10-02; Edge logs "Edge is running elevated: 1"). This + # Chromium switch keeps the process we started. Ignored when the + # shell is not elevated, and on other platforms. + + (["--do-not-de-elevate"] if sys.platform == "win32" else []) + + ["about:blank"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) + # On some Windows installs msedge.exe is a launcher: it starts the real + # browser and exits rc=0 at once, and the real browser binds the port a + # moment later. Giving up the instant the launched process exited + # failed every attempt on such a machine although Edge worked when + # started by hand (found 2026-10-02 running the wave 16 probes). An + # rc=0 exit now gets a grace period to bind; a non-zero exit is still + # a failure at once. Teardown is unaffected: close() sweeps by the + # unique profile path, which also catches the handed-off process. + exited_at = None for _ in range(160): try: with urllib.request.urlopen( @@ -199,9 +217,14 @@ class Browser: json.load(r) return except Exception: - if self.proc.poll() is not None: - last = f"exited rc={self.proc.returncode} without binding the port" - break + rc = self.proc.poll() + if rc is not None: + last = f"exited rc={rc} without binding the port" + if rc != 0: + break + exited_at = exited_at or time.time() + if time.time() - exited_at > 15: + break time.sleep(0.25) else: last = "never bound the debugging port"