test(shared): remove unsafe test assertions
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -5,7 +5,7 @@ import { OpenClawConfigSchema } from "../../config/schema/openclaw"
|
|||||||
|
|
||||||
describe("OpenClaw Config", () => {
|
describe("OpenClaw Config", () => {
|
||||||
test("resolveGateway resolves HTTP gateway", () => {
|
test("resolveGateway resolves HTTP gateway", () => {
|
||||||
const config: OpenClawConfig = {
|
const config: OpenClawConfig = testCoerce({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
gateways: {
|
gateways: {
|
||||||
discord: {
|
discord: {
|
||||||
@@ -20,7 +20,7 @@ describe("OpenClaw Config", () => {
|
|||||||
instruction: "Started session {{sessionId}}",
|
instruction: "Started session {{sessionId}}",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} as any
|
})
|
||||||
|
|
||||||
const resolved = resolveGateway(config, "session-start")
|
const resolved = resolveGateway(config, "session-start")
|
||||||
expect(resolved).not.toBeNull()
|
expect(resolved).not.toBeNull()
|
||||||
@@ -30,31 +30,31 @@ describe("OpenClaw Config", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test("resolveGateway returns null for disabled config", () => {
|
test("resolveGateway returns null for disabled config", () => {
|
||||||
const config: OpenClawConfig = {
|
const config: OpenClawConfig = testCoerce({
|
||||||
enabled: false,
|
enabled: false,
|
||||||
gateways: {},
|
gateways: {},
|
||||||
hooks: {},
|
hooks: {},
|
||||||
} as any
|
})
|
||||||
expect(resolveGateway(config, "session-start")).toBeNull()
|
expect(resolveGateway(config, "session-start")).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("resolveGateway returns null for unknown hook", () => {
|
test("resolveGateway returns null for unknown hook", () => {
|
||||||
const config: OpenClawConfig = {
|
const config: OpenClawConfig = testCoerce({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
gateways: {},
|
gateways: {},
|
||||||
hooks: {},
|
hooks: {},
|
||||||
} as any
|
})
|
||||||
expect(resolveGateway(config, "unknown")).toBeNull()
|
expect(resolveGateway(config, "unknown")).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
test("resolveGateway returns null for disabled hook", () => {
|
test("resolveGateway returns null for disabled hook", () => {
|
||||||
const config: OpenClawConfig = {
|
const config: OpenClawConfig = testCoerce({
|
||||||
enabled: true,
|
enabled: true,
|
||||||
gateways: { g: { type: "http", url: "https://example.com" } },
|
gateways: { g: { type: "http", url: "https://example.com" } },
|
||||||
hooks: {
|
hooks: {
|
||||||
event: { enabled: false, gateway: "g", instruction: "i" },
|
event: { enabled: false, gateway: "g", instruction: "i" },
|
||||||
},
|
},
|
||||||
} as any
|
})
|
||||||
expect(resolveGateway(config, "event")).toBeNull()
|
expect(resolveGateway(config, "event")).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ describe("pollDiscordReplies", () => {
|
|||||||
status: 401,
|
status: 401,
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
globalThis.fetch = fetchMock as unknown as typeof fetch
|
globalThis.fetch = testCoerce<typeof fetch>(fetchMock)
|
||||||
|
|
||||||
const state = createState()
|
const state = createState()
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ describe("pollDiscordReplies", () => {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.mockResolvedValueOnce(new Response(null, { status: 204 }))
|
.mockResolvedValueOnce(new Response(null, { status: 204 }))
|
||||||
globalThis.fetch = fetchMock as unknown as typeof fetch
|
globalThis.fetch = testCoerce<typeof fetch>(fetchMock)
|
||||||
const lookupSpy = spyOn(sessionRegistryModule, "lookupByMessageId").mockReturnValue({
|
const lookupSpy = spyOn(sessionRegistryModule, "lookupByMessageId").mockReturnValue({
|
||||||
sessionId: "ses-1",
|
sessionId: "ses-1",
|
||||||
tmuxSession: "session-1",
|
tmuxSession: "session-1",
|
||||||
|
|||||||
@@ -216,20 +216,23 @@ Body content`
|
|||||||
agent: string
|
agent: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface FrontmatterWithExtras extends MinimalMeta {
|
||||||
|
extra_field: string
|
||||||
|
another_extra: { nested: string; array: string[] }
|
||||||
|
custom_boolean: boolean
|
||||||
|
custom_number: number
|
||||||
|
}
|
||||||
|
|
||||||
// when
|
// when
|
||||||
const result = parseFrontmatter<MinimalMeta>(content)
|
const result = parseFrontmatter<FrontmatterWithExtras>(content)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
expect(result.data.description).toBe("Test command")
|
expect(result.data.description).toBe("Test command")
|
||||||
expect(result.data.agent).toBe("build")
|
expect(result.data.agent).toBe("build")
|
||||||
expect(result.body).toBe("Body content")
|
expect(result.body).toBe("Body content")
|
||||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
|
||||||
expect(result.data.extra_field).toBe("should not fail")
|
expect(result.data.extra_field).toBe("should not fail")
|
||||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
|
||||||
expect(result.data.another_extra).toEqual({ nested: "value", array: ["item1", "item2"] })
|
expect(result.data.another_extra).toEqual({ nested: "value", array: ["item1", "item2"] })
|
||||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
|
||||||
expect(result.data.custom_boolean).toBe(true)
|
expect(result.data.custom_boolean).toBe(true)
|
||||||
// @ts-expect-error - accessing extra field not in MinimalMeta
|
|
||||||
expect(result.data.custom_number).toBe(42)
|
expect(result.data.custom_number).toBe(42)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ describe("collectGitDiffStats", () => {
|
|||||||
expect(execSyncSpy).not.toHaveBeenCalled()
|
expect(execSyncSpy).not.toHaveBeenCalled()
|
||||||
expect(execFileSyncSpy.mock.calls.length).toBeGreaterThanOrEqual(3)
|
expect(execFileSyncSpy.mock.calls.length).toBeGreaterThanOrEqual(3)
|
||||||
|
|
||||||
const calls = execFileSyncSpy.mock.calls as unknown as Array<[string, string[], { cwd?: string }]>
|
const calls = testCoerce<Array<[string, string[], { cwd?: string }]>>(execFileSyncSpy.mock.calls)
|
||||||
const diffCall = calls.find(([, args]) => args[0] === "diff")
|
const diffCall = calls.find(([, args]) => args[0] === "diff")
|
||||||
const statusCall = calls.find(([, args]) => args[0] === "status")
|
const statusCall = calls.find(([, args]) => args[0] === "status")
|
||||||
const untrackedCall = calls.find(([, args]) => args[0] === "ls-files")
|
const untrackedCall = calls.find(([, args]) => args[0] === "ls-files")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as fs from "node:fs"
|
import * as fs from "node:fs"
|
||||||
import * as path from "node:path"
|
import * as path from "node:path"
|
||||||
import { log } from "../logger"
|
import { log } from "../logger"
|
||||||
|
import { isRecord } from "../record-type-guard"
|
||||||
import { writeFileAtomically } from "../write-file-atomically"
|
import { writeFileAtomically } from "../write-file-atomically"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,14 +49,9 @@ export function readAppliedMigrations(configPath: string): Set<string> {
|
|||||||
return new Set()
|
return new Set()
|
||||||
}
|
}
|
||||||
const content = fs.readFileSync(sidecarPath, "utf-8")
|
const content = fs.readFileSync(sidecarPath, "utf-8")
|
||||||
const parsed = JSON.parse(content) as unknown
|
const parsed: unknown = JSON.parse(content)
|
||||||
if (
|
if (isRecord(parsed) && Array.isArray(parsed.appliedMigrations)) {
|
||||||
parsed &&
|
return new Set(parsed.appliedMigrations.filter((migration): migration is string => typeof migration === "string"))
|
||||||
typeof parsed === "object" &&
|
|
||||||
!Array.isArray(parsed) &&
|
|
||||||
Array.isArray((parsed as MigrationsSidecar).appliedMigrations)
|
|
||||||
) {
|
|
||||||
return new Set((parsed as MigrationsSidecar).appliedMigrations.filter((m): m is string => typeof m === "string"))
|
|
||||||
}
|
}
|
||||||
return new Set()
|
return new Set()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
const client = { session: { promptAsync: promptMock } }
|
const client = { session: { promptAsync: promptMock } }
|
||||||
|
|
||||||
// when calling promptWithModelSuggestionRetry
|
// when calling promptWithModelSuggestionRetry
|
||||||
await promptWithModelSuggestionRetry(client as any, {
|
await promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -244,7 +244,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
// when calling promptWithModelSuggestionRetry
|
// when calling promptWithModelSuggestionRetry
|
||||||
// then should throw the error without retrying
|
// then should throw the error without retrying
|
||||||
await expect(
|
await expect(
|
||||||
promptWithModelSuggestionRetry(client as any, {
|
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
@@ -267,7 +267,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
// when calling promptWithModelSuggestionRetry
|
// when calling promptWithModelSuggestionRetry
|
||||||
// then should throw the original error
|
// then should throw the original error
|
||||||
await expect(
|
await expect(
|
||||||
promptWithModelSuggestionRetry(client as any, {
|
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -288,7 +288,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
// when calling promptWithModelSuggestionRetry
|
// when calling promptWithModelSuggestionRetry
|
||||||
// then should throw the error
|
// then should throw the error
|
||||||
await expect(
|
await expect(
|
||||||
promptWithModelSuggestionRetry(client as any, {
|
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -307,7 +307,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
const client = { session: { promptAsync: promptMock } }
|
const client = { session: { promptAsync: promptMock } }
|
||||||
|
|
||||||
// when calling with additional body fields
|
// when calling with additional body fields
|
||||||
await promptWithModelSuggestionRetry(client as any, {
|
await promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
agent: "explore",
|
agent: "explore",
|
||||||
@@ -341,7 +341,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
// when calling promptWithModelSuggestionRetry
|
// when calling promptWithModelSuggestionRetry
|
||||||
// then should throw the error
|
// then should throw the error
|
||||||
await expect(
|
await expect(
|
||||||
promptWithModelSuggestionRetry(client as any, {
|
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -365,7 +365,7 @@ describe("promptWithModelSuggestionRetry", () => {
|
|||||||
// when calling without model in body
|
// when calling without model in body
|
||||||
// then should throw the error
|
// then should throw the error
|
||||||
await expect(
|
await expect(
|
||||||
promptWithModelSuggestionRetry(client as any, {
|
promptWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -386,7 +386,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
const client = { session: { prompt: promptMock, promptAsync: promptAsyncMock } }
|
const client = { session: { prompt: promptMock, promptAsync: promptAsyncMock } }
|
||||||
|
|
||||||
// when calling promptSyncWithModelSuggestionRetry
|
// when calling promptSyncWithModelSuggestionRetry
|
||||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -424,7 +424,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
// when calling with short timeout
|
// when calling with short timeout
|
||||||
// then should abort the request and throw timeout error
|
// then should abort the request and throw timeout error
|
||||||
await expect(
|
await expect(
|
||||||
promptSyncWithModelSuggestionRetry(client as any, {
|
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -451,7 +451,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
const client = { session: { prompt: promptMock } }
|
const client = { session: { prompt: promptMock } }
|
||||||
|
|
||||||
// when calling promptSyncWithModelSuggestionRetry
|
// when calling promptSyncWithModelSuggestionRetry
|
||||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -477,7 +477,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
// when calling promptSyncWithModelSuggestionRetry
|
// when calling promptSyncWithModelSuggestionRetry
|
||||||
// then should throw the original error
|
// then should throw the original error
|
||||||
await expect(
|
await expect(
|
||||||
promptSyncWithModelSuggestionRetry(client as any, {
|
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -504,7 +504,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
// when calling without model in body
|
// when calling without model in body
|
||||||
// then should throw (cannot retry without original model)
|
// then should throw (cannot retry without original model)
|
||||||
await expect(
|
await expect(
|
||||||
promptSyncWithModelSuggestionRetry(client as any, {
|
promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
parts: [{ type: "text", text: "hello" }],
|
parts: [{ type: "text", text: "hello" }],
|
||||||
@@ -521,7 +521,7 @@ describe("promptSyncWithModelSuggestionRetry", () => {
|
|||||||
const client = { session: { prompt: promptMock } }
|
const client = { session: { prompt: promptMock } }
|
||||||
|
|
||||||
// when calling with additional body fields
|
// when calling with additional body fields
|
||||||
await promptSyncWithModelSuggestionRetry(client as any, {
|
await promptSyncWithModelSuggestionRetry(testCoerce(client), {
|
||||||
path: { id: "session-1" },
|
path: { id: "session-1" },
|
||||||
body: {
|
body: {
|
||||||
agent: "multimodal-looker",
|
agent: "multimodal-looker",
|
||||||
|
|||||||
Reference in New Issue
Block a user