Skip to content

fix(extract): parse only Astro frontmatter and scripts in the AST pass - #3902

Closed
Bosken85 wants to merge 1 commit into
Graphify-Labs:v8from
Bosken85:fix/astro-mask-non-script
Closed

Bosken85 wants to merge 1 commit into
Graphify-Labs:v8from
Bosken85:fix/astro-mask-non-script

Conversation

@Bosken85

@Bosken85 Bosken85 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

extract_astro fed the whole .astro file to the JavaScript grammar. The template is not JS, so almost every page was reported as a syntax error ("first error at line 1/2 … no symbols extracted"). Symbols that tree-sitter could not recover past the template were dropped. Fixes #2788, and covers the ".astro script blocks are parsed unmasked" half of #3337. The window/globalThis half is not touched.

The AST pass now runs on a masked copy of the file, the same approach as _vue_mask_non_script and _php_mask_to_script_blocks:

  • The frontmatter body and JS <script> bodies are kept verbatim. Every other character becomes a space, keeping \r/\n, so byte offsets and source_location still match the original file.
  • The masked source is parsed with the TS grammar, which is Astro's default script language and a superset of JS, after _normalize_ts_import_types.
  • <script> tags whose type is not JS are blanked too, because their bodies are not statements. That covers anything other than no type, module, text/javascript or application/javascript, for example application/ld+json.
  • The character right after a kept region (the < of </script>) becomes ;, so two scripts on one line don't merge into one statement. This doesn't change the length.

The existing regex import rescue (static and dynamic imports) is unchanged.

Type of change

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

Verification & Invariants

Invariant: every node extracted from a .astro file keeps a source_location that points at its line in the original file. The mask never inserts or removes characters, and the new test asserts L5 and L15 for a frontmatter function and a client-script function.

Persisted state: AST cache entries built before this change hold the old, poorer results for .astro files. They are keyed on file content, so they only refresh when a file changes or the cache is cleared.

Limitation: expressions inside the template ({items.map(...)}) are not parsed. They weren't meaningfully before either, since they sat inside the ERROR region. Imports inside them are still recovered by the regex pass.

  • 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.

How was this tested?

uv run pytest tests/test_astro_extraction.py tests/test_astro_import_ids.py -q
  12 passed
# regression check: both new tests fail on v8 without the fix
#   (parse_errors = {'first_error_line': 2, 'multiline_error': True} / line 1)
uv run pytest tests -q
  34 failed, 5942 passed, 99 skipped. The same 34 fail on unmodified v8 (erlang, r,
  solidity, vbnet extractors, skillgen, ollama_retry_cap in this environment).
uv run ruff check graphify/extract.py tests/test_astro_extraction.py
  All checks passed!
uv run pyright graphify/extract.py tests/test_astro_extraction.py
  119 errors before and after (no new errors)

Real-world check on two Astro sites (old vs patched extract_astro, file by file):

Site files with parse errors nodes edges
A (42 .astro files) 42 → 0 61 → 89 215 → 326
B (37 .astro files) 37 → 0 74 → 87 297 → 368

No file lost nodes.

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.

🤖 Generated with Claude Code

extract_astro fed the whole .astro file to the JS grammar. The template is
not JS, so every page reported a syntax error (usually at line 1-2) and
symbols tree-sitter could not recover past the template were dropped.

Blank everything outside the frontmatter and JS <script> bodies (keeping
newlines so locations still match, as _vue_mask_non_script does) and parse
with the TS grammar, Astro's default. Scripts with a non-JS type
(application/ld+json, ...) are blanked too. The existing regex import
rescue is unchanged.

Fixes Graphify-Labs#2788. Covers the unmasked-script half of Graphify-Labs#3337.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Bosken85. 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.10 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 reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Parses .astro files by masking everything except the frontmatter and JS <script> bodies to spaces (preserving newlines so line numbers hold), then running the AST pass with the TS grammar instead of extracting the whole file as JS — which previously flagged every template as a syntax error and dropped frontmatter symbols. Scripts with a non-JS type (e.g. application/ld+json) are blanked, and each kept region is terminated with a ; so two <script> bodies on one line don't merge into a single statement.

No blocking issues surfaced. 10 lower-confidence candidates did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 2182 functions depend on the 278 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 716 callers, 48 callees
  • new: _rebuild_code() — 146 callers, 55 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: main() — 98 callers, 3 callees
  • new: dispatch_command() — 2 callers, 125 callees
  • new: _get_extractor() — 26 callers, 6 callees
  • new: run_pipeline() — 8 callers, 13 callees
  • …and 34 more — each is listed as a finding

Verification — 2182 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

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

Advisory (not blocking):

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

Test selection

Test selection

130 of 304 test file(s) selected (43%) via static blast radius.

  • tests/test_astro_extraction.py — impact, changed-test
  • tests/test_astro_import_ids.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_file_node_id_spec.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_builtin_call_targets.py — impact
  • tests/test_go_import_repoint.py — impact
  • tests/test_go_interface_methods.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_import_self_loops.py — impact
  • tests/test_imported_export_forwarding.py — impact
  • tests/test_incremental.py — impact
  • tests/test_indirect_call_arrow_single_param_shadow.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_call_catch_binding_shadow.py — impact
  • tests/test_indirect_call_external_import_shadow.py — impact
  • tests/test_indirect_call_for_of_binding_shadow.py — impact
  • tests/test_indirect_call_function_expression_shadow.py — impact
  • … and 80 more

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.

Docs that may be stale (advisory)

…and 10 more.

· 1 grounded finding(s) anchored inline below; 41 more finding(s) on lines outside this diff (see the check run).

Comment thread graphify/extract.py
return "".join(chars)


def extract_astro(path: Path) -> dict:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Health regression — extract_astro()

fans out to 7 callees (efferent coupling); 8 callers depend on it (afferent coupling).

Grounded coupling-delta finding (deterministic), not an LLM guess.

safishamsi added a commit that referenced this pull request Sep 30, 2026
Solidity free functions (#3906), VB.NET qualified calls (#3909), Astro
frontmatter-only AST pass (#3902), surprise bonus/reason alignment (#3934),
exclude-hubs stranded-neighbour (#3933), graph-DB push index (#3957),
label retry keep-named (#3956), stale-hook status (#3951), virtual-workspace
Cargo.toml skip (#3930), and symlinked-instructions install/uninstall
handling (#3950/#3953).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.73 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @Bosken85!

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.73

@safishamsi safishamsi closed this Sep 30, 2026
ry-diffusion pushed a commit to ry-diffusion/graphify that referenced this pull request Oct 2, 2026
Ported onto v0.9.73 from Graphify-Labs#2731 (cherry picked from commit cf51a8c).
Only the Svelte half: upstream already masks .astro with _astro_mask_non_script
(Graphify-Labs#3902), so the PR's _astro_mask/_astro_best_mask and their three tests are
dropped. The TS/TSX branch also runs _normalize_ts_import_types, as the .vue
path does and as Graphify-Labs#3928 proposes — without it `import type` leaves ERROR nodes.
ry-diffusion pushed a commit to ry-diffusion/graphify that referenced this pull request Oct 2, 2026
Ported onto v0.9.73 from Graphify-Labs#2731 (cherry picked from commit cf51a8c).
Only the Svelte half: upstream already masks .astro with _astro_mask_non_script
(Graphify-Labs#3902), so the PR's _astro_mask/_astro_best_mask and their three tests are
dropped. The TS/TSX branch also runs _normalize_ts_import_types, as the .vue
path does and as Graphify-Labs#3928 proposes — without it `import type` leaves ERROR nodes.
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.

Astro: frontmatter fails at line 1 (partial extraction), and the warning hardcodes closed Kotlin issue #2551 for every language

2 participants