The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Require local validation receipts for mapped PR changes (#3444)
harness-for-autonomous[bot]1cfdeddcee79
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.mdindex b93421d7d..ab803877b 100644--- a/.github/pull_request_template.md+++ b/.github/pull_request_template.md@@ -12,6 +12,24 @@ For a visual change, include a screenshot or short recording.List the checks you ran, the engine and operating system you used, and any known limitations.For a harness, include `harness dsh check` and a real run of the example above.+For paths requiring local checks, the CI plan lists the check names. Run+`python3 scripts/local-checks.py --list PATH...` for their commands and working+directories. After testing the final commit, put its receipts in one JSON fence+like this **before pushing that commit or marking the PR ready**. Replace the+example with actual results; omit the fence when no local check is required.+Body edits alone do not start another CI run. These are attestations of successful+complete checks, not a way to waive failures. Native checks require `macos`.++```harness-local-checks+[+ {"check":"cli-core","command":"npm run test:core","cwd":"cli","head":"FULL_40_CHARACTER_TESTED_HEAD","status":"passed","passed":123,"platform":"macos"}+]+```++Use a positive test count; zero, failed, stale-head and wrong-platform receipts+cannot satisfy the gate. Coverage commands may add ` -- --maxWorkers=2` to cap+resources. Do not include logs, personal paths or environment values.+Record the tested commit/tree (or dirty-source fingerprint), check scope, and result links.When reusing CI or baseline evidence, link it and explain why it still covers this diff.For a release task, record request → checks complete → merge → live → completion times;diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex b05c3cf07..ddcd33142 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -113,6 +113,8 @@ jobs:retention-days: 14process-checks:+ outputs:+ local_receipts: ${{ steps.local.outputs.local_receipts }}concurrency:group: ci-${{ github.event_name }}-${{ github.event.action || 'run' }}-${{ github.event.pull_request.number || github.run_id }}-process-checkscancel-in-progress: ${{ github.event_name == 'pull_request' }}@@ -136,6 +138,11 @@ jobs:sparse-checkout-cone-mode: false- name: Verify declared source checkoutrun: python3 scripts/ci-source-inputs.py process+ - name: Require local validation receipts for mapped paths+ id: local+ env:+ CI_PLAN: ${{ needs.plan.outputs.plan }}+ run: python3 scripts/local-checks.py- name: Validation deadlines, cleanup, receipts and release version guards# The fixtures commit in temporary repositories. Each commit starts a detached# `git maintenance run --auto`, which can still be writing objects/pack when thediff --git a/docs/plans/2026-11-06-local-check-receipts-plan.md b/docs/plans/2026-11-06-local-check-receipts-plan.mdnew file mode 100644index 000000000..1e48242cf--- /dev/null+++ b/docs/plans/2026-11-06-local-check-receipts-plan.md@@ -0,0 +1,49 @@+# Local check receipts implementation plan++**Goal:** Task #3594: `ci/required` refuses a PR that changes a mapped local-check input without a passing receipt for its exact head.++**Architecture:** Add a bounded local-check contract beside the existing Python CI planner. The planner selects required checks from its complete Git diff (including deletions and both sides of renames); the process job validates a fenced JSON receipt in the PR body, and the aggregate requires that validated evidence. Keep receipt text as data and never execute it. Attach receipts after the final commit and before pushing or marking Ready; no new CI run is started on ordinary PR-body edits.++**Tech Stack:** Existing Python standard-library process tooling and GitHub Actions; unittest fixtures with temporary repositories and event files.++**Spec:** Harness #3594, conversation `ba757973e71728556c792f4d`, inventory Table A #3: eight CLI coverage gates, native serial/PTY checks, and macOS Desktop checks must have command/head/pass-count evidence. The referenced remote inventory is unavailable through the local shell guard; this task's quoted row and docs/validation-and-release.md define the scope.++Implement sequentially in this session, test first, with one independent review of the final pull request as the task requests.++## Global constraints++- Own scripts/ and .github/; this required plan is the only documentation outside them. The PM removes superseded policy prose after shipment.+- No runtime dependencies, live sign-ins, native tool execution or release actions in this gate. Tests use temporary folders and fixture evidence.+- Receipts identify the whole 40-character head, the named check, its canonical command and cwd, status passed, a positive integer pass count, and platform. Native Mac receipts require macos.+- At most one `harness-local-checks` fenced JSON list, bounded by the PR body limit and 32 entries; errors name only known required checks, never arbitrary PR text.+- A ready PR requires fresh evidence; a draft may omit it. Manual and merge-group runs have no PR receipts to collect and retain their existing behavior.+- Preserve the existing automatic-suite/reuse semantics and read-only workflow permissions. No new run on a body edit; prepare evidence before the next normal PR validation run.++## Design++- Growth/concurrency: no persisted data beyond the existing PR body and CI receipt/artifact lifetime; bounded list, immutable source identity, no new writer.+- Read cost/scale: one linear pass over the already bounded PR body and the planner's changed paths, no API or shell calls from receipt parsing.+- Compatibility: add optional fields to the existing CI plan/receipt; no public product wire change. Manual/merge-group CI unchanged. New ready PR runs enforce the gate immediately.+- Migration/rollback: no data migration; reverting the workflow and planner restores prior behavior. Existing prose evidence must be converted to the structured format before a mapped PR's next run.+- Audience/identity: PR body is already shared with repository readers; receipts are authors' attestations, not cryptographic proof of execution. No raw logs, environment values or arbitrary command output is copied into CI evidence.+- Failure/platforms: missing, stale, malformed, failed, zero-test and wrong-platform evidence fail with the missing-check list. Python runs on Linux CI and local macOS; it launches no native process on Windows.++## Review focus++- Each of the eight coverage gates, native serial/PTY/shell paths and macOS-specific Desktop paths selects the right checks; unrelated paths do not.+- Deleted/renamed files and sparse checkouts retain requirements; common CLI dependency/test configuration changes cover all CLI checks.+- Old-head, zero/boolean/negative-count, failed, wrong-command/cwd/platform and malformed receipts never count.+- PR-body text and commands are never evaluated or leaked; event/plan/head mismatches fail.+- A successful process job without its receipt output cannot bypass the aggregate; draft/manual/merge-group handling does not weaken ready-PR enforcement.++## Task 1: Select and enforce local evidence++**Files:** add `scripts/local-checks.py` and `scripts/tests/test_local_checks.py`; modify `scripts/ci-plan.py`, `.github/workflows/ci.yml`, `.github/pull_request_template.md`; extend planner tests where necessary.++**Interfaces:** `required_checks(paths) -> list[str]`; `validate_receipts(required, receipts, head) -> list[dict]`; `check(plan, event) -> list[dict]`. Plans expose `local_checks`; the process job exports validated `local_receipts`; `verify` revalidates them before emitting the existing `ci-required` receipt.++- [x] Commit tests first: literal path mapping cases, real-Git rename/delete planning, bounded parser/refusal cases, subprocess process-check behavior, and aggregate refusal/pass with missing/valid evidence.+- [x] Run the new tests, record their expected failure, then implement the contract and workflow wiring.+- [x] Run targeted receipt/planner/source-input/merge-helper tests and actionlint; use automatic process CI for the full scripts suite.+- [ ] Add concise receipt instructions/example to the PR template. Record red/green evidence, stable head, platform limits and timing in the draft PR before Ready.+- [ ] Obtain independent review and hand the completed revision to the PM for merge.diff --git a/scripts/ci-plan.py b/scripts/ci-plan.pyindex 6a21061f1..4b273c4df 100644--- a/scripts/ci-plan.py+++ b/scripts/ci-plan.py@@ -22,6 +22,10 @@ _spec = importlib.util.spec_from_file_location("ci_evidence", Path(__file__).witci = importlib.util.module_from_spec(_spec)_spec.loader.exec_module(ci)+_local_spec = importlib.util.spec_from_file_location("local_checks", Path(__file__).with_name("local-checks.py"))+local_checks = importlib.util.module_from_spec(_local_spec)+_local_spec.loader.exec_module(local_checks)+CORE = {"cli", "desktop", "tui", "backend", "companions"}EXTRA = {"website", "os", "provider", "firmware", "mobile", "daemons", "pty"}@@ -551,7 +555,11 @@ def main_planner(root, base):import tempfiletry:with tempfile.TemporaryDirectory(prefix="main-ci-plan-") as folder:- for name in ("ci-plan.py", "record-ci-validation.py"):+ names = ["ci-plan.py", "record-ci-validation.py"]+ # Older reviewed bases predate the local-receipt module.+ if git(root, "ls-tree", sha(base), "--", "scripts/local-checks.py"):+ names.append("local-checks.py")+ for name in names:data = subprocess.check_output(["git", "show", f"{sha(base)}:scripts/{name}"], cwd=root,stderr=subprocess.PIPE, timeout=15)(Path(folder) / name).write_bytes(data)@@ -694,6 +702,7 @@ def make_plan(root, event_name, event, scope="full", source=None, evidence=None)return dict(schema=1, kind="ci-plan", event=event_name, head=head, base=base, draft=draft,tree=git(root, "rev-parse", "HEAD^{tree}"), paths=paths, reasons=reasons,suites=sorted(suites), required_jobs=sorted(required), reused=reused, reuse=reuse,+ local_checks=local_checks.required_checks(paths) if event_name == "pull_request" else [],manual_acceptance="Review still selects relevant native, real-engine, hardware and visual acceptance.")@@ -725,10 +734,17 @@ def verify(plan, needs, source):for job, result in needs.items():if result.get("result") not in {"success", "skipped"}:raise ValueError(f"CI job did not complete successfully: {job}")+ required_local = local_checks.planned_checks(plan)+ try:+ receipts = json.loads(needs.get("process-checks", {}).get("outputs", {}).get("local_receipts", "[]"))+ except (ValueError, TypeError):+ raise local_checks.missing(required_local) from None+ receipts = local_checks.validate_receipts(required_local, receipts, plan["head"])return dict(schema=1, kind="ci-required", status="passed", source_sha=plan["head"],source_tree=plan["tree"], event=plan["event"], base=plan["base"],suites=suites, required_jobs=sorted(expected), results={k: v["result"] for k, v in needs.items()},reused=reused, reuse=plan.get("reuse"),+ local_receipts=receipts,run_id=int(os.environ.get("GITHUB_RUN_ID", "0")), run_attempt=int(os.environ.get("GITHUB_RUN_ATTEMPT", "0")))@@ -790,6 +806,8 @@ def main():with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as summary:summary.write(f"Source: `{record.get('head', record.get('source_sha'))}`\n\n")summary.write("Automatic suites: " + ", ".join(record["suites"] or ["repository process checks"]) + ".\n")+ if record.get("local_checks"):+ summary.write("\nRequired local receipts: " + ", ".join(record["local_checks"]) + ".\n")for suite, reused in sorted((record.get("reused") or {}).items()):summary.write(f"\nReused `{suite}` from [run {reused['run_id']}]({reused['run_url']}) "f"(attempt {reused['run_attempt']}, `{reused['origin_sha']}`): {reused['reason']}.\n")diff --git a/scripts/local-checks.py b/scripts/local-checks.pynew file mode 100644index 000000000..fb32d1216--- /dev/null+++ b/scripts/local-checks.py@@ -0,0 +1,169 @@+#!/usr/bin/env python3+"""Require bounded, exact-head local validation attestations in a PR body.++Before pushing the tested commit or marking Ready, add one harness-local-checks+JSON fence to the PR body. Each entry names check, command, cwd, head, status+(passed), passed (positive test count), and platform (macos, linux or windows).+Commands are data: this program never runs them. --list PATH... prints the+required checks and their commands before a PR validation run.+"""+import argparse+from fnmatch import fnmatchcase+import json+import os+from pathlib import Path+import re+import sys+++def cli_gate(name, *paths):+ return dict(command=f"npm run test:{name}", cwd="cli", platform=None,+ paths=paths + (f"cli/vitest.{name}.config.ts",))+++# Keep coverage inputs aligned with cli/package.json and the coverage include+# lists in cli/vitest.*.config.ts. Directory patterns also cover new files/tests.+CHECKS = {+ "cli-core": cli_gate("core", "cli/src/core/*", "cli/src/services/*"),+ "cli-harnessd": cli_gate("harnessd", "cli/src/harnessd/*"),+ "cli-orchestrator": cli_gate("orchestrator", "cli/src/orchestrator/*"),+ "cli-sharing": cli_gate("sharing", "cli/src/sharing/*"),+ "cli-resume": cli_gate("resume", *(f"cli/src/lib/{name}*.ts" for name in (+ "conversationIdentity", "captureResumeIdentity", "resumeStoppedAgent", "resumeAgentService",+ "stoppedAgents", "stopAgentService", "controlTranscript", "sessionRepair"))),+ "cli-remote-viewers": cli_gate("remote-viewers", "cli/vitest.viewer.config.ts",+ *(f"cli/src/lib/{name}*.ts" for name in ("viewerFrames", "viewerWire", "viewerForwarder",+ "remoteViewerProxy", "remoteViewerRelay"))),+ "cli-portability": cli_gate("portability", "cli/src/dsh/*.ts", "cli/src/backendSocket.dsh.spec.ts",+ "cli/src/backendSocket.models.spec.ts", *(f"cli/src/lib/{name}*.ts" for name in (+ "newAgentModel", "launchOverrides", "createAgentPane", "registry"))),+ "cli-local-models": cli_gate("local-models", "cli/src/dsh/builtins*.ts", "cli/src/lib/localModels*.ts",+ "cli/src/lib/gridFleetRpc*.ts"),+ "cli-serial": dict(command="npx vitest run src/cable/serial.real.spec.ts --maxWorkers=1", cwd="cli", platform="macos",+ paths=("cli/src/cable/serial*.ts", "cli/src/cable/windowsSerial*.ts", "cli/src/cable/__fixtures__/serial*")),+ "cli-pty": dict(command="npm run test:terminal-contract", cwd="cli", platform="macos",+ paths=("cli/src/lib/ptyHost*", "cli/src/lib/tmuxBackend*", "cli/src/lib/terminalBackend*",+ "pty/*", "term/*", "tui/vendor/*")),+ "cli-shell": dict(command="RUN_REAL_TMUX_DISCOVERY=1 npx vitest run src/lib/engineShellStartup.spec.ts --maxWorkers=1",+ cwd="cli", platform="macos", paths=("cli/src/lib/engineLaunch*.ts", "cli/src/lib/engineShellStartup*.ts",+ "cli/src/lib/engineShell*.ts", "cli/src/lib/zsh*.ts",+ "cli/src/lib/loginShellEnv*.ts", "cli/src/lib/userShell*.ts",+ "cli/src/lib/shellQuote*.ts")),+ "desktop-macos": dict(command="make desktop-test", cwd=".", platform="macos",+ paths=("desktop/macos/*", "desktop/lib/*/mac_*.dart", "desktop/lib/*/macos*.dart",+ "desktop/test/macos*.dart", "desktop/pubspec.yaml", "desktop/pubspec.lock")),+}+CLI_SHARED = ("cli/package.json", "cli/package-lock.json", "cli/vitest.config.ts", "cli/vitest.setup.ts",+ "cli/vitest.tmpdir.ts", "cli/tsconfig*.json", "cli/.node-version", "cli/.nvmrc")+FENCE = re.compile(r"^```harness-local-checks\s*\n(.*?)^```[ \t]*$", re.MULTILINE | re.DOTALL)+++def required_checks(paths):+ selected = set()+ for path in paths:+ if not isinstance(path, str) or not path or path.startswith("/") or ".." in path.split("/"):+ raise ValueError("invalid local check input path")+ selected.update(name for name, check in CHECKS.items() if any(fnmatchcase(path, p) for p in check["paths"]))+ if any(fnmatchcase(path, p) for p in CLI_SHARED):+ selected.update(name for name in CHECKS if name.startswith("cli-"))+ return sorted(selected)+++def planned_checks(plan):+ required = required_checks(plan.get("paths", [])) if plan.get("event") == "pull_request" else []+ if plan.get("local_checks", []) != required:+ raise ValueError("CI plan has incomplete local check coverage")+ return required+++def missing(required):+ # Only known names/commands are printed, never arbitrary PR content.+ return ValueError("Missing or invalid local check receipts: " + ", ".join(required)+ + ". Add the exact-head harness-local-checks JSON receipt before PR validation; use --list for commands.")+++def validate_receipts(required, receipts, head):+ if not required:+ return []+ if not isinstance(head, str) or not re.fullmatch(r"[0-9a-f]{40}", head):+ raise ValueError("invalid local check head")+ if not isinstance(receipts, list) or len(receipts) > 32:+ raise missing(required)+ found = {}+ for item in receipts:+ if not isinstance(item, dict) or not isinstance(item.get("check"), str):+ raise missing(required)+ name = item["check"]+ if name not in CHECKS or name in found:+ raise missing(required)+ contract = CHECKS[name]+ command = item.get("command")+ # Worker caps change resource use, not test selection or coverage. Reject+ # all other suffixes rather than accepting narrowed/disabled test runs.+ command_ok = isinstance(command, str) and re.fullmatch(+ re.escape(contract["command"]) + r"(?: -- --maxWorkers(?:=| )[1-9][0-9]?)?", command)+ if (item.get("head") != head or item.get("status") != "passed"+ or type(item.get("passed")) is not int or item["passed"] <= 0+ or not command_ok or item.get("cwd") != contract["cwd"]+ or item.get("platform") not in ("macos", "linux", "windows")+ or (contract["platform"] and item["platform"] != contract["platform"])):+ raise missing(required)+ found[name] = {key: item[key] for key in ("check", "command", "cwd", "head", "status", "passed", "platform")}+ absent = sorted(set(required) - set(found))+ if absent:+ raise missing(absent)+ return [found[name] for name in required]+++def check(plan, event):+ required = planned_checks(plan)+ if plan.get("event") != "pull_request":+ return []+ pr = event.get("pull_request", {})+ if pr.get("head", {}).get("sha") != plan.get("head"):+ raise ValueError("local check event differs from planned head")+ if plan.get("draft") is True or not required:+ return []+ body = pr.get("body") or ""+ if not isinstance(body, str) or len(body) > 65536:+ raise missing(required)+ blocks = FENCE.findall(body)+ if len(blocks) != 1:+ raise missing(required)+ try:+ receipts = json.loads(blocks[0])+ except (ValueError, RecursionError):+ raise missing(required) from None+ return validate_receipts(required, receipts, plan["head"])+++def main():+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--list", nargs="+", metavar="PATH")+ args = parser.parse_args()+ if args.list:+ print(json.dumps({name: {k: v for k, v in CHECKS[name].items() if k != "paths"}+ for name in required_checks(args.list)}, indent=2))+ return+ plan = json.loads(os.environ["CI_PLAN"])+ if plan.get("head") != os.environ["CI_SOURCE_SHA"] or plan.get("event") != os.environ["GITHUB_EVENT_NAME"]:+ raise ValueError("local check source differs from CI plan")+ records = check(plan, json.loads(Path(os.environ["GITHUB_EVENT_PATH"]).read_text()))+ with open(os.environ["GITHUB_OUTPUT"], "a") as output:+ output.write("local_receipts=" + json.dumps(records, separators=(",", ":")) + "\n")+ print(f"Local check receipts verified: {len(records)}")+++if __name__ == "__main__":+ try:+ main()+ except (ValueError, KeyError, TypeError, OSError):+ # The validation errors contain only fixed copy/known check ids. JSON and+ # IO errors can contain PR text or paths, so do not print their payloads.+ error = sys.exc_info()[1]+ message = str(error)+ if not message.startswith(("Missing or invalid local check receipts:", "CI plan has incomplete local check",+ "local check ", "invalid local check")):+ message = "Invalid local check input; no receipt accepted."+ print(message, file=sys.stderr)+ sys.exit(1)diff --git a/scripts/tests/test_ci_plan.py b/scripts/tests/test_ci_plan.pyindex a3fd8df92..5c42517a2 100644--- a/scripts/tests/test_ci_plan.py+++ b/scripts/tests/test_ci_plan.py@@ -873,6 +873,7 @@ class MainPlannerTests(unittest.TestCase):(self.root / "scripts").mkdir(exist_ok=True)(self.root / "scripts/ci-plan.py").write_text(planner_source)(self.root / "scripts/record-ci-validation.py").write_text((scripts / "record-ci-validation.py").read_text())+ (self.root / "scripts/local-checks.py").write_text((scripts / "local-checks.py").read_text())self.git("add", "-A")self.git("commit", "-qm", "main")return self.git("rev-parse", "HEAD")diff --git a/scripts/tests/test_local_checks.py b/scripts/tests/test_local_checks.pynew file mode 100644index 000000000..f56194d62--- /dev/null+++ b/scripts/tests/test_local_checks.py@@ -0,0 +1,207 @@+import importlib.util+import json+import os+from pathlib import Path+import subprocess+import sys+import tempfile+import unittest++SCRIPTS = Path(__file__).resolve().parents[1]+spec = importlib.util.spec_from_file_location("local_receipt_planner", SCRIPTS / "ci-plan.py")+planner = importlib.util.module_from_spec(spec)+spec.loader.exec_module(planner)+++def receipt(check="cli-core", **changes):+ return dict(dict(check=check, command="npm run test:core", cwd="cli", head="a" * 40,+ passed=12, status="passed", platform="macos"), **changes)+++def plan(paths=("cli/src/core/agents/create.ts",), **changes):+ return dict(dict(schema=1, kind="ci-plan", event="pull_request", draft=False, head="a" * 40,+ tree="b" * 40, base="c" * 40, paths=list(paths), suites=["cli"], reused={},+ required_jobs=["cli-tests", "cli-typecheck", "process-checks"], local_checks=["cli-core"]), **changes)+++def needs(receipts=None):+ result = {name: dict(result="success") for name in ("plan", "process-checks", "cli-tests", "cli-typecheck")}+ if receipts is not None:+ result["process-checks"]["outputs"] = dict(local_receipts=json.dumps(receipts))+ return result+++class LocalGateTests(unittest.TestCase):+ def test_shell_environment_and_quoting_changes_require_native_startup_evidence(self):+ for name in ("loginShellEnv", "userShell", "shellQuote"):+ with self.subTest(name=name):+ self.assertEqual(planner.local_checks.required_checks([f"cli/src/lib/{name}.ts"]), ["cli-shell"])++ def test_a_mapped_pr_cannot_pass_ci_required_without_local_evidence(self):+ with self.assertRaisesRegex(ValueError, "cli-core"):+ planner.verify(plan(), needs(), "a" * 40)++ def test_a_passing_receipt_is_retained_in_the_ci_required_artifact(self):+ result = planner.verify(plan(), needs([receipt()]), "a" * 40)+ self.assertEqual(result.get("local_receipts"), [receipt()])++ def test_bad_evidence_never_satisfies_the_gate(self):+ for change in [dict(head="d" * 40), dict(head="a" * 7), dict(passed=0), dict(passed=-1),+ dict(passed=True), dict(passed="12"), dict(status="failed"), dict(status="skipped"),+ dict(command="npm run test:core -- --testNamePattern one"), dict(cwd="backend"),+ dict(platform="unknown")]:+ with self.subTest(change=change), self.assertRaisesRegex(ValueError, "cli-core"):+ planner.verify(plan(), needs([receipt(**change)]), "a" * 40)++ def test_a_missing_requirement_cannot_be_removed_from_the_plan(self):+ with self.assertRaisesRegex(ValueError, "local check"):+ planner.verify(plan(local_checks=[]), needs([]), "a" * 40)++ def test_the_required_macos_check_cannot_use_a_linux_receipt(self):+ p = plan(["desktop/macos/Runner/MainFlutterWindow.swift"], local_checks=["desktop-macos"])+ r = receipt("desktop-macos", command="make desktop-test", cwd=".", platform="linux")+ with self.assertRaisesRegex(ValueError, "desktop-macos"):+ planner.verify(p, needs([r]), "a" * 40)++ def test_multiple_checks_need_all_receipts(self):+ p = plan(["cli/src/core/api.ts", "cli/src/harnessd/main.ts"], local_checks=["cli-core", "cli-harnessd"])+ with self.assertRaisesRegex(ValueError, "cli-harnessd"):+ planner.verify(p, needs([receipt()]), "a" * 40)++ def test_unmapped_manual_and_merge_group_runs_keep_their_contract(self):+ for p in [plan(["README.md"], local_checks=[]), plan(event="merge_group", local_checks=[]),+ plan(event="workflow_dispatch", local_checks=[])]:+ with self.subTest(event=p["event"]):+ self.assertEqual(planner.verify(p, needs(), "a" * 40)["status"], "passed")+++class LocalProcessTests(unittest.TestCase):+ def setUp(self):+ self.temp = tempfile.TemporaryDirectory()+ self.addCleanup(self.temp.cleanup)+ self.root = Path(self.temp.name)++ def run_check(self, body, p=None, event_head=None):+ p = p or plan()+ event = self.root / "event.json"+ output = self.root / "output"+ output.write_text("")+ event.write_text(json.dumps(dict(pull_request=dict(head=dict(sha=event_head or p["head"]), body=body))))+ env = dict(os.environ, CI_PLAN=json.dumps(p), CI_SOURCE_SHA=p["head"], GITHUB_EVENT_PATH=str(event),+ GITHUB_EVENT_NAME=p["event"], GITHUB_OUTPUT=str(output))+ result = subprocess.run([sys.executable, str(SCRIPTS / "local-checks.py")], env=env,+ cwd=self.root, text=True, capture_output=True, timeout=10)+ return result, output.read_text()++ @staticmethod+ def body(receipts):+ return "Unrelated PR prose\n```harness-local-checks\n" + json.dumps(receipts) + "\n```\n"++ def test_the_process_check_fails_with_a_missing_list_and_passes_with_the_receipt(self):+ result, output = self.run_check("Tests pass, trust me")+ self.assertEqual(result.returncode, 1, result.stderr)+ self.assertIn("cli-core", result.stdout + result.stderr)+ self.assertEqual(output, "")+ result, output = self.run_check(self.body([receipt()]))+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertEqual(json.loads(output.removeprefix("local_receipts=")), [receipt()])++ def test_receipt_text_is_data_never_a_command_or_error_payload(self):+ marker = self.root / "must-not-exist"+ secret = "private-content-do-not-echo"+ bad = receipt(command=f"touch {marker}; echo {secret}")+ result, _ = self.run_check(self.body([bad]))+ self.assertEqual(result.returncode, 1)+ self.assertFalse(marker.exists())+ self.assertNotIn(secret, result.stdout + result.stderr)++ def test_malformed_duplicate_overlarge_and_ambiguous_evidence_is_rejected(self):+ for body in ["```harness-local-checks\nnot json\n```", self.body([receipt(), receipt()]),+ self.body([receipt()]) * 2, self.body([receipt()] * 33), "x" * 65537,+ self.body({"not": "a list"}), self.body([None]), self.body([dict(head="a" * 40)])]:+ with self.subTest(length=len(body)):+ result, output = self.run_check(body)+ self.assertEqual(result.returncode, 1, result.stderr)+ self.assertEqual(output, "")++ def test_event_source_mismatch_fails_and_drafts_do_not_need_receipts(self):+ result, _ = self.run_check(self.body([receipt()]), event_head="f" * 40)+ self.assertEqual(result.returncode, 1)+ result, output = self.run_check("", plan(draft=True))+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertEqual(json.loads(output.removeprefix("local_receipts=")), [])+++class LocalMappingTests(unittest.TestCase):+ def setUp(self):+ self.temp = tempfile.TemporaryDirectory()+ self.addCleanup(self.temp.cleanup)+ self.root = Path(self.temp.name)+ self.git("init", "-q")+ self.git("config", "user.name", "Fixture")+ self.git("config", "user.email", "[email protected]")+ self.git("config", "maintenance.auto", "false")+ self.write("README.md")+ self.base = self.commit()++ def git(self, *args):+ return subprocess.check_output(["git", *args], cwd=self.root, text=True, stderr=subprocess.PIPE).strip()++ def write(self, path):+ target = self.root / path+ target.parent.mkdir(parents=True, exist_ok=True)+ target.write_text("fixture\n")++ def commit(self):+ self.git("add", ".")+ self.git("commit", "-qm", "fixture")+ return self.git("rev-parse", "HEAD")++ def select(self):+ head = self.git("rev-parse", "HEAD")+ event = dict(pull_request=dict(head=dict(sha=head), base=dict(sha=self.base)))+ return planner.make_plan(self.root, "pull_request", event, source=head)++ def test_each_local_area_is_selected_from_real_git_paths(self):+ cases = {+ "cli/src/core/agents/create.ts": ["cli-core"], "cli/src/services/edge.ts": ["cli-core"],+ "cli/src/harnessd/start.spec.ts": ["cli-harnessd"], "cli/src/lib/resumeStoppedAgent.ts": ["cli-resume"],+ "cli/src/orchestrator/main.ts": ["cli-orchestrator"], "cli/src/sharing/permissions.ts": ["cli-sharing"],+ "cli/src/lib/viewerForwarder.ts": ["cli-remote-viewers"], "cli/src/dsh/materialize.ts": ["cli-portability"],+ "cli/src/lib/localModels.ts": ["cli-local-models"], "cli/src/cable/serial.real.spec.ts": ["cli-serial"],+ "cli/src/lib/tmuxBackend.ts": ["cli-pty"], "cli/src/lib/ptyHost/stream.ts": ["cli-pty"],+ "pty/src/lib.rs": ["cli-pty"], "term/src/grid.rs": ["cli-pty"],+ "cli/src/lib/engineLaunch.ts": ["cli-shell"],+ "desktop/macos/Runner/MainFlutterWindow.swift": ["desktop-macos"],+ "desktop/test/macos_microphone_permission_test.dart": ["desktop-macos"],+ "desktop/lib/core/mac_responsibility_probe_native.dart": ["desktop-macos"],+ "cli/vitest.core.config.ts": ["cli-core"], "cli/vitest.viewer.config.ts": ["cli-remote-viewers"],+ "docs/guide.md": [], "cli/src/superTabs/cards.ts": [], "desktop/windows/runner/main.cpp": [],+ "cli/src/lib/viewerForwarderNote.md": [], "cli/src/coreish/other.ts": [],+ }+ for path, expected in cases.items():+ with self.subTest(path=path):+ self.git("reset", "--hard", self.base)+ self.write(path)+ self.commit()+ self.assertEqual(self.select().get("local_checks"), expected)++ def test_dependency_changes_require_every_cli_check(self):+ self.write("cli/package-lock.json")+ self.commit()+ self.assertEqual(self.select().get("local_checks"), ["cli-core", "cli-harnessd", "cli-local-models",+ "cli-orchestrator", "cli-portability", "cli-pty", "cli-remote-viewers", "cli-resume",+ "cli-serial", "cli-sharing", "cli-shell"])++ def test_deletes_and_renames_cannot_drop_the_old_area_even_when_sparse(self):+ self.write("cli/src/core/old.ts")+ self.base = self.commit()+ (self.root / "cli/src/core/old.ts").unlink()+ self.write("cli/src/harnessd/moved.ts")+ self.commit()+ self.git("sparse-checkout", "set", "scripts")+ self.assertEqual(self.select().get("local_checks"), ["cli-core", "cli-harnessd"])+++if __name__ == "__main__":+ unittest.main()