Skip to content

fix(app): resolve URL-style paths against the workspace on Windows - #58178

Open
harshitsharmaaaa wants to merge 1 commit into
anomalyco:devfrom
harshitsharmaaaa:windows-path-resolve
Open

harshitsharmaaaa wants to merge 1 commit into
anomalyco:devfrom
harshitsharmaaaa:windows-path-resolve

Conversation

@harshitsharmaaaa

Copy link
Copy Markdown

Issue for this PR

Closes #50913

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, a path such as /static/render/x.mp4 was treated as an absolute path even when it referred to a file inside the project. This caused the application to resolve it against the server's drive root (for example, C:\static) instead of the workspace.

This change treats paths with a single leading slash or backslash as workspace-relative when the workspace is on Windows and the path has no drive prefix or UNC prefix. It updates both file-path normalization and local image reads. Drive-qualified paths and UNC paths retain their existing behavior, and POSIX path handling remains unchanged.

How did you verify your code works?

  • Added regression tests for Windows workspace paths, backslash-style paths, and UNC workspaces.
  • packages/app unit tests: 768 passed across 109 files.
  • Root bun run check (lint and typecheck): passed.
  • Tested the path-resolution behavior against a real Windows OpenCode server, including a workspace-relative file and a valid absolute drive path.
  • The Playwright browser test was updated but not executed because a browser was unavailable in the test environment.

Screenshots / recordings

Not applicable. This is a filesystem path-resolution fix and does not introduce a visual UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

On Windows the server resolves a single leading separator relative to its process drive, so a URL-style path like /static/render/x.mp4 was read from C:\static and failed with a 500. Two places sent such paths as absolute: the file model normalized them outside the workspace and readLocalImage scoped them to the drive root parent directory.

Detect Windows scopes (drive letter or UNC directory) and treat drive-less, non-UNC paths as workspace-relative in both places. Full drive paths, file:// paths with a drive, and UNC paths (double separators) keep their absolute handling, so POSIX and out-of-project reads are unchanged.

Covers regression tests for the file model, image reads, and the markdown image contract.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks sound. I checked it by calling the path normaliser and readLocalImage directly on the base and on this branch, with a stub file API. On the base, /static/render/x.mp4 in a C:\repo workspace stays absolute, and the image read goes to directory /static/, which is the drive-root read from #50913. With this change, both resolve inside the workspace (static/render/x.mp4, and static/cover.png from C:/project). Drive paths, UNC paths (//server/share, \\server\share), /C:/… file-URL forms and POSIX workspaces behave as before. The unit tests for both files and the packages/app type check pass. I couldn't test against a real Windows server or the desktop app, and I didn't run the changed Playwright spec.

Public API is unchanged; these are client-side helpers in packages/app only.

No blocking concerns.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new commits only move the branch onto a newer dev; the change itself is the same as in the version I reviewed. I reran the unit tests for path.ts and image.ts and the packages/app type check on the new head, and both pass. Calling the path code directly still gives the fixed result: a Windows workspace now reads /static/... from inside the project, and drive and UNC paths are unchanged. I couldn't test against a real Windows server or the desktop app.

Public API is unchanged.

No new concerns.

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.

desktop: opening URL-style path resolves to C:\static, /api/fs/read returns 500 (UnexpectedStatus)

1 participant