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
|
//! Shape-CLASS gate for the native engine (this lane's translation of
//! the PORT-DESIGN stage gates, per AMENDMENT B: a DEVELOPMENT index,
//! class-level assertions, counts recorded as reference data only —
//! NEVER compared to production fixtures).
//!
//! Per shape, the expected class is derived from the parity harness
//! table `tests/search_parity.rs` (each entry below cites its
//! `shape!` line) plus the fixture's `recorded_status`:
//!
//! - `Match200` (recorded 200): the engine must return `Ok` with a hit
//! set — the DEV-INDEX COUNT IS PRINTED as reference data and never
//! compared to the production count (dev and production indexes
//! differ by design).
//! - `Error4xx` (recorded 4xx): the engine must return the typed parse
//! error `SearchError::InvalidQuery` (the blessed 422 contract).
//! - `Surface400` (Q48/Q49): route-level, zero engine calls — NOT run
//! here (pinned by the route tests).
//!
//! The lists are cumulative per stage, matching the parser
//! configuration at each commit:
//! - stage C3.1: free text, operators, phrase, wildcard, case,
//! unknown-prefix-as-text, the && shapes and the one parser-error
//! shape — Stem("en") + STEM_ALL_Z only;
//! - stage C3.2: + the boolean prefixes (author/species/group/tissue/
//! dataset/symbol/chr/peakchr) and the two mixed shapes;
//! - stage C3.3: + the probabilistic prefixes and aliases
//! (description/rif/wiki/RIF/WIKI);
//! - stage C3.4: + the numeric range prefixes (mean/peak/peakmb/
//! additive/year, slots 0/1/3/4/5) and the Q52 typed rejection
//! (`mean:abc..def` → InvalidQuery via the app-level guard — the
//! fork's decline→MatchNothing bridge swallows it at the parser
//! level, so the engine re-checks gn3's C++ NumberRangeProcessor
//! contract itself; see src/search/native.rs).
//! - stage C3.5: + the position/pos SI-suffix processor on slot 2
//! (Q32/Q33/Q34; Q53 `position:` is an empty value that parses as
//! free text), plus the POSABC probe row pinning the MatchNothing
//! bridge end-to-end: `position:abc` must parse and serve 200 with
//! 0 hits (the parity-metric amendment's safe default — never an
//! <INVALID> leaf, never a process abort).
//! - stage C3.6: + the Hs/Mm location processors (no liftover, OPEN-4)
//! and Q42's re-baselined class: an invalid location leaf (bad
//! chromosome form per search.py:179-201) surfaces as the engine's
//! InvalidQuery — the blessed 422 contract, detected by an app-level
//! guard BEFORE the mset call (no crash-mimicry, per AMENDMENT E).
//!
//! Env: `XAPIAN_DB_PATH` must point at the dev index (the gate runs
//! set it to ~/spikes/index-self-build/xapian-index); the test skips
//! loudly when unset so the hermetic suites stay green.
use genenetwork4::search::{Engine, SearchError, SearchHit, native::Native};
/// The recorded behavior class this gate asserts (see module doc).
#[derive(Clone, Copy, PartialEq, Eq)]
enum Class {
/// Recorded 200: parse + execute Ok, a hit set (any dev-index size).
Match200,
/// Recorded-200 class with a blessed EMPTY match set: parse +
/// execute Ok and zero hits (the MatchNothing bridge classes, e.g.
/// the `position:abc` verification probe of C3.5).
Match200Empty,
/// Recorded 4xx: typed parse rejection → InvalidQuery.
InvalidQuery,
}
fn variant_name(result: &Result<Vec<SearchHit>, SearchError>) -> &'static str {
match result {
Ok(_) => "Ok",
Err(SearchError::InvalidQuery { .. }) => "InvalidQuery",
Err(SearchError::Unreachable(_)) => "Unreachable",
Err(SearchError::Misbehaving(_)) => "Misbehaving",
Err(SearchError::Backend(_)) => "Backend",
Err(SearchError::Internal(_)) => "Internal",
}
}
/// (id, raw query, forwarded type, expected class, citation into
/// tests/search_parity.rs).
const SHAPES: &[(&str, &str, &str, Class)] = &[
// ---- stage C3.1: free text, operators, phrase, unknown prefixes ----
("Q01", "alcohol", "phenotype", Class::Match200), // parity.rs:112
("Q03", "alcohol dependence", "phenotype", Class::Match200), // parity.rs:121
(
"Q04",
"\"alcohol dependence\"",
"phenotype",
Class::Match200,
), // parity.rs:129
("Q05", "alcohol*", "phenotype", Class::Match200), // parity.rs:137
("Q06", "Alcohol", "phenotype", Class::Match200), // parity.rs:145
(
"Q07",
"alcohol AND dependence",
"phenotype",
Class::Match200,
), // parity.rs:153
("Q08", "alcohol OR dependence", "phenotype", Class::Match200), // parity.rs:161
(
"Q09",
"alcohol NOT dependence",
"phenotype",
Class::Match200,
), // parity.rs:169
(
"Q10",
"alcohol XOR dependence",
"phenotype",
Class::Match200,
), // parity.rs:177
(
"Q11",
"alcohol NEAR dependence",
"phenotype",
Class::Match200,
), // parity.rs:185
(
"Q12",
"alcohol ADJ dependence",
"phenotype",
Class::Match200,
), // parity.rs:193
(
"Q13",
"alcohol and dependence",
"phenotype",
Class::Match200,
), // parity.rs:201
// The && shapes are recorded 200s under libxapian 1.4.29 and live
// production (harness-report §4 F2/F4; binding-report R1)…
("Q47", "a&&b", "phenotype", Class::Match200), // parity.rs:459
// …while the truncated AND is the recorded 4xx (Q51.json).
("Q51", "alcohol AND", "phenotype", Class::InvalidQuery), // parity.rs:477
// An unregistered prefix parses as free text.
("Q50", "foo:bar", "phenotype", Class::Match200), // parity.rs:469
("Q54", "alcohol &&", "phenotype", Class::Match200), // parity.rs:501
// ---- stage C3.2: boolean prefixes (author/species/group/tissue/
// dataset/symbol/chr/peakchr + the two mixed shapes) ----
("Q14", "author:mulligan", "phenotype", Class::Match200), // parity.rs:209
("Q15", "species:mouse", "phenotype", Class::Match200), // parity.rs:217
("Q16", "group:B6", "phenotype", Class::Match200), // parity.rs:225
("Q17", "group:b6", "phenotype", Class::Match200), // parity.rs:233
("Q18", "tissue:brain", "phenotype", Class::Match200), // parity.rs:241
("Q19", "dataset:bxdpublish", "phenotype", Class::Match200), // parity.rs:249
("Q20", "symbol:insr", "gene", Class::Match200), // parity.rs:257
("Q26", "chr:m", "gene", Class::Match200), // parity.rs:305
("Q27", "peakchr:1", "phenotype", Class::Match200), // parity.rs:306
("Q43", "species:mouse alcohol", "phenotype", Class::Match200), // parity.rs:427
(
"Q46",
"(alcohol OR insulin) AND species:mouse",
"phenotype",
Class::Match200,
), // parity.rs:451
// ---- stage C3.3: probabilistic prefixes + uppercase aliases ----
// Corpus-lane note: on the DEPLOYED production index XD is
// unpopulated (Q21 documented-empty) while rif: has real hits on
// the dev index (RDF crawl); class-level assertions either way,
// counts printed as dev reference only.
("Q21", "description:insulin", "phenotype", Class::Match200), // parity.rs:265
("Q22", "rif:insulin", "gene", Class::Match200), // parity.rs:273
("Q23", "RIF:insulin", "gene", Class::Match200), // parity.rs:281
("Q24", "wiki:diabetes", "phenotype", Class::Match200), // parity.rs:289
("Q25", "WIKI:diabetes", "phenotype", Class::Match200), // parity.rs:297
("Q45", "symbol:insr OR rif:insulin", "gene", Class::Match200), // parity.rs:443
// ---- stage C3.4: numeric range prefixes (mean=0, peak=1,
// peakmb=3, additive=4, year=5; search.py:234-243) ----
("Q28", "mean:10..20", "phenotype", Class::Match200), // parity.rs:313
("Q29", "mean:..15", "phenotype", Class::Match200), // parity.rs:321
("Q30", "mean:10..", "phenotype", Class::Match200), // parity.rs:329
("Q31", "peak:5..15", "phenotype", Class::Match200), // parity.rs:337
("Q35", "peakmb:1.5..2.5", "phenotype", Class::Match200), // parity.rs:369
("Q36", "additive:0.5..1.0", "phenotype", Class::Match200), // parity.rs:377
("Q37", "year:2010..2020", "phenotype", Class::Match200), // parity.rs:385
("Q38", "year:2030..2050", "phenotype", Class::Match200), // parity.rs:393
("Q39", "mean:99999..100000", "phenotype", Class::Match200), // parity.rs:401
(
"Q44",
"author:mulligan AND year:2010..2015",
"phenotype",
Class::Match200,
), // parity.rs:435
// The typed parse-rejection shape: recorded production 400
// "Unknown range operation" → 422 invalid_query.
("Q52", "mean:abc..def", "phenotype", Class::InvalidQuery), // parity.rs:485
// ---- stage C3.5: position/pos SI-suffix processor (slot 2,
// search.py:237-241, 145-165) ----
("Q32", "position:1.05M..1.06M", "gene", Class::Match200), // parity.rs:371
("Q33", "position:7500000", "gene", Class::Match200), // parity.rs:379
("Q34", "pos:1.05M..1.06M", "gene", Class::Match200), // parity.rs:387
// Q53 `position:`: the empty value never reaches the processor —
// xapian parses it as free text (recorded production 200 with 576
// hits; dev count printed as reference).
("Q53", "position:", "phenotype", Class::Match200), // parity.rs:518
// C3.5 verification probe (not a corpus shape): an unparseable
// position must NOT process-abort — it declines to the bridge's
// MatchNothing and serves 200 with 0 hits (parity-metric
// amendment; fork commit aa915af verified end-to-end).
("POSABC", "position:abc", "phenotype", Class::Match200Empty), // parity-metric.md amendment 2026-10-06
// ---- stage C3.6: Hs/Mm location processors, no liftover (OPEN-4) ----
("Q40", "Hs:chr2:1M..1.2M", "gene", Class::Match200), // parity.rs:435
("Q41", "Mm:chr1:5M", "gene", Class::Match200), // parity.rs:442
// Q42's class: the recorded production 500 (mset-time
// InvalidOperationError) is re-baselined to the blessed 422 — the
// engine's app-level guard detects the invalid location leaf
// before any mset call and reports InvalidQuery (AMENDMENT E).
("Q42", "Hs:foo:1M", "phenotype", Class::InvalidQuery), // parity.rs:444
];
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn native_engine_shape_class_gate() {
let dev_index = std::env::var("XAPIAN_DB_PATH").unwrap_or_default();
if dev_index.is_empty()
|| !std::fs::metadata(&dev_index)
.map(|m| m.is_dir())
.unwrap_or(false)
{
eprintln!(
"SKIPPED: XAPIAN_DB_PATH is not set to an index directory \
(set it to the dev index for the shape-class gate)"
);
return;
}
eprintln!("shape-class gate against dev index: {dev_index}");
let mut passed = 0usize;
let mut failed = Vec::new();
for (id, query, type_, expected) in SHAPES {
let result = Native.search(query, type_, 100, 1).await;
match (expected, &result) {
(Class::Match200, Ok(hits)) => {
// Dev-index counts are REFERENCE DATA ONLY (AMENDMENT B):
// printed, never compared to production counts.
eprintln!(
" {id} q={query:?} type={type_} class=Match200 dev_hits={}",
hits.len()
);
passed += 1;
}
(Class::Match200Empty, Ok(hits)) => {
if hits.is_empty() {
eprintln!(" {id} q={query:?} type={type_} class=Match200Empty dev_hits=0");
passed += 1;
} else {
eprintln!(
" {id} q={query:?} type={type_} UNEXPECTED Match200Empty with {} hits",
hits.len()
);
failed.push(*id);
}
}
(Class::InvalidQuery, Err(SearchError::InvalidQuery { message, .. })) => {
eprintln!(" {id} q={query:?} type={type_} class=InvalidQuery detail={message:?}");
passed += 1;
}
_ => {
eprintln!(
" {id} q={query:?} type={type_} UNEXPECTED outcome={}",
variant_name(&result)
);
failed.push(*id);
}
}
}
let summary = if failed.is_empty() {
"stages C3.1 + C3.2 + C3.3 + C3.4 + C3.5 + C3.6".to_string()
} else {
format!("FAILED: {failed:?}")
};
eprintln!(
"SHAPE-CLASS GATE: {passed}/{} PASS ({summary})",
SHAPES.len()
);
assert!(
failed.is_empty(),
"shape-class gate failures: {failed:?} (expected classes per tests/search_parity.rs)"
);
}
|