라우터 7 동기 갱신 복구와 E2E 격리 수정, 검증 기록 동기화
Some checks failed
API contract / OpenAPI type drift (push) Failing after 3m30s

This commit is contained in:
Yun Chan 2026-10-24 21:55:17 +09:00
parent d801a1619d
commit b0ff44a1d4
9 changed files with 236 additions and 154 deletions

View file

@ -10,6 +10,10 @@ import { expect, test, type APIResponse, type Page } from "@playwright/test";
import {
acquireGlobalEngineConfigLock,
completeAlliancePreCheckpoint,
installControlledEngineConfig,
readEngineConfigSnapshot,
restoreEngineConfig,
type EngineConfigSnapshot,
} from "./support";
const API_PORT = 8018;
@ -29,15 +33,6 @@ interface ManagedServer {
requests: () => string[];
}
interface EngineConfigSnapshot {
engine_mode: string;
engine_url: string;
model: string;
reasoning_effort: string | null;
updated_by: string | null;
updated_at: string | null;
}
interface AdminEngineConfigResponse {
engine_mode: string;
engine_url: string;
@ -348,6 +343,8 @@ async function startApi(engineUrl: string): Promise<ManagedProcess> {
ENGINE_URL: engineUrl,
ENGINE_MODE: "claude_api",
VIGNETTE_LIVE_CLIENT_PROVIDER: "claude_api",
// apps/api/.env의 jev가 상속되면 가짜 엔진 호출 전에 OpenRouter 외부 호출이 끼어든다.
VIGNETTE_CLIENT_AFFECT_PROVIDER: "legacy",
ENGINE_TIMEOUT: "20",
ENGINE_CONNECT_TIMEOUT: "2",
EVALUATOR_SEMANTIC_CACHE_ENABLED: "false",
@ -447,86 +444,6 @@ function runPsql(sql: string): string {
return String(result.stdout).trim();
}
function sqlTextValue(value: string | null): string {
return value === null ? "NULL" : `'${value.replaceAll("'", "''")}'`;
}
function readEngineConfigSnapshot(): EngineConfigSnapshot | null {
const raw = runPsql(`
SELECT COALESCE(
(
SELECT json_build_object(
'engine_mode', engine_mode,
'engine_url', engine_url,
'model', model,
'reasoning_effort', reasoning_effort,
'updated_by', updated_by,
'updated_at', updated_at
)::text
FROM app.admin_engine_config
WHERE id = TRUE
),
'null'
);
`);
return raw === "null" ? null : (JSON.parse(raw) as EngineConfigSnapshot);
}
function installControlledEngineConfig(engineUrl: string): void {
runPsql(`
INSERT INTO app.admin_engine_config (
id, engine_mode, engine_url, model, reasoning_effort, updated_by, updated_at
)
VALUES (
TRUE, 'claude_api', ${sqlTextValue(engineUrl)}, 'req005-controlled', 'medium',
'req005-e2e', now()
)
ON CONFLICT (id) DO UPDATE SET
engine_mode = EXCLUDED.engine_mode,
engine_url = EXCLUDED.engine_url,
model = EXCLUDED.model,
reasoning_effort = EXCLUDED.reasoning_effort,
updated_by = EXCLUDED.updated_by,
updated_at = EXCLUDED.updated_at;
`);
expect(readEngineConfigSnapshot()).toMatchObject({
engine_mode: "claude_api",
engine_url: engineUrl,
model: "req005-controlled",
reasoning_effort: "medium",
updated_by: "req005-e2e",
});
}
function restoreEngineConfig(snapshot: EngineConfigSnapshot | null): void {
if (snapshot === null) {
runPsql("DELETE FROM app.admin_engine_config WHERE id = TRUE;");
} else {
runPsql(`
INSERT INTO app.admin_engine_config (
id, engine_mode, engine_url, model, reasoning_effort, updated_by, updated_at
)
VALUES (
TRUE,
${sqlTextValue(snapshot.engine_mode)},
${sqlTextValue(snapshot.engine_url)},
${sqlTextValue(snapshot.model)},
${sqlTextValue(snapshot.reasoning_effort)},
${sqlTextValue(snapshot.updated_by)},
${sqlTextValue(snapshot.updated_at)}::timestamptz
)
ON CONFLICT (id) DO UPDATE SET
engine_mode = EXCLUDED.engine_mode,
engine_url = EXCLUDED.engine_url,
model = EXCLUDED.model,
reasoning_effort = EXCLUDED.reasoning_effort,
updated_by = EXCLUDED.updated_by,
updated_at = EXCLUDED.updated_at;
`);
}
expect(readEngineConfigSnapshot()).toEqual(snapshot);
}
function sqlUuidArray(values: Iterable<string>): string {
const rows = [...values];
return rows.length ? `ARRAY[${rows.map((value) => `'${value}'::uuid`).join(",")}]` : "ARRAY[]::uuid[]";
@ -703,7 +620,12 @@ test.describe("real PostgreSQL persona and protocol lifecycle", () => {
engineConfigSnapshot = readEngineConfigSnapshot();
engineConfigSnapshotCaptured = true;
engine = await startControlledEngine();
installControlledEngineConfig(engine.url);
installControlledEngineConfig({
engineUrl: engine.url,
model: "req005-controlled",
reasoningEffort: "medium",
updatedBy: "req005-e2e",
});
api = await startApi(engine.url);
const bootstrapEmail = `req005-engine-bootstrap-${Date.now()}@twentyoz.kr`;
@ -998,6 +920,10 @@ test.describe("real PostgreSQL persona and protocol lifecycle", () => {
const streamResponse = await streamResponsePromise;
await expectOk(streamResponse);
expect(streamResponse.headers()["content-type"] ?? "").toContain("text/event-stream");
// SSE 헤더가 본문 생성기보다 먼저 오는 경쟁이 있어 단발 확인 대신 폴링한다.
await expect
.poll(() => (engine?.requests() ?? []).some((request) => request.startsWith("POST /v1/stream")))
.toBe(true);
const engineRequests = engine?.requests() ?? [];
const streamDiagnostics = [
`engine=${engineRequests.join(" | ") || "<none>"}`,
@ -1007,10 +933,6 @@ test.describe("real PostgreSQL persona and protocol lifecycle", () => {
body: streamDiagnostics,
contentType: "text/plain; charset=utf-8",
});
expect(
engineRequests.some((request) => request.startsWith("POST /v1/stream")),
streamDiagnostics,
).toBe(true);
await expect(page.locator(".sx-utt").filter({ hasText: learnerText })).toBeVisible();
await expect(page.locator(".sx-utt.is-client").last()).toContainText(
"조금 더 말해볼 수 있을 것 같아요.",

View file

@ -968,7 +968,7 @@ test.describe("session persistence", () => {
await page.goto(`/learn/session/${persona.code}`);
await page.getByRole("button", { name: "회기 시작" }).click();
await completeAlliancePreCheckpoint(page);
await page.getByRole("button", { name: "코칭" }).click();
await page.getByRole("button", { name: /^코칭 모드, 남은 기회 \d+개$/ }).click();
await expect(page.locator(".sx-page.sx-page--active")).toBeVisible({ timeout: 15_000 });
await expect(page).toHaveURL(/\/learn\/session\/[0-9a-f-]+$/i);
const sessionId = new URL(page.url()).pathname.split("/").at(-1);
@ -1165,9 +1165,10 @@ test.describe("session persistence", () => {
);
expect(probe.code, JSON.stringify(probe, null, 2)).toBe(1000);
expect(probe.events.some((event) => event.type === "error" || event.type === "degraded")).toBe(
false,
);
expect(
probe.events.filter((event) => event.type === "error" || event.type === "degraded"),
JSON.stringify(probe.events, null, 2),
).toEqual([]);
expect(probe.events).toEqual(
expect.arrayContaining([
expect.objectContaining({ type: "eot", ready: true }),

View file

@ -1,5 +1,6 @@
import { promises as fs } from "node:fs";
import path from "node:path";
import { spawnSync } from "node:child_process";
import { expect, type Page } from "@playwright/test";
export interface E2EPersona {
@ -86,6 +87,131 @@ export async function withGlobalEngineConfigLock<T>(
}
}
const ENGINE_CONFIG_DB_CONTAINER = process.env.E2E_DB_CONTAINER ?? "vignette-dev-db";
export interface EngineConfigSnapshot {
engine_mode: string;
engine_url: string;
model: string;
reasoning_effort: string | null;
updated_by: string | null;
updated_at: string | null;
}
function runEngineConfigPsql(sql: string): string {
const result = spawnSync(
"docker",
[
"exec",
"-i",
ENGINE_CONFIG_DB_CONTAINER,
"psql",
"-X",
"-U",
"vignette_owner",
"-d",
"vignette",
"-v",
"ON_ERROR_STOP=1",
"-A",
"-t",
"-F",
"|",
],
{ input: sql, encoding: "utf8", windowsHide: true },
);
if (result.status !== 0) {
throw new Error(`psql failed (${result.status}): ${String(result.stderr).trim()}`);
}
return String(result.stdout).trim();
}
function sqlEngineConfigTextValue(value: string | null): string {
return value === null ? "NULL" : `'${value.replaceAll("'", "''")}'`;
}
export function readEngineConfigSnapshot(): EngineConfigSnapshot | null {
const raw = runEngineConfigPsql(`
SELECT COALESCE(
(
SELECT json_build_object(
'engine_mode', engine_mode,
'engine_url', engine_url,
'model', model,
'reasoning_effort', reasoning_effort,
'updated_by', updated_by,
'updated_at', updated_at
)::text
FROM app.admin_engine_config
WHERE id = TRUE
),
'null'
);
`);
return raw === "null" ? null : (JSON.parse(raw) as EngineConfigSnapshot);
}
export function installControlledEngineConfig(options: {
engineUrl: string;
model: string;
reasoningEffort: string | null;
updatedBy: string;
}): void {
const { engineUrl, model, reasoningEffort, updatedBy } = options;
runEngineConfigPsql(`
INSERT INTO app.admin_engine_config (
id, engine_mode, engine_url, model, reasoning_effort, updated_by, updated_at
)
VALUES (
TRUE, 'claude_api', ${sqlEngineConfigTextValue(engineUrl)}, ${sqlEngineConfigTextValue(model)},
${sqlEngineConfigTextValue(reasoningEffort)}, ${sqlEngineConfigTextValue(updatedBy)}, now()
)
ON CONFLICT (id) DO UPDATE SET
engine_mode = EXCLUDED.engine_mode,
engine_url = EXCLUDED.engine_url,
model = EXCLUDED.model,
reasoning_effort = EXCLUDED.reasoning_effort,
updated_by = EXCLUDED.updated_by,
updated_at = EXCLUDED.updated_at;
`);
expect(readEngineConfigSnapshot()).toMatchObject({
engine_mode: "claude_api",
engine_url: engineUrl,
model,
reasoning_effort: reasoningEffort,
updated_by: updatedBy,
});
}
export function restoreEngineConfig(snapshot: EngineConfigSnapshot | null): void {
if (snapshot === null) {
runEngineConfigPsql("DELETE FROM app.admin_engine_config WHERE id = TRUE;");
} else {
runEngineConfigPsql(`
INSERT INTO app.admin_engine_config (
id, engine_mode, engine_url, model, reasoning_effort, updated_by, updated_at
)
VALUES (
TRUE,
${sqlEngineConfigTextValue(snapshot.engine_mode)},
${sqlEngineConfigTextValue(snapshot.engine_url)},
${sqlEngineConfigTextValue(snapshot.model)},
${sqlEngineConfigTextValue(snapshot.reasoning_effort)},
${sqlEngineConfigTextValue(snapshot.updated_by)},
${sqlEngineConfigTextValue(snapshot.updated_at)}::timestamptz
)
ON CONFLICT (id) DO UPDATE SET
engine_mode = EXCLUDED.engine_mode,
engine_url = EXCLUDED.engine_url,
model = EXCLUDED.model,
reasoning_effort = EXCLUDED.reasoning_effort,
updated_by = EXCLUDED.updated_by,
updated_at = EXCLUDED.updated_at;
`);
}
expect(readEngineConfigSnapshot()).toEqual(snapshot);
}
const E2E_COHORT_ID = "e2e-hanshin";
export async function signInAsLearner(page: Page) {

View file

@ -4,7 +4,13 @@ import { randomUUID } from "node:crypto";
import { existsSync } from "node:fs";
import http, { type IncomingMessage, type ServerResponse } from "node:http";
import net from "node:net";
import { completeAlliancePreCheckpoint } from "./support";
import {
acquireGlobalEngineConfigLock,
completeAlliancePreCheckpoint,
installControlledEngineConfig,
readEngineConfigSnapshot,
restoreEngineConfig,
} from "./support";
interface TestServer {
url: string;
@ -203,54 +209,77 @@ async function startApi({
process.env.E2E_PYTHON ??
process.env.PYTHON311 ??
(localPython311 && existsSync(localPython311) ? localPython311 : (process.env.PYTHON ?? "python"));
const proc = spawn(
python,
[
"-m",
"uvicorn",
"app.main:app",
"--host",
"127.0.0.1",
"--port",
String(port),
"--log-level",
"debug",
],
{
cwd: "../api",
env: {
...process.env,
PYTHONUNBUFFERED: "1",
ENVIRONMENT: "dev",
AUTH_DEV_LOGIN_ENABLED: "true",
AUTH_ALLOWED_EMAIL_DOMAINS: '["hs.ac.kr","twentyoz.kr"]',
ALLOW_SEED_PERSONA_FALLBACK: "true",
DB_POOL_MIN_SIZE: "1",
DB_COMMAND_TIMEOUT: "10",
ENGINE_URL: engineURL,
ENGINE_MODE: "claude_api",
ENGINE_TIMEOUT: "10",
ENGINE_CONNECT_TIMEOUT: "2",
OPENAI_API_KEY: "e2e-fake-key",
OPENAI_BASE_URL: `${openAIBaseURL}/v1`,
VIGNETTE_VOICE_POC_SAMPLE_TTS: "false",
FRONTEND_BASE_URL: frontendBaseURL,
CORS_ORIGINS: JSON.stringify([frontendBaseURL]),
},
windowsHide: true,
},
);
// 공유 개발 DB의 admin_engine_config 행(claude_cli 게이트웨이)이 기동 시 env의
// 가짜 엔진 설정을 덮어쓴다. 락을 잡고 가짜 엔진으로 일시 교체한 뒤, 기동된 API가
// 그 설정을 읽었는지 /health로 확인하고 즉시 원복한다(controlled providers 전제 보호).
const releaseEngineConfigLock = await acquireGlobalEngineConfigLock("voice-success:startApi");
const engineConfigSnapshot = readEngineConfigSnapshot();
let proc: ChildProcessWithoutNullStreams;
let logs = "";
proc.stdout.on("data", (chunk) => {
logs += String(chunk).slice(-4000);
});
proc.stderr.on("data", (chunk) => {
logs += String(chunk).slice(-4000);
});
await waitForApi(baseURL, proc).catch((err) => {
proc.kill();
throw new Error(`${err instanceof Error ? err.message : String(err)}\n${logs}`);
});
try {
installControlledEngineConfig({
engineUrl: engineURL,
model: "voice-success-controlled",
reasoningEffort: "medium",
updatedBy: "voice-success-e2e",
});
proc = spawn(
python,
[
"-m",
"uvicorn",
"app.main:app",
"--host",
"127.0.0.1",
"--port",
String(port),
"--log-level",
"debug",
],
{
cwd: "../api",
env: {
...process.env,
PYTHONUNBUFFERED: "1",
ENVIRONMENT: "dev",
AUTH_DEV_LOGIN_ENABLED: "true",
AUTH_ALLOWED_EMAIL_DOMAINS: '["hs.ac.kr","twentyoz.kr"]',
ALLOW_SEED_PERSONA_FALLBACK: "true",
DB_POOL_MIN_SIZE: "1",
DB_COMMAND_TIMEOUT: "10",
ENGINE_URL: engineURL,
ENGINE_MODE: "claude_api",
VIGNETTE_LIVE_CLIENT_PROVIDER: "claude_api",
VIGNETTE_CLIENT_AFFECT_PROVIDER: "legacy",
ENGINE_TIMEOUT: "10",
ENGINE_CONNECT_TIMEOUT: "2",
OPENAI_API_KEY: "e2e-fake-key",
OPENAI_BASE_URL: `${openAIBaseURL}/v1`,
VIGNETTE_VOICE_POC_SAMPLE_TTS: "false",
FRONTEND_BASE_URL: frontendBaseURL,
CORS_ORIGINS: JSON.stringify([frontendBaseURL]),
},
windowsHide: true,
},
);
proc.stdout.on("data", (chunk) => {
logs += String(chunk).slice(-4000);
});
proc.stderr.on("data", (chunk) => {
logs += String(chunk).slice(-4000);
});
await waitForApi(baseURL, proc).catch((err) => {
proc.kill();
throw new Error(`${err instanceof Error ? err.message : String(err)}\n${logs}`);
});
const health = await fetch(`${baseURL}/health`);
const healthBody = (await health.json()) as { engine_mode?: string };
if (healthBody.engine_mode !== "claude_api") proc.kill();
expect(healthBody.engine_mode, logs).toBe("claude_api");
} finally {
restoreEngineConfig(engineConfigSnapshot);
await releaseEngineConfigLock();
}
return {
baseURL,
logs: () => logs,

View file

@ -669,7 +669,9 @@ function AppRoutes() {
export default function App() {
return (
<BrowserRouter>
// v7 기본값은 위치 갱신을 startTransition으로 미뤄, URL 검색 파라미터를 값으로 쓰는
// 제어 입력(기록 검색 등)이 타이핑 중 글자를 잃는다. v6와 같은 동기 갱신을 유지한다.
<BrowserRouter useTransitions={false}>
<AuthProvider>
<ScrollToTopOnPathChange />
<AppRoutesWithBoundary />