Satisfy project quality gates
This commit is contained in:
+56
-7
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
@@ -73,8 +74,16 @@ def test_codex_resume_uses_uuid():
|
||||
def test_codex_capture_session_id(tmp_path):
|
||||
sessions_dir = tmp_path / ".codex" / "sessions" / "2026" / "06" / "09"
|
||||
sessions_dir.mkdir(parents=True)
|
||||
rollout = sessions_dir / "rollout-20260609-abcdef12-3456-7890-abcd-ef1234567890.jsonl"
|
||||
meta = {"type": "session_meta", "payload": {"id": "abcdef12-3456-7890-abcd-ef1234567890", "cwd": "/projects/foo"}}
|
||||
rollout = (
|
||||
sessions_dir / "rollout-20260609-abcdef12-3456-7890-abcd-ef1234567890.jsonl"
|
||||
)
|
||||
meta = {
|
||||
"type": "session_meta",
|
||||
"payload": {
|
||||
"id": "abcdef12-3456-7890-abcd-ef1234567890",
|
||||
"cwd": "/projects/foo",
|
||||
},
|
||||
}
|
||||
rollout.write_text(json.dumps(meta) + "\n")
|
||||
|
||||
since = time.time() - 60 # far enough back that freshly-written file qualifies
|
||||
@@ -100,7 +109,9 @@ def test_codex_capture_session_id_wrong_cwd(tmp_path):
|
||||
|
||||
@patch("hqt.harnesses.registry.shutil.which")
|
||||
def test_registry_discovers_harnesses(mock_which):
|
||||
mock_which.side_effect = lambda x: "/usr/bin/" + x if x in ("claude", "codex") else None
|
||||
mock_which.side_effect = lambda x: (
|
||||
"/usr/bin/" + x if x in ("claude", "codex") else None
|
||||
)
|
||||
result = discover_harnesses()
|
||||
assert "claude" in result
|
||||
assert "codex" in result
|
||||
@@ -120,6 +131,7 @@ def test_codex_captures_session_id_flag():
|
||||
def test_base_captures_session_id_flag_false():
|
||||
"""HarnessConfigurator base class default must be False."""
|
||||
from hqt.harnesses.base import HarnessConfigurator
|
||||
|
||||
assert HarnessConfigurator.captures_session_id is False
|
||||
|
||||
|
||||
@@ -128,8 +140,12 @@ def test_claude_captures_session_id_flag_false():
|
||||
assert ClaudeConfigurator.captures_session_id is False
|
||||
|
||||
|
||||
def _write_rollout(path: Path, session_id: str, cwd: str) -> None:
|
||||
def _write_rollout(
|
||||
path: Path, session_id: str, cwd: str, timestamp: str | None = None
|
||||
) -> None:
|
||||
meta = {"type": "session_meta", "payload": {"id": session_id, "cwd": cwd}}
|
||||
if timestamp:
|
||||
meta["payload"]["timestamp"] = timestamp
|
||||
path.write_text(json.dumps(meta) + "\n")
|
||||
|
||||
|
||||
@@ -168,8 +184,8 @@ def test_codex_capture_accepts_file_after_since(tmp_path):
|
||||
assert result == "new-id"
|
||||
|
||||
|
||||
def test_codex_capture_newest_post_since_cwd_match_wins(tmp_path):
|
||||
"""Among multiple post-since rollouts, newest matching cwd wins over older matching."""
|
||||
def test_codex_capture_first_post_since_cwd_match_wins(tmp_path):
|
||||
"""Among multiple post-since rollouts, the one started nearest since wins."""
|
||||
sessions_dir = tmp_path / ".codex" / "sessions" / "dir"
|
||||
sessions_dir.mkdir(parents=True)
|
||||
|
||||
@@ -186,7 +202,39 @@ def test_codex_capture_newest_post_since_cwd_match_wins(tmp_path):
|
||||
c = CodexConfigurator()
|
||||
with patch("hqt.harnesses.configurators.codex.Path.home", return_value=tmp_path):
|
||||
result = c.capture_session_id(Path("/projects/foo"), since)
|
||||
assert result == "newer-id"
|
||||
assert result == "older-id"
|
||||
|
||||
|
||||
def test_codex_capture_prefers_started_nearest_since_over_newest_file(tmp_path):
|
||||
"""Late capture should match the Codex session spawned at since, not a later same-cwd session."""
|
||||
sessions_dir = tmp_path / ".codex" / "sessions" / "dir"
|
||||
sessions_dir.mkdir(parents=True)
|
||||
|
||||
target = sessions_dir / "rollout-target.jsonl"
|
||||
unrelated_later = sessions_dir / "rollout-later.jsonl"
|
||||
|
||||
since = datetime(2026, 6, 10, 21, 9, 15, tzinfo=UTC).timestamp()
|
||||
_write_rollout(
|
||||
target,
|
||||
"target-id",
|
||||
"/projects/foo",
|
||||
timestamp="2026-06-10T21:09:16.000Z",
|
||||
)
|
||||
_write_rollout(
|
||||
unrelated_later,
|
||||
"later-id",
|
||||
"/projects/foo",
|
||||
timestamp="2026-06-10T21:45:45.000Z",
|
||||
)
|
||||
|
||||
now = time.time()
|
||||
os.utime(target, (now - 60, now - 60))
|
||||
os.utime(unrelated_later, (now, now))
|
||||
|
||||
c = CodexConfigurator()
|
||||
with patch("hqt.harnesses.configurators.codex.Path.home", return_value=tmp_path):
|
||||
result = c.capture_session_id(Path("/projects/foo"), since)
|
||||
assert result == "target-id"
|
||||
|
||||
|
||||
def test_codex_capture_skips_non_matching_cwd_picks_older_matching(tmp_path):
|
||||
@@ -273,6 +321,7 @@ CODEX_IDLE_SCREEN = """\
|
||||
def test_base_parse_status_returns_none():
|
||||
"""Base HarnessConfigurator.parse_status always returns None."""
|
||||
from hqt.harnesses.configurators.kiro import KiroConfigurator
|
||||
|
||||
k = KiroConfigurator()
|
||||
assert k.parse_status("anything") is None
|
||||
assert k.parse_status("") is None
|
||||
|
||||
Reference in New Issue
Block a user