1212#include "foundation/compat.h"
1313#include "foundation/compat_fs.h"
1414#include "foundation/compat_thread.h"
15+ #include "foundation/log.h"
1516#include "foundation/platform.h"
1617#include "foundation/sha256.h"
1718#include "foundation/subprocess.h"
@@ -2932,6 +2933,38 @@ TEST(daemon_application_programmatic_index_forwards_set_doc_candidates) {
29322933 ASSERT_EQ (garbage , -1 );
29332934 PASS ();
29342935}
2936+
2937+ /* #1818: the daemon.autoindex.skipped warning must name the effective limit,
2938+ * like the MCP autoindex.skip event does (#1466). The warning is emitted on the
2939+ * background-initialize thread, before the release increment of the
2940+ * background-initialize counter that the test waits for, so the captured line
2941+ * is complete once that wait returns. */
2942+ static char app_autoindex_skipped_line [1024 ];
2943+ static atomic_bool app_autoindex_skipped_seen = ATOMIC_VAR_INIT (false);
2944+
2945+ static void app_autoindex_skipped_sink (const char * line ) {
2946+ if (!line || !strstr (line , "msg=daemon.autoindex.skipped" ) ||
2947+ atomic_load_explicit (& app_autoindex_skipped_seen , memory_order_acquire )) {
2948+ return ;
2949+ }
2950+ (void )snprintf (app_autoindex_skipped_line , sizeof (app_autoindex_skipped_line ), "%s" , line );
2951+ atomic_store_explicit (& app_autoindex_skipped_seen , true, memory_order_release );
2952+ }
2953+
2954+ /* True when `line` carries the whole key=value field `field` (not a prefix of
2955+ * a longer value such as limit=00). */
2956+ static bool app_log_line_has_field (const char * line , const char * field ) {
2957+ size_t length = strlen (field );
2958+ for (const char * at = strstr (line , field ); at ; at = strstr (at + 1 , field )) {
2959+ bool starts = at == line || at [-1 ] == ' ' ;
2960+ char next = at [length ];
2961+ if (starts && (next == '\0' || next == ' ' || next == '\n' || next == '\r' )) {
2962+ return true;
2963+ }
2964+ }
2965+ return false;
2966+ }
2967+
29352968TEST (daemon_application_auto_index_honors_tracked_file_limit ) {
29362969 app_env_backup_t cache_environment ;
29372970 bool cache_saved = app_env_backup_capture (& cache_environment , "CBM_CACHE_DIR" );
@@ -2976,13 +3009,25 @@ TEST(daemon_application_auto_index_honors_tracked_file_limit) {
29763009 cbm_daemon_application_runtime_callbacks (application );
29773010 cbm_daemon_runtime_application_session_t * session =
29783011 application ? app_test_open (& callbacks , 4190 ) : NULL ;
3012+ app_autoindex_skipped_line [0 ] = '\0' ;
3013+ atomic_store_explicit (& app_autoindex_skipped_seen , false, memory_order_release );
3014+ CBMLogLevel previous_log_level = cbm_log_get_level ();
3015+ CBMLogFormat previous_log_format = cbm_log_get_format ();
3016+ cbm_log_set_level (CBM_LOG_INFO );
3017+ cbm_log_set_format (CBM_LOG_FORMAT_TEXT );
3018+ cbm_log_set_sink_ex (app_autoindex_skipped_sink , CBM_LOG_SINK_REPLACE );
29793019 int bg_baseline = cbm_daemon_application_background_initializes_for_test ();
29803020 bool initialized = app_test_initialize_profile (& callbacks , session , root ,
29813021 CBM_MCP_TOOL_PROFILE_ALL , NULL , NULL );
29823022 bool admission_evaluated = app_wait_for_background_initializes (bg_baseline + 1 );
29833023 bool limit_prevented_admission = initialized && admission_evaluated &&
29843024 atomic_load (& fake .starts ) == 0 &&
29853025 cbm_daemon_application_active_jobs (application ) == 0 ;
3026+ cbm_log_set_sink (NULL );
3027+ cbm_log_set_format (previous_log_format );
3028+ cbm_log_set_level (previous_log_level );
3029+ bool skip_logged = admission_evaluated &&
3030+ atomic_load_explicit (& app_autoindex_skipped_seen , memory_order_acquire );
29863031
29873032 if (session ) {
29883033 callbacks .session_cancel (callbacks .context , session );
@@ -3002,6 +3047,10 @@ TEST(daemon_application_auto_index_honors_tracked_file_limit) {
30023047 ASSERT_TRUE (config_ready );
30033048 ASSERT_TRUE (initialized );
30043049 ASSERT_TRUE (limit_prevented_admission );
3050+ ASSERT_TRUE (skip_logged );
3051+ ASSERT_TRUE (app_log_line_has_field (app_autoindex_skipped_line , "reason=too_many_files" ));
3052+ ASSERT_TRUE (app_log_line_has_field (app_autoindex_skipped_line , "files=1" ));
3053+ ASSERT_TRUE (app_log_line_has_field (app_autoindex_skipped_line , "limit=0" ));
30053054 ASSERT_TRUE (stopped );
30063055 ASSERT_TRUE (cache_restored );
30073056 PASS ();
0 commit comments