Skip to content

File status paths are relative to the server working directory, not the project #768

Closed

Description

What happened?

When OpenScience works in a subdirectory of a repository, the file status it
reports is unusable. Every path comes back as a chain of .. segments pointing
at wherever the server was started.

Two things combine:

// git prints repository-root-relative paths
const diffOutput = await $`git diff --numstat HEAD`.cwd(Instance.directory)…
// git ls-files --others prints cwd-relative paths
const untrackedOutput = await $`git ls-files --others --exclude-standard`.cwd(Instance.directory)…
// and then every one of them is re-relativized
return changedFiles.map((x) => ({ ...x, path: path.relative(Instance.directory, x.path) }))

path.relative(from, to) resolves a relative to against process.cwd(), not
against from. Nothing in the codebase calls process.chdir, so the server's
working directory is fixed at launch while Instance.directory is whatever
project the client selected.

Reproduced on 3e94875c with a repository whose pkg/ is the project, and a
change to pkg/tracked.txt:

..\..\..\..\..\Desktop\Projects\openscience\backend\cli\pkg\tracked.txt

instead of tracked.txt.

The same response also lists changes made outside the project
(outside.txt above), because both git diff calls were repo-wide.

The agent cannot open any of these paths, and the two branches disagree with each
other in the same response.

Steps to reproduce

  1. git init a repository containing a subdirectory, and commit a file in it.
  2. Start OpenScience in that subdirectory, or select it as the project.
  3. Modify the committed file, add a new one and delete another.
  4. Read the file status (GET /file/status, or the Files/Changes pane).

The focused regression in test/file/status-paths.test.ts fails on 3e94875c
and passes with the fix.

How did you install OpenScience?

From source (bun dev).

OpenScience version

Source commit 3e94875c.

Provider and model

Not applicable; this is the file status the server returns.

Operating system

Not OS-specific — it depends on the project directory differing from the server's
working directory, which is the normal case for both the server and the desktop
app.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions