@mmmbuto/anthmorph 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +48 -123
- package/bin/anthmorph +0 -0
- package/docs/CLAUDE_CODE_SETUP.md +78 -0
- package/docs/PACKAGING.md +59 -0
- package/docs/RELEASE.md +82 -0
- package/package.json +16 -4
- package/scripts/anthmorphctl +150 -8
- package/scripts/docker_build_linux.sh +11 -0
- package/scripts/docker_npm_dry_run.sh +25 -0
- package/scripts/docker_release_checks.sh +18 -0
- package/scripts/docker_rust_test.sh +35 -0
- package/scripts/docker_secret_scan.sh +11 -0
- package/scripts/postinstall.js +10 -1
- package/scripts/test_claude_code_patterns_real.sh +150 -0
- package/src/config.rs +33 -0
- package/src/main.rs +24 -5
- package/src/models/anthropic.rs +40 -0
- package/src/proxy.rs +374 -49
- package/src/transform.rs +312 -21
- package/scripts/smoke_test.sh +0 -72
- package/tests/real_backends.rs +0 -213
package/tests/real_backends.rs
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
use serde_json::Value;
|
|
2
|
-
use std::env;
|
|
3
|
-
use std::fs;
|
|
4
|
-
use std::net::TcpListener;
|
|
5
|
-
use std::path::PathBuf;
|
|
6
|
-
use std::process::{Child, Command, Stdio};
|
|
7
|
-
use std::thread;
|
|
8
|
-
use std::time::{Duration, Instant};
|
|
9
|
-
|
|
10
|
-
struct TestServer {
|
|
11
|
-
child: Child,
|
|
12
|
-
log_path: PathBuf,
|
|
13
|
-
port: u16,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
impl Drop for TestServer {
|
|
17
|
-
fn drop(&mut self) {
|
|
18
|
-
let _ = self.child.kill();
|
|
19
|
-
let _ = self.child.wait();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
fn configured_env(name: &str) -> Option<String> {
|
|
24
|
-
match env::var(name) {
|
|
25
|
-
Ok(value) if !value.trim().is_empty() => Some(value),
|
|
26
|
-
_ => None,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
fn require_env(name: &str) -> Option<String> {
|
|
31
|
-
match configured_env(name) {
|
|
32
|
-
Some(value) => Some(value),
|
|
33
|
-
None => {
|
|
34
|
-
eprintln!("skipping real backend test: missing {name}");
|
|
35
|
-
None
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
fn reserve_port() -> u16 {
|
|
41
|
-
TcpListener::bind("127.0.0.1:0")
|
|
42
|
-
.expect("bind ephemeral port")
|
|
43
|
-
.local_addr()
|
|
44
|
-
.expect("read local addr")
|
|
45
|
-
.port()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
fn anthmorph_bin() -> String {
|
|
49
|
-
env::var("CARGO_BIN_EXE_anthmorph").expect("cargo should expose anthmorph bin path")
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fn start_server(
|
|
53
|
-
backend_profile: &str,
|
|
54
|
-
backend_url: &str,
|
|
55
|
-
model: &str,
|
|
56
|
-
api_key: &str,
|
|
57
|
-
) -> TestServer {
|
|
58
|
-
let port = reserve_port();
|
|
59
|
-
let log_path = env::temp_dir().join(format!("anthmorph-itest-{backend_profile}-{port}.log"));
|
|
60
|
-
let log = fs::File::create(&log_path).expect("create log file");
|
|
61
|
-
let log_err = log.try_clone().expect("clone log file");
|
|
62
|
-
|
|
63
|
-
let child = Command::new(anthmorph_bin())
|
|
64
|
-
.arg("--port")
|
|
65
|
-
.arg(port.to_string())
|
|
66
|
-
.arg("--backend-profile")
|
|
67
|
-
.arg(backend_profile)
|
|
68
|
-
.arg("--backend-url")
|
|
69
|
-
.arg(backend_url)
|
|
70
|
-
.arg("--model")
|
|
71
|
-
.arg(model)
|
|
72
|
-
.arg("--api-key")
|
|
73
|
-
.arg(api_key)
|
|
74
|
-
.stdout(Stdio::from(log))
|
|
75
|
-
.stderr(Stdio::from(log_err))
|
|
76
|
-
.spawn()
|
|
77
|
-
.expect("spawn anthmorph");
|
|
78
|
-
|
|
79
|
-
let server = TestServer {
|
|
80
|
-
child,
|
|
81
|
-
log_path,
|
|
82
|
-
port,
|
|
83
|
-
};
|
|
84
|
-
wait_until_ready(&server);
|
|
85
|
-
server
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
fn wait_until_ready(server: &TestServer) {
|
|
89
|
-
let deadline = Instant::now() + Duration::from_secs(20);
|
|
90
|
-
while Instant::now() < deadline {
|
|
91
|
-
let status = Command::new("curl")
|
|
92
|
-
.arg("-fsS")
|
|
93
|
-
.arg(format!("http://127.0.0.1:{}/health", server.port))
|
|
94
|
-
.stdout(Stdio::null())
|
|
95
|
-
.stderr(Stdio::null())
|
|
96
|
-
.status()
|
|
97
|
-
.expect("run curl health");
|
|
98
|
-
if status.success() {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
thread::sleep(Duration::from_millis(250));
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let log = fs::read_to_string(&server.log_path).unwrap_or_else(|_| "<missing log>".to_string());
|
|
105
|
-
panic!("server did not become ready\n{}", log);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
fn post_messages(server: &TestServer, payload: &Value) -> (u16, Value) {
|
|
109
|
-
let body_path = env::temp_dir().join(format!("anthmorph-itest-body-{}.json", server.port));
|
|
110
|
-
let payload_text = serde_json::to_string(payload).expect("serialize payload");
|
|
111
|
-
|
|
112
|
-
let output = Command::new("curl")
|
|
113
|
-
.arg("-sS")
|
|
114
|
-
.arg("-o")
|
|
115
|
-
.arg(&body_path)
|
|
116
|
-
.arg("-w")
|
|
117
|
-
.arg("%{http_code}")
|
|
118
|
-
.arg(format!("http://127.0.0.1:{}/v1/messages", server.port))
|
|
119
|
-
.arg("-H")
|
|
120
|
-
.arg("content-type: application/json")
|
|
121
|
-
.arg("-d")
|
|
122
|
-
.arg(payload_text)
|
|
123
|
-
.output()
|
|
124
|
-
.expect("run curl request");
|
|
125
|
-
|
|
126
|
-
let status_text = String::from_utf8(output.stdout).expect("status utf8");
|
|
127
|
-
let status = status_text
|
|
128
|
-
.trim()
|
|
129
|
-
.parse::<u16>()
|
|
130
|
-
.expect("parse status code");
|
|
131
|
-
let body = fs::read_to_string(&body_path).expect("read response body");
|
|
132
|
-
let value: Value = serde_json::from_str(&body).unwrap_or_else(|err| {
|
|
133
|
-
panic!("parse response body as json failed: {err}; status={status}; body={body}")
|
|
134
|
-
});
|
|
135
|
-
(status, value)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
fn base_payload() -> Value {
|
|
139
|
-
serde_json::json!({
|
|
140
|
-
"model": "claude-sonnet-4",
|
|
141
|
-
"max_tokens": 128,
|
|
142
|
-
"messages": [
|
|
143
|
-
{"role": "user", "content": "Reply with exactly: anthmorph-smoke-ok"}
|
|
144
|
-
]
|
|
145
|
-
})
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
#[test]
|
|
149
|
-
fn chutes_real_backend_smoke() {
|
|
150
|
-
let Some(api_key) = require_env("CHUTES_API_KEY") else {
|
|
151
|
-
return;
|
|
152
|
-
};
|
|
153
|
-
let server = start_server(
|
|
154
|
-
"chutes",
|
|
155
|
-
&env::var("CHUTES_BASE_URL").unwrap_or_else(|_| "https://llm.chutes.ai/v1".to_string()),
|
|
156
|
-
&env::var("CHUTES_MODEL").unwrap_or_else(|_| "deepseek-ai/DeepSeek-V3.2-TEE".to_string()),
|
|
157
|
-
&api_key,
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
let (status, response) = post_messages(&server, &base_payload());
|
|
161
|
-
assert_eq!(status, 200, "unexpected status: {response}");
|
|
162
|
-
let text = response["content"][0]["text"]
|
|
163
|
-
.as_str()
|
|
164
|
-
.expect("text response");
|
|
165
|
-
assert_eq!(text.trim(), "anthmorph-smoke-ok");
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
#[test]
|
|
169
|
-
fn minimax_real_backend_smoke() {
|
|
170
|
-
let Some(api_key) = require_env("MINIMAX_API_KEY") else {
|
|
171
|
-
return;
|
|
172
|
-
};
|
|
173
|
-
let server = start_server(
|
|
174
|
-
"openai-generic",
|
|
175
|
-
&env::var("MINIMAX_BASE_URL").unwrap_or_else(|_| "https://api.minimax.io/v1".to_string()),
|
|
176
|
-
&env::var("MINIMAX_MODEL").unwrap_or_else(|_| "MiniMax-M2.5".to_string()),
|
|
177
|
-
&api_key,
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
let (status, response) = post_messages(&server, &base_payload());
|
|
181
|
-
assert_eq!(status, 200, "unexpected status: {response}");
|
|
182
|
-
let text = response["content"][0]["text"]
|
|
183
|
-
.as_str()
|
|
184
|
-
.expect("text response");
|
|
185
|
-
assert!(
|
|
186
|
-
text.contains("anthmorph-smoke-ok"),
|
|
187
|
-
"unexpected text: {text}"
|
|
188
|
-
);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
#[test]
|
|
192
|
-
fn alibaba_coding_plan_rejected_for_chat_completions() {
|
|
193
|
-
let Some(api_key) = require_env("ALIBABA_CODE_API_KEY") else {
|
|
194
|
-
return;
|
|
195
|
-
};
|
|
196
|
-
let server = start_server(
|
|
197
|
-
"openai-generic",
|
|
198
|
-
&env::var("ALIBABA_BASE_URL")
|
|
199
|
-
.unwrap_or_else(|_| "https://coding-intl.dashscope.aliyuncs.com/v1".to_string()),
|
|
200
|
-
&env::var("ALIBABA_MODEL").unwrap_or_else(|_| "qwen3-coder-plus".to_string()),
|
|
201
|
-
&api_key,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
let (status, response) = post_messages(&server, &base_payload());
|
|
205
|
-
assert_eq!(status, 502, "unexpected status: {response}");
|
|
206
|
-
let message = response["error"]["message"]
|
|
207
|
-
.as_str()
|
|
208
|
-
.expect("error message");
|
|
209
|
-
assert!(
|
|
210
|
-
message.contains("Coding Plan is currently only available for Coding Agents"),
|
|
211
|
-
"unexpected error message: {message}"
|
|
212
|
-
);
|
|
213
|
-
}
|