-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Release: msg_limit ceiling metadata decoupling (#6214, @webtecnica) #6216
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,3 +64,34 @@ def test_parse_msg_limit_zero_and_negative_clamp_to_one(): | |
| for msg_limit=0 gets a 1-row window, not the full transcript.""" | ||
| assert _parse_msg_limit("0") == 1 | ||
| assert _parse_msg_limit("-5") == 1 | ||
|
|
||
|
|
||
| # ── #6177: metadata-decoupling — the frontend reads the ceiling from the | ||
| # /api/session `_msg_limit_max` field instead of a hand-mirrored constant. ── | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| _ROUTES_SRC = (Path(__file__).resolve().parents[1] / "api" / "routes.py").read_text(encoding="utf-8") | ||
| _SESSIONS_JS = (Path(__file__).resolve().parents[1] / "static" / "sessions.js").read_text(encoding="utf-8") | ||
|
|
||
|
|
||
| def test_backend_exposes_msg_limit_max_in_session_response(): | ||
| """The /api/session handler advertises the ceiling as `_msg_limit_max` so the | ||
| frontend never has to hand-mirror _MAX_MSG_LIMIT (#6177 decoupling).""" | ||
| assert 'raw["_msg_limit_max"] = _MAX_MSG_LIMIT' in _ROUTES_SRC | ||
|
|
||
|
|
||
| def test_frontend_declares_live_ceiling_at_module_scope_with_fallback(): | ||
| """`_msgLimitMax` MUST be declared at module scope (not an implicit global) | ||
| with the static fallback, so the reload-width paths read a DEFINED value | ||
| before the first /api/session response lands — otherwise a cold load reads | ||
| `undefined`, drops msg_limit, and full-loads every session.""" | ||
| assert "let _msgLimitMax = _MSG_LIMIT_MAX;" in _SESSIONS_JS | ||
| # refreshed from the response metadata, falling back when the server omits it | ||
| assert "_msgLimitMax = data.session._msg_limit_max || _MSG_LIMIT_MAX;" in _SESSIONS_JS | ||
|
|
||
|
|
||
| def test_frontend_reload_width_paths_read_the_live_ceiling(): | ||
| """Both reload-width decisions read the live `_msgLimitMax`, not the mirror.""" | ||
| assert "reloadLimit <= _msgLimitMax" in _SESSIONS_JS # _ensureMessagesLoaded | ||
| assert "requestedLimit >= _msgLimitMax" in _SESSIONS_JS # _loadOlderMessages | ||
|
Comment on lines
+78
to
+97
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
All three new tests assert that specific literal strings appear somewhere in the source files — they pass equally whether the string is in live code, a comment, or dead code. AGENTS.md guideline 6 asks for assertions on observable behavior rather than source strings. The existing codebase already uses this pattern (the deleted drift-guard test did the same), so this is a known tradeoff, but the new tests would silently pass even if the string were in a commented-out block or unreachable branch. A complement that validates Context Used: AGENTS.md (source) Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_ROUTES_SRCand_SESSIONS_JSare populated at import time, not inside test functions. If eitherread_text()call raises (e.g. a permission error or an unexpected working directory), pytest reports the entire module as a collection error — silently preventingtest_max_msg_limit_constant_is_reasonableand the other pre-existing unit tests from running at all, with no signal that those tests were skipped rather than passing. Moving the reads inside each test function (or into apytest.fixture) would isolate the failure to only the affected tests. Thefrom pathlib import Pathimport mid-file rather than at the top is also worth tidying.