Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 20 additions & 1 deletion .claude/skills/dessen-app/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,23 @@ and the reference implementation is `apps/xpui/nook` (Book Nook). In short:
back to front with a paper edge; one grey for material and shadow; sizes
measured from the box; tens of draw calls per piece.
- **Done means looked at:** render each screen in the simulator, and leave a
`make test` check that opens every screen and comes back.
screen-test walk for every screen (below).

## Testing an xpui app

An xpui app is not done without screen tests and, for its logic, unit tests.
The recipe is in [`AGENTS.md`](../../../AGENTS.md#recipe-test-an-xpui-app) and the
reference in [`tests/xpui/README.md`](../../../tests/xpui/README.md). In short:

- `tests/xpui/<app>.scenarios` (copy `nook.scenarios`): a walk per screen and
state, each with `expect="..."`, tapping by label (`@Label`) where it can.
- `make xpui-screens` writes the goldens on the first run and fails; open every
PNG, then run again. Commit the goldens with the app.
- When a screen fails after a change: read what moved, look at
`build/screen-diffs/`, fix it or (if meant) `make xpui-bless APP=<app>`
and say so. Change and bless one app at a time.
Never bless unseen; never raise `SCREEN_TOLERANCE`.
- Logic that draws nothing: a crate in `tests/xpui/unit/` (copy `lightsout/`).

## The API surface

Expand Down Expand Up @@ -203,4 +219,7 @@ make sd # stage build/sd/plugins/<app>/ for an SD card
make rust # build + run the Rust example (needs the Rust toolchain)
make zig # build + run the Zig example (needs Zig)
make size # ESP32-C3 flash cost of the VM + binding
make xpui-screens # xpui screen tests (pictures + positions, 3 sizes)
make xpui-bless APP=nook # accept one app's deliberate screen changes, after looking
make xpui-unit # xpui host unit tests
```
85 changes: 85 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# `make test` on every pull request and every push to master: the VM, the
# binding, the C and Rust apps, and the xpui apps' screen and unit tests
# (tests/xpui/README.md). When a screen test fails, the diff images are
# uploaded as the `screen-diffs` artifact.
name: test

on:
pull_request:
push:
branches: [master]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
path: dessen

# The SDK commit the binding was last reviewed against (make sync-accept).
# It also draws the screen-test pictures, so the goldens are made with it.
- name: Read the FreeInk SDK pin
id: sdk
run: echo "sha=$(tr -d '[:space:]' < dessen/abi/.freeink-sync)" >> "$GITHUB_OUTPUT"

# A sibling checkout, where the Makefile looks by default (../freeink-sdk).
# Its submodule (the icon sources) is not needed: the icons are generated
# into its headers.
- uses: actions/checkout@v4
with:
repository: Free-Ink/freeink-sdk
ref: ${{ steps.sdk.outputs.sha }}
path: freeink-sdk

# The desktop runner needs OpenSSL (desktop crypto) and zlib (PNGs). Any
# RV32 GCC builds the C apps; Ubuntu's riscv64 one targets rv32im too.
- name: Install the C toolchains
run: |
sudo apt-get update -q
sudo apt-get install -y -q --no-install-recommends \
gcc-riscv64-unknown-elf libssl-dev zlib1g-dev

# The pin of apps/xpui/rust-toolchain.toml, as the default too, because
# the Makefile checks the default toolchain for the riscv32im target.
- name: Install Rust
run: |
rustup toolchain install 1.97.1 --profile minimal --target riscv32im-unknown-none-elf
rustup default 1.97.1

- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
dessen/build/rust
dessen/build/xpui
dessen/build/xpui-unit
key: cargo-${{ runner.os }}-${{ hashFiles('dessen/**/Cargo.lock', 'dessen/**/rust-toolchain.toml') }}
restore-keys: cargo-${{ runner.os }}-

# XPUI_LOCKED: build the xpui commits in the committed Cargo.lock, the
# ones the goldens were drawn with, and fail if a Cargo.toml changed
# without its lockfile. RISCV: Ubuntu's RV32 GCC; a Mac uses PlatformIO's (the
# Makefile's default), so run plain `make test` there.
- name: make test
working-directory: dessen
run: make RISCV=riscv64-unknown-elf- XPUI_LOCKED=--locked test

- name: Upload the screen diffs
if: failure()
uses: actions/upload-artifact@v4
with:
name: screen-diffs
path: dessen/build/screen-diffs/
if-no-files-found: ignore
retention-days: 14
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ docs/proposed-capabilities.md
# Generated by Cargo
# will have compiled files and executables
sdk/rust/target
# The SDK is a library: its users resolve its dependencies. The apps' and the
# tests' lockfiles are committed: they pin the xpui the screen goldens were
# drawn with (tests/xpui/README.md).
sdk/rust/Cargo.lock
Cargo.lock
debug/
target/
**/*.rs.bk
Expand Down
64 changes: 62 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ the **crosspoint-reader** repo on branch `feat/dessen-apps`, behind
interpreter and binding are tiny on purpose. Add a call only when a real app
needs it; don't speculatively mirror the whole SDK.
5. **Leave a test.** Non-trivial logic gets one runnable check (a self-checking
app or a `test_host.cpp` assertion) wired into `make test`.
app or a `test_host.cpp` assertion) wired into `make test`. An **xpui app**
gets screen tests for every screen and unit tests for its logic; see
[Recipe: test an xpui app](#recipe-test-an-xpui-app). Never bless a golden
you have not opened, and never raise the tolerance to make a test pass.

## Build & test

Expand All @@ -61,8 +64,18 @@ make test RUST=no # C only, when Rust (riscv32im target) or xpui-backends is a
make size # ESP32-C3 flash cost of the VM and the binding
zig build # the Zig apps with Zig alone (build.zig, also read by zls); zig build run -Dapp=hello
make FREEINK_SDK=/path/to/freeink-sdk test # if the SDK isn't a sibling dir
make xpui-screens # the xpui screen tests only: pictures + element positions, 3 sizes
make xpui-screens APP=nook # one app's walks
make xpui-bless APP=nook # rewrite its goldens after a deliberate change (look first!)
make xpui-standards # what each xpui app still breaks of the screen standards
make xpui-unit # the xpui apps' host unit tests only
```

`make test` is what CI runs (`.github/workflows/test.yml`, on every pull
request); it fails on any screen, element, standard or unit test failure, and
uploads the screen diffs as an artifact. More in
[`tests/xpui/README.md`](tests/xpui/README.md#in-ci).

The RISC-V compiler is expected at `~/.platformio/tools/toolchain-riscv32-esp/`.
Note PlatformIO sometimes removes the copy under `packages/`; the Makefile uses
the stable `tools/` path.
Expand Down Expand Up @@ -97,6 +110,52 @@ the stable `tools/` path.
manifest it checks; exit 103 = the board cannot drive the app).
7. Add a check and run `make test`.

## Recipe: test an xpui app

Every xpui app (new or changed) is covered by **screen tests**: walks that
drive it to each screen, drawn with FreeInk's real renderer and fonts at
480×800, 800×480 and 1448×1072, compared with committed PNG goldens and
element positions within 1 px. Pure logic gets **unit tests** on the host.
Full reference: [`tests/xpui/README.md`](tests/xpui/README.md).

For a **new** app:

1. Add it to `XPUI_APPS` in the `Makefile` and to `apps/xpui/Cargo.toml`.
2. Write `tests/xpui/<app>.scenarios`, copying `tests/xpui/nook.scenarios`.
One walk per reachable screen and state: the root screen (per board if it
differs), every pushed screen (`pushed`) and both ways back (`@back`, `b`),
every dialog and each answer, empty/error/old-firmware states, a step of
the main loop by keys and by touch, and leaving the app.
3. Give every walk `expect="..."`: text only its final screen shows. Tap by
label (`@New`, `@"Keep Playing"`); a pixel tap (`t173,291`) only where
nothing is labelled, one walk per size (`sizes=480x800`).
4. Run `make xpui-standards` and list what it passes on `standards =` (a new
app should pass `bar taps actions`).
5. Run `make xpui-screens`. The first run writes the goldens and **fails on
purpose**. Open every new PNG in `tests/xpui/golden/<app>/` and confirm it
shows the screen the walk names; run again, it must pass.
6. If the app has files that draw nothing, add a crate in `tests/xpui/unit/`
(copy `unit/lightsout/`; it `#[path]`-includes the app's files) and add it
to the workspace members.
7. `make test`. Commit the scenarios, the goldens and the unit tests with the
app.

For a **change** to how an app draws (a refactor, a new xpui component, a
framework migration), work one app at a time. The committed goldens are the
reference, so there is nothing to record first.

1. Change one app, then run `make xpui-screens APP=<app>`.
2. Each failure names what moved (`text 'How to Play' moved +0,+2`) and
writes a diff image to `build/screen-diffs/<app>/` (red = moved beyond
tolerance). Look at it.
3. Unintended: fix the code. Intended: tell the user what moved and why, then
`make xpui-bless APP=<app>` (never bless all apps for a one-app change)
and open the rewritten PNGs.
4. A walk that now fails "did not reach its screen" means its tap missed the
new layout: re-aim the tap, don't delete the walk.
5. `make test`, then commit the app with its blessed goldens before the next
app.

## Recipe: add a capability (one new call)

When an app needs something FreeInk/CrossPoint can do but no call exposes:
Expand Down Expand Up @@ -162,7 +221,8 @@ checklist, is [`docs/writing-apps.md`](docs/writing-apps.md#screen-standards);
9. **E-paper.** Redraw only on change; the same state draws the same picture;
no animation.
10. **Look at it.** Check each screen in the simulator before calling it done,
and leave a `make test` check that opens every screen and comes back.
and leave a screen-test walk for every screen
([Recipe: test an xpui app](#recipe-test-an-xpui-app)).
Game graphics follow [`docs/drawing-icons.md`](docs/drawing-icons.md).

## When NOT to proceed without asking
Expand Down
37 changes: 33 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ endif

GEN = sdk/dessen_sysnums.h sdk/dessen_calls.h freeink/dessen_dispatch.inc
HOSTFLAGS = -std=c++17 -O2 -Wall -Wextra -Ivm -Isdk -Ifreeink -Ihost $(OPENSSL_CFLAGS) -I$(FREEINK_SDK)/libs/ui/FreeInkUI/include
# The desktop runner's snapshots (host/Snapshot.h) draw with FreeInk's
# framebuffer target and its gallery fonts, and write PNGs with zlib.
SNAPFLAGS = -I$(FREEINK_SDK)/libs/ui/FreeInkUI/tools
BINDING = sdk/dessen_abi.h freeink/DessenFreeInk.cpp freeink/DessenFreeInk.h freeink/DessenServices.h host/DesktopServices.cpp host/DesktopServices.h host/TraceTarget.h host/Manifest.h vm/dessen_vm.h $(GEN)

all: build/dessen build/test_freeink $(APPS:%=build/%.bin)
Expand All @@ -54,8 +57,9 @@ build/dessen_vm.o: vm/dessen_vm.c vm/dessen_vm.h sdk/dessen_abi.h $(GEN)
@mkdir -p build
cc -O2 -Wall -Wextra -Ivm -Isdk -c vm/dessen_vm.c -o $@

build/dessen: host/main.cpp build/dessen_vm.o $(BINDING)
c++ $(HOSTFLAGS) host/main.cpp freeink/DessenFreeInk.cpp host/DesktopServices.cpp build/dessen_vm.o $(OPENSSL_LIBS) -o $@
build/dessen: host/main.cpp host/Snapshot.h build/dessen_vm.o $(BINDING)
c++ $(HOSTFLAGS) $(SNAPFLAGS) host/main.cpp freeink/DessenFreeInk.cpp host/DesktopServices.cpp \
$(FREEINK_SDK)/libs/ui/FreeInkUI/src/FreeInkUI.cpp build/dessen_vm.o $(OPENSSL_LIBS) -lz -o $@

build/test_freeink: freeink/test_host.cpp build/dessen_vm.o $(BINDING)
c++ $(HOSTFLAGS) freeink/test_host.cpp freeink/DessenFreeInk.cpp host/DesktopServices.cpp build/dessen_vm.o $(OPENSSL_LIBS) -o $@
Expand Down Expand Up @@ -179,8 +183,13 @@ rust-sdk: build/selftest_rs.bin build/dessen
# The xpui apps: one cargo build for the workspace, then each image cut out
# of its ELF. Every app is checked on the VM with scripted keys.
XPUI_OUT = build/xpui/riscv32im-unknown-none-elf/release
# XPUI_LOCKED=--locked (CI) builds exactly the xpui commits in the committed
# apps/xpui/Cargo.lock, the ones the screen goldens were drawn with, and fails
# if a Cargo.toml changed without its lockfile. Only the xpui workspaces have a
# committed lockfile; sdk/rust has no dependencies and none.
XPUI_LOCKED ?=
xpui-build: $(GEN)
cd apps/xpui && $(RUST_SDK) build --release --target-dir ../../build/xpui
cd apps/xpui && $(RUST_SDK) build $(XPUI_LOCKED) --release --target-dir ../../build/xpui

$(XPUI_APPS:%=build/%_xpui.bin): build/%_xpui.bin: xpui-build
$(RISCV)objcopy -O binary $(XPUI_OUT)/$*_xpui $@
Expand All @@ -202,8 +211,28 @@ xpui: $(XPUI_APPS:%=build/%_xpui.bin) build/dessen
printf nnc | build/dessen build/home_xpui.bin | grep -q 'launch reader /books/neuromancer.epub'
build/dessen build/home_xpui.bin </dev/null | grep -q '37%'
$(call readstats_check,build/readstats_xpui.bin)
@$(MAKE) --no-print-directory xpui-screens xpui-unit
@echo "xpui apps: PASS"

# The safety net for changing the xpui apps' screens (tests/xpui/README.md):
# every walk in tests/xpui/*.scenarios, at three screen sizes, drawn with real
# fonts and compared with its committed picture and element positions (1 px of
# tolerance) and checked against the screen standards the app declares; and
# the apps' pure logic, unit-tested on the host. After a deliberate change,
# look at build/screen-diffs/, then `make xpui-bless`. `make xpui-standards`
# lists what each app still breaks of the screen standards.
# APP=nook runs (or blesses) one app's walks only.
XPUI_SCENARIOS = $(wildcard tests/xpui/*.scenarios)
XPUI_ONLY = $(if $(APP),--only $(APP)_xpui)
xpui-screens: $(XPUI_APPS:%=build/%_xpui.bin) build/dessen
@python3 tools/screen_test.py $(XPUI_ONLY) $(XPUI_SCENARIOS)
xpui-bless: $(XPUI_APPS:%=build/%_xpui.bin) build/dessen
@python3 tools/screen_test.py --update $(XPUI_ONLY) $(XPUI_SCENARIOS)
xpui-standards: $(XPUI_APPS:%=build/%_xpui.bin) build/dessen
@python3 tools/screen_test.py --standards $(XPUI_SCENARIOS)
xpui-unit:
cd tests/xpui/unit && $(RUST_SDK) test $(XPUI_LOCKED) --target-dir ../../../build/xpui-unit

# The reading-stats checks, for a build of it ($(1)): the cards from a generated
# session log (tools/readstats_fixture.py), the empty state, an import from
# CrossPoint Sync, and launching from the book card and an app icon. Run for
Expand Down Expand Up @@ -257,4 +286,4 @@ zig: build/hello_zig.bin build/dessen
clean:
rm -rf build

.PHONY: all test sd sync sync-accept size rust rust-check rust-sdk xpui xpui-build xpui-sizes xpui-peaks zig clean
.PHONY: all test sd sync sync-accept size rust rust-check rust-sdk xpui xpui-build xpui-sizes xpui-peaks xpui-screens xpui-bless xpui-standards xpui-unit zig clean
Loading
Loading