[repo] FabricaRelease: Rosea as a Fabrica app: the release and e2e pipelines, the Aula page's words and pictures, the version check, the APK signed in Custos, domi-rosea:// from the installer, the phone target

This commit is contained in:
2026-11-19 01:38:53 +01:00
parent 185625e7fe
commit 0d37f91763
34 changed files with 1148 additions and 6 deletions
+54
View File
@@ -0,0 +1,54 @@
import { _android as android, expect, test, type AndroidDevice, type Page } from '@playwright/test';
import { en } from '@rosea/ui/copy';
import { pastGardener, openRing } from '../garden.js';
import { storedCare } from '../stored.js';
/**
* The Android app on Fabrica's test phone (.agents/features/fabrica-release.md F9): the debug
* APK Fabrica installed, reached through its WebView with Playwright's own Android support
* (Fabrica docs/22_devices.md). Only `fabrica tests run --target phone` runs it: the phone is
* leased from Fabrica's queue, the app's data is cleared first, and Fabrica stops the app after.
* Watering is by the keyboard's Space held down: the same pour as a held finger (rose.md), and
* the one input a WebView reached over DevTools takes as a player's.
*/
const PKG = process.env['FABRICA_TESTS_PACKAGE'];
const SERIAL = process.env['ANDROID_SERIAL'];
test.skip(!PKG || !SERIAL, "runs only through Fabrica's phone queue: fabrica tests run --target phone");
async function garden(device: AndroidDevice): Promise<Page> {
const webView = await device.webView({ pkg: PKG! }, { timeout: 30_000 });
const page = await webView.page();
await expect(page.getByRole('heading', { level: 2, name: en.gardener.question }).or(page.getByRole('button', { name: en.rose.care }))).toBeVisible({
timeout: 30_000
});
return page;
}
test('the garden opens on the phone; she is watered, and still watered after the app is closed and opened', async () => {
test.setTimeout(240_000);
const device = (await android.devices()).find((d) => d.serial() === SERIAL);
expect(device, `no phone with the serial ${SERIAL} on adb`).toBeDefined();
try {
let page = await garden(device!);
await pastGardener(page);
// No town: the private choice, and it keeps the test free of any place.
await page.getByRole('button', { name: /^Not now/ }).click();
await openRing(page);
await page.getByRole('button', { name: en.rose.water }).focus();
await page.keyboard.down('Space');
await page.waitForTimeout(1500);
await page.keyboard.up('Space');
await expect(page.getByText(en.rose.says.thanks)).toBeVisible();
await storedCare(page, 1);
await device!.shell(`am force-stop ${PKG!}`);
await device!.shell(`monkey -p ${PKG!} -c android.intent.category.LAUNCHER 1`);
page = await garden(device!);
await page.getByRole('button', { name: en.rose.numbers }).click();
await expect(page.locator('#rose-numbers')).toContainText(`${en.rose.daysOfCare}1`);
} finally {
await device?.close();
}
});
+164
View File
@@ -0,0 +1,164 @@
import { mkdirSync } from 'node:fs';
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { expect, test, type Browser, type BrowserContext, type Page } from '@playwright/test';
import { en } from '@rosea/ui/copy';
import { openRing, pastGardener } from './garden.js';
import { startStaticServer, type StaticServer } from './static-server.js';
import { storedCare, storedTown } from './stored.js';
/**
* The pictures for Rosea's Aula page (.agents/features/fabrica-release.md F7), taken from the
* BUILT PWA. The demo garden is made by the game itself, as a player makes one: the first look
* of the gardener, the town Prague, and two weeks of watering, once each morning, in an invented
* March. No file, profile or town of a real player is read. `.fabrica/aula.yaml` lists the files;
* `fabrica aula shots` checks and publishes them.
*/
const OUT = fileURLToPath(new URL('./aula/', import.meta.url));
const ZONE = 'Europe/Prague';
const DAYS = 14;
/** 08:00 in Prague on day `n` of March 2026 (CET, before the clocks change on the 29th). */
const morning = (n: number): number => Date.parse(`2026-03-${String(n).padStart(2, '0')}T08:00:00+01:00`);
const LAST = morning(DAYS + 1);
let server: StaticServer;
test.beforeAll(async () => {
mkdirSync(OUT, { recursive: true });
server = await startStaticServer();
});
test.afterAll(async () => {
await server.close();
});
/** Holds Water with the mouse, as a player holds it with a finger, until she thanks them. */
async function water(page: Page): Promise<void> {
await openRing(page);
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();
}
async function shot(page: Page, name: string): Promise<void> {
await page.screenshot({ path: `${OUT}${name}.png`, animations: 'disabled', caret: 'hide' });
}
/** Every request the page makes, to prove the pictures were taken with nothing from elsewhere. */
function watch(page: Page): string[] {
const requests: string[] = [];
page.on('request', (r) => requests.push(r.url()));
return requests;
}
async function chooseGardenerAndTown(page: Page): Promise<void> {
await pastGardener(page);
await page.getByRole('searchbox', { name: en.sunset.searchLabel }).fill('prague');
await page.getByRole('button', { name: /^Prague/ }).first().click();
await storedTown(page, 'Prague');
}
async function newContext(browser: Browser, phone: boolean): Promise<BrowserContext> {
const common = { timezoneId: ZONE, locale: 'en-US', colorScheme: 'light' as const, reducedMotion: 'reduce' as const };
return phone
? browser.newContext({
...common,
viewport: { width: 360, height: 800 },
deviceScaleFactor: 2,
isMobile: true,
hasTouch: true,
userAgent: 'Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Mobile Safari/537.36'
})
: browser.newContext({ ...common, viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 });
}
test.describe.configure({ mode: 'serial', timeout: 300_000 });
let saved = '';
test('two weeks in an invented garden, photographed on a desktop', async ({ browser }) => {
const context = await newContext(browser, false);
try {
const page = await context.newPage();
const requests = watch(page);
await page.clock.install({ time: morning(1) });
await page.goto(server.url);
await expect(page.getByRole('heading', { level: 2, name: en.gardener.question })).toBeVisible({ timeout: 20_000 });
await shot(page, 'first-open');
await chooseGardenerAndTown(page);
for (let day = 1; day <= DAYS; day += 1) {
if (day > 1) {
await page.clock.setSystemTime(morning(day));
await page.reload();
await expect(page.getByRole('button', { name: en.rose.care })).toBeVisible();
}
await water(page);
await storedCare(page, day);
}
// The fifteenth morning: what she needs today, before any care.
await page.clock.setSystemTime(LAST);
await page.reload();
await expect(page.getByRole('button', { name: en.rose.care })).toBeVisible();
await expect(page.locator('.sun p').first()).toHaveText(/in Prague\.$/);
await shot(page, 'garden');
await openRing(page);
await shot(page, 'ring');
await page.keyboard.press('Escape');
await page.getByRole('button', { name: en.rose.numbers }).click();
await expect(page.locator('#rose-numbers')).toContainText(en.rose.daysOfCare);
await page.locator('#rose-numbers').scrollIntoViewIfNeeded();
await shot(page, 'numbers');
await page.getByRole('button', { name: en.rose.safe.title }).click();
await expect(page.getByRole('button', { name: en.rose.safe.save })).toBeVisible();
await page.getByRole('button', { name: en.rose.safe.save }).scrollIntoViewIfNeeded();
await shot(page, 'safe');
// The same rose, carried to the phone below as a player carries her: in a file.
const download = page.waitForEvent('download');
await page.getByRole('button', { name: en.rose.safe.save }).click();
saved = await readFile((await (await download).path())!, 'utf8');
expect(saved).not.toMatch(/Prague|privateKey/);
await page.reload();
await page.getByRole('button', { name: en.chair.move }).click();
const scene = page.getByRole('dialog', { name: en.chair.scene });
await expect(scene).toBeVisible();
await page.clock.runFor(30_000);
await expect(scene.getByText(/^Tonight the sun sets at .* in Prague\.$/)).toBeVisible();
await shot(page, 'sunset');
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
} finally {
await context.close();
}
});
test('the same rose on a phone', async ({ browser }) => {
expect(saved, 'the desktop test saves the rose this one opens').not.toBe('');
const context = await newContext(browser, true);
try {
const page = await context.newPage();
const requests = watch(page);
await page.clock.install({ time: LAST });
await page.goto(server.url);
await chooseGardenerAndTown(page);
await page.getByRole('button', { name: en.rose.safe.title }).click();
await page.getByLabel(en.rose.safe.bringBack).setInputFiles({ name: 'rose.json', mimeType: 'application/json', buffer: Buffer.from(saved) });
await expect(page.getByText(/^She is back/)).toBeVisible();
await storedCare(page, DAYS);
await page.reload();
await expect(page.getByRole('button', { name: en.rose.care })).toBeVisible();
await shot(page, 'phone-garden');
await openRing(page);
await shot(page, 'phone-ring');
expect(requests.filter((url) => !url.startsWith(server.origin + '/'))).toEqual([]);
} finally {
await context.close();
}
});
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig, devices } from '@playwright/test';
/**
* The Aula pictures (`pnpm aula:shots`, .agents/features/fabrica-release.md F7): the BUILT PWA
* on demo data the game makes itself, written to e2e/aula/ (git-ignored). Its own config, so
* `pnpm test:e2e` stays the suite of record and the pictures are taken only when asked for.
*/
export default defineConfig({
testDir: '.',
testMatch: /aula\.spec\.ts/,
fullyParallel: false,
workers: 1,
retries: 0,
reporter: [['list']],
use: {
...devices['Desktop Chrome'],
trace: 'retain-on-failure'
}
});
+21
View File
@@ -0,0 +1,21 @@
import { defineConfig, devices } from '@playwright/test';
/**
* Fabrica's targets (.fabrica/tests.yaml; .agents/features/fabrica-release.md F9).
* - `web`: the specs of `pnpm test:e2e`, against the BUILT bundle (build it first).
* - `android`: the app on Fabrica's test phone, leased from its phone queue. Without the
* environment Fabrica gives it, the test skips and says why: it never reaches for a phone itself.
* `pnpm test:e2e` keeps its own config, so nothing here changes the suite of record.
*/
export default defineConfig({
testDir: '.',
fullyParallel: false,
workers: 1,
retries: 0,
reporter: [['list']],
use: { trace: 'retain-on-failure' },
projects: [
{ name: 'web', testMatch: /(shell|update|petal|planet)\.spec\.ts/, use: { ...devices['Desktop Chrome'] } },
{ name: 'android', testMatch: /android\/.*\.android\.ts/ }
]
});