Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ff3a996482 | |||
| a5480d2877 | |||
| beea8eaa10 | |||
| 8c84cbbb52 |
@@ -8,6 +8,7 @@ One row per feature, with its analysis document (CLAUDE.md §5.1). Gaps live in
|
|||||||
| Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) |
|
| Workspace, contracts, gates, PWA shell | 0 | Merged to `main` 2026-11-01 (`d11d242`); built, not deployed. Phase 0 gate still open | [phase0-workspace.md](features/phase0-workspace.md) | [feature-phase0-workspace.md](reviews/feature-phase0-workspace.md) |
|
||||||
| Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) |
|
| Roadmap and gameplay docs, read against the code | 0 | Merged 2026-11-01; Q1–Q7 answered by the author | — | [docs-roadmap-gameplay.md](reviews/docs-roadmap-gameplay.md) |
|
||||||
| The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) |
|
| The Letter slot: page at `#letter`, empty `docs/LETTER.md` | 0 | Merged to `main`; built, not deployed. Invisible until the author writes | [letter-slot.md](features/letter-slot.md) | [feature-letter-slot.md](reviews/feature-letter-slot.md) |
|
||||||
|
| A calm refresh: a waiting new version is offered in one line, never swapped in by itself | 0 | Merged to `main`; built, not deployed | [calm-refresh.md](features/calm-refresh.md) | [feature-calm-refresh.md](reviews/feature-calm-refresh.md) |
|
||||||
| The CPU guard: full runs wait for, then refuse, a busy machine | 0 | Merged to `main` | — | [fix-cpu-guard.md](reviews/fix-cpu-guard.md) |
|
| The CPU guard: full runs wait for, then refuse, a busy machine | 0 | Merged to `main` | — | [fix-cpu-guard.md](reviews/fix-cpu-guard.md) |
|
||||||
| Keep her safe: the browser's promise, save her to a file, bring her back | 0–1 | Merged to `main`; built, not deployed | [keep-her-safe.md](features/keep-her-safe.md) | [feature-keep-her-safe.md](reviews/feature-keep-her-safe.md) |
|
| Keep her safe: the browser's promise, save her to a file, bring her back | 0–1 | Merged to `main`; built, not deployed | [keep-her-safe.md](features/keep-her-safe.md) | [feature-keep-her-safe.md](reviews/feature-keep-her-safe.md) |
|
||||||
| The rose: care by feel, growth from days of care, drift, moods, her numbers; the care log and the identity | 1 | Merged to `main`; built, not deployed. Tuning is the author's | [rose.md](features/rose.md) | [feature-rose-care.md](reviews/feature-rose-care.md) |
|
| The rose: care by feel, growth from days of care, drift, moods, her numbers; the care log and the identity | 1 | Merged to `main`; built, not deployed. Tuning is the author's | [rose.md](features/rose.md) | [feature-rose-care.md](reviews/feature-rose-care.md) |
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ board exist, and the first real picture is the author's to make.
|
|||||||
| ~~G0.7~~ | ~~No commit guards~~ | Closed 2026-11-01. `pre-commit` blocked a 5.7 MB probe; `commit-msg` blocked a `Co-Authored-By: Claude` trailer; both passed clean input. |
|
| ~~G0.7~~ | ~~No commit guards~~ | Closed 2026-11-01. `pre-commit` blocked a 5.7 MB probe; `commit-msg` blocked a `Co-Authored-By: Claude` trailer; both passed clean input. |
|
||||||
| ~~G0.8~~ | ~~Never tested under the Pages sub-path~~ | Closed for the local build 2026-11-01. `shell.spec.ts` serves `dist/` at `/Rosea/` and asserts manifest scope = start_url = SW scope. Mutation: scope `/` fails it. **On real GitHub Pages: still predicted** (G0.13). |
|
| ~~G0.8~~ | ~~Never tested under the Pages sub-path~~ | Closed for the local build 2026-11-01. `shell.spec.ts` serves `dist/` at `/Rosea/` and asserts manifest scope = start_url = SW scope. Mutation: scope `/` fails it. **On real GitHub Pages: still predicted** (G0.13). |
|
||||||
| ~~G0.9~~ | ~~No proof the app opens offline~~ | Closed for the shell 2026-11-01. `offline.spec.ts` closes the server, then reload, cold start and a deep link all render. Mutations: `clientsClaim: false` and no `navigateFallback` both fail it. |
|
| ~~G0.9~~ | ~~No proof the app opens offline~~ | Closed for the shell 2026-11-01. `offline.spec.ts` closes the server, then reload, cold start and a deep link all render. Mutations: `clientsClaim: false` and no `navigateFallback` both fail it. |
|
||||||
| G0.10 | No calm *refresh* control for a waiting service worker (CLAUDE.md §8, stale SW) | Open. `registerType: 'prompt'` and `skipWaiting: false` are set, so a new worker waits. Nothing tells the player yet. |
|
| ~~G0.10~~ | ~~No calm *refresh* control for a waiting service worker (CLAUDE.md §8, stale SW)~~ | Closed 2026-11-02 on `feature/calm-refresh`: the app registers the worker and shows *A new version of the garden is ready.* with *Refresh*. e2e publishes a real second version: offered, not swapped, then taken over on Refresh; 3 of 3 put-back bugs caught. |
|
||||||
| ~~G0.11~~ | ~~IndexedDB eviction: no `navigator.storage.persist()`, no export-my-rose (§8)~~ | Closed 2026-11-02 on `feature/keep-her-safe`: *Keep her safe* asks the browser (and an installed app asks by itself), saves her to a file without the town or the private key, and brings her back additively on any device. e2e: saved on one browser profile, restored on a fresh one, survives a reload. Not seen in Firefox or Safari. |
|
| ~~G0.11~~ | ~~IndexedDB eviction: no `navigator.storage.persist()`, no export-my-rose (§8)~~ | Closed 2026-11-02 on `feature/keep-her-safe`: *Keep her safe* asks the browser (and an installed app asks by itself), saves her to a file without the town or the private key, and brings her back additively on any device. e2e: saved on one browser profile, restored on a fresh one, survives a reload. Not seen in Firefox or Safari. |
|
||||||
| G0.12 | The app cannot validate content in the browser | Open. Ajv compiles with `new Function`, which the CSP forbids. Needs standalone pre-compiled validators before the app reads the library. |
|
| G0.12 | The app cannot validate content in the browser | Open. Ajv compiles with `new Function`, which the CSP forbids. Needs standalone pre-compiled validators before the app reads the library. |
|
||||||
| G0.13 | No GitHub remote, no Pages deploy workflow, no mirror check (§5.2) | Open. Only the Gitea remote exists. |
|
| G0.13 | No GitHub remote, no Pages deploy workflow, no mirror check (§5.2) | Open. Only the Gitea remote exists. |
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
# A calm refresh — when a new version of the garden is waiting
|
||||||
|
|
||||||
|
Status: built on `feature/calm-refresh`. Gap G0.10; CLAUDE.md §8, *the stale service worker: a
|
||||||
|
precached shell keeps serving old JS to a player who has "updated". Detect a waiting worker and offer
|
||||||
|
an explicit, calm refresh control.* Needed before the Phase 1 gate, where the author plays the
|
||||||
|
installed app daily while fixes are deployed. Review:
|
||||||
|
[`feature-calm-refresh.md`](../reviews/feature-calm-refresh.md).
|
||||||
|
|
||||||
|
## 1. Why and what, in the player's terms
|
||||||
|
|
||||||
|
The garden works offline because a service worker keeps a copy of it. When a new version is
|
||||||
|
published, the browser fetches it in the background and **waits**: the garden the player has open
|
||||||
|
never changes under their hands. When the new one is ready, one quiet line appears at the foot of
|
||||||
|
the page: **"A new version of the garden is ready."** with a **Refresh** button. The player
|
||||||
|
refreshes when they like; nothing is lost either way, since the rose lives in the device's
|
||||||
|
database, not in the code.
|
||||||
|
|
||||||
|
## 2. Technical architecture
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant P as the open garden (version A)
|
||||||
|
participant B as the browser
|
||||||
|
participant S as the server
|
||||||
|
B->>S: sw.js (on a navigation or a check)
|
||||||
|
S-->>B: version B's bytes differ
|
||||||
|
B->>B: install B, precache; B waits (skipWaiting: false)
|
||||||
|
B-->>P: "waiting" (workbox-window, via virtual:pwa-register)
|
||||||
|
P->>P: show "A new version of the garden is ready." + Refresh
|
||||||
|
P->>B: Refresh: SKIP_WAITING to B
|
||||||
|
B-->>P: B controls; the page reloads under B
|
||||||
|
```
|
||||||
|
|
||||||
|
| # | Decision | Why |
|
||||||
|
|:--|:--|:--|
|
||||||
|
| U1 | Register through `virtual:pwa-register` in the app; `injectRegister: false`. | The emitted `registerSW.js` registers but tells the page nothing; the virtual module reports the waiting worker. Bundled, so the CSP needs no inline script. |
|
||||||
|
| U2 | **Never refresh by itself.** The line waits for the player. | CLAUDE.md §1, *gentle*; a reload in the middle of pouring water would lose the pour. |
|
||||||
|
| U3 | The line sits in its own `aside` at the foot, on the garden and the Letter alike. | It is about the whole app, not one page; a landmark keeps it findable. |
|
||||||
|
| U4 | The e2e test serves a **real second version** (version A's build with `sw.js` changed) from the same origin. | A waiting worker exists only between two builds; a mock would test the mock. |
|
||||||
|
|
||||||
|
## 3. Risk analysis
|
||||||
|
|
||||||
|
| Risk | Answer |
|
||||||
|
|:--|:--|
|
||||||
|
| A player keeps old code forever and never sees a fix. | The line appears as soon as a new worker waits; tested end to end. |
|
||||||
|
| A silent swap mid-action loses care. | U2; the test asserts the old worker still controls the page until Refresh. |
|
||||||
|
| Feeling pushed. | One line, no badge, no repeat, no count; nothing happens if it is ignored. |
|
||||||
|
| Privacy | Nothing new leaves the device: update checks were already made by the browser to the same origin. |
|
||||||
|
|
||||||
|
## 4. Gaps
|
||||||
|
|
||||||
|
| Gap | State |
|
||||||
|
|:--|:--|
|
||||||
|
| G0.10 | Built |
|
||||||
|
| What changed in a version (release notes) | Open: not needed for the Phase 1 gate |
|
||||||
|
|
||||||
|
## 5. Verification matrix
|
||||||
|
|
||||||
|
| Case | Kind | Where |
|
||||||
|
|:--|:--|:--|
|
||||||
|
| No line without a waiting version; the line and Refresh when there is one; Refresh calls the app; on the Letter too | unit | `ui/test/Shell.test.ts` |
|
||||||
|
| Built app: version A controls; version B published; the line appears; A still controls; Refresh; B controls and the line is gone; axe | e2e | `e2e/update.spec.ts` |
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Review — `feature/calm-refresh`
|
||||||
|
|
||||||
|
Adversarial self-review (CLAUDE.md §5.3). Analysis: [`features/calm-refresh.md`](../features/calm-refresh.md).
|
||||||
|
Reviewed 2026-11-02 on Node 22.11.0, Windows 10. There is no PR: the only remote is Gitea.
|
||||||
|
|
||||||
|
## Gates
|
||||||
|
|
||||||
|
Counts are on the merge; HANDOVER repeats them. New: ui +3 (the line, Refresh, on the Letter);
|
||||||
|
e2e +1 (`update.spec.ts`: a real second version).
|
||||||
|
|
||||||
|
**The app changed** (CLAUDE.md §5.4): the worker is registered by the app (`virtual:pwa-register`)
|
||||||
|
instead of the emitted `registerSW.js`, and a waiting version shows one line with *Refresh*. Rebuilt by
|
||||||
|
the e2e and offline runs; **not deployed** (G0.13). This is the change that lets every later fix
|
||||||
|
reach an installed garden.
|
||||||
|
|
||||||
|
## Bug drills — each put back once, the app rebuilt each time
|
||||||
|
|
||||||
|
| Put back | Result |
|
||||||
|
|:--|:--|
|
||||||
|
| The app never hears that a version waits | CAUGHT |
|
||||||
|
| The new worker swaps itself in silently (`skipWaiting: true`) | CAUGHT: version B controlled the page before Refresh |
|
||||||
|
| Refresh does nothing | CAUGHT: version A still controlled after Refresh |
|
||||||
|
|
||||||
|
## Findings
|
||||||
|
|
||||||
|
| # | Area | Finding | Resolution |
|
||||||
|
|:--|:--|:--|:--|
|
||||||
|
| 1 | Test honesty | A waiting worker cannot be faked without testing the fake. | The test publishes a real version B (A's build, `sw.js` changed) on the same origin; B's own listener says which worker controls the page, before and after. |
|
||||||
|
| 2 | Correctness | Registration moved from `registerSW.js` to the app bundle. The first worker must still control the first page, or the offline promise breaks. | `clientsClaim: true` unchanged; the offline suite (first load, server closed, reload, cold start) passes on the merge. |
|
||||||
|
| 3 | Correctness | A player who ignores the line keeps version A until every garden tab closes, which is how service workers work. | Accepted and intended (U2). Closing and reopening the app also brings B. |
|
||||||
|
| 4 | Soul | An update line can nag. | One line, no badge, no count, never repeated in a modal; it disappears after Refresh. |
|
||||||
|
| 5 | Privacy | Update checks are requests. | They already happened (the browser checks `sw.js` on navigation), same origin only; nothing new is sent. |
|
||||||
|
| 6 | Correctness | Two tabs: Refresh in one reloads only that one; the other keeps showing the line until it reloads. | Accepted; it is still true there. |
|
||||||
|
|
||||||
|
## What was not verified
|
||||||
|
|
||||||
|
- An installed PWA on a real phone, and Safari's update timing.
|
||||||
|
- The leftover `dist/registerSW.js` from older builds is no longer emitted; GitHub Pages will simply
|
||||||
|
not serve it. No page references it.
|
||||||
@@ -507,7 +507,7 @@ No timestamp finer than a day, no precise location, no free text, no link to the
|
|||||||
| **Copyright through the back door** | An image prompt "in the style of" the book's drawings, a fox or rose that looks like the original, or a famous line "paraphrased" too closely. All forbidden (§5.6); the art pipeline checks likeness (`docs/ART.md`). |
|
| **Copyright through the back door** | An image prompt "in the style of" the book's drawings, a fox or rose that looks like the original, or a famous line "paraphrased" too closely. All forbidden (§5.6); the art pipeline checks likeness (`docs/ART.md`). |
|
||||||
| **Medical claims in a store listing** | One word like *heal* in marketing copy can pull the product toward medical-device rules. `lint:copy` also runs on store text kept in the repo. |
|
| **Medical claims in a store listing** | One word like *heal* in marketing copy can pull the product toward medical-device rules. `lint:copy` also runs on store text kept in the repo. |
|
||||||
| **IndexedDB is evictable** *(predicted; answered by `keep-her-safe.md`)* | WebKit can discard origin storage after seven days without interaction — exactly the shape of a player who drifted away and comes back. Call `navigator.storage.persist()` where it exists, prompt iOS players to install, and make export-my-rose a first-class feature. A player returning to find their rose gone is the cruellest bug this product could have. |
|
| **IndexedDB is evictable** *(predicted; answered by `keep-her-safe.md`)* | WebKit can discard origin storage after seven days without interaction — exactly the shape of a player who drifted away and comes back. Call `navigator.storage.persist()` where it exists, prompt iOS players to install, and make export-my-rose a first-class feature. A player returning to find their rose gone is the cruellest bug this product could have. |
|
||||||
| **The stale service worker** | A precached shell keeps serving old JS to a player who has "updated". Detect a waiting worker and offer an explicit, calm *refresh* control. |
|
| **The stale service worker** *(answered by `calm-refresh.md`)* | A precached shell keeps serving old JS to a player who has "updated". Detect a waiting worker and offer an explicit, calm *refresh* control. |
|
||||||
| **Two tabs, one database** *(predicted)* | Two event streams into one store; derived state drifts. Use a `BroadcastChannel` lock. |
|
| **Two tabs, one database** *(predicted)* | Two event streams into one store; derived state drifts. Use a `BroadcastChannel` lock. |
|
||||||
| **GitHub Pages serves under a sub-path** *(predicted)* | A project site lives at `/<repo>/`, not `/`. Vite `base`, the web manifest `start_url` and `scope`, and the service worker scope must all agree, or the installed app opens a 404 or never updates. The offline suite runs against the same base path. |
|
| **GitHub Pages serves under a sub-path** *(predicted)* | A project site lives at `/<repo>/`, not `/`. Vite `base`, the web manifest `start_url` and `scope`, and the service worker scope must all agree, or the installed app opens a 404 or never updates. The offline suite runs against the same base path. |
|
||||||
| **GitHub Pages cannot set response headers** *(predicted)* | No custom CSP or cache headers. The content-security policy goes in a `<meta>` tag; caching is controlled by the service worker and hashed filenames. |
|
| **GitHub Pages cannot set response headers** *(predicted)* | No custom CSP or cache headers. The content-security policy goes in a `<meta>` tag; caching is controlled by the service worker and hashed filenames. |
|
||||||
|
|||||||
+7
-2
@@ -12,8 +12,8 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
|
|||||||
Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md).
|
Gitea hashes match. Analysis: [`.agents/features/phase0-workspace.md`](.agents/features/phase0-workspace.md).
|
||||||
Review, with counts and the mutation results:
|
Review, with counts and the mutation results:
|
||||||
[`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md).
|
[`.agents/reviews/feature-phase0-workspace.md`](.agents/reviews/feature-phase0-workspace.md).
|
||||||
- **Gates:** all pass on this machine. Unit tests: 386 (cpu-guard 13, identity 5, schema 16,
|
- **Gates:** all pass on this machine. Unit tests: 389 (cpu-guard 13, identity 5, schema 16,
|
||||||
content 71, storage 51, art-prep 56, engine 136, ui 38). E2E: 13. Offline: 1. `lint:copy`: 19 files, 0 problems.
|
content 71, storage 51, art-prep 56, engine 136, ui 41). E2E: 14. Offline: 1. `lint:copy`: 19 files, 0 problems.
|
||||||
`validate:library`: 13 of 13 fixtures rejected.
|
`validate:library`: 13 of 13 fixtures rejected.
|
||||||
- **Built, not deployed:** there is no host yet.
|
- **Built, not deployed:** there is no host yet.
|
||||||
- **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on
|
- **Roadmap and gameplay docs:** `docs/ROADMAP.md` and `docs/GAMEPLAY.md` are on
|
||||||
@@ -66,6 +66,11 @@ Rewritten at the end of each session (CLAUDE.md §5.1).
|
|||||||
[`.agents/features/keep-her-safe.md`](.agents/features/keep-her-safe.md). Review:
|
[`.agents/features/keep-her-safe.md`](.agents/features/keep-her-safe.md). Review:
|
||||||
[`.agents/reviews/feature-keep-her-safe.md`](.agents/reviews/feature-keep-her-safe.md).
|
[`.agents/reviews/feature-keep-her-safe.md`](.agents/reviews/feature-keep-her-safe.md).
|
||||||
|
|
||||||
|
- **A calm refresh (G0.10):** merged to `main`. When a new version of the garden is published, the
|
||||||
|
installed app fetches it and waits; one quiet line, *A new version of the garden is ready.*, offers
|
||||||
|
*Refresh*. Nothing reloads by itself. With this, fixes can reach a phone once the app is hosted.
|
||||||
|
Review: [`.agents/reviews/feature-calm-refresh.md`](.agents/reviews/feature-calm-refresh.md).
|
||||||
|
|
||||||
**Phase 0 is not finished.** The roadmap's Phase 0 is more than the workspace. Its
|
**Phase 0 is not finished.** The roadmap's Phase 0 is more than the workspace. Its
|
||||||
gate needs 60 verified sentences (G0.18) and one illustration through the art
|
gate needs 60 verified sentences (G0.18) and one illustration through the art
|
||||||
pipeline (G0.24). The pipeline and the board are built; the first real picture is not made yet. Also open: a GitHub remote (G0.13). The Letter slot is built (G0.25).
|
pipeline (G0.24). The pipeline and the board are built; the first real picture is not made yet. Also open: a GitHub remote (G0.13). The Letter slot is built (G0.25).
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
"svelte-check": "4.7.6",
|
"svelte-check": "4.7.6",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "6.4.3",
|
"vite": "6.4.3",
|
||||||
"vite-plugin-pwa": "1.3.0"
|
"vite-plugin-pwa": "1.3.0",
|
||||||
|
"workbox-window": "7.4.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import { createIdentity } from '@rosea/identity';
|
import { createIdentity } from '@rosea/identity';
|
||||||
import { openStorage } from '@rosea/storage';
|
import { openStorage } from '@rosea/storage';
|
||||||
import { Shell, type RoseWiring, type SunsetWiring } from '@rosea/ui';
|
import { Shell, type RoseWiring, type SunsetWiring } from '@rosea/ui';
|
||||||
|
import { registerSW } from 'virtual:pwa-register';
|
||||||
import { version } from '../package.json';
|
import { version } from '../package.json';
|
||||||
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
|
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
|
||||||
import letter from '../../../docs/LETTER.md?raw';
|
import letter from '../../../docs/LETTER.md?raw';
|
||||||
@@ -75,6 +76,15 @@
|
|||||||
setTimeout(() => URL.revokeObjectURL(url), 10_000);
|
setTimeout(() => URL.revokeObjectURL(url), 10_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- A new version waiting (calm-refresh.md) ----------------------------
|
||||||
|
// The worker is registered here so the page hears when a new version has installed
|
||||||
|
// and waits. It is offered, never swapped in by itself (U2).
|
||||||
|
let updateReady = $state(false);
|
||||||
|
const updateSW = registerSW({
|
||||||
|
onNeedRefresh: () => (updateReady = true),
|
||||||
|
onRegisterError: (error: unknown) => console.error('update: the service worker could not be registered', error)
|
||||||
|
});
|
||||||
|
|
||||||
const rose: RoseWiring = {
|
const rose: RoseWiring = {
|
||||||
identity: () => (identity ??= findIdentity()),
|
identity: () => (identity ??= findIdentity()),
|
||||||
loadCare: () => storage.loadCare(),
|
loadCare: () => storage.loadCare(),
|
||||||
@@ -94,4 +104,4 @@
|
|||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Shell {letter} {sunset} {rose} />
|
<Shell {letter} {sunset} {rose} {updateReady} onrefresh={() => void updateSW(true)} />
|
||||||
|
|||||||
Vendored
+1
@@ -1,2 +1,3 @@
|
|||||||
/// <reference types="svelte" />
|
/// <reference types="svelte" />
|
||||||
/// <reference types="vite/client" />
|
/// <reference types="vite/client" />
|
||||||
|
/// <reference types="vite-plugin-pwa/client" />
|
||||||
|
|||||||
@@ -66,9 +66,10 @@ export default defineConfig({
|
|||||||
// Never swap a running app silently. A new worker waits until the player
|
// Never swap a running app silently. A new worker waits until the player
|
||||||
// is offered a calm refresh control (CLAUDE.md §8, GAP_ANALYSIS G0.10).
|
// is offered a calm refresh control (CLAUDE.md §8, GAP_ANALYSIS G0.10).
|
||||||
registerType: 'prompt',
|
registerType: 'prompt',
|
||||||
// An emitted registerSW.js file, not an inline snippet: the CSP has no
|
// The app registers the worker itself through virtual:pwa-register, so it hears
|
||||||
// 'unsafe-inline' for scripts.
|
// when a new version is waiting (calm-refresh.md U1). Bundled, not inline: the
|
||||||
injectRegister: 'script',
|
// CSP has no 'unsafe-inline' for scripts.
|
||||||
|
injectRegister: false,
|
||||||
manifest: {
|
manifest: {
|
||||||
// The web manifest: one of the three places the name lives, built from
|
// The web manifest: one of the three places the name lives, built from
|
||||||
// the constants in @rosea/schema so the strings exist only there.
|
// the constants in @rosea/schema so the strings exist only there.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { defineConfig, devices } from '@playwright/test';
|
|||||||
*/
|
*/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
testDir: '.',
|
testDir: '.',
|
||||||
testMatch: /shell\.spec\.ts/,
|
testMatch: /(shell|update)\.spec\.ts/,
|
||||||
fullyParallel: false,
|
fullyParallel: false,
|
||||||
workers: 1,
|
workers: 1,
|
||||||
retries: 0,
|
retries: 0,
|
||||||
|
|||||||
+10
-4
@@ -19,7 +19,7 @@ import { fileURLToPath } from 'node:url';
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const BASE = process.env['ROSEA_BASE'] ?? '/Rosea/';
|
export const BASE = process.env['ROSEA_BASE'] ?? '/Rosea/';
|
||||||
const DIST = fileURLToPath(new URL('../apps/rosea/dist', import.meta.url));
|
export const DIST = fileURLToPath(new URL('../apps/rosea/dist', import.meta.url));
|
||||||
|
|
||||||
const MIME: Record<string, string> = {
|
const MIME: Record<string, string> = {
|
||||||
'.html': 'text/html; charset=utf-8',
|
'.html': 'text/html; charset=utf-8',
|
||||||
@@ -36,6 +36,8 @@ export interface StaticServer {
|
|||||||
readonly url: string;
|
readonly url: string;
|
||||||
readonly origin: string;
|
readonly origin: string;
|
||||||
readonly close: () => Promise<void>;
|
readonly close: () => Promise<void>;
|
||||||
|
/** Serves another build from now on, at the same URL: a new version being published. */
|
||||||
|
readonly serveFrom: (dir: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function startStaticServer(): Promise<StaticServer> {
|
export async function startStaticServer(): Promise<StaticServer> {
|
||||||
@@ -45,6 +47,7 @@ export async function startStaticServer(): Promise<StaticServer> {
|
|||||||
throw new Error(`No built app at ${DIST}. Run \`pnpm build\` first. (${String(error)})`);
|
throw new Error(`No built app at ${DIST}. Run \`pnpm build\` first. (${String(error)})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let root = DIST;
|
||||||
const server: Server = createServer((req, res) => {
|
const server: Server = createServer((req, res) => {
|
||||||
const path = decodeURIComponent((req.url ?? '/').split('?')[0] ?? '/');
|
const path = decodeURIComponent((req.url ?? '/').split('?')[0] ?? '/');
|
||||||
|
|
||||||
@@ -55,9 +58,9 @@ export async function startStaticServer(): Promise<StaticServer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const rel = normalize(path.slice(BASE.length) || 'index.html');
|
const rel = normalize(path.slice(BASE.length) || 'index.html');
|
||||||
const file = join(DIST, rel);
|
const file = join(root, rel);
|
||||||
// Confine to DIST: a test server is still a server.
|
// Confine to the served folder: a test server is still a server.
|
||||||
if (!file.startsWith(DIST + sep) && file !== DIST) {
|
if (!file.startsWith(root + sep) && file !== root) {
|
||||||
res.writeHead(403).end();
|
res.writeHead(403).end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -90,6 +93,9 @@ export async function startStaticServer(): Promise<StaticServer> {
|
|||||||
return {
|
return {
|
||||||
origin,
|
origin,
|
||||||
url: `${origin}${BASE}`,
|
url: `${origin}${BASE}`,
|
||||||
|
serveFrom: (dir) => {
|
||||||
|
root = dir;
|
||||||
|
},
|
||||||
close: () =>
|
close: () =>
|
||||||
new Promise<void>((resolve) => {
|
new Promise<void>((resolve) => {
|
||||||
server.closeAllConnections();
|
server.closeAllConnections();
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import AxeBuilder from '@axe-core/playwright';
|
||||||
|
import { expect, test, type Page } from '@playwright/test';
|
||||||
|
import { PRODUCT_NAME } from '@rosea/schema';
|
||||||
|
import { en } from '@rosea/ui/copy';
|
||||||
|
import { appendFileSync, cpSync, mkdtempSync, rmSync } from 'node:fs';
|
||||||
|
import { tmpdir } from 'node:os';
|
||||||
|
import { join } from 'node:path';
|
||||||
|
import { DIST, startStaticServer } from './static-server.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The stale service worker (CLAUDE.md §8, calm-refresh.md). A waiting worker exists
|
||||||
|
* only between two builds, so this publishes a real second one: version A's build
|
||||||
|
* with `sw.js` changed, served at the same URL. Its extra listener answers "which
|
||||||
|
* version are you?", so the test knows for certain which worker controls the page.
|
||||||
|
*/
|
||||||
|
const VERSION_B = `
|
||||||
|
// Added by e2e/update.spec.ts: version B of the worker, and a way to ask.
|
||||||
|
self.addEventListener('message', (event) => {
|
||||||
|
if (event.data === 'rosea-which-version') event.source?.postMessage('B');
|
||||||
|
});
|
||||||
|
`;
|
||||||
|
|
||||||
|
/** "A" unless the controlling worker answers that it is B. */
|
||||||
|
async function whichVersion(page: Page): Promise<string> {
|
||||||
|
return page.evaluate(
|
||||||
|
() =>
|
||||||
|
new Promise<string>((resolve) => {
|
||||||
|
const controller = navigator.serviceWorker.controller;
|
||||||
|
if (!controller) return resolve('none');
|
||||||
|
const timer = setTimeout(() => resolve('A'), 1500);
|
||||||
|
navigator.serviceWorker.addEventListener('message', (e) => {
|
||||||
|
if (e.data === 'B') {
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve('B');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
controller.postMessage('rosea-which-version');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('a new version waits, is offered in one quiet line, and comes only when the player refreshes', async ({ browser }) => {
|
||||||
|
const server = await startStaticServer();
|
||||||
|
const context = await browser.newContext();
|
||||||
|
const versionB = mkdtempSync(join(tmpdir(), 'rosea-version-b-'));
|
||||||
|
try {
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.goto(server.url);
|
||||||
|
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||||
|
await page.waitForFunction(() => navigator.serviceWorker.controller !== null, null, { timeout: 20_000 });
|
||||||
|
expect(await whichVersion(page)).toBe('A');
|
||||||
|
await expect(page.getByText(en.update.ready)).toHaveCount(0);
|
||||||
|
|
||||||
|
// Publish version B at the same URL.
|
||||||
|
cpSync(DIST, versionB, { recursive: true });
|
||||||
|
appendFileSync(join(versionB, 'sw.js'), VERSION_B);
|
||||||
|
server.serveFrom(versionB);
|
||||||
|
|
||||||
|
// A navigation makes the browser check for a new worker, as it does for a player.
|
||||||
|
await page.reload();
|
||||||
|
await expect(page.getByText(en.update.ready)).toBeVisible({ timeout: 20_000 });
|
||||||
|
|
||||||
|
// Offered, not swapped: A still controls the page, and B waits.
|
||||||
|
expect(await whichVersion(page)).toBe('A');
|
||||||
|
expect(await page.evaluate(async () => (await navigator.serviceWorker.getRegistration())?.waiting !== null)).toBe(true);
|
||||||
|
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||||
|
|
||||||
|
// The player refreshes: B takes over and the page reloads under it.
|
||||||
|
await Promise.all([page.waitForEvent('load'), page.getByRole('button', { name: en.update.refresh }).click()]);
|
||||||
|
await expect(page.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||||
|
await expect.poll(() => whichVersion(page), { timeout: 10_000 }).toBe('B');
|
||||||
|
await expect(page.getByText(en.update.ready)).toHaveCount(0);
|
||||||
|
} finally {
|
||||||
|
// A test run leaves the machine as it found it (CLAUDE.md §5.7).
|
||||||
|
await context.close();
|
||||||
|
await server.close();
|
||||||
|
rmSync(versionB, { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -13,7 +13,9 @@
|
|||||||
let {
|
let {
|
||||||
letter = '',
|
letter = '',
|
||||||
sunset,
|
sunset,
|
||||||
rose
|
rose,
|
||||||
|
updateReady = false,
|
||||||
|
onrefresh
|
||||||
}: {
|
}: {
|
||||||
/** The author's Markdown from docs/LETTER.md. Empty means there is no way to the page. */
|
/** The author's Markdown from docs/LETTER.md. Empty means there is no way to the page. */
|
||||||
letter?: string;
|
letter?: string;
|
||||||
@@ -21,6 +23,10 @@
|
|||||||
sunset?: SunsetWiring;
|
sunset?: SunsetWiring;
|
||||||
/** The rose and her care log. Absent, the garden has no rose. */
|
/** The rose and her care log. Absent, the garden has no rose. */
|
||||||
rose?: RoseWiring;
|
rose?: RoseWiring;
|
||||||
|
/** A new version of the garden is installed and waiting (calm-refresh.md). */
|
||||||
|
updateReady?: boolean;
|
||||||
|
/** Swap to the waiting version and reload. Only ever called by the player's tap. */
|
||||||
|
onrefresh?: () => void;
|
||||||
} = $props();
|
} = $props();
|
||||||
|
|
||||||
// --- The sunset (sunset-place.md) ---------------------------------------
|
// --- The sunset (sunset-place.md) ---------------------------------------
|
||||||
@@ -143,6 +149,14 @@
|
|||||||
</main>
|
</main>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
{#if updateReady && onrefresh}
|
||||||
|
<aside class="update" aria-label={en.update.ready}>
|
||||||
|
<p role="status">{en.update.ready}</p>
|
||||||
|
<button type="button" onclick={onrefresh}>{en.update.refresh}</button>
|
||||||
|
</aside>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.shell {
|
.shell {
|
||||||
min-height: 100dvh;
|
min-height: 100dvh;
|
||||||
@@ -205,6 +219,35 @@
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.update {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-2);
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
background: var(--paper);
|
||||||
|
border-top: 1px solid color-mix(in srgb, var(--ink-soft) 30%, transparent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update p {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--ink-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.update button {
|
||||||
|
font: inherit;
|
||||||
|
padding: var(--space-1) var(--space-3);
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid var(--rose);
|
||||||
|
background: var(--paper);
|
||||||
|
color: var(--ink);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.update button:focus-visible,
|
||||||
.quiet:focus-visible {
|
.quiet:focus-visible {
|
||||||
outline: 2px solid var(--rose);
|
outline: 2px solid var(--rose);
|
||||||
outline-offset: 2px;
|
outline-offset: 2px;
|
||||||
|
|||||||
@@ -88,6 +88,11 @@ export const en = {
|
|||||||
/** When the device refuses to keep anything (a private window). Calm, and true. */
|
/** When the device refuses to keep anything (a private window). Calm, and true. */
|
||||||
notKept: 'This device could not keep your choice, so the garden will ask again next time.'
|
notKept: 'This device could not keep your choice, so the garden will ask again next time.'
|
||||||
},
|
},
|
||||||
|
update: {
|
||||||
|
/** One quiet line when a new version waits; nothing reloads by itself (calm-refresh.md U2). */
|
||||||
|
ready: 'A new version of the garden is ready.',
|
||||||
|
refresh: 'Refresh'
|
||||||
|
},
|
||||||
letter: {
|
letter: {
|
||||||
/** The help section's name (ROADMAP §1). The letter itself is the author's, in docs/LETTER.md. */
|
/** The help section's name (ROADMAP §1). The letter itself is the author's, in docs/LETTER.md. */
|
||||||
title: 'A Letter from the Gardener',
|
title: 'A Letter from the Gardener',
|
||||||
|
|||||||
@@ -83,3 +83,27 @@ describe('Shell and the Letter', () => {
|
|||||||
expect(screen.getByText(/or not\./)).toBeTruthy();
|
expect(screen.getByText(/or not\./)).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Shell and a new version waiting (calm-refresh.md)', () => {
|
||||||
|
it('says nothing while no new version waits', () => {
|
||||||
|
render(Shell, { onrefresh: () => undefined });
|
||||||
|
expect(screen.queryByText(en.update.ready)).toBeNull();
|
||||||
|
expect(screen.queryByRole('button', { name: en.update.refresh })).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('when one waits: one quiet line and Refresh, which only the player\'s tap sends', async () => {
|
||||||
|
let refreshed = 0;
|
||||||
|
render(Shell, { updateReady: true, onrefresh: () => (refreshed += 1) });
|
||||||
|
expect(screen.getByRole('status').textContent).toBe(en.update.ready);
|
||||||
|
expect(refreshed).toBe(0);
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: en.update.refresh }));
|
||||||
|
expect(refreshed).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is there on the Letter too', () => {
|
||||||
|
window.location.hash = '#letter';
|
||||||
|
render(Shell, { letter: LETTER, updateReady: true, onrefresh: () => undefined });
|
||||||
|
expect(h1().textContent).toBe(en.letter.title);
|
||||||
|
expect(screen.getByRole('button', { name: en.update.refresh })).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Generated
+3
@@ -99,6 +99,9 @@ importers:
|
|||||||
vite-plugin-pwa:
|
vite-plugin-pwa:
|
||||||
specifier: 1.3.0
|
specifier: 1.3.0
|
||||||
version: 1.3.0(vite@6.4.3(@types/node@22.20.1)(terser@5.51.2)(tsx@4.23.12))(workbox-build@7.4.1)(workbox-window@7.4.1)
|
version: 1.3.0(vite@6.4.3(@types/node@22.20.1)(terser@5.51.2)(tsx@4.23.12))(workbox-build@7.4.1)(workbox-window@7.4.1)
|
||||||
|
workbox-window:
|
||||||
|
specifier: 7.4.1
|
||||||
|
version: 7.4.1
|
||||||
|
|
||||||
packages/content:
|
packages/content:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
Reference in New Issue
Block a user