mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-10-08 16:02:20 +02:00
fix(browser): derive batch navigation outcome from command rows
A batch whose open succeeded but whose later command failed was recorded as a failed navigation, so a following observation was wrongly labelled stale. Use the per-command rows; when the outcome cannot be determined, treat the page as unknown instead of claiming either result.
This commit is contained in:
@@ -2757,6 +2757,33 @@ class PrivateBrowserTool:
|
||||
header = "\n".join(part for part in (title, url) if part)
|
||||
return {"ok": True, "url": url, "text": f"{header}\n\n{text}".strip()}
|
||||
|
||||
@staticmethod
|
||||
def _batch_navigation_outcome(output: str, command_ok: bool) -> tuple[str, str]:
|
||||
"""Outcome of a batch's last navigation: ``ok``, ``failed`` or ``unknown``.
|
||||
|
||||
A later command failing does not undo a navigation that succeeded,
|
||||
so the per-command rows decide, not the batch exit status.
|
||||
"""
|
||||
|
||||
try:
|
||||
rows = json.loads(output)
|
||||
except (ValueError, TypeError):
|
||||
rows = None
|
||||
if isinstance(rows, list):
|
||||
for row in reversed(rows):
|
||||
command = row.get("command") if isinstance(row, dict) else None
|
||||
if not (
|
||||
isinstance(command, list)
|
||||
and command
|
||||
and str(command[0]).lower() in {"open", "goto", "navigate"}
|
||||
):
|
||||
continue
|
||||
if row.get("success") is True:
|
||||
result = row.get("result") if isinstance(row.get("result"), dict) else {}
|
||||
return "ok", str(result.get("url") or "")
|
||||
return "failed", ""
|
||||
return ("ok", "") if command_ok else ("unknown", "")
|
||||
|
||||
@staticmethod
|
||||
def _navigated_url(output: str) -> str:
|
||||
"""Final URL reported by ``open`` (after redirects), when present."""
|
||||
@@ -3028,12 +3055,20 @@ class PrivateBrowserTool:
|
||||
"untrusted_content": True,
|
||||
}
|
||||
if navigation_url:
|
||||
if command_ok:
|
||||
outcome, final_url = "ok" if command_ok else "failed", ""
|
||||
if action == "batch":
|
||||
outcome, final_url = self._batch_navigation_outcome(out, command_ok)
|
||||
if outcome == "ok":
|
||||
browser.navigated(
|
||||
(read_page or {}).get("url") or self._navigated_url(out) or navigation_url
|
||||
final_url
|
||||
or (read_page or {}).get("url")
|
||||
or self._navigated_url(out)
|
||||
or navigation_url
|
||||
)
|
||||
else:
|
||||
elif outcome == "failed":
|
||||
browser.navigation_failed(navigation_url)
|
||||
else:
|
||||
browser.navigation_unknown(navigation_url)
|
||||
if read_page is not None:
|
||||
if not command_ok:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user