[app] Rose: Wire identity and the care log into the garden; e2e and offline tend the rose
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@rosea/content": "workspace:*",
|
||||
"@rosea/identity": "workspace:*",
|
||||
"@rosea/schema": "workspace:*",
|
||||
"@rosea/storage": "workspace:*",
|
||||
"@rosea/ui": "workspace:*"
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { guessTown } from '@rosea/content/guess';
|
||||
import { openProfile } from '@rosea/storage';
|
||||
import { Shell, type SunsetWiring } from '@rosea/ui';
|
||||
import { createIdentity } from '@rosea/identity';
|
||||
import { openStorage } from '@rosea/storage';
|
||||
import { Shell, type RoseWiring, type SunsetWiring } from '@rosea/ui';
|
||||
import { version } from '../package.json';
|
||||
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
|
||||
import letter from '../../../docs/LETTER.md?raw';
|
||||
|
||||
// The device's own zone, read here and nowhere else: the engine never asks the
|
||||
// device anything (CLAUDE.md §2). Only the zone's name; never GPS, never a lookup.
|
||||
const deviceZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
const profile = openProfile();
|
||||
const storage = openStorage();
|
||||
|
||||
// The town list is large, so it loads on the first search (sunset-place.md P5).
|
||||
// A failed load is forgotten, so the next keystroke tries again.
|
||||
@@ -22,10 +24,38 @@
|
||||
const sunset: SunsetWiring = {
|
||||
guess: guessTown(deviceZone),
|
||||
search: async (query) => (await loadTowns()).searchTowns(query),
|
||||
load: () => profile.loadSunsetPlace(),
|
||||
save: (choice) => profile.saveSunsetPlace(choice),
|
||||
load: () => storage.loadSunsetPlace(),
|
||||
save: (choice) => storage.saveSunsetPlace(choice),
|
||||
now: () => Date.now()
|
||||
};
|
||||
|
||||
// The player's key names their rose (rose.md). Kept once; if the device will not
|
||||
// keep it, this visit still has a rose, under a key that lasts until closing.
|
||||
let identity: ReturnType<RoseWiring['identity']> | undefined;
|
||||
async function findIdentity(): ReturnType<RoseWiring['identity']> {
|
||||
try {
|
||||
const kept = await storage.loadIdentity();
|
||||
if (kept) return { publicKey: kept.publicKey, kept: true };
|
||||
} catch (error) {
|
||||
console.error('identity: the device could not read the kept key', error);
|
||||
}
|
||||
const fresh = await createIdentity();
|
||||
try {
|
||||
return { publicKey: (await storage.keepIdentity(fresh)).publicKey, kept: true };
|
||||
} catch (error) {
|
||||
console.error('identity: the device could not keep the key; this visit uses one that lasts until closing', error);
|
||||
return { publicKey: fresh.publicKey, kept: false };
|
||||
}
|
||||
}
|
||||
|
||||
const rose: RoseWiring = {
|
||||
identity: () => (identity ??= findIdentity()),
|
||||
loadCare: () => storage.loadCare(),
|
||||
appendCare: (event) => storage.appendCare(event),
|
||||
clientVersion: version,
|
||||
deviceZone,
|
||||
now: () => Date.now()
|
||||
};
|
||||
</script>
|
||||
|
||||
<Shell {letter} {sunset} />
|
||||
<Shell {letter} {sunset} {rose} />
|
||||
|
||||
+12
-1
@@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test';
|
||||
import { PRODUCT_NAME } from '@rosea/schema';
|
||||
import { en } from '@rosea/ui/copy';
|
||||
import { startStaticServer } from './static-server.js';
|
||||
import { storedTown } from './stored.js';
|
||||
import { storedCare, storedTown } from './stored.js';
|
||||
|
||||
/**
|
||||
* The offline suite. CLAUDE.md §3 describes its full shape: tend the rose, walk
|
||||
@@ -66,6 +66,14 @@ test('the shell opens from the service worker with the server gone', async ({ br
|
||||
await expect(page.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
|
||||
await storedTown(page, 'Plzeň');
|
||||
|
||||
// Tending the rose offline: hold Water, as a finger would (rose.md).
|
||||
await page.getByRole('button', { name: en.rose.water }).hover();
|
||||
await page.mouse.down();
|
||||
await page.waitForTimeout(1500);
|
||||
await page.mouse.up();
|
||||
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
|
||||
await storedCare(page, 1);
|
||||
|
||||
// 2. Close the tab and open a fresh one: a cold start, the shape of a player
|
||||
// coming back days later with no signal.
|
||||
await page.close();
|
||||
@@ -74,6 +82,9 @@ test('the shell opens from the service worker with the server gone', async ({ br
|
||||
await again.goto(server.url);
|
||||
await expect(again.getByRole('heading', { level: 1 })).toHaveText(PRODUCT_NAME);
|
||||
await expect(again.locator('.sun p').first()).toHaveText(/in Plzeň\.$/);
|
||||
// The care given offline survived the closed tab.
|
||||
await again.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(again.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
|
||||
// 3. A deep link inside the scope falls back to the shell, not an error page.
|
||||
await again.goto(`${server.url}somewhere/deeper`);
|
||||
|
||||
+41
-1
@@ -7,7 +7,7 @@ import { nextInvitation } from '@rosea/engine';
|
||||
import { searchTowns } from '@rosea/content/places';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { BASE, startStaticServer, type StaticServer } from './static-server.js';
|
||||
import { storedTown } from './stored.js';
|
||||
import { storedCare, storedTown } from './stored.js';
|
||||
|
||||
let server: StaticServer;
|
||||
|
||||
@@ -182,3 +182,43 @@ test.describe('the sunset place, in Prague\'s time zone at noon on 29 March 2026
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
// --- The rose (.agents/features/rose.md) -------------------------------------
|
||||
test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
|
||||
test.use({ timezoneId: 'Europe/Prague', locale: 'en-US' });
|
||||
const MORNING = Date.parse('2026-03-01T08:00:00+01:00');
|
||||
|
||||
/** Holds the Water button with the mouse, as a player holds it with a finger. */
|
||||
async function pour(page: Page, ms: number): Promise<void> {
|
||||
await page.getByRole('button', { name: en.rose.water }).hover();
|
||||
await page.mouse.down();
|
||||
await page.waitForTimeout(ms);
|
||||
await page.mouse.up();
|
||||
}
|
||||
|
||||
test('a new rose is a bud; holding Water is one day of care; a reload keeps it', async ({ page }) => {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
const { requests } = await open(page);
|
||||
await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible();
|
||||
await expect(page.getByText(en.rose.says.dry)).toBeVisible();
|
||||
|
||||
await pour(page, 1500);
|
||||
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
|
||||
await storedCare(page, 1);
|
||||
await page.reload();
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
|
||||
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
|
||||
});
|
||||
|
||||
test('the rose and her care have no accessibility violations', async ({ page }) => {
|
||||
await page.clock.setFixedTime(MORNING);
|
||||
await open(page);
|
||||
await page.getByRole('button', { name: en.rose.numbers }).click();
|
||||
await expect(page.locator('#rose-numbers')).toBeVisible();
|
||||
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,3 +34,33 @@ export async function storedTown(page: Page, name: string): Promise<void> {
|
||||
{ timeout: 5_000 }
|
||||
);
|
||||
}
|
||||
|
||||
/** Waits until the care log holds at least `count` events, for the same reason as above. */
|
||||
export async function storedCare(page: Page, count: number): Promise<void> {
|
||||
await page.waitForFunction(
|
||||
(expected) =>
|
||||
new Promise<boolean>((resolve) => {
|
||||
const req = indexedDB.open('rosea');
|
||||
req.onerror = () => resolve(false);
|
||||
req.onsuccess = () => {
|
||||
const db = req.result;
|
||||
if (!db.objectStoreNames.contains('events')) {
|
||||
db.close();
|
||||
resolve(false);
|
||||
return;
|
||||
}
|
||||
const n = db.transaction('events').objectStore('events').count();
|
||||
n.onsuccess = () => {
|
||||
db.close();
|
||||
resolve(n.result >= expected);
|
||||
};
|
||||
n.onerror = () => {
|
||||
db.close();
|
||||
resolve(false);
|
||||
};
|
||||
};
|
||||
}),
|
||||
count,
|
||||
{ timeout: 5_000 }
|
||||
);
|
||||
}
|
||||
|
||||
Generated
+18
@@ -68,6 +68,9 @@ importers:
|
||||
'@rosea/content':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/content
|
||||
'@rosea/identity':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/identity
|
||||
'@rosea/schema':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/schema
|
||||
@@ -129,6 +132,15 @@ importers:
|
||||
specifier: 3.2.7
|
||||
version: 3.2.7(@types/node@22.20.1)(jsdom@25.0.1)(terser@5.51.2)(tsx@4.23.12)
|
||||
|
||||
packages/identity:
|
||||
devDependencies:
|
||||
typescript:
|
||||
specifier: 5.9.3
|
||||
version: 5.9.3
|
||||
vitest:
|
||||
specifier: 3.2.7
|
||||
version: 3.2.7(@types/node@22.20.1)(jsdom@25.0.1)(terser@5.51.2)(tsx@4.23.12)
|
||||
|
||||
packages/schema:
|
||||
dependencies:
|
||||
ajv:
|
||||
@@ -150,6 +162,12 @@ importers:
|
||||
'@rosea/engine':
|
||||
specifier: workspace:*
|
||||
version: link:../engine
|
||||
'@rosea/identity':
|
||||
specifier: workspace:*
|
||||
version: link:../identity
|
||||
'@rosea/schema':
|
||||
specifier: workspace:*
|
||||
version: link:../schema
|
||||
dexie:
|
||||
specifier: 4.4.6
|
||||
version: 4.4.6
|
||||
|
||||
Reference in New Issue
Block a user