mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 09:11:34 +00:00
test(openai): cover GPT-Live delegation output bounds
This commit is contained in:
@@ -370,6 +370,31 @@ describe("OpenAIQuicksilverVoiceBridge", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("bounds direct tool results before sideband sends", async () => {
|
||||
const harness = createHarness();
|
||||
await harness.bridge.connect();
|
||||
|
||||
harness.socket.serverEvent({
|
||||
type: "delegation.created",
|
||||
item: {
|
||||
type: "delegation",
|
||||
target: "client",
|
||||
id: "delegation-large",
|
||||
content: [{ type: "input_text", text: "summarize everything" }],
|
||||
},
|
||||
});
|
||||
harness.bridge.submitToolResult("delegation-large", { text: "x".repeat(10_000) });
|
||||
|
||||
const appends = sentEvents(harness.socket).filter(
|
||||
(event) => event.type === "delegation.context.append",
|
||||
);
|
||||
expect(appends.length).toBeGreaterThan(0);
|
||||
expect(appends.length).toBeLessThanOrEqual(11);
|
||||
expect(
|
||||
appends.map((event) => (event.content as Array<{ text: string }>)[0]?.text ?? "").join(""),
|
||||
).toMatch(/^x+ \[truncated\]$/);
|
||||
});
|
||||
|
||||
it("normalizes assistant completion to the shared response lifecycle", async () => {
|
||||
const harness = createHarness();
|
||||
await harness.bridge.connect();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
boundOpenAIQuicksilverDelegationResult,
|
||||
chunkOpenAIQuicksilverAppendText,
|
||||
parseOpenAIQuicksilverEvent,
|
||||
} from "./realtime-quicksilver-wire.js";
|
||||
@@ -125,6 +126,22 @@ describe("GPT-Live sideband protocol", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("bounds total speakable text before chunking", () => {
|
||||
expect(boundOpenAIQuicksilverDelegationResult(" short result ")).toBe(" short result ");
|
||||
const limited = boundOpenAIQuicksilverDelegationResult(
|
||||
`${"a".repeat(1_783)}😀${"b".repeat(1_000)}`,
|
||||
);
|
||||
const chunks = chunkOpenAIQuicksilverAppendText(limited);
|
||||
|
||||
expect(limited).toMatch(/ \[truncated\]$/);
|
||||
expect(limited.length).toBeLessThanOrEqual(1_800);
|
||||
expect(limited).not.toContain("\uFFFD");
|
||||
expect(chunks.length).toBeLessThanOrEqual(11);
|
||||
for (const chunk of chunks) {
|
||||
expect(Buffer.byteLength(chunk, "utf8")).toBeLessThanOrEqual(500);
|
||||
}
|
||||
});
|
||||
|
||||
it("wraps delegated input and appends the raw speakable result", async () => {
|
||||
const runAgentConsult = vi.fn(async ({ prompt }: { prompt: string }) => ({
|
||||
text: `Result for ${prompt}`,
|
||||
@@ -194,6 +211,53 @@ describe("GPT-Live sideband protocol", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("bounds browser delegation output before sideband sends", async () => {
|
||||
const runAgentConsult = vi.fn(async () => ({ text: "x".repeat(10_000) }));
|
||||
const { realtime, sockets } = createBroker({ runAgentConsult });
|
||||
try {
|
||||
const reservation = await realtime.broker.createBrowserSession(
|
||||
{ providerConfig: {}, model: "gpt-live-1", runAgentConsult },
|
||||
{ type: "api-key", token: "platform-key" },
|
||||
);
|
||||
if (reservation.transport !== "webrtc") {
|
||||
throw new Error("Expected WebRTC reservation");
|
||||
}
|
||||
await realtime.handler(
|
||||
createRequest({ token: reservation.clientSecret }),
|
||||
createResponseHarness().res,
|
||||
);
|
||||
const socket = sockets[0];
|
||||
if (!socket) {
|
||||
throw new Error("Expected sideband socket");
|
||||
}
|
||||
|
||||
emitSideband(socket, {
|
||||
type: "delegation.created",
|
||||
item: {
|
||||
type: "delegation",
|
||||
target: "client",
|
||||
id: "delegation-large",
|
||||
content: [{ type: "input_text", text: "summarize everything" }],
|
||||
},
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
const appends = parseSent(socket).filter(
|
||||
(event) => event.type === "delegation.context.append",
|
||||
);
|
||||
expect(appends.length).toBeGreaterThan(0);
|
||||
expect(appends.length).toBeLessThanOrEqual(11);
|
||||
expect(
|
||||
appends
|
||||
.map((event) => (event.content as Array<{ text: string }>)[0]?.text ?? "")
|
||||
.join(""),
|
||||
).toMatch(/^x+ \[truncated\]$/);
|
||||
});
|
||||
} finally {
|
||||
await realtime.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("adds the in-call transcript delta to each delegation and resets it", async () => {
|
||||
const runAgentConsult = vi.fn(async (_params: { prompt: string; signal?: AbortSignal }) => ({
|
||||
text: "Done",
|
||||
|
||||
@@ -626,6 +626,30 @@ describe("GPT-Live gateway relay bridge", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("bounds gateway delegation output before sideband sends", async () => {
|
||||
const runAgentConsult = vi.fn(async () => ({ text: "x".repeat(10_000) }));
|
||||
const { bridge, socket, testBridge } = createDelegationBridge(runAgentConsult);
|
||||
try {
|
||||
await testBridge.runDelegation({
|
||||
delegationId: "delegation-large",
|
||||
prompt: "summarize everything",
|
||||
runAgentConsult,
|
||||
signal: new AbortController().signal,
|
||||
});
|
||||
|
||||
const appends = parseSent(socket).filter(
|
||||
(event) => event.type === "delegation.context.append",
|
||||
);
|
||||
expect(appends.length).toBeGreaterThan(0);
|
||||
expect(appends.length).toBeLessThanOrEqual(11);
|
||||
expect(
|
||||
appends.map((event) => (event.content as Array<{ text: string }>)[0]?.text ?? "").join(""),
|
||||
).toMatch(/^x+ \[truncated\]$/);
|
||||
} finally {
|
||||
bridge.close();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps only the latest delegation when the superseded consult rejects on abort", async () => {
|
||||
const resolvers: Array<(value: { text: string }) => void> = [];
|
||||
const signals: AbortSignal[] = [];
|
||||
|
||||
Reference in New Issue
Block a user