Skip to content

fix(core): resolve non-stem validator names in library mode - #772

Merged
kaifcodec merged 3 commits into
kaifcodec:mainfrom
lee3Q:fix/engine-validator-fallback
Nov 3, 2026
Merged

kaifcodec merged 3 commits into
kaifcodec:mainfrom
lee3Q:fix/engine-validator-fallback

Conversation

@lee3Q

@lee3Q lee3Q commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Problem

engine.check() (library mode, documented in docs/USAGE.md) resolves a module's validator as validate_<file-stem>. The CLI instead accepts any validate_* function via helpers.get_scan_func(). Two shipped modules have validators that cannot match their file stem:

  • user_scanner/user_scan/social/cups7.py → validate_7cups (a Python identifier cannot start with a digit)
  • user_scanner/email_scan/sports/besoccer.py → validate_okcats (legacy name)

Both scan fine from the CLI, but in library mode always return Result.error("Function validate_cups7 not found" / "Function validate_besoccer not found") without making any request.

Reproduction (no network):

import asyncio, importlib.util
from user_scanner.core import engine

spec = importlib.util.spec_from_file_location("cups7", "user_scanner/user_scan/social/cups7.py")
mod = importlib.util.module_from_spec(spec); spec.loader.exec_module(mod)
print(asyncio.run(engine.check(mod, "some_user")).get_reason())
# before: "Function validate_cups7 not found"

Fix

When the stem-named function is absent, fall back to the same shared resolver the CLI uses (helpers.get_scan_func). Conforming modules are unaffected (their stem-named validator still wins), and library mode now behaves like the CLI for digit-leading or legacy validator names.

Testing

  • New regression tests in tests/test_engine.py (sync validator, async validator, and a module with no validator still erroring): fail without the fix (2 failed / 24 passed), pass with it (26 passed).
  • Full suite: 518 passed locally on Python 3.10 (515 baseline + 3 new), repo-pinned mcp<2. An independent second environment observed 514 passed / 4 skipped (the 4 skips are test_pdf_generator.py ReportLab-absent skips) with the same +3 delta. No real handles were scanned and no network calls were made; tests use stubs.
  • ruff check: the repo carries pre-existing findings on main; the two changed files introduce zero new findings (identical 8 pre-existing ones before and after this change).
  • mypy user_scanner/core/engine.py --ignore-missing-imports: clean.

lee3Q added 3 commits November 4, 2026 00:59
Add functionality to resolve scan functions in library mode.
Added tests for non-stem validator resolution and error handling.

@kaifcodec kaifcodec left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@lee3Q Thank you for opening the PR, LGTM.

@kaifcodec kaifcodec added the bug fix Fixed a bug in existing files label Nov 3, 2026
@kaifcodec
kaifcodec merged commit 8ec1c6f into kaifcodec:main Nov 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Fixed a bug in existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants