Repository navigation
feat(editor): route the diff-view save through the guard (U8, #1375) #1916
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
base: main
Are you sure you want to change the base?
Changes from all commits
7505c8e
1b07409
8735c49
1fca597
4e74e82
815b5e0
ffa10b1
4653b34
dfac2c3
fed1242
27d98af
44dc7e1
91bd6c7
0a7fcff
716b5d9
c478fdc
02ce2e6
0aaf125
930c88d
f6b3e3d
f4e03eb
a5eaa7a
eb93e30
1140140
0d3697d
bb15ea9
8a86a91
732bfff
ebfc7fb
5b8fa7b
d87e1d4
90e4b22
6f69ff6
0028a1b
da01ba8
1c6e5d3
51137bf
26be948
2316165
c508da8
0f31b2d
c868022
abf03c5
9d2be1e
3a3473e
c075439
56fb9cc
8a29285
a8df293
d1ca165
d564f61
db5ef0a
fdc1ace
34a88e4
bc8aeee
facbc4c
f34215c
7b1a20d
0b12594
e0fbde1
95480b7
dc4a78a
0942fd1
87ac7b1
51257de
516496a
fc6ef60
625d412
56c45d6
d2ce125
05a5e1d
413fa01
81d16f3
2ba2936
716bff8
0a76af3
5a04426
9980ac7
3624e4f
f23e49f
c6b3e86
82cfbf2
5622f24
a00c5b7
e76c44a
3ea7348
1c34cec
4e4cf7f
096abc2
bf09481
1d77916
950752e
98ba389
24b6797
c055251
5cd9420
574f794
e77d20e
72f0d89
66c320f
676dea9
04d6a6d
9f5bf59
48bb73e
f95c7b4
e36a779
4a6d0f2
61b31b1
caabad3
2e00da1
680bdc2
da2b913
2a1b0a8
5f8474d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| import { type ProviderSettings } from "@roo-code/types" | ||
|
|
||
| import { Task } from "../Task" | ||
| import { ObservationRegistry } from "../observationRegistry" | ||
| import type { ClineProvider } from "../../webview/ClineProvider" | ||
| import { providerIdentifiers } from "@roo-code/types/provider-identifiers" | ||
|
|
||
| // Real-Task isolation proof for the observationRegistry field this PR adds to | ||
| // Task. The unit spec covers the registry's own semantics; this one pins the | ||
| // ownership contract the field exists for: every Task owns its registry, so a | ||
| // parent's observations never authorize a subtask's writes (and vice versa). | ||
| // The construction boilerplate mirrors Task.dispose.test.ts. | ||
| vi.mock("../../webview/ClineProvider") | ||
| vi.mock("../../../integrations/terminal/TerminalRegistry", () => ({ | ||
| TerminalRegistry: { | ||
| releaseTerminalsForTask: vi.fn(), | ||
| }, | ||
| })) | ||
| vi.mock("../../../utils/storage", () => ({ | ||
| getTaskDirectoryPath: vi.fn().mockResolvedValue("/test/path/tasks/test-task"), | ||
| })) | ||
| vi.mock("../../../integrations/terminal/OutputInterceptor", () => ({ | ||
| OutputInterceptor: { | ||
| cleanup: vi.fn().mockResolvedValue(undefined), | ||
| }, | ||
| })) | ||
| vi.mock("../../ignore/RooIgnoreController") | ||
| vi.mock("../../protect/RooProtectedController") | ||
| vi.mock("../../context-tracking/FileContextTracker") | ||
| vi.mock("../../../integrations/editor/DiffViewProvider") | ||
| vi.mock("../../tools/ToolRepetitionDetector") | ||
| vi.mock("../../../api", () => ({ | ||
| buildApiHandler: vi.fn(() => ({ | ||
| getModel: () => ({ info: {}, id: "test-model" }), | ||
| })), | ||
| })) | ||
| vi.mock("@roo-code/telemetry", () => ({ | ||
| TelemetryService: { | ||
| instance: { | ||
| captureTaskCreated: vi.fn(), | ||
| captureTaskRestarted: vi.fn(), | ||
| }, | ||
| }, | ||
| })) | ||
|
|
||
| describe("Task observation registry ownership", () => { | ||
| const makeProvider = () => ({ | ||
| context: { globalStorageUri: { fsPath: "/test/path" } }, | ||
| getState: vi.fn().mockResolvedValue({ mode: "code" }), | ||
| log: vi.fn(), | ||
| flushPostStateToWebviewThrottled: vi.fn().mockResolvedValue(undefined), | ||
| }) | ||
| const apiConfiguration = { | ||
| apiProvider: providerIdentifiers.anthropic, | ||
| apiKey: "test-key", | ||
| } as ProviderSettings | ||
|
|
||
| it("gives every real Task its own registry, isolated from every other", async () => { | ||
| const taskA = new Task({ | ||
| provider: makeProvider() as unknown as ClineProvider, | ||
| apiConfiguration, | ||
| startTask: false, | ||
| }) | ||
| const taskB = new Task({ | ||
| provider: makeProvider() as unknown as ClineProvider, | ||
| apiConfiguration, | ||
| startTask: false, | ||
| }) | ||
|
|
||
| try { | ||
| expect(taskA.observationRegistry).toBeInstanceOf(ObservationRegistry) | ||
| expect(taskB.observationRegistry).toBeInstanceOf(ObservationRegistry) | ||
| // Two real Tasks, two registries: a shared or static field fails here. | ||
| expect(taskA.observationRegistry).not.toBe(taskB.observationRegistry) | ||
|
|
||
| taskA.observationRegistry.observe("/tmp/observed-by-a.json", "version-a") | ||
|
|
||
| expect(taskA.observationRegistry.get("/tmp/observed-by-a.json")?.version).toBe("version-a") | ||
| // The other task's registry must not contain the observation: an | ||
| // observation earned by one task cannot authorize the other's writes. | ||
| expect(taskB.observationRegistry.get("/tmp/observed-by-a.json")).toBeUndefined() | ||
| expect(taskB.observationRegistry.has("/tmp/observed-by-a.json")).toBe(false) | ||
| expect(taskB.observationRegistry.size).toBe(0) | ||
| } finally { | ||
| await taskA.dispose().catch(() => {}) | ||
| await taskB.dispose().catch(() => {}) | ||
| } | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,7 +214,18 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> { | |
|
|
||
| // Save the changes | ||
| if (isPreventFocusDisruptionEnabled) { | ||
| await task.diffViewProvider.saveDirectly(relPath, newContent, true, diagnosticsEnabled, writeDelayMs) | ||
| // An Add change brings the target into being, so it publishes under create semantics. | ||
| await task.diffViewProvider.saveDirectly( | ||
| relPath, | ||
| newContent, | ||
| true, | ||
| diagnosticsEnabled, | ||
| writeDelayMs, | ||
| "create", | ||
| // The patch was applied to the bytes this tool just read, so it may re-observe what | ||
| // that read proves about the current version. | ||
| true, | ||
| ) | ||
| } else { | ||
| await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs) | ||
| } | ||
|
|
@@ -408,12 +419,18 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> { | |
|
|
||
| // Save new content to the new path | ||
| if (isPreventFocusDisruptionEnabled) { | ||
| // The destination is a new path: create semantics refuse to overwrite whatever is | ||
| // already standing there instead of moving bytes over it. | ||
| await task.diffViewProvider.saveDirectly( | ||
| change.movePath, | ||
| newContent, | ||
| false, | ||
| diagnosticsEnabled, | ||
| writeDelayMs, | ||
| "create", | ||
| // The patch was applied to the bytes this tool just read, so it may re-observe what | ||
| // that read proves about the current version. | ||
| true, | ||
|
easonLiangWorldedtech marked this conversation as resolved.
Resolved
Comment on lines
+430
to
+433
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) | ||
| } else { | ||
| // Write to new path and delete old file | ||
|
|
@@ -433,7 +450,19 @@ export class ApplyPatchTool extends BaseTool<"apply_patch"> { | |
| } else { | ||
| // Save changes to the same file | ||
| if (isPreventFocusDisruptionEnabled) { | ||
| await task.diffViewProvider.saveDirectly(relPath, newContent, false, diagnosticsEnabled, writeDelayMs) | ||
| // The hunks were applied to a base this tool read, so this is a full-file | ||
| // replacement of an existing target. | ||
| await task.diffViewProvider.saveDirectly( | ||
| relPath, | ||
| newContent, | ||
| false, | ||
| diagnosticsEnabled, | ||
| writeDelayMs, | ||
| "update", | ||
| // The patch was applied to the bytes this tool just read, so it may re-observe what | ||
| // that read proves about the current version. | ||
| true, | ||
| ) | ||
| } else { | ||
| await task.diffViewProvider.saveChanges(diagnosticsEnabled, writeDelayMs) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 4407
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 20484
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 42538
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 25331
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 10700
Script executed:
Repository: Zoo-Code-Org/Zoo-Code
Length of output: 13760
Enforce absence when publishing an Add.
With
preventFocusDisruptionenabled, a previously observed symlink can disappear before the initial check and return before publication. The matching observation letscreatereplace its referent instead of refusing the Add. Enforce absence at publication for Add operations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Measured: both the Add publish and the move-destination publish pass "create" through saveDirectly (ApplyPatchTool.ts:224 and :430 regions), so absence is the publish-side semantics the guard enforces, and saveDirectly's completeness parameter gates re-observation on the caller's read authority rather than writeKind. The claim's replacement scenario cannot pass create semantics on this tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rate Limit Exceeded
@easonLiangWorldedtechhave exceeded the limit for the number of chat messages per hour. Please wait 5 minutes and 50 seconds before sending another message.