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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
//! Strict schema contract: entity and relation surface — delete-entity, reclassify, merge-entities, memory-entities, prune-ner, rename-entity, deep-research, reclassify-relation, normalize-entities, enrich.
//!
//! Part of the strict JSON-Schema contract suite split by GAP-SG-208. Each
//! test runs the binary, captures stdout, parses it as JSON and validates it
//! against the published `docs/schemas/*.schema.json`. The shared harness lives
//! in `tests/schema_support/`.
//!
//! NOT gated behind `slow-tests`, unlike the 29 other heavy test files, because
//! this suite is the only thing that compares the binary's REAL stdout against
//! the published contract. GAP-SG-271 measured what the gate cost while it was
//! on: five files sat behind the feature, `cargo test` never compiled them, and
//! the published schemas drifted with nothing to notice. A gate the default
//! invocation never runs is not a gate — it is a gate-shaped reassurance.
//!
//! The attribute must never move back into `tests/schema_support/mod.rs`: a
//! shared `mod.rs` that cfg-es itself out does not become empty, it VANISHES
//! from the module graph, so every `use support::…` fails to resolve and the
//! whole test build breaks.
#[path = "schema_support/mod.rs"]
mod support;
use serde_json::Value;
use serial_test::serial;
use support::{validate_schema, Env};
// ---------------------------------------------------------------------------
// 30 — delete-entity
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_30_delete_entity() {
let env = Env::new();
env.init();
let (ent_a, _ent_b) = env.remember_with_entities("del-ent-schema");
let output = env
.cmd()
.args(["delete-entity", "--name", &ent_a, "--cascade"])
.output()
.expect("delete-entity failed");
assert!(
output.status.success(),
"delete-entity: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "delete-entity");
validate_schema(
"delete-entity",
include_str!("../docs/schemas/delete-entity.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 31 — reclassify
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_31_reclassify() {
let env = Env::new();
env.init();
let (ent_a, _ent_b) = env.remember_with_entities("reclass-schema");
let output = env
.cmd()
.args(["reclassify", "--name", &ent_a, "--new-type", "tool"])
.output()
.expect("reclassify failed");
assert!(
output.status.success(),
"reclassify: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "reclassify");
validate_schema(
"reclassify",
include_str!("../docs/schemas/reclassify.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 32 — merge-entities
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_32_merge_entities() {
let env = Env::new();
env.init();
let (ent_a, ent_b) = env.remember_with_entities("merge-schema");
let output = env
.cmd()
.args(["merge-entities", "--names", &ent_a, "--into", &ent_b])
.output()
.expect("merge-entities failed");
assert!(
output.status.success(),
"merge-entities: exit {:?}\nstdout: {}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
let instance = Env::parse_stdout(&output, "merge-entities");
validate_schema(
"merge-entities",
include_str!("../docs/schemas/merge-entities.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 33 — memory-entities
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_33_memory_entities() {
let env = Env::new();
env.init();
env.remember_with_entities("mem-ent-schema");
let output = env
.cmd()
.args(["memory-entities", "--name", "mem-ent-schema"])
.output()
.expect("memory-entities failed");
assert!(
output.status.success(),
"memory-entities: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "memory-entities");
validate_schema(
"memory-entities",
include_str!("../docs/schemas/memory-entities.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 33b — memory-entities reverse lookup (--entity)
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_33b_memory_entities_reverse() {
let env = Env::new();
env.init();
let (ent_a, _ent_b) = env.remember_with_entities("mem-ent-rev-schema");
let output = env
.cmd()
.args(["memory-entities", "--entity", &ent_a])
.output()
.expect("memory-entities --entity failed");
assert!(
output.status.success(),
"memory-entities --entity: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "memory-entities --entity");
validate_schema(
"memory-entities-reverse",
include_str!("../docs/schemas/memory-entities-reverse.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 34 — prune-ner
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_34_prune_ner() {
let env = Env::new();
env.init();
let (ent_a, _ent_b) = env.remember_with_entities("prune-schema");
let output = env
.cmd()
.args(["prune-ner", "--entity", &ent_a, "--dry-run"])
.output()
.expect("prune-ner failed");
assert!(
output.status.success(),
"prune-ner: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "prune-ner");
validate_schema(
"prune-ner",
include_str!("../docs/schemas/prune-ner.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 35 — rename-entity
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_35_rename_entity() {
let env = Env::new();
env.init();
let (ent_a, _ent_b) = env.remember_with_entities("rename-ent-schema");
let new_name = format!("{ent_a}-renamed");
let output = env
.cmd()
// rename-entity re-embeds the renamed entity; without a live key that
// would abort with exit 11 before any schema could be validated.
.args([
"--llm-backend",
"none",
"rename-entity",
"--name",
&ent_a,
"--new-name",
&new_name,
])
.output()
.expect("rename-entity failed");
assert!(
output.status.success(),
"rename-entity: exit {:?}",
output.status.code()
);
let instance = Env::parse_stdout(&output, "rename-entity");
validate_schema(
"rename-entity",
include_str!("../docs/schemas/rename-entity.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 36 — deep-research
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_36_deep_research() {
let env = Env::new();
env.init();
env.remember_simple("schema36-mem-a");
env.remember_simple("schema36-mem-b");
let output = env
.cmd()
.args([
"deep-research",
"auth and deploy",
"--max-sub-queries",
"2",
"--k",
"5",
])
.output()
.expect("deep-research failed");
assert!(
output.status.success(),
"deep-research: exit {:?}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stderr)
);
let instance = Env::parse_stdout(&output, "deep-research");
validate_schema(
"deep-research",
include_str!("../docs/schemas/deep-research.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 37 — reclassify-relation
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_37_reclassify_relation() {
let env = Env::new();
env.init();
let (ent_a, ent_b) = env.remember_with_entities("schema37-reclassify-rel");
// Link entities with a 'mentions' relation to give the command something to work with.
let _ = env
.cmd()
.args([
"link",
"--from",
&ent_a,
"--to",
&ent_b,
"--relation",
"mentions",
])
.output()
.expect("link failed");
// Dry-run: safe, validates JSON contract without committing.
let output = env
.cmd()
.args([
"reclassify-relation",
"--from-relation",
"mentions",
"--to-relation",
"related",
"--batch",
"--dry-run",
])
.output()
.expect("reclassify-relation failed");
assert!(
output.status.success(),
"reclassify-relation: exit {:?}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stderr)
);
let instance = Env::parse_stdout(&output, "reclassify-relation");
validate_schema(
"reclassify-relation",
include_str!("../docs/schemas/reclassify-relation.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 38 — normalize-entities
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_38_normalize_entities() {
let env = Env::new();
env.init();
env.remember_simple("schema38-normalize-ent");
// Dry-run: validates JSON contract without modifying data.
let output = env
.cmd()
.args(["normalize-entities", "--dry-run"])
.output()
.expect("normalize-entities failed");
assert!(
output.status.success(),
"normalize-entities: exit {:?}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stderr)
);
let instance = Env::parse_stdout(&output, "normalize-entities");
validate_schema(
"normalize-entities",
include_str!("../docs/schemas/normalize-entities.schema.json"),
&instance,
);
}
// ---------------------------------------------------------------------------
// 39 — enrich (dry-run, NDJSON: validate each line type against its schema)
// ---------------------------------------------------------------------------
#[test]
#[serial]
fn schema_39_enrich() {
let env = Env::new();
env.init();
env.remember_simple("schema39-enrich-mem");
let output = env
.cmd()
.args([
"enrich",
"--operation",
"memory-bindings",
// `--mode codex` stopped parsing when the codex backend was removed;
// `--dry-run` plans without an LLM, so it needs no mode at all and
// no API key.
"--dry-run",
])
.output()
.expect("enrich failed");
assert!(
output.status.success(),
"enrich: exit {:?}\nstderr: {}",
output.status.code(),
String::from_utf8_lossy(&output.stderr)
);
let stdout_str = String::from_utf8_lossy(&output.stdout);
let lines: Vec<&str> = stdout_str
.lines()
.filter(|l| !l.trim().is_empty())
.collect();
assert!(
!lines.is_empty(),
"enrich must emit at least one NDJSON line"
);
let phase_schema_str = include_str!("../docs/schemas/enrich-phase.schema.json");
let item_schema_str = include_str!("../docs/schemas/enrich-item-event.schema.json");
let summary_schema_str = include_str!("../docs/schemas/enrich-summary.schema.json");
let mut summary_found = false;
for line in &lines {
let val: Value = serde_json::from_str(line)
.unwrap_or_else(|e| panic!("enrich NDJSON line not valid JSON: {e}\n{line}"));
if val["summary"] == true {
validate_schema("enrich-summary", summary_schema_str, &val);
summary_found = true;
} else if val.get("phase").is_some() {
validate_schema("enrich-phase", phase_schema_str, &val);
} else if val.get("item").is_some() {
validate_schema("enrich-item", item_schema_str, &val);
}
// Lines from non-implemented operations include "operation" key — skip gracefully.
}
assert!(summary_found, "enrich must emit a summary line");
}