From 037a2d7bc1c3e188670a08b4389a63c7f544b3b1 Mon Sep 17 00:00:00 2001 From: Hung Pham Date: Mon, 26 Oct 2026 15:18:41 +0700 Subject: [PATCH] fix(extract/config): render inline-table call in list_effect_rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list_effect_rules read `call` via `.as_table()`, which only matches a standard table ([effect_rules.call]) — inline table `call = { exact = "PG_TRY" }` (the form users write in config.toml) was skipped, so `codegraph_config_effects list` showed an empty call. Switch to `.as_table_like()` (accepts both Table and InlineTable) and add test effect_rule_list_renders_call covering inline-table rules. Co-authored-by: CodeGraph agent --- crates/codegraph-extract/Cargo.toml | 1 + crates/codegraph-extract/src/config.rs | 2 +- .../codegraph-extract/tests/effects_config.rs | 43 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/crates/codegraph-extract/Cargo.toml b/crates/codegraph-extract/Cargo.toml index fcde7a9fe5..47c0c27de3 100644 --- a/crates/codegraph-extract/Cargo.toml +++ b/crates/codegraph-extract/Cargo.toml @@ -48,6 +48,7 @@ toml_edit = { workspace = true } [dev-dependencies] tempfile = "3" +camino = { workspace = true } tokio = { version = "1", features = ["macros", "rt"] } [features] diff --git a/crates/codegraph-extract/src/config.rs b/crates/codegraph-extract/src/config.rs index 6c92434857..179d931ac8 100644 --- a/crates/codegraph-extract/src/config.rs +++ b/crates/codegraph-extract/src/config.rs @@ -243,7 +243,7 @@ pub fn list_effect_rules(root: &Utf8Path) -> Vec { for t in arr.iter() { let (matcher, text) = t .get("call") - .and_then(|c| c.as_table()) + .and_then(|c| c.as_table_like()) .map(|c| { for k in ["contains", "prefix", "exact"] { if let Some(v) = c.get(k).and_then(|v| v.as_str()) { diff --git a/crates/codegraph-extract/tests/effects_config.rs b/crates/codegraph-extract/tests/effects_config.rs index e68d842730..a990c182af 100644 --- a/crates/codegraph-extract/tests/effects_config.rs +++ b/crates/codegraph-extract/tests/effects_config.rs @@ -549,3 +549,46 @@ int f(int v) { assert!(pos(MARKER_BRANCH_END) < pos(MARKER_TRY_END)); flows::install_current(None); } + +/// `list_effect_rules` đọc đúng `call` cả khi viết dưới dạng inline table +/// `call = { exact = "PG_TRY" }` (không chỉ standard table `[effect_rules.call]`). +#[test] +fn effect_rule_list_renders_call() { + use camino::Utf8Path; + use codegraph_extract::config::list_effect_rules; + + let dir = tempfile::tempdir().expect("tempdir"); + std::fs::create_dir_all(dir.path().join(".codegraph")).unwrap(); + std::fs::write( + dir.path().join(".codegraph").join("config.toml"), + r#" +[[effect_rules]] +call = { exact = "PG_TRY" } +marker = "try_start" + +[[effect_rules]] +call = { contains = "ereport" } +effect = "panic" +marker = "throw" +label = "Error" +"#, + ) + .unwrap(); + + let root = Utf8Path::new(dir.path().to_str().expect("temp dir is valid UTF-8")); + let rules = list_effect_rules(root); + let try_start = rules + .iter() + .find(|r| r.marker == "try_start") + .expect("try_start rule"); + assert_eq!(try_start.matcher, "exact"); + assert_eq!(try_start.text, "PG_TRY"); + let throw = rules + .iter() + .find(|r| r.marker == "throw") + .expect("throw rule"); + assert_eq!(throw.matcher, "contains"); + assert_eq!(throw.text, "ereport"); + assert_eq!(throw.effect, "panic"); + assert_eq!(throw.label, "Error"); +}