[app] KeepSafe: Wire persist, the file download and import; e2e restores her on a fresh profile

This commit is contained in:
2026-11-02 00:44:22 +01:00
parent 512c300973
commit e63563755b
2 changed files with 95 additions and 2 deletions
+57
View File
@@ -222,3 +222,60 @@ test.describe('the rose, in Prague at 08:00 on 1 March 2026', () => {
expect((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
});
});
// --- Keeping her (.agents/features/keep-her-safe.md) --------------------------
test.describe('keep her safe, 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');
test('save her to a file, lose everything, bring her back: her care returns, and the file never held the town', async ({ browser }) => {
// The first device: choose a town, tend the rose, save her.
const first = await browser.newContext({ timezoneId: 'Europe/Prague', locale: 'en-US' });
let saved = '';
try {
const page = await first.newPage();
await page.clock.setFixedTime(MORNING);
await page.goto(server.url);
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('brno');
await page.getByRole('button', { name: /^Brno/ }).first().click();
await page.getByRole('button', { name: en.rose.water }).hover();
await page.mouse.down();
await page.waitForTimeout(1500);
await page.mouse.up();
await storedCare(page, 1);
await page.getByRole('button', { name: en.rose.safe.title }).click();
const download = page.waitForEvent('download');
await page.getByRole('button', { name: en.rose.safe.save }).click();
const file = await download;
expect(file.suggestedFilename()).toBe('rose-2026-03-01.json');
saved = readFileSync((await file.path())!, 'utf8');
} finally {
await first.close();
}
expect(JSON.parse(saved)).toMatchObject({ format: 'rosea-rose', version: 1 });
expect(saved).not.toMatch(/Brno|privateKey/);
// A fresh profile: the shape of an evicted garden, or a new phone.
const second = await browser.newContext({ timezoneId: 'Europe/Prague', locale: 'en-US' });
try {
const page = await second.newPage();
await page.clock.setFixedTime(MORNING + 3_600_000);
await page.goto(server.url);
await expect(page.getByRole('img', { name: 'The rose, a bud.' })).toBeVisible();
await page.getByRole('button', { name: en.rose.safe.title }).click();
await page.getByLabel(en.rose.safe.bringBack).setInputFiles({ name: 'rose-2026-03-01.json', mimeType: 'application/json', buffer: Buffer.from(saved) });
await expect(page.getByText(en.rose.safe.broughtBack(1))).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((await new AxeBuilder({ page }).analyze()).violations.map((v) => `${v.id}: ${v.help}`)).toEqual([]);
} finally {
await second.close();
}
});
});