Skip to content

Commit 09ff1c3

Browse files
committed
chore(demo): refresh the console demo from the cozystack monorepo
Build the /demo/ console from the cozystack monorepo instead of the archived cozystack-ui, and bring the mock layer up to the current console. - build.sh clones packages/system/dashboard/images/console sparse and labels the header; the refresh workflow watches static/demo-app. - The smoke check sees un-mocked calls now and crawls 250 screens. - Mock Repositories, Migration, KubeVirt power state and the option sources behind the create forms; populate every instance's tabs. - Resolve inherited module status, drop sign out, and show Repositories under Admin ahead of cozystack/cozystack#4286 through a temporary patch. Assisted-by: LLM Signed-off-by: Andrei Kvapil <[email protected]>
1 parent 06cfe86 commit 09ff1c3

22 files changed

Lines changed: 1029 additions & 230 deletions

‎.github/workflows/demo-refresh.yml‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
# Rebuilds the mocked console demo (static/demo) from upstream cozystack-ui and
2-
# opens a PR with the result. Self-contained: the demo overlay lives in
3-
# demo-src/, the build clones upstream fresh, and the PR is opened in THIS repo
4-
# with the built-in GITHUB_TOKEN — no external tokens, no forks.
1+
# Rebuilds the mocked console demo (static/demo-app) from the console in the
2+
# cozystack monorepo and opens a PR with the result. Self-contained: the demo
3+
# overlay lives in demo-src/, the build clones upstream fresh, and the PR is
4+
# opened in THIS repo with the built-in GITHUB_TOKEN — no external tokens, no
5+
# forks.
56
#
67
# Requires: Settings → Actions → General → "Allow GitHub Actions to create and
78
# approve pull requests" (enabled once). This repo is public, so Actions
@@ -34,23 +35,26 @@ jobs:
3435
cache: pnpm
3536

3637
- name: Build demo from upstream (with smoke gate)
38+
env:
39+
# Label shown in the demo header; bump it with the release line.
40+
DEMO_VERSION: v1.7.0-rc.2
3741
run: bash demo-src/build.sh main
3842

3943
- name: Open a PR if the demo changed
4044
env:
4145
GH_TOKEN: ${{ github.token }}
4246
run: |
43-
if git diff --quiet -- static/demo; then
47+
if git diff --quiet -- static/demo-app; then
4448
echo "No demo changes — nothing to do."
4549
exit 0
4650
fi
4751
BR="demo/refresh-${GITHUB_RUN_ID}"
4852
git config user.name "github-actions[bot]"
4953
git config user.email "github-actions[bot]@users.noreply.github.com"
5054
git checkout -b "$BR"
51-
git add static/demo
52-
git commit --signoff -m "chore(demo): refresh mocked console demo from cozystack-ui"
55+
git add static/demo-app
56+
git commit --signoff -m "chore(demo): refresh mocked console demo from cozystack main"
5357
git push origin "$BR"
5458
gh pr create --base main --head "$BR" --draft \
5559
--title "chore(demo): refresh mocked console demo" \
56-
--body "Automated rebuild of the /demo/ bundle from the current cozystack-ui. The Playwright smoke check (every sidebar/tab screen, no un-mocked API call or page error) passed on this build. Review the Netlify deploy preview, then merge. Not auto-merged."
60+
--body "Automated rebuild of the /demo-app/ bundle from the console in the current cozystack main. The Playwright smoke check (every sidebar/tab screen, no un-mocked API call or page error) passed on this build. Review the Netlify deploy preview, then merge. Not auto-merged."

‎demo-src/build.sh‎

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,57 @@
11
#!/usr/bin/env bash
2-
# Builds the mocked Cozystack console demo into ../static/demo.
2+
# Builds the mocked Cozystack console demo into ../static/demo-app.
33
#
4-
# The demo is a thin overlay on cozystack/cozystack-ui: a few new files
5-
# (demo/ mock layer, MSW worker, smoke test) plus small patches to main.tsx,
6-
# vite.config and the manifests. This fetches upstream fresh, lays the overlay
7-
# on top, smoke-checks a root build, then produces the /demo/ bundle.
4+
# The console lives in the cozystack monorepo under
5+
# packages/system/dashboard/images/console. It used to be its own repository,
6+
# cozystack/cozystack-ui, which was archived in June 2026 — building from there
7+
# now pins the demo to a June snapshot, so this script follows the monorepo.
88
#
9-
# demo-src/build.sh [cozystack-ui-ref] # ref defaults to "main"
9+
# The demo is a thin overlay on that tree: a few new files (demo/ mock layer,
10+
# MSW worker, smoke test) plus small patches to main.tsx, vite.config and the
11+
# manifests. This fetches upstream fresh, lays the overlay on top, smoke-checks
12+
# a root build, then produces the /demo-app/ bundle.
13+
#
14+
# demo-src/build.sh [cozystack-ref] # branch or tag, defaults to "main"
1015
# SKIP_SMOKE=1 demo-src/build.sh # regenerate the bundle only
16+
# DEMO_VERSION=v1.7.0 demo-src/build.sh # label the header explicitly
1117
#
1218
set -euo pipefail
1319

