mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-16 05:30:43 +00:00
test: tighten core ui helper assertions
This commit is contained in:
@@ -23,7 +23,6 @@ function requireMediaProvider(
|
||||
providerId: string,
|
||||
): MediaUnderstandingProvider {
|
||||
const provider = getMediaUnderstandingProvider(providerId, registry);
|
||||
expect(provider).toBeDefined();
|
||||
if (!provider) {
|
||||
throw new Error(`expected media-understanding provider ${providerId}`);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ afterEach(() => {
|
||||
|
||||
function getFirstGuardedFetchCall() {
|
||||
const call = fetchWithSsrFGuardMock.mock.calls[0]?.[0];
|
||||
expect(call).toBeTruthy();
|
||||
if (!call) {
|
||||
throw new Error("Expected fetchWithSsrFGuard to be called");
|
||||
}
|
||||
|
||||
@@ -34,6 +34,32 @@ function createTempHome(): string {
|
||||
return makeTempDir(tempDirs, "openclaw-test-env-real-home-");
|
||||
}
|
||||
|
||||
function requireRecord(
|
||||
value: Record<string, unknown> | undefined,
|
||||
label: string,
|
||||
): Record<string, unknown> {
|
||||
if (!value) {
|
||||
throw new Error(`expected copied ${label} config`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function requireTelegramStreaming(
|
||||
value:
|
||||
| {
|
||||
mode?: string;
|
||||
chunkMode?: string;
|
||||
block?: { enabled?: boolean };
|
||||
preview?: { chunk?: { minChars?: number } };
|
||||
}
|
||||
| undefined,
|
||||
) {
|
||||
if (!value) {
|
||||
throw new Error("expected copied telegram streaming config");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
while (cleanupFns.length > 0) {
|
||||
cleanupFns.pop()?.();
|
||||
@@ -141,29 +167,17 @@ describe("installTestEnv", () => {
|
||||
};
|
||||
};
|
||||
const providers = copiedConfig.models?.providers;
|
||||
expect(providers).toBeDefined();
|
||||
if (!providers) {
|
||||
throw new Error("expected copied model providers config");
|
||||
}
|
||||
requireRecord(providers, "model providers");
|
||||
expect(providers.custom).toEqual({ baseUrl: "https://example.test/v1" });
|
||||
|
||||
const agentDefaults = copiedConfig.agents?.defaults;
|
||||
const agentConfig = copiedConfig.agents?.list?.[0];
|
||||
expect(agentDefaults).toBeDefined();
|
||||
expect(agentConfig).toBeDefined();
|
||||
if (!agentDefaults || !agentConfig) {
|
||||
throw new Error("expected copied agent config");
|
||||
}
|
||||
const agentDefaults = requireRecord(copiedConfig.agents?.defaults, "agent defaults");
|
||||
const agentConfig = requireRecord(copiedConfig.agents?.list?.[0], "agent");
|
||||
expect(agentDefaults.workspace).toBeUndefined();
|
||||
expect(agentDefaults.agentDir).toBeUndefined();
|
||||
expect(agentConfig.workspace).toBeUndefined();
|
||||
expect(agentConfig.agentDir).toBeUndefined();
|
||||
|
||||
const telegramStreaming = copiedConfig.channels?.telegram?.streaming;
|
||||
expect(telegramStreaming).toBeDefined();
|
||||
if (!telegramStreaming) {
|
||||
throw new Error("expected copied telegram streaming config");
|
||||
}
|
||||
const telegramStreaming = requireTelegramStreaming(copiedConfig.channels?.telegram?.streaming);
|
||||
expect(telegramStreaming).toEqual({
|
||||
mode: "block",
|
||||
chunkMode: "newline",
|
||||
|
||||
@@ -58,7 +58,6 @@ describe("renderDebug", () => {
|
||||
);
|
||||
|
||||
const command = container.querySelector<HTMLElement>(".callout .mono");
|
||||
expect(command).toBeTruthy();
|
||||
if (!command) {
|
||||
throw new Error("expected debug security audit command");
|
||||
}
|
||||
|
||||
@@ -69,14 +69,11 @@ describe("computeFilteredUsage", () => {
|
||||
makePoint({ timestamp: 3000, totalTokens: 300, cost: 0.3 }),
|
||||
];
|
||||
const result = computeFilteredUsage(baseUsage, points, 1000, 2000);
|
||||
expect(result).toMatchObject({
|
||||
const filtered = expectFilteredUsage(result);
|
||||
expect(filtered).toMatchObject({
|
||||
totalTokens: 300, // 100 + 200
|
||||
});
|
||||
expect(result).toBeDefined();
|
||||
if (!result) {
|
||||
throw new Error("expected filtered usage aggregate");
|
||||
}
|
||||
expect(result.totalCost).toBeCloseTo(0.3); // 0.1 + 0.2
|
||||
expect(filtered.totalCost).toBeCloseTo(0.3); // 0.1 + 0.2
|
||||
});
|
||||
|
||||
it("handles reversed range (end < start)", () => {
|
||||
|
||||
Reference in New Issue
Block a user