# home.dliu.com: health and guest checks

Full technical version of https://home.dliu.com/docs#health, for machines and AI agents. It follows the dliu.com health
contract used by https://status.dliu.com and is enough on its own to implement the tests.

The public S3 site serves the Microsoft sign-in landing page, Docs and static assets through CloudFront.
The dashboard and legacy task HTML are packaged only with the authenticated Lambda; every application read/write
requires a server-verified Microsoft session. There is no live device connection. The legacy records are retained;
`/health` is a public, read-only check of that database, NOT home-server, camera or lighting health.

This contract describes the replacement source version. It is not evidence that these changes have been deployed.

## Functions

| Key | Name | What it does | Critical |
| --- | --- | --- | --- |
| `pages` | Pages | Serves the sign-in landing page, public Docs, stylesheet and testing contract. | yes |
| `auth` | Microsoft sign-in boundary | Private pages redirect guests and application APIs refuse anonymous requests. | yes |
| `records` | Legacy database health | Public health reads one fixed database key without returning task records; unrelated to devices. | no |
| `routing` | Clean URLs and 404 | Serves `/docs`, redirects old health links to Testing, and returns 404 for missing pages. | no |
| `https` | HTTPS | Redirects plain HTTP to HTTPS. | no |

The site is "down" when a critical function fails.

## Guest checks

Send each request with no cookies, no `Authorization` header and no query string, and do not follow redirects. A check
passes when the status code matches, the `Content-Type` starts with the expected type (`-` means not checked), and the
body contains the marker (or, for a redirect, the `Location` header starts with it). A check that passes but takes
longer than the slow threshold counts as slow.

| Function | Method | URL | Status | Content type | Body marker or `Location` prefix | Slow after (ms) |
| --- | --- | --- | --- | --- | --- | --- |
| `pages` | GET | `https://home.dliu.com/` | 200 | `text/html` | `id="signin-heading"` | 2000 |
| `pages` | GET | `https://home.dliu.com/docs` | 200 | `text/html` | `dl-docs-main` | 2000 |
| `pages` | GET | `https://home.dliu.com/styles.css` | 200 | `text/css` | `.dashboard-columns` | 2000 |
| `pages` | GET | `https://home.dliu.com/docs/health.md` | 200 | `text/markdown` | `## Guest checks` | 2000 |
| `auth` | GET | `https://home.dliu.com/app` | 303 | - | `/auth/login?returnTo=` | 3000 |
| `auth` | GET | `https://home.dliu.com/api/timestamps` | 401 | `application/json` | `Microsoft sign-in is required.` | 3000 |
| `records` | GET | `https://home.dliu.com/health` | 200 | `application/health+json` | `"key":"records"` | 3000 |
| `routing` | GET | `https://home.dliu.com/docs/health` | 301 | - | `/docs#health` | 2000 |
| `routing` | GET | `https://home.dliu.com/status-check-missing-page` | 404 | `text/html` | `Page not found` | 2000 |
| `https` | HEAD | `http://home.dliu.com/` | 301 | - | `https://home.dliu.com/` | 2000 |

`GET /api/timestamps` without a session must return `401`, not task history. Only an authenticated user can read
the latest ten records or write a record. Guest checks never complete login and never use an owner's cookie.

## Health endpoint

`GET https://home.dliu.com/health` (also `HEAD`).

- **Format:** `Content-Type: application/health+json`; HTTP `200` when `status` is `pass` or `warn`, `503` when it is
  `fail`. Body: `{"status":"pass","time":"2026-11-03T23:00:00Z","functions":[{"key":"records","name":"Task records","status":"pass"}]}`.
  A function's `output` (only when not `pass`) is `slow`, `timeout` or `read failed`. The top-level `status` is the
  worst of the functions'.
- **Functions reported:**

| Key | Name | What the check reads | Pass / warn / fail |
| --- | --- | --- | --- |
| `records` | Task records | One DynamoDB `GetItem` of a fixed key in the task table (a 2 s timeout, no retries). | `pass` under 1 s, `warn` (`slow`) over 1 s, `fail` (`timeout` or `read failed`) on error |

- **Caching:** CloudFront caches the response for 60 s, keyed on nothing (`Cache-Control: public, max-age=60`), so the
  check runs at most about once a minute per edge location. A fresh result can take up to 60 s to appear.
- **No authentication and read only:** the `/health` behaviour forwards no cookies, no `Authorization` header and no
  query string, and the handler reads nothing from the request. It never writes and reveals no table names, counts or
  records. `pages`, `routing` and `https` have no backend to read, so only the guest checks test them.

## Caching

Public HTML has no `Cache-Control` header (CloudFront caches it for up to 1 day). `styles.css`, `app.js`, `session.js` and this file are
sent with `Cache-Control: public, max-age=300, s-maxage=86400, stale-while-revalidate=86400`. `/api/*` is never cached.
`/app`, `/app/*` and `/auth/*` are also uncached; private HTML sends `private, no-store` and authentication/API responses
send `no-store`. Error caching has zero TTL. Every deploy invalidates `/*`. CloudFront cookie logging is disabled:
authentication cookies must never be written to visitor/access logs.

