@enactprotocol/cli 2.1.10 → 2.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,56 @@ describe("publish command", () => {
54
54
  const jsonOpt = opts.find((o) => o.long === "--json");
55
55
  expect(jsonOpt).toBeDefined();
56
56
  });
57
+
58
+ test("has --public option", () => {
59
+ const program = new Command();
60
+ configurePublishCommand(program);
61
+
62
+ const publishCmd = program.commands.find((cmd) => cmd.name() === "publish");
63
+ const opts = publishCmd?.options ?? [];
64
+ const publicOpt = opts.find((o) => o.long === "--public");
65
+ expect(publicOpt).toBeDefined();
66
+ });
67
+
68
+ test("has --unlisted option", () => {
69
+ const program = new Command();
70
+ configurePublishCommand(program);
71
+
72
+ const publishCmd = program.commands.find((cmd) => cmd.name() === "publish");
73
+ const opts = publishCmd?.options ?? [];
74
+ const unlistedOpt = opts.find((o) => o.long === "--unlisted");
75
+ expect(unlistedOpt).toBeDefined();
76
+ });
77
+ });
78
+
79
+ describe("visibility determination", () => {
80
+ type ToolVisibility = "public" | "private" | "unlisted";
81
+
82
+ // Mirrors the logic in publish command
83
+ const determineVisibility = (options: {
84
+ public?: boolean;
85
+ unlisted?: boolean;
86
+ }): ToolVisibility => {
87
+ if (options.public) return "public";
88
+ if (options.unlisted) return "unlisted";
89
+ return "private"; // Default is private
90
+ };
91
+
92
+ test("defaults to private visibility", () => {
93
+ expect(determineVisibility({})).toBe("private");
94
+ });
95
+
96
+ test("--public flag sets public visibility", () => {
97
+ expect(determineVisibility({ public: true })).toBe("public");
98
+ });
99
+
100
+ test("--unlisted flag sets unlisted visibility", () => {
101
+ expect(determineVisibility({ unlisted: true })).toBe("unlisted");
102
+ });
103
+
104
+ test("--public takes precedence over --unlisted", () => {
105
+ expect(determineVisibility({ public: true, unlisted: true })).toBe("public");
106
+ });
57
107
  });
58
108
 
