diff --git a/.github/workflows/fullrun-compare.yml b/.github/workflows/fullrun-compare.yml index fd8a97dd..a11c2c80 100644 --- a/.github/workflows/fullrun-compare.yml +++ b/.github/workflows/fullrun-compare.yml @@ -1,8 +1,10 @@ -name: Compare six real patcher installations +name: Compare real patcher installations against the packaged patcher on: workflow_call: inputs: game: {type: string, required: true} + # JSON list of installed routes, e.g. '["cli","gui"]' or '["cli"]'. + modes: {type: string, default: '["cli","gui"]'} secrets: CACHE_ENCRYPTION_KEY: {required: true} DIAGNOSTICS_ENCRYPTION_KEY: {required: false} @@ -26,11 +28,12 @@ jobs: - name: Verify same-run provenance and compare every component and final tree env: GAME: ${{ inputs.game }} + MODES: ${{ join(fromJSON(inputs.modes), ',') }} GITHUB_TOKEN: ${{ github.token }} CACHE_ENCRYPTION_KEY: ${{ secrets.CACHE_ENCRYPTION_KEY }} run: | umask 077 - python tools/modsync-ci/patcher_comparison_artifacts.py --game "$GAME" \ + python tools/modsync-ci/patcher_comparison_artifacts.py --game "$GAME" --modes "$MODES" \ --work-dir "$RUNNER_TEMP/comparison-inputs" --output-dir "$RUNNER_TEMP/comparison-evidence" - name: Retain complete encrypted file differences if: ${{ success() || failure() }} diff --git a/.github/workflows/fullrun.yml b/.github/workflows/fullrun.yml index c2adc424..4a6ffde6 100644 --- a/.github/workflows/fullrun.yml +++ b/.github/workflows/fullrun.yml @@ -219,7 +219,9 @@ jobs: MOD_CACHE_S3_ENDPOINT: ${{ vars.MOD_CACHE_BUCKET && secrets.MOD_CACHE_S3_ENDPOINT || '' }} comparison: needs: [plan, install] - if: ${{ !cancelled() && (needs.plan.outputs.operation == 'full' || needs.plan.outputs.operation == 'install') && contains(fromJSON(needs.plan.outputs.modes || '[]'), 'cli') && contains(fromJSON(needs.plan.outputs.modes || '[]'), 'gui') }} + # Every installation plan runs all three patcher backends per route, so every + # one is compared against the packaged-patcher lane, for one route or both. + if: ${{ !cancelled() && (needs.plan.outputs.operation == 'full' || needs.plan.outputs.operation == 'install') }} strategy: fail-fast: false matrix: @@ -227,6 +229,7 @@ jobs: uses: ./.github/workflows/fullrun-compare.yml with: game: ${{ matrix.game }} + modes: ${{ needs.plan.outputs.modes }} secrets: CACHE_ENCRYPTION_KEY: ${{ secrets.CACHE_ENCRYPTION_KEY }} DIAGNOSTICS_ENCRYPTION_KEY: ${{ !vars.DIAGNOSTICS_ENCRYPTION_RECIPIENT && secrets.DIAGNOSTICS_ENCRYPTION_KEY || '' }} @@ -280,7 +283,7 @@ jobs: OPERATION: ${{ needs.plan.outputs.operation || 'check' }} REQUIRE_DOWNLOADER: ${{ needs.plan.outputs.release_candidate || 'false' }} REQUIRE_PRODUCTION: ${{ needs.plan.outputs.operation == 'full' || needs.plan.outputs.operation == 'install' }} - REQUIRE_COMPARISON: ${{ (needs.plan.outputs.operation == 'full' || needs.plan.outputs.operation == 'install') && contains(fromJSON(needs.plan.outputs.modes || '[]'), 'cli') && contains(fromJSON(needs.plan.outputs.modes || '[]'), 'gui') }} + REQUIRE_COMPARISON: ${{ needs.plan.outputs.operation == 'full' || needs.plan.outputs.operation == 'install' }} run: python tools/modsync-ci/fullrun_contract.py aggregate --operation "$OPERATION" --output "$RUNNER_TEMP/fullrun-result.json" - name: Retain public requested-scope verdict if: ${{ success() || failure() }} diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index e4ce33bb..99fa7eb2 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -5357,7 +5357,7 @@ The full installation matrix selects OdyPatcher, HoloPatcher and each mod's orig CI prints the actual ModSync commands and follows their stdout and stderr while they run. The desktop's `--stream-output` option includes complete installation events. Unix external process execution forwards child output to stderr while preserving structured CLI stdout. Public output is credential-redacted and prefixed against workflow-command injection. Complete raw logs are retained in encrypted diagnostics, with explicit resource limits reported as failures. Fresh patcher logs are also emitted when a process fails. Retained patcher output directories that may contain game files receive an additional envelope using the existing game-cache key before entering diagnostics. -The comparison exporter verifies committed production Store boundaries and records every game file's hash, size and permissions after each component and at completion. Six successful installations are judged against the lane that runs each mod's own packaged patcher (`mod-packaged`), which is authoritative: per route, OdyPatcher and HoloPatcher are each compared with `mod-packaged`, and the `mod-packaged` GUI route with its CLI route. Between backends on the same route, trees are compared after preparation, after every component that runs a Patcher operation, and at completion; a component without a patcher runs identical engine code in every backend lane and is not compared on its own. The CLI-versus-GUI pair installs every component through different code, so it is compared after every component. Any difference fails the comparison gate and names the non-authoritative lane as incorrect, with its first differing boundary. Missing lanes, failed execution and invalid evidence fail the comparison gate. Same-run encrypted manifests use the existing game-cache key for comparison access, while complete diagnostics and private differences use the independent diagnostics recipient. Hosted six-way installation and comparison verification remains pending. +The comparison exporter verifies committed production Store boundaries and records every game file's hash, size and permissions after each component and at completion. Every installation plan runs and requires this comparison, whether it installs one route (three lanes) or both (six lanes). A plan whose selected components run no Patcher operation fails the comparison as vacuous instead of passing. The installations are judged against the lane that runs each mod's own packaged patcher (`mod-packaged`), which is authoritative: per route, OdyPatcher and HoloPatcher are each compared with `mod-packaged`, and the `mod-packaged` GUI route with its CLI route. Between backends on the same route, trees are compared after preparation, after every component that runs a Patcher operation, and at completion; a component without a patcher runs identical engine code in every backend lane and is not compared on its own. The CLI-versus-GUI pair installs every component through different code, so it is compared after every component. Any difference fails the comparison gate and names the non-authoritative lane as incorrect, with its first differing boundary. Missing lanes, failed execution and invalid evidence fail the comparison gate. Same-run encrypted manifests use the existing game-cache key for comparison access, while complete diagnostics and private differences use the independent diagnostics recipient. Hosted six-way installation and comparison verification remains pending. Checkpoint ancestry validation streams full documents into a compact authenticated index. Selected documents are freshly checked against their complete digest, session identity and unchanged HEAD. Per-document bounds and all ancestry, definition-prefix, backend, finalization and lineage checks remain enforced. The aggregate validation budget supports full-guide histories above the former 256 MiB ceiling. The production `checkpoint export-history` command authenticates all finalized lineage boundaries and verifies each distinct content object once, then publishes a bounded file-backed index after checking unchanged session and HEAD identities. Comparison export uses this command instead of launching repeated whole-inventory verification. Actual full-guide coverage remains subject to the hosted installation gate. ### OdyPatcher source boundary and explicit executable selection diff --git a/tools/modsync-ci/patcher_comparison.py b/tools/modsync-ci/patcher_comparison.py index 694b7a00..9a25ffb4 100644 --- a/tools/modsync-ci/patcher_comparison.py +++ b/tools/modsync-ci/patcher_comparison.py @@ -410,12 +410,14 @@ def differences(left, right): return changes -def comparison_pairs(): +def comparison_pairs(modes=MODES): """(reference, candidate) cells. Each backend is held against the packaged-patcher - lane of the same route; the packaged GUI route is held against its CLI route.""" - pairs = [((AUTHORITY, mode), (backend, mode)) for mode in MODES + lane of the same route; when both routes ran, the packaged GUI route is held + against its CLI route.""" + pairs = [((AUTHORITY, mode), (backend, mode)) for mode in modes for backend in BACKENDS if backend != AUTHORITY] - pairs.append(((AUTHORITY, "cli"), (AUTHORITY, "gui"))) + if set(modes) == set(MODES): + pairs.append(((AUTHORITY, "cli"), (AUTHORITY, "gui"))) return pairs @@ -435,13 +437,17 @@ def route_boundaries(keys): return [key for key in keys if key != "sessionBaseline"] -def judge(trees, operations, load_tree): +def judge(trees, operations, load_tree, modes=MODES): """Compare every candidate lane with its reference after each relevant component. trees maps (backend, mode) to an ordered {boundary key: handle}; load_tree(handle) returns that boundary's game tree. Returns (comparisons, wrong_lanes).""" + # With no Patcher operation, every lane installs the same instructions with no + # patcher in play, so equal trees would prove nothing about any patcher. + require(operations, "No selected component runs a Patcher operation; the patcher " + "comparison would be vacuous") comparisons, wrong = [], [] - for reference, candidate in comparison_pairs(): + for reference, candidate in comparison_pairs(modes): ordered = list(trees[reference]) keys = (route_boundaries(ordered) if reference[0] == candidate[0] else patcher_boundaries(ordered, operations)) @@ -483,7 +489,11 @@ def verdict(wrong, game): def compare(args): - require(len(args.receipt) == 6, "Exactly six independently exported receipts are required") + modes = tuple(getattr(args, "modes", None) or MODES) + require(modes and set(modes) <= set(MODES) and len(set(modes)) == len(modes), "Unsupported route set") + expected_cells = len(BACKENDS) * len(modes) + require(len(args.receipt) == expected_cells, + f"Exactly {expected_cells} independently exported receipts are required") lanes = [] cells = set() for path in map(Path, args.receipt): @@ -501,7 +511,7 @@ def compare(args): and re.fullmatch(r"[0-9a-f]{40}", receipt["engine_sha"]) is not None, "Invalid source or engine digest") cell = (receipt["backend"], receipt["mode"]) - require(cell in set(itertools.product(BACKENDS, MODES)) and cell not in cells, + require(cell in set(itertools.product(BACKENDS, modes)) and cell not in cells, "Repeated or unsupported comparison cell") cells.add(cell) root = path.parent @@ -594,19 +604,19 @@ def compare(args): require(trees["sessionBaseline"][1]["game_tree_sha256"] == receipt["baseline_game_tree_sha256"] and list(trees.values())[-1][1]["game_tree_sha256"] == receipt["final_game_tree_sha256"], "Baseline or final tree digest differs") - require(len({lane[0]["session_chain"][-1]["session_id"] for lane in lanes}) == 6, - "Six cells reused an installation session") - for mode in MODES: + require(len({lane[0]["session_chain"][-1]["session_id"] for lane in lanes}) == expected_cells, + "Comparison cells reused an installation session") + for mode in modes: require(len({receipt["binary_sha256"] for receipt, _ in lanes if receipt["mode"] == mode}) == 1, "Backend cells used different binaries for the same route") output = Path(args.output_dir) output.mkdir(mode=0o700, parents=True, exist_ok=False) cells = {(receipt["backend"], receipt["mode"]): (receipt, trees) for receipt, trees in lanes} - authority = cells[(AUTHORITY, MODES[0])][0] + authority = cells[(AUTHORITY, modes[0])][0] require(all(receipt["patcher_operations"] == authority["patcher_operations"] for receipt, _ in lanes), "Lanes disagree on which components run a Patcher operation") comparisons, wrong = judge({cell: trees for cell, (_, trees) in cells.items()}, - authority["patcher_operations"], load_boundary) + authority["patcher_operations"], load_boundary, modes) total, pairs = 0, [] for pair_index, result in enumerate(comparisons): pair = {"reference": result["reference"], "candidate": result["candidate"], "boundaries": []} @@ -627,7 +637,7 @@ def compare(args): pairs.append(pair) write(output / "private-diff.json", {"schema": SCHEMA, "game": first["game"], "authority": AUTHORITY, "pairs": pairs}) - write(output / "summary.json", {"schema": SCHEMA, "game": first["game"], "cells": 6, + write(output / "summary.json", {"schema": SCHEMA, "game": first["game"], "cells": expected_cells, "modes": list(modes), "pairs": len(pairs), "differences": total, "equal": total == 0, "authority": AUTHORITY, "wrong_lanes": wrong, "patcher_components": len({str(op[0]).lower() for op in @@ -650,6 +660,8 @@ def main(): capture.add_argument("--mode", required=True, choices=MODES) comparison = sub.add_parser("compare") comparison.add_argument("--receipt", action="append", required=True) + comparison.add_argument("--mode", dest="modes", action="append", choices=MODES, + help="installed route; repeat for both (default: cli and gui)") comparison.add_argument("--output-dir", required=True) args = parser.parse_args() try: diff --git a/tools/modsync-ci/patcher_comparison_artifacts.py b/tools/modsync-ci/patcher_comparison_artifacts.py index f1cd17c1..32988ac8 100644 --- a/tools/modsync-ci/patcher_comparison_artifacts.py +++ b/tools/modsync-ci/patcher_comparison_artifacts.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 -"""Authenticate six current-run encrypted comparison exports and compare them.""" +"""Authenticate the current run's encrypted comparison exports (three backends per +installed route) and compare them.""" import argparse import contextlib @@ -97,7 +98,7 @@ def validate_artifact(artifact, name, repository, expected, source): "Comparison artifact belongs to another source/run/repository") -def selected_artifacts(api, repository, expected, source, game): +def selected_artifacts(api, repository, expected, source, game, modes=comparison.MODES): found = [] for page in range(1, 21): response = api.get(f"/actions/runs/{expected['run_id']}/artifacts?per_page=100&page={page}") @@ -113,7 +114,7 @@ def selected_artifacts(api, repository, expected, source, game): else: raise ValueError("Run artifact pagination exceeded bound") selected = [] - for backend, mode in itertools.product(comparison.BACKENDS, comparison.MODES): + for backend, mode in itertools.product(comparison.BACKENDS, modes): name = artifact_name(game, backend, mode, expected) matches = [artifact for artifact in found if artifact.get("name") == name] require(len(matches) == 1, "Missing or duplicate current comparison cell artifact") @@ -124,7 +125,7 @@ def selected_artifacts(api, repository, expected, source, game): require(all(fresh[key] == artifact[key] for key in ("id", "name", "digest", "size_in_bytes", "workflow_run")), "Comparison artifact metadata changed before download") selected.append((backend, mode, fresh)) - require(len({artifact["id"] for _, _, artifact in selected}) == 6, + require(len({artifact["id"] for _, _, artifact in selected}) == len(comparison.BACKENDS) * len(modes), "Comparison cells reused an artifact") return selected @@ -355,7 +356,12 @@ def main(): parser.add_argument("--game", required=True, choices=("k1", "k2")) parser.add_argument("--work-dir", required=True) parser.add_argument("--output-dir", required=True) + parser.add_argument("--modes", default=",".join(comparison.MODES), + help="comma-separated routes the run installed (cli, gui or both)") args = parser.parse_args() + modes = tuple(mode for mode in comparison.MODES if mode in args.modes.split(",")) + if not modes or len(modes) != len(set(args.modes.split(","))): + parser.error("--modes must name cli, gui or both") os.umask(0o077) try: expected, source = expected_identity(os.environ) @@ -364,7 +370,7 @@ def main(): work.mkdir(mode=0o700, parents=True) api = API() repository, _ = validate_run(api, expected, source, os.environ) - artifacts = selected_artifacts(api, repository, expected, source, args.game) + artifacts = selected_artifacts(api, repository, expected, source, args.game, modes) client = ArtifactsClient(REPOSITORY, os.environ["GITHUB_TOKEN"]) receipts, retained = [], [] for backend, mode, artifact in artifacts: @@ -398,7 +404,8 @@ def main(): comparison.write(work / "artifact-receipts.json", {"identity": expected, "artifacts": retained}) with (work / "comparison-events.jsonl").open("x", encoding="utf-8") as events: with contextlib.redirect_stdout(events): - result = comparison.compare(argparse.Namespace(receipt=receipts, output_dir=str(output))) + result = comparison.compare(argparse.Namespace(receipt=receipts, output_dir=str(output), + modes=modes)) with (work / "comparison-events.jsonl").open(encoding="utf-8") as events: for line in events: value = json.loads(line) diff --git a/tools/modsync-ci/test_fullrun_workflows.py b/tools/modsync-ci/test_fullrun_workflows.py index 295319dd..2a84de9d 100644 --- a/tools/modsync-ci/test_fullrun_workflows.py +++ b/tools/modsync-ci/test_fullrun_workflows.py @@ -30,6 +30,17 @@ def test_every_local_workflow_action_and_python_entrypoint_exists(self): self.assertTrue((ROOT / action[2:] / "action.yml").is_file()) for tool in re.findall(r"tools/modsync-ci/[A-Za-z0-9_-]+\.py", step.get("run", "")): self.assertTrue((ROOT / tool).is_file(), tool) + def test_every_installation_plan_runs_and_requires_the_patcher_comparison(self): + # A single-route dispatch still runs all three backends, so it must still be + # compared against the packaged lane rather than pass as "unverified". + main = yaml.load((ROOT / ".github/workflows/fullrun.yml").read_text(), Loader=yaml.BaseLoader) + comparison = main["jobs"]["comparison"] + self.assertNotIn("modes", comparison["if"]) + self.assertEqual(comparison["with"]["modes"], "${{ needs.plan.outputs.modes }}") + required = main["jobs"]["result"]["steps"][1]["env"]["REQUIRE_COMPARISON"] + self.assertNotIn("modes", required) + self.assertIn("install", required) + def test_matrix_has_no_fail_fast_and_honest_final_collector(self): main = yaml.load((ROOT / ".github/workflows/fullrun.yml").read_text(), Loader=yaml.BaseLoader) self.assertEqual(main["jobs"]["install"]["strategy"]["fail-fast"], "false") diff --git a/tools/modsync-ci/test_patcher_comparison.py b/tools/modsync-ci/test_patcher_comparison.py index f2f77237..66eb7e61 100644 --- a/tools/modsync-ci/test_patcher_comparison.py +++ b/tools/modsync-ci/test_patcher_comparison.py @@ -1,3 +1,4 @@ +import argparse import contextlib import hashlib import io @@ -89,10 +90,20 @@ def test_a_difference_inside_a_component_without_a_patcher_is_not_compared_on_it keys = [b["key"] for b in comparisons[0]["boundaries"]] self.assertNotIn(f"component/{PLAIN}/1", keys) - def test_a_guide_without_patcher_operations_compares_only_the_final_tree(self): - comparisons, wrong = run(lanes(), operations=[]) - self.assertEqual(wrong, []) - self.assertEqual([b["key"] for b in comparisons[0]["boundaries"]], ["final"]) + def test_a_plan_with_no_patcher_operation_is_refused_as_vacuous(self): + with self.assertRaisesRegex(ValueError, "vacuous"): + run(lanes(), operations=[]) + + def test_a_single_route_plan_compares_each_backend_with_the_packaged_lane_of_that_route(self): + self.assertEqual(pc.comparison_pairs(("cli",)), [ + (("mod-packaged", "cli"), ("ody-patcher", "cli")), + (("mod-packaged", "cli"), ("holo-patcher", "cli")), + ]) + cells = {cell: trees for cell, trees in lanes().items() if cell[1] == "gui"} + cells[("holo-patcher", "gui")] = dict(cells[("holo-patcher", "gui")], + **{f"component/{PATCHED}/1": tree(**{"override/a.2da": "drift"})}) + _, wrong = pc.judge(cells, OPERATIONS, lambda handle: handle, ("gui",)) + self.assertEqual([w["lane"] for w in wrong], [["holo-patcher", "gui"]]) def test_the_route_pair_compares_every_component_and_does_not_repeat_the_final_tree(self): comparisons, _ = run(lanes()) @@ -139,6 +150,13 @@ def test_verdict_fails_and_names_the_incorrect_lane_with_its_route(self): self.assertIn("::error", err.getvalue()) self.assertIn("mod-packaged (gui) is the incorrect lane", err.getvalue()) + def test_compare_requires_three_receipts_per_installed_route(self): + for modes, receipts, expected in ((("cli",), 6, "Exactly 3"), (None, 3, "Exactly 6")): + with self.assertRaisesRegex(ValueError, expected): + pc.compare(argparse.Namespace(receipt=["r"] * receipts, output_dir="unused", modes=modes)) + with self.assertRaisesRegex(ValueError, "Unsupported route set"): + pc.compare(argparse.Namespace(receipt=["r"] * 3, output_dir="unused", modes=("tui",))) + def test_verdict_passes_when_every_lane_agrees(self): with contextlib.redirect_stderr(io.StringIO()) as err: self.assertEqual(pc.verdict([], "k1"), 0)