Skip to content

fix(tests): correct test_model_group_mutations_refresh_audit_events - #1033

Closed
seonghobae wants to merge 2 commits into
mainfrom
fix/admin-contract-eval-extraction-bugs
Closed

fix(tests): correct test_model_group_mutations_refresh_audit_events#1033
seonghobae wants to merge 2 commits into
mainfrom
fix/admin-contract-eval-extraction-bugs

Conversation

@seonghobae

@seonghobae seonghobae commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

contextual-orchestrator#1026 (212ff43, item 25 in the standing .github backlog) added test_model_group_mutations_refresh_audit_events to tests/test_admin_contract.py, but the test was broken from the moment it was merged — three separate bugs, all masked because it never actually ran to completion before this fix. Found while investigating a handoff from a peer session that had hit this repeatedly and worked around it with deselect.

  1. Missing importsjson/subprocess/shutil are used but never imported (NameError on the first json.dumps call).
  2. Two end markers didn't point at their function's actual next sibling in admin.py:
    • saveModelGroup's end marker was 'async function deleteModelGroup', but ~568 unrelated lines (renderTrace, renderAccess, and several other panel-rendering functions) sit between them, so the extraction swept in a stray els.agentSearch.addEventListener(...) reference and threw Cannot access 'els' before initialization (TDZ) once the eval'd script reached it.
    • refreshModelGroups had the same shape of bug one function earlier: its end marker pulled in refreshAuditEvents's entire body too.
  3. A third, more fundamental bug once the ranges were correct: eval() of a bare function declaration (not wrapped in parens) returns undefined, not the callable — every const X = eval(...) assignment was silently undefined regardless of extraction correctness. Verified with a minimal node -e repro before writing the fix.

Also added showModelGroupRefreshWarning as a sixth extracted const — it's called internally by refreshModelGroupViews but was never itself extracted, so calling it threw ReferenceError even after fixes 1-3.

Each fix surfaced the next real error in sequence rather than a new symptom, confirming this is the actual converging root cause chain rather than a series of unrelated patches.

Test plan

  • pytest tests/test_admin_contract.py -v — all 3 tests pass
  • Full suite: python -m pytest tests -q --ignore=tests/fuzz — 3333 passed, 1 skipped (pre-existing, unrelated)
  • interrogate — 100% (tests/ excluded from the docstring gate, unaffected either way)

🤖 Generated with Claude Code


Devin Review

Summary by CodeRabbit

  • 테스트
    • 모델 그룹 변경 및 감사 이벤트 관련 테스트의 JavaScript 함수 추출·평가 방식을 개선했습니다.
    • 경고 표시와 저장 동작을 각각 정확히 검증하도록 테스트 범위를 조정했습니다.
    • 테스트 실행에 필요한 보조 모듈을 추가했습니다.
    • 제품 기능 자체의 변경은 없습니다.

This test (contextual-orchestrator#1026) was broken on main from the
moment it was added -- three separate bugs, all masked because the
test never actually ran to completion before this fix:

1. json/subprocess/shutil are used but never imported (NameError on
   the first line that touches json.dumps).

2. source_between()'s end markers for two of the six extractions
   didn't point at each function's actual next sibling in admin.py:
   - saveModelGroup's end marker was 'async function
     deleteModelGroup', but ~568 unrelated lines (renderTrace,
     renderAccess, and several other panel-rendering functions) sit
     between them, so the extraction swept in a stray
     `els.agentSearch.addEventListener(...)` reference and threw
     "Cannot access 'els' before initialization" (TDZ) once the
     eval'd script ran far enough to reach it.
   - refreshModelGroups had the identical shape of bug one function
     earlier: its end marker pulled in refreshAuditEvents's entire
     body too.
   Fixed both to their real immediate next sibling.

3. Once the ranges were correct, a third, more fundamental bug
   surfaced: eval() of a bare function *declaration* (not wrapped in
   parentheses) returns undefined, not the callable -- every one of
   these `const X = eval(...)` assignments was silently undefined
   regardless of extraction correctness. Verified with a minimal
   `node -e` repro before writing the fix. Wrapped each extracted
   function body in parens in source_between() so eval() evaluates it
   as an expression.

Also added showModelGroupRefreshWarning as a sixth extracted const --
it's called internally by refreshModelGroupViews but was never itself
extracted, so calling it threw ReferenceError even after fixes 1-3.

Verified incrementally: each fix surfaced the next real error in
sequence rather than a new symptom, confirming this is the actual
converging root cause chain, not a series of unrelated patches. Full
suite: 3333 passed, 1 skipped (pre-existing, unrelated). interrogate
100% (tests/ is excluded from the docstring gate, unaffected either
way).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
seonghobae added a commit to ContextualWisdomLab/.github that referenced this pull request Sep 2, 2026
contextual-orchestrator#1026 (item 25's fix) shipped a matching
contract test in the same PR, but the test never actually ran to
completion on main -- three separate bugs, uncaught because nobody had
run it since merge. Handed off by a peer session after hitting the
failure three times and deselecting around it each time.

