fix(init): stop the entry point from disabling the command it reaches
A field report from bootstrapping Services/Vault: ~20 CLI calls produced
three productive writes, and four of those calls were deliberate failures
sent only to discover a vocabulary.
The worst of it was self-inflicted and new. `repoctl skills install` is the
documented way to make the bootstrap skill reachable, and it writes the
three skill files -- which `init` then reported as INIT_PATH_COLLISION and
redirected to `adopt`. Every skill-driven bootstrap of an empty repository
was pushed onto the adoption path. The collision check exists to protect
content the tool did not author, and identical bytes are nothing to
protect: a path already holding exactly what the plan would write is no
longer a collision, at plan time or at write time, while a file whose
content differs still is. `init` reports only the files it actually wrote.
`--lifecycle` advertised no choices, so its vocabulary was reachable only
by sending a wrong value and reading the refusal; it now carries `choices`
like `--type` does.
`--answers-template` prints a commented answers file naming every key, its
allowed values and its default. The answers keys are not the flag names
(`--type` sets `repositoryType`) and nothing printed the mapping. It lists
`summary` and `namespace` too, which are cheap to answer once and otherwise
survive as generated placeholders in the contract.
`--repo .` proposed the name `adopted-repository`: `Path(".").name` is the
empty string, so the ordinary way to name the current repository fell
through to the generic fallback. Resolve before deriving.
Both skills gained what the report had to discover by hand: that `--plan`
already unwraps a saved result envelope, and that sibling repositories are
where a naming convention comes from.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
c80d39cc73
commit
5b9c97fdcd
@@ -157,3 +157,61 @@ def test_refusals_are_envelopes_not_stderr_lines(tmp_path: Path, capsys) -> None
|
||||
assert exit_code != 0
|
||||
assert envelope["outcome"] == "failure"
|
||||
assert envelope["findings"][0]["code"] == "INIT_NAME_INVALID"
|
||||
|
||||
|
||||
# --- what `repoctl skills install` leaves behind is not a collision ----------
|
||||
|
||||
def test_skills_already_installed_do_not_block_init(tmp_path: Path) -> None:
|
||||
"""The entry point must not disable the command it exists to reach.
|
||||
|
||||
`repoctl skills install` is the documented way to make the bootstrap skill
|
||||
reachable at all, and it writes exactly the files `init` plans to write.
|
||||
Treating those as collisions sent every skill-driven bootstrap to `adopt`.
|
||||
"""
|
||||
from stewardship import skills
|
||||
|
||||
repo = tmp_path / "vault"
|
||||
repo.mkdir()
|
||||
skills.install(repo)
|
||||
|
||||
answers = bootstrap.BootstrapAnswers.from_mapping(_answers())
|
||||
plan = bootstrap.build_bootstrap_plan(answers, repo)
|
||||
written = bootstrap.apply_bootstrap_plan(repo, plan, plan["planHash"])
|
||||
|
||||
assert not [path for path in written if path.startswith(".claude/skills/")]
|
||||
assert "ops/contract.yaml" in written
|
||||
assert (repo / ".claude" / "skills" / "repository-adoption" / "SKILL.md").is_file()
|
||||
|
||||
|
||||
def test_a_differing_file_is_still_a_collision(tmp_path: Path) -> None:
|
||||
"""Only byte-identical content is waived; edited content still protects."""
|
||||
repo = tmp_path / "vault"
|
||||
(repo / ".claude" / "skills" / "repo-handoff").mkdir(parents=True)
|
||||
(repo / ".claude" / "skills" / "repo-handoff" / "SKILL.md").write_text(
|
||||
"# locally rewritten\n", encoding="utf-8"
|
||||
)
|
||||
|
||||
answers = bootstrap.BootstrapAnswers.from_mapping(_answers())
|
||||
with pytest.raises(bootstrap.BootstrapError) as excinfo:
|
||||
bootstrap.build_bootstrap_plan(answers, repo)
|
||||
assert excinfo.value.code == "INIT_PATH_COLLISION"
|
||||
|
||||
|
||||
# --- the answers template ----------------------------------------------------
|
||||
|
||||
def test_answers_template_is_valid_yaml_and_accepted_as_answers() -> None:
|
||||
"""A template nobody can feed back to the tool is documentation, not a template."""
|
||||
from stewardship.markdown import load_yaml_text
|
||||
|
||||
data = load_yaml_text(bootstrap.answers_template())
|
||||
answers = bootstrap.BootstrapAnswers.from_mapping(data)
|
||||
assert answers.name and answers.owners and answers.repository_type
|
||||
|
||||
|
||||
def test_answers_template_names_every_vocabulary() -> None:
|
||||
"""The values were previously discoverable only by sending a wrong one."""
|
||||
text = bootstrap.answers_template()
|
||||
for value in ("service-config", "production", "restricted"):
|
||||
assert value in text
|
||||
# The key that differs from its flag name, which cost a round trip to learn.
|
||||
assert "repositoryType" in text
|
||||
|
||||
Reference in New Issue
Block a user