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/05 15:35:04 UTC
(shardingsphere) branch master updated: Add Java test coding standards (#39740)
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 b827c17e725 Add Java test coding standards (#39740)
b827c17e725 is described below
commit b827c17e72513566c5e8294d690feaea58260623
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Sep 5 23:34:57 2026 +0800
Add Java test coding standards (#39740)
---
.codex/harness/agents/cases.toml | 88 +++++++++++++++++++++-
.codex/harness/agents/policy-sources.toml | 21 ++++--
.codex/skills/coding-standards/SKILL.md | 3 +
.../references/rules/java-testing.md | 42 +++++++++++
4 files changed, 145 insertions(+), 9 deletions(-)
diff --git a/.codex/harness/agents/cases.toml b/.codex/harness/agents/cases.toml
index cdd46d23931..b8421c275d7 100644
--- a/.codex/harness/agents/cases.toml
+++ b/.codex/harness/agents/cases.toml
@@ -1313,6 +1313,27 @@ policy_binding_profile = "code-write"
policy_assertions = [{source = "coding-standards", statements = ["For every affected Java file, read the [Java line-wrapping rules](references/rules/java-line-wrapping.md) through EOF and add each applicable rule to the checklist.", "For Java, explicitly verify every applicable Java line-wrapping rule against each declaration header, statement, and expression added or modified by the task."]}, {source = "java-line-wrapping", statements = ["Keep the reconstructed form on one physical line [...]
critical = true
+[[cases]]
+id = "java_test_code_uses_actual_and_member_accessor"
+group = "coding / regular"
+description = "Uses actual-value naming and Mockito member access without adding an unnecessary local variable."
+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 `Object result = service.execute(); assertThat(result, is(expected));`, a direct `assertThat(service.status(), is(expectedStatus));`, and `field.setAccessible(true); field.set(target, value);`. Rename the asserted local and all its references, keep the direct assertion without introducing a local variable, replace the reflective field write with the repository member accessor, state all decisions i [...]
+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 = ["actual", "Plugins.getMemberAccessor"]
+required_summary_term_groups = [["direct assertion", "direct status assertion", "without introducing a local", "without adding a local", "Keep `assertThat(service.status()", "Keep assertThat(service.status()"]]
+forbidden_summary_terms = ["MemberAccessor#newInstance", "MemberAccessor#invoke"]
+policy_binding_profile = "test-write"
+policy_assertions = [{source = "coding-standards", statements = ["For every affected Java test file, read the [Java test code rules](references/rules/java-testing.md) through EOF and add each applicable rule to the checklist.", "For Java tests, explicitly verify every applicable Java test code rule against the effective task delta and the declarations and member types needed to resolve semantic applicability."]}, {source = "java-testing", statements = ["Name a local variable that stores [...]
+critical = true
+
[[cases]]
id = "standalone_coding_standards_audits_named_constant_order"
group = "policy routing"
@@ -1334,6 +1355,69 @@ policy_binding_profile = "coding-standards-audit"
policy_assertions = [{source = "coding-standards", statements = ["When the scope contains Java, read the [Java expression rules](references/rules/java-expressions.md) through EOF.", "Remain read-only throughout the audit."]}, {source = "java-expressions", statements = ["Place a resolved named constant on the left and a variable or other non-constant expression on the right when they are operands of `==` or `!=`.", "Do not classify an identifier as a constant from uppercase spelling alone [...]
critical = true
+[[cases]]
+id = "standalone_coding_standards_audits_java_test_code"
+group = "policy routing"
+description = "Audits actual-value naming and reflective test access without editing the current working tree."
+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 file `module-a/src/test/java/example/FooTest.java`. Its complete supplied content contains `Object result = service.execute(); assertThat(result, is(expected));`, a reflective field write through `field.setAccessible(true); field.set(target, value);`, and a private constructor invocation through `Plugins.getMemberAccessor().newInstance(constructor)`. Check the complete file, conclude `Non-co [...]
+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", "actual", "Plugins.getMemberAccessor", "public API"]
+required_summary_term_groups = [["field", "Field"], ["constructor", "newInstance"]]
+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 = "java-testing", statements = ["Do not name that local variable `result` when it supplies the actual value to an assertion.", "Do not call `AccessibleObject#setAccessible` i [...]
+critical = true
+
+[[cases]]
+id = "java_test_empty_assertion_requires_collection_or_map"
+group = "coding / regular"
+description = "Rewrites an empty Collection assertion without treating every size method as a Collection or Map contract."
+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 `List<String> actualItems = service.load(); assertThat(actualItems.size(), is(0));` and `PreparedStatementCacheContext cacheContext = createCacheContext(); assertThat(cacheContext.size(), is(0));`. The supplied declarations prove that `actualItems` is a `java.util.List` and that `PreparedStatementCacheContext` is a project type that does not implement `Collection` or `Map`. Correct only the applica [...]
+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 = ["assertTrue", "isEmpty", "PreparedStatementCacheContext"]
+required_summary_term_groups = [["outside", "not a Collection", "not a Map", "unchanged", "neither `Collection`", "does not trigger"]]
+forbidden_summary_terms = ["add isEmpty", "implement Collection", "implement Map"]
+policy_binding_profile = "test-write"
+policy_assertions = [{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 `assertThat(expression.size(), is(0))`.", "Resolve the receiver's declared type or the invoked method's return contract before applying this rule; the presence of a `size()` method alone does not prove that the receiver is a `Collection` or `Map`.", "Do not report or rewrite an assertion on [...]
+critical = true
+
+[[cases]]
+id = "standalone_coding_standards_audits_empty_collection_assertions_semantically"
+group = "policy routing"
+description = "Audits empty assertions only when the receiver is proved to be a Collection or Map."
+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 file `module-a/src/test/java/example/FooTest.java`. Its complete supplied content declares `List<String> actualItems`, declares a project type `PreparedStatementCacheContext` that does not implement `Collection` or `Map`, and asserts `assertThat(actualItems.size(), is(0));` and `assertThat(cacheContext.size(), is(0));`. Conclude `Non-compliant`, report only the List assertion under the empty [...]
+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", "actualItems", "assertTrue", "isEmpty", "PreparedStatementCacheContext"]
+required_summary_term_groups = [["not a Collection", "not a Map", "outside", "neither Collection", "neither `Collection`"]]
+forbidden_summary_terms = ["Strictly compliant", "add isEmpty", "implement Collection", "implement Map"]
+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 = "standalone_coding_standards_audits_java_line_wrapping"
group = "policy routing"
@@ -1369,8 +1453,8 @@ 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", "null", "Collections.unmodifiableList"]
-required_summary_term_groups = [["remove", "minimum correction", "pass, store, or return the original collection"]]
+required_summary_terms = ["Non-compliant", "null"]
+required_summary_term_groups = [["remove", "minimum correction", "pass, store, or return the original collection"], ["Collections.unmodifiableList", "unmodifiable wrapper"]]
forbidden_summary_terms = ["Strictly compliant"]
policy_binding_profile = "coding-standards-audit"
policy_assertions = [{source = "standalone-audit", statements = ["For defensive-code rules, inspect the relevant contracts, producers, consumers, callers, aliases, failures, concurrency, and lifecycle paths. Do not infer that an existing defense is unnecessary merely because a text search did not find its justification.", "An existing-code violation of an applicable written standard is sufficient to report non-compliance.", "For every defensive-code violation, also report the production [...]
diff --git a/.codex/harness/agents/policy-sources.toml b/.codex/harness/agents/policy-sources.toml
index a9068292f31..51c39fa9de2 100644
--- a/.codex/harness/agents/policy-sources.toml
+++ b/.codex/harness/agents/policy-sources.toml
@@ -18,16 +18,16 @@ root_max_bytes = 26000
[profiles]
root = ["agents"]
-code-write = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "change-completion"]
-test-write = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "change-completion"]
-code-review = ["agents", "code-of-conduct", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification"]
+code-write = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "change-completion"]
+test-write = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "change-completion"]
+code-review = ["agents", "code-of-conduct", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification"]
code-design = ["agents", "implementation-rules", "testing-rules", "contracts-and-removal", "cross-cutting-skills"]
-coding-standards-audit = ["agents", "code-of-conduct", "coding-standards", "standalone-audit", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code"]
+coding-standards-audit = ["agents", "code-of-conduct", "coding-standards", "standalone-audit", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code"]
runtime-diagnosis = ["agents", "runtime-triage", "code-verification"]
command-execution = ["agents", "token-efficiency", "code-verification"]
cross-cutting = ["agents", "cross-cutting-skills"]
-gen-ut = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "gen-ut", "gen-ut-verification", "change-completion"]
-review-pr = ["agents", "code-of-conduct", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "review-pr", "review-pr-evidence", "review-pr-high-risk", "review-pr-sql-parser", "review-pr-corrections"]
+gen-ut = ["agents", "code-of-conduct", "code-implementation", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "gen-ut", "gen-ut-verification", "change-completion"]
+review-pr = ["agents", "code-of-conduct", "coding-standards", "java-naming", "java-expressions", "java-line-wrapping", "java-testing", "defensive-code", "implementation-rules", "testing-rules", "contracts-and-removal", "non-regression", "code-verification", "review-pr", "review-pr-evidence", "review-pr-high-risk", "review-pr-sql-parser", "review-pr-corrections"]
policy-maintenance = ["agents", "policy-maintenance", "policy-source-manifest"]
[[sources]]
@@ -126,7 +126,7 @@ id = "coding-standards"
path = ".codex/skills/coding-standards/SKILL.md"
kind = "skill"
semantic = true
-references = ["AGENTS.md", "CODE_OF_CONDUCT.md", ".codex/skills/coding-standards/references/standalone-audit.md", ".codex/skills/coding-standards/references/rules/java-naming.md", ".codex/skills/coding-standards/references/rules/java-expressions.md", ".codex/skills/coding-standards/references/rules/java-line-wrapping.md", ".codex/skills/coding-standards/references/rules/defensive-code.md"]
+references = ["AGENTS.md", "CODE_OF_CONDUCT.md", ".codex/skills/coding-standards/references/standalone-audit.md", ".codex/skills/coding-standards/references/rules/java-naming.md", ".codex/skills/coding-standards/references/rules/java-expressions.md", ".codex/skills/coding-standards/references/rules/java-line-wrapping.md", ".codex/skills/coding-standards/references/rules/java-testing.md", ".codex/skills/coding-standards/references/rules/defensive-code.md"]
[[sources]]
id = "coding-standards-metadata"
@@ -163,6 +163,13 @@ kind = "rules"
semantic = true
references = []
+[[sources]]
+id = "java-testing"
+path = ".codex/skills/coding-standards/references/rules/java-testing.md"
+kind = "rules"
+semantic = true
+references = ["CODE_OF_CONDUCT.md", ".codex/skills/coding-standards/references/rules/java-naming.md"]
+
[[sources]]
id = "defensive-code"
path = ".codex/skills/coding-standards/references/rules/defensive-code.md"
diff --git a/.codex/skills/coding-standards/SKILL.md b/.codex/skills/coding-standards/SKILL.md
index 44ee12e6489..bf461d1d878 100644
--- a/.codex/skills/coding-standards/SKILL.md
+++ b/.codex/skills/coding-standards/SKILL.md
@@ -39,6 +39,7 @@ Use this mode when implementing, fixing, refactoring, or reviewing code unless t
- For every affected Java file, read the [Java naming and Lombok rules](references/rules/java-naming.md) through EOF and add each applicable rule to the checklist.
- For every affected Java file, read the [Java expression rules](references/rules/java-expressions.md) through EOF and add each applicable rule to the checklist.
- For every affected Java file, read the [Java line-wrapping rules](references/rules/java-line-wrapping.md) through EOF and add each applicable rule to the checklist.
+- For every affected Java test file, read the [Java test code rules](references/rules/java-testing.md) through EOF and add each applicable rule to the checklist.
- For every affected implementation artifact, read the [defensive-code rules](references/rules/defensive-code.md) through EOF and add each applicable rule to the checklist.
- Determine whether each rule governs all existing code or only code that is new, modified, touched, submitted, or generated by Codex.
- Apply every applicable rule to each modified file within the task's authorized scope.
@@ -47,6 +48,7 @@ Use this mode when implementing, fixing, refactoring, or reviewing code unless t
- For Java, explicitly verify every applicable Java naming and Lombok rule against the effective task delta and the surrounding declarations needed to resolve semantic applicability.
- For Java, explicitly verify every applicable Java expression rule against the effective task delta and the declarations needed to resolve named constants.
- For Java, explicitly verify every applicable Java line-wrapping rule against each declaration header, statement, and expression added or modified by the task.
+- For Java tests, explicitly verify every applicable Java test code rule against the effective task delta and the declarations and member types needed to resolve semantic applicability.
- Explicitly verify every applicable defensive-code rule against the effective task delta and the contracts, producers, consumers, and supported paths needed to determine whether each defensive construct has qualifying evidence.
- Treat passing Checkstyle and Spotless as evidence only for the rules those tools enforce; neither result replaces the manual recheck.
- A later write invalidates final-check evidence only for affected files and rules; recheck those portions before verification or handoff.
@@ -69,6 +71,7 @@ Use this mode only when the user explicitly asks to audit, check, or report codi
- When the scope contains Java, read the [Java naming and Lombok rules](references/rules/java-naming.md) through EOF.
- When the scope contains Java, read the [Java expression rules](references/rules/java-expressions.md) through EOF.
- When the scope contains Java, read the [Java line-wrapping rules](references/rules/java-line-wrapping.md) through EOF.
+- When the scope contains Java tests, read the [Java test code rules](references/rules/java-testing.md) through EOF.
- When the scope contains implementation artifacts, read the [defensive-code rules](references/rules/defensive-code.md) through EOF.
- Before auditing, run `scripts/build_audit_inventory.py` with the repository root and every user-specified repository-relative scope.
- Check every constrained file and every physical line in scope without sampling.
diff --git a/.codex/skills/coding-standards/references/rules/java-testing.md b/.codex/skills/coding-standards/references/rules/java-testing.md
new file mode 100644
index 00000000000..6b4d1de1c6d
--- /dev/null
+++ b/.codex/skills/coding-standards/references/rules/java-testing.md
@@ -0,0 +1,42 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+# Java Test Code Rules
+
+Apply these rules only to Java test code.
+
+## Actual-Value Naming
+
+- Name a local variable that stores the value produced by the operation under test with the `actual` prefix; use `actual` when no additional domain distinction is needed.
+- Do not name that local variable `result` when it supplies the actual value to an assertion.
+- When correcting the name, rename the declaration and every reference to the same variable.
+- Keep a direct assertion when the tested expression is clear; do not introduce an `actual` local whose only purpose is to satisfy the naming rule.
+- The returned-value rules in `java-naming.md` continue to govern a test helper's own return flow; the actual-value rule overrides them only for a local value asserted as the result of the operation under test.
+
+## Reflective Field Access
+
+- Do not call `AccessibleObject#setAccessible` in Java test code.
+- When the `CODE_OF_CONDUCT.md` field-access exception applies, use `Plugins.getMemberAccessor().get` or `Plugins.getMemberAccessor().set` instead of changing a `Field` object's accessibility and calling `Field#get` or `Field#set` directly.
+- 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.
+
+## 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))`.
+- When the original assertion supplies a failure reason, preserve it as the second argument to `assertTrue`.
+- Resolve the receiver's declared type or the invoked method's return contract before applying this rule; the presence of a `size()` method alone does not prove that the receiver is a `Collection` or `Map`.
+- Do not report or rewrite an assertion on another type merely because that type provides `size()`; when the receiver type cannot be proved, do not report a confirmed violation.