litellm/tests/e2e/codex/test_auto_compaction_e2e.py
ryan-crabbe-berri 50af27eaa6
test(e2e): add Codex file edit, long session and auto-compaction rows through LiteLLM (#49386)
* test(e2e): add the Codex file edit and long session rows

The file edit row has Codex change a random value into config.txt with the patch tool and checks the file on disk. The long session row has it follow a chain of random file names one cat at a time. new_workspace now returns the resolved path, because Codex reports patched files by their real path (/private/var on macOS).

* test(e2e): make the Codex long session prove every earlier command output reached the model

* test(e2e): Codex auto-compaction through LiteLLM (#49389)

* test(e2e): add the Codex auto-compaction row

Codex reads a random value, compacts through the gateway with its remote compaction forced on, and is asked for the value after the file holding it is deleted. The row reads the compaction from the thread's rollout file and marks Claude on Bedrock as a strict expected failure, since the Responses-to-chat bridge ignores the compaction_trigger item

* refactor(e2e): validate Codex rollout lines with the models directly
2026-11-03 01:52:29 +00:00

46 lines
1.7 KiB
Python

from __future__ import annotations
from typing import Final
import pytest
from codex.harness import CodexHarness
from codex.setups import ModelSetup, with_expected_failure
from e2e_config import unique_marker
pytestmark = pytest.mark.e2e
COMPACT_AFTER_TOKENS: Final = 500
PADDING: Final = "".join(f"line {number}: the quick brown fox jumps over the lazy dog\n" for number in range(400))
@pytest.mark.parametrize(
"deployment",
with_expected_failure(
"claude_bedrock",
reason="LiteLLM's Responses-to-chat bridge ignores Codex's compaction_trigger item, so Codex gets no"
" compaction back and fails the turn",
),
)
class TestCodexAutoCompaction:
def test_remembers_a_value_after_the_gateway_compacts_the_session(
self, codex: CodexHarness, setup: ModelSetup
) -> None:
marker: Final = unique_marker()
workspace: Final = codex.new_workspace(files={"secret.txt": marker, "padding.txt": PADDING})
first: Final = codex.exec(
"Run `cat secret.txt` and remember the value it prints. Then run `cat padding.txt`. Then reply with OK.",
model=setup.model,
cwd=workspace,
compact_after_tokens=COMPACT_AFTER_TOKENS,
)
assert first.thread_id is not None, first
(workspace / "secret.txt").unlink()
second: Final = codex.resume(
first.thread_id,
"What value did secret.txt print earlier? Reply with just that value.",
model=setup.model,
cwd=workspace,
compact_after_tokens=COMPACT_AFTER_TOKENS,
)
assert any(compaction.remote for compaction in codex.compactions(first.thread_id)), (first, second)
assert marker in second.answer, second