builderguild 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. builderguild-0.1.0/LICENSE +22 -0
  2. builderguild-0.1.0/PKG-INFO +13 -0
  3. builderguild-0.1.0/README.md +116 -0
  4. builderguild-0.1.0/builderguild/builderguild/__init__.py +1 -0
  5. builderguild-0.1.0/builderguild/builderguild/cli.py +76 -0
  6. builderguild-0.1.0/builderguild/builderguild/config.py +43 -0
  7. builderguild-0.1.0/builderguild/builderguild/errors.py +10 -0
  8. builderguild-0.1.0/builderguild/builderguild/graph.py +60 -0
  9. builderguild-0.1.0/builderguild/builderguild.egg-info/PKG-INFO +13 -0
  10. builderguild-0.1.0/builderguild/builderguild.egg-info/SOURCES.txt +27 -0
  11. builderguild-0.1.0/builderguild/builderguild.egg-info/dependency_links.txt +1 -0
  12. builderguild-0.1.0/builderguild/builderguild.egg-info/entry_points.txt +2 -0
  13. builderguild-0.1.0/builderguild/builderguild.egg-info/requires.txt +7 -0
  14. builderguild-0.1.0/builderguild/builderguild.egg-info/top_level.txt +1 -0
  15. builderguild-0.1.0/pyproject.toml +38 -0
  16. builderguild-0.1.0/setup.cfg +4 -0
  17. builderguild-0.1.0/tests/test_cli.py +33 -0
  18. builderguild-0.1.0/tests/test_cli_add.py +8 -0
  19. builderguild-0.1.0/tests/test_cli_done.py +14 -0
  20. builderguild-0.1.0/tests/test_cli_status_filter.py +26 -0
  21. builderguild-0.1.0/tests/test_commander.py +80 -0
  22. builderguild-0.1.0/tests/test_commander_main.py +31 -0
  23. builderguild-0.1.0/tests/test_config.py +39 -0
  24. builderguild-0.1.0/tests/test_config_validation.py +27 -0
  25. builderguild-0.1.0/tests/test_graph.py +15 -0
  26. builderguild-0.1.0/tests/test_graph_errors.py +27 -0
  27. builderguild-0.1.0/tests/test_graph_facts.py +38 -0
  28. builderguild-0.1.0/tests/test_graph_update.py +33 -0
  29. builderguild-0.1.0/tests/test_smoke.py +5 -0
