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
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ const fs = require('node:fs');
const path = require('node:path');
const { execFileSync } = require('node:child_process');
const OWNER = 'KeeperCommunity', REPO = 'bitcoin-keeper', REPOSITORY = 470904030;
const RUN = 39858617273, JOB = 120103187854, ANDROID = 120125972406, ARTIFACT = 12462694619;
const SOURCE = '1bc34890cb8618b2fffd446a63924974e0fe15b5';
const TREE = '2e9cd57bf9f78b92cac73e9343ddbd0eef25e86e';
const WORKFLOW = '3c44ab6412a8118b183273c402dd08136db05b28';
const DIGEST = '550142809a0faf812741a586630b17d6f458b2b6c935b5bab4b00f84da67c84f';
const RUN = 39873063291, JOB = 120151926152, ANDROID = 120167960772, ARTIFACT = 12469536083;
const SOURCE = '044ebb6ea2d465f6a70e9116e3feac5a604cd696';
const TREE = '4856035ece888230674e061c53115de3d6f025ed';
const WORKFLOW = '5a7b0c5da0a38197f6dd675ff424f3ba3f441d02';
const DIGEST = 'e244015128d4aa72e1e1c8be3072bc70d506ba11a804067448122d1318621caf';
const NAME = `keeper-diagnostic-native-IOS-${SOURCE}-${RUN}-1`;
const BRANCH = 'codex/r5-ios-startup-diagnosis-20261022';
const BRANCH = 'codex/r5-startup-credential-failure-observation-20261022';

