refactor: remove unused functions and frontend declarations
- Remove four redundant Rust functions - Update tests to call the active implementations directly - Remove unused TypeScript state, parameters, and imports - Resolve unused-code compiler warnings
This commit is contained in:
1 parent
a9297b86cc
commit
0725f6ed8a
8 files changed
+25
-58
No files matched your search
@@ -3200,17 +3200,6 @@ pub(crate) fn claude_effective_context_window(
|
||||
context_window
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn claude_code_max_context_tokens(
|
||||
mappings: &ClaudeDesktopModelMappings,
|
||||
models: &[AgentModelOption],
|
||||
) -> Result<u64, String> {
|
||||
let model = mappings.sonnet.as_str();
|
||||
let context_window = claude_effective_context_window(models, model, mappings.sonnet_1m)
|
||||
.ok_or_else(|| format!("CPA 模型 API 未返回 Claude Code 主模型 {model} 的上下文窗口"))?;
|
||||
Ok(context_window)
|
||||
}
|
||||
|
||||
pub(crate) fn agent_model_display_name<'a>(
|
||||
models: &'a [AgentModelOption],
|
||||
model_name: &'a str,
|
||||
|
||||
@@ -1667,15 +1667,6 @@ pub(crate) fn sanitize_gui_config(config: &mut GuiConfigFile) -> Result<bool, St
|
||||
Ok(changed)
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn write_gui_config_legacy(config: &GuiConfigFile) -> Result<(), String> {
|
||||
validate_gui_config(config)?;
|
||||
let config_path = gui_config_path()?;
|
||||
let content =
|
||||
toml::to_string_pretty(config).map_err(|err| format!("序列化 GUI 配置失败: {err}"))?;
|
||||
write_yaml_if_changed(&config_path, &content).map(|_| ())
|
||||
}
|
||||
|
||||
pub(crate) fn write_gui_config(config: &GuiConfigFile) -> Result<(), String> {
|
||||
write_gui_config_to_path(config, &gui_config_path()?)
|
||||
}
|
||||
|
||||
+6
-11
@@ -1894,14 +1894,6 @@ fn set_collector_status(
|
||||
});
|
||||
}
|
||||
|
||||
fn persist_queue_items(
|
||||
root: &Path,
|
||||
items: Vec<Value>,
|
||||
config: &GuiConfigFile,
|
||||
) -> Result<usize, String> {
|
||||
persist_queue_items_from_source(root, HTTP_USAGE_QUEUE_SOURCE, items, config)
|
||||
}
|
||||
|
||||
fn persist_queue_items_from_source(
|
||||
root: &Path,
|
||||
source: &str,
|
||||
@@ -4722,8 +4714,9 @@ mod tests {
|
||||
let root = test_root("usage-control-messages");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
let inserted = persist_queue_items(
|
||||
let inserted = persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({"refresh": true}),
|
||||
serde_json::json!({"support_refresh": true}),
|
||||
@@ -4791,8 +4784,9 @@ mod tests {
|
||||
let root = test_root("queue-events-without-generation");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
let inserted = persist_queue_items(
|
||||
let inserted = persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({
|
||||
"timestamp": "2026-07-29T10:00:00+08:00",
|
||||
@@ -4856,8 +4850,9 @@ mod tests {
|
||||
let root = test_root("usage-failure-details");
|
||||
initialize_usage_storage_at(&root).unwrap();
|
||||
let config = GuiConfigFile::default();
|
||||
persist_queue_items(
|
||||
persist_queue_items_from_source(
|
||||
&root,
|
||||
HTTP_USAGE_QUEUE_SOURCE,
|
||||
vec![
|
||||
serde_json::json!({
|
||||
"timestamp": "2026-07-29T10:00:00+08:00",
|
||||
|
||||
+17
-13
@@ -214,17 +214,6 @@ enum ParseResult {
|
||||
Incomplete,
|
||||
}
|
||||
|
||||
fn parse_resp_frame(input: &[u8], offset: usize, depth: usize) -> Result<ParseResult, String> {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
parse_resp_frame_with_limits(
|
||||
input,
|
||||
offset,
|
||||
depth,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
)
|
||||
}
|
||||
|
||||
fn parse_resp_frame_with_limits(
|
||||
input: &[u8],
|
||||
offset: usize,
|
||||
@@ -384,7 +373,15 @@ mod tests {
|
||||
#[test]
|
||||
fn parses_usage_subscription_message() {
|
||||
let input = b"*3\r\n$7\r\nmessage\r\n$5\r\nusage\r\n$16\r\n{\"request_id\":1}\r\n";
|
||||
let ParseResult::Complete(value, consumed) = parse_resp_frame(input, 0, 0).unwrap() else {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
let ParseResult::Complete(value, consumed) = parse_resp_frame_with_limits(
|
||||
input,
|
||||
0,
|
||||
0,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
)
|
||||
.unwrap() else {
|
||||
panic!("expected complete RESP frame");
|
||||
};
|
||||
assert_eq!(consumed, input.len());
|
||||
@@ -396,7 +393,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rejects_oversized_arrays() {
|
||||
let error = match parse_resp_frame(b"*17\r\n", 0, 0) {
|
||||
let mut remaining_bulk_bytes = SUBSCRIPTION_LIMITS.max_total_bulk_bytes;
|
||||
let error = match parse_resp_frame_with_limits(
|
||||
b"*17\r\n",
|
||||
0,
|
||||
0,
|
||||
SUBSCRIPTION_LIMITS,
|
||||
&mut remaining_bulk_bytes,
|
||||
) {
|
||||
Err(error) => error,
|
||||
_ => panic!("expected oversized RESP array to fail"),
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user