Keep copied source packages out of parent Git repositories

This commit is contained in:
gitea committed 2026-10-12 12:27:46 +08:00
1 parent 2654e1b870
commit fa304ca4dc
4 files changed
+33 -4

No files matched your search

+10 -1
View File
@@ -2,9 +2,18 @@ import { describe, expect, test } from "bun:test";
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { homebrewFormulaPrefix, installHomebrewSkill } from "./update.js";
import { handleUpdateCommand, homebrewFormulaPrefix, installHomebrewSkill } from "./update.js";
describe("Homebrew skill refresh", () => {
test("a copied source package cannot update its parent application's Git repository", async () => {
const dir = mkdtempSync(join(tmpdir(), "seal-source-update-test-"));
try {
await expect(handleUpdateCommand({ appRoot: dir, entryFile: join(dir, "src", "cli.ts") }))
.rejects.toMatchObject({ exitCode: 13 });
expect(existsSync(join(dir, "bun.lock"))).toBe(false);
} finally { rmSync(dir, { recursive: true, force: true }); }
});
test("uses the upgraded formula executable even when PATH contains an older standalone CLI", () => {
const dir = mkdtempSync(join(tmpdir(), "seal-brew-skill-test-"));
const originalPath = process.env.PATH;
+5 -1
View File
@@ -1,4 +1,4 @@
import { chmodSync, mkdirSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
import { chmodSync, existsSync, mkdirSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
import { basename, dirname, isAbsolute, join, relative } from "node:path";
import { spawn, spawnSync } from "node:child_process";
import { isCompiledBinary } from "../../core/runtime.js";
@@ -131,6 +131,10 @@ export async function handleUpdateCommand(runtime: CliRuntime, options: UpdateOp
return;
}
// Source updates must operate on this package's checkout, never a parent app's repository.
if (!existsSync(join(runtime.appRoot, ".git"))) {
throw validationError("当前源码安装目录不是 seal-use 的 Git 工作区。请使用发行版二进制,或从 seal-use 仓库通过 npm link 安装。");
}
try {
runCommand("git", ["-C", runtime.appRoot, "pull", "--ff-only"]);
} catch (err) {
+11 -1
View File
@@ -1,6 +1,6 @@
import { describe, expect, test } from "bun:test";
import { spawnSync } from "node:child_process";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { copyFileSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, resolve } from "node:path";
import { formatDevVersion, parseGitDescribe, resolveVersionInfo } from "./version.js";
@@ -84,6 +84,16 @@ describe("resolveVersionInfo configuration modes", () => {
expect(resolveVersionInfo({ env: emptyBuildEnv })).toEqual(expected);
// Explicit cwd remains available for callers/tests that intentionally inspect another checkout.
expect(resolveVersionInfo({ env: emptyBuildEnv, cwd: dir }).git?.baseVersion).toBe("99.99.99");
const copy = join(dir, "node_modules", "seal-use");
mkdirSync(join(copy, "src"), { recursive: true });
copyFileSync(join(repoRoot, "src", "version.ts"), join(copy, "src", "version.ts"));
copyFileSync(join(repoRoot, "package.json"), join(copy, "package.json"));
const child = spawnSync(process.execPath, ["-e", `import { VERSION_INFO } from ${JSON.stringify(join(copy, "src", "version.ts"))}; console.log(JSON.stringify(VERSION_INFO))`], {
cwd: dir, encoding: "utf8", env: { ...process.env, ...emptyBuildEnv }
});
expect(child.status).toBe(0);
expect(JSON.parse(child.stdout)).toMatchObject({ version: expect.stringContaining("+local"), channel: "dev" });
expect(JSON.parse(child.stdout).git).toBeUndefined();
} finally {
process.chdir(originalCwd);
rmSync(dir, { recursive: true, force: true });
+7 -1
View File
@@ -1,6 +1,7 @@
import { spawnSync } from "node:child_process";
import { dirname, resolve } from "node:path";
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { existsSync } from "node:fs";
import packageJson from "../package.json" with { type: "json" };
export interface GitBuildInfo {
@@ -124,6 +125,11 @@ export function resolveVersionInfo(options?: {
// 3. Dynamic resolution from git repository in dev mode
try {
// A copied npm package has no checkout. Git would otherwise walk up into
// the consuming application's repository and report its version as ours.
if (options?.cwd === undefined && !existsSync(join(cwd, ".git"))) {
return { name: "seal-use", version: `${packageJson.version}-dev.0+local`, channel: "dev", isRelease: false };
}
const res = spawnSync("git", ["describe", "--tags", "--long", "--dirty", "--always"], {
cwd,
encoding: "utf8",