Repository navigation
feat!: v0.5.0 Wave 2 — mds-cli output surface + watch (pipe/exit contract, panic hook, typed paths, anchored writes, lint result sink, watch robustness) - #438
Draft
dean0x wants to merge 248 commits into
Conversation
Characterization goldens for `mds lint`, added before any lint or stream change so every later commit that alters lint output has to regenerate them and name the cells it changed. They deliberately pin TODAY's output, including output that is known to be wrong (a clean JSON envelope printed before a failed write, residual diagnostics rendered against the pre-fix source, a partial module's safe fix rejected, no cap notice in report-only mode, the stdin `--fix --format json` refusal as plain text). What is pinned, per cell: exit code, exact stdout, exact stderr and the source file's bytes after the run (unchanged / rewritten bytes / missing). Matrix: input (stdin with cwd = the fixture dir so mds.json applies, or a relative `x.mds`) x format (human, json) x --quiet (off, on) x fix mode (none, --fix, --fix --check, --fix --diff, --fix --check --diff) x 13 fixtures: clean, warn, error (mds.json raises unused-variable), fixed (an always-false @if), partial (fixed + an unfixable warning after the removed block), rejected (the reverify gate refuses it), cap (1,001 unused keys), cap-fixable (1,001 empty @if blocks), analysis-fail (unterminated @if), limit (10 MiB + 1, generated at runtime), config-fail (mds.json = `{`), write-fail (0o555 dir, unix; skipped with a reason where a read-only dir still accepts files) and partial-module (`_p.mds`). Cells: 520 on unix (260 stdin + 260 file), 480 on Windows (240 + 240; no write-fail cells). One test per (input, fixture) group. Normalization, on the recorded streams only: every spelling of the cell's temp dir (as created, canonical, with/without /private, with/without a verbatim prefix, doubled or forward-slash separators) -> `$TMP`, counted in the golden; `.mds-tmp-` + six alphanumerics + `.tmp` -> `.mds-tmp-RANDOM.tmp`, counted; on Windows only, separators -> `/` (an escaped doubled backslash first). No sorting, trimming or line-ending rewrite. The child runs with a cleared environment plus PATH (and SystemRoot/TEMP on Windows) and NO_COLOR=1, piped streams, relative arguments. Fixture dirs live under /tmp on unix so a leaked absolute path is never wrapped by the renderer at machine-dependent positions. Path-leak baseline: 4 `$TMP` replacements (and 4 temp-name replacements) over all 520 cells, all in the four file-mode `--fix` write-fail cells. Storage: 126 deduplicated goldens plus a cell -> golden table, generated into tests/lint_golden/single.rs as single-line literals (Debug-escaped, braced escapes only) via `MDS_GOLDEN_PRINT=1 cargo nextest run -p mds-cli --test lint_golden golden_print_mode --no-capture`, which prints and never writes files. Streams over 16 KiB are stored as a digest: length, line count, FNV-1a-64, the first 40 lines (at most 4 KiB) and the last 20 lines (at most 2 KiB). Golden data: 125,778 bytes (capped at 1 MiB by a self-check). Self-checks: literal cell counts per platform; every cell maps to exactly one golden, no golden is unreferenced or duplicated; storage bounds, no control character but newline and no backslash in any golden; a comparator that detects a one-byte change in exit, stdout, stderr, file bytes and both replacement counts (inline and digest) and reports only the cell id, lengths and the first differing line with three lines of context; the normalizer's tempdir and temp-name rules; fixture markers checked against the tool rather than the goldens. Co-Authored-By: Claude <noreply@anthropic.com>
Add the directory cells of the lint characterization matrix: `mds lint ... d` (relative, cwd = the fixture's parent) x human/json x --quiet off/on x the five fix modes x 16 directory fixtures: the 13 outcome fixtures placed inside d/, plus an empty tree, an all-excluded tree (d/node_modules/a.mds only) and a mixed tree. 320 cells on unix, 300 on Windows (write-fail is unix-only); with the stdin and file cells the whole matrix is 840 / 780. Each directory cell runs twice, creating the fixture files in opposite orders, and the two normalized runs must be byte-identical before the result is compared with its golden. A directory golden records the exit code, exact stdout, exact stderr and the state of every file under the fixture directory (unchanged, new bytes, or missing), sorted by relative path. Normalization, storage, digests and the generator are shared with the single-file cells; single.rs is unchanged, and regenerating it still reproduces it byte for byte. Fixtures: - mixed: files with every outcome (clean, warning, fixable error, partial fix, unterminated @if, one byte over the size limit), a nested mds.json raising unused-variable to an error, a nested malformed mds.json, names whose byte order differs from path-component and case-insensitive order (B.mds, _unterminated.mds, api-utils.mds, api/x.mds), a hidden directory, node_modules and a non-.mds file. - write-fail, directory form: d/ at 0o555 holding the fixable x.mds, unreadable.mds at 0o000, and unreadable/ at 0o000 holding y.mds. It is the only unix-only group, so the chmod-000 cases live here to keep the planned counts. The permissions are probed after they are set; when they do not hold (euid 0, a filesystem that ignores mode bits) the cell is skipped with a printed reason. Goldens: 108 deduplicated directory goldens holding 128,293 bytes of golden text; 254,071 bytes across both tables (cap 1 MiB). Temp-directory replacements over the directory cells: 4, temp-name replacements: 4, all in dir/{human,json}/{loud,quiet}/fix/write-fail. That is the directory-mode path-leak baseline. Today's output is pinned deliberately, including output that is known to be wrong: an over-size file exits 2 and is counted "with errors" in human directory mode (3 and "resource-limited" in JSON); a directory-mode write failure prints the path twice and leaks the absolute temp path; empty and all-excluded trees emit no JSON envelope; a .mds file inside an unlistable directory is skipped without a word (#437). Self-checks: literal counts (840 / 780 by cfg, and per input), exactly one golden per cell across both tables, no dead or duplicate golden, fixture markers checked against the tool (positive controls for the skipped entries and the permission layout, at most one @define per fixture), storage bounds over both tables, and one-byte mutation detection for the directory comparator and the double-run check. The no-backslash rule now covers every golden that a cell running on Windows maps to; a golden that only unix-only cells map to may hold a backslash only as JSON's escaped quote, because the directory JSON write-failure message quotes the temp path. Co-Authored-By: Claude <noreply@anthropic.com>
Reduce duplication between the single-file/stdin and directory runners in lint_golden/harness.rs, with no behavior change: - Cell::id/DirCell::id and Cell::args/DirCell::args shared their "format/quiet/fix-mode/fixture" id suffix and their "lint" + format/quiet/fix flags via new variant_id and lint_args helpers. - group_cells/dir_group_cells shared their (format, quiet, fix mode) cartesian product via a new variant_combinations helper. - compare/compare_dir shared the ExpectedOutputs/ObservedOutputs construction from Golden/DirGolden and Observed/DirObserved via new expected_outputs/dir_expected_outputs/observed_outputs/ dir_observed_outputs helpers, following this file's existing xxx/dir_xxx naming convention (golden_data_bytes/ dir_golden_data_bytes, golden_strings/dir_golden_strings, etc.). Generated data files (single.rs, dir.rs) are untouched and confirmed byte-identical to a fresh MDS_GOLDEN_PRINT=1 regeneration. Co-Authored-By: Claude <noreply@anthropic.com>
Two ways the characterization goldens could mislead, closed without changing any golden (single.rs and dir.rs are untouched; no cell id changes): - An mds.json above the fixture directory applied to every cell. mds lint walks every ancestor for the nearest mds.json, and on unix the fixture directories live under the shared, world-writable /tmp, so a stray /tmp/mds.json turned every cell into a golden diff with no hint at the cause (with one raising unused-variable to error: "20 of 20 cells differ ... exit: expected 1, actual 2"), and during generation it would have been baked into the goldens. fixture_dir() now stops with the offending path; ancestor_config() does the lookup on the canonical path, as the product does, and a new test plants an mds.json one level up as its positive control. - A skipped cell passed silently. When a permission precondition does not hold (euid 0, or a filesystem that ignores mode bits) the 60 write-fail cells and the write-fail markers were skipped with a line on captured stderr only, so a green run hid their loss. Skips are now announced as a SKIPPED line and, under GitHub Actions, a job-summary warning with the skipped/total count (the cli_watch.rs convention), and a group in which no cell ran or was skipped fails instead of passing with nothing compared. Co-Authored-By: Claude <noreply@anthropic.com>
The watch suite waited on stderr with a helper that returned whatever it had when the time ran out, so a line that never appeared was reported by a later assertion as if it were a final answer, and several counts and absences were read from a snapshot of a live pipe. tests/common/mod.rs: - wait_for_tap and wait_for_tap_count panic on timeout; #[track_caller] and the message opens with the caller's file:line:column and ends with what the tap held. wait_for_tap_count is the former cli_watch.rs wait_for_stderr_count, moved and renamed (it polls any pipe tap). - poll_tap_until: the non-panicking poll both are built on, for the cap test, which treats "no rebuild yet" as data. - ORDER_MARKER_SOURCE / ORDER_MARKER_LINE: a source whose compile fails with one diagnostic. The watch loop finishes a rebuild before it takes the next event, so once the marker's diagnostic is on the tap every earlier rebuild's lines are too: an ordered anchor for exact counts. - tap_reader is public so the waits can be tested without a process; ChildGuard::wait_status is #[track_caller]. tests/cli_watch.rs: - wait_for_stderr_contains_str is gone; its 21 call sites use wait_for_tap, except the cap test, which uses poll_tap_until. - Every wait_* helper is #[track_caller]. - I8 and I9 read their exact final counts with finish_text behind the order marker; I18's two zero counts wait for the Compiled to / Recompiled line that follows the warning; I20's zero waits for the marker, since --quiet silences every status line. The burst test and the single-status-line test take their exact counts the same way. - The 500 ms sleeps: the three that stood in for an event are waits on it (quiet error, compile error, missing partial at startup); the two first windows of the error-settle tests now start from the first error they measure; the remaining four are negative windows, commented, each with a later positive anchor. - Self-tests catch the waits' panics with catch_unwind (no panic hook) and assert the message names this file's line of the call. Mutation controls, not committed: an extra duplicate-warning emit at the rebuild sites of watch.rs fails I8, I9, I18 and I20 at their count assertions; one at the file-mode startup site fails I18's startup zero and I20; dropping #[track_caller] from the waits fails both panic self-tests. Product source is unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
When every attempt of the watch cap test is inconclusive it skips by returning early. cargo test counts that as a pass and never shows a passing test's stderr, so the skip was invisible in CI logs and the watch soak tallied it as a pass. tests/cli_watch.rs: - The writer thread records when each write completed; every attempt logs a gap breakdown on stderr: write count and span, max / median / p99 gap, gaps at or over the window, and when the first rebuild was seen with the largest gap before it. The precondition still judges the same metric, the largest gap measured from the writer's start, so the test behaves as before. - A skip goes through record_skip: the SKIPPED line on stderr (kept), one line appended to the file MDS_TEST_SKIP_LOG names (a set variable that cannot be written fails the test, since whoever set it is counting), and the job-summary warning under GitHub Actions. The line carries every attempt's largest gap and the last attempt's breakdown. .github/workflows/watch-soak.yml (still workflow_dispatch only; no new job, both legs keep identical bounds): - A `test` input, allowlisted to cli_watch, cli_watch_cap and cli_watch_truncate and validated beside `iterations`, replaces the hard-coded `--test cli_watch`; a value outside the allowlist, or a test file absent at the dispatched ref, fails before the build. - MDS_TEST_SKIP_LOG is set per iteration; an iteration that passed but logged a skip is SKIP, tallied apart from pass and fail in summary.txt and the step summary, with its log kept in the artifact. - The tally lives in one shell helper sourced by the soak and by a new self-check step, which plants one skip line and asserts it counts as exactly one skipped iteration before anything is built. Checked locally: the three new run blocks, extracted verbatim, pass bash -n; the self-check passes and fails when the helper counts a skip as a pass; the loop, driven by a fake cargo, reports PASS, SKIP, FAIL, PASS with both summaries; the validation accepts cli_watch and rejects cli_lint, an empty value and a value with a newline (printed on one line). A temporary change that forced the skip path appended exactly one line to MDS_TEST_SKIP_LOG, which the tally counted as one SKIP. Co-Authored-By: Claude <noreply@anthropic.com>
The earlier #381 anchors left four count checks, and one negative window, unable to see the failure they guard; seven other zero-count or absence checks read the stream the same unordered way. - I16, I17 and I19 stopped the watcher the moment the expected count was reached, and I18's final count stopped at its second Recompiled line: a surplus warning printed just after was cut off by the kill. Each final count is now read behind the order marker and gains a Recompiled control. I16's startup and first-rebuild counts are anchored on the line file mode prints after them (Compiled to, Recompiled). - watch_import_removal_stops_tracking_dep could not observe the rebuild it forbids: the entry rendered the same text either way, and a rebuild that changes nothing is silent. Once it drops the import, the entry now @includes an empty module, so every compile of it warns; the test runs without -q and without the idle tick, and counts that warning across the helper edit behind the marker. - R3 read its absences from a live snapshot. The three startup no-spurious-rebuild tests, both idle tests and the 500-file idle test read a zero after a fixed window, with nothing proving the loop was still live. Each now writes the order marker after its window and reads behind it. - common: the order marker's line can print several times for one edit; wait for it, never count it. - watch-soak.yml: a rejected iterations value is printed with %q, as a rejected test value already was. Echoed raw, a value holding a newline started a line the runner reads as a workflow command. Mutation controls (product source restored and identical to bff9843 after each): a delayed second vars-file warning after every rebuild fails the new I16, I17, I18 and I19 at their final counts, while the previous I17, I18 and I19 passed; keeping a removed import tracked fails the import-removal test (previous passed); a late .tmp- status line fails R3 (previous passed); a loop that stalls after readiness fails all six window tests at the marker wait (previous passed). Co-Authored-By: Claude <noreply@anthropic.com>
… exit funnel `eprintln!` panics when stderr is gone, so a run whose stderr reader had exited ended with exit 101 whatever its verdict. This adds the machinery the #157 conversions build on, and moves main.rs and the error and warning helpers onto it: - output.rs: `ewrite!` / `ewriteln!` over `write_stderr_fmt`, which never panics. A closed pipe records a sticky stderr-closed fact and drops every later stderr write; any other failure records a sticky I/O-failed fact. The facts live in `OutputState` (one atomic); everything that decides from them takes `&OutputState`, so unit tests build their own. - `StdoutOutcome { Written, Closed, Failed }` and `write_stdout`, which writes and flushes and is Written only when both succeed. Its callers arrive with the build and fmt conversion. - `final_exit_code(verdict, &OutputState, ExitPolicy)`: a closed pipe never changes the code; under Batch any other output failure lifts it to max(verdict, 2); WatchSession keeps the verdict. `exit(verdict)` is the funnel, and `main` now ends in it. - main.rs: its 8 stderr prints and 6 `process::exit` calls go through the writer and the funnel. - `eprint_error` and `eprint_warning` write through `ewriteln!`. - `render_error_sanitized` no longer panics when a Display fails. The sanitized wrapper renders every text surface (code and url now included) without `to_string()`: a failing optional surface is dropped, a failing message becomes a placeholder. The frame renders through `fmt::Write`, and a render that fails part-way falls back to escaped plain text. - print_discipline.rs lists `ewriteln!` / `ewrite!` with the print macros, so every converted site stays under the guard, and adds per-file site floors for main.rs (11) and output.rs (7): with the macros unlisted, the crate-wide floor still passed (98 >= 80) while ten sites had left it. Tests: tests/broken_pipe.rs runs `check` (file, broken file, stdin, directory), `init` and `lint --format yaml` with stderr as a pipe whose reader is dropped before spawn, each beside an open-stderr control, and asserts the exit code, stdout and the files written. Unit tests pin the writer's sticky states through an injected sink, the stdout outcome mapping, a final_exit_code table for both policies, and the renderer fallback. RED at the parent: all six broken_pipe rows exited Some(101) with stderr closed while their open-stderr controls passed; the renderer tests panicked in to_string ("a Display implementation returned an error unexpectedly") and in format! ("a formatting trait implementation returned an error when the underlying stream did not"). Co-Authored-By: Claude <noreply@anthropic.com>
print_discipline scans the stderr writer macros by name, but not the
function they expand to. `write_stderr_fmt` is crate-visible and takes a
`format_args!`, which is not a print site, so a direct call wrote to
stderr with nothing it interpolated scanned, and so would every site of a
new macro built on it under a name the guard does not list. A planted
`output::write_stderr_fmt(format_args!("RED {}\n", dir.display()))` in
run_check_directory passed all 12 print_discipline tests: the per-file
floors only see a site leave a floored file, and main.rs kept its 11.
- print_discipline.rs: `the_stderr_writer_fn_is_called_only_by_the_writer_macros`
fails on any mention of `write_stderr_fmt` outside its `fn` definition
and the bodies of the `macro_rules!` definitions PRINT_MACROS names, a
renamed `use` of it included, and asserts it found the definition and
the writer macros' bodies in output.rs.
`the_writer_fn_guard_flags_direct_calls_aliases_and_unlisted_macros`
pins the accepted shapes, the reported ones (a direct call, a renamed
import, an unlisted macro built on it) and that comments, strings and
longer identifiers are not mentions. `matching_delim` extends
`matching_paren` to `[]` and `{}` for the macro bodies. The module doc
lists the new coverage and records renaming a print macro on import as
an accepted limit, the same shape as a renamed sanitizer.
- output.rs: the module doc names the writer macros as the stderr choke
point and eprint_error as the error-report choke point; two test
comments said eprint_warning calls eprintln!, where it calls ewriteln!.
Controls: with the planted call the new guard fails naming main.rs:396
while the 12 existing tests pass; accepting every macro body fails the
self-test (stray [3, 5] instead of [3, 5, 8]); a writer name that does
not exist fails the non-vacuity check (found 0). No product behaviour
changes; the lint goldens are unchanged.
Co-Authored-By: Claude <noreply@anthropic.com>
…mmary GitHub starts every run: block as `bash --noprofile --norc -eo pipefail`, so the soak loop's plain `cargo test` call followed by a read of `$?` ended the whole soak at the first failing iteration, before summary.txt and the step summary were written; the loop's own `set -uo pipefail` cannot clear -e. The loop body now lives in one sourced file, captures each exit code with `|| rc=$?`, runs every iteration, writes both summaries, and fails the step only at the end. The self-check now drives that real loop under the runner's exact flags with a planted cargo stand-in (pass, fail, skip, pass, zero tests) and fails against the old loop shape. The `filter` input is validated to A-Z, a-z, 0-9, _ and :, rejected values are printed with %q, and an iteration that runs no test (a filter matching nothing, or no test count at all) counts as a failure. The `iterations` check rejects over-long values, which `[` could not compare and which ran zero iterations. Proven live on a throwaway ref before this commit: smoke passed, a `filter=--list` dispatch failed at input validation, and a 50-iteration soak passed on both legs. Co-Authored-By: Claude <noreply@anthropic.com>
mds build and mds fmt printed through std's eprintln!/print!, which panic when the write fails: a closed stderr or a closed stdout ended the run with exit 101, and a directory build stopped at its first status line, so the files after it were never written. - build.rs and fmt.rs print every status line through output::ewriteln! and end the run through output::exit. - write_output's stdout arm writes through output::write_stdout. A closed stdout is not an error: nothing more is written and the verdict stands. Any other stdout failure is mds::io. - fmt's own write_stdout/print_diff are gone; its filter output and diffs go through output::write_stdout the same way. - StdoutOutcome::into_batch_result maps an outcome for a run that ends on its own. It records nothing; the error reaches the exit code through the caller. Tests: - broken_pipe.rs closes stdout or stderr per row. New rows: build to stdout from a file and from stdin (stdout closed), build a file, with a source map, a directory that compiles and one with a broken file (stderr closed, every output still written), fmt a file and fmt --check (stderr closed), fmt stdin, --diff and --check --diff on a file and a directory (stdout closed). The build and fmt stderr rows and both build stdout rows exited 101 before this change. The fmt stdout rows passed already: fmt's old helper treated a closed pipe as success, and they now guard its removal. - Two Linux-only rows put stdout on /dev/full: build -o - and fmt - must exit 2 with one mds::io error naming stdout. They are ignored off Linux. - cli_fmt.rs: the closed-pipe test drops the reader before the spawn, asserts exit 0 and compares against an open-pipe run that receives the formatted text. - print_discipline.rs: per-file floors for build.rs (30) and fmt.rs (11); the allowlist entry for build.rs's old print! of the compiled output is deleted. mds watch -o - shares write_output: when its stdout reader goes away it now keeps watching instead of panicking. Stopping the session there is the watch half of #157. Lint goldens are unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
A failed write, a failed mkdir and an unreadable stdin were uncoded
miette! errors, so build, check, fmt and init exited 1 for them - the
template-error code. A stale sibling that could not be removed only
warned (exit 0), and stdin over the 10 MiB cap exited 1 (2 under lint)
where a file over the same cap exits 3.
- atomic_write_file returns MdsError::Io (mds::io, exit 2) with its
wording unchanged; so do an output directory that cannot be created, a
stale sidecar or sibling that cannot be removed (now an error), and a
stdout write that fails for another reason than a closed pipe.
- read_stdin: over the cap is mds::resource_limit (exit 3); a read that
fails and bytes that are not UTF-8 are mds::io (exit 2). lint's stdin
path exits with the code's class (its human error is unchanged).
- output::note_io_failure records an I/O failure for the exit funnel, and
output::eprint_io_failure reports and records it. Directory builds and
fmt <dir> use it and carry on with the other files, exiting 2; a
template error alone still exits 1. write_output records nothing.
- main parses with Cli::try_parse and prints clap's help, version or
usage error under the same rule: a closed pipe changes nothing, a
failed stdout write is mds::io and exits 2.
- watch keeps its stale-sibling warning text (a rebuild's failure does
not change how a session exits); lint.rs and watch.rs change only
where atomic_write_file / read_stdin / probe_and_remove_stale changed.
Tests updated from exit 1 to exit 2 on a write failure:
- cli_commands.rs init_force_symlink_target_refused_plain_path_created
- cli_commands.rs init_dangling_symlink_refused_without_force
- cli_build.rs build_refuses_every_output_route_that_lands_on_the_entry
(symlink at the -o path)
Strengthened from "not 0" to exit 2 and mds::io:
- cli_build.rs build_o_write_failure_preserves_existing_output_no_temp_residue
- dir_build.rs dir_build_write_failure_preserves_existing_outputs
- dir_build.rs dir_build_source_map_sidecar_symlink_target_rejected
- security.rs stdin_size_limit_rejects_oversized_input (now exit 3)
- build.rs unit read_stdin_holds_at_most_the_cap_plus_one_byte
New tests: broken_pipe.rs rows for an unwritable output (build file,
build dir, fmt file, fmt dir, lint --fix, init), stdin that cannot be
read (a directory handle on unix, a write-only handle on Windows), stdin
that is not UTF-8, stdin over the cap (build, check, fmt, lint, lint
--format json) and exactly at the cap, clap's --help and --version with
stdout closed and a usage error with stderr closed, and --help into
/dev/full (Linux only). dir_build.rs: a template error plus a failed
mkdir exits 2 (a template error alone exits 1), and a stale sibling that
cannot be removed exits 2. build.rs unit: a stale map that cannot be
removed is mds::io.
print_discipline.rs floors: build.rs 30 -> 27 (four prints became
mds::io reports; one unit-test skip line counts), output.rs 7 -> 6 (the
stale-sibling warning moved to its watch caller).
Lint goldens changed only in these cells (goldens 49, 120, 121 of
single.rs; dir.rs byte-identical):
- file/human/loud/fix/write-fail, file/human/quiet/fix/write-fail,
file/json/loud/fix/write-fail, file/json/quiet/fix/write-fail
(stderr gains the mds::io code line)
- stdin/human/{loud,quiet}/{report,fix,fix-check,fix-diff,fix-check-diff}/limit
and stdin/json/{loud,quiet}/report/limit (exit 2 -> 3, stderr now
mds::resource_limit)
Docs: spec.md section 5 (a "Streams and I/O failures" rule, the mds::io
and mds::resource_limit rows), 7.2 (continue-on-error, stale-flip
cleanup, --quiet, output writing), 7.4, 7.6 and 7.9; README exit codes;
CHANGELOG BREAKING (CLI) entry. The build.rs "documented limitation"
comment is gone: the stale-unlink failure is now an error.
Co-Authored-By: Claude <noreply@anthropic.com>
exit_after_clap_output's match on the print-and-flush result used a
guarded Err arm plus a catch-all `Ok(()) | Err(_) => {}` to do nothing on
success and on a closed pipe. An `if let Err(e) = printed { if e.kind()
!= BrokenPipe { ... } }` says the same thing without the empty arm.
Reviewed the rest of the #157 stream-handling diff (output.rs, build.rs,
fmt.rs, and the broken_pipe/cli_build/cli_commands/cli_fmt/dir_build/
security test files) for slop, duplication and unclear naming; found
none worth changing. Behaviour, exit codes, and message wording are
unchanged.
Co-Authored-By: Claude <noreply@anthropic.com>
…tdout stays closed A directory build, check or fmt reported a source it could not read as mds::io but exited 1, while the same file given alone exits 2, and spec sections 5 and 7.9, the README and the fmt module doc promise 2. Each per-file failure now goes through output::eprint_file_failure, which records an I/O failure for the exit code when the error is in the exit-2 class (mds::io, mds::file_not_found, mds::not_mds) and then reports it. A directory run therefore exits 2 for a source that cannot be read, a path carrying a forbidden character (#265) or an @import of a file that does not exist, as that file alone does; a run whose failures are only template errors or resource limits still exits 1. Four walker tests in forbidden_paths.rs and one in security.rs pinned exit 1 for the forbidden-character refusal in directory mode; they now expect 2. write_stdout now remembers a closed stdout: once a write hits a closed pipe, OutputState records it and every later write returns Closed without writing. A stdout that fails for another reason is recorded too, and a repeat of that failure returns the new StdoutOutcome::FailedAgain, which a batch run does not report again: mds fmt --diff <dir> into a full device prints one mds::io frame, not one per file, and counts every file whose diff was lost as failed. A stale .map sidecar that could not be read (its metadata, open or read failing for a reason other than not-found) was reported as "not a tool-generated SMv3 map" and left in place with exit 0. It is now mds::io, "cannot read stale map <path>: <cause>", exit 2. The oversized-stdin message names the cap it enforces, 10 MiB, instead of 10 MB. Golden 49 of lint_golden/single.rs changed (message text only); its cells: stdin/human/loud/report/limit, stdin/human/loud/fix/limit, stdin/human/loud/fix-check/limit, stdin/human/loud/fix-diff/limit, stdin/human/loud/fix-check-diff/limit, stdin/human/quiet/report/limit, stdin/human/quiet/fix/limit, stdin/human/quiet/fix-check/limit, stdin/human/quiet/fix-diff/limit, stdin/human/quiet/fix-check-diff/limit, stdin/json/loud/report/limit, stdin/json/quiet/report/limit. lint_golden/dir.rs regenerated byte-identical. The CHANGELOG #157 entry no longer says a closed stdout used to panic under mds fmt (fmt already tolerated it), names the directory-mode change, and scopes its "every other I/O failure" to the failures it lists, as spec sections 5, 7.2, 7.4 and 7.9 and the README now do: an unreadable mds.json stays an uncoded exit 1. The closed_pipe() test helper moves to tests/common/mod.rs, shared by broken_pipe.rs and cli_fmt.rs. Co-Authored-By: Claude <noreply@anthropic.com>
…iled stdout write mds lint printed its status lines, its directory summary and its own usage errors with eprintln!, so a closed stderr ended a lint run with a Rust panic and exit 101: `mds lint ok.mds` (Clean:), `mds lint <dir>` (the summary), `mds lint --fix` (Fixed:), `mds lint --fix --check -` (Would fix:). Its local write_stdout treated a closed pipe as success, but every caller dropped any other stdout failure, so a clean `mds lint --format json` into a failing stdout exited 0 with its report lost. Every stderr print in lint.rs now goes through the non-panicking stderr writer, and every exit through the exit funnel. The local write_stdout is gone: the JSON report, the --diff output and the fixed source are written with output::write_stdout, and lint handles the outcome in one place. A closed stdout keeps the verdict. The first other failure is reported as one mds::io error naming stdout and recorded, so the funnel lifts the exit code to at least 2; a repeat is not reported again, and a resource limit keeps its 3. broken_pipe.rs gains the lint rows: stderr closed (a clean file, a file, a directory and stdin with warnings, --fix, --fix --check -) and stdout closed (--format json on a file, a directory and stdin, --fix -, --fix --diff) keep their verdicts; on Linux, stdout on /dev/full makes a clean JSON report of a file or a directory and --fix - exit 2, keeps 3 for a file over the size cap, and reports two lost diffs once. The lint goldens are unchanged. README and the #157 CHANGELOG entry now cover mds lint. Co-Authored-By: Claude <noreply@anthropic.com>
mds fmt --diff <dir> counts a file whose diff a stdout failing other than by a closed pipe lost as failed. mds lint --fix --diff <dir> reported the same failure once and lifted the exit code, but left the file in its findings bucket, so its summary read "2 clean, 0 with warnings, 0 with errors, 0 resource-limited" above exit 2. Decision: one rule for both, the one every directory run already applies to a file whose output fails. A file whose own diff a failing stdout lost counts as failed: "N failed" under fmt, "with errors" under lint, which is where lint already counts a --fix rewrite that fails. The failure is still reported once for the run. A closed stdout loses nothing and moves no file. Run-level writes (lint's JSON envelope, the single-file and stdin output) belong to no one file; the recorded failure lifts their exit code as before. fmt already followed the rule and is unchanged. lint's emit_stdout now says whether a failing stdout lost its text, and both directory emitters, human and JSON, count such a file under "with errors". broken_pipe.rs: every unix now has a stdout failure that is not a closed pipe, a regular file the child may not grow (file-size limit 0, SIGXFSZ ignored, so writes fail with EFBIG), beside Linux's /dev/full. The lint failing-stdout rows run on it, so they run on macOS too, and were renamed from "into a full device" to "into a failing stdout". New rows pin the rule for fmt and for both lint directory emitters, and that a closed stdout moves no lint directory file, for both emitters. The fmt /dev/full directory row became the fmt case of the shared rule. spec: the "Streams and I/O failures on the CLI" block names mds lint, the directory counting rule, and the one exception to mds::io (a directory rewrite failure under --format human prints "error writing"); lint's "with errors" bucket and its exit-2 row list these I/O failures. README dates lint's old exit 0 and states the counting rule; the #157 CHANGELOG entry scopes lint's mds::io rewrite report to a file argument and adds the counting rule. The lint goldens are unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
…- loses its reader mds watch printed its status lines with std's eprint macros, which panic when the write fails: a closed stderr ended the session with exit 101 at its first line, before it was watching. Every status line now goes through the CLI's stderr writer, which never panics; with stderr closed the session reaches readiness, rebuilds on every edit, and exits 0 at Ctrl+C. `ewrite!` gets its first caller (the --clear sequence). With -o -, stdout is the session's product. A write that finds its reader gone (a closed pipe) now ends the session: one `Stopped watching (stdout closed).` line, suppressed by --quiet, and exit 0, at startup or on a rebuild. Since the stream writer landed, such a session kept watching and printed `Recompiled <stdout>` for writes that went nowhere. The session reads each stdout outcome itself instead of through the batch reading, which takes a closed pipe and a repeated failure for success: - the first stdout failure for another reason is reported once as mds::io naming stdout, and watching continues; - a repeat of it is not reported again, is not announced as `Recompiled`, and is not recorded as written, so the content-dedup baseline keeps what was last written and a save of the same text writes again. Exit policy: a watch session that goes live (every watch armed, every baseline captured) records it in the output state, and the exit funnel then applies the watch-session rule, so an output failure during the session (a failed rebuild write, a stdout or stderr that fails other than by a closed pipe) never changes the Ctrl+C exit. A session that ends before going live keeps the batch rule. The go-live point is one function, shared by file and directory mode, which switches the policy before it writes the readiness marker. The output state stays private to output.rs. Tests (cli_watch.rs): stdout's reader gone before the spawn stops the session with the line and exit 0, silent under --quiet (open-pipe control); a reader that goes away after the first output stops it at the next rebuild; stderr closed from the start keeps watching in file and directory mode and exits 0 at Ctrl+C (open-stderr control); a stdout file the child may not grow is reported once, a repeat claims no rebuild, and a same-text save after room is made writes the output; a rebuild write that fails and a stderr that fails other than by a closed pipe leave the Ctrl+C exit at 0 (control: that stderr lifts mds check to 2). Unit tests pin the session's reading of each stdout outcome and the policy switch. The file-size-limit helper moves to tests/common so cli_watch and broken_pipe share it; the stream file is opened at its end rather than for appending, since macOS checks the limit against the descriptor offset. print_discipline gains a watch.rs site floor (18). README and the CHANGELOG #157 entry describe the watch behaviour. Co-Authored-By: Claude <noreply@anthropic.com>
…writer and the funnel print_discipline gains the two lexical bans the stream rule rests on. no_raw_print_macro_outside_the_writer: println!, print!, eprintln!, eprint! and dbg! panic when their write fails, which is how a closed or failing stream ended a run with exit 101. None may be named anywhere in crates/mds-cli/src: not called (path-qualified included), not renamed on import, not wrapped in another macro. There is no exemption, neither for test modules nor for the writer macros' own bodies: the writer expands to write_stderr_fmt and needs none, and a writer body that reached for eprintln! would bring the panic back. A method of that name (clap's err.print()), a function definition and a longer identifier are not mentions; clap's own output stays outside the scan by construction, as the guard doc now says. process_exit_only_in_the_funnel: std::process::exit may appear only in the body of output::exit, the funnel that applies the output-failure rule (EXIT_FUNNELS lists it; a second funnel is added there, never exempted elsewhere). std::process::abort appears nowhere, and a use item that would let a call avoid naming process::exit (renamed, braced, globbed, or a renamed process module) is reported. Both bans read every module the crate compiles: the source list is checked against each `mod name;` resolved from main.rs, and a #[path] module fails closed. every_printing_file_has_a_site_floor requires a SITE_FLOORS entry or a written reason in FLOORS_PENDING for each file that prints; lint.rs is the one pending file, until the lint pipeline refactor (#309) settles its site count. Synthetic positive and negative controls cover each scanner. Product-side change, test code only: the ban has no test-module exemption, so the four test-only skip notices (two in build.rs's tests, two in output.rs's tests) move from eprintln! to the writer macro. They print only when a test cannot run its vector (running as root, or Windows without symlink rights), and they now reach the real stderr uncaptured. No production code changes. broken_pipe.rs: the subcommand x closed-stream table is complete. The two missing cells are commands that write nothing to stdout, check and init; their rows assert the open run's stdout is empty and that closing it changes nothing. TABLE names one row per subcommand and stream (the watch rows live in cli_watch.rs), and every_subcommand_has_a_row_for_each_closed_stream fails for a subcommand `mds --help` lists without both rows, a row whose subcommand is gone, and a row that names no #[test] function. Co-Authored-By: Claude <noreply@anthropic.com>
stop_watching's StopReason match had one braced arm and one bare expression arm for what are both single ewriteln! calls; make both arms the same shape. Co-Authored-By: Claude <noreply@anthropic.com>
spec.md described no watch stream behaviour. Section 5's "Streams and I/O
failures on the CLI" now has a paragraph for `mds watch`: a closed stderr
keeps it watching; with `-o -` a gone reader ends the session with
`Stopped watching (stdout closed).` (not under --quiet) and exit 0; another
stdout failure is reported once and not recorded as written, so a save of
unchanged content retries it; once the session is live no output failure
changes the Ctrl+C exit; a session that ends before it is live follows the
batch rule.
Two of those promises had no test:
- the batch rule before the session is live. A new unix test stops a
session at startup on a gone stdout reader while stderr fails with EFBIG:
exit 2, with an open-stderr control that exits 0. Marking the session
live at the top of file mode makes it fail (exit 0).
- `--quiet` for a reader that goes away mid-session. The mid-session test
now runs a loud and a quiet arm. Passing `false` for quiet at the file
loop's stop line makes the quiet arm fail.
The print-discipline guards had gaps:
- the exit ban missed a `process` renamed through a braced `self`
(`use std::process::{self as p, Command};`) and a rename after another
`process` path in the same braces. Both are now reported. The synthetic
control failed on both lines before the scanner change.
- nothing kept a second writer from holding its own stdout or stderr
handle, which would skip the closed-pipe and report-once state, as lint's
duplicate `write_stdout` did. A new ban allows `stdout`/`stderr` only in
`write_stdout`, `write_stderr_fmt` and main's exit after clap's output,
or for an `.is_terminal()` query. It has synthetic controls, a check that
each owner holds its handle, and a planted handle in watch.rs makes it
fail.
watch.rs doc comments that said every stop exits 0 now name the startup
exception.
Co-Authored-By: Claude <noreply@anthropic.com>
…recovers A stdout write that failed for a reason other than a closed pipe was reported once for the whole process: the stdout-failed fact was sticky, so every later failure came back as a silent repeat. For a batch run that is the intended report-once. For a long `mds watch -o -` session it hid failures: stdout failed (reported), recovered (a rebuild wrote and printed `Recompiled`), then failed again with no report and no `Recompiled`. Now the report is once per failure: a stdout write that lands clears the stdout-failed fact, so the next failure is `Failed` again and reported. A write of no bytes proves nothing about stdout and clears nothing. A closed stdout stays closed. The fact that lifts a batch run's exit code to 2 is a separate bit and is never cleared, so a batch run that lost a stdout write still exits 2 after stdout recovers; a batch stdout that keeps failing is reported once, as before. Tests: a unit test drives the writer through fail, repeat, empty write, recovery, fail, repeat and checks the exit-lifting fact survives; a unix watch test makes stdout fail at startup, recover for one rebuild and fail again, and expects two reports, one `Recompiled` and exit 0 at Ctrl+C. Docs: spec §5 (the batch list, the watch paragraph) and the `mds fmt` directory sentence say "once while it keeps failing"; README and the #157 CHANGELOG entry say the same, and now state the exception spec already had: a session that stops at the startup write while stderr has also failed other than by a closed pipe exits 2, as the other commands do. Lint goldens unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
`LintSource` in lint.rs is the one place a lint input gets its names:
`Stdin`, `File { typed, name }` and `DirEntry { path, key }`, with
`display_label()` (the name its diagnostics carry: each diag.file, the
JSON files[].file key, the name a human frame renders the source under)
and `diff_label()` (the escaped name a --fix --diff header shows).
What moved:
- stdin: 7 of the 9 STDIN_DISPLAY_LABEL sites now go through
`LintSource::Stdin`: the diagnostic relabel, the preview and apply
labels, the three named sources and the diff header. The `Would fix:`
and `Partially fixed:` status lines keep the constant inside the
writer macro: print_discipline accepts only an escape call or an
allowlisted name there, and its allowlist liveness check fails once
lint.rs stops naming STDIN_DISPLAY_LABEL in a macro argument (planted
and observed failing).
- single file: the `<file>` fallback label is gone. `LintSource::file`
parses the typed path into its UTF-8 file name once, after the read;
the relabel, the named source, the preview and apply labels, both
`Clean:` lines and the diff header use it.
- directory: both per-file functions build a `DirEntry` from the walked
path and its root-relative key; the relabel, the error-entry JSON key,
the named source, the preview and apply labels and the diff header use
it.
- Status lines that name a path keep `safe_path(..)` inside the macro.
The `<file>` fallback was dead. `run_lint_file` has one caller, reached
only after `ensure_existing_mds_file` accepted the path, so its
extension is `Some("mds")` and `file_name()` is `Some` (the extension is
read from it). The fallback was evaluated after `read_source_file`
succeeded: `NativeFs::check_symlink` refuses a final-component symlink
and canonicalizes `canonicalize(parent).join(file_name)`, requiring the
result's parent to be that canonical parent, so the canonical path ends
in the file's own name; `read_canonical_source` then refuses a canonical
path that is not valid UTF-8 ("path is not valid UTF-8", exit 2, pinned
on Linux by cli_lint's lint_single_file_non_utf8_path_exits_2). The file
name was therefore always UTF-8 where the fallback ran. `LintSource::file`
keeps an `mds::io` refusal for that impossible case instead of a label.
No behaviour change: goldens and tests unchanged (crates/mds-cli/tests
is byte-identical to the parent commit; lint_golden 52/52, cli_lint 129,
print_discipline 22, mds-cli nextest 1124 passed + 3 skipped, bin 196).
Co-Authored-By: Claude <noreply@anthropic.com>
PR CI run 36703033927 failed in three jobs on one clippy error under Rust 1.98.0: clippy::byte_char_slices ("can be more succinctly written as a byte str") at crates/mds-cli/tests/print_discipline.rs, where asks_is_terminal loops over [b'(', b')', b'.']. The loop now iterates *b"().", clippy's suggestion; it yields the same three u8 values in the same order, so the guard behaves identically.
The error slipped through because the local default stable toolchain is Rust 1.96.0, whose clippy predates the lint, while CI's stable is 1.98.0. Local fmt and clippy gates now run with +1.98 to match CI.
Co-Authored-By: Claude <noreply@anthropic.com>
`run_lint_file` names its input with `LintSource::file` once `mds::lint` has accepted the path, instead of straight after the read. `mds::lint` refuses a path that is not valid UTF-8 before it reads anything, so once it has returned the typed file name is UTF-8 and the `mds::io` refusal in `LintSource::file` cannot be reached. The read before it does not guarantee that on its own: it validates the canonical path it opens, not the path as typed. In this order every refusal on this path is `mds::lint`'s own, exactly as before `LintSource` existed. The doc of `LintSource::file` now gives this reason. No behaviour change: goldens and tests unchanged (crates/mds-cli/tests is byte-identical to the parent commit). Co-Authored-By: Claude <noreply@anthropic.com>
…arator
Four broken_pipe rows failed on Windows in their open-stream control: the
expected text hard-coded `/` in a path mds builds by joining components,
which Windows prints with `\` (`Compiled to .\ok.md`, `+++ fixes\b.mds`).
The product's output is right on each OS; the expectations were not.
The expected paths are now built with `native()`, which writes a path
spelled with `/` in `std::path::MAIN_SEPARATOR_STR`, and `diff_header()`
(`+++ <path>\n` through `native()`), so each control is still an exact match
on every OS. `Row` and `FullRow` borrow their expected text for a lifetime
instead of `'static`, to hold the built strings.
Changed expectations (unix text unchanged; Windows now `\`):
- build_a_file_with_stderr_closed_exits_0_and_writes_the_output:
"Compiled to ./ok.md\n"
- build_with_a_source_map_and_stderr_closed_exits_0_and_writes_both_files:
"Source map written to ./ok.md.map\n"
- lint_fix_diff_of_a_directory_with_stdout_closed_exits_1 and
lint_json_fix_diff_of_a_directory_with_stdout_closed_exits_1:
"+++ fixes/b.mds\n"
- fmt_check_diff_on_a_directory_with_stdout_closed_exits_1: the path-less
"messy.mds\n" becomes the exact header "+++ m/messy.mds\n"
- the failing-stdout directory rows (unix only today):
"+++ two/a.mds\n", "+++ two/b.mds\n", "+++ fixes/a.mds\n",
"+++ fixes/b.mds\n", so they stay exact if a Windows vector is added
Paths compared as `Path` (`written()`, `files_under()`) and typed paths
printed as given ("+++ fix.mds\n", "Clean: ok.mds\n") need no change.
Co-Authored-By: Claude <noreply@anthropic.com>
`mds lint --fix` and its preview (`--fix --check` / `--fix --diff`) ran
the fix pipeline through two copies: plan_and_apply_fixes returned a
FixFileOutcome, preview_fixes a PreviewOutcome, and each built its own
reverify closure, the two identical in behaviour.
- ReverifyGate replaces the two closures. It is built once per plan
(the original's compiled output, kept only when every planned edit is
output-neutral) and its verify() is what apply_fixes_incremental
calls for each candidate: the candidate must lint, and when the
output check applies it must compile to the same output. The refusal
keeps its wording.
- run_fix_pipeline(&LintSource, ...) replaces both functions, and
FixPipelineOutcome { Fixed, PartiallyFixed, Rejected, NothingToFix }
replaces both outcome enums. The pipeline borrows the lint result
instead of handing it back, so Rejected and NothingToFix carry no
copy of it. `--fix` writes the source of Fixed and PartiallyFixed;
the preview reads either as "would fix", exactly as it read its own
WouldFix before.
- Stdin, single-file and both directory modes call run_fix_pipeline
with their LintSource in place of a display-label string.
In-module tests ported one to one (same fixtures, same assertions):
preview_fixes_surfaces_rejected_on_overlap ->
fix_pipeline_surfaces_rejected_on_overlap, and
preview_fixes_would_fix_relabels_residual_display_path ->
fix_pipeline_would_fix_relabels_residual_display_path. Their labels
come from LintSource::DirEntry values with the same names.
No behaviour change: goldens and tests unchanged.
Co-Authored-By: Claude <noreply@anthropic.com>
The reverify gate's compiled-output check refuses a fix that would change what a template compiles to when every planned edit is meant to leave the output alone. No test had seen it refuse anything: with the check disabled the whole mds-cli suite stayed green. No known `mds lint --fix` input reaches the refusal end to end, so these in-module tests drive it directly: - reverify_gate_refuses_a_candidate_that_changes_compiled_output: a gate built from a real, all output-neutral plan refuses a crafted candidate that still lints but compiles to different output, as an mds::io error with today's message. The plan's own fix, which keeps the output, is accepted. - reverify_gate_skips_the_output_check_for_a_plan_that_changes_output: a plan that also carries a legacy-interpolation edit accepts the same kind of candidate; the plan's output-neutral edits alone refuse it. - fix_pipeline_rejects_a_fix_that_would_change_compiled_output: a crafted output-neutral removal of a line of text comes out of run_fix_pipeline as Rejected, with the gate's message inside the reason `fix rejected:` prints. The real findings of the same source are fixed. Disabling the check fails all three; counting one output-neutral edit as enough fails the second; inverting the comparison fails the controls. Tests only: no product code, output or golden changes. Co-Authored-By: Claude <noreply@anthropic.com>
…not duplicate lines `no_raw_print_macro_outside_the_writer` requires a minimum number of `ewriteln!` / `ewrite!` calls across mds-cli/src. That number is a non-vacuity check only: it shows the scan found the registered writer macros at all, so the raw-print ban cannot pass by reading nothing. It is not a coverage count. Which files print through the writer is guarded file by file by `SITE_FLOORS`, with `lint.rs` pending in `FLOORS_PENDING` until its status lines move to the result sinks. At 80 the floor sat 5 under the crate's real count (85), so it had become a coverage count by accident. The lint refactor that follows gives stdin, a file argument and each directory entry one spine, which removes 16 duplicated status lines from lint.rs, and that alone would have failed the floor. Lower it to 60 and say in the comment what it guards. Planted control: pointing the scan at a macro name that does not exist fails the test with "non-vacuity: expected at least 60 `ewriteln!` / `ewrite!` calls across mds-cli/src, found 0". Co-Authored-By: Claude <noreply@anthropic.com>
…ntry Every input of `mds lint` now goes through one per-input spine, `lint_input`. It names the findings for the input, announces a capped result, then reports the findings, or runs the fix pipeline and applies `--fix` (`apply_fix`, with stdin's filter in `fix_stdin`) or previews it (`preview_fix`). It returns an `InputVerdict` (tally, would-fix, truncated): stdin and a file argument exit with its code, a directory counts it in its summary. The spine replaces the twin directory functions `lint_one_file_accumulating` and `lint_one_file_human`, and the report, fix and preview bodies of `run_lint_stdin` and `run_lint_file`, which now only load their input; a directory entry loads through `load_dir_entry`. `exit_by_severity` and `preview_exit_code` fold into `InputVerdict::exit_code`, and `emit_result` also collects a directory entry's findings into the directory's JSON document. Divergences kept, each an explicit branch: - A directory under human output reads each source first, so an oversized entry counts under "with errors" (exit 2) rather than resource-limited; JSON output reads a source only to fix it, after linting. - A directory's JSON document records a rewritten file's findings only once the rewrite succeeded; a file argument and a directory's human output show the residual first, then write. - A failed rewrite ends a file argument's run with the error (exit 2), prints `error writing` for a directory's human output, and becomes an error entry in a directory's JSON document. - `mds lint --fix -` stays a filter: its findings render against the source it emits, and it prints no `Fixed:`. - `Clean:` is printed for a file argument only, and a directory's status lines name the file (`<path>: fix rejected:`, the cap notice). No behaviour change: goldens and tests unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
lint_input's SourceText::Unread read-failure arm bound an intermediate `tally` variable only to move it, unchanged, into the following InputVerdict literal one line later. Inline the dir_entry_failed(...) call directly into the tally field, matching the sibling arm 12 lines above (which already inlines tally_from_result(&result)) and load_dir_entry's two analogous Err arms. No move-ordering hazard here (unlike load_dir_entry's other call site, where failure_tally(&e) must be evaluated before e is moved into dir_entry_failed, so that intermediate stays). Output, exit codes and control flow unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
…nical path The example of a path that display_native_path respells was an I/O failure below a canonicalized out-dir. Since the CLI names a written output as typed, no such error shows a canonical path. The example is now the directory of a dependency outside the entry's directory and the directory argument, which a failed-to-watch warning names by the path the compile reported. Co-Authored-By: Claude <noreply@anthropic.com>
Under --format json, mds lint prints exactly one JSON document on every exit but a usage error and a panic that ends the run: the panic prints the fixed internal-compiler-error text and no document. The spec's section 7 summary line, the lint module doc and the changelog entry said "except a usage error" only. The spec's detailed paragraph already named the panic, and now all four places agree. Co-Authored-By: Claude <noreply@anthropic.com>
…ning mds lint's warning for an unknown rule in mds.json names the file as the run reached it (warning: in ./mds.json: ...), but section 7.10 had no row for it. The new row cites the test that pins the form, and LABEL_TABLE in tests/path_labels.rs gets the matching entry, which the table check requires for every row. Mutation control: without the entry the table check fails with "spec.md section 7.10 cites tests LABEL_TABLE does not list". Co-Authored-By: Claude <noreply@anthropic.com>
The spec said that an unreadable, oversized or malformed mds.json has no error code and exits 1 under build, check and fmt and 2 under lint. Lint wraps such a failure as mds::io for a file argument, for stdin and for each entry of a directory, so under lint the error has a code. The paragraph and the lint.rules row of the config table now say so. Co-Authored-By: Claude <noreply@anthropic.com>
Without the feature, a panic prints the fixed internal-compiler-error text, and an escaped backtrace only when RUST_BACKTRACE is set. Co-Authored-By: Claude <noreply@anthropic.com>
The look of a directory batch stamped only the sources among the paths the batch names. A dependency outside the root that the batch names, and that a source of the same batch imports for the first time, was not stamped. A truncation after the look and before that source's read was then compiled as read, and the empty output was written. The look now stamps every path the batch names. Of the errored paths it still stamps only the sources. The baseline keeps its domain: a path nothing reads is stamped at the look and dropped when the batch ends, so its emptying still holds nothing. This holds the batch whose compile read the file. The batch that the truncation's own event starts compiles the file as it is, because the dependency is outside the baseline. Test: a_dependency_outside_the_root_a_batch_names_is_held_when_truncated_after_the_look runs a batch in a child process, stopped after its look by the debug build's pause. Before the change: watch.rs:10865:13, left "" right "X one\n" (the empty read was written). The pause variable's name is now visible to the test module. Co-Authored-By: Claude <noreply@anthropic.com>
…nd that each deadline is its own A compile that failed reports no dependencies, so the late look after a failure covers the entry (or source), the --vars file and the files the compile before it read. A file the failing edit itself starts to import, truncated after the look, is not among them, and the failure is reported. The spec now says so instead of "whether that read then failed or not" alone. The one-second deadline belongs to its hold. Once a hold has ended, a file found emptied again, at a later rebuild's look or after the look of the rebuild that found the file written, starts a hold of its own with a new deadline. The spec says this next to "that deadline never moves". Checked against EmptyHold::on_late_empty, run_file_rebuild and the directory-mode late look for a failed compile. Co-Authored-By: Claude <noreply@anthropic.com>
…test pins it The module and input refusal comes at the write, after the directories the write needs have been made, and removes none. `-o nd/../lib.md`, with `nd` not there yet and `lib.md` a module or a file the run reads, is refused and leaves an empty `nd`. Spec 7.2 now says so, naming the entry's refusal as the one that comes before any directory is made. A new test pins the leftover for both refusals: exit 2 with the cause, the file keeps its content, `nd` is an empty directory, and nothing else is created. A cleanup in the write that removed `nd` made it fail. Co-Authored-By: Claude <noreply@anthropic.com>
Only `mds build` of a file argument removes a stale `.map` sidecar: the reconciliation runs in run_build and not in the directory run, which writes sidecars and leaves a stale one in place without a warning. The Removals paragraph named the sidecar for every build. It now names a build of a file argument, and says a directory run does not look for one. Co-Authored-By: Claude <noreply@anthropic.com>
The note on replace-by-rename named crates/mds-cli/src/output.rs for atomic_write_file, which lives in crates/mds-cli/src/write.rs. It also left out the starter file of `mds init`: with --force it goes through atomic_write_file, and without it create_new writes a starter that never replaces a file. The note now names write.rs as the write funnel and lists the starter file with the writes that rely on the rename alone. Co-Authored-By: Claude <noreply@anthropic.com>
…an tag A test comment or assertion message that cited another file by line number (`lint.rs:1535`, `main.rs:31`, `fmt.rs:308`, `spec.md:938`, `cli_watch.rs:520`) now names the live symbol instead: `run_check`, `run_fmt_directory`, `Cli::quiet`, `ResultSink::fixed`, `ResultSink::fix_rejected`, `ResultSink::cap_reached`, `Rewrite::WriteFailed`, or the spec section. Three messages named functions that no longer exist (`lint_one_file_accumulating`, `lint_one_file_human`); they name the sink methods that gate the output today. The block above the human `Fixed:` test no longer says the human and JSON sinks are separate emitters: both use `ResultSink::fixed`. Plan tags in the same comments and messages are replaced by the rule they stood for, or dropped: the unknown-rule block of cli_build.rs, the preview-exit block, the rename-into-place tests, the dir_build.rs coverage list and the print_discipline.rs self-test headings. Comments and assertion message strings only: no code and no assertion condition changed. No lint golden cell changed. Co-Authored-By: Claude <noreply@anthropic.com>
… a plan tag A source comment that cited a line of another file now names the symbol: `run_check_directory`, `run_fmt_directory`, `write_compiled`, `Cli::quiet`, `ResultSink::fixed`, `Rewrite::WriteFailed`. Comments that named lint functions that no longer exist now name the `ResultSink` methods (`HumanSink`, `JsonSink`) that hold the quiet gates today. The `mds check <dir>` doc in main.rs now states all three exit codes: 1 for a template error, 2 when an I/O or file-system failure is among them, and 3 when a file failed with a resource limit. Plan tags in the same comments are replaced by the rule they stood for, or dropped. Comments and doc comments only: no code changed. Co-Authored-By: Claude <noreply@anthropic.com>
The entries for the write and removal below an anchor and for the path in an error message no longer carry a label or a weakness number. Each states what the CLI did and what it does now. Co-Authored-By: Claude <noreply@anthropic.com>
…nges The two entries that moved `mds lint` from exit 2 to exit 3 for a file or a vars file over the 10 MiB cap were listed under Fixed. They change an exit code a script can test, so they are now under Changed with a BREAKING (CLI) lead. Co-Authored-By: Claude <noreply@anthropic.com>
The refused-write test asserted one result on every OS: the write leaves an empty nd. On Windows the write makes no nd. Windows resolves nd\.. by its text, as the root, which exists, so no directory is made. The Windows CI job failed on that assertion. The test now states the result of each OS. On Unix nd stays, empty. On Windows no nd exists, and the entry list stays as it was before the run. Both OS keep the other assertions: exit 2, the refusal text, the file content and no temporary file. Spec 7.2 now says that nd is never made on Windows. No product code changes. Co-Authored-By: Claude <noreply@anthropic.com>
A directory batch compiles a source that imports a dependency outside the root for the first time. The dependency is truncated after the batch's look and before the compile reads it, and the compile is held. The truncation's own event starts a second batch that names the dependency. The dependency is no source, no tracked dependency and not among the sources held back, so the look of the second batch could not find it emptied, and its compile published the empty output. The files a held compile read empty now stay in the baseline's domain until the hold ends, as the held sources do. The look of a later batch stamps them, finds them emptied, and holds that batch too. The hold's deadline rule is unchanged. A path that nothing reads, named by a held batch, stays outside the domain and holds nothing when emptied. A source that drops an import of such a file waits for the file to be written, or for the deadline, as for any tracked dependency. The two unit tests that left the module empty while the page was saved now write the module whole with the page's save: each keeps its intent (the batch that ends the hold rebuilds the held source; a held source emptied before the hold ends is held again). Spec section 7.2 states the wait. Co-Authored-By: Claude <noreply@anthropic.com>
A file the --vars load or a compile read, emptied after the rebuild looked, holds the rebuild back. Six sites wrote that rule by hand. The rule now lives in held_after_look: it finds the files that went empty, reads the clock once, and returns them when the rebuild is held. File mode loads the variables and compiles as one result (load_and_compile) and takes one late look. It reads the files of interest the compile reported when it succeeded, and the files of interest of the compile before when the load or the compile failed. Directory mode holds a batch whose --vars load failed through DirWatchState::hold_after_vars_load_failed. Both holds in compile_one_source call the helper; the success hold keeps the files the helper returns as the files a held compile read empty. Behaviour is unchanged and no test changed. any_went_empty is now used by tests only, so it is compiled for tests only. Co-Authored-By: Claude <noreply@anthropic.com>
…tested A directory batch whose --vars load fails on a file emptied after the batch looked is held with that file joined to it. No test pinned the join: replacing it with the batch as it came passed every test, because an integration test needs a lost event to reach it. Three unit tests call DirWatchState::hold_after_vars_load_failed: - an emptied dependency joins the held batch as a path; - an emptied --vars file joins as a change to it, not as a path; - nothing is held when no file went empty, or when the deadline ended the hold in this rebuild (a positive control holds the same file with the deadline ahead). Test code only. Each test fails when its guard is removed: the join dropped, the --vars file not told from a path, the deadline ignored, the watched set empty. Co-Authored-By: Claude <noreply@anthropic.com>
compile_one_source matched the compile's result and ran the whole success path inside the Ok arm, six levels deep, with seven exits. The failures are now guard clauses ahead of it: the deleted source is retired, a failed compile is held or settled, each by a return. A source that is a partial, one whose output is unchanged, one held by the late look, one whose write is kept and one whose write failed each return in turn. What is left is the write and its record, at depth one. The two holds share DirWatchState::hold_back, which keeps what the rebuild before kept from being written and holds the source. The late look on the success path still runs only when the output would be written. Behaviour is unchanged: the same checks run in the same order, with the same effects, and no test changed. Co-Authored-By: Claude <noreply@anthropic.com>
The bullet in [Unreleased] said how a link came to be below the anchor and pointed to SECURITY.md for the residuals. It now says what a write or a removal did, and what every write and every removal does now. Only that bullet changed. The text already on main is untouched. Co-Authored-By: Claude <noreply@anthropic.com>
…gh one helper File mode and directory mode each wrote a rebuilt output in the same three ways and showed it with the same `Recompiled` line, in two copies. Each mode now calls one function for each step. - `write_rebuilt` refuses an out-dir that the typed path now leads elsewhere from. After a change of kind it writes only over a file the session wrote, and else keeps the file. Any other write goes below the checked out-dir and never over a file the compile read. It returns `Rewritten::Written`, `Rewritten::Kept` or the failure. - `announce_recompiled` shows the `Recompiled` line, then the notice for an output the write emptied. - Each mode keeps its own record of what it wrote, its own retirement of the other kind's output, and its own handling of a kept or failed write. Stdout stays in file mode: it has no out-dir and no change of kind. - The late look does not move. File mode takes one look before it uses the compile's result, for every outcome. Directory mode takes one look after the dedup, only when the output would be written. Each look stays where it was, so no gating parameter is needed. The behaviour of both modes is the same as before. No test changed: the print-site floor and the allowlist keys of the print guard still hold. Co-Authored-By: Claude <noreply@anthropic.com>
The write funnel's Commit enum took a type parameter for the stamp a rewrite is held to. Every use gave it the platform's own stamp reference, so the parameter named one type in every place. Replace(Option<&Stamp>) now names that type directly, and every signature that took Commit<'_, &Stamp> takes Commit<'_>. The unix and windows modules keep their own Stamp; the enum reaches it through the platform alias. No behaviour changes and no test changes. Co-Authored-By: Claude <noreply@anthropic.com>
A watch compile ran inside a panic catch at two places: the compile of a watched path, and the compile of a dependency outside the root. Each site repeated the same catch, the same default options and the same mapping of a panic and an error to a compile failure. compile_caught is now the one place a watch compile runs, so it is the one place a panic in it is caught. Both sites call it. Their order of checks and what they report do not change. The panic-catch pin in panic_hook.rs lists one watch.rs place, compile_caught, in place of the two it listed before. No other test changes. Co-Authored-By: Claude <noreply@anthropic.com>
Directory watch threaded a batch as a pair, its paths and whether one of them changed the --vars file, and rebound the pair three times as the look, the hold and the release each returned a new one. Batch holds the two. join_emptied and HeldBatch::release return one, and HeldBatch::hold takes one, so each step names the batch it works on and the rebinds are plain shadowing of one value. A batch kept for the next one while no hold runs, because the --vars file could not be read, is carried (HeldBatch::carry), not held; the two keep a batch the same way and release it the same way. rebuild_dir_batch keeps its signature. The unit tests that called hold, release, join_emptied and hold_after_vars_load_failed follow the new signatures and assert the same paths and flags. No behaviour changes. Co-Authored-By: Claude <noreply@anthropic.com>
The result sink's other failure methods are verbs: setup_failed, failed, write_failed and panicked. analysis_failure was a noun. It is now analysis_failed, in the trait, the human and JSON sinks, the recording sink of the lint unit tests and the doc lines that name it. The helper in lint.rs that shows the error and returns the exit code already had that name and keeps it. Output, exit codes and every lint golden are unchanged. Co-Authored-By: Claude <noreply@anthropic.com>
process_dir_batch, its two passes and compile_one_source each took the watched directory, the output base, the batch's variables and --quiet as separate parameters: seven parameters for the first, the clippy limit, and six for each of the others. BatchCtx holds the four. run_dir_batch builds it once for a batch, from the session's context and the variables it has just resolved, and each function takes it with the changed paths and the state. The unit tests that call process_dir_batch and process_dir_batch_incremental build one in place of the four arguments. No behaviour changes. Co-Authored-By: Claude <noreply@anthropic.com>
Directory watch derived what a path is in four places: the event filter, the batch's source lists, the compile dispatch and the deleted-source retirement. Each place used its own mix of the starts_with, extension, excluded-directory, partial and external-directory tests. classify(root, path, external_dirs) is now the one answer, a Node: Source, Partial, InRootModule, ExternalDep, ExcludedDep or Unrelated. The event filter, the incremental batch's dispatch (a match on the Node, with the dependency refresh as refresh_dependency) and retire_deleted take it. names_a_source is the source view of it, for the callers that hold no external directories. No behaviour changes. Tests that cover it run unchanged: the unit tests of the batches, the idle tick and the ghost dependency prune, and cli_watch. tests/print_discipline.rs: the path-text table no longer lists handle_fs_event_dir. The extension comparison it pinned moved into has_mds_extension, which compares the extension without turning it into text, so the listed count was no longer true. The rule and its assertions are unchanged. output.rs: the doc of is_within_default_excluded_dir names classify as its caller. Co-Authored-By: Claude <noreply@anthropic.com>
…, not only at the tick The event filter of a directory watch took .mds paths alone. An edit to a type: mds .md module that a source imports, below the directory argument or outside it, named no rebuild: only the idle tick's content check found it, and with --poll-interval 0, which runs no tick, nothing rebuilt the importers until one of them was edited. The filter now also takes any file a source imports (a graph-key lookup in the dependencies the sources recorded, built once per event and only when a path is no .mds file in scope). A file no source imports, such as a README.md beside the sources, still names no rebuild. The batch rebuilds the importers and, as before, never compiles the module as a source. Tests: - cli_watch: watch_dir_mode_event_rebuilds_the_importer_of_an_md_module_below_or_outside_the_root runs at --poll-interval 0 and edits one module below the root and one outside it; it failed before the fix at the first edit. - watch.rs unit test an_event_for_an_md_file_rebuilds_only_when_a_source_imports_it. - The tick test for the same module gets a barrier before its check that the module is never compiled, so an output written later in the batch cannot slip past, and its doc says that either the event or the tick delivers the edit. Docs: one CHANGELOG Fixed bullet; the older bullet for the module no longer says the tick alone finds it; one README directory-watch bullet for .md modules. The doc of a unit test no longer says the event path keeps .mds paths alone. Co-Authored-By: Claude <noreply@anthropic.com>
…ot that is no source A rebuild with a change compiled every affected dependency outside the root, or in a directory the walk skips, as an entry, quietly, to refresh its own edges. A type: mds .md module outside the root that was edited into a plain .md (or emptied) is no MDS file, so that compile failed: the module was marked errored and refused under its own canonical path. Errored files are seeded into every later rebuild with a change, so the same refusal printed again in each of them, next to the refusal of each source that imports it. Such a dependency is now left to its importers, as a module below the root is: only a dependency that is a .mds file gets the quiet refresh. The edges from the importers to it stay, so the edit that makes it a module again still rebuilds them. Test: cli_watch watch_dir_mode_never_compiles_an_md_dependency_outside_the_root_as_an_entry edits the module into a plain .md, makes two more rebuilds with a change, repairs the module, and counts the refusals that name something other than the import as written. It failed before the fix with 14 such refusals and passes with none. Docs: one CHANGELOG Fixed bullet; the README bullet for .md modules. Co-Authored-By: Claude <noreply@anthropic.com>
The operating system sends an event that names no path when it lost events: an overflowed inotify queue, or a macOS event stream that must rescan. The directory watch kept the event's paths and dropped the fact that events were lost, so the event became an empty batch and nothing was rebuilt. A source created, a source removed, a dependency edited or a --vars edit in that gap was found only by the idle tick, and under --poll-interval 0, which runs no tick, not at all. The debounce window now carries the flag to its result, and the event handler acts on it. The idle tick's look for changes it was not told of is one function, scan_directory: the content check of the watched files and, with walk, the walk that finds sources that appeared or were removed. The tick calls it as before. An event that says events were lost calls it with the walk, and its findings join the batch of the event. Test: watch::tests::a_rescan_event_finds_what_the_lost_events_would_have_said creates a source and edits the --vars file with no event, then sends a rescan event as the first event of a batch and as an event of its debounce window. It failed before the fix on "the rescan event rebuilds" and passes with the source built and the vars edit rebuilt. A control in it shows that an event with no path and no flag rebuilds nothing. watch::tests::a_debounce_window_keeps_that_an_event_said_events_were_lost covers the flag in the window. Docs: one CHANGELOG Fixed bullet; a README bullet for lost events. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem being solved
mds-cli's output and watch layer crashed on closed pipes, leaked raw panic text and absolute paths, followed planted symlinks on writes and deletes, deleted hand-written files in directory watch, published empty outputs mid-save, and hid lint output bugs behind duplicated code paths.
Progress
wait_for_stderr_contains_strreturns the partial text on timeout, so count assertions built on it are vacuous #381); the cap test's skip is visible and the watch soak takes an allowlisted test input and counts skips separately (test(watch): cap test's cadence precondition fails CI on loaded runners #397)mds lintCLI per-file dispatch spine #173, refactor(lint-cli): lint.rs output-matrix ResultSink redesign #309)mds watch --debounce 0: an in-place editor save can compile the 0-byte truncate intermediate and leave a transiently empty output #380)Test Plan
Closes #157
Closes #389
Closes #390
Closes #160
Closes #309
Closes #173
Closes #380
Closes #381
Closes #397
Closes #256
Closes #257