-
-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathPackagesMainCliSpec.cfc
More file actions
257 lines (237 loc) · 8.85 KB
/
Copy pathPackagesMainCliSpec.cfc
File metadata and controls
257 lines (237 loc) · 8.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
component extends="wheels.wheelstest.system.BaseSpec" {
function run() {
describe("PackagesMainCli", () => {
var fixturePath = ExpandPath("/cli/lucli/tests/_fixtures/packages/wheels-fake-1.0.0.tar.gz");
var $scratch = () => {
var root = GetTempDirectory() & "wheels-proj-" & CreateUUID() & "/";
DirectoryCreate(root, true);
return root;
};
var $sha = (path) => LCase(Hash(FileReadBinary(path), "SHA-256"));
// Builds a Registry pre-seeded with two fake packages + a FakeHttpClient.
var $buildStack = (projRoot) => {
var fake = new cli.lucli.tests.specs.packages._stubs.FakeHttpClient();
var cacheRoot = GetTempDirectory() & "wheels-cache-" & CreateUUID() & "/";
var cache = new cli.lucli.services.packages.ManifestCache(root = cacheRoot);
var registry = new cli.lucli.services.packages.Registry(
httpClient = fake, cache = cache, registryRepo = "test/reg"
);
fake.seed(
"https://api.github.com/repos/test/reg/contents/packages?ref=main",
{status: 200, body: SerializeJSON([
{name: "wheels-fake", type: "dir"},
{name: "wheels-other", type: "dir"}
])}
);
fake.seed(
"https://raw.githubusercontent.com/test/reg/main/packages/wheels-fake/manifest.json",
{status: 200, body: SerializeJSON({
name: "wheels-fake",
description: "Fake package for tests",
tags: ["monitoring", "test"],
versions: [{
version: "1.0.0", wheelsVersion: ">=4.0",
tarball: "https://example/wheels-fake-1.0.0.tar.gz",
sha256: $sha(fixturePath)
}]
})}
);
fake.seed(
"https://raw.githubusercontent.com/test/reg/main/packages/wheels-other/manifest.json",
{status: 200, body: SerializeJSON({
name: "wheels-other",
description: "Another one",
tags: ["ui"],
versions: [{
version: "2.0.0", wheelsVersion: ">=4.0",
tarball: "https://example/wheels-other-2.0.0.tar.gz",
sha256: "deadbeef"
}]
})}
);
fake.seed(
"https://example/wheels-fake-1.0.0.tar.gz",
{status: 200, body: FileReadBinary(fixturePath)}
);
var installer = new cli.lucli.services.packages.Installer(
httpClient = fake, projectRoot = projRoot
);
var cli = new cli.lucli.services.packages.PackagesMainCli(
registry = registry, installer = installer, runtimeVersion = "4.0.0"
);
return {cli: cli, fake: fake, cache: cache};
};
it("list returns all packages when no filter", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.list();
expect(out).toInclude("wheels-fake");
expect(out).toInclude("wheels-other");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("list --tag filters to matching tag", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.list({tag: "ui"});
expect(out).toInclude("wheels-other");
expect(out).notToInclude("wheels-fake");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("search matches against name, description, and tags", () => {
var proj = $scratch();
var stack = $buildStack(proj);
expect(stack.cli.search({query: "monitoring"})).toInclude("wheels-fake");
expect(stack.cli.search({query: "another"})).toInclude("wheels-other");
expect(stack.cli.search({query: "zzzz-no-match"})).toInclude("No packages matched");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("show renders package details and compatible versions", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.show({name: "wheels-fake"});
expect(out).toInclude("wheels-fake");
expect(out).toInclude("Fake package for tests");
expect(out).toInclude("1.0.0");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("install fetches manifest, picks latest compat, and extracts to vendor/", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.install({target: "wheels-fake"});
expect(out).toInclude("Installed wheels-fake@1.0.0");
expect(DirectoryExists(proj & "vendor/wheels-fake")).toBeTrue();
expect(FileExists(proj & "vendor/wheels-fake/package.json")).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("install tells the user a reload activates the package (reload re-fires onApplicationStart)", () => {
// An authorized `wheels reload` calls applicationStop(), so the
// next request re-fires onApplicationStart — which runs the
// PackageLoader. A cold restart is no longer required to
// activate an installed package (see #3110).
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.install({target: "wheels-fake"});
expect(out).toInclude("wheels reload");
expect(out).notToInclude("wheels stop && wheels start");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("install honours @version pin", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var out = stack.cli.install({target: "wheels-fake@1.0.0"});
expect(out).toInclude("1.0.0");
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("update <name> without --yes throws ConfirmationRequired", () => {
var proj = $scratch();
var stack = $buildStack(proj);
DirectoryCreate(proj & "vendor/wheels-fake", true);
FileWrite(proj & "vendor/wheels-fake/package.json", "{""name"":""wheels-fake"",""version"":""1.0.0""}");
var threw = false;
try {
stack.cli.update({target: "wheels-fake"});
} catch (any e) {
threw = true;
expect(e.type).toBe("Wheels.Packages.ConfirmationRequired");
}
expect(threw).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("update --all without --yes throws ConfirmationRequired", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var threw = false;
try {
stack.cli.update({all: true});
} catch (any e) {
threw = true;
expect(e.type).toBe("Wheels.Packages.ConfirmationRequired");
}
expect(threw).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("remove refuses a dir without package.json", () => {
var proj = $scratch();
var stack = $buildStack(proj);
DirectoryCreate(proj & "vendor/scary", true);
var threw = false;
try {
stack.cli.remove({target: "scary"});
} catch (any e) {
threw = true;
expect(e.type).toBe("Wheels.Packages.NotAPackage");
}
expect(threw).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("install throws BadInput when target is missing", () => {
var proj = $scratch();
var stack = $buildStack(proj);
var threw = false;
try {
stack.cli.install({});
} catch (any e) {
threw = true;
expect(e.type).toBe("Wheels.Packages.BadInput");
}
expect(threw).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
it("install throws BadInput when target starts with '@' (empty name)", () => {
// Regression guard: `@1.0.0` used to hit Left(str, 0), which
// crashes on Lucee 7 and produces a cryptic error on other
// engines. Must reject cleanly with BadInput.
var proj = $scratch();
var stack = $buildStack(proj);
var threw = false;
try {
stack.cli.install({target: "@1.0.0"});
} catch (any e) {
threw = true;
expect(e.type).toBe("Wheels.Packages.BadInput");
}
expect(threw).toBeTrue();
stack.cache.refresh();
DirectoryDelete(proj, true);
});
});
describe("PackagesRegistryCli", () => {
it("info prints registry details", () => {
var fake = new cli.lucli.tests.specs.packages._stubs.FakeHttpClient();
var cacheRoot = GetTempDirectory() & "wheels-cache-" & CreateUUID() & "/";
var cache = new cli.lucli.services.packages.ManifestCache(root = cacheRoot);
var registry = new cli.lucli.services.packages.Registry(
httpClient = fake, cache = cache, registryRepo = "acme/pkgs"
);
var cli = new cli.lucli.services.packages.PackagesRegistryCli(registry = registry);
var out = cli.info();
expect(out).toInclude("acme/pkgs");
expect(out).toInclude("main");
});
it("refresh wipes the cache", () => {
var fake = new cli.lucli.tests.specs.packages._stubs.FakeHttpClient();
var cacheRoot = GetTempDirectory() & "wheels-cache-" & CreateUUID() & "/";
var cache = new cli.lucli.services.packages.ManifestCache(root = cacheRoot);
cache.writeIndex(["a", "b"]);
expect(DirectoryExists(cacheRoot)).toBeTrue();
var registry = new cli.lucli.services.packages.Registry(
httpClient = fake, cache = cache, registryRepo = "acme/pkgs"
);
var cli = new cli.lucli.services.packages.PackagesRegistryCli(registry = registry);
cli.refresh();
expect(DirectoryExists(cacheRoot)).toBeFalse();
});
});
}
}