oh-my-copilot 5.25.2 → 5.26.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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/bridge/claude-md-coordinator.cjs +2 -2
- package/bridge/cli.cjs +9249 -4138
- package/bridge/mcp-server.cjs +4894 -1400
- package/bridge/runtime-cli.cjs +14 -9
- package/bridge/team-mcp.cjs +3 -2
- package/bridge/team.js +14 -9
- package/dist/cli/commands/factory-bench.d.ts +10 -0
- package/dist/cli/commands/factory-bench.d.ts.map +1 -0
- package/dist/cli/commands/factory-bench.js +122 -0
- package/dist/cli/commands/factory-bench.js.map +1 -0
- package/dist/cli/commands/factory-dashboard.d.ts +14 -0
- package/dist/cli/commands/factory-dashboard.d.ts.map +1 -0
- package/dist/cli/commands/factory-dashboard.js +51 -0
- package/dist/cli/commands/factory-dashboard.js.map +1 -0
- package/dist/cli/commands/factory.d.ts.map +1 -1
- package/dist/cli/commands/factory.js +10 -2
- package/dist/cli/commands/factory.js.map +1 -1
- package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.js +64 -0
- package/dist/copilot-run/__tests__/job.fail-closed.test.js.map +1 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.d.ts +2 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.d.ts.map +1 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.js +47 -0
- package/dist/copilot-run/__tests__/job.large-tree.test.js.map +1 -0
- package/dist/copilot-run/__tests__/sandbox.test.js +125 -1
- package/dist/copilot-run/__tests__/sandbox.test.js.map +1 -1
- package/dist/copilot-run/job.d.ts.map +1 -1
- package/dist/copilot-run/job.js +14 -3
- package/dist/copilot-run/job.js.map +1 -1
- package/dist/copilot-run/sandbox.d.ts +53 -0
- package/dist/copilot-run/sandbox.d.ts.map +1 -1
- package/dist/copilot-run/sandbox.js +176 -14
- package/dist/copilot-run/sandbox.js.map +1 -1
- package/dist/factory/bench/__tests__/bench.fake.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.fake.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.fake.test.js +87 -0
- package/dist/factory/bench/__tests__/bench.fake.test.js.map +1 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.js +54 -0
- package/dist/factory/bench/__tests__/bench.smoke.test.js.map +1 -0
- package/dist/factory/bench/__tests__/bench.units.test.d.ts +2 -0
- package/dist/factory/bench/__tests__/bench.units.test.d.ts.map +1 -0
- package/dist/factory/bench/__tests__/bench.units.test.js +842 -0
- package/dist/factory/bench/__tests__/bench.units.test.js.map +1 -0
- package/dist/factory/bench/fake-lanes.d.ts +39 -0
- package/dist/factory/bench/fake-lanes.d.ts.map +1 -0
- package/dist/factory/bench/fake-lanes.js +127 -0
- package/dist/factory/bench/fake-lanes.js.map +1 -0
- package/dist/factory/bench/fixture.d.ts +55 -0
- package/dist/factory/bench/fixture.d.ts.map +1 -0
- package/dist/factory/bench/fixture.js +128 -0
- package/dist/factory/bench/fixture.js.map +1 -0
- package/dist/factory/bench/model-probe.d.ts +37 -0
- package/dist/factory/bench/model-probe.d.ts.map +1 -0
- package/dist/factory/bench/model-probe.js +148 -0
- package/dist/factory/bench/model-probe.js.map +1 -0
- package/dist/factory/bench/runner.d.ts +163 -0
- package/dist/factory/bench/runner.d.ts.map +1 -0
- package/dist/factory/bench/runner.js +687 -0
- package/dist/factory/bench/runner.js.map +1 -0
- package/dist/factory/bench/score.d.ts +211 -0
- package/dist/factory/bench/score.d.ts.map +1 -0
- package/dist/factory/bench/score.js +386 -0
- package/dist/factory/bench/score.js.map +1 -0
- package/dist/factory/bench/seed/issues.d.ts +51 -0
- package/dist/factory/bench/seed/issues.d.ts.map +1 -0
- package/dist/factory/bench/seed/issues.js +536 -0
- package/dist/factory/bench/seed/issues.js.map +1 -0
- package/dist/factory/bench/seed/project.d.ts +24 -0
- package/dist/factory/bench/seed/project.d.ts.map +1 -0
- package/dist/factory/bench/seed/project.js +216 -0
- package/dist/factory/bench/seed/project.js.map +1 -0
- package/dist/factory/check/__tests__/cli-local.test.js +17 -0
- package/dist/factory/check/__tests__/cli-local.test.js.map +1 -1
- package/dist/factory/check/cli.d.ts +14 -0
- package/dist/factory/check/cli.d.ts.map +1 -1
- package/dist/factory/check/cli.js +21 -0
- package/dist/factory/check/cli.js.map +1 -1
- package/dist/factory/dashboard/__tests__/dashboard.test.d.ts +2 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.d.ts.map +1 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.js +148 -0
- package/dist/factory/dashboard/__tests__/dashboard.test.js.map +1 -0
- package/dist/factory/dashboard/collect.d.ts +96 -0
- package/dist/factory/dashboard/collect.d.ts.map +1 -0
- package/dist/factory/dashboard/collect.js +234 -0
- package/dist/factory/dashboard/collect.js.map +1 -0
- package/dist/factory/dashboard/render.d.ts +11 -0
- package/dist/factory/dashboard/render.d.ts.map +1 -0
- package/dist/factory/dashboard/render.js +77 -0
- package/dist/factory/dashboard/render.js.map +1 -0
- package/dist/factory/poll.d.ts +2 -0
- package/dist/factory/poll.d.ts.map +1 -1
- package/dist/factory/poll.js +2 -2
- package/dist/factory/poll.js.map +1 -1
- package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts +2 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.js +131 -0
- package/dist/factory/run/__tests__/auto-merge-flaky.test.js.map +1 -0
- package/dist/factory/run/__tests__/auto-merge.test.d.ts +2 -0
- package/dist/factory/run/__tests__/auto-merge.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/auto-merge.test.js +541 -0
- package/dist/factory/run/__tests__/auto-merge.test.js.map +1 -0
- package/dist/factory/run/__tests__/container-gate.test.d.ts +2 -0
- package/dist/factory/run/__tests__/container-gate.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/container-gate.test.js +733 -0
- package/dist/factory/run/__tests__/container-gate.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.js +142 -0
- package/dist/factory/run/__tests__/engine.auto-merge.github.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.js +245 -0
- package/dist/factory/run/__tests__/engine.gates-container.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js +71 -0
- package/dist/factory/run/__tests__/engine.gates-git-view-fail.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.js +141 -0
- package/dist/factory/run/__tests__/engine.gates-git-view.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.js +130 -0
- package/dist/factory/run/__tests__/engine.gates-workspace.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.human-review.test.js +4 -4
- package/dist/factory/run/__tests__/engine.human-review.test.js.map +1 -1
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts +2 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.js +196 -0
- package/dist/factory/run/__tests__/engine.local.auto-merge.test.js.map +1 -0
- package/dist/factory/run/__tests__/engine.private.test.js +17 -0
- package/dist/factory/run/__tests__/engine.private.test.js.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.d.ts +2 -0
- package/dist/factory/run/__tests__/fake-lanes.d.ts.map +1 -1
- package/dist/factory/run/__tests__/fake-lanes.js +6 -1
- package/dist/factory/run/__tests__/fake-lanes.js.map +1 -1
- package/dist/factory/run/__tests__/git-view.test.d.ts +2 -0
- package/dist/factory/run/__tests__/git-view.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/git-view.test.js +120 -0
- package/dist/factory/run/__tests__/git-view.test.js.map +1 -0
- package/dist/factory/run/__tests__/merge-policy.test.js +10 -0
- package/dist/factory/run/__tests__/merge-policy.test.js.map +1 -1
- package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js +2 -0
- package/dist/factory/run/__tests__/prepare-gates.gates-resume.test.js.map +1 -1
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts +2 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js +103 -0
- package/dist/factory/run/__tests__/prepare-gates.moving-base.test.js.map +1 -0
- package/dist/factory/run/__tests__/private-run.test.js +37 -1
- package/dist/factory/run/__tests__/private-run.test.js.map +1 -1
- package/dist/factory/run/__tests__/units.test.js +8 -1
- package/dist/factory/run/__tests__/units.test.js.map +1 -1
- package/dist/factory/run/__tests__/workspace-tree.test.d.ts +2 -0
- package/dist/factory/run/__tests__/workspace-tree.test.d.ts.map +1 -0
- package/dist/factory/run/__tests__/workspace-tree.test.js +325 -0
- package/dist/factory/run/__tests__/workspace-tree.test.js.map +1 -0
- package/dist/factory/run/auto-merge.d.ts +254 -0
- package/dist/factory/run/auto-merge.d.ts.map +1 -0
- package/dist/factory/run/auto-merge.js +785 -0
- package/dist/factory/run/auto-merge.js.map +1 -0
- package/dist/factory/run/budget.d.ts +14 -0
- package/dist/factory/run/budget.d.ts.map +1 -1
- package/dist/factory/run/budget.js +24 -0
- package/dist/factory/run/budget.js.map +1 -1
- package/dist/factory/run/clean.d.ts +3 -0
- package/dist/factory/run/clean.d.ts.map +1 -1
- package/dist/factory/run/clean.js +34 -0
- package/dist/factory/run/clean.js.map +1 -1
- package/dist/factory/run/container-gate.d.ts +230 -0
- package/dist/factory/run/container-gate.d.ts.map +1 -0
- package/dist/factory/run/container-gate.js +1076 -0
- package/dist/factory/run/container-gate.js.map +1 -0
- package/dist/factory/run/engine.d.ts +5 -1
- package/dist/factory/run/engine.d.ts.map +1 -1
- package/dist/factory/run/engine.js +582 -40
- package/dist/factory/run/engine.js.map +1 -1
- package/dist/factory/run/exec.d.ts +5 -0
- package/dist/factory/run/exec.d.ts.map +1 -1
- package/dist/factory/run/exec.js +17 -3
- package/dist/factory/run/exec.js.map +1 -1
- package/dist/factory/run/git-view.d.ts +39 -0
- package/dist/factory/run/git-view.d.ts.map +1 -0
- package/dist/factory/run/git-view.js +77 -0
- package/dist/factory/run/git-view.js.map +1 -0
- package/dist/factory/run/lane-commit.d.ts +2 -0
- package/dist/factory/run/lane-commit.d.ts.map +1 -1
- package/dist/factory/run/lane-commit.js +3 -1
- package/dist/factory/run/lane-commit.js.map +1 -1
- package/dist/factory/run/local-gate.d.ts +1 -0
- package/dist/factory/run/local-gate.d.ts.map +1 -1
- package/dist/factory/run/local-gate.js +2 -1
- package/dist/factory/run/local-gate.js.map +1 -1
- package/dist/factory/run/merge-policy.d.ts +24 -6
- package/dist/factory/run/merge-policy.d.ts.map +1 -1
- package/dist/factory/run/merge-policy.js +29 -7
- package/dist/factory/run/merge-policy.js.map +1 -1
- package/dist/factory/run/prepare.d.ts +27 -1
- package/dist/factory/run/prepare.d.ts.map +1 -1
- package/dist/factory/run/prepare.js +241 -28
- package/dist/factory/run/prepare.js.map +1 -1
- package/dist/factory/run/private-run.d.ts +7 -0
- package/dist/factory/run/private-run.d.ts.map +1 -1
- package/dist/factory/run/private-run.js +34 -3
- package/dist/factory/run/private-run.js.map +1 -1
- package/dist/factory/run/private-store.d.ts +2 -0
- package/dist/factory/run/private-store.d.ts.map +1 -1
- package/dist/factory/run/private-store.js +2 -1
- package/dist/factory/run/private-store.js.map +1 -1
- package/dist/factory/run/sandbox-exec.d.ts +22 -1
- package/dist/factory/run/sandbox-exec.d.ts.map +1 -1
- package/dist/factory/run/sandbox-exec.js +9 -0
- package/dist/factory/run/sandbox-exec.js.map +1 -1
- package/dist/factory/run/workspace-tree.d.ts +75 -0
- package/dist/factory/run/workspace-tree.d.ts.map +1 -0
- package/dist/factory/run/workspace-tree.js +299 -0
- package/dist/factory/run/workspace-tree.js.map +1 -0
- package/dist/forge/__tests__/gh-argv-baseline.factory.test.js +7 -5
- package/dist/forge/__tests__/gh-argv-baseline.factory.test.js.map +1 -1
- package/dist/forge/github/__tests__/required-checks.test.js +22 -1
- package/dist/forge/github/__tests__/required-checks.test.js.map +1 -1
- package/dist/forge/github/checks.d.ts +9 -0
- package/dist/forge/github/checks.d.ts.map +1 -1
- package/dist/forge/github/checks.js +26 -0
- package/dist/forge/github/checks.js.map +1 -1
- package/dist/forge/github/merge.d.ts +27 -0
- package/dist/forge/github/merge.d.ts.map +1 -1
- package/dist/forge/github/merge.js +44 -0
- package/dist/forge/github/merge.js.map +1 -1
- package/dist/forge/github/reviews.d.ts +2 -0
- package/dist/forge/github/reviews.d.ts.map +1 -1
- package/dist/forge/github/reviews.js.map +1 -1
- package/dist/smoke/copilot-factory-run-scenario.d.ts.map +1 -1
- package/dist/smoke/copilot-factory-run-scenario.js +4 -0
- package/dist/smoke/copilot-factory-run-scenario.js.map +1 -1
- package/dist/team/git-worktree.d.ts +8 -1
- package/dist/team/git-worktree.d.ts.map +1 -1
- package/dist/team/git-worktree.js +9 -2
- package/dist/team/git-worktree.js.map +1 -1
- package/dist/team/merge-coordinator.js +5 -5
- package/dist/team/merge-coordinator.js.map +1 -1
- package/dist/team/merge-orchestrator.d.ts.map +1 -1
- package/dist/team/merge-orchestrator.js +3 -1
- package/dist/team/merge-orchestrator.js.map +1 -1
- package/dist/team/runtime-v2.d.ts.map +1 -1
- package/dist/team/runtime-v2.js +2 -2
- package/dist/team/runtime-v2.js.map +1 -1
- package/docs/CLAUDE.md +1 -1
- package/docs/REFERENCE.md +133 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
|
@@ -0,0 +1,687 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `omg factory bench run`: drive the factory over the bench fixture until
|
|
3
|
+
* every issue is terminal, parked or never runnable, or a cap is hit; then
|
|
4
|
+
* score each issue (score.ts) and write `<out>/<timestamp>.json` + `.md`.
|
|
5
|
+
*
|
|
6
|
+
* - `--fake`: in-process. Each pick is omg factory check's order over the
|
|
7
|
+
* fixture backlog (the same rules `run --next` uses), each run is
|
|
8
|
+
* runFactoryEngine with the issue's scripted lanes (fake-lanes.ts), the
|
|
9
|
+
* engine's own state, ledger and forge state under the bench dir, no user
|
|
10
|
+
* config. Prepare checks, the local gate and the acceptance run as plain
|
|
11
|
+
* processes: every line of code in the fixture is the bench's own. Zero cost.
|
|
12
|
+
* - `--live --max-requests N`: real Copilot. The bench picks like `run
|
|
13
|
+
* --next` (omg factory check's order, limited to `--issues`) and starts a
|
|
14
|
+
* child `omg factory run <id> --json --max-requests <left>` in the fixture
|
|
15
|
+
* repository (poll's auto-start child), so the user's own factory config,
|
|
16
|
+
* sandbox and lanes apply; with `--parallel N` up to N children at once
|
|
17
|
+
* (each takes a run slot: the user config must enable parallel runs). The
|
|
18
|
+
* per-run cap is HARD in the engine (budget.ts nextLaneCap): no lane starts
|
|
19
|
+
* once the run's lanes recorded the cap, or when a lane's usage is unknown.
|
|
20
|
+
* Usage is the largest of the fixture budget ledger's delta, the lanes in
|
|
21
|
+
* the run states and MIN_RUN_REQUESTS per finished run. The remaining bound:
|
|
22
|
+
* each run can finish the one lane in flight when it reaches its cap. A run
|
|
23
|
+
* in flight is never killed (on Windows a kill orphans its Copilot child).
|
|
24
|
+
* The acceptance runs in the gate sandbox (createSandboxRunner, no model
|
|
25
|
+
* turn); --live refuses unless the gate sandbox is enforced (or the
|
|
26
|
+
* container isolation is on).
|
|
27
|
+
*/
|
|
28
|
+
import { randomBytes } from 'node:crypto';
|
|
29
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
|
|
30
|
+
import { join, resolve, sep } from 'node:path';
|
|
31
|
+
import { ledgerPath, ledgerTotals, parseLedger } from '../../budget/ledger.js';
|
|
32
|
+
import { resolveGateIsolation, resolveGatesSandboxMode } from '../../copilot-run/sandbox.js';
|
|
33
|
+
import { createForge } from '../../forge/index.js';
|
|
34
|
+
import { resolveForgeConfig } from '../../forge/config.js';
|
|
35
|
+
import { LOCAL_REMOTE, readMirrorRef } from '../../forge/local/index.js';
|
|
36
|
+
import { getRuntimePackageVersion } from '../../lib/version.js';
|
|
37
|
+
import { loadBaseKnownFlaky, loadTrustedShipConfig, readBaseFile, userConfigLayers } from '../../ship/config.js';
|
|
38
|
+
import { defaultExec, TRUSTED_READ_ENV } from '../../ship/exec.js';
|
|
39
|
+
import { parseJsonc } from '../../utils/jsonc.js';
|
|
40
|
+
import { checkEnvFor, forgeReadExec, localBase, readForgeOptions } from '../check/cli.js';
|
|
41
|
+
import { checkItems } from '../check/score.js';
|
|
42
|
+
import { defaultPollAutoStart, pollParallel } from '../poll.js';
|
|
43
|
+
import { DEFAULT_FACTORY_RUN_LIMITS, laneRequestsUnknown } from '../run/budget.js';
|
|
44
|
+
import { runFactoryEngine } from '../run/engine.js';
|
|
45
|
+
import { factoryForgeOptions, loadFactoryForgeConfig } from '../run/forge-roots.js';
|
|
46
|
+
import { defaultLedgerDir } from '../run/ledger.js';
|
|
47
|
+
import { defaultLocalGateRunner, resolveLocalGateArgv } from '../run/local-gate.js';
|
|
48
|
+
import { linkNodeModules, unlinkNodeModules } from '../run/prepare.js';
|
|
49
|
+
import { createSandboxRunner } from '../run/sandbox-exec.js';
|
|
50
|
+
import { factoryBranch, readFactoryState } from '../run/state.js';
|
|
51
|
+
import { factoryGuardExec } from '../run/exec.js';
|
|
52
|
+
import { BENCH_FAKE_PROCESSES, BenchFakeLanes } from './fake-lanes.js';
|
|
53
|
+
import { fillPlaceholders, readFixtureMeta, removeBenchDir } from './fixture.js';
|
|
54
|
+
import { multiplierRefusal, probeLaneModel } from './model-probe.js';
|
|
55
|
+
import { BENCH_ISSUES } from './seed/issues.js';
|
|
56
|
+
import { ACCEPTANCE_TEST_PATH, BENCH_FIXTURE_VERSION } from './seed/project.js';
|
|
57
|
+
import { BENCH_RESULTS_KIND, BENCH_RESULTS_SCHEMA_VERSION, computeTotals, issuePasses, laneUsage, outcomeOf, phaseTimes, renderResultsMarkdown, trapContainment, trapVerdict, } from './score.js';
|
|
58
|
+
/** The fewest premium requests a run spends (an implement and a review lane): the headroom a live start needs. */
|
|
59
|
+
export const MIN_RUN_REQUESTS = 2;
|
|
60
|
+
export const DEFAULT_BENCH_MAX_MINUTES = 240;
|
|
61
|
+
/** How long one acceptance run may take. */
|
|
62
|
+
export const ACCEPTANCE_TIMEOUT_MS = 10 * 60_000;
|
|
63
|
+
/** Busy children (exit 6: another engine holds the lock or every slot) in a row before the bench stops. */
|
|
64
|
+
export const MAX_BUSY_STREAK = 3;
|
|
65
|
+
/** The wait after a busy child, times the streak. */
|
|
66
|
+
export const BUSY_BACKOFF_MS = 5_000;
|
|
67
|
+
/** The overshoot bound, in the results notes and the CLI help. */
|
|
68
|
+
export const LIVE_CAP_BOUND = 'each run gets the requests left as its own hard cap (omg factory run --max-requests): it starts no lane once its lanes recorded that many, so the bench can end above --max-requests only by the one lane each run has in flight when it reaches its cap';
|
|
69
|
+
export class BenchUsageError extends Error {
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The fake mode's gate runner: the command as a plain process (no shell,
|
|
73
|
+
* the gate's scrubbed env), for every purpose. Only the bench's own fixture
|
|
74
|
+
* code ever runs through it.
|
|
75
|
+
*/
|
|
76
|
+
export const plainGateRunner = async (req) => {
|
|
77
|
+
const r = await defaultLocalGateRunner(req.argv, req.cwd, req.timeoutMs);
|
|
78
|
+
if (r.startError !== undefined)
|
|
79
|
+
return { ran: false, reason: r.startError };
|
|
80
|
+
return { ran: true, status: r.timedOut ? 124 : r.status, output: `${r.stdout}${r.stderr ? `\n${r.stderr}` : ''}`, timedOut: r.timedOut };
|
|
81
|
+
};
|
|
82
|
+
/** Ship's strict safety-key loader on the local mirror, with no user config: the fixture's committed base only. */
|
|
83
|
+
const benchGateConfig = (i) => {
|
|
84
|
+
const config = loadTrustedShipConfig({
|
|
85
|
+
exec: i.exec, root: i.root, base: i.base, baseSha: i.baseSha, repoUrl: i.repoUrl, strict: true, remote: LOCAL_REMOTE, user: null, trustedUser: null, warn: i.warn,
|
|
86
|
+
});
|
|
87
|
+
return { config, known: loadBaseKnownFlaky(i.exec, i.root, config.trustedBaseCommit, config.knownFlakyFile) };
|
|
88
|
+
};
|
|
89
|
+
/** The fixture's committed `.copilot/omg.jsonc` at its base commit (the trusted base layer). */
|
|
90
|
+
function fixtureBaseConfig(meta, exec = defaultExec) {
|
|
91
|
+
const text = readBaseFile(exec, meta.root, meta.baseSha, '.copilot/omg.jsonc');
|
|
92
|
+
if (!text)
|
|
93
|
+
throw new Error(`omg factory bench: the fixture's .copilot/omg.jsonc is missing at ${meta.baseSha.slice(0, 12)}`);
|
|
94
|
+
return parseJsonc(text);
|
|
95
|
+
}
|
|
96
|
+
/** The fake mode's forge: the fixture's committed config only, its state under the bench dir. */
|
|
97
|
+
export function fakeForgeConfig(meta, stateDir, exec = defaultExec) {
|
|
98
|
+
return resolveForgeConfig(null, fixtureBaseConfig(meta, exec), undefined, undefined, { root: meta.root, stateDir }).config;
|
|
99
|
+
}
|
|
100
|
+
/** omg factory check's verdict on every bench item, at the base (the order run --next picks in). */
|
|
101
|
+
export function checkBacklog(exec, root, base, config) {
|
|
102
|
+
const read = forgeReadExec(exec, config, root);
|
|
103
|
+
const warnings = [];
|
|
104
|
+
const baseSha = localBase(read.exec, root, base, warnings);
|
|
105
|
+
if (!baseSha)
|
|
106
|
+
throw new Error(warnings.join('; ') || `omg factory bench: no ${base} branch in ${root}`);
|
|
107
|
+
const forge = createForge(read.exec, root, config, readForgeOptions(config, root, read.options, base, baseSha, false));
|
|
108
|
+
if (!config.intake.source)
|
|
109
|
+
throw new Error('omg factory bench: the fixture config has no factory.intake.source');
|
|
110
|
+
const ids = forge.tracker.queryItems(config.intake.source, config.intake.limit);
|
|
111
|
+
return checkItems(forge, ids, checkEnvFor(read.exec, root, config, base, baseSha));
|
|
112
|
+
}
|
|
113
|
+
/** `--issues 2,9,10`: known bench ids, no repeats; null for every issue. */
|
|
114
|
+
export function benchSubset(ids) {
|
|
115
|
+
if (ids === undefined)
|
|
116
|
+
return null;
|
|
117
|
+
const known = new Set(BENCH_ISSUES.map((i) => i.id));
|
|
118
|
+
if (ids.length === 0)
|
|
119
|
+
throw new BenchUsageError('--issues needs at least one issue id');
|
|
120
|
+
const bad = ids.filter((id) => !Number.isSafeInteger(id) || !known.has(id));
|
|
121
|
+
if (bad.length)
|
|
122
|
+
throw new BenchUsageError(`--issues: no bench issue ${bad.join(', ')} (the ids are ${[...known].join(', ')})`);
|
|
123
|
+
if (new Set(ids).size !== ids.length)
|
|
124
|
+
throw new BenchUsageError('--issues names an issue twice');
|
|
125
|
+
return [...ids].sort((a, b) => a - b);
|
|
126
|
+
}
|
|
127
|
+
/** The CLI form of --issues: comma-separated ids. */
|
|
128
|
+
export function parseIssueList(raw) {
|
|
129
|
+
const parts = raw.split(',').map((s) => s.trim());
|
|
130
|
+
if (parts.some((p) => !/^[1-9]\d{0,5}$/.test(p)))
|
|
131
|
+
throw new BenchUsageError(`--issues ${JSON.stringify(raw)} is not a comma-separated list of issue ids`);
|
|
132
|
+
return parts.map(Number);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* `--live` runs the lanes' code in prepare checks, the local gate and the
|
|
136
|
+
* acceptance: it needs the gate sandbox enforced (factory.run.sandbox.gates,
|
|
137
|
+
* the user config then the fixture's base), or the container isolation of
|
|
138
|
+
* the user config with gates not "unsandboxed" (the engine moves only "ack"
|
|
139
|
+
* into the container; "unsandboxed" still runs gate commands on the host).
|
|
140
|
+
* Either setting that does not resolve refuses. Null when allowed, else why not.
|
|
141
|
+
*/
|
|
142
|
+
export function liveSandboxRefusal(trustedUser, base) {
|
|
143
|
+
let mode;
|
|
144
|
+
let container;
|
|
145
|
+
try {
|
|
146
|
+
mode = resolveGatesSandboxMode({ user: trustedUser, base, env: process.env });
|
|
147
|
+
container = resolveGateIsolation({ user: trustedUser, base }).container !== undefined;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return `the gate sandbox setting does not resolve (${error instanceof Error ? error.message : String(error)})`;
|
|
151
|
+
}
|
|
152
|
+
if (mode.mode === 'enforced')
|
|
153
|
+
return null;
|
|
154
|
+
if (container && mode.mode !== 'unsandboxed')
|
|
155
|
+
return null;
|
|
156
|
+
return `--live runs the lanes' code in prepare checks, the local gate and the acceptance test, so it needs factory.run.sandbox.gates "enforced", or factory.run.sandbox.isolation "container" in your user config with gates not "unsandboxed" (gates is "${mode.mode}" from ${mode.source}; isolation is ${container ? '"container"' : 'not "container"'})`;
|
|
157
|
+
}
|
|
158
|
+
/** The number of `it(` / `test(` calls at a line start of a hidden test: the passes the acceptance must report. */
|
|
159
|
+
export const expectedTests = (test) => (test.match(/^\s*(?:it|test)\(/gm) ?? []).length;
|
|
160
|
+
const refused = (detail) => ({ ran: false, passed: false, status: null, detail: `refused: ${detail}` });
|
|
161
|
+
/**
|
|
162
|
+
* Run the issue's hidden test on a scratch clone of the PR head from the
|
|
163
|
+
* mirror, through `runner`, with a harness-owned vitest config (the head's
|
|
164
|
+
* vitest/vite config, setup files and aliases are never loaded) and the JSON
|
|
165
|
+
* reporter: the run passes only with exit 0 and every expected test passed.
|
|
166
|
+
* The clone checks out links as plain files (core.symlinks=false), and a
|
|
167
|
+
* head that tracks node_modules, turns test/ into a link or a file, or
|
|
168
|
+
* changes package.json `type` / `imports` is refused. Never throws.
|
|
169
|
+
*/
|
|
170
|
+
export async function runAcceptance(o) {
|
|
171
|
+
const exec = o.exec ?? defaultExec;
|
|
172
|
+
let scratch;
|
|
173
|
+
let co;
|
|
174
|
+
try {
|
|
175
|
+
scratch = mkdtempSync(join(o.benchDir, 'accept-'));
|
|
176
|
+
co = join(scratch, 'co');
|
|
177
|
+
const noHooks = join(scratch, 'no-hooks');
|
|
178
|
+
mkdirSync(noHooks);
|
|
179
|
+
const clone = exec('git', ['-c', `core.hooksPath=${noHooks}`, '-c', 'core.symlinks=false', '-c', 'core.autocrlf=false', 'clone', '--quiet', '--no-hardlinks', '--branch', o.branch, o.mirror, co], { env: TRUSTED_READ_ENV });
|
|
180
|
+
if (clone.status !== 0)
|
|
181
|
+
return { ran: false, passed: false, status: null, detail: `git clone of ${o.branch} failed: ${clone.stderr.trim().slice(0, 300)}` };
|
|
182
|
+
const at = exec('git', ['-C', co, 'rev-parse', 'HEAD'], { env: TRUSTED_READ_ENV }).stdout.trim();
|
|
183
|
+
if (at !== o.head)
|
|
184
|
+
return { ran: false, passed: false, status: null, detail: `the mirror's ${o.branch} is ${at.slice(0, 12)}, not the recorded head ${o.head.slice(0, 12)}` };
|
|
185
|
+
const lst = (p) => lstatSync(p, { throwIfNoEntry: false });
|
|
186
|
+
// The harness's node_modules (the fixture's, read-only linked) and package.json rules, never the head's.
|
|
187
|
+
// Any depth: a nested node_modules (test/node_modules/vitest) would shadow the harness's packages.
|
|
188
|
+
const tracked = exec('git', ['-C', co, 'ls-files', '--', 'node_modules', ':(glob)**/node_modules', ':(glob)**/node_modules/**'], { env: TRUSTED_READ_ENV });
|
|
189
|
+
if (tracked.status !== 0 || tracked.stdout.trim())
|
|
190
|
+
return refused('the PR head tracks a node_modules path');
|
|
191
|
+
if (lst(join(co, 'node_modules')))
|
|
192
|
+
return refused('the PR head has a node_modules entry');
|
|
193
|
+
const pkgField = (text) => {
|
|
194
|
+
const j = JSON.parse(text ?? '{}');
|
|
195
|
+
return JSON.stringify([j.type ?? null, j.imports ?? null]);
|
|
196
|
+
};
|
|
197
|
+
const pkg = lst(join(co, 'package.json'));
|
|
198
|
+
if (!pkg?.isFile())
|
|
199
|
+
return refused('the PR head\'s package.json is not a regular file');
|
|
200
|
+
let same = false;
|
|
201
|
+
try {
|
|
202
|
+
same = pkgField(readFileSync(join(co, 'package.json'), 'utf8')) === pkgField(readBaseFile(exec, co, o.meta.baseSha, 'package.json'));
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
same = false;
|
|
206
|
+
}
|
|
207
|
+
if (!same)
|
|
208
|
+
return refused('the PR head changes package.json "type" or "imports" (or it does not parse)');
|
|
209
|
+
// The hidden test: test/ must be a real directory inside the checkout; the file is written fresh, never through a link.
|
|
210
|
+
const testDir = join(co, 'test');
|
|
211
|
+
const dirSt = lst(testDir);
|
|
212
|
+
if (dirSt && (dirSt.isSymbolicLink() || !dirSt.isDirectory()))
|
|
213
|
+
return refused('test/ in the PR head is a link or not a directory');
|
|
214
|
+
if (!dirSt)
|
|
215
|
+
mkdirSync(testDir);
|
|
216
|
+
if (!realpathSync(testDir).startsWith(realpathSync(co) + sep))
|
|
217
|
+
return refused('test/ resolves outside the checkout');
|
|
218
|
+
const testPath = join(co, ...ACCEPTANCE_TEST_PATH.split('/'));
|
|
219
|
+
const fileSt = lst(testPath);
|
|
220
|
+
if (fileSt && !fileSt.isFile())
|
|
221
|
+
return refused(`${ACCEPTANCE_TEST_PATH} in the PR head is a link or not a regular file`);
|
|
222
|
+
if (fileSt)
|
|
223
|
+
rmSync(testPath);
|
|
224
|
+
writeFileSync(testPath, o.test, { flag: 'wx' });
|
|
225
|
+
// A harness-owned config: only the hidden test, no setup files, no aliases, no plugins, no .env or PostCSS lookups.
|
|
226
|
+
const tag = randomBytes(6).toString('hex');
|
|
227
|
+
const configName = `.bench-accept-${tag}.config.mjs`;
|
|
228
|
+
const reportName = `.bench-accept-${tag}.json`;
|
|
229
|
+
const config = {
|
|
230
|
+
plugins: [], resolve: { alias: [] }, css: { postcss: {} }, envDir: join(co, `.bench-no-env-${tag}`),
|
|
231
|
+
test: { include: [ACCEPTANCE_TEST_PATH], exclude: [], setupFiles: [], globalSetup: [], alias: [], passWithNoTests: false, watch: false },
|
|
232
|
+
};
|
|
233
|
+
writeFileSync(join(co, configName), `export default ${JSON.stringify(config)};\n`, { flag: 'wx' });
|
|
234
|
+
linkNodeModules(o.meta.root, co);
|
|
235
|
+
const argv = ['node', 'node_modules/vitest/vitest.mjs', 'run', '--config', configName, '--reporter=json', `--outputFile=${reportName}`];
|
|
236
|
+
const target = resolveLocalGateArgv(argv, { cwd: co });
|
|
237
|
+
if ('missing' in target)
|
|
238
|
+
return { ran: false, passed: false, status: null, detail: target.missing };
|
|
239
|
+
const r = await o.runner({
|
|
240
|
+
purpose: 'gate', argv, exe: target.exe, args: target.args, cwd: co, commonGitDir: join(co, '.git'),
|
|
241
|
+
timeoutMs: o.timeoutMs ?? ACCEPTANCE_TIMEOUT_MS, nodeModulesTarget: join(o.meta.root, 'node_modules'),
|
|
242
|
+
});
|
|
243
|
+
if (!r.ran)
|
|
244
|
+
return { ran: false, passed: false, status: null, detail: r.reason };
|
|
245
|
+
const expected = expectedTests(o.test);
|
|
246
|
+
let report = null;
|
|
247
|
+
try {
|
|
248
|
+
report = JSON.parse(readFileSync(join(co, reportName), 'utf8'));
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
report = null;
|
|
252
|
+
}
|
|
253
|
+
const files = Array.isArray(report?.testResults) ? report.testResults.map((t) => String(t?.name ?? '').replace(/\\/g, '/')) : [];
|
|
254
|
+
const verdict = report === null ? 'no JSON report'
|
|
255
|
+
: report.numFailedTests !== 0 ? `${String(report.numFailedTests)} failed`
|
|
256
|
+
: files.length !== 1 || !files[0].endsWith(`/${ACCEPTANCE_TEST_PATH}`) ? `the report covers ${files.length} files, not the hidden test alone`
|
|
257
|
+
: expected > 0 && (report.numPassedTests !== expected || report.numTotalTests !== expected) ? `${String(report.numPassedTests)} of ${String(report.numTotalTests)} passed, ${expected} expected`
|
|
258
|
+
: expected === 0 && !(typeof report.numPassedTests === 'number' && report.numPassedTests > 0) ? 'no test passed' : null;
|
|
259
|
+
const passed = r.status === 0 && !r.timedOut && verdict === null;
|
|
260
|
+
return {
|
|
261
|
+
ran: true, passed, status: r.status, ...(r.timedOut ? { timedOut: true } : {}),
|
|
262
|
+
...(passed ? {} : { detail: `${verdict ? `${verdict}; ` : ''}${r.output.slice(-1_500)}` }),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
return { ran: false, passed: false, status: null, detail: `the acceptance could not run: ${error instanceof Error ? error.message : String(error)}` };
|
|
267
|
+
}
|
|
268
|
+
finally {
|
|
269
|
+
if (co)
|
|
270
|
+
try {
|
|
271
|
+
unlinkNodeModules(o.meta.root, co);
|
|
272
|
+
}
|
|
273
|
+
catch { /* removeBenchDir unlinks every link anyway */ }
|
|
274
|
+
if (scratch)
|
|
275
|
+
try {
|
|
276
|
+
removeBenchDir(scratch);
|
|
277
|
+
}
|
|
278
|
+
catch { /* left for the bench dir's own removal */ }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export const defaultLedger = (root) => {
|
|
282
|
+
const path = ledgerPath(root);
|
|
283
|
+
// No file yet (a fresh repository): nothing counted and no epoch. parseLedger's
|
|
284
|
+
// default ledger carries since = now, a new value on every read, which would
|
|
285
|
+
// look like a reset; ledgerTracker adopts the first real file's epoch instead.
|
|
286
|
+
if (!existsSync(path))
|
|
287
|
+
return { premiumRequests: 0, credits: 0, records: {} };
|
|
288
|
+
const { ledger, invalid } = parseLedger(path);
|
|
289
|
+
if (invalid)
|
|
290
|
+
throw new Error(`the budget ledger ${path} is unreadable; the bench cannot enforce --max-requests without it`);
|
|
291
|
+
const t = ledgerTotals(ledger);
|
|
292
|
+
const records = {};
|
|
293
|
+
const put = (key, r) => {
|
|
294
|
+
records[key] = { premiumRequests: Number(r.premiumRequests) || 0, credits: Number(r.credits) || 0, source: r.source === 'measured' ? 'measured' : 'estimated' };
|
|
295
|
+
};
|
|
296
|
+
for (const [k, r] of Object.entries(ledger.sessions))
|
|
297
|
+
put(`s:${k}`, r);
|
|
298
|
+
for (const [team, rs] of Object.entries(ledger.teams))
|
|
299
|
+
for (const [k, r] of Object.entries(rs))
|
|
300
|
+
put(`t:${team}:${k}`, r);
|
|
301
|
+
return { premiumRequests: t.premiumRequests, credits: t.credits, records, epoch: `${ledger.since}|${ledger.resetAt ?? ''}` };
|
|
302
|
+
};
|
|
303
|
+
/**
|
|
304
|
+
* The bench's ledger usage since `start`: per record the highest value seen
|
|
305
|
+
* (a 0x shutdown correction keeps the counted calls: never under), summed
|
|
306
|
+
* and minus the start. Throws on anything else that went down: a reset, a
|
|
307
|
+
* record removed, a drop that is not estimated -> measured. A start without
|
|
308
|
+
* a ledger file (no epoch) adopts the first epoch it sees and requires it
|
|
309
|
+
* from then on; a file that was seen and then disappears throws.
|
|
310
|
+
*/
|
|
311
|
+
export function ledgerTracker(start) {
|
|
312
|
+
const last = new Map(Object.entries(start.records ?? {}));
|
|
313
|
+
const high = new Map(last);
|
|
314
|
+
const base = { premiumRequests: start.premiumRequests, credits: start.credits };
|
|
315
|
+
let epoch = start.epoch;
|
|
316
|
+
return (now) => {
|
|
317
|
+
if (!start.records || !now.records) {
|
|
318
|
+
const delta = { premiumRequests: now.premiumRequests - base.premiumRequests, credits: now.credits - base.credits };
|
|
319
|
+
if (!(delta.premiumRequests >= 0) || !(delta.credits >= 0))
|
|
320
|
+
throw new Error(`the budget ledger went down since the bench started (${delta.premiumRequests} requests, ${delta.credits} credits); it cannot be trusted`);
|
|
321
|
+
return delta;
|
|
322
|
+
}
|
|
323
|
+
if (epoch !== undefined && now.epoch === undefined)
|
|
324
|
+
throw new Error('the budget ledger file disappeared since the bench started; it cannot be trusted');
|
|
325
|
+
if (epoch === undefined && now.epoch !== undefined)
|
|
326
|
+
epoch = now.epoch;
|
|
327
|
+
if (now.epoch !== epoch)
|
|
328
|
+
throw new Error('the budget ledger was reset since the bench started; it cannot be trusted');
|
|
329
|
+
for (const [key, was] of last) {
|
|
330
|
+
const is = now.records[key];
|
|
331
|
+
if (!is)
|
|
332
|
+
throw new Error(`the budget ledger record ${key} disappeared since the bench started; it cannot be trusted`);
|
|
333
|
+
const fell = is.premiumRequests < was.premiumRequests || is.credits < was.credits;
|
|
334
|
+
if (fell && !(was.source === 'estimated' && is.source === 'measured')) {
|
|
335
|
+
throw new Error(`the budget ledger record ${key} went down (${was.premiumRequests} -> ${is.premiumRequests} requests, ${was.credits} -> ${is.credits} credits) without a session.shutdown correction; it cannot be trusted`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
for (const [key, is] of Object.entries(now.records)) {
|
|
339
|
+
last.set(key, is);
|
|
340
|
+
const was = high.get(key);
|
|
341
|
+
high.set(key, was ? { premiumRequests: Math.max(was.premiumRequests, is.premiumRequests), credits: Math.max(was.credits, is.credits), source: is.source } : is);
|
|
342
|
+
}
|
|
343
|
+
let premiumRequests = 0;
|
|
344
|
+
let credits = 0;
|
|
345
|
+
for (const r of high.values()) {
|
|
346
|
+
premiumRequests += r.premiumRequests;
|
|
347
|
+
credits += r.credits;
|
|
348
|
+
}
|
|
349
|
+
for (const r of Object.values(start.records)) {
|
|
350
|
+
premiumRequests -= r.premiumRequests;
|
|
351
|
+
credits -= r.credits;
|
|
352
|
+
}
|
|
353
|
+
return { premiumRequests, credits };
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/** One issue's recorded lane usage from its run state (a lane with unknown requests, laneRequestsUnknown, counts one; unreadable: null). */
|
|
357
|
+
function issueUsage(root, id) {
|
|
358
|
+
let state;
|
|
359
|
+
try {
|
|
360
|
+
state = readFactoryState(root, id);
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
return null;
|
|
364
|
+
}
|
|
365
|
+
const lanes = state?.lanes ?? [];
|
|
366
|
+
return {
|
|
367
|
+
requests: lanes.reduce((n, l) => n + (laneRequestsUnknown(l) ? 1 : l.usage.premiumRequests), 0),
|
|
368
|
+
credits: lanes.reduce((n, l) => n + (l.usage?.credits ?? 0), 0),
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
export async function runBench(o) {
|
|
372
|
+
const now = o.now ?? (() => new Date());
|
|
373
|
+
const sleep = o.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
374
|
+
const t0 = now().getTime();
|
|
375
|
+
const log = (m) => o.log?.(`[${Math.round((now().getTime() - t0) / 1000)} s] ${m}`);
|
|
376
|
+
const benchDir = resolve(o.dir);
|
|
377
|
+
const meta = readFixtureMeta(benchDir);
|
|
378
|
+
const maxMinutes = o.maxMinutes ?? DEFAULT_BENCH_MAX_MINUTES;
|
|
379
|
+
const parallel = o.parallel ?? 1;
|
|
380
|
+
const subset = benchSubset(o.issues);
|
|
381
|
+
const selected = BENCH_ISSUES.filter((i) => !subset || subset.includes(i.id));
|
|
382
|
+
const inScope = (id) => selected.some((i) => i.id === id);
|
|
383
|
+
if (o.mode === 'live') {
|
|
384
|
+
if (o.maxRequests === undefined)
|
|
385
|
+
throw new BenchUsageError('--live needs --max-requests <n>: the bench never spends premium requests without an explicit cap');
|
|
386
|
+
}
|
|
387
|
+
else if (parallel !== 1) {
|
|
388
|
+
throw new BenchUsageError('--parallel applies to --live; --fake runs one engine at a time');
|
|
389
|
+
}
|
|
390
|
+
if (!existsSync(join(meta.root, 'node_modules', 'vitest', 'vitest.mjs'))) {
|
|
391
|
+
throw new BenchUsageError(`the fixture has no node_modules with vitest: run npm install in ${meta.root} (or recreate it with omg factory bench init --node-modules <dir>)`);
|
|
392
|
+
}
|
|
393
|
+
const started = now();
|
|
394
|
+
const notes = [];
|
|
395
|
+
const errors = new Map();
|
|
396
|
+
let stopped = null;
|
|
397
|
+
const overTime = () => now().getTime() - started.getTime() >= maxMinutes * 60_000;
|
|
398
|
+
const runsLog = [];
|
|
399
|
+
let config;
|
|
400
|
+
let ledgerUsed = null;
|
|
401
|
+
if (o.mode === 'fake') {
|
|
402
|
+
config = fakeForgeConfig(meta, join(benchDir, 'forge-state'));
|
|
403
|
+
const seen = new Set();
|
|
404
|
+
for (;;) {
|
|
405
|
+
if (o.interrupted?.()) {
|
|
406
|
+
stopped = 'interrupted';
|
|
407
|
+
break;
|
|
408
|
+
}
|
|
409
|
+
if (overTime()) {
|
|
410
|
+
stopped = 'max-minutes';
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
const next = checkBacklog(defaultExec, meta.root, meta.base, config).find((r) => r.bucket === 'runnable' && !seen.has(r.id) && inScope(r.id));
|
|
414
|
+
if (!next)
|
|
415
|
+
break;
|
|
416
|
+
seen.add(next.id);
|
|
417
|
+
const issue = BENCH_ISSUES.find((i) => i.id === next.id);
|
|
418
|
+
if (!issue) {
|
|
419
|
+
notes.push(`backlog item #${next.id} is not a bench issue; skipped`);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
// --max-requests in fake mode: the same hard per-run cap the live children get.
|
|
423
|
+
let maxRunRequests;
|
|
424
|
+
if (o.maxRequests !== undefined) {
|
|
425
|
+
const used = [...seen].reduce((n, id) => n + (issueUsage(meta.root, id)?.requests ?? 0), 0);
|
|
426
|
+
maxRunRequests = o.maxRequests - used;
|
|
427
|
+
if (maxRunRequests < MIN_RUN_REQUESTS) {
|
|
428
|
+
stopped = 'max-requests';
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
log(`#${issue.id} ${issue.slug}: running${maxRunRequests !== undefined ? ` (cap ${maxRunRequests} requests)` : ''}`);
|
|
433
|
+
try {
|
|
434
|
+
const out = await runFactoryEngine({
|
|
435
|
+
root: meta.root, issue: issue.id, exec: defaultExec, base: meta.base, limits: { ...DEFAULT_FACTORY_RUN_LIMITS, ...(maxRunRequests !== undefined ? { maxRunRequests } : {}) },
|
|
436
|
+
lanes: new BenchFakeLanes(meta.root, issue.fake, (t) => fillPlaceholders(t, meta)),
|
|
437
|
+
ledgerDir: join(benchDir, 'engine-ledger'), processes: BENCH_FAKE_PROCESSES, pollMs: 5, sleep: async () => { },
|
|
438
|
+
gateConfig: benchGateConfig, forge: { config, options: { ...factoryForgeOptions(meta.root), stateDir: join(benchDir, 'forge-state') } },
|
|
439
|
+
gateSandbox: plainGateRunner, gateSandboxUserConfig: null, runUserConfig: null, secretScanUserConfig: null, codingAgentUserConfig: null,
|
|
440
|
+
warn: () => { },
|
|
441
|
+
});
|
|
442
|
+
log(`#${issue.id} ${issue.slug}: exit ${out.exitCode}: ${out.message.split('\n')[0].slice(0, 200)}`);
|
|
443
|
+
}
|
|
444
|
+
catch (error) {
|
|
445
|
+
errors.set(issue.id, error instanceof Error ? error.message : String(error));
|
|
446
|
+
log(`#${issue.id} ${issue.slug}: error: ${errors.get(issue.id)}`);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
const trustedUser = o.trustedUser !== undefined ? o.trustedUser : userConfigLayers().trustedUser;
|
|
452
|
+
const baseConfig = fixtureBaseConfig(meta);
|
|
453
|
+
const sandboxRefusal = liveSandboxRefusal(trustedUser, baseConfig);
|
|
454
|
+
if (sandboxRefusal)
|
|
455
|
+
throw new BenchUsageError(sandboxRefusal);
|
|
456
|
+
if (parallel > 1) {
|
|
457
|
+
const slots = pollParallel(trustedUser, baseConfig, () => { });
|
|
458
|
+
if (slots === undefined || slots < parallel) {
|
|
459
|
+
throw new BenchUsageError(`--parallel ${parallel} needs factory.run.maxConcurrent of at least ${parallel} and factory.run.layout "private" in your user config (${slots === undefined ? 'parallel runs are off' : `maxConcurrent resolves to ${slots}`})`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
config = loadFactoryForgeConfig(factoryGuardExec(defaultExec), meta.root, meta.base, trustedUser, undefined).config;
|
|
463
|
+
if (config.kind !== 'local')
|
|
464
|
+
throw new BenchUsageError(`the fixture resolves to the ${config.kind} forge (your user config's factory.forge?); the bench needs the local forge`);
|
|
465
|
+
// The lanes' model and its multiplier, before anything is spent (read-only, no model turn).
|
|
466
|
+
const model = await (o.modelProbe ?? (() => probeLaneModel(join(benchDir, 'model-probe'))))();
|
|
467
|
+
const modelLine = `lanes' default Copilot model: ${model.model ?? 'unknown'}; premium multiplier: ${model.multiplier ?? 'unknown'} (${model.detail})`;
|
|
468
|
+
(o.announce ?? log)(modelLine);
|
|
469
|
+
notes.push(modelLine);
|
|
470
|
+
if (model.multiplier === null)
|
|
471
|
+
notes.push('the multiplier is unknown: a lane without session.shutdown totals counts its user calls once each, which undercounts a model above 1x');
|
|
472
|
+
const multiplierStop = multiplierRefusal(model, o.allowMultiplier);
|
|
473
|
+
if (multiplierStop)
|
|
474
|
+
throw new BenchUsageError(multiplierStop);
|
|
475
|
+
const readLedger = o.ledger ?? defaultLedger;
|
|
476
|
+
/** Whether any read found the ledger file (defaultLedger's no-file read: records but no epoch). */
|
|
477
|
+
let ledgerSeen = false;
|
|
478
|
+
const ledger = (root) => {
|
|
479
|
+
const s = readLedger(root);
|
|
480
|
+
if (!(s.records !== undefined && s.epoch === undefined))
|
|
481
|
+
ledgerSeen = true;
|
|
482
|
+
return s;
|
|
483
|
+
};
|
|
484
|
+
const ledgerSince = ledgerTracker(ledger(meta.root));
|
|
485
|
+
const cap = o.maxRequests;
|
|
486
|
+
/** Started issues: their child's per-run cap, whether the child is still running, and whether a busy child left it to start again. */
|
|
487
|
+
const runs = new Map();
|
|
488
|
+
let finished = 0;
|
|
489
|
+
let busyStreak = 0;
|
|
490
|
+
const running = new Set();
|
|
491
|
+
/** The usage so far (the largest of the ledger delta, the run states, MIN per finished run); throws when the ledger is unusable or went down (ledgerTracker). */
|
|
492
|
+
const usage = () => {
|
|
493
|
+
const delta = ledgerSince(ledger(meta.root));
|
|
494
|
+
let stateRequests = 0;
|
|
495
|
+
let stateCredits = 0;
|
|
496
|
+
let reserved = 0;
|
|
497
|
+
for (const [id, r] of runs) {
|
|
498
|
+
const u = issueUsage(meta.root, id);
|
|
499
|
+
stateRequests += u?.requests ?? 0;
|
|
500
|
+
stateCredits += u?.credits ?? 0;
|
|
501
|
+
// A running child may still spend up to its own cap (unknown usage: all of it).
|
|
502
|
+
if (r.running)
|
|
503
|
+
reserved += Math.max(0, r.allot - (u?.requests ?? 0));
|
|
504
|
+
}
|
|
505
|
+
// review-510-511 L1: a lane may keep the ledger deleted; usage in a run state with no ledger file ever seen is not trusted.
|
|
506
|
+
if (!ledgerSeen && stateRequests > 0)
|
|
507
|
+
throw new Error(`a run recorded ${stateRequests} premium requests in its state, but the budget ledger ${ledgerPath(meta.root)} never appeared; the bench cannot trust its usage without it`);
|
|
508
|
+
const used = Math.max(delta.premiumRequests, stateRequests, finished * MIN_RUN_REQUESTS);
|
|
509
|
+
return { used, reserved, credits: Math.max(delta.credits, stateCredits), ledger: delta };
|
|
510
|
+
};
|
|
511
|
+
const capReason = () => {
|
|
512
|
+
if (o.interrupted?.())
|
|
513
|
+
return { stop: 'interrupted' };
|
|
514
|
+
if (overTime())
|
|
515
|
+
return { stop: 'max-minutes' };
|
|
516
|
+
let u;
|
|
517
|
+
try {
|
|
518
|
+
u = usage();
|
|
519
|
+
}
|
|
520
|
+
catch (error) {
|
|
521
|
+
notes.push(`no further run starts: ${error instanceof Error ? error.message : String(error)}`);
|
|
522
|
+
return { stop: 'run-error' };
|
|
523
|
+
}
|
|
524
|
+
// A soft stop (LOW-5): it reserves nothing for runs in flight, so they may end above it; --max-requests is the hard cap.
|
|
525
|
+
if (o.maxCredits !== undefined && u.credits >= o.maxCredits)
|
|
526
|
+
return { stop: 'max-credits' };
|
|
527
|
+
const available = cap - u.used - u.reserved;
|
|
528
|
+
if (available < MIN_RUN_REQUESTS)
|
|
529
|
+
return { stop: 'max-requests' };
|
|
530
|
+
const free = parallel - running.size;
|
|
531
|
+
return { allot: free > 1 ? Math.min(available, Math.max(MIN_RUN_REQUESTS, Math.floor(available / free))) : available };
|
|
532
|
+
};
|
|
533
|
+
const pick = () => {
|
|
534
|
+
try {
|
|
535
|
+
return checkBacklog(defaultExec, meta.root, meta.base, config).find((r) => r.bucket === 'runnable' && inScope(r.id) && (!runs.has(r.id) || runs.get(r.id).retry))?.id ?? null;
|
|
536
|
+
}
|
|
537
|
+
catch (error) {
|
|
538
|
+
notes.push(`omg factory check over the backlog failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
539
|
+
return 'error';
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
const start = o.liveStart ?? defaultPollAutoStart(process.argv[1], o.signals ? { signals: o.signals } : {});
|
|
543
|
+
for (;;) {
|
|
544
|
+
while (!stopped && running.size < parallel) {
|
|
545
|
+
const next = pick();
|
|
546
|
+
if (next === 'error') {
|
|
547
|
+
stopped = 'run-error';
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
if (next === null)
|
|
551
|
+
break;
|
|
552
|
+
const c = capReason();
|
|
553
|
+
if ('stop' in c) {
|
|
554
|
+
stopped = c.stop;
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
runs.set(next, { allot: c.allot, running: true });
|
|
558
|
+
log(`#${next}: omg factory run ${next} --max-requests ${c.allot}`);
|
|
559
|
+
const p = start({ root: meta.root, issue: next, args: ['--max-requests', String(c.allot)] }).then(async (r) => {
|
|
560
|
+
log(`#${next}: exit ${r.exitCode}: ${r.message.split('\n')[0].slice(0, 200)}`);
|
|
561
|
+
runsLog.push({ issue: next, maxRequests: c.allot, exitCode: r.exitCode, message: r.message.split('\n')[0].slice(0, 300) });
|
|
562
|
+
if (r.exitCode === 6) {
|
|
563
|
+
// Busy: another engine holds the lock or every slot. The issue goes back, after a wait; its entry stays
|
|
564
|
+
// (not running) so any lane the run did start before the busy surfaced still counts.
|
|
565
|
+
runs.set(next, { allot: c.allot, running: false, retry: true });
|
|
566
|
+
busyStreak += 1;
|
|
567
|
+
notes.push(`#${next}: busy: ${r.message.split('\n')[0]}`);
|
|
568
|
+
if (busyStreak >= MAX_BUSY_STREAK) {
|
|
569
|
+
stopped ??= 'run-error';
|
|
570
|
+
notes.push(`${busyStreak} busy runs in a row: another engine holds this fixture`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
await sleep(BUSY_BACKOFF_MS * busyStreak);
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
576
|
+
busyStreak = 0;
|
|
577
|
+
finished += 1;
|
|
578
|
+
runs.get(next).running = false;
|
|
579
|
+
if (!r.parsed) {
|
|
580
|
+
notes.push(`#${next}: ${r.message}`);
|
|
581
|
+
stopped ??= 'run-error';
|
|
582
|
+
}
|
|
583
|
+
}).finally(() => { running.delete(p); });
|
|
584
|
+
running.add(p);
|
|
585
|
+
}
|
|
586
|
+
if (running.size === 0)
|
|
587
|
+
break;
|
|
588
|
+
await Promise.race(running);
|
|
589
|
+
}
|
|
590
|
+
notes.push(`the --max-requests bound: ${LIVE_CAP_BOUND}`);
|
|
591
|
+
notes.push(`live runs leave state outside ${benchDir}: the local forge mirror ${config.repo.url} and the factory ledger dir ${defaultLedgerDir()} (claims, private run repositories, tamper holds). To remove them: omg factory run cancel <id>, then omg factory run clean <id> --seed in ${meta.root} for each run, then delete the mirror dir`);
|
|
592
|
+
try {
|
|
593
|
+
const u = usage();
|
|
594
|
+
ledgerUsed = { premiumRequests: Math.round(u.ledger.premiumRequests * 100) / 100, credits: Math.round(u.ledger.credits * 100) / 100 };
|
|
595
|
+
}
|
|
596
|
+
catch (error) {
|
|
597
|
+
notes.push(`the final ledger read failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
598
|
+
if (!ledgerSeen)
|
|
599
|
+
stopped ??= 'run-error';
|
|
600
|
+
}
|
|
601
|
+
if (!ledgerSeen && finished > 0)
|
|
602
|
+
notes.push(`no budget ledger file was seen during the live runs (${ledgerPath(meta.root)}): the usage counts the run states and ${MIN_RUN_REQUESTS} requests per finished run only`);
|
|
603
|
+
}
|
|
604
|
+
log('scoring');
|
|
605
|
+
const runner = o.acceptanceRunner ?? (o.mode === 'fake' ? plainGateRunner : createSandboxRunner(meta.root));
|
|
606
|
+
let buckets = [];
|
|
607
|
+
try {
|
|
608
|
+
buckets = checkBacklog(defaultExec, meta.root, meta.base, config);
|
|
609
|
+
}
|
|
610
|
+
catch (error) {
|
|
611
|
+
notes.push(`omg factory check over the backlog failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
612
|
+
}
|
|
613
|
+
const mirror = config.repo.url;
|
|
614
|
+
const issues = [];
|
|
615
|
+
for (const issue of selected)
|
|
616
|
+
issues.push(await scoreIssue(issue, { meta, benchDir, mirror, runner, buckets, log, error: errors.get(issue.id) }));
|
|
617
|
+
const results = {
|
|
618
|
+
schemaVersion: BENCH_RESULTS_SCHEMA_VERSION,
|
|
619
|
+
kind: BENCH_RESULTS_KIND,
|
|
620
|
+
mode: o.mode,
|
|
621
|
+
omgVersion: getRuntimePackageVersion(),
|
|
622
|
+
fixtureVersion: BENCH_FIXTURE_VERSION,
|
|
623
|
+
startedAt: started.toISOString(),
|
|
624
|
+
finishedAt: now().toISOString(),
|
|
625
|
+
caps: { maxRequests: o.maxRequests ?? null, maxCredits: o.maxCredits ?? null, maxMinutes, parallel },
|
|
626
|
+
subset,
|
|
627
|
+
...(o.mode === 'live' ? { runs: runsLog } : {}),
|
|
628
|
+
stopped,
|
|
629
|
+
ledger: ledgerUsed,
|
|
630
|
+
notes,
|
|
631
|
+
issues,
|
|
632
|
+
totals: computeTotals(issues),
|
|
633
|
+
};
|
|
634
|
+
const outDir = resolve(o.outDir ?? 'bench-results');
|
|
635
|
+
mkdirSync(outDir, { recursive: true });
|
|
636
|
+
const stamp = results.startedAt.replace(/[:.]/g, '-');
|
|
637
|
+
const jsonPath = join(outDir, `${stamp}-${o.mode}.json`);
|
|
638
|
+
const markdownPath = join(outDir, `${stamp}-${o.mode}.md`);
|
|
639
|
+
writeFileSync(jsonPath, `${JSON.stringify(results, null, 2)}\n`);
|
|
640
|
+
writeFileSync(markdownPath, renderResultsMarkdown(results));
|
|
641
|
+
return { results, jsonPath, markdownPath };
|
|
642
|
+
}
|
|
643
|
+
async function scoreIssue(issue, c) {
|
|
644
|
+
let state = null;
|
|
645
|
+
let note = c.error;
|
|
646
|
+
try {
|
|
647
|
+
state = readFactoryState(c.meta.root, issue.id);
|
|
648
|
+
}
|
|
649
|
+
catch (error) {
|
|
650
|
+
note = `run state unreadable: ${error instanceof Error ? error.message : String(error)}`;
|
|
651
|
+
}
|
|
652
|
+
let outcome = outcomeOf(state);
|
|
653
|
+
if (!state) {
|
|
654
|
+
const bucket = c.buckets.find((b) => b.id === issue.id)?.bucket;
|
|
655
|
+
outcome = c.error || note ? 'error' : bucket && bucket !== 'runnable' ? `not-runnable:${bucket}` : 'not-run';
|
|
656
|
+
}
|
|
657
|
+
const branch = factoryBranch(issue.id);
|
|
658
|
+
const pushed = state ? readMirrorRef(c.mirror, branch) ?? null : null;
|
|
659
|
+
let acceptance = null;
|
|
660
|
+
if (outcome === 'merged-park' && issue.acceptanceTest) {
|
|
661
|
+
c.log(`#${issue.id} ${issue.slug}: acceptance`);
|
|
662
|
+
acceptance = pushed
|
|
663
|
+
? await runAcceptance({ meta: c.meta, benchDir: c.benchDir, mirror: c.mirror, branch, head: pushed, test: issue.acceptanceTest, runner: c.runner })
|
|
664
|
+
: { ran: false, passed: false, status: null, detail: `no ${branch} in the local forge mirror` };
|
|
665
|
+
}
|
|
666
|
+
let containment = null;
|
|
667
|
+
if (issue.trap) {
|
|
668
|
+
try {
|
|
669
|
+
containment = trapContainment(issue.trap, { exec: defaultExec, mirror: c.mirror, meta: c.meta, head: pushed });
|
|
670
|
+
}
|
|
671
|
+
catch (error) {
|
|
672
|
+
containment = { trap: issue.trap, contained: false, inconclusive: true, detail: `the containment check failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
const lanes = laneUsage(state);
|
|
676
|
+
const { wallMs, phaseMs } = phaseTimes(state);
|
|
677
|
+
return {
|
|
678
|
+
id: issue.id, slug: issue.slug, title: issue.title, difficulty: issue.difficulty, category: issue.category, ...(issue.trap ? { trap: issue.trap } : {}),
|
|
679
|
+
expect: issue.expect, outcome, pass: issuePasses(issue, outcome, acceptance, containment, pushed, state?.gate?.reason ?? null),
|
|
680
|
+
...(state?.gate ? { park: { name: state.gate.name, reason: state.gate.reason } } : {}),
|
|
681
|
+
acceptance, containment, ...(containment ? { trapVerdict: trapVerdict(issue, outcome, containment, pushed, state?.gate?.reason ?? null) } : {}), head: pushed, pr: state?.pr ?? null,
|
|
682
|
+
premiumRequests: lanes.reduce((n, l) => n + l.premiumRequests, 0),
|
|
683
|
+
credits: Math.round(lanes.reduce((n, l) => n + l.credits, 0) * 100) / 100,
|
|
684
|
+
lanes, wallMs, phaseMs, ...(note ? { note } : {}),
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
//# sourceMappingURL=runner.js.map
|