diff --git a/test/manual/ux/README.md b/test/manual/ux/README.md index c98c7830f..d59815ecf 100644 --- a/test/manual/ux/README.md +++ b/test/manual/ux/README.md @@ -11,6 +11,8 @@ fan-out of reviewer agents. Opt-in; nothing here runs in the gate. - `replies.py` is the fake model's script (`test/e2e/fake_provider.py`): a message with slow, hang, fail, tool, start jobs (three background jobs), start agents (three child agents), edit, think, code, table or long gets that kind of reply; anything else a short markdown one. +- `extensions_check.py` checks the global-only extension list, confirmation cancellation, global saves, stale writes and dependency refusal without selecting or creating a session. Run after `settings_check.py` on a disposable review. +- `settings_check.py` checks settings window deduplication/focus, category jumps and scroll tracking, cross-board drafts, saves, resets, stale edits, browser persistence and phone fallback through the real page (`await settings_check.check(ui)`). It changes settings, so use a disposable review run. - `kit.py` starts a run on a copy of the seed home and drives the page. `kit.scenarios()` lists the boards `load()` builds through the UI. diff --git a/test/manual/ux/extensions_check.py b/test/manual/ux/extensions_check.py new file mode 100644 index 000000000..3a8d4e71c --- /dev/null +++ b/test/manual/ux/extensions_check.py @@ -0,0 +1,139 @@ +"""Opt-in global Extensions UI checks against a disposable kit daemon. + +Run after settings_check has installed its no-credential settings-test profile. +The HTTP suite cannot catch accidental session controls or dependency-thread structure. +""" + +from __future__ import annotations + +from pathlib import Path + +import kit + + +async def check(ui: kit.Review) -> None: + """Edit global defaults without selecting, creating or reloading a session.""" + assert ui.home.resolve() != (Path.home() / ".albedo").resolve() + await ui.size(1440, 1000) + await ui.page.goto(ui.url) + + async def node(role: str, name: str): + await ui.js( + "() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done)))" + ) + return await ui.page.wait_for(role=role, name=name, exact=True) + + async def click(name: str) -> None: + await ui.page.click(await node("button", name)) + + async def api(method: str, path: str, body=None): + return await ui.js( + """async (method, path, body) => { + const headers = {accept:'application/json'}; + if (body !== null) headers['content-type'] = 'application/merge-patch+json'; + if (method === 'PATCH') headers['if-match'] = (await fetch('/api'+path)).headers.get('etag'); + const response = await fetch('/api'+path,{method,headers,...(body === null ? {} : {body:JSON.stringify(body)})}); + if (!response.ok) throw new Error(await response.text()); + return response.json(); + }""", + method, + path, + body, + ) + + before = await api("GET", "/sessions?scope=roots&limit=200") + original = await api("GET", "/settings?group=extensions") + await ui.key(",", kit.CTRL) + await click("extensions") + await node("button", "Disable skills globally") + assert not await ui.js( + "!!document.querySelector('[aria-label=\"Extension selection\"] select')" + ) + assert not await ui.js( + "!!document.querySelector('[aria-label=\"Extension selection\"] details')" + ) + assert await api("GET", "/sessions?scope=roots&limit=200") == before + assert await ui.js("""() => { + const rows = [...document.querySelectorAll('.threads article')]; + const ids = rows.map(row => row.getAttribute('aria-label')); + const skills = rows.find(row => row.getAttribute('aria-label') === 'Extension skills'); + const parent = skills.closest('li').parentElement.closest('li')?.querySelector(':scope > article'); + return new Set(ids).size === ids.length && parent?.getAttribute('aria-label') === 'Extension python'; + }""") + print( + "PASS global inventory loads once per extension with dependency thread ancestry, without sessions" + ) + view = await ui.js( + "document.querySelector('.svelte-flow__viewport').style.transform" + ) + wheel = await ui.js("""() => { + const content = document.querySelector('.settings .content'); + content.scrollTop = 0; + const r = content.getBoundingClientRect(); + return [r.x + r.width / 2, r.y + r.height / 2]; + }""") + await ui.wheel(wheel[0], wheel[1], 0, -180) + await ui.js("document.querySelector('.settings .content').scrollTop = 100") + await ui.wheel(wheel[0], wheel[1], 2, 180) + await node("button", "Disable skills globally") + assert await ui.js("document.querySelector('.settings .content').scrollTop") > 100 + await ui.js( + "const c = document.querySelector('.settings .content'); c.scrollTop = c.scrollHeight" + ) + await ui.wheel(wheel[0], wheel[1], 0, 180) + assert ( + await ui.js("document.querySelector('.svelte-flow__viewport').style.transform") + == view + ) + await ui.wheel(wheel[0], wheel[1], 0, -100, mods=kit.CTRL) + assert ( + await ui.js("document.querySelector('.svelte-flow__viewport').style.transform") + != view + ) + await ui.js("document.activeElement.blur()") + await ui.key("0", kit.SHIFT) + print( + "PASS settings scrolls without panning the canvas, including at edges; pinch still zooms" + ) + + await ui.page.fill(await node("searchbox", "Filter extensions"), "skills") + try: + await click("Disable skills globally") + await node("button", "Enable skills globally") + assert not await ui.js( + "[...document.querySelectorAll('button')].some(b => b.textContent.includes('Confirm'))" + ) + assert (await api("GET", "/settings?group=extensions"))["defaults"][ + "skills" + ] is False + assert await api("GET", "/sessions?scope=roots&limit=200") == before + print("PASS toggles change only global defaults") + + await api("PATCH", "/settings?group=extensions", {"defaults": {"skills": True}}) + await click("Enable skills globally") + await node("button", "Disable skills globally") + assert await ui.js( + "[...document.querySelectorAll('[role=alert]')].some(el => el.textContent.includes('choices changed elsewhere'))" + ) + assert (await api("GET", "/settings?group=extensions"))["defaults"][ + "skills" + ] is True + print("PASS stale writes refresh rather than overwrite global choices") + + await ui.page.fill(await node("searchbox", "Filter extensions"), "python") + await click("Disable python globally") + await node("alert", "") + assert await ui.js( + "[...document.querySelectorAll('[role=alert]')].some(el => /requir|depend/i.test(el.textContent))" + ) + assert ( + "python" not in (await api("GET", "/settings?group=extensions"))["defaults"] + ) + print("PASS dependency refusal leaves the global selection unchanged") + assert not await ui.errors(), await ui.errors() + finally: + await api( + "PATCH", + "/settings?group=extensions", + {"defaults": {"skills": original["defaults"].get("skills")}}, + ) diff --git a/test/manual/ux/settings_check.py b/test/manual/ux/settings_check.py new file mode 100644 index 000000000..d7c5bc501 --- /dev/null +++ b/test/manual/ux/settings_check.py @@ -0,0 +1,282 @@ +"""Settings through the real web client and private daemon (opt-in browser check). + +The HTTP E2E suite cannot exercise browser drafts, canvas window identity or +focus. Run on a disposable kit review, never a person's daemon: this changes +its settings. From an albedo kernel after building the client:: + + import sys; sys.path.insert(0, "test/manual/ux") + import kit, settings_check + ui = await kit.start("settings", dist=...) + try: + await settings_check.check(ui) + finally: + print(await ui.stop()) +""" + +from __future__ import annotations + +from pathlib import Path + +import kit + + +async def check(ui: kit.Review) -> None: + """Save and refuse conflicting edits without dropping browser-owned drafts.""" + assert ui.env["ALBEDO_HOME"] == str(ui.home) + assert ui.home.resolve() != (Path.home() / ".albedo").resolve() + await ui.media(reduced_motion=True) + + async def frame() -> None: + await ui.js( + "() => new Promise(done => requestAnimationFrame(() => requestAnimationFrame(done)))" + ) + + async def node(role: str, name: str): + await frame() + return await ui.page.wait_for( + role=role, + name=name, + exact=name not in {"extension config"}, + ) + + async def click(name: str) -> None: + await ui.page.click(await node("button", name)) + + async def fill(name: str, text: str) -> None: + await ui.page.fill( + await node( + "searchbox" if name == "Filter extension config" else "textbox", name + ), + text, + ) + + async def read(group: str): + return await ui.js( + """async (group) => { + const r = await fetch('/api/settings?group=' + group); + if (!r.ok) throw new Error(await r.text()); + return await r.json(); + }""", + group, + ) + + async def patch(group: str, value: dict) -> None: + result = await ui.js( + """async (group, value) => { + const url = '/api/settings?group=' + group; + const r = await fetch(url); + const saved = await fetch(url, {method:'PATCH', + headers:{'content-type':'application/merge-patch+json', 'if-match':r.headers.get('etag')}, + body:JSON.stringify(value)}); + return {status:saved.status, body:await saved.json()}; + }""", + group, + value, + ) + assert result["status"] == 200, result + + async def saved() -> None: + await ui.page.wait_for(role="status", name="Settings saved") + + # Add no-credential profiles pointing at a closed local port; no live provider. + await patch( + "providers", + { + "default_profile": "settings-test", + "profiles": { + name: { + "extension": "openai", + "endpoint": "http://127.0.0.1:1/v1", + "protocol": "chat_completions", + "model": "test-model", + } + for name in ("settings-test", "settings-other") + }, + }, + ) + await patch( + "extension_settings", + {"values": {"subagents": {"maxOpenChildren": None, "maxDepth": 3}}}, + ) + # Start closed, then use the same shortcut a person uses. + if await ui.js("!!document.querySelector('.window-slot[data-type=settings]')"): + await click("Close window") + if await ui.js("!!document.querySelector('.confirmation')"): + await click("discard changes and close") + await ui.key(",", kit.CTRL) + await node("region", "Settings") + await click("Settings") + await ui.key(",", kit.CTRL) + await frame() + assert ( + await ui.js( + "document.querySelectorAll('.window-slot[data-type=settings]').length" + ) + == 1 + ) + assert not await ui.js("!!document.querySelector('dialog[open]')") + assert await ui.js( + "!!document.activeElement.closest('.window-slot[data-type=settings]')" + ) + print("PASS config button and shortcut reuse and focus one canvas window") + before = await ui.js("localStorage.getItem('albedo.boards.v1')") + await ui.key("b") + assert await ui.js("localStorage.getItem('albedo.boards.v1')") == before + await ui.key("Tab") + assert await ui.js( + "!!document.activeElement.closest('.window-slot[data-type=settings]')" + ) + print("PASS settings controls do not trigger board shortcuts") + + await click("layout") + checkbox = await node("switch", "compact title bars") + was = checkbox["checked"] + # The switch paints its own knob; click its measured center as a pointer does. + point = await ui.js("""() => { + const r = document.querySelector('input[aria-label="compact title bars"]').getBoundingClientRect(); + return [r.x + r.width / 2, r.y + r.height / 2]; + }""") + await ui.click(*point) + await click("Close window") + await ui.page.goto(ui.url) + await click("Settings") + await node("region", "Settings") + await click("layout") + assert (await node("switch", "compact title bars"))["checked"] != was + print("PASS browser preferences survive reload") + + await click("login") + await ui.page.select( + await node("combobox", "New sessions start with"), "settings-other" + ) + await ui.page.wait_for( + role="combobox", name="New sessions start with", value="settings-other" + ) + assert (await read("providers"))["default_profile"] == "settings-other" + print( + "PASS the providers page saves where new sessions start as soon as it changes" + ) + await click("extension config") + await node("navigation", "Extension config categories") + assert await ui.js("""() => { + const nav = document.querySelector('[aria-label="Extension config categories"]'); + const names = [...nav.querySelectorAll('button')].map(b => b.textContent.trim()); + const headings = [...document.querySelectorAll('[data-category]')].map(h => h.textContent.trim()); + return JSON.stringify(names) === JSON.stringify(headings); + }""") + await click("Agents") + await frame() + assert ( + await ui.js( + "document.querySelector('.categories [aria-current]')?.textContent.trim()" + ) + == "Agents" + ) + wheel = await ui.js("""() => { + const root = document.querySelector('.settings .content'); + const r = root.getBoundingClientRect(); + const heading = document.querySelector('[data-category=context]').getBoundingClientRect(); + return [r.x + 50, r.y + 100, 0, heading.top - r.top - 16]; + }""") + await ui.wheel(*wheel) + await frame() + assert ( + await ui.js( + "document.querySelector('.categories [aria-current]')?.textContent.trim()" + ) + == "Context" + ) + print( + "PASS category outline follows page order, jumps, and tracks manual scrolling" + ) + await fill("Filter extension config", "Subagents") + assert await ui.js("document.querySelectorAll('.categories button').length") == 1 + await node("textbox", "Open children") + await fill("Open children", "14") + await click("New board") + await frame() + await click("Settings") + assert (await node("textbox", "Open children"))["value"] == "14" + assert ( + await ui.js( + "document.querySelectorAll('.window-slot[data-type=settings]').length" + ) + == 1 + ) + print("PASS reopening settings returns to its board and preserves the draft") + await click("extension config") + assert (await node("textbox", "Open children"))["value"] == "14" + await click("Close window") + await node("button", "discard changes and close") + await click("keep editing") + await click("Save") + await saved() + group = await read("extension_settings") + subagents = next(s for s in group["sections"] if s["name"] == "subagents") + assert ( + next(f for f in subagents["fields"] if f["key"] == "maxOpenChildren")["value"] + == 14 + ) + print("PASS section switches preserve drafts and saves reach the daemon") + + await fill("Open children", "15") + await patch("extension_settings", {"values": {"subagents": {"maxDepth": 4}}}) + await click("Save") + await node("button", "Discard my edits and reload") + assert (await node("textbox", "Open children"))["value"] == "15" + assert (await node("button", "Save"))["disabled"] + await click("Discard my edits and reload") + await ui.page.wait_for(role="textbox", name="Open children", value="14") + assert (await node("textbox", "Nesting depth"))["value"] == "4" + print("PASS stale saves retain edits and never overwrite another client's change") + + await fill("Open children", "0") + await click("Save") + await node("alert", "") + assert (await node("textbox", "Open children"))["value"] == "0" + await fill("Open children", "9" * 100) + assert (await node("button", "Save"))["disabled"] + await fill("Open children", "") + await click("Save") + await saved() + group = await read("extension_settings") + subagents = next(s for s in group["sections"] if s["name"] == "subagents") + assert ( + next(f for f in subagents["fields"] if f["key"] == "maxOpenChildren")["value"] + is None + ) + assert next(f for f in subagents["fields"] if f["key"] == "maxDepth")["value"] == 4 + print( + "PASS invalid values cannot save; reset restores inheritance only for that field" + ) + + await fill("Open children", "16") + await ui.js("document.activeElement.blur()") + await ui.key("w") + await node("button", "discard changes and close") + await click("discard changes and close") + await frame() + assert not await ui.js( + "!!document.querySelector('.window-slot[data-type=settings]')" + ) + assert not await ui.js("!!document.querySelector('.window-parking .settings')") + print("PASS window close shortcut protects drafts and releases the closed editor") + + await ui.size(390, 844) + await click("settings") + await node("dialog", "Settings") + await click("extension config") + await click("Agents") + await frame() + assert await ui.js("""() => { + const dialog = document.querySelector('dialog'); + const active = dialog.querySelector('.categories [aria-current]'); + const heading = dialog.querySelector('[data-category=agents]').getBoundingClientRect(); + const outline = dialog.querySelector('.categories').getBoundingClientRect(); + return active?.textContent.trim() === 'Agents' && heading.top >= outline.bottom; + }""") + await click("Close settings") + await frame() + assert not await ui.js("!!document.querySelector('dialog[open]')") + print("PASS phones retain the full-screen settings view") + assert not await ui.errors(), await ui.errors()