You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by yx...@apache.org on 2026/08/30 02:49:05 UTC

(shardingsphere) branch master updated: Refine Codex unit testing rules (#39640)

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

yx9o 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 b7077ba957a Refine Codex unit testing rules (#39640)
b7077ba957a is described below

commit b7077ba957a8907241ef15700e676f45ec07ffb5
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Aug 30 10:48:59 2026 +0800

    Refine Codex unit testing rules (#39640)
---
 .codex/harness/agents/cases.toml                       |  2 +-
 .../code-implementation/references/rules/testing.md    | 18 ++++++++++++------
 .codex/skills/gen-ut/SKILL.md                          |  6 +++---
 3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/.codex/harness/agents/cases.toml b/.codex/harness/agents/cases.toml
index 1e3a0118d5f..aef5058a96e 100644
--- a/.codex/harness/agents/cases.toml
+++ b/.codex/harness/agents/cases.toml
@@ -1046,7 +1046,7 @@ allowed_actions = []
 forbidden_actions = ["edit_code", "add_meaningless_test", "mutate_git", "mutate_remote"]
 required_reasons = ["meaningful_test_required"]
 policy_binding_profile = "test-write"
-policy_assertions = [{source = "testing-rules", statements = ["Do not add tests that only prove pass-throughs, constants, accessors, delegation, wiring, Java, Lombok, Mockito, parsers, collection libraries, framework behavior, or private implementation shape.", "Never add a test solely to increase a coverage number or duplicate an existing scenario unless it covers a new branch, input class, edge case, contract, calculation path, or failure mode."]}]
+policy_assertions = [{source = "testing-rules", statements = ["Test a pass-through, constant, accessor, delegation, wiring path, or contract literal only when it expresses documented behavior owned by the production type or a public or externally visible contract that no broader behavior test protects.", "Never add a test solely to increase a coverage number or duplicate an existing scenario unless it covers a new branch, input class, edge case, contract, calculation path, or failure mode."]}]
 critical = true
 
 [[cases]]
diff --git a/.codex/skills/code-implementation/references/rules/testing.md b/.codex/skills/code-implementation/references/rules/testing.md
index 713241a7980..cf134189561 100644
--- a/.codex/skills/code-implementation/references/rules/testing.md
+++ b/.codex/skills/code-implementation/references/rules/testing.md
@@ -17,13 +17,19 @@
 
 # Testing Rules
 
-- Test behavior owned by the production class: computation, decisions, validation, transformation, state transitions, error handling, or external contracts. Each test must fail for a realistic regression that matters. Do not add tests that only prove pass-throughs, constants, accessors, delegation, wiring, Java, Lombok, Mockito, parsers, collection libraries, framework behavior, or private implementation shape. A documented public or externally visible contract may justify testing pass-t [...]
+- Test behavior owned by the production class: computation, decisions, validation, transformation, state transitions, error handling, or external contracts.
+- Each test must fail for a realistic regression that matters.
+- Do not add tests that only prove behavior owned by Java, Lombok, Mockito, a third-party parser, a collection library, a framework, or another collaborator, or that lock in private implementation shape.
+- Test a pass-through, constant, accessor, delegation, wiring path, or contract literal only when it expresses documented behavior owned by the production type or a public or externally visible contract that no broader behavior test protects.
+- Never add a test solely to increase a coverage number or duplicate an existing scenario unless it covers a new branch, input class, edge case, contract, calculation path, or failure mode.
 - Never add tests whose subject is another test case, a test class or method, test fixture, mock helper, test utility, or other test-only code. Test only the production behavior that the test-only code supports. Test-support code distributed as an independent artifact with an external contract is production code for this rule.
-- Do not test collaborator rules through the current class. Mock the nearest stable boundary and test the collaborator rule in its owner. Cross-layer behavior belongs in an explicitly scoped integration, contract, or E2E test.
-- Give each behavior-owning public production method focused coverage. Each test method covers one scenario and invokes the target public method at most once; repeat only when the same scenario requires additional assertions. Do not create interface-only tests; exercise concrete implementations.
-- Every new public production type requires direct focused tests, except exception types covered by `Exception Tests`. Broad workflow tests do not replace them unless they explicitly exercise that type's public behavior. If a pure pass-through public type has no meaningful owned or external contract to test, do not add the type merely for structural completeness.
-- When a coverage target is stated, list every branch or path before coding and map each one to exactly one planned test. Add cases until every declared branch is covered or explicitly waived, update the map when code changes, and verify with JaCoCo when coverage is uncertain. Document unreachable code instead of adding redundant tests.
+- Do not test a collaborator-owned rule through the current class. Isolate the collaborator result at the nearest stable boundary and test the rule in its owner. Mock external or heavy dependencies and collaborator-owned decisions; use real simple values when they are stable and do not introduce cross-layer behavior. Cross-layer behavior belongs in an explicitly scoped integration, contract, or E2E test.
+- Give each behavior-owning public production method focused coverage. Each test method covers one scenario and invokes the target public method once by default. Invoke it more than once only when repeated invocation is itself the behavior under test, such as idempotency, accumulation, or a state transition.
+- Test interface-owned `default` or `static` methods directly. Test abstract interface contracts through concrete implementations.
+- Every new public production type that owns behavior or a public or externally visible contract requires direct focused tests, except exception types covered by `Exception Tests`. Broad workflow tests do not replace them unless they explicitly exercise that type's public behavior or external contract.
+- When a coverage target is stated, list every branch or path before coding and map each required branch or path to at least one planned scenario. Each additional case must protect a distinct branch, input class, edge case, contract, calculation path, or failure mode; one scenario may protect multiple paths. Update the map when production code changes and verify the final target with JaCoCo. Obtain explicit user authorization before lowering the stated coverage target.
+- If coverage exposes unreachable production code, apply the artifact-removal and contract-impact gate before classifying it as removable. If the required production change is outside the frozen boundary, report the exact blocker and request that scope instead of adding a redundant test.
 
 ## Exception Tests
 
-- Do not add dedicated tests for exception classes that only declare constructors or format and forward their arguments to a tested superclass. Add direct tests only for owned validation, branching, calculation, conversion, or a known regression.
+- Do not add a dedicated test for an exception class when it only forwards arguments to a superclass, adds no externally observable contract or owned behavior, and the production error path already protects the forwarded contract. Add direct tests for an owned error code, category, message format, cause conversion, field, validation, branch, calculation, conversion, or known regression.
diff --git a/.codex/skills/gen-ut/SKILL.md b/.codex/skills/gen-ut/SKILL.md
index ec1acdfe422..b1cc7a8243d 100644
--- a/.codex/skills/gen-ut/SKILL.md
+++ b/.codex/skills/gen-ut/SKILL.md
@@ -61,14 +61,14 @@ Reading either Skill does not expand the user-authorized scope, file types, Git
 ### R4: Branch map
 
 - Before coding, enumerate target public-method branches and map each planned scenario to one branch or path.
-- Classify every trigger and assertion as SUT-owned or collaborator-owned. Mock the nearest stable boundary for collaborator results.
+- Classify every trigger and assertion as SUT-owned or collaborator-owned. Isolate collaborator-owned results at the nearest stable boundary and apply `R6` to decide whether to mock them.
 - Exclude Lombok-generated behavior without custom logic. Default to one test per branch or path; use `R13` for additional cases.
 
 ### R5: Scenario granularity
 
-- Keep one scenario per test and invoke the target public method at most once per scenario.
+- Keep one scenario per test and invoke the target public method once by default. Invoke it more than once only when repeated invocation is itself the scenario, such as idempotency, accumulation, or a state transition.
 - Keep the coverage-relevant invocation and its externally observable assertions in the test body. Helpers and providers must not execute target behavior.
-- For interface targets, test only `default` methods unless the user explicitly requests abstract methods.
+- For interface targets, test owned `default` or `static` methods directly. Exercise abstract contracts through concrete implementations, including when the user explicitly requests an interface-contract test.
 
 ### R6: SPI, mocks, and reflection