Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions shape-doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,12 @@ def pin_reads_at(ctx: Context, rev: str) -> bool:
`parse_yaml` -- and `check_pin` makes the checks `read_pin` makes, so
the two cannot disagree about a pin. Where git gives no blob (no such
path, no such commit) there is no pin that reads, and `files: 5`, which
`read_pin` itself fails with a `TypeError`, does not read either.
`check_pin` refuses as `update-pin-row`, does not read either (#290).

A `TypeError` IS NOT CAUGHT. It was, for that `files: 5`; nothing in a
pin's bytes raises one now, so one means a caller out of step with
`check_pin`, and the doctor fails loudly rather than answer that no
commit holds a pin to put back.
"""
blob = git_answer(["cat-file", "blob", f"{rev}:./{SHAPE_PIN}"],
ctx.root, binary=True)
Expand All @@ -2197,8 +2202,8 @@ def pin_reads_at(ctx: Context, rev: str) -> bool:
us = ctx.update_shape()
try:
text = blob.decode("utf-8").replace("\r\n", "\n").replace("\r", "\n")
us.check_pin(us.parse_yaml(text), f"{rev}:{SHAPE_PIN}")
except (Refusal, us.YamlError, ValueError, TypeError):
us.check_pin(us.parse_yaml(text), f"{rev}:{SHAPE_PIN}", ctx.root)
except (Refusal, us.YamlError, ValueError):
return False
return True

Expand Down Expand Up @@ -3933,7 +3938,13 @@ def pinned_paths(root: Path) -> set:
pin = Context._read(root / "contracts" / "shape-pin.yaml")
if not isinstance(pin, dict):
return set()
return {str(row.get("path")) for row in (pin.get("files") or [])
# A `files:` that is not a list pins nothing, as a pin that is not a
# mapping pins nothing (#290): `files: 5` was iterated, a TypeError. The
# shape-currency row is where that pin is reported.
rows = pin.get("files")
if not isinstance(rows, list):
return set()
return {str(row.get("path")) for row in rows
if isinstance(row, dict) and row.get("path")}


Expand Down
8 changes: 8 additions & 0 deletions templates/assembly-root/scripts/validate-pins.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,14 @@ def _check_shape_pin(root: Path, manifest: dict, report: Report) -> None:
pin, rel = _check_shape_pin_header(root, manifest, report)
before = len(report.findings)
files = pin.get("files") or []
if not isinstance(files, list):
# Asked, not assumed (#290): `files: 5` was iterated, and the run
# ended in a TypeError with no finding naming the pin.
report.finding("shape-pin-row",
f"{rel}: `files:` is {files!r}, not a list of "
"`path:`/`sha256:` rows, so nothing about the copied "
"shape files is actually asserted")
return
if not files:
report.finding("shape-pin-no-files",
f"{rel}: no `files:` rows, so nothing about the copied "
Expand Down
8 changes: 8 additions & 0 deletions templates/family-root/scripts/validate-family.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ def _check_shape_pin_files(root: Path, pin: dict, rel: str,
"""
before = len(report.findings)
files = pin.get("files") or []
if not isinstance(files, list):
# Asked, not assumed (#290): `files: 5` was iterated, and the run
# ended in a TypeError with no finding naming the pin.
report.finding("shape-pin-row",
f"{rel}: `files:` is {files!r}, not a list of "
"`path:`/`sha256:` rows, so nothing about the copied "
"shape files is actually asserted")
return
if not files:
report.finding("shape-pin-no-files",
f"{rel}: no `files:` rows, so nothing about the copied "
Expand Down
6 changes: 6 additions & 0 deletions tests/test_shape_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3762,6 +3762,12 @@ def pin_with(old: str, new: str):
"update-pin-no-files", id="no-files-rows"),
pytest.param(pin_with(r'^ - path: .*$', ' - nopath: x'),
"update-pin-row", id="a-row-with-no-path"),
pytest.param(pin_with(r'(?s)^files:.*\Z', 'files: 5\n'),
"update-pin-row", id="files-5-not-a-list"),
pytest.param(pin_with(r'(?s)^files:.*\Z', 'files: true\n'),
"update-pin-row", id="files-true-not-a-list"),
pytest.param(pin_with(r'(?s)^files:.*\Z', 'files: 1.5\n'),
"update-pin-row", id="files-1.5-not-a-list"),
pytest.param(lambda text: None, "update-pin-missing",
id="a-deleted-pin"),
]
Expand Down
Loading
Loading