# Instructions

- Following Playwright test failed.
- Explain why, be concise, respect Playwright best practices.
- Provide a snippet of code with the fix, if possible.

# Test info

- Name: tests/ui/routing.spec.ts >> routing: every index link resolves >> /offices/ first-page links all answer 200 or 301
- Location: tests/ui/routing.spec.ts:73:9

# Error details

```
Error: /offices/ links that do not resolve

expect(received).toEqual(expected) // deep equality

- Expected  -  1
+ Received  + 48

- Array []
+ Array [
+   "/offices/7c29b59b-2482-71ba-7557-1ba7e77daa10/ -> 503",
+   "/offices/c0de7219-f25c-7dc2-d406-47a54c1225e8/ -> 503",
+   "/offices/20e183aa-eb55-7916-17e3-bfd156bf9cf2/ -> 503",
+   "/offices/43da91d3-9f25-3e9f-aa08-799f0c2043ad/ -> 503",
+   "/offices/c2ae5b3b-a878-91c3-1ac9-7a79511495db/ -> 503",
+   "/offices/9af54520-efe6-415b-0bed-cae1fe1fd830/ -> 503",
+   "/offices/619f3886-426d-8e0b-6141-a10cc7847e13/ -> 503",
+   "/offices/7562ba80-f191-b1df-8e76-54d703e10690/ -> 503",
+   "/offices/ba48d955-6e7e-670e-b85a-2537687c4175/ -> 503",
+   "/offices/62ce3c4e-7e94-b5fb-1d13-1adc42c33a37/ -> 503",
+   "/offices/2c4aa8c6-3f90-7c7c-b60c-6a995ae58f56/ -> 503",
+   "/offices/6e63f5e1-5a2e-5541-a643-1be9ac075136/ -> 503",
+   "/offices/91f59a74-fdb0-4ab4-dfd5-c2c40cad277b/ -> 503",
+   "/offices/b279284d-a3bf-24a2-94b8-0322becdccf4/ -> 503",
+   "/offices/556b8f9b-f71d-3211-c77c-96a1ded35121/ -> 503",
+   "/offices/82fbdb29-d08e-ad19-d664-580dabfcf109/ -> 503",
+   "/offices/2689b72f-c562-9f15-215e-982eb863d544/ -> 503",
+   "/offices/3c933155-9169-4ce9-c402-d5ba35879a08/ -> 503",
+   "/offices/5a28befd-a223-b925-04a6-9fe9ca6dbc64/ -> 503",
+   "/offices/fc78b296-bbc9-4535-4f6d-5493ec10dd7d/ -> 503",
+   "/offices/74a6b894-e193-d441-da59-53e3fa721166/ -> 503",
+   "/offices/772fc7ae-df97-2a68-fa25-d42a9c708193/ -> 503",
+   "/offices/5f2c9e2a-2cff-4165-901f-908650e0fd8c/ -> 503",
+   "/offices/d16d2005-352e-ecc7-45b0-0b4f7b8ae684/ -> 503",
+   "/offices/2982aecb-9d48-f36f-88d9-fc40b82b4610/ -> 503",
+   "/offices/353ad230-3b7d-a4fb-2531-9ed591bab14b/ -> 503",
+   "/offices/de60e95b-1dc2-2ec3-b731-620ae5bd1d99/ -> 503",
+   "/offices/9c5a47f9-0595-9cc6-e2c9-0e3947a52975/ -> 503",
+   "/offices/3ac0c724-530d-109e-6ac9-c365eb9955a6/ -> 503",
+   "/offices/f3358a0f-10e9-5735-819d-6f0088450477/ -> 503",
+   "/offices/95ae8a5a-ffd6-c8f7-fa53-9238c0f743f8/ -> 503",
+   "/offices/3c5e3293-d27d-b136-2a02-ec91622d0a93/ -> 503",
+   "/offices/f93d05ef-8b69-a9a7-a436-6351765712f6/ -> 503",
+   "/offices/891ab28c-a186-4f9d-d2ff-65ef725839a5/ -> 503",
+   "/offices/533226f3-0a1d-40e2-0db2-fb049e671bc9/ -> 503",
+   "/offices/18215183-520f-82fb-5654-a564567985b5/ -> 503",
+   "/offices/91b97e4a-3f0b-2759-55cb-d85a475e95eb/ -> 503",
+   "/offices/9feaa467-17fe-f823-33d9-5f21abd75b20/ -> 503",
+   "/offices/f2e1164f-57ea-97c8-1979-c0e54c37fc97/ -> 503",
+   "/offices/94a14c8a-449f-b7dd-f66c-07239bbe62d1/ -> 503",
+   "/offices/0b2331dd-006b-b79e-a3dd-d946a45e0989/ -> 503",
+   "/offices/fd8d29a7-e04b-14ab-910f-494a6a156c3a/ -> 503",
+   "/offices/3aef08d2-6100-0f2f-8eb5-e2962c7160d8/ -> 503",
+   "/offices/2549732c-b16f-a63b-de01-e895271dbe45/ -> 503",
+   "/offices/24170c05-7215-1b15-7368-6fc602c86a66/ -> 503",
+   "/offices/c9bbdc6f-a4d4-f176-9faf-83dd0aaa4016/ -> 503",
+ ]
```

