diff --git a/AGENTS.md b/AGENTS.md index ba3ec800..a364d641 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,12 +39,22 @@ Protocol) stdio server. No AI / vector / LLM anywhere in the binary — output i where the unit struct produced NO node before — plus the Rust half of PR #1516's first-class `union` kind, byte-for-byte; it deliberately claims NO `instantiates` edge, because that edge fires only for the call-expression construction form and - a Rust union is constructible only as `U { … }`). + a Rust union is constructible only as `U { … }`), and `reference/golden/go/` + (corpus `crates/codegraph-bench/fixtures/go/`; the repo's only Go corpus, and the + only corpus where `files.generated` is anything other than `0` — it byte-pins + #1500 content-header detection at BOTH values, three each way: `payroll.go` + (Go's codified `Code generated … DO NOT EDIT.`), `worker_types.go` (pattern 6 / + CG-25, Wrangler's TWO `by` clauses) and `api.pb.go` (the PATH signal, no banner) + at `1`; `payroll_usecase.go` (hand-written, and the must-not-demote side), + `nightly.go` (ONE `by` clause — ordinary prose) and `generator.go` (the banner is + a `const` in the function BODY, so the comment-line fence rejects it) at `0`). The Python cross-file edge is resolved by Gate 3a's unique-name fallback; import Gate 3b is deliberately unreachable for real Python nodes because the extractor does not mark them exported. Regen recipe: `docs/equivalence.md` "Godot fixture" / "Ruby fixture" / "Python fixture" / "Kotlin fixture" / - "TypeScript resolution fixture" / "C++ fixture" / "Rust fixture" sections. + "TypeScript resolution fixture" / "C++ fixture" / "Rust fixture" / "Go fixture" + sections. `mini` has no re-indexable provenance and a schema migration cannot + normalise it in place, so it has its own "Mini schema rebuild" recipe there. - **node-id formula**: `{kind}:{sha256("{filePath}:{kind}:{name}:{line}").hex[:32]}`; file nodes are the literal `file:{relpath}`; lines are 1-based; paths relative with `/`. - **No AI / vector / LLM crates** — enforced by `scripts/guardrail.sh` (CI gate): diff --git a/README.md b/README.md index 3aea8db5..09627189 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,19 @@ Project configuration remains in `.codegraph/config.toml` and fields `legacyIndexPresent` and `legacyIndexPaths` remain in `status --json`, but always report `false` and `[]` respectively. +### Re-index required for content-header generated-file detection + +Generated-file detection now also reads a file's **content banner**, not only its +filename, so a machine-written `payroll.go` carrying +`// Code generated … DO NOT EDIT.` is demoted in ranking like a `.pb.go` file +already was. The verdict is computed at index time and stored on the file row. + +An index built by an earlier release therefore reports every file as +non-generated for the content half until it is re-extracted. Nothing breaks in the +meantime — the filename signal keeps working exactly as before — and the next +`codegraph index` or `codegraph sync` picks the new detection up automatically, +since the extraction-version bump classifies the old index as outdated. + --- ## Installation diff --git a/crates/codegraph-bench/fixtures/go/api.pb.go b/crates/codegraph-bench/fixtures/go/api.pb.go new file mode 100644 index 00000000..443bceee --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/api.pb.go @@ -0,0 +1,14 @@ +package payroll + +type PayrollRequest struct { + ID string + Amount int64 +} + +func (m *PayrollRequest) Reset() { + *m = PayrollRequest{} +} + +func (m *PayrollRequest) GetAmount() int64 { + return m.Amount +} diff --git a/crates/codegraph-bench/fixtures/go/generator.go b/crates/codegraph-bench/fixtures/go/generator.go new file mode 100644 index 00000000..9f965b20 --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/generator.go @@ -0,0 +1,14 @@ +package payroll + +// Emitter writes CRUD scaffolding for a table. +type Emitter struct { + Table string +} + +// Emit renders the file body, prefixing it with the standard banner. +// The banner literal lives in the BODY as a string constant, so this +// generator source must NOT be classified as generated itself. +func (e *Emitter) Emit() string { + const banner = "// Code generated by fkit-crud. DO NOT EDIT." + return banner + "\\n\\npackage " + e.Table + "\\n" +} diff --git a/crates/codegraph-bench/fixtures/go/nightly.go b/crates/codegraph-bench/fixtures/go/nightly.go new file mode 100644 index 00000000..8dd61656 --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/nightly.go @@ -0,0 +1,9 @@ +package payroll + +// RunNightly kicks off the ETL job. Note the wording below: the report is +// generated by running the ETL job, which is ONE "by" clause and therefore +// ordinary prose rather than a generation banner. +func RunNightly(jobID string) error { + _ = jobID + return nil +} diff --git a/crates/codegraph-bench/fixtures/go/payroll.go b/crates/codegraph-bench/fixtures/go/payroll.go new file mode 100644 index 00000000..f4f00de3 --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/payroll.go @@ -0,0 +1,12 @@ +// Code generated by fkit-crud. DO NOT EDIT. + +package payroll + +type Payroll struct { + ID string + Amount int64 +} + +func ComputePay(p *Payroll) int64 { + return p.Amount +} diff --git a/crates/codegraph-bench/fixtures/go/payroll_usecase.go b/crates/codegraph-bench/fixtures/go/payroll_usecase.go new file mode 100644 index 00000000..6aac0d1c --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/payroll_usecase.go @@ -0,0 +1,6 @@ +package payroll + +// ComputePay applies the real business rules for a payroll run. +func ComputePay(p *Payroll, bonus int64) int64 { + return p.Amount + bonus +} diff --git a/crates/codegraph-bench/fixtures/go/worker_types.go b/crates/codegraph-bench/fixtures/go/worker_types.go new file mode 100644 index 00000000..58a3a991 --- /dev/null +++ b/crates/codegraph-bench/fixtures/go/worker_types.go @@ -0,0 +1,12 @@ +// Generated by Wrangler by running `wrangler types` (hash: 6f3a1c9d2b) + +package worker + +type Env struct { + AccountID string + Bucket string +} + +func NewEnv(account string, bucket string) *Env { + return &Env{AccountID: account, Bucket: bucket} +} diff --git a/crates/codegraph-bench/src/oracle/canonicalize.rs b/crates/codegraph-bench/src/oracle/canonicalize.rs index 67b5aab9..d1df91f3 100644 --- a/crates/codegraph-bench/src/oracle/canonicalize.rs +++ b/crates/codegraph-bench/src/oracle/canonicalize.rs @@ -146,8 +146,9 @@ fn canonical_refs(conn: &Connection) -> Result> { } fn canonical_files(conn: &Connection) -> Result> { - let mut stmt = - conn.prepare("SELECT path, content_hash, language, size, node_count, errors FROM files")?; + let mut stmt = conn.prepare( + "SELECT path, content_hash, language, size, node_count, errors, generated FROM files", + )?; let rows = stmt.query_map([], |row| { Ok(RawFile { path: row.get(0)?, @@ -156,6 +157,7 @@ fn canonical_files(conn: &Connection) -> Result> { size: row.get(3)?, node_count: row.get(4)?, errors: row.get(5)?, + generated: row.get(6)?, }) })?; @@ -387,6 +389,7 @@ struct RawFile { size: i64, node_count: i64, errors: Option, + generated: i64, } impl RawFile { @@ -399,6 +402,7 @@ impl RawFile { row.insert("size".to_string(), json!(self.size)); row.insert("node_count".to_string(), json!(self.node_count)); row.insert("errors".to_string(), json_column(self.errors, "errors")?); + row.insert("generated".to_string(), json!(self.generated)); Ok(row) } } diff --git a/crates/codegraph-bench/tests/equivalence.rs b/crates/codegraph-bench/tests/equivalence.rs index 76296097..1ab71041 100644 --- a/crates/codegraph-bench/tests/equivalence.rs +++ b/crates/codegraph-bench/tests/equivalence.rs @@ -128,6 +128,26 @@ fn rust_db_is_self_equivalent_to_rust_golden() { assert_equivalent(&rust_db(), &rust_golden_dir()).unwrap(); } +#[test] +fn generated_golden_matches_committed_go_fixture() { + // Guards #1500 content-header detection: `files.generated` is byte-pinned at + // BOTH values — 1 for the Go banner, the Wrangler double-`by` banner, and the + // path-only `.pb.go`; 0 for the hand-written sibling, the single-`by` prose + // negative, and the generator whose banner is a `const` in its body. + let tempdir = TestDir::new("generated-golden-go"); + write_golden(&go_db(), tempdir.path()).unwrap(); + + let expected = load_golden(&go_golden_dir()).unwrap(); + let actual = load_golden(tempdir.path()).unwrap(); + + diff_canonical(&expected, &actual, None).unwrap(); +} + +#[test] +fn go_db_is_self_equivalent_to_go_golden() { + assert_equivalent(&go_db(), &go_golden_dir()).unwrap(); +} + #[test] fn generated_golden_matches_committed_python_fixture() { let tempdir = TestDir::new("generated-golden-python"); @@ -438,6 +458,14 @@ fn rust_golden_dir() -> PathBuf { workspace_root().join("reference/golden/rust") } +fn go_db() -> PathBuf { + workspace_root().join("reference/golden/go/colby.db") +} + +fn go_golden_dir() -> PathBuf { + workspace_root().join("reference/golden/go") +} + fn python_db() -> PathBuf { workspace_root().join("reference/golden/python/colby.db") } diff --git a/crates/codegraph-cli/src/main.rs b/crates/codegraph-cli/src/main.rs index 09e1d085..8eb3e40d 100644 --- a/crates/codegraph-cli/src/main.rs +++ b/crates/codegraph-cli/src/main.rs @@ -17,6 +17,7 @@ use anyhow::{Context, Result, anyhow, bail}; use clap::{CommandFactory, Parser, Subcommand, ValueEnum}; use clap_complete::{Shell, generate}; use codegraph_core::config::Config; +use codegraph_core::generated_header::detect_generated_file; use codegraph_core::logger::{LoggerConfig, init_logger}; use codegraph_core::node_id::hash_content; use codegraph_core::types::{ExtractionResult, FileRecord, Language, Node, NodeKind}; @@ -4866,6 +4867,7 @@ fn index_project_inner( .filter(|n| n.file_path == *relative) .count() as i64, errors: result.errors.clone(), + generated: detect_generated_file(relative, &source), }; tx.send((i, relative.clone(), file, result)) .map_err(|_| anyhow!("parse result channel disconnected"))?; @@ -6957,6 +6959,7 @@ mod formatter_and_env_tests { indexed_at: 0, node_count, errors: Vec::new(), + generated: false, } } diff --git a/crates/codegraph-cli/tests/parallel_index.rs b/crates/codegraph-cli/tests/parallel_index.rs index 47703ae9..6b63f0a7 100644 --- a/crates/codegraph-cli/tests/parallel_index.rs +++ b/crates/codegraph-cli/tests/parallel_index.rs @@ -52,6 +52,10 @@ fn mini_fixture() -> PathBuf { workspace_root().join("crates/codegraph-bench/fixtures/mini") } +fn go_fixture() -> PathBuf { + workspace_root().join("crates/codegraph-bench/fixtures/go") +} + fn copy_tree(src: &Path, dst: &Path) { fs::create_dir_all(dst).unwrap(); for entry in fs::read_dir(src).unwrap() { @@ -258,6 +262,46 @@ fn oversized_file_size_skips_with_exact_file_record() { ); } +/// WRITE PATH 1 (`index --force`, the rayon producer closure): the persisted +/// `files.generated` must carry the real per-file verdict, not a hardcoded false. +/// This is the CLI counterpart to the two `codegraph-watch` tests that cover the +/// incremental-sync and Outdated-rebuild write paths — three independent sites +/// build their own `FileRecord`, so each needs its own end-to-end assertion. +#[test] +fn index_force_writes_the_generated_flag_per_file() { + let dir = TestDir::new("generated-flag"); + let project = dir.path().join("go"); + copy_tree(&go_fixture(), &project); + + init_and_force_index(&project); + + let store = Store::open(&db_path(&project)).unwrap(); + let mut rows: Vec<(String, i64)> = store + .connection() + .prepare("SELECT path, generated FROM files ORDER BY path") + .unwrap() + .query_map([], |row| { + Ok((row.get::<_, String>(0)?, row.get::<_, i64>(1)?)) + }) + .unwrap() + .map(Result::unwrap) + .collect(); + rows.sort(); + + assert_eq!( + rows, + vec![ + ("api.pb.go".to_string(), 1), + ("generator.go".to_string(), 0), + ("nightly.go".to_string(), 0), + ("payroll.go".to_string(), 1), + ("payroll_usecase.go".to_string(), 0), + ("worker_types.go".to_string(), 1), + ], + "index --force must persist the real generated verdict for every file" + ); +} + /// SYNC PRAGMA GUARD (end-to-end): the bulk-index path runs under /// `synchronous=OFF` (T5) but must restore NORMAL before returning. After a real /// `index --force` via the CLI, a FRESH `Store::open` on the produced DB must diff --git a/crates/codegraph-core/src/generated_header.rs b/crates/codegraph-core/src/generated_header.rs new file mode 100644 index 00000000..d67ca23f --- /dev/null +++ b/crates/codegraph-core/src/generated_header.rs @@ -0,0 +1,670 @@ +//! Content-header detection for machine-generated files (upstream #1500). +//! +//! [`crate::file_class::is_generated_file`] answers the same question from the +//! PATH alone, and for most ecosystems that is enough: codegen output follows a +//! `..` convention (`.pb.go`, `_pb2.py`, `.g.dart`) that a +//! suffix check catches for free. Go is the exception that motivates this +//! module. Its convention is a CONTENT marker rather than a filename one, so a +//! machine-written `payroll.go` sitting beside hand-written use-cases is +//! invisible to a path check — and renaming it is not an option, because +//! `payroll.go` is a legal, ordinary Go filename. +//! +//! The two signals stay deliberately separate: +//! +//! 1. the path check is pure, allocation-free, and safe to call inside a sort +//! comparator; +//! 2. this module reads the head of a file's text, so it is evaluated ONCE per +//! file at index time (the content is already in memory for parsing) and the +//! verdict is persisted to `files.generated`. Readers take it from the +//! database instead of re-reading headers per request, which is what keeps +//! ranking a function of the index rather than of the filesystem's current +//! state. +//! +//! The two are combined by [`detect_generated_file`], which is what the indexer +//! writes. Consumers UNION the stored flag with the path check rather than +//! trusting the column alone: a database written before this module existed has +//! `0` on every row, and reading it alone would silently drop the path demotion +//! those indexes already had. +//! +//! Both remain RELEVANCE HINTS, never filters, exactly as `file_class` says: a +//! machine-written file stays fully present in the graph and reachable in +//! results, and only ranks after a real implementation of the same name. +//! +//! # Three fences, all load-bearing +//! +//! Precision is the whole game here — a false positive silently demotes +//! hand-written code in every ranking path — so the marker must clear all +//! three: +//! +//! 1. **A bounded window.** [`HEADER_SCAN_CHARS`] AND [`HEADER_SCAN_LINES`], +//! both, not either. Generous enough for a build-tag block plus an +//! Apache-2.0 preamble above the marker, tight enough that the same text +//! quoted in the BODY of a generator's own source does not qualify. +//! 2. **A cheap stem pre-filter.** Every marker contains the stem `generat`, so +//! one unanchored case-insensitive scan rejects nearly every hand-written +//! file before any line splitting. This exists for SPEED, not precision. +//! 3. **A comment line.** The marker must sit on a line with a comment leader, +//! or inside an open block comment. Generators always emit theirs as a +//! comment, and requiring it is what rules out string literals and +//! identifiers that merely contain the words. +//! +//! # NOTE for future editors +//! +//! The marker literals in this file sit BELOW the line window this detector +//! scans, so the module does not classify its own source. A test pins that: if +//! you move the pattern table above [`HEADER_SCAN_LINES`], the test fails +//! rather than the repo silently demoting this file. The same hazard is live in +//! `file_class.rs`, whose own doc comment quotes the Go marker inside the +//! character window and is spared by the line bound alone; a second test pins +//! that too. + +use crate::file_class::is_generated_file; + +/// How much of a file's head counts as "the header", in bytes of the scanned +/// prefix. Paired with [`HEADER_SCAN_LINES`] — a marker must clear BOTH. +const HEADER_SCAN_CHARS: usize = 8192; + +/// How many lines of the window are examined. This bound is what spares this +/// module's own pattern table, so it is load-bearing rather than decorative. +const HEADER_SCAN_LINES: usize = 60; + +/// Line-comment leaders across the languages indexed here, matched after +/// leading whitespace and case-insensitively. `--` covers SQL/Haskell/Lua, `%` +/// LaTeX/Erlang/Prolog, `;` Lisp/asm/ini, `'` VB, `!` Fortran, and a bare `*` a +/// continuation line inside a `/* … */` block. +const COMMENT_LEADERS: &[&str] = &[ + "//", "/*", "*", "#", "--", ""), + ("\"\"\"", "\"\"\""), + ("'''", "'''"), + ("=begin", "=end"), + ("<#", "#>"), +]; + +/// Whether the head of `content` carries a recognized machine-generation +/// banner. +/// +/// Bounded to [`HEADER_SCAN_CHARS`] and [`HEADER_SCAN_LINES`], and the marker +/// must sit on a comment line, so a generator's own source — which holds the +/// same text as a string constant in its body — is not flagged. +pub fn has_generated_header(content: &str) -> bool { + if content.is_empty() { + return false; + } + + let head = header_window(content); + // Fast reject for nearly every hand-written file: every marker contains the + // stem, so this runs before any line splitting. Speed, not precision. + if !contains_ignore_ascii_case(head, "generat") { + return false; + } + + let mut open_block: Option<(&str, &str)> = None; + for line in head.lines().take(HEADER_SCAN_LINES) { + let lower = line.to_ascii_lowercase(); + + let on_comment_line = open_block.is_some() || starts_with_comment_leader(&lower); + if on_comment_line && matches_generated_banner(&lower) { + return true; + } + + // Advance the block state AFTER testing, so the opening line of a + // `/* Code generated … */` block is itself matched by the leader rule. + if let Some((_, close)) = open_block { + if lower.contains(close) { + open_block = None; + } + continue; + } + for &(open, close) in BLOCK_DELIMS { + let Some(at) = lower.find(open) else { continue }; + // A same-line close (`/* … */`, a one-line docstring) leaves no open + // block, so a later bare code line is not read as commented out. + if !lower[at + open.len()..].contains(close) { + open_block = Some((open, close)); + } + break; + } + } + + false +} + +/// The leading [`HEADER_SCAN_CHARS`] bytes, truncated at a char boundary. +/// +/// Slicing on the raw byte index would panic mid-codepoint, which a multibyte +/// file reaches routinely; `floor_char_boundary` is still unstable, so the +/// boundary is walked down by hand. +fn header_window(content: &str) -> &str { + if content.len() <= HEADER_SCAN_CHARS { + return content; + } + let mut end = HEADER_SCAN_CHARS; + while end > 0 && !content.is_char_boundary(end) { + end -= 1; + } + &content[..end] +} + +/// Whether `haystack` holds `needle` (already lowercase) anywhere, comparing +/// ASCII-case-insensitively without allocating. +fn contains_ignore_ascii_case(haystack: &str, needle: &str) -> bool { + let (h, n) = (haystack.as_bytes(), needle.as_bytes()); + if n.is_empty() || h.len() < n.len() { + return n.is_empty(); + } + h.windows(n.len()) + .any(|w| w.iter().zip(n).all(|(a, b)| a.to_ascii_lowercase() == *b)) +} + +/// Whether `lower` — a lowercased line — opens with a comment leader. +fn starts_with_comment_leader(lower: &str) -> bool { + let trimmed = lower.trim_start(); + COMMENT_LEADERS + .iter() + .any(|leader| trimmed.starts_with(leader)) +} + +/// Whether a lowercased comment line matches one of the eight banner shapes. +/// +/// The workspace deliberately carries no regex dependency (the sibling path +/// check is hand-written too), so each upstream pattern is expressed with +/// `find` plus a bounded-gap helper. Every gap bound is upstream's. +fn matches_generated_banner(lower: &str) -> bool { + // 1. Go's codified convention, honored by gofmt/linguist and emitted by + // protoc-gen-go, mockgen, sqlc, ent, wire, stringer. + if phrase_then(lower, "code generated", &["do not edit"], 200) { + return true; + } + + // 2. protoc's Java/C#/Python banner, ANTLR, Dagger, FlatBuffers, + // rust-bindgen, Xcode asset catalogs, Bazel. + for lead in ["generated by", "generated from", "generated with"] { + if phrase_then( + lower, + lead, + &["do not edit", "do not modify", "do not change"], + 200, + ) { + return true; + } + } + + // 3. The `@generated` tag, guarded so `foo@generated` and `@@generated` do + // not qualify: the preceding byte must not be alphanumeric, `_`, or `@`. + if let Some(rest) = find_standalone_at_generated(lower) { + return rest; + } + + // 4. .NET's `` / `` doc tag. + for open in ["') || tail.starts_with("/>") { + return true; + } + } + } + + // 5. swagger-codegen / OpenAPI Generator, Thrift, FlatBuffers. The trailing + // `by` is REQUIRED — bare "automatically generated" is ordinary prose. + for form in [ + "automatically generated by", + "auto-generated by", + "auto generated by", + "autogenerated by", + ] { + if lower.contains(form) { + return true; + } + } + + // 6. CG-25 — the "run this to regenerate" shape (Cloudflare Wrangler). + // TWO separate `by` clauses is the discriminator: the banner must name a + // tool AND then say `by running`, so "generated by running the nightly + // job" (one clause) is correctly rejected. + if let Some(at) = lower.find("generated by") { + let rest = &lower[at + "generated by".len()..]; + let named_tool = rest.trim_start(); + if named_tool.len() < rest.len() + && !named_tool.is_empty() + && within(named_tool, "by running", 80) + { + return true; + } + } + + // 7. Self-declaring in-house banners that name no tool. + for subject in ["this file ", "this class ", "this code ", "this module "] { + if let Some(at) = lower.find(subject) { + let rest = &lower[at + subject.len()..]; + for verb in ["is ", "was "] { + if let Some(tail) = rest.strip_prefix(verb) { + for form in [ + "generated", + "auto-generated", + "auto generated", + "autogenerated", + ] { + if tail.starts_with(form) { + return true; + } + } + } + } + } + } + + // 8. The reverse ordering: "DO NOT EDIT — this is a generated file". + for lead in ["do not edit", "do not modify"] { + if phrase_then( + lower, + lead, + &[ + "auto-generated", + "auto generated", + "autogenerated", + "generated file", + "generated code", + ], + 120, + ) { + return true; + } + } + + false +} + +/// Whether `lead` occurs and any of `tails` follows it within `gap` bytes. +fn phrase_then(lower: &str, lead: &str, tails: &[&str], gap: usize) -> bool { + let mut from = 0; + while let Some(rel) = lower[from..].find(lead) { + let after = from + rel + lead.len(); + if tails.iter().any(|t| within(&lower[after..], t, gap)) { + return true; + } + from = after; + } + false +} + +/// Whether `needle` starts within the first `gap` bytes of `rest`. +fn within(rest: &str, needle: &str, gap: usize) -> bool { + let mut end = rest.len().min(gap + needle.len()); + while end > 0 && !rest.is_char_boundary(end) { + end -= 1; + } + rest[..end] + .find(needle) + .is_some_and(|at| at <= gap.min(rest.len())) +} + +/// Whether the line carries a STANDALONE `@generated` tag. +/// +/// Returns `Some(true)` on a match. The byte before the `@` must not be a +/// letter, digit, `_`, or another `@`, which is what rejects `foo@generated` +/// (an address-shaped token) and `@@generated`. +fn find_standalone_at_generated(lower: &str) -> Option { + let tag = "@generated"; + let mut from = 0; + while let Some(rel) = lower[from..].find(tag) { + let at = from + rel; + let prev_ok = lower[..at] + .chars() + .next_back() + .is_none_or(|c| !(c.is_alphanumeric() || c == '_' || c == '@')); + let next_ok = lower[at + tag.len()..] + .chars() + .next() + .is_none_or(|c| !(c.is_alphanumeric() || c == '_')); + if prev_ok && next_ok { + return Some(true); + } + from = at + tag.len(); + } + None +} + +/// The union signal — path convention OR content banner — and the value the +/// indexer persists to `files.generated`. +/// +/// The content half only ever ADDS: a file the path check already flags stays +/// flagged whatever its header says, so this can never REMOVE a demotion an +/// existing index applied. +pub fn detect_generated_file(path: &str, content: &str) -> bool { + is_generated_file(path) || has_generated_header(content) +} + +#[cfg(test)] +mod tests { + use super::*; + + // ---- pattern 1: Go's codified convention (the #1500 defect itself) ----- + + #[test] + fn go_banner_in_header_is_detected() { + assert!(has_generated_header( + "// Code generated by fkit-crud. DO NOT EDIT.\n\npackage payroll\n" + )); + } + + // ---- patterns 2-5, 7, 8 ------------------------------------------------ + + #[test] + fn protoc_generated_by_do_not_edit_banner_is_detected() { + assert!(has_generated_header( + "// Generated by the protocol buffer compiler. DO NOT EDIT!\n// source: a.proto\n" + )); + // "from" and "with", and the DO NOT MODIFY / CHANGE spellings. + assert!(has_generated_header( + "# Generated from Foo.g4 - DO NOT EDIT\n" + )); + assert!(has_generated_header( + "/* generated with rust-bindgen; do not modify */\n" + )); + assert!(has_generated_header( + "-- automatically generated by sqlc. do not change.\n" + )); + } + + #[test] + fn standalone_at_generated_tag_is_detected() { + assert!(has_generated_header("// @generated\n")); + assert!(has_generated_header( + "/* @generated SignedSource<<0123456789abcdef>> */\n" + )); + // Start-of-line with no leader is still a comment line via `#`. + assert!(has_generated_header("# @generated by protobuf-es\n")); + } + + #[test] + fn dotnet_auto_generated_doc_tag_is_detected() { + assert!(has_generated_header("// \n")); + assert!(has_generated_header("// \n")); + assert!(has_generated_header( + "//------------------------------------------------------------------------------\n\ + // \n\ + // This code was generated by a tool.\n\ + // \n" + )); + } + + #[test] + fn openapi_and_thrift_autogenerated_by_banner_is_detected() { + assert!(has_generated_header( + "// NOTE: This class is auto generated by OpenAPI Generator.\n" + )); + assert!(has_generated_header( + "// Autogenerated by Thrift Compiler (0.14.1)\n" + )); + assert!(has_generated_header( + "// automatically generated by the FlatBuffers compiler, do not modify\n" + )); + } + + #[test] + fn bare_automatically_generated_prose_is_not_a_banner() { + // Pattern 5 REQUIRES a following "by": without it the phrase is ordinary + // prose, and flagging it would demote hand-written code. + assert!(!has_generated_header( + "// The table below is automatically generated at runtime.\n" + )); + } + + #[test] + fn self_declaring_in_house_banner_is_detected() { + assert!(has_generated_header("// This file is auto-generated.\n")); + assert!(has_generated_header( + "# This module was generated -- edits will be lost\n" + )); + assert!(has_generated_header("// This class is autogenerated\n")); + } + + #[test] + fn reverse_ordered_do_not_edit_banner_is_detected() { + assert!(has_generated_header( + "// DO NOT EDIT -- this is a generated file.\n" + )); + assert!(has_generated_header( + "# do not modify: generated code, regenerate instead\n" + )); + } + + // ---- pattern 6 / CG-25: the Wrangler double-`by` discriminator --------- + + #[test] + fn wrangler_double_by_banner_is_detected() { + assert!(has_generated_header( + "// Generated by Wrangler by running `wrangler types` (hash: abc123)\n" + )); + } + + #[test] + fn single_by_prose_is_not_a_banner() { + // ONE "by" clause. Bare "generated by" is deliberately not enough, or + // every changelog line describing a nightly job would be a banner. + assert!(!has_generated_header( + "// the report is generated by running the nightly job\n" + )); + assert!(!has_generated_header( + "// This chart is generated by the dashboard service.\n" + )); + } + + // ---- the three fences ------------------------------------------------- + + #[test] + fn banner_below_the_line_bound_is_not_detected() { + // 60 filler lines, so the banner lands on line 61 — one past the bound. + let mut content = String::new(); + for _ in 0..HEADER_SCAN_LINES { + content.push_str("// padding\n"); + } + content.push_str("// Code generated by protoc-gen-go. DO NOT EDIT.\n"); + assert!(!has_generated_header(&content)); + + // Moving it one line UP makes it the 60th line and it IS found, so the + // test pins the boundary rather than merely "deep banners are missed". + let mut inside = String::new(); + for _ in 0..(HEADER_SCAN_LINES - 1) { + inside.push_str("// padding\n"); + } + inside.push_str("// Code generated by protoc-gen-go. DO NOT EDIT.\n"); + assert!(has_generated_header(&inside)); + } + + #[test] + fn banner_beyond_the_char_window_is_not_detected() { + // ONE long comment line pushes the second line past the byte window, so + // this isolates the CHAR fence: the line count is 2, far under the line + // bound, so only the window can reject it. + let mut content = String::from("// "); + content.push_str(&"a".repeat(HEADER_SCAN_CHARS + 8)); + content.push('\n'); + content.push_str("// Code generated by protoc-gen-go. DO NOT EDIT.\n"); + assert!(content.lines().count() < HEADER_SCAN_LINES); + assert!(!has_generated_header(&content)); + } + + #[test] + fn banner_off_a_comment_line_is_not_detected() { + // A generator's OWN source holds the banner as a string constant in its + // body. Flagging that would demote the generator itself. + assert!(!has_generated_header( + "package gen\n\nconst Banner = \"Code generated by fkit-crud. DO NOT EDIT.\"\n" + )); + assert!(!has_generated_header( + "banner = 'Code generated by tool. DO NOT EDIT.'\n" + )); + } + + #[test] + fn banner_inside_an_open_block_comment_is_detected() { + // Line 2 carries NO comment leader of its own — only the open `/*` + // state makes it count. + assert!(has_generated_header( + "/*\nCode generated by protoc-gen-go. DO NOT EDIT.\n*/\npackage p\n" + )); + assert!(has_generated_header( + "\n" + )); + assert!(has_generated_header( + "\"\"\"\nGenerated by protoc. DO NOT EDIT.\n\"\"\"\n" + )); + } + + #[test] + fn a_closed_block_comment_does_not_leak_its_state() { + // A same-line close leaves NO open block, so a later bare code line + // holding the words must not be read as still-inside a comment. + assert!(!has_generated_header( + "/* header */\nbanner := \"Code generated by tool. DO NOT EDIT.\"\n" + )); + } + + #[test] + fn at_generated_requires_a_standalone_tag() { + // Guarded against an e-mail-ish `foo@generated` and a doubled `@@`. + assert!(!has_generated_header("// foo@generated\n")); + assert!(!has_generated_header("// @@generated\n")); + // The standalone form still matches, so the guard is not over-broad. + assert!(has_generated_header("// @generated\n")); + } + + #[test] + fn multibyte_content_does_not_panic_at_the_window_boundary() { + // A file whose 8192nd BYTE lands INSIDE a 3-byte codepoint, so a naive + // `&content[..HEADER_SCAN_CHARS]` panics instead of returning a verdict. + // The `is_char_boundary` assertions pin that precondition, so the test + // cannot silently degrade into scanning ordinary ASCII. + let filler = "€".repeat(4000); + assert!(!filler.is_char_boundary(HEADER_SCAN_CHARS)); + assert!(!has_generated_header(&filler)); + + // Same hazard WITH a real banner on line 1: the verdict must still be + // reachable, so the fix cannot be "give up on multibyte input". + let banner = format!("// Code generated by protoc-gen-go. DO NOT EDIT.\n{filler}"); + assert!(!banner.is_char_boundary(HEADER_SCAN_CHARS)); + assert!(has_generated_header(&banner)); + } + + #[test] + fn empty_and_stemless_content_is_rejected_cheaply() { + assert!(!has_generated_header("")); + assert!(!has_generated_header("package main\n\nfunc main() {}\n")); + } + + // ---- self-classification guards (D4) ---------------------------------- + + #[test] + fn this_module_does_not_classify_itself() { + // This file quotes all eight banner shapes. They sit below the line + // bound, so the detector must not flag its own source. Moving the + // pattern table above HEADER_SCAN_LINES fails HERE rather than silently + // demoting this module in every ranking path. + let own_source = include_str!("generated_header.rs"); + assert!( + !has_generated_header(own_source), + "generated_header.rs classified ITSELF as generated: the pattern \ + table has moved inside the first {HEADER_SCAN_LINES} lines" + ); + // The guard is the LINE bound, so prove the banner text really is + // present and inside the char window — otherwise this test could pass + // for the trivial reason that nothing matches anywhere. + let window = header_window(own_source); + assert!(contains_ignore_ascii_case(window, "generat")); + + // MEASURED, and thinner than it looks: the first banner LITERAL sits at + // byte ~8089 of this file, i.e. ~100 bytes inside the 8192 window, so + // widening HEADER_SCAN_LINES alone does NOT trip the assertion above — + // the char window clips the literals instead. Both fences must stay. + // Pin the line distance so growth above the table fails here rather + // than quietly consuming the cushion. + let first_literal = own_source + .find("\"code generated\"") + .expect("the pattern table must still hold the Go marker literal"); + let literal_line = own_source[..first_literal].lines().count(); + assert!( + literal_line > HEADER_SCAN_LINES, + "the first banner literal moved to line {literal_line}, inside the \ + {HEADER_SCAN_LINES}-line bound" + ); + } + + #[test] + fn file_class_rs_is_not_classified_by_its_own_doc_comment() { + // file_class.rs's doc comment quotes Go's marker on a `///` line, INSIDE + // the char window (measured: byte offset ~5519, line ~136). Only the + // line bound spares it, which is what makes that bound load-bearing. + let sibling = include_str!("file_class.rs"); + assert!( + !has_generated_header(sibling), + "file_class.rs classified as generated by its own doc comment" + ); + let window = header_window(sibling); + assert!(contains_ignore_ascii_case(window, "generat")); + } + + #[test] + fn no_first_party_source_in_this_crate_is_classified() { + // A Rust `///` doc comment IS a comment line, so any of this crate's + // files could trip the detector the same way. Sweep the whole crate + // rather than pinning the two files already known to be at risk. + for (name, source) in [ + ("lib.rs", include_str!("lib.rs")), + ("types.rs", include_str!("types.rs")), + ("traits.rs", include_str!("traits.rs")), + ("node_id.rs", include_str!("node_id.rs")), + ("config.rs", include_str!("config.rs")), + ("errors.rs", include_str!("errors.rs")), + ("index_paths.rs", include_str!("index_paths.rs")), + ("logger.rs", include_str!("logger.rs")), + ] { + assert!( + !has_generated_header(source), + "{name} was classified as generated" + ); + } + } + + // ---- the union written to files.generated ----------------------------- + + #[test] + fn detect_generated_file_unions_path_and_content() { + // Path signal alone: a `.pb.go` with NO banner is still generated. + assert!(detect_generated_file("api.pb.go", "package api\n")); + // Content signal alone: an ordinary Go filename WITH a banner. + assert!(detect_generated_file( + "payroll.go", + "// Code generated by fkit-crud. DO NOT EDIT.\npackage payroll\n" + )); + // Both. + assert!(detect_generated_file( + "api.pb.go", + "// Code generated by protoc-gen-go. DO NOT EDIT.\n" + )); + // Neither — a hand-written file must never be flagged. + assert!(!detect_generated_file( + "payroll_usecase.go", + "package payroll\n\nfunc ComputePay() {}\n" + )); + } + + #[test] + fn the_content_half_never_removes_the_path_signal() { + // D1's direction: content can only ADD. A path-flagged file stays + // flagged even when its content is plainly hand-written, so the union + // cannot re-rank an existing index in the wrong direction. + let handwritten = "package api\n\nfunc Real() {}\n"; + assert!(!has_generated_header(handwritten)); + assert!(detect_generated_file("api.pb.go", handwritten)); + } +} diff --git a/crates/codegraph-core/src/lib.rs b/crates/codegraph-core/src/lib.rs index e52b442a..e90c6fda 100644 --- a/crates/codegraph-core/src/lib.rs +++ b/crates/codegraph-core/src/lib.rs @@ -3,6 +3,7 @@ pub mod config; pub mod errors; pub mod file_class; +pub mod generated_header; pub mod index_paths; pub mod logger; pub mod node_id; diff --git a/crates/codegraph-core/src/types.rs b/crates/codegraph-core/src/types.rs index 7d5f6056..5ce22bb1 100644 --- a/crates/codegraph-core/src/types.rs +++ b/crates/codegraph-core/src/types.rs @@ -526,6 +526,11 @@ pub struct FileRecord { pub indexed_at: i64, pub node_count: i64, pub errors: Vec, + /// Whether this file looks machine-generated, from + /// [`crate::generated_header::detect_generated_file`] — the union of the + /// path convention and a content banner. A relevance hint for ranking, never + /// a filter. + pub generated: bool, } /// Structural label for HOW a reference was extracted, orthogonal to the typed @@ -700,6 +705,7 @@ mod tests { indexed_at: 1_700_000_001_000, node_count: 3, errors: vec!["warning".to_string()], + generated: false, }; let file_value = serde_json::to_value(file).expect("file record serializes"); assert_eq!(file_value["contentHash"], json!("sha256")); diff --git a/crates/codegraph-graph/tests/godot_resource_audit.rs b/crates/codegraph-graph/tests/godot_resource_audit.rs index e443f4bb..2fd55fbc 100644 --- a/crates/codegraph-graph/tests/godot_resource_audit.rs +++ b/crates/codegraph-graph/tests/godot_resource_audit.rs @@ -63,6 +63,7 @@ fn run_pipeline(test_name: &str, root: &Path, relative_files: &[&str]) -> Store indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-graph/tests/traversal.rs b/crates/codegraph-graph/tests/traversal.rs index 93506a6c..5532918b 100644 --- a/crates/codegraph-graph/tests/traversal.rs +++ b/crates/codegraph-graph/tests/traversal.rs @@ -498,6 +498,7 @@ fn file_record(path: &str) -> codegraph_core::types::FileRecord { indexed_at: 1, node_count: 1, errors: Vec::new(), + generated: false, } } diff --git a/crates/codegraph-mcp/src/engine.rs b/crates/codegraph-mcp/src/engine.rs index 688463fa..9863312a 100644 --- a/crates/codegraph-mcp/src/engine.rs +++ b/crates/codegraph-mcp/src/engine.rs @@ -1578,6 +1578,28 @@ impl CodeGraphEngine { // === Symbol resolution ============================================== + /// Sort `nodes` so machine-generated files rank LAST, by the D1 union of the + /// path convention and the stored `files.generated` flag. + /// + /// The union is what makes this safe on an index written before #1500: those + /// rows all read 0, so reading the column ALONE would drop the path demotion + /// they already had. One batch query over the sorted+deduped candidate paths, + /// so no `HashSet` iteration order reaches output. + fn sort_generated_last(&self, nodes: &mut [Node]) -> anyhow::Result<()> { + let mut paths = nodes + .iter() + .map(|n| n.file_path.clone()) + .collect::>(); + paths.sort_unstable(); + paths.dedup(); + let stored = self.store.generated_paths_among(&paths)?; + // ASCENDING on "is generated", so `false` (0) comes first. + nodes.sort_by_key(|n| { + u8::from(is_generated_file(&n.file_path) || stored.contains(&n.file_path)) + }); + Ok(()) + } + /// `findSymbolMatches` (`tools.ts:3220-3265`): exact-name enumeration for a /// bare name, falling back to the top fuzzy result. fn find_symbol_matches(&self, symbol: &str) -> anyhow::Result> { @@ -1586,7 +1608,7 @@ impl CodeGraphEngine { let exact = self.store.nodes_by_name(symbol)?; if !exact.is_empty() { let mut sorted = exact; - sorted.sort_by_key(|n| is_generated_file(&n.file_path) as u8); + self.sort_generated_last(&mut sorted)?; return Ok(sorted); } let fuzzy = search_nodes( @@ -1617,7 +1639,7 @@ impl CodeGraphEngine { return Ok(Vec::new()); } let mut sorted = exact; - sorted.sort_by_key(|n| is_generated_file(&n.file_path) as u8); + self.sort_generated_last(&mut sorted)?; Ok(sorted) } @@ -1643,7 +1665,7 @@ impl CodeGraphEngine { }); } let mut ranked = exact; - ranked.sort_by_key(|n| is_generated_file(&n.file_path) as u8); + self.sort_generated_last(&mut ranked)?; let locations = ranked .iter() .map(|n| format!("{} at {}:{}", n.kind.as_str(), n.file_path, n.start_line)) @@ -1747,6 +1769,18 @@ impl CodeGraphEngine { self.rescue_change_surface(&mut sub, &seed_ids, query, &traverser)?; + // The stored half of the generated signal, in ONE batch query. Sorted and + // deduped first, so no `HashSet` iteration order can reach output — the + // same discipline `rescue_change_surface` applies to its candidates. + let mut candidate_paths = sub + .nodes + .iter() + .map(|n| n.file_path.clone()) + .collect::>(); + candidate_paths.sort_unstable(); + candidate_paths.dedup(); + sub.generated_files = self.store.generated_paths_among(&candidate_paths)?; + sub.finalize(); Ok(sub) } @@ -2253,6 +2287,12 @@ struct ExploreSubgraph { /// lexically-dissimilar answer file (grpc's `dialoptions.go`) is not buried /// under incidental roots that merely share query words. rescued_files: HashSet, + /// Paths whose `files.generated` row is 1, fetched in ONE batch query before + /// `finalize` runs. `finalize` has no store handle, so the stored half of the + /// generated signal has to arrive as a field — exactly how `rescued_files` + /// reaches it. Empty leaves behavior on the path check alone, which is what + /// keeps a pre-#1500 index ranking as it always did. + generated_files: HashSet, } impl ExploreSubgraph { @@ -2336,7 +2376,8 @@ impl ExploreSubgraph { // when it is the only match. The sort is descending, so real // code must carry the HIGHER value. `find_symbol_matches` and // `find_all_symbols` apply the same signal. - let not_generated = u8::from(!is_generated_file(fp)); + let not_generated = + u8::from(!(is_generated_file(fp) || self.generated_files.contains(fp))); let sym_count = self .nodes .iter() @@ -3313,6 +3354,7 @@ mod tests { indexed_at: 0, node_count, errors: Vec::new(), + generated: false, } } @@ -3358,6 +3400,33 @@ mod tests { put_file(engine, &file); } + /// `put_indexed_source` plus the stored `files.generated` verdict, so a test + /// can model a banner-marked file (flag 1 on an ORDINARY path) and a + /// pre-#1500 index (flag 0 on a path the suffix check still catches). + fn put_indexed_source_generated( + engine: &CodeGraphEngine, + rel: &str, + content: &str, + language: Language, + node_count: i64, + generated: bool, + ) { + write_src(engine, rel, content); + let metadata = std::fs::metadata(engine.project_root.join(rel)).unwrap(); + let modified_at = metadata + .modified() + .unwrap() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_millis() as i64; + let mut file = file_rec(rel, language, node_count); + file.content_hash = codegraph_core::node_id::hash_content(content); + file.size = metadata.len() as i64; + file.modified_at = modified_at; + file.generated = generated; + put_file(engine, &file); + } + #[test] fn ext_search_empty_query_errors() { let engine = test_engine(); @@ -5103,6 +5172,254 @@ mod tests { ); } + /// #1500 — the same ranking property as the `.pb.go` test above, but the + /// generated file carries an ORDINARY Go filename and is known only by its + /// stored `files.generated` flag. The path check cannot see it, so this fails + /// unless `finalize` consults the batch-fetched set. + #[test] + fn explore_ranks_a_real_impl_above_a_banner_marked_generated_file() { + let mut engine = test_engine(); + // Both names are ordinary: `a_banner.go` sorts FIRST alphabetically and + // would win on the tie-break, so a pass cannot come from name ordering. + let generated = node_lang( + "ComputePay", + "ComputePay", + "payroll/a_banner.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + let real = node_lang( + "ComputePay", + "ComputePay", + "payroll/zz_real.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + put_indexed_source_generated( + &engine, + "payroll/a_banner.go", + "// Code generated by fkit-crud. DO NOT EDIT.\nfunc ComputePay() int {\n\treturn 0\n}\n", + Language::Go, + 1, + true, + ); + put_indexed_source_generated( + &engine, + "payroll/zz_real.go", + "func ComputePay() int {\n\treturn 42\n}\n", + Language::Go, + 1, + false, + ); + // Neither path matches the suffix check, so the stored flag is the ONLY + // signal available — that is what makes this test the #1500 regression. + assert!(!is_generated_file("payroll/a_banner.go")); + put_nodes(&mut engine, &[generated.clone(), real.clone()]); + + let text = text_of(&engine.execute( + "codegraph_explore", + &serde_json::json!({"query": "ComputePay"}), + )); + let order: Vec<&str> = text + .lines() + .filter(|l| l.starts_with("#### ")) + .filter_map(|l| { + ["payroll/zz_real.go", "payroll/a_banner.go"] + .into_iter() + .find(|f| l.contains(f)) + }) + .collect(); + assert_eq!( + order, + vec!["payroll/zz_real.go", "payroll/a_banner.go"], + "the real implementation must precede the banner-marked file; got {order:?} in:\n{text}" + ); + } + + /// #1500 — the same signal in `find_symbol_matches`, whose sort is ASCENDING + /// (so `false` sorts first). A flipped polarity would still compile, so this + /// pins the direction as well as the presence of the union. + #[test] + fn find_symbol_matches_demotes_a_banner_marked_definition() { + let mut engine = test_engine(); + let generated = node_lang( + "ComputePay", + "ComputePay", + "payroll/a_banner.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + let real = node_lang( + "ComputePay", + "ComputePay", + "payroll/zz_real.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + put_indexed_source_generated( + &engine, + "payroll/a_banner.go", + "// Code generated by fkit-crud. DO NOT EDIT.\nfunc ComputePay() int {\n\treturn 0\n}\n", + Language::Go, + 1, + true, + ); + put_indexed_source_generated( + &engine, + "payroll/zz_real.go", + "func ComputePay() int {\n\treturn 42\n}\n", + Language::Go, + 1, + false, + ); + put_nodes(&mut engine, &[generated, real]); + + let matches = engine.find_symbol_matches("ComputePay").unwrap(); + let files: Vec<&str> = matches.iter().map(|n| n.file_path.as_str()).collect(); + assert_eq!( + files, + vec!["payroll/zz_real.go", "payroll/a_banner.go"], + "find_symbol_matches must rank the banner-marked definition LAST" + ); + } + + /// D1 GUARD — the stored flag only ever ADDS. A database written before + /// #1500 has `generated = 0` on every row, so a `.pb.go` file must STILL be + /// demoted by the path check alone. Drop the `is_generated_file(...) ||` half + /// and this fails, which is what stops the change from silently re-ranking + /// every existing index in the wrong direction. + #[test] + fn a_pre_change_index_keeps_the_path_demotion_when_generated_is_zero() { + let mut engine = test_engine(); + let generated = node_lang( + "Marshal", + "Marshal", + "payroll/a_stub.pb.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + let real = node_lang( + "Marshal", + "Marshal", + "payroll/zz_real.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + // `generated = 0` on BOTH rows, exactly as a pre-#1500 database reads. + put_indexed_source_generated( + &engine, + "payroll/a_stub.pb.go", + "func Marshal() int {\n\treturn 0\n}\n", + Language::Go, + 1, + false, + ); + put_indexed_source_generated( + &engine, + "payroll/zz_real.go", + "func Marshal() int {\n\treturn 42\n}\n", + Language::Go, + 1, + false, + ); + put_nodes(&mut engine, &[generated, real]); + + // find_symbol_matches (ASCENDING) still demotes it. + let matches = engine.find_symbol_matches("Marshal").unwrap(); + let files: Vec<&str> = matches.iter().map(|n| n.file_path.as_str()).collect(); + assert_eq!( + files, + vec!["payroll/zz_real.go", "payroll/a_stub.pb.go"], + "a stored 0 must not remove the PATH demotion in find_symbol_matches" + ); + + // ... and so does finalize, through the explore surface. + let text = text_of(&engine.execute( + "codegraph_explore", + &serde_json::json!({"query": "Marshal"}), + )); + let order: Vec<&str> = text + .lines() + .filter(|l| l.starts_with("#### ")) + .filter_map(|l| { + ["payroll/zz_real.go", "payroll/a_stub.pb.go"] + .into_iter() + .find(|f| l.contains(f)) + }) + .collect(); + assert_eq!( + order, + vec!["payroll/zz_real.go", "payroll/a_stub.pb.go"], + "a stored 0 must not remove the PATH demotion in finalize; got {order:?} in:\n{text}" + ); + } + + /// Pins the TODO-28 wiring on its own, so a refactor that stops populating + /// the field fails a NAMED test instead of only shifting a ranking. + #[test] + fn explore_generated_files_set_is_populated_before_finalize() { + let mut engine = test_engine(); + let generated = node_lang( + "ComputePay", + "ComputePay", + "payroll/a_banner.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + put_indexed_source_generated( + &engine, + "payroll/a_banner.go", + "// Code generated by fkit-crud. DO NOT EDIT.\nfunc ComputePay() int {\n\treturn 0\n}\n", + Language::Go, + 1, + true, + ); + put_indexed_source_generated( + &engine, + "payroll/zz_real.go", + "func ComputePay() int {\n\treturn 42\n}\n", + Language::Go, + 1, + false, + ); + let real = node_lang( + "ComputePay", + "ComputePay", + "payroll/zz_real.go", + 1, + 3, + NodeKind::Function, + Language::Go, + ); + put_nodes(&mut engine, &[generated, real]); + + let sub = engine.find_relevant_context("ComputePay").unwrap(); + assert!( + sub.generated_files.contains("payroll/a_banner.go"), + "the flagged path must reach the subgraph before finalize; got {:?}", + sub.generated_files + ); + assert!( + !sub.generated_files.contains("payroll/zz_real.go"), + "an unflagged path must NOT appear; got {:?}", + sub.generated_files + ); + } + /// Tier 1 item 2 NEGATIVE — the demotion is a RANKING hint, never a filter: /// a generated file must stay reachable, and when it is the ONLY definition /// site it still renders. diff --git a/crates/codegraph-mcp/tests/godot_honesty_mcp.rs b/crates/codegraph-mcp/tests/godot_honesty_mcp.rs index 4a725e04..8149ad1d 100644 --- a/crates/codegraph-mcp/tests/godot_honesty_mcp.rs +++ b/crates/codegraph-mcp/tests/godot_honesty_mcp.rs @@ -78,6 +78,7 @@ fn pipeline_project(files: &[(&str, &str)]) -> TestProject { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .unwrap(); store.upsert_nodes(&result.nodes).unwrap(); diff --git a/crates/codegraph-mcp/tests/golden_mcp.rs b/crates/codegraph-mcp/tests/golden_mcp.rs index c30534a6..1e7057b0 100644 --- a/crates/codegraph-mcp/tests/golden_mcp.rs +++ b/crates/codegraph-mcp/tests/golden_mcp.rs @@ -774,6 +774,7 @@ fn index_fixture(files: &[(&str, &str)]) -> TestProject { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .unwrap(); } diff --git a/crates/codegraph-mcp/tests/reopen.rs b/crates/codegraph-mcp/tests/reopen.rs index fc80920a..f323d549 100644 --- a/crates/codegraph-mcp/tests/reopen.rs +++ b/crates/codegraph-mcp/tests/reopen.rs @@ -95,6 +95,7 @@ fn index_into(base: &Path, files: &[(&str, &str)]) { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .unwrap(); } diff --git a/crates/codegraph-resolve/src/context.rs b/crates/codegraph-resolve/src/context.rs index 2fc93e07..97d7db49 100644 --- a/crates/codegraph-resolve/src/context.rs +++ b/crates/codegraph-resolve/src/context.rs @@ -504,6 +504,7 @@ mod tests { indexed_at: 0, node_count: count, errors: Vec::new(), + generated: false, } } diff --git a/crates/codegraph-resolve/src/resolver.rs b/crates/codegraph-resolve/src/resolver.rs index f825dd13..7220bac9 100644 --- a/crates/codegraph-resolve/src/resolver.rs +++ b/crates/codegraph-resolve/src/resolver.rs @@ -2767,6 +2767,7 @@ mod tests { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); @@ -3820,6 +3821,7 @@ mod tests { indexed_at: 0, node_count: 0, errors: Vec::new(), + generated: false, } } @@ -3869,6 +3871,7 @@ mod tests { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/src/snapshot_context.rs b/crates/codegraph-resolve/src/snapshot_context.rs index d619b0fa..7e7c7f3a 100644 --- a/crates/codegraph-resolve/src/snapshot_context.rs +++ b/crates/codegraph-resolve/src/snapshot_context.rs @@ -422,6 +422,7 @@ mod tests { indexed_at: 0, node_count: count, errors: Vec::new(), + generated: false, } } diff --git a/crates/codegraph-resolve/tests/godot_class_member.rs b/crates/codegraph-resolve/tests/godot_class_member.rs index a80e0d25..cf974f83 100644 --- a/crates/codegraph-resolve/tests/godot_class_member.rs +++ b/crates/codegraph-resolve/tests/godot_class_member.rs @@ -70,6 +70,7 @@ fn run_pipeline(test_name: &str, root: &Path, relative_files: &[&str]) -> (Store indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/godot_post_extract.rs b/crates/codegraph-resolve/tests/godot_post_extract.rs index 02e3d8aa..e25e44c1 100644 --- a/crates/codegraph-resolve/tests/godot_post_extract.rs +++ b/crates/codegraph-resolve/tests/godot_post_extract.rs @@ -67,6 +67,7 @@ fn run_pipeline(test_name: &str, root: &Path, relative_files: &[&str]) -> (Store indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/golden_resolution.rs b/crates/codegraph-resolve/tests/golden_resolution.rs index 59be0e64..ad4c7493 100644 --- a/crates/codegraph-resolve/tests/golden_resolution.rs +++ b/crates/codegraph-resolve/tests/golden_resolution.rs @@ -137,6 +137,7 @@ fn resolve_fixture(test_name: &str, root: &Path, relative_files: &[&str]) -> Vec indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/snapshot_equivalence.rs b/crates/codegraph-resolve/tests/snapshot_equivalence.rs index 42c962bc..60386311 100644 --- a/crates/codegraph-resolve/tests/snapshot_equivalence.rs +++ b/crates/codegraph-resolve/tests/snapshot_equivalence.rs @@ -66,6 +66,7 @@ fn index_fixture(test_name: &str, root: &Path, relative_files: &[&str]) -> (Stor indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/tauri_ipc.rs b/crates/codegraph-resolve/tests/tauri_ipc.rs index 4a99dd1c..f9895c20 100644 --- a/crates/codegraph-resolve/tests/tauri_ipc.rs +++ b/crates/codegraph-resolve/tests/tauri_ipc.rs @@ -103,6 +103,7 @@ fn index_without_resolve(test_name: &str, root: &Path, relative_files: &[&str]) indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/tier2_false_edges.rs b/crates/codegraph-resolve/tests/tier2_false_edges.rs index 221cc1d7..930584d3 100644 --- a/crates/codegraph-resolve/tests/tier2_false_edges.rs +++ b/crates/codegraph-resolve/tests/tier2_false_edges.rs @@ -145,6 +145,7 @@ fn resolve_fixture(name: &str) -> Resolved { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/tier3_union_edges.rs b/crates/codegraph-resolve/tests/tier3_union_edges.rs index 22b2d848..f0d584b6 100644 --- a/crates/codegraph-resolve/tests/tier3_union_edges.rs +++ b/crates/codegraph-resolve/tests/tier3_union_edges.rs @@ -128,6 +128,7 @@ fn resolve_fixture(name: &str) -> Resolved { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-resolve/tests/tier6_resolution.rs b/crates/codegraph-resolve/tests/tier6_resolution.rs index 08cee4db..0184d68c 100644 --- a/crates/codegraph-resolve/tests/tier6_resolution.rs +++ b/crates/codegraph-resolve/tests/tier6_resolution.rs @@ -150,6 +150,7 @@ fn resolve_fixture(name: &str) -> Resolved { indexed_at: 0, node_count: result.nodes.len() as i64, errors: Vec::new(), + generated: false, }) .expect("upsert file"); store.upsert_nodes(&result.nodes).expect("upsert nodes"); diff --git a/crates/codegraph-store/src/index_state.rs b/crates/codegraph-store/src/index_state.rs index b33aba64..04dd58e9 100644 --- a/crates/codegraph-store/src/index_state.rs +++ b/crates/codegraph-store/src/index_state.rs @@ -115,7 +115,7 @@ pub const CURRENT_STORAGE_PROTOCOL: u64 = 2; /// The extraction-pipeline version this binary produces. This is the single /// source of truth: no other crate may define its own copy. -pub const CURRENT_EXTRACTION_VERSION: u64 = 8; +pub const CURRENT_EXTRACTION_VERSION: u64 = 9; /// The `project_metadata` key under which a built index records the extraction /// version it was produced with. Single source of truth for the key spelling. diff --git a/crates/codegraph-store/src/migrations.rs b/crates/codegraph-store/src/migrations.rs index 38313d88..eba02366 100644 --- a/crates/codegraph-store/src/migrations.rs +++ b/crates/codegraph-store/src/migrations.rs @@ -2,7 +2,7 @@ use rusqlite::{Connection, OptionalExtension, params}; use crate::schema::BASE_SCHEMA; -pub const CURRENT_SCHEMA_VERSION: i64 = 7; +pub const CURRENT_SCHEMA_VERSION: i64 = 8; pub const FRESH_SCHEMA_DESCRIPTION: &str = "Initial schema includes all migrations"; const MIGRATIONS: &[Migration] = &[ @@ -21,6 +21,7 @@ const MIGRATIONS: &[Migration] = &[ CREATE INDEX IF NOT EXISTS idx_unresolved_file_path ON unresolved_refs(file_path); CREATE INDEX IF NOT EXISTS idx_edges_provenance ON edges(provenance); "#, + adds_column: Some(("unresolved_refs", "file_path")), }, Migration { version: 3, @@ -28,6 +29,7 @@ const MIGRATIONS: &[Migration] = &[ sql: r#" CREATE INDEX IF NOT EXISTS idx_nodes_lower_name ON nodes(lower(name)); "#, + adds_column: None, }, Migration { version: 4, @@ -36,6 +38,7 @@ const MIGRATIONS: &[Migration] = &[ DROP INDEX IF EXISTS idx_edges_source; DROP INDEX IF EXISTS idx_edges_target; "#, + adds_column: None, }, Migration { version: 5, @@ -43,6 +46,7 @@ const MIGRATIONS: &[Migration] = &[ sql: r#" ALTER TABLE nodes ADD COLUMN return_type TEXT; "#, + adds_column: Some(("nodes", "return_type")), }, Migration { version: 6, @@ -50,6 +54,7 @@ const MIGRATIONS: &[Migration] = &[ sql: r#" ALTER TABLE unresolved_refs ADD COLUMN reference_subkind TEXT; "#, + adds_column: Some(("unresolved_refs", "reference_subkind")), }, Migration { version: 7, @@ -63,6 +68,22 @@ const MIGRATIONS: &[Migration] = &[ CREATE UNIQUE INDEX IF NOT EXISTS idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); "#, + adds_column: None, + }, + Migration { + version: 8, + description: "Add files.generated — content-header generated-file detection (#1500)", + // DDL ONLY, deliberately no backfill: the flag derives from file CONTENT + // and this table stores `content_hash`, not bytes. Backfilling would mean + // re-reading every file from disk inside a schema step, on paths that may + // no longer exist. Existing rows therefore stay 0 until re-extraction, + // and readers UNION the column with the path check so a pre-#1500 index + // keeps the demotion it already had. + sql: r#" + ALTER TABLE files ADD COLUMN generated INTEGER NOT NULL DEFAULT 0; + CREATE INDEX IF NOT EXISTS idx_files_generated ON files(path) WHERE generated = 1; + "#, + adds_column: Some(("files", "generated")), }, ]; @@ -71,6 +92,15 @@ struct Migration { version: i64, description: &'static str, sql: &'static str, + /// A `(table, column)` this migration ADDS. When the column is already + /// present the `sql` is skipped and only the version row is recorded. + /// + /// Needed because `ALTER TABLE` has no `IF NOT EXISTS` and + /// `run_pending_migrations` can legitimately replay a migration over a + /// database created from a NEWER `BASE_SCHEMA` that already carries the + /// column. Measured: without this, replaying migration 8 over a + /// `BASE_SCHEMA` database fails with `duplicate column name: generated`. + adds_column: Option<(&'static str, &'static str)>, } pub fn ensure_schema_and_migrations(conn: &mut Connection) -> rusqlite::Result<()> { @@ -174,7 +204,13 @@ fn run_pending_migrations(conn: &mut Connection) -> rusqlite::Result<()> { for migration in pending { let tx = conn.transaction()?; - tx.execute_batch(migration.sql)?; + let already_applied = match migration.adds_column { + Some((table, column)) => table_has_column(&tx, table, column)?, + None => false, + }; + if !already_applied { + tx.execute_batch(migration.sql)?; + } record_migration(&tx, migration.version, migration.description)?; tx.commit()?; } @@ -182,6 +218,21 @@ fn run_pending_migrations(conn: &mut Connection) -> rusqlite::Result<()> { Ok(()) } +/// Whether `table` already declares `column`, read from `PRAGMA table_info`. +/// +/// A missing table reports `false`, so a guarded migration still runs its `sql` +/// and fails loudly there rather than being silently skipped. +fn table_has_column(conn: &Connection, table: &str, column: &str) -> rusqlite::Result { + let mut stmt = conn.prepare(&format!("PRAGMA table_info({table})"))?; + let mut rows = stmt.query([])?; + while let Some(row) = rows.next()? { + if row.get::<_, String>(1)? == column { + return Ok(true); + } + } + Ok(false) +} + fn record_migration( conn: &Connection, version: i64, @@ -258,6 +309,7 @@ mod tests { CREATE TABLE unresolved_refs (id INTEGER PRIMARY KEY AUTOINCREMENT, from_node_id TEXT, reference_name TEXT, reference_kind TEXT, line INTEGER, col INTEGER, candidates TEXT); CREATE TABLE edges (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT, target TEXT, kind TEXT, metadata TEXT, line INTEGER, col INTEGER); CREATE TABLE nodes (id TEXT PRIMARY KEY, name TEXT); + CREATE TABLE files (path TEXT PRIMARY KEY, content_hash TEXT NOT NULL, language TEXT NOT NULL, size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, errors TEXT); CREATE INDEX idx_edges_source ON edges(source); CREATE INDEX idx_edges_target ON edges(target); INSERT INTO schema_versions (version, applied_at, description) VALUES (1, 0, 'base');", @@ -304,6 +356,101 @@ mod tests { .collect() } + // Builds a v7-shaped `files` table (the 8 pre-#1500 columns) with one row, so + // migration 8's effect on a PRE-EXISTING row is observable. + fn seed_v7_schema_with_one_file(conn: &Connection) { + conn.execute_batch( + "CREATE TABLE schema_versions (version INTEGER PRIMARY KEY, applied_at INTEGER NOT NULL, description TEXT); + CREATE TABLE files (path TEXT PRIMARY KEY, content_hash TEXT NOT NULL, language TEXT NOT NULL, size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, errors TEXT); + INSERT INTO schema_versions (version, applied_at, description) VALUES (7, 0, 'v7'); + INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors) + VALUES ('payroll.go', 'cafebabe', 'go', 172, 0, 0, 3, NULL);", + ) + .unwrap(); + } + + #[test] + fn migration_v8_adds_generated_column_defaulting_to_zero() { + let mut conn = Connection::open_in_memory().unwrap(); + seed_v7_schema_with_one_file(&conn); + assert_eq!(get_current_version(&conn).unwrap(), 7); + assert!(!has_column(&conn, "files", "generated")); + + run_pending_migrations(&mut conn).unwrap(); + + assert_eq!(get_current_version(&conn).unwrap(), CURRENT_SCHEMA_VERSION); + assert!(has_column(&conn, "files", "generated")); + assert!(has_index(&conn, "idx_files_generated")); + + // DDL only: the pre-existing row reads 0 rather than being backfilled, + // because the verdict derives from CONTENT this migration cannot see. + // Readers UNION the column with the path check, which is what keeps a + // pre-#1500 index ranking the way it already did. + let generated: i64 = conn + .query_row( + "SELECT generated FROM files WHERE path = 'payroll.go'", + [], + |row| row.get(0), + ) + .unwrap(); + assert_eq!(generated, 0); + + // NOT NULL, so a row inserted without the column still reads 0. + conn.execute_batch( + "INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at) + VALUES ('other.go', 'f00d', 'go', 1, 0, 0);", + ) + .unwrap(); + let nulls: i64 = conn + .query_row( + "SELECT COUNT(*) FROM files WHERE generated IS NULL", + [], + |r| r.get(0), + ) + .unwrap(); + assert_eq!(nulls, 0); + } + + #[test] + fn migration_v8_is_idempotent_when_the_column_already_exists() { + // Settles S4's guard question by MEASUREMENT: `ALTER TABLE` has no + // `IF NOT EXISTS`, so replaying migration 8 over a database whose + // BASE_SCHEMA already carries `generated` would raise + // `duplicate column name: generated` — and if it does, the migration + // needs a `PRAGMA table_info` guard rather than a plain `&'static str`. + let mut conn = Connection::open_in_memory().unwrap(); + ensure_schema_and_migrations(&mut conn).unwrap(); + assert!(has_column(&conn, "files", "generated")); + + // Rewind the recorded version to exactly 7 so ONLY migration 8 is + // pending, over a table that already has the column — the replay the + // guard must survive. `initialize_fresh_schema` records just two rows, + // 1 and CURRENT_SCHEMA_VERSION, so a row 7 has to be inserted rather + // than uncovered by deleting 8: dropping 8 alone would leave MAX = 1 and + // make migrations 2..8 pending, which tests a different thing. + conn.execute("DELETE FROM schema_versions WHERE version = 8", []) + .unwrap(); + conn.execute( + "INSERT INTO schema_versions (version, applied_at, description) VALUES (7, 0, 'v7')", + [], + ) + .unwrap(); + assert_eq!(get_current_version(&conn).unwrap(), 7); + + let replayed = run_pending_migrations(&mut conn); + + // Whichever way this lands, the column and index must still be intact + // and the version restored, so the assertion is meaningful either way. + assert!( + replayed.is_ok(), + "replaying migration 8 over a BASE_SCHEMA database must not fail: {:?}", + replayed.err() + ); + assert_eq!(get_current_version(&conn).unwrap(), CURRENT_SCHEMA_VERSION); + assert!(has_column(&conn, "files", "generated")); + assert!(has_index(&conn, "idx_files_generated")); + } + #[test] fn fresh_schema_dedups_duplicate_edge_identities() { let mut conn = Connection::open_in_memory().unwrap(); @@ -361,7 +508,7 @@ mod tests { run_pending_migrations(&mut conn).unwrap(); - assert_eq!(get_current_version(&conn).unwrap(), 7); + assert_eq!(get_current_version(&conn).unwrap(), CURRENT_SCHEMA_VERSION); assert!(has_index(&conn, "idx_edges_identity")); assert_eq!( @@ -391,6 +538,7 @@ mod tests { "CREATE TABLE schema_versions (version INTEGER PRIMARY KEY, applied_at INTEGER NOT NULL, description TEXT); CREATE TABLE nodes (id TEXT PRIMARY KEY, name TEXT); CREATE TABLE edges (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL, target TEXT NOT NULL, kind TEXT NOT NULL, metadata TEXT, line INTEGER, col INTEGER, provenance TEXT DEFAULT NULL); + CREATE TABLE files (path TEXT PRIMARY KEY, content_hash TEXT NOT NULL, language TEXT NOT NULL, size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, errors TEXT); INSERT INTO schema_versions (version, applied_at, description) VALUES (6, 0, 'v6'); INSERT INTO edges (id, source, target, kind, line, col) VALUES (1,'a','b','calls',5,3), diff --git a/crates/codegraph-store/src/queries.rs b/crates/codegraph-store/src/queries.rs index bc972211..c68c4fcc 100644 --- a/crates/codegraph-store/src/queries.rs +++ b/crates/codegraph-store/src/queries.rs @@ -1,4 +1,4 @@ -use std::collections::{BTreeSet, HashMap}; +use std::collections::{BTreeSet, HashMap, HashSet}; use codegraph_core::types::{ Edge, EdgeKind, FileRecord, Language, Node, NodeKind, ReferenceSubkind, UnresolvedRef, @@ -287,6 +287,37 @@ impl Store { Ok(out) } + /// The subset of `paths` whose file row has `generated = 1`. Batched and + /// chunked like [`Self::nodes_by_ids`]; a path with no row is simply absent + /// from the result. + /// + /// Reports ONLY what is stored: the union with the path convention + /// (`is_generated_file`) is the CALLER's job, so this stays a faithful view + /// of the column and the partial `idx_files_generated` index serves it. + pub fn generated_paths_among(&self, paths: &[String]) -> rusqlite::Result> { + let mut out = HashSet::new(); + if paths.is_empty() { + return Ok(out); + } + let mut unique = paths.to_vec(); + unique.sort_unstable(); + unique.dedup(); + for chunk in unique.chunks(SQLITE_PARAM_CHUNK_SIZE) { + let placeholders = std::iter::repeat_n("?", chunk.len()) + .collect::>() + .join(","); + let sql = + format!("SELECT path FROM files WHERE generated = 1 AND path IN ({placeholders})"); + let params = chunk.iter().map(|p| p as &dyn ToSql).collect::>(); + let mut stmt = self.conn.prepare(&sql)?; + let rows = stmt.query_map(params.as_slice(), |row| row.get::<_, String>(0))?; + for path in rows { + out.insert(path?); + } + } + Ok(out) + } + /// Ports the FTS SQL from `searchNodesFTS` in `upstream db/queries.ts:986-1052`. /// Keeps the upstream FTS5 escaping/prefix rules, BM25 weights, `ORDER BY score LIMIT/OFFSET`. pub fn search_nodes_fts( @@ -666,8 +697,8 @@ impl Store { let errors = json_array_or_null(&file.errors)?; self.conn.execute( r#" - INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors) - VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors) + INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors, generated) + VALUES (@path, @contentHash, @language, @size, @modifiedAt, @indexedAt, @nodeCount, @errors, @generated) ON CONFLICT(path) DO UPDATE SET content_hash = @contentHash, language = @language, @@ -675,7 +706,8 @@ impl Store { modified_at = @modifiedAt, indexed_at = @indexedAt, node_count = @nodeCount, - errors = @errors + errors = @errors, + generated = @generated "#, named_params! { "@path": file.path, @@ -686,6 +718,7 @@ impl Store { "@indexedAt": file.indexed_at, "@nodeCount": file.node_count, "@errors": errors, + "@generated": i64::from(file.generated), }, ) } @@ -1600,6 +1633,7 @@ fn row_to_file(row: &Row<'_>) -> rusqlite::Result { indexed_at: millis_column(row, "indexed_at")?, node_count: row.get("node_count")?, errors: parse_json_array(row.get("errors")?)?, + generated: row.get::<_, i64>("generated")? != 0, }) } @@ -1954,9 +1988,85 @@ mod tests { indexed_at: 2, node_count: 1, errors: vec!["warn".to_string()], + generated: false, } } + #[test] + fn upsert_file_round_trips_the_generated_flag() { + let store = store("generated-round-trip"); + + let mut rec = file("payroll.go"); + rec.generated = true; + store.upsert_file(&rec).unwrap(); + assert!(store.file_by_path("payroll.go").unwrap().unwrap().generated); + + // Re-upserting the SAME path with a false verdict must overwrite it. This + // half is what catches a missing `ON CONFLICT ... DO UPDATE SET generated`: + // without it the row keeps its stale `1` forever. + rec.generated = false; + store.upsert_file(&rec).unwrap(); + assert!(!store.file_by_path("payroll.go").unwrap().unwrap().generated); + + // And back again, so the update is not one-directional. + rec.generated = true; + store.upsert_file(&rec).unwrap(); + assert!(store.file_by_path("payroll.go").unwrap().unwrap().generated); + } + + #[test] + fn generated_paths_among_returns_only_flagged_paths() { + let store = store("generated-paths-among"); + + let mut flagged = file("api.pb.go"); + flagged.generated = true; + store.upsert_file(&flagged).unwrap(); + store.upsert_file(&file("handwritten.go")).unwrap(); + + let asked = vec![ + "api.pb.go".to_string(), + "handwritten.go".to_string(), + // A path with NO row at all is simply absent, never an error. + "never_indexed.go".to_string(), + ]; + let got = store.generated_paths_among(&asked).unwrap(); + assert_eq!(got, HashSet::from(["api.pb.go".to_string()])); + + // An EMPTY slice returns an empty set. MEASURED: `chunks()` on an empty + // slice yields ZERO chunks, so the loop body never runs and no `IN ()` + // syntax error is reachable — the early return saves an allocation and a + // sort, it is not what makes this correct. Asserted anyway: the contract + // is "no rows", and a future rewrite that builds SQL before chunking + // would break it. + assert!(store.generated_paths_among(&[]).unwrap().is_empty()); + } + + #[test] + fn generated_paths_among_crosses_the_parameter_chunk_boundary() { + let store = store("generated-paths-chunked"); + + // More paths than SQLITE_PARAM_CHUNK_SIZE, with flagged rows placed in the + // FIRST and LAST chunk, so a loop that only ever runs once still fails. + let total = SQLITE_PARAM_CHUNK_SIZE * 2 + 7; + let mut asked = Vec::with_capacity(total); + for i in 0..total { + let path = format!("gen/f{i:04}.go"); + let mut rec = file(&path); + rec.generated = i == 0 || i == total - 1; + store.upsert_file(&rec).unwrap(); + asked.push(path); + } + + let got = store.generated_paths_among(&asked).unwrap(); + assert_eq!( + got, + HashSet::from([ + "gen/f0000.go".to_string(), + format!("gen/f{:04}.go", total - 1), + ]) + ); + } + #[test] fn round_trip_insert_then_read_by_id_name_and_file() { let mut store = store("round-trip"); diff --git a/crates/codegraph-store/src/schema.rs b/crates/codegraph-store/src/schema.rs index d4ed1a59..c87f5c1a 100644 --- a/crates/codegraph-store/src/schema.rs +++ b/crates/codegraph-store/src/schema.rs @@ -65,7 +65,8 @@ CREATE TABLE IF NOT EXISTS files ( modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, - errors TEXT -- JSON array + errors TEXT, -- JSON array + generated INTEGER NOT NULL DEFAULT 0 ); -- Unresolved References: References that need resolution after full indexing @@ -149,6 +150,9 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_edges_identity -- File indexes CREATE INDEX IF NOT EXISTS idx_files_language ON files(language); CREATE INDEX IF NOT EXISTS idx_files_modified_at ON files(modified_at); +-- Partial: the generated set is a small minority of any repo, so the index is +-- proportional to the generated files rather than to the whole file table. +CREATE INDEX IF NOT EXISTS idx_files_generated ON files(path) WHERE generated = 1; -- Unresolved refs indexes CREATE INDEX IF NOT EXISTS idx_unresolved_from_node ON unresolved_refs(from_node_id); diff --git a/crates/codegraph-store/tests/index_state.rs b/crates/codegraph-store/tests/index_state.rs index 5d0fa0a6..c73152ba 100644 --- a/crates/codegraph-store/tests/index_state.rs +++ b/crates/codegraph-store/tests/index_state.rs @@ -119,7 +119,7 @@ fn assert_corrupt( fn index_state_constants_and_canonical_payload_are_exact() { /// The extraction version the immediately preceding release wrote. Read from /// `index_state.rs` at implementation time; see plan decision C1 step 0. - const PREVIOUS_EXTRACTION_VERSION: u64 = 7; + const PREVIOUS_EXTRACTION_VERSION: u64 = 8; assert_eq!(CURRENT_STORAGE_PROTOCOL, 2); assert_eq!(CURRENT_EXTRACTION_VERSION, PREVIOUS_EXTRACTION_VERSION + 1); diff --git a/crates/codegraph-store/tests/schema_parity.rs b/crates/codegraph-store/tests/schema_parity.rs index def17d0f..09425264 100644 --- a/crates/codegraph-store/tests/schema_parity.rs +++ b/crates/codegraph-store/tests/schema_parity.rs @@ -2,6 +2,7 @@ use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicU64, Ordering}; use codegraph_store::Store; +use codegraph_store::migrations::CURRENT_SCHEMA_VERSION; const GOLDEN_SCHEMA: &str = include_str!("../../../reference/golden/colby.schema.sql"); @@ -42,7 +43,7 @@ fn reopening_database_does_not_rerun_migrations() { assert_eq!(first_count, 2); assert_eq!(first_count, second_count); - assert_eq!(first_max, 7); + assert_eq!(first_max, CURRENT_SCHEMA_VERSION); assert_eq!(first_max, second_max); } @@ -86,8 +87,10 @@ fn old_v5_database_migrates_to_current_without_data_loss() { CREATE TABLE nodes (id TEXT PRIMARY KEY, kind TEXT NOT NULL, name TEXT NOT NULL, qualified_name TEXT NOT NULL, file_path TEXT NOT NULL, language TEXT NOT NULL, start_line INTEGER NOT NULL, end_line INTEGER NOT NULL, start_column INTEGER NOT NULL, end_column INTEGER NOT NULL, docstring TEXT, signature TEXT, visibility TEXT, is_exported INTEGER DEFAULT 0, is_async INTEGER DEFAULT 0, is_static INTEGER DEFAULT 0, is_abstract INTEGER DEFAULT 0, decorators TEXT, type_parameters TEXT, return_type TEXT, updated_at INTEGER NOT NULL); CREATE TABLE edges (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL, target TEXT NOT NULL, kind TEXT NOT NULL, metadata TEXT, line INTEGER, col INTEGER, provenance TEXT DEFAULT NULL); CREATE TABLE unresolved_refs (id INTEGER PRIMARY KEY AUTOINCREMENT, from_node_id TEXT NOT NULL, reference_name TEXT NOT NULL, reference_kind TEXT NOT NULL, line INTEGER NOT NULL, col INTEGER NOT NULL, candidates TEXT, file_path TEXT NOT NULL DEFAULT '', language TEXT NOT NULL DEFAULT 'unknown', FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE); + CREATE TABLE files (path TEXT PRIMARY KEY, content_hash TEXT NOT NULL, language TEXT NOT NULL, size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, errors TEXT); INSERT INTO schema_versions (version, applied_at, description) VALUES (1, 0, 'Initial schema'), (5, 0, 'Initial schema includes all migrations'); INSERT INTO nodes (id, kind, name, qualified_name, file_path, language, start_line, end_line, start_column, end_column, updated_at) VALUES ('file:a.gd', 'file', 'a.gd', 'a.gd', 'a.gd', 'gdscript', 1, 1, 0, 0, 0); + INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors) VALUES ('a.gd', 'deadbeef', 'gdscript', 12, 0, 0, 1, NULL); INSERT INTO unresolved_refs (from_node_id, reference_name, reference_kind, line, col, file_path, language) VALUES ('file:a.gd', 'player.gd', 'references', 3, 0, 'a.gd', 'godot_scene');", ) .unwrap(); @@ -98,7 +101,7 @@ fn old_v5_database_migrates_to_current_without_data_loss() { // Then it migrates to the current version, gains the reference_subkind column // (NULL for the pre-existing row), and the row's data is preserved. - assert_eq!(store.schema_version().unwrap(), 7); + assert_eq!(store.schema_version().unwrap(), CURRENT_SCHEMA_VERSION); let (name, subkind): (String, Option) = store .connection() .query_row( diff --git a/crates/codegraph-watch/src/migrate.rs b/crates/codegraph-watch/src/migrate.rs index de0f2cf6..4ddce4cf 100644 --- a/crates/codegraph-watch/src/migrate.rs +++ b/crates/codegraph-watch/src/migrate.rs @@ -34,6 +34,7 @@ use std::time::Instant; use anyhow::{Context, Result}; use codegraph_core::IndexPaths; +use codegraph_core::generated_header::detect_generated_file; use codegraph_core::node_id::hash_content; use codegraph_core::types::{Edge, FileRecord, Node, UnresolvedRef}; use codegraph_extract::{detect_language_with, extract_source_with}; @@ -126,6 +127,7 @@ pub(crate) fn migrate_project( .filter(|node| node.file_path == *relative) .count() as i64, errors: result.errors.clone(), + generated: detect_generated_file(relative, &source), }; rebuild.store().upsert_file(&file)?; diff --git a/crates/codegraph-watch/src/sync.rs b/crates/codegraph-watch/src/sync.rs index ed27445c..76242000 100644 --- a/crates/codegraph-watch/src/sync.rs +++ b/crates/codegraph-watch/src/sync.rs @@ -7,6 +7,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; use anyhow::{Context, Result, bail}; use codegraph_core::IndexPaths; use codegraph_core::config::Config; +use codegraph_core::generated_header::detect_generated_file; use codegraph_core::node_id::hash_content; use codegraph_core::types::FileRecord; use codegraph_extract::{ @@ -756,6 +757,7 @@ fn reextract_into_store( .filter(|node| node.file_path == relative) .count() as i64, errors: result.errors, + generated: detect_generated_file(relative, &source), }; // A name's resolution outcomes (confidence, chosen target) depend on the set @@ -1685,6 +1687,94 @@ pub(crate) mod tests { built } + #[test] + fn incremental_sync_writes_the_generated_flag_both_ways() { + // Given: an indexed hand-written Go file whose row reads 0. + let dir = TestDir::new("watch-generated-incremental"); + let target = dir.path().join("payroll.go"); + fs::write( + &target, + "package payroll\n\nfunc ComputePay() int64 { return 1 }\n", + ) + .unwrap(); + let db = default_db_path(dir.path()).unwrap(); + sync_changed_paths(dir.path(), &db, ["payroll.go"]).unwrap(); + assert!(!read_generated(dir.path(), "payroll.go")); + + // When: an edit ADDS a generation banner and the incremental sync runs. + fs::write( + &target, + "// Code generated by fkit-crud. DO NOT EDIT.\n\npackage payroll\n\nfunc ComputePay() int64 { return 1 }\n", + ) + .unwrap(); + sync_changed_paths(dir.path(), &db, ["payroll.go"]).unwrap(); + + // Then: the stored verdict flips 0 -> 1 through the real sync path. + assert!( + read_generated(dir.path(), "payroll.go"), + "adding a banner must flip the stored flag to 1" + ); + + // And removing the banner flips it BACK, which re-tests the + // `DO UPDATE SET` half through sync rather than through the store test. + fs::write( + &target, + "package payroll\n\nfunc ComputePay() int64 { return 2 }\n", + ) + .unwrap(); + sync_changed_paths(dir.path(), &db, ["payroll.go"]).unwrap(); + assert!( + !read_generated(dir.path(), "payroll.go"), + "removing the banner must flip the stored flag back to 0" + ); + } + + #[test] + fn outdated_rebuild_writes_the_generated_flag() { + // Given: a banner-marked file and a hand-written sibling, indexed and then + // marked Outdated so the next sync escalates into `migrate_project`. + let dir = TestDir::new("watch-generated-migrate"); + fs::write( + dir.path().join("payroll.go"), + "// Code generated by fkit-crud. DO NOT EDIT.\n\npackage payroll\n\nfunc ComputePay() int64 { return 1 }\n", + ) + .unwrap(); + fs::write( + dir.path().join("payroll_usecase.go"), + "package payroll\n\nfunc ComputeNet() int64 { return 2 }\n", + ) + .unwrap(); + sync_project_once(dir.path()).unwrap(); + stage_outdated(&dir); + + // When: the cold full sync runs, which is the path an existing index + // actually takes when it upgrades (migrate.rs, NOT main.rs). + sync_project_once(dir.path()).unwrap(); + + // Then: the rebuild wrote the real verdict, not a hardcoded false. This is + // the assertion that fails if write path 3 is left filling `false`. + assert!( + read_generated(dir.path(), "payroll.go"), + "the Outdated rebuild must write generated = 1 for a banner-marked file" + ); + assert!( + !read_generated(dir.path(), "payroll_usecase.go"), + "the Outdated rebuild must leave a hand-written file at 0" + ); + } + + fn read_generated(project_root: &Path, relative: &str) -> bool { + let paths = index_paths(project_root).unwrap(); + let store = + Store::open_for_read(&paths, Instant::now() + Duration::from_secs(10), || false) + .unwrap(); + store + .file_by_path(relative) + .unwrap() + .unwrap_or_else(|| panic!("{relative} must have a file row")) + .generated + } + #[test] fn watcher_sync_on_outdated_namespace_migrates_every_file_without_skips() { // Given: an indexed project whose namespace is then marked as built by an diff --git a/docs/equivalence.md b/docs/equivalence.md index 172f0503..3306df51 100644 --- a/docs/equivalence.md +++ b/docs/equivalence.md @@ -568,6 +568,127 @@ cargo run -p codegraph-bench --bin bench -- \ `generated_golden_matches_committed_rust_fixture` and `rust_db_is_self_equivalent_to_rust_golden` enforce byte-stability. +### Go fixture + +`reference/golden/go/` byte-pins `files.generated` — the content-header +generated-file detection ported from upstream #1500 (`16e1749`) plus the +Wrangler double-`by` fix (`57e0854`). It is the repo's only Go corpus, and the +only corpus where `files.generated` is anything other than `0`. + +Go is the language that forces content detection to exist: its convention for a +generated file is a **comment banner**, not a filename suffix, so a machine-written +`payroll.go` sitting beside hand-written use-cases is invisible to the path-only +`is_generated_file`. Renaming is not an option — `payroll.go` is a legal, ordinary +Go filename. + +Six files pin BOTH values of the flag, three each way: + +| fixture | `generated` | what it guards | +| -------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------- | +| `payroll.go` | **1** | pattern 1, Go's codified `Code generated … DO NOT EDIT.` — the #1500 defect itself | +| `worker_types.go` | **1** | pattern 6 / CG-25, Wrangler's TWO `by` clauses (`Generated by Wrangler by running …`) | +| `api.pb.go` | **1** | the PATH signal still writes 1 with no banner present | +| `payroll_usecase.go` | **0** | the must-not-demote side: hand-written code beside a generated sibling | +| `nightly.go` | **0** | pattern 6 PRECISION — one `by` clause (`generated by running the ETL job`) is ordinary prose | +| `generator.go` | **0** | the comment-line fence: the banner is a `const` string in the function BODY, so a generator's own source is not flagged | + +`payroll.go` and `payroll_usecase.go` both define `ComputePay`, which is what makes +the ranking effect observable: without the content signal the generated definition +wins on name overlap alone. + +Regenerate reproducibly (identical recipe to the Rust fixture, substituting `go`): + +```bash +mkdir -p reference/golden/go +rm -rf /tmp/cg-fixture-go +cp -r crates/codegraph-bench/fixtures/go /tmp/cg-fixture-go +cargo build --release -p codegraph-rs +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 \ + ./target/release/codegraph init /tmp/cg-fixture-go +cp /tmp/cg-fixture-go/.codegraph/codegraph.db reference/golden/go/colby.db +cargo run -p codegraph-bench --bin bench -- \ + --gen-golden reference/golden/go/colby.db reference/golden/go +``` + +`generated_golden_matches_committed_go_fixture` and +`go_db_is_self_equivalent_to_go_golden` enforce byte-stability. + +### Mini schema rebuild (schema-migration recipe) + +`reference/golden/mini/` is the one corpus with **no re-indexable provenance** — it +is upstream-derived, and its `files.modified_at` is a JS `Date.now()` +(`typeof(modified_at) = real`, versus `integer` in every corpus we produce). So the +recipe above cannot regenerate it: re-indexing the fixture would replace upstream's +data with ours. + +An in-place `Store::open` migration is also **not** sufficient when a schema +migration adds an index. `CREATE INDEX` APPENDS a `sqlite_master` row and never +reorders an existing one, and the golden `schema.sql` is a `sqlite_master` dump +compared as a strict string, so a migrated corpus accumulates its indexes in +migration order while a freshly-created one carries them in `BASE_SCHEMA` order. +That is why `mini` and `godot` used to carry `idx_edges_identity` LAST while the +other corpora carried it alphabetically. + +For a schema migration, rebuild `mini` on the fresh schema and transplant its rows: + +```bash +# 1. A fresh index over mini's own fixture → a database created from the CURRENT +# BASE_SCHEMA, so every index lands in declaration order. +rm -rf /tmp/mini-rebuild && mkdir -p /tmp/mini-rebuild +cp -a crates/codegraph-bench/fixtures/mini/. /tmp/mini-rebuild/ +CODEGRAPH_NO_DAEMON=1 CODEGRAPH_NO_WATCH=1 \ + ./target/release/codegraph init /tmp/mini-rebuild +DB=/tmp/mini-rebuild/.codegraph/codegraph.db + +# 2. Replace its freshly-extracted rows with mini's COMMITTED rows, preserving +# the upstream-derived values instead of re-extracting them. Run from the repo +# root — the ATTACH path is relative. +sqlite3 "$DB" " + ATTACH DATABASE 'reference/golden/mini/colby.db' AS src; + BEGIN; + DELETE FROM unresolved_refs; DELETE FROM edges; DELETE FROM files; + DELETE FROM nodes; DELETE FROM project_metadata; + INSERT INTO nodes SELECT * FROM src.nodes; + INSERT INTO edges SELECT * FROM src.edges; + INSERT INTO unresolved_refs SELECT * FROM src.unresolved_refs; + INSERT INTO project_metadata SELECT * FROM src.project_metadata; + INSERT INTO files (path, content_hash, language, size, modified_at, indexed_at, node_count, errors) + SELECT path, content_hash, language, size, modified_at, indexed_at, node_count, errors FROM src.files; + COMMIT; + DETACH src;" + +# 3. Commit as the fixture's colby.db, then re-derive the JSON + schema goldens. +cp "$DB" reference/golden/mini/colby.db +cargo run -p codegraph-bench --bin bench -- \ + --gen-golden reference/golden/mini/colby.db reference/golden/mini +``` + +Two constraints in that transplant are load-bearing: + +- **The `files` insert MUST use an explicit column list.** `SELECT *` fails with + `table files has N columns but 8 values were supplied` once a column is added, + and the omitted column correctly takes its `DEFAULT`, which is exactly the + migrated-but-not-re-extracted semantics the goldens should pin. +- **Do NOT transplant `schema_versions`.** `codegraph_store::test_support:: +finalize_current_test_fixture` calls `Store::open` on a COPY of this database + from seven call sites. Copying `mini`'s rows would leave `MAX(version)` behind + the current schema on a database that already HAS the new column, so + `run_pending_migrations` would fire the `ALTER TABLE` against it and every one of + those tests would die on `duplicate column name: …`. Keeping the fresh rows + leaves nothing pending, so `Store::open` is a no-op on the copy. + +Verify the rebuild preserved provenance and normalised the order: + +```bash +sqlite3 reference/golden/mini/colby.db 'SELECT DISTINCT typeof(modified_at) FROM files;' # real +sqlite3 reference/golden/mini/colby.db 'SELECT COUNT(*) FROM nodes;' # 13 +sqlite3 reference/golden/mini/colby.db 'SELECT COUNT(*) FROM edges;' # 21 +diff reference/golden/mini/schema.sql reference/golden/cpp/schema.sql # byte-equal +``` + +That last `diff` is the real proof: the rebuilt `mini` schema is now the same text +as a freshly-created corpus's, so every corpus `schema.sql` shares one hash. + ### Metal fixture A fifth golden fixture, `reference/golden/metal/`, guards Metal Shading Language diff --git a/reference/golden/arkts/colby.db b/reference/golden/arkts/colby.db index 84e0368d..c8eebe18 100644 Binary files a/reference/golden/arkts/colby.db and b/reference/golden/arkts/colby.db differ diff --git a/reference/golden/arkts/files.json b/reference/golden/arkts/files.json index ebca10c9..8e9d63a2 100644 --- a/reference/golden/arkts/files.json +++ b/reference/golden/arkts/files.json @@ -2,6 +2,7 @@ { "content_hash": "1299fbd03b9bf9cbbd560ce133ea00f5646f35e4574cc6e92123969de1608b80", "errors": null, + "generated": 0, "language": "arkts", "node_count": 7, "path": "component.ets", diff --git a/reference/golden/arkts/schema.sql b/reference/golden/arkts/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/arkts/schema.sql +++ b/reference/golden/arkts/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/cfml/colby.db b/reference/golden/cfml/colby.db index c7072ae4..cc4eedfe 100644 Binary files a/reference/golden/cfml/colby.db and b/reference/golden/cfml/colby.db differ diff --git a/reference/golden/cfml/files.json b/reference/golden/cfml/files.json index b27d561c..4089c0d3 100644 --- a/reference/golden/cfml/files.json +++ b/reference/golden/cfml/files.json @@ -2,6 +2,7 @@ { "content_hash": "1def57c4a549fb3f0100b4c1a3da65eb5d88d7048a030d66004ce46d157b1aa2", "errors": null, + "generated": 0, "language": "cfml", "node_count": 3, "path": "Base.cfc", @@ -10,6 +11,7 @@ { "content_hash": "9fe3c477ccee5efc741c301c391bf45a9b153bf9e2c02593f310d452280699c2", "errors": null, + "generated": 0, "language": "cfml", "node_count": 4, "path": "Gadget.cfs", @@ -18,6 +20,7 @@ { "content_hash": "c618667f944b633d15c80bf1e274aac80504af2fb2a82266f54ec5c819f76d6e", "errors": null, + "generated": 0, "language": "cfml", "node_count": 3, "path": "Widget.cfm", diff --git a/reference/golden/cfml/schema.sql b/reference/golden/cfml/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/cfml/schema.sql +++ b/reference/golden/cfml/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/colby.schema.sql b/reference/golden/colby.schema.sql index 04d625f7..80d93daa 100644 --- a/reference/golden/colby.schema.sql +++ b/reference/golden/colby.schema.sql @@ -47,7 +47,8 @@ CREATE TABLE files ( modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, - errors TEXT -- JSON array + errors TEXT, -- JSON array + generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/cpp/colby.db b/reference/golden/cpp/colby.db index 6e558a3a..b59a68db 100644 Binary files a/reference/golden/cpp/colby.db and b/reference/golden/cpp/colby.db differ diff --git a/reference/golden/cpp/files.json b/reference/golden/cpp/files.json index 0b31b98c..3bff7c69 100644 --- a/reference/golden/cpp/files.json +++ b/reference/golden/cpp/files.json @@ -2,6 +2,7 @@ { "content_hash": "ae235688285955ff53f65aa9468ee11fc2691fac2cbd99b76f36b6d72f363a98", "errors": null, + "generated": 0, "language": "c", "node_count": 6, "path": "attr_macro.c", @@ -10,6 +11,7 @@ { "content_hash": "918ff675ba5d4bc2916b5f0b01a6efe803acec492ab71f0bf83c593be612a202", "errors": null, + "generated": 0, "language": "cpp", "node_count": 9, "path": "base.hpp", @@ -18,6 +20,7 @@ { "content_hash": "6b55a06389ed10d1d23bcab95a9ae02421e1cf0aa566526df2f367e29270e7c2", "errors": null, + "generated": 0, "language": "cpp", "node_count": 7, "path": "com_interface.hpp", @@ -26,6 +29,7 @@ { "content_hash": "7866bdbba877acfa0b4b8e7e4be58875893da925ac91aa333a4c3658bea64e69", "errors": null, + "generated": 0, "language": "cpp", "node_count": 12, "path": "derived.cpp", @@ -34,6 +38,7 @@ { "content_hash": "e3331a39e14456236ae24d3d0cc31562b65008bf1027a065d8f403066d74a46e", "errors": null, + "generated": 0, "language": "cpp", "node_count": 5, "path": "instantiate_agg.cpp", @@ -42,6 +47,7 @@ { "content_hash": "5d9bf2ad4d29787d69c168a79c0efb471614f5996f9b065b206da7170bc0fe70", "errors": null, + "generated": 0, "language": "cpp", "node_count": 6, "path": "instantiate_rank.cpp", @@ -50,6 +56,7 @@ { "content_hash": "bfd6da256b748444e2bfdff365e7d56daa640afa638e50b294db94cca1f2a7f8", "errors": null, + "generated": 0, "language": "cpp", "node_count": 4, "path": "namespaced.cpp", @@ -58,6 +65,7 @@ { "content_hash": "e4419194da0741856b7b23dbc977893cdfda9a926201018b685dce64efbd1f30", "errors": null, + "generated": 0, "language": "cpp", "node_count": 4, "path": "namespaced_member.cpp", @@ -66,6 +74,7 @@ { "content_hash": "3d4b5ad9e00d6934eea58bd6707b171b7a335458df91499966798385a5d09ad7", "errors": null, + "generated": 0, "language": "cpp", "node_count": 2, "path": "namespaced_member.hpp", @@ -74,6 +83,7 @@ { "content_hash": "e934b42dfe376e8b29355a6ed84d713d44ba9b6f898df4d774f6bda378562bb3", "errors": null, + "generated": 0, "language": "cpp", "node_count": 4, "path": "neg_interface.hpp", @@ -82,6 +92,7 @@ { "content_hash": "61ac8b93b7094d0633203791513f3394c7f76e2993a50d75b9f8e32454dcccf6", "errors": null, + "generated": 0, "language": "cpp", "node_count": 9, "path": "operators.cpp", @@ -90,6 +101,7 @@ { "content_hash": "0527736aa5807318919d35bb62e2c3f8dc4be0e333cf2e27553b89dc59006b74", "errors": null, + "generated": 0, "language": "cpp", "node_count": 4, "path": "template_method.cpp", @@ -98,6 +110,7 @@ { "content_hash": "e72bc5982add705d170ebd03d4a3db5286237e5b8ab662fc9ed35cd51da438c9", "errors": null, + "generated": 0, "language": "cpp", "node_count": 3, "path": "templated_call.cpp", @@ -106,6 +119,7 @@ { "content_hash": "5afecb82e36830d924845a28b9069f2fb7cc3d9b15d74f6bf6623fd737b3d265", "errors": null, + "generated": 0, "language": "c", "node_count": 2, "path": "ue_actor.h", @@ -114,6 +128,7 @@ { "content_hash": "fd0d7579d620457505815a1d6829820f5512859858153568086bdebddcd0ead2", "errors": null, + "generated": 0, "language": "c", "node_count": 7, "path": "union_agg.c", @@ -122,6 +137,7 @@ { "content_hash": "d0f696b07337c1d1fcda49b0222d9b43a5c45a3932ff58cee2cd87b8d68caf53", "errors": null, + "generated": 0, "language": "cpp", "node_count": 7, "path": "union_agg.cpp", @@ -130,6 +146,7 @@ { "content_hash": "96f43a0f8244169fcc8281ef0f62de430a43436f39853e254ec27a840ccbe7c7", "errors": null, + "generated": 0, "language": "objc", "node_count": 3, "path": "union_agg.mm", diff --git a/reference/golden/cpp/schema.sql b/reference/golden/cpp/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/cpp/schema.sql +++ b/reference/golden/cpp/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/cuda/colby.db b/reference/golden/cuda/colby.db index 0981683f..2885fd31 100644 Binary files a/reference/golden/cuda/colby.db and b/reference/golden/cuda/colby.db differ diff --git a/reference/golden/cuda/files.json b/reference/golden/cuda/files.json index e8c574ba..6eab1f22 100644 --- a/reference/golden/cuda/files.json +++ b/reference/golden/cuda/files.json @@ -2,6 +2,7 @@ { "content_hash": "3f2656febed2ea1c1ae2498e3361ad5d667edc05d4abf561a0b189eddfe4d113", "errors": null, + "generated": 0, "language": "cpp", "node_count": 5, "path": "kernel.cu", diff --git a/reference/golden/cuda/schema.sql b/reference/golden/cuda/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/cuda/schema.sql +++ b/reference/golden/cuda/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/erlang/colby.db b/reference/golden/erlang/colby.db index cb061c34..557b3553 100644 Binary files a/reference/golden/erlang/colby.db and b/reference/golden/erlang/colby.db differ diff --git a/reference/golden/erlang/files.json b/reference/golden/erlang/files.json index 518690bd..2a7be30a 100644 --- a/reference/golden/erlang/files.json +++ b/reference/golden/erlang/files.json @@ -2,6 +2,7 @@ { "content_hash": "56a7be5a3cae1e5ae0a456229c15af753d04217c4415d02eeee7ae7d1aa91c0b", "errors": null, + "generated": 0, "language": "erlang", "node_count": 9, "path": "m.erl", diff --git a/reference/golden/erlang/schema.sql b/reference/golden/erlang/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/erlang/schema.sql +++ b/reference/golden/erlang/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/go/colby.db b/reference/golden/go/colby.db new file mode 100644 index 00000000..594396bd Binary files /dev/null and b/reference/golden/go/colby.db differ diff --git a/reference/golden/go/edges.json b/reference/golden/go/edges.json new file mode 100644 index 00000000..622ffe61 --- /dev/null +++ b/reference/golden/go/edges.json @@ -0,0 +1,128 @@ +[ + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:api.pb.go", + "target": "method:6212aa78f83979803561e5a35e2204ca" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:api.pb.go", + "target": "method:96ccb238e207922617dad91a1a3bd096" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:api.pb.go", + "target": "struct:69ce2dc78af1c72c5e705b2eff7d50b3" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:generator.go", + "target": "method:ef967dad7607276a0b2b0ab216d3512c" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:generator.go", + "target": "struct:f491ce4d77b17ba0283270af44baa3cb" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:nightly.go", + "target": "function:97cc2d07cb9dbe40a71cf1fcc47017c0" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:payroll.go", + "target": "function:0244d391763c9267d93aa0f3daec14c3" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:payroll.go", + "target": "struct:beab0d96e183bbfa38be5a5dae58f885" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:payroll_usecase.go", + "target": "function:8182c7b348a8f99ca98471df85b680d0" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:worker_types.go", + "target": "function:9ca48aa8a0359c83c2de731082d72870" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "file:worker_types.go", + "target": "struct:6e0211f4791dd90203584f4897508e01" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:69ce2dc78af1c72c5e705b2eff7d50b3", + "target": "method:6212aa78f83979803561e5a35e2204ca" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:69ce2dc78af1c72c5e705b2eff7d50b3", + "target": "method:96ccb238e207922617dad91a1a3bd096" + }, + { + "col": null, + "kind": "contains", + "line": null, + "metadata": null, + "provenance": null, + "source": "struct:f491ce4d77b17ba0283270af44baa3cb", + "target": "method:ef967dad7607276a0b2b0ab216d3512c" + } +] diff --git a/reference/golden/go/files.json b/reference/golden/go/files.json new file mode 100644 index 00000000..a0f47201 --- /dev/null +++ b/reference/golden/go/files.json @@ -0,0 +1,56 @@ +[ + { + "content_hash": "6266aa1b37584903c4bdb31325c4ad9d6baae30b2ab5282d38d2428afbe73374", + "errors": null, + "generated": 1, + "language": "go", + "node_count": 4, + "path": "api.pb.go", + "size": 203 + }, + { + "content_hash": "176b35b02d0f4e9aff372868b7b318d5e83a3a98702146b226647b203bba7a0b", + "errors": null, + "generated": 0, + "language": "go", + "node_count": 3, + "path": "generator.go", + "size": 459 + }, + { + "content_hash": "545c46190c505988dfa6b0a0029ab7eb9e9583d4b66c262e429c92354e5412d5", + "errors": null, + "generated": 0, + "language": "go", + "node_count": 2, + "path": "nightly.go", + "size": 282 + }, + { + "content_hash": "6df8e62ce5e6b7eb09837c1c0cb4e1236d78f451b5fba7a980577b948c5ba5fc", + "errors": null, + "generated": 1, + "language": "go", + "node_count": 3, + "path": "payroll.go", + "size": 172 + }, + { + "content_hash": "66291f001463b1dc06b4c145dbe74d30e8bcb1d82ca83f6d7453022ffc473d27", + "errors": null, + "generated": 0, + "language": "go", + "node_count": 2, + "path": "payroll_usecase.go", + "size": 158 + }, + { + "content_hash": "afd9d67706ef83f20e2e5c4832b28f3b18cfe3c972e047b1ec8a55d6361905ab", + "errors": null, + "generated": 1, + "language": "go", + "node_count": 3, + "path": "worker_types.go", + "size": 247 + } +] diff --git a/reference/golden/go/nodes.json b/reference/golden/go/nodes.json new file mode 100644 index 00000000..661a2ccf --- /dev/null +++ b/reference/golden/go/nodes.json @@ -0,0 +1,376 @@ +[ + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 15, + "file_path": "api.pb.go", + "id": "file:api.pb.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "api.pb.go", + "qualified_name": "api.pb.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 15, + "file_path": "generator.go", + "id": "file:generator.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "generator.go", + "qualified_name": "generator.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 10, + "file_path": "nightly.go", + "id": "file:nightly.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "nightly.go", + "qualified_name": "nightly.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 13, + "file_path": "payroll.go", + "id": "file:payroll.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "payroll.go", + "qualified_name": "payroll.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 7, + "file_path": "payroll_usecase.go", + "id": "file:payroll_usecase.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "payroll_usecase.go", + "qualified_name": "payroll_usecase.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 0, + "end_line": 13, + "file_path": "worker_types.go", + "id": "file:worker_types.go", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "file", + "language": "go", + "name": "worker_types.go", + "qualified_name": "worker_types.go", + "return_type": null, + "signature": null, + "start_column": 0, + "start_line": 1, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 12, + "file_path": "payroll.go", + "id": "function:0244d391763c9267d93aa0f3daec14c3", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "go", + "name": "ComputePay", + "qualified_name": "ComputePay", + "return_type": "int64", + "signature": "(p *Payroll) int64", + "start_column": 0, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": "ComputePay applies the real business rules for a payroll run.", + "end_column": 1, + "end_line": 6, + "file_path": "payroll_usecase.go", + "id": "function:8182c7b348a8f99ca98471df85b680d0", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "go", + "name": "ComputePay", + "qualified_name": "ComputePay", + "return_type": "int64", + "signature": "(p *Payroll, bonus int64) int64", + "start_column": 0, + "start_line": 4, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": "RunNightly kicks off the ETL job. Note the wording below: the report is\ngenerated by running the ETL job, which is ONE \"by\" clause and therefore\nordinary prose rather than a generation banner.", + "end_column": 1, + "end_line": 9, + "file_path": "nightly.go", + "id": "function:97cc2d07cb9dbe40a71cf1fcc47017c0", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "go", + "name": "RunNightly", + "qualified_name": "RunNightly", + "return_type": "error", + "signature": "(jobID string) error", + "start_column": 0, + "start_line": 6, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 12, + "file_path": "worker_types.go", + "id": "function:9ca48aa8a0359c83c2de731082d72870", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "function", + "language": "go", + "name": "NewEnv", + "qualified_name": "NewEnv", + "return_type": "Env", + "signature": "(account string, bucket string) *Env", + "start_column": 0, + "start_line": 10, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 14, + "file_path": "api.pb.go", + "id": "method:6212aa78f83979803561e5a35e2204ca", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "go", + "name": "GetAmount", + "qualified_name": "PayrollRequest::GetAmount", + "return_type": "int64", + "signature": "() int64", + "start_column": 0, + "start_line": 12, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 10, + "file_path": "api.pb.go", + "id": "method:96ccb238e207922617dad91a1a3bd096", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "go", + "name": "Reset", + "qualified_name": "PayrollRequest::Reset", + "return_type": null, + "signature": "()", + "start_column": 0, + "start_line": 8, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": "Emit renders the file body, prefixing it with the standard banner.\nThe banner literal lives in the BODY as a string constant, so this\ngenerator source must NOT be classified as generated itself.", + "end_column": 1, + "end_line": 14, + "file_path": "generator.go", + "id": "method:ef967dad7607276a0b2b0ab216d3512c", + "is_abstract": 0, + "is_async": 0, + "is_exported": 0, + "is_static": 0, + "kind": "method", + "language": "go", + "name": "Emit", + "qualified_name": "Emitter::Emit", + "return_type": "string", + "signature": "() string", + "start_column": 0, + "start_line": 11, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 6, + "file_path": "api.pb.go", + "id": "struct:69ce2dc78af1c72c5e705b2eff7d50b3", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "struct", + "language": "go", + "name": "PayrollRequest", + "qualified_name": "PayrollRequest", + "return_type": null, + "signature": null, + "start_column": 5, + "start_line": 3, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 8, + "file_path": "worker_types.go", + "id": "struct:6e0211f4791dd90203584f4897508e01", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "struct", + "language": "go", + "name": "Env", + "qualified_name": "Env", + "return_type": null, + "signature": null, + "start_column": 5, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 8, + "file_path": "payroll.go", + "id": "struct:beab0d96e183bbfa38be5a5dae58f885", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "struct", + "language": "go", + "name": "Payroll", + "qualified_name": "Payroll", + "return_type": null, + "signature": null, + "start_column": 5, + "start_line": 5, + "type_parameters": null, + "visibility": null + }, + { + "decorators": null, + "docstring": null, + "end_column": 1, + "end_line": 6, + "file_path": "generator.go", + "id": "struct:f491ce4d77b17ba0283270af44baa3cb", + "is_abstract": 0, + "is_async": 0, + "is_exported": 1, + "is_static": 0, + "kind": "struct", + "language": "go", + "name": "Emitter", + "qualified_name": "Emitter", + "return_type": null, + "signature": null, + "start_column": 5, + "start_line": 4, + "type_parameters": null, + "visibility": null + } +] diff --git a/reference/golden/go/refs.json b/reference/golden/go/refs.json new file mode 100644 index 00000000..fe51488c --- /dev/null +++ b/reference/golden/go/refs.json @@ -0,0 +1 @@ +[] diff --git a/reference/golden/go/schema.sql b/reference/golden/go/schema.sql new file mode 100644 index 00000000..e528b87c --- /dev/null +++ b/reference/golden/go/schema.sql @@ -0,0 +1,119 @@ +CREATE TABLE schema_versions ( +version INTEGER PRIMARY KEY, +applied_at INTEGER NOT NULL, +description TEXT +); +CREATE TABLE nodes ( +id TEXT PRIMARY KEY, +kind TEXT NOT NULL, +name TEXT NOT NULL, +qualified_name TEXT NOT NULL, +file_path TEXT NOT NULL, +language TEXT NOT NULL, +start_line INTEGER NOT NULL, +end_line INTEGER NOT NULL, +start_column INTEGER NOT NULL, +end_column INTEGER NOT NULL, +docstring TEXT, +signature TEXT, +visibility TEXT, +is_exported INTEGER DEFAULT 0, +is_async INTEGER DEFAULT 0, +is_static INTEGER DEFAULT 0, +is_abstract INTEGER DEFAULT 0, +decorators TEXT, -- JSON array +type_parameters TEXT, -- JSON array +return_type TEXT, -- normalized return/result type name (e.g. C++ method return, for receiver-type inference) +updated_at INTEGER NOT NULL +); +CREATE TABLE edges ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +source TEXT NOT NULL, +target TEXT NOT NULL, +kind TEXT NOT NULL, +metadata TEXT, -- JSON object +line INTEGER, +col INTEGER, +provenance TEXT DEFAULT NULL, +FOREIGN KEY (source) REFERENCES nodes(id) ON DELETE CASCADE, +FOREIGN KEY (target) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE TABLE sqlite_sequence(name,seq); +CREATE TABLE files ( +path TEXT PRIMARY KEY, +content_hash TEXT NOT NULL, +language TEXT NOT NULL, +size INTEGER NOT NULL, +modified_at INTEGER NOT NULL, +indexed_at INTEGER NOT NULL, +node_count INTEGER DEFAULT 0, +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 +); +CREATE TABLE unresolved_refs ( +id INTEGER PRIMARY KEY AUTOINCREMENT, +from_node_id TEXT NOT NULL, +reference_name TEXT NOT NULL, +reference_kind TEXT NOT NULL, +line INTEGER NOT NULL, +col INTEGER NOT NULL, +candidates TEXT, -- JSON array +file_path TEXT NOT NULL DEFAULT '', +language TEXT NOT NULL DEFAULT 'unknown', +reference_subkind TEXT, +FOREIGN KEY (from_node_id) REFERENCES nodes(id) ON DELETE CASCADE +); +CREATE INDEX idx_nodes_kind ON nodes(kind); +CREATE INDEX idx_nodes_name ON nodes(name); +CREATE INDEX idx_nodes_qualified_name ON nodes(qualified_name); +CREATE INDEX idx_nodes_file_path ON nodes(file_path); +CREATE INDEX idx_nodes_language ON nodes(language); +CREATE INDEX idx_nodes_file_line ON nodes(file_path, start_line); +CREATE INDEX idx_nodes_lower_name ON nodes(lower(name)); +CREATE VIRTUAL TABLE nodes_fts USING fts5( +id, +name, +qualified_name, +docstring, +signature, +content='nodes', +content_rowid='rowid' +) +/* nodes_fts(id,name,qualified_name,docstring,signature) */; +CREATE TABLE 'nodes_fts_data'(id INTEGER PRIMARY KEY, block BLOB); +CREATE TABLE 'nodes_fts_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID; +CREATE TABLE 'nodes_fts_docsize'(id INTEGER PRIMARY KEY, sz BLOB); +CREATE TABLE 'nodes_fts_config'(k PRIMARY KEY, v) WITHOUT ROWID; +CREATE TRIGGER nodes_ai AFTER INSERT ON nodes BEGIN +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE TRIGGER nodes_ad AFTER DELETE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +END; +CREATE TRIGGER nodes_au AFTER UPDATE ON nodes BEGIN +INSERT INTO nodes_fts(nodes_fts, rowid, id, name, qualified_name, docstring, signature) +VALUES ('delete', OLD.rowid, OLD.id, OLD.name, OLD.qualified_name, OLD.docstring, OLD.signature); +INSERT INTO nodes_fts(rowid, id, name, qualified_name, docstring, signature) +VALUES (NEW.rowid, NEW.id, NEW.name, NEW.qualified_name, NEW.docstring, NEW.signature); +END; +CREATE INDEX idx_edges_kind ON edges(kind); +CREATE INDEX idx_edges_source_kind ON edges(source, kind); +CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); +CREATE INDEX idx_files_language ON files(language); +CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; +CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); +CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); +CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); +CREATE INDEX idx_unresolved_from_name ON unresolved_refs(from_node_id, reference_name); +CREATE INDEX idx_edges_provenance ON edges(provenance); +CREATE TABLE project_metadata ( +key TEXT PRIMARY KEY, +value TEXT NOT NULL, +updated_at INTEGER NOT NULL +); +CREATE TABLE sqlite_stat1(tbl,idx,stat); diff --git a/reference/golden/godot/colby.db b/reference/golden/godot/colby.db index 78a0dc85..eaceafd5 100644 Binary files a/reference/golden/godot/colby.db and b/reference/golden/godot/colby.db differ diff --git a/reference/golden/godot/files.json b/reference/golden/godot/files.json index 0ae0221d..f0dd8e7d 100644 --- a/reference/golden/godot/files.json +++ b/reference/golden/godot/files.json @@ -2,6 +2,7 @@ { "content_hash": "33a6ab1ac82701bd870b22dd52e8677fc23e4099d38947face8b931780fd20bc", "errors": null, + "generated": 0, "language": "godot_scene", "node_count": 0, "path": "combo_ui.tscn", @@ -10,6 +11,7 @@ { "content_hash": "6f5b810b12eeba2d908d628a74a55dd5da8997f2775681cc26c584650d7d5581", "errors": null, + "generated": 0, "language": "gdscript", "node_count": 2, "path": "effect_manager.gd", @@ -18,6 +20,7 @@ { "content_hash": "40f411be7a8b9048869b5a8902243a44fcb645c67e3c1d2fb05b0f20b5c7075c", "errors": null, + "generated": 0, "language": "gdscript", "node_count": 2, "path": "game_flow.gd", @@ -26,6 +29,7 @@ { "content_hash": "fca10c3b36f6310276b07105d034d82d7f54f132283b460939dd05b213b2abf7", "errors": null, + "generated": 0, "language": "godot_scene", "node_count": 0, "path": "main.tscn", @@ -34,6 +38,7 @@ { "content_hash": "b01662a4255e8445a808378889ccf8b38b49d012cd8ed933fa540b5f9e097d60", "errors": null, + "generated": 0, "language": "godot_project", "node_count": 0, "path": "project.godot", @@ -42,6 +47,7 @@ { "content_hash": "5410c79a7bb764595c01f175fb3533956a84c884801660428bc032b000a01131", "errors": null, + "generated": 0, "language": "gdscript", "node_count": 6, "path": "stage_manager.gd", diff --git a/reference/golden/godot/schema.sql b/reference/golden/godot/schema.sql index a2ec49ae..e528b87c 100644 --- a/reference/golden/godot/schema.sql +++ b/reference/golden/godot/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -100,8 +101,11 @@ END; CREATE INDEX idx_edges_kind ON edges(kind); CREATE INDEX idx_edges_source_kind ON edges(source, kind); CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); @@ -113,5 +117,3 @@ value TEXT NOT NULL, updated_at INTEGER NOT NULL ); CREATE TABLE sqlite_stat1(tbl,idx,stat); -CREATE UNIQUE INDEX idx_edges_identity -ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); diff --git a/reference/golden/kotlin/colby.db b/reference/golden/kotlin/colby.db index a4823371..d1b95116 100644 Binary files a/reference/golden/kotlin/colby.db and b/reference/golden/kotlin/colby.db differ diff --git a/reference/golden/kotlin/files.json b/reference/golden/kotlin/files.json index aae630be..9a1632c2 100644 --- a/reference/golden/kotlin/files.json +++ b/reference/golden/kotlin/files.json @@ -2,6 +2,7 @@ { "content_hash": "bc5f142764204c3f0298334ebe62cf7e9b547694106085dcfe5ebff665e2cd65", "errors": null, + "generated": 0, "language": "kotlin", "node_count": 7, "path": "signatures.kt", diff --git a/reference/golden/kotlin/schema.sql b/reference/golden/kotlin/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/kotlin/schema.sql +++ b/reference/golden/kotlin/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/metal/colby.db b/reference/golden/metal/colby.db index 9d849d30..e6873f51 100644 Binary files a/reference/golden/metal/colby.db and b/reference/golden/metal/colby.db differ diff --git a/reference/golden/metal/files.json b/reference/golden/metal/files.json index 84c7f7c8..c24537f8 100644 --- a/reference/golden/metal/files.json +++ b/reference/golden/metal/files.json @@ -2,6 +2,7 @@ { "content_hash": "42a8ea57f43a0da7ea71ed53775560358fbfe499ed6414bb0be9a2cb43eeda30", "errors": null, + "generated": 0, "language": "cpp", "node_count": 6, "path": "shader.metal", diff --git a/reference/golden/metal/schema.sql b/reference/golden/metal/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/metal/schema.sql +++ b/reference/golden/metal/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/mini/colby.db b/reference/golden/mini/colby.db index 44c349cd..1d6ca93a 100644 Binary files a/reference/golden/mini/colby.db and b/reference/golden/mini/colby.db differ diff --git a/reference/golden/mini/files.json b/reference/golden/mini/files.json index 501106a4..d385493a 100644 --- a/reference/golden/mini/files.json +++ b/reference/golden/mini/files.json @@ -2,6 +2,7 @@ { "content_hash": "10857ef49b4fb2f611c10181f9fa4c955e86b1ec1a54b2a272b17ffb848598cd", "errors": null, + "generated": 0, "language": "typescript", "node_count": 3, "path": "src/app.ts", @@ -10,6 +11,7 @@ { "content_hash": "caebbaef45cf4da7e66dd1479300307d465c03a7a9be5c9e358877bcbc81efc8", "errors": null, + "generated": 0, "language": "typescript", "node_count": 5, "path": "src/math.ts", @@ -18,6 +20,7 @@ { "content_hash": "256033248f73c030955a522a62420fc54a5bdc1fc1c7aff58e55403e7b27cc3b", "errors": null, + "generated": 0, "language": "python", "node_count": 5, "path": "tools/greeter.py", diff --git a/reference/golden/mini/schema.sql b/reference/golden/mini/schema.sql index a2ec49ae..e528b87c 100644 --- a/reference/golden/mini/schema.sql +++ b/reference/golden/mini/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -100,8 +101,11 @@ END; CREATE INDEX idx_edges_kind ON edges(kind); CREATE INDEX idx_edges_source_kind ON edges(source, kind); CREATE INDEX idx_edges_target_kind ON edges(target, kind); +CREATE UNIQUE INDEX idx_edges_identity +ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); @@ -113,5 +117,3 @@ value TEXT NOT NULL, updated_at INTEGER NOT NULL ); CREATE TABLE sqlite_stat1(tbl,idx,stat); -CREATE UNIQUE INDEX idx_edges_identity -ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); diff --git a/reference/golden/nix/colby.db b/reference/golden/nix/colby.db index bb868d1f..08a0c9fd 100644 Binary files a/reference/golden/nix/colby.db and b/reference/golden/nix/colby.db differ diff --git a/reference/golden/nix/files.json b/reference/golden/nix/files.json index d3f47c55..17e4d2e0 100644 --- a/reference/golden/nix/files.json +++ b/reference/golden/nix/files.json @@ -2,6 +2,7 @@ { "content_hash": "7ea2d3f7da76e263d391b2ec6d7d99574db4c40cc9e4f33a5a305346c82ee3d5", "errors": null, + "generated": 0, "language": "nix", "node_count": 3, "path": "bar.nix", @@ -10,6 +11,7 @@ { "content_hash": "ed9b1d6a781e97666ec258cf392af57c8ab2cb1e818daac8ea099bef7e041a71", "errors": null, + "generated": 0, "language": "nix", "node_count": 15, "path": "default.nix", @@ -18,6 +20,7 @@ { "content_hash": "89378235fc3afa5147a2c9abeddc1fb5c31f736bb076c1ad13159b90791bce31", "errors": null, + "generated": 0, "language": "nix", "node_count": 4, "path": "foo.nix", diff --git a/reference/golden/nix/schema.sql b/reference/golden/nix/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/nix/schema.sql +++ b/reference/golden/nix/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/python/colby.db b/reference/golden/python/colby.db index a0826bdf..0da179b5 100644 Binary files a/reference/golden/python/colby.db and b/reference/golden/python/colby.db differ diff --git a/reference/golden/python/files.json b/reference/golden/python/files.json index dc1e461b..c026afad 100644 --- a/reference/golden/python/files.json +++ b/reference/golden/python/files.json @@ -2,6 +2,7 @@ { "content_hash": "ffcdab43044b451a4dd403d4d74460128523d9fcba30dfe75e9a595a0f2c46db", "errors": null, + "generated": 0, "language": "python", "node_count": 3, "path": "consumers.py", @@ -10,6 +11,7 @@ { "content_hash": "6cebb328503cb6d3a66c76ade1e6da7f16dbd066c1689c41765ea55255d9d030", "errors": null, + "generated": 0, "language": "python", "node_count": 2, "path": "imported_types.py", @@ -18,6 +20,7 @@ { "content_hash": "dcee64febdb07e86597a805d2ca48d93a6c69a4c547247399c39e316c21827d2", "errors": null, + "generated": 0, "language": "python", "node_count": 17, "path": "same_file.py", diff --git a/reference/golden/python/schema.sql b/reference/golden/python/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/python/schema.sql +++ b/reference/golden/python/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/ruby/colby.db b/reference/golden/ruby/colby.db index d83b2787..0d6e6d00 100644 Binary files a/reference/golden/ruby/colby.db and b/reference/golden/ruby/colby.db differ diff --git a/reference/golden/ruby/files.json b/reference/golden/ruby/files.json index 0fbe400e..e840082d 100644 --- a/reference/golden/ruby/files.json +++ b/reference/golden/ruby/files.json @@ -2,6 +2,7 @@ { "content_hash": "3a65be1da08f0b766455700e321bd9edb858cc78e21915e8bfaf3e49b5364f22", "errors": null, + "generated": 0, "language": "ruby", "node_count": 5, "path": "logger.rb", @@ -10,6 +11,7 @@ { "content_hash": "053a1a3cfdfe31ecabb5071c79aadd1b5939b20403e8681efcc0b138076bde79", "errors": null, + "generated": 0, "language": "ruby", "node_count": 6, "path": "service.rb", diff --git a/reference/golden/ruby/schema.sql b/reference/golden/ruby/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/ruby/schema.sql +++ b/reference/golden/ruby/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/rust/colby.db b/reference/golden/rust/colby.db index 7e760535..08bfca79 100644 Binary files a/reference/golden/rust/colby.db and b/reference/golden/rust/colby.db differ diff --git a/reference/golden/rust/files.json b/reference/golden/rust/files.json index 4ac637ce..15f9aa96 100644 --- a/reference/golden/rust/files.json +++ b/reference/golden/rust/files.json @@ -2,6 +2,7 @@ { "content_hash": "8121cdd4bac4cf4e031fa69ca8b2ceea14f7f61e2357a339025afdcb51ea6585", "errors": null, + "generated": 0, "language": "rust", "node_count": 4, "path": "consumer.rs", @@ -10,6 +11,7 @@ { "content_hash": "32fd3f5a2c8b2054c3197394a04d39f75f8ad52de6afe38e76ec0e4ee7358960", "errors": null, + "generated": 0, "language": "rust", "node_count": 14, "path": "lib.rs", diff --git a/reference/golden/rust/schema.sql b/reference/golden/rust/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/rust/schema.sql +++ b/reference/golden/rust/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/solidity/colby.db b/reference/golden/solidity/colby.db index a786dde9..a7cee4d5 100644 Binary files a/reference/golden/solidity/colby.db and b/reference/golden/solidity/colby.db differ diff --git a/reference/golden/solidity/files.json b/reference/golden/solidity/files.json index d14c8068..84c0c027 100644 --- a/reference/golden/solidity/files.json +++ b/reference/golden/solidity/files.json @@ -2,6 +2,7 @@ { "content_hash": "bef3d1355e28323c5eaeeac93fd3693297706de47dd276566eee9d64a4568d6f", "errors": null, + "generated": 0, "language": "solidity", "node_count": 3, "path": "IERC20.sol", @@ -10,6 +11,7 @@ { "content_hash": "c8976b8cc5a7ea552da5c19efd79afa395873bd8a1253ebe9282b538e4c9a8e3", "errors": null, + "generated": 0, "language": "solidity", "node_count": 20, "path": "Token.sol", diff --git a/reference/golden/solidity/schema.sql b/reference/golden/solidity/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/solidity/schema.sql +++ b/reference/golden/solidity/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/terraform/colby.db b/reference/golden/terraform/colby.db index 1415c653..56723302 100644 Binary files a/reference/golden/terraform/colby.db and b/reference/golden/terraform/colby.db differ diff --git a/reference/golden/terraform/files.json b/reference/golden/terraform/files.json index 549b157d..97aed078 100644 --- a/reference/golden/terraform/files.json +++ b/reference/golden/terraform/files.json @@ -2,6 +2,7 @@ { "content_hash": "7df7854f67b585b19f9fb67712ff48434fc209255e89d426d2036200cd4d960c", "errors": null, + "generated": 0, "language": "terraform", "node_count": 10, "path": "main.tf", diff --git a/reference/golden/terraform/schema.sql b/reference/golden/terraform/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/terraform/schema.sql +++ b/reference/golden/terraform/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path); diff --git a/reference/golden/typescript/colby.db b/reference/golden/typescript/colby.db index 2826b012..dcf0c348 100644 Binary files a/reference/golden/typescript/colby.db and b/reference/golden/typescript/colby.db differ diff --git a/reference/golden/typescript/files.json b/reference/golden/typescript/files.json index 7ecb899e..299b5a70 100644 --- a/reference/golden/typescript/files.json +++ b/reference/golden/typescript/files.json @@ -2,6 +2,7 @@ { "content_hash": "5d91d0b374e6bbe30c01d7932f5554fbf02f1a3d1eea2f0aee046ae6a891c182", "errors": null, + "generated": 0, "language": "javascript", "node_count": 2, "path": "collision.js", @@ -10,6 +11,7 @@ { "content_hash": "5d91d0b374e6bbe30c01d7932f5554fbf02f1a3d1eea2f0aee046ae6a891c182", "errors": null, + "generated": 0, "language": "typescript", "node_count": 2, "path": "collision.ts", @@ -18,6 +20,7 @@ { "content_hash": "417ddd5bafc0993f53e32c05d91eef694f7ef6b3d99fda239ae893be0fcc7c9b", "errors": null, + "generated": 0, "language": "typescript", "node_count": 9, "path": "consumer.ts", @@ -26,6 +29,7 @@ { "content_hash": "1a81c274140423b2a2f7ce75e1f010817827acf00fdab3a5bfe87a1c0b3aacde", "errors": null, + "generated": 0, "language": "typescript", "node_count": 5, "path": "exports.ts", @@ -34,6 +38,7 @@ { "content_hash": "82f12c230dbce8f54af95b6050c1cb9286d876373a38ceccb7c5cb00add8df80", "errors": null, + "generated": 0, "language": "typescript", "node_count": 2, "path": "extensionless.ts", @@ -42,6 +47,7 @@ { "content_hash": "04c00befb179da7e0748d6338704f7953a0f419fc1b566168f68567d1cc5e52c", "errors": null, + "generated": 0, "language": "typescript", "node_count": 2, "path": "js_target.ts", diff --git a/reference/golden/typescript/schema.sql b/reference/golden/typescript/schema.sql index d36218fe..e528b87c 100644 --- a/reference/golden/typescript/schema.sql +++ b/reference/golden/typescript/schema.sql @@ -47,7 +47,8 @@ size INTEGER NOT NULL, modified_at INTEGER NOT NULL, indexed_at INTEGER NOT NULL, node_count INTEGER DEFAULT 0, -errors TEXT -- JSON array +errors TEXT, -- JSON array +generated INTEGER NOT NULL DEFAULT 0 ); CREATE TABLE unresolved_refs ( id INTEGER PRIMARY KEY AUTOINCREMENT, @@ -104,6 +105,7 @@ CREATE UNIQUE INDEX idx_edges_identity ON edges(source, target, kind, IFNULL(line, -1), IFNULL(col, -1)); CREATE INDEX idx_files_language ON files(language); CREATE INDEX idx_files_modified_at ON files(modified_at); +CREATE INDEX idx_files_generated ON files(path) WHERE generated = 1; CREATE INDEX idx_unresolved_from_node ON unresolved_refs(from_node_id); CREATE INDEX idx_unresolved_name ON unresolved_refs(reference_name); CREATE INDEX idx_unresolved_file_path ON unresolved_refs(file_path);