[camera_android_camerax] Add agentic guidance for adding native unit tests - #12369
[camera_android_camerax] Add agentic guidance for adding native unit tests#12369camsim99 wants to merge 7 commits into
Conversation
|
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. |
There was a problem hiding this comment.
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.
| # 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)" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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." |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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/`. |
There was a problem hiding this comment.
Do you want to add kotlin here?
| - **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/`. |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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.
Adds guidance for agents to ensure native unit tests are added when native Android code is modified by:
AGENTS.mdto explicitly note how to run native unit tests + that tests should be added if any of the Java files re touchedpre-pushskill to ensure native unit tests are added as expected + passpre-pushskill to ensure native unit tests not being added or failing causes the skill to fail. Results of running them: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
[shared_preferences]///).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-assistbot 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
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