feat(opencode): remplace le profil Ollama HTTP par OpenCode
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -34,7 +34,7 @@ use domain::ports::{
|
||||
RemotePath, RuntimeError, SessionPlan, SkillStore, SpawnSpec, StoreError,
|
||||
};
|
||||
use domain::profile::{
|
||||
AgentProfile, ContextInjection, McpCapability, McpConfigStrategy, McpTransport,
|
||||
AgentProfile, ContextInjection, McpCapability, McpConfigStrategy, McpTransport, OpenCodeConfig,
|
||||
SessionStrategy, StructuredAdapter,
|
||||
};
|
||||
use domain::project::{Project, ProjectPath};
|
||||
@ -1584,6 +1584,16 @@ fn profile_with_mcp(id: ProfileId, config: McpConfigStrategy) -> AgentProfile {
|
||||
.with_mcp(McpCapability::new(config, McpTransport::Stdio))
|
||||
}
|
||||
|
||||
fn opencode_profile(id: ProfileId) -> AgentProfile {
|
||||
profile(id, ContextInjection::convention_file("AGENTS.md").unwrap())
|
||||
.with_structured_adapter(StructuredAdapter::OpenCode)
|
||||
.with_opencode(OpenCodeConfig::new(Some("ollama/qwen3-coder:30b".to_owned())).unwrap())
|
||||
.with_mcp(McpCapability::new(
|
||||
McpConfigStrategy::open_code_config("opencode.json").unwrap(),
|
||||
McpTransport::Stdio,
|
||||
))
|
||||
}
|
||||
|
||||
/// Returns the writes whose path ends with the given suffix (e.g. `/.mcp.json`).
|
||||
fn writes_ending_with(fs: &FakeFs, suffix: &str) -> Vec<(String, Vec<u8>)> {
|
||||
fs.writes()
|
||||
@ -1703,6 +1713,62 @@ async fn launch_mcp_config_file_write_failure_is_best_effort() {
|
||||
assert_eq!(pty.spawns().len(), 1, "the CLI is still spawned");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn launch_opencode_writes_isolated_config_and_env() {
|
||||
let profile = opencode_profile(pid(9));
|
||||
let (launch, agent, fs, pty, _bus, _sessions, _tr, _session) = launch_fixture_with_profile(
|
||||
profile,
|
||||
Some(ContextInjectionPlan::File {
|
||||
target: "AGENTS.md".to_owned(),
|
||||
}),
|
||||
);
|
||||
|
||||
launch.execute(launch_input(agent.id)).await.unwrap();
|
||||
|
||||
let run_dir = format!("/home/me/proj/.ideai/run/{}", agent.id);
|
||||
let opencode = writes_ending_with(&fs, "/opencode.json");
|
||||
assert_eq!(opencode.len(), 1, "one OpenCode config is written");
|
||||
assert_eq!(opencode[0].0, format!("{run_dir}/opencode.json"));
|
||||
let body: serde_json::Value = serde_json::from_slice(&opencode[0].1).unwrap();
|
||||
assert_eq!(body["model"], "ollama/qwen3-coder:30b");
|
||||
assert_eq!(
|
||||
body["provider"]["ollama"]["options"]["baseURL"],
|
||||
"http://localhost:11434/v1"
|
||||
);
|
||||
assert_eq!(body["mcp"]["idea"]["type"], "local");
|
||||
assert_eq!(body["mcp"]["idea"]["command"][0], "idea");
|
||||
|
||||
let spawn = pty
|
||||
.spawns()
|
||||
.pop()
|
||||
.expect("spawned via PTY fallback in this fixture");
|
||||
let env: std::collections::HashMap<_, _> = spawn.env.into_iter().collect();
|
||||
assert_eq!(
|
||||
env.get("OPENCODE_CONFIG").map(String::as_str),
|
||||
Some(format!("{run_dir}/opencode.json").as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
env.get("HOME").map(String::as_str),
|
||||
Some(format!("{run_dir}/.opencode").as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
env.get("XDG_CONFIG_HOME").map(String::as_str),
|
||||
Some(format!("{run_dir}/.opencode/config").as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
env.get("XDG_DATA_HOME").map(String::as_str),
|
||||
Some(format!("{run_dir}/.opencode/data").as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
env.get("XDG_CACHE_HOME").map(String::as_str),
|
||||
Some(format!("{run_dir}/.opencode/cache").as_str())
|
||||
);
|
||||
assert_eq!(
|
||||
env.get("OPENCODE_DISABLE_AUTOUPDATE").map(String::as_str),
|
||||
Some("1")
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn launch_mcp_flag_appends_flag_and_path_to_args() {
|
||||
// Test 5 — Flag { flag: "--mcp-config" } ⇒ spec.args carries the flag followed
|
||||
|
||||
Reference in New Issue
Block a user