1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! PATCH /api/v1/sessions/managed/{id} — rename a managed session.
//!
//! Why: `tm sessions rename` needs a daemon endpoint because the daemon owns
//! the [`crate::session_manager::SessionManager`] (the store + the live tmux
//! sessions); a rename mutates both, so it cannot be done from the thin CLI
//! client. Split into its own file (like `reactivate.rs`/`prune.rs`) so the
//! handler + request type do not grow `mod.rs`, which sits near its 500-SLOC
//! production cap.
//! What: [`RenameRequest`] (the `{ "name": … }` body) and
//! [`rename_managed_session`], which delegates to
//! [`crate::session_manager::SessionManager::rename`] and maps its typed errors
//! to HTTP status codes.
//! Test: `rename_route_*` in `tests/session_lifecycle.rs`.
use Arc;
use ;
use Deserialize;
use ;
use crateDaemonState;
use crateManagedError;
/// Request body for PATCH /api/v1/sessions/managed/{id}.
///
/// Why: rename takes exactly one caller input — the new name; a small typed
/// body keeps it explicit and validated (the manager rejects a bad name).
/// What: a single `name` field.
/// Test: `rename_route_renames` in `tests/session_lifecycle.rs`.
/// PATCH /api/v1/sessions/managed/{id} — rename a managed session.
///
/// Why: keeps the tmux entity's name in sync with the record's `tmux_name` so
/// operators can give a session a meaningful name and have `tmux attach`/`ls`
/// reflect it.
/// What: parses the id, delegates to
/// [`crate::session_manager::SessionManager::rename`], and maps its result —
/// `Ok` → 200 with the updated session summary (`name` may differ from the
/// request body if it collided and was auto-suffixed, issue #3692 —
/// `rename` no longer rejects a collision); `SessionNotFound` → 404;
/// `NameCollision` → 409 with the actionable message (retained for any other
/// caller of this shared error type; `rename` itself no longer produces it);
/// `InvalidState` (an invalid name, or a terminal record) → 400; any other
/// error → 500.
/// Test: `rename_route_renames`, `rename_route_suffixes_collision`,
/// `rename_route_rejects_invalid_name` in `tests/session_lifecycle.rs`.
pub async