@tangle-network/agent-bench 0.3.7 → 0.4.0
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/CHANGELOG.md +11 -0
- package/HARNESS.md +43 -0
- package/README.md +7 -0
- package/dist/adapters.js +23 -23
- package/dist/benchmarks/_harness.d.ts +1 -1
- package/dist/benchmarks/_harness.js +1 -1
- package/dist/benchmarks/aec-bench.js +2 -2
- package/dist/benchmarks/agentbench.js +2 -2
- package/dist/benchmarks/appworld.js +2 -2
- package/dist/benchmarks/bfcl.js +2 -2
- package/dist/benchmarks/commit0.js +2 -2
- package/dist/benchmarks/crag.js +2 -2
- package/dist/benchmarks/dabstep.js +2 -2
- package/dist/benchmarks/enterpriseops-gym.js +2 -2
- package/dist/benchmarks/finresearchbench.js +2 -2
- package/dist/benchmarks/nomiracl.js +2 -2
- package/dist/benchmarks/open-rag-bench.js +2 -2
- package/dist/benchmarks/programbench.js +2 -2
- package/dist/benchmarks/ragbench.js +2 -2
- package/dist/benchmarks/swe-bench.js +2 -2
- package/dist/benchmarks/t2-ragbench.js +2 -2
- package/dist/benchmarks/tau-bench-shared.js +2 -2
- package/dist/benchmarks/tau2-bench.js +3 -3
- package/dist/benchmarks/tau3-banking.js +3 -3
- package/dist/benchmarks/terminal-bench.js +2 -2
- package/dist/benchmarks/toollm.js +2 -2
- package/dist/benchmarks/webarena-verified.js +2 -2
- package/dist/{chunk-CKUVRZ2T.js → chunk-3U5TXJZS.js} +2 -2
- package/dist/{chunk-YCGY7UIZ.js → chunk-7GRVHU22.js} +2 -2
- package/dist/{chunk-Z7ML6L77.js → chunk-HWST3SED.js} +2 -2
- package/dist/{chunk-SYDW647C.js → chunk-IA2FBTWC.js} +2 -2
- package/dist/{chunk-R67DFVLO.js → chunk-IFVINJ4B.js} +2 -2
- package/dist/{chunk-R36V2VP7.js → chunk-IZ5M6OAC.js} +2 -2
- package/dist/{chunk-ODT47UAY.js → chunk-K3BQGZCT.js} +2 -2
- package/dist/{chunk-IFAV6KEM.js → chunk-KP5KD6EN.js} +2 -2
- package/dist/{chunk-ZEWMTR5M.js → chunk-MQMRLGOG.js} +2 -2
- package/dist/{chunk-TSWPNOYM.js → chunk-NQG5XDSB.js} +2 -2
- package/dist/{chunk-7WSD27QQ.js → chunk-PB64GYIG.js} +2 -2
- package/dist/{chunk-HBSWHQNJ.js → chunk-RCYQEFNX.js} +3 -3
- package/dist/{chunk-J3KDJNX2.js → chunk-RH5F53JT.js} +2 -2
- package/dist/{chunk-UAIOHCUK.js → chunk-SFLA7OH3.js} +3 -3
- package/dist/{chunk-Y6O2OCUO.js → chunk-SHM6MRRF.js} +2 -2
- package/dist/{chunk-KDIKRJGB.js → chunk-SHYIRB7I.js} +2 -2
- package/dist/{chunk-HHXFIHXC.js → chunk-SVR2LKYI.js} +2 -2
- package/dist/{chunk-PWQVGAJB.js → chunk-V7AEBY6U.js} +21 -21
- package/dist/{chunk-LRRD7NAG.js → chunk-WSKWVEQB.js} +18 -2
- package/dist/chunk-WSKWVEQB.js.map +1 -0
- package/dist/{chunk-2PVVP7GN.js → chunk-XKEFIFIC.js} +2 -2
- package/dist/{chunk-JRWWGMK7.js → chunk-XYA4XSNU.js} +2 -2
- package/dist/{chunk-X5YKXC6V.js → chunk-YSMEKBTD.js} +2 -2
- package/dist/{chunk-2XU6OGEN.js → chunk-Z4TZ76N7.js} +2 -2
- package/dist/index.js +23 -23
- package/package.json +5 -5
- package/scripts/trata-hedge/README.md +6 -5
- package/scripts/verify-packed-consumer.mjs +1 -1
- package/src/benchmarks/_harness.ts +20 -2
- package/src/benchmarks/humaneval.test.mts +2 -2
- package/src/gate.ts +1 -1
- package/src/hev-eval.mts +5 -2
- package/src/hev-improve.mts +118 -73
- package/src/official-optimizer-config.mts +89 -0
- package/src/official-optimizer-config.test.mts +88 -0
- package/src/profiles.ts +2 -2
- package/src/quant-arena/README.md +144 -0
- package/src/quant-arena/backtest.test.mts +135 -0
- package/src/quant-arena/backtest.ts +218 -0
- package/src/quant-arena/data.test.mts +44 -0
- package/src/quant-arena/data.ts +141 -0
- package/src/quant-arena/driver.test.mts +253 -0
- package/src/quant-arena/driver.ts +219 -0
- package/src/quant-arena/fixtures/data/PROVENANCE.md +26 -0
- package/src/quant-arena/fixtures/data/holdout/IDX.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S01.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S02.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S03.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S04.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S05.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S06.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S07.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S08.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S09.csv +523 -0
- package/src/quant-arena/fixtures/data/holdout/S10.csv +523 -0
- package/src/quant-arena/fixtures/data/insample/IDX.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S01.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S02.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S03.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S04.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S05.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S06.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S07.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S08.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S09.csv +2087 -0
- package/src/quant-arena/fixtures/data/insample/S10.csv +2087 -0
- package/src/quant-arena/fixtures/demo-campaign/cost-ledger.jsonl +16 -0
- package/src/quant-arena/fixtures/demo-campaign/notebook.jsonl +5 -0
- package/src/quant-arena/fixtures/demo-campaign/rollout-manifest.json +171 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-001-default-author/strategy.ts +119 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-002-default-author/strategy.ts +119 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-003-quant-researcher/strategy.ts +105 -0
- package/src/quant-arena/fixtures/demo-campaign/strategies/cand-004-quant-researcher/strategy.ts +102 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/cost-ledger.jsonl +4 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/notebook.jsonl +2 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/rollout-manifest.json +84 -0
- package/src/quant-arena/fixtures/demo-campaign-v2/strategies/cand-001-quant-researcher/strategy.ts +117 -0
- package/src/quant-arena/holdout-certify.mts +206 -0
- package/src/quant-arena/holdout-certify.test.mts +82 -0
- package/src/quant-arena/leak-audit.test.mts +79 -0
- package/src/quant-arena/leak-audit.ts +95 -0
- package/src/quant-arena/make-fixtures.mts +161 -0
- package/src/quant-arena/multiplicity.test.mts +68 -0
- package/src/quant-arena/multiplicity.ts +87 -0
- package/src/quant-arena/nautilus-certify.ts +31 -0
- package/src/quant-arena/oms.ts +90 -0
- package/src/quant-arena/profiles/quant-researcher.profile.json +7 -0
- package/src/quant-arena/python/pyproject.toml +8 -0
- package/src/quant-arena/python/uv.lock +1297 -0
- package/src/quant-arena/python/vbt-worker.py +192 -0
- package/src/quant-arena/quant-loop.mts +813 -0
- package/src/quant-arena/quant-loop.test.mts +75 -0
- package/src/quant-arena/strategies/buy-hold-index/strategy.ts +11 -0
- package/src/quant-arena/strategies/equal-weight/strategy.ts +20 -0
- package/src/quant-arena/strategies/sma-crossover/strategy.ts +42 -0
- package/src/quant-arena/types.ts +133 -0
- package/src/quant-arena/vbt-client.ts +321 -0
- package/src/quant-arena/vbt-parity.test.mts +183 -0
- package/src/quant-arena/windows.test.mts +45 -0
- package/src/quant-arena/windows.ts +54 -0
- package/src/rollout-ledger/backfill-swe-arena.mts +606 -0
- package/src/rollout-ledger/backfill-swe-arena.test.mts +342 -0
- package/src/rollout-ledger/settle-capture.mts +442 -0
- package/src/rollout-ledger/settle-capture.test.mts +270 -0
- package/src/smoke-structural-rollout.mts +15 -9
- package/src/swe-arena/activation.mts +225 -0
- package/src/swe-arena/activation.test.mts +300 -0
- package/src/swe-arena/arms.ts +30 -14
- package/src/swe-arena/briefing.mts +217 -0
- package/src/swe-arena/briefing.test.mts +178 -0
- package/src/swe-arena/calibrate.ts +102 -1
- package/src/swe-arena/cell-evidence.mts +41 -9
- package/src/swe-arena/factory-command-container.ts +284 -0
- package/src/swe-arena/factory-judge-child.mts +228 -0
- package/src/swe-arena/factory.test.mts +643 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/calibration.md +51 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/manifest.json +29 -0
- package/src/swe-arena/fixtures/factory/agent-eval-309/spec.md +64 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/calibration.md +48 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/manifest.json +29 -0
- package/src/swe-arena/fixtures/factory/agent-runtime-232/spec.md +48 -0
- package/src/swe-arena/fixtures/factory/loops-28/calibration.md +47 -0
- package/src/swe-arena/fixtures/factory/loops-28/manifest.json +30 -0
- package/src/swe-arena/fixtures/factory/loops-28/spec.md +50 -0
- package/src/swe-arena/fixtures/run-report/README.md +43 -0
- package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.json +173 -0
- package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.md +100 -0
- package/src/swe-arena/fixtures/run-report/gen3-rollup.json +551 -0
- package/src/swe-arena/fixtures/run-report/gen3-rollup.md +64 -0
- package/src/swe-arena/fixtures.ts +135 -2
- package/src/swe-arena/gepa-seat.mts +877 -0
- package/src/swe-arena/gepa-seat.test.mts +1059 -0
- package/src/swe-arena/implementation-ref.test.mts +64 -0
- package/src/swe-arena/implementation-ref.ts +62 -0
- package/src/swe-arena/ledger-orphans.mts +77 -0
- package/src/swe-arena/ledger-orphans.test.mts +147 -0
- package/src/swe-arena/outer-loop.mts +710 -33
- package/src/swe-arena/premeasured-from-cells.mts +281 -0
- package/src/swe-arena/premeasured-from-cells.test.mts +180 -0
- package/src/swe-arena/proposer-fanout.mts +327 -31
- package/src/swe-arena/proposer-fanout.test.mts +246 -0
- package/src/swe-arena/proposer-provenance.mts +172 -0
- package/src/swe-arena/proposer-provenance.test.mts +106 -0
- package/src/swe-arena/run-experiment.mts +367 -1
- package/src/swe-arena/run-report.mts +75 -0
- package/src/swe-arena/run-supervisor.test.mts +5 -3
- package/src/swe-arena/score-split.mts +140 -0
- package/src/swe-arena/score-split.test.mts +123 -0
- package/src/swe-arena/scratch-worktree.test.mts +55 -0
- package/src/swe-arena/scratch-worktree.ts +34 -0
- package/src/swe-arena/types.ts +52 -0
- package/src/swe-code-improve.mts +24 -25
- package/src/swe-improve.mts +129 -96
- package/src/swe-local-proof.mts +6 -1
- package/src/swe-stream.mts +4 -2
- package/src/swe-structural.mts +245 -837
- package/src/tb-container-executor.test.mts +30 -6
- package/src/tb-supervisor-sidecar.mts +2 -1
- package/src/trata-gepa.mts +182 -245
- package/dist/chunk-LRRD7NAG.js.map +0 -1
- package/src/live-improve-campaign-mbpp.mts +0 -641
- package/src/live-improve-campaign.mts +0 -500
- /package/dist/{chunk-CKUVRZ2T.js.map → chunk-3U5TXJZS.js.map} +0 -0
- /package/dist/{chunk-YCGY7UIZ.js.map → chunk-7GRVHU22.js.map} +0 -0
- /package/dist/{chunk-Z7ML6L77.js.map → chunk-HWST3SED.js.map} +0 -0
- /package/dist/{chunk-SYDW647C.js.map → chunk-IA2FBTWC.js.map} +0 -0
- /package/dist/{chunk-R67DFVLO.js.map → chunk-IFVINJ4B.js.map} +0 -0
- /package/dist/{chunk-R36V2VP7.js.map → chunk-IZ5M6OAC.js.map} +0 -0
- /package/dist/{chunk-ODT47UAY.js.map → chunk-K3BQGZCT.js.map} +0 -0
- /package/dist/{chunk-IFAV6KEM.js.map → chunk-KP5KD6EN.js.map} +0 -0
- /package/dist/{chunk-ZEWMTR5M.js.map → chunk-MQMRLGOG.js.map} +0 -0
- /package/dist/{chunk-TSWPNOYM.js.map → chunk-NQG5XDSB.js.map} +0 -0
- /package/dist/{chunk-7WSD27QQ.js.map → chunk-PB64GYIG.js.map} +0 -0
- /package/dist/{chunk-HBSWHQNJ.js.map → chunk-RCYQEFNX.js.map} +0 -0
- /package/dist/{chunk-J3KDJNX2.js.map → chunk-RH5F53JT.js.map} +0 -0
- /package/dist/{chunk-UAIOHCUK.js.map → chunk-SFLA7OH3.js.map} +0 -0
- /package/dist/{chunk-Y6O2OCUO.js.map → chunk-SHM6MRRF.js.map} +0 -0
- /package/dist/{chunk-KDIKRJGB.js.map → chunk-SHYIRB7I.js.map} +0 -0
- /package/dist/{chunk-HHXFIHXC.js.map → chunk-SVR2LKYI.js.map} +0 -0
- /package/dist/{chunk-PWQVGAJB.js.map → chunk-V7AEBY6U.js.map} +0 -0
- /package/dist/{chunk-2PVVP7GN.js.map → chunk-XKEFIFIC.js.map} +0 -0
- /package/dist/{chunk-JRWWGMK7.js.map → chunk-XYA4XSNU.js.map} +0 -0
- /package/dist/{chunk-X5YKXC6V.js.map → chunk-YSMEKBTD.js.map} +0 -0
- /package/dist/{chunk-2XU6OGEN.js.map → chunk-Z4TZ76N7.js.map} +0 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory judge child — the factory-bench equivalent of `judge-child.mts`.
|
|
3
|
+
* One candidate patch, one hidden-test verdict, printed as a single
|
|
4
|
+
* `JUDGE_RESULT {...}` line so serialized-judge.ts (queue, retry, SIGKILL
|
|
5
|
+
* ceiling) carries over unchanged. The judge workspace is a `git archive`
|
|
6
|
+
* export of the instance's base commit from the local mirror. Setup and judge
|
|
7
|
+
* commands run in separate containers, and the PR's added test files are
|
|
8
|
+
* overlaid from the merge commit only after setup completes.
|
|
9
|
+
*
|
|
10
|
+
* Steps: export base tree → apply candidate patch → run `setup_cmds` in a
|
|
11
|
+
* fresh container → overlay judge tests from `judge_ref` → run `judge_cmds`
|
|
12
|
+
* in a second network-disabled container →
|
|
13
|
+
* parse vitest's pass/fail counts → JUDGE_RESULT with partial credit.
|
|
14
|
+
*
|
|
15
|
+
* Verdict semantics:
|
|
16
|
+
* - `resolved` = every calibrated judge test passes (passed === total, 0 failed).
|
|
17
|
+
* - `score` = passed / judgeTestTotal, where the denominator is the CALIBRATED
|
|
18
|
+
* total from the manifest's resolved_criterion — never vitest's reported
|
|
19
|
+
* total, which shrinks when a judge file fails to collect.
|
|
20
|
+
* - An unappliable patch is the candidate's failure → resolved:false, score 0.
|
|
21
|
+
* - A setup/parse failure is an INFRA failure → exit 1 with no JUDGE_RESULT
|
|
22
|
+
* line, so serialized-judge retries and then records `resolved: null`
|
|
23
|
+
* (inconclusive), never a fabricated verdict.
|
|
24
|
+
*
|
|
25
|
+
* usage: node --import tsx src/swe-arena/factory-judge-child.mts <instanceDir> <patchPath>
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
|
29
|
+
import { tmpdir } from 'node:os'
|
|
30
|
+
import { dirname, join } from 'node:path'
|
|
31
|
+
import { pathToFileURL } from 'node:url'
|
|
32
|
+
import { applyPatchWithFallback } from './calibrate.ts'
|
|
33
|
+
import { runFactoryCommand } from './factory-command-container.ts'
|
|
34
|
+
import { loadFactoryInstance, type LoadedFactoryInstance } from './fixtures.ts'
|
|
35
|
+
import { runOk, shq } from './proc.ts'
|
|
36
|
+
|
|
37
|
+
export interface VitestSummary {
|
|
38
|
+
passed: number
|
|
39
|
+
failed: number
|
|
40
|
+
/** vitest's own reported total (collected tests only — informational). */
|
|
41
|
+
reportedTotal: number
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const stripAnsi = (s: string): string => s.replace(/\u001b\[[0-9;]*m/g, '')
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Parse the `Tests …` summary line of a vitest run (v3 and v4 formats):
|
|
48
|
+
* " Tests 30 passed (30)"
|
|
49
|
+
* " Tests 17 failed | 13 passed (30)"
|
|
50
|
+
* " Tests no tests" (collection failure — 0 passed is a verdict)
|
|
51
|
+
* Returns undefined when no summary line exists (infra failure, not a verdict).
|
|
52
|
+
*/
|
|
53
|
+
export function parseVitestSummary(output: string): VitestSummary | undefined {
|
|
54
|
+
for (const rawLine of stripAnsi(output).split('\n')) {
|
|
55
|
+
const m = /^\s*Tests\s{2,}(.+)$/.exec(rawLine)
|
|
56
|
+
if (!m) continue
|
|
57
|
+
const body = m[1].trim()
|
|
58
|
+
if (body.startsWith('no tests')) return { passed: 0, failed: 0, reportedTotal: 0 }
|
|
59
|
+
const passed = /(\d+) passed/.exec(body)
|
|
60
|
+
const failed = /(\d+) failed/.exec(body)
|
|
61
|
+
const total = /\((\d+)\)/.exec(body)
|
|
62
|
+
if (!passed && !failed) continue
|
|
63
|
+
return {
|
|
64
|
+
passed: passed ? Number(passed[1]) : 0,
|
|
65
|
+
failed: failed ? Number(failed[1]) : 0,
|
|
66
|
+
reportedTotal: total ? Number(total[1]) : 0,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return undefined
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The JUDGE_RESULT row this child prints (superset of the SWE child's fields). */
|
|
73
|
+
export interface FactoryJudgeResult {
|
|
74
|
+
iid: string
|
|
75
|
+
resolved: boolean
|
|
76
|
+
/** passed / judgeTestTotal — partial credit for the staircase. */
|
|
77
|
+
score: number
|
|
78
|
+
passed: number
|
|
79
|
+
total: number
|
|
80
|
+
secs: number
|
|
81
|
+
patch_bytes: number
|
|
82
|
+
error?: string
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Parse one JUDGE_RESULT line back out of child stdout (calibrate + tests). */
|
|
86
|
+
export function parseFactoryJudgeResult(stdout: string): FactoryJudgeResult | undefined {
|
|
87
|
+
const line = stdout.split('\n').find((l) => l.includes('JUDGE_RESULT'))
|
|
88
|
+
if (!line) return undefined
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(line.slice(line.indexOf('JUDGE_RESULT') + 'JUDGE_RESULT'.length).trim())
|
|
91
|
+
if (typeof parsed !== 'object' || parsed === null || typeof parsed.resolved !== 'boolean') return undefined
|
|
92
|
+
return parsed as FactoryJudgeResult
|
|
93
|
+
} catch {
|
|
94
|
+
return undefined
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** `git archive <ref> | tar -x` — a bare tree, no .git, no refs, no future history. */
|
|
99
|
+
export async function exportBaseTree(mirror: string, ref: string, dest: string): Promise<void> {
|
|
100
|
+
await mkdir(dest, { recursive: true })
|
|
101
|
+
await runOk('bash', ['-c', `git -C ${shq(mirror)} archive ${shq(ref)} | tar -x -C ${shq(dest)}`])
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Overlay each judge test from the merge commit (`git show <judge_ref>:<path>`). */
|
|
105
|
+
export async function overlayJudgeTests(inst: LoadedFactoryInstance, ws: string): Promise<void> {
|
|
106
|
+
for (const testPath of inst.judge_tests) {
|
|
107
|
+
const show = await runOk('git', ['-C', inst.repo_local_mirror, 'show', `${inst.judge_ref}:${testPath}`])
|
|
108
|
+
await mkdir(dirname(join(ws, testPath)), { recursive: true })
|
|
109
|
+
await writeFile(join(ws, testPath), show.stdout)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface FactoryJudgeOutcome {
|
|
114
|
+
result: FactoryJudgeResult
|
|
115
|
+
/** Raw judge_cmds output, for post-mortem. */
|
|
116
|
+
output: string
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Build the judge workspace and run the judge over one patch. Throws on infra
|
|
121
|
+
* failure (export/overlay/setup/parse); returns a verdict otherwise.
|
|
122
|
+
*/
|
|
123
|
+
export async function judgeFactoryPatch(
|
|
124
|
+
inst: LoadedFactoryInstance,
|
|
125
|
+
patch: string,
|
|
126
|
+
opts: { workDir?: string; keepWorkspace?: boolean } = {},
|
|
127
|
+
): Promise<FactoryJudgeOutcome> {
|
|
128
|
+
const t0 = Date.now()
|
|
129
|
+
const ws = opts.workDir ?? (await mkdtemp(join(tmpdir(), `factory-judge-${inst.id.replace(/[^a-zA-Z0-9.-]/g, '-')}-`)))
|
|
130
|
+
const cmdTimeoutMs = inst.timeout_s * 1000
|
|
131
|
+
try {
|
|
132
|
+
await exportBaseTree(inst.repo_local_mirror, inst.base_commit, ws)
|
|
133
|
+
// A git repo (fresh, historyless) so `git apply` and repo tooling behave;
|
|
134
|
+
// judge-side only, so its refs are irrelevant to leak prevention.
|
|
135
|
+
await runOk('git', ['-C', ws, 'init', '-q'])
|
|
136
|
+
|
|
137
|
+
if (patch.trim().length > 0) {
|
|
138
|
+
const patchFile = join(ws, '.factory-candidate.patch')
|
|
139
|
+
await writeFile(patchFile, patch)
|
|
140
|
+
const applyRc = await applyPatchWithFallback(ws, patchFile)
|
|
141
|
+
await rm(patchFile, { force: true })
|
|
142
|
+
if (applyRc !== 0) {
|
|
143
|
+
return {
|
|
144
|
+
result: {
|
|
145
|
+
iid: inst.id,
|
|
146
|
+
resolved: false,
|
|
147
|
+
score: 0,
|
|
148
|
+
passed: 0,
|
|
149
|
+
total: inst.judgeTestTotal,
|
|
150
|
+
secs: Math.round((Date.now() - t0) / 1000),
|
|
151
|
+
patch_bytes: patch.length,
|
|
152
|
+
error: `apply-failed rc=${applyRc}`,
|
|
153
|
+
},
|
|
154
|
+
output: '',
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
for (const cmd of inst.setup_cmds) {
|
|
160
|
+
const res = await runFactoryCommand(ws, cmd, {
|
|
161
|
+
image: inst.command_image,
|
|
162
|
+
network: 'enabled',
|
|
163
|
+
timeoutMs: cmdTimeoutMs,
|
|
164
|
+
})
|
|
165
|
+
if (res.code !== 0) {
|
|
166
|
+
throw new Error(
|
|
167
|
+
`setup_cmd failed (rc=${res.code}${res.timedOut ? ', timeout' : ''}): ${cmd}\n${(res.stderr || res.stdout).slice(-2000)}`,
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
await overlayJudgeTests(inst, ws)
|
|
173
|
+
|
|
174
|
+
let passed = 0
|
|
175
|
+
let failed = 0
|
|
176
|
+
let output = ''
|
|
177
|
+
for (const cmd of inst.judge_cmds) {
|
|
178
|
+
const res = await runFactoryCommand(ws, cmd, {
|
|
179
|
+
image: inst.command_image,
|
|
180
|
+
network: 'none',
|
|
181
|
+
timeoutMs: cmdTimeoutMs,
|
|
182
|
+
})
|
|
183
|
+
const combined = res.stdout + res.stderr
|
|
184
|
+
output += combined
|
|
185
|
+
if (res.timedOut) throw new Error(`judge_cmd timed out after ${cmdTimeoutMs}ms: ${cmd}`)
|
|
186
|
+
const summary = parseVitestSummary(combined)
|
|
187
|
+
if (!summary) {
|
|
188
|
+
throw new Error(`judge_cmd produced no parseable test summary (rc=${res.code}): ${cmd}\n${combined.slice(-2000)}`)
|
|
189
|
+
}
|
|
190
|
+
passed += summary.passed
|
|
191
|
+
failed += summary.failed
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const total = inst.judgeTestTotal
|
|
195
|
+
return {
|
|
196
|
+
result: {
|
|
197
|
+
iid: inst.id,
|
|
198
|
+
resolved: failed === 0 && passed === total,
|
|
199
|
+
score: total > 0 ? Number((passed / total).toFixed(4)) : 0,
|
|
200
|
+
passed,
|
|
201
|
+
total,
|
|
202
|
+
secs: Math.round((Date.now() - t0) / 1000),
|
|
203
|
+
patch_bytes: patch.length,
|
|
204
|
+
},
|
|
205
|
+
output,
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
if (!opts.keepWorkspace) await rm(ws, { recursive: true, force: true })
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ---------------------------------------------------------------------------
|
|
213
|
+
// CLI (guarded so calibrate/tests can import the helpers above).
|
|
214
|
+
// ---------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
const isMain = process.argv[1] !== undefined && import.meta.url === pathToFileURL(process.argv[1]).href
|
|
217
|
+
|
|
218
|
+
if (isMain) {
|
|
219
|
+
const [, , instanceDir, patchPath] = process.argv
|
|
220
|
+
if (!instanceDir || !patchPath) {
|
|
221
|
+
console.error('usage: node --import tsx factory-judge-child.mts <instanceDir> <patchPath>')
|
|
222
|
+
process.exit(2)
|
|
223
|
+
}
|
|
224
|
+
const inst = loadFactoryInstance(instanceDir)
|
|
225
|
+
const patch = await readFile(patchPath, 'utf8')
|
|
226
|
+
const { result } = await judgeFactoryPatch(inst, patch)
|
|
227
|
+
console.log('JUDGE_RESULT ' + JSON.stringify(result))
|
|
228
|
+
}
|