# Test Case: LZ4 ztailpacking Edge Cases

**Test ID**: TC092-ztailpacking-edge  

**G5 fixture contract**: Use [G5-MANUAL-SETUP.md](G5-MANUAL-SETUP.md).
Its generated paths, source comparisons, structured corruption offsets, and
cleanup rules supersede placeholder examples in this file.
**Category**: Compression  
**Priority**: Medium  
**Regression**: None

## Objective
Verify correct handling of edge cases in ztailpacking (compressed tail packing) feature.

## Preconditions
- Generated image: `images/lz4-ztail.erofs`
- Test files:
  - `/exact-pcluster.dat` (4096-byte non-tail control)
  - `/one-byte-tail.dat` (4097-byte logical boundary case)
  - `/max-tail.dat` (8191-byte logical boundary case)
  - `/zero-tail.dat` (empty-file control)
- `/inline.dat` is independently proven by the manifest to have
  `Z_EROFS_ADVISE_INLINE_PCLUSTER` and nonzero `h_idata_size`. The four edge
  controls must not be described as ztailpacked unless their own map headers
  prove it.
- Mount point: `/mnt/test`

## Test Steps
1. Mount the image:
   ```
   mount -t erofs /dev/md0 /mnt/test
   ```

2. Read file with exact pcluster size (no tail):
   ```
   cat /mnt/test/files/exact-pcluster.dat > /tmp/out1
   sha256sum /tmp/out1
   ```

3. Read file with minimal tail (1 byte):
   ```
   cat /mnt/test/files/one-byte-tail.dat > /tmp/out2
   tail -c 1 /tmp/out2 | od -A n -t x1
   ```

4. Read file with maximum tail size:
   ```
   cat /mnt/test/files/max-tail.dat > /tmp/out3
   stat -f %z /tmp/out3
   ```

5. Read file with zero-length tail:
   ```
   cat /mnt/test/files/zero-tail.dat > /tmp/out4
   ```

## Expected Results
- Step 2: File without tail read correctly
- Steps 2-5: Every exact logical size, full SHA256, and byte comparison matches
  its source file

## Verification Method
- Verify all tail size edge cases handled
- Confirm boundary conditions don't cause errors
- Test tail packing storage limits enforced correctly
- Verify data integrity for all edge cases

## Cleanup
```
umount /mnt/test
mdconfig -d -u "${unit#md}"
rm /tmp/out*
```

## Notes
- Tail size limits depend on inline storage capacity
- Zero-length tail is valid edge case
- Exact pcluster alignment means no tail needed
- Related tests: TC091 (basic ztailpacking)
