Skip to content

Commit d54fe57

Browse files
authored
Merge branch 'main' into fix/ollama-cloud-tool-call-arguments-string
2 parents 0564c6d + 47d3d1b commit d54fe57

7 files changed

Lines changed: 183 additions & 6 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ jobs:
251251
],
252252
};
253253
});
254-
255254
const createMatrix = (include) => ({ include });
256255
const outputPath = process.env.GITHUB_OUTPUT;
257256
const isCanonicalRepository = process.env.OPENCLAW_CI_REPOSITORY === "openclaw/openclaw";
@@ -285,6 +284,7 @@ jobs:
285284
if (runNodeFull) {
286285
checksFastCoreTasks.push(
287286
{ check_name: "checks-fast-bundled-protocol", runtime: "node", task: "bundled-protocol" },
287+
{ check_name: "QA Smoke CI", runtime: "node", task: "qa-smoke-ci" },
288288
{ check_name: "checks-fast-bun-launcher", runtime: "bun", task: "bun-launcher" },
289289
);
290290
} else {
@@ -922,6 +922,26 @@ jobs:
922922
pnpm test:bundled
923923
pnpm protocol:check
924924
;;
925+
qa-smoke-ci)
926+
output_dir=".artifacts/qa-e2e/smoke-ci-profile"
927+
export OPENCLAW_BUILD_PRIVATE_QA=1
928+
export OPENCLAW_ENABLE_PRIVATE_QA_CLI=1
929+
export OPENCLAW_DISABLE_BUNDLED_PLUGINS=0
930+
export OPENCLAW_QA_REDACT_PUBLIC_METADATA=1
931+
export OPENCLAW_QA_TRANSPORT_READY_TIMEOUT_MS=180000
932+
NODE_OPTIONS=--max-old-space-size=8192 node scripts/build-all.mjs qaRuntime
933+
qa_exit_code=0
934+
pnpm openclaw qa run \
935+
--repo-root . \
936+
--qa-profile smoke-ci \
937+
--concurrency 8 \
938+
--output-dir "$output_dir" || qa_exit_code=$?
939+
echo "QA smoke profile evidence: \`${output_dir}\`" >> "$GITHUB_STEP_SUMMARY"
940+
if [ "$qa_exit_code" -ne 0 ]; then
941+
echo "::error title=QA smoke profile failed::smoke-ci exited ${qa_exit_code}; evidence upload will still run"
942+
exit "$qa_exit_code"
943+
fi
944+
;;
925945
contracts-plugins-ci-routing)
926946
pnpm test:contracts:plugins
927947
pnpm test src/commands/status.scan-result.test.ts src/scripts/ci-changed-scope.test.ts test/scripts/changed-lanes.test.ts test/scripts/ci-workflow-guards.test.ts test/scripts/run-vitest.test.ts test/scripts/test-projects.test.ts
@@ -938,6 +958,15 @@ jobs:
938958
;;
939959
esac
940960
961+
- name: Upload QA smoke profile evidence
962+
if: always() && matrix.task == 'qa-smoke-ci'
963+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
964+
with:
965+
name: qa-smoke-profile-${{ github.run_id }}-${{ github.run_attempt }}
966+
path: .artifacts/qa-e2e/smoke-ci-profile/
967+
if-no-files-found: warn
968+
retention-days: 7
969+
941970
checks-fast-plugin-contracts-shard:
942971
permissions:
943972
contents: read

‎docs/ci.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ or an explicit manual dispatch.
3030
| `security-fast` | Private key detection, changed-workflow audit via `zizmor`, and production lockfile audit | Always on non-draft pushes and PRs |
3131
| `check-dependencies` | Production Knip dependency-only pass plus the unused-file allowlist guard | Node-relevant changes |
3232
| `build-artifacts` | Build `dist/`, Control UI, built-CLI smoke checks, embedded built-artifact checks, and reusable artifacts | Node-relevant changes |
33-
| `checks-fast-core` | Fast Linux correctness lanes such as bundled, protocol, and CI-routing checks | Node-relevant changes |
33+
| `checks-fast-core` | Fast Linux correctness lanes such as bundled, protocol, QA Smoke CI, and CI-routing checks | Node-relevant changes |
3434
| `checks-fast-contracts-plugins-*` | Two sharded plugin contract checks | Node-relevant changes |
3535
| `checks-fast-contracts-channels-*` | Two sharded channel contract checks | Node-relevant changes |
3636
| `checks-node-core-*` | Core Node test shards, excluding channel, bundled, contract, and extension lanes | Node-relevant changes |

‎extensions/xai/xai-oauth.test.ts‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,67 @@ describe("xAI OAuth", () => {
211211
expect(refreshed.expires).toBe(121_000);
212212
});
213213

