Skip to content

metrics-collection-orchestrator.cjs process.exit(1) at module load kills entire Jest run #3342

Description

@eleshar

Problem

.github/scripts/workflows/metrics-collection-orchestrator.cjs calls main() at module top-level (line 258), and main() calls process.exit(1) on failure (line 207/260). Its own test file (.github/scripts/workflows/__tests__/metrics-collection-orchestrator.test.js) require()s this module directly, so importing it for testing runs the whole orchestrator for real and can call process.exit(1) mid-test-run.

In this environment (no network access to whatever the collector calls), every collection attempt fails (✅ Successful: 0/1, ❌ Failed: 1/1), triggering process.exit(1) — which kills the entire Jest process outright, not just this one test file. Any npm run test run that reaches this file never produces a final summary.

Impact

Blocks getting a reliable full-suite pass/fail count locally. Discovered while verifying PR #3341 (issue #3340) — excluding this one file was required to get a clean Test Suites: 29 failed, 177 passed, 206 total summary.

Suggested fix

Guard the module so main() only runs when the file is executed directly, not when required:

if (require.main === module) {
  main().catch((error) => {
    console.error("Fatal error:", error);
    process.exit(1);
  });
}

This is the standard Node pattern for CLI scripts that are also required as test fixtures, and matches how other agent scripts in this repo are already structured.

Also seen (separate, in the same investigation)

scripts/agents/issues.agent.cjs:13const __filename = __filename || process.argv[1]; throws SyntaxError: Identifier '__filename' has already been declared (Jest treats the file as CommonJS, where __filename is already a module-scope binding). One of the 29 suites still failing after #3341.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions