Skip to content

Commit 8062e86

Browse files
committed
fix(codex): 校验原生发布中的平台安装包
仅在当前平台存在有效摘要的安装包及校验清单,或兼容 npm 归档时报告渠道版本。 覆盖六种平台架构、缺失资源、摘要无效及兼容归档,避免再次提示无法安装的版本。 80 个相关测试和变更范围检查通过,没有执行实际更新。
1 parent b6be1ad commit 8062e86

2 files changed

Lines changed: 130 additions & 3 deletions

File tree

‎apps/server/src/provider/Drivers/CodexDriver.test.ts‎

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,86 @@ it.layer(layerTest)("CodexDriver", (it) => {
388388
{ name: "an unavailable native channel", tag: "rust-v0.163.0", status: 503, expected: null },
389389
{ name: "malformed native metadata", tag: "not-a-version", status: 200, expected: null },
390390
{ name: "a newer native release", tag: "rust-v0.164.0", status: 200, expected: "0.164.0" },
391+
{
392+
name: "missing platform assets",
393+
tag: "rust-v0.163.0",
394+
status: 200,
395+
expected: null,
396+
assets: [],
397+
},
398+
{
399+
name: "a missing checksum manifest",
400+
tag: "rust-v0.163.0",
401+
status: 200,
402+
expected: null,
403+
assets: ["codex-package-aarch64-apple-darwin.tar.gz"],
404+
},
405+
{
406+
name: "an invalid asset digest",
407+
tag: "rust-v0.163.0",
408+
status: 200,
409+
expected: null,
410+
digest: "invalid",
411+
},
412+
{
413+
name: "the legacy npm archive",
414+
tag: "rust-v0.163.0",
415+
status: 200,
416+
expected: "0.163.0",
417+
assets: ["codex-npm-darwin-arm64-0.163.0.tgz"],
418+
},
419+
{
420+
name: "Linux x64 packages",
421+
tag: "rust-v0.163.0",
422+
status: 200,
423+
expected: "0.163.0",
424+
platform: "linux" as const,
425+
architecture: "x64" as const,
426+
assets: ["codex-package-x86_64-unknown-linux-musl.tar.gz", "codex-package_SHA256SUMS"],
427+
},
428+
{
429+
name: "Linux arm64 packages",
430+
tag: "rust-v0.163.0",
431+
status: 200,
432+
expected: "0.163.0",
433+
platform: "linux" as const,
434+
architecture: "arm64" as const,
435+
assets: ["codex-package-aarch64-unknown-linux-musl.tar.gz", "codex-package_SHA256SUMS"],
436+
},
437+
{
438+
name: "Windows x64 packages",
439+
tag: "rust-v0.163.0",
440+
status: 200,
441+
expected: "0.163.0",
442+
platform: "win32" as const,
443+
architecture: "x64" as const,
444+
assets: ["codex-package-x86_64-pc-windows-msvc.tar.gz", "codex-package_SHA256SUMS"],
445+
},
446+
{
447+
name: "Windows arm64 packages",
448+
tag: "rust-v0.163.0",
449+
status: 200,
450+
expected: "0.163.0",
451+
platform: "win32" as const,
452+
architecture: "arm64" as const,
453+
assets: ["codex-package-aarch64-pc-windows-msvc.tar.gz", "codex-package_SHA256SUMS"],
454+
},
455+
{
456+
name: "Intel macOS packages",
457+
tag: "rust-v0.163.0",
458+
status: 200,
459+
expected: "0.163.0",
460+
platform: "darwin" as const,
461+
architecture: "x64" as const,
462+
assets: ["codex-package-x86_64-apple-darwin.tar.gz", "codex-package_SHA256SUMS"],
463+
},
464+
{
465+
name: "assets for another platform",
466+
tag: "rust-v0.163.0",
467+
status: 200,
468+
expected: null,
469+
assets: ["codex-package-x86_64-unknown-linux-musl.tar.gz", "codex-package_SHA256SUMS"],
470+
},
391471
{
392472
name: "an explicit release",
393473
tag: "rust-v0.164.0",
@@ -421,7 +501,21 @@ it.layer(layerTest)("CodexDriver", (it) => {
421501
request,
422502
request.url.includes("registry.npmjs.org")
423503
? Response.json({ version: "0.164.0" })
424-
: Response.json({ tag_name: fixture.tag }, { status: fixture.status }),
504+
: Response.json(
505+
{
506+
tag_name: fixture.tag,
507+
assets: (
508+
fixture.assets ?? [
509+
"codex-package-aarch64-apple-darwin.tar.gz",
510+
"codex-package_SHA256SUMS",
511+
]
512+
).map((name) => ({
513+
name,
514+
digest: fixture.digest ?? `sha256:${"a".repeat(64)}`,
515+
})),
516+
},
517+
{ status: fixture.status },
518+
),
425519
);
426520
}),
427521
);
@@ -436,6 +530,8 @@ it.layer(layerTest)("CodexDriver", (it) => {
436530
expect(requests).toEqual([]);
437531
const latest = yield* resolveLatestProviderVersion(capabilities).pipe(
438532
Effect.provideService(HttpClient.HttpClient, http),
533+
Effect.provideService(HostProcess.Platform, fixture.platform ?? "darwin"),
534+
Effect.provideService(HostProcess.Architecture, fixture.architecture ?? "arm64"),
439535
);
440536
expect(latest).toBe(fixture.expected);
441537
expect(requests).toEqual(

‎apps/server/src/provider/Drivers/CodexDriver.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ function isCodexStandaloneCommandPath(commandPath: string): boolean {
6565
return normalizeCommandPath(commandPath).includes("/packages/standalone/");
6666
}
6767

68-
const CodexNativeReleaseMetadata = Schema.Struct({ tag_name: Schema.String });
68+
const CodexNativeReleaseMetadata = Schema.Struct({
69+
tag_name: Schema.String,
70+
assets: Schema.Array(
71+
Schema.Struct({ name: Schema.String, digest: Schema.optional(Schema.NullOr(Schema.String)) }),
72+
),
73+
});
6974

7075
/** The standalone installer consumes this channel, whose rollout can lag npm. */
7176
const lookupCodexNativeVersion = Effect.gen(function* () {
@@ -84,7 +89,33 @@ const lookupCodexNativeVersion = Effect.gen(function* () {
8489
const metadata = yield* response.json.pipe(
8590
Effect.flatMap(Schema.decodeUnknownEffect(CodexNativeReleaseMetadata)),
8691
);
87-
return /^(?:rust-v|v)?(\d+\.\d+\.\d+)$/.exec(metadata.tag_name)?.[1] ?? null;
92+
const version = /^rust-v(\d+\.\d+\.\d+)$/.exec(metadata.tag_name)?.[1];
93+
if (!version) return null;
94+
const platform = yield* HostProcess.Platform;
95+
const architecture = yield* HostProcess.Architecture;
96+
const targetArchitecture =
97+
architecture === "arm64" ? "aarch64" : architecture === "x64" ? "x86_64" : null;
98+
const targetPlatform =
99+
platform === "darwin"
100+
? "apple-darwin"
101+
: platform === "linux"
102+
? "unknown-linux-musl"
103+
: platform === "win32"
104+
? "pc-windows-msvc"
105+
: null;
106+
if (!targetArchitecture || !targetPlatform) return null;
107+
// The native installer accepts a package plus checksums, or a legacy platform
108+
// npm archive. Both layouts require asset SHA-256 metadata, not just a tag.
109+
const assets = new Set(
110+
metadata.assets
111+
.filter((asset) => /^sha256:[0-9a-fA-F]{64}$/.test(asset.digest ?? ""))
112+
.map((asset) => asset.name),
113+
);
114+
const hasPackage =
115+
assets.has(`codex-package-${targetArchitecture}-${targetPlatform}.tar.gz`) &&
116+
assets.has("codex-package_SHA256SUMS");
117+
const hasLegacyPackage = assets.has(`codex-npm-${platform}-${architecture}-${version}.tgz`);
118+
return hasPackage || hasLegacyPackage ? version : null;
88119
}).pipe(
89120
Effect.timeoutOption("4 seconds"),
90121
Effect.map(Option.getOrNull),

0 commit comments

Comments
 (0)