123# Markdown field fixtures intentionally keep backticks literal.4# shellcheck disable=SC20165set -euo pipefail67script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"8validator="$script_dir/hardware-matrix.sh"9fixture_root="$(mktemp -d "${TMPDIR:-/tmp}/goq-hardware-matrix.XXXXXX")"1011cleanup() {12 rm -rf -- "$fixture_root"13}14trap cleanup EXIT1516fail() {17 printf 'hardware matrix fixture test failed: %s\n' "$*" >&218 exit 119}2021sha256_file() {22 local path="$1"2324 if command -v sha256sum >/dev/null 2>&1; then25 sha256sum "$path" | awk '{print $1}'26 else27 shasum -a 256 "$path" | awk '{print $1}'28 fi29}3031write_evidence() {32 local path="$1"33 local row_id="$2"34 local commit="$3"35 local os_family="$4"36 local topology="$5"37 local connector_state="$6"38 local native_width="$7"39 local native_height="$8"4041 printf '%s\n' \42 'schema=goq-hardware-matrix-evidence-v1' \43 "matrix_row=$row_id" \44 "exact_commit=$commit" \45 'workflow_run_id=29999999999' \46 "host_model=Fixture $row_id" \47 "os_family=$os_family" \48 "gpu_topology=$topology" \49 "connector_state=$connector_state" \50 "native_width=$native_width" \51 "native_height=$native_height" \52 'native_refresh_millihz=60000' \53 'os_version=fixture-os-1' \54 'kernel_version=fixture-kernel-1' \55 'gamescope_version=fixture-gamescope-1' \56 'mesa_version=fixture-mesa-1' \57 'gstreamer_version=fixture-gstreamer-1' \58 'encoder_plugin_version=fixture-encoder-1' \59 'render_node=/dev/dri/renderD129' \60 'encoder_factory=varenderD129h264enc' \61 'fixed_capture_result=pass' \62 'fixed_capture_fps_milli=60000' \63 'fixed_post_encode_drops=0' \64 'native_capture_result=pass' \65 'native_capture_fps_milli=60000' \66 'native_post_encode_drops=0' \67 'portal_transport=iroh-moq' \68 'portal_video=pass' \69 'portal_audio=pass' \70 'portal_input=pass' \71 'portal_reconnect=pass' \72 'portal_second_client_rejection=pass' \73 'restoration=pass' \74 >"$path"75}7677write_report() {78 local path="$1"79 local row_id="$2"80 local commit="$3"81 local artifact_set="$4"82 local manifest="$5"83 local evidence="$6"8485 {86 printf '# Fixture hardware report\n\n'87 printf -- '- Matrix row: `%s`\n' "$row_id"88 printf -- '- Exact commit: `%s`\n' "$commit"89 printf -- '- Workflow run: `29999999999`\n'90 printf -- '- Candidate artifact set SHA256: `%s`\n' "$artifact_set"91 printf -- '- Candidate artifact manifest: `%s`\n' "$manifest"92 printf -- '- Evidence summary: `%s`\n' "$evidence"93 } >"$path"94}9596write_pass_matrix() {97 local path="$1"98 local prefix="$2"99100 printf '%s\n' \101 '# Fixture matrix' \102 '' \103 '| Row ID | Required class | Status | Evidence report |' \104 '| --- | --- | --- | --- |' \105 "| native-1280x800-handheld | handheld | pass | docs/hardware-uat/$prefix/native-1280x800-handheld/REPORT.md |" \106 "| physically-headless-desktop-dgpu | desktop | pass | docs/hardware-uat/$prefix/physically-headless-desktop-dgpu/REPORT.md |" \107 >"$path"108}109110write_pending_matrix() {111 local path="$1"112113 printf '%s\n' \114 '# Fixture matrix' \115 '' \116 '| Row ID | Required class | Status | Evidence report |' \117 '| --- | --- | --- | --- |' \118 '| native-1280x800-handheld | handheld | pending | pending |' \119 '| physically-headless-desktop-dgpu | desktop | pending | pending |' \120 >"$path"121}122123make_fixture() {124 local root="$1"125 local commit126 local prefix127 local manifest128 local manifest_relative129 local artifact_set130 local row_id131 local row_dir132133 mkdir -p "$root/docs/hardware-uat" "$root/website"134 git -C "$root" init --quiet135 git -C "$root" config user.name 'Hardware Matrix Fixture'136 git -C "$root" config user.email 'fixture@example.invalid'137 printf 'fixture source\n' >"$root/source.txt"138 git -C "$root" add source.txt139 git -C "$root" commit --quiet -m 'fixture source'140 commit="$(git -C "$root" rev-parse HEAD)"141 prefix="${commit:0:12}"142 mkdir -p "$root/docs/hardware-uat/$prefix"143144 manifest_relative="docs/hardware-uat/$prefix/candidate-artifacts.env"145 manifest="$root/$manifest_relative"146 printf '%s\n' \147 'schema=goq-hardware-matrix-artifacts-v1' \148 "exact_commit=$commit" \149 'candidate_kind=development' \150 'sigil_asset=sigil-fixture.tar.zst' \151 'sigil_sha256=1111111111111111111111111111111111111111111111111111111111111111' \152 'portal_asset=Portal-fixture.dmg' \153 'portal_sha256=2222222222222222222222222222222222222222222222222222222222222222' \154 >"$manifest"155 artifact_set="$(sha256_file "$manifest")"156157 for row_id in \158 native-1280x800-handheld \159 physically-headless-desktop-dgpu; do160 row_dir="$root/docs/hardware-uat/$prefix/$row_id"161 mkdir -p "$row_dir"162 if [[ "$row_id" == native-1280x800-handheld ]]; then163 write_evidence \164 "$row_dir/EVIDENCE.env" "$row_id" "$commit" \165 steamos-upstream integrated native-panel-connected 1280 800166 else167 write_evidence \168 "$row_dir/EVIDENCE.env" "$row_id" "$commit" \169 steamos-inspired discrete physically-headless 1920 1080170 fi171 write_report \172 "$row_dir/REPORT.md" "$row_id" "$commit" "$artifact_set" \173 "$manifest_relative" \174 "docs/hardware-uat/$prefix/$row_id/EVIDENCE.env"175 done176177 write_pass_matrix "$root/docs/hardware-uat/MATRIX.md" "$prefix"178 printf 'Goq hardware evidence remains explicitly qualified.\n' >"$root/README.md"179}180181remove_exact_line() {182 local path="$1"183 local exact_line="$2"184 local output="$path.next"185186 awk -v exact_line="$exact_line" '$0 != exact_line { print }' "$path" >"$output"187 mv "$output" "$path"188}189190replace_text() {191 local path="$1"192 local old="$2"193 local new="$3"194 local output="$path.next"195196 awk -v old="$old" -v new="$new" '{ gsub(old, new); print }' "$path" >"$output"197 mv "$output" "$path"198}199200expect_pass() {201 local label="$1"202 local root="$2"203 local log="$root/validator.log"204205 GOQ_HARDWARE_MATRIX_REPO_DIR="$root" "$validator" >"$log" 2>&1 \206 || {207 cat "$log" >&2208 fail "$label should pass"209 }210 grep -qx 'hardware_matrix_tests=ok' "$log" \211 || fail "$label did not report success"212}213214expect_fail() {215 local label="$1"216 local root="$2"217 local log="$root/validator.log"218219 if GOQ_HARDWARE_MATRIX_REPO_DIR="$root" "$validator" >"$log" 2>&1; then220 cat "$log" >&2221 fail "$label should fail"222 fi223 [[ -s "$log" ]] || fail "$label failed without a diagnostic"224}225226case_dir="$fixture_root/valid"227make_fixture "$case_dir"228expect_pass valid-complete-evidence "$case_dir"229230case_dir="$fixture_root/incomplete-report"231make_fixture "$case_dir"232commit="$(git -C "$case_dir" rev-parse HEAD)"233report="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/REPORT.md"234remove_exact_line "$report" '- Workflow run: `29999999999`'235expect_fail incomplete-report "$case_dir"236237case_dir="$fixture_root/incomplete-evidence"238make_fixture "$case_dir"239commit="$(git -C "$case_dir" rev-parse HEAD)"240evidence="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/EVIDENCE.env"241remove_exact_line "$evidence" 'portal_audio=pass'242expect_fail incomplete-evidence "$case_dir"243244case_dir="$fixture_root/duplicate-evidence"245make_fixture "$case_dir"246commit="$(git -C "$case_dir" rev-parse HEAD)"247evidence="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/EVIDENCE.env"248printf 'portal_audio=pass\n' >>"$evidence"249expect_fail duplicate-evidence "$case_dir"250251case_dir="$fixture_root/fabricated-commit"252make_fixture "$case_dir"253commit="$(git -C "$case_dir" rev-parse HEAD)"254report="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/REPORT.md"255replace_text "$report" "$commit" '0000000000000000000000000000000000000000'256expect_fail fabricated-commit "$case_dir"257258case_dir="$fixture_root/fabricated-artifact-set"259make_fixture "$case_dir"260commit="$(git -C "$case_dir" rev-parse HEAD)"261report="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/REPORT.md"262artifact_set="$(263 sed -n 's/^- Candidate artifact set SHA256: `\([0-9a-f]\{64\}\)`$/\1/p' \264 "$report"265)"266replace_text \267 "$report" "$artifact_set" \268 '0000000000000000000000000000000000000000000000000000000000000000'269expect_fail fabricated-artifact-set "$case_dir"270271case_dir="$fixture_root/wrong-row-topology"272make_fixture "$case_dir"273commit="$(git -C "$case_dir" rev-parse HEAD)"274evidence="$case_dir/docs/hardware-uat/${commit:0:12}/native-1280x800-handheld/EVIDENCE.env"275replace_text "$evidence" 'gpu_topology=integrated' 'gpu_topology=discrete'276expect_fail wrong-row-topology "$case_dir"277278case_dir="$fixture_root/overflowing-numeric-evidence"279make_fixture "$case_dir"280commit="$(git -C "$case_dir" rev-parse HEAD)"281evidence="$case_dir/docs/hardware-uat/${commit:0:12}/physically-headless-desktop-dgpu/EVIDENCE.env"282replace_text \283 "$evidence" 'native_width=1920' \284 'native_width=18446744073709551616'285replace_text \286 "$evidence" 'native_refresh_millihz=60000' \287 'native_refresh_millihz=18446744073709551616'288expect_fail overflowing-numeric-evidence "$case_dir"289290case_dir="$fixture_root/pending-matrix-claim"291make_fixture "$case_dir"292write_pending_matrix "$case_dir/docs/hardware-uat/MATRIX.md"293printf 'Goq is matrix-proven on all supported hardware.\n' \294 >"$case_dir/docs/public-claim.md"295expect_fail pending-matrix-claim "$case_dir"296297case_dir="$fixture_root/pending-hardware-claim"298make_fixture "$case_dir"299write_pending_matrix "$case_dir/docs/hardware-uat/MATRIX.md"300printf '<p>Goq is hardware-proven.</p>\n' >"$case_dir/website/index.html"301expect_fail pending-hardware-claim "$case_dir"302303case_dir="$fixture_root/development-release-claim"304make_fixture "$case_dir"305printf 'Goq is release-matrix-proven.\n' >"$case_dir/docs/public-claim.md"306expect_fail development-release-claim "$case_dir"307308echo 'hardware_matrix_fixture_tests=ok'