Skip to content

fix(tests): make the PilotTests target compile and run - #15

Merged
TeoSlayer merged 1 commit into
mainfrom
sec/findings-sdk-swift
Jul 26, 2026
Merged

fix(tests): make the PilotTests target compile and run#15
TeoSlayer merged 1 commit into
mainfrom
sec/findings-sdk-swift

Conversation

@TeoSlayer

Copy link
Copy Markdown
Contributor

Problem

The PilotTests target did not compile, so swift test was red and 0 tests ran.

Six compile errors, three distinct causes:

  1. Non-exhaustive switches over Pilot.Error.dataTooLarge was added to the enum but three switch statements in the tests were never updated (StartErrorPathTests.swift:84, :135, IntegrationTests.swift:73).
  2. testPortTruncationDetection was at file scope, after the closing brace of DatagramTests — XCTest could never have discovered it even if it compiled.
  3. Mixed-width NSNumber comparisonsXCTAssertEqual(n.uint16Value, n.uint64Value) binds both arguments to a single generic parameter T, so UInt16 vs UInt64 is a hard error. (The same expression compiles in Pilot.swift only because the stdlib has heterogeneous == for BinaryInteger.)

Changes

  • Added the missing .dataTooLarge cases in all three switches; extended ErrorTests to cover its description and case-distinctness.
  • Moved testPortTruncationDetection inside DatagramTests and pointed it at the real decode path instead of re-implementing the check inline. Pilot.decodeDatagram(_:) is split out of receive() (which now just calls it) and ports are validated by range-checking a single signed 64-bit value. NSNumber.uint16Value wraps, so 70000 read back as 4464 and -1 as 65535; both are now rejected with .invalidResponse. Added decode tests for missing/mistyped fields and the raw-byte-array / empty-data fallbacks.
  • Added internal Pilot.attach(driverHandle:start:) so MockDaemonTests can drive the public send() / receive() wrapper over the mock daemon's SendTo→RecvFrom loopback, not just the raw C symbols. stop() now tears down the embedded daemon only for instances that started it. New testWrapperSendReceiveRoundtrip actually calls receive() and asserts the round-tripped payload and ports.
  • Build the mock daemon with GOWORK=off. It is a nested Go module, and a go.work higher up the tree made go build fail with "main module does not contain package …", which silently skipped all 14 MockDaemonTests.

Verification

swift build   # Build complete
swift test    # Executed 49 tests, with 6 tests skipped and 0 failures

The 6 skips are the opt-in daemon-backed tests that require PILOT_INTEGRATION=1 and a reachable registry. All 14 MockDaemonTests now run (previously all skipped).

🤖 Generated with Claude Code

The test target failed to build, so `swift test` reported 0 tests run:

  * Three `switch pe { ... }` over `Pilot.Error` predated the
    `.dataTooLarge` case and were no longer exhaustive
    (StartErrorPathTests x2, IntegrationTests x1).
  * `testPortTruncationDetection` sat after the closing brace of
    `DatagramTests`, at file scope, and compared `NSNumber.uint16Value`
    against `NSNumber.uint64Value` inside `XCTAssertEqual` — which binds
    both arguments to one generic parameter and cannot mix UInt16/UInt64.

Changes:

  * Add the missing `.dataTooLarge` cases; extend ErrorTests to cover its
    description and case-distinctness.
  * Move `testPortTruncationDetection` inside `DatagramTests` and point it
    at the real decode path instead of re-implementing the check: split
    `Pilot.decodeDatagram(_:)` out of `receive()` and validate ports by
    range-checking a single signed 64-bit value. `uint16Value` wraps, so
    70000 previously read back as 4464 and -1 as 65535; both are now
    rejected with `.invalidResponse`.
  * Add `Pilot.attach(driverHandle:start:)` (internal) so MockDaemonTests
    can drive the public `send()` / `receive()` wrapper over the mock
    daemon's SendTo->RecvFrom loopback rather than only the C symbols.
    `stop()` closes the embedded daemon only for instances that started it.
  * Build the mock daemon with GOWORK=off — it is a nested module, and a
    go.work higher up the tree made `go build` fail, silently skipping all
    14 MockDaemonTests.

swift test: 49 tests, 6 skipped (opt-in PILOT_INTEGRATION), 0 failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@TeoSlayer
TeoSlayer merged commit 3b18f53 into main Jul 26, 2026
4 checks passed
@TeoSlayer
TeoSlayer deleted the sec/findings-sdk-swift branch July 26, 2026 14:12
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.

2 participants