mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-27 09:21:35 +07:00
refactor: harden generated-file guards and provider ids
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -5,6 +6,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
findConflictMarkerLines,
|
||||
findConflictMarkersInFiles,
|
||||
listTrackedFiles,
|
||||
} from "../../scripts/check-no-conflict-markers.mjs";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
@@ -21,6 +23,13 @@ function makeTempDir(): string {
|
||||
return dir;
|
||||
}
|
||||
|
||||
function git(cwd: string, ...args: string[]): string {
|
||||
return execFileSync("git", args, {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
}).trim();
|
||||
}
|
||||
|
||||
describe("check-no-conflict-markers", () => {
|
||||
it("finds git conflict markers at the start of lines", () => {
|
||||
expect(
|
||||
@@ -61,4 +70,34 @@ describe("check-no-conflict-markers", () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("finds conflict markers in tracked script files", () => {
|
||||
const rootDir = makeTempDir();
|
||||
git(rootDir, "init", "-q");
|
||||
git(rootDir, "config", "user.email", "test@example.com");
|
||||
git(rootDir, "config", "user.name", "Test User");
|
||||
|
||||
const scriptFile = path.join(rootDir, "scripts", "generate-bundled-plugin-metadata.mjs");
|
||||
fs.mkdirSync(path.dirname(scriptFile), { recursive: true });
|
||||
fs.writeFileSync(
|
||||
scriptFile,
|
||||
[
|
||||
"<<<<<<< HEAD",
|
||||
'const left = "left";',
|
||||
"=======",
|
||||
'const right = "right";',
|
||||
">>>>>>> branch",
|
||||
].join("\n"),
|
||||
);
|
||||
git(rootDir, "add", "scripts/generate-bundled-plugin-metadata.mjs");
|
||||
|
||||
const violations = findConflictMarkersInFiles(listTrackedFiles(rootDir));
|
||||
|
||||
expect(violations).toEqual([
|
||||
{
|
||||
filePath: scriptFile,
|
||||
lines: [1, 3, 5],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -99,4 +99,20 @@ describe("scripts/committer", () => {
|
||||
expect(committedPaths(repo)).toEqual(testCase.expected);
|
||||
}
|
||||
});
|
||||
|
||||
it("commits changelog-only changes without pulling in unrelated dirty files", () => {
|
||||
const repo = createRepo();
|
||||
writeRepoFile(repo, "CHANGELOG.md", "initial\n");
|
||||
writeRepoFile(repo, "unrelated.ts", "export const ok = true;\n");
|
||||
git(repo, "add", "CHANGELOG.md", "unrelated.ts");
|
||||
git(repo, "commit", "-qm", "seed extra files");
|
||||
|
||||
writeRepoFile(repo, "CHANGELOG.md", "breaking note\n");
|
||||
writeRepoFile(repo, "unrelated.ts", "<<<<<<< HEAD\nleft\n=======\nright\n>>>>>>> branch\n");
|
||||
|
||||
commitWithHelper(repo, "docs(changelog): note breaking change", "CHANGELOG.md");
|
||||
|
||||
expect(committedPaths(repo)).toEqual(["CHANGELOG.md"]);
|
||||
expect(git(repo, "status", "--short")).toContain("M unrelated.ts");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user