Propagate the docstring gate entry guard fix so an unresolvable entry cannot pass the gate

Merged
UN
4mo ago
+98-39

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: isMainInvocation now propagates realpathSync
    errors instead of catching them and returning false. The JSDoc is updated to
    document the new @throws contract and the rationale.
  • test/docstring-gate.test.ts: the test asserting false for an unresolvable
    argv[1] is replaced with one asserting assert.throws(..., /ENOENT/).

Verification

  • npm test — 249 tests pass
  • npm run docstring — exits 0, prints the "N file(s), N declaration(s)" line
  • Manual check: isMainInvocation(["node","/nonexistent/x.ts"],"file:///x")
    throws ENOENT (printed "GOOD: threw ENOENT")

pm item

pm-github-wb4q

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] and import.meta.url with realpathSync before comparing, so --preserve-symlinks* cannot cause a silent skip.
    • Tests cover a symlinked moduleUrl; use process.execPath and assert error.code === "ENOENT" for an unresolvable entry; clarify a test comment.