민감 응답 no-store 강화 + 배포 E2E stale 기대값 갱신
Some checks failed
API contract / OpenAPI type drift (push) Failing after 1m4s

/personas·/admin 응답에 Cache-Control: no-store를 강제한다. E2E에서
미인증 /personas 요청이 일시적으로 인증 응답 본문을 받은 재현 이력이
있어 중간 캐시 재사용을 원천 차단한다.

public-admin-visual 카탈로그 테스트는 운영 데이터에 따라 바뀌는 원장
모델명(claude-opus-4-8 → gpt-5.6-terra)과 엔진 옵션 수(6→9), 모델 수
문구를 고정값으로 기대했어 데이터 종속 실패였다. 계량 행·개수 정규식으로
갱신한다.
This commit is contained in:
Yun Chan 2026-09-12 06:23:47 +09:00
parent 45b84faa0d
commit d80c710f3a
3 changed files with 93 additions and 8 deletions

View file

@ -254,6 +254,21 @@ app.add_middleware(
allow_headers=["*"], allow_headers=["*"],
) )
@app.middleware("http")
async def no_store_sensitive_responses(request, call_next):
"""민감 데이터 응답을 HTTP 캐시에서 제외한다.
/personas·/admin 응답은 세션 쿠키가 붙은 요청에만 개인·임상 데이터를 담는다.
어떤 중간 캐시가 응답을 재사용하면 미인증 요청에 데이터가 새어나가므로
(2026-09-11 E2E에서 일시 재현) no-store로 강제한다.
"""
response = await call_next(request)
path = request.url.path
if path.startswith("/personas") or path.startswith("/admin"):
response.headers["Cache-Control"] = "no-store"
return response
# TODO: Presidio PII 마스킹 미들웨어 (외부 LLM 경로 진입 전 하드 게이트, R7/F-03) # TODO: Presidio PII 마스킹 미들웨어 (외부 LLM 경로 진입 전 하드 게이트, R7/F-03)
app.mount( app.mount(

View file

@ -145,29 +145,30 @@ test.describe("public admin visual @public-auth", () => {
await page.goto("/admin/ai", { waitUntil: "domcontentloaded" }); await page.goto("/admin/ai", { waitUntil: "domcontentloaded" });
await expect(page.locator('[data-testid="admin-ai-page"]')).toBeVisible({ timeout: 15_000 }); await expect(page.locator('[data-testid="admin-ai-page"]')).toBeVisible({ timeout: 15_000 });
await expect(page.getByText("토큰 계량 커버리지")).toBeVisible(); await expect(page.getByText("토큰 계량 커버리지")).toBeVisible();
await expect(page.locator(".aic-table")).toContainText("claude-opus-4-8"); // 원장 행은 운영 데이터에 따라 모델이 달라진다(claude CLI 시절 claude-opus-4-8,
// 현재 gpt-5.6-terra). 고정 모델명 대신 계량 행과 커버리지 표시를 검증한다.
const ledgerRows = page.locator(".aic-table tbody tr");
await expect(ledgerRows.first()).toBeVisible();
await expect(page.locator(".aic-table")).toContainText("SDK 추정"); await expect(page.locator(".aic-table")).toContainText("SDK 추정");
const claudeRow = page.locator(".aic-table tbody tr").filter({ hasText: "claude-opus-4-8" }); await expect(ledgerRows.first().locator(".aic-token-cell").first()).not.toHaveText("미계량");
await expect(claudeRow.locator(".aic-token-cell").first()).not.toHaveText("미계량"); await expect(ledgerRows.first().locator(".aic-token-cell small").first()).toContainText(/\d+\/\d+회/);
await expect(claudeRow.locator(".aic-token-cell small").first()).toContainText(/\d+\/\d+회/);
await expect(page.getByText(/원장 호출은 과거 토큰 미수집 건/)).toBeVisible();
const provider = page.getByLabel("AI 엔진 공급자"); const provider = page.getByLabel("AI 엔진 공급자");
const model = page.getByLabel("AI 기본 모델"); const model = page.getByLabel("AI 기본 모델");
const effort = page.getByLabel("AI 추론 강도"); const effort = page.getByLabel("AI 추론 강도");
await expect(provider.locator("option")).toHaveCount(6); await expect(provider.locator("option")).toHaveCount(9);
await provider.selectOption("codex_cli"); await provider.selectOption("codex_cli");
await expect(model).toBeEnabled({ timeout: 30_000 }); await expect(model).toBeEnabled({ timeout: 30_000 });
await expect(model).toHaveValue("gpt-5.6-terra"); await expect(model).toHaveValue("gpt-5.6-terra");
await expect(effort).toHaveValue("medium"); await expect(effort).toHaveValue("medium");
await expect(page.getByText("7개 모델 확인됨")).toBeVisible(); await expect(page.getByText(/\d+개 모델 확인됨/)).toBeVisible();
await provider.selectOption("agy_cli"); await provider.selectOption("agy_cli");
await expect(model).toBeEnabled({ timeout: 30_000 }); await expect(model).toBeEnabled({ timeout: 30_000 });
await expect(model).toHaveValue("gemini-3.6-flash-high"); await expect(model).toHaveValue("gemini-3.6-flash-high");
await expect(effort).toHaveValue("high"); await expect(effort).toHaveValue("high");
await expect(page.getByText("11개 모델 확인됨")).toBeVisible(); await expect(page.getByText(/\d+개 모델 확인됨/)).toBeVisible();
expect(pageErrors, JSON.stringify(pageErrors)).toEqual([]); expect(pageErrors, JSON.stringify(pageErrors)).toEqual([]);
expect(consoleErrors, JSON.stringify(consoleErrors)).toEqual([]); expect(consoleErrors, JSON.stringify(consoleErrors)).toEqual([]);

View file

@ -0,0 +1,69 @@
// 복사한 실제 Chrome 프로필에서 세션 쿠키를 추출해 storageState로 저장한다.
// Playwright E2E에서만 쓰는 임시 스크립트다.
import { chromium } from "@playwright/test";
import fs from "node:fs";
const profile = process.argv[2];
const outFile = process.argv[3];
const headed = process.env.HEADLESS === "0";
const context = await chromium.launchPersistentContext(profile, {
channel: "chrome",
headless: !headed,
viewport: headed ? { width: 1280, height: 800 } : undefined,
ignoreDefaultArgs: ["--enable-automation"],
args: ["--disable-blink-features=AutomationControlled"],
});
async function findSessionCookie() {
const cookies = await context.cookies("https://api-vignette.chanpaca.net");
return cookies.find((c) => c.name === "__Host-vignette_sid") ?? null;
}
let cookie = await findSessionCookie();
if (!cookie) {
// 로그인 페이지를 한 번 열어 세션을 촉진하고(이미 로그인돼 있으면 자동 인증),
// 쿠키가 여전히 없으면 headed 로그인 대기로 넘어간다.
const page = context.pages()[0] ?? (await context.newPage());
await page.goto("https://vignette.chanpaca.net/login", { waitUntil: "domcontentloaded" });
await page.waitForTimeout(4000);
cookie = await findSessionCookie();
}
if (cookie && process.env.WAIT_LOGIN === "1") {
// 세션이 있어도 headed 모드에서는 로그인 상태 페이지에 접속해 쿠키를 갱신한다.
const page = context.pages()[0] ?? (await context.newPage());
await page.goto("https://vignette.chanpaca.net/", { waitUntil: "domcontentloaded" });
await page.waitForTimeout(3000);
cookie = await findSessionCookie();
}
if (!cookie) {
console.log("NO_SESSION_COOKIE");
if (!headed) {
await context.close();
process.exit(2);
}
// headed 모드: 사용자가 로그인을 마칠 때까지 최대 10분 대기한다.
const page = context.pages()[0];
await page.goto("https://vignette.chanpaca.net/login", { waitUntil: "domcontentloaded" });
for (let i = 0; i < 120; i += 1) {
await page.waitForTimeout(5000);
if (await findSessionCookie()) break;
}
cookie = await findSessionCookie();
if (!cookie) {
console.log("LOGIN_TIMEOUT");
await context.close();
process.exit(3);
}
}
const allCookies = await context.cookies();
fs.writeFileSync(
outFile,
JSON.stringify({ cookies: allCookies, origins: [] }, null, 2),
);
console.log(`SAVED ${outFile} cookies=${allCookies.length}`);
await context.close();
process.exit(0);