Skip to content

fix: reject missing files before opening editor tabs#9012

Open
lee-eojin wants to merge 1 commit into
stablyai:mainfrom
lee-eojin:fix/cli-file-open-missing-path
Open

fix: reject missing files before opening editor tabs#9012
lee-eojin wants to merge 1 commit into
stablyai:mainfrom
lee-eojin:fix/cli-file-open-missing-path

Conversation

@lee-eojin

Copy link
Copy Markdown

Closes #8844

Summary

Prevent orca file open from reporting success for paths that do not
exist.

The runtime now verifies the target file before opening an editor tab:

  • Local worktrees use the authorized local filesystem path.
  • SSH worktrees use the SSH filesystem provider.
  • Missing files return ok: false and cause the CLI to exit with code
    1, instead of creating a ghost editor tab.

Screenshots

No visual change.

Testing

  • pnpm lint (targeted oxlint and formatting checks passed)
  • pnpm typecheck (runtime and CLI type checks passed)
  • pnpm test (full Vitest suite run on Node 24: 29,938 passed, 0
    failed)
  • pnpm build
  • Added regression tests for missing local files, missing SSH files,
    and CLI JSON failure / nonzero exit code

AI Review Report

Reviewed the file-open flow from CLI handler to RPC dispatcher to runtime
file commands.

Main risks checked:

  • Missing paths creating editor tabs before validation.
  • Local path authorization being bypassed.
  • SSH worktrees accidentally using the local filesystem.
  • RPC failures being converted into successful CLI output.
  • Existing binary-file behavior changing unexpectedly.

The review found that local and SSH paths required different existence
checks. The implementation now uses resolveAuthorizedPath + stat
locally and the SSH filesystem provider remotely.

Cross-platform compatibility was reviewed for macOS, Linux, and Windows.
The change uses existing Node path utilities and filesystem abstractions,
does not add shell commands, keyboard shortcuts, labels, or Electron-
specific behavior, and preserves the existing local/SSH routing model.

Security Audit

Reviewed path handling and IPC/RPC behavior.

  • User-provided paths remain restricted by the existing safe-relative-path
    validation.
  • Local paths continue through resolveAuthorizedPath before filesystem
    access.
  • SSH paths are checked through the registered SSH filesystem provider
    instead of local disk access.
  • Missing-file errors expose only the requested relative path, not an
    absolute filesystem path.
  • No command execution, authentication, secret handling, dependency, or
    new IPC surface was added.

No follow-up security work is required for this change.

Notes

  • This is a runtime behavior change only, with no UI change.
  • Full tests were run with Node 24.18.0, matching the project engine
    requirement.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

openMobileFile now checks that the requested file exists before opening it. Local files use authorized path resolution and filesystem statistics, while SSH-backed files use the SSH filesystem provider. Missing files produce a consistent File not found error, and the renderer host is not called. Tests cover existing file classifications, missing local and SSH files, and JSON CLI error output with exit code 1.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: rejecting missing files before opening editor tabs.
Description check ✅ Passed The description covers the required sections with a clear summary, testing, AI review, security audit, and notes.
Linked Issues check ✅ Passed The changes match #8844 by validating file existence, returning ok:false and exit code 1 for missing files, and avoiding ghost tabs.
Out of Scope Changes check ✅ Passed The code and test changes stay focused on file-existence validation and related CLI/runtime error handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e309d51f-4e8e-4a8e-8147-d1395f814765

📥 Commits

Reviewing files that changed from the base of the PR and between cf02cc4 and aee3663.

📒 Files selected for processing (3)
  • src/cli/handlers/file.test.ts
  • src/main/runtime/orca-runtime-files.test.ts
  • src/main/runtime/orca-runtime-files.ts

Comment on lines +91 to +113
it('reports a missing file as a JSON failure with a nonzero exit code', async () => {
const priorExitCode = process.exitCode
queueFixtures(callMock, worktreeListFixture([buildWorktree('/tmp/repo', 'feature')]))
callMock.mockRejectedValueOnce(
new RuntimeRpcFailureError({
id: 'req_open',
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' },
_meta: { runtimeId: 'runtime-1' }
})
)

await main(['file', 'open', 'docs/missing.md', '--json'], '/tmp/repo')

expect(JSON.parse(String(vi.mocked(console.log).mock.calls[0][0]))).toMatchObject({
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' }
})
expect(process.exitCode).toBe(1)

process.exitCode = priorExitCode
})

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use a try...finally block to ensure process.exitCode is restored.

