@@ -5726,20 +5726,15 @@ TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_
57265726 ASSERT_NOT_NULL(store);
57275727 char source_path[512];
57285728 snprintf(source_path, sizeof(source_path), "%s/project/main.go", tmp);
5729- struct stat source_stat;
5730- ASSERT_EQ(stat(source_path, &source_stat), 0);
5731- #ifdef __APPLE__
5732- int64_t source_mtime_ns =
5733- ((int64_t)source_stat.st_mtimespec.tv_sec * (int64_t)CBM_NSEC_PER_SEC) +
5734- (int64_t)source_stat.st_mtimespec.tv_nsec;
5735- #elif defined(_WIN32)
5736- int64_t source_mtime_ns = (int64_t)source_stat.st_mtime * (int64_t)CBM_NSEC_PER_SEC;
5737- #else
5738- int64_t source_mtime_ns = ((int64_t)source_stat.st_mtim.tv_sec * (int64_t)CBM_NSEC_PER_SEC) +
5739- (int64_t)source_stat.st_mtim.tv_nsec;
5740- #endif
5741- ASSERT_EQ(cbm_store_upsert_file_hash(store, "test-project", "main.go", "", source_mtime_ns,
5742- source_stat.st_size),
5729+ /* The fixture must record the hash with the SAME mtime source the indexer
5730+ * writes with — cbm_path_info_utf8 — not struct stat. On Windows stat
5731+ * truncates to seconds while the stored record carries FILETIME-derived
5732+ * nanoseconds, so a stat-written fixture would never compare equal and the
5733+ * metadata_match contract below would fail. */
5734+ cbm_path_info_t path_info;
5735+ ASSERT_EQ(cbm_path_info_utf8(source_path, &path_info), 0);
5736+ ASSERT_EQ(cbm_store_upsert_file_hash(store, "test-project", "main.go", "", path_info.mtime_ns,
5737+ path_info.size),
57435738 CBM_STORE_OK);
57445739 cbm_project_t project = {0};
57455740 ASSERT_EQ(cbm_store_get_project(store, "test-project", &project), CBM_STORE_OK);
@@ -5782,6 +5777,56 @@ TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_
57825777 PASS();
57835778}
57845779
5780+ /* #1714: coverage freshness must compare mtime_ns at the SAME precision the
5781+ * indexer records it. The pipeline records cbm_path_info_utf8's value (which
5782+ * on Windows derives from FILETIME — nanosecond), while the freshness reader
5783+ * used to recompute from struct stat, which on Windows truncates to seconds
5784+ * (st_mtime). A byte-identical file therefore never matched and every path was
5785+ * reported metadata_changed. The reader now uses the indexer's own source. */
5786+ TEST(tool_check_index_coverage_freshness_uses_indexer_mtime_source_issue1714) {
5787+ char tmp[256];
5788+ cbm_mcp_server_t *srv = setup_snippet_server(tmp, sizeof(tmp));
5789+ ASSERT_NOT_NULL(srv);
5790+ cbm_store_t *store = cbm_mcp_server_store(srv);
5791+ ASSERT_NOT_NULL(store);
5792+
5793+ char source_path[512];
5794+ snprintf(source_path, sizeof(source_path), "%s/project/main.go", tmp);
5795+ cbm_path_info_t info;
5796+ ASSERT_EQ(cbm_path_info_utf8(source_path, &info), 0);
5797+
5798+ /* The hash exactly as the indexer writes it: same source, ns precision. */
5799+ ASSERT_EQ(cbm_store_upsert_file_hash(store, "test-project", "main.go", "", info.mtime_ns,
5800+ info.size),
5801+ CBM_STORE_OK);
5802+
5803+ char *response = cbm_mcp_handle_tool(
5804+ srv, "check_index_coverage", "{\"project\":\"test-project\",\"paths\":[\"main.go\"]}");
5805+ ASSERT_NOT_NULL(response);
5806+ ASSERT_NOT_NULL(strstr(response, "\"freshness\":\"metadata_match\""));
5807+ free(response);
5808+
5809+ /* A hash stored at seconds precision — what a stat-based reader previously
5810+ * compared against — must NOT match an unchanged file: the comparison must
5811+ * stay nanosecond-exact, or part of mtime resolution is silently dropped. */
5812+ int64_t seconds_mtime_ns = (info.mtime_ns / (int64_t)CBM_NSEC_PER_SEC) *
5813+ (int64_t)CBM_NSEC_PER_SEC;
5814+ if (seconds_mtime_ns != info.mtime_ns) {
5815+ ASSERT_EQ(cbm_store_upsert_file_hash(store, "test-project", "main.go", "",
5816+ seconds_mtime_ns, info.size),
5817+ CBM_STORE_OK);
5818+ response = cbm_mcp_handle_tool(
5819+ srv, "check_index_coverage", "{\"project\":\"test-project\",\"paths\":[\"main.go\"]}");
5820+ ASSERT_NOT_NULL(response);
5821+ ASSERT_NOT_NULL(strstr(response, "\"freshness\":\"metadata_changed\""));
5822+ free(response);
5823+ }
5824+
5825+ cleanup_snippet_dir(tmp);
5826+ cbm_mcp_server_free(srv);
5827+ PASS();
5828+ }
5829+
57855830TEST(tool_check_index_coverage_rejects_stale_generation) {
57865831 char tmp[256];
57875832 cbm_mcp_server_t *srv = setup_snippet_server(tmp, sizeof(tmp));
@@ -20389,6 +20434,7 @@ SUITE(mcp) {
2038920434 RUN_TEST(tool_check_index_coverage_preserves_multiple_scope_labels);
2039020435 RUN_TEST(tool_check_index_coverage_accepts_truncated_ignored_catalog_for_fresh_path_issue1613);
2039120436 RUN_TEST(tool_check_index_coverage_rejects_stale_generation);
20437+ RUN_TEST(tool_check_index_coverage_freshness_uses_indexer_mtime_source_issue1714);
2039220438 RUN_TEST(tool_check_index_coverage_requires_source_when_file_metadata_changed);
2039320439 RUN_TEST(tool_check_index_coverage_surfaces_lookup_errors);
2039420440 RUN_TEST(tool_index_status_includes_git_metadata);
0 commit comments