-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(streaming): collapse old interim progress notes after 3 visible (#2403) #3574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| """Static-analysis tests for #2403 — collapse old interim progress notes. | ||
|
|
||
| When more than INTERIM_COLLAPSE_THRESHOLD interim_assistant events arrive in | ||
| one turn, earlier rendered blocks are hidden behind a toggle so the viewport | ||
| stays focused on the latest progress note. | ||
|
|
||
| These tests pin the structural invariants without a live browser, using the | ||
| same static-analysis pattern as test_issue2713_streaming_segment_flush.py. | ||
| """ | ||
| import pathlib | ||
| import re | ||
|
|
||
| REPO = pathlib.Path(__file__).parent.parent | ||
|
|
||
|
|
||
| def read(rel): | ||
| return (REPO / rel).read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def _extract_interim_handler(src): | ||
| """Return the full interim_assistant SSE handler body.""" | ||
| start_pattern = "source.addEventListener('interim_assistant'" | ||
| start = src.index(start_pattern) | ||
| end_marker = "\n });" | ||
| pos = start | ||
| while True: | ||
| idx = src.index(end_marker, pos + 1) | ||
| if idx > start + len(start_pattern) + 20: | ||
| return src[start : idx + len(end_marker)] | ||
| pos = idx | ||
|
|
||
|
|
||
| class TestInterimCollapseHandlerStructure: | ||
| """The interim_assistant handler must contain the collapse threshold and logic.""" | ||
|
|
||
| def test_collapse_threshold_constant_present(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| assert "INTERIM_COLLAPSE_THRESHOLD" in fn, ( | ||
| "interim_assistant handler must define INTERIM_COLLAPSE_THRESHOLD " | ||
| "to avoid scattered magic numbers" | ||
| ) | ||
|
|
||
| def test_threshold_is_three(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| # Constant must be assigned to 3 | ||
| assert re.search(r"INTERIM_COLLAPSE_THRESHOLD\s*=\s*3\b", fn), ( | ||
| "INTERIM_COLLAPSE_THRESHOLD must be set to 3" | ||
| ) | ||
|
|
||
| def test_visibleInterimSnippets_length_comparison(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| assert "visibleInterimSnippets.length" in fn, ( | ||
| "collapse guard must compare visibleInterimSnippets.length" | ||
| ) | ||
| assert "INTERIM_COLLAPSE_THRESHOLD" in fn, ( | ||
| "collapse guard must reference INTERIM_COLLAPSE_THRESHOLD, not a magic number" | ||
| ) | ||
|
|
||
| def test_interim_data_attribute_set(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| assert "data-interim" in fn, ( | ||
| "interim_assistant handler must mark each segment with data-interim " | ||
| "so collapse logic can query them" | ||
| ) | ||
|
|
||
| def test_interim_collapsed_class_applied(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| assert "interim-collapsed" in fn, ( | ||
| "collapse logic must apply the interim-collapsed CSS class to hide old blocks" | ||
| ) | ||
|
|
||
| def test_collapse_toggle_element_created(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| assert "interim-collapse-toggle" in fn, ( | ||
| "collapse logic must create an .interim-collapse-toggle element" | ||
| ) | ||
|
|
||
| def test_toggle_text_references_count(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| # Toggle label must be dynamic: "Show N earlier update(s)" | ||
| assert "earlier update" in fn, ( | ||
| "collapse toggle text must reference 'earlier update' so the count is visible" | ||
| ) | ||
|
|
||
| def test_attribute_set_before_flush(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| attr_pos = fn.index("setAttribute('data-interim','1')") | ||
| flush_pos = fn.rindex("_flushPendingSegmentRender({force:true})") | ||
| assert attr_pos < flush_pos, ( | ||
| "data-interim attribute must be set before _flushPendingSegmentRender " | ||
| "so the segment is marked before it is sealed" | ||
| ) | ||
|
|
||
| def test_collapse_after_flush_before_reset(self): | ||
| src = read("static/messages.js") | ||
| fn = _extract_interim_handler(src) | ||
| flush_pos = fn.index("_flushPendingSegmentRender({force:true})") | ||
| collapse_pos = fn.index("INTERIM_COLLAPSE_THRESHOLD") | ||
| reset_pos = fn.index("_resetAssistantSegment()", collapse_pos) | ||
| assert flush_pos < collapse_pos < reset_pos, ( | ||
| "collapse logic must run after flush but before _resetAssistantSegment" | ||
| ) | ||
|
|
||
|
|
||
| class TestInterimCollapseCSS: | ||
| """CSS must define both .interim-collapsed and .interim-collapse-toggle.""" | ||
|
|
||
| def test_interim_collapsed_rule_present(self): | ||
| css = read("static/style.css") | ||
| assert ".interim-collapsed" in css, ( | ||
| "style.css must define .interim-collapsed to hide collapsed blocks" | ||
| ) | ||
|
|
||
| def test_interim_collapsed_uses_display_none(self): | ||
| css = read("static/style.css") | ||
| m = re.search(r"\.interim-collapsed\s*\{[^}]*\}", css) | ||
| assert m, ".interim-collapsed rule not found in style.css" | ||
| rule = m.group(0) | ||
| assert "display" in rule and "none" in rule, ( | ||
| ".interim-collapsed must set display:none" | ||
| ) | ||
|
|
||
| def test_collapse_toggle_rule_present(self): | ||
| css = read("static/style.css") | ||
| assert ".interim-collapse-toggle" in css, ( | ||
| "style.css must define .interim-collapse-toggle" | ||
| ) | ||
|
|
||
| def test_collapse_toggle_has_cursor_pointer(self): | ||
| css = read("static/style.css") | ||
| # Extract the first .interim-collapse-toggle rule block | ||
| m = re.search(r"\.interim-collapse-toggle\s*\{[^}]*\}", css) | ||
| assert m, ".interim-collapse-toggle rule not found" | ||
| rule = m.group(0) | ||
| assert "cursor" in rule and "pointer" in rule, ( | ||
| ".interim-collapse-toggle must set cursor:pointer" | ||
| ) | ||
|
|
||
| def test_collapse_toggle_hover_rule_present(self): | ||
| css = read("static/style.css") | ||
| assert ".interim-collapse-toggle:hover" in css, ( | ||
| "style.css must define a :hover rule for .interim-collapse-toggle" | ||
| ) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.