Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge origin/main into fix/doc-link-missing-member

Martin Vogel406f6c7c71d9
diff --cc src/pipeline/doc_links_md.c
index 18c47b5cd,b23a53c9b..8a30d238d
--- a/src/pipeline/doc_links_md.c
+++ b/src/pipeline/doc_links_md.c
@@@ -10,21 -10,18 +10,23 @@@
* document says (the field tests' rule for bare file names).
*
* Into the file: a line range picks the innermost code definition that holds
- * the WHOLE range; a member (`path::Name`, `path::Owner::name`) picks the one
- * definition of that name in the file. Otherwise the edge goes to the file,
- * and the range stays on it ("target_lines"). Every edge is exact: the
- * document wrote the path.
+ * the WHOLE range; a member (`path::Name`, `path::Owner::name`; a call form
+ * `path::name()` reads as `path::name`) picks the one definition of that name
+ * in the file. Otherwise the edge goes to the file, and the range stays on it
+ * ("target_lines"); so does a member the code file writes without a
+ * definition the graph binds (a macro, a prototype, an enum member, a class
+ * attribute). Every edge is exact: the document wrote the path.
*
* Unresolved:
- * missing the path is not in the graph, but its directory is: the
- * document names something that is not there (doc rot); or a
- * member whose name the code file does not write at all
+ * missing the path is not in the graph, but its directory is, or a
+ * directory above it that the reference wrote is: the document
+ * names something that is not there (doc rot; a moved or
- * renamed directory)
++ * renamed directory); or a member whose name the code file
++ * does not write at all
* ambiguous a file name alone that is not next to the document but exists
- * elsewhere in the repository: the document does not say which
+ * elsewhere in the repository: the document does not say which;
+ * or a member name the file defines more than once, with no
+ * owner to pick one
* Not a reference to this repository at all (LOCAL: no edge, no row): a link
* back into the same document; a path that is neither indexed nor of a type
* the indexer reads (an image, an archive, an extensionless page); a path
diff --cc tests/test_doc_links_md.c
index 0eb9b000f,54d1d3a0d..c2328397f
--- a/tests/test_doc_links_md.c
+++ b/tests/test_doc_links_md.c
@@@ -604,68 -444,55 +604,117 @@@ TEST(doc_links_md_incremental)
PASS();
}
+/* #2587 incremental == full: whether a `path::member` row is missing depends
+ * on the member file's text, and the row leads to that file by no edge. A
+ * body edit that writes the name (no definition added) turns the row into a
+ * file edge, one that drops it turns the edge back into the row; a same-named
+ * group that shrinks to one turns an ambiguous row into an edge. */
+TEST(doc_links_md_member_missing_incremental) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_dlmd_inc_XXXXXX");
+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
+ char repo[512];
+ snprintf(repo, sizeof(repo), "%s/repo", tmp);
+ th_write_file(TH_PATH(repo, "docs/helpers.md"), "# Helpers\n\nSee `src/tools.py::helper2`.\n");
+ th_write_file(TH_PATH(repo, "docs/areas.md"), "# Areas\n\nSee `src/shapes.py::area`.\n");
+ th_write_file(TH_PATH(repo, "src/tools.py"), "def helper():\n"
+ " return 1\n");
+ th_write_file(TH_PATH(repo, "src/shapes.py"), "class Circle:\n"
+ " def area(self):\n"
+ " return 3\n"
+ "\n"
+ "\n"
+ "class Square:\n"
+ " def area(self):\n"
+ " return 4\n");
+ char db[512];
+ char full_db[512];
+ snprintf(db, sizeof(db), "%s/inc.db", tmp);
+ snprintf(full_db, sizeof(full_db), "%s/full.db", tmp);
+ ASSERT_EQ(dm_index(repo, db, NULL), 0);
+ char reason[64];
+ dm_row(db, "docs/helpers.md", "src/tools.py::helper2", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "missing");
+ dm_row(db, "docs/areas.md", "src/shapes.py::area", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "ambiguous");
+
+ /* the body writes the name, no definition added: the row becomes an edge */
+ th_write_file(TH_PATH(repo, "src/tools.py"), "def helper():\n"
+ " return 1 # helper2 follows\n");
+ ASSERT_EQ(dm_step(repo, db, full_db, "member written", CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR),
+ 0);
+ ASSERT_EQ(md_file_edges(db, "Helpers", "src/tools.py"), 1);
+ /* and drops it again: missing again */
+ th_write_file(TH_PATH(repo, "src/tools.py"), "def helper():\n"
+ " return 1\n");
+ ASSERT_EQ(dm_step(repo, db, full_db, "member dropped", CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR),
+ 0);
+ dm_row(db, "docs/helpers.md", "src/tools.py::helper2", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "missing");
+ /* one of two `area` methods goes, the name stays: the one left binds */
+ th_write_file(TH_PATH(repo, "src/shapes.py"), "class Circle:\n"
+ " pass\n"
+ "\n"
+ "\n"
+ "class Square:\n"
+ " def area(self):\n"
+ " return 4\n");
+ ASSERT_EQ(dm_step(repo, db, full_db, "group shrinks", CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR), 0);
+ char props[512];
+ ASSERT_EQ(md_edge(db, "Areas", "Square.area", props, sizeof(props)), 1);
+ th_cleanup(tmp);
+ PASS();
+}
+
+ /* #2588: a reference into a directory that was moved or renamed named a
+ * path whose directory is gone, so it counted as no reference to this
+ * repository: no edge and no row. A directory above it that the reference
+ * wrote is still there, so it is doc rot. A path none of whose directories
+ * the repository has stays no reference. */
+ TEST(doc_links_md_moved_directory_issue2588) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_dlmd_mv_XXXXXX");
+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
+ char repo[512];
+ snprintf(repo, sizeof(repo), "%s/repo", tmp);
+ th_write_file(TH_PATH(repo, "docs/notes.md"), "# Notes\n"
+ "\n"
+ "See `src/util/rounding.py::clamp` and "
+ "[rounding](../src/util/rounding.py).\n"
+ "Create `scratch/new/thing.py` first.\n");
+ th_write_file(TH_PATH(repo, "src/ledger.py"), "def balance(ledger):\n"
+ " return sum(ledger)\n");
+ th_write_file(TH_PATH(repo, "src/util/rounding.py"), "def clamp(x, lo, hi):\n"
+ " return max(lo, min(hi, x))\n");
+ char db[512];
+ char full_db[512];
+ snprintf(db, sizeof(db), "%s/inc.db", tmp);
+ snprintf(full_db, sizeof(full_db), "%s/full.db", tmp);
+ ASSERT_EQ(dm_index(repo, db, NULL), 0);
+ char props[512];
+ char reason[64];
+ ASSERT_EQ(md_edge(db, "Notes", "rounding.clamp", props, sizeof(props)), 1);
+
+ /* src/util moves to src/helpers: both references are missing, on the
+ * incremental route as in a full index */
+ th_write_file(TH_PATH(repo, "src/helpers/rounding.py"), "def clamp(x, lo, hi):\n"
+ " return max(lo, min(hi, x))\n");
+ ASSERT_EQ(th_rmtree(TH_PATH(repo, "src/util")), 0);
+ ASSERT_EQ(dm_step(repo, db, full_db, "directory moved", CBM_INCREMENTAL_ROUTE_FORCED_FULL), 0);
+ ASSERT_EQ(md_edge(db, "Notes", "rounding.clamp", props, sizeof(props)), 0);
+ dm_row(db, "docs/notes.md", "src/util/rounding.py::clamp", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "missing");
+ dm_row(db, "docs/notes.md", "../src/util/rounding.py", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "missing");
+
+ /* no directory of it in the repository: still no reference */
+ dm_row(db, "docs/notes.md", "scratch/new/thing.py", reason, sizeof(reason), NULL, 0);
+ ASSERT_STR_EQ(reason, "");
+
+ th_cleanup(tmp);
+ PASS();
+ }
+
/* ── ADRs ────────────────────────────────────────────────────────── */
static void md_write_adrs(const char *tmp, const char *first_status) {
@@@ -1087,10 -914,8 +1136,11 @@@ SUITE(doc_links_md)
RUN_TEST(doc_links_md_repeated_headings);
RUN_TEST(doc_links_md_classify_span);
RUN_TEST(doc_links_md_resolve);
+ RUN_TEST(doc_links_md_member_not_defined_issue2587);
+ RUN_TEST(doc_links_md_member_written_issue2587);
RUN_TEST(doc_links_md_incremental);
+ RUN_TEST(doc_links_md_member_missing_incremental);
+ RUN_TEST(doc_links_md_moved_directory_issue2588);
RUN_TEST(doc_links_md_adr);
RUN_TEST(doc_links_md_adr_label_choice);
RUN_TEST(doc_links_md_adr_reported);