fix(admin): repair test_model_group_mutations_refresh_audit_events - #1029
fix(admin): repair test_model_group_mutations_refresh_audit_events#1029seonghobae wants to merge 2 commits into
Conversation
Commit 212ff43 ("fix(admin): refresh audit after model-group mutations") added this contract test but never actually got it to pass before merge (its own message notes hosted checks were queue-saturated at merge time). It carries four stacked defects, all confined to this one test function: 1. Missing `import json`, `import shutil`, `import subprocess` — the test uses `json.dumps`, `shutil.which("node")`, and `subprocess.run` without importing any of the three, so every run failed immediately with `NameError: name 'json' is not defined`. 2. `source_between()` end markers for `refreshModelGroups`, `refreshAuditEvents`, and `saveModelGroup` pointed at the wrong next function name, so those extractions swallowed unrelated admin.py source between the real end of the target function and the (much later) marker text — e.g. saveModelGroup's extraction ran 550+ lines past its own closing brace into deleteModelGroup, producing `ReferenceError: Cannot access 'els' before initialization` when eval'd. 3. `eval()` of a bare `async function foo() {...}` declaration string has no completion value in this Node module context (it evaluates to `undefined`), so every `const x = eval(source)` silently produced `undefined` instead of a callable — only surfaced once (2) was fixed. `source_between()` now wraps its return value in parens so eval sees a function *expression*. 4. `showModelGroupRefreshWarning`, called from inside `refreshModelGroupViews`, was never extracted/defined in the harness, so any refresh-failure scenario threw `ReferenceError: showModelGroupRefreshWarning is not defined`. It is now extracted and bound alongside the other functions. Verified: `test_model_group_mutations_refresh_audit_events` and the rest of `tests/test_admin_contract.py` now pass under `python -m pytest`, and the file's `python tests/test_admin_contract.py` direct-run entrypoint also passes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BV96rXhqoR3tYZ9AeAVur4
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Broader-suite confidence check, as promised in the PR description: (the two ignored files fail to collect on unmodified Result on this branch: 2 failed, 3324 passed, 2 skipped. Both failures are pre-existing and unrelated to this change (this branch only touches
Neither touches Generated by Claude Code |
|
Exact-head fleet verification for
Keep this PR unmerged until the unchanged exact head receives terminal required evidence and independent current-head review under the live protected-branch rules. Predecessor/local test evidence is diagnostic only and does not transfer as merge evidence. |
…ssing-json-import # Conflicts: # tests/test_admin_contract.py
CodeQL failure: infrastructure, not a defectInvestigated That's a repository-level GitHub code-scanning configuration conflict (advanced/workflow-based CodeQL vs. GitHub's "default setup" both enabled), not a code security defect — a different concrete symptom than the Merge conflict: real, and the PR is now superseded — resolved anywayFresh Compared #1035's landed diff against this PR's diff line-by-line: both cover the identical 4 stacked defects (missing Resolved with a normal merge commit ( Given the fix is already on Verification
No sign of other recent activity on this branch (last prior commit Generated by Claude Code |
|
Fresh closure proof: protected |
Root cause
tests/test_admin_contract.py::test_model_group_mutations_refresh_audit_eventsfails on currentmain(confirmed at212ff437, unmodified) with:The test was added by commit
212ff437("fix(admin): refresh audit after model-group mutations"). That commit's own message notes hosted checks were queue-saturated at merge time ("CodeQL startup_failure has no analysis result and the executable contract test is included") — consistent with what this PR found: the new test never actually ran to green before merge. It carries four stacked defects, all confined to this one test function:json.dumps,shutil.which("node"), andsubprocess.runwithout importingjson,shutil, orsubprocessat all — hence the reportedNameError(the first of the three to be hit).source_between()end markers. The end markers used to slicerefreshModelGroups,refreshAuditEvents, andsaveModelGroupout ofADMIN_HTMLpointed at the next-next function's name instead of the function immediately following inadmin.py. E.g.saveModelGroup's extraction was bounded by' async function deleteModelGroup', butdeleteModelGroupis defined ~550 lines later — so the slice swallowed all the intervening admin-console source, which threwReferenceError: Cannot access 'els' before initializationwheneval'd.eval()of a bare function declaration has no completion value. Once (2) was fixed,const saveModelGroup = eval("async function saveModelGroup(...) {...}")evaluated toundefined(aFunctionDeclarationstatement doesn't produce a value), so calling it threwTypeError: saveModelGroup is not a function.source_between()now wraps its return value in parens soevalsees a function expression.showModelGroupRefreshWarningwas never extracted/bound.refreshModelGroupViewscalls it on any refresh failure, but the harness never defined it, so the audit/groups-refresh-failure scenarios threwReferenceError: showModelGroupRefreshWarning is not defined. It's now extracted and bound alongside the other functions.contextual_orchestrator/admin.pyitself is untouched — this is a test-only fix.Fix
All changes are in
tests/test_admin_contract.py:import json,import shutil,import subprocess(ordered per this repo's convention: plain stdlib imports alphabetically before thepathlib/syspath-bootstrap pair — matches the pattern intests/test_assistant_tool_calls_null_noop_http_honesty.pyand siblings).source_between()marker pairs forrefreshModelGroups,refreshAuditEvents, andsaveModelGroupto bound on the function that actually follows each inadmin.py.showModelGroupRefreshWarningextraction/binding.source_between()now parenthesizes its returned source so eacheval()yields a real function value.Test verification
No other test file imports/exercises this specific extraction harness (several other files import
contextual_orchestrator.adminfor unrelatedADMIN_HTMLstring assertions, unaffected by this change). A broaderpytest tests -qrun (excluding two files that fail to collect onmainfor unrelated, pre-existing reasons —tests/fuzz/test_fuzz_properties.pyneedshypothesis,tests/test_psychometric_routing.pyneedsnumpy, neither installed viarequirements.lock) was kicked off for extra confidence; see follow-up comment if anything else in that run needs attention.Commits
Introducing commit:
212ff437(fix(admin): refresh audit after model-group mutations).🤖 Generated with Claude Code
https://claude.ai/code/session_01BV96rXhqoR3tYZ9AeAVur4
Generated by Claude Code