Skip to content

Commit 53e0948

Browse files
committed
fix: address cross-platform and clippy issues
1 parent abcdbdd commit 53e0948

10 files changed

Lines changed: 59 additions & 28 deletions

File tree

apps/server/src/auth/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ fn random_hex(bytes_len: usize) -> Result<String, String> {
12291229
fn sha256_hex(value: &str) -> String {
12301230
let mut hasher = Sha256::new();
12311231
hasher.update(value.as_bytes());
1232-
hex_encode(&hasher.finalize())
1232+
hex_encode(hasher.finalize())
12331233
}
12341234

12351235
fn hex_encode(bytes: impl AsRef<[u8]>) -> String {

apps/server/src/command/http.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,11 @@ fn dispatch_rpc(
769769
}
770770
}
771771

772-
fn require_loopback(client_addr: std::net::SocketAddr) -> Result<(), Response> {
772+
fn require_loopback(client_addr: std::net::SocketAddr) -> Option<Response> {
773773
if client_addr.ip().is_loopback() {
774-
Ok(())
774+
None
775775
} else {
776-
Err(json_error(
776+
Some(json_error(
777777
StatusCode::FORBIDDEN,
778778
"loopback_required".to_string(),
779779
))
@@ -784,7 +784,7 @@ pub(crate) async fn system_config_handler(
784784
ConnectInfo(client_addr): ConnectInfo<std::net::SocketAddr>,
785785
AxumState(state): AxumState<HttpServerState>,
786786
) -> Response {
787-
if let Err(response) = require_loopback(client_addr) {
787+
if let Some(response) = require_loopback(client_addr) {
788788
return response;
789789
}
790790

@@ -799,7 +799,7 @@ pub(crate) async fn system_config_patch_handler(
799799
AxumState(state): AxumState<HttpServerState>,
800800
Json(payload): Json<Value>,
801801
) -> Response {
802-
if let Err(response) = require_loopback(client_addr) {
802+
if let Some(response) = require_loopback(client_addr) {
803803
return response;
804804
}
805805

@@ -818,7 +818,7 @@ pub(crate) async fn system_auth_status_handler(
818818
ConnectInfo(client_addr): ConnectInfo<std::net::SocketAddr>,
819819
AxumState(state): AxumState<HttpServerState>,
820820
) -> Response {
821-
if let Err(response) = require_loopback(client_addr) {
821+
if let Some(response) = require_loopback(client_addr) {
822822
return response;
823823
}
824824

@@ -832,7 +832,7 @@ pub(crate) async fn system_auth_ip_blocks_handler(
832832
ConnectInfo(client_addr): ConnectInfo<std::net::SocketAddr>,
833833
AxumState(state): AxumState<HttpServerState>,
834834
) -> Response {
835-
if let Err(response) = require_loopback(client_addr) {
835+
if let Some(response) = require_loopback(client_addr) {
836836
return response;
837837
}
838838

@@ -847,7 +847,7 @@ pub(crate) async fn system_auth_ip_unblock_handler(
847847
AxumState(state): AxumState<HttpServerState>,
848848
Json(payload): Json<Value>,
849849
) -> Response {
850-
if let Err(response) = require_loopback(client_addr) {
850+
if let Some(response) = require_loopback(client_addr) {
851851
return response;
852852
}
853853

apps/server/src/infra/runtime.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ pub(crate) fn run_wsl_shell_command(
120120
script: &str,
121121
) -> Result<String, String> {
122122
let mut cmd = Command::new("wsl.exe");
123-
if let ExecTarget::Wsl { distro } = target {
124-
if let Some(d) = distro {
125-
cmd.args(["-d", d]);
126-
}
123+
if let ExecTarget::Wsl {
124+
distro: Some(distro),
125+
} = target
126+
{
127+
cmd.args(["-d", distro]);
127128
}
128129
let shell_cmd = if cwd.is_empty() {
129130
script.to_string()
@@ -422,6 +423,6 @@ pub(crate) fn temp_root(target: &ExecTarget) -> Result<String, String> {
422423

423424
pub(crate) fn repo_name_from_url(url: &str) -> String {
424425
let trimmed = url.trim().trim_end_matches('/');
425-
let name = trimmed.split('/').last().unwrap_or("repo");
426+
let name = trimmed.split('/').next_back().unwrap_or("repo");
426427
name.trim_end_matches(".git").to_string()
427428
}

apps/server/src/services/agent.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,16 @@ pub(crate) fn agent_start(
103103
if text.is_empty() {
104104
continue;
105105
}
106-
emit_agent(&app_handle, &workspace_id_out, &session_out, "stdout", &text);
106+
emit_agent(
107+
&app_handle,
108+
&workspace_id_out,
109+
&session_out,
110+
"stdout",
111+
&text,
112+
);
107113
let state: State<AppState> = state_handle.state();
108-
let _ = append_session_stream(&state, &workspace_id_out, session_out_num, &text);
114+
let _ =
115+
append_session_stream(&state, &workspace_id_out, session_out_num, &text);
109116
}
110117
Err(_) => break,
111118
}
@@ -194,7 +201,12 @@ pub(crate) fn agent_stop(
194201
}
195202
drop(agents);
196203
if let Ok(session_id_num) = session_id.parse::<u64>() {
197-
let _ = set_session_status(&state, &workspace_id, session_id_num, SessionStatus::Interrupted);
204+
let _ = set_session_status(
205+
&state,
206+
&workspace_id,
207+
session_id_num,
208+
SessionStatus::Interrupted,
209+
);
198210
}
199211
Ok(())
200212
}

apps/server/src/services/claude.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ fn handle_claude_hook_payload(app: &tauri::AppHandle, envelope: ClaudeHookEnvelo
8484
{
8585
let state: State<AppState> = app.state();
8686
if let Ok(internal_session_id) = envelope.session_id.parse::<u64>() {
87-
let _ = set_session_claude_id(&state, &envelope.workspace_id, internal_session_id, claude_session_id);
87+
let _ = set_session_claude_id(
88+
&state,
89+
&envelope.workspace_id,
90+
internal_session_id,
91+
claude_session_id,
92+
);
8893
}
8994
}
9095

apps/server/src/services/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub(crate) fn worktree_list(path: String, target: ExecTarget) -> Result<Vec<Work
303303
current.name = current
304304
.path
305305
.split('/')
306-
.last()
306+
.next_back()
307307
.unwrap_or("worktree")
308308
.to_string();
309309
} else if line.starts_with("branch ") {

apps/server/src/services/terminal.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ pub(crate) fn terminal_create(
6868
if let Ok(mut child) = runtime.child.lock() {
6969
let _ = child.wait();
7070
}
71-
emit_terminal(&app_handle, &workspace_id, terminal_id, "\n[terminal exited]\n");
71+
emit_terminal(
72+
&app_handle,
73+
&workspace_id,
74+
terminal_id,
75+
"\n[terminal exited]\n",
76+
);
7277
let state: State<AppState> = state_handle.state();
7378
if let Ok(mut terms) = state.terminals.lock() {
7479
terms.remove(&key);

apps/server/src/ws/server.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) async fn ws_session(mut socket: WebSocket, app: tauri::AppHandle) {
5252
let Ok(body) = serde_json::to_string(&WsEnvelope::Pong { ts }) else {
5353
continue;
5454
};
55-
if socket.send(Message::Text(body.into())).await.is_err() {
55+
if socket.send(Message::Text(body)).await.is_err() {
5656
break;
5757
}
5858
}
@@ -73,7 +73,7 @@ pub(crate) async fn ws_session(mut socket: WebSocket, app: tauri::AppHandle) {
7373
let Ok(text) = serde_json::to_string(&envelope) else {
7474
continue;
7575
};
76-
if socket.send(Message::Text(text.into())).await.is_err() {
76+
if socket.send(Message::Text(text)).await.is_err() {
7777
break;
7878
}
7979
}
@@ -129,7 +129,12 @@ pub(crate) fn emit_agent(
129129
);
130130
}
131131

132-
pub(crate) fn emit_terminal(app: &tauri::AppHandle, workspace_id: &str, terminal_id: u64, data: &str) {
132+
pub(crate) fn emit_terminal(
133+
app: &tauri::AppHandle,
134+
workspace_id: &str,
135+
terminal_id: u64,
136+
data: &str,
137+
) {
133138
emit_transport_event(
134139
app,
135140
"terminal://event",

tests/cli/config.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test('resolveStateDir respects platform defaults', () => {
4444
const linux = resolveStateDir({ XDG_STATE_HOME: '/tmp/xdg-state' }, 'linux');
4545
const darwin = resolveStateDir({}, 'darwin');
4646
assert.equal(linux, path.join('/tmp/xdg-state', 'coder-studio'));
47-
assert.match(darwin, /Library\/Application Support\/coder-studio$/);
47+
assert.ok(darwin.endsWith(path.join('Library', 'Application Support', 'coder-studio')));
4848
});
4949

5050
test('resolveDataDir nests under stateDir by default', () => {

tests/cli/platform.test.mjs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import test from 'node:test';
22
import assert from 'node:assert/strict';
3+
import path from 'node:path';
34
import { resolvePlatformPackage } from '../../.build/cli/lib/platform.mjs';
45

56
test('resolvePlatformPackage supports explicit binary and dist overrides', () => {
7+
const binaryOverride = '/tmp/runtime/coder-studio';
8+
const distOverride = '/tmp/runtime/dist';
69
const result = resolvePlatformPackage({
710
env: {
8-
CODER_STUDIO_BINARY_PATH: '/tmp/runtime/coder-studio',
9-
CODER_STUDIO_DIST_DIR: '/tmp/runtime/dist'
11+
CODER_STUDIO_BINARY_PATH: binaryOverride,
12+
CODER_STUDIO_DIST_DIR: distOverride
1013
},
1114
platform: 'linux',
1215
arch: 'x64'
1316
});
1417

1518
assert.equal(result.packageName, 'override');
16-
assert.equal(result.binaryPath, '/tmp/runtime/coder-studio');
17-
assert.equal(result.distDir, '/tmp/runtime/dist');
19+
assert.equal(result.binaryPath, path.resolve(binaryOverride));
20+
assert.equal(result.distDir, path.resolve(distOverride));
1821
});
1922

2023
test('resolvePlatformPackage rejects unsupported platforms', () => {

0 commit comments

Comments
 (0)