#!/usr/bin/env python3 """Fixed Linux/Windows plan guards against isolated PostgreSQL; no approval/job.""" from pathlib import Path import subprocess import time import uuid ROOT=Path(__file__).resolve().parents[1] NAME='rmm-windows-plan-'+uuid.uuid4().hex[:10] def command(args, data=None, timeout=120): result=subprocess.run(args,input=data,capture_output=True,timeout=timeout) if result.returncode: raise RuntimeError(result.stderr.decode(errors='replace')[-4000:]) return result.stdout def main(): command(['docker','run','-d','--network','none','--name',NAME, '-e','POSTGRES_HOST_AUTH_METHOD=trust','postgres:17.6-bookworm']) try: for _ in range(100): logs=command(['docker','logs',NAME]) ready=subprocess.run(['docker','exec',NAME,'pg_isready','-U','postgres'],capture_output=True) if b'init process complete' in logs and ready.returncode==0:break time.sleep(.2) else:raise RuntimeError('ISOLATED_POSTGRES_NOT_READY') def sql(raw): return command(['docker','exec','-i',NAME,'psql','-X','-qAt','-v','ON_ERROR_STOP=1','-U','postgres'],raw.encode()) sql('CREATE ROLE rmm_app LOGIN NOINHERIT NOSUPERUSER NOBYPASSRLS;') for path in sorted((ROOT/'migrations').glob('*.sql')):sql(path.read_text()) output=command(['docker','run','--rm','--network','container:'+NAME, '--read-only','--tmpfs','/tmp:rw,size=512m','-v',str(ROOT)+':/src:ro', '-v',str(ROOT/'devstate/windows-server-contract/target')+':/target','-e','CARGO_TARGET_DIR=/target', '-e','RMM_TEST_REPAIR_ADMIN_URL=postgres://postgres@127.0.0.1/postgres', '-e','RMM_TEST_REPAIR_APP_URL=postgres://rmm_app@127.0.0.1/postgres', '--entrypoint','cargo','rust-discovery-windows-tls-full:local', 'test','--locked','--offline','-p','rmm-server','windows_plan_caps_persisted_database', '--','--include-ignored','--nocapture'],timeout=300) print(output.decode()) print('PASS: real isolated PostgreSQL, fixed mixed variants/hashes, missing interpreter capability, submit/recheck, tenant denial; zero jobs/outbox/permits, no approval.') finally: subprocess.run(['docker','rm','-f',NAME],capture_output=True) if __name__=='__main__':main()