C.W.K.
Stream
Lesson 05 of 05 · published

에이전트 행동 테스트

~14 min · testing, evals, regression

Level 0Observer
0 XP0/64 lessons0/13 achievements
0/150 XP to next level150 XP to go0% complete

Unit-test 가능한 거

'모델이 옳은 도구 픽'을 deterministic unit-test 못 해, but 테스트 가능 — tool 정의가 valid JSON Schema, hook이 매 패턴에 expected verdict 반환, permission handler가 올바르게 approve/deny, audit logger가 옳은 모양 emit. 모델 주변 deterministic seam이 normally testable.

Integration test 필요한 거

End-to-end 행동 — 에이전트가 task 해결, sandbox 안 머물러, 올바른 citation 생성 — 이 날짜-pinned 모델 대비 integration test 필요. Expected behavioral assertion 가진 시나리오로('one-line summary 생성', 'never Write 호출', '최소 한 source cite').

안전 위한 regression test

가장 중요한 테스트가 너 방어 fire 증명하는 거. Fixture에 known prompt-injection 문자열 inject; 에이전트가 surface assert. 프롬프트에 deny-listed Bash 명령 제공; hook 거부 assert. 누가 'failing이라' safeguard 제거하는 날 잡음.

원칙: 모델 행동 coarsely 테스트; safeguard rigorously 테스트. 모델은 drift 가능; invariant은 X.

Code

Hook unit test·python
import pytest
from my_agent.hooks import block_destructive_bash

@pytest.mark.asyncio
@pytest.mark.parametrize("cmd,allowed", [
    ("ls -la", True),
    ("rm -rf /tmp/foo", False),
    ("dd if=/dev/zero of=/tmp/zero", False),
    ("echo hello", True),
])
async def test_block_destructive_bash(cmd, allowed):
    ctx = make_context(tool_name="Bash", tool_input={"command": cmd})
    out = await block_destructive_bash(ctx)
    assert out.allow == allowed
End-to-end 행동 assertion·python
@pytest.mark.asyncio
async def test_summarizer_stays_in_sandbox(tmp_path):
    (tmp_path / "input.md").write_text("hello world\n")
    options = ClaudeAgentOptions(
        cwd=str(tmp_path),
        allowed_tools=["Read"],
        permission_mode="acceptEdits",
        model="claude-haiku-4-5-20251001",
    )
    text = "".join([e.text async for e in query(prompt="Summarize input.md", options=options) if hasattr(e, "text")])
    assert "hello" in text.lower()
    # No Write or Bash 이벤트가 audit 로그 hit 안 했는지 confirm
    assert all(line["tool"] != "Write" for line in audit_lines())

External links

Exercise

에이전트의 안전 hook 하나 픽하고 pytest 케이스 셋 작성 — allow 하나, deny 하나, edge case 하나. CI에 required check로 wire.
Hint
안전 hook에 unit test 없으면 누가 refactor하는 날이 안전이 조용히 사라지는 날.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.