mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-08-28 05:27:41 +00:00
chore(test): extract TestContext::set_http_target helper
Replace 16 inline copies of the `[cli.target] type = "http"` settings TOML across CLI integration tests with a single `set_http_target(&base_url)` method on `TestContext`. Removes a brittle format string that was maintained in ten files but only meaningfully asserted-against in one. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
015992208a
commit
46164fcda9
11 changed files with 27 additions and 120 deletions
|
|
@ -260,13 +260,7 @@ fn archive_resolves_selector_via_server_endpoint() {
|
|||
.to_string(),
|
||||
);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut filters = context.filters();
|
||||
filters.push(ulid_filter());
|
||||
|
|
|
|||
|
|
@ -106,13 +106,7 @@ fn create_uses_configured_server_target_without_server_flag() {
|
|||
.header("Content-Type", "application/json")
|
||||
.body(run_status_response(run_id.as_str(), "submitted").to_string());
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let output = context
|
||||
.create_cmd()
|
||||
|
|
@ -169,13 +163,7 @@ fn create_cli_server_target_overrides_configured_server_target() {
|
|||
.header("Content-Type", "application/json")
|
||||
.body(run_status_response(run_id.as_str(), "submitted").to_string());
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
config_server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&config_server.base_url());
|
||||
|
||||
let output = context
|
||||
.create_cmd()
|
||||
|
|
|
|||
|
|
@ -163,13 +163,7 @@ fn exec_configured_server_target_alone_does_not_reroute_exec() {
|
|||
when.method("POST").path("/api/v1/completions");
|
||||
then.status(500).body("config-should-not-be-used");
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut cmd = context.exec_cmd();
|
||||
cmd.env_clear();
|
||||
|
|
@ -212,13 +206,7 @@ fn exec_cli_server_target_overrides_configured_server_target() {
|
|||
// without paying the retry backoff cost of a 5xx response.
|
||||
then.status(400).body("cli-override-marker");
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
config_server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&config_server.base_url());
|
||||
|
||||
let mut cmd = context.exec_cmd();
|
||||
cmd.env_clear();
|
||||
|
|
|
|||
|
|
@ -227,13 +227,7 @@ fn list_uses_configured_server_target_without_server_flag() {
|
|||
.to_string(),
|
||||
);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut cmd = context.model();
|
||||
cmd.args(["list", "--json"]);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use assert_cmd::Command;
|
||||
use fabro_test::{TestContext, fabro_snapshot, test_context};
|
||||
use fabro_test::{fabro_snapshot, test_context};
|
||||
use httpmock::MockServer;
|
||||
|
||||
fn remove_provider_env(cmd: &mut Command) -> &mut Command {
|
||||
|
|
@ -13,16 +13,6 @@ fn remove_provider_env(cmd: &mut Command) -> &mut Command {
|
|||
.env_remove("INCEPTION_API_KEY")
|
||||
}
|
||||
|
||||
fn configure_server_target(context: &TestContext, server: &MockServer) {
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
fn model_json(id: &str, provider: &str, configured: bool) -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"id": id,
|
||||
|
|
@ -184,7 +174,7 @@ fn json_output_includes_skipped_models() {
|
|||
fn model_test_does_not_announce_unconfigured() {
|
||||
let context = test_context!();
|
||||
let server = MockServer::start();
|
||||
configure_server_target(&context, &server);
|
||||
context.set_http_target(&server.base_url());
|
||||
let list = mock_model_list(&server, [
|
||||
model_json("claude-opus-4-7", "anthropic", true),
|
||||
model_json("gpt-5.2", "openai", false),
|
||||
|
|
@ -233,7 +223,7 @@ fn model_test_does_not_announce_unconfigured() {
|
|||
fn model_test_skipped_footer_sources_from_listing() {
|
||||
let context = test_context!();
|
||||
let server = MockServer::start();
|
||||
configure_server_target(&context, &server);
|
||||
context.set_http_target(&server.base_url());
|
||||
mock_model_list(&server, [
|
||||
model_json("claude-opus-4-7", "anthropic", true),
|
||||
model_json("gpt-5.2", "openai", false),
|
||||
|
|
@ -267,7 +257,7 @@ fn model_test_skipped_footer_sources_from_listing() {
|
|||
fn model_test_post_list_race_is_a_failure() {
|
||||
let context = test_context!();
|
||||
let server = MockServer::start();
|
||||
configure_server_target(&context, &server);
|
||||
context.set_http_target(&server.base_url());
|
||||
mock_model_list(&server, [model_json("claude-opus-4-7", "anthropic", true)]);
|
||||
server.mock(|when, then| {
|
||||
when.method("POST")
|
||||
|
|
@ -301,7 +291,7 @@ fn model_test_post_list_race_is_a_failure() {
|
|||
fn model_test_json_partitions_skip_and_fail() {
|
||||
let context = test_context!();
|
||||
let server = MockServer::start();
|
||||
configure_server_target(&context, &server);
|
||||
context.set_http_target(&server.base_url());
|
||||
mock_model_list(&server, [
|
||||
model_json("gpt-5.2", "openai", false),
|
||||
model_json("claude-opus-4-7", "anthropic", true),
|
||||
|
|
|
|||
|
|
@ -369,13 +369,7 @@ fn ps_uses_configured_server_target_without_server_flag() {
|
|||
.to_string(),
|
||||
);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let output = context
|
||||
.ps()
|
||||
|
|
|
|||
|
|
@ -187,13 +187,7 @@ fn rm_force_removes_active_run() {
|
|||
.query_param("force", "true");
|
||||
then.status(204);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut filters = context.filters();
|
||||
filters.push((
|
||||
|
|
@ -265,13 +259,7 @@ fn rm_without_force_uses_resolve_then_surfaces_server_conflict() {
|
|||
.to_string(),
|
||||
);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut filters = context.filters();
|
||||
filters.push((
|
||||
|
|
@ -384,13 +372,7 @@ fn rm_uses_configured_server_target_without_local_run_dir() {
|
|||
when.method("DELETE").path(format!("/api/v1/runs/{run_id}"));
|
||||
then.status(204);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let output = context
|
||||
.command()
|
||||
|
|
|
|||
|
|
@ -227,13 +227,7 @@ fn detach_uses_configured_server_target_without_server_flag() {
|
|||
.header("Content-Type", "application/json")
|
||||
.body(run_status_response(run_id.as_str(), "queued").to_string());
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let workflow = context.install_fixture("simple.fabro");
|
||||
let output = context
|
||||
|
|
@ -411,13 +405,7 @@ fn detach_cli_server_target_overrides_configured_server_target() {
|
|||
.header("Content-Type", "application/json")
|
||||
.body(run_status_response(run_id.as_str(), "queued").to_string());
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
config_server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&config_server.base_url());
|
||||
|
||||
let workflow = context.install_fixture("simple.fabro");
|
||||
let output = context
|
||||
|
|
|
|||
|
|
@ -265,13 +265,7 @@ fn unarchive_resolves_selector_via_server_endpoint() {
|
|||
.to_string(),
|
||||
);
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&server.base_url());
|
||||
|
||||
let mut filters = context.filters();
|
||||
filters.push(ulid_filter());
|
||||
|
|
|
|||
|
|
@ -302,13 +302,7 @@ fn attach_smoke_covers_arg_validation_and_remote_server_behaviors() {
|
|||
.header("Content-Type", "text/event-stream")
|
||||
.body(run_sse_body(success_run_id.as_str()));
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
success_server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&success_server.base_url());
|
||||
|
||||
let success_output = context
|
||||
.command()
|
||||
|
|
@ -406,13 +400,7 @@ fn attach_smoke_covers_arg_validation_and_remote_server_behaviors() {
|
|||
.header("Content-Type", "text/event-stream")
|
||||
.body("");
|
||||
});
|
||||
context.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!(
|
||||
"_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{}/api/v1\"\n",
|
||||
eof_server.base_url()
|
||||
),
|
||||
);
|
||||
context.set_http_target(&eof_server.base_url());
|
||||
|
||||
let eof_output = context
|
||||
.command()
|
||||
|
|
|
|||
|
|
@ -1581,6 +1581,13 @@ impl TestContext {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn set_http_target(&self, base_url: &str) -> &Self {
|
||||
self.write_home(
|
||||
".fabro/settings.toml",
|
||||
format!("_version = 1\n\n[cli.target]\ntype = \"http\"\nurl = \"{base_url}/api/v1\"\n"),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn ensure_home_server_auth_methods(&self) -> &Self {
|
||||
let settings_path = home_settings_path(&self.home_dir);
|
||||
ensure_home_server_auth_methods(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue