Commit Graph

28 Commits

Author SHA1 Message Date
Kovid Goyal
9acc16cc44 Clarify that end of drop escape code discards queued requests 2026-04-26 22:34:30 +05:30
Kovid Goyal
cadaec5712 Cleanup previous PR 2026-04-23 12:51:27 +05:30
copilot-swe-agent[bot]
fd1e55dd81 Add tests for broken and non-broken symlinks in URI drop protocol
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/9be1623f-7a9a-451b-a0ed-695882c7c8f4

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-23 07:13:34 +00:00
Kovid Goyal
f3c8ce919d Refactor test code to make it less cluttered 2026-04-19 14:28:46 +05:30
Kovid Goyal
79bb660493 Remove unused code 2026-04-19 14:03:32 +05:30
Kovid Goyal
b4d07ddece DRYer 2026-04-19 13:54:13 +05:30
Kovid Goyal
dc9bf889a6 Fix chunking of t=k not handling metadata present only on first chunk 2026-04-19 12:52:00 +05:30
copilot-swe-agent[bot]
e8e2b31182 Fix memory safety issues, protocol bugs, and add tests for DnD implementation
Fixes:
- Memory leak: drag_free_remote_item now frees children array
- Memory leak: drag_free_offer now frees pending data
- Memory leak: toplevel_data_for_drag frees old URI string before replacement
- Protocol bug: drag_notify missing OSC prefix in escape code output
- Protocol bug: drag_notify missing colon separators between metadata keys
- Buffer overflow: add_payload symlink case ensures capacity for null terminator
- Integer overflow: expand_rgb_data uses size_t casts for multiplication
- Memory leak: realloc anti-pattern fixed in 7 locations (drop_register_window,
  drop_dispatch_data, drag_add_mimes, drag_add_pre_sent_data, drag_add_image,
  add_payload default case, queue_payload_to_child)
- UB: queue_payload_to_child guards memcpy with NULL source + 0 count

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/3c7e550c-e8e8-413e-a54b-87d61cb8e574

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-14 09:33:23 +00:00
copilot-swe-agent[bot]
519fd49ce6 Fix bugs in t=k remote drag implementation and add comprehensive tests
Bug fixes in dnd.c:
- mktempdir_in_cache: add missing 'return ans' after successful strdup
- mktempdir_in_cache (utils.py): use O_RDONLY instead of O_RDWR for directories
- remote_items allocation: use mi.num_uris instead of ds.num_mimes
- Off-by-one: uri_item_idx > changed to >= for bounds checks
- Off-by-one: entry_num > changed to >= for bounds checks
- populate_dir_entries: fix missing last entry after final null separator
- add_payload directory finalization: create directory on disk with mkdirat
- get_errno_name: add EFBIG, EISDIR, ENOSPC error codes

Test infrastructure:
- Add dnd_test_force_drag_dropped() to simulate DROPPED state
- Make notify_drag_data_ready() succeed in test mode

Comprehensive t=k tests added:
- Single file, empty file, single symlink transfer
- Chunked file transfer with m=1
- Single directory with children
- Directory with symlinks
- Multiple URIs
- Deep directory trees (breadth-first and depth-first, 3+ levels)
- Mixed file/dir/symlink at top level
- Completion signal
- Error handling (client errors, invalid state)
- DoS limits (REMOTE_DRAG_LIMIT, PRESENT_DATA_CAP)
- Invalid input (bad base64, too large chunks, invalid indices/handles)
- URI list with comments
- Multiple chunks for directory listing

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/9da0bff7-6a1a-490f-a4c5-8cb328e056ce

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-13 15:54:34 +00:00
Kovid Goyal
864ef70484 Have the client send machine id to terminal rather than vice versa
The terminal is the trusted by user party here.
2026-04-12 11:00:23 +05:30
Kovid Goyal
9ebe692bf7 Allow drop clients to use machine id as well 2026-04-12 09:27:16 +05:30
Kovid Goyal
df20d4aa7c Add machine id and stub for t=k transfers 2026-04-11 17:20:53 +05:30
copilot-swe-agent[bot]
b8cbb7f68d Address code review: use < 2 condition, fix docstring, assert first handle = 2
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/6973699c-a979-4d97-8213-1a4a501044a1

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-10 07:39:40 +00:00
copilot-swe-agent[bot]
afa63ccec7 Implement new drop protocol X/Y key handling from b466f8b
- dnd.c: drop_send_dir_listing now uses drop_append_request_keys (echoes
  all request keys including Y for sub-dirs) and emits :X=handle instead
  of :Y=handle:X=2.  Directory handles are now the X value itself.
- dnd.c: drop_alloc_dir_handle starts handle counter at 1 so first
  handle is 2, keeping 0 (absent) and 1 (symlink) reserved as per protocol.
