fix(cli): make the CLI entrypoint run on Windows (normalize argv[1] separators)#3
fix(cli): make the CLI entrypoint run on Windows (normalize argv[1] separators)#3oceanlongnion wants to merge 4 commits into
Conversation
…on Windows On Windows, process.argv[1] is an absolute path with backslashes (e.g. C:\...\dist\cli\index.js) for every invocation style (direct ode, npm .cmd/.ps1 global shims). The guard process.argv[1].endsWith(cli/index.js) uses a forward slash, so it never matched and the CLI silently exited 0 without parsing any command. Normalize backslashes to forward slashes before the check so code2wiki <cmd> works on Windows as well as POSIX. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Context for prioritization: I hit this while running Worth flagging because it's a 100% failure on Windows via the documented global-install path — the CLI appears "installed and on PATH" ( |
…point Refactor the bottom-of-file main-entry guard into an exported pure function isCliEntrypoint(argv1) so the Windows-path-separator bug is directly unit-testable, and add src/cli/entrypoint.test.ts: - Unit tests pin the exact regression: a backslash argv[1] (C:\...\dist\cli\index.js) must be recognized as the entrypoint, plus POSIX paths, the .ts (tsx) variant, undefined, and non-matches. - Subprocess smoke tests run the real CLI via node --import tsx and assert --version / --help produce output, proving the guard is wired to process.argv[1] end to end (argv[1] is a backslash path on Windows, so these would fail under the old forward-slash-only guard). No behavior change to the runtime guard. 8 new tests pass; full suite unchanged otherwise (same 8 pre-existing, unrelated Windows-CRLF snapshot/drift failures). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Added the regression test I offered above (commit 81a2d50). I extracted the main-entry guard into an exported pure function
8 new tests, all green; the rest of the suite is unchanged (same pre-existing CRLF-related snapshot/drift failures on |
loadConfig read the config with Node's "utf-8" decoder, which preserves a leading BOM (U+FEFF), then handed it to JSON.parse, which rejects it with an opaque "Unexpected token" SyntaxError. Any editor or shell that writes "UTF-8 with BOM" tripped this -- notably Windows PowerShell 5.1's Set-Content -Encoding UTF8, which always prepends a BOM -- so an otherwise valid config failed to load for list/generate/etc. Strip a single leading BOM before parsing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…on=length When an Azure deployment returns a non-empty but truncated body (partial JSON cut off at the completion budget -- common with reasoning deployments like gpt-5-mini whose invisible chain-of-thought consumes the budget), the empty-content guard did not fire and parseJsonObject threw the generic "LLM did not return valid JSON" with no hint that the fix is a larger budget. Catch that case when finish_reason=length and rethrow with guidance to raise AZURE_OPENAI_MAX_COMPLETION_TOKENS, use a smaller file, or a non-reasoning deployment. Malformed JSON with any other finish_reason still surfaces the generic parse error. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pushed two more Windows/real-run robustness fixes surfaced while doing a real generation pass on a large ColdFusion module:
Verification: typecheck + build clean; full suite 1412 passed (+4 new), same 8 pre-existing unrelated Windows-CRLF snapshot/drift failures. Also verified the BOM fix end-to-end by running the built CLI against a real BOM-encoded config (previously crashed at parse, now loads). |
Summary
On Windows,
code2wiki <cmd>silently exits0without doing anything — no output, no error.--versionand--helpprint nothing;generate/preview/listall no-op. This affects every Windows invocation path:node dist/cli/index.js …, the npm-installedcode2wiki.cmdshim, and thecode2wiki.ps1shim.Root cause
The main-entry guard at the bottom of
src/cli/index.tscomparesprocess.argv[1]against a forward-slash suffix:On Windows, Node sets
process.argv[1]to an absolute path with backslashes for every invocation style, e.g.C:\Users\me\...\dist\cli\index.js. SoendsWith("cli/index.js")is alwaysfalse,parseAsyncnever runs, and the process exits cleanly having done nothing. On POSIX it happens to work because the separators are already/.Verified on Windows (Node 22):
Fix
Extract the guard into a small exported pure function
isCliEntrypoint(argv1)that normalizes separators to/before the suffix check, so it fires on both Windows and POSIX. Pulling it out of the top-levelifalso makes the exact bug directly unit-testable.getProgram()and all command wiring are unchanged.Regression test
Added
src/cli/entrypoint.test.tsso this can't silently break again:argv[1](C:\...\dist\cli\index.js) must be recognized as the entrypoint — plus POSIX paths, the.ts(tsx) variant,undefined, and non-matches (.json/.jsx, unrelated scripts). These fail under the old forward-slash-only guard.node --import tsx src/cli/index.tsand assert--version→0.1.0and--helprenders the command list. This proves the guard is wired toprocess.argv[1]end to end; on Windowsargv[1]is a backslash path, so these would fail under the old guard.Verification
Rebuilt (
npm run build) and reinstalled globally (npm install -g .) on Windows:code2wiki --version→ (empty, exit 0)code2wiki --version→0.1.0;code2wiki --helprenders the full command list;code2wiki list --cwd <dir>andgenerate --mock/previewproduce output as expected.Test suite (
npx vitest run): typecheck clean; 1408 passed, 7 skipped (the 8 new tests included). The 8 failing tests (examples.test.tsstructural-snapshot hash mismatches + one README drift guard) are pre-existing onmainand unrelated to this change — they stem from a Windows CRLF checkout affecting content hashes / README parsing, confirmed identical onmainwithout this commit. This change adds no new failures.Scope
Behavioral fix is one normalized comparison, refactored into a tested pure function, plus a new test file. No public API, config, command, or output changes. POSIX behavior is identical to before.