Skip to content

Commit a8293c4

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 DeusData#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 eaf5904 commit a8293c4

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>
@@ -502,10 +503,29 @@ bool cbm_suppress_weak_local_binding_call(bool enabled, bool callee_is_locally_b
502503
}
503504

504505
/* A module specifier that names a path inside the indexed tree ("./x", "../x",
505-
* "/abs/x") rather than an external package. Package specifiers are everything
506-
* else — "drizzle-orm", "rxjs/operators", "@scope/pkg". */
506+
* "/abs/x", and on Windows "C:\x", "C:/x", "\\server\share\x") rather than an
507+
* external package. Package specifiers are everything else — "drizzle-orm",
508+
* "rxjs/operators", "@scope/pkg". Windows paths must count as in-tree here:
509+
* pr-smoke runs this pipeline on Windows, and misclassifying a drive-letter or
510+
* UNC specifier as "external" is exactly the false-external edge this guard
511+
* exists to prevent (#1355). */
507512
static bool specifier_is_relative(const char *module_path) {
508-
return module_path && (module_path[0] == '.' || module_path[0] == '/');
513+
if (!module_path || !module_path[0]) {
514+
return false;
515+
}
516+
if (module_path[0] == '.' || module_path[0] == '/') {
517+
return true;
518+
}
519+
/* UNC share: \\server\share\... */
520+
if (module_path[0] == '\\' && module_path[1] == '\\') {
521+
return true;
522+
}
523+
/* Drive-letter absolute path: C:\repo\... or C:/repo/... */
524+
if (isalpha((unsigned char)module_path[0]) && module_path[1] == ':' &&
525+
(module_path[2] == '\\' || module_path[2] == '/')) {
526+
return true;
527+
}
528+
return false;
509529
}
510530

511531
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
@@ -4976,6 +4976,17 @@ static int count_nodes_named(cbm_store_t *s, const char *project, const char *na
49764976
* (axios.get, api.patch on a renamed-axios instance, supertest request(app).get).
49774977
* The regex false edge must stay suppressed in parallel too. CBM_WORKERS forces
49784978
* >1 worker so the parallel path is taken regardless of the host core count. */
4979+
/* #1355: padding count for write_external_import_shadow_fixture, deliberately
4980+
* well past MIN_FILES_FOR_PARALLEL (=50, a private #define in
4981+
* src/pipeline/pipeline.c — not exposed to tests, so this cannot be a
4982+
* static_assert against it) rather than sitting right at the threshold. The
4983+
* margin, not the exact value, is what the test depends on: a modest bump to
4984+
* the real threshold must not silently drop this fixture back onto the
4985+
* sequential-only path and leave the parallel resolver unexercised. Same
4986+
* pattern as ET_PARALLEL_PAD / CP_PARALLEL_PAD in test_edge_types_probe.c /
4987+
* test_convergence_probe.c. */
4988+
enum { EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD = 64 };
4989+
49794990
/* #1355: write the shared external-import-shadow fixture into `dir`.
49804991
* `pad_files` filler modules push the run over MIN_FILES_FOR_PARALLEL so the
49814992
* same tree can be indexed by both resolvers. */
@@ -5066,11 +5077,13 @@ TEST(pipeline_external_import_shadow_not_bound_to_local_homonym_issue1355) {
50665077
/* Enough files that CBM_WORKERS can take the fused-parallel path; the same
50675078
* tree is then indexed by each resolver in turn, because the guard lives at
50685079
* two independent emit sites (pass_calls.c and pass_parallel.c). */
5069-
write_external_import_shadow_fixture(tmp, 50);
5080+
write_external_import_shadow_fixture(tmp, EXTERNAL_IMPORT_SHADOW_PARALLEL_PAD);
50705081

5071-
char *old_workers = getenv("CBM_WORKERS");
5082+
/* getenv() returns a pointer into the process environment that must be
5083+
* treated as read-only; strdup() below only ever reads through it. */
5084+
const char *old_workers = getenv("CBM_WORKERS");
50725085
char *saved_workers = old_workers ? strdup(old_workers) : NULL;
5073-
char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
5086+
const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
50745087
char *saved_single = old_single ? strdup(old_single) : NULL;
50755088

50765089
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
@@ -1059,6 +1059,39 @@ TEST(external_import_shadow_relative_binding_wins_the_tie) {
10591059
PASS();
10601060
}
10611061

1062+
TEST(external_import_shadow_windows_relative_specifier_kept) {
1063+
/* #1355 follow-up: a Windows-style specifier —
1064+
* drive-letter absolute (`C:\...` / `C:/...`) or UNC share (`\\server\...`)
1065+
* — names a path inside the indexed tree exactly like a POSIX "./x" or
1066+
* "/x". pr-smoke runs this pipeline on Windows; before this fix these
1067+
* specifiers fell through to "external package" and the same-name guess
1068+
* they'd otherwise validate got suppressed on that platform only. */
1069+
CBMImport imports[] = {
1070+
{.local_name = "eq", .module_path = "C:\\repo\\src\\text-utils.ts"},
1071+
{.local_name = "sql", .module_path = "C:/repo/src/text-utils.ts"},
1072+
{.local_name = "normalize", .module_path = "\\\\server\\share\\text-utils.ts"},
1073+
};
1074+
CBMImportArray arr = {.items = imports, .count = 3, .cap = 3};
1075+
1076+
/* None of these materialized an import-map key (as if resolution missed
1077+
* them, mirroring the reported scenario) — the specifier alone must still
1078+
* keep the edge because it is in-tree, not external. RED before the fix
1079+
* (specifier_is_relative saw '.' / '/' only, so all three were classified
1080+
* external and suppressed); GREEN after. */
1081+
ASSERT_FALSE(cbm_suppress_external_import_shadow("eq", "unique_name", &arr, NULL, 0));
1082+
ASSERT_FALSE(cbm_suppress_external_import_shadow("sql", "unique_name", &arr, NULL, 0));
1083+
ASSERT_FALSE(cbm_suppress_external_import_shadow("normalize", "unique_name", &arr, NULL, 0));
1084+
/* A bare package specifier without any drive letter or leading separator
1085+
* (e.g. "drizzle-orm") must still be external — this predicate must not
1086+
* become "anything with a colon or backslash". */
1087+
CBMImport pkg_only[] = {
1088+
{.local_name = "eq", .module_path = "drizzle-orm"},
1089+
};
1090+
CBMImportArray parr = {.items = pkg_only, .count = 1, .cap = 1};
1091+
ASSERT_TRUE(cbm_suppress_external_import_shadow("eq", "unique_name", &parr, NULL, 0));
1092+
PASS();
1093+
}
1094+
10621095
/* ── Suite ─────────────────────────────────────────────────────── */
10631096

10641097
/* Method call THROUGH an imported symbol that is itself an indexed node
@@ -1161,4 +1194,5 @@ SUITE(registry) {
11611194
RUN_TEST(external_import_shadow_drops_package_bound_bare_call);
11621195
RUN_TEST(external_import_shadow_keeps_everything_else);
11631196
RUN_TEST(external_import_shadow_relative_binding_wins_the_tie);
1197+
RUN_TEST(external_import_shadow_windows_relative_specifier_kept);
11641198
}

0 commit comments

Comments
 (0)