teamsmith 0.0.0-stage → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# shellcheck shell=bash
|
|
3
|
+
# pty-wait.sh — the settled-frame waits, the state-checked cleanup keys and the failure scenes for
|
|
4
|
+
# the pty/tmux fixtures (M59; the M55 review's §38-b cascade was ✓33 ✗62).
|
|
5
|
+
#
|
|
6
|
+
# The incident: Ink paints a frame line by line, so a capture can hold the title of a widget whose
|
|
7
|
+
# body has not been written yet. The fixture's waits grepped the title and returned immediately
|
|
8
|
+
# (one frame = proof); the very next entry assertions failed against the half frame; and the
|
|
9
|
+
# "cleanup" send-keys Escape that followed hit a widget that was not open any more — it closed the
|
|
10
|
+
# whole settings view and every later assertion ran against the wrong scene (the 62-bogus-failure
|
|
11
|
+
# cascade).
|
|
12
|
+
#
|
|
13
|
+
# Three rules, all enforced here:
|
|
14
|
+
# 1. A wait releases only on a *settled* frame: every needle is in the capture AND the frame has
|
|
15
|
+
# stopped changing — a second capture, taken after PTY_SETTLE_PAUSE, is byte-identical after
|
|
16
|
+
# masking the title clock (the only per-second repaint; masking is a fixed HH:MM:SS pattern,
|
|
17
|
+
# not a content-dependent loosening). A needle of the form `!text` must be ABSENT.
|
|
18
|
+
# 2. A cleanup key goes out only after the same check: the widget's marker must be on a settled
|
|
19
|
+
# frame (see pty_key_when / pty_cleanup_esc). A widget that is not there gets no key, so a
|
|
20
|
+
# missed wait can no longer be upgraded into "the next esc closes the whole view".
|
|
21
|
+
# 3. A failure carries its own scene: a timed-out wait prints which wait, how long, what was
|
|
22
|
+
# missing, the last lines of the pane, and a fresh capture right after (still moving?); the
|
|
23
|
+
# failure streak classifies the red as isolated or a cascade. A dead pane is named.
|
|
24
|
+
#
|
|
25
|
+
# The caller provides:
|
|
26
|
+
# pty_cap — prints the current capture (required; scrollback-inclusive is fine)
|
|
27
|
+
# pty_keys — sends keys (required only by pty_key_when / pty_cleanup_esc)
|
|
28
|
+
# pty_pane_state — prints "<dead>:<status>" for the pane (optional; a dead pane is named)
|
|
29
|
+
#
|
|
30
|
+
# Knobs (fixture-only; the defaults are what the fixtures run with):
|
|
31
|
+
# PTY_WAIT_ITERS=40 poll rounds before a wait is declared timed out (a failure-detector
|
|
32
|
+
# horizon, not a "wait this long" budget: a green run returns on the
|
|
33
|
+
# first settled frame, typically rounds 1-3)
|
|
34
|
+
# PTY_WAIT_PAUSE=0.35 pause between polls (a poll interval, never a fixed UI wait)
|
|
35
|
+
# PTY_SETTLE_PAUSE=0.25 pause between the two captures the settle check compares
|
|
36
|
+
# PTY_CLEANUP_ITERS=4 poll rounds allowed for the cleanup guard to find the widget
|
|
37
|
+
# PTY_SCENE_LINES=12 pane lines printed in a failure scene
|
|
38
|
+
# PTY_SCENE_DIR when set, each timed-out wait's two captures are saved there
|
|
39
|
+
# PTY_TRACE=0 print every wait/cleanup decision to stderr (fixture diagnostics)
|
|
40
|
+
# PTY_SELFTEST_BREAK="" self-test only (`--self-test`): sabotage one rule so the guard test
|
|
41
|
+
# can go red (early / nosettle / noclockmask / unguarded / noscene /
|
|
42
|
+
# noext / alwaysext / noskip / alwaysskip / pipeshadow)
|
|
43
|
+
#
|
|
44
|
+
# P48 `pty-fixture-load-premise` (panel#The project-settings pty fixture judges under a machine
|
|
45
|
+
# premise; the gate rule is verification#The correctness gate judges correctness only): the horizon
|
|
46
|
+
# above is a **failure detector, never a judgment**. Time is the machine's dimension, so a machine
|
|
47
|
+
# that cannot deliver a frame must not turn into a red. Two in-run instruments, both bounded:
|
|
48
|
+
#
|
|
49
|
+
# PTY_STALL_ROUNDS=8 the progress window, in rounds. A wait is extended only while the masked
|
|
50
|
+
# capture changed within the last this many rounds AND at least this many
|
|
51
|
+
# rounds have been observed — a horizon below the window (the fixture's own
|
|
52
|
+
# site overrides at 6/8 rounds) is never extended and a scene that stopped
|
|
53
|
+
# painting gets no extension at all, so the extension can never hide a
|
|
54
|
+
# static failure. Measured basis: a round costs ~0.6-0.85 s, so 8 rounds is
|
|
55
|
+
# ~5-7 s of identical masked frames.
|
|
56
|
+
# PTY_EXT_FACTOR=3 the extension ceiling: at most this many times the base horizon (bounded
|
|
57
|
+
# cost: a red can never take more than 3 x ~26 s per wait, and the scenario
|
|
58
|
+
# stops at the first unattributable exhaustion)
|
|
59
|
+
#
|
|
60
|
+
# At that ceiling the wait asks the caller's premise hook and decides:
|
|
61
|
+
# still painting OR pty_premise_over returns 0 (the machine's own readings are over their
|
|
62
|
+
# ceilings) -> a **visible SKIP**: one line naming the wait, its rounds, its elapsed time, the
|
|
63
|
+
# M59 scene report and the reason (the readings). The wait returns 3, sets PTY_SKIPPED=1 and
|
|
64
|
+
# runs the caller's pty_on_skip when it defines one (the fixtures stop that scenario there);
|
|
65
|
+
# a static scene with the readings under their ceilings -> the ordinary failure (rc 1) with the
|
|
66
|
+
# M59 scene, so a real regression always reds on a healthy machine. A skip is never reported as
|
|
67
|
+
# a pass and never as a failure by this file.
|
|
68
|
+
#
|
|
69
|
+
# The caller may define (both optional; absent = "the machine is under its premise"):
|
|
70
|
+
# pty_premise_over 0 when the machine is over its premise (attributed -> SKIP), 1 otherwise
|
|
71
|
+
# pty_premise_reason prints the one-line reason the SKIP line carries (loadavg/cores/probe)
|
|
72
|
+
# pty_on_skip called after a skip is printed (the pty fixtures exit their scenario with 4)
|
|
73
|
+
# PTY_INJECT_NEEDLE="" fixture/self-test only: an extra needle that can never appear, appended to
|
|
74
|
+
# every wait — the "the state never arrives" shape the exhaustion tests need.
|
|
75
|
+
# Wait verdict: 0 green | 1 red (the M59 failure scene) | 3 visible SKIP (machine, not code) | 2
|
|
76
|
+
# setup (pty_cap missing).
|
|
77
|
+
#
|
|
78
|
+
# Constants, bands and how to re-derive them (design.md §3/§4; the raw table is
|
|
79
|
+
# docs/team/reports/P48-dev3.md):
|
|
80
|
+
# PTY_STALL_ROUNDS=8 band: a round costs ~0.6-0.85 s (two captures + 0.25 s settle + 0.35 s
|
|
81
|
+
# pause), so 8 rounds is ~5-7 s of identical masked frames; the fixture's
|
|
82
|
+
# observed needles need 1-4 rounds, interactions land inside the window.
|
|
83
|
+
# PTY_EXT_FACTOR=3 band: the base horizon is ~26 s, so a red can never take more than ~78 s
|
|
84
|
+
# per wait (bounded cost); a 2.8x slower machine still needed only 1-4
|
|
85
|
+
# rounds (a 10-40x slack), so this is a wait, not a relaxed threshold.
|
|
86
|
+
# probe/load ceilings the fixture owns them (panel-p21.sh: 120 ms and 2.0 x cores); they are
|
|
87
|
+
# measured there and re-derived with tests/load-experiment.sh
|
|
88
|
+
# {probe,storm,burn} (owned load, owned targets, private roots).
|
|
89
|
+
set -uo pipefail
|
|
90
|
+
|
|
91
|
+
PTY_WAIT_ITERS="${PTY_WAIT_ITERS:-40}"
|
|
92
|
+
PTY_WAIT_PAUSE="${PTY_WAIT_PAUSE:-0.35}"
|
|
93
|
+
PTY_SETTLE_PAUSE="${PTY_SETTLE_PAUSE:-0.25}"
|
|
94
|
+
PTY_CLEANUP_ITERS="${PTY_CLEANUP_ITERS:-4}"
|
|
95
|
+
PTY_SCENE_LINES="${PTY_SCENE_LINES:-12}"
|
|
96
|
+
PTY_STALL_ROUNDS="${PTY_STALL_ROUNDS:-8}"
|
|
97
|
+
PTY_EXT_FACTOR="${PTY_EXT_FACTOR:-3}"
|
|
98
|
+
PTY_INJECT_NEEDLE="${PTY_INJECT_NEEDLE:-}"
|
|
99
|
+
PTY_TRACE="${PTY_TRACE:-0}"
|
|
100
|
+
PTY_KEYS_SENT="${PTY_KEYS_SENT:-0}"
|
|
101
|
+
PTY_SKIPPED="${PTY_SKIPPED:-0}"
|
|
102
|
+
PTY_WAIT_PAINTING="${PTY_WAIT_PAINTING:-}"
|
|
103
|
+
PTY_WAIT_CEILING="${PTY_WAIT_CEILING:-}"
|
|
104
|
+
PTY_FAIL_STREAK="${PTY_FAIL_STREAK:-0}"
|
|
105
|
+
PTY_WAIT_FAILED="${PTY_WAIT_FAILED:-0}"
|
|
106
|
+
|
|
107
|
+
pty_trace() {
|
|
108
|
+
[ "${PTY_TRACE:-0}" = "1" ] || return 0
|
|
109
|
+
printf ' \033[2m· pty-wait: %s\033[0m\n' "$*" >&2
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
# ---- predicates -------------------------------------------------------------
|
|
113
|
+
|
|
114
|
+
# _pty_contains <capture> <literal> — 0 when <literal> sits inside <capture>.
|
|
115
|
+
#
|
|
116
|
+
# P127: this matcher is bash-internal on purpose. `printf '%s\n' "$c" | grep -qF` hands the
|
|
117
|
+
# capture to a separate writer; grep -q exits on the first hit and the writer takes SIGPIPE, so
|
|
118
|
+
# under `set -o pipefail` a real hit comes back as rc=141 and the wait reports "not there" — the
|
|
119
|
+
# engine's four sites were that shape and P124's 120607-byte frame hit them deterministically.
|
|
120
|
+
# `pipeshadow` is the self-test's red side: it shadows this helper back to the pre-fix pipeline
|
|
121
|
+
# so the long-frame guard must go red (the guard test asserts exactly that).
|
|
122
|
+
_pty_contains() {
|
|
123
|
+
if [ "${PTY_SELFTEST_BREAK:-}" = "pipeshadow" ]; then
|
|
124
|
+
printf '%s\n' "$1" | grep -qF -- "$2"
|
|
125
|
+
return $?
|
|
126
|
+
fi
|
|
127
|
+
[[ "$1" == *"$2"* ]]
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
_pty_has_all() { # <capture> <needle...> — a `!text` needle must be ABSENT from the capture
|
|
131
|
+
local c="$1"; shift
|
|
132
|
+
local n
|
|
133
|
+
for n in "$@"; do
|
|
134
|
+
[ -n "$n" ] || continue
|
|
135
|
+
case "$n" in
|
|
136
|
+
'!'*) _pty_contains "$c" "${n#!}" && return 1 ;;
|
|
137
|
+
*) _pty_contains "$c" "$n" || return 1 ;;
|
|
138
|
+
esac
|
|
139
|
+
done
|
|
140
|
+
return 0
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
_pty_report_missing() { # <capture> <needle...> → a one-line "缺 […];仍在 […]" report
|
|
144
|
+
local c="$1"; shift
|
|
145
|
+
local n miss="" still=""
|
|
146
|
+
for n in "$@"; do
|
|
147
|
+
[ -n "$n" ] || continue
|
|
148
|
+
case "$n" in
|
|
149
|
+
'!'*) _pty_contains "$c" "${n#!}" && still="$still ${n#!}" ;;
|
|
150
|
+
*) _pty_contains "$c" "$n" || miss="$miss $n" ;;
|
|
151
|
+
esac
|
|
152
|
+
done
|
|
153
|
+
if [ -n "$miss" ]; then printf '缺 [%s]' "${miss# }"; fi
|
|
154
|
+
if [ -n "$still" ]; then
|
|
155
|
+
[ -n "$miss" ] && printf ';'
|
|
156
|
+
printf '仍在 [%s]' "${still# }"
|
|
157
|
+
fi
|
|
158
|
+
[ -n "$miss$still" ] || printf '(条件其实已成立——这是稳定确认没过)'
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
# The title clock is the only thing that repaints every second (main.tsx writes it in place).
|
|
162
|
+
# Two consecutive captures that differ ONLY in the clock are the same frame: mask it.
|
|
163
|
+
_pty_mask_clock() {
|
|
164
|
+
printf '%s\n' "$1" | sed -E 's/[0-9]{2}:[0-9]{2}:[0-9]{2}/HH:MM:SS/g'
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
pty_frame_settled() { # <capture> → 0 when the frame has stopped being painted
|
|
168
|
+
local a b
|
|
169
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noclockmask" ] || a="$(_pty_mask_clock "$1")"
|
|
170
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noclockmask" ] && a="$1"
|
|
171
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "nosettle" ] && return 0
|
|
172
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "early" ] && return 0 # the old rule: fixed sleep, no settle at all
|
|
173
|
+
sleep "${PTY_SETTLE_PAUSE:-0.25}"
|
|
174
|
+
b="$(pty_cap)"
|
|
175
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noclockmask" ] || b="$(_pty_mask_clock "$b")"
|
|
176
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noclockmask" ] && b="$b"
|
|
177
|
+
[ "$a" = "$b" ]
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
_pty_condition_met() { # <capture> <needle...>
|
|
181
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "early" ] && return 0 # self-test: the pre-M59 "title only" rule
|
|
182
|
+
_pty_has_all "$@"
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
# ---- the wait engine --------------------------------------------------------
|
|
186
|
+
|
|
187
|
+
# _pty_painting_recent <round> <round-of-last-change> — 0 while the scene counts as still painting.
|
|
188
|
+
# Two conditions: at least PTY_STALL_ROUNDS rounds were observed (a horizon shorter than the window
|
|
189
|
+
# never extends), and the masked capture changed within the last PTY_STALL_ROUNDS rounds. The
|
|
190
|
+
# `alwaysext` self-test break forces 0, so the guard test can catch an extension that forgets to
|
|
191
|
+
# check progress.
|
|
192
|
+
_pty_painting_recent() {
|
|
193
|
+
local stall="${PTY_STALL_ROUNDS:-8}"
|
|
194
|
+
case "$stall" in ''|*[!0-9]*) stall=8 ;; esac
|
|
195
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "alwaysext" ] && return 0
|
|
196
|
+
[ "$1" -ge "$stall" ] || return 1
|
|
197
|
+
[ "$(( $1 - $2 ))" -le "$stall" ]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
# _pty_premise_over — the caller's hook, with the two self-test sabotages: `noskip` makes an
|
|
201
|
+
# over-premise exhaustion fail anyway (the guard test must catch a skip that stopped happening) and
|
|
202
|
+
# `alwaysskip` skips even under the premise (the guard test must catch a skip that swallows a red).
|
|
203
|
+
_pty_premise_over() {
|
|
204
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "alwaysskip" ] && return 0
|
|
205
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noskip" ] && return 1
|
|
206
|
+
declare -F pty_premise_over >/dev/null 2>&1 || return 1
|
|
207
|
+
pty_premise_over
|
|
208
|
+
}
|
|
209
|
+
_pty_premise_reason() {
|
|
210
|
+
if declare -F pty_premise_reason >/dev/null 2>&1; then pty_premise_reason
|
|
211
|
+
else printf '机器读数超前提'; fi
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
# pty_skip_line — the one visible line a skip prints. It names the wait, its rounds against the
|
|
215
|
+
# ceiling, the elapsed time, whether the scene was still painting, what was missing (the M59
|
|
216
|
+
# report) and the caller's reason (the readings). stdout, so the gate's log carries it.
|
|
217
|
+
pty_skip_line() {
|
|
218
|
+
local painting='场景已静止'
|
|
219
|
+
[ "${PTY_WAIT_PAINTING:-no}" = "yes" ] && painting='场景仍在绘制'
|
|
220
|
+
printf ' \033[33mSKIP\033[0m 等待耗尽但归因于机器(既不是通过也不是失败):%s · 轮数 %s/%s · 耗时约 %ss · %s · %s · 归因:%s\n' \
|
|
221
|
+
"${PTY_WAIT_LABEL:-?}" "${PTY_WAIT_ROUNDS:-?}" "${PTY_WAIT_CEILING:-?}" "${PTY_WAIT_SECONDS:-?}" \
|
|
222
|
+
"$painting" "${PTY_WAIT_REPORT:-}" "$(_pty_premise_reason)"
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
# pty_wait_frame <outfile|-> <label> <needle...> → 0 when a settled frame carries every needle
|
|
226
|
+
# (absent ones prefixed with `!`). The latest capture is written to <outfile> every round so the
|
|
227
|
+
# caller's assertion can show what was on screen. The horizon is a failure detector: it is extended
|
|
228
|
+
# (bounded, PTY_EXT_FACTOR) while the scene is still painting, and at the ceiling the verdict is
|
|
229
|
+
# attributed — the machine (visible SKIP, rc 3, PTY_SKIPPED=1) or the code (the M59 failure scene,
|
|
230
|
+
# rc 1, which the caller's bad() classifies as isolated vs cascade).
|
|
231
|
+
pty_wait_frame() {
|
|
232
|
+
local out="$1" label="$2"; shift 2
|
|
233
|
+
declare -F pty_cap >/dev/null 2>&1 || { printf 'pty-wait: pty_cap is not defined\n' >&2; return 2; }
|
|
234
|
+
local base="${PTY_WAIT_ITERS:-40}" extf="${PTY_EXT_FACTOR:-3}"
|
|
235
|
+
case "$base" in ''|*[!0-9]*) base=40 ;; esac
|
|
236
|
+
[ "$base" -ge 1 ] || base=1
|
|
237
|
+
case "$extf" in ''|*[!0-9]*) extf=3 ;; esac
|
|
238
|
+
[ "$extf" -ge 1 ] || extf=1
|
|
239
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noext" ] && extf=1
|
|
240
|
+
local ceiling=$(( base * extf ))
|
|
241
|
+
local extra="${PTY_INJECT_NEEDLE:-}"
|
|
242
|
+
local i=0 a last_masked='' masked last_change=0 t0="$SECONDS"
|
|
243
|
+
PTY_WAIT_FAILED=0
|
|
244
|
+
PTY_SKIPPED=0
|
|
245
|
+
while [ "$i" -lt "$ceiling" ]; do
|
|
246
|
+
i=$((i + 1))
|
|
247
|
+
a="$(pty_cap)"
|
|
248
|
+
[ "$out" != "-" ] && printf '%s\n' "$a" > "$out"
|
|
249
|
+
if _pty_condition_met "$a" "$@" ${extra:+"$extra"} && pty_frame_settled "$a"; then
|
|
250
|
+
PTY_WAIT_ROUNDS="$i"; PTY_WAIT_CEILING="$ceiling"
|
|
251
|
+
# The trace line keeps the pre-P48 shape (`rounds=$i`): panel-p21.sh's own M59 assertion
|
|
252
|
+
# (`wait picker … rounds=[0-9]+ settled=1`) pins it, and the ceiling already appears in the
|
|
253
|
+
# exhaustion report and the skip line. A diagnostics line is no place to break a pin.
|
|
254
|
+
[ "${PTY_TRACE:-0}" = "1" ] && pty_trace "wait $label rounds=$i settled=1"
|
|
255
|
+
return 0
|
|
256
|
+
fi
|
|
257
|
+
masked="$(_pty_mask_clock "$a")"
|
|
258
|
+
[ "$masked" != "$last_masked" ] && last_change="$i"
|
|
259
|
+
last_masked="$masked"
|
|
260
|
+
# Past the base horizon the extension only continues while the scene is still painting; a
|
|
261
|
+
# static scene stops here (bounded cost, and the extension can never hide a static failure).
|
|
262
|
+
if [ "$i" -ge "$base" ] && ! _pty_painting_recent "$i" "$last_change"; then
|
|
263
|
+
break
|
|
264
|
+
fi
|
|
265
|
+
sleep "${PTY_WAIT_PAUSE:-0.35}"
|
|
266
|
+
done
|
|
267
|
+
[ "${PTY_TRACE:-0}" = "1" ] && pty_trace "wait $label rounds=$i settled=0"
|
|
268
|
+
PTY_WAIT_LABEL="$label"; PTY_WAIT_ROUNDS="$i"; PTY_WAIT_CEILING="$ceiling"
|
|
269
|
+
PTY_WAIT_SECONDS="$((SECONDS - t0))"
|
|
270
|
+
PTY_WAIT_PAINTING="no"
|
|
271
|
+
_pty_painting_recent "$i" "$last_change" && PTY_WAIT_PAINTING="yes"
|
|
272
|
+
PTY_WAIT_REPORT="$(_pty_report_missing "$a" "$@" ${extra:+"$extra"})"
|
|
273
|
+
if [ "$PTY_WAIT_PAINTING" = "yes" ] || _pty_premise_over; then
|
|
274
|
+
PTY_SKIPPED=1
|
|
275
|
+
pty_skip_line
|
|
276
|
+
if declare -F pty_on_skip >/dev/null 2>&1; then pty_on_skip; fi
|
|
277
|
+
return 3
|
|
278
|
+
fi
|
|
279
|
+
pty_wait_scene "$label" "$i" "$((SECONDS - t0))" "$a" "$@" ${extra:+"$extra"}
|
|
280
|
+
return 1
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
# pty_wait_scene <label> <rounds> <seconds> <capture> <needle...> — the failure carries its own
|
|
284
|
+
# scene: which wait timed out, for how long, what was missing, the pane tail, a fresh capture right
|
|
285
|
+
# after (still moving?), and a dead pane if the caller's pty_pane_state answers.
|
|
286
|
+
pty_wait_scene() {
|
|
287
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noscene" ] && return 0
|
|
288
|
+
local label="$1" rounds="$2" secs="$3" last="$4"; shift 4
|
|
289
|
+
local fresh same dead="" report f
|
|
290
|
+
fresh="$(pty_cap)"
|
|
291
|
+
if [ "$(_pty_mask_clock "$fresh")" = "$(_pty_mask_clock "$last")" ]; then
|
|
292
|
+
same="画面已静止(条件确实没到,不是中间帧)"
|
|
293
|
+
else
|
|
294
|
+
same="画面还在变(这是中间帧/慢帧,条件没落定)"
|
|
295
|
+
fi
|
|
296
|
+
report="$(_pty_report_missing "$last" "$@")"
|
|
297
|
+
if declare -F pty_pane_state >/dev/null 2>&1; then dead="$(pty_pane_state 2>/dev/null || true)"; fi
|
|
298
|
+
if [ -n "${PTY_SCENE_DIR:-}" ] && [ -d "$PTY_SCENE_DIR" ]; then
|
|
299
|
+
f="$PTY_SCENE_DIR/pty-scene-$(date +%H%M%S)-$$.txt"
|
|
300
|
+
{
|
|
301
|
+
printf '# wait timed out: %s (%s rounds / ~%ss)\n' "$label" "$rounds" "$secs"
|
|
302
|
+
printf '# report: %s\n' "$report"
|
|
303
|
+
printf '# pane at timeout:\n%s\n# pane right after:\n%s\n' "$last" "$fresh"
|
|
304
|
+
} > "$f" 2>/dev/null || true
|
|
305
|
+
fi
|
|
306
|
+
PTY_WAIT_FAILED=1
|
|
307
|
+
PTY_WAIT_LABEL="$label"; PTY_WAIT_ROUNDS="$rounds"; PTY_WAIT_SECONDS="$secs"; PTY_WAIT_REPORT="$report"
|
|
308
|
+
{
|
|
309
|
+
printf ' \033[33m·\033[0m 等待超时:%s\n' "$label"
|
|
310
|
+
printf ' 轮数 %s/%s,耗时约 %ss(轮询 %ss + 稳定确认 %ss);%s\n' \
|
|
311
|
+
"$rounds" "${PTY_WAIT_ITERS:-40}" "$secs" "${PTY_WAIT_PAUSE:-0.35}" "${PTY_SETTLE_PAUSE:-0.25}" "$report"
|
|
312
|
+
printf ' 超时后立即再 capture:%s\n' "$same"
|
|
313
|
+
case "$dead" in
|
|
314
|
+
1:*) printf ' 面板进程已经死了:tmux pane_dead status=%s(先看它死前的最后一帧)\n' "${dead#1:}" ;;
|
|
315
|
+
'') printf ' 面板窗口已经不在了(pane 不在 tmux 里)\n' ;;
|
|
316
|
+
esac
|
|
317
|
+
printf ' pane 末 %s 行(超时时):\n' "${PTY_SCENE_LINES:-12}"
|
|
318
|
+
printf '%s\n' "$last" | tail -n "${PTY_SCENE_LINES:-12}" | sed 's/^/ │ /'
|
|
319
|
+
} >&2
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
# ---- failures: isolated vs cascade ------------------------------------------
|
|
323
|
+
|
|
324
|
+
pty_fail_reset() {
|
|
325
|
+
PTY_FAIL_STREAK=0
|
|
326
|
+
PTY_WAIT_FAILED=0
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
# pty_bad <text> — the failure line plus its scene. The fixture's bad() calls this after counting;
|
|
330
|
+
# pty_failure_context prints the streak and, for the first red since the last pass, the pane tail.
|
|
331
|
+
pty_bad() {
|
|
332
|
+
printf ' \033[31m✗\033[0m %s\n' "$1"
|
|
333
|
+
pty_failure_context "$1"
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
pty_failure_context() { # <text> (the ✗ line was already printed)
|
|
337
|
+
[ "${PTY_SELFTEST_BREAK:-}" = "noscene" ] && { PTY_FAIL_STREAK=$(( ${PTY_FAIL_STREAK:-0} + 1 )); PTY_WAIT_FAILED=0; return 0; }
|
|
338
|
+
local had_wait="${PTY_WAIT_FAILED:-0}"
|
|
339
|
+
PTY_FAIL_STREAK=$(( ${PTY_FAIL_STREAK:-0} + 1 ))
|
|
340
|
+
{
|
|
341
|
+
if [ "$had_wait" = "1" ]; then
|
|
342
|
+
printf ' 现场:这次失败来自等待超时 —— %s(%s 轮 / 约 %ss;%s),上面的 pane 现场就是它\n' \
|
|
343
|
+
"$PTY_WAIT_LABEL" "$PTY_WAIT_ROUNDS" "$PTY_WAIT_SECONDS" "$PTY_WAIT_REPORT"
|
|
344
|
+
fi
|
|
345
|
+
if [ "${PTY_FAIL_STREAK:-0}" -eq 1 ]; then
|
|
346
|
+
printf ' 这是一次孤立失败(上一个失败之后有过成功)\n'
|
|
347
|
+
else
|
|
348
|
+
printf ' 级联:这是本轮第 %s 次失败(上一个失败之后没有再通过过)——先修第一条\n' "${PTY_FAIL_STREAK:-?}"
|
|
349
|
+
fi
|
|
350
|
+
# Every failure carries observed pane state; a cascade only needs a hint (it is the echo of
|
|
351
|
+
# the first red, whose full scene is above).
|
|
352
|
+
if [ "$had_wait" != "1" ]; then
|
|
353
|
+
local n="$PTY_SCENE_LINES"
|
|
354
|
+
if [ "${PTY_FAIL_STREAK:-0}" -gt 1 ]; then n=4; fi
|
|
355
|
+
printf ' 失败后立即再 capture(末 %s 行):\n' "$n"
|
|
356
|
+
pty_cap 2>/dev/null | tail -n "$n" | sed 's/^/ │ /'
|
|
357
|
+
fi
|
|
358
|
+
} >&2
|
|
359
|
+
PTY_WAIT_FAILED=0
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
# ---- cleanup keys: only when the widget is really there ---------------------
|
|
363
|
+
|
|
364
|
+
# pty_key_when <label> <needle> <key...> — send the keys only when <needle> sits on a settled
|
|
365
|
+
# frame. Returns 0 when they were sent, 1 when the guard blocked them (nothing is pressed).
|
|
366
|
+
pty_key_when() {
|
|
367
|
+
local label="$1" needle="$2"; shift 2
|
|
368
|
+
declare -F pty_keys >/dev/null 2>&1 || { printf 'pty-wait: pty_keys is not defined\n' >&2; return 2; }
|
|
369
|
+
if [ "${PTY_SELFTEST_BREAK:-}" = "unguarded" ]; then
|
|
370
|
+
pty_keys "$@"
|
|
371
|
+
PTY_KEYS_SENT=$((PTY_KEYS_SENT + 1))
|
|
372
|
+
pty_trace "key ${*} label=$needle action=esc reason=unguarded"
|
|
373
|
+
return 0
|
|
374
|
+
fi
|
|
375
|
+
local i=1 c
|
|
376
|
+
while [ "$i" -le "${PTY_CLEANUP_ITERS:-4}" ]; do
|
|
377
|
+
c="$(pty_cap)"
|
|
378
|
+
if _pty_has_all "$c" "$needle" && pty_frame_settled "$c"; then
|
|
379
|
+
pty_keys "$@"
|
|
380
|
+
PTY_KEYS_SENT=$((PTY_KEYS_SENT + 1))
|
|
381
|
+
pty_trace "key ${*} label=$label action=sent reason=settled"
|
|
382
|
+
return 0
|
|
383
|
+
fi
|
|
384
|
+
i=$((i + 1))
|
|
385
|
+
sleep "${PTY_WAIT_PAUSE:-0.35}"
|
|
386
|
+
done
|
|
387
|
+
pty_trace "key - label=$label action=none reason=not-settled"
|
|
388
|
+
return 1
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
# pty_cleanup_esc <label> <needle> — esc a widget only while it is really on screen, then confirm
|
|
392
|
+
# it is gone. Returns 0 when the widget is gone afterwards (the esc closed it, or it was never
|
|
393
|
+
# there — in that case NO key was sent, so the next esc cannot close the whole view), 1 when the
|
|
394
|
+
# esc was sent but the widget is still there (the caller's bad() names that).
|
|
395
|
+
pty_cleanup_esc() {
|
|
396
|
+
local label="$1" needle="$2" i=1
|
|
397
|
+
if ! pty_key_when "$label" "$needle" Escape; then
|
|
398
|
+
return 0
|
|
399
|
+
fi
|
|
400
|
+
while [ "$i" -le "${PTY_CLEANUP_ITERS:-4}" ]; do
|
|
401
|
+
if ! _pty_has_all "$(pty_cap)" "$needle"; then
|
|
402
|
+
pty_trace "cleanup $label action=esc result=closed"
|
|
403
|
+
return 0
|
|
404
|
+
fi
|
|
405
|
+
i=$((i + 1))
|
|
406
|
+
sleep "${PTY_WAIT_PAUSE:-0.35}"
|
|
407
|
+
done
|
|
408
|
+
pty_trace "cleanup $label action=esc result=still-present"
|
|
409
|
+
return 1
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
# ---------------------------------------------------------------- self-test --
|
|
413
|
+
# `bash skills/teamsmith/tests/lib/pty-wait.sh --self-test` — no tmux, no project: a fake pane
|
|
414
|
+
# paints its picker one line per capture (the incident's mid-frame), an old-title-only wait and the
|
|
415
|
+
# new settled-frame wait run over the SAME frame sequence, the cleanup guard faces an
|
|
416
|
+
# already-closed picker, and a deliberate timeout must print the whole scene. `--break=<stage>`
|
|
417
|
+
# sabotages one rule so the guard test goes red (the flip the PM asks defect-fix reports to carry).
|
|
418
|
+
pty_selftest() {
|
|
419
|
+
local break_stage="${1#--break=}"
|
|
420
|
+
[ -n "$break_stage" ] && [ "$break_stage" != "${1}" ] || break_stage=""
|
|
421
|
+
[ -n "$break_stage" ] && PTY_SELFTEST_BREAK="$break_stage"
|
|
422
|
+
local st_dir
|
|
423
|
+
# P53:临时根的唯一创建者(自检结束后由助手回收)
|
|
424
|
+
. "$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)/tmp-root.sh"
|
|
425
|
+
st_dir="$(tmp_root_create pty-wait-selftest)" || return 3
|
|
426
|
+
trap 'tmp_root_reap_all' EXIT
|
|
427
|
+
local _PASS=0 _FAIL=0 _SKIP=0
|
|
428
|
+
_st_ok() { printf ' \033[32m✓\033[0m %s\n' "$1"; _PASS=$((_PASS + 1)); pty_fail_reset; }
|
|
429
|
+
_st_bad() { printf ' \033[31m✗\033[0m %s\n' "$1"; _FAIL=$((_FAIL + 1)); }
|
|
430
|
+
_st_skip() { printf ' \033[33mSKIP\033[0m %s\n' "$1"; _SKIP=$((_SKIP + 1)); pty_fail_reset; }
|
|
431
|
+
|
|
432
|
+
# The fake pane: a settings view; a picker paints one line per capture (max 4); the title clock
|
|
433
|
+
# ticks every capture so only the masked comparison can settle. Keys mutate the app state:
|
|
434
|
+
# Escape in the picker closes it; Escape anywhere else closes the whole view (the M55 casualty).
|
|
435
|
+
_st_mode() { printf '%s\n' "$1" > "$st_dir/mode"; printf '0\n' > "$st_dir/paint"; }
|
|
436
|
+
_st_reset() { _st_mode "$1"; printf '0\n' > "$st_dir/ticks"; printf '0\n' > "$st_dir/slow"; : > "$st_dir/keys"; PTY_KEYS_SENT=0; pty_fail_reset; }
|
|
437
|
+
pty_cap() {
|
|
438
|
+
local mode paint ticks
|
|
439
|
+
mode="$(cat "$st_dir/mode")"; paint="$(cat "$st_dir/paint")"; ticks="$(cat "$st_dir/ticks")"
|
|
440
|
+
# 判据⑥(P127):一个静态的超大帧(>128 KiB),第一行就是 needle —— 旧写法在这里被 SIGPIPE 吃掉。
|
|
441
|
+
if [ "$mode" = "long" ]; then cat "$st_dir/longframe"; return 0; fi
|
|
442
|
+
printf '╭─ 项目设置 · 09:41:%02d\n' "$ticks"
|
|
443
|
+
case "$mode" in
|
|
444
|
+
view) printf '%s\n' '│ 监控界面 tui · 当前' '│ 会话名 readonly · 只读' ;;
|
|
445
|
+
picker)
|
|
446
|
+
printf '%s\n' '│ 监控界面 tui · 当前'
|
|
447
|
+
[ "$paint" -ge 1 ] && printf '%s\n' '选择 监控界面 的值 · TEAM_MONITOR_UI'
|
|
448
|
+
[ "$paint" -ge 2 ] && printf '%s\n' '› 保持未设'
|
|
449
|
+
[ "$paint" -ge 3 ] && printf '%s\n' 'tui · 当前'
|
|
450
|
+
[ "$paint" -ge 4 ] && printf '%s\n' 'auto · 默认'
|
|
451
|
+
;;
|
|
452
|
+
closed) printf '%s\n' '(设置视图已被关掉,这是错的场景)' ;;
|
|
453
|
+
slow)
|
|
454
|
+
# 判据④:慢但仍在绘制。每次 capture 画一格进度(画面在变),进度到 _ST_SLOW_AT 拍才
|
|
455
|
+
# 同时出现条目并**停止绘制** —— 于是条目落在稳定帧上(同一轮的两张捕获相同),
|
|
456
|
+
# 而基础视界之前的每一轮画面都在变:要在基础视界之上多等才拿得到。
|
|
457
|
+
printf '%s\n' '│ 监控界面 tui · 当前'
|
|
458
|
+
local slow
|
|
459
|
+
slow="$(cat "$st_dir/slow")"
|
|
460
|
+
if [ "$slow" -lt "${_ST_SLOW_AT:-9}" ]; then slow=$(( slow + 1 )); printf '%s\n' "$slow" > "$st_dir/slow"; fi
|
|
461
|
+
printf '%s\n' "│ 进度 $slow"
|
|
462
|
+
[ "$slow" -ge "${_ST_SLOW_AT:-9}" ] && printf '%s\n' '慢帧条目'
|
|
463
|
+
;;
|
|
464
|
+
esac
|
|
465
|
+
printf '%s\n' "$((ticks + 1))" > "$st_dir/ticks"
|
|
466
|
+
[ "$paint" -lt 4 ] && printf '%s\n' "$((paint + 1))" > "$st_dir/paint"
|
|
467
|
+
return 0
|
|
468
|
+
}
|
|
469
|
+
pty_keys() {
|
|
470
|
+
printf '%s\n' "$*" >> "$st_dir/keys"
|
|
471
|
+
PTY_KEYS_SENT=$((PTY_KEYS_SENT + 1))
|
|
472
|
+
case "${1:-}" in
|
|
473
|
+
Escape) if [ "$(cat "$st_dir/mode")" = "picker" ]; then _st_mode view; else _st_mode closed; fi ;;
|
|
474
|
+
Enter) [ "$(cat "$st_dir/mode")" = "view" ] && _st_mode picker ;;
|
|
475
|
+
esac
|
|
476
|
+
}
|
|
477
|
+
pty_pane_state() { printf '0:\n'; }
|
|
478
|
+
_st_ticks() { cat "$st_dir/ticks"; }
|
|
479
|
+
_st_keys_count() { [ -f "$st_dir/keys" ] && wc -l < "$st_dir/keys" || echo 0; }
|
|
480
|
+
|
|
481
|
+
# The pre-M59 wait, copied verbatim from the old fixture: grep the title, fixed sleep, release.
|
|
482
|
+
_st_old_wait() { # <needle> → 0 with the released frame on stdout
|
|
483
|
+
local i c
|
|
484
|
+
for i in 1 2 3; do
|
|
485
|
+
c="$(pty_cap)"
|
|
486
|
+
if printf '%s\n' "$c" | grep -qF -- "$1"; then printf '%s' "$c"; return 0; fi
|
|
487
|
+
sleep 0.01
|
|
488
|
+
done
|
|
489
|
+
return 1
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
printf '\033[1m== pty-wait 自检(注入中间帧 + 清理守卫 + 失败现场) ==\033[0m\n'
|
|
493
|
+
printf ' 注入的帧序列:选择器打开后每次 capture 多画一行(标题→› 保持未设→tui · 当前→auto · 默认),\n'
|
|
494
|
+
printf ' 标题时钟每次 capture 跳一秒(只有 HH:MM:SS 掩码后的比较才算「帧静止」)。\n'
|
|
495
|
+
printf ' 判据④/⑤:慢但仍在绘制的场景会被延长(第 %s 拍才到条目),静态场景一点不延长;耗尽那一刻\n' "${_ST_SLOW_AT:-9}"
|
|
496
|
+
printf ' 按机器读数归因 —— 超前提 → 一行可见 SKIP(rc=3),前提之内 → 红(rc=1 + 现场)。\n'
|
|
497
|
+
printf ' 判据⑥(P127):>128 KiB 的长帧里,第一行的 needle 必须命中、缺失必须照缺报;旧写法\n'
|
|
498
|
+
printf ' `printf | grep -q` 在长帧上给写端 SIGPIPE → pipefail 下 rc=141 → 假缺(红侧见 --break=pipeshadow)。\n'
|
|
499
|
+
|
|
500
|
+
# ── 判据①:同一个中间帧序列,旧逻辑放行(演示红)/ 新逻辑不放行 ──
|
|
501
|
+
# A picker opens on Enter; the fake pane then paints it one line per capture.
|
|
502
|
+
_st_reset view
|
|
503
|
+
local old_frame old_rc new_rc caps
|
|
504
|
+
pty_keys Enter
|
|
505
|
+
old_frame="$(_st_old_wait " · TEAM_MONITOR_UI")"; old_rc=$?
|
|
506
|
+
if [ "$old_rc" -eq 0 ] && ! printf '%s' "$old_frame" | grep -qF '› 保持未设'; then
|
|
507
|
+
_st_ok "旧逻辑(只看标题 + 固定 sleep)在同一帧序列上第 1 帧就放行,而那一帧还没有条目标记 —— §38-b 的假红入口"
|
|
508
|
+
printf ' 旧逻辑放行的那一帧:\n'
|
|
509
|
+
printf '%s\n' "$old_frame" | sed 's/^/ │ /'
|
|
510
|
+
else
|
|
511
|
+
_st_bad "旧逻辑居然没有在中间帧放行(演示不成立)rc=$old_rc"
|
|
512
|
+
fi
|
|
513
|
+
_st_reset view
|
|
514
|
+
pty_keys Enter
|
|
515
|
+
caps="$(_st_ticks)"
|
|
516
|
+
PTY_WAIT_ITERS=8 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 pty_wait_frame "$st_dir/released.txt" "picker" " · TEAM_MONITOR_UI" "› 保持未设"
|
|
517
|
+
new_rc=$?
|
|
518
|
+
caps=$(( $(_st_ticks) - caps ))
|
|
519
|
+
if [ "$new_rc" -eq 0 ] && grep -qF '› 保持未设' "$st_dir/released.txt" && grep -qF 'auto · 默认' "$st_dir/released.txt"; then
|
|
520
|
+
_st_ok "新逻辑等到条目落地、帧静止才放行($caps 次 capture / 8 轮预算 —— 自适应,不是熬预算)"
|
|
521
|
+
_st_ok "新逻辑放行的那一帧同时有条目标记 [› 保持未设] 和最后一条目 [auto · 默认](标题命中不算数,中间帧不放行)"
|
|
522
|
+
else
|
|
523
|
+
_st_bad "新逻辑没有等到稳定帧(rc=$new_rc,PTY_SELFTEST_BREAK=${PTY_SELFTEST_BREAK:-无})"
|
|
524
|
+
fi
|
|
525
|
+
|
|
526
|
+
# ── 判据②:清理 esc 先确认状态 ──
|
|
527
|
+
_st_reset view
|
|
528
|
+
local guard_rc
|
|
529
|
+
pty_cleanup_esc "cleanup-already-closed" " · TEAM_MONITOR_UI"; guard_rc=$?
|
|
530
|
+
if [ "$guard_rc" -eq 0 ] && [ "$(_st_keys_count)" -eq 0 ] && [ "$(cat "$st_dir/mode")" = "view" ]; then
|
|
531
|
+
_st_ok "选择器早已关闭的现场:清理不发键(0 次 send-keys),设置视图完好 —— 旧写法的裸 esc 在这里"
|
|
532
|
+
_st_ok " 会把它整个关掉"
|
|
533
|
+
else
|
|
534
|
+
_st_bad "清理守卫把键发出去了或视图没了(keys=$(_st_keys_count) mode=$(cat "$st_dir/mode") rc=$guard_rc)"
|
|
535
|
+
fi
|
|
536
|
+
# The old shape, demonstrated on the same closed scene: a bare esc closes the whole view.
|
|
537
|
+
_st_reset view
|
|
538
|
+
pty_keys Escape
|
|
539
|
+
if [ "$(cat "$st_dir/mode")" = "closed" ]; then
|
|
540
|
+
_st_ok "旧写法(裸 esc)在同一现场按下一次键、设置视图被关掉 —— 这就是 62 条级联的第一个入口"
|
|
541
|
+
else
|
|
542
|
+
_st_bad "裸 esc 的演示没有关掉视图(假件不符合预期)"
|
|
543
|
+
fi
|
|
544
|
+
# And the guard is not "never send": with the picker really open it escs exactly once.
|
|
545
|
+
_st_reset picker
|
|
546
|
+
pty_cleanup_esc "cleanup-open" " · TEAM_MONITOR_UI"; guard_rc=$?
|
|
547
|
+
if [ "$guard_rc" -eq 0 ] && [ "$(_st_keys_count)" -eq 1 ] && [ "$(cat "$st_dir/mode")" = "view" ]; then
|
|
548
|
+
_st_ok "选择器真开着:守卫恰好发一个 esc 并确认关闭(选择器 → 设置视图)"
|
|
549
|
+
else
|
|
550
|
+
_st_bad "清理守卫在选择器开着时没有 esc 或没有关掉(keys=$(_st_keys_count) mode=$(cat "$st_dir/mode"))"
|
|
551
|
+
fi
|
|
552
|
+
|
|
553
|
+
# ── 判据③:失败自带现场(三次故意失败一次性做完再断言 —— _st_ok 会把级联清零,就像真夹具里的 ok) ──
|
|
554
|
+
_st_reset view
|
|
555
|
+
local scene1 scene2 scene3 scene4
|
|
556
|
+
PTY_WAIT_ITERS=3 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 pty_wait_frame "$st_dir/last.txt" "绝不存在的条目" "这条目永远不来" 2> "$st_dir/scene1.txt" || true
|
|
557
|
+
pty_bad "故意失败①" 2> "$st_dir/scene2.txt"
|
|
558
|
+
pty_bad "故意失败②" 2> "$st_dir/scene3.txt"
|
|
559
|
+
_st_ok "(级联计数中间的一次成功,等价于真夹具里通过的那条断言)"
|
|
560
|
+
pty_bad "故意失败③" 2> "$st_dir/scene4.txt"
|
|
561
|
+
scene1="$(cat "$st_dir/scene1.txt")"; scene2="$(cat "$st_dir/scene2.txt")"
|
|
562
|
+
scene3="$(cat "$st_dir/scene3.txt")"; scene4="$(cat "$st_dir/scene4.txt")"
|
|
563
|
+
if printf '%s' "$scene1" | grep -q '绝不存在的条目' \
|
|
564
|
+
&& printf '%s' "$scene1" | grep -q '这条目永远不来' \
|
|
565
|
+
&& printf '%s' "$scene1" | grep -q '再 capture' \
|
|
566
|
+
&& printf '%s' "$scene1" | grep -q '│ ' \
|
|
567
|
+
&& printf '%s' "$scene1" | grep -q '轮数 3/3'; then
|
|
568
|
+
_st_ok "等待超时自带现场:等待名 / 轮数与耗时 / 缺失项 / pane 末行 / 超时后立即再 capture,五样都在"
|
|
569
|
+
else
|
|
570
|
+
_st_bad "超时现场缺项(见 $st_dir/scene1.txt)"
|
|
571
|
+
fi
|
|
572
|
+
if printf '%s' "$scene2" | grep -q '孤立' && printf '%s' "$scene2" | grep -q '等待超时'; then
|
|
573
|
+
_st_ok "第一次失败被标成孤立,并指回上面那条等待超时现场"
|
|
574
|
+
else
|
|
575
|
+
_st_bad "第一次失败没有被标成孤立"
|
|
576
|
+
fi
|
|
577
|
+
if printf '%s' "$scene3" | grep -q '级联'; then
|
|
578
|
+
_st_ok "紧接着的第二次失败被标成级联(先修第一条)"
|
|
579
|
+
else
|
|
580
|
+
_st_bad "第二次失败没有被标成级联"
|
|
581
|
+
fi
|
|
582
|
+
if printf '%s' "$scene4" | grep -q '孤立'; then
|
|
583
|
+
_st_ok "成功之后的新失败回到孤立"
|
|
584
|
+
else
|
|
585
|
+
_st_bad "成功之后的新失败没有回到孤立"
|
|
586
|
+
fi
|
|
587
|
+
|
|
588
|
+
# ── 判据④:视界是失败探测器 —— 慢但仍在绘制就延长,静态场景一点不延长 ──
|
|
589
|
+
local ext_rc ext_rounds stat_rc stat_rounds
|
|
590
|
+
_st_reset slow
|
|
591
|
+
PTY_WAIT_ITERS=6 PTY_STALL_ROUNDS=2 PTY_EXT_FACTOR=3 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
592
|
+
pty_wait_frame "$st_dir/slow.txt" "慢但仍在绘制" "慢帧条目" 2> "$st_dir/slow.err"
|
|
593
|
+
ext_rc=$?; ext_rounds="${PTY_WAIT_ROUNDS:-0}"
|
|
594
|
+
if [ "$ext_rc" -eq 0 ] && [ "$ext_rounds" -gt 6 ]; then
|
|
595
|
+
_st_ok "慢但仍在绘制:基础视界 6 轮之上仍在等,第 $ext_rounds 轮拿到条目(延长是等出来的,不是放松阈值)"
|
|
596
|
+
else
|
|
597
|
+
_st_bad "延长没有生效(rc=$ext_rc rounds=$ext_rounds;断点=${PTY_SELFTEST_BREAK:-无})"
|
|
598
|
+
fi
|
|
599
|
+
_st_reset view
|
|
600
|
+
PTY_WAIT_ITERS=6 PTY_STALL_ROUNDS=2 PTY_EXT_FACTOR=3 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
601
|
+
pty_wait_frame "$st_dir/static.txt" "静态场景" "这条目永远不来" 2> "$st_dir/static.err"
|
|
602
|
+
stat_rc=$?; stat_rounds="${PTY_WAIT_ROUNDS:-0}"
|
|
603
|
+
if [ "$stat_rc" -eq 1 ] && [ "$stat_rounds" -eq 6 ]; then
|
|
604
|
+
_st_ok "静态场景:基础视界 6 轮就用满(不是延长的 18 轮)→ 红:延长永远藏不住静态失败"
|
|
605
|
+
else
|
|
606
|
+
_st_bad "静态场景被延长或没红(rc=$stat_rc rounds=$stat_rounds;断点=${PTY_SELFTEST_BREAK:-无})"
|
|
607
|
+
fi
|
|
608
|
+
|
|
609
|
+
# ── 判据⑤:耗尽那一刻的归因 —— 超前提是可见 SKIP(不是失败),前提之下仍是红 ──
|
|
610
|
+
# 注入的前提钩子(真实夹具里由 panel-p21.sh 提供;这里换成一个可切换的自检读数)。
|
|
611
|
+
_pty_selftest_premise="under"
|
|
612
|
+
pty_premise_over() { [ "${_pty_selftest_premise:-under}" = "over" ]; }
|
|
613
|
+
pty_premise_reason() {
|
|
614
|
+
printf '注入读数:探针 999ms > 顶 120ms(loadavg %s · %s 核)' \
|
|
615
|
+
"$(cut -d' ' -f1 /proc/loadavg 2>/dev/null || echo '?')" "$(nproc 2>/dev/null || echo '?')"
|
|
616
|
+
}
|
|
617
|
+
local skip_rc red_rc
|
|
618
|
+
_st_reset view
|
|
619
|
+
_pty_selftest_premise="over"
|
|
620
|
+
PTY_WAIT_ITERS=6 PTY_STALL_ROUNDS=2 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
621
|
+
pty_wait_frame "$st_dir/skip.txt" "超前提的等待" "这条目永远不来" > "$st_dir/skip.out" 2> "$st_dir/skip.err"
|
|
622
|
+
skip_rc=$?
|
|
623
|
+
if [ "$skip_rc" -eq 3 ] && [ "${PTY_SKIPPED:-0}" = "1" ] \
|
|
624
|
+
&& grep -q 'SKIP' "$st_dir/skip.out" && grep -q '超前提的等待' "$st_dir/skip.out" \
|
|
625
|
+
&& grep -q '999ms' "$st_dir/skip.out" && grep -q '这条目永远不来' "$st_dir/skip.out"; then
|
|
626
|
+
_st_skip "超前提:rc=3 + PTY_SKIPPED=1 + 一行可见 SKIP(点名等待/轮数/耗时/现场/读数)→ 记为 skip,不是失败"
|
|
627
|
+
else
|
|
628
|
+
_st_bad "超前提没有给出可见 SKIP(rc=$skip_rc PTY_SKIPPED=${PTY_SKIPPED:-};断点=${PTY_SELFTEST_BREAK:-无})"
|
|
629
|
+
fi
|
|
630
|
+
_st_reset view
|
|
631
|
+
_pty_selftest_premise="under"
|
|
632
|
+
PTY_WAIT_ITERS=6 PTY_STALL_ROUNDS=2 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
633
|
+
pty_wait_frame "$st_dir/red.txt" "前提之内的等待" "这条目永远不来" 2> "$st_dir/red.err"
|
|
634
|
+
red_rc=$?
|
|
635
|
+
if [ "$red_rc" -eq 1 ] && [ "${PTY_SKIPPED:-0}" = "0" ] && grep -q '等待超时' "$st_dir/red.err"; then
|
|
636
|
+
_st_ok "前提之内:同一个静态现场仍是红(rc=1 + M59 现场)—— SKIP 不是逃逸门"
|
|
637
|
+
else
|
|
638
|
+
_st_bad "前提之内的耗尽没有红(rc=$red_rc PTY_SKIPPED=${PTY_SKIPPED:-};断点=${PTY_SELFTEST_BREAK:-无})"
|
|
639
|
+
fi
|
|
640
|
+
|
|
641
|
+
# ── 判据⑥:长帧(>128 KiB)的两向 —— 命中不能被 SIGPIPE 吃掉,缺失必须照缺报(P127)──
|
|
642
|
+
# P124 的最小复现:帧 120607 B > 管道缓冲(64 KiB),needle 在最前面;旧写法
|
|
643
|
+
# `printf '%s\n' "$c" | grep -qF` 命中即退 → 写端 SIGPIPE → pipefail 下 rc=141 → 假「没出现」。
|
|
644
|
+
# 这里把帧撑到 >128 KiB,正反两向都走等待引擎本身(不是直调内部谓词)。
|
|
645
|
+
head -c 140000 /dev/zero | tr '\0' 'x' > "$st_dir/long-body"
|
|
646
|
+
{ printf 'P127-LONG-NEEDLE\n'; cat "$st_dir/long-body"; } > "$st_dir/longframe"
|
|
647
|
+
local long_bytes long_hit_rc long_miss_rc
|
|
648
|
+
long_bytes="$(wc -c < "$st_dir/longframe" | tr -d ' ')"
|
|
649
|
+
_pty_selftest_premise="under"
|
|
650
|
+
_st_reset long
|
|
651
|
+
PTY_WAIT_ITERS=6 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
652
|
+
pty_wait_frame "$st_dir/longhit.txt" "P127 长帧命中" "P127-LONG-NEEDLE" 2> "$st_dir/longhit.err"
|
|
653
|
+
long_hit_rc=$?
|
|
654
|
+
if [ "$long_hit_rc" -eq 0 ] && [ "$(sed -n 1p "$st_dir/longhit.txt")" = "P127-LONG-NEEDLE" ]; then
|
|
655
|
+
_st_ok "长帧命中:${long_bytes}B(>128 KiB)里第一行的 needle 直接命中(rc=0;旧写法在这里 rc=141 假缺)"
|
|
656
|
+
else
|
|
657
|
+
_st_bad "长帧命中被判成没出现(rc=$long_hit_rc;断点=${PTY_SELFTEST_BREAK:-无})"
|
|
658
|
+
fi
|
|
659
|
+
_st_reset long
|
|
660
|
+
PTY_WAIT_ITERS=6 PTY_WAIT_PAUSE=0.01 PTY_SETTLE_PAUSE=0.01 \
|
|
661
|
+
pty_wait_frame "$st_dir/longmiss.txt" "P127 长帧缺失" "P127-NEEDLE-NEVER" 2> "$st_dir/longmiss.err"
|
|
662
|
+
long_miss_rc=$?
|
|
663
|
+
if [ "$long_miss_rc" -eq 1 ] && grep -qF '缺 [P127-NEEDLE-NEVER]' "$st_dir/longmiss.err"; then
|
|
664
|
+
_st_ok "长帧缺失:同一个 ${long_bytes}B 的帧里 needle 不在 → 照缺报(rc=1 + 现场点名缺项)"
|
|
665
|
+
else
|
|
666
|
+
_st_bad "长帧缺失没有照缺报(rc=$long_miss_rc;断点=${PTY_SELFTEST_BREAK:-无})"
|
|
667
|
+
fi
|
|
668
|
+
|
|
669
|
+
printf '\n\033[1m== 结果 ==\033[0m ✓ %d ✗ %d SKIP %d\n' "$_PASS" "$_FAIL" "$_SKIP"
|
|
670
|
+
[ "$_FAIL" -eq 0 ] && exit 0
|
|
671
|
+
exit 1
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if [ "${BASH_SOURCE[0]:-}" = "${0:-}" ] && [ "${1:-}" = "--self-test" ]; then
|
|
675
|
+
pty_selftest "${2:-}"
|
|
676
|
+
fi
|