From d3c3d9beb8c24a34d8dba9168e5ea8f37fea5a40 Mon Sep 17 00:00:00 2001 From: Antuz tap Date: Sat, 24 Oct 2026 08:28:32 +0000 Subject: [PATCH 1/2] ci: read frozen d270 Android failed-sample observations --- .../scripts/read-d270-android-artifact.cjs | 122 ++++++++++++++ .github/scripts/read-d270-android-artifact.py | 102 ++++++++++++ .../d270-android-artifact-readout.test.cjs | 152 ++++++++++++++++++ .../test_d270_android_artifact_readout.py | 107 ++++++++++++ .../r5-d270-android-artifact-readout.yml | 36 +++++ docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md | 9 ++ 6 files changed, 528 insertions(+) create mode 100644 .github/scripts/read-d270-android-artifact.cjs create mode 100644 .github/scripts/read-d270-android-artifact.py create mode 100644 .github/tests/d270-android-artifact-readout.test.cjs create mode 100644 .github/tests/test_d270_android_artifact_readout.py create mode 100644 .github/workflows/r5-d270-android-artifact-readout.yml create mode 100644 docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md diff --git a/.github/scripts/read-d270-android-artifact.cjs b/.github/scripts/read-d270-android-artifact.cjs new file mode 100644 index 000000000..0dea666a6 --- /dev/null +++ b/.github/scripts/read-d270-android-artifact.cjs @@ -0,0 +1,122 @@ +'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 = 120796675691; +const SOURCE = 'd27007078808617a97ee460b592eefb44e7e5325'; +const WORKFLOW = 'f5f20e6d959109cdc2e0096099992d72307255bf'; +// Exact terminal Android job/artifact API and upload facts. +const ARTIFACT = 12551461839, ZIP_SIZE = 9596, DIGEST = 'b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a'; +const NATIVE_CONCLUSION = 'failure', STEP_CONCLUSIONS = ['success', 'failure']; +const STEPS = ['Build development app', 'Run Android startup and native persistence probes']; +const CONCLUSIONS = ['success', 'failure', 'skipped']; +const NAME = `keeper-diagnostic-native-ANDROID-${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-android-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'); + assert.equal(r.data.status, 'completed'); assert.equal(r.data.conclusion, 'failure'); + 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-android-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-android-artifact.py'], + { encoding: 'utf8', timeout: 30000, maxBuffer: 2 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] }); + } catch (error) { + const match = /^D270_ANDROID_OBSERVATION_READOUT_FAILED:(PRIVATE_FILE|KERNEL|ZIP_IDENTITY|ZIP_LAYOUT|JSON|ROOT_KEYS|PRODUCT|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_ANDROID_OBSERVATIONS_BEGIN'); + assert.equal(lines[2], 'D270_ANDROID_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-android-artifact.py b/.github/scripts/read-d270-android-artifact.py new file mode 100644 index 000000000..9a5a1ced1 --- /dev/null +++ b/.github/scripts/read-d270-android-artifact.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +"""Project fixed d270 Android failure facts using the unchanged 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 = '1e9fc4370d733041fb5a48dc8c022e3461decafbf970ba030e90784208aed1d9' +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 = 9596 +DIGEST = 'b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a' +SCOPE = 'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE' +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')) +SAMPLE_FIELDS = frozenset(('sample', 'status', 'completed_stages', 'pin_onboarding_progress', + 'create_new_app_calls', 'other_backend_calls_rejected', 'failure_observation', + 'failed_assertion_snapshot', 'android_runtime_diagnostic')) + + +def project(blob): + global PHASE + PHASE = 'KERNEL' + source = ROOT / 'read-044-android-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_android_kernel', source) + kernel = importlib.util.module_from_spec(spec) + spec.loader.exec_module(kernel) + literals = kernel.public_literals() # Original hash-checked 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 | {SOURCE, WORKFLOW, WORKFLOW_REF, RUN, ATTEMPT} + 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 != 'android/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 = 'PRODUCT' + product = data.get('product_ui') + if (type(product) is not dict or product.get('status') != 'FAIL' or + type(product.get('samples')) is not list or not 1 <= len(product['samples']) <= 6 or + any(type(sample) is not dict for sample in product['samples'])): + kernel.rejected() + projected['product_ui'] = {key: product[key] for key in ('status', 'failure_category') if key in product} + projected['product_ui']['samples'] = [{key: value for key, value in sample.items() if key in SAMPLE_FIELDS} + for sample in product['samples']] + 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-android-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_ANDROID_OBSERVATION_READOUT_FAILED:' + PHASE) + return 1 + print('D270_ANDROID_OBSERVATIONS_BEGIN') + print(json.dumps(result, sort_keys=True, separators=(',', ':'))) + print('D270_ANDROID_OBSERVATIONS_END') + return 0 + + +if __name__ == '__main__': + import sys + raise SystemExit(main(sys.argv[1:])) diff --git a/.github/tests/d270-android-artifact-readout.test.cjs b/.github/tests/d270-android-artifact-readout.test.cjs new file mode 100644 index 000000000..5f892bd4d --- /dev/null +++ b/.github/tests/d270-android-artifact-readout.test.cjs @@ -0,0 +1,152 @@ +'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-android-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 = 12551461839, ZIP_SIZE = 9596, DIGEST = 'b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a';"; +const OUTCOME = "const NATIVE_CONCLUSION = 'failure', STEP_CONCLUSIONS = ['success', 'failure'];"; + +function fixture(options = {}) { + const context = { repo: { owner: 'KeeperCommunity', repo: 'bitcoin-keeper' }, + eventName: 'push', ref: 'refs/heads/codex/r5-d270-android-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: 'completed', conclusion: 'failure', + referenced_workflows: [{path: `KeeperCommunity/bitcoin-keeper/.github/workflows/keeper-native-platform.yml@${WORKFLOW}`, + ref: 'refs/pull/7149/merge', sha: WORKFLOW}] }; + const jobData = { id: 120796675691, run_id: 40065599904, run_attempt: 1, head_sha: SOURCE, + status: 'completed', conclusion: 'failure', steps: [ + ['Build development app', 'success'], ['Run Android startup and native persistence probes', 'failure'], ['Retain safe Phase A evidence', 'success'] + ].map(([name, conclusion]) => ({name, conclusion, status: 'completed'})) }; + const artifact = {id: options.production ? 12551461839 : 991, + name: `keeper-diagnostic-native-ANDROID-${SOURCE}-40065599904-1`, expired: false, + size_in_bytes: options.production ? 9596 : PAYLOAD.length, + digest: 'sha256:' + (options.production ? 'b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a' : 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-android-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-android-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_ANDROID_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_ANDROID_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(9596)}); + 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,12551461839); assert.equal(f.calls[3][1].artifact_id,12551461839); + assert.deepEqual(f.events,[]); assert.deepEqual(f.output,[]); +}); + +test('every incomplete observed binding fails before API/filesystem', async()=>{ + for(const [before,after] of [["ARTIFACT = 12551461839","ARTIFACT = null"], ['ZIP_SIZE = 9596','ZIP_SIZE = null'], + ["DIGEST = 'b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a'",'DIGEST = null'], ["NATIVE_CONCLUSION = 'failure'",'NATIVE_CONCLUSION = null'], + ["STEP_CONCLUSIONS = ['success', 'failure']",'STEP_CONCLUSIONS = null'], + ["STEP_CONCLUSIONS = ['success', 'failure']", "STEP_CONCLUSIONS = ['success', ,]"], + ["STEP_CONCLUSIONS = ['success', 'failure']", "STEP_CONCLUSIONS = ['success', undefined]"], + ["STEP_CONCLUSIONS = ['success', 'failure']", "STEP_CONCLUSIONS = ['success', null]"]]) { + 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 terminal job binds exact outcomes and purge precedes projection 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,120796675691); + 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[2].conclusion='failure',f=>f.jobData.steps.push(f.jobData.steps[2]),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_ANDROID_OBSERVATION_READOUT_FAILED:PRODUCT\n','DECODE_PRODUCT'], + ['D270_ANDROID_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_android_artifact_readout.py b/.github/tests/test_d270_android_artifact_readout.py new file mode 100644 index 000000000..102b24352 --- /dev/null +++ b/.github/tests/test_d270_android_artifact_readout.py @@ -0,0 +1,107 @@ +"""Original-byte binding and private-output controls, using synthetic receipts only.""" +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_android_readout', + Path(__file__).resolve().parents[1] / 'scripts/read-d270-android-artifact.py') +reader = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(reader) +FIXTURE_SPEC = importlib.util.spec_from_file_location('fixed_android_fixtures', + Path(__file__).with_name('test_044_android_artifact_readout.py')) +fixtures = importlib.util.module_from_spec(FIXTURE_SPEC) +FIXTURE_SPEC.loader.exec_module(fixtures) + + +def fixture(): + value = fixtures.observed_data() + value.update(source_sha=reader.SOURCE, workflow_sha=reader.WORKFLOW, + workflow_ref=reader.WORKFLOW_REF, run_id=reader.RUN, run_attempt=reader.ATTEMPT) + value['commands'] = [{'PRIVATE_PATH_OR_OTHER_UNEXPORTED_CONTENT': 'PRIVATE_SENTINEL'}] + value['product_ui']['performance_scope'] = 'PRIVATE_SENTINEL' + value['product_ui']['samples'][0]['unselected_optional_field'] = 'PRIVATE_SENTINEL' + return value + + +def archive(data=None, raw=None, extra=False): + stream = io.BytesIO() + with zipfile.ZipFile(stream, 'w', zipfile.ZIP_DEFLATED) as output: + output.writestr('android/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 D270AndroidReadoutTests(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_bounded_failure_facts_survive_and_unselected_content_never_exports(self): + data = fixture(); result = self.project(data) + self.assertEqual(result['scope'], 'OBSERVATIONS_ONLY_NOT_NATIVE_ACCEPTANCE_OR_CAUSE') + self.assertEqual(result['observations']['smoke'], 'PASS') + self.assertEqual(result['observations']['product_ui']['status'], 'FAIL') + self.assertEqual(result['observations']['product_ui']['samples'][0]['failure_observation'], + data['product_ui']['samples'][0]['failure_observation']) + self.assertEqual(result['observations']['product_ui']['samples'][0]['failed_assertion_snapshot'], + data['product_ui']['samples'][0]['failed_assertion_snapshot']) + self.assertEqual(len(result['metadata_sha256']), 64) + self.assertNotIn('commands', result['observations']) + self.assertNotIn('PRIVATE_SENTINEL', json.dumps(result)) + + def test_wrong_source_platform_attempt_workflow_and_unknown_root_reject(self): + for key, value in [('source_sha', '0' * 40), ('platform', 'IOS'), ('run_attempt', '2'), + ('workflow_sha', '0' * 40), ('raw_logs', 'PRIVATE_SENTINEL')]: + data = fixture(); data[key] = value + with self.subTest(key=key), self.assertRaises(Exception): self.project(data) + + def test_projected_raw_values_unknown_nested_data_and_bad_snapshot_types_reject(self): + changes = [lambda s: s['failure_observation'].update(raw_logs='PRIVATE_SENTINEL'), + lambda s: s['failure_observation']['hierarchy']['flags'].update(onboarding_skip=1), + lambda s: s['failed_assertion_snapshot']['skip'].update(clickable='false'), + lambda s: s['failed_assertion_snapshot'].update(node_count=10001), + lambda s: s['failed_assertion_snapshot'].update(raw='PRIVATE_SENTINEL'), + lambda s: s['android_runtime_diagnostic']['facts'].update(message='PRIVATE_SENTINEL'), + lambda s: s['failed_assertion_snapshot']['failed_assertion'].update(selector='onboarding_skip')] + for change in changes: + data = fixture(); change(data['product_ui']['samples'][0]) + with self.subTest(change=change), self.assertRaises(Exception): self.project(data) + + def test_missing_failed_sample_wrong_product_types_and_unsafe_json_reject(self): + for product in [None, [], {'status': 'PASS', 'samples': [{}]}, + {'status': 'FAIL', 'samples': []}, {'status': 'FAIL', 'samples': [None]}, + {'status': 'FAIL', 'samples': [{}] * 7}]: + data = fixture(); data['product_ui'] = product + with self.subTest(product=product), self.assertRaises(Exception): self.project(data) + for blob in [archive(raw='{"schema":1,"schema":1}'), archive(raw='{"schema":NaN}'), + archive(extra=True), archive() + b'PRIVATE_SENTINEL']: + with self.subTest(size=len(blob)), self.assertRaises(Exception): self.project(blob=blob) + + def test_original_digest_kernel_change_and_private_file_alias_fail_without_observations(self): + blob = archive() + with self.assertRaises(Exception): reader.project(blob) + with bound(blob), mock.patch.object(reader, 'KERNEL_SHA256', '0' * 64), self.assertRaises(Exception): + reader.project(blob) + 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-android-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_ANDROID_OBSERVATION_READOUT_FAILED:PRIVATE_FILE\n') + + +if __name__ == '__main__': + unittest.main() diff --git a/.github/workflows/r5-d270-android-artifact-readout.yml b/.github/workflows/r5-d270-android-artifact-readout.yml new file mode 100644 index 000000000..515cdd81c --- /dev/null +++ b/.github/workflows/r5-d270-android-artifact-readout.yml @@ -0,0 +1,36 @@ +name: Read fixed d270 Android observations + +on: + push: + branches: [codex/r5-d270-android-artifact-readout-20261024] + paths: + - .github/workflows/r5-d270-android-artifact-readout.yml + - .github/scripts/read-d270-android-artifact.cjs + - .github/scripts/read-d270-android-artifact.py + - .github/tests/d270-android-artifact-readout.test.cjs + - .github/tests/test_d270_ios_artifact_readout.py + +permissions: + contents: read + actions: read + +concurrency: + group: r5-fixed-d270-android-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-android-artifact-readout-20261024' + runs-on: ubuntu-24.04 + 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-android-artifact.cjs').run({ github, context, core }) + - if: always() + run: node .github/scripts/verify-ci-source.cjs diff --git a/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md b/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md new file mode 100644 index 000000000..11cd1a10c --- /dev/null +++ b/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md @@ -0,0 +1,9 @@ +# Exact d270 Android failed-sample observation readout + +This additive, metadata-only work reads existing Android artifact `12551461839` from completed native run `40065599904` attempt 1, job `120796675691`, app source `d27007078808617a97ee460b592eefb44e7e5325` and workflow `f5f20e6d959109cdc2e0096099992d72307255bf`. The original ZIP is 9,596 bytes with SHA256 `b9182e02a33b7e0568d73654b42d61f66bce8e425d65a6960aa0f4f2194ee13a`. + +The actual job built successfully and passed its startup, native persistence, controlled-adapter worker and completed-phase installed-byte probes. The first full-product first-wallet/relaunch sample then failed. The job log does not identify the exact failed UI assertion. Its retained metadata already has finite failure observations, post-assertion snapshots and scoped runtime markers; this readout exposes only those selected facts and source/status fields. It does not export command arguments, raw bytes, logs, UI text, screenshots or unselected product fields. + +The unchanged hash-pinned `read-044-android-artifact.py` kernel and its original policy validate the fixed ZIP layout, unique JSON keys, bounded values, reviewed public vocabulary and explicit hierarchy/snapshot/runtime privacy shapes. The new reader changes only fixed source/run bindings and selects a projection. The JavaScript transport checks official source, workflow, completed job, step outcomes and artifact identity both before download and before output. It deletes its owned mode-0600 temporary ZIP before logging. SDK buffering before length/digest validation remains an inherited transport limit. + +Validation: 8 Node controls and 5 Python controls passed. Actionlint 1.7.12 passed the new Ubuntu metadata-only workflow. Independent source review and hosted readout are pending. No app, native producer, privacy kernel, policy or source guard changes; no native rerun, merge, release signing, store upload or deployment. Native acceptance and the app failure cause remain unestablished until actual observations support a conclusion. From c79ca7443c1d1a4fab119dca50a0274d5d31049a Mon Sep 17 00:00:00 2001 From: Antuz tap Date: Sat, 24 Oct 2026 08:29:09 +0000 Subject: [PATCH 2/2] ci: include Android reader Python controls in path filter --- .github/workflows/r5-d270-android-artifact-readout.yml | 2 +- docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/r5-d270-android-artifact-readout.yml b/.github/workflows/r5-d270-android-artifact-readout.yml index 515cdd81c..c5244686d 100644 --- a/.github/workflows/r5-d270-android-artifact-readout.yml +++ b/.github/workflows/r5-d270-android-artifact-readout.yml @@ -8,7 +8,7 @@ on: - .github/scripts/read-d270-android-artifact.cjs - .github/scripts/read-d270-android-artifact.py - .github/tests/d270-android-artifact-readout.test.cjs - - .github/tests/test_d270_ios_artifact_readout.py + - .github/tests/test_d270_android_artifact_readout.py permissions: contents: read diff --git a/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md b/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md index 11cd1a10c..6c9028cf0 100644 --- a/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md +++ b/docs/r5/D270-ANDROID-FAILURE-OBSERVATIONS.md @@ -6,4 +6,4 @@ The actual job built successfully and passed its startup, native persistence, co The unchanged hash-pinned `read-044-android-artifact.py` kernel and its original policy validate the fixed ZIP layout, unique JSON keys, bounded values, reviewed public vocabulary and explicit hierarchy/snapshot/runtime privacy shapes. The new reader changes only fixed source/run bindings and selects a projection. The JavaScript transport checks official source, workflow, completed job, step outcomes and artifact identity both before download and before output. It deletes its owned mode-0600 temporary ZIP before logging. SDK buffering before length/digest validation remains an inherited transport limit. -Validation: 8 Node controls and 5 Python controls passed. Actionlint 1.7.12 passed the new Ubuntu metadata-only workflow. Independent source review and hosted readout are pending. No app, native producer, privacy kernel, policy or source guard changes; no native rerun, merge, release signing, store upload or deployment. Native acceptance and the app failure cause remain unestablished until actual observations support a conclusion. +Validation: 8 Node controls and 5 Python controls passed. Inherited unchanged-kernel controls also passed (6 Node, 16 Python). Actionlint 1.7.12 passed the new Ubuntu metadata-only workflow; shellcheck and pyflakes are unavailable locally. Independent source review and hosted readout are pending. No app, native producer, privacy kernel, policy or source guard changes; no native rerun, merge, release signing, store upload or deployment. Native acceptance and the app failure cause remain unestablished until actual observations support a conclusion.