#!/usr/bin/env python3 """Shared Test2 process boundary; no release selection or database mutations.""" from __future__ import annotations import argparse import json import subprocess from pathlib import Path from standalone_l0_workers import ( L0_WORKER_STEMS, RETIRED_L0_WORKER_STEMS, WORK_FAMILY_STEMS, configured_workers, ) ENV_ROOT = Path('/home/ec2-user/nexuscrm-deployment/offline/envs/test/test2') INTEGRATION_CONTAINER = 'nexuscrm-l0-test2-integration-service' def docker(*args: str) -> str: return subprocess.run(('docker', *args), check=True, text=True, capture_output=True).stdout.strip() def require_standalone(root: Path, inventory: list[dict] | None = None) -> None: active = root / '.runtime/serviceification-d3/active.json' if active.exists() or active.is_symlink(): raise RuntimeError('Test2 is owned by an active full-D3 deployment') if inventory is None: ids = docker('ps', '-aq', '--filter', 'label=io.nexuscrm.serviceification-d3=test2').split() inventory = json.loads(docker('inspect', *ids)) if ids else [] # The handover retains Integration unchanged. Its immutable Docker labels # still record its original creator; that is not ownership of L0 or L1. for item in inventory: if (item['Name'] != '/' + INTEGRATION_CONTAINER or not item['Config']['Image'].startswith( 'ghcr.io/pingcap-inc/nexuscrm-integration-service@sha256:')): raise RuntimeError('Test2 has an unretired full-D3 process inventory') def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('operation', choices=('guard', 'workers')) parser.add_argument('--state-root', type=Path) args = parser.parse_args() if args.operation == 'guard': if args.state_root is not None: parser.error('--state-root is only valid with workers') require_standalone(ENV_ROOT) else: stems = configured_workers(args.state_root) if args.state_root else L0_WORKER_STEMS print(' '.join(stems)) if __name__ == '__main__': main()