Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ 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. 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.
- 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
Expand Down
1 change: 1 addition & 0 deletions .github/unraid-compat/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
313 changes: 313 additions & 0 deletions .github/unraid-compat/browser_test.js

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions .github/unraid-compat/browser_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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 <fake-unraid-image> <webgui-tree> <unraid-version> <screenshot-dir>
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
fail() { echo "FAILED [Unraid $version]: $*"; exit 1; }
# 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

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)"
[ $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 --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
exit $status
48 changes: 48 additions & 0 deletions .github/unraid-compat/fake_logs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
// What a run against the fake Unraid left in its logs, for pages_test.php and browser_test.sh: [passed, what failed] per check.
// A command run with 2>/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"
$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/<file>.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+$/';
// 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))];
$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";
}
26 changes: 26 additions & 0 deletions .github/unraid-compat/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .github/unraid-compat/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
24 changes: 4 additions & 20 deletions .github/unraid-compat/pages_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -239,25 +240,8 @@ 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/<file>.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
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";
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ 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"

# 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
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
Expand Down
14 changes: 14 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -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=(?<depName>mcr\\.microsoft\\.com/playwright):(?<currentValue>v[0-9.]+-noble)@(?<currentDigest>sha256:[a-f0-9]{64})"
],
"datasourceTemplate": "docker"
}
],
"packageRules": [
Expand Down Expand Up @@ -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"
}
]
}
Loading