field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

commit 415a20399a7e210a88bf5daa1e8c6fa30176b659
parent de35829d6718a3e473029fa48a2de830cadf74a2
Author: triesap <tyson@radroots.org>
Date:   Sat,  3 Oct 2026 23:38:10 +0000

fix: select bounded measured persona attachments

- Validate the complete native diagnostic export
- Project exactly fifteen measured attempt attachments
- Reject unsafe unknown and foreign diagnostic evidence
- Verify tooling and the complete affected standalone lane

Diffstat:
MTeraFFI/provenance.json | 26+++++++++++++-------------
MTeraFFI/source.lock | 4++--
MTeraFFI/source/aarch64-apple-darwin.json | 26+++++++++++++++++++-------
MTeraFFI/source/aarch64-apple-ios-sim.json | 26+++++++++++++++++++-------
MTeraFFI/source/aarch64-apple-ios.json | 26+++++++++++++++++++-------
Mrelease/provenance.json | 4++--
Mscripts/local-social-fixture.py | 60++++++++++++++++++++++++++----------------------------------
Ascripts/persona_attachment_selection.py | 183+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/test_persona_attachment_selection.py | 151++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/verify-package-contract.sh | 1+
10 files changed, 435 insertions(+), 72 deletions(-)

diff --git a/TeraFFI/provenance.json b/TeraFFI/provenance.json @@ -92,19 +92,19 @@ "sha256": "e1c4926a9eef1db20cf5e0b7c17c6afae45773d88f7743502ccb5dcb4eab26ae" }, { - "bytes": 143011, + "bytes": 143532, "path": "source/aarch64-apple-darwin.json", - "sha256": "598ddf533e91ed2a3dfe3b4b6827a3e823eae1a09825bc28d28a43e8c2bf78e1" + "sha256": "375b206a62885771055f19f4b4d758201c011510da9b60d8e285b4a5c5848895" }, { - "bytes": 142855, + "bytes": 143376, "path": "source/aarch64-apple-ios-sim.json", - "sha256": "c2c0c58ad1ad7ee77d8baf3490899af3e34d54b73e8940072c6768f077876aba" + "sha256": "fe2290895145c6b29ec9bba6b90a72610b60de7369e1a363d5e2d6dca47c643a" }, { - "bytes": 142851, + "bytes": 143372, "path": "source/aarch64-apple-ios.json", - "sha256": "48331bc6eeb9a86247a167089e840a1302fb8087a994ba69faf158c35d0b8939" + "sha256": "e44044de5b14f331498229f3c64f24ec77e245280255a8066c6632217b64cade" } ], "language": "swift", @@ -112,7 +112,7 @@ "schema": "radroots.artifact-manifest.v2", "source": { "repository": "https://github.com/radrootslabs/tera", - "tree": "2b657cd1eb84af0fd5559c9e841845b489e9ef80" + "tree": "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e" }, "source_records": { "aarch64-apple-darwin": "source/aarch64-apple-darwin.json", @@ -174,19 +174,19 @@ "sha256": "5d74060f97e52dad69ab7567c16d6b6b34acfab846f468450d89e2394a8a69d5" }, { - "bytes": 143011, + "bytes": 143532, "path": "TeraFFI/source/aarch64-apple-darwin.json", - "sha256": "598ddf533e91ed2a3dfe3b4b6827a3e823eae1a09825bc28d28a43e8c2bf78e1" + "sha256": "375b206a62885771055f19f4b4d758201c011510da9b60d8e285b4a5c5848895" }, { - "bytes": 142855, + "bytes": 143376, "path": "TeraFFI/source/aarch64-apple-ios-sim.json", - "sha256": "c2c0c58ad1ad7ee77d8baf3490899af3e34d54b73e8940072c6768f077876aba" + "sha256": "fe2290895145c6b29ec9bba6b90a72610b60de7369e1a363d5e2d6dca47c643a" }, { - "bytes": 142851, + "bytes": 143372, "path": "TeraFFI/source/aarch64-apple-ios.json", - "sha256": "48331bc6eeb9a86247a167089e840a1302fb8087a994ba69faf158c35d0b8939" + "sha256": "e44044de5b14f331498229f3c64f24ec77e245280255a8066c6632217b64cade" } ], "schema": "tera.installed-native-artifacts.v1" diff --git a/TeraFFI/source.lock b/TeraFFI/source.lock @@ -1,7 +1,7 @@ schema = "tera.installed-source.v1" repository = "https://github.com/radrootslabs/tera" -source_tree = "2b657cd1eb84af0fd5559c9e841845b489e9ef80" -manifest_sha256 = "9309f414a72871dd586a09068b8d8678cdf527481983f06d5989713392149d3b" +source_tree = "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e" +manifest_sha256 = "16c3fab480159b62889b417453e35fd4c0b393ef037c1a7de651c65acf09f23c" source_date_epoch = 1787871027 [foundation] diff --git a/TeraFFI/source/aarch64-apple-darwin.json b/TeraFFI/source/aarch64-apple-darwin.json @@ -2878,10 +2878,10 @@ "sha256": "087faddef16e99f10bb7ad7b39d649e7e410b558ed1f9f4f4e498ab861eea622" }, "scripts/local-social-fixture.py": { - "bytes": 101032, - "git_blob": "4cbe745064f3bed7a9c0a359c40dd5996c5d7478", + "bytes": 100982, + "git_blob": "3d8c072afa7878ae3a40b5a9eaff5274b7c5f2f7", "mode": "100644", - "sha256": "31b482693d217eb2859847e197c434c43fc104da63917d93e11c69ebfebca9a0" + "sha256": "9dbb354f4656e1827143033fcb475afb2f247c6c32263c71bfce3b9b6ede5843" }, "scripts/local_social_test_support.py": { "bytes": 582, @@ -2925,6 +2925,12 @@ "mode": "100644", "sha256": "af175b24907863f548d0d93a585ceab8d65a686e5152f70739384dd5b8ef2b96" }, + "scripts/persona_attachment_selection.py": { + "bytes": 6266, + "git_blob": "a7daf9b0a35bed60804a64f517870e77cd7aae19", + "mode": "100644", + "sha256": "0fd26ba301a301caaba97d3bba314a9fe322c12a26e99f8fce5f272eb2cf39fc" + }, "scripts/release-evidence.sh": { "bytes": 8527, "git_blob": "8c3a82074f4bceddbe14cee5d6b642c39e551f05", @@ -3021,6 +3027,12 @@ "mode": "100644", "sha256": "651fc803fe3e3dd1636aec75f9ea79d81b9407317f93a02e4074a8369558bc33" }, + "scripts/test_persona_attachment_selection.py": { + "bytes": 5355, + "git_blob": "13bd0cece4ea4c73c2807275fad51ebf6582590e", + "mode": "100644", + "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", @@ -3028,10 +3040,10 @@ "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, "scripts/verify-package-contract.sh": { - "bytes": 1614, - "git_blob": "170f25c675b29871a46cbfa5675a5d8cf919eebb", + "bytes": 1663, + "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", "mode": "100755", - "sha256": "e9f3dfdc2932b7a5b32154c08c8ff4512f80ff40ebd05f1ee8d0a2154fa14441" + "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3047,6 +3059,6 @@ } }, "policy": "staged_inputs", - "tree": "2b657cd1eb84af0fd5559c9e841845b489e9ef80" + "tree": "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e" } } diff --git a/TeraFFI/source/aarch64-apple-ios-sim.json b/TeraFFI/source/aarch64-apple-ios-sim.json @@ -2874,10 +2874,10 @@ "sha256": "087faddef16e99f10bb7ad7b39d649e7e410b558ed1f9f4f4e498ab861eea622" }, "scripts/local-social-fixture.py": { - "bytes": 101032, - "git_blob": "4cbe745064f3bed7a9c0a359c40dd5996c5d7478", + "bytes": 100982, + "git_blob": "3d8c072afa7878ae3a40b5a9eaff5274b7c5f2f7", "mode": "100644", - "sha256": "31b482693d217eb2859847e197c434c43fc104da63917d93e11c69ebfebca9a0" + "sha256": "9dbb354f4656e1827143033fcb475afb2f247c6c32263c71bfce3b9b6ede5843" }, "scripts/local_social_test_support.py": { "bytes": 582, @@ -2921,6 +2921,12 @@ "mode": "100644", "sha256": "af175b24907863f548d0d93a585ceab8d65a686e5152f70739384dd5b8ef2b96" }, + "scripts/persona_attachment_selection.py": { + "bytes": 6266, + "git_blob": "a7daf9b0a35bed60804a64f517870e77cd7aae19", + "mode": "100644", + "sha256": "0fd26ba301a301caaba97d3bba314a9fe322c12a26e99f8fce5f272eb2cf39fc" + }, "scripts/release-evidence.sh": { "bytes": 8527, "git_blob": "8c3a82074f4bceddbe14cee5d6b642c39e551f05", @@ -3017,6 +3023,12 @@ "mode": "100644", "sha256": "651fc803fe3e3dd1636aec75f9ea79d81b9407317f93a02e4074a8369558bc33" }, + "scripts/test_persona_attachment_selection.py": { + "bytes": 5355, + "git_blob": "13bd0cece4ea4c73c2807275fad51ebf6582590e", + "mode": "100644", + "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", @@ -3024,10 +3036,10 @@ "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, "scripts/verify-package-contract.sh": { - "bytes": 1614, - "git_blob": "170f25c675b29871a46cbfa5675a5d8cf919eebb", + "bytes": 1663, + "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", "mode": "100755", - "sha256": "e9f3dfdc2932b7a5b32154c08c8ff4512f80ff40ebd05f1ee8d0a2154fa14441" + "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3043,6 +3055,6 @@ } }, "policy": "staged_inputs", - "tree": "2b657cd1eb84af0fd5559c9e841845b489e9ef80" + "tree": "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e" } } diff --git a/TeraFFI/source/aarch64-apple-ios.json b/TeraFFI/source/aarch64-apple-ios.json @@ -2874,10 +2874,10 @@ "sha256": "087faddef16e99f10bb7ad7b39d649e7e410b558ed1f9f4f4e498ab861eea622" }, "scripts/local-social-fixture.py": { - "bytes": 101032, - "git_blob": "4cbe745064f3bed7a9c0a359c40dd5996c5d7478", + "bytes": 100982, + "git_blob": "3d8c072afa7878ae3a40b5a9eaff5274b7c5f2f7", "mode": "100644", - "sha256": "31b482693d217eb2859847e197c434c43fc104da63917d93e11c69ebfebca9a0" + "sha256": "9dbb354f4656e1827143033fcb475afb2f247c6c32263c71bfce3b9b6ede5843" }, "scripts/local_social_test_support.py": { "bytes": 582, @@ -2921,6 +2921,12 @@ "mode": "100644", "sha256": "af175b24907863f548d0d93a585ceab8d65a686e5152f70739384dd5b8ef2b96" }, + "scripts/persona_attachment_selection.py": { + "bytes": 6266, + "git_blob": "a7daf9b0a35bed60804a64f517870e77cd7aae19", + "mode": "100644", + "sha256": "0fd26ba301a301caaba97d3bba314a9fe322c12a26e99f8fce5f272eb2cf39fc" + }, "scripts/release-evidence.sh": { "bytes": 8527, "git_blob": "8c3a82074f4bceddbe14cee5d6b642c39e551f05", @@ -3017,6 +3023,12 @@ "mode": "100644", "sha256": "651fc803fe3e3dd1636aec75f9ea79d81b9407317f93a02e4074a8369558bc33" }, + "scripts/test_persona_attachment_selection.py": { + "bytes": 5355, + "git_blob": "13bd0cece4ea4c73c2807275fad51ebf6582590e", + "mode": "100644", + "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", @@ -3024,10 +3036,10 @@ "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, "scripts/verify-package-contract.sh": { - "bytes": 1614, - "git_blob": "170f25c675b29871a46cbfa5675a5d8cf919eebb", + "bytes": 1663, + "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", "mode": "100755", - "sha256": "e9f3dfdc2932b7a5b32154c08c8ff4512f80ff40ebd05f1ee8d0a2154fa14441" + "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3043,6 +3055,6 @@ } }, "policy": "staged_inputs", - "tree": "2b657cd1eb84af0fd5559c9e841845b489e9ef80" + "tree": "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e" } } diff --git a/release/provenance.json b/release/provenance.json @@ -2,7 +2,7 @@ "artifacts": { "app_api_sha256": "020924097c0d7efc33128cb8fd3d3b2026d95f57c44da71880e585aff80f070b", "ffi_api_sha256": "5d74060f97e52dad69ab7567c16d6b6b34acfab846f468450d89e2394a8a69d5", - "ffi_provenance_sha256": "9309f414a72871dd586a09068b8d8678cdf527481983f06d5989713392149d3b", + "ffi_provenance_sha256": "16c3fab480159b62889b417453e35fd4c0b393ef037c1a7de651c65acf09f23c", "info_plist_sha256": "b55010dd73b34bf5ad910a888be0ea1ae45f2a5c14329fa6a57059a317bdbd42", "privacy_manifest_sha256": "0f2103257ba596fbcaeb1d6a4dffe3ae021e84c010178852c6bf500a8cfb0f19", "sbom_sha256": "f0a15c2c9ad7799539fbc52fd1fdbcf17f4046b6f86cfe0a9b8980adc0079e10", @@ -22,7 +22,7 @@ "lib_revision": "189c49b74b4bafc142b00b76b296477931139e72", "source_date_epoch": 1787871027, "swift_package_lock_sha256": "8aec408132602a249111a65903c985cca5898ec316a45916d88ba756f08ea40d", - "tera_ffi_source_tree": "2b657cd1eb84af0fd5559c9e841845b489e9ef80", + "tera_ffi_source_tree": "9c3f9ea1dea95b4ad49e82848008c0eb4762bb2e", "xcode_package_lock_sha256": "3656728f8251f3ea644aa150d154819766470ca7bd4f85b7c51fdf301d361d16" }, "version": "0.1.0-alpha" diff --git a/scripts/local-social-fixture.py b/scripts/local-social-fixture.py @@ -8,6 +8,7 @@ import base64 import hashlib import http.server import importlib.metadata +import importlib.util import ipaddress import json import os @@ -20,7 +21,6 @@ import stat import subprocess import struct import sys -import tempfile import threading import time import unicodedata @@ -2065,41 +2065,33 @@ def extract_persona_attempt_attachments( *, require_measured_network: bool, ) -> list[tuple[bytes, dict[str, Any]]]: - tests = run_json_command_bounded( - [ - "xcrun", - "xcresulttool", - "get", - "test-results", - "tests", - "--path", - str(result_bundle), - ], + spec = importlib.util.spec_from_file_location( + "tera_persona_attachment_selection", + Path(__file__).with_name("persona_attachment_selection.py"), + ) + assert spec is not None and spec.loader is not None + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + tools = module.ExtractionTools( + run_json_command_bounded, + exact_persona_test_node, + read_json_bounded, + bounded_directory_inventory, + directory_digest, + load_exported_persona_attachments, + xcresult_attachment_attempt_id, + PERSONA_XCRESULT_NODE_IDENTIFIER, + PERSONA_XCRESULT_NODE_URL, + PERSONA_ATTACHMENT_NAMES, MAX_XCRESULT_JSON_BYTES, + MAX_PERSONA_ATTACHMENT_BYTES, + ) + return module.extract( + result_bundle, + suite, + tools, + require_measured_network=require_measured_network, ) - exact_persona_test_node(tests) - with tempfile.TemporaryDirectory() as directory: - export_directory = Path(directory) - subprocess.run( - [ - "xcrun", - "xcresulttool", - "export", - "attachments", - "--test-id", - PERSONA_XCRESULT_NODE_URL, - "--path", - str(result_bundle), - "--output-path", - str(export_directory), - ], - check=True, - ) - return load_exported_persona_attachments( - export_directory, - suite, - require_measured_network=require_measured_network, - ) def reconstruct_persona_result_v2( diff --git a/scripts/persona_attachment_selection.py b/scripts/persona_attachment_selection.py @@ -0,0 +1,183 @@ +"""Select measured persona evidence from a bounded native audit export.""" + +import json +from pathlib import Path +import re +import subprocess +import tempfile +from typing import Any, Callable, NamedTuple + +AUDIT_UUID = r"[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}" +AUDIT_NAME = re.compile( + rf"^(?:Screen before audit_0_{AUDIT_UUID}\.png|" + rf"Accessibility tree before audit_0_{AUDIT_UUID}\.txt)$" +) +REQUIRED_ROW_KEYS = { + "exportedFileName", + "suggestedHumanReadableName", + "isAssociatedWithFailure", + "configurationName", + "deviceName", + "deviceId", +} +ALLOWED_ROW_KEYS = REQUIRED_ROW_KEYS | { + "timestamp", + "repetitionNumber", + "arguments", +} + + +class ExtractionTools(NamedTuple): + run_json: Callable + exact_node: Callable + read_json: Callable + inventory: Callable + digest: Callable + load_selected: Callable + attempt_id: Callable + node_identifier: str + node_url: str + names: tuple[str, ...] + maximum_json_bytes: int + maximum_attempt_bytes: int + + +def filename(value: object) -> str: + if not isinstance(value, str) or not value: + raise ValueError("xcresult exported filename is invalid") + if len(value.encode("utf-8")) > 255 or Path(value).name != value: + raise ValueError("xcresult exported filename is invalid") + return value + + +def row_identity(value: Any) -> tuple[str, str]: + if not isinstance(value, dict): + raise ValueError("xcresult attachment row is invalid") + if not REQUIRED_ROW_KEYS <= value.keys() <= ALLOWED_ROW_KEYS: + raise ValueError("xcresult attachment row is invalid") + if ( + value["isAssociatedWithFailure"] is not False + or value["configurationName"] != "Test Scheme Action" + ): + raise ValueError("xcresult attachment context is invalid") + if not all( + isinstance(value[k], str) and value[k] + for k in ["deviceName", "deviceId", "suggestedHumanReadableName"] + ): + raise ValueError("xcresult attachment context is invalid") + return filename(value["exportedFileName"]), value["suggestedHumanReadableName"] + + +def group_value(value: Any, tools: ExtractionTools) -> dict: + if not isinstance(value, list) or len(value) != 1: + raise ValueError("xcresult attachment manifest is invalid") + group = value[0] + if not isinstance(group, dict) or set(group) != { + "testIdentifier", + "testIdentifierURL", + "attachments", + }: + raise ValueError("xcresult attachment manifest is invalid") + if ( + group["testIdentifier"] != tools.node_identifier + or group["testIdentifierURL"] != tools.node_url + ): + raise ValueError("xcresult attachment test binding is invalid") + if not isinstance(group["attachments"], list): + raise ValueError("xcresult attachment inventory is invalid") + return group + + +def selected_rows( + group: dict, inventory: set[str], tools: ExtractionTools +) -> list[dict]: + selected, seen = [], set() + for row in group["attachments"]: + exported, name = row_identity(row) + if exported in seen: + raise ValueError("xcresult attachment export identity is duplicated") + seen.add(exported) + if tools.attempt_id(name) is not None: + selected.append(row) + elif AUDIT_NAME.fullmatch(name) is None: + raise ValueError("xcresult contains an unknown diagnostic attachment") + if inventory != {"manifest.json", *seen}: + raise ValueError("xcresult raw export inventory is invalid") + if len(selected) != len(tools.names): + raise ValueError("xcresult requires exactly fifteen measured attempts") + devices = {(r["deviceName"], r["deviceId"]) for r in group["attachments"]} + if len(devices) != 1: + raise ValueError("xcresult diagnostics do not bind the attempt device") + return selected + + +def flat_inventory(path: Path, tools: ExtractionTools) -> set[str]: + values = tools.inventory(path) + if any(kind != 1 or b"/" in name for kind, name, _ in values): + raise ValueError("xcresult raw export inventory is invalid") + return {name.decode("utf-8") for _, name, _ in values} + + +def project(raw: Path, selected: Path, tools: ExtractionTools) -> None: + # The full raw export retains the existing result-bundle entry/file/total + # byte, regular-file, no-follow and stable-read gates, without new limits. + tools.digest(raw) + _, value = tools.read_json(raw / "manifest.json", tools.maximum_json_bytes) + group = group_value(value, tools) + rows = selected_rows(group, flat_inventory(raw, tools), tools) + for row in rows: + name = row["exportedFileName"] + payload, _ = tools.read_json(raw / name, tools.maximum_attempt_bytes) + (selected / name).write_bytes(payload) + (selected / "manifest.json").write_text( + json.dumps([{**group, "attachments": rows}]), encoding="utf-8" + ) + + +def extract( + result_bundle: Path, + suite: dict, + tools: ExtractionTools, + *, + require_measured_network: bool, +): + tools.exact_node( + tools.run_json( + [ + "xcrun", + "xcresulttool", + "get", + "test-results", + "tests", + "--path", + str(result_bundle), + ], + tools.maximum_json_bytes, + ) + ) + with ( + tempfile.TemporaryDirectory() as raw_directory, + tempfile.TemporaryDirectory() as selected_directory, + ): + raw, selected = Path(raw_directory), Path(selected_directory) + subprocess.run( + [ + "xcrun", + "xcresulttool", + "export", + "attachments", + "--test-id", + tools.node_url, + "--path", + str(result_bundle), + "--output-path", + str(raw), + ], + check=True, + ) + project(raw, selected, tools) + # This parser still requires exactly fifteen canonical, bounded, + # measured attempts and a strict sixteen-entry selected inventory. + return tools.load_selected( + selected, suite, require_measured_network=require_measured_network + ) diff --git a/scripts/test_persona_attachment_selection.py b/scripts/test_persona_attachment_selection.py @@ -0,0 +1,151 @@ +import json +import unittest +from pathlib import Path +from unittest import mock + +from scripts import test_local_social_fixture as support + +fixture = support.fixture + + +class PersonaAttachmentExtractionTests(unittest.TestCase): + def setUp(self) -> None: + self.suite, self.attempts = ( + support.LocalSocialFixtureTests().persona_attempt_attachments() + ) + + def export(self, destination: Path) -> list[dict]: + rows = [] + for index, (name, (raw, _)) in enumerate( + zip(fixture.PERSONA_ATTACHMENT_NAMES, self.attempts, strict=True) + ): + exported = f"attempt-{index}.json" + (destination / exported).write_bytes(raw) + rows.append( + self.row( + exported, + f"{name[:-5]}_0_{index:08X}-0000-0000-0000-000000000000.json", + ) + ) + for index in range(3): + for label, suffix in [ + ("Screen before audit", "png"), + ("Accessibility tree before audit", "txt"), + ]: + exported = f"audit-{index}.{suffix}" + (destination / exported).write_bytes(b"native audit diagnostic") + rows.append( + self.row( + exported, + f"{label}_0_{index:08X}-0000-0000-0000-000000000000.{suffix}", + ) + ) + return rows + + @staticmethod + def row(exported: str, name: str) -> dict: + return { + "exportedFileName": exported, + "suggestedHumanReadableName": name, + "isAssociatedWithFailure": False, + "configurationName": "Test Scheme Action", + "deviceName": "iPhone 17 Pro", + "deviceId": "11111111-2222-3333-4444-555555555555", + } + + def extract(self, mutation=None): + def run(command, **_): + destination = Path(command[command.index("--output-path") + 1]) + rows = self.export(destination) + if mutation is not None: + mutation(destination, rows) + (destination / "manifest.json").write_text( + json.dumps( + [ + { + "testIdentifier": fixture.PERSONA_XCRESULT_NODE_IDENTIFIER, + "testIdentifierURL": fixture.PERSONA_XCRESULT_NODE_URL, + "attachments": rows, + } + ] + ) + ) + + tests = { + "devices": [], + "testPlanConfigurations": [], + "testNodes": [ + { + "name": "testLocalSocialDeterministicPersonas()", + "nodeIdentifier": fixture.PERSONA_XCRESULT_NODE_IDENTIFIER, + "nodeIdentifierURL": fixture.PERSONA_XCRESULT_NODE_URL, + "nodeType": "Test Case", + "result": "Passed", + } + ], + } + with ( + mock.patch.object(fixture, "run_json_command_bounded", return_value=tests), + mock.patch.object(fixture.subprocess, "run", side_effect=run), + ): + return fixture.extract_persona_attempt_attachments( + Path("synthetic.xcresult"), self.suite, require_measured_network=True + ) + + def test_native_audit_diagnostics_do_not_replace_any_measured_attempt(self) -> None: + actual = self.extract() + self.assertEqual(actual, self.attempts) + self.assertEqual(len(actual), 15) + + def test_unknown_unsafe_or_foreign_diagnostics_are_rejected(self) -> None: + def unknown(_, rows): + rows[-1]["suggestedHumanReadableName"] = "unknown.json" + + def unrelated_file(destination, _): + (destination / "unreferenced.txt").write_text("unreferenced") + + def failure(_, rows): + rows[-1]["isAssociatedWithFailure"] = True + + def foreign(_, rows): + rows[-1]["deviceId"] = "22222222-2222-3333-4444-555555555555" + + def traversal(_, rows): + rows[-1]["exportedFileName"] = "../outside.txt" + + def duplicate(_, rows): + rows[0]["suggestedHumanReadableName"] = rows[1][ + "suggestedHumanReadableName" + ] + + def symbolic_link(destination, rows): + path = destination / rows[-1]["exportedFileName"] + path.unlink() + path.symlink_to(destination / rows[0]["exportedFileName"]) + + for mutation in [ + unknown, + unrelated_file, + failure, + foreign, + traversal, + duplicate, + symbolic_link, + ]: + with ( + self.subTest(mutation=mutation.__name__), + self.assertRaises(ValueError), + ): + self.extract(mutation) + + def test_raw_diagnostics_retain_the_existing_result_file_byte_bound(self) -> None: + def oversized(destination, rows): + with (destination / rows[-1]["exportedFileName"]).open("wb") as stream: + stream.truncate(fixture.MAX_RESULT_BUNDLE_FILE_BYTES + 1) + + with self.assertRaisesRegex(ValueError, "byte bound"): + self.extract(oversized) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/verify-package-contract.sh b/scripts/verify-package-contract.sh @@ -23,6 +23,7 @@ sh "$repo_root/scripts/ffi-provenance.sh" contract-check scripts/test_kotlin_smoke.py \ scripts/test_xcode_selection.py \ scripts/test_local_social_fixture.py \ + scripts/test_persona_attachment_selection.py \ scripts/test_local_social_relay.py \ scripts/test_legacy_upgrade_fixture.py )