claude-dev-env 2.3.0 → 2.5.0
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.
- package/CLAUDE.md +53 -48
- package/_shared/pr-loop/scripts/_claude_permissions_common.py +84 -0
- package/_shared/pr-loop/scripts/code_rules_gate.py +4 -2
- package/_shared/pr-loop/scripts/grant_project_claude_permissions.py +306 -306
- package/_shared/pr-loop/scripts/pr_loop_shared_constants/claude_permissions_constants.py +44 -0
- package/_shared/pr-loop/scripts/pr_loop_shared_constants/copilot_quota_constants.py +24 -24
- package/_shared/pr-loop/scripts/pr_loop_shared_constants/stale_worktree_rule_sweep_constants.py +107 -107
- package/_shared/pr-loop/scripts/revoke_project_claude_permissions.py +290 -48
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_common.py +42 -2
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_constants.py +36 -0
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +100 -1
- package/_shared/pr-loop/scripts/tests/test_fix_hookspath.py +497 -497
- package/_shared/pr-loop/scripts/tests/test_revoke_project_claude_permissions.py +311 -2
- package/_shared/pr-loop/scripts/tests/test_stale_worktree_rule_sweep.py +301 -301
- package/_shared/pr-loop/scripts/tests/test_stale_worktree_rule_sweep_constants.py +85 -85
- package/_shared/pr-loop/worker-spawn.md +1 -1
- package/agents/CLAUDE.md +3 -1
- package/agents/caveman.md +0 -1
- package/agents/clasp-deployment-orchestrator.md +0 -1
- package/agents/clean-coder.md +0 -1
- package/agents/code-advisor.md +0 -1
- package/agents/code-quality-agent.md +1 -2
- package/agents/code-verifier.md +3 -4
- package/agents/deep-research.md +0 -1
- package/agents/docs-agent.md +0 -1
- package/agents/git-commit-crafter.md +0 -1
- package/agents/issue-tracker.md +42 -0
- package/agents/plan-packet-validator.md +0 -1
- package/agents/pr-description-writer.md +0 -1
- package/agents/skill-writer-agent.md +84 -0
- package/agents/test_agent_frontmatter.py +67 -18
- package/audit-rubrics/category_rubrics/category-o-docstring-vs-impl-drift.md +105 -3
- package/audit-rubrics/prompts/category-o-docstring-vs-impl-drift.md +29 -13
- package/bin/CLAUDE.md +68 -5
- package/bin/ever-shipped-skills.mjs +1 -0
- package/bin/install-constants.mjs +88 -0
- package/bin/install.mjs +1138 -114
- package/bin/install.prune.test.mjs +869 -19
- package/bin/install.test.mjs +906 -2
- package/commands/implement.md +1 -1
- package/commands/right-size.md +1 -1
- package/docs/CLAUDE.md +2 -0
- package/docs/host-pool-health-monitor.md +102 -0
- package/docs/references/CLAUDE.md +5 -2
- package/docs/references/advisor-tool.md +13 -0
- package/docs/references/code-review-enforcement.md +107 -0
- package/docs/references/team-advisor-skill.md +14 -0
- package/docs/wsl-docker-cowork-starter-matrix.md +89 -0
- package/hooks/blocking/CLAUDE.md +9 -1
- package/hooks/blocking/code_review_enforcement_config_bootstrap.py +53 -0
- package/hooks/blocking/code_review_gate_deny.py +74 -0
- package/hooks/blocking/code_review_pr_create_gate.py +198 -0
- package/hooks/blocking/code_review_push_gate.py +145 -0
- package/hooks/blocking/code_review_stamp_directory_write_blocker.py +348 -0
- package/hooks/blocking/code_review_stamp_store.py +233 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/__init__.py +7 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/conftest.py +15 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/obfuscated_stamp_path_reference.py +212 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/split_directory_change_into_stamp.py +138 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/test_obfuscated_stamp_path_reference.py +49 -0
- package/hooks/blocking/code_review_stamp_write_blocker_parts/test_split_directory_change_into_stamp.py +38 -0
- package/hooks/blocking/code_verifier_spawn_preflight_gate.py +39 -27
- package/hooks/blocking/config/__init__.py +5 -5
- package/hooks/blocking/config/code_review_enforcement_constants.py +113 -0
- package/hooks/blocking/config/test_code_review_enforcement_constants.py +113 -0
- package/hooks/blocking/config/verified_commit_constants.py +160 -155
- package/hooks/blocking/conftest.py +2 -0
- package/hooks/blocking/convergence_gate_blocker.py +112 -23
- package/hooks/blocking/destructive_command_blocker.py +19 -6
- package/hooks/blocking/orchestrator_refresh_reschedule_gate.py +256 -0
- package/hooks/blocking/pr_description_proof_of_work.py +52 -34
- package/hooks/blocking/pre_tool_use_dispatcher.py +24 -24
- package/hooks/blocking/test_bash_pre_tool_use_dispatcher.py +4 -1
- package/hooks/blocking/test_code_review_enforcement_config_bootstrap.py +62 -0
- package/hooks/blocking/test_code_review_gate_deny.py +54 -0
- package/hooks/blocking/test_code_review_pr_create_gate.py +199 -0
- package/hooks/blocking/test_code_review_push_gate.py +205 -0
- package/hooks/blocking/test_code_review_stamp_directory_write_blocker.py +199 -0
- package/hooks/blocking/test_code_review_stamp_store.py +205 -0
- package/hooks/blocking/test_code_verifier_spawn_preflight_gate.py +124 -2
- package/hooks/blocking/test_convergence_gate_blocker.py +153 -5
- package/hooks/blocking/test_destructive_command_blocker.py +1 -1
- package/hooks/blocking/test_destructive_command_blocker_deny_mode.py +45 -0
- package/hooks/blocking/test_orchestrator_refresh_reschedule_gate.py +231 -0
- package/hooks/blocking/test_pr_description_proof_of_work.py +151 -0
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +17 -8
- package/hooks/blocking/test_verdict_directory_write_blocker.py +808 -808
- package/hooks/blocking/test_verification_verdict_store.py +974 -903
- package/hooks/blocking/test_verified_commit_gate.py +581 -581
- package/hooks/blocking/test_verified_commit_message_accuracy_blocker.py +131 -131
- package/hooks/blocking/test_volatile_path_in_post_blocker.py +114 -2
- package/hooks/blocking/verdict_directory_write_blocker.py +687 -687
- package/hooks/blocking/verification_verdict_store.py +1039 -1014
- package/hooks/blocking/verified_commit_gate_parts/gated_invocations.py +29 -17
- package/hooks/blocking/verified_commit_gate_parts/tests/test_gated_invocations.py +35 -0
- package/hooks/blocking/verified_commit_message_accuracy_blocker.py +167 -167
- package/hooks/blocking/verifier_verdict_minter.py +280 -280
- package/hooks/blocking/volatile_path_in_post_blocker.py +69 -8
- package/hooks/git-hooks/git_hooks_constants/__init__.py +6 -0
- package/hooks/git-hooks/pre_push.py +89 -2
- package/hooks/git-hooks/test_pre_push.py +128 -0
- package/hooks/hooks.json +26 -1
- package/hooks/hooks_constants/CLAUDE.md +3 -1
- package/hooks/hooks_constants/bash_pre_tool_use_dispatcher_constants.py +8 -0
- package/hooks/hooks_constants/code_rules_path_utils_constants.py +1 -0
- package/hooks/hooks_constants/code_verifier_spawn_preflight_gate_constants.py +26 -11
- package/hooks/hooks_constants/convergence_gate_blocker_constants.py +20 -3
- package/hooks/hooks_constants/destructive_command_segment_constants.py +3 -1
- package/hooks/hooks_constants/enter_worktree_prefetch_constants.py +18 -18
- package/hooks/hooks_constants/orchestrator_refresh_reschedule_gate_constants.py +48 -0
- package/hooks/hooks_constants/pr_description_proof_of_work_constants.py +0 -4
- package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +4 -0
- package/hooks/hooks_constants/pyproject_config_discovery_constants.py +16 -0
- package/hooks/hooks_constants/ruff_integration_constants.py +16 -0
- package/hooks/hooks_constants/test_bash_pre_tool_use_dispatcher_constants.py +24 -0
- package/hooks/hooks_constants/test_pre_tool_use_dispatcher_constants.py +6 -0
- package/hooks/hooks_constants/volatile_path_in_post_blocker_constants.py +8 -1
- package/hooks/lifecycle/enter_worktree_origin_prefetch.py +163 -146
- package/hooks/lifecycle/test_enter_worktree_origin_prefetch.py +185 -178
- package/hooks/pyproject.toml +1 -0
- package/hooks/validators/CLAUDE.md +2 -0
- package/hooks/validators/config/__init__.py +0 -0
- package/hooks/validators/config/directory_exemption_constants.py +183 -0
- package/hooks/validators/config/test_directory_exemption_constants.py +21 -0
- package/hooks/validators/conftest.py +4 -0
- package/hooks/validators/mypy_integration.py +63 -50
- package/hooks/validators/pyproject_config_discovery.py +101 -0
- package/hooks/validators/ruff_integration.py +257 -25
- package/hooks/validators/run_all_validators.py +223 -19
- package/hooks/validators/test_directory_exemption_constants.py +185 -0
- package/hooks/validators/test_mypy_integration.py +32 -0
- package/hooks/validators/test_pyproject_config_discovery.py +94 -0
- package/hooks/validators/test_python_antipattern_checks.py +110 -5
- package/hooks/validators/test_ruff_integration.py +160 -2
- package/hooks/validators/test_run_all_validators.py +140 -68
- package/hooks/validators/test_run_all_validators_config_discovery.py +123 -0
- package/hooks/validators/test_run_all_validators_pretooluse.py +159 -1
- package/package.json +10 -2
- package/rules/CLAUDE.md +1 -0
- package/rules/docstring-prose-matches-implementation.md +45 -67
- package/rules/durable-post-artifacts.md +7 -0
- package/rules/state-what-is.md +25 -0
- package/rules/verified-commit-gate-skip.md +1 -1
- package/scripts/CLAUDE.md +1 -0
- package/scripts/Capture-PoolHealth.ps1 +410 -0
- package/scripts/_code_review_test_support.py +404 -0
- package/scripts/claude_chain_runner.py +141 -1
- package/scripts/codec_forwarding_test_support.py +83 -0
- package/scripts/conftest.py +23 -0
- package/scripts/dev_env_scripts_constants/CLAUDE.md +2 -2
- package/scripts/dev_env_scripts_constants/claude_chain_constants.py +53 -1
- package/scripts/dev_env_scripts_constants/code_review_constants.py +129 -12
- package/scripts/dev_env_scripts_constants/test_code_review_constants.py +55 -0
- package/scripts/invoke_code_review.py +550 -38
- package/scripts/resolve_worker_spawn.py +626 -619
- package/scripts/spawn_grok_batch.py +672 -672
- package/scripts/test_claude_chain_runner.py +131 -0
- package/scripts/test_invoke_code_review_chain.py +70 -0
- package/scripts/test_invoke_code_review_cli.py +192 -0
- package/scripts/test_invoke_code_review_codec.py +77 -0
- package/scripts/test_invoke_code_review_contract.py +256 -0
- package/scripts/test_invoke_code_review_git.py +123 -0
- package/scripts/test_invoke_code_review_mode.py +99 -0
- package/scripts/test_resolve_worker_spawn.py +1014 -1014
- package/scripts/test_resolve_worker_spawn_codec.py +101 -0
- package/skills/CLAUDE.md +2 -0
- package/skills/auditing-claude-config/SKILL.md +114 -114
- package/skills/autoconverge/SKILL.md +427 -421
- package/skills/autoconverge/reference/convergence.md +26 -4
- package/skills/autoconverge/reference/multi-pr.md +6 -1
- package/skills/autoconverge/reference/stop-conditions.md +16 -10
- package/skills/autoconverge/workflow/CLAUDE.md +1 -0
- package/skills/autoconverge/workflow/converge.clean-audit.test.mjs +4 -4
- package/skills/autoconverge/workflow/converge.codex-gate.test.mjs +175 -3
- package/skills/autoconverge/workflow/converge.contract.test.mjs +1263 -1244
- package/skills/autoconverge/workflow/converge.mjs +191 -8
- package/skills/autoconverge/workflow/converge.p2-advance.test.mjs +202 -0
- package/skills/autoconverge/workflow/converge_multi.mjs +7 -3
- package/skills/autoconverge/workflow/converge_multi.run-input.test.mjs +5 -0
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a11d903476b803493.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a26213978adeef6fb.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a3def0d15ed9d9110.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a41f41b1b708ee3b7.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a758b880abecc3ff7.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-a8897b89656b1bd16.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-abd463d744a1437bc.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/subagents/workflows/wf_881252e6-700/agent-ad19d027ae8ee1816.jsonl +2 -2
- package/skills/autoconverge/workflow/fixtures/wf_run/workflows/wf_881252e6-700.json +265 -265
- package/skills/closeout/SKILL.md +33 -50
- package/skills/codex-review/scripts/codex_review_scripts_constants/run_constants.py +8 -0
- package/skills/codex-review/scripts/run_codex_review.py +233 -1
- package/skills/codex-review/scripts/test_run_codex_review.py +189 -0
- package/skills/condensing-instructions/SKILL.md +81 -0
- package/skills/copilot-review/SKILL.md +119 -119
- package/skills/e-code-review/SKILL.md +52 -0
- package/skills/e-code-review/reference/fix.md +54 -0
- package/skills/e-code-review/reference/loop.md +43 -0
- package/skills/e-code-review/reference/low.md +57 -0
- package/skills/e-code-review/reference/medium.md +153 -0
- package/skills/e-code-review/reference/xhigh.md +182 -0
- package/skills/e-simplify/SKILL.md +97 -0
- package/skills/fresh-branch/CLAUDE.md +2 -0
- package/skills/fresh-branch/SKILL.md +2 -0
- package/skills/fresh-branch/scripts/create_fresh_branch.py +78 -180
- package/skills/fresh-branch/scripts/fresh_branch_git_commands.py +285 -0
- package/skills/fresh-branch/scripts/fresh_branch_scripts_constants/fresh_branch_cli_constants.py +1 -0
- package/skills/fresh-branch/scripts/pytest.ini +4 -0
- package/skills/fresh-branch/scripts/test_create_fresh_branch.py +98 -0
- package/skills/fresh-branch/scripts/test_fresh_branch_git_commands.py +310 -0
- package/skills/issue-tracker/SKILL.md +92 -0
- package/skills/issue-tracker/reference/epic-and-sub-issue-model.md +55 -0
- package/skills/issue-tracker/reference/handoff-schema.md +64 -0
- package/skills/issue-tracker/reference/operation-matrix.md +41 -0
- package/skills/orchestrator/SKILL.md +162 -21
- package/skills/orchestrator/scripts/status_gate.py +625 -0
- package/skills/orchestrator/scripts/status_gate_constants/__init__.py +1 -0
- package/skills/orchestrator/scripts/status_gate_constants/config/__init__.py +1 -0
- package/skills/orchestrator/scripts/status_gate_constants/config/constants.py +47 -0
- package/skills/orchestrator/scripts/test_status_gate.py +439 -0
- package/skills/orchestrator-refresh/SKILL.md +110 -35
- package/skills/plan-to-pr/SKILL.md +155 -0
- package/skills/plan-to-pr/reference/final-validation-tasks.md +15 -0
- package/skills/plan-to-pr/reference/model-routing.md +36 -0
- package/skills/plan-to-pr/reference/packet-contract.md +43 -0
- package/skills/plan-to-pr/reference/packet-schema.json +57 -0
- package/skills/plan-to-pr/reference/process-inventory.md +22 -0
- package/skills/plan-to-pr/reference/review-loop.md +33 -0
- package/skills/plan-to-pr/reference/run-record.schema.json +27 -0
- package/skills/plan-to-pr/reference/self-audit-tasks.md +15 -0
- package/skills/plan-to-pr/reference/task-seeds.md +14 -0
- package/skills/plan-to-pr/reference/task-ticket.md +38 -0
- package/skills/plan-to-pr/scripts/config/__init__.py +1 -0
- package/skills/plan-to-pr/scripts/config/constants.py +193 -0
- package/skills/plan-to-pr/scripts/create_packet.py +173 -0
- package/skills/plan-to-pr/scripts/test_create_packet.py +102 -0
- package/skills/plan-to-pr/scripts/test_validate_packet.py +256 -0
- package/skills/plan-to-pr/scripts/test_validate_protocol.py +135 -0
- package/skills/plan-to-pr/scripts/test_validate_run.py +158 -0
- package/skills/plan-to-pr/scripts/validate_packet.py +655 -0
- package/skills/plan-to-pr/scripts/validate_protocol.py +622 -0
- package/skills/plan-to-pr/scripts/validate_run.py +173 -0
- package/skills/plan-to-pr/test_skill_contract.py +207 -0
- package/skills/plan-to-pr/test_task_ticket_contract.py +151 -0
- package/skills/pr-converge/SKILL.md +472 -469
- package/skills/pr-converge/reference/examples.md +3 -3
- package/skills/pr-converge/reference/fix-protocol.md +1 -1
- package/skills/pr-converge/reference/ground-rules.md +7 -4
- package/skills/pr-converge/reference/multi-pr-orchestration.md +4 -1
- package/skills/pr-converge/reference/per-tick.md +5 -5
- package/skills/pr-converge/reference/progress-checklist.md +1 -1
- package/skills/pr-converge/scripts/check_convergence_gates.py +279 -279
- package/skills/pr-converge/scripts/test_check_convergence_codex.py +507 -507
- package/skills/pr-converge/scripts/test_check_convergence_gates.py +84 -84
- package/skills/pr-converge/test_step5_host_branch.py +1 -1
- package/skills/pr-fix-protocol/SKILL.md +1 -1
- package/skills/privacy-hygiene/SKILL.md +68 -68
- package/skills/prototype/SKILL.md +86 -0
- package/skills/prototype/reference/honest-limitations.md +23 -0
- package/skills/prototype/reference/promotion-tasks.md +23 -0
- package/skills/prototype/scripts/build_sandbox_settings.py +249 -0
- package/skills/prototype/scripts/conftest.py +15 -0
- package/skills/prototype/scripts/launch_sandbox.py +205 -0
- package/skills/prototype/scripts/probe_sandbox_safety.py +311 -0
- package/skills/prototype/scripts/prototype_scripts_constants/__init__.py +1 -0
- package/skills/prototype/scripts/prototype_scripts_constants/config/__init__.py +0 -0
- package/skills/prototype/scripts/prototype_scripts_constants/config/build_sandbox_settings_constants.py +41 -0
- package/skills/prototype/scripts/prototype_scripts_constants/config/launch_sandbox_constants.py +23 -0
- package/skills/prototype/scripts/prototype_scripts_constants/config/probe_sandbox_safety_constants.py +45 -0
- package/skills/prototype/scripts/prototype_scripts_constants/config/prototype_common_constants.py +10 -0
- package/skills/prototype/scripts/test_build_sandbox_settings.py +275 -0
- package/skills/prototype/scripts/test_launch_sandbox.py +303 -0
- package/skills/prototype/scripts/test_probe_sandbox_safety.py +284 -0
- package/skills/prototype/workflows/promotion.md +27 -0
- package/skills/prototype/workflows/sandbox.md +35 -0
- package/skills/release-notes-html/SKILL.md +164 -0
- package/skills/skill-builder/CLAUDE.md +3 -3
- package/skills/skill-builder/SKILL.md +5 -5
- package/skills/skill-builder/references/CLAUDE.md +1 -1
- package/skills/skill-builder/references/delegation-map.md +3 -3
- package/skills/skill-builder/references/description-field.md +1 -1
- package/skills/skill-builder/references/skill-modularity.md +2 -3
- package/skills/skill-builder/workflows/CLAUDE.md +1 -1
- package/skills/skill-builder/workflows/improve-skill.md +1 -1
- package/skills/skill-builder/workflows/new-skill.md +2 -2
- package/skills/task-build/CLAUDE.md +8 -7
- package/skills/task-build/SKILL.md +16 -8
- package/skills/task-build/reference/tool-routing.md +19 -0
- package/skills/team-advisor/SKILL.md +2 -2
- package/scripts/test_invoke_code_review.py +0 -672
- package/skills/closeout/reference/issue-body-templates.md +0 -108
|
@@ -1,672 +0,0 @@
|
|
|
1
|
-
"""Behavioral tests for the host-aware ``/code-review`` invoker."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import json
|
|
6
|
-
import subprocess
|
|
7
|
-
import sys
|
|
8
|
-
from collections.abc import Sequence
|
|
9
|
-
from dataclasses import dataclass, field
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
import pytest
|
|
13
|
-
|
|
14
|
-
_SCRIPTS_DIR = Path(__file__).resolve().parent
|
|
15
|
-
if str(_SCRIPTS_DIR) not in sys.path:
|
|
16
|
-
sys.path.insert(0, str(_SCRIPTS_DIR))
|
|
17
|
-
|
|
18
|
-
import claude_chain_runner as chain_runner # noqa: E402
|
|
19
|
-
import invoke_code_review as invoker # noqa: E402
|
|
20
|
-
from claude_chain_runner import ( # noqa: E402
|
|
21
|
-
ChainAttempt,
|
|
22
|
-
ChainConfigurationError,
|
|
23
|
-
ChainInvocationOutcome,
|
|
24
|
-
)
|
|
25
|
-
from dev_env_scripts_constants.claude_chain_constants import ( # noqa: E402
|
|
26
|
-
CHAIN_CONFIG_ERROR_EXIT_CODE,
|
|
27
|
-
)
|
|
28
|
-
from dev_env_scripts_constants.code_review_constants import ( # noqa: E402
|
|
29
|
-
CLI_SESSION_MODEL_FLAG,
|
|
30
|
-
CODE_REVIEW_MODEL_ALIAS,
|
|
31
|
-
CODE_REVIEW_PROMPT,
|
|
32
|
-
GIT_BINARY,
|
|
33
|
-
GIT_PORCELAIN_FLAG,
|
|
34
|
-
GIT_STATUS_SUBCOMMAND,
|
|
35
|
-
HOST_PROFILE_ERROR_RETURNCODE,
|
|
36
|
-
IN_SESSION_RETURNCODE,
|
|
37
|
-
MODE_CHAIN,
|
|
38
|
-
MODE_IN_SESSION,
|
|
39
|
-
PERMISSION_MODE_BYPASS,
|
|
40
|
-
PERMISSION_MODE_FLAG,
|
|
41
|
-
RESULT_KEY_DIRTY_TREE,
|
|
42
|
-
RESULT_KEY_MODE,
|
|
43
|
-
RESULT_KEY_RETURNCODE,
|
|
44
|
-
RESULT_KEY_SERVED_COMMAND,
|
|
45
|
-
)
|
|
46
|
-
from dev_env_scripts_constants.grok_worker_constants import ( # noqa: E402
|
|
47
|
-
CLI_TIMEOUT_FLAG,
|
|
48
|
-
CWD_FLAG,
|
|
49
|
-
MODEL_FLAG,
|
|
50
|
-
OUTPUT_FORMAT_FLAG,
|
|
51
|
-
OUTPUT_FORMAT_JSON,
|
|
52
|
-
SINGLE_TURN_FLAG,
|
|
53
|
-
)
|
|
54
|
-
from dev_env_scripts_constants.timing import ( # noqa: E402
|
|
55
|
-
DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
HOST_PROFILE_CLAUDE = "Claude"
|
|
59
|
-
HOST_PROFILE_THIRD_PARTY = "ThirdParty"
|
|
60
|
-
|
|
61
|
-
FIXTURE_SERVED_COMMAND = "claude"
|
|
62
|
-
FIXTURE_CHAIN_RETURNCODE = 0
|
|
63
|
-
FIXTURE_FAILED_RETURNCODE = 1
|
|
64
|
-
FIXTURE_GIT_STATUS_FAILURE_RETURNCODE = 128
|
|
65
|
-
FIXTURE_CHAIN_STDOUT = '{"result":"review done"}'
|
|
66
|
-
FIXTURE_SESSION_OPUS = "opus"
|
|
67
|
-
FIXTURE_SESSION_OPUS_UPPER = "Opus"
|
|
68
|
-
FIXTURE_SESSION_SONNET = "sonnet"
|
|
69
|
-
FIXTURE_SESSION_HAIKU = "haiku"
|
|
70
|
-
FIXTURE_CHAIN_CONFIG_ERROR_MESSAGE = "chain config missing"
|
|
71
|
-
FIXTURE_HOST_PROFILE_ERROR_MESSAGE = "unknown host profile"
|
|
72
|
-
DIRTY_FILE_NAME = "review_fix.txt"
|
|
73
|
-
DIRTY_FILE_CONTENTS = "applied fix\n"
|
|
74
|
-
GIT_INIT_TIMEOUT_SECONDS = 30
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def _claude_served(
|
|
78
|
-
*,
|
|
79
|
-
returncode: int = FIXTURE_CHAIN_RETURNCODE,
|
|
80
|
-
stdout: str = FIXTURE_CHAIN_STDOUT,
|
|
81
|
-
) -> ChainInvocationOutcome:
|
|
82
|
-
return ChainInvocationOutcome(
|
|
83
|
-
served_command=FIXTURE_SERVED_COMMAND,
|
|
84
|
-
returncode=returncode,
|
|
85
|
-
stdout=stdout,
|
|
86
|
-
stderr="",
|
|
87
|
-
attempts=(
|
|
88
|
-
ChainAttempt(command=FIXTURE_SERVED_COMMAND, status="served"),
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def _claude_failed() -> ChainInvocationOutcome:
|
|
94
|
-
return ChainInvocationOutcome(
|
|
95
|
-
served_command=None,
|
|
96
|
-
returncode=FIXTURE_FAILED_RETURNCODE,
|
|
97
|
-
stdout="",
|
|
98
|
-
stderr="chain exhausted",
|
|
99
|
-
attempts=(
|
|
100
|
-
ChainAttempt(command=FIXTURE_SERVED_COMMAND, status="usage_limited"),
|
|
101
|
-
),
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
def _init_git_repository(repository_directory: Path) -> Path:
|
|
106
|
-
repository_directory.mkdir(parents=True, exist_ok=True)
|
|
107
|
-
subprocess.run(
|
|
108
|
-
[GIT_BINARY, "init"],
|
|
109
|
-
cwd=str(repository_directory),
|
|
110
|
-
check=True,
|
|
111
|
-
capture_output=True,
|
|
112
|
-
text=True,
|
|
113
|
-
timeout=GIT_INIT_TIMEOUT_SECONDS,
|
|
114
|
-
)
|
|
115
|
-
subprocess.run(
|
|
116
|
-
[GIT_BINARY, "config", "user.email", "reviewer@example.com"],
|
|
117
|
-
cwd=str(repository_directory),
|
|
118
|
-
check=True,
|
|
119
|
-
capture_output=True,
|
|
120
|
-
text=True,
|
|
121
|
-
timeout=GIT_INIT_TIMEOUT_SECONDS,
|
|
122
|
-
)
|
|
123
|
-
subprocess.run(
|
|
124
|
-
[GIT_BINARY, "config", "user.name", "Reviewer"],
|
|
125
|
-
cwd=str(repository_directory),
|
|
126
|
-
check=True,
|
|
127
|
-
capture_output=True,
|
|
128
|
-
text=True,
|
|
129
|
-
timeout=GIT_INIT_TIMEOUT_SECONDS,
|
|
130
|
-
)
|
|
131
|
-
tracked_file = repository_directory / "README.md"
|
|
132
|
-
tracked_file.write_text("baseline\n", encoding="utf-8")
|
|
133
|
-
subprocess.run(
|
|
134
|
-
[GIT_BINARY, "add", "README.md"],
|
|
135
|
-
cwd=str(repository_directory),
|
|
136
|
-
check=True,
|
|
137
|
-
capture_output=True,
|
|
138
|
-
text=True,
|
|
139
|
-
timeout=GIT_INIT_TIMEOUT_SECONDS,
|
|
140
|
-
)
|
|
141
|
-
subprocess.run(
|
|
142
|
-
[GIT_BINARY, "commit", "-m", "baseline"],
|
|
143
|
-
cwd=str(repository_directory),
|
|
144
|
-
check=True,
|
|
145
|
-
capture_output=True,
|
|
146
|
-
text=True,
|
|
147
|
-
timeout=GIT_INIT_TIMEOUT_SECONDS,
|
|
148
|
-
)
|
|
149
|
-
return repository_directory
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
@dataclass
|
|
153
|
-
class SeamCallLog:
|
|
154
|
-
claude_calls: int = 0
|
|
155
|
-
claude_arguments: list[str] | None = None
|
|
156
|
-
host_profile_calls: int = 0
|
|
157
|
-
is_stdin_empty: bool = False
|
|
158
|
-
claude_working_directory: Path | None = None
|
|
159
|
-
all_observed_working_directories: list[Path] = field(default_factory=list)
|
|
160
|
-
all_git_status_commands: list[list[str]] = field(default_factory=list)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
def _install_seams(
|
|
164
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
165
|
-
*,
|
|
166
|
-
host_profile: str = HOST_PROFILE_CLAUDE,
|
|
167
|
-
claude_outcome: ChainInvocationOutcome | BaseException | None = None,
|
|
168
|
-
should_dirty_tree_on_chain: bool = False,
|
|
169
|
-
working_directory: Path | None = None,
|
|
170
|
-
) -> SeamCallLog:
|
|
171
|
-
call_log = SeamCallLog()
|
|
172
|
-
|
|
173
|
-
def fake_host_profile(
|
|
174
|
-
setting_by_name: object | None = None,
|
|
175
|
-
) -> str:
|
|
176
|
-
del setting_by_name
|
|
177
|
-
call_log.host_profile_calls += 1
|
|
178
|
-
return host_profile
|
|
179
|
-
|
|
180
|
-
def fake_claude(
|
|
181
|
-
all_claude_arguments: list[str], *, timeout_seconds: int
|
|
182
|
-
) -> ChainInvocationOutcome:
|
|
183
|
-
call_log.claude_calls += 1
|
|
184
|
-
call_log.claude_arguments = list(all_claude_arguments)
|
|
185
|
-
chain_runner.chain_subprocess_runner(
|
|
186
|
-
["claude", *all_claude_arguments],
|
|
187
|
-
capture_output=True,
|
|
188
|
-
text=True,
|
|
189
|
-
timeout=timeout_seconds,
|
|
190
|
-
check=False,
|
|
191
|
-
)
|
|
192
|
-
if should_dirty_tree_on_chain and working_directory is not None:
|
|
193
|
-
dirty_file = working_directory / DIRTY_FILE_NAME
|
|
194
|
-
dirty_file.write_text(DIRTY_FILE_CONTENTS, encoding="utf-8")
|
|
195
|
-
if isinstance(claude_outcome, BaseException):
|
|
196
|
-
raise claude_outcome
|
|
197
|
-
assert isinstance(claude_outcome, ChainInvocationOutcome)
|
|
198
|
-
return claude_outcome
|
|
199
|
-
|
|
200
|
-
def _tracking_subprocess_runner(
|
|
201
|
-
all_invocation_tokens: Sequence[str],
|
|
202
|
-
*all_positionals: object,
|
|
203
|
-
**all_keywords: object,
|
|
204
|
-
) -> subprocess.CompletedProcess[str]:
|
|
205
|
-
del all_positionals
|
|
206
|
-
maybe_stdin = all_keywords.get("stdin")
|
|
207
|
-
if maybe_stdin is subprocess.DEVNULL:
|
|
208
|
-
call_log.is_stdin_empty = True
|
|
209
|
-
elif maybe_stdin is not None:
|
|
210
|
-
maybe_read = getattr(maybe_stdin, "read", None)
|
|
211
|
-
if callable(maybe_read):
|
|
212
|
-
call_log.is_stdin_empty = maybe_read() == ""
|
|
213
|
-
maybe_seek = getattr(maybe_stdin, "seek", None)
|
|
214
|
-
if callable(maybe_seek):
|
|
215
|
-
maybe_seek(0)
|
|
216
|
-
maybe_cwd = all_keywords.get("cwd")
|
|
217
|
-
if maybe_cwd is not None:
|
|
218
|
-
resolved_directory = Path(str(maybe_cwd))
|
|
219
|
-
call_log.claude_working_directory = resolved_directory
|
|
220
|
-
call_log.all_observed_working_directories.append(resolved_directory)
|
|
221
|
-
return subprocess.CompletedProcess(
|
|
222
|
-
args=list(all_invocation_tokens),
|
|
223
|
-
returncode=0,
|
|
224
|
-
stdout="{}",
|
|
225
|
-
stderr="",
|
|
226
|
-
)
|
|
227
|
-
|
|
228
|
-
monkeypatch.setattr(invoker, "review_host_profile_detector", fake_host_profile)
|
|
229
|
-
monkeypatch.setattr(invoker, "review_claude_runner", fake_claude)
|
|
230
|
-
monkeypatch.setattr(
|
|
231
|
-
chain_runner, "chain_subprocess_runner", _tracking_subprocess_runner
|
|
232
|
-
)
|
|
233
|
-
return call_log
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
@pytest.mark.parametrize(
|
|
237
|
-
("host_profile", "session_model", "expected_mode"),
|
|
238
|
-
[
|
|
239
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_OPUS, MODE_IN_SESSION),
|
|
240
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_OPUS_UPPER, MODE_IN_SESSION),
|
|
241
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_SONNET, MODE_CHAIN),
|
|
242
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_HAIKU, MODE_CHAIN),
|
|
243
|
-
(HOST_PROFILE_THIRD_PARTY, FIXTURE_SESSION_OPUS, MODE_CHAIN),
|
|
244
|
-
(HOST_PROFILE_THIRD_PARTY, FIXTURE_SESSION_SONNET, MODE_CHAIN),
|
|
245
|
-
],
|
|
246
|
-
)
|
|
247
|
-
def test_mode_decision_host_and_model_matrix(
|
|
248
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
249
|
-
tmp_path: Path,
|
|
250
|
-
host_profile: str,
|
|
251
|
-
session_model: str,
|
|
252
|
-
expected_mode: str,
|
|
253
|
-
) -> None:
|
|
254
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
255
|
-
claude_outcome = _claude_served() if expected_mode == MODE_CHAIN else None
|
|
256
|
-
call_log = _install_seams(
|
|
257
|
-
monkeypatch,
|
|
258
|
-
host_profile=host_profile,
|
|
259
|
-
claude_outcome=claude_outcome,
|
|
260
|
-
working_directory=working_directory,
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
review_outcome = invoker.invoke_code_review(
|
|
264
|
-
working_directory=working_directory,
|
|
265
|
-
session_model=session_model,
|
|
266
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
assert review_outcome.mode == expected_mode
|
|
270
|
-
assert call_log.host_profile_calls == 1
|
|
271
|
-
if expected_mode == MODE_IN_SESSION:
|
|
272
|
-
assert call_log.claude_calls == 0
|
|
273
|
-
assert review_outcome.served_command is None
|
|
274
|
-
assert review_outcome.returncode == IN_SESSION_RETURNCODE
|
|
275
|
-
assert review_outcome.is_dirty_tree is False
|
|
276
|
-
else:
|
|
277
|
-
assert call_log.claude_calls == 1
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
def test_chain_argv_assembly(
|
|
281
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
282
|
-
) -> None:
|
|
283
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
284
|
-
call_log = _install_seams(
|
|
285
|
-
monkeypatch,
|
|
286
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
287
|
-
claude_outcome=_claude_served(),
|
|
288
|
-
working_directory=working_directory,
|
|
289
|
-
)
|
|
290
|
-
|
|
291
|
-
invoker.invoke_code_review(
|
|
292
|
-
working_directory=working_directory,
|
|
293
|
-
session_model=FIXTURE_SESSION_SONNET,
|
|
294
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
295
|
-
)
|
|
296
|
-
|
|
297
|
-
assert call_log.claude_arguments == [
|
|
298
|
-
SINGLE_TURN_FLAG,
|
|
299
|
-
CODE_REVIEW_PROMPT,
|
|
300
|
-
MODEL_FLAG,
|
|
301
|
-
CODE_REVIEW_MODEL_ALIAS,
|
|
302
|
-
OUTPUT_FORMAT_FLAG,
|
|
303
|
-
OUTPUT_FORMAT_JSON,
|
|
304
|
-
PERMISSION_MODE_FLAG,
|
|
305
|
-
PERMISSION_MODE_BYPASS,
|
|
306
|
-
]
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
def test_chain_redirects_empty_stdin_and_sets_cwd(
|
|
310
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
311
|
-
) -> None:
|
|
312
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
313
|
-
call_log = _install_seams(
|
|
314
|
-
monkeypatch,
|
|
315
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
316
|
-
claude_outcome=_claude_served(),
|
|
317
|
-
working_directory=working_directory,
|
|
318
|
-
)
|
|
319
|
-
|
|
320
|
-
invoker.invoke_code_review(
|
|
321
|
-
working_directory=working_directory,
|
|
322
|
-
session_model=FIXTURE_SESSION_OPUS,
|
|
323
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
324
|
-
)
|
|
325
|
-
|
|
326
|
-
assert call_log.is_stdin_empty is True
|
|
327
|
-
assert call_log.claude_working_directory == working_directory
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
def test_dirty_tree_true_after_chain_writes_file(
|
|
331
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
332
|
-
) -> None:
|
|
333
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
334
|
-
_install_seams(
|
|
335
|
-
monkeypatch,
|
|
336
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
337
|
-
claude_outcome=_claude_served(),
|
|
338
|
-
should_dirty_tree_on_chain=True,
|
|
339
|
-
working_directory=working_directory,
|
|
340
|
-
)
|
|
341
|
-
|
|
342
|
-
review_outcome = invoker.invoke_code_review(
|
|
343
|
-
working_directory=working_directory,
|
|
344
|
-
session_model=FIXTURE_SESSION_OPUS,
|
|
345
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
346
|
-
)
|
|
347
|
-
|
|
348
|
-
assert review_outcome.mode == MODE_CHAIN
|
|
349
|
-
assert review_outcome.is_dirty_tree is True
|
|
350
|
-
assert review_outcome.served_command == FIXTURE_SERVED_COMMAND
|
|
351
|
-
assert review_outcome.returncode == FIXTURE_CHAIN_RETURNCODE
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
def test_dirty_tree_false_when_chain_leaves_tree_clean(
|
|
355
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
356
|
-
) -> None:
|
|
357
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
358
|
-
_install_seams(
|
|
359
|
-
monkeypatch,
|
|
360
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
361
|
-
claude_outcome=_claude_served(),
|
|
362
|
-
should_dirty_tree_on_chain=False,
|
|
363
|
-
working_directory=working_directory,
|
|
364
|
-
)
|
|
365
|
-
|
|
366
|
-
review_outcome = invoker.invoke_code_review(
|
|
367
|
-
working_directory=working_directory,
|
|
368
|
-
session_model=FIXTURE_SESSION_OPUS,
|
|
369
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
370
|
-
)
|
|
371
|
-
|
|
372
|
-
assert review_outcome.is_dirty_tree is False
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
def test_cli_prints_result_json_only(
|
|
376
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
377
|
-
tmp_path: Path,
|
|
378
|
-
capsys: pytest.CaptureFixture[str],
|
|
379
|
-
) -> None:
|
|
380
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
381
|
-
_install_seams(
|
|
382
|
-
monkeypatch,
|
|
383
|
-
host_profile=HOST_PROFILE_CLAUDE,
|
|
384
|
-
claude_outcome=None,
|
|
385
|
-
working_directory=working_directory,
|
|
386
|
-
)
|
|
387
|
-
|
|
388
|
-
exit_code = invoker.main(
|
|
389
|
-
[
|
|
390
|
-
CWD_FLAG,
|
|
391
|
-
str(working_directory),
|
|
392
|
-
CLI_SESSION_MODEL_FLAG,
|
|
393
|
-
FIXTURE_SESSION_OPUS,
|
|
394
|
-
CLI_TIMEOUT_FLAG,
|
|
395
|
-
str(DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS),
|
|
396
|
-
]
|
|
397
|
-
)
|
|
398
|
-
|
|
399
|
-
assert exit_code == IN_SESSION_RETURNCODE
|
|
400
|
-
captured = capsys.readouterr()
|
|
401
|
-
assert captured.err == ""
|
|
402
|
-
parsed_payload = json.loads(captured.out)
|
|
403
|
-
assert parsed_payload == {
|
|
404
|
-
RESULT_KEY_MODE: MODE_IN_SESSION,
|
|
405
|
-
RESULT_KEY_SERVED_COMMAND: None,
|
|
406
|
-
RESULT_KEY_RETURNCODE: IN_SESSION_RETURNCODE,
|
|
407
|
-
RESULT_KEY_DIRTY_TREE: False,
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
def test_build_code_review_arguments_matches_contract() -> None:
|
|
412
|
-
all_arguments = invoker.build_code_review_arguments()
|
|
413
|
-
assert all_arguments == [
|
|
414
|
-
SINGLE_TURN_FLAG,
|
|
415
|
-
CODE_REVIEW_PROMPT,
|
|
416
|
-
MODEL_FLAG,
|
|
417
|
-
CODE_REVIEW_MODEL_ALIAS,
|
|
418
|
-
OUTPUT_FORMAT_FLAG,
|
|
419
|
-
OUTPUT_FORMAT_JSON,
|
|
420
|
-
PERMISSION_MODE_FLAG,
|
|
421
|
-
PERMISSION_MODE_BYPASS,
|
|
422
|
-
]
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
def test_is_working_tree_dirty_against_real_git_repo(tmp_path: Path) -> None:
|
|
426
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
427
|
-
assert invoker.is_working_tree_dirty(working_directory) is False
|
|
428
|
-
(working_directory / DIRTY_FILE_NAME).write_text(
|
|
429
|
-
DIRTY_FILE_CONTENTS, encoding="utf-8"
|
|
430
|
-
)
|
|
431
|
-
assert invoker.is_working_tree_dirty(working_directory) is True
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
def test_git_status_command_uses_porcelain(
|
|
435
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
436
|
-
) -> None:
|
|
437
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
438
|
-
all_commands: list[list[str]] = []
|
|
439
|
-
|
|
440
|
-
def fake_git_status(
|
|
441
|
-
all_command_tokens: Sequence[str],
|
|
442
|
-
*all_positionals: object,
|
|
443
|
-
**all_keywords: object,
|
|
444
|
-
) -> subprocess.CompletedProcess[str]:
|
|
445
|
-
del all_positionals, all_keywords
|
|
446
|
-
all_commands.append(list(all_command_tokens))
|
|
447
|
-
return subprocess.CompletedProcess(
|
|
448
|
-
args=list(all_command_tokens),
|
|
449
|
-
returncode=0,
|
|
450
|
-
stdout="",
|
|
451
|
-
stderr="",
|
|
452
|
-
)
|
|
453
|
-
|
|
454
|
-
monkeypatch.setattr(invoker, "review_git_status_runner", fake_git_status)
|
|
455
|
-
invoker.is_working_tree_dirty(working_directory)
|
|
456
|
-
assert all_commands == [
|
|
457
|
-
[GIT_BINARY, GIT_STATUS_SUBCOMMAND, GIT_PORCELAIN_FLAG]
|
|
458
|
-
]
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
def test_chain_failure_preserves_returncode(
|
|
462
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
463
|
-
) -> None:
|
|
464
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
465
|
-
_install_seams(
|
|
466
|
-
monkeypatch,
|
|
467
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
468
|
-
claude_outcome=_claude_failed(),
|
|
469
|
-
working_directory=working_directory,
|
|
470
|
-
)
|
|
471
|
-
|
|
472
|
-
review_outcome = invoker.invoke_code_review(
|
|
473
|
-
working_directory=working_directory,
|
|
474
|
-
session_model=FIXTURE_SESSION_OPUS,
|
|
475
|
-
timeout_seconds=DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS,
|
|
476
|
-
)
|
|
477
|
-
|
|
478
|
-
assert review_outcome.mode == MODE_CHAIN
|
|
479
|
-
assert review_outcome.served_command is None
|
|
480
|
-
assert review_outcome.returncode == FIXTURE_FAILED_RETURNCODE
|
|
481
|
-
assert review_outcome.is_dirty_tree is False
|
|
482
|
-
assert invoker.is_successful_code_review(review_outcome) is False
|
|
483
|
-
assert invoker.is_code_review_clean_stamp_allowed(review_outcome) is False
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
def test_is_working_tree_dirty_nonzero_returncode_is_not_clean(
|
|
487
|
-
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
488
|
-
) -> None:
|
|
489
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
490
|
-
|
|
491
|
-
def fake_git_status(
|
|
492
|
-
all_command_tokens: Sequence[str],
|
|
493
|
-
*all_positionals: object,
|
|
494
|
-
**all_keywords: object,
|
|
495
|
-
) -> subprocess.CompletedProcess[str]:
|
|
496
|
-
del all_positionals, all_keywords
|
|
497
|
-
return subprocess.CompletedProcess(
|
|
498
|
-
args=list(all_command_tokens),
|
|
499
|
-
returncode=FIXTURE_GIT_STATUS_FAILURE_RETURNCODE,
|
|
500
|
-
stdout="",
|
|
501
|
-
stderr="fatal: not a git repository",
|
|
502
|
-
)
|
|
503
|
-
|
|
504
|
-
monkeypatch.setattr(invoker, "review_git_status_runner", fake_git_status)
|
|
505
|
-
assert invoker.is_working_tree_dirty(working_directory) is True
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
def test_cli_emits_json_on_chain_configuration_error(
|
|
509
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
510
|
-
tmp_path: Path,
|
|
511
|
-
capsys: pytest.CaptureFixture[str],
|
|
512
|
-
) -> None:
|
|
513
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
514
|
-
_install_seams(
|
|
515
|
-
monkeypatch,
|
|
516
|
-
host_profile=HOST_PROFILE_THIRD_PARTY,
|
|
517
|
-
claude_outcome=ChainConfigurationError(FIXTURE_CHAIN_CONFIG_ERROR_MESSAGE),
|
|
518
|
-
working_directory=working_directory,
|
|
519
|
-
)
|
|
520
|
-
|
|
521
|
-
exit_code = invoker.main(
|
|
522
|
-
[
|
|
523
|
-
CWD_FLAG,
|
|
524
|
-
str(working_directory),
|
|
525
|
-
CLI_SESSION_MODEL_FLAG,
|
|
526
|
-
FIXTURE_SESSION_OPUS,
|
|
527
|
-
CLI_TIMEOUT_FLAG,
|
|
528
|
-
str(DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS),
|
|
529
|
-
]
|
|
530
|
-
)
|
|
531
|
-
|
|
532
|
-
assert exit_code == CHAIN_CONFIG_ERROR_EXIT_CODE
|
|
533
|
-
captured = capsys.readouterr()
|
|
534
|
-
parsed_payload = json.loads(captured.out)
|
|
535
|
-
assert parsed_payload == {
|
|
536
|
-
RESULT_KEY_MODE: MODE_CHAIN,
|
|
537
|
-
RESULT_KEY_SERVED_COMMAND: None,
|
|
538
|
-
RESULT_KEY_RETURNCODE: CHAIN_CONFIG_ERROR_EXIT_CODE,
|
|
539
|
-
RESULT_KEY_DIRTY_TREE: False,
|
|
540
|
-
}
|
|
541
|
-
assert invoker.is_code_review_clean_stamp_allowed(
|
|
542
|
-
invoker.CodeReviewOutcome(
|
|
543
|
-
mode=MODE_CHAIN,
|
|
544
|
-
served_command=None,
|
|
545
|
-
returncode=CHAIN_CONFIG_ERROR_EXIT_CODE,
|
|
546
|
-
is_dirty_tree=False,
|
|
547
|
-
)
|
|
548
|
-
) is False
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
def test_cli_emits_json_on_host_profile_value_error(
|
|
552
|
-
monkeypatch: pytest.MonkeyPatch,
|
|
553
|
-
tmp_path: Path,
|
|
554
|
-
capsys: pytest.CaptureFixture[str],
|
|
555
|
-
) -> None:
|
|
556
|
-
working_directory = _init_git_repository(tmp_path / "repo")
|
|
557
|
-
|
|
558
|
-
def fake_host_profile_raises(
|
|
559
|
-
setting_by_name: object | None = None,
|
|
560
|
-
) -> str:
|
|
561
|
-
del setting_by_name
|
|
562
|
-
raise ValueError(FIXTURE_HOST_PROFILE_ERROR_MESSAGE)
|
|
563
|
-
|
|
564
|
-
monkeypatch.setattr(
|
|
565
|
-
invoker, "review_host_profile_detector", fake_host_profile_raises
|
|
566
|
-
)
|
|
567
|
-
|
|
568
|
-
exit_code = invoker.main(
|
|
569
|
-
[
|
|
570
|
-
CWD_FLAG,
|
|
571
|
-
str(working_directory),
|
|
572
|
-
CLI_SESSION_MODEL_FLAG,
|
|
573
|
-
FIXTURE_SESSION_OPUS,
|
|
574
|
-
CLI_TIMEOUT_FLAG,
|
|
575
|
-
str(DEFAULT_CODE_REVIEW_TIMEOUT_SECONDS),
|
|
576
|
-
]
|
|
577
|
-
)
|
|
578
|
-
|
|
579
|
-
assert exit_code == HOST_PROFILE_ERROR_RETURNCODE
|
|
580
|
-
captured = capsys.readouterr()
|
|
581
|
-
parsed_payload = json.loads(captured.out)
|
|
582
|
-
assert parsed_payload == {
|
|
583
|
-
RESULT_KEY_MODE: MODE_CHAIN,
|
|
584
|
-
RESULT_KEY_SERVED_COMMAND: None,
|
|
585
|
-
RESULT_KEY_RETURNCODE: HOST_PROFILE_ERROR_RETURNCODE,
|
|
586
|
-
RESULT_KEY_DIRTY_TREE: False,
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
def test_clean_stamp_allowed_only_on_successful_clean_serve() -> None:
|
|
591
|
-
clean_success = invoker.CodeReviewOutcome(
|
|
592
|
-
mode=MODE_CHAIN,
|
|
593
|
-
served_command=FIXTURE_SERVED_COMMAND,
|
|
594
|
-
returncode=FIXTURE_CHAIN_RETURNCODE,
|
|
595
|
-
is_dirty_tree=False,
|
|
596
|
-
)
|
|
597
|
-
dirty_success = invoker.CodeReviewOutcome(
|
|
598
|
-
mode=MODE_CHAIN,
|
|
599
|
-
served_command=FIXTURE_SERVED_COMMAND,
|
|
600
|
-
returncode=FIXTURE_CHAIN_RETURNCODE,
|
|
601
|
-
is_dirty_tree=True,
|
|
602
|
-
)
|
|
603
|
-
failed_serve = invoker.CodeReviewOutcome(
|
|
604
|
-
mode=MODE_CHAIN,
|
|
605
|
-
served_command=None,
|
|
606
|
-
returncode=FIXTURE_FAILED_RETURNCODE,
|
|
607
|
-
is_dirty_tree=False,
|
|
608
|
-
)
|
|
609
|
-
in_session_ready = invoker.CodeReviewOutcome(
|
|
610
|
-
mode=MODE_IN_SESSION,
|
|
611
|
-
served_command=None,
|
|
612
|
-
returncode=IN_SESSION_RETURNCODE,
|
|
613
|
-
is_dirty_tree=False,
|
|
614
|
-
)
|
|
615
|
-
|
|
616
|
-
assert invoker.is_code_review_clean_stamp_allowed(clean_success) is True
|
|
617
|
-
assert invoker.is_code_review_clean_stamp_allowed(dirty_success) is False
|
|
618
|
-
assert invoker.is_code_review_clean_stamp_allowed(failed_serve) is False
|
|
619
|
-
assert invoker.is_code_review_clean_stamp_allowed(in_session_ready) is True
|
|
620
|
-
assert invoker.is_successful_code_review(failed_serve) is False
|
|
621
|
-
assert invoker.is_successful_code_review(clean_success) is True
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
@pytest.mark.parametrize(
|
|
625
|
-
("session_model", "expected_is_opus"),
|
|
626
|
-
[
|
|
627
|
-
(FIXTURE_SESSION_OPUS, True),
|
|
628
|
-
(FIXTURE_SESSION_OPUS_UPPER, True),
|
|
629
|
-
(FIXTURE_SESSION_SONNET, False),
|
|
630
|
-
(" opus ", True),
|
|
631
|
-
],
|
|
632
|
-
)
|
|
633
|
-
def test_is_opus_session_model(
|
|
634
|
-
session_model: str, expected_is_opus: bool
|
|
635
|
-
) -> None:
|
|
636
|
-
assert invoker.is_opus_session_model(session_model) is expected_is_opus
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
@pytest.mark.parametrize(
|
|
640
|
-
("host_profile", "session_model", "expected_mode"),
|
|
641
|
-
[
|
|
642
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_OPUS, MODE_IN_SESSION),
|
|
643
|
-
(HOST_PROFILE_CLAUDE, FIXTURE_SESSION_SONNET, MODE_CHAIN),
|
|
644
|
-
(HOST_PROFILE_THIRD_PARTY, FIXTURE_SESSION_OPUS, MODE_CHAIN),
|
|
645
|
-
],
|
|
646
|
-
)
|
|
647
|
-
def test_decide_review_mode(
|
|
648
|
-
host_profile: str, session_model: str, expected_mode: str
|
|
649
|
-
) -> None:
|
|
650
|
-
assert (
|
|
651
|
-
invoker.decide_review_mode(
|
|
652
|
-
host_profile=host_profile,
|
|
653
|
-
session_model=session_model,
|
|
654
|
-
)
|
|
655
|
-
== expected_mode
|
|
656
|
-
)
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
def test_encode_code_review_outcome_shape() -> None:
|
|
660
|
-
review_outcome = invoker.CodeReviewOutcome(
|
|
661
|
-
mode=MODE_CHAIN,
|
|
662
|
-
served_command=FIXTURE_SERVED_COMMAND,
|
|
663
|
-
returncode=FIXTURE_CHAIN_RETURNCODE,
|
|
664
|
-
is_dirty_tree=True,
|
|
665
|
-
)
|
|
666
|
-
encoded_payload = invoker.encode_code_review_outcome(review_outcome)
|
|
667
|
-
assert encoded_payload == {
|
|
668
|
-
RESULT_KEY_MODE: MODE_CHAIN,
|
|
669
|
-
RESULT_KEY_SERVED_COMMAND: FIXTURE_SERVED_COMMAND,
|
|
670
|
-
RESULT_KEY_RETURNCODE: FIXTURE_CHAIN_RETURNCODE,
|
|
671
|
-
RESULT_KEY_DIRTY_TREE: True,
|
|
672
|
-
}
|