# Page snapshot

```yaml
- generic [active] [ref=e1]:
  - link "← Back to Home" [ref=e2] [cursor=pointer]:
    - /url: /
  - banner [ref=e3]:
    - heading "Federal Offices" [level=1] [ref=e4]
    - paragraph [ref=e5]: President, Senate, and House positions
  - generic [ref=e6]:
    - generic [ref=e7]:
      - generic [ref=e8]: Not signed in
      - generic [ref=e10]:
        - link "Log in" [ref=e11] [cursor=pointer]:
          - /url: /outpost.goauthentik.io/start?rd=http%3A%2F%2Fpreview-us-elect-info.electinfo.svc.cluster.local%2Foffices%2F
        - link "Create an account" [ref=e12] [cursor=pointer]:
          - /url: /signin/register?rd=http%3A%2F%2Fpreview-us-elect-info.electinfo.svc.cluster.local%2Foffices%2F
    - toolbar "Member tools" [ref=e13]:
      - button "All cycles (Sign in to use the cycle facet)" [disabled] [ref=e14] [cursor=pointer]:
        - generic [ref=e18]: All cycles
      - button "Graph (Sign in to use Graph)" [disabled] [ref=e21] [cursor=pointer]:
        - generic [ref=e30]: Graph
  - generic [ref=e33]:
    - generic [ref=e34]:
      - textbox "Search offices..." [ref=e35]
      - button "Search" [ref=e36] [cursor=pointer]
    - generic [ref=e37]:
      - button "All Offices" [ref=e38] [cursor=pointer]
      - button "National" [ref=e39] [cursor=pointer]
      - button "State-wide" [ref=e40] [cursor=pointer]
      - button "District" [ref=e41] [cursor=pointer]
    - generic [ref=e42]:
      - heading "All Offices" [level=3] [ref=e44]
      - generic [ref=e45]:
        - link "President of the United States President - US" [ref=e46] [cursor=pointer]:
          - /url: /offices/684f6e2d-7105-932b-8b7f-94016580f727/
          - generic [ref=e47]: President of the United States
          - generic [ref=e48]: President - US
        - link "U.S. Representative - Alabama District 01 House - AL" [ref=e49] [cursor=pointer]:
          - /url: /offices/7c29b59b-2482-71ba-7557-1ba7e77daa10/
          - generic [ref=e50]: U.S. Representative - Alabama District 01
          - generic [ref=e51]: House - AL
        - link "U.S. Representative - Alabama District 02 House - AL" [ref=e52] [cursor=pointer]:
          - /url: /offices/c0de7219-f25c-7dc2-d406-47a54c1225e8/
          - generic [ref=e53]: U.S. Representative - Alabama District 02
          - generic [ref=e54]: House - AL
        - link "U.S. Representative - Alabama District 03 House - AL" [ref=e55] [cursor=pointer]:
          - /url: /offices/20e183aa-eb55-7916-17e3-bfd156bf9cf2/
          - generic [ref=e56]: U.S. Representative - Alabama District 03
          - generic [ref=e57]: House - AL
        - link "U.S. Representative - Alabama District 04 House - AL" [ref=e58] [cursor=pointer]:
          - /url: /offices/43da91d3-9f25-3e9f-aa08-799f0c2043ad/
          - generic [ref=e59]: U.S. Representative - Alabama District 04
          - generic [ref=e60]: House - AL
        - link "U.S. Representative - Alabama District 05 House - AL" [ref=e61] [cursor=pointer]:
          - /url: /offices/b9c15a02-2752-7905-5fef-cf9fcc262b56/
          - generic [ref=e62]: U.S. Representative - Alabama District 05
          - generic [ref=e63]: House - AL
        - link "U.S. Representative - Alabama District 06 House - AL" [ref=e64] [cursor=pointer]:
          - /url: /offices/c2ae5b3b-a878-91c3-1ac9-7a79511495db/
          - generic [ref=e65]: U.S. Representative - Alabama District 06
          - generic [ref=e66]: House - AL
        - link "U.S. Representative - Alabama District 07 House - AL" [ref=e67] [cursor=pointer]:
          - /url: /offices/9af54520-efe6-415b-0bed-cae1fe1fd830/
          - generic [ref=e68]: U.S. Representative - Alabama District 07
          - generic [ref=e69]: House - AL
        - link "U.S. Representative - Alabama District 12 House - AL" [ref=e70] [cursor=pointer]:
          - /url: /offices/619f3886-426d-8e0b-6141-a10cc7847e13/
          - generic [ref=e71]: U.S. Representative - Alabama District 12
          - generic [ref=e72]: House - AL
        - link "U.S. Representative - Alabama District 13 House - AL" [ref=e73] [cursor=pointer]:
          - /url: /offices/7562ba80-f191-b1df-8e76-54d703e10690/
          - generic [ref=e74]: U.S. Representative - Alabama District 13
          - generic [ref=e75]: House - AL
        - link "U.S. Representative - Alabama District 88 House - AL" [ref=e76] [cursor=pointer]:
          - /url: /offices/ba48d955-6e7e-670e-b85a-2537687c4175/
          - generic [ref=e77]: U.S. Representative - Alabama District 88
          - generic [ref=e78]: House - AL
        - link "U.S. Representative - Alaska District 00 House - AK" [ref=e79] [cursor=pointer]:
          - /url: /offices/62ce3c4e-7e94-b5fb-1d13-1adc42c33a37/
          - generic [ref=e80]: U.S. Representative - Alaska District 00
          - generic [ref=e81]: House - AK
        - link "U.S. Representative - Alaska District 01 House - AK" [ref=e82] [cursor=pointer]:
          - /url: /offices/2c4aa8c6-3f90-7c7c-b60c-6a995ae58f56/
          - generic [ref=e83]: U.S. Representative - Alaska District 01
          - generic [ref=e84]: House - AK
        - link "U.S. Representative - American Samoa District 00 House - AS" [ref=e85] [cursor=pointer]:
          - /url: /offices/6e63f5e1-5a2e-5541-a643-1be9ac075136/
          - generic [ref=e86]: U.S. Representative - American Samoa District 00
          - generic [ref=e87]: House - AS
        - link "U.S. Representative - Arizona District 00 House - AZ" [ref=e88] [cursor=pointer]:
          - /url: /offices/91f59a74-fdb0-4ab4-dfd5-c2c40cad277b/
          - generic [ref=e89]: U.S. Representative - Arizona District 00
          - generic [ref=e90]: House - AZ
        - link "U.S. Representative - Arizona District 01 House - AZ" [ref=e91] [cursor=pointer]:
          - /url: /offices/859cf88c-5c7e-608f-02e1-4ba5cdf53f3e/
          - generic [ref=e92]: U.S. Representative - Arizona District 01
          - generic [ref=e93]: House - AZ
        - link "U.S. Representative - Arizona District 02 House - AZ" [ref=e94] [cursor=pointer]:
          - /url: /offices/b279284d-a3bf-24a2-94b8-0322becdccf4/
          - generic [ref=e95]: U.S. Representative - Arizona District 02
          - generic [ref=e96]: House - AZ
        - link "U.S. Representative - Arizona District 03 House - AZ" [ref=e97] [cursor=pointer]:
          - /url: /offices/8159f3ce-c08b-2eef-dd56-a8a831857505/
          - generic [ref=e98]: U.S. Representative - Arizona District 03
          - generic [ref=e99]: House - AZ
        - link "U.S. Representative - Arizona District 04 House - AZ" [ref=e100] [cursor=pointer]:
          - /url: /offices/556b8f9b-f71d-3211-c77c-96a1ded35121/
          - generic [ref=e101]: U.S. Representative - Arizona District 04
          - generic [ref=e102]: House - AZ
        - link "U.S. Representative - Arizona District 05 House - AZ" [ref=e103] [cursor=pointer]:
          - /url: /offices/82fbdb29-d08e-ad19-d664-580dabfcf109/
          - generic [ref=e104]: U.S. Representative - Arizona District 05
          - generic [ref=e105]: House - AZ
        - link "U.S. Representative - Arizona District 06 House - AZ" [ref=e106] [cursor=pointer]:
          - /url: /offices/2689b72f-c562-9f15-215e-982eb863d544/
          - generic [ref=e107]: U.S. Representative - Arizona District 06
          - generic [ref=e108]: House - AZ
        - link "U.S. Representative - Arizona District 07 House - AZ" [ref=e109] [cursor=pointer]:
          - /url: /offices/3c933155-9169-4ce9-c402-d5ba35879a08/
          - generic [ref=e110]: U.S. Representative - Arizona District 07
          - generic [ref=e111]: House - AZ
        - link "U.S. Representative - Arizona District 08 House - AZ" [ref=e112] [cursor=pointer]:
          - /url: /offices/5a28befd-a223-b925-04a6-9fe9ca6dbc64/
          - generic [ref=e113]: U.S. Representative - Arizona District 08
          - generic [ref=e114]: House - AZ
        - link "U.S. Representative - Arizona District 09 House - AZ" [ref=e115] [cursor=pointer]:
          - /url: /offices/fc78b296-bbc9-4535-4f6d-5493ec10dd7d/
          - generic [ref=e116]: U.S. Representative - Arizona District 09
          - generic [ref=e117]: House - AZ
        - link "U.S. Representative - Arizona District 14 House - AZ" [ref=e118] [cursor=pointer]:
          - /url: /offices/74a6b894-e193-d441-da59-53e3fa721166/
          - generic [ref=e119]: U.S. Representative - Arizona District 14
          - generic [ref=e120]: House - AZ
        - link "U.S. Representative - Arizona District 20 House - AZ" [ref=e121] [cursor=pointer]:
          - /url: /offices/772fc7ae-df97-2a68-fa25-d42a9c708193/
          - generic [ref=e122]: U.S. Representative - Arizona District 20
          - generic [ref=e123]: House - AZ
        - link "U.S. Representative - Arkansas District 01 House - AR" [ref=e124] [cursor=pointer]:
          - /url: /offices/5f2c9e2a-2cff-4165-901f-908650e0fd8c/
          - generic [ref=e125]: U.S. Representative - Arkansas District 01
          - generic [ref=e126]: House - AR
        - link "U.S. Representative - Arkansas District 02 House - AR" [ref=e127] [cursor=pointer]:
          - /url: /offices/d16d2005-352e-ecc7-45b0-0b4f7b8ae684/
          - generic [ref=e128]: U.S. Representative - Arkansas District 02
          - generic [ref=e129]: House - AR
        - link "U.S. Representative - Arkansas District 03 House - AR" [ref=e130] [cursor=pointer]:
          - /url: /offices/2982aecb-9d48-f36f-88d9-fc40b82b4610/
          - generic [ref=e131]: U.S. Representative - Arkansas District 03
          - generic [ref=e132]: House - AR
        - link "U.S. Representative - Arkansas District 04 House - AR" [ref=e133] [cursor=pointer]:
          - /url: /offices/353ad230-3b7d-a4fb-2531-9ed591bab14b/
          - generic [ref=e134]: U.S. Representative - Arkansas District 04
          - generic [ref=e135]: House - AR
        - link "U.S. Representative - California District 00 House - CA" [ref=e136] [cursor=pointer]:
          - /url: /offices/de60e95b-1dc2-2ec3-b731-620ae5bd1d99/
          - generic [ref=e137]: U.S. Representative - California District 00
          - generic [ref=e138]: House - CA
        - link "U.S. Representative - California District 01 House - CA" [ref=e139] [cursor=pointer]:
          - /url: /offices/9c5a47f9-0595-9cc6-e2c9-0e3947a52975/
          - generic [ref=e140]: U.S. Representative - California District 01
          - generic [ref=e141]: House - CA
        - link "U.S. Representative - California District 02 House - CA" [ref=e142] [cursor=pointer]:
          - /url: /offices/3ac0c724-530d-109e-6ac9-c365eb9955a6/
          - generic [ref=e143]: U.S. Representative - California District 02
          - generic [ref=e144]: House - CA
        - link "U.S. Representative - California District 03 House - CA" [ref=e145] [cursor=pointer]:
          - /url: /offices/f3358a0f-10e9-5735-819d-6f0088450477/
          - generic [ref=e146]: U.S. Representative - California District 03
          - generic [ref=e147]: House - CA
        - link "U.S. Representative - California District 04 House - CA" [ref=e148] [cursor=pointer]:
          - /url: /offices/95ae8a5a-ffd6-c8f7-fa53-9238c0f743f8/
          - generic [ref=e149]: U.S. Representative - California District 04
          - generic [ref=e150]: House - CA
        - link "U.S. Representative - California District 05 House - CA" [ref=e151] [cursor=pointer]:
          - /url: /offices/3c5e3293-d27d-b136-2a02-ec91622d0a93/
          - generic [ref=e152]: U.S. Representative - California District 05
          - generic [ref=e153]: House - CA
        - link "U.S. Representative - California District 06 House - CA" [ref=e154] [cursor=pointer]:
          - /url: /offices/f93d05ef-8b69-a9a7-a436-6351765712f6/
          - generic [ref=e155]: U.S. Representative - California District 06
          - generic [ref=e156]: House - CA
        - link "U.S. Representative - California District 07 House - CA" [ref=e157] [cursor=pointer]:
          - /url: /offices/891ab28c-a186-4f9d-d2ff-65ef725839a5/
          - generic [ref=e158]: U.S. Representative - California District 07
          - generic [ref=e159]: House - CA
        - link "U.S. Representative - California District 08 House - CA" [ref=e160] [cursor=pointer]:
          - /url: /offices/533226f3-0a1d-40e2-0db2-fb049e671bc9/
          - generic [ref=e161]: U.S. Representative - California District 08
          - generic [ref=e162]: House - CA
        - link "U.S. Representative - California District 09 House - CA" [ref=e163] [cursor=pointer]:
          - /url: /offices/18215183-520f-82fb-5654-a564567985b5/
          - generic [ref=e164]: U.S. Representative - California District 09
          - generic [ref=e165]: House - CA
        - link "U.S. Representative - California District 10 House - CA" [ref=e166] [cursor=pointer]:
          - /url: /offices/91b97e4a-3f0b-2759-55cb-d85a475e95eb/
          - generic [ref=e167]: U.S. Representative - California District 10
          - generic [ref=e168]: House - CA
        - link "U.S. Representative - California District 11 House - CA" [ref=e169] [cursor=pointer]:
          - /url: /offices/9feaa467-17fe-f823-33d9-5f21abd75b20/
          - generic [ref=e170]: U.S. Representative - California District 11
          - generic [ref=e171]: House - CA
        - link "U.S. Representative - California District 12 House - CA" [ref=e172] [cursor=pointer]:
          - /url: /offices/f2e1164f-57ea-97c8-1979-c0e54c37fc97/
          - generic [ref=e173]: U.S. Representative - California District 12
          - generic [ref=e174]: House - CA
        - link "U.S. Representative - California District 13 House - CA" [ref=e175] [cursor=pointer]:
          - /url: /offices/94a14c8a-449f-b7dd-f66c-07239bbe62d1/
          - generic [ref=e176]: U.S. Representative - California District 13
          - generic [ref=e177]: House - CA
        - link "U.S. Representative - California District 14 House - CA" [ref=e178] [cursor=pointer]:
          - /url: /offices/0b2331dd-006b-b79e-a3dd-d946a45e0989/
          - generic [ref=e179]: U.S. Representative - California District 14
          - generic [ref=e180]: House - CA
        - link "U.S. Representative - California District 15 House - CA" [ref=e181] [cursor=pointer]:
          - /url: /offices/fd8d29a7-e04b-14ab-910f-494a6a156c3a/
          - generic [ref=e182]: U.S. Representative - California District 15
          - generic [ref=e183]: House - CA
        - link "U.S. Representative - California District 16 House - CA" [ref=e184] [cursor=pointer]:
          - /url: /offices/3aef08d2-6100-0f2f-8eb5-e2962c7160d8/
          - generic [ref=e185]: U.S. Representative - California District 16
          - generic [ref=e186]: House - CA
        - link "U.S. Representative - California District 17 House - CA" [ref=e187] [cursor=pointer]:
          - /url: /offices/2549732c-b16f-a63b-de01-e895271dbe45/
          - generic [ref=e188]: U.S. Representative - California District 17
          - generic [ref=e189]: House - CA
        - link "U.S. Representative - California District 18 House - CA" [ref=e190] [cursor=pointer]:
          - /url: /offices/24170c05-7215-1b15-7368-6fc602c86a66/
          - generic [ref=e191]: U.S. Representative - California District 18
          - generic [ref=e192]: House - CA
        - link "U.S. Representative - California District 19 House - CA" [ref=e193] [cursor=pointer]:
          - /url: /offices/c9bbdc6f-a4d4-f176-9faf-83dd0aaa4016/
          - generic [ref=e194]: U.S. Representative - California District 19
          - generic [ref=e195]: House - CA
      - generic [ref=e196]:
        - generic [ref=e197]: Showing 1-50
        - generic [ref=e198]:
          - button "First" [disabled] [ref=e199]
          - button "Prev" [disabled] [ref=e200]
          - button "1" [ref=e201] [cursor=pointer]
          - button "Next" [ref=e202] [cursor=pointer]
  - main [ref=e203]
```

