Skip to content

fix(file): report status paths from the project directory - #769

Merged
Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/file-status-relative-paths
Sep 28, 2026
Merged

Ishaan Gangwani (ishaan1124) merged 1 commit into
synthetic-sciences:mainfrom
aniruddhaadak80:fix/file-status-relative-paths

Conversation

@aniruddhaadak80

Copy link
Copy Markdown
Contributor

What does this PR do, and why?

When OpenScience works in a subdirectory of a repository, the file status it
reports cannot be opened. 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 all three sources are 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, the response contained:

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

The same response also listed changes made outside the project, because both
git diff calls were repo-wide.

The fix asks git for paths relative to the project — the same form
ls-files --others already returned — and drops the remap that corrupted it:

const diffOutput = await $`git -c core.quotepath=false diff --numstat --relative HEAD`
const deletedOutput = await $`git -c core.quotepath=false diff --name-only --diff-filter=D --relative HEAD`
return changedFiles

--relative also scopes both diffs to the project directory, which is why
outside.txt is no longer reported as one of its changes.

Linked issue

Fixes #768

How did you verify it?

backend/cli/test/file/status-paths.test.ts builds a real repository, commits
pkg/tracked.txt, pkg/removed.txt and outside.txt, then works in pkg/ and
changes all three. It asserts that every reported path is relative and free of
.. segments, that each of the three files is reported under its
project-relative name with the right status, and that the change outside the
project is not listed.

On unmodified 3e94875c it fails on the .. check:

Expected: not to contain: ".."
Received: ["..\..\..\..\..\Desktop\Projects\openscience\backend\cli\outside.txt",
           "..\..\..\..\..\Desktop\Projects\openscience\backend\cli\pkg\removed.txt",
           "..\..\..\..\..\Desktop\Projects\openscience\backend\cli\pkg\tracked.txt"]

Commands run:

  • bun test --timeout 30000 ./test/file/status-paths.test.ts → 1 pass
  • bun run --cwd backend/cli typecheck → exit 0

I checked the two consumers of File.status() before changing its contract:
cli/cmd/debug/file.ts writes the result as JSON, and server/routes/file.ts
returns it from GET /file/status. Neither re-roots the paths or expects
repository-relative ones, so nothing depended on the old shape. The CLI
bootstraps with process.cwd(), so for it the project directory is the working
directory and --relative returns exactly what it returned before.

Two things I deliberately did not change, both pre-existing and visible in
the reproduction above:

  • A deleted file is also counted as modified, because git diff --numstat
    includes deletions. The test asserts toContain("deleted") for that path
    rather than pretending the duplicate is not there.
  • A file with a path git prints quoted (core.quotepath) is not unquoted here.
    That is unchanged behaviour and out of scope.

Pre-existing reds on this Windows checkout, not from this diff:

  • bun run format:check cannot pass here: git materializes the LF blobs as CRLF,
    so Prettier flags hundreds of untouched files. I verified all three changed
    files are formatted per the repo config with line endings normalized.
  • bun run typecheck: backend is clean; @synsci/workspace fails because
    frontend/workspace/src/custom-elements.d.ts is a symlink (mode 120000) that
    Windows checked out as a text file, which TypeScript then parses as source →
    TS1128.

Checklist

  • bun run check is green (format, typecheck, backend + frontend/ui + SDK tests) — blocked on this Windows checkout by the CRLF and symlink artifacts described above; backend typecheck is clean and the new test is green
  • bun run --cwd frontend/workspace build succeeds if I touched frontend/workspace or frontend/ui — not touched
  • ./tooling/repo/generate.ts was run and the tooling/sdk output committed if I changed backend/cli/src/server — not touched
  • CHANGELOG.md has an Unreleased entry if the change is user-visible
  • The matching docs page under frontend/docs/src/content/openscience/ is updated if behavior changed — no doc change needed: the status was always meant to be project-relative, and the Files/Changes pane resolves these paths from the project
  • Screenshots or a short video are attached for UI changes — not a UI change
  • No version bumps (package.json versions and tags are written by the release workflow)
  • install and frontend/landing/public/install are still byte-identical if I touched either — not touched

@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown

ANIRUDDHA ADAK (@aniruddhaadak80) is attempting to deploy a commit to the InkVell Team on Vercel.

A member of the Team first needs to authorize it.

Both git diff calls printed repository-root-relative paths and the result was
re-relativized with path.relative, which resolves a relative path against the
process working directory, so a subdirectory project got a chain of `..` that
resolved to no file. Ask git for the paths relative to the project instead, which
also stops changes outside the project being listed as its own.
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.

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

2 participants