@@ -0,0 +1,22 @@
1
+ ```text
2
+ MIT License
3
+
4
+ Copyright (c) 2026 Nuzuli
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: builderguild
3
+ Version: 0.1.0
4
+ Summary: Autonomous software engineering legion
5
+ Requires-Python: >=3.10
6
+ License-File: LICENSE
7
+ Provides-Extra: dev
8
+ Requires-Dist: pytest; extra == "dev"
9
+ Requires-Dist: pytest-cov; extra == "dev"
10
+ Requires-Dist: ruff; extra == "dev"
11
+ Requires-Dist: pip-audit; extra == "dev"
12
+ Requires-Dist: mypy; extra == "dev"
13
+ Dynamic: license-file
@@ -0,0 +1,116 @@
1
+ # builderguild — The Autonomous Software Legion
2
+
3
+ > Legion AI untuk software engineering: commander, scout, soldier, dan signalman yang bekerja bersama menyimpan memori di fact-intent graph.
4
+
5
+ Status: tahap awal (prototipe). API bisa berubah.
6
+
7
+ ![Demo](demo.gif)
8
+
9
+ ## Kebutuhan
10
+
11
+ - Python 3.10 atau lebih baru
12
+ - git
13
+ - tmux (hanya untuk `commander.py`)
14
+
15
+ ## Instalasi
16
+
17
+ Cara termudah, dari PyPI:
18
+
19
+ ```bash
20
+ pip install builderguild
21
+ ```
22
+
23
+ Paket ini murni memakai pustaka standar Python — tidak ada dependensi tambahan yang perlu dipasang.
24
+
25
+ Untuk menjalankan `commander.py` (dispatch tmux) atau ikut mengembangkan, pasang dari sumber:
26
+
27
+ ```bash
28
+ git clone https://github.com/Nuzuli/builderguild.git
29
+ cd builderguild
30
+ pip install -r requirements-lock.txt
31
+ pip install -e .
32
+ ```
33
+
34
+ `requirements-lock.txt` berisi versi pasti semua dependensi pengembangan supaya instalasi bisa diulang dengan hasil yang sama.
35
+
36
+ ## Cara Menjalankan
37
+
38
+ ```bash
39
+ # Inisialisasi graph
40
+ builderguild setup
41
+
42
+ # Tampilkan daftar fakta/task
43
+ builderguild status
44
+
45
+ # Jalankan commander (membagi task ke sesi tmux "bg-soldier")
46
+ python commander.py
47
+ ```
48
+
49
+ ## Konfigurasi
50
+
51
+ Semua konfigurasi dibaca dari environment variable. Salin `.env.example` sebagai acuan.
52
+
53
+ | Variabel | Default | Keterangan |
54
+ | --- | --- | --- |
55
+ | `BG_COMMANDER_MODEL` | `claude-sonnet-4-5` | Model untuk commander |
56
+ | `BG_SOLDIER_MODEL` | `claude-haiku-4-5` | Model untuk soldier |
57
+ | `BG_MAX_TOKENS` | `200000` | Batas token (harus angka bulat) |
58
+ | `BG_MAX_AGENTS` | `6` | Jumlah agent maksimum (harus angka bulat) |
59
+ | `BG_DB_PATH` | `runs/graph.db` | Lokasi database SQLite |
60
+ | `BG_REPO_PATH` | `.` | Lokasi repo yang dikerjakan |
61
+
62
+ Nilai angka yang tidak valid menghasilkan `ConfigError` dengan nama variabelnya.
63
+
64
+ ## Arsitektur
65
+
66
+ - `builderguild/builderguild/config.py`: membaca konfigurasi dari environment dan memvalidasinya (`Config`, `ConfigError`).
67
+ - `builderguild/builderguild/graph.py`: `FactGraph`, penyimpanan fakta dan status task di SQLite.
68
+ - `builderguild/builderguild/cli.py`: perintah `builderguild setup`, `status`, `add`, dan `done`.
69
+ - `commander.py`: membuat sesi tmux dan mengirim task dari graph ke soldier, lalu menandai statusnya `in_progress`.
70
+
71
+ Alur: `commander.py` membaca task dari `FactGraph`, mengirimnya ke sesi tmux, lalu memperbarui statusnya di graph.
72
+
73
+ ## Struktur Proyek
74
+
75
+ ```
76
+ .
77
+ ├── builderguild/builderguild/ # paket utama (config, graph, cli)
78
+ ├── tests/ # tes otomatis (pytest)
79
+ ├── commander.py # titik masuk commander
80
+ ├── pyproject.toml # konfigurasi paket, ruff, pytest
81
+ ├── requirements.txt # dependensi langsung
82
+ ├── requirements-lock.txt # dependensi terkunci
83
+ └── .github/workflows/ # CI dan pembuat lockfile
84
+ ```
85
+
86
+ ## Perintah CLI
87
+
88
+ Setelah `pip install builderguild` (atau `pip install -e .` dari sumber), perintah `builderguild` tersedia:
89
+
90
+ | Perintah | Fungsi |
91
+ | --- | --- |
92
+ | `builderguild setup` | Membuat graph dan task awal |
93
+ | `builderguild status` | Menampilkan semua task |
94
+ | `builderguild status --filter done` | Menampilkan task dengan status tertentu |
95
+ | `builderguild add "Judul" --detail "Keterangan"` | Menambah task baru |
96
+ | `builderguild done <id>` | Menandai task selesai |
97
+
98
+ Lokasi database diatur lewat `BG_DB_PATH` (lihat `.env.example`).
99
+
100
+
101
+ ## Menjalankan Tes
102
+
103
+ ```bash
104
+ pip install pytest pytest-cov
105
+ pytest --cov=builderguild --cov-fail-under=70
106
+ ```
107
+
108
+ CI (GitHub Actions) menjalankan lint (`ruff`), tes dengan batas coverage 70%, dan `pip-audit` di Python 3.10 dan 3.12 pada setiap push dan pull request.
109
+
110
+ ## Memperbarui Lockfile
111
+
112
+ Jalankan workflow **Generate lockfile** dari tab Actions (Run workflow). Hasilnya di-commit otomatis ke `requirements-lock.txt`.
113
+
114
+ ## Lisensi
115
+
116
+ Lihat file [LICENSE](LICENSE).
@@ -0,0 +1 @@
1
+ # paket builderguild
@@ -0,0 +1,76 @@
1
+ import argparse
2
+ import sys
3
+
4
+ from .config import Config
5
+ from .graph import FactGraph
6
+
7
+
8
+ def cmd_setup(args) -> int:
9
+ cfg = Config.load()
10
+ fg = FactGraph(cfg.db_path)
11
+ fg.add("Setup awal", "Graph berhasil dibuat", {"path": cfg.db_path})
12
+ fg.close()
13
+ print(f"[setup] graph siap: {cfg.db_path}")
14
+ return 0
15
+
16
+
17
+ def cmd_status(args) -> int:
18
+ cfg = Config.load()
19
+ fg = FactGraph(cfg.db_path)
20
+ for f in fg.list_titles():
21
+ if args.filter and f["status"] != args.filter:
22
+ continue
23
+ print(f"#{f['id']:>3} [{f['status']}] {f['title']}")
24
+ fg.close()
25
+ return 0
26
+
27
+
28
+ def cmd_add(args) -> int:
29
+ cfg = Config.load()
30
+ fg = FactGraph(cfg.db_path)
31
+ fg.add(args.title, args.detail, {})
32
+ fg.close()
33
+ print(f"[add] task ditambahkan: {args.title}")
34
+ return 0
35
+
36
+
37
+ def cmd_done(args) -> int:
38
+ cfg = Config.load()
39
+ fg = FactGraph(cfg.db_path)
40
+ ids = {f["id"] for f in fg.list_titles()}
41
+ if args.id not in ids:
42
+ fg.close()
43
+ print(f"[done] task #{args.id} tidak ditemukan", file=sys.stderr)
44
+ return 1
45
+ fg.update_status(args.id, "done")
46
+ fg.close()
47
+ print(f"[done] task #{args.id} selesai")
48
+ return 0
49
+
50
+
51
+ def main(argv: list[str] | None = None) -> int:
52
+ p = argparse.ArgumentParser(prog="builderguild")
53
+ sub = p.add_subparsers(dest="cmd", required=True)
54
+
55
+ s = sub.add_parser("setup", help="inisialisasi graph")
56
+ s.set_defaults(func=cmd_setup)
57
+
58
+ s = sub.add_parser("status", help="tampilkan board")
59
+ s.add_argument("--filter", default=None, help="hanya tampilkan status ini")
60
+ s.set_defaults(func=cmd_status)
61
+
62
+ s = sub.add_parser("add", help="tambah task baru")
63
+ s.add_argument("title")
64
+ s.add_argument("--detail", default="")
65
+ s.set_defaults(func=cmd_add)
66
+
67
+ s = sub.add_parser("done", help="tandai task selesai")
68
+ s.add_argument("id", type=int)
69
+ s.set_defaults(func=cmd_done)
70
+
71
+ args = p.parse_args(argv)
72
+ return args.func(args)
73
+
74
+
75
+ if __name__ == "__main__":
76
+ sys.exit(main())
@@ -0,0 +1,43 @@
1
+ import os
2
+ from dataclasses import dataclass, field
3
+
4
+
5
+ class ConfigError(ValueError):
6
+ """Dilempar saat nilai konfigurasi dari environment tidak valid."""
7
+
8
+
9
+ def _env(key: str, default: str = "") -> str:
10
+ return os.environ.get(key, default)
11
+
12
+
13
+ def _env_int(key: str, default: str, minimum: int | None = None) -> int:
14
+ raw = _env(key, default)
15
+ try:
16
+ value = int(raw)
17
+ except ValueError:
18
+ raise ConfigError(f"{key} harus berupa angka bulat, dapat: {raw!r}") from None
19
+ if minimum is not None and value < minimum:
20
+ raise ConfigError(f"{key} minimal {minimum}, dapat: {value}")
21
+ return value
22
+
23
+
24
+ @dataclass
25
+ class Config:
26
+ commander_model: str = field(
27
+ default_factory=lambda: _env("BG_COMMANDER_MODEL", "claude-sonnet-4-5")
28
+ )
29
+ soldier_model: str = field(
30
+ default_factory=lambda: _env("BG_SOLDIER_MODEL", "claude-haiku-4-5")
31
+ )
32
+ max_tokens: int = field(
33
+ default_factory=lambda: _env_int("BG_MAX_TOKENS", "200000", minimum=1)
34
+ )
35
+ max_agents: int = field(
36
+ default_factory=lambda: _env_int("BG_MAX_AGENTS", "6", minimum=1)
37
+ )
38
+ db_path: str = field(default_factory=lambda: _env("BG_DB_PATH", "runs/graph.db"))
39
+ repo_path: str = field(default_factory=lambda: _env("BG_REPO_PATH", "."))
40
+
41
+ @classmethod
42
+ def load(cls) -> "Config":
43
+ return cls()
@@ -0,0 +1,10 @@
1
+ class TmuxError(Exception):
2
+ """Perintah tmux gagal dijalankan."""
3
+
4
+
5
+ class TmuxNotAvailableError(TmuxError):
6
+ """tmux belum terinstall."""
7
+
8
+
9
+ class GraphError(Exception):
10
+ """Operasi pada fact graph gagal."""
@@ -0,0 +1,60 @@
1
+ from __future__ import annotations
2
+ import sqlite3
3
+ import os
4
+ import time
5
+ import json
6
+
7
+ from .errors import GraphError
8
+
9
+ SCHEMA = """
10
+ CREATE TABLE IF NOT EXISTS facts (
11
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
12
+ title TEXT NOT NULL,
13
+ summary TEXT NOT NULL,
14
+ evidence TEXT NOT NULL,
15
+ kind TEXT DEFAULT 'fact',
16
+ status TEXT DEFAULT 'open',
17
+ owner TEXT DEFAULT '',
18
+ created REAL NOT NULL,
19
+ updated REAL NOT NULL
20
+ );
21
+ """
22
+
23
+
24
+ class FactGraph:
25
+ def __init__(self, db_path: str):
26
+ os.makedirs(os.path.dirname(db_path) or ".", exist_ok=True)
27
+ self.conn = sqlite3.connect(db_path)
28
+ self.conn.row_factory = sqlite3.Row
29
+ self.conn.executescript(SCHEMA)
30
+ self.conn.commit()
31
+
32
+ def list_titles(self, status: str | None = None) -> list[dict]:
33
+ q = "SELECT id, title, status, owner FROM facts"
34
+ args: tuple = ()
35
+ if status:
36
+ q += " WHERE status = ?"
37
+ args = (status,)
38
+ q += " ORDER BY id"
39
+ return [dict(r) for r in self.conn.execute(q, args)]
40
+
41
+ def add(self, title: str, summary: str, evidence: dict, kind: str = "fact", owner: str = "") -> int:
42
+ now = time.time()
43
+ cur = self.conn.execute(
44
+ "INSERT INTO facts(title,summary,evidence,kind,status,owner,created,updated) VALUES (?,?,?,?,?,?,?,?)",
45
+ (title, summary, json.dumps(evidence), kind, "open", owner, now, now),
46
+ )
47
+ self.conn.commit()
48
+ if cur.lastrowid is None:
49
+ raise GraphError("INSERT gagal: tidak ada id baris baru")
50
+ return cur.lastrowid
51
+
52
+ def update_status(self, fact_id: int, status: str) -> None:
53
+ self.conn.execute(
54
+ "UPDATE facts SET status = ?, updated = ? WHERE id = ?",
55
+ (status, time.time(), fact_id),
56
+ )
57
+ self.conn.commit()
58
+
59
+ def close(self) -> None:
60
+ self.conn.close()
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.4
2
+ Name: builderguild
3
+ Version: 0.1.0
4
+ Summary: Autonomous software engineering legion
5
+ Requires-Python: >=3.10
6
+ License-File: LICENSE
7
+ Provides-Extra: dev
8
+ Requires-Dist: pytest; extra == "dev"
9
+ Requires-Dist: pytest-cov; extra == "dev"
10
+ Requires-Dist: ruff; extra == "dev"
11
+ Requires-Dist: pip-audit; extra == "dev"
12
+ Requires-Dist: mypy; extra == "dev"
13
+ Dynamic: license-file
@@ -0,0 +1,27 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ builderguild/builderguild/__init__.py
5
+ builderguild/builderguild/cli.py
6
+ builderguild/builderguild/config.py
7
+ builderguild/builderguild/errors.py
8
+ builderguild/builderguild/graph.py
9
+ builderguild/builderguild.egg-info/PKG-INFO
10
+ builderguild/builderguild.egg-info/SOURCES.txt
11
+ builderguild/builderguild.egg-info/dependency_links.txt
12
+ builderguild/builderguild.egg-info/entry_points.txt
13
+ builderguild/builderguild.egg-info/requires.txt
14
+ builderguild/builderguild.egg-info/top_level.txt
15
+ tests/test_cli.py
16
+ tests/test_cli_add.py
17
+ tests/test_cli_done.py
18
+ tests/test_cli_status_filter.py
19
+ tests/test_commander.py
20
+ tests/test_commander_main.py
21
+ tests/test_config.py
22
+ tests/test_config_validation.py
23
+ tests/test_graph.py
24
+ tests/test_graph_errors.py
25
+ tests/test_graph_facts.py
26
+ tests/test_graph_update.py
27
+ tests/test_smoke.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ builderguild = builderguild.cli:main
@@ -0,0 +1,7 @@
1
+
2
+ [dev]
3
+ pytest
4
+ pytest-cov
5
+ ruff
6
+ pip-audit
7
+ mypy
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "builderguild"
7
+ version = "0.1.0"
8
+ description = "Autonomous software engineering legion"
9
+ requires-python = ">=3.10"
10
+
11
+ [project.optional-dependencies]
12
+ dev = ["pytest", "pytest-cov", "ruff", "pip-audit", "mypy"]
13
+
14
+ [project.scripts]
15
+ builderguild = "builderguild.cli:main"
16
+
17
+ [tool.setuptools.packages.find]
18
+ where = ["builderguild"]
19
+ include = ["builderguild*"]
20
+
21
+ [tool.ruff]
22
+ line-length = 100
23
+ target-version = "py310"
24
+
25
+ [tool.ruff.lint]
26
+ select = ["E", "F"]
27
+ ignore = ["E501"]
28
+
29
+ [tool.pytest.ini_options]
30
+ testpaths = ["tests"]
31
+ pythonpath = [".", "builderguild"]
32
+
33
+ [tool.mypy]
34
+ python_version = "3.10"
35
+ mypy_path = "builderguild"
36
+ explicit_package_bases = true
37
+ warn_unused_ignores = true
38
+ warn_redundant_casts = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ import pytest
2
+
3
+ from builderguild.cli import main
4
+
5
+
6
+ def test_setup_creates_graph(tmp_path, monkeypatch, capsys):
7
+ db = tmp_path / "graph.db"
8
+ monkeypatch.setenv("BG_DB_PATH", str(db))
9
+ assert main(["setup"]) == 0
10
+ assert db.exists()
11
+ assert "[setup] graph siap" in capsys.readouterr().out
12
+
13
+
14
+ def test_status_lists_facts_after_setup(tmp_path, monkeypatch, capsys):
15
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "graph.db"))
16
+ main(["setup"])
17
+ capsys.readouterr()
18
+ assert main(["status"]) == 0
19
+ out = capsys.readouterr().out
20
+ assert "Setup awal" in out
21
+ assert "[open]" in out
22
+
23
+
24
+ def test_status_on_empty_graph_prints_nothing(tmp_path, monkeypatch, capsys):
25
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "graph.db"))
26
+ assert main(["status"]) == 0
27
+ assert capsys.readouterr().out == ""
28
+
29
+
30
+ def test_missing_command_exits_with_code_2():
31
+ with pytest.raises(SystemExit) as exc:
32
+ main([])
33
+ assert exc.value.code == 2
@@ -0,0 +1,8 @@
1
+ from builderguild import cli
2
+
3
+
4
+ def test_add_creates_task(monkeypatch, tmp_path, capsys):
5
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
6
+ assert cli.main(["add", "Perbaiki bug", "--detail", "login gagal"]) == 0
7
+ cli.main(["status"])
8
+ assert "Perbaiki bug" in capsys.readouterr().out
@@ -0,0 +1,14 @@
1
+ from builderguild import cli
2
+
3
+
4
+ def test_done_marks_task(monkeypatch, tmp_path, capsys):
5
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
6
+ cli.main(["add", "Perbaiki bug"])
7
+ assert cli.main(["done", "1"]) == 0
8
+ cli.main(["status"])
9
+ assert "[done]" in capsys.readouterr().out
10
+
11
+
12
+ def test_done_unknown_id(monkeypatch, tmp_path):
13
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
14
+ assert cli.main(["done", "999"]) == 1
@@ -0,0 +1,26 @@
1
+ from builderguild import cli
2
+
3
+
4
+ def test_status_filter_only_done(monkeypatch, tmp_path, capsys):
5
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
6
+ cli.main(["add", "Tugas Alpha"])
7
+ cli.main(["add", "Tugas Beta"])
8
+ cli.main(["done", "1"])
9
+ capsys.readouterr()
10
+
11
+ cli.main(["status", "--filter", "done"])
12
+ out = capsys.readouterr().out
13
+ assert "Tugas Alpha" in out
14
+ assert "Tugas Beta" not in out
15
+
16
+
17
+ def test_status_without_filter_shows_all(monkeypatch, tmp_path, capsys):
18
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
19
+ cli.main(["add", "Tugas Alpha"])
20
+ cli.main(["add", "Tugas Beta"])
21
+ capsys.readouterr()
22
+
23
+ cli.main(["status"])
24
+ out = capsys.readouterr().out
25
+ assert "Tugas Alpha" in out
26
+ assert "Tugas Beta" in out
@@ -0,0 +1,80 @@
1
+ import subprocess
2
+
3
+ import pytest
4
+
5
+ import commander
6
+ from builderguild.errors import TmuxError, TmuxNotAvailableError
7
+
8
+
9
+ class _Result:
10
+ def __init__(self, returncode):
11
+ self.returncode = returncode
12
+
13
+
14
+ def _raise_called_process_error(cmd, **kwargs):
15
+ raise subprocess.CalledProcessError(1, cmd, stderr=b"boom")
16
+
17
+
18
+ def test_session_exists_true(monkeypatch):
19
+ monkeypatch.setattr(commander.subprocess, "run", lambda *a, **k: _Result(0))
20
+ assert commander.session_exists("bg-test") is True
21
+
22
+
23
+ def test_session_exists_false(monkeypatch):
24
+ monkeypatch.setattr(commander.subprocess, "run", lambda *a, **k: _Result(1))
25
+ assert commander.session_exists("bg-test") is False
26
+
27
+
28
+ def test_spawn_tmux_without_tmux(monkeypatch):
29
+ monkeypatch.setattr(commander.shutil, "which", lambda name: None)
30
+ with pytest.raises(TmuxNotAvailableError, match="tmux belum diinstall"):
31
+ commander.spawn_tmux("bg-test")
32
+
33
+
34
+ def test_spawn_tmux_creates_session(monkeypatch):
35
+ calls = []
36
+ monkeypatch.setattr(commander.shutil, "which", lambda name: "/usr/bin/tmux")
37
+ monkeypatch.setattr(commander, "session_exists", lambda name: False)
38
+ monkeypatch.setattr(commander.subprocess, "run", lambda cmd, **k: calls.append(cmd))
39
+ assert commander.spawn_tmux("bg-test", "bash") is True
40
+ assert calls == [["tmux", "new-session", "-d", "-s", "bg-test", "bash"]]
41
+
42
+
43
+ def test_spawn_tmux_skips_existing_session(monkeypatch):
44
+ calls = []
45
+ monkeypatch.setattr(commander.shutil, "which", lambda name: "/usr/bin/tmux")
46
+ monkeypatch.setattr(commander, "session_exists", lambda name: True)
47
+ monkeypatch.setattr(commander.subprocess, "run", lambda cmd, **k: calls.append(cmd))
48
+ assert commander.spawn_tmux("bg-test") is True
49
+ assert calls == []
50
+
51
+
52
+ def test_spawn_tmux_raises_when_command_fails(monkeypatch):
53
+ monkeypatch.setattr(commander.shutil, "which", lambda name: "/usr/bin/tmux")
54
+ monkeypatch.setattr(commander, "session_exists", lambda name: False)
55
+ monkeypatch.setattr(commander.subprocess, "run", _raise_called_process_error)
56
+ with pytest.raises(TmuxError, match="boom"):
57
+ commander.spawn_tmux("bg-test")
58
+
59
+
60
+ def test_tell_tmux_sends_keys(monkeypatch):
61
+ calls = []
62
+ monkeypatch.setattr(commander, "session_exists", lambda name: True)
63
+ monkeypatch.setattr(commander.subprocess, "run", lambda cmd, **k: calls.append(cmd))
64
+ commander.tell_tmux("bg-test", "halo")
65
+ assert calls == [["tmux", "send-keys", "-t", "bg-test", "halo", "Enter"]]
66
+
67
+
68
+ def test_tell_tmux_skips_missing_session(monkeypatch):
69
+ calls = []
70
+ monkeypatch.setattr(commander, "session_exists", lambda name: False)
71
+ monkeypatch.setattr(commander.subprocess, "run", lambda cmd, **k: calls.append(cmd))
72
+ commander.tell_tmux("bg-test", "halo")
73
+ assert calls == []
74
+
75
+
76
+ def test_tell_tmux_raises_when_command_fails(monkeypatch):
77
+ monkeypatch.setattr(commander, "session_exists", lambda name: True)
78
+ monkeypatch.setattr(commander.subprocess, "run", _raise_called_process_error)
79
+ with pytest.raises(TmuxError, match="send-keys gagal"):
80
+ commander.tell_tmux("bg-test", "halo")
@@ -0,0 +1,31 @@
1
+ import commander
2
+ from builderguild.errors import TmuxNotAvailableError
3
+
4
+
5
+ def test_main_dispatches_tasks(monkeypatch, tmp_path):
6
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
7
+ spawned, told = [], []
8
+ monkeypatch.setattr(
9
+ commander, "spawn_tmux", lambda name, cmd="bash": spawned.append(name) or True
10
+ )
11
+ monkeypatch.setattr(
12
+ commander, "tell_tmux", lambda name, text: told.append((name, text))
13
+ )
14
+ commander.main()
15
+ assert spawned == ["bg-soldier"]
16
+ assert len(told) == 2
17
+
18
+
19
+ def test_main_stops_when_tmux_missing(monkeypatch, tmp_path):
20
+ monkeypatch.setenv("BG_DB_PATH", str(tmp_path / "bg.db"))
21
+ told = []
22
+
23
+ def fake_spawn(name, cmd="bash"):
24
+ raise TmuxNotAvailableError("tmux belum diinstall!")
25
+
26
+ monkeypatch.setattr(commander, "spawn_tmux", fake_spawn)
27
+ monkeypatch.setattr(
28
+ commander, "tell_tmux", lambda name, text: told.append((name, text))
29
+ )
30
+ commander.main()
31
+ assert told == []
@@ -0,0 +1,39 @@
1
+ import pytest
2
+
3
+ from builderguild.config import Config, ConfigError
4
+
5
+
6
+ def test_config_defaults(monkeypatch):
7
+ for key in ["BG_MAX_AGENTS", "BG_DB_PATH"]:
8
+ monkeypatch.delenv(key, raising=False)
9
+ cfg = Config.load()
10
+ assert cfg.max_agents == 6
11
+ assert cfg.db_path == "runs/graph.db"
12
+
13
+
14
+ def test_config_reads_env(monkeypatch):
15
+ monkeypatch.setenv("BG_MAX_AGENTS", "3")
16
+ assert Config.load().max_agents == 3
17
+
18
+
19
+ def test_config_rejects_non_numeric_agents(monkeypatch):
20
+ monkeypatch.setenv("BG_MAX_AGENTS", "abc")
21
+ with pytest.raises(ConfigError, match="BG_MAX_AGENTS"):
22
+ Config.load()
23
+
24
+
25
+ def test_config_rejects_non_numeric_tokens(monkeypatch):
26
+ monkeypatch.setenv("BG_MAX_TOKENS", "banyak")
27
+ with pytest.raises(ConfigError, match="BG_MAX_TOKENS"):
28
+ Config.load()
29
+
30
+ def test_config_rejects_zero_agents(monkeypatch):
31
+ monkeypatch.setenv("BG_MAX_AGENTS", "0")
32
+ with pytest.raises(ConfigError, match="minimal 1"):
33
+ Config.load()
34
+
35
+
36
+ def test_config_rejects_negative_tokens(monkeypatch):
37
+ monkeypatch.setenv("BG_MAX_TOKENS", "-5")
38
+ with pytest.raises(ConfigError, match="minimal 1"):
39
+ Config.load()
@@ -0,0 +1,27 @@
1
+ import pytest
2
+
3
+ from builderguild.config import Config, ConfigError
4
+
5
+
6
+ def test_non_numeric_max_agents_raises_config_error(monkeypatch):
7
+ monkeypatch.setenv("BG_MAX_AGENTS", "abc")
8
+ with pytest.raises(ConfigError, match="BG_MAX_AGENTS"):
9
+ Config.load()
10
+
11
+
12
+ def test_non_numeric_max_tokens_raises_config_error(monkeypatch):
13
+ monkeypatch.setenv("BG_MAX_TOKENS", "banyak")
14
+ with pytest.raises(ConfigError, match="BG_MAX_TOKENS"):
15
+ Config.load()
16
+
17
+
18
+ def test_config_error_is_value_error():
19
+ assert issubclass(ConfigError, ValueError)
20
+
21
+
22
+ def test_numeric_values_are_parsed(monkeypatch):
23
+ monkeypatch.setenv("BG_MAX_AGENTS", "3")
24
+ monkeypatch.setenv("BG_MAX_TOKENS", "1000")
25
+ cfg = Config.load()
26
+ assert cfg.max_agents == 3
27
+ assert cfg.max_tokens == 1000
@@ -0,0 +1,15 @@
1
+ import sqlite3
2
+
3
+ from builderguild.graph import FactGraph
4
+
5
+
6
+ def test_fact_graph_creates_facts_table(tmp_path):
7
+ db = tmp_path / "graph.db"
8
+ FactGraph(str(db))
9
+
10
+ conn = sqlite3.connect(db)
11
+ columns = {row[1] for row in conn.execute("PRAGMA table_info(facts)")}
12
+ conn.close()
13
+
14
+ expected = {"id", "title", "summary", "evidence", "kind", "status", "owner", "created", "updated"}
15
+ assert expected <= columns
@@ -0,0 +1,27 @@
1
+ import pytest
2
+
3
+ from builderguild.errors import GraphError
4
+ from builderguild.graph import FactGraph
5
+
6
+
7
+ class _FakeCursor:
8
+ lastrowid = None
9
+
10
+
11
+ class _FakeConn:
12
+ def execute(self, *args, **kwargs):
13
+ return _FakeCursor()
14
+
15
+ def commit(self):
16
+ pass
17
+
18
+ def close(self):
19
+ pass
20
+
21
+
22
+ def test_add_raises_graph_error_when_no_row_id(tmp_path):
23
+ fg = FactGraph(str(tmp_path / "bg.db"))
24
+ fg.conn.close()
25
+ fg.conn = _FakeConn()
26
+ with pytest.raises(GraphError, match="INSERT gagal"):
27
+ fg.add("judul", "ringkasan", {})
@@ -0,0 +1,38 @@
1
+ from builderguild.graph import FactGraph
2
+
3
+
4
+ def make_graph(tmp_path):
5
+ return FactGraph(str(tmp_path / "graph.db"))
6
+
7
+
8
+ def test_add_returns_incrementing_ids(tmp_path):
9
+ fg = make_graph(tmp_path)
10
+ first = fg.add("Judul 1", "Ringkasan", {"a": 1})
11
+ second = fg.add("Judul 2", "Ringkasan", {"b": 2})
12
+ assert second == first + 1
13
+ fg.close()
14
+
15
+
16
+ def test_list_titles_returns_all(tmp_path):
17
+ fg = make_graph(tmp_path)
18
+ fg.add("Satu", "s", {}, owner="scout")
19
+ fg.add("Dua", "s", {})
20
+ rows = fg.list_titles()
21
+ assert [r["title"] for r in rows] == ["Satu", "Dua"]
22
+ assert rows[0]["owner"] == "scout"
23
+ assert rows[0]["status"] == "open"
24
+ fg.close()
25
+
26
+
27
+ def test_list_titles_filters_by_status(tmp_path):
28
+ fg = make_graph(tmp_path)
29
+ fg.add("Satu", "s", {})
30
+ assert len(fg.list_titles(status="open")) == 1
31
+ assert fg.list_titles(status="done") == []
32
+ fg.close()
33
+
34
+
35
+ def test_list_titles_empty(tmp_path):
36
+ fg = make_graph(tmp_path)
37
+ assert fg.list_titles() == []
38
+ fg.close()
@@ -0,0 +1,33 @@
1
+ from builderguild.graph import FactGraph
2
+
3
+
4
+ def make_graph(tmp_path):
5
+ return FactGraph(str(tmp_path / "graph.db"))
6
+
7
+
8
+ def test_update_status_changes_status(tmp_path):
9
+ fg = make_graph(tmp_path)
10
+ fact_id = fg.add("Tugas", "ringkasan", {})
11
+ fg.update_status(fact_id, "in_progress")
12
+ rows = fg.list_titles(status="in_progress")
13
+ assert [r["id"] for r in rows] == [fact_id]
14
+ assert fg.list_titles(status="open") == []
15
+ fg.close()
16
+
17
+
18
+ def test_update_status_only_affects_target(tmp_path):
19
+ fg = make_graph(tmp_path)
20
+ first = fg.add("Satu", "s", {})
21
+ second = fg.add("Dua", "s", {})
22
+ fg.update_status(first, "done")
23
+ statuses = {r["id"]: r["status"] for r in fg.list_titles()}
24
+ assert statuses == {first: "done", second: "open"}
25
+ fg.close()
26
+
27
+
28
+ def test_update_status_unknown_id_is_noop(tmp_path):
29
+ fg = make_graph(tmp_path)
30
+ fg.add("Satu", "s", {})
31
+ fg.update_status(999, "done")
32
+ assert [r["status"] for r in fg.list_titles()] == ["open"]
33
+ fg.close()
@@ -0,0 +1,5 @@
1
+ import builderguild # noqa: F401
2
+
3
+
4
+ def test_import():
5
+ assert builderguild is not None