Skip to content

test(task): add contract tests for repair-args double-encode detection#3332

Closed
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:test/repair-args-contract-tests
Closed

test(task): add contract tests for repair-args double-encode detection#3332
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:test/repair-args-contract-tests

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Summary

Adds 17 contract tests for repairDoubleEncodedJsonString and repairTaskParams in packages/coding-agent/src/task/repair-args.ts — a pure function module with no prior test coverage.

What's tested

repairDoubleEncodedJsonString (9 tests)

  • Repairs double-encoded newlines, quotes, and unicode (the core contract)
  • Leaves normal prose untouched (fast path)
  • Leaves strings with no backslash untouched
  • Leaves a lone \n mention untouched (incidental, not double-encoded — hasDoubleEncodeSignature requires a structural escape or 2+ backslashes)
  • Repairs strings with structural escapes (```)
  • Repairs strings with backslash-backslash (\\)
  • Leaves Windows paths with single backslash untouched (\U is not a valid JSON escape)
  • Leaves regex patterns untouched (\d is not a valid JSON escape)
  • Returns same reference when nothing changed

repairTaskParams (8 tests)

  • Repairs double-encoded assignment in flat form
  • Repairs double-encoded description in flat form
  • Repairs double-encoded context in batch form
  • Repairs double-encoded fields in batch task items
  • Returns same reference when nothing needs repair
  • Handles null/undefined params defensively
  • Handles params with undefined optional fields
  • Handles partially streamed params (missing fields)

Verification

  • bun check passes
  • 17 tests pass, 0 fail

17 tests covering:
- repairDoubleEncodedJsonString: double-encode detection via structural
  escapes (", \, \uXXXX), false-positive avoidance (Windows paths,
  regexes, lone \n mentions), reference stability when unchanged
- repairTaskParams: flat/batch form repair, per-task-item repair,
  null/undefined defensive handling, partially streamed params
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026
@roboomp roboomp added agent Agent runtime planning and orchestration review:p0 test tool Tool behavior and integrations triaged labels Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review:p0 for a small test-only change with no production behavior risk; targeted repair tests pass locally (27 pass, including the existing suite).
Two should-fix cleanup items: the new file duplicates existing repair-args coverage on origin/main, and one string “same reference” assertion is tautological for a primitive.
Thanks for tightening coverage around the task argument repair path.

import { repairDoubleEncodedJsonString, repairTaskParams } from "../../src/task/repair-args";
import type { TaskParams } from "../../src/task/types";

describe("repairDoubleEncodedJsonString", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: origin/main already has packages/coding-agent/test/tools/task-repair-args.test.ts covering the same repairDoubleEncodedJsonString contract (uniform decode, Windows paths, regexes, lone \n, no-op). Adding a second suite here duplicates those cases and splits the contract across two files; please fold only the new batch/context/defensive cases into the existing test file, or move the existing suite rather than keeping both.

expect(repairDoubleEncodedJsonString(input)).toBe(input);
});

it("returns same reference when nothing changed", () => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should-fix: string is a primitive, so toBe(input) here checks value equality, not object identity/reference reuse. This duplicates the no-backslash no-op assertions above without defending a separate contract; either drop it or change the test to an object-level identity case like repairTaskParams already does.

Address review feedback: origin/main already had
packages/coding-agent/test/tools/task-repair-args.test.ts covering
the same repairDoubleEncodedJsonString contracts.

- Removed duplicate packages/coding-agent/test/task/repair-args.test.ts
- Added only new cases to the existing file:
  - backslash-backslash decode
  - batch form context repair
  - per-task-item repair
  - null/undefined defensive handling
  - partially streamed params (missing fields)
@oldschoola

Copy link
Copy Markdown
Contributor Author

Fixed in the latest push. Removed the duplicate packages/coding-agent/test/task/repair-args.test.ts and folded only the new cases (backslash-backslash decode, batch form context repair, per-task-item repair, null/undefined defensive handling, partially streamed params) into the existing packages/coding-agent/test/tools/task-repair-args.test.ts. Also removed the toBe(input) reference-stability assertion on a string primitive (the existing repairTaskParams test already covers object-level identity).

@oldschoola

Copy link
Copy Markdown
Contributor Author

Closing — the reviewer correctly identified that packages/coding-agent/test/tools/task-repair-args.test.ts already exists on origin/main and covers the same repairDoubleEncodedJsonString contract (uniform decode, Windows paths, regexes). This PR duplicates existing coverage without adding new contracts. The second review point about toBe(input) testing value equality rather than reference identity for primitives is also valid — the assertion doesn't defend a distinct contract.

@oldschoola oldschoola closed this Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Agent runtime planning and orchestration review:p0 test tool Tool behavior and integrations triaged vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants