You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(live-activity): stop a leaked title refresh from failing the excerpt test - #1792
testChatViewModelSuppressesLiveActivityResponseExcerptsByDefault sometimes failed in CI with "/api/session" is not equal to "/api/chat/start". The request came from the test that runs just before it.
Cause.testChatViewModelRunEndTriggerCoversFailedAndCompletedRunsButNotStoppedOnes emits done and then streamEnd. That path (ChatStreamCoordinator.finishStream → refreshCompletedResponseTitleIfNeeded) starts an /api/session title refresh, and nothing awaits it. LiveActivityURLProtocol.handler is one static shared by every test in the file. So when the URL loading thread reached startLoading after the next test had installed its handler, the leaked request went to the excerpt test's strict handler. A slow CI host widens that window; the failing run took about 7 s. The excerpt test's own view model never requests /api/session: it emits no done, and its chat/start succeeds, so neither the title-refresh path nor the error-recovery paths run. Two other tests with strict handlers, testStreamEndWithoutDone… and testFollowupMessage…, also run right after tests that issue /api/session, so they had the same exposure.
Fix (test-only).LiveActivityURLProtocol.makeSession() gives each test's URLSession its own owner header, and startLoading serves only requests from the session the current test created. A request left over from an earlier test now fails with badServerResponse, which the title refresh already ignores. All 11 call sites use the helper, so the whole file is covered. No app code changed, and no request the app makes is hidden from its own test.
How it was tested
Reproduced first: a temporary change, not committed, made the protocol hold the /api/session load until the next test had installed its handler. On master that fails with the exact CI error (LiveActivityTests.swift:360: XCTAssertEqual failed: ("Optional("/api/session")") is not equal to ("Optional("/api/chat/start")")). With this fix plus the same temporary change, both tests pass.
scripts/test-sim CDCCCF6B-ED3F-4599-B932-FCBD7726D3C2 --only HermesMobileTests/LiveActivityTests --repeat 20: PASS. All 44 tests ran 20 times (-run-tests-until-failure) with 0 failures.
python3 ci/check_comments.py, python3 ci/check_test_waits.py, and python3 -m unittest discover -s ci -p 'test_*.py': all pass.
Checklist
Local validation passes using scripts/test-sim <assigned-simulator-udid> with the tests required by AGENTS.md § Verifying; the selection and results are recorded above
New/changed Codable models decode tolerantly (optionals for fields the server might add or rename) (n/a, none changed)
No new third-party dependencies (the list in AGENTS.md is locked)
No invented API endpoints or JSON shapes (verified against upstream source or a running server) (n/a, test-only)
Made by Claude Opus 5.5 (claude-opus-5-5) running in Claude Code, via T3 Code.
Improved isolation and consistency in automated lifecycle tests by ensuring simulated network requests are handled only by the session that created them. Requests without a matching session are now rejected, reducing cross-test interference and making test results more reliable. These changes affect test behavior only and do not change app functionality.
…erpt test
A completed run fires an unawaited /api/session title refresh. When it
loaded after the next test installed its handler, it tripped that
test's strict path assertion. Each test's URLSession now carries an
owner header, and the protocol serves only the current test's session.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
Live Activity lifecycle tests now use LiveActivityURLProtocol.makeSession(). The helper assigns each session a UUID owner header. The protocol handles a request only when its owner matches the stored owner and a handler exists.
makeSession() assigns a UUID owner header to each session. startLoading() checks the request owner and handler, and rejects unmatched requests with URLError(.badServerResponse).
Live Activity test session migration HermesMobileTests/LiveActivityTests.swift
Live Activity tests create their API client sessions through LiveActivityURLProtocol.makeSession().
This change only affects test infrastructure. It stops a leaked title-refresh request from an earlier test from failing a later test. It has no production impact and is ready to merge.
Security architecture risk: Minimal · up to b27cb
The change rejects requests left over from earlier tests without changing application behavior. No introduced or worsened risk affecting security, rollback, or production ownership guarantees was established.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the change (a test-only fix that stops a leaked title refresh from failing the excerpt test). The changeset adds a per-test session owner header and a guarded URL protocol in LiveActiv…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the change (a test-only fix that stops a leaked title refresh from failing the excerpt test). The changeset adds a per-test session owner header and a guarded URL protocol in LiveActivityTests, which targets that same race. The title uses the conventional type(scope) prefix and is specific and concise, so it passes.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between 44d252c and b27cbd8.
Files selected for processing: 1
HermesMobileTests/LiveActivityTests.swift
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Reviewing files that changed from the base of the PR and between d35a0fc and 44d252c.
Files selected for processing: 1
HermesMobileTests/LiveActivityTests.swift
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
No issue: a maintainer-approved flake fix.
What changed
testChatViewModelSuppressesLiveActivityResponseExcerptsByDefaultsometimes failed in CI with"/api/session" is not equal to "/api/chat/start". The request came from the test that runs just before it.Cause.
testChatViewModelRunEndTriggerCoversFailedAndCompletedRunsButNotStoppedOnesemitsdoneand thenstreamEnd. That path (ChatStreamCoordinator.finishStream→refreshCompletedResponseTitleIfNeeded) starts an/api/sessiontitle refresh, and nothing awaits it.LiveActivityURLProtocol.handleris one static shared by every test in the file. So when the URL loading thread reachedstartLoadingafter the next test had installed its handler, the leaked request went to the excerpt test's strict handler. A slow CI host widens that window; the failing run took about 7 s. The excerpt test's own view model never requests/api/session: it emits nodone, and itschat/startsucceeds, so neither the title-refresh path nor the error-recovery paths run. Two other tests with strict handlers,testStreamEndWithoutDone…andtestFollowupMessage…, also run right after tests that issue/api/session, so they had the same exposure.Fix (test-only).
LiveActivityURLProtocol.makeSession()gives each test'sURLSessionits own owner header, andstartLoadingserves only requests from the session the current test created. A request left over from an earlier test now fails withbadServerResponse, which the title refresh already ignores. All 11 call sites use the helper, so the whole file is covered. No app code changed, and no request the app makes is hidden from its own test.How it was tested
/api/sessionload until the next test had installed its handler. Onmasterthat fails with the exact CI error (LiveActivityTests.swift:360: XCTAssertEqual failed: ("Optional("/api/session")") is not equal to ("Optional("/api/chat/start")")). With this fix plus the same temporary change, both tests pass.scripts/test-sim CDCCCF6B-ED3F-4599-B932-FCBD7726D3C2 --only HermesMobileTests/LiveActivityTests --repeat 20: PASS. All 44 tests ran 20 times (-run-tests-until-failure) with 0 failures.python3 ci/check_comments.py,python3 ci/check_test_waits.py, andpython3 -m unittest discover -s ci -p 'test_*.py': all pass.Checklist
scripts/test-sim <assigned-simulator-udid>with the tests required byAGENTS.md§ Verifying; the selection and results are recorded aboveCodablemodels decode tolerantly (optionals for fields the server might add or rename) (n/a, none changed)AGENTS.mdis locked)Made by Claude Opus 5.5 (
claude-opus-5-5) running in Claude Code, via T3 Code.🤖 Generated with Claude Code
Summary by CodeRabbit