@@ -3328,3 +3328,54 @@ def test_rewire_does_not_bind_supertype_stub_to_function():
33283328 "source_file" : "store.py" , "weight" : 1.0 }]
33293329 _rewire_unique_stub_nodes (nodes , edges )
33303330 assert edges [0 ]["target" ] == "BookStore" # inherits stub not bound to function
3331+
3332+
3333+ def test_extract_emits_posix_source_file_for_relative_inputs (tmp_path ):
3334+ r"""source_file must be canonical POSIX on every node AND edge, whatever
3335+ separator the caller's input paths used.
3336+
3337+ Extractors build source_file from the Path handed to them, and only the
3338+ relativizing branch of extract()'s remap calls as_posix(), so a run given
3339+ relative inputs used to keep the native separator on Windows — mixing
3340+ `src\lib\content.ts` and `src/pages/index.astro` in one extraction.
3341+ source_file is compared as a string downstream (build keying, prune-root
3342+ derivation, dedup, analyze.find_import_cycles), so two spellings are two
3343+ different files (#683 / #2625).
3344+
3345+ Uses the relative-input form deliberately: passing an explicit ``root``
3346+ takes the branch that already normalized, and would make this vacuous.
3347+ """
3348+ (tmp_path / "src" / "lib" ).mkdir (parents = True )
3349+ (tmp_path / "src" / "pages" ).mkdir (parents = True )
3350+ (tmp_path / "src" / "lib" / "content.ts" ).write_text (
3351+ "export function getPosts() { return []; }\n " , encoding = "utf-8"
3352+ )
3353+ (tmp_path / "src" / "pages" / "index.astro" ).write_text (
3354+ "---\n import { getPosts } from '../lib/content';\n "
3355+ "const posts = getPosts();\n ---\n <h1>{posts.length}</h1>\n " ,
3356+ encoding = "utf-8" ,
3357+ )
3358+
3359+ cwd = os .getcwd ()
3360+ os .chdir (tmp_path )
3361+ try :
3362+ result = extract ([Path ("src/lib/content.ts" ), Path ("src/pages/index.astro" )])
3363+ finally :
3364+ os .chdir (cwd )
3365+
3366+ carriers = [
3367+ (kind , item .get ("source_file" ))
3368+ for kind , items in (("node" , result ["nodes" ]), ("edge" , result ["edges" ]))
3369+ for item in items
3370+ if item .get ("source_file" )
3371+ ]
3372+ assert carriers , "fixture produced nothing with a source_file; test would be vacuous"
3373+
3374+ offenders = [(kind , sf ) for kind , sf in carriers if "\\ " in sf ]
3375+ assert not offenders , f"native separator survived into source_file: { offenders } "
3376+
3377+ # ...and both files are present under one spelling each, so the graph sees
3378+ # two files rather than four.
3379+ assert {sf for _ , sf in carriers } == {
3380+ "src/lib/content.ts" , "src/pages/index.astro" ,
3381+ }
0 commit comments