@exercode/problem-utils 1.20.0 → 2.0.1

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.
package/README.md CHANGED
@@ -8,24 +8,24 @@
8
8
 
9
9
  ## CLI
10
10
 
11
- The package ships an `exercode` command for problem authors (run it with `bun x` in a repository that depends on `@exercode/problem-utils`):
11
+ The package ships an `exercode-problem` command for problem authors (run it with `bun x` in a repository that depends on `@exercode/problem-utils`):
12
12
 
13
13
  ```bash
14
14
  # Judge all model answers of all problems (directories containing problem.md or <id>.problem.md) under a directory.
15
15
  # model_answers/* must be fully accepted; model_answers.fails/* must fail at least one test case.
16
- bun x exercode # everything under the current directory
17
- bun x exercode courses/foo # everything under courses/foo
18
- bun x exercode --only a_plus --skip gui_ --concurrency 2
16
+ bun x exercode-problem # everything under the current directory
17
+ bun x exercode-problem courses/foo # everything under courses/foo
18
+ bun x exercode-problem --only a_plus --skip gui_ --concurrency 2
19
19
 
20
20
  # Judge one answer directory of the problem in the current directory.
21
- bun x exercode judge model_answers/python
22
- bun x exercode judge model_answers/python '{ "language": "python" }'
21
+ bun x exercode-problem judge model_answers/python
22
+ bun x exercode-problem judge model_answers/python '{ "language": "python" }'
23
23
 
24
24
  # Debug one answer directory of the problem in the current directory.
25
- bun x exercode debug model_answers/python '{ "stdin": "1 2" }'
25
+ bun x exercode-problem debug model_answers/python '{ "stdin": "1 2" }'
26
26
  ```
27
27
 
28
- `judge` and `debug` run a custom `judge.ts` / `debug.ts` when the problem has one, and apply `stdioJudgePreset` / `stdioDebugPreset` otherwise, mirroring the Exercode server. The debug fallback applies only to standard problems: a problem with a custom `judge.ts` needs its own `debug.ts`, and `exercode debug` fails with a message otherwise (the server likewise reports debug as unsupported there).
28
+ `judge` and `debug` run a custom `judge.ts` / `debug.ts` when the problem has one, and apply `stdioJudgePreset` / `stdioDebugPreset` otherwise, mirroring the Exercode server. The debug fallback applies only to standard problems: a problem with a custom `judge.ts` needs its own `debug.ts`, and `exercode-problem debug` fails with a message otherwise (the server likewise reports debug as unsupported there).
29
29
 
30
30
  The all-problem check judges serially by default because time limits are measured in wall-clock time; pass `--concurrency <n>` to parallelize when the checked problems are not timing-sensitive.
31
31
 
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ import '../dist/cli/exercodeProblem.js';
@@ -0,0 +1,9 @@
1
+ "use strict";const e=require("./runSingleHarness.cjs"),t=require("./checkAllProblems.cjs"),n=`Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]
2
+ exercode-problem judge <answerDir> [paramsJson]
3
+ exercode-problem debug <answerDir> [paramsJson]
4
+
5
+ Without a subcommand, judge all model answers of all problems under rootDir
6
+ (default: the current directory). Use \`judge\` or \`debug\` in a problem
7
+ directory to run one answer directory, e.g.:
8
+ exercode-problem debug model_answers/python '{ "stdin": "1 2" }'`;r();async function r(){let r=process.argv.slice(2);if(r[0]===`--help`||r[0]===`-h`){console.info(n);return}try{if(r[0]===`judge`||r[0]===`debug`){if(r.length<2){console.error(n),process.exitCode=1;return}process.argv.splice(2,1),process.exitCode=await e.runSingleHarness(r[0])}else process.exitCode=await t.checkAllProblems(r)}catch(e){console.error(e),process.exitCode=1}}
9
+ //# sourceMappingURL=exercodeProblem.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exercodeProblem.cjs","names":["runSingleHarness","checkAllProblems"],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.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\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\" }'`;\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 {\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"],"mappings":"2FAGM,EAAQ;;;;;;;oEAUT,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,KACE,SAAQ,SAAW,MAAMC,EAAAA,iBAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF"}
@@ -0,0 +1,9 @@
1
+ import{runSingleHarness as e}from"./runSingleHarness.js";import{checkAllProblems as t}from"./checkAllProblems.js";const n=`Usage: exercode-problem [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]
2
+ exercode-problem judge <answerDir> [paramsJson]
3
+ exercode-problem debug <answerDir> [paramsJson]
4
+
5
+ Without a subcommand, judge all model answers of all problems under rootDir
6
+ (default: the current directory). Use \`judge\` or \`debug\` in a problem
7
+ directory to run one answer directory, e.g.:
8
+ exercode-problem debug model_answers/python '{ "stdin": "1 2" }'`;r();async function r(){let r=process.argv.slice(2);if(r[0]===`--help`||r[0]===`-h`){console.info(n);return}try{if(r[0]===`judge`||r[0]===`debug`){if(r.length<2){console.error(n),process.exitCode=1;return}process.argv.splice(2,1),process.exitCode=await e(r[0])}else process.exitCode=await t(r)}catch(e){console.error(e),process.exitCode=1}}
9
+ //# sourceMappingURL=exercodeProblem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exercodeProblem.js","names":[],"sources":["../../src/cli/exercodeProblem.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.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\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\" }'`;\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 {\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"],"mappings":"kHAGA,MAAM,EAAQ;;;;;;;oEAUT,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,KACE,SAAQ,SAAW,MAAM,EAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF"}
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../_virtual/_rolldown/runtime.cjs"),t=require("../helpers/defaultStdioHarness.cjs"),n=require("../helpers/readProblemMarkdownFrontMatter.cjs"),r=require("../helpers/readTestCases.cjs"),i=require("../presets/stdio.cjs");let a=require("node:path");a=e.__toESM(a,1);let o=require("node:child_process");o=e.__toESM(o,1);let s=require("node:fs");s=e.__toESM(s,1);const c=`a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired`;async function l(e){let l=process.cwd(),d=await t.findDefaultStdioHarnessFiles(l);if(d.length>0)return console.error(u(d)),1;let f=e===`judge`?`judge.ts`:`debug.ts`;if(s.default.existsSync(a.default.join(l,f))){let e=o.default.spawnSync(process.execPath,[`run`,f,...process.argv.slice(2)],{cwd:l,stdio:`inherit`});return e.error?(console.error(`failed to run ${f}: ${e.error.message}`),1):e.status??1}return e===`debug`&&s.default.existsSync(a.default.join(l,`judge.ts`))?(console.error(`This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.`),1):e===`judge`&&(await r.readTestCases(a.default.join(l,`test_cases`))).length===0&&!n.judgesWithoutTestCases(await n.readProblemMarkdownFrontMatter(l))?(console.error(c),1):(await(e===`judge`?i.stdioJudgePreset(l):i.stdioDebugPreset(l)),0)}function u(e){let t=e.join(` and `);return`${t} must not be committed because the content is identical to the default stdio harness.
2
2
  A problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,
