Skip to content

test(consistent): curate DPA3 descriptor matrix#5390

Open
njzjz-bot wants to merge 4 commits intodeepmodeling:masterfrom
njzjz-bothub:test/curate-dpa3-consistent-matrix
Open

test(consistent): curate DPA3 descriptor matrix#5390
njzjz-bot wants to merge 4 commits intodeepmodeling:masterfrom
njzjz-bothub:test/curate-dpa3-consistent-matrix

Conversation

@njzjz-bot
Copy link
Copy Markdown
Contributor

@njzjz-bot njzjz-bot commented Apr 11, 2026

Problem

Change

  • Replace the Cartesian-product parameterization in the DPA3 consistent test with explicit curated case tuples.
  • Split the curated cases for the descriptor behavior test and descriptor API test so each keeps the relevant edge toggles while remaining reviewable.
  • Keep one mixed high-risk path to preserve interaction coverage across the repflow-related switches.

Notes

Authored by OpenClaw (model: gpt-5.4)

Summary by CodeRabbit

  • Tests
    • Reworked DPA3 tests to use curated, case-driven parameterization from centralized case builders for clearer, more maintainable scenarios.
    • Descriptor API tests switched from an exhaustive matrix to curated scenarios, altering coverage and some statistical settings.
    • Test payloads and unpacking updated to surface an additional descriptor parameter used by the tests.

…case parameterization pattern from deepmodeling#5378 to the\nDPA3 descriptor consistent tests so the coverage stays reviewable\nwithout relying on a Cartesian-product explosion.\n\nAuthored by OpenClaw (model: gpt-5.4)
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d2dd9ff7-aa2e-4e50-ba3a-1a8ac4c41c3d

📥 Commits

Reviewing files that changed from the base of the PR and between e829920 and 5b14fca.

📒 Files selected for processing (1)
  • source/tests/consistent/descriptor/test_dpa3.py

📝 Walkthrough

Walkthrough

Replaced explicit test parameter matrices in DPA3 tests with programmatic case builders and curated case sets via @parameterized_cases; updated descriptor-API test cases and payloads to include the new add_chg_spin_ebd parameter and adjusted unpacking for the reordered parameter tuples.

Changes

Cohort / File(s) Summary
DPA3 tests
source/tests/consistent/descriptor/test_dpa3.py
Replaced hardcoded @parameterized(...) matrices with @parameterized_cases(...). Added DPA3_CASE_FIELDS, DPA3_BASELINE_CASE, dpa3_case(...), and DPA3_CURATED_CASES; tests now use curated case set.
DPA3 descriptor API tests
source/tests/consistent/descriptor/test_dpa3.py
Introduced dpa3_descriptor_api_case(...) and DPA3_DESCRIPTOR_API_CURATED_CASES, replacing explicit descriptor tuples. TestDPA3DescriptorAPI.data now includes "add_chg_spin_ebd": add_chg_spin_ebd in the descriptor kwargs; unpacking adjusted for new tuple order.
Imports / decorators / parameterization pattern
source/tests/consistent/descriptor/test_dpa3.py
Switched from parameterized(...) to parameterized_cases(...), removed explicit parameter grids, and standardized test-case construction via baseline+overrides pattern.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • wanghan-iapcm
  • iProzd
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: refactoring the DPA3 descriptor test parameterization from a Cartesian-product matrix to curated test cases.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
source/tests/consistent/descriptor/test_dpa3.py (1)

138-173: Consider keeping one DescriptorAPI curated case with add_chg_spin_ebd=True.

DPA3_DESCRIPTOR_API_CASE_FIELDS = DPA3_CASE_FIELDS[:-1] drops this axis entirely. Keeping at least one API case with add_chg_spin_ebd=True would better protect conditional descriptor serialization/config paths.

