bmsdna-devtools 0.57.2__tar.gz → 0.58.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.57.2 → bmsdna_devtools-0.58.0}/PKG-INFO +1 -1
  2. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/cli.py +5 -2
  3. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/cli_tools.py +106 -0
  4. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/pyproject.toml +1 -1
  5. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/skills/bmsdna-devtools/SKILL.md +2 -1
  6. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_wait_timeout.py +120 -1
  7. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/uv.lock +1 -1
  8. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/.github/workflows/auto-release.yml +0 -0
  9. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/.github/workflows/python-publish.yml +0 -0
  10. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/.github/workflows/python-test.yml +0 -0
  11. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/.gitignore +0 -0
  12. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/.python-version +0 -0
  13. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/README.md +0 -0
  14. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/__init__.py +0 -0
  15. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/_api_dump.py +0 -0
  16. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/ado_auth.py +0 -0
  17. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/ado_issue.py +0 -0
  18. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/agent_mentions.py +0 -0
  19. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/api_usage.py +0 -0
  20. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/app_service_logs.py +0 -0
  21. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/azure_arm.py +0 -0
  22. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/azure_auth.py +0 -0
  23. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/bdt_config.py +0 -0
  24. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/business_user.py +0 -0
  25. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/ci_plan.py +0 -0
  26. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/ci_plan_env.py +0 -0
  27. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/commit.py +0 -0
  28. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/dead_code.py +0 -0
  29. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/__init__.py +0 -0
  30. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/advisories.py +0 -0
  31. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/cli.py +0 -0
  32. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/cooldown.py +0 -0
  33. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/lockfiles.py +0 -0
  34. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/osv.py +0 -0
  35. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/deps/versions.py +0 -0
  36. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/env_config.py +0 -0
  37. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/env_files.py +0 -0
  38. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/find_injection.py +0 -0
  39. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/find_repo.py +0 -0
  40. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/gh_args.py +0 -0
  41. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/gh_issue.py +0 -0
  42. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/gh_pr.py +0 -0
  43. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/github_api.py +0 -0
  44. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/gitrepo.py +0 -0
  45. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/injection_frontend.py +0 -0
  46. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/injection_python.py +0 -0
  47. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/issue_do.py +0 -0
  48. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/issue_show.py +0 -0
  49. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/issue_watch.py +0 -0
  50. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint.py +0 -0
  51. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_findings.py +0 -0
  52. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_models.py +0 -0
  53. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_sql.py +0 -0
  54. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_sql_files.py +0 -0
  55. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_tooling.py +0 -0
  56. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/lint_typescript.py +0 -0
  57. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/logs.py +0 -0
  58. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_build.py +0 -0
  59. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_cancel.py +0 -0
  60. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_choice.py +0 -0
  61. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_create_args.py +0 -0
  62. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_drift.py +0 -0
  63. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_info.py +0 -0
  64. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_issue_link.py +0 -0
  65. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_labels.py +0 -0
  66. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_markdown.py +0 -0
  67. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_merge_defaults.py +0 -0
  68. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pr_ref.py +0 -0
  69. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/pull.py +0 -0
  70. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/testdb.py +0 -0
  71. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/translate.py +0 -0
  72. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/__init__.py +0 -0
  73. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/cli.py +0 -0
  74. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/pipeline.py +0 -0
  75. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/pricing.py +0 -0
  76. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/report.py +0 -0
  77. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/00_schema.sql +0 -0
  78. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/01_ingest_claude.sql +0 -0
  79. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/01_ingest_codex.sql +0 -0
  80. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/02_messages.sql +0 -0
  81. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/03_markers.sql +0 -0
  82. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/04_facts.sql +0 -0
  83. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/usage/sql/05_views.sql +0 -0
  84. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/bmsdna/devtools/worktree.py +0 -0
  85. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/justfile +0 -0
  86. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/conftest.py +0 -0
  87. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/fake_github.py +0 -0
  88. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_ado_auth.py +0 -0
  89. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_ado_issue.py +0 -0
  90. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_ado_issue_flow.py +0 -0
  91. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_agent_mentions.py +0 -0
  92. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_api_usage.py +0 -0
  93. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_app_service_logs.py +0 -0
  94. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_azure_arm.py +0 -0
  95. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_bdt_config.py +0 -0
  96. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_business_user.py +0 -0
  97. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_ci_plan.py +0 -0
  98. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_ci_plan_env.py +0 -0
  99. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_cleanup.py +0 -0
  100. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_commit.py +0 -0
  101. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_deps.py +0 -0
  102. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_issue.py +0 -0
  103. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_pr_create.py +0 -0
  104. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_pr_id.py +0 -0
  105. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_pull.py +0 -0
  106. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_tools.py +0 -0
  107. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_cli_version.py +0 -0
  108. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_commit.py +0 -0
  109. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_deps_advisories.py +0 -0
  110. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_deps_cooldown.py +0 -0
  111. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_deps_lockfiles.py +0 -0
  112. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_deps_osv.py +0 -0
  113. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_deps_versions.py +0 -0
  114. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_env_config.py +0 -0
  115. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_env_files.py +0 -0
  116. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_find_injection.py +0 -0
  117. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_find_repo.py +0 -0
  118. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_gh_issue.py +0 -0
  119. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_gh_pr.py +0 -0
  120. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_github_api.py +0 -0
  121. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_gitrepo.py +0 -0
  122. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_issue_do.py +0 -0
  123. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_issue_for_me.py +0 -0
  124. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_issue_show.py +0 -0
  125. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_issue_watch.py +0 -0
  126. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint.py +0 -0
  127. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint_models.py +0 -0
  128. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint_sql.py +0 -0
  129. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint_sql_files.py +0 -0
  130. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint_tooling.py +0 -0
  131. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_lint_typescript.py +0 -0
  132. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_logs.py +0 -0
  133. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_build.py +0 -0
  134. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_build_create_options.py +0 -0
  135. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_build_flow.py +0 -0
  136. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_cancel_build.py +0 -0
  137. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_choice.py +0 -0
  138. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_create_args.py +0 -0
  139. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_description_not_truncated.py +0 -0
  140. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_drift.py +0 -0
  141. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_info.py +0 -0
  142. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_issue_link.py +0 -0
  143. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_labels.py +0 -0
  144. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_markdown.py +0 -0
  145. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pr_merge_defaults.py +0 -0
  146. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_pull.py +0 -0
  147. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_testdb.py +0 -0
  148. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_translate.py +0 -0
  149. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.0}/tests/test_usage.py +0 -0
  150. {bmsdna_devtools-0.57.2 → bmsdna_devtools-0.58.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.57.2
3
+ Version: 0.58.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
@@ -38,7 +38,7 @@ from . import translate as translate_mod
38
38
  from . import pr_build, pr_cancel, pr_info as pr_info_mod, pr_issue_link, pr_merge_defaults, pr_ref, pr_labels, pull as pull_mod, worktree as worktree_mod
39
39
  from .ado_auth import AdoAuthError, ado_session, auth_header
40
40
  from .bdt_config import find_pyproject, load_bdt_table
41
- from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, require_gh
41
+ from .cli_tools import CLI_TIMEOUT_SECS, EXIT_WAIT_TIMEOUT, detect_agent_session, limit_by_enclosing_timeout, require_gh
42
42
  from .github_api import GitHubClient
43
43
  from .pr_create_args import PrCreateArgsError, extract_labels, parse_pr_create_args, resolve_body, unsupported_notes
44
44
  from .deps.cli import deps_app
@@ -575,7 +575,8 @@ def pr_status(
575
575
  "--timeout",
576
576
  help="With --wait: stop after this many seconds if the checks are still running, print their current state and exit "
577
577
  f"{EXIT_WAIT_TIMEOUT} (0 = wait forever, the default). Use it where the caller's own time limit is shorter than CI, "
578
- "e.g. an agent's shell tool, then re-run the same command to keep waiting",
578
+ "e.g. an agent's shell tool, then re-run the same command to keep waiting. Under an enclosing `timeout N` (as in "
579
+ "`timeout 590 bdt pr status --wait`) it is cut to end shortly before that kills us, even without --timeout",
579
580
  ),
580
581
  pr_id: int | None = typer.Option(None, "--pr-id", help=_PR_ID_HELP),
581
582
  pat: str | None = typer.Option(None, "--pat", envvar=["AZURE_DEVOPS_EXT_PAT", "AZURE_DEVOPS_PAT"], help="Azure DevOps PAT (else uses DefaultAzureCredential, e.g. your `az login`)"),
@@ -586,6 +587,8 @@ def pr_status(
586
587
  if timeout and not wait:
587
588
  raise typer.BadParameter("--timeout only works together with --wait", param_hint="--timeout")
588
589
  _check_poll_options(None, timeout)
590
+ if wait:
591
+ timeout = limit_by_enclosing_timeout(timeout)
589
592
  remote = current_remote()
590
593
  if isinstance(remote, GitHubRemote):
591
594
  gh = require_gh()
@@ -9,8 +9,11 @@ concerns for arguments that come from user input, e.g. PR titles).
9
9
 
10
10
  from __future__ import annotations
11
11
 
12
+ import math
12
13
  import os
14
+ import re
13
15
  import shutil
16
+ import subprocess
14
17
  import sys
15
18
  import time
16
19
  from collections.abc import Callable
@@ -39,6 +42,11 @@ EXIT_WAIT_TIMEOUT = 4
39
42
  # not to spam a captured log.
40
43
  POLL_HEARTBEAT_SECS = 600.0
41
44
 
45
+ # How long before an enclosing `timeout N bdt pr status --wait` would kill us the wait loop gives up on its own
46
+ # (see `limit_by_enclosing_timeout`): enough for a poll that is in flight (HTTP_TIMEOUT_SECS) plus printing the
47
+ # per-build details of the final status.
48
+ ENCLOSING_TIMEOUT_MARGIN_SECS = 30.0
49
+
42
50
  # Bounds a single call to an external CLI (`gh`/`az`/`git`) or a single Azure DevOps REST
43
51
  # request. Without a timeout, a stalled network call or the CLI blocking on an interactive
44
52
  # prompt (e.g. an expired `az`/`gh` login) could hang a command -- most importantly a
@@ -114,6 +122,104 @@ def exit_wait_timeout(msg: str, print_details: Callable[[], object], deadline: W
114
122
  sys.exit(EXIT_WAIT_TIMEOUT)
115
123
 
116
124
 
125
+ _TIMEOUT_COMMANDS = ("timeout", "gtimeout") # GNU coreutils; macOS has it as `gtimeout` unless aliased
126
+ _TIMEOUT_LONG_OPTIONS_WITH_VALUE = ("--kill-after", "--signal")
127
+ _DURATION_UNITS = {"": 1, "s": 1, "m": 60, "h": 3600, "d": 86400}
128
+ _ETIME_RE = re.compile(r"^(?:(?:(\d+)-)?(\d+):)?(\d+):(\d+)$") # [[dd-]hh:]mm:ss, as printed by `ps -o etime`
129
+ _MAX_ANCESTORS = 8
130
+
131
+
132
+ def parse_timeout_command(args: list[str]) -> float | None:
133
+ """The duration (seconds) of a `timeout [OPTION]... DURATION COMMAND...` command line, or None if `args` isn't
134
+ one, the duration is 0 / infinite (= no limit) or the options can't be read with confidence: not detecting a
135
+ limit is harmless, a wrong one would cut the wait short."""
136
+ if not args or os.path.basename(args[0]) not in _TIMEOUT_COMMANDS:
137
+ return None
138
+ rest = iter(args[1:])
139
+ for arg in rest:
140
+ if arg == "--":
141
+ arg = next(rest, "")
142
+ elif arg.startswith("--"):
143
+ # getopt accepts any unambiguous prefix of a long option (`--kill 5`)
144
+ if "=" not in arg and len(arg) > 2 and any(opt.startswith(arg) for opt in _TIMEOUT_LONG_OPTIONS_WITH_VALUE):
145
+ next(rest, None)
146
+ continue
147
+ elif arg.startswith("-") and arg != "-":
148
+ for pos, flag in enumerate(arg[1:], start=1):
149
+ if flag in "ks": # the value is the rest of the cluster (`-k5`), else the next argument
150
+ if pos == len(arg) - 1:
151
+ next(rest, None)
152
+ break
153
+ if flag not in "fpv":
154
+ return None
155
+ continue
156
+ return _parse_duration(arg)
157
+ return None
158
+
159
+
160
+ def _parse_duration(text: str) -> float | None:
161
+ m = re.fullmatch(r"(.+?)([smhd]?)", text)
162
+ try:
163
+ seconds = float(m.group(1)) * _DURATION_UNITS[m.group(2)] if m else 0.0
164
+ except ValueError:
165
+ return None
166
+ return seconds if math.isfinite(seconds) and seconds > 0 else None
167
+
168
+
169
+ def _parse_etime(text: str) -> float | None:
170
+ m = _ETIME_RE.match(text.strip())
171
+ if not m:
172
+ return None
173
+ days, hours, minutes, seconds = (int(g or 0) for g in m.groups())
174
+ return float(((days * 24 + hours) * 60 + minutes) * 60 + seconds)
175
+
176
+
177
+ def _process_info(pid: int) -> tuple[int, float, list[str]] | None:
178
+ """(parent pid, seconds since it started, command line) of process `pid`, via `ps` (Linux and macOS; None
179
+ anywhere it isn't available, e.g. Windows)."""
180
+ try:
181
+ r = subprocess.run(["ps", "-o", "ppid=,etime=,args=", "-p", str(pid)], capture_output=True, encoding="utf-8", timeout=CLI_TIMEOUT_SECS, check=False)
182
+ except (OSError, subprocess.SubprocessError):
183
+ return None
184
+ parts = r.stdout.split(None, 2)
185
+ if r.returncode != 0 or len(parts) < 3 or not parts[0].isdigit():
186
+ return None
187
+ elapsed = _parse_etime(parts[1])
188
+ return (int(parts[0]), elapsed, parts[2].split()) if elapsed is not None else None
189
+
190
+
191
+ def enclosing_timeout_remaining() -> float | None:
192
+ """Seconds until a `timeout N ...` wrapped around this process (as in `timeout 590 bdt pr status --wait`) kills
193
+ it, or None when there is none (the closest limit when several are nested). Best-effort: walks up the parent
194
+ processes, so it also sees through the shells and launcher shims in between."""
195
+ remaining: float | None = None
196
+ pid = os.getppid()
197
+ for _ in range(_MAX_ANCESTORS):
198
+ if pid < 1 or (info := _process_info(pid)) is None:
199
+ break
200
+ ppid, elapsed, args = info
201
+ limit = parse_timeout_command(args)
202
+ if limit is not None:
203
+ remaining = min(remaining if remaining is not None else limit, max(limit - elapsed, 0.0))
204
+ pid = ppid
205
+ return remaining
206
+
207
+
208
+ def limit_by_enclosing_timeout(timeout_secs: float) -> float:
209
+ """`timeout_secs` of a `--wait` loop (0 = forever), cut down to end `ENCLOSING_TIMEOUT_MARGIN_SECS` before an
210
+ enclosing `timeout N` would kill us. Otherwise that kill drops everything we would have printed, which is
211
+ exactly what `--timeout` is there to avoid -- and callers (agents) keep wrapping the command in `timeout`
212
+ instead of passing `--timeout`."""
213
+ remaining = enclosing_timeout_remaining()
214
+ if remaining is None:
215
+ return timeout_secs
216
+ limit = max(remaining - ENCLOSING_TIMEOUT_MARGIN_SECS, 1.0)
217
+ if timeout_secs and timeout_secs <= limit:
218
+ return timeout_secs
219
+ print(f"Enclosing `timeout` ends in {remaining:.0f} s: giving up waiting after {limit:.0f} s so the status gets printed first.", file=sys.stderr)
220
+ return limit
221
+
222
+
117
223
  def is_claude_code() -> bool:
118
224
  """True if this process is running as a subprocess of Claude Code.
119
225
 
@@ -10,7 +10,7 @@ packages = ["bmsdna"]
10
10
 
11
11
  [project]
12
12
  name = "bmsdna-devtools"
13
- version = "0.57.2"
13
+ version = "0.58.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,7 +54,8 @@ 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. Exit 3 = a stage needs a human's approval.
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.
58
59
 
59
60
  `pr status`, `info`, `retry`, `publish`, `update`, `comment` (and `issue take`
60
61
  without a number) find the PR opened from the current branch into **any**
@@ -4,6 +4,9 @@ whose own time limit is shorter than CI (an agent's shell tool, say) gets a resu
4
4
  from __future__ import annotations
5
5
 
6
6
  import re
7
+ import shutil
8
+ import subprocess
9
+ import sys
7
10
  import time
8
11
  from unittest.mock import MagicMock
9
12
 
@@ -11,7 +14,7 @@ import pytest
11
14
  from typer.testing import CliRunner
12
15
 
13
16
  from bmsdna.devtools.cli import app
14
- from bmsdna.devtools.cli_tools import EXIT_WAIT_TIMEOUT, WaitDeadline
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
15
18
  from bmsdna.devtools.gh_pr import run as gh_run
16
19
  from bmsdna.devtools.gitrepo import AdoRemote, GitHubRemote
17
20
  from bmsdna.devtools.issue_watch import EXIT_TIMEOUT
@@ -20,6 +23,13 @@ from bmsdna.devtools.pr_build import run as ado_run
20
23
  runner = CliRunner()
21
24
 
22
25
 
26
+ @pytest.fixture(autouse=True)
27
+ def no_enclosing_timeout(monkeypatch) -> None:
28
+ """Whatever wraps the test run (an agent's `timeout 300 pytest`) must not clamp the waits under test; the tests
29
+ of the detection itself set their own."""
30
+ monkeypatch.setattr("bmsdna.devtools.cli_tools.enclosing_timeout_remaining", lambda: None)
31
+
32
+
23
33
  @pytest.fixture
24
34
  def sleeps(monkeypatch) -> list[float]:
25
35
  """A fake clock: `time.sleep` only advances `time.monotonic`, and records what it was asked for."""
@@ -185,3 +195,112 @@ def test_cli_rejects_a_timeout_that_is_not_a_finite_number(monkeypatch, bad) ->
185
195
  result = runner.invoke(app, ["pr", "status", "--wait", "--timeout", bad])
186
196
 
187
197
  assert result.exit_code == 2
198
+
199
+
200
+ # -- an enclosing `timeout N` (as in `timeout 590 bdt pr status --wait`) ----------
201
+
202
+
203
+ @pytest.mark.parametrize(
204
+ ("args", "expected"),
205
+ [
206
+ (["timeout", "590", "bdt", "pr", "status", "--wait"], 590),
207
+ (["/usr/bin/timeout", "9m", "bdt"], 540),
208
+ (["gtimeout", "1.5h", "bdt"], 5400),
209
+ (["timeout", "-k", "10", "--signal=INT", "-v", "600", "bdt"], 600),
210
+ (["timeout", "--kill-after", "10", "--foreground", "600s", "bdt"], 600),
211
+ (["timeout", "-vk", "5", "600", "bdt"], 600), # a flag cluster ending in -k takes the next argument
212
+ (["timeout", "-vk5", "600", "bdt"], 600),
213
+ (["timeout", "--kill", "5", "--sig", "KILL", "600", "bdt"], 600), # abbreviated long options
214
+ (["timeout", "--", "600", "bdt"], 600),
215
+ (["timeout", "1e3", "bdt"], 1000),
216
+ (["timeout", "-x", "600", "bdt"], None), # unknown option: don't guess
217
+ (["timeout", "inf", "bdt"], None),
218
+ (["timeout", "0", "bdt"], None), # 0 = no limit
219
+ (["timeout", "soon", "bdt"], None),
220
+ (["timeout"], None),
221
+ (["bdt", "pr", "status", "--wait", "--timeout", "590"], None),
222
+ ([], None),
223
+ ],
224
+ )
225
+ def test_parse_timeout_command(args: list[str], expected: float | None) -> None:
226
+ assert parse_timeout_command(args) == expected
227
+
228
+
229
+ def _fake_ancestors(monkeypatch, chain: list[tuple[int, float, list[str]]]) -> None:
230
+ """The process tree above us, nearest parent first: (parent pid, seconds running, command line)."""
231
+ by_pid = {100 + i: info for i, info in enumerate(chain)}
232
+ monkeypatch.setattr("os.getppid", lambda: 100)
233
+ monkeypatch.setattr("bmsdna.devtools.cli_tools._process_info", lambda pid: by_pid.get(pid))
234
+
235
+
236
+ def test_remaining_time_of_the_enclosing_timeout_counts_what_already_ran(monkeypatch) -> None:
237
+ # bdt <- timeout 590 (running for 3 s) <- bash
238
+ _fake_ancestors(monkeypatch, [(101, 3.0, ["timeout", "590", "bdt", "pr", "status", "--wait"]), (1, 900.0, ["bash"])])
239
+
240
+ assert enclosing_timeout_remaining() == 587
241
+
242
+
243
+ def test_the_closest_of_several_nested_timeouts_wins(monkeypatch) -> None:
244
+ _fake_ancestors(monkeypatch, [(101, 0.0, ["timeout", "590", "bdt"]), (102, 0.0, ["bash", "-c", "..."]), (1, 50.0, ["timeout", "300", "bash"])])
245
+
246
+ assert enclosing_timeout_remaining() == 250
247
+
248
+
249
+ def test_a_timeout_that_is_pid_1_is_found_too(monkeypatch) -> None:
250
+ # `docker run image timeout 590 bdt pr status --wait`
251
+ monkeypatch.setattr("os.getppid", lambda: 1)
252
+ monkeypatch.setattr("bmsdna.devtools.cli_tools._process_info", lambda pid: (0, 2.0, ["timeout", "590", "bdt"]) if pid == 1 else None)
253
+
254
+ assert enclosing_timeout_remaining() == 588
255
+
256
+
257
+ def test_no_enclosing_timeout(monkeypatch) -> None:
258
+ _fake_ancestors(monkeypatch, [(101, 5.0, ["bash"]), (1, 5.0, ["claude"])])
259
+
260
+ assert enclosing_timeout_remaining() is None
261
+
262
+
263
+ def test_unreadable_process_tree_is_no_enclosing_timeout(monkeypatch) -> None:
264
+ _fake_ancestors(monkeypatch, [])
265
+
266
+ assert enclosing_timeout_remaining() is None
267
+
268
+
269
+ @pytest.mark.parametrize(
270
+ ("enclosing", "own", "expected"),
271
+ [
272
+ (None, 0, 0), # nothing around us: wait forever, as before
273
+ (None, 120, 120),
274
+ (590, 0, 590 - ENCLOSING_TIMEOUT_MARGIN_SECS),
275
+ (590, 3600, 590 - ENCLOSING_TIMEOUT_MARGIN_SECS),
276
+ (590, 120, 120), # an explicit --timeout that fits stays
277
+ (10, 0, 1), # hardly any time left: still one status report
278
+ ],
279
+ )
280
+ def test_limit_by_enclosing_timeout(monkeypatch, enclosing: float | None, own: float, expected: float) -> None:
281
+ monkeypatch.setattr("bmsdna.devtools.cli_tools.enclosing_timeout_remaining", lambda: enclosing)
282
+
283
+ assert limit_by_enclosing_timeout(own) == expected
284
+
285
+
286
+ @pytest.mark.parametrize(("args", "expected"), [(["--wait"], 70), (["--wait", "--timeout", "30"], 30), (["--wait", "--timeout", "0"], 70), ([], 0)])
287
+ def test_pr_status_passes_the_limited_timeout_on(monkeypatch, args: list[str], expected: float) -> None:
288
+ run = MagicMock()
289
+ monkeypatch.setattr("bmsdna.devtools.cli.current_remote", lambda: AdoRemote("myorg", "MyProj", "myrepo"))
290
+ monkeypatch.setattr("bmsdna.devtools.cli.pr_build.run", run)
291
+ monkeypatch.setattr("bmsdna.devtools.cli_tools.enclosing_timeout_remaining", lambda: 100.0)
292
+
293
+ result = runner.invoke(app, ["pr", "status", "--pr-id", "42", *args])
294
+
295
+ assert result.exit_code == 0, result.output
296
+ assert run.call_args.kwargs["timeout"] == expected
297
+
298
+
299
+ 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
+ code = "from bmsdna.devtools.cli_tools import enclosing_timeout_remaining as r; print(r())"
303
+ out = subprocess.run(["timeout", "600", sys.executable, "-c", code], capture_output=True, encoding="utf-8", check=True).stdout
304
+
305
+ assert out.strip() != "None"
306
+ assert 0 <= float(out) <= 600 # less if the test run itself is under a shorter `timeout`
@@ -51,7 +51,7 @@ wheels = [
51
51
 
52
52
  [[package]]
53
53
  name = "bmsdna-devtools"
54
- version = "0.57.2"
54
+ version = "0.58.0"
55
55
  source = { editable = "." }
56
56
  dependencies = [
57
57
  { name = "azure-identity" },