운영 안정화와 화면 회귀 검증을 반영
Some checks failed
API contract / OpenAPI type drift (push) Failing after 6m2s

This commit is contained in:
Yun Chan 2026-10-20 16:33:48 +09:00
parent 6e3123091a
commit aeddaa6972
69 changed files with 3178 additions and 424 deletions

View file

@ -1,5 +1,6 @@
import { expect, test, type Page } from "@playwright/test";
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
import { randomUUID } from "node:crypto";
import { existsSync } from "node:fs";
import http, { type IncomingMessage, type ServerResponse } from "node:http";
import net from "node:net";
@ -328,6 +329,40 @@ async function completeControlledVoicePreflight(
expect(result).toMatchObject({ ok: true });
}
async function endControlledVoiceSession(
page: Page,
apiBaseURL: string,
sessionId: string,
): Promise<void> {
const result = await page.evaluate(
async ({ apiBase, session }) => {
const response = await fetch(`${apiBase}/sessions/${session}/end`, {
method: "POST",
credentials: "include",
});
return {
ok: response.ok,
status: response.status,
body: await response.json() as {
session_id?: string;
session_no?: number;
digest_pending?: boolean;
end_state?: Record<string, unknown>;
},
};
},
{ apiBase: apiBaseURL, session: sessionId },
);
expect(result).toMatchObject({
ok: true,
status: 200,
body: { session_id: sessionId },
});
expect(typeof result.body.session_no).toBe("number");
expect(typeof result.body.digest_pending).toBe("boolean");
expect(result.body.end_state).toEqual(expect.any(Object));
}
async function waitForWeb(baseURL: string, proc: ChildProcessWithoutNullStreams): Promise<void> {
const started = Date.now();
let lastError = "";
@ -471,7 +506,18 @@ async function installSyntheticVoiceCapture(
messages: ProbeMessage[];
closeEvents: number[];
};
const w = window as Window & { __voiceUiProbe?: ProbeState };
type GetUserMediaGate = {
promise: Promise<void>;
release: () => void;
};
type ProbeControl = {
blockNextGetUserMedia: () => void;
releaseGetUserMedia: () => void;
};
const w = window as Window & {
__voiceUiProbe?: ProbeState;
__voiceUiProbeControl?: ProbeControl;
};
const probe: ProbeState = {
getUserMediaCalls: 0,
webSocketConstructs: 0,
@ -489,6 +535,27 @@ async function installSyntheticVoiceCapture(
closeEvents: [],
};
w.__voiceUiProbe = probe;
let pendingGetUserMediaGate: GetUserMediaGate | null = null;
let activeGetUserMediaGate: GetUserMediaGate | null = null;
w.__voiceUiProbeControl = {
blockNextGetUserMedia: () => {
if (pendingGetUserMediaGate || activeGetUserMediaGate) {
throw new Error("이미 getUserMedia 대기 중입니다.");
}
let release = () => undefined;
const promise = new Promise<void>((resolve) => {
release = resolve;
});
pendingGetUserMediaGate = { promise, release };
},
releaseGetUserMedia: () => {
const gate = activeGetUserMediaGate ?? pendingGetUserMediaGate;
if (!gate) throw new Error("해제할 getUserMedia 대기가 없습니다.");
pendingGetUserMediaGate = null;
activeGetUserMediaGate = null;
gate.release();
},
};
const fakeTrack = {
kind: "audio",
@ -509,6 +576,13 @@ async function installSyntheticVoiceCapture(
value: {
getUserMedia: async () => {
probe.getUserMediaCalls += 1;
const gate = pendingGetUserMediaGate;
if (gate) {
pendingGetUserMediaGate = null;
activeGetUserMediaGate = gate;
await gate.promise;
if (activeGetUserMediaGate === gate) activeGetUserMediaGate = null;
}
if ((opts.getUserMediaDelayMs ?? 0) > 0) {
await new Promise((resolve) => window.setTimeout(resolve, opts.getUserMediaDelayMs));
}
@ -793,6 +867,30 @@ async function readVoiceUiProbe(page: Page): Promise<VoiceUiProbeState> {
});
}
async function blockNextSyntheticGetUserMedia(page: Page): Promise<void> {
const blocked = await page.evaluate(() => {
const control = (window as Window & {
__voiceUiProbeControl?: { blockNextGetUserMedia: () => void };
}).__voiceUiProbeControl;
if (!control) return false;
control.blockNextGetUserMedia();
return true;
});
expect(blocked).toBe(true);
}
async function releaseSyntheticGetUserMedia(page: Page): Promise<void> {
const released = await page.evaluate(() => {
const control = (window as Window & {
__voiceUiProbeControl?: { releaseGetUserMedia: () => void };
}).__voiceUiProbeControl;
if (!control) return false;
control.releaseGetUserMedia();
return true;
});
expect(released).toBe(true);
}
async function parsedVoiceUiEvents(page: Page): Promise<Array<{ type?: string; [key: string]: unknown }>> {
const probe = await readVoiceUiProbe(page);
return probe.messages
@ -810,18 +908,19 @@ test.describe("voice cascade success path", () => {
const engine = await startFakeEngine();
const api = await startApi({ engineURL: engine.url, openAIBaseURL: openai.url });
try {
const testAccountEmail = `voice-success.${testInfo.workerIndex}.${randomUUID()}@hs.ac.kr`;
const health = await page.request.get(`${api.baseURL}/voice/health`);
expect(health.ok(), await health.text()).toBeTruthy();
await expect(await health.json()).toMatchObject({ status: "ok", available: true });
await page.goto(`${api.baseURL}/health`);
const browserSetup = await page.evaluate(async ({ apiBase, seededPersonaCode, workerIndex }) => {
const browserSetup = await page.evaluate(async ({ apiBase, seededPersonaCode, email }) => {
const login = await fetch(`${apiBase}/auth/dev-login`, {
method: "POST",
credentials: "include",
headers: { "content-type": "application/json" },
body: JSON.stringify({
email: `voice-success.${workerIndex}@hs.ac.kr`,
email,
role: "learner",
display_name: "Voice Success",
}),
@ -880,7 +979,7 @@ test.describe("voice cascade success path", () => {
}, {
apiBase: api.baseURL,
seededPersonaCode: SEEDED_VOICE_PERSONA_CODE,
workerIndex: testInfo.workerIndex,
email: testAccountEmail,
});
expect(browserSetup, api.logs()).toMatchObject({ ok: true });
if (!browserSetup.ok) throw new Error(JSON.stringify(browserSetup));
@ -914,10 +1013,19 @@ test.describe("voice cascade success path", () => {
]),
);
expect(result.binaryChunks).toBeGreaterThan(0);
await test.step("음성 캐스케이드 회기 종료", async () => {
await endControlledVoiceSession(page, api.baseURL, started.session_id);
});
} finally {
await api.stop();
await engine.close();
await openai.close();
await test.step("controlled API 종료", async () => {
await api.stop();
});
await test.step("controlled engine 종료", async () => {
await engine.close();
});
await test.step("controlled OpenAI 종료", async () => {
await openai.close();
});
}
});
@ -925,6 +1033,7 @@ test.describe("voice cascade success path", () => {
page,
}, testInfo) => {
test.setTimeout(150_000);
const testAccountEmail = `voice-ui.${testInfo.workerIndex}.${randomUUID()}@hs.ac.kr`;
const diagnostics: string[] = [];
page.on("pageerror", (error) => diagnostics.push(`pageerror: ${error.message}`));
@ -989,13 +1098,13 @@ test.describe("voice cascade success path", () => {
});
await page.goto(`${web.baseURL}/login`, { waitUntil: "domcontentloaded" });
const browserLogin = await page.evaluate(async ({ apiBase, workerIndex }) => {
const browserLogin = await page.evaluate(async ({ apiBase, email }) => {
const login = await fetch(`${apiBase}/auth/dev-login`, {
method: "POST",
credentials: "include",
headers: { "content-type": "application/json" },
body: JSON.stringify({
email: `voice-ui.${workerIndex}@hs.ac.kr`,
email,
role: "learner",
display_name: "Voice UI",
}),
@ -1039,7 +1148,7 @@ test.describe("voice cascade success path", () => {
return { ok: true, me: JSON.parse(meBody) as unknown };
}, {
apiBase: api.baseURL,
workerIndex: testInfo.workerIndex,
email: testAccountEmail,
});
expect(browserLogin, api.logs()).toMatchObject({ ok: true });
@ -1073,6 +1182,14 @@ test.describe("voice cascade success path", () => {
.poll(async () => (await readVoiceUiProbe(page)).audioBufferStarts, { timeout: 30_000 })
.toBeGreaterThan(0);
await expect(page.locator(".sx-utt").filter({ hasText: "괜찮아요. 천천히 말해볼게요." })).toBeVisible();
const initialVoiceSessionId = await page.evaluate(() => {
const match = window.location.pathname.match(/^\/learn\/session\/([^/]+)$/);
if (!match) throw new Error(`현재 회기 URL을 확인할 수 없습니다: ${window.location.pathname}`);
return match[1];
});
await test.step("첫 UI 회기 종료", async () => {
await endControlledVoiceSession(page, api.baseURL, initialVoiceSessionId);
});
const freshVoiceSession = await page.evaluate(async ({ apiBase, personaCode }) => {
const response = await fetch(`${apiBase}/sessions`, {
@ -1108,9 +1225,15 @@ test.describe("voice cascade success path", () => {
const mic = page.locator(".sx-mic");
await expect(mic).toBeEnabled();
await page.keyboard.press("Space");
await expect.poll(async () => (await readVoiceUiProbe(page)).getUserMediaCalls).toBe(0);
await expect.poll(async () => (await readVoiceUiProbe(page)).webSocketConstructs).toBe(0);
await test.step("Space 단축키 일시정지와 재개", async () => {
await page.keyboard.press("Space");
await expect(page.getByRole("button", { name: "이어가기" })).toBeVisible();
await expect.poll(async () => (await readVoiceUiProbe(page)).getUserMediaCalls).toBe(0);
await expect.poll(async () => (await readVoiceUiProbe(page)).webSocketConstructs).toBe(0);
await page.keyboard.press("p");
await expect(page.getByRole("button", { name: "일시정지" })).toBeVisible();
await expect(mic).toBeEnabled();
});
await mic.click();
const consentDialog = page.getByRole("dialog", { name: "음성 입력을 사용하기 전에" });
@ -1257,47 +1380,63 @@ test.describe("voice cascade success path", () => {
expect.arrayContaining(["POST /v1/audio/transcriptions", "POST /v1/audio/speech"]),
);
expect(engine.requests()).toContain("POST /v1/generate");
await test.step("fresh UI 회기 종료", async () => {
await endControlledVoiceSession(page, api.baseURL, freshVoiceSession.body.session_id ?? "");
});
const stalePermissionSession = await page.evaluate(async ({ apiBase, personaCode }) => {
const response = await fetch(`${apiBase}/sessions`, {
method: "POST",
credentials: "include",
headers: { "content-type": "application/json" },
body: JSON.stringify({ persona_code: personaCode, theory_mode: "humanistic" }),
});
return {
ok: response.ok,
status: response.status,
body: await response.json() as { session_id?: string },
};
}, { apiBase: api.baseURL, personaCode: SEEDED_VOICE_PERSONA_CODE });
expect(stalePermissionSession, api.logs()).toMatchObject({ ok: true });
const staleSessionId = stalePermissionSession.body.session_id ?? "";
await completeControlledVoicePreflight(page, api.baseURL, staleSessionId);
await page.goto(`${web.baseURL}/learn/session/${staleSessionId}`);
await expect(page.locator(".sx-page.sx-page--active")).toBeVisible({ timeout: 20_000 });
await test.step("stale 권한 회기 검사와 종료", async () => {
const stalePermissionSession = await page.evaluate(async ({ apiBase, personaCode }) => {
const response = await fetch(`${apiBase}/sessions`, {
method: "POST",
credentials: "include",
headers: { "content-type": "application/json" },
body: JSON.stringify({ persona_code: personaCode, theory_mode: "humanistic" }),
});
return {
ok: response.ok,
status: response.status,
body: await response.json() as { session_id?: string },
};
}, { apiBase: api.baseURL, personaCode: SEEDED_VOICE_PERSONA_CODE });
expect(stalePermissionSession, api.logs()).toMatchObject({ ok: true });
const staleSessionId = stalePermissionSession.body.session_id ?? "";
await completeControlledVoicePreflight(page, api.baseURL, staleSessionId);
await page.goto(`${web.baseURL}/learn/session/${staleSessionId}`);
await expect(page.locator(".sx-page.sx-page--active")).toBeVisible({ timeout: 20_000 });
const beforeStaleAttempt = await readVoiceUiProbe(page);
await page.keyboard.press("Alt+m");
const staleConsentDialog = page.getByRole("dialog", { name: "음성 입력을 사용하기 전에" });
await expect(staleConsentDialog).toBeVisible();
await staleConsentDialog.getByRole("button", { name: "동의하고 마이크 켜기" }).click();
await expect
.poll(async () => (await readVoiceUiProbe(page)).getUserMediaCalls)
.toBe(beforeStaleAttempt.getUserMediaCalls + 1);
await page.keyboard.press("p");
await expect(page.getByRole("button", { name: "이어가기" })).toBeVisible();
await expect
.poll(async () => (await readVoiceUiProbe(page)).trackStops, { timeout: 5_000 })
.toBe(beforeStaleAttempt.trackStops + 1);
await expect.poll(async () => (await readVoiceUiProbe(page)).webSocketConstructs).toBe(
beforeStaleAttempt.webSocketConstructs,
);
await blockNextSyntheticGetUserMedia(page);
const beforeStaleAttempt = await readVoiceUiProbe(page);
await page.keyboard.press("Alt+m");
const staleConsentDialog = page.getByRole("dialog", { name: "음성 입력을 사용하기 전에" });
await expect(staleConsentDialog).toBeVisible();
await staleConsentDialog.getByRole("button", { name: "동의하고 마이크 켜기" }).click();
await expect
.poll(async () => (await readVoiceUiProbe(page)).getUserMediaCalls)
.toBe(beforeStaleAttempt.getUserMediaCalls + 1);
await page.keyboard.press("p");
await expect(page.getByRole("button", { name: "이어가기" })).toBeVisible();
await releaseSyntheticGetUserMedia(page);
await expect
.poll(async () => (await readVoiceUiProbe(page)).trackStops, { timeout: 5_000 })
.toBe(beforeStaleAttempt.trackStops + 1);
await expect.poll(async () => (await readVoiceUiProbe(page)).webSocketConstructs).toBe(
beforeStaleAttempt.webSocketConstructs,
);
await endControlledVoiceSession(page, api.baseURL, staleSessionId);
});
} finally {
await web.stop();
await api.stop();
await engine.close();
await openai.close();
await test.step("controlled web 종료", async () => {
await web.stop();
});
await test.step("controlled API 종료", async () => {
await api.stop();
});
await test.step("controlled engine 종료", async () => {
await engine.close();
});
await test.step("controlled OpenAI 종료", async () => {
await openai.close();
});
}
});
});