Updates
CI / PowerShell tests on Ubuntu (push) Failing after 3s
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 22s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 11s
CI / Installed client configuration smoke tests (push) Successful in 59s
CI / Bash integration and installation guards (push) Successful in 1m31s
CI / PowerShell tests on Ubuntu (push) Failing after 3s
CI / CI configuration security checks (push) Successful in 2s
CI / Capabilities and shell quality (push) Successful in 12s
CI / Python tests and compilation (push) Successful in 22s
CI / QMD unit tests (push) Successful in 5s
CI / Build and inspect generated packages (push) Successful in 11s
CI / Installed client configuration smoke tests (push) Successful in 59s
CI / Bash integration and installation guards (push) Successful in 1m31s
This commit is contained in:
1 parent
2192b4613d
commit
e19aa2e27c
26 files changed
+278
-31
No files matched your search
@@ -0,0 +1,113 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
SCRIPTS = ROOT / 'shared/hooks/scripts'
|
||||
GUARDS = SCRIPTS / 'agent-guards.py'
|
||||
|
||||
|
||||
def guard(mode, event, cwd=None):
|
||||
payload = event if isinstance(event, str) else json.dumps(event)
|
||||
result = subprocess.run([sys.executable, str(GUARDS), mode], cwd=cwd, input=payload, capture_output=True,
|
||||
encoding='utf-8', timeout=20)
|
||||
assert result.returncode == 0, result.stderr
|
||||
return result.stdout
|
||||
|
||||
|
||||
def git(workspace, *args):
|
||||
subprocess.run(['git', '-C', str(workspace), *args], check=True, capture_output=True)
|
||||
|
||||
|
||||
class CompletionEvidenceTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.workspace = Path(directory.name)
|
||||
git(self.workspace, 'init', '--quiet')
|
||||
|
||||
def event(self, message, **overrides):
|
||||
return dict({'cwd': str(self.workspace), 'stop_hook_active': False, 'last_assistant_message': message}, **overrides)
|
||||
|
||||
def test_blocks_unbacked_claim_with_changed_code(self):
|
||||
(self.workspace / 'app.py').write_text('x = 1\n')
|
||||
for message in ('All done.', 'Fehler ist behoben.'):
|
||||
self.assertEqual(json.loads(guard('stop', self.event(message)))['decision'], 'block')
|
||||
|
||||
def test_allows_other_stops(self):
|
||||
(self.workspace / 'app.py').write_text('x = 1\n')
|
||||
cases = (self.event('Done. Tests: 12 passed.'), self.event('Fertig, aber nicht getestet.'),
|
||||
self.event('Which option do you prefer?'), self.event('All done.', stop_hook_active=True))
|
||||
for event in cases:
|
||||
self.assertEqual(guard('stop', event), '')
|
||||
|
||||
def test_allows_clean_or_prose_only_workspace(self):
|
||||
self.assertEqual(guard('stop', self.event('All done.')), '')
|
||||
(self.workspace / 'notes.md').write_text('text\n')
|
||||
self.assertEqual(guard('stop', self.event('All done.')), '')
|
||||
|
||||
def test_fails_open_on_malformed_events(self):
|
||||
for event in ('', 'not json', '[]', {'cwd': 7, 'last_assistant_message': 'done'},
|
||||
{'cwd': str(self.workspace / 'missing'), 'last_assistant_message': 'done'},
|
||||
{'cwd': str(self.workspace), 'last_assistant_message': None}):
|
||||
self.assertEqual(guard('stop', event, cwd=self.workspace), '')
|
||||
|
||||
def test_does_not_run_repository_fsmonitor(self):
|
||||
marker = self.workspace / 'fsmonitor-ran'
|
||||
hook = self.workspace / 'monitor.py'
|
||||
hook.write_text(f'open({str(marker)!r}, "w")\n')
|
||||
git(self.workspace, 'config', 'core.fsmonitor', f'{Path(sys.executable).as_posix()} {hook.as_posix()}')
|
||||
guard('stop', self.event('All done.'))
|
||||
self.assertFalse(marker.exists())
|
||||
|
||||
|
||||
class CorrectionPromptTests(unittest.TestCase):
|
||||
def test_flags_corrections(self):
|
||||
for prompt in ('Nein, nimm die andere Datei', 'das ist falsch', 'Er darf niemals pushen', "that's wrong",
|
||||
'you forgot the tests', 'not what I asked', 'Schon wieder ohne Tests'):
|
||||
output = json.loads(guard('prompt', {'prompt': prompt}))['hookSpecificOutput']
|
||||
self.assertEqual(output['hookEventName'], 'UserPromptSubmit')
|
||||
self.assertIn('approval', output['additionalContext'])
|
||||
|
||||
def test_ignores_other_prompts(self):
|
||||
for prompt in ('Add a logout button', 'was würdest du mir stattdessen empfehlen?', '/nein', 'no' + ' x' * 1500,
|
||||
'Der Test ist nicht grün'):
|
||||
self.assertEqual(guard('prompt', {'prompt': prompt}), '')
|
||||
|
||||
def test_never_echoes_the_prompt(self):
|
||||
self.assertNotIn('geheim', guard('prompt', {'prompt': 'Nein, das Passwort geheim bleibt'}))
|
||||
|
||||
def test_fails_open_on_malformed_events(self):
|
||||
for event in ('', 'not json', {}, {'prompt': 3}):
|
||||
self.assertEqual(guard('prompt', event), '')
|
||||
|
||||
|
||||
class EntryPointTests(unittest.TestCase):
|
||||
def test_shell_entry_points(self):
|
||||
shells = (('powershell', shutil.which('pwsh') or shutil.which('powershell'), 0), ('bash', shutil.which('bash'), 1))
|
||||
names = ((('Show-CorrectionPrompt.ps1', 'show-correction-prompt.sh'), {'prompt': 'Nein, anders'}, 'additionalContext'),
|
||||
(('Check-CompletionEvidence.ps1', 'check-completion-evidence.sh'), None, 'decision'))
|
||||
for shell, executable, index in shells:
|
||||
if not executable or (shell == 'bash' and sys.platform == 'win32'):
|
||||
continue
|
||||
with self.subTest(shell=shell), tempfile.TemporaryDirectory() as directory:
|
||||
workspace = Path(directory)
|
||||
git(workspace, 'init', '--quiet')
|
||||
(workspace / 'app.py').write_text('x = 1\n')
|
||||
for scripts, event, expected in names:
|
||||
event = event or {'cwd': str(workspace), 'last_assistant_message': 'All done.'}
|
||||
script = str(SCRIPTS / scripts[index])
|
||||
command = ([executable, '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', script]
|
||||
if shell == 'powershell' else [executable, script])
|
||||
result = subprocess.run(command, input=json.dumps(event), capture_output=True, encoding='utf-8', timeout=30)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stderr, '')
|
||||
self.assertIn(expected, json.loads(result.stdout) | json.loads(result.stdout).get('hookSpecificOutput', {}))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -61,12 +61,12 @@ foreach ($shell in @('powershell','bash')) {
|
||||
if ($shell -eq 'powershell' -and $content -match 'WindowStyle\s+Hidden') { throw "PowerShell hook hides the terminal in $package" }
|
||||
if ($client -eq 'codex') {
|
||||
$events = @([regex]::Matches($content, '(?m)^\[\[hooks\.([^.\]]+)\]\]\s*$') | ForEach-Object { $_.Groups[1].Value })
|
||||
if ((($events | Sort-Object) -join ',') -ne 'SessionStart,Stop' -or $content -match 'flashbang-if-input' -or $content -match '(?m)^async\s*=\s*true\s*$') { throw "Codex finish hook is incorrect in $package" }
|
||||
if ((($events | Sort-Object) -join ',') -ne 'SessionStart,Stop,Stop,UserPromptSubmit' -or $content -match 'flashbang-if-input' -or $content -match '(?m)^async\s*=\s*true\s*$') { throw "Codex finish hook is incorrect in $package" }
|
||||
if ($content -notmatch 'approvals_reviewer\s*=\s*"auto_review"') { throw "Codex auto review is missing in $package" }
|
||||
if ($content -notmatch '(?m)^sandbox_mode\s*=\s*"danger-full-access"\s*$') { throw "Codex full access is missing in $package" }
|
||||
if ($content -notmatch '(?m)^max_depth\s*=\s*1\s*$') { throw "Codex agent depth limit is missing in $package" }
|
||||
if ($content -notmatch 'status_line\s*=\s*\["model", "reasoning", "fast-mode", "approval-mode", "five-hour-limit", "weekly-limit", "project-name", "git-branch", "context-window-size", "context-used", "used-tokens"\]') { throw "Codex status line is incorrect in $package" }
|
||||
} elseif ((($settings.hooks.PSObject.Properties.Name | Sort-Object) -join ',') -ne 'PreCompact,SessionStart,Stop' -or $content -match 'flashbang-if-input' -or $settings.hooks.Stop[0].hooks[0].async) {
|
||||
} elseif ((($settings.hooks.PSObject.Properties.Name | Sort-Object) -join ',') -ne 'PreCompact,SessionStart,Stop,UserPromptSubmit' -or $content -match 'flashbang-if-input' -or $settings.hooks.Stop[0].hooks[0].async) {
|
||||
throw "Claude finish hook is incorrect in $package"
|
||||
} elseif ($content -notmatch '"defaultMode"\s*:\s*"auto"') {
|
||||
throw "Claude auto permission mode is missing in $package"
|
||||
|
||||
@@ -79,7 +79,7 @@ for shell in powershell bash; do
|
||||
grep -q 'bash .*flashbang.sh' "$package/$file"
|
||||
fi
|
||||
if [ "$client" = codex ]; then
|
||||
[ "$(sed -n 's/^\[\[hooks\.\([^].]*\)\]\]$/\1/p' "$package/$file" | sort)" = $'SessionStart\nStop' ]
|
||||
[ "$(sed -n 's/^\[\[hooks\.\([^].]*\)\]\]$/\1/p' "$package/$file" | sort)" = $'SessionStart\nStop\nStop\nUserPromptSubmit' ]
|
||||
! grep -q 'flashbang-if-input' "$package/$file"
|
||||
! grep -Eq '^async[[:space:]]*=[[:space:]]*true[[:space:]]*$' "$package/$file"
|
||||
grep -q 'approvals_reviewer[[:space:]]*=[[:space:]]*"auto_review"' "$package/$file"
|
||||
@@ -87,7 +87,7 @@ for shell in powershell bash; do
|
||||
grep -Eq '^max_depth[[:space:]]*=[[:space:]]*1[[:space:]]*$' "$package/$file"
|
||||
grep -Fq 'status_line = ["model", "reasoning", "fast-mode", "approval-mode", "five-hour-limit", "weekly-limit", "project-name", "git-branch", "context-window-size", "context-used", "used-tokens"]' "$package/$file"
|
||||
else
|
||||
python3 -c 'import json,sys; settings=json.load(open(sys.argv[1], encoding="utf-8-sig")); assert set(settings["hooks"]) == {"PreCompact", "SessionStart", "Stop"}' "$package/$file"
|
||||
python3 -c 'import json,sys; settings=json.load(open(sys.argv[1], encoding="utf-8-sig")); assert set(settings["hooks"]) == {"PreCompact", "SessionStart", "Stop", "UserPromptSubmit"}' "$package/$file"
|
||||
! grep -q 'flashbang-if-input' "$package/$file"
|
||||
! grep -q '"async"[[:space:]]*:[[:space:]]*true' "$package/$file"
|
||||
grep -q '"defaultMode"[[:space:]]*:[[:space:]]*"auto"' "$package/$file"
|
||||
|
||||
Reference in new issue
Block a user