# Test source

```ts
  1   | import { test, expect, APIRequestContext } from '@playwright/test';
  2   | import { canonicalPath, getRandomItems, premiumGated, toRelativePath } from './helpers';
  3   | 
  4   | /*
  5   |  * Routing coverage across every collection (electinfo/rundeck#700, ops#514).
  6   |  *
  7   |  * What slipped past the existing specs:
  8   |  *   - the preview nginx lacked the /politicians/ -> /candidates/ rewrite the
  9   |  *     production config has (sites#162) -- only 3 random index links were followed;
  10  |  *   - unknown paths fall through to the Payload slug lookup, which answers
  11  |  *     400/500 instead of 404.
  12  |  */
  13  | 
  14  | const ALIASES = process.env.EXPECT_ALIASES === '1';
  15  | 
  16  | /** Collections whose sitemap lists canonical URLs (rundeck PagePaths Sitemaps + CyclePages). */
  17  | const SITEMAP_COLLECTIONS = ['candidates', 'committees', 'parties', 'offices', 'districts', 'states', 'elections'];
  18  | 
  19  | /** Indexes whose first results page lists entity links (.entity-search-result). */
  20  | // (/states/ lists map chips — its sitemap test covers it; /districts/ uses the
  21  | // shared EntityIndex and lists .entity-search-result directly, so it is included here)
  22  | const LINKED_INDEXES = ['/candidates/', '/committees/', '/parties/', '/offices/', '/districts/', '/elections/', '/employers/', '/vendors/'];
  23  | 
  24  | const locs = (xml: string) => [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map(m => m[1]);
  25  | 
  26  | /** Canonical page URLs from a collection's sitemap, following one level of sitemap index. */
  27  | async function sitemapLocs(request: APIRequestContext, collection: string): Promise<string[]> {
  28  |   const path = `/${collection}/sitemap-${collection}.xml`;
  29  |   const res = await request.get(path);
  30  |   expect(res.status(), `${path} should answer 200`).toBe(200);
  31  |   const xml = await res.text();
  32  |   if (!xml.includes('<sitemapindex')) return locs(xml);
  33  |   const [child] = getRandomItems(locs(xml), 1, `child:${path}`);
  34  |   const childPath = toRelativePath(child);
  35  |   const childRes = await request.get(childPath);
  36  |   expect(childRes.status(), `${childPath} should answer 200`).toBe(200);
  37  |   return locs(await childRes.text());
  38  | }
  39  | 
  40  | test.describe('routing: canonical URLs per collection', () => {
  41  |   test.skip(!ALIASES, 'Set EXPECT_ALIASES=1 against a target with published page paths');
  42  | 
  43  |   for (const collection of SITEMAP_COLLECTIONS) {
  44  |     test(`${collection}: sitemap URLs serve their page with rel=canonical = the sitemap URL`, async ({ request }) => {
  45  |       // Entity pages only: a sitemap may also list the collection's index (/elections/)
  46  |       const entityLocs = (await sitemapLocs(request, collection)).filter(l => toRelativePath(l) !== `/${collection}/`);
  47  |       const sample = getRandomItems(entityLocs, 3);
  48  |       expect(sample.length, `${collection} sitemap should list URLs`).toBeGreaterThan(0);
  49  |       for (const loc of sample) {
  50  |         const path = toRelativePath(loc);
  51  |         const res = await request.get(path, { maxRedirects: 0 });
  52  |         expect(res.status(), `${path} (from the ${collection} sitemap) should answer 200`).toBe(200);
  53  |         expect(canonicalPath(await res.text()), `${path} rel=canonical`).toBe(path);
  54  |       }
  55  |     });
  56  |   }
  57  | 
  58  | 
  59  |   test('party badge links by FEC code redirect to the party page', async ({ request }) => {
  60  |     // us.elect.news links parties as /parties/<code>/ (sites#164)
  61  |     for (const code of ['rep', 'dem']) {
  62  |       const res = await request.get(`/parties/${code}/`, { maxRedirects: 0 });
  63  |       expect(res.status(), `/parties/${code}/ should redirect permanently`).toBe(301);
  64  |       const target = res.headers()['location'] ?? '';
  65  |       const page = await request.get(target, { maxRedirects: 0 });
  66  |       expect(page.status(), `/parties/${code}/ -> ${target} should answer 200`).toBe(200);
  67  |     }
  68  |   });
  69  | });
  70  | 
  71  | test.describe('routing: every index link resolves', () => {
  72  |   for (const index of LINKED_INDEXES) {
  73  |     test(`${index} first-page links all answer 200 or 301`, async ({ page, request }) => {
  74  |       test.setTimeout(120000);
  75  |       const res = await page.goto(index);
  76  |       expect(res?.status(), `${index} should answer 200`).toBe(200);
  77  |       await expect(page.locator('.entity-search-result').first(), `${index} should list results`).toBeVisible({ timeout: 15000 });
  78  |       const hrefs = (await page.locator('.entity-search-result').evaluateAll(els => els.map(e => e.getAttribute('href'))))
  79  |         .filter((h): h is string => !!h)
  80  |         .map(toRelativePath);
  81  |       const broken: string[] = [];
  82  |       for (const href of [...new Set(hrefs)]) {
  83  |         const r = await request.get(href, { maxRedirects: 0 });
  84  |         if (r.status() !== 200 && r.status() !== 301) broken.push(`${href} -> ${r.status()}`);
  85  |       }
> 86  |       expect(broken, `${index} links that do not resolve`).toEqual([]);
      |                                                            ^ Error: /offices/ links that do not resolve
  87  |     });
  88  |   }
  89  | });
  90  | 
  91  | test.describe('routing: unknown addresses', () => {
  92  |   test('an unknown entity path answers 404', async ({ request }) => {
  93  |     // A miss in /_resolve (or the API being unavailable) ends in nginx's own
  94  |     // 404. It used to fall through to Payload's slug-lookup, which answered
  95  |     // 400/500 (electinfo/sites#218). Only the alias-routed collections apply:
  96  |     // leaf collections are covered below.
  97  |     for (const path of ['/candidates/no-such-entity-zz/', '/committees/no-such-entity-zz/']) {
  98  |       const res = await request.get(path, { maxRedirects: 0 });
  99  |       expect(res.status(), `${path} should answer 404`).toBe(404);
  100 |     }
  101 |   });
  102 | 
  103 |   test('an unknown leaf entity path serves the collection shell', async ({ request }) => {
  104 |     // Leaf collections (individuals, employers, vendors, blocks, precincts,
  105 |     // tracts) render client-side from the baked collection shell (sites#209),
  106 |     // so nginx answers every subpath with that shell and the runtime reports
  107 |     // a missing entity itself. There is no server-side 404 to expect here.
  108 |     for (const col of ['individuals', 'employers', 'vendors', 'blocks', 'precincts', 'tracts']) {
  109 |       // A premium section closed to this visitor answers sign-in or 403 instead (auth.spec.ts).
  110 |       if (await premiumGated(request, `/${col}/`)) continue;
  111 |       const res = await request.get(`/${col}/no-such-entity-zz/`, { maxRedirects: 0 });
  112 |       expect(res.status(), `/${col}/no-such-entity-zz/ should serve the shell`).toBe(200);
  113 |       expect(res.headers()['content-type'] ?? '', `/${col}/ shell is HTML`).toContain('text/html');
  114 |     }
  115 |   });
  116 | });
  117 | 
```