Skip to content

refactor: derive replay metadata platforms from the canonical selectors#899

Merged
thymikee merged 1 commit into
mainfrom
refactor/replay-metadata-platforms
Jun 27, 2026
Merged

refactor: derive replay metadata platforms from the canonical selectors#899
thymikee merged 1 commit into
mainfrom
refactor/replay-metadata-platforms

Conversation

@thymikee

Copy link
Copy Markdown
Member

Follow-up to thymikee's review on #895: the replay parser hand-restated the leaf-platform allow-list a 4th time, and the type/runtime didn't agree.

Problem

src/replay/script.ts defined type ReplayScriptPlatform = Exclude<PlatformSelector, 'apple'> (which still INCLUDES 'web') while REPLAY_METADATA_PLATFORMS was a hardcoded Set(['ios','android','macos','linux']) (omits 'web'). So context platform=web lines were silently dropped even though the type permitted web — a type/runtime mismatch and a copy of the allow-list that can drift.

Fix (behaviorless)

  • Narrow the type so web's exclusion is explicit: Exclude<PlatformSelector, 'apple' | 'web'>.
  • Derive the runtime set from the already-exported canonical PLATFORM_SELECTORS (src/utils/device.ts) instead of hardcoding. This yields exactly ['ios','macos','android','linux'] today and auto-includes any future leaf platform except web.
  • Comment that replay metadata context platform= lines do not support web.

Web stays dropped exactly as before — now intentionally, type-safe, and derived from a single source. Adding web support remains a separate feature decision and is out of scope here. This branch does not depend on #895 (it derives from PLATFORM_SELECTORS, already exported on main).

Tests

Extended src/replay/__tests__/script.test.ts:

  • REPLAY_METADATA_PLATFORMS equals exactly the non-web leaf platforms.
  • every concrete leaf platform (ios/android/macos/linux) is accepted in a context line.
  • a context platform=web line is dropped (behaviorless).

Verified: tsc --noEmit, oxfmt, oxlint --deny-warnings, and vitest run replay (153 passed) all green.

@github-actions

Copy link
Copy Markdown

Size Report

Metric Base Current Diff
JS raw 1.4 MB 1.4 MB +49 B
JS gzip 445.2 kB 445.2 kB +31 B
npm tarball 583.3 kB 583.3 kB +12 B
npm unpacked 2.0 MB 2.0 MB +49 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 25.9 ms 26.1 ms +0.2 ms
CLI --help 46.1 ms 45.9 ms -0.2 ms

Top changed chunks:

Chunk Raw diff Gzip diff
dist/src/4428.js +49 B +31 B

@thymikee

Copy link
Copy Markdown
Member Author

Reviewed — merge-ready. ✅

Verified

  • PLATFORM_SELECTORS.filter(p => p !== 'apple' && p !== 'web') derives exactly {ios, macos, android, linux} — byte-identical to the old hardcoded set, so this is genuinely behaviorless today (checked by hand, not just CI).
  • Type now matches runtime: Exclude<PlatformSelector, 'apple' | 'web'> drops the stale 'web' member the old Exclude<…, 'apple'> left in. The .has() guard at script.ts:83 still rejects web at runtime, so context platform=web stays dropped — confirmed by the new test.
  • Single source of truth: no more 4th copy of the leaf-platform allow-list. The type guard in the .filter is sound.
  • No accidental widening of supported runtime behavior. Tests are accurate (set membership, all 4 leaves accepted, web dropped). Typecheck/Unit/Coverage/Web Platform Smoke all green.

Residual risk (non-blocking, both out of scope per the description)

  1. The derive flips the default for future leaf platforms from opt-in to opt-out: any new entry added to PLATFORM_SELECTORS is auto-accepted as a replay metadata platform unless it's hand-excluded like web. That's the documented intent, just worth keeping in mind when the next platform lands.
  2. Pre-existing round-trip asymmetry (not introduced here): the write path at script.ts:461 emits context platform=${session.device.platform}, which can be web, but read-back drops it → metadata.platform undefined for web replay scripts. This is exactly the gap the PR scopes out for a separate web-support decision.

@thymikee thymikee merged commit fc81c9e into main Jun 27, 2026
20 checks passed
@thymikee thymikee deleted the refactor/replay-metadata-platforms branch June 27, 2026 12:02
@github-actions

Copy link
Copy Markdown
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-27 12:02 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant