Skip to content

Commit 76d0382

Browse files
authored
Merge branch 'main' into codex/fix-1689-codex-agents-cleanup
2 parents 1d35def + aa44c28 commit 76d0382

22 files changed

Lines changed: 1558 additions & 72 deletions

‎Makefile.cbm‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ endif
9898
KOTLIN_DEDUP_TEST_DEFINE = -DCBM_KOTLIN_DEDUP_TEST_API=1
9999
CALL_REFERENCE_LOOKUP_TEST_DEFINE = -DCBM_CALL_REFERENCE_LOOKUP_TEST_API=1
100100
INCREMENTAL_TEST_DEFINE = -DCBM_INCREMENTAL_TEST_API=1
101+
COVERAGE_MARKER_TEST_DEFINE = -DCBM_COVERAGE_MARKER_TEST_API=1
101102
CFLAGS_TEST = $(CFLAGS_COMMON) $(EDITOR_TEST_DEFINES) $(SANITIZED_DEFINE) \
102103
$(KOTLIN_DEDUP_TEST_DEFINE) $(CALL_REFERENCE_LOOKUP_TEST_DEFINE) \
103-
$(INCREMENTAL_TEST_DEFINE) -g -O1 $(SANITIZE)
104+
$(INCREMENTAL_TEST_DEFINE) $(COVERAGE_MARKER_TEST_DEFINE) -g -O1 $(SANITIZE)
104105
CXXFLAGS_TEST = $(CXXFLAGS_COMMON) $(SANITIZED_DEFINE) -g -O1 $(SANITIZE) $(CXX_STDLIB_FLAGS)
105106

106107
# TSan (can't combine with ASan)
@@ -118,6 +119,7 @@ TSAN_SANITIZE = -fsanitize=thread -fno-omit-frame-pointer
118119
# macro of ours.
119120
CFLAGS_TSAN = $(CFLAGS_COMMON) $(EDITOR_TEST_DEFINES) $(KOTLIN_DEDUP_TEST_DEFINE) \
120121
$(CALL_REFERENCE_LOOKUP_TEST_DEFINE) $(INCREMENTAL_TEST_DEFINE) \
122+
$(COVERAGE_MARKER_TEST_DEFINE) \
121123
-DCBM_SANITIZED_BUILD=1 -g -O1 $(TSAN_SANITIZE)
122124
CXXFLAGS_TSAN = $(CXXFLAGS_COMMON) -DCBM_SANITIZED_BUILD=1 -g -O1 \
123125
$(TSAN_SANITIZE)

‎internal/cbm/cbm.c‎

Lines changed: 413 additions & 31 deletions
Large diffs are not rendered by default.

‎internal/cbm/cbm.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,21 @@ typedef struct CBMFileResult {
522522
* completeness guarantee. Callers should treat a flagged file as "prefer
523523
* grep here", never treat an unflagged file as provably complete. */
524524
bool parse_incomplete;
525+
/* True when the ranges cover so much of the file that they are no longer
526+
* useful advice — one range over 80% of the line count. The file WAS
527+
* indexed, but pointing a reader at almost every line tells them nothing,
528+
* so the report says "read the source" instead of listing the range.
529+
*
530+
* Its main customers are non-C languages. The refinement that narrows a
531+
* whole-file range using the preprocessed parse only runs for C, C++ and
532+
* CUDA, so a Python, Java or Ruby file whose root node is ERROR still
533+
* reports 1-N.
534+
*
535+
* Note the naming: this field and the phase string it produces are both
536+
* `parse_unusable`. The older `parse_incomplete` field emits the phase
537+
* `parse_partial` instead. That mismatch is historical, not deliberate —
538+
* do not copy it. */
539+
bool parse_unusable;
525540
const char *error_ranges;
526541
int error_region_count;
527542
bool is_test_file;

‎src/cli/config_yaml_edit.c‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3601,8 +3601,49 @@ int cbm_yaml_upsert_mapping_entry(const char *file_path, const char *section_key
36013601
return result == 0 && release_result == 0 ? 0 : YAML_ERROR;
36023602
}
36033603

3604+
/* Removal is idempotent: a config that does not exist has nothing to remove.
3605+
* The JSON removers already answer OK here (cbm_json_like_read_document's
3606+
* "missing" result); the YAML removers instead took the lock first, and the
3607+
* lock directory is created beside the target — so with the parent directory
3608+
* absent (`~/.hermes/` never created because Hermes was detected by its
3609+
* binary on PATH, not by its home) every uninstall reported
3610+
* "does not exist or cannot be inspected" and refused to remove the
3611+
* executable. Only a true ENOENT short-circuits: a dangling symlink still
3612+
* reaches the reader and its byte-identical rejection. */
3613+
static bool yaml_remove_target_absent(const char *path) {
3614+
if (!path) {
3615+
return false;
3616+
}
3617+
#ifdef _WIN32
3618+
/* FILE_FLAG_OPEN_REPARSE_POINT, as in toml_read_file: opens the link
3619+
* itself rather than following it, so a dangling symlink does NOT count as
3620+
* absent and still reaches the reader — matching the POSIX branch, where
3621+
* lstat does not follow either. */
3622+
wchar_t *wide = cbm_utf8_to_wide(path);
3623+
if (!wide) {
3624+
return false;
3625+
}
3626+
HANDLE handle = CreateFileW(
3627+
wide, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
3628+
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
3629+
DWORD error = handle == INVALID_HANDLE_VALUE ? GetLastError() : 0;
3630+
free(wide);
3631+
if (handle != INVALID_HANDLE_VALUE) {
3632+
CloseHandle(handle);
3633+
return false;
3634+
}
3635+
return error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND;
3636+
#else
3637+
struct stat path_state;
3638+
return lstat(path, &path_state) != 0 && errno == ENOENT;
3639+
#endif
3640+
}
3641+
36043642
int cbm_yaml_remove_mapping_entry(const char *file_path, const char *section_key,
36053643
const char *entry_key) {
3644+
if (yaml_remove_target_absent(file_path)) {
3645+
return 0;
3646+
}
36063647
yaml_config_lock_t lock;
36073648
if (yaml_lock_acquire(file_path, &lock) != 0) {
36083649
return YAML_ERROR;
@@ -3626,6 +3667,9 @@ int cbm_yaml_upsert_owned_mapping_entry(const char *file_path, const char *secti
36263667

36273668
int cbm_yaml_remove_owned_mapping_entry(const char *file_path, const char *section_key,
36283669
const char *entry_key, const char *canonical_entry_block) {
3670+
if (yaml_remove_target_absent(file_path)) {
3671+
return CBM_YAML_IDENTITY_EDIT_OK;
3672+
}
36293673
yaml_config_lock_t lock;
36303674
if (yaml_lock_acquire(file_path, &lock) != 0) {
36313675
return CBM_YAML_IDENTITY_EDIT_ERROR;
@@ -3653,6 +3697,9 @@ int cbm_yaml_upsert_mapping_sequence_item(const char *file_path, const char *con
36533697
int cbm_yaml_remove_mapping_sequence_item(const char *file_path, const char *const *sequence_path,
36543698
size_t sequence_path_len, const char *identity_key,
36553699
const char *identity_scalar, const char *canonical_item) {
3700+
if (yaml_remove_target_absent(file_path)) {
3701+
return CBM_YAML_IDENTITY_EDIT_OK;
3702+
}
36563703
yaml_config_lock_t lock;
36573704
if (yaml_lock_acquire(file_path, &lock) != 0) {
36583705
return CBM_YAML_IDENTITY_EDIT_ERROR;
@@ -3675,6 +3722,9 @@ int cbm_yaml_upsert_string_list_item(const char *file_path, const char *key, con
36753722
}
36763723

36773724
int cbm_yaml_remove_string_list_item(const char *file_path, const char *key, const char *item) {
3725+
if (yaml_remove_target_absent(file_path)) {
3726+
return 0;
3727+
}
36783728
yaml_config_lock_t lock;
36793729
if (yaml_lock_acquire(file_path, &lock) != 0) {
36803730
return YAML_ERROR;

‎src/daemon/application.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,6 +1588,33 @@ static bool application_index_args_normalize_defaults(yyjson_mut_val *root) {
15881588
return true;
15891589
}
15901590

1591+
/* One directory is one root. The auto-index job spells repo_path the way the
1592+
* session policy holds it - the platform's native form, backslashes on
1593+
* Windows - while an explicit index_repository request arrives in the
1594+
* handler's forward-slash spelling. Compared byte-exact the two never matched
1595+
* on Windows, and the request was refused as an options conflict instead of
1596+
* joining the job already running for its root. The policy keeps its
1597+
* spelling: the sensitive-root and allowed-root containment checks match it
1598+
* byte-exact against HOME and the granted roots, and respelling it there
1599+
* admitted $HOME. So the fold happens here, on this comparison's private copy,
1600+
* and nothing the daemon stores changes. */
1601+
static bool application_index_args_fold_repo_path(yyjson_mut_doc *document) {
1602+
yyjson_mut_val *root = yyjson_mut_doc_get_root(document);
1603+
yyjson_mut_val *repo_path = yyjson_mut_obj_get(root, "repo_path");
1604+
if (!repo_path || !yyjson_mut_is_str(repo_path)) {
1605+
return true;
1606+
}
1607+
char *folded = strdup(yyjson_mut_get_str(repo_path));
1608+
if (!folded) {
1609+
return false;
1610+
}
1611+
cbm_normalize_path_sep(folded);
1612+
yyjson_mut_val *key = yyjson_mut_str(document, "repo_path");
1613+
yyjson_mut_val *value = yyjson_mut_strcpy(document, folded);
1614+
free(folded);
1615+
return key && value && yyjson_mut_obj_replace(root, key, value);
1616+
}
1617+
15911618
static bool application_index_args_equal(const char *left, const char *right) {
15921619
if (!left || !right) {
15931620
return false;
@@ -1600,6 +1627,8 @@ static bool application_index_args_equal(const char *left, const char *right) {
16001627
yyjson_mut_val *right_root = right_copy ? yyjson_mut_doc_get_root(right_copy) : NULL;
16011628
bool equal = application_index_args_normalize_defaults(left_root) &&
16021629
application_index_args_normalize_defaults(right_root) &&
1630+
application_index_args_fold_repo_path(left_copy) &&
1631+
application_index_args_fold_repo_path(right_copy) &&
16031632
yyjson_mut_equals(left_root, right_root);
16041633
yyjson_mut_doc_free(left_copy);
16051634
yyjson_mut_doc_free(right_copy);
@@ -1608,6 +1637,10 @@ static bool application_index_args_equal(const char *left, const char *right) {
16081637
return equal;
16091638
}
16101639

1640+
bool cbm_daemon_application_index_args_equal_for_test(const char *left, const char *right) {
1641+
return application_index_args_equal(left, right);
1642+
}
1643+
16111644
/* Caller holds application->mutex. Keeping watcher ownership validation and
16121645
* this admission in the same critical section closes the unwatch race. */
16131646
static cbm_daemon_application_job_t *application_job_subscribe_locked(

‎src/daemon/application_internal.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ int cbm_daemon_application_busy_queue_waits_for_test(void);
4545
char *cbm_daemon_application_framable_response_for_test(char *response,
4646
const cbm_jsonrpc_request_t *request);
4747

48+
/* The job registry's index-argument equality: the running job's args against
49+
* a request's. Exposed because the two repo_path spellings it folds - the
50+
* session policy's native root and a handler's forward-slash one - only differ
51+
* on Windows, while the fold itself runs on every platform. */
52+
bool cbm_daemon_application_index_args_equal_for_test(const char *left, const char *right);
53+
4854
#endif /* CBM_DAEMON_APPLICATION_INTERNAL_H */

‎src/discover/discover.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ static CBMLanguage detect_file_language(const char *entry_name, const char *abs_
700700
if (dot && strcmp(dot, ".m") == 0) {
701701
lang = cbm_disambiguate_m(abs_path);
702702
}
703-
/* Special: .cls is shared by ObjectScript UDL and Apex */
703+
/* Special: .cls is shared by ObjectScript UDL, Apex and VB6 class modules */
704704
if (dot && strcmp(dot, ".cls") == 0) {
705705
lang = cbm_disambiguate_cls(abs_path);
706706
}
@@ -712,6 +712,10 @@ static CBMLanguage detect_file_language(const char *entry_name, const char *abs_
712712
if (dot && strcmp(dot, ".cfc") == 0) {
713713
lang = cbm_disambiguate_cfc(abs_path);
714714
}
715+
/* Special: .frm is shared by FORM and VB6 forms (#721) */
716+
if (dot && strcmp(dot, ".frm") == 0) {
717+
lang = cbm_disambiguate_frm(abs_path);
718+
}
715719
/* Special: ObjectScript Studio Export XML (<Export generator="...">) is
716720
* detected by content; otherwise .xml stays XML. */
717721
if (lang == CBM_LANG_XML) {

‎src/discover/discover.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ CBMLanguage cbm_disambiguate_m(const char *path);
4141

4242
/* Disambiguate .cls files by reading first 4KB of content.
4343
* Returns CBM_LANG_OBJECTSCRIPT_UDL if a line starts with "Class <Uppercase>",
44+
* CBM_LANG_COUNT (unsupported) for a Visual Basic 6 class module (#721),
4445
* otherwise CBM_LANG_APEX. On read failure, defaults to CBM_LANG_APEX. */
4546
CBMLanguage cbm_disambiguate_cls(const char *path);
4647

48+
/* Disambiguate .frm files by reading first 4KB of content (#721).
49+
* Returns CBM_LANG_COUNT (unsupported) for a Visual Basic 6 form, otherwise
50+
* CBM_LANG_FORM. On read failure, defaults to CBM_LANG_FORM. */
51+
CBMLanguage cbm_disambiguate_frm(const char *path);
52+
4753
/* Disambiguate .inc files by reading first 4KB of content.
4854
* Returns CBM_LANG_OBJECTSCRIPT_ROUTINE if it looks like an ObjectScript
4955
* include (a "ROUTINE <Uppercase>" header), otherwise CBM_LANG_BITBAKE.

‎src/discover/language.c‎

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,9 +1249,49 @@ CBMLanguage cbm_disambiguate_m(const char *path) {
12491249
return CBM_LANG_MATLAB;
12501250
}
12511251

1252-
/* Disambiguate .cls files: shared by InterSystems ObjectScript UDL and
1253-
* Salesforce Apex. ObjectScript class files begin with a line of the form
1254-
* "Class <UppercasePackage>...". Defaults to Apex on any doubt. */
1252+
/* Visual Basic 6 / VBA source exports are recognisable from their header (#721):
1253+
* every module carries `Attribute VB_Name = "..."`, class modules open with
1254+
* `VERSION 1.0 CLASS`, forms/controls with `VERSION 5.00` + `Begin VB.Form` /
1255+
* `Begin VB.UserControl`. None of these occur in Apex or ObjectScript classes
1256+
* or in FORM programs, whose .cls / .frm extensions VB6 happens to share. */
1257+
static bool has_vb6_markers(const char *buf) {
1258+
return str_contains(buf, "Attribute VB_Name") || str_contains(buf, "VERSION 1.0 CLASS") ||
1259+
str_contains(buf, "Begin VB.") || str_contains(buf, "\nOption Explicit");
1260+
}
1261+
1262+
/* Disambiguate .frm files: shared by the FORM symbolic-manipulation language
1263+
* and Visual Basic 6 forms (#721). There is no Visual Basic language yet, so a
1264+
* VB6 form is reported as unsupported (CBM_LANG_COUNT) rather than handed to
1265+
* the FORM grammar, which yields no defs and stray junk nodes. Defaults to
1266+
* FORM on any doubt (preserves existing behaviour). */
1267+
CBMLanguage cbm_disambiguate_frm(const char *path) {
1268+
if (!path) {
1269+
return CBM_LANG_FORM;
1270+
}
1271+
1272+
FILE *f = cbm_fopen(path, "r");
1273+
if (!f) {
1274+
return CBM_LANG_FORM;
1275+
}
1276+
1277+
char buf[CBM_SZ_4K + SKIP_ONE];
1278+
size_t n = fread(buf, SKIP_ONE, CBM_SZ_4K, f);
1279+
buf[n] = '\0';
1280+
(void)fclose(f);
1281+
1282+
/* VB6 form files open with "VERSION x.yy" on line 1. */
1283+
if (strncmp(buf, "VERSION ", SLEN("VERSION ")) == 0 &&
1284+
isdigit((unsigned char)buf[SLEN("VERSION ")])) {
1285+
return CBM_LANG_COUNT;
1286+
}
1287+
return has_vb6_markers(buf) ? CBM_LANG_COUNT : CBM_LANG_FORM;
1288+
}
1289+
1290+
/* Disambiguate .cls files: shared by InterSystems ObjectScript UDL, Salesforce
1291+
* Apex and Visual Basic 6 class modules (#721). ObjectScript class files begin
1292+
* with a line of the form "Class <UppercasePackage>..."; VB6 class modules
1293+
* carry the VB6 header markers and are reported as unsupported (CBM_LANG_COUNT)
1294+
* until a Visual Basic grammar exists. Defaults to Apex on any doubt. */
12551295
CBMLanguage cbm_disambiguate_cls(const char *path) {
12561296
if (!path) {
12571297
return CBM_LANG_APEX;
@@ -1267,6 +1307,10 @@ CBMLanguage cbm_disambiguate_cls(const char *path) {
12671307
buf[n] = '\0';
12681308
(void)fclose(f);
12691309

1310+
if (has_vb6_markers(buf)) {
1311+
return CBM_LANG_COUNT;
1312+
}
1313+
12701314
const char *line = buf;
12711315
while (*line) {
12721316
if (strncmp(line, "Class ", SLEN("Class ")) == 0 &&

0 commit comments

Comments
 (0)