feat: project directory management — create, log, read, list
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import json
|
||||
from kitty_workbench.project import (
|
||||
create_project, project_exists, project_path,
|
||||
append_log, read_log, list_projects, log_session_event,
|
||||
)
|
||||
|
||||
|
||||
def test_create_project(tmp_workbench):
|
||||
path = create_project("io102", "Heathkit IO-102", workbench_dir=tmp_workbench)
|
||||
assert path.exists()
|
||||
assert (path / "session.md").exists()
|
||||
assert (path / "session.jsonl").exists()
|
||||
assert (path / "cost-log.jsonl").exists()
|
||||
assert (path / "assets").is_dir()
|
||||
md = (path / "session.md").read_text()
|
||||
assert "Heathkit IO-102" in md
|
||||
|
||||
|
||||
def test_create_project_idempotent(tmp_workbench):
|
||||
create_project("io102", "First", workbench_dir=tmp_workbench)
|
||||
append_log("io102", "test entry", workbench_dir=tmp_workbench)
|
||||
create_project("io102", "Second", workbench_dir=tmp_workbench)
|
||||
entries = read_log("io102", workbench_dir=tmp_workbench)
|
||||
assert len(entries) == 1
|
||||
|
||||
|
||||
def test_project_exists(tmp_workbench):
|
||||
assert not project_exists("io102", workbench_dir=tmp_workbench)
|
||||
create_project("io102", "Test", workbench_dir=tmp_workbench)
|
||||
assert project_exists("io102", workbench_dir=tmp_workbench)
|
||||
|
||||
|
||||
def test_append_and_read_log(tmp_workbench):
|
||||
create_project("io102", "Test", workbench_dir=tmp_workbench)
|
||||
append_log("io102", "R412 measured 1.05M", data={"ohms": 1050000}, workbench_dir=tmp_workbench)
|
||||
append_log("io102", "R413 OK", workbench_dir=tmp_workbench)
|
||||
entries = read_log("io102", tail=10, workbench_dir=tmp_workbench)
|
||||
assert len(entries) == 2
|
||||
assert entries[0]["entry"] == "R412 measured 1.05M"
|
||||
assert entries[0]["ohms"] == 1050000
|
||||
assert entries[1]["entry"] == "R413 OK"
|
||||
|
||||
|
||||
def test_read_log_tail(tmp_workbench):
|
||||
create_project("io102", "Test", workbench_dir=tmp_workbench)
|
||||
for i in range(30):
|
||||
append_log("io102", f"Entry {i}", workbench_dir=tmp_workbench)
|
||||
entries = read_log("io102", tail=5, workbench_dir=tmp_workbench)
|
||||
assert len(entries) == 5
|
||||
assert entries[0]["entry"] == "Entry 25"
|
||||
|
||||
|
||||
def test_list_projects(tmp_workbench):
|
||||
assert list_projects(workbench_dir=tmp_workbench) == []
|
||||
create_project("io102", "First", workbench_dir=tmp_workbench)
|
||||
create_project("psu-rebuild", "Second", workbench_dir=tmp_workbench)
|
||||
projects = list_projects(workbench_dir=tmp_workbench)
|
||||
assert [p["name"] for p in projects] == ["io102", "psu-rebuild"]
|
||||
|
||||
|
||||
def test_log_session_event(tmp_workbench):
|
||||
create_project("io102", "Test", workbench_dir=tmp_workbench)
|
||||
log_session_event("io102", "session_start", workbench_dir=tmp_workbench)
|
||||
cost_log = (tmp_workbench / "io102" / "cost-log.jsonl").read_text().strip()
|
||||
entry = json.loads(cost_log.split("\n")[-1])
|
||||
assert entry["event"] == "session_start"
|
||||
assert entry["project"] == "io102"
|
||||
Reference in New Issue
Block a user