fix(agent-browser): bound crashed preview cleanup
This commit is contained in:
@@ -924,6 +924,54 @@ describe('AgentBrowserModule', () => {
|
||||
expect(adapter.views).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('bounds crashed preview cleanup so a subsequent data-enabled open completes', async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
const adapter = new FakeAdapter();
|
||||
const preview = new FakePreviewDataSession();
|
||||
adapter.onCreate = (view) => {
|
||||
view.webContents.debugger.responders.set('Page.addScriptToEvaluateOnNewDocument', async () => ({
|
||||
identifier: 'script-root',
|
||||
}));
|
||||
};
|
||||
const module = new AgentBrowserModule(adapter, { previewDataSession: preview });
|
||||
|
||||
await module.open({
|
||||
projectId: 'clock',
|
||||
projectPath,
|
||||
url: 'http://127.0.0.1:4173/',
|
||||
injectProjectData: true,
|
||||
});
|
||||
const crashedView = adapter.views[0];
|
||||
crashedView.webContents.debugger.responders.set(
|
||||
'Page.removeScriptToEvaluateOnNewDocument',
|
||||
async () => await new Promise<unknown>(() => undefined),
|
||||
);
|
||||
|
||||
crashedView.webContents.emit('render-process-gone', {}, { reason: 'crashed' });
|
||||
expect(preview.invalidations).toContain('browser_crashed');
|
||||
expect(preview.getInjectionValue()).toBeNull();
|
||||
|
||||
const reopening = module.open({
|
||||
projectId: 'clock',
|
||||
projectPath,
|
||||
url: 'http://127.0.0.1:4173/',
|
||||
injectProjectData: true,
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(1_000);
|
||||
|
||||
await expect(reopening).resolves.toMatchObject({
|
||||
state: 'attached',
|
||||
generation: 2,
|
||||
});
|
||||
expect(preview.invalidations).toContain('browser_crashed');
|
||||
expect(preview.opens).toHaveLength(2);
|
||||
expect(adapter.views).toHaveLength(2);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it('replaces a data-enabled browser when a later ordinary open omits the opt-in', async () => {
|
||||
const adapter = new FakeAdapter();
|
||||
const preview = new FakePreviewDataSession();
|
||||
|
||||
Reference in New Issue
Block a user