From 5112ab7da9c381c126a9528138a5b08d6fc55d29 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Thu, 26 Mar 2026 15:32:44 +1100 Subject: [PATCH] fix(site/e2e): fix flaky updateTemplate test expecting transient URL (#23655) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _PR generated by Mux but reviewed by a human_ ## Problem The e2e test `template update with new name redirects on successful submit` is flaky. After saving template settings, the app navigates to `/templates/`, which immediately redirects to `/templates//docs` via the router's index route (``). The assertion used `expect.poll()` with `toHavePathNameEndingWith(`/${name}`)`, which matches only the **transient intermediate URL** — it only exists while `TemplateLayout`'s async data fetch is pending. Once the fetch resolves and the `` renders, the index route fires the `/docs` redirect and the URL no longer matches. ## Why it's flaky (not deterministic) The flakiness depends on whether the template query cache is warm: - **Cache miss → PASSES**: The mutation's `onSuccess` handler invalidates the query cache. If `TemplateLayout` needs to re-fetch, it shows a ``, which delays rendering the `` that contains the ``. This gives `expect.poll()` time to see the transient `/new-name` URL → **pass**. - **Cache hit → FAILS**: If the template data is still in the query client, `TemplateLayout` renders immediately and the `` fires nearly instantly. By the time the first poll runs, the URL is already `/new-name/docs` → **fail**. ## Fix Assert the **final stable URL** (`/${name}/docs`) instead of the transient one. This is safe because `expect.poll()` is retry-based: it keeps sampling until a match is found (or timeout). Seeing the transient `/new-name` URL just causes harmless retries — once the redirect completes and the URL settles on `/new-name/docs`, the poll matches and the test passes. | Poll | URL | Ends with `/new-name/docs`? | Action | |---|---|---|---| | 1st | `/templates/new-name` | No | Retry | | 2nd | `/templates/new-name` | No | Retry | | 3rd | `/templates/new-name/docs` | Yes | **Pass** ✅ | Closes https://github.com/coder/internal/issues/1403 --- site/e2e/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/e2e/helpers.ts b/site/e2e/helpers.ts index 5b1376359b..2e14620597 100644 --- a/site/e2e/helpers.ts +++ b/site/e2e/helpers.ts @@ -1171,7 +1171,7 @@ export const updateTemplateSettings = async ( await page.getByRole("button", { name: /save/i }).click(); const name = templateSettingValues.name ?? templateName; - await expectUrl(page).toHavePathNameEndingWith(`/${name}`); + await expectUrl(page).toHavePathNameEndingWith(`/${name}/docs`); }; export const updateWorkspace = async (