Files
opsxshell/test/utils/agentHarness.test.ts
T
Logan.Li b0d0e3a5f3 feat(i18n): add multi-language support (ja/ko/vi/ru/zh-TW) with system auto-detection
- Extend AppLanguage to 7 locales: zh-CN, zh-TW, en, ja, ko, vi, ru
- Auto-detect system language via navigator.languages; fallback to English
- Add BCP47 locale mapping for date formatting and sorting
- Create 50 translation JSON files (5 languages × 10 namespaces, 1137 keys each)
- Update language selector with native language names
- Extend locale key parity test to cover all 7 languages (70 assertions)
- Add VNC/RDP desktop, serial terminal, AI agent, port forwarding, and SFTP features
- Add credential encryption, host metrics, session backup crypto, and zmodem bridge
- Update Rust backend: desktop services, host metrics, SSH/SFTP enhancements
2026-08-12 00:07:48 +08:00

58 lines
2.3 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { analyzeAgentOutput } from '../../src/utils/agentOutput'
import {
agentCommandAllowFingerprint,
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 and relaxed confirmation thresholds', () => {
expect(agentCommandNeedsConfirmation('safe', 'strict')).toBe(false)
expect(agentCommandNeedsConfirmation('medium', 'strict')).toBe(true)
expect(agentCommandNeedsConfirmation('medium', 'relaxed')).toBe(false)
expect(agentCommandNeedsConfirmation('high', 'relaxed')).toBe(true)
expect(agentCommandNeedsConfirmation('critical', 'relaxed')).toBe(false)
expect(agentCommandNeedsConfirmation('critical', 'strict')).toBe(false)
})
it('fingerprints similar temp-path commands for session Always', () => {
expect(agentCommandAllowFingerprint('rm /tmp/tmp.3RUZRHTwk2', 'high')).toBe(
agentCommandAllowFingerprint('rm /tmp/tmp.ABCDEFG123', 'high')
)
expect(agentCommandAllowFingerprint('rm /tmp/tmp.3RUZRHTwk2', 'high')).not.toBe(
agentCommandAllowFingerprint('rm -rf /var/log/nginx', 'high')
)
})
})
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 行')
})
})