Skip to content

Commit 5985d82

Browse files
perf(tests): reuse seed git fixtures to cut suite wall time (#1548)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
1 parent f662cad commit 5985d82

8 files changed

Lines changed: 81 additions & 23 deletions

tests/ce-code-review-mechanics.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { mkdtempSync, mkdirSync, writeFileSync } from "fs"
22
import { tmpdir } from "os"
33
import path from "path"
44
import { spawnSync } from "node:child_process"
5-
import { describe, expect, test } from "bun:test"
5+
import { describe, expect, setDefaultTimeout, test } from "bun:test"
6+
7+
setDefaultTimeout(20_000)
68

79
const SKILL_DIR = path.join(process.cwd(), "skills", "ce-code-review")
810
const SCOPE_SCRIPT = path.join(SKILL_DIR, "scripts", "review-scope.py")

tests/cli.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { afterAll, describe, expect, test } from "bun:test"
1+
import { afterAll, describe, expect, setDefaultTimeout, test } from "bun:test"
22
import { promises as fs } from "fs"
33
import path from "path"
44
import os from "os"
55
import { materializeClaudePluginFixture } from "./helpers/claude-plugin-fixture"
66

7+
setDefaultTimeout(20_000)
8+
79
const fixture = materializeClaudePluginFixture(path.join(import.meta.dir, "fixtures", "sample-plugin"))
810
const fixtureRoot = fixture.root
911

tests/codex-dev.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, describe, expect, test } from "bun:test"
1+
import { afterEach, describe, expect, setDefaultTimeout, test } from "bun:test"
22
import { promises as fs } from "node:fs"
33
import os from "node:os"
44
import path from "node:path"
@@ -21,6 +21,8 @@ import {
2121
type InstalledPlugin,
2222
} from "../src/dev/codex-dev"
2323

24+
setDefaultTimeout(20_000)
25+
2426
const tempRoots: string[] = []
2527

