{
  "part": 16,
  "title": "Standalone transport-file checker (utilities/checkSneakernetFile)",
  "reset": "standard",
  "_comment": "Both steps use the deterministic filename 'ds1' rather than discovering it at runtime - compression is 'off' at this point in the catalogue (restored at Part 8.6), so the transport filename for a flat top-level dataset is exactly its configured 'dataset' key (see the Part 7.2c note on this same convention). A mini-cycle establishes an incremental base first - TESTING.md's own note warns that pointing --target at a full/base file's own source dataset fails FULL-STREAM CHECK with 'destination has snapshots'; only ds1's history on the source, via an established status-file resume point, avoids that.",
  "steps": [
    { "id": "16.1", "title": "Good file",
      "actions": [
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P16_1a" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 1, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "write_repeated_line", "path": "/storage/testing/src/ds1/p16pad.txt",
          "line": "padding to give checkSneakernetFile a file of meaningful size", "count": 200 },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P16_1b" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 1, "expect_exit": 0 },
        { "do": "run_utility", "script": "checkSneakernetFile", "code_dir": "{CODE}",
          "args": [ "--file", "{TRANSPORT}/datasets/ds1", "--key", "$TESTKEY", "--target", "storage/testing/src/ds1", "--debug" ],
          "capture": { "name": "LOG161" } }
      ],
      "assertions": [
        { "type": "regex_present", "var": "LOG161", "pattern": "HEADER CHECK: OK", "message": "header check passes" },
        { "type": "regex_present", "var": "LOG161", "pattern": "FULL-STREAM CHECK: OK", "message": "full-stream (zfs receive -nF) check passes" }
      ]
    },
    { "id": "16.2", "title": "Bad key, corrupted file, missing sidecar", "depends_on": ["16.1"],
      "actions": [
        { "do": "run_utility", "script": "checkSneakernetFile", "code_dir": "{CODE}",
          "args": [ "--file", "{TRANSPORT}/datasets/ds1", "--key", "0000000000000000000000000000000000000000000000000000000000000000" ],
          "capture": { "name": "LOG162A" } },
        { "do": "copy_file", "from": "{TRANSPORT}/datasets/ds1", "to": "{TMP}/corrupt162.bin" },
        { "do": "copy_file", "from": "{TRANSPORT}/datasets/ds1.IV", "to": "{TMP}/corrupt162.bin.IV" },
        { "do": "corrupt_file", "path": "{TMP}/corrupt162.bin", "offset": 4096, "length": 512 },
        { "do": "run_utility", "script": "checkSneakernetFile", "code_dir": "{CODE}",
          "args": [ "--file", "{TMP}/corrupt162.bin", "--key", "$TESTKEY" ],
          "capture": { "name": "LOG162B" } },
        { "do": "copy_file", "from": "{TRANSPORT}/datasets/ds1", "to": "{TMP}/noiv162.bin" },
        { "do": "run_utility", "script": "checkSneakernetFile", "code_dir": "{CODE}",
          "args": [ "--file", "{TMP}/noiv162.bin", "--key", "$TESTKEY" ],
          "capture": { "name": "LOG162C" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 }
      ],
      "assertions": [
        { "type": "regex_present", "var": "LOG162A", "pattern": "HEADER CHECK: FAILED", "message": "wrong key fails the header check" },
        { "type": "regex_present", "var": "LOG162B", "pattern": "HEADER CHECK: FAILED|FULL-STREAM CHECK: FAILED", "message": "the corrupted file fails a check" },
        { "type": "regex_present", "var": "LOG162C", "pattern": "(?i)cannot read companion IV file", "message": "the missing .IV sidecar fails immediately" }
      ]
    }
  ]
}
