Coverage for src/orchestration/run_config.py: 67%

1"""Run configuration builders for MalaOrchestrator.

2

3 This module contains helper functions for building run configuration

4 objects used during orchestrator execution.

5"""

6

7 from __future__ import annotations

8

9 from typing import TYPE_CHECKING

10

11 from src.core.protocols import EventRunConfig

12 from src.infra.io.log_output.run_metadata import RunConfig, RunMetadata

13

14 if TYPE_CHECKING:

15 from pathlib import Path

16

17

18 def build_event_run_config(

19 repo_path: Path,

20 max_agents: int | None,

21 timeout_seconds: int | None,

22 max_issues: int | None,

23 max_gate_retries: int,

24 max_review_retries: int,

25 epic_id: str | None,

26 only_ids: set[str] | None,

27 braintrust_enabled: bool,

28 review_enabled: bool,

29 review_disabled_reason: str | None,

30 prioritize_wip: bool,

31 orphans_only: bool,

32 cli_args: dict[str, object] | None,

33 braintrust_disabled_reason: str | None,

34) -> EventRunConfig:

35 """Build EventRunConfig for on_run_started event.

36

37 Args:

38 repo_path: Path to the repository.

39 max_agents: Maximum concurrent agents.

40 timeout_seconds: Timeout per agent in seconds.

41 max_issues: Maximum issues to process.

42 max_gate_retries: Maximum quality gate retry attempts.

43 max_review_retries: Maximum code review retry attempts.

44 epic_id: Epic ID filter.

45 only_ids: Set of issue IDs to process exclusively.

46 braintrust_enabled: Whether Braintrust tracing is enabled.

47 review_enabled: Whether code review is enabled.

48 review_disabled_reason: Reason review is disabled (if any).

49 prioritize_wip: Whether to prioritize in-progress issues.

50 orphans_only: Whether to only process issues without parent epic.

51 cli_args: CLI arguments for logging.

52 braintrust_disabled_reason: Pre-computed reason braintrust is disabled (if any).

53

54 Returns:

55 EventRunConfig for the run.

56 """

57 return EventRunConfig(

58 repo_path=str(repo_path),

59 max_agents=max_agents,

60 timeout_minutes=timeout_seconds // 60 if timeout_seconds else None,

61 max_issues=max_issues,

62 max_gate_retries=max_gate_retries,

63 max_review_retries=max_review_retries,

64 epic_id=epic_id,

65 only_ids=list(only_ids) if only_ids else None,

66 braintrust_enabled=braintrust_enabled,

67 braintrust_disabled_reason=braintrust_disabled_reason,

68 review_enabled=review_enabled,

69 review_disabled_reason=review_disabled_reason,

70 prioritize_wip=prioritize_wip,

71 orphans_only=orphans_only,

72 cli_args=cli_args,

73 )

74

75

76 def build_run_metadata(

77 repo_path: Path,

78 max_agents: int | None,

79 timeout_seconds: int | None,

80 max_issues: int | None,

81 epic_id: str | None,

82 only_ids: set[str] | None,

83 braintrust_enabled: bool,

84 max_gate_retries: int,

85 max_review_retries: int,

86 review_enabled: bool,

87 orphans_only: bool,

88 cli_args: dict[str, object] | None,

89 version: str,

90) -> RunMetadata:

91 """Create run metadata tracker with current configuration.

92

93 Args:

94 repo_path: Path to the repository.

95 max_agents: Maximum concurrent agents.

96 timeout_seconds: Timeout per agent in seconds.

97 max_issues: Maximum issues to process.

98 epic_id: Epic ID filter.

99 only_ids: Set of issue IDs to process exclusively.

100 braintrust_enabled: Whether Braintrust tracing is enabled.

101 max_gate_retries: Maximum quality gate retry attempts.

102 max_review_retries: Maximum code review retry attempts.

103 review_enabled: Whether code review is enabled.

104 orphans_only: Whether to only process issues without parent epic.

105 cli_args: CLI arguments for logging.

106 version: Mala version string.

107

108 Returns:

109 RunMetadata instance for the run.

110 """

111 run_config = RunConfig(

112 max_agents=max_agents,

113 timeout_minutes=timeout_seconds // 60 if timeout_seconds else None,

114 max_issues=max_issues,

115 epic_id=epic_id,

116 only_ids=list(only_ids) if only_ids else None,

117 braintrust_enabled=braintrust_enabled,

118 max_gate_retries=max_gate_retries,

119 max_review_retries=max_review_retries,

120 review_enabled=review_enabled,

121 orphans_only=orphans_only,

122 cli_args=cli_args,

123 )

124 return RunMetadata(repo_path, run_config, version)