argus-code-review 0.4.1__tar.gz → 0.4.3__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 (164) hide show
  1. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/CHANGELOG.md +16 -1
  2. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/PKG-INFO +1 -1
  3. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/gemini_runner.py +169 -20
  4. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/graph.py +29 -3
  5. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_gemini_runner.py +120 -7
  6. argus_code_review-0.4.3/tests/test_prior_sha_unreachable.py +54 -0
  7. argus_code_review-0.4.3/tests/test_round2_pr_scope.py +57 -0
  8. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/.gitignore +0 -0
  9. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/LICENSE +0 -0
  10. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/README.md +0 -0
  11. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/__init__.py +0 -0
  12. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/bench.py +0 -0
  13. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/bench_default.toml +0 -0
  14. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/cli.py +0 -0
  15. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/config.py +0 -0
  16. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/coverage.py +0 -0
  17. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/dotenv_utils.py +0 -0
  18. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/gemini_cache.py +0 -0
  19. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/github_client.py +0 -0
  20. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/helpers.py +0 -0
  21. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/llm/models.py +0 -0
  22. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/llm/output_models.py +0 -0
  23. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/llm/pricing.py +0 -0
  24. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/llm/usage.py +0 -0
  25. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/models.py +0 -0
  26. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/openai_client.py +0 -0
  27. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/openai_runner.py +0 -0
  28. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/pipeline_models.py +0 -0
  29. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/__init__.py +0 -0
  30. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/actions_scanner.py +0 -0
  31. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/engine.py +0 -0
  32. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/eslint_bundle/.gitignore +0 -0
  33. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/eslint_bundle/README.md +0 -0
  34. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/eslint_bundle/eslint.config.js +0 -0
  35. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/eslint_bundle/package-lock.json +0 -0
  36. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/eslint_bundle/package.json +0 -0
  37. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/js_scanner.py +0 -0
  38. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/migration_scanner.py +0 -0
  39. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/rules/README.md +0 -0
  40. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/sarif.py +0 -0
  41. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/scanner_utils.py +0 -0
  42. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/secrets_scanner.py +0 -0
  43. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/shadow.py +0 -0
  44. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/terraform_scanner.py +0 -0
  45. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/precheck/workflow_lint_scanner.py +0 -0
  46. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/__init__.py +0 -0
  47. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-blocking-validator.md +0 -0
  48. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-coverage-check.md +0 -0
  49. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-cross-cutting.md +0 -0
  50. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-feedback-verifier.md +0 -0
  51. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-lite.md +0 -0
  52. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-planner.md +0 -0
  53. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-preflight-router.md +0 -0
  54. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-prior-art.md +0 -0
  55. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-scope.md +0 -0
  56. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-deployment.md +0 -0
  57. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-frontend.md +0 -0
  58. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-infra.md +0 -0
  59. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-llm-patterns.md +0 -0
  60. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-observability.md +0 -0
  61. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-orchestration.md +0 -0
  62. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-security.md +0 -0
  63. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-slackbot.md +0 -0
  64. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-specialist-sql.md +0 -0
  65. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-subagent.md +0 -0
  66. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-tests-and-docs.md +0 -0
  67. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts/pr-review-writer.md +0 -0
  68. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/prompts_runtime.py +0 -0
  69. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/repo_provision.py +0 -0
  70. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/review_tools.py +0 -0
  71. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/runners.py +0 -0
  72. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/scope.py +0 -0
  73. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/__init__.py +0 -0
  74. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/http.py +0 -0
  75. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/models.py +0 -0
  76. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/precheck.py +0 -0
  77. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/resolver.py +0 -0
  78. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/session.py +0 -0
  79. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/sql.py +0 -0
  80. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/argus/storage/sqlite.py +0 -0
  81. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/pyproject.toml +0 -0
  82. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/008_add_code_reviews.sql +0 -0
  83. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/009_add_reviewer_version.sql +0 -0
  84. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/010_add_review_patterns.sql +0 -0
  85. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/011_add_review_progress_columns.sql +0 -0
  86. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/015_create_agent_runs.sql +0 -0
  87. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/016_add_agent_runs_failure_reason.sql +0 -0
  88. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/017_add_precheck_rules.sql +0 -0
  89. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/schema/018_widen_agent_runs_failure_reason.sql +0 -0
  90. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/__init__.py +0 -0
  91. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/conftest.py +0 -0
  92. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/golden/review_response.schema.json +0 -0
  93. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/__init__.py +0 -0
  94. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_backend_contract.py +0 -0
  95. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_http.py +0 -0
  96. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_models.py +0 -0
  97. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_resolver.py +0 -0
  98. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_session.py +0 -0
  99. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_sql.py +0 -0
  100. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/storage/test_sqlite_backend.py +0 -0
  101. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_actions_scanner.py +0 -0
  102. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_argus_review_local.py +0 -0
  103. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_bench.py +0 -0
  104. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_bench_config_guard.py +0 -0
  105. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_catchup_gate.py +0 -0
  106. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_cli_args.py +0 -0
  107. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_cli_output_contract.py +0 -0
  108. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_cli_post_review.py +0 -0
  109. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_cli_preflight.py +0 -0
  110. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_cli_prompts.py +0 -0
  111. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_config.py +0 -0
  112. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_conftest.py +0 -0
  113. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_dotenv_utils.py +0 -0
  114. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_failure_diagnostics.py +0 -0
  115. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_gemini_cache.py +0 -0
  116. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_gemini_http_retry.py +0 -0
  117. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_github_client_checks_signal.py +0 -0
  118. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_github_client_write.py +0 -0
  119. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_fetch_diff.py +0 -0
  120. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_get_llm_temperature.py +0 -0
  121. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_http_guards.py +0 -0
  122. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_precheck.py +0 -0
  123. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_preflight_image_bump.py +0 -0
  124. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_progress.py +0 -0
  125. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_storage_resolution.py +0 -0
  126. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_graph_timeout_surfacing.py +0 -0
  127. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_js_scanner.py +0 -0
  128. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_llm_models.py +0 -0
  129. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_llm_models_override.py +0 -0
  130. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_llm_pricing.py +0 -0
  131. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_migration_scanner.py +0 -0
  132. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_models.py +0 -0
  133. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_multi_round.py +0 -0
  134. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_openai_client.py +0 -0
  135. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_openai_runner.py +0 -0
  136. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_output_models.py +0 -0
  137. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_packaging.py +0 -0
  138. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_plan_review.py +0 -0
  139. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_precheck_engine.py +0 -0
  140. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_precheck_engine_integration.py +0 -0
  141. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_precheck_sarif.py +0 -0
  142. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_precheck_shadow.py +0 -0
  143. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_precheck_shadow_integration.py +0 -0
  144. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_prompts.py +0 -0
  145. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_repo_provision.py +0 -0
  146. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_review_patterns_integration.py +0 -0
  147. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_review_tools.py +0 -0
  148. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_runners_context7.py +0 -0
  149. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_runners_context_usage.py +0 -0
  150. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_runners_helpers.py +0 -0
  151. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_runners_new.py +0 -0
  152. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_runners_turn_budget.py +0 -0
  153. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_scanner_utils.py +0 -0
  154. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_scope.py +0 -0
  155. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_scope_gate.py +0 -0
  156. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_sdk_bundled_cli_version.py +0 -0
  157. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_secrets_scanner.py +0 -0
  158. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_specialist_validation.py +0 -0
  159. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_stage_costs.py +0 -0
  160. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_storage_precheck.py +0 -0
  161. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_structured_output_methods.py +0 -0
  162. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_terraform_scanner.py +0 -0
  163. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_terraform_scanner_integration.py +0 -0
  164. {argus_code_review-0.4.1 → argus_code_review-0.4.3}/tests/test_workflow_lint_scanner.py +0 -0
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.3] - 2026-11-18
11
+
12
+ ### Fixed
13
+
14
+ - Round 2+ reviews no longer halt with `dispatch_budget_exceeded` after a catch-up merge from the base branch. The round's diff (`prior_sha...head`) held every change the merge brought in, so the planner fanned out over code the PR did not write (for example 65 files for an 8-file PR). The diff now keeps only the files the PR itself changes, and stays whole when the PR file list cannot be confirmed. A file that both the PR and the base branch changed still shows the base branch's lines.
15
+ - A prior review whose commit no longer exists in the repo no longer fails the round with a GitHub 404 (reported by the service as `worker_error`). Storage keys prior rounds by repo and PR number, so a recreated repo or a rewritten history can return such a round. Argus now logs a warning and reviews the whole PR as round 1.
16
+
17
+ ## [0.4.2] - 2026-10-29
18
+
19
+ ### Changed
20
+
21
+ - A Gemini `400 INVALID_ARGUMENT` no longer ends the reviewer session on the first occurrence. Argus now logs a key-free, text-free summary of the failing request (message count, approximate size, part kinds and sizes for the last four turns, and anomalies such as empty parts or function calls with no matching result) plus any error `details` the API returned, then retries the same request once after a short pause (`ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S` / `_MAX_S`, default 2-5 s). The log records whether the retry recovered, which separates a transient fault from a malformed request. Other 4xx errors still fail immediately.
22
+
10
23
  ## [0.4.1] - 2026-10-28
