Skip to content

Add tuistory PTY integration coverage#139

Merged
benvinegar merged 1 commit intomainfrom
pi/tuistory-integration-tests
Mar 30, 2026
Merged

Add tuistory PTY integration coverage#139
benvinegar merged 1 commit intomainfrom
pi/tuistory-integration-tests

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • add tuistory-backed PTY integration coverage under the standard Bun test runner
  • cover wrap toggles, agent notes, hunk navigation, resize behavior, filtering, pager paging, and mouse-wheel scrolling
  • disable startup update notices in deterministic integration sessions and run the new suite in CI

Testing

  • bun run test:integration
  • bun test test/update-notice.test.ts

This PR description was generated by Pi using OpenAI o3

@socket-security
Copy link
Copy Markdown

socket-security bot commented Mar 30, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedtuistory@​0.0.167610010095100

View full report

@benvinegar benvinegar force-pushed the pi/tuistory-integration-tests branch from 2faad4f to 1398897 Compare March 30, 2026 12:25
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 30, 2026

Greptile Summary

This PR introduces a tuistory-backed PTY integration test suite that runs under the standard Bun test runner, covering seven user-visible behaviors: wrap-line toggle, agent notes reveal/hide, hunk navigation, live terminal resize, filter focus, pager paging, and mouse-wheel scrolling. A supporting HUNK_DISABLE_UPDATE_NOTICE env flag is added to updateNotice.ts so integration sessions are deterministic (no outbound npm fetch), and both CI workflows are updated to run the new suite automatically.

Key changes:

  • test/integration/tuistoryHarness.ts: New test harness — resolves the Bun executable, creates isolated temp fixtures (file pairs, git repos, patch files), and exposes launchHunk / waitForSnapshot helpers. One minor timing edge case exists in waitForSnapshot where the very last polled snapshot is not checked against the predicate before the timeout error is thrown.
  • test/integration/tuistory-hunk.integration.ts: Seven integration tests, each using try/finally to guarantee session cleanup on failure.
  • src/core/updateNotice.ts: Clean env-var guard (HUNK_DISABLE_UPDATE_NOTICE=1) that short-circuits the async npm fetch path; covered by a new unit test in test/update-notice.test.ts.
  • CI workflows: bun run test:integration added as a sequential step in both ci.yml and pr-ci.yml after the regular test suite.

Confidence Score: 5/5

Safe to merge — all findings are P2 quality suggestions and no production code paths are at risk.

The only finding is a minor polling-loop race in the test harness's waitForSnapshot that could occasionally produce a false timeout (~1.6% of cycles at the timeout boundary). Production code changes are minimal and well-tested. CI integration is straightforward.

test/integration/tuistoryHarness.ts — the waitForSnapshot polling loop should add a final predicate check before throwing.

Important Files Changed

Filename Overview
test/integration/tuistoryHarness.ts New PTY test harness: resolves bun binary, creates typed fixtures, exposes launchHunk/waitForSnapshot. One timing edge case in waitForSnapshot where the final snapshot is not predicate-checked before the timeout throw.
test/integration/tuistory-hunk.integration.ts New integration test suite covering 7 PTY scenarios (wrap toggle, agent notes, hunk navigation, resize, filter, pager, mouse wheel). try/finally pattern correctly closes sessions on failure.
src/core/updateNotice.ts Adds HUNK_DISABLE_UPDATE_NOTICE env guard to short-circuit resolveStartupUpdateNotice in CI/integration sessions. Clean, well-tested change.
test/update-notice.test.ts Adds a unit test for the new HUNK_DISABLE_UPDATE_NOTICE guard; correctly restores the env var in a finally block.
.github/workflows/ci.yml Adds bun run test:integration step to the main CI job after the regular test suite. No issues.
.github/workflows/pr-ci.yml Adds bun run test:integration step to the PR CI job between test suite and terminal tools verification. No issues.
package.json Adds test:integration script and tuistory ^0.0.16 devDependency. Conservative pre-release pinning is appropriate.

Sequence Diagram

sequenceDiagram
    participant BunTest as Bun Test Runner
    participant Harness as tuistoryHarness
    participant Tuistory as tuistory (PTY)
    participant Hunk as hunk process (PTY child)

    BunTest->>Harness: createTuistoryHarness()
    BunTest->>Harness: createXxxFixture()
    Harness-->>BunTest: { fixture paths }
    BunTest->>Harness: launchHunk({ args, cols, rows })
    Harness->>Tuistory: launchTerminal(bun run src/main.tsx)
    Tuistory->>Hunk: spawn in PTY (HUNK_DISABLE_UPDATE_NOTICE=1)
    Hunk-->>Tuistory: PTY output stream
    Tuistory-->>BunTest: Session
    BunTest->>Harness: session.waitForText(regex)
    Harness->>Tuistory: session.text({ immediate })
    Tuistory-->>Harness: snapshot string
    BunTest->>Harness: session.press(key) / scrollDown / resize
    Harness->>Tuistory: forward input to PTY
    BunTest->>Harness: waitForSnapshot(predicate, timeout)
    loop poll every ~80 ms
        Harness->>Tuistory: waitIdle + session.text
        Tuistory-->>Harness: snapshot
    end
    Harness-->>BunTest: snapshot (or timeout error)
    BunTest->>Harness: session.close()
    BunTest->>Harness: cleanup() [afterEach]
    Harness->>Harness: rmSync all temp dirs
Loading

Comments Outside Diff (1)

  1. test/integration/tuistoryHarness.ts, line 915-927 (link)

    P2 waitForSnapshot can miss a satisfied snapshot at timeout boundary

    After session.text() refreshes snapshot at the bottom of the loop body, the loop's while condition is re-evaluated before the predicate is checked on that new snapshot. If the timeout has just elapsed between the await session.text(...) call and the condition check, the loop exits and the function throws — even though snapshot now satisfies the predicate. The error message even shows that content in the Last snapshot: dump, which can be confusing during debugging.

    With a ~80 ms polling cadence against a 5 000 ms timeout this affects roughly the last cycle (~1.6 %), which is just enough to produce occasional flaky CI failures.

    Adding a final predicate check before throwing eliminates the race entirely:

Reviews (1): Last reviewed commit: "Add tuistory PTY integration tests" | Re-trigger Greptile

@benvinegar benvinegar force-pushed the pi/tuistory-integration-tests branch from 1398897 to 8c7f422 Compare March 30, 2026 12:34
@benvinegar benvinegar force-pushed the pi/tuistory-integration-tests branch from 8c7f422 to 547cc38 Compare March 30, 2026 12:46
@benvinegar benvinegar merged commit b209e85 into main Mar 30, 2026
3 checks passed
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.

1 participant