@@ -266,6 +266,102 @@ static int ei_edge_present(const EILangFile *files, int nfiles, const char *edge
266266 return got >= floor ;
267267}
268268
269+ typedef struct {
270+ const char * importer ;
271+ const char * target ;
272+ } EIFileEdgeExpect ;
273+
274+ static int ei_file_edges_match (const EILangFile * files , int nfiles , const EIFileEdgeExpect * want ,
275+ int nwant , int expected_count ) {
276+ EILangProj lp ;
277+ cbm_store_t * store = ei_index_files (& lp , files , nfiles );
278+ int ok = store && cbm_store_count_edges_by_type (store , lp .project , "IMPORTS" ) == expected_count ;
279+ if (store && !ok ) {
280+ int got = cbm_store_count_edges_by_type (store , lp .project , "IMPORTS" );
281+ fprintf (stderr , " [IMPORTS] FAIL count=%d expected==%d\n" , got , expected_count );
282+ }
283+ for (int i = 0 ; store && i < nwant ; i ++ ) {
284+ int64_t source_id = ei_node_id_for_file_label (store , lp .project , want [i ].importer , "File" );
285+ cbm_edge_t * edges = NULL ;
286+ int edge_count = 0 ;
287+ int found = 0 ;
288+ if (source_id > 0 &&
289+ cbm_store_find_edges_by_source_type (store , source_id , "IMPORTS" , & edges , & edge_count ) ==
290+ CBM_STORE_OK ) {
291+ for (int j = 0 ; j < edge_count ; j ++ ) {
292+ cbm_node_t target ;
293+ memset (& target , 0 , sizeof (target ));
294+ if (cbm_store_find_node_by_id (store , edges [j ].target_id , & target ) == CBM_STORE_OK ) {
295+ found = target .file_path && strcmp (target .file_path , want [i ].target ) == 0 ;
296+ cbm_node_free_fields (& target );
297+ }
298+ if (found ) {
299+ break ;
300+ }
301+ }
302+ }
303+ cbm_store_free_edges (edges , edge_count );
304+ if (!found ) {
305+ fprintf (stderr , " [IMPORTS] FAIL %s -> %s\n" , want [i ].importer , want [i ].target );
306+ ok = 0 ;
307+ }
308+ }
309+ ei_cleanup (& lp , store );
310+ return ok ;
311+ }
312+
313+ TEST (ei_relative_astro_css_imports_issue2558 ) {
314+ static const EILangFile f [] = {
315+ {"Badge.astro" , "<span>outside</span>\n" },
316+ {"src/components/shared/Button.astro" ,
317+ "---\nexport function buttonLabel(t: string): string { return t; }\n---\n<button />\n" },
318+ {"src/components/Badge.astro" , "<span>badge</span>\n" },
319+ {"src/components/Card.astro" ,
320+ "---\nimport Badge from './Badge.astro';\n"
321+ "import Button from './shared/Button.astro';\n---\n<div><Badge /><Button /></div>\n" },
322+ {"src/layouts/local.css" , "body { margin: 0; }\n" },
323+ {"src/styles/global.css" , "body { color: black; }\n" },
324+ {"src/layouts/Layout.astro" ,
325+ "---\nimport '../styles/global.css';\nimport './local.css';\n---\n"
326+ "<html><body><slot /></body></html>\n" },
327+ {"src/lib/format.ts" , "export function formatTitle(t: string): string { return t.trim(); }\n" },
328+ {"src/lib/registry.ts" ,
329+ "import Badge from '../components/Badge.astro';\n"
330+ "import '../styles/global.css';\n"
331+ "import { formatTitle } from './format';\n"
332+ "export function registry(): unknown[] { return [Badge, formatTitle]; }\n" },
333+ {"src/lib/sub/deep.ts" ,
334+ "import { formatTitle } from '../format';\n"
335+ "import { registry } from '../registry.ts';\n"
336+ "export function deep(): string { registry(); return formatTitle('x'); }\n" },
337+ {"src/pages/index.astro" ,
338+ "---\nimport Layout from '../layouts/Layout.astro';\n"
339+ "import Card from '../components/Card.astro';\n"
340+ "import Outside from '../../../Badge.astro';\n"
341+ "import { formatTitle } from '../lib/format';\n"
342+ "const title = formatTitle(' Home ');\n---\n"
343+ "<Layout><h1>{title}</h1><Card /></Layout>\n" },
344+ };
345+ static const EIFileEdgeExpect want [] = {
346+ {"src/components/Card.astro" , "src/components/Badge.astro" },
347+ {"src/components/Card.astro" , "src/components/shared/Button.astro" },
348+ {"src/layouts/Layout.astro" , "src/styles/global.css" },
349+ {"src/layouts/Layout.astro" , "src/layouts/local.css" },
350+ {"src/lib/registry.ts" , "src/components/Badge.astro" },
351+ {"src/lib/registry.ts" , "src/styles/global.css" },
352+ {"src/lib/registry.ts" , "src/lib/format.ts" },
353+ {"src/lib/sub/deep.ts" , "src/lib/format.ts" },
354+ {"src/lib/sub/deep.ts" , "src/lib/registry.ts" },
355+ {"src/pages/index.astro" , "src/layouts/Layout.astro" },
356+ {"src/pages/index.astro" , "src/components/Card.astro" },
357+ {"src/pages/index.astro" , "src/lib/format.ts" },
358+ };
359+
360+ ASSERT_TRUE (ei_file_edges_match (f , (int )(sizeof (f ) / sizeof (f [0 ])), want ,
361+ (int )(sizeof (want ) / sizeof (want [0 ])), 12 ));
362+ PASS ();
363+ }
364+
269365/* ═══════════════════════════════════════════════════════════════════════════
270366 * GREEN GUARD — Python
271367 *
@@ -1604,6 +1700,8 @@ TEST(ei_php_psr4_missing_class_file_unresolved_issue1186) {
16041700 * ═══════════════════════════════════════════════════════════════════════════ */
16051701
16061702SUITE (edge_imports ) {
1703+ RUN_TEST (ei_relative_astro_css_imports_issue2558 );
1704+
16071705 /* ── GREEN GUARDS — Python (must stay passing) ── */
16081706 RUN_TEST (ei_python_relative_from_import );
16091707 RUN_TEST (ei_python_absolute_import );
0 commit comments