-
Notifications
You must be signed in to change notification settings - Fork 76
fix(tool-projection): expose host_file_* on cross-client transports when capable client connected #29613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
credence-the-bot
merged 6 commits into
credence-the-bot/host-file-cross-client-exposure-plan
from
run-plan/host-file-cross-client/pr-1
May 5, 2026
Merged
fix(tool-projection): expose host_file_* on cross-client transports when capable client connected #29613
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3335032
feat(tool-projection): add CROSS_CLIENT_EXPOSED_CAPABILITIES set
credence-the-bot[bot] 0a6a196
test(tool-projection): cover host_file_* cross-client exposure paths
credence-the-bot[bot] 5874e9f
docs(tool-projection): update file docstring for cross-client carve-out
credence-the-bot[bot] 4ec0e1a
fix(tool-projection): add host_file_* executor guards for cross-clien…
credence-the-bot[bot] da11f13
fix(tool-projection): scope host_file_* disconnected-target guard to …
credence-the-bot[bot] 54a2e39
fix(tool-projection): scope host_file_transfer disconnected-target gu…
credence-the-bot[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { mkdtempSync, realpathSync, rmSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { afterEach, describe, expect, mock, test } from "bun:test"; | ||
|
|
||
| import type { ToolContext } from "../types.js"; | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Singleton mocks — must precede the tool import so bun's module mock applies. | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| let mockProxyAvailable = false; | ||
|
|
||
| mock.module("../../daemon/host-file-proxy.js", () => ({ | ||
| HostFileProxy: { | ||
| get instance() { | ||
| return { | ||
| isAvailable: () => mockProxyAvailable, | ||
| request: () => Promise.resolve({ content: "ok", isError: false }), | ||
| }; | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| mock.module("../../runtime/assistant-event-hub.js", () => ({ | ||
| assistantEventHub: { | ||
| listClientsByCapability: () => [], | ||
| }, | ||
| })); | ||
|
|
||
| const { hostFileEditTool } = await import("./edit.js"); | ||
|
|
||
| const testDirs: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| mockProxyAvailable = false; | ||
| for (const dir of testDirs.splice(0)) { | ||
| rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| function makeTempDir(): string { | ||
| const dir = realpathSync(mkdtempSync(join(tmpdir(), "host-edit-test-"))); | ||
| testDirs.push(dir); | ||
| return dir; | ||
| } | ||
|
|
||
| function makeContext( | ||
| workingDir: string, | ||
| transportInterface: ToolContext["transportInterface"], | ||
| ): ToolContext { | ||
| return { | ||
| workingDir, | ||
| conversationId: "test-conv", | ||
| trustClass: "guardian", | ||
| transportInterface, | ||
| }; | ||
| } | ||
|
|
||
| describe("host_file_edit cross-client guards", () => { | ||
| test("returns 'no client' error on web transport when proxy unavailable and no targetClientId", async () => { | ||
| const workingDir = makeTempDir(); | ||
| const result = await hostFileEditTool.execute( | ||
| { | ||
| path: "/some/host/path.txt", | ||
| old_string: "foo", | ||
| new_string: "bar", | ||
| }, | ||
| makeContext(workingDir, "web"), | ||
| ); | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content).toContain( | ||
| "no client with host_file capability is connected", | ||
| ); | ||
| }); | ||
|
|
||
| test("returns 'specified client disconnected' error when targetClientId set but proxy unavailable on web", async () => { | ||
| const workingDir = makeTempDir(); | ||
| const result = await hostFileEditTool.execute( | ||
| { | ||
| path: "/some/host/path.txt", | ||
| old_string: "foo", | ||
| new_string: "bar", | ||
| target_client_id: "abc-123", | ||
| }, | ||
| makeContext(workingDir, "web"), | ||
| ); | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content).toContain( | ||
| 'target client "abc-123" is no longer connected', | ||
| ); | ||
| }); | ||
|
|
||
| test("falls through to local fs on macos transport when proxy unavailable", async () => { | ||
| const workingDir = makeTempDir(); | ||
| const result = await hostFileEditTool.execute( | ||
| { | ||
| path: "/nonexistent/x.txt", | ||
| old_string: "foo", | ||
| new_string: "bar", | ||
| }, | ||
| makeContext(workingDir, "macos"), | ||
| ); | ||
| // Proves the guard did NOT fire on macOS — instead we got the | ||
| // local FileSystemOps error path (file not found / IO error). | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content.toLowerCase()).toMatch(/not found|enoent|editing/); | ||
| }); | ||
|
|
||
| test("does NOT reject on macos transport with a stale target_client_id when proxy unavailable (regression: P2 fix)", async () => { | ||
| const workingDir = makeTempDir(); | ||
| const result = await hostFileEditTool.execute( | ||
| { | ||
| path: "/nonexistent/x.txt", | ||
| old_string: "foo", | ||
| new_string: "bar", | ||
| target_client_id: "stale-mac", | ||
| }, | ||
| makeContext(workingDir, "macos"), | ||
| ); | ||
| // The disconnected-target guard is scoped to non-host-proxy transports | ||
| // (!supportsHostProxy). On macos, a stale target_client_id auto-filled | ||
| // from a prior cross-client turn must be silently ignored and the call | ||
| // must fall through to local FileSystemOps, NOT reject with "target | ||
| // client ... is no longer connected". | ||
| expect(result.isError).toBe(true); | ||
| expect(result.content).not.toContain("is no longer connected"); | ||
| expect(result.content.toLowerCase()).toMatch(/not found|enoent|editing/); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.