Skip to content

Commit 00f95c1

Browse files
committed
test(cli): pin that a redundant re-add leaves the config file untouched
The value-comparison guard is what stops an install rewriting a committed config, so it deserves a check that fails if the guard regresses. Asserted through the file's own byte-level formatting: a rewrite would re-serialize it.
1 parent f77813e commit 00f95c1

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

packages/cli/src/utils/projectConfig.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ describe("projectConfig", () => {
398398
}
399399
});
400400

401+
// The old guard compared object identity, and `add` always builds fresh
402+
// records, so a redundant re-add always rewrote the file. Pinned through
403+
// the file's own byte-level formatting: a rewrite would re-serialize it.
404+
it("does not rewrite the file when every item is already recorded", () => {
405+
const dir = tmp();
406+
try {
407+
const text = `{\n\t"registry": "https://example.com/r",\n\t"registryItems": [\n\t\t{ "name": "data-chart", "type": "hyperframes:block", "target": "compositions/data-chart.html" }\n\t]\n}\n`;
408+
writeFileSync(projectConfigPath(dir), text, "utf-8");
409+
recordProjectRegistryItems(dir, [{ ...BLOCK }]);
410+
expect(readFileSync(projectConfigPath(dir), "utf-8")).toBe(text);
411+
} finally {
412+
rmSync(dir, { recursive: true, force: true });
413+
}
414+
});
415+
401416
// The config is normally committed, so an install must not rewrite keys it
402417
// does not own or reflow the file.
403418
it("preserves unknown keys and the file's own indentation", () => {

0 commit comments

Comments
 (0)