Hmbown/CodeWhale · error

expected replacement text, got

Error message

expected replacement text, got {other:?}

What it means

Test-only panic in a_blind_route_gets_text_in_place_of_every_image: after stripping images for an unsupported route, messages[0].content[0] was not a ContentBlock::Text, meaning strip_images_when_unsupported did not replace the first image with the expected text fallback naming the model and /model command.

Solutions

  1. Make strip_images_when_unsupported replace each ImageUrl block with a Text block at the same position
  2. Verify the SupportState was actually Unsupported for the model passed
  3. Check notices produced during stripping for clues about skipped replacements
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/tui/src/image_attach/tests.rs:389 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e2efdd044f10a034. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/image_attach/tests.rs:389

    let stripped =
        strip_images_when_unsupported(&mut messages, SupportState::Unsupported, "deepseek-chat");

    assert_eq!(stripped, 1);
    assert!(
        !messages[0]
            .content
            .iter()
            .any(|block| matches!(block, ContentBlock::ImageUrl { .. })),
        "no image may survive to a route that cannot read one"
    );
    match &messages[0].content[0] {
        ContentBlock::Text { text, .. } => {
            assert!(text.contains("deepseek-chat"), "{text}");
            assert!(text.contains("/model"), "{text}");
            assert!(text.contains("omitted"), "{text}");
        }
        other => panic!("expected replacement text, got {other:?}"),
    }
}

#[test]
fn a_supported_or_unknown_route_keeps_its_images() {
    // Unknown is the common case: models.dev has no modality data for most
    // routes. Stripping there would make the feature dead on arrival for
    // self-hosted and custom providers.
    for vision in [SupportState::Supported, SupportState::Unknown] {
        let mut messages = vec![message_with_image("data:image/png;base64,QUJD")];

        let stripped = strip_images_when_unsupported(&mut messages, vision, "some-model");

        assert_eq!(stripped, 0, "{vision:?} must not strip");
        assert!(
            messages[0]
                .content
                .iter()

View on GitHub (pinned to 433685b202)