Skip to content

Commit 533316c

Browse files
committed
style(agent): fix ruff lint + format to unblock CI build (aws-samples#247 PR aws-samples#373)
CI 'build (agentcore)' failed on //agent:lint (6 ruff errors that landed across the #1 build-command + upstream-merge commits, committed without the agent lint gate passing): - E501 ×4: config.py _KNOWN_WRITEABLE_WORKFLOW_IDS, test_prompts.py restack-assert + workflow-id loop, test_verify_commands.py real-failure fixture → wrapped. - PLR2004: post_hooks.py magic 127 → new SHELL_COMMAND_NOT_FOUND const. - SIM108: repo.py if/else default_branch → 'or' expression. Then applied ruff format (the CI self-mutation guard enforces format, not just check) — normalized config.py/repo.py/test_repo.py/test_verify_commands.py. ruff check + ruff format --check both clean; agent suite 1116 green.
1 parent 42a9c83 commit 533316c

6 files changed

Lines changed: 49 additions & 26 deletions

File tree

agent/src/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
# on the write-deny invariant). pr-review-v1 is intentionally excluded (it is
2727
# read-only); default/agent-v1 is excluded because its conservative posture
2828
# should fail closed too.
29-
_KNOWN_WRITEABLE_WORKFLOW_IDS = frozenset(("coding/new-task-v1", "coding/pr-iteration-v1", "coding/restack-v1"))
29+
_KNOWN_WRITEABLE_WORKFLOW_IDS = frozenset(
30+
(
31+
"coding/new-task-v1",
32+
"coding/pr-iteration-v1",
33+
"coding/restack-v1",
34+
)
35+
)
3036

3137

3238
def resolve_github_token() -> str:

agent/src/post_hooks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
DEFAULT_BUILD_COMMAND = "mise run build"
2020
DEFAULT_LINT_COMMAND = "mise run lint"
2121

22+
# POSIX shell exit code for "command not found" — an inert build signal (the
23+
# configured verify command isn't installed), not a genuine build failure.
24+
SHELL_COMMAND_NOT_FOUND = 127
25+
2226

2327
def is_verify_command_inert(returncode: int, stderr: str) -> bool:
2428
"""True when a verify command did not actually RUN (vs ran-and-failed).
@@ -34,7 +38,7 @@ def is_verify_command_inert(returncode: int, stderr: str) -> bool:
3438
A repo that genuinely fails its build returns some other non-zero code with
3539
real compiler/test output, which this does NOT flag.
3640
"""
37-
if returncode == 127:
41+
if returncode == SHELL_COMMAND_NOT_FOUND:
3842
return True
3943
s = (stderr or "").lower()
4044
return (

agent/src/repo.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ def setup_repo(config: TaskConfig) -> RepoSetup:
127127
# still runs rather than failing setup; the predecessor's code
128128
# is likely in the default branch by now anyway.
129129
notes.append(
130-
f"base branch '{config.base_branch}' not fetchable; "
131-
"branched off default instead"
130+
f"base branch '{config.base_branch}' not fetchable; branched off default instead"
132131
)
133132
log("SETUP", f"Base branch not found; creating {branch} off HEAD")
134133
run_cmd(["git", "checkout", "-b", branch], label="create-branch", cwd=repo_dir)
@@ -227,10 +226,7 @@ def setup_repo(config: TaskConfig) -> RepoSetup:
227226
# - #247 A4 stacked children: base_branch is the predecessor's branch
228227
# (linear) or main (diamond) — the child's PR targets it.
229228
# - Otherwise: detect the repo default (main/master).
230-
if config.base_branch:
231-
default_branch = config.base_branch
232-
else:
233-
default_branch = detect_default_branch(config.repo_url, repo_dir)
229+
default_branch = config.base_branch or detect_default_branch(config.repo_url, repo_dir)
234230

235231
# Install prepare-commit-msg hook for code attribution
236232
_install_commit_hook(repo_dir)

agent/tests/test_prompts.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,23 @@ def test_restack_returns_prompt_with_remerge_workflow(self):
109109
prompt = get_system_prompt("coding/restack-v1")
110110
assert "RE-STACKING" in prompt
111111
assert "predecessor" in prompt
112-
assert "do NOT add features" in prompt or "NOT new feature work" in prompt or "not new feature" in prompt.lower()
112+
assert (
113+
"do NOT add features" in prompt
114+
or "NOT new feature work" in prompt
115+
or "not new feature" in prompt.lower()
116+
)
113117
assert "{branch_name}" in prompt # pushes to the SAME existing branch
114118
assert "{pr_number}" in prompt
115119
assert "{repo_url}" in prompt
116120
assert "{workflow}" not in prompt
117121

118122
def test_all_workflows_contain_shared_base_sections(self):
119-
for workflow_id in ("coding/new-task-v1", "coding/pr-iteration-v1", "coding/pr-review-v1", "coding/restack-v1"):
123+
for workflow_id in (
124+
"coding/new-task-v1",
125+
"coding/pr-iteration-v1",
126+
"coding/pr-review-v1",
127+
"coding/restack-v1",
128+
):
120129
prompt = get_system_prompt(workflow_id)
121130
assert "## Environment" in prompt, f"Missing Environment in {workflow_id}"
122131
has_rules = "## Rules" in prompt or "## Rules override" in prompt

agent/tests/test_repo.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,30 +154,36 @@ def test_uses_platform_branch_name_verbatim_for_new_task(self, monkeypatch):
154154
fake = _fake_run_cmd()
155155
_patch_common(monkeypatch, fake)
156156
monkeypatch.setattr(repo, "detect_default_branch", lambda url, d: "main")
157-
setup = repo.setup_repo(_config(
158-
is_pr_workflow=False,
159-
branch_name="bgagent/01TESTTASKID/abca-166-add-seville-guide-html",
160-
task_description="ABCA-166: Add seville-guide.html",
161-
))
157+
setup = repo.setup_repo(
158+
_config(
159+
is_pr_workflow=False,
160+
branch_name="bgagent/01TESTTASKID/abca-166-add-seville-guide-html",
161+
task_description="ABCA-166: Add seville-guide.html",
162+
)
163+
)
162164
assert setup.branch == "bgagent/01TESTTASKID/abca-166-add-seville-guide-html"
163165

164166
def test_uses_platform_branch_name_verbatim_for_pr_workflow(self, monkeypatch):
165167
fake = _fake_run_cmd()
166168
_patch_common(monkeypatch, fake)
167-
setup = repo.setup_repo(_config(
168-
is_pr_workflow=True,
169-
branch_name="bgagent/01TESTTASKID/abca-167-stacked-child",
170-
base_branch="bgagent/01PREDTASK/abca-166-predecessor",
171-
))
169+
setup = repo.setup_repo(
170+
_config(
171+
is_pr_workflow=True,
172+
branch_name="bgagent/01TESTTASKID/abca-167-stacked-child",
173+
base_branch="bgagent/01PREDTASK/abca-166-predecessor",
174+
)
175+
)
172176
assert setup.branch == "bgagent/01TESTTASKID/abca-167-stacked-child"
173177

174178
def test_falls_back_to_derived_slug_only_when_no_branch_name(self, monkeypatch):
175179
# No platform branch_name → the agent derives its own slug (legacy path).
176180
fake = _fake_run_cmd()
177181
_patch_common(monkeypatch, fake)
178182
monkeypatch.setattr(repo, "detect_default_branch", lambda url, d: "main")
179-
setup = repo.setup_repo(_config(
180-
is_pr_workflow=False,
181-
task_description="ABCA-168: derive me",
182-
))
183+
setup = repo.setup_repo(
184+
_config(
185+
is_pr_workflow=False,
186+
task_description="ABCA-168: derive me",
187+
)
188+
)
183189
assert setup.branch.startswith("bgagent/")

agent/tests/test_verify_commands.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def test_configured_command_splits_to_argv(self):
3030

3131
def test_quoted_args_preserved(self):
3232
assert resolve_verify_argv('make "target with spaces"', DEFAULT_BUILD_COMMAND) == [
33-
"make", "target with spaces",
33+
"make",
34+
"target with spaces",
3435
]
3536

3637

@@ -84,7 +85,8 @@ def test_no_task_named_is_inert(self):
8485

8586
def test_genuine_build_failure_is_NOT_inert(self):
8687
# Real compiler/test output, exited non-zero → meaningful gating signal.
87-
assert is_verify_command_inert(2, "TypeError: cannot read property 'x'\n1 test failed") is False
88+
real_failure = "TypeError: cannot read property 'x'\n1 test failed"
89+
assert is_verify_command_inert(2, real_failure) is False
8890

8991
def test_clean_exit_is_not_inert(self):
9092
assert is_verify_command_inert(0, "") is False

0 commit comments

Comments
 (0)