Skip to content

fix(test): stabilize terminal PTY fragments and add timing diagnostics - #746

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/terminal-pty-fragment-timing
Sep 10, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
loveRhythm1990:fix/terminal-pty-fragment-timing

Conversation

@loveRhythm1990

Copy link
Copy Markdown
Collaborator

Summary

Stabilize the fragmented-response PTY fixture and add useful failure diagnostics after the macOS terminal PTY lane failed on main.

  • Replace one write/sleep per byte with four deliberate chunks, splitting the opening ESC, ST terminator, and RGB payload. Pace them against absolute offsets instead of accumulating relative sleep overshoot.
  • Keep the real 300 ms startup deadline, parser deadlines, expected light/dark result, input-preservation checks, and terminal-restoration checks unchanged. No retries or ignored tests are added.
  • Include parent query-observation, response-write, DA1-write, and readiness timestamps in test failure output, alongside the child's startup duration and decoded colors/theme/events.
  • Add a parser unit test that feeds foreground and background replies byte by byte without sleeps, complementing the existing every-split-boundary test. PTY writes can be coalesced by the OS, so exact bytewise parsing coverage belongs in the parser tests.
  • Document the fixture and timing fields in the vendor patch notes.

Related issue

Follow-up to #745 and the failing macOS PTY job.

That run passed every other job, including Linux PTY and the previously repaired Docker layout contract. The failure was pty_detects_light_dark_and_fragmented_responses: the fragmented case expected light mode but received dark mode. Accumulated sender scheduling delays are a plausible cause, not proven by the old logs, which did not include timing or the complete probe result. Thirty local repetitions of the old fixture did not reproduce the failure. This change removes the avoidable accumulated-sleep dependency and adds evidence for any remaining failures; it does not claim to have conclusively reproduced the runner's original timing.

Change type

  • Feature
  • Bug fix
  • Documentation
  • Refactor or performance improvement
  • Test
  • Build, CI, or maintenance

User and compatibility impact

None for application behavior, APIs, credentials, or database schemas. Only test fixtures, test diagnostics, a parser unit test, and patch documentation change. Product timeouts and terminal parsing behavior remain unchanged. Diagnostics contain synthetic test-terminal data, not user terminal content.

Architecture and complexity delta

N/A for production architecture.

  • Canonical owner changed or extended: existing CLI terminal-startup PTY harness and vendored Unix parser tests.
  • Existing implementations and callers searched: StartupTerminal::begin, query_startup_attributes, parser escape/response deadlines, PTY sender and assertions, and both CI reader invocations.
  • Superseded code, states, tables, shims, or self-only tests removed: per-byte relative sleeps in the end-to-end sender; no product implementation removed.
  • If parallel implementations remain, their boundary and retirement condition: none. Unit tests force exact parser fragmentation; PTY tests exercise the real startup/reader/terminal lifecycle.

Verification

Commands and results on local macOS ARM:

  • cargo test --locked -p astra-cli --lib tui::terminal_startup -- --test-threads=2: 14 passed.
  • cargo test --locked -p astra-cli --lib --features crossterm/use-dev-tty tui::terminal_startup -- --test-threads=2: 14 passed.
  • Repeated tui::terminal_startup::pty_tests::pty_detects_light_dark_and_fragmented_responses directly from each freshly built test executable: 50 runs per reader, two concurrent processes, zero failures, with no retries. Each run covers light, fragmented, background-only, and dark cases.
  • cargo test --locked --manifest-path vendor/crossterm/Cargo.toml --lib --features event-stream: 106 passed, 7 ignored.
  • cargo test --locked --manifest-path vendor/crossterm/Cargo.toml --lib --features event-stream,use-dev-tty: 106 passed, 7 ignored.
  • python3 -m unittest discover -s scripts/ci -p 'test_*.py': 77 passed.
  • python3 scripts/ci/validate_repository.py: passed.
  • cargo fmt --all --check: passed.
  • rustfmt --check --edition 2021 vendor/crossterm/src/event/source/unix/parser.rs: passed.
  • git diff --check: passed.

Public entrypoint exercised: real CLI startup, terminal guard, event reader, and EventStream through isolated PTYs; no model or service required.

Unhappy paths exercised: existing unsupported/late/malformed responses, timeouts, interrupted startup/handoff, escape/input preservation, and terminal-mode restoration tests remain enabled and passed for both readers.

Database verification: not applicable.

Limits: the original GitHub macOS failure was not reproduced locally; hosted macOS/Linux verification remains for CI. Full workspace Rust suites and release images were not rebuilt for this test-only change. The local CLI links emitted the existing __eh_frame size warning; selected tests passed.

Final checklist

  • I added or updated tests at the layer that owns the behavior, or explained why no test is needed.
  • I updated public or design documentation for contract changes, or the change needs no documentation update.
  • I checked the diff for credentials, private URLs, customer data, generated files, and other sensitive information.
  • The PR title follows the repository's Conventional Commit format.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 26d2035 against e86f9bb. No blocking findings.

I read all three changed files and traced the fixture through StartupTerminal::begin, query_startup_attributes, parser framing/deadlines, the pre-handoff Sixel cache observation, and the subsequent input/restoration assertions.

The four fragments concatenate to the original reply and retain the opening-ESC, ST, and RGB splits. Absolute offsets remove accumulated relative-sleep overhead without changing the 300 ms product deadline or the parser's deadlines. Exact bytewise fragmentation is tested directly through Parser::advance, with ordered OSC responses and surrounding keys asserted; PTY write coalescing therefore does not invalidate that coverage.

The delayed-DA1 case still checks a product result (sixel_before == true before TUI/EventStream handoff), in addition to the sender's recorded delay. The explicit negative-response and late-response/unknown cases remain. Moving the reply to 80 ms gives the integration fixture scheduling headroom; it deliberately gives up the former near-deadline timing scenario, as documented. This is not evidence that every response close to the deadline will be accepted under arbitrary scheduling.

I also read the original failing macOS job: it shows the fragmented light/dark mismatch, but does not establish the timing root cause. The PR appropriately treats scheduling as a hypothesis and adds observations without claiming conclusive reproduction. Parent timestamps are observations after spawn, not the child's actual query-start clock.

Validation: local git diff --check passed. Cargo is unavailable here, so I did not locally execute Rust tests or reproduce the original failure. I independently fetched the current GitHub Actions results and logs: Static Checks and Test Suite succeeded; Linux and macOS each ran both reader configurations with 14 PTY tests passing per invocation. The Linux vendor log confirms the new bytewise test ran and both configurations passed 106 tests with 7 ignored; the macOS vendor job also succeeded. No production code, live services, or release artifacts were changed during this review.

The PR head was rechecked immediately before submission and is unchanged.

@mergify mergify Bot added the queued label Sep 10, 2026
@mergify

mergify Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-10 06:12 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-09-10 06:12 UTC · at 5ac805dc1dad95c00ba876ae6e48447a4f801a2a · squash

This pull request spent 12 seconds in the queue, including 1 second running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Check PR title
    • check-neutral = Check PR title
    • check-skipped = Check PR title
  • any of [🛡 GitHub branch protection]:
    • check-success = check
    • check-neutral = check
    • check-skipped = check
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: core crates + bridge hooks
    • check-neutral = Test: core crates + bridge hooks
    • check-skipped = Test: core crates + bridge hooks
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-runtime
    • check-neutral = Test: astra-runtime
    • check-skipped = Test: astra-runtime
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-fs-tools)
    • check-neutral = Test: astra-cli (edge-fs-tools)
    • check-skipped = Test: astra-cli (edge-fs-tools)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-git-gix)
    • check-neutral = Test: astra-cli (edge-git-gix)
    • check-skipped = Test: astra-cli (edge-git-gix)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-rest)
    • check-neutral = Test: astra-cli (edge-rest)
    • check-skipped = Test: astra-cli (edge-rest)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (edge-shell)
    • check-neutral = Test: astra-cli (edge-shell)
    • check-skipped = Test: astra-cli (edge-shell)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: astra-cli (non-edge)
    • check-neutral = Test: astra-cli (non-edge)
    • check-skipped = Test: astra-cli (non-edge)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (core)
    • check-neutral = Test: online (core)
    • check-skipped = Test: online (core)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: online (integration)
    • check-neutral = Test: online (integration)
    • check-skipped = Test: online (integration)
  • any of [🛡 GitHub branch protection]:
    • check-success = Test: turn-core + services + plan
    • check-neutral = Test: turn-core + services + plan
    • check-skipped = Test: turn-core + services + plan
  • any of [🛡 GitHub branch protection]:
    • check-skipped = web (typecheck, test, build)
    • check-neutral = web (typecheck, test, build)
    • check-success = web (typecheck, test, build)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Astra SDK (typecheck, test+coverage, build)
    • check-neutral = Astra SDK (typecheck, test+coverage, build)
    • check-success = Astra SDK (typecheck, test+coverage, build)

@mergify
mergify Bot merged commit 5ac805d into matrixorigin:main Sep 10, 2026
26 of 27 checks passed
@mergify mergify Bot removed the queued label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants