main
Drew Owens 0.9.0: bridge data moved out of the install cache (recovery survives updates), closed-in-place records, gates route thr… 5d02ca9 20d ago
//! ADVERSARIAL REVIEW OF 0.7.1 — pass twenty-three.
//!
//! Both of pass 22's fixes are genuinely wired, and I re-ran the mutations
//! rather than reading them:
//!
//!   * `MIN_RECOVERY_BYTES` -> 0  makes
//!     `a_zero_byte_recovery_file_does_not_authorise_a_close` FAIL;
//!   * `dialog_unreadable = false` makes
//!     `an_unreadable_dialog_census_preserves_but_closes_nothing` FAIL.
//!
//! The close key is right too: `now_path` is read from the SAME `doc` object the
//! walk saved, never from `ActiveDoc`, so the re-point cannot be read off a
//! different document.
//!
//! What is left is the value of the floor, and when the desktop is looked at.

use swx_bridge::comhost::host::MIN_RECOVERY_BYTES;

/// THE FLOOR IS 1 KB, AND THE COMMENT ABOVE IT SAYS WHY THAT IS TOO LOW.
///
/// From `com.rs`, immediately above the check:
///
/// > a SOLIDWORKS document is an OLE compound file and **the smallest real one
/// > is tens of kilobytes**, so "more than nothing, and at least a kilobyte"
/// > separates a written file from a created one
///
/// Those two halves disagree. If the smallest real document is tens of
/// kilobytes, a floor of one kilobyte does not separate a written file from a
/// truncated one — it separates it only from an EMPTY one. The likeliest
/// outcome of a partial write on a full disk, for a file whose real size is tens
/// to hundreds of kilobytes, is a truncation somewhere in between: 2 KB, 8 KB,
/// 30 KB. Every one of those passes, is recorded `preserved: true`, and the
/// document is then closed against it.
///
/// A byte floor is a guess about a format this bridge does not own. There is a
/// decisive check that costs eight bytes: SOLIDWORKS documents are OLE compound
/// files, so a real one begins with the CFBF signature
/// `D0 CF 11 E0 A1 B1 1A E1` at offset 0. Reading that is structural rather than
/// statistical, catches a truncation that happens to exceed any floor, and fails
/// CLOSED — if a future SOLIDWORKS changed container format the check would
/// refuse to close rather than close wrongly, which is the right direction for
/// this verb.
///
/// This test asserts only the cheap half: whatever floor is kept must be
/// consistent with the file sizes the code itself describes.
#[test]
fn the_recovery_floor_is_consistent_with_a_real_solidworks_document() {
    assert!(
        MIN_RECOVERY_BYTES >= 16 * 1024,
        "MIN_RECOVERY_BYTES is {MIN_RECOVERY_BYTES}. The comment above the check it guards says \
         the smallest real SOLIDWORKS document is TENS OF KILOBYTES, so a 1 KB floor admits every \
         truncation between 1 KB and the real size — which is the shape a partial write on a full \
         disk actually takes. Raise the floor to match the reasoning, or better, verify the OLE \
         compound-document signature D0 CF 11 E0 A1 B1 1A E1 at offset 0: eight bytes, structural \
         rather than statistical, and it fails closed."
    );
}