# - flush-hash: write to disk
# - Assert: beeshash.dat exists and is non-empty
#
-# Phase 10: Nested extent-tree readback
-# - Build a block-ID file
-# - Construct SubExtent(SuperExtent(...)) trees in the REPL
-# - Verify readback returns blocks in the expected remapped order
+# Phase 10: SubExtent of a SuperExtent
+# - Build SuperExtent { right, left } from two slices of the block-ID file
+# - A SubExtent inside one part reads that part's blocks
+# - A SubExtent across parts is rejected
#
# Phase 11: Mixed materialized-source readback
# - Build a tree containing direct btrfs slices, a tempfile-backed copy,
EXPECT_COMP_COPY_HEX=$(it_hex_range "$COMP_SUBVOL/zstd-small" 1024 1024)
EXPECT_COPY_HEX="${EXPECT_SHARED_HEX}${EXPECT_TAIL_HEX}"
SIZE_COPY_BYTES=$(( 4096 + SIZE_TAIL_WINDOW ))
-EXPECT_TREE_NESTED_HEX=$(it_hex_concat_ranges "$RW_SUBVOL/blockids" 24576 8192 4096 8192)
+EXPECT_TREE_SUB_RIGHT_HEX=$(it_hex_concat_ranges "$RW_SUBVOL/blockids" 24576 8192)
+EXPECT_TREE_SUB_LEFT_HEX=$(it_hex_concat_ranges "$RW_SUBVOL/blockids" 8192 8192)
EXPECT_TREE_MIXED_HEX_HEAD=$(it_hex_concat_ranges "$RW_SUBVOL/blockids" 0 8192 16384 8192)
EXPECT_TREE_MIXED_HEX_TAIL=$(it_hex_concat_ranges "$RW_SUBVOL/blockids" 12288 4096)
EXPECT_TREE_HOLE_HEX=$(python3 - <<'PY'
it_assert_remote_file "$BEESHOME/beeshash.dat"
it_assert_remote_file_nonempty "$BEESHOME/beeshash.dat"
-# ── Phase 10: nested extent-tree readback (DISABLED) ──────────────────────────
+# ── Phase 10: SubExtent of a SuperExtent ───────────────────────────────────────
#
-# Exercises tree-subextent composed on top of tree-superextent (sub-of-super).
-# BeesSubExtentNode's constructor rejects super children (bees-extent-tree.cc
-# around 1764) because its bytenr() delegates to the child and a super has no
-# single bytenr. Lifting that constraint requires design work on
-# BeesSubExtentNode (representative-part bytenr, or ctor-time flattening into
-# per-part sub slices). Until that lands, phase10 cannot pass; leaving it
-# enabled makes every release run report a failure that is actually a
-# pending-feature marker.
-#
-# To re-enable: change `if false` to `if true` after the sub-of-super
-# constraint is relaxed. Expected passing output is preserved below.
+# t_join = SuperExtent { t_right at [0, 12288), t_left at [12288, 24576) }.
+# A SubExtent inside one part narrows that part's child, so it has the
+# part's bytenr. A SubExtent across parts has no btrfs counterpart and is
+# rejected; that case needs a TempExtent or MaterializedExtent (phase 11).
-if false; then
-echo "[phase10] nested extent-tree readback"
+echo "[phase10] subextent within one part of a superextent"
it_repl "$BEESHOME" <<REPL
set paths.home $BEESHOME
open-root $TEST_MOUNT
tree-subextent t_left t_base 4096 16384
tree-subextent t_right t_base 20480 32768
tree-superextent t_join t_right 0 12288 0 12288 t_left 0 12288 12288 24576
-tree-subextent t_nested t_join 4096 20480
-tree-read t_nested 0 16384
-tree-blocks t_nested 0 16384
+tree-subextent t_in_right t_join 4096 12288
+tree-read t_in_right 0 8192
+tree-subextent t_in_left t_join 16384 24576
+tree-read t_in_left 0 8192
+tree-blocks t_in_left 0 8192
quit
REPL
-it_assert_repl_line "phase10: nested tree reads four blocks" \
- "value bytes 16384"
-it_assert_repl_line "phase10: nested tree remaps blocks in expected order" \
- "value data 0 $EXPECT_TREE_NESTED_HEX"
-it_assert_repl_line "phase10: nested tree reports four logical blocks" \
- "value blocks 4"
-it_assert_repl_line "phase10: nested tree sees four data blocks" \
- "value data_blocks 4"
-it_assert_repl_line "phase10: nested tree sees four hashes" \
- "value hashed_blocks 4"
-it_assert_repl_line "phase10: nested tree stays insertable" \
+it_assert_repl_line "phase10: sub within one part reads two blocks" \
+ "value bytes 8192"
+it_assert_repl_line "phase10: sub within the first part reads its blocks" \
+ "value data 0 $EXPECT_TREE_SUB_RIGHT_HEX"
+it_assert_repl_line "phase10: sub within the second part reads its blocks" \
+ "value data 0 $EXPECT_TREE_SUB_LEFT_HEX"
+it_assert_repl_line "phase10: sub within one part reports two logical blocks" \
+ "value blocks 2"
+it_assert_repl_line "phase10: sub within one part sees two data blocks" \
+ "value data_blocks 2"
+it_assert_repl_line "phase10: sub within one part sees two hashes" \
+ "value hashed_blocks 2"
+it_assert_repl_line "phase10: sub within one part stays insertable" \
"value insertable yes"
it_assert_repl_log_empty "phase10: repl stderr log is empty"
-fi
+
+echo "[phase10] subextent across superextent parts is rejected"
+it_repl "$BEESHOME" <<REPL
+set paths.home $BEESHOME
+open-root $TEST_MOUNT
+apply-config
+
+extent-create e_blocks $BYTENR_BLOCKIDS
+tree-from-extent t_base e_blocks
+tree-subextent t_left t_base 4096 16384
+tree-subextent t_right t_base 20480 32768
+tree-superextent t_join t_right 0 12288 0 12288 t_left 0 12288 12288 24576
+tree-subextent t_cross t_join 4096 20480
+
+quit
+REPL
+
+it_assert_repl_out_grep "phase10: sub across parts is rejected" \
+ "spans more than one part of a SuperExtent"
# ── Phase 11: mixed materialized-source readback ─────────────────────────────