ci: Woodpecker pipeline runs guest-guard test + page-JS harnesses on push (gates merges); vendor check-page-js.sh
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
1 parent
dd63750871
commit
267a573eda
2 files changed
+127
No files matched your search
@@ -0,0 +1,48 @@
|
|||||||
|
# Woodpecker CI pipeline for the admin panel — THIN on purpose.
|
||||||
|
#
|
||||||
|
# Runs the panel's EXISTING checks, unchanged:
|
||||||
|
# tests/test_guest_guard.py server-side duplicate-guest guard (pure, stdlib only)
|
||||||
|
# tests/check-page-js.sh + harnesses the page JS checker (node --check on the real
|
||||||
|
# <script> block, then stub + page JS + harness
|
||||||
|
# in ONE node scope) against every harness:
|
||||||
|
# admin-panel-chart-harness.js admin-panel-guests-harness.js
|
||||||
|
# admin-panel-invite-harness.js tests/money-chart-harness.js
|
||||||
|
#
|
||||||
|
# tests/check-page-js.sh is vendored byte-identically from the steward's skill
|
||||||
|
# script (the CI agent container has no host filesystem) — keep the two in step;
|
||||||
|
# its md5 is recorded in ops-docs so drift is detectable.
|
||||||
|
#
|
||||||
|
# Gating: `push` fires on every push (including branch pushes) so a red run
|
||||||
|
# blocks the merge via Gitea branch protection (status check
|
||||||
|
# `ci/woodpecker/push/main`). `manual` kept for hand-triggered runs.
|
||||||
|
#
|
||||||
|
# Backend note (why there are no container images here):
|
||||||
|
# The agent is a Cloudron app with no Docker socket → Woodpecker `local`
|
||||||
|
# backend: each step is a shell command INSIDE the agent container and the
|
||||||
|
# step's `image:` field selects the SHELL. python3 + node + bash are baked
|
||||||
|
# into the agent image (co-op/woodpecker-agent). Nothing to install at run
|
||||||
|
# time — the guest-guard test and the checker are stdlib-only by design.
|
||||||
|
|
||||||
|
when:
|
||||||
|
- event: push
|
||||||
|
- event: manual
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: tests
|
||||||
|
image: bash
|
||||||
|
commands:
|
||||||
|
- python3 tests/test_guest_guard.py
|
||||||
|
# Run every harness even when one fails, then fail the step — a plain
|
||||||
|
# command chain would hide all failures after the first.
|
||||||
|
- |
|
||||||
|
fails=0
|
||||||
|
for h in admin-panel-chart-harness.js admin-panel-guests-harness.js \
|
||||||
|
admin-panel-invite-harness.js tests/money-chart-harness.js; do
|
||||||
|
echo "== harness: $h"
|
||||||
|
bash tests/check-page-js.sh app/main.py "$h" || fails=$((fails+1))
|
||||||
|
done
|
||||||
|
if [ "$fails" -ne 0 ]; then
|
||||||
|
echo "FAILED: $fails harness run(s) red"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "all admin-panel checks green"
|
||||||
Executable
+79
@@ -0,0 +1,79 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Pre-deploy check for the panel/dashboard PAGE_HTML frontends.
|
||||||
|
#
|
||||||
|
# scripts/check-page-js.sh <path/to/app/main.py> [harness.js]
|
||||||
|
#
|
||||||
|
# 1. Slices PAGE_HTML out of the SOURCE TEXT. Do NOT import the module instead:
|
||||||
|
# app/oidc.py needs authlib, which is not installed on the steward host.
|
||||||
|
# 2. Extracts the single <script> block and runs `node --check` on it.
|
||||||
|
# 3. Given a harness file, runs stub + page JS + harness in ONE node eval scope,
|
||||||
|
# so the harness can call the page's real functions against real data.
|
||||||
|
#
|
||||||
|
# Never skip step 2. It is load-bearing, not ritual: it has caught a broken
|
||||||
|
# string escape and a duplicate `const` that py_compile passed, either of which
|
||||||
|
# blanks every data table on the live page.
|
||||||
|
#
|
||||||
|
# Harness rules (learned the hard way — see references/panel-and-dashboard-patterns.md):
|
||||||
|
# * Assert invariants, not the shape you happened to observe. Parse the
|
||||||
|
# rendered markup into value/position pairs and check the RELATIONSHIP.
|
||||||
|
# * A regex ending in `<` swallows the closing bracket and garbles every
|
||||||
|
# captured label. Match `[^<]*` and stop.
|
||||||
|
# * parseFloat("10-28") is 10. Date labels impersonate numeric ticks; filter
|
||||||
|
# them out by their dash before trusting a numeric parse.
|
||||||
|
# * When a check fails, suspect the ASSERTION first and fix it — never loosen
|
||||||
|
# it to get a green run.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
MAIN="${1:?usage: check-page-js.sh <path/to/app/main.py> [harness.js]}"
|
||||||
|
HARNESS="${2:-}"
|
||||||
|
TMP="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$TMP"' EXIT
|
||||||
|
|
||||||
|
python3 - "$MAIN" "$TMP/page.js" <<'PY'
|
||||||
|
import re, sys
|
||||||
|
src = open(sys.argv[1]).read()
|
||||||
|
marker = 'PAGE_HTML = """'
|
||||||
|
start = src.index(marker) + len(marker)
|
||||||
|
html = src[start:src.index('"""', start)]
|
||||||
|
blocks = re.findall(r"<script>(.*?)</script>", html, re.S)
|
||||||
|
if len(blocks) != 1:
|
||||||
|
sys.exit(f"expected exactly 1 <script> block in PAGE_HTML, found {len(blocks)}")
|
||||||
|
open(sys.argv[2], "w").write(blocks[0])
|
||||||
|
print(f"extracted {len(blocks[0])} chars of page JS from PAGE_HTML")
|
||||||
|
PY
|
||||||
|
|
||||||
|
node --check "$TMP/page.js"
|
||||||
|
echo "node --check: OK"
|
||||||
|
|
||||||
|
if [ -n "$HARNESS" ]; then
|
||||||
|
cat > "$TMP/stub.js" <<'JS'
|
||||||
|
// Minimal browser stubs, loaded BEFORE the page JS: these pages call
|
||||||
|
// load()/loadModels() at the end of the script, which need document + fetch.
|
||||||
|
const els = {};
|
||||||
|
const mkEl = (id) => ({
|
||||||
|
id, style: {}, textContent: "", innerHTML: "", className: "",
|
||||||
|
offsetWidth: 120, offsetHeight: 48,
|
||||||
|
getAttribute: () => null,
|
||||||
|
appendChild: () => {},
|
||||||
|
});
|
||||||
|
globalThis.document = {
|
||||||
|
getElementById: (id) => (els[id] = els[id] || mkEl(id)),
|
||||||
|
querySelectorAll: () => [],
|
||||||
|
body: { innerHTML: "", appendChild: (el) => { globalThis.__lastAppended = el; } },
|
||||||
|
createElement: (tag) => mkEl(undefined),
|
||||||
|
addEventListener: (type, fn) => { (globalThis.__listeners = globalThis.__listeners || {})[type] = fn; },
|
||||||
|
};
|
||||||
|
globalThis.fetch = async () => ({
|
||||||
|
status: 200,
|
||||||
|
json: async () => ({ series: [], totals: {}, members: [], admins: [], models: [] }),
|
||||||
|
});
|
||||||
|
globalThis.window = {
|
||||||
|
innerWidth: 1440,
|
||||||
|
innerHeight: 900,
|
||||||
|
addEventListener: (type, fn) => {},
|
||||||
|
};
|
||||||
|
JS
|
||||||
|
node -e 'const fs=require("fs"), r=p=>fs.readFileSync(p,"utf8");
|
||||||
|
eval(r(process.argv[1]) + r(process.argv[2]) + r(process.argv[3]));' \
|
||||||
|
"$TMP/stub.js" "$TMP/page.js" "$HARNESS"
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user