AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(frontend/copilot): stop two copilot tests failing on slow CI runners (#15963)
Reinier van der Leer00ec269672b8
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-lifecycle.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-lifecycle.test.tsxindex aca909c54b..a8614becdf 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-lifecycle.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-lifecycle.test.tsx@@ -183,12 +183,10 @@ describe.each(STREAM_PATHS)("on the %s path", (path) => {);renderHost();const cancels = countCancels();- const user = userEvent.setup();+ const tappedWhileDisarmed = tapStopWithin(150);await typeAndSend("hello");- const stop = await screen.findByRole("button", { name: /^stop$/i });- await sleep(150);- await user.click(stop);+ expect(await tappedWhileDisarmed).toBe(true);await sleep(200);expect(cancels()).toBe(0);@@ -252,3 +250,30 @@ function sendSlot() {function sleep(ms: number) {return new Promise((resolve) => setTimeout(resolve, ms));}++// Taps Stop at most `ms` after it mounts. The timer starts before Stop can+// mount, so it is always due before Stop's 1 s arm. Resolves to `disabled`.+function tapStopWithin(ms: number) {+ return new Promise<boolean>((resolve) => {+ let isDue = false;+ const observer = new MutationObserver(tap);+ function tap() {+ const stop = document.querySelector<HTMLButtonElement>(+ 'button[aria-label="Stop"]',+ );+ if (!isDue || !stop) return;+ observer.disconnect();+ resolve(stop.disabled);+ stop.click();+ }+ observer.observe(document.body, {+ childList: true,+ subtree: true,+ attributeFilter: ["aria-label"],+ });+ setTimeout(() => {+ isDue = true;+ tap();+ }, ms);+ });+}diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsxindex 73bdb9e026..5095890dd6 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx@@ -74,7 +74,8 @@ afterEach(() => {useAutopilotModeStore.setState({ choices: {} });});-describe("AutoPilot mode selector", () => {+// These flows take 3-4.5 s on CI's slower runners, close to the 5 s default.+describe("AutoPilot mode selector", { timeout: 15_000 }, () => {it("is absent with the flag off, and the request carries no mode", async () => {flags.autoMode = false;const bodies = captureStreamBodies();