@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,314 @@
1
+ "use strict";
2
+ /**
3
+ * Record folder naming: one folder per record, on every disk.
4
+ *
5
+ * Three ways a mirror lost records, each reproduced here from the shape of the
6
+ * records that were lost on a real instance:
7
+ *
8
+ * 1. NAME TWINS. Two records of one table share their display name AND the
9
+ * first 8 characters of their sys_id (access controls created in one
10
+ * transaction differ only in the last few characters). `Name (first 8)`
11
+ * was the same folder for both, so one of them had no folder and no
12
+ * manifest entry.
13
+ * 2. LETTER-CASE TWINS. "Search default" and "Search Default" were treated as
14
+ * two names, got no suffix, and are one folder on macOS and Windows.
15
+ * 3. Anything else that would make two records share a folder must fail
16
+ * loudly instead of dropping one.
17
+ *
18
+ * The rule under test keeps every name a record has today unless that record
19
+ * collides, so an existing mirror renames as little as possible.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ const folderNaming_1 = require("../folderNaming");
23
+ // assignFolderNames answers in input order; index the answers by sys_id.
24
+ const names = (records) => {
25
+ const out = {};
26
+ (0, folderNaming_1.assignFolderNames)(records).forEach((folder, index) => {
27
+ out[records[index].sys_id] = folder;
28
+ });
29
+ return out;
30
+ };
31
+ const folders = (records) => Object.values(names(records)).sort();
32
+ // Real shapes: sys_ids generated in one transaction share all but the tail.
33
+ const FIRE_LOG_A = "15f0e0ea33dfc7107b18bc534d5c7bc4";
34
+ const FIRE_LOG_B = "15f0e0ea33dfc7107b18bc534d5c7bf5";
35
+ const ANNOUNCE_A = "6d462a3bc3744714d4ddf1db05013163";
36
+ const ANNOUNCE_B = "6d462a3bc3744714d4ddf1db0501317b";
37
+ const ANNOUNCE_C = "6d462a3bc3744714d4ddf1db05013193";
38
+ describe("assignFolderNames: records that do not collide keep their name", () => {
39
+ it("leaves a unique display name plain", () => {
40
+ expect(names([
41
+ { name: "Send Email", sys_id: "dc2ef56133a0e2507b18bc534d5c7bf5" },
42
+ { name: "Send Text", sys_id: "0d4626f933e826507b18bc534d5c7b37" },
43
+ ])).toEqual({
44
+ dc2ef56133a0e2507b18bc534d5c7bf5: "Send Email",
45
+ "0d4626f933e826507b18bc534d5c7b37": "Send Text",
46
+ });
47
+ });
48
+ it("keeps the 8-character suffix for namesakes whose ids differ in the first 8", () => {
49
+ // As the instance sends them: already suffixed.
50
+ expect(folders([
51
+ { name: "Audience (0616384a)", sys_id: "0616384ac3f492d085b196c4e40131aa" },
52
+ { name: "Audience (92953c0a)", sys_id: "92953c0ac3f492d085b196c4e40131bb" },
53
+ ])).toEqual(["Audience (0616384a)", "Audience (92953c0a)"]);
54
+ });
55
+ it("suffixes every namesake when the instance did not", () => {
56
+ // No record keeps the bare name: which one would is an accident of order.
57
+ expect(folders([
58
+ { name: "Blueprint", sys_id: "1607d7f0c373f2d0d4ddf1db05013101" },
59
+ { name: "Blueprint", sys_id: "46ae2decc33f32d0d4ddf1db050131d9" },
60
+ ])).toEqual(["Blueprint (1607d7f0)", "Blueprint (46ae2dec)"]);
61
+ });
62
+ it("keeps the sys_id fallback for a name no disk can hold", () => {
63
+ expect(names([
64
+ { name: "x_cadso_work_task.*", sys_id: "bc91c2a5f334621048dff31590812771" },
65
+ { name: "Email Status Change ", sys_id: "fefb8758330ede107b18bc534d5c7bfb" },
66
+ { name: "", sys_id: "03227e9bc3850f10d4ddf1db050131b0" },
67
+ ])).toEqual({
68
+ bc91c2a5f334621048dff31590812771: "bc91c2a5f334621048dff31590812771",
69
+ fefb8758330ede107b18bc534d5c7bfb: "fefb8758330ede107b18bc534d5c7bfb",
70
+ "03227e9bc3850f10d4ddf1db050131b0": "03227e9bc3850f10d4ddf1db050131b0",
71
+ });
72
+ });
73
+ });
74
+ describe("assignFolderNames: name twins (same name, same first 8 id characters)", () => {
75
+ it("gives each twin its own folder: the suffix grows to the full id", () => {
76
+ const out = names([
77
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_A },
78
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_B },
79
+ ]);
80
+ expect(out[FIRE_LOG_A]).toBe("x_cadso_journey_fire_log (" + FIRE_LOG_A + ")");
81
+ expect(out[FIRE_LOG_B]).toBe("x_cadso_journey_fire_log (" + FIRE_LOG_B + ")");
82
+ });
83
+ it("does not leave either twin in the ambiguous 8-character folder", () => {
84
+ // Whichever twin kept `Name (15f0e0ea)` would hand it to the other the day
85
+ // it is deleted, and a push to that folder would write the wrong record.
86
+ expect(folders([
87
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_A },
88
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_B },
89
+ ])).not.toContain("x_cadso_journey_fire_log (15f0e0ea)");
90
+ });
91
+ it("handles a three-way twin group: one folder per record", () => {
92
+ const out = folders([
93
+ { name: "x_cadso_core_announcement", sys_id: ANNOUNCE_A },
94
+ { name: "x_cadso_core_announcement", sys_id: ANNOUNCE_B },
95
+ { name: "x_cadso_core_announcement", sys_id: ANNOUNCE_C },
96
+ ]);
97
+ expect(out).toHaveLength(3);
98
+ expect(new Set(out).size).toBe(3);
99
+ expect(out).toEqual([
100
+ "x_cadso_core_announcement (" + ANNOUNCE_A + ")",
101
+ "x_cadso_core_announcement (" + ANNOUNCE_B + ")",
102
+ "x_cadso_core_announcement (" + ANNOUNCE_C + ")",
103
+ ]);
104
+ });
105
+ it("lengthens only the records that collide, not their other namesakes", () => {
106
+ const other = "aa11bb22cc33dd44ee55ff6600112233";
107
+ const out = names([
108
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_A },
109
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_B },
110
+ { name: "x_cadso_journey_fire_log", sys_id: other },
111
+ ]);
112
+ expect(out[other]).toBe("x_cadso_journey_fire_log (aa11bb22)");
113
+ expect(out[FIRE_LOG_A]).toBe("x_cadso_journey_fire_log (" + FIRE_LOG_A + ")");
114
+ expect(out[FIRE_LOG_B]).toBe("x_cadso_journey_fire_log (" + FIRE_LOG_B + ")");
115
+ });
116
+ it("resolves twins the instance already suffixed with 8 characters", () => {
117
+ // What an instance that still names by `Name (first 8)` would send if it
118
+ // listed both: the same name twice.
119
+ const out = names([
120
+ { name: "Instance Step (c63eea7d)", sys_id: "c63eea7d33591a107b18bc534d5c7b12" },
121
+ { name: "Instance Step (c63eea7d)", sys_id: "c63eea7d33591a107b18bc534d5c7b3d" },
122
+ ]);
123
+ expect(out).toEqual({
124
+ c63eea7d33591a107b18bc534d5c7b12: "Instance Step (c63eea7d33591a107b18bc534d5c7b12)",
125
+ c63eea7d33591a107b18bc534d5c7b3d: "Instance Step (c63eea7d33591a107b18bc534d5c7b3d)",
126
+ });
127
+ });
128
+ it("never returns fewer folders than records", () => {
129
+ const records = [];
130
+ for (let i = 0; i < 40; i++) {
131
+ // 40 records, one name, ids identical in the first 30 characters.
132
+ records.push({
133
+ name: "x_cadso_work_goal",
134
+ sys_id: "c7fdaa3d470ef510b0361ae8036d43" + (i < 16 ? "0" : "") + i.toString(16),
135
+ });
136
+ }
137
+ const out = folders(records);
138
+ expect(out).toHaveLength(40);
139
+ expect(new Set(out.map(folderNaming_1.foldFolderName)).size).toBe(40);
140
+ });
141
+ });
142
+ describe("assignFolderNames: letter-case and normalization twins", () => {
143
+ it("suffixes names that differ only in letter case", () => {
144
+ expect(names([
145
+ { name: "Search default", sys_id: "7daaf59947d56910fc4c1ae8036d43c0" },
146
+ { name: "Search Default", sys_id: "fb55e60db195a5101b815df7b6dd8425" },
147
+ ])).toEqual({
148
+ "7daaf59947d56910fc4c1ae8036d43c0": "Search default (7daaf599)",
149
+ fb55e60db195a5101b815df7b6dd8425: "Search Default (fb55e60d)",
150
+ });
151
+ });
152
+ it("covers the other pairs lost on a case-insensitive disk", () => {
153
+ expect(folders([
154
+ { name: "Attachment", sys_id: "a77c5d71c3af025085b196c4e40131a4" },
155
+ { name: "attachment", sys_id: "67ac6651c34b421085b196c4e40131ea" },
156
+ { name: "instanceStepGr", sys_id: "12f10af8c3591610d4ddf1db05013195" },
157
+ { name: "instanceStepGR", sys_id: "c283177233fd1a107b18bc534d5c7ba6" },
158
+ ])).toEqual([
159
+ "Attachment (a77c5d71)",
160
+ "attachment (67ac6651)",
161
+ "instanceStepGR (c2831772)",
162
+ "instanceStepGr (12f10af8)",
163
+ ]);
164
+ });
165
+ it("produces folders that are distinct on a case-insensitive disk", () => {
166
+ const out = folders([
167
+ { name: "Link to destination relay (Lead - Overview)", sys_id: "132cdca9c372821085b196c4e4013139" },
168
+ { name: "Link to destination Relay (Lead - Overview)", sys_id: "d6e4b328c3f492d085b196c4e40131e4" },
169
+ ]);
170
+ expect(new Set(out.map(folderNaming_1.foldFolderName)).size).toBe(2);
171
+ });
172
+ it("suffixes names that differ only in Unicode normalization form", () => {
173
+ const composed = "Café"; // é as one code point
174
+ const decomposed = "Café"; // e + combining acute
175
+ const out = names([
176
+ { name: composed, sys_id: "aaaaaaaa000000000000000000000001" },
177
+ { name: decomposed, sys_id: "bbbbbbbb000000000000000000000002" },
178
+ ]);
179
+ expect(out["aaaaaaaa000000000000000000000001"]).toBe(composed + " (aaaaaaaa)");
180
+ expect(out["bbbbbbbb000000000000000000000002"]).toBe(decomposed + " (bbbbbbbb)");
181
+ });
182
+ it("counts a differently-cased name against namesakes the instance suffixed", () => {
183
+ // The instance counts exact names: two "Skip" got a suffix, "skip" did not.
184
+ expect(folders([
185
+ { name: "Skip (497eb251)", sys_id: "497eb251c3591610d4ddf1db05013100" },
186
+ { name: "Skip (74d107d5)", sys_id: "74d107d5c3591610d4ddf1db05013101" },
187
+ { name: "skip", sys_id: "0a0b0c0dc3591610d4ddf1db05013102" },
188
+ ])).toEqual(["Skip (497eb251)", "Skip (74d107d5)", "skip (0a0b0c0d)"]);
189
+ });
190
+ it("lengthens case twins that also share the first 8 id characters", () => {
191
+ const out = folders([
192
+ { name: "Report", sys_id: "abcdef0011111111111111111111111a" },
193
+ { name: "REPORT", sys_id: "abcdef0011111111111111111111111b" },
194
+ ]);
195
+ expect(out).toEqual([
196
+ "REPORT (abcdef0011111111111111111111111b)",
197
+ "Report (abcdef0011111111111111111111111a)",
198
+ ]);
199
+ });
200
+ it("does not rename a record whose name is unique ignoring case", () => {
201
+ expect(folders([
202
+ { name: "Nav Header API Success", sys_id: "11111111c3591610d4ddf1db05013100" },
203
+ { name: "Nav Header API Failure", sys_id: "22222222c3591610d4ddf1db05013100" },
204
+ ])).toEqual(["Nav Header API Failure", "Nav Header API Success"]);
205
+ });
206
+ });
207
+ describe("assignFolderNames: deterministic", () => {
208
+ const records = [
209
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_A },
210
+ { name: "Search default", sys_id: "7daaf59947d56910fc4c1ae8036d43c0" },
211
+ { name: "Send Email", sys_id: "dc2ef56133a0e2507b18bc534d5c7bf5" },
212
+ { name: "x_cadso_journey_fire_log", sys_id: FIRE_LOG_B },
213
+ { name: "Search Default", sys_id: "fb55e60db195a5101b815df7b6dd8425" },
214
+ { name: "x_cadso_work_task.*", sys_id: "bc91c2a5f334621048dff31590812771" },
215
+ ];
216
+ it("gives the same names whatever order the records arrive in", () => {
217
+ const forward = names(records);
218
+ const backward = names(records.slice().reverse());
219
+ expect(backward).toEqual(forward);
220
+ });
221
+ it("is idempotent: naming the named records again changes nothing", () => {
222
+ const first = names(records);
223
+ const renamed = records.map((r) => ({ name: first[r.sys_id], sys_id: r.sys_id }));
224
+ expect(names(renamed)).toEqual(first);
225
+ });
226
+ it("treats one sys_id listed twice as one record, not as two namesakes", () => {
227
+ expect((0, folderNaming_1.assignFolderNames)([
228
+ { name: "Send Email", sys_id: "dc2ef56133a0e2507b18bc534d5c7bf5" },
229
+ { name: "Send Email", sys_id: "dc2ef56133a0e2507b18bc534d5c7bf5" },
230
+ ])).toEqual(["Send Email", "Send Email"]);
231
+ });
232
+ it("answers in input order, one name per record", () => {
233
+ expect((0, folderNaming_1.assignFolderNames)([
234
+ { name: "Search Default", sys_id: "fb55e60db195a5101b815df7b6dd8425" },
235
+ { name: "Send Email", sys_id: "dc2ef56133a0e2507b18bc534d5c7bf5" },
236
+ { name: "Search default", sys_id: "7daaf59947d56910fc4c1ae8036d43c0" },
237
+ ])).toEqual(["Search Default (fb55e60d)", "Send Email", "Search default (7daaf599)"]);
238
+ });
239
+ });
240
+ describe("assignFolderNames: names the project configured", () => {
241
+ // tableOptions.differentiatorField: "sys_id" and a nameTemplate ending in
242
+ // "({sys_id})" put the record's own id at the end of its name on purpose.
243
+ // That is the name the project asked for, not a suffix naming added.
244
+ const HOME = "0a1b2c3d47d56910fc4c1ae8036d43c0";
245
+ it("keeps an id the configuration put in the name", () => {
246
+ expect((0, folderNaming_1.assignFolderNames)([{ name: "Home (" + HOME + ")", sys_id: HOME }], { configuredNames: true })).toEqual(["Home (" + HOME + ")"]);
247
+ });
248
+ it("still gives every record its own folder", () => {
249
+ expect((0, folderNaming_1.assignFolderNames)([
250
+ { name: "Search default", sys_id: "7daaf59947d56910fc4c1ae8036d43c0" },
251
+ { name: "Search Default", sys_id: "fb55e60db195a5101b815df7b6dd8425" },
252
+ { name: "x_cadso_journey_fire_log (15f0e0ea)", sys_id: FIRE_LOG_A },
253
+ { name: "x_cadso_journey_fire_log (15f0e0ea)", sys_id: FIRE_LOG_B },
254
+ ], { configuredNames: true })).toEqual([
255
+ "Search default (7daaf599)",
256
+ "Search Default (fb55e60d)",
257
+ "x_cadso_journey_fire_log (15f0e0ea) (" + FIRE_LOG_A + ")",
258
+ "x_cadso_journey_fire_log (15f0e0ea) (" + FIRE_LOG_B + ")",
259
+ ]);
260
+ });
261
+ it("without the option, the same name is read as a suffix and recomputed", () => {
262
+ expect((0, folderNaming_1.assignFolderNames)([{ name: "Home (" + HOME + ")", sys_id: HOME }])).toEqual(["Home"]);
263
+ });
264
+ });
265
+ describe("assignFolderNames: refuses to drop a record", () => {
266
+ it("throws, naming the records, when two cannot be told apart", () => {
267
+ // No sys_id to tell them apart: there is no honest folder name for both.
268
+ const run = () => (0, folderNaming_1.assignFolderNames)([
269
+ { name: "Orphan", sys_id: "" },
270
+ { name: "orphan", sys_id: "" },
271
+ { name: "Other", sys_id: "cccccccc000000000000000000000003" },
272
+ ]);
273
+ expect(run).toThrow(folderNaming_1.FolderNameCollisionError);
274
+ expect(run).toThrow(/Orphan/);
275
+ });
276
+ it("rejects input that is not a list of records", () => {
277
+ expect(() => (0, folderNaming_1.assignFolderNames)(null)).toThrow(TypeError);
278
+ });
279
+ it("tells records apart whose ids are also Object.prototype members", () => {
280
+ // Nothing a real instance sends; the bookkeeping must not trip on it.
281
+ expect((0, folderNaming_1.assignFolderNames)([
282
+ { name: "Dup", sys_id: "constructor" },
283
+ { name: "Dup", sys_id: "toString" },
284
+ { name: "Dup", sys_id: "__proto__" },
285
+ ])).toEqual(["Dup (construc)", "Dup (toString)", "Dup (__proto_)"]);
286
+ });
287
+ it("refuses malformed entries with the same error, not a crash", () => {
288
+ const broken = [null, null];
289
+ expect(() => (0, folderNaming_1.assignFolderNames)(broken)).toThrow(folderNaming_1.FolderNameCollisionError);
290
+ });
291
+ });
292
+ describe("baseRecordName", () => {
293
+ it("removes the id suffix the instance added", () => {
294
+ expect((0, folderNaming_1.baseRecordName)("Audience (0616384a)", "0616384ac3f492d085b196c4e40131aa")).toBe("Audience");
295
+ expect((0, folderNaming_1.baseRecordName)("x_cadso_journey_fire_log (" + FIRE_LOG_A + ")", FIRE_LOG_A)).toBe("x_cadso_journey_fire_log");
296
+ });
297
+ it("keeps parentheses that are part of the display name", () => {
298
+ expect((0, folderNaming_1.baseRecordName)("Check for Journey (Email Event)", "be252ec7c3dad690d4ddf1db050131d2")).toBe("Check for Journey (Email Event)");
299
+ // Another record's id prefix is not this record's suffix.
300
+ expect((0, folderNaming_1.baseRecordName)("Audience (0616384a)", "92953c0ac3f492d085b196c4e40131bb")).toBe("Audience (0616384a)");
301
+ // Fewer than 8 characters is not a suffix Dovetail writes.
302
+ expect((0, folderNaming_1.baseRecordName)("Step (0616)", "0616384ac3f492d085b196c4e40131aa")).toBe("Step (0616)");
303
+ });
304
+ });
305
+ describe("foldFolderName", () => {
306
+ it("is equal for names a case-insensitive disk cannot tell apart", () => {
307
+ expect((0, folderNaming_1.foldFolderName)("Search default")).toBe((0, folderNaming_1.foldFolderName)("Search Default"));
308
+ expect((0, folderNaming_1.foldFolderName)("Café")).toBe((0, folderNaming_1.foldFolderName)("Café"));
309
+ expect((0, folderNaming_1.foldFolderName)("STRASSE")).toBe((0, folderNaming_1.foldFolderName)("straße"));
310
+ });
311
+ it("is different for names that really differ", () => {
312
+ expect((0, folderNaming_1.foldFolderName)("Send Email")).not.toBe((0, folderNaming_1.foldFolderName)("Send Text"));
313
+ });
314
+ });
@@ -79,16 +79,95 @@ describe("normalizeManifestKeys", () => {
79
79
  expect(record).toBeDefined();
80
80
  expect(record.sys_id).toBe("fefb8758");
81
81
  });
82
- it("disambiguates duplicate folder names with a sys_id suffix", () => {
82
+ it("disambiguates duplicate folder names with a sys_id suffix on EVERY duplicate", () => {
83
+ // Used to leave the first record under the bare name and suffix only the
84
+ // later ones, so which record owned "Duplicate" depended on key order. The
85
+ // instance already suffixes every namesake; the client now agrees with it.
83
86
  const manifest = buildManifest([
84
87
  rec("Duplicate", "1111111111111111"),
85
88
  rec("Duplicate", "2222222222222222"),
86
89
  ]);
87
90
  (0, appUtils_1.normalizeManifestKeys)(manifest);
88
91
  const keys = Object.keys(manifest.tables.sys_script.records);
89
- expect(keys).toContain("Duplicate");
90
- expect(keys).toContain("Duplicate (22222222)");
91
- // invariant still holds for the suffixed record
92
+ expect(keys.sort()).toEqual(["Duplicate (11111111)", "Duplicate (22222222)"]);
93
+ // invariant still holds for the suffixed records
92
94
  expect(manifest.tables.sys_script.records["Duplicate (22222222)"].name).toBe("Duplicate (22222222)");
93
95
  });
96
+ // One manifest entry per record, whatever the names: the count of keys is the
97
+ // count of records. Shapes taken from records a real mirror lost.
98
+ describe("never leaves a manifest with fewer entries than records", () => {
99
+ const keysOf = (records) => {
100
+ const manifest = buildManifest(records);
101
+ (0, appUtils_1.normalizeManifestKeys)(manifest);
102
+ const out = manifest.tables.sys_script.records;
103
+ Object.keys(out).forEach((key) => expect(out[key].name).toBe(key));
104
+ return Object.keys(out).sort();
105
+ };
106
+ it("name twins: same name, same first 8 id characters", () => {
107
+ expect(keysOf([
108
+ rec("x_cadso_journey_fire_log", "15f0e0ea33dfc7107b18bc534d5c7bc4"),
109
+ rec("x_cadso_journey_fire_log", "15f0e0ea33dfc7107b18bc534d5c7bf5"),
110
+ ])).toEqual([
111
+ "x_cadso_journey_fire_log (15f0e0ea33dfc7107b18bc534d5c7bc4)",
112
+ "x_cadso_journey_fire_log (15f0e0ea33dfc7107b18bc534d5c7bf5)",
113
+ ]);
114
+ });
115
+ it("letter-case twins", () => {
116
+ expect(keysOf([
117
+ rec("Search default", "7daaf59947d56910fc4c1ae8036d43c0"),
118
+ rec("Search Default", "fb55e60db195a5101b815df7b6dd8425"),
119
+ ])).toEqual(["Search Default (fb55e60d)", "Search default (7daaf599)"]);
120
+ });
121
+ it("a table that mixes every case keeps one key per record", () => {
122
+ const records = [
123
+ rec("Send Email", "dc2ef56133a0e2507b18bc534d5c7bf5"),
124
+ rec("Audience (0616384a)", "0616384ac3f492d085b196c4e40131aa"),
125
+ rec("Audience (92953c0a)", "92953c0ac3f492d085b196c4e40131bb"),
126
+ rec("x_cadso_core_announcement", "6d462a3bc3744714d4ddf1db05013163"),
127
+ rec("x_cadso_core_announcement", "6d462a3bc3744714d4ddf1db0501317b"),
128
+ rec("x_cadso_core_announcement", "6d462a3bc3744714d4ddf1db05013193"),
129
+ rec("Attachment", "a77c5d71c3af025085b196c4e40131a4"),
130
+ rec("attachment", "67ac6651c34b421085b196c4e40131ea"),
131
+ rec("x_cadso_work_task.*", "bc91c2a5f334621048dff31590812771"),
132
+ rec("constructor", "c0c0c0c0c3f492d085b196c4e40131cc"),
133
+ ];
134
+ const keys = keysOf(records);
135
+ expect(keys).toHaveLength(records.length);
136
+ // Untouched: the unique name, the namesakes that already differ, the
137
+ // sys_id fallback, and a name that is also an Object.prototype member.
138
+ expect(keys).toEqual(expect.arrayContaining([
139
+ "Send Email",
140
+ "Audience (0616384a)",
141
+ "Audience (92953c0a)",
142
+ "bc91c2a5f334621048dff31590812771",
143
+ "constructor",
144
+ ]));
145
+ });
146
+ it("refuses, naming the table, when records cannot be told apart", () => {
147
+ const manifest = {
148
+ scope: "x_cadso_test",
149
+ tables: {
150
+ sys_script: {
151
+ records: {
152
+ a: { name: "Orphan", sys_id: "", files: [] },
153
+ b: { name: "orphan", sys_id: "", files: [] },
154
+ },
155
+ },
156
+ },
157
+ };
158
+ expect(() => (0, appUtils_1.normalizeManifestKeys)(manifest)).toThrow(/sys_script: Cannot give these 2 records/);
159
+ });
160
+ it("is idempotent", () => {
161
+ const manifest = buildManifest([
162
+ rec("x_cadso_journey_fire_log", "15f0e0ea33dfc7107b18bc534d5c7bc4"),
163
+ rec("x_cadso_journey_fire_log", "15f0e0ea33dfc7107b18bc534d5c7bf5"),
164
+ rec("Search default", "7daaf59947d56910fc4c1ae8036d43c0"),
165
+ rec("Search Default", "fb55e60db195a5101b815df7b6dd8425"),
166
+ ]);
167
+ (0, appUtils_1.normalizeManifestKeys)(manifest);
168
+ const once = JSON.stringify(manifest);
169
+ (0, appUtils_1.normalizeManifestKeys)(manifest);
170
+ expect(JSON.stringify(manifest)).toBe(once);
171
+ });
172
+ });
94
173
  });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ // A fingerprinted field is in the branch as a digest only (fingerprint.ts), and
3
+ // its metaData.json value is the digest too. `dove reconcile --apply` must not
4
+ // create such a record from the branch: it would write the digest over the
5
+ // field's real content. The create is refused per record and nothing is posted.
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ jest.mock("../Logger", function () {
11
+ return {
12
+ logger: {
13
+ info: jest.fn(),
14
+ debug: jest.fn(),
15
+ warn: jest.fn(),
16
+ error: jest.fn(),
17
+ success: jest.fn(),
18
+ getLogLevel: function () { return "debug"; },
19
+ },
20
+ };
21
+ });
22
+ jest.mock("../FileLogger", function () {
23
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
24
+ });
25
+ var mockSourcePath = "";
26
+ jest.mock("../config", function () {
27
+ return {
28
+ getSourcePathForScope: function () {
29
+ return mockSourcePath;
30
+ },
31
+ };
32
+ });
33
+ var mockPost = jest.fn();
34
+ jest.mock("../snClient", function () {
35
+ var actual = jest.requireActual("../snClient");
36
+ var client = actual.snClient("https://x.service-now.com/", "u", "p");
37
+ client.client.post = mockPost;
38
+ return Object.assign({}, actual, {
39
+ defaultClient: function () {
40
+ return client;
41
+ },
42
+ });
43
+ });
44
+ const fs_1 = __importDefault(require("fs"));
45
+ const os_1 = __importDefault(require("os"));
46
+ const path_1 = __importDefault(require("path"));
47
+ const reconcileCommand_1 = require("../reconcileCommand");
48
+ const fingerprint_1 = require("../fingerprint");
49
+ describe("reconcile applyCreates with a fingerprinted record", function () {
50
+ var tmp = "";
51
+ beforeEach(function () {
52
+ mockPost.mockReset();
53
+ tmp = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-fp-create-"));
54
+ mockSourcePath = tmp;
55
+ var recordDir = path_1.default.join(tmp, "sys_ux_lib_source_script", "Bundle");
56
+ fs_1.default.mkdirSync(recordDir, { recursive: true });
57
+ fs_1.default.writeFileSync(path_1.default.join(recordDir, "script.sha256"), (0, fingerprint_1.formatFingerprint)("!function(){}();"));
58
+ fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), JSON.stringify({ name: { value: "@tenon/ui-form" }, script: { value: "sha256:" + "0".repeat(64) } }));
59
+ });
60
+ afterEach(function () {
61
+ fs_1.default.rmSync(tmp, { recursive: true, force: true });
62
+ });
63
+ it("refuses the create with a named reason and never posts", async function () {
64
+ var change = {
65
+ kind: "create",
66
+ table: "sys_ux_lib_source_script",
67
+ scope: "x_cadso_ui_form",
68
+ sys_id: "f9cd",
69
+ name: "Bundle",
70
+ fieldDeltas: [],
71
+ };
72
+ var outcomes = await (0, reconcileCommand_1.applyCreates)("x_cadso_ui_form", [change], "us1");
73
+ expect(outcomes).toHaveLength(1);
74
+ expect(outcomes[0].ok).toBe(false);
75
+ expect(outcomes[0].error).toMatch(/fingerprint only/);
76
+ expect(outcomes[0].error).toMatch(/sys_ux_lib_source_script\/Bundle/);
77
+ expect(mockPost).not.toHaveBeenCalled();
78
+ });
79
+ });
@@ -176,6 +176,7 @@ describe("refreshCommand — exit code reflects failed scopes", function () {
176
176
  { scope: "x_cadso_core", error: "HTTP 400" },
177
177
  { scope: "x_cadso_work", error: "HTTP 400" },
178
178
  ],
179
+ notWritten: [],
179
180
  });
180
181
  await (0, commands_1.refreshCommand)({});
181
182
  expect(process.exitCode).toBe(1);
@@ -186,7 +187,7 @@ describe("refreshCommand — exit code reflects failed scopes", function () {
186
187
  expect(lines.some(function (l) { return l.indexOf("x_cadso_work: HTTP 400") !== -1; })).toBe(true);
187
188
  });
188
189
  test("clean refresh → 'Refresh complete!' and exit code untouched", async function () {
189
- jest.spyOn(AppUtils, "syncManifest").mockResolvedValue({ failedScopes: [] });
190
+ jest.spyOn(AppUtils, "syncManifest").mockResolvedValue({ failedScopes: [], notWritten: [] });
190
191
  await (0, commands_1.refreshCommand)({});
191
192
  expect(process.exitCode).toBeUndefined();
192
193
  expect(mockLogger.success).toHaveBeenCalledWith("Refresh complete!");