From 16f26d7d60ce9fbc62feb0e8e83f93951f7b53fe Mon Sep 17 00:00:00 2001 From: cflmy Date: Tue, 27 Oct 2026 09:18:27 +0800 Subject: [PATCH] fix(knowledge): warm-load IR for preflight/find/reuse queries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stop full recompile on every knowledge preflight by writing ekc/graph/ir.json and loading it unless --refresh or missing projections, cutting chat预检 wall time. Co-authored-by: Cursor --- CHANGELOG.md | 7 +++ doc/design/engineering-knowledge.md | 11 +++-- src/knowledge/compile.rs | 72 ++++++++++++++------------- src/knowledge/ir.rs | 76 +++++++++++++++++++++++++---- src/knowledge/mod.rs | 9 +++- src/knowledge/preflight.rs | 12 ++++- src/main.rs | 75 +++++++++++++++++++++------- tests/gold.rs | 43 ++++++++++++++++ 8 files changed, 237 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18042fe..da5e023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,10 +4,17 @@ ### Added +- **EKC `ir.json` 快照**:`marqdo knowledge` 写入 `.marqdo/ekc/graph/ir.json`;查询命令暖机热加载,免全量重编译。 +- **`--refresh`**:`knowledge preflight` / `find` / `reuse` / `impact` / `conflicts` / `stale` / `duplicate` / `verify` 可强制重编译。 + ### Fixed +- **工程预检热路径**:`knowledge preflight`(及 find/reuse 等)默认不再每次 `ensure_compiled` 全量 compile,修复聊天「工程预检」墙钟过长。 + ### Changed +- 查询类 knowledge CLI:**缺投影才 compile**;CI / 源变更请先 `marqdo knowledge` 或 `--refresh`。 + ## v2.1.4 — 2026-10-26 ### Highlights diff --git a/doc/design/engineering-knowledge.md b/doc/design/engineering-knowledge.md index 721a991..3cf8495 100644 --- a/doc/design/engineering-knowledge.md +++ b/doc/design/engineering-knowledge.md @@ -53,22 +53,23 @@ Marqdo 把仓库投影为 **可查询、可验证、可复用** 的工程知识 落盘(G01 分离后): - **权威语义图**:`.marqdo/graph/edges.json` · `nodes.json`(`SemanticProject`,含 `authority` 字段)· `steps.json` -- **EKC 检索投影**(非执行依据):`.marqdo/ekc/graph/graph.json` · `edges.json` · `index.json` +- **EKC 检索投影**(非执行依据):`.marqdo/ekc/graph/graph.json` · `edges.json` · `index.json` · **`ir.json`**(完整 IR 快照,供查询热路径) ## 5. CLI ```bash -marqdo knowledge [PATH] -o .marqdo # compile(默认) -marqdo knowledge preflight "task" +marqdo knowledge [PATH] -o .marqdo # compile(默认;写投影 + ir.json) +marqdo knowledge preflight "task" # 暖机读 ir.json;缺图才 compile +marqdo knowledge preflight "task" --refresh # 强制全量重编译后再预检 marqdo knowledge record REUSE marqdo knowledge learn --task ... --failure ... -marqdo find "authentication" +marqdo find "authentication" # 同上:缺图才 compile;--refresh 强制 marqdo reuse "implement oauth login" marqdo impact path/to/file.mq.md marqdo conflicts | stale | duplicate [--fail] | verify ``` -统一 `--json`。`duplicate` 默认阈值 `0.75`;`--fail` 作 CI Gate。 +统一 `--json`。查询类命令(`preflight` / `find` / `reuse` / `impact` / `conflicts` / `stale` / `duplicate` / `verify`)默认 **读已编译投影**;CI 或源变更后应先 `marqdo knowledge` 或加 `--refresh`。`duplicate` 默认阈值 `0.75`;`--fail` 作 CI Gate。 ## 6. Reuse 协议 diff --git a/src/knowledge/compile.rs b/src/knowledge/compile.rs index b7ae745..0899746 100644 --- a/src/knowledge/compile.rs +++ b/src/knowledge/compile.rs @@ -114,7 +114,23 @@ pub fn ekc_graph_dir(out_dir: &Path) -> std::path::PathBuf { out_dir.join("ekc").join("graph") } +/// Path of the full IR snapshot used by warm query paths (preflight/find/reuse). +pub fn ir_snapshot_path(out_dir: &Path) -> std::path::PathBuf { + ekc_graph_dir(out_dir).join("ir.json") +} + +/// Load a previously compiled KnowledgeGraph without re-extracting sources. +/// Prefers `ekc/graph/ir.json`. Does **not** walk the source tree. pub fn load_graph(out_dir: &Path) -> Result { + let ir_path = ir_snapshot_path(out_dir); + if ir_path.exists() { + let raw = fs::read_to_string(&ir_path) + .with_context(|| format!("read {}", ir_path.display()))?; + let graph: KnowledgeGraph = serde_json::from_str(&raw) + .with_context(|| format!("parse {}", ir_path.display()))?; + return Ok(graph); + } + let graph_path = ekc_graph_dir(out_dir).join("graph.json"); let edges_path = ekc_graph_dir(out_dir).join("edges.json"); if !graph_path.exists() { @@ -123,47 +139,19 @@ pub fn load_graph(out_dir: &Path) -> Result { graph_path.display() ); } - // Prefer re-extract for freshness when source path known; for query commands - // we rebuild from JSON snapshot fields + re-scan if catalog sibling exists. - // Snapshot load: reconstruct minimal IR from written pages + edges.json. + + // Legacy projections without ir.json: edges-only fallback (no source walk). let edges_raw = fs::read_to_string(&edges_path).unwrap_or_else(|_| "{\"edges\":[]}".into()); let edges_v: serde_json::Value = serde_json::from_str(&edges_raw)?; let graph_raw = fs::read_to_string(&graph_path)?; let graph_v: serde_json::Value = serde_json::from_str(&graph_raw)?; - // Re-compile from recorded root if present in graph.json - if let Some(root) = graph_v - .pointer("/repository/root") - .and_then(|v| v.as_str()) - { - let root_path = Path::new(root); - if root_path.exists() { - return extract_graph(&ExtractOptions { - path: root_path.to_path_buf(), - out_dir: out_dir.to_path_buf(), - }); - } - } - - // Fallback: empty-ish graph with edges only let mut edges = Vec::new(); if let Some(arr) = edges_v.get("edges").and_then(|e| e.as_array()) { for e in arr { - let kind = match e.get("kind").and_then(|k| k.as_str()).unwrap_or("") { - "implements" => crate::knowledge::ir::EdgeKind::Implements, - "uses" => crate::knowledge::ir::EdgeKind::Uses, - "depends_on" => crate::knowledge::ir::EdgeKind::DependsOn, - "tested_by" => crate::knowledge::ir::EdgeKind::TestedBy, - "documented_by" => crate::knowledge::ir::EdgeKind::DocumentedBy, - "constrained_by" => crate::knowledge::ir::EdgeKind::ConstrainedBy, - "decided_by" => crate::knowledge::ir::EdgeKind::DecidedBy, - "supersedes" => crate::knowledge::ir::EdgeKind::Supersedes, - "conflicts_with" => crate::knowledge::ir::EdgeKind::ConflictsWith, - "deprecated_by" => crate::knowledge::ir::EdgeKind::DeprecatedBy, - "derived_from" => crate::knowledge::ir::EdgeKind::DerivedFrom, - "failed_by" => crate::knowledge::ir::EdgeKind::FailedBy, - _ => crate::knowledge::ir::EdgeKind::RelatedTo, - }; + let kind = crate::knowledge::ir::EdgeKind::parse( + e.get("kind").and_then(|k| k.as_str()).unwrap_or(""), + ); edges.push(crate::knowledge::ir::Edge { from: e.get("from").and_then(|v| v.as_str()).unwrap_or("").into(), to: e.get("to").and_then(|v| v.as_str()).unwrap_or("").into(), @@ -204,14 +192,27 @@ pub fn load_graph(out_dir: &Path) -> Result { }) } +/// Force a full knowledge compile (write path / `--refresh`). pub fn ensure_compiled(path: &Path, out_dir: &Path) -> Result { - // Always refresh from source when path is given. compile(KnowledgeOptions { path: path.to_path_buf(), out_dir: out_dir.to_path_buf(), }) } +/// Query path loader: compile if missing (or `refresh`), else hot-load `ir.json`. +pub fn graph_for_query(path: &Path, out_dir: &Path, refresh: bool) -> Result { + if refresh { + return ensure_compiled(path, out_dir); + } + let has_ir = ir_snapshot_path(out_dir).exists(); + let has_graph = ekc_graph_dir(out_dir).join("graph.json").exists(); + if has_ir || has_graph { + return load_graph(out_dir); + } + ensure_compiled(path, out_dir) +} + fn write_projections(out_dir: &Path, graph: &KnowledgeGraph) -> Result<()> { let dirs = [ "catalog/modules", @@ -299,6 +300,9 @@ fn write_projections(out_dir: &Path, graph: &KnowledgeGraph) -> Result<()> { fs::write(ekc.join("graph.json"), graph_json)?; let edges_json = serde_json::to_string_pretty(&graph.to_edges_json())?; fs::write(ekc.join("edges.json"), edges_json)?; + // Full IR snapshot for warm query paths (preflight/find/reuse) — no re-extract. + let ir_json = serde_json::to_string(&graph)?; + fs::write(ekc.join("ir.json"), ir_json)?; // Search index let index = json!({ diff --git a/src/knowledge/ir.rs b/src/knowledge/ir.rs index 1bebb78..58cd37c 100644 --- a/src/knowledge/ir.rs +++ b/src/knowledge/ir.rs @@ -1,5 +1,6 @@ //! Engineering Knowledge IR (L0–L4) — projections of `.mq.md`, not a second source of truth. +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde_json::{json, Value}; use std::collections::BTreeMap; @@ -13,6 +14,19 @@ pub enum Lifecycle { Superseded, } +impl Serialize for Lifecycle { + fn serialize(&self, serializer: S) -> Result { + serializer.serialize_str(self.as_str()) + } +} + +impl<'de> Deserialize<'de> for Lifecycle { + fn deserialize>(deserializer: D) -> Result { + let s = String::deserialize(deserializer)?; + Ok(Self::parse(&s)) + } +} + impl Lifecycle { pub fn as_str(&self) -> &'static str { match self { @@ -35,7 +49,7 @@ impl Lifecycle { } } -#[derive(Debug, Clone, Default)] +#[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Evidence { pub sources: Vec, pub tests: Vec, @@ -55,7 +69,7 @@ impl Evidence { } /// Graded confidence with explanation (not a bare float). -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Confidence { pub level: String, // high | medium | low pub implementation: String, @@ -87,7 +101,7 @@ impl Confidence { } } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct RepositoryInfo { pub title: String, pub root: String, @@ -98,7 +112,7 @@ pub struct RepositoryInfo { pub knowledge_count: usize, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct ModuleInfo { pub id: String, pub resource: String, @@ -111,7 +125,7 @@ pub struct ModuleInfo { pub status: Lifecycle, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct SymbolInfo { pub id: String, pub name: String, @@ -135,7 +149,7 @@ pub struct SymbolInfo { pub confidence: Confidence, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct CapabilityInfo { pub id: String, pub name: String, @@ -215,7 +229,20 @@ impl KnowledgeKind { } } -#[derive(Debug, Clone)] +impl Serialize for KnowledgeKind { + fn serialize(&self, serializer: S) -> Result { + serializer.serialize_str(self.as_str()) + } +} + +impl<'de> Deserialize<'de> for KnowledgeKind { + fn deserialize>(deserializer: D) -> Result { + let s = String::deserialize(deserializer)?; + Ok(Self::parse(&s)) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct KnowledgeItem { pub id: String, pub kind: KnowledgeKind, @@ -269,9 +296,40 @@ impl EdgeKind { Self::RelatedTo => "related_to", } } + + pub fn parse(s: &str) -> Self { + match s.trim() { + "implements" => Self::Implements, + "uses" => Self::Uses, + "depends_on" => Self::DependsOn, + "tested_by" => Self::TestedBy, + "documented_by" => Self::DocumentedBy, + "constrained_by" => Self::ConstrainedBy, + "decided_by" => Self::DecidedBy, + "supersedes" => Self::Supersedes, + "conflicts_with" => Self::ConflictsWith, + "deprecated_by" => Self::DeprecatedBy, + "derived_from" => Self::DerivedFrom, + "failed_by" => Self::FailedBy, + _ => Self::RelatedTo, + } + } } -#[derive(Debug, Clone)] +impl Serialize for EdgeKind { + fn serialize(&self, serializer: S) -> Result { + serializer.serialize_str(self.as_str()) + } +} + +impl<'de> Deserialize<'de> for EdgeKind { + fn deserialize>(deserializer: D) -> Result { + let s = String::deserialize(deserializer)?; + Ok(Self::parse(&s)) + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Edge { pub from: String, pub to: String, @@ -336,7 +394,7 @@ pub struct ReuseResult { pub recommended: Vec, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct KnowledgeGraph { pub repository: RepositoryInfo, pub modules: Vec, diff --git a/src/knowledge/mod.rs b/src/knowledge/mod.rs index db003a7..3b8dbc9 100644 --- a/src/knowledge/mod.rs +++ b/src/knowledge/mod.rs @@ -20,7 +20,10 @@ pub mod preflight; pub mod reuse; pub mod util; -pub use compile::{compile, ekc_graph_dir, ensure_compiled, load_graph, KnowledgeOptions}; +pub use compile::{ + compile, ekc_graph_dir, ensure_compiled, graph_for_query, ir_snapshot_path, load_graph, + KnowledgeOptions, +}; pub use duplicate::{find_duplicates, format_duplicates_text}; pub use find::{find, find_json, format_find_text}; pub use impact::{format_impact_text, impact, impact_json}; @@ -32,7 +35,9 @@ pub use lifecycle::{ }; pub use metrics::{load_metrics, record_decision, save_metrics, ReuseMetrics}; pub use policy::compile_policy; -pub use preflight::{format_preflight_yaml, preflight, preflight_json, PreflightResult}; +pub use preflight::{ + format_preflight_yaml, preflight, preflight_from_reuse, preflight_json, PreflightResult, +}; pub use reuse::{format_reuse_text, resolve, reuse_json, ReuseBudget}; use std::path::{Path, PathBuf}; diff --git a/src/knowledge/preflight.rs b/src/knowledge/preflight.rs index 5cac85a..a5ba701 100644 --- a/src/knowledge/preflight.rs +++ b/src/knowledge/preflight.rs @@ -33,6 +33,16 @@ pub fn preflight( out_dir: Option<&Path>, ) -> Result { let reuse = resolve(graph, task, budget); + preflight_from_reuse(graph, task, &reuse, out_dir) +} + +/// Build a Context Pack from an already-resolved reuse result (avoids a second `resolve`). +pub fn preflight_from_reuse( + graph: &KnowledgeGraph, + task: &str, + reuse: &crate::knowledge::ir::ReuseResult, + out_dir: Option<&Path>, +) -> Result { let intent = reuse .capability .clone() @@ -46,7 +56,7 @@ pub fn preflight( .map(|c| c.title.clone()) .collect(); - let pack = render_context_pack(task, &intent, &reuse, graph); + let pack = render_context_pack(task, &intent, reuse, graph); let mut context_path = None; if let Some(out) = out_dir { let contexts = out.join("agent/contexts"); diff --git a/src/main.rs b/src/main.rs index 2acfe5d..dcaf0f7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,12 +9,12 @@ use marqdo::diagnostics::{Diagnostic, Span}; use marqdo::ext_cli::{add_ext, list_ext, remove_ext}; use marqdo::input_feed::load_stdin_file; use marqdo::knowledge::{ - compile_policy, conflicts_json, ensure_compiled, find, find_conflicts, find_duplicates, - find_json, find_stale, format_conflicts_text, format_duplicates_text, format_find_text, - format_impact_text, format_preflight_yaml, format_reuse_text, format_stale_text, - format_verify_text, impact, impact_json, learn, preflight, preflight_json, record_decision, - resolve, reuse_json, stale_json, verify, verify_json, write_knowledge, KnowledgeOptions, - LearnInput, ReuseBudget, + compile_policy, conflicts_json, find, find_conflicts, find_duplicates, find_json, find_stale, + format_conflicts_text, format_duplicates_text, format_find_text, format_impact_text, + format_preflight_yaml, format_reuse_text, format_stale_text, format_verify_text, graph_for_query, + impact, impact_json, learn, preflight_from_reuse, preflight_json, record_decision, resolve, + reuse_json, stale_json, verify, verify_json, write_knowledge, KnowledgeOptions, LearnInput, + ReuseBudget, }; use marqdo::view::{ serve, serve_debug, write_capture, write_static, CaptureOptions, DebugOptions, OutputOptions, @@ -265,6 +265,10 @@ enum Commands { #[arg(long, global = true)] json: bool, + + /// Force a full knowledge recompile before query actions (preflight, …) + #[arg(long, global = true)] + refresh: bool, }, /// Find engineering capabilities / symbols / knowledge Find { @@ -282,6 +286,10 @@ enum Commands { #[arg(long)] json: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Engineering First Information: REUSE / ADAPT / CREATE Reuse { @@ -306,6 +314,10 @@ enum Commands { #[arg(long)] json: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Knowledge impact of changed paths Impact { @@ -320,6 +332,10 @@ enum Commands { #[arg(long)] json: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Detect knowledge conflicts / possible duplicates edges Conflicts { @@ -335,6 +351,10 @@ enum Commands { /// Exit non-zero when conflicts found (CI gate; default remains report-only) #[arg(long)] fail: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// List stale / deprecated / superseded knowledge Stale { @@ -350,6 +370,10 @@ enum Commands { /// Exit non-zero when stale items found (CI gate; default remains report-only) #[arg(long)] fail: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Detect duplicate capabilities via symbol fingerprints Duplicate { @@ -368,6 +392,10 @@ enum Commands { #[arg(long)] json: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Verify code ↔ knowledge consistency (EKC structural; exit 1 only on errors) Verify { @@ -383,6 +411,10 @@ enum Commands { /// Also fail on warnings (does not change default success-when-no-errors) #[arg(long)] fail_on_warning: bool, + + /// Force a full knowledge recompile before querying + #[arg(long)] + refresh: bool, }, /// Official extension installer (`list` / `add` / `remove`) Ext { @@ -1235,6 +1267,7 @@ fn try_main(cli: Cli) -> Result { path, out, json, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); match action.unwrap_or(KnowledgeAction::Compile) { @@ -1479,14 +1512,15 @@ fn try_main(cli: Cli) -> Result { min_candidates, allow_create_after, } => { - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let budget = ReuseBudget { min_candidates, allow_create_after, ..ReuseBudget::default() }; - let pf = preflight(&graph, &task, &budget, Some(&out))?; - let _ = compile_policy(&out, &task, &resolve(&graph, &task, &budget)); + let reuse = resolve(&graph, &task, &budget); + let pf = preflight_from_reuse(&graph, &task, &reuse, Some(&out))?; + let _ = compile_policy(&out, &task, &reuse); if json { println!("{}", preflight_json(&pf)); } else { @@ -1554,9 +1588,10 @@ fn try_main(cli: Cli) -> Result { out, limit, json, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let hits = find(&graph, &query, limit); if json { println!("{}", find_json(&query, &hits)); @@ -1573,9 +1608,10 @@ fn try_main(cli: Cli) -> Result { min_candidates, allow_create_after, json, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let budget = ReuseBudget { min_candidates, allow_create_after, @@ -1584,7 +1620,7 @@ fn try_main(cli: Cli) -> Result { let result = resolve(&graph, &task, &budget); let _ = compile_policy(&out, &task, &result); if do_preflight { - let _ = preflight(&graph, &task, &budget, Some(&out))?; + let _ = preflight_from_reuse(&graph, &task, &result, Some(&out))?; } if json { println!("{}", reuse_json(&task, &result)); @@ -1598,8 +1634,9 @@ fn try_main(cli: Cli) -> Result { root, out, json, + refresh, } => { - let graph = ensure_compiled(&root, &out)?; + let graph = graph_for_query(&root, &out, refresh)?; let path_strs: Vec = paths .iter() .map(|p| p.to_string_lossy().replace('\\', "/")) @@ -1617,9 +1654,10 @@ fn try_main(cli: Cli) -> Result { out, json, fail, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let items = find_conflicts(&graph); if json { println!("{}", conflicts_json(&items)); @@ -1633,9 +1671,10 @@ fn try_main(cli: Cli) -> Result { out, json, fail, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let items = find_stale(&graph, &path); if json { println!("{}", stale_json(&items)); @@ -1650,9 +1689,10 @@ fn try_main(cli: Cli) -> Result { threshold, fail, json, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let pairs = find_duplicates(&graph.symbols, threshold); if json { println!( @@ -1682,9 +1722,10 @@ fn try_main(cli: Cli) -> Result { out, json, fail_on_warning, + refresh, } => { let path = path.unwrap_or_else(|| PathBuf::from(".")); - let graph = ensure_compiled(&path, &out)?; + let graph = graph_for_query(&path, &out, refresh)?; let issues = verify(&graph); if json { println!("{}", verify_json(&issues)); diff --git a/tests/gold.rs b/tests/gold.rs index 8b65b87..5d63696 100644 --- a/tests/gold.rs +++ b/tests/gold.rs @@ -1431,6 +1431,49 @@ fn knowledge_preflight_writes_context_pack() { assert!(!packs.is_empty(), "expected context pack"); } +#[test] +fn knowledge_preflight_warm_loads_ir_without_recompile() { + let dir = tempfile_dir("mq-pf-warm"); + let out = dir.to_str().unwrap(); + let (code, _, stderr) = run(&["knowledge", "tests/engineering", "-o", out]); + assert_eq!(code, 0, "{stderr}"); + assert!( + dir.join("ekc/graph/ir.json").exists(), + "expected ir.json snapshot after compile" + ); + let gens = dir.join("generations"); + let before: Vec<_> = if gens.exists() { + std::fs::read_dir(&gens).unwrap().flatten().collect() + } else { + Vec::new() + }; + let (code2, stdout, stderr2) = run(&[ + "knowledge", + "tests/engineering", + "preflight", + "resolve configuration", + "-o", + out, + "--json", + ]); + assert_eq!(code2, 0, "{stderr2}\n{stdout}"); + assert!(stdout.contains("create_allowed"), "{stdout}"); + assert!( + !stderr2.contains("marqdo knowledge timing_ms:"), + "warm preflight must not full-compile: {stderr2}" + ); + let after: Vec<_> = if gens.exists() { + std::fs::read_dir(&gens).unwrap().flatten().collect() + } else { + Vec::new() + }; + assert_eq!( + before.len(), + after.len(), + "warm preflight must not create a new generations/ tree" + ); +} + #[test] fn catalog_hooks_knowledge_by_default() { let dir = tempfile_dir("mq-cat-ekc");