diff --git a/core/CONTRACT.md b/core/CONTRACT.md index a8568896..34662df7 100644 --- a/core/CONTRACT.md +++ b/core/CONTRACT.md @@ -154,6 +154,9 @@ runner reliability or speed) go to the front of the merge line, ahead of feature work, through the repository's queue priority if it has one. Infra-only fixes may use the infra-only route above. +Finish planned base updates before starting checks. Wait for an identical check +already queued or running at the same head and fingerprint. Before a fallback +check on a published head, run `loopzero ready` and reuse any receipt it accepts. The builder runs each full local gate once and records its command, exact head SHA, environment fingerprint (from consumer AGENTS.md/docs), result, time and log path. Builders, reviewers and coordinators reuse green receipts at the same head and @@ -203,9 +206,10 @@ Freeze new work on Codex evidence projections. Simplify or delete them when they Preserve the approved head; optional suggestions do not justify edits. - After an approved ordinary delta with blocking findings resolved, one more delta can review a suffix of verified base merges containing a conflict. Otherwise, merge with readiness passing or split a head that needs more review. -- After an approved primary or a delta review, take base changes by merging the - base into the existing branch. Readiness and hosted eligibility can inherit - coverage only across proven clean base merges. A request_changes primary +- When a base update is needed after a published review, merge the configured + base into the existing branch to preserve reviewed ancestry. Readiness and + hosted eligibility can inherit coverage only across proven clean base merges. + A request_changes primary additionally requires resolution of every blocking finding. Source commits, modified merges, and rebases that rewrite the reviewed commit require review coverage for the new head. diff --git a/core/skills/implement/SKILL.md b/core/skills/implement/SKILL.md index fd485570..64a6f994 100644 --- a/core/skills/implement/SKILL.md +++ b/core/skills/implement/SKILL.md @@ -19,6 +19,8 @@ freeze them. Change Acceptance only with a recorded reason in Notes, before implementing the change. For changes touching guards, auth, permissions, sessions, secrets or trust boundaries, record a short design pass in Notes before the first code edit: threats, invariants and chosen approach. +When deduplicating tests, list their distinct assertions before editing, +keep each in a surviving test, and record where in the PR body. Use [write-tests](../write-tests/SKILL.md) to prove the bounded acceptance. Map migration, authorization, locking/concurrency and policy edge cases to tests @@ -62,6 +64,8 @@ Before the check and draft push for primary review, rebase your own commits onto Leave base merges out of a branch awaiting its delta. For base or check-script changes after review, follow the [Review budget](../../CONTRACT.md#review-budget). +If a reviewed branch needs a conflict refresh, confirm the review path and +merge the base before starting the check for the resolved head. Preserve the primary for the delta and the delta for post-review fixes. Never bypass the sandbox, change the check list or enable `[checks].network` to pass checks. diff --git a/core/skills/work-issue/SKILL.md b/core/skills/work-issue/SKILL.md index 73e4ae31..d2be8ef0 100644 --- a/core/skills/work-issue/SKILL.md +++ b/core/skills/work-issue/SKILL.md @@ -29,6 +29,9 @@ include required completion in the closing delivery. A child does not own its pa Recheck collisions, live acceptance, prior delivery and ownership before publication and merge. Reconcile changes before proceeding. On approval, run readiness at the approved head and defer optional changes. +Before queueing, check the candidate merged with the current base against +every repository size cap, including the combined effect of any batch. +Verify the replacement is installed and works before retiring a deployment workaround. Before a source edit for [delta](../../CONTRACT.md#review-budget), name the unmet criterion or verified defect. Own review, CI and post-merge acceptance waits. Use the [acceptance evidence](reference.md#acceptance-evidence) and diff --git a/src/loopzero/candidate.py b/src/loopzero/candidate.py index 27eff315..676b9926 100644 --- a/src/loopzero/candidate.py +++ b/src/loopzero/candidate.py @@ -80,6 +80,14 @@ def _require(condition: bool, message: str, error: type[CandidateError] = Candid raise error(message) +def _field(value: object, name: str) -> object: + return value.get(name) if isinstance(value, dict) else None + + +def _matches(pattern: re.Pattern[str], value: object) -> bool: + return isinstance(value, str) and pattern.fullmatch(value) is not None + + def _identity(actor: object) -> tuple[object, object, object, object]: if not isinstance(actor, dict): return (None, None, None, None) @@ -151,8 +159,8 @@ def _candidate_lineage(status: JsonObject, candidate_number: int) -> tuple[str, return candidate_id, sorted(source_numbers), sorted(missing) -def _repo_identity(repo: JsonObject) -> tuple[object, object]: - return repo.get("id"), repo.get("full_name") +def _repo_identity(repo: object) -> tuple[object, object]: + return _field(repo, "id"), _field(repo, "full_name") def _candidate_snapshot( @@ -179,25 +187,14 @@ def _candidate_snapshot( def _source_fingerprint(source: JsonObject) -> tuple[object, ...]: - head = source.get("head") base = source.get("base") - base = base if isinstance(base, dict) else {} - base_repo = base.get("repo") + base_repo = _field(base, "repo") labels = source.get("labels", []) if not isinstance(labels, list) or any(not isinstance(label, dict) or not isinstance(label.get("name"), str) for label in labels): raise CandidateError("invalid source PR labels") - return ( - source.get("number"), - source.get("merged"), - source.get("mergeable") is False, - tuple(label["name"] for label in labels), - source.get("state"), - source.get("draft"), - source.get("body"), - head.get("sha") if isinstance(head, dict) else None, - base.get("ref"), - *_repo_identity(base_repo if isinstance(base_repo, dict) else {}), - ) + return (source.get("number"), source.get("merged"), source.get("mergeable") is False, + tuple(label["name"] for label in labels), source.get("state"), source.get("draft"), source.get("body"), + _field(source.get("head"), "sha"), _field(base, "ref"), *_repo_identity(base_repo)) def _lookup_source(github_get: GitHubGet, repo: str, number: int) -> JsonObject: @@ -220,12 +217,8 @@ def _attest_source( f"source PR #{number} is not open", CandidateRaceError if source.get("merged") is True else CandidateError, ) - head = source.get("head") - base = source.get("base") - _require( - isinstance(head, dict) and isinstance(base, dict), - f"source PR #{number} refs are missing", - ) + head, base = source.get("head"), source.get("base") + _require(isinstance(head, dict) and isinstance(base, dict), f"source PR #{number} refs are missing") base_repo = base.get("repo") _require( base.get("ref") == base_branch @@ -234,17 +227,13 @@ def _attest_source( f"source PR #{number} does not target this repository's {base_branch} branch", ) source_sha = head.get("sha") - _require( - isinstance(source_sha, str) and _SHA.fullmatch(source_sha) is not None, - f"source PR #{number} has an invalid head", - ) + _require(_matches(_SHA, source_sha), f"source PR #{number} has an invalid head") comparison = _object( github_get(f"/repos/{repository['full_name']}/compare/{source_sha}...{candidate_sha}"), "GitHub compare returned an invalid payload", ) - merge_base = comparison.get("merge_base_commit") _require(comparison.get("status") in {"ahead", "identical"} - and isinstance(merge_base, dict) and merge_base.get("sha") == source_sha, + and _field(comparison.get("merge_base_commit"), "sha") == source_sha, f"source PR #{number} head {source_sha} is not an ancestor of the candidate") return source_sha @@ -426,8 +415,7 @@ def _attest_candidate_once( _require(event.get("action") in {"opened", "synchronize"}, "Candidate attestation requires its creation or head-update event") full_name = repository.get("full_name") - _require(isinstance(full_name, str) and _REPOSITORY.fullmatch(full_name) is not None, - "GitHub event repository name is invalid") + _require(_matches(_REPOSITORY, full_name), "GitHub event repository name is invalid") event_head = _object(event_pr.get("head"), "GitHub event candidate head is missing") event_ref = event_head.get("ref") _require(isinstance(event_ref, str) and event_ref.startswith(QUEUE_BRANCH_PREFIX), @@ -435,9 +423,8 @@ def _attest_candidate_once( owner, repo = full_name.split("/", 1) app = _object(github_get("/apps/mergify"), "GitHub App lookup is invalid") - app_owner = app.get("owner") _require(app.get("id") == MERGIFY_APP_ID and app.get("slug") == "mergify" - and isinstance(app_owner, dict) and app_owner.get("login") == MERGIFY_APP_OWNER, + and _field(app.get("owner"), "login") == MERGIFY_APP_OWNER, "Could not resolve the official Mergify GitHub App") expected_identity = _identity(_object(github_get("/users/mergify%5Bbot%5D"), "GitHub bot lookup is invalid")) _require(expected_identity == (MERGIFY_BOT_ID, MERGIFY_BOT_LOGIN, "Bot", MERGIFY_APP_URL), @@ -450,8 +437,7 @@ def _attest_candidate_once( candidate_number = event_pr.get("number") candidate_sha = event_head.get("sha") _require(isinstance(candidate_number, int) and candidate_number > 0, "Candidate PR number is invalid") - _require(isinstance(candidate_sha, str) and _SHA.fullmatch(candidate_sha) is not None, - "Candidate head SHA is invalid") + _require(_matches(_SHA, candidate_sha), "Candidate head SHA is invalid") candidate_path = f"/repos/{full_name}/pulls/{candidate_number}" def recheck_candidate(message: str = "GitHub candidate lookup returned an invalid payload") -> None: candidate = _object(github_get(candidate_path), message) @@ -498,8 +484,7 @@ def live_lineage() -> tuple[str, list[int], list[str]]: with contextlib.suppress(Exception): current = _lookup_source(github_get, full_name, number) if (isinstance(current, dict) and current.get("merged") is True - and isinstance(current.get("head"), dict) - and current["head"].get("sha") == source_sha): + and _field(current.get("head"), "sha") == source_sha): raise CandidateRaceError(f"source PR #{number} landed during attestation") from exc raise @@ -507,7 +492,7 @@ def live_lineage() -> tuple[str, list[int], list[str]]: try: base_ref = _object(base_before, f"{base_branch} ref unavailable") base_sha = _object(base_ref.get("object"), f"{base_branch} object unavailable").get("sha") - _require(isinstance(base_sha, str) and _SHA.fullmatch(base_sha) is not None, f"invalid {base_branch} head") + _require(_matches(_SHA, base_sha), f"invalid {base_branch} head") _verify_tree(full_name, base_sha, candidate_sha, [snapshot[0] for snapshot in source_snapshots.values()]) _require( @@ -531,11 +516,8 @@ def live_lineage() -> tuple[str, list[int], list[str]]: recheck_candidate() for number, (expected_sha, expected_fingerprint) in source_snapshots.items(): current = _lookup_source(github_get, full_name, number) - current_head = current.get("head") - _require( - isinstance(current_head, dict) and current_head.get("sha") == expected_sha, - f"source PR #{number} head changed during attestation", - ) + _require(_field(current.get("head"), "sha") == expected_sha, + f"source PR #{number} head changed during attestation") _require( _source_fingerprint(current) == expected_fingerprint, f"source PR #{number} metadata changed during attestation", diff --git a/src/loopzero/sandbox.py b/src/loopzero/sandbox.py index 0e2f3514..a015f279 100644 --- a/src/loopzero/sandbox.py +++ b/src/loopzero/sandbox.py @@ -276,9 +276,7 @@ def _has_inputs(config: Config, command: str) -> bool: def _input_key(config: Config, worktree: Path, command: str, base: str, *, status: Callable[[str], None] | None = None, workflow: str | Path = "workflow.toml") -> str | None: - if not _has_inputs(config, command): - return None - if not base and status is None: + if not _has_inputs(config, command) or (not base and status is None): return None entries = {key: config.inputs[key] for key in (command, "*") if key in config.inputs} try: diff --git a/src/loopzero/worktree.py b/src/loopzero/worktree.py index f71e1ded..aeaa60b2 100644 --- a/src/loopzero/worktree.py +++ b/src/loopzero/worktree.py @@ -373,13 +373,10 @@ def _require_no_ignored_user_files(wt: Path) -> None: wt, "ls-files", "--others", "--ignored", "--exclude-standard", "-z", preserve_newlines=True ) for path in ignored.split("\0")[:-1]: - if ( - (path in {".loopzero/task.md", ".loopzero/checks.json"} - or re.fullmatch(r"\.loopzero/review(?:er-output)?-[0-9a-f]{12}-(primary|delta)\.json", path)) - and not (wt / path).is_symlink() - ): - continue - raise WorktreeError(f"worktree contains ignored file {path!r}, refusing to remove: {wt}") + if not ((path in {".loopzero/task.md", ".loopzero/checks.json"} + or re.fullmatch(r"\.loopzero/review(?:er-output)?-[0-9a-f]{12}-(primary|delta)\.json", path)) + and not (wt / path).is_symlink()): + raise WorktreeError(f"worktree contains ignored file {path!r}, refusing to remove: {wt}") def cleanup(wt: Path, expected_head: str) -> None: