Improve benchmark case details and score chart scaling (#146)

Co-authored-by: Yaowei Zheng <hiyouga@buaa.edu.cn>
This commit is contained in:
Jingzhe Xu
2026-07-31 20:42:32 +08:00
committed by GitHub
parent 5308002d72
commit 740f101242
19 changed files with 519 additions and 212 deletions
@@ -25,6 +25,7 @@ import type {
BenchmarkRunScore,
BenchmarkSummary,
BenchmarksResponse,
CaseMaterial,
WorkspaceFilesResponse,
} from "../api/types.js";
import type {
@@ -235,7 +236,13 @@ export class BenchmarkService {
.sort((a, b) => a.name.localeCompare(b.name))) {
const fallback: BenchmarkCaseSummary = { id: entry.name, title: entry.name };
try {
const statementDir = await this.statementRoot(projectId, agentId, benchmarkId, entry.name);
const statementDir = await this.caseMaterialRoot(
projectId,
agentId,
benchmarkId,
entry.name,
"statement",
);
const realReadme = await fs.realpath(path.join(statementDir, "README.md"));
if (!isWithin(statementDir, realReadme)) throw new Error("README escapes Statement");
cases.push({
@@ -255,9 +262,16 @@ export class BenchmarkService {
benchmarkId: string,
caseId: string,
rel: string,
material: CaseMaterial,
): Promise<WorkspaceFilesResponse> {
const statementDir = await this.statementRoot(projectId, agentId, benchmarkId, caseId);
return this.workspaceFiles.list(statementDir, rel);
const materialRoot = await this.caseMaterialRoot(
projectId,
agentId,
benchmarkId,
caseId,
material,
);
return this.workspaceFiles.list(materialRoot, rel);
}
async readCaseFile(
@@ -266,37 +280,45 @@ export class BenchmarkService {
benchmarkId: string,
caseId: string,
rel: string,
material: CaseMaterial,
options?: WorkspaceFileReadOptions,
): Promise<WorkspaceFileContent> {
const statementDir = await this.statementRoot(projectId, agentId, benchmarkId, caseId);
return this.workspaceFiles.read(statementDir, rel, options);
const materialRoot = await this.caseMaterialRoot(
projectId,
agentId,
benchmarkId,
caseId,
material,
);
return this.workspaceFiles.read(materialRoot, rel, options);
}
private async statementRoot(
private async caseMaterialRoot(
projectId: string,
agentId: string,
benchmarkId: string,
caseId: string,
material: CaseMaterial,
): Promise<string> {
const benchDir = path.join(benchmarksDir(this.root, projectId, agentId), benchmarkId);
const caseDir = path.join(benchDir, caseId);
const statementDir = path.join(caseDir, "statement");
const materialRoot = path.join(caseDir, material);
try {
const [realBenchDir, realCaseDir, realStatementDir] = await Promise.all([
const [realBenchDir, realCaseDir, realMaterialRoot] = await Promise.all([
fs.realpath(benchDir),
fs.realpath(caseDir),
fs.realpath(statementDir),
fs.realpath(materialRoot),
]);
if (
!isWithin(realBenchDir, realCaseDir) ||
path.dirname(realStatementDir) !== realCaseDir ||
path.basename(realStatementDir) !== "statement"
path.dirname(realMaterialRoot) !== realCaseDir ||
path.basename(realMaterialRoot) !== material
) {
throw new Error("Statement path is not canonical");
throw new Error("Case material is not canonical");
}
return realStatementDir;
return realMaterialRoot;
} catch {
throw new HttpError(404, "not_found", "Public Case Statement does not exist.");
throw new HttpError(404, "not_found", `Case ${material} does not exist.`);
}
}