Skip to content

Open an LED port that appears after its controller connected (#148) - #153

Merged
Skeyelab merged 2 commits into
mainfrom
led-cache-148
Nov 16, 2026
Merged

Skeyelab merged 2 commits into
mainfrom
led-cache-148

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Closes #148

Summary

 devicesChanged()
   for each controller
     if it has a source
       if the source is gone → disconnect
+      else if it has no LED output → openOutput(…); if opened → repaintLEDs()
     else if connect(index) → start()

Coordinator.connect's output choice now lives in openOutput(_:for:profile:), so the late-port retry uses exactly the same rules: the chosen port, then the same-name port, then the hint, and never an excluded port.

What #148 turned out to be

The issue was filed as "an LED write before the output opens is cached as sent". Testing it at the Coordinator seam found the reachable bug one step earlier: a controller whose output port appears after its input never got that port at all, because devicesChanged only reconnected controllers with no source. With the retry in place, every path that opens an output repaints with a cleared cache (start, reconnect, and now a late port). So a write cached while the output was closed is repainted, and no test can observe the cache ordering any more. I left it unchanged rather than add untested code.

Found along the way: a test shape that can't fail

#expect((x?.y ?? []).contains(z)) passes when x is nil. Swift Testing expands the contains call, and the optional chain short-circuits it. I checked six shapes on a nil subject. Only this one passes; x?.y == v, x?.y ?? [] == v and (x?.y ?? []).last == v all fail correctly.

There was exactly one such expectation, in excludedPortNeverGetsLEDs from #144. It's now bound to a local first, and it still passes. The test that first exposed the shape went red properly once its expectation was bound to a local.

Evidence

  • New test lateOutputPortIsOpened: the controls input is present, with no destination yet, and Playing 1 arrives. Then the controls destination appears, devicesChanged runs, and Playing 1 arrives again. Expect Play at 127 on ch1 on the controls port.
    • Before the fix: red. The port was never opened, and the outputs map was empty.
    • After: green.
  • Totals: 358 Core and 81 Presentation tests pass, and the Release build succeeds.

Merge Danger

Door: two-way. Blast Radius: device changes.

  • A connected controller with no LED output now gets one when a matching port appears, and it repaints once.
  • Pitch pickup isn't re-armed, since only the LEDs repaint.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCgWWsoPKWUFiYf5pcC5B5

…ort, and its LEDs paint into it (#148)

devicesChanged only reconnected controllers with no source, so an output
port that appeared after its input was never opened. Also binds the one
#expect((x?.y ?? []).contains(z)) in the tests to a local: Swift Testing
passes that shape when x is nil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgWWsoPKWUFiYf5pcC5B5
@Skeyelab
Skeyelab merged commit c30fe56 into main Nov 16, 2026
3 checks passed
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.

An LED write made while the output is closed is cached as sent, so it is never resent

1 participant