Skip to content

fix(tests): resolve 5 cross-file test isolation failures#2841

Merged
code-yeongyu merged 1 commit intodevfrom
fix/model-fallback-test-isolation
Mar 26, 2026
Merged

fix(tests): resolve 5 cross-file test isolation failures#2841
code-yeongyu merged 1 commit intodevfrom
fix/model-fallback-test-isolation

Conversation

@code-yeongyu
Copy link
Copy Markdown
Owner

Summary

Fixes 5 test failures that only appear in the full bun test suite (4456 tests across 424 files) but pass individually.

Root Causes & Fixes

1-2. model-fallback hook (2 failures)

Cause: fallback-retry-handler.test.ts mocked readProviderModelsCache with mockReturnValue (permanent) and used mock.module without mock.restore(). The mock leaked to the model-fallback hook test, overriding its own mock with stale connected-provider state.

Fix:

  • Added afterAll(() => mock.restore()) to fallback-retry-handler test
  • Changed mockReturnValuemockReturnValueOnce for provider mocks
  • Added _resetForTesting() to model-fallback hook (clears pendingModelFallbacks, lastToastKey, sessionFallbackChains)
  • Added selectFallbackProvider mock to hook test for full isolation
  • Global test-setup.ts now resets model-fallback state in beforeEach

3. opencode-config-dir Windows test (1 failure)

Cause: path.join('C:\\...', name) on macOS prepends CWD because C:\\ isn't an absolute path on POSIX. process.platform = 'win32' override doesn't change path.join behavior.

Fix: Use win32.join in both implementation (getTauriConfigDir) and test assertion.

4-5. system-loaded-version symlink (2 failures)

Cause: mkdtempSync returns /var/folders/... but realpathSync returns /private/var/folders/... on macOS (/var/private/var symlink).

Fix: Use resolveSymlink from file-utils (which already handles this normalization) instead of raw realpathSync.

Verification

bun test  # 4456 pass, 0 fail (ran twice to confirm stability)
bunx tsc --noEmit  # clean

- model-fallback hook: mock selectFallbackProvider and add _resetForTesting()
  to test-setup.ts to clear module-level state between files
- fallback-retry-handler: add afterAll(mock.restore) and use mockReturnValueOnce
  to prevent connected-providers mock leaking to subsequent test files
- opencode-config-dir: use win32.join for Windows APPDATA path construction
  so tests pass on macOS (path.join uses POSIX semantics regardless of
  process.platform override)
- system-loaded-version: use resolveSymlink from file-utils instead of
  realpathSync to handle macOS /var -> /private/var symlink consistently

All 4456 tests pass (0 failures) on full bun test suite.
@code-yeongyu code-yeongyu merged commit 23df6bd into dev Mar 26, 2026
5 checks passed
@code-yeongyu code-yeongyu deleted the fix/model-fallback-test-isolation branch March 26, 2026 00:31
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes test isolation and cross-platform path issues using standard cleanup patterns. Addresses macOS symlink and Windows path normalization in tests. Low risk, improves suite stability.

@code-yeongyu code-yeongyu restored the fix/model-fallback-test-isolation branch March 26, 2026 00:54
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