59
109
  describe("manifest file detection", () => {
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Tests for the visibility command
3
+ */
4
+
5
+ import { describe, expect, test } from "bun:test";
6
+ import { Command } from "commander";
7
+ import { configureVisibilityCommand } from "../../src/commands/visibility";
8
+
9
+ describe("visibility command", () => {
10
+ describe("command configuration", () => {
11
+ test("configures visibility command on program", () => {
12
+ const program = new Command();
13
+ configureVisibilityCommand(program);
14
+
15
+ const visibilityCmd = program.commands.find((cmd) => cmd.name() === "visibility");
16
+ expect(visibilityCmd).toBeDefined();
17
+ });
18
+
19
+ test("has correct description", () => {
20
+ const program = new Command();
21
+ configureVisibilityCommand(program);
22
+
23
+ const visibilityCmd = program.commands.find((cmd) => cmd.name() === "visibility");
24
+ expect(visibilityCmd?.description()).toBe(
25
+ "Change tool visibility (public, private, or unlisted)"
26
+ );
27
+ });
28
+
29
+ test("accepts tool and visibility arguments", () => {
30
+ const program = new Command();
31
+ configureVisibilityCommand(program);
32
+
33
+ const visibilityCmd = program.commands.find((cmd) => cmd.name() === "visibility");
34
+ const args = visibilityCmd?.registeredArguments ?? [];
35
+ expect(args.length).toBe(2);
36
+ });
37
+
38
+ test("has --json option", () => {
39
+ const program = new Command();
40
+ configureVisibilityCommand(program);
41
+
42
+ const visibilityCmd = program.commands.find((cmd) => cmd.name() === "visibility");
43
+ const opts = visibilityCmd?.options ?? [];
44
+ const jsonOpt = opts.find((o) => o.long === "--json");
45
+ expect(jsonOpt).toBeDefined();
46
+ });
47
+
48
+ test("has --verbose option", () => {
49
+ const program = new Command();
50
+ configureVisibilityCommand(program);
51
+
52
+ const visibilityCmd = program.commands.find((cmd) => cmd.name() === "visibility");
53
+ const opts = visibilityCmd?.options ?? [];
54
+ const verboseOpt = opts.find((o) => o.long === "--verbose");
55
+ expect(verboseOpt).toBeDefined();
56
+ });
57
+ });
58
+
59
+ describe("visibility value validation", () => {
60
+ const VALID_VISIBILITIES = ["public", "private", "unlisted"] as const;
61
+
62
+ test("accepts 'public' visibility", () => {
63
+ expect(VALID_VISIBILITIES.includes("public")).toBe(true);
64
+ });
65
+
66
+ test("accepts 'private' visibility", () => {
67
+ expect(VALID_VISIBILITIES.includes("private")).toBe(true);
68
+ });
69
+
70
+ test("accepts 'unlisted' visibility", () => {
71
+ expect(VALID_VISIBILITIES.includes("unlisted")).toBe(true);
72
+ });
73
+
74
+ test("rejects invalid visibility values", () => {
75
+ const isValid = (v: string): boolean =>
76
+ VALID_VISIBILITIES.includes(v as (typeof VALID_VISIBILITIES)[number]);
77
+
78
+ expect(isValid("internal")).toBe(false);
79
+ expect(isValid("PUBLIC")).toBe(false);
80
+ expect(isValid("")).toBe(false);
81
+ expect(isValid("org-private")).toBe(false);
82
+ });
83
+ });
84
+
85
+ describe("visibility behavior", () => {
86
+ test("public tools are searchable", () => {
87
+ const isSearchable = (visibility: string): boolean => {
88
+ return visibility === "public";
89
+ };
90
+
91
+ expect(isSearchable("public")).toBe(true);
92
+ expect(isSearchable("private")).toBe(false);
93
+ expect(isSearchable("unlisted")).toBe(false);
94
+ });
95
+
96
+ test("public and unlisted tools are accessible via direct link", () => {
97
+ const isDirectAccessible = (visibility: string): boolean => {
98
+ return visibility === "public" || visibility === "unlisted";
99
+ };
100
+
101
+ expect(isDirectAccessible("public")).toBe(true);
102
+ expect(isDirectAccessible("unlisted")).toBe(true);
103
+ expect(isDirectAccessible("private")).toBe(false);
104
+ });
105
+
106
+ test("private tools are only accessible to owner", () => {
107
+ const canAccess = (visibility: string, isOwner: boolean): boolean => {
108
+ if (visibility === "public" || visibility === "unlisted") return true;
109
+ if (visibility === "private") return isOwner;
110
+ return false;
111
+ };
112
+
113
+ expect(canAccess("private", true)).toBe(true);
114
+ expect(canAccess("private", false)).toBe(false);
115
+ expect(canAccess("public", false)).toBe(true);
116
+ expect(canAccess("unlisted", false)).toBe(true);
117
+ });
118
+ });
119
+
120
+ describe("visibility result handling", () => {
121
+ test("success result structure", () => {
122
+ interface VisibilityResult {
123
+ tool: string;
124
+ visibility: string;
125
+ success: boolean;
126
+ }
127
+
128
+ const result: VisibilityResult = {
129
+ tool: "alice/tools/my-tool",
130
+ visibility: "private",
131
+ success: true,
132
+ };
133
+
134
+ expect(result.success).toBe(true);
135
+ expect(result.tool).toBeDefined();
136
+ expect(result.visibility).toBe("private");
137
+ });
138
+
139
+ test("error result for unauthorized", () => {
140
+ interface VisibilityError {
141
+ success: boolean;
142
+ error: string;
143
+ code?: string;
144
+ }
145
+
146
+ const error: VisibilityError = {
147
+ success: false,
148
+ error: "You do not own this tool",
149
+ code: "UNAUTHORIZED",
150
+ };
151
+
152
+ expect(error.success).toBe(false);
153
+ expect(error.error).toBeDefined();
154
+ });
155
+ });
156
+ });