51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
import json
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from scripts.oc_dispatch_audit import audit
|
|
|
|
FIXTURES_DIR = os.path.abspath(
|
|
os.path.join(os.path.dirname(__file__), "fixtures/oc_audit")
|
|
)
|
|
|
|
|
|
def load_fixture(name):
|
|
with open(os.path.join(FIXTURES_DIR, f"{name}.json"), "r") as f:
|
|
return json.load(f)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"fixture, worktree, child_tool_counts, expected_flags",
|
|
[
|
|
("dead_dispatch", None, {}, ["DEAD"]),
|
|
("banned_agent", None, {}, ["BANNED"]),
|
|
("clean", "/tmp/work", {}, []),
|
|
("task_id_resume", None, {}, []),
|
|
("nowt", "/tmp/work", {}, ["NOWT"]),
|
|
("idle", None, {"ses_idle": 0}, ["IDLE"]),
|
|
],
|
|
)
|
|
def test_audit_scenarios(fixture, worktree, child_tool_counts, expected_flags):
|
|
parts = load_fixture(fixture)
|
|
results = audit(parts, child_tool_counts, worktree)
|
|
|
|
assert len(results) > 0, f"No results for {fixture}"
|
|
actual_flags = results[0]["flags"]
|
|
assert set(actual_flags) == set(expected_flags), (
|
|
f"Fixture {fixture}: expected {expected_flags}, got {actual_flags}"
|
|
)
|
|
|
|
|
|
def test_clean_with_worktree():
|
|
parts = load_fixture("clean")
|
|
results = audit(parts, {}, "/tmp/work")
|
|
assert results[0]["flags"] == []
|
|
|
|
|
|
def test_nowt_without_worktree():
|
|
# If worktree arg is NOT provided, NOWT should not flag
|
|
parts = load_fixture("nowt")
|
|
results = audit(parts, {}, None)
|
|
assert "NOWT" not in results[0]["flags"]
|