Skip to content

Commit a7d6fb3

Browse files
committed
feat: expose helper for writing reports to disk
This is useful for programmatic usage of WCS.
1 parent 5c35026 commit a7d6fb3

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

runner/eval-cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DEFAULT_MAX_TEST_REPAIR_ATTEMPTS,
88
DEFAULT_MODEL_NAME,
99
DEFAULT_PROMPT_TIMEOUT_RETRIES,
10+
REPORTS_ROOT_DIR,
1011
} from './configuration/constants.js';
1112
import {generateCodeAndAssess} from './orchestration/generate.js';
1213
import {logReportToConsole, writeReportToDisk} from './reporting/report-logging.js';
@@ -236,7 +237,7 @@ async function handler(cliArgs: Arguments<Options>): Promise<void> {
236237
});
237238

238239
logReportToConsole(runInfo);
239-
await writeReportToDisk(runInfo, runInfo.details.summary.environmentId);
240+
await writeReportToDisk(runInfo, runInfo.details.summary.environmentId, REPORTS_ROOT_DIR);
240241
} catch (error: unknown) {
241242
if (error instanceof UserFacingError) {
242243
console.error(chalk.red(error.message));

runner/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ export {type ServeTestingResult} from './workers/serve-testing/worker-types.js';
5151
export {replaceAtReferencesInPrompt} from './utils/prompt-at-references.js';
5252
export {extractRubrics} from './utils/extract-rubrics.js';
5353
export {combineReports} from './utils/combine-reports.mjs';
54+
export {writeReportToDisk} from './reporting/report-logging.js';

runner/reporting/report-logging.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {join} from 'path';
22
import chalk from 'chalk';
33
import boxen from 'boxen';
44
import {IndividualAssessmentState, RunInfo, ScoreBucket} from '../shared-interfaces.js';
5-
import {DEFAULT_AUTORATER_MODEL_NAME, REPORTS_ROOT_DIR} from '../configuration/constants.js';
5+
import {DEFAULT_AUTORATER_MODEL_NAME} from '../configuration/constants.js';
66
import {calculateBuildAndCheckStats} from '../ratings/stats.js';
77
import {safeWriteFile} from '../file-system-utils.js';
88
import {BuildResultStatus} from '../workers/builder/builder-types.js';
@@ -17,7 +17,6 @@ import {
1717
} from './format.js';
1818
import {Environment} from '../configuration/environment.js';
1919
import {groupSimilarReports} from '../orchestration/grouping.js';
20-
import {LocalExecutor} from '../orchestration/executors/local-executor.js';
2120

2221
/**
2322
* Generates a structured report on fs, based on the assessment run information.
@@ -38,14 +37,19 @@ import {LocalExecutor} from '../orchestration/executors/local-executor.js';
3837
*
3938
* @param runInfo An object containing all details and results of the assessment run.
4039
* @param id ID of the environment that was used for the eval.
40+
* @param reportsRootDir Root directory where the reports are written to.
4141
* @returns The original `runInfo` object, allowing for chaining.
4242
*/
43-
export async function writeReportToDisk(runInfo: RunInfo, id: string): Promise<void> {
43+
export async function writeReportToDisk(
44+
runInfo: RunInfo,
45+
id: string,
46+
reportsRootDir: string,
47+
): Promise<void> {
4448
// Sanitize report name: allow only a-z, A-Z, 0-9, and hyphens. Replace others with a hyphen.
4549
const sanitizedReportName = runInfo.details.reportName.replace(/[^a-zA-Z0-9-]/g, '-');
4650

4751
const {results} = runInfo;
48-
const reportBaseDir = join(REPORTS_ROOT_DIR, id, sanitizedReportName);
52+
const reportBaseDir = join(reportsRootDir, id, sanitizedReportName);
4953

5054
// Write `summary.json` file, which contains **all** available info.
5155
const summaryJsonPath = join(reportBaseDir, 'summary.json');

0 commit comments

Comments
 (0)