From 5c93517b9e8bd45dd65ecf51e7299b1a04a373c2 Mon Sep 17 00:00:00 2001 From: Canina Automation Date: Wed, 28 Oct 2026 20:57:03 +0000 Subject: [PATCH] fix(stage): stream Redis snapshot with native stdout support --- scripts/stage-author-bootstrap/operation.py | 2 +- scripts/stage-author-bootstrap/test_ci.py | 16 ++++++++++++++++ scripts/stage-author-bootstrap/test_operation.py | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/scripts/stage-author-bootstrap/operation.py b/scripts/stage-author-bootstrap/operation.py index 87730846..afb15b44 100644 --- a/scripts/stage-author-bootstrap/operation.py +++ b/scripts/stage-author-bootstrap/operation.py @@ -161,7 +161,7 @@ def rehearse(d, backup, sql, backend_image, env_file, token, owned, evidence): if redis_info.get('Name') != '/canino_redis_stage' or not redis_info.get('State', {}).get('Running'): raise ValueError('Stage session validator unavailable') rdb = d.run(['exec', 'canino_redis_stage', 'sh', '-c', - 'export REDISCLI_AUTH="$REDIS_PASSWORD"; exec redis-cli --rdb /dev/stdout'], timeout=120) + 'if [ -n "$REDIS_PASSWORD" ]; then export REDISCLI_AUTH="$REDIS_PASSWORD"; else unset REDISCLI_AUTH; fi; exec redis-cli --rdb -'], timeout=120) if not rdb.startswith(b'REDIS'): raise ValueError('Invalid Stage blacklist snapshot') redis = d.run(['create', '--pull=never', '--network=container:' + cid, redis_info['Image'], 'redis-server', '--bind', '127.0.0.1', diff --git a/scripts/stage-author-bootstrap/test_ci.py b/scripts/stage-author-bootstrap/test_ci.py index 0761b350..ba48bcb3 100644 --- a/scripts/stage-author-bootstrap/test_ci.py +++ b/scripts/stage-author-bootstrap/test_ci.py @@ -96,6 +96,22 @@ class WorkflowTests(unittest.TestCase): class MaintenanceTests(unittest.TestCase): + def test_snapshot_stream_auth_matches_existing_configuration(self): + import os + text = (HERE / 'operation.py').read_text() + command = next(line.strip().split("'", 2)[1] for line in text.splitlines() + if 'if [ -n "$REDIS_PASSWORD" ]' in line) + self.assertIn('exec redis-cli --rdb -', command) + with tempfile.TemporaryDirectory(dir='/opt/data/cache/scratch') as tmp: + cli = Path(tmp) / 'redis-cli' + cli.write_text('#!/bin/sh\nprintf "%s:%s:%s" "${REDISCLI_AUTH-unset}" "$1" "$2"\n') + cli.chmod(0o700) + for password, expected in [('', 'unset:--rdb:-'), ('fixture', 'fixture:--rdb:-')]: + env = dict(os.environ, PATH=tmp+':'+os.environ['PATH'], + REDIS_PASSWORD=password, REDISCLI_AUTH='stale-fixture') + result = subprocess.run(['sh','-c',command], env=env, capture_output=True, text=True, check=True) + self.assertEqual(result.stdout, expected) + def test_no_published_port_real_validator_and_single_post(self): op=ci.op calls=[] diff --git a/scripts/stage-author-bootstrap/test_operation.py b/scripts/stage-author-bootstrap/test_operation.py index 3ca55420..5642e456 100644 --- a/scripts/stage-author-bootstrap/test_operation.py +++ b/scripts/stage-author-bootstrap/test_operation.py @@ -33,7 +33,7 @@ class RecoveryTests(unittest.TestCase): return b'[{"Name":"/canino_redis_stage","State":{"Running":true},"Image":"redis"}]' if args[:2] == ['inspect', '-f']: return b'true' if args[0] == 'create': return ('b'*64).encode() - if '--rdb /dev/stdout' in ' '.join(args): return b'REDISsnapshot' + if '--rdb -' in ' '.join(args): return b'REDISsnapshot' if 'PING' in args: return b'PONG' if args[0] == 'run': return ('a'*64).encode() if 'pg_restore' in args: