@exercode/problem-utils 4.3.1 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/cli/checkAllProblems.cjs.map +1 -1
  2. package/dist/cli/checkAllProblems.js.map +1 -1
  3. package/dist/cli/exercodeProblem.cjs.map +1 -1
  4. package/dist/cli/exercodeProblem.js.map +1 -1
  5. package/dist/cli/runSingleHarness.cjs.map +1 -1
  6. package/dist/cli/runSingleHarness.js.map +1 -1
  7. package/dist/cli/validateLearningMaterial.cjs.map +1 -1
  8. package/dist/cli/validateLearningMaterial.js.map +1 -1
  9. package/dist/helpers/checkProblemDirIsolation.cjs.map +1 -1
  10. package/dist/helpers/checkProblemDirIsolation.js.map +1 -1
  11. package/dist/helpers/cleanWorkingDirectory.cjs.map +1 -1
  12. package/dist/helpers/cleanWorkingDirectory.js.map +1 -1
  13. package/dist/helpers/compareExpectedOutputFiles.cjs.map +1 -1
  14. package/dist/helpers/compareExpectedOutputFiles.js.map +1 -1
  15. package/dist/helpers/compareStdoutAsSpaceSeparatedTokens.cjs.map +1 -1
  16. package/dist/helpers/compareStdoutAsSpaceSeparatedTokens.js.map +1 -1
  17. package/dist/helpers/copyTestCaseFileInput.cjs.map +1 -1
  18. package/dist/helpers/copyTestCaseFileInput.js.map +1 -1
  19. package/dist/helpers/defaultStdioHarness.cjs.map +1 -1
  20. package/dist/helpers/defaultStdioHarness.js.map +1 -1
  21. package/dist/helpers/findEntryPointFile.cjs.map +1 -1
  22. package/dist/helpers/findEntryPointFile.js.map +1 -1
  23. package/dist/helpers/findLanguageDefinitionByPath.cjs.map +1 -1
  24. package/dist/helpers/findLanguageDefinitionByPath.js.map +1 -1
  25. package/dist/helpers/findModelAnswerDirs.cjs.map +1 -1
  26. package/dist/helpers/findModelAnswerDirs.js.map +1 -1
  27. package/dist/helpers/guiRecording.cjs.map +1 -1
  28. package/dist/helpers/guiRecording.js.map +1 -1
  29. package/dist/helpers/javaJudge.cjs.map +1 -1
  30. package/dist/helpers/javaJudge.js.map +1 -1
  31. package/dist/helpers/judgeByStaticAnalysis.cjs.map +1 -1
  32. package/dist/helpers/judgeByStaticAnalysis.js.map +1 -1
  33. package/dist/helpers/parseArgs.cjs.map +1 -1
  34. package/dist/helpers/parseArgs.js.map +1 -1
  35. package/dist/helpers/parseCsv.cjs.map +1 -1
  36. package/dist/helpers/parseCsv.js.map +1 -1
  37. package/dist/helpers/printDebugBanner.cjs.map +1 -1
  38. package/dist/helpers/printDebugBanner.js.map +1 -1
  39. package/dist/helpers/printTestCaseResult.cjs.map +1 -1
  40. package/dist/helpers/printTestCaseResult.js.map +1 -1
  41. package/dist/helpers/readOutputFiles.cjs.map +1 -1
  42. package/dist/helpers/readOutputFiles.js.map +1 -1
  43. package/dist/helpers/readProblemMarkdownFrontMatter.cjs.map +1 -1
  44. package/dist/helpers/readProblemMarkdownFrontMatter.js.map +1 -1
  45. package/dist/helpers/readTestCases.cjs.map +1 -1
  46. package/dist/helpers/readTestCases.js.map +1 -1
  47. package/dist/helpers/removeCommentsInSourceCode.cjs.map +1 -1
  48. package/dist/helpers/removeCommentsInSourceCode.js.map +1 -1
  49. package/dist/helpers/resolveCwds.cjs.map +1 -1
  50. package/dist/helpers/resolveCwds.js.map +1 -1
  51. package/dist/helpers/runCommandInTemporaryPackageManagerProject.cjs.map +1 -1
  52. package/dist/helpers/runCommandInTemporaryPackageManagerProject.js.map +1 -1
  53. package/dist/helpers/runHarnessProcess.cjs.map +1 -1
  54. package/dist/helpers/runHarnessProcess.js.map +1 -1
  55. package/dist/helpers/runIsolationCheckInDebugMode.cjs.map +1 -1
  56. package/dist/helpers/runIsolationCheckInDebugMode.js.map +1 -1
  57. package/dist/helpers/runPythonInTemporaryUvProject.cjs.map +1 -1
  58. package/dist/helpers/runPythonInTemporaryUvProject.js.map +1 -1
  59. package/dist/helpers/sourceCodeGrammars.cjs.map +1 -1
  60. package/dist/helpers/sourceCodeGrammars.js.map +1 -1
  61. package/dist/helpers/spawnWithLimits.cjs.map +1 -1
  62. package/dist/helpers/spawnWithLimits.js.map +1 -1
  63. package/dist/helpers/spawnWithTimeout.cjs.map +1 -1
  64. package/dist/helpers/spawnWithTimeout.js.map +1 -1
  65. package/dist/helpers/startHttpServer.cjs.map +1 -1
  66. package/dist/helpers/startHttpServer.js.map +1 -1
  67. package/dist/helpers/stdioJudgeRules.cjs.map +1 -1
  68. package/dist/helpers/stdioJudgeRules.js.map +1 -1
  69. package/dist/helpers/temporaryProblemDirCopy.cjs.map +1 -1
  70. package/dist/helpers/temporaryProblemDirCopy.js.map +1 -1
  71. package/dist/learningMaterial/frontmatter.cjs.map +1 -1
  72. package/dist/learningMaterial/frontmatter.js.map +1 -1
  73. package/dist/learningMaterial/fsHelpers.cjs.map +1 -1
  74. package/dist/learningMaterial/fsHelpers.js.map +1 -1
  75. package/dist/learningMaterial/schemas.cjs.map +1 -1
  76. package/dist/learningMaterial/schemas.js.map +1 -1
  77. package/dist/learningMaterial/validateContest.cjs.map +1 -1
  78. package/dist/learningMaterial/validateContest.js.map +1 -1
  79. package/dist/learningMaterial/validateCourse.cjs.map +1 -1
  80. package/dist/learningMaterial/validateCourse.js.map +1 -1
  81. package/dist/learningMaterial/validateMaterial.cjs.map +1 -1
  82. package/dist/learningMaterial/validateMaterial.js.map +1 -1
  83. package/dist/learningMaterial/validateProblem.cjs.map +1 -1
  84. package/dist/learningMaterial/validateProblem.js.map +1 -1
  85. package/dist/learningMaterial/validationResult.cjs.map +1 -1
  86. package/dist/learningMaterial/validationResult.js.map +1 -1
  87. package/dist/presets/command.cjs.map +1 -1
  88. package/dist/presets/command.js.map +1 -1
  89. package/dist/presets/evaluation.cjs.map +1 -1
  90. package/dist/presets/evaluation.js.map +1 -1
  91. package/dist/presets/guiCommand.cjs.map +1 -1
  92. package/dist/presets/guiCommand.js.map +1 -1
  93. package/dist/presets/springBoot.cjs.map +1 -1
  94. package/dist/presets/springBoot.js.map +1 -1
  95. package/dist/presets/stdio.cjs.map +1 -1
  96. package/dist/presets/stdio.js.map +1 -1
  97. package/dist/presets/tomcat.cjs.map +1 -1
  98. package/dist/presets/tomcat.js.map +1 -1
  99. package/dist/types/decisionCode.cjs.map +1 -1
  100. package/dist/types/decisionCode.js.map +1 -1
  101. package/dist/types/language.cjs.map +1 -1
  102. package/dist/types/language.js.map +1 -1
  103. package/dist/types/problem.cjs.map +1 -1
  104. package/dist/types/problem.js.map +1 -1
  105. package/dist/types/testCaseResult.cjs.map +1 -1
  106. package/dist/types/testCaseResult.js.map +1 -1
  107. package/package.json +4 -4
