Skip to content

fix(dart): link every URI of a configurable import/export (#4002) - #4003

Closed
brlumen wants to merge 1 commit into
Graphify-Labs:v8from
brlumen:fix/dart-conditional-uris
Closed

brlumen wants to merge 1 commit into
Graphify-Labs:v8from
brlumen:fix/dart-conditional-uris

Conversation

@brlumen

@brlumen brlumen commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #4002.

The Dart extractor matched import/export directives only up to the first quoted string, so every if (...) alternative of a configurable directive was dropped:

export 'service_stub.dart' if (dart.library.io) 'service_io.dart';

produced only exports -> service_stub.dart. In the usual Flutter facade the stub is an empty placeholder and the real implementation lives in the conditional branch, so the implementation was unreachable from the facade and everything importing it.

Change (section "6. Imports and Exports" of graphify/extractors/dart.py):

  • the whole directive is parsed: default URI, then any number of if (<dotted.name> [== '<value>']) '<uri>' branches (single or double quotes, across line breaks);
  • the default URI keeps exactly the edge it had before (same relation, no context);
  • each alternative gets the same relation (imports/exports) tagged context="conditional_uri" and its own source_location, so consumers can tell the platform-selected branches from the default one;
  • a string literal inside the condition (if (app.flavor == 'prod')) is part of the URI test and is not emitted as a URI.

Type of change

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

Verification & Invariants

Invariant: an import/export edge is emitted for every library URI the directive names, and only for those. The default-URI edge is unchanged (same target, relation, line, no context), so existing graphs and caches do not change for non-configurable directives; only new conditional_uri edges (and their target stub nodes) appear for configurable ones. No persisted-state format change.

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

Limitations: URIs are still minted as unresolved targets keyed by the URI string, exactly like the default URI today; resolving Dart URIs to file nodes is #2329 / #2570 and out of scope here. String interpolation in a URI is not valid Dart and is not handled.

How was this tested?

uv run pytest tests/test_dart.py -k conditional   # on unpatched v8: 1 failed (regression test reproduces the bug)
uv run pytest tests/test_dart.py tests/test_extract.py   # with the fix: 242 passed, 4 skipped
uv run pytest tests -q   # 6136 passed, 102 skipped, 28 failed - the same 28 fail on unpatched v8
                         # (erlang / r / solidity / vbnet extractors, ollama retry cap; local environment)
uv run ruff check .      # All checks passed
uv run pyright graphify/extractors/dart.py   # 0 errors

Also ran graphify extract . --code-only on a ~300-file Flutter app: all four conditional-export facades in the project now link to their *_io.dart implementations (before: no edge from any facade to its implementation).

Graphify-specific checklist

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

…abs#4002)

A configurable directive such as

    export 'service_stub.dart' if (dart.library.io) 'service_io.dart';

was matched only up to its first quoted string, so the `if` alternatives
were dropped. In the usual Flutter facade the stub is an empty placeholder
and the real implementation lives in the conditional branch, which left
the implementation unreachable from the facade and its importers.

Parse the whole directive and emit one edge per URI: the default URI keeps
its plain edge (unchanged), each alternative gets the same relation tagged
context="conditional_uri" with its own source line. A string literal inside
the condition (`if (app.flavor == 'prod')`) is part of the URI test and is
not mistaken for a URI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@brlumen
brlumen requested a review from safishamsi as a code owner October 2, 2026 16:57
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

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

Adds support for Dart configurable imports/exports (import 'x_stub.dart' if (dart.library.io) 'x_io.dart';) in extract_dart. Every if (...) branch now gets its own imports/exports edge tagged context="conditional_uri", alongside the plain edge for the default URI, and each edge points at that branch's own line. A string literal inside the condition itself, such as == 'prod', is treated as part of the test and never becomes a node.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 34 functions depend on the 33 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract_dart() — 12 callers, 7 callees

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

Test selection

Test selection

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

  • tests/test_dart.py — impact, changed-test
  • tests/test_extract.py — impact

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)

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

@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.75 (live on PyPI as graphifyy==0.9.75). Landed on v8 via an authorship-preserving cherry-pick, so your original commit authorship is kept. Thanks @brlumen for linking every URI of a configurable Dart import/export 🙏

Closing as shipped.

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]: Dart conditional import/export links only the default URI, dropping the platform implementation

2 participants