Repository navigation
[AI] test(tool-call-repair): add unit tests for grammar and payload modules - #98984
wangyan2026 wants to merge 2 commits into
Conversation
…odules Add 112 unit tests covering: - grammar.ts: all 12 exports + 4 constants (83 tests) - payload.ts: parseStandalonePlainTextToolCallBlocks and stripPlainTextToolCallBlocks (29 tests) Tests cover three opening formats (bracket, tool: prefix, harmony), three closing formats, allowedToolNames filtering, maxPayloadBytes, JSON boundary cases, line-start detection, and strip behavior. Related to: test-coverage-improvement
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Codex review: needs real behavior proof before merge. Reviewed July 2, 2026, 4:30 AM ET / 08:30 UTC. Summary PR surface: Tests +711. Total +711 across 2 files. Reproducibility: yes. for the PR defect: the latest Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Keep the test-only scope, remove the lint-triggering assertions, rerun focused test plus lint validation, and add redacted real behavior proof or get a maintainer proof override before merge. Do we have a high-confidence way to reproduce the issue? Yes for the PR defect: the latest Is this the best way to solve the issue? No as submitted. Direct package-level tests are an appropriate layer, but the mergeable version must satisfy existing lint rules and the external-PR proof gate without production-code changes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against f2abf57d32ad. Label changesLabel justifications:
Evidence reviewedPR surface: Tests +711. Total +711 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
- grammar.test.ts: remove unused functionOpen, rename params_ to p - payload.test.ts: replace result! assertions with local const blocks = result! Related to: openclaw#98984
|
@clawsweeper re-review I've fixed the lint issues and pushed the changes. Please re-review. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Superseded by #104100, landed as The landed canonical scanner refactor includes and expands this proposed grammar/payload coverage as part of a 315-test focused matrix, alongside stream-normalizer, provider payload, and agent-path regressions. Exact-head CI and live gateway proof are recorded on #104100. Thanks @ZOOWH for identifying and covering this gap. |
Summary
Add unit tests for the
packages/tool-call-repair/module covering grammar parsing and payload parsing. The package currently has zero test coverage across all 5 source files. This PR adds comprehensive tests for the two foundational files (grammar.tsandpayload.ts) that handle plain-text tool call format recognition, JSON boundary tracking, and tool call block stripping.packages/tool-call-repair/(2,299 lines of logic across 5 source files) had zero test coveragepromote.tsandstream-normalizer.ts(main state machine) test coverage is deferred to follow-upChange Type
Scope
Motivation
packages/tool-call-repair/implements the runtime logic for detecting, parsing, and promoting plain-text tool calls emitted by models that do not support native tool calling. The package is consumed bysrc/shared/,src/plugin-sdk/,src/infra/, andsrc/agents/modules, making it a critical dependency. Despite 2,299 lines of parsing logic (state machine, grammar, JSON boundary tracking, promotion), it had zero unit tests. This PR adds coverage for the two pure-logic foundation files that all other modules depend on.Real behavior proof
test/tool-call-repair-unit-testsgrammar.test.ts— 83 tests passing, covering: all 4 grammar constants,matchesLiteralPrefix(exact/prefix/suffix/empty),isPlainTextToolNameChar/isXmlishNameCharcharacter classification,skipHorizontalWhitespace/skipWhitespace(spaces/tabs/newlines),consumeLineBreak(Unix/Windows/standalone CR),findJsonObjectEnd(simple/nested/escaped strings/backslash/empty/unclosed/maxPayloadBytes/offset),skipSerializedToolCallTrailingLineBreak,consumeJsonToolClosingMarker(3 marker formats + leading whitespace),findBracketedJsonPayloadStart(bracket/JSON/missing close/no JSON/CRLF/whitespace),findHarmonyJsonPayloadStart(with/without channel marker/message marker/unknown channel/missing to=/no tool name/missing code/no JSON/commentary/final channels),startsWithAsciiMarkerIgnoreCase(case-insensitive/no match/too short/offset),indexOfAsciiMarkerIgnoreCase(start/offset/not found/available),findXmlishToolCallEnd(XML-ish/bracket/tool: prefix/plain text/no parameters/unclosed/multiple params/case-insensitive/trailing newline)payload.test.ts— 29 tests passing, covering:parseStandalonePlainTextToolCallBlocks(single/multiple bracket, tool: prefix, harmony with/without channel marker, harmony with message marker, allowedToolNames filter/reject, mixed text rejection, invalid JSON, JSON array rejection, missing/mismatched closing markers, maxPayloadBytes, consecutive tool: calls, CRLF line endings, raw/offset tracking),stripPlainTextToolCallBlocks(bracket-style removal, unchanged text, empty input, start/end removal, multiple blocks, tool: prefix at line start)promote.tsandstream-normalizer.ts(main state machine) — deferred to follow-up PRs.stream-normalizer.tsrequires AsyncIterable mocking for the corenormalizePlainTextToolCallStreamEventsgenerator.User-visible / Behavior Changes
None
Security Impact
Compatibility / Migration
Best-fix Verdict
AI Assistance 🤖
Risks and Mitigations
None — test-only change, zero production code modifications.