Skip to content

Commit ed85ff7

Browse files
committed
comments and more deps
1 parent 3317944 commit ed85ff7

4 files changed

Lines changed: 55 additions & 51 deletions

File tree

cli/Cargo.lock

Lines changed: 11 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ http-body-util = "0.1"
4343
tokio-tungstenite = { version = "0.29", features = ["native-tls"] }
4444
indicatif = "0.17.4"
4545
tempfile = "3.5.0"
46-
clap_lex = "0.7.0"
46+
clap_lex = "1"
4747
url = "2.5.4"
4848
log = "0.4.18"
4949
const_format = "0.2.31"
5050
sha2 = "0.10.6"
51-
base64 = "0.21.2"
51+
base64 = "0.22"
5252
shell-escape = "0.1.5"
53-
thiserror = "1.0.40"
53+
thiserror = "2"
5454
cfg-if = "1.0.0"
5555
pin-project = "1.1.0"
5656
console = "0.15.7"
@@ -67,9 +67,9 @@ serde_json = "1.0.96"
6767
winresource = "0.1"
6868

6969
[target.'cfg(windows)'.dependencies]
70-
winreg = "0.50.0"
70+
winreg = "0.56"
7171
winapi = "0.3.9"
72-
windows-sys = { version = "0.59.0", features = ["Win32_System_Console", "Win32_UI_Input_KeyboardAndMouse"] }
72+
windows-sys = { version = "0.61", features = ["Win32_System_Console", "Win32_UI_Input_KeyboardAndMouse"] }
7373

7474
[target.'cfg(target_os = "macos")'.dependencies]
7575
core-foundation = "0.9.3"

