From a0d588ba12282a43818fb6d57c120c662b3c4566 Mon Sep 17 00:00:00 2001 From: Canina Automation Date: Wed, 28 Oct 2026 21:02:09 +0000 Subject: [PATCH] fix(stage): retain allowlisted bootstrap API failure status --- scripts/stage-author-bootstrap/operation.py | 13 +++++++++---- scripts/stage-author-bootstrap/test_ci.py | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/stage-author-bootstrap/operation.py b/scripts/stage-author-bootstrap/operation.py index afb15b44..60351853 100644 --- a/scripts/stage-author-bootstrap/operation.py +++ b/scripts/stage-author-bootstrap/operation.py @@ -26,7 +26,12 @@ def check_image(d, image, sha): def api(d, backend, token): # No retry: a lost response can follow a committed transaction. - result = json.loads(d.run(['exec', '-i', backend, 'node', '-e', API_JS], token, timeout=40)) + try: + result = json.loads(d.run(['exec', '-i', backend, 'node', '-e', API_JS], token, timeout=40)) + except subprocess.CalledProcessError as error: + diagnostic = (error.stderr or b'').decode(errors='replace') + match = re.search(r'BOOTSTRAP_API_(?:STATUS_[0-9]{3}|CONTRACT|TRANSPORT)', diagnostic) + raise ValueError(match.group(0) if match else 'Bootstrap API process failed') from None if {a.get('id') for a in result.get('authors', [])} != AUTHOR_IDS: raise ValueError('API returned unexpected author identities') return result @@ -127,9 +132,9 @@ def readiness(d, cid): API_JS = r'''const fs=require('fs'); const token=fs.readFileSync(0,'utf8').trim(); (async()=>{let r=await fetch('http://127.0.0.1:39071/api/admin/users/stage-author-restoration',{ method:'POST',headers:{Authorization:'Bearer '+token},signal:AbortSignal.timeout(30000)}); -if(!r.ok)throw Error('API status '+r.status);let x=await r.json(); -if(x.success!==true||x.totalConfigured!==5||x.restoredCount+x.existingCount!==5)throw Error('API contract'); -process.stdout.write(JSON.stringify(x));})().catch(()=>{process.exit(1)});''' +if(!r.ok){console.error('BOOTSTRAP_API_STATUS_'+r.status);process.exit(1)}let x=await r.json(); +if(x.success!==true||x.totalConfigured!==5||x.restoredCount+x.existingCount!==5){console.error('BOOTSTRAP_API_CONTRACT');process.exit(1)} +process.stdout.write(JSON.stringify(x));})().catch(()=>{console.error('BOOTSTRAP_API_TRANSPORT');process.exit(1)});''' def rehearse(d, backup, sql, backend_image, env_file, token, owned, evidence): def clone(): diff --git a/scripts/stage-author-bootstrap/test_ci.py b/scripts/stage-author-bootstrap/test_ci.py index ba48bcb3..f7608e6f 100644 --- a/scripts/stage-author-bootstrap/test_ci.py +++ b/scripts/stage-author-bootstrap/test_ci.py @@ -96,6 +96,13 @@ class WorkflowTests(unittest.TestCase): class MaintenanceTests(unittest.TestCase): + def test_api_failure_diagnostic_never_leaks_stderr(self): + class D: + def run(self, *args, **kwargs): + raise subprocess.CalledProcessError(1, ['fixture'], stderr=b'private fixture BOOTSTRAP_API_STATUS_403 private fixture') + with self.assertRaisesRegex(ValueError, '^BOOTSTRAP_API_STATUS_403$'): + ci.op.api(D(), 'fixture', b'fixture') + def test_snapshot_stream_auth_matches_existing_configuration(self): import os text = (HERE / 'operation.py').read_text()