Skip to content

Stabilize flaky tests and expand coverage - #1967

Merged
ymichael merged 6 commits into
mainfrom
bb/audit-and-fix-test-coverage-thr_sjkgnzm8bp
Aug 19, 2026
Merged

ymichael merged 6 commits into
mainfrom
bb/audit-and-fix-test-coverage-thr_sjkgnzm8bp

Conversation

@ymichael

@ymichael ymichael commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What was wrong

The test suite had three related quality problems: an ACP integration test used file existence as a proxy for completed output and could race with a confirmed child-process stdin teardown error (CI run 32188276525); package coverage reports omitted unimported runtime files, hiding substantial gaps; and high-risk JSON-RPC/GitHub behavior had little boundary coverage while presentation-only header sizing assertions added maintenance cost without protecting product behavior. Recent GitHub sync/auth fixes in #1282, #1758, and #1854 helped identify the missing regression surfaces. The first PR run also exposed a source-wrapper test that deep-compared the unrelated, evolving bb status payload; Turbo did not model its hidden @bb/cli dependency, so the stale assertion had previously remained cached green.

What changed

  • Wait for the completed ACP turn rather than file creation, and suppress only the benign EPIPE/ERR_STREAM_DESTROYED child-stdin teardown race.
  • Add lifecycle regression tests for ACP connection shutdown and write completion.
  • Add opt-in reproducible V8 coverage for packages using the shared Vitest configuration. Explicit source globs include files never imported by tests; normal test and CI runs remain unchanged unless --coverage is passed, and no threshold is imposed.
  • Expand provider JSON-RPC coverage from one test to ten across parsing, malformed messages, schema validation, timeouts, notifications, structured errors, and exactly-once settlement.
  • Add GitHub plugin RPC tests for sync, cache patching, PR/check/review normalization, pagination, and file patches, plus app tests for routes, query matching, and suggestions.
  • Ensure all GitHub plugin test files are included in typechecking and remove three presentation-only header sizing tests.
  • Keep the source CLI wrapper test focused on clean, parseable JSON and declare its @bb/cli#build Turbo dependency so CLI changes cannot reuse a stale test result.

There are no server/daemon wire changes, CLI changes, or user-facing configuration changes, so no protocol-version or guide update is required.

How you verified

  • Replacement PR CI run 32311230863 passed every required check, including packages, server, integration, all app shards, and Linux/macOS package smoke.
  • pnpm exec turbo run test --filter=@bb/scripts --force — 17 files and 92 tests passed; the command explicitly executes @bb/cli#build first.
  • pnpm exec turbo run test --filter=@bb/integration-tests --force — 55 tests passed.
  • pnpm exec turbo run test typecheck --filter=@bb/provider-bridge-protocol --filter=bb-plugin-github --force after rebasing — 86 provider tests and 21 GitHub tests passed; both relevant typechecks passed.
  • Repeated the new provider transport tests 25 times (250 executions) and the complete GitHub plugin suite 10 times (210 executions) without a failure.
  • Provider bridge line coverage increased from 60.00% to 66.96%; runtime-json-rpc.ts reaches 90.32%.
  • GitHub plugin line coverage increased from 23.07% to 41.19%; server.ts increased from 40.22% to 69.31%.
  • Full app and server audit runs passed 3,092 app tests and 1,775 server tests.

Fixes: N/A — test-coverage audit without a single tracking issue.

AGENT GENERATED: by GPT-5

@bb-slop-cop

bb-slop-cop Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, duplication, and product behavior. Three review agents will work in parallel. I will also run focused tests and a browser check when this change affects a browser route.

@ymichael
ymichael force-pushed the bb/audit-and-fix-test-coverage-thr_sjkgnzm8bp branch from b4462ce to d7419a7 Compare August 19, 2026 22:58
@ymichael
ymichael merged commit abbc3f9 into main Aug 19, 2026
12 checks passed
@ymichael
ymichael deleted the bb/audit-and-fix-test-coverage-thr_sjkgnzm8bp branch August 19, 2026 23:06
// and the kernel accepting the write. Node reports that race asynchronously
// on the stream; without a listener it becomes an uncaught EPIPE and can
// crash the bridge worker while the normal child-exit path is settling.
child.stdin?.on("error", handleAgentStdinError);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — This handler can leave ACP requests pending forever.

