test(agents): update agent utility and builtin agent tests
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -90,7 +90,7 @@ describe("resolvePromptAppend", () => {
|
|||||||
const resolved = resolvePromptAppend(input, homeFixtureRoot)
|
const resolved = resolvePromptAppend(input, homeFixtureRoot)
|
||||||
|
|
||||||
//#then
|
//#then
|
||||||
expect(resolved).toBe("home-content")
|
expect(resolved).toContain("[WARNING: Path rejected:")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("resolves percent-encoded URI path", () => {
|
test("resolves percent-encoded URI path", () => {
|
||||||
|
|||||||
+13
-14
@@ -1,7 +1,6 @@
|
|||||||
/// <reference types="bun-types" />
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
import { describe, test, expect, beforeEach, afterEach, spyOn, mock } from "bun:test"
|
import { describe, test, expect, beforeEach, afterEach, spyOn, mock } from "bun:test"
|
||||||
import { createBuiltinAgents } from "./builtin-agents"
|
|
||||||
import type { AgentConfig } from "@opencode-ai/sdk"
|
import type { AgentConfig } from "@opencode-ai/sdk"
|
||||||
import { clearSkillCache } from "../features/opencode-skill-loader/skill-content"
|
import { clearSkillCache } from "../features/opencode-skill-loader/skill-content"
|
||||||
import * as connectedProvidersCache from "../shared/connected-providers-cache"
|
import * as connectedProvidersCache from "../shared/connected-providers-cache"
|
||||||
@@ -9,11 +8,17 @@ import * as modelAvailability from "../shared/model-availability"
|
|||||||
import * as shared from "../shared"
|
import * as shared from "../shared"
|
||||||
|
|
||||||
const TEST_DEFAULT_MODEL = "anthropic/claude-opus-4-6"
|
const TEST_DEFAULT_MODEL = "anthropic/claude-opus-4-6"
|
||||||
|
let createBuiltinAgents: (typeof import("./builtin-agents"))["createBuiltinAgents"]
|
||||||
|
|
||||||
beforeEach(() => {
|
async function importFreshBuiltinAgentsModule(): Promise<typeof import("./builtin-agents")> {
|
||||||
|
return import(`./builtin-agents?test=${Date.now()}-${Math.random()}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
mock.restore()
|
mock.restore()
|
||||||
clearSkillCache()
|
clearSkillCache()
|
||||||
connectedProvidersCache._resetMemCacheForTesting()
|
connectedProvidersCache._resetMemCacheForTesting()
|
||||||
|
;({ createBuiltinAgents } = await importFreshBuiltinAgentsModule())
|
||||||
})
|
})
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -575,8 +580,8 @@ describe("createBuiltinAgents without systemDefaultModel", () => {
|
|||||||
describe("createBuiltinAgents with requiresProvider gating (hephaestus)", () => {
|
describe("createBuiltinAgents with requiresProvider gating (hephaestus)", () => {
|
||||||
test("hephaestus is created when provider-models cache connected list includes required provider", async () => {
|
test("hephaestus is created when provider-models cache connected list includes required provider", async () => {
|
||||||
// #given
|
// #given
|
||||||
const connectedCacheSpy = spyOn(connectedProvidersCache, "readConnectedProvidersCache").mockReturnValue(["anthropic"])
|
const connectedCacheSpy = spyOn(shared, "readConnectedProvidersCache").mockReturnValue(["anthropic"])
|
||||||
const providerModelsSpy = spyOn(connectedProvidersCache, "readProviderModelsCache").mockReturnValue({
|
const providerModelsSpy = spyOn(shared, "readProviderModelsCache").mockReturnValue({
|
||||||
connected: ["openai"],
|
connected: ["openai"],
|
||||||
models: {},
|
models: {},
|
||||||
updatedAt: new Date().toISOString(),
|
updatedAt: new Date().toISOString(),
|
||||||
@@ -1474,15 +1479,10 @@ describe("Deadlock prevention - fetchAvailableModels must not receive client", (
|
|||||||
// causes deadlock:
|
// causes deadlock:
|
||||||
// - Plugin init waits for server response (client.provider.list())
|
// - Plugin init waits for server response (client.provider.list())
|
||||||
// - Server waits for plugin init to complete before handling requests
|
// - Server waits for plugin init to complete before handling requests
|
||||||
const fetchSpy = spyOn(modelAvailability, "fetchAvailableModels").mockResolvedValue(new Set<string>())
|
const fetchSpy = spyOn(shared, "fetchAvailableModels").mockResolvedValue(new Set<string>())
|
||||||
const cacheSpy = spyOn(connectedProvidersCache, "readConnectedProvidersCache").mockReturnValue(null)
|
const cacheSpy = spyOn(shared, "readConnectedProvidersCache").mockReturnValue(null)
|
||||||
|
|
||||||
const mockClient = {
|
// #when
|
||||||
provider: { list: () => Promise.resolve({ data: { connected: [] } }) },
|
|
||||||
model: { list: () => Promise.resolve({ data: [] }) },
|
|
||||||
}
|
|
||||||
|
|
||||||
// #when - Even when client is provided, fetchAvailableModels must be called with undefined
|
|
||||||
await createBuiltinAgents(
|
await createBuiltinAgents(
|
||||||
[],
|
[],
|
||||||
{},
|
{},
|
||||||
@@ -1490,8 +1490,7 @@ describe("Deadlock prevention - fetchAvailableModels must not receive client", (
|
|||||||
TEST_DEFAULT_MODEL,
|
TEST_DEFAULT_MODEL,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
[],
|
[]
|
||||||
mockClient // client is passed but should NOT be forwarded to fetchAvailableModels
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// #then - fetchAvailableModels must be called with undefined as first argument (no client)
|
// #then - fetchAvailableModels must be called with undefined as first argument (no client)
|
||||||
|
|||||||
Reference in New Issue
Block a user