From a10601444838025c2180480f07ee2be7b58e0eac Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Sun, 15 Nov 2026 06:40:06 +0800 Subject: [PATCH 1/4] ci: FV3's pages in Chromium and Firefox on every Unraid row, every theme and width, the advanced preview's layout included browser_test.sh runs the fake Unraid with no network and the Playwright image in a container that joins it. browser_test.js checks the drawn folders, an opened folder and the advanced preview against values written by hand, and fails on any FV3 error; screenshots are kept as an artifact. The fake's log checks move to fake_logs.php for both tests. --- .coderabbit.yaml | 9 + .github/unraid-compat/browser_test.js | 229 ++++++++++++++++++++++++ .github/unraid-compat/browser_test.sh | 32 ++++ .github/unraid-compat/fake_logs.php | 42 +++++ .github/unraid-compat/package-lock.json | 26 +++ .github/unraid-compat/package.json | 8 + .github/unraid-compat/pages_test.php | 22 +-- .github/workflows/ci.yml | 24 +++ renovate.json | 14 ++ 9 files changed, 387 insertions(+), 19 deletions(-) create mode 100644 .github/unraid-compat/browser_test.js create mode 100644 .github/unraid-compat/browser_test.sh create mode 100644 .github/unraid-compat/fake_logs.php create mode 100644 .github/unraid-compat/package-lock.json create mode 100644 .github/unraid-compat/package.json diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 73a03c99..f10fccdd 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -226,6 +226,15 @@ reviews: docker and domain cfg). A call a stand-in does not answer fails the run: flag an answer that hides one, and any stand-in for code the webGUI repo has. + - browser_test.sh starts fake_unraid.sh in a container with no network + and runs the Playwright image in a second container that joins its + network. browser_test.js drives FV3's Docker, VMs and Dashboard + pages in Chromium and Firefox and checks what the user sees (rows, + tiles, an opened folder, the advanced preview's layout) against + values written by hand. A failed request or console error passes + only for a service the fake does not run (ABSENT) or for Unraid's + own unload handler. fake_logs.php holds the log checks both tests + run. package.json pins playwright-core to the image's version. - matrix_check.py keeps ci.yml's Unraid rows at one per minor from the .plg's min to the newest release; Renovate only moves rows. - Each step asserts what the user is left with (live files, the diff --git a/.github/unraid-compat/browser_test.js b/.github/unraid-compat/browser_test.js new file mode 100644 index 00000000..be0cc7e4 --- /dev/null +++ b/.github/unraid-compat/browser_test.js @@ -0,0 +1,229 @@ +// FV3's pages in Chromium and Firefox on the fake Unraid browser_test.sh started, every theme and width; a screenshot per view. +// Usage: node browser_test.js +'use strict'; +const fs = require('fs'); +const { chromium, firefox } = require('playwright-core'); + +const [version, shots, fakeToken] = process.argv.slice(2); +const base = 'http://127.0.0.1'; +const failures = []; +let checks = 0; +const check = (ok, what) => { checks++; if (!ok) failures.push(what); return ok; }; +const same = (got, want) => JSON.stringify(got) === JSON.stringify(want); + +const MEDIA = 'MediaAbCdEfGhIjKlMnO'; +const LAB = 'LabFoldAbCdEfGhIjKlM'; +const THEMES = ['black', 'white', 'azure', 'gray']; +const SIZES = [[1440, 900], [768, 1024], [400, 860]]; + +// Unraid's services the fake does not run. A failed request, or a console error naming one, passes only on its path here. +const ABSENT = [ + [/^\/sub\//, "Unraid's nchan push channels: the fake runs no nchan, so the page's live updates never connect"], + [/^\/graphql$/, "the Unraid API: the fake has none, so FV3's fv3DetectApi takes the PHP path"], +]; +const absent = (url) => { try { const path = new URL(url).pathname; return ABSENT.some(([re]) => re.test(path)); } catch { return false; } }; +// Chromium refuses every unload handler: Unraid's dynamix.js adds some, and on 7.0 the Docker and Dashboard pages' inline +// scripts too. From those sources the refusal is Unraid's, while FV3's shipped files add none +const plugin = `${__dirname}/../../src/folder.view3/usr/local/emhttp/plugins/folder.view3`; +const fv3Unload = fs.readdirSync(plugin, { recursive: true }).filter((f) => /\.(js|page|php)$/.test(f)) + .filter((f) => /(? { + if (fv3Unload.length || m.text() !== 'Permissions policy violation: unload is not allowed in this document.') return false; + try { return ['/webGui/javascript/dynamix.js', `/${page}`].includes(new URL(m.location()?.url).pathname); } catch { return false; } +}; + +// Each page's own rows, tiles and folders as the user sees them, read in the page: a folder as "name [members it shows]", a +// container or VM by its name +const READ = { + Docker: () => window.fv3Test.tableRows('docker_list', 'ct-name'), + VMs: () => { + // Each VM's detail row stays right after its VM, wherever FV3 moved the pair + const details = [...document.querySelectorAll('#kvm_list tr[child-id]')]; + const paired = details.filter((d) => d.previousElementSibling?.getAttribute('parent-id') === d.getAttribute('child-id')).length; + return { rows: window.fv3Test.tableRows('kvm_list', 'vm-name'), details: `${paired} of ${details.length} detail rows after their VM` }; + }, + Dashboard: () => { + const { seen, name } = window.fv3Test; + const tiles = (view) => [...document.querySelectorAll(`tbody#${view} > tr.updated > td > *`)].filter(seen).map((tile) => { + if (!tile.classList.contains('folder-showcase-outer')) return name(tile); + const members = [...tile.querySelectorAll('.folder-storage > span.outer, .folder-showcase > span.outer')]; + return `${tile.querySelector('.fv3-folder-appname').innerText.trim()} [${members.map(name).join(', ')}] shows [${members.filter(seen).map(name).join(', ')}]`; + }); + return { docker: tiles('docker_view'), vms: tiles('vm_view') }; + }, +}; + +// What fake_unraid.sh saved: Media holds app-a by hand and app-b by its label, Tools takes tool-c by regex, app-d is loose, Lab +// holds Debian 12; each list in Unraid's saved order +const WANT = { + Docker: { shut: ['Media [app-a, app-b]', 'Tools [tool-c]', 'app-d'], open: ['Media [app-a, app-b]', 'app-a', 'app-b', 'Tools [tool-c]', 'app-d'] }, + VMs: { + shut: { rows: ['Lab [Debian 12]', 'Home Assistant', 'Windows 11'], details: '3 of 3 detail rows after their VM' }, + open: { rows: ['Lab [Debian 12]', 'Debian 12', 'Home Assistant', 'Windows 11'], details: '3 of 3 detail rows after their VM' }, + }, + Dashboard: { + shut: { docker: ['Media [app-a, app-b] shows []', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, + open: { docker: ['Media [app-a, app-b] shows [app-a, app-b]', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, + }, +}; +// FV3's events for a finished draw; the folder each page opens, its event when open, and how a user opens it +const DRAWN = { Docker: ['docker-post-folders-creation'], VMs: ['vm-post-folders-creation'], Dashboard: ['docker-post-folders-creation', 'vm-post-folders-creation'] }; +const OPEN = { + Docker: ['Media', 'docker-post-folder-expansion', (p) => p.click(`button.dropDown-${MEDIA}`)], + VMs: ['Lab', 'vm-post-folder-expansion', (p) => p.click(`button.dropDown-${LAB}`)], + // The Dashboard opens a folder from its tile's menu; this is the call that menu entry makes (dashboard.js, its Expand item) + Dashboard: ['Media', 'docker-post-folder-expansion', (p) => p.evaluate((id) => expandFolderDocker(id), MEDIA)], +}; +// The first member of Media, and where a click opens its advanced preview once Media is open +const PREVIEWED = 'app-a'; +const PREVIEW = { Docker: `tr.folder-id-${MEDIA} .folder-preview span.hand[id^="folder-preview-"]`, Dashboard: `.folder-showcase-${MEDIA} > span.outer > span.hand` }; + +// Before the page's scripts: records FV3's draw and expansion events as they fire, and the readers' helpers. A display: contents +// element (FV3's Dashboard folders) is seen when a child is; a name is .inner's text before its first line break, drawn or not +function testHelpers() { + const events = []; + const dispatch = EventTarget.prototype.dispatchEvent; + EventTarget.prototype.dispatchEvent = function (event) { + if (/-post-folders?-(creation|expansion)$/.test(event.type)) events.push(event.type); + return dispatch.call(this, event); + }; + const seen = (el) => getComputedStyle(el).visibility !== 'hidden' + && (el.getClientRects().length > 0 || (getComputedStyle(el).display === 'contents' && [...el.children].some(seen))); + const name = (outer) => { + const before = []; + for (const node of outer.querySelector('.inner').childNodes) { if (node.nodeName === 'BR') break; before.push(node.textContent); } + return before.join('').trim(); + }; + const tableRows = (list, nameCell) => [...document.querySelectorAll(`#${list} > tr`)].filter(seen).map((row) => row.classList.contains('folder') + ? `${row.querySelector('.folder-appname').innerText.trim()} [${[...row.querySelectorAll('.folder-preview span.outer')].filter(seen).map(name).join(', ')}]` + : name(row.querySelector(`td.${nameCell} span.outer`))); + window.fv3Test = { events, seen, name, tableRows }; +} + +// The page's reading once two in a row agree: FV3 animates an opening and Unraid may reload a list after the first draw +async function settled(page, read, arg) { + let last = null; + for (let i = 0; i < 40; i++) { + const now = await page.evaluate(read, arg); + if (last !== null && same(now, last)) return now; + last = now; + await page.waitForTimeout(250); + } + throw new Error(`still changing after 10 s: ${JSON.stringify(last)}`); +} + +const waitEvents = (page, names) => page.waitForFunction((names) => names.every((n) => window.fv3Test.events.includes(n)), names, { timeout: 20000 }); + +// The popup's markup is indented HTML: with each blank text node set to one space nothing may move, as it does where Unraid's +// tooltip box keeps line breaks (7.4's .tooltipster-content white-space: pre-line) and FV3 does not reset it +function popupState(name) { + const base = [...document.querySelectorAll('.tooltipster-base')].find((b) => b.getClientRects().length && b.querySelector('.preview-outbox')); + if (!base) return { error: 'no advanced preview open' }; + const box = base.querySelector('.preview-outbox'); + const elements = [box, ...box.querySelectorAll('*')]; + const boxes = () => elements.map((e) => { const r = e.getBoundingClientRect(); return [r.top, r.left, r.width, r.height].map(Math.round).join(','); }); + const before = boxes(); + const blanks = []; + const walker = document.createTreeWalker(box, NodeFilter.SHOW_TEXT); + for (let node; (node = walker.nextNode());) if (node.data.trim() === '' && node.data !== ' ') blanks.push([node, node.data]); + blanks.forEach(([node]) => { node.data = ' '; }); + const after = boxes(); + blanks.forEach(([node, data]) => { node.data = data; }); + const moved = elements.filter((e, i) => before[i] !== after[i]); + const r = base.getBoundingClientRect(); + return { + named: box.innerText.includes(name), + blanks: blanks.length, + moved: moved.length ? `${moved.length} elements, first ${moved.slice(0, 3).map((e) => `${e.tagName.toLowerCase()}.${[...e.classList].join('.')}`).join(', ')}` : '', + inside: r.left >= 0 && r.right <= window.innerWidth + 1 ? '' : `left ${Math.round(r.left)}, right ${Math.round(r.right)} of ${window.innerWidth}`, + }; +} + +async function view(browser, kind, theme, [width, height], page) { + const where = `${kind} ${theme} ${width}px ${page}`; + const context = await browser.newContext({ viewport: { width, height } }); + await context.addInitScript(testHelpers); + const tab = await context.newPage(); + const errors = []; + tab.on('pageerror', (e) => errors.push(`page error: ${e.message}`)); + tab.on('console', (m) => { + if (m.type() !== 'error') return; + const urls = [m.location()?.url, ...(m.text().match(/\b(?:https?|wss?):\/\/[^\s'"]+/g) || [])].filter(Boolean); + if (!urls.some(absent) && !unraidUnload(m, page)) errors.push(`console error: ${m.text()} (${m.location()?.url || 'no source'})`); + }); + tab.on('response', (r) => { if (r.status() >= 400 && !absent(r.url())) errors.push(`${r.status()} for ${r.url()}`); }); + tab.on('requestfailed', (r) => { if (!absent(r.url())) errors.push(`request failed: ${r.url()} ${r.failure()?.errorText}`); }); + const file = `${shots}/${kind}/${theme}-${width}-${page}`; + try { + await tab.goto(`${base}/${page}`); + check(await tab.evaluate((t) => [...document.querySelectorAll('link[rel=stylesheet]')] + .some((l) => new RegExp(`/webGui/styles/(?:themes/|default-)${t}\\.css`).test(l.getAttribute('href'))), theme), `${where}: the ${theme} theme's stylesheet is not on the page`); + await waitEvents(tab, DRAWN[page]).catch(() => { throw new Error(`FV3 did not finish drawing within 20 s (${DRAWN[page].join(', ')})`); }); + let got = await settled(tab, READ[page]); + check(same(got, WANT[page].shut), `${where}: drawn as ${JSON.stringify(got)}, not ${JSON.stringify(WANT[page].shut)}`); + const [folder, opened, open] = OPEN[page]; + await open(tab); + await waitEvents(tab, [opened]).catch(() => { throw new Error(`${folder} did not open within 20 s (${opened})`); }); + got = await settled(tab, READ[page]); + check(same(got, WANT[page].open), `${where}: with ${folder} open, drawn as ${JSON.stringify(got)}, not ${JSON.stringify(WANT[page].open)}`); + await tab.screenshot({ path: `${file}.png`, fullPage: true }); + if (PREVIEW[page]) { + await tab.locator(PREVIEW[page]).first().click(); + await tab.waitForSelector('.tooltipster-base .preview-outbox', { state: 'visible', timeout: 10000 }) + .catch(() => { throw new Error('the advanced preview did not open within 10 s'); }); + // The popup fades in and draws its graph after it opens + const popup = await settled(tab, popupState, PREVIEWED); + if (popup.error) throw new Error(popup.error); + check(popup.named, `${where}: the advanced preview is not ${PREVIEWED}'s`); + check(!popup.moved, `${where}: the advanced preview draws its markup's line breaks: ${popup.moved} moved when ${popup.blanks} blank text nodes became one space`); + check(!popup.inside, `${where}: the advanced preview leaves the window: ${popup.inside}`); + await tab.screenshot({ path: `${file}-preview.png` }); + } + check(!(await tab.locator('.fv3-banner').count()), `${where}: FV3 shows a banner: ${await tab.locator('.fv3-banner').allInnerTexts()}`); + } catch (e) { + check(false, `${where}: ${e.message.split('\n')[0]}`); + await tab.screenshot({ path: `${file}-failed.png`, fullPage: true }).catch(() => {}); + } + check(!errors.length, `${where}:\n ${[...new Set(errors)].join('\n ')}`); + await context.close(); +} + +// A save as the page posts it; anything but a 200, or an FV3 answer without FV3's header, stops the run +async function post(request, path, form, what) { + const r = await request.post(`${base}${path}`, { form }); + if (r.status() !== 200 || (path.includes('folder.view3') && !r.headers()['x-fv3-answer'])) throw new Error(`${what}: status ${r.status()}, ${(await r.text()).slice(0, 200)}`); +} + +(async () => { + if (!fs.existsSync('/.dockerenv') || !fakeToken) { console.error('Run browser_test.sh: this needs the fake Unraid it starts'); process.exit(2); } + check(!fv3Unload.length, `FV3 adds an unload handler, which Chromium never runs: ${fv3Unload.join(', ')}`); + const browsers = { chromium: await chromium.launch(), firefox: await firefox.launch() }; + const setup = await browsers.chromium.newContext(); + const tab = await setup.newPage(); + await tab.goto(`${base}/Docker`); + // The token of the fake browser_test.sh started, so these writes never reach any other server on this loopback + const token = await tab.evaluate(() => typeof csrf_token === 'string' ? csrf_token : ''); + if (token !== fakeToken) { console.error(`127.0.0.1 is not the fake Unraid browser_test.sh started (token "${token}")`); process.exit(2); } + // Media as fake_unraid.sh saved it, with the advanced preview on + const saved = await setup.request.get(`${base}/plugins/folder.view3/server/read.php?type=docker`); + const media = saved.ok() ? (await saved.json())[MEDIA] : undefined; + if (!media) throw new Error(`no Media folder to turn the advanced preview on: status ${saved.status()}`); + await post(setup.request, '/plugins/folder.view3/server/update.php', { type: 'docker', id: MEDIA, csrf_token: token, + content: JSON.stringify({ ...media, settings: { ...media.settings, context: 2 } }) }, "Media's advanced preview"); + await post(setup.request, '/plugins/folder.view3/server/update_settings.php', { key: 'dashboard_context', value: '2', csrf_token: token }, "the Dashboard's advanced preview"); + for (const theme of THEMES) { + // As Unraid's Display Settings saves it + await post(setup.request, '/update.php', { '#file': 'dynamix/dynamix.cfg', '#section': 'display', theme, csrf_token: token }, `the ${theme} theme`); + for (const [kind, browser] of Object.entries(browsers)) { + fs.mkdirSync(`${shots}/${kind}`, { recursive: true }); + for (const size of SIZES) for (const page of ['Docker', 'VMs', 'Dashboard']) await view(browser, kind, theme, size, page); + } + } + await setup.close(); + for (const browser of Object.values(browsers)) await browser.close(); + if (failures.length) { + console.log(`FAILED [Unraid ${version}]: ${failures.length} of ${checks} browser checks\n- ${failures.join('\n- ')}`); + process.exit(1); + } + console.log(`Unraid ${version}: FV3's pages in Chromium and Firefox, ${THEMES.length} themes at ${SIZES.length} widths, passed (${checks} checks)`); +})().catch((e) => { console.log(`FAILED [Unraid ${version}]: ${e.message}`); process.exit(1); }); diff --git a/.github/unraid-compat/browser_test.sh b/.github/unraid-compat/browser_test.sh new file mode 100644 index 00000000..f29233dc --- /dev/null +++ b/.github/unraid-compat/browser_test.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# FV3's pages in Chromium and Firefox: the fake Unraid in a container with no network, the browsers in one that joins its network. +# From the repo root, after npm ci here: browser_test.sh +set -u +image=$1; tree=$2; version=$3; shots=$4 +# Renovate moves this with playwright-core in package.json: the driver only runs the browsers built for its own version +browsers=mcr.microsoft.com/playwright:v1.65.1-noble@sha256:1507cbfc550a63a6b7396791ca4f00df17beb56342d2447b3f106c306f525579 +fake=fv3-browser-test-$$ +fail() { echo "FAILED [Unraid $version]: $*"; exit 1; } +trap 'docker rm -f $fake >/dev/null 2>&1' EXIT + +[ -d .github/unraid-compat/node_modules/playwright-core ] || fail "no playwright-core: run npm ci in .github/unraid-compat first" +docker run -d --name $fake --network none -v "$PWD:/repo" -w /repo "$image" \ + bash -c 'bash .github/unraid-compat/fake_unraid.sh "$0" "$1" && touch /run/fv3-fake-up && exec sleep infinity' "$tree" "$version" \ + >/dev/null || fail 'the fake Unraid container did not start' +end=$((SECONDS + 120)) +until docker exec $fake test -f /run/fv3-fake-up 2>/dev/null; do + [ "$(docker inspect -f '{{.State.Running}}' $fake 2>/dev/null)" = true ] || fail "the fake Unraid stopped: $(docker logs $fake 2>&1 | tail -20)" + [ $SECONDS -lt $end ] || fail 'the fake Unraid was not up within 2 minutes' + sleep 0.5 +done +# browser_test.js writes only once the page it reaches carries this token +token=$(docker exec $fake php -d auto_prepend_file= -r 'echo parse_ini_file("/var/local/emhttp/var.ini")["csrf_token"] ?? "";') +[ -n "$token" ] || fail "no csrf_token in the fake's var.ini" + +mkdir -p "$shots" || fail "cannot make $shots" +docker run --rm --network container:$fake --shm-size=1g -v "$PWD:/repo:ro" -v "$(cd "$shots" && pwd):/shots" \ + -w /repo/.github/unraid-compat "$browsers" node browser_test.js "$version" /shots "$token" +status=$? +# The logs hold what the pages asked of Unraid's PHP and the fakes, for every run above +docker exec $fake php -d auto_prepend_file= -d display_errors=stderr .github/unraid-compat/fake_logs.php "$version" || status=1 +exit $status diff --git a/.github/unraid-compat/fake_logs.php b/.github/unraid-compat/fake_logs.php new file mode 100644 index 00000000..d9efa473 --- /dev/null +++ b/.github/unraid-compat/fake_logs.php @@ -0,0 +1,42 @@ +/dev/null that is missing goes unseen: only errors that reach php -S's log are caught +function fv3_fake_log_checks(): array { + $checks = []; + // fake_unraid.sh makes each log, FV3 its error.log on its first line: one that cannot be read fails, never "nothing logged" + $read = function (string $file, bool $mayBeAbsent = false) use (&$checks): array { + if ($mayBeAbsent && !file_exists($file)) return []; + $lines = @file($file, FILE_IGNORE_NEW_LINES); + $checks[] = [$lines !== false, "$file could not be read"]; + return $lines ?: []; + }; + // From 7.2 Unraid logs a .page's inline PHP as "in plugins/folder.view3/.page", with no leading slash + $phplog = $read('/var/log/phplog'); + $fv3Lines = preg_grep('#plugins/folder\.view3/#', $phplog); + $checks[] = [!$fv3Lines, "PHP logged from FV3's files:\n " . implode("\n ", array_slice($fv3Lines, 0, 20))]; + // No script died or failed an include: in Unraid's own code, a sign of state the fakes lack + $broken = preg_grep('/PHP Fatal error|Failed opening .* for inclusion/', $phplog); + $checks[] = [!$broken, "PHP died or missed a file:\n " . implode("\n ", array_slice(array_unique($broken), 0, 20))]; + // FV3's error log copies every warning raised in its requests, Unraid's too, by basename. With VM debug on, a real Unraid's + // libvirt.php adds one when it keys an array by a domain handle; any other line fails + $handleWarning = '/^\[[^]]+\] php-error: Resource ID#\d+ used as offset, casting to integer \(\d+\) at libvirt\.php:\d+$/'; + $reported = preg_grep($handleWarning, $read('/boot/config/plugins/folder.view3/error.log', true), PREG_GREP_INVERT); + $checks[] = [!$reported, "FV3's error.log:\n " . implode("\n ", $reported)]; + $unknown = preg_grep('/UNKNOWN/', $read('/var/log/fv3-fakes.log')); + $checks[] = [!$unknown, "the fakes were asked what they do not answer:\n " . implode("\n ", array_unique($unknown))]; + $missing = preg_grep('/command not found/', $read('/var/log/php-server.log')); + $checks[] = [!$missing, "the webGUI ran commands this image lacks:\n " . implode("\n ", array_unique($missing))]; + return $checks; +} + +// Run on its own (browser_test.sh): print what failed, exit 1 on any +if (PHP_SAPI === 'cli' && realpath($argv[0] ?? '') === __FILE__) { + if (!is_file('/.dockerenv') || !is_file('/var/run/fv3-fake-unraid')) { fwrite(STDERR, "Run in the container fake_unraid.sh set up\n"); exit(2); } + $version = $argv[1] ?? '?'; + $failed = array_column(array_filter(fv3_fake_log_checks(), fn($c) => !$c[0]), 1); + if ($failed) { + echo "FAILED [Unraid $version]: the fake Unraid's logs\n- " . implode("\n- ", $failed) . "\n"; + exit(1); + } + echo "Unraid $version: the fake Unraid's logs are clean\n"; +} diff --git a/.github/unraid-compat/package-lock.json b/.github/unraid-compat/package-lock.json new file mode 100644 index 00000000..702bb3fa --- /dev/null +++ b/.github/unraid-compat/package-lock.json @@ -0,0 +1,26 @@ +{ + "name": "folder-view3-unraid-browser-test", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "folder-view3-unraid-browser-test", + "devDependencies": { + "playwright-core": "1.65.1" + } + }, + "node_modules/playwright-core": { + "version": "1.65.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz", + "integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/.github/unraid-compat/package.json b/.github/unraid-compat/package.json new file mode 100644 index 00000000..2a7b95a1 --- /dev/null +++ b/.github/unraid-compat/package.json @@ -0,0 +1,8 @@ +{ + "name": "folder-view3-unraid-browser-test", + "private": true, + "description": "browser_test.js's driver; nothing here ships in the plugin. Its version must equal the Playwright image's in browser_test.sh", + "devDependencies": { + "playwright-core": "1.65.1" + } +} diff --git a/.github/unraid-compat/pages_test.php b/.github/unraid-compat/pages_test.php index d350dc1a..186ec117 100644 --- a/.github/unraid-compat/pages_test.php +++ b/.github/unraid-compat/pages_test.php @@ -239,25 +239,9 @@ function get_json(string $path, ?int &$status = null) { check($status === 200 && json_decode($body) !== null, "sync_order: status $status, $body"); $leaves('sync_order', ['autostart' => "app-a\napp-d 10\n"]); -// What the runs left in the logs: FV3's files must log nothing, no stand-in was asked anything it does not answer, and no -// command the webGUI ran was missing where the shell's error reached php -S's log (one run with 2>/dev/null fails unseen) -// From 7.2 Unraid logs a .page's inline PHP as "in plugins/folder.view3/.page", with no leading slash -$phplog = file('/var/log/phplog', FILE_IGNORE_NEW_LINES); -$fv3Lines = preg_grep('#plugins/folder\.view3/#', $phplog); -check(!$fv3Lines, "PHP logged from FV3's files:\n " . implode("\n ", array_slice($fv3Lines, 0, 20))); -// No script died or failed an include: in Unraid's own code, a sign of state the fakes lack -$broken = preg_grep('/PHP Fatal error|Failed opening .* for inclusion/', $phplog); -check(!$broken, "PHP died or missed a file:\n " . implode("\n ", array_slice(array_unique($broken), 0, 20))); -// FV3's error log copies every warning raised in its requests, Unraid's too, by basename. With VM debug on, a real Unraid's -// libvirt.php adds one when it keys an array by a domain handle; any other line fails -$errorLog = is_file("$flash/error.log") ? file("$flash/error.log", FILE_IGNORE_NEW_LINES) : []; -$handleWarning = '/^\[[^]]+\] php-error: Resource ID#\d+ used as offset, casting to integer \(\d+\) at libvirt\.php:\d+$/'; -$reported = $errorLog === false ? ['error.log could not be read'] : preg_grep($handleWarning, $errorLog, PREG_GREP_INVERT); -check(!$reported, "FV3's error.log:\n " . implode("\n ", $reported)); -$unknown = preg_grep('/UNKNOWN/', file('/var/log/fv3-fakes.log', FILE_IGNORE_NEW_LINES)); -check(!$unknown, "the fakes were asked what they do not answer:\n " . implode("\n ", array_unique($unknown))); -$missing = preg_grep('/command not found/', file('/var/log/php-server.log', FILE_IGNORE_NEW_LINES)); -check(!$missing, "the webGUI ran commands this image lacks:\n " . implode("\n ", array_unique($missing))); +// What the runs left in the logs +require __DIR__ . '/fake_logs.php'; +foreach (fv3_fake_log_checks() as [$ok, $what]) check($ok, $what); if ($failures) { echo "FAILED [Unraid $version]: " . count($failures) . " of $checks checks\n- " . implode("\n- ", $failures) . "\n"; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2c5905cb..ff1c6217 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -221,6 +221,30 @@ jobs: UNRAID_VERSION: ${{ matrix.unraid }} run: docker run --rm --network none -v "$PWD:/repo" -w /repo fv3-unraid bash .github/unraid-compat/pages_test.sh .webgui "$UNRAID_VERSION" + - name: Set up Node + if: ${{ (success() || failure()) && env.RUNS == 'true' }} + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: 26 + + # Runs after a failed step above too: this one checks what the pages draw + - name: FV3's pages in Chromium and Firefox, every theme at desktop, tablet and phone widths + if: ${{ (success() || failure()) && env.RUNS == 'true' }} + timeout-minutes: 20 + env: + UNRAID_VERSION: ${{ matrix.unraid }} + run: | + (cd .github/unraid-compat && npm ci --ignore-scripts --no-audit --no-fund) + bash .github/unraid-compat/browser_test.sh fv3-unraid .webgui "$UNRAID_VERSION" "$RUNNER_TEMP/screenshots" + + - name: Keep the browsers' screenshots + if: ${{ always() && env.RUNS == 'true' }} + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: screenshots-unraid-${{ matrix.unraid }} + path: ${{ runner.temp }}/screenshots + retention-days: 14 + # One check per matrix for beta's branch protection: the version rows rename themselves as Renovate moves them php-compat: name: PHP compatibility diff --git a/renovate.json b/renovate.json index ab655f85..084ed7a3 100644 --- a/renovate.json +++ b/renovate.json @@ -54,6 +54,15 @@ "datasourceTemplate": "git-refs", "packageNameTemplate": "https://github.com/{{{depName}}}", "depTypeTemplate": "bundled" + }, + { + "customType": "regex", + "description": "The Playwright image browser_test.sh runs the browsers in, by tag and digest.", + "managerFilePatterns": ["/^\\.github/unraid-compat/browser_test\\.sh$/"], + "matchStrings": [ + "browsers=(?mcr\\.microsoft\\.com/playwright):(?v[0-9.]+-noble)@(?sha256:[a-f0-9]{64})" + ], + "datasourceTemplate": "docker" } ], "packageRules": [ @@ -102,6 +111,11 @@ "matchFileNames": [".github/scripts/package.json"], "matchPackageNames": ["jquery"], "allowedVersions": "<4" + }, + { + "description": "playwright-core drives only the browsers of its own release, so it moves with the Playwright image in one PR.", + "matchPackageNames": ["playwright-core", "mcr.microsoft.com/playwright"], + "groupName": "Playwright" } ] } From 0c5f72113b6b7dfaa60cd1585586e6d48e64aecf Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Sun, 15 Nov 2026 08:58:43 +0800 Subject: [PATCH 2/4] ci: browser checks open folders as a user does, count only members a user can see, and stop a stuck run - Folders open by their chevron or the Dashboard tile's menu; a click is dispatched only where Unraid's layout covers it - A member must be visible, not transparent or clipped away; every banner shown is recorded - Failures print as they happen, a view has 90 s, and 3 undrawn views in a row stop the run - An empty folder whose name must be escaped; the driver's version is checked against the image's - The fake's flash folder must exist before its error.log is read; node_modules stays out of the image --- .coderabbit.yaml | 7 +- .github/unraid-compat/.dockerignore | 1 + .github/unraid-compat/browser_test.js | 160 +++++++++++++++++++------- .github/unraid-compat/browser_test.sh | 26 +++-- .github/unraid-compat/fake_logs.php | 8 +- .github/unraid-compat/pages_test.php | 4 +- .github/workflows/ci.yml | 8 +- 7 files changed, 147 insertions(+), 67 deletions(-) create mode 100644 .github/unraid-compat/.dockerignore diff --git a/.coderabbit.yaml b/.coderabbit.yaml index f10fccdd..d50cecb2 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -233,8 +233,11 @@ reviews: tiles, an opened folder, the advanced preview's layout) against values written by hand. A failed request or console error passes only for a service the fake does not run (ABSENT) or for Unraid's - own unload handler. fake_logs.php holds the log checks both tests - run. package.json pins playwright-core to the image's version. + own unload handler. Clicks are a user's; only where Unraid's own + layout covers the target is the click dispatched instead. + fake_logs.php holds the log checks both tests run. package.json + pins playwright-core to the image's version, which + browser_test.sh checks. - matrix_check.py keeps ci.yml's Unraid rows at one per minor from the .plg's min to the newest release; Renovate only moves rows. - Each step asserts what the user is left with (live files, the diff --git a/.github/unraid-compat/.dockerignore b/.github/unraid-compat/.dockerignore new file mode 100644 index 00000000..3c3629e6 --- /dev/null +++ b/.github/unraid-compat/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/.github/unraid-compat/browser_test.js b/.github/unraid-compat/browser_test.js index be0cc7e4..75ea84a1 100644 --- a/.github/unraid-compat/browser_test.js +++ b/.github/unraid-compat/browser_test.js @@ -1,4 +1,4 @@ -// FV3's pages in Chromium and Firefox on the fake Unraid browser_test.sh started, every theme and width; a screenshot per view. +// FV3's pages in Chromium and Firefox on the fake Unraid browser_test.sh started, 4 themes at 3 widths, screenshots kept. // Usage: node browser_test.js 'use strict'; const fs = require('fs'); @@ -8,11 +8,13 @@ const [version, shots, fakeToken] = process.argv.slice(2); const base = 'http://127.0.0.1'; const failures = []; let checks = 0; -const check = (ok, what) => { checks++; if (!ok) failures.push(what); return ok; }; +// Each failure prints as it happens, so a run the step's time limit kills still shows what failed +const check = (ok, what) => { checks++; if (!ok) { failures.push(what); console.log(`- ${what}`); } return ok; }; const same = (got, want) => JSON.stringify(got) === JSON.stringify(want); const MEDIA = 'MediaAbCdEfGhIjKlMnO'; const LAB = 'LabFoldAbCdEfGhIjKlM'; +const SPARE = 'Spare & '; const THEMES = ['black', 'white', 'azure', 'gray']; const SIZES = [[1440, 900], [768, 1024], [400, 860]]; @@ -21,15 +23,23 @@ const ABSENT = [ [/^\/sub\//, "Unraid's nchan push channels: the fake runs no nchan, so the page's live updates never connect"], [/^\/graphql$/, "the Unraid API: the fake has none, so FV3's fv3DetectApi takes the PHP path"], ]; -const absent = (url) => { try { const path = new URL(url).pathname; return ABSENT.some(([re]) => re.test(path)); } catch { return false; } }; -// Chromium refuses every unload handler: Unraid's dynamix.js adds some, and on 7.0 the Docker and Dashboard pages' inline -// scripts too. From those sources the refusal is Unraid's, while FV3's shipped files add none +const pathOf = (url) => { try { return new URL(url).pathname; } catch { return ''; } }; +const absent = (url) => ABSENT.some(([re]) => re.test(pathOf(url))); +// Chromium refuses every unload handler: Unraid's dynamix.js adds some, and 7.0's inline page scripts. From dynamix.js or the +// page itself the refusal is Unraid's while FV3's shipped files add none, which fv3Unload checks const plugin = `${__dirname}/../../src/folder.view3/usr/local/emhttp/plugins/folder.view3`; const fv3Unload = fs.readdirSync(plugin, { recursive: true }).filter((f) => /\.(js|page|php)$/.test(f)) .filter((f) => /(? { if (fv3Unload.length || m.text() !== 'Permissions policy violation: unload is not allowed in this document.') return false; - try { return ['/webGui/javascript/dynamix.js', `/${page}`].includes(new URL(m.location()?.url).pathname); } catch { return false; } + return ['/webGui/javascript/dynamix.js', `/${page}`].includes(pathOf(m.location()?.url)); +}; +// A console error from FV3's files is never excused; elsewhere, by its source or a URL in its text (trailing punctuation dropped) +const excused = (m, page) => { + const from = m.location()?.url || ''; + if (pathOf(from).startsWith('/plugins/folder.view3/')) return false; + const urls = [from, ...(m.text().match(/\b(?:https?|wss?):\/\/[^\s'"]+/g) || []).map((u) => u.replace(/[.,;:)]+$/, ''))]; + return urls.some(absent) || unraidUnload(m, page); }; // Each page's own rows, tiles and folders as the user sees them, read in the page: a folder as "name [members it shows]", a @@ -53,26 +63,32 @@ const READ = { }, }; -// What fake_unraid.sh saved: Media holds app-a by hand and app-b by its label, Tools takes tool-c by regex, app-d is loose, Lab -// holds Debian 12; each list in Unraid's saved order +// fake_unraid.sh's setup in Unraid's saved order: Media holds app-a by hand and app-b by its label, Tools takes tool-c by regex, +// app-d is loose, Lab holds Debian 12. The empty folder made below is in no saved order, so FV3 draws it first const WANT = { - Docker: { shut: ['Media [app-a, app-b]', 'Tools [tool-c]', 'app-d'], open: ['Media [app-a, app-b]', 'app-a', 'app-b', 'Tools [tool-c]', 'app-d'] }, + Docker: { + shut: [`${SPARE} []`, 'Media [app-a, app-b]', 'Tools [tool-c]', 'app-d'], + open: [`${SPARE} []`, 'Media [app-a, app-b]', 'app-a', 'app-b', 'Tools [tool-c]', 'app-d'], + }, VMs: { shut: { rows: ['Lab [Debian 12]', 'Home Assistant', 'Windows 11'], details: '3 of 3 detail rows after their VM' }, open: { rows: ['Lab [Debian 12]', 'Debian 12', 'Home Assistant', 'Windows 11'], details: '3 of 3 detail rows after their VM' }, }, Dashboard: { - shut: { docker: ['Media [app-a, app-b] shows []', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, - open: { docker: ['Media [app-a, app-b] shows [app-a, app-b]', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, + shut: { docker: [`${SPARE} [] shows []`, 'Media [app-a, app-b] shows []', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, + open: { docker: [`${SPARE} [] shows []`, 'Media [app-a, app-b] shows [app-a, app-b]', 'Tools [tool-c] shows []', 'app-d'], vms: ['Lab [Debian 12] shows []', 'Home Assistant', 'Windows 11'] }, }, }; // FV3's events for a finished draw; the folder each page opens, its event when open, and how a user opens it const DRAWN = { Docker: ['docker-post-folders-creation'], VMs: ['vm-post-folders-creation'], Dashboard: ['docker-post-folders-creation', 'vm-post-folders-creation'] }; const OPEN = { - Docker: ['Media', 'docker-post-folder-expansion', (p) => p.click(`button.dropDown-${MEDIA}`)], - VMs: ['Lab', 'vm-post-folder-expansion', (p) => p.click(`button.dropDown-${LAB}`)], - // The Dashboard opens a folder from its tile's menu; this is the call that menu entry makes (dashboard.js, its Expand item) - Dashboard: ['Media', 'docker-post-folder-expansion', (p) => p.evaluate((id) => expandFolderDocker(id), MEDIA)], + Docker: ['Media', 'docker-post-folder-expansion', (p) => press(p.locator(`button.dropDown-${MEDIA}`), "Media's chevron")], + VMs: ['Lab', 'vm-post-folder-expansion', (p) => press(p.locator(`button.dropDown-${LAB}`), "Lab's chevron")], + // The tile's menu, the item FV3's lang pack labels 'expand' + Dashboard: ['Media', 'docker-post-folder-expansion', async (p) => { + await press(p.locator(`#folder-id-${MEDIA}`), "Media's tile"); + await press(p.locator('ul.dropdown-context:visible li > a', { hasText: await p.evaluate(() => $.i18n('expand')) }), "its menu's Expand"); + }], }; // The first member of Media, and where a click opens its advanced preview once Media is open const PREVIEWED = 'app-a'; @@ -87,8 +103,23 @@ function testHelpers() { if (/-post-folders?-(creation|expansion)$/.test(event.type)) events.push(event.type); return dispatch.call(this, event); }; - const seen = (el) => getComputedStyle(el).visibility !== 'hidden' - && (el.getClientRects().length > 0 || (getComputedStyle(el).display === 'contents' && [...el.children].some(seen))); + // Seen: drawn, not transparent or hidden, and not clipped away by an overflow: hidden/clip ancestor (scrolling ones are reachable) + const seen = (el) => { + if (getComputedStyle(el).display === 'contents') return [...el.children].some(seen); + if (!el.checkVisibility({ opacityProperty: true, visibilityProperty: true })) return false; + let { left, right, top, bottom } = el.getBoundingClientRect(); + for (let a = el.parentElement; a && right > left && bottom > top; a = a.parentElement) { + const style = getComputedStyle(a), box = a.getBoundingClientRect(); + if (/hidden|clip/.test(style.overflowX)) { left = Math.max(left, box.left); right = Math.min(right, box.right); } + if (/hidden|clip/.test(style.overflowY)) { top = Math.max(top, box.top); bottom = Math.min(bottom, box.bottom); } + } + return right > left && bottom > top; + }; + // Every FV3 banner shown, kept after the page removes it + const banners = []; + new MutationObserver((changes) => changes.forEach((c) => c.addedNodes.forEach((n) => { + if (n.nodeType === 1 && n.matches('.fv3-banner, :has(.fv3-banner)')) banners.push(n.textContent.trim()); + }))).observe(document, { childList: true, subtree: true }); const name = (outer) => { const before = []; for (const node of outer.querySelector('.inner').childNodes) { if (node.nodeName === 'BR') break; before.push(node.textContent); } @@ -97,7 +128,7 @@ function testHelpers() { const tableRows = (list, nameCell) => [...document.querySelectorAll(`#${list} > tr`)].filter(seen).map((row) => row.classList.contains('folder') ? `${row.querySelector('.folder-appname').innerText.trim()} [${[...row.querySelectorAll('.folder-preview span.outer')].filter(seen).map(name).join(', ')}]` : name(row.querySelector(`td.${nameCell} span.outer`))); - window.fv3Test = { events, seen, name, tableRows }; + window.fv3Test = { events, seen, name, tableRows, banners }; } // The page's reading once two in a row agree: FV3 animates an opening and Unraid may reload a list after the first draw @@ -112,6 +143,27 @@ async function settled(page, read, arg) { throw new Error(`still changing after 10 s: ${JSON.stringify(last)}`); } +// A user's click, the target scrolled to the middle first. When something lies over it, FV3's own element fails the view; Unraid's +// (7.0's fixed sidebar themes cover the left of the page below desktop width) gets the click dispatched to the target instead +async function press(locator, what) { + await locator.evaluate((el) => el.scrollIntoView({ block: 'center', inline: 'center' })); + try { + await locator.click({ timeout: 5000 }); + } catch (e) { + const cover = await locator.evaluate((el) => { + if (!window.fv3Test.seen(el)) return null; + const r = el.getBoundingClientRect(); + const top = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); + if (!top || el.contains(top)) return null; + for (let n = top; n && n !== document.body; n = n.parentElement) if ([...n.classList].some((c) => /^(fv3|folder-)/.test(c))) return `FV3's ${n.tagName.toLowerCase()}.${[...n.classList].join('.')}`; + return ''; + }); + if (cover === null) throw new Error(`${what} could not be clicked: ${e.message.split('\n')[0]}`); + if (cover) throw new Error(`${what} is covered by ${cover}`); + await locator.dispatchEvent('click'); + } +} + const waitEvents = (page, names) => page.waitForFunction((names) => names.every((n) => window.fv3Test.events.includes(n)), names, { timeout: 20000 }); // The popup's markup is indented HTML: with each blank text node set to one space nothing may move, as it does where Unraid's @@ -139,26 +191,41 @@ function popupState(name) { }; } +// A page whose script never yields stalls page.evaluate, which has no timeout: past this the view fails, not the step's time limit +const VIEW_LIMIT = 90000; + +// One page in one browser, theme and width; false when it ended before FV3 drew async function view(browser, kind, theme, [width, height], page) { const where = `${kind} ${theme} ${width}px ${page}`; - const context = await browser.newContext({ viewport: { width, height } }); - await context.addInitScript(testHelpers); - const tab = await context.newPage(); - const errors = []; - tab.on('pageerror', (e) => errors.push(`page error: ${e.message}`)); - tab.on('console', (m) => { - if (m.type() !== 'error') return; - const urls = [m.location()?.url, ...(m.text().match(/\b(?:https?|wss?):\/\/[^\s'"]+/g) || [])].filter(Boolean); - if (!urls.some(absent) && !unraidUnload(m, page)) errors.push(`console error: ${m.text()} (${m.location()?.url || 'no source'})`); - }); - tab.on('response', (r) => { if (r.status() >= 400 && !absent(r.url())) errors.push(`${r.status()} for ${r.url()}`); }); - tab.on('requestfailed', (r) => { if (!absent(r.url())) errors.push(`request failed: ${r.url()} ${r.failure()?.errorText}`); }); const file = `${shots}/${kind}/${theme}-${width}-${page}`; + const errors = []; + let context, tab, timer, drew = false; try { - await tab.goto(`${base}/${page}`); + context = await browser.newContext({ viewport: { width, height } }); + await context.addInitScript(testHelpers); + tab = await context.newPage(); + tab.on('pageerror', (e) => errors.push(`page error: ${e.message}`)); + tab.on('console', (m) => { if (m.type() === 'error' && !excused(m, page)) errors.push(`console error: ${m.text()} (${m.location()?.url || 'no source'})`); }); + tab.on('response', (r) => { if (r.status() >= 400 && !absent(r.url())) errors.push(`${r.status()} for ${r.url()}`); }); + tab.on('requestfailed', (r) => { if (!absent(r.url())) errors.push(`request failed: ${r.url()} ${r.failure()?.errorText}`); }); + await Promise.race([steps(), new Promise((_, reject) => { timer = setTimeout(() => reject(new Error(`the view took over ${VIEW_LIMIT / 1000} s`)), VIEW_LIMIT); })]); + } catch (e) { + check(false, `${where}: ${e.message.split('\n')[0]}`); + await tab?.screenshot({ path: `${file}-failed.png`, fullPage: true, timeout: 10000 }).catch(() => {}); + } finally { + clearTimeout(timer); + } + check(!errors.length, `${where}:\n ${[...new Set(errors)].join('\n ')}`); + await context?.close().catch(() => {}); + return drew; + + async function steps() { + const loaded = await tab.goto(`${base}/${page}`); + if (loaded?.status() !== 200) throw new Error(`/${page} answered ${loaded?.status()}`); check(await tab.evaluate((t) => [...document.querySelectorAll('link[rel=stylesheet]')] .some((l) => new RegExp(`/webGui/styles/(?:themes/|default-)${t}\\.css`).test(l.getAttribute('href'))), theme), `${where}: the ${theme} theme's stylesheet is not on the page`); await waitEvents(tab, DRAWN[page]).catch(() => { throw new Error(`FV3 did not finish drawing within 20 s (${DRAWN[page].join(', ')})`); }); + drew = true; let got = await settled(tab, READ[page]); check(same(got, WANT[page].shut), `${where}: drawn as ${JSON.stringify(got)}, not ${JSON.stringify(WANT[page].shut)}`); const [folder, opened, open] = OPEN[page]; @@ -168,7 +235,7 @@ async function view(browser, kind, theme, [width, height], page) { check(same(got, WANT[page].open), `${where}: with ${folder} open, drawn as ${JSON.stringify(got)}, not ${JSON.stringify(WANT[page].open)}`); await tab.screenshot({ path: `${file}.png`, fullPage: true }); if (PREVIEW[page]) { - await tab.locator(PREVIEW[page]).first().click(); + await press(tab.locator(PREVIEW[page]).first(), `${PREVIEWED}'s preview icon`); await tab.waitForSelector('.tooltipster-base .preview-outbox', { state: 'visible', timeout: 10000 }) .catch(() => { throw new Error('the advanced preview did not open within 10 s'); }); // The popup fades in and draws its graph after it opens @@ -179,13 +246,9 @@ async function view(browser, kind, theme, [width, height], page) { check(!popup.inside, `${where}: the advanced preview leaves the window: ${popup.inside}`); await tab.screenshot({ path: `${file}-preview.png` }); } - check(!(await tab.locator('.fv3-banner').count()), `${where}: FV3 shows a banner: ${await tab.locator('.fv3-banner').allInnerTexts()}`); - } catch (e) { - check(false, `${where}: ${e.message.split('\n')[0]}`); - await tab.screenshot({ path: `${file}-failed.png`, fullPage: true }).catch(() => {}); + const banners = await tab.evaluate(() => window.fv3Test.banners); + check(!banners.length, `${where}: FV3 showed a banner: ${banners.join(' | ')}`); } - check(!errors.length, `${where}:\n ${[...new Set(errors)].join('\n ')}`); - await context.close(); } // A save as the page posts it; anything but a 200, or an FV3 answer without FV3's header, stops the run @@ -200,8 +263,9 @@ async function post(request, path, form, what) { const browsers = { chromium: await chromium.launch(), firefox: await firefox.launch() }; const setup = await browsers.chromium.newContext(); const tab = await setup.newPage(); - await tab.goto(`${base}/Docker`); - // The token of the fake browser_test.sh started, so these writes never reach any other server on this loopback + const loaded = await tab.goto(`${base}/Docker`); + if (loaded?.status() !== 200) throw new Error(`/Docker answered ${loaded?.status()}, so the setup could not read Unraid's token`); + // lib.sh gives every fake this token and a real Unraid never has it, so no real server on this loopback is written to const token = await tab.evaluate(() => typeof csrf_token === 'string' ? csrf_token : ''); if (token !== fakeToken) { console.error(`127.0.0.1 is not the fake Unraid browser_test.sh started (token "${token}")`); process.exit(2); } // Media as fake_unraid.sh saved it, with the advanced preview on @@ -211,19 +275,29 @@ async function post(request, path, form, what) { await post(setup.request, '/plugins/folder.view3/server/update.php', { type: 'docker', id: MEDIA, csrf_token: token, content: JSON.stringify({ ...media, settings: { ...media.settings, context: 2 } }) }, "Media's advanced preview"); await post(setup.request, '/plugins/folder.view3/server/update_settings.php', { key: 'dashboard_context', value: '2', csrf_token: token }, "the Dashboard's advanced preview"); + // A folder with no members, named in characters a page must escape + await post(setup.request, '/plugins/folder.view3/server/create.php', { type: 'docker', csrf_token: token, + content: JSON.stringify({ name: SPARE, icon: '', regex: '', containers: [], settings: { preview: 1 }, actions: [] }) }, 'the empty folder'); + let undrawn = 0; for (const theme of THEMES) { // As Unraid's Display Settings saves it await post(setup.request, '/update.php', { '#file': 'dynamix/dynamix.cfg', '#section': 'display', theme, csrf_token: token }, `the ${theme} theme`); for (const [kind, browser] of Object.entries(browsers)) { fs.mkdirSync(`${shots}/${kind}`, { recursive: true }); - for (const size of SIZES) for (const page of ['Docker', 'VMs', 'Dashboard']) await view(browser, kind, theme, size, page); + for (const size of SIZES) for (const page of ['Docker', 'VMs', 'Dashboard']) { + undrawn = (await view(browser, kind, theme, size, page)) ? 0 : undrawn + 1; + if (undrawn === 3) throw new Error('3 views in a row ended before FV3 drew, so the rest were not run'); + } } } await setup.close(); for (const browser of Object.values(browsers)) await browser.close(); if (failures.length) { - console.log(`FAILED [Unraid ${version}]: ${failures.length} of ${checks} browser checks\n- ${failures.join('\n- ')}`); + console.log(`FAILED [Unraid ${version}]: ${failures.length} of ${checks} browser checks, each listed above`); process.exit(1); } console.log(`Unraid ${version}: FV3's pages in Chromium and Firefox, ${THEMES.length} themes at ${SIZES.length} widths, passed (${checks} checks)`); -})().catch((e) => { console.log(`FAILED [Unraid ${version}]: ${e.message}`); process.exit(1); }); +})().catch((e) => { + console.log(`FAILED [Unraid ${version}]: ${e.message.split('\n')[0]}${failures.length ? ` (after ${failures.length} failed checks, listed above)` : ''}`); + process.exit(1); +}); diff --git a/.github/unraid-compat/browser_test.sh b/.github/unraid-compat/browser_test.sh index f29233dc..7b41b87b 100644 --- a/.github/unraid-compat/browser_test.sh +++ b/.github/unraid-compat/browser_test.sh @@ -5,28 +5,30 @@ set -u image=$1; tree=$2; version=$3; shots=$4 # Renovate moves this with playwright-core in package.json: the driver only runs the browsers built for its own version browsers=mcr.microsoft.com/playwright:v1.65.1-noble@sha256:1507cbfc550a63a6b7396791ca4f00df17beb56342d2447b3f106c306f525579 -fake=fv3-browser-test-$$ fail() { echo "FAILED [Unraid $version]: $*"; exit 1; } -trap 'docker rm -f $fake >/dev/null 2>&1' EXIT +# Removes only the container this run made; one a killed run leaves stops within the hour (its sleep 3600) +fake= +trap '[ -z "$fake" ] || docker rm -f "$fake" >/dev/null 2>&1' EXIT -[ -d .github/unraid-compat/node_modules/playwright-core ] || fail "no playwright-core: run npm ci in .github/unraid-compat first" -docker run -d --name $fake --network none -v "$PWD:/repo" -w /repo "$image" \ - bash -c 'bash .github/unraid-compat/fake_unraid.sh "$0" "$1" && touch /run/fv3-fake-up && exec sleep infinity' "$tree" "$version" \ - >/dev/null || fail 'the fake Unraid container did not start' +driver=$(node -p "require('./.github/unraid-compat/node_modules/playwright-core/package.json').version" 2>/dev/null) +[[ $browsers == *":v$driver-"* ]] || fail "playwright-core ${driver:-is not installed (npm ci in .github/unraid-compat)}, but the browsers are ${browsers%@*}" +fake=$(docker run -d --network none -v "$PWD:/repo" -w /repo "$image" \ + bash -c 'bash .github/unraid-compat/fake_unraid.sh "$0" "$1" && touch /run/fv3-fake-up && exec sleep 3600' "$tree" "$version") \ + || fail 'the fake Unraid container did not start' end=$((SECONDS + 120)) -until docker exec $fake test -f /run/fv3-fake-up 2>/dev/null; do - [ "$(docker inspect -f '{{.State.Running}}' $fake 2>/dev/null)" = true ] || fail "the fake Unraid stopped: $(docker logs $fake 2>&1 | tail -20)" +until docker exec "$fake" test -f /run/fv3-fake-up 2>/dev/null; do + [ "$(docker inspect -f '{{.State.Running}}' "$fake" 2>/dev/null)" = true ] || fail "the fake Unraid stopped: $(docker logs "$fake" 2>&1 | tail -20)" [ $SECONDS -lt $end ] || fail 'the fake Unraid was not up within 2 minutes' sleep 0.5 done # browser_test.js writes only once the page it reaches carries this token -token=$(docker exec $fake php -d auto_prepend_file= -r 'echo parse_ini_file("/var/local/emhttp/var.ini")["csrf_token"] ?? "";') +token=$(docker exec "$fake" php -d auto_prepend_file= -r 'echo parse_ini_file("/var/local/emhttp/var.ini")["csrf_token"] ?? "";') [ -n "$token" ] || fail "no csrf_token in the fake's var.ini" mkdir -p "$shots" || fail "cannot make $shots" -docker run --rm --network container:$fake --shm-size=1g -v "$PWD:/repo:ro" -v "$(cd "$shots" && pwd):/shots" \ - -w /repo/.github/unraid-compat "$browsers" node browser_test.js "$version" /shots "$token" +docker run --rm --network container:"$fake" --shm-size=1g --user "$(id -u):$(id -g)" -e HOME=/tmp \ + -v "$PWD:/repo:ro" -v "$(cd "$shots" && pwd):/shots" -w /repo/.github/unraid-compat "$browsers" node browser_test.js "$version" /shots "$token" status=$? # The logs hold what the pages asked of Unraid's PHP and the fakes, for every run above -docker exec $fake php -d auto_prepend_file= -d display_errors=stderr .github/unraid-compat/fake_logs.php "$version" || status=1 +docker exec "$fake" php -d auto_prepend_file= -d display_errors=stderr .github/unraid-compat/fake_logs.php "$version" || status=1 exit $status diff --git a/.github/unraid-compat/fake_logs.php b/.github/unraid-compat/fake_logs.php index d9efa473..916309c3 100644 --- a/.github/unraid-compat/fake_logs.php +++ b/.github/unraid-compat/fake_logs.php @@ -1,6 +1,10 @@ /dev/null that is missing goes unseen: only errors that reach php -S's log are caught + +// FV3's flash folder in the fake, as lib.sh's $flash names it +const FV3T_FLASH = '/boot/config/plugins/folder.view3'; + function fv3_fake_log_checks(): array { $checks = []; // fake_unraid.sh makes each log, FV3 its error.log on its first line: one that cannot be read fails, never "nothing logged" @@ -20,7 +24,9 @@ function fv3_fake_log_checks(): array { // FV3's error log copies every warning raised in its requests, Unraid's too, by basename. With VM debug on, a real Unraid's // libvirt.php adds one when it keys an array by a domain handle; any other line fails $handleWarning = '/^\[[^]]+\] php-error: Resource ID#\d+ used as offset, casting to integer \(\d+\) at libvirt\.php:\d+$/'; - $reported = preg_grep($handleWarning, $read('/boot/config/plugins/folder.view3/error.log', true), PREG_GREP_INVERT); + // No error.log means nothing logged only while its folder is there + $checks[] = [is_dir(FV3T_FLASH), FV3T_FLASH . ' is missing, so its error.log was never read']; + $reported = preg_grep($handleWarning, $read(FV3T_FLASH . '/error.log', true), PREG_GREP_INVERT); $checks[] = [!$reported, "FV3's error.log:\n " . implode("\n ", $reported)]; $unknown = preg_grep('/UNKNOWN/', $read('/var/log/fv3-fakes.log')); $checks[] = [!$unknown, "the fakes were asked what they do not answer:\n " . implode("\n ", array_unique($unknown))]; diff --git a/.github/unraid-compat/pages_test.php b/.github/unraid-compat/pages_test.php index 186ec117..93c7c332 100644 --- a/.github/unraid-compat/pages_test.php +++ b/.github/unraid-compat/pages_test.php @@ -45,7 +45,8 @@ function get_json(string $path, ?int &$status = null) { return json_decode($body, true); } -$flash = '/boot/config/plugins/folder.view3'; +require __DIR__ . '/fake_logs.php'; +$flash = FV3T_FLASH; $media = 'MediaAbCdEfGhIjKlMnO'; $tools = 'ToolsPqRsTuVwXyZaBcD'; $lab = 'LabFoldAbCdEfGhIjKlM'; @@ -240,7 +241,6 @@ function get_json(string $path, ?int &$status = null) { $leaves('sync_order', ['autostart' => "app-a\napp-d 10\n"]); // What the runs left in the logs -require __DIR__ . '/fake_logs.php'; foreach (fv3_fake_log_checks() as [$ok, $what]) check($ok, $what); if ($failures) { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ff1c6217..6d5fbd4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -221,13 +221,7 @@ jobs: UNRAID_VERSION: ${{ matrix.unraid }} run: docker run --rm --network none -v "$PWD:/repo" -w /repo fv3-unraid bash .github/unraid-compat/pages_test.sh .webgui "$UNRAID_VERSION" - - name: Set up Node - if: ${{ (success() || failure()) && env.RUNS == 'true' }} - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: 26 - - # Runs after a failed step above too: this one checks what the pages draw + # Runs after a failed step above too: this one checks what the pages draw. The runner's own npm installs the driver - name: FV3's pages in Chromium and Firefox, every theme at desktop, tablet and phone widths if: ${{ (success() || failure()) && env.RUNS == 'true' }} timeout-minutes: 20 From 532fdc97ab4f939c2de9d5073c704d7b1fd959bc Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Sun, 15 Nov 2026 09:37:46 +0800 Subject: [PATCH 3/4] ci: a click is dispatched only where Unraid's 7.0 sidebar covers it; any other cover fails by name --- .coderabbit.yaml | 5 +++-- .github/unraid-compat/browser_test.js | 17 +++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index d50cecb2..4d3ef96d 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -233,8 +233,9 @@ reviews: tiles, an opened folder, the advanced preview's layout) against values written by hand. A failed request or console error passes only for a service the fake does not run (ABSENT) or for Unraid's - own unload handler. Clicks are a user's; only where Unraid's own - layout covers the target is the click dispatched instead. + own unload handler. Clicks are a user's; only where an element of + Unraid's page frame named in FRAME covers the target is the click + dispatched instead. fake_logs.php holds the log checks both tests run. package.json pins playwright-core to the image's version, which browser_test.sh checks. diff --git a/.github/unraid-compat/browser_test.js b/.github/unraid-compat/browser_test.js index 75ea84a1..2f97d827 100644 --- a/.github/unraid-compat/browser_test.js +++ b/.github/unraid-compat/browser_test.js @@ -143,21 +143,26 @@ async function settled(page, read, arg) { throw new Error(`still changing after 10 s: ${JSON.stringify(last)}`); } -// A user's click, the target scrolled to the middle first. When something lies over it, FV3's own element fails the view; Unraid's -// (7.0's fixed sidebar themes cover the left of the page below desktop width) gets the click dispatched to the target instead +// Unraid's own page frame. A click it covers is dispatched to the target; any other cover fails the view +const FRAME = [ + ['#menu', "7.0's azure and gray sidebar: fixed at the left edge, it lies over the page below desktop width"], +]; + +// A user's click, the target scrolled to the middle first async function press(locator, what) { await locator.evaluate((el) => el.scrollIntoView({ block: 'center', inline: 'center' })); try { await locator.click({ timeout: 5000 }); } catch (e) { - const cover = await locator.evaluate((el) => { + const cover = await locator.evaluate((el, frame) => { if (!window.fv3Test.seen(el)) return null; const r = el.getBoundingClientRect(); const top = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); if (!top || el.contains(top)) return null; - for (let n = top; n && n !== document.body; n = n.parentElement) if ([...n.classList].some((c) => /^(fv3|folder-)/.test(c))) return `FV3's ${n.tagName.toLowerCase()}.${[...n.classList].join('.')}`; - return ''; - }); + if (frame.some((selector) => top.closest(selector))) return ''; + const n = top.closest('[id], [class]') || top; + return `${n.tagName.toLowerCase()}${n.id ? `#${n.id}` : ''}${[...n.classList].map((c) => `.${c}`).join('')}`; + }, FRAME.map(([selector]) => selector)); if (cover === null) throw new Error(`${what} could not be clicked: ${e.message.split('\n')[0]}`); if (cover) throw new Error(`${what} is covered by ${cover}`); await locator.dispatchEvent('click'); From f3436d986e7eac6c0fb27037eaedc0470234b528 Mon Sep 17 00:00:00 2001 From: chodeus <190988615+chodeus@users.noreply.github.com> Date: Sun, 15 Nov 2026 10:58:20 +0800 Subject: [PATCH 4/4] ci: the advanced preview must be visible, fit the window's width and lie where the page can scroll to --- .github/unraid-compat/browser_test.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/unraid-compat/browser_test.js b/.github/unraid-compat/browser_test.js index 2f97d827..42c4ec52 100644 --- a/.github/unraid-compat/browser_test.js +++ b/.github/unraid-compat/browser_test.js @@ -187,12 +187,15 @@ function popupState(name) { const after = boxes(); blanks.forEach(([node, data]) => { node.data = data; }); const moved = elements.filter((e, i) => before[i] !== after[i]); - const r = base.getBoundingClientRect(); + // Within the window's width, and nowhere the page cannot scroll to: a clicked popup stays open and in place while the page scrolls + const r = base.getBoundingClientRect(), top = r.top + scrollY, bottom = r.bottom + scrollY, page = document.documentElement.scrollHeight; + const fits = r.left >= 0 && r.right <= innerWidth + 1 && top >= 0 && bottom <= page + 1; return { + seen: window.fv3Test.seen(box), named: box.innerText.includes(name), blanks: blanks.length, moved: moved.length ? `${moved.length} elements, first ${moved.slice(0, 3).map((e) => `${e.tagName.toLowerCase()}.${[...e.classList].join('.')}`).join(', ')}` : '', - inside: r.left >= 0 && r.right <= window.innerWidth + 1 ? '' : `left ${Math.round(r.left)}, right ${Math.round(r.right)} of ${window.innerWidth}`, + inside: fits ? '' : `left ${Math.round(r.left)}, right ${Math.round(r.right)} of the window's ${innerWidth}; top ${Math.round(top)}, bottom ${Math.round(bottom)} of the page's ${page}`, }; } @@ -246,9 +249,11 @@ async function view(browser, kind, theme, [width, height], page) { // The popup fades in and draws its graph after it opens const popup = await settled(tab, popupState, PREVIEWED); if (popup.error) throw new Error(popup.error); + // Playwright's visible ignores opacity: a popup tooltipster leaves transparent opens to nothing + if (!popup.seen) throw new Error('the advanced preview opened but cannot be seen'); check(popup.named, `${where}: the advanced preview is not ${PREVIEWED}'s`); check(!popup.moved, `${where}: the advanced preview draws its markup's line breaks: ${popup.moved} moved when ${popup.blanks} blank text nodes became one space`); - check(!popup.inside, `${where}: the advanced preview leaves the window: ${popup.inside}`); + check(!popup.inside, `${where}: the advanced preview is out of reach: ${popup.inside}`); await tab.screenshot({ path: `${file}-preview.png` }); } const banners = await tab.evaluate(() => window.fv3Test.banners);