{
  "part": 12,
  "title": "Durable status-file anchor (long-TTL retention)",
  "reset": "standard",
  "_comment": "isLongRetentionSnapshot (ZFS_Utils.pm) requires a snapshot name ending '--<N><d|w|m|y>' where N*daysPerUnit >= 90 - '--3m' (90 days) and '--1y' (365 days) both qualify, matching TESTING.md's own examples.",
  "steps": [
    { "id": "12.1", "title": "Confirm the anchor gets recorded",
      "actions": [
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P12_1_anchor--3m" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P12_1_newest" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 4, "log": "part12_1", "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/sneakernet_target.status",
          "capture": { "name": "STATUS_121", "select": "^(storage/testing/dst/ds1\\@\\S+)$", "reduce": "count" } }
      ],
      "assertions": [
        { "type": "count_equals", "var": "STATUS_121", "n": 2, "message": "two lines for ds1 - the newest-sent snapshot and the --3m snapshot recorded separately as a long-retention anchor" }
      ]
    },
    { "id": "12.2", "title": "No duplicate line when the newest snapshot is itself long-retention", "depends_on": ["12.1"],
      "actions": [
        { "do": "zfs_destroy", "dataset": "{DST}/ds1", "recursive": 1, "missing_ok": 1 },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^sneakernet_target\\.status(\\.[0-9_.-]+)?$" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P12_2_only--1y" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 1, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "read_file", "path": "{SN}/sneakernet_target.status",
          "capture": { "name": "STATUS_122", "select": "^(storage/testing/dst/ds1\\@\\S+)$", "reduce": "count" } }
      ],
      "assertions": [
        { "type": "count_equals", "var": "STATUS_122", "n": 1, "message": "exactly one line - no duplicate when the anchor and the primary resume point are the same snapshot" }
      ]
    },
    { "id": "12.3", "title": "The anchor survives a gap and avoids the fallback guesswork entirely", "depends_on": ["12.2"],
      "_comment": "findCommonBaseSnapshot's date filter runs on EVERY candidate, including a recorded long-retention anchor - parseSnapshotDateTime must find a YYYY-MM-DD substring in its name or it never enters the candidate list at all, confirmed status-file recording notwithstanding. The anchor therefore needs both a real date (now_suffix, inserted before the suffix) AND its '--3m' long-retention tail (isLongRetentionSnapshot requires that literally at the end of the name). S2/S3 only need the date.",
      "actions": [
        { "do": "zfs_destroy", "dataset": "{DST}/ds1", "recursive": 1, "missing_ok": 1 },
        { "do": "rm_matching", "dir": "{SN}", "pattern": "^sneakernet_target\\.status(\\.[0-9_.-]+)?$" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "now_suffix", "store_as": "SUFA_123" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@P12_3_anchor_$SUFA_123--3m" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 1, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "sleep", "seconds": 1 },
        { "do": "now_suffix", "store_as": "SUFB_123" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@S2_$SUFB_123" },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 1, "expect_exit": 0 },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 },
        { "do": "sleep", "seconds": 1 },
        { "do": "now_suffix", "store_as": "SUFC_123" },
        { "do": "zfs_snapshot", "dataset": "{SRC}/ds1@S3_$SUFC_123" },
        { "do": "zfs_destroy", "dataset": "{SRC}/ds1@S2_$SUFB_123", "recursive": 0, "missing_ok": 0 },
        { "do": "empty_dir", "path": "{TRANSPORT}" },
        { "do": "run_sneakernet", "servername": "test-source", "verbosity": 4, "log": "part12_3", "expect_exit": 0,
          "capture": { "name": "LOG123" } },
        { "do": "run_sneakernet", "servername": "test-target", "verbosity": 1, "expect_exit": 0 }
      ],
      "assertions": [
        { "type": "regex_present", "var": "LOG123", "pattern": "(?i)confirmed present in the recorded target snapshot state", "message": "resolution is confirmed, not inferred - the anchor recorded automatically two runs earlier makes this possible with no manual file editing" },
        { "type": "regex_absent", "var": "LOG123", "pattern": "(?i)inferred substitute base", "message": "no inferred-fallback guesswork was needed" }
      ]
    }
  ]
}
