Skip to content

docs: add testing policy for agent PRs - #11455

Open
mantoujun12 wants to merge 2 commits into
AstrBotDevs:masterfrom
mantoujun12:docs/testing-policy
Open

mantoujun12 wants to merge 2 commits into
AstrBotDevs:masterfrom
mantoujun12:docs/testing-policy

Conversation

@mantoujun12

@mantoujun12 mantoujun12 commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #11446 for part 1

Add a Testing Policy section to AGENTS.md and replace the soft "do not generate test files for now" wording in .github/copilot-instructions.md with the same rules, so every coding agent reads one consistent policy instead of contradictory signals; the closing "Always test thoroughly" reminder is reworded to verify against existing behavior.

The policy: default to no new tests; verify with throwaway local tests that are never committed, pasting evidence in the PR instead; bug fixes carry at most one fast, deterministic regression test; features allow up to three behavioral tests justified in the PR description; refactors add none, since the existing suite passing is the proof. Exhaustive enumeration, mock-heavy implementation-detail tests, and tests requiring real API keys or a full app boot are banned from regular PRs (unavoidable ones go to tests/integration/ with @pytest.mark.slow).

CI runs the full unit suite on every PR, so every new test taxes all future PRs — this curbs unsolicited low-value test bloat while keeping a legitimate verification path.

Modifications / 改动点

AGENTS.md

新增 ## Testing Policy 小节(位于 Pre-commit setup 之后):

  • 默认:不为 PR 新增测试,除非任务明确要求;tests/ 下不新建或修改文件。
  • 本地验证通道:可用一次性临时测试自证改动——跑完即删、输出贴进 PR,不提交进 diff。
  • bug 修复:至多 1 个快速、确定性的回归测试(不打网络、不 sleep、不启动完整应用);启动、仪表盘、平台类 bug 改用 uv run scripts/smoke_startup_check.py 加手工步骤验证。
  • 新功能:至多 3 个行为级测试,只测用户可见行为、不测实现细节,需在 PR 描述中说明理由。
  • 重构:不新增测试,既有序列通过即证明。
  • 禁止提交:穷举枚举、mock 堆断言实现细节、琐碎代码测试、依赖真实 API 或完整启动的测试(确需时放 tests/integration/ 并标记 @pytest.mark.slow)。
  • 既有测试:不得弱化断言让改动通过,修改动本身;随行为变更同步更新测试允许,需在 PR 中说明。
  • 必做:运行改动涉及的现有测试并把结果贴进 PR。

.github/copilot-instructions.md

  • ### Testing 段由单句软禁令「Do not generate test files for now.」替换为与 AGENTS.md 同文的政策细则,消除「一处软禁、一处无文」的矛盾,使各主流 coding agent 与 Copilot 读到同一套规则。

  • 结尾提醒句由「Always test thoroughly…」改为「Always verify changes against existing behavior instead of adding new tests」,去掉推动写新测试的暗示。

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

验证步骤

合并后,给你的 Agent 派一个任务,观察它有没有写多余且没用的测试,并且即使写测试且推送线上也应该按照规则。

写了测试之后,sourcery-ai 应该不会再发表关于在 .github/copilot-instructions.md 中的 Do not generate test files for now. 规则评论。


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Establish a consistent, low-bloat testing policy for repository contributors and coding agents.

Enhancements:

  • Add a repository-wide testing policy that standardizes when tests should be added, how changes should be verified, and which test patterns are discouraged or prohibited.
  • Align Copilot instructions with the repository testing policy and emphasize validating changes against existing behavior rather than adding unnecessary tests.

Documentation:

  • Document the testing policy in AGENTS.md and .github/copilot-instructions.md for consistent guidance across coding agents.

Add a Testing Policy section to AGENTS.md and replace the soft "do not generate test files for now" wording in .github/copilot-instructions.md with the same rules, so every coding agent reads one consistent policy instead of contradictory signals; the closing "Always test thoroughly" reminder is reworded to verify against existing behavior.

The policy: default to no new tests; verify with throwaway local tests that are never committed, pasting evidence in the PR instead; bug fixes carry at most one fast, deterministic regression test; features allow up to three behavioral tests justified in the PR description; refactors add none, since the existing suite passing is the proof. Exhaustive enumeration, mock-heavy implementation-detail tests, and tests requiring real API keys or a full app boot are banned from regular PRs (unavoidable ones go to tests/integration/ with @pytest.mark.slow).

CI runs the full unit suite on every PR, so every new test taxes all future PRs — this curbs unsolicited low-value test bloat while keeping a legitimate verification path.
@mantoujun12 mantoujun12 self-assigned this Nov 28, 2026
@mantoujun12 mantoujun12 added the documentation Improvements or additions to documentation label Nov 28, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 5 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".github/copilot-instructions.md" line_range="33" />
<code_context>
+- **Bug fix: at most one fast, deterministic regression test** (no network, no sleeps, no full app boot). Startup / dashboard / platform bugs: `uv run scripts/smoke_startup_check.py` + manual steps in the PR.
+- **Feature: at most three behavioral tests** asserting the new user-visible behavior (not implementation details), justified in the PR description.
+- **Refactor: no new tests** — behavior is unchanged; the existing suite passing is the proof.
+- **Never commit**: exhaustive enumeration; mock-heavy tests asserting implementation details; tests for trivial code; tests needing real API keys or the running app (if truly unavoidable: `tests/integration/` with `@pytest.mark.slow`).
+- **Never weaken an existing test** to make your change pass — fix the change. Updating tests for an intentional behavior change is fine; say so in the PR.
+- **Always run** the existing tests your change touches and paste the results in the PR.
</code_context>
<issue_to_address>
**Slow integration tests run in CI**

