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
5 changes: 5 additions & 0 deletions .changeset/gap-partial-report-on-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/oracles': patch
---

`oracle-gaps`: a run whose own process dies in its mutant phase (a native crash in a worker thread under `--pool threads`, or any other signal or exit that skips the run's own ending) no longer loses the mutants it had judged. The CLI writes them as a partial report: `results.json` with `status: "partial"`, the `cause` (`the run's process exited with <signal>`), the run's usual fields, the judged `results` in report order, and `unjudged`, the ids of every mutant it did not judge; and `summary.md`, which renders the judged mutants under a `**Partial report**` line that names the cause, the count judged of all, and the unjudged ids. The done line ends `; partial report <out>/summary.md`. A run whose process dies before its mutant phase writes no report, as before; a stopped run is unchanged.
80 changes: 54 additions & 26 deletions packages/oracles/oracle-gaps/check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2385,9 +2385,58 @@ export default async (env) => {
)
const results = []
const started = Date.now()
// Results are appended as they finish, so a stopped survey keeps them.
// What results.json says of the run besides its results, and what the
// summary renders them under.
const reportFields = {
run: runIdentity,
options: { ...options, only: options.only && [...options.only] },
// A report with a failing oracle file is provisional: its failing
// laws judge nothing (Block per law). Each test file's baseline, as
// the report leads with it.
provisional,
baseline: baselineFiles.map(({ tests, ...file }) => ({
...file,
passed: tests.filter((t) => t.state === `passed`).length,
failed: tests.filter((t) => t.state === `failed`).length,
skipped: tests.filter((t) => t.state === `skipped`).length,
})),
excluded,
nondeterministic: [...nondeterministic],
}
const renderFields = {
run: runIdentity,
excluded: excluded.map(relative),
baseline: baselineFiles,
config: options.config,
}
// Results are appended as they finish, so a stopped survey keeps them,
// after a first line that holds what a partial report of them needs
// (ending.mjs, partialEnding): this process, the ids of every mutant the
// run judges in the order its report lists them, and the report's other
// fields. The CLI writes that report when this process dies before its
// own ending.
const partial = join(options.out, `results.jsonl`)
rmSync(partial, { force: true })
const order = (a, b) =>
a.number - b.number || a.source.localeCompare(b.source)
writeFileSync(
partial,
`${JSON.stringify({
partialOf: {
pid: process.pid,
ids: [
...[...queue].sort(order).map((mutant) => mutant.id),
...authored
.filter(
(mutant) =>
!options.only || options.only.has(`authored:${mutant.id}`),
)
.map((mutant) => `authored:${mutant.id}`),
],
report: reportFields,
render: renderFields,
},
})}\n`,
)
// A selection no plan foresaw (the ordinary tier's) is checked when a
// mutant first asks for it, once even when several contexts ask at once.
const selectionFor = async (slot, file, keys) => {
Expand Down Expand Up @@ -2597,9 +2646,7 @@ export default async (env) => {
)
await evaluateGroup(group, slot)
})
results.sort(
(a, b) => a.number - b.number || a.source.localeCompare(b.source),
)
results.sort(order)
endPhase(`operator mutants`, { mutants: results.length })

// 6. Authored mutants, spread across the contexts. Each serves a patched
Expand Down Expand Up @@ -2712,20 +2759,7 @@ export default async (env) => {
join(options.out, `results.json`),
JSON.stringify(
{
run: runIdentity,
options: { ...options, only: options.only && [...options.only] },
// A report with a failing oracle file is provisional: its failing
// laws judge nothing (Block per law). Each test file's baseline, as
// the report leads with it.
provisional,
baseline: baselineFiles.map(({ tests, ...file }) => ({
...file,
passed: tests.filter((t) => t.state === `passed`).length,
failed: tests.filter((t) => t.state === `failed`).length,
skipped: tests.filter((t) => t.state === `skipped`).length,
})),
excluded,
nondeterministic: [...nondeterministic],
...reportFields,
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 @@ -2740,13 +2774,7 @@ export default async (env) => {
span(`check`, checkStarted, { evidence })
writeFileSync(
join(options.out, `summary.md`),
renderReport({
results,
run: runIdentity,
excluded: excluded.map(relative),
baseline: baselineFiles,
config: options.config,
}),
renderReport({ ...renderFields, results }),
)
if (existsSync(testOutput) && statSync(testOutput).size > 0)
log(
Expand Down
62 changes: 61 additions & 1 deletion packages/oracles/oracle-gaps/ending.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
// a line of the stream (stream.mjs) or of the refusal block. Each ending
// replaces the files of another ending that an earlier run left in the
// directory (check.mjs removes error.log when a check completes).
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
import {
existsSync,
mkdirSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { posix, realPathOf } from './paths.mjs'
import { renderReport } from './report.mjs'
import { escapeControls, streamLine } from './stream.mjs'

// A path as a line of the stream shows it: in forward slashes, with a line
Expand Down Expand Up @@ -92,3 +99,56 @@ function write(out, results, summary, log) {
return false
}
}

/**
* The partial report of a run whose process `pid` ended, by `cause`, before
* it wrote its own ending: when it ended in its mutant phase, its
* results.jsonl in `out` starts with what the report needs (check.mjs) and
* holds the mutants it judged. results.json then has status `partial`, the
* cause, the judged results in report order, and the ids of the mutants it
* did not judge, and summary.md renders the judged under a line that says the
* report is partial. Returns the summary's path, or undefined when the run
* ended before its mutant phase (no results.jsonl of this process) or the
* report cannot be written.
*/
export function partialEnding(out, pid, cause) {
try {
const at = join(out, `results.jsonl`)
if (!existsSync(at)) return undefined
const [head, ...rows] = readFileSync(at, `utf8`).split(`\n`)
const of = JSON.parse(head).partialOf
if (of?.pid !== pid) return undefined
// Each row ends with its line break, so only a complete row is judged.
const byId = new Map(
rows.slice(0, -1).map((row) => {
const result = JSON.parse(row)
return [result.id, result]
}),
)
const results = of.ids
.filter((id) => byId.has(id))
.map((id) => byId.get(id))
const unjudged = of.ids.filter((id) => !byId.has(id))
writeFileSync(
join(out, `results.json`),
JSON.stringify(
{ status: `partial`, cause, ...of.report, results, unjudged },
null,
1,
),
)
const summary = join(out, `summary.md`)
writeFileSync(
summary,
renderReport({
...of.render,
results,
partial: { cause, all: of.ids.length, unjudged },
}),
)
rmSync(join(out, `error.log`), { force: true })
return summary
} catch {
return undefined
}
}
26 changes: 23 additions & 3 deletions packages/oracles/oracle-gaps/gap-report-model-oracle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5189,16 +5189,34 @@ const NATIVE_CRASHES = [
* thread in it, so the step is the forks pool, where a crash ends only its own
* worker (whose mutants the run reports), or another Node version; under
* forks, the crash was the run's own process, so the step is another Node
* version.
* version. A run whose process ended once its baseline was done wrote a
* partial report of the mutants it had judged (`partialOwed`), and the line
* ends by naming its summary, `report`.
*/
const crashLine = (signal, pool) =>
const crashLine = (signal, pool, report) =>
`oracle-gaps: done error, the run's process exited with ${signal}${
!NATIVE_CRASHES.includes(signal)
? ``
: pool === `threads`
? `: a native crash, a fault in Node, V8 or a native addon, which ends every worker thread with it; rerun with --pool forks, where it ends only its worker, or with another Node version`
: `: a native crash, a fault in Node, V8 or a native addon; rerun with another Node version`
}`
}${report === undefined ? `` : `; partial report ${report}`}`
/**
* Whether a run whose process ended by itself (`when`) owes a partial report:
* when its process ended after the baseline, with mutants still to judge. A
* crash comes from the stop witness's test where its mutant changes its
* output, which no baseline run does, so it always ends a run in its mutant
* phase; the CLI's abort strikes as its session opens, before any baseline,
* so nothing was judged and no report is owed.
*/
const partialOwed = (when) => when === `crash`
/**
* The line a partial report's summary.md holds under its inputs: what ended
* the run, how many of its `all` mutants it judged, and the ids of those it
* did not, in the order a completed report lists them.
*/
const partialNote = (cause, judged, all, unjudged) =>
`**Partial report**: ${cause} after ${judged} of ${all} mutants were judged. Not judged: ${unjudged.join(`, `)}.`

function model(plan) {
const refused = refusal(plan)
Expand Down Expand Up @@ -7031,6 +7049,8 @@ export {
verdictLine,
doneLine,
crashLine,
partialOwed,
partialNote,
kill,
push,
judging,
Expand Down
Loading
Loading