mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-21 05:52:35 +08:00
Resolve merge conflicts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { test, expect, describe } from "bun:test"
|
||||
import { extractResponseText } from "../../src/cli/cmd/github"
|
||||
import { extractResponseText, formatPromptTooLargeError } from "../../src/cli/cmd/github"
|
||||
import type { MessageV2 } from "../../src/session/message-v2"
|
||||
|
||||
// Helper to create minimal valid parts
|
||||
@@ -159,3 +159,39 @@ describe("extractResponseText", () => {
|
||||
expect(extractResponseText(parts)).toBe("Here's what I found")
|
||||
})
|
||||
})
|
||||
|
||||
describe("formatPromptTooLargeError", () => {
|
||||
test("formats error without files", () => {
|
||||
const result = formatPromptTooLargeError([])
|
||||
expect(result).toBe("PROMPT_TOO_LARGE: The prompt exceeds the model's context limit.")
|
||||
})
|
||||
|
||||
test("formats error with files (base64 content)", () => {
|
||||
// Base64 is ~33% larger than original, so we multiply by 0.75 to get original size
|
||||
// 400 KB base64 = 300 KB original, 200 KB base64 = 150 KB original
|
||||
const files = [
|
||||
{ filename: "screenshot.png", content: "a".repeat(400 * 1024) },
|
||||
{ filename: "diagram.png", content: "b".repeat(200 * 1024) },
|
||||
]
|
||||
const result = formatPromptTooLargeError(files)
|
||||
|
||||
expect(result).toStartWith("PROMPT_TOO_LARGE: The prompt exceeds the model's context limit.")
|
||||
expect(result).toInclude("Files in prompt:")
|
||||
expect(result).toInclude("screenshot.png (300 KB)")
|
||||
expect(result).toInclude("diagram.png (150 KB)")
|
||||
})
|
||||
|
||||
test("lists all files when multiple present", () => {
|
||||
// Base64 sizes: 4KB -> 3KB, 8KB -> 6KB, 12KB -> 9KB
|
||||
const files = [
|
||||
{ filename: "img1.png", content: "x".repeat(4 * 1024) },
|
||||
{ filename: "img2.jpg", content: "y".repeat(8 * 1024) },
|
||||
{ filename: "img3.gif", content: "z".repeat(12 * 1024) },
|
||||
]
|
||||
const result = formatPromptTooLargeError(files)
|
||||
|
||||
expect(result).toInclude("img1.png (3 KB)")
|
||||
expect(result).toInclude("img2.jpg (6 KB)")
|
||||
expect(result).toInclude("img3.gif (9 KB)")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
import { test, expect, describe } from "bun:test"
|
||||
import { resolvePluginProviders } from "../../src/cli/cmd/auth"
|
||||
import type { Hooks } from "@kilocode/plugin"
|
||||
|
||||
function hookWithAuth(provider: string): Hooks {
|
||||
return {
|
||||
auth: {
|
||||
provider,
|
||||
methods: [],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function hookWithoutAuth(): Hooks {
|
||||
return {}
|
||||
}
|
||||
|
||||
describe("resolvePluginProviders", () => {
|
||||
test("returns plugin providers not in models.dev", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("skips providers already in models.dev", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("anthropic")],
|
||||
existingProviders: { anthropic: {} },
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("deduplicates across plugins", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey"), hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("respects disabled_providers", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(["portkey"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("respects enabled_providers when provider is absent", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
enabled: new Set(["anthropic"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
|
||||
test("includes provider when in enabled set", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
enabled: new Set(["portkey"]),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("resolves name from providerNames", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: { portkey: "Portkey AI" },
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "Portkey AI" }])
|
||||
})
|
||||
|
||||
test("falls back to id when no name configured", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithAuth("portkey")],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("skips hooks without auth", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [hookWithoutAuth(), hookWithAuth("portkey"), hookWithoutAuth()],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([{ id: "portkey", name: "portkey" }])
|
||||
})
|
||||
|
||||
test("returns empty for no hooks", () => {
|
||||
const result = resolvePluginProviders({
|
||||
hooks: [],
|
||||
existingProviders: {},
|
||||
disabled: new Set(),
|
||||
providerNames: {},
|
||||
})
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user