Skip to content

Commit e56e965

Browse files
fix(python): clang-format pkgmap + ghost-module CALLS negative
Unblock CI lint so the test job runs. Prefer Homebrew LLVM formatting on the member IMPORTS retarget. Add contract that `from ghost_module import nope as alias; alias()` emits no CALLS. Relabel registry alias pin as adversarial (behavior already on main). Signed-off-by: 涂名恩 <125283161+Joseph-MingEn@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 61a0542 commit e56e965

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎src/pipeline/pass_pkgmap.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,8 @@ const cbm_gbuf_node_t *cbm_pipeline_resolve_import_node(const cbm_pipeline_ctx_t
15301530
char symbuf[256];
15311531
const char *sym = import_candidate_symbol(imp->module_path, symbuf, sizeof(symbuf));
15321532
if (sym && sym[0] && strcmp(sym, "*") != 0) {
1533-
const char *mod_tail = import_last_segment(target->qualified_name
1534-
? target->qualified_name
1535-
: "");
1533+
const char *mod_tail =
1534+
import_last_segment(target->qualified_name ? target->qualified_name : "");
15361535
if (!mod_tail || strcmp(mod_tail, sym) != 0) {
15371536
char member_qn[CBM_SZ_512];
15381537
snprintf(member_qn, sizeof(member_qn), "%s.%s", target->qualified_name, sym);

‎tests/test_lang_contract.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,47 @@ TEST(contract_python_absolute_aliased_from_import_calls) {
553553
PASS();
554554
}
555555

556+
/* Python: unresolvable module + alias must emit no CALLS (no invented edge). */
557+
TEST(contract_python_ghost_module_aliased_from_import_no_calls) {
558+
static const LangFile f[] = {
559+
{"router.py",
560+
"from ghost_module import nope as alias\n\n\n"
561+
"def submit_task(y):\n return alias(y)\n"}};
562+
LangProj lp;
563+
cbm_store_t *store = lang_index_files(&lp, f, 1);
564+
ASSERT_TRUE(store != NULL);
565+
cbm_node_t *nodes = NULL;
566+
int ncount = 0;
567+
ASSERT_EQ(cbm_store_find_nodes_by_name(store, lp.project, "submit_task", &nodes, &ncount),
568+
CBM_STORE_OK);
569+
ASSERT_TRUE(ncount >= 1);
570+
char **callers = NULL;
571+
char **callees = NULL;
572+
int n_callers = 0;
573+
int n_callees = 0;
574+
ASSERT_EQ(cbm_store_node_neighbor_names(store, nodes[0].id, 32, &callers, &n_callers, &callees,
575+
&n_callees),
576+
0);
577+
int saw_any_callee = 0;
578+
for (int i = 0; i < n_callees; i++) {
579+
if (callees[i] && callees[i][0]) {
580+
saw_any_callee = 1;
581+
}
582+
}
583+
for (int i = 0; i < n_callers; i++) {
584+
free(callers[i]);
585+
}
586+
for (int i = 0; i < n_callees; i++) {
587+
free(callees[i]);
588+
}
589+
free(callers);
590+
free(callees);
591+
cbm_store_free_nodes(nodes, ncount);
592+
lang_cleanup(&lp, store);
593+
ASSERT_FALSE(saw_any_callee);
594+
PASS();
595+
}
596+
556597
/* TypeScript: a relative import resolves to a sibling module → IMPORTS edge. */
557598
TEST(contract_typescript_relative_import) {
558599
static const LangFile f[] = {
@@ -1724,6 +1765,7 @@ SUITE(lang_contract) {
17241765
RUN_TEST(contract_python_relative_import);
17251766
RUN_TEST(contract_python_aliased_from_import_calls);
17261767
RUN_TEST(contract_python_absolute_aliased_from_import_calls);
1768+
RUN_TEST(contract_python_ghost_module_aliased_from_import_no_calls);
17271769
RUN_TEST(contract_typescript_relative_import);
17281770

17291771
/* Graph-level breadth across all grammars (P4). */

‎tests/test_registry.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ TEST(resolve_import_map_bare_alias) {
386386
PASS();
387387
}
388388

389-
/* from M import execute as bridge_execute + bridge_execute() — IMPORTS target is
390-
* already the def QN. Must CALLS→execute, not invent …M.bridge_execute.
391-
* Yui G1 shape (alongside resolve_import_map_bare_alias). */
389+
/* Adversarial pin: when import_map already stores the def QN under the alias
390+
* key, bare alias call must CALLS→def (not invent …M.bridge_execute). Behavior
391+
* already on main via #875/#979; this locks the Yui G1 shape. */
392392
TEST(resolve_import_map_aliased_from_import) {
393393
cbm_registry_t *r = cbm_registry_new();
394394
cbm_registry_add(r, "execute", "proj.services.satori_bridge.gate.execute", "Function");

0 commit comments

Comments
 (0)