Skip to content

Commit 0790d9f

Browse files
committed
fix(plugins): accept singleton npm view metadata
1 parent 81ac4f3 commit 0790d9f

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Docs: https://docs.openclaw.ai
44

5+
## 2026.7.1-2
6+
7+
### Fixes
8+
9+
- **npm plugin updates:** accept singleton-array metadata from newer npm clients so tracked official plugins can install and update to correction releases. (#108336)
10+
511
## 2026.7.1-1
612

713
### Fixes

‎src/infra/install-source-utils.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createTrackedTempDirs } from "../test-utils/tracked-temp-dirs.js";
66
import {
77
packNpmSpecToArchive,
88
resolveArchiveSourcePath,
9+
resolveNpmSpecMetadata,
910
withTempDir,
1011
} from "./install-source-utils.js";
1112

@@ -183,6 +184,44 @@ describe("resolveArchiveSourcePath", () => {
183184
);
184185
});
185186

187+
describe("resolveNpmSpecMetadata", () => {
188+
const npmViewMetadata = {
189+
name: "@openclaw/codex",
190+
version: "2026.7.1-1",
191+
"dist.integrity": "sha512-test-integrity",
192+
"dist.shasum": "abc123",
193+
};
194+
195+
it.each([
196+
{ shape: "object", stdout: JSON.stringify(npmViewMetadata) },
197+
{ shape: "singleton array", stdout: JSON.stringify([npmViewMetadata]) },
198+
])("normalizes npm view $shape output", async ({ stdout }) => {
199+
mockPackCommandResult({ stdout });
200+
201+
await expect(resolveNpmSpecMetadata({ spec: "@openclaw/codex" })).resolves.toEqual({
202+
ok: true,
203+
metadata: {
204+
name: "@openclaw/codex",
205+
version: "2026.7.1-1",
206+
resolvedSpec: "@openclaw/[email protected]",
207+
integrity: "sha512-test-integrity",
208+
shasum: "abc123",
209+
},
210+
});
211+
});
212+
213+
it("rejects multi-version arrays instead of guessing an integrity", async () => {
214+
mockPackCommandResult({
215+
stdout: JSON.stringify([npmViewMetadata, { ...npmViewMetadata, version: "2026.7.1-2" }]),
216+
});
217+
218+
await expect(resolveNpmSpecMetadata({ spec: "@openclaw/codex" })).resolves.toEqual({
219+
ok: false,
220+
error: "npm view produced incomplete package metadata",
221+
});
222+
});
223+
});
224+
186225
describe("packNpmSpecToArchive", () => {
187226
it("packs spec and returns archive path using JSON output metadata", async () => {
188227
const cwd = await createFixtureDir();

‎src/infra/install-source-utils.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ export function createNpmMetadataEnv(
5858
}
5959

6060
function normalizeNpmViewMetadata(value: unknown): NpmSpecResolution | null {
61-
if (!value || typeof value !== "object") {
61+
// Newer npm clients wrap a single `npm view --json` result in an array.
62+
// Multiple matches stay ambiguous for integrity checks and fail closed.
63+
const entry = Array.isArray(value) && value.length === 1 ? value[0] : value;
64+
if (!isRecord(entry) || Array.isArray(entry)) {
6265
return null;
6366
}
64-
const rec = value as Record<string, unknown>;
67+
const rec = entry;
6568
const name = normalizeOptionalString(rec.name);
6669
const version = normalizeOptionalString(rec.version);
6770
const resolvedSpec = name && version ? `${name}@${version}` : undefined;

0 commit comments

Comments
 (0)