@nuelink/nuelink-cli 1.4.1 → 1.4.3
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.
- package/README.md +47 -41
- package/package.json +31 -30
- package/src/commands.js +194 -142
- package/src/http.js +126 -126
- package/src/postPayload.js +26 -20
- package/src/validation.js +94 -50
- package/test/cli.test.mjs +320 -219
package/test/cli.test.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import test from "node:test";
|
|
|
2
2
|
import assert from "node:assert/strict";
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
|
-
import { mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
|
|
5
|
+
import { mkdir, mkdtemp, readFile, readdir, writeFile } from "node:fs/promises";
|
|
6
6
|
import { spawnSync } from "node:child_process";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
@@ -23,7 +23,7 @@ function currentApiKey() {
|
|
|
23
23
|
return process.env.NUELINK_API_KEY || "test_api_key";
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function runCli({ args, homeDir, capturePath, withMock = true, input, extraEnv = {} }) {
|
|
26
|
+
function runCli({ args, homeDir, capturePath, withMock = true, input, extraEnv = {} }) {
|
|
27
27
|
const nodeArgs = withMock
|
|
28
28
|
? ["--require", mockCjsPath, mainPath, ...args]
|
|
29
29
|
: [mainPath, ...args];
|
|
@@ -41,16 +41,16 @@ function runCli({ args, homeDir, capturePath, withMock = true, input, extraEnv =
|
|
|
41
41
|
},
|
|
42
42
|
input,
|
|
43
43
|
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function assertJsonError(result, code) {
|
|
47
|
-
assert.equal(result.status, 1, result.stderr);
|
|
48
|
-
assert.equal(result.stderr, "");
|
|
49
|
-
const output = JSON.parse(result.stdout);
|
|
50
|
-
assert.equal(output.success, false);
|
|
51
|
-
assert.equal(output.error.code, code);
|
|
52
|
-
return output.error;
|
|
53
|
-
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assertJsonError(result, code) {
|
|
47
|
+
assert.equal(result.status, 1, result.stderr);
|
|
48
|
+
assert.equal(result.stderr, "");
|
|
49
|
+
const output = JSON.parse(result.stdout);
|
|
50
|
+
assert.equal(output.success, false);
|
|
51
|
+
assert.equal(output.error.code, code);
|
|
52
|
+
return output.error;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
55
|
test("brands command builds pagination query", async () => {
|
|
56
56
|
const homeDir = await setupTempHome();
|
|
@@ -134,6 +134,89 @@ test("posts command builds pagination query", async () => {
|
|
|
134
134
|
assert.equal(url.searchParams.get("page"), "4");
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
test("auth:validate calls the documented token-validation route", async () => {
|
|
138
|
+
const homeDir = await setupTempHome();
|
|
139
|
+
const capturePath = path.join(homeDir, "capture-auth-validate.json");
|
|
140
|
+
|
|
141
|
+
const result = runCli({
|
|
142
|
+
args: ["auth:validate"],
|
|
143
|
+
homeDir,
|
|
144
|
+
capturePath,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
assert.equal(result.status, 0, result.stderr);
|
|
148
|
+
const capture = JSON.parse(await readFile(capturePath, "utf8"));
|
|
149
|
+
const url = new URL(capture.url);
|
|
150
|
+
assert.equal(url.origin, "https://app.nuelink.com");
|
|
151
|
+
assert.equal(url.pathname, "/api/public/v1/auth");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("posts command supports all documented filter parameters", async () => {
|
|
155
|
+
const homeDir = await setupTempHome();
|
|
156
|
+
const capturePath = path.join(homeDir, "capture-posts-filters.json");
|
|
157
|
+
|
|
158
|
+
const result = runCli({
|
|
159
|
+
args: [
|
|
160
|
+
"posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
161
|
+
"--status", "pending", "--post-type", "image", "--posting-type", "schedule",
|
|
162
|
+
"--created-from", "2026-10-01 00:00:00", "--created-to", "2026-10-31 23:59:59",
|
|
163
|
+
"--sort-by", "post_date", "--sort-order", "ASC",
|
|
164
|
+
],
|
|
165
|
+
homeDir,
|
|
166
|
+
capturePath,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
assert.equal(result.status, 0, result.stderr);
|
|
170
|
+
const url = new URL(JSON.parse(await readFile(capturePath, "utf8")).url);
|
|
171
|
+
assert.equal(url.searchParams.get("status"), "PENDING");
|
|
172
|
+
assert.equal(url.searchParams.get("post_type"), "IMAGE");
|
|
173
|
+
assert.equal(url.searchParams.get("posting_type"), "SCHEDULE");
|
|
174
|
+
assert.equal(url.searchParams.get("created_from"), "2026-10-01 00:00:00");
|
|
175
|
+
assert.equal(url.searchParams.get("created_to"), "2026-10-31 23:59:59");
|
|
176
|
+
assert.equal(url.searchParams.get("sort_by"), "post_date");
|
|
177
|
+
assert.equal(url.searchParams.get("sort_order"), "asc");
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("posts command rejects reversed or invalid creation-time filters", async () => {
|
|
181
|
+
const homeDir = await setupTempHome();
|
|
182
|
+
const capturePath = path.join(homeDir, "capture-posts-invalid-filters.json");
|
|
183
|
+
|
|
184
|
+
const result = runCli({
|
|
185
|
+
args: [
|
|
186
|
+
"--json", "posts", "--brand-id", "13493", "--collection-id", "33273",
|
|
187
|
+
"--created-from", "2026-10-02 00:00:00", "--created-to", "2026-10-01 00:00:00",
|
|
188
|
+
],
|
|
189
|
+
homeDir,
|
|
190
|
+
capturePath,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
assertJsonError(result, "VALIDATION_ERROR");
|
|
194
|
+
await assert.rejects(readFile(capturePath, "utf8"));
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test("media upload accepts documented PDF files and rejects unsupported GIF uploads", async () => {
|
|
198
|
+
const homeDir = await setupTempHome();
|
|
199
|
+
const pdfPath = path.join(homeDir, "document.pdf");
|
|
200
|
+
const gifPath = path.join(homeDir, "animation.gif");
|
|
201
|
+
await writeFile(pdfPath, "pdf content");
|
|
202
|
+
await writeFile(gifPath, "gif content");
|
|
203
|
+
|
|
204
|
+
const pdfResult = runCli({
|
|
205
|
+
args: ["media:upload", "--brand-id", "42", "--file", pdfPath, "--dry-run"],
|
|
206
|
+
homeDir,
|
|
207
|
+
capturePath: path.join(homeDir, "capture-pdf.json"),
|
|
208
|
+
});
|
|
209
|
+
assert.equal(pdfResult.status, 0, pdfResult.stderr);
|
|
210
|
+
assert.equal(JSON.parse(pdfResult.stdout).multipart.type, "application/pdf");
|
|
211
|
+
|
|
212
|
+
const gifResult = runCli({
|
|
213
|
+
args: ["--json", "media:upload", "--brand-id", "42", "--file", gifPath, "--dry-run"],
|
|
214
|
+
homeDir,
|
|
215
|
+
capturePath: path.join(homeDir, "capture-gif.json"),
|
|
216
|
+
});
|
|
217
|
+
assertJsonError(gifResult, "VALIDATION_ERROR");
|
|
218
|
+
});
|
|
219
|
+
|
|
137
220
|
test("brands command renders table output", async () => {
|
|
138
221
|
const homeDir = await setupTempHome();
|
|
139
222
|
const capturePath = path.join(homeDir, "capture-brands-table.json");
|
|
@@ -211,7 +294,7 @@ test("version flags print package version", async () => {
|
|
|
211
294
|
});
|
|
212
295
|
|
|
213
296
|
assert.equal(result.status, 0, result.stderr);
|
|
214
|
-
assert.equal(result.stdout.trim(), "1.4.
|
|
297
|
+
assert.equal(result.stdout.trim(), "1.4.3");
|
|
215
298
|
assert.equal(result.stderr, "");
|
|
216
299
|
}
|
|
217
300
|
});
|
|
@@ -298,7 +381,7 @@ test("automations:create works when boolean flags are omitted", async () => {
|
|
|
298
381
|
assert.equal(capture.body.addPostsAsDraft, undefined);
|
|
299
382
|
});
|
|
300
383
|
|
|
301
|
-
test("auth:login stores token in isolated home config", async () => {
|
|
384
|
+
test("auth:login stores token in isolated home config", async () => {
|
|
302
385
|
const homeDir = await setupTempHome();
|
|
303
386
|
const result = runCli({
|
|
304
387
|
args: ["auth:login", "--stdin"],
|
|
@@ -316,44 +399,44 @@ test("auth:login stores token in isolated home config", async () => {
|
|
|
316
399
|
assert.equal(config.apiKey, undefined);
|
|
317
400
|
assert.equal(typeof config.encryptedApiKey, "string");
|
|
318
401
|
assert.equal(typeof config.iv, "string");
|
|
319
|
-
assert.equal(typeof config.authTag, "string");
|
|
320
|
-
assert.deepEqual(
|
|
321
|
-
(await readdir(path.dirname(configPath))).filter((name) => name.endsWith(".tmp")),
|
|
322
|
-
[],
|
|
323
|
-
);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test("auth:clear atomically replaces an existing saved config", async () => {
|
|
327
|
-
const homeDir = await setupTempHome();
|
|
328
|
-
const capturePath = path.join(homeDir, "capture-auth-clear.json");
|
|
329
|
-
|
|
330
|
-
const login = runCli({
|
|
331
|
-
args: ["auth:login", "--stdin"],
|
|
332
|
-
homeDir,
|
|
333
|
-
capturePath,
|
|
334
|
-
withMock: false,
|
|
335
|
-
input: "saved_token\n",
|
|
336
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
337
|
-
});
|
|
338
|
-
assert.equal(login.status, 0, login.stderr);
|
|
339
|
-
|
|
340
|
-
const clear = runCli({
|
|
341
|
-
args: ["--json", "auth:clear"],
|
|
342
|
-
homeDir,
|
|
343
|
-
capturePath,
|
|
344
|
-
withMock: false,
|
|
345
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
346
|
-
});
|
|
347
|
-
assert.equal(clear.status, 0, clear.stderr);
|
|
348
|
-
assert.deepEqual(JSON.parse(clear.stdout), { success: true, cleared: true });
|
|
349
|
-
|
|
350
|
-
const configPath = path.join(homeDir, ".nuelink-cli", "config.json");
|
|
351
|
-
assert.deepEqual(JSON.parse(await readFile(configPath, "utf8")), {});
|
|
352
|
-
assert.deepEqual(
|
|
353
|
-
(await readdir(path.dirname(configPath))).filter((name) => name.endsWith(".tmp")),
|
|
354
|
-
[],
|
|
355
|
-
);
|
|
356
|
-
});
|
|
402
|
+
assert.equal(typeof config.authTag, "string");
|
|
403
|
+
assert.deepEqual(
|
|
404
|
+
(await readdir(path.dirname(configPath))).filter((name) => name.endsWith(".tmp")),
|
|
405
|
+
[],
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
test("auth:clear atomically replaces an existing saved config", async () => {
|
|
410
|
+
const homeDir = await setupTempHome();
|
|
411
|
+
const capturePath = path.join(homeDir, "capture-auth-clear.json");
|
|
412
|
+
|
|
413
|
+
const login = runCli({
|
|
414
|
+
args: ["auth:login", "--stdin"],
|
|
415
|
+
homeDir,
|
|
416
|
+
capturePath,
|
|
417
|
+
withMock: false,
|
|
418
|
+
input: "saved_token\n",
|
|
419
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
420
|
+
});
|
|
421
|
+
assert.equal(login.status, 0, login.stderr);
|
|
422
|
+
|
|
423
|
+
const clear = runCli({
|
|
424
|
+
args: ["--json", "auth:clear"],
|
|
425
|
+
homeDir,
|
|
426
|
+
capturePath,
|
|
427
|
+
withMock: false,
|
|
428
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
429
|
+
});
|
|
430
|
+
assert.equal(clear.status, 0, clear.stderr);
|
|
431
|
+
assert.deepEqual(JSON.parse(clear.stdout), { success: true, cleared: true });
|
|
432
|
+
|
|
433
|
+
const configPath = path.join(homeDir, ".nuelink-cli", "config.json");
|
|
434
|
+
assert.deepEqual(JSON.parse(await readFile(configPath, "utf8")), {});
|
|
435
|
+
assert.deepEqual(
|
|
436
|
+
(await readdir(path.dirname(configPath))).filter((name) => name.endsWith(".tmp")),
|
|
437
|
+
[],
|
|
438
|
+
);
|
|
439
|
+
});
|
|
357
440
|
|
|
358
441
|
test("runtime api key is exposed as a runtime auth source", async () => {
|
|
359
442
|
const homeDir = await setupTempHome();
|
|
@@ -475,6 +558,7 @@ test("posts:add-json forwards payload file to API", async () => {
|
|
|
475
558
|
title: "post title",
|
|
476
559
|
caption: "post body",
|
|
477
560
|
publishMode: "DRAFT",
|
|
561
|
+
autoThreadText: true,
|
|
478
562
|
};
|
|
479
563
|
|
|
480
564
|
await writeFile(payloadPath, JSON.stringify(payload, null, 2), "utf8");
|
|
@@ -560,6 +644,20 @@ test("posts:add-json validates calendar dates", async () => {
|
|
|
560
644
|
assert.match(result.stderr, /Invalid scheduled-at/);
|
|
561
645
|
});
|
|
562
646
|
|
|
647
|
+
test("posts:add-json rejects invalid autoThreadText values", async () => {
|
|
648
|
+
const homeDir = await setupTempHome();
|
|
649
|
+
|
|
650
|
+
const result = runCli({
|
|
651
|
+
args: ["posts:add-json", "--brand-id", "10", "--collection-id", "20", "--payload", "-"],
|
|
652
|
+
homeDir,
|
|
653
|
+
capturePath: path.join(homeDir, "capture-posts-invalid-auto-thread-text.json"),
|
|
654
|
+
input: JSON.stringify({ caption: "post", publishMode: "DRAFT", autoThreadText: "true" }),
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
assert.equal(result.status, 1);
|
|
658
|
+
assert.match(result.stderr, /Invalid autoThreadText/);
|
|
659
|
+
});
|
|
660
|
+
|
|
563
661
|
test("dry-run prints validated request without sending", async () => {
|
|
564
662
|
const homeDir = await setupTempHome();
|
|
565
663
|
const capturePath = path.join(homeDir, "capture-dry-run.json");
|
|
@@ -612,6 +710,8 @@ test("posts:create builds full payload from options", async () => {
|
|
|
612
710
|
"alt text",
|
|
613
711
|
"--link",
|
|
614
712
|
"https://nuelink.com",
|
|
713
|
+
"--auto-thread-text",
|
|
714
|
+
"true",
|
|
615
715
|
"--publish-mode",
|
|
616
716
|
"DRAFT",
|
|
617
717
|
"--post-as-story",
|
|
@@ -669,6 +769,7 @@ test("posts:create builds full payload from options", async () => {
|
|
|
669
769
|
assert.equal(capture.method, "POST");
|
|
670
770
|
assert.equal(capture.body.title, "title here");
|
|
671
771
|
assert.equal(capture.body.caption, "body here");
|
|
772
|
+
assert.equal(capture.body.autoThreadText, true);
|
|
672
773
|
assert.equal(capture.body.postAsStory, true);
|
|
673
774
|
assert.equal(capture.body.comment.delay, 30);
|
|
674
775
|
assert.deepEqual(capture.body.media, [
|
|
@@ -992,7 +1093,7 @@ test("timeouts exit non-zero", async () => {
|
|
|
992
1093
|
assert.match(result.stderr, /Request timed out/);
|
|
993
1094
|
});
|
|
994
1095
|
|
|
995
|
-
test("malformed JSON success responses fail as protocol errors", async () => {
|
|
1096
|
+
test("malformed JSON success responses fail as protocol errors", async () => {
|
|
996
1097
|
const homeDir = await setupTempHome();
|
|
997
1098
|
|
|
998
1099
|
const result = runCli({
|
|
@@ -1004,172 +1105,172 @@ test("malformed JSON success responses fail as protocol errors", async () => {
|
|
|
1004
1105
|
},
|
|
1005
1106
|
});
|
|
1006
1107
|
|
|
1007
|
-
const error = assertJsonError(result, "PROTOCOL_ERROR");
|
|
1008
|
-
assert.match(error.message, /Protocol error: expected a JSON response/);
|
|
1009
|
-
assert.equal(error.httpStatus, 200);
|
|
1010
|
-
});
|
|
1011
|
-
|
|
1012
|
-
for (const fixture of [
|
|
1013
|
-
{
|
|
1014
|
-
name: "collection titles",
|
|
1015
|
-
args: ["collections:create", "--brand-id", "1", "--title", " ", "--dry-run"],
|
|
1016
|
-
},
|
|
1017
|
-
{
|
|
1018
|
-
name: "automation titles",
|
|
1019
|
-
args: [
|
|
1020
|
-
"automations:create", "--brand-id", "1", "--collection-id", "2",
|
|
1021
|
-
"--feed-url", "https://example.com/feed.xml", "--import-as-type", "IMAGE",
|
|
1022
|
-
"--sub-type", "RSS", "--title", " ", "--dry-run",
|
|
1023
|
-
],
|
|
1024
|
-
},
|
|
1025
|
-
{
|
|
1026
|
-
name: "post captions",
|
|
1027
|
-
args: ["posts:create", "--brand-id", "1", "--collection-id", "2", "--caption", " ", "--dry-run"],
|
|
1028
|
-
},
|
|
1029
|
-
]) {
|
|
1030
|
-
test(`rejects whitespace-only ${fixture.name}`, async () => {
|
|
1031
|
-
const homeDir = await setupTempHome();
|
|
1032
|
-
const result = runCli({
|
|
1033
|
-
args: fixture.args,
|
|
1034
|
-
homeDir,
|
|
1035
|
-
capturePath: path.join(homeDir, `capture-blank-${fixture.name}.json`),
|
|
1036
|
-
});
|
|
1037
|
-
|
|
1038
|
-
assert.equal(result.status, 1);
|
|
1039
|
-
assert.match(result.stderr, /must not be blank/);
|
|
1040
|
-
});
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
test("--json emits one structured object for missing authentication", async () => {
|
|
1044
|
-
const homeDir = await setupTempHome();
|
|
1045
|
-
const result = runCli({
|
|
1046
|
-
args: ["--json", "brands"],
|
|
1047
|
-
homeDir,
|
|
1048
|
-
capturePath: path.join(homeDir, "capture-json-auth.json"),
|
|
1049
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
1050
|
-
});
|
|
1051
|
-
|
|
1052
|
-
assertJsonError(result, "AUTH_MISSING");
|
|
1053
|
-
});
|
|
1054
|
-
|
|
1055
|
-
test("--json emits one structured object for validation errors", async () => {
|
|
1056
|
-
const homeDir = await setupTempHome();
|
|
1057
|
-
const result = runCli({
|
|
1058
|
-
args: ["--json", "collections:create", "--brand-id", "1", "--title", " ", "--dry-run"],
|
|
1059
|
-
homeDir,
|
|
1060
|
-
capturePath: path.join(homeDir, "capture-json-validation.json"),
|
|
1061
|
-
});
|
|
1062
|
-
|
|
1063
|
-
assertJsonError(result, "VALIDATION_ERROR");
|
|
1064
|
-
});
|
|
1065
|
-
|
|
1066
|
-
test("--json emits one structured object for command usage errors", async () => {
|
|
1067
|
-
const homeDir = await setupTempHome();
|
|
1068
|
-
const result = runCli({
|
|
1069
|
-
args: ["--json", "collections"],
|
|
1070
|
-
homeDir,
|
|
1071
|
-
capturePath: path.join(homeDir, "capture-json-usage.json"),
|
|
1072
|
-
});
|
|
1073
|
-
|
|
1074
|
-
assertJsonError(result, "USAGE_ERROR");
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
test("--json emits one structured object for HTTP errors", async () => {
|
|
1078
|
-
const homeDir = await setupTempHome();
|
|
1079
|
-
const result = runCli({
|
|
1080
|
-
args: ["--json", "brands"],
|
|
1081
|
-
homeDir,
|
|
1082
|
-
capturePath: path.join(homeDir, "capture-json-http.json"),
|
|
1083
|
-
extraEnv: {
|
|
1084
|
-
NUELINK_MOCK_FAIL_COUNT: "1",
|
|
1085
|
-
NUELINK_MOCK_FAIL_STATUS: "422",
|
|
1086
|
-
NUELINK_MOCK_FAIL_PATH: "/brands",
|
|
1087
|
-
NUELINK_GET_RETRIES: "0",
|
|
1088
|
-
},
|
|
1089
|
-
});
|
|
1090
|
-
|
|
1091
|
-
const error = assertJsonError(result, "HTTP_ERROR");
|
|
1092
|
-
assert.equal(error.httpStatus, 422);
|
|
1093
|
-
});
|
|
1094
|
-
|
|
1095
|
-
test("--json reports malformed config without silently ignoring it", async () => {
|
|
1096
|
-
const homeDir = await setupTempHome();
|
|
1097
|
-
const configDir = path.join(homeDir, ".nuelink-cli");
|
|
1098
|
-
await mkdir(configDir, { recursive: true });
|
|
1099
|
-
await writeFile(path.join(configDir, "config.json"), "{not-json}", "utf8");
|
|
1100
|
-
|
|
1101
|
-
const result = runCli({
|
|
1102
|
-
args: ["--json", "auth:status"],
|
|
1103
|
-
homeDir,
|
|
1104
|
-
capturePath: path.join(homeDir, "capture-json-config.json"),
|
|
1105
|
-
withMock: false,
|
|
1106
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
1107
|
-
});
|
|
1108
|
-
|
|
1109
|
-
assertJsonError(result, "CONFIG_INVALID");
|
|
1110
|
-
});
|
|
1111
|
-
|
|
1112
|
-
test("--json reports corrupted saved credentials", async () => {
|
|
1113
|
-
const homeDir = await setupTempHome();
|
|
1114
|
-
const configDir = path.join(homeDir, ".nuelink-cli");
|
|
1115
|
-
await mkdir(configDir, { recursive: true });
|
|
1116
|
-
await writeFile(path.join(configDir, "config.json"), JSON.stringify({
|
|
1117
|
-
version: 1,
|
|
1118
|
-
encryptedApiKey: "invalid",
|
|
1119
|
-
iv: "invalid",
|
|
1120
|
-
authTag: "invalid",
|
|
1121
|
-
}), "utf8");
|
|
1122
|
-
|
|
1123
|
-
const result = runCli({
|
|
1124
|
-
args: ["--json", "auth:status"],
|
|
1125
|
-
homeDir,
|
|
1126
|
-
capturePath: path.join(homeDir, "capture-json-corrupt-config.json"),
|
|
1127
|
-
withMock: false,
|
|
1128
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
1129
|
-
});
|
|
1130
|
-
|
|
1131
|
-
assertJsonError(result, "CONFIG_INVALID");
|
|
1132
|
-
});
|
|
1133
|
-
|
|
1134
|
-
test("auth:login refuses an unsafe config directory path", async () => {
|
|
1135
|
-
const homeDir = await setupTempHome();
|
|
1136
|
-
await writeFile(path.join(homeDir, ".nuelink-cli"), "not-a-directory", "utf8");
|
|
1137
|
-
|
|
1138
|
-
const result = runCli({
|
|
1139
|
-
args: ["--json", "auth:login", "--stdin"],
|
|
1140
|
-
homeDir,
|
|
1141
|
-
capturePath: path.join(homeDir, "capture-unsafe-config.json"),
|
|
1142
|
-
withMock: false,
|
|
1143
|
-
input: "saved_token\n",
|
|
1144
|
-
extraEnv: { NUELINK_API_KEY: "" },
|
|
1145
|
-
});
|
|
1146
|
-
|
|
1147
|
-
assertJsonError(result, "CONFIG_UNSAFE");
|
|
1148
|
-
});
|
|
1149
|
-
|
|
1150
|
-
test("--json emits one structured object for timeouts", async () => {
|
|
1151
|
-
const homeDir = await setupTempHome();
|
|
1152
|
-
const result = runCli({
|
|
1153
|
-
args: ["--json", "brands"],
|
|
1154
|
-
homeDir,
|
|
1155
|
-
capturePath: path.join(homeDir, "capture-json-timeout.json"),
|
|
1156
|
-
extraEnv: { NUELINK_MOCK_THROW_TIMEOUT: "1" },
|
|
1157
|
-
});
|
|
1158
|
-
|
|
1159
|
-
assertJsonError(result, "TIMEOUT");
|
|
1160
|
-
});
|
|
1161
|
-
|
|
1162
|
-
test("invalid timeout and retry environment values fail before a request", async () => {
|
|
1163
|
-
const homeDir = await setupTempHome();
|
|
1164
|
-
const result = runCli({
|
|
1165
|
-
args: ["--json", "brands"],
|
|
1166
|
-
homeDir,
|
|
1167
|
-
capturePath: path.join(homeDir, "capture-invalid-timeout.json"),
|
|
1168
|
-
extraEnv: { NUELINK_TIMEOUT_MS: "not-a-number" },
|
|
1169
|
-
});
|
|
1170
|
-
|
|
1171
|
-
assertJsonError(result, "CONFIG_INVALID");
|
|
1172
|
-
});
|
|
1108
|
+
const error = assertJsonError(result, "PROTOCOL_ERROR");
|
|
1109
|
+
assert.match(error.message, /Protocol error: expected a JSON response/);
|
|
1110
|
+
assert.equal(error.httpStatus, 200);
|
|
1111
|
+
});
|
|
1112
|
+
|
|
1113
|
+
for (const fixture of [
|
|
1114
|
+
{
|
|
1115
|
+
name: "collection titles",
|
|
1116
|
+
args: ["collections:create", "--brand-id", "1", "--title", " ", "--dry-run"],
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
name: "automation titles",
|
|
1120
|
+
args: [
|
|
1121
|
+
"automations:create", "--brand-id", "1", "--collection-id", "2",
|
|
1122
|
+
"--feed-url", "https://example.com/feed.xml", "--import-as-type", "IMAGE",
|
|
1123
|
+
"--sub-type", "RSS", "--title", " ", "--dry-run",
|
|
1124
|
+
],
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
name: "post captions",
|
|
1128
|
+
args: ["posts:create", "--brand-id", "1", "--collection-id", "2", "--caption", " ", "--dry-run"],
|
|
1129
|
+
},
|
|
1130
|
+
]) {
|
|
1131
|
+
test(`rejects whitespace-only ${fixture.name}`, async () => {
|
|
1132
|
+
const homeDir = await setupTempHome();
|
|
1133
|
+
const result = runCli({
|
|
1134
|
+
args: fixture.args,
|
|
1135
|
+
homeDir,
|
|
1136
|
+
capturePath: path.join(homeDir, `capture-blank-${fixture.name}.json`),
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
assert.equal(result.status, 1);
|
|
1140
|
+
assert.match(result.stderr, /must not be blank/);
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
test("--json emits one structured object for missing authentication", async () => {
|
|
1145
|
+
const homeDir = await setupTempHome();
|
|
1146
|
+
const result = runCli({
|
|
1147
|
+
args: ["--json", "brands"],
|
|
1148
|
+
homeDir,
|
|
1149
|
+
capturePath: path.join(homeDir, "capture-json-auth.json"),
|
|
1150
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1151
|
+
});
|
|
1152
|
+
|
|
1153
|
+
assertJsonError(result, "AUTH_MISSING");
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
test("--json emits one structured object for validation errors", async () => {
|
|
1157
|
+
const homeDir = await setupTempHome();
|
|
1158
|
+
const result = runCli({
|
|
1159
|
+
args: ["--json", "collections:create", "--brand-id", "1", "--title", " ", "--dry-run"],
|
|
1160
|
+
homeDir,
|
|
1161
|
+
capturePath: path.join(homeDir, "capture-json-validation.json"),
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
assertJsonError(result, "VALIDATION_ERROR");
|
|
1165
|
+
});
|
|
1166
|
+
|
|
1167
|
+
test("--json emits one structured object for command usage errors", async () => {
|
|
1168
|
+
const homeDir = await setupTempHome();
|
|
1169
|
+
const result = runCli({
|
|
1170
|
+
args: ["--json", "collections"],
|
|
1171
|
+
homeDir,
|
|
1172
|
+
capturePath: path.join(homeDir, "capture-json-usage.json"),
|
|
1173
|
+
});
|
|
1174
|
+
|
|
1175
|
+
assertJsonError(result, "USAGE_ERROR");
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
test("--json emits one structured object for HTTP errors", async () => {
|
|
1179
|
+
const homeDir = await setupTempHome();
|
|
1180
|
+
const result = runCli({
|
|
1181
|
+
args: ["--json", "brands"],
|
|
1182
|
+
homeDir,
|
|
1183
|
+
capturePath: path.join(homeDir, "capture-json-http.json"),
|
|
1184
|
+
extraEnv: {
|
|
1185
|
+
NUELINK_MOCK_FAIL_COUNT: "1",
|
|
1186
|
+
NUELINK_MOCK_FAIL_STATUS: "422",
|
|
1187
|
+
NUELINK_MOCK_FAIL_PATH: "/brands",
|
|
1188
|
+
NUELINK_GET_RETRIES: "0",
|
|
1189
|
+
},
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
const error = assertJsonError(result, "HTTP_ERROR");
|
|
1193
|
+
assert.equal(error.httpStatus, 422);
|
|
1194
|
+
});
|
|
1195
|
+
|
|
1196
|
+
test("--json reports malformed config without silently ignoring it", async () => {
|
|
1197
|
+
const homeDir = await setupTempHome();
|
|
1198
|
+
const configDir = path.join(homeDir, ".nuelink-cli");
|
|
1199
|
+
await mkdir(configDir, { recursive: true });
|
|
1200
|
+
await writeFile(path.join(configDir, "config.json"), "{not-json}", "utf8");
|
|
1201
|
+
|
|
1202
|
+
const result = runCli({
|
|
1203
|
+
args: ["--json", "auth:status"],
|
|
1204
|
+
homeDir,
|
|
1205
|
+
capturePath: path.join(homeDir, "capture-json-config.json"),
|
|
1206
|
+
withMock: false,
|
|
1207
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1208
|
+
});
|
|
1209
|
+
|
|
1210
|
+
assertJsonError(result, "CONFIG_INVALID");
|
|
1211
|
+
});
|
|
1212
|
+
|
|
1213
|
+
test("--json reports corrupted saved credentials", async () => {
|
|
1214
|
+
const homeDir = await setupTempHome();
|
|
1215
|
+
const configDir = path.join(homeDir, ".nuelink-cli");
|
|
1216
|
+
await mkdir(configDir, { recursive: true });
|
|
1217
|
+
await writeFile(path.join(configDir, "config.json"), JSON.stringify({
|
|
1218
|
+
version: 1,
|
|
1219
|
+
encryptedApiKey: "invalid",
|
|
1220
|
+
iv: "invalid",
|
|
1221
|
+
authTag: "invalid",
|
|
1222
|
+
}), "utf8");
|
|
1223
|
+
|
|
1224
|
+
const result = runCli({
|
|
1225
|
+
args: ["--json", "auth:status"],
|
|
1226
|
+
homeDir,
|
|
1227
|
+
capturePath: path.join(homeDir, "capture-json-corrupt-config.json"),
|
|
1228
|
+
withMock: false,
|
|
1229
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1230
|
+
});
|
|
1231
|
+
|
|
1232
|
+
assertJsonError(result, "CONFIG_INVALID");
|
|
1233
|
+
});
|
|
1234
|
+
|
|
1235
|
+
test("auth:login refuses an unsafe config directory path", async () => {
|
|
1236
|
+
const homeDir = await setupTempHome();
|
|
1237
|
+
await writeFile(path.join(homeDir, ".nuelink-cli"), "not-a-directory", "utf8");
|
|
1238
|
+
|
|
1239
|
+
const result = runCli({
|
|
1240
|
+
args: ["--json", "auth:login", "--stdin"],
|
|
1241
|
+
homeDir,
|
|
1242
|
+
capturePath: path.join(homeDir, "capture-unsafe-config.json"),
|
|
1243
|
+
withMock: false,
|
|
1244
|
+
input: "saved_token\n",
|
|
1245
|
+
extraEnv: { NUELINK_API_KEY: "" },
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
assertJsonError(result, "CONFIG_UNSAFE");
|
|
1249
|
+
});
|
|
1250
|
+
|
|
1251
|
+
test("--json emits one structured object for timeouts", async () => {
|
|
1252
|
+
const homeDir = await setupTempHome();
|
|
1253
|
+
const result = runCli({
|
|
1254
|
+
args: ["--json", "brands"],
|
|
1255
|
+
homeDir,
|
|
1256
|
+
capturePath: path.join(homeDir, "capture-json-timeout.json"),
|
|
1257
|
+
extraEnv: { NUELINK_MOCK_THROW_TIMEOUT: "1" },
|
|
1258
|
+
});
|
|
1259
|
+
|
|
1260
|
+
assertJsonError(result, "TIMEOUT");
|
|
1261
|
+
});
|
|
1262
|
+
|
|
1263
|
+
test("invalid timeout and retry environment values fail before a request", async () => {
|
|
1264
|
+
const homeDir = await setupTempHome();
|
|
1265
|
+
const result = runCli({
|
|
1266
|
+
args: ["--json", "brands"],
|
|
1267
|
+
homeDir,
|
|
1268
|
+
capturePath: path.join(homeDir, "capture-invalid-timeout.json"),
|
|
1269
|
+
extraEnv: { NUELINK_TIMEOUT_MS: "not-a-number" },
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1272
|
+
assertJsonError(result, "CONFIG_INVALID");
|
|
1273
|
+
});
|
|
1173
1274
|
|
|
1174
1275
|
test("empty success bodies return an empty object", async () => {
|
|
1175
1276
|
const homeDir = await setupTempHome();
|