Skip to content

test: add the family-import scan to nine more mirror facades - #36627

Open
bolichen97 wants to merge 1 commit into
mainfrom
fix/22413-facade-owner-scan-nine
Open

bolichen97 wants to merge 1 commit into
mainfrom
fix/22413-facade-owner-scan-nine

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: the nine mirror facades whose owners no outside module imports today (acp.skill_projection, cli, dashboard.session_directive_apply, deploy.handlers, mcp_cron, platform.policy_distribution, security.argv_floor, security.exfil, ui_index) get the family-import scan, so a module outside the family that imports an owner directly turns a test red.

On main, 26 facade tests carry test_only_the_family_imports_an_owner, and a few more carry the same check under another name. These nine facades have owners that no module outside their family imports, but nothing checks that. So a new module could import, say, kiro_crew.security.exfil_bash directly instead of going through kiro_crew.security.exfil, and every test would stay green.

Why it matters

A module that imports an owner directly holds its own binding of the owner's names. A test that patches the name through the facade then misses that module, so the patch silently does nothing there and the test proves less than it claims. Without the scan, the first such import in these nine families goes unnoticed.

Not a goal

  • The mirror facades whose owners some outside module already imports on main (for example mcp_core, mcp_shared, mcp_discovery, llm_helpers, validation): a scan there would be red today and needs a production change first.
  • Facades without a mirror index (acp, agent, acp.liveness and the like), and the meta and helper files that match test/*facade*.py but test no single facade.
  • mcp_dashboard and work_ledger, which already check the same thing under the name test_no_module_outside_the_family_imports_an_owner.
  • Built-in app facades.
  • Any production code change, and any change to test/owner_import_scan.py.

What changed (motivation → approach → change)

A module outside one of these nine families that imports an owner directly now turns a test red, as it already does for the facades swept before. Each facade test gains one test_only_the_family_imports_an_owner, built on the shared helper test/owner_import_scan.py, the same shape as the seven dashboard handler facades in #35593.

The test reads the owner list from the facade's own mirror index, so it follows the facade if an owner is added. It streams only the source files that name an owner, collects every file that imports one, and asserts two things: one real import of an owner is found (so a scan that read nothing fails), and every importer is the facade or one of its owners. Each file's module docstring names the new check.

Backwards compatibility

Compatible: test-only; nine tests are added, and the only other edits are one import and one docstring clause per file.
Removes nothing: no test, helper, record or public name is removed or renamed.

Tests

file owner import it finds
test/test_skill_projection_facade.py acp/skill_projection_parts/alias_reclaim.py
test/test_cli_split_facade.py the facade cli.py (its owners import no other owner)
test/test_session_directive_apply_facade.py dashboard/session_directive_apply_monitor.py
test/test_handlers_deploy_facade.py deploy/handlers_sites.py
test/test_mcp_cron_facade.py mcp_cron_vet.py
test/test_policy_distribution_facade.py platform/policy_distribution_boot.py
test/test_argv_floor_facade.py security/argv_floor_ssh.py
test/test_exfil_facade.py security/exfil_git_object.py
test/test_ui_index_facade.py ui_index_load.py
  • All 87 tests in the nine files pass (78 existing, 9 new).

  • Mutation proof, run on Ubuntu Linux and not committed: a throwaway src/kiro_crew/_owner_probe_22413.py imports one owner of each family (absolute, from package import owner, import a.b, aliased and relative spellings). On the base the nine files stay green with it, which is the gap. With this change all nine new tests go red, and with the probe removed they are green again:

    probe present, nine new tests:  9 failed
    FAILED test/test_exfil_facade.py::test_only_the_family_imports_an_owner - AssertionError: assert {'_owner_probe_22413.py'} == set()
    (the same line for each of the other eight files)
    probe removed, nine new tests:  9 passed
    
  • Determinism, on the nine new tests: 20 runs at -n0, then 10 at -n 4 --dist loadgroup --max-worker-restart=2 with the family-import tests of test/test_usage_facade.py and test/test_hooks_handler_facade.py as co-tenants, all green. All 87 tests of the nine files in one shuffled order (seed 3476249225) are green. test/test_flake_pattern_ratchet.py and the repository semgrep rules on the diff are green.

Manual verification

N/A — unit coverage sufficient: the change is nine tests, and the mutation proof above shows each one fails on an outside importer.

Screenshots / video

N/A — no frontend file is touched.

Related Issues

Part of #22413

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

The skill_projection, cli, session_directive_apply, deploy handlers,
mcp_cron, policy_distribution, argv_floor, exfil and ui_index facades
had no check that only their own family imports an owner. A module that
imported an owner directly would keep its own binding, so a patch
through the facade would miss it.

Each of the nine facade tests gains test_only_the_family_imports_an_owner
on the shared test/owner_import_scan.py helper. It reads the owners from
the facade's mirror index, asserts it sees one real import of an owner,
and asserts every importer is the facade or an owner.

Part of #22413

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging e3a2536af69e28440d820c56def33a571fd3af66. Adjudication upheld 1 of 1 blocking finding(s); those must be resolved before merging.

This comment is updated in place on each push.

BLOCKING -- test/test_argv_floor_facade.py:425 -- Two family-import checks fail on existing production imports

assert importers - family == set()
Trigger: Running this check and test/test_ui_index_facade.py:172 on the merged tree sends existing imports through owner_import_scan.owner_importers: security/ssh_config_route.py imports argv_floor_hosts, and guide_catalog.py imports ui_index_load.
Outcome: Both new assertions fail, with outside-importer sets {'security/ssh_config_route.py'} and {'guide_catalog.py'}, respectively, blocking the backend test gate.
Anchor: defect
Fix: Restrict this test-only change to the seven eligible families; add these two checks after their existing production importers migrate through the facades.

[BLOCK-MERGE] e3a2536
[GPT-REVIEWED] e3a2536

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1 is upheld. The defect is real and the fix is cheap. I couldn't run the two tests because pytest isn't installed in this environment, so the failure below comes from reading the code.

F1: MEDIUM harm, but it fires on every run. The scan in test/owner_import_scan.py:34 walks every import in a file with ast.walk, including imports inside functions. src/kiro_crew/security/ssh_config_route.py:355,403,482 imports from argv_floor_hosts, which the facade lists as an owner at security/argv_floor.py:82. src/kiro_crew/guide_catalog.py:912 imports from ui_index_load, an owner listed at ui_index.py:1047. Neither file is in its family, so test/test_argv_floor_facade.py:425 and test/test_ui_index_facade.py:172 will always fail and keep the backend test gate red. There is no retry or fallback that clears it. The real fix is small: drop these two checks from this PR, or move those importers onto the facades. It adds no new mechanism.

[ADJUDICATION] e3a2536af69e28440d820c56def33a571fd3af66 total=1 uphold=1 downgrade=0
UPHOLD F1 test/test_argv_floor_facade.py:425 reason=harm-warrants-remedy
[GPT-ADJUDICATED] e3a2536af69e28440d820c56def33a571fd3af66

False positive or not applicable? A repository writer can comment:
/ai-review override gpt e3a2536af69e28440d820c56def33a571fd3af66 false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 13, 2026
@bolichen97
bolichen97 disabled auto-merge November 15, 2026 01:52
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Holding this PR: auto-merge is off until its scope is settled.

#36839 (merged 2026-11-14) added src/kiro_crew/security/ssh_config_route.py, which imports the argv_floor_hosts owner directly (three function-level from .argv_floor_hosts import ... lines). This PR's CI ran on an older base, so it did not see that module. On today's main, test/test_argv_floor_facade.py::test_only_the_family_imports_an_owner would fail: the scan reports {'security/ssh_config_route.py'} outside the family. The other eight scans still pass on today's main, and the branch still merges cleanly.

Two ways forward: take argv_floor out of this PR and handle it in a later sweep PR together with that import, or route those imports through the kiro_crew.security.argv_floor facade. The second one changes production code, which this PR's "Not a goal" rules out. I will post the choice here before the next push.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 4% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

Test-only PR that adds the existing family-import scan to nine more mirror facade tests. Each new test copies the established version in test_usage_facade.py and test_hooks_handler_facade.py line for line and uses the unchanged shared helper owner_import_scan.py. All nine files already define FACADE and _index(). In the cli case the facade imports its owners by name inside its type-checking-only block, so the scan finds cli.py as expected. Every other mention of the cli owners in src/ is a comment or string, not an import. skill_projection_parts/init.py is only a docstring. Backend tests pass on Linux and Windows. The failing AI-review lanes failed on API rate limits and a merge-base read error, not on the code.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit e3a2536af6 · 241 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@buluoray

Copy link
Copy Markdown
Contributor

Please rebase onto the latest main. This head is 572 commits behind main, and its CI ran on a base from 11-13.

On today's main, two of the nine new scans will fail, because main gained a direct owner import in each family after this branch was cut:

Either fix works:

  1. Drop the argv_floor and ui_index scans from this PR for now, and add them in a later sweep.
  2. Open a separate production PR that routes those two importers through their facades, and land it first.

The other seven scans pass on today's main.

@bolichen97 bolichen97 changed the title test: add the family-import scan to nine more mirror facades test: add the family-import scan to seven more mirror facades Nov 15, 2026
@bolichen97 bolichen97 changed the title test: add the family-import scan to seven more mirror facades test: add the family-import scan to nine more mirror facades Nov 15, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Maintainer decision: this PR takes option 1 from the review above. The next push drops the security.argv_floor and ui_index scans and rebases the branch onto today's main. Both families stay in #22413 for a later sweep.

The reason: option 1 keeps this PR test-only, while option 2 would hold it until a production change to a file under src/kiro_crew/security/ lands.

  • Goal edit. I am making it because the review asked for this scope cut, and it is the only one. In that push, the Goal and "Why it matters" say seven facades and seven families instead of nine. The "Not a goal" bullet for facades that already have an outside importer names security.argv_floor and ui_index.
  • Where the later sweep starts. These are the four imports: src/kiro_crew/security/ssh_config_route.py:355,403,482 (importing argv_floor_hosts, from fix(security): allow ssh to a proxy-only host ssh config routes elsewhere #36839) and src/kiro_crew/guide_catalog.py:912 (importing ui_index_load, from build(ui-index): drop the digest and count lines that every UI change edited #37406). All four are inside functions, so a patch through the facade still reaches them at call time. That sweep decides whether a function-level import counts as a violation.
  • Already checked on the rebased branch. On today's main, the seven remaining scans pass, and each one finds its own real inner import. The two dropped files match main byte for byte, and their tests pass. The push follows shortly.

@bolichen97
bolichen97 enabled auto-merge (squash) November 16, 2026 07:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants