Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
a9650db
test(oracle-gaps): constructed history for a config whose root is a s…
KyleAMathews Nov 15, 2026
1c1e828
test(oracle-gaps): declare the constructed config-root field in the g…
KyleAMathews Nov 15, 2026
b6522a6
test(oracle-gaps): set the constructed history's root through test.root
KyleAMathews Nov 15, 2026
4e2c233
test(oracle-gaps): the test-root history holds no torn row
KyleAMathews Nov 15, 2026
ce77765
fix(oracle-gaps): copies resolve when the vitest config sets root
KyleAMathews Nov 15, 2026
b0d97be
chore: changeset for the test-root copy fix
KyleAMathews Nov 15, 2026
69e90e2
Merge origin/main into fix/oracle-gaps-root-copies
KyleAMathews Nov 15, 2026
5ac152e
ci(oracle-gaps): place the test-root history in a Windows fixed-seed …
KyleAMathews Nov 15, 2026
ff1705d
ci(oracle-gaps): place the test-root history's units in an e2e shard
KyleAMathews Nov 15, 2026
12a2981
test(oracle-gaps): constructed histories for each shape of a config's…
KyleAMathews Nov 16, 2026
7bdef53
test(oracle-gaps): share the test-root fixture row of the linked root…
KyleAMathews Nov 16, 2026
6adb42d
ci(oracle-gaps): place the new test-root histories in Windows shard 6…
KyleAMathews Nov 16, 2026
7e08435
fix(oracle-gaps): serve copies of test files only through the read of…
KyleAMathews Nov 16, 2026
6fa802f
test(oracle-gaps): install a pragma's environment where a root above …
KyleAMathews Nov 16, 2026
867dc2d
Merge remote-tracking branch 'origin/main' into fix103
KyleAMathews Nov 16, 2026
17fceb9
test(oracle-gaps): a constructed history whose config plugin loads te…
KyleAMathews Nov 16, 2026
fc02a63
fix(oracle-gaps): the wrapper's load serves a copy before the config'…
KyleAMathews Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/oracle-gaps-test-root-copies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/oracles': patch
---

The `oracle-gaps` CLI judges the mutants of a package whose Vitest config sets `test.root`. Before, the CLI resolved each in-memory copy of a test file to its path, so Vite named the copy from its root and imported it again by that name. Under a test root other than the package, that name (`/.oracle-gaps-…`) matched no copy, the copy failed to load, and the mutants of an owner there reported `setup-error`. The CLI now leaves a copy unresolved: Vite keeps the absolute path that Vitest imports it by, and the CLI serves the copy from that path. This works for a test root inside the package, above it, a root that holds no test file, and a root that is a symbolic link.
28 changes: 15 additions & 13 deletions packages/oracles/oracle-gaps/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ function alive(pid) {
* process to find its per-file pragmas (`@vitest-environment`,
* `@module-tag`; cli-api's `promises.readFile(filepath)`, which gives "" for
* a file that is not there), so a copy would run in the config's default
* environment instead of its file's. The read of a copy's path returns its
* text; any other read is Node's own.
* environment instead of its file's. The wrapper's plugin serves the copy to
* Vite, by the absolute path that Vitest imports it by: no plugin resolves a
* copy, since Vite would name a resolved copy from its root, the config's
* test root, and import it again by that name (issue #101). The read of a
* copy's path returns its text; any other read is Node's own.
*/
let copiesServed = false
function serveCopies() {
Expand All @@ -133,9 +136,7 @@ function serveCopies() {
promises.readFile = function (path, options, ...rest) {
const text =
typeof path === `string`
? globalThis.__oracleGapsCopies?.get(
path.replaceAll(String.fromCharCode(92), '/'),
)
? globalThis.__oracleGapsCopies?.get(posix(path))
: undefined
if (text === undefined) return readFile.call(this, path, options, ...rest)
const encoded =
Expand Down Expand Up @@ -500,6 +501,8 @@ export async function openSession(pkg) {
wrapper,
`import { realpathSync } from 'node:fs'
import { mergeConfig } from 'vitest/config'
// The path rule beside this wrapper, by which copies are keyed.
import { posix } from './paths.mjs'
${
config
? `import * as config from ${JSON.stringify(specifierOf(home, join(pkg, config)))}
Expand All @@ -521,14 +524,11 @@ export default async (env) => {
plugins: [{
name: 'oracle-gaps-schemata',
enforce: 'pre',
// A copy of a test file (runBatch) exists only here, so no other Vitest
// run finds it; Vite names a file in the package by its path from the
// package. A workspace dependency loads from its one-file bundle
// (workspaceBundles).
// A workspace dependency loads from its one-file bundle
// (workspaceBundles). A copy of a test file is not resolved here, so
// Vite keeps the absolute path that Vitest imports it by, and \`load\`
// serves it.
resolveId(source) {
const copies = globalThis.__oracleGapsCopies
for (const path of [source, ${JSON.stringify(pkg)} + source])
if (copies?.has(path.replaceAll(String.fromCharCode(92), '/'))) return path
return globalThis.__oracleGapsBundles?.get(source)
},
// Each module this context transforms, so a run is stored under the
Expand All @@ -546,7 +546,9 @@ export default async (env) => {
const at = id.indexOf('?')
if (at >= 0 && [...new URLSearchParams(id.slice(at + 1)).keys()].every((key) => ['raw', 'url', 'worker', 'sharedworker', 'inline'].includes(key))) return undefined
const path = at < 0 ? id : id.slice(0, at)
const copy = globalThis.__oracleGapsCopies?.get(path.replaceAll(String.fromCharCode(92), '/'))
// A copy of a test file (runBatch) exists only in memory, so this
// plugin, which loads before the config's own, answers for it.
const copy = globalThis.__oracleGapsCopies?.get(posix(path))
if (copy !== undefined) return copy
// This context's authored patch, or else the instrumented source of the
// current check, both set by the runner in this process.
Expand Down
152 changes: 127 additions & 25 deletions packages/oracles/oracle-gaps/gap-report-model-oracle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,15 @@ const drawn = fc.record({
// Whether the warm daemon is replaced after the warm check (review of #73, B2).
// Only the constructed history of a replaced warm daemon sets it.
warmReplaced: fc.constant(false),
// Where the config's `test.root` sits (issue #101, `testRoots`): `none`, the
// package, or a shape that only a constructed history sets. The constant
// draws nothing, so generated histories keep their values; `histories`
// takes a constructed one back as this constant, as `tornRows` does.
testRoot: fc.constant(`none`),
// Whether the config has a plugin whose own \`load\` reads each test file
// with a sync read (\`LOAD_PLUGIN\`, review of #103). Only a constructed
// history sets it; \`histories\` takes it back as this constant.
loadPlugin: fc.constant(false),
})

// The edit sequence over the witness module, the one list of steps that a
Expand Down Expand Up @@ -888,14 +897,15 @@ const keepsSteps = (history) => {
// steps (`laterStepsOf`). Taking a history back returns it unchanged,
// except a constructed one whose `steps` hold a later edit, which the
// steps grammar cannot draw: its later edits move to `laterSteps`. A
// constructed history may also set `tornRows` (issue #83), which `drawn`
// cannot produce, so its take-back reads it as the drawn constant `false`
// (as `claimScenario` does): a shrink is torn-row-free.
// constructed history may also set `tornRows` (issue #83) or `testRoot`
// (issue #101), which `drawn` cannot produce, so its take-back reads each as
// its drawn constant (as `claimScenario` does): a shrink is torn-row-free and
// runs with the package as the config's root.
const histories = drawn.map(
(history) => (keepsSteps(history) ? history : { ...history, steps: null }),
(value) => {
const history =
/** @type {{ witness: unknown, steps: unknown[] | null, tornRows: unknown }} */ (
/** @type {{ witness: unknown, steps: unknown[] | null, tornRows: unknown, testRoot: unknown }} */ (
value
)
if (!keepsSteps(history))
Expand All @@ -904,7 +914,11 @@ const histories = drawn.map(
// only the constructed history sets it) comes back as engaged, so the
// arbitrary can shrink it. The disarm is therefore not kept by a shrink.
const taken =
history.tornRows === false ? value : { ...history, tornRows: false }
history.tornRows === false &&
history.testRoot === `none` &&
history.loadPlugin === false
? value
: { ...history, tornRows: false, testRoot: `none`, loadPlugin: false }
const later = (history.steps ?? []).filter((step) =>
laterEdits.includes(step),
)
Expand Down Expand Up @@ -2951,6 +2965,11 @@ function resolveHistory(history) {
tornRows: history.tornRows === true,
...configOf(history),
configEnv: history.configEnv === true,
// Where the config's `test.root` sits (`testRoots`, issue #101): only a
// constructed history sets it, so a generated one runs with the package
// as the root.
testRoot: history.testRoot ?? `none`,
loadPlugin: history.loadPlugin === true,
native: history.native ?? `none`,
// A prebuilt addon in the workspace dependency's build/Release
// (`addRelease`).
Expand Down Expand Up @@ -5183,13 +5202,23 @@ const altConfigPath = (plan) =>
// package that it transforms, keeping what the module does.
const PRE_PLUGIN = `{ name: 'gap-pre-rewrite', enforce: 'pre', transform(code, id) { const path = id.split('?')[0]; return /\\.(ts|js|mjs)$/.test(path) && !path.includes('/node_modules/') ? code + '\\n// rewritten by a pre plugin\\n' : undefined } }`

// The config's own plugin with a \`load\` hook (\`loadPlugin\`): it loads each
// test file itself, with a sync read of its path, as a plugin that reads a
// module's source does. The runner's copy of a test file exists only in
// memory, so only the runner's own \`load\` can answer for it (review of #103).
const LOAD_PLUGIN = `{ name: 'gap-own-load', load(id) { const path = id.split('?')[0]; return path.endsWith('.test.ts') ? readFileSync(path, 'utf8') : undefined } }`

/**
* The text of the package's config, in its syntax (`configOf`), with the
* fault, the top-level await, or the `require` calls the plan holds. `test`
* is the config's `test` object.
*/
function configText(plan, test) {
const commonjs = plan.configSyntax === `cjs`
const plugins = [
...(plan.prePlugin ? [PRE_PLUGIN] : []),
...(plan.loadPlugin ? [LOAD_PLUGIN] : []),
]
const config = `defineConfig(${
{ object: ``, function: `() => (`, async: `async () => (`, promise: `` }[
plan.config
Expand All @@ -5198,7 +5227,7 @@ function configText(plan, test) {
plan.fault === `projects`
? `{ projects: [{ test: { name: 'unit', ...${test} } }] }`
: test
}${plan.prePlugin ? `, plugins: [${PRE_PLUGIN}]` : ``} }${plan.config === `object` || plan.config === `promise` ? `` : `)`})`
}${plugins.length > 0 ? `, plugins: [${plugins.join(`, `)}]` : ``} }${plan.config === `object` || plan.config === `promise` ? `` : `)`})`
// A promise of the config, a null default, or a config cut off mid-object.
const body =
plan.fault === `configNull`
Expand All @@ -5212,6 +5241,11 @@ function configText(plan, test) {
commonjs
? `const { defineConfig } = require('vitest/config')`
: `import { defineConfig } from 'vitest/config'`,
...(plan.testRoot === `none`
? []
: [`import { fileURLToPath } from 'node:url'`]),
// Only an ES module config has the load plugin (its constructed history).
...(plan.loadPlugin ? [`import { readFileSync } from 'node:fs'`] : []),
...(plan.fault === `configThrows`
? [`throw new Error('the fixture config broke')`]
: []),
Expand Down Expand Up @@ -5259,6 +5293,54 @@ const parentModules = (plan, state) =>
? `../node_modules`
: `node_modules`

/**
* Where a config's `test.root` sits (issue #101), as a path from the config,
* with the test files' glob and the setup file as Vitest reads them: relative
* to that root. `none` sets no root, so the root is the package. `tests` is
* the directory that holds the tests, as the repository's own oracle-gaps
* config sets it. `parent` is the directory above the package, which the
* driver places in a directory `pkg` of its scratch directory, so the glob
* names it. `outside` is a directory of the package that holds no test file,
* so the test files lie outside the root. `link` is `tests`, where the
* package's `tests` is a symbolic link to the directory that holds them
* (`linkedTests`), so the root's path is a link's. Vite names a module that
* a plugin resolves inside its root by its path from the root, and one
* outside it by its absolute path, so each shape names a copy of a test file
* differently if the runner resolves it. Every shape names each test file by
* its path in the package, so the model's keys are the same in all of them.
* Vitest resolves the package of a pragma's environment from the root (its
* init chunk's `vitest-environment-<name>` resolution), so under `parent` that
* package lies in the root's node_modules (`environments`); every other shape
* finds the package's own.
* Only an ES module config sets a root (it reads its own URL), and only the
* constructed histories set one, each as an ES module config.
*/
const inTests = {
root: `./tests`,
include: `**/*.test.ts`,
setup: `./setup.ts`,
}
const testRoots = {
none: { include: `tests/**/*.test.ts`, setup: `./tests/setup.ts` },
tests: inTests,
parent: {
root: `..`,
include: `pkg/tests/**/*.test.ts`,
setup: `./pkg/tests/setup.ts`,
environments: `../node_modules`,
},
outside: {
root: `./src`,
include: `../tests/**/*.test.ts`,
setup: `../tests/setup.ts`,
},
link: inTests,
}

// The directory that the package's `tests` links to under the `link` test
// root.
const linkedTests = `tests-target`

function fixtureFiles(plan, state = initialState(plan)) {
const manifest = (fields) =>
`${JSON.stringify({ private: true, type: `module`, ...fields })}\n`
Expand All @@ -5269,11 +5351,18 @@ function fixtureFiles(plan, state = initialState(plan)) {
: `${JSON.stringify({ private: true, ...fields })}\n`
// A symbolic link, as a package manager links a workspace package.
const link = (target) => ({ link: target })
const test = `{ include: ${
// The config's test root, and the test files' glob and the setup file,
// which Vitest reads relative to it (`testRoots`, issue #101).
const testRoot = testRoots[plan.testRoot]
const testRootOption =
testRoot.root === undefined
? ``
: `root: fileURLToPath(new URL('${testRoot.root}', import.meta.url)), `
const test = `{ ${testRootOption}include: ${
plan.configEnv
? `process.env.VITEST === 'true' && process.env.TEST === 'true' && process.env.NODE_ENV === 'test' ? ['tests/**/*.test.ts'] : []`
: `['tests/**/*.test.ts']`
}${plan.setupGlobal || plan.fault === `setupThrows` ? `, setupFiles: ['./tests/setup.ts']` : ``} }`
? `process.env.VITEST === 'true' && process.env.TEST === 'true' && process.env.NODE_ENV === 'test' ? ['${testRoot.include}'] : []`
: `['${testRoot.include}']`
}${plan.setupGlobal || plan.fault === `setupThrows` ? `, setupFiles: ['${testRoot.setup}']` : ``} }`
// A history that installs a scoped addon later declares it from the
// start, beside a scoped package already installed in its scope.
const scoped = plan.steps.includes(`addScopedAddon`)
Expand Down Expand Up @@ -5453,21 +5542,22 @@ function fixtureFiles(plan, state = initialState(plan)) {
: {}),
'tests/c.test.ts': ordinaryTestFile(plan),
// The environment oracle file a's pragma names (`pragma`), a package
// as Vitest finds one (`vitest-environment-<name>`).
// as Vitest finds one (`vitest-environment-<name>`) from the test root.
...(plan.pragma
? {
'node_modules/vitest-environment-marked/package.json': `${JSON.stringify({ name: `vitest-environment-marked`, type: `module`, exports: `./index.js` })}\n`,
'node_modules/vitest-environment-marked/index.js': [
`export default {`,
` name: 'marked',`,
` viteEnvironment: 'ssr',`,
` setup(global) {`,
` global.__gapEnvironment = 'marked'`,
` return { teardown() { delete global.__gapEnvironment } }`,
` },`,
`}`,
``,
].join(`\n`),
[`${testRoot.environments ?? `node_modules`}/vitest-environment-marked/package.json`]: `${JSON.stringify({ name: `vitest-environment-marked`, type: `module`, exports: `./index.js` })}\n`,
[`${testRoot.environments ?? `node_modules`}/vitest-environment-marked/index.js`]:
[
`export default {`,
` name: 'marked',`,
` viteEnvironment: 'ssr',`,
` setup(global) {`,
` global.__gapEnvironment = 'marked'`,
` return { teardown() { delete global.__gapEnvironment } }`,
` },`,
`}`,
``,
].join(`\n`),
}
: {}),
// A copy that a check which died left behind (the runner names its
Expand Down Expand Up @@ -5519,7 +5609,18 @@ function fixtureFiles(plan, state = initialState(plan)) {
intent: `pushes a different label`,
author: `gap-report oracle`,
})
return files
if (plan.testRoot !== `link`) return files
// The `link` test root: the files of `tests` live in `linkedTests`, and
// `tests` links to it.
return Object.fromEntries([
...Object.entries(files).map(([path, text]) => [
path.startsWith(`tests/`)
? `${linkedTests}/${path.slice(`tests/`.length)}`
: path,
text,
]),
[`tests`, link(linkedTests)],
])
}

/**
Expand Down Expand Up @@ -5554,7 +5655,8 @@ function writeFixture(dir, files) {
`deps/state-dep`,
`node_modules`,
])
mkdirSync(join(dir, sub), { recursive: true })
// A directory that the state links elsewhere is the link's.
if (!(sub in files)) mkdirSync(join(dir, sub), { recursive: true })
if (!existsSync(join(dir, `node_modules/state-dep`)))
symlinkSync(`../deps/state-dep`, join(dir, `node_modules/state-dep`), `dir`)
for (const path of written.get(dir) ?? [])
Expand Down
Loading
Loading