Skip to content

Commit 0370d52

Browse files
committed
fix: harden index persistence and MCP outputs
Make index writes and artifact refreshes use verified temp files plus atomic replacement, preserving Windows replace semantics and avoiding fixed temp-path collisions. Thread the remaining pipeline confidence knobs through config while keeping zero-valued defaults backward compatible with existing upstream behavior. Tighten route-node gates and architecture route output so infra URL nodes stay queryable in the graph but do not pollute get_architecture route summaries; preserve code-created absolute URL routes for all language extractors. Harden MCP and CLI path handling around cache paths, grep scratch files, update downloads, checksum validation, stale checks, and project DB discovery without writing protocol noise to stdout. Add regression coverage for corrupt-DB recovery, concurrent atomic writes, tmp-prefixed project DBs, duplicate search result fields, route output filtering, config registry entries, and focused suite selectors. Validated with: git diff --check; make -f Makefile.cbm build/c/test-runner; focused suites security, artifact, graph_buffer, sqlite_writer, store_search, store_bulk, store_pragmas, store_checkpoint, watcher, infrascan, pipeline, store_nodes, mcp, cli, parallel, tool_consolidation, incremental, and store_arch; make -f Makefile.cbm cbm; isolated dogfood index/query run. Signed-off-by: Andrew Hundt <[email protected]>
1 parent 2509ccb commit 0370d52

55 files changed

Lines changed: 2075 additions & 547 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎internal/cbm/service_patterns.c‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,9 @@ static bool has_filesystem_extension(const char *path) {
649649

650650
static const char *const hard_file_exts[] = {
651651
".cfg", ".conf", ".credentials", ".crt", ".db", ".env",
652-
".ini", ".key", ".pem", ".pid", ".properties", ".service",
653-
".sock", ".socket", ".sqlite", ".toml", NULL};
652+
".ini", ".key", ".log", ".md", ".pdf", ".pem",
653+
".pid", ".properties", ".rst", ".service", ".sock", ".socket",
654+
".sqlite", ".toml", ".txt", NULL};
654655
for (int i = 0; hard_file_exts[i]; i++) {
655656
if (path_ext_matches(ext, hard_file_exts[i])) {
656657
return true;
@@ -716,6 +717,11 @@ bool cbm_service_pattern_is_http_route_literal(const char *literal, const char *
716717
if (!path || !path[0]) {
717718
return false;
718719
}
720+
/* Routes never contain whitespace; reject command/description strings
721+
* (e.g. "/autorun test task description") that start with '/'. */
722+
if (strpbrk(path, " \t\r\n")) {
723+
return false;
724+
}
719725
if (strncmp(path, "http://", 7) == 0 || strncmp(path, "https://", 8) == 0) {
720726
return true;
721727
}
@@ -725,6 +731,16 @@ bool cbm_service_pattern_is_http_route_literal(const char *literal, const char *
725731
if (path[0] != '/') {
726732
return false;
727733
}
734+
/* Reject CLI slash-command syntax ("/ar:allow", "/gh:pr") without blocking
735+
* ordinary route parameters in later segments ("/teams/:team/users/:id"). */
736+
const char *first_slash = strchr(path + 1, '/');
737+
size_t first_segment_len = first_slash ? (size_t)(first_slash - (path + 1)) : strlen(path + 1);
738+
if (first_segment_len > 0) {
739+
const char *colon = memchr(path + 1, ':', first_segment_len);
740+
if (colon && path[1] != ':') {
741+
return false;
742+
}
743+
}
728744
if (callee_is_delimiter_or_filesystem_builder(callee_name)) {
729745
return false;
730746
}

‎internal/cbm/service_patterns.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef CBM_SERVICE_PATTERNS_H
1212
#define CBM_SERVICE_PATTERNS_H
1313

14+
#include <stdbool.h>
15+
1416
/* Edge type returned by pattern match. */
1517
typedef enum {
1618
CBM_SVC_NONE = 0, /* Not a service pattern — use normal CALLS */
@@ -51,6 +53,15 @@ const char *cbm_service_pattern_http_method(const char *callee_name);
5153
* Returns NULL if not a known route registration method. */
5254
const char *cbm_service_pattern_route_method(const char *callee_name);
5355

56+
/* Classify a string literal as a genuine HTTP route path. Returns true for
57+
* real routes ("/api/orders", "/users/:id", "https://..."); false for file
58+
* paths ("/tmp/foo.md"), CLI slash-commands ("/ar:allow"), description strings
59+
* (contain whitespace), and other non-route args that extraction may surface.
60+
* Used to gate Route-node creation/emit sites so non-routes don't pollute the
61+
* graph. callee_name is used to reject string-builder callees (str.split,
62+
* os.path.join, ...). May be NULL. */
63+
bool cbm_service_pattern_is_http_route_literal(const char *literal, const char *callee_name);
64+
5465
/* Get the broker name for an async QN (e.g., "pubsub" from a Pub/Sub QN).
5566
* Returns NULL if not an async pattern. */
5667
const char *cbm_service_pattern_broker(const char *resolved_qn);

0 commit comments

Comments
 (0)