use crate::support::Seat;
use serde_json::json;
use std::io::Write as _;
use std::process::{Command, Stdio};
#[test]
fn assist004_r3_codex_proxy_settings_follow_the_seat_arguments() -> anyhow::Result<()> {
check(Some("http://127.0.0.1:9/synthetic-run/openai/v1"), "codex")
}
#[test]
fn assist004_r3_absent_proxy_adds_no_settings() -> anyhow::Result<()> {
check(None, "codex")
}
#[test]
fn assist004_r3_other_harness_gets_no_codex_settings() -> anyhow::Result<()> {
check(
Some("http://127.0.0.1:9/synthetic-run/openai/v1"),
"claude-code",
)
}
#[test]
fn assist004_r3_proxy_quotes_and_backslashes_round_trip_as_toml() -> anyhow::Result<()> {
check(
Some("http://127.0.0.1:9/synthetic/\"quoted\\path\u{7f}"),
"codex",
)
}
fn check(base: Option<&str>, id: &str) -> anyhow::Result<()> {
let mut seat = Seat::configured(&[], &[("OPENAI_BASE_URL", base.unwrap_or(""))], |config| {
config["harness"]["id"] = json!(id);
})?;
let initialized = seat.event("initialize")?;
let args: Vec<String> = serde_json::from_value(initialized["argv"].clone())?;
let original: serde_json::Value =
serde_json::from_slice(&std::fs::read(seat.directory.path().join("seat.json"))?)?;
let expected: Vec<String> = serde_json::from_value(original["harness"]["args"].clone())?;
assert!(
args.starts_with(&expected),
"proxy settings replaced seat arguments"
);
if let Some(base) = base.filter(|_| id == "codex") {
let suffix = &args[expected.len()..];
assert_eq!(
suffix.len(),
4,
"Codex never received both Lys provider settings"
);
assert!(
suffix[0] == "-c" && suffix[2] == "-c" && suffix[3] == "model_provider=\"lys\"",
"provider selector differs from Lys"
);
let mut parser = Command::new("python3").args(["-I", "-c",
"import json,sys,tomllib; x=json.load(sys.stdin); p=tomllib.loads(x['setting'])['model_providers']['lys']; assert p == dict(name='OpenAI through Lys',base_url=x['base'],wire_api='responses',requires_openai_auth=True,supports_websockets=False)"])
.stdin(Stdio::piped()).stdout(Stdio::null()).stderr(Stdio::null()).spawn()?;
let mut input = parser
.stdin
.take()
.ok_or_else(|| anyhow::anyhow!("TOML parser input absent"))?;
input.write_all(&serde_json::to_vec(
&json!({"setting":suffix[1],"base":base}),
)?)?;
drop(input);
assert!(
parser.wait()?.success(),
"provider setting did not round trip through TOML"
);
} else {
assert!(
args == expected,
"proxy settings were appended without a Codex proxy"
);
}
seat.event("session_opened")?;
seat.close(0)
}