| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #!/usr/bin/env python3
- """Offline acceptance of the existing Sentinel -> Redis -> OrderBooker code.
- No alternative signal format, TTL, account selector, dispatcher or browser
- lifecycle is implemented here. Tests execute the real framework methods;
- only external boundaries (pool/order API, Redis and browser) are simulated.
- The old live --run entry is deliberately unsupported. Explicit --local-run
- uses the same framework with a private Redis process and real site sessions;
- only order provision/reporting is local. Final booking requires --submit-once
- with --local-run; it then submits automatically within the configured date range.
- """
- from __future__ import annotations
- import argparse
- import contextlib
- import io
- import json
- from pathlib import Path
- import sys
- import unittest
- REPO_ROOT = Path(__file__).resolve().parents[1]
- if str(REPO_ROOT) not in sys.path:
- sys.path.insert(0, str(REPO_ROOT))
- CONTRACT = "existing-framework-offline-v2"
- TEST_NAMES = (
- "test.test_debug_ita_query_book.ExistingFrameworkJointTests",
- "test.test_ita_plugin.ItaSignalReuseTests",
- "test.test_ita_booker_integration",
- "test.test_ita_query_recovery.ExistingSentinelLifecycleTests",
- "test.test_debug_ita_query_book.LocalHarnessTests",
- "test.test_debug_ita_query_book.LocalConfigurationTests",
- "test.test_debug_ita_query_book.LocalFinalTests",
- "test.test_ita_workflow.RealFinalAuditTests",
- "test.test_debug_ita_query_book.LocalFinalCompositionTests",
- )
- def main(argv=None):
- parser = argparse.ArgumentParser(description=__doc__)
- mode = parser.add_mutually_exclusive_group()
- mode.add_argument("--offline", action="store_true", help="Run offline framework acceptance (the default).")
- mode.add_argument("--local-preflight", action="store_true", help="Check local dependencies/config only; no account allocation.")
- mode.add_argument("--local-run", action="store_true", help="One real pool Query -> private Redis -> applicant Book; pre-final unless --submit-once.")
- parser.add_argument("--submit-once", action="store_true", help="With --local-run, automatically create ONE REAL appointment without a confirmation prompt. Never retry an unknown result.")
- parser.add_argument("--group", default="ita.hong_kong")
- parser.add_argument("--config", default="config/config_sentinel.json")
- parser.add_argument("--proxy", default="http://127.0.0.1:6268")
- parser.add_argument("--book-account-file", help="Existing private local account JSON; otherwise prompt for applicant credentials.")
- parser.add_argument("--expected-start-date")
- parser.add_argument("--expected-end-date")
- args = parser.parse_args(argv)
- if args.submit_once and not args.local_run:
- parser.error("--submit-once requires --local-run")
- if args.local_preflight or args.local_run:
- from tools.ita_query_book_local import main_local
- return main_local(args)
- print("ITA_QUERY_BOOK_TOOL=" + CONTRACT, flush=True)
- # Fixtures use synthetic accounts only. Keep incidental fixture output out
- # of the summary; unittest still reports failures through its own stream.
- runner = unittest.TextTestRunner(stream=sys.stderr, verbosity=1)
- with contextlib.redirect_stdout(io.StringIO()):
- suite = unittest.defaultTestLoader.loadTestsFromNames(TEST_NAMES)
- result = runner.run(suite)
- passed = result.wasSuccessful() and result.testsRun > 0 and not result.skipped
- print("ITA_QUERY_BOOK_FRAMEWORK_RESULT=" + json.dumps({
- "contract": CONTRACT, "mode": "offline", "passed": passed,
- "testsRun": result.testsRun, "failures": len(result.failures),
- "errors": len(result.errors), "skipped": len(result.skipped),
- "externalBoundaries": "simulated", "liveAcceptance": False,
- }, sort_keys=True), flush=True)
- return 0 if passed else 1
- if __name__ == "__main__":
- raise SystemExit(main())
|