2628
afterEach(async () => {

tests/plugin-path.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { afterAll, describe, expect, test } from "bun:test"
1+
import { afterAll, describe, expect, setDefaultTimeout, test } from "bun:test"
22
import { promises as fs } from "fs"
33
import path from "path"
44
import os from "os"
55
import { materializeClaudePluginFixture } from "./helpers/claude-plugin-fixture"
66

7+
setDefaultTimeout(20_000)
8+
79
async function exists(filePath: string): Promise<boolean> {
810
try {
911
await fs.access(filePath)

tests/skill-eval-cell/extract.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { afterAll, expect, test } from "bun:test"
1+
import { afterAll, expect, setDefaultTimeout, test } from "bun:test"
2+
3+
setDefaultTimeout(20_000)
24
import { spawnSync } from "node:child_process"
35
import fs from "node:fs"
46
import path from "node:path"

tests/skill-eval-cell/path-shim.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { describe, expect, test } from "bun:test"
1+
import { describe, expect, setDefaultTimeout, test } from "bun:test"
2+
3+
setDefaultTimeout(20_000)
24
import { spawnSync } from "node:child_process"
35
import fs from "node:fs"
46
import os from "node:os"

tests/skills/ce-work-cross-model-routes.test.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { afterAll, describe, expect, setDefaultTimeout, test } from "bun:test"
22
import {
33
chmodSync,
44
copyFileSync,
5+
cpSync,
56
existsSync,
67
mkdirSync,
78
mkdtempSync,
@@ -33,32 +34,47 @@ const ROUTE_CONTRACTS = {
3334
"grok-cursor": { target: "grok", harness: "cursor-agent", intermediaries: ["cursor"], model: "cursor-grok-4.6-high", restriction: "adapter-enforced" },
3435
} as const
3536
const roots: string[] = []
37+
const templateRoots: string[] = []
38+
let seedCanonical: string | null = null
3639

3740
function temp(prefix: string): string {
3841
const dir = mkdtempSync(path.join(tmpdir(), prefix))
3942
roots.push(dir)
4043
return dir
4144
}
4245

43-
afterAll(() => roots.forEach((dir) => rmSync(dir, { recursive: true, force: true })))
46+
afterAll(() => {
47+
for (const dir of [...roots, ...templateRoots]) rmSync(dir, { recursive: true, force: true })
48+
})
49+
50+
function seedCanonicalRepo(): string {
51+
if (seedCanonical) return seedCanonical
52+
const root = mkdtempSync(path.join(tmpdir(), "ce-work-route-template-"))
53+
templateRoots.push(root)
54+
const canonical = path.join(root, "canonical")
55+
mkdirSync(canonical)
56+
mkdirSync(path.join(canonical, "docs", "plans"), { recursive: true })
57+
writeFileSync(path.join(canonical, "README.md"), "seed\n")
58+
writeFileSync(path.join(canonical, "docs", "plans", "plan.md"), "# Test plan\n")
59+
spawnSync("git", ["init", "-q", canonical])
60+
spawnSync("git", ["-C", canonical, "config", "user.email", "test@example.com"])
61+
spawnSync("git", ["-C", canonical, "config", "user.name", "Test"])
62+
spawnSync("git", ["-C", canonical, "add", "."])
63+
spawnSync("git", ["-C", canonical, "commit", "-qm", "seed"])
64+
seedCanonical = canonical
65+
return canonical
66+
}
4467

4568
function fixture() {
4669
const root = temp("ce-work-route-")
4770
const canonical = path.join(root, "canonical")
4871
const packet = path.join(root, "packet.md")
4972
const capture = path.join(root, "capture")
5073
const runs = path.join(root, "runs")
51-
mkdirSync(canonical)
74+
mkdirSync(root, { recursive: true })
5275
mkdirSync(capture)
5376
writeFileSync(packet, "Implement U3 only.\n")
54-
spawnSync("git", ["init", "-q", canonical])
55-
spawnSync("git", ["-C", canonical, "config", "user.email", "test@example.com"])
56-
spawnSync("git", ["-C", canonical, "config", "user.name", "Test"])
57-
mkdirSync(path.join(canonical, "docs", "plans"), { recursive: true })
58-
writeFileSync(path.join(canonical, "README.md"), "seed\n")
59-
writeFileSync(path.join(canonical, "docs", "plans", "plan.md"), "# Test plan\n")
60-
spawnSync("git", ["-C", canonical, "add", "."])
61-
spawnSync("git", ["-C", canonical, "commit", "-qm", "seed"])
77+
cpSync(seedCanonicalRepo(), canonical, { recursive: true })
6278
return {
6379
root,
6480
canonical,
@@ -520,7 +536,7 @@ describe("ce-work fixed write routes", () => {
520536
const quietBin = temp("ce-work-bin-")
521537
writeFileSync(path.join(quietBin, "claude"), `#!/bin/sh
522538
cat > '${quiet.capture}/stdin'
523-
sleep 2
539+
sleep 1.1
524540
exit 7
525541
`)
526542
chmodSync(path.join(quietBin, "claude"), 0o755)
@@ -882,14 +898,15 @@ printf '%s' '${prefix}${sentinel}${"y".repeat(maxRawBytes)}'
882898
const bin = temp("ce-work-bin-")
883899
writeFileSync(path.join(bin, "claude"), `#!/bin/sh
884900
cat > '${f.capture}/stdin'
885-
python3 -c 'import sys; sys.stdout.buffer.write(b"x" * 8388608)'
901+
python3 -c 'import sys; sys.stdout.buffer.write(b"x" * 65536)'
886902
`)
887903
chmodSync(path.join(bin, "claude"), 0o755)
888904

889905
const result = run("claude", f, {
890906
...process.env,
891907
PATH: `${bin}:${process.env.PATH}`,
892908
CE_WORK_MAX_RAW_BYTES: String(maxRawBytes),
909+
CE_WORK_ACTIVITY_POLL_SECS: "1",
893910
})
894911

895912
expect(result.code).toBe(1)

tests/skills/helpers/ce-work-workspace-harness.ts

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { afterEach } from "bun:test"
1+
import { afterAll, afterEach } from "bun:test"
22
import { spawnSync } from "node:child_process"
33
import {
44
chmodSync,
5+
cpSync,
56
existsSync,
67
linkSync,
78
mkdtempSync,
@@ -24,6 +25,12 @@ import { createHash } from "node:crypto"
2425
export const SCRIPT = path.join(__dirname, "../../../skills/ce-work/scripts/unit-workspace.py")
2526
export const ADAPTER = path.join(__dirname, "../../../skills/ce-work/scripts/cross-model-work.sh")
2627
const roots: string[] = []
28+
const templateRoots: string[] = []
29+
const seedTemplates = new Map<string, { repo: string; digest: string; base: string }>()
30+
31+
afterAll(() => {
32+
for (const root of templateRoots.splice(0)) rmSync(root, { recursive: true, force: true })
33+
})
2734

2835
export function tmp(prefix: string): string {
2936
const root = mkdtempSync(path.join(tmpdir(), prefix))
@@ -41,8 +48,12 @@ export function git(cwd: string, ...args: string[]): string {
4148
return sh(cwd, ["git", ...args]).stdout.trim()
4249
}
4350

44-
export function makeRepo(objectFormat: "sha1" | "sha256" = "sha1"): { repo: string; plan: string; digest: string; base: string } {
45-
const repo = path.join(tmp("ce-work-repo-"), "repo")
51+
function seedTemplate(objectFormat: "sha1" | "sha256"): { repo: string; digest: string; base: string } {
52+
const cached = seedTemplates.get(objectFormat)
53+
if (cached) return cached
54+
const root = mkdtempSync(path.join(tmpdir(), "ce-work-repo-template-"))
55+
templateRoots.push(root)
56+
const repo = path.join(root, "repo")
4657
mkdirSync(repo)
4758
git(repo, "init", `--object-format=${objectFormat}`, "-b", "main")
4859
git(repo, "config", "user.name", "CE Work Test")
@@ -56,8 +67,26 @@ export function makeRepo(objectFormat: "sha1" | "sha256" = "sha1"): { repo: stri
5667
writeFileSync(plan, "# Plan\n")
5768
git(repo, "add", ".")
5869
git(repo, "commit", "-m", "seed")
59-
const digest = createHash("sha256").update(readFileSync(plan)).digest("hex")
60-
return { repo, plan, digest, base: git(repo, "rev-parse", "HEAD") }
70+
const template = {
71+
repo,
72+
digest: createHash("sha256").update(readFileSync(plan)).digest("hex"),
73+
base: git(repo, "rev-parse", "HEAD"),
74+
}
75+
seedTemplates.set(objectFormat, template)
76+
return template
77+
}
78+
79+
export function makeRepo(objectFormat: "sha1" | "sha256" = "sha1"): { repo: string; plan: string; digest: string; base: string } {
80+
const template = seedTemplate(objectFormat)
81+
const repo = path.join(tmp("ce-work-repo-"), "repo")
82+
mkdirSync(path.dirname(repo), { recursive: true })
83+
cpSync(template.repo, repo, { recursive: true })
84+
return {
85+
repo,
86+
plan: path.join(repo, "docs", "plans", "plan.md"),
87+
digest: template.digest,
88+
base: template.base,
89+
}
6190
}
6291

6392
export function packetFile(content: string): string {

0 commit comments

Comments
 (0)