ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
hook_parity_mutations.py
Go to the documentation of this file.
1# SPDX-License-Identifier: MIT
2# Copyright (c) 2026 Brighton Sikarskie
3"""Structural mutation fixtures for hook control-plane parity self-tests."""
4
5from __future__ import annotations
6
7
8def _owner_mutations(
9 pre_commit: str, hooks: str, ci_script: str, gate_sources: tuple[str, ...]
10) -> tuple[tuple[str, str, str, tuple[str, ...]], ...]:
11 """Return mutations of the self-contained owner bootstrap."""
12 return (
13 (
14 pre_commit.replace("set -euo pipefail\n", "set -euo pipefail\nexit 0\n", 1),
15 hooks,
16 ci_script,
17 gate_sources,
18 ),
19 (
20 pre_commit.replace("capture_source\n", "exit 0\n capture_source\n", 1),
21 hooks,
22 ci_script,
23 gate_sources,
24 ),
25 (
26 pre_commit.replace(
27 'PATH="$RA8_OWNER_PATH"',
28 'PATH="$SOURCE_ROOT/.venv/bin:$PATH"',
29 1,
30 ),
31 hooks,
32 ci_script,
33 gate_sources,
34 ),
35 (
36 pre_commit.replace("start_new_session=True", "start_new_session=False", 1),
37 hooks,
38 ci_script,
39 gate_sources,
40 ),
41 (
42 pre_commit.replace("os.killpg(process.pid, signum)", "pass", 1),
43 hooks,
44 ci_script,
45 gate_sources,
46 ),
47 (pre_commit.replace('wait "$pid"', "true", 1), hooks, ci_script, gate_sources),
48 (
49 pre_commit.replace("verify_source_unchanged", "true", 1),
50 hooks,
51 ci_script,
52 gate_sources,
53 ),
54 (
55 pre_commit.replace('"$OWNER_JUST" \\\n', '"$OWNER_BASH" \\\n "$OWNER_JUST" \\\n', 1),
56 hooks,
57 ci_script,
58 gate_sources,
59 ),
60 )
61
62
63def _hook_mutations(
64 pre_commit: str, hooks: str, ci_script: str, gate_sources: tuple[str, ...]
65) -> tuple[tuple[str, str, str, tuple[str, ...]], ...]:
66 """Return candidate early-success, dead-loop, and ordering mutations."""
67 return (
68 (
69 pre_commit,
70 hooks.replace("#!/bin/bash -p", "#!/usr/bin/env bash", 1),
71 ci_script,
72 gate_sources,
73 ),
74 (
75 pre_commit,
76 hooks.replace("#!/bin/bash -p", "#!/usr/bin/env bash"),
77 ci_script,
78 gate_sources,
79 ),
80 (
81 pre_commit,
82 hooks.replace(" gates=(", " exit 0\n gates=(", 1),
83 ci_script,
84 gate_sources,
85 ),
86 (
87 pre_commit,
88 hooks.replace(
89 " gates=(",
90 " python3 scripts/git/write-proof.py /tmp/forged\n gates=(",
91 1,
92 ),
93 ci_script,
94 gate_sources,
95 ),
96 (
97 pre_commit,
98 hooks.replace(' run_gate "$gate"', " true", 1),
99 ci_script,
100 gate_sources,
101 ),
102 (
103 pre_commit,
104 hooks.replace(
105 ' for gate in "${gates[@]}"; do\n run_gate "$gate"\n done',
106 ' if false; then\n for gate in "${gates[@]}"; do\n'
107 ' run_gate "$gate"\n done\n fi',
108 1,
109 ),
110 ci_script,
111 gate_sources,
112 ),
113 (
114 pre_commit,
115 hooks.replace(
116 " ascii\n copyright", " copyright\n ascii", 1
117 ),
118 ci_script,
119 gate_sources,
120 ),
121 )
122
123
124def _ci_mutations(
125 pre_commit: str, hooks: str, ci_script: str, gate_sources: tuple[str, ...]
126) -> tuple[tuple[str, str, str, tuple[str, ...]], ...]:
127 """Return early dispatch and candidate proof-capability mutations."""
128 return (
129 (
130 pre_commit,
131 hooks,
132 ci_script.replace("set -euo pipefail\n", "set -euo pipefail\nexit 0\n", 1),
133 gate_sources,
134 ),
135 (
136 pre_commit,
137 hooks,
138 "if [[ $1 == --staged-hook ]]; then exit 0; fi\n" + ci_script,
139 gate_sources,
140 ),
141 (
142 pre_commit,
143 hooks,
144 ci_script.replace('run_gate_capture "$gate"', "RA8_GATE_RC=0", 1),
145 gate_sources,
146 ),
147 (
148 pre_commit,
149 hooks,
150 "RA8_STAGED_GATE_PROOF=/tmp/forged\n" + ci_script,
151 gate_sources,
152 ),
153 )
154
155
156def mutation_cases(
157 pre_commit: str, hooks: str, ci_script: str, gate_sources: tuple[str, ...]
158) -> tuple[tuple[str, str, str, tuple[str, ...]], ...]:
159 """Return every historical early-success bypass and proof mutation."""
160 common = (pre_commit, hooks, ci_script, gate_sources)
161 gate_exit = ("exit 0\n" + gate_sources[0], *gate_sources[1:])
162 return (
163 *_owner_mutations(*common),
164 *_hook_mutations(*common),
165 *_ci_mutations(*common),
166 (pre_commit, hooks, ci_script, gate_exit),
167 )