Documentation

42.14 Failure fixtures and negative tests

Failure fixtures: every refusal is a tested feature

What you will learn

  • Explain why refusals are features that deserve tests as much as results do.
  • Use the exit-code fixtures, the twelve seeded data defects and the broken control streams.
  • Write a negative test that asserts the exit code, the message and that nothing was written.
  • Build a failure fixture for a refusal in your own workflow.

Prerequisites: Chapter 39 errors, warnings and troubleshooting and 42.9 Operational qualification.

The most dangerous failure of analysis software is the one that does not look like one: a malformed data set quietly accepted, a fractional event count silently rounded, a non-positive-definite covariance matrix quietly used. The refusal is the safety feature, and a refusal that is never tested may not exist. The package therefore contains as many deliberate-failure fixtures as it does success fixtures, and the requirement behind them is explicit: each class of failure shall end with its documented exit code and an explanatory message with a hint; no failure shall end silently or with exit code 0 (URS-GEN-003).

The anatomy of a negative test

A good negative test asserts three things, not one.

  1. The exit code is the documented one. Not merely "non-zero": the class matters, because pipelines branch on it (Chapter 39).
  2. The message is explanatory. The text names what was wrong and gives a hint. A bare "error" fails the requirement. For the fractional EVID fixture, the test requires the message to name the column and the value ("column EVID has the value 0.9, which is not a whole number"), to state the exit code, and to say why ("CMT, EVID, MDV, SS and ADDL are integer data items in NONMEM").
  3. Nothing was written that could be mistaken for a result: no output folder with a plausible-looking file, or, if a partial folder is documented, its status says so.

A fourth assertion belongs where it applies: the inputs are untouched (DI-005), because a failing command that edits its input is worse than one that succeeds.

The exit-code fixtures (OQ-GEN-003)

One test provokes every failure class that can be provoked on demand and checks the code:

Exit Meaning (Chapter 39) Fixture that provokes it
2 invalid command-line usage an option value outside its documented range (OQ-GEN-002, OQ-GEN-009): refused before anything is written
3 discovery, files, output nca no_such_file.csv; a second run into a non-empty output folder without --overwrite (DI-004, twelve commands)
4 invalid settings a settings file with method = "bogus-method"; another that is not valid TOML ([nonsense)
5 unsupported model or method feature a control stream with $MIX, produced by make_mix_model.py from the reference model
6 inconsistent model artifacts qc-nm bad_model.ctl --fail-on error
7 data validation failure qc-data qc_dirty.csv --fail-on error; a fractional EVID or ADDL in an otherwise valid data set
9 numerical or learner failure $OMEGA BLOCK(2) with a correlation of 2 (not positive definite); a record altered after the fit under validate --strict
11 checkpoint or resume incompatibility resume with no checkpoint; resume after the settings were changed

Notice that each fixture is minimal: one deliberate fault in an otherwise valid input. A fixture with three faults cannot tell you which one triggered the code.

The twelve seeded data defects (OQ-QCD-002)

For qc-data the package seeds one defect per individual in a dataset of fourteen individuals. Individuals 1 and 2 are clean on purpose: the test must also prove that clean individuals are not flagged. The expected finding for each defect was written when the data were seeded, so it is independent of the program.

Individual Seeded defect Expected check
3 duplicated record REC17
4 decreasing time TIM01
5 negative DV OBS02
6 missing DV REC04
7 no dose record DOS01
8 no observation DOS02
9 implausible body weight COV03
10 excluded observation REC05
11 dose with AMT = 0 REC07
12 text in DV VAL01
13 concentration spike OBS06
14 MDV inconsistent with EVID REC03

The test requires every expected (check, individual) pair to appear in qc_findings.csv and no finding for individuals 1 and 2. Two further tests exercise the gate around the findings (OQ-QCD-003, --fail-on: exit 7 only when the level is reached) and the file-format defects that no spreadsheet shows (a byte-order mark; mixed line endings, OQ-QCD-004). The sibling command qc-nm has the same design: a control stream with known defects (OQ-QCN-001), a clean one (OQ-QCN-003), a promise that the original is never changed and safe corrections go to a copy (OQ-QCN-002, OQ-QCN-004).

Why a seeded-defect design works

It gives both error rates. Sensitivity: of twelve defects, how many were found? False-positive rate: of the clean individuals, how many were flagged? A check that flags everything has perfect sensitivity and is useless; one that flags nothing has perfect specificity and is worse. Counting both is what the two clean individuals are for.

Refusals inside an otherwise valid model

Several fixtures are variants of the reference model with one deliberate fault each. They test that the program refuses what it cannot do correctly, loudly:

Fixture Fault Expected behaviour Test
pop_oral1_same_orphan.ctl SAME with nothing to repeat refused OQ-FIT-009
pop_oral1_same_mismatch.ctl SAME after a block of another size refused OQ-FIT-009
pop_oral1_evid_fraction.* one EVID of 0.9 refused (exit 7), not truncated OQ-FIT-010
pop_oral1_addl_fraction.* one ADDL of 1.5 refused (exit 7), not truncated OQ-FIT-010
pop_oral1_advan99.ctl unsupported ADVAN99 as one member of a batch that member fails; the others still run; the summary line reads "Fit of 3 control stream(s): 2 fitted, 1 failed", the failed one is listed with its reason, and the batch exits 5 OQ-FIT-013
pop_oral1_unused_theta.ctl a fourth THETA that no equation uses flagged; the other standard errors are not spoiled OQ-FIT-014
pop_oral1_indefinite_omega.ctl $OMEGA BLOCK(2) with correlation 2 refused (exit 9) OQ-SIM-005
A fit whose record was altered after the run edited OFV in the artifacts validate gives FAIL; --strict turns it into an error (exit 9) OQ-INS-005

The pair OQ-INS-004 and OQ-INS-005 shows the principle at its clearest. A consistent fit must get a PASS verdict with every check recorded; the same fit with one number edited must get FAIL. If only the second test existed, a validate that always said FAIL would pass the suite; if only the first, one that always said PASS would. A refusal is only meaningful alongside its acceptance.

The assistant's refusals

For the language-model assistant (Chapters 34–35) the refusals are the validation. A scripted mock model replays prepared replies so the guardrails can be tested deterministically:

  • OQ-ASK-001 — every forbidden command class is refused.
  • OQ-ASK-002 — a permitted command runs inside its session folder with a complete record.
  • OQ-ASK-005 — a settings file or control stream that points outside the permitted folders is refused: the policy resolves the data file named inside the file the command reads, not only on the command line. The test creates the outside files so the refusal is exercised on files that exist.
  • OQ-ASK-003 — with no model reachable, exit 3 with a hint.

The package is open about one gap: a reference to a file that does not exist is not refused by the policy; the command then fails with exit 3 because the file is missing, so nothing is read. A limit, recorded with its compensating control (every command is recorded and reviewed before it runs).

Building a failure fixture for your own workflow

  1. List your refusals: the situations your SOP says must stop the pipeline (an unsupported feature, a data defect, a missing prerequisite).
  2. For each, make the smallest input that triggers it, with one fault.
  3. Write the expected exit code and message class before running.
  4. Assert three things: exit code, explanatory text, nothing written (or a clearly marked partial).
  5. Pair it with an acceptance case that differs by the single fault.
  6. Add the fixture to the package and trace it to a requirement (page 42.3).

Review checklist

  • For every documented exit code, is there a fixture that provokes it?
  • Does each negative test assert the exit code, the message and the absence of output?
  • Is each refusal paired with an acceptance case that differs by the single fault?
  • For seeded-defect fixtures, are clean cases included to measure false positives?

See the previous page, the next page and the complete validation reference.