(input: {
sessionID: string
count?: number
models?: BenchmarkSchema.Model[]
allowDuplicates?: boolean
})
| 66 | } |
| 67 | |
| 68 | export async function start(input: { |
| 69 | sessionID: string |
| 70 | count?: number |
| 71 | models?: BenchmarkSchema.Model[] |
| 72 | allowDuplicates?: boolean |
| 73 | }) { |
| 74 | let parent = await Session.get(input.sessionID) |
| 75 | if (isChild(parent)) { |
| 76 | parent = await Session.get(parent.benchmark.parentID) |
| 77 | } |
| 78 | if (isParent(parent)) { |
| 79 | await stop({ sessionID: parent.id }) |
| 80 | } |
| 81 | |
| 82 | const models = await resolveModels({ |
| 83 | sessionID: parent.id, |
| 84 | models: input.models, |
| 85 | count: input.count, |
| 86 | }) |
| 87 | |
| 88 | if (!input.allowDuplicates && hasDuplicates(models)) { |
| 89 | throw new DuplicateModelsError({ |
| 90 | models: models.map((item) => `${item.providerID}/${item.modelID}`), |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | const baseSnapshot = await Snapshot.track() |
| 95 | if (!baseSnapshot) { |
| 96 | throw new SnapshotUnavailableError({ |
| 97 | message: "Benchmark mode requires snapshots (git) to be enabled.", |
| 98 | }) |
| 99 | } |
| 100 | |
| 101 | // Create worktree root directory |
| 102 | const worktreeRoot = path.join(Global.Path.data, "benchmark", parent.id) |
| 103 | await fs.mkdir(worktreeRoot, { recursive: true }) |
| 104 | |
| 105 | // Create base worktree (+1 worktree for initial codebase) |
| 106 | const baseWorktree = path.join(worktreeRoot, "base") |
| 107 | await fs.mkdir(baseWorktree, { recursive: true }) |
| 108 | await Snapshot.restoreTo(baseSnapshot, baseWorktree, { cleanUntracked: true }) |
| 109 | |
| 110 | const children: BenchmarkSchema.Child[] = [] |
| 111 | for (const model of models) { |
| 112 | const title = `Benchmark - ${model.providerID}/${model.modelID} - ${new Date().toISOString()}` |
| 113 | const childID = Identifier.descending("session") |
| 114 | const childWorktree = path.join(worktreeRoot, childID) |
| 115 | const child = await Session.createNext({ |
| 116 | id: childID, |
| 117 | parentID: parent.id, |
| 118 | directory: childWorktree, |
| 119 | title, |
| 120 | }) |
| 121 | await fs.mkdir(childWorktree, { recursive: true }) |
| 122 | await Snapshot.restoreTo(baseSnapshot, childWorktree, { cleanUntracked: true }) |
| 123 | await Session.update(child.id, (draft) => { |
| 124 | draft.benchmark = { |
| 125 | type: "child", |
nothing calls this directly
no test coverage detected