function validateRun(value, jobs) {
assert.equal(value.id, RUN); assert.equal(value.run_attempt, 1);
Expand All @@ -24,11 +24,11 @@ function validateRun(value, jobs) {
(value.status === 'completed' && value.conclusion === 'failure'));
assert.deepEqual(value.referenced_workflows, [{
path: `${OWNER}/${REPO}/.github/workflows/keeper-native-platform.yml@${WORKFLOW}`,
ref: 'refs/pull/7116/merge', sha: WORKFLOW,
ref: 'refs/pull/7131/merge', sha: WORKFLOW,
}]);
assert.equal(jobs.total_count, 3); assert.equal(jobs.jobs.length, 3);
assert.deepEqual(jobs.jobs.map(row => row.id).sort((a, b) => a - b),
[JOB, 120103189932, ANDROID].sort((a, b) => a - b));
[JOB, 120151928067, ANDROID].sort((a, b) => a - b));
const android = jobs.jobs.find(row => row.id === ANDROID);
assert.equal(android.run_id, RUN); assert.equal(android.head_sha, SOURCE);
assert.equal(android.name, 'android / Native ANDROID build and probes');
Expand Down Expand Up @@ -60,7 +60,7 @@ function validateJob(value) {

function validateArtifact(value) {
assert.equal(value.id, ARTIFACT); assert.equal(value.name, NAME);
assert.equal(value.expired, false); assert.equal(value.size_in_bytes, 6884);
assert.equal(value.expired, false); assert.equal(value.size_in_bytes, 7232);
assert.equal(value.digest, `sha256:${DIGEST}`);
assert.equal(value.workflow_run.id, RUN); assert.equal(value.workflow_run.head_sha, SOURCE);
assert.equal(value.workflow_run.repository_id, REPOSITORY);
Expand All @@ -73,7 +73,7 @@ async function run({ github, context, core }) {
try {
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-1bc-ios-artifact-readout');
assert.equal(context.ref, 'refs/heads/codex/r5-044-ios-artifact-readout');
const args = { owner: OWNER, repo: REPO, request: { timeout: 30000 } };
async function snapshot() {
const [r, j, a, jobs] = await Promise.all([
Expand All @@ -87,27 +87,27 @@ async function run({ github, context, core }) {
await snapshot();
const [commit, pr] = await Promise.all([
github.rest.repos.getCommit({ ...args, ref: SOURCE }),
github.rest.pulls.get({ ...args, pull_number: 7116 }),
github.rest.pulls.get({ ...args, pull_number: 7131 }),
]);
assert.equal(commit.data.sha, SOURCE); assert.equal(commit.data.commit.tree.sha, TREE);
assert.equal(pr.data.number, 7116); assert.equal(pr.data.head.sha, SOURCE);
assert.equal(pr.data.number, 7131); assert.equal(pr.data.head.sha, SOURCE);
assert.equal(pr.data.head.ref, BRANCH); assert.equal(pr.data.head.repo.id, REPOSITORY);
assert.equal(pr.data.state, 'open'); assert.equal(pr.data.merged, false);
const download = await github.rest.actions.downloadArtifact({ ...args, artifact_id: ARTIFACT, archive_format: 'zip' });
const bytes = Buffer.from(download.data);
assert.equal(bytes.length, 6884);
assert.equal(bytes.length, 7232);
assert.equal(crypto.createHash('sha256').update(bytes).digest('hex'), DIGEST);
await snapshot(); // A later attempt or replacement cannot supply this readout.
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-1bc-ios-fixed.zip');
const filename = path.join(temp, 'r5-044-ios-fixed.zip');
const descriptor = fs.openSync(filename, 'wx', 0o600);
owned = { filename }; // A failed stat still reports unresolved private cleanup.
try {
const info = fs.fstatSync(descriptor); Object.assign(owned, { dev: info.dev, ino: info.ino });
fs.writeFileSync(descriptor, bytes);
} finally { fs.closeSync(descriptor); }
output = execFileSync('python3', ['-B', '.github/scripts/read-1bc-ios-artifact.py'],
output = execFileSync('python3', ['-B', '.github/scripts/read-044-ios-artifact.py'],
{ encoding: 'utf8', timeout: 30000, maxBuffer: 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
const tag = 'SAFE_R5_IOS_READOUT ';
assert.ok(output.startsWith(tag));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import sys
import zipfile

SOURCE = '1bc34890cb8618b2fffd446a63924974e0fe15b5'
WORKFLOW = '3c44ab6412a8118b183273c402dd08136db05b28'
WORKFLOW_REF = 'KeeperCommunity/bitcoin-keeper/.github/workflows/keeper-native-diagnostic.yml@refs/pull/7116/merge'
RUN, ATTEMPT, ARTIFACT = '39858617273', '1', '12462694619'
ZIP_SIZE, LIMIT = 6884, 1024 * 1024
ZIP_SHA256 = '550142809a0faf812741a586630b17d6f458b2b6c935b5bab4b00f84da67c84f'
SOURCE = '044ebb6ea2d465f6a70e9116e3feac5a604cd696'
WORKFLOW = '5a7b0c5da0a38197f6dd675ff424f3ba3f441d02'
WORKFLOW_REF = 'KeeperCommunity/bitcoin-keeper/.github/workflows/keeper-native-diagnostic.yml@refs/pull/7131/merge'
RUN, ATTEMPT, ARTIFACT = '39873063291', '1', '12469536083'
ZIP_SIZE, LIMIT = 7232, 1024 * 1024
ZIP_SHA256 = 'e244015128d4aa72e1e1c8be3072bc70d506ba11a804067448122d1318621caf'
ERROR_TYPES = ('ValueError', 'TypeError', 'OSError', 'FileNotFoundError', 'PermissionError',
'TimeoutExpired', 'JSONDecodeError', 'RuntimeError', 'OTHER_ERROR')
IOS_CATEGORIES = ('JS_TYPE', 'JS_REFERENCE', 'JS_SYNTAX', 'JS_RANGE', 'JS_INVARIANT',
Expand Down Expand Up @@ -142,6 +142,35 @@ def observations(value):
return result


def startup_failure(value):
value = obj(value)
phases = ('ACCOUNT_STATE', 'NATIVE_CREDENTIAL_READ', 'CREDENTIAL_JSON', 'NAVIGATION')
names = ('Error', 'TypeError', 'SyntaxError', 'ReferenceError', 'RangeError',
'EvalError', 'URIError', 'AggregateError', 'OTHER', 'UNKNOWN')
rows = value.get('records')
safe_rows = []
for row in rows[:32] if type(rows) is list else []:
row = obj(row)
phase, outcome = enum(row.get('phase'), phases), enum(row.get('outcome'), ('THREW', 'REJECTED'))
code = row.get('code')
safe_rows.append({'phase': phase, 'outcome': outcome, 'error_name': enum(row.get('error_name'), names),
'code': code if phase == 'NATIVE_CREDENTIAL_READ' and outcome == 'REJECTED' and
type(code) is int and -2147483648 <= code <= 2147483647 else None,
'window_relation': enum(row.get('window_relation'), ('IN_WINDOW',))})
reasons = ('MISSING_WINDOW', 'INVALID_WINDOW', 'NO_MARKER_OBSERVED', 'INVALID_COMPACT_RECORD',
'INVALID_RECORD_FIELDS', 'MALFORMED_MARKER', 'UNSUPPORTED_FRAMING', 'FOREIGN_PROCESS_MARKER',
'OUTSIDE_WINDOW', 'MULTIPLE_OWN_PIDS', 'DUPLICATE_MARKER', 'MULTIPLE_MARKERS',
'OBSERVATION_LIMIT', 'PARTIAL_INPUT', 'QUERY_UNAVAILABLE')
return {'status': enum(value.get('status'), ('OBSERVED', 'AMBIGUOUS', 'UNKNOWN')),
'cause': 'UNDETERMINED', 'window': enum(value.get('window'), ('BOUNDED', 'UNKNOWN', 'INVALID')),
'records': safe_rows, 'reasons': fixed_list(value.get('reasons'), reasons),
**{key: count(value.get(key), 32) for key in ('marker_records_seen', 'duplicate_records',
'malformed_markers', 'invalid_compact_markers', 'invalid_record_fields', 'foreign_process_markers',
'outside_window_markers', 'own_process_count')},
**flags(value, ('own_process_count_capped', 'limit_reached', 'input_partial')),
'scope': 'REPORTED_ORIGINAL_MARKERS_NOT_CAUSE_OR_ACCEPTANCE_NO_RAW_PID_OR_TIMESTAMP'}


def diagnostics(value):
value = obj(value)
ios, driver, maestro = (obj(value.get(key)) for key in ('ios_errors', 'maestro_preflight', 'maestro'))
Expand All @@ -153,6 +182,7 @@ def diagnostics(value):
'error_type': enum(obj(row).get('error_type'), ERROR_TYPES)}
for row in errors[:32]] if type(errors) is list else [],
'ios_errors': {
'startup_failure_receipt': startup_failure(ios.get('startup_failure_receipt')),
'cause': 'UNDETERMINED', 'query_status': enum(ios.get('query_status'), ('SUCCESS', 'FAILED', 'TIMEOUT')),
'parse_status': enum(ios.get('parse_status'), ('PARSED', 'PARTIAL', 'UNKNOWN')),
'observation_state': enum(ios.get('observation_state'), ('OWN_RECORDS_OBSERVED', 'UNKNOWN')),
Expand Down Expand Up @@ -253,7 +283,7 @@ def main(argv=None):
temp = Path(os.environ['RUNNER_TEMP'])
if not temp.is_absolute() or temp.resolve(strict=True) != temp:
raise ValueError('Artifact rejected.')
path = temp / 'r5-1bc-ios-fixed.zip'
path = temp / 'r5-044-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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ const test = require('node:test');
const fs = require('node:fs');
const path = require('node:path');
const vm = require('node:vm');
const { run } = require('../scripts/read-1bc-ios-artifact.cjs');
const SOURCE = '1bc34890cb8618b2fffd446a63924974e0fe15b5';
const WORKFLOW = '3c44ab6412a8118b183273c402dd08136db05b28';
const DIGEST = '550142809a0faf812741a586630b17d6f458b2b6c935b5bab4b00f84da67c84f';
const { run } = require('../scripts/read-044-ios-artifact.cjs');
const SOURCE = '044ebb6ea2d465f6a70e9116e3feac5a604cd696';
const WORKFLOW = '5a7b0c5da0a38197f6dd675ff424f3ba3f441d02';
const DIGEST = 'e244015128d4aa72e1e1c8be3072bc70d506ba11a804067448122d1318621caf';

function fixture() {
const context = { repo: { owner: 'KeeperCommunity', repo: 'bitcoin-keeper' },
eventName: 'push', ref: 'refs/heads/codex/r5-1bc-ios-artifact-readout' };
const runData = { id: 39858617273, run_attempt: 1, repository: { id: 470904030 },
eventName: 'push', ref: 'refs/heads/codex/r5-044-ios-artifact-readout' };
const runData = { id: 39873063291, run_attempt: 1, repository: { id: 470904030 },
head_repository: { id: 470904030 }, head_sha: SOURCE, event: 'pull_request',
head_branch: 'codex/r5-ios-startup-diagnosis-20261022', path: '.github/workflows/keeper-native-diagnostic.yml',
head_branch: 'codex/r5-startup-credential-failure-observation-20261022', 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/7116/merge', sha: WORKFLOW }] };
const jobData = { id: 120103187854, run_id: 39858617273, head_sha: SOURCE,
ref: 'refs/pull/7131/merge', sha: WORKFLOW }] };
const jobData = { id: 120151926152, run_id: 39873063291, head_sha: SOURCE,
name: 'ios / Native IOS build and probes', status: 'completed', conclusion: 'failure',
steps: [['Check out exact app source', 'success'], ['Verify current diagnostic source', 'success'],
['Install immutable native dependencies', 'success'], ['Check disposable iOS driver readiness', 'success'],
['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 jobs = { total_count: 3, jobs: [{ id: 120103187854 }, { id: 120103189932 },
{ id: 120125972406, run_id: 39858617273, head_sha: SOURCE,
const jobs = { total_count: 3, jobs: [{ id: 120151926152 }, { id: 120151928067 },
{ id: 120167960772, run_id: 39873063291, head_sha: SOURCE,
name: 'android / Native ANDROID build and probes', status: 'in_progress', conclusion: null }] };
const artifact = { id: 12462694619, name: `keeper-diagnostic-native-IOS-${SOURCE}-39858617273-1`,
expired: false, size_in_bytes: 6884, digest: `sha256:${DIGEST}`, workflow_run: {
id: 39858617273, head_sha: SOURCE, repository_id: 470904030, head_repository_id: 470904030,
head_branch: 'codex/r5-ios-startup-diagnosis-20261022' } };
const commit = { sha: SOURCE, commit: { tree: { sha: '2e9cd57bf9f78b92cac73e9343ddbd0eef25e86e' } } };
const pr = { number: 7116, head: { sha: SOURCE, ref: runData.head_branch, repo: { id: 470904030 } },
const artifact = { id: 12469536083, name: `keeper-diagnostic-native-IOS-${SOURCE}-39873063291-1`,
expired: false, size_in_bytes: 7232, digest: `sha256:${DIGEST}`, workflow_run: {
id: 39873063291, head_sha: SOURCE, repository_id: 470904030, head_repository_id: 470904030,
head_branch: 'codex/r5-startup-credential-failure-observation-20261022' } };
const commit = { sha: SOURCE, commit: { tree: { sha: '4856035ece888230674e061c53115de3d6f025ed' } } };
const pr = { number: 7131, head: { sha: SOURCE, ref: runData.head_branch, repo: { id: 470904030 } },
state: 'open', merged: false };
const calls = [], output = [], actions = {};
for (const [name, data] of [['getWorkflowRun', runData], ['getJobForWorkflowRun', jobData],
['getArtifact', artifact], ['listJobsForWorkflowRun', jobs]]) {
actions[name] = async args => { calls.push([name, args]); return { data }; };
}
actions.downloadArtifact = async args => { calls.push(['downloadArtifact', args]); return { data: Buffer.alloc(6884) }; };
actions.downloadArtifact = async args => { calls.push(['downloadArtifact', args]); return { data: Buffer.alloc(7232) }; };
const inputs = { github: { rest: { actions,
repos: { getCommit: async args => { calls.push(['getCommit', args]); return { data: commit }; } },
pulls: { get: async args => { calls.push(['getPR', args]); return { data: pr }; } } } }, context,
Expand All @@ -54,7 +54,7 @@ test('current iOS provenance reaches only the fixed archive; unknown bytes suppl
await assert.rejects(f.invoke, /^Error: FIXED_IOS_ARTIFACT_READOUT_FAILED$/);
assert.deepEqual(f.calls.at(-1), ['downloadArtifact', {
owner: 'KeeperCommunity', repo: 'bitcoin-keeper', request: { timeout: 30000 },
artifact_id: 12462694619, archive_format: 'zip' }]);
artifact_id: 12469536083, archive_format: 'zip' }]);
assert.deepEqual(f.output, []);
});

Expand Down Expand Up @@ -92,8 +92,8 @@ test('stale, contradictory or cross-source API evidence fails before download',

function synthetic(f, options = {}) {
const events = [];
const receipt = { source_sha: SOURCE, workflow_sha: WORKFLOW, run_id: '39858617273', run_attempt: '1',
artifact_id: '12462694619', readout_only: true, authorization_eligible: false, trusted_native_acceptance: false };
const receipt = { source_sha: SOURCE, workflow_sha: WORKFLOW, run_id: '39873063291', run_attempt: '1',
artifact_id: '12469536083', readout_only: true, authorization_eligible: false, trusted_native_acceptance: false };
const sandbox = { 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)));
Expand All @@ -102,7 +102,7 @@ function synthetic(f, options = {}) {
if (name === 'node:crypto') return { createHash: () => ({ update() { return this; }, digest: () => DIGEST }) };
if (name === 'node:fs') return {
realpathSync: x => x, openSync(filename, flags, mode) {
assert.equal(filename, '/owned/r5-1bc-ios-fixed.zip'); assert.equal(flags, 'wx'); assert.equal(mode, 0o600);
assert.equal(filename, '/owned/r5-044-ios-fixed.zip'); assert.equal(flags, 'wx'); assert.equal(mode, 0o600);
events.push('open'); return 42;
}, fstatSync() { if (options.stat) throw new Error('PRIVATE_SENTINEL'); return { dev: 1, ino: 2 }; },
writeFileSync() { events.push('write'); if (options.write) throw new Error('PRIVATE_SENTINEL'); },
Expand All @@ -111,20 +111,20 @@ function synthetic(f, options = {}) {
unlinkSync() { events.push('unlink'); if (options.unlink) throw new Error('PRIVATE_SENTINEL'); },
};
if (name === 'node:child_process') return { execFileSync(command, args) {
assert.equal(command, 'python3'); assert.deepEqual(Array.from(args), ['-B', '.github/scripts/read-1bc-ios-artifact.py']);
assert.equal(command, 'python3'); assert.deepEqual(Array.from(args), ['-B', '.github/scripts/read-044-ios-artifact.py']);
events.push('decoder'); if (options.decoder) throw new Error('PRIVATE_SENTINEL');
return options.raw ? 'PRIVATE_SENTINEL' : 'SAFE_R5_IOS_READOUT ' + JSON.stringify(receipt);
} };
throw new Error('Unexpected synthetic import');
} };
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../scripts/read-1bc-ios-artifact.cjs'), 'utf8'), sandbox);
vm.runInNewContext(fs.readFileSync(path.join(__dirname, '../scripts/read-044-ios-artifact.cjs'), 'utf8'), sandbox);
f.inputs.core = { info(value) { events.push('info'); f.output.push(value); }, warning(value) { events.push('warning'); f.output.push(value); } };
return { events, invoke: () => sandbox.module.exports.run(f.inputs) };
}

test('post-download freshness rejects a later attempt before private write or decoding', async () => {
const f = fixture(); f.inputs.github.rest.actions.downloadArtifact = async () => {
f.runData.run_attempt++; return { data: Buffer.alloc(6884) };
f.runData.run_attempt++; return { data: Buffer.alloc(7232) };
};
const s = synthetic(f); await assert.rejects(s.invoke, /FIXED_IOS_ARTIFACT_READOUT_FAILED/);
assert.deepEqual(s.events, []); assert.deepEqual(f.output, []);
Expand Down
Loading