@tenonhq/dovetail-core 0.0.132 → 0.0.134
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 +1 -1
- package/dist/FileUtils.js +7 -0
- package/dist/appUtils.js +296 -51
- package/dist/commands.js +13 -1
- package/dist/createRecordCommand.js +19 -7
- package/dist/fingerprint.js +4 -3
- package/dist/folderNaming.js +193 -0
- package/dist/gitIgnoreCheck.js +167 -0
- package/dist/layoutElements.js +386 -0
- package/dist/reconcileCommand.js +6 -0
- package/dist/snClient.js +49 -6
- package/dist/tests/dovetailUtilsMSCollision.test.js +140 -0
- package/dist/tests/folderNaming.test.js +314 -0
- package/dist/tests/layoutElements.test.js +259 -0
- package/dist/tests/layoutElementsWriteGuards.test.js +113 -0
- package/dist/tests/normalizeManifestKeys.test.js +83 -4
- package/dist/tests/refreshFailedScopes.test.js +2 -1
- package/dist/tests/refreshFolderCollisions.test.js +459 -0
- package/dist/tests/snClient.layoutElements.test.js +133 -0
- package/package.json +3 -3
- package/release-manifest.json +329 -363
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A layout elements file (columns.txt, fields.txt, sections.txt) is read from the
|
|
3
|
+
// child rows of a layout; it is not a field of the layout record. Push must
|
|
4
|
+
// refuse it even though the manifest lists it, and a reconcile create must not
|
|
5
|
+
// send it as a field.
|
|
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(), log: jest.fn() } };
|
|
24
|
+
});
|
|
25
|
+
var mockManifest = null;
|
|
26
|
+
var mockSourcePath = "";
|
|
27
|
+
jest.mock("../config", function () {
|
|
28
|
+
return {
|
|
29
|
+
getManifest: function () { return mockManifest; },
|
|
30
|
+
isMultiScopeManifest: function () { return false; },
|
|
31
|
+
resolveScopeFromPath: function () { return undefined; },
|
|
32
|
+
resolveManifestForScope: function () { return undefined; },
|
|
33
|
+
getSourcePathForScope: function () { return mockSourcePath; },
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
var mockPost = jest.fn();
|
|
37
|
+
jest.mock("../snClient", function () {
|
|
38
|
+
var actual = jest.requireActual("../snClient");
|
|
39
|
+
var client = actual.snClient("https://x.service-now.com/", "u", "p");
|
|
40
|
+
client.client.post = mockPost;
|
|
41
|
+
return Object.assign({}, actual, {
|
|
42
|
+
defaultClient: function () {
|
|
43
|
+
return client;
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const fs_1 = __importDefault(require("fs"));
|
|
48
|
+
const os_1 = __importDefault(require("os"));
|
|
49
|
+
const path_1 = __importDefault(require("path"));
|
|
50
|
+
const FileUtils_1 = require("../FileUtils");
|
|
51
|
+
const reconcileCommand_1 = require("../reconcileCommand");
|
|
52
|
+
const LIST = "a".repeat(32);
|
|
53
|
+
describe("push refuses layout elements files", function () {
|
|
54
|
+
beforeEach(function () {
|
|
55
|
+
mockManifest = {
|
|
56
|
+
scope: "x_cadso_work",
|
|
57
|
+
tables: {
|
|
58
|
+
sys_ui_list: {
|
|
59
|
+
records: {
|
|
60
|
+
"x_cadso_work_task.Default view": {
|
|
61
|
+
name: "x_cadso_work_task.Default view",
|
|
62
|
+
sys_id: LIST,
|
|
63
|
+
files: [{ name: "name", type: "txt" }, { name: "columns", type: "txt" }],
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
it("skips columns.txt with a named reason although the manifest lists it", function () {
|
|
71
|
+
const result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/sys_ui_list/x_cadso_work_task.Default view/columns.txt");
|
|
72
|
+
expect(result.context).toBeUndefined();
|
|
73
|
+
expect(result.skipReason).toBe("layout elements, read-only");
|
|
74
|
+
});
|
|
75
|
+
it("still resolves the layout's own field file", function () {
|
|
76
|
+
const result = (0, FileUtils_1.getFileContextWithSkipReason)("/project/src/sys_ui_list/x_cadso_work_task.Default view/name.txt");
|
|
77
|
+
expect(result.skipReason).toBeUndefined();
|
|
78
|
+
expect(result.context && result.context.targetField).toBe("name");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
describe("reconcile create leaves layout elements out of the record fields", function () {
|
|
82
|
+
let tmp = "";
|
|
83
|
+
beforeEach(function () {
|
|
84
|
+
mockPost.mockReset();
|
|
85
|
+
mockPost.mockResolvedValue({ status: 201, data: { result: { sys_id: LIST } } });
|
|
86
|
+
tmp = fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), "dove-layout-create-"));
|
|
87
|
+
mockSourcePath = tmp;
|
|
88
|
+
const recordDir = path_1.default.join(tmp, "sys_ui_list", "x_cadso_work_task.Default view");
|
|
89
|
+
fs_1.default.mkdirSync(recordDir, { recursive: true });
|
|
90
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "name.txt"), "x_cadso_work_task");
|
|
91
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "columns.txt"), "number\nstate\n");
|
|
92
|
+
fs_1.default.writeFileSync(path_1.default.join(recordDir, "metaData.json"), JSON.stringify({ name: { value: "x_cadso_work_task" } }));
|
|
93
|
+
});
|
|
94
|
+
afterEach(function () {
|
|
95
|
+
fs_1.default.rmSync(tmp, { recursive: true, force: true });
|
|
96
|
+
});
|
|
97
|
+
it("posts the record without a columns field", async function () {
|
|
98
|
+
const change = {
|
|
99
|
+
kind: "create",
|
|
100
|
+
table: "sys_ui_list",
|
|
101
|
+
scope: "x_cadso_work",
|
|
102
|
+
sys_id: LIST,
|
|
103
|
+
name: "x_cadso_work_task.Default view",
|
|
104
|
+
fieldDeltas: [],
|
|
105
|
+
};
|
|
106
|
+
await (0, reconcileCommand_1.applyCreates)("x_cadso_work", [change], "us1");
|
|
107
|
+
expect(mockPost).toHaveBeenCalled();
|
|
108
|
+
const body = JSON.stringify(mockPost.mock.calls[0][1]);
|
|
109
|
+
expect(body).toContain("x_cadso_work_task");
|
|
110
|
+
expect(body).not.toContain("columns");
|
|
111
|
+
expect(body).not.toContain("number\\nstate");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -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).
|
|
90
|
-
|
|
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
|
});
|
|
@@ -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!");
|