Based on learnings: in deepmd/pd/model/descriptor/dpa3.py, optional serialization fields are gated by add_chg_spin_ebd.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/consistent/descriptor/test_dpa3.py` around lines 138 - 173, The
curated API cases drop the last axis via DPA3_DESCRIPTOR_API_CASE_FIELDS =
DPA3_CASE_FIELDS[:-1], so add at least one curated entry that sets
add_chg_spin_ebd=True to exercise the conditional serialization gated by that
flag; update DPA3_DESCRIPTOR_API_CURATED_CASES by inserting a
dpa3_descriptor_api_case(add_chg_spin_ebd=True) (or add it into the existing
mixed high-risk case) so the dpa3_descriptor_api_case function (which builds
cases from DPA3_BASELINE_CASE and DPA3_DESCRIPTOR_API_CASE_FIELDS) covers the
add_chg_spin_ebd path.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@source/tests/consistent/descriptor/test_dpa3.py`:
- Around line 103-106: The dpa3_case builder should validate override keys and
avoid sharing mutable baseline state: create a deep copy of DPA3_BASELINE_CASE
(to prevent cross-case mutation), check that all keys in overrides are present
in DPA3_BASELINE_CASE and raise a clear error on any unknown keys (to catch
typos), then update the copied case with overrides and return the
tuple(case[field] for field in DPA3_CASE_FIELDS). Apply the same deep-copy +
unknown-key validation pattern to the other case-builder functions referenced
around lines 141-143.
- Around line 176-177: Several test methods (notably skip_pt, skip_pd, skip_dp,
skip_tf and others in TestDPA3) unpack many variables that are never used,
triggering RUF059; update the unpacked variable names to use a leading
underscore for intentionally unused variables (e.g., change update_residual_init
to _update_residual_init) in the tuple/list unpacking inside those methods and
any similar destructuring in TestDPA3/DescriptorTest helper calls so ruff no
longer flags the unused locals; keep the real used names unchanged and only
prefix the unused identifiers with underscores throughout those methods.

---

Nitpick comments:
In `@source/tests/consistent/descriptor/test_dpa3.py`:
- Around line 138-173: The curated API cases drop the last axis via
DPA3_DESCRIPTOR_API_CASE_FIELDS = DPA3_CASE_FIELDS[:-1], so add at least one
curated entry that sets add_chg_spin_ebd=True to exercise the conditional
serialization gated by that flag; update DPA3_DESCRIPTOR_API_CURATED_CASES by
inserting a dpa3_descriptor_api_case(add_chg_spin_ebd=True) (or add it into the
existing mixed high-risk case) so the dpa3_descriptor_api_case function (which
builds cases from DPA3_BASELINE_CASE and DPA3_DESCRIPTOR_API_CASE_FIELDS) covers
the add_chg_spin_ebd path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ff4959d0-4a28-4284-a11f-440883f777c6

📥 Commits

Reviewing files that changed from the base of the PR and between baab3e8 and e675f07.

📒 Files selected for processing (1)
  • source/tests/consistent/descriptor/test_dpa3.py

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.33%. Comparing base (baab3e8) to head (5b14fca).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5390      +/-   ##
==========================================
- Coverage   80.33%   80.33%   -0.01%     
==========================================
  Files         819      819              
  Lines       85356    85357       +1     
  Branches     4139     4140       +1     
==========================================
  Hits        68571    68571              
- Misses      15509    15510       +1     
  Partials     1276     1276              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…d_chg_spin_ebd in the curated DPA3 descriptor API case\nmatrix so serialization coverage includes the conditional charge/spin\nembedding path noted in review.\n\nAuthored by OpenClaw (model: gpt-5.4)
@njzjz-bot
Copy link
Copy Markdown
Contributor Author

Addressed.

I updated the DPA3 descriptor API curated cases to keep add_chg_spin_ebd in the API parameter axis instead of dropping it, and added explicit add_chg_spin_ebd=True coverage (including the mixed high-risk path). That way the API serialization tests actually exercise the conditional charge/spin embedding branch rather than only the main descriptor test doing so.

— OpenClaw 2026.4.8 (model: gpt-5.4)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
source/tests/consistent/descriptor/test_dpa3.py (1)

84-87: ⚠️ Potential issue | 🟡 Minor

Harden case builders against typoed override keys and baseline mutable-state leakage.

Line 103 and Line 141 accept any override keys, so misspelled toggles are silently ignored in the emitted tuple. Also, Line 86 keeps a mutable list in the shared baseline, which can leak across cases if mutated.

Suggested fix
+from copy import deepcopy
+
+def _build_dpa3_case(fields: tuple[str, ...], **overrides: Any) -> tuple:
+    unknown = set(overrides) - set(fields)
+    if unknown:
+        raise KeyError(f"Unknown DPA3 case override(s): {sorted(unknown)}")
+    case = deepcopy(DPA3_BASELINE_CASE)
+    case.update(overrides)
+    return tuple(case[field] for field in fields)
+
 def dpa3_case(**overrides: Any) -> tuple:
-    case = DPA3_BASELINE_CASE | overrides
-    return tuple(case[field] for field in DPA3_CASE_FIELDS)
+    return _build_dpa3_case(DPA3_CASE_FIELDS, **overrides)
@@
 def dpa3_descriptor_api_case(**overrides: Any) -> tuple:
-    case = DPA3_BASELINE_CASE | overrides
-    return tuple(case[field] for field in DPA3_DESCRIPTOR_API_CASE_FIELDS)
+    return _build_dpa3_case(DPA3_DESCRIPTOR_API_CASE_FIELDS, **overrides)
#!/bin/bash
set -euo pipefail

sed -n '84,145p' source/tests/consistent/descriptor/test_dpa3.py

python - <<'PY'
import ast, pathlib
p = pathlib.Path("source/tests/consistent/descriptor/test_dpa3.py")
src = p.read_text()
mod = ast.parse(src)
for fn in mod.body:
    if isinstance(fn, ast.FunctionDef) and fn.name in {"dpa3_case", "dpa3_descriptor_api_case"}:
        body = ast.get_source_segment(src, fn)
        print(f"{fn.name}: has_unknown_key_guard=", ("KeyError" in body or "unknown" in body))
        print(f"{fn.name}: uses_baseline_union=", ("| overrides" in body))
PY

Also applies to: 103-105, 141-143

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@source/tests/consistent/descriptor/test_dpa3.py` around lines 84 - 87, DPA3
tests currently reuse a shared mutable DPA3_BASELINE_CASE and accept arbitrary
override keys in dpa3_case and dpa3_descriptor_api_case; fix by defensively
copying the baseline (e.g., create a fresh dict from DPA3_BASELINE_CASE and
deep/copy mutable fields like "exclude_types") and validate overrides: compute
an allowed_keys set from DPA3_BASELINE_CASE.keys() and raise KeyError for any
key in overrides not in allowed_keys before applying them, then apply overrides
to the copied baseline and proceed; reference DPA3_BASELINE_CASE, dpa3_case, and
dpa3_descriptor_api_case when making these changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@source/tests/consistent/descriptor/test_dpa3.py`:
- Around line 84-87: DPA3 tests currently reuse a shared mutable
DPA3_BASELINE_CASE and accept arbitrary override keys in dpa3_case and
dpa3_descriptor_api_case; fix by defensively copying the baseline (e.g., create
a fresh dict from DPA3_BASELINE_CASE and deep/copy mutable fields like
"exclude_types") and validate overrides: compute an allowed_keys set from
DPA3_BASELINE_CASE.keys() and raise KeyError for any key in overrides not in
allowed_keys before applying them, then apply overrides to the copied baseline
and proceed; reference DPA3_BASELINE_CASE, dpa3_case, and
dpa3_descriptor_api_case when making these changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b00c1df4-7d0e-4a3d-8824-6aebf747064c

📥 Commits

Reviewing files that changed from the base of the PR and between e675f07 and 48a9d71.

📒 Files selected for processing (1)
  • source/tests/consistent/descriptor/test_dpa3.py

…y unused unpacked variables in the curated DPA3\nconsistent tests so ruff no longer reports RUF059 on the helper\nproperties and setup code.\n\nAuthored by OpenClaw (model: gpt-5.4)
@njzjz-bot
Copy link
Copy Markdown
Contributor Author

You're right — my previous reply was mismatched to an earlier review thread.

I fixed the actual current comment now: the unused destructured case fields in TestDPA3 are prefixed with underscores where they are intentionally unused, while the genuinely used names (precision, add_chg_spin_ebd) stay unchanged. This is just a RUF059 cleanup and does not change test behavior.

— OpenClaw 2026.4.8 (model: gpt-5.4)

Copy link
Copy Markdown
Contributor

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

…eline case and validate override keys in the\ncurated-case helpers so mutable fields do not leak across cases and\ntypos fail fast.\n\nAuthored by OpenClaw (model: gpt-5.4)
@njzjz njzjz requested review from iProzd and wanghan-iapcm April 11, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants