Skip to content

docs: add test discipline rules to agent guidelines - #8372

Merged
pengdurice merged 5 commits into
masterfrom
docs/agents-test-discipline
Sep 3, 2026
Merged

pengdurice merged 5 commits into
masterfrom
docs/agents-test-discipline

Conversation

@delock

@delock delock commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Motivation

AI coding agents increasingly submit tests alongside features, and a recurring failure mode of such contributions is tests coupled to the implementation rather than the contract:

  • asserting private method return values or exact internal strings,
  • re-implementing the logic under test as the test's own reference,
  • mocks that stand in for internals instead of a documented collaborator contract.

Such tests pass trivially, break on harmless refactors (or worse, survive bugs they should catch), and give false coverage confidence.

What this PR adds

A ### Test discipline section to the agent guidelines (AGENTS.md + CLAUDE.md, kept in sync as the file header requires) with operational rules:

  1. A test is well-formed only if a different correct implementation of the same contract passes it.
  2. Name the concrete incorrect behavior a test would catch before writing it; if none can be named, do not write it.
  3. Assert observable outcomes through public/stable interfaces; white-box pinning only for specific fixed bugs, justified in a comment.
  4. Anchor to an external oracle or an independently derived reference instead of re-implementing the logic under test.
  5. Mocks must stand in for a collaborator's documented contract (schema, protocol), never for internals of the module under test.

The rules are deliberately example-free to keep the guide lean.

AI coding agents increasingly contribute tests alongside features. A
common failure mode is tests coupled to the implementation under test
(assertions on private internals, mirror-image references, mocks of
internals) that pass trivially and give false coverage confidence.
Codify contract-testing rules so agent-authored tests verify behavior
through stable interfaces instead.

CLAUDE.md kept in sync with AGENTS.md as required by the file header.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0b2d1163c3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread AGENTS.md
- Comments should explain **why**, not **what**. Describe the purpose and reasoning, not the mechanics that the code already shows.
- New features must include corresponding tests and documentation updates.

### Test discipline

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required sign-off trailer

This is a non-merge commit, but its commit message contains no Signed-off-by trailer. Add the author sign-off so the commit satisfies the repository's mandatory contribution requirement.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

@pengdurice

Copy link
Copy Markdown
Contributor

Thank you for adding this! Do we want to add something like: if the change is substantially large, add integration test? i.e. if we make changes on optimizer, instead of just unit test the optimizer, we should add a minimal training loop with a SimpleModel like training-framework-benchmarking-v5/third_party/DeepSpeed/tests/unit/checkpoint/test_universal_checkpoint.py

@delock

delock commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you for adding this! Do we want to add something like: if the change is substantially large, add integration test? i.e. if we make changes on optimizer, instead of just unit test the optimizer, we should add a minimal training loop with a SimpleModel like training-framework-benchmarking-v5/third_party/DeepSpeed/tests/unit/checkpoint/test_universal_checkpoint.py

Hi @pengdurice , add integration test is a good idea. Let me add it. Thanks!

… changes

Address review feedback: a contract change observable only at the
training-loop or inference level (e.g. optimizer behavior) needs an
integration test, not just unit tests. CLAUDE.md kept in sync with
AGENTS.md as required by the file header.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>
@delock

delock commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Hi @pengdurice , I added a line for integration test and tried to clearly define substaintial change. Can you take a look? Thanks!

Make the trigger an affirmative, external check (does the change affect
the external contract at the training-loop or inference level?) instead
of a negative one (observable only at that level), with no size or
complexity vocabulary. CLAUDE.md kept in sync with AGENTS.md.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>

@pengdurice pengdurice 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.

one last question, does the agent read the PR description? I think so? do we need to add requests of adding verification on at least some hardware when the change is substantial?

Address review feedback: executing the integration test and reporting
the hardware spec and results in the PR is what makes it evidence,
so require both. CLAUDE.md kept in sync with AGENTS.md.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>
Comment thread AGENTS.md Outdated
- Anchor to an external oracle or an independently derived reference instead of re-implementing the logic under test.
- Mocks must stand in for a collaborator's documented contract (schema, protocol), never for internals of the module under test.
- Changes that affect the external contract at the training-loop or inference level require integration tests, not just unit tests (e.g. a minimal training loop with `SimpleModel`).
- Integration tests must be executed on an actual device, not merely written: report the execution hardware spec and results in the PR.

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.

nit: an actual device --> actual devices. Thank you!

@delock

delock commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

one last question, does the agent read the PR description? I think so? do we need to add requests of adding verification on at least some hardware when the change is substantial?

I believe most morden agents would be able to get PR description with tool call. I add a line to require agents to report the hardware spec and result used for local validation when submit integration test.

Review nit: an actual device -> actual devices.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>

@pengdurice pengdurice 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.

Thank you for adding this test rules!

@pengdurice
pengdurice added this pull request to the merge queue Sep 3, 2026
Merged via the queue into master with commit f15c990 Sep 3, 2026
13 checks passed
@pengdurice
pengdurice deleted the docs/agents-test-discipline branch September 3, 2026 05:27
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants