Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
"""把 Windows 真机抓回来的原始 ANSI 流还原成画面,再判断它有没有花屏。
|
|
|
|
|
|
|
|
|
|
|
|
用法:
|
|
|
|
|
|
python3 scripts/tui-frame-check.py /tmp/squid-win-tui.bin
|
|
|
|
|
|
python3 scripts/tui-frame-check.py --selftest # 判据自己的回归测试
|
|
|
|
|
|
|
|
|
|
|
|
为什么要脚本而不是让 cargo test 跑:花屏不长在数据里,长在"终端把这一串字节
|
|
|
|
|
|
摆成什么"里。crossterm 发出的是坐标 + 字形,谁收到这些字节谁才知道会不会错位,
|
|
|
|
|
|
而在 macOS/Linux 上没有任何一个终端是 Windows 控制台。所以流程反过来:
|
|
|
|
|
|
真机上的 ConPTY 收到什么,我们就原样存什么(scripts/win-tui-capture.sh),
|
|
|
|
|
|
回到本地用 pyte 这个终端仿真器把它重放成画面,再量画面。
|
|
|
|
|
|
|
|
|
|
|
|
判据本身在 geometry() 里,它只认结构不认内容:边框必须横平竖直。
|
|
|
|
|
|
"""
|
|
|
|
|
|
import re
|
|
|
|
|
|
import sys
|
|
|
|
|
|
import unicodedata
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
import pyte
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
sys.exit("需要 pyte: pip3 install pyte")
|
|
|
|
|
|
|
|
|
|
|
|
# 能合法出现在一行之末的只有竖线和拐角。横线(─═-)只配当"这行属于某个框"的线索
|
|
|
|
|
|
# —— 半帧里 ╰──── 刚画了一半,尾巴就是根横线,把它当右边框会冤枉一幅好画面。
|
|
|
|
|
|
BORDER = '│┃|+╭╮╰╯┌┐└┘╔╗╚╝'
|
|
|
|
|
|
ANCHOR = BORDER + '─═-'
|
|
|
|
|
|
|
|
|
|
|
|
# 一行至少要占这么多个格子才算"框的一行"。绘制中间态的残行(ratatui 刚把这行的
|
|
|
|
|
|
# 左边界写下去、正文还没画到)一定很短,rstrip() 之后更是短得离谱;而真正排错了的
|
|
|
|
|
|
# 行只会太长、不会太短 —— 溢出是把行推到行尾之外,不是把它缩短。所以短行一律不看,
|
|
|
|
|
|
# 半帧就再也冤枉不了一幅好画面。
|
|
|
|
|
|
MIN_ROW = 8
|
|
|
|
|
|
|
|
|
|
|
|
# 界面一起步就画二十几行。少于这个数的画面是程序还没跑起来(屏上只有一行标记),
|
|
|
|
|
|
# 拿"屏上没有边框"去判它们,是把等待判成故障。
|
|
|
|
|
|
PAINTED = 8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cells(ch):
|
|
|
|
|
|
"""这个字符在终端里占几格。
|
|
|
|
|
|
|
|
|
|
|
|
列号不能数 len():屏上一个汉字占两格,pyte 的 display 却只在串里留一个字符,
|
|
|
|
|
|
数字符会把带中文的行少算几十列,一幅整齐的界面同样被读成"右边框散落四处"。
|
|
|
|
|
|
"""
|
|
|
|
|
|
return 2 if unicodedata.east_asian_width(ch) in ('W', 'F') else 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def column_of_right_border(line):
|
|
|
|
|
|
"""行里最后一个边框字符落在第几列(从 0 数)。"""
|
|
|
|
|
|
col, edge = 0, -1
|
|
|
|
|
|
for ch in line:
|
|
|
|
|
|
if ch in BORDER:
|
|
|
|
|
|
edge = col
|
|
|
|
|
|
col += cells(ch)
|
|
|
|
|
|
return edge
|
|
|
|
|
|
|
|
|
|
|
|
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
def border_columns(line):
|
|
|
|
|
|
"""行里每一个边框字符落在第几列(从 0 数)。
|
|
|
|
|
|
|
|
|
|
|
|
只量"最右边那个边框字符"的列,会把并排的两个框读成一幅画:左栏在 31 列收口、
|
|
|
|
|
|
面板在 140 列收口,一行之上两个收口点都存在,量到的永远是右边那个。要知道这一行
|
|
|
|
|
|
到底属于哪个框,得把它全部的边框列都记下来。
|
|
|
|
|
|
"""
|
|
|
|
|
|
col, out = 0, []
|
|
|
|
|
|
for ch in line:
|
|
|
|
|
|
if ch in BORDER and (not out or out[-1] != col):
|
|
|
|
|
|
out.append(col)
|
|
|
|
|
|
col += cells(ch)
|
|
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
def geometry(lines, cols):
|
|
|
|
|
|
"""量一帧,返回(问题列表, 给人看的说明, 这一帧值不值得判)。
|
|
|
|
|
|
|
|
|
|
|
|
花屏只有两种走样:两张画叠在一起(窗口尺寸变了却没重画),或者行写过了行尾、
|
|
|
|
|
|
被换行挤到下一行开头 —— 而"一列的字符被控制台收了两格价"正是这么坏掉的:
|
|
|
|
|
|
ratatui 以为这行正好 100 列,终端却按 118 格排版。两种走样都会破坏同一件事:
|
|
|
|
|
|
所有右边框落在同一列,且没有一行的右边框被挤到行尾之外。
|
|
|
|
|
|
"""
|
|
|
|
|
|
problems, notes = [], []
|
|
|
|
|
|
box_rows, strays, torn = [], [], []
|
|
|
|
|
|
for n, line in enumerate(lines, 1):
|
|
|
|
|
|
stripped = line.rstrip()
|
|
|
|
|
|
if not stripped:
|
|
|
|
|
|
continue
|
|
|
|
|
|
# 哪些行算边框行:不能拿"行里最右边的边框字符"当右边框。边框在不同价格下
|
|
|
|
|
|
# 是不同的字符 —— 一格收一笔的终端画 │,两格收一笔的终端退化成 | —— 而 |
|
|
|
|
|
|
# 同时也是正文里的普通字符(路径、分隔符、页脚)。用 rindex 找它,会把正文
|
|
|
|
|
|
# 里一个无辜的竖线当成第 76 列的"右边框",整齐的界面被判成花屏。
|
|
|
|
|
|
# 真正贴着框的行,第一个字符就是边框字符:左边界贴着屏幕最左边。
|
|
|
|
|
|
if stripped[0] in ANCHOR:
|
|
|
|
|
|
box_rows.append((n, stripped))
|
|
|
|
|
|
continue
|
|
|
|
|
|
if any(ch in stripped for ch in '│┃|'):
|
|
|
|
|
|
strays.append(n)
|
|
|
|
|
|
# 一行正文压在边框行上的样子很好认:不是边框行,却以一长串横线收尾 ——
|
|
|
|
|
|
# 那些横线是被 Clear 挖剩下的边框。toast 曾经画在卡片底边框那一行,于是
|
|
|
|
|
|
# 屏上出现"功能菜单 — 上下键选择,回车返回 ----------╯"这种半是句子半是
|
|
|
|
|
|
# 框的东西,用户看到的正是"重叠"。自己起手的边框行不算(上面已经 continue):
|
|
|
|
|
|
# 带标题的 ╭ squid ────╮ 本来就是这个样子。
|
|
|
|
|
|
if stripped[-1] in BORDER and re.search(r'[-─═]{8,}', stripped):
|
|
|
|
|
|
torn.append((n, stripped))
|
|
|
|
|
|
|
|
|
|
|
|
edges, ragged, stubs = {}, [], 0
|
|
|
|
|
|
for n, stripped in box_rows:
|
|
|
|
|
|
width = sum(cells(ch) for ch in stripped)
|
|
|
|
|
|
if width < MIN_ROW:
|
|
|
|
|
|
stubs += 1
|
|
|
|
|
|
elif stripped[-1] in BORDER:
|
|
|
|
|
|
edges.setdefault(column_of_right_border(stripped), []).append(n)
|
|
|
|
|
|
elif width >= cols:
|
|
|
|
|
|
# 已经写到屏幕最右边,尾巴上却没有边框 —— 边框被挤到行尾之外了。
|
|
|
|
|
|
ragged.append((n, stripped))
|
|
|
|
|
|
else:
|
|
|
|
|
|
stubs += 1
|
|
|
|
|
|
|
|
|
|
|
|
if not edges and not ragged and not torn:
|
|
|
|
|
|
return [], [], False # 整帧没有可判的边框行:多半是绘制中间态
|
|
|
|
|
|
if torn:
|
|
|
|
|
|
for n, stripped in torn[:2]:
|
|
|
|
|
|
notes.append(f"[frame ] 第 {n} 行正文压在边框上: {stripped[:26]!r}…{stripped[-12:]!r}")
|
|
|
|
|
|
problems.append(f"有 {len(torn)} 行正文压在边框行上、把边框截成了一段横线 —— 重叠")
|
|
|
|
|
|
|
|
|
|
|
|
hist = ", ".join(f"第{c + 1}列x{len(v)}" for c, v in sorted(edges.items())) or "无"
|
|
|
|
|
|
judged = sum(len(v) for v in edges.values()) + len(ragged)
|
|
|
|
|
|
notes.append(f"[frame ] 边框行 {judged} 行(跳过未画完 {stubs}) · 右边框所在列: {hist} · "
|
|
|
|
|
|
f"含竖线的正文行 {len(strays)} 行(不计入)")
|
|
|
|
|
|
if ragged:
|
|
|
|
|
|
for n, stripped in ragged[:2]:
|
|
|
|
|
|
notes.append(f"[frame ] 第 {n} 行右边界缺失: ...{stripped[-20:]!r}")
|
|
|
|
|
|
problems.append(f"有 {len(ragged)} 行左边框在、右边框却被挤没了 —— 行写过了行尾")
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
# 右边框不止一列,有两种解释,只有一种是病。
|
|
|
|
|
|
#
|
|
|
|
|
|
# 界面天生就是好几个框并排画的:左栏收在第 31 列,面板一直画到第 140 列。
|
|
|
|
|
|
# 于是"左栏比面板长"的那些行,行尾落在第 31 列 —— 这是合法布局里最常见的一种,
|
|
|
|
|
|
# 而按"所有右边框必须落在同一列"去判,它每一拍都是花屏。
|
|
|
|
|
|
# 合法的真正特征不是宽度相等,而是"截短":短行的每一个边框列,宽行上也都有。
|
|
|
|
|
|
# 左栏行 {0,30} 的两条边,面板行 {0,30,31,139} 里都找得到 —— 它看起来就是那幅
|
|
|
|
|
|
# 宽画被从右边切掉一截的样子,而切掉一截正是 ratatui 少画一个框时的行为。
|
|
|
|
|
|
# 真叠帧坏在另一件事上:窄框(70 列)接在宽框(100 列)下面时,它的右边框落在
|
|
|
|
|
|
# 第 69 列,而宽框那一行从来没有第 69 列。这一列是凭空冒出来的,只能来自另一幅画
|
|
|
|
|
|
# —— 尺寸变了却没重画,新旧两版叠在同一屏上,就是用户说的"重叠"。
|
|
|
|
|
|
widest = max(edges, default=-1)
|
|
|
|
|
|
frame = set()
|
|
|
|
|
|
for _, stripped in box_rows:
|
|
|
|
|
|
if column_of_right_border(stripped) == widest:
|
|
|
|
|
|
frame.update(border_columns(stripped))
|
|
|
|
|
|
strangers = [n for n, stripped in box_rows
|
|
|
|
|
|
if any(c not in frame for c in border_columns(stripped))]
|
|
|
|
|
|
# edges 为空 = 没有任何一行画出了右边框,那正是 ragged 在管的事,
|
|
|
|
|
|
# 这里再插一句"叠帧"只是把同一个毛病换名再报一遍。
|
|
|
|
|
|
if edges and strangers:
|
|
|
|
|
|
for n in strangers[:2]:
|
|
|
|
|
|
line = dict(box_rows)[n]
|
|
|
|
|
|
extra = [c for c in border_columns(line) if c not in frame]
|
|
|
|
|
|
notes.append(f"[frame ] 第 {n} 行有宽框上不存在边框列 {extra}: {line[:26]!r}…")
|
|
|
|
|
|
problems.append(f"有 {len(strangers)} 行的边框列在最宽那一行上根本不存在"
|
|
|
|
|
|
" —— 屏上有两幅不同尺寸的画叠着")
|
|
|
|
|
|
if edges:
|
|
|
|
|
|
if widest + 1 > cols:
|
|
|
|
|
|
problems.append(f"右边框在第 {widest + 1} 列,超出 {cols} 列")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
else:
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
notes.append(f"[frame ] 画面宽 {widest + 1} 列(窗口 {cols} 列)")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
return problems, notes, True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def analyze(raw, echo=True):
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
"""重放整条流,量每一个画稳的画面,返回问题列表(空 = 没花屏)。
|
|
|
|
|
|
|
|
|
|
|
|
"画稳"在这份文件里是有定义的:同一幅画面顶住 SETTLE 字节的写入不变。
|
|
|
|
|
|
"""
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
reported = re.search(r'MARK_STARTED\s+(\d{1,4})\s*x\s*(\d{1,4})', raw)
|
|
|
|
|
|
if reported:
|
|
|
|
|
|
cols, rows = int(reported.group(1)), int(reported.group(2))
|
|
|
|
|
|
else:
|
|
|
|
|
|
cols, rows = 120, 30
|
|
|
|
|
|
print("[size] !!! 流里没有 MARK_STARTED,退回 120x30 仿真(结论不可信)")
|
|
|
|
|
|
print(f"[size] 控制台实际 {cols}x{rows}")
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
# 代码页要印出来:同一个二进制在 65001 和 936 下可以是两幅画 —— 代码页决定
|
|
|
|
|
|
# "没被问到"的字符按几格算,而用户那个窗口就站在 936 上。一帧是在哪个代码页上
|
|
|
|
|
|
# 抓的,结论就只对那个代码页成立,所以这件事必须写在报告的第一行。
|
|
|
|
|
|
codepage = re.search(r'MARK_CODEPAGE\s+(\d+)', raw)
|
|
|
|
|
|
print(f"[size] 代码页 {codepage.group(1) if codepage else '未知(旧版抓帧脚本)'}")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
|
|
|
|
|
|
def render(data):
|
|
|
|
|
|
screen = pyte.Screen(cols, rows)
|
|
|
|
|
|
pyte.Stream(screen).feed(data)
|
|
|
|
|
|
try:
|
|
|
|
|
|
lines = [l.rstrip() for l in screen.display]
|
|
|
|
|
|
except IndexError:
|
|
|
|
|
|
# 这一帧正好喂到被截断的半个字符上,pyte 量宽度时会越界。跳过它。
|
|
|
|
|
|
return []
|
|
|
|
|
|
while lines and not lines[-1]:
|
|
|
|
|
|
lines.pop()
|
|
|
|
|
|
return lines
|
|
|
|
|
|
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
# 只对"画稳了"的画面下判据 —— 半张画当然缺右边界,拿它判花屏是自己冤枉自己。
|
|
|
|
|
|
#
|
|
|
|
|
|
# 这里原来写的是"同一个画面被采到第二次就算画稳",听着顺理成章,其实是错的:
|
|
|
|
|
|
# 一次绘制在流里是一整段连续的写入(实测切面板那一次是 34688→37376,2.7 KB 一个
|
|
|
|
|
|
# burst),而采样每 64 字节一刀;一行中文要占掉 190 字节上下,也就是三刀。半张画
|
|
|
|
|
|
# 被连着采到两三次是必然发生的事,根本不是"画完了"的证据。真机那条流里,"进程卡片
|
|
|
|
|
|
# 压在历史面板上"的半帧有 33 个,每一个只顶住 64~192 字节的写入;而真正画完的画面
|
|
|
|
|
|
# 在两次绘制之间稳稳站住 1024~3840 字节(界面每一拍都在重画同一幅画,只有样式在动,
|
|
|
|
|
|
# 屏上的字却没变)。所以判据看的是寿命:一幅画要顶住 SETTLE 字节的写入不变,才算
|
|
|
|
|
|
# 画完过、终端真的停在那儿过 —— 用户在屏上能看见的,只有这种画面。
|
|
|
|
|
|
#
|
|
|
|
|
|
# 不用时间戳:流里压根没有时刻,能信的只有字节数。这条判据还顺带挡掉一件事:
|
|
|
|
|
|
# 流尾长度不是 step 的整数倍时,最后几刀采到的是同一份字节,旧判据会把它们
|
|
|
|
|
|
# 当成"画稳了",等于给一条被切短的流发合格证。
|
|
|
|
|
|
step, SETTLE = 64, 512
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
frames = [tuple(render(raw[:cut])) for cut in range(step, len(raw) + step, step)]
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
|
|
|
|
|
|
def painted(frame):
|
|
|
|
|
|
return sum(1 for l in frame if l.strip()) >= PAINTED
|
|
|
|
|
|
|
|
|
|
|
|
# 把采样按"同一幅画连着被采到"切成段:段长 = 这个画面顶住了多少字节的写入。
|
|
|
|
|
|
runs = []
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
for frame in frames:
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
if runs and runs[-1][0] == frame:
|
|
|
|
|
|
runs[-1][1] += step
|
|
|
|
|
|
else:
|
|
|
|
|
|
runs.append([frame, step])
|
|
|
|
|
|
lived = [run for run in runs if painted(run[0])]
|
|
|
|
|
|
stable = [frame for frame, span in lived if span >= SETTLE]
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
|
|
|
|
|
|
# 退出时 TUI 会擦掉整屏(crossterm 的 Clear + LeaveAlternateScreen),所以"最后
|
|
|
|
|
|
# 一帧"必然是空的。给人看的那一帧取画稳的画面里内容最多的那个。
|
|
|
|
|
|
best = list(max(stable, key=lambda f: sum(1 for l in f if l.strip()), default=()))
|
|
|
|
|
|
if echo:
|
|
|
|
|
|
print("\n".join(best))
|
|
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
problems = []
|
|
|
|
|
|
# 制表符没解码出来 = 字体/代码页问题;U+FFFD = 编码链路某一环把字节弄丢了。
|
|
|
|
|
|
bad = [ch for ch in raw if ch == '\ufffd']
|
|
|
|
|
|
if bad:
|
|
|
|
|
|
at = raw.index('\ufffd')
|
|
|
|
|
|
where = ('流中间 = 控制台画不出这个字形' if at < len(raw) - 24
|
|
|
|
|
|
else '流末尾 = ssh 断开切掉半帧')
|
|
|
|
|
|
print(f"[decode] 第一个 U+FFFD 在偏移 {at}/{len(raw)}:{where}")
|
|
|
|
|
|
screen_text = "".join(best)
|
|
|
|
|
|
fbad = screen_text.count('\ufffd')
|
|
|
|
|
|
print(f"[decode] {len(raw)} 字符 · 原始流 U+FFFD {len(bad)} 个 · 屏上 U+FFFD {fbad} 个 · "
|
|
|
|
|
|
f"制表符 {'出现' if any(c in screen_text for c in '─│┌┐└┘') else '未出现'}")
|
|
|
|
|
|
for n, line in enumerate(best, 1):
|
|
|
|
|
|
if '\ufffd' in line:
|
|
|
|
|
|
problems.append(f"第 {n} 行有画不出来的字形: {line!r}")
|
|
|
|
|
|
cjk = [ch for ch in raw if 'CJK' in unicodedata.name(ch, '')]
|
|
|
|
|
|
print(f"[decode] CJK 字符 {len(cjk)} 个")
|
|
|
|
|
|
if 'panicked' in raw.lower():
|
|
|
|
|
|
problems.append("输出里有 panic 字样")
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
# 抓帧的壳子坏在程序之前。win-tui-run.ps1 一旦有语法错误,PowerShell 报完自己
|
|
|
|
|
|
# 的错就退出,屏上一个边框都不会有 —— 那会被下面读成"界面没跑起来",再往下就是
|
|
|
|
|
|
# 有人上真机去找一个根本不存在的排版 bug。这一条把案发现场直接摆出来:
|
|
|
|
|
|
# 换行符或 BOM 被谁改坏过一次,就够了两次这种空跑的调试轮。
|
|
|
|
|
|
parse = re.search(r'CategoryInfo\s*:\s*\(.*?\)[^\r\n]*', raw)
|
|
|
|
|
|
if parse:
|
|
|
|
|
|
problems.append("抓帧脚本自己没跑起来,远端 PowerShell 报的是它自己的错: "
|
|
|
|
|
|
f"{parse.group(0).strip()!r} —— 界面根本没被启动")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
if 'MARK_QUIT' not in raw:
|
|
|
|
|
|
problems.append("没有 MARK_QUIT —— 界面没退,或根本没跑起来")
|
|
|
|
|
|
|
|
|
|
|
|
checked, failures = 0, []
|
|
|
|
|
|
for frame in stable:
|
|
|
|
|
|
probs, notes, judgeable = geometry(list(frame), cols)
|
|
|
|
|
|
if not judgeable:
|
|
|
|
|
|
continue
|
|
|
|
|
|
checked += 1
|
|
|
|
|
|
if echo and (checked == 1 or probs and not failures):
|
|
|
|
|
|
for note in notes:
|
|
|
|
|
|
print(note)
|
|
|
|
|
|
if probs:
|
|
|
|
|
|
failures.append((checked, probs))
|
|
|
|
|
|
if echo and checked:
|
|
|
|
|
|
last = geometry(list(stable[-1]), cols)[1] if stable else []
|
|
|
|
|
|
for note in last:
|
|
|
|
|
|
print(note)
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
print(f"[frame ] 采样 {len(frames)} 次 · 画过的画面 {len(lived)} 幅 · "
|
|
|
|
|
|
f"顶住 {SETTLE} 字节不变的 {len(stable)} 幅 · 量过 {checked} 幅 · "
|
|
|
|
|
|
f"不合格 {len(failures)} 幅")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
for index, probs in failures[:3]:
|
|
|
|
|
|
for problem in probs:
|
|
|
|
|
|
print(f"[frame ] 第 {index} 个画面: {problem}")
|
|
|
|
|
|
problems.extend(p for _, probs in failures for p in probs)
|
|
|
|
|
|
if not checked:
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
# 没有一幅画站得住,有三种可能,都得说清楚,否则下一位又会跑到真机上
|
|
|
|
|
|
# 去找一个根本不存在的花屏:抓的那块屏一直在动(扫描进度就是这样)、
|
|
|
|
|
|
# 抓得太短(程序刚画完第一帧就退了)、或者屏上真的没画框。
|
|
|
|
|
|
longest = max([span for _, span in lived], default=0)
|
|
|
|
|
|
problems.append(f"屏上没有一幅画顶住 {SETTLE} 字节的写入不变"
|
|
|
|
|
|
f"(最长的一幅只活了 {longest} 字节),所以没有可判的画面 —— "
|
|
|
|
|
|
"要么抓的那块屏一直在动(避开扫描进度这类带进度的面板),"
|
|
|
|
|
|
"要么抓得太短(把 TUI_DELAY / TUI_HOLD 调大),"
|
|
|
|
|
|
f"要么屏上根本没画出边框(至少 {PAINTED} 行、边框行不短于 {MIN_ROW} 格)")
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
return problems
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def selftest():
|
|
|
|
|
|
"""判据自己也要能被证明会抓花屏 —— 否则它只是在给坏消息开门。"""
|
|
|
|
|
|
def card(width, height, fill=' 尚未扫描', footer=()):
|
|
|
|
|
|
top = '╭' + '─' * (width - 2) + '╮'
|
|
|
|
|
|
mid = '│' + fill + ' ' * (width - 2 - sum(cells(c) for c in fill)) + '│'
|
|
|
|
|
|
bottom = '╰' + '─' * (width - 2) + '╯'
|
|
|
|
|
|
return [top] + [mid] * height + [bottom] + list(footer)
|
|
|
|
|
|
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
def side_by_side(left, right, left_rows, right_rows):
|
|
|
|
|
|
"""左栏和面板并排,左栏比面板长 —— 用户那个 140 列窗口就是这个样子。"""
|
|
|
|
|
|
top = '╭' + '─' * (left - 2) + '╮' + '╭' + '─' * (right - 2) + '╮'
|
|
|
|
|
|
mid = ('│' + ' ' * (left - 2) + '│' + '│' + ' ' * (right - 2) + '│')
|
|
|
|
|
|
bottom = '╰' + '─' * (left - 2) + '╯' + '╰' + '─' * (right - 2) + '╯'
|
|
|
|
|
|
only = '│' + ' ' * (left - 2) + '│' # 面板已经结束、只剩左栏的那些行
|
|
|
|
|
|
return ([top] + [mid] * right_rows + [bottom]
|
|
|
|
|
|
+ [only] * (left_rows - right_rows))
|
|
|
|
|
|
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
def mid_paint(good, half, invisible=20, repeats=2):
|
|
|
|
|
|
"""一幅整齐的画站定之后又画了第二幅,而第二幅只画到一半就没有下文。
|
|
|
|
|
|
|
|
|
|
|
|
invisible 段是纯粹的 SGR + 光标移动:屏上一个字都没改,却足够让"同一幅画
|
|
|
|
|
|
连着被采到"成立 —— 旧判据要的就是这个,可它采到的仍然是半张画。
|
|
|
|
|
|
"""
|
|
|
|
|
|
return ('MARK_STARTED 140x35\r\n'
|
|
|
|
|
|
+ ('\x1b[H' + '\r\n'.join(good)) * repeats
|
|
|
|
|
|
+ '\x1b[2J\x1b[H' + '\r\n'.join(half)
|
|
|
|
|
|
+ '\x1b[0m\x1b[?25l' * invisible
|
|
|
|
|
|
+ '\x1b[2J\r\nMARK_QUIT\r\n')
|
|
|
|
|
|
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
def stream(*screens, size='100x30'):
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
"""把若干画面写成一条流。每个画面写两遍:第二遍一个字都没改,于是这幅画
|
|
|
|
|
|
在流里站住了整整一遍画面的字节数 —— 这正是 SETTLE 要看见的那件事。"""
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
out = [f'MARK_STARTED {size}\r\n']
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
for screen in screens:
|
|
|
|
|
|
body = '\x1b[H' + '\r\n'.join(screen)
|
|
|
|
|
|
out.append(body * 2)
|
|
|
|
|
|
out.append('\x1b[2J\r\nMARK_QUIT\r\n')
|
|
|
|
|
|
return "".join(out)
|
|
|
|
|
|
|
|
|
|
|
|
good = card(100, 10, footer=[' 语言 · zh(环境变量 SQUID_LANG)'] * 4)
|
|
|
|
|
|
cases = [
|
|
|
|
|
|
("整齐的界面", stream(good), False),
|
|
|
|
|
|
# 中文行:len() 只有 78 个字符,占格却是 100 —— 数 len() 的判据会误报。
|
|
|
|
|
|
("中文把 len 骗窄了", stream(card(100, 10, fill=' 12.58 MB 移入回收站后才真正释放 删除方式')), False),
|
|
|
|
|
|
# 两张画叠在一起:同一屏上出现了两种宽度的框。
|
|
|
|
|
|
("窄框和宽框叠着", stream(card(100, 10) + card(70, 6)), True),
|
|
|
|
|
|
# 一列字符被收了两格价:行被推到行尾之外,右边框整个不见了。
|
|
|
|
|
|
("右边框被挤出行尾", stream(['│' + 'x' * 99] * 12), True),
|
|
|
|
|
|
("屏上根本没画框", stream([' 没有边框的一行'] * 12), True),
|
|
|
|
|
|
# toast 画在卡片底边框那一行上留下的痕迹:句子 + 剩下的半截边框。
|
|
|
|
|
|
("正文压在边框上", stream(['╭' + '─' * 98 + '╮'] * 2
|
|
|
|
|
|
+ [' 功能菜单 — 上下键选择,回车返回 ' + '-' * 60 + '+']
|
|
|
|
|
|
+ ['│' + ' ' * 98 + '│'] * 8, ), True),
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
# 左栏 31 列 + 面板到 140 列并排,左栏比面板长四行。
|
|
|
|
|
|
# 这一条是判据自己欠的账:窗口一超过 104 列,"所有右边框必须同列"这句
|
|
|
|
|
|
# 就不成立了 —— 左栏那些比面板长的行,行尾当然落在第 31 列。
|
|
|
|
|
|
# 一幅整齐的界面因此每拍都被判成花屏。判据错了不该让真机再跑一遍,
|
|
|
|
|
|
# 所以把它写成回归:以后谁再把"并排"判成"叠帧",这里就红。
|
|
|
|
|
|
("左栏比面板长", stream(side_by_side(31, 109, 14, 18), size='140x35'), False),
|
|
|
|
|
|
# 而"窄框接在宽框下面"在 140 列窗口里同样得报:第 69 列是凭空冒出来的。
|
|
|
|
|
|
("140 列上窄框叠宽框", stream(card(100, 8) + card(70, 6), size='140x35'), True),
|
A half-drawn frame can be seen twice, so being seen twice is not evidence
The Windows box came back with a ghost: the process card of the system panel
standing on top of the history panel, in a frame our own checker had certified as
a settled interface. No such layout exists in the code — the two panels are two
rectangles of one `Layout`, and one of them is cleared before the other is drawn —
so the honest reading was that `squid-tui` was painting something nobody had ever
seen on a screen. It took a round of measurement over the archived captures to
find out that the thing lying about the interface was not the interface. It was
the sentence in `tui-frame-check.py` that decides which frames are allowed to be
judged at all, and it had been lying quietly for every capture since the checker
was written.
The sentence was: a picture counts as settled once the same screen has been
sampled a second time. It reads well — crossterm patches a diff cell by cell, so
an unfinished paint keeps changing and cannot possibly be seen twice; the moment
it stops changing, the paint must be over. What it forgets is that the sampler
walks the stream every 64 bytes while one row of this interface costs about 190
bytes of it, so three samples land inside a single row; and that a paint which
has stopped is a paint whose next bytes belong to the next paint, not a verdict.
A frame cut in half is therefore guaranteed to be sampled two or three times in a
row — the same half picture, again, with nothing drawn in between. Being seen
twice was never evidence that the paint had finished. It was arithmetic, and it
cost a round spent chasing a rendering bug that cannot be written down.
Grouping the samples by how long each screen survives says it plainly. Switching
panels is one continuous write, offset 34688 to 37376, 2.7 KB without a pause;
inside that burst the screen passes through 33 states that carry both the process
card and the history card, and every one of them survives between 64 and 192
bytes of writes. The frames a human being stood in front of survive 1024 to 3840
bytes, because an idle interface repaints the same words every tick and nothing on
screen moves — which is exactly what "the user saw that" means. Lifetime is the
measurement, and it is the only one on offer: a captured stream carries no clock,
so "for a moment" has to be spelled out in bytes.
`analyze()` now cuts its samples into runs of consecutive identical screens, where
a run's length is how many bytes of stream passed while that screen sat there
unchanged, and only screens that survived `SETTLE`, 512 bytes, are judged. 512 is
not a magic number: it is comfortably above the 192 bytes that the longest-lived
half frame in that capture managed, and comfortably below the 1024 that the
shortest real one did, on the same stream, in the same second. The report says all
of it out loud — pictures painted, pictures that rested, pictures measured —
because the ratio between those numbers is the one piece of information that tells
the next reader whether the capture was worth anything at all. A stream where
nothing rests is now reported as unanswerable, with the three reasons a stream can
be unanswerable named next to it (a screen that animates forever, a capture cut
short, a screen with no borders at all) rather than being read as a clean pass.
Both new selftest cases were also run against the previous criterion, so that this
commit can be seen to bite rather than merely to look tidy. `半张画不许下判词`
paints a clean 140-column card, lets it rest, then begins a second paint mixing a
100-column card with a 70-column one and stops there, followed by 200 bytes of SGR
and cursor movement that change not one glyph. It is the same content as
`窄框和宽框叠着` above it — which is a fault, and still reported as one, because
that one rests — and under the old criterion the invisible padding is enough to
admit it and convict the capture of two frames stacked on each other. It lived 192
bytes, and under the new criterion it is not allowed to speak. `整条流没有一幅画
站得住` points the same machinery the other way: two clean pictures, neither of
them ever resting. The old criterion certified that stream as free of problems,
which is the more dangerous direction to be wrong in, since it files a measurement
that proved nothing as a pass; the new one refuses to answer. Under the old code
both cases are judged wrongly, under the new one all twelve are right.
On the archived real captures the filter is not cosmetic. The system-panel capture
went from 82 "settled" interfaces measured to 8, out of 327 screens painted; the
long kill capture from 291 to 36, out of 1198; the 140-column clean capture from
101 to 8, out of 376. All of them still come back with zero failures, which is the
point: not one verdict got worse, and every screen that no user ever saw is gone
from the docket. Sweeping every capture left in /tmp turned up one more fact worth
writing down — of the screens that the geometry rule has ever convicted, not one
survived more than 320 bytes. Every conviction this tool has ever handed down came
from a frame caught mid-sentence, which is why the overlap class of bug now has its
regression case in the selftest, where the picture is written twice on purpose and
therefore rests.
What the change gives up, named rather than glossed: a panel that animates for as
long as it is open — a scan progress line is the obvious one — never rests, so a
capture of it is now "cannot judge" instead of a verdict, and the handful of 10 KB
start-and-quit captures in /tmp moved to that verdict. That is a real narrowing.
The way through it is a marker inside the stream, since the interface knows when a
draw ended and the checker cannot infer it from bytes alone, and that belongs to a
round allowed to touch `squid-tui` and `win-tui-capture.sh`; this one only stops the
checker from inventing screens. No Rust changed: 190 tests, `cargo fmt --check`
clean.
2026-10-16 04:02:21 +00:00
|
|
|
|
# 同一幅"窄框叠在宽框上"的画,站得住就判、站不住就不判。
|
|
|
|
|
|
# 这是本轮真机上那次误报的现场还原:切面板那一次绘制是 2.7 KB 一个 burst,
|
|
|
|
|
|
# 采样每 64 字节一刀,于是两幅画叠在一起的中间态被连着采到了三次。旧判据把
|
|
|
|
|
|
# "连着采到"读成"画稳了",当场判下"进程卡片压在历史面板上";而那一帧只活了
|
|
|
|
|
|
# 192 字节,用户在那台 Windows 上从来没看见过它 —— 我们却照着它查了一整轮
|
|
|
|
|
|
# 根本不存在的绘制 bug。现在同一幅画只许在"顶得住 512 字节不变"时定罪:
|
|
|
|
|
|
# 上面那条窄框叠宽框(站得住)照旧要报,这一条(半路上被切走)必须安静。
|
|
|
|
|
|
("半张画不许下判词",
|
|
|
|
|
|
mid_paint(card(140, 12, fill=' 存储空间'), card(100, 6) + card(70, 4)), False),
|
|
|
|
|
|
# 反过来也必须成立:一幅画都没站住的流,判据要说"我判不了",不许趁乱发合格证。
|
|
|
|
|
|
# 这条是 SETTLE 自己的保险 —— 否则"只看寿命"会被误读成"寿命不够就挑一幅像样的
|
|
|
|
|
|
# 判",那条路通向的正是本轮那种没人见过的花屏。同一条流在旧判据下是安静通过的:
|
|
|
|
|
|
# 最后一幅画被那段看不见的写入连着采到三次,旧判据认它画稳了,而它干净,于是
|
|
|
|
|
|
# 整条流被判成"没问题"—— 一次什么都没证明的测量,被记成了一次通过。
|
|
|
|
|
|
("整条流没有一幅画站得住",
|
|
|
|
|
|
mid_paint(card(140, 12, fill=' 存储空间'),
|
|
|
|
|
|
card(140, 12, fill=' 系统状态'), repeats=1), True),
|
Say which console a frame was judged on, and stop blaming the interface for the shell
Three ways this pipeline produced a verdict that was not about the TUI.
The frame judge required every right border on a screen to land in the same
column. That was written when the widest window anyone captured was 100 columns
and the interface drew one card. At 140 columns the menu column and the panel
are two frames side by side — the menu ends at column 31, the panel at 140 — and
the rows where the panel has already finished genuinely do end at 31. A tidy
140-column screen was therefore garbled on every single capture, which is a
mistake the judge makes rather than the console, and mistakes the judge makes
should not have to be re-litigated on real hardware. The rule is now the one that
survives both layouts: the border columns of the widest rows are the picture, and
a row with a border column that appears nowhere in that picture means two
pictures of different sizes are stacked on one screen. `side_by_side` and the
narrow-card-under-wide-card case are both in `--selftest`, so whoever tightens
that rule again finds out there, in a millisecond, rather than on the box.
`win-tui-run.ps1` always ran `chcp 65001`, because UTF-8 comes back through the
capture with no decoding guess involved. It also means the probe always measured
a UTF-8 console, while the window being complained about sits on cp936 — and
which code page a console is on is exactly what decides what an unasked-for
character costs. `$SQUID_TUI_CP` picks the code page now, the runner reports it
as `MARK_CODEPAGE`, and the judge prints it on the first line of every report,
because a frame is only evidence for the console it was taken from. Both routes
are green on the box with the price list as it now stands: 140x35 on 65001, 101
settled frames, none of them overflowing, box-drawing intact; 100x32 on 936, 54
frames, same. The comments that claimed the ConPTY measures one cell because
UTF-8 is forgiving have been corrected too — it measures one cell on 936 as
well, which is a fact about a console with no font, not about a code page.
And when the runner itself fails to parse, the stream still contains a console:
a PowerShell error block, and then nothing. The judge said "no settled frame with
a border was ever drawn", which is true and useless, and it read like a rendering
regression badly enough that drawing code got changed because of it. A
`CategoryInfo` in the stream is now reported as what it is — the capture script
never started the interface — and it is a selftest case, so the excuse is on
record as belonging to the harness.
2026-10-15 14:28:49 +00:00
|
|
|
|
# 抓帧脚本自己炸了:远端 PowerShell 吐出一段它自己的报错,界面上一个字都没画。
|
|
|
|
|
|
# 这种流必须把"壳子坏了"单独说出来。否则"花屏"的罪名会扣在一个根本没启动的
|
|
|
|
|
|
# 界面上 —— 我们真的被这个假故障骗着去改过一版绘制代码。
|
|
|
|
|
|
("抓帧脚本自己没跑起来",
|
|
|
|
|
|
'MARK_STARTED 140x35\r\n'
|
|
|
|
|
|
'CategoryInfo : (:) [], ParentContainsErrorRecordException\r\n'
|
|
|
|
|
|
'FullyQualifiedErrorId : PositionalParameterNotFound\r\n', True),
|
Judge a captured frame by what is on the screen, not by what was sent
`tui-frame-check.py` is the part of `win-tui-capture.sh` that decides whether a
run passed, taken out of the shell script so that fixing the judgement does not
require the real machine to run again — `TUI_REUSE=1` re-reads a saved byte
stream, which is how both bugs in this branch were confirmed fixed against
captures taken before the fix existed. `--selftest` feeds it six screens it made
up — two good ones and four broken ones, including a screen where every Chinese
character makes `len()` measure the frame too narrow — and fails if the judge
goes quiet on a bug or shouts at a good screen.
The four rules it encodes were each paid for with a false verdict:
* the right border is only trusted on rows whose *first* character is a border
character, because the box-drawing bar also appears in prose and in ASCII mode
as `|`, and reading the last one on a row found the wrong column;
* columns are counted by accumulated display width, not by `len()`, because a
terminal emulator keeps one character for a glyph that occupies two cells;
* only a screen that was painted at least eight rows and seen twice is judged,
so a half-drawn frame cannot be mistaken for a torn one;
* a row that ends in a border but starts with prose is a row sitting *on* a
border — the shape the toast produced — which is how the judge caught a bug
nobody had thought to look for.
`win-tui-run.ps1` was missing from the repository while `win-tui-capture.sh`
depended on it, so the proof the last commit described was not in fact
repeatable. It exists here, and it is the reason the captures are trustworthy:
`mode con cols=100 lines=30` fails silently on the ConPTY that Windows OpenSSH
allocates, so every earlier "capture at 100 columns" was a 120-column frame
reflowed by the emulator. It sets the size through `[Console]::WindowWidth` and
reports the size it ended up with, and the emulator replays that rather than the
one we asked for.
2026-10-15 13:20:58 +00:00
|
|
|
|
]
|
|
|
|
|
|
failed = 0
|
|
|
|
|
|
for name, data, want_problems in cases:
|
|
|
|
|
|
problems = analyze(data, echo=False)
|
|
|
|
|
|
ok = bool(problems) == want_problems
|
|
|
|
|
|
failed += 0 if ok else 1
|
|
|
|
|
|
verdict = '按预期' if ok else '判错了'
|
|
|
|
|
|
want = '该报问题' if want_problems else '该安静'
|
|
|
|
|
|
print(f"[selftest] {name}: {verdict}(期望{want})"
|
|
|
|
|
|
+ (f" -> {problems}" if problems else ""))
|
|
|
|
|
|
print(f"[selftest] {'RESULT: OK' if not failed else f'RESULT: {failed} 个用例判错了'}")
|
|
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
if '--selftest' in sys.argv:
|
|
|
|
|
|
sys.exit(selftest())
|
|
|
|
|
|
if len(sys.argv) != 2:
|
|
|
|
|
|
sys.exit(__doc__)
|
|
|
|
|
|
found = analyze(open(sys.argv[1], 'rb').read().decode('utf-8', 'replace'))
|
|
|
|
|
|
print()
|
|
|
|
|
|
for problem in found:
|
|
|
|
|
|
print(f"[FAIL] {problem}")
|
|
|
|
|
|
print(f"RESULT: {'FAIL' if found else 'OK'}")
|
|
|
|
|
|
sys.exit(1 if found else 0)
|