Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
tests: byte-exact .coli_ssd fixtures; pin CRLF rejection in the shared vectors (#379)
monotophic0d15ba29b0f2
diff --git a/c/colibri.c b/c/colibri.cindex 448419a0..acae9772 100644--- a/c/colibri.c+++ b/c/colibri.c@@ -7831,7 +7831,8 @@ static double coli_ssd_probe_cached(const char *snap_dir){snprintf(cpath,sizeof(cpath),"%s/.coli_ssd",snap_dir);struct stat dst;unsigned long long cur_dev = stat(snap_dir,&dst)==0 ? (unsigned long long)dst.st_dev : 0;- FILE *f=fopen(cpath,"r");+ FILE *f=fopen(cpath,"rb"); /* exact bytes: never let a text-mode+ * layer eat the \r the grammar rejects */if(f){char buf[COLI_SSD_CACHE_MAX+2];size_t n=fread(buf,1,sizeof(buf),f);diff --git a/c/tests/fixtures/ssd_cache_vectors.txt b/c/tests/fixtures/ssd_cache_vectors.txtindex 29c95932..50536b3a 100644--- a/c/tests/fixtures/ssd_cache_vectors.txt+++ b/c/tests/fixtures/ssd_cache_vectors.txt@@ -36,6 +36,9 @@ garbage 9.5\s\ngarbage 9.5\t\ngarbage 9.5\r\ngarbage 9.5\n\n+# CRLF is not a line ending here -- the format is exact bytes, and a Windows+# text-mode writer once smuggled \r into fixtures (CI, 2026-07): pinned forever+garbage v2 14.322 123\r\n# --- garbage: strtod-isms the strict grammar bans ------------------------garbage inf\ngarbage -inf\ndiff --git a/c/tests/test_doctor.py b/c/tests/test_doctor.pyindex 5d46fe8f..97f933d8 100644--- a/c/tests/test_doctor.py+++ b/c/tests/test_doctor.py@@ -157,7 +157,9 @@ class DoctorTest(unittest.TestCase):self.assertEqual(checks["storage.ssd_probe"]["status"], "skip")def test_ssd_probe_check_passes_and_reports_cached_value(self):- (self.model / ".coli_ssd").write_text(f"v2 14.3 {os.stat(self.model).st_dev}\n")+ # byte-exact (write_bytes): Windows text mode would CRLF-translate and the+ # strict reader would (correctly) reject the fixture as garbage+ (self.model / ".coli_ssd").write_bytes(f"v2 14.3 {os.stat(self.model).st_dev}\n".encode("ascii"))checks = self.checks_by_id(self.report())self.assertEqual(checks["storage.ssd_probe"]["status"], "pass")self.assertEqual(checks["storage.ssd_probe"]["details"]["gbs"], 14.3)@@ -165,13 +167,13 @@ class DoctorTest(unittest.TestCase):def test_ssd_probe_wording_names_why_a_cache_is_pending(self):# #386 r2, F10: "no cached probe yet" is a lie when a file exists --# each untrusted state names what will actually happen instead.- cases = (- ("14.3\n", "legacy cache pending engine upgrade"),- (f"v2 14.3 {os.stat(self.model).st_dev + 1}\n", "cache from another volume"),- ("not-a-number\n", "unreadable cache"),+ cases = ( # byte-exact fixtures: no text-mode CRLF on Windows+ (b"14.3\n", "legacy cache pending engine upgrade"),+ (f"v2 14.3 {os.stat(self.model).st_dev + 1}\n".encode("ascii"), "cache from another volume"),+ (b"not-a-number\n", "unreadable cache"),)for content, expected in cases:- (self.model / ".coli_ssd").write_text(content)+ (self.model / ".coli_ssd").write_bytes(content)check = self.checks_by_id(self.report())["storage.ssd_probe"]self.assertEqual(check["status"], "skip", content)self.assertIn(expected, check["summary"], content)@@ -185,7 +187,7 @@ class DoctorTest(unittest.TestCase):# it as the bare literal Infinity, which is not JSON -- machine# consumers of `coli doctor --json` would then fail to parse the whole# report. The strict v2 grammar bans inf/nan outright (#386 fix round).- (self.model / ".coli_ssd").write_text("inf\n")+ (self.model / ".coli_ssd").write_bytes(b"inf\n")report = self.report()checks = self.checks_by_id(report)self.assertEqual(checks["storage.ssd_probe"]["status"], "skip")diff --git a/c/tests/test_resource_plan.py b/c/tests/test_resource_plan.pyindex 32c208d0..c5a3fac9 100644--- a/c/tests/test_resource_plan.py+++ b/c/tests/test_resource_plan.py@@ -84,7 +84,9 @@ class ResourcePlanTest(unittest.TestCase):def _write_v2_cache(self, gbs="14.322", dev=None):if dev is None:dev = os.stat(self.model).st_dev- (self.model / ".coli_ssd").write_text(f"v2 {gbs} {dev}\n")+ # byte-exact: text mode would CRLF-translate on Windows and the strict+ # reader would (correctly) reject the fixture as garbage+ (self.model / ".coli_ssd").write_bytes(f"v2 {gbs} {dev}\n".encode("ascii"))def test_ssd_probe_missing_file_returns_none(self):self.assertIsNone(read_ssd_probe(self.model))@@ -103,15 +105,15 @@ class ResourcePlanTest(unittest.TestCase):# Pre-v2 caches were written before cold-range steering existed, so the# value may be page-cache contamination; the engine re-probes and# upgrades, and until then there is no number worth surfacing.- (self.model / ".coli_ssd").write_text("14.322\n")+ (self.model / ".coli_ssd").write_bytes(b"14.322\n")self.assertIsNone(read_ssd_probe(self.model))def test_ssd_probe_unparsable_file_returns_none(self):- (self.model / ".coli_ssd").write_text("not-a-number\n")+ (self.model / ".coli_ssd").write_bytes(b"not-a-number\n")self.assertIsNone(read_ssd_probe(self.model))def test_ssd_probe_empty_file_returns_none(self):- (self.model / ".coli_ssd").write_text("")+ (self.model / ".coli_ssd").write_bytes(b"")self.assertIsNone(read_ssd_probe(self.model))def test_ssd_probe_grammar_matches_c_reader_vectors(self):@@ -160,9 +162,9 @@ class ResourcePlanTest(unittest.TestCase):self.assertEqual(ssd_probe_state(self.model), ("ok", 14.322))self._write_v2_cache("14.322", dev=os.stat(self.model).st_dev + 1)self.assertEqual(ssd_probe_state(self.model), ("foreign", None))- (self.model / ".coli_ssd").write_text("14.322\n")+ (self.model / ".coli_ssd").write_bytes(b"14.322\n")self.assertEqual(ssd_probe_state(self.model), ("legacy", None))- (self.model / ".coli_ssd").write_text("inf\n")+ (self.model / ".coli_ssd").write_bytes(b"inf\n")self.assertEqual(ssd_probe_state(self.model), ("garbage", None))def test_ssd_probe_surfaces_in_plan_and_format(self):@@ -173,7 +175,7 @@ class ResourcePlanTest(unittest.TestCase):self.assertIn("14.3 GB/s", format_plan(plan))def test_ssd_probe_pending_states_surface_in_format(self):- (self.model / ".coli_ssd").write_text("14.3\n") # legacy+ (self.model / ".coli_ssd").write_bytes(b"14.3\n") # legacyplan = build_plan(self.model, available_memory=16 * GB, available_disk=1)self.assertIsNone(plan["ssd_probe_gbs"])self.assertEqual(plan["ssd_probe_state"], "legacy")diff --git a/c/tests/test_ssd_probe.c b/c/tests/test_ssd_probe.cindex 589a5de6..0a16a6b3 100644--- a/c/tests/test_ssd_probe.c+++ b/c/tests/test_ssd_probe.c@@ -212,14 +212,14 @@ static void run_steering(void){#ifdef __APPLE__static void write_file(const char *dir, const char *name, const char *data){char p[1400]; snprintf(p,sizeof(p),"%s/%s",dir,name);- FILE *f=fopen(p,"w");+ FILE *f=fopen(p,"wb"); /* exact bytes -- these fixtures feed a strict parser */if(!f){ perror(p); failures++; return; }fputs(data,f); fclose(f);}static int read_file(const char *dir, const char *name, char *out, size_t outsz){char p[1400]; snprintf(p,sizeof(p),"%s/%s",dir,name);- FILE *f=fopen(p,"r");+ FILE *f=fopen(p,"rb");if(!f) return -1;size_t n=fread(out,1,outsz-1,f); out[n]=0; fclose(f);return (int)n;@@ -266,7 +266,7 @@ static void run_cached_decisions(void){* write any .coli_ssd */{char p[1400]; snprintf(p,sizeof(p),"%s/out-00000.safetensors",dirbuf);- FILE *f=fopen(p,"w");+ FILE *f=fopen(p,"wb");if(f){char *mb=malloc(1024*1024);memset(mb,0xA5,1024*1024);