Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 31 additions & 7 deletions packages/oracles/oracle-gaps/args.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { stateDirOf } from './evidence.mjs'
import { posix, realPathOf } from './paths.mjs'
import { Refusal } from './ending.mjs'

const flags = new Set([`daemon`, `stop-daemon`, `ordinary`, `help`])
const flags = new Set([
`daemon`,
`stop-daemon`,
`ordinary`,
`typecheck`,
`help`,
])
// The options that take a positive whole number.
const counts = [
`contexts`,
Expand All @@ -33,19 +39,21 @@ const valued = new Set([
`diff-base`,
`pool`,
`config`,
`tsconfig`,
])
// The usage text `--help` prints (index.mjs).
export const usage = `Usage: oracle-gaps --package <dir> --source <src/x.ts,...>
[--env-prefix <name>] [--daemon] [--ordinary] [--seed <n>] [--mutants <dir>]
[--out <dir>] [--only <id,id>] [--diff-base <rev>] [--test-timeout <ms>]
[--sample <n>] [--contexts <n>] [--pool threads|forks] [--config <file>]
[--env-prefix <name>] [--daemon] [--ordinary] [--typecheck]
[--tsconfig <file>] [--seed <n>] [--mutants <dir>] [--out <dir>]
[--only <id,id>] [--diff-base <rev>] [--test-timeout <ms>] [--sample <n>]
[--contexts <n>] [--pool threads|forks] [--config <file>]
[--first-limit <ms>] [--hang-limit <ms>] [--mutant-limit <ms>]
oracle-gaps --stop-daemon --package <dir>
oracle-gaps --help

The paths in --source and --config are relative to --package. Without
--config, the run loads the Vitest config that Vitest discovers for the
package: in its directory, or else in the nearest parent directory that
The paths in --source, --config, and --tsconfig are relative to --package.
Without --config, the run loads the Vitest config that Vitest discovers for
the package: in its directory, or else in the nearest parent directory that
has one. Run the CLI from any directory.
Every line the CLI writes for a check starts with \`oracle-gaps: \` and its
kind (config, note, baseline, blocked, progress, gap, busy, done), on
Expand Down Expand Up @@ -176,6 +184,18 @@ function optionsOf(args, cwd) {
`--config ${args.config} is not a file of the package`,
`Pass --config the package's Vitest config file, relative to --package.`,
)
// The TypeScript config used to check oracle files (`--tsconfig`); by
// default tsconfig.json in the package when present (typecheck.mjs).
const tsconfig =
args.tsconfig === undefined ? undefined : packagePath(pkg, args.tsconfig)
if (
tsconfig !== undefined &&
!statSync(join(pkg, tsconfig), { throwIfNoEntry: false })?.isFile()
)
throw new Refusal(
`--tsconfig ${args.tsconfig} is not a file of the package`,
`Pass --tsconfig the package's TypeScript config file, relative to --package.`,
)
const mutants = args.mutants && resolve(cwd, args.mutants)
if (mutants && !statSync(mutants, { throwIfNoEntry: false })?.isDirectory())
throw new Refusal(
Expand Down Expand Up @@ -203,6 +223,9 @@ function optionsOf(args, cwd) {
// Ordinary (non-oracle) test files run only when asked: they never close
// a gap, and only report whether they would have caught a survivor.
ordinary: args.ordinary === true,
// Refuse the run when TypeScript oracle files are excluded from tsconfig
// or have TypeScript errors (typecheck.mjs).
typecheck: args.typecheck === true,
// Each warm context runs one mutant at a time with one worker. Measured on
// offline-transactions' FIFO executor (163 mutants, 18 cores): 8 contexts
// 124 s, 16 contexts 91 s, with identical classes.
Expand Down Expand Up @@ -240,6 +263,7 @@ function optionsOf(args, cwd) {
// A directory of authored mutants (see loadAuthored).
mutants,
config,
tsconfig,
}
}

Expand Down
33 changes: 33 additions & 0 deletions packages/oracles/oracle-gaps/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
} from './stream.mjs'
import { analyze, isRunnerCopy } from './analysis.mjs'
import { Refusal } from './ending.mjs'
import { typecheckOracleFiles, typecheckRefusal } from './typecheck.mjs'
import {
baseOf,
isWithin,
Expand Down Expand Up @@ -158,6 +159,7 @@ const ownFiles = [
`evidence.mjs`,
`daemon.mjs`,
`ending.mjs`,
`typecheck.mjs`,
`../src/oracle-property.ts`,
].map((file) => join(here, file))

Expand Down Expand Up @@ -1635,6 +1637,24 @@ export default async (env) => {
)
endPhase(`static analysis`, { mutants: mutants.length })

// TypeScript coverage and semantic check for TypeScript oracle files
// (typecheck.mjs). Without --typecheck, issues surface as notes; with
// --typecheck, any uncovered oracle file, incompatible tsconfig, or
// TypeScript error refuses the run before baseline tests execute.
const typecheck = typecheckOracleFiles(ts, pkg, [...declarations.keys()], {
config: options.tsconfig,
})
for (const line of typecheck.notes) log(line)
if (options.typecheck) {
const refusal = typecheckRefusal(ts, typecheck)
if (refusal) throw refusal
}
endPhase(`typecheck`, {
checked: typecheck.checked.length,
uncovered: typecheck.uncovered.length,
diagnostics: typecheck.diagnostics.length,
})

// The global inputs of every unit.
const lockfile = lockfileOf(pkg)
const globalKey = sha1(
Expand Down Expand Up @@ -2643,6 +2663,17 @@ export default async (env) => {
})),
excluded,
nondeterministic: [...nondeterministic],
...(typecheck.found
? {
typecheck: {
config: typecheck.config,
checked: typecheck.checked,
uncovered: typecheck.uncovered,
skipped: typecheck.skipped,
diagnostics: typecheck.diagnostics,
},
}
: {}),
mutantSeconds,
// How the result was produced: units reused from the evidence
// store and units run in this check, runs cut off at their time
Expand All @@ -2663,6 +2694,7 @@ export default async (env) => {
excluded: excluded.map(relative),
baseline: baselineFiles,
config: options.config,
typecheck,
}),
)
if (existsSync(testOutput) && statSync(testOutput).size > 0)
Expand All @@ -2679,6 +2711,7 @@ export default async (env) => {
pkg,
baseline: baselineFiles,
config: options.config,
typecheck,
paths: {
report: escapeControls(posix(join(options.out, `summary.md`))),
results: join(options.out, `results.json`),
Expand Down
4 changes: 4 additions & 0 deletions packages/oracles/oracle-gaps/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
// [--env-prefix <name>] (the framework's variable prefix; default ORACLE)
// [--daemon] (check through the package's daemon)
// [--ordinary] (also run ordinary test files, for information)
// [--typecheck] (refuse if TypeScript oracle files are excluded
// from tsconfig or have TypeScript errors)
// [--tsconfig <file>] (the TypeScript config, relative to <dir>;
// default tsconfig.json when present)
// [--seed <n>] [--mutants <dir>] [--out <dir>] [--only <id,id>]
// [--diff-base <rev>]
// [--first-limit <ms>] (a copy's first budget; default 2000)
Expand Down
19 changes: 19 additions & 0 deletions packages/oracles/oracle-gaps/report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export function renderReport({
excluded,
baseline = [],
config,
typecheck,
}) {
const gaps = gapsOf(results)
const guards = results.filter((r) => r.probeGuard)
Expand Down Expand Up @@ -327,6 +328,22 @@ export function renderReport({
fence,
``,
)
if (typecheck?.notes?.length > 0) {
lines.push(`## Typecheck notes`, ``)
for (const item of typecheck.skipped ?? [])
lines.push(
`- Skipped ${codeSpan(item.config)}: ${escapeControls(item.reason)}`,
)
for (const file of typecheck.uncovered ?? [])
lines.push(
`- ${codeSpan(file)} is not included in ${codeSpan(typecheck.config)}; \`tsc\` will not typecheck it.`,
)
for (const diag of typecheck.diagnostics ?? [])
lines.push(
`- ${codeSpan(`${diag.file}:${diag.line}:${diag.column}`)} TS${diag.code}: ${escapeControls(diag.message)}`,
)
lines.push(``)
}
lines.push(
`## How to use this report`,
``,
Expand Down Expand Up @@ -414,6 +431,7 @@ export function renderStdout({
paths,
baseline = [],
config,
typecheck,
}) {
const gaps = gapsOf(results)
const unowned = results.filter(
Expand Down Expand Up @@ -468,6 +486,7 @@ export function renderStdout({
`left out, failing with no mutant active: ${excluded.join(`, `)}`,
),
)
for (const note of typecheck?.notes ?? []) lines.push(note)
lines.push(
streamLine(`note`, `results ${escapeControls(posix(paths.results))}`),
)
Expand Down
Loading
Loading