Skip to content

test: add unit tests for extractJsonFromModelOutput and removeThinkTags#321

Open
nuthalapativarun wants to merge 1 commit into
nanobrowser:masterfrom
nuthalapativarun:test/agent-helper-coverage
Open

test: add unit tests for extractJsonFromModelOutput and removeThinkTags#321
nuthalapativarun wants to merge 1 commit into
nanobrowser:masterfrom
nuthalapativarun:test/agent-helper-coverage

Conversation

@nuthalapativarun
Copy link
Copy Markdown

Problem

extractJsonFromModelOutput and removeThinkTags in chrome-extension/src/background/agent/messages/utils.ts have zero test coverage despite handling several branching code paths (plain JSON, markdown code blocks, Llama tool call / python tag formats, stray closing think tags).

Solution

Add src/background/agent/__tests__/utils.test.ts with 14 tests following the same Vitest pattern used by the existing guardrails test suite.

Coverage added:

  • removeThinkTags: well-formed tags, multiline, stray closing tag, no tags, tags-only
  • extractJsonFromModelOutput: plain JSON, generic code block, json-tagged code block, Llama <|tool_call_start_id|> with and without end tag, Llama <|python_tag|>, invalid JSON, empty string, nested objects

Changes

  • chrome-extension/src/background/agent/__tests__/utils.test.ts — new test file, 14 tests

Testing

  • pnpm -F chrome-extension test passes — 28 tests total (14 existing + 14 new)
  • ESLint clean on new file
  • pnpm -F @extension/i18n type-check passes

Add 14 tests covering all JSON extraction paths in messages/utils.ts:
plain JSON, code block (generic and json-tagged), Llama tool_call and
python_tag formats, error cases (invalid JSON, empty string), and nested
objects. Also covers removeThinkTags including stray closing tags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant