diff --git a/.github/scripts/read-d270-ios-artifact.cjs b/.github/scripts/read-d270-ios-artifact.cjs new file mode 100644 index 000000000..a90b1a599 --- /dev/null +++ b/.github/scripts/read-d270-ios-artifact.cjs @@ -0,0 +1,126 @@ +'use strict'; +// One finite metadata projection; no native worker, release authority or selector input. +const assert = require('node:assert/strict'); +const crypto = require('node:crypto'); +const fs = require('node:fs'); +const path = require('node:path'); +const { execFileSync } = require('node:child_process'); +const OWNER = 'KeeperCommunity', REPO = 'bitcoin-keeper'; +const RUN = 40065599904, JOB = 120788067210; +const SOURCE = 'd27007078808617a97ee460b592eefb44e7e5325'; +const WORKFLOW = 'f5f20e6d959109cdc2e0096099992d72307255bf'; +// Exact completed iOS job/artifact API and upload facts; Android may continue. +const ARTIFACT = 12550480968, ZIP_SIZE = 7339, DIGEST = '5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032'; +const NATIVE_CONCLUSION = 'failure', STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped']; +const STEPS = ['Build development app', 'Run disposable startup smoke', + 'Run disposable native persistence probe', 'Run R5 production worker native scenarios', + 'Measure five full-product startup and first-wallet runs']; +const CONCLUSIONS = ['success', 'failure', 'skipped']; +const NAME = `keeper-diagnostic-native-IOS-${SOURCE}-${RUN}-1`; + +async function run({ github, context, core }) { + let owned, primary = false, output, stage = 'SELECTION'; + try { + assert.ok(Number.isSafeInteger(ARTIFACT) && ARTIFACT > 0); + assert.ok(Number.isSafeInteger(ZIP_SIZE) && ZIP_SIZE > 0 && ZIP_SIZE <= 1024 * 1024 + 4096); + assert.match(DIGEST ?? '', /^[a-f0-9]{64}$/); + assert.ok(['success', 'failure'].includes(NATIVE_CONCLUSION)); + assert.ok(Array.isArray(STEP_CONCLUSIONS) && STEP_CONCLUSIONS.length === STEPS.length && + STEPS.every((_, index) => CONCLUSIONS.includes(STEP_CONCLUSIONS[index]))); + assert.equal(context.repo.owner, OWNER); assert.equal(context.repo.repo, REPO); + assert.equal(context.eventName, 'push'); + assert.equal(context.ref, 'refs/heads/codex/r5-d270-ios-artifact-readout-20261024'); + const args = { owner: OWNER, repo: REPO, request: { timeout: 30000 } }; + const admit = async () => { + stage = 'API_LOOKUP'; + const [r, j, a] = await Promise.all([ + github.rest.actions.getWorkflowRun({ ...args, run_id: RUN }), + github.rest.actions.getJobForWorkflowRun({ ...args, job_id: JOB }), + github.rest.actions.getArtifact({ ...args, artifact_id: ARTIFACT }), + ]); + stage = 'RUN_BINDING'; + assert.equal(r.data.id, RUN); assert.equal(r.data.run_attempt, 1); + assert.equal(r.data.repository.id, 470904030); assert.equal(r.data.head_repository.id, 470904030); + assert.equal(r.data.head_sha, SOURCE); assert.equal(r.data.event, 'pull_request'); + assert.equal(r.data.head_branch, 'codex/r5-native-acceptance-20261024'); + assert.equal(r.data.path, '.github/workflows/keeper-native-diagnostic.yml'); + // Only this completed iOS job is needed; Android may continue untouched. + assert.ok((r.data.status === 'in_progress' && r.data.conclusion === null) || + (r.data.status === 'completed' && ['success', 'failure'].includes(r.data.conclusion))); + assert.deepEqual(r.data.referenced_workflows, [{ + path: `${OWNER}/${REPO}/.github/workflows/keeper-native-platform.yml@${WORKFLOW}`, + ref: 'refs/pull/7149/merge', sha: WORKFLOW, + }]); + stage = 'JOB_BINDING'; + assert.equal(j.data.id, JOB); assert.equal(j.data.run_id, RUN); assert.equal(j.data.run_attempt, 1); + assert.equal(j.data.head_sha, SOURCE); assert.equal(j.data.status, 'completed'); + assert.equal(j.data.conclusion, NATIVE_CONCLUSION); + for (const [index, name] of STEPS.entries()) { + const steps = j.data.steps.filter(step => step.name === name); + assert.equal(steps.length, 1); assert.equal(steps[0].status, 'completed'); + assert.equal(steps[0].conclusion, STEP_CONCLUSIONS[index]); + } + const upload = j.data.steps.filter(step => step.name === 'Retain safe Phase A evidence'); + assert.equal(upload.length, 1); assert.equal(upload[0].status, 'completed'); + assert.equal(upload[0].conclusion, 'success'); + stage = 'ARTIFACT_BINDING'; + assert.equal(a.data.id, ARTIFACT); assert.equal(a.data.name, NAME); + assert.equal(a.data.expired, false); assert.equal(a.data.size_in_bytes, ZIP_SIZE); + assert.equal(a.data.digest, `sha256:${DIGEST}`); + assert.equal(a.data.workflow_run.id, RUN); assert.equal(a.data.workflow_run.head_sha, SOURCE); + assert.equal(a.data.workflow_run.repository_id, 470904030); + assert.equal(a.data.workflow_run.head_repository_id, 470904030); + }; + await admit(); + stage = 'DOWNLOAD'; + const download = await github.rest.actions.downloadArtifact({ ...args, artifact_id: ARTIFACT, archive_format: 'zip' }); + const bytes = Buffer.from(download.data); + assert.equal(bytes.length, ZIP_SIZE); + assert.equal(crypto.createHash('sha256').update(bytes).digest('hex'), DIGEST); + stage = 'PRIVATE_FILE'; + const temp = process.env.RUNNER_TEMP; + assert.ok(temp && path.isAbsolute(temp)); assert.equal(fs.realpathSync(temp), path.resolve(temp)); + const filename = path.join(temp, 'r5-d270-ios-fixed.zip'); + const descriptor = fs.openSync(filename, 'wx', 0o600); owned = filename; + try { fs.writeFileSync(descriptor, bytes); } + finally { fs.closeSync(descriptor); } + stage = 'DECODE'; + try { + output = execFileSync('python3', ['-B', '.github/scripts/read-d270-ios-artifact.py'], + { encoding: 'utf8', timeout: 30000, maxBuffer: 2 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] }); + } catch (error) { + const match = /^D270_IOS_OBSERVATION_READOUT_FAILED:(PRIVATE_FILE|KERNEL|ZIP_IDENTITY|ZIP_LAYOUT|JSON|ROOT_KEYS|SIGNATURE_POLICY|IDENTITY|STARTUP_DIAGNOSTICS|STARTUP_OBSERVATION|DRIVER|INSTALLED|SIGNATURE|PROJECTED_METADATA)\n$/.exec(String(error.stdout ?? '')); + if (match) stage = 'DECODE_' + match[1]; + throw error; + } + stage = 'PROJECTION_FRAME'; + const lines = output.trim().split('\n'); + assert.equal(lines.length, 3); + assert.equal(lines[0], 'D270_IOS_OBSERVATIONS_BEGIN'); + assert.equal(lines[2], 'D270_IOS_OBSERVATIONS_END'); + const projection = JSON.parse(lines[1]); + assert.deepEqual(Object.keys(projection).sort(), ['schema', 'scope', 'original_zip_sha256', 'metadata_sha256', 'observations'].sort()); + assert.equal(projection.schema, 1); + assert.equal(projection.scope, 'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE'); + assert.equal(projection.original_zip_sha256, DIGEST); + assert.match(projection.metadata_sha256, /^[a-f0-9]{64}$/); + assert.equal(projection.observations.source_sha, SOURCE); + assert.equal(projection.observations.run_id, String(RUN)); + assert.equal(projection.observations.run_attempt, '1'); + await admit(); // Recheck official immutable source/workflow/job/attempt/artifact before releasing output. + } catch (_) { + primary = true; + throw new Error('FIXED_NATIVE_ARTIFACT_READOUT_FAILED_' + stage); + } finally { + if (owned) { + try { fs.unlinkSync(owned); } + catch (_) { + try { core.warning('FIXED_NATIVE_ARTIFACT_PRIVATE_CLEANUP_FAILED'); } catch (_) { /* retain primary */ } + if (!primary) throw new Error('FIXED_NATIVE_ARTIFACT_PRIVATE_CLEANUP_FAILED'); + } + } + } + try { core.info(output.trim()); } + catch (_) { throw new Error('FIXED_NATIVE_ARTIFACT_READOUT_FAILED'); } +} +module.exports = { run }; diff --git a/.github/scripts/read-d270-ios-artifact.py b/.github/scripts/read-d270-ios-artifact.py new file mode 100644 index 000000000..ffbb78d32 --- /dev/null +++ b/.github/scripts/read-d270-ios-artifact.py @@ -0,0 +1,133 @@ +#!/usr/bin/env python3 +"""Project reviewed observations from one original ZIP using the fixed 044 kernel.""" +import hashlib +import importlib.util +import io +import json +import os +from pathlib import Path +import stat +import zipfile + +ROOT = Path(__file__).parent +KERNEL_SHA256 = 'c2dd21633de27f44d2bd8c7ef50907384094d64d67060852339e97af42821abf' +SOURCE = 'd27007078808617a97ee460b592eefb44e7e5325' +WORKFLOW = 'f5f20e6d959109cdc2e0096099992d72307255bf' +WORKFLOW_REF = 'KeeperCommunity/bitcoin-keeper/.github/workflows/keeper-native-diagnostic.yml@refs/pull/7149/merge' +RUN, ATTEMPT = '40065599904', '1' +ZIP_SIZE = 7339 +DIGEST = '5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032' +SCOPE = 'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE' +STARTUP_SCOPE = 'Owned simulator launch window; fixed facts only; cause UNKNOWN.' +HIERARCHY_SCOPE = 'ANY_RETAINED_SNAPSHOT_NOT_FINAL_ROUTE_OR_VISIBILITY_PROOF' +PHASE = 'PRIVATE_FILE' +FIELDS = frozenset(('schema', 'source_sha', 'workflow_sha', 'workflow_ref', 'run_id', 'run_attempt', + 'platform', 'diagnostic_only', 'build', 'smoke', 'native_probe', 'r5_features', 'hardware', 'signing', + 'app_id', 'install_succeeded', 'installed_artifact_verified', 'installed_artifact', + 'startup_diagnostics', 'startup_observation', 'driver_preflight', 'simulator_app_service_readiness', + 'failed_phase', 'startup_observation_capture', 'startup_observation_cleanup', + 'startup_cleanup_errors', 'cleanup_failures', 'disposable_cleanup')) +ADDITIONAL_LITERALS = frozenset(('--info', 'CONNECTION_ERROR', 'EXCEPTION_MARKER', 'FATAL_MARKER', + 'HERMES_ERROR', 'JS_EXCEPTION', 'NATIVE_EXCEPTION', 'SCRIPT_LOAD_ERROR', 'SCRIPT_URL_MISSING', + 'PREFIXED_OWN_PROCESS_MARKERS_ONLY_NOT_CAUSE_OR_ACCEPTANCE', 'ios_simulator_signature', + 'verified', 'ADHOC_SIMULATOR_ONLY_NOT_RELEASE_SIGNING', 'bundle_id', 'entitlements_sha256', + 'embedded_code_count', STARTUP_SCOPE)) + + +def project(blob): + global PHASE + PHASE = 'KERNEL' + source = ROOT / 'read-044-ios-artifact.py' + if hashlib.sha256(source.read_bytes()).hexdigest() != KERNEL_SHA256: + raise ValueError('Fixed kernel changed.') + spec = importlib.util.spec_from_file_location('fixed_044_kernel', source) + kernel = importlib.util.module_from_spec(spec) + spec.loader.exec_module(kernel) + literals = kernel.public_literals() # Original hash-checked 044 policy remains unchanged. + kernel.SOURCE, kernel.WORKFLOW, kernel.WORKFLOW_REF = SOURCE, WORKFLOW, WORKFLOW_REF + kernel.RUN, kernel.ATTEMPT = RUN, ATTEMPT + kernel.public_literals = lambda: literals | ADDITIONAL_LITERALS | {SOURCE, WORKFLOW, WORKFLOW_REF, RUN, ATTEMPT} + old_hierarchy = kernel.validate_hierarchy + + def current_hierarchy(value, product=False): + if product: + return old_hierarchy(value, product=True) + if type(value) is not dict or value.get('scope') != HIERARCHY_SCOPE: + kernel.rejected() + # Current d270 adds this fixed conservative scope. Keep it in output; + # apply the unchanged 044 flag/type/bound checks to its original fields. + return old_hierarchy({key: item for key, item in value.items() if key != 'scope'}) + + kernel.validate_hierarchy = current_hierarchy + PHASE = 'ZIP_IDENTITY' + if type(blob) is not bytes or len(blob) != ZIP_SIZE or hashlib.sha256(blob).hexdigest() != DIGEST: + kernel.rejected() + PHASE = 'ZIP_LAYOUT' + with zipfile.ZipFile(io.BytesIO(blob)) as archive: + members = archive.infolist() + if len(members) != 1: + kernel.rejected() + entry = members[0] + if (entry.filename != 'ios/metadata.json' or entry.orig_filename != entry.filename or + entry.flag_bits & 1 or stat.S_IFMT(entry.external_attr >> 16) not in (0, stat.S_IFREG) or + entry.file_size > kernel.LIMIT or entry.compress_type not in (zipfile.ZIP_STORED, zipfile.ZIP_DEFLATED)): + kernel.rejected() + raw = kernel.canonical_payload(blob, entry, archive.start_dir, archive.comment) + PHASE = 'JSON' + data = json.loads(raw, object_pairs_hook=kernel.pairs, parse_float=kernel.finite, + parse_constant=lambda _: kernel.rejected()) + PHASE = 'ROOT_KEYS' + if type(data) is not dict or not set(data) <= kernel.ROOT_KEYS: + kernel.rejected() + projected = {key: value for key, value in data.items() if key in FIELDS} + PHASE = 'SIGNATURE_POLICY' + signature = data.get('toolchain', {}).get('ios_simulator_signature') + if (type(signature) is not dict or set(signature) != {'verified', 'scope', 'bundle_id', + 'entitlements_sha256', 'embedded_code_count'} or signature['verified'] is not True or + signature['scope'] != 'ADHOC_SIMULATOR_ONLY_NOT_RELEASE_SIGNING' or + signature['bundle_id'] != 'io.hexawallet.hexakeeper.dev' or + not kernel.re.fullmatch(r'[a-f0-9]{64}', signature['entitlements_sha256']) or + not kernel.bounded_int(signature['embedded_code_count'], 0, 128)): + kernel.rejected() + projected['toolchain'] = {'ios_simulator_signature': signature} + observation = projected.get('startup_observation') + PHASE = 'STARTUP_OBSERVATION' + if observation is not None and (type(observation) is not dict or observation.get('scope') != STARTUP_SCOPE): + kernel.rejected() + identity = {key: projected.get(key) for key in ('schema', 'source_sha', 'workflow_sha', 'workflow_ref', + 'run_id', 'run_attempt', 'platform', 'diagnostic_only')} + for key, value in projected.items(): + PHASE = {'startup_diagnostics': 'STARTUP_DIAGNOSTICS', 'startup_observation': 'STARTUP_OBSERVATION', + 'driver_preflight': 'DRIVER', 'installed_artifact': 'INSTALLED', + 'toolchain': 'SIGNATURE'}.get(key, 'IDENTITY') + kernel.validate_metadata(dict(identity, **{key: value})) + PHASE = 'PROJECTED_METADATA' + kernel.validate_metadata(projected) + return {'schema': 1, 'scope': SCOPE, 'original_zip_sha256': DIGEST, + 'metadata_sha256': hashlib.sha256(raw).hexdigest(), 'observations': projected} + + +def main(argv=None): + global PHASE + PHASE = 'PRIVATE_FILE' + try: + if argv: + raise ValueError('No selectors.') + path = Path(os.environ['RUNNER_TEMP']) / 'r5-d270-ios-fixed.zip' + with os.fdopen(os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK), 'rb') as source: + info = os.fstat(source.fileno()) + if not stat.S_ISREG(info.st_mode) or stat.S_IMODE(info.st_mode) != 0o600 or info.st_size != ZIP_SIZE: + raise ValueError('Invalid private file.') + result = project(source.read(ZIP_SIZE + 1)) + except Exception: + print('D270_IOS_OBSERVATION_READOUT_FAILED:' + PHASE) + return 1 + print('D270_IOS_OBSERVATIONS_BEGIN') + print(json.dumps(result, sort_keys=True, separators=(',', ':'))) + print('D270_IOS_OBSERVATIONS_END') + return 0 + + +if __name__ == '__main__': + import sys + raise SystemExit(main(sys.argv[1:])) diff --git a/.github/tests/d270-ios-artifact-readout.test.cjs b/.github/tests/d270-ios-artifact-readout.test.cjs new file mode 100644 index 000000000..b15776b27 --- /dev/null +++ b/.github/tests/d270-ios-artifact-readout.test.cjs @@ -0,0 +1,154 @@ +'use strict'; +// Fabricated API and byte transport only; no current artifact/native operation. +const assert = require('node:assert/strict'); +const crypto = require('node:crypto'); +const fs = require('node:fs'); +const path = require('node:path'); +const test = require('node:test'); +const vm = require('node:vm'); +const SCRIPT = path.join(__dirname, '../scripts/read-d270-ios-artifact.cjs'); +const SOURCE = 'd27007078808617a97ee460b592eefb44e7e5325'; +const WORKFLOW = 'f5f20e6d959109cdc2e0096099992d72307255bf'; +const PAYLOAD = Buffer.from('OFFLINE_SYNTHETIC_METADATA_ZIP_BYTES'); +const DIGEST = crypto.createHash('sha256').update(PAYLOAD).digest('hex'); +const SELECTION = "const ARTIFACT = 12550480968, ZIP_SIZE = 7339, DIGEST = '5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032';"; +const OUTCOME = "const NATIVE_CONCLUSION = 'failure', STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped'];"; + +function fixture(options = {}) { + const context = { repo: { owner: 'KeeperCommunity', repo: 'bitcoin-keeper' }, + eventName: 'push', ref: 'refs/heads/codex/r5-d270-ios-artifact-readout-20261024' }; + const runData = { id: 40065599904, run_attempt: 1, repository: { id: 470904030 }, + head_repository: { id: 470904030 }, head_sha: SOURCE, event: 'pull_request', + head_branch: 'codex/r5-native-acceptance-20261024', + path: '.github/workflows/keeper-native-diagnostic.yml', status: 'in_progress', conclusion: null, + referenced_workflows: [{path: `KeeperCommunity/bitcoin-keeper/.github/workflows/keeper-native-platform.yml@${WORKFLOW}`, + ref: 'refs/pull/7149/merge', sha: WORKFLOW}] }; + const jobData = { id: 120788067210, run_id: 40065599904, run_attempt: 1, head_sha: SOURCE, + status: 'completed', conclusion: 'failure', steps: [ + ['Build development app', 'success'], ['Run disposable startup smoke', 'failure'], + ['Run disposable native persistence probe', 'skipped'], ['Run R5 production worker native scenarios', 'skipped'], + ['Measure five full-product startup and first-wallet runs', 'skipped'], ['Retain safe Phase A evidence', 'success'] + ].map(([name, conclusion]) => ({name, conclusion, status: 'completed'})) }; + const artifact = {id: options.production ? 12550480968 : 991, + name: `keeper-diagnostic-native-IOS-${SOURCE}-40065599904-1`, expired: false, + size_in_bytes: options.production ? 7339 : PAYLOAD.length, + digest: 'sha256:' + (options.production ? '5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032' : DIGEST), workflow_run: { + id: 40065599904, head_sha: SOURCE, repository_id: 470904030, head_repository_id: 470904030}}; + const calls = [], events = [], output = [], actions = {}; + for (const [name, data] of [['getWorkflowRun', runData], ['getJobForWorkflowRun', jobData], ['getArtifact', artifact]]) { + actions[name] = async args => { calls.push([name, args]); return {data}; }; + } + actions.downloadArtifact = async args => {calls.push(['downloadArtifact', args]); if(options.after) options.after({runData,jobData,artifact}); return {data: options.payload ?? PAYLOAD};}; + const inputs = {github: {rest: {actions}}, context, core: { + info(value) {events.push('info'); if (options.info) throw Error('PRIVATE_SENTINEL'); output.push(value);}, + warning(value) {events.push('warning'); if (options.warning) throw Error('PRIVATE_SENTINEL'); output.push(value);}}}; + let source = fs.readFileSync(SCRIPT, 'utf8'); + assert.ok(source.includes(SELECTION) && source.includes(OUTCOME)); + if (!options.production) source = source.replace(SELECTION, + `const ARTIFACT = 991, ZIP_SIZE = ${PAYLOAD.length}, DIGEST = '${DIGEST}';`); + if (options.edit) source = options.edit(source); + const api = {module: {exports: {}}, Buffer, process: {env: {RUNNER_TEMP: '/owned'}}, require(name) { + if (name === 'node:assert/strict') return {...assert, deepEqual(a,b) {assert.deepEqual(JSON.parse(JSON.stringify(a)), JSON.parse(JSON.stringify(b)));}}; + if (name === 'node:crypto') return crypto; + if (name === 'node:path') return path; + if (name === 'node:fs') return {realpathSync: x => x, + openSync(file, flags, mode) {assert.equal(file, '/owned/r5-d270-ios-fixed.zip'); assert.equal(flags, 'wx'); assert.equal(mode, 0o600); events.push('open'); return 42;}, + writeFileSync(fd, bytes) {assert.equal(fd,42); assert.deepEqual(bytes,PAYLOAD); events.push('write'); if(options.write) throw Error('PRIVATE_SENTINEL');}, + closeSync(fd) {assert.equal(fd,42); events.push('close'); if(options.close) throw Error('PRIVATE_SENTINEL');}, + unlinkSync() {events.push('unlink'); if(options.unlink) throw Error('PRIVATE_SENTINEL');}}; + if (name === 'node:child_process') return {execFileSync(command,args,settings) { + assert.equal(command,'python3'); assert.deepEqual(Array.from(args),['-B','.github/scripts/read-d270-ios-artifact.py']); + assert.equal(settings.timeout,30000); events.push('decoder'); if(options.decoder) { + const error = Error('PRIVATE_SENTINEL'); error.stdout = options.decoderOutput; throw error; + } + return options.wrongOutput ? 'PRIVATE_SENTINEL' : 'D270_IOS_OBSERVATIONS_BEGIN\n' + JSON.stringify({schema:1,scope:'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE',original_zip_sha256:DIGEST,metadata_sha256:'a'.repeat(64),observations:{source_sha:SOURCE,run_id:'40065599904',run_attempt:'1'}}) + '\nD270_IOS_OBSERVATIONS_END\n';}}; + throw Error('Unexpected test import'); + }}; + vm.runInNewContext(source,api); + return {context,runData,jobData,artifact,calls,events,output,inputs,invoke:()=>api.module.exports.run(inputs)}; +} + +test('exact observed production selection reaches only its archive and rejects wrong digest before file/log', async()=>{ + const f=fixture({production:true,payload:Buffer.alloc(7339)}); + await assert.rejects(f.invoke,/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.deepEqual(f.calls.map(([name])=>name),['getWorkflowRun','getJobForWorkflowRun','getArtifact','downloadArtifact']); + assert.equal(f.calls[2][1].artifact_id,12550480968); assert.equal(f.calls[3][1].artifact_id,12550480968); + assert.deepEqual(f.events,[]); assert.deepEqual(f.output,[]); +}); + +test('every incomplete observed binding fails before API/filesystem', async()=>{ + for(const [before,after] of [["ARTIFACT = 12550480968","ARTIFACT = null"], ['ZIP_SIZE = 7339','ZIP_SIZE = null'], + ["DIGEST = '5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032'",'DIGEST = null'], ["NATIVE_CONCLUSION = 'failure'",'NATIVE_CONCLUSION = null'], + ["STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped']",'STEP_CONCLUSIONS = null'], + ["STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped']", "STEP_CONCLUSIONS = ['success', , 'skipped', 'skipped', 'skipped']"], + ["STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped']", "STEP_CONCLUSIONS = ['success', undefined, 'skipped', 'skipped', 'skipped']"], + ["STEP_CONCLUSIONS = ['success', 'failure', 'skipped', 'skipped', 'skipped']", "STEP_CONCLUSIONS = ['success', null, 'skipped', 'skipped', 'skipped']"]]) { + const f=fixture({production:true,edit:s=>{assert.ok(s.includes(before)); return s.replace(before,after);}}); + await assert.rejects(f.invoke,/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.deepEqual(f.calls,[]); assert.deepEqual(f.events,[]); assert.deepEqual(f.output,[]); + } +}); + +test('synthetic completed iOS job can be read while Android continues and purge precedes exact-byte output',async()=>{ + for(const completed of [false,true]) { + const f=fixture(); if(completed) Object.assign(f.runData,{status:'completed',conclusion:'failure'}); + await f.invoke(); assert.equal(f.calls.filter(([name])=>name==='getJobForWorkflowRun').length,2); + assert.equal(f.calls[1][1].job_id,120788067210); + assert.ok(f.events.indexOf('close'){ + for(const change of [f=>f.context.eventName='workflow_dispatch',f=>f.context.repo.owner='foreign',f=>f.context.ref='refs/heads/sprint', + f=>f.runData.id++,f=>f.runData.run_attempt++,f=>f.runData.head_sha=WORKFLOW,f=>f.runData.repository.id++, + f=>f.runData.head_repository.id++,f=>f.runData.status='queued',f=>f.runData.referenced_workflows=[], + f=>f.runData.referenced_workflows[0].sha=SOURCE,f=>f.jobData.id++,f=>f.jobData.run_attempt++,f=>f.jobData.run_id++, + f=>f.jobData.status='in_progress',f=>f.jobData.conclusion='success',f=>f.jobData.steps[0].conclusion='failure', + f=>f.jobData.steps[5].conclusion='failure',f=>f.jobData.steps.push(f.jobData.steps[5]),f=>f.artifact.id++, + f=>f.artifact.name+='foreign',f=>f.artifact.size_in_bytes++,f=>f.artifact.expired=true, + f=>f.artifact.digest='sha256:'+'0'.repeat(64),f=>f.artifact.workflow_run.id++,f=>f.artifact.workflow_run.head_sha=WORKFLOW]) { + const f=fixture({production:true}); change(f); await assert.rejects(f.invoke,/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.equal(f.calls.some(([name])=>name==='downloadArtifact'),false); assert.deepEqual(f.events,[]); assert.deepEqual(f.output,[]); + } +}); + +test('wrong ZIP size or digest fails before any filesystem or log operation',async()=>{ + for(const payload of [Buffer.from('PRIVATE_SENTINEL'),Buffer.alloc(PAYLOAD.length)]) { + const f=fixture({payload}); await assert.rejects(f.invoke,/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.deepEqual(f.events,[]); assert.deepEqual(f.output,[]); + } +}); + +test('decoder write close cleanup and logging errors stay fixed and preserve purge ordering',async()=>{ + for(const options of [{write:true,unlink:true,warning:true},{close:true},{decoder:true,unlink:true,warning:true}, + {wrongOutput:true},{unlink:true,warning:true},{info:true}]) { + const f=fixture(options); await assert.rejects(f.invoke,options.unlink&&!options.write&&!options.decoder ? + /FIXED_NATIVE_ARTIFACT_PRIVATE_CLEANUP_FAILED/:/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.equal(f.events.filter(x=>x==='unlink').length,1); + if(options.info) assert.ok(f.events.indexOf('unlink'){ + for(const after of [v=>v.runData.run_attempt++,v=>v.jobData.head_sha='0'.repeat(40),v=>v.artifact.expired=true]) { + const f=fixture({after}); + await assert.rejects(f.invoke,/FIXED_NATIVE_ARTIFACT_READOUT_FAILED/); + assert.equal(f.events.includes('info'),false); + assert.equal(f.events.filter(x=>x==='unlink').length,1); + } +}); + +test('decoder diagnostics admit only fixed stage labels without private output',async()=>{ + for(const [decoderOutput,stage] of [ + ['D270_IOS_OBSERVATION_READOUT_FAILED:STARTUP_OBSERVATION\n','DECODE_STARTUP_OBSERVATION'], + ['D270_IOS_OBSERVATION_READOUT_FAILED:PRIVATE_SENTINEL\n','DECODE'], + ['PRIVATE_SENTINEL','DECODE']]) { + const f=fixture({decoder:true,decoderOutput}); + await assert.rejects(f.invoke,error=>error.message==='FIXED_NATIVE_ARTIFACT_READOUT_FAILED_'+stage); + assert.deepEqual(f.output,[]); + assert.equal(f.events.filter(x=>x==='unlink').length,1); + } +}); diff --git a/.github/tests/test_d270_ios_artifact_readout.py b/.github/tests/test_d270_ios_artifact_readout.py new file mode 100644 index 000000000..62d43effe --- /dev/null +++ b/.github/tests/test_d270_ios_artifact_readout.py @@ -0,0 +1,109 @@ +"""Portable projection/identity/privacy controls; no original native receipt fabricated.""" +from contextlib import redirect_stdout +import copy +import hashlib +import importlib.util +import io +import json +import os +from pathlib import Path +import tempfile +import unittest +from unittest import mock +import zipfile + +SPEC = importlib.util.spec_from_file_location('d270_readout', + Path(__file__).resolve().parents[1] / 'scripts/read-d270-ios-artifact.py') +reader = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(reader) + + +def fixture(): + return {'schema': 1, 'source_sha': reader.SOURCE, 'workflow_sha': reader.WORKFLOW, + 'workflow_ref': reader.WORKFLOW_REF, 'run_id': reader.RUN, 'run_attempt': reader.ATTEMPT, + 'platform': 'IOS', 'diagnostic_only': True, 'build': 'PASS', 'smoke': 'FAIL', + 'native_probe': 'NOT RUN', 'r5_features': 'NOT RUN', 'hardware': 'NOT RUN', 'signing': 'NOT RUN', + 'app_id': 'io.hexawallet.hexakeeper.dev', 'install_succeeded': True, + 'installed_artifact_verified': True, 'toolchain': {'ios_simulator_signature': { + 'verified': True, 'scope': 'ADHOC_SIMULATOR_ONLY_NOT_RELEASE_SIGNING', + 'bundle_id': 'io.hexawallet.hexakeeper.dev', 'entitlements_sha256': 'a' * 64, + 'embedded_code_count': 1}}, + 'commands': [{'PRIVATE_PATH_OR_OTHER_UNEXPORTED_CONTENT': 'PRIVATE_SENTINEL'}]} + + +def observation(): + flags = dict.fromkeys(('credential_error', 'retry', 'logbox_controls', 'redbox_resource', 'loading', + 'login', 'welcome_back', 'logbox_error_header', 'logbox_warning_header', + 'logbox_syntax_footer', 'logbox_counter'), None) + return {'scope': reader.STARTUP_SCOPE, 'collection_errors': [], + 'hierarchy': dict(flags, observation_state='UNKNOWN', snapshot_count=0, scope=reader.HIERARCHY_SCOPE)} + + +def archive(data=None, raw=None, extra=False): + stream = io.BytesIO() + with zipfile.ZipFile(stream, 'w', zipfile.ZIP_DEFLATED) as output: + output.writestr('ios/metadata.json', raw if raw is not None else json.dumps(fixture() if data is None else data)) + if extra: output.writestr('raw.log', 'PRIVATE_SENTINEL') + return stream.getvalue() + + +def bound(blob): + return mock.patch.multiple(reader, ZIP_SIZE=len(blob), DIGEST=hashlib.sha256(blob).hexdigest()) + + +class D270ReadoutTests(unittest.TestCase): + def project(self, data=None, blob=None): + blob = archive(data) if blob is None else blob + with bound(blob): return reader.project(blob) + + def test_projection_keeps_source_and_false_failure_facts_without_exporting_commands(self): + value = self.project() + self.assertEqual(value['scope'], 'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE') + self.assertEqual(value['observations']['smoke'], 'FAIL') + self.assertEqual(value['observations']['native_probe'], 'NOT RUN') + self.assertNotIn('commands', value['observations']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(value)) + self.assertEqual(len(value['metadata_sha256']), 64) + + def test_wrong_source_attempt_and_effective_signature_policy_reject(self): + mutations = [lambda d: d.update(source_sha='0' * 40), lambda d: d.update(run_attempt='2'), + lambda d: d.update(workflow_sha='0' * 40), lambda d: d.update(raw_logs='PRIVATE_SENTINEL'), + lambda d: d['toolchain']['ios_simulator_signature'].update(verified=False), + lambda d: d['toolchain']['ios_simulator_signature'].update(bundle_id='FOREIGN'), + lambda d: d['toolchain']['ios_simulator_signature'].update(extra='PRIVATE_SENTINEL')] + for mutation in mutations: + data = fixture(); mutation(data) + with self.subTest(mutation=mutation), self.assertRaises(Exception): self.project(data) + + def test_exported_unknown_or_raw_nested_values_are_rejected(self): + for value in [{'raw_logs': 'PRIVATE_SENTINEL'}, {'scope': 'PRIVATE_SENTINEL'}, + {'hierarchy': {'text': 'PRIVATE_SENTINEL'}}]: + data = fixture(); data['startup_diagnostics'] = value + with self.subTest(value=value), self.assertRaises(Exception): self.project(data) + + def test_current_producer_conservative_scopes_are_retained_and_strict(self): + data = fixture(); data['startup_observation'] = observation() + self.assertEqual(self.project(data)['observations']['startup_observation'], data['startup_observation']) + for mutation in [lambda d: d['startup_observation'].update(scope='UNKNOWN'), + lambda d: d['startup_observation']['hierarchy'].pop('scope'), + lambda d: d['startup_observation']['hierarchy'].update(scope='UNKNOWN'), + lambda d: d['startup_observation']['hierarchy'].update(text='PRIVATE_SENTINEL'), + lambda d: d['startup_observation']['hierarchy'].update(credential_error='false')]: + changed = copy.deepcopy(data); mutation(changed) + with self.subTest(mutation=mutation), self.assertRaises(Exception): self.project(changed) + + def test_original_digest_archive_layout_duplicate_json_and_private_file_alias_reject(self): + blob = archive() + with self.assertRaises(Exception): reader.project(blob) + for value in [archive(extra=True), archive(raw='{"schema":1,"schema":1}'), blob + b'PRIVATE_SENTINEL']: + with self.subTest(length=len(value)), self.assertRaises(Exception): self.project(blob=value) + with tempfile.TemporaryDirectory() as directory, mock.patch.dict(os.environ, {'RUNNER_TEMP': directory}): + source = Path(directory) / 'original.zip'; source.write_bytes(blob); source.chmod(0o600) + target = Path(directory) / 'r5-d270-ios-fixed.zip'; target.symlink_to(source) + with bound(blob), redirect_stdout(io.StringIO()) as output: + self.assertEqual(reader.main([]), 1) + self.assertEqual(output.getvalue(), 'D270_IOS_OBSERVATION_READOUT_FAILED:PRIVATE_FILE\n') + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/workflows/r5-d270-ios-artifact-readout.yml b/.github/workflows/r5-d270-ios-artifact-readout.yml new file mode 100644 index 000000000..de596a720 --- /dev/null +++ b/.github/workflows/r5-d270-ios-artifact-readout.yml @@ -0,0 +1,36 @@ +name: Read fixed d270 iOS observations + +on: + push: + branches: [codex/r5-d270-ios-artifact-readout-20261024] + paths: + - .github/workflows/r5-d270-ios-artifact-readout.yml + - .github/scripts/read-d270-ios-artifact.cjs + - .github/scripts/read-d270-ios-artifact.py + - .github/tests/d270-ios-artifact-readout.test.cjs + - .github/tests/test_d270_ios_artifact_readout.py + +permissions: + contents: read + actions: read + +concurrency: + group: r5-fixed-d270-ios-observation-readout + cancel-in-progress: false + +jobs: + readout: + if: github.repository == 'KeeperCommunity/bitcoin-keeper' && github.event_name == 'push' && github.ref == 'refs/heads/codex/r5-d270-ios-artifact-readout-20261024' + runs-on: macos-15 + timeout-minutes: 5 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + ref: ${{ github.sha }} + persist-credentials: false + - run: node .github/scripts/verify-ci-source.cjs + - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8 + with: + script: await require('./.github/scripts/read-d270-ios-artifact.cjs').run({ github, context, core }) + - if: always() + run: node .github/scripts/verify-ci-source.cjs diff --git a/docs/r5-d270-ios-observation-readout.md b/docs/r5-d270-ios-observation-readout.md new file mode 100644 index 000000000..db31011a9 --- /dev/null +++ b/docs/r5-d270-ios-observation-readout.md @@ -0,0 +1,58 @@ +# Read the existing d270 iOS observations + +This metadata-only package uses fixed review base +`1ea0b7c2008a57b3450abd38257ea5eb37ad46fa` (#7146). It changes no native +candidate, runtime, signing configuration or existing reader. The selected app +source remains frozen at `d27007078808617a97ee460b592eefb44e7e5325` (#7149). + +The original iOS job `120788067210` in run `40065599904`, attempt 1, passed +dependencies, driver readiness, build and ad-hoc signing checks, then failed +startup. Persistence/workers/product phases did not run. Android continues in +the original serialized window and must not be cancelled or duplicated. + +The sole admitted artifact is `12550480968`, **7,339 bytes**, SHA-256 +`5891036cd8225b97c7edaff9bc057e2c70a8f8720e8f9def3ef0369de043d032`. +The reusable workflow identity is +`f5f20e6d959109cdc2e0096099992d72307255bf`, `refs/pull/7149/merge`. +Official run/source/workflow/attempt, completed iOS job/step outcomes and artifact +metadata are checked both before and after the download/decoder operation. + +The decoder reuses the unchanged #7146 canonical ZIP, strict JSON and bounded +metadata/privacy kernel, pinned by SHA-256 +`c2dd21633de27f44d2bd8c7ef50907384094d64d67060852339e97af42821abf`. +Its original policy stays hash-checked and unchanged. Only the finite current +identity, known reconciled diagnostic vocabulary and fixed simulator-signature +fields are admitted additionally. Original commands, runner paths and unselected +content are never exported; the output projects only reviewed startup, driver, +installed-byte and simulator-signature observations with original ZIP/member +digests. It exports neither raw logs/UI trees nor the original ZIP bytes. + +The private file is exclusive mode0600, decoded through captured IPC, then +deleted before the projection is logged. Downloading uses the previously +reviewed SDK route, which buffers before exact length/digest validation; this +package does not introduce or claim a universal streaming download cap. + +Local synthetic contracts test exact identity, post-download races, cleanup, +original digest/layout/duplicate JSON, no-follow access and projection privacy. +They do not fabricate or pass native acceptance. Current iOS ConnectException +markers are not cause proof; missing own-process markers do not prove that the +Keychain issue is fixed. Keep actual outcomes and unknown causes intact. + +No native build/rerun, producer edit, merge, release signing, upload, deployment +or publication is performed by this reader. + +The first hosted readout `40069585314` at `035ca695` failed inside the reader; +both raw-source guards passed and no observations were exported. The bounded +follow-up adds only fixed admission/decode section labels to rejected output so +API binding and schema/vocabulary rejection can be distinguished. Raw errors, +unknown keys and values remain private; every original admission check remains. + +The next exact readout `40069912749` at `08577ed` rejected the decoded +`STARTUP_OBSERVATION` section. The current d270 producer's immutable +`.github/native/startup_diagnosis.py` adds two conservative fixed scope fields +relative to 044: the launch-window facts scope says cause UNKNOWN, and the +hierarchy explicitly says retained snapshots do not prove route or visibility. +The finite current profile now requires those exact scopes; the unchanged kernel +still validates every original hierarchy flag, type and bound. The scopes remain +in the exported observation. No arbitrary text, UI field or generic pattern is +admitted, and no old or current failed app observation is changed into a pass.