Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 62 additions & 20 deletions .github/native/hosted_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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',
Expand Down Expand Up @@ -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()
Expand All @@ -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])
Expand All @@ -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

Expand Down
32 changes: 32 additions & 0 deletions .github/native/release_acceptance.cjs
Original file line number Diff line number Diff line change
@@ -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 };
48 changes: 48 additions & 0 deletions .github/native/release_evidence.cjs
Original file line number Diff line number Diff line change
@@ -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 };
19 changes: 19 additions & 0 deletions .github/native/release_metro.cjs
Original file line number Diff line number Diff line change
@@ -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);
};
},
},
};
58 changes: 58 additions & 0 deletions .github/native/release_preflight.cjs
Original file line number Diff line number Diff line change
@@ -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 };
38 changes: 38 additions & 0 deletions .github/native/release_probe.js
Original file line number Diff line number Diff line change
@@ -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 (
<SafeAreaView>
<Text testID={`native-probe-${result.stage}`}>Keeper native probe {result.stage}</Text>
<Text testID="native-probe-code">{result.code}</Text>
</SafeAreaView>
);
}

AppRegistry.registerComponent(appName, () => ReleaseProbe);
32 changes: 32 additions & 0 deletions .github/native/release_probe.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading