Both numbers an interface is laid out against used to be taken on trust: the
size the terminal reported, and the one column per glyph that a layout measured
in columns pays for. On the Windows console in front of us, both were wrong,
and both failures arrive at the same place — cells written past the end of a row
reappear at the start of the next one, so the screen becomes several copies of
itself at several offsets and looks like a renderer that cannot count.
`squid-platform::console` measures instead of trusting. It asks three questions
because a console has three ways to be too optimistic — the window, the buffer
behind it, and the largest window it could show at all — and it asks them of the
buffer being *shown*, because entering the alternate screen on a legacy console
activates a second buffer while the process keeps holding the handle it started
with, which then describes a screen nobody is looking at. A window wider than
the cells that exist is where the wrapping starts, so `repair` asks the console
for the cells it does have; a window that slid down its own scrollback moves the
picture without moving the size, which is why the renderer watches the offset too
and wipes rather than diffs when the screen moved under it.
The second measurement is what makes a whole screen break at once. East Asian
Ambiguous characters have no agreed price, and a console left on a Far-Eastern
code page charges two cells for exactly the class of characters an interface is
built out of: the rules, the shading, the arrows, the ticks, the middot. ratatui
charges one, so every row of the layout is longer than the glass by the symbols
it contains. `symbol_cells` writes one box-drawing bar and reads how far the
cursor moved, because the two things that decide the price — code page and
font — are both set outside this program, and `chcp 65001` moves the same bar
back to one cell on the box that charges two.
`squid-tui::glyphs` then rewrites the finished frame one column for one column:
the rules become `|-+`, the gauges `#`, the arrows `<^>v`, so the rows fit
without the layout moving at all. Chinese text and ordinary letters are left
alone — neither is ambiguous, so neither caused the overflow, and a person's
paths and process names are not what an alignment bug should be allowed to
rewrite. `SQUID_SYMBOL_CELLS` overrides the measurement for the case the
measurement cannot reach: over ssh this program measures the console sshd made
for it, not the one on the glass. `SQUID_CONSOLE_TRACE` writes the two buffer
answers side by side, since a hand-made resize leaves no other evidence.
`cargo fmt --all --check` had opinions about three call sites that were already
wide enough to need breaking, and the incoming Windows work touches all three
files. Split off so the commits after this one contain only the changes they
are about.
`win-tui-capture.sh` drives the real binary over `ssh -tt`, which is the only
way to render the TUI the way a Windows console does: sshd allocates a
pseudoconsole, crossterm takes its Windows backend, and the bytes it emits are
decoded back into a frame locally. The existing smoke script cannot do this
because it forks its own pty, which is POSIX-only.
It now takes a key sequence, so the interesting case — a populated list, not an
empty panel — is the one that gets checked, and it keeps the fullest frame
rather than the last one, because quitting wipes the screen. It reports where a
replacement character appeared, since mid-stream means the console could not
draw the glyph and at the tail only means ssh truncated a frame on disconnect.
`win-hwcheck.ps1` measures the volume before and after a real deletion, counts
entries in the shell's Recycle Bin, and asserts the two agree; that is what
caught the missing undo flag. Its fixtures clean themselves up.
Windows moves from "cross-compile only" to verified on real hardware in the
roadmap. UAC elevation, the long-path manifest, and publishing stay pending.
Found by pointing the hardware checks at the binary they were meant to test.
`purge --json --yes` printed a human plan on stdout before its JSON, so the
first thing a machine reading that output saw was `Invalid JSON primitive`.
The design already had the right rule — `diag`/`shout`/`heading` go to stderr
under `--json` — but anything that printed an already-formatted line bypassed
it. `say` is now that one writer, and the `\r` progress spinner writes to
stderr whenever `--json` owns stdout, so a progress bar can no longer land
inside a document.
Being quiet on stdout is only useful if the document is still complete, and it
was not: the early return was conditioned on `!yes`, so `--json --dry-run`
printed no JSON at all, and the nothing-to-do paths returned before the
summary existed. Both now emit one document; `undo` keeps its own shape because
it always reaches the remove plan and would otherwise print twice.
`undo` also lied. It reported "1 could not be put back (path in use)" for every
entry, because the ledger's recycle-bin destination is always empty on Windows:
`IFileOperation` moves the file and the shell takes over the bookkeeping, so
squid never has a destination to move back from. The run had succeeded. It now
checks the session's mode and says the true thing — those files are in the
Recycle Bin, restore them there.
Finally, the copy that named the wrong operating system: `--trash` help, the
confirmation prompt, `history` and `doctor` all said Trash on a box whose shell
says Recycle Bin. The history column widens for the longer name instead of
eliding it.
Measured by driving the real binary through a pseudoconsole that sshd hands out
(`scripts/win-tui-capture.sh`), then decoding the bytes it emitted.
The lock glyph was U+1F512. Every astral-plane character comes back out of a
conhost/ConPTY session as U+FFFD followed by the glyph, i.e. one cell too many,
which shifted every locked row in the list by one column. `⊘` is in the BMP,
one cell wide, and survives the same session; the other glyphs in use were
checked the same way.
A row wider than its card used to spill: `joined` collapsed the filler to
nothing and the terminal cut off whatever came last, which is the right half —
the delete mode the user is about to act on. Now the left half yields, giving
up whole spans before cutting one in half. This is what the longer Windows name
for the recycle bin exposed at 100 columns, where "empties only with the
Recycle Bin" had swallowed "delete to · Recycle Bin" whole.
The status row's trailing note is the one part of that line the user is not
acting on, so it is dropped rather than allowed to push the mode off the card.
Both languages were re-checked on the box afterwards: no replacement characters
left, and the note still shows wherever it fits.
`the_recycle_bin_is_called_what_the_os_calls_it` pins the new copy rule; the
group-name test now expects the operating system's word for that one group,
which is why it fails on Windows and passes on macOS until the rule is stated.
Three things the interface used to assume from its own build rather than from
the machine it was on.
`device()` says whether to address the user's machine as a Mac, a PC, or a
machine. The status line asked the locale, so the Chinese interface on a
Windows box told people to press `s` to scan 这台 Mac.
`bin_noun()` says what the operating system calls the place deleted files wait
in. Windows calls it the Recycle Bin and has no Trash folder to open, so copy
promising "empty the Trash" there sends the user to a control that does not
exist — in the header, in the mode chip, in the group list, in `history`, in
`doctor`, and in the `--trash` help.
`trash_target()` for Linux now resolves the XDG Trash instead of falling back
to "no trash here", which made `doctor` claim deletions were permanent on any
desktop that does have one.
`windows_allocation` built its UTF-16 argument with `to_string_lossy`, so a
path that an `OsString` can hold but a `String` cannot arrived at
`GetCompressedFileSizeW` with replacement characters in it, and any path past
the 260-character legacy limit was answered with `ERROR_PATH_NOT_FOUND` — the
deep `node_modules` trees this tool exists to measure cross that line
routinely. `wide_path` keeps every UTF-16 unit and adds the verbatim prefix
only where it is honest (absolute, no `.` or `..`), because the prefix also
switches off normalisation.
The scratch-directory fixture now removes itself even when an assertion
panics halfway through. That is not housekeeping: a file extended with
`set_len` is charged as if written in full, and one surviving fixture sat on
the test machine's disk at 11 GB — in `AppData\Local\Temp`, where squid then
correctly offered it back as junk.
`FileStandardInfo.AllocationSize` turned out to be the wrong question. Measured
against `fsutil` and `compact` on a real Windows 10 volume:
- it returns the cluster-rounded logical length for ordinary files, including
1 GiB files extended by `SetEndOfFile` (NTFS does hand over the whole tail,
and free space moves accordingly) and sub-cluster files living in `$MFT`;
- it reported the full 8 MiB for a file `compact` accounts as 1,572,864 stored
bytes, i.e. it is blind to NTFS compression, which is the one way Windows
really does hide size on disk;
- `FSCTL_QUERY_ALLOCATED_RANGES` reported that same compressed file as fully
allocated, so "which clusters exist" is not "what do they weigh".
`GetCompressedFileSizeW` answers 1,572,864, matching `compact` byte for byte.
It takes the path we already hold instead of a handle, so it is one query per
file rather than a `CreateFileW` pair, and it keeps answering while another
process holds the file open exclusively — the normal state of a cache file.
That also removes the `ALLOCATION_PROBE_MIN` cutoff: it existed to avoid a
handle per small file, and small files on a compressed volume need the honest
number just as much.
Guard the zero answer behind `FILE_ATTRIBUTE_COMPRESSED`/`SPARSE_FILE` (free
from the `Metadata` we already have) so a deleted-but-still-open file cannot
zero out a total the user is about to act on, and read `GetLastError` to tell
failure from a genuine 4 GiB-minus-one length.
Tests: each platform now gets the fixture that provokes its own divergence —
POSIX holes for `st_blocks`, and a `compact`-compressed file for the Windows
path. The old Windows sparse fixture proved nothing: extending a file does not
hole out on NTFS, and `FSCTL_SET_SPARSE` is refused outright on this volume
(`ERROR_INVALID_FUNCTION`), as is `FSCTL_SET_COMPRESSION`
(`ERROR_ACCESS_DENIED`) even for a file we created ourselves.
The purge test compared rendered path strings against `demo/node_modules` and
friends, so on Windows every positive assertion failed and the negative one —
`loose/dist` must not be offered — passed for the wrong reason. Assertions now
compare trailing components, which is what they meant all along and holds on
both separators.
`category_index` made the same assumption in production: it lowercased the path
and looked for `/library/caches`, so a leftover root was only ever reclassified
on the OS whose separator it was written for.
Real Windows 10 hardware turned up two failures the macOS and cross-compile
checks could not see:
- squid-core::fs reported every file's logical length as its allocated size,
because `allocated_bytes` returned 0 on non-Unix and `on_disk()` then fell
back to logical. NTFS only answers the allocation question through a handle,
so ask `GetFileInformationByHandleEx(FileStandardInfo)` for files big enough
to distort a total. Files below the cutoff keep counting as their length,
which is also what keeps MFT-resident entries — they report an allocation of
0 — from shrinking a cache cleanup down to nothing.
- the "a plain user can still uninstall into /Applications" safety test hard
coded a Unix path, so on Windows it asserted that a folder the policy never
looked at was refused. The fixture now comes from the policy's own shared
install folder, `/Applications` on Unix and the machine-wide program-data
folders on Windows.
Also added:
- `a_written_file_reports_what_the_volume_gave_it`, the cross-platform
invariant the missing backend silently violated.
- the sparse-file test now marks its file sparse via `fsutil` on Windows and
skips when the volume will not cooperate, instead of pretending a hole
exists.
- `scripts/win-sync.sh`, `scripts/win-check.ps1` and `scripts/win-hwcheck.ps1`
for iterating against a LAN Windows host over SSH without git credentials.
- new squid_core::elevation_hint(): sudo on Unix, elevated Administrator
terminal on Windows; used by the locked-item notes in clean/uninstall
and the user-only safety refusal.
- the Permission error no longer tells Windows users to grant Full Disk
Access (a macOS-only concept).
- paths: platform-semantic comparisons. Component keys are lower-cased
and canonical \\?\\ verbatim prefixes folded away on Windows, so
is_within/same_path/depth_below/relative_below match how the OS
actually resolves paths; pretty() got the same treatment.
- safety: drive roots and UNC roots are hard-denied (is_root_like);
Windows hard-deny grows env-derived entries (SystemRoot, ProgramFiles,
ProgramData, USERPROFILE, ...); DENY_EXACT gains the AppData tree and
shell folders; OUTSIDE_HOME_OK becomes platform-supplied
(%ProgramData%, %PUBLIC% mirror /Applications); a path containing
$Recycle.Bin / System Volume Information / Recovery is always refused;
the canonicalize-vs-expected symlink probe now compares with
platform semantics instead of raw equality.
- rules: $VAR heads stop at backslashes too; ${VAR} resolves in every
occurrence; glob component matching is case-insensitive on Windows;
protect patterns normalise \\ to / so protections keep working there;
anchor_for keeps drive prefixes instead of bailing out, and folds
Prefix+RootDir into a rooted C:\ anchor.
- rules/windows.toml: 30 rules for Win10/11 (temp, WER/crash dumps,
browser caches, shell caches, dev caches, Windows.old, Package Cache)
embedded under cfg(windows) and parse-checked on every host.
- squid-core: trash moves behind a platform seam — Windows recycles via
IFileOperation (shell owns $Recycle.Bin bookkeeping; ledger records no
physical path there), Unix keeps the rename/copy path untouched
- squid-core: default cleanup anchors per platform; Unix-only helpers
(getuid, statvfs-style trash dirs, symlink copy) gated
- squid-platform: windows.rs rewritten — installed apps from the uninstall
registry (HKLM 64/32-bit views + HKCU, SystemComponent/patch filtering),
BIOS/NT version keys for hardware/OS strings, sysinfo for volumes and
running processes; winreg replaces the PowerShell stub
- squid-stats: COMPUTERNAME hostname off-unix; battery parsers gated
- CI: .gitlab-ci.yml with a Linux job that cross-checks the whole workspace
against x86_64-pc-windows-msvc, plus a manual tagged Windows job driven by
scripts/ci-windows.ps1 (build + test on a real machine)
- host (macOS) tests, clippy -D warnings and fmt stay green