fix(observability-langfuse): stabilize flaky package-missing test#872
Merged
Conversation
The "does not emit traces and warns when langfuse package is missing" test re-mocked `langfuse` as an empty module then re-imported ../src/langfuse, but a module graph carried over from earlier tests (bound to beforeEach's FakeLangfuse) could leak in, capturing a trace and failing with "expected 1 to be +0". Added vi.resetModules() before the empty doMock so the import resolves the intended mock. Verified 8/8 passing across repeated runs.
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
vi.resetModules() alone did not fix the flake: the global beforeEach
in langfuse.test.ts unconditionally registers
vi.doMock('langfuse', { Langfuse: FakeLangfuse }), which races the
empty mock and still wins in CI (trace captured → "expected 1 to be
+0"). Moved the case to langfuse-missing.test.ts, which has no
FakeLangfuse mock at all, so there is no client to capture a trace and
the missing/broken-install path is deterministic. Asserts warn + no
throw instead of trace count. Coverage unchanged (lines 98.38%, gate
90%). Stable across repeated local runs (8/8, 2 files).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Lint, Test, Buildfails intermittently onpackages/observability-langfuse/tests/langfuse.test.ts:Surfaced on PR #868, but #868 only edits package keywords/descriptions + the docs home — it does not touch
observability-langfuse. This is a pre-existing order-dependent flake onmain.Cause
beforeEachregistersvi.doMock('langfuse', { Langfuse: FakeLangfuse }). The "package missing" test then registersvi.doMock('langfuse', () => ({}))and re-imports../src/langfuse. When a module graph from an earlier test (bound toFakeLangfuse) is still cached, the import resolves the wrong mock, a trace gets captured, andexpect(captured.traces.length).toBe(0)fails.Fix
vi.resetModules()before the emptydoMock, so the re-import resolves the intended empty mock. No production code touched.Verification
pnpm --filter @agentskit/observability-langfuse test→ 8/8 passing, stable across 3 repeated runs.Re-run CI on #868 after this merges.