If an assertion (like expect) fails during the test, it throws an error and halts the test execution. Without a try...finally block, process.exitCode will not be restored to priorExitCode, which can cause subsequent tests to misbehave or the test runner process to exit with an incorrect status code.

🛡️ Proposed fix to ensure cleanup
   it('reports a missing file as a JSON failure with a nonzero exit code', async () => {
     const priorExitCode = process.exitCode
-    queueFixtures(callMock, worktreeListFixture([buildWorktree('/tmp/repo', 'feature')]))
-    callMock.mockRejectedValueOnce(
-      new RuntimeRpcFailureError({
-        id: 'req_open',
-        ok: false,
-        error: { code: 'runtime_error', message: 'File not found: docs/missing.md' },
-        _meta: { runtimeId: 'runtime-1' }
-      })
-    )
-
-    await main(['file', 'open', 'docs/missing.md', '--json'], '/tmp/repo')
-
-    expect(JSON.parse(String(vi.mocked(console.log).mock.calls[0][0]))).toMatchObject({
-      ok: false,
-      error: { code: 'runtime_error', message: 'File not found: docs/missing.md' }
-    })
-    expect(process.exitCode).toBe(1)
-
-    process.exitCode = priorExitCode
+    try {
+      queueFixtures(callMock, worktreeListFixture([buildWorktree('/tmp/repo', 'feature')]))
+      callMock.mockRejectedValueOnce(
+        new RuntimeRpcFailureError({
+          id: 'req_open',
+          ok: false,
+          error: { code: 'runtime_error', message: 'File not found: docs/missing.md' },
+          _meta: { runtimeId: 'runtime-1' }
+        })
+      )
+
+      await main(['file', 'open', 'docs/missing.md', '--json'], '/tmp/repo')
+
+      expect(JSON.parse(String(vi.mocked(console.log).mock.calls[0][0]))).toMatchObject({
+        ok: false,
+        error: { code: 'runtime_error', message: 'File not found: docs/missing.md' }
+      })
+      expect(process.exitCode).toBe(1)
+    } finally {
+      process.exitCode = priorExitCode
+    }
   })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('reports a missing file as a JSON failure with a nonzero exit code', async () => {
const priorExitCode = process.exitCode
queueFixtures(callMock, worktreeListFixture([buildWorktree('/tmp/repo', 'feature')]))
callMock.mockRejectedValueOnce(
new RuntimeRpcFailureError({
id: 'req_open',
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' },
_meta: { runtimeId: 'runtime-1' }
})
)
await main(['file', 'open', 'docs/missing.md', '--json'], '/tmp/repo')
expect(JSON.parse(String(vi.mocked(console.log).mock.calls[0][0]))).toMatchObject({
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' }
})
expect(process.exitCode).toBe(1)
process.exitCode = priorExitCode
})
it('reports a missing file as a JSON failure with a nonzero exit code', async () => {
const priorExitCode = process.exitCode
try {
queueFixtures(callMock, worktreeListFixture([buildWorktree('/tmp/repo', 'feature')]))
callMock.mockRejectedValueOnce(
new RuntimeRpcFailureError({
id: 'req_open',
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' },
_meta: { runtimeId: 'runtime-1' }
})
)
await main(['file', 'open', 'docs/missing.md', '--json'], '/tmp/repo')
expect(JSON.parse(String(vi.mocked(console.log).mock.calls[0][0]))).toMatchObject({
ok: false,
error: { code: 'runtime_error', message: 'File not found: docs/missing.md' }
})
expect(process.exitCode).toBe(1)
} finally {
process.exitCode = priorExitCode
}
})

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.

[Bug]: orca file open reports ok:true / exit 0 for a path that resolves to a non-existent file (creates a ghost tab)

2 participants