debug_ita_query_book.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env python3
  2. """Offline acceptance of the existing Sentinel -> Redis -> OrderBooker code.
  3. No alternative signal format, TTL, account selector, dispatcher or browser
  4. lifecycle is implemented here. Tests execute the real framework methods;
  5. only external boundaries (pool/order API, Redis and browser) are simulated.
  6. The old live --run entry is deliberately unsupported. Explicit --local-run
  7. uses the same framework with a private Redis process and real site sessions;
  8. only order provision/reporting is local. Final booking requires --submit-once
  9. with --local-run; it then submits automatically within the configured date range.
  10. """
  11. from __future__ import annotations
  12. import argparse
  13. import contextlib
  14. import io
  15. import json
  16. from pathlib import Path
  17. import sys
  18. import unittest
  19. REPO_ROOT = Path(__file__).resolve().parents[1]
  20. if str(REPO_ROOT) not in sys.path:
  21. sys.path.insert(0, str(REPO_ROOT))
  22. CONTRACT = "existing-framework-offline-v2"
  23. TEST_NAMES = (
  24. "test.test_debug_ita_query_book.ExistingFrameworkJointTests",
  25. "test.test_ita_plugin.ItaSignalReuseTests",
  26. "test.test_ita_booker_integration",
  27. "test.test_ita_query_recovery.ExistingSentinelLifecycleTests",
  28. "test.test_debug_ita_query_book.LocalHarnessTests",
  29. "test.test_debug_ita_query_book.LocalConfigurationTests",
  30. "test.test_debug_ita_query_book.LocalFinalTests",
  31. "test.test_ita_workflow.RealFinalAuditTests",
  32. "test.test_debug_ita_query_book.LocalFinalCompositionTests",
  33. )
  34. def main(argv=None):
  35. parser = argparse.ArgumentParser(description=__doc__)
  36. mode = parser.add_mutually_exclusive_group()
  37. mode.add_argument("--offline", action="store_true", help="Run offline framework acceptance (the default).")
  38. mode.add_argument("--local-preflight", action="store_true", help="Check local dependencies/config only; no account allocation.")
  39. mode.add_argument("--local-run", action="store_true", help="One real pool Query -> private Redis -> applicant Book; pre-final unless --submit-once.")
  40. 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.")
  41. parser.add_argument("--group", default="ita.hong_kong")
  42. parser.add_argument("--config", default="config/config_sentinel.json")
  43. parser.add_argument("--proxy", default="http://127.0.0.1:6268")
  44. parser.add_argument("--book-account-file", help="Existing private local account JSON; otherwise prompt for applicant credentials.")
  45. parser.add_argument("--expected-start-date")
  46. parser.add_argument("--expected-end-date")
  47. args = parser.parse_args(argv)
  48. if args.submit_once and not args.local_run:
  49. parser.error("--submit-once requires --local-run")
  50. if args.local_preflight or args.local_run:
  51. from tools.ita_query_book_local import main_local
  52. return main_local(args)
  53. print("ITA_QUERY_BOOK_TOOL=" + CONTRACT, flush=True)
  54. # Fixtures use synthetic accounts only. Keep incidental fixture output out
  55. # of the summary; unittest still reports failures through its own stream.
  56. runner = unittest.TextTestRunner(stream=sys.stderr, verbosity=1)
  57. with contextlib.redirect_stdout(io.StringIO()):
  58. suite = unittest.defaultTestLoader.loadTestsFromNames(TEST_NAMES)
  59. result = runner.run(suite)
  60. passed = result.wasSuccessful() and result.testsRun > 0 and not result.skipped
  61. print("ITA_QUERY_BOOK_FRAMEWORK_RESULT=" + json.dumps({
  62. "contract": CONTRACT, "mode": "offline", "passed": passed,
  63. "testsRun": result.testsRun, "failures": len(result.failures),
  64. "errors": len(result.errors), "skipped": len(result.skipped),
  65. "externalBoundaries": "simulated", "liveAcceptance": False,
  66. }, sort_keys=True), flush=True)
  67. return 0 if passed else 1
  68. if __name__ == "__main__":
  69. raise SystemExit(main())