Skip to content

Increase Scrcpy/Agent test coverage for previously untested integration and error branches#49

Open
Copilot wants to merge 8 commits intomainfrom
copilot/add-missing-test-coverage-scrcpy
Open

Increase Scrcpy/Agent test coverage for previously untested integration and error branches#49
Copilot wants to merge 8 commits intomainfrom
copilot/add-missing-test-coverage-scrcpy

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

  • Fetch open PR review comments and capture exact file/line locations from GitHub API
  • Read current code at each commented line and verify whether requested coverage exists
  • Modify the exact commented line in internal/livefeed/scrcpy_control_test.go while preserving the InjectText failure-path assertion
  • Run gofmt and targeted internal/livefeed tests
  • Run full make lint && make build && make test validation
  • Clarify mockConn.failWriteAt comment indexing per validation feedback and re-run targeted tests

@deepsource-io
Copy link
Copy Markdown

deepsource-io bot commented Apr 16, 2026

DeepSource Code Review

We reviewed changes in f359fdc...3a541d4 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Go Apr 16, 2026 7:53p.m. Review ↗
Code coverage Apr 16, 2026 7:53p.m. Review ↗
Secrets Apr 16, 2026 7:53p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@uelkerd uelkerd requested a review from Copilot April 16, 2026 16:03
Copilot AI changed the title [WIP] Add tests for missing coverage in Scrcpy integration Increase Scrcpy/Agent test coverage for previously untested integration and error branches Apr 16, 2026
Copilot AI requested a review from uelkerd April 16, 2026 16:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds targeted unit tests to increase branch/edge-case coverage in the Scrcpy livefeed integration and agent multi-device execution paths.

Changes:

  • Extend ScrcpyClient control-path tests to cover additional error branches (deadline-setting failure, mid-swipe write failure, first-write failure, and input-action settle timeout).
  • Add agent tests covering multi-device error handling (device listing failure) and runMultiDeviceInternal result population (agent creation error + history assignment).
  • Minor test cleanups/whitespace normalization in existing test files.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
internal/livefeed/scrcpy_control_test.go Adds new coverage-focused tests and enhances mockConn to simulate additional failure modes.
internal/livefeed/scrcpy_capturer_test.go Minor comment/whitespace cleanup (no behavioral change).
internal/agent/agent_test.go Adds multi-device and internal runner coverage tests; minor formatting/whitespace cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@uelkerd uelkerd marked this pull request as ready for review April 16, 2026 18:18
@uelkerd
Copy link
Copy Markdown
Owner

uelkerd commented Apr 16, 2026

/gemini review

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Apr 16, 2026

Reviewer's Guide

Adds branch-focused tests to improve coverage of scrcpy control-path error handling and agent multi-device orchestration paths, plus minor test refactors and mock enhancements, without changing production behavior.

File-Level Changes

Change Details Files
Expanded scrcpy control-path tests to cover previously untested error branches and connection/deadline failures.
  • Extended mockConn to support selective write failures, write counting, and configurable SetWriteDeadline errors.
  • Added coverage for executeInputAction empty input, focus-tap failure with bounds, and context timeout during input settle delay.
  • Added tests for InjectBack first-write failure, InjectSwipe move-step write failure, InjectSwipe zero-step behavior, and InjectKey deadline failure paths.
  • Added additional hardening tests around SetConnWriteDeadlineFromContext and control operation failures when the client is not connected.
internal/livefeed/scrcpy_control_test.go
Improved agent multi-device orchestration coverage and consolidated ADB failure mocking helpers.
  • Added MultiDeviceRun test to assert list-devices errors propagate correctly when ADB listing fails.
  • Added runMultiDeviceInternal tests for NewAgent construction failure and successful history/device result assignment across devices.
  • Introduced reusable mockADBRunnerFail helper for inducing ADB failures in tests and strengthened assertions on per-device error attribution.
  • Expanded various Agent tests to exercise error paths in iteration, streaming loop, session history save, task execution, and MCP serving, improving coverage for context cancellation and configuration edge cases.
internal/agent/agent_test.go
Slightly refined scrcpy capturer tests to support dynamic decoder behavior across calls.
  • Updated scrcpy capturer tests to use a dynamic mock decoder implementation that switches behavior based on call count, enabling coverage of retry behavior when initial frames are metadata and subsequent frames decode successfully.
internal/livefeed/scrcpy_capturer_test.go

Assessment against linked issues

Issue Objective Addressed Explanation
#48 Add unit tests for the missing code paths in internal/livefeed/scrcpy.go (Scrcpy control path and input/inject error branches).
#48 Add unit tests for the missing code paths in internal/agent/agent.go (multi-device orchestration and related error/success branches).
#48 Add unit/integration tests for the missing decoder error handling in internal/livefeed/scrcpy_decoder.go and internal/livefeed/scrcpy_decoder_harden_helper.go. The PR does not add new tests targeting scrcpy_decoder.go or scrcpy_decoder_harden_helper.go; it only mentions relying on existing hardening tests without extending coverage for the previously uncovered decoder error-handling lines.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Some of the new timeout-based tests (e.g., executeInputAction using a 20ms context timeout) may be brittle under slow CI; consider using a longer timeout with explicit cancellation or a controllable clock/timer to avoid flakiness.
  • The expanded mockConn uses overlapping failWrite and failAtWrite controls; it would be clearer to consolidate the failure configuration into a single mechanism or document the precedence to avoid confusion in future tests.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Some of the new timeout-based tests (e.g., `executeInputAction` using a 20ms context timeout) may be brittle under slow CI; consider using a longer timeout with explicit cancellation or a controllable clock/timer to avoid flakiness.
