scroll-restoration, production-csp, old-tab-chunk-recovery, boot-module-failure는 템플릿처럼 page.goto 뒤 첫 expect(5초) 안에 첫 화면이 그려지기를 기다린다. desktop 호스트의 WebKit은 화면 하나를 여는 데 혼자 돌 때도 3.8~4.6초가 걸린다(Case 화면, Chromium 0.93초). 그래서 다른 worker와 함께 돌면 5초를 넘겨 「불러오는 중」에서 떨어진다. 전체 test:e2e와 3회 반복에서 webkit만 이렇게 떨어졌다. 이 제품의 다른 브라우저 시험처럼 앱이 그려진 것(.site-frame, 부팅 실패면 alert)을 먼저 기다린다. scroll-restoration은 gotoTechLog로 연다. 시험하는 것(스크롤 위치, CSP, 다시 불러오기 횟수, 실패 화면 내용)은 그대로다. 부팅 실패 청크 수정 전후 WebKit 시간이 같아서(JS 14개일 때 3.8~4.6초, 36개일 때 3.8~4.1초) 청크 수가 원인은 아니다. 검증: 네 시험과 app-shell을 chromium·firefox·webkit에서 --repeat-each=3으로 81건 모두 통과.
77 lines
3.2 KiB
TypeScript
77 lines
3.2 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
|
|
import { expect, test, type Page } from "../support/browser/strict-browser-test.ts";
|
|
|
|
// 13-08. The Content-Security-Policy in config/hosting/security-headers.json was
|
|
// declared but never applied in a browser: `vite preview` sends no security
|
|
// headers. This smoke serves the build with the production headers attached
|
|
// and fails on any securitypolicyviolation event or console error.
|
|
const { headers: declaredHeaders } = JSON.parse(
|
|
readFileSync("config/hosting/security-headers.json", "utf8"),
|
|
) as { headers: Record<string, string> };
|
|
// The preview server is plain HTTP on loopback. `upgrade-insecure-requests` is a
|
|
// no-op for an HTTPS origin, but WebKit applies it to loopback and rewrites
|
|
// every same-origin request to https, which this server cannot answer. Every
|
|
// other directive is served exactly as declared.
|
|
const securityHeaders = {
|
|
...declaredHeaders,
|
|
"Content-Security-Policy": declaredHeaders["Content-Security-Policy"]!
|
|
.split(";")
|
|
.map((directive) => directive.trim())
|
|
.filter((directive) => directive !== "upgrade-insecure-requests")
|
|
.join("; "),
|
|
};
|
|
|
|
// F-7. No zod setup here: the app sets `jitless` in src/contracts/zod.ts before
|
|
// any schema is built, so zod's `Function("")` probe never reaches the policy.
|
|
test.beforeEach(async ({ page, baseURL }) => {
|
|
const origin = new URL(baseURL ?? "http://127.0.0.1:4173").origin;
|
|
await page.route(
|
|
(url) => url.origin === origin,
|
|
async (route) => {
|
|
const response = await route.fetch();
|
|
await route.fulfill({
|
|
response,
|
|
headers: { ...response.headers(), ...securityHeaders },
|
|
});
|
|
},
|
|
);
|
|
await page.addInitScript(() => {
|
|
const violations: string[] = [];
|
|
Object.defineProperty(window, "__cspViolations", { value: violations });
|
|
document.addEventListener("securitypolicyviolation", (event) => {
|
|
violations.push(`${event.effectiveDirective} ${event.blockedURI}`);
|
|
});
|
|
});
|
|
});
|
|
|
|
async function cspViolations(page: Page): Promise<string[]> {
|
|
return page.evaluate(() => (window as unknown as { __cspViolations: string[] }).__cspViolations);
|
|
}
|
|
|
|
test("boots and changes route under the production security headers", async ({ page }) => {
|
|
const response = await page.goto("/");
|
|
// The app draws after the document loads; see scroll-restoration.spec.ts.
|
|
await page.locator(".site-frame").waitFor();
|
|
expect(response?.headers()["content-security-policy"]).toBe(
|
|
securityHeaders["Content-Security-Policy"],
|
|
);
|
|
// Template sync (af3d8e6): TechLog's home and a primary-navigation page in
|
|
// place of upstream's example screens.
|
|
await expect(page.getByRole("heading", { level: 1 })).toHaveText("TechLog");
|
|
|
|
await page
|
|
.getByRole("navigation", { name: "주요 탐색" })
|
|
.getByRole("link", { name: "프로젝트" })
|
|
.click();
|
|
// Upstream also waits for route focus here. TechLog's Public shell does not
|
|
// move focus on navigation (app-router.tsx leaves it to the shell); that is
|
|
// app-shell.spec.ts's to check, so this smoke stays about the policy.
|
|
await expect(page).toHaveURL(/\/projects$/);
|
|
await expect(
|
|
page.getByRole("heading", { level: 1, name: "프로젝트" }),
|
|
).toBeVisible();
|
|
|
|
expect(await cspViolations(page)).toEqual([]);
|
|
});
|