| 1 | #!/usr/bin/env python3 |
| 2 | """Run opt-in, private-store HTTPS acceptance across sibling app worktrees.""" |
| 3 | import argparse |
| 4 | import json |
| 5 | import os |
| 6 | from pathlib import Path |
| 7 | import subprocess |
| 8 | import tempfile |
| 9 | import time |
| 10 | |
| 11 | parser = argparse.ArgumentParser(description=__doc__) |
| 12 | parser.add_argument('--workspace', type=Path, default=Path(__file__).resolve().parents[2]) |
| 13 | args = parser.parse_args() |
| 14 | runtime = Path(__file__).resolve().parents[1] |
| 15 | env = dict(os.environ, GOTOOLCHAIN='go1.26.5', CGO_ENABLED='0') |
| 16 | with tempfile.TemporaryDirectory(prefix='oficina-suite-interop-') as temporary: |
| 17 | directory = Path(temporary) |
| 18 | binaries = {} |
| 19 | for app in ('docs', 'calls', 'calendar'): |
| 20 | binary = directory / (app + '.test') |
| 21 | subprocess.run(['go', 'test', '-c', '-o', str(binary), './internal/' + app], cwd=args.workspace / (app + '-agent-access'), env=env, check=True) |
| 22 | binaries[app] = binary |
| 23 | env['OFICINA_INTEROP_DIR'] = str(directory) |
| 24 | processes = [] |
| 25 | logs = [] |
| 26 | try: |
| 27 | for app, binary in binaries.items(): |
| 28 | log = (directory / (app + '.log')).open('w+') |
| 29 | logs.append((app, log)) |
| 30 | processes.append(subprocess.Popen([str(binary), '-test.run=^TestSuiteInteropFixture$', '-test.v'], cwd=args.workspace / (app + '-agent-access'), env=env, stdout=log, stderr=subprocess.STDOUT)) |
| 31 | deadline = time.monotonic() + 30 |
| 32 | while not all((directory / (app + '.json')).exists() for app in binaries): |
| 33 | if time.monotonic() >= deadline or any(p.poll() is not None for p in processes): |
| 34 | raise RuntimeError('An app fixture did not start') |
| 35 | time.sleep(.1) |
| 36 | subprocess.run(['go', 'test', '.', '-run', '^TestSuiteSchedulingInterop$', '-count=1', '-v'], cwd=runtime, env=env, check=True) |
| 37 | finally: |
| 38 | (directory / 'stop').touch() |
| 39 | for process in processes: |
| 40 | try: |
| 41 | process.wait(timeout=10) |
| 42 | except subprocess.TimeoutExpired: |
| 43 | process.terminate() |
| 44 | process.wait(timeout=10) |
| 45 | for app, log in logs: |
| 46 | log.seek(0) |
| 47 | print(f'{app}:\n{log.read()}') |
| 48 | log.close() |
| 49 | if any(p.returncode for p in processes): |
| 50 | raise RuntimeError('An app fixture failed') |
| 51 | |