Skip to content

Commit 89e1c47

Browse files
author
LA-10
committed
fix(registry): resolve aliased direct-symbol imports in import_map
Signed-off-by: LA-10 <lashuha@uwaterloo.com>
1 parent 3d8d2c1 commit 89e1c47

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

‎src/pipeline/registry.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ static cbm_resolution_t resolve_import_map(const cbm_registry_t *r, const char *
618618
* function name and suffix is NULL, so the target QN must be
619619
* resolved.requireAdmin — not just resolved, which would point at the
620620
* module node and miss the function entirely. */
621+
const char *direct = cbm_ht_get_key(r->exact, resolved);
622+
if (direct) {
623+
return (cbm_resolution_t){direct, "import_map", CONF_IMPORT_MAP, REG_RESOLVED};
624+
}
621625
char candidate[CBM_SZ_512];
622626
if (suffix && suffix[0]) {
623627
snprintf(candidate, sizeof(candidate), "%s.%s", resolved, suffix);

‎tests/test_registry.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,25 @@ TEST(resolve_import_map_bare_function) {
367367
PASS();
368368
}
369369

370+
/* Aliased bare import (`from m import f as g`, called as g()). The import-map
371+
* value is the full symbol QN (IMPORTS edge targets the function node), and
372+
* the callee at the site is the alias g — NOT f. Resolution must return the
373+
* symbol directly instead of appending the alias (which yields m.f.g → miss).
374+
* Regression for #875. */
375+
TEST(resolve_import_map_bare_alias) {
376+
cbm_registry_t *r = cbm_registry_new();
377+
cbm_registry_add(r, "scan_bash", "proj.security_scan.scan_bash", "Function");
378+
/* Import map: alias "_scan_bash" → FULL SYMBOL QN (not the module). */
379+
const char *keys[] = {"_scan_bash"};
380+
const char *vals[] = {"proj.security_scan.scan_bash"};
381+
cbm_resolution_t res =
382+
cbm_registry_resolve(r, "_scan_bash", "proj.hooks.pre_tool", keys, vals, 1);
383+
ASSERT_STR_EQ(res.qualified_name, "proj.security_scan.scan_bash");
384+
ASSERT_STR_EQ(res.strategy, "import_map");
385+
cbm_registry_free(r);
386+
PASS();
387+
}
388+
370389
TEST(resolve_unique_name) {
371390
cbm_registry_t *r = cbm_registry_new();
372391
cbm_registry_add(r, "UniqueFunc", "proj.deep.path.UniqueFunc", "Function");
@@ -818,6 +837,7 @@ SUITE(registry) {
818837
RUN_TEST(resolve_qualified_ambiguous_tail_falls_through);
819838
RUN_TEST(resolve_import_map);
820839
RUN_TEST(resolve_import_map_bare_function);
840+
RUN_TEST(resolve_import_map_bare_alias);
821841
RUN_TEST(resolve_unique_name);
822842
RUN_TEST(resolve_unresolved);
823843
RUN_TEST(resolve_many_nodes);

0 commit comments

Comments
 (0)