"""Wheeze-only consistency anchors the wheeze logit and leaves crackle logits out of the MSE."""

import torch

from method.feedback_decoder import consistency_loss, wheeze_consistency_loss


def test_wheeze_consistency_loss_ignores_crackle_logits():
    logit_c1 = torch.full((3, 4), 3.0)
    logit_w1 = torch.full((3, 4), -3.0)
    logit_c2 = torch.zeros(3, 4)
    logit_w2 = torch.zeros(3, 4)
    base = wheeze_consistency_loss(logit_c1, logit_w1, logit_c2, logit_w2)

    # Sign flip keeps pass-1 crackle entropy, so the shared weight stays put.
    # The added shift would have changed the crackle half of the default MSE.
    crackle_changed = wheeze_consistency_loss(
        -logit_c1, logit_w1, logit_c2 + 5.0, logit_w2)
    wheeze_changed = wheeze_consistency_loss(
        logit_c1, logit_w1, logit_c2, logit_w2 + 5.0)

    assert torch.allclose(base, crackle_changed)
    assert not torch.allclose(base, wheeze_changed)

    full = consistency_loss(logit_c1, logit_w1, logit_c2, logit_w2)
    full_crackle = consistency_loss(logit_c1, logit_w1, logit_c2 + 5.0, logit_w2)
    assert not torch.allclose(full, full_crackle)
