# 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/page-aliases.spec.ts >> static page aliases >> legacy URL shapes redirect to the canonical URL
- Location: tests/ui/page-aliases.spec.ts:73:7

# Error details

```
Error: expect(received).toContain(expected) // indexOf

Expected substring: "max-age=86400"
Received string:    "public, max-age=300"
```

# Test source

```ts
  1  | import { test, expect, APIResponse } from '@playwright/test';
  2  | 
  3  | // Static-page addressing (electinfo/rundeck#700): pages are stored at
  4  | // /<collection>/<uuid>/, each has one canonical (vanity) URL, and every other
  5  | // address is an alias the njs handler serves from /static-pages/_aliases/.
  6  | //
  7  | // These checks need a target whose aliases have been published by the
  8  | // PagePaths AliasPublish stage, so they run only when EXPECT_ALIASES=1
  9  | // (sites-preview-e2e after a preview data run, or a front-door check).
  10 | // The fixtures are stable: entity ids are UUID5 of the natural key.
  11 | 
  12 | const enabled = process.env.EXPECT_ALIASES === '1';
  13 | 
  14 | const AK_STATE_UUID = '032f8d61-f554-f435-2a6d-50b3c8cc01d7'; // UUID5('State', 'AK')
  15 | const P40012809_UUID = 'eb6fa940-ff44-efdf-2ffb-166ce3073b5c'; // UUID5('Candidate', 'P40012809')
  16 | 
  17 | /** The path of the page's rel=canonical, whatever host the page was generated for. */
  18 | function canonicalPath(html: string): string | null {
  19 |   const m = html.match(/<link[^>]+rel=['"]canonical['"][^>]+href=['"]([^'"]+)['"]/i)
  20 |     ?? html.match(/<link[^>]+href=['"]([^'"]+)['"][^>]+rel=['"]canonical['"]/i);
  21 |   if (!m) return null;
  22 |   try {
  23 |     return new URL(m[1]).pathname;
  24 |   } catch {
  25 |     return m[1];
  26 |   }
  27 | }
  28 | 
  29 | async function expectServed(res: APIResponse, canonical: string | RegExp) {
  30 |   expect(res.status(), `${res.url()} should be served`).toBe(200);
  31 |   const path = canonicalPath(await res.text());
  32 |   expect(path, `${res.url()} should carry a rel=canonical`).not.toBeNull();
  33 |   if (typeof canonical === 'string') expect(path).toBe(canonical);
  34 |   else expect(path).toMatch(canonical);
  35 | }
  36 | 
  37 | function expectRedirect(res: APIResponse, location: string | RegExp) {
  38 |   expect(res.status(), `${res.url()} should redirect permanently`).toBe(301);
  39 |   const loc = res.headers()['location'] ?? '';
  40 |   if (typeof location === 'string') expect(loc).toBe(location);
  41 |   else expect(loc).toMatch(location);
> 42 |   expect(res.headers()['cache-control'] ?? '').toContain('max-age=86400');
     |                                                ^ Error: expect(received).toContain(expected) // indexOf
  43 | }
  44 | 
  45 | test.describe('static page aliases', () => {
  46 |   test.skip(!enabled, 'Set EXPECT_ALIASES=1 against a target with published aliases');
  47 | 
  48 |   test('canonical vanity URL serves the stored page', async ({ request }) => {
  49 |     await expectServed(await request.get('/states/alaska/', { maxRedirects: 0 }), '/states/alaska/');
  50 |   });
  51 | 
  52 |   test('vanity lookup ignores case, trailing slash and index.html', async ({ request }) => {
  53 |     for (const path of ['/STATES/Alaska/', '/states/alaska', '/states/alaska/index.html']) {
  54 |       await expectServed(await request.get(path, { maxRedirects: 0 }), '/states/alaska/');
  55 |     }
  56 |   });
  57 | 
  58 |   test('UUID URL serves the page with its vanity canonical', async ({ request }) => {
  59 |     await expectServed(await request.get(`/states/${AK_STATE_UUID}/`, { maxRedirects: 0 }), '/states/alaska/');
  60 |     await expectServed(
  61 |       await request.get(`/candidates/${P40012809_UUID}/`, { maxRedirects: 0 }),
  62 |       /^\/candidates\/[a-z0-9-]+-p40012809\/$/,
  63 |     );
  64 |   });
  65 | 
  66 |   test('secondary keys redirect to the canonical URL', async ({ request }) => {
  67 |     expectRedirect(await request.get('/states/ak/', { maxRedirects: 0 }), '/states/alaska/');
  68 |     expectRedirect(await request.get('/parties/dem/', { maxRedirects: 0 }), '/parties/democratic/');
  69 |     expectRedirect(await request.get('/counties/06037/', { maxRedirects: 0 }), /^\/counties\/los-angeles-county-ca\/$/);
  70 |     expectRedirect(await request.get('/candidates/p40012809/', { maxRedirects: 0 }), /^\/candidates\/[a-z0-9-]+-p40012809\/$/);
  71 |   });
  72 | 
  73 |   test('legacy URL shapes redirect to the canonical URL', async ({ request }) => {
  74 |     expectRedirect(await request.get('/districts/ca/27/', { maxRedirects: 0 }), '/districts/ca-27/');
  75 |     expectRedirect(await request.get('/offices/senate/ca/', { maxRedirects: 0 }), '/offices/senate/california/');
  76 |     expectRedirect(await request.get('/cycles/cycle-2024/', { maxRedirects: 0 }), '/elections/2024/');
  77 |   });
  78 | 
  79 |   test('redirect targets are served', async ({ request }) => {
  80 |     for (const path of ['/districts/ca-27/', '/offices/senate/california/', '/elections/2024/', '/parties/democratic/']) {
  81 |       await expectServed(await request.get(path, { maxRedirects: 0 }), path);
  82 |     }
  83 |   });
  84 | 
  85 |   test('an unknown address is not served as a page', async ({ request }) => {
  86 |     const res = await request.get('/states/not-a-state-zz/', { maxRedirects: 0 });
  87 |     expect(res.status()).not.toBe(200);
  88 |   });
  89 | });
  90 | 
```