From 765c84ee864edc605b21159043a3d13dcb0febd1 Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:18:22 +0100 Subject: [PATCH 1/6] ci: run the macOS media check as a job of the CI workflow Move the end-to-end check from its own workflow into ci.yml, so it is part of the commit status CI and can block a merge. The new area installer_macos runs it when installer/internal/media or installer/internal/host change, and like every job on push runs and when the workflows or scripts/ci change. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 68 +++++++++++++++++ .github/workflows/installer-macos-media.yml | 75 ------------------- .../internal/host/media_darwin_e2e_test.go | 4 +- scripts/ci/detect_changes.py | 8 ++ scripts/tests/test_detect_changes.py | 5 ++ 5 files changed, 83 insertions(+), 77 deletions(-) delete mode 100644 .github/workflows/installer-macos-media.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef35d4c1b..41fda0492 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -40,6 +40,7 @@ jobs: installer_go: ${{ steps.filter.outputs.installer_go }} installer_cross: ${{ steps.filter.outputs.installer_cross }} installer_webui: ${{ steps.filter.outputs.installer_webui }} + installer_macos: ${{ steps.filter.outputs.installer_macos }} python: ${{ steps.filter.outputs.python }} shell: ${{ steps.filter.outputs.shell }} bootstrap: ${{ steps.filter.outputs.bootstrap }} @@ -173,6 +174,72 @@ jobs: go-version-file: installer/go.mod - run: go test ./internal/media/... ./internal/host/... ./cmd/installer/... + # Die Medien-Vorbereitung auf macOS mit dem echten Imager. Der Imager + # schreibt nur auf eine RAM-Disk, das Schreibrecht dafuer gilt nur auf dem + # Wegwerf-Runner. Der Passwortdialog selbst bleibt ungeprueft. + installer-macos: + name: Installer media end to end (macOS) + needs: changes + if: needs.changes.outputs.installer_macos == 'true' || github.event_name == 'push' + runs-on: macos-latest + timeout-minutes: 30 + permissions: + contents: read + defaults: + run: + shell: bash + working-directory: installer + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: installer/go.mod + - name: Install the Raspberry Pi Imager + run: brew install --cask raspberry-pi-imager + - name: Unit tests of the media mode + run: go test ./internal/media/... ./internal/host/... ./cmd/installer/... + - name: Create the RAM disk + run: | + dev=$(hdiutil attach -nomount ram://2500000 | awk '{print $1}') + if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then + echo "::error::keine RAM-Disk: '$dev'" + exit 1 + fi + echo "EN_MAC_RAMDISK=$dev" >> "$GITHUB_ENV" + - name: Give the RAM disk the node layout of a stick + run: | + dev="$EN_MAC_RAMDISK" + if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then + echo "::error::ungueltiges Geraet: '$dev'" + exit 1 + fi + sudo chown root:operator "$dev" "/dev/r${dev#/dev/}" + sudo chmod 640 "$dev" "/dev/r${dev#/dev/}" + - name: Allow the imager to open the RAM disk + run: | + dev="$EN_MAC_RAMDISK" + if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then + echo "::error::ungueltiges Geraet: '$dev'" + exit 1 + fi + sudo security authorizationdb write "sys.openfile.readwrite./dev/r${dev#/dev/}" allow + - name: End-to-end test on the RAM disk + run: go test -tags mediae2e ./internal/host -run TestMacMediaEndToEnd -v + - name: Remove the right + if: always() + run: | + dev="${EN_MAC_RAMDISK:-}" + if [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then + sudo security authorizationdb remove "sys.openfile.readwrite./dev/r${dev#/dev/}" || true + fi + - name: Detach the RAM disk + if: always() + run: | + dev="${EN_MAC_RAMDISK:-}" + if [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then + hdiutil detach "$dev" -force || true + fi + dashboard-js: name: Dashboard (JS) needs: changes @@ -532,6 +599,7 @@ jobs: - dashboard-go - installer-go - installer-windows + - installer-macos - dashboard-js - dashboard-smoke - installer-webui-go diff --git a/.github/workflows/installer-macos-media.yml b/.github/workflows/installer-macos-media.yml deleted file mode 100644 index 1ea11939d..000000000 --- a/.github/workflows/installer-macos-media.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Installer media (macOS) - -# Abnahme der Medien-Vorbereitung auf macOS. Laeuft auf einem Wegwerf-Runner -# mit RAM-Disk. Nicht Teil von ci-ok, der Lauf kostet macOS-Minuten. - -on: - workflow_dispatch: - pull_request: - paths: - - installer/internal/media/** - - installer/internal/host/** - - .github/workflows/installer-macos-media.yml - -permissions: - contents: read - -jobs: - media-macos: - name: Installer media end to end (macOS) - runs-on: macos-latest - timeout-minutes: 30 - defaults: - run: - shell: bash - working-directory: installer - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: installer/go.mod - - name: Install the Raspberry Pi Imager - run: brew install --cask raspberry-pi-imager - - name: Unit tests of the media mode - run: go test ./internal/media/... ./internal/host/... ./cmd/installer/... - - name: Create the RAM disk - run: | - dev=$(hdiutil attach -nomount ram://2500000 | awk '{print $1}') - if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then - echo "::error::keine RAM-Disk: '$dev'" - exit 1 - fi - echo "EN_MAC_RAMDISK=$dev" >> "$GITHUB_ENV" - - name: Give the RAM disk the node layout of a stick - run: | - dev="$EN_MAC_RAMDISK" - if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then - echo "::error::ungueltiges Geraet: '$dev'" - exit 1 - fi - sudo chown root:operator "$dev" "/dev/r${dev#/dev/}" - sudo chmod 640 "$dev" "/dev/r${dev#/dev/}" - - name: Allow the imager to open the RAM disk - run: | - dev="$EN_MAC_RAMDISK" - if ! [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then - echo "::error::ungueltiges Geraet: '$dev'" - exit 1 - fi - sudo security authorizationdb write "sys.openfile.readwrite./dev/r${dev#/dev/}" allow - - name: End-to-end test on the RAM disk - run: go test -tags mediae2e ./internal/host -run TestMacMediaEndToEnd -v - - name: Remove the right - if: always() - run: | - dev="${EN_MAC_RAMDISK:-}" - if [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then - sudo security authorizationdb remove "sys.openfile.readwrite./dev/r${dev#/dev/}" || true - fi - - name: Detach the RAM disk - if: always() - run: | - dev="${EN_MAC_RAMDISK:-}" - if [[ "$dev" =~ ^/dev/disk[0-9]+$ ]]; then - hdiutil detach "$dev" -force || true - fi diff --git a/installer/internal/host/media_darwin_e2e_test.go b/installer/internal/host/media_darwin_e2e_test.go index bd7bc34f9..1c6a86476 100644 --- a/installer/internal/host/media_darwin_e2e_test.go +++ b/installer/internal/host/media_darwin_e2e_test.go @@ -22,8 +22,8 @@ import ( "github.com/Developer-Simon/energy-node-installer/internal/media" ) -// Der Test laeuft nur auf dem macOS-Wegwerf-Runner des Workflows -// installer-macos-media.yml. EN_MAC_RAMDISK zeigt auf eine RAM-Disk +// Der Test laeuft nur auf dem macOS-Wegwerf-Runner des CI-Jobs +// installer-macos. EN_MAC_RAMDISK zeigt auf eine RAM-Disk // (Disk-Image), auf die der Imager schreibt. Auf jedem anderen Rechner // wird der Test uebersprungen. var macRAMDiskRE = regexp.MustCompile(`^/dev/disk[0-9]+$`) diff --git a/scripts/ci/detect_changes.py b/scripts/ci/detect_changes.py index 5e2ea49d4..019ea99d1 100644 --- a/scripts/ci/detect_changes.py +++ b/scripts/ci/detect_changes.py @@ -20,6 +20,7 @@ "installer_go", "installer_cross", "installer_webui", + "installer_macos", "python", "shell", "bootstrap", @@ -38,6 +39,7 @@ # 29, 30: Das Dashboard bindet installer/webui per replace ein. # 29, 32: Der Installer bindet ./webui ein, daher Cross-Compile bei Go-Code in webui. # 36, 38: bootstrap_container.sh baut das Bundle über scripts/build/make_bundle.sh. +# macOS: internal/media und internal/host tragen den Medien-Modus, den nur der macOS-Job mit dem echten Imager prüft. # 21: Die bisherige Dashboard-Breite ist ein sicherer Rückfall für Dateien wie Caddyfile und Service-Units. # 19: energy-node-updater.sh löste bisher den Shell-Job nicht aus, obwohl dieser shellcheck und test_updater*.sh darauf laufen lässt. RULES: list[tuple[re.Pattern, frozenset[str]]] = [ @@ -122,6 +124,12 @@ frozenset({"installer_webui", "installer_go", "installer_cross", "dashboard_go"})), # 30 (re.compile(r"^installer/webui/"), frozenset({"installer_webui", "installer_go", "dashboard_go"})), + # macOS: wie 31 bis 33, dazu der macOS-Job. Muss davor greifen. + (re.compile(r"^installer/internal/(media|host)/.*_test\.go$"), + frozenset({"installer_go", "installer_macos"})), + (re.compile(r"^installer/internal/(media|host)/.*\.go$"), + frozenset({"installer_go", "installer_cross", "installer_macos"})), + (re.compile(r"^installer/internal/(media|host)/"), frozenset({"installer_go", "installer_macos"})), # 31 (re.compile(r"^installer/.*_test\.go$"), frozenset({"installer_go"})), # 32 diff --git a/scripts/tests/test_detect_changes.py b/scripts/tests/test_detect_changes.py index f3d0615e5..cae7adec1 100644 --- a/scripts/tests/test_detect_changes.py +++ b/scripts/tests/test_detect_changes.py @@ -66,6 +66,11 @@ ("installer/internal/shell/shell.go", {"installer_go", "installer_cross"}), ("installer/go.mod", {"installer_go", "installer_cross"}), ("installer/internal/assets/logo.png", {"installer_go"}), + ("installer/internal/media/job.go", {"installer_go", "installer_cross", "installer_macos"}), + ("installer/internal/media/drives_darwinparse_test.go", {"installer_go", "installer_macos"}), + ("installer/internal/media/testdata/darwin/info-root.json", {"installer_go", "installer_macos"}), + ("installer/internal/host/media_darwin.go", {"installer_go", "installer_cross", "installer_macos"}), + ("installer/internal/host/media_darwin_e2e_test.go", {"installer_go", "installer_macos"}), ("scripts/bootstrap/steps/10_apt.sh", {"installer_go", "shell", "bootstrap"}), ("scripts/tests/test_highlight_i18n.py", {"python"}), ("scripts/tests/bootstrap_container.sh", {"shell", "bootstrap"}), From d5303896970b063d2b0342db272eec6594c1c445 Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:31:50 +0100 Subject: [PATCH 2/6] test(demo): shut down the fake test servers without waiting for the poll interval Co-Authored-By: Claude Sonnet 5.5 --- demo/fakes/conftest.py | 16 ++++++++++++++++ demo/fakes/test_server_shutdown.py | 17 +++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 demo/fakes/test_server_shutdown.py diff --git a/demo/fakes/conftest.py b/demo/fakes/conftest.py index 91fa8000b..0158f3102 100644 --- a/demo/fakes/conftest.py +++ b/demo/fakes/conftest.py @@ -14,6 +14,7 @@ import secrets import select import socket +import socketserver import ssl import struct import subprocess @@ -30,6 +31,21 @@ PING_SECONDS = 0.5 +@pytest.fixture(autouse=True, scope="session") +def _fast_server_shutdown(): + """shutdown() wartet auf die laufende Abfragerunde von serve_forever, in der + Vorgabe bis zu 0,5 s. Bei hunderten Testservern ist das der groesste Teil der + Laufzeit, darum fragen sie in den Tests oefter ab.""" + original = socketserver.BaseServer.serve_forever + + def serve_forever(self, poll_interval=0.02): + original(self, poll_interval) + + with pytest.MonkeyPatch.context() as patch: + patch.setattr(socketserver.BaseServer, "serve_forever", serve_forever) + yield + + def _mac(code, message): return hmac.new(code.upper().encode(), message.encode(), hashlib.sha256).hexdigest() diff --git a/demo/fakes/test_server_shutdown.py b/demo/fakes/test_server_shutdown.py new file mode 100644 index 000000000..c45268ed0 --- /dev/null +++ b/demo/fakes/test_server_shutdown.py @@ -0,0 +1,17 @@ +"""Die Tests beenden ihre Testserver ohne Wartezeit (siehe conftest.py).""" + +import http.server +import threading +import time + + +def test_shutdown_does_not_wait_for_a_slow_poll(): + start = time.monotonic() + for _ in range(5): + server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), http.server.BaseHTTPRequestHandler) + thread = threading.Thread(target=server.serve_forever, daemon=True) + thread.start() + server.shutdown() + server.server_close() + thread.join(timeout=5) + assert time.monotonic() - start < 0.6 From fa7e3dfd46da4dbb1a6bfc1e74367dbd4d9d5bd3 Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:38:14 +0100 Subject: [PATCH 3/6] test(smoke): split the main run into four independent runs The run haupt becomes kern, updates, zugang and system with the same configuration, so CI can execute them side by side. --run haupt stays as a short name and --list shows every run with its groups. create_smoke_user moves to core.sh, because the update checks needed it from the user checks. A script test keeps groups and runs together. Co-Authored-By: Claude Sonnet 5.5 --- dashboard/test/smoke/README.md | 31 +++++--- dashboard/test/smoke/checks/access.sh | 10 +-- dashboard/test/smoke/checks/core.sh | 14 +++- dashboard/test/smoke/checks/updates.sh | 2 +- dashboard/test/smoke/smoke.sh | 99 +++++++++++++++----------- scripts/ci/detect_changes.py | 2 + scripts/tests/test_detect_changes.py | 3 +- scripts/tests/test_smoke_runs.py | 44 ++++++++++++ 8 files changed, 140 insertions(+), 65 deletions(-) create mode 100644 scripts/tests/test_smoke_runs.py diff --git a/dashboard/test/smoke/README.md b/dashboard/test/smoke/README.md index 92f49c6cc..1041fef6f 100644 --- a/dashboard/test/smoke/README.md +++ b/dashboard/test/smoke/README.md @@ -12,12 +12,14 @@ demo, which keeps it running until Ctrl-C: see [demo/README.md](../../../demo/RE The fakes and fixtures are described there too. ```bash -dashboard/test/smoke/smoke.sh # all five runs -dashboard/test/smoke/smoke.sh --run haupt # one run, the option can be repeated +dashboard/test/smoke/smoke.sh # all eight runs +dashboard/test/smoke/smoke.sh --run kern # one run, the option can be repeated +dashboard/test/smoke/smoke.sh --run haupt # short for kern, updates, zugang, system +dashboard/test/smoke/smoke.sh --list # the runs and their check groups ``` -The runs always execute in the same order (`haupt`, `ohne-dienste`, `bilanz`, `seed`, -`falsches-passwort`), +The runs always execute in the same order (`kern`, `updates`, `zugang`, `system`, +`ohne-dienste`, `bilanz`, `seed`, `falsches-passwort`), whatever order `--run` names them in. Each run starts a fresh dashboard in its own directory `.run/-XXXXXX` below this folder. A passed run deletes that directory, a failed run keeps it for analysis. The script exits with 0 only when @@ -26,11 +28,14 @@ all selected runs pass. Before a run starts, all five ports below are checked. A port that is already in use makes the run fail, and the script leaves the process that holds it alone. -## The five runs +## The eight runs | Run | Configuration | Check groups | |---|---|---| -| `haupt` | Sources, fixture and seed data of the demo (`demo/demo.sh`), HTTPS, simulated power values, service logs, installed state, package and update fake | `topics`, `battery_config`, `shelly`, `seed`, `dataflow`, `live_push`, `update_offer`, `package`, `installed`, `journal`, `users`, `onboarding`, `update_install`, `companion`, `history_exchange`, `backup`, `storage`, `network`, `settings_subpages`, `performance` | +| `kern` | Sources, fixture and seed data of the demo (`demo/demo.sh`), HTTPS, simulated power values, service logs, installed state, package and update fake | `topics`, `battery_config`, `shelly`, `seed`, `dataflow`, `live_push` | +| `updates` | The same as `kern` | `update_offer`, `package`, `installed`, `update_install` | +| `zugang` | The same as `kern` | `journal`, `users`, `onboarding`, `companion`, `history_exchange` | +| `system` | The same as `kern` | `backup`, `storage`, `network`, `settings_subpages`, `performance`, `monitoring` | | `ohne-dienste` | The demo sources, but all seven services switched off | `services_off` | | `bilanz` | `energie-ueberschuss.json` with the seed set `energie-alle-karten`, only the battery service, no simulation | `seed`, `energy_balance`, `companion` | | `seed` | The demo sources, plus an installer `onboarding-seed.json` next to `auth.pw` before the start | `onboarding_seed` | @@ -38,8 +43,10 @@ use makes the run fail, and the script leaves the process that holds it alone. Why each run exists: -- **`haupt`** checks the demo itself. The demo shows the same fixture, the same - seed data and the same services. +- **`kern`, `updates`, `zugang` and `system`** check the demo itself. The demo + shows the same fixture, the same seed data and the same services. They are four + runs so that CI can execute them side by side. Each one has to pass on its own, + so a check group must not depend on a group of another run. - **`ohne-dienste`** contradicts the demo on purpose. With all seven services off, only the `services_off` group applies. - **`bilanz`** needs exact energy values, which the simulation in the demo @@ -67,7 +74,11 @@ other ports, set the variables above before the call. ## CI -The CI job `dashboard-smoke` runs the same script (see `.github/workflows/ci.yml`). +The CI job `dashboard-smoke` runs the same script as a matrix: `kern`, `updates`, +`zugang` and `system` as one job each, the other four runs together as +`varianten` (see `.github/workflows/ci.yml`). The tests of the fakes run in the +job `dashboard-fakes`. A new check group goes into `gruppe()` and into one run +in `gruppen_fuer()`, which `scripts/tests/test_smoke_runs.py` checks. ## What is checked @@ -98,7 +109,7 @@ truth for the details. rights gets 403, no session 401, and deleted archives leave the status - the performance API under `/api/v1/performance` answers 200 with rows, units, target and measured time, and the settings page Leistung carries both tour - targets (`performance-budget`, `performance-measure`); the run `haupt` sets + targets (`performance-budget`, `performance-measure`); the run `system` sets `ENERGY_NODE_PERFORMANCE_FAKE=1` so the values are the invented ones - with the simulation on, the PV power under `/api/v1/topics/samples` changes within ten seconds, proof that the simulated values arrive as MQTT `PUBLISH` diff --git a/dashboard/test/smoke/checks/access.sh b/dashboard/test/smoke/checks/access.sh index aecbc3b80..085b3e618 100644 --- a/dashboard/test/smoke/checks/access.sh +++ b/dashboard/test/smoke/checks/access.sh @@ -4,7 +4,7 @@ # Benutzerverwaltung mit Sichten je Konto. Jede Funktion setzt bei einem Fehler # FAILED=1 und laeuft ohne Abbruch weiter. Die Auswahl der Gruppen trifft der Lauf. # Globals wie BASE, COOKIES, CURL_INSECURE, SECURE_HEADER, WORK kommen vom Aufrufer. -# check_status kommt aus core.sh. +# check_status, create_smoke_user und SMOKE_PASSWORD kommen aus core.sh. checks_journal() { # Service-Logs end-to-end, vom Endpunkt ueber sudo-Shim und Fake-Helper bis @@ -37,7 +37,6 @@ checks_users() { echo "==> Benutzerverwaltung: eingeschraenktes Konto" ADMIN_CSRF="$(api "$BASE/api/v1/auth/session" | python3 -c 'import json,sys; print(json.load(sys.stdin)["csrf_token"])')" SMOKE_USER="smoke-user" - SMOKE_PASSWORD="smoke-user-pass-1" USER_COOKIES="$WORK/smoke-user-cookies.txt" curl -sf "${CURL_INSECURE[@]}" -m 5 -o /dev/null -H "$SECURE_HEADER" -H "X-CSRF-Token: $ADMIN_CSRF" \ -H 'Content-Type: application/json' -X POST "$BASE/api/v1/users" \ @@ -80,13 +79,6 @@ sys.exit(0 if json.load(sys.stdin)["roles"] == [] else 1) # Ansehen auf Seitenebene: ein Konto mit nur view_stats sieht nur seine Seite. # Der Admin ergaenzt view_automations, dieselbe Sitzung darf sofort mehr. echo "==> Ansehen: eingeschraenktes Konto mit view_stats" - create_smoke_user() { # Name, Rollen (JSON), Cookie-Datei - curl -sf "${CURL_INSECURE[@]}" -m 5 -o /dev/null -H "$SECURE_HEADER" -H "X-CSRF-Token: $ADMIN_CSRF" \ - -H 'Content-Type: application/json' -X POST "$BASE/api/v1/users" \ - -b "$COOKIES" -d "{\"username\":\"$1\",\"password\":\"$SMOKE_PASSWORD\",\"roles\":$2}" || FAILED=1 - curl -sf "${CURL_INSECURE[@]}" -m 5 -c "$3" -H "$SECURE_HEADER" -H 'Content-Type: application/json' \ - -X POST "$BASE/api/v1/auth/login" -d "{\"username\":\"$1\",\"password\":\"$SMOKE_PASSWORD\"}" > /dev/null || FAILED=1 - } VIEWER_COOKIES="$WORK/smoke-viewer-cookies.txt" create_smoke_user "smoke-viewer" '["view_stats"]' "$VIEWER_COOKIES" check_status "Verlaufs-Entitaeten (anyView) fuer smoke-viewer erlaubt" "!403" "$VIEWER_COOKIES" "$BASE/api/v1/history/entities" diff --git a/dashboard/test/smoke/checks/core.sh b/dashboard/test/smoke/checks/core.sh index 7dc2668aa..1ebe7bac1 100644 --- a/dashboard/test/smoke/checks/core.sh +++ b/dashboard/test/smoke/checks/core.sh @@ -1,10 +1,22 @@ # shellcheck shell=bash # shellcheck disable=SC2154,SC2034 # Globals kommen vom Aufrufer, FAILED wird dort gelesen # Gemeinsame Pruefhelfer fuer die Smoke-Gruppen: check (JSON-Probe), -# check_status (HTTP-Code) und html_lacks (Praesenz im HTML). +# check_status (HTTP-Code), html_lacks (Praesenz im HTML) und create_smoke_user. # Die Gruppen setzen bei einem Fehler FAILED=1 und brechen nicht ab. # Globals wie BASE, COOKIES, CURL_INSECURE, SECURE_HEADER kommen vom Aufrufer. +# Kennwort aller Konten, die die Gruppen anlegen. +SMOKE_PASSWORD="smoke-user-pass-1" + +# Legt ein Konto an und meldet es an. ADMIN_CSRF kommt aus env_login. +create_smoke_user() { # Name, Rollen (JSON), Cookie-Datei + curl -sf "${CURL_INSECURE[@]}" -m 5 -o /dev/null -H "$SECURE_HEADER" -H "X-CSRF-Token: $ADMIN_CSRF" \ + -H 'Content-Type: application/json' -X POST "$BASE/api/v1/users" \ + -b "$COOKIES" -d "{\"username\":\"$1\",\"password\":\"$SMOKE_PASSWORD\",\"roles\":$2}" || FAILED=1 + curl -sf "${CURL_INSECURE[@]}" -m 5 -c "$3" -H "$SECURE_HEADER" -H 'Content-Type: application/json' \ + -X POST "$BASE/api/v1/auth/login" -d "{\"username\":\"$1\",\"password\":\"$SMOKE_PASSWORD\"}" > /dev/null || FAILED=1 +} + check() { # name, bedingung-als-python-ausdruck ueber `data` local name="$1" expression="$2" source="$3" if api "$source" | python3 -c " diff --git a/dashboard/test/smoke/checks/updates.sh b/dashboard/test/smoke/checks/updates.sh index 9a56fd2e1..2a250cdae 100644 --- a/dashboard/test/smoke/checks/updates.sh +++ b/dashboard/test/smoke/checks/updates.sh @@ -4,7 +4,7 @@ # mit installiertem Zustand und Installation durch ein Konto mit install_updates. # Jede Funktion setzt bei einem Fehler FAILED=1 und laeuft ohne Abbruch weiter. # Globals wie BASE, WORK, COOKIES, CURL_INSECURE, SECURE_HEADER kommen vom Aufrufer. -# checks_update_install nutzt create_smoke_user aus checks_users (access.sh). +# checks_update_install nutzt create_smoke_user aus core.sh. checks_update_offer() { # --simulate-update zeigt den Checker per ENERGY_NODE_UPDATES_API_BASE auf diff --git a/dashboard/test/smoke/smoke.sh b/dashboard/test/smoke/smoke.sh index 0a5010cd0..4ecccec31 100755 --- a/dashboard/test/smoke/smoke.sh +++ b/dashboard/test/smoke/smoke.sh @@ -1,17 +1,20 @@ #!/usr/bin/env bash -# Smoke-Test: startet das Dashboard in drei Konfigurationen und prueft je Lauf -# die gewaehlten Gruppen aus checks/. Gemeinsamer Unterbau (Start, Konfiguration, -# Daten, Abbau) liegt in demo/lib/env.sh. +# Smoke-Test: startet das Dashboard in mehreren Konfigurationen und prueft je Lauf +# die Gruppen aus checks/. Gemeinsamer Unterbau (Start, Konfiguration, Daten, +# Abbau) liegt in demo/lib/env.sh. # -# dashboard/test/smoke/smoke.sh # alle drei Laeufe -# dashboard/test/smoke/smoke.sh --run haupt # nur einen Lauf, mehrfach angebbar +# dashboard/test/smoke/smoke.sh # alle Laeufe nacheinander +# dashboard/test/smoke/smoke.sh --run kern # nur einen Lauf, mehrfach angebbar +# dashboard/test/smoke/smoke.sh --run haupt # kern, updates, zugang, system +# dashboard/test/smoke/smoke.sh --list # Laeufe und ihre Gruppen # # Laeufe in fester Reihenfolge, jeder frisch in .run/-XXXXXX. Bestanden: # der Ordner wird geloescht. Fehlgeschlagen: der Ordner bleibt fuer die Analyse. # Exit 0 nur, wenn alle gewaehlten Laeufe gruen sind. # -# Lauf haupt: prueft genau die Demo (demo/demo.sh, Standard). Alle Gruppen, weil -# die Demo dieselbe Fixture, dieselben Seeds und dieselben Dienste zeigt. +# Laeufe kern, updates, zugang, system: pruefen genau die Demo (demo/demo.sh, +# Standard), weil die Demo dieselbe Fixture, dieselben Seeds und dieselben +# Dienste zeigt. Vier Laeufe, damit die CI sie nebeneinander ausfuehren kann. # Lauf ohne-dienste: widerspricht der Demo. Alle sieben Dienste sind aus, deshalb # nur die Gruppe services_off. # Lauf bilanz: die Bilanz braucht exakte Werte ohne Simulation. Ueber HTTP laeuft @@ -61,12 +64,32 @@ RUN_DIR="$SMOKE_DIR/.run" BIN="$RUN_DIR/bin/dashboard" FAILED=0 +# Laeufe in Ausfuehrungsreihenfolge. +HAUPT_LAEUFE=(kern updates zugang system) +ALLE_LAEUFE=("${HAUPT_LAEUFE[@]}" ohne-dienste bilanz seed falsches-passwort) + trap env_cleanup EXIT trap 'exit 130' INT TERM usage() { - echo "Aufruf: dashboard/test/smoke/smoke.sh [--run NAME]..." >&2 - echo "Laeufe: haupt, ohne-dienste, bilanz, seed, falsches-passwort" >&2 + echo "Aufruf: dashboard/test/smoke/smoke.sh [--run NAME]... | --list" >&2 + echo "Laeufe: ${ALLE_LAEUFE[*]}, haupt (= ${HAUPT_LAEUFE[*]})" >&2 +} + +# Die Gruppen eines Laufs, in Ausfuehrungsreihenfolge. Jede Gruppe aus gruppe() +# gehoert in mindestens einen Lauf (scripts/tests/test_smoke_runs.py). +gruppen_fuer() { + case "$1" in + kern) echo "topics battery_config shelly seed dataflow live_push" ;; + updates) echo "update_offer package installed update_install" ;; + zugang) echo "journal users onboarding companion history_exchange" ;; + system) echo "backup storage network settings_subpages performance monitoring" ;; + ohne-dienste) echo "services_off" ;; + bilanz) echo "seed energy_balance companion" ;; + seed) echo "onboarding_seed" ;; + falsches-passwort) echo "mqtt_falsch" ;; + *) return 1 ;; + esac } # Setzt alle Schalter auf den Stand "aus". Jeder Lauf schaltet nur sein Noetiges an. @@ -251,31 +274,36 @@ while [[ $# -gt 0 ]]; do usage exit 2 fi - case "$2" in - haupt|ohne-dienste|bilanz|seed|falsches-passwort) WANTED+=("$2") ;; - *) - echo "FEHLER: unbekannter Lauf $2" >&2 - usage - exit 2 - ;; - esac + if [[ "$2" == haupt ]]; then + WANTED+=("${HAUPT_LAEUFE[@]}") + elif gruppen_fuer "$2" >/dev/null; then + WANTED+=("$2") + else + echo "FEHLER: unbekannter Lauf $2" >&2 + usage + exit 2 + fi shift 2 ;; + --list) + for name in "${ALLE_LAEUFE[@]}"; do + echo "$name: $(gruppen_fuer "$name")" + done + exit 0 + ;; -h|--help) usage; exit 0 ;; *) echo "FEHLER: unbekannte Option $1" >&2; usage; exit 2 ;; esac done if (( ${#WANTED[@]} == 0 )); then - WANTED=(haupt ohne-dienste bilanz seed falsches-passwort) + WANTED=("${ALLE_LAEUFE[@]}") fi vorbereiten || exit 1 # Reihenfolge fest, egal in welcher Reihenfolge --run angegeben wurde. -# Gruppen: haupt prueft die Demo, ohne-dienste prueft abgeschaltete Dienste, -# bilanz prueft exakte Energiewerte ohne Simulation. RESULT=0 -for name in haupt ohne-dienste bilanz seed falsches-passwort; do +for name in "${ALLE_LAEUFE[@]}"; do wanted=0 for w in "${WANTED[@]}"; do [[ "$w" == "$name" ]] && wanted=1 @@ -284,29 +312,14 @@ for name in haupt ohne-dienste bilanz seed falsches-passwort; do setze_grundstand case "$name" in - haupt) - konfiguriere_haupt - fuehre_lauf haupt topics battery_config shelly seed dataflow live_push \ - update_offer package installed journal users onboarding update_install companion \ - history_exchange backup storage network settings_subpages performance monitoring || RESULT=1 - ;; - ohne-dienste) - konfiguriere_ohne_dienste - fuehre_lauf ohne-dienste services_off || RESULT=1 - ;; - bilanz) - konfiguriere_bilanz - fuehre_lauf bilanz seed energy_balance companion || RESULT=1 - ;; - seed) - konfiguriere_seed - fuehre_lauf seed onboarding_seed || RESULT=1 - ;; - falsches-passwort) - konfiguriere_falsches_passwort - fuehre_lauf falsches-passwort mqtt_falsch || RESULT=1 - ;; + ohne-dienste) konfiguriere_ohne_dienste ;; + bilanz) konfiguriere_bilanz ;; + seed) konfiguriere_seed ;; + falsches-passwort) konfiguriere_falsches_passwort ;; + *) konfiguriere_haupt ;; esac + read -r -a GRUPPEN <<<"$(gruppen_fuer "$name")" + fuehre_lauf "$name" "${GRUPPEN[@]}" || RESULT=1 done exit "$RESULT" diff --git a/scripts/ci/detect_changes.py b/scripts/ci/detect_changes.py index 019ea99d1..c70230bc9 100644 --- a/scripts/ci/detect_changes.py +++ b/scripts/ci/detect_changes.py @@ -81,6 +81,8 @@ frozenset({"dashboard_go", "dashboard_js", "dashboard_smoke"})), # 15 (re.compile(r"^dashboard/.*_test\.go$"), frozenset({"dashboard_go"})), + # Smoke-Laeufe: der Waechtertest scripts/tests/test_smoke_runs.py laeuft mit python. + (re.compile(r"^dashboard/test/smoke/smoke\.sh$"), frozenset({"dashboard_smoke", "python"})), # 16 (re.compile(r"^dashboard/test/smoke/|^demo/"), frozenset({"dashboard_smoke"})), # 17 diff --git a/scripts/tests/test_detect_changes.py b/scripts/tests/test_detect_changes.py index cae7adec1..44a299bab 100644 --- a/scripts/tests/test_detect_changes.py +++ b/scripts/tests/test_detect_changes.py @@ -40,7 +40,8 @@ ("dashboard/internal/webui/templates/base.html", {"dashboard_go", "dashboard_js", "dashboard_smoke"}), ("dashboard/internal/webui/catalogs/en.json", {"dashboard_go", "dashboard_js", "dashboard_smoke"}), ("dashboard/internal/webui/webui_test.go", {"dashboard_go"}), - ("dashboard/test/smoke/smoke.sh", {"dashboard_smoke"}), + ("dashboard/test/smoke/smoke.sh", {"dashboard_smoke", "python"}), + ("dashboard/test/smoke/checks/core.sh", {"dashboard_smoke"}), ("demo/fakes/fake_shelly.py", {"dashboard_smoke"}), ("dashboard/test/browser/screenshot.mjs", set()), ("dashboard/test/config.page.test.mjs", {"dashboard_js"}), diff --git a/scripts/tests/test_smoke_runs.py b/scripts/tests/test_smoke_runs.py new file mode 100644 index 000000000..3324b8130 --- /dev/null +++ b/scripts/tests/test_smoke_runs.py @@ -0,0 +1,44 @@ +"""Haelt Pruefgruppen, Laeufe von smoke.sh und die CI-Matrix zusammen.""" +import re +import subprocess +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +SMOKE = ROOT / "dashboard" / "test" / "smoke" / "smoke.sh" + +TEILE = { + "kern": ["topics", "battery_config", "shelly", "seed", "dataflow", "live_push"], + "updates": ["update_offer", "package", "installed", "update_install"], + "zugang": ["journal", "users", "onboarding", "companion", "history_exchange"], + "system": ["backup", "storage", "network", "settings_subpages", "performance", "monitoring"], +} + + +def laeufe() -> dict[str, list[str]]: + out = subprocess.run(["bash", str(SMOKE), "--list"], capture_output=True, text=True, check=True).stdout + result = {} + for line in out.splitlines(): + name, _, gruppen = line.partition(":") + result[name] = gruppen.split() + return result + + +def test_every_group_runs_exactly_where_expected(): + found = laeufe() + assert {name: found.get(name) for name in TEILE} == TEILE + assert set(found) == set(TEILE) | {"ohne-dienste", "bilanz", "seed", "falsches-passwort"} + + +def test_every_group_of_gruppe_is_in_a_run(): + text = SMOKE.read_text(encoding="utf-8") + known = set(re.findall(r"^\s+(\w+)\) checks_\w+ ;;", text, re.MULTILINE)) + assert known, "keine Gruppen in gruppe() gefunden" + listed = {g for gruppen in laeufe().values() for g in gruppen} + assert known - listed == set() + assert listed - known == set() + + +def test_no_group_is_in_two_haupt_parts(): + found = laeufe() + gruppen = [g for name in TEILE for g in found[name]] + assert len(gruppen) == len(set(gruppen)) From 2e37d7f912e91920dd1d2e80e60baf69af33207c Mon Sep 17 00:00:00 2001 From: DevSimon <73778205+Developer-Simon@users.noreply.github.com> Date: Sun, 29 Nov 2026 23:38:40 +0100 Subject: [PATCH 4/6] ci: run the smoke test as parallel jobs and restore the Go caches dashboard-smoke becomes a matrix of kern, updates, zugang, system and varianten, and the tests of the fakes get their own job, so the longest part sets the waiting time. Every setup-go step now names the file for its cache key, because the default looks for go.sum in the repository root and never found one. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/ci.yml | 53 +++++++++++++++++++++++++++----- scripts/tests/test_smoke_runs.py | 19 ++++++++++++ 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 41fda0492..f00a3bd0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -118,6 +118,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: dashboard/go.mod + cache-dependency-path: dashboard/go.sum - run: test -z "$(gofmt -l .)" - run: go vet ./... - run: go test ./... @@ -135,6 +136,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: installer/go.mod + cache-dependency-path: installer/go.sum - run: test -z "$(gofmt -l .)" - run: go vet ./... # Task 5 braucht einen echten sshd fuer den Transport-Integrationstest; @@ -172,6 +174,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: installer/go.mod + cache-dependency-path: installer/go.sum - run: go test ./internal/media/... ./internal/host/... ./cmd/installer/... # Die Medien-Vorbereitung auf macOS mit dem echten Imager. Der Imager @@ -194,6 +197,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: installer/go.mod + cache-dependency-path: installer/go.sum - name: Install the Raspberry Pi Imager run: brew install --cask raspberry-pi-imager - name: Unit tests of the media mode @@ -266,29 +270,60 @@ jobs: - run: npm ci - run: npm test + # Die Tests der Fakes, die der Smoke-Test benutzt. Eigener Job, damit sie + # neben den Laeufen statt davor laufen. + dashboard-fakes: + name: Demo fakes (tests) + needs: changes + if: needs.changes.outputs.dashboard_smoke == 'true' || github.event_name == 'push' + runs-on: ubuntu-latest + defaults: + run: + working-directory: demo/fakes + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + - run: pip install pytest + - run: python -m pytest -q + + # Ein Job je Zweig, jeder baut und startet sein eigenes Dashboard. Jeder Lauf + # von smoke.sh steht in genau einem Zweig (scripts/tests/test_smoke_runs.py). dashboard-smoke: - name: Dashboard smoke test + name: Dashboard smoke test (${{ matrix.teil }}) needs: changes if: needs.changes.outputs.dashboard_smoke == 'true' || github.event_name == 'push' runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - teil: kern + laeufe: --run kern + - teil: updates + laeufe: --run updates + - teil: zugang + laeufe: --run zugang + - teil: system + laeufe: --run system + - teil: varianten + laeufe: --run ohne-dienste --run bilanz --run seed --run falsches-passwort steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version-file: dashboard/go.mod + cache-dependency-path: dashboard/go.sum - uses: actions/setup-python@v5 with: python-version: "3.12" - - run: pip install pytest - - name: Fake tests - working-directory: demo/fakes - run: python -m pytest -q - name: Smoke test - run: dashboard/test/smoke/smoke.sh + run: dashboard/test/smoke/smoke.sh ${{ matrix.laeufe }} - if: failure() uses: actions/upload-artifact@v4 with: - name: dashboard-smoke-logs + name: dashboard-smoke-logs-${{ matrix.teil }} path: dashboard/test/smoke/.run/ if-no-files-found: ignore @@ -305,6 +340,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version: '1.22' + cache-dependency-path: installer/webui/go.mod - run: test -z "$(gofmt -l .)" - run: go vet ./... - run: go test ./... @@ -340,6 +376,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version: '1.22' + cache-dependency-path: installer/webui/go.mod - uses: actions/setup-node@v4 with: node-version: 22 @@ -379,6 +416,7 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: installer/go.mod + cache-dependency-path: installer/go.sum - name: Build for ${{ matrix.target }} env: TARGET: ${{ matrix.target }} @@ -601,6 +639,7 @@ jobs: - installer-windows - installer-macos - dashboard-js + - dashboard-fakes - dashboard-smoke - installer-webui-go - installer-webui-js diff --git a/scripts/tests/test_smoke_runs.py b/scripts/tests/test_smoke_runs.py index 3324b8130..90e3a622a 100644 --- a/scripts/tests/test_smoke_runs.py +++ b/scripts/tests/test_smoke_runs.py @@ -42,3 +42,22 @@ def test_no_group_is_in_two_haupt_parts(): found = laeufe() gruppen = [g for name in TEILE for g in found[name]] assert len(gruppen) == len(set(gruppen)) + + +def ci_job(name: str) -> str: + text = (ROOT / ".github" / "workflows" / "ci.yml").read_text(encoding="utf-8") + match = re.search(rf"^ {name}:\n(.*?)(?=^ [\w-]+:\n|\Z)", text, re.MULTILINE | re.DOTALL) + assert match, f"Job {name} fehlt in ci.yml" + return match[1] + + +def test_ci_matrix_runs_every_run_once(): + names = re.findall(r"--run (\S+)", ci_job("dashboard-smoke")) + assert sorted(names) == sorted(laeufe()) + + +def test_every_setup_go_has_a_cache_dependency_path(): + text = (ROOT / ".github" / "workflows" / "ci.yml").read_text(encoding="utf-8") + paths = re.findall(r"^\s+cache-dependency-path: (\S+/go\.(?:sum|mod))$", text, re.MULTILINE) + assert len(paths) == text.count("actions/setup-go@") + assert [p for p in paths if not (ROOT / p).is_file()] == [] From 5fed69059761abc6ec09ce27aec7c64d16416d76 Mon Sep 17 00:00:00 2001 From: energy-node-bot Date: Sun, 29 Nov 2026 22:45:38 +0000 Subject: [PATCH 5/6] chore(release): bump component versions --- dashboard/VERSION | 2 +- installer/VERSION | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dashboard/VERSION b/dashboard/VERSION index 4e86b9543..aa6dc42ee 100644 --- a/dashboard/VERSION +++ b/dashboard/VERSION @@ -1 +1 @@ -v0.11.22-pre.38 +v0.11.22-pre.39 diff --git a/installer/VERSION b/installer/VERSION index 06a71cc10..cc85b486c 100644 --- a/installer/VERSION +++ b/installer/VERSION @@ -1 +1 @@ -v0.3.4-pre.8 +v0.3.4-pre.9 From 1412dec7d1af97d192b33be6250b19001975c51c Mon Sep 17 00:00:00 2001 From: energy-node-bot Date: Sun, 29 Nov 2026 22:46:39 +0000 Subject: [PATCH 6/6] docs(changelog): update changelogs --- dashboard/CHANGELOG.md | 7 ++++++- installer/CHANGELOG.md | 6 ++++-- installer/webui/CHANGELOG.md | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/dashboard/CHANGELOG.md b/dashboard/CHANGELOG.md index ed8d31682..f377c6f58 100644 --- a/dashboard/CHANGELOG.md +++ b/dashboard/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.11.22-pre.38 (2026-11-06) +## v0.11.22-pre.39 (2026-11-06) ### Features @@ -546,6 +546,7 @@ ### Tests +- **smoke:** split the main run into four independent runs (fa7e3df) - **demo:** expect a sure effect beside the estimates (aa987aa) - **demo:** fake the system packages for the versions page (ca2dc1e) - **autolearn:** keep the cycle test window open until today (ab438d5) @@ -606,6 +607,10 @@ - **webui:** record the cache-bust history for the performance check assets (c01d9e9) - **webui:** record the cache-bust marks of the performance page (5b896c1) +### CI + +- parallelize the smoke test and run the macOS media check (#302) + ## v0.11.20 (2026-11-16) ### Features diff --git a/installer/CHANGELOG.md b/installer/CHANGELOG.md index 3bbdd8866..82e5f5c71 100644 --- a/installer/CHANGELOG.md +++ b/installer/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## v0.3.4-pre.8 (2026-11-15) +## v0.3.4-pre.9 (2026-11-15) ### Features @@ -11,11 +11,11 @@ - **installer:** The configure screen of the installer shows its services and tuning as modules (#280) (f85e2a6) - **installer:** apply a changed service selection without a full update (#282) (ab11a7a) - **installer:** prepare storage media on Windows (#298) (96ffa09) +- **installer:** prepare storage media on macOS (#301) (d68584e) - **installer:** find the Raspberry Pi Imager on macOS (539c6c9) - **installer:** write media on macOS with the imager's own authorization (2dde909) - **installer:** list macOS drives for the media mode (c76d1ae) - **installer:** take timezone, keyboard and country from macOS (5864fd9) -- **installer:** prepare storage media on macOS (#301) - **installer:** check the target again before writing and read Windows imager output (c0a7cd7) - **installer:** add the zone tables for the media defaults (d895abc) - **installer:** add the media helper that runs the imager on behalf of the installer (b24ec8d) @@ -104,6 +104,8 @@ ### CI +- run the macOS media check as a job of the CI workflow (765c84e) +- parallelize the smoke test and run the macOS media check (#302) - check the media mode on a macOS runner with a RAM disk (f1eb28c) - run the installer media tests on Windows (c7d413f) diff --git a/installer/webui/CHANGELOG.md b/installer/webui/CHANGELOG.md index 05d191e05..ff1041854 100644 --- a/installer/webui/CHANGELOG.md +++ b/installer/webui/CHANGELOG.md @@ -14,9 +14,9 @@ - **installer:** apply a changed service selection without a full update (#282) (ab11a7a) - **installer:** highlight that the Debian stick needs a network cable (#286) (01a23f2) - **installer:** prepare storage media on Windows (#298) (96ffa09) +- **installer:** prepare storage media on macOS (#301) (d68584e) - **installer:** add the macOS texts of the media mode (6f270aa) - **installer:** show the macOS install paths for the imager (1141119) -- **installer:** prepare storage media on macOS (#301) - **installer:** show the Windows install paths for the imager (4b4a5c1) - **installer:** add texts for the running and cancelling write (2fb9672) - **installer:** add the hint text for small media (b4d7e92)