라우터 7 동기 갱신 복구와 E2E 격리 수정, 검증 기록 동기화
Some checks failed
API contract / OpenAPI type drift (push) Failing after 3m30s
Some checks failed
API contract / OpenAPI type drift (push) Failing after 3m30s
This commit is contained in:
parent
d801a1619d
commit
b0ff44a1d4
9 changed files with 236 additions and 154 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue