Skip to content

[Data] Add agent instructions for test structure and fixtures - #68289

Merged
richardliaw merged 1 commit into
ray-project:masterfrom
abhishekverma-ray:data/tests-agents-md
Nov 21, 2026
Merged

richardliaw merged 1 commit into
ray-project:masterfrom
abhishekverma-ray:data/tests-agents-md

Conversation

@abhishekverma-ray

Copy link
Copy Markdown
Contributor

Summary

Adds python/ray/data/tests/AGENTS.md, short instructions that tell coding agents how to write Ray Data tests: shared cluster fixtures, DataContext fixtures, test data, parametrize, asserts and mocks, plus one before/after example. Recent agent-written Data PRs added 1.6× to 15× more test code than library code, much of it repeated setup: a Ray cluster per test, a hand-set DataContext, field-by-field asserts.

It also adds one shared datasource_v2 fixture to tests/conftest.py, which the instructions point to. It replaces three copies of the same fixture.

Before

After

  • python/ray/data/tests/AGENTS.md holds the instructions. Codex, Cursor and other agents read AGENTS.md; python/ray/data/tests/.claude/CLAUDE.md imports it for Claude Code, as python/ray/data/ already does. The rules apply to new and changed tests, not to rewriting untouched ones.
  • One datasource_v2 fixture in tests/conftest.py. test_orc.py and test_parquet.py take it by name, and test_mcap.py applies it to every test through pytestmark. Test ids ([v1], [v2]) don't change.

No library code changes. The fixture change is a refactor: each file collects the same tests as before.

Subsystems

None. Tests and agent instructions only.

Questions for reviewers

Additional information

Not a duplicate

#67919 and #67928 are the only open PRs with agent rules for Data tests. This PR covers what they don't: test structure and fixtures, in a file that agents other than Claude Code also read.

Testing

Command Result
pre-commit on the 6 changed files Passed
pytest datasource/test_mcap.py 67 passed, 6 skipped. The collected test ids are identical to master's (73).
pytest datasource/test_parquet.py -k "v1 or v2" (the tests that use the fixture) 23 passed, 1 skipped
pytest datasource/test_orc.py 217 passed, 6 failed: all test_read_orc_v2_partitioned_scan_optimizations, which asserts the reader's source path ends in python/ray/data/.... That isn't true for the pip-installed Ray used locally, and the test doesn't use the renamed fixture.

Environment: Ray nightly (3eb9895) with this branch's python/ray/data and python/ray/tests linked over it, Python 3.12.10, pyarrow 23.0.1, pandas 2.3.3, pytest 7.4.4.

Not checked yet: that Codex and Claude Code load the new file when run from the repository root.

Note for open PRs

#68235 adds a test that takes use_datasource_v2. If it merges after this PR, that test needs the one-word rename to datasource_v2.

AI assistance (Claude Code) was used to draft the instructions, the fixture change and this description.

🤖 Generated with Claude Code

Add python/ray/data/tests/AGENTS.md: short instructions for coding agents
on how to write Ray Data tests. It covers the shared cluster fixtures,
DataContext fixtures, test data, parametrize, asserts and mocks, with one
before/after example. python/ray/data/tests/.claude/CLAUDE.md imports it
for Claude Code, as python/ray/data/ already does.

Add one shared datasource_v2 fixture to tests/conftest.py, which the
instructions point to. It replaces three copies: orc_reader_version in
test_orc.py, use_datasource_v2 in test_parquet.py, and the autouse
datasource_v2 in test_mcap.py, which now applies it with pytestmark.
Test ids don't change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Abhishek Verma <[email protected]>
@abhishekverma-ray
abhishekverma-ray requested review from a team as code owners November 18, 2026 03:36
@abhishekverma-ray abhishekverma-ray added the data Ray Data-related issues label Nov 18, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@abhishekverma-ray

abhishekverma-ray commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Back-test

To see whether these instructions change what an agent writes, I took the code-only change from two Data PRs that merged yesterday. I had an agent add tests for it twice: once without this file, and once told to read it. It was the same model (Claude) with the same prompt otherwise, one run each. Then I reverted each code change to see which new tests catch it.

#67079 (synthesized path filtering, +29 code lines)

Tests Lines added New cases Cases that run Ray Fail when the change is reverted
Original PR (Codex, before review) 432 56 36 not run
Merged, after review 243 25 7 not run
Agent without this file 211 61 13 39 of 61
Agent with this file 93 8 3 7 of 8

#67228 (filtered Lance row counts, +56 code lines)

Tests Lines added New cases Fail when the change is reverted
Original PR (Codex, before review) 352 76 not run
Merged, after review 134 15 not run
Agent without this file 45 8 4 of 8
Agent with this file 48 8 5 of 8

What the file changed:

  • [Data] Fix synthesized path filtering in DataSourceV2 #67079:
    • Without the file, the agent wrote 48 unit cases: scanner × partitioning × existing predicate × predicate shape. 20 of them pass with the change reverted. It also set use_datasource_v2 by hand three times and read Parquet without a shared cluster fixture.
    • With the file, it wrote one unit table and one end-to-end test. The end-to-end test uses ray_start_regular_shared, the datasource_v2 fixture with indirect=True, and a single rows_same assert.
  • [Data] Fix filtered Lance row-count metadata #67228: both runs were already small. The file only changed style: named cases (pytest.param(..., id=...)) and a module-scoped data fixture.
  • With the file, the cases that still pass on revert are deliberate guards: the unchanged data-only path, and the options that must keep an exact row count.

Caveats:

  • One run per arm.
  • The agent differs from the original PRs' (Codex), so part of the drop from the original rows is the agent, not the file.
  • The smaller [Data] Fix synthesized path filtering in DataSourceV2 #67079 tests skip two cases that review kept: MCAP, and a renamed path column. They still need review.
  • I checked that both agents pick up the file on their own. Claude Code loads it when it reads any file under python/ray/data/tests/. Codex, started at the repo root, searched for and read it in 3 of 3 test-writing runs, then used ray_start_regular_shared and datasource_v2.

@abhishekverma-ray abhishekverma-ray added the go add ONLY when ready to merge, run all tests label Nov 18, 2026
@richardliaw
richardliaw merged commit 3cf61c5 into ray-project:master Nov 21, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants