Elffuss BraidHub

kikocis/continue public

main · 3.4 KiBRawPermalink
1import {
2 convertLegacyModeFlags,
3 buildPermissionOverrides,
4 processCommandFlags,
5} from "./flagProcessor.js";
6
7describe("convertLegacyModeFlags", () => {
8 test("should return 'plan' when readonly is true", () => {
9 expect(convertLegacyModeFlags(true, false)).toBe("plan");
10 });
11
12 test("should return 'auto' when auto is true", () => {
13 expect(convertLegacyModeFlags(false, true)).toBe("auto");
14 });
15
16 test("should return undefined when both flags are false", () => {
17 expect(convertLegacyModeFlags(false, false)).toBeUndefined();
18 });
19
20 test("should return undefined when no flags provided", () => {
21 expect(convertLegacyModeFlags()).toBeUndefined();
22 });
23
24 test("should throw error when both readonly and auto are true", () => {
25 expect(() => convertLegacyModeFlags(true, true)).toThrow(
26 "Cannot use both --readonly and --auto flags together",
27 );
28 });
29});
30
31describe("buildPermissionOverrides", () => {
32 test("should build permission overrides with all parameters", () => {
33 const result = buildPermissionOverrides(
34 ["readFile"],
35 ["writeFile"],
36 ["runTerminalCommand"],
37 "plan",
38 );
39
40 expect(result).toEqual({
41 allow: ["readFile"],
42 ask: ["writeFile"],
43 exclude: ["runTerminalCommand"],
44 mode: "plan",
45 });
46 });
47
48 test("should handle undefined parameters", () => {
49 const result = buildPermissionOverrides();
50
51 expect(result).toEqual({
52 allow: undefined,
53 ask: undefined,
54 exclude: undefined,
55 mode: undefined,
56 });
57 });
58
59 test("should handle partial parameters", () => {
60 const result = buildPermissionOverrides(["readFile"], undefined, ["Write"]);
61
62 expect(result).toEqual({
63 allow: ["readFile"],
64 ask: undefined,
65 exclude: ["Write"],
66 mode: undefined,
67 });
68 });
69});
70
71describe("processCommandFlags", () => {
72 test("should process readonly flag correctly", () => {
73 const result = processCommandFlags({
74 readonly: true,
75 allow: ["readFile"],
76 exclude: ["Write"],
77 });
78
79 expect(result).toEqual({
80 mode: "plan",
81 permissionOverrides: {
82 allow: ["readFile"],
83 ask: undefined,
84 exclude: ["Write"],
85 mode: "plan",
86 },
87 });
88 });
89
90 test("should process auto flag correctly", () => {
91 const result = processCommandFlags({
92 auto: true,
93 ask: ["writeFile"],
94 });
95
96 expect(result).toEqual({
97 mode: "auto",
98 permissionOverrides: {
99 allow: undefined,
100 ask: ["writeFile"],
101 exclude: undefined,
102 mode: "auto",
103 },
104 });
105 });
106
107 test("should handle no mode flags", () => {
108 const result = processCommandFlags({
109 allow: ["readFile", "searchCode"],
110 });
111
112 expect(result).toEqual({
113 mode: undefined,
114 permissionOverrides: {
115 allow: ["readFile", "searchCode"],
116 ask: undefined,
117 exclude: undefined,
118 mode: undefined,
119 },
120 });
121 });
122
123 test("should throw error for conflicting flags", () => {
124 expect(() =>
125 processCommandFlags({
126 readonly: true,
127 auto: true,
128 }),
129 ).toThrow("Cannot use both --readonly and --auto flags together");
130 });
131
132 test("should handle empty options", () => {
133 const result = processCommandFlags({});
134
135 expect(result).toEqual({
136 mode: undefined,
137 permissionOverrides: {
138 allow: undefined,
139 ask: undefined,
140 exclude: undefined,
141 mode: undefined,
142 },
143 });
144 });
145});