mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-25 02:53:40 +08:00
The shared cross-file layer (scope facts for languages without an engine)
needs one place where it can answer a call or usage site before main's
name chain, the same on the sequential and on the parallel route, without
the resolvers being edited for each rule.
site_bind.{c,h} is that place. Both call resolvers (pass_calls.c,
pass_parallel.c) and both usage resolvers (pass_usages.c,
pass_parallel.c) ask it at the same sites: a call no engine row matched
that does not require one, and a usage no engine row was found for. A
PROVEN answer replaces the chain where the chain runs (a call keeps every
later step of main: service classification, spawn, field policy,
guards); POSSIBLE and NO_ANSWER leave the chain as it is. A begin and an
end step per file hold the file's state and hand the layer the buffer the
file's edges went to, so an answer drawn after main's own edges needs no
further edit of the resolvers.
No language has a row yet: every file is inactive and every site gets
NO_ANSWER. Graphs are byte-identical to the base on both routes (etcd,
click, devise and two fixtures, one worker and padded past 50 files;
nodes and edges compared with strategy and properties).
tests/test_site_bind.c pins the contract for a language without a row:
no answer at a call or a usage, no edge drawn at the file's end.
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
67 lines
2.3 KiB
C
67 lines
2.3 KiB
C
/*
|
|
* test_site_bind.c -- the site hook of the shared cross-file layer
|
|
* (src/pipeline/site_bind.h).
|
|
*
|
|
* A file of a language without a row is inactive: every call and usage site
|
|
* of it gets NO_ANSWER (main's name chain decides, unchanged) and the end
|
|
* step draws no edge. Go has an engine and never gets a row of this layer,
|
|
* so these hold as rows for other languages arrive.
|
|
*/
|
|
#include "test_framework.h"
|
|
#include "../src/pipeline/site_bind.h"
|
|
#include "../src/graph_buffer/graph_buffer.h"
|
|
|
|
#include <stdint.h>
|
|
#include <string.h>
|
|
|
|
TEST(site_bind_language_without_row_answers_nothing) {
|
|
cbm_gbuf_t *gb = cbm_gbuf_new("p", "/tmp/p");
|
|
ASSERT_NOT_NULL(gb);
|
|
int64_t caller = cbm_gbuf_upsert_node(gb, "Function", "f", "p.a.f", "a.go", 1, 3, "{}");
|
|
int64_t callee = cbm_gbuf_upsert_node(gb, "Function", "g", "p.b.g", "b.go", 1, 3, "{}");
|
|
ASSERT_GT(caller, 0);
|
|
ASSERT_GT(callee, 0);
|
|
const cbm_gbuf_node_t *source = cbm_gbuf_find_by_qn(gb, "p.a.f");
|
|
ASSERT_NOT_NULL(source);
|
|
|
|
CBMCall calls[1];
|
|
memset(calls, 0, sizeof(calls));
|
|
calls[0].callee_name = "g";
|
|
calls[0].enclosing_func_qn = "p.a.f";
|
|
CBMUsage usages[1];
|
|
memset(usages, 0, sizeof(usages));
|
|
usages[0].ref_name = "g";
|
|
usages[0].enclosing_func_qn = "p.a.f";
|
|
CBMFileResult result;
|
|
memset(&result, 0, sizeof(result));
|
|
result.calls.items = calls;
|
|
result.calls.count = 1;
|
|
result.usages.items = usages;
|
|
result.usages.count = 1;
|
|
|
|
cbm_site_file_t sf;
|
|
cbm_pipeline_site_bind_begin(&sf, NULL, gb, "a.go", CBM_LANG_GO, &result);
|
|
ASSERT_FALSE(sf.active);
|
|
|
|
cbm_site_answer_t at_call = cbm_pipeline_site_bind_call(&sf, &calls[0], source);
|
|
ASSERT_EQ(at_call.verdict, CBM_SITE_NO_ANSWER);
|
|
ASSERT_NULL(at_call.res.qualified_name);
|
|
ASSERT_NULL(at_call.target);
|
|
|
|
cbm_site_answer_t at_usage = cbm_pipeline_site_bind_usage(&sf, &usages[0], source);
|
|
ASSERT_EQ(at_usage.verdict, CBM_SITE_NO_ANSWER);
|
|
ASSERT_NULL(at_usage.res.qualified_name);
|
|
ASSERT_NULL(at_usage.target);
|
|
|
|
int edges_before = cbm_gbuf_edge_count(gb);
|
|
cbm_pipeline_site_bind_end(&sf, gb);
|
|
ASSERT_EQ(cbm_gbuf_edge_count(gb), edges_before);
|
|
|
|
cbm_gbuf_free(gb);
|
|
PASS();
|
|
}
|
|
|
|
SUITE(site_bind) {
|
|
RUN_TEST(site_bind_language_without_row_answers_nothing);
|
|
}
|