Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/github_agent_bridge/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 21 additions & 0 deletions tests/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down