Skip to content

Commit 9e98229

Browse files
authored
fix(plugins): report Git commit updates when package version is unchanged (#128841)
1 parent b91f1ea commit 9e98229

4 files changed

Lines changed: 53 additions & 43 deletions

File tree

‎src/plugins/update-attempt.ts‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,42 @@ type PluginUpdateAttemptResult =
236236
| { kind: "exception"; message: string }
237237
| ({ kind: "result"; result: PluginUpdateInstallResult } & PluginUpdateAttemptState);
238238

239+
function isPluginUpdateUnchanged(
240+
params: Parameters<typeof buildPluginUpdateVersionOutcome>[0],
241+
): boolean {
242+
const { record, result, currentVersion, nextVersion } = params;
243+
const nextCommit = record.source === "git" && "git" in result ? result.git.commit : undefined;
244+
return record.gitCommit && nextCommit
245+
? record.gitCommit === nextCommit
246+
: Boolean(currentVersion && nextVersion && currentVersion === nextVersion);
247+
}
248+
249+
export function buildPluginUpdateVersionOutcome(params: {
250+
pluginId: string;
251+
record: UpdatablePluginInstallRecord;
252+
result: PluginUpdateSuccess;
253+
currentVersion?: string;
254+
nextVersion?: string;
255+
channelFallbackSuffix: string;
256+
channelFallback?: PluginUpdateChannelFallback;
257+
}): PluginUpdateOutcome {
258+
const currentLabel = params.currentVersion ?? "unknown";
259+
const unchanged = isPluginUpdateUnchanged(params);
260+
const verb = isPackageVersionDowngrade(params.currentVersion, params.nextVersion)
261+
? "Downgraded"
262+
: "Updated";
263+
return {
264+
pluginId: params.pluginId,
265+
status: unchanged ? "unchanged" : "updated",
266+
currentVersion: params.currentVersion,
267+
nextVersion: params.nextVersion,
268+
message: unchanged
269+
? `${params.pluginId} already at ${currentLabel}.${params.channelFallbackSuffix}`
270+
: `${verb} ${params.pluginId}: ${currentLabel} -> ${params.nextVersion ?? "unknown"}.${params.channelFallbackSuffix}`,
271+
...(params.channelFallback ? { channelFallback: params.channelFallback } : {}),
272+
};
273+
}
274+
239275
export async function buildDryRunPluginUpdateOutcome(params: {
240276
pluginId: string;
241277
record: UpdatablePluginInstallRecord;
@@ -268,16 +304,7 @@ export async function buildDryRunPluginUpdateOutcome(params: {
268304
: undefined);
269305
const nextVersion = resolvedProbeVersion ?? "unknown";
270306
const currentLabel = params.currentVersion ?? "unknown";
271-
const gitProbe =
272-
params.record.source === "git" && "git" in params.result ? params.result.git : undefined;
273-
const unchanged =
274-
params.record.source === "git" && params.record.gitCommit && gitProbe?.commit
275-
? params.record.gitCommit === gitProbe.commit
276-
: Boolean(
277-
params.currentVersion &&
278-
resolvedProbeVersion &&
279-
params.currentVersion === resolvedProbeVersion,
280-
);
307+
const unchanged = isPluginUpdateUnchanged({ ...params, nextVersion: resolvedProbeVersion });
281308
const newerExactPinnedDefaultLine =
282309
unchanged &&
283310
params.record.source === "npm" &&

‎src/plugins/update-claw-lifecycle.ts‎

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import { parseClawHubPluginSpec } from "../infra/clawhub-spec.js";
2-
import { isPackageVersionDowngrade } from "../infra/package-update-utils.js";
32
import { markClawPackageIndependentlyOwned } from "../state/claw-package-adoption.js";
43
import { withClawPackageLifecycleLease } from "../state/claw-package-lifecycle-lease.js";
54
import type { ClawHubRiskAcknowledgementRequest } from "./clawhub.js";
65
import { installPluginFromNpmSpec } from "./install.js";
7-
import type { PluginUpdateChannelFallback, PluginUpdateOutcome } from "./update-source.js";
86

97
type ClawHubInstallRecord = {
108
source?: string;
@@ -42,33 +40,6 @@ export function resolveClawHubRiskAcknowledgementOptions(params: {
4240
};
4341
}
4442

45-
export function buildPluginUpdateVersionOutcome(params: {
46-
pluginId: string;
47-
currentVersion?: string;
48-
nextVersion?: string;
49-
channelFallbackSuffix: string;
50-
channelFallback?: PluginUpdateChannelFallback;
51-
}): PluginUpdateOutcome {
52-
const currentLabel = params.currentVersion ?? "unknown";
53-
const nextLabel = params.nextVersion ?? "unknown";
54-
const unchanged = Boolean(
55-
params.currentVersion && params.nextVersion && params.currentVersion === params.nextVersion,
56-
);
57-
const verb = isPackageVersionDowngrade(params.currentVersion, params.nextVersion)
58-
? "Downgraded"
59-
: "Updated";
60-
return {
61-
pluginId: params.pluginId,
62-
status: unchanged ? "unchanged" : "updated",
63-
currentVersion: params.currentVersion,
64-
nextVersion: params.nextVersion,
65-
message: unchanged
66-
? `${params.pluginId} already at ${currentLabel}.${params.channelFallbackSuffix}`
67-
: `${verb} ${params.pluginId}: ${currentLabel} -> ${nextLabel}.${params.channelFallbackSuffix}`,
68-
...(params.channelFallback ? { channelFallback: params.channelFallback } : {}),
69-
};
70-
}
71-
7243
export async function runPluginUpdateWithClawHubLease<T>(params: {
7344
pluginId: string;
7445
clawhubPackage?: string;

‎src/plugins/update-installed.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { auditDeclaredOpenClawHostDependency } from "./plugin-peer-link.js";
2828
import {
2929
buildClawHubTrustSkippedOutcome,
3030
buildDryRunPluginUpdateOutcome,
31+
buildPluginUpdateVersionOutcome,
3132
formatClawHubInstallFailure,
3233
formatGitInstallFailure,
3334
formatMarketplaceInstallFailure,
@@ -42,7 +43,6 @@ import {
4243
type NpmPluginUpdateSuccess,
4344
} from "./update-attempt.js";
4445
import {
45-
buildPluginUpdateVersionOutcome,
4646
createTrackedNpmUpdateInstaller,
4747
resolveClawHubRiskAcknowledgementOptions,
4848
resolveRecordedClawHubPackage,
@@ -701,6 +701,8 @@ export async function updateNpmInstalledPlugins(params: {
701701
outcomes.push(
702702
buildPluginUpdateVersionOutcome({
703703
pluginId,
704+
record,
705+
result,
704706
currentVersion,
705707
nextVersion,
706708
channelFallbackSuffix,

‎src/plugins/update.test.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,10 +4665,11 @@ describe("updateNpmInstalledPlugins", () => {
46654665
});
46664666

46674667
it("updates git installs and records resolved commit metadata", async () => {
4668+
const installPath = createInstalledPackageDir({ name: "demo", version: "1.3.0" });
46684669
installPluginFromGitSpecMock.mockResolvedValue({
46694670
ok: true,
46704671
pluginId: "demo",
4671-
targetDir: "/tmp/demo",
4672+
targetDir: installPath,
46724673
version: "1.3.0",
46734674
extensions: ["index.ts"],
46744675
git: {
@@ -4682,7 +4683,7 @@ describe("updateNpmInstalledPlugins", () => {
46824683
const result = await updatePlugin(
46834684
createGitInstallConfig({
46844685
pluginId: "demo",
4685-
installPath: "/tmp/demo",
4686+
installPath,
46864687
spec: "git:github.com/acme/demo@main",
46874688
commit: "abc123",
46884689
}),
@@ -4693,10 +4694,19 @@ describe("updateNpmInstalledPlugins", () => {
46934694
expect(gitInstallCall()?.expectedPluginId).toBe("demo");
46944695
expect(gitInstallCall()?.mode).toBe("update");
46954696
expect(result.changed).toBe(true);
4697+
expect(result.outcomes).toEqual([
4698+
{
4699+
pluginId: "demo",
4700+
status: "updated",
4701+
currentVersion: "1.3.0",
4702+
nextVersion: "1.3.0",
4703+
message: "Updated demo: 1.3.0 -> 1.3.0.",
4704+
},
4705+
]);
46964706
expectRecordFields(result.config.plugins?.installs?.demo, {
46974707
source: "git",
46984708
spec: "git:github.com/acme/demo@main",
4699-
installPath: "/tmp/demo",
4709+
installPath,
47004710
version: "1.3.0",
47014711
gitUrl: "https://github.com/acme/demo.git",
47024712
gitRef: "main",

0 commit comments

Comments
 (0)