dsh-protect-tests: An Agent Editing Approach for Intercepting Test Weakening Before Application

Introduction

When you use DeepSeek Harness (DSH) to have an agent “make tests green”, sometimes it achieves the goal in ways you don’t want: adding .skip to failing cases, commenting out assertions, or changing expect(total).toBe(42) to expect(total).toBeDefined(). The test report turns green, but the bugs remain. Manually reviewing every diff is costly, and relying solely on prompts is unstable.

dsh-protect-tests is a community-maintained DSH plugin (categorized as admin-security) that compares old and new text before each edit to test files is applied; if the change makes tests “check less”, it rejects the edit and explains the reason to the model. Below is its positioning, capabilities, and installation/configuration methods.

What Is This

  • Name: dsh-protect-tests (GitHub: acus9345/dsh-protect-tests)
  • Maintainer: acus9345
  • License: MIT (according to the repository README)
  • One-liner: A DeepSeek Harness plugin that intercepts agent edits that weaken tests, such as .skip, deletion or dilution of assertions.

The plugin is mounted as a DSH Cordis patch and takes effect on test file edits matching the rules after installation; normal case additions/deletions, adding assertions, renaming, organizing setup, etc. are not affected.

Core Features

Interception Timing and Feedback

When editing test files, the plugin compares old and new text before applying the change. If determined to weaken tests, it rejects and returns an explanation, for example:

dsh-protect-tests blocked this change to src/sum.test.ts because it makes the tests check less:
- replaces specific assertions with existence/truthiness checks (0 → 1): `expect(sum(1, 2)).toBeDefined()`
Tests should keep failing until the code is fixed. Fix the implementation instead, or make
the test more accurate without weakening it. If the test itself is wrong (the requirement
changed, or it tested a bug), tell the user which test you are changing and why, then
repeat the identical call once to confirm.

The model should fix the implementation rather than weaken tests; if the test itself is wrong, it needs to explain to the user which test is being changed and why, then repeat the identical call to confirm. The second attempt can pass (allowIdenticalRetry defaults to true).

Detectable Patterns (according to README)

  1. New skip added: it.skip, test.only, xit, xdescribe, @pytest.mark.skip / xfail, @unittest.skip, t.Skip(), @Disabled, #[ignore], as well as equivalent forms in xUnit, RSpec, PHPUnit, XCTest, etc.
  2. Fewer tests or assertions: deletion of cases, or deletion of no fewer than threshold assertions in a single edit (defaults: minAssertionsRemoved: 2, minTestsRemoved: 1, configurable).
  3. Trivial assertions: such as expect(true).toBe(true), assert True, assertEquals(x, x), assert!(true).
  4. Commented-out assertions.
  5. Swallowed failures: empty catch {} or except AssertionError: pass wrapping assertions.
  6. Weakened assertions: specific assertions replaced with toBeDefined(), toBeTruthy(), assert.ok(x), is not None, etc.
  7. Deletion of test files: shell commands like rm, git rm, unlink on test files or directories; on Windows, PowerShell’s Remove-Item, del, rd are also monitored (guardDeletes).
  8. Infallible test scripts: modifying package.json’s "test" to echo, exit 0, ... || true, or adding --passWithNoTests (guardTestScript).

How Test Files Are Identified

By default, matching by filename and path, such as *.test.*, *.spec.*, *_test.*, test_*.py, *Test.java, conftest.py, as well as files in directories like tests/, __tests__/, spec/, e2e/. The list can be overridden via testFiles, with exclusion support (e.g., !tests/fixtures/**).

The README notes: refactors such as merging multiple approximate cases into test.each / @pytest.mark.parametrize / t.Run, or combining multiple toBe into toEqual({...}), while looking like “fewer” on paper, generally pass.

Deliberately Not Covered

The plugin is pattern-based rather than semantic. Changing toBe(4) to toBe(5) to match an incorrect implementation, or rewriting test logic so it no longer touches the defect, usually won’t be blocked. It mainly targets common lazy tricks and cannot replace human diff review.

Installation and Activation

DSH maintains plugin lists per profile; web corresponds to the browser UI of dsh web, headless is for scripts and CI, acp is for editor integration. Each profile you actually use needs separate installation.

Install under the web profile:

dsh plugin --profile web add dsh-protect-tests

It takes effect immediately after installation, no additional switch needed. To uninstall:

dsh plugin --profile web remove dsh-protect-tests

If you run DSH via headless or acp, replace --profile web with headless or acp.

Community plugin directory page: https://www.skillhub.cn/plugins/acus9345/dsh-protect-tests (independent site, no official affiliation with DeepSeek / Hiong). Repository: https://github.com/acus9345/dsh-protect-tests.

Configuration

You can click dsh-protect-tests in the DSH sidebar Plugins, modify and Save; it takes effect on the next tool call without restart.

Or add a fragment to ~/.dsh/profiles/<profile>/cordis.patch.yml (current profile only) or ~/.dsh/cordis.patch.yml (all profiles); unwritten keys remain default:

- id: protect-tests
  config:
    mode: deny                  # or ask: pop up approval
    testFiles: ['*.test.*', '**/tests/**', '!tests/fixtures/**']
    minAssertionsRemoved: 2
    minTestsRemoved: 1
    disabledSignals: []         # skip, fewer-assertions, fewer-tests, trivial-assert,
                                # commented-assert, swallowed-failure, weaker-assert
    guardDeletes: true
    guardTestScript: true
    allowIdenticalRetry: true   # when false, rejection is final
    shellTools: [bash, pwsh]   # on Windows, DSH uses pwsh

When mode: ask, weakening changes can go through approval instead of being rejected outright.

Use Cases and Notes

Suitable for: Teams or individuals using DSH to let agents fix code and run tests, wanting to block “skip / delete assertions / weaken assertions” reward hacking by default, while retaining a path to modify tests with second confirmation after explaining reasons.

Permissions and security: The plugin runs with the permissions of the current DSH process, can intercept edits and monitor shell tools configured for deletions of test paths. Read the repository source code and MIT license before installation to confirm it meets your security policy; do not blindly add third-party plugins to sensitive repositories without review.

Limitations: Cannot prevent semantic test degradation; critical changes still require manual review.

Conclusion

dsh-protect-tests adds a pattern-level guardrail on the test file edit chain: tests should keep failing until the implementation is fixed, rather than being silently turned green. Check the directory page when needed, or file issues on GitHub.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye