Skip to content

Commit ea2e36a

Browse files
committed
Merge main into fix/issue-2078 for the release batch
Conflict in tests/test_parse_coverage.c: this branch's DeusData#2078 tests and main's DeusData#1967 line-count test (DeusData#2336) were both appended before the suite; both kept, every TEST still registered. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2 parents fe6deaa + bf93f0b commit ea2e36a

16 files changed

Lines changed: 1066 additions & 68 deletions

‎docs/CONFIGURATION.md‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,33 @@ be indexed and later returned. And the credential list is a denylist, so it
236236
raises the cost of a mistake rather than closing the class — a directory it does
237237
not name is permitted.
238238

239+
### Shared / HPC filesystems
240+
241+
On clusters and other shared machines, home directories often live on a network
242+
filesystem (NFS, Lustre, GPFS, SMB/CIFS), and `~/.cache` is sometimes a symlink
243+
into a shared tree. Three rules keep CBM working there:
244+
245+
- **Put the cache and the rendezvous on local storage.** Set `CBM_CACHE_DIR` (indexes,
246+
`_config.db`) and, if needed, `CBM_RUNTIME_DIR` (the daemon rendezvous) to a
247+
local disk you own, for example `/local/scratch/$USER/cbm` or `/tmp/$USER-cbm`.
248+
Set the same values in your MCP client's environment and your shell.
249+
- **Do not route the cache into another account's tree.** A symlinked `~/.cache` is
250+
resolved and allowed, but every directory on the *resolved* path must be owned
251+
by you or by root. If a parent such as `/shared/fs` belongs to another account,
252+
that account can rename or replace anything below it, so CBM refuses the path
253+
and names the directory and its owner:
254+
255+
```text
256+
... (cache-private) - '/shared/fs' is owned by uid 1234 (alice), not by you (uid 1000) or root; ...
257+
```
258+
259+
This check has no override. Choose a location with a safe ancestry instead.
260+
- **Avoid network filesystems for the cache.** The indexes are SQLite databases in
261+
WAL mode, which needs shared-memory locking that network filesystems do not
262+
provide reliably. On Linux, CBM logs one `daemon.cache_root_network_fs` warning
263+
at startup when the cache root is on NFS, Lustre, GPFS, CIFS or SMB2. The cache
264+
still works there, but it can be slow, and a database can be corrupted.
265+
239266
## 5. Agent and Editor Integration Files
240267

241268
The `install` command can also write MCP entries and instruction blocks into agent/editor config files such as Claude Code, Codex, Gemini, VS Code, Cursor, Zed, and others.

‎internal/cbm/cbm.c‎

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,26 @@ static void cbm_mark_pp_error_rows(TSNode n, uint8_t *rows, uint32_t row_count,
14981498
}
14991499
}
15001500

1501+
/* The ONE line counter for a source buffer (#1967). Every caller that asks
1502+
* "how many lines does this file have" uses it, so the coverage report never
1503+
* holds two answers for the same buffer.
1504+
*
1505+
* Convention: a '\n' TERMINATES a line; it does not open a new one. So the
1506+
* count is the number of '\n' that have at least one byte after them, plus
1507+
* one. "a\nb" and "a\nb\n" both have 2 lines (the trailing newline adds no
1508+
* phantom empty line, matching what an editor shows); "a\nb" without a final
1509+
* newline still counts its last line. An empty buffer counts as 1 line, because
1510+
* tree-sitter still reports row 0 for it and 1-based line maps index line 1. */
1511+
uint32_t cbm_source_line_count(const char *src, int src_len) {
1512+
uint32_t n = 1;
1513+
for (int i = 0; i + 1 < src_len; i++) {
1514+
if (src[i] == '\n') {
1515+
n++;
1516+
}
1517+
}
1518+
return n;
1519+
}
1520+
15011521
/* Recovery subtraction (#963): tree-sitter error recovery plus the
15021522
* ERROR-descending def walker often still extract constructs INSIDE a failed
15031523
* region (verified: a function in an #ifdef-split ERROR region and even a
@@ -1515,12 +1535,7 @@ static void cbm_mark_pp_error_rows(TSNode n, uint8_t *rows, uint32_t row_count,
15151535
* Now the uncovered gaps are reported instead, and a gap holding only blank,
15161536
* comment or preprocessor lines is not a miss at all. */
15171537
static uint32_t *cbm_line_offsets(const char *src, int src_len, uint32_t *out_lines) {
1518-
uint32_t lines = 1;
1519-
for (int i = 0; i < src_len; i++) {
1520-
if (src[i] == '\n') {
1521-
lines++;
1522-
}
1523-
}
1538+
uint32_t lines = cbm_source_line_count(src, src_len);
15241539
uint32_t *offs =
15251540
(uint32_t *)cbm_alloc(CBM_MEM_CLASS_EXTRACT, (size_t)(lines + 1) * sizeof(uint32_t));
15261541
if (!offs) {
@@ -2125,18 +2140,6 @@ static void cbm_refine_regions_with_pp_lines(cbm_error_regions_t *regs, const ui
21252140
* this repo covers 25.5% of its file, and the next widest 3.9%. */
21262141
#define CBM_UNUSABLE_PCT 80
21272142

2128-
/* Number of 1-based lines in `src`. A file that does not end with a newline
2129-
* still has a last line, so the count is separators plus one. */
2130-
static uint32_t cbm_count_lines(const char *src, int src_len) {
2131-
uint32_t n = 1;
2132-
for (int i = 0; i < src_len; i++) {
2133-
if (src[i] == '\n' && i + 1 < src_len) {
2134-
n++;
2135-
}
2136-
}
2137-
return n;
2138-
}
2139-
21402143
/* Serialize collected regions as "start-end,start-end,...", with a trailing
21412144
* ",+<N>" when the cap threw N ranges away.
21422145
*
@@ -2926,12 +2929,7 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
29262929
* total loss (root is ERROR), because then it vouches for
29272930
* nothing and there is no refinement to make. */
29282931
if (strcmp(ts_node_type(pp_root), "ERROR") != 0) {
2929-
uint32_t orig_lines = 1;
2930-
for (int ci = 0; ci < source_len; ci++) {
2931-
if (source[ci] == '\n') {
2932-
orig_lines++;
2933-
}
2934-
}
2932+
uint32_t orig_lines = cbm_source_line_count(source, source_len);
29352933
uint8_t *map = (uint8_t *)cbm_arena_alloc(a, (size_t)orig_lines + 2);
29362934
int exp_lines = preprocessed->expanded_line_count;
29372935
uint8_t *bad_rows =
@@ -3127,7 +3125,7 @@ static CBMFileResult *extract_file_ex_body(const char *source, int source_len, C
31273125
* so the report can say "read the source" instead. See
31283126
* parse_unusable in cbm.h for which files land here and why. */
31293127
if (regs.count == 1 && regs.dropped == 0) {
3130-
uint32_t total = cbm_count_lines(source, source_len);
3128+
uint32_t total = cbm_source_line_count(source, source_len);
31313129
uint32_t span = regs.ends[0] - regs.starts[0] + 1;
31323130
if (total > 0 && span * 100 >= total * CBM_UNUSABLE_PCT) {
31333131
result->parse_unusable = true;

‎internal/cbm/cbm.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,11 @@ uint64_t cbm_usage_field_lookup_test_work(void);
10131013
uint64_t cbm_usage_slow_parent_fallback_test_count(void);
10141014
#endif
10151015

1016+
// Number of 1-based lines in a source buffer. The single line-count convention
1017+
// for coverage reporting (#1967): a trailing '\n' ends the last line and opens
1018+
// no new one; an empty buffer counts as 1 line. See the definition in cbm.c.
1019+
uint32_t cbm_source_line_count(const char *src, int src_len);
1020+
10161021
// Toggle C/C++ preprocessor Macro-node extraction (#375). The pipeline enables
10171022
// it only for full/advanced index modes (it dominates extraction on macro-dense
10181023
// codebases). Default ON. Set before extraction; read-only during.

‎internal/cbm/extract_calls.c‎

Lines changed: 150 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,59 @@ static const char *php_chain_prefix_arg(CBMArena *a, TSNode call_node, const cha
17631763
return NULL;
17641764
}
17651765

1766+
/* The value of a plain PHP string literal ('...' or "..." with no
1767+
* interpolation or escapes), "" for an empty one; NULL for anything else. */
1768+
static const char *php_plain_string_value(CBMArena *a, TSNode node, const char *source) {
1769+
const char *kind = ts_node_type(node);
1770+
if (strcmp(kind, "string") != 0 && strcmp(kind, "encapsed_string") != 0) {
1771+
return NULL;
1772+
}
1773+
uint32_t nc = ts_node_named_child_count(node);
1774+
for (uint32_t i = 0; i < nc; i++) {
1775+
if (strcmp(ts_node_type(ts_node_named_child(node, i)), "string_content") != 0) {
1776+
return NULL;
1777+
}
1778+
}
1779+
return nc == 0 ? "" : cbm_node_text(a, ts_node_named_child(node, 0), source);
1780+
}
1781+
1782+
/* The first argument's value node of a PHP call (unwrapping `argument`). */
1783+
static TSNode php_first_arg_value(TSNode call_node) {
1784+
TSNode none = {0};
1785+
TSNode args = ts_node_child_by_field_name(call_node, TS_FIELD("arguments"));
1786+
if (ts_node_is_null(args) || ts_node_named_child_count(args) == 0) {
1787+
return none;
1788+
}
1789+
TSNode arg = ts_node_named_child(args, 0);
1790+
if (strcmp(ts_node_type(arg), "argument") == 0) {
1791+
return ts_node_named_child_count(arg) == SKIP_ONE ? ts_node_named_child(arg, 0) : none;
1792+
}
1793+
return arg;
1794+
}
1795+
1796+
/* The literal 'prefix' of an attribute-array group (#1146):
1797+
* Route::group(['prefix' => 'v1/autocomplete', 'as' => ...], function () {...}),
1798+
* the form Firefly III's whole API is written in. */
1799+
static const char *php_group_array_prefix(CBMArena *a, TSNode group_call, const char *source) {
1800+
TSNode attrs = php_first_arg_value(group_call);
1801+
if (ts_node_is_null(attrs) || strcmp(ts_node_type(attrs), "array_creation_expression") != 0) {
1802+
return NULL;
1803+
}
1804+
uint32_t nc = ts_node_named_child_count(attrs);
1805+
for (uint32_t i = 0; i < nc; i++) {
1806+
TSNode el = ts_node_named_child(attrs, i);
1807+
if (strcmp(ts_node_type(el), "array_element_initializer") != 0 ||
1808+
ts_node_named_child_count(el) != PAIR_LEN) {
1809+
continue;
1810+
}
1811+
const char *key = php_plain_string_value(a, ts_node_named_child(el, 0), source);
1812+
if (key && strcmp(key, "prefix") == 0) {
1813+
return php_plain_string_value(a, ts_node_named_child(el, SKIP_ONE), source);
1814+
}
1815+
}
1816+
return NULL;
1817+
}
1818+
17661819
static const char *php_group_prefix_for_call(CBMArena *a, TSNode node, const char *source) {
17671820
const char *parts[PHP_PREFIX_PARTS_MAX];
17681821
int part_count = 0;
@@ -1785,7 +1838,14 @@ static const char *php_group_prefix_for_call(CBMArena *a, TSNode node, const cha
17851838
strcmp(ts_node_type(p), "scoped_call_expression") == 0)) {
17861839
TSNode gname = ts_node_child_by_field_name(p, TS_FIELD("name"));
17871840
char *gtxt = ts_node_is_null(gname) ? NULL : cbm_node_text(a, gname, source);
1788-
if (gtxt && strcmp(gtxt, "group") == 0) {
1841+
const char *array_prefix = gtxt && strcmp(gtxt, "group") == 0
1842+
? php_group_array_prefix(a, p, source)
1843+
: NULL;
1844+
if (array_prefix) {
1845+
if (part_count < PHP_PREFIX_PARTS_MAX) {
1846+
parts[part_count++] = array_prefix; /* inner-first */
1847+
}
1848+
} else if (gtxt && strcmp(gtxt, "group") == 0) {
17891849
/* Scan the receiver chain for prefix('...'). */
17901850
TSNode recv = ts_node_child_by_field_name(p, TS_FIELD("object"));
17911851
for (int hops = 0; hops < PHP_GROUP_WALK_MAX && !ts_node_is_null(recv);
@@ -1843,6 +1903,81 @@ static const char *php_group_prefix_for_call(CBMArena *a, TSNode node, const cha
18431903
return pos ? cbm_arena_strndup(a, buf, pos) : NULL;
18441904
}
18451905

1906+
/* A Laravel route registrar receiver (#1146): the Route facade — also at the
1907+
* root of a registrar chain, Route::middleware('auth')->get(...) — or the
1908+
* $router instance route files are loaded with (RouteServiceProvider, Lumen).
1909+
* The same literal `Route` scope the #952 callee qualification accepts. */
1910+
static bool php_is_laravel_registrar(CBMArena *a, TSNode call_node, const char *source) {
1911+
TSNode cur = call_node;
1912+
for (int hops = 0; hops < PHP_GROUP_WALK_MAX && !ts_node_is_null(cur); hops++) {
1913+
const char *kind = ts_node_type(cur);
1914+
if (strcmp(kind, "scoped_call_expression") == 0) {
1915+
TSNode scope = ts_node_child_by_field_name(cur, TS_FIELD("scope"));
1916+
const char *st = ts_node_is_null(scope) ? NULL : cbm_node_text(a, scope, source);
1917+
return st && strcmp(st, "Route") == 0;
1918+
}
1919+
if (strcmp(kind, "variable_name") == 0) {
1920+
const char *vt = cbm_node_text(a, cur, source);
1921+
return vt && strcmp(vt, "$router") == 0;
1922+
}
1923+
if (strcmp(kind, "member_call_expression") != 0) {
1924+
return false;
1925+
}
1926+
cur = ts_node_child_by_field_name(cur, TS_FIELD("object"));
1927+
}
1928+
return false;
1929+
}
1930+
1931+
/* Laravel accepts a route URI with or without its leading slash and trims
1932+
* '/' from both ends: Route::get('users', ...) serves /users, and '' is the
1933+
* group root. The route passes only mint a Route for a path that starts with
1934+
* '/', so give a recognised registration's literal URI its slash here, where
1935+
* the first argument is still at hand (#1146). Returns NULL — leave the call
1936+
* alone — for any other call, any non-literal URI, or one already slashed:
1937+
* `$request->get('name')`, `Cache::get('key')` and a collection's get('k')
1938+
* keep their argument. */
1939+
static const char *php_laravel_route_uri(CBMArena *a, TSNode call_node, const char *source) {
1940+
static const char *const verbs[] = {"get", "post", "put", "patch", "delete", NULL};
1941+
TSNode mname = ts_node_child_by_field_name(call_node, TS_FIELD("name"));
1942+
const char *verb = ts_node_is_null(mname) ? NULL : cbm_node_text(a, mname, source);
1943+
bool is_verb = false;
1944+
for (int i = 0; verb && verbs[i] && !is_verb; i++) {
1945+
is_verb = strcmp(verb, verbs[i]) == 0;
1946+
}
1947+
if (!is_verb || !php_is_laravel_registrar(a, call_node, source)) {
1948+
return NULL;
1949+
}
1950+
TSNode arg0 = php_first_arg_value(call_node);
1951+
const char *uri = ts_node_is_null(arg0) ? NULL : php_plain_string_value(a, arg0, source);
1952+
if (!uri || uri[0] == '/') {
1953+
return NULL;
1954+
}
1955+
size_t len = strlen(uri);
1956+
while (len > 0 && uri[len - SKIP_ONE] == '/') {
1957+
len--;
1958+
}
1959+
return cbm_arena_sprintf(a, "/%.*s", (int)len, uri);
1960+
}
1961+
1962+
/* Is a Laravel registration's action (its last argument) a string — 'index'
1963+
* inside a Route::controller() group, 'UserController@show'? Such an action
1964+
* does not say which class owns the method, so resolving it could only guess a
1965+
* same-named function anywhere in the repo. */
1966+
static bool php_route_action_is_string(TSNode call_node) {
1967+
TSNode args = ts_node_child_by_field_name(call_node, TS_FIELD("arguments"));
1968+
uint32_t nc = ts_node_is_null(args) ? 0 : ts_node_named_child_count(args);
1969+
if (nc < PAIR_LEN) {
1970+
return false;
1971+
}
1972+
TSNode action = ts_node_named_child(args, nc - SKIP_ONE);
1973+
if (strcmp(ts_node_type(action), "argument") == 0 &&
1974+
ts_node_named_child_count(action) == SKIP_ONE) {
1975+
action = ts_node_named_child(action, 0);
1976+
}
1977+
const char *kind = ts_node_type(action);
1978+
return strcmp(kind, "string") == 0 || strcmp(kind, "encapsed_string") == 0;
1979+
}
1980+
18461981
static bool is_nested_verilog_call_wrapper(CBMLanguage lang, TSNode node) {
18471982
if (lang != CBM_LANG_VERILOG || strcmp(ts_node_type(node), "subroutine_call") != 0) {
18481983
return false;
@@ -3941,6 +4076,16 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
39414076
}
39424077
if (!ts_node_is_null(args)) {
39434078
call.first_string_arg = extract_url_or_topic_arg(ctx, args, call.callee_name);
4079+
/* #1146: a Laravel registration's slashless URI ('users', '')
4080+
* becomes '/users' / '/' so it mints and composes below. */
4081+
const char *laravel_uri = NULL;
4082+
if (ctx->language == CBM_LANG_PHP && call.callee_name &&
4083+
cbm_service_pattern_route_method(call.callee_name) != NULL) {
4084+
laravel_uri = php_laravel_route_uri(ctx->arena, node, ctx->source);
4085+
if (laravel_uri) {
4086+
call.first_string_arg = laravel_uri;
4087+
}
4088+
}
39444089
/* #952: routes registered inside Laravel `prefix()->group()`
39454090
* closures must carry the composed path — the resolve passes
39464091
* only see the flat CBMCall, so the enclosing chain can only
@@ -3959,7 +4104,10 @@ CBMInvocationDescriptor handle_calls(CBMExtractCtx *ctx, TSNode node, const CBML
39594104
: cbm_arena_strndup(ctx->arena, gp, strlen(gp));
39604105
}
39614106
}
3962-
if (call.first_string_arg && call.first_string_arg[0] == '/') {
4107+
/* A slashless registration's string action would only be
4108+
* guessed at (#1146): mint its Route without a handler. */
4109+
if (call.first_string_arg && call.first_string_arg[0] == '/' &&
4110+
!(laravel_uri && php_route_action_is_string(node))) {
39634111
call.second_arg_name = extract_handler_arg(ctx, args);
39644112
}
39654113
if (ctx->language == CBM_LANG_OBJECTSCRIPT_UDL ||

‎internal/cbm/extract_defs.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2987,7 +2987,11 @@ static bool try_drf_action_decorator(CBMArena *a, TSNode dchild, const char *sou
29872987
}
29882988

29892989
// Try to extract a route from a single decorator call node.
2990-
// Returns true if a route method was found (even with fallback path "/").
2990+
// Returns true if a route method was found. The fallback path "/" applies only
2991+
// to a zero-argument call (`@app.route()`): a call that HAS arguments but none
2992+
// path-shaped is not a route -- unittest.mock's `@patch("subprocess.run")`
2993+
// shares its name with the HTTP verb and used to mint a PATCH "/" handler for
2994+
// every mocked test function (distilled from PR #1245).
29912995
static bool try_route_from_decorator_call(CBMArena *a, TSNode dchild, const char *source,
29922996
const char **out_path, const char **out_method) {
29932997
TSNode fn = ts_node_child_by_field_name(dchild, TS_FIELD("function"));
@@ -3012,6 +3016,9 @@ static bool try_route_from_decorator_call(CBMArena *a, TSNode dchild, const char
30123016
*out_method = method;
30133017
return true;
30143018
}
3019+
if (ts_node_named_child_count(args) > 0) {
3020+
return false;
3021+
}
30153022
}
30163023
*out_path = "/";
30173024
*out_method = method;

‎internal/cbm/service_patterns.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,11 @@ static const method_suffix_t route_reg_suffixes[] = {
577577
{".add_route", "ANY"},
578578
{".add_api_route", "ANY"},
579579
{".add_api_websocket_route", "ANY"},
580+
/* FastAPI/Starlette WebSocket decorators (`@router.websocket('/ws')`,
581+
* `@app.websocket_route('/events')`): not an HTTP verb, so ANY — mirrors
582+
* .add_api_websocket_route above (#1245). */
583+
{".websocket", "ANY"},
584+
{".websocket_route", "ANY"},
580585
{NULL, NULL},
581586
};
582587

0 commit comments

Comments
 (0)