Commit 7912a1d
authored
* feat: add stream_validate() hook to Requirement (#900)
Add an async `stream_validate(chunk, backend, ctx)` method to the base
`Requirement` class. The default implementation returns
`PartialValidationResult("unknown")`; subclasses override to inspect the
accumulated chunk and return `"pass"` or `"fail"` early.
Per the Phase 1 design: `"pass"` is informational and does not
short-circuit the final `validate()` call. The method must not mutate
`self` — state isolation is the orchestrator's responsibility.
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* fix(core): address PR #925 review feedback on stream_validate
- Remove "In Phase 1" temporal qualifier from docstring — reworded to
timeless statement about orchestrator responsibility
- Add type annotations (str, Backend, Context) to test subclass overrides
- Add idempotency test: multiple calls on the same Requirement instance
leave state unchanged
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* fix(core): make stream_validate backend/ctx keyword-only
Prevents positional confusion and makes future parameter additions
to the signature non-breaking for existing subclass overrides.
Assisted-by: Claude Code
* fix(core): fix stream_validate docstring and add missing stateful tests
The docstring incorrectly stated that implementations must not mutate
self. Issue #900 spec explicitly allows stateful accumulation and
requires the shallow-copy caveat to be documented. Fix the docstring
to match the spec.
Add two tests required by the issue acceptance criteria:
- test_stateful_subclass_accumulates_state: verifies a subclass can
accumulate state (bullet counter) across stream_validate calls
- test_stateful_subclass_clone_isolation: verifies copy() gives an
independent clone, confirming the orchestrator clone pattern
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* test(core): make BulletCounter genuinely stateful via delta extraction
The previous implementation overwrote _bullet_count from the full
accumulated chunk on each call — equivalent to a pure function with
no real dependency on prior state.
Use _seen_len to extract only the new portion of each accumulated
chunk, accumulating the count additively. This genuinely requires
prior-call state to know where to slice, making the test name
"accumulates_state" accurate.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* test(core): fix missing type: ignore on backend=None in multi-line call
In multi-line calls, # type: ignore only suppresses errors on its own
line. The backend=None argument was uncovered; add the ignore there too.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* test(core): fix import path and clone test orchestrator pattern
Use the public API for imports: Backend and Context both appear in
mellea.core.__all__, so import from mellea.core rather than the
internal submodules.
Rewrite test_stateful_subclass_clone_isolation to simulate the correct
orchestrator pattern: the original requirement is never called directly;
each attempt clones from the fresh original, giving _calls == 0 at the
start of every attempt. The previous test cloned mid-stream, which
tested shallow-copy isolation but demonstrated the wrong usage pattern.
Assisted-by: Claude Code
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
* fix(core): stream_validate receives a single chunk, not accumulated text
Restores the chunk-at-a-time semantics set out in the #891 epic and
#900 spec: stream_validate is called once per complete chunk produced
by the chunking strategy, and receives that single chunk. Requirements
that need history accumulate it on self.
Commit 315a98c inadvertently flipped this: the BulletCounter test was
rewritten to recover deltas from accumulated text via self._seen_len,
and the docstring was updated to match ("The accumulated model output
so far"). Neither change reflected a design decision — it was drift
during a test fix, and buries a confusing workaround in what should be
a straightforward stateful override.
Changes:
- requirement.py: rewrite chunk Args description to name the
chunking-strategy-produced delta, clarify that ctx does not contain
the generated output during streaming, and note the MOT
single-consumer constraint
- test_stream_validate.py: rewrite BulletCounter to accumulate its own
running count (no self._seen_len); calls pass delta chunks
("\n- one\n- two") rather than re-sending accumulated text
The corresponding orchestrator fix in stream_with_chunking() -- pass
the chunk, iterate per chunk -- is in the stacked Wave 3 branch.
Assisted-by: Claude Code
---------
Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
1 parent c1622f5 commit 7912a1d
2 files changed
Lines changed: 209 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
286 | 331 | | |
287 | 332 | | |
288 | 333 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
0 commit comments