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
163 lines
6.4 KiB
TypeScript
163 lines
6.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import {
|
|
ATTACK_PROVIDER_IDS,
|
|
getAttackProviderFullId,
|
|
isAttackProvider,
|
|
isMultiTurnStrategy,
|
|
} from '../../../src/redteam/shared/attackProviders';
|
|
|
|
describe('attackProviders', () => {
|
|
describe('ATTACK_PROVIDER_IDS', () => {
|
|
it('should contain all expected multi-turn attack providers', () => {
|
|
expect(ATTACK_PROVIDER_IDS).toContain('hydra');
|
|
expect(ATTACK_PROVIDER_IDS).toContain('crescendo');
|
|
expect(ATTACK_PROVIDER_IDS).toContain('goat');
|
|
expect(ATTACK_PROVIDER_IDS).toContain('custom');
|
|
});
|
|
|
|
it('should contain all expected single-turn iterative attack providers', () => {
|
|
expect(ATTACK_PROVIDER_IDS).toContain('iterative');
|
|
expect(ATTACK_PROVIDER_IDS).toContain('iterative:meta');
|
|
expect(ATTACK_PROVIDER_IDS).toContain('iterative:tree');
|
|
});
|
|
|
|
it('should not contain unsupported strategies', () => {
|
|
expect(ATTACK_PROVIDER_IDS).not.toContain('mischievous-user');
|
|
});
|
|
});
|
|
|
|
describe('isAttackProvider', () => {
|
|
describe('multi-turn conversation providers', () => {
|
|
it('should return true for hydra variants', () => {
|
|
expect(isAttackProvider('hydra')).toBe(true);
|
|
expect(isAttackProvider('jailbreak:hydra')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:hydra')).toBe(true);
|
|
});
|
|
|
|
it('should return true for crescendo variants', () => {
|
|
expect(isAttackProvider('crescendo')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:crescendo')).toBe(true);
|
|
});
|
|
|
|
it('should return true for goat variants', () => {
|
|
expect(isAttackProvider('goat')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:goat')).toBe(true);
|
|
});
|
|
|
|
it('should return true for custom variants', () => {
|
|
expect(isAttackProvider('custom')).toBe(true);
|
|
expect(isAttackProvider('custom:my-custom')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:custom')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('multi-attempt single-turn providers', () => {
|
|
it('should return true for iterative (base jailbreak)', () => {
|
|
expect(isAttackProvider('iterative')).toBe(true);
|
|
expect(isAttackProvider('jailbreak')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:iterative')).toBe(true);
|
|
});
|
|
|
|
it('should return true for iterative:meta (jailbreak:meta)', () => {
|
|
expect(isAttackProvider('iterative:meta')).toBe(true);
|
|
expect(isAttackProvider('jailbreak:meta')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:iterative:meta')).toBe(true);
|
|
});
|
|
|
|
it('should return true for iterative:tree (jailbreak:tree)', () => {
|
|
expect(isAttackProvider('iterative:tree')).toBe(true);
|
|
expect(isAttackProvider('jailbreak:tree')).toBe(true);
|
|
expect(isAttackProvider('promptfoo:redteam:iterative:tree')).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('non-attack providers', () => {
|
|
it('should return false for transform strategies', () => {
|
|
expect(isAttackProvider('base64')).toBe(false);
|
|
expect(isAttackProvider('rot13')).toBe(false);
|
|
expect(isAttackProvider('hex')).toBe(false);
|
|
expect(isAttackProvider('audio')).toBe(false);
|
|
expect(isAttackProvider('image')).toBe(false);
|
|
});
|
|
|
|
it('should return false for unsupported attack strategies', () => {
|
|
expect(isAttackProvider('mischievous-user')).toBe(false);
|
|
});
|
|
|
|
it('should return false for basic and other non-attack strategies', () => {
|
|
expect(isAttackProvider('basic')).toBe(false);
|
|
expect(isAttackProvider('default')).toBe(false);
|
|
expect(isAttackProvider('unknown')).toBe(false);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getAttackProviderFullId', () => {
|
|
describe('already full IDs', () => {
|
|
it('should return the same ID if already full', () => {
|
|
expect(getAttackProviderFullId('promptfoo:redteam:hydra')).toBe('promptfoo:redteam:hydra');
|
|
expect(getAttackProviderFullId('promptfoo:redteam:iterative')).toBe(
|
|
'promptfoo:redteam:iterative',
|
|
);
|
|
expect(getAttackProviderFullId('promptfoo:redteam:iterative:meta')).toBe(
|
|
'promptfoo:redteam:iterative:meta',
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('jailbreak variants', () => {
|
|
it('should convert jailbreak (base) to promptfoo:redteam:iterative', () => {
|
|
expect(getAttackProviderFullId('jailbreak')).toBe('promptfoo:redteam:iterative');
|
|
});
|
|
|
|
it('should convert jailbreak:meta to promptfoo:redteam:iterative:meta', () => {
|
|
expect(getAttackProviderFullId('jailbreak:meta')).toBe('promptfoo:redteam:iterative:meta');
|
|
});
|
|
|
|
it('should convert jailbreak:tree to promptfoo:redteam:iterative:tree', () => {
|
|
expect(getAttackProviderFullId('jailbreak:tree')).toBe('promptfoo:redteam:iterative:tree');
|
|
});
|
|
|
|
it('should convert jailbreak:hydra to promptfoo:redteam:hydra', () => {
|
|
expect(getAttackProviderFullId('jailbreak:hydra')).toBe('promptfoo:redteam:hydra');
|
|
});
|
|
});
|
|
|
|
describe('custom variants', () => {
|
|
it('should convert custom to promptfoo:redteam:custom', () => {
|
|
expect(getAttackProviderFullId('custom')).toBe('promptfoo:redteam:custom');
|
|
});
|
|
|
|
it('should convert custom:variant to promptfoo:redteam:custom', () => {
|
|
expect(getAttackProviderFullId('custom:my-custom')).toBe('promptfoo:redteam:custom');
|
|
});
|
|
});
|
|
|
|
describe('short IDs', () => {
|
|
it('should convert short IDs to full IDs', () => {
|
|
expect(getAttackProviderFullId('hydra')).toBe('promptfoo:redteam:hydra');
|
|
expect(getAttackProviderFullId('crescendo')).toBe('promptfoo:redteam:crescendo');
|
|
expect(getAttackProviderFullId('goat')).toBe('promptfoo:redteam:goat');
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('isMultiTurnStrategy', () => {
|
|
it('should return true for multi-turn strategies', () => {
|
|
expect(isMultiTurnStrategy('hydra')).toBe(true);
|
|
expect(isMultiTurnStrategy('crescendo')).toBe(true);
|
|
expect(isMultiTurnStrategy('goat')).toBe(true);
|
|
});
|
|
|
|
it('should handle various ID formats', () => {
|
|
expect(isMultiTurnStrategy('jailbreak:hydra')).toBe(true);
|
|
expect(isMultiTurnStrategy('promptfoo:redteam:hydra')).toBe(true);
|
|
});
|
|
|
|
it('should return false for non-multi-turn strategies', () => {
|
|
expect(isMultiTurnStrategy('base64')).toBe(false);
|
|
expect(isMultiTurnStrategy('basic')).toBe(false);
|
|
});
|
|
});
|
|
});
|