The handler ignores a closed input stream, but it leaves exited false. request() then adds an entry before writeLine() returns without a write. A child can close its input and remain alive. The pending request then has no timeout or exit event. I reproduced this result with a persistent child: still-pending. Please close the connection for these errors. Reject pending and future requests, then stop the child. Add a request rejection test for this path.

@@ -0,0 +1,122 @@
// @vitest-environment jsdom

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 slopcop/review — These pure logic tests load the complete GitHub panel.

This file starts JSDOM, installs the plugin runtime, and imports the 2,508-line app.tsx module. A focused run took 21.45 seconds. The import took 13.70 seconds, the environment took 6.31 seconds, and the tests took 8 milliseconds. Please move the route, query, and suggestion logic into a small Node-safe module. Import that module from the panel and this test. This change will also remove the test-only exports from the panel.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

Plain-English summary: This pull request adds tests for the GitHub plugin and the provider bridge. It also prevents two expected input errors from stopping the ACP bridge process. It adds optional V8 coverage data and removes a fragile button-size test.

I found one blocking defect and one important test cost.

  • The new ACP input error handler can leave requests pending forever. A child can close its input but remain alive. I reproduced the unresolved request with a persistent child. The connection must reject pending and future requests, then stop the child.
  • Five pure GitHub logic tests load the complete 2,508-line panel. A focused run took 21.45 seconds, but the tests used only 8 milliseconds. A small logic module will remove this cost and the test-only panel exports.

The security review found no new security risk. The dependency stays development-only and has lockfile integrity data.

The architecture scan found three duplicate patterns. The ACP closed-stream policy also exists in the provider bridge protocol. The new GitHub server test repeats the fake gh setup from server.auth-latch.test.ts. The GitHub query functions belong in a small shared logic module.

Verification passed for 275 focused tests: 86 protocol tests, 21 GitHub tests, and 168 ACP tests. git diff --check also passed. All GitHub CI jobs passed, including the build and type check. The local dev launcher did not finish its SDK declaration build, so I could not complete the browser check.

I used a comment review only. I did not approve the pull request or request changes.

ymichael added a commit that referenced this pull request Aug 19, 2026
## What was wrong

The post-merge review on
[#1967](#1967 (review))
identified two valid root causes. The ACP connection suppressed expected
EPIPE / ERR_STREAM_DESTROYED events without changing connection state,
so an agent that closed stdin but kept another handle alive could leave
pending requests unresolved forever and continue accepting future
requests. Separately, five pure GitHub route and query tests imported
the 2,508-line panel entrypoint, initializing its React, plugin SDK, and
UI dependency graph just to exercise synchronous logic.

## What changed

- Treat a closed ACP stdin as a fatal transport closure: make the
connection unavailable, reject pending requests, force-stop the child,
and report the exit. The regression fixture closes fd 0 while
deliberately keeping the process alive and checks both pending and
future requests.
- Move GitHub item, route, query, and suggestion logic into
app-logic.ts. The pure module returns serializable icon descriptors;
app.tsx alone renders them into the existing state-dot and avatar UI.
- Point the logic tests directly at the pure module and remove their
jsdom and plugin-runtime setup.
- No server/daemon wire contract, CLI, user-facing configuration, guide,
or protocol-version changes are involved.
- I did not consolidate the two fake-gh fixtures noted by the review:
they share only temporary PATH plumbing, while their command behavior
and failure controls are intentionally different.

## How you verified

- The new ACP persistent-child regression failed before the fix because
the request remained pending past its deadline; it passes after the
connection teardown change.
- pnpm exec turbo run test typecheck --filter=bb-plugin-github
--filter=bb-plugin-provider-acp — 21 GitHub tests and 169 ACP tests
passed; both typechecks passed.
- pnpm exec turbo run build --filter=bb-plugin-github — the production
server, app JavaScript, and app CSS bundles built successfully.
- git diff --check origin/main...HEAD passed.
- In the focused GitHub logic test, Vitest import time dropped from 2.75
s to 27 ms and total file duration dropped from 3.53 s to 129 ms.

Fixes: N/A — post-merge review follow-up to #1967.

> AGENT GENERATED: by GPT-5
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