Skip to content

Commit 704729c

Browse files
wolfibDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[Patch agent] Skip workspace selection dialog for disconnected
automatic workspaces Bug: 399560823 Change-Id: I1656bffcec9afd4d3237d00bb5465b003eab67ff Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6446876 Auto-Submit: Wolfgang Beyer <wolfi@chromium.org> Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
1 parent 2ad5ab4 commit 704729c

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

front_end/panels/ai_assistance/PatchWidget.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,27 @@ Files:
278278
// Assert that the project has been updated
279279
assert.strictEqual(input.projectName, 'test2');
280280
});
281+
282+
it('preselects an automatic workspace folder and allows connecting to it', async () => {
283+
setupAutomaticFileSystem({hasFileSystem: true});
284+
const showSelectWorkspaceDialogSpy = sinon.spy(AiAssistance.SelectWorkspaceDialog, 'show');
285+
const applyChangesSpy = sinon.spy(AiAssistanceModel.PatchAgent.prototype, 'applyChanges');
286+
287+
const {view, widget} = await createPatchWidget();
288+
widget.changeSummary = 'body { background-color: red; }';
289+
assert.strictEqual(view.input.projectName, 'my-automatic-file-system');
290+
assert.strictEqual(view.input.projectPath, '/path/to/my-automatic-file-system');
291+
292+
// Clicking on "Apply to workspace" does not open a SelectWorkspaceDialog
293+
view.input.onApplyToWorkspace();
294+
assert.isTrue(showSelectWorkspaceDialogSpy.notCalled);
295+
await new Promise(resolve => setTimeout(resolve, 0));
296+
assert.isTrue(applyChangesSpy.notCalled);
297+
298+
// This simulates the user confirming the file permissions dialog
299+
createTestFilesystem('file:///path/to/my-automatic-file-system');
300+
assert.isTrue(applyChangesSpy.calledOnce);
301+
});
281302
});
282303

283304
describe('diff view', () => {

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export class PatchWidget extends UI.Widget.Widget {
209209
#workspace = Workspace.Workspace.WorkspaceImpl.instance();
210210
#automaticFileSystem =
211211
Persistence.AutomaticFileSystemManager.AutomaticFileSystemManager.instance().automaticFileSystem;
212+
#applyToDisconnectedAutomaticWorkspace = false;
212213

213214
constructor(element?: HTMLElement, view?: View, opts?: {
214215
aidaClient: Host.AidaClient.AidaClient,
@@ -518,6 +519,7 @@ export class PatchWidget extends UI.Widget.Widget {
518519
}
519520

520521
override willHide(): void {
522+
this.#applyToDisconnectedAutomaticWorkspace = false;
521523
if (isAiAssistancePatchingEnabled()) {
522524
this.#workspace.removeEventListener(Workspace.Workspace.Events.ProjectAdded, this.#onProjectAdded, this);
523525
this.#workspace.removeEventListener(Workspace.Workspace.Events.ProjectRemoved, this.#onProjectRemoved, this);
@@ -581,8 +583,14 @@ export class PatchWidget extends UI.Widget.Widget {
581583
this.requestUpdate();
582584
}
583585

584-
#onProjectAdded(): void {
585-
if (this.#project === undefined) {
586+
#onProjectAdded(event: Common.EventTarget.EventTargetEvent<Workspace.Workspace.Project>): void {
587+
const addedProject = event.data;
588+
if (this.#applyToDisconnectedAutomaticWorkspace && this.#automaticFileSystem &&
589+
addedProject === this.#workspace.projectForFileSystemRoot(this.#automaticFileSystem.root)) {
590+
this.#applyToDisconnectedAutomaticWorkspace = false;
591+
this.#project = addedProject;
592+
void this.#applyPatchAndUpdateUI();
593+
} else if (this.#project === undefined) {
586594
this.#selectDefaultProject();
587595
}
588596
}
@@ -623,6 +631,10 @@ export class PatchWidget extends UI.Widget.Widget {
623631

624632
if (this.#project) {
625633
await this.#applyPatchAndUpdateUI();
634+
} else if (this.#automaticFileSystem) {
635+
this.#applyToDisconnectedAutomaticWorkspace = true;
636+
await Persistence.AutomaticFileSystemManager.AutomaticFileSystemManager.instance().connectAutomaticFileSystem(
637+
/* addIfMissing= */ true);
626638
} else {
627639
this.#showSelectWorkspaceDialog({applyPatch: true});
628640
}

0 commit comments

Comments
 (0)