95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
import { describe, it, expect } from 'vitest';
|
|
import { decide } from './enforce-classifier-match.mjs';
|
|
|
|
describe('enforce-classifier-match / decide', () => {
|
|
it('allows pure conversation (no mutating tools)', () => {
|
|
expect(decide({
|
|
toolUses: [{ name: 'Read' }],
|
|
recommendation: 'superpowers:writing-plans',
|
|
confidence: 0.9,
|
|
}).block).toBe(false);
|
|
});
|
|
|
|
it('allows when no recommendation', () => {
|
|
expect(decide({
|
|
toolUses: [{ name: 'Edit', input: {} }],
|
|
recommendation: null,
|
|
confidence: null,
|
|
}).block).toBe(false);
|
|
});
|
|
|
|
it('allows when confidence below threshold', () => {
|
|
expect(decide({
|
|
toolUses: [{ name: 'Edit', input: {} }],
|
|
recommendation: 'superpowers:writing-plans',
|
|
confidence: 0.5,
|
|
}).block).toBe(false);
|
|
});
|
|
|
|
it('blocks when recommendation high-confidence + no matching tool', () => {
|
|
const r = decide({
|
|
toolUses: [{ name: 'Edit', input: { file_path: 'x.mjs' } }],
|
|
recommendation: 'superpowers:writing-plans',
|
|
confidence: 0.9,
|
|
});
|
|
expect(r.block).toBe(true);
|
|
expect(r.message).toMatch(/writing-plans/);
|
|
});
|
|
|
|
it('allows when Skill tool invoked with matching name', () => {
|
|
const r = decide({
|
|
toolUses: [
|
|
{ name: 'Skill', input: { skill: 'superpowers:writing-plans' } },
|
|
{ name: 'Edit', input: { file_path: 'x.mjs' } },
|
|
],
|
|
recommendation: 'superpowers:writing-plans',
|
|
confidence: 0.9,
|
|
});
|
|
expect(r.block).toBe(false);
|
|
});
|
|
|
|
it('matches normalized name without superpowers: prefix', () => {
|
|
const r = decide({
|
|
toolUses: [
|
|
{ name: 'Skill', input: { skill: 'writing-plans' } },
|
|
{ name: 'Edit', input: {} },
|
|
],
|
|
recommendation: 'superpowers:writing-plans',
|
|
confidence: 0.9,
|
|
});
|
|
expect(r.block).toBe(false);
|
|
});
|
|
|
|
it('matches Task subagent', () => {
|
|
const r = decide({
|
|
toolUses: [
|
|
{ name: 'Task', input: { subagent_type: 'rls-reviewer' } },
|
|
{ name: 'Edit', input: {} },
|
|
],
|
|
recommendation: 'rls-reviewer',
|
|
confidence: 0.85,
|
|
});
|
|
expect(r.block).toBe(false);
|
|
});
|
|
|
|
it('allows when explicit "override:" in assistant text', () => {
|
|
const r = decide({
|
|
toolUses: [{ name: 'Edit', input: {} }],
|
|
recommendation: 'foo:bar',
|
|
confidence: 0.9,
|
|
assistantText: 'override: simpler direct edit, foo:bar overkill here\n',
|
|
});
|
|
expect(r.block).toBe(false);
|
|
});
|
|
|
|
it('allows when override phrase present', () => {
|
|
const r = decide({
|
|
toolUses: [{ name: 'Edit', input: {} }],
|
|
recommendation: 'foo:bar',
|
|
confidence: 0.9,
|
|
override: { phrase: 'direct ok', suppresses: ['classifier-mismatch'] },
|
|
});
|
|
expect(r.block).toBe(false);
|
|
});
|
|
});
|