@tenonhq/dovetail-core 0.0.117 → 0.0.118

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/dist/FileUtils.js CHANGED
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.writeFileForce = exports.writeSNFileForce = exports.writeSNFileIfNotExists = exports.writeBuildFile = exports.summarizeFile = exports.encodedPathsToFilePaths = exports.isValidPath = exports.splitEncodedPaths = exports.getPathsInPath = exports.isDirectory = exports.toAbsolutePath = exports.getFileContextFromPath = exports.getFileContextWithSkipReason = exports.getBuildExt = exports.isUnderPath = exports.appendToPath = exports.pathExists = exports.createDirRecursively = exports.writeSNFileIfDifferent = exports.writeSNFileCurry = exports.writeScopeManifest = exports.writeManifestFile = exports.SNFileExists = void 0;
39
+ exports.writeFileForce = exports.writeSNFileForce = exports.writeSNFileIfNotExists = exports.writeBuildFile = exports.summarizeFile = exports.encodedPathsToFilePaths = exports.isValidPath = exports.splitEncodedPaths = exports.getPathsInPath = exports.isExistingDirectory = exports.isDirectory = exports.toAbsolutePath = exports.getFileContextFromPath = exports.getFileContextWithSkipReason = exports.getBuildExt = exports.isUnderPath = exports.appendToPath = exports.pathExists = exports.createDirRecursively = exports.writeSNFileIfDifferent = exports.writeSNFileCurry = exports.writeScopeManifest = exports.writeManifestFile = exports.SNFileExists = void 0;
40
40
  exports.writeEnvVar = writeEnvVar;
41
41
  exports.writeEnvVars = writeEnvVars;
42
42
  const constants_1 = require("./constants");
@@ -263,11 +263,41 @@ const getFileContextFromPath = (filePath) => {
263
263
  exports.getFileContextFromPath = getFileContextFromPath;
264
264
  const toAbsolutePath = (p) => path_1.default.isAbsolute(p) ? p : path_1.default.join(process.cwd(), p);
265
265
  exports.toAbsolutePath = toAbsolutePath;
266
+ /**
267
+ * True when `p` is a directory. THROWS if `p` does not exist — `fsp.stat`
268
+ * rejects with ENOENT and that rejection is deliberately not swallowed, because
269
+ * `getPathsInPath` relies on a missing path being an error rather than being
270
+ * silently treated as a file.
271
+ *
272
+ * If you are asking "is there a directory here?" about a path that may legally
273
+ * be absent, you want `isExistingDirectory` instead. Using this one for that
274
+ * shipped a real bug: the `--metadata-only` refresh aborted an entire scope on
275
+ * the first record present on the instance but absent from the branch, which is
276
+ * the common case, not an edge one.
277
+ */
266
278
  const isDirectory = async (p) => {
267
279
  const stats = await fs_1.promises.stat(p);
268
280
  return stats.isDirectory();
269
281
  };
270
282
  exports.isDirectory = isDirectory;
283
+ /**
284
+ * True when `p` exists AND is a directory; false for a missing path, a regular
285
+ * file, or an unreadable one. Never throws.
286
+ *
287
+ * Prefer this over `pathExists` when the caller is about to write *into* `p` —
288
+ * `pathExists` also returns true for a regular file, so a stray file sitting at
289
+ * a record path would pass the check and fail confusingly at write time.
290
+ */
291
+ const isExistingDirectory = async (p) => {
292
+ try {
293
+ const stats = await fs_1.promises.stat(p);
294
+ return stats.isDirectory();
295
+ }
296
+ catch (e) {
297
+ return false;
298
+ }
299
+ };
300
+ exports.isExistingDirectory = isExistingDirectory;
271
301
  const getPathsInPath = async (p) => {
272
302
  if (!(0, exports.isUnderPath)(ConfigManager.getSourcePath(), p) &&
273
303
  !(0, exports.isUnderPath)(ConfigManager.getBuildPath(), p)) {
package/dist/appUtils.js CHANGED
@@ -95,16 +95,32 @@ const stripRecordLinkHost = (link) => link.replace(/^https?:\/\/[^/]+\.service-n
95
95
  // entirely and push keys off `value` / the manifest.
96
96
  const SYS_DATETIME_RE = /^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$/;
97
97
  // References carried by nearly every record — one rename churns the whole tree.
98
- const WHOLE_TREE_REFERENCE_KEYS = ["sys_scope", "sys_package"];
99
- // Normalize for comparison: the server uses null and "" interchangeably across
100
- // the two halves of a pair, and String(null) would otherwise read as "null".
101
- const displayNorm = (v) => v === null || v === undefined ? "" : String(v);
98
+ const WHOLE_TREE_REFERENCE_KEYS = new Set(["sys_scope", "sys_package"]);
99
+ // Normalize a half of the pair for comparison. Returns null for anything that
100
+ // is not a primitive: String({}) collapses every object to "[object Object]",
101
+ // so two structurally different values would compare equal and silently lose a
102
+ // display_value. A non-primitive is treated as "not comparable" instead.
103
+ // null and "" are deliberately folded together — the server uses them
104
+ // interchangeably across the two halves, and String(null) would read as "null".
105
+ const displayNorm = (v) => {
106
+ if (v === null || v === undefined)
107
+ return "";
108
+ const t = typeof v;
109
+ if (t === "string" || t === "number" || t === "boolean")
110
+ return String(v);
111
+ return null;
112
+ };
102
113
  const shouldDropDisplayValue = (key, value, displayValue) => {
103
- if (displayNorm(value) === displayNorm(displayValue))
114
+ const normValue = displayNorm(value);
115
+ const normDisplay = displayNorm(displayValue);
116
+ // Identical -> the display_value carries no information, at any size.
117
+ if (normValue !== null && normValue === normDisplay)
104
118
  return true;
105
- if (SYS_DATETIME_RE.test(displayNorm(value)))
119
+ // Datetime -> display_value is rendered in the PULLER's timezone.
120
+ if (normValue !== null && SYS_DATETIME_RE.test(normValue))
106
121
  return true;
107
- if (WHOLE_TREE_REFERENCE_KEYS.indexOf(key) !== -1)
122
+ // Present in ~every record -> one rename rewrites the whole mirror.
123
+ if (WHOLE_TREE_REFERENCE_KEYS.has(key))
108
124
  return true;
109
125
  return false;
110
126
  };
@@ -745,11 +761,11 @@ const refreshAllFiles = async (newManifest, sourcePath, options = {}) => {
745
761
  // metadataOnly refreshes what is already checked out. A record the
746
762
  // instance has but this branch does not is left alone — pulling it in
747
763
  // would be a content change, which is exactly what this mode excludes.
748
- // pathExists, NOT isDirectory: isDirectory stats unguarded and REJECTS
749
- // on ENOENT, and processBatched propagates, so a single absent record
750
- // would abort the whole scope — the common case, since "the instance
751
- // has records this branch doesn't" is precisely what we're skipping.
752
- if (metadataOnly && !(await fUtils.pathExists(recPath))) {
764
+ // isExistingDirectory, not isDirectory (which REJECTS on ENOENT, and
765
+ // processBatched propagates, so one absent record aborted the whole
766
+ // scope) and not pathExists (which is true for a regular file too, so a
767
+ // stray file at a record path would pass and fail at write time).
768
+ if (metadataOnly && !(await fUtils.isExistingDirectory(recPath))) {
753
769
  skippedAbsentCount++;
754
770
  // Drop the downloaded content for skipped records too — filesToProcess
755
771
  // accumulates across every chunk, so holding it would grow unbounded
@@ -847,7 +863,10 @@ const refreshAllFiles = async (newManifest, sourcePath, options = {}) => {
847
863
  Logger_1.logger.debug("No file changes detected from instance (" + unchangedCount + " checked)");
848
864
  }
849
865
  if (options.benchmarkCollector) {
850
- options.benchmarkCollector.endScope(writtenCount, unchangedCount);
866
+ // metadataOnly writes no field file, so writtenCount is always 0 — report
867
+ // the metaData writes instead, or `--benchmark --metadata-only` would show
868
+ // a scope that did thousands of writes as having done nothing.
869
+ options.benchmarkCollector.endScope(metadataOnly ? metadataWrittenCount : writtenCount, metadataOnly ? skippedAbsentCount : unchangedCount);
851
870
  }
852
871
  }
853
872
  catch (e) {
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /**
3
+ * Coverage for the `dove refresh` flag guards and the filesystem predicate the
4
+ * `--metadata-only` skip depends on.
5
+ *
6
+ * Both were gaps found reviewing the metaData work after it shipped:
7
+ *
8
+ * 1. `--metadata-only` + `--force` is contradictory (one writes no field file,
9
+ * the other overwrites every field file). refreshCommand refuses the
10
+ * combination, but that refusal was user-facing behaviour with zero tests.
11
+ *
12
+ * 2. `isDirectory` REJECTS on a missing path rather than returning false, and
13
+ * `processBatched` propagates — which aborted an entire scope on the first
14
+ * record present on the instance but absent from the branch. That is the
15
+ * common case for `--metadata-only`, not an edge one. `isExistingDirectory`
16
+ * is the guarded predicate; these tests pin the contract of all three so
17
+ * the next caller picks the right one deliberately.
18
+ */
19
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20
+ if (k2 === undefined) k2 = k;
21
+ var desc = Object.getOwnPropertyDescriptor(m, k);
22
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
23
+ desc = { enumerable: true, get: function() { return m[k]; } };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }) : (function(o, m, k, k2) {
27
+ if (k2 === undefined) k2 = k;
28
+ o[k2] = m[k];
29
+ }));
30
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
31
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
32
+ }) : function(o, v) {
33
+ o["default"] = v;
34
+ });
35
+ var __importStar = (this && this.__importStar) || (function () {
36
+ var ownKeys = function(o) {
37
+ ownKeys = Object.getOwnPropertyNames || function (o) {
38
+ var ar = [];
39
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
+ return ar;
41
+ };
42
+ return ownKeys(o);
43
+ };
44
+ return function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
51
+ })();
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ const fs = __importStar(require("fs"));
54
+ const os = __importStar(require("os"));
55
+ const path = __importStar(require("path"));
56
+ var mockLogger = {
57
+ info: jest.fn(),
58
+ debug: jest.fn(),
59
+ warn: jest.fn(),
60
+ error: jest.fn(),
61
+ success: jest.fn(),
62
+ setLogLevel: jest.fn(),
63
+ getLogLevel: function () { return "warn"; },
64
+ };
65
+ jest.mock("../Logger", function () { return { logger: mockLogger }; });
66
+ jest.mock("../FileLogger", function () {
67
+ return { fileLogger: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() } };
68
+ });
69
+ jest.mock("../snClient", function () {
70
+ return {
71
+ defaultClient: function () { return { getManifest: jest.fn(), getMissingFiles: jest.fn() }; },
72
+ unwrapSNResponse: function (p) { return Promise.resolve(p); },
73
+ processPushResponse: jest.fn(),
74
+ retryOnErr: jest.fn(),
75
+ retryOnHttpErr: jest.fn(),
76
+ unwrapTableAPIFirstItem: jest.fn(),
77
+ };
78
+ });
79
+ jest.mock("../config", function () {
80
+ return {
81
+ getConfig: jest.fn().mockReturnValue({ scopes: { x_cadso_core: {} }, tableOptions: {} }),
82
+ getManifest: jest.fn().mockResolvedValue({}),
83
+ getSourcePath: jest.fn(),
84
+ getSourcePathForScope: jest.fn(),
85
+ getManifestPath: jest.fn().mockReturnValue("/tmp/dove.manifest.json"),
86
+ getScopeManifestPath: jest.fn().mockReturnValue("/tmp/dove.manifest.json"),
87
+ resolveConfigForScope: jest.fn().mockReturnValue({
88
+ tables: ["sys_script_include"],
89
+ fieldOverrides: {},
90
+ apiIncludes: {},
91
+ apiExcludes: {},
92
+ }),
93
+ isMultiScopeManifest: jest.fn().mockReturnValue(true),
94
+ updateManifest: jest.fn(),
95
+ };
96
+ });
97
+ jest.mock("progress", function () {
98
+ return jest.fn().mockImplementation(function () { return { tick: jest.fn() }; });
99
+ });
100
+ const AppUtils = __importStar(require("../appUtils"));
101
+ const fUtils = __importStar(require("../FileUtils"));
102
+ const commands_1 = require("../commands");
103
+ describe("refresh — --metadata-only and --force are mutually exclusive", function () {
104
+ beforeEach(function () {
105
+ jest.clearAllMocks();
106
+ jest.spyOn(AppUtils, "syncManifest").mockResolvedValue(undefined);
107
+ });
108
+ afterEach(function () {
109
+ jest.restoreAllMocks();
110
+ });
111
+ test("rejects the combination instead of silently picking one", async function () {
112
+ // Silently honouring --force here would overwrite every field file from the
113
+ // instance for someone who explicitly asked to touch nothing but metaData.
114
+ await expect((0, commands_1.refreshCommand)({ metadataOnly: true, force: true })).rejects.toThrow(/--metadata-only cannot be combined with --force/);
115
+ });
116
+ test("does not reach syncManifest when the combination is refused", async function () {
117
+ await expect((0, commands_1.refreshCommand)({ metadataOnly: true, force: true })).rejects.toThrow();
118
+ expect(AppUtils.syncManifest).not.toHaveBeenCalled();
119
+ });
120
+ test("each flag on its own is accepted", async function () {
121
+ await (0, commands_1.refreshCommand)({ metadataOnly: true });
122
+ await (0, commands_1.refreshCommand)({ force: true });
123
+ expect(AppUtils.syncManifest).toHaveBeenCalledTimes(2);
124
+ expect(AppUtils.syncManifest.mock.calls[0][1]).toMatchObject({
125
+ metadataOnly: true,
126
+ force: false,
127
+ });
128
+ expect(AppUtils.syncManifest.mock.calls[1][1]).toMatchObject({
129
+ metadataOnly: false,
130
+ force: true,
131
+ });
132
+ });
133
+ });
134
+ describe("FileUtils directory predicates — pick the right one deliberately", function () {
135
+ var tmpRoot;
136
+ var dir;
137
+ var file;
138
+ var missing;
139
+ beforeEach(function () {
140
+ tmpRoot = fs.mkdtempSync(path.join(os.tmpdir(), "dove-dirpred-"));
141
+ dir = path.join(tmpRoot, "a-directory");
142
+ file = path.join(tmpRoot, "a-file");
143
+ missing = path.join(tmpRoot, "does-not-exist");
144
+ fs.mkdirSync(dir);
145
+ fs.writeFileSync(file, "x");
146
+ });
147
+ afterEach(function () {
148
+ try {
149
+ fs.rmSync(tmpRoot, { recursive: true, force: true });
150
+ }
151
+ catch (e) { }
152
+ });
153
+ test("isExistingDirectory: true only for a real directory, never throws", async function () {
154
+ expect(await fUtils.isExistingDirectory(dir)).toBe(true);
155
+ expect(await fUtils.isExistingDirectory(file)).toBe(false);
156
+ expect(await fUtils.isExistingDirectory(missing)).toBe(false);
157
+ });
158
+ test("isDirectory still REJECTS on a missing path (documented, relied on)", async function () {
159
+ // getPathsInPath treats a missing path as an error rather than a file, so
160
+ // this rejection is deliberate. Pinning it stops a well-meaning "fix" from
161
+ // changing that behaviour silently.
162
+ expect(await fUtils.isDirectory(dir)).toBe(true);
163
+ expect(await fUtils.isDirectory(file)).toBe(false);
164
+ await expect(fUtils.isDirectory(missing)).rejects.toThrow();
165
+ });
166
+ test("pathExists is true for a plain file — why it is the wrong write-target check", async function () {
167
+ expect(await fUtils.pathExists(file)).toBe(true);
168
+ expect(await fUtils.isExistingDirectory(file)).toBe(false);
169
+ });
170
+ });
@@ -172,6 +172,15 @@ describe("stampMetadataContent — display_value DROPPED where it is churn", ()
172
172
  const out = (0, appUtils_1.stampMetadataContent)(metaFile({ controlled_by_refs: { value: null, display_value: "" } }));
173
173
  expect(parse(out).controlled_by_refs).toEqual({ value: null });
174
174
  });
175
+ it("does not treat two different objects as identical", () => {
176
+ // String({}) collapses every object to "[object Object]", so a naive
177
+ // stringify-and-compare would call these equal and drop a display_value
178
+ // that carries real information. Non-primitives are simply not comparable.
179
+ const out = (0, appUtils_1.stampMetadataContent)(metaFile({
180
+ weird: { value: { a: 1 }, display_value: { b: 2 } },
181
+ }));
182
+ expect(parse(out).weird.display_value).toEqual({ b: 2 });
183
+ });
175
184
  });
176
185
  describe("stampMetadataContent — display_value KEPT where it is information", () => {
177
186
  it("keeps a reference's human name (the sys_id -> name mapping)", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tenonhq/dovetail-core",
3
- "version": "0.0.117",
3
+ "version": "0.0.118",
4
4
  "description": "Next-gen file syncer",
5
5
  "license": "GPL-3.0",
6
6
  "main": "./dist/index.js",
@@ -1,7 +1,33 @@
1
1
  {
2
2
  "$schema": "dovetail-manifest/v1",
3
- "generated_at": "2026-07-28T06:17:01.139Z",
3
+ "generated_at": "2026-07-28T06:44:03.536Z",
4
4
  "events": [
5
+ {
6
+ "$schema": "dovetail-release-event/v1",
7
+ "event_id": "dovetail-core@0.0.117",
8
+ "package": "@tenonhq/dovetail-core",
9
+ "version": "0.0.117",
10
+ "prev_version": "0.0.116",
11
+ "published_at": "2026-07-28T06:44:03.528Z",
12
+ "git": {
13
+ "sha": "47199bcf436db3be5b8fd6728265444e72a96bc0",
14
+ "tag": "dovetail-core@0.0.117"
15
+ },
16
+ "semver_bump": "patch",
17
+ "commits": [
18
+ {
19
+ "sha": "47199bcf4",
20
+ "subject": "fix(core): keep informative display_value, drop only the churning kinds (#250)",
21
+ "pr": 250
22
+ },
23
+ {
24
+ "sha": "afd387889",
25
+ "subject": "chore(release): @tenonhq/dovetail-core@0.0.116 [skip ci]"
26
+ }
27
+ ],
28
+ "exports_delta": null,
29
+ "narrative": null
30
+ },
5
31
  {
6
32
  "$schema": "dovetail-release-event/v1",
7
33
  "event_id": "dovetail-core@0.0.116",
@@ -1228,32 +1254,6 @@
1228
1254
  ],
1229
1255
  "exports_delta": null,
1230
1256
  "narrative": null
1231
- },
1232
- {
1233
- "$schema": "dovetail-release-event/v1",
1234
- "event_id": "dovetail-servicenow@0.0.21",
1235
- "package": "@tenonhq/dovetail-servicenow",
1236
- "version": "0.0.21",
1237
- "prev_version": "0.0.20",
1238
- "published_at": "2026-06-15T17:59:30.698Z",
1239
- "git": {
1240
- "sha": "51e4e4592d491cd337f5bc1aa93d04f582f555a1",
1241
- "tag": "dovetail-servicenow@0.0.21"
1242
- },
1243
- "semver_bump": "patch",
1244
- "commits": [
1245
- {
1246
- "sha": "51e4e4592",
1247
- "subject": "feat(mcp): per-call instance retarget for servicenow_query_table (#180)",
1248
- "pr": 180
1249
- },
1250
- {
1251
- "sha": "c5d9106c4",
1252
- "subject": "chore(release): publish 2 packages [skip ci]"
1253
- }
1254
- ],
1255
- "exports_delta": null,
1256
- "narrative": null
1257
1257
  }
1258
1258
  ]
1259
1259
  }