3
- so delete ${t} and run the problem with \`bun x exercode judge <answerDir>\` or \`bun x exercode debug <answerDir>\`.
3
+ so delete ${t} and run the problem with \`bun x exercode-problem judge <answerDir>\` or \`bun x exercode-problem debug <answerDir>\`.
4
4
  If the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`}exports.MISSING_TEST_CASES_ERROR=c,exports.formatDefaultHarnessError=u,exports.runSingleHarness=l;
5
5
  //# sourceMappingURL=runSingleHarness.cjs.map
@@ -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 judge <answerDir>\\` or \\`bun x exercode 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"],"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,5 +1,5 @@
1
1
  import{findDefaultStdioHarnessFiles as e}from"../helpers/defaultStdioHarness.js";import{judgesWithoutTestCases as t,readProblemMarkdownFrontMatter as n}from"../helpers/readProblemMarkdownFrontMatter.js";import{readTestCases as r}from"../helpers/readTestCases.js";import{stdioDebugPreset as i,stdioJudgePreset as a}from"../presets/stdio.js";import o from"node:path";import s from"node:child_process";import c from"node:fs";const l=`a standard stdio problem (without judge.ts) needs at least one test case under test_cases/, static-analysis rules (e.g. requiredRegExpsInCode), or isManualScoringRequired`;async function u(u){let f=process.cwd(),p=await e(f);if(p.length>0)return console.error(d(p)),1;let m=u===`judge`?`judge.ts`:`debug.ts`;if(c.existsSync(o.join(f,m))){let e=s.spawnSync(process.execPath,[`run`,m,...process.argv.slice(2)],{cwd:f,stdio:`inherit`});return e.error?(console.error(`failed to run ${m}: ${e.error.message}`),1):e.status??1}return u===`debug`&&c.existsSync(o.join(f,`judge.ts`))?(console.error(`This problem has a custom judge.ts but no debug.ts; add a debug.ts to support debugging.`),1):u===`judge`&&(await r(o.join(f,`test_cases`))).length===0&&!t(await n(f))?(console.error(l),1):(await(u===`judge`?a(f):i(f)),0)}function d(e){let t=e.join(` and `);return`${t} must not be committed because the content is identical to the default stdio harness.
2
2
  A problem without judge.ts is automatically judged with stdioJudgePreset and debugged with stdioDebugPreset,
3
- so delete ${t} and run the problem with \`bun x exercode judge <answerDir>\` or \`bun x exercode debug <answerDir>\`.
3
+ so delete ${t} and run the problem with \`bun x exercode-problem judge <answerDir>\` or \`bun x exercode-problem debug <answerDir>\`.
4
4
  If the file intentionally demonstrates the default harness, add an explanatory comment to mark it as custom.`}export{l as MISSING_TEST_CASES_ERROR,d as formatDefaultHarnessError,u as runSingleHarness};
5
5
  //# sourceMappingURL=runSingleHarness.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runSingleHarness.js","names":[],"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 judge <answerDir>\\` or \\`bun x exercode 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,EAAc,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":[],"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,EAAc,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 +1 @@
