test(9.20): claude_guard селфтест закрывает круг-8 обе оси
Правки круга 8 (тело исполняемого heredoc под всеми гейтами, cp -n не легализует другой глагол по пути, путь подстановкой команды под гейтом удаления, ложные тревоги пополнения — склеенные флаги/-t/zip-резерв) уже в коде, но собственный селфтест сторожа их не фиксировал. Добавлены 18 кейсов (блок + пропуск для каждого правила): - тело bash/python3 <<EOF: rm первички, распаковка в дело, запись кода — блок; cp во /tmp — пропуск; - cp -n свежего + truncate/редирект существующей первички — блок; два cp -n подряд свежими именами — пропуск; - rm $(echo …)/`pwd` первички — блок; rm $(echo /tmp/…) — пропуск; - mv -vn/-nv/cp -an/mv -n -t 00_intake — пропуск; mv без -n поверх канонического имени — блок; zip-резерв наружу — пропуск; zip внутрь дела — блок. Селфтест 126/126, stage9_spec 96/96, --only 9.20 зелёный. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
f63b9eb0dc
commit
a0195d869a
@@ -1670,6 +1670,68 @@ def selftest() -> int:
|
|||||||
run({"tool_name": "Read", "tool_input": {"file_path": ext_big}}), 0),
|
run({"tool_name": "Read", "tool_input": {"file_path": ext_big}}), 0),
|
||||||
("симлинк вне проекта на большой файл внутри — блок",
|
("симлинк вне проекта на большой файл внутри — блок",
|
||||||
run({"tool_name": "Read", "tool_input": {"file_path": ext_link}}) if ext_link else 2, 2),
|
run({"tool_name": "Read", "tool_input": {"file_path": ext_link}}) if ext_link else 2, 2),
|
||||||
|
# ── Круг 8: тело ИСПОЛНЯЕМОГО heredoc судится ВСЕМИ гейтами, не только чужим CLI ──
|
||||||
|
# `bash <<EOF … EOF` исполняет тело: rm первички, распаковка в дело и запись кода
|
||||||
|
# обязаны блокироваться так же, как в обычной команде (не только вызов чужого CLI).
|
||||||
|
("тело bash <<EOF: rm первички — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "bash <<EOF\nrm " + shlex_quote(existing_intake) + "\nEOF"}}), 2),
|
||||||
|
("тело bash <<EOF: распаковка в первичку — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "bash <<EOF\ntar xf /tmp/a.tar -C cases/klient/delo-2026/00_intake\nEOF"}}), 2),
|
||||||
|
("тело bash <<EOF: cp кода в дело — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "bash <<EOF\ncp /tmp/x.py cases/klient/delo-2026/gen.py\nEOF"}}), 2),
|
||||||
|
("тело python3 - <<EOF: запись кода в дело — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "python3 - <<EOF\nopen('cases/klient/delo-2026/g.py','w')\nEOF"}}), 2),
|
||||||
|
("тело bash <<EOF во временный каталог пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "bash <<EOF\ncp /tmp/a.md /tmp/b.md\nEOF"}}), 0),
|
||||||
|
# ── Круг 8: один cp -n на путь НЕ легализует другой глагол по тому же пути ──────
|
||||||
|
("cp -n свежего + truncate существующей первички — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"cp -n /tmp/a.pdf {shlex_quote(new_intake)} && "
|
||||||
|
f"truncate -s 0 {shlex_quote(existing_intake)}"}}), 2),
|
||||||
|
("cp -n свежего + редирект поверх существующей первички — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"cp -n /tmp/a.pdf {shlex_quote(new_intake)}; "
|
||||||
|
f"echo x > {shlex_quote(existing_intake)}"}}), 2),
|
||||||
|
("два cp -n подряд, обе цели свежие — пропуск",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"cp -n /tmp/a.pdf {shlex_quote(new_intake)} && "
|
||||||
|
f"cp -n /tmp/b.pdf {shlex_quote(intake + '/drug-2026-08-20.pdf')}"}}), 0),
|
||||||
|
# ── Круг 8: путь подстановкой команды ($(…)/бэктики) не уходит мимо гейта удаления ──
|
||||||
|
("rm $(echo …) первички — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"rm -rf $(echo {shlex_quote(intake)})"}}), 2),
|
||||||
|
("rm `pwd` после cd в первичку — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"cd {shlex_quote(intake)} && rm -rf `pwd`"}}), 2),
|
||||||
|
("rm $(echo /tmp/…) вне дела — пропуск",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {"command": "rm -rf $(echo /tmp/scratch)"}}), 0),
|
||||||
|
# ── Круг 8: ложные тревоги пополнения — склеенные флаги, -t, zip-резерв наружу ──
|
||||||
|
("mv -vn свежего файла в 00_intake пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"mv -vn /tmp/a.pdf {shlex_quote(new_intake)}"}}), 0),
|
||||||
|
("mv -nv свежего файла в 00_intake пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"mv -nv /tmp/a.pdf {shlex_quote(intake + '/drug2.pdf')}"}}), 0),
|
||||||
|
("cp -an свежего файла в 00_intake пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"cp -an /tmp/a.pdf {shlex_quote(intake + '/drug3.pdf')}"}}), 0),
|
||||||
|
("mv -n -t 00_intake пополнение пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"mv -n -t {shlex_quote(intake)} /tmp/a.pdf"}}), 0),
|
||||||
|
("mv БЕЗ -n поверх канонического имени первички — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"mv /tmp/a.pdf {shlex_quote(intake + '/skan.pdf')}"}}), 2),
|
||||||
|
("zip-резерв первички наружу пропускается",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": f"zip -r /tmp/rezerv.zip {shlex_quote(intake)}"}}), 0),
|
||||||
|
("zip-архив ВНУТРЬ дела мимо конвейера — блок",
|
||||||
|
run({"tool_name": "Bash", "tool_input": {
|
||||||
|
"command": "zip -r cases/klient/delo-2026/GOTOVO/out.zip /tmp/x"}}), 2),
|
||||||
]
|
]
|
||||||
bad = [name for name, got, want in cases if got != want]
|
bad = [name for name, got, want in cases if got != want]
|
||||||
for name, got, want in cases:
|
for name, got, want in cases:
|
||||||
|
|||||||
Reference in New Issue
Block a user