chore: import upstream snapshot with attribution
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { EvalSchemas } from '../../../src/types/api/eval';
|
||||
|
||||
describe('Eval API schemas', () => {
|
||||
it('validates table response envelopes without deep-parsing table rows', () => {
|
||||
const body = new Proxy([{ outputs: [{ text: 'large output' }] }], {
|
||||
get(target, property, receiver) {
|
||||
if (property === '0') {
|
||||
throw new Error('table body was deep-parsed');
|
||||
}
|
||||
return Reflect.get(target, property, receiver);
|
||||
},
|
||||
});
|
||||
const head = { prompts: [], vars: [] };
|
||||
|
||||
const parsed = EvalSchemas.Table.Response.parse({
|
||||
table: { head, body },
|
||||
totalCount: 1,
|
||||
filteredCount: 1,
|
||||
filteredMetrics: null,
|
||||
config: {},
|
||||
author: null,
|
||||
version: 4,
|
||||
id: 'eval-1',
|
||||
stats: {},
|
||||
});
|
||||
|
||||
expect(parsed.table.head).toBe(head);
|
||||
expect(parsed.table.body).toBe(body);
|
||||
});
|
||||
|
||||
it('rejects table responses where version is not a number', () => {
|
||||
const result = EvalSchemas.Table.Response.safeParse({
|
||||
table: { head: { prompts: [], vars: [] }, body: [] },
|
||||
totalCount: 0,
|
||||
filteredCount: 0,
|
||||
filteredMetrics: null,
|
||||
config: {},
|
||||
author: null,
|
||||
version: '4',
|
||||
id: 'eval-1',
|
||||
stats: {},
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects table responses where body is not an array', () => {
|
||||
const result = EvalSchemas.Table.Response.safeParse({
|
||||
table: { head: { prompts: [], vars: [] }, body: 'not-an-array' },
|
||||
totalCount: 0,
|
||||
filteredCount: 0,
|
||||
filteredMetrics: null,
|
||||
config: {},
|
||||
author: null,
|
||||
version: 4,
|
||||
id: 'eval-1',
|
||||
stats: {},
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it('SubmitRating response schema preserves the persisted EvalResult row', () => {
|
||||
const parsed = EvalSchemas.SubmitRating.Response.parse({
|
||||
id: 'result-123',
|
||||
success: true,
|
||||
score: 0.75,
|
||||
gradingResult: { pass: true, score: 0.75, reason: 'manual override' },
|
||||
promptIdx: 0,
|
||||
});
|
||||
expect(parsed.id).toBe('result-123');
|
||||
expect(parsed.success).toBe(true);
|
||||
expect(parsed.score).toBe(0.75);
|
||||
// Passthrough preserves additional EvalResult fields like gradingResult.
|
||||
// The inferred Zod type carries an index signature for the passthrough
|
||||
// bucket but doesn't statically include `gradingResult`, so cast through
|
||||
// `unknown` to read it.
|
||||
expect((parsed as unknown as { gradingResult: { pass: boolean } }).gradingResult.pass).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('SubmitRating response schema rejects payloads missing the row identifier', () => {
|
||||
const result = EvalSchemas.SubmitRating.Response.safeParse({
|
||||
success: true,
|
||||
score: 1,
|
||||
});
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user