Back to The Bathyal Post
SOURCE / PINNED RELEASE

Made of little things.

The Bathyal Post

Release
fa6ce530b9f3…
Author-recorded commit
b255b3c9fd49…
License
LICENSE
Author’s source reference
nostr://npub182jczunncwe0jn6frpqwq3e0qjws7yqqnc3auccqv9nte2dnd63scjm4rf/wss%3A%2F%2Fgit.napplet.soy%2F/n-55c50b9a042

Archive hash verified: 03cf62191e7476c5…. The source-to-build association is the author’s claim; it has not been independently rebuilt.

.claude/skills/napplet-test/SKILL.md
---
name: napplet-test
description: Use to verify a napplet before publishing - build, run protocol conformance with napplet-conformance (real Chromium, reference shell), interpret failures, audit the OUTBOX-first boundaries and forbidden browser-authority surfaces, confirm the single-file artifact, run the applet UI checks (visual direction, four frame sizes, chosen theme policy, minimum notice), scenario smoke tests, Paja preview, and CI wiring. Run after napplet-build, before shipping.
---

# Testing a Napplet

Conformance proves the build speaks NIP-5D inside a real `sandbox="allow-scripts"` iframe driven by a reference shell, catching malformed envelopes, manifest problems, boot failures, and forbidden browser-authority references locally. Truth: NIP-5D (<https://github.com/nostr-protocol/nips/pull/2303>) and the NAPs (<https://github.com/napplet/naps>). A check that fails a spec-faithful napplet but passes only this toolchain is a tooling bug — flag it; do not work around it.

## Step 1 — Build, then test the build

```bash
pnpm verify              # template guidance test + type-check + single-file build
pnpm test:conformance    # napplet-conformance ./dist → exit 0 conformant, 1 non-conformant, 2 usage/runtime error
npx napplet-conformance ./dist        # package-manager agnostic
napplet-conformance --ui ./dist       # live visual report
```

Conformance runs against `./dist` (prefers `dist/index.html`). Never test source.

## Step 2 — Interpret failures (fix the napplet, not the check)

- **Boot failure** — the runtime did not inject `window.napplet` before app code ran, or a top-level throw blocked boot.
- **Malformed envelope** — a message that is not a valid `{ type: "domain.action", … }` for its NAP; re-check the SDK call arguments.
- **Manifest problem** — check the standalone HTML SHA-256 `x`, nonempty plain-text content and required `R` domains. Only named events carry `d`; `O` is optional. Older `path`/aggregate manifests remain readable. See docs/napplet-manifest.md; do not rewrite signed events or weaken host verification.
- **Forbidden global** — the bundle references `fetch`, `localStorage`, `window.nostr`, `XMLHttpRequest`, `WebSocket`, … (static scan; unreachable references flag too). Replace with `resource` / `storage` / `outbox`, or prove and document a tooling false positive.

## Step 3 — Boundary audit

| Check | Expected |
| --- | --- |
| Normal social reads / publishes | `outbox`, `common`, `lists`, `count`, `dm` — not default `relay` |
| Any `relay.subscribe` / `relay.publish` | A comment or spec note naming the relay-local escape hatch |
| Signing / encryption | No `window.nostr`, keys, local signing, app-owned encryption |
| Relay routing | No NIP-65 resolver, relay pool, WebSocket client, fanout policy in the napplet |
| Network and media bytes | No `fetch`, XHR, WebSocket, external `<img src>`; `resource` instead |
| Persistence | No `localStorage`, IndexedDB, cookies; `storage` instead |
| Optional-domain gating | `window.napplet?.domain` after injection; no `shell.ready()` / `shell.supports()` / service probes |
| `requires` | Bare domain names, hard requirements only; matches the design spec |

```bash
grep -RInE "fetch\\s*\\(|XMLHttpRequest|WebSocket|localStorage|sessionStorage|indexedDB|document\\.cookie|window\\.nostr|<img[^>]+src=['\\\"]?https?:|<script[^>]+src=['\\\"]?https?:|<link[^>]+href=['\\\"]?https?:" src dist index.html
```

Any hit in authored or bundled napplet code is removed or explained as a tooling false positive before shipping.

## Step 4 — Artifact

`dist/index.html` is one self-contained file: inline JS, folded assets, no external `<script src>` (opaque-origin `srcdoc` has nothing to fetch). `artifactMode: 'single-file'` produces it; verify by inspecting the file, not by trusting the config.

## Step 5 — Visual and responsive checks (napplet-ui)

Use the actual hosted frame at 200×160, 320×560, 900×600 and full screen, plus
the touch checks in docs/napplet-mobile.md. Check the main interaction, UI/HUD,
legibility, focus, reduced motion, state feedback and any minimum-size notice.
Large frames should have intentional composition or useful additional workspace.

Compare with the project brief using docs/napplet-visual-design.md: remove unintended
demo styling. Switch host light/dark and remove the optional theme domain.
App-owned colors remain intact; host-matched surfaces update consistently; hybrids
change only chosen regions. Inspect CSS and rendered game/artwork colors. Record
frames, theme policy, interactions and gaps, including actual cover/clip review.

## Step 6 — Scenario smoke tests

- **Signed-out:** `identity.getPublicKey()` returns `""`; publish / list / DM actions degrade with an inline state.
- **OUTBOX options:** only current fields — `getEvent`: `author`, `relays`, `timeoutMs`; `query` / `subscribe`: `authors`, `relays`, `limit`, `timeoutMs`; `publish`: `relays`, `toOutbox`, `toInboxes`. No `strategy`, subscribe `live`, publish `timeoutMs`, or `outbox.eose`.
- **Optional domain absent:** remove it from the mock runtime; the affordance hides or falls back, nothing else breaks.
- **Theme change:** emit a theme change; verify the chosen policy. App-owned art stays intact, opted-in UI updates coherently, and gameplay/state does not reset.
- **Escape hatch:** if `relay` is used, exercise the relay-local behavior and teardown.
- **Teardown:** subscriptions, key bindings, and object URLs are released when the view goes away.

## Step 7 — Runtime preview

```bash
napplet paja -- pnpm vite --host 127.0.0.1
```

Report the Paja URL. If `napplet`, Kehto, or Paja is not installed, report the exact missing prerequisite and leave the manual runtime check open; never present the raw Vite URL as a napplet preview.

## Step 8 — CI

```yaml
- run: pnpm build
- run: npx napplet-conformance ./dist   # non-zero exit fails the job
```

Cache Playwright's Chromium. Green conformance + a clean boundary audit + a self-contained single-file build + the four-frame UI check = ready to publish.

## soyLI manifest metadata

Before publication or changing capabilities/discovery, read docs/napplet-manifest.md. Save metadata in napplet.json; the publisher creates the signed event. Choose optional archetypes in napplet.json for what the napplet does (game for games). Consult https://archetypes.napplet.run/ for observed spellings; new names are valid. Keep descriptive topics separate. For opt-in public rooms follow docs/napplet-backend.md, retain manual entry and never advertise private rooms or guest keys. Advertise only implemented intents and optional integrations, and verify their absent-domain fallbacks.

## soyLI controller input (NAP-GAMEPAD)

Read this before adding, porting or testing USB/Bluetooth gamepad support. Read
docs/napplet-controllers.md for the full guide and use docs/examples/gamepad.ts.

**Protocol.** Controllers follow the NAP-GAMEPAD draft,
https://github.com/napplet/naps/pull/130 (draft revision 0b28f77e3dfa0f07dd7c0f9d61a7090ee99f3a5e). The upstream shim supplies the standard binding over the private NIP-5D port. Controllers are browser-wide devices, so the soyLI
runtime is their only native reader. It denies the native API to napplet frames
(Permissions-Policy `gamepad 'none'`) and pushes `gamepad.state` snapshots to
the napplet that holds input focus. Other napplets see connected pads with zero
axes/buttons and `timestamp` 0.

**How it is patched in.** The host prelude runs before your scripts. Where the
native `navigator.getGamepads()` exists but is denied, it replaces only
`Navigator.prototype.getGamepads` with a reader of the latest snapshot and sends
one `gamepad.subscribe`. Pads keep native `Gamepad`/`GamepadButton` prototypes,
in slot order with `null` gaps. `gamepadconnected`/`gamepaddisconnected` arrive
as `GamepadEvent`s through listeners and `on…` handlers. A host `blocked` state
throws `SecurityError`; `unavailable` returns empty slots. Where native access is
allowed or there is no Gamepad API, the native API is untouched; the standard binding subscribes on first use. The shim also exposes the
optional `window.napplet.gamepad`: `getGamepads()`, `available`, `focused` and
`onChange(callback) → { close }`. It is installed independently of native API replacement.

**Build rules.**
- Write ordinary Gamepad API code: poll `navigator.getGamepads()` once per
  `requestAnimationFrame`, or use `createGamepadInput` from the bundled helper.
  The same code runs on hosts with native access. Feature-detect
  `window.napplet?.gamepad` only for its `focused`/`available` state.
- Gamepad is optional. Do not add `gamepad` (or SERIAL) to `requires`; keep
  complete keyboard and pointer/touch controls. Use NAP-KEYS (`keys`) for named
  keyboard actions when the game has them.
- Treat `focused: false` as idle input: pause or freeze controller-driven
  actions; do not treat the neutral snapshot as release events. Do not fire a
  press for a button already held when focus returns; the helper waits for
  `focused: true` for you.
- Route players by `pad.index`, never array position. Handle disconnect by
  clearing that player's input. Do not use `pad.id` as an identity.
- Expect about one host frame of extra latency and no rumble
  (`vibrationActuator` is `null`). `event.isTrusted` is `false`; do not gate on it.
  Do not rely on own-property shape, `JSON.stringify(pad)` or `[native code]`.
- Show players that the napplet must be clicked/focused to receive controller
  input, for example on the title or pause screen.

**Verify.** Use the Controller tester in soyli dev, then click the napplet to give
it input. Check movement, edges (one press per press), pause on focus loss, no
phantom press on refocus, disconnect/reconnect and keyboard/touch fallback.
Synthetic or simulated input and soyli check are not hardware tests: report
physical-controller and Safari/Firefox coverage separately.