Skip to content

[camera_android_camerax] Add agentic guidance for adding native unit tests - #12369

Open
camsim99 wants to merge 7 commits into
flutter:mainfrom
camsim99:cos_nativetests
Open

[camera_android_camerax] Add agentic guidance for adding native unit tests#12369
camsim99 wants to merge 7 commits into
flutter:mainfrom
camsim99:cos_nativetests

Conversation

@camsim99

@camsim99 camsim99 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Adds guidance for agents to ensure native unit tests are added when native Android code is modified by:

  • Updating AGENTS.md to explicitly note how to run native unit tests + that tests should be added if any of the Java files re touched
  • Updating the pre-push skill to ensure native unit tests are added as expected + pass
  • Adds evals for the new guidance added to the pre-push skill to ensure native unit tests not being added or failing causes the skill to fail. Results of running them:
    • Eval 1 (Missing Native Test): PASSED – Detected that CameraProxyApi.java was modified without tests in android/src/test/ and blocked push readiness (# NO, you are not ready to push.).
    • Eval 2 (Success Native Test): PASSED – Ran both dart-test and native-test --no-integration, verified CameraTest.java covered CameraProxyApi.java, handled unrelated test environment exceptions per the rubric, and approved push readiness (# YES, you are ready to push!).
    • Eval 3 (Mixed Missing Native Test): PASSED – Detected that although Dart unit tests were updated for Dart changes, CameraProxyApi.java lacked a test update in android/src/test/, and blocked push readiness.
    • Eval 4 (Bypassed Mixed Missing Native Test): PASSED -- Explicitly identified that CameraProxyApi.java
      was modified without a native test update, but noted: "since you explicitly approved bypassing the native test requirement for this comment-only change, this check is marked as approved."

Follow up from one-shot attempt #12302. See go/flutter-project-one-shot for more information on the project.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 4, 2026
@flutter-dashboard

Copy link
Copy Markdown

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the pre-push skill documentation and agent guidelines to require and verify native Android unit tests alongside Dart unit tests, and adds evaluation scripts to test this behavior. The reviewer feedback suggests wrapping command substitutions in double quotes to handle paths with spaces, running repository-level tools from the repository root, and configuring temporary git author information in evaluation scripts to prevent commit failures in clean CI/CD environments.

Comment thread packages/camera/camera_android_camerax/.agents/skills/pre-push-skill/SKILL.md Outdated
Comment thread packages/camera/camera_android_camerax/AGENTS.md Outdated
@camsim99 camsim99 added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Aug 4, 2026
# Modifies a native Java file without updating a corresponding test file,
# and commits the change to test that pre-push-skill detects missing native tests.

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

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.

FWIW I think I used bash so shame on me and I will make this a non blocking nit. We should have this code be dart scripts instead of bash files for team readability.

# Commit so git status is clean and git diff against origin/main shows the Java change
cd "$PACKAGE_DIR" || exit 1
git add "$JAVA_FILE"
git -c user.name="Author" -c user.email="author@example.com" commit -m "eval: temporary commit with Java change and no test update"

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.

Is there a way to see if git can confirm it is in a tree and not on master. I can see agents running this eval in the wrong context and polluting the git history.

JAVA_FILE="$PACKAGE_DIR/android/src/main/java/io/flutter/plugins/camerax/CameraProxyApi.java"

# Add a harmless comment to CameraProxyApi.java
echo "// Eval comment" >> "$JAVA_FILE"

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.

a comment should not need a native test right?

"id": 1,
"prompt": "First, run 'bash .agents/skills/pre-push-skill/evals/test_data/setup_missing_native_test.sh'. Then, run the pre-push skill.",
"expected_chat_output": [
"The agent should detect that a native Java source file was modified without a corresponding native unit test being added or updated, and report that the code is not ready to push or ask for test coverage approval."

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.

This expectation reads like a summary of what should happen not an expectation about what information is shared with the user.

The reason I point this out is jetski ide + gemini 3.1 pro regularly made this mistake and you and I intentionally changed the structure to have expectations for output and state.

Please change this to a list of expectations

},
{
"id": 2,
"prompt": "First, run 'bash .agents/skills/pre-push-skill/evals/test_data/setup_success_native_test.sh'. Then, run the pre-push skill.",

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.

I dont know if it matters but lets use the syntax we would use in chat "run the /pre-push skill" not "run the pre-push skill"

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.

Meta comment these are expensive tests to run and I predict we will want to minimize the number of these and maximize the things being evaluated per eval. Similar to an integration test.

No changed needed for now but next time we are adding evals for a particular pre-push situation lets try to pick one of the three test_data/setup_* scripts to update.

TEST_FILE="$PACKAGE_DIR/android/src/test/java/io/flutter/plugins/camerax/CameraTest.java"

# Modify CameraProxyApi.java and CameraTest.java
echo "// Eval comment" >> "$JAVA_FILE"

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.

For the code cases I think adding a new java/dart file is probably an easier to maintain and safer change for the evals. That way if it accidentally gets added to git or runs in a place we dont expect it is easy to find. Also new functionality is more likely to require a test as models get better and start reasoning.

"evals": [
{
"id": 1,
"prompt": "First, run 'bash .agents/skills/pre-push-skill/evals/test_data/setup_missing_native_test.sh'. Then, run the pre-push skill.",

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.

I think you will need to add one more line that the agent should not attempt to fix any issues it fines only report the output of the skill.

and [dart-collect-coverage](.agents/skills/dart-collect-coverage/SKILL.md).
- Avoid duplicating constant strings; reuse existing ones from adjacent code.
- **Testing Guidelines**: You MUST read and follow all rules in [TESTING.md](TESTING.md) BEFORE writing or modifying any tests. This is CRITICAL for preventing CI flakiness.
- **Native Unit Tests**: When modifying `.java` files in `android/src/main/`, you MUST add or update corresponding native unit test files in `android/src/test/`.

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.

Do you want to add kotlin here?

Suggested change
- **Native Unit Tests**: When modifying `.java` files in `android/src/main/`, you MUST add or update corresponding native unit test files in `android/src/test/`.
- **Native Unit Tests**: When modifying `.java` files in `android/src/main/` with logic changes, you MUST add or update corresponding native unit test files in `android/src/test/`.

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.

Also I think you will want to exclude .g.kt files. for Pigeon

any new logic. For integration tests, see [flutter-add-integration-test](.agents/skills/flutter-add-integration-test/SKILL.md).
any new logic.
- **Dart Unit Tests**: See [dart-add-unit-test](.agents/skills/dart-add-unit-test/SKILL.md).
- **Native Unit Tests**: Run `cd "$(git rev-parse --show-toplevel)" && dart run script/tool/bin/flutter_plugin_tools.dart native-test --packages camera_android_camerax --no-integration`.

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.

Do you need to run cd "$(git rev-parse --show-toplevel)" Shouldn't the flutter_plugin_tools command work no matter the directory? If we need to find flutter_plugin_tools we can modify the bootstrapping skill that runs to make sure agents are ready to work by either installing the tool or adding an environment variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: camera

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants