Propagate the docstring gate entry guard fix so an unresolvable entry cannot pass the gate
Propagate the docstring gate entry guard fix
Summary
The isMainInvocation guard in scripts/docstring-gate.ts caught realpathSync
errors and returned false. When argv[1] could not be resolved, the top-level
selector called the no-op placeholder instead of main, so npm run docstring
exited 0 having scanned nothing — a mandatory release gate reporting success
without doing its job.
The corrected implementation propagates the realpathSync error. A broken
environment must not silently satisfy a gate; crashing loudly is the safe outcome.
Changes
scripts/docstring-gate.ts:isMainInvocationnow propagatesrealpathSync
errors instead of catching them and returningfalse. The JSDoc is updated to
document the new@throwscontract and the rationale.test/docstring-gate.test.ts: the test assertingfalsefor an unresolvable
argv[1]is replaced with one assertingassert.throws(..., /ENOENT/).
Verification
npm test— 249 tests passnpm run docstring— exits 0, prints the "N file(s), N declaration(s)" line- Manual check:
isMainInvocation(["node","/nonexistent/x.ts"],"file:///x")
throwsENOENT(printed "GOOD: threw ENOENT")
pm item
Summary by Sourcery
Ensure the docstring gate process entry guard fails loudly when the entry script path cannot be resolved so a broken environment cannot silently skip the mandatory docstring check.
Bug Fixes:
- Change the isMainInvocation check to propagate realpathSync failures when argv[1] is unresolvable, preventing the docstring gate from exiting successfully without scanning.
- Update the docstring gate tests to assert that an unresolvable entry path throws an error instead of returning false.
Enhancements:
- Simplify isMainInvocation to compare the resolved entry path as a file URL directly against import.meta.url and clarify its JSDoc around safety and failure behavior.
Documentation:
- Document the corrected behavior and rationale of the docstring gate entry guard in JSDoc and add a corresponding entry to the changelog.
Chores:
- Record the associated product management item in the pm history and issues directories.
Summary by cubic
Fixes the docstring gate to fail loudly on missing or invalid entry paths and makes the main check robust to symlink-preserving runtime flags. Clarifies comments and removes an unused pathToFileURL import.
- Bug Fixes
- Canonicalize both
argv[1]andimport.meta.urlwithrealpathSyncbefore comparing, so--preserve-symlinks*cannot cause a silent skip. - Tests cover a symlinked
moduleUrl; useprocess.execPathand asserterror.code === "ENOENT"for an unresolvable entry; clarify a test comment.
- Canonicalize both