Skip to content

Commit 36ea43b

Browse files
authored
Merge branch 'main' into fix/index-worker-explicit-memory-budget
2 parents e9ac991 + 4d7d9f1 commit 36ea43b

29 files changed

Lines changed: 1999 additions & 215 deletions

‎.gitattributes‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Shell scripts must stay LF: with git's Windows default (core.autocrlf=true)
2+
# they check out as CRLF and bash inside the build containers rejects them.
3+
*.sh text eol=lf
4+
15
# Vendored tree-sitter grammars — machine-generated, hide from stats and diffs
26
internal/cbm/vendored/grammars/**/parser.c linguist-generated=true diff=false
37
internal/cbm/vendored/grammars/**/scanner.c linguist-generated=true diff=false

‎Makefile.cbm‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ PP_OBJ_TSAN = $(BUILD_DIR)/tsan_preprocessor.o
729729

730730
# ── Targets ──────────────────────────────────────────────────────
731731

732-
.PHONY: test test-par test-repro test-foundation test-tsan test-daemon-smoke cbm cbm-with-ui frontend embed clean-c lint lint-tidy lint-cppcheck lint-format security
732+
.PHONY: test test-par test-repro test-foundation test-tsan test-daemon-smoke cbm cbm-with-ui frontend embed clean-c lint lint-tidy lint-tidy-diff lint-cppcheck lint-format security
733733

734734
$(BUILD_DIR):
735735
mkdir -p $(BUILD_DIR)
@@ -1103,6 +1103,12 @@ lint-tidy:
11031103
@echo "=== clang-tidy ==="
11041104
@$(CLANG_TIDY) --quiet $(LINT_SRCS) -- $(CFLAGS_COMMON) $(SYSROOT_FLAG)
11051105

1106+
# clang-tidy, scoped to this commit's staged changes only (scripts/lint-tidy-diff.sh).
1107+
# The pre-commit hook runs this instead of the full lint-tidy sweep above, so a
1108+
# clean commit is not blocked by pre-existing findings elsewhere in the tree.
1109+
lint-tidy-diff:
1110+
@scripts/lint-tidy-diff.sh "$(CLANG_TIDY)" $(LINT_SRCS) -- $(CFLAGS_COMMON) $(SYSROOT_FLAG)
1111+
11061112
# cppcheck: complementary analysis (config in .cppcheck)
11071113
lint-cppcheck:
11081114
@echo "=== cppcheck ==="

‎internal/cbm/extract_defs.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3747,6 +3747,14 @@ static void extract_func_def(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec
37473747
def.is_test = true;
37483748
}
37493749

3750+
// A function/method defined in a file cbm treats as a test file is itself
3751+
// a test, regardless of its own name (tests/helpers/fixtures.c has none
3752+
// of the test_/_test naming conventions, but every function in it is
3753+
// still test code) (#1294). OR'd so the Rust attribute check above, which
3754+
// additionally catches #[test] functions embedded in an otherwise regular
3755+
// .rs file, is never downgraded by this.
3756+
def.is_test = def.is_test || ctx->result->is_test_file;
3757+
37503758
// Docstring
37513759
def.docstring = extract_docstring(a, node, ctx->source, ctx->language);
37523760

@@ -4728,6 +4736,10 @@ static void push_method_def(CBMExtractCtx *ctx, TSNode child, TSNode class_node,
47284736
// MinHash fingerprint
47294737
compute_fingerprint(ctx, &def, child);
47304738

4739+
// A method on a class defined in a test file (e.g. a JUnit/pytest
4740+
// TestFoo.test_bar) is itself a test, same as free functions (#1294).
4741+
def.is_test = def.is_test || ctx->result->is_test_file;
4742+
47314743
cbm_defs_push(&ctx->result->defs, a, def);
47324744
}
47334745

‎internal/cbm/helpers.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ bool cbm_is_test_file(const char *rel_path, CBMLanguage lang) {
295295
}
296296
const char *base = path_basename(rel_path);
297297

298+
/* Directory-based, language-agnostic: a file under a conventional test
299+
* directory is a test file regardless of its own basename (e.g.
300+
* tests/helpers/fixtures.c, which no per-language suffix/prefix rule
301+
* below would otherwise catch). Mirrors the directory set cbm_is_test_path
302+
* (src/pipeline/pass_tests.c) already uses for TESTS-edge detection, so
303+
* the extraction-time is_test_file flag agrees with it (#1294). */
304+
if (strstr(rel_path, "__tests__/") || strstr(rel_path, "/tests/") ||
305+
strstr(rel_path, "/test/") || strstr(rel_path, "/spec/") ||
306+
has_prefix(rel_path, "tests/") || has_prefix(rel_path, "test/") ||
307+
has_prefix(rel_path, "spec/") || has_prefix(rel_path, "__tests__/")) {
308+
return true;
309+
}
310+
298311
switch (lang) {
299312
case CBM_LANG_GO:
300313
return has_suffix(base, "_test.go");

‎scripts/hooks/pre-commit‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ set -euo pipefail
77
# git config core.hooksPath scripts/hooks
88

99
echo "pre-commit: running all linters in parallel..."
10-
make -j3 -f Makefile.cbm lint
10+
# clang-tidy runs diff-scoped (lint-tidy-diff, see scripts/lint-tidy-diff.sh):
11+
# the full lint-tidy sweep surfaces thousands of pre-existing findings that
12+
# have nothing to do with this commit and would block every contributor who
13+
# has clang-tidy on PATH. `make lint-tidy` remains available for a full audit.
14+
make -j3 -f Makefile.cbm lint-ci lint-tidy-diff
1115

1216
echo "pre-commit: security audit (source-level)..."
1317
scripts/security-audit.sh

‎scripts/lint-tidy-diff.sh‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/env bash
2+
# lint-tidy-diff.sh — clang-tidy scoped to the lines this commit changes.
3+
#
4+
# `make lint-tidy` (the full sweep) checks the entire LINT_SRCS tree, which
5+
# currently surfaces ~5,100 pre-existing findings unrelated to any given
6+
# commit (see Makefile.cbm's `lint-tidy` target). That is fine for a manual
7+
# deep audit but makes the pre-commit hook unusable: it blocks every commit,
8+
# including ones that touch files with zero findings on the touched lines.
9+
#
10+
# This script runs the same clang-tidy binary/config against the SAME staged
11+
# .c files, but passes clang-tidy's own `-line-filter` so only lines the
12+
# commit actually added/modified can produce a diagnostic. Pre-existing
13+
# findings on untouched lines — in the same file or elsewhere — are not
14+
# reported.
15+
#
16+
# Invoked by `make lint-tidy-diff` (scripts/hooks/pre-commit), which supplies
17+
# the resolved clang-tidy binary, then LINT_SRCS, then `--`, then the
18+
# compiler flags — the same argv shape as the `lint-tidy` target itself.
19+
#
20+
# Known limitation: only staged *.c files that are members of LINT_SRCS are
21+
# checked (matching the full sweep's own scope: vendored code and tests/ are
22+
# never clang-tidy'd). clang-tidy reports a header's diagnostics under
23+
# whatever path it was #include-d with, which is not reliably the same
24+
# string as its path in the working tree, so a commit that touches only a
25+
# header is not covered here even if a .c file including it also changed;
26+
# run `make lint-tidy` for a full pass in that case.
27+
28+
set -euo pipefail
29+
30+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
31+
cd "$ROOT"
32+
33+
if [ "$#" -lt 1 ]; then
34+
echo "usage: lint-tidy-diff.sh <clang-tidy-bin> [LINT_SRCS...] -- [CFLAGS...]" >&2
35+
exit 2
36+
fi
37+
38+
CLANG_TIDY="$1"
39+
shift
40+
41+
LINT_SRCS=()
42+
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
43+
LINT_SRCS+=("$1")
44+
shift
45+
done
46+
[ "$#" -gt 0 ] && shift # drop the `--` separator
47+
CFLAGS=("$@")
48+
49+
# bash 3.2 (macOS default, see scripts/check-lsp-originality.sh) has neither
50+
# `mapfile` nor associative arrays — read loop + linear membership check.
51+
is_lint_src() {
52+
local needle="$1" f
53+
[ "${#LINT_SRCS[@]}" -eq 0 ] && return 1
54+
for f in "${LINT_SRCS[@]}"; do
55+
[ "$f" = "$needle" ] && return 0
56+
done
57+
return 1
58+
}
59+
60+
# Staged .c files this commit actually changed (added/copied/modified/
61+
# renamed — a delete has no new lines to check) that are members of
62+
# LINT_SRCS.
63+
CHANGED=()
64+
while IFS= read -r f; do
65+
[ -n "$f" ] && is_lint_src "$f" && CHANGED+=("$f")
66+
done < <(git diff --cached --name-only --diff-filter=ACMR -- '*.c')
67+
68+
if [ "${#CHANGED[@]}" -eq 0 ]; then
69+
echo "lint-tidy-diff: no staged changes to a linted .c file, skipping clang-tidy"
70+
exit 0
71+
fi
72+
73+
# For each changed file, turn its staged hunks into a clang-tidy line-filter
74+
# range: `@@ -a,b +c,d @@` -> lines [c, c+d-1]. Zero-context (-U0) so a range
75+
# never includes untouched, pre-existing lines. Pure-deletion hunks (d == 0)
76+
# add no new lines and are skipped.
77+
LINE_FILTER='['
78+
FILTER_SEP=''
79+
TARGETS=()
80+
for f in "${CHANGED[@]}"; do
81+
[ -f "$f" ] || continue # renamed away / not present in the working tree
82+
ranges=''
83+
range_sep=''
84+
while IFS= read -r hunk; do
85+
if [[ "$hunk" =~ ^@@\ -[0-9]+(,[0-9]+)?\ \+([0-9]+)(,([0-9]+))?\ @@ ]]; then
86+
new_start="${BASH_REMATCH[2]}"
87+
new_count="${BASH_REMATCH[4]:-1}"
88+
[ "$new_count" -eq 0 ] && continue
89+
new_end=$((new_start + new_count - 1))
90+
ranges+="${range_sep}[${new_start},${new_end}]"
91+
range_sep=','
92+
fi
93+
done < <(git diff --cached -U0 --diff-filter=ACMR -- "$f" | grep -E '^@@ ')
94+
[ -z "$ranges" ] && continue
95+
96+
LINE_FILTER+="${FILTER_SEP}{\"name\":\"${f}\",\"lines\":[${ranges}]}"
97+
FILTER_SEP=','
98+
TARGETS+=("$f")
99+
done
100+
LINE_FILTER+=']'
101+
102+
if [ "${#TARGETS[@]}" -eq 0 ]; then
103+
echo "lint-tidy-diff: staged .c changes are deletion-only, skipping clang-tidy"
104+
exit 0
105+
fi
106+
107+
echo "lint-tidy-diff: ${#TARGETS[@]} changed file(s), diff-scoped clang-tidy"
108+
"$CLANG_TIDY" --quiet "-line-filter=${LINE_FILTER}" "${TARGETS[@]}" -- "${CFLAGS[@]}"

‎src/cypher/cypher.c‎

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,31 +3071,14 @@ static void scan_alternation_labels(cbm_store_t *store, const char *project, con
30713071
free(copy);
30723072
}
30733073

3074-
static void scan_pattern_nodes(cbm_store_t *store, const char *project, int max_rows,
3075-
cbm_node_pattern_t *first, cbm_node_t **out_nodes, int *out_count) {
3074+
static void scan_pattern_nodes(cbm_store_t *store, const char *project, cbm_node_pattern_t *first,
3075+
cbm_node_t **out_nodes, int *out_count) {
30763076
if (first->label && strchr(first->label, '|')) {
30773077
scan_alternation_labels(store, project, first->label, out_nodes, out_count);
30783078
} else if (first->label) {
30793079
cbm_store_find_nodes_by_label(store, project, first->label, out_nodes, out_count);
30803080
} else {
3081-
cbm_search_params_t params = {.project = project,
3082-
.min_degree = CYP_FOUND_NONE,
3083-
.max_degree = CYP_FOUND_NONE,
3084-
.limit = max_rows * CYP_GROWTH_10};
3085-
cbm_search_output_t sout = {0};
3086-
cbm_store_search(store, &params, &sout);
3087-
*out_count = sout.count;
3088-
*out_nodes = malloc(sout.count * sizeof(cbm_node_t));
3089-
for (int i = 0; i < sout.count; i++) {
3090-
(*out_nodes)[i] = sout.results[i].node;
3091-
sout.results[i].node.name = NULL;
3092-
sout.results[i].node.project = NULL;
3093-
sout.results[i].node.label = NULL;
3094-
sout.results[i].node.qualified_name = NULL;
3095-
sout.results[i].node.file_path = NULL;
3096-
sout.results[i].node.properties_json = NULL;
3097-
}
3098-
cbm_store_search_free(&sout);
3081+
cbm_store_find_nodes(store, project, out_nodes, out_count);
30993082
}
31003083
/* Apply inline property filters — free rejected nodes' strings */
31013084
if (first->prop_count > 0) {
@@ -4779,7 +4762,7 @@ static int expand_additional_patterns(cbm_store_t *store, cbm_query_t *q, const
47794762

47804763
cbm_node_t *extra_nodes = NULL;
47814764
int extra_count = 0;
4782-
scan_pattern_nodes(store, project, max_rows, &patn->nodes[0], &extra_nodes, &extra_count);
4765+
scan_pattern_nodes(store, project, &patn->nodes[0], &extra_nodes, &extra_count);
47834766
int rc = 0;
47844767
if (patn->rel_count == 0) {
47854768
rc = cross_join_nodes(bindings, bind_count, extra_nodes, extra_count, nvar, opt);
@@ -4831,7 +4814,7 @@ static int execute_single(cbm_store_t *store, cbm_query_t *q, const char *projec
48314814
/* Step 1: Scan initial nodes */
48324815
cbm_node_t *scanned = NULL;
48334816
int scan_count = 0;
4834-
scan_pattern_nodes(store, project, max_rows, &pat0->nodes[0], &scanned, &scan_count);
4817+
scan_pattern_nodes(store, project, &pat0->nodes[0], &scanned, &scan_count);
48354818

48364819
/* Build initial bindings with early WHERE */
48374820
int bind_cap = scan_count > max_rows ? scan_count : (max_rows > 0 ? max_rows : SKIP_ONE);

‎src/daemon/ipc.c‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,12 +1344,18 @@ static bool private_log_base_name_valid(const char *base_name) {
13441344
}
13451345

13461346
static char *private_log_directory_path_copy(const char *directory_path) {
1347-
#ifdef __APPLE__
1348-
/* Darwin exposes the trusted top-level aliases /tmp -> /private/tmp and
1349-
* /var -> /private/var. Resolve only those root-owned aliases before the
1347+
#if defined(__APPLE__) || defined(__FreeBSD__)
1348+
/* Resolve only those root-owned aliases before the
13501349
* component-wise O_NOFOLLOW walk. Canonicalizing the complete caller path
13511350
* would follow an attacker-controlled cache/log symlink and is forbidden. */
1351+
#if defined(__APPLE__)
1352+
/* Darwin exposes the trusted top-level aliases /tmp -> /private/tmp and
1353+
* /var -> /private/var. */
13521354
static const char *const aliases[] = {"/tmp", "/var"};
1355+
#else
1356+
/* FreeBSD additionally exposes /home -> /usr/home as a root-owned alias. */
1357+
static const char *const aliases[] = {"/tmp", "/var", "/home"};
1358+
#endif
13531359
for (size_t index = 0; index < sizeof(aliases) / sizeof(aliases[0]); index++) {
13541360
const char *alias = aliases[index];
13551361
size_t alias_length = strlen(alias);

0 commit comments

Comments
 (0)