Compare commits

..

1 Commits

Author SHA1 Message Date
adevwithpurpose
6bc9dad0ce fix(cliproxy): read os.platform()/os.arch() at runtime in binaryManager platform detection (#10244)
detectPlatform()/detectArch() read the module's process.platform/process.arch,
which Turbopack `next build` (run only on Linux) constant-folds, pruning every
Windows/arm64 branch from the published npm artifact — so the embedded CLIProxyAPI
installer downloads the Linux ELF binary on Windows. Switch to runtime os.platform()/
os.arch() calls (the repo's established anti-fold pattern) so the Windows/ARM branches
survive any build machine. Add a regression guard mocking os.platform()/os.arch() to
win32/arm64 asserting the Windows/ARM path is reachable — RED before, GREEN after.
2026-08-15 11:34:33 -03:00
6 changed files with 22 additions and 67 deletions

View File

@@ -0,0 +1 @@
- **fix(cliproxy):** read platform/arch at runtime via `os.platform()`/`os.arch()` in `binaryManager` so the embedded installer selects the Windows/ARM assets even when the release bundle is built on a Linux runner (fixes #10244)

View File

@@ -1 +0,0 @@
- fix(providers): GitLab Duo falls back to the public Code Suggestions endpoint when direct_access returns 401 (#10365)

View File

@@ -583,20 +583,10 @@ export class GitlabExecutor extends BaseExecutor {
}
if (response.status === 401) {
if (input.log) {
input.log.warn(
"GITLAB-DUO",
"direct_access exchange rejected (401); falling back to public completions endpoint"
);
}
return {
target: {
mode: "monolith",
url: endpoints.publicCompletionsUrl,
headers: buildMonolithHeaders(credentials.accessToken || null),
},
target: null,
credentials,
errorResponse: null,
errorResponse: toOpenAIError(401, "GitLab Duo direct access token request was rejected"),
};
}

View File

@@ -16,7 +16,7 @@ type Platform = "linux" | "darwin" | "windows" | "freebsd";
type Arch = "amd64" | "arm64";
function detectPlatform(): Platform {
const p = process.platform;
const p = os.platform();
if (p === "linux") return "linux";
if (p === "darwin") return "darwin";
if (p === "win32") return "windows";
@@ -24,7 +24,7 @@ function detectPlatform(): Platform {
}
function detectArch(): Arch {
const a = process.arch;
const a = os.arch();
if (a === "x64") return "amd64";
if (a === "arm64") return "arm64";
return "amd64";

View File

@@ -1,4 +1,4 @@
import { describe, it, afterEach, after } from "node:test";
import { describe, it, afterEach, after, mock } from "node:test";
import assert from "node:assert/strict";
import path from "node:path";
import fs from "node:fs";
@@ -63,6 +63,22 @@ describe("binaryManager", () => {
assert.ok(["linux", "darwin", "windows"].includes(platform));
assert.ok(["amd64", "arm64"].includes(arch));
});
it("should read platform/arch at runtime from os (anti build-folding guard) (#10244)", () => {
// Regression guard for #10244/#10293: detectPlatform/detectArch must read
// os.platform()/os.arch() at call time, NOT the build-machine foldable
// process.platform/process.arch constants. Turbopack `next build` running
// on Linux constant-folds `process.platform` and prunes every Windows/arm64
// branch from the published npm artifact. Simulate a Windows arm64 host via
// the runtime os.* functions; the Windows/arm64 branch must be reachable.
mock.method(os, "platform", () => "win32");
mock.method(os, "arch", () => "arm64");
assert.deepEqual(mod.getTargetPlatform(), { platform: "windows", arch: "arm64" });
assert.equal(
mod.getAssetName(),
"CLIProxyAPI_{version}_windows_arm64.zip"
);
});
});
describe("getCurrentBinaryPath", () => {

View File

@@ -261,54 +261,3 @@ test("GitlabExecutor falls back to the public Code Suggestions endpoint when dir
globalThis.fetch = originalFetch;
}
});
// #10365: a 401 from the direct_access exchange must ALSO fall back to the public
// Code Suggestions completions endpoint (same resilience as the 403-disabled case
// above), instead of surfacing an opaque 401 token error with no fallback.
test("GitlabExecutor falls back to the public Code Suggestions endpoint when direct_access returns 401", async () => {
const executor = getExecutor("gitlab-duo") as GitlabExecutor;
const originalFetch = globalThis.fetch;
const calls: string[] = [];
globalThis.fetch = async (url) => {
calls.push(String(url));
if (String(url) === "https://gitlab.example.com/api/v4/code_suggestions/direct_access") {
return jsonResponse({ error: "invalid_token" }, 401);
}
return jsonResponse({
model: { name: "code-gecko" },
choices: [{ text: "monolith fallback works" }],
});
};
try {
const result = await executor.execute({
model: "gitlab-duo-code-suggestions",
body: {
messages: [{ role: "user", content: "Say hello" }],
},
stream: false,
credentials: {
accessToken: "oauth-access",
providerSpecificData: {
baseUrl: "https://gitlab.example.com",
},
},
signal: AbortSignal.timeout(10_000),
log: null,
});
assert.deepEqual(calls, [
"https://gitlab.example.com/api/v4/code_suggestions/direct_access",
"https://gitlab.example.com/api/v4/code_suggestions/completions",
]);
const body = (await result.response.json()) as any;
assert.equal(body.model, "code-gecko");
assert.match(body.choices[0].message.content, /monolith fallback works/i);
} finally {
globalThis.fetch = originalFetch;
}
});