-
Notifications
You must be signed in to change notification settings - Fork 68
[IUO] Fix runbook URL test failures #4741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,8 +57,17 @@ def available_runbook_urls(): | |
| url=runbooks_api_url, | ||
| timeout=TIMEOUT_10SEC, | ||
| ): | ||
| if sample.status_code == requests.codes.ok: | ||
| return {entry["html_url"] for entry in sample.json()} | ||
| if sample: | ||
| try: | ||
| runbook_urls = {entry["html_url"] for entry in sample.json()} | ||
| except ValueError: | ||
| LOGGER.error( | ||
| f"Failed to decode JSON from '{runbooks_api_url}', " | ||
| f"status: {sample.status_code}, content-type: {sample.headers.get('Content-Type')}" | ||
| ) | ||
| continue | ||
| if runbook_urls: | ||
| return runbook_urls | ||
|
Comment on lines
+60
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HIGH: Validate JSON payload shape before extracting At Line 62, valid-but-unexpected JSON (e.g., dict payload or entries without Proposed fix if sample:
try:
- runbook_urls = {entry["html_url"] for entry in sample.json()}
+ payload = sample.json()
except ValueError:
LOGGER.error(
f"Failed to decode JSON from '{runbooks_api_url}', "
f"status: {sample.status_code}, content-type: {sample.headers.get('Content-Type')}"
)
continue
+ if not isinstance(payload, list):
+ LOGGER.error(
+ f"Unexpected JSON payload type from '{runbooks_api_url}': "
+ f"{type(payload).__name__}, status: {sample.status_code}"
+ )
+ continue
+ runbook_urls = {
+ entry.get("html_url")
+ for entry in payload
+ if isinstance(entry, dict) and entry.get("html_url")
+ }
if runbook_urls:
return runbook_urls🧰 Tools🪛 Ruff (0.15.12)[warning] 64-67: Use Replace with (TRY400) [warning] 65-66: Logging statement uses f-string (G004) 🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
To summarize why this matters for Here's the proposed fix for reference: if sample:
try:
payload = sample.json()
except ValueError:
LOGGER.error(
f"Failed to decode JSON from '{runbooks_api_url}', "
f"status: {sample.status_code}, content-type: {sample.headers.get('Content-Type')}"
)
continue
if not isinstance(payload, list):
LOGGER.error(
f"Unexpected JSON payload type from '{runbooks_api_url}': "
f"{type(payload).__name__}, status: {sample.status_code}"
)
continue
runbook_urls = {
entry.get("html_url")
for entry in payload
if isinstance(entry, dict) and entry.get("html_url")
}
if runbook_urls:
return runbook_urlsWhy each guard exists:
🧠 Learnings used |
||
| except TimeoutExpiredError: | ||
| LOGGER.error( | ||
| f"Failed to fetch runbooks directory listing from '{runbooks_api_url}', " | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm I dont think we need this check, HCO must exist for functional cluster ^^'