11
24
 
12
25
  ### Fixed
@@ -469,7 +482,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
469
482
  packaged set.
470
483
  - `argus --version`, `argus prompts list`, and `argus prompts export`.
471
484
 
472
- [Unreleased]: https://github.com/redesignhealth/argus-review/compare/v0.4.1...HEAD
485
+ [Unreleased]: https://github.com/redesignhealth/argus-review/compare/v0.4.3...HEAD
486
+ [0.4.3]: https://github.com/redesignhealth/argus-review/compare/v0.4.2...v0.4.3
487
+ [0.4.2]: https://github.com/redesignhealth/argus-review/compare/v0.4.1...v0.4.2
473
488
  [0.4.1]: https://github.com/redesignhealth/argus-review/compare/v0.4.0...v0.4.1
474
489
  [0.4.0]: https://github.com/redesignhealth/argus-review/compare/v0.3.4...v0.4.0
475
490
  [0.3.4]: https://github.com/redesignhealth/argus-review/compare/v0.3.3...v0.3.4
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: argus-code-review
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: Self-orchestrated PR review agent using LangGraph + Claude Agent SDK
5
5
  Project-URL: Repository, https://github.com/redesignhealth/argus-review
6
6
  Project-URL: Issues, https://github.com/redesignhealth/argus-review/issues