@@ -1 +1 @@
1
- {"version":3,"file":"checkAllProblems.cjs","names":["DecisionCode","path","findDefaultStdioHarnessFiles","formatDefaultHarnessError","findModelAnswerDirs","readTestCases","readProblemMarkdownFrontMatter","getErrorMessage","judgesWithoutTestCases","MISSING_TEST_CASES_ERROR","findFailingModelAnswerDirs","forEachConcurrently","copyProblemDirToTemporaryRoot","runHarnessProcess","forciblyRemoveDirectory","TEST_CASE_RESULT_PREFIX","testCaseResultSchema","fs"],"sources":["../../src/cli/checkAllProblems.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { forEachConcurrently, getErrorMessage } from '@willbooster/shared-lib';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { findFailingModelAnswerDirs, findModelAnswerDirs } from '../helpers/findModelAnswerDirs.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { type HarnessProcessResult, runHarnessProcess } from '../helpers/runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from '../helpers/temporaryProblemDirCopy.js';\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { formatDefaultHarnessError, MISSING_TEST_CASES_ERROR } from './runSingleHarness.js';\n\nconst RUN_TIMEOUT_MS = 600_000;\nconst MAX_RUN_OUTPUT_BYTES = 64 * 1024 * 1024;\nconst MAX_FAILURE_DETAIL_LENGTH = 1000;\n\n// DecisionCode is a plain const object (not a TypeScript enum), so it has no reverse mapping.\nconst decisionCodeNames = new Map<number, string>(Object.entries(DecisionCode).map(([name, code]) => [code, name]));\n\ninterface CheckOptions {\n rootDir: string;\n concurrency: number;\n only: string[];\n skip: string[];\n}\n\ninterface CheckRun {\n problemDir: string;\n answerDir: string;\n /** Whether all test cases must be accepted (`model_answers`) or at least one must fail (`model_answers.fails`). */\n expectation: 'accepted' | 'rejected';\n}\n\n/**\n * Judge all model answers of all problems (directories containing `problem.md` or\n * `<id>.problem.md`) under a root directory: `model_answers/*` must be fully accepted and\n * `model_answers.fails/*` must fail at least one test case. Returns the process exit code.\n */\nexport async function checkAllProblems(args: readonly string[]): Promise<number> {\n const options = parseCheckArgs(args);\n const rootDir = path.resolve(options.rootDir);\n // Normalize to forward slashes so --only / --skip substrings like courses/foo match on Windows.\n const toRelative = (dir: string): string => (path.relative(rootDir, dir) || '.').replaceAll(path.sep, '/');\n\n const allProblemDirs = await findProblemDirs(rootDir);\n const problemDirs = allProblemDirs.filter((problemDir) => {\n const relativeDir = toRelative(problemDir);\n if (options.only.length > 0 && !options.only.some((substring) => relativeDir.includes(substring))) return false;\n return !options.skip.some((substring) => relativeDir.includes(substring));\n });\n if (problemDirs.length === 0) {\n console.error(\n allProblemDirs.length === 0\n ? `No problem directories (containing problem.md or <id>.problem.md) found under ${rootDir}.`\n : `All ${allProblemDirs.length} problem directories under ${rootDir} were excluded by --only/--skip.`\n );\n return 1;\n }\n\n const failures: string[] = [];\n const runs: CheckRun[] = [];\n for (const problemDir of problemDirs) {\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n failures.push(`${toRelative(problemDir)}: ${formatDefaultHarnessError(defaultHarnessFileNames)}`);\n continue;\n }\n\n const modelAnswerDirs = await findModelAnswerDirs(problemDir);\n if (modelAnswerDirs.length === 0) {\n failures.push(`${toRelative(problemDir)}: no model answers found under model_answers/`);\n continue;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (!(await fileExists(path.join(problemDir, 'judge.ts')))) {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0) {\n let frontMatter;\n try {\n frontMatter = await readProblemMarkdownFrontMatter(problemDir);\n } catch (error) {\n failures.push(\n `${toRelative(problemDir)}: failed to read the problem markdown front matter: ${getErrorMessage(error)}`\n );\n continue;\n }\n if (!judgesWithoutTestCases(frontMatter)) {\n failures.push(`${toRelative(problemDir)}: ${MISSING_TEST_CASES_ERROR}`);\n continue;\n }\n }\n }\n\n const failingModelAnswerDirs = await findFailingModelAnswerDirs(problemDir);\n runs.push(\n ...modelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'accepted' })),\n ...failingModelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'rejected' }))\n );\n }\n for (const failure of failures) console.error(`✗ ${failure}`);\n\n const cliEntryPath = path.resolve(process.argv[1] ?? '');\n let passedCount = 0;\n await forEachConcurrently(runs, options.concurrency, async (run) => {\n const label = `${toRelative(run.problemDir)} ${path.relative(run.problemDir, run.answerDir).replaceAll(path.sep, '/')}`;\n const failureDetail = await executeCheckRun(run, cliEntryPath);\n if (failureDetail === undefined) {\n passedCount++;\n console.info(`✓ ${label}`);\n } else {\n failures.push(`${label}: ${failureDetail}`);\n console.error(`✗ ${label}: ${failureDetail}`);\n }\n });\n\n console.info(\n `\\n${passedCount} passed, ${failures.length} failed (${runs.length} runs, ${problemDirs.length} problems)`\n );\n return failures.length === 0 ? 0 : 1;\n}\n\n/**\n * Run one answer directory through the problem's harness and return a failure detail, if any.\n * The problem directory is copied to a temporary location first so that judging (e.g. build\n * artifacts in answer directories) never modifies the checked repository.\n */\nasync function executeCheckRun(run: CheckRun, cliEntryPath: string): Promise<string | undefined> {\n let tempRoot: string;\n let copiedProblemDir: string;\n try {\n ({ tempRoot, copiedProblemDir } = await copyProblemDirToTemporaryRoot(run.problemDir));\n } catch (error) {\n return truncate(`failed to copy the problem directory to a temporary location: ${getErrorMessage(error)}`);\n }\n\n let harnessFailureDetail;\n let removedTempRoot;\n try {\n const result = await runHarnessProcess(\n ['run', cliEntryPath, 'judge', path.relative(run.problemDir, run.answerDir)],\n {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs: RUN_TIMEOUT_MS,\n maxOutputBytes: MAX_RUN_OUTPUT_BYTES,\n tempRoot,\n }\n );\n harnessFailureDetail = summarizeHarnessFailure(run, result);\n } catch (error) {\n harnessFailureDetail = truncate(`harness execution failed: ${getErrorMessage(error)}`);\n } finally {\n removedTempRoot = await forciblyRemoveDirectory(tempRoot);\n }\n if (removedTempRoot) return harnessFailureDetail;\n const removalFailureDetail = `failed to remove the temporary copy at ${tempRoot} (judged code may have left permission-locked files)`;\n return harnessFailureDetail === undefined\n ? removalFailureDetail\n : truncate(`${harnessFailureDetail}; ${removalFailureDetail}`);\n}\n\n/** Return why the harness run failed the check, or `undefined` when it passed. */\nfunction summarizeHarnessFailure(run: CheckRun, result: HarnessProcessResult): string | undefined {\n const { stdout, stderr } = result;\n if (result.failureReason !== undefined) return truncate(result.failureReason);\n if (result.exitCode !== 0) {\n return truncate(`harness exited with ${result.exitCode ?? 'a signal'}${stderr.trim() ? `: ${stderr.trim()}` : ''}`);\n }\n\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n const testCaseResults = [];\n for (const line of resultLines) {\n let parsedResult;\n try {\n parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n } catch {\n parsedResult = undefined;\n }\n if (!parsedResult?.success) return truncate(`malformed test case result line: ${line}`);\n testCaseResults.push(parsedResult.data);\n }\n if (testCaseResults.length === 0) return 'no test case results were printed';\n\n if (run.expectation === 'accepted') {\n const rejectedResult = testCaseResults.find((result) => result.decisionCode !== DecisionCode.ACCEPTED);\n if (rejectedResult) {\n return truncate(\n `${decisionCodeNames.get(rejectedResult.decisionCode) ?? rejectedResult.decisionCode} on test case ${rejectedResult.testCaseId}${rejectedResult.stderr?.trim() ? `: ${rejectedResult.stderr.trim()}` : ''}`\n );\n }\n return undefined;\n }\n return testCaseResults.every((result) => result.decisionCode === DecisionCode.ACCEPTED)\n ? 'expected at least one failing test case, but all test cases were accepted'\n : undefined;\n}\n\nfunction parseCheckArgs(args: readonly string[]): CheckOptions {\n const options: CheckOptions = {\n rootDir: '.',\n // Serial by default: judging decides TIME_LIMIT_EXCEEDED from wall-clock time, so parallel\n // runs on a small CI runner could fail timing-sensitive problems non-deterministically.\n concurrency: 1,\n only: [],\n skip: [],\n };\n let hasRootDir = false;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--concurrency' || arg === '--only' || arg === '--skip') {\n const value = args[++index];\n if (value === undefined) throw new Error(`${arg} requires a value`);\n if (arg === '--concurrency') {\n options.concurrency = Number(value);\n if (!Number.isInteger(options.concurrency) || options.concurrency <= 0) {\n throw new Error(`--concurrency requires a positive integer, but got ${value}`);\n }\n } else if (arg === '--only') {\n options.only.push(value);\n } else {\n options.skip.push(value);\n }\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else if (hasRootDir) {\n throw new Error(`Only one root directory can be specified, but got both ${options.rootDir} and ${arg}`);\n } else {\n options.rootDir = arg;\n hasRootDir = true;\n }\n }\n return options;\n}\n\n/** Find directories containing `problem.md` or `<id>.problem.md`, without descending into found problems. */\nasync function findProblemDirs(rootDir: string): Promise<string[]> {\n const problemDirs: string[] = [];\n await visitDirectory(rootDir, problemDirs);\n return problemDirs.toSorted();\n}\n\nasync function visitDirectory(dir: string, problemDirs: string[]): Promise<void> {\n // Traversal errors (e.g. an unreadable subtree) must fail the check: skipping them silently\n // could report a green result while covering only part of the repository.\n const entries = await fs.readdir(dir, { withFileTypes: true });\n if (entries.some((entry) => entry.isFile() && (entry.name === 'problem.md' || entry.name.endsWith('.problem.md')))) {\n problemDirs.push(dir);\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n await visitDirectory(path.join(dir, entry.name), problemDirs);\n }\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await fs.stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction truncate(text: string): string {\n return text.length <= MAX_FAILURE_DETAIL_LENGTH ? text : `${text.slice(0, MAX_FAILURE_DETAIL_LENGTH)}...`;\n}\n"],"mappings":"wqBAeA,MAEM,EAA4B,IAG5B,EAAoB,IAAI,IAAoB,OAAO,QAAQA,EAAAA,YAAY,CAAC,CAAC,KAAK,CAAC,EAAM,KAAU,CAAC,EAAM,CAAI,CAAC,CAAC,EAqBlH,eAAsB,EAAiB,EAA0C,CAC/E,IAAM,EAAU,EAAe,CAAI,EAC7B,EAAUC,EAAAA,QAAK,QAAQ,EAAQ,OAAO,EAEtC,EAAc,IAAyBA,EAAAA,QAAK,SAAS,EAAS,CAAG,GAAK,IAAA,CAAK,WAAWA,EAAAA,QAAK,IAAK,GAAG,EAEnG,EAAiB,MAAM,EAAgB,CAAO,EAC9C,EAAc,EAAe,OAAQ,GAAe,CACxD,IAAM,EAAc,EAAW,CAAU,EAEzC,OADI,EAAQ,KAAK,OAAS,GAAK,CAAC,EAAQ,KAAK,KAAM,GAAc,EAAY,SAAS,CAAS,CAAC,EAAU,GACnG,CAAC,EAAQ,KAAK,KAAM,GAAc,EAAY,SAAS,CAAS,CAAC,CAC1E,CAAC,EACD,GAAI,EAAY,SAAW,EAMzB,OALA,QAAQ,MACN,EAAe,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EAAW,EAAoC,CAC5D,GAAI,CAEF,OADA,MAAMgB,EAAAA,QAAG,KAAK,CAAQ,EACf,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAEA,SAAS,EAAS,EAAsB,CACtC,OAAO,EAAK,QAAU,EAA4B,EAAO,GAAG,EAAK,MAAM,EAAG,CAAyB,EAAE,IACvG"}
1
+ {"version":3,"file":"checkAllProblems.cjs","names":["DecisionCode","path","findDefaultStdioHarnessFiles","formatDefaultHarnessError","findModelAnswerDirs","readTestCases","readProblemMarkdownFrontMatter","getErrorMessage","judgesWithoutTestCases","MISSING_TEST_CASES_ERROR","findFailingModelAnswerDirs","forEachConcurrently","copyProblemDirToTemporaryRoot","runHarnessProcess","forciblyRemoveDirectory","TEST_CASE_RESULT_PREFIX","testCaseResultSchema","fs","require_runtime","require_testCaseResult","require_defaultStdioHarness","require_readTestCases","require_temporaryProblemDirCopy","require_readProblemMarkdownFrontMatter","require_decisionCode","require_runHarnessProcess","require_findModelAnswerDirs","require_runSingleHarness","node_path","node_fs_promises","_willbooster_shared_lib","MAX_FAILURE_DETAIL_LENGTH","decisionCodeNames","name","code","checkAllProblems","options","parseCheckArgs","args","rootDir","toRelative","dir","allProblemDirs","findProblemDirs","problemDirs","relativeDir","problemDir","substring","failures","runs","defaultHarnessFileNames","modelAnswerDirs","fileExists","frontMatter","error","failingModelAnswerDirs","failure","cliEntryPath","passedCount","label","run","failureDetail","executeCheckRun","tempRoot","copiedProblemDir","truncate","harnessFailureDetail","removedTempRoot","summarizeHarnessFailure","removalFailureDetail","result","stderr","resultLines","stdout","line","testCaseResults","parsedResult","rejectedResult","hasRootDir","index","arg","value","visitDirectory","entries","entry","filePath","text"],"sources":["../../src/cli/checkAllProblems.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { forEachConcurrently, getErrorMessage } from '@willbooster/shared-lib';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { findFailingModelAnswerDirs, findModelAnswerDirs } from '../helpers/findModelAnswerDirs.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { type HarnessProcessResult, runHarnessProcess } from '../helpers/runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from '../helpers/temporaryProblemDirCopy.js';\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { formatDefaultHarnessError, MISSING_TEST_CASES_ERROR } from './runSingleHarness.js';\n\nconst RUN_TIMEOUT_MS = 600_000;\nconst MAX_RUN_OUTPUT_BYTES = 64 * 1024 * 1024;\nconst MAX_FAILURE_DETAIL_LENGTH = 1000;\n\n// DecisionCode is a plain const object (not a TypeScript enum), so it has no reverse mapping.\nconst decisionCodeNames = new Map<number, string>(Object.entries(DecisionCode).map(([name, code]) => [code, name]));\n\ninterface CheckOptions {\n rootDir: string;\n concurrency: number;\n only: string[];\n skip: string[];\n}\n\ninterface CheckRun {\n problemDir: string;\n answerDir: string;\n /** Whether all test cases must be accepted (`model_answers`) or at least one must fail (`model_answers.fails`). */\n expectation: 'accepted' | 'rejected';\n}\n\n/**\n * Judge all model answers of all problems (directories containing `problem.md` or\n * `<id>.problem.md`) under a root directory: `model_answers/*` must be fully accepted and\n * `model_answers.fails/*` must fail at least one test case. Returns the process exit code.\n */\nexport async function checkAllProblems(args: readonly string[]): Promise<number> {\n const options = parseCheckArgs(args);\n const rootDir = path.resolve(options.rootDir);\n // Normalize to forward slashes so --only / --skip substrings like courses/foo match on Windows.\n const toRelative = (dir: string): string => (path.relative(rootDir, dir) || '.').replaceAll(path.sep, '/');\n\n const allProblemDirs = await findProblemDirs(rootDir);\n const problemDirs = allProblemDirs.filter((problemDir) => {\n const relativeDir = toRelative(problemDir);\n if (options.only.length > 0 && !options.only.some((substring) => relativeDir.includes(substring))) return false;\n return !options.skip.some((substring) => relativeDir.includes(substring));\n });\n if (problemDirs.length === 0) {\n console.error(\n allProblemDirs.length === 0\n ? `No problem directories (containing problem.md or <id>.problem.md) found under ${rootDir}.`\n : `All ${allProblemDirs.length} problem directories under ${rootDir} were excluded by --only/--skip.`\n );\n return 1;\n }\n\n const failures: string[] = [];\n const runs: CheckRun[] = [];\n for (const problemDir of problemDirs) {\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n failures.push(`${toRelative(problemDir)}: ${formatDefaultHarnessError(defaultHarnessFileNames)}`);\n continue;\n }\n\n const modelAnswerDirs = await findModelAnswerDirs(problemDir);\n if (modelAnswerDirs.length === 0) {\n failures.push(`${toRelative(problemDir)}: no model answers found under model_answers/`);\n continue;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (!(await fileExists(path.join(problemDir, 'judge.ts')))) {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0) {\n let frontMatter;\n try {\n frontMatter = await readProblemMarkdownFrontMatter(problemDir);\n } catch (error) {\n failures.push(\n `${toRelative(problemDir)}: failed to read the problem markdown front matter: ${getErrorMessage(error)}`\n );\n continue;\n }\n if (!judgesWithoutTestCases(frontMatter)) {\n failures.push(`${toRelative(problemDir)}: ${MISSING_TEST_CASES_ERROR}`);\n continue;\n }\n }\n }\n\n const failingModelAnswerDirs = await findFailingModelAnswerDirs(problemDir);\n runs.push(\n ...modelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'accepted' })),\n ...failingModelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'rejected' }))\n );\n }\n for (const failure of failures) console.error(`✗ ${failure}`);\n\n const cliEntryPath = path.resolve(process.argv[1] ?? '');\n let passedCount = 0;\n await forEachConcurrently(runs, options.concurrency, async (run) => {\n const label = `${toRelative(run.problemDir)} ${path.relative(run.problemDir, run.answerDir).replaceAll(path.sep, '/')}`;\n const failureDetail = await executeCheckRun(run, cliEntryPath);\n if (failureDetail === undefined) {\n passedCount++;\n console.info(`✓ ${label}`);\n } else {\n failures.push(`${label}: ${failureDetail}`);\n console.error(`✗ ${label}: ${failureDetail}`);\n }\n });\n\n console.info(\n `\\n${passedCount} passed, ${failures.length} failed (${runs.length} runs, ${problemDirs.length} problems)`\n );\n return failures.length === 0 ? 0 : 1;\n}\n\n/**\n * Run one answer directory through the problem's harness and return a failure detail, if any.\n * The problem directory is copied to a temporary location first so that judging (e.g. build\n * artifacts in answer directories) never modifies the checked repository.\n */\nasync function executeCheckRun(run: CheckRun, cliEntryPath: string): Promise<string | undefined> {\n let tempRoot: string;\n let copiedProblemDir: string;\n try {\n ({ tempRoot, copiedProblemDir } = await copyProblemDirToTemporaryRoot(run.problemDir));\n } catch (error) {\n return truncate(`failed to copy the problem directory to a temporary location: ${getErrorMessage(error)}`);\n }\n\n let harnessFailureDetail;\n let removedTempRoot;\n try {\n const result = await runHarnessProcess(\n ['run', cliEntryPath, 'judge', path.relative(run.problemDir, run.answerDir)],\n {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs: RUN_TIMEOUT_MS,\n maxOutputBytes: MAX_RUN_OUTPUT_BYTES,\n tempRoot,\n }\n );\n harnessFailureDetail = summarizeHarnessFailure(run, result);\n } catch (error) {\n harnessFailureDetail = truncate(`harness execution failed: ${getErrorMessage(error)}`);\n } finally {\n removedTempRoot = await forciblyRemoveDirectory(tempRoot);\n }\n if (removedTempRoot) return harnessFailureDetail;\n const removalFailureDetail = `failed to remove the temporary copy at ${tempRoot} (judged code may have left permission-locked files)`;\n return harnessFailureDetail === undefined\n ? removalFailureDetail\n : truncate(`${harnessFailureDetail}; ${removalFailureDetail}`);\n}\n\n/** Return why the harness run failed the check, or `undefined` when it passed. */\nfunction summarizeHarnessFailure(run: CheckRun, result: HarnessProcessResult): string | undefined {\n const { stdout, stderr } = result;\n if (result.failureReason !== undefined) return truncate(result.failureReason);\n if (result.exitCode !== 0) {\n return truncate(`harness exited with ${result.exitCode ?? 'a signal'}${stderr.trim() ? `: ${stderr.trim()}` : ''}`);\n }\n\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n const testCaseResults = [];\n for (const line of resultLines) {\n let parsedResult;\n try {\n parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n } catch {\n parsedResult = undefined;\n }\n if (!parsedResult?.success) return truncate(`malformed test case result line: ${line}`);\n testCaseResults.push(parsedResult.data);\n }\n if (testCaseResults.length === 0) return 'no test case results were printed';\n\n if (run.expectation === 'accepted') {\n const rejectedResult = testCaseResults.find((result) => result.decisionCode !== DecisionCode.ACCEPTED);\n if (rejectedResult) {\n return truncate(\n `${decisionCodeNames.get(rejectedResult.decisionCode) ?? rejectedResult.decisionCode} on test case ${rejectedResult.testCaseId}${rejectedResult.stderr?.trim() ? `: ${rejectedResult.stderr.trim()}` : ''}`\n );\n }\n return undefined;\n }\n return testCaseResults.every((result) => result.decisionCode === DecisionCode.ACCEPTED)\n ? 'expected at least one failing test case, but all test cases were accepted'\n : undefined;\n}\n\nfunction parseCheckArgs(args: readonly string[]): CheckOptions {\n const options: CheckOptions = {\n rootDir: '.',\n // Serial by default: judging decides TIME_LIMIT_EXCEEDED from wall-clock time, so parallel\n // runs on a small CI runner could fail timing-sensitive problems non-deterministically.\n concurrency: 1,\n only: [],\n skip: [],\n };\n let hasRootDir = false;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--concurrency' || arg === '--only' || arg === '--skip') {\n const value = args[++index];\n if (value === undefined) throw new Error(`${arg} requires a value`);\n if (arg === '--concurrency') {\n options.concurrency = Number(value);\n if (!Number.isInteger(options.concurrency) || options.concurrency <= 0) {\n throw new Error(`--concurrency requires a positive integer, but got ${value}`);\n }\n } else if (arg === '--only') {\n options.only.push(value);\n } else {\n options.skip.push(value);\n }\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else if (hasRootDir) {\n throw new Error(`Only one root directory can be specified, but got both ${options.rootDir} and ${arg}`);\n } else {\n options.rootDir = arg;\n hasRootDir = true;\n }\n }\n return options;\n}\n\n/** Find directories containing `problem.md` or `<id>.problem.md`, without descending into found problems. */\nasync function findProblemDirs(rootDir: string): Promise<string[]> {\n const problemDirs: string[] = [];\n await visitDirectory(rootDir, problemDirs);\n return problemDirs.toSorted();\n}\n\nasync function visitDirectory(dir: string, problemDirs: string[]): Promise<void> {\n // Traversal errors (e.g. an unreadable subtree) must fail the check: skipping them silently\n // could report a green result while covering only part of the repository.\n const entries = await fs.readdir(dir, { withFileTypes: true });\n if (entries.some((entry) => entry.isFile() && (entry.name === 'problem.md' || entry.name.endsWith('.problem.md')))) {\n problemDirs.push(dir);\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n await visitDirectory(path.join(dir, entry.name), problemDirs);\n }\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await fs.stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction truncate(text: string): string {\n return text.length <= MAX_FAILURE_DETAIL_LENGTH ? text : `${text.slice(0, MAX_FAILURE_DETAIL_LENGTH)}...`;\n}\n"],"mappings":"wqBAeA,MAEM+B,EAA4B,IAG5BC,EAAoB,IAAI,IAAoB,OAAO,QAAQhC,EAAAA,YAAY,CAAC,CAAC,KAAK,CAACiC,EAAMC,KAAU,CAACA,EAAMD,CAAI,CAAC,CAAC,EAqBlH,eAAsBE,EAAiB,EAA0C,CAC/E,IAAMC,EAAUC,EAAeC,CAAI,EAC7BC,EAAUtC,EAAAA,QAAK,QAAQmC,EAAQ,OAAO,EAEtCI,EAAc,IAAyBvC,EAAAA,QAA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mBAAmBA,GAAK,OACnC,GAAIF,EACT,MAAU,MAAM,0DAA0D1C,EAAQ,QAAQ,OAAO4C,GAAK,MAEtG,GAAQ,QAAUA,EAClB,EAAa,EAEjB,CACA,OAAO5C,CACT,CAGA,eAAeO,EAAgB,EAAoC,CACjE,IAAMC,EAAwB,CAAC,EAE/B,OADA,MAAMsC,EAAe3C,EAASK,CAAW,EAClCA,EAAY,SAAS,CAC9B,CAEA,eAAesC,EAAe,EAAa,EAAsC,CAG/E,IAAMC,EAAU,MAAMlE,EAAAA,QAAG,QAAQwB,EAAK,CAAE,cAAe,EAAK,CAAC,EAC7D,GAAI0C,EAAQ,KAAM,GAAUC,EAAM,OAAO,IAAMA,EAAM,OAAS,cAAgBA,EAAM,KAAK,SAAS,aAAa,EAAE,EAAG,CAClHxC,EAAY,KAAKH,CAAG,EACpB,MACF,CACA,IAAK,IAAM2C,KAASD,EACbC,EAAM,YAAY,GAAKA,EAAM,OAAS,gBAAkB,GAAM,KAAK,WAAW,GAAG,GACtF,MAAMF,EAAejF,EAAAA,QAAK,KAAKwC,EAAK2C,EAAM,IAAI,EAAGxC,CAAW,CAEhE,CAEA,eAAeQ,EAAW,EAAoC,CAC5D,GAAI,CAEF,OADA,MAAMnC,EAAAA,QAAG,KAAKoE,CAAQ,EACf,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAEA,SAASpB,EAAS,EAAsB,CACtC,OAAOqB,EAAK,QAAUvD,EAA4BuD,EAAO,GAAGA,EAAK,MAAM,EAAGvD,CAAyB,EAAE,IACvG"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkAllProblems.js","names":[],"sources":["../../src/cli/checkAllProblems.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { forEachConcurrently, getErrorMessage } from '@willbooster/shared-lib';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { findFailingModelAnswerDirs, findModelAnswerDirs } from '../helpers/findModelAnswerDirs.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { type HarnessProcessResult, runHarnessProcess } from '../helpers/runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from '../helpers/temporaryProblemDirCopy.js';\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { formatDefaultHarnessError, MISSING_TEST_CASES_ERROR } from './runSingleHarness.js';\n\nconst RUN_TIMEOUT_MS = 600_000;\nconst MAX_RUN_OUTPUT_BYTES = 64 * 1024 * 1024;\nconst MAX_FAILURE_DETAIL_LENGTH = 1000;\n\n// DecisionCode is a plain const object (not a TypeScript enum), so it has no reverse mapping.\nconst decisionCodeNames = new Map<number, string>(Object.entries(DecisionCode).map(([name, code]) => [code, name]));\n\ninterface CheckOptions {\n rootDir: string;\n concurrency: number;\n only: string[];\n skip: string[];\n}\n\ninterface CheckRun {\n problemDir: string;\n answerDir: string;\n /** Whether all test cases must be accepted (`model_answers`) or at least one must fail (`model_answers.fails`). */\n expectation: 'accepted' | 'rejected';\n}\n\n/**\n * Judge all model answers of all problems (directories containing `problem.md` or\n * `<id>.problem.md`) under a root directory: `model_answers/*` must be fully accepted and\n * `model_answers.fails/*` must fail at least one test case. Returns the process exit code.\n */\nexport async function checkAllProblems(args: readonly string[]): Promise<number> {\n const options = parseCheckArgs(args);\n const rootDir = path.resolve(options.rootDir);\n // Normalize to forward slashes so --only / --skip substrings like courses/foo match on Windows.\n const toRelative = (dir: string): string => (path.relative(rootDir, dir) || '.').replaceAll(path.sep, '/');\n\n const allProblemDirs = await findProblemDirs(rootDir);\n const problemDirs = allProblemDirs.filter((problemDir) => {\n const relativeDir = toRelative(problemDir);\n if (options.only.length > 0 && !options.only.some((substring) => relativeDir.includes(substring))) return false;\n return !options.skip.some((substring) => relativeDir.includes(substring));\n });\n if (problemDirs.length === 0) {\n console.error(\n allProblemDirs.length === 0\n ? `No problem directories (containing problem.md or <id>.problem.md) found under ${rootDir}.`\n : `All ${allProblemDirs.length} problem directories under ${rootDir} were excluded by --only/--skip.`\n );\n return 1;\n }\n\n const failures: string[] = [];\n const runs: CheckRun[] = [];\n for (const problemDir of problemDirs) {\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n failures.push(`${toRelative(problemDir)}: ${formatDefaultHarnessError(defaultHarnessFileNames)}`);\n continue;\n }\n\n const modelAnswerDirs = await findModelAnswerDirs(problemDir);\n if (modelAnswerDirs.length === 0) {\n failures.push(`${toRelative(problemDir)}: no model answers found under model_answers/`);\n continue;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (!(await fileExists(path.join(problemDir, 'judge.ts')))) {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0) {\n let frontMatter;\n try {\n frontMatter = await readProblemMarkdownFrontMatter(problemDir);\n } catch (error) {\n failures.push(\n `${toRelative(problemDir)}: failed to read the problem markdown front matter: ${getErrorMessage(error)}`\n );\n continue;\n }\n if (!judgesWithoutTestCases(frontMatter)) {\n failures.push(`${toRelative(problemDir)}: ${MISSING_TEST_CASES_ERROR}`);\n continue;\n }\n }\n }\n\n const failingModelAnswerDirs = await findFailingModelAnswerDirs(problemDir);\n runs.push(\n ...modelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'accepted' })),\n ...failingModelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'rejected' }))\n );\n }\n for (const failure of failures) console.error(`✗ ${failure}`);\n\n const cliEntryPath = path.resolve(process.argv[1] ?? '');\n let passedCount = 0;\n await forEachConcurrently(runs, options.concurrency, async (run) => {\n const label = `${toRelative(run.problemDir)} ${path.relative(run.problemDir, run.answerDir).replaceAll(path.sep, '/')}`;\n const failureDetail = await executeCheckRun(run, cliEntryPath);\n if (failureDetail === undefined) {\n passedCount++;\n console.info(`✓ ${label}`);\n } else {\n failures.push(`${label}: ${failureDetail}`);\n console.error(`✗ ${label}: ${failureDetail}`);\n }\n });\n\n console.info(\n `\\n${passedCount} passed, ${failures.length} failed (${runs.length} runs, ${problemDirs.length} problems)`\n );\n return failures.length === 0 ? 0 : 1;\n}\n\n/**\n * Run one answer directory through the problem's harness and return a failure detail, if any.\n * The problem directory is copied to a temporary location first so that judging (e.g. build\n * artifacts in answer directories) never modifies the checked repository.\n */\nasync function executeCheckRun(run: CheckRun, cliEntryPath: string): Promise<string | undefined> {\n let tempRoot: string;\n let copiedProblemDir: string;\n try {\n ({ tempRoot, copiedProblemDir } = await copyProblemDirToTemporaryRoot(run.problemDir));\n } catch (error) {\n return truncate(`failed to copy the problem directory to a temporary location: ${getErrorMessage(error)}`);\n }\n\n let harnessFailureDetail;\n let removedTempRoot;\n try {\n const result = await runHarnessProcess(\n ['run', cliEntryPath, 'judge', path.relative(run.problemDir, run.answerDir)],\n {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs: RUN_TIMEOUT_MS,\n maxOutputBytes: MAX_RUN_OUTPUT_BYTES,\n tempRoot,\n }\n );\n harnessFailureDetail = summarizeHarnessFailure(run, result);\n } catch (error) {\n harnessFailureDetail = truncate(`harness execution failed: ${getErrorMessage(error)}`);\n } finally {\n removedTempRoot = await forciblyRemoveDirectory(tempRoot);\n }\n if (removedTempRoot) return harnessFailureDetail;\n const removalFailureDetail = `failed to remove the temporary copy at ${tempRoot} (judged code may have left permission-locked files)`;\n return harnessFailureDetail === undefined\n ? removalFailureDetail\n : truncate(`${harnessFailureDetail}; ${removalFailureDetail}`);\n}\n\n/** Return why the harness run failed the check, or `undefined` when it passed. */\nfunction summarizeHarnessFailure(run: CheckRun, result: HarnessProcessResult): string | undefined {\n const { stdout, stderr } = result;\n if (result.failureReason !== undefined) return truncate(result.failureReason);\n if (result.exitCode !== 0) {\n return truncate(`harness exited with ${result.exitCode ?? 'a signal'}${stderr.trim() ? `: ${stderr.trim()}` : ''}`);\n }\n\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n const testCaseResults = [];\n for (const line of resultLines) {\n let parsedResult;\n try {\n parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n } catch {\n parsedResult = undefined;\n }\n if (!parsedResult?.success) return truncate(`malformed test case result line: ${line}`);\n testCaseResults.push(parsedResult.data);\n }\n if (testCaseResults.length === 0) return 'no test case results were printed';\n\n if (run.expectation === 'accepted') {\n const rejectedResult = testCaseResults.find((result) => result.decisionCode !== DecisionCode.ACCEPTED);\n if (rejectedResult) {\n return truncate(\n `${decisionCodeNames.get(rejectedResult.decisionCode) ?? rejectedResult.decisionCode} on test case ${rejectedResult.testCaseId}${rejectedResult.stderr?.trim() ? `: ${rejectedResult.stderr.trim()}` : ''}`\n );\n }\n return undefined;\n }\n return testCaseResults.every((result) => result.decisionCode === DecisionCode.ACCEPTED)\n ? 'expected at least one failing test case, but all test cases were accepted'\n : undefined;\n}\n\nfunction parseCheckArgs(args: readonly string[]): CheckOptions {\n const options: CheckOptions = {\n rootDir: '.',\n // Serial by default: judging decides TIME_LIMIT_EXCEEDED from wall-clock time, so parallel\n // runs on a small CI runner could fail timing-sensitive problems non-deterministically.\n concurrency: 1,\n only: [],\n skip: [],\n };\n let hasRootDir = false;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--concurrency' || arg === '--only' || arg === '--skip') {\n const value = args[++index];\n if (value === undefined) throw new Error(`${arg} requires a value`);\n if (arg === '--concurrency') {\n options.concurrency = Number(value);\n if (!Number.isInteger(options.concurrency) || options.concurrency <= 0) {\n throw new Error(`--concurrency requires a positive integer, but got ${value}`);\n }\n } else if (arg === '--only') {\n options.only.push(value);\n } else {\n options.skip.push(value);\n }\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else if (hasRootDir) {\n throw new Error(`Only one root directory can be specified, but got both ${options.rootDir} and ${arg}`);\n } else {\n options.rootDir = arg;\n hasRootDir = true;\n }\n }\n return options;\n}\n\n/** Find directories containing `problem.md` or `<id>.problem.md`, without descending into found problems. */\nasync function findProblemDirs(rootDir: string): Promise<string[]> {\n const problemDirs: string[] = [];\n await visitDirectory(rootDir, problemDirs);\n return problemDirs.toSorted();\n}\n\nasync function visitDirectory(dir: string, problemDirs: string[]): Promise<void> {\n // Traversal errors (e.g. an unreadable subtree) must fail the check: skipping them silently\n // could report a green result while covering only part of the repository.\n const entries = await fs.readdir(dir, { withFileTypes: true });\n if (entries.some((entry) => entry.isFile() && (entry.name === 'problem.md' || entry.name.endsWith('.problem.md')))) {\n problemDirs.push(dir);\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n await visitDirectory(path.join(dir, entry.name), problemDirs);\n }\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await fs.stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction truncate(text: string): string {\n return text.length <= MAX_FAILURE_DETAIL_LENGTH ? text : `${text.slice(0, MAX_FAILURE_DETAIL_LENGTH)}...`;\n}\n"],"mappings":"y6BAeA,MAEM,EAA4B,IAG5B,EAAoB,IAAI,IAAoB,OAAO,QAAQ,CAAY,CAAC,CAAC,KAAK,CAAC,EAAM,KAAU,CAAC,EAAM,CAAI,CAAC,CAAC,EAqBlH,eAAsB,EAAiB,EAA0C,CAC/E,IAAM,EAAU,EAAe,CAAI,EAC7B,EAAU,EAAK,QAAQ,EAAQ,OAAO,EAEtC,EAAc,IAAyB,EAAK,SAAS,EAAS,CAAG,GAAK,IAAA,CAAK,WAAW,EAAK,IAAK,GAAG,EAEnG,EAAiB,MAAM,E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oC,CAC5D,GAAI,CAEF,OADA,MAAM,EAAG,KAAK,CAAQ,EACf,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAEA,SAAS,EAAS,EAAsB,CACtC,OAAO,EAAK,QAAU,EAA4B,EAAO,GAAG,EAAK,MAAM,EAAG,CAAyB,EAAE,IACvG"}
1
+ {"version":3,"file":"checkAllProblems.js","names":["path","fs","MAX_FAILURE_DETAIL_LENGTH","decisionCodeNames","DecisionCode","name","code","checkAllProblems","options","parseCheckArgs","args","rootDir","toRelative","dir","allProblemDirs","findProblemDirs","problemDirs","relativeDir","problemDir","substring","failures","runs","defaultHarnessFileNames","findDefaultStdioHarnessFiles","formatDefaultHarnessError","modelAnswerDirs","findModelAnswerDirs","fileExists","readTestCases","frontMatter","readProblemMarkdownFrontMatter","error","getErrorMessage","judgesWithoutTestCases","MISSING_TEST_CASES_ERROR","failingModelAnswerDirs","findFailingModelAnswerDirs","failure","cliEntryPath","passedCount","forEachConcurrently","label","run","failureDetail","executeCheckRun","tempRoot","copiedProblemDir","copyProblemDirToTemporaryRoot","truncate","harnessFailureDetail","removedTempRoot","summarizeHarnessFailure","runHarnessProcess","forciblyRemoveDirectory","removalFailureDetail","result","stderr","resultLines","stdout","line","TEST_CASE_RESULT_PREFIX","testCaseResults","parsedResult","testCaseResultSchema","rejectedResult","hasRootDir","index","arg","value","visitDirectory","entries","entry","filePath","text"],"sources":["../../src/cli/checkAllProblems.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\nimport { forEachConcurrently, getErrorMessage } from '@willbooster/shared-lib';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { findFailingModelAnswerDirs, findModelAnswerDirs } from '../helpers/findModelAnswerDirs.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { type HarnessProcessResult, runHarnessProcess } from '../helpers/runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from '../helpers/temporaryProblemDirCopy.js';\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { formatDefaultHarnessError, MISSING_TEST_CASES_ERROR } from './runSingleHarness.js';\n\nconst RUN_TIMEOUT_MS = 600_000;\nconst MAX_RUN_OUTPUT_BYTES = 64 * 1024 * 1024;\nconst MAX_FAILURE_DETAIL_LENGTH = 1000;\n\n// DecisionCode is a plain const object (not a TypeScript enum), so it has no reverse mapping.\nconst decisionCodeNames = new Map<number, string>(Object.entries(DecisionCode).map(([name, code]) => [code, name]));\n\ninterface CheckOptions {\n rootDir: string;\n concurrency: number;\n only: string[];\n skip: string[];\n}\n\ninterface CheckRun {\n problemDir: string;\n answerDir: string;\n /** Whether all test cases must be accepted (`model_answers`) or at least one must fail (`model_answers.fails`). */\n expectation: 'accepted' | 'rejected';\n}\n\n/**\n * Judge all model answers of all problems (directories containing `problem.md` or\n * `<id>.problem.md`) under a root directory: `model_answers/*` must be fully accepted and\n * `model_answers.fails/*` must fail at least one test case. Returns the process exit code.\n */\nexport async function checkAllProblems(args: readonly string[]): Promise<number> {\n const options = parseCheckArgs(args);\n const rootDir = path.resolve(options.rootDir);\n // Normalize to forward slashes so --only / --skip substrings like courses/foo match on Windows.\n const toRelative = (dir: string): string => (path.relative(rootDir, dir) || '.').replaceAll(path.sep, '/');\n\n const allProblemDirs = await findProblemDirs(rootDir);\n const problemDirs = allProblemDirs.filter((problemDir) => {\n const relativeDir = toRelative(problemDir);\n if (options.only.length > 0 && !options.only.some((substring) => relativeDir.includes(substring))) return false;\n return !options.skip.some((substring) => relativeDir.includes(substring));\n });\n if (problemDirs.length === 0) {\n console.error(\n allProblemDirs.length === 0\n ? `No problem directories (containing problem.md or <id>.problem.md) found under ${rootDir}.`\n : `All ${allProblemDirs.length} problem directories under ${rootDir} were excluded by --only/--skip.`\n );\n return 1;\n }\n\n const failures: string[] = [];\n const runs: CheckRun[] = [];\n for (const problemDir of problemDirs) {\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n failures.push(`${toRelative(problemDir)}: ${formatDefaultHarnessError(defaultHarnessFileNames)}`);\n continue;\n }\n\n const modelAnswerDirs = await findModelAnswerDirs(problemDir);\n if (modelAnswerDirs.length === 0) {\n failures.push(`${toRelative(problemDir)}: no model answers found under model_answers/`);\n continue;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (!(await fileExists(path.join(problemDir, 'judge.ts')))) {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0) {\n let frontMatter;\n try {\n frontMatter = await readProblemMarkdownFrontMatter(problemDir);\n } catch (error) {\n failures.push(\n `${toRelative(problemDir)}: failed to read the problem markdown front matter: ${getErrorMessage(error)}`\n );\n continue;\n }\n if (!judgesWithoutTestCases(frontMatter)) {\n failures.push(`${toRelative(problemDir)}: ${MISSING_TEST_CASES_ERROR}`);\n continue;\n }\n }\n }\n\n const failingModelAnswerDirs = await findFailingModelAnswerDirs(problemDir);\n runs.push(\n ...modelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'accepted' })),\n ...failingModelAnswerDirs.map((answerDir): CheckRun => ({ problemDir, answerDir, expectation: 'rejected' }))\n );\n }\n for (const failure of failures) console.error(`✗ ${failure}`);\n\n const cliEntryPath = path.resolve(process.argv[1] ?? '');\n let passedCount = 0;\n await forEachConcurrently(runs, options.concurrency, async (run) => {\n const label = `${toRelative(run.problemDir)} ${path.relative(run.problemDir, run.answerDir).replaceAll(path.sep, '/')}`;\n const failureDetail = await executeCheckRun(run, cliEntryPath);\n if (failureDetail === undefined) {\n passedCount++;\n console.info(`✓ ${label}`);\n } else {\n failures.push(`${label}: ${failureDetail}`);\n console.error(`✗ ${label}: ${failureDetail}`);\n }\n });\n\n console.info(\n `\\n${passedCount} passed, ${failures.length} failed (${runs.length} runs, ${problemDirs.length} problems)`\n );\n return failures.length === 0 ? 0 : 1;\n}\n\n/**\n * Run one answer directory through the problem's harness and return a failure detail, if any.\n * The problem directory is copied to a temporary location first so that judging (e.g. build\n * artifacts in answer directories) never modifies the checked repository.\n */\nasync function executeCheckRun(run: CheckRun, cliEntryPath: string): Promise<string | undefined> {\n let tempRoot: string;\n let copiedProblemDir: string;\n try {\n ({ tempRoot, copiedProblemDir } = await copyProblemDirToTemporaryRoot(run.problemDir));\n } catch (error) {\n return truncate(`failed to copy the problem directory to a temporary location: ${getErrorMessage(error)}`);\n }\n\n let harnessFailureDetail;\n let removedTempRoot;\n try {\n const result = await runHarnessProcess(\n ['run', cliEntryPath, 'judge', path.relative(run.problemDir, run.answerDir)],\n {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs: RUN_TIMEOUT_MS,\n maxOutputBytes: MAX_RUN_OUTPUT_BYTES,\n tempRoot,\n }\n );\n harnessFailureDetail = summarizeHarnessFailure(run, result);\n } catch (error) {\n harnessFailureDetail = truncate(`harness execution failed: ${getErrorMessage(error)}`);\n } finally {\n removedTempRoot = await forciblyRemoveDirectory(tempRoot);\n }\n if (removedTempRoot) return harnessFailureDetail;\n const removalFailureDetail = `failed to remove the temporary copy at ${tempRoot} (judged code may have left permission-locked files)`;\n return harnessFailureDetail === undefined\n ? removalFailureDetail\n : truncate(`${harnessFailureDetail}; ${removalFailureDetail}`);\n}\n\n/** Return why the harness run failed the check, or `undefined` when it passed. */\nfunction summarizeHarnessFailure(run: CheckRun, result: HarnessProcessResult): string | undefined {\n const { stdout, stderr } = result;\n if (result.failureReason !== undefined) return truncate(result.failureReason);\n if (result.exitCode !== 0) {\n return truncate(`harness exited with ${result.exitCode ?? 'a signal'}${stderr.trim() ? `: ${stderr.trim()}` : ''}`);\n }\n\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n const testCaseResults = [];\n for (const line of resultLines) {\n let parsedResult;\n try {\n parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n } catch {\n parsedResult = undefined;\n }\n if (!parsedResult?.success) return truncate(`malformed test case result line: ${line}`);\n testCaseResults.push(parsedResult.data);\n }\n if (testCaseResults.length === 0) return 'no test case results were printed';\n\n if (run.expectation === 'accepted') {\n const rejectedResult = testCaseResults.find((result) => result.decisionCode !== DecisionCode.ACCEPTED);\n if (rejectedResult) {\n return truncate(\n `${decisionCodeNames.get(rejectedResult.decisionCode) ?? rejectedResult.decisionCode} on test case ${rejectedResult.testCaseId}${rejectedResult.stderr?.trim() ? `: ${rejectedResult.stderr.trim()}` : ''}`\n );\n }\n return undefined;\n }\n return testCaseResults.every((result) => result.decisionCode === DecisionCode.ACCEPTED)\n ? 'expected at least one failing test case, but all test cases were accepted'\n : undefined;\n}\n\nfunction parseCheckArgs(args: readonly string[]): CheckOptions {\n const options: CheckOptions = {\n rootDir: '.',\n // Serial by default: judging decides TIME_LIMIT_EXCEEDED from wall-clock time, so parallel\n // runs on a small CI runner could fail timing-sensitive problems non-deterministically.\n concurrency: 1,\n only: [],\n skip: [],\n };\n let hasRootDir = false;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--concurrency' || arg === '--only' || arg === '--skip') {\n const value = args[++index];\n if (value === undefined) throw new Error(`${arg} requires a value`);\n if (arg === '--concurrency') {\n options.concurrency = Number(value);\n if (!Number.isInteger(options.concurrency) || options.concurrency <= 0) {\n throw new Error(`--concurrency requires a positive integer, but got ${value}`);\n }\n } else if (arg === '--only') {\n options.only.push(value);\n } else {\n options.skip.push(value);\n }\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else if (hasRootDir) {\n throw new Error(`Only one root directory can be specified, but got both ${options.rootDir} and ${arg}`);\n } else {\n options.rootDir = arg;\n hasRootDir = true;\n }\n }\n return options;\n}\n\n/** Find directories containing `problem.md` or `<id>.problem.md`, without descending into found problems. */\nasync function findProblemDirs(rootDir: string): Promise<string[]> {\n const problemDirs: string[] = [];\n await visitDirectory(rootDir, problemDirs);\n return problemDirs.toSorted();\n}\n\nasync function visitDirectory(dir: string, problemDirs: string[]): Promise<void> {\n // Traversal errors (e.g. an unreadable subtree) must fail the check: skipping them silently\n // could report a green result while covering only part of the repository.\n const entries = await fs.readdir(dir, { withFileTypes: true });\n if (entries.some((entry) => entry.isFile() && (entry.name === 'problem.md' || entry.name.endsWith('.problem.md')))) {\n problemDirs.push(dir);\n return;\n }\n for (const entry of entries) {\n if (!entry.isDirectory() || entry.name === 'node_modules' || entry.name.startsWith('.')) continue;\n await visitDirectory(path.join(dir, entry.name), problemDirs);\n }\n}\n\nasync function fileExists(filePath: string): Promise<boolean> {\n try {\n await fs.stat(filePath);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction truncate(text: string): string {\n return text.length <= MAX_FAILURE_DETAIL_LENGTH ? text : `${text.slice(0, MAX_FAILURE_DETAIL_LENGTH)}...`;\n}\n"],"mappings":"y6BAeA,MAEME,EAA4B,IAG5BC,EAAoB,IAAI,IAAoB,OAAO,QAAQC,CAAY,CAAC,CAAC,KAAK,CAACC,EAAMC,KAAU,CAACA,EAAMD,CAAI,CAAC,CAAC,EAqBlH,eAAsBE,EAAiB,EAA0C,CAC/E,IAAMC,EAAUC,EAAeC,CAAI,EAC7BC,EAAUX,EAAK,QAAQQ,EAAQ,OAAO,EAEtCI,EAAc,IAAyBZ,EAAK,SAASW,EAASE,CAAG,GAAK,IAAA,CAAK,WAAWb,EAAK,IAAK,GAAG,EAEnGc,EAAiB,MAAMC,EAAgBJ,CAAO,EAC9CK,EAAcF,EAAe,OAAQ,GAAe,CACxD,IAAMG,EAAcL,EAAWM,CAAU,EAEzC,OADIV,EAAQ,KAAK,OAAS,GAAK,C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AAG,EACpB,MACF,CACA,IAAK,IAAM0D,KAASD,EACbC,EAAM,YAAY,GAAKA,EAAM,OAAS,gBAAkB,GAAM,KAAK,WAAW,GAAG,GACtF,MAAMF,EAAerE,EAAK,KAAKa,EAAK0D,EAAM,IAAI,EAAGvD,CAAW,CAEhE,CAEA,eAAeW,EAAW,EAAoC,CAC5D,GAAI,CAEF,OADA,MAAM1B,EAAG,KAAKuE,CAAQ,EACf,EACT,MAAQ,CACN,MAAO,EACT,CACF,CAEA,SAASxB,EAAS,EAAsB,CACtC,OAAOyB,EAAK,QAAUvE,EAA4BuE,EAAO,GAAGA,EAAK,MAAM,EAAGvE,CAAyB,EAAE,IACvG"}
@@ -1 +1 @@
1
- {"version":3,"file":"exercodeProblem.cjs","names":["runSingleHarness","validateLearningMaterial","checkAllProblems","VALIDATE_SUBCOMMANDS"],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\nimport { VALIDATE_SUBCOMMANDS, type ValidateSubcommand, validateLearningMaterial } from './validateLearningMaterial.js';\n\nconst usage = `Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode-problem judge <answerDir> [paramsJson]\n exercode-problem debug <answerDir> [paramsJson]\n exercode-problem validate-problem <problemDir>...\n exercode-problem validate-course <courseDir> [--problems-dir <dir>]\n exercode-problem validate-contest <contestYamlPath> [--problems-dir <dir>]\n\nWithout a subcommand, judge all model answers of all problems under rootDir\n(default: the current directory). Use \\`judge\\` or \\`debug\\` in a problem\ndirectory to run one answer directory, e.g.:\n exercode-problem debug model_answers/python '{ \"stdin\": \"1 2\" }'\nThe \\`validate-*\\` subcommands check problem directories, a course directory\n(course.yaml and lecture materials), or a contest (*.contest.yaml) file\nwithout running any program.`;\n\n// oxlint-disable-next-line unicorn/prefer-top-level-await -- the CJS build output does not support top-level await\nvoid main();\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n if (args[0] === '--help' || args[0] === '-h') {\n // console.log would be stripped from the built CLI, so print the usage with console.info.\n console.info(usage);\n return;\n }\n try {\n if (args[0] === 'judge' || args[0] === 'debug') {\n if (args.length < 2) {\n console.error(usage);\n process.exitCode = 1;\n return;\n }\n // Harness scripts and presets read the answer directory and params from fixed positions in\n // `process.argv`, so drop the subcommand to restore those positions.\n process.argv.splice(2, 1);\n process.exitCode = await runSingleHarness(args[0]);\n } else if (isValidateSubcommand(args[0])) {\n process.exitCode = await validateLearningMaterial(args[0], args.slice(1));\n } else {\n process.exitCode = await checkAllProblems(args);\n }\n } catch (error) {\n // Print the whole error: harness failures need their stack and `cause`, not just the message.\n console.error(error);\n process.exitCode = 1;\n }\n}\n\nfunction isValidateSubcommand(arg: string | undefined): arg is ValidateSubcommand {\n return (VALIDATE_SUBCOMMANDS as readonly string[]).includes(arg ?? '');\n}\n"],"mappings":"uIAIM,EAAQ;;;;;;;;;;;;;8BAgBT,EAAK,EAEV,eAAe,GAAsB,CACnC,IAAM,EAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,GAAI,EAAK,KAAO,UAAY,EAAK,KAAO,KAAM,CAE5C,QAAQ,KAAK,CAAK,EAClB,MACF,CACA,GAAI,CACF,GAAI,EAAK,KAAO,SAAW,EAAK,KAAO,QAAS,CAC9C,GAAI,EAAK,OAAS,EAAG,CACnB,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,EACnB,MACF,CAGA,QAAQ,KAAK,OAAO,EAAG,CAAC,EACxB,QAAQ,SAAW,MAAMA,EAAAA,iBAAiB,EAAK,EAAE,CACnD,MAAW,EAAqB,EAAK,EAAE,EACrC,QAAQ,SAAW,MAAMC,EAAAA,yBAAyB,EAAK,GAAI,EAAK,MAAM,CAAC,CAAC,EAExE,QAAQ,SAAW,MAAMC,EAAAA,iBAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF,CAEA,SAAS,EAAqB,EAAoD,CAChF,OAAQC,EAAAA,qBAA2C,SAAS,GAAO,EAAE,CACvE"}
1
+ {"version":3,"file":"exercodeProblem.cjs","names":["runSingleHarness","validateLearningMaterial","checkAllProblems","VALIDATE_SUBCOMMANDS","require_runSingleHarness","require_checkAllProblems","require_validateLearningMaterial","usage","main","args","isValidateSubcommand","error","arg"],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\nimport { VALIDATE_SUBCOMMANDS, type ValidateSubcommand, validateLearningMaterial } from './validateLearningMaterial.js';\n\nconst usage = `Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode-problem judge <answerDir> [paramsJson]\n exercode-problem debug <answerDir> [paramsJson]\n exercode-problem validate-problem <problemDir>...\n exercode-problem validate-course <courseDir> [--problems-dir <dir>]\n exercode-problem validate-contest <contestYamlPath> [--problems-dir <dir>]\n\nWithout a subcommand, judge all model answers of all problems under rootDir\n(default: the current directory). Use \\`judge\\` or \\`debug\\` in a problem\ndirectory to run one answer directory, e.g.:\n exercode-problem debug model_answers/python '{ \"stdin\": \"1 2\" }'\nThe \\`validate-*\\` subcommands check problem directories, a course directory\n(course.yaml and lecture materials), or a contest (*.contest.yaml) file\nwithout running any program.`;\n\n// oxlint-disable-next-line unicorn/prefer-top-level-await -- the CJS build output does not support top-level await\nvoid main();\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n if (args[0] === '--help' || args[0] === '-h') {\n // console.log would be stripped from the built CLI, so print the usage with console.info.\n console.info(usage);\n return;\n }\n try {\n if (args[0] === 'judge' || args[0] === 'debug') {\n if (args.length < 2) {\n console.error(usage);\n process.exitCode = 1;\n return;\n }\n // Harness scripts and presets read the answer directory and params from fixed positions in\n // `process.argv`, so drop the subcommand to restore those positions.\n process.argv.splice(2, 1);\n process.exitCode = await runSingleHarness(args[0]);\n } else if (isValidateSubcommand(args[0])) {\n process.exitCode = await validateLearningMaterial(args[0], args.slice(1));\n } else {\n process.exitCode = await checkAllProblems(args);\n }\n } catch (error) {\n // Print the whole error: harness failures need their stack and `cause`, not just the message.\n console.error(error);\n process.exitCode = 1;\n }\n}\n\nfunction isValidateSubcommand(arg: string | undefined): arg is ValidateSubcommand {\n return (VALIDATE_SUBCOMMANDS as readonly string[]).includes(arg ?? '');\n}\n"],"mappings":"uIAIMO,EAAQ;;;;;;;;;;;;;8BAgBTC,EAAK,EAEV,eAAeA,GAAsB,CACnC,IAAMC,EAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,GAAIA,EAAK,KAAO,UAAYA,EAAK,KAAO,KAAM,CAE5C,QAAQ,KAAKF,CAAK,EAClB,MACF,CACA,GAAI,CACF,GAAIE,EAAK,KAAO,SAAWA,EAAK,KAAO,QAAS,CAC9C,GAAIA,EAAK,OAAS,EAAG,CACnB,QAAQ,MAAMF,CAAK,EACnB,QAAQ,SAAW,EACnB,MACF,CAGA,QAAQ,KAAK,OAAO,EAAG,CAAC,EACxB,QAAQ,SAAW,MAAMP,EAAAA,iBAAiBS,EAAK,EAAE,CACnD,MAAWC,EAAqBD,EAAK,EAAE,EACrC,QAAQ,SAAW,MAAMR,EAAAA,yBAAyBQ,EAAK,GAAIA,EAAK,MAAM,CAAC,CAAC,EAExE,QAAQ,SAAW,MAAMP,EAAAA,iBAAiBO,CAAI,CAElD,OAASE,EAAO,CAEd,QAAQ,MAAMA,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF,CAEA,SAASD,EAAqB,EAAoD,CAChF,OAAQP,EAAAA,qBAA2C,SAASS,GAAO,EAAE,CACvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"exercodeProblem.js","names":[],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\nimport { VALIDATE_SUBCOMMANDS, type ValidateSubcommand, validateLearningMaterial } from './validateLearningMaterial.js';\n\nconst usage = `Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode-problem judge <answerDir> [paramsJson]\n exercode-problem debug <answerDir> [paramsJson]\n exercode-problem validate-problem <problemDir>...\n exercode-problem validate-course <courseDir> [--problems-dir <dir>]\n exercode-problem validate-contest <contestYamlPath> [--problems-dir <dir>]\n\nWithout a subcommand, judge all model answers of all problems under rootDir\n(default: the current directory). Use \\`judge\\` or \\`debug\\` in a problem\ndirectory to run one answer directory, e.g.:\n exercode-problem debug model_answers/python '{ \"stdin\": \"1 2\" }'\nThe \\`validate-*\\` subcommands check problem directories, a course directory\n(course.yaml and lecture materials), or a contest (*.contest.yaml) file\nwithout running any program.`;\n\n// oxlint-disable-next-line unicorn/prefer-top-level-await -- the CJS build output does not support top-level await\nvoid main();\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n if (args[0] === '--help' || args[0] === '-h') {\n // console.log would be stripped from the built CLI, so print the usage with console.info.\n console.info(usage);\n return;\n }\n try {\n if (args[0] === 'judge' || args[0] === 'debug') {\n if (args.length < 2) {\n console.error(usage);\n process.exitCode = 1;\n return;\n }\n // Harness scripts and presets read the answer directory and params from fixed positions in\n // `process.argv`, so drop the subcommand to restore those positions.\n process.argv.splice(2, 1);\n process.exitCode = await runSingleHarness(args[0]);\n } else if (isValidateSubcommand(args[0])) {\n process.exitCode = await validateLearningMaterial(args[0], args.slice(1));\n } else {\n process.exitCode = await checkAllProblems(args);\n }\n } catch (error) {\n // Print the whole error: harness failures need their stack and `cause`, not just the message.\n console.error(error);\n process.exitCode = 1;\n }\n}\n\nfunction isValidateSubcommand(arg: string | undefined): arg is ValidateSubcommand {\n return (VALIDATE_SUBCOMMANDS as readonly string[]).includes(arg ?? '');\n}\n"],"mappings":"qNAIA,MAAM,EAAQ;;;;;;;;;;;;;8BAgBT,EAAK,EAEV,eAAe,GAAsB,CACnC,IAAM,EAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,GAAI,EAAK,KAAO,UAAY,EAAK,KAAO,KAAM,CAE5C,QAAQ,KAAK,CAAK,EAClB,MACF,CACA,GAAI,CACF,GAAI,EAAK,KAAO,SAAW,EAAK,KAAO,QAAS,CAC9C,GAAI,EAAK,OAAS,EAAG,CACnB,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,EACnB,MACF,CAGA,QAAQ,KAAK,OAAO,EAAG,CAAC,EACxB,QAAQ,SAAW,MAAM,EAAiB,EAAK,EAAE,CACnD,MAAW,EAAqB,EAAK,EAAE,EACrC,QAAQ,SAAW,MAAM,EAAyB,EAAK,GAAI,EAAK,MAAM,CAAC,CAAC,EAExE,QAAQ,SAAW,MAAM,EAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF,CAEA,SAAS,EAAqB,EAAoD,CAChF,OAAQ,EAA2C,SAAS,GAAO,EAAE,CACvE"}
1
+ {"version":3,"file":"exercodeProblem.js","names":["usage","main","args","runSingleHarness","isValidateSubcommand","validateLearningMaterial","checkAllProblems","error","VALIDATE_SUBCOMMANDS","arg"],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\nimport { VALIDATE_SUBCOMMANDS, type ValidateSubcommand, validateLearningMaterial } from './validateLearningMaterial.js';\n\nconst usage = `Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode-problem judge <answerDir> [paramsJson]\n exercode-problem debug <answerDir> [paramsJson]\n exercode-problem validate-problem <problemDir>...\n exercode-problem validate-course <courseDir> [--problems-dir <dir>]\n exercode-problem validate-contest <contestYamlPath> [--problems-dir <dir>]\n\nWithout a subcommand, judge all model answers of all problems under rootDir\n(default: the current directory). Use \\`judge\\` or \\`debug\\` in a problem\ndirectory to run one answer directory, e.g.:\n exercode-problem debug model_answers/python '{ \"stdin\": \"1 2\" }'\nThe \\`validate-*\\` subcommands check problem directories, a course directory\n(course.yaml and lecture materials), or a contest (*.contest.yaml) file\nwithout running any program.`;\n\n// oxlint-disable-next-line unicorn/prefer-top-level-await -- the CJS build output does not support top-level await\nvoid main();\n\nasync function main(): Promise<void> {\n const args = process.argv.slice(2);\n if (args[0] === '--help' || args[0] === '-h') {\n // console.log would be stripped from the built CLI, so print the usage with console.info.\n console.info(usage);\n return;\n }\n try {\n if (args[0] === 'judge' || args[0] === 'debug') {\n if (args.length < 2) {\n console.error(usage);\n process.exitCode = 1;\n return;\n }\n // Harness scripts and presets read the answer directory and params from fixed positions in\n // `process.argv`, so drop the subcommand to restore those positions.\n process.argv.splice(2, 1);\n process.exitCode = await runSingleHarness(args[0]);\n } else if (isValidateSubcommand(args[0])) {\n process.exitCode = await validateLearningMaterial(args[0], args.slice(1));\n } else {\n process.exitCode = await checkAllProblems(args);\n }\n } catch (error) {\n // Print the whole error: harness failures need their stack and `cause`, not just the message.\n console.error(error);\n process.exitCode = 1;\n }\n}\n\nfunction isValidateSubcommand(arg: string | undefined): arg is ValidateSubcommand {\n return (VALIDATE_SUBCOMMANDS as readonly string[]).includes(arg ?? '');\n}\n"],"mappings":"qNAIA,MAAMA,EAAQ;;;;;;;;;;;;;8BAgBTC,EAAK,EAEV,eAAeA,GAAsB,CACnC,IAAMC,EAAO,QAAQ,KAAK,MAAM,CAAC,EACjC,GAAIA,EAAK,KAAO,UAAYA,EAAK,KAAO,KAAM,CAE5C,QAAQ,KAAKF,CAAK,EAClB,MACF,CACA,GAAI,CACF,GAAIE,EAAK,KAAO,SAAWA,EAAK,KAAO,QAAS,CAC9C,GAAIA,EAAK,OAAS,EAAG,CACnB,QAAQ,MAAMF,CAAK,EACnB,QAAQ,SAAW,EACnB,MACF,CAGA,QAAQ,KAAK,OAAO,EAAG,CAAC,EACxB,QAAQ,SAAW,MAAMG,EAAiBD,EAAK,EAAE,CACnD,MAAWE,EAAqBF,EAAK,EAAE,EACrC,QAAQ,SAAW,MAAMG,EAAyBH,EAAK,GAAIA,EAAK,MAAM,CAAC,CAAC,EAExE,QAAQ,SAAW,MAAMI,EAAiBJ,CAAI,CAElD,OAASK,EAAO,CAEd,QAAQ,MAAMA,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF,CAEA,SAASH,EAAqB,EAAoD,CAChF,OAAQI,EAA2C,SAASC,GAAO,EAAE,CACvE"}
@@ -1 +1 @@
1
- {"version":3,"file":"runSingleHarness.cjs","names":["findDefaultStdioHarnessFiles","fs","path","child_process","readTestCases","judgesWithoutTestCases","readProblemMarkdownFrontMatter","stdioJudgePreset","stdioDebugPreset"],"sources":["../../src/cli/runSingleHarness.ts"],"sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { stdioDebugPreset, stdioJudgePreset } from '../presets/stdio.js';\n\nexport const MISSING_TEST_CASES_ERROR =\n 'a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired';\n\n/**\n * Run the judge or debug harness of the problem in the current working directory: a custom\n * `judge.ts` / `debug.ts` when present, or the default stdio preset otherwise (mirroring the\n * Exercode server, which applies the stdio presets to problems without these files).\n */\nexport async function runSingleHarness(kind: 'judge' | 'debug'): Promise<number> {\n const problemDir = process.cwd();\n\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n console.error(formatDefaultHarnessError(defaultHarnessFileNames));\n return 1;\n }\n\n const harnessFileName = kind === 'judge' ? 'judge.ts' : 'debug.ts';\n if (fs.existsSync(path.join(problemDir, harnessFileName))) {\n // process.execPath keeps the harness on the same bun executable regardless of PATH.\n const spawnResult = child_process.spawnSync(process.execPath, ['run', harnessFileName, ...process.argv.slice(2)], {\n cwd: problemDir,\n stdio: 'inherit',\n });\n if (spawnResult.error) {\n console.error(`failed to run ${harnessFileName}: ${spawnResult.error.message}`);\n return 1;\n }\n return spawnResult.status ?? 1;\n }\n\n // A custom judge.ts marks the problem as non-standard, so the stdio debug preset would judge the\n // answer against a contract the problem does not have (mirroring the server, which reports debug\n // as unsupported in this case).\n if (kind === 'debug' && fs.existsSync(path.join(problemDir, 'judge.ts'))) {\n console.error('This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.');\n return 1;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (kind === 'judge') {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0 && !judgesWithoutTestCases(await readProblemMarkdownFrontMatter(problemDir))) {\n console.error(MISSING_TEST_CASES_ERROR);\n return 1;\n }\n }\n\n // The presets read the answer directory and params from `process.argv`, which holds them at the\n // same positions as when a harness script is invoked directly.\n await (kind === 'judge' ? stdioJudgePreset(problemDir) : stdioDebugPreset(problemDir));\n return 0;\n}\n\nexport function formatDefaultHarnessError(defaultHarnessFileNames: readonly string[]): string {\n const fileNames = defaultHarnessFileNames.join(' and ');\n return `${fileNames} must not be committed because the content is identical to the default stdio harness.\nA problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,\nso delete ${fileNames} and run the problem with \\`bun x exercode-problem judge <answerDir>\\` or \\`bun x exercode-problem debug <answerDir>\\`.\nIf the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`;\n}\n"],"mappings":"ucASA,MAAa,EACX,6KAOF,eAAsB,EAAiB,EAA0C,CAC/E,IAAM,EAAa,QAAQ,IAAI,EAEzB,EAA0B,MAAMA,EAAAA,6BAA6B,CAAU,EAC7E,GAAI,EAAwB,OAAS,EAEnC,OADA,QAAQ,MAAM,EAA0B,CAAuB,CAAC,EACzD,EAGT,IAAM,EAAkB,IAAS,QAAU,WAAa,WACxD,GAAIC,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAK,EAAY,CAAe,CAAC,EAAG,CAEzD,IAAM,EAAcC,EAAAA,QAAc,UAAU,QAAQ,SAAU,CAAC,MAAO,EAAiB,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAG,CAChH,IAAK,EACL,MAAO,SACT,CAAC,EAKD,OAJI,EAAY,OACd,QAAQ,MAAM,iBAAiB,EAAgB,IAAI,EAAY,MAAM,SAAS,EACvE,GAEF,EAAY,QAAU,CAC/B,CAwBA,OAnBI,IAAS,SAAWF,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAK,EAAY,UAAU,CAAC,GACrE,QAAQ,MAAM,0FAA0F,EACjG,GAML,IAAS,UAEP,MADoBE,EAAAA,cAAcF,EAAAA,QAAK,KAAK,EAAY,YAAY,CAAC,EAAA,CAC3D,SAAW,GAAK,CAACG,EAAAA,uBAAuB,MAAMC,EAAAA,+BAA+B,CAAU,CAAC,GACpG,QAAQ,MAAM,CAAwB,EAC/B,IAMX,MAAO,IAAS,QAAUC,EAAAA,iBAAiB,CAAU,EAAIC,EAAAA,iBAAiB,CAAU,GAC7E,EACT,CAEA,SAAgB,EAA0B,EAAoD,CAC5F,IAAM,EAAY,EAAwB,KAAK,OAAO,EACtD,MAAO,GAAG,EAAU;;YAEV,EAAU;6GAEtB"}
1
+ {"version":3,"file":"runSingleHarness.cjs","names":["findDefaultStdioHarnessFiles","fs","path","child_process","readTestCases","judgesWithoutTestCases","readProblemMarkdownFrontMatter","stdioJudgePreset","stdioDebugPreset","require_runtime","require_defaultStdioHarness","require_readTestCases","require_readProblemMarkdownFrontMatter","require_stdio","node_fs","node_path","node_child_process","MISSING_TEST_CASES_ERROR","runSingleHarness","problemDir","defaultHarnessFileNames","formatDefaultHarnessError","harnessFileName","kind","spawnResult","fileNames"],"sources":["../../src/cli/runSingleHarness.ts"],"sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { stdioDebugPreset, stdioJudgePreset } from '../presets/stdio.js';\n\nexport const MISSING_TEST_CASES_ERROR =\n 'a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired';\n\n/**\n * Run the judge or debug harness of the problem in the current working directory: a custom\n * `judge.ts` / `debug.ts` when present, or the default stdio preset otherwise (mirroring the\n * Exercode server, which applies the stdio presets to problems without these files).\n */\nexport async function runSingleHarness(kind: 'judge' | 'debug'): Promise<number> {\n const problemDir = process.cwd();\n\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n console.error(formatDefaultHarnessError(defaultHarnessFileNames));\n return 1;\n }\n\n const harnessFileName = kind === 'judge' ? 'judge.ts' : 'debug.ts';\n if (fs.existsSync(path.join(problemDir, harnessFileName))) {\n // process.execPath keeps the harness on the same bun executable regardless of PATH.\n const spawnResult = child_process.spawnSync(process.execPath, ['run', harnessFileName, ...process.argv.slice(2)], {\n cwd: problemDir,\n stdio: 'inherit',\n });\n if (spawnResult.error) {\n console.error(`failed to run ${harnessFileName}: ${spawnResult.error.message}`);\n return 1;\n }\n return spawnResult.status ?? 1;\n }\n\n // A custom judge.ts marks the problem as non-standard, so the stdio debug preset would judge the\n // answer against a contract the problem does not have (mirroring the server, which reports debug\n // as unsupported in this case).\n if (kind === 'debug' && fs.existsSync(path.join(problemDir, 'judge.ts'))) {\n console.error('This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.');\n return 1;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (kind === 'judge') {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0 && !judgesWithoutTestCases(await readProblemMarkdownFrontMatter(problemDir))) {\n console.error(MISSING_TEST_CASES_ERROR);\n return 1;\n }\n }\n\n // The presets read the answer directory and params from `process.argv`, which holds them at the\n // same positions as when a harness script is invoked directly.\n await (kind === 'judge' ? stdioJudgePreset(problemDir) : stdioDebugPreset(problemDir));\n return 0;\n}\n\nexport function formatDefaultHarnessError(defaultHarnessFileNames: readonly string[]): string {\n const fileNames = defaultHarnessFileNames.join(' and ');\n return `${fileNames} must not be committed because the content is identical to the default stdio harness.\nA problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,\nso delete ${fileNames} and run the problem with \\`bun x exercode-problem judge <answerDir>\\` or \\`bun x exercode-problem debug <answerDir>\\`.\nIf the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`;\n}\n"],"mappings":"ucASA,MAAaiB,EACX,6KAOF,eAAsBC,EAAiB,EAA0C,CAC/E,IAAMC,EAAa,QAAQ,IAAI,EAEzBC,EAA0B,MAAMpB,EAAAA,6BAA6BmB,CAAU,EAC7E,GAAIC,EAAwB,OAAS,EAEnC,OADA,QAAQ,MAAMC,EAA0BD,CAAuB,CAAC,EACzD,EAGT,IAAME,EAAkBC,IAAS,QAAU,WAAa,WACxD,GAAItB,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAKiB,EAAYG,CAAe,CAAC,EAAG,CAEzD,IAAME,EAAcrB,EAAAA,QAAc,UAAU,QAAQ,SAAU,CAAC,MAAOmB,EAAiB,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAG,CAChH,IAAKH,EACL,MAAO,SACT,CAAC,EAKD,OAJIK,EAAY,OACd,QAAQ,MAAM,iBAAiBF,EAAgB,IAAIE,EAAY,MAAM,SAAS,EACvE,GAEFA,EAAY,QAAU,CAC/B,CAwBA,OAnBID,IAAS,SAAWtB,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAKiB,EAAY,UAAU,CAAC,GACrE,QAAQ,MAAM,0FAA0F,EACjG,GAMLI,IAAS,UAEP,MADoBnB,EAAAA,cAAcF,EAAAA,QAAK,KAAKiB,EAAY,YAAY,CAAC,EAAA,CAC3D,SAAW,GAAK,CAACd,EAAAA,uBAAuB,MAAMC,EAAAA,+BAA+Ba,CAAU,CAAC,GACpG,QAAQ,MAAMF,CAAwB,EAC/B,IAMX,MAAOM,IAAS,QAAUhB,EAAAA,iBAAiBY,CAAU,EAAIX,EAAAA,iBAAiBW,CAAU,GAC7E,EACT,CAEA,SAAgBE,EAA0B,EAAoD,CAC5F,IAAMI,EAAYL,EAAwB,KAAK,OAAO,EACtD,MAAO,GAAGK,EAAU;;YAEVA,EAAU;6GAEtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"runSingleHarness.js","names":["child_process"],"sources":["../../src/cli/runSingleHarness.ts"],"sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { stdioDebugPreset, stdioJudgePreset } from '../presets/stdio.js';\n\nexport const MISSING_TEST_CASES_ERROR =\n 'a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired';\n\n/**\n * Run the judge or debug harness of the problem in the current working directory: a custom\n * `judge.ts` / `debug.ts` when present, or the default stdio preset otherwise (mirroring the\n * Exercode server, which applies the stdio presets to problems without these files).\n */\nexport async function runSingleHarness(kind: 'judge' | 'debug'): Promise<number> {\n const problemDir = process.cwd();\n\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n console.error(formatDefaultHarnessError(defaultHarnessFileNames));\n return 1;\n }\n\n const harnessFileName = kind === 'judge' ? 'judge.ts' : 'debug.ts';\n if (fs.existsSync(path.join(problemDir, harnessFileName))) {\n // process.execPath keeps the harness on the same bun executable regardless of PATH.\n const spawnResult = child_process.spawnSync(process.execPath, ['run', harnessFileName, ...process.argv.slice(2)], {\n cwd: problemDir,\n stdio: 'inherit',\n });\n if (spawnResult.error) {\n console.error(`failed to run ${harnessFileName}: ${spawnResult.error.message}`);\n return 1;\n }\n return spawnResult.status ?? 1;\n }\n\n // A custom judge.ts marks the problem as non-standard, so the stdio debug preset would judge the\n // answer against a contract the problem does not have (mirroring the server, which reports debug\n // as unsupported in this case).\n if (kind === 'debug' && fs.existsSync(path.join(problemDir, 'judge.ts'))) {\n console.error('This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.');\n return 1;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (kind === 'judge') {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0 && !judgesWithoutTestCases(await readProblemMarkdownFrontMatter(problemDir))) {\n console.error(MISSING_TEST_CASES_ERROR);\n return 1;\n }\n }\n\n // The presets read the answer directory and params from `process.argv`, which holds them at the\n // same positions as when a harness script is invoked directly.\n await (kind === 'judge' ? stdioJudgePreset(problemDir) : stdioDebugPreset(problemDir));\n return 0;\n}\n\nexport function formatDefaultHarnessError(defaultHarnessFileNames: readonly string[]): string {\n const fileNames = defaultHarnessFileNames.join(' and ');\n return `${fileNames} must not be committed because the content is identical to the default stdio harness.\nA problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,\nso delete ${fileNames} and run the problem with \\`bun x exercode-problem judge <answerDir>\\` or \\`bun x exercode-problem debug <answerDir>\\`.\nIf the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`;\n}\n"],"mappings":"saASA,MAAa,EACX,6KAOF,eAAsB,EAAiB,EAA0C,CAC/E,IAAM,EAAa,QAAQ,IAAI,EAEzB,EAA0B,MAAM,EAA6B,CAAU,EAC7E,GAAI,EAAwB,OAAS,EAEnC,OADA,QAAQ,MAAM,EAA0B,CAAuB,CAAC,EACzD,EAGT,IAAM,EAAkB,IAAS,QAAU,WAAa,WACxD,GAAI,EAAG,WAAW,EAAK,KAAK,EAAY,CAAe,CAAC,EAAG,CAEzD,IAAM,EAAcA,EAAc,UAAU,QAAQ,SAAU,CAAC,MAAO,EAAiB,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAG,CAChH,IAAK,EACL,MAAO,SACT,CAAC,EAKD,OAJI,EAAY,OACd,QAAQ,MAAM,iBAAiB,EAAgB,IAAI,EAAY,MAAM,SAAS,EACvE,GAEF,EAAY,QAAU,CAC/B,CAwBA,OAnBI,IAAS,SAAW,EAAG,WAAW,EAAK,KAAK,EAAY,UAAU,CAAC,GACrE,QAAQ,MAAM,0FAA0F,EACjG,GAML,IAAS,UAEP,MADoB,EAAc,EAAK,KAAK,EAAY,YAAY,CAAC,EAAA,CAC3D,SAAW,GAAK,CAAC,EAAuB,MAAM,EAA+B,CAAU,CAAC,GACpG,QAAQ,MAAM,CAAwB,EAC/B,IAMX,MAAO,IAAS,QAAU,EAAiB,CAAU,EAAI,EAAiB,CAAU,GAC7E,EACT,CAEA,SAAgB,EAA0B,EAAoD,CAC5F,IAAM,EAAY,EAAwB,KAAK,OAAO,EACtD,MAAO,GAAG,EAAU;;YAEV,EAAU;6GAEtB"}
1
+ {"version":3,"file":"runSingleHarness.js","names":["child_process","fs","path","childProcess","MISSING_TEST_CASES_ERROR","runSingleHarness","problemDir","defaultHarnessFileNames","findDefaultStdioHarnessFiles","formatDefaultHarnessError","harnessFileName","kind","spawnResult","readTestCases","judgesWithoutTestCases","readProblemMarkdownFrontMatter","stdioJudgePreset","stdioDebugPreset","fileNames"],"sources":["../../src/cli/runSingleHarness.ts"],"sourcesContent":["import child_process from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport { findDefaultStdioHarnessFiles } from '../helpers/defaultStdioHarness.js';\nimport { judgesWithoutTestCases, readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { stdioDebugPreset, stdioJudgePreset } from '../presets/stdio.js';\n\nexport const MISSING_TEST_CASES_ERROR =\n 'a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired';\n\n/**\n * Run the judge or debug harness of the problem in the current working directory: a custom\n * `judge.ts` / `debug.ts` when present, or the default stdio preset otherwise (mirroring the\n * Exercode server, which applies the stdio presets to problems without these files).\n */\nexport async function runSingleHarness(kind: 'judge' | 'debug'): Promise<number> {\n const problemDir = process.cwd();\n\n const defaultHarnessFileNames = await findDefaultStdioHarnessFiles(problemDir);\n if (defaultHarnessFileNames.length > 0) {\n console.error(formatDefaultHarnessError(defaultHarnessFileNames));\n return 1;\n }\n\n const harnessFileName = kind === 'judge' ? 'judge.ts' : 'debug.ts';\n if (fs.existsSync(path.join(problemDir, harnessFileName))) {\n // process.execPath keeps the harness on the same bun executable regardless of PATH.\n const spawnResult = child_process.spawnSync(process.execPath, ['run', harnessFileName, ...process.argv.slice(2)], {\n cwd: problemDir,\n stdio: 'inherit',\n });\n if (spawnResult.error) {\n console.error(`failed to run ${harnessFileName}: ${spawnResult.error.message}`);\n return 1;\n }\n return spawnResult.status ?? 1;\n }\n\n // A custom judge.ts marks the problem as non-standard, so the stdio debug preset would judge the\n // answer against a contract the problem does not have (mirroring the server, which reports debug\n // as unsupported in this case).\n if (kind === 'debug' && fs.existsSync(path.join(problemDir, 'judge.ts'))) {\n console.error('This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.');\n return 1;\n }\n\n // Without test cases, stdioJudgePreset prints a single accepted sentinel result, so a standard\n // problem with an empty or missing test_cases/ would otherwise pass without being judged —\n // unless static-analysis rules or manual scoring make the problem judgeable without them.\n if (kind === 'judge') {\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n if (testCases.length === 0 && !judgesWithoutTestCases(await readProblemMarkdownFrontMatter(problemDir))) {\n console.error(MISSING_TEST_CASES_ERROR);\n return 1;\n }\n }\n\n // The presets read the answer directory and params from `process.argv`, which holds them at the\n // same positions as when a harness script is invoked directly.\n await (kind === 'judge' ? stdioJudgePreset(problemDir) : stdioDebugPreset(problemDir));\n return 0;\n}\n\nexport function formatDefaultHarnessError(defaultHarnessFileNames: readonly string[]): string {\n const fileNames = defaultHarnessFileNames.join(' and ');\n return `${fileNames} must not be committed because the content is identical to the default stdio harness.\nA problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,\nso delete ${fileNames} and run the problem with \\`bun x exercode-problem judge <answerDir>\\` or \\`bun x exercode-problem debug <answerDir>\\`.\nIf the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`;\n}\n"],"mappings":"saASA,MAAaI,EACX,6KAOF,eAAsBC,EAAiB,EAA0C,CAC/E,IAAMC,EAAa,QAAQ,IAAI,EAEzBC,EAA0B,MAAMC,EAA6BF,CAAU,EAC7E,GAAIC,EAAwB,OAAS,EAEnC,OADA,QAAQ,MAAME,EAA0BF,CAAuB,CAAC,EACzD,EAGT,IAAMG,EAAkBC,IAAS,QAAU,WAAa,WACxD,GAAIV,EAAG,WAAWC,EAAK,KAAKI,EAAYI,CAAe,CAAC,EAAG,CAEzD,IAAME,EAAcZ,EAAc,UAAU,QAAQ,SAAU,CAAC,MAAOU,EAAiB,GAAG,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAG,CAChH,IAAKJ,EACL,MAAO,SACT,CAAC,EAKD,OAJIM,EAAY,OACd,QAAQ,MAAM,iBAAiBF,EAAgB,IAAIE,EAAY,MAAM,SAAS,EACvE,GAEFA,EAAY,QAAU,CAC/B,CAwBA,OAnBID,IAAS,SAAWV,EAAG,WAAWC,EAAK,KAAKI,EAAY,UAAU,CAAC,GACrE,QAAQ,MAAM,0FAA0F,EACjG,GAMLK,IAAS,UAEP,MADoBE,EAAcX,EAAK,KAAKI,EAAY,YAAY,CAAC,EAAA,CAC3D,SAAW,GAAK,CAACQ,EAAuB,MAAMC,EAA+BT,CAAU,CAAC,GACpG,QAAQ,MAAMF,CAAwB,EAC/B,IAMX,MAAOO,IAAS,QAAUK,EAAiBV,CAAU,EAAIW,EAAiBX,CAAU,GAC7E,EACT,CAEA,SAAgBG,EAA0B,EAAoD,CAC5F,IAAMS,EAAYX,EAAwB,KAAK,OAAO,EACtD,MAAO,GAAGW,EAAU;;YAEVA,EAAU;6GAEtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateLearningMaterial.cjs","names":["formatValidationReport","validateProblemDirectory","validateCourseDirectory","validateContestFile"],"sources":["../../src/cli/validateLearningMaterial.ts"],"sourcesContent":["import { validateContestFile } from '../learningMaterial/validateContest.js';\nimport { validateCourseDirectory } from '../learningMaterial/validateCourse.js';\nimport { validateProblemDirectory } from '../learningMaterial/validateProblem.js';\nimport { formatValidationReport, type ValidationResult } from '../learningMaterial/validationResult.js';\n\nexport const VALIDATE_SUBCOMMANDS = ['validate-problem', 'validate-course', 'validate-contest'] as const;\n\nexport type ValidateSubcommand = (typeof VALIDATE_SUBCOMMANDS)[number];\n\n/**\n * Validate learning-material files without running any program and print one report per target.\n * Returns the process exit code: 1 when any target has an error (warnings alone pass).\n */\nexport async function validateLearningMaterial(\n subcommand: ValidateSubcommand,\n args: readonly string[]\n): Promise<number> {\n const { targets, problemsDir } = parseValidateArgs(args);\n if (targets.length === 0) throw new Error(`${subcommand} requires at least one path`);\n if (subcommand === 'validate-problem') {\n if (problemsDir !== undefined) throw new Error(`${subcommand} does not take --problems-dir`);\n } else if (targets.length > 1) {\n throw new Error(`${subcommand} accepts exactly one path, but got ${targets.length}`);\n }\n\n let hasError = false;\n for (const target of targets) {\n const result = await validate(subcommand, target, problemsDir);\n process.stdout.write(formatValidationReport(target, result));\n hasError ||= result.errors.length > 0;\n }\n return hasError ? 1 : 0;\n}\n\nasync function validate(\n subcommand: ValidateSubcommand,\n target: string,\n problemsDirectoryPath: string | undefined\n): Promise<ValidationResult> {\n switch (subcommand) {\n case 'validate-problem': {\n return validateProblemDirectory(target);\n }\n case 'validate-course': {\n return validateCourseDirectory(target, { problemsDirectoryPath });\n }\n case 'validate-contest': {\n return validateContestFile(target, { problemsDirectoryPath });\n }\n }\n}\n\nfunction parseValidateArgs(args: readonly string[]): { targets: string[]; problemsDir: string | undefined } {\n const targets: string[] = [];\n let problemsDir: string | undefined;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--problems-dir') {\n problemsDir = args[++index];\n if (problemsDir === undefined) throw new Error(`${arg} requires a value`);\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else {\n targets.push(arg);\n }\n }\n return { targets, problemsDir };\n}\n"],"mappings":"0SAKa,EAAuB,CAAC,mBAAoB,kBAAmB,kBAAkB,EAQ9F,eAAsB,EACpB,EACA,EACiB,CACjB,GAAM,CAAE,UAAS,eAAgB,EAAkB,CAAI,EACvD,GAAI,EAAQ,SAAW,EAAG,MAAU,MAAM,GAAG,EAAW,4BAA4B,EACpF,GAAI,IAAe,mBACb,IAAA,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAG,EAAW,8BAA8B,CAAA,MACtF,GAAI,EAAQ,OAAS,EAC1B,MAAU,MAAM,GAAG,EAAW,qCAAqC,EAAQ,QAAQ,EAGrF,IAAI,EAAW,GACf,IAAK,IAAM,KAAU,EAAS,CAC5B,IAAM,EAAS,MAAM,EAAS,EAAY,EAAQ,CAAW,EAC7D,QAAQ,OAAO,MAAMA,EAAAA,uBAAuB,EAAQ,CAAM,CAAC,EAC3D,IAAa,EAAO,OAAO,OAAS,CACtC,CACA,MAAO,IACT,CAEA,eAAe,EACb,EACA,EACA,EAC2B,CAC3B,OAAQ,EAAR,CACE,IAAK,mBACH,OAAOC,EAAAA,yBAAyB,CAAM,EAExC,IAAK,kBACH,OAAOC,EAAAA,wBAAwB,EAAQ,CAAE,uBAAsB,CAAC,EAElE,IAAK,mBACH,OAAOC,EAAAA,oBAAoB,EAAQ,CAAE,uBAAsB,CAAC,CAEhE,CACF,CAEA,SAAS,EAAkB,EAAiF,CAC1G,IAAM,EAAoB,CAAC,EACvB,EACJ,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAK,OAAQ,IAAS,CAChD,IAAM,EAAM,EAAK,GACjB,GAAI,IAAQ,IAAA,GAAW,MACvB,GAAI,IAAQ,iBAEV,IADA,EAAc,EAAK,EAAE,GACjB,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAG,EAAI,kBAAkB,CAAA,MACnE,GAAI,EAAI,WAAW,IAAI,EAC5B,MAAU,MAAM,mBAAmB,GAAK,OAExC,EAAQ,KAAK,CAAG,CAEpB,CACA,MAAO,CAAE,UAAS,aAAY,CAChC"}
1
+ {"version":3,"file":"validateLearningMaterial.cjs","names":["formatValidationReport","validateProblemDirectory","validateCourseDirectory","validateContestFile","require_validationResult","require_validateContest","require_validateCourse","require_validateProblem","VALIDATE_SUBCOMMANDS","validateLearningMaterial","parseValidateArgs","args","targets","subcommand","problemsDir","hasError","target","result","validate","index","arg"],"sources":["../../src/cli/validateLearningMaterial.ts"],"sourcesContent":["import { validateContestFile } from '../learningMaterial/validateContest.js';\nimport { validateCourseDirectory } from '../learningMaterial/validateCourse.js';\nimport { validateProblemDirectory } from '../learningMaterial/validateProblem.js';\nimport { formatValidationReport, type ValidationResult } from '../learningMaterial/validationResult.js';\n\nexport const VALIDATE_SUBCOMMANDS = ['validate-problem', 'validate-course', 'validate-contest'] as const;\n\nexport type ValidateSubcommand = (typeof VALIDATE_SUBCOMMANDS)[number];\n\n/**\n * Validate learning-material files without running any program and print one report per target.\n * Returns the process exit code: 1 when any target has an error (warnings alone pass).\n */\nexport async function validateLearningMaterial(\n subcommand: ValidateSubcommand,\n args: readonly string[]\n): Promise<number> {\n const { targets, problemsDir } = parseValidateArgs(args);\n if (targets.length === 0) throw new Error(`${subcommand} requires at least one path`);\n if (subcommand === 'validate-problem') {\n if (problemsDir !== undefined) throw new Error(`${subcommand} does not take --problems-dir`);\n } else if (targets.length > 1) {\n throw new Error(`${subcommand} accepts exactly one path, but got ${targets.length}`);\n }\n\n let hasError = false;\n for (const target of targets) {\n const result = await validate(subcommand, target, problemsDir);\n process.stdout.write(formatValidationReport(target, result));\n hasError ||= result.errors.length > 0;\n }\n return hasError ? 1 : 0;\n}\n\nasync function validate(\n subcommand: ValidateSubcommand,\n target: string,\n problemsDirectoryPath: string | undefined\n): Promise<ValidationResult> {\n switch (subcommand) {\n case 'validate-problem': {\n return validateProblemDirectory(target);\n }\n case 'validate-course': {\n return validateCourseDirectory(target, { problemsDirectoryPath });\n }\n case 'validate-contest': {\n return validateContestFile(target, { problemsDirectoryPath });\n }\n }\n}\n\nfunction parseValidateArgs(args: readonly string[]): { targets: string[]; problemsDir: string | undefined } {\n const targets: string[] = [];\n let problemsDir: string | undefined;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--problems-dir') {\n problemsDir = args[++index];\n if (problemsDir === undefined) throw new Error(`${arg} requires a value`);\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else {\n targets.push(arg);\n }\n }\n return { targets, problemsDir };\n}\n"],"mappings":"0SAKaQ,EAAuB,CAAC,mBAAoB,kBAAmB,kBAAkB,EAQ9F,eAAsBC,EACpB,EACA,EACiB,CACjB,GAAM,CAAE,UAAS,eAAgBC,EAAkBC,CAAI,EACvD,GAAIC,EAAQ,SAAW,EAAG,MAAU,MAAM,GAAGC,EAAW,4BAA4B,EACpF,GAAIA,IAAe,mBACb,IAAAC,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAGD,EAAW,8BAA8B,CAAA,MACtF,GAAID,EAAQ,OAAS,EAC1B,MAAU,MAAM,GAAGC,EAAW,qCAAqCD,EAAQ,QAAQ,EAGrF,IAAIG,EAAW,GACf,IAAK,IAAMC,KAAUJ,EAAS,CAC5B,IAAMK,EAAS,MAAMC,EAASL,EAAYG,EAAQF,CAAW,EAC7D,QAAQ,OAAO,MAAMd,EAAAA,uBAAuBgB,EAAQC,CAAM,CAAC,EAC3D,IAAaA,EAAO,OAAO,OAAS,CACtC,CACA,MAAO,IACT,CAEA,eAAeC,EACb,EACA,EACA,EAC2B,CAC3B,OAAQL,EAAR,CACE,IAAK,mBACH,OAAOZ,EAAAA,yBAAyBe,CAAM,EAExC,IAAK,kBACH,OAAOd,EAAAA,wBAAwBc,EAAQ,CAAE,uBAAsB,CAAC,EAElE,IAAK,mBACH,OAAOb,EAAAA,oBAAoBa,EAAQ,CAAE,uBAAsB,CAAC,CAEhE,CACF,CAEA,SAASN,EAAkB,EAAiF,CAC1G,IAAME,EAAoB,CAAC,EACvBE,EACJ,IAAK,IAAIK,EAAQ,EAAGA,EAAQR,EAAK,OAAQ,IAAS,CAChD,IAAMS,EAAMT,EAAKQ,GACjB,GAAIC,IAAQ,IAAA,GAAW,MACvB,GAAIA,IAAQ,iBAEV,IADA,EAAcT,EAAK,EAAEQ,GACjBL,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAGM,EAAI,kBAAkB,CAAA,MACnE,GAAIA,EAAI,WAAW,IAAI,EAC5B,MAAU,MAAM,mBAAmBA,GAAK,OAExCR,EAAQ,KAAKQ,CAAG,CAEpB,CACA,MAAO,CAAE,UAAS,aAAY,CAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"validateLearningMaterial.js","names":[],"sources":["../../src/cli/validateLearningMaterial.ts"],"sourcesContent":["import { validateContestFile } from '../learningMaterial/validateContest.js';\nimport { validateCourseDirectory } from '../learningMaterial/validateCourse.js';\nimport { validateProblemDirectory } from '../learningMaterial/validateProblem.js';\nimport { formatValidationReport, type ValidationResult } from '../learningMaterial/validationResult.js';\n\nexport const VALIDATE_SUBCOMMANDS = ['validate-problem', 'validate-course', 'validate-contest'] as const;\n\nexport type ValidateSubcommand = (typeof VALIDATE_SUBCOMMANDS)[number];\n\n/**\n * Validate learning-material files without running any program and print one report per target.\n * Returns the process exit code: 1 when any target has an error (warnings alone pass).\n */\nexport async function validateLearningMaterial(\n subcommand: ValidateSubcommand,\n args: readonly string[]\n): Promise<number> {\n const { targets, problemsDir } = parseValidateArgs(args);\n if (targets.length === 0) throw new Error(`${subcommand} requires at least one path`);\n if (subcommand === 'validate-problem') {\n if (problemsDir !== undefined) throw new Error(`${subcommand} does not take --problems-dir`);\n } else if (targets.length > 1) {\n throw new Error(`${subcommand} accepts exactly one path, but got ${targets.length}`);\n }\n\n let hasError = false;\n for (const target of targets) {\n const result = await validate(subcommand, target, problemsDir);\n process.stdout.write(formatValidationReport(target, result));\n hasError ||= result.errors.length > 0;\n }\n return hasError ? 1 : 0;\n}\n\nasync function validate(\n subcommand: ValidateSubcommand,\n target: string,\n problemsDirectoryPath: string | undefined\n): Promise<ValidationResult> {\n switch (subcommand) {\n case 'validate-problem': {\n return validateProblemDirectory(target);\n }\n case 'validate-course': {\n return validateCourseDirectory(target, { problemsDirectoryPath });\n }\n case 'validate-contest': {\n return validateContestFile(target, { problemsDirectoryPath });\n }\n }\n}\n\nfunction parseValidateArgs(args: readonly string[]): { targets: string[]; problemsDir: string | undefined } {\n const targets: string[] = [];\n let problemsDir: string | undefined;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--problems-dir') {\n problemsDir = args[++index];\n if (problemsDir === undefined) throw new Error(`${arg} requires a value`);\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else {\n targets.push(arg);\n }\n }\n return { targets, problemsDir };\n}\n"],"mappings":"gUAKA,MAAa,EAAuB,CAAC,mBAAoB,kBAAmB,kBAAkB,EAQ9F,eAAsB,EACpB,EACA,EACiB,CACjB,GAAM,CAAE,UAAS,eAAgB,EAAkB,CAAI,EACvD,GAAI,EAAQ,SAAW,EAAG,MAAU,MAAM,GAAG,EAAW,4BAA4B,EACpF,GAAI,IAAe,mBACb,IAAA,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAG,EAAW,8BAA8B,CAAA,MACtF,GAAI,EAAQ,OAAS,EAC1B,MAAU,MAAM,GAAG,EAAW,qCAAqC,EAAQ,QAAQ,EAGrF,IAAI,EAAW,GACf,IAAK,IAAM,KAAU,EAAS,CAC5B,IAAM,EAAS,MAAM,EAAS,EAAY,EAAQ,CAAW,EAC7D,QAAQ,OAAO,MAAM,EAAuB,EAAQ,CAAM,CAAC,EAC3D,IAAa,EAAO,OAAO,OAAS,CACtC,CACA,MAAO,IACT,CAEA,eAAe,EACb,EACA,EACA,EAC2B,CAC3B,OAAQ,EAAR,CACE,IAAK,mBACH,OAAO,EAAyB,CAAM,EAExC,IAAK,kBACH,OAAO,EAAwB,EAAQ,CAAE,uBAAsB,CAAC,EAElE,IAAK,mBACH,OAAO,EAAoB,EAAQ,CAAE,uBAAsB,CAAC,CAEhE,CACF,CAEA,SAAS,EAAkB,EAAiF,CAC1G,IAAM,EAAoB,CAAC,EACvB,EACJ,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAK,OAAQ,IAAS,CAChD,IAAM,EAAM,EAAK,GACjB,GAAI,IAAQ,IAAA,GAAW,MACvB,GAAI,IAAQ,iBAEV,IADA,EAAc,EAAK,EAAE,GACjB,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAG,EAAI,kBAAkB,CAAA,MACnE,GAAI,EAAI,WAAW,IAAI,EAC5B,MAAU,MAAM,mBAAmB,GAAK,OAExC,EAAQ,KAAK,CAAG,CAEpB,CACA,MAAO,CAAE,UAAS,aAAY,CAChC"}
1
+ {"version":3,"file":"validateLearningMaterial.js","names":["VALIDATE_SUBCOMMANDS","validateLearningMaterial","parseValidateArgs","args","targets","subcommand","problemsDir","hasError","target","result","validate","formatValidationReport","validateProblemDirectory","validateCourseDirectory","validateContestFile","index","arg"],"sources":["../../src/cli/validateLearningMaterial.ts"],"sourcesContent":["import { validateContestFile } from '../learningMaterial/validateContest.js';\nimport { validateCourseDirectory } from '../learningMaterial/validateCourse.js';\nimport { validateProblemDirectory } from '../learningMaterial/validateProblem.js';\nimport { formatValidationReport, type ValidationResult } from '../learningMaterial/validationResult.js';\n\nexport const VALIDATE_SUBCOMMANDS = ['validate-problem', 'validate-course', 'validate-contest'] as const;\n\nexport type ValidateSubcommand = (typeof VALIDATE_SUBCOMMANDS)[number];\n\n/**\n * Validate learning-material files without running any program and print one report per target.\n * Returns the process exit code: 1 when any target has an error (warnings alone pass).\n */\nexport async function validateLearningMaterial(\n subcommand: ValidateSubcommand,\n args: readonly string[]\n): Promise<number> {\n const { targets, problemsDir } = parseValidateArgs(args);\n if (targets.length === 0) throw new Error(`${subcommand} requires at least one path`);\n if (subcommand === 'validate-problem') {\n if (problemsDir !== undefined) throw new Error(`${subcommand} does not take --problems-dir`);\n } else if (targets.length > 1) {\n throw new Error(`${subcommand} accepts exactly one path, but got ${targets.length}`);\n }\n\n let hasError = false;\n for (const target of targets) {\n const result = await validate(subcommand, target, problemsDir);\n process.stdout.write(formatValidationReport(target, result));\n hasError ||= result.errors.length > 0;\n }\n return hasError ? 1 : 0;\n}\n\nasync function validate(\n subcommand: ValidateSubcommand,\n target: string,\n problemsDirectoryPath: string | undefined\n): Promise<ValidationResult> {\n switch (subcommand) {\n case 'validate-problem': {\n return validateProblemDirectory(target);\n }\n case 'validate-course': {\n return validateCourseDirectory(target, { problemsDirectoryPath });\n }\n case 'validate-contest': {\n return validateContestFile(target, { problemsDirectoryPath });\n }\n }\n}\n\nfunction parseValidateArgs(args: readonly string[]): { targets: string[]; problemsDir: string | undefined } {\n const targets: string[] = [];\n let problemsDir: string | undefined;\n for (let index = 0; index < args.length; index++) {\n const arg = args[index];\n if (arg === undefined) break;\n if (arg === '--problems-dir') {\n problemsDir = args[++index];\n if (problemsDir === undefined) throw new Error(`${arg} requires a value`);\n } else if (arg.startsWith('--')) {\n throw new Error(`Unknown option: ${arg}`);\n } else {\n targets.push(arg);\n }\n }\n return { targets, problemsDir };\n}\n"],"mappings":"gUAKA,MAAaA,EAAuB,CAAC,mBAAoB,kBAAmB,kBAAkB,EAQ9F,eAAsBC,EACpB,EACA,EACiB,CACjB,GAAM,CAAE,UAAS,eAAgBC,EAAkBC,CAAI,EACvD,GAAIC,EAAQ,SAAW,EAAG,MAAU,MAAM,GAAGC,EAAW,4BAA4B,EACpF,GAAIA,IAAe,mBACb,IAAAC,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAGD,EAAW,8BAA8B,CAAA,MACtF,GAAID,EAAQ,OAAS,EAC1B,MAAU,MAAM,GAAGC,EAAW,qCAAqCD,EAAQ,QAAQ,EAGrF,IAAIG,EAAW,GACf,IAAK,IAAMC,KAAUJ,EAAS,CAC5B,IAAMK,EAAS,MAAMC,EAASL,EAAYG,EAAQF,CAAW,EAC7D,QAAQ,OAAO,MAAMK,EAAuBH,EAAQC,CAAM,CAAC,EAC3D,IAAaA,EAAO,OAAO,OAAS,CACtC,CACA,MAAO,IACT,CAEA,eAAeC,EACb,EACA,EACA,EAC2B,CAC3B,OAAQL,EAAR,CACE,IAAK,mBACH,OAAOO,EAAyBJ,CAAM,EAExC,IAAK,kBACH,OAAOK,EAAwBL,EAAQ,CAAE,uBAAsB,CAAC,EAElE,IAAK,mBACH,OAAOM,EAAoBN,EAAQ,CAAE,uBAAsB,CAAC,CAEhE,CACF,CAEA,SAASN,EAAkB,EAAiF,CAC1G,IAAME,EAAoB,CAAC,EACvBE,EACJ,IAAK,IAAIS,EAAQ,EAAGA,EAAQZ,EAAK,OAAQ,IAAS,CAChD,IAAMa,EAAMb,EAAKY,GACjB,GAAIC,IAAQ,IAAA,GAAW,MACvB,GAAIA,IAAQ,iBAEV,IADA,EAAcb,EAAK,EAAEY,GACjBT,IAAgB,IAAA,GAAW,MAAU,MAAM,GAAGU,EAAI,kBAAkB,CAAA,MACnE,GAAIA,EAAI,WAAW,IAAI,EAC5B,MAAU,MAAM,mBAAmBA,GAAK,OAExCZ,EAAQ,KAAKY,CAAG,CAEpB,CACA,MAAO,CAAE,UAAS,aAAY,CAChC"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkProblemDirIsolation.cjs","names":["copyProblemDirToTemporaryRoot","path","isRecord","runHarnessProcess","getErrorMessage","forciblyRemoveDirectory","TEST_CASE_RESULT_PREFIX","testCaseResultSchema","DecisionCode"],"sources":["../../src/helpers/checkProblemDirIsolation.ts"],"sourcesContent":["import path from 'node:path';\nimport { getErrorMessage, isRecord } from '@willbooster/shared-lib';\n\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { printDebugBanner } from './printDebugBanner.js';\nimport type { ResolvedCwd } from './resolveCwds.js';\nimport { type HarnessProcessResult, runHarnessProcess } from './runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from './temporaryProblemDirCopy.js';\n\nconst ISOLATION_CHECK_MIN_TIMEOUT_MS = 30_000;\n// Starting bun and printing results are not covered by the judge's own limits.\nconst ISOLATION_CHECK_OVERHEAD_MS = 10_000;\nconst ISOLATION_CHECK_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;\n\nexport interface ProblemDirIsolationCheckOptions {\n /**\n * The judge's declared worst-case duration for one accepted submission (build timeout plus the\n * time limit of every test case). The check allows at least that plus a fixed overhead; per-case\n * process startup and custom judge callbacks are not budgeted separately.\n */\n expectedMaxDurationMs?: number;\n}\n\nexport interface ProblemDirIsolationCheckResult {\n passed: boolean;\n}\n\n/**\n * Check that a judge can run after only the problem directory is copied elsewhere.\n */\nexport async function checkProblemDirIsolation(\n problemDir: string,\n resolvedCwd: ResolvedCwd,\n params: unknown,\n options: ProblemDirIsolationCheckOptions = {}\n): Promise<ProblemDirIsolationCheckResult> {\n const timeoutMs = Math.max(\n ISOLATION_CHECK_MIN_TIMEOUT_MS,\n (options.expectedMaxDurationMs ?? 0) + ISOLATION_CHECK_OVERHEAD_MS\n );\n let tempRoot: string | undefined;\n try {\n const copyResult = await copyProblemDirToTemporaryRoot(problemDir);\n tempRoot = copyResult.tempRoot;\n const { copiedProblemDir } = copyResult;\n const absoluteProblemDir = path.resolve(problemDir);\n\n const relativeCwd = path.relative(absoluteProblemDir, path.resolve(resolvedCwd.cwd));\n const copiedCwd = path.join(copiedProblemDir, relativeCwd);\n const scriptPath = getInvokedScriptPath(absoluteProblemDir);\n if (scriptPath.startsWith('..') || path.isAbsolute(scriptPath)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check skipped',\n '',\n 'The invoked judge script is located outside the problem directory.',\n `Script path: ${scriptPath}`,\n ]);\n return { passed: true };\n }\n const execArgv = process.execArgv.filter(isIsolationExecArg);\n const paramsJson = JSON.stringify(isRecord(params) ? params : {});\n const result = await runHarnessProcess([...execArgv, scriptPath, copiedCwd, paramsJson], {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs,\n maxOutputBytes: ISOLATION_CHECK_MAX_OUTPUT_BYTES,\n tempRoot,\n });\n\n if (result.exitCode === 0 && isAcceptedJudgeOutput(result.stdout)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check passed',\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n ]);\n return { passed: true };\n }\n\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed',\n '',\n ...describeFailure(result, timeoutMs, options),\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n `Exit status : ${result.exitCode ?? result.signal ?? 'unknown'}`,\n `Failure reason : ${result.failureReason ?? '<none>'}`,\n '',\n 'stdout:',\n result.stdout.trimEnd() || '<empty>',\n '',\n 'stderr:',\n result.stderr.trimEnd() || '<empty>',\n ]);\n return { passed: false };\n } catch (error) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed due to an unexpected error',\n '',\n getErrorMessage(error),\n ]);\n return { passed: false };\n } finally {\n // Cleanup failures must not mask the primary isolation check result.\n if (tempRoot) await forciblyRemoveDirectory(tempRoot);\n }\n}\n\nfunction describeFailure(\n result: HarnessProcessResult,\n timeoutMs: number,\n options: ProblemDirIsolationCheckOptions\n): string[] {\n if (result.timedOut) {\n return [\n `The judge did not finish within ${timeoutMs / 1000} seconds after copying only the problem directory to a temporary location.`,\n ...(options.expectedMaxDurationMs === undefined\n ? [\n `This judge declares no run time, so the check uses its fixed ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000}-second budget.`,\n ]\n : [\n `The budget is the larger of ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000} seconds and the build timeout plus the time limit of every test case plus a ${ISOLATION_CHECK_OVERHEAD_MS / 1000}-second overhead.`,\n 'Check timeLimitMs, the number of test cases, and one-off startup costs such as cold caches.',\n ]),\n ];\n }\n if (result.failureReason !== undefined) {\n return ['The judge was stopped before it finished; see the failure reason below.'];\n }\n if (result.exitCode === undefined) {\n return [\n `The judge was terminated by ${result.signal ?? 'an unknown signal'} (e.g. an out-of-memory kill or a cancelled job).`,\n ];\n }\n return [\n 'The judge did not complete successfully after copying only the problem directory to a temporary location.',\n 'Make sure judge.ts imports only files included in the problem directory.',\n ];\n}\n\nfunction isIsolationExecArg(arg: string): boolean {\n return !arg.startsWith('--inspect') && !arg.startsWith('--watch') && !arg.startsWith('--hot');\n}\n\nfunction getInvokedScriptPath(problemDir: string): string {\n const scriptPath = process.argv[1];\n if (!scriptPath) return `.${path.sep}judge.ts`;\n const relativeScriptPath = path.relative(problemDir, path.resolve(scriptPath));\n if (path.isAbsolute(relativeScriptPath)) return relativeScriptPath;\n return relativeScriptPath.startsWith('.') ? relativeScriptPath : `.${path.sep}${relativeScriptPath}`;\n}\n\nfunction isAcceptedJudgeOutput(stdout: string): boolean {\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n if (resultLines.length === 0) return false;\n\n return resultLines.every((line) => {\n try {\n const parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n return parsedResult.success && parsedResult.data.decisionCode === DecisionCode.ACCEPTED;\n } catch {\n return false;\n }\n });\n}\n"],"mappings":"2VAWA,MAAM,EAAiC,IAEjC,EAA8B,IAmBpC,eAAsB,EACpB,EACA,EACA,EACA,EAA2C,CAAC,EACH,CACzC,IAAM,EAAY,KAAK,IACrB,GACC,EAAQ,uBAAyB,GAAK,CACzC,EACI,EACJ,GAAI,CACF,IAAM,EAAa,MAAMA,EAAAA,8BAA8B,CAAU,EACjE,EAAW,EAAW,SACtB,GAAM,CAAE,oBAAqB,EACvB,EAAqBC,EAAAA,QAAK,QAAQ,CAAU,EAE5C,EAAcA,EAAAA,QAAK,SAAS,EAAoBA,EAAAA,QAAK,QAAQ,EAAY,GAAG,CAAC,EAC7E,EAAYA,EAAAA,QAAK,KAAK,EAAkB,CAAW,EACnD,EAAa,EAAqB,CAAkB,EAC1D,GAAI,EAAW,WAAW,IAAI,GAAKA,EAAAA,QAAK,WAAW,CAAU,EAO3D,OANA,EAAA,iBAAiB,CACf,wDACA,GACA,qEACA,gBAAgB,GAClB,CAAC,EACM,CAAE,OAAQ,EAAK,EAExB,IAAM,EAAW,QAAQ,SAAS,OAAO,CAAkB,EACrD,EAAa,KAAK,WAAA,EAAUC,EAAAA,SAAAA,CAAS,CAAM,EAAI,EAAS,CAAC,CAAC,EAC1D,EAAS,MAAMC,EAAAA,kBAAkB,CAAC,GAAG,EAAU,EAAY,EAAW,CAAU,EAAG,CACvF,IAAK,EACL,IAAK,QAAQ,IACb,YACA,eAAgB,SAChB,UACF,CAAC,EA4BD,OA1BI,EAAO,WAAa,GAAK,EAAsB,EAAO,MAAM,GAC9D,EAAA,iBAAiB,CACf,uDACA,GACA,wBAAwB,IACx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CAAC,EAE7E,OADIA,EAAAA,QAAK,WAAW,CAAkB,GAC/B,EAAmB,WAAW,GAAG,EADQ,EACiB,IAAIA,EAAAA,QAAK,MAAM,GAClF,CAEA,SAAS,EAAsB,EAAyB,CACtD,IAAM,EAAc,EAAO,MAAM,OAAO,CAAC,CAAC,OAAQ,GAAS,EAAK,WAAWK,EAAAA,uBAAuB,CAAC,EAGnG,OAFI,EAAY,SAAW,GAEpB,EAAY,MAAO,GAAS,CACjC,GAAI,CACF,IAAM,EAAeC,EAAAA,qBAAqB,UAAU,KAAK,MAAM,EAAK,MAAMD,EAAAA,wBAAwB,MAAM,CAAC,CAAC,EAC1G,OAAO,EAAa,SAAW,EAAa,KAAK,eAAiBE,EAAAA,aAAa,QACjF,MAAQ,CACN,MAAO,EACT,CACF,CAAC,CACH"}
1
+ {"version":3,"file":"checkProblemDirIsolation.cjs","names":["copyProblemDirToTemporaryRoot","path","isRecord","runHarnessProcess","getErrorMessage","forciblyRemoveDirectory","TEST_CASE_RESULT_PREFIX","testCaseResultSchema","DecisionCode","require_runtime","require_testCaseResult","require_temporaryProblemDirCopy","require_decisionCode","require_printDebugBanner","require_runHarnessProcess","node_path","_willbooster_shared_lib","ISOLATION_CHECK_MIN_TIMEOUT_MS","ISOLATION_CHECK_OVERHEAD_MS","checkProblemDirIsolation","timeoutMs","options","tempRoot","copyResult","problemDir","absoluteProblemDir","relativeCwd","resolvedCwd","copiedCwd","copiedProblemDir","scriptPath","getInvokedScriptPath","execArgv","isIsolationExecArg","paramsJson","params","result","isAcceptedJudgeOutput","describeFailure","error","arg","relativeScriptPath","resultLines","stdout","line","parsedResult"],"sources":["../../src/helpers/checkProblemDirIsolation.ts"],"sourcesContent":["import path from 'node:path';\nimport { getErrorMessage, isRecord } from '@willbooster/shared-lib';\n\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { printDebugBanner } from './printDebugBanner.js';\nimport type { ResolvedCwd } from './resolveCwds.js';\nimport { type HarnessProcessResult, runHarnessProcess } from './runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from './temporaryProblemDirCopy.js';\n\nconst ISOLATION_CHECK_MIN_TIMEOUT_MS = 30_000;\n// Starting bun and printing results are not covered by the judge's own limits.\nconst ISOLATION_CHECK_OVERHEAD_MS = 10_000;\nconst ISOLATION_CHECK_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;\n\nexport interface ProblemDirIsolationCheckOptions {\n /**\n * The judge's declared worst-case duration for one accepted submission (build timeout plus the\n * time limit of every test case). The check allows at least that plus a fixed overhead; per-case\n * process startup and custom judge callbacks are not budgeted separately.\n */\n expectedMaxDurationMs?: number;\n}\n\nexport interface ProblemDirIsolationCheckResult {\n passed: boolean;\n}\n\n/**\n * Check that a judge can run after only the problem directory is copied elsewhere.\n */\nexport async function checkProblemDirIsolation(\n problemDir: string,\n resolvedCwd: ResolvedCwd,\n params: unknown,\n options: ProblemDirIsolationCheckOptions = {}\n): Promise<ProblemDirIsolationCheckResult> {\n const timeoutMs = Math.max(\n ISOLATION_CHECK_MIN_TIMEOUT_MS,\n (options.expectedMaxDurationMs ?? 0) + ISOLATION_CHECK_OVERHEAD_MS\n );\n let tempRoot: string | undefined;\n try {\n const copyResult = await copyProblemDirToTemporaryRoot(problemDir);\n tempRoot = copyResult.tempRoot;\n const { copiedProblemDir } = copyResult;\n const absoluteProblemDir = path.resolve(problemDir);\n\n const relativeCwd = path.relative(absoluteProblemDir, path.resolve(resolvedCwd.cwd));\n const copiedCwd = path.join(copiedProblemDir, relativeCwd);\n const scriptPath = getInvokedScriptPath(absoluteProblemDir);\n if (scriptPath.startsWith('..') || path.isAbsolute(scriptPath)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check skipped',\n '',\n 'The invoked judge script is located outside the problem directory.',\n `Script path: ${scriptPath}`,\n ]);\n return { passed: true };\n }\n const execArgv = process.execArgv.filter(isIsolationExecArg);\n const paramsJson = JSON.stringify(isRecord(params) ? params : {});\n const result = await runHarnessProcess([...execArgv, scriptPath, copiedCwd, paramsJson], {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs,\n maxOutputBytes: ISOLATION_CHECK_MAX_OUTPUT_BYTES,\n tempRoot,\n });\n\n if (result.exitCode === 0 && isAcceptedJudgeOutput(result.stdout)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check passed',\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n ]);\n return { passed: true };\n }\n\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed',\n '',\n ...describeFailure(result, timeoutMs, options),\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n `Exit status : ${result.exitCode ?? result.signal ?? 'unknown'}`,\n `Failure reason : ${result.failureReason ?? '<none>'}`,\n '',\n 'stdout:',\n result.stdout.trimEnd() || '<empty>',\n '',\n 'stderr:',\n result.stderr.trimEnd() || '<empty>',\n ]);\n return { passed: false };\n } catch (error) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed due to an unexpected error',\n '',\n getErrorMessage(error),\n ]);\n return { passed: false };\n } finally {\n // Cleanup failures must not mask the primary isolation check result.\n if (tempRoot) await forciblyRemoveDirectory(tempRoot);\n }\n}\n\nfunction describeFailure(\n result: HarnessProcessResult,\n timeoutMs: number,\n options: ProblemDirIsolationCheckOptions\n): string[] {\n if (result.timedOut) {\n return [\n `The judge did not finish within ${timeoutMs / 1000} seconds after copying only the problem directory to a temporary location.`,\n ...(options.expectedMaxDurationMs === undefined\n ? [\n `This judge declares no run time, so the check uses its fixed ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000}-second budget.`,\n ]\n : [\n `The budget is the larger of ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000} seconds and the build timeout plus the time limit of every test case plus a ${ISOLATION_CHECK_OVERHEAD_MS / 1000}-second overhead.`,\n 'Check timeLimitMs, the number of test cases, and one-off startup costs such as cold caches.',\n ]),\n ];\n }\n if (result.failureReason !== undefined) {\n return ['The judge was stopped before it finished; see the failure reason below.'];\n }\n if (result.exitCode === undefined) {\n return [\n `The judge was terminated by ${result.signal ?? 'an unknown signal'} (e.g. an out-of-memory kill or a cancelled job).`,\n ];\n }\n return [\n 'The judge did not complete successfully after copying only the problem directory to a temporary location.',\n 'Make sure judge.ts imports only files included in the problem directory.',\n ];\n}\n\nfunction isIsolationExecArg(arg: string): boolean {\n return !arg.startsWith('--inspect') && !arg.startsWith('--watch') && !arg.startsWith('--hot');\n}\n\nfunction getInvokedScriptPath(problemDir: string): string {\n const scriptPath = process.argv[1];\n if (!scriptPath) return `.${path.sep}judge.ts`;\n const relativeScriptPath = path.relative(problemDir, path.resolve(scriptPath));\n if (path.isAbsolute(relativeScriptPath)) return relativeScriptPath;\n return relativeScriptPath.startsWith('.') ? relativeScriptPath : `.${path.sep}${relativeScriptPath}`;\n}\n\nfunction isAcceptedJudgeOutput(stdout: string): boolean {\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n if (resultLines.length === 0) return false;\n\n return resultLines.every((line) => {\n try {\n const parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n return parsedResult.success && parsedResult.data.decisionCode === DecisionCode.ACCEPTED;\n } catch {\n return false;\n }\n });\n}\n"],"mappings":"2VAWA,MAAMiB,EAAiC,IAEjCC,EAA8B,IAmBpC,eAAsBC,EACpB,EACA,EACA,EACA,EAA2C,CAAC,EACH,CACzC,IAAMC,EAAY,KAAK,IACrBH,GACCI,EAAQ,uBAAyB,GAAKH,CACzC,EACII,EACJ,GAAI,CACF,IAAMC,EAAa,MAAMvB,EAAAA,8BAA8BwB,CAAU,EACjE,EAAWD,EAAW,SACtB,GAAM,CAAE,oBAAqBA,EACvBE,EAAqBxB,EAAAA,QAAK,QAAQuB,C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AWA,EAAa,KAAK,eAAiBrC,EAAAA,aAAa,QACjF,MAAQ,CACN,MAAO,EACT,CACF,CAAC,CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkProblemDirIsolation.js","names":[],"sources":["../../src/helpers/checkProblemDirIsolation.ts"],"sourcesContent":["import path from 'node:path';\nimport { getErrorMessage, isRecord } from '@willbooster/shared-lib';\n\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { printDebugBanner } from './printDebugBanner.js';\nimport type { ResolvedCwd } from './resolveCwds.js';\nimport { type HarnessProcessResult, runHarnessProcess } from './runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from './temporaryProblemDirCopy.js';\n\nconst ISOLATION_CHECK_MIN_TIMEOUT_MS = 30_000;\n// Starting bun and printing results are not covered by the judge's own limits.\nconst ISOLATION_CHECK_OVERHEAD_MS = 10_000;\nconst ISOLATION_CHECK_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;\n\nexport interface ProblemDirIsolationCheckOptions {\n /**\n * The judge's declared worst-case duration for one accepted submission (build timeout plus the\n * time limit of every test case). The check allows at least that plus a fixed overhead; per-case\n * process startup and custom judge callbacks are not budgeted separately.\n */\n expectedMaxDurationMs?: number;\n}\n\nexport interface ProblemDirIsolationCheckResult {\n passed: boolean;\n}\n\n/**\n * Check that a judge can run after only the problem directory is copied elsewhere.\n */\nexport async function checkProblemDirIsolation(\n problemDir: string,\n resolvedCwd: ResolvedCwd,\n params: unknown,\n options: ProblemDirIsolationCheckOptions = {}\n): Promise<ProblemDirIsolationCheckResult> {\n const timeoutMs = Math.max(\n ISOLATION_CHECK_MIN_TIMEOUT_MS,\n (options.expectedMaxDurationMs ?? 0) + ISOLATION_CHECK_OVERHEAD_MS\n );\n let tempRoot: string | undefined;\n try {\n const copyResult = await copyProblemDirToTemporaryRoot(problemDir);\n tempRoot = copyResult.tempRoot;\n const { copiedProblemDir } = copyResult;\n const absoluteProblemDir = path.resolve(problemDir);\n\n const relativeCwd = path.relative(absoluteProblemDir, path.resolve(resolvedCwd.cwd));\n const copiedCwd = path.join(copiedProblemDir, relativeCwd);\n const scriptPath = getInvokedScriptPath(absoluteProblemDir);\n if (scriptPath.startsWith('..') || path.isAbsolute(scriptPath)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check skipped',\n '',\n 'The invoked judge script is located outside the problem directory.',\n `Script path: ${scriptPath}`,\n ]);\n return { passed: true };\n }\n const execArgv = process.execArgv.filter(isIsolationExecArg);\n const paramsJson = JSON.stringify(isRecord(params) ? params : {});\n const result = await runHarnessProcess([...execArgv, scriptPath, copiedCwd, paramsJson], {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs,\n maxOutputBytes: ISOLATION_CHECK_MAX_OUTPUT_BYTES,\n tempRoot,\n });\n\n if (result.exitCode === 0 && isAcceptedJudgeOutput(result.stdout)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check passed',\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n ]);\n return { passed: true };\n }\n\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed',\n '',\n ...describeFailure(result, timeoutMs, options),\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n `Exit status : ${result.exitCode ?? result.signal ?? 'unknown'}`,\n `Failure reason : ${result.failureReason ?? '<none>'}`,\n '',\n 'stdout:',\n result.stdout.trimEnd() || '<empty>',\n '',\n 'stderr:',\n result.stderr.trimEnd() || '<empty>',\n ]);\n return { passed: false };\n } catch (error) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed due to an unexpected error',\n '',\n getErrorMessage(error),\n ]);\n return { passed: false };\n } finally {\n // Cleanup failures must not mask the primary isolation check result.\n if (tempRoot) await forciblyRemoveDirectory(tempRoot);\n }\n}\n\nfunction describeFailure(\n result: HarnessProcessResult,\n timeoutMs: number,\n options: ProblemDirIsolationCheckOptions\n): string[] {\n if (result.timedOut) {\n return [\n `The judge did not finish within ${timeoutMs / 1000} seconds after copying only the problem directory to a temporary location.`,\n ...(options.expectedMaxDurationMs === undefined\n ? [\n `This judge declares no run time, so the check uses its fixed ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000}-second budget.`,\n ]\n : [\n `The budget is the larger of ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000} seconds and the build timeout plus the time limit of every test case plus a ${ISOLATION_CHECK_OVERHEAD_MS / 1000}-second overhead.`,\n 'Check timeLimitMs, the number of test cases, and one-off startup costs such as cold caches.',\n ]),\n ];\n }\n if (result.failureReason !== undefined) {\n return ['The judge was stopped before it finished; see the failure reason below.'];\n }\n if (result.exitCode === undefined) {\n return [\n `The judge was terminated by ${result.signal ?? 'an unknown signal'} (e.g. an out-of-memory kill or a cancelled job).`,\n ];\n }\n return [\n 'The judge did not complete successfully after copying only the problem directory to a temporary location.',\n 'Make sure judge.ts imports only files included in the problem directory.',\n ];\n}\n\nfunction isIsolationExecArg(arg: string): boolean {\n return !arg.startsWith('--inspect') && !arg.startsWith('--watch') && !arg.startsWith('--hot');\n}\n\nfunction getInvokedScriptPath(problemDir: string): string {\n const scriptPath = process.argv[1];\n if (!scriptPath) return `.${path.sep}judge.ts`;\n const relativeScriptPath = path.relative(problemDir, path.resolve(scriptPath));\n if (path.isAbsolute(relativeScriptPath)) return relativeScriptPath;\n return relativeScriptPath.startsWith('.') ? relativeScriptPath : `.${path.sep}${relativeScriptPath}`;\n}\n\nfunction isAcceptedJudgeOutput(stdout: string): boolean {\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n if (resultLines.length === 0) return false;\n\n return resultLines.every((line) => {\n try {\n const parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n return parsedResult.success && parsedResult.data.decisionCode === DecisionCode.AC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AAa,KAAK,eAAiB,EAAa,QACjF,MAAQ,CACN,MAAO,EACT,CACF,CAAC,CACH"}
1
+ {"version":3,"file":"checkProblemDirIsolation.js","names":["path","ISOLATION_CHECK_MIN_TIMEOUT_MS","ISOLATION_CHECK_OVERHEAD_MS","checkProblemDirIsolation","timeoutMs","options","tempRoot","copyResult","copyProblemDirToTemporaryRoot","problemDir","absoluteProblemDir","relativeCwd","resolvedCwd","copiedCwd","copiedProblemDir","scriptPath","getInvokedScriptPath","printDebugBanner","execArgv","isIsolationExecArg","paramsJson","isRecord","params","result","runHarnessProcess","isAcceptedJudgeOutput","describeFailure","error","getErrorMessage","forciblyRemoveDirectory","arg","relativeScriptPath","resultLines","stdout","line","TEST_CASE_RESULT_PREFIX","parsedResult","testCaseResultSchema","DecisionCode"],"sources":["../../src/helpers/checkProblemDirIsolation.ts"],"sourcesContent":["import path from 'node:path';\nimport { getErrorMessage, isRecord } from '@willbooster/shared-lib';\n\nimport { DecisionCode } from '../types/decisionCode.js';\nimport { TEST_CASE_RESULT_PREFIX, testCaseResultSchema } from '../types/testCaseResult.js';\n\nimport { printDebugBanner } from './printDebugBanner.js';\nimport type { ResolvedCwd } from './resolveCwds.js';\nimport { type HarnessProcessResult, runHarnessProcess } from './runHarnessProcess.js';\nimport { copyProblemDirToTemporaryRoot, forciblyRemoveDirectory } from './temporaryProblemDirCopy.js';\n\nconst ISOLATION_CHECK_MIN_TIMEOUT_MS = 30_000;\n// Starting bun and printing results are not covered by the judge's own limits.\nconst ISOLATION_CHECK_OVERHEAD_MS = 10_000;\nconst ISOLATION_CHECK_MAX_OUTPUT_BYTES = 64 * 1024 * 1024;\n\nexport interface ProblemDirIsolationCheckOptions {\n /**\n * The judge's declared worst-case duration for one accepted submission (build timeout plus the\n * time limit of every test case). The check allows at least that plus a fixed overhead; per-case\n * process startup and custom judge callbacks are not budgeted separately.\n */\n expectedMaxDurationMs?: number;\n}\n\nexport interface ProblemDirIsolationCheckResult {\n passed: boolean;\n}\n\n/**\n * Check that a judge can run after only the problem directory is copied elsewhere.\n */\nexport async function checkProblemDirIsolation(\n problemDir: string,\n resolvedCwd: ResolvedCwd,\n params: unknown,\n options: ProblemDirIsolationCheckOptions = {}\n): Promise<ProblemDirIsolationCheckResult> {\n const timeoutMs = Math.max(\n ISOLATION_CHECK_MIN_TIMEOUT_MS,\n (options.expectedMaxDurationMs ?? 0) + ISOLATION_CHECK_OVERHEAD_MS\n );\n let tempRoot: string | undefined;\n try {\n const copyResult = await copyProblemDirToTemporaryRoot(problemDir);\n tempRoot = copyResult.tempRoot;\n const { copiedProblemDir } = copyResult;\n const absoluteProblemDir = path.resolve(problemDir);\n\n const relativeCwd = path.relative(absoluteProblemDir, path.resolve(resolvedCwd.cwd));\n const copiedCwd = path.join(copiedProblemDir, relativeCwd);\n const scriptPath = getInvokedScriptPath(absoluteProblemDir);\n if (scriptPath.startsWith('..') || path.isAbsolute(scriptPath)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check skipped',\n '',\n 'The invoked judge script is located outside the problem directory.',\n `Script path: ${scriptPath}`,\n ]);\n return { passed: true };\n }\n const execArgv = process.execArgv.filter(isIsolationExecArg);\n const paramsJson = JSON.stringify(isRecord(params) ? params : {});\n const result = await runHarnessProcess([...execArgv, scriptPath, copiedCwd, paramsJson], {\n cwd: copiedProblemDir,\n env: process.env,\n timeoutMs,\n maxOutputBytes: ISOLATION_CHECK_MAX_OUTPUT_BYTES,\n tempRoot,\n });\n\n if (result.exitCode === 0 && isAcceptedJudgeOutput(result.stdout)) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check passed',\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n ]);\n return { passed: true };\n }\n\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed',\n '',\n ...describeFailure(result, timeoutMs, options),\n '',\n `Copied problem dir : ${copiedProblemDir}`,\n `Checked cwd : ${relativeCwd}`,\n `Exit status : ${result.exitCode ?? result.signal ?? 'unknown'}`,\n `Failure reason : ${result.failureReason ?? '<none>'}`,\n '',\n 'stdout:',\n result.stdout.trimEnd() || '<empty>',\n '',\n 'stderr:',\n result.stderr.trimEnd() || '<empty>',\n ]);\n return { passed: false };\n } catch (error) {\n printDebugBanner([\n '[DEBUG MODE] isolated problem directory check failed due to an unexpected error',\n '',\n getErrorMessage(error),\n ]);\n return { passed: false };\n } finally {\n // Cleanup failures must not mask the primary isolation check result.\n if (tempRoot) await forciblyRemoveDirectory(tempRoot);\n }\n}\n\nfunction describeFailure(\n result: HarnessProcessResult,\n timeoutMs: number,\n options: ProblemDirIsolationCheckOptions\n): string[] {\n if (result.timedOut) {\n return [\n `The judge did not finish within ${timeoutMs / 1000} seconds after copying only the problem directory to a temporary location.`,\n ...(options.expectedMaxDurationMs === undefined\n ? [\n `This judge declares no run time, so the check uses its fixed ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000}-second budget.`,\n ]\n : [\n `The budget is the larger of ${ISOLATION_CHECK_MIN_TIMEOUT_MS / 1000} seconds and the build timeout plus the time limit of every test case plus a ${ISOLATION_CHECK_OVERHEAD_MS / 1000}-second overhead.`,\n 'Check timeLimitMs, the number of test cases, and one-off startup costs such as cold caches.',\n ]),\n ];\n }\n if (result.failureReason !== undefined) {\n return ['The judge was stopped before it finished; see the failure reason below.'];\n }\n if (result.exitCode === undefined) {\n return [\n `The judge was terminated by ${result.signal ?? 'an unknown signal'} (e.g. an out-of-memory kill or a cancelled job).`,\n ];\n }\n return [\n 'The judge did not complete successfully after copying only the problem directory to a temporary location.',\n 'Make sure judge.ts imports only files included in the problem directory.',\n ];\n}\n\nfunction isIsolationExecArg(arg: string): boolean {\n return !arg.startsWith('--inspect') && !arg.startsWith('--watch') && !arg.startsWith('--hot');\n}\n\nfunction getInvokedScriptPath(problemDir: string): string {\n const scriptPath = process.argv[1];\n if (!scriptPath) return `.${path.sep}judge.ts`;\n const relativeScriptPath = path.relative(problemDir, path.resolve(scriptPath));\n if (path.isAbsolute(relativeScriptPath)) return relativeScriptPath;\n return relativeScriptPath.startsWith('.') ? relativeScriptPath : `.${path.sep}${relativeScriptPath}`;\n}\n\nfunction isAcceptedJudgeOutput(stdout: string): boolean {\n const resultLines = stdout.split(/\\r?\\n/).filter((line) => line.startsWith(TEST_CASE_RESULT_PREFIX));\n if (resultLines.length === 0) return false;\n\n return resultLines.every((line) => {\n try {\n const parsedResult = testCaseResultSchema.safeParse(JSON.parse(line.slice(TEST_CASE_RESULT_PREFIX.length)));\n return parsedResult.success && parsedResult.data.decisionCode === DecisionCode.ACCEPTED;\n } catch {\n return false;\n }\n });\n}\n"],"mappings":"sdAWA,MAAMC,EAAiC,IAEjCC,EAA8B,IAmBpC,eAAsBC,EACpB,EACA,EACA,EACA,EAA2C,CAAC,EACH,CACzC,IAAMC,EAAY,KAAK,IACrBH,GACCI,EAAQ,uBAAyB,GAAKH,CACzC,EACII,EACJ,GAAI,CACF,IAAMC,EAAa,MAAMC,EAA8BC,CAAU,EACjE,EAAWF,EAAW,SACtB,GAAM,CAAE,oBAAqBA,EACvBG,EAAqBV,EAAK,QAAQS,CAAU,EAE5CE,EAAcX,EAAK,SAASU,EAAoBV,EAAK,QAAQY,EAAY,GAAG,CAAC,EAC7EC,EAAYb,EAAK,KAAKc,EAAkBH,CAAW,EACnDI,EAAaC,EAAqBN,CAAkB,EAC1D,GAAIK,EAAW,WAAW,IAAI,GAAKf,EAAK,WAAWe,CAAU,EAO3D,OANAE,EAAiB,CACf,wDACA,GACA,qEACA,gBAAgBF,GAClB,CAAC,EACM,CAAE,OAAQ,EAAK,EAExB,IAAMG,EAAW,QAAQ,SAAS,OAAOC,CAAkB,EACrDC,EAAa,KAAK,UAAUC,EAASC,CAAM,EAAIA,EAAS,CAAC,CAAC,EAC1DC,EAAS,MAAMC,EAAkB,CAAC,GAAGN,EAAUH,EAAYF,EAAWO,CAAU,EAAG,CACvF,IAAKN,EACL,IAAK,QAAQ,IACb,YACA,eAAgB,SAChB,UACF,CA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AIf,EAAK,IAAI,UACrC,IAAM+B,EAAqB/B,EAAK,SAASS,EAAYT,EAAK,QAAQe,CAAU,CAAC,EAE7E,OADIf,EAAK,WAAW+B,CAAkB,GAC/BA,EAAmB,WAAW,GAAG,EADQA,EACiB,IAAI/B,EAAK,MAAM+B,GAClF,CAEA,SAASN,EAAsB,EAAyB,CACtD,IAAMO,EAAcC,EAAO,MAAM,OAAO,CAAC,CAAC,OAAQ,GAASC,EAAK,WAAWC,CAAuB,CAAC,EAGnG,OAFIH,EAAY,SAAW,GAEpBA,EAAY,MAAO,GAAS,CACjC,GAAI,CACF,IAAMI,EAAeC,EAAqB,UAAU,KAAK,MAAMH,EAAK,MAAMC,EAAwB,MAAM,CAAC,CAAC,EAC1G,OAAOC,EAAa,SAAWA,EAAa,KAAK,eAAiBE,EAAa,QACjF,MAAQ,CACN,MAAO,EACT,CACF,CAAC,CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"cleanWorkingDirectory.cjs","names":["fs","path"],"sources":["../../src/helpers/cleanWorkingDirectory.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\n// Currently, it does not support changing file contents and deleting files.\nexport async function snapshotWorkingDirectory(cwd: string): Promise<ReadonlySet<string>> {\n const paths = await fs.readdir(cwd, { recursive: true });\n return new Set(paths);\n}\n\nexport async function cleanWorkingDirectory(cwd: string, snapshot: ReadonlySet<string>): Promise<void> {\n await cleanDirectory(cwd, '', snapshot);\n}\n\nasync function cleanDirectory(dir: string, relativePrefix: string, snapshot: ReadonlySet<string>): Promise<void> {\n for (const entry of await fs.readdir(dir, { withFileTypes: true })) {\n const relativePath = path.join(relativePrefix, entry.name);\n if (!snapshot.has(relativePath)) {\n // An unsnapshotted directory is removed whole, so its contents are never visited.\n await fs.rm(path.join(dir, entry.name), { force: true, recursive: true });\n } else if (entry.isDirectory()) {\n await cleanDirectory(path.join(dir, entry.name), relativePath, snapshot);\n }\n }\n}\n"],"mappings":"iKAIA,eAAsB,EAAyB,EAA2C,CACxF,IAAM,EAAQ,MAAMA,EAAAA,QAAG,QAAQ,EAAK,CAAE,UAAW,EAAK,CAAC,EACvD,OAAO,IAAI,IAAI,CAAK,CACtB,CAEA,eAAsB,EAAsB,EAAa,EAA8C,CACrG,MAAM,EAAe,EAAK,GAAI,CAAQ,CACxC,CAEA,eAAe,EAAe,EAAa,EAAwB,EAA8C,CAC/G,IAAK,IAAM,KAAS,MAAMA,EAAAA,QAAG,QAAQ,EAAK,CAAE,cAAe,EAAK,CAAC,EAAG,CAClE,IAAM,EAAeC,EAAAA,QAAK,KAAK,EAAgB,EAAM,IAAI,EACpD,EAAS,IAAI,CAAY,EAGnB,EAAM,YAAY,GAC3B,MAAM,EAAeA,EAAAA,QAAK,KAAK,EAAK,EAAM,IAAI,EAAG,EAAc,CAAQ,EAFvE,MAAMD,EAAAA,QAAG,GAAGC,EAAAA,QAAK,KAAK,EAAK,EAAM,IAAI,EAAG,CAAE,MAAO,GAAM,UAAW,EAAK,CAAC,CAI5E,CACF"}
1
+ {"version":3,"file":"cleanWorkingDirectory.cjs","names":["fs","path","require_runtime","node_path","node_fs_promises","snapshotWorkingDirectory","paths","cwd","cleanWorkingDirectory","cleanDirectory","snapshot","entry","dir","relativePath","relativePrefix"],"sources":["../../src/helpers/cleanWorkingDirectory.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\n// Currently, it does not support changing file contents and deleting files.\nexport async function snapshotWorkingDirectory(cwd: string): Promise<ReadonlySet<string>> {\n const paths = await fs.readdir(cwd, { recursive: true });\n return new Set(paths);\n}\n\nexport async function cleanWorkingDirectory(cwd: string, snapshot: ReadonlySet<string>): Promise<void> {\n await cleanDirectory(cwd, '', snapshot);\n}\n\nasync function cleanDirectory(dir: string, relativePrefix: string, snapshot: ReadonlySet<string>): Promise<void> {\n for (const entry of await fs.readdir(dir, { withFileTypes: true })) {\n const relativePath = path.join(relativePrefix, entry.name);\n if (!snapshot.has(relativePath)) {\n // An unsnapshotted directory is removed whole, so its contents are never visited.\n await fs.rm(path.join(dir, entry.name), { force: true, recursive: true });\n } else if (entry.isDirectory()) {\n await cleanDirectory(path.join(dir, entry.name), relativePath, snapshot);\n }\n }\n}\n"],"mappings":"iKAIA,eAAsBK,EAAyB,EAA2C,CACxF,IAAMC,EAAQ,MAAMN,EAAAA,QAAG,QAAQO,EAAK,CAAE,UAAW,EAAK,CAAC,EACvD,OAAO,IAAI,IAAID,CAAK,CACtB,CAEA,eAAsBE,EAAsB,EAAa,EAA8C,CACrG,MAAMC,EAAeF,EAAK,GAAIG,CAAQ,CACxC,CAEA,eAAeD,EAAe,EAAa,EAAwB,EAA8C,CAC/G,IAAK,IAAME,KAAS,MAAMX,EAAAA,QAAG,QAAQY,EAAK,CAAE,cAAe,EAAK,CAAC,EAAG,CAClE,IAAMC,EAAeZ,EAAAA,QAAK,KAAKa,EAAgBH,EAAM,IAAI,EACpDD,EAAS,IAAIG,CAAY,EAGnBF,EAAM,YAAY,GAC3B,MAAMF,EAAeR,EAAAA,QAAK,KAAKW,EAAKD,EAAM,IAAI,EAAGE,EAAcH,CAAQ,EAFvE,MAAMV,EAAAA,QAAG,GAAGC,EAAAA,QAAK,KAAKW,EAAKD,EAAM,IAAI,EAAG,CAAE,MAAO,GAAM,UAAW,EAAK,CAAC,CAI5E,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"cleanWorkingDirectory.js","names":[],"sources":["../../src/helpers/cleanWorkingDirectory.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\n// Currently, it does not support changing file contents and deleting files.\nexport async function snapshotWorkingDirectory(cwd: string): Promise<ReadonlySet<string>> {\n const paths = await fs.readdir(cwd, { recursive: true });\n return new Set(paths);\n}\n\nexport async function cleanWorkingDirectory(cwd: string, snapshot: ReadonlySet<string>): Promise<void> {\n await cleanDirectory(cwd, '', snapshot);\n}\n\nasync function cleanDirectory(dir: string, relativePrefix: string, snapshot: ReadonlySet<string>): Promise<void> {\n for (const entry of await fs.readdir(dir, { withFileTypes: true })) {\n const relativePath = path.join(relativePrefix, entry.name);\n if (!snapshot.has(relativePath)) {\n // An unsnapshotted directory is removed whole, so its contents are never visited.\n await fs.rm(path.join(dir, entry.name), { force: true, recursive: true });\n } else if (entry.isDirectory()) {\n await cleanDirectory(path.join(dir, entry.name), relativePath, snapshot);\n }\n }\n}\n"],"mappings":"yDAIA,eAAsB,EAAyB,EAA2C,CACxF,IAAM,EAAQ,MAAM,EAAG,QAAQ,EAAK,CAAE,UAAW,EAAK,CAAC,EACvD,OAAO,IAAI,IAAI,CAAK,CACtB,CAEA,eAAsB,EAAsB,EAAa,EAA8C,CACrG,MAAM,EAAe,EAAK,GAAI,CAAQ,CACxC,CAEA,eAAe,EAAe,EAAa,EAAwB,EAA8C,CAC/G,IAAK,IAAM,KAAS,MAAM,EAAG,QAAQ,EAAK,CAAE,cAAe,EAAK,CAAC,EAAG,CAClE,IAAM,EAAe,EAAK,KAAK,EAAgB,EAAM,IAAI,EACpD,EAAS,IAAI,CAAY,EAGnB,EAAM,YAAY,GAC3B,MAAM,EAAe,EAAK,KAAK,EAAK,EAAM,IAAI,EAAG,EAAc,CAAQ,EAFvE,MAAM,EAAG,GAAG,EAAK,KAAK,EAAK,EAAM,IAAI,EAAG,CAAE,MAAO,GAAM,UAAW,EAAK,CAAC,CAI5E,CACF"}
1
+ {"version":3,"file":"cleanWorkingDirectory.js","names":["path","fs","snapshotWorkingDirectory","paths","cwd","cleanWorkingDirectory","cleanDirectory","snapshot","entry","dir","relativePath","relativePrefix"],"sources":["../../src/helpers/cleanWorkingDirectory.ts"],"sourcesContent":["import fs from 'node:fs/promises';\nimport path from 'node:path';\n\n// Currently, it does not support changing file contents and deleting files.\nexport async function snapshotWorkingDirectory(cwd: string): Promise<ReadonlySet<string>> {\n const paths = await fs.readdir(cwd, { recursive: true });\n return new Set(paths);\n}\n\nexport async function cleanWorkingDirectory(cwd: string, snapshot: ReadonlySet<string>): Promise<void> {\n await cleanDirectory(cwd, '', snapshot);\n}\n\nasync function cleanDirectory(dir: string, relativePrefix: string, snapshot: ReadonlySet<string>): Promise<void> {\n for (const entry of await fs.readdir(dir, { withFileTypes: true })) {\n const relativePath = path.join(relativePrefix, entry.name);\n if (!snapshot.has(relativePath)) {\n // An unsnapshotted directory is removed whole, so its contents are never visited.\n await fs.rm(path.join(dir, entry.name), { force: true, recursive: true });\n } else if (entry.isDirectory()) {\n await cleanDirectory(path.join(dir, entry.name), relativePath, snapshot);\n }\n }\n}\n"],"mappings":"yDAIA,eAAsBE,EAAyB,EAA2C,CACxF,IAAMC,EAAQ,MAAMF,EAAG,QAAQG,EAAK,CAAE,UAAW,EAAK,CAAC,EACvD,OAAO,IAAI,IAAID,CAAK,CACtB,CAEA,eAAsBE,EAAsB,EAAa,EAA8C,CACrG,MAAMC,EAAeF,EAAK,GAAIG,CAAQ,CACxC,CAEA,eAAeD,EAAe,EAAa,EAAwB,EAA8C,CAC/G,IAAK,IAAME,KAAS,MAAMP,EAAG,QAAQQ,EAAK,CAAE,cAAe,EAAK,CAAC,EAAG,CAClE,IAAMC,EAAeV,EAAK,KAAKW,EAAgBH,EAAM,IAAI,EACpDD,EAAS,IAAIG,CAAY,EAGnBF,EAAM,YAAY,GAC3B,MAAMF,EAAeN,EAAK,KAAKS,EAAKD,EAAM,IAAI,EAAGE,EAAcH,CAAQ,EAFvE,MAAMN,EAAG,GAAGD,EAAK,KAAKS,EAAKD,EAAM,IAAI,EAAG,CAAE,MAAO,GAAM,UAAW,EAAK,CAAC,CAI5E,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"compareExpectedOutputFiles.cjs","names":["fs","path","encodeFileForTestCaseResult","compareStdoutAsSpaceSeparatedTokens"],"sources":["../../src/helpers/compareExpectedOutputFiles.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { TestCaseResult } from '../types/testCaseResult.js';\n\nimport { compareStdoutAsSpaceSeparatedTokens } from './compareStdoutAsSpaceSeparatedTokens.js';\nimport { encodeFileForTestCaseResult } from './printTestCaseResult.js';\n\ntype OutputFile = NonNullable<TestCaseResult['outputFiles']>[number];\n\n// Bound what the harness reads and reports.\nexport const MAX_COMPARED_FILE_BYTES = 8 * 1024 * 1024;\nexport const MAX_REPORTED_FILE_BYTES = 1024 * 1024;\n\nexport interface ExpectedOutputFilesComparison {\n /** Whether every file under the expected directory has a matching file in the working directory. */\n matches: boolean;\n /** Relative paths (from the working directory) of the files that are missing or different. */\n mismatchedPaths: string[];\n /**\n * `<name>_expected.<ext>` / `<name>_received.<ext>` pairs for each mismatched file, in the\n * format Exercode renders side by side. A received file that is missing, unreadable, not a\n * regular file or larger than `MAX_COMPARED_FILE_BYTES` yields only the expected entry, and a\n * file larger than `MAX_REPORTED_FILE_BYTES` is left out of the pair. Exercode decides per test case whether a learner may see these files.\n */\n outputFiles: OutputFile[];\n}\n\n/**\n * Compare the files under a test case's `.fout` directory with the files the submission wrote to\n * its working directory. Text files are compared like stdout (space-separated tokens with a\n * numeric tolerance); binary files must match byte for byte.\n */\nexport async function compareExpectedOutputFiles(\n cwd: string,\n fileOutputPath: string\n): Promise<ExpectedOutputFilesComparison> {\n const mismatchedPaths: string[] = [];\n const outputFiles: OutputFile[] = [];\n const dirents = await fs.promises.readdir(fileOutputPath, { withFileTypes: true, recursive: true });\n const expectedFiles = dirents\n .filter((dirent) => dirent.isFile())\n .map((dirent) => ({\n absolutePath: path.join(dirent.parentPath, dirent.name),\n // POSIX separators: `requiredOutputFilePaths` and the result format use them on every platform.\n relativePath: path.posix.join(...path.relative(fileOutputPath, dirent.parentPath).split(path.sep), dirent.name),\n }))\n .toSorted((a, b) => (a.relativePath < b.relativePath ? -1 : a.relativePath > b.relativePath ? 1 : 0));\n for (const { absolutePath, relativePath } of expectedFiles) {\n // A larger expectation could never be matched by a received file, so it is an authoring error.\n const expectedStats = await fs.promises.stat(absolutePath);\n if (expectedStats.size > MAX_COMPARED_FILE_BYTES) {\n throw new Error(`expected output file ${relativePath} exceeds ${MAX_COMPARED_FILE_BYTES} bytes`);\n }\n const expected = await fs.promises.readFile(absolutePath);\n const received = await readReceivedFile(path.join(cwd, relativePath));\n if (received && fileContentsMatch(expected, received)) continue;\n\n mismatchedPaths.push(relativePath);\n // A file too large to ship in a result line is left out of the pair rather than truncated.\n if (expected.length <= MAX_REPORTED_FILE_BYTES) {\n outputFiles.push(encodeFileForTestCaseResult(toComparisonPath(relativePath, 'expected'), expected));\n }\n if (received && received.length <= MAX_REPORTED_FILE_BYTES) {\n outputFiles.push(encodeFileForTestCaseResult(toComparisonPath(relativePath, 'received'), received));\n }\n }\n return { matches: mismatchedPaths.length === 0, mismatchedPaths, outputFiles };\n}\n\n/**\n * The default verdict of the presets: `.out` decides stdout and `.fout/` decides output files, both\n * checked so a result carries every mismatch; either expectation may be absent. Returns whether the\n * run matched and the output files to report (the plain copies of mismatched required output files\n * replaced by their comparison pairs).\n */\nexport async function judgeAgainstExpectations(context: {\n stdout: string;\n expectedStdout: string | undefined;\n fileOutputPath: string | undefined;\n cwd: string;\n outputFiles: readonly OutputFile[];\n}): Promise<{ matches: boolean; outputFiles: OutputFile[] }> {\n const { stdout, expectedStdout, fileOutputPath, cwd } = context;\n let outputFiles = [...context.outputFiles];\n let matches = expectedStdout === undefined || compareStdoutAsSpaceSeparatedTokens(stdout, expectedStdout);\n if (fileOutputPath !== undefined) {\n const comparison = await compareExpectedOutputFiles(cwd, fileOutputPath);\n if (!comparison.matches) {\n matches = false;\n outputFiles = mergeComparisonOutputFiles(outputFiles, comparison);\n }\n }\n return { matches, outputFiles };\n}\n\n/**\n * Replace the plain copies of mismatched required output files with the comparison pairs, so a\n * result shows `<name>_expected.<ext>` / `<name>_received.<ext>` instead of a lone `<name>.<ext>`.\n */\nexport function mergeComparisonOutputFiles(\n outputFiles: readonly OutputFile[],\n comparison: ExpectedOutputFilesComparison\n): OutputFile[] {\n const comparisonPaths = new Set(comparison.outputFiles.map((file) => file.path));\n // The plain copy gives way to its `_received` entry; a mismatch too large for a pair keeps the\n // plain copy, and a kept file literally named like a pair entry would make the path ambiguous.\n const replacedPaths = new Set(\n comparison.mismatchedPaths.filter((filePath) => comparisonPaths.has(toComparisonPath(filePath, 'received')))\n );\n return [\n ...outputFiles.filter((file) => !replacedPaths.has(file.path) && !comparisonPaths.has(file.path)),\n ...comparison.outputFiles,\n ];\n}\n\n/** `c.txt` → `c_expected.txt`; `out/c.txt` → `out/c_expected.txt`. */\nfunction toComparisonPath(filePath: string, role: 'expected' | 'received'): string {\n const { dir, name, ext } = path.posix.parse(filePath);\n return path.posix.join(dir, `${name}_${role}${ext}`);\n}\n\n// Anything that is not a plain, readable file within the size limit (a directory, a FIFO that would\n// block, an unreadable or huge file) counts as \"not produced\".\nasync function readReceivedFile(receivedPath: string): Promise<Buffer | undefined> {\n try {\n const stats = await fs.promises.stat(receivedPath);\n if (!stats.isFile() || stats.size > MAX_COMPARED_FILE_BYTES) return undefined;\n return await fs.promises.readFile(receivedPath);\n } catch {\n return undefined;\n }\n}\n\nfunction fileContentsMatch(expected: Buffer, received: Buffer): boolean {\n if (!isTextFile(expected)) return received.equals(expected);\n if (!isTextFile(received)) return false;\n return compareStdoutAsSpaceSeparatedTokens(received.toString('utf8'), expected.toString('utf8'));\n}\n\nconst utf8Decoder = new TextDecoder('utf-8', { fatal: true });\n\n// Valid UTF-8 without NUL bytes: a binary format that happens to decode (e.g. a PNG chunk) almost\n// always contains NUL, while text files containing U+FFFD are still treated as text.\nfunction isTextFile(data: Buffer): boolean {\n if (data.includes(0)) return false;\n try {\n utf8Decoder.decode(data);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"sPAWA,MAAa,EAA0B,QAsBvC,eAAsB,EACpB,EACA,EACwC,CACxC,IAAM,EAA4B,CAAC,EAC7B,EAA4B,CAAC,EAE7B,GAAgB,MADAA,EAAAA,QAAG,SAAS,QAAQ,EAAgB,CAAE,cAAe,GAAM,UAAW,EAAK,CAAC,EAAA,CAE/F,OAAQ,GAAW,E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ExpectedOutputFiles.cjs","names":["fs","path","encodeFileForTestCaseResult","compareStdoutAsSpaceSeparatedTokens","require_runtime","require_compareStdoutAsSpaceSeparatedTokens","require_printTestCaseResult","node_fs","node_path","MAX_COMPARED_FILE_BYTES","compareExpectedOutputFiles","mismatchedPaths","outputFiles","expectedFiles","fileOutputPath","dirent","a","b","absolutePath","relativePath","expected","received","readReceivedFile","cwd","fileContentsMatch","toComparisonPath","judgeAgainstExpectations","context","matches","expectedStdout","stdout","comparison","mergeComparisonOutputFiles","comparisonPaths","file","replacedPaths","filePath","dir","name","role","ext","stats","receivedPath","isTextFile","utf8Decoder","data"],"sources":["../../src/helpers/compareExpectedOutputFiles.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport type { TestCaseResult } from '../types/testCaseResult.js';\n\nimport { compareStdoutAsSpaceSeparatedTokens } from './compareStdoutAsSpaceSeparatedTokens.js';\nimport { encodeFileForTestCaseResult } from './printTestCaseResult.js';\n\ntype OutputFile = NonNullable<TestCaseResult['outputFiles']>[number];\n\n// Bound what the harness reads and reports.\nexport const MAX_COMPARED_FILE_BYTES = 8 * 1024 * 1024;\nexport const MAX_REPORTED_FILE_BYTES = 1024 * 1024;\n\nexport interface ExpectedOutputFilesComparison {\n /** Whether every file under the expected directory has a matching file in the working directory. */\n matches: boolean;\n /** Relative paths (from the working directory) of the files that are missing or different. */\n mismatchedPaths: string[];\n /**\n * `<name>_expected.<ext>` / `<name>_received.<ext>` pairs for each mismatched file, in the\n * format Exercode renders side by side. A received file that is missing, unreadable, not a\n * regular file or larger than `MAX_COMPARED_FILE_BYTES` yields only the expected entry, and a\n * file larger than `MAX_REPORTED_FILE_BYTES` is left out of the pair. Exercode decides per test case whether a learner may see these files.\n */\n outputFiles: OutputFile[];\n}\n\n/**\n * Compare the files under a test case's `.fout` directory with the files the submission wrote to\n * its working directory. Text files are compared like stdout (space-separated tokens with a\n * numeric tolerance); binary files must match byte for byte.\n */\nexport async function compareExpectedOutputFiles(\n cwd: string,\n fileOutputPath: string\n): Promise<ExpectedOutputFilesComparison> {\n const mismatchedPaths: string[] = [];\n const outputFiles: OutputFile[] = [];\n const dirents = await fs.promises.readdir(fileOutputPath, { withFileTypes: true, recursive: true });\n const expectedFiles = dirents\n .filter((dirent) => dirent.isFile())\n .map((dirent) => ({\n absolutePath: path.join(dirent.parentPath, dirent.name),\n // POSIX separators: `requiredOutputFilePaths` and the result format use them on every platform.\n relativePath: path.posix.join(...path.relative(fileOutputPath, dirent.parentPath).split(path.sep), dirent.name),\n }))\n .toSorted((a, b) => (a.relativePath < b.relativePath ? -1 : a.relativePath > b.relativePath ? 1 : 0));\n for (const { absolutePath, relativePath } of expectedFiles) {\n // A larger expectation could never be matched by a received file, so it is an authoring error.\n const expectedStats = await fs.promises.stat(absolutePath);\n if (expectedStats.size > MAX_COMPARED_FILE_BYTES) {\n throw new Error(`expected output file ${relativePath} exceeds ${MAX_COMPARED_FILE_BYTES} bytes`);\n }\n const expected = await fs.promises.readFile(absolutePath);\n const received = await readReceivedFile(path.join(cwd, relativePath));\n if (received && fileContentsMatch(expected, received)) continue;\n\n mismatchedPaths.push(relativePath);\n // A file too large to ship in a result line is left out of the pair rather than truncated.\n if (expected.length <= MAX_REPORTED_FILE_BYTES) {\n outputFiles.push(encodeFileForTestCaseResult(toComparisonPath(relativePath, 'expected'), expected));\n }\n if (received && received.length <= MAX_REPORTED_FILE_BYTES) {\n outputFiles.push(encodeFileForTestCaseResult(toComparisonPath(relativePath, 'received'), received));\n }\n }\n return { matches: mismatchedPaths.length === 0, mismatchedPaths, outputFiles };\n}\n\n/**\n * The default verdict of the presets: `.out` decides stdout and `.fout/` decides output files, both\n * checked so a result carries every mismatch; either expectation may be absent. Returns whether the\n * run matched and the output files to report (the plain copies of mismatched required output files\n * replaced by their comparison pairs).\n */\nexport async function judgeAgainstExpectations(context: {\n stdout: string;\n expectedStdout: string | undefined;\n fileOutputPath: string | undefined;\n cwd: string;\n outputFiles: readonly OutputFile[];\n}): Promise<{ matches: boolean; outputFiles: OutputFile[] }> {\n const { stdout, expectedStdout, fileOutputPath, cwd } = context;\n let outputFiles = [...context.outputFiles];\n let matches = expectedStdout === undefined || compareStdoutAsSpaceSeparatedTokens(stdout, expectedStdout);\n if (fileOutputPath !== undefined) {\n const comparison = await compareExpectedOutputFiles(cwd, fileOutputPath);\n if (!comparison.matches) {\n matches = false;\n outputFiles = mergeComparisonOutputFiles(outputFiles, comparison);\n }\n }\n return { matches, outputFiles };\n}\n\n/**\n * Replace the plain copies of mismatched required output files with the comparison pairs, so a\n * result shows `<name>_expected.<ext>` / `<name>_received.<ext>` instead of a lone `<name>.<ext>`.\n */\nexport function mergeComparisonOutputFiles(\n outputFiles: readonly OutputFile[],\n comparison: ExpectedOutputFilesComparison\n): OutputFile[] {\n const comparisonPaths = new Set(comparison.outputFiles.map((file) => file.path));\n // The plain copy gives way to its `_received` entry; a mismatch too large for a pair keeps the\n // plain copy, and a kept file literally named like a pair entry would make the path ambiguous.\n const replacedPaths = new Set(\n comparison.mismatchedPaths.filter((filePath) => comparisonPaths.has(toComparisonPath(filePath, 'received')))\n );\n return [\n ...outputFiles.filter((file) => !replacedPaths.has(file.path) && !comparisonPaths.has(file.path)),\n ...comparison.outputFiles,\n ];\n}\n\n/** `c.txt` → `c_expected.txt`; `out/c.txt` → `out/c_expected.txt`. */\nfunction toComparisonPath(filePath: string, role: 'expected' | 'received'): string {\n const { dir, name, ext } = path.posix.parse(filePath);\n return path.posix.join(dir, `${name}_${role}${ext}`);\n}\n\n// Anything that is not a plain, readable file within the size limit (a directory, a FIFO that would\n// block, an unreadable or huge file) counts as \"not produced\".\nasync function readReceivedFile(receivedPath: string): Promise<Buffer | undefined> {\n try {\n const stats = await fs.promises.stat(receivedPath);\n if (!stats.isFile() || stats.size > MAX_COMPARED_FILE_BYTES) return undefined;\n return await fs.promises.readFile(receivedPath);\n } catch {\n return undefined;\n }\n}\n\nfunction fileContentsMatch(expected: Buffer, received: Buffer): boolean {\n if (!isTextFile(expected)) return received.equals(expected);\n if (!isTextFile(received)) return false;\n return compareStdoutAsSpaceSeparatedTokens(received.toString('utf8'), expected.toString('utf8'));\n}\n\nconst utf8Decoder = new TextDecoder('utf-8', { fatal: true });\n\n// Valid UTF-8 without NUL bytes: a binary format that happens to decode (e.g. a PNG chunk) almost\n// always contains NUL, while text files containing U+FFFD are still treated as text.\nfunction isTextFile(data: Buffer): boolean {\n if (data.includes(0)) return false;\n try {\n utf8Decoder.decode(data);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":"sPAWA,MAAaS,EAA0B,QAsBvC,eAAsBC,EACpB,EACA,EACwC,CACxC,IAAMC,EAA4B,CAAC,EAC7BC,EAA4B,CAAC,EAE7BC,GAAgB,MADAb,EAAAA,QAAG,SAAS,QAAQc,EAAgB,CAAE,cAAe,GAAM,UAAW,EAAK,CAAC,EAAA,CAE/F,OAAQ,GAAWC,EAAO,OAAO,CAAC,CAAC,CACnC,IAAK,IAAY,CAChB,aAAcd,EAAAA,QAAK,KAAKc,EAAO,WAAYA,EAAO,IAAI,EAEtD,aAAcd,EAAAA,QAAK,MAAM,KAAK,GAAGA,EAAAA,QAAK,SAASa,EAAgBC,EAAO,UAAU,CAAC,CAAC,MAAMd,EAAAA,QAAK,GAAG,EAAGc,EAAO,IAAI,CAChH,EAAE,CAAC,CACF,UAAU,EAAG,IAAOC,EAAE,aAAeC,EAAE,aAAe,GAAK,IAAE,aAAeA,EAAE,aAAqB,EACtG,IAAK,GAAM,CAAE,eAAc,kBAAkBJ,EAAe,CAG1D,IAAI,MADwBb,EAAAA,QAAG,SAAS,KAAKkB,CAAY,EAAA,CACvC,KAAA,QAChB,MAAU,MAAM,wBAAwBC,EAAa,WAAWV,EAAwB,OAAO,EAEjG,IAAMW,EAAW,MAAMpB,EAAAA,QAAG,SAAS,SAASkB,CAAY,EAClDG,EAAW,MAAMC,EAAiBrB,EAAAA,QAAK,KAAKsB,EAAKJ,CAAY,CAAC,EAChEE,GAAYG,E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