cli/src/commands/agent_host.rs

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use super::CommandContext;
3939
/// commands (e.g. `code agent ps`) can discover a running agent host.
4040
#[derive(Debug, Clone, Serialize, Deserialize)]
4141
pub struct AgentHostLockData {
42-
/// WebSocket address the agent host is listening on (e.g. `ws://127.0.0.1:4567`).
42+
/// WebSocket address the agent host is listening on (e.g. `ws://127.0.0.1:4567/`).
4343
pub address: String,
4444
/// PID of the CLI process running the agent host.
4545
pub pid: u32,
@@ -125,10 +125,7 @@ pub async fn agent_host(ctx: CommandContext, mut args: AgentHostArgs) -> Result<
125125
.local_addr()
126126
.map_err(CodeError::CouldNotListenOnInterface)?;
127127

128-
let mut url = format!("ws://{bound_addr}");
129-
if let Some(ct) = &args.connection_token {
130-
url.push_str(&format!("?tkn={ct}"));
131-
}
128+
let local_agent_host_url = format!("ws://{bound_addr}/");
132129

133130
let product = constants::QUALITYLESS_PRODUCT_NAME;
134131
let token_suffix = args
@@ -199,12 +196,12 @@ pub async fn agent_host(ctx: CommandContext, mut args: AgentHostArgs) -> Result<
199196
// Write lockfile so `code agent ps` can discover this instance.
200197
let lockfile_path = ctx.paths.agent_host_lockfile();
201198
let lock_data = AgentHostLockData {
202-
address: format!("ws://{bound_addr}/"),
199+
address: local_agent_host_url,
203200
pid: std::process::id(),
204201
connection_token: args.connection_token.clone(),
205202
tunnel_name: tunnel_name.clone(),
206203
};
207-
if let Err(e) = fs::write(&lockfile_path, serde_json::to_string(&lock_data).unwrap()) {
204+
if let Err(e) = write_agent_host_lockfile(&lockfile_path, &lock_data) {
208205
warning!(ctx.log, "Failed to write agent host lockfile: {}", e);
209206
}
210207

@@ -290,29 +287,45 @@ fn mint_connection_token(path: &Path, prefer_token: Option<String>) -> std::io::
290287
#[cfg(not(windows))]
291288
use std::os::unix::fs::OpenOptionsExt;
292289

293-
let mut f = fs::OpenOptions::new();
294-
f.create(true);
295-
f.write(true);
296-
f.read(true);
290+
let mut file_options = fs::OpenOptions::new();
291+
file_options.create(true);
292+
file_options.write(true);
293+
file_options.read(true);
297294
#[cfg(not(windows))]
298-
f.mode(0o600);
299-
let mut f = f.open(path)?;
295+
file_options.mode(0o600);
296+
let mut file = file_options.open(path)?;
300297

301298
if prefer_token.is_none() {
302-
let mut t = String::new();
303-
f.read_to_string(&mut t)?;
304-
let t = t.trim();
305-
if !t.is_empty() {
306-
return Ok(t.to_string());
299+
let mut token = String::new();
300+
file.read_to_string(&mut token)?;
301+
let token = token.trim();
302+
if !token.is_empty() {
303+
return Ok(token.to_string());
307304
}
308305
}
309306

310-
f.set_len(0)?;
307+
file.set_len(0)?;
311308
let prefer_token = prefer_token.unwrap_or_else(|| uuid::Uuid::new_v4().to_string());
312-
f.write_all(prefer_token.as_bytes())?;
309+
file.write_all(prefer_token.as_bytes())?;
313310
Ok(prefer_token)
314311
}
315312

313+
fn write_agent_host_lockfile(path: &Path, lock_data: &AgentHostLockData) -> std::io::Result<()> {
314+
#[cfg(not(windows))]
315+
use std::os::unix::fs::{OpenOptionsExt, PermissionsExt};
316+
317+
let mut file_options = fs::OpenOptions::new();
318+
file_options.create(true);
319+
file_options.write(true);
320+
file_options.truncate(true);
321+
#[cfg(not(windows))]
322+
file_options.mode(0o600);
323+
let mut file = file_options.open(path)?;
324+
#[cfg(not(windows))]
325+
file.set_permissions(fs::Permissions::from_mode(0o600))?;
326+
file.write_all(serde_json::to_string(lock_data).unwrap().as_bytes())
327+
}
328+
316329
#[cfg(test)]
317330
mod tests {
318331
use super::*;

cli/src/util/io.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ where
6868

6969
Ok(bytes_so_far)
7070
}
71-
7271
/// Helper used when converting Future interfaces to poll-based interfaces.
7372
/// Stores excess data that can be reused on future polls.
7473
#[derive(Default)]
@@ -221,7 +220,7 @@ pub fn tailf(file: File, n: usize) -> mpsc::UnboundedReceiver<TailEvent> {
221220

222221
#[cfg(test)]
223222
mod tests {
224-
use rand::Rng;
223+
use rand::RngExt;
225224
use std::{fs::OpenOptions, io::Write};
226225

227226
use super::*;
@@ -315,7 +314,11 @@ mod tests {
315314
let mut written = vec![];
316315
let base_line = "Elit ipsum cillum ex cillum. Adipisicing consequat cupidatat do proident ut in sunt Lorem ipsum tempor. Eiusmod ipsum Lorem labore exercitation sunt pariatur excepteur fugiat cillum velit cillum enim. Nisi Lorem cupidatat ad enim velit officia eiusmod esse tempor aliquip. Deserunt pariatur tempor in duis culpa esse sit nulla irure ullamco ipsum voluptate non laboris. Occaecat officia nulla officia mollit do aliquip reprehenderit ad incididunt.";
317316
for i in 0..100 {
318-
let line = format!("{}: {}", i, &base_line[..rng.gen_range(0..base_line.len())]);
317+
let line = format!(
318+
"{}: {}",
319+
i,
320+
&base_line[..rng.random_range(0..base_line.len())]
321+
);
319322
writeln!(&mut read_file, "{line}").unwrap();
320323
written.push(line);
321324
}

0 commit comments

Comments
 (0)