skip to content

general code and the edge-case tail · lesson 5 of 9 · sources checked 2026-11-30

add one case without a regression

This lesson adds a case to general code with a test in production shape, one source for each fact, and a guard that can fail.

status of this lesson: documented in my test system

purpose

A fix for one case can break a case that worked. Such a regression can come from a test that cannot fail, or from a second copy of one fact. A short, fixed procedure makes each new case safe for the cases that already work.

objectives

  1. Write the failed case as a test in the exact production shape.
  2. Keep one source for each fact, with one constant or a parity test.
  3. Explain why a new guard must show one time that it can fail.
  4. Record a mutation check: break the guard, and count the red tests.
  5. Set the confidence label of a rule, and score only a confirmed rule.

new terms

production shape
The exact form of an input that the producer in production sends.

how it works

I add each new case with the same seven steps:

  1. Keep the evidence: the failed input, as it arrived.
  2. Find the general rule, and each other copy of the same fact.
  3. Write a test of the case in the production shape. The test fails now.
  4. Add a test for the nearest case that works now. That test passes now.
  5. Make the smallest change that turns the first test green, and keeps the second test green.
  6. Keep one source for the fact.
  7. Break the new guard one time, record the count of red tests, and set the confidence label of the rule.

three causes of a regression

In my model, a regression in general code has three causes:

  • a second copy of one fact, which a change updates in one place only;
  • a silent default arm, which takes a new case with no record;
  • a test input that is not the production shape, so that the test passes and the real input fails.

For example, a test sends a page as plain text. Production sends the rendered page with its derived markers. The test is green, and production is wrong.

faults on the benchmark platform

The records of the benchmark platform, my test system, show each of these causes. A correct fix can make each rendered page of a protected site class read as a challenge. The correction was a separate field for derived markers, and a test in the exact production shape.

Some credential refusals had a terminal class, and the code still tried them again. Two parts of the code held their own list of terminal errors. The correction was one exported constant for both parts.

A speed change can also alter each verdict of some rules.

The settle step stops at the first pass of a verdict rule, before the page is complete. The correction is an early stop only for a rule with a positive condition, and a test that holds the gate in place.

one source for each fact

A fact in two places drifts. Use one constant that both readers import. When two copies are necessary, add a parity test that fails when the copies differ. For example, a list of trusted clients in a detector and the same list in its test data are two copies.

a guard must show that it can fail

A guard that cannot fail gives no information. On the benchmark platform, some checks stayed green over an empty set. An assertion over an empty set is true for each item, because the set has no item. The correction had three parts:

  • a count floor before each assertion over a derived set;
  • a meta-test over all test files, which finds an assertion with no floor;
  • one mutation check for each new guard.

A mutation check is a deliberate break of the guard. Make the change one time, run the suite, and record the count of red tests. A count of zero means that no test protects the guard. Then put the guard back. For example, a guard that selects blocked rows can return an empty list for the check.

Some verdict rules on the platform passed for each visitor. Such a rule is a vacuous rule. The correction was a test with two structural clauses. A rule that cannot fail cannot be confirmed, and a rule that is not confirmed cannot score.

A rule can also lose its label by mistake. The correction is a second test with the browser of the collector, and a positive control.

the confidence label of a rule

Each rule gets a label of the confidence ladder. Only a confirmed rule changes a score. For example, a new rule starts as unmeasured. It becomes confirmed only after a stored case shows that it can fail and a stored case shows that it can pass.

the two sides

automation sidedetection side
A regression in general code can come from three causes. They are a second copy of one fact, a silent default arm, and a test input that is not the production shape.A detection team has the same causes. Two copies of a list of trusted clients can drift, and a rule can pass a synthetic test that it cannot fail.

design decisions

optiongaincostwhen it is correct
Test with a simple synthetic inputThe test is fast to write.The real input can still fail.Only next to a test in production shape
Test in the exact production shapeThe test fails as production fails.The team must keep a stored real form.For each new case
One exported constantNo drift is possible.Each reader must import it.When both readers are in one code base
Parity test over two copiesEach copy stays in its place.Somebody must run and keep the test.When two copies are necessary
Mutation check for each new guardIt proves that the guard can fail.One more run for each guardFor each new guard

diagram

The first diagram shows one fact in two places.

one fact in two places, and the two corrections

A change to one copy makes the copies differ. One constant or a parity test stops the drift.source: My model of one source for each fact

The second diagram shows the seven steps in order.

the procedure to add one case

The last two messages are the mutation check and the confidence label.source: My model of the procedure to add one case

The third diagram shows a regression in general form.

a regression in general form: a speed change and a false pass

An early stop reads a page with no markers, and a rule with only negative conditions passes.source: My model of a regression in general form

code example

The four examples use synthetic rules, pages, and forms. The first example is a rule language with two guards.

m53-x07-rules.tstypescript

Refuse a rule with only negative conditions at load time, and give no verdict for an empty observation.

// A small rule language for verdict rules. All rules and pages are synthetic.
type Cond = { marker: string; test: "present" | "absent" };
type Rule = { id: string; conds: Cond[] };
type Verdict = "pass" | "fail" | "inconclusive";

// Gate at load time: a rule with only negative conditions passes on an empty page.
function load(rules: Rule[]): Rule[] {
  const ok: Rule[] = [];
  for (const r of rules) {
    if (!r.conds.some((c) => c.test === "present")) {
      console.log(`refused at load: ${r.id} has only negative conditions`);
    } else {
      ok.push(r);
    }
  }
  return ok;
}

// Guard: an empty observation gives no verdict.
function evaluate(rule: Rule, markers: Set<string>): Verdict {
  if (markers.size === 0) return "inconclusive";
  const hit = rule.conds.every((c) => (c.test === "present") === markers.has(c.marker));
  return hit ? "pass" : "fail";
}

const rules = load([
  { id: "rule-a", conds: [{ marker: "result-panel", test: "present" }, { marker: "error-text", test: "absent" }] },
  { id: "rule-b", conds: [{ marker: "error-text", test: "absent" }, { marker: "warning-text", test: "absent" }] },
]);

const pages: [string, Set<string>][] = [
  ["page with result", new Set(["result-panel"])],
  ["page with error", new Set(["result-panel", "error-text"])],
  ["empty page", new Set()],
];

for (const r of rules) {
  for (const [name, markers] of pages) console.log(`${r.id} on ${name}: ${evaluate(r, markers)}`);
}

output

The refused rule, and the verdict of the other rule on three synthetic pages.

refused at load: rule-b has only negative conditions
rule-a on page with result: pass
rule-a on page with error: fail
rule-a on empty page: inconclusive

The output shows that the rule with only negative conditions does not load, and that the empty page gives no verdict.

The second example is the structural gate on rule data.

m53-x08-gate.tstypescript

Check two clauses on synthetic rule files: a confirmed rule has a stored case on which it fails, and only a confirmed rule scores.

// A structural gate on rule data. The rule files are synthetic.
type Label = "confirmed" | "speculative" | "unmeasured";
type RuleFile = {
  id: string;
  label: Label;
  scores: boolean;
  failCase: string | null; // a stored page on which the rule must fail
};

const files: RuleFile[] = [
  { id: "rule-a", label: "confirmed", scores: true, failCase: "stored-page-a-fail" },
  { id: "rule-b", label: "confirmed", scores: true, failCase: null },
  { id: "rule-c", label: "speculative", scores: true, failCase: "stored-page-c-fail" },
  { id: "rule-d", label: "speculative", scores: false, failCase: null },
  { id: "rule-e", label: "unmeasured", scores: false, failCase: null },
];

const faults: string[] = [];
for (const f of files) {
  // Clause 1: a rule that cannot fail cannot be confirmed.
  if (f.label === "confirmed" && f.failCase === null) {
    faults.push(`${f.id}: confirmed, but no stored case shows that it can fail`);
  }
  // Clause 2: a rule that is not confirmed cannot score.
  if (f.scores && f.label !== "confirmed") {
    faults.push(`${f.id}: scores, but its label is ${f.label}`);
  }
}

for (const f of faults) console.log(`gate: ${f}`);
console.log(faults.length === 0 ? "gate: pass" : `gate: fail (${faults.length} faults)`);

output

One line for each fault, and the result of the gate.

gate: rule-b: confirmed, but no stored case shows that it can fail
gate: rule-c: scores, but its label is speculative
gate: fail (2 faults)

The output shows one fault for each clause.

The third example puts a count floor before each assertion over a derived set. Then it breaks the guard one time.

m53-x09-floor.tstypescript

Compare an assertion with no count floor and an assertion with a floor, before and after a deliberate break of the guard.

// A count floor before each assertion over a derived set, and one mutation check.
type Row = { id: string; status: number; blocked: boolean };

// Synthetic stored rows of a lab run.
const rows: Row[] = [
  { id: "r1", status: 403, blocked: true },
  { id: "r2", status: 200, blocked: false },
  { id: "r3", status: 429, blocked: true },
];

// The guard under test: it selects the rows that the code calls blocked.
let selectBlocked = (rs: Row[]) => rs.filter((r) => r.status === 403 || r.status === 429);

// Without a floor, "each item passes" is true for an empty set.
function eachNoFloor<T>(items: T[], pred: (t: T) => boolean): boolean {
  return items.every(pred);
}

// With a floor, an empty or small set is a failure, not a pass.
function eachWithFloor<T>(items: T[], floor: number, pred: (t: T) => boolean): boolean {
  return items.length >= floor && items.every(pred);
}

function suite(): { noFloor: boolean[]; withFloor: boolean[] } {
  const set = selectBlocked(rows);
  const checks = [(r: Row) => r.blocked, (r: Row) => r.status >= 400];
  return {
    noFloor: checks.map((c) => eachNoFloor(set, c)),
    withFloor: checks.map((c) => eachWithFloor(set, 1, c)),
  };
}

// Meta-test: each assertion over a derived set must declare a floor of 1 or more.
const declaredFloors: Record<string, number> = { "blocked rows": 1, "error rows": 1 };
const noFloor = Object.entries(declaredFloors).filter(([, f]) => f < 1);
console.log(`meta-test: ${noFloor.length === 0 ? "each assertion has a floor" : "missing floor"}`);

const red = (r: boolean[]) => r.filter((x) => !x).length;
let s = suite();
console.log(`normal code: red without floor ${red(s.noFloor)}, red with floor ${red(s.withFloor)}`);

// Mutation check: break the guard one time, so that it selects nothing.
selectBlocked = () => [];
s = suite();
console.log(`broken guard: red without floor ${red(s.noFloor)}, red with floor ${red(s.withFloor)}`);

output

The meta-test result, and the count of red tests for the normal code and for the broken guard.

meta-test: each assertion has a floor
normal code: red without floor 0, red with floor 0
broken guard: red without floor 0, red with floor 2

The output shows that the broken guard gives no red test without the floor, and two red tests with the floor. The count of two is the mutation record.

The fourth example is a lab dispatch switch over invented input forms. Its default arm fails loud, and a parity test compares the switch with the registry.

m53-x10-dispatch.tstypescript

Route invented lab forms with a default arm that fails loud, and compare the handled forms with the registry.

// A lab dispatch switch over invented input forms. No form is a real product.
const REGISTRY = ["form-a", "form-b", "form-c"] as const;

// The forms that the switch handles. A parity test compares this list with the registry.
const HANDLED = ["form-a", "form-b"];

function route(form: string): string {
  switch (form) {
    case "form-a":
      return "reader for form a";
    case "form-b":
      return "reader for form b";
    default:
      // The default arm fails loud. It never takes the nearest reader.
      throw new Error(`not covered: ${form}`);
  }
}

// Parity test: each registry entry is handled, and each handled form is in the registry.
const missing = REGISTRY.filter((f) => !HANDLED.includes(f));
const extra = HANDLED.filter((f) => !(REGISTRY as readonly string[]).includes(f));
console.log(`parity: missing ${JSON.stringify(missing)}, extra ${JSON.stringify(extra)}`);

for (const f of REGISTRY) {
  try {
    console.log(`${f}: ${route(f)}`);
  } catch (e) {
    console.log(`${f}: ${(e as Error).message}`);
  }
}

output

The parity result, and the route of each form of the registry.

parity: missing ["form-c"], extra []
form-a: reader for form a
form-b: reader for form b
form-c: not covered: form-c

The output shows that the parity test finds the missing form before a real input arrives.

data

confidence labels of the verdict rule files

status of this figure: documented in my test system

confidence labels of the verdict rule filesverdict rule files6667unit: rule files1. confirmed and scored2. confirmed, not scored3. speculative4. unmeasured
  1. confirmed and scored: verdict rule files 6
  2. confirmed, not scored: verdict rule files 6
  3. speculative: verdict rule files 6
  4. unmeasured: verdict rule files 7

source: Benchmark platform, code (my test system): confidence labels of the verdict rule files; date 2026-11-16; sample of 25; condition: State of the rule files when the report was made. The segment "confirmed, not scored" is the difference of 12 and 6.

data table
confidence labels of the verdict rule files
seriessetrule files
confirmed and scoredverdict rule files6
confirmed, not scoredverdict rule files6
speculativeverdict rule files6
unmeasuredverdict rule files7
The 25 rule files by confidence label. The first two segments are the 12 confirmed rules: 6 are scored and 6 are not.

The chart shows the labels of the verdict rule files of the benchmark platform. Only a part of the confirmed rules change a score, and the rest of the files have a weaker label.

failure modes

problemcausecorrection
A correct fix makes real pages fail.The test input is not the production shape.Write the test in the exact production shape.
Errors with a terminal class are tried again.Two parts hold their own copy of the list.Use one exported constant for both parts.
A speed change alters verdicts.A rule with only negative conditions passes on an incomplete page.Stop early only for a rule with a positive condition, and hold the gate in place with a test.
Checks stay green when the guard is broken.The assertions run over an empty set.Put a count floor first, and add a meta-test.
A rule passes for each visitor and still scores.Nothing ties the score to the label.Score only a confirmed rule, and confirm only a rule that can fail.
A new form takes the nearest path.The switch has a silent default arm.Fail loud in the default arm, and add a parity test against the registry.

check questions

  1. Production sends a rendered page with derived markers. A new test sends the same page as plain text. The test is green. What is wrong?

    1. Nothing, because the test is green.
    2. The test input is not the production shape, so the real input can still fail.
    3. The test must use a live page of the target.
    answer

    b. The test input is not the production shape, so the real input can still fail.

    A test in the exact production shape fails as production fails. A simpler input can pass while the real input fails.

  2. Two parts of the code must read the same list of terminal errors, and both are in one code base. Which correction keeps one source for the fact?

    1. One exported constant that both parts import.
    2. A comment in each copy that names the other copy.
    3. A second copy in the test data.
    answer

    a. One exported constant that both parts import.

    One constant makes drift impossible. A parity test is the correction when two copies are necessary.

  3. Explain why a new guard must show one time that it can fail.

    sample answer

    A guard that cannot fail gives no information. For example, an assertion over an empty set is true for each item, so the check stays green when the guard is broken. A deliberate break of the guard must make one or more tests red. Else no test protects the guard.

  4. You break a new guard one time, and you run the suite. No test is red. What does the record show?

    1. The guard is correct.
    2. The suite is complete.
    3. No test protects the guard, so you add a count floor or a test and check again.
    answer

    c. No test protects the guard, so you add a count floor or a test and check again.

    A count of zero red tests means that no test protects the guard. Add a count floor or a test, and make the mutation check again.

  5. A rule has the label speculative, and it changes a score. What does the structural gate give?

    1. A fault, because only a confirmed rule can score.
    2. A pass, because the rule has a label.
    3. A pass, because the rule can fail.
    answer

    a. A fault, because only a confirmed rule can score.

    The gate has two clauses. A rule that cannot fail cannot be confirmed, and a rule that is not confirmed cannot score.

exercise

exercise Do this task on paper. A team adds a rule for a new page form. Use these synthetic records of the change:

recordvalue
Failed inputA rendered page with derived markers
New test inputThe same page as plain text, with no derived markers
Nearest working caseA page of the old form, test green
Copies of the marker listOne in the rule code, one in the test data, no parity test
Mutation checkThe guard broken one time: 0 red tests
Label from the teamconfirmed, scores
  1. Find each step of the seven steps that the change does not meet.
  2. Write the correction for each such step.
  3. Write the correct label of the rule.
sample answer

The answer uses the six synthetic records of the task.

Step 3 fails, because the new test is plain text and not the production shape. The correction is a test with the rendered page and its derived markers. Step 6 fails, because the marker list has two copies and no parity test. The correction is one constant, or a parity test.

Step 7 fails, because the mutation check gave 0 red tests. No test protects the guard. The correction is a count floor, and a new mutation check with one or more red tests. Until then, the label is unmeasured, and the rule does not score.

sources

  1. Benchmark platform, code (my test system): the regressions and their corrections in general form, 2026-11 (not public).
  2. My model of the procedure to add one case and of the three causes of a regression, 2026-11 (not public).