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

@ -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 = {