1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 EnvironmentAuthInvalidError,
5 EnvironmentInternalError,
6 EnvironmentOperationForbiddenError,
7 EnvironmentRequestInvalidError,
8 EnvironmentResourceNotFoundError,
9 EnvironmentScopeRequiredError,
10} from "./environmentHttp.ts";
11
12const traceId = "trace-1";
13
14describe("environment HTTP errors", () => {
15 // A client squashes the cause and shows `message`; an empty one becomes a generic
16 // "The environment request failed." that names nothing the reader can act on.
17 it("each carries a message that names its reason", () => {
18 const errors = [
19 new EnvironmentRequestInvalidError({
20 code: "invalid_request",
21 reason: "invalid_command",
22 traceId,
23 }),
24 new EnvironmentAuthInvalidError({
25 code: "auth_invalid",
26 reason: "missing_credential",
27 traceId,
28 }),
29 new EnvironmentScopeRequiredError({
30 code: "insufficient_scope",
31 requiredScope: "orchestration:read",
32 traceId,
33 }),
34 new EnvironmentOperationForbiddenError({
35 code: "operation_forbidden",
36 reason: "current_session_revoke_not_allowed",
37 traceId,
38 }),
39 new EnvironmentResourceNotFoundError({
40 code: "not_found",
41 reason: "thread_not_found",
42 traceId,
43 }),
44 new EnvironmentInternalError({
45 code: "internal_error",
46 reason: "orchestration_snapshot_failed",
47 traceId,
48 }),
49 ] as const;
50 const details = [
51 "invalid_command",
52 "missing_credential",
53 "orchestration:read",
54 "current_session_revoke_not_allowed",
55 "thread_not_found",
56 "orchestration_snapshot_failed",
57 ];
58 errors.forEach((error, index) => {
59 expect(error.message).toContain(details[index]);
60 });
61 });
62});