-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration_scribe.py
More file actions
79 lines (66 loc) · 2.34 KB
/
Copy pathtest_integration_scribe.py
File metadata and controls
79 lines (66 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"""Integration tests for Sentinel Scribe — subprocess-level tests with mocked Ollama."""
import json
import os
import sys
import subprocess
import tempfile
import time
import pytest
import yaml
@pytest.fixture
def project_dir(tmp_path):
"""Create a full project directory structure for scribe testing."""
sentinel_dir = tmp_path / ".claude" / "sentinel"
sentinel_dir.mkdir(parents=True)
rules_dir = sentinel_dir / "rules"
rules_dir.mkdir()
drafts_dir = sentinel_dir / "drafts"
drafts_dir.mkdir()
config = {
"model": "gemma3:4b",
"ollama_url": "http://localhost:11434",
"scribe": {
"enabled": True,
"guidance": None,
},
}
with open(sentinel_dir / "config.yaml", "w") as f:
yaml.dump(config, f)
return tmp_path
def test_observe_subprocess_exits_cleanly_without_ollama(project_dir):
"""--observe should exit 0 even when Ollama is unreachable."""
transcript = project_dir / "transcript.jsonl"
with open(transcript, "w") as f:
f.write(json.dumps({
"type": "assistant",
"message": {"role": "assistant", "content": [{"type": "text", "text": "test"}]},
"timestamp": "T1",
}) + "\n")
event = {
"session_id": "integration-test",
"user_prompt": "never touch the billing module",
"transcript_path": str(transcript),
}
env = os.environ.copy()
env["SENTINEL_CONFIG_DIR"] = str(project_dir / ".claude" / "sentinel")
proc = subprocess.run(
[sys.executable, "sentinel_scribe.py", "--observe"],
input=json.dumps(event),
capture_output=True, text=True, env=env,
cwd=os.path.dirname(os.path.abspath(__file__)),
timeout=10,
)
assert proc.returncode == 0
def test_learn_subprocess_exits_cleanly_without_ollama(project_dir):
"""--learn should exit 0 even when Ollama is unreachable."""
with open(project_dir / "CLAUDE.md", "w") as f:
f.write("# Rules\nNever commit secrets.")
env = os.environ.copy()
env["SENTINEL_CONFIG_DIR"] = str(project_dir / ".claude" / "sentinel")
proc = subprocess.run(
[sys.executable, "sentinel_scribe.py", "--learn"],
capture_output=True, text=True, env=env,
cwd=os.path.dirname(os.path.abspath(__file__)),
timeout=10,
)
assert proc.returncode == 0