bmsdna-devtools 0.58.0__tar.gz → 0.59.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/PKG-INFO +1 -1
  2. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/cli_tools.py +81 -6
  3. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_pr.py +11 -3
  4. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_build.py +15 -2
  5. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/pyproject.toml +1 -1
  6. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/skills/bmsdna-devtools/SKILL.md +1 -2
  7. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_wait_timeout.py +196 -3
  8. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/uv.lock +1 -1
  9. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/.github/workflows/auto-release.yml +0 -0
  10. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/.github/workflows/python-publish.yml +0 -0
  11. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/.github/workflows/python-test.yml +0 -0
  12. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/.gitignore +0 -0
  13. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/.python-version +0 -0
  14. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/README.md +0 -0
  15. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/__init__.py +0 -0
  16. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/_api_dump.py +0 -0
  17. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ado_auth.py +0 -0
  18. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ado_issue.py +0 -0
  19. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/agent_mentions.py +0 -0
  20. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/api_usage.py +0 -0
  21. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/app_service_logs.py +0 -0
  22. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/azure_arm.py +0 -0
  23. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/azure_auth.py +0 -0
  24. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/bdt_config.py +0 -0
  25. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/business_user.py +0 -0
  26. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ci_plan.py +0 -0
  27. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/ci_plan_env.py +0 -0
  28. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/cli.py +0 -0
  29. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/commit.py +0 -0
  30. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/dead_code.py +0 -0
  31. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/__init__.py +0 -0
  32. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/advisories.py +0 -0
  33. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/cli.py +0 -0
  34. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/cooldown.py +0 -0
  35. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/lockfiles.py +0 -0
  36. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/osv.py +0 -0
  37. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/deps/versions.py +0 -0
  38. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/env_config.py +0 -0
  39. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/env_files.py +0 -0
  40. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/find_injection.py +0 -0
  41. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/find_repo.py +0 -0
  42. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_args.py +0 -0
  43. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gh_issue.py +0 -0
  44. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/github_api.py +0 -0
  45. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/gitrepo.py +0 -0
  46. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/injection_frontend.py +0 -0
  47. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/injection_python.py +0 -0
  48. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_do.py +0 -0
  49. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_show.py +0 -0
  50. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/issue_watch.py +0 -0
  51. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint.py +0 -0
  52. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_findings.py +0 -0
  53. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_models.py +0 -0
  54. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_sql.py +0 -0
  55. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_sql_files.py +0 -0
  56. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_tooling.py +0 -0
  57. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/lint_typescript.py +0 -0
  58. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/logs.py +0 -0
  59. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_cancel.py +0 -0
  60. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_choice.py +0 -0
  61. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_create_args.py +0 -0
  62. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_drift.py +0 -0
  63. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_info.py +0 -0
  64. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_issue_link.py +0 -0
  65. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_labels.py +0 -0
  66. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_markdown.py +0 -0
  67. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
  68. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pr_ref.py +0 -0
  69. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/pull.py +0 -0
  70. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/testdb.py +0 -0
  71. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/translate.py +0 -0
  72. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/__init__.py +0 -0
  73. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/cli.py +0 -0
  74. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/pipeline.py +0 -0
  75. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/pricing.py +0 -0
  76. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/report.py +0 -0
  77. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
  78. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
  79. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
  80. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
  81. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
  82. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
  83. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
  84. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/bmsdna/devtools/worktree.py +0 -0
  85. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/justfile +0 -0
  86. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/conftest.py +0 -0
  87. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/fake_github.py +0 -0
  88. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_ado_auth.py +0 -0
  89. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_ado_issue.py +0 -0
  90. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_ado_issue_flow.py +0 -0
  91. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_agent_mentions.py +0 -0
  92. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_api_usage.py +0 -0
  93. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_app_service_logs.py +0 -0
  94. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_azure_arm.py +0 -0
  95. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_bdt_config.py +0 -0
  96. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_business_user.py +0 -0
  97. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_ci_plan.py +0 -0
  98. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_ci_plan_env.py +0 -0
  99. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_cleanup.py +0 -0
  100. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_commit.py +0 -0
  101. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_deps.py +0 -0
  102. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_issue.py +0 -0
  103. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_pr_create.py +0 -0
  104. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_pr_id.py +0 -0
  105. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_pull.py +0 -0
  106. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_tools.py +0 -0
  107. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_cli_version.py +0 -0
  108. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_commit.py +0 -0
  109. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_deps_advisories.py +0 -0
  110. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_deps_cooldown.py +0 -0
  111. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_deps_lockfiles.py +0 -0
  112. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_deps_osv.py +0 -0
  113. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_deps_versions.py +0 -0
  114. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_env_config.py +0 -0
  115. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_env_files.py +0 -0
  116. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_find_injection.py +0 -0
  117. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_find_repo.py +0 -0
  118. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_gh_issue.py +0 -0
  119. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_gh_pr.py +0 -0
  120. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_github_api.py +0 -0
  121. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_gitrepo.py +0 -0
  122. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_issue_do.py +0 -0
  123. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_issue_for_me.py +0 -0
  124. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_issue_show.py +0 -0
  125. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_issue_watch.py +0 -0
  126. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint.py +0 -0
  127. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint_models.py +0 -0
  128. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint_sql.py +0 -0
  129. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint_sql_files.py +0 -0
  130. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint_tooling.py +0 -0
  131. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_lint_typescript.py +0 -0
  132. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_logs.py +0 -0
  133. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_build.py +0 -0
  134. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_build_create_options.py +0 -0
  135. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_build_flow.py +0 -0
  136. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_cancel_build.py +0 -0
  137. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_choice.py +0 -0
  138. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_create_args.py +0 -0
  139. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_description_not_truncated.py +0 -0
  140. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_drift.py +0 -0
  141. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_info.py +0 -0
  142. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_issue_link.py +0 -0
  143. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_labels.py +0 -0
  144. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_markdown.py +0 -0
  145. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pr_merge_defaults.py +0 -0
  146. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_pull.py +0 -0
  147. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_testdb.py +0 -0
  148. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_translate.py +0 -0
  149. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_usage.py +0 -0
  150. {bmsdna_devtools-0.58.0 → bmsdna_devtools-0.59.0}/tests/test_worktree_clean.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: bmsdna-devtools
