Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion tests/unit/test_code_ask_cache_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ def test_the_key_covers_scope_rerank_budget_model_and_prompt(
answers_entry.cache_key_for({"top_k": 10, "token_budget": 4000}, "gpt-4o-mini"),
):
assert other.digest() != base.digest()
assert answers_entry.token_budget_bucket(None) == 4000 # the deployment default
assert answers_entry.token_budget_bucket(None) == 0 # unlimited deployment default
assert answers_entry.cache_key_for({"top_k": 10}, "gpt-4o").digest() != base.digest()
monkeypatch.setattr(settings, "code_ask_token_budget", 4000)
assert answers_entry.token_budget_bucket(None) == 4000
assert answers_entry.cache_key_for({"top_k": 10}, "gpt-4o").digest() == base.digest()
assert answers_entry.token_budget_bucket(12000) == 12000
v1 = answers_entry.prompt_version()
monkeypatch.setattr(answers_entry, "_SYNTH_SYSTEM", answers_entry._SYNTH_SYSTEM + " Be brief.")
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/test_code_review_brief_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,10 @@ async def test_miss_builds_once_and_stores_then_the_next_read_is_a_point(
)
assert wired["built"][0]["changed_paths"] == PATHS
assert [t for t, _ in repo.inserted] == ["code_review_briefs"]
assert out.decisions["randomized_setting"] is True and out.token_budget == 4000
assert set(out.sections) == set(rb.SERVED_ORDER) and out.tokens_used <= 4000
assert out.decisions["randomized_setting"] is True and out.token_budget == 0
assert set(out.sections) == set(rb.SERVED_ORDER)
assert out.tokens_used == sum(section["tokens"] for section in out.sections.values())
assert not any(section["truncated"] for section in out.sections.values())
assert wired["traces"][-1]["route"] == "brief_built" and wired["traces"][-1]["abstain"] is False
# the row it stored is what the next read serves, without a build
stored_row = repo.inserted[0][1][0]
Expand All @@ -663,7 +665,7 @@ async def test_miss_builds_once_and_stores_then_the_next_read_is_a_point(
wired["built"].clear()
out2 = await h.handle_code_review_brief(CodeReviewBriefInput(pr_number=117354, tier="trivial"))
assert out2.source == "precomputed" and wired["built"] == [] and repo2.inserted == []
assert list(out2.sections) == ["paths", "symbols", "do_not_flag"] and out2.token_budget == 700
assert list(out2.sections) == ["paths", "symbols", "do_not_flag"] and out2.token_budget == 0
assert out2.built_at == "2026-09-15T20:00:00Z" and out2.indexed_commit == SHA
assert repo2.reads == [(117354, "")]
# a merge_sha-only read passes the sha through, lower-cased
Expand Down Expand Up @@ -786,8 +788,9 @@ async def _decisions(org: str, trunk: str, paths: Any, *, limit: int, **kw: Any)


@pytest.mark.asyncio
@pytest.mark.parametrize(("budget", "expected_rows"), [(50, 0), (0, 3)])
async def test_rationale_serves_whole_rows_up_to_its_token_setting(
wired: dict[str, Any], monkeypatch: pytest.MonkeyPatch
wired: dict[str, Any], monkeypatch: pytest.MonkeyPatch, budget: int, expected_rows: int
) -> None:
from server.code.app import memory_links
from server.memory.app import code_plane_reads
Expand All @@ -810,12 +813,13 @@ async def _decisions(org: str, trunk: str, paths: Any, *, limit: int, **kw: Any)

monkeypatch.setattr(memory_links, "trunk_namespace", lambda org, ns: ns)
monkeypatch.setattr(code_plane_reads, "decisions_for_paths", _decisions)
monkeypatch.setattr(settings, "code_review_brief_rationale_tokens", 50)
monkeypatch.setattr(settings, "code_review_brief_rationale_tokens", budget)
wired["repo"] = _HandlerRepo(stored=None)
out = await h.handle_code_review_brief(CodeReviewBriefInput(pr_number=117354))
sec = out.sections["rationale"]
# the first row always; the second would pass 50 tokens
assert len(sec["rows"]) == 1 and sec["rows_total"] == 3 and sec["truncated"]
assert len(sec["rows"]) == expected_rows and sec["rows_total"] == 3
assert sec["truncated"] is (expected_rows < 3)
assert not budget or sec["tokens"] <= budget


@pytest.mark.asyncio
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_settings_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ def test_the_reference_hides_exactly_the_fields_repr_masks() -> None:


def test_a_token_budget_is_not_a_secret() -> None:
assert gen._default("code_ask_token_budget") == "`4000`"
assert gen._default("code_ask_token_budget") == "`0`"
assert is_secret_field("code_github_token")