0d3cb498a3
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Waiting to run
Test and Publish Multi-arch Docker Image / test (push) Waiting to run
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Blocked by required conditions
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) Blocked by required conditions
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Blocked by required conditions
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Blocked by required conditions
Validate Renovate Config / Validate Renovate Configuration (push) Waiting to run
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
81 lines
3.1 KiB
TypeScript
81 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { normalizeFinishReason } from '../../src/util/finishReason';
|
|
|
|
describe('normalizeFinishReason', () => {
|
|
describe('OpenAI mappings', () => {
|
|
it('should pass through OpenAI standard reasons unchanged', () => {
|
|
expect(normalizeFinishReason('stop')).toBe('stop');
|
|
expect(normalizeFinishReason('length')).toBe('length');
|
|
expect(normalizeFinishReason('content_filter')).toBe('content_filter');
|
|
expect(normalizeFinishReason('tool_calls')).toBe('tool_calls');
|
|
});
|
|
|
|
it('should map function_call to tool_calls', () => {
|
|
expect(normalizeFinishReason('function_call')).toBe('tool_calls');
|
|
});
|
|
});
|
|
|
|
describe('Anthropic mappings', () => {
|
|
it('should normalize Anthropic reasons to standard values', () => {
|
|
expect(normalizeFinishReason('end_turn')).toBe('stop');
|
|
expect(normalizeFinishReason('stop_sequence')).toBe('stop');
|
|
expect(normalizeFinishReason('max_tokens')).toBe('length');
|
|
expect(normalizeFinishReason('tool_use')).toBe('tool_calls');
|
|
expect(normalizeFinishReason('refusal')).toBe('content_filter');
|
|
});
|
|
|
|
it('should preserve pause_turn as-is', () => {
|
|
expect(normalizeFinishReason('pause_turn')).toBe('pause_turn');
|
|
});
|
|
});
|
|
|
|
describe('case normalization', () => {
|
|
it('should handle uppercase input', () => {
|
|
expect(normalizeFinishReason('STOP')).toBe('stop');
|
|
expect(normalizeFinishReason('LENGTH')).toBe('length');
|
|
expect(normalizeFinishReason('END_TURN')).toBe('stop');
|
|
});
|
|
|
|
it('should handle mixed case input', () => {
|
|
expect(normalizeFinishReason('Stop')).toBe('stop');
|
|
expect(normalizeFinishReason('Length')).toBe('length');
|
|
expect(normalizeFinishReason('End_Turn')).toBe('stop');
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should handle null and undefined', () => {
|
|
expect(normalizeFinishReason(null)).toBeUndefined();
|
|
expect(normalizeFinishReason(undefined)).toBeUndefined();
|
|
});
|
|
|
|
it('should handle empty and whitespace strings', () => {
|
|
expect(normalizeFinishReason('')).toBeUndefined();
|
|
expect(normalizeFinishReason(' ')).toBeUndefined();
|
|
expect(normalizeFinishReason('\t\n')).toBeUndefined();
|
|
});
|
|
|
|
it('should handle non-string input', () => {
|
|
expect(normalizeFinishReason(123 as any)).toBeUndefined();
|
|
expect(normalizeFinishReason({} as any)).toBeUndefined();
|
|
expect(normalizeFinishReason([] as any)).toBeUndefined();
|
|
});
|
|
|
|
it('should trim whitespace', () => {
|
|
expect(normalizeFinishReason(' stop ')).toBe('stop');
|
|
expect(normalizeFinishReason('\tlength\n')).toBe('length');
|
|
});
|
|
});
|
|
|
|
describe('unmapped reasons', () => {
|
|
it('should pass through unknown reasons unchanged', () => {
|
|
expect(normalizeFinishReason('unknown_reason')).toBe('unknown_reason');
|
|
expect(normalizeFinishReason('custom_stop')).toBe('custom_stop');
|
|
});
|
|
|
|
it('should preserve case for unknown reasons after normalization', () => {
|
|
expect(normalizeFinishReason('CUSTOM_REASON')).toBe('custom_reason');
|
|
});
|
|
});
|
|
});
|