Skip to content

feat(cli): add junit reporter and output support - #590

Merged
anurag629 merged 3 commits into
codercops:devfrom
kachamsiddarth:feat/cli-junit-reporter-416
Nov 6, 2026
Merged

anurag629 merged 3 commits into
codercops:devfrom
kachamsiddarth:feat/cli-junit-reporter-416

Conversation

@kachamsiddarth

Copy link
Copy Markdown
Contributor

What does this change?

Adds a JUnit XML reporter and --output support to chatcops test.

The JUnit reporter generates CI-compatible XML with test cases, failures, execution errors, timing, and aggregate pass-rate information. Output destinations can be shared between reporters while validating duplicate, ambiguous, and invalid configurations.

Closes #416

How I tested this

  • pnpm --filter @chatcops/cli test — 142/142 passed
  • pnpm --filter @chatcops/cli typecheck — passed
  • pnpm --filter @chatcops/cli build — passed
  • pnpm lint — passed
  • pnpm test:coverage --maxWorkers=2 — 2,463 passed, 65 skipped; coverage gates passed
  • git diff --check — passed
  • pnpm install --frozen-lockfile — passed
  • Added unit tests covering JUnit XML generation, escaping, timing, failures/errors, output routing, and invalid reporter/output configurations
  • Updated testing documentation with JUnit reporter and --output usage

AI assistance

Codex was used to assist with implementation, test generation, debugging, and validation. I reviewed the generated changes and ran the test, typecheck, build, lint, and coverage checks locally.

Checklist

  • This PR targets dev
  • I was assigned the linked issue
  • pnpm -r build, pnpm test and pnpm -r typecheck pass locally
  • Tests added or updated where it makes sense
  • For a bug fix: the new test fails without my change
  • Changeset added (pnpm changeset) if this changes core, widget or server
  • pnpm api run and api/ committed if an exported type or option changed
  • Docs updated if behavior or options changed

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @kachamsiddarth, nearly there. The XML has what #416 asked for (one <testsuite> per eval file, the failed reasons and the reply in <failure>, <, & and quotes escaped), and name=file with --output as the shortcut for one reporter reads well. All checks pass, including e2e.

Two things need to change before it can go in, both about writing the file:

  1. A missing parent folder fails the run. CI setups usually write to something like reports/evals.xml, and with no reports/ folder the writeFile at packages/cli/src/test/command.ts:153 throws after every test has run, so CI gets exit 2 and no report. Create the folder first, the way cassettes do at packages/cli/src/test/cassette.ts:115:

    await mkdir(dirname(file), { recursive: true });

    Then drop "Parent folders must exist" from the help (packages/cli/src/main.ts:64) and the docs (testing.mdx:302), and have the missing/report.xml case in test-command.test.ts:388 check that the file gets written there.

  2. A write error loses the recordings. The throw at command.ts:155 is inside the reporter loop and before cassettes.save at line 160, so chatcops test --record --output evals (a folder, so the write fails) calls every API and then saves none of what it recorded. A reporter after the failing one also never gets onEnd: with --reporter junit=evals --reporter pretty the terminal shows no results at all, since pretty writes everything in onEnd. Run every onEnd first, then save the cassettes, then write the files. For the test, tests/cassette.test.ts has the setup: run ['test', '--record', '--output', 'evals'], expect exit 2, and check cassetteOf(dir) was still written.

@kachamsiddarth

Copy link
Copy Markdown
Contributor Author

Implemented both requested review fixes:

  • Report output now creates missing parent directories automatically.
  • All reporters complete their onEnd callbacks before cassette saving and report-file writes, so a report write failure no longer prevents recordings or later reporter summaries from being preserved.
  • Added regression coverage for both cases.

Validation:

  • CLI tests: 144/144 passed
  • Build: passed
  • Typecheck: passed
  • Lint: passed with existing warnings
  • git diff --check: passed

Pushed the follow-up commit to feat/cli-junit-reporter-416.

@anurag629 anurag629 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @kachamsiddarth, both points are in. --output reports/evals.xml now creates reports/ before writing (packages/cli/src/test/command.ts:160), and the file writes come after every onEnd and cassettes.save, so --record --output evals keeps its recordings and --reporter junit=evals --reporter pretty still prints the summary. The two new tests check exactly those cases. CI passed on your last push, including e2e. dev moved since then, so I've updated the branch, and I'll merge once CI passes on that.

@anurag629
anurag629 merged commit 7259529 into codercops:dev Nov 6, 2026
5 checks passed
@github-actions github-actions Bot added the codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com) label Nov 6, 2026
@anurag629

Copy link
Copy Markdown
Member

Merged, thanks @kachamsiddarth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codercops-accepted Merged PR that counts on the monthly leaderboard (oss.codercops.com)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chatcops test: JUnit reporter and --output

2 participants