

























@@ -55,10 +55,17 @@ describe("git commit resolution", () => {
5555const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
5656let resolveCommitHash: (typeof import("./git-commit.js"))["resolveCommitHash"];
5757let testing: (typeof import("./git-commit.js"))["testing"];
58+let repoHead: string;
58595960beforeAll(async () => {
6061vi.doUnmock("node:fs");
6162vi.doUnmock("node:module");
63+repoHead = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
64+cwd: repoRoot,
65+encoding: "utf-8",
66+})
67+.trim()
68+.slice(0, 7);
6269({ resolveCommitHash, testing } = await import("./git-commit.js"));
6370});
6471@@ -78,46 +85,19 @@ describe("git commit resolution", () => {
7885});
79868087it("resolves commit metadata from the caller module root instead of the caller cwd", async () => {
81-const repoHead = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
82-cwd: repoRoot,
83-encoding: "utf-8",
84-})
85-.trim()
86-.slice(0, 7);
87-8888const temp = await makeTempDir("git-commit-cwd");
8989const otherRepo = path.join(temp, "other");
90-await fs.mkdir(otherRepo, { recursive: true });
91-execFileSync("git", ["init", "-q"], { cwd: otherRepo });
92-await fs.writeFile(path.join(otherRepo, "note.txt"), "x\n", "utf-8");
93-execFileSync("git", ["add", "note.txt"], { cwd: otherRepo });
94-execFileSync(
95-"git",
96-["-c", "user.name=test", "-c", "user.email=test@example.com", "commit", "-q", "-m", "init"],
97-{ cwd: otherRepo },
98-);
99-const otherHead = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
100-cwd: otherRepo,
101-encoding: "utf-8",
102-})
103-.trim()
104-.slice(0, 7);
90+const otherCommit = "1234567890abcdef1234567890abcdef12345678";
91+await makeFakeGitRepo(otherRepo, { head: otherCommit });
1059210693const entryModuleUrl = pathToFileURL(path.join(repoRoot, "src", "entry.ts")).href;
10794vi.spyOn(process, "cwd").mockReturnValue(otherRepo);
1089510996expect(resolveCommitHash({ moduleUrl: entryModuleUrl })).toBe(repoHead);
110-expect(resolveCommitHash({ moduleUrl: entryModuleUrl })).not.toBe(otherHead);
97+expect(resolveCommitHash({ moduleUrl: entryModuleUrl })).not.toBe(otherCommit.slice(0, 7));
11198});
11299113100it("prefers live git metadata over stale build info in a real checkout", () => {
114-const repoHead = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
115-cwd: repoRoot,
116-encoding: "utf-8",
117-})
118-.trim()
119-.slice(0, 7);
120-121101const entryModuleUrl = pathToFileURL(path.join(repoRoot, "src", "entry.ts")).href;
122102123103expect(
@@ -176,13 +156,6 @@ describe("git commit resolution", () => {
176156});
177157178158it("treats invalid moduleUrl inputs as a fallback hint instead of throwing", () => {
179-const repoHead = execFileSync("git", ["rev-parse", "--short=7", "HEAD"], {
180-cwd: repoRoot,
181-encoding: "utf-8",
182-})
183-.trim()
184-.slice(0, 7);
185-186159expect(resolveCommitHash({ moduleUrl: "not-a-file-url", cwd: repoRoot, env: {} })).toBe(
187160repoHead,
188161);
@@ -191,15 +164,7 @@ describe("git commit resolution", () => {
191164it("does not walk out of the openclaw package into a host repo", async () => {
192165const temp = await makeTempDir("git-commit-package-boundary");
193166const hostRepo = path.join(temp, "host");
194-await fs.mkdir(hostRepo, { recursive: true });
195-execFileSync("git", ["init", "-q"], { cwd: hostRepo });
196-await fs.writeFile(path.join(hostRepo, "host.txt"), "x\n", "utf-8");
197-execFileSync("git", ["add", "host.txt"], { cwd: hostRepo });
198-execFileSync(
199-"git",
200-["-c", "user.name=test", "-c", "user.email=test@example.com", "commit", "-q", "-m", "init"],
201-{ cwd: hostRepo },
202-);
167+await makeFakeGitRepo(hostRepo, { head: "abcdef1234567890abcdef1234567890abcdef12" });
203168204169const packageRoot = path.join(hostRepo, "node_modules", "openclaw");
205170await fs.mkdir(path.join(packageRoot, "dist"), { recursive: true });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。