Skip to content

fix(extract): prevent false cycles from same-stem CSS imports - #5653

Open
rvitaliy wants to merge 1 commit into
Graphify-Labs:v8from
rvitaliy:feature/css-import-cycle-identity
Open

rvitaliy wants to merge 1 commit into
Graphify-Labs:v8from
rvitaliy:feature/css-import-cycle-identity

Conversation

@rvitaliy

@rvitaliy rvitaliy commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #5652. When Card.tsx imports ./Card.css and the stylesheet has no indexed file node, the old extensionless target can resolve to Card.tsx itself. This adds a spurious one-file cycle to graphify cycles and can send other importers of that stylesheet to the component.

A resolved stylesheet dependency now points to its indexed CSS file node when one exists. Otherwise both graph writers retain a source-less reference keyed by the portable path, including the extension. The import keeps its source location. An incremental run can reuse the indexed stylesheet from the persisted graph, including a file with a disambiguated ID. Named JS/TS re-exports of ordinary CSS keep the file-level dependency, since the CSS extractor does not declare JavaScript named exports.

Verification & invariants

  • Bug fix with a regression test that fails on v0.9.124.
  • The CLI fixture runs graphify extract --code-only --no-cluster and then graphify cycles --json. Its complete cycle list must contain exactly the genuine self.ts self-import. Two different TSX files must point to the same stylesheet reference.
  • Additional cases cover indexed Shopify CSS, an importer-only edit, a named re-export, and collisions with code IDs and legacy aliases in both graph writers.
  • The Astro import test checks all three expected targets and still rejects IDs that embed the checkout path.
  • Read the contribution guide, updated the architecture notes, and disclosed AI assistance in the commit. The fixtures are synthetic.

The change applies to resolved .css dependencies. To refresh existing edges in a raw code graph, run graphify extract . --code-only --no-cluster --force once.

How was this tested?

  • graphify extract . --code-only --no-cluster and graphify cycles --json on a separate seven-file sample. The base reports three false TSX cycles and one real TypeScript self-import. With this fix the only cycle is the real self-import.
  • python -m pytest -q tests/test_cycles_cli.py tests/test_css_extractor.py tests/test_build.py tests/test_cross_extension_reexport_self_cycle.py tests/test_type_only_import_cycles.py tests/test_astro_import_ids.py on Python 3.11 and 3.13.
  • uv run --locked --all-extras ruff check ., git diff --check, and uv run --locked --all-extras graphify update ..
  • uv run --locked --all-extras pyright --outputjson reports the same 767 pre-existing diagnostics on the base and head, compared by file, severity, and message.
  • Full local tests/ suite on CPython 3.14.10: 12,631 passed, 135 skipped, 2 expected failures. Ran the non-serial set with pytest tests -q --tb=short -n 6 --dist worksteal -m 'not serial', excluding the worker-size and three language-override modules from that invocation and running their non-serial cases in one process. Ran pytest tests -q --tb=short -m serial for the serial set.

Resolve CSS imports against indexed stylesheet files or an extension-bearing asset reference. Preserve that identity through incremental extraction and both graph writers. Exercise the cycles CLI with a same-stem stylesheet and a genuine TypeScript self-import.

Co-Authored-By: Codex <[email protected]>
@rvitaliy
rvitaliy requested a review from safishamsi as a code owner November 30, 2026 20:02
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 30, 2026
@github-actions

Copy link
Copy Markdown

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

@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 review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

Extraction now preserves dependencies on unindexed stylesheets and removes CSS symbol-level import edges.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 8 of 8 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 8017 functions depend on this change
  • 3 functions became more coupled. extract() (1453 callers), build_from_json() (357 callers), finalize_raw_graph_endpoints() (14 callers).
  • 665 of 665 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 5a5faf9

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.

[Bug]: A sibling CSS import creates a false TypeScript self-import cycle

1 participant