Skip to content

fix(cli): resolve entrypoint mismatch under symlinked paths - #17

Open
imbajin wants to merge 2 commits into
xqy2006:mainfrom
imbajin:fix/symlink-cli-entrypoint
Open

imbajin wants to merge 2 commits into
xqy2006:mainfrom
imbajin:fix/symlink-cli-entrypoint

Conversation

@imbajin

@imbajin imbajin commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Note

Symlinked CLI paths now resolve to the same file before entrypoint detection, so doctor executes instead of silently exiting.

image

Running guard.mjs through a symlink could exit successfully without doing anything. For example, on macOS the CLI path can contain /tmp, while Node resolves the module to /private/tmp. The old entrypoint check compared these path strings, skipped main(), and produced no output.

isDirectCall() keeps the direct-path fast path, then compares realpathSync() results when the strings differ. Symlinked invocations now reach main(); doctor returns its JSON result.

Changes

  • Accept file URLs or filesystem paths; return false for missing arguments or path-resolution errors.
  • Cover direct paths, symlinks, chained symlinks, and missing paths in helper tests.
  • Exercise doctor through symlinks and chained symlinks, including --preserve-symlinks.

Validation

  • npm test in codex-plugin/modeltrace-guard: 172 passed, 0 failed, 0 skipped on macOS with Node.js v22.21.1 (code commit 80b800e).
  • Windows behavior and --preserve-symlinks-main were not validated in this run.

@imbajin
imbajin force-pushed the fix/symlink-cli-entrypoint branch from ce881e2 to e2c631d Compare September 23, 2026 14:02
In environments where execution paths or script directories involve symbolic links
(e.g. macOS /tmp -> /private/tmp, /var -> /private/var, or symlinked plugin directories),
path.resolve(process.argv[1]) does not match fileURLToPath(import.meta.url), causing
CLI commands to silently exit.

Changes:
1. Encapsulate robust isDirectCall(entryUrl, argv1 = process.argv[1]) supporting file URLs, URL objects, and raw file paths with null safety.
2. Fast-path check with path.resolve, falling back to realpathSync to resolve canonical physical paths across nested symlinks and --preserve-symlinks.
3. Added comprehensive test coverage for symlink execution, nested symlinks, and cross-platform error safety.
@imbajin
imbajin force-pushed the fix/symlink-cli-entrypoint branch from e2c631d to 80b800e Compare September 23, 2026 14:02
@imbajin imbajin changed the title fix: 解决软链接路径下 CLI 入口判断失败导致静默退出的问题 fix(cli): resolve entrypoint mismatch under symlinked paths Sep 23, 2026
@imbajin
imbajin force-pushed the fix/symlink-cli-entrypoint branch from 0e5d6d6 to 80b800e Compare September 23, 2026 14:10

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant