Skip to content

fix(razor): extract methods from @functions blocks, not just @code - #3908

Closed
rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/razor-functions-block
Closed

rajatnagda45 wants to merge 1 commit into
Graphify-Labs:v8from
rajatnagda45:fix/razor-functions-block

Conversation

@rajatnagda45

Copy link
Copy Markdown
Contributor

What does this PR do?

@code is the Blazor (.razor) spelling of an embedded C# member block; @functions is the equivalent Razor Pages / MVC (.cshtml) spelling. Both compile to class members, and this extractor serves both file types (.razor and .cshtml route here), but only @code was matched. A .cshtml page that declares its methods inside an @functions { } block lost every one of them — the methods simply weren't nodes.

@functions {
    public int Square(int x) { return x * x; }
    public string Greet() { return "hi"; }
}

Before: Square and Greet absent. After: both extracted, exactly as their @code equivalents already were.

Type of change

  • Bug fix

Verification & Invariants

Invariant protected: extraction completeness — a real, source-backed member block must not be dropped just because it uses the other legal spelling. The fix is a single alternation in the block-detecting regex (@(?:code|functions)\s*\{); the existing brace-balanced body scan and method extraction are reused unchanged, so there is no new heuristic and no determinism/ambient-state impact.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (fails before the fix, passes after).
  • Kept the PR description synchronized with the final implementation.
  • Documented limitations: only method declarations carrying an access modifier are captured (unchanged from the existing @code behaviour).

How was this tested?

python -m pytest tests/test_languages.py -k razor -q     # passes (new test fails on pre-fix tree)
python -m pytest tests/ -q \
  --deselect tests/test_security.py \
  --deselect "tests/test_install_references.py::test_built_wheel_ships_the_full_skill_payload"
# 6037 passed, 15 skipped
ruff check graphify/extractors/razor.py    # clean
pyright graphify/extractors/razor.py       # 0 errors

Graphify-specific checklist

  • No generated skill artifacts touched.
  • Confirmed extraction remains deterministic (pure regex over file text, no ambient state).
  • Reviewed for security implications (no shell/Python interpolation of template text).
  • No API keys or local graph data included.

@code is the Blazor (.razor) spelling of an embedded C# member block;
@functions is the equivalent Razor Pages / MVC (.cshtml) spelling. Both
compile to class members, and this extractor serves both file types, but
only @code was matched. A .cshtml page that declared its methods inside an
@functions block lost every one of them.

Match @functions alongside @code in the block regex; the existing
brace-balanced body scan and method extraction are reused unchanged.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @rajatnagda45. 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

Extends the Razor extractor's method-block detection to recognise @functions blocks alongside @code, so methods declared in .cshtml (Razor Pages/MVC) files are now extracted as class members instead of being dropped. Adds test_razor_finds_functions_block_methods covering the .cshtml @functions spelling.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 606 functions depend on the 600 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract_razor() — 15 callers, 4 callees

Verification — 606 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: 606 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

2 of 304 test file(s) selected (1%) via static blast radius.

  • tests/test_dotnet.py — impact
  • tests/test_languages.py — impact, changed-test

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.

· 1 grounded finding(s) anchored inline below.

@@ -9,7 +9,7 @@


def extract_razor(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_razor()

15 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 29, 2026
…ction

HTML node-info field fix (#3918), Kotlin annotated-inferred-property
crash (#3915/#3899), SQL DDL-before-DO (#3900), Razor @functions (#3908),
Blade @extends (#3907), and imported-module resolution (#3898).

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

Copy link
Copy Markdown
Member

Shipped in v0.9.72 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @rajatnagda45! Razor @functions blocks are extracted, not just @code.

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

@safishamsi safishamsi closed this Sep 29, 2026
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.

2 participants