retire identifier registrar guard
All checks were successful
CI Smoke / host-smoke (push) Successful in 0s
CI Smoke / container-smoke (push) Successful in 1s
Build and Publish Multi-Context Image / build-and-push (push) Successful in 26s

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a053ff-1d6f-7fe2-ac1c-a6eb40a42a0c
This commit is contained in:
tegwick 2026-08-31 19:34:11 +02:00
parent 667ed28037
commit 5dd04dcb3d
3 changed files with 106 additions and 72 deletions

View file

@ -1587,12 +1587,12 @@ class TestC06WorkstreamCreation:
assert f'state_hub_task_id: "{expected_task_id}"' in patched
assert any("C-06 fixed" in fix for fix in report.fixes_applied)
def test_fix_repo_skips_c06_mint_when_not_registrar(self, tmp_path, monkeypatch):
repo = tmp_path / "repo"
workplans = repo / "workplans"
workplans.mkdir(parents=True)
wp = workplans / "STATE-WP-0001-demo.md"
wp.write_text(
def test_fix_repo_derives_identical_writeback_across_instances(
self, tmp_path, monkeypatch
):
import socket
source = (
"---\n"
"id: STATE-WP-0001\n"
"type: workplan\n"
@ -1607,30 +1607,75 @@ class TestC06WorkstreamCreation:
"id: STATE-WP-0001-T01\n"
"status: todo\n"
"priority: high\n"
"```\n",
encoding="utf-8",
"```\n"
)
repos = {}
for instance in ("hub-a", "hub-b"):
repo = tmp_path / instance
workplans = repo / "workplans"
workplans.mkdir(parents=True)
(workplans / "STATE-WP-0001-demo.md").write_text(source, encoding="utf-8")
repos[instance] = repo
created = []
stores = {
instance: {"workplans": {}, "tasks": {}}
for instance in repos
}
create_attempts = {
instance: {"workplans": 0, "tasks": 0}
for instance in repos
}
def fake_get(_api_base, path, params=None, **_kwargs):
def instance_name(api_base):
return api_base.rsplit("/", 1)[-1]
def fake_get(api_base, path, params=None, **_kwargs):
instance = instance_name(api_base)
store = stores[instance]
if path == "/repos/demo-repo":
import socket
return {
"id": "repo-1",
"id": f"repo-{instance}",
"slug": "demo-repo",
"local_path": str(repo),
"host_paths": {socket.gethostname(): str(repo)},
"local_path": str(repos[instance]),
"host_paths": {socket.gethostname(): str(repos[instance])},
"domain_slug": "financials",
}
if path == "/topics":
return [{"id": "topic-1", "domain_slug": "financials"}]
return [{"id": f"topic-{instance}", "domain_slug": "financials"}]
if path.startswith("/workplans/"):
return store["workplans"].get(path.rsplit("/", 1)[-1])
if path.startswith("/tasks/"):
return store["tasks"].get(path.rsplit("/", 1)[-1])
if path == "/workplans":
rows = list(store["workplans"].values())
if params:
rows = [
row for row in rows
if all(row.get(key) == value for key, value in params.items())
]
return rows
if path == "/tasks":
rows = list(store["tasks"].values())
if params:
rows = [
row for row in rows
if all(row.get(key) == value for key, value in params.items())
]
return rows
return []
def fake_post(_api_base, path, body):
created.append((path, body))
return {"id": "should-not-mint", **body}
def fake_post(api_base, path, body):
instance = instance_name(api_base)
collection = path.strip("/")
if collection not in {"workplans", "tasks"}:
return {"ok": True}
create_attempts[instance][collection] += 1
existing = stores[instance][collection].get(body["id"])
if existing is not None:
return existing
stored = dict(body)
stores[instance][collection][body["id"]] = stored
return stored
monkeypatch.setattr("consistency_check._api_get", fake_get)
monkeypatch.setattr("consistency_check._api_post", fake_post)
@ -1639,18 +1684,43 @@ class TestC06WorkstreamCreation:
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.setattr(
"consistency_check._git_commit_writeback", lambda *args, **kwargs: False
)
monkeypatch.setenv("STATEHUB_REGISTRAR", "0")
report = fix_repo("http://unused", "demo-repo")
reports = {
instance: fix_repo(f"http://{instance}", "demo-repo")
for instance in repos
}
written = [
(repo / "workplans" / "STATE-WP-0001-demo.md").read_bytes()
for repo in repos.values()
]
assert written[0] == written[1]
workplan_id = _derived_work_record_uuid("STATE-WP-0001")
task_id = _derived_work_record_uuid("STATE-WP-0001-T01")
text = written[0].decode("utf-8")
assert f'state_hub_workstream_id: "{workplan_id}"' in text
assert f'state_hub_task_id: "{task_id}"' in text
for instance in repos:
assert set(stores[instance]["workplans"]) == {workplan_id}
assert set(stores[instance]["tasks"]) == {task_id}
assert create_attempts[instance] == {"workplans": 1, "tasks": 1}
assert not any("identifier registrar" in fix for fix in reports[instance].fixes_applied)
assert created == []
patched = wp.read_text(encoding="utf-8")
assert "state_hub_workstream_id" not in patched
assert "state_hub_task_id" not in patched
assert any("not the identifier registrar" in fix for fix in report.fixes_applied)
assert any("rmgr sync" in fix for fix in report.fixes_applied)
assert not any("set STATEHUB_REGISTRAR=1" in fix for fix in report.fixes_applied)
assert any(issue.check_id == "C-06" for issue in report.issues)
# A second reconcile is idempotent: neither independent hub creates a
# duplicate record and the repository bytes remain unchanged.
for instance in repos:
fix_repo(f"http://{instance}", "demo-repo")
assert create_attempts == {
"hub-a": {"workplans": 1, "tasks": 1},
"hub-b": {"workplans": 1, "tasks": 1},
}
assert [
(repo / "workplans" / "STATE-WP-0001-demo.md").read_bytes()
for repo in repos.values()
] == written
# ---------------------------------------------------------------------------
# _git_pull (T02 remote fix helper)