- dnd.py: add is_dir_event() / dir_handle() helpers; update all tests to
  use int(X) > 1 as directory indicator and X as the handle value.
- dnd.py: rename test_Y_key_in_dir_listing_response to
  test_X_key_is_handle_in_dir_listing_response with updated assertions.
- dnd.py: test_uri_directory_transfer_tree expanded to verify unambiguous
  identification (Y=parent, x=entry echoed) at all three directory levels.

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/6973699c-a979-4d97-8213-1a4a501044a1

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-10 07:35:09 +00:00
copilot-swe-agent[bot]
0a8713972c Change drag offer error responses from t=R to t=E in dnd.c and dnd.py
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/b0dd4978-d0b4-42a3-81e0-51b5ce155db9

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 17:14:44 +00:00
copilot-swe-agent[bot]
0f47a23c36 Update DnD tests for new protocol: use x/y/Y disambiguation instead of request_id
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/cdeecb3c-8589-4622-8f6b-21b724e4d5fd

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 15:35:23 +00:00
copilot-swe-agent[bot]
4d2b63fce8 Revert to 1-based directory entry indexing in DnD protocol
- dnd.c: entry_num==0 closes handle; entry_num>=1 reads at entry_num-1
- parse-dnd-command.h: revert cell_y default to 0 (from {0} init)
- gen/apc_parsers.py: remove post_init for DnD parser
- docs/dnd-protocol.rst: update to say 1-based indexing
- tests: all .index() calls add +1, rename test_dir_entry_one_based_index

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/d4074aba-3aeb-4d2b-adc1-d6c6f2b539e7

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 11:52:31 +00:00
copilot-swe-agent[bot]
7e0e3eb6ac Fix os.makedirs to os.mkdir for single-level directory in test
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/d09883e5-f460-471d-9dcf-e64e7b96882f

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 11:38:49 +00:00
copilot-swe-agent[bot]
d548afc94a Implement DnD protocol changes for symlinks and directory handling
- Remove unique identifier (device:inode) from directory listings
- Change directory entry indexing from 1-based to 0-based
- Add symlink handling in directories: respond with t=r:X=1 and target
- Update parser to default cell_y to -1 for close handle detection
- Update and extend tests for all new behaviors

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/d09883e5-f460-471d-9dcf-e64e7b96882f

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 11:33:43 +00:00
copilot-swe-agent[bot]
4339deb647 Add comprehensive tests for request queue and request_id behavior
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/3a4975c2-8691-486b-8ff9-f8a2146b8756

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-09 03:20:41 +00:00
Kovid Goyal
47b5b2ea65 Prevent reading uri-list items for a drag and drop in same window 2026-04-09 06:38:58 +05:30
copilot-swe-agent[bot]
9cd8558cfd Address code review feedback: improve test names and docstrings
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/f9868553-29a2-48c4-85c2-b6b8f686dccc

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-08 15:47:31 +00:00
copilot-swe-agent[bot]
7d33569c1a Add comprehensive drag protocol tests and fix double-free bug in drag_free_built_data
- Add 37 new tests covering the drag source side of the DND protocol
- Test drag offer registration/unregistration (t=o, t=O)
- Test drag MIME type offering with various operations (copy/move/both)
- Test pre-sent data for valid/invalid indices, chunked data, multiple MIMEs
- Test image thumbnails: valid RGBA/RGB, invalid formats, dimensions, chunking
- Test drag start failures (no window, no offer, image size mismatches)
- Test drag cancellation from client (t=E:y=-1)
- Test offer replacement, cleanup, and error propagation
- Test client_id propagation for drag operations
- Test resource cleanup on window close during drag build
- Fix double-free in drag_free_built_data: set ds.items=NULL after free
- Add drag_free_offer to destroy_fake_window_contents for proper cleanup

Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/f9868553-29a2-48c4-85c2-b6b8f686dccc

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-08 15:43:37 +00:00
Kovid Goyal
03cf6f9348 Fix unclosed resource warning in test 2026-04-01 20:01:28 +05:30
Kovid Goyal
78f1607bf5 Cleanup previous PR 2026-04-01 19:52:40 +05:30
copilot-swe-agent[bot]
51fe3dc274 Implement DnD protocol: t=s URI file transfer and t=d directory listing with tests
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/a5aee38b-1746-4699-9dcc-2138f43cabe8

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-01 08:55:55 +00:00
Kovid Goyal
81d0e2dc8e Cleanup previous PR 2026-04-01 13:05:56 +05:30
copilot-swe-agent[bot]
02aec3fa3e Add DnD protocol test framework and tests
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/faa69cb9-991d-49f4-802b-263f4bb28ee9

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-01 07:22:47 +00:00