Skip to content

fix(php): stop the route path scan at the closure's own argument (#5135) - #5141

Closed
mppyxx wants to merge 1 commit into
Graphify-Labs:v8from
mppyxx:fix/php-route-prefix-node-identity
Closed

mppyxx wants to merge 1 commit into
Graphify-Labs:v8from
mppyxx:fix/php-route-prefix-node-identity

Conversation

@mppyxx

@mppyxx mppyxx commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Closes #5135.

_php_get_route_name reads a route's path (or an enclosing group's prefix) from the string arguments before the closure, and stops at the closure's own argument with sibling is curr. py-tree-sitter hands back a new Node object on every access, so is never matched. The scan ran past the closure and took a string argument after it:

PHP v8 label with this PR
$app->get(function () { return 1; }, '/late'); GET /late() {closure#1}() (not a route)
$app->group(function ($g) { $g->get('/users', fn); }, '/late'); GET /late/users() GET /users()
$app->group('/api/v1', function ($g) { $g->get('/users/{id}', fn); }); GET /api/v1/users/{id}() unchanged

The fix compares with ==, which py-tree-sitter defines on the node's identity in the tree, the same as the #5113 fix. _AST_CACHE_SCHEMA goes 43 -> 44 so cached PHP extractions re-run.

Diff: engine.py +4/-1, cache.py +1/-1, two tests in tests/test_extract_php_closures.py.

Type of change

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

Verification & Invariants

Invariant: a PHP route closure's path and its group prefixes come only from arguments that precede the closure in their call. Persisted state: PHP labels can change for files that hit this case, so the AST cache schema is bumped and cached PHP extractions re-run. Routes with the path before the closure (every existing fixture) keep their labels.

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

# both new tests fail with `is` and pass with `==`
uv run pytest tests/test_extract_php_closures.py -q -k "before_the_closure or after_the_closure"   # with `is`: 2 failed
uv run pytest tests/test_extract_php_closures.py -q                                               # with `==`: 9 passed
uv run pytest tests -q          # 11016 passed, 133 skipped, 2 failed (both fail the same way on v8 without this change, see below)
uv run --python 3.10 pytest tests/test_extract_php_closures.py -q   # 9 passed
uv run --python 3.13 pytest tests/test_extract_php_closures.py -q   # 9 passed
uv run ruff check .             # All checks passed!
uv run pyright graphify/extractors/engine.py graphify/cache.py   # 23 errors, the same 23 as on v8 without this change

The two failures in the full run are unrelated and reproduce on a clean v8 checkout here (macOS, Python 3.12, uv):

  • tests/test_languages.py::test_cpp_paired_merged_node_records_definition_site: definition_file comes out relative to a different root than source_file (PosixPath('.') != PosixPath('../../../../../../../Users/.../tests/fixtures/cpp_paired')), so it looks checkout-location dependent.
  • tests/test_skill_no_backtick_substitution.py::test_control_a_backticked_unknown_command_is_caught

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill sources 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

…phify-Labs#5135)

_php_get_route_name reads a route's path (or a group's prefix) from the
string arguments before the closure, and stops at the closure's argument
with `sibling is curr`. py-tree-sitter hands back a new Node object on every
access, so `is` never matched: the scan ran past the closure and took a
string argument after it. `$app->get(function () {...}, '/late')` became a
`GET /late` route, and `$app->group(function ($g) { $g->get('/users', ...); },
'/late')` labelled the inner route `GET /late/users`. Compare with `==`,
which py-tree-sitter defines on the node's identity in the tree. Same class
of bug as Graphify-Labs#5113.

Bump _AST_CACHE_SCHEMA to 44 so cached PHP extractions re-run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mppyxx
mppyxx requested a review from safishamsi as a code owner November 10, 2026 23:09
Copilot AI balanced review requested due to automatic review settings November 10, 2026 23:09

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@github-actions

Copy link
Copy Markdown

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

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).

Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: \_php\_get\_route\_name (vacuous: never exercised).


Graphify review — findings

Bumps the AST cache schema so cached extractions re-run, and widens extractor coverage across several languages: Swift constructor types and in-scope type parameters, Java and Kotlin annotation names, C++ parameter types and header-guard detection, Scala type refs, Ruby local class bindings, JS/Python dispatch-table values, and TS public/private twin marking. A PHP generic closure now gets an ordinal name. In the semantic cache, save_semantic_cache recovers group paths and handles hyperedges that dangle. Cache keys also pick up a grammar fingerprint, and stat keys can be mapped back to absolute paths. The diff is truncated, so this summary is based on the visible schema-bump comment and the changed symbol names.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 4530 functions depend on the 542 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract_php() — 40 callers, 5 callees

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

Test selection

Test selection

97 of 554 test file(s) selected (18%) via static blast radius.

  • tests/test_4992_ts_import_types.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_binary_media_words.py — impact
  • tests/test_build.py — impact
  • tests/test_cache.py — impact
  • tests/test_cache_long_paths.py — impact
  • tests/test_cache_stale_import_target.py — impact
  • tests/test_cache_windows_case_4925.py — impact
  • tests/test_charmap_encoding.py — impact
  • tests/test_chunking.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_code_only_scope_4923.py — impact
  • tests/test_cpp_alias_member_resolution.py — impact
  • tests/test_cpp_conditional_initializers.py — impact
  • tests/test_cpp_inherited_member_resolution.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_template_members.py — impact
  • tests/test_csharp_extension_calls.py — impact
  • tests/test_csharp_extension_metadata.py — impact
  • tests/test_csharp_extension_resolution.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_cli.py — impact
  • tests/test_extract_php_closures.py — impact, changed-test
  • tests/test_grammar_cache_key.py — impact
  • tests/test_hook_content_freshness.py — impact
  • tests/test_ignore_file_encoding.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_incremental_mtime_collision.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_language_override_lifecycle.py — impact
  • tests/test_language_overrides.py — impact
  • tests/test_languages.py — impact
  • tests/test_linked_worktree_reconcile.py — impact
  • tests/test_llm_backends.py — impact
  • tests/test_manifest_ingest.py — impact
  • tests/test_msbuild_dir_evidence.py — impact
  • tests/test_multilang.py — impact
  • … and 47 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.

Formal verification

Could not verify: Could not verify \_php\_get\_route\_name.

The verifier did not have enough to check \_php\_get\_route\_name, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: not verifiable: all 66 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed on v8 as 094a007 via authorship-preserving cherry-pick, released in graphify 0.9.107. Thanks @mppyxx.

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.

[Bug]: PHP route-prefix loop uses is on tree-sitter nodes (same class as #5113)

3 participants