Skip to content

fix(test): repair stale test_delegate_compactor_safety.py on live-config - #52

Merged
exiao merged 1 commit into
live-configfrom
fix/delegate-compactor-test-task-count
Jun 27, 2026
Merged

fix(test): repair stale test_delegate_compactor_safety.py on live-config#52
exiao merged 1 commit into
live-configfrom
fix/delegate-compactor-test-task-count

Conversation

@exiao

@exiao exiao commented Jun 27, 2026

Copy link
Copy Markdown
Owner

What

Repairs the pre-existing RED test tests/tools/test_delegate_compactor_safety.py on the live-config base. Every fork PR inherits this failure (#46/#47/#48 test slices 1-5,8 were RED on it).

Two layers of staleness

1. The two failures called out in the brief (mechanical):

  • _build_child_agent() on live-config now requires a positional task_count: int (tools/delegate_tool.py). The test called it without that arg at both call sites → TypeError.
  • The compaction path now reaches agent/conversation_compression.py:check_compression_model_feasibility, which reads agent.compression_enabled. The MagicMock(spec=AIAgent) agents lacked it → AttributeError.

2. The deeper cause (orphaned feature tests):
After the two mechanical fixes, 2 of 5 tests still failed because they assert invariants of a feature that was removed from the source in the upstream sync that landed on live-config (293a237fd Merge origin/main into live-config (upstream sync: 107 commits)):

  • tools/delegate_tool.py no longer touches the child compactor (protect_first_n, _delegation_shape_snapshot, messages_prefix, context_compressor).
  • run_agent.py no longer defines capture_delegation_snapshot or _frozen_system_prompt.
  • agent/conversation_compression.py unconditionally rebuilds the system prompt — no frozen-prompt reuse branch.

So TestProtectFirstNBump (whole class) and test_frozen_prompt_reused_after_compaction were orphaned. Removed them; kept the still-valid rebuild-on-compaction assertion (test_no_frozen_prompt_means_rebuild_happens, renamed test_rebuild_happens_on_compaction).

Verification

$ uv run python -m pytest tests/tools/test_delegate_compactor_safety.py
1 passed
$ ruff check tests/tools/test_delegate_compactor_safety.py
All checks passed!

(run via the shared venv: venv/bin/python -m pytest …)

Out of scope (follow-up)

tests/tools/test_delegate_shape_mirror.py is orphaned the same way (11/12 RED) — tracked as a separate cleanup card so this PR stays scoped to the file the task named.

Patch note: ~/.hermes/plans/hermes-patches/delegate-compactor-test-task-count.md. Do not merge — Eric merges.

Two failures the brief named (add task_count=1 at both _build_child_agent
call sites; set compression_enabled on the compaction-path mocks) plus the
deeper cause: the delegation shape-mirror feature these tests validated
(_delegation_shape_snapshot / protect_first_n bump / _frozen_system_prompt
reuse) was removed from the source in the upstream sync on live-config.
Removed the orphaned TestProtectFirstNBump class and the orphaned
test_frozen_prompt_reused_after_compaction; kept the still-valid
rebuild-on-compaction assertion. File is now green.

Sibling tests/tools/test_delegate_shape_mirror.py is orphaned the same way
(tracked separately).

Patch note: ~/.hermes/plans/hermes-patches/delegate-compactor-test-task-count.md
@github-actions

Copy link
Copy Markdown

🔎 Lint report: fix/delegate-compactor-test-task-count vs origin/live-config

ruff

Total: 1 on HEAD, 1 on base (➖ 0)

🆕 New issues (1):

Rule Count
PLW1514 1
First entries
gateway/run.py:5594: [PLW1514] `open` in text mode without explicit `encoding` argument

✅ Fixed issues (1):

Rule Count
PLW1514 1
First entries
../../../../../tmp/lint-base/gateway/run.py:5594: [PLW1514] `open` in text mode without explicit `encoding` argument

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 11571 on HEAD, 11572 on base (✅ -1)

🆕 New issues (2):

Rule Count
unresolved-attribute 2
First entries
tests/run_agent/test_credits_notices_toggle.py:76: [unresolved-attribute] unresolved-attribute: Unresolved attribute `_credits_session_start_micros` on type `AIAgent`
run_agent.py:3026: [unresolved-attribute] unresolved-attribute: Object of type `Self@get_credits_spent_micros` has no attribute `_credits_session_start_micros`

✅ Fixed issues (3):

Rule Count
missing-argument 1
invalid-argument-type 1
invalid-assignment 1
First entries
tests/tools/test_delegate_compactor_safety.py:156: [missing-argument] missing-argument: No argument provided for required parameter `task_count` of function `_build_child_agent`
tests/tools/test_delegate_compactor_safety.py:209: [invalid-argument-type] invalid-argument-type: Argument to function `AIAgent._compress_context` is incorrect: Expected `str`, found `None`
tests/run_agent/test_credits_notices_toggle.py:76: [invalid-assignment] invalid-assignment: Object of type `None` is not assignable to attribute `_credits_session_start_micros` of type `int`

Unchanged: 6090 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request cleans up tests/tools/test_delegate_compactor_safety.py by removing obsolete tests for delegation shape mirror invariants that were removed in an upstream sync. It introduces a new test class, TestCompressContextRebuildsPrompt, to verify that the system prompt is rebuilt on compaction. Feedback on this change suggests setting agent.compression_enabled to False in the unit test to prevent executing unnecessary auxiliary client resolution logic, which makes the test more robust and isolated.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.


agent = MagicMock(spec=AIAgent)
agent._frozen_system_prompt = None # ← not a child
agent.compression_enabled = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Setting agent.compression_enabled = True causes check_compression_model_feasibility to run its full auxiliary client resolution logic, which is unnecessary for this unit test and could make it fragile if the environment or configuration changes. Setting it to False allows the feasibility check to return immediately, making the test more robust, isolated, and faster.

Suggested change
agent.compression_enabled = True
agent.compression_enabled = False

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

agent.context_compressor = MagicMock()

P2 Badge Make the compactor mock take the success path

Because context_compressor is a bare MagicMock, getattr(agent.context_compressor, "_last_compress_aborted", False) in compress_context returns a truthy child mock. This test therefore exercises the compression-aborted fallback and returns the original messages; _build_system_prompt is still called there, so the assertion passes without covering the successful compaction path it claims to verify. Set _last_compress_aborted = False (and preferably the related error fields to None) on the fake compressor before invoking _compress_context.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"""Compaction invokes _build_system_prompt and returns its result."""
from run_agent import AIAgent

agent = MagicMock(spec=AIAgent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Seed tools on the compression mock

When this test runs with the normal dependencies installed, the mocked compression path reaches agent.conversation_compression.compress_context's final token estimate, which directly evaluates agent.tools or None. MagicMock(spec=AIAgent) does not expose instance attributes like tools unless the fixture sets them, so this test still raises AttributeError: Mock object has no attribute 'tools' instead of proving the prompt rebuild behavior. Add agent.tools = [] (or avoid a strict spec for instance state) before calling _compress_context.

Useful? React with 👍 / 👎.

@exiao
exiao merged commit b924e04 into live-config Jun 27, 2026
27 of 36 checks passed
@exiao
exiao deleted the fix/delegate-compactor-test-task-count branch June 27, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant