{
  "part": 14,
  "title": "Cleanup script mechanism",
  "reset": "standard",
  "steps": [
    { "id": "14.1", "title": "Scheduled cleanup script (helloWorld)",
      "_comment": "The test config already schedules helloWorld for every month (Step 0.5).",
      "actions": [
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P14_1" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 3, "expect_exit": 0 },
        { "do": "list_matching", "dir": "{TRANSPORT}/cleanUpScripts", "pattern": "^helloWorld$",
          "capture": { "name": "HELLO_ENC_141", "reduce": "count" } },
        { "do": "list_matching", "dir": "{TRANSPORT}/cleanUpScripts", "pattern": "^helloWorld\\.IV$",
          "capture": { "name": "HELLO_IV_141", "reduce": "count" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 3, "log": "part14_1_target", "expect_exit": 0,
          "capture": { "name": "LOG141_TARGET" } }
      ],
      "assertions": [
        { "type": "count_equals", "var": "HELLO_ENC_141", "n": 1, "message": "an encrypted copy of helloWorld appears on the transport drive" },
        { "type": "count_equals", "var": "HELLO_IV_141", "n": 1, "message": "its .IV file appears too" },
        { "type": "regex_present", "var": "LOG141_TARGET", "pattern": "(?i)\\bhello\\b", "message": "the target run's log shows helloWorld's output" },
        { "type": "regex_present", "var": "LOG141_TARGET", "pattern": "(?i)\\bworld\\b", "message": "at verbosity >= 2, 'world' also appears" },
        { "type": "regex_present", "var": "LOG141_TARGET", "pattern": "(?i)Cleanup scripts completed with errors:\\s*\\nThis is a test error message", "message": "the deliberate test error message appears, correctly reported as a cleanup-script error (expected - helloWorld's own self-test)" }
      ]
    },
    { "id": "14.2", "title": "One-shot cleanup script", "depends_on": ["14.1"],
      "actions": [
        { "do": "copy_file", "from": "{CODE}/sneakernet/cleanupScripts/helloWorld", "to": "{ONESHOT}/helloWorld" },
        { "do": "list_matching", "dir": "{ONESHOT}", "pattern": "^helloWorld$",
          "capture": { "name": "ONESHOT_BEFORE_142", "reduce": "count" } },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 2, "log": "part14_2", "expect_exit": 0,
          "capture": { "name": "LOG142" } },
        { "do": "list_matching", "dir": "{ONESHOT}", "pattern": "^helloWorld$",
          "capture": { "name": "ONESHOT_AFTER_142", "reduce": "count" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 }
      ],
      "assertions": [
        { "type": "count_equals", "var": "ONESHOT_BEFORE_142", "n": 1, "message": "the copy is staged in oneshot/ before the run" },
        { "type": "count_equals", "var": "ONESHOT_AFTER_142", "n": 0, "message": "the copy disappears from oneshot/ after the source run - deleted after successful shipping, a one-shot only ships once" },
        { "type": "regex_present", "var": "LOG142", "pattern": "(?i)one-shot", "message": "the log mentions removing it as a one-shot" }
      ]
    }
  ]
}