@@ -426,6 +426,113 @@ def _failure_detail(exc: BaseException) -> str:
426
426
  return detail
427
427
 
428
428
 
429
+ _INVALID_ARGUMENT_RETRY_MIN_S = 2.0
430
+ _INVALID_ARGUMENT_RETRY_MAX_S = 5.0
431
+ _SHAPE_TAIL_CONTENTS = 4
432
+
433
+
434
+ def _is_invalid_argument(exc: BaseException) -> bool:
435
+ """True for a Gemini ``400 INVALID_ARGUMENT`` API answer."""
436
+ code, status = _error_code_status(exc)
437
+ return code == 400 and (status or "").upper() == "INVALID_ARGUMENT"
438
+
439
+
440
+ def _part_shape(part: Any) -> str:
441
+ """Kind and size of one content part -- never its text."""
442
+ call = getattr(part, "function_call", None)
443
+ if call is not None:
444
+ size = len(json.dumps(call.args or {}, default=str))
445
+ return f"call:{call.name}({size})"
446
+ resp = getattr(part, "function_response", None)
447
+ if resp is not None:
448
+ # An empty result reports size 0 so _describe_request can flag it. The
449
+ # runner wraps every tool output as {"result": output}, so unwrap it.
450
+ payload = resp.response
451
+ if isinstance(payload, dict) and set(payload) == {"result"}:
452
+ payload = payload["result"]
453
+ size = len(json.dumps(payload, default=str)) if payload else 0
454
+ return f"result:{resp.name}({size})"
455
+ text = getattr(part, "text", None)
456
+ if text is not None:
457
+ tag = "thought" if getattr(part, "thought", False) else "text"
458
+ return f"{tag}({len(text)})"
459
+ return type(part).__name__
460
+
461
+
462
+ def _describe_request(contents: list[Any], config: Any = None) -> str:
463
+ """Key-free, text-free summary of a request for diagnosing a 400.
464
+
465
+ Gemini's INVALID_ARGUMENT body carries no field name, so this records the
466
+ structure that could make a request malformed: roles, part kinds and sizes
467
+ for the last few turns, plus anomalies (empty parts, unanswered function
468
+ calls, consecutive same-role turns).
469
+ """
470
+ total = 0
471
+ biggest = 0
472
+ anomalies: list[str] = []
473
+ prev_role = None
474
+ for i, content in enumerate(contents):
475
+ parts = list(content.parts or [])
476
+ if not parts:
477
+ anomalies.append(f"empty-content@{i}")
478
+ calls = results = 0
479
+ for part in parts:
480
+ shape = _part_shape(part)
481
+ size = int(m.group(1)) if (m := re.search(r"\((\d+)\)$", shape)) else 0
482
+ total += size
483
+ biggest = max(biggest, size)
484
+ if shape.startswith("call:"):
485
+ calls += 1
486
+ elif shape.startswith("result:"):
487
+ results += 1
488
+ if size == 0 and shape.startswith(("text", "thought", "result")):
489
+ anomalies.append(f"zero-size-{re.split(r'[:(]', shape)[0]}@{i}")
490
+ if prev_role is not None and content.role == prev_role:
491
+ anomalies.append(f"repeated-role-{content.role}@{i}")
492
+ prev_role = content.role
493
+ nxt = contents[i + 1] if i + 1 < len(contents) else None
494
+ if calls and nxt is not None:
495
+ answered = sum(
496
+ 1 for p in (nxt.parts or []) if getattr(p, "function_response", None) is not None
497
+ )
498
+ if answered != calls:
499
+ anomalies.append(f"calls({calls})!=results({answered})@{i}")
500
+ tail = contents[-_SHAPE_TAIL_CONTENTS:]
501
+ first = len(contents) - len(tail)
502
+ tail_desc = "; ".join(
503
+ f"#{first + j} {c.role}[{', '.join(_part_shape(p) for p in (c.parts or []))}]"
504
+ for j, c in enumerate(tail)
505
+ )
506
+ cfg = ""
507
+ if config is not None:
508
+ cfg = (
509
+ f" tools={len(getattr(config, 'tools', None) or [])}"
510
+ f" system_instruction={bool(getattr(config, 'system_instruction', None))}"
511
+ f" cached_content={bool(getattr(config, 'cached_content', None))}"
512
+ )
513
+ return (
514
+ f"contents={len(contents)} approx_chars={total} largest_part={biggest}{cfg} "
515
+ f"anomalies={anomalies or 'none'} tail: {tail_desc}"
516
+ )
517
+
518
+
519
+ def _safe_describe_request(contents: list[Any], config: Any) -> str:
520
+ """``_describe_request`` that can never mask the error being diagnosed."""
521
+ try:
522
+ return _describe_request(contents, config)
523
+ except Exception as exc: # noqa: BLE001 - diagnostics must not replace the 400
524
+ return f"unavailable ({type(exc).__name__})"
525
+
526
+
527
+ def _error_details(exc: BaseException) -> str:
528
+ """Scrubbed ``details`` payload of an API error (may name the bad field)."""
529
+ details = getattr(exc, "details", None)
530
+ try:
531
+ return _scrub(json.dumps(details, default=str)) if details else ""
532
+ except (TypeError, ValueError):
533
+ return ""
534
+
535
+
429
536
  # Matches the fenced-json extraction argus.helpers.parse_review_result
