Skip to content

test(live-activity): stop a leaked title refresh from failing the excerpt test - #1792

Merged
uzairansaruzi merged 2 commits into
masterfrom
fix/live-activity-test-flake
Nov 20, 2026
Merged

uzairansaruzi merged 2 commits into
masterfrom
fix/live-activity-test-flake

Conversation

@uzairansaruzi

@uzairansaruzi uzairansaruzi commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Linked issue

No issue: a maintainer-approved flake fix.

What changed

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.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • 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>
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Changes: Live Activity test session isolation

Layer / File(s) Summary
Owner-tagged session handling
HermesMobileTests/LiveActivityTests.swift
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().

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · up to b27cb

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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
Recent review info

Run configuration

Commits

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.

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge.

Summary

This test-only change keeps delayed requests from reaching another test’s handler.

  • Live activity tests reject requests from older test sessions.

Reviews (2) · Last reviewed commit: "test(live-activity): lock the mock's han..." · Reviewed by Greptile

The URL loading thread reads both while the next test replaces them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

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.

@uzairansaruzi
uzairansaruzi merged commit a9861b9 into master Nov 20, 2026
5 checks passed
@uzairansaruzi
uzairansaruzi deleted the fix/live-activity-test-flake branch November 20, 2026 20:08
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