@@ -2727,20 +2727,15 @@ TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_
27272727 ASSERT_NOT_NULL (store );
27282728 char source_path [512 ];
27292729 snprintf (source_path , sizeof (source_path ), "%s/project/main.go" , tmp );
2730- struct stat source_stat ;
2731- ASSERT_EQ (stat (source_path , & source_stat ), 0 );
2732- #ifdef __APPLE__
2733- int64_t source_mtime_ns =
2734- ((int64_t )source_stat .st_mtimespec .tv_sec * (int64_t )CBM_NSEC_PER_SEC ) +
2735- (int64_t )source_stat .st_mtimespec .tv_nsec ;
2736- #elif defined(_WIN32 )
2737- int64_t source_mtime_ns = (int64_t )source_stat .st_mtime * (int64_t )CBM_NSEC_PER_SEC ;
2738- #else
2739- int64_t source_mtime_ns = ((int64_t )source_stat .st_mtim .tv_sec * (int64_t )CBM_NSEC_PER_SEC ) +
2740- (int64_t )source_stat .st_mtim .tv_nsec ;
2741- #endif
2742- ASSERT_EQ (cbm_store_upsert_file_hash (store , "test-project" , "main.go" , "" , source_mtime_ns ,
2743- source_stat .st_size ),
2730+ /* The fixture must record the hash with the SAME mtime source the indexer
2731+ * writes with — cbm_path_info_utf8 — not struct stat. On Windows stat
2732+ * truncates to seconds while the stored record carries FILETIME-derived
2733+ * nanoseconds, so a stat-written fixture would never compare equal and the
2734+ * metadata_match contract below would fail. */
2735+ cbm_path_info_t path_info ;
2736+ ASSERT_EQ (cbm_path_info_utf8 (source_path , & path_info ), 0 );
2737+ ASSERT_EQ (cbm_store_upsert_file_hash (store , "test-project" , "main.go" , "" , path_info .mtime_ns ,
2738+ path_info .size ),
27442739 CBM_STORE_OK );
27452740 cbm_project_t project = {0 };
27462741 ASSERT_EQ (cbm_store_get_project (store , "test-project" , & project ), CBM_STORE_OK );
@@ -2782,6 +2777,56 @@ TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_
27822777 PASS ();
27832778}
27842779
2780+ /* #1714: coverage freshness must compare mtime_ns at the SAME precision the
2781+ * indexer records it. The pipeline records cbm_path_info_utf8's value (which
2782+ * on Windows derives from FILETIME — nanosecond), while the freshness reader
2783+ * used to recompute from struct stat, which on Windows truncates to seconds
2784+ * (st_mtime). A byte-identical file therefore never matched and every path was
2785+ * reported metadata_changed. The reader now uses the indexer's own source. */
2786+ TEST (tool_check_index_coverage_freshness_uses_indexer_mtime_source_issue1714 ) {
2787+ char tmp [256 ];
2788+ cbm_mcp_server_t * srv = setup_snippet_server (tmp , sizeof (tmp ));
2789+ ASSERT_NOT_NULL (srv );
2790+ cbm_store_t * store = cbm_mcp_server_store (srv );
2791+ ASSERT_NOT_NULL (store );
2792+
2793+ char source_path [512 ];
2794+ snprintf (source_path , sizeof (source_path ), "%s/project/main.go" , tmp );
2795+ cbm_path_info_t info ;
2796+ ASSERT_EQ (cbm_path_info_utf8 (source_path , & info ), 0 );
2797+
2798+ /* The hash exactly as the indexer writes it: same source, ns precision. */
2799+ ASSERT_EQ (cbm_store_upsert_file_hash (store , "test-project" , "main.go" , "" , info .mtime_ns ,
2800+ info .size ),
2801+ CBM_STORE_OK );
2802+
2803+ char * response = cbm_mcp_handle_tool (
2804+ srv , "check_index_coverage" , "{\"project\":\"test-project\",\"paths\":[\"main.go\"]}" );
2805+ ASSERT_NOT_NULL (response );
2806+ ASSERT_NOT_NULL (strstr (response , "\"freshness\":\"metadata_match\"" ));
2807+ free (response );
2808+
2809+ /* A hash stored at seconds precision — what a stat-based reader previously
2810+ * compared against — must NOT match an unchanged file: the comparison must
2811+ * stay nanosecond-exact, or part of mtime resolution is silently dropped. */
2812+ int64_t seconds_mtime_ns = (info .mtime_ns / (int64_t )CBM_NSEC_PER_SEC ) *
2813+ (int64_t )CBM_NSEC_PER_SEC ;
2814+ if (seconds_mtime_ns != info .mtime_ns ) {
2815+ ASSERT_EQ (cbm_store_upsert_file_hash (store , "test-project" , "main.go" , "" ,
2816+ seconds_mtime_ns , info .size ),
2817+ CBM_STORE_OK );
2818+ response = cbm_mcp_handle_tool (
2819+ srv , "check_index_coverage" , "{\"project\":\"test-project\",\"paths\":[\"main.go\"]}" );
2820+ ASSERT_NOT_NULL (response );
2821+ ASSERT_NOT_NULL (strstr (response , "\"freshness\":\"metadata_changed\"" ));
2822+ free (response );
2823+ }
2824+
2825+ cleanup_snippet_dir (tmp );
2826+ cbm_mcp_server_free (srv );
2827+ PASS ();
2828+ }
2829+
27852830TEST (tool_check_index_coverage_rejects_stale_generation ) {
27862831 char tmp [256 ];
27872832 cbm_mcp_server_t * srv = setup_snippet_server (tmp , sizeof (tmp ));
@@ -11332,6 +11377,7 @@ SUITE(mcp) {
1133211377 RUN_TEST (tool_check_index_coverage_preserves_multiple_scope_labels );
1133311378 RUN_TEST (tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_issue1613 );
1133411379 RUN_TEST (tool_check_index_coverage_rejects_stale_generation );
11380+ RUN_TEST (tool_check_index_coverage_freshness_uses_indexer_mtime_source_issue1714 );
1133511381 RUN_TEST (tool_check_index_coverage_requires_source_when_file_metadata_changed );
1133611382 RUN_TEST (tool_check_index_coverage_surfaces_lookup_errors );
1133711383 RUN_TEST (tool_index_status_includes_git_metadata );
0 commit comments