feat(labels): M9 两级词表检索 — labels CLI + MLSP labels.search

第一级(内置,数据常量):六组关键词 —— 未完成/假数据/示例/实验/废弃/待校验,
pending = 未完成 ∪ 假数据。作用是默认查询、LLM 范例、跨项目可比。
第二级(参数):--grep 替换,--also-builtin 并集,--group 选组。
**词表是数据不是语法**:扩充它不改任何解析规则。

CLI:
  marqdo labels .                              # pending 口径
  marqdo labels . --grep "联调"                 # 自定义替换
  marqdo labels . --grep "联调" --also-builtin   # 并集
  marqdo labels . --group 示例,实验
  marqdo labels . --count / --json

MLSP:{"method":"labels.search","params":{path|source, grep?, also_builtin?, group?}}
→ {"ok":true,"words":[…],"count":N,"hits":[{line,unit,label,words,has_payload}]}
与 CLI 共用同一份 label::search。

检索语义 v1:子串匹配(CJK 无词边界)、多词 OR、英文大小写不敏感;
误判只影响计数,输出带描述原文可人工判断;不做否定语法(留 v1.1)。

测试:4 个集成(pending=2 / grep 替换=1 / also-builtin 并集=3 / MLSP 返回 hits);
全量 cargo test --release:587 passed / 0 failed(M4 后 583 + 4)。

实测:
  pending → 2 命中("待开发"、"模拟"两处)
  --grep 联调 → 1 命中
  --grep 联调 --also-builtin → 3 命中

文档:doc/design/change-m9-label-search.md
This commit is contained in:
cflmy committed 2026-10-22 15:16:39 +08:00
1 parent 6dd0ce47b1
commit fd0cfcb566
6 files changed
+468

No files matched your search

+69
View File
@@ -99,3 +99,72 @@ fn label_refs_that_resolve_are_fine() {
assert_eq!(code, 0, "text={text}");
assert!(!text.contains("不存在的实体"), "text={text}");
}
// ---- M9: two-tier label search (`labels` CLI + MLSP `labels.search`) ----
fn labels(args: &[&str]) -> (i32, String) {
let out = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.arg("labels")
.args(args)
.env("MARQDO_MARKUP", "occlusion")
.output()
.expect("run marqdo labels");
(
out.status.code().unwrap_or(1),
format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
),
)
}
#[test]
fn labels_pending_uses_builtin_groups() {
let (code, text) = labels(&["tests/occlusion/labels.mq.md", "--count"]);
assert_eq!(code, 0, "text={text}");
assert_eq!(text.trim(), "2", "expected 待开发 + 模拟: {text}");
}
#[test]
fn labels_grep_replaces_builtin() {
let (code, text) = labels(&["tests/occlusion/labels.mq.md", "--grep", "联调", "--count"]);
assert_eq!(code, 0, "text={text}");
assert_eq!(text.trim(), "1", "text={text}");
}
#[test]
fn labels_grep_with_builtin_unions() {
let (code, text) = labels(&[
"tests/occlusion/labels.mq.md",
"--grep",
"联调",
"--also-builtin",
"--count",
]);
assert_eq!(code, 0, "text={text}");
assert_eq!(text.trim(), "3", "text={text}");
}
#[test]
fn mlsp_labels_search_returns_hits() {
use std::io::Write;
let mut child = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.arg("mlsp")
.env("MARQDO_MARKUP", "occlusion")
.stdin(std::process::Stdio::piped())
.stdout(std::process::Stdio::piped())
.spawn()
.expect("spawn mlsp");
let req = r#"{"id":1,"method":"labels.search","params":{"path":"tests/occlusion/labels.mq.md","also_builtin":true}}"#;
child
.stdin
.as_mut()
.unwrap()
.write_all(format!("{req}\n").as_bytes())
.unwrap();
let out = child.wait_with_output().unwrap();
let text = String::from_utf8_lossy(&out.stdout).into_owned();
assert!(text.contains("\"count\":2"), "text={text}");
assert!(text.contains("客户留存率"), "text={text}");
}
+11
View File
@@ -0,0 +1,11 @@
---
title: label search fixture
---
# main
**x = [按关键词检索,接口未接,待开发](None)**
**y = [客户留存率,模拟](0.0)**
**z = [导出报表,示例](1)**
**w = [接口还在联调,先返回空](0)**
> print text=`x`