nx_ingest_batch_test.nx source
↩ module page · 86 lines · 3950 B
1// nx_ingest_batch_test.nx -- smoke for the bits-up ingestion SYSTEM.
2//
3// Runs the batch driver over ../../nishi-library/fixtures/gbif/
4// with suffix ".raw" + emits ingested_system.jsonl. No upstream-
5// source-specific code in this test or the driver -- the JSON shape
6// is discovered at parse time and emitted flat.
7
8import "syscalls.nx"
9import "nx_ingest_batch.nx"
10
11const NX_TEST_NOW_UNIX: i64 = 1747436400
12
13func make_dir_path(out: *u8) -> i64 {
14 // "../../nishi-library/fixtures/gbif" (33 bytes, no trailing slash)
15 out[0] = 0x2E; out[1] = 0x2E; out[2] = 0x2F
16 out[3] = 0x2E; out[4] = 0x2E; out[5] = 0x2F
17 out[6] = 0x6E; out[7] = 0x69; out[8] = 0x73; out[9] = 0x68
18 out[10] = 0x69; out[11] = 0x2D; out[12] = 0x6C; out[13] = 0x69
19 out[14] = 0x62; out[15] = 0x72; out[16] = 0x61; out[17] = 0x72
20 out[18] = 0x79; out[19] = 0x2F
21 out[20] = 0x66; out[21] = 0x69; out[22] = 0x78; out[23] = 0x74
22 out[24] = 0x75; out[25] = 0x72; out[26] = 0x65; out[27] = 0x73
23 out[28] = 0x2F
24 out[29] = 0x67; out[30] = 0x62; out[31] = 0x69; out[32] = 0x66
25 out[33] = 0
26 return 33
27}
28
29func make_out_path(out: *u8) -> i64 {
30 // "../../nishi-library/fixtures/gbif/ingested_system.jsonl" (55 bytes)
31 out[0] = 0x2E; out[1] = 0x2E; out[2] = 0x2F
32 out[3] = 0x2E; out[4] = 0x2E; out[5] = 0x2F
33 out[6] = 0x6E; out[7] = 0x69; out[8] = 0x73; out[9] = 0x68
34 out[10] = 0x69; out[11] = 0x2D; out[12] = 0x6C; out[13] = 0x69
35 out[14] = 0x62; out[15] = 0x72; out[16] = 0x61; out[17] = 0x72
36 out[18] = 0x79; out[19] = 0x2F
37 out[20] = 0x66; out[21] = 0x69; out[22] = 0x78; out[23] = 0x74
38 out[24] = 0x75; out[25] = 0x72; out[26] = 0x65; out[27] = 0x73
39 out[28] = 0x2F
40 out[29] = 0x67; out[30] = 0x62; out[31] = 0x69; out[32] = 0x66
41 out[33] = 0x2F
42 out[34] = 0x69; out[35] = 0x6E; out[36] = 0x67; out[37] = 0x65
43 out[38] = 0x73; out[39] = 0x74; out[40] = 0x65; out[41] = 0x64
44 out[42] = 0x5F // "_"
45 out[43] = 0x73; out[44] = 0x79; out[45] = 0x73; out[46] = 0x74
46 out[47] = 0x65; out[48] = 0x6D // "system"
47 out[49] = 0x2E; out[50] = 0x6A; out[51] = 0x73; out[52] = 0x6F
48 out[53] = 0x6E; out[54] = 0x6C // ".jsonl"
49 out[55] = 0
50 return 55
51}
52
53func main() -> i64 {
54 let dpath: *u8 = sys_mmap(64)
55 let dlen: i64 = make_dir_path(dpath)
56 let opath: *u8 = sys_mmap(64)
57 make_out_path(opath)
58
59 // Empty suffix: accept all regular files; let internal
60 // dispatch route by extension (.raw / .json -> json parser,
61 // .csv -> csv parser, .tsv -> tsv parser).
62 let sfx: *u8 = sys_mmap(8)
63 sfx[0] = 0
64
65 let rep_raw: *u8 = sys_mmap(NX_INGEST_REPORT_BYTES)
66 let rep: *NxIngestReport = rep_raw as *NxIngestReport
67
68 let v: i64 = nx_ingest_batch_run(
69 dpath, dlen, sfx, 0, opath, rep, NX_TEST_NOW_UNIX)
70
71 if v != NX_INGEST_OK { return __syscall(93, 1, 0, 0, 0, 0, 0) }
72 if rep.verdict != NX_INGEST_OK { return __syscall(93, 2, 0, 0, 0, 0, 0) }
73 // At least 2 fixtures exist (Solanum + Apis); more as we add more.
74 if rep.files_matched < 2 { return __syscall(93, 3, 0, 0, 0, 0, 0) }
75 if rep.parses_ok < 2 { return __syscall(93, 4, 0, 0, 0, 0, 0) }
76 if rep.rows_emitted < 2 { return __syscall(93, 5, 0, 0, 0, 0, 0) }
77 if rep.parses_failed != 0 { return __syscall(93, 6, 0, 0, 0, 0, 0) }
78 // Every match must parse successfully. Rows emitted may EXCEED
79 // parses_ok because CSV files contribute one row per inner OBJECT.
80 if rep.files_matched != rep.parses_ok { return __syscall(93, 7, 0, 0, 0, 0, 0) }
81 if rep.rows_emitted < rep.parses_ok { return __syscall(93, 8, 0, 0, 0, 0, 0) }
82 if rep.bytes_total_read < 800 { return __syscall(93, 9, 0, 0, 0, 0, 0) }
83 if rep.bytes_total_written < 200 { return __syscall(93, 10, 0, 0, 0, 0, 0) }
84
85 return 0
86}