@tenonhq/dovetail-core 0.0.131 → 0.0.133

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.
@@ -0,0 +1,459 @@
1
+ "use strict";
2
+ /**
3
+ * `dove refresh` writes one folder per record, and says so when it cannot.
4
+ *
5
+ * Regression targets, each taken from a clean resync of a real instance:
6
+ *
7
+ * - LETTER-CASE TWINS. The instance lists "Search default" and "Search
8
+ * Default" as two records. Both were written to one folder on macOS and
9
+ * Windows, and the record written last won.
10
+ * - NAME TWINS. Two access controls with one name and the same first 8 id
11
+ * characters. Once the instance lists both, both need a folder.
12
+ * - THE DOWNLOAD NAMES A RECORD DIFFERENTLY. bulkDownload names records from
13
+ * the records in that one request, so a namesake pulled alone came back
14
+ * under the bare name and was written to a second folder. The manifest is
15
+ * the one naming authority: the download's own names never pick a folder.
16
+ * - A PATH GIT IGNORES. A client script named `console.log` lands in a folder
17
+ * a `*.log` ignore rule hides, so it never reached the repository.
18
+ * - A FOLDER THAT CANNOT BE CREATED took the whole application down with it.
19
+ *
20
+ * These run against the real file system (and a real `git init` for the ignore
21
+ * case) so they hold on case-insensitive and case-sensitive disks alike.
22
+ */
23
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ var desc = Object.getOwnPropertyDescriptor(m, k);
26
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
27
+ desc = { enumerable: true, get: function() { return m[k]; } };
28
+ }
29
+ Object.defineProperty(o, k2, desc);
30
+ }) : (function(o, m, k, k2) {
31
+ if (k2 === undefined) k2 = k;
32
+ o[k2] = m[k];
33
+ }));
34
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }) : function(o, v) {
37
+ o["default"] = v;
38
+ });
39
+ var __importStar = (this && this.__importStar) || (function () {
40
+ var ownKeys = function(o) {
41
+ ownKeys = Object.getOwnPropertyNames || function (o) {
42
+ var ar = [];
43
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
44
+ return ar;
45
+ };
46
+ return ownKeys(o);
47
+ };
48
+ return function (mod) {
49
+ if (mod && mod.__esModule) return mod;
50
+ var result = {};
51
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
52
+ __setModuleDefault(result, mod);
53
+ return result;
54
+ };
55
+ })();
56
+ Object.defineProperty(exports, "__esModule", { value: true });
57
+ const cp = __importStar(require("child_process"));
58
+ const fs = __importStar(require("fs"));
59
+ const os = __importStar(require("os"));
60
+ const path = __importStar(require("path"));
61
+ // ---------- mocks (must come before importing the module under test) ----------
62
+ var mockLogger = {
63
+ info: jest.fn(),
64
+ debug: jest.fn(),
65
+ warn: jest.fn(),
66
+ error: jest.fn(),
67
+ success: jest.fn(),
68
+ setLogLevel: jest.fn(),
69
+ getLogLevel: function () { return "warn"; },
70
+ };
71
+ var mockClient = {
72
+ getManifest: jest.fn(),
73
+ getMissingFiles: jest.fn(),
74
+ };
75
+ jest.mock("../Logger", function () { return { logger: mockLogger }; });
76
+ jest.mock("../FileLogger", function () {
77
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
78
+ });
79
+ jest.mock("../snClient", function () {
80
+ return {
81
+ defaultClient: function () { return mockClient; },
82
+ unwrapSNResponse: function (p) { return Promise.resolve(p); },
83
+ processPushResponse: jest.fn(),
84
+ retryOnErr: jest.fn(),
85
+ retryOnHttpErr: jest.fn(),
86
+ unwrapTableAPIFirstItem: jest.fn(),
87
+ };
88
+ });
89
+ var mockConfig = {
90
+ getConfig: jest.fn().mockReturnValue({ scopes: { x_cadso_work: {} }, tableOptions: {} }),
91
+ getManifest: jest.fn().mockResolvedValue({ x_cadso_work: { scope: "x_cadso_work", tables: {} } }),
92
+ getSourcePathForScope: jest.fn(),
93
+ getSourcePath: jest.fn(),
94
+ getManifestPath: jest.fn().mockReturnValue("/tmp/dove.manifest.json"),
95
+ resolveConfigForScope: jest.fn().mockImplementation(function () {
96
+ return {
97
+ tables: ["sys_ux_screen", "sys_security_acl", "sys_hub_action_input", "sys_ux_client_script"],
98
+ fieldOverrides: {},
99
+ apiIncludes: {},
100
+ apiExcludes: {},
101
+ };
102
+ }),
103
+ isMultiScopeManifest: jest.fn().mockReturnValue(true),
104
+ updateManifest: jest.fn(),
105
+ };
106
+ jest.mock("../config", function () { return mockConfig; });
107
+ jest.mock("progress", function () {
108
+ return jest.fn().mockImplementation(function () { return { tick: jest.fn() }; });
109
+ });
110
+ // Real FileUtils, so the assertions read the actual disk. Only the scope
111
+ // manifest write is captured instead of written.
112
+ var mockWriteScopeManifest = jest.fn().mockResolvedValue(undefined);
113
+ jest.mock("../FileUtils", function () {
114
+ var actual = jest.requireActual("../FileUtils");
115
+ return Object.assign({}, actual, { writeScopeManifest: mockWriteScopeManifest });
116
+ });
117
+ const AppUtils = __importStar(require("../appUtils"));
118
+ const commands_1 = require("../commands");
119
+ var tmpRoot;
120
+ function serverManifest(rows) {
121
+ var tables = {};
122
+ rows.forEach(function (r) {
123
+ if (!tables[r.table])
124
+ tables[r.table] = { records: {} };
125
+ tables[r.table].records[r.name] = {
126
+ name: r.name,
127
+ sys_id: r.sys_id,
128
+ files: [{ name: "script", type: "js" }],
129
+ };
130
+ });
131
+ return { scope: "x_cadso_work", tables: tables };
132
+ }
133
+ function serverDownload(rows) {
134
+ var tables = {};
135
+ rows.forEach(function (r) {
136
+ var name = r.downloadName === undefined ? r.name : r.downloadName;
137
+ if (!tables[r.table])
138
+ tables[r.table] = { records: {} };
139
+ tables[r.table].records[name] = {
140
+ name: name,
141
+ sys_id: r.sys_id,
142
+ files: [{ name: "script", type: "js", content: r.script }],
143
+ };
144
+ });
145
+ return tables;
146
+ }
147
+ function serve(rows) {
148
+ mockClient.getManifest.mockResolvedValue(serverManifest(rows));
149
+ mockClient.getMissingFiles.mockResolvedValue(serverDownload(rows));
150
+ }
151
+ /** Folder names on disk, exactly as the disk spells them. */
152
+ function foldersOf(table) {
153
+ try {
154
+ return fs.readdirSync(path.join(tmpRoot, table)).sort();
155
+ }
156
+ catch (e) {
157
+ return [];
158
+ }
159
+ }
160
+ function scriptIn(table, folder) {
161
+ return fs.readFileSync(path.join(tmpRoot, table, folder, "script.js"), "utf8");
162
+ }
163
+ function writtenManifest() {
164
+ expect(mockWriteScopeManifest).toHaveBeenCalled();
165
+ return mockWriteScopeManifest.mock.calls[0][1];
166
+ }
167
+ function manifestKeys(table) {
168
+ return Object.keys(writtenManifest().tables[table].records).sort();
169
+ }
170
+ function git(args) {
171
+ cp.execFileSync("git", args, { cwd: tmpRoot, stdio: "ignore" });
172
+ }
173
+ beforeEach(function () {
174
+ jest.clearAllMocks();
175
+ // realpath: os.tmpdir() is a symlink on macOS, and git reports real paths.
176
+ tmpRoot = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "dove-collisions-")));
177
+ mockConfig.getSourcePathForScope.mockReturnValue(tmpRoot);
178
+ mockConfig.getSourcePath.mockReturnValue(tmpRoot);
179
+ });
180
+ afterEach(function () {
181
+ try {
182
+ fs.rmSync(tmpRoot, { recursive: true, force: true });
183
+ }
184
+ catch (e) { }
185
+ });
186
+ // ---------- letter-case twins ----------
187
+ describe("refresh: names that differ only in letter case", function () {
188
+ var rows = [
189
+ { table: "sys_ux_screen", name: "Search default", sys_id: "7daaf59947d56910fc4c1ae8036d43c0", script: "// lower" },
190
+ { table: "sys_ux_screen", name: "Search Default", sys_id: "fb55e60db195a5101b815df7b6dd8425", script: "// upper" },
191
+ { table: "sys_ux_screen", name: "Home", sys_id: "0a1b2c3d47d56910fc4c1ae8036d43c0", script: "// home" },
192
+ ];
193
+ test("each record gets its own folder, on any disk", async function () {
194
+ serve(rows);
195
+ var result = await AppUtils.syncManifest("x_cadso_work");
196
+ expect(result.failedScopes).toEqual([]);
197
+ expect(foldersOf("sys_ux_screen")).toEqual([
198
+ "Home",
199
+ "Search Default (fb55e60d)",
200
+ "Search default (7daaf599)",
201
+ ]);
202
+ // Neither record's content was overwritten by its twin.
203
+ expect(scriptIn("sys_ux_screen", "Search default (7daaf599)")).toBe("// lower");
204
+ expect(scriptIn("sys_ux_screen", "Search Default (fb55e60d)")).toBe("// upper");
205
+ });
206
+ test("the manifest lists every record under the folder it was written to", async function () {
207
+ serve(rows);
208
+ await AppUtils.syncManifest("x_cadso_work");
209
+ expect(manifestKeys("sys_ux_screen")).toEqual(foldersOf("sys_ux_screen"));
210
+ var records = writtenManifest().tables.sys_ux_screen.records;
211
+ expect(records["Search default (7daaf599)"].sys_id).toBe("7daaf59947d56910fc4c1ae8036d43c0");
212
+ expect(records["Search Default (fb55e60d)"].sys_id).toBe("fb55e60db195a5101b815df7b6dd8425");
213
+ });
214
+ test("a record whose name is unique ignoring case is not renamed", async function () {
215
+ serve(rows);
216
+ await AppUtils.syncManifest("x_cadso_work");
217
+ expect(foldersOf("sys_ux_screen")).toContain("Home");
218
+ });
219
+ });
220
+ // ---------- name twins ----------
221
+ describe("refresh: same name and same first 8 id characters", function () {
222
+ var A = "15f0e0ea33dfc7107b18bc534d5c7bc4";
223
+ var B = "15f0e0ea33dfc7107b18bc534d5c7bf5";
224
+ test("both twins are written and listed once the instance sends both", async function () {
225
+ // An instance that no longer collapses the pair sends two entries.
226
+ serve([
227
+ { table: "sys_security_acl", name: "x_cadso_journey_fire_log (" + A + ")", sys_id: A, script: "// read" },
228
+ { table: "sys_security_acl", name: "x_cadso_journey_fire_log (" + B + ")", sys_id: B, script: "// write" },
229
+ ]);
230
+ await AppUtils.syncManifest("x_cadso_work");
231
+ var folders = foldersOf("sys_security_acl");
232
+ expect(folders).toEqual([
233
+ "x_cadso_journey_fire_log (" + A + ")",
234
+ "x_cadso_journey_fire_log (" + B + ")",
235
+ ]);
236
+ expect(manifestKeys("sys_security_acl")).toEqual(folders);
237
+ expect(scriptIn("sys_security_acl", folders[0])).toBe("// read");
238
+ expect(scriptIn("sys_security_acl", folders[1])).toBe("// write");
239
+ });
240
+ test("a download that names both twins alike still writes two folders", async function () {
241
+ // The manifest tells them apart; the download repeats one 8-character name.
242
+ mockClient.getManifest.mockResolvedValue(serverManifest([
243
+ { table: "sys_security_acl", name: "x_cadso_journey_fire_log (" + A + ")", sys_id: A, script: "" },
244
+ { table: "sys_security_acl", name: "x_cadso_journey_fire_log (" + B + ")", sys_id: B, script: "" },
245
+ ]));
246
+ mockClient.getMissingFiles.mockResolvedValue({
247
+ sys_security_acl: {
248
+ records: {
249
+ first: { name: "x_cadso_journey_fire_log (15f0e0ea)", sys_id: A, files: [{ name: "script", type: "js", content: "// read" }] },
250
+ second: { name: "x_cadso_journey_fire_log (15f0e0ea)", sys_id: B, files: [{ name: "script", type: "js", content: "// write" }] },
251
+ },
252
+ },
253
+ });
254
+ await AppUtils.syncManifest("x_cadso_work");
255
+ expect(foldersOf("sys_security_acl")).toEqual([
256
+ "x_cadso_journey_fire_log (" + A + ")",
257
+ "x_cadso_journey_fire_log (" + B + ")",
258
+ ]);
259
+ expect(scriptIn("sys_security_acl", "x_cadso_journey_fire_log (" + A + ")")).toBe("// read");
260
+ expect(scriptIn("sys_security_acl", "x_cadso_journey_fire_log (" + B + ")")).toBe("// write");
261
+ });
262
+ });
263
+ // ---------- the manifest names the folder, not the download ----------
264
+ describe("refresh: the download's own names never pick the folder", function () {
265
+ test("a namesake the download returns under the bare name lands in its manifest folder", async function () {
266
+ serve([
267
+ {
268
+ table: "sys_hub_action_input",
269
+ name: "Audience (0616384a)",
270
+ sys_id: "0616384ac3f492d085b196c4e40131aa",
271
+ script: "// a",
272
+ downloadName: "Audience",
273
+ },
274
+ {
275
+ table: "sys_hub_action_input",
276
+ name: "Audience (92953c0a)",
277
+ sys_id: "92953c0ac3f492d085b196c4e40131bb",
278
+ script: "// b",
279
+ downloadName: "Audience (92953c0a)",
280
+ },
281
+ ]);
282
+ await AppUtils.syncManifest("x_cadso_work");
283
+ // No second, bare "Audience" folder for a record the manifest files elsewhere.
284
+ expect(foldersOf("sys_hub_action_input")).toEqual(["Audience (0616384a)", "Audience (92953c0a)"]);
285
+ expect(scriptIn("sys_hub_action_input", "Audience (0616384a)")).toBe("// a");
286
+ });
287
+ });
288
+ // ---------- names the project configured ----------
289
+ describe("refresh: an id the configuration put in the name is kept", function () {
290
+ var HOME = "0a1b2c3d47d56910fc4c1ae8036d43c0";
291
+ afterEach(function () {
292
+ mockConfig.getConfig.mockReturnValue({ scopes: { x_cadso_work: {} }, tableOptions: {} });
293
+ });
294
+ test("differentiatorField: \"sys_id\" keeps `Name (sys_id)` as the folder", async function () {
295
+ mockConfig.getConfig.mockReturnValue({
296
+ scopes: { x_cadso_work: {} },
297
+ tableOptions: { sys_ux_screen: { differentiatorField: "sys_id" } },
298
+ });
299
+ serve([{ table: "sys_ux_screen", name: "Home (" + HOME + ")", sys_id: HOME, script: "// home" }]);
300
+ await AppUtils.syncManifest("x_cadso_work");
301
+ expect(foldersOf("sys_ux_screen")).toEqual(["Home (" + HOME + ")"]);
302
+ expect(manifestKeys("sys_ux_screen")).toEqual(["Home (" + HOME + ")"]);
303
+ });
304
+ test("a nameTemplate table is named exactly as the template says", async function () {
305
+ mockConfig.getConfig.mockReturnValue({
306
+ scopes: { x_cadso_work: {} },
307
+ tableOptions: { sys_ux_screen: { nameTemplate: "{name} ({sys_id})" } },
308
+ });
309
+ serve([{ table: "sys_ux_screen", name: "Home (" + HOME + ")", sys_id: HOME, script: "// home" }]);
310
+ await AppUtils.syncManifest("x_cadso_work");
311
+ expect(foldersOf("sys_ux_screen")).toEqual(["Home (" + HOME + ")"]);
312
+ });
313
+ test("a table with no such option still has the instance's suffix recomputed", async function () {
314
+ serve([{ table: "sys_ux_screen", name: "Home (" + HOME.substring(0, 8) + ")", sys_id: HOME, script: "// home" }]);
315
+ await AppUtils.syncManifest("x_cadso_work");
316
+ // The only record of that name: no namesake, so no suffix.
317
+ expect(foldersOf("sys_ux_screen")).toEqual(["Home"]);
318
+ });
319
+ });
320
+ // ---------- paths git ignores ----------
321
+ describe("refresh: a folder the repository ignores is reported, not lost", function () {
322
+ var rows = [
323
+ { table: "sys_ux_client_script", name: "console.log", sys_id: "c0ffee0047d56910fc4c1ae8036d43c0", script: "// hidden" },
324
+ { table: "sys_ux_client_script", name: "onLoad", sys_id: "0d15ea5e47d56910fc4c1ae8036d43c0", script: "// seen" },
325
+ ];
326
+ beforeEach(function () {
327
+ git(["init", "-q"]);
328
+ fs.writeFileSync(path.join(tmpRoot, ".gitignore"), "# build output\n*.log\n");
329
+ });
330
+ test("the ignored record is named, with the rule that hides it", async function () {
331
+ serve(rows);
332
+ var result = await AppUtils.syncManifest("x_cadso_work");
333
+ expect(result.notWritten).toHaveLength(1);
334
+ var lost = result.notWritten[0];
335
+ expect(lost.scope).toBe("x_cadso_work");
336
+ expect(lost.table).toBe("sys_ux_client_script");
337
+ expect(lost.sysId).toBe("c0ffee0047d56910fc4c1ae8036d43c0");
338
+ expect(lost.folder).toBe("console.log");
339
+ expect(lost.path).toBe(path.join(tmpRoot, "sys_ux_client_script", "console.log"));
340
+ expect(lost.reason).toContain("ignored by git");
341
+ expect(lost.reason).toContain("*.log");
342
+ expect(lost.reason).toContain(".gitignore:2");
343
+ });
344
+ test("the files are still on disk, so fixing the ignore rule is enough", async function () {
345
+ serve(rows);
346
+ await AppUtils.syncManifest("x_cadso_work");
347
+ expect(scriptIn("sys_ux_client_script", "console.log")).toBe("// hidden");
348
+ });
349
+ test("a record git can see is not reported", async function () {
350
+ serve([rows[1]]);
351
+ var result = await AppUtils.syncManifest("x_cadso_work");
352
+ expect(result.notWritten).toEqual([]);
353
+ });
354
+ test("an ignored file inside a visible folder is reported too", async function () {
355
+ fs.writeFileSync(path.join(tmpRoot, ".gitignore"), "script.js\n");
356
+ serve([rows[1]]);
357
+ var result = await AppUtils.syncManifest("x_cadso_work");
358
+ expect(result.notWritten).toHaveLength(1);
359
+ expect(result.notWritten[0].folder).toBe("onLoad");
360
+ expect(result.notWritten[0].reason).toContain("script.js");
361
+ });
362
+ test("a file git already tracks is not reported, whatever the ignore rules say", async function () {
363
+ serve(rows);
364
+ await AppUtils.syncManifest("x_cadso_work");
365
+ git(["add", "-f", "--", "sys_ux_client_script/console.log"]);
366
+ var result = await AppUtils.syncManifest("x_cadso_work");
367
+ expect(result.notWritten).toEqual([]);
368
+ });
369
+ test("outside a git repository nothing is reported", async function () {
370
+ fs.rmSync(path.join(tmpRoot, ".git"), { recursive: true, force: true });
371
+ serve(rows);
372
+ var result = await AppUtils.syncManifest("x_cadso_work");
373
+ expect(result.notWritten).toEqual([]);
374
+ });
375
+ });
376
+ // ---------- folders that cannot be created ----------
377
+ describe("refresh: a folder that cannot be created is reported, and the rest is written", function () {
378
+ var rows = [
379
+ { table: "sys_ux_client_script", name: "blocked", sys_id: "b10cced047d56910fc4c1ae8036d43c0", script: "// blocked" },
380
+ { table: "sys_ux_client_script", name: "onLoad", sys_id: "0d15ea5e47d56910fc4c1ae8036d43c0", script: "// seen" },
381
+ ];
382
+ beforeEach(function () {
383
+ // A regular file sits where the record's folder has to go.
384
+ fs.mkdirSync(path.join(tmpRoot, "sys_ux_client_script"), { recursive: true });
385
+ fs.writeFileSync(path.join(tmpRoot, "sys_ux_client_script", "blocked"), "not a folder");
386
+ });
387
+ test("the record is named with the reason", async function () {
388
+ serve(rows);
389
+ var result = await AppUtils.syncManifest("x_cadso_work");
390
+ expect(result.failedScopes).toEqual([]);
391
+ expect(result.notWritten).toHaveLength(1);
392
+ expect(result.notWritten[0].sysId).toBe("b10cced047d56910fc4c1ae8036d43c0");
393
+ expect(result.notWritten[0].folder).toBe("blocked");
394
+ expect(result.notWritten[0].reason).toContain("could not be written");
395
+ });
396
+ test("every other record of the application is still written", async function () {
397
+ serve(rows);
398
+ await AppUtils.syncManifest("x_cadso_work");
399
+ expect(scriptIn("sys_ux_client_script", "onLoad")).toBe("// seen");
400
+ });
401
+ });
402
+ // ---------- the command ----------
403
+ describe("refreshCommand: records that were not written fail the command", function () {
404
+ var originalExitCode;
405
+ beforeEach(function () {
406
+ originalExitCode = process.exitCode;
407
+ process.exitCode = undefined;
408
+ });
409
+ afterEach(function () {
410
+ process.exitCode = originalExitCode;
411
+ jest.restoreAllMocks();
412
+ });
413
+ function errorLines() {
414
+ return mockLogger.error.mock.calls.map(function (c) { return String(c[0]); });
415
+ }
416
+ test("prints every record by name, exits non-zero, and does not claim success", async function () {
417
+ jest.spyOn(AppUtils, "syncManifest").mockResolvedValue({
418
+ failedScopes: [],
419
+ notWritten: [
420
+ {
421
+ scope: "x_cadso_work",
422
+ table: "sys_ux_client_script",
423
+ sysId: "c0ffee0047d56910fc4c1ae8036d43c0",
424
+ folder: "console.log",
425
+ path: "/repo/src/Work/sys_ux_client_script/console.log",
426
+ reason: "ignored by git (.gitignore:2 *.log)",
427
+ },
428
+ ],
429
+ });
430
+ await (0, commands_1.refreshCommand)({});
431
+ expect(process.exitCode).toBe(1);
432
+ expect(mockLogger.success).not.toHaveBeenCalled();
433
+ var lines = errorLines();
434
+ expect(lines.some(function (l) { return l.indexOf("1 record") !== -1 && l.indexOf("not written") !== -1; })).toBe(true);
435
+ expect(lines.some(function (l) {
436
+ return l.indexOf("/repo/src/Work/sys_ux_client_script/console.log") !== -1 &&
437
+ l.indexOf("c0ffee0047d56910fc4c1ae8036d43c0") !== -1 &&
438
+ l.indexOf("ignored by git (.gitignore:2 *.log)") !== -1;
439
+ })).toBe(true);
440
+ });
441
+ test("end to end: a refresh that hits an ignored folder exits non-zero", async function () {
442
+ git(["init", "-q"]);
443
+ fs.writeFileSync(path.join(tmpRoot, ".gitignore"), "*.log\n");
444
+ serve([
445
+ { table: "sys_ux_client_script", name: "console.log", sys_id: "c0ffee0047d56910fc4c1ae8036d43c0", script: "// hidden" },
446
+ ]);
447
+ await (0, commands_1.refreshCommand)({ scope: "x_cadso_work" });
448
+ expect(process.exitCode).toBe(1);
449
+ expect(errorLines().join("\n")).toContain("console.log");
450
+ });
451
+ test("a clean refresh still succeeds", async function () {
452
+ serve([
453
+ { table: "sys_ux_client_script", name: "onLoad", sys_id: "0d15ea5e47d56910fc4c1ae8036d43c0", script: "// seen" },
454
+ ]);
455
+ await (0, commands_1.refreshCommand)({ scope: "x_cadso_work" });
456
+ expect(process.exitCode).toBeUndefined();
457
+ expect(mockLogger.success).toHaveBeenCalledWith("Refresh complete!");
458
+ });
459
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // resolveScopeFromPath (config.ts) maps a file to the scope whose folder holds
3
+ // it; push relies on it (FileUtils.getFileContextWithSkipReason). With scopes in
4
+ // nested folders (src/UIComponents/<scope>) a plain string prefix is wrong: a
5
+ // folder claims a sibling whose name starts the same. Matching is now on a
6
+ // separator boundary, and the deepest folder wins regardless of declaration order.
7
+ var __importDefault = (this && this.__importDefault) || function (mod) {
8
+ return (mod && mod.__esModule) ? mod : { "default": mod };
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ jest.mock("../Logger", function () {
12
+ return {
13
+ logger: {
14
+ info: jest.fn(),
15
+ debug: jest.fn(),
16
+ warn: jest.fn(),
17
+ error: jest.fn(),
18
+ success: jest.fn(),
19
+ getLogLevel: function () { return "debug"; },
20
+ setLogLevel: jest.fn(),
21
+ },
22
+ };
23
+ });
24
+ jest.mock("../FileLogger", function () {
25
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
26
+ });
27
+ const fs_1 = __importDefault(require("fs"));
28
+ const os_1 = __importDefault(require("os"));
29
+ const path_1 = __importDefault(require("path"));
30
+ const config_1 = require("../config");
31
+ const CONFIG = [
32
+ "module.exports = {",
33
+ " sourceDirectory: 'src',",
34
+ " buildDirectory: 'build',",
35
+ " includes: { _tables: ['sys_script_include'] },",
36
+ " excludes: { _tables: [] },",
37
+ " tableOptions: {},",
38
+ " scopes: {",
39
+ // Declared parent-first on purpose: the old first-match loop returned it for
40
+ // every file below it.
41
+ " x_parent: { sourceDirectory: 'src/UIComponents' },",
42
+ " x_cadso_ui_form: { sourceDirectory: 'src/UIComponents/x_cadso_ui_form' },",
43
+ " x_cadso_ui_form_x: { sourceDirectory: 'src/UIComponents/x_cadso_ui_form_x' },",
44
+ " x_cadso_core: { sourceDirectory: 'src/Core' },",
45
+ " },",
46
+ "};",
47
+ "",
48
+ ].join("\n");
49
+ describe("resolveScopeFromPath", function () {
50
+ var tmp = "";
51
+ var cwd = process.cwd();
52
+ beforeAll(async function () {
53
+ tmp = fs_1.default.realpathSync(fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-scope-path-")));
54
+ fs_1.default.writeFileSync(path_1.default.join(tmp, "dove.config.js"), CONFIG);
55
+ process.chdir(tmp);
56
+ await (0, config_1.loadConfigs)();
57
+ });
58
+ afterAll(function () {
59
+ process.chdir(cwd);
60
+ fs_1.default.rmSync(tmp, { recursive: true, force: true });
61
+ });
62
+ function file(rel) {
63
+ return path_1.default.join(tmp, rel);
64
+ }
65
+ it("resolves each scope's folder from the config", function () {
66
+ expect((0, config_1.getSourcePathForScope)("x_cadso_ui_form")).toBe(file("src/UIComponents/x_cadso_ui_form"));
67
+ });
68
+ it("does not let a folder claim a sibling that shares its prefix", function () {
69
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form_x/sys_ux_lib_component/a/metaData.json"))).toBe("x_cadso_ui_form_x");
70
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form/sys_ux_lib_component/a/metaData.json"))).toBe("x_cadso_ui_form");
71
+ });
72
+ it("picks the deepest folder when scope folders nest", function () {
73
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/x_cadso_ui_form/t/r/script.js"))).toBe("x_cadso_ui_form");
74
+ expect((0, config_1.resolveScopeFromPath)(file("src/UIComponents/other/t/r/script.js"))).toBe("x_parent");
75
+ });
76
+ it("still resolves a flat scope folder", function () {
77
+ expect((0, config_1.resolveScopeFromPath)(file("src/Core/sys_script_include/APIUtils/script.js"))).toBe("x_cadso_core");
78
+ });
79
+ it("returns undefined outside every scope folder or for bad input", function () {
80
+ expect((0, config_1.resolveScopeFromPath)(file("src/CoreX/sys_script_include/a/script.js"))).toBeUndefined();
81
+ expect((0, config_1.resolveScopeFromPath)("")).toBeUndefined();
82
+ });
83
+ });
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ // getManifest and getMissingFiles (bulkDownload) are the two reads every
3
+ // refresh/download/pull path uses, so fingerprinting is applied there once.
4
+ // Checks that `fingerprint` never reaches the instance and that the response
5
+ // comes back rewritten.
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ jest.mock("../Logger", function () {
8
+ return {
9
+ logger: {
10
+ info: jest.fn(),
11
+ debug: jest.fn(),
12
+ warn: jest.fn(),
13
+ error: jest.fn(),
14
+ getLogLevel: function () { return "debug"; },
15
+ },
16
+ };
17
+ });
18
+ jest.mock("../FileLogger", function () {
19
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
20
+ });
21
+ const snClient_1 = require("../snClient");
22
+ const fingerprint_1 = require("../fingerprint");
23
+ const BUNDLE = "!function(){}();";
24
+ function okResponse(result) {
25
+ return { status: 200, data: { result: result }, headers: {}, statusText: "OK", config: {} };
26
+ }
27
+ function makeClient(post) {
28
+ var c = (0, snClient_1.snClient)("https://x.service-now.com/", "u", "p");
29
+ c.client.post = post;
30
+ return c;
31
+ }
32
+ const TABLE_OPTIONS = {
33
+ sys_ux_lib_source_script: { fingerprint: ["script"], query: "active=true" },
34
+ };
35
+ describe("snClient fingerprint hook", function () {
36
+ it("getManifest strips fingerprint from the request and renames the field in the manifest", async function () {
37
+ var post = jest.fn().mockResolvedValue(okResponse({
38
+ scope: "x_cadso_ui_form",
39
+ tables: {
40
+ sys_ux_lib_source_script: {
41
+ records: { a: { name: "a", sys_id: "1", files: [{ name: "script", type: "js" }] } },
42
+ },
43
+ },
44
+ }));
45
+ var c = makeClient(post);
46
+ var config = { includes: {}, excludes: {}, tableOptions: TABLE_OPTIONS };
47
+ var resp = await c.getManifest("x_cadso_ui_form", config);
48
+ var body = post.mock.calls[0][1];
49
+ expect(body.tableOptions).toEqual({ sys_ux_lib_source_script: { query: "active=true" } });
50
+ expect(JSON.stringify(body)).not.toContain("fingerprint");
51
+ expect(resp.data.result.tables.sys_ux_lib_source_script.records.a.files[0]).toEqual({
52
+ name: "script",
53
+ type: "sha256",
54
+ });
55
+ // The caller's config is not mutated.
56
+ expect(TABLE_OPTIONS.sys_ux_lib_source_script.fingerprint).toEqual(["script"]);
57
+ });
58
+ it("getMissingFiles strips fingerprint from the request and hashes the downloaded content", async function () {
59
+ var post = jest.fn().mockResolvedValue(okResponse({
60
+ sys_ux_lib_source_script: {
61
+ records: {
62
+ a: { name: "a", sys_id: "1", files: [{ name: "script", type: "sha256", content: BUNDLE }] },
63
+ },
64
+ },
65
+ }));
66
+ var c = makeClient(post);
67
+ var resp = await c.getMissingFiles({ sys_ux_lib_source_script: { "1": [{ name: "script", type: "sha256" }] } }, TABLE_OPTIONS);
68
+ var body = post.mock.calls[0][1];
69
+ expect(JSON.stringify(body.tableOptions)).not.toContain("fingerprint");
70
+ expect(resp.data.result.sys_ux_lib_source_script.records.a.files[0].content).toBe((0, fingerprint_1.formatFingerprint)(BUNDLE));
71
+ });
72
+ it("passes responses through untouched when nothing is fingerprinted", async function () {
73
+ var result = {
74
+ sys_script_include: {
75
+ records: { a: { name: "a", sys_id: "1", files: [{ name: "script", type: "js", content: "x" }] } },
76
+ },
77
+ };
78
+ var post = jest.fn().mockResolvedValue(okResponse(result));
79
+ var c = makeClient(post);
80
+ var resp = await c.getMissingFiles({ sys_script_include: { "1": [{ name: "script", type: "js" }] } }, {});
81
+ expect(resp.data.result).toEqual(result);
82
+ });
83
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/dovetail-core",
3
- "version": "0.0.131",
3
+ "version": "0.0.133",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "node": ">=22"
23
23
  },
24
24
  "devDependencies": {
25
- "@tenonhq/dovetail-types": "~0.0.22",
25
+ "@tenonhq/dovetail-types": "~0.0.24",
26
26
  "@types/dotenv": "^6.1.1",
27
27
  "@types/inquirer": "^8.2.10",
28
28
  "@types/jest": "^29.5.5",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@tenonhq/dovetail-clickup": "~0.0.15",
42
- "@tenonhq/dovetail-schema": "~0.0.16",
42
+ "@tenonhq/dovetail-schema": "~0.0.17",
43
43
  "axios": "^1.20.0",
44
44
  "axios-cookiejar-support": "^4.0.7",
45
45
  "axios-rate-limit": "^1.3.0",