{
  "part": 18,
  "title": "maxDelta behavior",
  "reset": "standard",
  "_comment": "The baseline (Step 0.5, Parts 1-17) keeps ds1's maxDelta COMMENTED OUT per TESTING_automation.md 9.2's deliberate deviation - this Part is where it is deliberately exercised. Step 18.1 uncomments it (a plain 'set' on a commented-only path is refused by YAMLPatch); Step 18.3 DELETEs the key entirely (not just a large value) to test the key-absent code path specifically, then 18.3-cleanup re-inserts it since it no longer exists to 'set'.",
  "steps": [
    { "id": "18.1", "title": "Trigger the abort deliberately, check message wording",
      "config": { "mutations": [
        { "op": "uncomment", "path": "datasets.ds1.maxDelta" },
        { "op": "set", "path": "datasets.ds1.maxDelta", "value": "0.01" }
      ], "restore": "none" },
      "actions": [
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^history\\.tsv$" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_1a" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "write_repeated_line", "path": "/storage/testing/src/ds1/p18pad.txt",
          "line": "padding data to grow the estimated stream size for this test", "count": 200000 },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_1b" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "log": "part18_1", "expect_exit": "any",
          "capture": { "name": "LOG181" } }
      ],
      "assertions": [
        { "type": "regex_present", "var": "LOG181", "pattern": "(?i)FATAL ERROR", "message": "the run aborts" },
        { "type": "regex_present", "var": "LOG181", "pattern": "(?i)exceeds its running average of the last \\d+ run", "message": "message names the dataset and states it exceeds its running average of the last N runs" },
        { "type": "regex_present", "var": "LOG181", "pattern": "maxDelta \\(0\\.01 = 1%\\)", "message": "maxDelta is shown as a percentage, not a confusing byte-count comparison" },
        { "type": "regex_present", "var": "LOG181", "pattern": "(?i)degraded to a full send", "message": "message suggests checking for a full-send degradation" }
      ]
    },
    { "id": "18.2", "title": "Normal growth within bounds does NOT abort", "depends_on": ["18.1"],
      "config": { "mutations": [ { "op": "set", "path": "datasets.ds1.maxDelta", "value": "0.9" } ], "restore": "none" },
      "actions": [
        { "do": "zfs_destroy", "dataset": "{DST}/ds1", "recursive": 1, "missing_ok": 1 },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^sneakernet_target\\.status(\\.[0-9_.-]+)?$" },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^history\\.tsv$" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "rm_matching", "dir": "/storage/testing/src/ds1", "pattern": "^p18pad\\.txt$" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_2a" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/history.tsv", "capture": { "name": "HIST_182A", "select": "(ds1)", "reduce": "count" } },
        { "do": "write_repeated_line", "path": "/storage/testing/src/ds1/p18pad2.txt", "line": "small amount of new data", "count": 50 },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_2b" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "log": "part18_2", "expect_exit": 0,
          "capture": { "name": "LOG182" } },
        { "do": "list_matching", "dir": "{TRANSPORT}", "pattern": "^serial\\.txt$", "capture": { "name": "SERIAL_182", "reduce": "count" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/history.tsv", "capture": { "name": "HIST_182B", "select": "(ds1)", "reduce": "count" } }
      ],
      "assertions": [
        { "type": "regex_absent", "var": "LOG182", "pattern": "(?i)FATAL ERROR|exceeds its running average", "message": "the second run completes normally - no abort" },
        { "type": "count_equals", "var": "HIST_182A", "n": 1, "message": "one history.tsv line for ds1 after the first run" },
        { "type": "count_equals", "var": "HIST_182B", "n": 2, "message": "two lines after the second run (one per run) instead of one" },
        { "type": "count_equals", "var": "SERIAL_182", "n": 1, "message": "serial.txt is created" }
      ]
    },
    { "id": "18.3", "title": "maxDelta unset disables the check (and history tracking) entirely", "depends_on": ["18.2"],
      "config": { "mutations": [ { "op": "delete", "path": "datasets.ds1.maxDelta" } ], "restore": "none" },
      "actions": [
        { "do": "zfs_destroy", "dataset": "{DST}/ds1", "recursive": 1, "missing_ok": 1 },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^sneakernet_target\\.status(\\.[0-9_.-]+)?$" },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^history\\.tsv$" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "rm_matching", "dir": "/storage/testing/src/ds1", "pattern": "^p18pad2\\.txt$" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_3a" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/history.tsv", "capture": { "name": "HIST_183A", "select": "(ds1)", "reduce": "count" } },
        { "do": "write_repeated_line", "path": "/storage/testing/src/ds1/p18pad.txt",
          "line": "padding data to grow the estimated stream size for this test", "count": 200000 },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P18_3b" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "log": "part18_3", "expect_exit": 0,
          "capture": { "name": "LOG183" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/history.tsv", "capture": { "name": "HIST_183B", "select": "(ds1)", "reduce": "count" } }
      ],
      "assertions": [
        { "type": "regex_absent", "var": "LOG183", "pattern": "(?i)FATAL ERROR", "message": "both runs complete normally regardless of the large size jump" },
        { "type": "count_equals", "var": "HIST_183A", "n": 0, "message": "history.tsv has no ds1 entries after the first run" },
        { "type": "count_equals", "var": "HIST_183B", "n": 0, "message": "still zero after the second (large-jump) run - maxDelta unset disables history tracking entirely, not just the check" }
      ]
    },
    { "id": "18.3-cleanup", "title": "Restore maxDelta: 0.9 and remove pad files", "depends_on": ["18.3"],
      "config": { "restore": "none", "mutations": [
        { "op": "insert_kv", "parent": "datasets.ds1", "key": "maxDelta", "value": "0.9" }
      ] },
      "actions": [
        { "do": "rm_matching", "dir": "/storage/testing/src/ds1", "pattern": "^p18pad\\.txt$" },
        { "do": "rm_matching", "dir": "/storage/testing/src/ds1", "pattern": "^p18pad2\\.txt$" }
      ]
    }
  ]
}
