Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions examples/contract/scripts/check-repo-materialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,25 @@ interface GraderPayload {
readonly workspace_path?: string | null;
}

interface Assertion {
interface Check {
readonly text: string;
readonly passed: boolean;
readonly pass: boolean;
readonly reason: string;
readonly evidence?: string;
}

const payloadText = readFileSync(0, 'utf8');
const payload = JSON.parse(payloadText) as GraderPayload;
const workspacePath = payload.workspace_path ?? process.env.AGENTV_WORKSPACE_PATH;
const assertions: Assertion[] = [];
const checks: Check[] = [];

function push(text: string, passed: boolean, evidence?: string): void {
assertions.push({ text, passed, ...(evidence ? { evidence } : {}) });
checks.push({
text,
pass: passed,
reason: evidence ?? (passed ? 'Check passed' : 'Check failed'),
...(evidence ? { evidence } : {}),
});
}

function runGit(repoPath: string, args: readonly string[]): string {
Expand All @@ -59,7 +65,7 @@ function collectStrings(value: unknown, strings: string[]): void {

if (!workspacePath) {
push('workspace_path is provided', false, 'workspace_path was missing from the grader payload');
console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
process.exit(0);
}

Expand Down Expand Up @@ -127,4 +133,4 @@ push(
fileInputWasSubstituted ? undefined : `Marker ${FILE_INPUT_MARKER} not found in grader payload`,
);

console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
20 changes: 13 additions & 7 deletions examples/contract/scripts/check-script-grader-payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@

import { readFileSync } from 'node:fs';

interface Assertion {
interface Check {
readonly text: string;
readonly passed: boolean;
readonly pass: boolean;
readonly reason: string;
readonly evidence?: string;
}

const assertions: Assertion[] = [];
const checks: Check[] = [];

function push(text: string, passed: boolean, evidence?: string): void {
assertions.push({ text, passed, ...(evidence ? { evidence } : {}) });
checks.push({
text,
pass: passed,
reason: evidence ?? (passed ? 'Check passed' : 'Check failed'),
...(evidence ? { evidence } : {}),
});
}

function isRecord(value: unknown): value is Record<string, unknown> {
Expand Down Expand Up @@ -49,14 +55,14 @@ try {
const parsed = JSON.parse(readFileSync(0, 'utf8')) as unknown;
if (!isRecord(parsed)) {
push('stdin payload is a JSON object', false, `Received ${typeof parsed}`);
console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
process.exit(0);
}
payload = parsed;
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
push('stdin payload is valid JSON', false, message);
console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
process.exit(0);
}

Expand Down Expand Up @@ -145,4 +151,4 @@ push(
hasOwn(payload, 'answer') ? 'Unexpected answer field found in payload' : undefined,
);

console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
18 changes: 12 additions & 6 deletions examples/contract/scripts/check-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@ interface GraderPayload {
readonly workspace_path?: string | null;
}

interface Assertion {
interface Check {
readonly text: string;
readonly passed: boolean;
readonly pass: boolean;
readonly reason: string;
readonly evidence?: string;
}

const payload = JSON.parse(readFileSync(0, 'utf8')) as GraderPayload;
const workspacePath = payload.workspace_path ?? process.env.AGENTV_WORKSPACE_PATH;
const assertions: Assertion[] = [];
const checks: Check[] = [];

function push(text: string, passed: boolean, evidence?: string): void {
assertions.push({ text, passed, ...(evidence ? { evidence } : {}) });
checks.push({
text,
pass: passed,
reason: evidence ?? (passed ? 'Check passed' : 'Check failed'),
...(evidence ? { evidence } : {}),
});
}

if (!workspacePath) {
push('workspace_path is provided', false, 'workspace_path was missing from the grader payload');
console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
process.exit(0);
}

Expand Down Expand Up @@ -67,4 +73,4 @@ if (markerExists) {
}
}

console.log(JSON.stringify({ assertions }));
console.log(JSON.stringify({ checks }));
Loading