Skip to content

A single extraction emits source_file with mixed path separators (src\lib\content.ts and src/pages/index.astro in the same output) on Windows #2625

Open

Description

@rajarshidattapy

Labels: bug, windows, extract, node-identity
Version: 0.9.38 (commit 10ad921)
Environment: Windows 11, Python 3.13.6

Summary

When extract() is handed relative paths, the source_file written onto nodes keeps the
native separator for some extractors and is normalised to POSIX for others — inside one
extraction run. The graph then contains two spellings of the same directory layout, which is
the fragmentation #683 described.

Steps to reproduce

project/
  src/lib/content.ts      export function getPosts() { return []; }
  src/pages/index.astro   ---
                          import { getPosts } from '../lib/content';
                          const posts = getPosts();
                          ---
                          <h1>{posts.length}</h1>

Using the module's own documented entry point, with relative arguments:

$ python -m graphify.extract src/lib/content.ts src/pages/index.astro

Actual behavior

"id": "lib_content",            "source_file": "src\\lib\\content.ts"
"id": "lib_content_getposts",   "source_file": "src\\lib\\content.ts"
"id": "pages_index",            "source_file": "src/pages/index.astro"
"id": "src_pages_index_posts",  "source_file": "src/pages/index.astro"

Two separator conventions in one document. The .ts nodes use \, the .astro nodes use
/.

Expected behavior

Every source_file is the canonical root-relative POSIX form, matching what the CLI
already produces. For contrast, the same project through the normal CLI path is correct:

$ python -m graphify extract .
...
"id": "src_a",  "source_file": "src/a.py"     # POSIX, consistent

and passing an explicit root is also correct:

extract(paths, root=Path(".").resolve())
# source_file = "src/lib/content.ts"  and  "src/pages/index.astro"   -- both POSIX

So the canonical behaviour exists; the relative-input path just misses the normalisation.

Impact

source_file is compared as a string in several places, so the two spellings are
different files as far as graphify is concerned:

Reachability

Reachable from the documented python -m graphify.extract <file> ... entry point
(graphify/extract.py:6513-6523), which calls extract(paths) with no root, and from
any library caller following ARCHITECTURE.md (see issue_9.md — that document advertises
extract(path) as the public API).

The primary graphify extract CLI passes root and is not affected.

Root cause

The source_file value is taken from the input path as given, and only the explicit-root
branch runs it through the POSIX normalisation. The inferred-root fallback
(graphify/extract.py:5197-5211) computes a root but the per-extractor source_file
assignment is not uniformly as_posix()-normalised — the .astro extractor happens to
normalise, the shared jsts path does not.

Suggested fix

Normalise once, centrally, in the extract() post-pass that already walks every node to
canonicalise IDs — rather than in each extractor:

for n in nodes:
    sf = n.get("source_file")
    if sf:
        n["source_file"] = PurePath(sf).as_posix()

That is the single choke point all extractors route through, so it also covers the ones not
exercised here.

Collateral evidence

tests/test_astro_import_ids.py::test_astro_relative_inputs_keep_canonical_ids fails on
Windows on a clean checkout for exactly this reason:

assert 'src\\lib\\content.ts' == 'src/lib/content.ts'

Related

Activity

  1. added a commit that references this issue on Sep 5, 2026
    1bd4f06
  2. added a commit that references this issue on Oct 16, 2026
    04e2d66
  3. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by ce942e14 (fix(extract): canonicalize source_file to POSIX separators (#2627)). Could a maintainer confirm and close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions