// 실행 기록 하나의 최종 판정. run.mjs(실행 직후)와 rejudge.mjs(기존 기록 재판정)가 같은 함수를 쓴다. // 둘의 판정이 갈리면 같은 원본에서 한쪽은 ERROR, 한쪽은 PASS 가 나온다(감사 F003). // // 러너가 정상으로 끝나지 못한 실행(spawn 실패, 타임아웃, 비정상 종료, 빈 스트림)은 PASS 도 NO-TRIGGER 도 아니라 // ERROR 다. 로그인 만료·CLI 오류·네트워크 장애로 이벤트가 없는 실행이 no-trigger 시나리오의 통과율에 들어가면 안 된다. import fs from "node:fs"; import path from "node:path"; import { judge, normalizeClaude, normalizeCodex } from "./judge.mjs"; /** * 평가 세션이 저장소 지침(AGENTS.md·CLAUDE.md)을 읽었다는 표지. 평가 대상은 스킬이어야 하는데 * "게이트를 약화하지 말라"는 저장소 지침을 함께 읽으면 ask/direction 통과율이 부풀려진다(감사 F001). * 스킬 본문에는 이 문자열이 없다(lint 대상 아님 — 평가 사본 기준으로 확인했다). */ export const REPO_CONTEXT_MARKERS = ["designpaca monorepo", "Never soften the step-0 interview gate"]; /** 파일들에서 저장소 지침 표지를 찾는다. 찾은 파일 경로(중복 없이)를 돌려준다. */ export function findRepoContext(files) { const hits = []; for (const f of files) { let text; try { text = fs.readFileSync(f, "utf8"); } catch { continue; } if (REPO_CONTEXT_MARKERS.some((m) => text.includes(m))) hits.push(f); } return hits; } /** 디렉터리 아래의 .jsonl 파일을 모두 모은다(Codex 롤아웃 등). 없으면 빈 배열. */ export function listJsonl(dir) { const out = []; function walk(d) { let entries; try { entries = fs.readdirSync(d, { withFileTypes: true }); } catch { return; } for (const e of entries) { const full = path.join(d, e.name); if (e.isDirectory()) walk(full); else if (e.isFile() && e.name.endsWith(".jsonl")) out.push(full); } } walk(dir); return out; } /** * 시작 디렉터리의 상위 경로에 프로젝트 지침(AGENTS.md·CLAUDE.md)이나 .git 이 있으면 그 경로를 돌려준다. * Codex·Claude Code 는 작업 디렉터리에서 위로 올라가며 프로젝트 문서를 찾으므로, 평가 작업 디렉터리의 조상에 * 이런 파일이 있으면 격리가 깨진다. */ export function findProjectDocsAbove(dir) { let cur = path.resolve(dir); for (;;) { for (const name of ["AGENTS.md", "CLAUDE.md", ".git"]) { if (fs.existsSync(path.join(cur, name))) return path.join(cur, name); } const parent = path.dirname(cur); if (parent === cur) return null; cur = parent; } } /** * @param {object} scenario scenarios.json 의 한 항목 * @param {object} record 러너가 쓴 result.json 내용(없으면 {}) * @param {string} rawLogPath 원본 스트림 경로 * @param {string} runner "codex" 이면 Codex 스트림, 그 밖에는 Claude 스트림으로 읽는다 * @param {object} [extra] judge 에 넘기는 러너 밖 측정값 * @param {{contextFiles?: string[]}} [opts] contextFiles: 저장소 지침 표지를 찾아볼 추가 파일(Codex 롤아웃 등) */ export function computeVerdict(scenario, record, rawLogPath, runner, extra, opts = {}) { record = record || {}; if (record.error) return { verdict: "ERROR", note: String(record.error) }; if (record.killedReason) { return { verdict: "ERROR", note: `러너가 정상 종료하지 못했다(${record.killedReason}) — 결과를 판정하지 않는다` }; } if (record.exitCode !== undefined && record.exitCode !== null && record.exitCode !== 0) { const tail = record.stderrTail ? `: ${String(record.stderrTail).trim().slice(-200)}` : ""; return { verdict: "ERROR", note: `러너가 비정상 종료했다(exit ${record.exitCode})${tail}` }; } let raw = ""; try { raw = fs.readFileSync(rawLogPath, "utf8"); } catch { return { verdict: "ERROR", note: `원본 스트림이 없다: ${rawLogPath}` }; } const contaminated = findRepoContext([rawLogPath, ...(opts.contextFiles || [])]); if (contaminated.length) { return { verdict: "ERROR", note: `평가 세션이 저장소 지침(AGENTS.md)을 읽었다 — 격리가 깨져 판정하지 않는다: ${contaminated.map((f) => path.basename(f)).join(", ")}`, }; } const events = runner === "codex" ? normalizeCodex(raw) : normalizeClaude(raw); return judge(scenario, events, extra); }