fix(adopt): make verify check something
verify re-derived baselineRevision from current HEAD instead of reading the plan's, so drift between the planned and the actual baseline was undetectable by construction. Called without --plan -- the obvious way to call it -- it returned empty changedPaths and preservedPaths, which reads as "adoption touched nothing" when it means "this verified nothing"; the pilot run reported a green pass that was entirely vacuous. None of the specific checks runbook section 13 promises were implemented. Learned that a preserve promise was never actually enforced: overwriting a preserved file after apply still produced a passing report. - take the baseline from the plan and flag divergence from HEAD - fail on a modified preserved path, warn on changes outside the plan - mark an unscoped report rather than letting empty lists imply success - express all of this through unresolvedFindings, since the report schema is closed and widening it would be a normative change - expand untracked directories in dirty_paths; git collapses them to "dir/", which never matches the file paths a plan names Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
523ef61fe3
commit
56a42389ab
@@ -616,21 +616,50 @@ def apply_plan(root: Path, plan: dict[str, Any], approve_hash: str) -> list[str]
|
||||
return written
|
||||
|
||||
|
||||
def _covers(rel_path: str, entries: set[str]) -> bool:
|
||||
"""True when ``rel_path`` is one of ``entries`` or sits beneath one of them."""
|
||||
return rel_path in entries or any(rel_path.startswith(f"{entry}/") for entry in entries)
|
||||
|
||||
|
||||
def verify(root: Path, plan: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
validation = validate_repository(root)
|
||||
baseline = gitutil.head_revision(root)
|
||||
head = gitutil.head_revision(root)
|
||||
|
||||
changed_paths: list[str] = []
|
||||
preserved_paths: list[str] = []
|
||||
if plan is not None:
|
||||
extra: list[tuple[str, str]] = []
|
||||
|
||||
if plan is None:
|
||||
# Without the plan there is nothing to check the repository against, and
|
||||
# empty changedPaths/preservedPaths would otherwise read as "adoption
|
||||
# touched nothing" rather than "this report verified nothing".
|
||||
baseline = head
|
||||
extra.append(("warning", "ADOPT_REPORT_UNSCOPED"))
|
||||
else:
|
||||
baseline = plan.get("baselineRevision", head)
|
||||
for change in plan["changes"]:
|
||||
if change["action"] in ("create", "patch-managed-block"):
|
||||
changed_paths.append(change["path"])
|
||||
elif change["action"] == "preserve":
|
||||
preserved_paths.append(change["path"])
|
||||
|
||||
unresolved = sorted({f.code for f in validation.findings if f.severity in ("warning", "error")})
|
||||
if any(f.severity == "error" for f in validation.findings):
|
||||
dirty = gitutil.dirty_paths(root)
|
||||
preserved_set, changed_set = set(preserved_paths), set(changed_paths)
|
||||
if any(_covers(path, preserved_set) for path in dirty):
|
||||
extra.append(("error", "ADOPT_PRESERVED_MODIFIED"))
|
||||
if any(
|
||||
not _covers(path, preserved_set) and not _covers(path, changed_set) for path in dirty
|
||||
):
|
||||
extra.append(("warning", "ADOPT_DIFF_OUTSIDE_PLAN"))
|
||||
if baseline != head:
|
||||
extra.append(("warning", "ADOPT_BASELINE_CHANGED"))
|
||||
|
||||
severities = [f.severity for f in validation.findings] + [severity for severity, _ in extra]
|
||||
unresolved = sorted(
|
||||
{f.code for f in validation.findings if f.severity in ("warning", "error")}
|
||||
| {code for _, code in extra}
|
||||
)
|
||||
if "error" in severities:
|
||||
outcome = "fail"
|
||||
elif unresolved:
|
||||
outcome = "pass-with-warnings"
|
||||
|
||||
@@ -43,8 +43,12 @@ def dirty_paths(root: Path) -> set[str]:
|
||||
so paths containing spaces or non-ASCII are neither quoted nor mangled, and so
|
||||
rename entries split reliably: a rename emits the destination path, then a
|
||||
second NUL-terminated field holding the original path.
|
||||
|
||||
``-uall`` matters as much as ``-z``: by default Git collapses a wholly
|
||||
untracked directory to a single ``dir/`` entry, which would never match the
|
||||
file paths a plan names and so would read as a change outside the plan.
|
||||
"""
|
||||
result = _run(["status", "--porcelain", "-z"], root)
|
||||
result = _run(["status", "--porcelain", "-z", "-uall"], root)
|
||||
if result.returncode != 0:
|
||||
return set()
|
||||
fields = [field for field in result.stdout.split("\0") if field]
|
||||
|
||||
Reference in New Issue
Block a user