1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
use assert_cmd::Command;
use serial_test::serial;
use tempfile::TempDir;
/// Builds a fresh `Command` with the mock LLM PATH prepended.
///
/// v1.0.76 spawns `claude` or `codex` on every `remember` / `ingest` /
/// `edit`. The bundled mocks under `tests/mock-llm/` return a fixed
/// 64-dim zero vector so the binary finishes without a real OAuth
/// login. The mock directory is leaked (no TempDir cleanup) so the
/// spawned subprocess always finds the mocks.
fn sgr_cmd() -> Command {
let mock_dir = common::mock_llm_path();
let mut c = Command::cargo_bin("sqlite-graphrag").expect("sqlite-graphrag binary not found");
c.env("PATH", common::prepend_path(&mock_dir));
c
}
#[path = "common/mod.rs"]
mod common;
fn cmd_base(tmp: &TempDir) -> Command {
let mut c = sgr_cmd();
c.env("SQLITE_GRAPHRAG_DB_PATH", tmp.path().join("test.sqlite"));
c.env("SQLITE_GRAPHRAG_CACHE_DIR", tmp.path().join("cache"));
c.env("SQLITE_GRAPHRAG_LOG_LEVEL", "error");
c.arg("--skip-memory-guard");
c
}
fn init_db(tmp: &TempDir) {
cmd_base(tmp).arg("init").assert().success();
}
fn create_entity(tmp: &TempDir, name: &str) {
cmd_base(tmp)
.args([
"link",
"--from",
name,
"--to",
"e2e-anchor-entity",
"--relation",
"related",
"--create-missing",
])
.assert()
.success();
}
#[test]
#[serial]
fn entity_name_too_short_rejected_via_link() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd_base(&tmp)
.args([
"link",
"--from",
"x",
"--to",
"valid-entity",
"--relation",
"uses",
"--create-missing",
])
.assert()
.failure();
}
#[test]
#[serial]
fn entity_name_all_caps_short_rejected_via_link_v1088() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
// ADR-0046 / BUG-13 v1.0.88: link --create-missing now validates the
// ORIGINAL args.from BEFORE normalization, so short ALL_CAPS names
// (≤4 chars, all uppercase) are rejected even though normalize would
// produce "ram". This restores parity with rename-entity and remember
// --graph-stdin which already validated the original.
cmd_base(&tmp)
.args([
"link",
"--from",
"RAM",
"--to",
"valid-entity",
"--relation",
"uses",
"--create-missing",
])
.assert()
.failure();
}
#[test]
#[serial]
fn entity_name_valid_passes_via_link() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd_base(&tmp)
.args([
"link",
"--from",
"valid-name",
"--to",
"valid-target",
"--relation",
"uses",
"--create-missing",
])
.assert()
.success();
}
#[test]
#[serial]
fn rename_entity_rejects_short_new_name() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
create_entity(&tmp, "rename-source-entity");
cmd_base(&tmp)
.args([
"rename-entity",
"--name",
"rename-source-entity",
"--new-name",
"z",
])
.assert()
.failure();
}
#[test]
#[serial]
fn rename_entity_rejects_all_caps_short_new_name() {
let tmp = TempDir::new().unwrap();
init_db(&tmp);
create_entity(&tmp, "rename-caps-entity");
cmd_base(&tmp)
.args([
"rename-entity",
"--name",
"rename-caps-entity",
"--new-name",
"WAL",
])
.assert()
.failure();
}
#[test]
#[serial]
fn link_rejects_all_caps_short_to_arg_v1088() {
// ADR-0046 / BUG-13 v1.0.88: --to side must also validate the original
// before normalize, otherwise "--to API" would silently create entity "api".
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd_base(&tmp)
.args([
"link",
"--from",
"valid-source",
"--to",
"API",
"--relation",
"uses",
"--create-missing",
])
.assert()
.failure();
}
#[test]
#[serial]
fn link_rejects_four_char_all_caps_v1088() {
// ADR-0046 / BUG-13 v1.0.88: 4-char ALL_CAPS ("RUST") must also be rejected.
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd_base(&tmp)
.args([
"link",
"--from",
"RUST",
"--to",
"valid-target",
"--relation",
"uses",
"--create-missing",
])
.assert()
.failure();
}
#[test]
#[serial]
fn link_accepts_five_char_all_caps_v1088() {
// ADR-0046 / BUG-13 v1.0.88: 5+ char ALL_CAPS passes (e.g. "RUSTC", "LLMDS").
let tmp = TempDir::new().unwrap();
init_db(&tmp);
cmd_base(&tmp)
.args([
"link",
"--from",
"RUSTC",
"--to",
"valid-target",
"--relation",
"uses",
"--create-missing",
])
.assert()
.success();
}