1420
REF="${1:-main}"
21+
REPO="${DEMO_UI_REPO:-https://github.com/cozystack/cozystack.git}"
22+
SUBDIR="${DEMO_UI_SUBDIR:-packages/system/dashboard/images/console}"
1523
HERE="$(cd "$(dirname "$0")" && pwd)"
1624
SITE="$(cd "$HERE/.." && pwd)"
1725
WORK="$(mktemp -d)"
1826
trap 'rm -rf "$WORK"' EXIT
27+
SRC="$WORK/src"
1928
UI="$WORK/ui"
2029

21-
echo "==> cloning cozystack-ui @ $REF"
22-
git clone --depth 1 --branch "$REF" https://github.com/cozystack/cozystack-ui.git "$UI"
30+
echo "==> cloning $REPO @ $REF ($SUBDIR)"
31+
# Blobless + sparse: the monorepo is large and only the console tree is wanted.
32+
git clone --filter=blob:none --no-checkout --depth 1 --branch "$REF" "$REPO" "$SRC"
33+
git -C "$SRC" sparse-checkout set --no-cone "$SUBDIR"
34+
git -C "$SRC" checkout
35+
# Shown in the header where a release build shows its version, so a visitor (and
36+
# a reviewer of the refresh PR) can tell which upstream commit the demo is. A
37+
# release tag reads as itself, a branch as branch@sha; DEMO_VERSION overrides.
38+
if [ -n "${DEMO_VERSION:-}" ]; then
39+
VERSION="$DEMO_VERSION"
40+
elif git -C "$SRC" rev-parse -q --verify "refs/tags/$REF" >/dev/null; then
41+
VERSION="$REF"
42+
else
43+
VERSION="$REF@$(git -C "$SRC" rev-parse --short HEAD)"
44+
fi
45+
export VITE_APP_VERSION="$VERSION"
46+
47+
# The patches are rooted at the console directory, so lift that subtree into a
48+
# repository of its own — `git apply --3way` then resolves their preimages, and
49+
# the overlay paths stay the same as when the console had its own repo.
50+
mkdir -p "$UI"
51+
cp -R "$SRC/$SUBDIR/." "$UI/"
52+
git -C "$UI" init -q
53+
git -C "$UI" add -A
54+
git -C "$UI" -c user.email=demo@localhost -c user.name=demo commit -qm "upstream $REF"
2355

2456
echo "==> applying demo overlay"
2557
cp -R "$HERE/overlay/." "$UI/"
@@ -45,7 +77,7 @@ if [ "${SKIP_SMOKE:-0}" != "1" ]; then
4577
SMOKE_DIST="$UI/apps/console/dist" node apps/console/demo-smoke.mjs )
4678
fi
4779

48-
echo "==> building demo (base /demo/)"
80+
echo "==> building demo (base /demo-app/, version $VERSION)"
4981
( cd "$UI"
5082
VITE_DEMO=1 DEMO_BASE_PATH=/demo-app/ pnpm --filter @cozystack/console build
5183
cp apps/console/dist/index.html apps/console/dist/404.html )

‎demo-src/overlay/apps/console/demo-smoke.mjs‎

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1-
// Demo smoke check for the mocked console. Serves nothing itself — point it at
2-
// a running static server of the VITE_DEMO build (SPA fallback required):
1+
// Demo smoke check for the mocked console. Self-contained — it serves the built
2+
// bundle itself (SPA fallback included) and drives a headless browser over it:
33
//
44
// VITE_DEMO=1 pnpm --filter @cozystack/console build
5-
// cp apps/console/dist/index.html apps/console/dist/404.html
6-
// (serve apps/console/dist on $SMOKE_BASE with SPA fallback)
7-
// node apps/console/demo-smoke.mjs
5+
// SMOKE_DIST=apps/console/dist node apps/console/demo-smoke.mjs
86
//
9-
// It walks every sidebar/tab destination reachable from the three top sections,
10-
// visits each, and fails on any un-mocked Kubernetes call (4xx/5xx to /api or
11-
// /apis), any page error. Exit code is non-zero on
7+
// It crawls every destination reachable from the three top sections — list
8+
// screens, detail tabs, create forms — and fails on any un-mocked Kubernetes
9+
// call (4xx/5xx to /api or /apis) or any page error. Exit code is non-zero on
1210
// failure so CI can gate a deploy on it.
1311

1412
import { chromium } from "@playwright/test"
1513
import http from "node:http"
1614
import fs from "node:fs"
1715
import path from "node:path"
1816

