Files
wehub-resource-sync 0d3cb498a3
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
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

118 lines
5.9 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { getGraderById } from '../../src/redteam/graders';
import { AegisGrader } from '../../src/redteam/plugins/aegis';
import { AsciiSmugglingGrader } from '../../src/redteam/plugins/asciiSmuggling';
import { BeavertailsGrader } from '../../src/redteam/plugins/beavertails';
import { BiasGrader } from '../../src/redteam/plugins/bias';
import { CodingAgentGrader } from '../../src/redteam/plugins/codingAgent/graders';
import { FinancialCalculationErrorPluginGrader } from '../../src/redteam/plugins/financial/financialCalculationError';
import { FinancialComplianceViolationPluginGrader } from '../../src/redteam/plugins/financial/financialComplianceViolation';
import { FinancialDataLeakagePluginGrader } from '../../src/redteam/plugins/financial/financialDataLeakage';
import { FinancialHallucinationPluginGrader } from '../../src/redteam/plugins/financial/financialHallucination';
import { FinancialSycophancyPluginGrader } from '../../src/redteam/plugins/financial/financialSycophancy';
import {
HarmfulGrader,
MisinformationDisinformationGrader,
} from '../../src/redteam/plugins/harmful/graders';
import { MCPPluginGrader } from '../../src/redteam/plugins/mcp';
import { MedicalAnchoringBiasPluginGrader } from '../../src/redteam/plugins/medical/medicalAnchoringBias';
import { MedicalHallucinationPluginGrader } from '../../src/redteam/plugins/medical/medicalHallucination';
import { OffTopicPluginGrader } from '../../src/redteam/plugins/offTopic';
import { PlinyGrader } from '../../src/redteam/plugins/pliny';
import { ToolDiscoveryGrader } from '../../src/redteam/plugins/toolDiscovery';
import { ToxicChatGrader } from '../../src/redteam/plugins/toxicChat';
import { UnsafeBenchGrader } from '../../src/redteam/plugins/unsafebench';
describe('getGraderById', () => {
it('should return correct grader for valid ID', () => {
const asciiGrader = getGraderById('promptfoo:redteam:ascii-smuggling');
expect(asciiGrader).toBeInstanceOf(AsciiSmugglingGrader);
const beavertailsGrader = getGraderById('promptfoo:redteam:beavertails');
expect(beavertailsGrader).toBeInstanceOf(BeavertailsGrader);
const harmfulGrader = getGraderById('promptfoo:redteam:harmful');
expect(harmfulGrader).toBeInstanceOf(HarmfulGrader);
const unsafebenchGrader = getGraderById('promptfoo:redteam:unsafebench');
expect(unsafebenchGrader).toBeInstanceOf(UnsafeBenchGrader);
const plinyGrader = getGraderById('promptfoo:redteam:pliny');
expect(plinyGrader).toBeInstanceOf(PlinyGrader);
const toxicChatGrader = getGraderById('promptfoo:redteam:toxic-chat');
expect(toxicChatGrader).toBeInstanceOf(ToxicChatGrader);
const financialCalculationGrader = getGraderById(
'promptfoo:redteam:financial:calculation-error',
);
expect(financialCalculationGrader).toBeInstanceOf(FinancialCalculationErrorPluginGrader);
const financialComplianceGrader = getGraderById(
'promptfoo:redteam:financial:compliance-violation',
);
expect(financialComplianceGrader).toBeInstanceOf(FinancialComplianceViolationPluginGrader);
const financialDataLeakageGrader = getGraderById('promptfoo:redteam:financial:data-leakage');
expect(financialDataLeakageGrader).toBeInstanceOf(FinancialDataLeakagePluginGrader);
const financialHallucinationGrader = getGraderById('promptfoo:redteam:financial:hallucination');
expect(financialHallucinationGrader).toBeInstanceOf(FinancialHallucinationPluginGrader);
const financialSycophancyGrader = getGraderById('promptfoo:redteam:financial:sycophancy');
expect(financialSycophancyGrader).toBeInstanceOf(FinancialSycophancyPluginGrader);
const aegisGrader = getGraderById('promptfoo:redteam:aegis');
expect(aegisGrader).toBeInstanceOf(AegisGrader);
const mcpGrader = getGraderById('promptfoo:redteam:mcp');
expect(mcpGrader).toBeInstanceOf(MCPPluginGrader);
const medicalAnchoringBiasGrader = getGraderById('promptfoo:redteam:medical:anchoring-bias');
expect(medicalAnchoringBiasGrader).toBeInstanceOf(MedicalAnchoringBiasPluginGrader);
const medicalHallucinationGrader = getGraderById('promptfoo:redteam:medical:hallucination');
expect(medicalHallucinationGrader).toBeInstanceOf(MedicalHallucinationPluginGrader);
const offTopicGrader = getGraderById('promptfoo:redteam:off-topic');
expect(offTopicGrader).toBeInstanceOf(OffTopicPluginGrader);
const toolDiscoveryGrader = getGraderById('promptfoo:redteam:tool-discovery');
expect(toolDiscoveryGrader).toBeInstanceOf(ToolDiscoveryGrader);
const biasGrader = getGraderById('promptfoo:redteam:bias');
expect(biasGrader).toBeInstanceOf(BiasGrader);
const codingAgentGrader = getGraderById('promptfoo:redteam:coding-agent:secret-env-read');
expect(codingAgentGrader).toBeInstanceOf(CodingAgentGrader);
});
it('should return specific grader for misinformation-disinformation', () => {
const misinformationGrader = getGraderById(
'promptfoo:redteam:harmful:misinformation-disinformation',
);
expect(misinformationGrader).toBeInstanceOf(MisinformationDisinformationGrader);
expect(misinformationGrader?.id).toBe(
'promptfoo:redteam:harmful:misinformation-disinformation',
);
});
it('should return harmful grader for IDs starting with promptfoo:redteam:harmful', () => {
const specificHarmfulGrader = getGraderById('promptfoo:redteam:harmful:specific-type');
expect(specificHarmfulGrader).toBeInstanceOf(HarmfulGrader);
const anotherHarmfulGrader = getGraderById('promptfoo:redteam:harmful:another-type');
expect(anotherHarmfulGrader).toBeInstanceOf(HarmfulGrader);
});
it('should return undefined for invalid ID', () => {
const invalidGrader = getGraderById('invalid-id');
expect(invalidGrader).toBeUndefined();
});
it('should return undefined for empty ID', () => {
const emptyGrader = getGraderById('');
expect(emptyGrader).toBeUndefined();
});
});