feat(consistency): bootstrap empty repo projections
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a023c0-a0a3-7c03-b395-5a0d2757214d
This commit is contained in:
tegwick 2026-08-22 12:07:08 +02:00
parent 52a7d6bb73
commit 03c7924b7f
3 changed files with 187 additions and 7 deletions

View file

@ -1272,6 +1272,112 @@ class TestC20DependencyDetection:
class TestC06WorkstreamCreation:
def test_fix_repo_bootstraps_legacy_ids_only_into_empty_projection(
self, tmp_path, monkeypatch
):
repo = tmp_path / "repo"
workplans = repo / "workplans"
workplans.mkdir(parents=True)
workplan_id = "11111111-1111-4111-8111-111111111111"
task_id = "22222222-2222-4222-8222-222222222222"
wp = workplans / "DEMO-WP-0001.md"
wp.write_text(
"---\n"
"id: DEMO-WP-0001\n"
"type: workplan\n"
"title: Demo Workplan\n"
"domain: financials\n"
"repo: demo-repo\n"
"status: ready\n"
f'state_hub_workstream_id: "{workplan_id}"\n'
"---\n\n"
"## Task\n\n"
"```task\n"
"id: DEMO-WP-0001-T01\n"
"status: todo\n"
"priority: high\n"
f'state_hub_task_id: "{task_id}"\n'
"```\n",
encoding="utf-8",
)
created = []
def fake_get(_api_base, path, params=None, **_kwargs):
if path == "/repos/demo-repo":
return {
"id": "repo-1",
"slug": "demo-repo",
"local_path": str(repo),
"host_paths": {},
"domain_slug": "financials",
}
if path == "/topics":
return [{"id": "topic-1", "domain_slug": "financials"}]
if path == "/workplans" and params == {"repo_id": "repo-1"}:
return []
if path == f"/workplans/{workplan_id}":
return None
if path == "/workplans" and params and "slug" in params:
return []
return []
def fake_post(_api_base, path, body):
created.append((path, body))
return body
monkeypatch.setattr("consistency_check._api_get", fake_get)
monkeypatch.setattr("consistency_check._api_post", fake_post)
monkeypatch.setattr("consistency_check._api_patch", lambda *args, **kwargs: {"ok": True})
monkeypatch.setattr("consistency_check._detect_behind_remote", lambda _repo_path: False)
monkeypatch.setattr("consistency_check._detect_ahead_of_remote", lambda _repo_path: 0)
monkeypatch.setattr("consistency_check._write_custodian_brief", lambda *args, **kwargs: False)
monkeypatch.setattr("consistency_check._git_push", lambda _repo_path: (True, "pushed"))
monkeypatch.setenv("STATEHUB_REGISTRAR", "1")
report = fix_repo(
"http://unused",
"demo-repo",
bootstrap_empty_projection=True,
)
assert [body["id"] for path, body in created if path == "/workplans"] == [workplan_id]
assert [body["id"] for path, body in created if path == "/tasks"] == [task_id]
assert any("explicitly empty projection" in issue.message for issue in report.issues)
def test_fix_repo_refuses_empty_bootstrap_when_projection_has_rows(
self, tmp_path, monkeypatch
):
repo = tmp_path / "repo"
(repo / "workplans").mkdir(parents=True)
def fake_get(_api_base, path, params=None, **_kwargs):
if path == "/repos/demo-repo":
return {
"id": "repo-1",
"slug": "demo-repo",
"local_path": str(repo),
"host_paths": {},
"domain_slug": "financials",
}
if path == "/workplans" and params == {"repo_id": "repo-1"}:
return [{"id": "existing"}]
return []
monkeypatch.setattr("consistency_check._api_get", fake_get)
monkeypatch.setattr(
"consistency_check._api_post",
lambda *_args, **_kwargs: pytest.fail("bootstrap must not mutate a non-empty projection"),
)
report = fix_repo(
"http://unused",
"demo-repo",
bootstrap_empty_projection=True,
)
assert len(report.failures) == 1
assert report.failures[0].check_id == "C-36"
def test_fix_repo_rebuilds_missing_projection_from_derived_file_ids(
self, tmp_path, monkeypatch
):