When a contributor adds a test under the documented integration/slow exception, `tests.yml` runs `scripts/run_pytests_ci.sh ./tests` with the default `all` profile, so collection keeps `tests/integration/` tests despite `@pytest.mark.slow`; those tests run on every PR and fail when required credentials or the app are unavailable.

Exclude integration/slow tests from the regular PR run or revise the documented exception to match what CI actually skips.
</issue_to_address>

### Comment 2
<location path=".github/copilot-instructions.md" line_range="30" />
<code_context>
+- Unjustified test diffs get deleted in review.
+- **Default: no new tests** — nothing under `tests/` unless the task explicitly asks for tests.
+- **Scratch verification is fine; committing it is NOT**: write a throwaway test, run it, delete it, paste the output in the PR.
+- **Bug fix: at most one fast, deterministic regression test** (no network, no sleeps, no full app boot). Startup / dashboard / platform bugs: `uv run scripts/smoke_startup_check.py` + manual steps in the PR.
+- **Feature: at most three behavioral tests** asserting the new user-visible behavior (not implementation details), justified in the PR description.
+- **Refactor: no new tests** — behavior is unchanged; the existing suite passing is the proof.
</code_context>
<issue_to_address>
**Startup smoke check can pass falsely**

When port 6185 is already serving an HTTP response while the launched application cannot bind or start, `smoke_startup_check.py` treats any successful response from port 6185 as readiness before checking whether the child process started, so an existing service can make the recommended verification report success even when the changed application fails to start.

Have the smoke check use a free or configurable port and verify the launched process is the one serving the health endpoint before reporting success.
</issue_to_address>

### Comment 3
<location path=".github/copilot-instructions.md" line_range="29" />
<code_context>
-- Do not generate test files for now.
+- Unjustified test diffs get deleted in review.
+- **Default: no new tests** — nothing under `tests/` unless the task explicitly asks for tests.
+- **Scratch verification is fine; committing it is NOT**: write a throwaway test, run it, delete it, paste the output in the PR.
+- **Bug fix: at most one fast, deterministic regression test** (no network, no sleeps, no full app boot). Startup / dashboard / platform bugs: `uv run scripts/smoke_startup_check.py` + manual steps in the PR.
+- **Feature: at most three behavioral tests** asserting the new user-visible behavior (not implementation details), justified in the PR description.
</code_context>
<issue_to_address>
**Testing ban is relaxed**

When agents follow the updated testing guidance, the instructions permit scratch test files and committed tests for bug fixes, features, and unavoidable integration cases. Agents following them can generate test files despite the repository rule, leaving conflicting guidance.

Keep the testing guidance consistent with the no-test-files rule, or update that repository rule to explicitly allow these exceptions.

Also at `.github/copilot-instructions.md:30-31`, `.github/copilot-instructions.md:33`.
</issue_to_address>

### Comment 4
<location path=".github/copilot-instructions.md" line_range="28" />
<code_context>
 ### Testing
-- Do not generate test files for now.
+- Unjustified test diffs get deleted in review.
+- **Default: no new tests** — nothing under `tests/` unless the task explicitly asks for tests.
+- **Scratch verification is fine; committing it is NOT**: write a throwaway test, run it, delete it, paste the output in the PR.
+- **Bug fix: at most one fast, deterministic regression test** (no network, no sleeps, no full app boot). Startup / dashboard / platform bugs: `uv run scripts/smoke_startup_check.py` + manual steps in the PR.
</code_context>
<issue_to_address>
**Allowed test updates are blocked**

When a task intentionally changes behavior but does not explicitly ask for tests, agents following the default instruction are told not to change anything under `tests/`, while the later instruction permits updating tests for intentional behavior changes. They receive conflicting guidance and can leave stale tests that fail CI.

Clarify that the default restriction applies to adding new tests, while updating existing tests for intentional behavior changes is permitted.

Also at `.github/copilot-instructions.md:34`.
</issue_to_address>

### Comment 5
<location path=".github/copilot-instructions.md" line_range="28" />
<code_context>
 ### Testing
-- Do not generate test files for now.
+- Unjustified test diffs get deleted in review.
+- **Default: no new tests** — nothing under `tests/` unless the task explicitly asks for tests.
+- **Scratch verification is fine; committing it is NOT**: write a throwaway test, run it, delete it, paste the output in the PR.
+- **Bug fix: at most one fast, deterministic regression test** (no network, no sleeps, no full app boot). Startup / dashboard / platform bugs: `uv run scripts/smoke_startup_check.py` + manual steps in the PR.
</code_context>
<issue_to_address>
**Non-Copilot agents miss policy**

When a coding agent relies on `AGENTS.md` rather than `.github/copilot-instructions.md`, a coding agent that follows `AGENTS.md` but not Copilot-specific instructions never receives these rules, so the promised consistent testing guidance is not delivered to that agent.

Ensure the testing policy is included in the committed `AGENTS.md` (force-add it or adjust the ignore rule) and include that change in the PR.
</issue_to_address>

Sourcery assessment

Approval pending. 5 findings to address first.

Blocking findings: .github/copilot-instructions.md:33, .github/copilot-instructions.md:30, .github/copilot-instructions.md:29, .github/copilot-instructions.md:28, .github/copilot-instructions.md:28


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .github/copilot-instructions.md Resolved
Comment thread .github/copilot-instructions.md Resolved
Comment thread .github/copilot-instructions.md Resolved
Comment thread .github/copilot-instructions.md Resolved
Comment thread .github/copilot-instructions.md Resolved
Updating existing tests for intentional behavior changes stays governed by the later carve-out, resolving the wording contradiction flagged in review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant