@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,95 @@
1
+ "use strict";
2
+ // After the instance delete, `dove delete` removes the record's local folder.
3
+ // It used to join the TOP-LEVEL sourceDirectory (src/<table>/<name>), but
4
+ // records live under their scope's folder (src/Core/..., or nested as
5
+ // src/UIComponents/<scope>/...), so the cleanup silently found nothing. It now
6
+ // uses the scope's own folder.
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 "info"; },
20
+ },
21
+ };
22
+ });
23
+ jest.mock("../FileLogger", function () {
24
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
25
+ });
26
+ jest.mock("../commands", function () {
27
+ return { setLogLevel: jest.fn() };
28
+ });
29
+ var mockRoot = "";
30
+ jest.mock("../config", function () {
31
+ var p = jest.requireActual("path");
32
+ return {
33
+ getSourcePath: function () { return p.join(mockRoot, "src"); },
34
+ getSourcePathForScope: function (scope) {
35
+ return p.join(mockRoot, "src", "UIComponents", scope);
36
+ },
37
+ loadScopeManifest: jest.fn().mockResolvedValue(undefined),
38
+ getManifest: function () { return undefined; },
39
+ getConfig: function () { return { scopes: {} }; },
40
+ isMultiScopeManifest: function () { return false; },
41
+ };
42
+ });
43
+ jest.mock("../FileUtils", function () {
44
+ return { writeScopeManifest: jest.fn().mockResolvedValue(undefined) };
45
+ });
46
+ var mockDelete = jest.fn();
47
+ jest.mock("../snClient", function () {
48
+ return {
49
+ defaultClient: function () {
50
+ return { deleteRecord: mockDelete };
51
+ },
52
+ };
53
+ });
54
+ const fs_1 = __importDefault(require("fs"));
55
+ const os_1 = __importDefault(require("os"));
56
+ const path_1 = __importDefault(require("path"));
57
+ const deleteRecordCommand_1 = require("../deleteRecordCommand");
58
+ describe("deleteRecordCommand local cleanup", function () {
59
+ beforeEach(function () {
60
+ mockRoot = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-delete-"));
61
+ mockDelete.mockReset();
62
+ mockDelete.mockResolvedValue({ data: { result: { name: "Panel" } } });
63
+ });
64
+ afterEach(function () {
65
+ fs_1.default.rmSync(mockRoot, { recursive: true, force: true });
66
+ });
67
+ it("removes the record folder under the scope's own folder", async function () {
68
+ var recordDir = path_1.default.join(mockRoot, "src", "UIComponents", "x_cadso_ui_panel", "sys_ux_lib_component", "Panel");
69
+ fs_1.default.mkdirSync(recordDir, { recursive: true });
70
+ fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), "{}");
71
+ await (0, deleteRecordCommand_1.deleteRecordCommand)({
72
+ table: "sys_ux_lib_component",
73
+ name: "Panel",
74
+ scope: "x_cadso_ui_panel",
75
+ sysid: "abc",
76
+ ci: true,
77
+ logLevel: "info",
78
+ });
79
+ expect(mockDelete).toHaveBeenCalledTimes(1);
80
+ expect(fs_1.default.existsSync(recordDir)).toBe(false);
81
+ });
82
+ it("leaves a same-named folder under the top-level source path alone", async function () {
83
+ var wrongDir = path_1.default.join(mockRoot, "src", "sys_ux_lib_component", "Panel");
84
+ fs_1.default.mkdirSync(wrongDir, { recursive: true });
85
+ await (0, deleteRecordCommand_1.deleteRecordCommand)({
86
+ table: "sys_ux_lib_component",
87
+ name: "Panel",
88
+ scope: "x_cadso_ui_panel",
89
+ sysid: "abc",
90
+ ci: true,
91
+ logLevel: "info",
92
+ });
93
+ expect(fs_1.default.existsSync(wrongDir)).toBe(true);
94
+ });
95
+ });
@@ -230,3 +230,143 @@ describe("DovetailUtilsMS.processMissingFiles — duplicate display names", () =
230
230
  expect(out.warnings).toHaveLength(0);
231
231
  });
232
232
  });
233
+ /**
234
+ * NAME TWINS. Records created in one transaction (the access controls of a new
235
+ * table) get sys_ids that differ only in the last few characters, so two that
236
+ * share a display name also share `Name (first 8)`. That key collapsed exactly
237
+ * like the bare name used to: one record left the manifest, silently.
238
+ */
239
+ const TWIN_A = "15f0e0ea33dfc7107b18bc534d5c7bc4";
240
+ const TWIN_B = "15f0e0ea33dfc7107b18bc534d5c7bf5";
241
+ const TRIPLET = [
242
+ "6d462a3bc3744714d4ddf1db05013163",
243
+ "6d462a3bc3744714d4ddf1db0501317b",
244
+ "6d462a3bc3744714d4ddf1db05013193",
245
+ ];
246
+ describe("DovetailUtilsMS.buildTableMap — same name and same first 8 id characters", () => {
247
+ it("keeps BOTH twins (regression: the 8-character key collapsed and one was dropped)", () => {
248
+ const out = buildMap([
249
+ { sys_id: TWIN_A, name: "x_cadso_journey_fire_log" },
250
+ { sys_id: TWIN_B, name: "x_cadso_journey_fire_log" },
251
+ ]);
252
+ const keys = Object.keys(out.records);
253
+ expect(keys).toHaveLength(2);
254
+ expect(keys.map((k) => out.records[k].sys_id).sort()).toEqual([TWIN_A, TWIN_B]);
255
+ });
256
+ it("lengthens the suffix to the full id for both, so neither holds the ambiguous key", () => {
257
+ const out = buildMap([
258
+ { sys_id: TWIN_A, name: "x_cadso_journey_fire_log" },
259
+ { sys_id: TWIN_B, name: "x_cadso_journey_fire_log" },
260
+ ]);
261
+ expect(Object.keys(out.records).sort()).toEqual([
262
+ "x_cadso_journey_fire_log (" + TWIN_A + ")",
263
+ "x_cadso_journey_fire_log (" + TWIN_B + ")",
264
+ ]);
265
+ expect(out.records["x_cadso_journey_fire_log (15f0e0ea)"]).toBeUndefined();
266
+ Object.keys(out.records).forEach((key) => {
267
+ expect(out.records[key].name).toBe(key);
268
+ });
269
+ });
270
+ it("keeps all three of a three-way twin group", () => {
271
+ const out = buildMap(TRIPLET.map((id) => ({ sys_id: id, name: "x_cadso_core_announcement" })));
272
+ expect(Object.keys(out.records).sort()).toEqual(TRIPLET.map((id) => "x_cadso_core_announcement (" + id + ")"));
273
+ });
274
+ it("lengthens only the records that collide; a namesake with another prefix keeps 8 characters", () => {
275
+ const out = buildMap([
276
+ { sys_id: TWIN_A, name: "x_cadso_journey_fire_log" },
277
+ { sys_id: TWIN_B, name: "x_cadso_journey_fire_log" },
278
+ { sys_id: "aa11bb22cc33dd44ee55ff6600112233", name: "x_cadso_journey_fire_log" },
279
+ ]);
280
+ expect(Object.keys(out.records).sort()).toEqual([
281
+ "x_cadso_journey_fire_log (" + TWIN_A + ")",
282
+ "x_cadso_journey_fire_log (" + TWIN_B + ")",
283
+ "x_cadso_journey_fire_log (aa11bb22)",
284
+ ]);
285
+ });
286
+ it("never returns fewer records than the table holds", () => {
287
+ const rows = [];
288
+ for (let i = 0; i < 25; i++) {
289
+ rows.push({
290
+ sys_id: "c7fdaa3d470ef510b0361ae8036d43" + (i < 16 ? "0" : "") + i.toString(16),
291
+ name: "x_cadso_work_goal",
292
+ });
293
+ }
294
+ expect(Object.keys(buildMap(rows).records)).toHaveLength(25);
295
+ });
296
+ });
297
+ /**
298
+ * LETTER-CASE TWINS. "Search default" and "Search Default" are two keys in a
299
+ * map and one folder on macOS and Windows. Counting names without regard to
300
+ * letter case gives both the id suffix, so the tree is the same on every disk.
301
+ */
302
+ describe("DovetailUtilsMS.buildTableMap — names that differ only in letter case", () => {
303
+ it("suffixes both, so they are two folders on a case-insensitive disk", () => {
304
+ const out = buildMap([
305
+ { sys_id: "7daaf59947d56910fc4c1ae8036d43c0", name: "Search default" },
306
+ { sys_id: "fb55e60db195a5101b815df7b6dd8425", name: "Search Default" },
307
+ ]);
308
+ expect(Object.keys(out.records).sort()).toEqual([
309
+ "Search Default (fb55e60d)",
310
+ "Search default (7daaf599)",
311
+ ]);
312
+ });
313
+ it("counts a differently-cased name against its exact namesakes", () => {
314
+ const out = buildMap([
315
+ { sys_id: "497eb251c3591610d4ddf1db05013100", name: "Skip" },
316
+ { sys_id: "74d107d5c3591610d4ddf1db05013101", name: "Skip" },
317
+ { sys_id: "0a0b0c0dc3591610d4ddf1db05013102", name: "skip" },
318
+ ]);
319
+ expect(Object.keys(out.records).sort()).toEqual([
320
+ "Skip (497eb251)",
321
+ "Skip (74d107d5)",
322
+ "skip (0a0b0c0d)",
323
+ ]);
324
+ });
325
+ it("lengthens case twins that also share the first 8 id characters", () => {
326
+ const out = buildMap([
327
+ { sys_id: "abcdef0011111111111111111111111a", name: "Report" },
328
+ { sys_id: "abcdef0011111111111111111111111b", name: "REPORT" },
329
+ ]);
330
+ expect(Object.keys(out.records).sort()).toEqual([
331
+ "REPORT (abcdef0011111111111111111111111b)",
332
+ "Report (abcdef0011111111111111111111111a)",
333
+ ]);
334
+ });
335
+ it("leaves names that are unique ignoring case untouched", () => {
336
+ const out = buildMap([
337
+ { sys_id: "11111111c3591610d4ddf1db05013100", name: "Nav Header API Success" },
338
+ { sys_id: "22222222c3591610d4ddf1db05013100", name: "Nav Header API Failure" },
339
+ ]);
340
+ expect(Object.keys(out.records).sort()).toEqual([
341
+ "Nav Header API Failure",
342
+ "Nav Header API Success",
343
+ ]);
344
+ expect(out.warnings).toHaveLength(0);
345
+ });
346
+ });
347
+ describe("DovetailUtilsMS.processMissingFiles — twins keep their own content", () => {
348
+ it("returns both name twins, each with its own payload", () => {
349
+ const out = processMissing([
350
+ { sys_id: TWIN_A, name: "x_cadso_journey_fire_log", script: "// read" },
351
+ { sys_id: TWIN_B, name: "x_cadso_journey_fire_log", script: "// write" },
352
+ ]);
353
+ expect(Object.keys(out.records).sort()).toEqual([
354
+ "x_cadso_journey_fire_log (" + TWIN_A + ")",
355
+ "x_cadso_journey_fire_log (" + TWIN_B + ")",
356
+ ]);
357
+ expect(out.records["x_cadso_journey_fire_log (" + TWIN_A + ")"].files[0].content).toBe("// read");
358
+ expect(out.records["x_cadso_journey_fire_log (" + TWIN_B + ")"].files[0].content).toBe("// write");
359
+ });
360
+ it("returns both letter-case twins, each with its own payload", () => {
361
+ const out = processMissing([
362
+ { sys_id: "a77c5d71c3af025085b196c4e40131a4", name: "Attachment", script: "// upper" },
363
+ { sys_id: "67ac6651c34b421085b196c4e40131ea", name: "attachment", script: "// lower" },
364
+ ]);
365
+ expect(Object.keys(out.records).sort()).toEqual([
366
+ "Attachment (a77c5d71)",
367
+ "attachment (67ac6651)",
368
+ ]);
369
+ expect(out.records["Attachment (a77c5d71)"].files[0].content).toBe("// upper");
370
+ expect(out.records["attachment (67ac6651)"].files[0].content).toBe("// lower");
371
+ });
372
+ });
@@ -107,6 +107,25 @@ describe("getFileContextWithSkipReason", function () {
107
107
  expect(result.context.name).toBe("TestRecord");
108
108
  expect(result.context.scope).toBe("x_test");
109
109
  });
110
+ it("refuses a .sha256 fingerprint file even when its field is in the manifest", function () {
111
+ mockManifest = {
112
+ scope: "x_cadso_ui_form",
113
+ tables: {
114
+ sys_ux_lib_source_script: {
115
+ records: {
116
+ Bundle: {
117
+ sys_id: "f9cd",
118
+ files: [{ name: "script", type: "sha256" }],
119
+ },
120
+ },
121
+ },
122
+ },
123
+ };
124
+ mockIsMultiScope = false;
125
+ var result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/UIComponents/x_cadso_ui_form/sys_ux_lib_source_script/Bundle/script.sha256");
126
+ expect(result.context).toBeUndefined();
127
+ expect(result.skipReason).toBe("fingerprint only, read-only");
128
+ });
110
129
  it("throws when no manifest is loaded", function () {
111
130
  mockManifest = null;
112
131
  expect(function () {
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ // Fingerprint mode (fingerprint.ts): a configured field is mirrored as a
3
+ // SHA-256 digest instead of its content. Covers the digest format, config
4
+ // validation, request stripping, response rewriting (manifest structure,
5
+ // bulkDownload content, metaData.json), idempotency and the push-side path test.
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
+ const crypto_1 = __importDefault(require("crypto"));
11
+ const fingerprint_1 = require("../fingerprint");
12
+ const BUNDLE = "!function(){console.log(\"bundle ü\")}();";
13
+ const HEX = crypto_1.default.createHash("sha256").update(BUNDLE, "utf8").digest("hex");
14
+ const OPTIONS = {
15
+ sys_ux_lib_source_script: { fingerprint: ["script"] },
16
+ sys_choice: { nameTemplate: "{name}.{element}.{value}" },
17
+ };
18
+ function metaContent(extra) {
19
+ return JSON.stringify(Object.assign({ _table: "sys_ux_lib_source_script", name: { value: "@tenon/ui-form" } }, extra), null, 2);
20
+ }
21
+ function bulkResult(files) {
22
+ return {
23
+ sys_ux_lib_source_script: {
24
+ records: {
25
+ "@tenon/ui-form": { name: "@tenon/ui-form", sys_id: "f9cd", files: files },
26
+ },
27
+ },
28
+ };
29
+ }
30
+ describe("formatFingerprint", function () {
31
+ it("writes the digest and the UTF-8 byte length", function () {
32
+ expect((0, fingerprint_1.formatFingerprint)(BUNDLE)).toBe("sha256:" + HEX + "\nbytes:" + Buffer.byteLength(BUNDLE, "utf8") + "\n");
33
+ });
34
+ it("is recognized by isFingerprintContent", function () {
35
+ expect((0, fingerprint_1.isFingerprintContent)((0, fingerprint_1.formatFingerprint)(BUNDLE))).toBe(true);
36
+ expect((0, fingerprint_1.isFingerprintContent)(BUNDLE)).toBe(false);
37
+ expect((0, fingerprint_1.isFingerprintContent)(undefined)).toBe(false);
38
+ });
39
+ });
40
+ describe("fingerprintFieldsFor", function () {
41
+ it("returns the configured fields", function () {
42
+ expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_ux_lib_source_script")).toEqual(["script"]);
43
+ });
44
+ it("returns nothing for an unconfigured table or missing options", function () {
45
+ expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_choice")).toEqual([]);
46
+ expect((0, fingerprint_1.fingerprintFieldsFor)(OPTIONS, "sys_script")).toEqual([]);
47
+ expect((0, fingerprint_1.fingerprintFieldsFor)(undefined, "sys_ux_lib_source_script")).toEqual([]);
48
+ expect((0, fingerprint_1.fingerprintFieldsFor)(null, "sys_ux_lib_source_script")).toEqual([]);
49
+ });
50
+ it("drops malformed entries instead of throwing", function () {
51
+ var bad = {
52
+ t1: { fingerprint: "script" },
53
+ t2: { fingerprint: ["", " ", 5, "script", "script"] },
54
+ };
55
+ expect((0, fingerprint_1.fingerprintFieldsFor)(bad, "t1")).toEqual([]);
56
+ expect((0, fingerprint_1.fingerprintFieldsFor)(bad, "t2")).toEqual(["script"]);
57
+ });
58
+ });
59
+ describe("stripClientOnlyTableOptions", function () {
60
+ it("removes fingerprint and keeps every other option", function () {
61
+ var out = (0, fingerprint_1.stripClientOnlyTableOptions)(OPTIONS);
62
+ expect(out.sys_ux_lib_source_script).toEqual({});
63
+ expect(out.sys_choice).toEqual({ nameTemplate: "{name}.{element}.{value}" });
64
+ });
65
+ it("never mutates the caller's options", function () {
66
+ (0, fingerprint_1.stripClientOnlyTableOptions)(OPTIONS);
67
+ expect(OPTIONS.sys_ux_lib_source_script.fingerprint).toEqual(["script"]);
68
+ });
69
+ it("returns an empty map for missing options", function () {
70
+ expect((0, fingerprint_1.stripClientOnlyTableOptions)(undefined)).toEqual({});
71
+ });
72
+ });
73
+ describe("applyFingerprints", function () {
74
+ it("renames a structure-only manifest entry to .sha256 without content", function () {
75
+ var tables = bulkResult([{ name: "script", type: "js" }]);
76
+ (0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
77
+ var file = tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0];
78
+ expect(file).toEqual({ name: "script", type: "sha256" });
79
+ });
80
+ it("hashes downloaded content, whatever type the server echoed", function () {
81
+ var tables = bulkResult([
82
+ { name: "script", type: "js", content: BUNDLE },
83
+ { name: "script_b", type: "sha256", content: BUNDLE },
84
+ ]);
85
+ (0, fingerprint_1.applyFingerprints)(tables, { sys_ux_lib_source_script: { fingerprint: ["script", "script_b"] } });
86
+ var files = tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files;
87
+ expect(files[0]).toEqual({ name: "script", type: "sha256", content: (0, fingerprint_1.formatFingerprint)(BUNDLE) });
88
+ expect(files[1].content).toBe((0, fingerprint_1.formatFingerprint)(BUNDLE));
89
+ });
90
+ it("replaces the field's metaData.json value with the digest and drops display_value", function () {
91
+ var tables = bulkResult([
92
+ {
93
+ name: "metaData",
94
+ type: "json",
95
+ content: metaContent({ script: { value: BUNDLE, display_value: BUNDLE } }),
96
+ },
97
+ ]);
98
+ (0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
99
+ var meta = JSON.parse(tables.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0].content);
100
+ expect(meta.script).toEqual({ value: "sha256:" + HEX });
101
+ expect(meta.name).toEqual({ value: "@tenon/ui-form" });
102
+ expect(JSON.stringify(meta)).not.toContain("bundle");
103
+ });
104
+ it("is idempotent", function () {
105
+ var tables = bulkResult([
106
+ { name: "script", type: "js", content: BUNDLE },
107
+ { name: "metaData", type: "json", content: metaContent({ script: { value: BUNDLE } }) },
108
+ ]);
109
+ (0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
110
+ var once = JSON.stringify(tables);
111
+ (0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
112
+ expect(JSON.stringify(tables)).toBe(once);
113
+ });
114
+ it("leaves tables without fingerprint config untouched", function () {
115
+ var tables = {
116
+ sys_script_include: {
117
+ records: {
118
+ Foo: { name: "Foo", sys_id: "1", files: [{ name: "script", type: "js", content: "x" }] },
119
+ },
120
+ },
121
+ };
122
+ var before = JSON.stringify(tables);
123
+ (0, fingerprint_1.applyFingerprints)(tables, OPTIONS);
124
+ expect(JSON.stringify(tables)).toBe(before);
125
+ });
126
+ it("tolerates malformed responses", function () {
127
+ expect((0, fingerprint_1.applyFingerprints)(null, OPTIONS)).toBeNull();
128
+ expect((0, fingerprint_1.applyFingerprints)("nope", OPTIONS)).toBe("nope");
129
+ var odd = {
130
+ sys_ux_lib_source_script: { records: { a: null, b: { files: "x" }, c: { files: [null, 7] } } },
131
+ };
132
+ expect(function () { (0, fingerprint_1.applyFingerprints)(odd, OPTIONS); }).not.toThrow();
133
+ var badMeta = bulkResult([{ name: "metaData", type: "json", content: "not json" }]);
134
+ (0, fingerprint_1.applyFingerprints)(badMeta, OPTIONS);
135
+ expect(badMeta.sys_ux_lib_source_script.records["@tenon/ui-form"].files[0].content).toBe("not json");
136
+ });
137
+ });
138
+ describe("isFingerprintFilePath", function () {
139
+ it("matches only a .sha256 extension", function () {
140
+ expect((0, fingerprint_1.isFingerprintFilePath)("/r/src/UIComponents/x/sys_ux_lib_source_script/a/script.sha256")).toBe(true);
141
+ expect((0, fingerprint_1.isFingerprintFilePath)("/r/src/Core/sys_script_include/a/script.js")).toBe(false);
142
+ expect((0, fingerprint_1.isFingerprintFilePath)("/r/a/sha256")).toBe(false);
143
+ });
144
+ });