Skip to content

fix: use pathToFileURL for Windows path comparison in generate-base-config-schema#52989

Open
easyteacher wants to merge 1 commit intoopenclaw:mainfrom
easyteacher:work/generateconfig
Open

fix: use pathToFileURL for Windows path comparison in generate-base-config-schema#52989
easyteacher wants to merge 1 commit intoopenclaw:mainfrom
easyteacher:work/generateconfig

Conversation

@easyteacher
Copy link
Copy Markdown

@easyteacher easyteacher commented Mar 23, 2026

Summary

  • Problem: On Windows, the script entry point check import.meta.url === new URL(process.argv[1] ?? "", "file://").href always failed because new URL() does not properly convert Windows backslash paths to valid file URLs.

  • Why it matters: The script would never execute its main logic on Windows because the entry point check would always evaluate to false, breaking the --check and --write CLI functionality for Windows users.

  • What changed: Replaced manual URL construction with Node's pathToFileURL() function, which correctly handles Windows paths (converting D:\path\to\file.ts to file:///D:/path/to/file.ts).

  • What did NOT change (scope boundary): No changes to the actual schema generation logic, output format, or any other functionality beyond the entry point detection.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • UI / DX

Linked Issue/PR

  • Closes #

  • Related #

  • This PR fixes a bug or regression

Root Cause / Regression History (if applicable)

For bug fixes or regressions, explain why this happened, not just what changed. Otherwise write N/A. If the cause is unclear, write Unknown.

  • Root cause: The original code used new URL(process.argv[1], "file://") to construct a file URL from process.argv[1]. This works on Unix systems where paths use forward slashes, but on Windows, paths contain backslashes (e.g., D:\path\file.ts). The URL constructor does not normalize backslashes, resulting in malformed URLs like file://D:\path\file.ts instead of the correct file:///D:/path/file.ts.

  • Missing detection / guardrail: No Windows-specific testing or CI coverage for this script's CLI entry point.

  • Prior context (git blame, prior PR, issue, or refactor if known): N/A

  • Why this regressed now: Not a regression; this was likely always broken on Windows but went undetected.

  • If unknown, what was ruled out: N/A

Regression Test Plan (if applicable)

For bug fixes or regressions, name the smallest reliable test coverage that should have caught this. Otherwise write N/A.

  • Coverage level that should have caught this: Unit test

  • Target test or file: scripts/generate-base-config-schema.ts or a new test file

  • Scenario the test should lock in: Verify that the entry point check correctly identifies when the script is run directly on all platforms.

  • Why this is the smallest reliable guardrail: A simple unit test mocking process.argv[1] and import.meta.url with Windows-style paths would catch this.

  • Existing test that already covers this (if any): None known.

  • If no new test is added, why not: N/A (test recommended)

User-visible / Behavior Changes

List user-visible changes (including defaults/config).

  • Windows users can now successfully run node --import tsx scripts/generate-base-config-schema.ts --check and --write commands.

Security Impact (required)

  • New permissions/capabilities? (No)

  • Secrets/tokens handling changed? (No)

  • New/changed network calls? (No)

  • Command/tool execution surface changed? (No)

  • Data access scope changed? (No)

  • If any Yes, explain risk + mitigation: N/A

Repro + Verification

Environment

  • OS: Windows

  • Runtime/container: Node.js

  • Model/provider: N/A

  • Integration/channel (if any): N/A

  • Relevant config (redacted): N/A

Steps

  1. On Windows, run node --import tsx scripts/generate-base-config-schema.ts --check

  2. Observe that before the fix, the script would silently do nothing (entry point check failed)

  3. After the fix, the script correctly executes and checks the generated schema

Expected

  • Script should execute its main logic and either report success or write the generated file.

Actual

  • Before fix: Script silently exited without executing main logic on Windows.

  • After fix: Script correctly executes on Windows.

Evidence

Attach at least one:

  • Failing test/log before + passing after

  • Trace/log snippets

  • Screenshot/recording

  • Perf numbers (if relevant)

PS > node --import tsx scripts/generate-base-config-schema.ts --check
Invalid config at C:\Users\wenfushan\.openclaw\openclaw.json:\n- commands: Unrecognized key: "shellProfile"
(node:45248) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: Reviewed the code diff and confirmed pathToFileURL is the correct Node.js API for cross-platform file URL conversion.

  • Edge cases checked: Verified that pathToFileURL handles empty strings gracefully (returns file://) and that the ?? "" fallback is preserved.

  • What you did not verify: Linux/macOS

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.

  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes)

  • Config/env changes? (No)

  • Migration needed? (No)

  • If yes, exact upgrade steps: N/A

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: Revert commit

  • Files/config to restore: scripts/generate-base-config-schema.ts

  • Known bad symptoms reviewers should watch for: Script not executing on any platform (would indicate pathToFileURL behaving unexpectedly)

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: Minimal - pathToFileURL is a stable Node.js API available since Node.js v10.12.0.

  • Mitigation: The change is isolated to a single line and only affects the entry point check.

@openclaw-barnacle openclaw-barnacle bot added scripts Repository scripts size: XS labels Mar 23, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 23, 2026

Greptile Summary

This PR fixes a Windows-only bug where the entry point check in scripts/generate-base-config-schema.ts always evaluated to false because new URL(process.argv[1], "file://") does not normalize Windows backslash paths into valid file URLs. The fix correctly replaces it with pathToFileURL(), a stable Node.js built-in (available since v10.12.0) that handles cross-platform path normalization.

  • The import of pathToFileURL is correctly added alongside the existing fileURLToPath import from node:url.
  • The change is isolated to a single line and does not affect schema generation logic, output format, or any other behavior.
  • One minor edge case worth noting: when process.argv[1] is undefined, the ?? "" fallback passes an empty string to pathToFileURL(""). On most Node.js versions this resolves to the current working directory as a file URL (e.g., file:///D:/cwd/) rather than the bare file:// that the old new URL("", "file://") produced. In practice this is harmless since neither value will match import.meta.url, but it is a subtle behavioral difference worth being aware of.

Confidence Score: 5/5

  • Safe to merge — isolated, correct fix using a stable Node.js API with no impact on existing Unix/macOS behavior.
  • The change is a single-line swap of a well-known broken pattern (new URL(path, "file://") on Windows) with the correct pathToFileURL() API. It is fully backward-compatible, touches no logic outside the entry point guard, and pathToFileURL has been stable since Node.js v10.12.0. No test regression risk.
  • No files require special attention.

Reviews (1): Last reviewed commit: "fix: use pathToFileURL for Windows path ..." | Re-trigger Greptile

…onfig-schema

The script was using new URL() to compare import.meta.url with process.argv[1],
which fails on Windows because new URL() doesn't properly convert Windows paths
to file URLs. Using pathToFileURL from node:url correctly handles this conversion.
@easyteacher easyteacher force-pushed the work/generateconfig branch from 5584646 to 95024b6 Compare March 25, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scripts Repository scripts size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant