@tangle-network/agent-bench 0.11.3 → 0.13.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.
Files changed (170) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/HARNESS.md +6 -2
  3. package/README.md +1 -4
  4. package/package.json +5 -5
  5. package/scripts/run-package-tests.mjs +2 -2
  6. package/src/quant-arena/README.md +0 -144
  7. package/src/quant-arena/backtest.test.mts +0 -135
  8. package/src/quant-arena/backtest.ts +0 -218
  9. package/src/quant-arena/data.test.mts +0 -44
  10. package/src/quant-arena/data.ts +0 -141
  11. package/src/quant-arena/driver.test.mts +0 -253
  12. package/src/quant-arena/driver.ts +0 -219
  13. package/src/quant-arena/fixtures/data/PROVENANCE.md +0 -26
  14. package/src/quant-arena/fixtures/data/holdout/IDX.csv +0 -523
  15. package/src/quant-arena/fixtures/data/holdout/S01.csv +0 -523
  16. package/src/quant-arena/fixtures/data/holdout/S02.csv +0 -523
  17. package/src/quant-arena/fixtures/data/holdout/S03.csv +0 -523
  18. package/src/quant-arena/fixtures/data/holdout/S04.csv +0 -523
  19. package/src/quant-arena/fixtures/data/holdout/S05.csv +0 -523
  20. package/src/quant-arena/fixtures/data/holdout/S06.csv +0 -523
  21. package/src/quant-arena/fixtures/data/holdout/S07.csv +0 -523
  22. package/src/quant-arena/fixtures/data/holdout/S08.csv +0 -523
  23. package/src/quant-arena/fixtures/data/holdout/S09.csv +0 -523
  24. package/src/quant-arena/fixtures/data/holdout/S10.csv +0 -523
  25. package/src/quant-arena/fixtures/data/insample/IDX.csv +0 -2087
  26. package/src/quant-arena/fixtures/data/insample/S01.csv +0 -2087
  27. package/src/quant-arena/fixtures/data/insample/S02.csv +0 -2087
  28. package/src/quant-arena/fixtures/data/insample/S03.csv +0 -2087
  29. package/src/quant-arena/fixtures/data/insample/S04.csv +0 -2087
  30. package/src/quant-arena/fixtures/data/insample/S05.csv +0 -2087
  31. package/src/quant-arena/fixtures/data/insample/S06.csv +0 -2087
  32. package/src/quant-arena/fixtures/data/insample/S07.csv +0 -2087
  33. package/src/quant-arena/fixtures/data/insample/S08.csv +0 -2087
  34. package/src/quant-arena/fixtures/data/insample/S09.csv +0 -2087
  35. package/src/quant-arena/fixtures/data/insample/S10.csv +0 -2087
  36. package/src/quant-arena/fixtures/demo-campaign/cost-ledger.jsonl +0 -16
  37. package/src/quant-arena/fixtures/demo-campaign/notebook.jsonl +0 -5
  38. package/src/quant-arena/fixtures/demo-campaign/rollout-manifest.json +0 -171
  39. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-001-default-author/strategy.ts +0 -119
  40. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-002-default-author/strategy.ts +0 -119
  41. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-003-quant-researcher/strategy.ts +0 -105
  42. package/src/quant-arena/fixtures/demo-campaign/strategies/cand-004-quant-researcher/strategy.ts +0 -102
  43. package/src/quant-arena/fixtures/demo-campaign-v2/cost-ledger.jsonl +0 -4
  44. package/src/quant-arena/fixtures/demo-campaign-v2/notebook.jsonl +0 -2
  45. package/src/quant-arena/fixtures/demo-campaign-v2/rollout-manifest.json +0 -84
  46. package/src/quant-arena/fixtures/demo-campaign-v2/strategies/cand-001-quant-researcher/strategy.ts +0 -117
  47. package/src/quant-arena/holdout-certify.mts +0 -206
  48. package/src/quant-arena/holdout-certify.test.mts +0 -82
  49. package/src/quant-arena/leak-audit.test.mts +0 -79
  50. package/src/quant-arena/leak-audit.ts +0 -95
  51. package/src/quant-arena/make-fixtures.mts +0 -161
  52. package/src/quant-arena/multiplicity.test.mts +0 -68
  53. package/src/quant-arena/multiplicity.ts +0 -87
  54. package/src/quant-arena/nautilus-certify.ts +0 -31
  55. package/src/quant-arena/oms.ts +0 -90
  56. package/src/quant-arena/profiles/quant-researcher.profile.json +0 -12
  57. package/src/quant-arena/python/pyproject.toml +0 -8
  58. package/src/quant-arena/python/uv.lock +0 -1297
  59. package/src/quant-arena/python/vbt-worker.py +0 -192
  60. package/src/quant-arena/quant-loop.mts +0 -840
  61. package/src/quant-arena/quant-loop.test.mts +0 -75
  62. package/src/quant-arena/strategies/buy-hold-index/strategy.ts +0 -11
  63. package/src/quant-arena/strategies/equal-weight/strategy.ts +0 -20
  64. package/src/quant-arena/strategies/sma-crossover/strategy.ts +0 -42
  65. package/src/quant-arena/types.ts +0 -133
  66. package/src/quant-arena/vbt-client.ts +0 -321
  67. package/src/quant-arena/vbt-parity.test.mts +0 -183
  68. package/src/quant-arena/windows.test.mts +0 -45
  69. package/src/quant-arena/windows.ts +0 -54
  70. package/src/rollout-ledger/backfill-swe-arena.mts +0 -610
  71. package/src/rollout-ledger/backfill-swe-arena.test.mts +0 -347
  72. package/src/rollout-ledger/settle-capture.mts +0 -448
  73. package/src/rollout-ledger/settle-capture.test.mts +0 -270
  74. package/src/swe-arena/activation.mts +0 -225
  75. package/src/swe-arena/activation.test.mts +0 -300
  76. package/src/swe-arena/analyze.ts +0 -211
  77. package/src/swe-arena/arms.ts +0 -862
  78. package/src/swe-arena/bootstrap-meta.mts +0 -188
  79. package/src/swe-arena/bootstrap-meta.test.mts +0 -51
  80. package/src/swe-arena/briefing.mts +0 -217
  81. package/src/swe-arena/briefing.test.mts +0 -179
  82. package/src/swe-arena/calibrate.ts +0 -217
  83. package/src/swe-arena/capabilities.mts +0 -76
  84. package/src/swe-arena/capabilities.test.mts +0 -57
  85. package/src/swe-arena/capacity.ts +0 -198
  86. package/src/swe-arena/cell-evidence.mts +0 -437
  87. package/src/swe-arena/cell-evidence.test.mts +0 -248
  88. package/src/swe-arena/diagnosis-ensemble.test.mts +0 -210
  89. package/src/swe-arena/diagnosis-ensemble.ts +0 -523
  90. package/src/swe-arena/execution.test.mts +0 -1171
  91. package/src/swe-arena/factory-command-container.ts +0 -284
  92. package/src/swe-arena/factory-judge-child.mts +0 -228
  93. package/src/swe-arena/factory.test.mts +0 -645
  94. package/src/swe-arena/fixtures/analyze.py +0 -80
  95. package/src/swe-arena/fixtures/excludes.txt +0 -8
  96. package/src/swe-arena/fixtures/factory/agent-eval-309/calibration.md +0 -51
  97. package/src/swe-arena/fixtures/factory/agent-eval-309/manifest.json +0 -29
  98. package/src/swe-arena/fixtures/factory/agent-eval-309/spec.md +0 -64
  99. package/src/swe-arena/fixtures/factory/agent-runtime-232/calibration.md +0 -48
  100. package/src/swe-arena/fixtures/factory/agent-runtime-232/manifest.json +0 -29
  101. package/src/swe-arena/fixtures/factory/agent-runtime-232/spec.md +0 -48
  102. package/src/swe-arena/fixtures/factory/loops-28/calibration.md +0 -47
  103. package/src/swe-arena/fixtures/factory/loops-28/manifest.json +0 -30
  104. package/src/swe-arena/fixtures/factory/loops-28/spec.md +0 -50
  105. package/src/swe-arena/fixtures/gen1-salvage/README.md +0 -45
  106. package/src/swe-arena/fixtures/gen1-salvage/cand0-e6d7361.diff +0 -116
  107. package/src/swe-arena/fixtures/gen1-salvage/cand1-76a8590.diff +0 -293
  108. package/src/swe-arena/fixtures/holdout-preregister.log +0 -12
  109. package/src/swe-arena/fixtures/holdout.json +0 -44
  110. package/src/swe-arena/fixtures/instances.json +0 -146
  111. package/src/swe-arena/fixtures/ledger.jsonl +0 -12
  112. package/src/swe-arena/fixtures/patches/pallets__flask-5014.solo.patch +0 -36
  113. package/src/swe-arena/fixtures/patches/pydata__xarray-4687.sup.patch +0 -33
  114. package/src/swe-arena/fixtures/rejudge.jsonl +0 -15
  115. package/src/swe-arena/fixtures/rematch.jsonl +0 -3
  116. package/src/swe-arena/fixtures/rematch2.jsonl +0 -3
  117. package/src/swe-arena/fixtures/rematch3.jsonl +0 -3
  118. package/src/swe-arena/fixtures/run-report/README.md +0 -43
  119. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.json +0 -173
  120. package/src/swe-arena/fixtures/run-report/factory-agent-eval-309-FSUP0.md +0 -100
  121. package/src/swe-arena/fixtures/run-report/gen3-rollup.json +0 -551
  122. package/src/swe-arena/fixtures/run-report/gen3-rollup.md +0 -64
  123. package/src/swe-arena/fixtures/sup-journal-true.json +0 -19
  124. package/src/swe-arena/fixtures/verify/astropy__astropy-13033.sh +0 -48
  125. package/src/swe-arena/fixtures/verify/django__django-11532.sh +0 -50
  126. package/src/swe-arena/fixtures/verify/matplotlib__matplotlib-20826.sh +0 -76
  127. package/src/swe-arena/fixtures/verify/pydata__xarray-4687.sh +0 -44
  128. package/src/swe-arena/fixtures/verify/pytest-dev__pytest-6197.sh +0 -32
  129. package/src/swe-arena/fixtures/verify/sphinx-doc__sphinx-9658.sh +0 -51
  130. package/src/swe-arena/fixtures/worker-tokens.json +0 -42
  131. package/src/swe-arena/fixtures.ts +0 -237
  132. package/src/swe-arena/gepa-seat.mts +0 -886
  133. package/src/swe-arena/gepa-seat.test.mts +0 -1136
  134. package/src/swe-arena/holdout-certify.mts +0 -408
  135. package/src/swe-arena/holdout-certify.test.mts +0 -160
  136. package/src/swe-arena/implementation-ref.test.mts +0 -64
  137. package/src/swe-arena/implementation-ref.ts +0 -62
  138. package/src/swe-arena/judge-child.mts +0 -37
  139. package/src/swe-arena/ledger-orphans.mts +0 -77
  140. package/src/swe-arena/ledger-orphans.test.mts +0 -149
  141. package/src/swe-arena/manifest.mts +0 -293
  142. package/src/swe-arena/manifest.test.mts +0 -169
  143. package/src/swe-arena/materialize.ts +0 -142
  144. package/src/swe-arena/outer-loop.mts +0 -2854
  145. package/src/swe-arena/outer-loop.test.mts +0 -714
  146. package/src/swe-arena/parity.test.mts +0 -87
  147. package/src/swe-arena/premeasured-from-cells.mts +0 -296
  148. package/src/swe-arena/premeasured-from-cells.test.mts +0 -201
  149. package/src/swe-arena/proc.test.mts +0 -172
  150. package/src/swe-arena/proc.ts +0 -260
  151. package/src/swe-arena/profiles/deepseek-author.profile.json +0 -12
  152. package/src/swe-arena/profiles/default-author.profile.json +0 -12
  153. package/src/swe-arena/proposer-fanout.mts +0 -736
  154. package/src/swe-arena/proposer-fanout.test.mts +0 -660
  155. package/src/swe-arena/proposer-provenance.mts +0 -176
  156. package/src/swe-arena/proposer-provenance.test.mts +0 -106
  157. package/src/swe-arena/reconcile.ts +0 -0
  158. package/src/swe-arena/replay.mts +0 -183
  159. package/src/swe-arena/replay.test.mts +0 -300
  160. package/src/swe-arena/run-experiment.mts +0 -729
  161. package/src/swe-arena/run-report.mts +0 -75
  162. package/src/swe-arena/run-supervisor.mjs +0 -297
  163. package/src/swe-arena/run-supervisor.test.mts +0 -539
  164. package/src/swe-arena/score-split.mts +0 -140
  165. package/src/swe-arena/score-split.test.mts +0 -123
  166. package/src/swe-arena/scratch-worktree-serialization.test.mts +0 -72
  167. package/src/swe-arena/scratch-worktree.test.mts +0 -56
  168. package/src/swe-arena/scratch-worktree.ts +0 -64
  169. package/src/swe-arena/serialized-judge.ts +0 -414
  170. package/src/swe-arena/types.ts +0 -218
@@ -1,347 +0,0 @@
1
- import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
2
- import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
4
- import { afterEach, beforeEach, describe, expect, it } from 'vitest'
5
- import {
6
- assertMintedLines,
7
- assertRolloutLine,
8
- claudeProjectSlug,
9
- toSftRows,
10
- } from '@tangle-network/agent-eval/rollout'
11
- import { backfillSweArena } from './backfill-swe-arena.mts'
12
-
13
- let dir: string
14
- let outDir: string
15
- let dbPath: string
16
- let projectsDir: string
17
- beforeEach(async () => {
18
- dir = await mkdtemp(join(tmpdir(), 'backfill-swe-'))
19
- outDir = join(dir, 'out')
20
- dbPath = join(dir, 'opencode.db')
21
- projectsDir = join(dir, 'claude-projects')
22
- })
23
- afterEach(async () => {
24
- await rm(dir, { recursive: true, force: true })
25
- })
26
-
27
- const COMMIT = '1deb554c45d31dd0d4a851efe90da875cd9b50c8'
28
- const WORKER_CWD = '/tmp/loops-w-0-backfill-fixture'
29
- const MISSING_CWD = '/tmp/loops-w-1-backfill-missing'
30
-
31
- async function writeJson(path: string, value: unknown): Promise<void> {
32
- await mkdir(join(path, '..'), { recursive: true })
33
- await writeFile(path, JSON.stringify(value, null, 1))
34
- }
35
-
36
- function cachedResult(iid: string, resolved: boolean, runDir: string): unknown {
37
- return {
38
- manifestHash: 'x',
39
- cellId: `${iid}:0`,
40
- scenarioId: iid,
41
- rep: 0,
42
- artifact: {
43
- kind: 'swe-arm',
44
- iid,
45
- commit: COMMIT,
46
- resolved,
47
- verifyPass: true,
48
- patchLines: 12,
49
- wallS: 549,
50
- spentTokens: 70222,
51
- spentUsd: 0.05,
52
- recoveredTokens: 169560,
53
- workerTokIn: 100,
54
- workerTokOut: 50,
55
- judgeAttempts: 1,
56
- judgeWallS: 62,
57
- runDir,
58
- patchPath: join(runDir, 'patch.diff'),
59
- },
60
- judgeScores: {
61
- 'swe-arena-official-judge': { composite: resolved ? 1 : 0, dimensions: { resolved: resolved ? 1 : 0 } },
62
- },
63
- costUsd: 0.05,
64
- costEstimated: false,
65
- costCallIds: ['call-a'],
66
- tokenUsage: { input: 100, output: 50 },
67
- resolvedModel: 'zai-coding-plan/glm-5.2',
68
- durationMs: 639038,
69
- seed: 42,
70
- cached: false,
71
- }
72
- }
73
-
74
- async function writeArmRun(runDir: string, iid: string, resolved: boolean, workerCwds: string[]): Promise<void> {
75
- await mkdir(runDir, { recursive: true })
76
- await writeJson(join(runDir, 'judge.json'), { iid, resolved, score: resolved ? 1 : 0, secs: 59, attempts: 1 })
77
- await writeJson(join(runDir, 'result.json'), {
78
- arm: 'R4',
79
- iid,
80
- driver_rc: 0,
81
- wall_s: 549,
82
- sup_status: 'completed',
83
- sup_verdict: 'delivered',
84
- spawned: 2,
85
- workers: workerCwds.length,
86
- settled: workerCwds.length,
87
- subtasks: ['fix-it'],
88
- recoveredSpend: {
89
- workerTokJournal: 0,
90
- workerCwds,
91
- workerSessions: workerCwds.length,
92
- workerTokSqlite: 150,
93
- workerTokIn: 100,
94
- workerTokOut: 50,
95
- },
96
- })
97
- await writeFile(join(runDir, 'patch.diff'), 'diff --git a/x b/x\n')
98
- }
99
-
100
- async function buildFixtureDb(): Promise<void> {
101
- const { DatabaseSync } = await import('node:sqlite')
102
- const db = new DatabaseSync(dbPath)
103
- db.exec(`
104
- CREATE TABLE session (
105
- id text PRIMARY KEY, project_id text NOT NULL, parent_id text, slug text, directory text NOT NULL,
106
- title text, version text, agent text, model text, cost real DEFAULT 0 NOT NULL,
107
- tokens_input integer DEFAULT 0 NOT NULL, tokens_output integer DEFAULT 0 NOT NULL,
108
- tokens_reasoning integer DEFAULT 0 NOT NULL, tokens_cache_read integer DEFAULT 0 NOT NULL,
109
- tokens_cache_write integer DEFAULT 0 NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL
110
- );
111
- CREATE TABLE message (id text PRIMARY KEY, session_id text NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL, data text NOT NULL);
112
- CREATE TABLE part (id text PRIMARY KEY, message_id text NOT NULL, session_id text NOT NULL, time_created integer NOT NULL, time_updated integer NOT NULL, data text NOT NULL);
113
- `)
114
- db.prepare(
115
- `INSERT INTO session (id, project_id, parent_id, directory, agent, model, cost, tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, tokens_cache_write, time_created, time_updated)
116
- VALUES ('ses_w0', 'prj', 'ses_root', ?, 'build', '{"id":"glm-5.2","providerID":"tangle-router"}', 0, 100, 50, 5, 30, 10, 1000, 61000)`,
117
- ).run(WORKER_CWD)
118
- db.prepare("INSERT INTO message (id, session_id, time_created, time_updated, data) VALUES ('msg_u', 'ses_w0', 1000, 1000, ?)").run(
119
- JSON.stringify({ role: 'user' }),
120
- )
121
- db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_u', 'msg_u', 'ses_w0', 1000, 1000, ?)").run(
122
- JSON.stringify({ type: 'text', text: 'Fix the failing test.' }),
123
- )
124
- db.prepare("INSERT INTO message (id, session_id, time_created, time_updated, data) VALUES ('msg_a', 'ses_w0', 2000, 2000, ?)").run(
125
- JSON.stringify({ role: 'assistant', modelID: 'glm-5.2', providerID: 'tangle-router' }),
126
- )
127
- db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_a1', 'msg_a', 'ses_w0', 2000, 2000, ?)").run(
128
- JSON.stringify({ type: 'step-start' }),
129
- )
130
- db.prepare("INSERT INTO part (id, message_id, session_id, time_created, time_updated, data) VALUES ('prt_a2', 'msg_a', 'ses_w0', 2000, 2000, ?)").run(
131
- JSON.stringify({ type: 'text', text: 'Patched.' }),
132
- )
133
- db.close()
134
- }
135
-
136
- async function buildFixtureTree(): Promise<void> {
137
- // Baseline (resolved=false) + gen-0 candidate-0 (resolved=true), same
138
- // instance — resolvedInstanceCount scores candidates against the baseline's
139
- // instance set, exactly like a real round.
140
- const baselineRun = join(outDir, 'arm-runs', 'baseline', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4')
141
- const candidateRun = join(outDir, 'arm-runs', 'cand-0', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4')
142
- await writeArmRun(baselineRun, 'astropy__astropy-13033', false, [WORKER_CWD, MISSING_CWD])
143
- await writeArmRun(candidateRun, 'astropy__astropy-13033', true, [WORKER_CWD])
144
- await writeJson(
145
- join(outDir, 'improve-run', 'baseline', 'astropy__astropy-13033_0', 'cached-result.json'),
146
- cachedResult('astropy__astropy-13033', false, baselineRun),
147
- )
148
- await writeJson(
149
- join(outDir, 'improve-run', 'gen-0', 'candidate-0', 'astropy__astropy-13033_0', 'cached-result.json'),
150
- cachedResult('astropy__astropy-13033', true, candidateRun),
151
- )
152
- await writeJson(join(outDir, 'improve-run', 'loop-provenance.json'), {
153
- schema: 'tangle.loop-provenance',
154
- runId: `${outDir}/improve-run#42`,
155
- })
156
- await mkdir(join(outDir, 'candidates'), { recursive: true })
157
- await writeFile(join(outDir, 'candidates', `${COMMIT.slice(0, 10)}.patch`), 'diff --git a/y b/y\n')
158
-
159
- // Proposer shot receipt + matching claude transcript.
160
- await writeJson(join(outDir, 'proposer-shots', 'default-author', 'gen0-cand0-shot1.json'), {
161
- receipt: {
162
- generation: 0,
163
- candidateIndex: 0,
164
- shot: 1,
165
- maxShots: 3,
166
- harness: 'claude-code',
167
- model: null,
168
- promptSha256: 'sha256:abc',
169
- startedAt: '2026-07-22T19:27:18.350Z',
170
- completedAt: '2026-07-22T19:34:55.925Z',
171
- durationMs: 457571,
172
- exitCode: 0,
173
- timedOut: false,
174
- costUsd: null,
175
- },
176
- stdoutTail: 'Done.',
177
- })
178
- const proposerCwd = join(outDir, 'proposer-wt', 'gen0-cand0-default-author')
179
- const projectDir = join(projectsDir, claudeProjectSlug(proposerCwd))
180
- await mkdir(projectDir, { recursive: true })
181
- await writeFile(
182
- join(projectDir, 'sess-1.jsonl'),
183
- [
184
- JSON.stringify({
185
- type: 'user',
186
- timestamp: '2026-07-22T19:27:19.104Z',
187
- message: { role: 'user', content: 'Improve the supervisor.' },
188
- }),
189
- JSON.stringify({
190
- type: 'assistant',
191
- timestamp: '2026-07-22T19:27:21.583Z',
192
- message: {
193
- id: 'msg_p1',
194
- model: 'claude-fable-5',
195
- role: 'assistant',
196
- content: [{ type: 'text', text: 'Diagnosed and patched the prompts.' }],
197
- usage: { input_tokens: 2, output_tokens: 462, cache_read_input_tokens: 15109, cache_creation_input_tokens: 33218 },
198
- },
199
- }),
200
- ].join('\n') + '\n',
201
- )
202
- }
203
-
204
- describe('backfillSweArena', () => {
205
- it('joins cells, worker sessions, and proposer shots into labeled ledger lines', async () => {
206
- await buildFixtureTree()
207
- await buildFixtureDb()
208
- const { lines, stats } = await backfillSweArena(outDir, {
209
- opencodeDb: dbPath,
210
- claudeProjectsDir: projectsDir,
211
- now: () => new Date('2026-07-23T00:00:00.000Z'),
212
- })
213
- for (const line of lines) assertRolloutLine(line)
214
-
215
- // 2 supervisors + 3 worker cwd joins (2 found, 1 missing) + 1 proposer.
216
- expect(stats.lines).toBe(6)
217
- expect(stats.byRole).toEqual({ supervisor: 2, worker: 3, proposer: 1 })
218
- expect(stats.fullTranscripts).toBe(3)
219
- expect(stats.gapLines).toBe(3)
220
- expect(stats.workerSessionsJoined).toBe(2)
221
- expect(stats.workerCwdsMissed).toBe(1)
222
- expect(stats.proposerShotsJoined).toBe(1)
223
- expect(stats.rewardLabeled).toBe(6)
224
-
225
- const runId = `${outDir}/improve-run#42`
226
- expect(new Set(lines.map((l) => l.run_id))).toEqual(new Set([runId]))
227
-
228
- const baselineSup = lines.find((l) => l.role === 'supervisor' && l.candidate_index === -1)
229
- expect(baselineSup).toBeDefined()
230
- expect(baselineSup?.candidate_id).toBe('baseline')
231
- expect(baselineSup?.outcome.reward).toBe(0)
232
- expect(baselineSup?.outcome.reward_source).toBe('swe-arena-official-judge')
233
- expect(baselineSup?.outcome.verdict).toMatchObject({ iid: 'astropy__astropy-13033', resolved: false })
234
- expect(baselineSup?.policy).toMatchObject({ harness: 'pi-loops', model: 'glm-5.2', provider: 'zai-coding-plan' })
235
- expect(baselineSup?.task).toMatchObject({ split: 'search', seed: 42, rep: 0 })
236
- expect(baselineSup?.provenance.gap).toMatch(/brain transcript/)
237
-
238
- const candidateSup = lines.find((l) => l.role === 'supervisor' && l.candidate_index === 0)
239
- expect(candidateSup?.outcome.reward).toBe(1)
240
- expect(candidateSup?.generation).toBe(0)
241
- expect(candidateSup?.candidate_id).toBe('gen0-cand0')
242
-
243
- const workers = lines.filter((l) => l.role === 'worker')
244
- const joined = workers.filter((l) => l.messages.length > 0)
245
- expect(joined).toHaveLength(2)
246
- for (const worker of joined) {
247
- expect(worker.parent_rollout_id).toBe(
248
- lines.find((l) => l.role === 'supervisor' && l.candidate_index === worker.candidate_index)?.rollout_id,
249
- )
250
- expect(worker.outcome.reward_source).toBe('swe-arena-official-judge/inherited')
251
- expect(worker.policy).toMatchObject({ harness: 'opencode', model: 'glm-5.2', provider: 'tangle-router' })
252
- expect(worker.cost).toMatchObject({ tokens_in: 100, tokens_out: 50, tokens_reasoning: 5 })
253
- expect(worker.artifacts.transcript_ref).toBe('opencode:ses_w0')
254
- expect(worker.messages[0]).toEqual({ role: 'user', content: 'Fix the failing test.' })
255
- }
256
- const missed = workers.find((l) => l.messages.length === 0)
257
- expect(missed?.provenance.gap).toMatch(/no opencode session/)
258
- expect(missed?.outcome.reward).toBe(0)
259
-
260
- const proposer = lines.find((l) => l.role === 'proposer')
261
- expect(proposer?.messages).toHaveLength(2)
262
- expect(proposer?.outcome.reward).toBe(1)
263
- expect(proposer?.outcome.reward_source).toBe('swe-arena-official-judge/candidate-resolved-fraction')
264
- expect(proposer?.policy).toMatchObject({ harness: 'claude-code', model: 'claude-fable-5' })
265
- expect(proposer?.cost.tokens_out).toBe(462)
266
- expect(proposer?.task).toMatchObject({ suite: 'swe-arena-proposer', rep: 1 })
267
-
268
- // The dataset is immediately trainable: reward==1 trainable-split lines
269
- // with transcripts → SFT rows (candidate worker + proposer here).
270
- expect(toSftRows(assertMintedLines(lines))).toHaveLength(2)
271
- })
272
-
273
- it('joins a respawned worker cwd once, not once per recovered entry', async () => {
274
- await buildFixtureTree()
275
- await buildFixtureDb()
276
- // A crashed-and-retried worker reuses its clone dir, so the recovered list
277
- // names it twice.
278
- await writeArmRun(
279
- join(outDir, 'arm-runs', 'cand-0', 'rep-0', 'runs', 'astropy__astropy-13033', 'R4'),
280
- 'astropy__astropy-13033',
281
- true,
282
- [WORKER_CWD, WORKER_CWD],
283
- )
284
- const { lines, stats } = await backfillSweArena(outDir, {
285
- opencodeDb: dbPath,
286
- claudeProjectsDir: projectsDir,
287
- })
288
- const candidateWorkers = lines.filter((l) => l.role === 'worker' && l.candidate_index === 0)
289
- expect(candidateWorkers).toHaveLength(1)
290
- expect(stats.workerSessionsJoined).toBe(2)
291
- })
292
-
293
- it(
294
- 'marks a session with no readable parts as an incomplete gap line',
295
- async () => {
296
- await buildFixtureTree()
297
- await buildFixtureDb()
298
- const { DatabaseSync } = await import('node:sqlite')
299
- const db = new DatabaseSync(dbPath)
300
- // Session row survives; its message parts do not.
301
- db.exec("DELETE FROM part; DELETE FROM message")
302
- db.close()
303
-
304
- const { lines, stats } = await backfillSweArena(outDir, {
305
- opencodeDb: dbPath,
306
- claudeProjectsDir: projectsDir,
307
- })
308
- const joinedCwd = lines.filter((l) => l.role === 'worker' && l.outcome.metrics.has_session === true)
309
- expect(joinedCwd.length).toBeGreaterThan(0)
310
- for (const worker of joinedCwd) {
311
- expect(worker.messages).toHaveLength(0)
312
- expect(worker.outcome.is_completed).toBe(false)
313
- expect(worker.provenance.gap).toMatch(/no readable message parts/)
314
- }
315
- // The store-integrity failure is counted apart from the cwd-join failure.
316
- expect(stats.workerSessionsEmpty).toBe(2)
317
- expect(stats.workerCwdsMissed).toBe(1)
318
- expect(stats.workerSessionsJoined).toBe(0)
319
- },
320
- 15_000,
321
- )
322
-
323
- it('fails loud on a cell cache that carries no scenarioId/rep identity', async () => {
324
- await buildFixtureTree()
325
- await writeJson(join(outDir, 'improve-run', 'baseline', 'astropy__astropy-13033_0', 'cached-result.json'), {
326
- artifact: { resolved: true },
327
- })
328
- await expect(
329
- backfillSweArena(outDir, { opencodeDb: join(dir, 'absent.db'), claudeProjectsDir: projectsDir }),
330
- ).rejects.toThrow(/is not a campaign cell \(scenarioId\/rep missing\)/)
331
- })
332
-
333
- it('records worker gap lines when the opencode store is unavailable', async () => {
334
- await buildFixtureTree()
335
- const { lines, stats } = await backfillSweArena(outDir, {
336
- opencodeDb: join(dir, 'absent.db'),
337
- claudeProjectsDir: projectsDir,
338
- })
339
- expect(stats.opencodeDbAvailable).toBe(false)
340
- const workers = lines.filter((l) => l.role === 'worker')
341
- expect(workers).toHaveLength(3)
342
- for (const worker of workers) {
343
- expect(worker.messages).toHaveLength(0)
344
- expect(worker.provenance.gap).toMatch(/opencode store unavailable/)
345
- }
346
- })
347
- })