Skip to content

armgit / kiln

Public Imported from GitHub
0

Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.

ci: fail on merge markers left in tracked files (#328)

Matthew Kissinger5e1bc682c3da
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e5b2a9a5..44abae7b 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -44,6 +44,9 @@ jobs:
- name: Check skills against the Agent Skills specification
run: bun run check:skills
+ - name: Check tracked files for merge markers
+ run: bun run check:merge-markers
+
- name: Install
run: bun install --frozen-lockfile
diff --git a/package.json b/package.json
index c579f170..68c2a83c 100644
--- a/package.json
+++ b/package.json
@@ -318,6 +318,7 @@
"kiln": "bun src/cli.ts",
"check:toolchain": "bun scripts/check-toolchain.mjs",
"check:skills": "node scripts/check-skills.mjs",
+ "check:merge-markers": "node scripts/check-merge-markers.mjs",
"typecheck": "tsc --noEmit",
"build": "tsc --noEmit",
"build:mcp": "node scripts/build-runtime.mjs mcp",
diff --git a/scripts/check-merge-markers.mjs b/scripts/check-merge-markers.mjs
new file mode 100644
index 00000000..cef467eb
--- /dev/null
+++ b/scripts/check-merge-markers.mjs
@@ -0,0 +1,25 @@
+/**
+ * Fails on merge-conflict lines in tracked files. Merge-conflict lines reached
+ * CHANGELOG.md on main twice, once in a published release, because no other gate reads
+ * Markdown. `=======` alone is left out: it is also a Markdown heading underline.
+ * `dist/` is generated, and minified output can start a line with anything.
+ */
+import { spawnSync } from 'node:child_process';
+
+const result = spawnSync(
+ 'git',
+ ['grep', '-nIE', '^(<<<<<<< |\\|\\|\\|\\|\\|\\|\\| |>>>>>>> )', '--', '.', ':(exclude)dist/**'],
+ { encoding: 'utf8' },
+);
+
+// `git grep` exits 1 when nothing matches, which is the passing case here.
+if (result.status === 1) {
+ console.log('Merge markers: none in tracked files');
+ process.exit(0);
+}
+if (result.status !== 0) {
+ console.error(result.stderr || result.error?.message || 'git grep failed');
+ process.exit(2);
+}
+console.error(`Merge markers left in tracked files:\n${result.stdout}`);
+process.exit(1);
diff --git a/scripts/check-merge-markers.test.mjs b/scripts/check-merge-markers.test.mjs
new file mode 100644
index 00000000..b6361802
--- /dev/null
+++ b/scripts/check-merge-markers.test.mjs
@@ -0,0 +1,50 @@
+import { afterEach, expect, test } from 'bun:test';
+import { spawnSync } from 'node:child_process';
+import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const checker = fileURLToPath(new URL('./check-merge-markers.mjs', import.meta.url));
+const roots = [];
+
+afterEach(async () => {
+ await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
+});
+
+async function check(files, untracked = {}) {
+ const root = await mkdtemp(join(tmpdir(), 'kiln-merge-markers-'));
+ roots.push(root);
+ spawnSync('git', ['init', '-q'], { cwd: root });
+ for (const [path, text] of Object.entries({ ...files, ...untracked })) {
+ await mkdir(dirname(join(root, path)), { recursive: true });
+ await writeFile(join(root, path), text);
+ }
+ spawnSync('git', ['add', '--', ...Object.keys(files)], { cwd: root });
+ return spawnSync(process.execPath, [checker], { cwd: root, encoding: 'utf8' });
+}
+
+for (const marker of ['<<<<<<< ours', '||||||| base', '>>>>>>> theirs']) {
+ test(`fails on ${marker} and names the file and line`, async () => {
+ const result = await check({ 'CHANGELOG.md': `# Notes\n${marker}\n` });
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain(`CHANGELOG.md:2:${marker}`);
+ });
+}
+
+test('passes when a marker is not at the start of a line, or is only a separator', async () => {
+ const result = await check({
+ 'a.md':
+ 'Conflicts look like `<<<<<<< ours`.\n >>>>>>> indented\n=======\nHeading\n=======\n',
+ });
+ expect(result.stderr).toBe('');
+ expect(result.status).toBe(0);
+});
+
+test('leaves generated bundles and untracked files alone', async () => {
+ const result = await check(
+ { 'dist/cli.mjs': '<<<<<<< minified\n', 'a.md': 'clean\n' },
+ { 'scratch.md': '>>>>>>> local\n' },
+ );
+ expect(result.status).toBe(0);
+});