Skip to content

Fix: name the diverging event in the conformance replay comparison - #840

Open
AmaadMartin wants to merge 2 commits into
mainfrom
fix/conformance-report-event-index
Open

Fix: name the diverging event in the conformance replay comparison#840
AmaadMartin wants to merge 2 commits into
mainfrom
fix/conformance-report-event-index

Conversation

@AmaadMartin

@AmaadMartin AmaadMartin commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

  1. Link to an existing issue (if applicable):

  2. Or, if no issue exists, describe the change:

Problem: validateSession compares the two normalized event arrays with one assert.deepStrictEqual. The failure diffs the whole session and never names the event that diverged. Node elides unchanged regions, so the reader cannot recover the index by counting. A length difference is also reported as a content difference.

Solution: validateSession checks the event count first, then compares the arrays one event at a time. A count difference reports Event count mismatch - Actual: <n>, Recorded: <m> and stops before any element comparison. A content difference reports event <i> mismatch: followed by Node's + actual - expected diff for that event alone. This ports the granularity and the message vocabulary of compare_events() in adk-python src/google/adk/cli/conformance/_replay_validators.py.

Parity note: the message words follow adk-python, the layout does not. The reference embeds newlines in the count message. Two integers read better on one line, and the failure printer indents every line it is given.

Scope note: dev/src/integration/run_integration_tests.ts still discards the message it catches. That file belongs to a separate change, so this PR leaves it alone. The harness prints these messages once that change lands.

Collision check: I listed all 729 open PRs on the fork and read the diff of every PR that touches dev/src/integration/test_runner.ts (#494, #643, #746, #749, #231) and the two conformance-reporting PRs (#745, #839). None reports the event index. #746 edits the same function to add a session-state assertion, but it keeps the single whole-array deepStrictEqual, so it is an overlap and not a duplicate. I branched from main rather than stacking on #746: stacking would pull the unrelated state comparison into this review, and both PRs add the same export keyword, so a rebase resolves cleanly.

Testing Plan

Please describe the tests that you ran to verify your changes. This is required for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

New file dev/test/integration/test_runner_test.ts, 7 cases: identical sessions, per-run fields only, empty sessions, both count directions, the diverging index, and the first of several diverging indexes.

npx vitest run dev/test/integration/test_runner_test.ts     # 7 passed
npx tsc --noEmit                                            # no error in either changed file
npx eslint "**/*.ts"                                        # clean
npx prettier "**/*.ts" --check                              # clean

Coverage of the new code is 100% of lines and branches, measured with --coverage.include='dev/src/integration/test_runner.ts': no statement between the new lines 153 and 176 is uncovered, and every branch counter in that range is non-zero.

Proof the tests can fail. I reverted validateSession to its old body:

export function validateSession(actual: Session, expected: Session) {
  const actualEvents = actual.events.map(normalizeEvent);
  const expectedEvents = expected.events.map(normalizeEvent);

  assert.deepStrictEqual(actualEvents, expectedEvents);
}

4 of the 7 cases then failed (both count cases and both index cases), for example:

FAIL  validateSession > reports the count when the replay produced more events
AssertionError: expected 'Expected values to be strictly deep-e…' to contain 'Event count mismatch - Actual: 2, Rec…'

Restoring the new body returns all 7 to green.

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any necessary setup or configuration.

I drove the real replay path with no mocks: batchLoadYamlAgentConfig and batchLoadYamlTestDefs over a YAML fixture tree, then TestRunner.run(), which builds a real Runner, InMemorySessionService, ReplayPlugin and DummyLlm. To repeat it:

  1. Run npm run build --workspace core && npm run build --workspace dev.
  2. Create a conformance fixture directory: an agent root_agent.yaml, plus spec.yaml, generated-recordings.yaml and generated-session.yaml for one test.
  3. Load it with the two YAML loaders, register the agent, and call TestRunner.run(testInfo, true) inside a try/catch that prints error.message.
  4. Delete the last event from generated-session.yaml. The caught error reads Event count mismatch - Actual: 2, Recorded: 1.
  5. Restore the event and change one text. The caught error names the event index, for example event 0 mismatch: followed by the diff of that event.

The fixture tree lives outside the repository, so it is not part of this diff.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Amaad Martin added 2 commits August 8, 2026 20:21
validateSession compared the two normalized event arrays with one
assert.deepStrictEqual, so a failure diffed the whole session and never
said which event diverged. Node elides unchanged regions, so the reader
could not recover the index by counting either.

Compare the arrays one event at a time and check the length first, so a
mismatch reports either "Event count mismatch - Actual: n, Recorded: m"
or "event <i> mismatch:" with the diff of that event alone. Mirrors
compare_events() in adk-python's _replay_validators.py.
The helper had one caller and existed only to mirror a function name in
adk-python. The observable failure messages are what parity requires,
and inlining leaves them identical.
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