Bunch of runtime fixes for MegaTask and other issues

This commit is contained in:
Renn F
2026-06-27 06:52:59 +02:00
parent 517bee7d28
commit 53d60da37e
31 changed files with 1407 additions and 249 deletions
+87 -1
View File
@@ -6,7 +6,11 @@ from uuid import uuid4
import pytest
from pydantic import ValidationError
from roboco.api.schemas.v1.flow import DelegateRequest
from roboco.api.schemas.v1.flow import (
DelegateRequest,
IWillPlanRequest,
IWillWorkOnRequest,
)
def test_delegate_request_requires_task_type() -> None:
@@ -48,3 +52,85 @@ def test_delegate_request_accepts_explicit_task_type() -> None:
acceptance_criteria=["returns 200"],
)
assert req.task_type == "code"
# ---------------------------------------------------------------------------
# StrList — SDK-nested list-of-strings coercion (Bug A)
# ---------------------------------------------------------------------------
def test_i_will_plan_request_flattens_sdk_nested_technical_considerations() -> None:
"""The Claude SDK parses XML-ish ``<item>…</item>`` list-of-strings tool
input into nested arrays (``[[[""]]]``). A bare ``list[str]`` field
hard-rejects element 1 (a list, not a str) at validation time — the live
``i_will_plan`` crash: ``technical_considerations.1 Input should be a
valid string``. The ``StrList`` BeforeValidator must flatten it to a flat
``list[str]`` so the verb body receives clean strings.
"""
req = IWillPlanRequest(
task_id=uuid4(),
plan="Plan narrative describing the approach in full sentences.",
approach=(
"Approach text long enough to clear the 150-character minimum "
"enforced on the plan's Approach field so the Plan tab is fully "
"populated for audit and tracing instead of rendering an empty view."
),
technical_considerations=[
[[["Empty state distinct from loaded state, coverage target 80%"]]],
[{"item": {"$text": "Use asyncpg prepared statements"}}],
],
)
assert req.technical_considerations == [
"Empty state distinct from loaded state, coverage target 80%",
"Use asyncpg prepared statements",
]
def test_i_will_work_on_request_flattens_dict_wrapped_technical_considerations() -> (
None
):
"""Same coercion on the developer planning verb — a dict-wrapped string
(``{"item": {"$text": ""}}``, the SDK's element-text marker) must reduce
to the bare string, not ``str(dict)``."""
req = IWillWorkOnRequest(
task_id=uuid4(),
technical_considerations=[{"item": {"$text": "Cache the lookup result"}}],
)
assert req.technical_considerations == ["Cache the lookup result"]
def test_delegate_request_flattens_sdk_nested_acceptance_criteria() -> None:
"""``delegate``'s ``acceptance_criteria`` is the same list-of-strings shape
the SDK can nest (this is the ``delegate``-verb analogue of the MegaTask
Bug 3 crash). The ``StrList`` field must flatten the nested input so the
VARCHAR[] insert downstream never sees a dict/list element."""
req = DelegateRequest(
parent_task_id=uuid4(),
title="t",
description="add the new endpoint plus tests",
assigned_to="be-dev-1",
team="backend",
task_type="code",
nature="technical",
estimated_complexity="medium",
acceptance_criteria=[
[[["returns 200 for valid input"]]],
[{"item": {"$text": "rejects malformed input with 400"}}],
],
)
assert req.acceptance_criteria == [
"returns 200 for valid input",
"rejects malformed input with 400",
]
def test_strlist_drops_non_string_junk_instead_of_crashing() -> None:
"""Non-string junk (a bare int, a dict with no string values, whitespace)
is dropped — the field never raises on garbage the SDK might emit; only
real strings survive. An all-junk payload yields an empty list (the
delegate min_length=1 gate then rejects it cleanly, not a 500)."""
req = IWillWorkOnRequest(
task_id=uuid4(),
technical_considerations=[42, {"foo": 123}, [[" "]], "real note"],
)
assert req.technical_considerations == ["real note"]