Skip to content

test(desktop): enroll BYOK fingerprints so paywall/agent tests match #11454's contract - #12277

Merged
Git-on-my-level merged 3 commits into
mainfrom
fix/byok-paywall-test-enrollment
Aug 27, 2026
Merged

test(desktop): enroll BYOK fingerprints so paywall/agent tests match #11454's contract#12277
Git-on-my-level merged 3 commits into
mainfrom
fix/byok-paywall-test-enrollment

Conversation

@Git-on-my-level

@Git-on-my-level Git-on-my-level commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Test-only fix. BYOKPaywallTests and AgentRuntimeProcessTests have been failing on main since #11454 merged (#12276) — 7 tests still set up BYOK state the old way (raw UserDefaults keys, no enrollment) against a contract #11454 already changed and already tests correctly elsewhere: APIKeyService.isByokActive now requires the selected provider's current key to match a fingerprint persisted via persistEnrolledFingerprints (written by activateBYOK reconciliation after BYOKValidator succeeds), not just raw key presence.

This PR transcribes that already-stated, already-merged contract into the tests that never learned about it. No Sources/ change — every fix completes test setup, none weakens or removes an assertion.

  • BYOKPaywallTests.swift: adds a private enroll(_:) helper that persists the fingerprint of a provider's current key, then calls it in the 5 failing tests (testByokActiveRequiresSelectedLLMKey, testBuildHeadersAttachSelectedLLMByokKey, testBuildHeadersSuppressesOnlyInvalidByokHeader, testPaywallFlagSuppressedWhenByokActive, testRemovingDeepgramKeyLeavesSelectedLLMByokActive).
  • AgentRuntimeProcessTests.swift: enrolls the selected provider in the 2 failing tests (testUsableByokEnvironmentIncludesAllKeysWhenAllProvidersAreUsable, testUsableByokEnvironmentSuppressesAllKeysWhenOneProviderIsKnownBad); both existing defer blocks now also save/restore the enrollment map.
  • Carries the shared chore(desktop): unbreak the local Swift build and formatter gate on Xcode 26 and chore(desktop): dodge the Xcode 16.4 SILGen segfault on alertPresenter commits (tracked in main's Desktop Swift CI has read green since 08-26 18:24Z while the alertPresenter SILGen crash from d49f978512 sits unfixed #12275) so this branch can actually compile and reach test execution on the CI-pinned Xcode 16.4 — otherwise this PR's own contract job would hit the same masked crash it's trying to fix visibility for.

Two sharp edges (why this isn't a mechanical find-and-replace)

  • testByokActiveRequiresSelectedLLMKey needs two enrollments: setAllBYOKKeys() at line 43 (of the original file) rewrites openrouter's key to "sk-test-openrouter", which changes its fingerprint and invalidates the enrollment from line 40. Re-enroll after the rewrite.
  • testPaywallFlagSuppressedWhenByokActive and testRemovingDeepgramKeyLeavesSelectedLLMByokActive now set .byokLLMProvider explicitly instead of relying on legacy first-match inference — with every provider's key present via setAllBYOKKeys(), inference could silently resolve to a provider we didn't enroll.

What I deliberately did not touch

testBuildHeadersCanExplicitlyExcludeByokKeys and testLowLevelTransportDefaultsToExcludingByokKeys currently pass vacuously: neither enrolls a provider, so isByokActive is already false and headers come back nil regardless of includeBYOK. They're not asserting what their names claim. Flagging for whoever owns BYOK rather than fixing here — giving them real coverage means deciding what "explicitly excluded while actually active" should assert, which is a product call, not a transcription of an existing contract.

Context

This PR is on the critical path for #12267, #12269, #12271 (unrelated telemetry-fix PRs currently blocked by this same regression) and for main's own CI health.

Verification

  • Local: git push pre-push gate ran a full local Swift build (Build complete) plus the repo's manifest/format/lint checks — all passed.
  • CI: this PR's own Desktop Swift Static & Test Contracts run is the real verification for the two fixed suites; linking once green.

Failure-Class: none

Review in cubic

Git-on-my-level and others added 3 commits August 26, 2026 22:52
…code 26

Two pre-existing blockers on `main` that fail the pre-push gate for any
desktop PR when the local toolchain is newer than the pinned Xcode 16.4:

- `AppState+Permissions.swift` has swift-format drift, and
  `desktop-swift-format-lint` runs `lint-scope` over every first-party
  Swift file. Formatter output only.
- `AppState+Transcription.swift:848` captures `alertPresenter` implicitly
  in an escaping closure. Swift 6.2 (Xcode 26.x) rejects this; Xcode 16.4
  accepts it. Writing `self.` is what the diagnostic asks for and is the
  same strong capture the implicit form already produced, so behavior is
  unchanged on both toolchains.

Failure-Class: none
Every desktop CI lane (Static & Test Contracts, Release Compile, Build &
Tests aggregate) has been red since main's d49f978 landed
`var alertPresenter: any DesktopAlertPresenting = AppKitSheetAlertPresenter()`:
the pinned Xcode 16.4 toolchain segfaults (signal 11) in silgen
emitStoredPropertyInitialization while lowering that existential-erasure
default initializer. Reproduced on main itself (d49f978, fb67ca9,
50cf064 all failed; d06e220 passed only because its desktop jobs were
path-filter skipped) and on unrelated PRs (#12269, #12272), so this is not
specific to this branch.

Move the initializer from the stored-property default position into
init(). Identical semantics on both toolchains - AppState is @mainactor
with a single designated init, and the alert tests overwrite the presenter
immediately after construction. Xcode 26.6 parses, swift-format lint
passes, changelog gate passes.

Failure-Class: none
…11454's contract

#11454 replaced the old "all keys present in UserDefaults" check for
isByokActive with a stricter one: the selected provider's *current* key
must match a fingerprint already persisted via
APIKeyService.persistEnrolledFingerprints (set by activateBYOK
reconciliation after BYOKValidator confirms the key). Seven tests across
BYOKPaywallTests and AgentRuntimeProcessTests still set up state the old
way — raw UserDefaults keys, no enrollment — and started failing the
moment CI could actually reach them (#12276): main's own contract job
caught this on #11454 before merge, but a compiler crash landed 8
minutes earlier (tracked separately in #12275) blocked every real
desktop Swift test run afterward, so it went unnoticed.

This is a test-only fix that transcribes #11454's already-stated and
already-tested enrollment contract into the tests that never learned
about it; no Sources change.

- BYOKPaywallTests: add `enroll(_:)`, calling
  `persistEnrolledFingerprints` with the SHA-256 fingerprint of the
  provider's current key, exactly as `activateBYOK` reconciliation would
  after successful validation. Five tests were asserting on raw key
  presence: testByokActiveRequiresSelectedLLMKey (needs a *second*
  enrollment after setAllBYOKKeys() rewrites openrouter's key and
  invalidates the first fingerprint), testBuildHeadersAttachSelectedLLMByokKey,
  testBuildHeadersSuppressesOnlyInvalidByokHeader,
  testPaywallFlagSuppressedWhenByokActive, and
  testRemovingDeepgramKeyLeavesSelectedLLMByokActive (both of the last
  two now select the provider explicitly rather than relying on legacy
  first-match inference, since every provider's key is set and the test
  must enroll the same provider it selects).
- AgentRuntimeProcessTests: enroll the selected provider in
  testUsableByokEnvironmentIncludesAllKeysWhenAllProvidersAreUsable and
  testUsableByokEnvironmentSuppressesAllKeysWhenOneProviderIsKnownBad —
  usableBYOKEnvironment() gates on isByokActive before the
  CredentialHealthManager suppression these tests exercise. Both
  existing `defer` blocks now also save/restore the enrollment map.

Not touched: testBuildHeadersCanExplicitlyExcludeByokKeys and
testLowLevelTransportDefaultsToExcludingByokKeys currently pass
vacuously — neither enrolls a provider, so isByokActive is false and
headers come back nil regardless of includeBYOK. Flagging for whoever
owns BYOK rather than fixing here, since giving them real coverage
means deciding what "excluded despite being active" should assert, and
that's a product call, not a mechanical transcription of #11454.

No assertions were weakened or removed — every fix completes test setup
to match the stated contract. testPaywallFlagSuppressedWhenByokActive is
the only coverage that an enrolled BYOK user is never paywalled; it was
made to pass by enrolling correctly, not by loosening what it checks.

Fixes: #12276
Failure-Class: none
@Git-on-my-level
Git-on-my-level merged commit 2bbb2ba into main Aug 27, 2026
31 checks passed
@Git-on-my-level
Git-on-my-level deleted the fix/byok-paywall-test-enrollment branch August 27, 2026 03:49
sujeito-operator added a commit to sujeito-operator/omi that referenced this pull request Aug 28, 2026
…itly-escaping

The production fix this class was born alongside -- writing the capture explicitly at
AppState+Transcription.swift:848 -- reached main in BasedHardware#12277, so this branch rebases to
the registry entry alone. evidence_prs now cites BasedHardware#12277 rather than being empty:
the class has a merged PR evidencing it.
sujeito-operator added a commit to sujeito-operator/omi that referenced this pull request Aug 28, 2026
… the caller

Rebased onto main. The desktop Swift lanes that held this approved PR were red on
main itself; BasedHardware#12277 fixed both causes, so this rebase is what turns them green.

The checks-manifest edit is re-applied to main's text rather than overwriting it,
so the legacy-memory-surface-ratchet entry main added since the merge base survives.
One prose fix in the reason field: BasedHardware#12194 is still open, so it proposes the composite
action rather than having moved it.
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