|
20 | 20 | MESSAGE_COLLAPSE_JS = PROJECT_ROOT / "webui" / "js" / "message-collapse.js" |
21 | 21 |
|
22 | 22 |
|
| 23 | +def test_response_updates_leave_scrolling_to_the_chat_viewport(): |
| 24 | + if not shutil.which("node"): |
| 25 | + pytest.skip("Node.js is required to execute the message-render regression.") |
| 26 | + |
| 27 | + source = (PROJECT_ROOT / "webui" / "js" / "messages.js").read_text() |
| 28 | + draw_message = source[ |
| 29 | + source.index("export function _drawMessage("): |
| 30 | + source.index("\nfunction renderStandaloneMessageContent(") |
| 31 | + ].replace("export function", "function", 1) |
| 32 | + script = f""" |
| 33 | +import assert from "node:assert/strict"; |
| 34 | +let measurements = 0, scrolls = 0, renders = 0; |
| 35 | +class Scroller {{ |
| 36 | + constructor(body) {{ measurements++; void body.scrollHeight; }} |
| 37 | + reApplyScroll() {{ scrolls++; }} |
| 38 | +}} |
| 39 | +const renderStandaloneMessageContent = () => renders++; |
| 40 | +const isMassRender = () => false; |
| 41 | +const _windowedRender = false; |
| 42 | +{draw_message} |
| 43 | +
|
| 44 | +function update(mainClass, expanded) {{ |
| 45 | + const body = {{ dataset: {{}}, scrollTop: 8, |
| 46 | + get scrollHeight() {{ |
| 47 | + assert.notEqual(mainClass, "message-agent-response", |
| 48 | + "response updates must not force layout for an inner scroll viewport"); |
| 49 | + return 100; |
| 50 | + }}, |
| 51 | + }}; |
| 52 | + const message = {{ |
| 53 | + classList: {{ contains: name => name === "expanded" && expanded, remove() {{}} }}, |
| 54 | + querySelector: selector => selector === ".message-body" ? body : null, |
| 55 | + }}; |
| 56 | + _drawMessage({{ |
| 57 | + messageContainer: {{ querySelector: () => message }}, |
| 58 | + mainClass, content: "streaming content", markdown: true, |
| 59 | + }}); |
| 60 | + return body; |
| 61 | +}} |
| 62 | +
|
| 63 | +update("message-agent-response", true); |
| 64 | +update("message-agent-response", false); |
| 65 | +assert.equal(measurements, 0); |
| 66 | +assert.equal(scrolls, 0); |
| 67 | +update("message-default", true); |
| 68 | +assert.equal(scrolls, 1, "other standalone messages must retain auto-scroll"); |
| 69 | +assert.equal(update("message-default", false).scrollTop, 0); |
| 70 | +assert.equal(measurements, 2); |
| 71 | +assert.equal(renders, 4, "scroll changes must not skip content rendering"); |
| 72 | +""" |
| 73 | + subprocess.run(["node", "--input-type=module", "-e", script], check=True, text=True) |
| 74 | + |
| 75 | + |
23 | 76 | def test_text_editor_and_code_execution_keep_memory_search_in_the_process_group(): |
24 | 77 | if not shutil.which("node"): |
25 | 78 | pytest.skip("Node.js is required to execute the message-window regression.") |
|
0 commit comments