Files
kandev/apps/web/components/task/chat/messages/agent-error-label.test.ts
T
João Salavisa d3058276d7 feat(i18n): localize task chat surface (#2303)
Co-authored-by: Kandev Agent <agent@kandev.dev>
2026-08-06 03:01:51 +02:00

56 lines
2.0 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { isEnvironmentSetupError, resolveAgentErrorLabelKey } from "./agent-error-label";
const FALLBACK = "task:agentHasEncounteredAnError";
describe("isEnvironmentSetupError", () => {
it("matches genuine environment/workspace setup failures", () => {
const setupFailures = [
'environment preparation failed: branch "feature/foo" not found locally or on remote',
"failed to launch container",
"session already has an agent running somewhere",
"race resolved during register",
"failed to prepare fresh branch",
];
for (const msg of setupFailures) {
expect(isEnvironmentSetupError(msg)).toBe(true);
}
});
it("does not match downstream agent / API errors", () => {
const agentErrors = [
"API Error: 400 messages.0.content.1: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified.",
"API Error: 401 authentication_error: OAuth token has expired",
"rate_limit_exceeded",
"the agent crashed unexpectedly",
"",
];
for (const msg of agentErrors) {
expect(isEnvironmentSetupError(msg)).toBe(false);
}
});
it("is case-insensitive", () => {
expect(isEnvironmentSetupError("Environment Preparation Failed: x")).toBe(true);
});
});
describe("resolveAgentErrorLabelKey", () => {
it("returns the setup label key only for genuine setup failures", () => {
expect(resolveAgentErrorLabelKey("failed to launch container", FALLBACK)).toBe(
"task:environmentSetupFailed",
);
});
it("returns the fallback label key for downstream agent/API errors", () => {
expect(
resolveAgentErrorLabelKey("API Error: 400 thinking blocks cannot be modified", FALLBACK),
).toBe(FALLBACK);
});
it("returns the fallback label key when there is no error message", () => {
expect(resolveAgentErrorLabelKey(undefined, FALLBACK)).toBe(FALLBACK);
expect(resolveAgentErrorLabelKey("", FALLBACK)).toBe(FALLBACK);
});
});