Skip to content

fix: replace force-unwraps in host command paths - #82

Merged
yashranaway merged 1 commit into
mainfrom
t3code/fix-force-unwraps
Aug 5, 2026
Merged

fix: replace force-unwraps in host command paths#82
yashranaway merged 1 commit into
mainfrom
t3code/fix-force-unwraps

Conversation

@yashranaway

Copy link
Copy Markdown
Collaborator

Closes #13.

visual compare read its two artifact names as request.parameters["before"]!.stringValue! on both hosts. That is safe only while CommandRequest.validate() has run first — and these are long-lived host processes, so a trap does not fail one command, it kills the browser, every session, and any active recording.

Both sites now guard and answer MISSING_PARAMETER. Also replaced a nil-check-then-force-unwrap in Diagnostics.swift with a plain if let.

Honest scope

This is defence in depth, not a live bug fix. The validator does require both parameters (Protocol.swift:364-370, required: true), so no request reaching the host today can trip these unwraps. The reason to fix them anyway is the asymmetry: the cost of the guard is two lines, the cost of being wrong later is the whole host.

Rather than add an unreachable test, ProtocolTests now asserts the property the guards depend on — that visual.compare rejects a request missing before or after. If someone relaxes the validator, a test fails instead of the guards quietly becoming load-bearing.

Per AGENTS.md, remaining force-unwraps in host paths are tracked, not precedent — this clears the known set.

Closes #13.

visual compare read its two artifact names with request.parameters[...]!
.stringValue! on both hosts. That is safe only while CommandRequest.validate()
has run first, and these hosts are long-lived: a trap kills the browser, every
session, and any active recording, so the failure mode is out of proportion to
the mistake. Both sites now guard and answer MISSING_PARAMETER.

Also replaces a nil-check-then-force-unwrap in Diagnostics with a plain
if-let. Same behaviour, no trap to reason about.

The validator does require both parameters, so these guards are defence in
depth rather than a live bug fix. ProtocolTests now asserts that requirement
directly, so relaxing the validator fails a test instead of quietly making the
guards load-bearing.
@yashranaway
yashranaway requested a review from SarthakWade August 5, 2026 19:51
@yashranaway
yashranaway merged commit 27d2eb6 into main Aug 5, 2026
7 checks passed
@yashranaway
yashranaway deleted the t3code/fix-force-unwraps branch August 5, 2026 19:53
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.

A2 — Force-unwraps in a long-lived host

1 participant