430
537
  # already applies for the Claude path.
431
538
  _FENCED_JSON_RE = re.compile(r"```(?:json)?\s*(\{.*?\})\s*```", re.DOTALL)
@@ -965,26 +1072,68 @@ async def _run_turns(
965
1072
  _turn,
966
1073
  _scrub(str(exc)),
967
1074
  )
968
- raise
969
- logger.warning(
970
- "Gemini cache [%s] appears invalid upstream (role=%s); "
971
- "invalidating the local record and retrying this turn "
972
- "uncached: %s",
973
- label or "unlabeled",
974
- entry.role,
975
- exc,
976
- )
977
- await asyncio.to_thread(
978
- _invalidate_cache_record,
979
- entry=entry,
980
- model=model,
981
- system_prompt=system_prompt,
982
- )
983
- cached_content_name = None
984
- config = _build_config(None)
985
- response = await client.aio.models.generate_content(
986
- model=model, contents=contents, config=config
987
- )
1075
+ if not _is_invalid_argument(exc):
1076
+ raise
1077
+ # A 400 INVALID_ARGUMENT names no field, so record the
1078
+ # request's shape, then retry this SAME request once:
1079
+ # whether it recovers tells a transient fault from a
1080
+ # deterministic one.
1081
+ logger.error(
1082
+ "Gemini 400 request shape [%s] (turn=%d) details=%s: %s",
1083
+ label or "unlabeled",
1084
+ _turn,
1085
+ _error_details(exc) or "none",
1086
+ _safe_describe_request(contents, config),
1087
+ )
1088
+ lo = _env_float(
1089
+ "ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S",
1090
+ _INVALID_ARGUMENT_RETRY_MIN_S,
1091
+ )
1092
+ hi = _env_float(
1093
+ "ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MAX_S",
1094
+ _INVALID_ARGUMENT_RETRY_MAX_S,
1095
+ )
1096
+ await asyncio.sleep(
1097
+ random.uniform(lo, max(lo, hi)) # noqa: S311 - jitter, not security
1098
+ )
1099
+ try:
1100
+ response = await client.aio.models.generate_content(
1101
+ model=model, contents=contents, config=config
1102
+ )
1103
+ except Exception as retry_exc:
1104
+ logger.error(
1105
+ "Gemini 400 retry failed [%s] (turn=%d): %s",
1106
+ label or "unlabeled",
1107
+ _turn,
1108
+ _scrub(str(retry_exc)),
1109
+ )
1110
+ raise
1111
+ logger.warning(
1112
+ "Gemini 400 recovered on retry [%s] (turn=%d): the failure "
1113
+ "was transient, not a malformed request",
1114
+ label or "unlabeled",
1115
+ _turn,
1116
+ )
1117
+ else:
1118
+ logger.warning(
1119
+ "Gemini cache [%s] appears invalid upstream (role=%s); "
1120
+ "invalidating the local record and retrying this turn "
1121
+ "uncached: %s",
1122
+ label or "unlabeled",
1123
+ entry.role,
1124
+ exc,
1125
+ )
1126
+ await asyncio.to_thread(
1127
+ _invalidate_cache_record,
1128
+ entry=entry,
1129
+ model=model,
1130
+ system_prompt=system_prompt,
1131
+ )
1132
+ cached_content_name = None
1133
+ config = _build_config(None)
1134
+ response = await client.aio.models.generate_content(
1135
+ model=model, contents=contents, config=config
1136
+ )
988
1137
 
