Skip to content

Canonicalize tests around @safetestset (isolation, matches OrdinaryDiffEq)#158

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:canonicalize-safetestset
Closed

Canonicalize tests around @safetestset (isolation, matches OrdinaryDiffEq)#158
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:mainfrom
ChrisRackauckas-Claude:canonicalize-safetestset

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Summary

Canonicalizes the test suite to run each independent Core test unit in its own module via @safetestset, matching the canonical OrdinaryDiffEq structure (cross-unit isolation + world-age safety). SafeTestsets expands @safetestset "name" begin ... end into a fresh module, so each unit body must be self-contained.

This is the test-isolation branch only. It does not touch the GROUP-dispatch ladder, run_tests harness, or any assertion/logic (the harness migration is a separate branch).

What changed

  • test/runtests.jl: each Core unit @testset "X" begin include("x.jl") end -> @safetestset "X" begin include("x.jl") end (Dense, Sparse, Symbols, Legacy, Miscellaneous, Public). The outer @testset verbose = true "ADTypes.jl" wrapper and the GROUP == "All"/"Core"/"QA" dispatch are unchanged. QA is untouched.
  • test/test_setup.jl (new): holds the shared using imports and the shared structs/helpers that previously lived at runtests.jl top-level — CustomTag, ForwardRuleConfig/ReverseRuleConfig/ForwardOrReverseRuleConfig, FakeSparsityDetector, FakeColoringAlgorithm, every_ad(), every_ad_with_options(). Each unit file now include("test_setup.jl") so its @safetestset module is self-contained.
  • test/{dense,sparse,legacy,misc}.jl: add include("test_setup.jl") at the top (symbols.jl/public.jl already carried their own using ADTypes; using Test).
  • Project.toml: add SafeTestsets to [extras], [targets].test, and [compat] ("0.1, 1").

Subtlety worth flagging (load-bearing)

using ADTypes is kept at runtests.jl top level (Main) on purpose. Julia qualifies a type's module in show based on visibility in Base.active_module() (which is Main), not the module the test actually runs in. With the units now in fresh modules, Main would no longer have ADTypes in scope, so string(AutoForwardDiff()) becomes "ADTypes.AutoForwardDiff()" and the startswith(string(ad), "Auto") assertions in the Printing block fail. Keeping using ADTypes in Main restores the exact printing context the original tests relied on. (Caught by the local runtime gate — first run had 25 Printing failures, fixed by this.)

Verification (local, Julia 1.11)

  • GROUP=Core: ADTypes.jl | 507 passed, 0 failed (same 507 tests as before: previously 482 pass + 25 Printing fail in an intermediate state, now all 507 pass).
  • GROUP unset (All): 507 passed.
  • GROUP=QA: Quality Assurance | 11 passed (Aqua deps_compat happy with the new [compat] SafeTestsets).
  • Runic --check --diff clean on all changed/new files.

Ignore until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

…ffEq)

Wrap each independent Core test unit (Dense, Sparse, Symbols, Legacy,
Miscellaneous, Public) in `@safetestset` so each runs in its own fresh
module, giving cross-unit isolation and world-age safety, matching the
canonical OrdinaryDiffEq structure.

The shared `using` imports and the shared structs/helpers (CustomTag, the
RuleConfig subtypes, FakeSparsityDetector, FakeColoringAlgorithm,
every_ad, every_ad_with_options) that previously lived at runtests.jl
top-level are moved into test/test_setup.jl, which each unit file now
includes so every @safetestset module is self-contained.

`using ADTypes` is kept in runtests.jl (Main): Julia qualifies a type's
module in `show` based on visibility in `Base.active_module()` (Main),
not the module the test runs in, so the printing assertions
(`startswith(string(ad), "Auto")`) require ADTypes to be in scope in Main.

Same tests, same assertions, same GROUP dispatch; only the unit wrappers
and import plumbing changed. Adds SafeTestsets to the test deps.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gdalle

gdalle commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

@ChrisRackauckas what's the deal with the sequence of Claude-generated PRs changing tests and CI? Seems that's all we're getting in ADTypes lately

@ChrisRackauckas

Copy link
Copy Markdown
Member

It's the canonicalization roll out matching the new CI runners. Anant talked about it a bit ago:

https://www.youtube.com/watch?v=CFzfJ7F-6Ks

It started to become a major deal with the codecov v6/v7 issues, julia cache action v3 crashing runners (and effectively being a useless waste of time), etc. so most Julia repos were getting random test reds due to different interactions between runners and the random CI script changes. So I took the time to finish Anant's canonicalization, which is a pretty mechanical set of changes. But the canonicalization also found lots of little inconsistencies and issues with the current CI setup when rolled out across the mass of repos (which was the point of course), so the CI scripts needed a little bit in order to be hardened to all of the different possible behaviors.

There will be another pass that happens hopefully later today that rips out the bespoke runtests.jl and instead uses the new SciMLTesting.jl repo in order to further reduce the repeated code. That will happen right on this PR though, no merging of this until that is done, and with the rollout we'll need to see if there's any edge case missed in SciMLTesting.jl.

While this repo is relatively simple so most of the PRs passed right through it without hitting any troubles, it still will help a lot that it's canonicalized so that for example, the next time CodeCov decides to do a breaking v8, that gets fixed in 1 PR instead of 192, which was the main motivation to finally finish this project.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor Author

superseded by the v1.2 folder conversion on sciml-testing-rollout (#159)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants