Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
48cb94f
fix(pipeline): preserve dotted TypeScript import basenames
pcristin Aug 23, 2026
2b6266b
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 27, 2026
3643ac3
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 27, 2026
fc8da75
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 28, 2026
2a7f442
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 28, 2026
28d9892
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 28, 2026
834e4f0
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 29, 2026
dd74440
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 31, 2026
b3d7940
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Aug 31, 2026
fb2e38f
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 1, 2026
b149247
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 1, 2026
cd8a5ed
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 2, 2026
3f08fac
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 2, 2026
57ef0a6
fix(traces): stop an unreadable span timestamp from becoming a real d…
CaptainMittens Aug 28, 2026
2c76563
fix(registry): refuse a name-only match the receiver chain contradicts
CaptainMittens Aug 29, 2026
da09b73
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 3, 2026
e79a7d7
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 3, 2026
1770d68
feat(extract): discover Razor Pages / MVC views (.cshtml) and route t…
DeusData Sep 3, 2026
bbecc9b
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 3, 2026
b64e217
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
pcristin Sep 3, 2026
4d4af28
Merge branch 'main' into fix/span-duration-unreadable-timestamps
DeusData Sep 3, 2026
4291412
Merge branch 'main' into fix/resolve-receiver-chain-mismatch
DeusData Sep 3, 2026
380b1c5
Merge branch 'main' into feat/cshtml-razor-pages
DeusData Sep 3, 2026
f47cd47
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
DeusData Sep 3, 2026
9d0c6a1
Merge pull request #1881 from CaptainMittens/fix/span-duration-unread…
DeusData Sep 4, 2026
91a1723
Merge pull request #1897 from CaptainMittens/fix/resolve-receiver-cha…
DeusData Sep 4, 2026
9ed01a4
Merge pull request #2024 from DeusData/feat/cshtml-razor-pages
DeusData Sep 4, 2026
3bbabf1
Merge pull request #1811 from pcristin/fix/issue-1682-dotted-ts-imports
DeusData Sep 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions internal/cbm/extract_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7908,13 +7908,23 @@ void cbm_extract_definitions_without_module(CBMExtractCtx *ctx) {

/* True when rel_path names a Blazor component file. */
static bool cbm_path_is_razor(const char *rel_path) {
/* Both Razor file types, not just components. `@page` is what DEFINES a
* Razor Page, so a .cshtml route is at least as worth extracting as a
* .razor one. Deliberately not .aspx/.ascx: Web Forms is a different
* templating syntax (`<%@ %>`, `runat="server"`) with no `@page`
* directive, so neither the C# recovery nor the scan below applies. */
if (!rel_path) {
return false;
}
static const char *const suffixes[] = {".razor", ".cshtml"};
size_t len = strlen(rel_path);
static const char suffix[] = ".razor";
size_t slen = sizeof(suffix) - 1U;
return len > slen && strcmp(rel_path + (len - slen), suffix) == 0;
for (size_t i = 0; i < sizeof(suffixes) / sizeof(suffixes[0]); i++) {
size_t slen = strlen(suffixes[i]);
if (len > slen && strcmp(rel_path + (len - slen), suffixes[i]) == 0) {
return true;
}
}
return false;
}

/* Match `@page "/route"` on ONE line; returns the route text or NULL.
Expand Down
8 changes: 8 additions & 0 deletions src/discover/language.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ static const ext_entry_t EXT_TABLE[] = {
* parse_partial, which is why this is a best-effort mapping rather
* than a dedicated grammar. */
{".razor", CBM_LANG_CSHARP},
/* Razor Pages / MVC views. Same Razor syntax and the same C# host as
* .razor, and equally unmapped before this: an ASP.NET Core app's views
* produced no nodes at all. The `@page` directive that defines a Razor
* Page lives in this file type, so the route extraction below matters
* more here than it does for components. Best-effort on the same terms:
* the C# grammar recovers the @{ } / @functions blocks, the surrounding
* markup lands in ERROR regions and is reported via parse_partial. */
{".cshtml", CBM_LANG_CSHARP},

/* Clojure */
{".clj", CBM_LANG_CLOJURE},
Expand Down
25 changes: 12 additions & 13 deletions src/pipeline/fqn.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,20 +282,19 @@ static char *resolve_python_relative(char *buf, size_t buf_size, const char *mod
return strdup(buf);
}

/* Strip a trailing file extension from a segment (e.g. "helpers.ts" → "helpers").
* Returns the new segment length. */
static size_t strip_ext(const char *seg_start, size_t seg_len) {
const char *seg_end = seg_start + seg_len;
const char *dot = NULL;
for (const char *d = seg_end - FQN_SEP_LEN; d >= seg_start; d--) {
if (*d == '.') {
dot = d;
break;
/* Strip an explicit JS/TS module file extension while preserving dots that are
* part of an extensionless basename (e.g. "featureX.engine"). */
static size_t strip_js_module_ext(const char *seg_start, size_t seg_len) {
static const char *const extensions[] = {
".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts", ".json",
};
for (size_t i = 0; i < sizeof(extensions) / sizeof(extensions[0]); i++) {
size_t ext_len = strlen(extensions[i]);
if (seg_len > ext_len &&
memcmp(seg_start + seg_len - ext_len, extensions[i], ext_len) == 0) {
return seg_len - ext_len;
}
}
if (dot && dot > seg_start) {
return (size_t)(dot - seg_start);
}
return seg_len;
}

Expand All @@ -322,7 +321,7 @@ static char *resolve_js_relative(char *buf, size_t buf_size, const char *module_
continue;
}
if (*p == '\0') {
seg_len = strip_ext(seg_start, seg_len);
seg_len = strip_js_module_ext(seg_start, seg_len);
}
if (seg_len > 0 && !path_append_segment(buf, buf_size, seg_start, seg_len)) {
return NULL;
Expand Down
6 changes: 5 additions & 1 deletion src/pipeline/pass_pkgmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,11 @@ char *cbm_pipeline_resolve_module(const cbm_pipeline_ctx_t *ctx, const char *sou
/* 1. Try relative import resolution (existing logic) */
char *resolved = cbm_pipeline_resolve_relative_import(source_rel, module_path);
if (resolved) {
char *qn = cbm_pipeline_fqn_module(ctx->project_name, resolved);
/* The relative resolver has already removed an explicit JS/TS file
* extension. Treat the remaining path as a module path verbatim so a
* dotted extensionless basename such as `featureX.engine` is not
* stripped a second time by cbm_pipeline_fqn_module. */
char *qn = cbm_pipeline_fqn_folder(ctx->project_name, resolved);
free(resolved);
return qn;
}
Expand Down
87 changes: 87 additions & 0 deletions src/pipeline/registry.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,87 @@ static const char *qualified_suffix_match(const qn_array_t *arr, const char *cal
return match;
}

/* A dotted callee whose FIRST segment starts upper-case names a type — URLSession,
* Calendar, JSONEncoder. That receiver chain is evidence the bare-name scorers
* throw away, and throwing it away binds Foundation's URLSession.shared.data to
* a project's own PickedFile.data: high confidence, and nothing in the graph
* shows it is wrong. Require instead that the candidate's own parent segment
* appears somewhere in the chain. Calendar.utcGregorian.startOfDayUTC resolving
* to AuthDTOs.Calendar.startOfDayUTC passes, because Calendar is in the chain.
*
* Only an upper-case first segment is guarded. A lower-case root names a value
* (vm.load, http.Get, os.path.join) whose declared type the chain does not
* show, so the chain proves nothing there and the call passes through
* unchanged. A callee with no separator passes through as well.
*
* Language agnostic by design: the registry holds no language, and every
* language that writes receiver chains gains the same protection. */
static bool receiver_chain_admits(const char *callee_name, const char *candidate_qn) {
/* Normalize "::" -> "." so the chain composes with dotted candidate QNs,
* the same way qualified_suffix_match does. */
char dotted[CBM_SZ_512];
size_t w = 0;
for (const char *s = callee_name; *s && w + SKIP_ONE < sizeof(dotted);) {
if (s[0] == ':' && s[1] == ':') {
dotted[w++] = '.';
s += 2;
} else {
dotted[w++] = *s++;
}
}
dotted[w] = '\0';

const char *last_dot = strrchr(dotted, '.');
if (!last_dot) {
return true; /* bare name — no receiver chain to judge */
}
if (dotted[0] < 'A' || dotted[0] > 'Z') {
return true; /* lower-case root names a value, not a type */
}
/* A name written in capitals with underscores is a constant holding a
* value, not a type: ISO_4217_URL.lower is a string's own method. JSON and
* URL carry no underscore and stay guarded. */
int has_underscore = 0;
int all_caps = 1;
for (const char *c = dotted; c < last_dot && *c != '.'; c++) {
if (*c == '_') {
has_underscore = 1;
} else if (*c >= 'a' && *c <= 'z') {
all_caps = 0;
break;
}
}
if (all_caps && has_underscore) {
return true;
}

/* The candidate's parent segment: the one before its final name. */
const char *cand_last = strrchr(candidate_qn, '.');
if (!cand_last || cand_last == candidate_qn) {
return true; /* top-level candidate — no parent to look for */
}
const char *parent = cand_last;
while (parent > candidate_qn && parent[-1] != '.') {
parent--;
}
size_t parent_len = (size_t)(cand_last - parent);

/* Walk the chain — every segment before the final callee name. A trailing
* "()" is dropped so JSONEncoder().encode reads as JSONEncoder. */
for (const char *seg = dotted; seg < last_dot;) {
const char *end = strchr(seg, '.');
size_t len = (size_t)(end - seg);
if (len >= 2 && seg[len - 2] == '(' && seg[len - 1] == ')') {
len -= 2; /* an empty "()" — JSONEncoder().encode names JSONEncoder */
}
if (len == parent_len && strncmp(seg, parent, parent_len) == 0) {
return true;
}
seg = end + SKIP_ONE;
}
return false;
}

/* Strategy 3+4: Name lookup + suffix match */
static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char *callee_name,
const char *module_qn, const char **import_vals,
Expand All @@ -950,6 +1031,9 @@ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char

/* Strategy 3: unique name */
if (arr->count == SKIP_ONE) {
if (!receiver_chain_admits(callee_name, arr->items[0])) {
return empty_result();
}
double conf = CONF_UNIQUE_NAME;
if (import_vals && import_count > 0 &&
!is_import_reachable(arr->items[0], import_vals, import_count)) {
Expand All @@ -964,6 +1048,9 @@ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char
}
const char *best = best_by_import_distance((const char **)arr->items, arr->count, module_qn);
if (best) {
if (!receiver_chain_admits(callee_name, best)) {
return empty_result();
}
double conf = candidate_count_penalty(CONF_SUFFIX_MATCH, arr->count);
return (cbm_resolution_t){best, "suffix_match", conf, arr->count};
}
Expand Down
43 changes: 42 additions & 1 deletion src/traces/traces.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "foundation/constants.h"

enum { TRACE_PATH_SLASHES = 3, TRACE_NOT_FOUND = -1 };
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -63,6 +65,38 @@ const char *cbm_extract_path_from_url(const char *url, char *buf, size_t buf_sz)

/* ── parseDuration ───────────────────────────────────────────────── */

/* Read one nanosecond timestamp. Answers false for text that does not read
* cleanly from its first character to its last, the way src/main.c:1104 does
* it: an end pointer says where the read stopped, errno catches a number too
* large, and *end == '\0' catches anything left over. A leading blank is
* refused too, because strtoll would otherwise step over it. */
static bool trace_read_nano(const char *text, int64_t *out) {
if (!text || !text[0] || isspace((unsigned char)text[0])) {
return false;
}
char *end = NULL;
errno = 0;
long long value = strtoll(text, &end, CBM_DECIMAL_BASE);
if (errno != 0 || !end || end == text || *end != '\0') {
return false;
}
*out = (int64_t)value;
return true;
}

int64_t cbm_parse_duration_checked(const char *start_nano, const char *end_nano, bool *ok) {
int64_t start = 0;
int64_t end = 0;
bool read_both = trace_read_nano(start_nano, &start) && trace_read_nano(end_nano, &end);
if (ok) {
*ok = read_both;
}
if (!read_both) {
return 0;
}
return (end > start) ? (end - start) : 0;
}

int64_t cbm_parse_duration(const char *start_nano, const char *end_nano) {
if (!start_nano || !end_nano) {
return 0;
Expand Down Expand Up @@ -115,7 +149,14 @@ bool cbm_extract_http_info(const cbm_trace_span_t *span, const char *service_nam
return false;
}

out->duration_ns = cbm_parse_duration(span->start_time, span->end_time);
/* A timestamp nobody can read is not a measurement. It used to read as 0,
* so an unreadable START time reported the whole end time as the duration
* -- a made-up number that looks like a real one. The HTTP method and path
* on this span are still good, so the span is still returned and only the
* duration says it is missing. */
bool timed = false;
int64_t duration = cbm_parse_duration_checked(span->start_time, span->end_time, &timed);
out->duration_ns = timed ? duration : CBM_DURATION_UNKNOWN;
return true;
}

Expand Down
15 changes: 14 additions & 1 deletion src/traces/traces.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef struct {
const char *path;
const char *status_code;
int span_kind;
/* Nanoseconds, or CBM_DURATION_UNKNOWN when the span's timestamps could
* not be read. A duration of 0 means the span really took no time. */
int64_t duration_ns;
} cbm_http_span_info_t;

Expand All @@ -62,9 +64,20 @@ bool cbm_extract_http_info(const cbm_trace_span_t *span, const char *service_nam
* Writes to buf (up to buf_sz). Returns buf, or "" if not a valid URL. */
const char *cbm_extract_path_from_url(const char *url, char *buf, size_t buf_sz);

/* Parse nanosecond timestamp strings and return duration. */
/* A duration nobody could measure. Kept apart from 0, which is a real span
* that took no time. */
#define CBM_DURATION_UNKNOWN (-1)

/* Parse nanosecond timestamp strings and return duration. Text that cannot be
* read counts as 0, so an unreadable timestamp and a span that took no time
* give the same answer. Use cbm_parse_duration_checked when that matters. */
int64_t cbm_parse_duration(const char *start_nano, const char *end_nano);

/* Same, and also says whether both timestamps could be read. *ok is false for
* a NULL argument and for any text that does not read cleanly end to end, so
* a caller can tell "took no time" from "nobody could measure this". */
int64_t cbm_parse_duration_checked(const char *start_nano, const char *end_nano, bool *ok);

/* Calculate P99 from an array of int64_t values.
* Sorts values in-place. Returns 0 for empty array. */
int64_t cbm_calculate_p99(int64_t *values, int count);
Expand Down
Loading
Loading