Files
DeepTutor/web/tests/codebuddy-auth-settings-contract.test.ts
Ching Wing Kwok 8297fc7b7e feat(provider): add codebuddy as a LLM provider (#780)
* feat: add codebuddy provider

* fix: treat codebuddy as login-backed provider

* feat: sync codebuddy account models

* fix: ignore no-key placeholder for codebuddy

* feat: add codebuddy web login

* fix: streamline codebuddy settings and latency

* fix: support switching codebuddy accounts

* fix: preserve codebuddy sessions and tool calls

* feat: use CodeBuddy HTTP provider over Agent SDK

Chat with CodeBuddy over plain HTTP by reusing the login state that the
IDE plugin / CLI stores on disk, instead of bundling the ~130MB Agent SDK.

- add codebuddy_http_provider (OpenAI-compatible /chat/completions on
  <endpoint>/v2) with codebuddy_credentials for local OAuth session reuse
- provider_factory picks HTTP transport whenever a login state or API key
  is available; Agent SDK stays as fallback for CLI agent features
- demote codebuddy-agent-sdk from core deps to optional codebuddy extra
- default model codebuddy/default -> codebuddy/hy3
- update auth card UX and locales for SDK-less sign-in flow

* chore: label codebuddy provider as codebuddy/workbuddy in the dashboard

* style: apply pre-commit formatting after upstream merge

* chore: capitalise codebuddy provider label as CodeBuddy/WorkBuddy

---------

Co-authored-by: Bingxi Zhao (Frank) <13051345080@163.com>
2026-08-13 00:02:42 +08:00

73 lines
2.4 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import path from "node:path";
import test from "node:test";
import { shouldPollCodeBuddyAuth } from "../lib/codebuddy-auth";
const EDITOR = path.resolve(
process.cwd(),
"components/settings/ServiceConfigEditor.tsx",
);
const CARD = path.resolve(
process.cwd(),
"components/settings/CodeBuddyAuthCard.tsx",
);
const EN = path.resolve(process.cwd(), "locales/en/app.json");
const ZH = path.resolve(process.cwd(), "locales/zh/app.json");
test("CodeBuddy renders a login card without changing other OAuth cards", () => {
const editor = readFileSync(EDITOR, "utf8");
assert.match(editor, /providerValue === "codebuddy"/);
assert.match(editor, /<CodeBuddyAuthCard/);
assert.match(editor, /<CodexOAuthCard/);
assert.match(editor, /isCodexOAuth \|\| isCodeBuddyAuth/);
assert.match(editor, /!isCodexOAuth && !isCodeBuddyAuth/);
assert.match(readFileSync(CARD, "utf8"), /startCodeBuddyLogin/);
assert.match(readFileSync(CARD, "utf8"), /logoutCodeBuddy/);
});
test("CodeBuddy model sync cannot write into a profile after provider switch", () => {
const editor = readFileSync(EDITOR, "utf8");
assert.match(editor, /!profile \|\| profile\.binding !== binding/);
assert.match(editor, /previousProvider === "codebuddy"/);
assert.match(editor, /profile\.models = \[\]/);
});
test("CodeBuddy auth polling only runs while browser authorization is waiting", () => {
const base = {
connection: "authorizing" as const,
operation_state: "waiting" as const,
authorize_url: "https://codebuddy.example/login",
user_label: null,
error_code: null,
};
assert.equal(shouldPollCodeBuddyAuth(base), true);
assert.equal(
shouldPollCodeBuddyAuth({
...base,
connection: "connected",
operation_state: "completed",
}),
false,
);
});
test("CodeBuddy auth copy stays in sync across locales", () => {
const en = JSON.parse(readFileSync(EN, "utf8")) as Record<string, unknown>;
const zh = JSON.parse(readFileSync(ZH, "utf8")) as Record<string, unknown>;
const keys = (locale: Record<string, unknown>) =>
Object.keys(locale)
.filter((key) => key.startsWith("codebuddy.auth."))
.sort();
assert.deepEqual(keys(en), keys(zh));
for (const key of keys(en)) {
assert.equal(typeof en[key], "string");
assert.equal(typeof zh[key], "string");
}
});