## Not tested

- Recording a task (`POST /api/timestamps`) and deleting a record (`DELETE /api/timestamps`): they change the household's
  records, so guest checks must never send them.
- The one-hour rules for recording and deleting, which only a write would exercise.
- Deploys and cache invalidation, which run from the owner's machine.
- The `dl_vid` visitor cookie and the CloudFront access logs used by traffic.dliu.com.
- Camera streams, recording/playback, bulbs, automation, Google Assistant and home-server availability: public checks
  have no device credentials and never operate hardware. All delivered-device acceptance checks below are pending.
- A real Microsoft login/callback, assigned-user policy and session expiry in the deployed service. Local tests mock
  Microsoft and AWS; do not describe them as live-account validation.

## Interface regression checks

- The previous dashboard used invented online totals and a mock device-control presentation. Keep ordered inventory
  separate from measured device state: six replacement cameras, fourteen bulbs (six B22/eight E27), one ordered
  server, and four existing GC4 cameras with only one representative under test.
- With no device backend, the signed-in dashboard must expose no private stream URL and keep the light-control
  button disabled. Its session/sign-out script is not a device controller. Never represent a local UI toggle as a
  successful physical command.
- The previous stylesheet nested the tablet breakpoint inside the phone breakpoint. At viewport widths 390, 768
  and 1280 CSS pixels, check no horizontal page overflow, no overlapping cards, working navigation and readable
  camera/light sections. The two-column dashboard must collapse on tablet and phone, not only narrow phones.
- In the repository, run `cd cdk && npm test -- --runInBand` and `npx tsc --noEmit`. The shared-UI suite covers
  consistent navigation, disabled controls and internal dashboard/docs links; the routing suite checks that the
  old `/docs/health` link redirects to `/docs#health` while `/docs/health.md` remains a Markdown file.

## Authentication regression checks

- Guests may read Docs without a session or API call. The dashboard/private task HTML must not be present in the
  public static asset directory. Private-page GET/HEAD redirects to sign-in; API GET/POST/DELETE refuses guests.
- Forged, expired and wrong-purpose cookies cannot authorize any action. In particular, a publicly issued login
  cookie cannot be substituted for a session, even when its `typ` is changed.
- The Microsoft callback validates state, PKCE verifier, nonce, RS256 signature, issuer, tenant, audience and expiry.
  Tokens from another tenant/app or a disallowed account cannot create a session. Return paths stay inside `/app`.
- Missing/failed SSM reads produce an explicit unavailable response, never anonymous access or stale indefinite
  credentials. The Lambda reads only `/home/entra-client-id`, `/home/entra-client-secret` and the shared tenant.
- Even with a valid session, writes and sign-out reject an absent or foreign Origin; JSON writes reject other
  content types. Browser requests carry the exact body SHA-256 required by the CloudFront OAC origin.
- Private page/API/auth behaviors have caching disabled, Lambda URLs use AWS_IAM, and raw cookie logging stays off.
  Local tests cover these boundaries without reading real credentials or modifying cloud settings.
- A production deployment exposed a missing-origin-permission regression: Lambda URL requests require both
  `lambda:InvokeFunctionUrl` and `lambda:InvokeFunction`. Without the latter, CloudFront received a forbidden
  origin response and the site's error mapping displayed 404 for `/app`, `/api/*`, `/auth/*` and `/health`.
  The infrastructure regression checks require both handlers to grant the additional permission only to this
  distribution, with `InvokedViaFunctionUrl: true`. Never work around this by making the Lambda URLs public.

## Owner-run hardware acceptance

These are NOT anonymous guest checks. They require the owner and local access. All are pending.

| Area | Acceptance evidence |
| --- | --- |
| One existing GC4 representative | Record exact model/firmware, any reachable services and a reproducible independent stream if found. Timeouts or an incomplete TCP sweep are inconclusive, not proof every port is closed. No comparison across the whole four-pack is required. |
| Each replacement camera model/revision | Verify local credentials and streams, audio where supported, day/night, 24-hour recording and saved playback. With device internet blocked but LAN preserved, verify reconnect and cold-restart recovery; check IPv6 does not bypass the block. |
| Each exact bulb model | Pair via Zigbee or WiZ; test on/off and supported optional features without vendor internet, including power-cycle recovery. |
| Automation | Verify motion/person event delivery, response time, inactivity delays, manual override and lighting-change retriggers. No detection does not prove a still occupant is absent. |
| Server | SSD health, hardware acceleration, measured retention, concurrent recording/playback/selective AI and restart recovery; local automation must survive Google/backup outages. |

## Rules

- Only `GET` and `HEAD`, as an anonymous guest. The tests are read only and must never change content: never `POST` or
  `DELETE` to `/api/timestamps`.
- Use the user agent `dliu-status-bot/1.0 (+https://status.dliu.com/docs)`, so traffic.dliu.com leaves the requests out.
- Keep this file, https://home.dliu.com/docs#health and the retained technical reference `docs-health.html` in sync.
  The repo's `cdk/test/health.test.ts` checks the machine contract against the technical reference.
