Skip to content

refactor(extract): rename _safe_extract_with_xaml_root to _safe_extract_with_scan_root; guard invariant #4 package-wide (#3666) - #5309

Open
Vijay431 wants to merge 1 commit into
Graphify-Labs:v8from
Vijay431:fix/3666-scan-root-rename
Open

Vijay431 wants to merge 1 commit into
Graphify-Labs:v8from
Vijay431:fix/3666-scan-root-rename

Conversation

@Vijay431

Copy link
Copy Markdown

What does this PR do?

Follow-up to #3666. Item 1 of the issue (extractors/markdown.py importing graphify.extract) was already fixed in #3758, which moved the in-flight scan root to extractors/base.py. This PR covers the two remaining pieces from item 1:

  1. Rename (the issue's side note). _safe_extract_with_xaml_root publishes the scan root around every per-file extraction, not just XAML, so the XAML-era name was misleading. It is now _safe_extract_with_scan_root. No alias is kept. Tests monkeypatch the module attribute, and an alias would make a patch on the old name silently stop intercepting calls. The function is private and has one production importer (watch.py).

  2. Package-wide guard for MIGRATION.md invariant Telemetry and data privacy #4. Only markdown.py was checked. The issue noted the reverse import "will recur for the next extractor that needs it". tests/test_extractor_scan_root_context.py now parses every module under graphify/extractors/ with ast (no imports, so no side effects). It fails if any module imports the facade in any of these forms:

    • import graphify.extract
    • from graphify.extract import …
    • from graphify import extract
    • from ..extract import …
    • from .. import extract

    Each offender is listed as file:line. MIGRATION.md invariant Telemetry and data privacy #4 now points to this test.

Item 2 of the issue (the facade re-exporting private symbols) is a direction question for maintainers and is intentionally not addressed here.

Refs #3666

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant protected: MIGRATION.md #4, "never import from graphify.extract inside graphify/extractors/". The rename is behavior-neutral: the same function does the same thing under a new name. No persisted or generated state is affected.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

Proof that the guard catches the old failure:

Limitation: the guard is static (AST). It does not catch dynamic imports such as importlib.import_module("graphify.extract") or __import__.

How was this tested?

uv run pytest tests/test_extractor_scan_root_context.py -q   # with probe A applied -> 1 failed, 5 passed (expected)
uv run python -c "...  _imports_graphify_extract(Path('old_md.py'))"   # probe B -> [149]
uv run pytest tests/test_extractor_scan_root_context.py tests/test_cache.py tests/test_terraform_modules.py tests/test_zero_node_no_cache.py tests/test_watch.py -q
# 362 passed, 1 skipped
uv run pytest tests -q
# 11593 passed, 122 skipped, 1 xfailed
uv run ruff check .
# All checks passed!
uv run pyright
# 761 errors before and after the change (no new errors)
graphify update .

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (N/A: no fragments touched)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

…ct_with_scan_root; guard invariant Graphify-Labs#4 package-wide (Graphify-Labs#3666)

_safe_extract_with_xaml_root publishes the in-flight scan root around every
per-file extraction, not just XAML, so the XAML-era name was misleading (the
side note in Graphify-Labs#3666). Rename it; no alias is kept, because tests monkeypatch
the module attribute and an alias would make patches on the old name silently
stop intercepting calls.

Graphify-Labs#3666's reverse import from extractors/markdown.py was fixed in Graphify-Labs#3758, but only
markdown.py was guarded. Add a test that parses every module under
graphify/extractors/ and fails if any imports the graphify.extract facade in
any form (absolute, `from graphify import extract`, or relative), so MIGRATION.md
invariant Graphify-Labs#4 cannot silently regress. Verified to fail when such an import is
introduced and to flag the pre-Graphify-Labs#3758 markdown.py.

Refs Graphify-Labs#3666
@Vijay431
Vijay431 requested a review from safishamsi as a code owner November 18, 2026 12:18
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Vijay431. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs 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.

Graphify code review View in Graphify

Review completed · 483893fe079e

Tip

Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported

The extraction wrapper was renamed, and its internal extraction and Markdown-reconciliation callers were updated.

Full summary

The extraction wrapper was renamed, and its internal extraction and Markdown-reconciliation callers were updated. Tests and comments were changed to use the new name and broaden the import-direction guard.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 8 of 8 changed files inspected. This is scope, not a correctness guarantee.
Code graph and static checks · 6929 functions depend on this change

Impact & health

Impact — 6929 functions depend on the 1249 functions this change touches.

Health — grade A; 10 existing hotspot(s) in the area this change touches (pre-existing, not introduced here):

  • extract() — 1282 callers, 78 callees (high)
  • _rebuild_code() — 281 callers, 76 callees (high)
  • build_from_json() — 324 callers, 26 callees (high)
  • build_merge() — 125 callers, 18 callees (high)
  • dispatch_command() — 8 callers, 156 callees (high)
  • _extract_generic() — 21 callers, 55 callees (high)
  • extract_sql() — 59 callers, 14 callees (high)
  • extract_js() — 101 callers, 8 callees (high)
  • …and 2 more

Formal checks — 6929 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 6229 function(s) in the blast radius were not formally verified this run

Test selection

593 of 593 test file(s) selected (100%) via static blast radius.

Escalated to a full run for safety (noncode-change, uncovered-code) — the selection is not trustworthy on its own (see below). CI should run the whole suite.

  • tests/pi.test.ts — full-run-safety
  • tests/test_4874_jvm_resolution.py — impact, full-run-safety
  • tests/test_4909_reference_binding_scale.py — impact, full-run-safety
  • tests/test_4978_reconcile_cost.py — impact, full-run-safety
  • tests/test_4992_ts_import_types.py — impact, full-run-safety
  • tests/test_5072_splittable_under_cap_retry.py — impact, full-run-safety
  • tests/test_affected_cli.py — full-run-safety
  • tests/test_affected_defines.py — full-run-safety
  • tests/test_affected_member_seed.py — full-run-safety
  • tests/test_affected_overrides.py — impact, full-run-safety
  • tests/test_affected_path_file_node.py — full-run-safety
  • tests/test_affected_seed_reference_forms.py — full-run-safety
  • tests/test_agents_platform.py — full-run-safety
  • tests/test_alias_folding.py — impact, full-run-safety
  • tests/test_analyze.py — impact, full-run-safety
  • tests/test_anthropic_custom_endpoint.py — full-run-safety
  • tests/test_antigravity_install.py — full-run-safety
  • tests/test_apm_fallback_version.py — full-run-safety
  • tests/test_architecture_doc.py — full-run-safety
  • tests/test_astro_extraction.py — impact, full-run-safety
  • tests/test_astro_import_ids.py — impact, full-run-safety
  • tests/test_atomic_canvas_export.py — full-run-safety
  • tests/test_atomic_version_stamp.py — full-run-safety
  • tests/test_atomic_writes.py — full-run-safety
  • tests/test_backend_env_isolation.py — full-run-safety
  • tests/test_backend_extras.py — full-run-safety
  • tests/test_backend_opt_in.py — impact, full-run-safety
  • tests/test_benchmark.py — full-run-safety
  • tests/test_benchmark_raw_graph.py — full-run-safety
  • tests/test_benchmark_real_query.py — full-run-safety
  • tests/test_binary_media_words.py — full-run-safety
  • tests/test_blade_extractor.py — impact, full-run-safety
  • tests/test_build.py — impact, full-run-safety
  • tests/test_build_located_semantic_identity.py — impact, full-run-safety
  • tests/test_build_merge_dedup_scope.py — impact, full-run-safety
  • tests/test_build_merge_ghost_fold_4955.py — impact, full-run-safety
  • tests/test_build_merge_hyperedges_and_prune.py — impact, full-run-safety
  • tests/test_build_merge_shrink_guard.py — impact, full-run-safety
  • tests/test_builtin_global_type_refs.py — impact, full-run-safety
  • tests/test_c_include_resolution.py — impact, full-run-safety
  • tests/test_cache.py — impact, changed-test, full-run-safety
  • tests/test_cache_long_paths.py — full-run-safety
  • tests/test_cache_stale_import_target.py — impact, full-run-safety
  • tests/test_cache_windows_case_4925.py — full-run-safety
  • tests/test_callflow_html.py — full-run-safety
  • tests/test_cargo_introspect.py — full-run-safety
  • tests/test_cargo_missing_manifest.py — full-run-safety
  • tests/test_carried_hyperedge_remap.py — impact, full-run-safety
  • tests/test_case_only_decl_ids_4904.py — impact, full-run-safety
  • tests/test_case_sensitive_resolution.py — impact, full-run-safety
  • … and 543 more

⚠️ non-code file(s) changed (graphify/extractors/MIGRATION.md) → running the full suite for safety (a code graph can't see config/fixture/data deps)

⚠️ changed code file(s) with no mapped test (graphify/extractors/MIGRATION.md) — a coverage gap or a missing link — running the full suite rather than only the selected tests

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant