Skip to content

Commit 61fbc23

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[AI Assistance] Remove inspector protocol changes after save
We want to minimize the layout/style shift, so we apply things to the working copy and then remove the inspector stylesheets Fixed: 407972738 Change-Id: Ie6700ac485ccc8c409506a41051d05f29b8f7977 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6434111 Commit-Queue: Alex Rudenko <[email protected]> Reviewed-by: Alex Rudenko <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent 52ddffb commit 61fbc23

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

front_end/panels/ai_assistance/PatchWidget.test.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ Files:
281281
let uiSourceCode: Workspace.UISourceCode.UISourceCode;
282282
let commitWorkingCopyStub:
283283
sinon.SinonStub<Parameters<typeof Workspace.UISourceCode.UISourceCode.prototype.commitWorkingCopy>>;
284-
let resetWorkingCopyStub:
285-
sinon.SinonStub<Parameters<typeof Workspace.UISourceCode.UISourceCode.prototype.resetWorkingCopy>>;
286284

287285
beforeEach(() => {
288286
uiSourceCode = createTestFilesystem('file://test').uiSourceCode;
@@ -296,49 +294,50 @@ Files:
296294

297295
commitWorkingCopyStub =
298296
sinon.stub(Workspace.UISourceCode.UISourceCode.prototype, 'commitWorkingCopy').callThrough();
299-
resetWorkingCopyStub =
300-
sinon.stub(Workspace.UISourceCode.UISourceCode.prototype, 'resetWorkingCopy').callThrough();
301297
});
302298

303-
it('on apply should call handle function and stash changes', async () => {
299+
it('on apply should should not call stashChanges', async () => {
304300
const {
305301
view,
306302
widget,
307-
} = await createPatchWidget({aidaClient: mockAidaClient([[{explanation: 'patch applied'}]])});
303+
} = await createPatchWidget({
304+
aidaClient: mockAidaClient([[{explanation: 'patch applied'}]]),
305+
});
308306
widget.changeSummary = 'body { background-color: red; }';
309307
const changeManager = sinon.createStubInstance(AiAssistanceModel.ChangeManager);
308+
changeManager.stashChanges.returns(Promise.resolve());
310309
widget.changeManager = changeManager;
311310
view.input.onApplyToWorkspace();
312311
await view.nextInput;
313-
assert.isTrue(changeManager.stashChanges.calledOnce);
312+
assert.isTrue(changeManager.stashChanges.notCalled);
314313
});
315314

316-
it('save all should commit the working copy of the changed UI codes to the disk and render savedToDisk view',
317-
async () => {
318-
const {view, widget} = await createPatchWidgetWithDiffView();
319-
const changeManager = sinon.createStubInstance(AiAssistanceModel.ChangeManager);
320-
widget.changeManager = changeManager;
321-
uiSourceCode.setWorkingCopy('working copy');
315+
it('on save should stash changes', async () => {
316+
const {view, widget} = await createPatchWidgetWithDiffView();
317+
const changeManager = sinon.createStubInstance(AiAssistanceModel.ChangeManager);
318+
changeManager.stashChanges.returns(Promise.resolve());
319+
widget.changeManager = changeManager;
320+
uiSourceCode.setWorkingCopy('working copy');
322321

323-
view.input.onSaveAll();
324-
const nextInput = await view.nextInput;
322+
view.input.onSaveAll();
323+
const nextInput = await view.nextInput;
325324

326-
assert.isTrue(nextInput.savedToDisk);
327-
assert.isTrue(commitWorkingCopyStub.called, 'Expected commitWorkingCopy to be called but it is not called');
328-
assert.isTrue(changeManager.dropStashedChanges.calledOnce);
329-
});
325+
assert.isTrue(nextInput.savedToDisk);
326+
assert.isTrue(commitWorkingCopyStub.called, 'Expected commitWorkingCopy to be called but it is not called');
327+
assert.isTrue(changeManager.stashChanges.calledOnce);
328+
});
330329

331330
it('discard should discard the working copy and render the view without patchSuggestion', async () => {
332331
const {view, widget} = await createPatchWidgetWithDiffView();
333332
const changeManager = sinon.createStubInstance(AiAssistanceModel.ChangeManager);
333+
changeManager.stashChanges.returns(Promise.resolve());
334334
widget.changeManager = changeManager;
335335
uiSourceCode.setWorkingCopy('working copy');
336336

337337
view.input.onDiscard();
338338
const nextInput = await view.nextInput;
339339

340340
assert.strictEqual(nextInput.patchSuggestionState, AiAssistance.PatchWidget.PatchSuggestionState.INITIAL);
341-
assert.isTrue(resetWorkingCopyStub.called, 'Expected resetWorkingCopy to be called but it is not called');
342341
assert.isTrue(changeManager.popStashedChanges.calledOnce);
343342
});
344343
});

front_end/panels/ai_assistance/PatchWidget.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ export class PatchWidget extends UI.Widget.Widget {
541541
this.requestUpdate();
542542
const {response, processedFiles} = await this.#applyPatch(changeSummary);
543543
if (response?.type === AiAssistanceModel.ResponseType.ANSWER) {
544-
await this.changeManager?.stashChanges();
545544
this.#patchSuggestionState = PatchSuggestionState.SUCCESS;
546545
} else if (
547546
response?.type === AiAssistanceModel.ResponseType.ERROR &&
@@ -570,11 +569,15 @@ ${processedFiles.map(filename => `* ${filename}`).join('\n')}`;
570569

571570
#onSaveAll(): void {
572571
this.#workspaceDiff.modifiedUISourceCodes().forEach(modifiedUISourceCode => {
573-
modifiedUISourceCode.commitWorkingCopy();
572+
if (!modifiedUISourceCode.url().startsWith('inspector://')) {
573+
modifiedUISourceCode.commitWorkingCopy();
574+
}
575+
});
576+
void this.changeManager?.stashChanges().then(() => {
577+
this.changeManager?.dropStashedChanges();
574578
});
575579

576580
this.#savedToDisk = true;
577-
this.changeManager?.dropStashedChanges();
578581
this.requestUpdate();
579582
}
580583

0 commit comments

Comments
 (0)