Skip to content

Commit 1a06b6d

Browse files
cameroncookecodex
andcommitted
fix(benchmarks): Isolate local suite discovery tests
Allow Claude UI suite discovery helpers to receive suite directories so tests can exercise local suite lookup without writing fake files into the real repository tree. Co-Authored-By: Codex <noreply@openai.com>
1 parent efffe69 commit 1a06b6d

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/benchmarks/claude-ui/__tests__/claude-ui-benchmark.test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,22 @@ describe('Claude UI benchmark harness', () => {
8989
});
9090

9191
it('discovers local private suites when present', async () => {
92-
const localSuitesDir = path.join(repoRoot, 'benchmarks/claude-ui/local/suites');
93-
const suiteName = `unit-private-suite-${process.pid}`;
94-
const suitePath = path.join(localSuitesDir, `${suiteName}.yml`);
95-
await mkdir(localSuitesDir, { recursive: true });
96-
await writeFile(suitePath, `name: ${suiteName}\nprompt: ../prompts/weather.md\n`, 'utf8');
92+
const dir = await mkdtemp(path.join(tmpdir(), 'claude-ui-suites-'));
9793
try {
98-
await expect(resolveSuitePath(suiteName)).resolves.toBe(suitePath);
99-
await expect(listSuitePaths()).resolves.toContain(suitePath);
94+
const suiteDirectories = {
95+
suitesDir: path.join(dir, 'suites'),
96+
localSuitesDir: path.join(dir, 'local-suites'),
97+
};
98+
const suiteName = `unit-private-suite-${process.pid}`;
99+
const suitePath = path.join(suiteDirectories.localSuitesDir, `${suiteName}.yml`);
100+
await mkdir(suiteDirectories.suitesDir, { recursive: true });
101+
await mkdir(suiteDirectories.localSuitesDir, { recursive: true });
102+
await writeFile(suitePath, `name: ${suiteName}\nprompt: ../prompts/weather.md\n`, 'utf8');
103+
104+
await expect(resolveSuitePath(suiteName, suiteDirectories)).resolves.toBe(suitePath);
105+
await expect(listSuitePaths(suiteDirectories)).resolves.toContain(suitePath);
100106
} finally {
101-
await rm(suitePath, { force: true });
107+
await rm(dir, { recursive: true, force: true });
102108
}
103109
});
104110
});

src/benchmarks/claude-ui/harness.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ interface StreamJsonResult {
5858
type?: unknown;
5959
is_error?: unknown;
6060
}
61+
interface SuiteDirectories {
62+
suitesDir: string;
63+
localSuitesDir: string;
64+
}
6165
async function fileExists(filePath: string): Promise<boolean> {
6266
try {
6367
await access(filePath);
@@ -67,7 +71,10 @@ async function fileExists(filePath: string): Promise<boolean> {
6771
}
6872
}
6973

70-
export async function resolveSuitePath(suite: string): Promise<string> {
74+
export async function resolveSuitePath(
75+
suite: string,
76+
directories: SuiteDirectories = { suitesDir, localSuitesDir },
77+
): Promise<string> {
7178
if (
7279
path.isAbsolute(suite) ||
7380
suite.includes(path.sep) ||
@@ -78,8 +85,8 @@ export async function resolveSuitePath(suite: string): Promise<string> {
7885
}
7986

8087
const candidates = [
81-
path.join(suitesDir, `${suite}.yml`),
82-
path.join(localSuitesDir, `${suite}.yml`),
88+
path.join(directories.suitesDir, `${suite}.yml`),
89+
path.join(directories.localSuitesDir, `${suite}.yml`),
8390
];
8491
const matches = [];
8592
for (const candidate of candidates) {
@@ -110,10 +117,12 @@ async function listYamlFiles(directory: string, required: boolean): Promise<stri
110117
.sort();
111118
}
112119

113-
export async function listSuitePaths(): Promise<string[]> {
120+
export async function listSuitePaths(
121+
directories: SuiteDirectories = { suitesDir, localSuitesDir },
122+
): Promise<string[]> {
114123
return [
115-
...(await listYamlFiles(suitesDir, true)),
116-
...(await listYamlFiles(localSuitesDir, false)),
124+
...(await listYamlFiles(directories.suitesDir, true)),
125+
...(await listYamlFiles(directories.localSuitesDir, false)),
117126
];
118127
}
119128

0 commit comments

Comments
 (0)