989
1138
  progress.responses += 1
990
1139
  usage = response.usage_metadata
@@ -43,6 +43,7 @@ from argus.helpers import (
43
43
  apply_bench_config_change_gate,
44
44
  apply_precheck_gate_and_surface_degraded_coverage,
45
45
  compute_persisted_finding_counts,
46
+ filter_diff_for_files,
46
47
  )
47
48
  from argus.llm.models import ALIAS_MAP, CLAUDE_DEFAULT, CLAUDE_FRONTIER, CLAUDE_MINI
48
49
  from argus.llm.usage import (
@@ -2505,6 +2506,8 @@ async def _node_fetch_diff(state: ReviewState, config: RunnableConfig) -> dict[s
2505
2506
  Also fetches the prior review from storage. If a prior review exists,
2506
2507
  the diff is scoped to reviewed_sha..HEAD (round 2+).
2507
2508
  """
2509
+ from argus.github_client import GitHubAPIError
2510
+
2508
2511
  req = ReviewRequest.model_validate(state["request"])
2509
2512
 
2510
2513
  # Step 0: check for prior review + dismiss commands (parallel)
@@ -2523,9 +2526,27 @@ async def _node_fetch_diff(state: ReviewState, config: RunnableConfig) -> dict[s
2523
2526
 
2524
2527
  pre_resolved_head_sha: str | None = config.get("configurable", {}).get("head_sha")
2525
2528
 
2526
- diff, description, head_sha, base_branch, scope_base_sha = await _fetch_pr_diff_and_description(
2527
- req, prior_sha=prior_sha, pre_resolved_head_sha=pre_resolved_head_sha
2528
- )
2529
+ def fetch(sha: str | None) -> Any:
2530
+ return _fetch_pr_diff_and_description(
2531
+ req, prior_sha=sha, pre_resolved_head_sha=pre_resolved_head_sha
2532
+ )
2533
+
2534
+ try:
2535
+ fetched = await fetch(prior_sha)
2536
+ except GitHubAPIError as exc:
2537
+ if prior is None or exc.status_code != 404:
2538
+ raise
2539
+ # Storage keys prior rounds by (repo, PR number), so a recreated repo or a rewritten
2540
+ # history can return a round whose commit is gone here. Review the whole PR instead.
2541
+ logger.warning(
2542
+ "Prior review %s sha %s is not reachable in %s (404); treating as round 1",
2543
+ prior.review_id,
2544
+ prior_sha,
2545
+ req.repo,
2546
+ )
2547
+ prior, prior_sha = None, None
2548
+ fetched = await fetch(None)
2549
+ diff, description, head_sha, base_branch, scope_base_sha = fetched
2529
2550
 
2530
2551
  # Log review metadata
2531
2552
  lines = diff.splitlines()
@@ -2550,6 +2571,11 @@ async def _node_fetch_diff(state: ReviewState, config: RunnableConfig) -> dict[s
2550
2571
  req, base_branch, head_sha, diff, prior_sha=prior_sha, base_sha=scope_base_sha
2551
2572
  )
2552
2573
 
2574
+ if prior_sha and full_changed_files and not unconfirmed_reason:
2575
+ # A catch-up merge puts the base branch's changes inside prior_sha..head. Keep only
2576
+ # files the PR itself changes, or the plan fans out over code nobody here wrote.
2577
+ diff = filter_diff_for_files(diff, [f.get("filename", "") for f in full_changed_files])
2578
+
2553
2579
  bench_config_changes: list[str] = []
2554
2580
  for f in full_changed_files:
2555
2581
  # Exclude files with status == 'removed' — pure deletion of a bench config is safe
@@ -33,7 +33,12 @@ from google.genai import errors as genai_errors # noqa: E402
33
33
  from google.genai import types # noqa: E402
34
34
 
35
35
  from argus.bench import BenchEntry # noqa: E402
36
- from argus.gemini_runner import _MAX_TURNS_GEMINI, run_session_gemini # noqa: E402
36
+ from argus.gemini_runner import ( # noqa: E402
37
+ _MAX_TURNS_GEMINI,
38
+ _describe_request,
39
+ _safe_describe_request,
40
+ run_session_gemini,
41
+ )
37
42
  from argus.llm.models import resolve as resolve_alias # noqa: E402
38
43
  from argus.runners import _TURN_BUDGET_SYSTEM_PROMPT_LINE # noqa: E402
39
44
 
@@ -65,7 +70,7 @@ def _isolate_gemini_cache_dir(tmp_path: Any, monkeypatch: pytest.MonkeyPatch) ->
65
70
 
66
71
  monkeypatch.setenv("ARGUS_GEMINI_CACHE_DIR", str(tmp_path / "gemini-cache"))
67
72
  # Existing tests must not sleep through the real retry cooldown.
68
- for name in ("RATE_LIMIT", "COOLDOWN"):
73
+ for name in ("RATE_LIMIT", "COOLDOWN", "INVALID_ARGUMENT"):
69
74
  monkeypatch.setenv(f"ARGUS_GEMINI_RETRY_{name}_MIN_S", "0")
70
75
  monkeypatch.setenv(f"ARGUS_GEMINI_RETRY_{name}_MAX_S", "0")
71
76
  clear_settings_cache()
@@ -1601,10 +1606,13 @@ class TestCacheInvalidatedUpstreamDegradesGracefully:
1601
1606
  repo_root="/tmp/does-not-need-to-exist",
1602
1607
  )
1603
1608
 
1604
- # Not retried uncached (that would mean 2 awaits, as in the
1605
- # cache-invalid-recovery test above) -- the error propagated
1606
- # straight out of the cache-retry logic on the first attempt.
1607
- assert fake_client.aio.models.generate_content.await_count == 1
1609
+ # Not retried uncached: the one retry a 400 INVALID_ARGUMENT gets
1610
+ # re-sends the exact same request (cache reference included), unlike
1611
+ # the cache-invalid-recovery test above, which drops the cache.
1612
+ calls = fake_client.aio.models.generate_content.await_args_list
1613
+ assert len(calls) == 2
1614
+ assert calls[0].kwargs["config"].cached_content == "cachedContents/abc123"
1615
+ assert calls[1].kwargs["config"].cached_content == "cachedContents/abc123"
1608
1616
  assert result.failure_reason == "worker_crashed"
1609
1617
  assert result.result_text == ""
1610
1618
 
@@ -1807,7 +1815,7 @@ class TestTransientRetry:
1807
1815
  [
1808
1816
  (401, "UNAUTHENTICATED"),
1809
1817
  (403, "PERMISSION_DENIED"),
1810
- (400, "INVALID_ARGUMENT"),
1818
+ (400, "FAILED_PRECONDITION"),
1811
1819
  (404, "NOT_FOUND"),
1812
1820
  ],
1813
1821
  )
@@ -1818,6 +1826,49 @@ class TestTransientRetry:
1818
1826
  assert result.failure_reason == "worker_crashed"
1819
1827
  assert result.failure_detail == f"{code} {status}, turn 0"
1820
1828
 
1829
+ async def test_invalid_argument_logs_request_shape_and_retries_once(
1830
+ self, caplog: pytest.LogCaptureFixture
1831
+ ) -> None:
1832
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1833
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1834
+ with caplog.at_level("INFO", logger="argus.gemini_runner"):
1835
+ result = await _run(client)
1836
+ assert result.failure_reason is None
1837
+ assert client.aio.models.generate_content.await_count == 2
1838
+ messages = [r.message for r in caplog.records]
1839
+ assert any("Gemini 400 request shape [retry-test] (turn=0)" in m for m in messages)
1840
+ assert any("Gemini 400 recovered on retry [retry-test]" in m for m in messages)
1841
+
1842
+ async def test_describer_failure_does_not_skip_the_retry(self) -> None:
1843
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1844
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1845
+ with patch("argus.gemini_runner._describe_request", side_effect=ValueError("odd args")):
1846
+ result = await _run(client)
1847
+ assert result.failure_reason is None
1848
+ assert client.aio.models.generate_content.await_count == 2
1849
+
1850
+ async def test_inverted_retry_bounds_do_not_crash(
1851
+ self, monkeypatch: pytest.MonkeyPatch
1852
+ ) -> None:
1853
+ monkeypatch.setenv("ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MIN_S", "0.02")
1854
+ monkeypatch.setenv("ARGUS_GEMINI_RETRY_INVALID_ARGUMENT_MAX_S", "0")
1855
+ ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1856
+ client = _make_fake_client([_api_error(400, "INVALID_ARGUMENT"), ok])
1857
+ result = await _run(client)
1858
+ assert result.failure_reason is None
1859
+
1860
+ async def test_invalid_argument_failing_twice_fails_session_after_one_retry(
1861
+ self, caplog: pytest.LogCaptureFixture
1862
+ ) -> None:
1863
+ err = _api_error(400, "INVALID_ARGUMENT")
1864
+ client = _make_fake_client([err, err, err])
1865
+ with caplog.at_level("INFO", logger="argus.gemini_runner"):
1866
+ result = await _run(client)
1867
+ assert client.aio.models.generate_content.await_count == 2
1868
+ assert result.failure_reason == "worker_crashed"
1869
+ assert result.failure_detail == "400 INVALID_ARGUMENT, turn 0"
1870
+ assert any("Gemini 400 retry failed [retry-test]" in r.message for r in caplog.records)
1871
+
1821
1872
  async def test_httpx_connect_error_is_retried(self) -> None:
1822
1873
  ok = _make_response(calls=[], usage=_make_usage(1, 1), text="fine")
1823
1874
  client = _make_fake_client([httpx.ConnectError("reset"), ok])
@@ -1988,3 +2039,65 @@ class TestTransientRetry:
1988
2039
  text = " ".join(r.getMessage() for r in caplog.records)
1989
2040
  assert secret not in text
1990
2041
  assert len(text) < 1200
2042
+
2043
+
2044
+ class TestDescribeRequest:
2045
+ async def test_summarises_shape_without_leaking_text(self) -> None:
2046
+ contents = [
2047
+ types.Content(role="user", parts=[types.Part.from_text(text="SECRETBODY" * 50)]),
2048
+ types.Content(
2049
+ role="model",
2050
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2051
+ ),
2052
+ types.Content(role="user", parts=[types.Part.from_text(text="")]),
2053
+ ]
2054
+ out = _describe_request(contents)
2055
+ assert "SECRETBODY" not in out
2056
+ assert "contents=3" in out
2057
+ assert "call:grep(" in out
2058
+ assert "calls(1)!=results(0)@1" in out # the call was never answered
2059
+ assert "zero-size-text@2" in out
2060
+
2061
+ async def test_clean_request_reports_no_anomalies(self) -> None:
2062
+ contents = [
2063
+ types.Content(role="user", parts=[types.Part.from_text(text="hi")]),
2064
+ types.Content(
2065
+ role="model",
2066
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2067
+ ),
2068
+ types.Content(
2069
+ role="user",
2070
+ parts=[types.Part.from_function_response(name="grep", response={"output": "ok"})],
2071
+ ),
2072
+ ]
2073
+ assert "anomalies=none" in _describe_request(contents)
2074
+
2075
+ async def test_empty_tool_result_is_flagged(self) -> None:
2076
+ contents = [
2077
+ types.Content(
2078
+ role="model",
2079
+ parts=[types.Part.from_function_call(name="grep", args={"pattern": "x"})],
2080
+ ),
2081
+ types.Content(
2082
+ role="user",
2083
+ parts=[types.Part.from_function_response(name="grep", response={})],
2084
+ ),
2085
+ ]
2086
+ assert "zero-size-result@1" in _describe_request(contents)
2087
+
2088
+ async def test_empty_wrapped_tool_result_is_flagged(self) -> None:
2089
+ contents = [
2090
+ types.Content(
2091
+ role="user",
2092
+ parts=[types.Part.from_function_response(name="grep", response={"result": ""})],
2093
+ ),
2094
+ ]
2095
+ assert "zero-size-result@0" in _describe_request(contents)
2096
+
2097
+ async def test_first_turn_without_role_is_not_a_repeat(self) -> None:
2098
+ contents = [types.Content(role=None, parts=[types.Part.from_text(text="hi")])]
2099
+ assert "repeated-role" not in _describe_request(contents)
2100
+
2101
+ async def test_safe_describe_never_raises(self) -> None:
2102
+ out = _safe_describe_request(object(), None)
2103
+ assert out.startswith("unavailable (")
@@ -0,0 +1,54 @@
1
+ """A prior review whose commit is not in this repo must not fail the round."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+ from unittest.mock import AsyncMock, MagicMock, patch
7
+
8
+ import pytest
9
+
10
+ from argus.github_client import GitHubAPIError
11
+ from argus.graph import _node_fetch_diff
12
+ from argus.models import ReviewRequest
13
+
14
+ _GH_CLIENT_CLASS = "argus.github_client.GitHubClient"
15
+
16
+
17
+ @pytest.mark.asyncio
18
+ async def test_unreachable_prior_sha_falls_back_to_round_one() -> None:
19
+ prior = MagicMock(reviewed_sha="a" * 40, findings=[], dismissed_findings=[])
20
+ fetch = AsyncMock(
21
+ side_effect=[
22
+ GitHubAPIError(404, "Not Found"),
23
+ ("diff", "desc", "b" * 40, "main", None),
24
+ ]
25
+ )
26
+ gh = MagicMock()
27
+ gh.get_compare_files.return_value = ([], False)
28
+ state = {"request": ReviewRequest(repo="org/repo", pr_number=4).model_dump()}
29
+
30
+ with (
31
+ patch("argus.graph._fetch_prior_review", new_callable=AsyncMock, return_value=prior),
32
+ patch("argus.graph._fetch_dismissed_findings", new_callable=AsyncMock, return_value=[]),
33
+ patch("argus.graph._fetch_pr_diff_and_description", fetch),
34
+ patch(_GH_CLIENT_CLASS, return_value=gh),
35
+ ):
36
+ result: dict[str, Any] = await _node_fetch_diff(state, {"configurable": {}})
37
+
38
+ assert [c.kwargs["prior_sha"] for c in fetch.call_args_list] == ["a" * 40, None]
39
+ assert result["prior_review"] == {}
40
+ assert result["diff"] == "diff"
41
+
42
+
43
+ @pytest.mark.asyncio
44
+ async def test_404_without_prior_still_raises() -> None:
45
+ fetch = AsyncMock(side_effect=GitHubAPIError(404, "Not Found"))
46
+ state = {"request": ReviewRequest(repo="org/repo", pr_number=4).model_dump()}
47
+
48
+ with (
49
+ patch("argus.graph._fetch_prior_review", new_callable=AsyncMock, return_value=None),
50
+ patch("argus.graph._fetch_dismissed_findings", new_callable=AsyncMock, return_value=[]),
51
+ patch("argus.graph._fetch_pr_diff_and_description", fetch),
52
+ pytest.raises(GitHubAPIError),
53
+ ):
54
+ await _node_fetch_diff(state, {"configurable": {}})
@@ -0,0 +1,57 @@
1
+ """Round 2+ reviews only the PR's own files, not what a catch-up merge brought from main."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any
6
+ from unittest.mock import AsyncMock, MagicMock, patch
7
+
8
+ import pytest
9
+
10
+ from argus.graph import _node_fetch_diff
11
+ from argus.models import ReviewRequest
12
+
13
+ _GH_CLIENT_CLASS = "argus.github_client.GitHubClient"
14
+
15
+
16
+ def _file_diff(path: str) -> str:
17
+ return f"diff --git a/{path} b/{path}\n--- a/{path}\n+++ b/{path}\n@@ -1 +1 @@\n-old\n+new\n"
18
+
19
+
20
+ def _prior() -> MagicMock:
21
+ prior = MagicMock(reviewed_sha="a" * 40, findings=[], dismissed_findings=[])
22
+ prior.model_dump.return_value = {"reviewed_sha": "a" * 40}
23
+ return prior
24
+
25
+
26
+ async def _run(compare_files: list[dict[str, Any]], truncated: bool = False) -> dict[str, Any]:
27
+ window = _file_diff("src/pr.py") + _file_diff("from_main/a.py") + _file_diff("from_main/b.py")
28
+ gh = MagicMock()
29
+ gh.get_compare_files.return_value = (compare_files, truncated)
30
+ state = {"request": ReviewRequest(repo="org/repo", pr_number=126).model_dump()}
31
+ with (
32
+ patch("argus.graph._fetch_prior_review", new_callable=AsyncMock, return_value=_prior()),
33
+ patch("argus.graph._fetch_dismissed_findings", new_callable=AsyncMock, return_value=[]),
34
+ patch(
35
+ "argus.graph._fetch_pr_diff_and_description",
36
+ new_callable=AsyncMock,
37
+ return_value=(window, "desc", "b" * 40, "main", "c" * 40),
38
+ ),
39
+ patch(_GH_CLIENT_CLASS, return_value=gh),
40
+ ):
41
+ return await _node_fetch_diff(state, {"configurable": {}})
42
+
43
+
44
+ @pytest.mark.asyncio
45
+ async def test_round2_diff_drops_files_the_pr_did_not_change() -> None:
46
+ result = await _run([{"filename": "src/pr.py", "status": "modified", "patch": "+new\n"}])
47
+
48
+ assert "src/pr.py" in result["diff"]
49
+ assert "from_main" not in result["diff"]
50
+
51
+
52
+ @pytest.mark.asyncio
53
+ async def test_round2_diff_is_kept_whole_when_pr_file_list_is_truncated() -> None:
54
+ files = [{"filename": "src/pr.py", "status": "modified", "patch": "+new\n"}]
55
+ result = await _run(files, truncated=True)
56
+
57
+ assert "from_main/a.py" in result["diff"]