fix: the API emitted undefined optionals as null, and the UI couldn't decode them (v0.3.2)
CI / publish (push) Successful in 22s
CI / build (push) Successful in 34s

`Schema.optional(X)` means `X | undefined`, and the plain Schema encoder omits a
present-but-undefined key — but the HttpApi RESPONSE path serialises it as
`null`, which `X | undefined` then refuses when the client decodes it. Two
user-visible failures shipped in 0.3.1:

  - GET /api/status on a never-synced host returned `"lastSync":null`, so the
    Overview page could not decode its own status — i.e. every fresh install
    until the first successful sync.
  - POST /api/detect on a box with any emulator installed returned
    `"contested":null` / `"appId":null`, so the Emulators page's Detect button
    could not decode the result. It only looked fine because a value that has
    round-tripped through cache.json has those keys ABSENT rather than present
    -and-undefined, and absent keys encode correctly.

Nothing on this wire is `undefined` any more. EngineStatus.{lastSync,lastReport,
detectedAt} are `Schema.NullOr` and the engine sends explicit nulls. The
DetectedEmulator fields use `Schema.optional(Schema.NullOr(...))` instead —
tolerant of absent, undefined and null — because they also live in cache.json,
and requiring them would fail the whole cache decode on upgrade and silently
discard every art verdict.

plugin/test/wire.test.ts pins it: it drives the real makeApi handler stack
through toWebHandler and decodes the bytes with the shared contract schemas.
Against the old schema all five of its assertions fail; a unit test of either
side in isolation passes while the product is broken.

Also: the SSE feed now emits the current status on subscribe rather than only on
the next engine transition, so a freshly-opened console page is correct
immediately instead of stale until something happens.
This commit is contained in:
2026-07-20 23:36:01 +02:00
parent d830b7133d
commit 94f18e38b4
8 changed files with 233 additions and 22 deletions
+12 -4
View File
@@ -212,9 +212,10 @@ function make(): Effect.Effect<
os,
artProvider: selectArtProvider(config)?.id ?? null,
syncing: engineStatus.syncing,
lastSync: engineStatus.lastSync,
lastReport: engineStatus.lastReport,
detectedAt: c.detect?.at,
// Explicit nulls, never undefined — see the trap note in contract/domain.ts.
lastSync: engineStatus.lastSync ?? null,
lastReport: engineStatus.lastReport ?? null,
detectedAt: c.detect?.at ?? null,
paths: {
dir: nodePath.dirname(cfg.path),
config: cfg.path,
@@ -228,7 +229,14 @@ function make(): Effect.Effect<
preview: computeWith(false),
detect,
status,
statusChanges: engine.changes.pipe(Stream.mapEffect(() => status)),
// A fresh subscriber gets the CURRENT status immediately, then one frame per
// engine transition — so the console's live view is right the moment it
// connects, rather than stale until the next sync. Each frame is a full
// snapshot, so the sliver between the two stages costs nothing.
statusChanges: Stream.concat(
Stream.fromEffect(status),
engine.changes.pipe(Stream.mapEffect(() => status)),
),
} satisfies RomSyncService;
});
}