feat: delegate project register; registrar-only ID minting
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 39s

STATE-WP-0080-T02: statehub register routes project-flavor scaffolding
through rmgr scaffold and keeps only repo + host-path registration.
T01 refuse remains when GOAL.md is missing and --wp-prefix is not set.

RMGR-WP-0005-T01: C-06/C-11/C-32 skip mint+writeback unless this
instance is the identifier registrar (STATEHUB_REGISTRAR or railiance
hostname).
This commit is contained in:
tegwick 2026-08-18 21:49:15 +02:00
parent 71ad6c5d17
commit d8e0eddb22
6 changed files with 419 additions and 25 deletions

View file

@ -1299,6 +1299,7 @@ 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.setenv("STATEHUB_REGISTRAR", "1")
report = fix_repo("http://unused", "demo-repo")
@ -1309,6 +1310,69 @@ class TestC06WorkstreamCreation:
assert 'state_hub_task_id: "new-task"' 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(
"---\n"
"id: STATE-WP-0001\n"
"type: workplan\n"
"title: Demo Workplan\n"
"domain: financials\n"
"repo: demo-repo\n"
"status: ready\n"
"owner: codex\n"
"---\n\n"
"## Implement Demo\n\n"
"```task\n"
"id: STATE-WP-0001-T01\n"
"status: todo\n"
"priority: high\n"
"```\n",
encoding="utf-8",
)
created = []
def fake_get(_api_base, path, params=None, **_kwargs):
if path == "/repos/demo-repo":
import socket
return {
"id": "repo-1",
"slug": "demo-repo",
"local_path": str(repo),
"host_paths": {socket.gethostname(): str(repo)},
"domain_slug": "financials",
}
if path == "/topics":
return [{"id": "topic-1", "domain_slug": "financials"}]
return []
def fake_post(_api_base, path, body):
created.append((path, body))
return {"id": "should-not-mint", **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", "0")
report = fix_repo("http://unused", "demo-repo")
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(issue.check_id == "C-06" for issue in report.issues)
# ---------------------------------------------------------------------------
# _git_pull (T02 remote fix helper)
# ---------------------------------------------------------------------------

View file

@ -12,6 +12,7 @@ from custodian_cli import cmd_fix_consistency
from statehub_register import (
RegisterInference,
detect_project_flavor_signal,
project_registration_plan,
refuse_project_flavor_scaffold,
run_register,
_invoke_llm,
@ -205,6 +206,132 @@ def test_run_register_refuses_prj_repo_without_writing_or_calling_api(
assert not (repo / "workplans").exists()
def test_project_registration_plan_durable_vs_refuse_vs_delegate(tmp_path: Path):
durable = tmp_path / "demo-service"
durable.mkdir()
assert project_registration_plan(durable) == ("durable", None)
fresh = tmp_path / "prj-example"
fresh.mkdir()
assert project_registration_plan(fresh)[0] == "refuse"
assert project_registration_plan(fresh, wp_prefix="EXCO-WP") == (
"delegate",
"EXCO-WP",
)
(fresh / "GOAL.md").write_text(
"---\nrepo_flavor: project\n---\n# Goal\n", encoding="utf-8"
)
assert project_registration_plan(fresh) == ("register-only", None)
assert project_registration_plan(fresh, wp_prefix="EXCO-WP") == (
"register-only",
None,
)
def _stub_register_io(monkeypatch: pytest.MonkeyPatch):
written: list[dict] = []
registered: list[tuple] = []
monkeypatch.setattr("statehub_register._check_api", lambda *_a, **_k: None)
monkeypatch.setattr(
"statehub_register._api_get",
lambda path, *_a, **_k: (
[{"slug": "infotech", "id": "dom-1"}]
if str(path).startswith("/domains")
else [{"id": "topic-1", "slug": "infotech", "domain_slug": "infotech"}]
),
)
monkeypatch.setattr(
"statehub_register.write_registration_files",
lambda **kwargs: written.append(kwargs) or [],
)
monkeypatch.setattr(
"statehub_register._register_or_update_repo",
lambda **kwargs: registered.append(("repo", kwargs)) or {"id": "repo-1"},
)
monkeypatch.setattr(
"statehub_register._register_host_path",
lambda *a, **k: registered.append(("path", a, k)),
)
monkeypatch.setattr("statehub_register._record_progress", lambda *_a, **_k: None)
return written, registered
def _register_args(path: Path, **overrides):
values = {
"path": str(path),
"repo_slug": None,
"wp_prefix": None,
"domain": "infotech",
"description": "Test project.",
"intent": None,
"api_base": "http://unused",
"no_llm": True,
"force": False,
"llm_provider": "mock",
"llm_model": None,
"llm_api_key": None,
"llm_timeout": 5,
}
values.update(overrides)
return argparse.Namespace(**values)
def test_run_register_delegates_project_scaffold_and_skips_templating(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
repo = tmp_path / "prj-example"
repo.mkdir()
written, registered = _stub_register_io(monkeypatch)
delegated: list[dict] = []
def fake_delegate(project_path, **kwargs):
delegated.append(kwargs)
(project_path / "GOAL.md").write_text(
"---\nrepo_flavor: project\n---\n# Goal\n", encoding="utf-8"
)
return {"status": "applied"}
monkeypatch.setattr("statehub_register.delegate_project_scaffold", fake_delegate)
run_register(_register_args(repo, wp_prefix="EXCO-WP"))
assert delegated == [
{
"slug": "prj-example",
"wp_prefix": "EXCO-WP",
"domain": "infotech",
"force": False,
}
]
assert written == []
assert [kind for kind, *_ in registered] == ["repo", "path"]
assert not (repo / "INTENT.md").exists()
assert (repo / "GOAL.md").is_file()
def test_run_register_existing_project_skips_scaffold_and_templating(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
):
repo = tmp_path / "prj-example"
repo.mkdir()
(repo / "GOAL.md").write_text(
"---\nrepo_flavor: project\n---\n# Goal\n", encoding="utf-8"
)
written, registered = _stub_register_io(monkeypatch)
monkeypatch.setattr(
"statehub_register.delegate_project_scaffold",
lambda *_a, **_k: (_ for _ in ()).throw(AssertionError("should not scaffold")),
)
run_register(_register_args(repo))
assert written == []
assert [kind for kind, *_ in registered] == ["repo", "path"]
assert not (repo / "INTENT.md").exists()
def test_write_registration_files_is_idempotent_without_force(tmp_path: Path):
inference = RegisterInference()
kwargs = {