Skip to content

Commit e9c4827

Browse files
brettheapclaude
andauthored
update-shape.py: the no-shape refusal names the kind's manifest validator (#52)
On a family root the "no `shape:` block" remediation sent the operator to validate-manifest.py, which a family root does not carry; its validator is validate-family.py. Kind now names its manifest validator explicitly and the refusal (and rewrite_manifest's docstring) use it. Tests: the refusal names validate-family.py on a family root and validate-manifest.py on a project root. Closes #48 Lane: xFactory-1 Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
1 parent 355f6ef commit e9c4827

3 files changed

Lines changed: 78 additions & 6 deletions

File tree

‎tests/test_family.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import pytest
2929

3030
from conftest import FILE_PROTOCOL, REPO, git, run_script
31+
from test_update_shape import strip_shape_block
3132

3233
sys.path.insert(0, str(REPO / "scripts"))
3334
from repo_shape import load_yaml, tree_digest # noqa: E402
@@ -728,6 +729,37 @@ def test_update_shape_reads_a_family_root_and_mirrors_into_family_yaml(
728729
assert validate(holder).returncode == 0
729730

730731

732+
def test_update_shape_with_no_shape_block_names_the_family_validator(
733+
family, tmp_path):
734+
"""A FAMILY root's remediation must send the operator to
735+
`validate-family.py` — the validator this root actually carries, not
736+
`validate-manifest.py`, which a family root does not have. See the twin
737+
of this test on a project root in `test_update_shape.py`."""
738+
upstream = upstream_clone(tmp_path / "openRepoShape")
739+
changed = "templates/family-root/scripts/validate-family.py"
740+
source = upstream / changed
741+
source.write_text(source.read_text()
742+
+ "\n# forces a target commit past the family's pin.\n")
743+
git("-c", "user.name=t", "-c", "user.email=t@t", "commit", "-q", "-m",
744+
"Force a target commit past the family's pin", "--", changed,
745+
cwd=upstream)
746+
target_commit = git("rev-parse", "HEAD", cwd=upstream).stdout.strip()
747+
748+
holder = tmp_path / NAME
749+
shutil.copytree(family["root"], holder, symlinks=True)
750+
before = load_yaml(holder / "contracts" / "shape-pin.yaml")["commit"]
751+
strip_shape_block(holder / "family.yaml")
752+
753+
applied = run_script(UPDATE, "apply", "--root", str(holder), "--yes",
754+
"--upstream", str(upstream), "--at", target_commit)
755+
assert applied.returncode == 2
756+
assert "update-manifest-no-shape" in applied.stderr
757+
assert "validate-family.py" in applied.stderr
758+
assert "validate-manifest.py" not in applied.stderr
759+
assert load_yaml(holder / "contracts" / "shape-pin.yaml")["commit"] \
760+
== before, "a refused apply writes nothing at all"
761+
762+
731763
def test_update_shape_does_not_resync_a_family_bootstrap_from_the_project_one(
732764
family, tmp_path):
733765
"""BOTH ROOTS HOLD A `scripts/bootstrap.py` AND THEY ARE DIFFERENT FILES.

‎tests/test_update_shape.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,37 @@ def test_apply_without_yes_refuses_where_nobody_can_be_asked(
219219
== upstream_and_project["a"]
220220

221221

222+
def strip_shape_block(manifest_path) -> None:
223+
"""Remove the `shape:` block from a manifest, as if it had never been
224+
elected — the one way `rewrite_manifest` has nothing to mirror the pin
225+
into."""
226+
lines = manifest_path.read_text(encoding="utf-8").splitlines()
227+
start = next(i for i, line in enumerate(lines) if line.rstrip() == "shape:")
228+
end = len(lines)
229+
for index in range(start + 1, len(lines)):
230+
if lines[index].strip() and not lines[index].startswith((" ", "\t")):
231+
end = index
232+
break
233+
manifest_path.write_text("\n".join(lines[:start] + lines[end:]) + "\n",
234+
encoding="utf-8")
235+
236+
237+
def test_apply_with_no_shape_block_names_this_kinds_own_manifest_validator(
238+
root, upstream_and_project):
239+
"""A PROJECT root's remediation must send the operator to
240+
`validate-manifest.py`, the validator this root actually carries — see
241+
the family-side twin of this test in `test_family.py`, which asserts the
242+
opposite name on a root that does not carry this one."""
243+
strip_shape_block(root / "project.yaml")
244+
result = apply(root, upstream_and_project)
245+
assert result.returncode == 2
246+
assert "update-manifest-no-shape" in result.stderr
247+
assert "validate-manifest.py" in result.stderr
248+
assert "validate-family.py" not in result.stderr
249+
assert load_yaml(root / "contracts" / "shape-pin.yaml")["commit"].lower() \
250+
== upstream_and_project["a"], "a refused apply writes nothing at all"
251+
252+
222253
# --- drift the project introduced ------------------------------------------
223254

224255
def edit_locally(root, rel: str) -> None:

‎update-shape.py‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ class Kind:
152152
"""
153153

154154
def __init__(self, name: str, manifest: str, template_dir: str,
155-
copy_source: dict, lists: tuple, validators: tuple):
155+
copy_source: dict, lists: tuple, validators: tuple,
156+
manifest_validator: str):
156157
self.name = name
157158
self.manifest = manifest
158159
self.template_dir = template_dir
@@ -163,18 +164,26 @@ def __init__(self, name: str, manifest: str, template_dir: str,
163164
#: matter are the TARGET COMMIT's, not this checkout's.
164165
self.lists = lists
165166
self.validators = validators
167+
#: Which of `validators` checks the manifest's `shape:` block, named
168+
#: explicitly rather than read off `validators[-1]`: a refusal that
169+
#: sends the operator to a validator they do not carry is a wrong
170+
#: answer with a confident tone, same as the ones `Refusal` itself is
171+
#: for.
172+
self.manifest_validator = manifest_validator
166173

167174

168175
PROJECT_KIND = Kind("project", "project.yaml", "templates/assembly-root",
169176
COPY_SOURCE,
170177
("COPIED_VERBATIM", "COPIED_FROM_SHAPE", "EXECUTABLE"),
171178
("scripts/validate-pins.py",
172-
"scripts/validate-manifest.py"))
179+
"scripts/validate-manifest.py"),
180+
"scripts/validate-manifest.py")
173181
FAMILY_KIND = Kind("family", "family.yaml", "templates/family-root",
174182
FAMILY_COPY_SOURCE,
175183
("FAMILY_COPIED_VERBATIM", "FAMILY_COPIED_FROM_SHAPE",
176184
"FAMILY_EXECUTABLE"),
177-
("scripts/validate-family.py",))
185+
("scripts/validate-family.py",),
186+
"scripts/validate-family.py")
178187

179188

180189
def root_kind(root: Path) -> Kind:
@@ -763,7 +772,7 @@ def rewrite_shape_pin(text: str, commit: str, tree: str,
763772

764773

765774
def rewrite_manifest(text: str, commit: str, tree: str, kind: Kind) -> str:
766-
"""The two fields `validate-manifest.py` checks, inside `shape:`.
775+
"""The two fields the kind's manifest validator checks, inside `shape:`.
767776
768777
Scoped to the block on purpose: `commit:` and `tree_sha256:` are spelled
769778
the same way in every pin, and a whole-file replacement would move a leg's
@@ -780,8 +789,8 @@ def rewrite_manifest(text: str, commit: str, tree: str, kind: Kind) -> str:
780789
"update-manifest-no-shape",
781790
f"{kind.manifest} has no `shape:` block, so there is nothing to "
782791
"mirror the pin into",
783-
"Remediation: `validate-manifest.py` requires one; add it, or "
784-
"re-scaffold.")
792+
f"Remediation: `{Path(kind.manifest_validator).name}` requires "
793+
"one; add it, or re-scaffold.")
785794
end = len(lines)
786795
for index in range(start + 1, len(lines)):
787796
line = lines[index]

0 commit comments

Comments
 (0)