logstat regenerated: the worker’s report
Every function body in examples/programs/logstat/ was written again from the modules’
intents, types, signatures, contracts, and tests, against
mo-wiki/spec/programs/02-log-analyzer.md. The tests were not touched.
Done-when
mo checkclean onparse.mo,stats.mo,report.mo,main.mo.mo test: 6 + 10 + 7 + 8 = 31 passed, 0 failed, 0 skipped;mo test --all main.mois 31 too. The same counts undermo test --sim 100.- All four
# run:lines match their.expectedfile byte for byte, with the exit codes the# exit:lines name (0, 0, 2, 1). mo test --write --sim 100has rewritten eachverified:line; the four lines are character for character the ones the stripped commit removed, and the ids inexamples/programs/.mo.idskept their values (only the hashes moved, and only for logstat’s four files).- Beyond the Done-when:
mo fmt --checkis clean on all four;mo build --testsof each module prints exactly whatmo testprints and exits as it exits;mo build main.mogives a binary whose four runs matchmo run’s stdout, stderr, and exit code.
Wall-clock
13 minutes 26 seconds, 2026-09-15 23:49:52 UTC to 2026-09-16 00:03:18 UTC. About half of
that was reading the prelude, the stdlib rows, and eight corpus files before writing a line,
and running two scratch probe modules (both green first time) to settle what the stdlib
does: String.grouped, "".split(" "), String.lines past a CRLF and a trailing newline,
whether sort_by/sort_by_desc are stable and take a tuple key, Map keyed by a tuple,
pad_left/pad_right when the text is already wider, checked_to_u32, slice’s bounds,
Time.parse on 2026-13-12 and 2026-02-30, and Duration.minutes.
Loops to green: 2
Every function body was written once. No mo test run ever failed, and no # run: line
ever mismatched its .expected file: the four modules’ 31 tests and the four runs were
right the first time they were run. The two failures were both about the file’s shape, not
its code:
mo fmt --check, all four modules — Mo wants a blank line between a function’s contract clauses and its first statement, and it rewraps a few long argument lists. The first fix worked: I restructuredReport.jsonby hand first (binding the slowest rows to a name) so the formatter’s own wrapping stayed readable, then ranmo fmt.mo checknever saw this; onlymo fmt --checkdid.MO0317onreport.moandmain.mo— self-inflicted ordering: I re-ranmo checkafter the formatting pass but beforemo test --write, so theverified:lines were stale, andmain.mowas stale twice over because a module it uses had changed. The first fix worked:mo test --write --sim 100over the four files in dependency order (parse,stats,report,main), after whichmo checkwas clean.
Other measures the spec asks for
- Stdlib or platform names missing: none. Nothing had to go to
GAPS.md. Everything the program needed was already in the prelude, including the three that would otherwise have been hand-written:String.groupedfor the1_204separator, stablesort_byandsort_by_descover a tuple key, andJson.encodeover a struct, whose field order and", "spacing are exactly the spec’s JSON line. - Lines per function (body only, contracts and comments not counted): max 20
(
main.mo:step), then 18 (stats.mo:add); median 4.5 over 42 functions. - Diagnostics that helped:
MO0317named the function that had changed (fn json) and, formain.mo, said which module it uses had changed — that is the whole fix in one line.mo fmt --checkprinted a diff, so the shape law needed no lookup. Nothing misled.
Decisions the spec did not cover
- Which methods are well-formed. The tests demand that
getbeBadMethod, but the spec names no method set.method_ofaccepts the nine HTTP methods in upper case (GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS,TRACE,CONNECT) and nothing else. - Which paths are well-formed. The tests demand that
aand/a"bbeBadPath.path_ofasks only that a path start with/and hold no"; it caps no length and refuses no other character. - Where the mask is applied.
parse_linestores the masked path in the record, so every later reader — the busiest key, the slowest list, the text report, the JSON — sees only the masked form, and no unmasked path exists past parsing. One consequence shows in the fixture: two different card numbers under one route collapse into a single busiest row (4111...and5500...count together as 2). - What “16 digits” means for a longer run. A maximal run of sixteen or more digits is
starred whole, one
*per digit. That keepsmasked_cards’sresult.size == path.sizeand leaves no sixteen-digit run behind in a seventeen-digit one. firstandlastfor “per minute”. The tally keeps the earliest and the latest timestamp counted, not the first and last seen. The span then never runs backwards whatever order the lines arrive in, which is what letsper_minute’srequires first <= lasthold for any list of records, as the property demands.- Whether
--sincefilters malformed lines. It does not: a malformed line has no timestamp to compare against, so it is counted as malformed whatever--sincesays. Run 2’srequestsfalls to 12 whilemalformedstays 4. - The
--sinceboundary. “Ignore lines before T” is read strictly: a record exactly at T is counted. - One error rate, two spellings.
Summary.error_rateholds the unrounded ratio. The text report printsone_decimal(error_rate * 100)and the JSON printserror_rate.round(3), so18.8%and0.167come from the same number. per_minutein JSON. Rounded to one decimal, matching the text report, since the spec’s JSON sample shows40.1.- The text report’s column rule. The spec shows one worked sample, not a rule. Each
head row is the label padded right to the widest label, one space, then the value padded
left to the widest value, with
(N%)after the errors row only. A slowest row pads the duration to the widest duration andMETHOD pathto the widest of those, with three spaces before the timestamp. A busiest row pads the count to the widest count. - Empty sections. The
slowestandbusiestheadings are printed even when their lists are empty; the report’s shape does not change with the data. - What the one usage line says. The spec asks for one line on stderr. It is
<what was wrong>; usage: logstat <dir> [--top N] [--since <ISO-8601>] [--json], so the reason and the usage are both in the one line. - Which problems exit 1. The spec names only “no
.logfile”. A file that cannot be read (Unread) and a file system too slow to answer (Slow) exit 1 as well, each with its own line on stderr. Only a usage error exits 2. - A directory that cannot be listed at all. Treated as
NoLogs, the same as an empty one — except a timeout, which isSlow. That is what makesanalyze(Fs.fixture(), …)NoLogsandanalyze(Fs.fixture(delay: 1.minute), …)Slow. - How long a capability call may wait. The spec names no bound:
within: 10.secondsto list a directory,within: 30.secondsto read one file. .logalone is not a log file. The test skips a file named exactly.log, so the rule is “a name longer than.logthat ends in.log”.- Trailing whitespace on a line. Each line is trimmed before parsing, so a CRLF file’s
\rdoes not make every one of its lines malformed. - One summary, not one per file. The
.lognames are sorted ascending and folded one file at a time into a single shared tally, so a directory prints one report. - Ties in “busiest” past the path. The spec orders by count then path; the module’s comment adds method. It is count descending, then path ascending, then method ascending, written as two stable sorts.
ms_ofon text that spells no number. Text that is not a number stands in as 4_294_967_296, one pastUInt32, so “not a number” and “too large for a duration” fall out of the samechecked_to_u32and are bothBadDuration.