refactor(multi-folder-scan): return ExitCode instead of calling process.exit()#822
refactor(multi-folder-scan): return ExitCode instead of calling process.exit()#822luojiyin1987 wants to merge 5 commits into
Conversation
sonukapoor
left a comment
There was a problem hiding this comment.
Thanks for this - moving process.exit() out of handleMultiFolderScan and into the call site is the right call. It makes the function composable and testable, and the mock change from mockImplementation(() => process.exit(0)) to mockResolvedValue(0) is much cleaner.
Two things before merging: the --fix and --sarif/--cdx unsupported-feature paths return EXIT_FINDINGS (1), but exit code 1 in this codebase means "findings were found above threshold." These paths never evaluate any findings - they bail early because the feature isn't available yet. That's EXIT_ERROR (3) per the contract in src/types.ts. A CI script testing exitCode === 1 would get a false positive here.
The return after process.exit(exitCode) in index.ts is also now unreachable dead code - small cleanup.
Minor: mockResolvedValue(EXIT_OK) would be more intentional than the raw 0, but not a blocker.
|
Thanks, fixed. The unsupported multi-folder --fix / --sarif / --cdx paths now return EXIT_ERROR instead of EXIT_FINDINGS, since they bail out before evaluating findings. I also removed the unreachable return after process.exit(exitCode), and changed the integration test mock to use EXIT_OK instead of a raw 0. No new test file was added; I only added coverage to the existing multi-folder scan test file. |
sonukapoor
left a comment
There was a problem hiding this comment.
This addresses everything - EXIT_ERROR for the unsupported-feature paths is the right call, the dead return is gone, the test mock uses EXIT_OK, and the new handleMultiFolderScan tests cover all the EXIT_ERROR cases cleanly. The audit log close path is now correct too. Nice work.
What
Replace 4
process.exit()calls inhandleMultiFolderScanwithreturn ExitCode.This fixes the multi-folder audit-log close path by returning the exit code to the caller, so
src/index.tscan close the audit log before exiting.Why
handleMultiFolderScantestable without mockingprocess.exitChanges
src/scan/multi-folder-scan.ts: ReturnEXIT_OK/EXIT_FINDINGSinstead of callingprocess.exit(), change return type toPromise<ExitCode>src/index.ts: Capture returned exit code and callprocess.exit()at the call siteTesting
Closes #821