Skip to content

Commit abb71db

Browse files
committed
doc-links(cs): a directives-only file that loses its scope fails the layer in both routes (R7)
The re-check suspected that the worker pipeline never reads the doc-link failure flag of a C# file holding only directives, because its resolve loop skips a file with no definitions, calls, usages, throws, reads or writes, or impl traits. That case does not occur: every extraction pushes the file's Module definition first (cbm_extract_definitions, before the doc-link driver runs, with no return in between), so such a file has one definition and reaches cbm_doclinks_resolve_file, which reads the flag. No production code changes. Test: directives_only_failure (a repository of 62 files whose only C# file holds two global usings, its scope scan failing: one error row with four workers and with one; none without the failure; the file has nothing but its Module). Making the skip pass over a Module-only file turns the four-worker case red (0 error rows), so the test binds that path. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent ba529c9 commit abb71db

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

‎tests/test_doc_mentions.c‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10179,6 +10179,83 @@ TEST(doc_mentions_cs_rejected_scope_across_runs) {
1017910179
PASS();
1018010180
}
1018110181

10182+
enum { DM_DIRECTIVE_FILLERS = 60 }; /* with the C# file: above MIN_FILES_FOR_PARALLEL */
10183+
10184+
static const char DM_DIRECTIVES_ONLY[] = "global using System;\nglobal using System.IO;\n";
10185+
10186+
/* Error rows of one index of a repository whose only C# file holds nothing
10187+
* but global usings, its scope scan failing when `fail`. `workers` "4" runs
10188+
* the worker pipeline, "1" the sequential passes (CBM_WORKERS is restored).
10189+
* -1 when the repository cannot be indexed. */
10190+
static int dm_directives_only_errors(const char *workers, bool fail) {
10191+
char tmp[256];
10192+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_dm_r7_XXXXXX");
10193+
if (!cbm_mkdtemp(tmp)) {
10194+
return -1;
10195+
}
10196+
char repo[400];
10197+
snprintf(repo, sizeof(repo), "%s/repo", tmp);
10198+
th_write_file(TH_PATH(repo, "src/App.csproj"), DM_EMPTY_PROJECT);
10199+
th_write_file(TH_PATH(repo, "src/Usings.cs"), DM_DIRECTIVES_ONLY);
10200+
for (int i = 0; i < DM_DIRECTIVE_FILLERS; i++) {
10201+
char path[512];
10202+
snprintf(path, sizeof(path), "%s/py/m%02d.py", repo, i);
10203+
th_write_file(path, "def f():\n return 1\n");
10204+
}
10205+
const char *saved = getenv("CBM_WORKERS");
10206+
char *saved_copy = saved ? strdup(saved) : NULL;
10207+
cbm_setenv("CBM_WORKERS", workers, 1);
10208+
if (fail) {
10209+
cbm_doclink_test_fail_alloc_after(CBM_DOCLINK_ALLOC_SCOPE, 1); /* the one C# file */
10210+
}
10211+
char db[512];
10212+
snprintf(db, sizeof(db), "%s/r7.db", tmp);
10213+
int errors =
10214+
dm_index(repo, db, NULL) == 0
10215+
? dm_count(db, "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'")
10216+
: -1;
10217+
cbm_doclink_test_reset_alloc();
10218+
if (saved_copy) {
10219+
cbm_setenv("CBM_WORKERS", saved_copy, 1);
10220+
free(saved_copy);
10221+
} else {
10222+
cbm_unsetenv("CBM_WORKERS");
10223+
}
10224+
dm_unlink_db(db);
10225+
th_rmtree(tmp);
10226+
return errors;
10227+
}
10228+
10229+
/* R7: a C# file of nothing but global usings has no call, usage, throw,
10230+
* read/write or impl trait; its one definition is the Module every
10231+
* extraction pushes first. That keeps it out of the worker pipeline's skip
10232+
* of files with nothing to resolve, so its doc-link failure flag is read
10233+
* there: its scope scan running out of memory fails the layer in both
10234+
* routes. The fixture holds only while the file has nothing but the Module. */
10235+
TEST(doc_mentions_directives_only_failure) {
10236+
CBMFileResult *r = dm_extract(DM_DIRECTIVES_ONLY, CBM_LANG_CSHARP, "src/Usings.cs");
10237+
ASSERT_NOT_NULL(r);
10238+
bool module_only = r->calls.count == 0 && r->usages.count == 0 && r->throws.count == 0 &&
10239+
r->rw.count == 0 && r->impl_traits.count == 0 && r->defs.count == 1 &&
10240+
strcmp(r->defs.items[0].label, "Module") == 0;
10241+
cbm_free_result(r);
10242+
ASSERT_TRUE(module_only);
10243+
static const char *const routes[] = {"4", "1"};
10244+
bool ok = true;
10245+
for (size_t k = 0; k < sizeof(routes) / sizeof(routes[0]); k++) {
10246+
int clean = dm_directives_only_errors(routes[k], false);
10247+
int failed = dm_directives_only_errors(routes[k], true);
10248+
if (clean != 0 || failed != 1) {
10249+
printf(" %s worker(s): %d error rows without a failure (want 0), %d with one (want "
10250+
"1)\n",
10251+
routes[k], clean, failed);
10252+
ok = false;
10253+
}
10254+
}
10255+
ASSERT_TRUE(ok);
10256+
PASS();
10257+
}
10258+
1018210259
TEST(doc_mentions_alloc_failure_status) {
1018310260
static const struct {
1018410261
int point;
@@ -10318,6 +10395,7 @@ SUITE(doc_mentions) {
1031810395
RUN_TEST(doc_mentions_cs_scratch_table_work);
1031910396
RUN_TEST(doc_mentions_incremental_non_ascii_name);
1032010397
RUN_TEST(doc_mentions_alloc_failure_status);
10398+
RUN_TEST(doc_mentions_directives_only_failure);
1032110399
RUN_TEST(doc_mentions_cs_scanner_output_reads_back);
1032210400
RUN_TEST(doc_mentions_cs_rejected_scope_contained);
1032310401
RUN_TEST(doc_mentions_cs_rejected_scope_across_runs);

0 commit comments

Comments
 (0)