diff --git a/.coderabbit.yaml b/.coderabbit.yaml index 4d3ef96d..ad04c22e 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -239,6 +239,15 @@ reviews: 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. + - browser_test.sh runs an Unraid-alone pass first, FV3's three + page hooks moved out of its plugin folder. It checks hooks.js, a + hand-written list of Unraid's DOM hooks, functions, stylesheet + classes and endpoints FV3 relies on, each naming the FV3 file that + still mentions it and what the user loses; any/since only where + FV3 itself branches. + layout.js holds the layout rules FV3's pass checks against that + pass and a loose container on the same page, each from a fix FV3 + has shipped. - 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 index 42c4ec52..113bc3b3 100644 --- a/.github/unraid-compat/browser_test.js +++ b/.github/unraid-compat/browser_test.js @@ -1,14 +1,21 @@ // 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 +// Usage: node browser_test.js [unraid-alone] 'use strict'; const fs = require('fs'); +const path = require('path'); const { chromium, firefox } = require('playwright-core'); +const { HOOKS, tokens, mentions, describe, applies, forView, missingHooks } = require('./hooks'); +const { widths, layoutState } = require('./layout'); -const [version, shots, fakeToken] = process.argv.slice(2); +const [version, shots, fakeToken, tree, mode = 'fv3'] = process.argv.slice(2); +// The Unraid-alone pass runs with FV3's page hooks moved away: it checks Unraid's hooks and measures what FV3's pass compares with +const ALONE = mode === 'unraid-alone'; +const MEASURED = `${shots}/unraid-alone.json`; const base = 'http://127.0.0.1'; const failures = []; let checks = 0; -// Each failure prints as it happens, so a run the step's time limit kills still shows what failed +// Each failure prints as it happens, so a run the step's time limit kills still shows what failed; a missing hook prints once the +// views end, as one line for all its views 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); @@ -53,11 +60,11 @@ const READ = { 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) => { + const { seen, name, members } = window.fv3Test; + const tiles = (view) => [...document.querySelectorAll(`tbody#${view} > tr.updated > td > :not(.fv3-fullwidth-panel)`)].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(', ')}]`; + const mine = members(tile); + return `${tile.querySelector('.fv3-folder-appname').innerText.trim()} [${mine.map(name).join(', ')}] shows [${mine.filter(seen).map(name).join(', ')}]`; }); return { docker: tiles('docker_view'), vms: tiles('vm_view') }; }, @@ -76,23 +83,33 @@ const WANT = { }, Dashboard: { 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'] }, + 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 [Debian 12]', '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 +// FV3's events for a finished draw; the folders each page opens, their events once open, and how a user opens them 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) => 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"); + 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")], + // Each by its tile's menu, the item FV3's lang pack labels 'expand'. Unraid fades a used menu out and hides every menu as each + // fade ends, so a user's next menu waits for the fade (jQuery's :animated): one opened during it closes at once + Dashboard: ['Media and Lab', ['docker-post-folder-expansion', 'vm-post-folder-expansion'], async (p) => { + const expand = await p.evaluate(() => $.i18n('expand')); + for (const [id, folder] of [[MEDIA, 'Media'], [LAB, 'Lab']]) { + await press(p.locator(`#folder-id-${id}`), `${folder}'s tile`); + await press(p.locator('ul.dropdown-context:visible li > a', { hasText: expand }), `${folder}'s menu's Expand`); + await p.waitForFunction(() => !$('ul.dropdown-context:animated').length && [...document.querySelectorAll('ul.dropdown-context')].every((u) => !u.offsetParent), null, { timeout: 5000 }) + .catch(() => { throw new Error(`${folder}'s menu did not close within 5 s`); }); + } }], }; -// The first member of Media, and where a click opens its advanced preview once Media is open +// FV3's Dashboard layouts for the Docker and VM cards in each theme, so every layout is drawn at every width +const LAYOUTS = [['classic', 'embossed'], ['fullwidth', 'classic'], ['accordion', 'fullwidth'], ['inset', 'accordion']]; +// Unraid's own list on each page once its rows load: a loading placeholder row is not one +const LISTED = { Docker: '#docker_list > tr.sortable', VMs: '#kvm_list > tr.sortable', Dashboard: 'tbody#docker_view > tr.updated' }; +// The first member of Media, and where a click opens its advanced preview once Media is open (fullwidth: in the panel after its row) 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` }; +const PREVIEW = { Docker: `tr.folder-id-${MEDIA} .folder-preview span.hand[id^="folder-preview-"]`, Dashboard: `.folder-showcase-${MEDIA} > span.outer > span.hand, .fv3-fullwidth-panel[data-folder-name="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 @@ -125,10 +142,16 @@ function testHelpers() { for (const node of outer.querySelector('.inner').childNodes) { if (node.nodeName === 'BR') break; before.push(node.textContent); } return before.join('').trim(); }; + // A Dashboard folder's member tiles wherever its layout puts them: in the folder, or the fullwidth layout's panel in its row + const members = (folder) => { + const named = folder.querySelector('.folder-showcase')?.dataset.folderName; + const panel = [...folder.parentElement.querySelectorAll(':scope > .fv3-fullwidth-panel')].find((p) => p.dataset.folderName === named); + return [...folder.querySelectorAll('.folder-storage > span.outer, .folder-showcase > span.outer'), ...(panel?.querySelectorAll(':scope > span.outer') || [])]; + }; 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, banners }; + window.fv3Test = { events, seen, name, members, 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 @@ -148,12 +171,23 @@ 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 +// A user's click, the target scrolled to the middle until it stays there: a folder opening above it can still move it async function press(locator, what) { - await locator.evaluate((el) => el.scrollIntoView({ block: 'center', inline: 'center' })); + const middle = () => locator.evaluate((el) => { + el.scrollIntoView({ block: 'center', inline: 'center' }); + const r = el.getBoundingClientRect(); + return `${Math.round(r.top)},${Math.round(r.left)}`; + }, null, { timeout: 10000 }).catch(() => { throw new Error(`${what} is not on the page within 10 s`); }); + for (let at = await middle(), i = 0; i < 20; i++) { + await locator.page().waitForTimeout(100); + if (at === (at = await middle())) break; + } try { await locator.click({ timeout: 5000 }); } catch (e) { + // Playwright's own retries scroll the target elsewhere: what covers it is read back in the middle, beside Playwright's reason + const why = e.message.split('\n').find((l) => l.includes('intercepts pointer events'))?.trim().replace(/^- /, '') || e.message.split('\n')[0]; + await middle().catch(() => {}); const cover = await locator.evaluate((el, frame) => { if (!window.fv3Test.seen(el)) return null; const r = el.getBoundingClientRect(); @@ -162,9 +196,10 @@ async function press(locator, what) { 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}`); + }, FRAME.map(([selector]) => selector), { timeout: 5000 }).catch(() => undefined); + if (cover === undefined) throw new Error(`${what} could not be clicked, then left the page: ${why}`); + if (cover === null) throw new Error(`${what} could not be clicked: ${why}`); + if (cover) throw new Error(`${what} is covered by ${cover} (${why})`); await locator.dispatchEvent('click'); } } @@ -202,12 +237,12 @@ 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 file = `${shots}/${kind}/${theme}-${width}-${page}`; +// One page in one browser, theme and width, through one pass's steps; false when it ended before the page drew +async function view(browser, kind, theme, [width, height], page, steps) { + const v = { where: `${kind} ${theme} ${width}px ${page}`, file: `${shots}/${kind}/${theme}-${width}-${page}${ALONE ? '-unraid-alone' : ''}`, theme, width, page, drew: false }; + const { where, file } = v; const errors = []; - let context, tab, timer, drew = false; + let context, tab, timer; try { context = await browser.newContext({ viewport: { width, height } }); await context.addInitScript(testHelpers); @@ -216,60 +251,127 @@ async function view(browser, kind, theme, [width, height], page) { 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); })]); + await Promise.race([steps(tab, v), 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); } + // Unraid alone must run clean too: an error there is Unraid's or the fake's, and its readings would not hold check(!errors.length, `${where}:\n ${[...new Set(errors)].join('\n ')}`); await context?.close().catch(() => {}); - return drew; + return v.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]; - 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 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 - 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 is out of reach: ${popup.inside}`); - await tab.screenshot({ path: `${file}-preview.png` }); - } - const banners = await tab.evaluate(() => window.fv3Test.banners); - check(!banners.length, `${where}: FV3 showed a banner: ${banners.join(' | ')}`); +// The page as the theme's stylesheet draws it, or the view fails +async function load(tab, { where, page, theme }) { + 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`); +} + +// Unraid alone: its list drawn, the widths FV3's pass compares with, and which of FV3's hooks it lacks +const measured = {}, lacking = new Map(); +async function aloneSteps(tab, v) { + await load(tab, v); + // An FV3 page hook left in place would compare FV3 with itself + const fv3 = await tab.$('script[src*="/plugins/folder.view3/"], link[href*="/plugins/folder.view3/"]'); + if (!check(!fv3, `${v.where}: FV3 is on the page, so this is not Unraid alone and nothing was read`)) return; + v.drew = await tab.waitForSelector(LISTED[v.page], { timeout: 20000 }).then(() => true, () => false); + if (!check(v.drew, `${v.where}: Unraid alone drew no ${LISTED[v.page]} within 20 s, so its hooks and widths were not read`)) return; + measured[v.where] = await settled(tab, widths); + const hooks = forView(v.page, version); + for (const i of await settled(tab, missingHooks, hooks)) lacking.set(hooks[i], [...(lacking.get(hooks[i]) || []), v.where]); +} + +// FV3's pass: drawn in the saved order, folders opened as a user opens them, the layout rules, the advanced preview, no banners +async function fv3Steps(tab, v) { + const { where, file, page } = v; + await load(tab, v); + await waitEvents(tab, DRAWN[page]).catch(() => { throw new Error(`FV3 did not finish drawing within 20 s (${DRAWN[page].join(', ')})`); }); + v.drew = true; + if (page === 'Dashboard') { + const want = LAYOUTS[THEMES.indexOf(v.theme)]; + const drawn = await tab.evaluate(() => ['docker_view', 'vm_view'].map((t) => [...(document.querySelector(`tbody#${t} > tr.updated > td`)?.classList || [])] + .find((c) => c.startsWith('fv3-layout-'))?.slice('fv3-layout-'.length) || 'no layout')); + check(same(drawn, want), `${where}: the Docker and VM cards are drawn in ${drawn.join(' and ')}, not ${want.join(' and ')}`); } + 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.join(', ')})`); }); + 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)}`); + const layout = await settled(tab, layoutState, page); + if (layout.error) throw new Error(layout.error); + for (const problem of Object.values(layout.rules)) check(!problem, `${where}: ${problem}`); + // Only where Unraid alone fits: where it already scrolls sideways, FV3 may be wider + const now = await tab.evaluate(widths), was = measured[where]; + if (was) check((!was.page || now.page) && (was.table !== true || now.table), `${where}: FV3 adds sideways scrolling Unraid alone does not have: ${now.sizes} (Unraid alone ${was.sizes})`); + else if (Object.keys(measured).length) check(false, `${where}: widths not compared, the Unraid-alone pass did not measure this view`); + await tab.screenshot({ path: `${file}.png`, fullPage: true }); + if (PREVIEW[page]) { + 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 + 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 is out of reach: ${popup.inside}`); + await tab.screenshot({ path: `${file}-preview.png` }); + } + const banners = await tab.evaluate(() => window.fv3Test.banners); + check(!banners.length, `${where}: FV3 showed a banner: ${banners.join(' | ')}`); } // 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 function post(request, route, form, what) { + const r = await request.post(`${base}${route}`, { form }); + if (r.status() !== 200 || (route.includes('folder.view3') && !r.headers()['x-fv3-answer'])) throw new Error(`${what}: status ${r.status()}, ${(await r.text()).slice(0, 200)}`); +} + +// FV3's pass starts from: Media and the Dashboard with the advanced preview on, and an empty folder +async function fv3Setup(request, token) { + // Media as fake_unraid.sh saved it + const saved = await 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(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(request, '/plugins/folder.view3/server/update_settings.php', { key: 'dashboard_context', value: '2', csrf_token: token }, "the Dashboard's advanced preview"); + // Named in characters a page must escape + await post(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'); +} + +// Before the views: each hook's FV3 file still mentions it, and each endpoint is a webGUI file, called from Unraid's pages +// where FV3 intercepts it +function hookFiles(webgui) { + for (const h of HOOKS) { + const text = fs.existsSync(`${plugin}/${h.file}`) ? fs.readFileSync(`${plugin}/${h.file}`, 'utf8') : null; + const gone = text === null ? [h.file] : tokens(h).filter((t) => !mentions(text, t)); + check(!gone.length, `hooks.js names ${h.file} for ${describe(h)}, but FV3 no longer has ${gone.join(', ')} there`); + } + const plugins = `${webgui}/emhttp/plugins`; + const pages = fs.readdirSync(plugins, { recursive: true }).filter((f) => /\.(page|php|js)$/.test(f)).map((f) => [`/plugins/${f}`, fs.readFileSync(`${plugins}/${f}`, 'utf8')]); + for (const h of HOOKS.filter((x) => x.url)) { + const file = h.url.replace(/^\/webGui\//, '/plugins/dynamix/'); + if (!check(fs.existsSync(`${webgui}/emhttp${file}`), `Unraid ${version} lacks ${h.url}, which ${h.file} needs: ${h.loses}`) || !h.intercepts) continue; + check(pages.some(([f, text]) => f !== file && text.includes(h.url)), `Unraid ${version}'s pages no longer call ${h.url}, which ${h.file} intercepts: ${h.loses}`); + } } (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 webgui = path.resolve(__dirname, '../..', tree || ''); + if (!fs.existsSync('/.dockerenv') || !fakeToken || !fs.existsSync(`${webgui}/emhttp`)) { console.error('Run browser_test.sh: this needs the fake Unraid it starts and its webGUI tree'); process.exit(2); } + if (!ALONE) 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(); @@ -278,35 +380,42 @@ async function post(request, path, form, what) { // 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 - 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"); - // 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'); + if (!ALONE) { + // Without them only the width comparison is lost; FV3's pass still runs + try { Object.assign(measured, JSON.parse(fs.readFileSync(MEASURED, 'utf8'))); } catch (e) { check(false, `the Unraid-alone pass left no measurements, so no widths are compared: ${e.message}`); } + await fv3Setup(setup.request, token); + } + if (ALONE) hookFiles(webgui); 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']) { - 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'); + try { + for (const [i, theme] of THEMES.entries()) { + // 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`); + if (!ALONE) for (const [card, layout] of [['docker', LAYOUTS[i][0]], ['vm', LAYOUTS[i][1]]]) { + await post(setup.request, '/plugins/folder.view3/server/update_settings.php', { key: `dashboard_${card}_layout`, value: layout, csrf_token: token }, `the Dashboard's ${layout} ${card} card`); + } + 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']) { + undrawn = (await view(browser, kind, theme, size, page, ALONE ? aloneSteps : fv3Steps)) ? 0 : undrawn + 1; + if (undrawn === 3) throw new Error(`3 views in a row ended before ${ALONE ? 'Unraid' : 'FV3'} drew, so the rest were not run`); + } } } + } finally { + // Each missing hook once, with the views it was missing from, also when the run stops early + for (const [h, where] of lacking) check(false, `Unraid ${version} lacks ${describe(h)} on ${h.page} (${where.length} views, first ${where[0]}), which ${h.file} needs: ${h.loses}`); } await setup.close(); for (const browser of Object.values(browsers)) await browser.close(); + if (ALONE) fs.writeFileSync(MEASURED, JSON.stringify(measured)); + const what = ALONE ? `Unraid alone has the ${HOOKS.filter((h) => applies(h, version)).length} hooks FV3 relies on, ${THEMES.length} themes at ${SIZES.length} widths in Chromium and Firefox` + : `FV3's pages in Chromium and Firefox, ${THEMES.length} themes at ${SIZES.length} widths`; if (failures.length) { - console.log(`FAILED [Unraid ${version}]: ${failures.length} of ${checks} browser checks, each listed above`); + console.log(`FAILED [Unraid ${version}]: ${failures.length} of ${checks} checks (${ALONE ? 'Unraid alone' : "FV3's pages"}), 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)`); + console.log(`Unraid ${version}: ${what}, passed (${checks} checks)`); })().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 7b41b87b..5624e2c0 100644 --- a/.github/unraid-compat/browser_test.sh +++ b/.github/unraid-compat/browser_test.sh @@ -1,6 +1,6 @@ #!/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 +# 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 @@ -26,9 +26,15 @@ token=$(docker exec "$fake" php -d auto_prepend_file= -r 'echo parse_ini_file("/ [ -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 --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=$? +browse() { 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" "$tree" "$@"; } +# Unraid alone first, with FV3's page hooks (folder.view3..page) out of its plugin folder; FV3's pass then compares with it +docker exec "$fake" bash -c 'mkdir -p /run/fv3-off && mv /usr/local/emhttp/plugins/folder.view3/folder.view3.*.page /run/fv3-off/' || fail "FV3's pages could not be moved aside" +# FV3's pass must never compare with an earlier run's measurements +rm -f "$shots/unraid-alone.json" || fail "the last run's measurements could not be removed from $shots" +browse unraid-alone; status=$? +docker exec "$fake" bash -c 'mv /run/fv3-off/* /usr/local/emhttp/plugins/folder.view3/' || fail "FV3's pages could not be put back" +browse || status=1 # 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/hooks.js b/.github/unraid-compat/hooks.js new file mode 100644 index 00000000..ee7e7470 --- /dev/null +++ b/.github/unraid-compat/hooks.js @@ -0,0 +1,105 @@ +// Unraid's own parts FV3 relies on, each with the FV3 file that uses it and what the user loses without it. browser_test.js checks +// them on Unraid alone (endpoints as webGUI files), each file still naming its hook; any/since only where FV3 itself branches +'use strict'; +const D = 'Docker', V = 'VMs', B = 'Dashboard', ALL = 'any page'; +const HOOKS = [ + // Docker's list and its rows + { page: D, dom: '#docker_list > tr.sortable', file: 'scripts/docker.js', loses: 'folders never draw' }, + { page: D, dom: '#docker_containers > thead > tr > th', file: 'scripts/docker.js', loses: 'folder rows lose their column spans and widths' }, + { page: D, dom: '#docker_list td.ct-name > span.outer > span.hand > img.img', file: 'scripts/docker.js', loses: "folder previews show no containers' icons" }, + { page: D, dom: '#docker_list td.ct-name span.inner > span.appname > a.exec', file: 'scripts/docker.js', loses: 'containers are not read into their folders' }, + { page: D, dom: '#docker_list td.ct-name span.outer i[id^="load-"]', file: 'scripts/docker.js', loses: "folder icons stop showing their containers' state" }, + { page: D, dom: 'td.updatecolumn', file: 'scripts/shared.js', loses: 'incognito leaves version text showing' }, + { page: D, dom: '#docker_list td.advanced', file: 'scripts/docker.js', loses: "the folder autostart switch cannot find its containers' switches" }, + { page: D, dom: '#docker_list input.autostart', file: 'scripts/docker.js', loses: 'the folder autostart switch does nothing' }, + { page: D, dom: '.switch-button-background', file: 'scripts/docker.js', loses: "the folder autostart switch leaves its members' switches unchanged" }, + { page: D, dom: '#docker_containers th.nine', file: 'scripts/shared.js', loses: 'the autostart column is sized wrong' }, + { page: D, dom: '.advancedview', file: 'scripts/docker.js', loses: 'folders are not redrawn on the basic/advanced toggle' }, + { page: D, any: ['.js-actions', 'input[value="Add Container"]'], file: 'folder.view3.Docker.page', loses: 'no Add Folder button' }, + { page: D, dom: 'div.spinner.fixed', file: 'scripts/docker.js', loses: 'no spinner during folder actions' }, + // VMs' list and its rows + { page: V, dom: '#kvm_list > tr.sortable', file: 'scripts/vm.js', loses: 'folders never draw' }, + { page: V, dom: '#kvm_table > thead > tr', file: 'scripts/vm.js', loses: 'folder rows lose their column spans' }, + { page: V, dom: '#kvm_list td.vm-name span.outer span.inner a', file: 'scripts/vm.js', loses: 'VMs are not read into their folders' }, + { page: V, dom: '#kvm_list td.vm-name span.hand > img.img', file: 'scripts/vm.js', loses: "folder previews show no VMs' icons" }, + { page: V, dom: '#kvm_list tr[id^="name-"]', file: 'scripts/vm.js', loses: 'VM detail rows escape their folders' }, + { page: V, dom: '#kvm_list a[onclick*="toggle_id"]', file: 'scripts/vm.js', loses: 'VM detail rows escape their folders' }, + { page: V, dom: '#kvm_table th.th1', file: 'scripts/vm.js', loses: 'the name column is not sized' }, + { page: V, dom: '#kvm_list input.autostart', file: 'scripts/vm.js', loses: 'the folder autostart switch throws' }, + { page: V, any: ['.js-actions', 'input[value="Add VM"]'], file: 'folder.view3.VMs.page', loses: 'no Add Folder button' }, + // The Dashboard's tiles + { page: B, dom: 'tbody#docker_view > tr.updated > td', file: 'scripts/dashboard.js', loses: 'Docker folders never draw' }, + { page: B, dom: 'tbody#vm_view > tr.updated > td', file: 'scripts/dashboard.js', loses: 'VM folders never draw' }, + { page: B, dom: 'tbody#docker_view span.outer.solid.apps > span.hand', file: 'scripts/dashboard.js', loses: 'containers are not moved into folder tiles' }, + { page: B, dom: 'tbody#docker_view span.outer.apps > span.inner', file: 'scripts/dashboard.js', loses: "containers' names are not read" }, + { page: B, dom: 'tbody#vm_view span.outer.vms > span.hand', file: 'scripts/dashboard.js', loses: 'VMs are not moved into folder tiles' }, + { page: B, dom: 'input#apps', file: 'scripts/dashboard.js', loses: "hide-stopped ignores Docker folders" }, + { page: B, dom: 'input#vms', file: 'scripts/dashboard.js', loses: 'hide-stopped ignores VM folders' }, + { page: B, dom: 'table.dashboard', file: 'styles/dashboard.css', loses: 'folder tiles lose their padding' }, + // Every page + { page: ALL, dom: 'link[href*="default-base"]', since: '7.1', file: 'scripts/include/customEvents.js', loses: "FV3 styles the page as 7.0's layout" }, + // Classes FV3 puts on its own markup for Unraid's stylesheet to colour + { page: ALL, css: 'green-text', file: 'scripts/docker.js', loses: 'a started folder loses its green state' }, + { page: ALL, css: 'red-text', file: 'scripts/docker.js', loses: 'a stopped folder loses its red state' }, + { page: ALL, css: 'orange-text', file: 'scripts/docker.js', loses: "a folder's drag handle and update mark lose their colour" }, + // Unraid's functions and jQuery plugins, each callable, and its CSRF token, a non-empty string + { page: D, js: 'loadlist', file: 'scripts/docker.js', loses: 'folders never draw' }, + { page: D, js: 'listview', file: 'scripts/docker.js', loses: 'folders are not redrawn after a view toggle' }, + { page: D, js: 'openDocker', file: 'scripts/docker.js', loses: "a folder's Update does nothing" }, + { page: D, js: 'openTerminal', file: 'scripts/docker.js', loses: 'the console and log buttons do nothing' }, + { page: D, js: 'dockerload.addEventListener', file: 'scripts/docker.js', loses: 'no CPU and memory stats without the Unraid API' }, + { page: V, js: 'loadlist', file: 'scripts/vm.js', loses: 'folders never draw' }, + { page: ALL, js: 'context.attach', file: 'scripts/docker.js', loses: 'folders have no menus' }, + { page: ALL, js: 'swal', file: 'scripts/shared.js', loses: 'no confirm or error dialogs' }, + { page: ALL, js: 'csrf_token', type: 'string', file: 'scripts/include/customEvents.js', loses: "every FV3 save is refused" }, + { page: ALL, js: '$.fn.tooltipster', file: 'scripts/advanced-preview.js', loses: 'no advanced preview' }, + { page: D, js: '$.fn.switchButton', file: 'scripts/docker.js', loses: 'the folder autostart switch never draws' }, + { page: D, js: '$.fn.sortable', file: 'scripts/docker.js', loses: 'folders cannot be dragged' }, + { page: D, js: '$.cookie', file: 'scripts/docker.js', loses: 'docker.js stops at load, so folders never draw' }, + { page: D, js: '$.fn.readmore', file: 'scripts/shared.js', loses: "an opened folder's long descriptions are not folded" }, + { page: ALL, js: 'openBox', file: 'scripts/shared.js', loses: "a folder's user script actions do nothing" }, + // Unraid's endpoints FV3 calls, as files in the webGUI; one it intercepts must also still be called from Unraid's pages + { url: '/plugins/dynamix.docker.manager/include/UserPrefs.php', intercepts: true, file: 'scripts/docker.js', loses: "Unraid saves an order without FV3's folders" }, + { url: '/plugins/dynamix.vm.manager/include/UserPrefs.php', intercepts: true, file: 'scripts/vm.js', loses: "Unraid saves an order without FV3's folders" }, + { url: '/plugins/dynamix.vm.manager/include/VMMachines.php', intercepts: true, file: 'scripts/vm.js', loses: 'folders are not redrawn when the VM list reloads' }, + { url: '/webGui/include/DashboardApps.php', intercepts: true, file: 'scripts/dashboard.js', loses: 'Dashboard folders are not redrawn when the tiles reload' }, + { url: '/plugins/dynamix.docker.manager/include/UpdateConfig.php', intercepts: true, file: 'scripts/docker.js', loses: 'folder autostart falls out of step' }, + { url: '/plugins/dynamix.docker.manager/include/DockerUpdate.php', intercepts: true, file: 'scripts/docker.js', loses: 'folders are not redrawn after an update' }, + { url: '/plugins/dynamix.vm.manager/include/VMajax.php', file: 'scripts/shared.js', loses: 'VM folder actions fail' }, + { url: '/plugins/dynamix.vm.manager/vnc.html', file: 'scripts/vm.js', loses: "a folder member's VNC button does nothing" }, + { url: '/plugins/dynamix.docker.manager/images/question.png', file: 'scripts/docker.js', loses: 'folders without an icon show a broken image' }, +]; + +// What a hook's FV3 file must still mention: a selector's #ids, .classes and quoted values, a function's name, a URL's file +const tokens = (h) => (h.js ? [h.js.startsWith('$.fn.') ? h.js.slice(4) : h.js] : h.url ? [h.url.split('/').pop()] : h.css ? [h.css] + : (h.any || [h.dom]).flatMap((s) => [...s.matchAll(/([#.][\w-]+)|"([^"]+)"/g)].map((m) => m[1] || m[2]))); +const esc = (t) => t.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +// As a whole token (a #id or .class starts at its mark); a class may also be named in a class attribute or as a quoted string +const mentions = (text, t) => new RegExp(`${/^[#.]/.test(t) ? '' : '(? h.dom || (h.any && `any of ${h.any.join(', ')}`) || (h.css && `a stylesheet rule for .${h.css}`) || h.url + || (h.type === 'string' ? `${h.js} as a non-empty string` : `the function ${h.js}`); +const older = (a, b) => { const [x, y] = [a, b].map((v) => v.split('.').map(Number)); const i = x.findIndex((n, k) => n !== y[k]); return i >= 0 && x[i] < y[i]; }; +const applies = (h, version) => !h.since || !older(version, h.since); +// The hooks one view checks: its page's and every page's that apply to this version (endpoints are checked as files) +const forView = (page, version) => HOOKS.filter((h) => !h.url && [page, ALL].includes(h.page) && applies(h, version)); + +// In the page: the indexes of the hooks it lacks. Rules in @media and @import count; a sheet that cannot be read counts as none +function missingHooks(hooks) { + const own = (sheet) => { try { return [...sheet.cssRules]; } catch { return []; } }; + const flat = (rules) => rules.flatMap((r) => (r.styleSheet ? flat(own(r.styleSheet)) : r.cssRules ? [r, ...flat([...r.cssRules])] : [r])); + const selectors = flat([...document.styleSheets].flatMap(own)) + .map((r) => r.selectorText || '').join('\n'); + const present = (h) => { + if (h.dom) return !!document.querySelector(h.dom); + if (h.any) return h.any.some((s) => document.querySelector(s)); + if (h.css) return new RegExp(`\\.${h.css}(?![\\w-])`).test(selectors); + try { + const value = (0, eval)(h.js); + return typeof value === (h.type || 'function') && value !== ''; + } catch { return false; } + }; + return hooks.map((h, i) => (present(h) ? -1 : i)).filter((i) => i >= 0); +} + +module.exports = { HOOKS, tokens, mentions, describe, applies, forView, missingHooks }; diff --git a/.github/unraid-compat/layout.js b/.github/unraid-compat/layout.js new file mode 100644 index 00000000..39310694 --- /dev/null +++ b/.github/unraid-compat/layout.js @@ -0,0 +1,55 @@ +// The layout rules browser_test.js checks once FV3 has opened a folder, each from a fix FV3 has shipped, read in the page +'use strict'; + +// Whether the page, and the table wrapper where only the table scrolls (7.2's .TableContainer), fit without scrolling sideways +function widths() { + const page = document.documentElement, table = document.querySelector('.TableContainer'); + const fits = (el) => el.scrollWidth <= el.clientWidth + 1; + const size = (el) => `${el.scrollWidth} of ${el.clientWidth} px`; + return { page: fits(page), table: table ? fits(table) : null, sizes: `page ${size(page)}${table ? `, table ${size(table)}` : ''}` }; +} + +// Each rule's failure, '' when it holds. A folder against a loose container on its page (Unraid's name element, a link only +// with a template): name and row no taller than 1.5x theirs. A preview item clipped wholly out of sight drops out of the readout +function layoutState(page) { + const { seen, name, members } = window.fv3Test; + const box = (el) => el.getBoundingClientRect(); + const tall = (node) => { const r = document.createRange(); r.selectNodeContents(node); return Math.round(r.getBoundingClientRect().height); }; + const shown = (label, nameEl, icon, other, loose) => [ + !nameEl || !seen(nameEl) ? `${label}'s name cannot be seen` : tall(nameEl) > 1.5 * tall(other) ? `${label}'s name is ${tall(nameEl)} px tall, ${loose}'s ${tall(other)} px` : '', + !icon || !seen(icon) ? `${label}'s icon cannot be seen` : !icon.complete || !icon.naturalWidth ? `${label}'s icon did not load` : '', + ].filter(Boolean); + // A folder by its name's text, even where that text cannot be seen + const nameOf = (el) => el?.textContent.trim() || 'a folder'; + const rules = { name: [] }; + + if (page === 'Dashboard') { + const tile = [...document.querySelectorAll('tbody#docker_view span.outer')].find((o) => !o.closest('.folder-showcase-outer') && seen(o) && name(o) === 'app-d'); + const otherName = tile?.querySelector('.inner > *'); + if (!otherName) return { error: "no app-d tile to compare folders' tiles with" }; + rules.card = []; + for (const folder of document.querySelectorAll('.folder-showcase-outer')) { + const label = nameOf(folder.querySelector('.fv3-folder-appname')); + rules.name.push(...shown(label, folder.querySelector('.fv3-folder-appname'), folder.querySelector('img.fv3-folder-icon'), otherName, 'app-d')); + const card = box(folder.closest('tbody')); + const own = folder.querySelector(':scope > span.outer'); + const out = [own, ...members(folder)].filter((o) => o && seen(o)).filter((o) => box(o).left < card.left - 1 || box(o).right > card.right + 1); + if (out.length) rules.card.push(`${label}'s ${out.map((o) => (o === own ? 'tile' : name(o))).join(', ')} outside the card (${Math.round(card.left)} to ${Math.round(card.right)} px)`); + } + } else { + const [list, cell, loose] = page === 'Docker' ? ['docker_list', 'ct-name', 'app-d'] : ['kvm_list', 'vm-name', 'Home Assistant']; + const rows = [...document.querySelectorAll(`#${list} > tr`)].filter(seen); + const other = rows.find((r) => !r.classList.contains('folder') && r.querySelector(`td.${cell} span.outer`) && name(r.querySelector(`td.${cell} span.outer`)) === loose); + const otherName = other?.querySelector(`td.${cell} span.inner > *`); + if (!otherName) return { error: `no ${loose} row to compare folders with` }; + rules.height = []; + for (const row of rows.filter((r) => r.classList.contains('folder'))) { + const label = nameOf(row.querySelector('a.folder-appname')); + rules.name.push(...shown(label, row.querySelector('a.folder-appname'), row.querySelector('img.folder-img'), otherName, loose)); + if (box(row).height > 1.5 * box(other).height) rules.height.push(`${label}'s row is ${Math.round(box(row).height)} px tall, ${loose}'s ${Math.round(box(other).height)} px`); + } + } + return { rules: Object.fromEntries(Object.entries(rules).map(([rule, problems]) => [rule, problems.join('; ')])) }; +} + +module.exports = { widths, layoutState };