1
- {"version":3,"file":"stdio.cjs","names":["z","parseArgs","readProblemMarkdownFrontMatter","readTestCases","path","judgeByStaticAnalysis","findEntryPointFile","DecisionCode","findLanguageDefinitionByPath","spawnSyncWithTimeout","snapshotWorkingDirectory","copyTestCaseFileInput","readOutputFiles","compareStdoutAsSpaceSeparatedTokens","fs","isSafeSubmissionOutputPath","cleanWorkingDirectory"],"sources":["../../src/presets/stdio.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { z } from 'zod';\n\nimport { cleanWorkingDirectory, snapshotWorkingDirectory } from '../helpers/cleanWorkingDirectory.js';\nimport { compareStdoutAsSpaceSeparatedTokens } from '../helpers/compareStdoutAsSpaceSeparatedTokens.js';\nimport { copyTestCaseFileInput } from '../helpers/copyTestCaseFileInput.js';\nimport { findEntryPointFile } from '../helpers/findEntryPointFile.js';\nimport { findLanguageDefinitionByPath } from '../helpers/findLanguageDefinitionByPath.js';\nimport { judgeByStaticAnalysis } from '../helpers/judgeByStaticAnalysis.js';\nimport { parseArgs } from '../helpers/parseArgs.js';\nimport { printTestCaseResult } from '../helpers/printTestCaseResult.js';\nimport { isSafeSubmissionOutputPath, readOutputFiles } from '../helpers/readOutputFiles.js';\nimport { makeAccessibleToSandboxUser } from '../helpers/sandboxUser.js';\nimport { readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { spawnSyncWithTimeout } from '../helpers/spawnSyncWithTimeout.js';\nimport { DecisionCode } from '../types/decisionCode.js';\n\nconst BUILD_TIMEOUT_SECONDS = 10;\nconst JUDGE_DEFAULT_TIMEOUT_SECONDS = 2;\nconst DEBUG_DEFAULT_TIMEOUT_SECONDS = 10;\n\nconst MAX_STDOUT_LENGTH = 50_000;\n\nconst judgeParamsSchema = z.object({\n language: z.union([z.string(), z.array(z.string())]).optional(),\n});\n\nconst debugParamsSchema = judgeParamsSchema.extend({\n stdin: z.string().optional(),\n});\n\n/**\n * A preset judge function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `judge.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `judge.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `judge.ts`:\n * ```bash\n * bun x exercode judge model_answers/java\n * ```\n *\n * Run with the optional parameters:\n * ```bash\n * bun x exercode judge model_answers/java '{ \"language\": \"javascript\" }'\n * ```\n */\nexport async function stdioJudgePreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = judgeParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n\n const staticAnalysisTestCaseResult = await judgeByStaticAnalysis(args.cwd, problemMarkdownFrontMatter);\n if (staticAnalysisTestCaseResult) {\n printTestCaseResult({ testCaseId: testCases[0]?.id ?? 'prebuild', ...staticAnalysisTestCaseResult });\n return;\n }\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const cwdSnapshot = await snapshotWorkingDirectory(args.cwd);\n\n if (testCases.length === 0) {\n printTestCaseResult({ testCaseId: 'default', decisionCode: DecisionCode.ACCEPTED });\n }\n\n for (const testCase of testCases) {\n // prepare test case\n if (testCases.shared?.fileInputPath) await copyTestCaseFileInput(testCases.shared.fileInputPath, args.cwd);\n if (testCase.fileInputPath) await copyTestCaseFileInput(testCase.fileInputPath, args.cwd);\n\n // run\n const timeoutSeconds =\n typeof problemMarkdownFrontMatter.timeLimitMs === 'number'\n ? problemMarkdownFrontMatter.timeLimitMs / 1000\n : JUDGE_DEFAULT_TIMEOUT_SECONDS;\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: testCase.input, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n // calculate decision\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n } else if (!compareStdoutAsSpaceSeparatedTokens(spawnResult.stdout, testCase.output ?? '')) {\n decisionCode = DecisionCode.WRONG_ANSWER;\n } else if (testCase.fileOutputPath) {\n const dirents = await fs.promises.readdir(testCase.fileOutputPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents) {\n if (!dirent.isFile()) continue;\n const direntRelativePath = path.relative(testCase.fileOutputPath, dirent.parentPath);\n const expected = await fs.promises.readFile(path.join(dirent.parentPath, dirent.name));\n try {\n const receivedPath = path.join(args.cwd, direntRelativePath, dirent.name);\n // A submission-planted symlink to the expected file itself would otherwise compare equal.\n if (!(await isSafeSubmissionOutputPath(args.cwd, receivedPath))) throw new Error('unsafe output path');\n const received = await fs.promises.readFile(receivedPath);\n if (received.compare(expected) !== 0) decisionCode = DecisionCode.WRONG_ANSWER;\n } catch (error) {\n console.error(error);\n decisionCode = DecisionCode.WRONG_ANSWER;\n }\n }\n }\n\n printTestCaseResult({\n testCaseId: testCase.id,\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: testCase.input,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n\n // clean up\n await cleanWorkingDirectory(args.cwd, cwdSnapshot);\n\n if (decisionCode !== DecisionCode.ACCEPTED) break;\n }\n}\n\n/**\n * A preset debug function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `debug.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `debug.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `debug.ts`:\n * ```bash\n * bun x exercode debug model_answers/java '{ \"stdin\": \"1 2\" }'\n * ```\n */\nexport async function stdioDebugPreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = debugParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n {\n const timeoutSeconds = Math.max(\n DEBUG_DEFAULT_TIMEOUT_SECONDS,\n (problemMarkdownFrontMatter.timeLimitMs ?? 0) / 1000\n );\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: params.stdin, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n }\n\n printTestCaseResult({\n testCaseId: 'debug',\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: params.stdin,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n }\n}\n"],"mappings":"i5BAoBA,MAIM,EAAoB,IAEpB,EAAoBA,EAAAA,EAAE,OAAO,CACjC,SAAUA,EAAAA,EAAE,MAAM,CAACA,EAAAA,EAAE,OAAO,EAAGA,EAAAA,EAAE,MAAMA,EAAAA,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC,EAEK,EAAoB,EAAkB,OAAO,CACjD,MAAOA,EAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,CAC7B,CAAC,EAoBD,eAAsB,EAAiB,EAAmC,CACxE,IAAM,EAAOC,EAAAA,UAAU,QAAQ,IAAI,EACnC,GAAI,CAAC,EAAK,IAAK,MAAU,MAAM,uBAAuB,EACtD,IAAM,EAAS,EAAkB,MAAM,EAAK,MAAM,EAGlD,EAAA,4BAA4B,EAAK,GAAG,EAEpC,IAAM,EAA6B,MAAMC,EAAAA,+BAA+B,CAAU,EAC5E,EAAY,MAAMC,EAAAA,cAAcC,EAAAA,QAAK,KAAK,EAAY,YAAY,CAAC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QAAQ,CAAY,EAEjD,EAAcE,EAAAA,qBAClB,EAAQ,GACR,EAAQ,MAAM,CAAC,EACf,CAAE,IAAK,EAAK,IAAK,SAAU,OAAQ,MAAO,EAAO,MAAO,KAAI,EAC5D,CACF,EAEM,EAAc,MAAMG,EAAAA,gBAAgB,EAAK,IAAK,EAA2B,yBAA2B,CAAC,CAAC,EAExG,EAA6BL,EAAAA,aAAa,SAE1C,EAAY,SAAW,EAEhB,EAAY,YAAc,EACnC,EAAeA,EAAAA,aAAa,oBACnB,EAAY,aAAe,EAA2B,iBAAmB,KAClF,EAAeA,EAAAA,aAAa,sBACnB,EAAY,OAAO,OAAS,GAAqB,EAAY,OAAO,OAAS,EACtF,EAAeA,EAAAA,aAAa,2BACnB,EAAY,QAAU,EAA2B,yBAAyB,QAAU,KAC7F,EAAeA,EAAAA,aAAa,oCAR5B,EAAeA,EAAAA,aAAa,cAW9B,EAAA,oBAAoB,CAClB,WAAY,QACZ,eACA,WAAY,EAAY,QAAU,IAAA,GAClC,MAAO,EAAO,MACd,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,YAAa,EAAY,YACzB,YAAa,EAAY,YACzB,YAAa,EAAY,OAAS,EAAI,EAAc,IAAA,EACtD,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"stdio.cjs","names":["z","parseArgs","readProblemMarkdownFrontMatter","readTestCases","path","judgeByStaticAnalysis","findEntryPointFile","DecisionCode","findLanguageDefinitionByPath","spawnSyncWithTimeout","snapshotWorkingDirectory","copyTestCaseFileInput","readOutputFiles","compareStdoutAsSpaceSeparatedTokens","fs","isSafeSubmissionOutputPath","cleanWorkingDirectory"],"sources":["../../src/presets/stdio.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { z } from 'zod';\n\nimport { cleanWorkingDirectory, snapshotWorkingDirectory } from '../helpers/cleanWorkingDirectory.js';\nimport { compareStdoutAsSpaceSeparatedTokens } from '../helpers/compareStdoutAsSpaceSeparatedTokens.js';\nimport { copyTestCaseFileInput } from '../helpers/copyTestCaseFileInput.js';\nimport { findEntryPointFile } from '../helpers/findEntryPointFile.js';\nimport { findLanguageDefinitionByPath } from '../helpers/findLanguageDefinitionByPath.js';\nimport { judgeByStaticAnalysis } from '../helpers/judgeByStaticAnalysis.js';\nimport { parseArgs } from '../helpers/parseArgs.js';\nimport { printTestCaseResult } from '../helpers/printTestCaseResult.js';\nimport { isSafeSubmissionOutputPath, readOutputFiles } from '../helpers/readOutputFiles.js';\nimport { makeAccessibleToSandboxUser } from '../helpers/sandboxUser.js';\nimport { readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { spawnSyncWithTimeout } from '../helpers/spawnSyncWithTimeout.js';\nimport { DecisionCode } from '../types/decisionCode.js';\n\nconst BUILD_TIMEOUT_SECONDS = 10;\nconst JUDGE_DEFAULT_TIMEOUT_SECONDS = 2;\nconst DEBUG_DEFAULT_TIMEOUT_SECONDS = 10;\n\nconst MAX_STDOUT_LENGTH = 50_000;\n\nconst judgeParamsSchema = z.object({\n language: z.union([z.string(), z.array(z.string())]).optional(),\n});\n\nconst debugParamsSchema = judgeParamsSchema.extend({\n stdin: z.string().optional(),\n});\n\n/**\n * A preset judge function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `judge.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `judge.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `judge.ts`:\n * ```bash\n * bun x exercode-problem judge model_answers/java\n * ```\n *\n * Run with the optional parameters:\n * ```bash\n * bun x exercode-problem judge model_answers/java '{ \"language\": \"javascript\" }'\n * ```\n */\nexport async function stdioJudgePreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = judgeParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n\n const staticAnalysisTestCaseResult = await judgeByStaticAnalysis(args.cwd, problemMarkdownFrontMatter);\n if (staticAnalysisTestCaseResult) {\n printTestCaseResult({ testCaseId: testCases[0]?.id ?? 'prebuild', ...staticAnalysisTestCaseResult });\n return;\n }\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const cwdSnapshot = await snapshotWorkingDirectory(args.cwd);\n\n if (testCases.length === 0) {\n printTestCaseResult({ testCaseId: 'default', decisionCode: DecisionCode.ACCEPTED });\n }\n\n for (const testCase of testCases) {\n // prepare test case\n if (testCases.shared?.fileInputPath) await copyTestCaseFileInput(testCases.shared.fileInputPath, args.cwd);\n if (testCase.fileInputPath) await copyTestCaseFileInput(testCase.fileInputPath, args.cwd);\n\n // run\n const timeoutSeconds =\n typeof problemMarkdownFrontMatter.timeLimitMs === 'number'\n ? problemMarkdownFrontMatter.timeLimitMs / 1000\n : JUDGE_DEFAULT_TIMEOUT_SECONDS;\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: testCase.input, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n // calculate decision\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n } else if (!compareStdoutAsSpaceSeparatedTokens(spawnResult.stdout, testCase.output ?? '')) {\n decisionCode = DecisionCode.WRONG_ANSWER;\n } else if (testCase.fileOutputPath) {\n const dirents = await fs.promises.readdir(testCase.fileOutputPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents) {\n if (!dirent.isFile()) continue;\n const direntRelativePath = path.relative(testCase.fileOutputPath, dirent.parentPath);\n const expected = await fs.promises.readFile(path.join(dirent.parentPath, dirent.name));\n try {\n const receivedPath = path.join(args.cwd, direntRelativePath, dirent.name);\n // A submission-planted symlink to the expected file itself would otherwise compare equal.\n if (!(await isSafeSubmissionOutputPath(args.cwd, receivedPath))) throw new Error('unsafe output path');\n const received = await fs.promises.readFile(receivedPath);\n if (received.compare(expected) !== 0) decisionCode = DecisionCode.WRONG_ANSWER;\n } catch (error) {\n console.error(error);\n decisionCode = DecisionCode.WRONG_ANSWER;\n }\n }\n }\n\n printTestCaseResult({\n testCaseId: testCase.id,\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: testCase.input,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n\n // clean up\n await cleanWorkingDirectory(args.cwd, cwdSnapshot);\n\n if (decisionCode !== DecisionCode.ACCEPTED) break;\n }\n}\n\n/**\n * A preset debug function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `debug.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `debug.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `debug.ts`:\n * ```bash\n * bun x exercode-problem debug model_answers/java '{ \"stdin\": \"1 2\" }'\n * ```\n */\nexport async function stdioDebugPreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = debugParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n {\n const timeoutSeconds = Math.max(\n DEBUG_DEFAULT_TIMEOUT_SECONDS,\n (problemMarkdownFrontMatter.timeLimitMs ?? 0) / 1000\n );\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: params.stdin, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n }\n\n printTestCaseResult({\n testCaseId: 'debug',\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: params.stdin,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n }\n}\n"],"mappings":"i5BAoBA,MAIM,EA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C,MAAO,EAAO,MACd,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,YAAa,EAAY,YACzB,YAAa,EAAY,YACzB,YAAa,EAAY,OAAS,EAAI,EAAc,IAAA,EACtD,CAAC,CACH,CACF"}
@@ -8,12 +8,12 @@
8
8
  * @example
9
9
  * Run in a problem directory without `judge.ts`:
10
10
  * ```bash
11
- * bun x exercode judge model_answers/java
11
+ * bun x exercode-problem judge model_answers/java
12
12
  * ```
13
13
  *
14
14
  * Run with the optional parameters:
15
15
  * ```bash
16
- * bun x exercode judge model_answers/java '{ "language": "javascript" }'
16
+ * bun x exercode-problem judge model_answers/java '{ "language": "javascript" }'
17
17
  * ```
18
18
  */
19
19
  export declare function stdioJudgePreset(problemDir: string): Promise<void>;
@@ -27,7 +27,7 @@ export declare function stdioJudgePreset(problemDir: string): Promise<void>;
27
27
  * @example
28
28
  * Run in a problem directory without `debug.ts`:
29
29
  * ```bash
30
- * bun x exercode debug model_answers/java '{ "stdin": "1 2" }'
30
+ * bun x exercode-problem debug model_answers/java '{ "stdin": "1 2" }'
31
31
  * ```
32
32
  */
33
33
  export declare function stdioDebugPreset(problemDir: string): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"stdio.js","names":[],"sources":["../../src/presets/stdio.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { z } from 'zod';\n\nimport { cleanWorkingDirectory, snapshotWorkingDirectory } from '../helpers/cleanWorkingDirectory.js';\nimport { compareStdoutAsSpaceSeparatedTokens } from '../helpers/compareStdoutAsSpaceSeparatedTokens.js';\nimport { copyTestCaseFileInput } from '../helpers/copyTestCaseFileInput.js';\nimport { findEntryPointFile } from '../helpers/findEntryPointFile.js';\nimport { findLanguageDefinitionByPath } from '../helpers/findLanguageDefinitionByPath.js';\nimport { judgeByStaticAnalysis } from '../helpers/judgeByStaticAnalysis.js';\nimport { parseArgs } from '../helpers/parseArgs.js';\nimport { printTestCaseResult } from '../helpers/printTestCaseResult.js';\nimport { isSafeSubmissionOutputPath, readOutputFiles } from '../helpers/readOutputFiles.js';\nimport { makeAccessibleToSandboxUser } from '../helpers/sandboxUser.js';\nimport { readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { spawnSyncWithTimeout } from '../helpers/spawnSyncWithTimeout.js';\nimport { DecisionCode } from '../types/decisionCode.js';\n\nconst BUILD_TIMEOUT_SECONDS = 10;\nconst JUDGE_DEFAULT_TIMEOUT_SECONDS = 2;\nconst DEBUG_DEFAULT_TIMEOUT_SECONDS = 10;\n\nconst MAX_STDOUT_LENGTH = 50_000;\n\nconst judgeParamsSchema = z.object({\n language: z.union([z.string(), z.array(z.string())]).optional(),\n});\n\nconst debugParamsSchema = judgeParamsSchema.extend({\n stdin: z.string().optional(),\n});\n\n/**\n * A preset judge function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `judge.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `judge.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `judge.ts`:\n * ```bash\n * bun x exercode judge model_answers/java\n * ```\n *\n * Run with the optional parameters:\n * ```bash\n * bun x exercode judge model_answers/java '{ \"language\": \"javascript\" }'\n * ```\n */\nexport async function stdioJudgePreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = judgeParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n\n const staticAnalysisTestCaseResult = await judgeByStaticAnalysis(args.cwd, problemMarkdownFrontMatter);\n if (staticAnalysisTestCaseResult) {\n printTestCaseResult({ testCaseId: testCases[0]?.id ?? 'prebuild', ...staticAnalysisTestCaseResult });\n return;\n }\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const cwdSnapshot = await snapshotWorkingDirectory(args.cwd);\n\n if (testCases.length === 0) {\n printTestCaseResult({ testCaseId: 'default', decisionCode: DecisionCode.ACCEPTED });\n }\n\n for (const testCase of testCases) {\n // prepare test case\n if (testCases.shared?.fileInputPath) await copyTestCaseFileInput(testCases.shared.fileInputPath, args.cwd);\n if (testCase.fileInputPath) await copyTestCaseFileInput(testCase.fileInputPath, args.cwd);\n\n // run\n const timeoutSeconds =\n typeof problemMarkdownFrontMatter.timeLimitMs === 'number'\n ? problemMarkdownFrontMatter.timeLimitMs / 1000\n : JUDGE_DEFAULT_TIMEOUT_SECONDS;\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: testCase.input, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n // calculate decision\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n } else if (!compareStdoutAsSpaceSeparatedTokens(spawnResult.stdout, testCase.output ?? '')) {\n decisionCode = DecisionCode.WRONG_ANSWER;\n } else if (testCase.fileOutputPath) {\n const dirents = await fs.promises.readdir(testCase.fileOutputPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents) {\n if (!dirent.isFile()) continue;\n const direntRelativePath = path.relative(testCase.fileOutputPath, dirent.parentPath);\n const expected = await fs.promises.readFile(path.join(dirent.parentPath, dirent.name));\n try {\n const receivedPath = path.join(args.cwd, direntRelativePath, dirent.name);\n // A submission-planted symlink to the expected file itself would otherwise compare equal.\n if (!(await isSafeSubmissionOutputPath(args.cwd, receivedPath))) throw new Error('unsafe output path');\n const received = await fs.promises.readFile(receivedPath);\n if (received.compare(expected) !== 0) decisionCode = DecisionCode.WRONG_ANSWER;\n } catch (error) {\n console.error(error);\n decisionCode = DecisionCode.WRONG_ANSWER;\n }\n }\n }\n\n printTestCaseResult({\n testCaseId: testCase.id,\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: testCase.input,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n\n // clean up\n await cleanWorkingDirectory(args.cwd, cwdSnapshot);\n\n if (decisionCode !== DecisionCode.ACCEPTED) break;\n }\n}\n\n/**\n * A preset debug function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `debug.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `debug.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `debug.ts`:\n * ```bash\n * bun x exercode debug model_answers/java '{ \"stdin\": \"1 2\" }'\n * ```\n */\nexport async function stdioDebugPreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = debugParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n {\n const timeoutSeconds = Math.max(\n DEBUG_DEFAULT_TIMEOUT_SECONDS,\n (problemMarkdownFrontMatter.timeLimitMs ?? 0) / 1000\n );\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: params.stdin, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n }\n\n printTestCaseResult({\n testCaseId: 'debug',\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: params.stdin,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n }\n}\n"],"mappings":"kpCAoBA,MAIM,EAAoB,IAEpB,EAAoB,EAAE,OAAO,CACjC,SAAU,EAAE,MAAM,CAAC,EAAE,OAAO,EAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC,EAEK,EAAoB,EAAkB,OAAO,CACjD,MAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAC7B,CAAC,EAoBD,eAAsB,EAAiB,EAAmC,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,EAAe,EAAa,sBACnB,EAAY,OAAO,OAAS,GAAqB,EAAY,OAAO,OAAS,EACtF,EAAe,EAAa,2BACnB,EAAY,QAAU,EAA2B,yBAAyB,QAAU,KAC7F,EAAe,EAAa,oCAR5B,EAAe,EAAa,cAW9B,EAAoB,CAClB,WAAY,QACZ,eACA,WAAY,EAAY,QAAU,IAAA,GAClC,MAAO,EAAO,MACd,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,OAAQ,EAAY,OAAO,MAAM,EAAG,CAAiB,GAAK,IAAA,GAC1D,YAAa,EAAY,YACzB,YAAa,EAAY,YACzB,YAAa,EAAY,OAAS,EAAI,EAAc,IAAA,EACtD,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"stdio.js","names":[],"sources":["../../src/presets/stdio.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { z } from 'zod';\n\nimport { cleanWorkingDirectory, snapshotWorkingDirectory } from '../helpers/cleanWorkingDirectory.js';\nimport { compareStdoutAsSpaceSeparatedTokens } from '../helpers/compareStdoutAsSpaceSeparatedTokens.js';\nimport { copyTestCaseFileInput } from '../helpers/copyTestCaseFileInput.js';\nimport { findEntryPointFile } from '../helpers/findEntryPointFile.js';\nimport { findLanguageDefinitionByPath } from '../helpers/findLanguageDefinitionByPath.js';\nimport { judgeByStaticAnalysis } from '../helpers/judgeByStaticAnalysis.js';\nimport { parseArgs } from '../helpers/parseArgs.js';\nimport { printTestCaseResult } from '../helpers/printTestCaseResult.js';\nimport { isSafeSubmissionOutputPath, readOutputFiles } from '../helpers/readOutputFiles.js';\nimport { makeAccessibleToSandboxUser } from '../helpers/sandboxUser.js';\nimport { readProblemMarkdownFrontMatter } from '../helpers/readProblemMarkdownFrontMatter.js';\nimport { readTestCases } from '../helpers/readTestCases.js';\nimport { spawnSyncWithTimeout } from '../helpers/spawnSyncWithTimeout.js';\nimport { DecisionCode } from '../types/decisionCode.js';\n\nconst BUILD_TIMEOUT_SECONDS = 10;\nconst JUDGE_DEFAULT_TIMEOUT_SECONDS = 2;\nconst DEBUG_DEFAULT_TIMEOUT_SECONDS = 10;\n\nconst MAX_STDOUT_LENGTH = 50_000;\n\nconst judgeParamsSchema = z.object({\n language: z.union([z.string(), z.array(z.string())]).optional(),\n});\n\nconst debugParamsSchema = judgeParamsSchema.extend({\n stdin: z.string().optional(),\n});\n\n/**\n * A preset judge function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `judge.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `judge.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `judge.ts`:\n * ```bash\n * bun x exercode-problem judge model_answers/java\n * ```\n *\n * Run with the optional parameters:\n * ```bash\n * bun x exercode-problem judge model_answers/java '{ \"language\": \"javascript\" }'\n * ```\n */\nexport async function stdioJudgePreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = judgeParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n const testCases = await readTestCases(path.join(problemDir, 'test_cases'));\n\n const staticAnalysisTestCaseResult = await judgeByStaticAnalysis(args.cwd, problemMarkdownFrontMatter);\n if (staticAnalysisTestCaseResult) {\n printTestCaseResult({ testCaseId: testCases[0]?.id ?? 'prebuild', ...staticAnalysisTestCaseResult });\n return;\n }\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: testCases[0]?.id ?? 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const cwdSnapshot = await snapshotWorkingDirectory(args.cwd);\n\n if (testCases.length === 0) {\n printTestCaseResult({ testCaseId: 'default', decisionCode: DecisionCode.ACCEPTED });\n }\n\n for (const testCase of testCases) {\n // prepare test case\n if (testCases.shared?.fileInputPath) await copyTestCaseFileInput(testCases.shared.fileInputPath, args.cwd);\n if (testCase.fileInputPath) await copyTestCaseFileInput(testCase.fileInputPath, args.cwd);\n\n // run\n const timeoutSeconds =\n typeof problemMarkdownFrontMatter.timeLimitMs === 'number'\n ? problemMarkdownFrontMatter.timeLimitMs / 1000\n : JUDGE_DEFAULT_TIMEOUT_SECONDS;\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: testCase.input, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n // calculate decision\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n } else if (!compareStdoutAsSpaceSeparatedTokens(spawnResult.stdout, testCase.output ?? '')) {\n decisionCode = DecisionCode.WRONG_ANSWER;\n } else if (testCase.fileOutputPath) {\n const dirents = await fs.promises.readdir(testCase.fileOutputPath, { withFileTypes: true, recursive: true });\n for (const dirent of dirents) {\n if (!dirent.isFile()) continue;\n const direntRelativePath = path.relative(testCase.fileOutputPath, dirent.parentPath);\n const expected = await fs.promises.readFile(path.join(dirent.parentPath, dirent.name));\n try {\n const receivedPath = path.join(args.cwd, direntRelativePath, dirent.name);\n // A submission-planted symlink to the expected file itself would otherwise compare equal.\n if (!(await isSafeSubmissionOutputPath(args.cwd, receivedPath))) throw new Error('unsafe output path');\n const received = await fs.promises.readFile(receivedPath);\n if (received.compare(expected) !== 0) decisionCode = DecisionCode.WRONG_ANSWER;\n } catch (error) {\n console.error(error);\n decisionCode = DecisionCode.WRONG_ANSWER;\n }\n }\n }\n\n printTestCaseResult({\n testCaseId: testCase.id,\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: testCase.input,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n\n // clean up\n await cleanWorkingDirectory(args.cwd, cwdSnapshot);\n\n if (decisionCode !== DecisionCode.ACCEPTED) break;\n }\n}\n\n/**\n * A preset debug function using stdin and stdout as test cases.\n *\n * A standard stdio problem must NOT commit a `debug.ts` that only calls this preset: the Exercode\n * server applies this preset automatically when `debug.ts` is absent, and committed copies would\n * drift from the server's defaults.\n *\n * @example\n * Run in a problem directory without `debug.ts`:\n * ```bash\n * bun x exercode-problem debug model_answers/java '{ \"stdin\": \"1 2\" }'\n * ```\n */\nexport async function stdioDebugPreset(problemDir: string): Promise<void> {\n const args = parseArgs(process.argv);\n if (!args.cwd) throw new Error('cwd argument required');\n const params = debugParamsSchema.parse(args.params);\n\n // The sandboxed submission must read its sources and write build/run outputs in its directory.\n makeAccessibleToSandboxUser(args.cwd);\n\n const problemMarkdownFrontMatter = await readProblemMarkdownFrontMatter(problemDir);\n\n const originalMainFilePath = await findEntryPointFile(args.cwd, params.language);\n if (!originalMainFilePath) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.MISSING_REQUIRED_SUBMISSION_FILE_ERROR,\n stderr: `main file not found${params.language ? `: language: ${params.language}` : ''}`,\n });\n return;\n }\n\n const languageDefinition = findLanguageDefinitionByPath(originalMainFilePath);\n if (!languageDefinition) {\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.WRONG_ANSWER,\n stderr: 'unsupported language',\n });\n return;\n }\n\n // `CI` changes affects Chainlit. `FORCE_COLOR` affects Bun.\n const env = { ...process.env, CI: '', FORCE_COLOR: '0' };\n\n let prebuiltMainFilePath: string | undefined;\n\n if (languageDefinition.prebuild) {\n try {\n await languageDefinition.prebuild(args.cwd);\n prebuiltMainFilePath = await findEntryPointFile(args.cwd, params.language);\n } catch (error) {\n console.error('prebuild error', error);\n\n printTestCaseResult({\n testCaseId: 'prebuild',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n const mainFilePath = prebuiltMainFilePath ?? originalMainFilePath;\n\n if (languageDefinition.buildCommand) {\n try {\n const buildCommand = languageDefinition.buildCommand(mainFilePath);\n\n const buildSpawnResult = spawnSyncWithTimeout(\n buildCommand[0],\n buildCommand.slice(1),\n { cwd: args.cwd, encoding: 'utf8', env },\n BUILD_TIMEOUT_SECONDS\n );\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (buildSpawnResult.status !== 0) {\n decisionCode = DecisionCode.BUILD_ERROR;\n } else if (buildSpawnResult.timeSeconds > BUILD_TIMEOUT_SECONDS) {\n decisionCode = DecisionCode.BUILD_TIME_LIMIT_EXCEEDED;\n } else if (\n buildSpawnResult.stdout.length > MAX_STDOUT_LENGTH ||\n buildSpawnResult.stderr.length > MAX_STDOUT_LENGTH\n ) {\n decisionCode = DecisionCode.BUILD_OUTPUT_SIZE_LIMIT_EXCEEDED;\n }\n\n if (decisionCode !== DecisionCode.ACCEPTED) {\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode,\n exitStatus: buildSpawnResult.status ?? undefined,\n stdout: buildSpawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: buildSpawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: buildSpawnResult.timeSeconds,\n memoryBytes: buildSpawnResult.memoryBytes,\n });\n return;\n }\n } catch (error) {\n console.error('build error', error);\n\n printTestCaseResult({\n testCaseId: 'build',\n decisionCode: DecisionCode.BUILD_ERROR,\n stderr: error instanceof Error ? error.message : String(error),\n });\n return;\n }\n }\n\n {\n const timeoutSeconds = Math.max(\n DEBUG_DEFAULT_TIMEOUT_SECONDS,\n (problemMarkdownFrontMatter.timeLimitMs ?? 0) / 1000\n );\n\n const command = languageDefinition.command(mainFilePath);\n\n const spawnResult = spawnSyncWithTimeout(\n command[0],\n command.slice(1),\n { cwd: args.cwd, encoding: 'utf8', input: params.stdin, env },\n timeoutSeconds\n );\n\n const outputFiles = await readOutputFiles(args.cwd, problemMarkdownFrontMatter.requiredOutputFilePaths ?? []);\n\n let decisionCode: DecisionCode = DecisionCode.ACCEPTED;\n\n if (spawnResult.status !== 0) {\n decisionCode = DecisionCode.RUNTIME_ERROR;\n } else if (spawnResult.timeSeconds > timeoutSeconds) {\n decisionCode = DecisionCode.TIME_LIMIT_EXCEEDED;\n } else if (spawnResult.memoryBytes > (problemMarkdownFrontMatter.memoryLimitByte ?? Number.POSITIVE_INFINITY)) {\n decisionCode = DecisionCode.MEMORY_LIMIT_EXCEEDED;\n } else if (spawnResult.stdout.length > MAX_STDOUT_LENGTH || spawnResult.stderr.length > MAX_STDOUT_LENGTH) {\n decisionCode = DecisionCode.OUTPUT_SIZE_LIMIT_EXCEEDED;\n } else if (outputFiles.length < (problemMarkdownFrontMatter.requiredOutputFilePaths?.length ?? 0)) {\n decisionCode = DecisionCode.MISSING_REQUIRED_OUTPUT_FILE_ERROR;\n }\n\n printTestCaseResult({\n testCaseId: 'debug',\n decisionCode,\n exitStatus: spawnResult.status ?? undefined,\n stdin: params.stdin,\n stdout: spawnResult.stdout.slice(0, MAX_STDOUT_LENGTH) || undefined,\n stderr: spawnResult.stderr.slice(0, MAX_STDOUT_LENGTH) || undefined,\n timeSeconds: spawnResult.timeSeconds,\n memoryBytes: spawnResult.memoryBytes,\n outputFiles: outputFiles.length > 0 ? outputFiles : undefined,\n });\n }\n}\n"],"mappings":"kpCAoBA,MAIM,EAAoB,IAEpB,EAAoB,EAAE,OAAO,CACjC,SAAU,EAAE,MAAM,CAAC,EAAE,OAAO,EAAG,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAChE,CAAC,EAEK,EAAoB,EAAkB,OAAO,CACjD,MAAO,EAAE,OAAO,CAAC,CAAC,SAAS,CAC7B,CAAC,EAoBD,eAAsB,EAAiB,EAAmC,CACxE,IAAM,EAAO,EAAU,QAAQ,IAAI,EACnC,GAAI,CAAC,EAAK,IAAK,MAAU,MAAM,uBAAuB,EACtD,IAAM,EAAS,EAAkB,MAAM,EAAK,MAAM,EAGlD,EAA4B,EAAK,GAAG,EAEpC,IAAM,EAA6B,MAAM,EAA+B,CAAU,EAC5E,EAAY,MAAM,EAAc,EAAK,KAAK,EAAY,YAAY,CAAC,EAEnE,EAA+B,MAAM,EAAsB,EAAK,IAAK,CAA0B,EACrG,GAAI,EAA8B,CAChC,EAAoB,CAAE,WAAY,EA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K,IAAA,GAC1D,YAAa,EAAY,YACzB,YAAa,EAAY,YACzB,YAAa,EAAY,OAAS,EAAI,EAAc,IAAA,EACtD,CAAC,CACH,CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exercode/problem-utils",
3
- "version": "1.20.0",
3
+ "version": "2.0.1",
4
4
  "description": ":100: A set of utilities for judging programs on Exercode (https://exercode.willbooster.com/).",
5
5
  "keywords": [
6
6
  "exercode",
@@ -30,7 +30,7 @@
30
30
  "module": "dist/index.js",
31
31
  "types": "dist/index.d.ts",
32
32
  "bin": {
33
- "exercode": "bin/exercode.mjs"
33
+ "exercode-problem": "bin/exercode-problem.mjs"
34
34
  },
35
35
  "files": [
36
36
  "bin/",
@@ -53,11 +53,11 @@
53
53
  },
54
54
  "prettier": "@willbooster/prettier-config",
55
55
  "dependencies": {
56
- "@ai-sdk/amazon-bedrock": "5.0.50",
57
- "@ai-sdk/google": "4.0.39",
58
- "@ai-sdk/openai": "4.0.36",
59
- "@ai-sdk/xai": "4.0.33",
60
- "ai": "7.0.58",
56
+ "@ai-sdk/amazon-bedrock": "5.0.57",
57
+ "@ai-sdk/google": "4.0.44",
58
+ "@ai-sdk/openai": "4.0.42",
59
+ "@ai-sdk/xai": "4.0.39",
60
+ "ai": "7.0.66",
61
61
  "front-matter": "4.0.2",
62
62
  "zod": "4.4.3"
63
63
  },
@@ -71,12 +71,12 @@
71
71
  "@willbooster/oxfmt-config": "1.2.2",
72
72
  "@willbooster/oxlint-config": "1.4.8",
73
73
  "@willbooster/prettier-config": "10.4.0",
74
- "@willbooster/wb": "21.7.2",
74
+ "@willbooster/wb": "21.7.3",
75
75
  "build-ts": "21.0.7",
76
76
  "conventional-changelog-conventionalcommits": "10.2.1",
77
77
  "lefthook": "2.1.10",
78
- "oxfmt": "0.62.0",
79
- "oxlint": "1.77.0",
78
+ "oxfmt": "0.63.0",
79
+ "oxlint": "1.78.0",
80
80
  "oxlint-tsgolint": "7.0.2001",
81
81
  "prettier": "3.9.6",
82
82
  "prettier-plugin-java": "2.10.3",
package/bin/exercode.mjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env bun
2
- import '../dist/cli/exercode.js';
@@ -1,9 +0,0 @@
1
- "use strict";const e=require("./runSingleHarness.cjs"),t=require("./checkAllProblems.cjs"),n=`Usage: exercode [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]
2
- exercode judge <answerDir> [paramsJson]
3
- exercode debug <answerDir> [paramsJson]
4
-
5
- Without a subcommand, judge all model answers of all problems under rootDir
6
- (default: the current directory). Use \`judge\` or \`debug\` in a problem
7
- directory to run one answer directory, e.g.:
8
- exercode debug model_answers/python '{ "stdin": "1 2" }'`;r();async function r(){let r=process.argv.slice(2);if(r[0]===`--help`||r[0]===`-h`){console.info(n);return}try{if(r[0]===`judge`||r[0]===`debug`){if(r.length<2){console.error(n),process.exitCode=1;return}process.argv.splice(2,1),process.exitCode=await e.runSingleHarness(r[0])}else process.exitCode=await t.checkAllProblems(r)}catch(e){console.error(e),process.exitCode=1}}
9
- //# sourceMappingURL=exercode.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exercode.cjs","names":["runSingleHarness","checkAllProblems"],"sources":["../../src/cli/exercode.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\n\nconst usage = `Usage: exercode [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode judge <answerDir> [paramsJson]\n exercode debug <answerDir> [paramsJson]\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 debug model_answers/python '{ \"stdin\": \"1 2\" }'`;\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 {\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"],"mappings":"2FAGM,EAAQ;;;;;;;4DAUT,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,KACE,SAAQ,SAAW,MAAMC,EAAAA,iBAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF"}
@@ -1,9 +0,0 @@
1
- import{runSingleHarness as e}from"./runSingleHarness.js";import{checkAllProblems as t}from"./checkAllProblems.js";const n=`Usage: exercode [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]
2
- exercode judge <answerDir> [paramsJson]
3
- exercode debug <answerDir> [paramsJson]
4
-
5
- Without a subcommand, judge all model answers of all problems under rootDir
6
- (default: the current directory). Use \`judge\` or \`debug\` in a problem
7
- directory to run one answer directory, e.g.:
8
- exercode debug model_answers/python '{ "stdin": "1 2" }'`;r();async function r(){let r=process.argv.slice(2);if(r[0]===`--help`||r[0]===`-h`){console.info(n);return}try{if(r[0]===`judge`||r[0]===`debug`){if(r.length<2){console.error(n),process.exitCode=1;return}process.argv.splice(2,1),process.exitCode=await e(r[0])}else process.exitCode=await t(r)}catch(e){console.error(e),process.exitCode=1}}
9
- //# sourceMappingURL=exercode.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"exercode.js","names":[],"sources":["../../src/cli/exercode.ts"],"sourcesContent":["import { checkAllProblems } from './checkAllProblems.js';\nimport { runSingleHarness } from './runSingleHarness.js';\n\nconst usage = `Usage: exercode [rootDir] [--only <substring>]... [--skip <substring>]... [--concurrency <n>]\n exercode judge <answerDir> [paramsJson]\n exercode debug <answerDir> [paramsJson]\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 debug model_answers/python '{ \"stdin\": \"1 2\" }'`;\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 {\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"],"mappings":"kHAGA,MAAM,EAAQ;;;;;;;4DAUT,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,KACE,SAAQ,SAAW,MAAM,EAAiB,CAAI,CAElD,OAAS,EAAO,CAEd,QAAQ,MAAM,CAAK,EACnB,QAAQ,SAAW,CACrB,CACF"}