Skip to content

Commit 2bd5472

Browse files
committed
feature-296-bugbot-autofix: Refactor CLI and GitHub Action execution logic to prevent auto-running during tests by checking for JEST_WORKER_ID. Export program instance in CLI modules for better accessibility. Enhance test coverage by adding scenarios for error handling and command execution, ensuring robust logging and proper management of exit codes. Update type definitions for clarity in CLI and GitHub Action modules.
1 parent 1e1d6d6 commit 2bd5472

14 files changed

Lines changed: 239 additions & 13 deletions

File tree

build/cli/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47245,6 +47245,7 @@ var __importStar = (this && this.__importStar) || (function () {
4724547245
};
4724647246
})();
4724747247
Object.defineProperty(exports, "__esModule", ({ value: true }));
47248+
exports.program = void 0;
4724847249
const child_process_1 = __nccwpck_require__(2081);
4724947250
const commander_1 = __nccwpck_require__(4379);
4725047251
const dotenv = __importStar(__nccwpck_require__(2437));
@@ -47258,6 +47259,7 @@ const ai_repository_1 = __nccwpck_require__(8307);
4725847259
// Load environment variables from .env file
4725947260
dotenv.config();
4726047261
const program = new commander_1.Command();
47262+
exports.program = program;
4726147263
// Function to get git repository info
4726247264
function getGitInfo() {
4726347265
try {
@@ -47665,7 +47667,9 @@ program
4766547667
];
4766647668
await (0, local_action_1.runLocalAction)(params);
4766747669
});
47668-
program.parse(process.argv);
47670+
if (typeof process.env.JEST_WORKER_ID === 'undefined') {
47671+
program.parse(process.argv);
47672+
}
4766947673

4767047674

4767147675
/***/ }),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for CLI commands.
3+
* Mocks execSync (getGitInfo), runLocalAction, IssueRepository, AiRepository.
4+
*/
5+
export {};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for runGitHubAction.
3+
* Mocks @actions/core, ProjectRepository, mainRun, and finish flow.
4+
*/
5+
export {};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for runLocalAction.
3+
* Mocks getActionInputsWithDefaults, ProjectRepository, mainRun, chalk, boxen.
4+
*/
5+
export {};

build/cli/src/cli.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
export {};
1+
import { Command } from 'commander';
2+
declare const program: Command;
3+
export { program };

build/github_action/index.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42766,13 +42766,16 @@ function setFirstErrorIfExists(results) {
4276642766
}
4276742767
}
4276842768
}
42769-
runGitHubAction()
42770-
.then(() => process.exit(0))
42771-
.catch((err) => {
42772-
(0, logger_1.logError)(err);
42773-
core.setFailed(err instanceof Error ? err.message : String(err));
42774-
process.exit(1);
42775-
});
42769+
// Only auto-run when executed as the action entry (not when imported by tests)
42770+
if (typeof process.env.JEST_WORKER_ID === 'undefined') {
42771+
runGitHubAction()
42772+
.then(() => process.exit(0))
42773+
.catch((err) => {
42774+
(0, logger_1.logError)(err);
42775+
core.setFailed(err instanceof Error ? err.message : String(err));
42776+
process.exit(1);
42777+
});
42778+
}
4277642779

4277742780

4277842781
/***/ }),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for CLI commands.
3+
* Mocks execSync (getGitInfo), runLocalAction, IssueRepository, AiRepository.
4+
*/
5+
export {};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for runGitHubAction.
3+
* Mocks @actions/core, ProjectRepository, mainRun, and finish flow.
4+
*/
5+
export {};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Unit tests for runLocalAction.
3+
* Mocks getActionInputsWithDefaults, ProjectRepository, mainRun, chalk, boxen.
4+
*/
5+
export {};

build/github_action/src/cli.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
#!/usr/bin/env node
2-
export {};
2+
import { Command } from 'commander';
3+
declare const program: Command;
4+
export { program };

0 commit comments

Comments
 (0)