hackbot-runtime 0.1.0__py3-none-any.whl
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.
- hackbot_runtime/__init__.py +24 -0
- hackbot_runtime/actions/__init__.py +41 -0
- hackbot_runtime/actions/action_records.py +51 -0
- hackbot_runtime/actions/agents.py +55 -0
- hackbot_runtime/actions/bugzilla.py +232 -0
- hackbot_runtime/actions/claude_sdk.py +49 -0
- hackbot_runtime/actions/email.py +152 -0
- hackbot_runtime/actions/feedback.py +60 -0
- hackbot_runtime/actions/github.py +208 -0
- hackbot_runtime/actions/mcp_server.py +39 -0
- hackbot_runtime/actions/phabricator.py +234 -0
- hackbot_runtime/actions/recorder.py +146 -0
- hackbot_runtime/actions/slack.py +101 -0
- hackbot_runtime/actions/testrail.py +206 -0
- hackbot_runtime/actions/tools.py +46 -0
- hackbot_runtime/actions/try_server.py +166 -0
- hackbot_runtime/artifacts.py +89 -0
- hackbot_runtime/changes.py +431 -0
- hackbot_runtime/claude.py +96 -0
- hackbot_runtime/codex.py +366 -0
- hackbot_runtime/config.py +82 -0
- hackbot_runtime/context.py +362 -0
- hackbot_runtime/errors.py +7 -0
- hackbot_runtime/providers.py +46 -0
- hackbot_runtime/pull_request.py +130 -0
- hackbot_runtime/results.py +13 -0
- hackbot_runtime/revision.py +238 -0
- hackbot_runtime/runtime.py +244 -0
- hackbot_runtime/searchfox.py +182 -0
- hackbot_runtime/slack_kit.py +51 -0
- hackbot_runtime/source.py +157 -0
- hackbot_runtime/tracing.py +230 -0
- hackbot_runtime/transcript.py +61 -0
- hackbot_runtime/uploader.py +76 -0
- hackbot_runtime/wif.py +359 -0
- hackbot_runtime-0.1.0.dist-info/METADATA +25 -0
- hackbot_runtime-0.1.0.dist-info/RECORD +38 -0
- hackbot_runtime-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Slack-domain recordable actions.
|
|
2
|
+
|
|
3
|
+
An agent -- or the deterministic code around it, via :func:`record_message` --
|
|
4
|
+
records a message it wants delivered to a Slack channel; the apply side posts it
|
|
5
|
+
with ``chat.postMessage`` (see ``handlers/slack_handler.py``). Nothing is sent
|
|
6
|
+
during the run, so a notification gets the same properties as every other
|
|
7
|
+
action: it is visible in the UI before it lands, it is applied at most once
|
|
8
|
+
(an already-applied row is never reposted, so a redelivered completion event
|
|
9
|
+
cannot double-post), and its text may reference an earlier action's apply-time
|
|
10
|
+
result through ``{{actions.<action_id>.<field>}}`` -- e.g. the URL of a bug comment
|
|
11
|
+
this run posted.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from typing import Annotated
|
|
15
|
+
|
|
16
|
+
from agent_tools.registry import ToolError, tool, tools_in
|
|
17
|
+
from pydantic import Field
|
|
18
|
+
|
|
19
|
+
from hackbot_runtime.actions.recorder import ActionsRecorder, confirmation
|
|
20
|
+
|
|
21
|
+
ACTION_TYPE = "slack.post_message"
|
|
22
|
+
HACKBOT_UI_URL = "https://hackbot.moz.tools"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _params(
|
|
26
|
+
channel: str,
|
|
27
|
+
text: str | None,
|
|
28
|
+
blocks: list[dict] | None = None,
|
|
29
|
+
unfurl: bool = False,
|
|
30
|
+
) -> dict[str, str | bool | list[dict]]:
|
|
31
|
+
if not channel:
|
|
32
|
+
raise ToolError("channel must not be blank")
|
|
33
|
+
if not text and not blocks:
|
|
34
|
+
raise ToolError("either 'text' or 'blocks' must be provided")
|
|
35
|
+
|
|
36
|
+
params: dict[str, str | bool | list[dict]] = {"channel": channel, "text": text}
|
|
37
|
+
|
|
38
|
+
if blocks:
|
|
39
|
+
params["blocks"] = blocks
|
|
40
|
+
|
|
41
|
+
if unfurl:
|
|
42
|
+
params["unfurl_links"] = True
|
|
43
|
+
params["unfurl_media"] = True
|
|
44
|
+
|
|
45
|
+
return params
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@tool
|
|
49
|
+
async def post_message(
|
|
50
|
+
recorder: ActionsRecorder,
|
|
51
|
+
channel: Annotated[
|
|
52
|
+
str,
|
|
53
|
+
Field(
|
|
54
|
+
description=(
|
|
55
|
+
'Where to post: a Slack channel ("#example-channel") or a channel ID.'
|
|
56
|
+
)
|
|
57
|
+
),
|
|
58
|
+
],
|
|
59
|
+
text: Annotated[
|
|
60
|
+
str,
|
|
61
|
+
Field(
|
|
62
|
+
description=(
|
|
63
|
+
"Message body in Slack mrkdwn: *bold*, `code`, and <url|label> for "
|
|
64
|
+
"links. Keep it to the few lines the channel needs, with links out "
|
|
65
|
+
"for detail."
|
|
66
|
+
)
|
|
67
|
+
),
|
|
68
|
+
],
|
|
69
|
+
reasoning: Annotated[
|
|
70
|
+
str,
|
|
71
|
+
Field(description="Why this channel needs to hear about it (for audit log)."),
|
|
72
|
+
],
|
|
73
|
+
) -> str:
|
|
74
|
+
"""Record an intended Slack message.
|
|
75
|
+
|
|
76
|
+
Recorded into the run summary for human review -- does not post to Slack.
|
|
77
|
+
"""
|
|
78
|
+
action = recorder.record(ACTION_TYPE, _params(channel, text), reasoning=reasoning)
|
|
79
|
+
return confirmation(action)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def record_message(
|
|
83
|
+
recorder: ActionsRecorder,
|
|
84
|
+
channel: str,
|
|
85
|
+
text: str | None = None,
|
|
86
|
+
blocks: list[dict] | None = None,
|
|
87
|
+
*,
|
|
88
|
+
unfurl: bool = False,
|
|
89
|
+
) -> dict:
|
|
90
|
+
"""Record a notification the agent was never asked to decide on.
|
|
91
|
+
|
|
92
|
+
For a run whose outcome is always worth reporting: the wording is code, not
|
|
93
|
+
a model turn, and the message is recorded once the result exists.
|
|
94
|
+
|
|
95
|
+
``unfurl`` turns Slack's previews back on, recorded as its link and media
|
|
96
|
+
flags separately.
|
|
97
|
+
"""
|
|
98
|
+
return recorder.record(ACTION_TYPE, _params(channel, text, blocks, unfurl))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
TOOLS = tools_in(__name__)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""TestRail recordable actions."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated, Any, Literal
|
|
4
|
+
|
|
5
|
+
from agent_tools.registry import ToolError, tool, tools_in
|
|
6
|
+
from pydantic import (
|
|
7
|
+
BaseModel,
|
|
8
|
+
Field,
|
|
9
|
+
ValidationError,
|
|
10
|
+
field_validator,
|
|
11
|
+
model_validator,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from hackbot_runtime.actions.recorder import ActionsRecorder, confirmation
|
|
15
|
+
|
|
16
|
+
ACTION_TYPE = "testrail.submit_test_plan"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TestRailStepInput(BaseModel):
|
|
20
|
+
action: Annotated[str, Field(description="Test step action.")]
|
|
21
|
+
expectation: Annotated[
|
|
22
|
+
str | None,
|
|
23
|
+
Field(
|
|
24
|
+
description=("Expected result for this step."),
|
|
25
|
+
),
|
|
26
|
+
] = None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class TestRailCaseResultInput(BaseModel):
|
|
30
|
+
status: Literal["passed", "failed", "unsuitable"]
|
|
31
|
+
summary: str
|
|
32
|
+
failure_reason: Annotated[
|
|
33
|
+
str | None,
|
|
34
|
+
Field(
|
|
35
|
+
description="Required when status is failed or unsuitable.",
|
|
36
|
+
),
|
|
37
|
+
] = None
|
|
38
|
+
|
|
39
|
+
@model_validator(mode="after")
|
|
40
|
+
def failure_reason_required_for_non_passing_cases(
|
|
41
|
+
self,
|
|
42
|
+
) -> TestRailCaseResultInput:
|
|
43
|
+
if self.status in {"failed", "unsuitable"} and not self.failure_reason:
|
|
44
|
+
raise ValueError("failed or unsuitable cases must include failure_reason")
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class TestRailCaseInput(BaseModel):
|
|
49
|
+
id: int
|
|
50
|
+
title: Annotated[str, Field(description="TestRail test case title.")]
|
|
51
|
+
preconditions: Annotated[
|
|
52
|
+
str | None,
|
|
53
|
+
Field(
|
|
54
|
+
description="Optional setup required before running this case.",
|
|
55
|
+
),
|
|
56
|
+
] = None
|
|
57
|
+
steps: Annotated[
|
|
58
|
+
list[TestRailStepInput],
|
|
59
|
+
Field(
|
|
60
|
+
min_length=1,
|
|
61
|
+
description=(
|
|
62
|
+
"Ordered steps a QA engineer should follow. Each step has an action "
|
|
63
|
+
"and an optional expectation."
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
]
|
|
67
|
+
result: Annotated[
|
|
68
|
+
TestRailCaseResultInput,
|
|
69
|
+
Field(
|
|
70
|
+
description=(
|
|
71
|
+
"Execution result for this generated test case after the agent ran it."
|
|
72
|
+
)
|
|
73
|
+
),
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
@field_validator("title")
|
|
77
|
+
@classmethod
|
|
78
|
+
def title_must_not_be_blank(cls, value: str) -> str:
|
|
79
|
+
value = value.strip()
|
|
80
|
+
if not value:
|
|
81
|
+
raise ValueError("title must not be blank")
|
|
82
|
+
return value
|
|
83
|
+
|
|
84
|
+
@field_validator("steps")
|
|
85
|
+
@classmethod
|
|
86
|
+
def steps_must_not_be_blank(
|
|
87
|
+
cls, value: list[TestRailStepInput]
|
|
88
|
+
) -> list[TestRailStepInput]:
|
|
89
|
+
if any(not step.action.strip() for step in value):
|
|
90
|
+
raise ValueError("step's actions must not contain blank items")
|
|
91
|
+
return value
|
|
92
|
+
|
|
93
|
+
@model_validator(mode="after")
|
|
94
|
+
def expectations_must_include_verification(self) -> TestRailCaseInput:
|
|
95
|
+
if not any(step.expectation for step in self.steps):
|
|
96
|
+
raise ValueError("at least one step must include an expected result")
|
|
97
|
+
return self
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class SubmitTestPlanInput(BaseModel):
|
|
101
|
+
feature: Annotated[
|
|
102
|
+
str, Field(description="Feature covered by the generated test cases.")
|
|
103
|
+
]
|
|
104
|
+
generated_test_cases: Annotated[
|
|
105
|
+
list[TestRailCaseInput],
|
|
106
|
+
Field(
|
|
107
|
+
min_length=1,
|
|
108
|
+
max_length=30,
|
|
109
|
+
description="Generated test cases to upload to TestRail.",
|
|
110
|
+
),
|
|
111
|
+
]
|
|
112
|
+
summary: Annotated[
|
|
113
|
+
str | None,
|
|
114
|
+
Field(
|
|
115
|
+
description="Optional summary of the generated test-plan execution.",
|
|
116
|
+
),
|
|
117
|
+
] = None
|
|
118
|
+
|
|
119
|
+
@field_validator("feature")
|
|
120
|
+
@classmethod
|
|
121
|
+
def feature_must_not_be_blank(cls, value: str) -> str:
|
|
122
|
+
value = value.strip()
|
|
123
|
+
if not value:
|
|
124
|
+
raise ValueError("feature must not be blank")
|
|
125
|
+
return value
|
|
126
|
+
|
|
127
|
+
@model_validator(mode="after")
|
|
128
|
+
def case_ids_must_be_sequential(self) -> SubmitTestPlanInput:
|
|
129
|
+
case_ids = [case.id for case in self.generated_test_cases]
|
|
130
|
+
expected_ids = list(range(1, len(self.generated_test_cases) + 1))
|
|
131
|
+
if case_ids != expected_ids:
|
|
132
|
+
raise ToolError("test case ids must be sequential starting at 1")
|
|
133
|
+
return self
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _validated_params(
|
|
137
|
+
feature: str,
|
|
138
|
+
generated_test_cases: list[Any],
|
|
139
|
+
*,
|
|
140
|
+
summary: str | None = None,
|
|
141
|
+
) -> dict[str, Any]:
|
|
142
|
+
try:
|
|
143
|
+
validated = SubmitTestPlanInput.model_validate(
|
|
144
|
+
{
|
|
145
|
+
"feature": feature,
|
|
146
|
+
"generated_test_cases": generated_test_cases,
|
|
147
|
+
"summary": summary,
|
|
148
|
+
}
|
|
149
|
+
)
|
|
150
|
+
except ValidationError as exc:
|
|
151
|
+
raise ToolError(
|
|
152
|
+
"invalid TestRail submission",
|
|
153
|
+
payload={"error": "invalid TestRail submission", "details": exc.errors()},
|
|
154
|
+
) from exc
|
|
155
|
+
return validated.model_dump(mode="json")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
@tool
|
|
159
|
+
async def submit_test_plan(
|
|
160
|
+
recorder: ActionsRecorder,
|
|
161
|
+
feature: Annotated[
|
|
162
|
+
str,
|
|
163
|
+
Field(
|
|
164
|
+
description=(
|
|
165
|
+
"Feature name for the new TestRail suite. The apply step always "
|
|
166
|
+
"creates a new suite for this feature."
|
|
167
|
+
)
|
|
168
|
+
),
|
|
169
|
+
],
|
|
170
|
+
generated_test_cases: Annotated[
|
|
171
|
+
list[TestRailCaseInput],
|
|
172
|
+
# Bounds are repeated from SubmitTestPlanInput: this copy is the agent's
|
|
173
|
+
# schema, that one is the enforcement.
|
|
174
|
+
Field(
|
|
175
|
+
min_length=1,
|
|
176
|
+
max_length=30,
|
|
177
|
+
description="Generated test cases to upload together to TestRail.",
|
|
178
|
+
),
|
|
179
|
+
],
|
|
180
|
+
summary: Annotated[
|
|
181
|
+
str | None,
|
|
182
|
+
Field(description="Short overview of how the run went as a whole."),
|
|
183
|
+
] = None,
|
|
184
|
+
) -> str:
|
|
185
|
+
"""Record a generated test plan for deferred TestRail submission.
|
|
186
|
+
|
|
187
|
+
Call this at most once per run: the apply step creates a new TestRail suite
|
|
188
|
+
for every recorded action, so a second call would duplicate the whole plan.
|
|
189
|
+
The apply step creates the suite, creates a section in it, and uploads all
|
|
190
|
+
supplied test cases. Nothing is sent to TestRail during the agent run.
|
|
191
|
+
"""
|
|
192
|
+
if any(action["type"] == ACTION_TYPE for action in recorder.actions):
|
|
193
|
+
raise ToolError(
|
|
194
|
+
"a test plan is already recorded for this run; do not call "
|
|
195
|
+
"submit_test_plan again"
|
|
196
|
+
)
|
|
197
|
+
params = _validated_params(
|
|
198
|
+
feature,
|
|
199
|
+
generated_test_cases,
|
|
200
|
+
summary=summary,
|
|
201
|
+
)
|
|
202
|
+
action = recorder.record(ACTION_TYPE, params)
|
|
203
|
+
return confirmation(action)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
TOOLS = tools_in(__name__)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""The recordable actions served by the shared ``actions`` server.
|
|
2
|
+
|
|
3
|
+
Framework-neutral: the claude-sdk and Codex adapters both build their
|
|
4
|
+
``actions`` server from these tools and instructions.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from agent_tools.registry import ToolDefinition
|
|
8
|
+
|
|
9
|
+
from hackbot_runtime.actions import (
|
|
10
|
+
action_records,
|
|
11
|
+
agents,
|
|
12
|
+
bugzilla,
|
|
13
|
+
feedback,
|
|
14
|
+
github,
|
|
15
|
+
phabricator,
|
|
16
|
+
slack,
|
|
17
|
+
testrail,
|
|
18
|
+
try_server,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
ACTIONS_INSTRUCTIONS = """\
|
|
22
|
+
Each recorded action returns its ID. A later action can use an earlier action's \
|
|
23
|
+
result (`url`, or `bug_id` for a new bug) as `{{actions.<action_id>.<field>}}`; \
|
|
24
|
+
it is filled in when the actions are applied. For example, if an action returned \
|
|
25
|
+
`(ID: e42219b46c164b2c97785769d6bd1b3e)`, its `url` is \
|
|
26
|
+
`{{actions.e42219b46c164b2c97785769d6bd1b3e.url}}`.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def action_tools(types: list[str] | None = None) -> list[ToolDefinition]:
|
|
31
|
+
"""The recordable actions served by the ``actions`` server."""
|
|
32
|
+
tools = (
|
|
33
|
+
action_records.TOOLS
|
|
34
|
+
+ agents.TOOLS
|
|
35
|
+
+ bugzilla.TOOLS
|
|
36
|
+
+ phabricator.TOOLS
|
|
37
|
+
+ github.TOOLS
|
|
38
|
+
+ testrail.TOOLS
|
|
39
|
+
+ slack.TOOLS
|
|
40
|
+
+ try_server.TOOLS
|
|
41
|
+
+ feedback.TOOLS
|
|
42
|
+
)
|
|
43
|
+
if types is not None:
|
|
44
|
+
wanted = set(types)
|
|
45
|
+
tools = [t for t in tools if t.dotted in wanted]
|
|
46
|
+
return tools
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"""Try-server-domain recordable actions."""
|
|
2
|
+
|
|
3
|
+
from typing import Annotated
|
|
4
|
+
|
|
5
|
+
from agent_tools.registry import ToolError, tool, tools_in
|
|
6
|
+
from pydantic import Field
|
|
7
|
+
|
|
8
|
+
from hackbot_runtime.actions.recorder import ActionsRecorder, confirmation
|
|
9
|
+
|
|
10
|
+
TRY_PUSH_ACTION_TYPE = "try_server.push"
|
|
11
|
+
|
|
12
|
+
# Anything gated on "this run pushes to try" — today the patch-series artifact
|
|
13
|
+
# built in ``context.publish_changes`` — keys off this set, for symmetry with
|
|
14
|
+
# ``phabricator.PATCH_ACTION_TYPES``.
|
|
15
|
+
TRY_ACTION_TYPES = frozenset({TRY_PUSH_ACTION_TYPE})
|
|
16
|
+
|
|
17
|
+
# `mach try --rebuild` allows up to 20 (tools/tryselect/task_config.py), but
|
|
18
|
+
# that is too many runs for an agent push.
|
|
19
|
+
MAX_REBUILD = 10
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def validate_test_paths(tests: dict[str, list[str]]) -> dict[str, list[str]]:
|
|
23
|
+
"""Check the shape of an agent-supplied ``{suite: [paths]}`` narrowing."""
|
|
24
|
+
cleaned: dict[str, list[str]] = {}
|
|
25
|
+
for suite, paths in tests.items():
|
|
26
|
+
name = suite.strip()
|
|
27
|
+
if not name or "/" in name or name != "".join(name.split()):
|
|
28
|
+
raise ToolError(
|
|
29
|
+
f"{suite!r} is not a test suite name. The key is the suite whose "
|
|
30
|
+
"harness runs the tests ('mochitest-browser-chrome', "
|
|
31
|
+
"'xpcshell', 'web-platform-tests', ...), and the paths go in the "
|
|
32
|
+
"value. Read both out of the try_task_config.json that "
|
|
33
|
+
'`./mach try fuzzy --no-push -q "<query>" <paths>` prints, under '
|
|
34
|
+
"`tasks` and `env.MOZHARNESS_TEST_PATHS`."
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
if not isinstance(paths, (list, tuple)):
|
|
38
|
+
raise ToolError(
|
|
39
|
+
f"The paths for suite {name!r} must be a list of "
|
|
40
|
+
f"repository-relative paths, not a {type(paths).__name__}. This "
|
|
41
|
+
"is the shape mach prints in MOZHARNESS_TEST_PATHS, so copy it "
|
|
42
|
+
"from there as-is."
|
|
43
|
+
)
|
|
44
|
+
wanted = sorted({path.strip().strip("/") for path in paths if path.strip()})
|
|
45
|
+
if not wanted:
|
|
46
|
+
raise ToolError(
|
|
47
|
+
f"No test paths given for suite {name!r}; drop the suite or give "
|
|
48
|
+
"it at least one repository-relative path."
|
|
49
|
+
)
|
|
50
|
+
cleaned[name] = wanted
|
|
51
|
+
return cleaned
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@tool
|
|
55
|
+
async def push(
|
|
56
|
+
recorder: ActionsRecorder,
|
|
57
|
+
reasoning: Annotated[
|
|
58
|
+
str, Field(description="Why you are pushing to try (for audit log).")
|
|
59
|
+
],
|
|
60
|
+
tasks: Annotated[
|
|
61
|
+
list[str] | None,
|
|
62
|
+
Field(
|
|
63
|
+
description=(
|
|
64
|
+
"Treeherder task labels, e.g. ['build-linux64/opt']. Only tasks "
|
|
65
|
+
"that exercise your change; each costs machine time. Not with "
|
|
66
|
+
"`auto`."
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
] = None,
|
|
70
|
+
auto: Annotated[
|
|
71
|
+
bool,
|
|
72
|
+
Field(
|
|
73
|
+
description=(
|
|
74
|
+
"Let CI pick the tasks for the files you changed (`mach try "
|
|
75
|
+
"auto`). Prefer this when unsure. Not with `tasks`."
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
] = False,
|
|
79
|
+
tests: Annotated[
|
|
80
|
+
dict[str, list[str]] | None,
|
|
81
|
+
Field(
|
|
82
|
+
description=(
|
|
83
|
+
"Narrow the selection to specific tests: {suite: [repo-relative "
|
|
84
|
+
"paths]}, e.g. {'mochitest-browser-chrome': "
|
|
85
|
+
"['browser/base/content/test']}. Needs `tasks` or `auto` too. A "
|
|
86
|
+
"suite name that is not the one running is silently ignored, so "
|
|
87
|
+
"copy it from mach rather than guessing."
|
|
88
|
+
),
|
|
89
|
+
),
|
|
90
|
+
] = None,
|
|
91
|
+
rebuild: Annotated[
|
|
92
|
+
int | None,
|
|
93
|
+
Field(
|
|
94
|
+
default=None,
|
|
95
|
+
description=(
|
|
96
|
+
f"Run each selected task this many times (2-{MAX_REBUILD}), as "
|
|
97
|
+
"`mach try --rebuild` does. For telling whether an intermittent "
|
|
98
|
+
"failure is fixed; each extra run costs machine time."
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
] = None,
|
|
102
|
+
title: Annotated[
|
|
103
|
+
str | None,
|
|
104
|
+
Field(
|
|
105
|
+
description=(
|
|
106
|
+
"One-line commit message shown on Treeherder, e.g. 'Bug 123 - "
|
|
107
|
+
"verify the fix on Linux'."
|
|
108
|
+
),
|
|
109
|
+
),
|
|
110
|
+
] = None,
|
|
111
|
+
) -> str:
|
|
112
|
+
"""Run your changes on the Firefox try server.
|
|
113
|
+
|
|
114
|
+
For work only CI can verify — a platform you cannot build, a suite you cannot
|
|
115
|
+
run. It does not deliver a fix; ``submit_patch`` does that.
|
|
116
|
+
|
|
117
|
+
Pass `auto` (CI picks the tasks) or `tasks` (labels you name), plus optional
|
|
118
|
+
`tests` to narrow to specific tests. Do not guess labels or suite names: run
|
|
119
|
+
``./mach try fuzzy --no-push -q "<query>" [paths]``, which pushes nothing,
|
|
120
|
+
and copy `tasks` and `env.MOZHARNESS_TEST_PATHS` out of the config it prints.
|
|
121
|
+
|
|
122
|
+
Your working-directory changes are pushed as-is, so finish your edits first.
|
|
123
|
+
This records the push for review rather than performing it, so you will not
|
|
124
|
+
see the results.
|
|
125
|
+
|
|
126
|
+
Later actions can reference its `url`.
|
|
127
|
+
"""
|
|
128
|
+
cleaned_tasks = [task.strip() for task in (tasks or []) if task and task.strip()]
|
|
129
|
+
if cleaned_tasks and auto:
|
|
130
|
+
raise ToolError(
|
|
131
|
+
"Pass either `tasks` or `auto`, not both: `auto` lets CI choose the "
|
|
132
|
+
"tasks, so naming them as well is contradictory."
|
|
133
|
+
)
|
|
134
|
+
if not cleaned_tasks and not auto:
|
|
135
|
+
raise ToolError(
|
|
136
|
+
"A try push needs a selection: pass `auto=True` to let CI pick the "
|
|
137
|
+
"tasks for your change, or list Treeherder labels in `tasks`."
|
|
138
|
+
+ (
|
|
139
|
+
" `tests` only narrows a selection down to those test paths; on "
|
|
140
|
+
"its own it would run nothing."
|
|
141
|
+
if tests
|
|
142
|
+
else ""
|
|
143
|
+
)
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
if rebuild is not None and not 1 <= rebuild <= MAX_REBUILD:
|
|
147
|
+
raise ToolError(
|
|
148
|
+
f"`rebuild` must be between 1 and {MAX_REBUILD}; {rebuild} is outside it."
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
params: dict = {
|
|
152
|
+
"tasks": cleaned_tasks or None,
|
|
153
|
+
"auto": auto,
|
|
154
|
+
"title": title,
|
|
155
|
+
}
|
|
156
|
+
if tests:
|
|
157
|
+
params["test_paths"] = validate_test_paths(tests)
|
|
158
|
+
# One run is what a push does anyway, so only a real repeat is recorded.
|
|
159
|
+
if rebuild is not None and rebuild > 1:
|
|
160
|
+
params["rebuild"] = rebuild
|
|
161
|
+
|
|
162
|
+
action = recorder.record(TRY_PUSH_ACTION_TYPE, params, reasoning=reasoning)
|
|
163
|
+
return confirmation(action)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
TOOLS = tools_in(__name__)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Publish run artifacts: upload via the signed policy, else write locally.
|
|
2
|
+
|
|
3
|
+
A single rule across the runtime — summary, logs, attachments: if an uploader
|
|
4
|
+
is configured the artifact is uploaded under ``key``; otherwise it is written
|
|
5
|
+
to ``artifacts_dir / key`` so local/compose/direct runs leave everything
|
|
6
|
+
retrievable on the host. Both branches use the same ``key``, so a downstream
|
|
7
|
+
apply step resolves it identically against GCS or the local dir.
|
|
8
|
+
|
|
9
|
+
A chained run reads its parent's artifacts back through signed URLs, see
|
|
10
|
+
:func:`download_all`.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import json
|
|
14
|
+
import shutil
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import requests
|
|
18
|
+
from requests.adapters import HTTPAdapter
|
|
19
|
+
from urllib3.util.retry import Retry
|
|
20
|
+
|
|
21
|
+
from hackbot_runtime.uploader import SignedPolicyUploader
|
|
22
|
+
|
|
23
|
+
_DOWNLOAD_RETRY = Retry(
|
|
24
|
+
total=5, backoff_factor=1, status_forcelist=[408, 429, *range(500, 600)]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def publish_file(
|
|
29
|
+
uploader: SignedPolicyUploader | None,
|
|
30
|
+
artifacts_dir: Path | None,
|
|
31
|
+
key: str,
|
|
32
|
+
path: Path,
|
|
33
|
+
content_type: str | None = None,
|
|
34
|
+
) -> str:
|
|
35
|
+
if uploader is not None:
|
|
36
|
+
uploader.upload_file(key, path, content_type)
|
|
37
|
+
elif artifacts_dir is not None:
|
|
38
|
+
dest = artifacts_dir / key
|
|
39
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
40
|
+
shutil.copyfile(path, dest)
|
|
41
|
+
return key
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def publish_bytes(
|
|
45
|
+
uploader: SignedPolicyUploader | None,
|
|
46
|
+
artifacts_dir: Path | None,
|
|
47
|
+
key: str,
|
|
48
|
+
data: bytes,
|
|
49
|
+
content_type: str = "application/octet-stream",
|
|
50
|
+
) -> str:
|
|
51
|
+
if uploader is not None:
|
|
52
|
+
uploader.upload_bytes(key, data, content_type)
|
|
53
|
+
elif artifacts_dir is not None:
|
|
54
|
+
dest = artifacts_dir / key
|
|
55
|
+
dest.parent.mkdir(parents=True, exist_ok=True)
|
|
56
|
+
dest.write_bytes(data)
|
|
57
|
+
return key
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def publish_json(
|
|
61
|
+
uploader: SignedPolicyUploader | None,
|
|
62
|
+
artifacts_dir: Path | None,
|
|
63
|
+
key: str,
|
|
64
|
+
payload: dict,
|
|
65
|
+
) -> str:
|
|
66
|
+
return publish_bytes(
|
|
67
|
+
uploader,
|
|
68
|
+
artifacts_dir,
|
|
69
|
+
key,
|
|
70
|
+
json.dumps(payload, indent=2, default=str).encode("utf-8"),
|
|
71
|
+
"application/json",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def download_all(urls: dict[str, str], dest: Path) -> None:
|
|
76
|
+
"""Download each ``key: signed URL`` to ``dest / key``."""
|
|
77
|
+
session = requests.Session()
|
|
78
|
+
session.mount("https://", HTTPAdapter(max_retries=_DOWNLOAD_RETRY))
|
|
79
|
+
root = dest.resolve()
|
|
80
|
+
for key, url in urls.items():
|
|
81
|
+
path = (dest / key).resolve()
|
|
82
|
+
if not path.is_relative_to(root):
|
|
83
|
+
raise ValueError(f"artifact key {key!r} escapes {dest}")
|
|
84
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
85
|
+
with session.get(url, stream=True, timeout=300) as response:
|
|
86
|
+
response.raise_for_status()
|
|
87
|
+
with path.open("wb") as fp:
|
|
88
|
+
for chunk in response.iter_content(chunk_size=1 << 20):
|
|
89
|
+
fp.write(chunk)
|