214+
it("rediscovers the current token endpoint for stale xAI OAuth credentials", async () => {
215+
const fetchImpl = vi.fn<typeof fetch>(async (url, init) => {
216+
if (requestUrl(url) === XAI_OAUTH_DISCOVERY_URL) {
217+
expect(init?.method).toBeUndefined();
218+
return jsonResponse({
219+
authorization_endpoint: "https://auth.x.ai/oauth2/authorize",
220+
token_endpoint: "https://auth.x.ai/oauth2/token",
221+
});
222+
}
223+
expect(requestUrl(url)).toBe("https://auth.x.ai/oauth2/token");
224+
expect(init?.method).toBe("POST");
225+
expect(requireStringBody(init)).toContain("refresh_token=refresh-1");
226+
return jsonResponse({
227+
access_token: "access-2",
228+
refresh_token: "refresh-2",
229+
expires_in: 120,
230+
});
231+
});
232+
const credential = {
233+
type: "oauth",
234+
provider: "xai",
235+
access: "access-1",
236+
refresh: "refresh-1",
237+
expires: 100,
238+
tokenEndpoint: "https://auth.x.ai/oauth/token",
239+
} satisfies OAuthCredential & { tokenEndpoint: string };
240+
241+
const refreshed = await refreshXaiOAuthCredential(credential, { fetchImpl, now: () => 1_000 });
242+
243+
expect(fetchImpl).toHaveBeenCalledTimes(2);
244+
expect(fetchImpl.mock.calls.map(([url]) => requestUrl(url))).toEqual([
245+
XAI_OAUTH_DISCOVERY_URL,
246+
"https://auth.x.ai/oauth2/token",
247+
]);
248+
expect(refreshed).toMatchObject({
249+
access: "access-2",
250+
refresh: "refresh-2",
251+
tokenEndpoint: "https://auth.x.ai/oauth2/token",
252+
});
253+
});
254+
255+
it("does not reuse the stale xAI OAuth token endpoint when discovery fails", async () => {
256+
const fetchImpl = vi.fn<typeof fetch>(async (url) => {
257+
expect(requestUrl(url)).toBe(XAI_OAUTH_DISCOVERY_URL);
258+
throw new Error("discovery unavailable");
259+
});
260+
const credential = {
261+
type: "oauth",
262+
provider: "xai",
263+
access: "access-1",
264+
refresh: "refresh-1",
265+
expires: 100,
266+
tokenEndpoint: "https://auth.x.ai/oauth/token",
267+
} satisfies OAuthCredential & { tokenEndpoint: string };
268+
269+
await expect(refreshXaiOAuthCredential(credential, { fetchImpl })).rejects.toThrow(
270+
"discovery unavailable",
271+
);
272+
expect(fetchImpl).toHaveBeenCalledTimes(1);
273+
});
274+
214275
it("does not coerce partial xAI expires_in values", async () => {
215276
const fetchImpl = vi.fn<typeof fetch>(async () =>
216277
jsonResponse({

‎extensions/xai/xai-oauth.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const XAI_OAUTH_CLIENT_ID = "b1a00492-073a-47ea-816f-4c329264a828";
2727
export const XAI_OAUTH_SCOPE = "openid profile email offline_access grok-cli:access api:access";
2828
export const XAI_OAUTH_ISSUER = "https://auth.x.ai";
2929
export const XAI_OAUTH_DISCOVERY_URL = `${XAI_OAUTH_ISSUER}/.well-known/openid-configuration`;
30+
const XAI_LEGACY_OAUTH_TOKEN_ENDPOINT = `${XAI_OAUTH_ISSUER}/oauth/token`;
3031
export const XAI_OAUTH_CALLBACK_HOST = "127.0.0.1";
3132
export const XAI_OAUTH_CALLBACK_PORT = 56121;
3233
export const XAI_OAUTH_CALLBACK_PATH = "/callback";
@@ -492,6 +493,28 @@ function readCredentialString<TKey extends string>(
492493
return typeof value === "string" && value.trim().length > 0 ? value : undefined;
493494
}
494495

496+
async function resolveXaiOAuthRefreshTokenEndpoint(
497+
credential: OAuthCredential,
498+
options: XaiOAuthFetchOptions,
499+
): Promise<string> {
500+
const cachedEndpoint = readCredentialString(credential, "tokenEndpoint");
501+
if (!cachedEndpoint) {
502+
return (await fetchXaiOAuthDiscovery(options)).tokenEndpoint;
503+
}
504+
let endpoint: URL;
505+
try {
506+
endpoint = new URL(cachedEndpoint);
507+
} catch {
508+
return cachedEndpoint;
509+
}
510+
if (`${endpoint.origin}${endpoint.pathname}` !== XAI_LEGACY_OAUTH_TOKEN_ENDPOINT) {
511+
return cachedEndpoint;
512+
}
513+
// Older persisted xAI OAuth credentials can point at the retired endpoint;
514+
// rediscover once so refresh writes back the current OAuth token endpoint.
515+
return (await fetchXaiOAuthDiscovery(options)).tokenEndpoint;
516+
}
517+
495518
async function noteXaiOAuthUrl(ctx: ProviderAuthContext, authorizeUrl: string): Promise<void> {
496519
const lines = ["Open this xAI OAuth URL in your browser:"];
497520
if (ctx.isRemote) {
@@ -665,9 +688,7 @@ export async function refreshXaiOAuthCredential(
665688
if (!refreshToken) {
666689
throw new Error("xAI OAuth credential is missing refresh token");
667690
}
668-
const tokenEndpoint =
669-
readCredentialString(credential, "tokenEndpoint") ??
670-
(await fetchXaiOAuthDiscovery(options)).tokenEndpoint;
691+
const tokenEndpoint = await resolveXaiOAuthRefreshTokenEndpoint(credential, options);
671692
const tokens = await exchangeXaiOAuthToken({
672693
...options,
673694
tokenEndpoint,

‎packages/media-core/src/mime.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
FILE_TYPE_SNIFF_MAX_BYTES,
99
imageMimeFromFormat,
1010
isAudioFileName,
11+
isGifMedia,
1112
kindFromMime,
1213
mimeTypeFromFilePath,
1314
normalizeMimeType,
@@ -271,6 +272,29 @@ describe("isAudioFileName", () => {
271272
});
272273
});
273274

275+
describe("isGifMedia", () => {
276+
it.each([
277+
{
278+
opts: { contentType: "image/gif; charset=binary" },
279+
expected: true,
280+
},
281+
{
282+
opts: { contentType: " IMAGE/GIF " },
283+
expected: true,
284+
},
285+
{
286+
opts: { contentType: "image/png" },
287+
expected: false,
288+
},
289+
{
290+
opts: { fileName: "animation.GIF" },
291+
expected: true,
292+
},
293+
] as const)("detects GIF media from normalized metadata %#", ({ opts, expected }) => {
294+
expect(isGifMedia(opts)).toBe(expected);
295+
});
296+
});
297+
274298
describe("normalizeMimeType", () => {
275299
function expectNormalizedMimeCase(
276300
input: Parameters<typeof normalizeMimeType>[0],

‎packages/media-core/src/mime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export function isGifMedia(opts: {
252252
contentType?: string | null;
253253
fileName?: string | null;
254254
}): boolean {
255-
if (opts.contentType?.toLowerCase() === "image/gif") {
255+
if (normalizeMimeType(opts.contentType) === "image/gif") {
256256
return true;
257257
}
258258
const ext = getFileExtension(opts.fileName);

‎test/scripts/ci-workflow-guards.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,55 @@ describe("ci workflow guards", () => {
795795

796796
it("keeps workflow guards in fast CI-routing checks", () => {
797797
const workflow = readCiWorkflow();
798+
const preflightStep = workflow.jobs.preflight.steps.find(
799+
(step) => step.name === "Build CI manifest",
800+
);
801+
const taxonomy = parse(readFileSync("taxonomy.yaml", "utf8")) as {
802+
profiles: Array<{ id: string; categoryIds: string[] }>;
803+
};
804+
const smokeProfile = taxonomy.profiles.find((profile) => profile.id === "smoke-ci");
805+
if (!smokeProfile) {
806+
throw new Error("taxonomy.yaml is missing the smoke-ci profile");
807+
}
798808
const fastCoreJob = workflow.jobs["checks-fast-core"];
799809
const runStep = fastCoreJob.steps.find(
800810
(step) => step.name === "Run ${{ matrix.task }} (${{ matrix.runtime }})",
801811
);
812+
const uploadStep = fastCoreJob.steps.find(
813+
(step) => step.name === "Upload QA smoke profile evidence",
814+
);
815+
816+
const ciWorkflowText = readFileSync(".github/workflows/ci.yml", "utf8");
802817

818+
expect(preflightStep.run).not.toContain("qa-smoke-profile");
819+
expect(preflightStep.run).not.toContain("qa_category");
820+
expect(smokeProfile.categoryIds).toHaveLength(30);
821+
for (const categoryId of smokeProfile.categoryIds) {
822+
expect(ciWorkflowText).not.toContain(`"${categoryId}"`);
823+
}
824+
expect(runStep.run).toContain("bundled-protocol)");
825+
expect(runStep.run).toContain("qa-smoke-ci)");
803826
expect(runStep.run).toContain("contracts-plugins-ci-routing)");
804827
expect(runStep.run).toContain("ci-routing)");
828+
expect(ciWorkflowText).toContain(
829+
'{ check_name: "QA Smoke CI", runtime: "node", task: "qa-smoke-ci" }',
830+
);
831+
expect(runStep.run).toContain("--qa-profile smoke-ci");
832+
expect(runStep.run).toContain("--concurrency 8");
833+
expect(runStep.run).not.toContain("--category");
834+
expect(runStep.run).not.toContain("--allow-failures");
835+
expect(runStep.run).toContain("qa_exit_code=0");
836+
expect(runStep.run).toContain('exit "$qa_exit_code"');
837+
expect(runStep.run).toContain("scripts/build-all.mjs qaRuntime");
838+
expect(runStep.run).not.toContain("OPENAI_API_KEY");
839+
expect(runStep.run).toMatch(
840+
/bundled-protocol\)\s+pnpm test:bundled\s+pnpm protocol:check\s+;;\s+qa-smoke-ci\)/,
841+
);
842+
expect(uploadStep.if).toBe("always() && matrix.task == 'qa-smoke-ci'");
843+
expect(uploadStep.with).toMatchObject({
844+
path: ".artifacts/qa-e2e/smoke-ci-profile/",
845+
"if-no-files-found": "warn",
846+
});
805847
expect(runStep.run.match(/test\/scripts\/ci-workflow-guards\.test\.ts/g)?.length).toBe(2);
806848
});
807849

0 commit comments

Comments
 (0)