{"version":3,"file":"resolveCwds.cjs","names":["findModelAnswerDirs","findFailingModelAnswerDirs","path","MODEL_ANSWERS_DIRNAME","FAILING_MODEL_ANSWERS_DIRNAME"],"sources":["../../src/helpers/resolveCwds.ts"],"sourcesContent":["import path from 'node:path';\n\nimport {\n  FAILING_MODEL_ANSWERS_DIRNAME,\n  MODEL_ANSWERS_DIRNAME,\n  findFailingModelAnswerDirs,\n  findModelAnswerDirs,\n} from './findModelAnswerDirs.js';\nimport { printDebugBanner } from './printDebugBanner.js';\n\nexport type ExpectedJudgeResult = 'accepted' | 'rejected';\n\nexport interface ResolvedCwd {\n  cwd: string;\n  expectedResult: ExpectedJudgeResult;\n}\n\nexport interface ResolvedCwds {\n  cwds: readonly ResolvedCwd[];\n  isDebugMode: boolean;\n}\n\n/**\n * Resolve which working directories to judge.\n *\n * - If `cwdArg` is provided, use it as the single cwd.\n * - Otherwise (debug mode), enumerate `<problemDir>/model_answers/*` and\n *   `<problemDir>/model_answers.fails/*` and judge each.\n *   A prominent banner is printed so users can tell at a glance that this is a debug run.\n *\n * @throws if `cwdArg` is missing and no model answer directories are found.\n */\nexport async function resolveCwds(problemDir: string, cwdArg: string | undefined): Promise<ResolvedCwds> {\n  if (cwdArg) return { cwds: [{ cwd: cwdArg, expectedResult: 'accepted' }], isDebugMode: false };\n\n  const [modelAnswerDirs, failingModelAnswerDirs] = await Promise.all([\n    findModelAnswerDirs(problemDir),\n    findFailingModelAnswerDirs(problemDir),\n  ]);\n  if (modelAnswerDirs.length === 0 && failingModelAnswerDirs.length === 0) {\n    throw new Error(\n      `cwd argument required (no model answer directories found in ${path.join(problemDir, MODEL_ANSWERS_DIRNAME)} or ${path.join(problemDir, FAILING_MODEL_ANSWERS_DIRNAME)})`\n    );\n  }\n\n  const scriptName = getInvokedScriptName();\n  const exampleAnswer =\n    path.relative(problemDir, modelAnswerDirs[0] ?? failingModelAnswerDirs[0] ?? '') || '<model_answer>';\n  printDebugBanner([\n    '[DEBUG MODE] cwd not provided -- judging against all model answers',\n    '',\n    `Problem dir : ${problemDir}`,\n    `Model answers (${modelAnswerDirs.length}):`,\n    ...modelAnswerDirs.map((dir) => `  - ${path.relative(problemDir, dir)}`),\n    `Failing model answers (${failingModelAnswerDirs.length}):`,\n    ...failingModelAnswerDirs.map((dir) => `  - ${path.relative(problemDir, dir)}`),\n    '',\n    'To judge a single cwd (e.g., a user submission), pass it as the first argument:',\n    `  bun ${scriptName} <cwd> [params-json]`,\n    'For example:',\n    `  bun ${scriptName} ${exampleAnswer}`,\n    `  bun ${scriptName} ${exampleAnswer} '{\"language\":\"python\"}'`,\n  ]);\n\n  return {\n    cwds: [\n      ...modelAnswerDirs.map((cwd) => ({ cwd, expectedResult: 'accepted' as const })),\n      ...failingModelAnswerDirs.map((cwd) => ({ cwd, expectedResult: 'rejected' as const })),\n    ],\n    isDebugMode: true,\n  };\n}\n\n/**\n * Print a per-cwd banner shown before judging each model answer in debug mode.\n * Includes the command for re-running this single cwd.\n */\nexport function printDebugCwdBanner(problemDir: string, resolvedCwd: ResolvedCwd): void {\n  const relativeCwd = path.relative(problemDir, resolvedCwd.cwd) || resolvedCwd.cwd;\n  const scriptName = getInvokedScriptName();\n  printDebugBanner([\n    `[DEBUG MODE] judging: ${relativeCwd}`,\n    `Expected result: ${resolvedCwd.expectedResult}`,\n    '',\n    'To judge only this cwd as a normal submission:',\n    `  bun ${scriptName} ${relativeCwd}`,\n    'Run without a cwd to check debug-mode expectations.',\n  ]);\n}\n\nexport function printDebugExpectationFailureBanner(problemDir: string, resolvedCwd: ResolvedCwd): void {\n  const relativeCwd = path.relative(problemDir, resolvedCwd.cwd) || resolvedCwd.cwd;\n  printDebugBanner([\n    `[DEBUG MODE] expectation failed: ${relativeCwd}`,\n    `Expected result: ${resolvedCwd.expectedResult}`,\n    resolvedCwd.expectedResult === 'accepted'\n      ? 'The model answer was rejected by the judge.'\n      : 'The failing model answer was accepted by the judge.',\n  ]);\n}\n\nfunction getInvokedScriptName(): string {\n  const scriptP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