Artifact 18f9f7a5b8d8418e333387fc2b55a5539c950367ec4f74b1e7c5d8be38edb029:
- File
test/fuzz_curate.c
— part of check-in
[cef6a0ad45]
at
2026-11-17 07:37:01
on branch trunk
— suit curate writes a page for deciding what each asset is worth keeping
suit curate [--since DAYS] [--out FILE] runs a usage scan and writes one self-contained HTML page, mode 0600, atomically, to curate.html in suit's home folder or to FILE. It changes no wardrobe file, config, stamp or ledger. The page names projects and stays on this machine; it loads nothing from the network and has no inline handlers.
Each skill, agent and command in the wardrobes is a row: uses in the window and in each of the last four weeks, last used, the projects it was used in, its description and what that costs every session, where it is worn, whether it is in the attic, and whether it is the owner's or an upstream's. Origin comes from the entries of the check-in the upstream's record names, so an upstream's skills beside the owner's own in skills/ are told apart. A name in two wardrobes is tagged with its wardrobe.
Each row starts from a suggestion with its reason: retire when unused in the window, unless its files changed within it; limit when three or more uses all came from one known project; otherwise keep. A folder that is not a known project cannot be limited to, and the page says how to make it one. The owner picks keep, limit or retire per row, with keys or in bulk on what is shown, and copies or saves the choices as a short text file. Applying it is a separate step, not in this check-in. The format is in docs/curate.md: one line per asset, `keep KIND WARDROBE NAME`, `retire KIND WARDROBE NAME`, or `personal KIND WARDROBE NAME PROJECT`.
The page is src/curate.html, turned into a C array at build time with od and awk, so the release build needs no other tool. Values are written as JSON with markup characters, U+2028 and U+2029 escaped and invalid UTF-8 replaced. The page script has its own test, run under node where node is installed and reported as skipped elsewhere. A new fuzz target covers the front-matter reader and the JSON writer.
Page sizes: 37 KB for the test fixture, 252 KB for 500 assets, 805 KB at the 4096-asset bound.
A new suite, test/curate.sh, with 288 cases, is part of the gate.
2993 unit checks (was 2855), 620 shell cases, 1153 store cases, 846 placement cases, 378 project cases, 236 usage cases and 288 curate cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (66 minutes, on a loaded machine; one earlier run failed only the loaded speed measurement, at 1.06 to 1.11 ms, and this run passed it at 0.99 ms). 100% coverage in all 31 source files. No existing case was changed. (user: dmestas, size: 3130) [annotate] [blame] [check-ins using]
// Fuzz target for what `suit curate` reads out of a file it did not write: the // description in a front matter, cut to a length, and written as a JSON string. // Whatever the bytes: the description is at most as long as the input, ends in a // NUL, has its white space collapsed, and is cut on a character boundary; and the // JSON string is bounded by its buffer, holds no "<", ">", "&", control byte or // U+2028/2029, and is valid UTF-8. #include "curate.h" #include "platform.h" #include <stdint.h> #include <string.h> int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); // The length of the UTF-8 character at S, or 0, decided without the code under test. static size_t char_len(const uint8_t *s, size_t n) { if (s[0] < 0x80) return 1; size_t need = s[0] >= 0xF0 ? 4 : s[0] >= 0xE0 ? 3 : 2; if (s[0] < 0xC2 || s[0] > 0xF4 || n < need) return 0; uint32_t cp = s[0] & (need == 2 ? 0x1Fu : need == 3 ? 0x0Fu : 0x07u); for (size_t i = 1; i < need; i++) { if ((s[i] & 0xC0) != 0x80) return 0; cp = cp << 6 | (s[i] & 0x3Fu); } uint32_t min = need == 2 ? 0x80 : need == 3 ? 0x800 : 0x10000; return cp < min || cp > 0x10FFFF || (cp >= 0xD800 && cp <= 0xDFFF) ? 0 : need; } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { if (size > CURATE_HEAD_MAX) return 0; static char in[CURATE_HEAD_MAX + 1]; static char out[CURATE_HEAD_MAX + 2]; memcpy(in, data, size); size_t n = curate_front_description(in, size, out); ensure(n <= size); ensure(out[n] == '\0'); for (size_t i = 0; i < n; i++) { ensure(out[i] != '\t' && out[i] != '\r' && out[i] != '\n'); ensure(out[i] != ' ' || (i > 0 && i + 1 < n && out[i + 1] != ' ')); } size_t keep = curate_cut(out, n, CURATE_DESC_KEEP); ensure(keep <= n && keep <= CURATE_DESC_KEEP); ensure(keep == n || keep == 0 || ((uint8_t)out[keep] & 0xC0) != 0x80); // A buffer of a size taken from the input, with a guard behind it. static char json[8 * CURATE_DESC_KEEP + 64]; size_t cap = size % 64 == 0 ? sizeof json - 16 : size % 64; memset(json, 0xAA, sizeof json); CurateBuf b = {.p = json, .cap = cap}; curate_json_string(&b, out, keep); ensure(b.len <= cap); for (size_t i = cap; i < sizeof json; i++) ensure((uint8_t)json[i] == 0xAA); if (b.over) return 0; ensure(b.len >= 2 && json[0] == '"' && json[b.len - 1] == '"'); for (size_t i = 1; i + 1 < b.len;) { uint8_t c = (uint8_t)json[i]; ensure(c >= 0x20 && c != '<' && c != '>' && c != '&'); size_t l = char_len((const uint8_t *)json + i, b.len - 1 - i); ensure(l > 0); ensure(!(l == 3 && c == 0xE2 && json[i + 1] == (char)0x80 && ((uint8_t)json[i + 2] == 0xA8 || (uint8_t)json[i + 2] == 0xA9))); if (c == '\\') { // an escape: \" or \\ or \uXXXX, never a lone backslash ensure(i + 1 < b.len - 1); char e = json[i + 1]; ensure(e == '"' || e == '\\' || e == 'u'); i += e == 'u' ? 6 : 2; } else { i += l; } } return 0; }