3
- Version: 0.58.0
3
+ Version: 0.59.0
4
4
  Summary: Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects
5
5
  Requires-Python: >=3.14
6
6
  Requires-Dist: azure-identity>=1.19.0
@@ -13,11 +13,13 @@ import math
13
13
  import os
14
14
  import re
15
15
  import shutil
16
+ import signal
16
17
  import subprocess
17
18
  import sys
18
19
  import time
19
20
  from collections.abc import Callable
20
21
  from dataclasses import dataclass
22
+ from types import FrameType, TracebackType
21
23
  from typing import NoReturn
22
24
 
23
25
  PSQL_INSTALL_HINT = "Install the PostgreSQL client tools (psql): https://www.postgresql.org/download/"
@@ -86,30 +88,100 @@ class PollHeartbeat:
86
88
  self._last_print = now
87
89
 
88
90
 
91
+ # Windows: how long `WaitDeadline.sleep` sleeps at a time, so a stop signal is answered within about that long.
92
+ WINDOWS_SLEEP_SLICE_SECS = 1.0
93
+
94
+ # What asks a `--wait` loop to stop and report: SIGTERM (what `timeout`, `kill`, `docker stop` and most agent harnesses
95
+ # send first) and, on Windows, where SIGTERM is never delivered by the OS, Ctrl+Break. Windows lacks the rest.
96
+ _STOP_SIGNALS = tuple(sig for sig in (getattr(signal, "SIGTERM", None), getattr(signal, "SIGBREAK", None)) if sig is not None)
97
+
98
+
99
+ _SignalHandler = Callable[[int, FrameType | None], object] | int | None # what `signal.getsignal` returns
100
+
101
+
102
+ class _WaitStopped(Exception):
103
+ """Raised by the stop-signal handler inside `WaitDeadline.sleep` to cut the sleep short."""
104
+
105
+
89
106
  class WaitDeadline:
90
107
  """Optional overall time limit of a `--wait` poll loop (`timeout_secs` of 0 / None = wait forever).
91
108
 
92
109
  Exists because a caller often can't wait as long as CI takes: an agent's shell tool kills a command
93
110
  after a few minutes and throws its output away. Giving up on our own terms lets us report where things
94
111
  stand and exit with `EXIT_WAIT_TIMEOUT` so the caller knows to re-run.
112
+
113
+ With `stop_on_signal` (use it as a context manager, which puts the previous signal handlers back) a stop signal
114
+ does the same thing at once: `expired()` turns true and a running `sleep` ends, so the loop reports and exits
115
+ on its own instead of dying silently. The handler only sets a flag, and a second signal terminates as usual --
116
+ a loop stuck in a slow request can still be killed.
95
117
  """
96
118
 
97
- def __init__(self, timeout_secs: float | None) -> None:
119
+ def __init__(self, timeout_secs: float | None, *, stop_on_signal: bool = False) -> None:
98
120
  self.timeout_secs = timeout_secs or 0.0
99
121
  self._end = time.monotonic() + self.timeout_secs if self.timeout_secs else None
122
+ self.stopped_by_signal = False
123
+ self._sleeping = False
124
+ self._previous_handlers: dict[int, _SignalHandler] = {}
125
+ if stop_on_signal:
126
+ for sig in _STOP_SIGNALS:
127
+ try:
128
+ self._previous_handlers[sig] = signal.signal(sig, self._on_stop_signal)
129
+ except (ValueError, OSError): # not the main thread (ValueError), or the OS refuses this signal
130
+ pass
131
+
132
+ def __enter__(self) -> WaitDeadline:
133
+ return self
134
+
135
+ def __exit__(self, exc_type: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> None:
136
+ self._restore_handlers()
137
+
138
+ def _restore_handlers(self) -> None:
139
+ for sig, previous in self._previous_handlers.items():
140
+ try:
141
+ signal.signal(sig, previous if previous is not None else signal.SIG_DFL)
142
+ except (ValueError, OSError):
143
+ pass
144
+ self._previous_handlers.clear()
145
+
146
+ def _on_stop_signal(self, signum: int, frame: FrameType | None) -> None:
147
+ self.stopped_by_signal = True
148
+ self._restore_handlers()
149
+ if self._sleeping:
150
+ raise _WaitStopped
100
151
 
101
152
  def expired(self) -> bool:
102
- return self._end is not None and time.monotonic() >= self._end
153
+ return self.stopped_by_signal or (self._end is not None and time.monotonic() >= self._end)
103
154
 
104
155
  def sleep(self, secs: float) -> None:
105
- """`time.sleep(secs)`, cut short so the loop wakes up right at the deadline."""
106
- time.sleep(secs if self._end is None else max(0.0, min(secs, self._end - time.monotonic())))
156
+ """`time.sleep(secs)`, cut short so the loop wakes up right at the deadline (or when a stop signal arrives).
157
+ `_sleeping` goes up before the signal check, so a signal landing anywhere in between still ends the sleep;
158
+ the outer `try` also covers one landing in the `finally` that puts it back down."""
159
+ try:
160
+ self._sleeping = True
161
+ try:
162
+ if not self.stopped_by_signal:
163
+ self._sleep(secs if self._end is None else max(0.0, min(secs, self._end - time.monotonic())))
164
+ finally:
165
+ self._sleeping = False
166
+ except _WaitStopped:
167
+ pass
168
+
169
+ def _sleep(self, secs: float) -> None:
170
+ if sys.platform != "win32":
171
+ time.sleep(secs)
172
+ return
173
+ # Windows only runs a signal handler once `time.sleep` returns (it is woken by Ctrl+C alone): in slices, so
174
+ # a Ctrl+Break is answered within a second instead of after the full sleep
175
+ end = time.monotonic() + secs
176
+ while not self.stopped_by_signal and (left := end - time.monotonic()) > 0:
177
+ time.sleep(min(left, WINDOWS_SLEEP_SLICE_SECS))
107
178
 
108
179
 
109
180
  def status_rerun_cmd(pr_id: int | None, timeout_secs: float) -> str:
110
181
  """The command that keeps waiting where a timed-out `pr status --wait` stopped. Pins `--pr-id` to the PR that
111
182
  was being watched, so re-running can't resolve to a different PR (e.g. another branch checked out since)."""
112
- return f"bdt pr status --pr-id {pr_id} --wait --timeout {timeout_secs:g}" if pr_id else f"bdt pr status --wait --timeout {timeout_secs:g}"
183
+ cmd = f"bdt pr status --pr-id {pr_id} --wait" if pr_id else "bdt pr status --wait"
184
+ return f"{cmd} --timeout {timeout_secs:g}" if timeout_secs else cmd
113
185
 
114
186
 
115
187
  def exit_wait_timeout(msg: str, print_details: Callable[[], object], deadline: WaitDeadline, rerun_cmd: str) -> NoReturn:
@@ -118,7 +190,10 @@ def exit_wait_timeout(msg: str, print_details: Callable[[], object], deadline: W
118
190
  print(msg)
119
191
  print("\nDetails:")
120
192
  print_details()
121
- print(f"\nStill running after {deadline.timeout_secs:g} s. Re-run `{rerun_cmd}` to keep waiting.")
193
+ if deadline.stopped_by_signal:
194
+ print(f"\nTerminated while still running. Re-run `{rerun_cmd}` to keep waiting.")
195
+ else:
196
+ print(f"\nStill running after {deadline.timeout_secs:g} s. Re-run `{rerun_cmd}` to keep waiting.")
122
197
  sys.exit(EXIT_WAIT_TIMEOUT)
123
198
 
124
199
 
@@ -550,9 +550,13 @@ def exit_needs_approval(msg: str, item_lines: list[str], rerun_cmd: str) -> None
550
550
 
551
551
  def run(gh: GitHubClient, wait: bool, pr_id: int | None = None, timeout: float = 0) -> None:
552
552
  """`timeout` (seconds, only with `wait`): stop polling after that long and exit `EXIT_WAIT_TIMEOUT`
553
- with the current state; 0 = wait until every check is done."""
553
+ with the current state; 0 = wait until every check is done. A SIGTERM while waiting does the same at once."""
554
+ with WaitDeadline(timeout, stop_on_signal=wait) as deadline:
555
+ _status(gh, wait, pr_id, timeout, deadline)
556
+
557
+
558
+ def _status(gh: GitHubClient, wait: bool, pr_id: int | None, timeout: float, deadline: WaitDeadline) -> None:
554
559
  heartbeat = PollHeartbeat()
555
- deadline = WaitDeadline(timeout)
556
560
  draft_notice_shown = False
557
561
  while True:
558
562
  pr = get_pr(gh, pr_id)
@@ -562,7 +566,11 @@ def run(gh: GitHubClient, wait: bool, pr_id: int | None = None, timeout: float =
562
566
  # isn't safe (could spin forever if it never resolves) — only retry
563
567
  # when the caller already opted into waiting.
564
568
  if pr.get("mergeable") == UNKNOWN_MERGEABLE and wait:
565
- time.sleep(3)
569
+ if deadline.expired():
570
+ exit_wait_timeout(
571
+ f"PR #{pr.get('number')}: {pr.get('title', '?')} | mergeability not computed yet", lambda: None, deadline, status_rerun_cmd(pr.get("number"), timeout)
572
+ )
573
+ deadline.sleep(3)
566
574
  continue
567
575
 
568
576
  conflict = merge_conflict_message(pr)
@@ -1216,7 +1216,21 @@ def run(
1216
1216
  timeout: float = 0,
1217
1217
  ) -> None:
1218
1218
  """`timeout` (seconds, only with `wait`): stop polling after that long and exit `EXIT_WAIT_TIMEOUT`
1219
- with the current state; 0 = wait until every pipeline is done."""
1219
+ with the current state; 0 = wait until every pipeline is done. A SIGTERM while waiting does the same at once."""
1220
+ with WaitDeadline(timeout, stop_on_signal=wait) as deadline:
1221
+ _status(remote, pat, target_branch, wait, source_branch, pr_id, timeout, deadline)
1222
+
1223
+
1224
+ def _status(
1225
+ remote: AdoRemote,
1226
+ pat: str | None,
1227
+ target_branch: str | None,
1228
+ wait: bool,
1229
+ source_branch: str | None,
1230
+ pr_id: int | None,
1231
+ timeout: float,
1232
+ deadline: WaitDeadline,
1233
+ ) -> None:
1220
1234
  session = ado_session(pat)
1221
1235
 
1222
1236
  def fetch_pr() -> dict:
@@ -1254,7 +1268,6 @@ def run(
1254
1268
  drift_notice_shown: str | None = None
1255
1269
  policy_checked = False
1256
1270
  heartbeat = PollHeartbeat()
1257
- deadline = WaitDeadline(timeout)
1258
1271
 
1259
1272
  def time_out(msg: str, builds: list, pr_number: int) -> NoReturn:
1260
1273
  exit_wait_timeout(msg, lambda: [print_build(session, remote, b) for b in builds], deadline, status_rerun_cmd(pr_number, timeout))
@@ -10,7 +10,7 @@ packages = ["bmsdna"]
10
10
 
11
11
  [project]
12
12
  name = "bmsdna-devtools"
13
- version = "0.58.0"
13
+ version = "0.59.0"
14
14
  description = "Shared Azure DevOps / GitHub / git / Azure Monitor developer tooling for BMS projects"
15
15
  readme = "README.md"
16
16
  requires-python = ">=3.14" # pgdevkit>=0.7.1 requires 3.14; was >=3.11 before adding it as a dependency
@@ -54,8 +54,7 @@ only informational.
54
54
 
55
55
  Where your shell tool has a time limit shorter than CI (it kills the command and drops its output), run
56
56
  `bdt pr status --wait --timeout 540` (seconds, below the limit): after that long it prints the current state and
57
- exits 4 — just run the same command again to keep waiting. (Wrapping it as `timeout 590 bdt pr status --wait` works
58
- too: `bdt` sees the enclosing `timeout` and stops 30 s before it.) Exit 3 = a stage needs a human's approval.
57
+ exits 4 — just run the same command again to keep waiting. Exit 3 = a stage needs a human's approval.
59
58
 
60
59
  `pr status`, `info`, `retry`, `publish`, `update`, `comment` (and `issue take`
61
60
  without a number) find the PR opened from the current branch into **any**
@@ -5,8 +5,10 @@ from __future__ import annotations
5
5
 
6
6
  import re
7
7
  import shutil
8
+ import signal
8
9
  import subprocess
9
10
  import sys
11
+ import threading
10
12
  import time
11
13
  from unittest.mock import MagicMock
12
14
 
@@ -14,7 +16,7 @@ import pytest
14
16
  from typer.testing import CliRunner
15
17
 
16
18
  from bmsdna.devtools.cli import app
17
- from bmsdna.devtools.cli_tools import ENCLOSING_TIMEOUT_MARGIN_SECS, EXIT_WAIT_TIMEOUT, WaitDeadline, enclosing_timeout_remaining, limit_by_enclosing_timeout, parse_timeout_command
19
+ from bmsdna.devtools.cli_tools import ENCLOSING_TIMEOUT_MARGIN_SECS, EXIT_WAIT_TIMEOUT, WaitDeadline, enclosing_timeout_remaining, limit_by_enclosing_timeout, parse_timeout_command, status_rerun_cmd
18
20
  from bmsdna.devtools.gh_pr import run as gh_run
19
21
  from bmsdna.devtools.gitrepo import AdoRemote, GitHubRemote
20
22
  from bmsdna.devtools.issue_watch import EXIT_TIMEOUT
@@ -297,10 +299,201 @@ def test_pr_status_passes_the_limited_timeout_on(monkeypatch, args: list[str], e
297
299
 
298
300
 
299
301
  def test_a_real_timeout_process_is_found_above_us() -> None:
300
- if shutil.which("timeout") is None or shutil.which("ps") is None:
301
- pytest.skip("needs coreutils timeout and ps")
302
+ if sys.platform == "win32" or shutil.which("timeout") is None or shutil.which("ps") is None:
303
+ pytest.skip("needs coreutils timeout and ps") # Windows' own timeout.exe is a different tool
302
304
  code = "from bmsdna.devtools.cli_tools import enclosing_timeout_remaining as r; print(r())"
303
305
  out = subprocess.run(["timeout", "600", sys.executable, "-c", code], capture_output=True, encoding="utf-8", check=True).stdout
304
306
 
305
307
  assert out.strip() != "None"
306
308
  assert 0 <= float(out) <= 600 # less if the test run itself is under a shorter `timeout`
309
+
310
+
311
+ def test_no_ps_means_no_enclosing_timeout(monkeypatch) -> None:
312
+ """Windows has no `ps`: the detection quietly finds nothing instead of failing the command."""
313
+
314
+ def no_ps(*args, **kwargs):
315
+ raise FileNotFoundError("ps")
316
+
317
+ monkeypatch.setattr("subprocess.run", no_ps)
318
+
319
+ assert enclosing_timeout_remaining() is None
320
+
321
+
322
+ def test_rerun_command_without_a_timeout() -> None:
323
+ assert status_rerun_cmd(42, 0) == "bdt pr status --pr-id 42 --wait"
324
+ assert status_rerun_cmd(None, 0) == "bdt pr status --wait"
325
+ assert status_rerun_cmd(42, 70) == "bdt pr status --pr-id 42 --wait --timeout 70"
326
+
327
+
328
+ # -- a stop signal (SIGTERM from `timeout`, `kill`, an agent harness) ---------------
329
+ # `signal.raise_signal` rather than `os.kill`: on Windows only the former runs the handler (the latter terminates us).
330
+
331
+
332
+ STOP = signal.SIGTERM
333
+
334
+
335
+ @pytest.fixture
336
+ def sigterm_during_sleep(monkeypatch) -> list[float]:
337
+ """`time.sleep` that gets a SIGTERM instead of sleeping, once; records what it was asked for."""
338
+ asked: list[float] = []
339
+
340
+ def sleep(secs: float) -> None:
341
+ asked.append(secs)
342
+ if len(asked) == 1:
343
+ signal.raise_signal(STOP)
344
+ pytest.fail("kept sleeping after SIGTERM")
345
+
346
+ monkeypatch.setattr(time, "sleep", sleep)
347
+ return asked
348
+
349
+
350
+ def test_stop_signal_ends_the_sleep_and_expires_the_deadline(sigterm_during_sleep) -> None:
351
+ before = signal.getsignal(STOP)
352
+ with WaitDeadline(0, stop_on_signal=True) as deadline:
353
+ assert signal.getsignal(STOP) != before
354
+ assert not deadline.expired()
355
+
356
+ deadline.sleep(30)
357
+
358
+ assert deadline.expired() and deadline.stopped_by_signal
359
+ assert signal.getsignal(STOP) == before # a second signal terminates as usual
360
+ assert sigterm_during_sleep == [30]
361
+
362
+
363
+ def test_stop_signal_outside_of_a_sleep_only_sets_the_flag(monkeypatch) -> None:
364
+ slept: list[float] = []
365
+ monkeypatch.setattr(time, "sleep", slept.append)
366
+ with WaitDeadline(0, stop_on_signal=True) as deadline:
367
+ signal.raise_signal(STOP) # e.g. in the middle of a request
368
+
369
+ assert deadline.expired()
370
+ deadline.sleep(30)
371
+
372
+ assert slept == []
373
+
374
+
375
+ def test_previous_handler_is_put_back_on_exit() -> None:
376
+ before = signal.getsignal(STOP)
377
+ with WaitDeadline(0, stop_on_signal=True):
378
+ pass
379
+
380
+ assert signal.getsignal(STOP) == before
381
+
382
+
383
+ def test_no_handler_without_stop_on_signal() -> None:
384
+ before = signal.getsignal(STOP)
385
+ with WaitDeadline(0):
386
+ assert signal.getsignal(STOP) == before
387
+
388
+
389
+ def test_stop_on_signal_off_the_main_thread_is_a_no_op() -> None:
390
+ """`signal.signal` raises ValueError outside the main thread."""
391
+ errors: list[BaseException] = []
392
+
393
+ def target() -> None:
394
+ try:
395
+ with WaitDeadline(0, stop_on_signal=True) as deadline:
396
+ assert not deadline.expired()
397
+ except BaseException as e:
398
+ errors.append(e)
399
+
400
+ t = threading.Thread(target=target)
401
+ t.start()
402
+ t.join()
403
+
404
+ assert errors == []
405
+
406
+
407
+ def test_stop_on_signal_survives_an_os_that_refuses_the_handler(monkeypatch) -> None:
408
+ def refuse(*args, **kwargs):
409
+ raise OSError("invalid argument")
410
+
411
+ monkeypatch.setattr(signal, "signal", refuse)
412
+ with WaitDeadline(0, stop_on_signal=True) as deadline:
413
+ assert not deadline.expired()
414
+
415
+
416
+ def test_gh_wait_reports_and_exits_4_on_sigterm(monkeypatch, sigterm_during_sleep, capsys) -> None:
417
+ monkeypatch.setattr("bmsdna.devtools.gh_pr.get_pr", lambda gh, pr_id=None: _gh_pr([PASSED, PENDING]))
418
+
419
+ with pytest.raises(SystemExit) as exc:
420
+ gh_run("gh", wait=True)
421
+
422
+ out = capsys.readouterr().out
423
+ assert exc.value.code == EXIT_WAIT_TIMEOUT
424
+ assert "[✓ PASS] CI / lint" in out and "[… PENDING] CI / build" in out
425
+ assert out.rstrip().endswith("Terminated while still running. Re-run `bdt pr status --pr-id 42 --wait` to keep waiting.")
426
+
427
+
428
+ def test_ado_wait_reports_and_exits_4_on_sigterm(monkeypatch, sigterm_during_sleep, capsys) -> None:
429
+ _ado_env(monkeypatch, [{"id": 200, "status": "inProgress", "result": None, "definition": {"id": 2, "name": "ci"}}])
430
+
431
+ with pytest.raises(SystemExit) as exc:
432
+ ado_run(AdoRemote("myorg", "MyProj", "myrepo"), None, "main", wait=True, source_branch="feature-x")
433
+
434
+ out = capsys.readouterr().out
435
+ assert exc.value.code == EXIT_WAIT_TIMEOUT
436
+ assert "build #200 inProgress" in out
437
+ assert out.rstrip().endswith("Terminated while still running. Re-run `bdt pr status --pr-id 42 --wait` to keep waiting.")
438
+
439
+
440
+ def test_status_without_wait_leaves_sigterm_alone(monkeypatch) -> None:
441
+ """Nothing would ever look at the flag there, so a SIGTERM must keep killing the command."""
442
+ seen: list[object] = []
443
+ monkeypatch.setattr("bmsdna.devtools.gh_pr.get_pr", lambda gh, pr_id=None: seen.append(signal.getsignal(STOP)) or _gh_pr([PASSED]))
444
+ monkeypatch.setattr("bmsdna.devtools.gh_pr.deploy_run_hint", lambda gh, base: None)
445
+ before = signal.getsignal(STOP)
446
+
447
+ gh_run("gh", wait=False)
448
+
449
+ assert seen == [before]
450
+
451
+
452
+ def test_gh_wait_stops_on_sigterm_while_mergeability_is_unknown(monkeypatch, sigterm_during_sleep, capsys) -> None:
453
+ monkeypatch.setattr("bmsdna.devtools.gh_pr.get_pr", lambda gh, pr_id=None: {**_gh_pr([PENDING]), "mergeable": "UNKNOWN"})
454
+
455
+ with pytest.raises(SystemExit) as exc:
456
+ gh_run("gh", wait=True)
457
+
458
+ out = capsys.readouterr().out
459
+ assert exc.value.code == EXIT_WAIT_TIMEOUT
460
+ assert sigterm_during_sleep == [3]
461
+ assert "mergeability not computed yet" in out
462
+ assert out.rstrip().endswith("Terminated while still running. Re-run `bdt pr status --pr-id 42 --wait` to keep waiting.")
463
+
464
+
465
+ def test_gh_wait_timeout_applies_while_mergeability_is_unknown(monkeypatch, sleeps, capsys) -> None:
466
+ monkeypatch.setattr("bmsdna.devtools.gh_pr.get_pr", lambda gh, pr_id=None: {**_gh_pr([PENDING]), "mergeable": "UNKNOWN"})
467
+
468
+ with pytest.raises(SystemExit) as exc:
469
+ gh_run("gh", wait=True, timeout=10)
470
+
471
+ assert exc.value.code == EXIT_WAIT_TIMEOUT
472
+ assert sleeps == [3, 3, 3, 1]
473
+
474
+
475
+ def test_windows_sleeps_in_slices_so_a_signal_is_answered_promptly(monkeypatch) -> None:
476
+ now = [0.0]
477
+ slept: list[float] = []
478
+ monkeypatch.setattr(sys, "platform", "win32")
479
+ monkeypatch.setattr(time, "monotonic", lambda: now[0])
480
+ monkeypatch.setattr(time, "sleep", lambda secs: (slept.append(secs), now.__setitem__(0, now[0] + secs))[0])
481
+
482
+ WaitDeadline(0).sleep(2.5)
483
+
484
+ assert slept == [1.0, 1.0, 0.5]
485
+
486
+
487
+ def test_windows_stops_slicing_once_signalled(monkeypatch) -> None:
488
+ slept: list[float] = []
489
+ monkeypatch.setattr(sys, "platform", "win32")
490
+
491
+ def sleep(secs: float) -> None:
492
+ slept.append(secs)
493
+ signal.raise_signal(STOP) # the handler runs once the sleep returns
494
+
495
+ monkeypatch.setattr(time, "sleep", sleep)
496
+ with WaitDeadline(0, stop_on_signal=True) as deadline:
497
+ deadline.sleep(30)
498
+
499
+ assert slept == [1.0]
@@ -51,7 +51,7 @@ wheels = [
51
51
 
52
52
  [[package]]
53
53
  name = "bmsdna-devtools"
54
- version = "0.58.0"
54
+ version = "0.59.0"
55
55
  source = { editable = "." }
56
56
  dependencies = [
57
57
  { name = "azure-identity" },