diff --git a/src/github_agent_bridge/queue.py b/src/github_agent_bridge/queue.py index 5d0903c..73b0393 100644 --- a/src/github_agent_bridge/queue.py +++ b/src/github_agent_bridge/queue.py @@ -27,11 +27,11 @@ def load_schema() -> str: class JobQueue: def __init__(self, path: str | Path): - self.path = Path(path) - self.path.parent.mkdir(parents=True, exist_ok=True) + self.path = Path(path).expanduser() self.init() def connect(self) -> sqlite3.Connection: + self.path.parent.mkdir(parents=True, exist_ok=True) con = sqlite3.connect(self.path, timeout=30, isolation_level=None) con.row_factory = sqlite3.Row con.execute("PRAGMA foreign_keys=ON") diff --git a/tests/test_queue.py b/tests/test_queue.py index 584d07c..74efe9d 100644 --- a/tests/test_queue.py +++ b/tests/test_queue.py @@ -15,6 +15,27 @@ def policy(): return Policy(trusted_orgs={"gisce"}) +def test_queue_expands_user_in_db_path(tmp_path, monkeypatch): + home = tmp_path / "home" + monkeypatch.setenv("HOME", str(home)) + monkeypatch.chdir(tmp_path) + + JobQueue("~/state/q.sqlite3") + + assert (home / "state" / "q.sqlite3").exists() + assert not (tmp_path / "~").exists() + + +def test_connect_recreates_missing_parent_directory(tmp_path): + q = object.__new__(JobQueue) + q.path = tmp_path / "missing" / "q.sqlite3" + + with q.connect() as con: + con.execute("SELECT 1") + + assert q.path.exists() + + def test_enqueue_and_coalesce_same_work_key(tmp_path, monkeypatch): monkeypatch.setattr("github_agent_bridge.actors.github_actor_details_for_context", lambda ctx, *, gh_bin="gh": None) q = JobQueue(tmp_path / "q.sqlite3")