mirror of https://github.com/openclaw/openclaw.git
chore: Fix types in tests 37/N.
This commit is contained in:
parent
7b31e8fc59
commit
238718c1d8
|
|
@ -28,7 +28,7 @@ async function createBootstrapContext(params: {
|
|||
sessionKey: string;
|
||||
rootFiles: Array<{ name: string; content: string }>;
|
||||
}): Promise<AgentBootstrapHookContext> {
|
||||
const bootstrapFiles = await Promise.all(
|
||||
const bootstrapFiles = (await Promise.all(
|
||||
params.rootFiles.map(async (file) => ({
|
||||
name: file.name,
|
||||
path: await writeWorkspaceFile({
|
||||
|
|
@ -39,7 +39,7 @@ async function createBootstrapContext(params: {
|
|||
content: file.content,
|
||||
missing: false,
|
||||
})),
|
||||
);
|
||||
)) as AgentBootstrapHookContext["bootstrapFiles"];
|
||||
return {
|
||||
workspaceDir: params.workspaceDir,
|
||||
bootstrapFiles,
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ beforeAll(async () => {
|
|||
* Create a mock session JSONL file with various entry types
|
||||
*/
|
||||
function createMockSessionContent(
|
||||
entries: Array<{ role: string; content: string } | { type: string }>,
|
||||
entries: Array<{ role: string; content: string } | ({ type: string } & Record<string, unknown>)>,
|
||||
): string {
|
||||
return entries
|
||||
.map((entry) => {
|
||||
|
|
|
|||
|
|
@ -180,7 +180,14 @@ describe("installHooksFromPath", () => {
|
|||
);
|
||||
|
||||
const run = vi.mocked(runCommandWithTimeout);
|
||||
run.mockResolvedValue({ code: 0, stdout: "", stderr: "" });
|
||||
run.mockResolvedValue({
|
||||
code: 0,
|
||||
stdout: "",
|
||||
stderr: "",
|
||||
signal: null,
|
||||
killed: false,
|
||||
termination: "exit",
|
||||
});
|
||||
|
||||
const res = await installHooksFromPath({
|
||||
path: pkgDir,
|
||||
|
|
@ -239,9 +246,16 @@ describe("installHooksFromNpmSpec", () => {
|
|||
const packedName = "test-hooks-0.0.1.tgz";
|
||||
run.mockImplementation(async (argv, opts) => {
|
||||
if (argv[0] === "npm" && argv[1] === "pack") {
|
||||
packTmpDir = String(opts?.cwd ?? "");
|
||||
packTmpDir = String(typeof opts === "number" ? "" : (opts.cwd ?? ""));
|
||||
fs.writeFileSync(path.join(packTmpDir, packedName), npmPackHooksBuffer);
|
||||
return { code: 0, stdout: `${packedName}\n`, stderr: "", signal: null, killed: false };
|
||||
return {
|
||||
code: 0,
|
||||
stdout: `${packedName}\n`,
|
||||
stderr: "",
|
||||
signal: null,
|
||||
killed: false,
|
||||
termination: "exit",
|
||||
};
|
||||
}
|
||||
throw new Error(`unexpected command: ${argv.join(" ")}`);
|
||||
});
|
||||
|
|
@ -269,7 +283,8 @@ describe("installHooksFromNpmSpec", () => {
|
|||
}
|
||||
const [argv, options] = packCall;
|
||||
expect(argv).toEqual(["npm", "pack", "@openclaw/test-hooks@0.0.1", "--ignore-scripts"]);
|
||||
expect(options?.env).toMatchObject({ NPM_CONFIG_IGNORE_SCRIPTS: "true" });
|
||||
const commandOptions = typeof options === "number" ? undefined : options;
|
||||
expect(commandOptions?.env).toMatchObject({ NPM_CONFIG_IGNORE_SCRIPTS: "true" });
|
||||
|
||||
expect(packTmpDir).not.toBe("");
|
||||
expect(fs.existsSync(packTmpDir)).toBe(false);
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ describe("deliverLineAutoReply", () => {
|
|||
pushMessageLine,
|
||||
pushTextMessageWithQuickReplies,
|
||||
createTextMessageWithQuickReplies,
|
||||
createQuickReplyItems,
|
||||
createQuickReplyItems: createQuickReplyItems as LineAutoReplyDeps["createQuickReplyItems"],
|
||||
pushMessagesLine,
|
||||
createFlexMessage,
|
||||
createFlexMessage: createFlexMessage as LineAutoReplyDeps["createFlexMessage"],
|
||||
createImageMessage,
|
||||
createLocationMessage,
|
||||
...overrides,
|
||||
|
|
@ -146,7 +146,8 @@ describe("deliverLineAutoReply", () => {
|
|||
quickReplies: ["A"],
|
||||
};
|
||||
const { deps, pushMessagesLine, replyMessageLine } = createDeps({
|
||||
createTextMessageWithQuickReplies,
|
||||
createTextMessageWithQuickReplies:
|
||||
createTextMessageWithQuickReplies as LineAutoReplyDeps["createTextMessageWithQuickReplies"],
|
||||
});
|
||||
|
||||
await deliverLineAutoReply({
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ describe("buildLineMessageContext", () => {
|
|||
cfg,
|
||||
account,
|
||||
});
|
||||
expect(context).not.toBeNull();
|
||||
if (!context) {
|
||||
throw new Error("context missing");
|
||||
}
|
||||
|
||||
expect(context.ctxPayload.OriginatingTo).toBe("line:group:group-1");
|
||||
expect(context.ctxPayload.To).toBe("line:group:group-1");
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ describe("messageAction", () => {
|
|||
it("truncates label to 20 characters", () => {
|
||||
const action = messageAction("This is a very long label text");
|
||||
|
||||
expect(action.label.length).toBe(20);
|
||||
expect((action.label ?? "").length).toBe(20);
|
||||
expect(action.label).toBe("This is a very long ");
|
||||
});
|
||||
});
|
||||
|
|
@ -43,7 +43,7 @@ describe("uriAction", () => {
|
|||
it("truncates label to 20 characters", () => {
|
||||
const action = uriAction("Click here to visit our website", "https://example.com");
|
||||
|
||||
expect(action.label.length).toBe(20);
|
||||
expect((action.label ?? "").length).toBe(20);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ describe("applyMediaUnderstanding", () => {
|
|||
body: "[Audio]\nTranscript:\ntranscribed text",
|
||||
commandBody: "transcribed text",
|
||||
});
|
||||
expect(ctx.BodyForAgent).toBe(ctx.Body);
|
||||
expect((ctx as unknown as { BodyForAgent?: string }).BodyForAgent).toBe(ctx.Body);
|
||||
});
|
||||
|
||||
it("skips file blocks for text-like audio when transcription succeeds", async () => {
|
||||
|
|
@ -308,7 +308,7 @@ describe("applyMediaUnderstanding", () => {
|
|||
});
|
||||
|
||||
expect(result.appliedAudio).toBe(true);
|
||||
expect(ctx.Transcript).toBe("cli transcript");
|
||||
expect((ctx as unknown as { Transcript?: string }).Transcript).toBe("cli transcript");
|
||||
expect(ctx.Body).toBe("[Audio]\nTranscript:\ncli transcript");
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ describe("media understanding scope", () => {
|
|||
it("matches channel chatType explicitly", () => {
|
||||
const scope = {
|
||||
rules: [{ action: "deny", match: { chatType: "channel" } }],
|
||||
} as const;
|
||||
} as Parameters<typeof resolveMediaUnderstandingScope>[0]["scope"];
|
||||
|
||||
expect(resolveMediaUnderstandingScope({ scope, chatType: "channel" })).toBe("deny");
|
||||
});
|
||||
|
|
|
|||
|
|
@ -13,8 +13,12 @@ function makeStream(chunks: Uint8Array[]) {
|
|||
}
|
||||
|
||||
describe("fetchRemoteMedia", () => {
|
||||
type LookupFn = NonNullable<Parameters<typeof fetchRemoteMedia>[0]["lookupFn"]>;
|
||||
|
||||
it("rejects when content-length exceeds maxBytes", async () => {
|
||||
const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
|
||||
const lookupFn = vi.fn(async () => [
|
||||
{ address: "93.184.216.34", family: 4 },
|
||||
]) as unknown as LookupFn;
|
||||
const fetchImpl = async () =>
|
||||
new Response(makeStream([new Uint8Array([1, 2, 3, 4, 5])]), {
|
||||
status: 200,
|
||||
|
|
@ -32,7 +36,9 @@ describe("fetchRemoteMedia", () => {
|
|||
});
|
||||
|
||||
it("rejects when streamed payload exceeds maxBytes", async () => {
|
||||
const lookupFn = vi.fn(async () => [{ address: "93.184.216.34", family: 4 }]);
|
||||
const lookupFn = vi.fn(async () => [
|
||||
{ address: "93.184.216.34", family: 4 },
|
||||
]) as unknown as LookupFn;
|
||||
const fetchImpl = async () =>
|
||||
new Response(makeStream([new Uint8Array([1, 2, 3]), new Uint8Array([4, 5, 6])]), {
|
||||
status: 200,
|
||||
|
|
|
|||
Loading…
Reference in New Issue