Skip to content

fix(observability-langfuse): stabilize flaky package-missing test#872

Merged
EmersonBraun merged 3 commits into
mainfrom
fix/langfuse-test-flake
May 19, 2026
Merged

fix(observability-langfuse): stabilize flaky package-missing test#872
EmersonBraun merged 3 commits into
mainfrom
fix/langfuse-test-flake

Conversation

@EmersonBraun
Copy link
Copy Markdown
Collaborator

Problem

Lint, Test, Build fails intermittently on packages/observability-langfuse/tests/langfuse.test.ts:

FAIL  langfuse observer > does not emit traces and warns when langfuse package is missing
AssertionError: expected 1 to be +0

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 on main.

Cause

beforeEach registers vi.doMock('langfuse', { Langfuse: FakeLangfuse }). The "package missing" test then registers vi.doMock('langfuse', () => ({})) and re-imports ../src/langfuse. When a module graph from an earlier test (bound to FakeLangfuse) is still cached, the import resolves the wrong mock, a trace gets captured, and expect(captured.traces.length).toBe(0) fails.

Fix

vi.resetModules() before the empty doMock, 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.

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.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agentskit-doc Ignored Ignored Preview May 19, 2026 9:06pm

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).
@EmersonBraun EmersonBraun merged commit 354aa16 into main May 19, 2026
12 checks passed
@EmersonBraun EmersonBraun deleted the fix/langfuse-test-flake branch May 19, 2026 21:10
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