Complete multi-pane broadcast, standard terminal right-click actions, batch host selection with progress, and native ssh_close_shell so closing a pane tears down the remote shell. Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.9 KiB
TypeScript
48 lines
1.9 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { analyzeAgentOutput } from '../../src/utils/agentOutput'
|
|
import {
|
|
agentCommandNeedsConfirmation,
|
|
assessAgentCommandRisk,
|
|
} from '../../src/utils/agentCommandRisk'
|
|
|
|
describe('Agent command guardrail', () => {
|
|
it.each([
|
|
['df -h', 'safe'],
|
|
['journalctl -u nginx -n 100', 'safe'],
|
|
['custom-health-check --json', 'low'],
|
|
['sudo cp /tmp/a /etc/a', 'high'],
|
|
['systemctl restart nginx', 'high'],
|
|
['rm -rf /', 'critical'],
|
|
['sudo rm -r -f -- /', 'critical'],
|
|
['dd if=/dev/zero of=/dev/sda', 'critical'],
|
|
['find /tmp -delete', 'high'],
|
|
['cat /etc/os-release && systemctl restart nginx', 'high'],
|
|
])('classifies %s as %s', (command, expected) => {
|
|
expect(assessAgentCommandRisk(command)).toBe(expected)
|
|
})
|
|
|
|
it('uses strict, balanced and permissive confirmation thresholds', () => {
|
|
expect(agentCommandNeedsConfirmation('safe', 'strict')).toBe(false)
|
|
expect(agentCommandNeedsConfirmation('medium', 'strict')).toBe(true)
|
|
expect(agentCommandNeedsConfirmation('medium', 'balanced')).toBe(false)
|
|
expect(agentCommandNeedsConfirmation('high', 'balanced')).toBe(true)
|
|
expect(agentCommandNeedsConfirmation('high', 'permissive')).toBe(false)
|
|
expect(agentCommandNeedsConfirmation('critical', 'permissive')).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('Agent analyze_output tool', () => {
|
|
it('keeps error evidence while bounding long output by line count', () => {
|
|
const lines = Array.from({ length: 160 }, (_, index) =>
|
|
index === 150 ? 'FATAL connection refused' : `normal line ${index}`
|
|
)
|
|
const result = analyzeAgentOutput(lines.join('\n'))
|
|
|
|
expect(result.totalLines).toBe(160)
|
|
expect(result.truncated).toBe(true)
|
|
expect(result.errorLines).toBe(1)
|
|
expect(result.text).toContain('FATAL connection refused')
|
|
expect(result.text).toContain('已省略 80 行')
|
|
})
|
|
})
|