Files
flynn/src/backends/native/guardrails.test.ts
T
William Valentin 90ce622080 feat(policy): enforce truthfulness and autonomy guardrails
Add runtime truthfulness modes and autonomy-level tool gating with audit metadata for overrides/denials.

Wire policy through prompt assembly, tool execution context, and daemon/gateway agent paths; update tests and planning state for Phase 3 PR #2 completion.
2026-02-12 16:06:45 -08:00

48 lines
1.9 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { getTruthfulnessGuidance, type TruthfulnessMode } from './guardrails.js';
describe('guardrails', () => {
describe('getTruthfulnessGuidance', () => {
it('returns strict guidance for strict mode', () => {
const guidance = getTruthfulnessGuidance('strict');
expect(guidance).toContain('STRICT MODE');
expect(guidance).toContain('Always tell the truth');
expect(guidance).toContain('No lies. No invention. No fabrication.');
expect(guidance).toContain('Tool output and user data');
});
it('returns standard guidance for standard mode', () => {
const guidance = getTruthfulnessGuidance('standard');
expect(guidance).toContain('Truthfulness Policy');
expect(guidance).not.toContain('STRICT MODE');
expect(guidance).toContain('actual tool output');
expect(guidance).toContain('report the failure accurately');
});
it('returns relaxed guidance for relaxed mode', () => {
const guidance = getTruthfulnessGuidance('relaxed');
expect(guidance).toContain('Truthfulness Policy');
expect(guidance).toContain('Be accurate');
expect(guidance.length).toBeLessThan(getTruthfulnessGuidance('standard').length);
});
it('all modes return non-empty strings', () => {
const modes: TruthfulnessMode[] = ['strict', 'standard', 'relaxed'];
for (const mode of modes) {
const guidance = getTruthfulnessGuidance(mode);
expect(guidance).toBeTruthy();
expect(guidance.trim().length).toBeGreaterThan(0);
}
});
it('strict mode has the longest guidance', () => {
const strict = getTruthfulnessGuidance('strict');
const standard = getTruthfulnessGuidance('standard');
const relaxed = getTruthfulnessGuidance('relaxed');
expect(strict.length).toBeGreaterThan(standard.length);
expect(standard.length).toBeGreaterThan(relaxed.length);
});
});
});