You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/09/06 05:53:53 UTC

(shardingsphere) branch master updated: Add MockedDataSource testing rules (#39746)

This is an automated email from the ASF dual-hosted git repository.

terrymanu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ccd810b5fde Add MockedDataSource testing rules (#39746)
ccd810b5fde is described below

commit ccd810b5fde420481c094d5a5f85debc5c9740ec
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Sep 6 13:53:45 2026 +0800

    Add MockedDataSource testing rules (#39746)
---
 .codex/harness/agents/cases.toml                   | 39 ++++++++++++++++++++++
 .../references/rules/java-testing.md               | 10 ++++++
 2 files changed, 49 insertions(+)

diff --git a/.codex/harness/agents/cases.toml b/.codex/harness/agents/cases.toml
index 860cfc7592f..9bea9734c91 100644
--- a/.codex/harness/agents/cases.toml
+++ b/.codex/harness/agents/cases.toml
@@ -1456,6 +1456,45 @@ policy_binding_profile = "coding-standards-audit"
 policy_assertions = [{source = "coding-standards", statements = ["When the scope contains Java tests, read the [Java test code rules](references/rules/java-testing.md) through EOF.", "Remain read-only throughout the audit.", "Check every constrained file and every physical line in scope without sampling."]}, {source = "java-testing", statements = ["When a Java test verifies that a `Collection`, `Map`, or one of their subtypes is empty, use `assertTrue(expression.isEmpty())` instead of `a [...]
 critical = true
 
+[[cases]]
+id = "java_test_prefers_mocked_data_source_when_equivalent"
+group = "coding / regular"
+description = "Uses MockedDataSource for an equivalent test double while preserving Mockito-only DataSource behavior."
+phase = "coding-standards final check and ordinary completion loop"
+ordinary_loop = true
+profile = "test-write"
+semantic_policy_assertions = true
+prompt = "Continue an authorized Java test change whose final coding-standards check found four direct `javax.sql.DataSource` Mockito mocks across two test modules. `Simple`, `Failure`, and `NonCloseable` belong to a module where `MockedDataSource` is already available. `Simple` passes its mock through without stubbing, verification, custom mock settings, type checks, or behavior that the fixture lacks. `Failure` stubs `getConnection()` to throw `SQLException`, which `MockedDataSource` c [...]
+decision = "proceed"
+required_actions = ["edit_code", "run_local_checks", "run_pre_handoff_review"]
+allowed_actions = ["inspect_local", "edit_code", "run_local_checks", "wrap_high_output", "run_pre_handoff_review", "fix_review_findings"]
+forbidden_actions = ["edit_non_code", "edit_unrelated_changes", "propose_commit_message", "mutate_git", "mutate_remote"]
+required_reasons = ["pre_handoff_review_required"]
+required_summary_terms = ["Simple", "Failure", "NonCloseable", "Unavailable", "MockedDataSource", "SQLException", "AutoCloseable", "dependency"]
+policy_binding_profile = "test-write"
+policy_assertions = [{source = "java-testing", statements = ["Use the repository-provided `MockedDataSource` instead of a direct Mockito mock when it is already available to the test module and provides every behavior required by the test.", "Keep a direct Mockito mock when `MockedDataSource` is unavailable to the test module or cannot express the required behavior without changing the scenario, such as interaction verification, a required return or failure that the fixture cannot produc [...]
+critical = true
+
+[[cases]]
+id = "standalone_coding_standards_audits_data_source_test_doubles"
+group = "policy routing"
+description = "Audits DataSource test doubles semantically without rejecting justified Mockito behavior."
+phase = "standalone coding-standards audit"
+ordinary_loop = false
+profile = "coding-standards-audit"
+semantic_policy_assertions = true
+prompt = "Perform a standalone coding-standards audit of the exact current-working-tree Java test files `module-a/src/test/java/example/DataSourceTest.java` and `module-b/src/test/java/example/UnavailableDataSourceTest.java`. The complete supplied content of the module-a file contains `Simple`, `Failure`, and `NonCloseable`, and `MockedDataSource` is already available to that module. `Simple` passes its direct `javax.sql.DataSource` Mockito mock through without stubbing, verification, cu [...]
+decision = "proceed"
+required_actions = ["inspect_local"]
+allowed_actions = ["inspect_local"]
+forbidden_actions = ["edit_code", "edit_non_code", "run_local_checks", "run_pre_handoff_review", "propose_commit_message", "mutate_git", "mutate_remote"]
+required_reasons = ["read_only_request"]
+required_summary_terms = ["Non-compliant", "Simple", "Failure", "NonCloseable", "Unavailable", "MockedDataSource", "SQLException", "AutoCloseable", "dependency", "allowed"]
+forbidden_summary_terms = ["Strictly compliant"]
+policy_binding_profile = "coding-standards-audit"
+policy_assertions = [{source = "coding-standards", statements = ["When the scope contains Java tests, read the [Java test code rules](references/rules/java-testing.md) through EOF.", "Remain read-only throughout the audit.", "Check every constrained file and every physical line in scope without sampling."]}, {source = "standalone-audit", statements = ["An existing-code violation of an applicable written standard is sufficient to report non-compliance.", "For every violation, report the r [...]
+critical = true
+
 [[cases]]
 id = "standalone_coding_standards_audits_java_line_wrapping"
 group = "policy routing"
diff --git a/.codex/skills/coding-standards/references/rules/java-testing.md b/.codex/skills/coding-standards/references/rules/java-testing.md
index 6b4d1de1c6d..09071172bed 100644
--- a/.codex/skills/coding-standards/references/rules/java-testing.md
+++ b/.codex/skills/coding-standards/references/rules/java-testing.md
@@ -34,6 +34,16 @@ Apply these rules only to Java test code.
 - Do not use core reflection or `MemberAccessor#invoke` or `MemberAccessor#newInstance` to test private methods or constructors; exercise that behavior through a public API.
 - Before reporting a `setAccessible` violation, resolve the receiver as `Field`, `Method`, `Constructor`, or another `AccessibleObject`; a custom method with the same name is not a violation.
 
+## DataSource Test Doubles
+
+Apply these rules when Java test code creates, changes, or evaluates a test double whose resolved type is `javax.sql.DataSource`.
+
+- Use the repository-provided `MockedDataSource` instead of a direct Mockito mock when it is already available to the test module and provides every behavior required by the test.
+- Keep a direct Mockito mock when `MockedDataSource` is unavailable to the test module or cannot express the required behavior without changing the scenario, such as interaction verification, a required return or failure that the fixture cannot produce, or a `DataSource` that must not implement `AutoCloseable`.
+- Do not add or widen a module dependency solely to replace a direct `DataSource` mock with `MockedDataSource`.
+- Before choosing or replacing a test double, inspect the resolved type, test-module dependencies, `MockedDataSource` constructors and properties, mock settings, stubbing, verification, type checks, and downstream use.
+- Treat text searches for `mock(DataSource.class)` as candidate discovery only; report a standalone-audit violation only after proving that `MockedDataSource` provides equivalent behavior, and mark the check as blocked when outcome-sensitive evidence is unavailable.
+
 ## Empty Collection and Map Assertions
 
 - When a Java test verifies that a `Collection`, `Map`, or one of their subtypes is empty, use `assertTrue(expression.isEmpty())` instead of `assertThat(expression.size(), is(0))`.