Skip to content

Commit 420ce20

Browse files
fix: CoPilot review round-3 pass on PR #45
- harness/prompt_management.py: fix misleading comment on FixtureExpectedRaises.carries (secondary_backend_call_count is a sibling field on FixtureExpectedPerCall, not inside carries). - manager.py: replace 'assert causes' with an explicit 'if not causes: raise RuntimeError(...)' guard so the invariant holds under 'python -O' (asserts stripped) and surfaces as a clear RuntimeError rather than an opaque IndexError if a future change ever silently swallows an exception in the fallback loop. - test_prompts.py: rewrite the active-prompt-in-nested-async-function test to spawn via asyncio.create_task so it actually exercises context-copy across the task boundary, matching the function name's implied claim. The previous form's await ran in the same context where ContextVar propagation is trivially expected.
1 parent bcf63a2 commit 420ce20

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/openarmature/prompts/manager.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,19 @@ async def fetch(self, name: str, label: str = "production") -> Prompt:
8181
label,
8282
)
8383
continue
84-
assert causes
84+
if not causes:
85+
# Unreachable under current control flow: the constructor
86+
# guarantees ``len(self._backends) >= 1`` and the only
87+
# fall-through path from the for-loop appends to
88+
# ``causes``. Explicit guard rather than ``assert`` so
89+
# the invariant holds under ``python -O`` (asserts get
90+
# stripped) — a future change that silently swallowed an
91+
# exception in the loop would surface here as a clear
92+
# RuntimeError instead of an opaque IndexError on the
93+
# next line.
94+
raise RuntimeError(
95+
"PromptManager.fetch internal invariant violated: no backends consulted but loop exhausted"
96+
)
8597
raise PromptStoreUnavailable(
8698
f"all prompt backends unavailable for ({name!r}, {label!r})",
8799
name=name,

tests/conformance/harness/prompt_management.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ class BackendTarget(_StrictModel):
7272

7373
class FixtureExpectedRaises(_PermissiveModel):
7474
category: str
75-
# Optional extra carries — fixture 005 uses ``description_mentions``,
76-
# ``name``, ``version``, ``label``. fixture 008 uses
77-
# ``secondary_backend_call_count``. Permissive on this shape so
78-
# fixtures evolve.
75+
# Optional extra carries. Fixture 005 surfaces
76+
# ``description_mentions`` / ``name`` / ``version`` / ``label``
77+
# here. Permissive on this shape so fixtures evolve;
78+
# per-backend call-count assertions live on the parent
79+
# ``FixtureExpectedPerCall`` (see ``secondary_backend_call_count``
80+
# and ``backend_call_counts`` below), not in ``carries``.
7981
carries: dict[str, Any] | None = None
8082

8183

tests/unit/test_prompts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ async def _read_in_task() -> PromptResult | None:
354354
return current_prompt_result()
355355

356356
with with_active_prompt(pr):
357-
result = await _read_in_task()
357+
task = asyncio.create_task(_read_in_task())
358+
result = await task
358359
assert result is pr
359360

360361

0 commit comments

Comments
 (0)