- The expanded `mockConn` uses overlapping `failWrite` and `failAtWrite` controls; it would be clearer to consolidate the failure configuration into a single mechanism or document the precedence to avoid confusion in future tests.

## Individual Comments

### Comment 1
<location path="internal/livefeed/scrcpy_control_test.go" line_range="958" />
<code_context>
 	})
 }
+
+func TestScrcpyClient_executeInputAction_ErrorPaths_Coverage(t *testing.T) {
+	client := &ScrcpyClient{}
+	action := types.Action{Action: "input"}
</code_context>
<issue_to_address>
**suggestion (testing):** `executeInputAction` tests cover empty input, focus-tap failure, and settle-timeout, but they don't exercise the InjectText failure path.

To fully cover the error paths, consider also testing the case where the focus tap succeeds but `InjectText` fails (e.g., via a `ScrcpyClient` using `mockConn{failWrite: true}` and a non-nil `Target.Bounds`). Then assert that the returned error clearly reflects the injection failure, completing coverage of `executeInputAction`’s control-path errors.

Suggested implementation:

```golang
func TestScrcpyClient_executeInputAction_ErrorPaths_Coverage(t *testing.T) {
	client := &ScrcpyClient{}
	action := types.Action{Action: "input"}

	// Empty input value should fail early.
	err := client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "empty input value") {
		t.Fatalf("expected empty input error, got %v", err)
	}

	// Non-empty value with bounds but no control connection should fail with a
	// clear "control socket not connected" error.
	action.Value = "hello"
	action.Target = &types.Target{
		Bounds: &types.Bounds{
			X:      10,
			Y:      10,
			Width:  20,
			Height: 20,
		},
	}

	err = client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "control socket not connected") {
		t.Fatalf("expected control socket not connected error, got %v", err)
	}

	// Now simulate a connected control socket where InjectText fails due to a
	// write error. The focus tap should succeed, but text injection should fail.
	client.control = &mockConn{failWrite: true}

	err = client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "failed to inject text") {
		t.Fatalf("expected inject text error, got %v", err)
	}

```

Because only part of the function was visible in the snippet, you should:

1. Ensure there is no leftover body from the old `TestScrcpyClient_executeInputAction_ErrorPaths_Coverage` after this replacement (i.e., the function should close with the final `}` shown in the REPLACE block).
2. Confirm the actual error string used in `executeInputAction` for the InjectText failure path. If it differs from `"failed to inject text"`, update the substring in the final `strings.Contains` check to match the real message.
3. Verify that `mockConn` is already defined in this test file with a `failWrite` field that triggers a write failure on the control socket, consistent with the existing InjectTap write-failure tests. If the field name or behavior differs, adjust `&mockConn{failWrite: true}` accordingly.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

})
}

func TestScrcpyClient_executeInputAction_ErrorPaths_Coverage(t *testing.T) {
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.

suggestion (testing): executeInputAction tests cover empty input, focus-tap failure, and settle-timeout, but they don't exercise the InjectText failure path.

To fully cover the error paths, consider also testing the case where the focus tap succeeds but InjectText fails (e.g., via a ScrcpyClient using mockConn{failWrite: true} and a non-nil Target.Bounds). Then assert that the returned error clearly reflects the injection failure, completing coverage of executeInputAction’s control-path errors.

Suggested implementation:

func TestScrcpyClient_executeInputAction_ErrorPaths_Coverage(t *testing.T) {
	client := &ScrcpyClient{}
	action := types.Action{Action: "input"}

	// Empty input value should fail early.
	err := client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "empty input value") {
		t.Fatalf("expected empty input error, got %v", err)
	}

	// Non-empty value with bounds but no control connection should fail with a
	// clear "control socket not connected" error.
	action.Value = "hello"
	action.Target = &types.Target{
		Bounds: &types.Bounds{
			X:      10,
			Y:      10,
			Width:  20,
			Height: 20,
		},
	}

	err = client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "control socket not connected") {
		t.Fatalf("expected control socket not connected error, got %v", err)
	}

	// Now simulate a connected control socket where InjectText fails due to a
	// write error. The focus tap should succeed, but text injection should fail.
	client.control = &mockConn{failWrite: true}

	err = client.executeInputAction(context.Background(), action)
	if err == nil || !strings.Contains(err.Error(), "failed to inject text") {
		t.Fatalf("expected inject text error, got %v", err)
	}

Because only part of the function was visible in the snippet, you should:

  1. Ensure there is no leftover body from the old TestScrcpyClient_executeInputAction_ErrorPaths_Coverage after this replacement (i.e., the function should close with the final } shown in the REPLACE block).
  2. Confirm the actual error string used in executeInputAction for the InjectText failure path. If it differs from "failed to inject text", update the substring in the final strings.Contains check to match the real message.
  3. Verify that mockConn is already defined in this test file with a failWrite field that triggers a write failure on the control socket, consistent with the existing InjectTap write-failure tests. If the field name or behavior differs, adjust &mockConn{failWrite: true} accordingly.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request focuses on improving test coverage by adding new test cases for error paths in the agent and scrcpy control logic. It also includes widespread whitespace and formatting cleanup across several test files. The feedback suggests refining test assertions in the new coverage tests to provide clearer failure messages by separating result count checks from content validation.

Comment thread internal/agent/agent_test.go Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

Tech Debt: Address Missing Test Coverage from Scrcpy Integration (PR #41)

3 participants