diff --git a/.github/native/hosted_native.py b/.github/native/hosted_native.py index c3b98795d..b0be15cb0 100644 --- a/.github/native/hosted_native.py +++ b/.github/native/hosted_native.py @@ -442,7 +442,7 @@ def record(): 'run_id': os.environ.get('GITHUB_RUN_ID'), 'run_attempt': os.environ.get('GITHUB_RUN_ATTEMPT'), 'runner': {key: os.environ.get(key) for key in ['RUNNER_OS', 'RUNNER_ARCH', 'ImageOS', 'ImageVersion']}, - 'os': platform.platform(), 'commands': [], 'build': 'NOT RUN', 'smoke': 'NOT RUN', + 'os': platform.platform(), 'commands': [], 'build': 'NOT RUN', 'smoke': 'NOT RUN', 'native_probe': 'NOT RUN', 'hardware': 'NOT RUN', 'signing': 'NOT RUN', 'app_id': APP_IDS[PLATFORM], 'smoke_scope': 'Fresh install; render Create a passcode; type four disposable digits; assert Confirm your passcode; stop before persisting credentials.', 'startup_timing_scope': 'Bounded cold development bundle/startup allowance; no release performance acceptance.', @@ -696,7 +696,7 @@ def build(): save(data) -def warm_metro_bundle(): +def warm_metro_bundle(suite='startup'): """Bound cold development bundling before starting either disposable app.""" bundle_platform = {'IOS': 'ios', 'ANDROID': 'android'}.get(PLATFORM) if bundle_platform is None: @@ -723,20 +723,30 @@ def warm_metro_bundle(): finally: details['duration_seconds'] = round(time.monotonic() - started, 1) data = read() - data['metro_warmup'] = details + data['metro_warmup' if suite == 'startup' else 'probe_bundle'] = details save(data) -def smoke(): +def smoke(suite='startup'): + if suite not in ['startup', 'probe']: + raise ValueError('Unknown disposable native suite.') + is_probe = suite == 'probe' + result_key = 'native_probe' if is_probe else 'smoke' + if is_probe and read()['smoke'] != 'PASS': + raise RuntimeError('The real app startup smoke must pass before module probes.') if read()['build'] != 'PASS': raise RuntimeError('A successful native build is required before smoke testing.') if artifact_identity() != read()['built_artifact']: raise RuntimeError('Built artifact changed before the disposable startup smoke.') + report = PRIVATE / ('probe-junit.xml' if is_probe else 'smoke-junit.xml') + report.unlink(missing_ok=True) metro_output = (PRIVATE / 'metro.log').open('wb') - metro = subprocess.Popen(['node', 'node_modules/react-native/cli.js', 'start', '--port', '8081'], + metro_args = ['node', 'node_modules/react-native/cli.js', 'start', '--port', '8081'] + if is_probe: + metro_args += ['--config', str(ROOT / '.github/native/release_metro.cjs')] + metro = subprocess.Popen(metro_args, cwd=ROOT, stdout=metro_output, stderr=subprocess.STDOUT, start_new_session=True) device = None - report = PRIVATE / 'smoke-junit.xml' try: for _ in range(60): if metro.poll() is not None: @@ -749,7 +759,7 @@ def smoke(): time.sleep(1) else: raise RuntimeError('Metro did not become ready within 60 attempts.') - warm_metro_bundle() + warm_metro_bundle(suite) if PLATFORM == 'IOS': device = command(['xcrun', 'simctl', 'create', 'Keeper-disposable-ci', 'com.apple.CoreSimulator.SimDeviceType.iPhone-16', @@ -785,19 +795,31 @@ def smoke(): command([data['maestro']['binary'], '--device', device, 'test', '--env', 'APP_ID=' + APP_IDS[PLATFORM], '--flatten-debug-output', '--debug-output', str(PRIVATE / 'maestro-output'), '--format', 'junit', '--output', str(report), '--test-output-dir', str(PRIVATE / 'maestro-output'), - '.github/native/startup.yaml'], 'Assert startup and disposable passcode transition', timeout=420) - suite = ET.parse(report).getroot() - cases = list(suite.iter('testcase')) - if not cases or any(list(case.iter('failure')) or list(case.iter('error')) or list(case.iter('skipped')) - for case in cases): - raise RuntimeError('Maestro did not produce a complete successful smoke report.') + '.github/native/release_probe.yaml' if is_probe else '.github/native/startup.yaml'], + 'Assert native persistence across process launches' if is_probe else + 'Assert startup and disposable passcode transition', timeout=300 if is_probe else 420, + error_details=not is_probe) + cases = successful_junit(report) + if artifact_identity() != read()['built_artifact']: + raise RuntimeError('Built artifact changed during native execution.') data = read() - data['smoke'] = 'PASS' - data['smoke_test_cases'] = len(cases) + data[result_key] = 'PASS' + data[result_key + '_test_cases'] = cases + if is_probe: + data['probe_scope'] = ('CI-only Metro entrypoint; actual encrypted Realm/current schemas and production MMKV; ' + 'three process launches, rollback, wrong-key rejection, targeted primitive deletion, ' + 'separate database files and cleanup. NOT app key deletion, account isolation, ' + 'setup/recovery or release performance acceptance.') save(data) except Exception: try: - record_startup_failure(report, device) + if not is_probe: + record_startup_failure(report, device) + else: + data = read() + data['native_probe'] = 'FAIL' + data['probe_diagnostics'] = 'Native module probe failed; raw output retained only on ephemeral runner.' + save(data) except Exception as error: # Diagnostics never replace the original failed native/UI result. data = read() @@ -823,9 +845,29 @@ def smoke(): stderr=subprocess.DEVNULL, timeout=30, check=False) +def successful_junit(report): + if not report.is_file() or report.stat().st_size > 1024 * 1024: + raise RuntimeError('Missing or oversized native JUnit report.') + root = ET.parse(report).getroot() + for suite in root.iter(): + if suite.tag in ['testsuite', 'testsuites']: + for attribute in ['failures', 'errors', 'skipped', 'disabled']: + if int(suite.get(attribute, '0')) != 0: + raise RuntimeError('Native JUnit declares unsuccessful cases.') + cases = list(root.iter('testcase')) + if not cases or any(list(root.iter(tag)) for tag in ['failure', 'error', 'skipped']) or any( + case.get('status', 'SUCCESS').upper() != 'SUCCESS' for case in cases): + raise RuntimeError('Maestro did not produce a complete successful native report.') + return len(cases) + + +def probe(): + smoke('probe') + + def main(): - if PLATFORM not in APP_IDS or len(sys.argv) != 2 or sys.argv[1] not in ['record', 'prepare', 'driver', 'build', 'smoke']: - raise RuntimeError('Expected a hosted platform and record|prepare|driver|build|smoke.') + if PLATFORM not in APP_IDS or len(sys.argv) != 2 or sys.argv[1] not in ['record', 'prepare', 'driver', 'build', 'smoke', 'probe']: + raise RuntimeError('Expected a hosted platform and record|prepare|driver|build|smoke|probe.') os.environ.update({'ENVFILE': '.env.ci', 'RCT_NO_LAUNCH_PACKAGER': '1', 'RCT_NEW_ARCH_ENABLED': '1', 'MAESTRO_CLI_NO_ANALYTICS': '1'}) run_phase(sys.argv[1]) @@ -838,8 +880,8 @@ def run_phase(phase): if EVIDENCE.exists(): evidence = read() evidence['failed_phase'] = phase - if phase in ['build', 'smoke']: - evidence[phase] = 'FAIL' + if phase in ['build', 'smoke', 'probe']: + evidence['native_probe' if phase == 'probe' else phase] = 'FAIL' save(evidence) raise diff --git a/.github/native/release_acceptance.cjs b/.github/native/release_acceptance.cjs new file mode 100644 index 000000000..01a8c5e0b --- /dev/null +++ b/.github/native/release_acceptance.cjs @@ -0,0 +1,32 @@ +// Common release obligations. Extend with real executable scenarios, never status-only waivers. +// Native module checks are deliberately distinct from app-account or feature acceptance. +const REQUIRED = Object.freeze([ + 'native-build-and-startup', + 'native-realm-mmkv-process-persistence', + 'key-deletion-live-reference-and-privacy', + 'setup-offline-retry-relaunch-no-duplicates', + 'app-account-session-isolation', + 'normal-page-runtime-and-recovery-regression', + 'cold-start-and-first-wallet-performance', +]); +function acceptance({ trusted, ios, android }) { + const executed = trusted === true && ios === 'success' && android === 'success'; + const cases = REQUIRED.map((id, index) => ({ + id, + status: index < 2 ? (executed ? 'PASS' : 'NOT VERIFIED') : 'NOT IMPLEMENTED', + scope: index === 1 ? 'CI entrypoint; actual native storage, not application account isolation' : + index > 1 ? 'Requires reviewed app scenarios; R5 R4-dependent checks wait for reconciliation' : + 'Unsigned simulator / development debug-key emulator; narrow passcode smoke', + })); + return { release_ready: false, phase_a: 'BLOCKED', cases, + signing: 'NOT IMPLEMENTED / NOT VERIFIED (separate Phase B)', + physical: 'NOT RUN (authorized tester and exact distributed artifact required)' }; +} +function markdown(result) { + return '# Keeper Phase A release acceptance: BLOCKED\n\n' + + 'This check cannot approve a release. Startup and native module probes do not cover the app matrix.\n\n' + + '| Required scenario | Result | Scope |\n| --- | --- | --- |\n' + + result.cases.map(c => `| ${c.id} | ${c.status} | ${c.scope} |`).join('\n') + + `\n\nSigning/distribution: ${result.signing}.\n\nPhysical: ${result.physical}.\n`; +} +module.exports = { REQUIRED, acceptance, markdown }; diff --git a/.github/native/release_evidence.cjs b/.github/native/release_evidence.cjs new file mode 100644 index 000000000..542f6dff9 --- /dev/null +++ b/.github/native/release_evidence.cjs @@ -0,0 +1,48 @@ +// Read-only Actions provenance. Writable PR assertions/artifacts supply no credit. +async function evidence(github, context, { ios, android, attempt }) { + const pr = context.payload.pull_request; + const { owner, repo } = context.repo; + const repository = owner + '/' + repo; + if (ios !== 'success' || android !== 'success' || context.eventName !== 'pull_request' || + !pr || pr.number === 7045 || pr.base.ref !== 'sprint' || + pr.head.repo?.full_name !== repository || pr.base.repo?.full_name !== repository || + !pr.head.repo.id || !pr.base.repo.id || !/^[a-f0-9]{40}$/.test(pr.head.sha) || + !Number.isSafeInteger(attempt) || attempt < 1) return false; + try { + const runs = await github.paginate(github.rest.actions.listWorkflowRuns, { + owner, repo, workflow_id: 'keeper-release-acceptance.yml', + head_sha: pr.head.sha, event: 'pull_request', per_page: 100, + }); + const run = runs.sort((a, b) => b.id - a.id)[0]; + if (!run || run.id !== context.runId || run.run_attempt !== attempt || + run.path !== '.github/workflows/keeper-release-acceptance.yml' || + run.event !== 'pull_request' || run.head_sha !== pr.head.sha || + run.head_branch !== pr.head.ref || run.head_repository?.full_name !== repository || + run.head_repository?.id !== pr.head.repo.id || + (!['in_progress', 'completed'].includes(run.status) || + (run.status === 'completed' && !['success', 'failure'].includes(run.conclusion)))) return false; + const linked = run.pull_requests?.find(item => item.number === pr.number); + if (!linked || linked.head?.sha !== pr.head.sha || linked.head?.ref !== pr.head.ref || + linked.head?.repo?.id !== pr.head.repo.id || linked.base?.ref !== 'sprint' || + linked.base?.sha !== pr.base.sha || linked.base?.repo?.id !== pr.base.repo.id) return false; + const jobs = await github.paginate(github.rest.actions.listJobsForWorkflowRunAttempt, { + owner, repo, run_id: run.id, attempt_number: attempt, per_page: 100, + }); + return ['IOS', 'ANDROID'].every(platform => { + const matches = jobs.filter(job => job.name === + `${platform.toLowerCase()} / Native ${platform} build and probes`); + if (matches.length !== 1) return false; + const job = matches[0]; + if (job.head_sha !== pr.head.sha || job.run_id !== run.id || job.run_attempt !== attempt || + job.status !== 'completed' || job.conclusion !== 'success') return false; + const steps = ['Build development app', ...(platform === 'IOS' + ? ['Run disposable startup smoke', 'Run disposable native persistence probe'] + : ['Run Android startup and native persistence probes'])]; + return steps.every(name => { + const found = job.steps?.filter(step => step.name === name) ?? []; + return found.length === 1 && found[0].status === 'completed' && found[0].conclusion === 'success'; + }); + }); + } catch { return false; } +} +module.exports = { evidence }; diff --git a/.github/native/release_metro.cjs b/.github/native/release_metro.cjs new file mode 100644 index 000000000..df8c39ad6 --- /dev/null +++ b/.github/native/release_metro.cjs @@ -0,0 +1,19 @@ +// CI-only entrypoint for native module persistence. No product source is rewritten. +const path = require('node:path'); +const base = require('../../metro.config'); +const enhance = base.server?.enhanceMiddleware; +module.exports = { + ...base, + projectRoot: path.resolve(__dirname, '../..'), + server: { + ...base.server, + enhanceMiddleware(middleware, server) { + const inner = enhance ? enhance(middleware, server) : middleware; + return (req, res, next) => { + req.url = req.url.replace(/^\/index\.(bundle|map)(?=\?|$)/, + '/.github/native/release_probe.$1'); + return inner(req, res, next); + }; + }, + }, +}; diff --git a/.github/native/release_preflight.cjs b/.github/native/release_preflight.cjs new file mode 100644 index 000000000..b95377b4e --- /dev/null +++ b/.github/native/release_preflight.cjs @@ -0,0 +1,58 @@ +// Unprivileged PR bootstrap check, not a release authorization or commit-status writer. +const WORKFLOWS = [ + '.github/workflows/keeper-hosted-native.yml', + '.github/workflows/keeper-release-acceptance.yml', + '.github/workflows/keeper-native-platform.yml', +]; +const NATIVE_FILES = [ + 'hosted_native.py', 'nodeify.cjs', 'startup.yaml', 'release_preflight.cjs', + 'release_acceptance.cjs', 'release_evidence.cjs', 'release_metro.cjs', 'release_probe.js', + 'release_probe_core.js', 'release_probe.yaml', +].map(name => '.github/native/' + name); +function fingerprint(tree) { + if (tree.truncated) throw new Error('Truncated CI tree'); + const entries = tree.tree.filter(e => WORKFLOWS.includes(e.path) || e.path.startsWith('.github/native/')); + if (![...WORKFLOWS, ...NATIVE_FILES].every(p => entries.some(e => e.path === p && e.type === 'blob' && ['100644', '100755'].includes(e.mode)))) { + throw new Error('Reviewed Phase A / #7060 infrastructure is not installed'); + } + return JSON.stringify(entries.map(e => [e.path, e.mode, e.type, e.sha]) + .sort((a, b) => a[0].localeCompare(b[0]))); +} +async function preflight(github, context) { + const original = context.payload.pull_request; + if (context.eventName !== 'pull_request' || !original || original.number === 7045) { + return { trusted: false, reason: 'Outside Phase A scope; frozen R4 excluded' }; + } + const { owner, repo } = context.repo; + const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number: original.number }); + const repository = owner + '/' + repo; + if (pr.base.ref !== 'sprint' || pr.head.repo?.full_name !== repository || + pr.base.repo?.full_name !== repository || pr.head.sha !== original.head.sha || + pr.head.ref !== original.head.ref || !/^[a-f0-9]{40}$/.test(pr.head.sha) || + !pr.head.repo.id || pr.head.repo.id !== original.head.repo?.id || + !pr.base.repo.id || pr.base.repo.id !== original.base.repo?.id || + original.base.ref !== 'sprint') { + return { trusted: false, reason: 'Exact current same-repository PR provenance is unavailable' }; + } + try { + const snapshots = await Promise.all([pr.head.sha, pr.base.sha, original.base.sha].map(async ref => { + const { data } = await github.rest.git.getTree({ owner, repo, tree_sha: ref, recursive: '1' }); + return fingerprint(data); + })); + if (!snapshots.every(value => value === snapshots[0])) { + return { trusted: false, reason: 'CI differs from current or run base; review/install before native acceptance' }; + } + // Re-read after API work so a concurrent push cannot supply current-head credit. + const { data: latest } = await github.rest.pulls.get({ owner, repo, pull_number: original.number }); + if (latest.head.sha !== pr.head.sha || latest.base.sha !== pr.base.sha || + latest.base.ref !== pr.base.ref || latest.head.ref !== pr.head.ref || + latest.head.repo?.id !== pr.head.repo.id || latest.base.repo?.id !== pr.base.repo.id || + latest.head.repo?.full_name !== repository || latest.base.repo?.full_name !== repository) { + return { trusted: false, reason: 'PR source/base changed during provenance verification' }; + } + return { trusted: true, reason: 'Exact-head CI matches both protected base snapshots' }; + } catch { + return { trusted: false, reason: 'Reviewed Phase A / #7060 infrastructure unavailable; no native credit' }; + } +} +module.exports = { WORKFLOWS, NATIVE_FILES, fingerprint, preflight }; diff --git a/.github/native/release_probe.js b/.github/native/release_probe.js new file mode 100644 index 000000000..827687c28 --- /dev/null +++ b/.github/native/release_probe.js @@ -0,0 +1,38 @@ +// Alternative Metro entrypoint, used only by the disposable release acceptance job. +// The production app entrypoint and bundle remain unchanged on disk. +import 'react-native-get-random-values'; +import React, { useEffect, useState } from 'react'; +import { AppRegistry, SafeAreaView, Text } from 'react-native'; +import Realm from 'realm'; +import schema from '../../src/storage/realm/schema'; +import * as storage from '../../src/storage'; +import { name as appName } from '../../app.json'; +import { runProbe, ProbeFailure } from './release_probe_core'; + +// No app services, Sentry, account creation, keychain, migrations or network imports. +let attempt; +function ReleaseProbe() { + const [result, setResult] = useState({ stage: 'running', code: '' }); + useEffect(() => { + let active = true; + // A remount must not advance the persistence phase in the same JS process. + if (!attempt) { + attempt = __DEV__ + ? runProbe({ Realm, schema, storage }).then( + (stage) => ({ stage, code: '' }), + (error) => ({ stage: 'failed', code: error instanceof ProbeFailure ? error.code : 'native-exception' }) + ) + : Promise.resolve({ stage: 'failed', code: 'development-only' }); + } + attempt.then((value) => { if (active) setResult(value); }); + return () => { active = false; }; + }, []); + return ( + + Keeper native probe {result.stage} + {result.code} + + ); +} + +AppRegistry.registerComponent(appName, () => ReleaseProbe); diff --git a/.github/native/release_probe.yaml b/.github/native/release_probe.yaml new file mode 100644 index 000000000..bc9fad6f5 --- /dev/null +++ b/.github/native/release_probe.yaml @@ -0,0 +1,32 @@ +appId: ${APP_ID} +name: Disposable native module persistence across process relaunch +--- +- launchApp: + clearState: true + permissions: + all: deny +- extendedWaitUntil: + visible: + id: native-probe-seeded + timeout: 60000 +- assertNotVisible: + id: native-probe-failed +- stopApp +- launchApp: + clearState: false +- extendedWaitUntil: + visible: + id: native-probe-mutated + timeout: 60000 +- assertNotVisible: + id: native-probe-failed +- stopApp +- launchApp: + clearState: false +- extendedWaitUntil: + visible: + id: native-probe-pass + timeout: 60000 +- assertNotVisible: + id: native-probe-failed +- stopApp diff --git a/.github/native/release_probe_core.js b/.github/native/release_probe_core.js new file mode 100644 index 000000000..c9903e122 --- /dev/null +++ b/.github/native/release_probe_core.js @@ -0,0 +1,144 @@ +/* CI-only native persistence acceptance. No accounts, network or fundable keys. */ +const PHASE_KEY = 'keeper-ci-release-probe-v1-phase'; +const MARKER_KEY = 'keeper-ci-release-probe-v1-marker'; +const PRIMARY = 'keeper-ci-synthetic-wallet'; +const OTHER = 'keeper-ci-synthetic-unrelated-wallet'; +const ROLLBACK = 'keeper-ci-synthetic-rolled-back-wallet'; +const SCHEMA_VERSION = 1; // Fresh current schema only; never an upgrade/migration claim. + +class ProbeFailure extends Error { + constructor(code) { + super(code); + this.code = code; + } +} + +function check(condition, code) { + if (!condition) throw new ProbeFailure(code); +} + +function wallet(id, name) { + return { + id, + entityKind: 'WALLET', + type: 'DEFAULT', + networkType: 'TESTNET', + scriptType: 'P2WPKH', + // Invalid public sentinel, deliberately unusable as an account/key fixture. + specs: { + xpub: 'CI-SYNTHETIC-NOT-A-KEY', + nextFreeAddressIndex: 0, + nextFreeChangeAddressIndex: 0, + totalExternalAddresses: 0, + confirmedUTXOs: [], + unconfirmedUTXOs: [], + balances: { confirmed: 0, unconfirmed: 0 }, + transactions: [], + hasNewUpdates: false, + lastSynched: 0, + }, + presentationData: { name, description: 'Disposable CI fixture', visibility: 'DEFAULT' }, + }; +} + +// Realm and storage are the actual native modules in release_probe.js. +// Injection exists solely to test failure/phase orchestration on non-native hosts. +async function runProbe({ Realm, schema, storage }) { + const phase = storage.getString(PHASE_KEY); + check(phase === undefined || phase === 'seeded' || phase === 'mutated', 'invalid-phase'); + const directory = Realm.defaultPath.slice(0, Realm.defaultPath.lastIndexOf('/') + 1); + check(directory.length > 0, 'missing-native-directory'); + // Published constants encrypt synthetic disposable data, never product secrets. + const config = (suffix, keyByte = 7) => ({ + path: `${directory}keeper-ci-release-probe-v1-${suffix}.realm`, + schema, + schemaVersion: SCHEMA_VERSION, + encryptionKey: new Uint8Array(64).fill(keyByte), + }); + const aConfig = config('a'); + const bConfig = config('b', 8); + let a; + let b; + try { + a = await Realm.open(aConfig); + b = await Realm.open(bConfig); + const get = (realm, id) => realm.objectForPrimaryKey('Wallet', id); + if (phase === undefined) { + check(a.objects('Wallet').length === 0 && b.objects('Wallet').length === 0, 'fixture-not-fresh'); + a.write(() => { + a.create('Wallet', wallet(PRIMARY, 'CI primary')); + a.create('Wallet', wallet(OTHER, 'CI unrelated')); + }); + b.write(() => b.create('Wallet', wallet(PRIMARY, 'CI separate database'))); + storage.setItem(MARKER_KEY, 'synthetic-marker-v1'); + storage.setItem(PHASE_KEY, 'seeded'); + return 'seeded'; + } + + check(storage.getString(MARKER_KEY) === 'synthetic-marker-v1', 'mmkv-marker-not-persisted'); + check(get(a, OTHER)?.presentationData.name === 'CI unrelated', 'unrelated-wallet-not-persisted'); + const otherSpecs = get(a, OTHER).specs; + check(otherSpecs.xpub === 'CI-SYNTHETIC-NOT-A-KEY' + && otherSpecs.balances.confirmed === 0 && otherSpecs.balances.unconfirmed === 0 + && otherSpecs.confirmedUTXOs.length === 0 && otherSpecs.transactions.length === 0, + 'embedded-wallet-state-not-persisted'); + check(get(b, PRIMARY)?.presentationData.name === 'CI separate database', 'separate-file-not-persisted'); + check(a.objects('Wallet').length === (phase === 'seeded' ? 2 : 1), 'unexpected-primary-record-count'); + check(b.objects('Wallet').length === 1, 'unexpected-separate-record-count'); + + if (phase === 'seeded') { + check(get(a, PRIMARY)?.presentationData.name === 'CI primary', 'primary-wallet-not-persisted'); + const aborted = new Error('intentional-synthetic-transaction-abort'); + let rolledBack = false; + try { + a.write(() => { + a.create('Wallet', wallet(ROLLBACK, 'CI rollback')); + throw aborted; + }); + } catch (error) { + if (error !== aborted) throw error; + rolledBack = true; + } + check(rolledBack && !get(a, ROLLBACK), 'transaction-rollback-failed'); + + // Close the correct-key handle first so rejection checks persisted file encryption. + a.close(); + a = undefined; + let rejected = false; + let wrongKeyRealm; + try { + wrongKeyRealm = await Realm.open(config('a', 9)); + } catch { + rejected = true; + } finally { + if (wrongKeyRealm) wrongKeyRealm.close(); + } + check(rejected, 'wrong-encryption-key-accepted'); + a = await Realm.open(aConfig); + check(get(a, PRIMARY)?.presentationData.name === 'CI primary', 'correct-key-reopen-failed'); + // Deliberately only Realm deletion semantics; no claim about product key deletion. + a.write(() => a.delete(get(a, PRIMARY))); + check(!get(a, PRIMARY) && get(a, OTHER), 'targeted-wallet-delete-failed'); + storage.setItem(PHASE_KEY, 'mutated'); + return 'mutated'; + } + + check(!get(a, PRIMARY) && !get(a, ROLLBACK), 'delete-or-rollback-not-persisted'); + a.close(); + b.close(); + a = undefined; + b = undefined; + Realm.deleteFile(aConfig); + Realm.deleteFile(bConfig); + storage.deleteItem(MARKER_KEY); + storage.deleteItem(PHASE_KEY); + check(storage.getString(MARKER_KEY) === undefined && storage.getString(PHASE_KEY) === undefined, + 'fixture-cleanup-failed'); + return 'pass'; + } finally { + if (a) a.close(); + if (b) b.close(); + } +} + +module.exports = { runProbe, ProbeFailure, PHASE_KEY, MARKER_KEY, PRIMARY, OTHER, ROLLBACK }; diff --git a/.github/tests/release-evidence.test.cjs b/.github/tests/release-evidence.test.cjs new file mode 100644 index 000000000..fd818601f --- /dev/null +++ b/.github/tests/release-evidence.test.cjs @@ -0,0 +1,61 @@ +const assert = require('node:assert/strict'); +const { test } = require('node:test'); +const { evidence } = require('../native/release_evidence.cjs'); +function fixture() { + const repository = 'KeeperCommunity/bitcoin-keeper'; + const pr = { number: 7058, head: { sha: 'a'.repeat(40), ref: 'future-release', + repo: { full_name: repository, id: 1 } }, base: { sha: 'b'.repeat(40), ref: 'sprint', + repo: { full_name: repository, id: 1 } } }; + const context = { repo: { owner: 'KeeperCommunity', repo: 'bitcoin-keeper' }, + eventName: 'pull_request', runId: 90, payload: { pull_request: pr } }; + const run = { id: 90, run_attempt: 2, path: '.github/workflows/keeper-release-acceptance.yml', + event: 'pull_request', head_sha: pr.head.sha, head_branch: pr.head.ref, + head_repository: pr.head.repo, pull_requests: [structuredClone(pr)], status: 'in_progress' }; + const jobs = ['IOS', 'ANDROID'].map(platform => ({ + name: `${platform.toLowerCase()} / Native ${platform} build and probes`, head_sha: pr.head.sha, + run_id: 90, run_attempt: 2, status: 'completed', conclusion: 'success', + steps: ['Build development app', ...(platform === 'IOS' + ? ['Run disposable startup smoke', 'Run disposable native persistence probe'] + : ['Run Android startup and native persistence probes'])].map(name => + ({ name, status: 'completed', conclusion: 'success' })), + })); + const state = { runs: [run], jobs, context, input: { ios: 'success', android: 'success', attempt: 2 }, calls: [] }; + const runsAPI = () => {}; const jobsAPI = () => {}; + state.github = { rest: { actions: { listWorkflowRuns: runsAPI, listJobsForWorkflowRunAttempt: jobsAPI } }, + paginate: async (api, args) => { state.calls.push(args); if (state.error) throw new Error('private'); + return api === runsAPI ? [...state.runs] : state.jobs; } }; + state.check = () => evidence(state.github, state.context, state.input); + return state; +} +test('current in-progress summary credits both completed exact-attempt native jobs only', async () => { + const state = fixture(); assert.equal(await state.check(), true); + assert.equal(state.calls[1].attempt_number, 2); + assert.equal(state.calls[0].head_sha, state.context.payload.pull_request.head.sha); +}); +test('latest run and attempt prevent summary-only partial reruns and older-run reuse', async () => { + for (const mutate of [s => { s.jobs.pop(); }, s => { s.jobs[0].run_attempt = 1; }, + s => { s.runs[0].run_attempt = 3; }, s => { s.runs.push({ ...s.runs[0], id: 91 }); }]) { + const state = fixture(); mutate(state); assert.equal(await state.check(), false); + } +}); +test('wrong source, workflow, event, PR association and repository provide no evidence', async () => { + for (const mutate of [s => { s.runs[0].head_sha = 'c'.repeat(40); }, + s => { s.runs[0].path = 'other.yml'; }, s => { s.runs[0].event = 'push'; }, + s => { s.runs[0].head_branch = 'other'; }, s => { s.runs[0].head_repository = { id: 9 }; }, + s => { s.runs[0].pull_requests[0].number += 1; }, + s => { s.runs[0].pull_requests[0].base.sha = 'c'.repeat(40); }]) { + const state = fixture(); mutate(state); assert.equal(await state.check(), false); + } +}); +test('failed/skipped/pending jobs, build-only results and ambiguous steps cannot pass', async () => { + for (const mutate of [s => { s.jobs[0].conclusion = 'failure'; }, + s => { s.jobs[1].status = 'in_progress'; }, s => { s.jobs[0].steps.pop(); }, + s => { s.jobs[1].steps[1].conclusion = 'skipped'; }, s => { s.jobs.push(s.jobs[0]); }, + s => { s.jobs[0].steps.push(s.jobs[0].steps[0]); }, s => { s.input.android = 'skipped'; }, + s => { s.context.payload.pull_request.number = 7045; }, + s => { s.context.payload.pull_request.head.repo.full_name = 'fork/bitcoin-keeper'; }, + s => { s.runs[0].status = 'queued'; }, + s => { Object.assign(s.runs[0], { status: 'completed', conclusion: 'cancelled' }); }, s => { s.error = true; }]) { + const state = fixture(); mutate(state); assert.equal(await state.check(), false); + } +}); diff --git a/.github/tests/release-pipeline.test.cjs b/.github/tests/release-pipeline.test.cjs new file mode 100644 index 000000000..459d06002 --- /dev/null +++ b/.github/tests/release-pipeline.test.cjs @@ -0,0 +1,334 @@ +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const path = require('node:path'); +const vm = require('node:vm'); +const { test } = require('node:test'); +const { WORKFLOWS, fingerprint, preflight } = require('../native/release_preflight.cjs'); +const { REQUIRED, acceptance, markdown } = require('../native/release_acceptance.cjs'); + +// GitHub metadata models only: these tests supply no native or release evidence. +const repository = 'KeeperCommunity/bitcoin-keeper'; +const repositoryId = 470904030; +const headSha = 'a'.repeat(40); +const baseSha = 'b'.repeat(40); +const runBaseSha = 'c'.repeat(40); +const NATIVE_FILES = [ + 'hosted_native.py', 'startup.yaml', 'nodeify.cjs', 'release_preflight.cjs', + 'release_acceptance.cjs', 'release_evidence.cjs', 'release_metro.cjs', 'release_probe.js', + 'release_probe_core.js', 'release_probe.yaml', +].map(name => '.github/native/' + name); +const clone = value => structuredClone(value); + +function trustedTree() { + const paths = [...WORKFLOWS, ...NATIVE_FILES, 'src/index.ts']; + return { + truncated: false, + tree: paths.map((path, index) => ({ + path, mode: '100644', type: 'blob', sha: (index + 1).toString(16).padStart(40, '0'), + })), + }; +} + +function pullRequest() { + return { + number: 7058, + head: { sha: headSha, ref: 'codex/future-release', + repo: { full_name: repository, id: repositoryId } }, + base: { sha: baseSha, ref: 'sprint', + repo: { full_name: repository, id: repositoryId } }, + }; +} + +async function evaluate(options = {}) { + const original = pullRequest(); + original.base.sha = runBaseSha; + const current = pullRequest(); + options.original?.(original); + options.current?.(current); + const latest = clone(current); + options.latest?.(latest); + const calls = []; + let reads = 0; + const github = { + rest: { + pulls: { + get: async args => { + calls.push({ api: 'pulls.get', ...args }); + reads += 1; + if (options.pullError) throw new Error('Private API detail must not be reported'); + return { data: clone(reads === 1 ? current : latest) }; + }, + }, + git: { + getTree: async args => { + calls.push({ api: 'git.getTree', ...args }); + if (options.treeError === args.tree_sha) throw new Error('Private API detail'); + return { data: clone(options.trees?.[args.tree_sha] ?? trustedTree()) }; + }, + }, + }, + }; + const context = { + eventName: options.eventName ?? 'pull_request', + repo: { owner: 'KeeperCommunity', repo: 'bitcoin-keeper' }, + payload: { pull_request: options.withoutPR ? undefined : original }, + }; + return { result: await preflight(github, context), calls }; +} + +test('unchanged reviewed CI on app/current-base/run-base yields exact-head preflight only', async () => { + const { result, calls } = await evaluate(); + assert.equal(result.trusted, true); + assert.equal(calls.filter(call => call.api === 'pulls.get').length, 2); + assert.deepEqual(calls.filter(call => call.api === 'git.getTree').map(call => call.tree_sha), + [headSha, baseSha, runBaseSha]); + assert.ok(calls.filter(call => call.api === 'git.getTree').every(call => call.recursive === '1')); + assert.ok(calls.every(call => !/create|update|dispatch|status/.test(call.api))); +}); + +test('all later same-repository release PRs use the same preflight without release-number routing', async () => { + for (const number of [7058, 8001, 12000]) { + const { result } = await evaluate({ + original: pr => { pr.number = number; }, + current: pr => { pr.number = number; }, + }); + assert.equal(result.trusted, true, String(number)); + } +}); + +test('R4 is excluded before any API read, even when its source otherwise matches', async () => { + const { result, calls } = await evaluate({ original: pr => { pr.number = 7045; } }); + assert.equal(result.trusted, false); + assert.match(result.reason, /R4/); + assert.deepEqual(calls, []); +}); + +test('non-PR events and missing PR metadata never trigger native authorization', async () => { + for (const options of [{ eventName: 'workflow_dispatch' }, { eventName: 'pull_request_target' }, + { eventName: 'push' }, { withoutPR: true }]) { + const { result, calls } = await evaluate(options); + assert.equal(result.trusted, false); + assert.deepEqual(calls, []); + } +}); + +test('forks, wrong target branches, stale payloads and repository-ID drift fail before tree reads', async () => { + const mutations = [ + pr => { pr.head.repo = { full_name: 'fork/bitcoin-keeper', id: 123 }; }, + pr => { pr.base.repo.full_name = 'fork/bitcoin-keeper'; }, + pr => { pr.base.ref = 'other-base'; }, + pr => { pr.head.ref = 'other-head'; }, + pr => { pr.head.sha = 'd'.repeat(40); }, + pr => { pr.head.sha = 'not-a-sha'; }, + pr => { pr.head.repo.id += 1; }, + pr => { pr.base.repo.id += 1; }, + pr => { delete pr.head.repo; }, + pr => { delete pr.base.repo.id; }, + ]; + for (const current of mutations) { + const { result, calls } = await evaluate({ current }); + assert.equal(result.trusted, false); + assert.equal(calls.filter(call => call.api === 'git.getTree').length, 0); + } +}); + +test('source or base movement while checking provenance cannot receive current-head credit', async () => { + for (const latest of [pr => { pr.head.sha = 'd'.repeat(40); }, + pr => { pr.base.sha = 'd'.repeat(40); }]) { + const { result } = await evaluate({ latest }); + assert.equal(result.trusted, false); + assert.match(result.reason, /changed|provenance/); + } +}); + +test('retargeting or repository/ref identity drift at unchanged SHAs is still a race', async () => { + for (const latest of [pr => { pr.base.ref = 'another-branch-at-same-sha'; }, + pr => { pr.head.ref = 'another-head-at-same-sha'; }, + pr => { pr.base.repo.id += 1; }, pr => { pr.head.repo.id += 1; }, + pr => { pr.base.repo.full_name = 'fork/bitcoin-keeper'; }, + pr => { pr.head.repo.full_name = 'fork/bitcoin-keeper'; }]) { + const { result } = await evaluate({ latest }); + assert.equal(result.trusted, false); + } +}); + +test('every workflow/harness addition, deletion, content, mode or type mutation denies trust in each snapshot', async () => { + for (const ref of [headSha, baseSha, runBaseSha]) { + for (const target of [...WORKFLOWS, ...NATIVE_FILES]) { + for (const mutation of ['content', 'delete', 'mode', 'type']) { + const tree = trustedTree(); + const index = tree.tree.findIndex(entry => entry.path === target); + if (mutation === 'content') tree.tree[index].sha = 'f'.repeat(40); + if (mutation === 'delete') tree.tree.splice(index, 1); + if (mutation === 'mode') tree.tree[index].mode = '100755'; + if (mutation === 'type') tree.tree[index].type = 'commit'; + const { result } = await evaluate({ trees: { [ref]: tree } }); + assert.equal(result.trusted, false, `${ref}:${target}:${mutation}`); + } + } + const tree = trustedTree(); + tree.tree.push({ path: '.github/native/unreviewed-helper.cjs', mode: '100644', + type: 'blob', sha: 'f'.repeat(40) }); + assert.equal((await evaluate({ trees: { [ref]: tree } })).result.trusted, false); + } +}); + +test('bootstrap is unavailable when any transitive workflow/native dependency is absent from every snapshot', async () => { + for (const missing of [...WORKFLOWS, ...NATIVE_FILES]) { + const tree = trustedTree(); + tree.tree = tree.tree.filter(entry => entry.path !== missing); + const { result } = await evaluate({ trees: { + [headSha]: tree, [baseSha]: tree, [runBaseSha]: tree, + } }); + assert.equal(result.trusted, false, missing); + } +}); + +test('required infrastructure symlinks cannot move executable dependencies outside the fingerprint', async () => { + for (const target of [...WORKFLOWS, ...NATIVE_FILES]) { + const tree = trustedTree(); + tree.tree.find(entry => entry.path === target).mode = '120000'; + const { result } = await evaluate({ trees: { + [headSha]: tree, [baseSha]: tree, [runBaseSha]: tree, + } }); + assert.equal(result.trusted, false, target); + } +}); + +test('truncated or unavailable GitHub trees fail closed with bounded public reasons', async () => { + for (const ref of [headSha, baseSha, runBaseSha]) { + const tree = trustedTree(); + tree.truncated = true; + for (const options of [{ trees: { [ref]: tree } }, { treeError: ref }]) { + const { result } = await evaluate(options); + assert.equal(result.trusted, false); + assert.doesNotMatch(result.reason, /Private API detail/); + } + } +}); + +test('fingerprinting is order independent and ordinary app changes are outside CI provenance', async () => { + const tree = trustedTree(); + tree.tree.reverse(); + assert.equal(fingerprint(tree), fingerprint(trustedTree())); + tree.tree.find(entry => entry.path === 'src/index.ts').sha = 'f'.repeat(40); + const { result } = await evaluate({ trees: { [headSha]: tree } }); + assert.equal(result.trusted, true); +}); + +test('two successful native jobs record only their implemented scope and never imply release readiness', () => { + const result = acceptance({ trusted: true, ios: 'success', android: 'success' }); + assert.equal(result.release_ready, false); + assert.equal(result.phase_a, 'BLOCKED'); + assert.deepEqual(result.cases.map(scenario => scenario.id), REQUIRED); + assert.deepEqual(result.cases.slice(0, 2).map(scenario => scenario.status), ['PASS', 'PASS']); + assert.ok(result.cases.slice(2).every(scenario => scenario.status === 'NOT IMPLEMENTED')); + assert.match(result.cases[1].scope, /not application account isolation/); + assert.match(result.signing, /NOT IMPLEMENTED.*NOT VERIFIED/); + assert.match(result.physical, /NOT RUN/); +}); + +test('failed, skipped, cancelled, pending or missing platform jobs provide no matrix credit', () => { + for (const value of [undefined, null, '', 'failure', 'skipped', 'cancelled', 'pending', + 'in_progress', 'neutral', 'SUCCESS', true]) { + for (const platform of ['ios', 'android']) { + const result = acceptance({ trusted: true, ios: 'success', android: 'success', [platform]: value }); + assert.ok(result.cases.slice(0, 2).every(scenario => scenario.status === 'NOT VERIFIED'), + `${platform}:${value}`); + assert.equal(result.release_ready, false); + assert.equal(result.phase_a, 'BLOCKED'); + } + } +}); + +test('only a boolean trusted preflight permits implemented native scope to receive PASS', () => { + for (const trusted of [undefined, null, false, 'true', 1, {}]) { + const result = acceptance({ trusted, ios: 'success', android: 'success' }); + assert.ok(result.cases.slice(0, 2).every(scenario => scenario.status === 'NOT VERIFIED')); + assert.equal(result.release_ready, false); + } +}); + +test('human-readable acceptance preserves all blocked scenarios and separate signing/physical requirements', () => { + const result = acceptance({ trusted: true, ios: 'success', android: 'success' }); + const text = markdown(result); + assert.match(text, /Phase A release acceptance: BLOCKED/); + assert.match(text, /cannot approve a release/); + for (const id of REQUIRED) assert.ok(text.includes(id)); + assert.match(text, /NOT IMPLEMENTED/); + assert.match(text, /exact distributed artifact required/); +}); + +test('Phase A caller and reusable worker expose no production-secret, protected-environment or privileged-event path', () => { + // The inherited #7060 workflow is independently reviewed; protect new Phase A execution here. + for (const filename of WORKFLOWS.filter(name => !name.endsWith('/keeper-hosted-native.yml'))) { + const source = fs.readFileSync(path.join(__dirname, '../..', filename), 'utf8') + .split('\n').filter(line => !line.trimStart().startsWith('#')).join('\n'); + // Static security policy: these constructs change the runner trust boundary. + assert.doesNotMatch(source, /^\s*(?:secrets|environment)\s*:/m, filename); + assert.doesNotMatch(source, /\bsecrets\s*\./, filename); + assert.doesNotMatch(source, /^\s*(?:pull_request_target|workflow_dispatch|repository_dispatch)\s*:/m, + filename); + assert.doesNotMatch(source, /^\s*[\w-]+:\s*write\s*$/m, filename); + assert.doesNotMatch(source, /\bfastlane\b|\bgh\s+release\b/, filename); + for (const match of source.matchAll(/^\s*(?:-\s*)?uses:\s*(\S+)/gm)) { + assert.ok(match[1].startsWith('./.github/workflows/') || /@[a-f0-9]{40}$/.test(match[1]), + `${filename}: unpinned dependency ${match[1]}`); + } + } +}); + +function probeMiddleware(enhanced) { + const seen = []; + const original = (request, response, next) => { + seen.push({ url: request.url, response, next }); + return 'served'; + }; + const base = { resolver: { preserved: true }, server: { preserveSetting: true } }; + let enhancementCalls = 0; + if (enhanced) base.server.enhanceMiddleware = (inner, server) => { + enhancementCalls += 1; + assert.equal(inner, original); + assert.equal(server.marker, true); + return (request, response, next) => original(request, response, next); + }; + const file = path.join(__dirname, '../native/release_metro.cjs'); + const context = { + __dirname: path.dirname(file), module: { exports: {} }, + require: name => { + if (name === '../../metro.config') return base; + if (name === 'node:path') return path; + throw new Error('Unexpected Metro dependency: ' + name); + }, + }; + vm.runInNewContext(fs.readFileSync(file, 'utf8'), context, { filename: file }); + const config = context.module.exports; + assert.equal(config.resolver, base.resolver); + assert.equal(config.server.preserveSetting, true); + assert.equal(config.projectRoot, path.resolve(__dirname, '../..')); + assert.equal(base.projectRoot, undefined); + return { middleware: config.server.enhanceMiddleware(original, { marker: true }), + seen, getEnhancementCalls: () => enhancementCalls }; +} + +test('CI Metro remaps only the native entrypoint while preserving query, source maps and base middleware', () => { + for (const enhanced of [true, false]) { + const state = probeMiddleware(enhanced); + const cases = [ + ['/index.bundle?platform=ios&dev=true', '/.github/native/release_probe.bundle?platform=ios&dev=true'], + ['/index.map?platform=android', '/.github/native/release_probe.map?platform=android'], + ['/index.bundle', '/.github/native/release_probe.bundle'], + ['/status', '/status'], + ['/nested/index.bundle?platform=ios', '/nested/index.bundle?platform=ios'], + ['/index.bundle.other?platform=ios', '/index.bundle.other?platform=ios'], + ['/another.bundle?platform=android', '/another.bundle?platform=android'], + ]; + for (const [url, expected] of cases) { + const response = {}; + const next = () => {}; + assert.equal(state.middleware({ url }, response, next), 'served'); + assert.deepEqual(state.seen.at(-1), { url: expected, response, next }); + } + assert.equal(state.getEnhancementCalls(), enhanced ? 1 : 0); + } +}); diff --git a/.github/tests/release-probe.test.cjs b/.github/tests/release-probe.test.cjs new file mode 100644 index 000000000..5f702b7e1 --- /dev/null +++ b/.github/tests/release-probe.test.cjs @@ -0,0 +1,135 @@ +/* Host-only orchestration tests. This model supplies NO native platform evidence. */ +const assert = require('node:assert/strict'); +const { test } = require('node:test'); +const { runProbe, PHASE_KEY, MARKER_KEY, PRIMARY, OTHER, ROLLBACK } = require('../native/release_probe_core'); + +function fixture(bugs = {}) { + const disk = new Map(); + const values = new Map([['unrelated-storage-key', 'preserve']]); + const handles = new Set(); + const storage = { + getString: (key) => values.get(key), + setItem: (key, value) => values.set(key, value), + deleteItem: (key) => values.delete(key), + }; + const Realm = { + defaultPath: '/synthetic-device/default.realm', + async open(config) { + const key = config.encryptionKey[0]; + if (!disk.has(config.path)) disk.set(config.path, { key, wallets: new Map() }); + const file = disk.get(config.path); + if (key !== file.key && !bugs.acceptWrongKey) throw new Error('modeled wrong key'); + const handle = { + objectForPrimaryKey: (_table, id) => file.wallets.get(id), + objects: () => [...file.wallets.values()], + write(callback) { + const before = structuredClone(file.wallets); + try { + callback(); + } catch (error) { + if (!bugs.skipRollback) file.wallets = before; + throw error; + } + }, + create(_table, value) { file.wallets.set(value.id, structuredClone(value)); }, + delete(value) { if (!bugs.skipDelete) file.wallets.delete(value.id); }, + close() { handles.delete(handle); }, + }; + handles.add(handle); + return handle; + }, + deleteFile(config) { + if (bugs.cleanupFailure) throw new Error('modeled cleanup failure'); + disk.delete(config.path); + }, + }; + return { + options: { Realm, schema: [], storage }, disk, values, handles, + a: () => disk.get('/synthetic-device/keeper-ci-release-probe-v1-a.realm'), + }; +} + +test('three process phases require persisted state and clean only disposable fixture', async () => { + const state = fixture(); + assert.equal(await runProbe(state.options), 'seeded'); + assert.equal(state.handles.size, 0); + assert.equal(state.values.get(PHASE_KEY), 'seeded'); + assert.equal(await runProbe(state.options), 'mutated'); + assert.equal(state.handles.size, 0); + assert.equal(state.a().wallets.has(PRIMARY), false); + assert.equal(state.a().wallets.has(OTHER), true); + assert.equal(state.a().wallets.has(ROLLBACK), false); + assert.equal(await runProbe(state.options), 'pass'); + assert.equal(state.handles.size, 0); + assert.equal(state.disk.size, 0); + assert.deepEqual([...state.values], [['unrelated-storage-key', 'preserve']]); +}); + +test('missing persisted MMKV marker cannot progress after relaunch', async () => { + const state = fixture(); + await runProbe(state.options); + state.values.delete(MARKER_KEY); + await assert.rejects(runProbe(state.options), { code: 'mmkv-marker-not-persisted' }); + assert.equal(state.values.get(PHASE_KEY), 'seeded'); + assert.equal(state.handles.size, 0); +}); + +test('wrong-key acceptance fails closed before wallet deletion', async () => { + const state = fixture({ acceptWrongKey: true }); + await runProbe(state.options); + await assert.rejects(runProbe(state.options), { code: 'wrong-encryption-key-accepted' }); + assert.equal(state.a().wallets.has(PRIMARY), true); + assert.equal(state.handles.size, 0); +}); + +test('corruption of embedded wallet balances cannot pass', async () => { + const state = fixture(); + await runProbe(state.options); + state.a().wallets.get(OTHER).specs.balances.confirmed = 1; + await assert.rejects(runProbe(state.options), { code: 'embedded-wallet-state-not-persisted' }); + assert.equal(state.values.get(PHASE_KEY), 'seeded'); + assert.equal(state.handles.size, 0); +}); + +test('failed transaction rollback cannot progress', async () => { + const state = fixture({ skipRollback: true }); + await runProbe(state.options); + await assert.rejects(runProbe(state.options), { code: 'transaction-rollback-failed' }); + assert.equal(state.values.get(PHASE_KEY), 'seeded'); + assert.equal(state.handles.size, 0); +}); + +test('failed deletion cannot advance persistence marker', async () => { + const state = fixture({ skipDelete: true }); + await runProbe(state.options); + await assert.rejects(runProbe(state.options), { code: 'targeted-wallet-delete-failed' }); + assert.equal(state.values.get(PHASE_KEY), 'seeded'); + assert.equal(state.handles.size, 0); +}); + +test('lost deletion after second relaunch cannot pass', async () => { + const state = fixture(); + await runProbe(state.options); + const original = structuredClone(state.a().wallets.get(PRIMARY)); + await runProbe(state.options); + state.a().wallets.set(PRIMARY, original); + await assert.rejects(runProbe(state.options), { code: 'unexpected-primary-record-count' }); + assert.equal(state.values.get(PHASE_KEY), 'mutated'); + assert.equal(state.handles.size, 0); +}); + +test('fixture cleanup failure cannot produce pass', async () => { + const state = fixture({ cleanupFailure: true }); + await runProbe(state.options); + await runProbe(state.options); + await assert.rejects(runProbe(state.options), /modeled cleanup failure/); + assert.equal(state.values.get(PHASE_KEY), 'mutated'); + assert.equal(state.handles.size, 0); +}); + +test('unknown phase stops before accessing native databases', async () => { + const state = fixture(); + state.values.set(PHASE_KEY, 'unexpected'); + await assert.rejects(runProbe(state.options), { code: 'invalid-phase' }); + assert.equal(state.disk.size, 0); +}); diff --git a/.github/tests/test_release_native.py b/.github/tests/test_release_native.py new file mode 100644 index 000000000..86e177949 --- /dev/null +++ b/.github/tests/test_release_native.py @@ -0,0 +1,150 @@ +"""Host-only Phase A harness contracts; no native runtime or platform credit.""" +import contextlib +import importlib.util +from pathlib import Path +import tempfile +import unittest +from unittest import mock + + +SPEC = importlib.util.spec_from_file_location( + 'release_native', Path(__file__).resolve().parents[1] / 'native' / 'hosted_native.py') +native = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(native) + + +class ReleaseJunitTest(unittest.TestCase): + def setUp(self): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + self.report = Path(directory.name) / 'probe.xml' + + def test_actual_success_cases_are_required(self): + self.report.write_text('' + '') + self.assertEqual(native.successful_junit(self.report), 1) + + def test_missing_empty_oversized_or_malformed_report_never_passes(self): + with self.assertRaises(RuntimeError): + native.successful_junit(self.report) + for content in ['', '', 'x' * (1024 * 1024 + 1), '<{tag}/>') + with self.assertRaises(RuntimeError): + native.successful_junit(self.report) + for status in ['ERROR', 'FAILED', 'SKIPPED', 'PENDING', '']: + with self.subTest(status=status): + self.report.write_text(f'') + with self.assertRaises(RuntimeError): + native.successful_junit(self.report) + + def test_declared_suite_failures_without_child_details_never_pass(self): + for field in ['failures', 'errors', 'skipped']: + with self.subTest(field=field): + self.report.write_text(f'') + with self.assertRaises(RuntimeError): + native.successful_junit(self.report) + + +class ReleaseNativeExecutionTest(unittest.TestCase): + def setUp(self): + directory = tempfile.TemporaryDirectory() + self.addCleanup(directory.cleanup) + self.root = Path(directory.name) + self.private = self.root / 'private' + self.private.mkdir() + patch = mock.patch.multiple(native, ROOT=self.root, PRIVATE=self.private, + EVIDENCE=self.root / 'metadata.json', PLATFORM='ANDROID') + patch.start() + self.addCleanup(patch.stop) + self.identity = {'sha256': 'synthetic-artifact-identity'} + native.save({'commands': [], 'build': 'PASS', 'smoke': 'PASS', 'native_probe': 'NOT RUN', + 'built_artifact': self.identity, 'maestro': {'binary': 'synthetic-maestro'}, + 'toolchain': {}}) + + def exercise(self, after_identity=None, maestro_failure=False, report_failure=False, report_missing=False): + def command(args, label, **kwargs): + if '--format' in args: + if maestro_failure: + raise RuntimeError('PRIVATE_SENTINEL native failure') + if not report_missing: + (self.private / 'probe-junit.xml').write_text( + '' + + ('' if report_failure else '') + '') + return 'synthetic-device' + + process = mock.Mock(pid=12345) + process.poll.return_value = None + response = mock.MagicMock() + response.__enter__.return_value.read.return_value = b'packager-status:running' + stack = contextlib.ExitStack() + self.addCleanup(stack.close) + stack.enter_context(mock.patch.object(native.subprocess, 'check_call')) + stack.enter_context(mock.patch.object(native.subprocess, 'Popen', return_value=process)) + stack.enter_context(mock.patch.object(native.subprocess, 'run')) + stack.enter_context(mock.patch.object(native.os, 'killpg')) + stack.enter_context(mock.patch.object(native.urllib.request, 'urlopen', return_value=response)) + stack.enter_context(mock.patch.object(native, 'command', side_effect=command)) + stack.enter_context(mock.patch.object(native, 'warm_metro_bundle')) + stack.enter_context(mock.patch.object(native, 'android_sdk_metadata', return_value={})) + stack.enter_context(mock.patch.object(native, 'artifact_identity', + side_effect=[self.identity, after_identity or self.identity])) + native.run_phase('probe') + + def test_probe_requires_actual_app_smoke_first(self): + data = native.read() + data['smoke'] = 'NOT RUN' + native.save(data) + with mock.patch.object(native.subprocess, 'check_call'), \ + mock.patch.object(native.subprocess, 'Popen') as popen: + with self.assertRaisesRegex(RuntimeError, 'app startup smoke'): + native.run_phase('probe') + popen.assert_not_called() + self.assertEqual(native.read()['native_probe'], 'FAIL') + + def test_changed_artifact_before_probe_stops_before_runtime(self): + with mock.patch.object(native.subprocess, 'check_call'), \ + mock.patch.object(native, 'artifact_identity', return_value={'sha256': 'changed'}), \ + mock.patch.object(native.subprocess, 'Popen') as popen: + with self.assertRaisesRegex(RuntimeError, 'artifact changed'): + native.run_phase('probe') + popen.assert_not_called() + self.assertEqual(native.read()['native_probe'], 'FAIL') + + def test_probe_success_is_distinct_from_application_acceptance(self): + self.exercise() + data = native.read() + self.assertEqual(data['native_probe'], 'PASS') + self.assertEqual(data['native_probe_test_cases'], 1) + self.assertIn('NOT app key deletion', data['probe_scope']) + self.assertNotIn('release_ready', data) + + def test_artifact_change_during_execution_cannot_pass(self): + with self.assertRaisesRegex(RuntimeError, 'artifact changed during'): + self.exercise(after_identity={'sha256': 'changed'}) + self.assertEqual(native.read()['native_probe'], 'FAIL') + + def test_missing_new_report_cannot_reuse_stale_success(self): + (self.private / 'probe-junit.xml').write_text('') + with self.assertRaisesRegex(RuntimeError, 'Missing or oversized'): + self.exercise(report_missing=True) + self.assertEqual(native.read()['native_probe'], 'FAIL') + + def test_failed_native_command_or_report_never_exports_raw_data_or_passes(self): + for command_failure in [True, False]: + with self.subTest(command_failure=command_failure): + with self.assertRaises(RuntimeError): + self.exercise(maestro_failure=command_failure, report_failure=not command_failure) + self.assertEqual(native.read()['native_probe'], 'FAIL') + self.assertNotIn('PRIVATE_SENTINEL', native.EVIDENCE.read_text()) + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/workflows/keeper-native-platform.yml b/.github/workflows/keeper-native-platform.yml new file mode 100644 index 000000000..08e14b698 --- /dev/null +++ b/.github/workflows/keeper-native-platform.yml @@ -0,0 +1,121 @@ +name: Keeper reusable native platform + +on: + workflow_call: + inputs: + source_sha: + type: string + required: true + platform: + type: string + required: true + +# This worker has no environment, release credentials, secret inputs or dispatch. +permissions: + contents: read + +jobs: + native: + name: Native ${{ inputs.platform }} build and probes + if: github.event_name == 'pull_request' && github.event.pull_request.number != 7045 && inputs.source_sha == github.event.pull_request.head.sha + runs-on: ${{ inputs.platform == 'IOS' && 'macos-15' || 'ubuntu-24.04' }} + timeout-minutes: 75 + env: + CI: 'true' + HUSKY: '0' + KEEPER_SOURCE_SHA: ${{ inputs.source_sha }} + KEEPER_NATIVE_PLATFORM: ${{ inputs.platform }} + MAESTRO_CLI_NO_ANALYTICS: '1' + steps: + - name: Check out exact app source + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ inputs.source_sha }} + persist-credentials: false + - name: Set up Node + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6 + with: + node-version: '22.23.3' + cache: yarn + - name: Set up Java + uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5 + with: + distribution: temurin + java-version: '17' + cache: gradle + - name: Set up Ruby + if: inputs.platform == 'IOS' + uses: ruby/setup-ruby@675dd7ba1b06c8786a1480d89c384f5620a42647 # v1.281.0 + with: + ruby-version: '3.3.8' + - name: Select reviewed Xcode + if: inputs.platform == 'IOS' + run: echo 'DEVELOPER_DIR=/Applications/Xcode_16.4.app/Contents/Developer' >> "$GITHUB_ENV" + - name: Set up Android command-line tools + if: inputs.platform == 'ANDROID' + uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4 + with: + cmdline-tools-version: '13114758' + packages: platform-tools + log-accepted-android-sdk-licenses: false + - name: Record runner and toolchain + run: python3 .github/native/hosted_native.py record + - name: Install immutable native dependencies + run: python3 .github/native/hosted_native.py prepare + - name: Check disposable iOS driver readiness + if: inputs.platform == 'IOS' + run: | + test "$(git rev-parse HEAD)" = '${{ inputs.source_sha }}' + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py driver + - name: Build development app + run: | + test "$(git rev-parse HEAD)" = '${{ inputs.source_sha }}' + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py build + - name: Run disposable startup smoke + if: inputs.platform == 'IOS' + run: | + test "$(git rev-parse HEAD)" = '${{ inputs.source_sha }}' + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py smoke + - name: Run disposable native persistence probe + if: inputs.platform == 'IOS' + run: | + test "$(git rev-parse HEAD)" = '${{ inputs.source_sha }}' + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py probe + - name: Enable emulator acceleration + if: inputs.platform == 'ANDROID' + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-keeper-kvm.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + - name: Run Android startup and native persistence probes + if: inputs.platform == 'ANDROID' + uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # v2.34.0 + with: + api-level: 35 + target: google_apis + arch: x86_64 + profile: pixel_6 + cores: 2 + ram-size: 3072M + force-avd-creation: true + disable-animations: true + emulator-boot-timeout: 240 + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -no-snapshot -camera-back none -camera-front none + script: | + test "$(git rev-parse HEAD)" = '${{ inputs.source_sha }}' + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py smoke + git diff --exit-code HEAD -- .github/native .github/workflows + python3 .github/native/hosted_native.py probe + - name: Retain safe Phase A evidence + if: always() + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6 + with: + name: keeper-release-native-${{ inputs.platform }}-${{ inputs.source_sha }} + path: artifacts/native/*/metadata.json + if-no-files-found: error + retention-days: 7 diff --git a/.github/workflows/keeper-release-acceptance.yml b/.github/workflows/keeper-release-acceptance.yml new file mode 100644 index 000000000..06055cb94 --- /dev/null +++ b/.github/workflows/keeper-release-acceptance.yml @@ -0,0 +1,83 @@ +name: Keeper release acceptance + +on: + pull_request: + branches: [sprint] + types: [opened, synchronize, reopened, ready_for_review] + +permissions: + contents: read + pull-requests: read + actions: read + +concurrency: + group: keeper-release-acceptance-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + provenance: + name: Reviewed CI bootstrap and exact-head provenance + # Freeze the existing R4 release and its gate, even after future CI installation. + if: github.event.pull_request.number != 7045 + runs-on: ubuntu-24.04 + timeout-minutes: 5 + outputs: + trusted: ${{ steps.check.outputs.trusted }} + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + - id: check + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 + with: + script: | + const { preflight } = require('./.github/native/release_preflight.cjs'); + const result = await preflight(github, context); + core.setOutput('trusted', String(result.trusted)); + await core.summary.addHeading('Phase A provenance').addRaw(result.reason).write(); + + ios: + needs: provenance + if: needs.provenance.outputs.trusted == 'true' + uses: ./.github/workflows/keeper-native-platform.yml + with: + source_sha: ${{ github.event.pull_request.head.sha }} + platform: IOS + + android: + needs: provenance + if: needs.provenance.outputs.trusted == 'true' + uses: ./.github/workflows/keeper-native-platform.yml + with: + source_sha: ${{ github.event.pull_request.head.sha }} + platform: ANDROID + + acceptance: + name: Phase A release acceptance (incomplete matrix blocks) + needs: [provenance, ios, android] + if: always() && github.event.pull_request.number != 7045 + runs-on: ubuntu-24.04 + timeout-minutes: 5 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 + env: + IOS_RESULT: ${{ needs.ios.result }} + ANDROID_RESULT: ${{ needs.android.result }} + with: + script: | + const { preflight } = require('./.github/native/release_preflight.cjs'); + const { acceptance, markdown } = require('./.github/native/release_acceptance.cjs'); + const { evidence } = require('./.github/native/release_evidence.cjs'); + const verified = await preflight(github, context); + const currentAttempt = verified.trusted && await evidence(github, context, { + ios: process.env.IOS_RESULT, android: process.env.ANDROID_RESULT, + attempt: Number(process.env.GITHUB_RUN_ATTEMPT) }); + const result = acceptance({ trusted: currentAttempt, + ios: process.env.IOS_RESULT, android: process.env.ANDROID_RESULT }); + await core.summary.addRaw(markdown(result)).write(); + core.setFailed('BLOCKED: full app acceptance is NOT IMPLEMENTED / NOT VERIFIED; no release approval'); diff --git a/AGENTS.md b/AGENTS.md index bf74bc552..28cfb7c53 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,6 +4,40 @@ This repository uses a **Cloud code complete → hosted native validation → sh Repository: `KeeperCommunity/bitcoin-keeper`. Use `sprint` as the PR base unless the task explicitly specifies another base. +## R5 and future releases: permanent cloud-first default + +Follow [the cloud release pipeline](docs/cloud-release-pipeline.md) for R5 and every +subsequent release. Complete code and representative native acceptance on hosted +iOS simulators/Android emulators, then assign remaining real-device checks to a +named authorized tester. The release owner's personal Mac is not the default +handoff destination. Keep the existing Local path below as the safe fallback +until each hosted capability is reviewed, installed and verified; its current +`Codex local handoff` / `State: NEEDS_LOCAL` syntax remains the gate protocol, not +a claim that a Mac session is always required. In that handoff, put hosted work +and run URLs in `Cloud checks`, and set `Local checks requested: NONE` only when +trusted hosted evidence satisfies all requested native checks and no physical +checks remain. Otherwise name the actual remaining checks and who can run them. + +Bootstrap depends on reviewed [PR #7060](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7060); +check its current state. The initial Phase A candidate is stacked on that PR. +Its reusable `keeper-native-platform.yml` workflow is called by +`keeper-release-acceptance.yml` automatically for future PRs targeting `sprint`; +there is no R5-only release selector or manual copying step. The active R4 PR +#7045 is excluded. Do not change R4 source, refs, private fixtures, Mac work, +required gate or approval process. Installing #7060 and this infrastructure on +`sprint` requires independent review and owner approval. Diagnostic candidate +runs are not trusted acceptance for R5 or another source SHA. + +Record the exact source SHA, workflow run/attempt, both platforms' actual +build/UI outcomes, safe artifact hashes and unresolved feature acceptance. +A startup smoke or representative probe does not prove R5's deletion, recovery, +upgrade or security matrix. R4-dependent app checks wait for R4 baseline +reconciliation; unresolved high-risk cases remain blocking. Phase B protected +signing and distribution are **NOT IMPLEMENTED / NOT VERIFIED** until their +separate reviewed workflow and exact-artifact controls are proven. Do not merge, +sign, upload a beta, submit to a store or publish without explicit owner approval +for that action and artifact. Passing CI provides none of these approvals. + ## Codex Cloud: implement and prepare handoff 1. Work in a task-specific branch; investigate, implement, add or update tests, and run suitable checks (for example, `npm run test` and `npm run lint`). Report actual pass/fail results; do not claim a native simulator was run unless it really was. diff --git a/docs/cloud-release-pipeline.md b/docs/cloud-release-pipeline.md new file mode 100644 index 000000000..387bf3c35 --- /dev/null +++ b/docs/cloud-release-pipeline.md @@ -0,0 +1,191 @@ +# Permanent cloud release pipeline + +[Issue #7061](https://github.com/KeeperCommunity/bitcoin-keeper/issues/7061) +establishes the default process for R5 and every later Keeper release: cloud code +completion, hosted native acceptance, authorized physical testing, independent +review, and separately approved signing/distribution/publication. R5 is the first +rollout, not a special workflow. The target is zero ongoing dependency on the +release owner's personal Mac; hosted iOS jobs still use macOS and physical +checks still need suitable phones/signers and authorized people. + +This document describes the Phase A candidate and the separate Phase B plan. +It does not grant merge, signing, upload, submission or publication approval. + +## Current capability and adoption + +Status snapshot: 2026-10-18. Recheck linked PRs and current trusted workflows at +each handoff; these initial blockers are not evidence about a later head. + +| Capability | Current state and evidence boundary | +| --- | --- | +| Hosted development builds and account-free startup smoke | #7060 has actual iOS and Android build/UI passes at `d865ca9c4f91532a1524443cc6da42d8d7b07e1a`, run [39024530330](https://github.com/KeeperCommunity/bitcoin-keeper/actions/runs/39024530330). It remains an unmerged draft. That evidence belongs only to its tested source. | +| Reusable Phase A release acceptance | Candidate infrastructure stacked on #7060. Its local contract checks are distinct from actual hosted builds/UI execution. R5 native and release acceptance remain **NOT VERIFIED** until R5's own exact head runs after trusted installation and baseline reconciliation. | +| R5 feature/security matrix | **BLOCKED / NOT VERIFIED** until the relevant R4 baseline is reconciled and R5's own deletion/reference, setup/persistence, account-isolation and recovery/regression cases actually run. Representative probes do not waive missing or failed cases. | +| Protected signed beta and store delivery | Phase B: **NOT IMPLEMENTED / NOT VERIFIED**. Existing Fastlane lanes are not a validated cloud release workflow. | +| Physical phone/signer acceptance | **NOT VERIFIED** without named authorized tester reports for the exact approved distributed artifact. Hosted simulators/emulators supply no physical credit. | + +The Phase A action-pin contract also found a malformed inherited Android +emulator-action reference in #7060. The new worker uses the verified v2.34.0 +commit; resolve/review the dependency reference in #7060 before installation. +Its historical successful run is not proof that the malformed literal works. + +The active R4 PR [#7045](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7045) +and its existing process remain untouched. Do not update its source, refs, +fixtures, Mac work, gate or approvals to adopt this pipeline. Do not transfer +#7060's or this candidate's results to R4 or +[R5 #7058](https://github.com/KeeperCommunity/bitcoin-keeper/pull/7058). + +Before adoption, independently review #7060's workflow, dependency and iOS-native +changes against R4's eventual released baseline. Obtain owner approval before +merging it. Then review the separate Phase A candidate and install its reviewed +workflows on `sprint` only with approval. A stacked candidate can test its +infrastructure, but cannot certify its own untrusted CI or bypass the currently +required `keeper/local-validation` and `Tests` checks. Preserve the existing safe +Local fallback until the applicable hosted capability is proven. + +## Phase A: reusable hosted acceptance + +The shared platform job is `.github/workflows/keeper-native-platform.yml` +(`workflow_call`); `.github/workflows/keeper-release-acceptance.yml` invokes it for +PRs targeting `sprint`. The trigger applies to future release/app PRs without a +version-specific selector or manual workflow copy. The explicit active-R4 #7045 +exclusion prevents this rollout from starting new work on that release. + +Each run must use the full current PR head SHA and a disposable development +configuration, with read-only repository access, no persisted checkout credential +and no production signing/service secrets. Native builds execute PR-controlled +source on disposable runners; independent source/CI review remains necessary. +Reviewed workflow/harness provenance and actual step outcomes must be checked +before treating a run as trusted evidence. Changing CI infrastructure requires +review before it supplies authoritative acceptance. + +Preflight compares the caller, shared worker, existing #7060 workflow and the +complete native harness against the exact app source, the current `sprint` base +and the event's original base. The summary also verifies the newest Actions run, +its exact attempt, PR association and actual native job/step results through the +read-only Actions API. A partial rerun cannot reuse an earlier attempt's pass. +Required executable files must exist as ordinary +files in all three snapshots. Missing installation, changed CI, fork provenance +or a concurrent source/base change supplies no native credit. Consequently this +stacked candidate **skips its new native jobs** before reviewed installation. +The full acceptance summary deliberately fails even if both primitive probe jobs +pass: five required app scenarios are still **NOT IMPLEMENTED**. Extending those +scenarios requires executable tests and review, not changing a status/waiver. + +The bounded representative matrix extends #7060's startup smoke with a separate +development-only probe entrypoint using real native Realm/MMKV modules and the +current app schema. Across three process launches it seeds synthetic wallet +records, checks persistence and separate Realm-file isolation, rejects a wrong +Realm encryption key, checks transaction rollback and targeted Realm deletion, +then verifies persistence and deletes its disposable state. Its wallet records +contain an invalid public sentinel, with no fundable keys. This verifies native +storage primitives, not product key deletion/reference protections, app account +isolation, setup/retry behavior, recovery, upgrade or release performance. + +Use only job-created throwaway state: no Mac accounts, keystores, private signer +material, historical fixtures, funding or live signing. The summary must fail +full acceptance when required R5 app/security cases are missing, blocked or +failed. Keep the matrix small enough to fit the hosted job budget; expand +coverage only for a concrete release risk. + +For every release, the Cloud handoff records: + +- Full PR head SHA and PR URL; required `IOS`, `ANDROID` and, when applicable, + `HARDWARE` checks. +- Workflow run URL/attempt and actual build, startup, integration and timing + outcomes for each platform: `PASS`, `FAIL`, `NOT RUN` or `BLOCKED`. +- Safe artifact identity/hashes and the exact scenarios exercised, with missing + feature/security cases and failures kept explicit. +- Remaining physical checks, assigned tester and any required owner decision. + +Use the existing **Codex local handoff**, `State: NEEDS_LOCAL` and `Required local +checks` fields in [AGENTS.md](../AGENTS.md). These are the current gate's protocol; +the default execution destination for R5/future native work is hosted CI. +`Local checks requested: NONE` is appropriate only when trusted hosted evidence +satisfies all required native checks and no physical checks remain. Otherwise +describe the actual fallback or physical work. Do not invent a passing Local +report to represent a hosted run. + +A new head commit invalidates previous native evidence and owner scope decisions. +Rerun both platforms on that head. Retain bounded safe metadata and diagnostic +outcomes on failure; do not upload raw logs, credentials, generated account data, +screenshots or development app bundles just to document a pass. A development +artifact hash is not a signed beta identity. Follow the trust, bootstrap, runner +budget and evidence rules in [hosted native validation](hosted-native-validation.md). + +### Staged runner budget + +The current R4 gate and #7060 startup workflow stay unchanged. During staged +adoption, each eligible app PR push can therefore run the original startup pair +as well as the new build/probe pair. The original caps are 65 iOS / 60 Android +minutes; the new shared worker caps each platform at 75 minutes, builds once and +runs startup plus native storage probes. Neither has automatic retries. The +combined ceiling is 275 runner-minutes per push, approximately $9.49 if billable +at the reference rates in [hosted validation](hosted-native-validation.md), before +allowances/storage/other CI. This is a planning ceiling, not observed runtime or +an account bill. The uninstalled candidate starts no new native jobs. + +Consolidating those platform builds and their trusted gate consumer needs a later +reviewed change after the R4 noninterference constraint permits it. Do not alter +R4's current gate or discard failed evidence to reduce this rollout's cost. + +## Phase B: separate protected delivery workflow + +**NOT IMPLEMENTED / NOT VERIFIED.** Deliver this in a separate PR with a short +scope estimate before implementation. Keep Phase A focused; split or defer work +if a phase approaches approximately 20,000 changed code/test tokens or contains +two substantial independent features. + +Review the existing `ios/fastlane/Fastfile` and `android/fastlane/Fastfile` before +choosing hosted macOS/Linux delivery, or Xcode Cloud for iOS. Inventory these +prerequisites with the owner; record credential owners and availability without +copying secret values into issues, PRs, logs or artifacts: + +| Area | Setup to resolve before signing/distribution | +| --- | --- | +| iOS | Apple team/app identifiers, distribution certificate/private-key custody, provisioning profiles, App Store Connect upload authorization, TestFlight groups and approved channel mappings. | +| Android | Package identity, existing upload-key custody and alias, Play App Signing status, least-privileged Play service account, internal-test track and tester access. Never regenerate an upload key without authorization. | +| Both | Reviewed production configuration, immutable commit/version/build identity, fresh store histories/counters, protected environments and approvers, retained artifact hashes/signatures/provenance and distribution receipts. | + +Audit tracked native signing configuration for embedded credential fields without +printing their values. If values may be live, use the project's private security +process and plan replacement/rotation with the owner. Do not assume tracked +values are valid, usable or safe to reuse. Existing Fastlane build-number +mutation and immediate upload behavior must be reviewed for exact-artifact and +approval controls before being used remotely. + +The release-only workflow must accept trusted reviewed release source and bind +its exact commit, version, build and channel. Production secrets belong only in +least-privileged protected environments, never a PR job. Require explicit owner +approval before signing and before any TestFlight/Play internal upload or other +distribution. Preserve the signed artifact's hash, signature identity, provenance +and upload receipt; testers and publication decisions must refer to that same +artifact. Require separate explicit owner approval for external submission and +public publication. Never treat a passing build, gate or beta test as approval. + +One-time account/provisioning/key-custody setup may require the owner. Describe +that setup honestly; it is separate from an ongoing requirement to unlock the +owner's Mac for each release. + +## Physical checks and final review + +Assign a named trusted tester/maintainer, or a securely operated device facility +for supported cases, to install the approved TestFlight/Play internal artifact. +Record the artifact hash/build/channel and head SHA, tester, phone OS/model, +signer model/firmware, requested scenarios, actual outcomes and unresolved cases. +Exercise real biometrics, cameras, NFC/USB/BLE, hardware signers and relevant +policy/recovery behavior on the devices that support them. A simulator report +cannot stand in for those results. + +Use owner-approved physical scope and retain [the existing exact-SHA HARDWARE +deferral and critical-defect restrictions](../AGENTS.md#owner-directed-post-release-test-scope). +A failed check or high-risk issue involving keys, recovery, funds, backups or +incorrect signing stays blocking. Owner deferral must remain honest about +unrun cases and cannot waive a required failed platform or physical result. + +Independent review, feature/security acceptance, artifact/version checks and +explicit per-release approvals remain separate from CI. Report each unproven +capability as **NOT IMPLEMENTED / NOT VERIFIED**, preserve current safe fallback, +and state the next concrete action. Future releases reuse these reviewed shared +workflows; only their source, versions, relevant acceptance cases, artifact and +approvals change.