Skip to content

Resolve the entry-point path so the CLI is not a silent no-op - #104

Merged
portdeveloper merged 1 commit into
portdeveloper:mainfrom
rustemar:fix/fetch-model-entrypoint-guard
Sep 22, 2026
Merged

portdeveloper merged 1 commit into
portdeveloper:mainfrom
rustemar:fix/fetch-model-entrypoint-guard

Conversation

@rustemar

Copy link
Copy Markdown
Contributor

Closes #102

The entry-point guard compared new URL(import.meta.url).pathname against process.argv[1]. A URL pathname is percent-encoded and always POSIX-shaped, while argv holds the raw platform path, so the two only agree on a plain POSIX path with no spaces. They disagree on a path containing a space (%20 on one side, a literal space on the other), when the script is reached through a symlink (Node resolves import.meta.url to the realpath, argv keeps the link), and on every Windows checkout (/C:/… against C:\…). Since the whole CLI sits inside if (isEntryPoint), a mismatch made npm run fetch-model print nothing, create no models/ directory and exit 0.

The guard now compares resolved filesystem paths:

const isEntryPoint =
  Boolean(process.argv[1]) && realpathSync(process.argv[1]) === fileURLToPath(import.meta.url);

fileURLToPath decodes the escape and emits a native path on Windows, realpathSync collapses the symlink, and the Boolean guard keeps node -e and the REPL — where argv[1] is undefined — from throwing inside realpathSync. This is the form src/mcp.mjs, src/policy.mjs and src/addressBook.mjs already use; fetch-model.mjs was the last one on the URL comparison. Importing the module still leaves the guard false, which the rest of the suite depends on. GGUFDownloader, the resume logic and the MD5 check are untouched.

Three tests in test/fetch-model.test.mjs, all spawning the script for real because the mismatch is invisible to an in-process import:

  • missing URL argument prints the usage banner and exits 1;
  • the script still runs from a directory whose name has a space — it imports only node: builtins, so a copy runs standalone, and this reproduces on POSIX exactly what Windows does;
  • the script still runs when invoked through a symlink (skipped on an EPERM, for Windows without developer mode).

Tested: node --test test/fetch-model.test.mjs — 27 pass, 0 fail. Against the guard as it stands on main the space and symlink tests fail, and the missing-URL test is the one that turns windows-latest red on the matrix ci.yml already runs; I checked both directions by putting the old guard back and restoring it. The rest of the suite is unchanged by this PR — the 16 unrelated failures in my sandbox are ERR_MODULE_NOT_FOUND: ethers, identical with and without the change, since I did not run npm install for the QVAC prebuild.

The guard compared a percent-encoded URL pathname against a raw argv path, so
it never matched on Windows, on a path holding a space, or through a symlink,
and every side effect in the script sits behind it.

@portdeveloper portdeveloper left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, thanks

@portdeveloper
portdeveloper merged commit b150bb9 into portdeveloper:main Sep 22, 2026
3 checks passed
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.

npm run fetch-model exits 0 without downloading on Windows, and on any path containing a space

2 participants