mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-06 07:38:47 +01:00
Skip git describe during server startup outside a Git checkout (#22493)
## Thinking Path > - Paperclip is an open source app for managing AI agents at work. > - At startup, the server determines the version it reports. > - A source checkout can supply this version through `git describe`. > - A build without Git metadata can supply the version through a build stamp. > - The version resolver used to start Git even when there was no checkout. > - This change checks for Git metadata before starting the process. > - Builds without a checkout can use the stamped version without starting Git. ## Linked Issues or Issue Description - Fixes #22044 - Refs #21122, which added a checkout guard to the server info probe. - Refs #10257, which added the build version stamp for images. ## What Changed - Check for `GIT_DIR` or a `.git` entry before the server version resolver runs `git describe`. A linked worktree can supply a `.git` file. - Use the existing fallback path when the check finds no Git metadata. - Test that the version resolver skips the Git process outside a checkout, and that checkout metadata and `GIT_DIR` allow the live version to take priority over a stamp. ## Verification - `pnpm install --frozen-lockfile` completed with pnpm 9.15.4. - `pnpm exec vitest run server/src/__tests__/version.test.ts server/src/__tests__/build-version.test.ts server/src/__tests__/build-commit.test.ts` passed all 35 tests. - `pnpm verify` passed its first 15 tests. Before interruption, the broad server group reported 237 failed test files and 22 failed test cases. Clean `master` reproduced every reported failure. These included a plugin SDK import error and Pi tests that received `EPERM` when creating their state directory. - I stopped both broad runs before a selected suite could call Docker. The broad runs have partial results. CI coverage is pending. ## Risks - The server now checks the filesystem for Git metadata before it starts the command. If metadata exists but Git cannot use it, the server uses the existing fallback path. ## Model Used OpenAI gpt-6.2-sol via Codex CLI, reasoning high, tools: shell, git, pnpm. I used npm to install the pinned pnpm version and CRW to search public GitHub pages. The context window size was unavailable in this session. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [ ] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge
This commit is contained in:
1 parent
56b3899af6
commit
364d3cab6c
2 files changed
+60
-5
No files matched your search
@@ -1,6 +1,15 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { parseGitDescribeVersion, resolveServerVersion } from "../version.js";
|
||||
|
||||
const gitDescribeProcess = vi.hoisted(() => vi.fn());
|
||||
vi.mock("node:child_process", () => ({ execFileSync: gitDescribeProcess }));
|
||||
|
||||
afterEach(() => {
|
||||
gitDescribeProcess.mockReset();
|
||||
vi.unstubAllEnvs();
|
||||
});
|
||||
|
||||
describe("parseGitDescribeVersion", () => {
|
||||
it("reports drift from the nearest release tag as a PEP 440 local version", () => {
|
||||
expect(parseGitDescribeVersion("v2026.626.0-58-g518fc71ce\n")).toBe(
|
||||
@@ -30,6 +39,39 @@ describe("parseGitDescribeVersion", () => {
|
||||
});
|
||||
|
||||
describe("resolveServerVersion", () => {
|
||||
it("uses the build stamp without spawning git outside a checkout", () => {
|
||||
vi.stubEnv("GIT_DIR", "");
|
||||
gitDescribeProcess.mockClear();
|
||||
|
||||
expect(resolveServerVersion({
|
||||
packageRoot: path.resolve("unpacked", "server"),
|
||||
pathExists: () => false,
|
||||
realpath: (value) => value,
|
||||
buildVersion: "v2026.1117.0-5-g012345678",
|
||||
packageVersion: "0.3.1",
|
||||
})).toBe("2026.1117.0+5.git.012345678");
|
||||
expect(gitDescribeProcess).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(["checkout metadata", "GIT_DIR"])("uses live git when %s is present", (metadata) => {
|
||||
const root = path.resolve("checkout", "server");
|
||||
vi.stubEnv("GIT_DIR", metadata === "GIT_DIR" ? "/custom/git-dir" : "");
|
||||
gitDescribeProcess.mockClear().mockReturnValue("v2026.1117.0-3-g012345678-dirty");
|
||||
|
||||
expect(resolveServerVersion({
|
||||
packageRoot: root,
|
||||
pathExists: (value) => metadata === "checkout metadata" && value === path.join(root, "..", ".git"),
|
||||
realpath: (value) => value,
|
||||
buildVersion: "v2026.1117.0-0-g012345678",
|
||||
packageVersion: "0.3.1",
|
||||
})).toBe("2026.1117.0+3.git.012345678.dirty");
|
||||
expect(gitDescribeProcess).toHaveBeenCalledExactlyOnceWith(
|
||||
"git",
|
||||
["describe", "--tags", "--match", "v*", "--long", "--dirty"],
|
||||
expect.objectContaining({ cwd: root }),
|
||||
);
|
||||
});
|
||||
|
||||
it("returns the parsed git-derived version when git describe succeeds", () => {
|
||||
expect(
|
||||
resolveServerVersion({
|
||||
|
||||
+17
-4
@@ -27,12 +27,23 @@ function defaultDebugLog(fields: Record<string, unknown>, message: string): void
|
||||
console.debug(message, fields);
|
||||
}
|
||||
|
||||
function defaultGitDescribeCommand(): string {
|
||||
function defaultGitDescribeCommand(
|
||||
root: string,
|
||||
pathExists: PathExists = existsSync,
|
||||
realpath: Realpath = realpathSync,
|
||||
): string {
|
||||
if (
|
||||
!process.env.GIT_DIR &&
|
||||
!hasGitMetadataBeforeNodeModulesBoundary(safeRealpath(root, realpath), pathExists)
|
||||
) {
|
||||
throw new Error("The package root is not inside a Git checkout");
|
||||
}
|
||||
|
||||
return execFileSync(
|
||||
"git",
|
||||
["describe", "--tags", "--match", "v*", "--long", "--dirty"],
|
||||
{
|
||||
cwd: packageRoot,
|
||||
cwd: root,
|
||||
encoding: "utf8",
|
||||
stdio: ["ignore", "pipe", "ignore"],
|
||||
timeout: 1500,
|
||||
@@ -160,7 +171,6 @@ export function resolveServerVersion(
|
||||
} = {},
|
||||
): string {
|
||||
const packageVersion = opts.packageVersion ?? pkg.version ?? "0.0.0";
|
||||
const gitDescribeCommand = opts.gitDescribeCommand ?? defaultGitDescribeCommand;
|
||||
const debugLog = opts.debugLog ?? defaultDebugLog;
|
||||
const resolvedPackageRoot = opts.packageRoot ?? packageRoot;
|
||||
|
||||
@@ -178,7 +188,10 @@ export function resolveServerVersion(
|
||||
}
|
||||
|
||||
try {
|
||||
const parsedVersion = parseGitDescribeVersion(gitDescribeCommand());
|
||||
const output = opts.gitDescribeCommand
|
||||
? opts.gitDescribeCommand()
|
||||
: defaultGitDescribeCommand(resolvedPackageRoot, opts.pathExists, opts.realpath);
|
||||
const parsedVersion = parseGitDescribeVersion(output);
|
||||
if (parsedVersion) return parsedVersion;
|
||||
|
||||
debugLog(
|
||||
|
||||
Reference in new issue
Block a user