19-
// Self-contained: serve the built demo (SPA fallback) so CI just runs
20-
// VITE_DEMO=1 pnpm --filter @cozystack/console build && node demo-smoke.mjs
2117
const DIST = process.env.SMOKE_DIST || "dist"
2218
const TYPES = { ".html":"text/html", ".js":"text/javascript", ".css":"text/css", ".json":"application/json", ".svg":"image/svg+xml", ".ico":"image/x-icon", ".woff2":"font/woff2", ".png":"image/png" }
2319
const server = http.createServer((req, res) => {
2420
const url = req.url.split("?")[0]
21+
// Kubernetes paths never fall back to index.html. MSW passes a request it has
22+
// no handler for straight through to the network, and with a blanket SPA
23+
// fallback that request would come back 200 text/html — so a screen the mock
24+
// layer has never heard of would look exactly like a working one. Answering
25+
// 404 here is what makes an un-mocked call visible to the check below.
26+
if (/^\/(api|apis)(\/|$)/.test(url)) {
27+
res.statusCode = 404
28+
res.end("not mocked")
29+
return
30+
}
2531
let file = path.join(DIST, url)
2632
if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) file = path.join(DIST, "index.html")
2733
res.setHeader("Content-Type", TYPES[path.extname(file)] || "application/octet-stream")
@@ -53,21 +59,32 @@ page.on("response", (r) => {
5359
})
5460
page.on("pageerror", (e) => pageErrors.push(String(e).slice(0, 160)))
5561

56-
const routes = new Set(ENTRIES)
57-
for (const entry of ENTRIES) {
58-
await page.goto(BASE + entry, { waitUntil: "domcontentloaded" })
59-
await page.waitForTimeout(1500)
60-
for (const href of await page
61-
.locator("aside a, nav a, [role=tablist] a, a[href^='/console'], a[href^='/admin'], a[href^='/marketplace']")
62-
.evaluateAll((as) => as.map((a) => a.getAttribute("href"))))
63-
if (href && href.startsWith("/") && !href.startsWith("//")) routes.add(href)
64-
}
62+
const LINK_SEL =
63+
"aside a, nav a, [role=tablist] a, a[href^='/console'], a[href^='/admin'], a[href^='/marketplace']"
64+
const harvest = async () =>
65+
(await page.locator(LINK_SEL).evaluateAll((as) => as.map((a) => a.getAttribute("href"))))
66+
.filter((h) => h && h.startsWith("/") && !h.startsWith("//"))
6567

66-
console.log(`\n########## visiting ${routes.size} destinations\n`)
67-
for (const route of [...routes].sort()) {
68-
await page.goto(BASE + route, { waitUntil: "domcontentloaded" })
69-
await page.waitForTimeout(1200)
68+
// Crawl outwards from the three top sections rather than only one hop: a hop
69+
// reaches the list screens, and it takes a second to reach the tabs of a detail
70+
// page and the create forms behind a "New …" button — which is where the mock
71+
// layer actually tends to have holes.
72+
const seen = new Set()
73+
let frontier = [...ENTRIES]
74+
for (let wave = 0; wave < 3 && frontier.length; wave++) {
75+
console.log(`\n########## wave ${wave}: ${frontier.length} destinations\n`)
76+
const next = new Set()
77+
for (const route of [...frontier].sort()) {
78+
if (seen.has(route)) continue
79+
seen.add(route)
80+
console.log(" " + route)
81+
await page.goto(BASE + route, { waitUntil: "domcontentloaded" })
82+
await page.waitForTimeout(1200)
83+
for (const h of await harvest()) if (!seen.has(h)) next.add(h)
84+
}
85+
frontier = [...next]
7086
}
87+
console.log(`\n########## visited ${seen.size} destinations\n`)
7188
// This console has no distinct "not found" screen (an unknown route just
7289
// renders the shell), so a broken screen shows up as an un-mocked API call or
7390
// a page error, both collected above — not as body text.

‎demo-src/overlay/apps/console/src/demo/browser.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { setupWorker } from "msw/browser"
22
import { handlers } from "./handlers.ts"
33

4-
// Запускается только в demo-сборке (VITE_DEMO=1). unhandled-запросы пропускаем
5-
// молча — часть путей k8s UI может дёргать опционально.
4+
// Only ever started in a demo build (VITE_DEMO=1). Unhandled requests are let
5+
// through silently — the Kubernetes UI asks for some paths optionally.
66
export async function startDemo() {
77
const worker = setupWorker(...handlers)
8-
// worker + его scope должны жить под base-путём (напр. /demo/), иначе на
9-
// под-путях моки не перехватываются.
8+
// The worker and its scope have to live under the base path (e.g. /demo-app/),
9+
// otherwise nothing is intercepted on sub-paths.
1010
await worker.start({
1111
onUnhandledRequest: "bypass",
1212
quiet: true,

0 commit comments

Comments
 (0)