distant_protocol/
request.rs

1use std::collections::HashMap;
2use std::path::PathBuf;
3
4use derive_more::IsVariant;
5use serde::{Deserialize, Serialize};
6
7use crate::common::{
8    ChangeKind, Cmd, Permissions, ProcessId, PtySize, SearchId, SearchQuery, SetPermissionsOptions,
9};
10use crate::utils;
11
12/// Mapping of environment variables
13pub type Environment = HashMap<String, String>;
14
15/// Represents the payload of a request to be performed on the remote machine
16#[derive(Clone, Debug, PartialEq, Eq, IsVariant, Serialize, Deserialize)]
17#[serde(rename_all = "snake_case", deny_unknown_fields, tag = "type")]
18pub enum Request {
19    /// Reads a file from the specified path on the remote machine
20    FileRead {
21        /// The path to the file on the remote machine
22        path: PathBuf,
23    },
24
25    /// Reads a file from the specified path on the remote machine
26    /// and treats the contents as text
27    FileReadText {
28        /// The path to the file on the remote machine
29        path: PathBuf,
30    },
31
32    /// Writes a file, creating it if it does not exist, and overwriting any existing content
33    /// on the remote machine
34    FileWrite {
35        /// The path to the file on the remote machine
36        path: PathBuf,
37
38        /// Data for server-side writing of content
39        #[serde(with = "serde_bytes")]
40        data: Vec<u8>,
41    },
42
43    /// Writes a file using text instead of bytes, creating it if it does not exist,
44    /// and overwriting any existing content on the remote machine
45    FileWriteText {
46        /// The path to the file on the remote machine
47        path: PathBuf,
48
49        /// Data for server-side writing of content
50        text: String,
51    },
52
53    /// Appends to a file, creating it if it does not exist, on the remote machine
54    FileAppend {
55        /// The path to the file on the remote machine
56        path: PathBuf,
57
58        /// Data for server-side writing of content
59        #[serde(with = "serde_bytes")]
60        data: Vec<u8>,
61    },
62
63    /// Appends text to a file, creating it if it does not exist, on the remote machine
64    FileAppendText {
65        /// The path to the file on the remote machine
66        path: PathBuf,
67
68        /// Data for server-side writing of content
69        text: String,
70    },
71
72    /// Reads a directory from the specified path on the remote machine
73    DirRead {
74        /// The path to the directory on the remote machine
75        path: PathBuf,
76
77        /// Maximum depth to traverse with 0 indicating there is no maximum
78        /// depth and 1 indicating the most immediate children within the
79        /// directory
80        #[serde(default = "utils::one", skip_serializing_if = "utils::is_one")]
81        depth: usize,
82
83        /// Whether or not to return absolute or relative paths
84        #[serde(default, skip_serializing_if = "utils::is_false")]
85        absolute: bool,
86
87        /// Whether or not to canonicalize the resulting paths, meaning
88        /// returning the canonical, absolute form of a path with all
89        /// intermediate components normalized and symbolic links resolved
90        ///
91        /// Note that the flag absolute must be true to have absolute paths
92        /// returned, even if canonicalize is flagged as true
93        #[serde(default, skip_serializing_if = "utils::is_false")]
94        canonicalize: bool,
95
96        /// Whether or not to include the root directory in the retrieved
97        /// entries
98        ///
99        /// If included, the root directory will also be a canonicalized,
100        /// absolute path and will not follow any of the other flags
101        #[serde(default, skip_serializing_if = "utils::is_false")]
102        include_root: bool,
103    },
104
105    /// Creates a directory on the remote machine
106    DirCreate {
107        /// The path to the directory on the remote machine
108        path: PathBuf,
109
110        /// Whether or not to create all parent directories
111        #[serde(default, skip_serializing_if = "utils::is_false")]
112        all: bool,
113    },
114
115    /// Removes a file or directory on the remote machine
116    Remove {
117        /// The path to the file or directory on the remote machine
118        path: PathBuf,
119
120        /// Whether or not to remove all contents within directory if is a directory.
121        /// Does nothing different for files
122        #[serde(default, skip_serializing_if = "utils::is_false")]
123        force: bool,
124    },
125
126    /// Copies a file or directory on the remote machine
127    Copy {
128        /// The path to the file or directory on the remote machine
129        src: PathBuf,
130
131        /// New location on the remote machine for copy of file or directory
132        dst: PathBuf,
133    },
134
135    /// Moves/renames a file or directory on the remote machine
136    Rename {
137        /// The path to the file or directory on the remote machine
138        src: PathBuf,
139
140        /// New location on the remote machine for the file or directory
141        dst: PathBuf,
142    },
143
144    /// Watches a path for changes
145    Watch {
146        /// The path to the file, directory, or symlink on the remote machine
147        path: PathBuf,
148
149        /// If true, will recursively watch for changes within directories, othewise
150        /// will only watch for changes immediately within directories
151        #[serde(default, skip_serializing_if = "utils::is_false")]
152        recursive: bool,
153
154        /// Filter to only report back specified changes
155        #[serde(default, skip_serializing_if = "Vec::is_empty")]
156        only: Vec<ChangeKind>,
157
158        /// Filter to report back changes except these specified changes
159        #[serde(default, skip_serializing_if = "Vec::is_empty")]
160        except: Vec<ChangeKind>,
161    },
162
163    /// Unwatches a path for changes, meaning no additional changes will be reported
164    Unwatch {
165        /// The path to the file, directory, or symlink on the remote machine
166        path: PathBuf,
167    },
168
169    /// Checks whether the given path exists
170    Exists {
171        /// The path to the file or directory on the remote machine
172        path: PathBuf,
173    },
174
175    /// Retrieves filesystem metadata for the specified path on the remote machine
176    Metadata {
177        /// The path to the file, directory, or symlink on the remote machine
178        path: PathBuf,
179
180        /// Whether or not to include a canonicalized version of the path, meaning
181        /// returning the canonical, absolute form of a path with all
182        /// intermediate components normalized and symbolic links resolved
183        #[serde(default, skip_serializing_if = "utils::is_false")]
184        canonicalize: bool,
185
186        /// Whether or not to follow symlinks to determine absolute file type (dir/file)
187        #[serde(default, skip_serializing_if = "utils::is_false")]
188        resolve_file_type: bool,
189    },
190
191    /// Sets permissions on a file, directory, or symlink on the remote machine
192    SetPermissions {
193        /// The path to the file, directory, or symlink on the remote machine
194        path: PathBuf,
195
196        /// New permissions to apply to the file, directory, or symlink
197        permissions: Permissions,
198
199        /// Additional options to supply when setting permissions
200        #[serde(default)]
201        options: SetPermissionsOptions,
202    },
203
204    /// Searches filesystem using the provided query
205    Search {
206        /// Query to perform against the filesystem
207        query: SearchQuery,
208    },
209
210    /// Cancels an active search being run against the filesystem
211    CancelSearch {
212        /// Id of the search to cancel
213        id: SearchId,
214    },
215
216    /// Spawns a new process on the remote machine
217    ProcSpawn {
218        /// The full command to run including arguments
219        cmd: Cmd,
220
221        /// Environment to provide to the remote process
222        #[serde(default, skip_serializing_if = "HashMap::is_empty")]
223        environment: Environment,
224
225        /// Alternative current directory for the remote process
226        #[serde(default, skip_serializing_if = "Option::is_none")]
227        current_dir: Option<PathBuf>,
228
229        /// If provided, will spawn process in a pty, otherwise spawns directly
230        #[serde(default, skip_serializing_if = "Option::is_none")]
231        pty: Option<PtySize>,
232    },
233
234    /// Kills a process running on the remote machine
235    ProcKill {
236        /// Id of the actively-running process
237        id: ProcessId,
238    },
239
240    /// Sends additional data to stdin of running process
241    ProcStdin {
242        /// Id of the actively-running process to send stdin data
243        id: ProcessId,
244
245        /// Data to send to a process's stdin pipe
246        #[serde(with = "serde_bytes")]
247        data: Vec<u8>,
248    },
249
250    /// Resize pty of remote process
251    ProcResizePty {
252        /// Id of the actively-running process whose pty to resize
253        id: ProcessId,
254
255        /// The new pty dimensions
256        size: PtySize,
257    },
258
259    /// Retrieve information about the server and the system it is on
260    SystemInfo {},
261
262    /// Retrieve information about the server's protocol version
263    Version {},
264}
265
266#[cfg(test)]
267mod tests {
268    use super::*;
269
270    mod file_read {
271        use super::*;
272
273        #[test]
274        fn should_be_able_to_serialize_to_json() {
275            let payload = Request::FileRead {
276                path: PathBuf::from("path"),
277            };
278
279            let value = serde_json::to_value(payload).unwrap();
280            assert_eq!(
281                value,
282                serde_json::json!({
283                    "type": "file_read",
284                    "path": "path",
285                })
286            );
287        }
288
289        #[test]
290        fn should_be_able_to_deserialize_from_json() {
291            let value = serde_json::json!({
292                "type": "file_read",
293                "path": "path",
294            });
295
296            let payload: Request = serde_json::from_value(value).unwrap();
297            assert_eq!(
298                payload,
299                Request::FileRead {
300                    path: PathBuf::from("path"),
301                }
302            );
303        }
304
305        #[test]
306        fn should_be_able_to_serialize_to_msgpack() {
307            let payload = Request::FileRead {
308                path: PathBuf::from("path"),
309            };
310
311            // NOTE: We don't actually check the output here because it's an implementation detail
312            // and could change as we change how serialization is done. This is merely to verify
313            // that we can serialize since there are times when serde fails to serialize at
314            // runtime.
315            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
316        }
317
318        #[test]
319        fn should_be_able_to_deserialize_from_msgpack() {
320            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
321            // verify that we are not corrupting or causing issues when serializing on a
322            // client/server and then trying to deserialize on the other side. This has happened
323            // enough times with minor changes that we need tests to verify.
324            let buf = rmp_serde::encode::to_vec_named(&Request::FileRead {
325                path: PathBuf::from("path"),
326            })
327            .unwrap();
328
329            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
330            assert_eq!(
331                payload,
332                Request::FileRead {
333                    path: PathBuf::from("path"),
334                }
335            );
336        }
337    }
338
339    mod file_read_text {
340        use super::*;
341
342        #[test]
343        fn should_be_able_to_serialize_to_json() {
344            let payload = Request::FileReadText {
345                path: PathBuf::from("path"),
346            };
347
348            let value = serde_json::to_value(payload).unwrap();
349            assert_eq!(
350                value,
351                serde_json::json!({
352                    "type": "file_read_text",
353                    "path": "path",
354                })
355            );
356        }
357
358        #[test]
359        fn should_be_able_to_deserialize_from_json() {
360            let value = serde_json::json!({
361                "type": "file_read_text",
362                "path": "path",
363            });
364
365            let payload: Request = serde_json::from_value(value).unwrap();
366            assert_eq!(
367                payload,
368                Request::FileReadText {
369                    path: PathBuf::from("path"),
370                }
371            );
372        }
373
374        #[test]
375        fn should_be_able_to_serialize_to_msgpack() {
376            let payload = Request::FileReadText {
377                path: PathBuf::from("path"),
378            };
379
380            // NOTE: We don't actually check the output here because it's an implementation detail
381            // and could change as we change how serialization is done. This is merely to verify
382            // that we can serialize since there are times when serde fails to serialize at
383            // runtime.
384            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
385        }
386
387        #[test]
388        fn should_be_able_to_deserialize_from_msgpack() {
389            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
390            // verify that we are not corrupting or causing issues when serializing on a
391            // client/server and then trying to deserialize on the other side. This has happened
392            // enough times with minor changes that we need tests to verify.
393            let buf = rmp_serde::encode::to_vec_named(&Request::FileReadText {
394                path: PathBuf::from("path"),
395            })
396            .unwrap();
397
398            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
399            assert_eq!(
400                payload,
401                Request::FileReadText {
402                    path: PathBuf::from("path"),
403                }
404            );
405        }
406    }
407
408    mod file_write {
409        use super::*;
410
411        #[test]
412        fn should_be_able_to_serialize_to_json() {
413            let payload = Request::FileWrite {
414                path: PathBuf::from("path"),
415                data: vec![0, 1, 2, u8::MAX],
416            };
417
418            let value = serde_json::to_value(payload).unwrap();
419            assert_eq!(
420                value,
421                serde_json::json!({
422                    "type": "file_write",
423                    "path": "path",
424                    "data": [0, 1, 2, u8::MAX],
425                })
426            );
427        }
428
429        #[test]
430        fn should_be_able_to_deserialize_from_json() {
431            let value = serde_json::json!({
432                "type": "file_write",
433                "path": "path",
434                "data": [0, 1, 2, u8::MAX],
435            });
436
437            let payload: Request = serde_json::from_value(value).unwrap();
438            assert_eq!(
439                payload,
440                Request::FileWrite {
441                    path: PathBuf::from("path"),
442                    data: vec![0, 1, 2, u8::MAX],
443                }
444            );
445        }
446
447        #[test]
448        fn should_be_able_to_serialize_to_msgpack() {
449            let payload = Request::FileWrite {
450                path: PathBuf::from("path"),
451                data: vec![0, 1, 2, u8::MAX],
452            };
453
454            // NOTE: We don't actually check the output here because it's an implementation detail
455            // and could change as we change how serialization is done. This is merely to verify
456            // that we can serialize since there are times when serde fails to serialize at
457            // runtime.
458            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
459        }
460
461        #[test]
462        fn should_be_able_to_deserialize_from_msgpack() {
463            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
464            // verify that we are not corrupting or causing issues when serializing on a
465            // client/server and then trying to deserialize on the other side. This has happened
466            // enough times with minor changes that we need tests to verify.
467            let buf = rmp_serde::encode::to_vec_named(&Request::FileWrite {
468                path: PathBuf::from("path"),
469                data: vec![0, 1, 2, u8::MAX],
470            })
471            .unwrap();
472
473            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
474            assert_eq!(
475                payload,
476                Request::FileWrite {
477                    path: PathBuf::from("path"),
478                    data: vec![0, 1, 2, u8::MAX],
479                }
480            );
481        }
482    }
483
484    mod file_write_text {
485        use super::*;
486
487        #[test]
488        fn should_be_able_to_serialize_to_json() {
489            let payload = Request::FileWriteText {
490                path: PathBuf::from("path"),
491                text: String::from("text"),
492            };
493
494            let value = serde_json::to_value(payload).unwrap();
495            assert_eq!(
496                value,
497                serde_json::json!({
498                    "type": "file_write_text",
499                    "path": "path",
500                    "text": "text",
501                })
502            );
503        }
504
505        #[test]
506        fn should_be_able_to_deserialize_from_json() {
507            let value = serde_json::json!({
508                "type": "file_write_text",
509                "path": "path",
510                "text": "text",
511            });
512
513            let payload: Request = serde_json::from_value(value).unwrap();
514            assert_eq!(
515                payload,
516                Request::FileWriteText {
517                    path: PathBuf::from("path"),
518                    text: String::from("text"),
519                }
520            );
521        }
522
523        #[test]
524        fn should_be_able_to_serialize_to_msgpack() {
525            let payload = Request::FileWriteText {
526                path: PathBuf::from("path"),
527                text: String::from("text"),
528            };
529
530            // NOTE: We don't actually check the output here because it's an implementation detail
531            // and could change as we change how serialization is done. This is merely to verify
532            // that we can serialize since there are times when serde fails to serialize at
533            // runtime.
534            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
535        }
536
537        #[test]
538        fn should_be_able_to_deserialize_from_msgpack() {
539            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
540            // verify that we are not corrupting or causing issues when serializing on a
541            // client/server and then trying to deserialize on the other side. This has happened
542            // enough times with minor changes that we need tests to verify.
543            let buf = rmp_serde::encode::to_vec_named(&Request::FileWriteText {
544                path: PathBuf::from("path"),
545                text: String::from("text"),
546            })
547            .unwrap();
548
549            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
550            assert_eq!(
551                payload,
552                Request::FileWriteText {
553                    path: PathBuf::from("path"),
554                    text: String::from("text"),
555                }
556            );
557        }
558    }
559
560    mod file_append {
561        use super::*;
562
563        #[test]
564        fn should_be_able_to_serialize_to_json() {
565            let payload = Request::FileAppend {
566                path: PathBuf::from("path"),
567                data: vec![0, 1, 2, u8::MAX],
568            };
569
570            let value = serde_json::to_value(payload).unwrap();
571            assert_eq!(
572                value,
573                serde_json::json!({
574                    "type": "file_append",
575                    "path": "path",
576                    "data": [0, 1, 2, u8::MAX],
577                })
578            );
579        }
580
581        #[test]
582        fn should_be_able_to_deserialize_from_json() {
583            let value = serde_json::json!({
584                "type": "file_append",
585                "path": "path",
586                "data": [0, 1, 2, u8::MAX],
587            });
588
589            let payload: Request = serde_json::from_value(value).unwrap();
590            assert_eq!(
591                payload,
592                Request::FileAppend {
593                    path: PathBuf::from("path"),
594                    data: vec![0, 1, 2, u8::MAX],
595                }
596            );
597        }
598
599        #[test]
600        fn should_be_able_to_serialize_to_msgpack() {
601            let payload = Request::FileAppend {
602                path: PathBuf::from("path"),
603                data: vec![0, 1, 2, u8::MAX],
604            };
605
606            // NOTE: We don't actually check the output here because it's an implementation detail
607            // and could change as we change how serialization is done. This is merely to verify
608            // that we can serialize since there are times when serde fails to serialize at
609            // runtime.
610            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
611        }
612
613        #[test]
614        fn should_be_able_to_deserialize_from_msgpack() {
615            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
616            // verify that we are not corrupting or causing issues when serializing on a
617            // client/server and then trying to deserialize on the other side. This has happened
618            // enough times with minor changes that we need tests to verify.
619            let buf = rmp_serde::encode::to_vec_named(&Request::FileAppend {
620                path: PathBuf::from("path"),
621                data: vec![0, 1, 2, u8::MAX],
622            })
623            .unwrap();
624
625            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
626            assert_eq!(
627                payload,
628                Request::FileAppend {
629                    path: PathBuf::from("path"),
630                    data: vec![0, 1, 2, u8::MAX],
631                }
632            );
633        }
634    }
635
636    mod file_append_text {
637        use super::*;
638
639        #[test]
640        fn should_be_able_to_serialize_to_json() {
641            let payload = Request::FileAppendText {
642                path: PathBuf::from("path"),
643                text: String::from("text"),
644            };
645
646            let value = serde_json::to_value(payload).unwrap();
647            assert_eq!(
648                value,
649                serde_json::json!({
650                    "type": "file_append_text",
651                    "path": "path",
652                    "text": "text",
653                })
654            );
655        }
656
657        #[test]
658        fn should_be_able_to_deserialize_from_json() {
659            let value = serde_json::json!({
660                "type": "file_append_text",
661                "path": "path",
662                "text": "text",
663            });
664
665            let payload: Request = serde_json::from_value(value).unwrap();
666            assert_eq!(
667                payload,
668                Request::FileAppendText {
669                    path: PathBuf::from("path"),
670                    text: String::from("text"),
671                }
672            );
673        }
674
675        #[test]
676        fn should_be_able_to_serialize_to_msgpack() {
677            let payload = Request::FileAppendText {
678                path: PathBuf::from("path"),
679                text: String::from("text"),
680            };
681
682            // NOTE: We don't actually check the output here because it's an implementation detail
683            // and could change as we change how serialization is done. This is merely to verify
684            // that we can serialize since there are times when serde fails to serialize at
685            // runtime.
686            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
687        }
688
689        #[test]
690        fn should_be_able_to_deserialize_from_msgpack() {
691            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
692            // verify that we are not corrupting or causing issues when serializing on a
693            // client/server and then trying to deserialize on the other side. This has happened
694            // enough times with minor changes that we need tests to verify.
695            let buf = rmp_serde::encode::to_vec_named(&Request::FileAppendText {
696                path: PathBuf::from("path"),
697                text: String::from("text"),
698            })
699            .unwrap();
700
701            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
702            assert_eq!(
703                payload,
704                Request::FileAppendText {
705                    path: PathBuf::from("path"),
706                    text: String::from("text"),
707                }
708            );
709        }
710    }
711
712    mod dir_read {
713        use super::*;
714
715        #[test]
716        fn should_be_able_to_serialize_minimal_payload_to_json() {
717            let payload = Request::DirRead {
718                path: PathBuf::from("path"),
719                depth: 1,
720                absolute: false,
721                canonicalize: false,
722                include_root: false,
723            };
724
725            let value = serde_json::to_value(payload).unwrap();
726            assert_eq!(
727                value,
728                serde_json::json!({
729                    "type": "dir_read",
730                    "path": "path",
731                })
732            );
733        }
734
735        #[test]
736        fn should_be_able_to_serialize_full_payload_to_json() {
737            let payload = Request::DirRead {
738                path: PathBuf::from("path"),
739                depth: usize::MAX,
740                absolute: true,
741                canonicalize: true,
742                include_root: true,
743            };
744
745            let value = serde_json::to_value(payload).unwrap();
746            assert_eq!(
747                value,
748                serde_json::json!({
749                    "type": "dir_read",
750                    "path": "path",
751                    "depth": usize::MAX,
752                    "absolute": true,
753                    "canonicalize": true,
754                    "include_root": true,
755                })
756            );
757        }
758
759        #[test]
760        fn should_be_able_to_deserialize_minimal_payload_from_json() {
761            let value = serde_json::json!({
762                "type": "dir_read",
763                "path": "path",
764            });
765
766            let payload: Request = serde_json::from_value(value).unwrap();
767            assert_eq!(
768                payload,
769                Request::DirRead {
770                    path: PathBuf::from("path"),
771                    depth: 1,
772                    absolute: false,
773                    canonicalize: false,
774                    include_root: false,
775                }
776            );
777        }
778
779        #[test]
780        fn should_be_able_to_deserialize_full_payload_from_json() {
781            let value = serde_json::json!({
782                "type": "dir_read",
783                "path": "path",
784                "depth": usize::MAX,
785                "absolute": true,
786                "canonicalize": true,
787                "include_root": true,
788            });
789
790            let payload: Request = serde_json::from_value(value).unwrap();
791            assert_eq!(
792                payload,
793                Request::DirRead {
794                    path: PathBuf::from("path"),
795                    depth: usize::MAX,
796                    absolute: true,
797                    canonicalize: true,
798                    include_root: true,
799                }
800            );
801        }
802
803        #[test]
804        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
805            let payload = Request::DirRead {
806                path: PathBuf::from("path"),
807                depth: 1,
808                absolute: false,
809                canonicalize: false,
810                include_root: false,
811            };
812
813            // NOTE: We don't actually check the output here because it's an implementation detail
814            // and could change as we change how serialization is done. This is merely to verify
815            // that we can serialize since there are times when serde fails to serialize at
816            // runtime.
817            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
818        }
819
820        #[test]
821        fn should_be_able_to_serialize_full_payload_to_msgpack() {
822            let payload = Request::DirRead {
823                path: PathBuf::from("path"),
824                depth: usize::MAX,
825                absolute: true,
826                canonicalize: true,
827                include_root: true,
828            };
829
830            // NOTE: We don't actually check the output here because it's an implementation detail
831            // and could change as we change how serialization is done. This is merely to verify
832            // that we can serialize since there are times when serde fails to serialize at
833            // runtime.
834            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
835        }
836
837        #[test]
838        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
839            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
840            // verify that we are not corrupting or causing issues when serializing on a
841            // client/server and then trying to deserialize on the other side. This has happened
842            // enough times with minor changes that we need tests to verify.
843            let buf = rmp_serde::encode::to_vec_named(&Request::DirRead {
844                path: PathBuf::from("path"),
845                depth: 1,
846                absolute: false,
847                canonicalize: false,
848                include_root: false,
849            })
850            .unwrap();
851
852            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
853            assert_eq!(
854                payload,
855                Request::DirRead {
856                    path: PathBuf::from("path"),
857                    depth: 1,
858                    absolute: false,
859                    canonicalize: false,
860                    include_root: false,
861                }
862            );
863        }
864
865        #[test]
866        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
867            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
868            // verify that we are not corrupting or causing issues when serializing on a
869            // client/server and then trying to deserialize on the other side. This has happened
870            // enough times with minor changes that we need tests to verify.
871            let buf = rmp_serde::encode::to_vec_named(&Request::DirRead {
872                path: PathBuf::from("path"),
873                depth: usize::MAX,
874                absolute: true,
875                canonicalize: true,
876                include_root: true,
877            })
878            .unwrap();
879
880            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
881            assert_eq!(
882                payload,
883                Request::DirRead {
884                    path: PathBuf::from("path"),
885                    depth: usize::MAX,
886                    absolute: true,
887                    canonicalize: true,
888                    include_root: true,
889                }
890            );
891        }
892    }
893
894    mod dir_create {
895        use super::*;
896
897        #[test]
898        fn should_be_able_to_serialize_minimal_payload_to_json() {
899            let payload = Request::DirCreate {
900                path: PathBuf::from("path"),
901                all: false,
902            };
903
904            let value = serde_json::to_value(payload).unwrap();
905            assert_eq!(
906                value,
907                serde_json::json!({
908                    "type": "dir_create",
909                    "path": "path",
910                })
911            );
912        }
913
914        #[test]
915        fn should_be_able_to_serialize_full_payload_to_json() {
916            let payload = Request::DirCreate {
917                path: PathBuf::from("path"),
918                all: true,
919            };
920
921            let value = serde_json::to_value(payload).unwrap();
922            assert_eq!(
923                value,
924                serde_json::json!({
925                    "type": "dir_create",
926                    "path": "path",
927                    "all": true,
928                })
929            );
930        }
931
932        #[test]
933        fn should_be_able_to_deserialize_minimal_payload_from_json() {
934            let value = serde_json::json!({
935                "type": "dir_create",
936                "path": "path",
937            });
938
939            let payload: Request = serde_json::from_value(value).unwrap();
940            assert_eq!(
941                payload,
942                Request::DirCreate {
943                    path: PathBuf::from("path"),
944                    all: false,
945                }
946            );
947        }
948
949        #[test]
950        fn should_be_able_to_deserialize_full_payload_from_json() {
951            let value = serde_json::json!({
952                "type": "dir_create",
953                "path": "path",
954                "all": true,
955            });
956
957            let payload: Request = serde_json::from_value(value).unwrap();
958            assert_eq!(
959                payload,
960                Request::DirCreate {
961                    path: PathBuf::from("path"),
962                    all: true,
963                }
964            );
965        }
966
967        #[test]
968        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
969            let payload = Request::DirCreate {
970                path: PathBuf::from("path"),
971                all: false,
972            };
973
974            // NOTE: We don't actually check the output here because it's an implementation detail
975            // and could change as we change how serialization is done. This is merely to verify
976            // that we can serialize since there are times when serde fails to serialize at
977            // runtime.
978            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
979        }
980
981        #[test]
982        fn should_be_able_to_serialize_full_payload_to_msgpack() {
983            let payload = Request::DirCreate {
984                path: PathBuf::from("path"),
985                all: true,
986            };
987
988            // NOTE: We don't actually check the output here because it's an implementation detail
989            // and could change as we change how serialization is done. This is merely to verify
990            // that we can serialize since there are times when serde fails to serialize at
991            // runtime.
992            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
993        }
994
995        #[test]
996        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
997            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
998            // verify that we are not corrupting or causing issues when serializing on a
999            // client/server and then trying to deserialize on the other side. This has happened
1000            // enough times with minor changes that we need tests to verify.
1001            let buf = rmp_serde::encode::to_vec_named(&Request::DirCreate {
1002                path: PathBuf::from("path"),
1003                all: false,
1004            })
1005            .unwrap();
1006
1007            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1008            assert_eq!(
1009                payload,
1010                Request::DirCreate {
1011                    path: PathBuf::from("path"),
1012                    all: false,
1013                }
1014            );
1015        }
1016
1017        #[test]
1018        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
1019            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1020            // verify that we are not corrupting or causing issues when serializing on a
1021            // client/server and then trying to deserialize on the other side. This has happened
1022            // enough times with minor changes that we need tests to verify.
1023            let buf = rmp_serde::encode::to_vec_named(&Request::DirCreate {
1024                path: PathBuf::from("path"),
1025                all: true,
1026            })
1027            .unwrap();
1028
1029            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1030            assert_eq!(
1031                payload,
1032                Request::DirCreate {
1033                    path: PathBuf::from("path"),
1034                    all: true,
1035                }
1036            );
1037        }
1038    }
1039
1040    mod remove {
1041        use super::*;
1042
1043        #[test]
1044        fn should_be_able_to_serialize_minimal_payload_to_json() {
1045            let payload = Request::Remove {
1046                path: PathBuf::from("path"),
1047                force: false,
1048            };
1049
1050            let value = serde_json::to_value(payload).unwrap();
1051            assert_eq!(
1052                value,
1053                serde_json::json!({
1054                    "type": "remove",
1055                    "path": "path",
1056                })
1057            );
1058        }
1059
1060        #[test]
1061        fn should_be_able_to_serialize_full_payload_to_json() {
1062            let payload = Request::Remove {
1063                path: PathBuf::from("path"),
1064                force: true,
1065            };
1066
1067            let value = serde_json::to_value(payload).unwrap();
1068            assert_eq!(
1069                value,
1070                serde_json::json!({
1071                    "type": "remove",
1072                    "path": "path",
1073                    "force": true,
1074                })
1075            );
1076        }
1077
1078        #[test]
1079        fn should_be_able_to_deserialize_minimal_payload_from_json() {
1080            let value = serde_json::json!({
1081                "type": "remove",
1082                "path": "path",
1083            });
1084
1085            let payload: Request = serde_json::from_value(value).unwrap();
1086            assert_eq!(
1087                payload,
1088                Request::Remove {
1089                    path: PathBuf::from("path"),
1090                    force: false,
1091                }
1092            );
1093        }
1094
1095        #[test]
1096        fn should_be_able_to_deserialize_full_payload_from_json() {
1097            let value = serde_json::json!({
1098                "type": "remove",
1099                "path": "path",
1100                "force": true,
1101            });
1102
1103            let payload: Request = serde_json::from_value(value).unwrap();
1104            assert_eq!(
1105                payload,
1106                Request::Remove {
1107                    path: PathBuf::from("path"),
1108                    force: true,
1109                }
1110            );
1111        }
1112
1113        #[test]
1114        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
1115            let payload = Request::Remove {
1116                path: PathBuf::from("path"),
1117                force: false,
1118            };
1119
1120            // NOTE: We don't actually check the output here because it's an implementation detail
1121            // and could change as we change how serialization is done. This is merely to verify
1122            // that we can serialize since there are times when serde fails to serialize at
1123            // runtime.
1124            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1125        }
1126
1127        #[test]
1128        fn should_be_able_to_serialize_full_payload_to_msgpack() {
1129            let payload = Request::Remove {
1130                path: PathBuf::from("path"),
1131                force: true,
1132            };
1133
1134            // NOTE: We don't actually check the output here because it's an implementation detail
1135            // and could change as we change how serialization is done. This is merely to verify
1136            // that we can serialize since there are times when serde fails to serialize at
1137            // runtime.
1138            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1139        }
1140
1141        #[test]
1142        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
1143            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1144            // verify that we are not corrupting or causing issues when serializing on a
1145            // client/server and then trying to deserialize on the other side. This has happened
1146            // enough times with minor changes that we need tests to verify.
1147            let buf = rmp_serde::encode::to_vec_named(&Request::Remove {
1148                path: PathBuf::from("path"),
1149                force: false,
1150            })
1151            .unwrap();
1152
1153            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1154            assert_eq!(
1155                payload,
1156                Request::Remove {
1157                    path: PathBuf::from("path"),
1158                    force: false,
1159                }
1160            );
1161        }
1162
1163        #[test]
1164        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
1165            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1166            // verify that we are not corrupting or causing issues when serializing on a
1167            // client/server and then trying to deserialize on the other side. This has happened
1168            // enough times with minor changes that we need tests to verify.
1169            let buf = rmp_serde::encode::to_vec_named(&Request::Remove {
1170                path: PathBuf::from("path"),
1171                force: true,
1172            })
1173            .unwrap();
1174
1175            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1176            assert_eq!(
1177                payload,
1178                Request::Remove {
1179                    path: PathBuf::from("path"),
1180                    force: true,
1181                }
1182            );
1183        }
1184    }
1185
1186    mod copy {
1187        use super::*;
1188
1189        #[test]
1190        fn should_be_able_to_serialize_to_json() {
1191            let payload = Request::Copy {
1192                src: PathBuf::from("src"),
1193                dst: PathBuf::from("dst"),
1194            };
1195
1196            let value = serde_json::to_value(payload).unwrap();
1197            assert_eq!(
1198                value,
1199                serde_json::json!({
1200                    "type": "copy",
1201                    "src": "src",
1202                    "dst": "dst",
1203                })
1204            );
1205        }
1206
1207        #[test]
1208        fn should_be_able_to_deserialize_from_json() {
1209            let value = serde_json::json!({
1210                "type": "copy",
1211                "src": "src",
1212                "dst": "dst",
1213            });
1214
1215            let payload: Request = serde_json::from_value(value).unwrap();
1216            assert_eq!(
1217                payload,
1218                Request::Copy {
1219                    src: PathBuf::from("src"),
1220                    dst: PathBuf::from("dst"),
1221                }
1222            );
1223        }
1224
1225        #[test]
1226        fn should_be_able_to_serialize_to_msgpack() {
1227            let payload = Request::Copy {
1228                src: PathBuf::from("src"),
1229                dst: PathBuf::from("dst"),
1230            };
1231
1232            // NOTE: We don't actually check the output here because it's an implementation detail
1233            // and could change as we change how serialization is done. This is merely to verify
1234            // that we can serialize since there are times when serde fails to serialize at
1235            // runtime.
1236            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1237        }
1238
1239        #[test]
1240        fn should_be_able_to_deserialize_from_msgpack() {
1241            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1242            // verify that we are not corrupting or causing issues when serializing on a
1243            // client/server and then trying to deserialize on the other side. This has happened
1244            // enough times with minor changes that we need tests to verify.
1245            let buf = rmp_serde::encode::to_vec_named(&Request::Copy {
1246                src: PathBuf::from("src"),
1247                dst: PathBuf::from("dst"),
1248            })
1249            .unwrap();
1250
1251            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1252            assert_eq!(
1253                payload,
1254                Request::Copy {
1255                    src: PathBuf::from("src"),
1256                    dst: PathBuf::from("dst"),
1257                }
1258            );
1259        }
1260    }
1261
1262    mod rename {
1263        use super::*;
1264
1265        #[test]
1266        fn should_be_able_to_serialize_to_json() {
1267            let payload = Request::Rename {
1268                src: PathBuf::from("src"),
1269                dst: PathBuf::from("dst"),
1270            };
1271
1272            let value = serde_json::to_value(payload).unwrap();
1273            assert_eq!(
1274                value,
1275                serde_json::json!({
1276                    "type": "rename",
1277                    "src": "src",
1278                    "dst": "dst",
1279                })
1280            );
1281        }
1282
1283        #[test]
1284        fn should_be_able_to_deserialize_from_json() {
1285            let value = serde_json::json!({
1286                "type": "rename",
1287                "src": "src",
1288                "dst": "dst",
1289            });
1290
1291            let payload: Request = serde_json::from_value(value).unwrap();
1292            assert_eq!(
1293                payload,
1294                Request::Rename {
1295                    src: PathBuf::from("src"),
1296                    dst: PathBuf::from("dst"),
1297                }
1298            );
1299        }
1300
1301        #[test]
1302        fn should_be_able_to_serialize_to_msgpack() {
1303            let payload = Request::Rename {
1304                src: PathBuf::from("src"),
1305                dst: PathBuf::from("dst"),
1306            };
1307
1308            // NOTE: We don't actually check the output here because it's an implementation detail
1309            // and could change as we change how serialization is done. This is merely to verify
1310            // that we can serialize since there are times when serde fails to serialize at
1311            // runtime.
1312            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1313        }
1314
1315        #[test]
1316        fn should_be_able_to_deserialize_from_msgpack() {
1317            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1318            // verify that we are not corrupting or causing issues when serializing on a
1319            // client/server and then trying to deserialize on the other side. This has happened
1320            // enough times with minor changes that we need tests to verify.
1321            let buf = rmp_serde::encode::to_vec_named(&Request::Rename {
1322                src: PathBuf::from("src"),
1323                dst: PathBuf::from("dst"),
1324            })
1325            .unwrap();
1326
1327            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1328            assert_eq!(
1329                payload,
1330                Request::Rename {
1331                    src: PathBuf::from("src"),
1332                    dst: PathBuf::from("dst"),
1333                }
1334            );
1335        }
1336    }
1337
1338    mod watch {
1339        use super::*;
1340
1341        #[test]
1342        fn should_be_able_to_serialize_minimal_payload_to_json() {
1343            let payload = Request::Watch {
1344                path: PathBuf::from("path"),
1345                recursive: false,
1346                only: Vec::new(),
1347                except: Vec::new(),
1348            };
1349
1350            let value = serde_json::to_value(payload).unwrap();
1351            assert_eq!(
1352                value,
1353                serde_json::json!({
1354                    "type": "watch",
1355                    "path": "path",
1356                })
1357            );
1358        }
1359
1360        #[test]
1361        fn should_be_able_to_serialize_full_payload_to_json() {
1362            let payload = Request::Watch {
1363                path: PathBuf::from("path"),
1364                recursive: true,
1365                only: vec![ChangeKind::Access],
1366                except: vec![ChangeKind::Modify],
1367            };
1368
1369            let value = serde_json::to_value(payload).unwrap();
1370            assert_eq!(
1371                value,
1372                serde_json::json!({
1373                    "type": "watch",
1374                    "path": "path",
1375                    "recursive": true,
1376                    "only": ["access"],
1377                    "except": ["modify"],
1378                })
1379            );
1380        }
1381
1382        #[test]
1383        fn should_be_able_to_deserialize_minimal_payload_from_json() {
1384            let value = serde_json::json!({
1385                "type": "watch",
1386                "path": "path",
1387            });
1388
1389            let payload: Request = serde_json::from_value(value).unwrap();
1390            assert_eq!(
1391                payload,
1392                Request::Watch {
1393                    path: PathBuf::from("path"),
1394                    recursive: false,
1395                    only: Vec::new(),
1396                    except: Vec::new(),
1397                }
1398            );
1399        }
1400
1401        #[test]
1402        fn should_be_able_to_deserialize_full_payload_from_json() {
1403            let value = serde_json::json!({
1404                "type": "watch",
1405                "path": "path",
1406                "recursive": true,
1407                "only": ["access"],
1408                "except": ["modify"],
1409            });
1410
1411            let payload: Request = serde_json::from_value(value).unwrap();
1412            assert_eq!(
1413                payload,
1414                Request::Watch {
1415                    path: PathBuf::from("path"),
1416                    recursive: true,
1417                    only: vec![ChangeKind::Access],
1418                    except: vec![ChangeKind::Modify],
1419                }
1420            );
1421        }
1422
1423        #[test]
1424        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
1425            let payload = Request::Watch {
1426                path: PathBuf::from("path"),
1427                recursive: false,
1428                only: Vec::new(),
1429                except: Vec::new(),
1430            };
1431
1432            // NOTE: We don't actually check the output here because it's an implementation detail
1433            // and could change as we change how serialization is done. This is merely to verify
1434            // that we can serialize since there are times when serde fails to serialize at
1435            // runtime.
1436            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1437        }
1438
1439        #[test]
1440        fn should_be_able_to_serialize_full_payload_to_msgpack() {
1441            let payload = Request::Watch {
1442                path: PathBuf::from("path"),
1443                recursive: true,
1444                only: vec![ChangeKind::Access],
1445                except: vec![ChangeKind::Modify],
1446            };
1447
1448            // NOTE: We don't actually check the output here because it's an implementation detail
1449            // and could change as we change how serialization is done. This is merely to verify
1450            // that we can serialize since there are times when serde fails to serialize at
1451            // runtime.
1452            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1453        }
1454
1455        #[test]
1456        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
1457            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1458            // verify that we are not corrupting or causing issues when serializing on a
1459            // client/server and then trying to deserialize on the other side. This has happened
1460            // enough times with minor changes that we need tests to verify.
1461            let buf = rmp_serde::encode::to_vec_named(&Request::Watch {
1462                path: PathBuf::from("path"),
1463                recursive: false,
1464                only: Vec::new(),
1465                except: Vec::new(),
1466            })
1467            .unwrap();
1468
1469            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1470            assert_eq!(
1471                payload,
1472                Request::Watch {
1473                    path: PathBuf::from("path"),
1474                    recursive: false,
1475                    only: Vec::new(),
1476                    except: Vec::new(),
1477                }
1478            );
1479        }
1480
1481        #[test]
1482        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
1483            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1484            // verify that we are not corrupting or causing issues when serializing on a
1485            // client/server and then trying to deserialize on the other side. This has happened
1486            // enough times with minor changes that we need tests to verify.
1487            let buf = rmp_serde::encode::to_vec_named(&Request::Watch {
1488                path: PathBuf::from("path"),
1489                recursive: true,
1490                only: vec![ChangeKind::Access],
1491                except: vec![ChangeKind::Modify],
1492            })
1493            .unwrap();
1494
1495            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1496            assert_eq!(
1497                payload,
1498                Request::Watch {
1499                    path: PathBuf::from("path"),
1500                    recursive: true,
1501                    only: vec![ChangeKind::Access],
1502                    except: vec![ChangeKind::Modify],
1503                }
1504            );
1505        }
1506    }
1507
1508    mod unwatch {
1509        use super::*;
1510
1511        #[test]
1512        fn should_be_able_to_serialize_to_json() {
1513            let payload = Request::Unwatch {
1514                path: PathBuf::from("path"),
1515            };
1516
1517            let value = serde_json::to_value(payload).unwrap();
1518            assert_eq!(
1519                value,
1520                serde_json::json!({
1521                    "type": "unwatch",
1522                    "path": "path",
1523                })
1524            );
1525        }
1526
1527        #[test]
1528        fn should_be_able_to_deserialize_from_json() {
1529            let value = serde_json::json!({
1530                "type": "unwatch",
1531                "path": "path",
1532            });
1533
1534            let payload: Request = serde_json::from_value(value).unwrap();
1535            assert_eq!(
1536                payload,
1537                Request::Unwatch {
1538                    path: PathBuf::from("path")
1539                }
1540            );
1541        }
1542
1543        #[test]
1544        fn should_be_able_to_serialize_to_msgpack() {
1545            let payload = Request::Unwatch {
1546                path: PathBuf::from("path"),
1547            };
1548
1549            // NOTE: We don't actually check the output here because it's an implementation detail
1550            // and could change as we change how serialization is done. This is merely to verify
1551            // that we can serialize since there are times when serde fails to serialize at
1552            // runtime.
1553            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1554        }
1555
1556        #[test]
1557        fn should_be_able_to_deserialize_from_msgpack() {
1558            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1559            // verify that we are not corrupting or causing issues when serializing on a
1560            // client/server and then trying to deserialize on the other side. This has happened
1561            // enough times with minor changes that we need tests to verify.
1562            let buf = rmp_serde::encode::to_vec_named(&Request::Unwatch {
1563                path: PathBuf::from("path"),
1564            })
1565            .unwrap();
1566
1567            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1568            assert_eq!(
1569                payload,
1570                Request::Unwatch {
1571                    path: PathBuf::from("path"),
1572                }
1573            );
1574        }
1575    }
1576
1577    mod exists {
1578        use super::*;
1579
1580        #[test]
1581        fn should_be_able_to_serialize_to_json() {
1582            let payload = Request::Exists {
1583                path: PathBuf::from("path"),
1584            };
1585
1586            let value = serde_json::to_value(payload).unwrap();
1587            assert_eq!(
1588                value,
1589                serde_json::json!({
1590                    "type": "exists",
1591                    "path": "path",
1592                })
1593            );
1594        }
1595
1596        #[test]
1597        fn should_be_able_to_deserialize_from_json() {
1598            let value = serde_json::json!({
1599                "type": "exists",
1600                "path": "path",
1601            });
1602
1603            let payload: Request = serde_json::from_value(value).unwrap();
1604            assert_eq!(
1605                payload,
1606                Request::Exists {
1607                    path: PathBuf::from("path")
1608                }
1609            );
1610        }
1611
1612        #[test]
1613        fn should_be_able_to_serialize_to_msgpack() {
1614            let payload = Request::Exists {
1615                path: PathBuf::from("path"),
1616            };
1617
1618            // NOTE: We don't actually check the output here because it's an implementation detail
1619            // and could change as we change how serialization is done. This is merely to verify
1620            // that we can serialize since there are times when serde fails to serialize at
1621            // runtime.
1622            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1623        }
1624
1625        #[test]
1626        fn should_be_able_to_deserialize_from_msgpack() {
1627            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1628            // verify that we are not corrupting or causing issues when serializing on a
1629            // client/server and then trying to deserialize on the other side. This has happened
1630            // enough times with minor changes that we need tests to verify.
1631            let buf = rmp_serde::encode::to_vec_named(&Request::Exists {
1632                path: PathBuf::from("path"),
1633            })
1634            .unwrap();
1635
1636            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1637            assert_eq!(
1638                payload,
1639                Request::Exists {
1640                    path: PathBuf::from("path"),
1641                }
1642            );
1643        }
1644    }
1645
1646    mod metadata {
1647        use super::*;
1648
1649        #[test]
1650        fn should_be_able_to_serialize_minimal_payload_to_json() {
1651            let payload = Request::Metadata {
1652                path: PathBuf::from("path"),
1653                canonicalize: false,
1654                resolve_file_type: false,
1655            };
1656
1657            let value = serde_json::to_value(payload).unwrap();
1658            assert_eq!(
1659                value,
1660                serde_json::json!({
1661                    "type": "metadata",
1662                    "path": "path",
1663                })
1664            );
1665        }
1666
1667        #[test]
1668        fn should_be_able_to_serialize_full_payload_to_json() {
1669            let payload = Request::Metadata {
1670                path: PathBuf::from("path"),
1671                canonicalize: true,
1672                resolve_file_type: true,
1673            };
1674
1675            let value = serde_json::to_value(payload).unwrap();
1676            assert_eq!(
1677                value,
1678                serde_json::json!({
1679                    "type": "metadata",
1680                    "path": "path",
1681                    "canonicalize": true,
1682                    "resolve_file_type": true,
1683                })
1684            );
1685        }
1686
1687        #[test]
1688        fn should_be_able_to_deserialize_minimal_payload_from_json() {
1689            let value = serde_json::json!({
1690                "type": "metadata",
1691                "path": "path",
1692            });
1693
1694            let payload: Request = serde_json::from_value(value).unwrap();
1695            assert_eq!(
1696                payload,
1697                Request::Metadata {
1698                    path: PathBuf::from("path"),
1699                    canonicalize: false,
1700                    resolve_file_type: false,
1701                }
1702            );
1703        }
1704
1705        #[test]
1706        fn should_be_able_to_deserialize_full_payload_from_json() {
1707            let value = serde_json::json!({
1708                "type": "metadata",
1709                "path": "path",
1710                "canonicalize": true,
1711                "resolve_file_type": true,
1712            });
1713
1714            let payload: Request = serde_json::from_value(value).unwrap();
1715            assert_eq!(
1716                payload,
1717                Request::Metadata {
1718                    path: PathBuf::from("path"),
1719                    canonicalize: true,
1720                    resolve_file_type: true,
1721                }
1722            );
1723        }
1724
1725        #[test]
1726        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
1727            let payload = Request::Metadata {
1728                path: PathBuf::from("path"),
1729                canonicalize: false,
1730                resolve_file_type: false,
1731            };
1732
1733            // NOTE: We don't actually check the output here because it's an implementation detail
1734            // and could change as we change how serialization is done. This is merely to verify
1735            // that we can serialize since there are times when serde fails to serialize at
1736            // runtime.
1737            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1738        }
1739
1740        #[test]
1741        fn should_be_able_to_serialize_full_payload_to_msgpack() {
1742            let payload = Request::Metadata {
1743                path: PathBuf::from("path"),
1744                canonicalize: true,
1745                resolve_file_type: true,
1746            };
1747
1748            // NOTE: We don't actually check the output here because it's an implementation detail
1749            // and could change as we change how serialization is done. This is merely to verify
1750            // that we can serialize since there are times when serde fails to serialize at
1751            // runtime.
1752            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1753        }
1754
1755        #[test]
1756        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
1757            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1758            // verify that we are not corrupting or causing issues when serializing on a
1759            // client/server and then trying to deserialize on the other side. This has happened
1760            // enough times with minor changes that we need tests to verify.
1761            let buf = rmp_serde::encode::to_vec_named(&Request::Metadata {
1762                path: PathBuf::from("path"),
1763                canonicalize: false,
1764                resolve_file_type: false,
1765            })
1766            .unwrap();
1767
1768            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1769            assert_eq!(
1770                payload,
1771                Request::Metadata {
1772                    path: PathBuf::from("path"),
1773                    canonicalize: false,
1774                    resolve_file_type: false,
1775                }
1776            );
1777        }
1778
1779        #[test]
1780        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
1781            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1782            // verify that we are not corrupting or causing issues when serializing on a
1783            // client/server and then trying to deserialize on the other side. This has happened
1784            // enough times with minor changes that we need tests to verify.
1785            let buf = rmp_serde::encode::to_vec_named(&Request::Metadata {
1786                path: PathBuf::from("path"),
1787                canonicalize: true,
1788                resolve_file_type: true,
1789            })
1790            .unwrap();
1791
1792            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1793            assert_eq!(
1794                payload,
1795                Request::Metadata {
1796                    path: PathBuf::from("path"),
1797                    canonicalize: true,
1798                    resolve_file_type: true,
1799                }
1800            );
1801        }
1802    }
1803
1804    mod set_permissions {
1805        use super::*;
1806
1807        const fn full_permissions() -> Permissions {
1808            Permissions {
1809                owner_read: Some(true),
1810                owner_write: Some(true),
1811                owner_exec: Some(true),
1812                group_read: Some(true),
1813                group_write: Some(true),
1814                group_exec: Some(true),
1815                other_read: Some(true),
1816                other_write: Some(true),
1817                other_exec: Some(true),
1818            }
1819        }
1820
1821        const fn full_options() -> SetPermissionsOptions {
1822            SetPermissionsOptions {
1823                exclude_symlinks: true,
1824                follow_symlinks: true,
1825                recursive: true,
1826            }
1827        }
1828
1829        #[test]
1830        fn should_be_able_to_serialize_minimal_payload_to_json() {
1831            let payload = Request::SetPermissions {
1832                path: PathBuf::from("path"),
1833                permissions: Default::default(),
1834                options: Default::default(),
1835            };
1836
1837            let value = serde_json::to_value(payload).unwrap();
1838            assert_eq!(
1839                value,
1840                serde_json::json!({
1841                    "type": "set_permissions",
1842                    "path": "path",
1843                    "permissions": {},
1844                    "options": {},
1845                })
1846            );
1847        }
1848
1849        #[test]
1850        fn should_be_able_to_serialize_full_payload_to_json() {
1851            let payload = Request::SetPermissions {
1852                path: PathBuf::from("path"),
1853                permissions: full_permissions(),
1854                options: full_options(),
1855            };
1856
1857            let value = serde_json::to_value(payload).unwrap();
1858            assert_eq!(
1859                value,
1860                serde_json::json!({
1861                    "type": "set_permissions",
1862                    "path": "path",
1863                    "permissions": {
1864                        "owner_read": true,
1865                        "owner_write": true,
1866                        "owner_exec": true,
1867                        "group_read": true,
1868                        "group_write": true,
1869                        "group_exec": true,
1870                        "other_read": true,
1871                        "other_write": true,
1872                        "other_exec": true,
1873                    },
1874                    "options": {
1875                        "exclude_symlinks": true,
1876                        "follow_symlinks": true,
1877                        "recursive": true,
1878                    },
1879                })
1880            );
1881        }
1882
1883        #[test]
1884        fn should_be_able_to_deserialize_minimal_payload_from_json() {
1885            let value = serde_json::json!({
1886                "type": "set_permissions",
1887                "path": "path",
1888                "permissions": {},
1889                "options": {},
1890            });
1891
1892            let payload: Request = serde_json::from_value(value).unwrap();
1893            assert_eq!(
1894                payload,
1895                Request::SetPermissions {
1896                    path: PathBuf::from("path"),
1897                    permissions: Default::default(),
1898                    options: Default::default(),
1899                }
1900            );
1901        }
1902
1903        #[test]
1904        fn should_be_able_to_deserialize_full_payload_from_json() {
1905            let value = serde_json::json!({
1906                "type": "set_permissions",
1907                "path": "path",
1908                "permissions": {
1909                    "owner_read": true,
1910                    "owner_write": true,
1911                    "owner_exec": true,
1912                    "group_read": true,
1913                    "group_write": true,
1914                    "group_exec": true,
1915                    "other_read": true,
1916                    "other_write": true,
1917                    "other_exec": true,
1918                },
1919                "options": {
1920                    "exclude_symlinks": true,
1921                    "follow_symlinks": true,
1922                    "recursive": true,
1923                },
1924            });
1925
1926            let payload: Request = serde_json::from_value(value).unwrap();
1927            assert_eq!(
1928                payload,
1929                Request::SetPermissions {
1930                    path: PathBuf::from("path"),
1931                    permissions: full_permissions(),
1932                    options: full_options(),
1933                }
1934            );
1935        }
1936
1937        #[test]
1938        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
1939            let payload = Request::SetPermissions {
1940                path: PathBuf::from("path"),
1941                permissions: Default::default(),
1942                options: Default::default(),
1943            };
1944
1945            // NOTE: We don't actually check the output here because it's an implementation detail
1946            // and could change as we change how serialization is done. This is merely to verify
1947            // that we can serialize since there are times when serde fails to serialize at
1948            // runtime.
1949            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1950        }
1951
1952        #[test]
1953        fn should_be_able_to_serialize_full_payload_to_msgpack() {
1954            let payload = Request::SetPermissions {
1955                path: PathBuf::from("path"),
1956                permissions: full_permissions(),
1957                options: full_options(),
1958            };
1959
1960            // NOTE: We don't actually check the output here because it's an implementation detail
1961            // and could change as we change how serialization is done. This is merely to verify
1962            // that we can serialize since there are times when serde fails to serialize at
1963            // runtime.
1964            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
1965        }
1966
1967        #[test]
1968        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
1969            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1970            // verify that we are not corrupting or causing issues when serializing on a
1971            // client/server and then trying to deserialize on the other side. This has happened
1972            // enough times with minor changes that we need tests to verify.
1973            let buf = rmp_serde::encode::to_vec_named(&Request::SetPermissions {
1974                path: PathBuf::from("path"),
1975                permissions: Default::default(),
1976                options: Default::default(),
1977            })
1978            .unwrap();
1979
1980            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
1981            assert_eq!(
1982                payload,
1983                Request::SetPermissions {
1984                    path: PathBuf::from("path"),
1985                    permissions: Default::default(),
1986                    options: Default::default(),
1987                }
1988            );
1989        }
1990
1991        #[test]
1992        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
1993            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
1994            // verify that we are not corrupting or causing issues when serializing on a
1995            // client/server and then trying to deserialize on the other side. This has happened
1996            // enough times with minor changes that we need tests to verify.
1997            let buf = rmp_serde::encode::to_vec_named(&Request::SetPermissions {
1998                path: PathBuf::from("path"),
1999                permissions: full_permissions(),
2000                options: full_options(),
2001            })
2002            .unwrap();
2003
2004            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2005            assert_eq!(
2006                payload,
2007                Request::SetPermissions {
2008                    path: PathBuf::from("path"),
2009                    permissions: full_permissions(),
2010                    options: full_options(),
2011                }
2012            );
2013        }
2014    }
2015
2016    mod search {
2017        use super::*;
2018        use crate::common::{
2019            FileType, SearchQueryCondition, SearchQueryOptions, SearchQueryTarget,
2020        };
2021
2022        #[test]
2023        fn should_be_able_to_serialize_minimal_payload_to_json() {
2024            let payload = Request::Search {
2025                query: SearchQuery {
2026                    target: SearchQueryTarget::Contents,
2027                    condition: SearchQueryCondition::equals("hello world"),
2028                    paths: vec![PathBuf::from("path")],
2029                    options: Default::default(),
2030                },
2031            };
2032
2033            let value = serde_json::to_value(payload).unwrap();
2034            assert_eq!(
2035                value,
2036                serde_json::json!({
2037                    "type": "search",
2038                    "query": {
2039                        "target": "contents",
2040                        "condition": {
2041                            "type": "equals",
2042                            "value": "hello world",
2043                        },
2044                        "paths": ["path"],
2045                        "options": {},
2046                    },
2047                })
2048            );
2049        }
2050
2051        #[test]
2052        fn should_be_able_to_serialize_full_payload_to_json() {
2053            let payload = Request::Search {
2054                query: SearchQuery {
2055                    target: SearchQueryTarget::Contents,
2056                    condition: SearchQueryCondition::equals("hello world"),
2057                    paths: vec![PathBuf::from("path")],
2058                    options: SearchQueryOptions {
2059                        allowed_file_types: [FileType::File].into_iter().collect(),
2060                        include: Some(SearchQueryCondition::Equals {
2061                            value: String::from("hello"),
2062                        }),
2063                        exclude: Some(SearchQueryCondition::Contains {
2064                            value: String::from("world"),
2065                        }),
2066                        upward: true,
2067                        follow_symbolic_links: true,
2068                        limit: Some(u64::MAX),
2069                        max_depth: Some(u64::MAX),
2070                        pagination: Some(u64::MAX),
2071                        ignore_hidden: true,
2072                        use_ignore_files: true,
2073                        use_parent_ignore_files: true,
2074                        use_git_ignore_files: true,
2075                        use_global_git_ignore_files: true,
2076                        use_git_exclude_files: true,
2077                    },
2078                },
2079            };
2080
2081            let value = serde_json::to_value(payload).unwrap();
2082            assert_eq!(
2083                value,
2084                serde_json::json!({
2085                    "type": "search",
2086                    "query": {
2087                        "target": "contents",
2088                        "condition": {
2089                            "type": "equals",
2090                            "value": "hello world",
2091                        },
2092                        "paths": ["path"],
2093                        "options": {
2094                            "allowed_file_types": ["file"],
2095                            "include": {
2096                                "type": "equals",
2097                                "value": "hello",
2098                            },
2099                            "exclude": {
2100                                "type": "contains",
2101                                "value": "world",
2102                            },
2103                            "upward": true,
2104                            "follow_symbolic_links": true,
2105                            "limit": u64::MAX,
2106                            "max_depth": u64::MAX,
2107                            "pagination": u64::MAX,
2108                            "ignore_hidden": true,
2109                            "use_ignore_files": true,
2110                            "use_parent_ignore_files": true,
2111                            "use_git_ignore_files": true,
2112                            "use_global_git_ignore_files": true,
2113                            "use_git_exclude_files": true,
2114                        },
2115                    },
2116                })
2117            );
2118        }
2119
2120        #[test]
2121        fn should_be_able_to_deserialize_minimal_payload_from_json() {
2122            let value = serde_json::json!({
2123                "type": "search",
2124                "query": {
2125                    "target": "contents",
2126                    "condition": {
2127                        "type": "equals",
2128                        "value": "hello world",
2129                    },
2130                    "paths": ["path"],
2131                },
2132            });
2133
2134            let payload: Request = serde_json::from_value(value).unwrap();
2135            assert_eq!(
2136                payload,
2137                Request::Search {
2138                    query: SearchQuery {
2139                        target: SearchQueryTarget::Contents,
2140                        condition: SearchQueryCondition::equals("hello world"),
2141                        paths: vec![PathBuf::from("path")],
2142                        options: Default::default(),
2143                    },
2144                }
2145            );
2146        }
2147
2148        #[test]
2149        fn should_be_able_to_deserialize_full_payload_from_json() {
2150            let value = serde_json::json!({
2151                "type": "search",
2152                "query": {
2153                    "target": "contents",
2154                    "condition": {
2155                        "type": "equals",
2156                        "value": "hello world",
2157                    },
2158                    "paths": ["path"],
2159                    "options": {
2160                        "allowed_file_types": ["file"],
2161                        "include": {
2162                            "type": "equals",
2163                            "value": "hello",
2164                        },
2165                        "exclude": {
2166                            "type": "contains",
2167                            "value": "world",
2168                        },
2169                        "upward": true,
2170                        "follow_symbolic_links": true,
2171                        "limit": u64::MAX,
2172                        "max_depth": u64::MAX,
2173                        "pagination": u64::MAX,
2174                        "ignore_hidden": true,
2175                        "use_ignore_files": true,
2176                        "use_parent_ignore_files": true,
2177                        "use_git_ignore_files": true,
2178                        "use_global_git_ignore_files": true,
2179                        "use_git_exclude_files": true,
2180                    },
2181                },
2182            });
2183
2184            let payload: Request = serde_json::from_value(value).unwrap();
2185            assert_eq!(
2186                payload,
2187                Request::Search {
2188                    query: SearchQuery {
2189                        target: SearchQueryTarget::Contents,
2190                        condition: SearchQueryCondition::equals("hello world"),
2191                        paths: vec![PathBuf::from("path")],
2192                        options: SearchQueryOptions {
2193                            allowed_file_types: [FileType::File].into_iter().collect(),
2194                            include: Some(SearchQueryCondition::Equals {
2195                                value: String::from("hello"),
2196                            }),
2197                            exclude: Some(SearchQueryCondition::Contains {
2198                                value: String::from("world"),
2199                            }),
2200                            upward: true,
2201                            follow_symbolic_links: true,
2202                            limit: Some(u64::MAX),
2203                            max_depth: Some(u64::MAX),
2204                            pagination: Some(u64::MAX),
2205                            ignore_hidden: true,
2206                            use_ignore_files: true,
2207                            use_parent_ignore_files: true,
2208                            use_git_ignore_files: true,
2209                            use_global_git_ignore_files: true,
2210                            use_git_exclude_files: true,
2211                        },
2212                    },
2213                }
2214            );
2215        }
2216
2217        #[test]
2218        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
2219            let payload = Request::Search {
2220                query: SearchQuery {
2221                    target: SearchQueryTarget::Contents,
2222                    condition: SearchQueryCondition::equals("hello world"),
2223                    paths: vec![PathBuf::from("path")],
2224                    options: Default::default(),
2225                },
2226            };
2227
2228            // NOTE: We don't actually check the output here because it's an implementation detail
2229            // and could change as we change how serialization is done. This is merely to verify
2230            // that we can serialize since there are times when serde fails to serialize at
2231            // runtime.
2232            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2233        }
2234
2235        #[test]
2236        fn should_be_able_to_serialize_full_payload_to_msgpack() {
2237            let payload = Request::Search {
2238                query: SearchQuery {
2239                    target: SearchQueryTarget::Contents,
2240                    condition: SearchQueryCondition::equals("hello world"),
2241                    paths: vec![PathBuf::from("path")],
2242                    options: SearchQueryOptions {
2243                        allowed_file_types: [FileType::File].into_iter().collect(),
2244                        include: Some(SearchQueryCondition::Equals {
2245                            value: String::from("hello"),
2246                        }),
2247                        exclude: Some(SearchQueryCondition::Contains {
2248                            value: String::from("world"),
2249                        }),
2250                        upward: true,
2251                        follow_symbolic_links: true,
2252                        limit: Some(u64::MAX),
2253                        max_depth: Some(u64::MAX),
2254                        pagination: Some(u64::MAX),
2255                        ignore_hidden: true,
2256                        use_ignore_files: true,
2257                        use_parent_ignore_files: true,
2258                        use_git_ignore_files: true,
2259                        use_global_git_ignore_files: true,
2260                        use_git_exclude_files: true,
2261                    },
2262                },
2263            };
2264
2265            // NOTE: We don't actually check the output here because it's an implementation detail
2266            // and could change as we change how serialization is done. This is merely to verify
2267            // that we can serialize since there are times when serde fails to serialize at
2268            // runtime.
2269            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2270        }
2271
2272        #[test]
2273        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
2274            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2275            // verify that we are not corrupting or causing issues when serializing on a
2276            // client/server and then trying to deserialize on the other side. This has happened
2277            // enough times with minor changes that we need tests to verify.
2278            let buf = rmp_serde::encode::to_vec_named(&Request::Search {
2279                query: SearchQuery {
2280                    target: SearchQueryTarget::Contents,
2281                    condition: SearchQueryCondition::equals("hello world"),
2282                    paths: vec![PathBuf::from("path")],
2283                    options: Default::default(),
2284                },
2285            })
2286            .unwrap();
2287
2288            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2289            assert_eq!(
2290                payload,
2291                Request::Search {
2292                    query: SearchQuery {
2293                        target: SearchQueryTarget::Contents,
2294                        condition: SearchQueryCondition::equals("hello world"),
2295                        paths: vec![PathBuf::from("path")],
2296                        options: Default::default(),
2297                    },
2298                }
2299            );
2300        }
2301
2302        #[test]
2303        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
2304            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2305            // verify that we are not corrupting or causing issues when serializing on a
2306            // client/server and then trying to deserialize on the other side. This has happened
2307            // enough times with minor changes that we need tests to verify.
2308            let buf = rmp_serde::encode::to_vec_named(&Request::Search {
2309                query: SearchQuery {
2310                    target: SearchQueryTarget::Contents,
2311                    condition: SearchQueryCondition::equals("hello world"),
2312                    paths: vec![PathBuf::from("path")],
2313                    options: SearchQueryOptions {
2314                        allowed_file_types: [FileType::File].into_iter().collect(),
2315                        include: Some(SearchQueryCondition::Equals {
2316                            value: String::from("hello"),
2317                        }),
2318                        exclude: Some(SearchQueryCondition::Contains {
2319                            value: String::from("world"),
2320                        }),
2321                        upward: true,
2322                        follow_symbolic_links: true,
2323                        limit: Some(u64::MAX),
2324                        max_depth: Some(u64::MAX),
2325                        pagination: Some(u64::MAX),
2326                        ignore_hidden: true,
2327                        use_ignore_files: true,
2328                        use_parent_ignore_files: true,
2329                        use_git_ignore_files: true,
2330                        use_global_git_ignore_files: true,
2331                        use_git_exclude_files: true,
2332                    },
2333                },
2334            })
2335            .unwrap();
2336
2337            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2338            assert_eq!(
2339                payload,
2340                Request::Search {
2341                    query: SearchQuery {
2342                        target: SearchQueryTarget::Contents,
2343                        condition: SearchQueryCondition::equals("hello world"),
2344                        paths: vec![PathBuf::from("path")],
2345                        options: SearchQueryOptions {
2346                            allowed_file_types: [FileType::File].into_iter().collect(),
2347                            include: Some(SearchQueryCondition::Equals {
2348                                value: String::from("hello"),
2349                            }),
2350                            exclude: Some(SearchQueryCondition::Contains {
2351                                value: String::from("world"),
2352                            }),
2353                            upward: true,
2354                            follow_symbolic_links: true,
2355                            limit: Some(u64::MAX),
2356                            max_depth: Some(u64::MAX),
2357                            pagination: Some(u64::MAX),
2358                            ignore_hidden: true,
2359                            use_ignore_files: true,
2360                            use_parent_ignore_files: true,
2361                            use_git_ignore_files: true,
2362                            use_global_git_ignore_files: true,
2363                            use_git_exclude_files: true,
2364                        },
2365                    },
2366                }
2367            );
2368        }
2369    }
2370
2371    mod cancel_search {
2372        use super::*;
2373
2374        #[test]
2375        fn should_be_able_to_serialize_to_json() {
2376            let payload = Request::CancelSearch { id: u32::MAX };
2377
2378            let value = serde_json::to_value(payload).unwrap();
2379            assert_eq!(
2380                value,
2381                serde_json::json!({
2382                    "type": "cancel_search",
2383                    "id": u32::MAX,
2384                })
2385            );
2386        }
2387
2388        #[test]
2389        fn should_be_able_to_deserialize_from_json() {
2390            let value = serde_json::json!({
2391                "type": "cancel_search",
2392                "id": u32::MAX,
2393            });
2394
2395            let payload: Request = serde_json::from_value(value).unwrap();
2396            assert_eq!(payload, Request::CancelSearch { id: u32::MAX });
2397        }
2398
2399        #[test]
2400        fn should_be_able_to_serialize_to_msgpack() {
2401            let payload = Request::CancelSearch { id: u32::MAX };
2402
2403            // NOTE: We don't actually check the output here because it's an implementation detail
2404            // and could change as we change how serialization is done. This is merely to verify
2405            // that we can serialize since there are times when serde fails to serialize at
2406            // runtime.
2407            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2408        }
2409
2410        #[test]
2411        fn should_be_able_to_deserialize_from_msgpack() {
2412            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2413            // verify that we are not corrupting or causing issues when serializing on a
2414            // client/server and then trying to deserialize on the other side. This has happened
2415            // enough times with minor changes that we need tests to verify.
2416            let buf =
2417                rmp_serde::encode::to_vec_named(&Request::CancelSearch { id: u32::MAX }).unwrap();
2418
2419            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2420            assert_eq!(payload, Request::CancelSearch { id: u32::MAX });
2421        }
2422    }
2423
2424    mod proc_spawn {
2425        use super::*;
2426
2427        #[test]
2428        fn should_be_able_to_serialize_minimal_payload_to_json() {
2429            let payload = Request::ProcSpawn {
2430                cmd: Cmd::new("echo some text"),
2431                environment: Environment::new(),
2432                current_dir: None,
2433                pty: None,
2434            };
2435
2436            let value = serde_json::to_value(payload).unwrap();
2437            assert_eq!(
2438                value,
2439                serde_json::json!({
2440                    "type": "proc_spawn",
2441                    "cmd": "echo some text",
2442                })
2443            );
2444        }
2445
2446        #[test]
2447        fn should_be_able_to_serialize_full_payload_to_json() {
2448            let payload = Request::ProcSpawn {
2449                cmd: Cmd::new("echo some text"),
2450                environment: [(String::from("hello"), String::from("world"))]
2451                    .into_iter()
2452                    .collect(),
2453                current_dir: Some(PathBuf::from("current-dir")),
2454                pty: Some(PtySize {
2455                    rows: u16::MAX,
2456                    cols: u16::MAX,
2457                    pixel_width: u16::MAX,
2458                    pixel_height: u16::MAX,
2459                }),
2460            };
2461
2462            let value = serde_json::to_value(payload).unwrap();
2463            assert_eq!(
2464                value,
2465                serde_json::json!({
2466                    "type": "proc_spawn",
2467                    "cmd": "echo some text",
2468                    "environment": { "hello": "world" },
2469                    "current_dir": "current-dir",
2470                    "pty": {
2471                        "rows": u16::MAX,
2472                        "cols": u16::MAX,
2473                        "pixel_width": u16::MAX,
2474                        "pixel_height": u16::MAX,
2475                    },
2476                })
2477            );
2478        }
2479
2480        #[test]
2481        fn should_be_able_to_deserialize_minimal_payload_from_json() {
2482            let value = serde_json::json!({
2483                "type": "proc_spawn",
2484                "cmd": "echo some text",
2485            });
2486
2487            let payload: Request = serde_json::from_value(value).unwrap();
2488            assert_eq!(
2489                payload,
2490                Request::ProcSpawn {
2491                    cmd: Cmd::new("echo some text"),
2492                    environment: Environment::new(),
2493                    current_dir: None,
2494                    pty: None,
2495                }
2496            );
2497        }
2498
2499        #[test]
2500        fn should_be_able_to_deserialize_full_payload_from_json() {
2501            let value = serde_json::json!({
2502                "type": "proc_spawn",
2503                "cmd": "echo some text",
2504                "environment": { "hello": "world" },
2505                "current_dir": "current-dir",
2506                "pty": {
2507                    "rows": u16::MAX,
2508                    "cols": u16::MAX,
2509                    "pixel_width": u16::MAX,
2510                    "pixel_height": u16::MAX,
2511                },
2512            });
2513
2514            let payload: Request = serde_json::from_value(value).unwrap();
2515            assert_eq!(
2516                payload,
2517                Request::ProcSpawn {
2518                    cmd: Cmd::new("echo some text"),
2519                    environment: [(String::from("hello"), String::from("world"))]
2520                        .into_iter()
2521                        .collect(),
2522                    current_dir: Some(PathBuf::from("current-dir")),
2523                    pty: Some(PtySize {
2524                        rows: u16::MAX,
2525                        cols: u16::MAX,
2526                        pixel_width: u16::MAX,
2527                        pixel_height: u16::MAX,
2528                    }),
2529                }
2530            );
2531        }
2532
2533        #[test]
2534        fn should_be_able_to_serialize_minimal_payload_to_msgpack() {
2535            let payload = Request::ProcSpawn {
2536                cmd: Cmd::new("echo some text"),
2537                environment: Environment::new(),
2538                current_dir: None,
2539                pty: None,
2540            };
2541
2542            // NOTE: We don't actually check the output here because it's an implementation detail
2543            // and could change as we change how serialization is done. This is merely to verify
2544            // that we can serialize since there are times when serde fails to serialize at
2545            // runtime.
2546            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2547        }
2548
2549        #[test]
2550        fn should_be_able_to_serialize_full_payload_to_msgpack() {
2551            let payload = Request::ProcSpawn {
2552                cmd: Cmd::new("echo some text"),
2553                environment: [(String::from("hello"), String::from("world"))]
2554                    .into_iter()
2555                    .collect(),
2556                current_dir: Some(PathBuf::from("current-dir")),
2557                pty: Some(PtySize {
2558                    rows: u16::MAX,
2559                    cols: u16::MAX,
2560                    pixel_width: u16::MAX,
2561                    pixel_height: u16::MAX,
2562                }),
2563            };
2564
2565            // NOTE: We don't actually check the output here because it's an implementation detail
2566            // and could change as we change how serialization is done. This is merely to verify
2567            // that we can serialize since there are times when serde fails to serialize at
2568            // runtime.
2569            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2570        }
2571
2572        #[test]
2573        fn should_be_able_to_deserialize_minimal_payload_from_msgpack() {
2574            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2575            // verify that we are not corrupting or causing issues when serializing on a
2576            // client/server and then trying to deserialize on the other side. This has happened
2577            // enough times with minor changes that we need tests to verify.
2578            let buf = rmp_serde::encode::to_vec_named(&Request::ProcSpawn {
2579                cmd: Cmd::new("echo some text"),
2580                environment: Environment::new(),
2581                current_dir: None,
2582                pty: None,
2583            })
2584            .unwrap();
2585
2586            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2587            assert_eq!(
2588                payload,
2589                Request::ProcSpawn {
2590                    cmd: Cmd::new("echo some text"),
2591                    environment: Environment::new(),
2592                    current_dir: None,
2593                    pty: None,
2594                }
2595            );
2596        }
2597
2598        #[test]
2599        fn should_be_able_to_deserialize_full_payload_from_msgpack() {
2600            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2601            // verify that we are not corrupting or causing issues when serializing on a
2602            // client/server and then trying to deserialize on the other side. This has happened
2603            // enough times with minor changes that we need tests to verify.
2604            let buf = rmp_serde::encode::to_vec_named(&Request::ProcSpawn {
2605                cmd: Cmd::new("echo some text"),
2606                environment: [(String::from("hello"), String::from("world"))]
2607                    .into_iter()
2608                    .collect(),
2609                current_dir: Some(PathBuf::from("current-dir")),
2610                pty: Some(PtySize {
2611                    rows: u16::MAX,
2612                    cols: u16::MAX,
2613                    pixel_width: u16::MAX,
2614                    pixel_height: u16::MAX,
2615                }),
2616            })
2617            .unwrap();
2618
2619            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2620            assert_eq!(
2621                payload,
2622                Request::ProcSpawn {
2623                    cmd: Cmd::new("echo some text"),
2624                    environment: [(String::from("hello"), String::from("world"))]
2625                        .into_iter()
2626                        .collect(),
2627                    current_dir: Some(PathBuf::from("current-dir")),
2628                    pty: Some(PtySize {
2629                        rows: u16::MAX,
2630                        cols: u16::MAX,
2631                        pixel_width: u16::MAX,
2632                        pixel_height: u16::MAX,
2633                    }),
2634                }
2635            );
2636        }
2637    }
2638
2639    mod proc_kill {
2640        use super::*;
2641
2642        #[test]
2643        fn should_be_able_to_serialize_to_json() {
2644            let payload = Request::ProcKill { id: u32::MAX };
2645
2646            let value = serde_json::to_value(payload).unwrap();
2647            assert_eq!(
2648                value,
2649                serde_json::json!({
2650                    "type": "proc_kill",
2651                    "id": u32::MAX,
2652                })
2653            );
2654        }
2655
2656        #[test]
2657        fn should_be_able_to_deserialize_from_json() {
2658            let value = serde_json::json!({
2659                "type": "proc_kill",
2660                "id": u32::MAX,
2661            });
2662
2663            let payload: Request = serde_json::from_value(value).unwrap();
2664            assert_eq!(payload, Request::ProcKill { id: u32::MAX });
2665        }
2666
2667        #[test]
2668        fn should_be_able_to_serialize_to_msgpack() {
2669            let payload = Request::ProcKill { id: u32::MAX };
2670
2671            // NOTE: We don't actually check the output here because it's an implementation detail
2672            // and could change as we change how serialization is done. This is merely to verify
2673            // that we can serialize since there are times when serde fails to serialize at
2674            // runtime.
2675            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2676        }
2677
2678        #[test]
2679        fn should_be_able_to_deserialize_from_msgpack() {
2680            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2681            // verify that we are not corrupting or causing issues when serializing on a
2682            // client/server and then trying to deserialize on the other side. This has happened
2683            // enough times with minor changes that we need tests to verify.
2684            let buf = rmp_serde::encode::to_vec_named(&Request::ProcKill { id: u32::MAX }).unwrap();
2685
2686            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2687            assert_eq!(payload, Request::ProcKill { id: u32::MAX });
2688        }
2689    }
2690
2691    mod proc_stdin {
2692        use super::*;
2693
2694        #[test]
2695        fn should_be_able_to_serialize_to_json() {
2696            let payload = Request::ProcStdin {
2697                id: u32::MAX,
2698                data: vec![0, 1, 2, 3, u8::MAX],
2699            };
2700
2701            let value = serde_json::to_value(payload).unwrap();
2702            assert_eq!(
2703                value,
2704                serde_json::json!({
2705                    "type": "proc_stdin",
2706                    "id": u32::MAX,
2707                    "data": [0, 1, 2, 3, u8::MAX],
2708                })
2709            );
2710        }
2711
2712        #[test]
2713        fn should_be_able_to_deserialize_from_json() {
2714            let value = serde_json::json!({
2715                "type": "proc_stdin",
2716                "id": u32::MAX,
2717                "data": [0, 1, 2, 3, u8::MAX],
2718            });
2719
2720            let payload: Request = serde_json::from_value(value).unwrap();
2721            assert_eq!(
2722                payload,
2723                Request::ProcStdin {
2724                    id: u32::MAX,
2725                    data: vec![0, 1, 2, 3, u8::MAX],
2726                }
2727            );
2728        }
2729
2730        #[test]
2731        fn should_be_able_to_serialize_to_msgpack() {
2732            let payload = Request::ProcStdin {
2733                id: u32::MAX,
2734                data: vec![0, 1, 2, 3, u8::MAX],
2735            };
2736
2737            // NOTE: We don't actually check the output here because it's an implementation detail
2738            // and could change as we change how serialization is done. This is merely to verify
2739            // that we can serialize since there are times when serde fails to serialize at
2740            // runtime.
2741            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2742        }
2743
2744        #[test]
2745        fn should_be_able_to_deserialize_from_msgpack() {
2746            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2747            // verify that we are not corrupting or causing issues when serializing on a
2748            // client/server and then trying to deserialize on the other side. This has happened
2749            // enough times with minor changes that we need tests to verify.
2750            let buf = rmp_serde::encode::to_vec_named(&Request::ProcStdin {
2751                id: u32::MAX,
2752                data: vec![0, 1, 2, 3, u8::MAX],
2753            })
2754            .unwrap();
2755
2756            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2757            assert_eq!(
2758                payload,
2759                Request::ProcStdin {
2760                    id: u32::MAX,
2761                    data: vec![0, 1, 2, 3, u8::MAX],
2762                }
2763            );
2764        }
2765    }
2766
2767    mod proc_resize_pty {
2768        use super::*;
2769
2770        #[test]
2771        fn should_be_able_to_serialize_to_json() {
2772            let payload = Request::ProcResizePty {
2773                id: u32::MAX,
2774                size: PtySize {
2775                    rows: u16::MAX,
2776                    cols: u16::MAX,
2777                    pixel_width: u16::MAX,
2778                    pixel_height: u16::MAX,
2779                },
2780            };
2781
2782            let value = serde_json::to_value(payload).unwrap();
2783            assert_eq!(
2784                value,
2785                serde_json::json!({
2786                    "type": "proc_resize_pty",
2787                    "id": u32::MAX,
2788                    "size": {
2789                        "rows": u16::MAX,
2790                        "cols": u16::MAX,
2791                        "pixel_width": u16::MAX,
2792                        "pixel_height": u16::MAX,
2793                    },
2794                })
2795            );
2796        }
2797
2798        #[test]
2799        fn should_be_able_to_deserialize_from_json() {
2800            let value = serde_json::json!({
2801                "type": "proc_resize_pty",
2802                "id": u32::MAX,
2803                "size": {
2804                    "rows": u16::MAX,
2805                    "cols": u16::MAX,
2806                    "pixel_width": u16::MAX,
2807                    "pixel_height": u16::MAX,
2808                },
2809            });
2810
2811            let payload: Request = serde_json::from_value(value).unwrap();
2812            assert_eq!(
2813                payload,
2814                Request::ProcResizePty {
2815                    id: u32::MAX,
2816                    size: PtySize {
2817                        rows: u16::MAX,
2818                        cols: u16::MAX,
2819                        pixel_width: u16::MAX,
2820                        pixel_height: u16::MAX,
2821                    },
2822                }
2823            );
2824        }
2825
2826        #[test]
2827        fn should_be_able_to_serialize_to_msgpack() {
2828            let payload = Request::ProcResizePty {
2829                id: u32::MAX,
2830                size: PtySize {
2831                    rows: u16::MAX,
2832                    cols: u16::MAX,
2833                    pixel_width: u16::MAX,
2834                    pixel_height: u16::MAX,
2835                },
2836            };
2837
2838            // NOTE: We don't actually check the output here because it's an implementation detail
2839            // and could change as we change how serialization is done. This is merely to verify
2840            // that we can serialize since there are times when serde fails to serialize at
2841            // runtime.
2842            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2843        }
2844
2845        #[test]
2846        fn should_be_able_to_deserialize_from_msgpack() {
2847            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2848            // verify that we are not corrupting or causing issues when serializing on a
2849            // client/server and then trying to deserialize on the other side. This has happened
2850            // enough times with minor changes that we need tests to verify.
2851            let buf = rmp_serde::encode::to_vec_named(&Request::ProcResizePty {
2852                id: u32::MAX,
2853                size: PtySize {
2854                    rows: u16::MAX,
2855                    cols: u16::MAX,
2856                    pixel_width: u16::MAX,
2857                    pixel_height: u16::MAX,
2858                },
2859            })
2860            .unwrap();
2861
2862            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2863            assert_eq!(
2864                payload,
2865                Request::ProcResizePty {
2866                    id: u32::MAX,
2867                    size: PtySize {
2868                        rows: u16::MAX,
2869                        cols: u16::MAX,
2870                        pixel_width: u16::MAX,
2871                        pixel_height: u16::MAX,
2872                    },
2873                }
2874            );
2875        }
2876    }
2877
2878    mod system_info {
2879        use super::*;
2880
2881        #[test]
2882        fn should_be_able_to_serialize_to_json() {
2883            let payload = Request::SystemInfo {};
2884
2885            let value = serde_json::to_value(payload).unwrap();
2886            assert_eq!(
2887                value,
2888                serde_json::json!({
2889                    "type": "system_info",
2890                })
2891            );
2892        }
2893
2894        #[test]
2895        fn should_be_able_to_deserialize_from_json() {
2896            let value = serde_json::json!({
2897                "type": "system_info",
2898            });
2899
2900            let payload: Request = serde_json::from_value(value).unwrap();
2901            assert_eq!(payload, Request::SystemInfo {});
2902        }
2903
2904        #[test]
2905        fn should_be_able_to_serialize_to_msgpack() {
2906            let payload = Request::SystemInfo {};
2907
2908            // NOTE: We don't actually check the output here because it's an implementation detail
2909            // and could change as we change how serialization is done. This is merely to verify
2910            // that we can serialize since there are times when serde fails to serialize at
2911            // runtime.
2912            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2913        }
2914
2915        #[test]
2916        fn should_be_able_to_deserialize_from_msgpack() {
2917            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2918            // verify that we are not corrupting or causing issues when serializing on a
2919            // client/server and then trying to deserialize on the other side. This has happened
2920            // enough times with minor changes that we need tests to verify.
2921            let buf = rmp_serde::encode::to_vec_named(&Request::SystemInfo {}).unwrap();
2922
2923            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2924            assert_eq!(payload, Request::SystemInfo {});
2925        }
2926    }
2927
2928    mod version {
2929        use super::*;
2930
2931        #[test]
2932        fn should_be_able_to_serialize_to_json() {
2933            let payload = Request::Version {};
2934
2935            let value = serde_json::to_value(payload).unwrap();
2936            assert_eq!(
2937                value,
2938                serde_json::json!({
2939                    "type": "version",
2940                })
2941            );
2942        }
2943
2944        #[test]
2945        fn should_be_able_to_deserialize_from_json() {
2946            let value = serde_json::json!({
2947                "type": "version",
2948            });
2949
2950            let payload: Request = serde_json::from_value(value).unwrap();
2951            assert_eq!(payload, Request::Version {});
2952        }
2953
2954        #[test]
2955        fn should_be_able_to_serialize_to_msgpack() {
2956            let payload = Request::Version {};
2957
2958            // NOTE: We don't actually check the output here because it's an implementation detail
2959            // and could change as we change how serialization is done. This is merely to verify
2960            // that we can serialize since there are times when serde fails to serialize at
2961            // runtime.
2962            let _ = rmp_serde::encode::to_vec_named(&payload).unwrap();
2963        }
2964
2965        #[test]
2966        fn should_be_able_to_deserialize_from_msgpack() {
2967            // NOTE: It may seem odd that we are serializing just to deserialize, but this is to
2968            // verify that we are not corrupting or causing issues when serializing on a
2969            // client/server and then trying to deserialize on the other side. This has happened
2970            // enough times with minor changes that we need tests to verify.
2971            let buf = rmp_serde::encode::to_vec_named(&Request::Version {}).unwrap();
2972
2973            let payload: Request = rmp_serde::decode::from_slice(&buf).unwrap();
2974            assert_eq!(payload, Request::Version {});
2975        }
2976    }
2977}