Cloned contextual-orchestrator (previously deferred across several
ticks citing "no local clone") and fixed it directly:
ContextualWisdomLab/contextual-orchestrator#1033. Full details in the
gap-baseline correction. The underlying admin.py fix was never in
question -- only its own test's ability to prove that fix works was
broken. Item 25 remains resolved; recorded the narrower lesson that
"PR merged with tests included" and "those tests actually ran and
passed" are different verification steps.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 6bbdfaf2-c2f4-4c4f-af7c-e86d1e24ad54

📥 Commits

Reviewing files that changed from the base of the PR and between 212ff43 and 3ca8c94.

📒 Files selected for processing (1)
  • tests/test_admin_contract.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

관리자 계약 테스트가 추출한 JavaScript 함수 표현식을 eval()로 올바르게 평가하도록 수정되었습니다. 함수별 소스 종료 지점도 조정되었고, 테스트에 필요한 Python import가 추가되었습니다.

Changes

관리자 계약 테스트

Layer / File(s) Summary
JavaScript 함수 추출 및 평가 수정
tests/test_admin_contract.py
source_between이 추출된 소스를 괄호로 감싸 함수 표현식의 값을 반환합니다. refreshModelGroups, refreshAuditEvents, showModelGroupRefreshWarning, saveModelGroup의 추출 종료 지점을 조정했습니다. json, shutil, subprocess import를 추가했습니다.

Estimated code review effort: 3 (Moderate) | ~15–30 minutes

Merge Risk: ⚪ Minimal · up to c8f08

This change repairs an existing administrative contract test without changing production behavior, APIs, permissions, dependencies, or deployment settings. It is merge-ready after normal checks and review, with no actionable merge-blocking risk remaining.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR 제목은 test_model_group_mutations_refresh_audit_events 테스트 수정이라는 주요 변경 사항을 정확하고 간결하게 설명합니다.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/admin-contract-eval-extraction-bugs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

This report is out of date. Scroll down for Devin Review's latest report on this PR.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@seonghobae

Copy link
Copy Markdown
Contributor Author

Independently re-verified (can't formally approve — same account as the PR author): re-derived every marker pair's adjacency directly against admin.py (refreshModelGroups→refreshAuditEvents→showModelGroupRefreshWarning→refreshModelGroupViews→saveModelGroup→renderTrace, plus confirmed deleteModelGroup→els.modelGroups.addEventListener was already correct and untouched) — no sweep-in anywhere. Checked out the branch fresh and ran test_admin_contract.py myself: 3 passed. The eval()-of-a-bare-declaration-returns-undefined root cause is correct JS semantics. Looks good to merge.

seonghobae added a commit that referenced this pull request Sep 2, 2026
Non-force descendant integration of PR #1033 into the orchestrator/free routing repair lane. The production fix in #1032 is unchanged; this adds the executable Node-backed admin contract repair so the branch no longer carries the known pre-existing broken test that masked model-group audit-refresh behavior.

Parents preserve both exact histories: #1032 ef971be and #1033 3ca8c94.
…al-extraction-bugs

# Conflicts:
#	tests/test_admin_contract.py
@seonghobae

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict per Autofix's standing authorization: merged main into this branch (no rebase/force-push). The conflict was entirely in tests/test_admin_contract.py, and turned out to be trivial to resolve — #1035 (merged 2026-09-03T02:22:27Z as fix(tests): repair test_model_group_mutations_refresh_audit_events) already contains this PR's exact fix in full: same paren-wrap for eval()'s declaration-vs-expression completion-value bug, same corrected extraction boundaries for refreshModelGroups/refreshAuditEvents/showModelGroupRefreshWarning/saveModelGroup, same imports. Verified by diffing this PR's changes directly against current main before touching anything — byte-identical in substance.

After the merge, tests/test_admin_contract.py on this branch is now byte-identical to main's version (confirmed via diff). Ran tests/test_admin_contract.py (3/3 passed) before pushing.

Net effect: this PR's own delta is now fully superseded/inherited by #1035, which already merged. Flagging rather than closing myself — Autofix's authorization here covers fixing/pushing, not close decisions. If nothing else is intended to land on this branch, it looks safe to close as fully covered by #1035.

🤖 Addressed by Claude Code

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 0 new potential issues.

Devin Review

Copy link
Copy Markdown
Contributor Author

Verified succession before closure: live base main@39a4348e61930aa132efeb1a454de1054fda6843 already contains the complete valid semantic delta this PR was created to carry. tests/test_admin_contract.py on that protected base imports json, shutil, and subprocess; source_between() parenthesizes extracted declarations so eval() returns callables; the refreshModelGroups, refreshAuditEvents, showModelGroupRefreshWarning, refreshModelGroupViews, saveModelGroup, and deleteModelGroup extraction boundaries use their actual next siblings; and the executable Node scenario remains present. Fresh main...c8f08939935e91a7756f75cdde572816f3169d62 comparison reports ahead_by=2, behind_by=0, but files=[]: the branch tree has no remaining file delta against protected main after the non-force reconciliation. Therefore there is no unique test/fixture/contract/evidence left to land from #1033, and closing it is full semantic succession rather than queue reduction or discarded work.

@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

자동 정리: base 대비 실제 변경(diff)이 0건이라 이 PR을 닫습니다. 변경을 추가한 뒤 reopen하세요.

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