Skip to content

fix(ruby): emit mixes_in for include/prepend inside class << self - #5317

Open
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/ruby-singleton-class-mixin-v2
Open

Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/ruby-singleton-class-mixin-v2

Conversation

@Synvoya

@Synvoya Synvoya commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Re-submission of #1816, rebased onto current v8 (340268a), which supersedes it.

An include/prepend inside a class << self block injects the module's instance methods as the enclosing class's own singleton (class) methods, the same relationship extend Mod expresses in the class body, which the extractor already captures as mixes_in (#1668). The Ruby mixin scan only walked the class/module body's direct children, so the nested form produced no edge:

module Announceable
  def announce; end
end

class Broadcaster
  class << self
    include Announceable   # Broadcaster gains `announce` as a class method
  end
end

The scan now also iterates the statements of class << self blocks in the body, reusing the existing constant-argument filter and the single-owner resolver guard. Only self counts: class << other opens a different object's singleton class, so an include there stays unlinked.

Type of change

  • Bug fix

Verification & Invariants

Invariant: a module mixed into a class's singleton class is a mixes_in of that class, however it is written. The negative test covers class << obj, which must not produce an edge.

Limitation: only class << self blocks directly in the class/module body are scanned; one nested inside a method or a conditional is not.

Cached Ruby extractions need a schema bump to pick this up. I left _AST_CACHE_SCHEMA alone, since recent fixes have it folded into your combined bump; happy to add it here instead.

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

Python 3.11.16 on macOS, environment from uv sync --all-extras, branch based on v8 340268a.

pytest tests/test_ruby_resolution.py   # 70 passed with the fix; 1 failed with engine.py reverted (test_include_in_singleton_class_emits_mixes_in)
pytest tests -q                        # v8: 11548 passed, 165 skipped, 1 xfailed; this branch: 11549 passed, 1 failed, same skips
    # the failure was tests/test_language_override_lifecycle.py::test_watch_declared_code_updates_graph_on_observer_thread,
    # a watch observer-thread test, while four full suites ran in parallel on one machine; that file passed 3/3 rerun on its own.
    # This change does not touch watch code.
ruff check .                           # All checks passed
pyright                                # 759 errors on v8 and on this branch; same set, none new (compared ignoring line numbers)

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.

AI disclosure: drafted with help from Claude Code and reviewed before posting; the commit carries a Co-Authored-By trailer.

An `include`/`prepend` inside a `class << self` block injects the
module's instance methods as the enclosing class's own singleton
(class) methods — the very mixin relationship `extend <Mod>` expresses
in the class body, which the extractor already captures (Graphify-Labs#1668). The
mixin scan only walked the class/module body's direct children, so the
`class << self` form was silently dropped and emitted no `mixes_in`
edge.

Scan `class << self` blocks as well, reusing the existing
constant-argument filter and the single-owner resolver guard. Only
`self` counts: `class << other` opens a different object's singleton,
not the enclosing class's, so an include there stays unlinked.

Co-Authored-By: Claude <noreply@anthropic.com>
@Synvoya
Synvoya requested a review from safishamsi as a code owner November 18, 2026 13:59
@github-actions

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 18, 2026

@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 · a82f30f1c57f

Tip

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

The extractor now scans direct statements inside class << self when collecting Ruby mixin relationships.

Full summary

The extractor now scans direct statements inside class << self when collecting Ruby mixin relationships. A regression test checks that this adds a mixes_in edge while class << obj does not.

Code graph and static checks · 4380 functions depend on this change

Impact & health

Impact — 4380 functions depend on the 572 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1284 callers, 78 callees

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

Test selection

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

  • tests/test_4992_ts_import_types.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.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_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_dart.py — impact
  • tests/test_dart_typedef.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_php_closures.py — impact
  • tests/test_import_extension_resolution.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_java_nested_type_identity.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_languages.py — impact
  • tests/test_multilang.py — impact
  • tests/test_php_unparsed_casts.py — impact
  • tests/test_python_inherited_method_calls.py — impact
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_python_subscript_type_refs.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact, changed-test
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_extension_methods.py — impact
  • tests/test_scala_given_instances.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_scala_top_level_binding.py — impact
  • tests/test_scala_type_definition.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • … and 2 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.

Every flagged function

  • extract() in graphify/extract.py:11742 · 1284 callers, 78 callees: fans out to 78 callees (efferent coupling); 1284 callers depend on it (afferent coupling)

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

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant