diff --git a/CHANGELOG.md b/CHANGELOG.md index b8c079a..1f01965 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- **`cora index` re-extracts every file once after an extractor change (#803).** A file was skipped when its `mtime:size` matched, so an upgrade that improved an extractor (the Ruby nesting of #791, for example) never reached the files that had not changed, until someone ran `cora index --rebuild`. The fingerprint now carries an extractor version, so the first `cora index` after such an upgrade re-extracts all files once; later runs skip unchanged files as before. + - **Ruby: methods in modules and classes nested in modules are indexed (#791).** Two gaps in the Tree-sitter extractor: a second `"module"` arm that also extracts the methods was unreachable, and only the direct children of a file were visited, so the usual `module Outer; class Inner; def run` layout indexed nothing inside `Outer`. The superclass edge of a Ruby class also carried the `<` of `< Base` in its target, so it never matched the symbol `Base`. On Sinatra (147 Ruby files) the index grows from 184 to 853 symbols, the methods from 79 to 622, and `cora explore halt` finds `Sinatra::Base#halt`. Projects with Ruby code need one `cora index` to benefit. - **`index-breaking-change` no longer reports a removal whose callers are deleted in the same change (#794).** The index predates the diff, so a helper removed together with its only caller was reported as "breaks 1 caller" and blocked the review; callers whose call site is one of the removed lines (or in a deleted file) are now ignored, and the finding stays for callers that remain. diff --git a/src/index/mod.rs b/src/index/mod.rs index f919e5a..a2e3b5d 100644 --- a/src/index/mod.rs +++ b/src/index/mod.rs @@ -463,7 +463,7 @@ fn index_project_with_id( .map(|d| d.as_secs()) .unwrap_or(0); let size = metadata.len(); - let cheap_fp = format!("{mtime}:{size}"); + let cheap_fp = format!("v{EXTRACTOR_VERSION}:{mtime}:{size}"); // O(1) hashmap lookup — skip file entirely if unchanged if let Some(stored) = stored_fingerprints.get(&rel_str) { @@ -741,6 +741,12 @@ fn file_fingerprint(content: &str) -> String { format!("{:x}", hasher.finalize()) } +/// Version of what the extractors record. It is part of every file fingerprint, +/// so bumping it makes the next `cora index` re-extract every file once, including +/// files that did not change (#803). Bump it whenever an extractor starts to +/// record symbols or edges it did not record before, or stops recording wrong ones. +const EXTRACTOR_VERSION: u32 = 1; + /// Statistics from an index build run. #[derive(Debug, Clone, Default)] pub struct IndexStats { @@ -1039,6 +1045,48 @@ pub struct AuthService { ); } + /// #803: the stored fingerprint names the extractor version, so an extractor + /// that records more (or different) edges is applied to files that did not change. + #[test] + fn test_fingerprint_carries_the_extractor_version() { + let conn = mem_conn(); + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path().to_path_buf(); + std::fs::write(root.join("lib.rs"), "pub fn alpha() {}\n").unwrap(); + index_project(&conn, &root, false).unwrap(); + let stored: String = conn + .query_row("SELECT fingerprint FROM files LIMIT 1", [], |r| r.get(0)) + .unwrap(); + assert!( + stored.starts_with(&format!("v{EXTRACTOR_VERSION}:")), + "fingerprint {stored:?} must start with the extractor version" + ); + } + + #[test] + fn test_index_from_an_older_extractor_is_re_extracted_once() { + let conn = mem_conn(); + let tmp = tempfile::tempdir().unwrap(); + let root = tmp.path().to_path_buf(); + std::fs::write(root.join("lib.rs"), "pub fn alpha() {}\n").unwrap(); + index_project(&conn, &root, false).unwrap(); + // An index written before the version existed (or by an older extractor). + conn.execute( + "UPDATE files SET fingerprint = substr(fingerprint, instr(fingerprint, ':') + 1)", + [], + ) + .unwrap(); + let again = index_project(&conn, &root, false).unwrap(); + assert_eq!( + again.files_indexed, 1, + "an old-format fingerprint must be re-extracted" + ); + assert_eq!(again.files_skipped, 0); + let third = index_project(&conn, &root, false).unwrap(); + assert_eq!(third.files_skipped, 1, "and then skipped as before"); + assert_eq!(third.files_indexed, 0); + } + /// Regression (#522): an incremental no-op re-index (all fingerprints /// match) must keep reporting the STORED symbol count — DB state must /// survive untouched re-runs.