mirror of
https://github.com/rennf93/roboco.git
synced 2026-08-03 07:23:24 +02:00
fix: post-finale completeness sweep — routing surface, provider config, budgets, compose env, interactive exemption (#661)
This commit is contained in:
@@ -489,4 +489,34 @@ describe("EditProjectDialog — Monthly Budget (USD)", () => {
|
||||
};
|
||||
expect(call.updates.monthly_budget_usd).toBe(100);
|
||||
});
|
||||
|
||||
it("shows this month's spend against the cap when monthly_spend_usd is present", async () => {
|
||||
renderDialog(
|
||||
makeProject({ monthly_budget_usd: 100, monthly_spend_usd: 42.5 }),
|
||||
);
|
||||
await screen.findByRole("button", { name: /Save Changes/i });
|
||||
openAutonomySection();
|
||||
|
||||
expect(screen.getByTestId("project-spend").textContent).toBe(
|
||||
"Spent: $42.50 this month / $100.00",
|
||||
);
|
||||
});
|
||||
|
||||
it("hides the ratio (but still shows spend) when there is no monthly cap", async () => {
|
||||
renderDialog(makeProject({ monthly_budget_usd: null, monthly_spend_usd: 10 }));
|
||||
await screen.findByRole("button", { name: /Save Changes/i });
|
||||
openAutonomySection();
|
||||
|
||||
expect(screen.getByTestId("project-spend").textContent).toBe(
|
||||
"Spent: $10.00 this month",
|
||||
);
|
||||
});
|
||||
|
||||
it("hides the spend line entirely when monthly_spend_usd is absent (flag off)", async () => {
|
||||
renderDialog(makeProject({ monthly_budget_usd: 100, monthly_spend_usd: null }));
|
||||
await screen.findByRole("button", { name: /Save Changes/i });
|
||||
openAutonomySection();
|
||||
|
||||
expect(screen.queryByTestId("project-spend")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -833,6 +833,15 @@ function EditProjectForm({
|
||||
Must be greater than 0 — a 0 budget would block every claim
|
||||
immediately. Leave blank for no cap.
|
||||
</p>
|
||||
{project.monthly_spend_usd != null && (
|
||||
<p className="text-xs text-muted-foreground" data-testid="project-spend">
|
||||
Spent: ${project.monthly_spend_usd.toFixed(2)} this month
|
||||
{monthlyBudgetUsd.trim() &&
|
||||
!Number.isNaN(Number(monthlyBudgetUsd))
|
||||
? ` / $${Number(monthlyBudgetUsd).toFixed(2)}`
|
||||
: ""}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
@@ -50,6 +50,11 @@ const {
|
||||
provider_type: "openai",
|
||||
display_name: "GPT-5.3 Codex",
|
||||
},
|
||||
{
|
||||
model_name: "gemini-2.5-pro",
|
||||
provider_type: "gemini",
|
||||
display_name: "Gemini 2.5 Pro",
|
||||
},
|
||||
]),
|
||||
getOllamaKey: vi.fn(async () => ({ has_key: false, enabled: true })),
|
||||
setOllamaKey: vi.fn(async () => ({ has_key: true, enabled: true })),
|
||||
@@ -387,6 +392,13 @@ function withQueryClient(ui: ReactNode) {
|
||||
return <QueryClientProvider client={client}>{ui}</QueryClientProvider>;
|
||||
}
|
||||
|
||||
// Finds a per-agent Mix row's container div by its agent-id text. `.closest`
|
||||
// on a non-tag-name CSS selector types as `Element | null`, not `HTMLElement`
|
||||
// — cast once here rather than at every call site.
|
||||
function mixRowFor(agentId: string): HTMLElement {
|
||||
return screen.getByText(agentId).closest("div.grid") as HTMLElement;
|
||||
}
|
||||
|
||||
describe("AIRoutingCard", () => {
|
||||
beforeEach(() => {
|
||||
catalog.mockClear();
|
||||
@@ -761,6 +773,102 @@ describe("AIRoutingCard", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Codex and Gemini mode buttons + Mix picker visibility (the headline gap:
|
||||
// both were built but unreachable from the panel — no apply-mode card, no
|
||||
// Mix group).
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
describe("Codex and Gemini mode buttons", () => {
|
||||
it("renders the Codex button and applies mode='codex' on confirm", async () => {
|
||||
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(true);
|
||||
render(withQueryClient(<AIRoutingCard />));
|
||||
await screen.findByText("Grok (xAI) API key");
|
||||
|
||||
fireEvent.click(screen.getByText("Codex"));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(applyMode).toHaveBeenCalledWith({ mode: "codex" }),
|
||||
);
|
||||
confirmSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("renders the Gemini button and applies mode='gemini' on confirm", async () => {
|
||||
const confirmSpy = vi.spyOn(window, "confirm").mockReturnValue(true);
|
||||
render(withQueryClient(<AIRoutingCard />));
|
||||
await screen.findByText("Grok (xAI) API key");
|
||||
|
||||
fireEvent.click(screen.getByText("Gemini"));
|
||||
|
||||
await waitFor(() =>
|
||||
expect(applyMode).toHaveBeenCalledWith({ mode: "gemini" }),
|
||||
);
|
||||
confirmSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("neither button is gated on a key (no key card exists for either provider)", async () => {
|
||||
render(withQueryClient(<AIRoutingCard />));
|
||||
await screen.findByText("Grok (xAI) API key");
|
||||
|
||||
expect(screen.getByText("Codex").closest("button")).not.toBeDisabled();
|
||||
expect(screen.getByText("Gemini").closest("button")).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Mix picker Codex/Gemini group visibility", () => {
|
||||
it("shows Codex and Gemini provider groups for a delivery role's per-agent select", async () => {
|
||||
render(withQueryClient(<AIRoutingCard />));
|
||||
await screen.findByText("Per-agent override (mix mode)");
|
||||
|
||||
const beDevRow = mixRowFor("be-dev-1");
|
||||
// The catalog query resolves asynchronously — the per-agent groups are
|
||||
// absent on the first render pass, so wait for them (findByText) rather
|
||||
// than asserting synchronously.
|
||||
expect(
|
||||
await within(beDevRow).findByText("Codex (OpenAI)"),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
within(beDevRow).getByText("Gemini (Google)"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("excludes Codex and Gemini from the Intake/Secretary/PR Review group, with an inline note", async () => {
|
||||
render(withQueryClient(<AIRoutingCard />));
|
||||
await screen.findByText("Per-agent override (mix mode)");
|
||||
|
||||
expect(
|
||||
screen.getByText(/Codex and Gemini are delivery-roles-only/i),
|
||||
).toBeInTheDocument();
|
||||
|
||||
// Wait for the catalog query to resolve (an unrelated row's groups)
|
||||
// before asserting absence on this group's rows below.
|
||||
await within(mixRowFor("be-dev-1")).findByText("Codex (OpenAI)");
|
||||
|
||||
const secretaryRow = mixRowFor("secretary-1");
|
||||
expect(
|
||||
within(secretaryRow).queryByText("Codex (OpenAI)"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(secretaryRow).queryByText("Gemini (Google)"),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
const intakeRow = mixRowFor("intake-1");
|
||||
expect(
|
||||
within(intakeRow).queryByText("Codex (OpenAI)"),
|
||||
).not.toBeInTheDocument();
|
||||
expect(
|
||||
within(intakeRow).queryByText("Gemini (Google)"),
|
||||
).not.toBeInTheDocument();
|
||||
|
||||
// The root PR reviewer shares the same group/note, even though it is
|
||||
// technically one-shot-capable — the panel restricts the whole group.
|
||||
const prReviewerRow = mixRowFor("pr-reviewer-1");
|
||||
expect(
|
||||
within(prReviewerRow).queryByText("Codex (OpenAI)"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Mode switches preserve complexity overrides (2026-07-17-style incident:
|
||||
// these same buttons once wiped AGENT_SLUG pins) — the confirm text says so
|
||||
|
||||
@@ -40,8 +40,10 @@ import {
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
AlertTriangle,
|
||||
Bot,
|
||||
Cpu,
|
||||
Gauge,
|
||||
Gem,
|
||||
Key,
|
||||
KeyRound,
|
||||
Server,
|
||||
@@ -115,6 +117,12 @@ const AGENT_GROUP_DEFS: {
|
||||
},
|
||||
];
|
||||
|
||||
// Codex/Gemini are V1 delivery-roles-only — no interactive Intake/Secretary
|
||||
// support (see roboco.llm.providers.codex / .gemini). This group's per-agent
|
||||
// picker excludes both providers below instead of offering a route that
|
||||
// would silently misroute the persistent Intake/Secretary session at spawn.
|
||||
const INTERACTIVE_ONLY_GROUP_TITLE = "Intake / Secretary / PR Review";
|
||||
|
||||
// Stable within-group ordering (PM/lead first, devs, QA, doc, reviewer last)
|
||||
// so the picker doesn't churn alphabetically as the live roster loads —
|
||||
// ties (e.g. dev-1/dev-2) break on slug, which already sorts correctly.
|
||||
@@ -280,6 +288,10 @@ export function AIRoutingCard() {
|
||||
(c: { provider_type: ModelProvider }) =>
|
||||
c.provider_type === ModelProvider.OPENAI,
|
||||
);
|
||||
const catalogGeminiOnly = catalog.filter(
|
||||
(c: { provider_type: ModelProvider }) =>
|
||||
c.provider_type === ModelProvider.GEMINI,
|
||||
);
|
||||
const catalogAnthropicOnly = catalog.filter(
|
||||
(c: { provider_type: ModelProvider }) =>
|
||||
c.provider_type === ModelProvider.ANTHROPIC,
|
||||
@@ -326,6 +338,46 @@ export function AIRoutingCard() {
|
||||
}
|
||||
};
|
||||
|
||||
const flipToCodex = async () => {
|
||||
if (
|
||||
!confirm(
|
||||
"Switch every agent to Codex? Per-agent pins and complexity " +
|
||||
"overrides are kept; other role/global assignments are replaced. " +
|
||||
"Intake and Secretary stay on Anthropic (Codex has no interactive " +
|
||||
"chat support).",
|
||||
)
|
||||
)
|
||||
return;
|
||||
try {
|
||||
await applyMode.mutateAsync({ mode: "codex" });
|
||||
toast.success(
|
||||
"Role/global routing now on Codex — pins/overrides kept, Intake & Secretary stay on Anthropic",
|
||||
);
|
||||
} catch (e) {
|
||||
toast.error("Switch failed: " + errMsg(e));
|
||||
}
|
||||
};
|
||||
|
||||
const flipToGemini = async () => {
|
||||
if (
|
||||
!confirm(
|
||||
"Switch every agent to Gemini? Per-agent pins and complexity " +
|
||||
"overrides are kept; other role/global assignments are replaced. " +
|
||||
"Intake and Secretary stay on Anthropic (Gemini has no interactive " +
|
||||
"chat support).",
|
||||
)
|
||||
)
|
||||
return;
|
||||
try {
|
||||
await applyMode.mutateAsync({ mode: "gemini" });
|
||||
toast.success(
|
||||
"Role/global routing now on Gemini — pins/overrides kept, Intake & Secretary stay on Anthropic",
|
||||
);
|
||||
} catch (e) {
|
||||
toast.error("Switch failed: " + errMsg(e));
|
||||
}
|
||||
};
|
||||
|
||||
const flipToOllama = async () => {
|
||||
if (!hasOllamaKey) {
|
||||
toast.error("Save an Ollama API key first");
|
||||
@@ -551,6 +603,126 @@ export function AIRoutingCard() {
|
||||
}
|
||||
};
|
||||
|
||||
// The full per-agent model-picker option list, shared by every group's
|
||||
// Select — factored out so the Codex/Gemini exclusion for the interactive
|
||||
// group (`restrictInteractiveOnly`) doesn't require duplicating the whole
|
||||
// catalog-grouped SelectContent tree.
|
||||
const renderMixSelectOptions = (restrictInteractiveOnly: boolean) => (
|
||||
<>
|
||||
<SelectItem value="__clear__">(inherit global)</SelectItem>
|
||||
|
||||
{/* Anthropic models */}
|
||||
{catalogAnthropicOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="anthropic" />
|
||||
Anthropic
|
||||
</SelectLabel>
|
||||
{catalogAnthropicOnly.map(
|
||||
(c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Grok (xAI) models */}
|
||||
{catalogGrokOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="grok" />
|
||||
Grok (xAI)
|
||||
</SelectLabel>
|
||||
{catalogGrokOnly.map(
|
||||
(c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Codex (OpenAI) models — excluded for the interactive-only group */}
|
||||
{!restrictInteractiveOnly && catalogOpenaiOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="openai" />
|
||||
Codex (OpenAI)
|
||||
</SelectLabel>
|
||||
{catalogOpenaiOnly.map(
|
||||
(c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Gemini (Google) models — excluded for the interactive-only group */}
|
||||
{!restrictInteractiveOnly && catalogGeminiOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="gemini" />
|
||||
Gemini (Google)
|
||||
</SelectLabel>
|
||||
{catalogGeminiOnly.map(
|
||||
(c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Ollama Cloud models */}
|
||||
{catalogOllamaOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="ollama" />
|
||||
Ollama Cloud
|
||||
</SelectLabel>
|
||||
{catalogOllamaOnly.map(
|
||||
(c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Self-Hosted models */}
|
||||
{selfHostedModels.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="self-hosted" />
|
||||
Self-Hosted
|
||||
</SelectLabel>
|
||||
{selfHostedModels.map((m: SelfHostedModel) => (
|
||||
<SelectItem key={m.model_name} value={m.model_name}>
|
||||
{m.display_name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Fallback: un-grouped catalog when no grouping is possible */}
|
||||
{catalogAnthropicOnly.length === 0 &&
|
||||
catalogOllamaOnly.length === 0 &&
|
||||
selfHostedModels.length === 0 &&
|
||||
catalogForMix.map((c: { model_name: string; display_name: string }) => (
|
||||
<SelectItem key={c.model_name} value={c.model_name}>
|
||||
{c.display_name} — {c.model_name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
@@ -560,8 +732,10 @@ export function AIRoutingCard() {
|
||||
<CardDescription>
|
||||
Decide which model backs each agent. Anthropic uses the mounted
|
||||
<code className="px-1"> ~/.claude </code> auth; Grok (xAI) and Ollama
|
||||
Cloud use the API keys you save below; Self-Hosted connects to any
|
||||
OpenAI-compatible endpoint you run locally.
|
||||
Cloud use the API keys you save below; Codex and Gemini authenticate
|
||||
via their own mounted CLI subscriptions (no key needed) — V1:
|
||||
delivery roles only, not Intake/Secretary; Self-Hosted connects to
|
||||
any OpenAI-compatible endpoint you run locally.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
@@ -700,10 +874,10 @@ export function AIRoutingCard() {
|
||||
|
||||
{/* -------- Mode toggle -------- */}
|
||||
<section className="space-y-3">
|
||||
<HelpTip label="Anthropic / Grok / Ollama / Self-Hosted replace role/global routing with that provider; per-agent pins in the table below survive the switch. Mix keeps whatever's picked in the table.">
|
||||
<HelpTip label="Anthropic / Grok / Codex / Gemini / Ollama / Self-Hosted replace role/global routing with that provider; per-agent pins in the table below survive the switch. Mix keeps whatever's picked in the table.">
|
||||
<Label className="text-sm font-medium">Routing mode</Label>
|
||||
</HelpTip>
|
||||
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-2">
|
||||
<div className="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-8 gap-2">
|
||||
<ModeButton
|
||||
icon={<ShieldCheck className="h-4 w-4" />}
|
||||
label="Anthropic"
|
||||
@@ -724,6 +898,24 @@ export function AIRoutingCard() {
|
||||
onClick={flipToGrok}
|
||||
disabled={applyMode.isPending || !hasGrokKey}
|
||||
/>
|
||||
<ModeButton
|
||||
icon={<Bot className="h-4 w-4" />}
|
||||
label="Codex"
|
||||
description="Every agent uses Codex (gpt-5.3-codex)."
|
||||
active={currentMode === "codex"}
|
||||
onClick={flipToCodex}
|
||||
disabled={applyMode.isPending}
|
||||
labelHint="Codex authenticates via a mounted ~/.codex subscription (ChatGPT, no API key) — always available once the CLI is logged in on the host. V1: delivery roles only, not offered for Intake/Secretary."
|
||||
/>
|
||||
<ModeButton
|
||||
icon={<Gem className="h-4 w-4" />}
|
||||
label="Gemini"
|
||||
description="Every agent uses Gemini (gemini-2.5-pro)."
|
||||
active={currentMode === "gemini"}
|
||||
onClick={flipToGemini}
|
||||
disabled={applyMode.isPending}
|
||||
labelHint="Gemini authenticates via a mounted ~/.gemini OAuth login (no API key) — always available once the CLI is logged in on the host. V1: delivery roles only, not offered for Intake/Secretary."
|
||||
/>
|
||||
<ModeButton
|
||||
icon={<Sparkles className="h-4 w-4" />}
|
||||
label="Ollama"
|
||||
@@ -784,6 +976,22 @@ export function AIRoutingCard() {
|
||||
per-agent cost cap all apply.
|
||||
</p>
|
||||
) : null}
|
||||
{currentMode === "codex" || currentMode === "mix" ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Codex agents run on OpenAI's official Codex CLI (ChatGPT
|
||||
subscription, mounted ~/.codex); the same command /
|
||||
secret-exfiltration guard, prompt-injection guard, and per-agent
|
||||
cost cap apply. V1: delivery roles only — not available for
|
||||
Intake/Secretary.
|
||||
</p>
|
||||
) : null}
|
||||
{currentMode === "gemini" || currentMode === "mix" ? (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Gemini agents run on Google's official gemini CLI (OAuth
|
||||
login, mounted ~/.gemini); the same guards apply. V1: delivery
|
||||
roles only — not available for Intake/Secretary.
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
|
||||
{/* -------- Self-Hosted model picker (when self_hosted mode active) -------- */}
|
||||
@@ -953,178 +1161,58 @@ export function AIRoutingCard() {
|
||||
</div>
|
||||
) : (
|
||||
<div className="divide-y rounded-md border">
|
||||
{agentGroups.map((group) => (
|
||||
<div key={group.title} className="p-4">
|
||||
<HelpTip label={group.titleHint}>
|
||||
<h4 className="mb-2 w-fit text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{group.title}
|
||||
</h4>
|
||||
</HelpTip>
|
||||
<div className="grid grid-cols-1 gap-x-8 gap-y-3 sm:grid-cols-2">
|
||||
{group.agents.map((a) => (
|
||||
<div
|
||||
key={a.id}
|
||||
className="grid grid-cols-[1fr_170px] items-center gap-4 rounded-md border px-3 py-2.5"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-mono text-xs">
|
||||
{a.id}
|
||||
</div>
|
||||
<div className="truncate text-[11px] text-muted-foreground">
|
||||
{a.name}
|
||||
</div>
|
||||
</div>
|
||||
<Select
|
||||
value={mixMap[a.id] ?? ""}
|
||||
onValueChange={(v: string) =>
|
||||
setMixMap((prev) => ({
|
||||
...prev,
|
||||
[a.id]: v === "__clear__" ? "" : v,
|
||||
}))
|
||||
}
|
||||
{agentGroups.map((group) => {
|
||||
const restrictInteractiveOnly =
|
||||
group.title === INTERACTIVE_ONLY_GROUP_TITLE;
|
||||
return (
|
||||
<div key={group.title} className="p-4">
|
||||
<HelpTip label={group.titleHint}>
|
||||
<h4 className="mb-2 w-fit text-xs font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{group.title}
|
||||
</h4>
|
||||
</HelpTip>
|
||||
{restrictInteractiveOnly ? (
|
||||
<p className="mb-2 text-[11px] text-muted-foreground">
|
||||
Codex and Gemini are delivery-roles-only (V1) — not
|
||||
offered here (no interactive Intake/Secretary support).
|
||||
</p>
|
||||
) : null}
|
||||
<div className="grid grid-cols-1 gap-x-8 gap-y-3 sm:grid-cols-2">
|
||||
{group.agents.map((a) => (
|
||||
<div
|
||||
key={a.id}
|
||||
className="grid grid-cols-[1fr_170px] items-center gap-4 rounded-md border px-3 py-2.5"
|
||||
>
|
||||
<SelectTrigger size="sm" className="w-full text-xs">
|
||||
<SelectValue placeholder="(inherit)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__clear__">
|
||||
(inherit global)
|
||||
</SelectItem>
|
||||
|
||||
{/* Anthropic models */}
|
||||
{catalogAnthropicOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="anthropic" />
|
||||
Anthropic
|
||||
</SelectLabel>
|
||||
{catalogAnthropicOnly.map(
|
||||
(c: {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
}) => (
|
||||
<SelectItem
|
||||
key={c.model_name}
|
||||
value={c.model_name}
|
||||
>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Grok (xAI) models */}
|
||||
{catalogGrokOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="grok" />
|
||||
Grok (xAI)
|
||||
</SelectLabel>
|
||||
{catalogGrokOnly.map(
|
||||
(c: {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
}) => (
|
||||
<SelectItem
|
||||
key={c.model_name}
|
||||
value={c.model_name}
|
||||
>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Codex (OpenAI) models */}
|
||||
{catalogOpenaiOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="openai" />
|
||||
Codex (OpenAI)
|
||||
</SelectLabel>
|
||||
{catalogOpenaiOnly.map(
|
||||
(c: {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
}) => (
|
||||
<SelectItem
|
||||
key={c.model_name}
|
||||
value={c.model_name}
|
||||
>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Ollama Cloud models */}
|
||||
{catalogOllamaOnly.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="ollama" />
|
||||
Ollama Cloud
|
||||
</SelectLabel>
|
||||
{catalogOllamaOnly.map(
|
||||
(c: {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
}) => (
|
||||
<SelectItem
|
||||
key={c.model_name}
|
||||
value={c.model_name}
|
||||
>
|
||||
{c.display_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Self-Hosted models */}
|
||||
{selfHostedModels.length > 0 && (
|
||||
<SelectGroup>
|
||||
<SelectLabel>
|
||||
<ProviderBadge variant="self-hosted" />
|
||||
Self-Hosted
|
||||
</SelectLabel>
|
||||
{selfHostedModels.map((m: SelfHostedModel) => (
|
||||
<SelectItem
|
||||
key={m.model_name}
|
||||
value={m.model_name}
|
||||
>
|
||||
{m.display_name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectGroup>
|
||||
)}
|
||||
|
||||
{/* Fallback: un-grouped catalog when no grouping is possible */}
|
||||
{catalogAnthropicOnly.length === 0 &&
|
||||
catalogOllamaOnly.length === 0 &&
|
||||
selfHostedModels.length === 0 &&
|
||||
catalogForMix.map(
|
||||
(c: {
|
||||
model_name: string;
|
||||
display_name: string;
|
||||
}) => (
|
||||
<SelectItem
|
||||
key={c.model_name}
|
||||
value={c.model_name}
|
||||
>
|
||||
{c.display_name} — {c.model_name}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
))}
|
||||
<div className="min-w-0">
|
||||
<div className="truncate font-mono text-xs">
|
||||
{a.id}
|
||||
</div>
|
||||
<div className="truncate text-[11px] text-muted-foreground">
|
||||
{a.name}
|
||||
</div>
|
||||
</div>
|
||||
<Select
|
||||
value={mixMap[a.id] ?? ""}
|
||||
onValueChange={(v: string) =>
|
||||
setMixMap((prev) => ({
|
||||
...prev,
|
||||
[a.id]: v === "__clear__" ? "" : v,
|
||||
}))
|
||||
}
|
||||
>
|
||||
<SelectTrigger size="sm" className="w-full text-xs">
|
||||
<SelectValue placeholder="(inherit)" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{renderMixSelectOptions(restrictInteractiveOnly)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
{catalogOllamaOnly.length === 0 ? (
|
||||
@@ -1274,7 +1362,13 @@ function errMsg(e: unknown): string {
|
||||
function ProviderBadge({
|
||||
variant,
|
||||
}: {
|
||||
variant: "anthropic" | "grok" | "openai" | "ollama" | "self-hosted";
|
||||
variant:
|
||||
| "anthropic"
|
||||
| "grok"
|
||||
| "openai"
|
||||
| "gemini"
|
||||
| "ollama"
|
||||
| "self-hosted";
|
||||
}) {
|
||||
const styles: Record<string, string> = {
|
||||
anthropic: "bg-blue-500/20 text-blue-700 dark:text-blue-400",
|
||||
@@ -1282,6 +1376,7 @@ function ProviderBadge({
|
||||
"self-hosted": "bg-purple-500/20 text-purple-700 dark:text-purple-400",
|
||||
grok: "bg-teal-500/20 text-teal-700 dark:text-teal-400",
|
||||
openai: "bg-emerald-500/20 text-emerald-700 dark:text-emerald-400",
|
||||
gemini: "bg-sky-500/20 text-sky-700 dark:text-sky-400",
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
anthropic: "A",
|
||||
@@ -1289,6 +1384,7 @@ function ProviderBadge({
|
||||
"self-hosted": "S",
|
||||
grok: "G",
|
||||
openai: "C",
|
||||
gemini: "Ge",
|
||||
};
|
||||
return (
|
||||
<span
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
|
||||
const { mutateAsync } = vi.hoisted(() => ({
|
||||
const { mutateAsync, spendState } = vi.hoisted(() => ({
|
||||
mutateAsync: vi.fn().mockResolvedValue(undefined),
|
||||
// Mutable per-test stand-in for useTask's query result — mirrors the
|
||||
// real hook's shape ({ data }) so the dialog's spend read-out can be
|
||||
// exercised without a real fetch.
|
||||
spendState: { data: undefined as { spend_usd?: number | null } | undefined },
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-tasks", () => ({
|
||||
useUpdateTask: () => ({ mutateAsync, isPending: false }),
|
||||
useTask: () => spendState,
|
||||
}));
|
||||
|
||||
vi.mock("sonner", () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
|
||||
@@ -82,6 +87,7 @@ function budgetInput(): HTMLInputElement {
|
||||
describe("EditTaskDialog — Budget (USD) input", () => {
|
||||
beforeEach(() => {
|
||||
mutateAsync.mockClear();
|
||||
spendState.data = undefined;
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -183,3 +189,63 @@ describe("EditTaskDialog — Budget (USD) input", () => {
|
||||
expect(updates.budget_usd).toBe(2.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("EditTaskDialog — spend read-out", () => {
|
||||
beforeEach(() => {
|
||||
mutateAsync.mockClear();
|
||||
spendState.data = undefined;
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("renders spend against the cap once useTask resolves", () => {
|
||||
spendState.data = { spend_usd: 12.34 };
|
||||
render(
|
||||
<EditTaskDialog
|
||||
task={{ ...task, budget_usd: 20 }}
|
||||
open={true}
|
||||
onOpenChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByTestId("task-spend").textContent).toBe(
|
||||
"Spent: $12.34 / $20.00",
|
||||
);
|
||||
});
|
||||
|
||||
it("hides the ratio (but still shows spend) when there is no budget cap", () => {
|
||||
spendState.data = { spend_usd: 5 };
|
||||
render(
|
||||
<EditTaskDialog
|
||||
task={{ ...task, budget_usd: null }}
|
||||
open={true}
|
||||
onOpenChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.getByTestId("task-spend").textContent).toBe("Spent: $5.00");
|
||||
});
|
||||
|
||||
it("renders nothing while the spend fetch hasn't resolved yet", () => {
|
||||
spendState.data = undefined;
|
||||
render(
|
||||
<EditTaskDialog
|
||||
task={{ ...task, budget_usd: 20 }}
|
||||
open={true}
|
||||
onOpenChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.queryByTestId("task-spend")).toBeNull();
|
||||
});
|
||||
|
||||
it("renders nothing when the task-budgets flag is off (spend_usd null)", () => {
|
||||
spendState.data = { spend_usd: null };
|
||||
render(
|
||||
<EditTaskDialog
|
||||
task={{ ...task, budget_usd: 20 }}
|
||||
open={true}
|
||||
onOpenChange={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
expect(screen.queryByTestId("task-spend")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useUpdateTask } from "@/hooks/use-tasks";
|
||||
import { useTask, useUpdateTask } from "@/hooks/use-tasks";
|
||||
import { Task, Team, Complexity, TaskNature, TaskType } from "@/types";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -126,6 +126,12 @@ function EditTaskDialogInner({
|
||||
const [advancedOpen, setAdvancedOpen] = useState(false);
|
||||
|
||||
const updateTask = useUpdateTask();
|
||||
// Read-only spend, refetched fresh whenever this dialog is mounted (it only
|
||||
// mounts while open — see EditTaskDialog below). null while loading, when
|
||||
// the task-budgets flag is off, or on fetch error — all rendered the same
|
||||
// way: the spend line is simply omitted (never a broken "$undefined").
|
||||
const { data: freshTask } = useTask(task.id);
|
||||
const spendUsd = freshTask?.spend_usd;
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
@@ -369,6 +375,14 @@ function EditTaskDialogInner({
|
||||
before it spends a cent. Leave blank for the task-type
|
||||
default.
|
||||
</p>
|
||||
{spendUsd != null && (
|
||||
<p className="text-xs text-muted-foreground" data-testid="task-spend">
|
||||
Spent: ${spendUsd.toFixed(2)}
|
||||
{budgetUsd.trim() && !Number.isNaN(Number(budgetUsd))
|
||||
? ` / $${Number(budgetUsd).toFixed(2)}`
|
||||
: ""}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Git Configuration Section */}
|
||||
|
||||
@@ -26,15 +26,15 @@ export interface ModelAssignment {
|
||||
model_name: string;
|
||||
}
|
||||
|
||||
// "codex" is READ-only (derive_mode can report it for a pure-OPENAI global
|
||||
// assignment) — there is no apply_mode="codex" write path, so no UI ever
|
||||
// constructs an ApplyModePayload with this value. One shared type (not a
|
||||
// split read/write pair) keeps this file small; nothing calls applyMode with
|
||||
// mode: "codex" since no button exists for it.
|
||||
// One shared read/write type keeps this file small — every value here has
|
||||
// both an apply_mode write path (a ModeButton) and a derive_mode read path
|
||||
// (GET /providers), except "mix"/"cost_tiered" which are additive/table-driven
|
||||
// rather than single mode-button flips.
|
||||
export type RoutingMode =
|
||||
| "anthropic"
|
||||
| "grok"
|
||||
| "codex"
|
||||
| "gemini"
|
||||
| "ollama"
|
||||
| "self_hosted"
|
||||
| "mix"
|
||||
|
||||
@@ -106,6 +106,7 @@ export enum ModelProvider {
|
||||
OPENAI = "openai",
|
||||
LOCAL = "local",
|
||||
GROK = "grok",
|
||||
GEMINI = "gemini",
|
||||
}
|
||||
|
||||
export enum AssignmentScope {
|
||||
@@ -226,6 +227,10 @@ export interface Task {
|
||||
priority: number; // 0=P0(highest), 1=P1, 2=P2, 3=P3(lowest)
|
||||
// Cost cap (ROBOCO_TASK_BUDGETS_ENABLED). null = use the task-type default.
|
||||
budget_usd?: number | null;
|
||||
// This task's own accumulated agent-spawn spend. Only populated by the
|
||||
// single-task detail fetch (GET /tasks/{id}) when the budgets flag is on;
|
||||
// null on list rows and when the flag is off.
|
||||
spend_usd?: number | null;
|
||||
sequence: number; // Order number within siblings
|
||||
team: Team;
|
||||
created_by: string;
|
||||
@@ -1064,6 +1069,10 @@ export interface Project {
|
||||
// Calendar-month cap on summed agent-spawn spend across this project's
|
||||
// tasks; null = no cap. Only enforced when ROBOCO_TASK_BUDGETS_ENABLED is on.
|
||||
monthly_budget_usd: number | null;
|
||||
// This calendar month's summed agent-spawn spend across this project's
|
||||
// tasks (ProjectService.project_month_spend_usd). Only populated when
|
||||
// ROBOCO_TASK_BUDGETS_ENABLED is on; null otherwise.
|
||||
monthly_spend_usd?: number | null;
|
||||
sandbox_services: string[] | null;
|
||||
sandbox_extensions: Record<string, string[]> | null;
|
||||
// Runtime state
|
||||
|
||||
Reference in New Issue
Block a user