Skip to content

Commit 9ce0c1c

Browse files
committed
fix: address review feedback on external-import-shadow guard
- specifier_is_relative() now also recognizes Windows drive-letter (C:\ / C:/) and UNC (\\server\share) specifiers as in-tree, not external packages. pr-smoke runs this pipeline on Windows, and the previous POSIX-only check ('.' / '/') classified those specifiers as external, which could suppress a real edge on that platform only. Added external_import_shadow_windows_relative_specifier_kept (tests/test_registry.c): red before this fix, green after. - old_workers / old_single in the #1355 pipeline test are now const char*, matching getenv()'s read-only contract. - The pad_files literal (50) is now a named EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD constant with a comment tying it to MIN_FILES_FOR_PARALLEL (a private #define in pipeline.c, not reachable for a static_assert from tests), so a future bump to that threshold can't silently drop the fixture back onto the sequential-only path. Signed-off-by: Yyunozor <yyunozor@icloud.com>
1 parent 30633b4 commit 9ce0c1c

3 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎src/pipeline/registry.c‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum { REG_MAX_CANDIDATES = 256 };
3131
#include "foundation/dyn_array.h"
3232
#include "foundation/platform.h"
3333

34+
#include <ctype.h>
3435
#include <math.h>
3536
#include <stdio.h>
3637
#include <stdlib.h>
@@ -457,10 +458,29 @@ bool cbm_tsjs_suppress_weak_method_match(bool is_tsjs, bool is_method, const cha
457458
}
458459

