buzz icon indicating copy to clipboard operation
buzz copied to clipboard

fix(cli): preserve attachments on buzz messages edit (#3022)

Open maikunari opened this issue 4 months ago • 1 comments

Problem

buzz messages edit silently deletes a message's attachments. build_edit (crates/buzz-sdk/src/builders.rs) emits only h + e tags — never imeta. The desktop render/cache overlay (desktop/src/features/messages/lib/applyEditTagOverlay.mjs) treats an edit carrying zero imeta tags as "the attachment set is now empty" — this is intentional (it's how deliberate attachment removal works), and is pinned by a test. Because the CLI never carried imeta forward, an agent fixing a typo in its own message deletes the screenshot it attached. buzz exits 0, nothing warns, and there's no flag to restore them.

Desktop was fixed for its own builder in #755; the CLI was never brought along. Closes #3022.

Fix

Fixed at the builder + CLI, not the overlay (the overlay's replace-on-imeta semantics is correct and load-bearing for desktop removal).

  • build_edit gains a media_tags: &[Vec<String>] parameter and emits imeta via the same imeta_tags() helper build_message already uses (same validation path).
  • buzz messages edit gains --file and --no-media:
    • (neither flag — default) carry-forward: fetch the target event and preserve its existing imeta tags, so today's invocations stop losing attachments.
    • --file <path> (repeatable): upload and replace attachments — identical upload path to buzz messages send (this is why the flag is --file, matching send, not --media).
    • --no-media: clear all attachments (explicit). Mutually exclusive with --file (enforced by clap).

The single relay fetch already performed to resolve the channel id is reused to read the carry-forward imeta — no extra round-trip. A failed/absent fetch aborts before signing, so an attachment-wiping edit can never be published on error.

Tests

  • buzz-sdk: edit_with_media (imeta emitted), edit_without_media_has_no_imeta (clear contract), edit_rejects_malformed_media_tag.
  • buzz-cli: extract_imeta_tags_returns_only_imeta / _empty_when_none / _handles_missing_tags (only imeta carried, full vectors preserved), and a clap test that --file + --no-media is rejected.
cargo test -p buzz-sdk     # 238 passed
cargo test -p buzz-cli     # 254 passed
cargo fmt --all -- --check # clean
cargo clippy -p buzz-sdk -p buzz-cli -- -D warnings  # clean

Known follow-ups (non-blocking)

  • No automated end-to-end test for the full fetch→extract→build path — the unit tests cover the pieces; the full flow is covered by the manual runbook in crates/buzz-cli/TESTING.md (no mocked-relay harness exists for CLI command handlers). Verified manually.
  • Inline ![image](url) markdown in the old body is not carried forward — --content replaces the body wholesale. The imeta attachment (what desktop renders) is preserved; only inline markdown in a plaintext client would be affected. Left as-is to keep the change surgical.

maikunari avatar Jul 27 '26 03:07 maikunari

Rebased onto latest main (f53bbd115).

  • Conflict was only in crates/buzz-cli/src/lib.rs (new projects clap tests on main vs our edit-flag clap test) — kept both.
  • Local verification on rebased tip: cargo test -p buzz-sdk (257 passed) and cargo test -p buzz-cli (325 passed).
  • Branch is now up to date / should be mergeable pending review.

vs #3062: same issue (#3022). This PR stays the surgical path — fix at build_edit + CLI carry-forward default, with explicit --file (replace) and --no-media (clear). Happy to close as duplicate if maintainers prefer #3062's approach once one lands.

Re-requesting review from @block/buzz-oss-team.

maikunari avatar Aug 07 '26 09:08 maikunari