Skip to content

test: add offset assertion and merged-summary verification for incremental parse (#1169)#1171

Open
microsasa wants to merge 1 commit intomainfrom
fix/1169-incremental-merge-test-assertions-dacc1ac173790810
Open

test: add offset assertion and merged-summary verification for incremental parse (#1169)#1171
microsasa wants to merge 1 commit intomainfrom
fix/1169-incremental-merge-test-assertions-dacc1ac173790810

Conversation

@microsasa
Copy link
Copy Markdown
Owner

Closes #1169

Changes

Strengthens TestSessionCacheMtime.test_unchanged_file_not_reparsed and adds a regression companion test to guard the incremental-merge path in get_all_sessions.

1. Offset assertion (test_unchanged_file_not_reparsed)

assert spy.call_args[0][1] > 0, (
    "expected incremental parse from cached offset, got full reparse from 0"
)

Previously the test used ANY for the offset argument, which would pass even if the incremental path's ev_cached.end_offset > 0 guard were broken and a full reparse from 0 occurred.

2. Merged-summary data verification (test_unchanged_file_not_reparsed)

sess_a = next(s for s in result2 if s.events_path == p1)
assert sess_a.is_active is True
assert sess_a.active_output_tokens == 42

The appended assistant.message event has outputTokens=42. After the incremental merge, the resumed session must reflect these tokens. Previously only session count was checked.

3. Regression test (test_incremental_merge_preserves_cached_events)

A dedicated test that:

  • Verifies shutdown model_metrics from the cached prefix survive the merge (would fail if list(ev_cached.events) + new_events were replaced with just new_events)
  • Verifies the appended event's outputTokens appear in active_output_tokens
  • Verifies user_messages count includes the original user message from cached events

This mirrors the approach used in TestIncrementalCacheLogic.test_incremental_append_uses_cached_prefix in test_vscode_parser.py.

Warning

⚠️ Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • astral.sh
  • pypi.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "astral.sh"
    - "pypi.org"

See Network Configuration for more information.

Generated by Issue Implementer · ● 15.3M ·

…ental parse (#1169)

Strengthen test_unchanged_file_not_reparsed:
- Assert the incremental offset is > 0 (not a full reparse from 0)
- Assert the merged summary reflects appended event data
  (active_output_tokens == 42 for the resumed session)

Add test_incremental_merge_preserves_cached_events:
- Regression test proving cached prefix events (shutdown model_metrics)
  survive the incremental merge
- Verifies both shutdown metrics retention and new event data inclusion
- Anchors the list(ev_cached.events) + new_events merge behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 3, 2026 09:57
@microsasa microsasa added the aw Created by agentic workflow label May 3, 2026
@microsasa microsasa enabled auto-merge May 3, 2026 09:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens the test suite coverage around copilot_usage.parser.get_all_sessions incremental parsing by adding assertions that the cached-offset fast path is actually used and that merged session summaries reflect appended event data after an incremental refresh.

Changes:

  • Tighten TestSessionCacheMtime.test_unchanged_file_not_reparsed to assert a non-zero incremental offset and validate active_output_tokens after merge.
  • Add a new regression test test_incremental_merge_preserves_cached_events to ensure cached-prefix data (e.g., shutdown model_metrics, earlier user_messages) is preserved when new events are appended.

Comment on lines +6928 to +6931
# Second call — incremental parse merges cached + new events.
result2 = get_all_sessions(tmp_path)
assert len(result2) == 1
sess_after = result2[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aw Created by agentic workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[aw][test audit] get_all_sessions incremental-merge path: no offset assertion and no merged-summary data verification

2 participants