Skip to content

Latest commit

 

History

History
156 lines (129 loc) · 16.5 KB

README.md

File metadata and controls

156 lines (129 loc) · 16.5 KB

PoPunkouterSoftware

PoPunkouterSoftware is the Po apps portfolio and Azure ops dashboard: a .NET 10 Blazor Web App (ASP.NET Core host + WebAssembly client) showing every Po app, how each is built, and the health, uptime, cost and security of the Azure estate behind them.

  • Live: https://app-popunkoutersoftware2.azurewebsites.net (System status: /diag)
  • Deploys: every push to master runs .github/workflows/deploy.yml (format, ruff, build, Unit + Integration tests, publish, deploy to App Service, confirm /health/live reports the pushed commit in X-Commit).
  • Agents and contributors: read AGENTS.md; the architecture map is docs/architecture.md, the test tiers docs/testing.md. Before/after pages of UI changes are kept in SCREENSHOTS/; pwsh ./scripts/screenshots.ps1 -Feature <name> makes one (local Release builds of before and after, never the live site).

Solution Layout

  • src/PoPunkouterSoftware.Api/: ASP.NET Core host + BFF. Feature slices under Features/<Area>/ (Config, Diag, Portfolio, SignIns); host-level plumbing that belongs to no slice lives in Host/. Hosts the Blazor WASM shell.
  • src/PoPunkouterSoftware.Client/: WASM UI, layouts, pages, and static assets.
  • src/PoPunkouterSoftware.Shared/: contracts and models shared between the host and client.
  • src/PoPunkouterSoftware.Infrastructure/: Azure and integration adapters.
  • tests/PoPunkouterSoftware.Unit/: xUnit, strictly no-I/O.
  • tests/PoPunkouterSoftware.Integration/: WebApplicationFactory in-process host & contract tests.
  • tests/PoPunkouterSoftware.E2EAPI/: pure-HTTP contract tests against a live instance.
  • tests/PoPunkouterSoftware.E2EUI/: C# Playwright browser tests (run on demand against a live instance).
  • scripts/: setup and helper scripts (run-dev.ps1, ensure-azure-access.ps1, post-deploy-smoke.ps1, the icon-font subset builder) and the GLOBAL crawlers under scripts/global/ (build_global_data.py refreshes the fleet snapshot the /global pages read).
  • infra/: Bicep (main.bicep, main.bicepparam, modules/), applied by hand.
  • docs/: architecture and testing notes, the Google Cloud training runbook (docs/gcp-training.md), the GitHub Pages site (privacy pages linked from app stores), the UNITE prefabs and rules in docs/unite/, and the GLOBAL migration record in docs/global-migration.md.

Local Development

Prerequisites:

  • .NET SDK from global.json
  • az login as the owner (Storage Table Data Contributor on stpopunkoutersoftware2; local and Azure both use Azure Table Storage, never Azurite)
  • PowerShell 7 (scripts/run-dev.ps1)

Common commands (the full, tested list is "3. Verification" in AGENTS.md):

pwsh ./scripts/run-dev.ps1 -NoWatch        # http://localhost:8000 (cloud Table Storage, shared by every laptop)
dotnet build PoPunkouterSoftware.slnx -c Release
dotnet test tests/PoPunkouterSoftware.Unit -c Release --no-build
dotnet test tests/PoPunkouterSoftware.Integration -c Release --no-build

Available VS Code tasks in this workspace include:

  • build
  • test-unit
  • start-api-server
  • deep-clean (removes every bin/ and obj/; dotnet clean leaves obj/ behind)

The app runs locally on HTTP port 8000. In Development, requests from this computer to localhost or a loopback IP can browse the fleet pages and their APIs without Microsoft sign-in, and start local training using the same-origin management control. Cloud training, other management actions, Azure and Users still require a Microsoft session. This bypass is not available in Testing, Staging, Production, through a proxy, or to remote clients. Local training opens a PowerShell window and writes its queue log and summary under scripts/global/.local/runs/. The training queue page shows a live grid and progress dialog for queue runs started after the monitor was added and Google Cloud training VMs. It refreshes every 15 seconds; Google Cloud logs can lag by five minutes. Independent local trainers are not discovered, and a running long-lived cloud runner VM does not by itself prove a job is running.

The local R1 stand UNITE pipeline (scripts/global/unite_pipeline.py, jobs in scripts/global/unite_pipelines.json) trains with this repo's docs/unite/tools/unite_train.py --backend warp in an isolated Python environment under scripts/global/.local/envs/robottrain. Set it up from the repo root:

uv venv scripts\global\.local\envs\robottrain --python 3.12
uv pip install --system-certs --python scripts\global\.local\envs\robottrain\Scripts\python.exe mujoco==4.1.0 mujoco-warp==4.1.0 warp-lang==1.19.0 numpy==2.5.5 torch==2.14.1+cu130 onnx==1.23.2 onnxruntime==1.32.0 --extra-index-url https://download.pytorch.org/whl/cu130 --index-strategy unsafe-best-match
python scripts\global\build_global_data.py --only queue

Reload the queue page after refreshing. Other trainers keep their existing environments; their dependency versions are not necessarily compatible with this one.

Runtime Notes

  • The portfolio (/) and friendly /diag remain public. /azure, /users, their report/summary/sign-in APIs, Azure mutation APIs, and /hubs/refresh require Microsoft sign-in. The GLOBAL/RL pages moved into this app on 2026-11-27 and sit behind the same boundary (/global and /api/global/*). See docs/global-migration.md.

  • /global/brains shows the UNITE brain store and gallery (/global/unite/gallery); Step 5 (/global/results?run=, the old /global/unite/live URL lands there) runs the brain picked on Step 4 on its body in the browser (MuJoCo WASM 4.1.0, the UNITE v3 pin, + onnxruntime-web in a worker, three.js on the page) and checks it against the trainer's own trajectory before it plays. Brains stream from the private store through /api/global/unite/brains/{sha}/onnx|sidecar with the site identity (Storage Blob Data Reader on stpobrains); they are never committed here. scripts/unite-live/parity.mjs runs the same check headless for every brain. A "Test conditions" panel puts the body in any of the 10 envelope eval corners (or a custom mix of friction, payload, motor strength, latency, slope, pushes, rough ground, sensor noise), applied as unite_eval.py does. Each brain in the gallery shows its certified 10-corner eval as a pass/fail strip.

  • Sign-in is optional and owner-only: only the account in MicrosoftAuth:OwnerEmail can complete it, and only then does the header show Azure, Users and Fleet. Set it up once with pwsh ./scripts/setup-microsoft-signin.ps1 -OwnerEmail <owner address>.

  • Microsoft OIDC uses a server-owned HttpOnly session cookie; access tokens are not sent to the Blazor client. The header provides Microsoft sign-in and antiforgery-protected sign-out. Missing Microsoft configuration leaves private routes inaccessible and sign-in reports 503.

  • /health is the deep probe (Key Vault, Table Storage); /health/live is a static liveness ping carrying X-Commit.

  • GET /api/diag returns the System status report (DiagReportDto: status, environment, version, checks grouped api / data / service), the only source of the /diag page — statuses, latencies and fixed text, safe for anonymous Production visitors (no config block, URIs, paths or ids). /api/diag/* (summary, report, refresh, cancel-refresh, restart/{name}, ai) are the dashboard's own endpoints. POST /api/diag/ai validates its body with the shared FluentValidation AiTriageAdHocRequestValidator (400 validation problem on a bad list). restart/{name} restarts (or starts) one scanned App Service and sits behind the same management gate as refresh; in Azure it also needs Website Contributor, which infra does not grant.

  • Each scan also reads Azure Resource Health (for down apps), Azure Advisor, 24h exception types per app from the shared Application Insights component (SignIns:ResourceId), and open Dependabot alerts per matched repo (needs Dependabot enabled on the repo and a PAT with "Dependabot alerts: read").

  • Four keyless public APIs feed the scan through the public-api HttpClient: each matched repo's Directory.Packages.props (read with the GitHub PAT) is checked against nuget.org for newer versions and OSV.dev for known advisories; the Azure Retail Prices API prices B1/S1/P0v3 in each app's region; RDAP reads the registration expiry of any custom domain. Each catalog entry in apps.json may set expect, text the live page must contain; a page that answers 2xx without it is flagged. Each entry may also carry a stack block of short labels (frontend, backend, realtime, data, extras = the app's unique tech, ai, signIn, delivery) plus a details map of the same keys holding the full wording, and an aiServices list (cloud, name, use, optional) for the AI column. An entry may also set androidPackage; each scan checks anonymously whether its Google Play page and its githubRepo are public, and the home page links each only once it is — the home page's matrix of how each app is built.

  • Push alerts go through ntfy (Alerts:NtfyTopic): app down/up, failed scan, spend spike, an SSL certificate crossing 14 days, the month-end forecast crossing the budget, a page losing its expect text, a custom domain crossing 30 days to expiry.

  • deploy.yml is the only workflow (no infra job, no rollback, no pull-request runs). E2E tiers run locally; scripts/post-deploy-smoke.ps1 -BaseUrl <url> is a manual check.

  • Dropped on 2026-11-20 (owner's choice, instead of upgrading the F1 plan): the scheduled workflows ci-watch.yml, conventions.yml, uptime-scan.yml, weekly-digest.yml and screenshots.yml. There is no nightly scan (a scan runs when a visitor loads a report older than 12h, so a day nobody visits has no uptime data), no Monday digest, no estate CI watcher, and no new card screenshots: cards keep the last captured picture and the home page says so. The PageSpeed score chips went with the capture.

  • Shell: this repo's own po-tokens.css look (indigo accent, light/dark from the device, Inter and Space Grotesk), a header with the app name upper-left and Microsoft session controls upper-right (the settings gear stays removed), one vYYMMDD stamp lower-right (UTC date of HEAD), and /diag status cards.

  • Azure behavior prefers Key Vault and managed identity when available, with local fallback configuration for development.

  • The client dashboard consumes the shared Azure report models generated by the server and infrastructure layers.

  • Every page shows the build date (YYMMDD) in the lower-right corner, from the client assembly's BuildVersion metadata; it links to /diag.

  • Theme, density, sound and details are fixed for everyone (since 2026-11-17): the theme follows the device, the layout is compact, there is no sound, and every detail shows. There is no settings page (deleted 2026-11-28) and no decorative animation layer.

  • /global is the fleet view that used to be the standalone global/ folder: fleet health, the morning briefing, the brain vault, the UNITE brain store with the R1 skills backlog, showroom, ship board, lessons, disk, the RL dashboard, UNITE and the incubator. Its data is a committed snapshot (src/PoPunkouterSoftware.Api/App_Data/global, written by scripts/global/build_global_data.py) read by /api/global/*; nothing under App_Data is ever served statically.

Configuration

appsettings.json holds values only; what each section means lives here. Secrets come from Key Vault kv-poshared2 under the prefix PoPunkouterSoftware-- and are never committed.

Key What it does
UniteBrains:BlobServiceUri Blob endpoint of the UNITE brain store the live player reads (default https://stpobrains.blob.core.windows.net, container brains), with the shared DefaultAzureCredential.
AzureBlobStorage:Endpoint Public endpoint of the account holding the app-screenshots container (the last captured card pictures; nothing writes them since 2026-11-20), used on the managed-identity path. Without it stored screenshots never serve.
ApplicationInsights:ConnectionString Left blank; supplied by the vault secret ApplicationInsights--ConnectionString or APPLICATIONINSIGHTS_CONNECTION_STRING.
FeatureFlags:EnableManagementActions Enables Azure controls for authenticated users. Mutations also require the same-origin X-Management-Request: 1 header, sent by the client. /api/config reports whether this browser can use the controls.
FeatureFlags:EnableAutoInventoryRefresh A portfolio load with a report older than 12h starts a background rescan (30-min cooldown). Defaults on outside Development/Testing.
FeatureFlags:EnableAiSummary The AI status paragraph on /azure; false falls back to the rule-based narrative.
StatusNarrator:* Azure AI Foundry chat completions on po-aiservices-shared2 (gpt-5.4-nano). Deliberately NOT named AzureAi: the vault's estate-wide AzureAI--* secrets would be picked up case-insensitively and 401 every call. Blank ApiKey means Entra ID (needs Cognitive Services OpenAI User), falling back to the vault's AzureOpenAI--ApiKey.
SignIns:* The /users roster, read live from the shared Application Insights component's traces (UserSignedIn). Needs Monitoring Reader; anything missing degrades to "unavailable", never a 500. WindowDays is capped at 90 (the component's retention).
Budget:MonthlyUsd Monthly ceiling for the /azure forecast. 0 or absent shows the projection with no comparison.
Alerts:* ntfy push alerts. Off while NtfyTopic is blank; on ntfy.sh the topic IS the credential, so set it only through the vault secret PoPunkouterSoftware--Alerts--NtfyTopic. SiteUrl is where a tapped alert opens.
RateLimits:* Global (not per-IP) ceilings on /api/signins and POST /api/diag/ai, the two anonymous endpoints that cost money per call.
Retention:HistoryDays Days before history rows are pruned (0 disables). Blob lifecycle is in infra/main.bicep.
Pinger:* Background sweep that warms cold starts and records daily reachability for the uptime grid. Off means the grid uses scan observations alone.
MicrosoftAuth:ClientId This app's Microsoft Entra application ID. Use an app registration supporting the Microsoft account types you want to admit.
MicrosoftAuth:ClientSecret Server-only credential from PoPunkouterSoftware--MicrosoftAuth--ClientSecret in Key Vault (never put it in client assets or source control).
MicrosoftAuth:TenantId Defaults to common for work/school and personal Microsoft accounts. A tenant GUID restricts sign-in to that tenant. All admitted authenticated users can access Azure and Users; there is no separate administrator role.

Microsoft sign-in setup

Register Web redirect URIs http://localhost:8000/signin-oidc and https://app-popunkoutersoftware2.azurewebsites.net/signin-oidc on this app's Entra registration. Set MicrosoftAuth:ClientId, MicrosoftAuth:ClientSecret, and optionally MicrosoftAuth:TenantId through app-prefixed Key Vault secrets or server environment variables. No browser-side secret or Graph permission is required: only openid, profile, and email scopes are requested. The former management API-key gate has been replaced by authenticated sessions. Local tests may explicitly send X-Fake-User; those headers never authenticate Production or Staging.

Testing Strategy

  • Unit tests (PoPunkouterSoftware.Unit) cover pure logic and API helpers, no I/O.
  • Integration tests (PoPunkouterSoftware.Integration) cover host configuration, diagnostics endpoints, and Table Storage guardrails via WebApplicationFactory.
  • E2E tests (PoPunkouterSoftware.E2EAPI, PoPunkouterSoftware.E2EUI) cover the HTTP contract and browser flows against a live instance; on demand, not in CI, and they skip with a clear message when no app answers at BASE_URL. E2EUI runs axe-core's WCAG 2.1 A/AA rules over every page (Deque.AxeCore.Playwright) and fails on serious or critical violations.
  • Current caps (Python ≤100, Unit ≤100, Integration ≤50, E2E API ≤25, E2E UI ≤25) are enforced in CI by scripts/check-conventions.ps1 (see docs/testing.md).

Developer Guidance

  • Read AGENTS.md before changing anything; docs/architecture.md is the context map.
  • Keep /api/diag/* available but do not link them from the UI — diagnostics surface only in the /azure Advanced diagnostics drawer.
  • Preserve Po-prefixed naming and strict build quality defaults from Directory.Build.props.