459460
/* A module specifier that names a path inside the indexed tree ("./x", "../x",
460-
* "/abs/x") rather than an external package. Package specifiers are everything
461-
* else — "drizzle-orm", "rxjs/operators", "@scope/pkg". */
461+
* "/abs/x", and on Windows "C:\x", "C:/x", "\\server\share\x") rather than an
462+
* external package. Package specifiers are everything else — "drizzle-orm",
463+
* "rxjs/operators", "@scope/pkg". Windows paths must count as in-tree here:
464+
* pr-smoke runs this pipeline on Windows, and misclassifying a drive-letter or
465+
* UNC specifier as "external" is exactly the false-external edge this guard
466+
* exists to prevent (#1355). */
462467
static bool specifier_is_relative(const char *module_path) {
463-
return module_path && (module_path[0] == '.' || module_path[0] == '/');
468+
if (!module_path || !module_path[0]) {
469+
return false;
470+
}
471+
if (module_path[0] == '.' || module_path[0] == '/') {
472+
return true;
473+
}
474+
/* UNC share: \\server\share\... */
475+
if (module_path[0] == '\\' && module_path[1] == '\\') {
476+
return true;
477+
}
478+
/* Drive-letter absolute path: C:\repo\... or C:/repo/... */
479+
if (isalpha((unsigned char)module_path[0]) && module_path[1] == ':' &&
480+
(module_path[2] == '\\' || module_path[2] == '/')) {
481+
return true;
482+
}
483+
return false;
464484
}
465485

466486
static bool import_map_binds(const char **import_map_keys, int import_map_count,

‎tests/test_pipeline.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,17 @@ static int count_nodes_named(cbm_store_t *s, const char *project, const char *na
46494649
* (axios.get, api.patch on a renamed-axios instance, supertest request(app).get).
46504650
* The regex false edge must stay suppressed in parallel too. CBM_WORKERS forces
46514651
* >1 worker so the parallel path is taken regardless of the host core count. */
4652+
/* #1355: padding count for write_external_import_shadow_fixture, deliberately
4653+
* well past MIN_FILES_FOR_PARALLEL (=50, a private #define in
4654+
* src/pipeline/pipeline.c — not exposed to tests, so this cannot be a
4655+
* static_assert against it) rather than sitting right at the threshold. The
4656+
* margin, not the exact value, is what the test depends on: a modest bump to
4657+
* the real threshold must not silently drop this fixture back onto the
4658+
* sequential-only path and leave the parallel resolver unexercised. Same
4659+
* pattern as ET_PARALLEL_PAD / CP_PARALLEL_PAD in test_edge_types_probe.c /
4660+
* test_convergence_probe.c. */
4661+
enum { EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD = 64 };
4662+
46524663
/* #1355: write the shared external-import-shadow fixture into `dir`.
46534664
* `pad_files` filler modules push the run over MIN_FILES_FOR_PARALLEL so the
46544665
* same tree can be indexed by both resolvers. */
@@ -4739,11 +4750,13 @@ TEST(pipeline_external_import_shadow_not_bound_to_local_homonym_issue1355) {
47394750
/* Enough files that CBM_WORKERS can take the fused-parallel path; the same
47404751
* tree is then indexed by each resolver in turn, because the guard lives at
47414752
* two independent emit sites (pass_calls.c and pass_parallel.c). */
4742-
write_external_import_shadow_fixture(tmp, 50);
4753+
write_external_import_shadow_fixture(tmp, EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD);
47434754

4744-
char *old_workers = getenv("CBM_WORKERS");
4755+
/* getenv() returns a pointer into the process environment that must be
4756+
* treated as read-only; strdup() below only ever reads through it. */
4757+
const char *old_workers = getenv("CBM_WORKERS");
47454758
char *saved_workers = old_workers ? strdup(old_workers) : NULL;
4746-
char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
4759+
const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
47474760
char *saved_single = old_single ? strdup(old_single) : NULL;
47484761

47494762
cbm_setenv("CBM_INDEX_SINGLE_THREAD", "1", 1);

‎tests/test_registry.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,39 @@ TEST(external_import_shadow_relative_binding_wins_the_tie) {
942942
PASS();
943943
}
944944

945+
TEST(external_import_shadow_windows_relative_specifier_kept) {
946+
/* #1355 follow-up: a Windows-style specifier —
947+
* drive-letter absolute (`C:\...` / `C:/...`) or UNC share (`\\server\...`)
948+
* — names a path inside the indexed tree exactly like a POSIX "./x" or
949+
* "/x". pr-smoke runs this pipeline on Windows; before this fix these
950+
* specifiers fell through to "external package" and the same-name guess
951+
* they'd otherwise validate got suppressed on that platform only. */
952+
CBMImport imports[] = {
953+
{.local_name = "eq", .module_path = "C:\\repo\\src\\text-utils.ts"},
954+
{.local_name = "sql", .module_path = "C:/repo/src/text-utils.ts"},
955+
{.local_name = "normalize", .module_path = "\\\\server\\share\\text-utils.ts"},
956+
};
957+
CBMImportArray arr = {.items = imports, .count = 3, .cap = 3};
958+
959+
/* None of these materialized an import-map key (as if resolution missed
960+
* them, mirroring the reported scenario) — the specifier alone must still
961+
* keep the edge because it is in-tree, not external. RED before the fix
962+
* (specifier_is_relative saw '.' / '/' only, so all three were classified
963+
* external and suppressed); GREEN after. */
964+
ASSERT_FALSE(cbm_suppress_external_import_shadow("eq", "unique_name", &arr, NULL, 0));
965+
ASSERT_FALSE(cbm_suppress_external_import_shadow("sql", "unique_name", &arr, NULL, 0));
966+
ASSERT_FALSE(cbm_suppress_external_import_shadow("normalize", "unique_name", &arr, NULL, 0));
967+
/* A bare package specifier without any drive letter or leading separator
968+
* (e.g. "drizzle-orm") must still be external — this predicate must not
969+
* become "anything with a colon or backslash". */
970+
CBMImport pkg_only[] = {
971+
{.local_name = "eq", .module_path = "drizzle-orm"},
972+
};
973+
CBMImportArray parr = {.items = pkg_only, .count = 1, .cap = 1};
974+
ASSERT_TRUE(cbm_suppress_external_import_shadow("eq", "unique_name", &parr, NULL, 0));
975+
PASS();
976+
}
977+
945978
/* ── Suite ─────────────────────────────────────────────────────── */
946979

947980
/* Method call THROUGH an imported symbol that is itself an indexed node
@@ -1039,4 +1072,5 @@ SUITE(registry) {
10391072
RUN_TEST(external_import_shadow_drops_package_bound_bare_call);
10401073
RUN_TEST(external_import_shadow_keeps_everything_else);
10411074
RUN_TEST(external_import_shadow_relative_binding_wins_the_tie);
1075+
RUN_TEST(external_import_shadow_windows_relative_specifier_kept);
10421076
}

0 commit comments

Comments
 (0)