Repository navigation
test: isolate GeoIP and replay event-trigger tests from other SDK instances - #899
Conversation
…tances - GeoIP tests use a token per test and record only their own /flags and /batch requests, and no longer wipe the shared Application Support folder. - Replay event-trigger tests use a token per test, so another suite saving remote config under the shared test token can't replace the seeded recording config. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
[Medium risk] Test isolation refactored to use unique tokens per test. Remove the shared-token Reviews (1) · Last reviewed commit: "test: isolate GeoIP and replay event-tri..." |
| // REPRO: another suite's SDK saves its remote config (no event triggers) under the shared test token | ||
| PostHogStorage(PostHogConfig(projectToken: "test_project_token")) | ||
| .setDictionary(forKey: .remoteConfig, contents: ["sessionRecording": ["endpoint": "/s/"]]) |
There was a problem hiding this comment.
Replay tests overwrite shared config
getSut() now overwrites .remoteConfig under the shared test_project_token in every replay test. If this lands between the seed and read in loadsCachedRemoteConfig(), that test reads the replay dictionary instead of ["foo": "bar"] and fails. .serialized does not serialize unrelated suites.
Remove this temporary REPRO write, or give both SDK instances in a dedicated regression test their own tokens.
| // REPRO: another suite's SDK saves its remote config (no event triggers) under the shared test token | |
| PostHogStorage(PostHogConfig(projectToken: "test_project_token")) | |
| .setDictionary(forKey: .remoteConfig, contents: ["sessionRecording": ["endpoint": "/s/"]]) |
Knowledge Base Used: Restore iOS test coverage and harden test assertions
Prompt To Fix With AI
This is a comment left during a code review.
Path: PostHogTests/PostHogSessionReplayEventTriggersTest.swift
Line: 54-56
Comment:
**Replay tests overwrite shared config**
`getSut()` now overwrites `.remoteConfig` under the shared `test_project_token` in every replay test. If this lands between the seed and read in `loadsCachedRemoteConfig()`, that test reads the replay dictionary instead of `["foo": "bar"]` and fails. `.serialized` does not serialize unrelated suites.
Remove this temporary `REPRO` write, or give both SDK instances in a dedicated regression test their own tokens.
```suggestion
```
**Knowledge Base Used:** [Restore iOS test coverage and harden test assertions](https://app.greptile.com/posthog-org-19734/-/custom-context/knowledge-base/posthog/posthog-ios/-/reverts/rollback_854-20260929-ios-test-coverage-and-flaky-assertions-a8c1692.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Good catch, that was the temporary repro write and shouldn't have been committed. Removed in 38e3fde.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
💡 Motivation and Context
Two tests fail intermittently on
test-ios-simulator, for example on #897 (run 1, run 2):Both have the same cause as #885: another test's SDK instance is still running.
localhost:9001, and OHHTTPStubs routes each/flagsrequest to whicheverMockPostHogServeris current. The test checksserver.flagsRequests.last, which can be another instance's request sent with GeoIP enabled.test_project_token, then starts the SDK. Storage is kept per token, so any other suite saving remote config under that same token in between replaces the event triggers, and replay starts as active.Changes
MockPostHogServer: a newflagsProjectToken, the same filter asbatchProjectTokenbut for/flags.batchProjectTokenandflagsProjectTokento it.init()no longer deletes the whole Application Support folder. That folder holds every suite's storage, and the suite doesn't need it cleared because its tokens are unique.Other suites are unchanged.
This is test-only. SDK behavior and public API are unchanged.
💚 How did you test it?
I reproduced both failures deterministically with a temporary change that simulates the other SDK instance:
main/flagsafter the GeoIP test's own requestgeoip_disable → falsetest_project_tokenduring replay test setupisActive() → truein 6 testsWithout the repros:
make testpasses (935 Swift Testing + 174 XCTest tests).make lintreports no new warnings.📝 Checklist
If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
🤖 Generated with Claude Code