forked from mtusi2026/mtusi2026lab4
Add two API replicas, safe object reconciliation, upload validation, regression tests and documented load experiments.
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
"""Run the isolated writer/scanner integration test without logging credentials."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
|
|
|
|
def main():
|
|
result = subprocess.run(
|
|
['docker', 'compose', 'exec', '-T', 'reconciler', 'node', '-e',
|
|
'process.stdout.write(JSON.stringify({S3_ACCESS_KEY_ID:process.env.S3_ACCESS_KEY_ID,'
|
|
'S3_SECRET_ACCESS_KEY:process.env.S3_SECRET_ACCESS_KEY}))'],
|
|
cwd=ROOT, capture_output=True, text=True, check=True, timeout=30,
|
|
)
|
|
credentials = json.loads(result.stdout)
|
|
if not all(credentials.values()):
|
|
raise RuntimeError('Reconciler credentials are missing')
|
|
payload = json.dumps({
|
|
'credentials': credentials,
|
|
'source': (ROOT / 'test/reconcile.mjs').read_text(encoding='utf-8'),
|
|
})
|
|
loader = (
|
|
"let input='';for await(const chunk of process.stdin)input+=chunk;"
|
|
"const {source,credentials}=JSON.parse(input);"
|
|
"process.env.RECONCILE_TEST_SCANNER_CREDENTIALS=JSON.stringify(credentials);"
|
|
"await import('data:text/javascript;base64,'+"
|
|
"Buffer.from(source+'\\n//# sourceURL=reconcile.integration.mjs').toString('base64'));"
|
|
)
|
|
return subprocess.run(
|
|
['docker', 'compose', 'exec', '-T', '--index', '1', 'api',
|
|
'node', '--input-type=module', '-e', loader],
|
|
cwd=ROOT, input=payload, text=True, timeout=120,
|
|
).returncode
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
sys.exit(main())
|
|
except (subprocess.SubprocessError, ValueError, RuntimeError) as error:
|
|
print(f'Reconciliation test could not run: {type(error).__name__}', file=sys.stderr)
|
|
sys.exit(1)
|