graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Keep Jev provider-switch coverage under source line cap
justrachfb3516155c4c
diff --git a/src/jev_provider_switch_tests.zig b/src/jev_provider_switch_tests.zignew file mode 100644index 00000000..3f4cf4b0--- /dev/null+++ b/src/jev_provider_switch_tests.zig@@ -0,0 +1,71 @@+//! Regression for same-wire and cross-wire provider switches changing Jev visibility.+const std = @import("std");+const Agent = @import("agent.zig").Agent;+const Provider = @import("provider.zig").Provider;+const providers = @import("providers.zig");+const jev_tool = @import("jev_tool.zig");++test "native Jev catalog refreshes on eligible and ineligible model switches" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();+ const p: Provider = .{ .id = "codex", .kind = .responses, .auth = .bearer, .url = "", .api_key = "", .model = "gpt-5", .context = 270_000 };++ var root: Agent = undefined;+ root.provider = p;+ root.subagent_provider = null;+ root.subagent_provider_explicit = true;+ root.arena = a;+ root.registry = null;+ root.messages = std.json.Array.init(a);+ root.sub = false;+ root.strict = false;+ root.sys_normal = "";+ root.sys_strict = "";+ root.tools_anthropic = "";+ root.tools_openai = "";+ root.tools_responses = "";+ root.keep_context = true;+ root.last_context_tokens = 220_000;+ root.context_local_tokens = root.fullRequestEstimateTokens();+ root.last_cache_read = 12_345;+ root.cap_new = true;+ root.sox_json_object = true;+ root.effort_rejected = true;+ root.ws_off = true;+ root.ws_transport_failures = 2;++ const mock = struct {+ pub fn get(_: @This(), key: []const u8) ?[]const u8 {+ return if (std.mem.eql(u8, key, "JEV_BACKEND")) "mock" else null;+ }+ }{};+ jev_tool.configure(mock);+ defer jev_tool.configure(struct {+ pub fn get(_: @This(), _: []const u8) ?[]const u8 {+ return null;+ }+ }{});+ _ = jev_tool.setCodegraffLogin(true);++ var gpt6 = p;+ gpt6.model = "gpt-6-sol";+ _ = try providers.applyProviderInner(&root, a, gpt6, false);+ try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) != null);+ _ = try providers.applyProviderInner(&root, a, p, false);+ try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) == null);++ var mimo = p;+ mimo.id = "codegraff";+ mimo.kind = .openai;+ mimo.model = "mimo-v2.6-pro";+ _ = try providers.applyProviderInner(&root, a, mimo, false);+ try std.testing.expect(std.mem.indexOf(u8, root.tools_openai, jev_tool.name) != null);+ var deepseek = mimo;+ deepseek.id = "deepseek";+ deepseek.model = "deepseek-chat";+ _ = try providers.applyProviderInner(&root, a, deepseek, false);+ try std.testing.expect(std.mem.indexOf(u8, root.tools_openai, jev_tool.name) == null);+ _ = try providers.applyProviderInner(&root, a, gpt6, false);+ try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) != null);+}diff --git a/src/jev_tool.zig b/src/jev_tool.zigindex 39d2ff2a..dfa5d89c 100644--- a/src/jev_tool.zig+++ b/src/jev_tool.zig@@ -54,6 +54,12 @@ pub fn available(provider: Provider) bool {!state.down.load(.acquire) and scope.eligible(provider);}+/// A model switch can change Jev visibility even when the wire format stays the same.+pub fn updateProvider(root: anytype, p: Provider) void {+ if (available(root.provider) != available(p)) root.invalidateRootTools();+ root.provider = p;+}+pub fn catalogExtras(provider: Provider) []const ToolSpec {return if (available(provider)) &.{spec} else &.{};}diff --git a/src/main.zig b/src/main.zigindex b2e1eb43..12e33602 100644--- a/src/main.zig+++ b/src/main.zig@@ -558,7 +558,7 @@ const agentJobsReap = subagent.agentJobsReap; // #276 P0-3: background subagentsconst workflow = @import("workflow_test.zig"); // the engine's tests live here (workflow.zig hit the 600-line cap)const exec = @import("exec.zig");test { // ── Unit tests (`zig build test`): pull in tests from imported modules (mcp.zig)- _ = .{ @import("jev_tool.zig"), @import("jev_model_scope.zig") };+ _ = .{ @import("jev_tool.zig"), @import("jev_model_scope.zig"), @import("jev_provider_switch_tests.zig") };_ = .{ @import("mcp_apps.zig"), @import("html_view.zig"), @import("providers_confirmation_tests.zig"), @import("repl_model_confirmation_tests.zig"), @import("repl_model_pick_tests.zig"), @import("engine_sink_citation_tests.zig"), @import("cite_markup_stream_tests.zig"), @import("oneshot_citation_tests.zig"), @import("tui_acp.zig"), @import("acp_permission.zig"), @import("acp_usage.zig") };_ = .{ @import("mcp_server_tests.zig"), @import("main_test.zig"), @import("artifact_claim_command.zig"), @import("cli_path_hint.zig"), @import("run_budget.zig"), @import("pr_review_input.zig"), @import("pr_claim_review.zig"), @import("tui_paste_transfer.zig") };_ = .{ @import("session_catalog.zig"), @import("session_prompt.zig"), @import("session_discovery.zig") };diff --git a/src/providers.zig b/src/providers.zigindex 6cd7ff68..0a51bb17 100644--- a/src/providers.zig+++ b/src/providers.zig@@ -26,7 +26,6 @@ const fallback_config = @import("fallback_config.zig");const util = @import("util.zig");const trace = @import("trace.zig");const orch_rows = @import("orchestration_rows.zig");-const jev_tool = @import("jev_tool.zig");fn localProviderUrl(url: []const u8) bool {return std.mem.startsWith(u8, url, "http://127.0.0.1") or std.mem.startsWith(u8, url, "http://localhost") or std.mem.startsWith(u8, url, "http://[::1]");@@ -76,7 +75,6 @@ fn translateHistory(arena: Allocator, msgs: *std.json.Array, to_kind: Provider.Kpub fn applyProviderInner(root: *Agent, arena: Allocator, p: Provider, persist: bool) ![]const u8 {const same_format = root.provider.kind == p.kind;- const same_jev_scope = jev_tool.available(root.provider) == jev_tool.available(p);const same_selection = same_format androot.provider.context == p.context andstd.mem.eql(u8, root.provider.id, p.id) and@@ -94,7 +92,7 @@ pub fn applyProviderInner(root: *Agent, arena: Allocator, p: Provider, persist:note = "history cleared — /keepcontext on to carry it across formats";}}- root.provider = p;+ @import("jev_tool.zig").updateProvider(root, p);// #371: the #291 worker default resolved once at startup; without this a// /model switch left children on the OLD provider's rung (root on codex,// workers silently still on kimi — a cost and consent surprise) or with@@ -103,8 +101,6 @@ pub fn applyProviderInner(root: *Agent, arena: Allocator, p: Provider, persist:if (!root.subagent_provider_explicit) if (@import("bench_priors.zig").g_keys) |k| {root.subagent_provider = @import("subagent_selection.zig").resolveSubagentProvider(k.*, p, null, null, false, false);};- // A same-format model switch can change native Jev visibility.- if (!same_jev_scope) root.invalidateRootTools();// Keep the context estimate and first request exact without eagerly// materializing formats this session has never used.try root.ensureRootTools(p.kind);@@ -551,31 +547,6 @@ test "applyProviderInner preserves the server meter on an exact model re-selectitry std.testing.expect(root.tools_openai.len > 0);try std.testing.expect(root.tools_responses.len > 0); // already paid for, remains cachedtry std.testing.expectEqual(@as(usize, 0), root.tools_anthropic.len);-- const mock = struct {- pub fn get(_: @This(), key: []const u8) ?[]const u8 {- return if (std.mem.eql(u8, key, "JEV_BACKEND")) "mock" else null;- }- }{};- jev_tool.configure(mock);- defer jev_tool.configure(struct {- pub fn get(_: @This(), _: []const u8) ?[]const u8 {- return null;- }- }{});- _ = jev_tool.setCodegraffLogin(true);- // Same-format GPT-6 → GPT-5 switches must also rebuild the catalog.- var gpt6 = changed;- gpt6.model = "gpt-6-sol";- root.invalidateRootTools();- _ = try applyProviderInner(&root, a, gpt6, false);- try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) != null);- _ = try applyProviderInner(&root, a, changed, false);- try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) == null);- _ = try applyProviderInner(&root, a, changed_format, false);- try std.testing.expect(std.mem.indexOf(u8, root.tools_openai, jev_tool.name) == null);- _ = try applyProviderInner(&root, a, gpt6, false);- try std.testing.expect(std.mem.indexOf(u8, root.tools_responses, jev_tool.name) != null);}test "set_model control resolves explicit provider/model fields" {