| """Corpus trail logging - appends JSONL rows with a timestamp (no HF needed).""" | |
| import json | |
| import jailbreak_dojo.corpus as corpus_mod | |
| def test_log_appends_jsonl_rows(tmp_path, monkeypatch): | |
| monkeypatch.delenv("HF_TOKEN", raising=False) | |
| monkeypatch.setattr(corpus_mod, "_LOCAL", tmp_path) | |
| monkeypatch.setattr(corpus_mod, "_FILE", tmp_path / "turns.jsonl") | |
| corpus = corpus_mod.Corpus(dataset="") | |
| corpus.log({"session": "s1", "level": 2, "input": "hello wood", "blocked": False, "tokens": 7}) | |
| corpus.log({"session": "s1", "level": 2, "event": "cracked", "tokens": 42}) # no "input" key | |
| rows = [json.loads(line) for line in (tmp_path / "turns.jsonl").read_text().splitlines()] | |
| assert len(rows) == 2 | |
| assert rows[0]["session"] == "s1" and rows[0]["level"] == 2 and "ts" in rows[0] | |
| assert rows[1]["event"] == "cracked" # rows without "input" still log fine | |