Repository navigation
[CI Failure Doctor] CI Failure Doctor: close_older_issues.test.cjs uses Jest instead of Vitest #10895
Description
Activity
- addedbugSomething isn't workingSomething isn't workingjavascriptPull requests that update javascript codePull requests that update javascript code
on Jan 20, 2026 github-actions commented
on Jan 20, 2026 on Jan 20, 2026 – with GitHub ActionsContributorAuthorMore actions🔄 Duplicate Failure - Run #21185331298
This issue has caused another CI failure:
- Run: 21185331298
- Commit: 5f89796
- Trigger: Push to main (PR Add upgrade command combining init and codemods for all workflows #10884 - "Add upgrade command combining init and codemods for all workflows")
- Failed Job:
js(JavaScript tests) - Status: Same root cause -
close_older_issues.test.cjsuses Jest instead of Vitest
🔍 Investigation Findings
Scope Confirmation
I've verified that only one file in the entire test suite uses Jest syntax:
close_older_issues.test.cjsis the only file using@jest/globalsclose_older_issues.test.cjsis the only file usingjest.fn()- All other 60+ test files correctly use Vitest syntax
Correct Pattern (from other test files)
// ✅ CORRECT - Vitest syntax import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"; // Use vi.fn() instead of jest.fn() const mockFunction = vi.fn(); // Use vi.clearAllMocks() instead of jest.clearAllMocks() beforeEach(() => { vi.clearAllMocks(); });
Current Incorrect Pattern
// ❌ INCORRECT - Jest syntax (from close_older_issues.test.cjs) const { describe, it, expect, beforeEach } = require("@jest/globals"); // Wrong - uses jest.fn() global.core = { info: jest.fn(), warning: jest.fn(), error: jest.fn(), }; // Wrong - uses jest.clearAllMocks() beforeEach(() => { jest.clearAllMocks(); });
🛠️ Recommended Fix
Convert
close_older_issues.test.cjsto use Vitest syntax:-
Change import statement:
// From: const { describe, it, expect, beforeEach } = require("@jest/globals"); // To: import { describe, it, expect, beforeEach, vi } from "vitest";
-
Replace all
jest.fn()withvi.fn() -
Replace all
jest.clearAllMocks()withvi.clearAllMocks() -
Replace all
.mockResolvedValue()with.mockResolvedValue()(Vitest compatible) -
Replace all
.mockRejectedValue()with.mockRejectedValue()(Vitest compatible)
🚨 Impact
This bug is blocking all CI runs on the main branch. Every push triggers the same failure, preventing:
- All other CI checks from being meaningful
- Deployment of new features
- Merge of new PRs (if CI is required)
📋 AI Team Self-Improvement Prompt
To prevent this type of failure in the future, add this to AI coding agent instructions:
### JavaScript Testing Framework **CRITICAL**: This codebase uses **Vitest**, NOT Jest. When creating or modifying test files (`*.test.cjs`): - ✅ **ALWAYS use**: `import { describe, it, expect, beforeEach, vi } from "vitest"` - ✅ **ALWAYS use**: `vi.fn()` for mocking functions - ✅ **ALWAYS use**: `vi.clearAllMocks()` for clearing mocks - ❌ **NEVER use**: `@jest/globals`, `jest.fn()`, `jest.clearAllMocks()` - ❌ **NEVER add**: Jest as a dependency in `package.json` **Before committing test changes**: ``````bash make fmt-cjs # Format JavaScript files make test-unit # Run unit tests to verify
Reference any existing test file in
actions/setup/js/*.test.cjsas a template.## 🔗 Related Information - Package.json confirms: `"vitest": "^4.0.10"` (NO Jest dependency) - Test command: `npm test` runs `vitest run --no-file-parallelism` - File was likely added by an AI coding agent unfamiliar with the project's testing framework choice > AI generated by [CI Failure Doctor](https://github.com/githubnext/gh-aw/actions/runs/21185491970)github-actions commented
on Jan 20, 2026 on Jan 20, 2026 – with GitHub ActionsContributorAuthorMore actions🍪 Issue Monster has assigned this to Copilot!
I've identified this issue as a good candidate for automated resolution and assigned it to the Copilot agent.
The Copilot agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
AI generated by Issue Monster
github-actions commented
on Jan 20, 2026 on Jan 20, 2026 – with GitHub ActionsContributorAuthorMore actions🔄 Duplicate Failure Detected - Run #21187161778
This CI run failed with the SAME Jest/Vitest incompatibility issue as originally reported in this issue.
Run Details
- Run: #21187161778
- Commit: a1a2854
- Commit Message: "chore: switch campaign orchestrator to use claude (chore: switch campaign orchestrator to use claude #10900)"
- Timestamp: 2026-01-20 22:04 UTC (approximately 2 hours after this issue was opened)
- Failed Job:
js
Error Details
Identical error as originally reported:
Error: Cannot find module '@jest/globals' Require stack: - /home/runner/work/gh-aw/gh-aw/actions/setup/js/close_older_issues.test.cjs ❯ close_older_issues.test.cjs:3:46Context
This failure occurred as part of a massive PR #10900 that added 330+ files. The PR merged successfully despite this test file still having Jest syntax incompatibility issues.
Additional Failures in Same Run
This run also had 41 additional test failures unrelated to the Jest/Vitest issue:
- 36 validation test failures in
collect_ndjson_output.test.cjs(validation regression - duplicate of closed issue [CI Failure Doctor] JS validation regression after PR #10125 - 43 tests failing #10137) - 2 timeout failures in
safe_outputs_mcp_server_defaults.test.cjs(MCP server branch parameter tests)
See full investigation report:
/tmp/investigation/reports/full-investigation.md(available in workflow artifacts if needed)Impact
Status: Issue persists on main branch
Severity: CRITICAL - blocking all CI runs on main branch
Duration: ~2 hours since issue opened, still not fixedRecommended Fix
Same as originally identified - convert Jest syntax to Vitest:
- const { describe, it, expect, beforeEach } = require("@jest/globals"); + const { describe, it, expect, beforeEach, vi } = require("vitest"); - jest.fn() + vi.fn() - jest.clearAllMocks() + vi.clearAllMocks()
Investigation by CI Failure Doctor
AI generated by CI Failure Doctor
Summary
The CI workflow failed on commit c1c6704 (PR #10882) because the newly added test file
close_older_issues.test.cjsuses Jest test framework syntax (@jest/globalsandjest.fn()) instead of the Vitest framework used throughout the codebase.Failure Details
js(JavaScript tests)Root Cause Analysis
Primary Error
Technical Details
The test file
close_older_issues.test.cjs(334 lines) uses Jest syntax patterns that are incompatible with Vitest:Incorrect imports (Line 3):
Incorrect mocking (Lines 8-10):
Incorrect module loading:
require()instead of ES modulesimportCorrect Patterns Used in Other Test Files
All existing test files use Vitest:
Additional Test Failures
The run also showed 42 other test failures, mostly in
collect_ndjson_output.test.cjsandsafe_outputs_mcp_server_defaults.test.cjs, but these appear to be pre-existing issues unrelated to this specific failure.Recommended Actions
Fix #1: Convert Test File to Vitest (Required)
Replace Jest syntax with Vitest in
close_older_issues.test.cjs:Changes needed:
Update imports (line 3):
Update module imports (line 4):
Update mocking (lines 8-10):
Update all mock functions (lines 18-28 and throughout):
Update beforeEach (line 17):
Fix #2: Run Local Tests Before Committing
Always run the full test suite locally:
This would have caught the error immediately.
Prevention Strategies
1. Add Pre-commit Validation
Update AGENTS.md to emphasize test validation:
Example - Correct test file structure:
3. Template Test File
Create a template test file in the repository:
# actions/setup/js/TEMPLATE.test.cjsAI Team Self-Improvement
Instructions to add to AGENTS.md:
Incorrect patterns to avoid:
Pre-commit checklist for JavaScript tests:
vitest, NOT@jest/globalsvi.fn()for mocks, NOTjest.fn()import, NOTrequire()npm testlocally before committingnpm testInvestigation completed: 2026-01-20T20:00:00Z
Pattern stored:
/tmp/gh-aw/cache-memory/investigations/2026-01-20-21185259940.jsonError Pattern:
MODULE_NOT_FOUND_JEST_GLOBALSSeverity: High (blocks CI)
Complexity: Low (straightforward find-replace fix)
Automated Fix: Possible (systematic replacement of Jest with Vitest syntax)