mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(test): consolidate duplicated requireRecord and provider HTTP mock helpers (#119982)
* refactor(test): consolidate duplicated test helpers * test: remove stale record guard import * fix(test): remove orphaned record guards * refactor(test): keep record requirement messages exhaustively typed * fix(test): keep packages/ai record guard package-local
This commit is contained in:
committed by
GitHub
parent
f5e3b5ef54
commit
b4a26783f7
@@ -1,4 +1,3 @@
|
||||
// Alibaba tests cover video generation provider plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -9,6 +8,7 @@ import {
|
||||
import {
|
||||
getProviderHttpMocks,
|
||||
installProviderHttpMockCleanup,
|
||||
requireFirstPostJsonRecordRequest as requireFirstPostJsonRequest,
|
||||
} from "openclaw/plugin-sdk/provider-http-test-mocks";
|
||||
import {
|
||||
expectDashscopeVideoTaskPoll,
|
||||
@@ -16,6 +16,8 @@ import {
|
||||
expectSuccessfulDashscopeVideoResult,
|
||||
mockSuccessfulDashscopeVideoTask,
|
||||
} from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
// Alibaba tests cover video generation provider plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import {
|
||||
DASHSCOPE_WAN_VIDEO_MODELS,
|
||||
DEFAULT_DASHSCOPE_WAN_VIDEO_MODEL,
|
||||
@@ -50,20 +52,7 @@ function clearAlibabaAuthEnvironment(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function requireFirstPostJsonRequest(label: string): Record<string, unknown> {
|
||||
const [call] = postJsonRequestMock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return requireRecord(call[0], label);
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
describe("alibaba video generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
@@ -274,7 +263,7 @@ describe("alibaba video generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledOnce();
|
||||
const request = requireFirstPostJsonRequest("DashScope request");
|
||||
const request = requireFirstPostJsonRequest(postJsonRequestMock, "DashScope request");
|
||||
expect(request.url).toBe(
|
||||
"https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis",
|
||||
);
|
||||
@@ -338,7 +327,10 @@ describe("alibaba video generation provider", () => {
|
||||
request: requestPolicy,
|
||||
}),
|
||||
);
|
||||
const request = requireFirstPostJsonRequest("DashScope request with request policy");
|
||||
const request = requireFirstPostJsonRequest(
|
||||
postJsonRequestMock,
|
||||
"DashScope request with request policy",
|
||||
);
|
||||
expect(request.allowPrivateNetwork).toBe(true);
|
||||
expect(request.dispatcherPolicy).toBe(dispatcherPolicy);
|
||||
expect(request.headers).toBeInstanceOf(Headers);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Amazon Bedrock Mantle tests cover mantle anthropic plugin behavior.
|
||||
import type { Model } from "openclaw/plugin-sdk/llm";
|
||||
// Amazon Bedrock Mantle tests cover mantle anthropic plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createMantleAnthropicStreamFn } from "./mantle-anthropic.runtime.js";
|
||||
|
||||
@@ -29,12 +30,7 @@ function createTestDeps() {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object-capitalized");
|
||||
|
||||
function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0, argIndex = 0): unknown {
|
||||
const call = mock.mock.calls[index];
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Amazon Bedrock tests cover index plugin behavior.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
@@ -10,6 +9,8 @@ import {
|
||||
registerSingleProviderPlugin,
|
||||
} from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
import { withEnvAsync } from "openclaw/plugin-sdk/test-env";
|
||||
// Amazon Bedrock tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { supportsBedrockPromptCaching } from "./bedrock-options.js";
|
||||
import { resetBedrockDiscoveryCacheForTest } from "./discovery.js";
|
||||
@@ -237,12 +238,7 @@ function runtimePluginConfig(config?: Record<string, unknown>): OpenClawConfig {
|
||||
} as OpenClawConfig;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Anthropic tests cover index plugin behavior.
|
||||
import { calculateCost, type Usage } from "openclaw/plugin-sdk/llm";
|
||||
import type {
|
||||
ProviderResolveDynamicModelContext,
|
||||
@@ -9,6 +8,8 @@ import {
|
||||
capturePluginRegistration,
|
||||
registerSingleProviderPlugin,
|
||||
} from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
// Anthropic tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { readClaudeCliCredentialsForSetupMock, readClaudeCliCredentialsForRuntimeMock } = vi.hoisted(
|
||||
@@ -53,12 +54,7 @@ function createModelRegistry(models: ProviderRuntimeModel[]) {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectFields(value: unknown, fields: Record<string, unknown>) {
|
||||
const record = requireRecord(value, "record");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Browser tests cover agent.existing session plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { EXISTING_SESSION_LIMITS } from "./existing-session-limits.js";
|
||||
import {
|
||||
@@ -126,12 +127,7 @@ function getDialogHookPostHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
|
||||
+3
-11
@@ -1,8 +1,9 @@
|
||||
// Browser tests cover server.agent contract form layout act commands plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
// Browser tests cover server.agent contract form layout act commands plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import "../test-support/browser-security.mock.js";
|
||||
import { DEFAULT_DOWNLOAD_DIR, DEFAULT_TRACE_DIR, DEFAULT_UPLOAD_DIR } from "./paths.js";
|
||||
@@ -176,16 +177,7 @@ async function withSymlinkPathEscape<T>(params: {
|
||||
|
||||
type MockWithCalls = { mock: { calls: unknown[][] } };
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function expectRecordFields(value: unknown, label: string, expected: Record<string, unknown>) {
|
||||
const record = requireRecord(value, label);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Byteplus tests cover video generation provider plugin behavior.
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import { streamedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
// Submit/poll transport is mocked locally so each test can inject the BytePlus task JSON
|
||||
@@ -189,20 +190,6 @@ function streamedVideoResponse(bytes: string): Response {
|
||||
);
|
||||
}
|
||||
|
||||
// BytePlus submit/poll task JSON is now read through the byte-bounded reader, so the
|
||||
// mocked responses must expose a real readable body (not just a json() shortcut).
|
||||
function streamedJsonResponse(payload: unknown): Response {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(JSON.stringify(payload)));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ status: 200, headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}
|
||||
|
||||
// Builds a JSON body larger than the shared 16 MiB readProviderJsonResponse cap so the
|
||||
// bounded reader cancels the stream mid-flight; if the cap were removed the reader would
|
||||
// buffer the whole advertised payload before parsing. Tracks how many bytes were pulled
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Codex tests cover approval bridge plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -11,6 +10,8 @@ import {
|
||||
runBeforeToolCallHook,
|
||||
type EmbeddedRunAttemptParams,
|
||||
} from "openclaw/plugin-sdk/agent-harness-runtime";
|
||||
// Codex tests cover approval bridge plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { handleCodexAppServerApprovalRequest } from "./approval-bridge.js";
|
||||
import {
|
||||
@@ -46,12 +47,7 @@ const mockResolveNativeHookRelayDeferredToolApproval = vi.mocked(
|
||||
const mockReviewExecRequestWithConfiguredModel = vi.mocked(reviewExecRequestWithConfiguredModel);
|
||||
const mockRunBeforeToolCallHook = vi.mocked(runBeforeToolCallHook);
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-capitalized");
|
||||
|
||||
function gatewayCallAt(callIndex = 0) {
|
||||
const call = mockCallGatewayTool.mock.calls[callIndex];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Codex tests cover computer use plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
// Codex tests cover computer use plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveCodexAppServerRuntimeOptions } from "./config.js";
|
||||
import { acquireCodexNativeConfigFence } from "./native-config-fence.js";
|
||||
@@ -61,12 +62,7 @@ async function expectSetupErrorStatus(
|
||||
expectStatusFields(status, fields);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function requestCalls(
|
||||
request: CodexComputerUseRequest,
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Codex tests cover config plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "openclaw/plugin-sdk/number-runtime";
|
||||
import { withTempDir } from "openclaw/plugin-sdk/test-env";
|
||||
// Codex tests cover config plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
canUseCodexModelBackedApprovalsReviewerForModel,
|
||||
@@ -45,12 +46,7 @@ function envRef(id: string) {
|
||||
return { source: "env" as const, provider: "default", id };
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-capitalized");
|
||||
|
||||
function expectFields(
|
||||
value: unknown,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Codex tests cover dynamic tools plugin behavior.
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
@@ -26,6 +25,8 @@ import {
|
||||
createTestRegistry,
|
||||
setActivePluginRegistry,
|
||||
} from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
// Codex tests cover dynamic tools plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createOpenClawTestState } from "openclaw/plugin-sdk/test-state";
|
||||
import { estimateToolResultTextChars } from "openclaw/plugin-sdk/text-utility-runtime";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -105,12 +106,7 @@ function expectInputText(text: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
function callArg(
|
||||
mock: { mock: { calls: Array<Array<unknown>> } },
|
||||
callIndex: number,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Codex tests cover openclaw owned tool runtime contract plugin behavior.
|
||||
import type { AnyAgentTool } from "openclaw/plugin-sdk/agent-harness";
|
||||
import { wrapToolWithBeforeToolCallHook } from "openclaw/plugin-sdk/agent-harness-runtime";
|
||||
import {
|
||||
@@ -8,6 +7,8 @@ import {
|
||||
resetOpenClawOwnedToolHooks,
|
||||
textToolResult,
|
||||
} from "openclaw/plugin-sdk/agent-runtime-test-contracts";
|
||||
// Codex tests cover openclaw owned tool runtime contract plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createCodexDynamicToolBridge } from "./dynamic-tools.js";
|
||||
|
||||
@@ -21,12 +22,7 @@ function createContractTool(overrides: Partial<AnyAgentTool>): AnyAgentTool {
|
||||
} as unknown as AnyAgentTool;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Codex tests cover run attempt.context engine plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -20,6 +19,8 @@ import { createMockPluginRegistry } from "openclaw/plugin-sdk/plugin-test-runtim
|
||||
import { registerSandboxBackend } from "openclaw/plugin-sdk/sandbox";
|
||||
import { upsertSessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
|
||||
import { formatSqliteSessionFileMarker } from "openclaw/plugin-sdk/sqlite-runtime-testing";
|
||||
// Codex tests cover run attempt.context engine plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { readAttemptTerminal } from "./attempt-terminal.test-helper.js";
|
||||
import { shouldEnableCodexAppServerNativeToolSurface } from "./dynamic-tool-build.js";
|
||||
@@ -382,12 +383,7 @@ function createContextEngine(overrides: Partial<ContextEngine> = {}): ContextEng
|
||||
|
||||
type MockCallReader = { mock: { calls: unknown[][] } };
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function optionalString(value: unknown): string {
|
||||
return typeof value === "string" ? value : "";
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Codex tests cover commands plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -11,6 +10,8 @@ import {
|
||||
import { MODEL_SELECTION_LOCKED_MESSAGE } from "openclaw/plugin-sdk/model-session-runtime";
|
||||
import type { PluginCommandContext, PluginCommandResult } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { upsertSessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
|
||||
// Codex tests cover commands plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { CODEX_CONTROL_METHODS } from "./app-server/capabilities.js";
|
||||
import type { CodexComputerUseStatus } from "./app-server/computer-use.js";
|
||||
@@ -302,12 +303,7 @@ function codexRateLimitPayload(params: {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, message: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(message);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "message");
|
||||
|
||||
function mockCall(mockFn: ReturnType<typeof vi.fn>, callIndex = 0): ReadonlyArray<unknown> {
|
||||
const call = mockFn.mock.calls[callIndex];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Deepinfra tests cover speech provider plugin behavior.
|
||||
import { requireFirstPostJsonRequest } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { buildDeepInfraSpeechProvider } from "./speech-provider.js";
|
||||
|
||||
@@ -33,14 +34,6 @@ afterAll(() => {
|
||||
vi.resetModules();
|
||||
});
|
||||
|
||||
function requireFirstPostJsonRequest(): unknown {
|
||||
const [call] = postJsonRequestMock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected DeepInfra speech request");
|
||||
}
|
||||
return call[0];
|
||||
}
|
||||
|
||||
describe("deepinfra speech provider", () => {
|
||||
afterEach(() => {
|
||||
assertOkOrThrowHttpErrorMock.mockClear();
|
||||
@@ -126,7 +119,10 @@ describe("deepinfra speech provider", () => {
|
||||
],
|
||||
]);
|
||||
expect(postJsonRequestMock).toHaveBeenCalledOnce();
|
||||
const postRequest = requireFirstPostJsonRequest();
|
||||
const postRequest = requireFirstPostJsonRequest(
|
||||
postJsonRequestMock,
|
||||
"DeepInfra speech request",
|
||||
);
|
||||
const postRequestHeaders = Reflect.get(postRequest ?? {}, "headers");
|
||||
expect(postRequestHeaders).toBeInstanceOf(Headers);
|
||||
expect(Object.fromEntries((postRequestHeaders as Headers).entries())).toEqual({
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
import {
|
||||
getProviderHttpMocks,
|
||||
installProviderHttpMockCleanup,
|
||||
requireFirstPostJsonRequest,
|
||||
} from "openclaw/plugin-sdk/provider-http-test-mocks";
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
@@ -30,14 +31,6 @@ function mockSubmit(job: unknown, release = vi.fn(async () => {})): typeof relea
|
||||
return release;
|
||||
}
|
||||
|
||||
function requireFirstPostJsonRequest(): unknown {
|
||||
const [call] = postJsonRequestMock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected DeepInfra video submit request");
|
||||
}
|
||||
return call[0];
|
||||
}
|
||||
|
||||
describe("deepinfra video generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
expectExplicitVideoGenerationCapabilities(buildDeepInfraVideoGenerationProvider());
|
||||
@@ -101,7 +94,10 @@ describe("deepinfra video generation provider", () => {
|
||||
]);
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledOnce();
|
||||
const postRequest = requireFirstPostJsonRequest();
|
||||
const postRequest = requireFirstPostJsonRequest(
|
||||
postJsonRequestMock,
|
||||
"DeepInfra video submit request",
|
||||
);
|
||||
const postRequestHeaders = Reflect.get(postRequest ?? {}, "headers");
|
||||
expect(postRequestHeaders).toBeInstanceOf(Headers);
|
||||
expect(Object.fromEntries((postRequestHeaders as Headers).entries())).toEqual({
|
||||
@@ -196,9 +192,12 @@ describe("deepinfra video generation provider", () => {
|
||||
} as unknown as OpenClawConfig,
|
||||
});
|
||||
|
||||
expect(Reflect.get(requireFirstPostJsonRequest() ?? {}, "url")).toBe(
|
||||
"https://video.example.com/v1/openai/videos",
|
||||
);
|
||||
expect(
|
||||
Reflect.get(
|
||||
requireFirstPostJsonRequest(postJsonRequestMock, "DeepInfra video submit request") ?? {},
|
||||
"url",
|
||||
),
|
||||
).toBe("https://video.example.com/v1/openai/videos");
|
||||
expect(result.videos).toEqual([
|
||||
{
|
||||
url: "https://video.example.com/generated/custom.mp4",
|
||||
@@ -287,7 +286,10 @@ describe("deepinfra video generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledOnce();
|
||||
const postRequest = requireFirstPostJsonRequest();
|
||||
const postRequest = requireFirstPostJsonRequest(
|
||||
postJsonRequestMock,
|
||||
"DeepInfra video submit request",
|
||||
);
|
||||
expect(Reflect.get(Reflect.get(postRequest ?? {}, "body") ?? {}, "seed")).toBeUndefined();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Diffs tests cover config plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import {
|
||||
validateJsonSchemaValue,
|
||||
type JsonSchemaObject,
|
||||
} from "openclaw/plugin-sdk/json-schema-runtime";
|
||||
// Diffs tests cover config plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import {
|
||||
diffsPluginConfigSchema,
|
||||
@@ -63,12 +64,7 @@ function compileManifestConfigSchema() {
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectFields(value: unknown, fields: Record<string, unknown>) {
|
||||
const record = requireRecord(value, "record");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Discord tests cover monitor plugin behavior.
|
||||
import { danger } from "openclaw/plugin-sdk/runtime-env";
|
||||
import { typedCases } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createRequireRecord, typedCases } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ChannelType, type Guild } from "./internal/discord.js";
|
||||
import {
|
||||
@@ -949,12 +949,7 @@ function firstMockArg(mock: MockWithCalls, label: string) {
|
||||
return firstMockCall(mock, label)[0];
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label-object");
|
||||
|
||||
function makeReactionEvent(overrides?: {
|
||||
guildId?: string;
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Discord tests cover message utils plugin behavior.
|
||||
import {
|
||||
type APIAttachment,
|
||||
type APIStickerItem,
|
||||
MessageReferenceType,
|
||||
StickerFormatType,
|
||||
} from "discord-api-types/v10";
|
||||
// Discord tests cover message utils plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { Message } from "../internal/discord.js";
|
||||
|
||||
@@ -97,12 +98,7 @@ const DISCORD_CDN_HOSTNAMES = [
|
||||
"*.discordapp.net",
|
||||
];
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireArray(value: unknown, label: string): Array<unknown> {
|
||||
expect(Array.isArray(value), label).toBe(true);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Discord tests cover thread bindings.lifecycle plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -15,6 +14,8 @@ import {
|
||||
setRuntimeConfigSnapshot,
|
||||
type OpenClawConfig,
|
||||
} from "openclaw/plugin-sdk/runtime-config-snapshot";
|
||||
// Discord tests cover thread bindings.lifecycle plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { setDiscordRuntime } from "../runtime.js";
|
||||
import { EMPTY_DISCORD_TEST_CONFIG } from "../test-support/config.js";
|
||||
@@ -92,12 +93,7 @@ function createTestThreadBindingManager(
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-capitalized");
|
||||
|
||||
function expectFields(
|
||||
value: unknown,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Discord tests cover threading.auto thread plugin behavior.
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
// Discord tests cover threading.auto thread plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { ChannelType } from "../internal/discord.js";
|
||||
import { EMPTY_DISCORD_TEST_CONFIG } from "../test-support/config.js";
|
||||
@@ -57,12 +58,7 @@ async function flushAsyncWork() {
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Discord tests cover send.creates thread plugin behavior.
|
||||
import { ChannelType, MessageFlags, Routes } from "discord-api-types/v10";
|
||||
// Discord tests cover send.creates thread plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { loadWebMediaRaw } from "openclaw/plugin-sdk/web-media";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { RateLimitError } from "./internal/discord.js";
|
||||
@@ -45,12 +46,7 @@ type MockCallSource = {
|
||||
};
|
||||
};
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function mockArg(source: MockCallSource, callIndex: number, argIndex: number, label: string) {
|
||||
const call = source.mock.calls[callIndex];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Discord tests cover send.sends basic channel messages plugin behavior.
|
||||
import { ChannelType, MessageFlags, PermissionFlagsBits, Routes } from "discord-api-types/v10";
|
||||
// Discord tests cover send.sends basic channel messages plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { Container, TextDisplay } from "./internal/discord.js";
|
||||
import { discordWebMediaMockFactory, makeDiscordRest } from "./send.test-harness.js";
|
||||
@@ -113,16 +114,7 @@ beforeEach(() => {
|
||||
clearDiscordDirectoryCacheForTest();
|
||||
});
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Feishu tests cover bot.card action plugin behavior.
|
||||
import { createRuntimeEnv } from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
// Feishu tests cover bot.card action plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import type { ClawdbotConfig, RuntimeEnv } from "../runtime-api.js";
|
||||
import { processedCardActions, resolvedCardActionChatTypes } from "./card-action-state.js";
|
||||
@@ -133,12 +134,7 @@ describe("Feishu Card Action Handler", () => {
|
||||
return call[0];
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label-capitalized");
|
||||
|
||||
function handleMessageEvent(callIndex = 0) {
|
||||
const arg = requireRecord(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Feishu tests cover channel plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../runtime-api.js";
|
||||
import { feishuPlugin } from "./channel.js";
|
||||
@@ -82,12 +83,7 @@ function getDescribedActions(cfg: OpenClawConfig, accountId?: string): string[]
|
||||
return [...(feishuPlugin.actions?.describeMessageTool?.({ cfg, accountId })?.actions ?? [])];
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-capitalized");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Feishu tests cover docx plugin behavior.
|
||||
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
// Feishu tests cover docx plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { FEISHU_HTTP_TIMEOUT_MS } from "./client-timeout.js";
|
||||
import { createToolFactoryHarness, type ToolLike } from "./tool-factory-test-harness.js";
|
||||
@@ -69,12 +70,7 @@ type ToolResultWithDetails = {
|
||||
|
||||
const WORKSPACE_ROOT = path.resolve("/workspace");
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// File Transfer tests cover node invoke policy plugin behavior.
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import { gzipSync } from "node:zlib";
|
||||
import type { OpenClawPluginNodeInvokePolicyContext } from "openclaw/plugin-sdk/plugin-entry";
|
||||
// File Transfer tests cover node invoke policy plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { appendFileTransferAudit } from "./audit.js";
|
||||
import { createFileTransferNodeInvokePolicy } from "./node-invoke-policy.js";
|
||||
@@ -128,12 +129,7 @@ function createCtx(overrides: {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Google Meet tests cover index.create plugin behavior.
|
||||
import { Command } from "commander";
|
||||
// Google Meet tests cover index.create plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import plugin, { testing as googleMeetPluginTesting } from "./index.js";
|
||||
import { registerGoogleMeetCli } from "./src/cli.js";
|
||||
@@ -137,12 +138,7 @@ async function runCreateMeetBrowserScript(params: { buttonText: string }) {
|
||||
return { button, result: scriptResult };
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
type BrowserProxyBody = {
|
||||
fn?: string;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Google Meet tests cover index plugin behavior.
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -22,6 +21,8 @@ import type {
|
||||
RealtimeVoiceBridge,
|
||||
RealtimeVoiceProviderPlugin,
|
||||
} from "openclaw/plugin-sdk/realtime-voice";
|
||||
// Google Meet tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import plugin, { testing as googleMeetPluginTesting } from "./index.js";
|
||||
import { findGoogleMeetCalendarEvent, listGoogleMeetCalendarEvents } from "./src/calendar.js";
|
||||
@@ -612,12 +613,7 @@ function createMockSessionRuntime(sessionStore: Record<string, unknown>) {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`Expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object-capitalized");
|
||||
|
||||
function mockCall(mock: { mock: { calls: unknown[][] } }, callIndex = 0): unknown[] {
|
||||
const call = mock.mock.calls.at(callIndex);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Google tests cover video generation provider plugin behavior.
|
||||
import { mockPinnedHostnameResolution } from "openclaw/plugin-sdk/test-env";
|
||||
import { oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { createGoogleGenAIMock, downloadMock, generateVideosMock, getVideosOperationMock } =
|
||||
@@ -94,39 +95,6 @@ function fetchInputUrl(fetchMock: ReturnType<typeof vi.fn>, index: number): stri
|
||||
return input.url;
|
||||
}
|
||||
|
||||
function oversizedJsonResponse(params: { chunkCount: number; chunkSize: number }): {
|
||||
response: Response;
|
||||
getReadCount: () => number;
|
||||
wasCanceled: () => boolean;
|
||||
} {
|
||||
const chunk = new Uint8Array(params.chunkSize);
|
||||
let readCount = 0;
|
||||
let canceled = false;
|
||||
return {
|
||||
response: new Response(
|
||||
new ReadableStream<Uint8Array>({
|
||||
pull(controller) {
|
||||
if (readCount >= params.chunkCount) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
readCount += 1;
|
||||
controller.enqueue(chunk);
|
||||
},
|
||||
cancel() {
|
||||
canceled = true;
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
getReadCount: () => readCount,
|
||||
wasCanceled: () => canceled,
|
||||
};
|
||||
}
|
||||
|
||||
let ssrfMock: { mockRestore: () => void } | undefined;
|
||||
|
||||
describe("google video generation provider", () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Kilocode tests cover provider models plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({
|
||||
@@ -41,12 +42,7 @@ function requireModelById(
|
||||
return model;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireFirstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
|
||||
const [call] = mock.mock.calls;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Lmstudio tests cover setup plugin behavior.
|
||||
import { createDeferred } from "openclaw/plugin-sdk/extension-shared";
|
||||
import {
|
||||
createNonExitingRuntimeEnv,
|
||||
@@ -17,7 +16,8 @@ import {
|
||||
type ProviderCatalogContext,
|
||||
} from "openclaw/plugin-sdk/provider-setup";
|
||||
import type { WizardPrompter } from "openclaw/plugin-sdk/setup";
|
||||
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
// Lmstudio tests cover setup plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
LMSTUDIO_DEFAULT_API_KEY_ENV_VAR,
|
||||
@@ -265,12 +265,7 @@ function createMethodBoundWizardPrompterHarness(values: WizardPromptValues = {})
|
||||
return { prompter: new MethodBoundWizardPrompter(), note, text };
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function expectRecordFields(
|
||||
value: unknown,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Lmstudio tests cover stream plugin behavior.
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import { createAssistantMessageEventStream } from "openclaw/plugin-sdk/llm";
|
||||
// Lmstudio tests cover stream plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
let wrapLmstudioInferencePreload: typeof import("./stream.js").wrapLmstudioInferencePreload;
|
||||
@@ -38,12 +39,7 @@ afterAll(() => {
|
||||
|
||||
type StreamEvent = { type: string } & Record<string, unknown>;
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
// Lobster tests cover lobster runner plugin behavior.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
// Lobster tests cover lobster runner plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { createEmbeddedLobsterRunner, resolveLobsterCwd } from "./lobster-runner.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireFirstCallParam(calls: ReadonlyArray<readonly unknown[]>, label: string) {
|
||||
const call = calls[0];
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Lobster tests cover lobster tool plugin behavior.
|
||||
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
||||
// Lobster tests cover lobster tool plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawPluginApi, OpenClawPluginToolContext } from "../runtime-api.js";
|
||||
import { createLobsterTool } from "./lobster-tool.js";
|
||||
@@ -30,12 +31,7 @@ function fakeCtx(overrides: Partial<OpenClawPluginToolContext> = {}): OpenClawPl
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
describe("lobster plugin tool", () => {
|
||||
it("returns the Lobster envelope in details", async () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Matrix tests cover client plugin behavior.
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
// Matrix tests cover client plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { installMatrixTestRuntime } from "../test-runtime.js";
|
||||
import type { CoreConfig } from "../types.js";
|
||||
@@ -53,12 +54,7 @@ vi.mock("./client/logging.js", () => ({
|
||||
ensureMatrixSdkLoggingConfigured: authClientMocks.ensureMatrixSdkLoggingConfigured,
|
||||
}));
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Matrix tests cover events plugin behavior.
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
// Matrix tests cover events plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { CoreConfig } from "../../types.js";
|
||||
import type { MatrixAuth } from "../client.js";
|
||||
@@ -35,12 +36,7 @@ function expectBodiesExclude(bodies: string[], text: string) {
|
||||
expect(bodies.join("\n")).not.toContain(text);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Matrix tests cover handler plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -14,6 +13,8 @@ import {
|
||||
sessionDeliveryOrigin,
|
||||
upsertSessionEntry,
|
||||
} from "openclaw/plugin-sdk/session-store-runtime";
|
||||
// Matrix tests cover handler plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { installMatrixMonitorTestRuntime } from "../../test-runtime.js";
|
||||
import { MATRIX_OPENCLAW_FINALIZED_PREVIEW_KEY } from "../send/types.js";
|
||||
@@ -172,12 +173,7 @@ function createReactionHarness(params?: {
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireArray(value: unknown, label: string): Array<unknown> {
|
||||
expect(Array.isArray(value), label).toBe(true);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Matrix tests cover handler.thread root media plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { installMatrixMonitorTestRuntime } from "../../test-runtime.js";
|
||||
import {
|
||||
@@ -7,12 +8,7 @@ import {
|
||||
createMatrixTextMessageEvent,
|
||||
} from "./handler.test-helpers.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function readFirstMockArg(fn: unknown): unknown {
|
||||
return (fn as { mock: { calls: unknown[][] } }).mock.calls.at(0)?.[0];
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
// Matrix tests cover sdk plugin behavior.
|
||||
import "fake-indexeddb/auto";
|
||||
import { EventEmitter } from "node:events";
|
||||
import "fake-indexeddb/auto";
|
||||
import fs from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import os from "node:os";
|
||||
@@ -12,6 +11,8 @@ import { type MatrixEvent, MsgType } from "matrix-js-sdk/lib/matrix.js";
|
||||
import { EventStatus } from "matrix-js-sdk/lib/models/event-status.js";
|
||||
import { SyncApi, SyncState } from "matrix-js-sdk/lib/sync.js";
|
||||
import { resetPluginStateStoreForTests } from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
// Matrix tests cover sdk plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { installMatrixTestRuntime } from "../test-runtime.js";
|
||||
import { readMatrixRecoveryKeyStateForPath } from "./crypto-state-store.js";
|
||||
@@ -32,12 +33,7 @@ function requestUrl(input: RequestInfo | URL | undefined): string {
|
||||
return input.url;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Matrix tests cover send plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -6,6 +5,8 @@ import {
|
||||
resetPluginBlobStoreForTests,
|
||||
resetPluginStateStoreForTests,
|
||||
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
// Matrix tests cover send plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { PluginRuntime } from "../../runtime-api.js";
|
||||
import { setMatrixRuntime } from "../runtime.js";
|
||||
@@ -165,12 +166,7 @@ function makeEncryptedMediaClient() {
|
||||
return result;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireArray(value: unknown, label: string): Array<unknown> {
|
||||
expect(Array.isArray(value), label).toBe(true);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Matrix tests cover subagent hooks plugin behavior.
|
||||
import type { OpenClawPluginApi as MatrixEntryPluginApi } from "openclaw/plugin-sdk/channel-entry-contract";
|
||||
import {
|
||||
getRequiredHookHandler,
|
||||
registerHookHandlersForTest,
|
||||
} from "openclaw/plugin-sdk/channel-test-helpers";
|
||||
// Matrix tests cover subagent hooks plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { registerMatrixSubagentHooks } from "../../subagent-hooks-api.js";
|
||||
|
||||
@@ -158,12 +159,7 @@ function makeDeliveryResult(
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
// Moonshot tests cover media understanding provider plugin behavior.
|
||||
import {
|
||||
createRequestCaptureJsonFetch,
|
||||
@@ -18,39 +19,6 @@ async function describeVideo(
|
||||
return await handler(params);
|
||||
}
|
||||
|
||||
function oversizedJsonResponse(params: { chunkCount: number; chunkSize: number }): {
|
||||
response: Response;
|
||||
getReadCount: () => number;
|
||||
wasCanceled: () => boolean;
|
||||
} {
|
||||
const chunk = new Uint8Array(params.chunkSize);
|
||||
let readCount = 0;
|
||||
let canceled = false;
|
||||
return {
|
||||
response: new Response(
|
||||
new ReadableStream<Uint8Array>({
|
||||
pull(controller) {
|
||||
if (readCount >= params.chunkCount) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
readCount += 1;
|
||||
controller.enqueue(chunk);
|
||||
},
|
||||
cancel() {
|
||||
canceled = true;
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
getReadCount: () => readCount,
|
||||
wasCanceled: () => canceled,
|
||||
};
|
||||
}
|
||||
|
||||
describe("describeMoonshotVideo", () => {
|
||||
it("builds an OpenAI-compatible video request", async () => {
|
||||
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Ollama tests cover index plugin behavior.
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import type { ProviderAuthMethod } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
|
||||
import { clearLiveCatalogCacheForTests } from "openclaw/plugin-sdk/provider-catalog-shared";
|
||||
// Ollama tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import plugin from "./index.js";
|
||||
import { OLLAMA_DEFAULT_API_KEY } from "./src/discovery-shared.js";
|
||||
@@ -177,12 +178,7 @@ function createOllamaResetValidationContext(
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireConfiguredStreamParams(): Record<string, unknown> {
|
||||
return requireRecord(createConfiguredOllamaStreamFnMock.mock.calls[0]?.[0], "stream params");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Ollama tests cover stream runtime plugin behavior.
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
// Ollama tests cover stream runtime plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { fetchWithSsrFGuardMock, ollamaStreamWarnMock } = vi.hoisted(() => ({
|
||||
@@ -44,12 +45,7 @@ function requireEntry<T>(entries: readonly T[], index: number, context: string):
|
||||
return expectDefined(entries[index], context);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireOptionalRecord(value: unknown): Record<string, unknown> | undefined {
|
||||
return value === undefined ? undefined : requireRecord(value, "request options");
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Opencode Go tests cover index plugin behavior.
|
||||
import { clampThinkingLevel } from "openclaw/plugin-sdk/llm";
|
||||
import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import {
|
||||
@@ -8,6 +7,8 @@ import {
|
||||
import { NON_ENV_SECRETREF_MARKER } from "openclaw/plugin-sdk/provider-auth-runtime";
|
||||
import { clearLiveCatalogCacheForTests } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
||||
import { expectPassthroughReplayPolicy } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
// Opencode Go tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import plugin from "./index.js";
|
||||
import manifest from "./openclaw.plugin.json" with { type: "json" };
|
||||
@@ -17,12 +18,7 @@ import {
|
||||
} from "./provider-catalog.js";
|
||||
import opencodeGoProviderDiscovery from "./provider-discovery.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireMapEntry<T>(map: Map<string, T>, id: string): T {
|
||||
const entry = map.get(id);
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Opencode tests cover index plugin behavior.
|
||||
import { readFileSync } from "node:fs";
|
||||
import type { ProviderRuntimeModel } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import {
|
||||
@@ -9,17 +8,14 @@ import {
|
||||
import { NON_ENV_SECRETREF_MARKER } from "openclaw/plugin-sdk/provider-auth-runtime";
|
||||
import { clearLiveCatalogCacheForTests } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
||||
import { expectPassthroughReplayPolicy } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
// Opencode tests cover index plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import plugin from "./index.js";
|
||||
import manifest from "./openclaw.plugin.json" with { type: "json" };
|
||||
import { buildOpencodeZenLiveProviderConfig } from "./provider-catalog.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireMapEntry<T>(map: Map<string, T>, id: string): T {
|
||||
const entry = map.get(id);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Openrouter tests cover video generation provider plugin behavior.
|
||||
import { clearLiveCatalogCacheForTests } from "openclaw/plugin-sdk/provider-catalog-shared";
|
||||
import {
|
||||
expectExplicitVideoGenerationCapabilities,
|
||||
expectUnifiedModelCatalogEntries,
|
||||
} from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
// Openrouter tests cover video generation provider plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildOpenRouterVideoGenerationProvider,
|
||||
@@ -142,12 +143,7 @@ function requireFetchCallHeaders(index: number): Headers {
|
||||
return new Headers(init.headers);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import {
|
||||
getProviderHttpMocks,
|
||||
installProviderHttpMockCleanup,
|
||||
oversizedJsonResponse,
|
||||
streamedJsonResponse,
|
||||
} from "openclaw/plugin-sdk/provider-http-test-mocks";
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
@@ -56,18 +58,6 @@ function pollFetchHeaders(callIndex: number): Headers | undefined {
|
||||
return (init as { headers?: Headers } | undefined)?.headers;
|
||||
}
|
||||
|
||||
function streamedJsonResponse(payload: unknown): Response {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(JSON.stringify(payload)));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}
|
||||
|
||||
function mockPixVerseVideoSubmit(videoId = 123) {
|
||||
postJsonRequestMock.mockResolvedValue({
|
||||
response: streamedJsonResponse({
|
||||
@@ -107,37 +97,6 @@ function mockPixVerseVideoTask(
|
||||
});
|
||||
}
|
||||
|
||||
// Drives an unbounded JSON body (>16 MiB, no Content-Length) so the bounded
|
||||
// reader has to cancel the stream instead of buffering it all. A hard ceiling
|
||||
// guards the test from hanging if the reader ever fails to cancel.
|
||||
function oversizedJsonResponse(): {
|
||||
response: Response;
|
||||
state: { canceled: boolean; enqueuedBytes: number };
|
||||
} {
|
||||
const state = { canceled: false, enqueuedBytes: 0 };
|
||||
const chunk = 1024 * 1024;
|
||||
const maxChunks = 64; // 64 MiB ceiling, 4x the 16 MiB cap.
|
||||
let emitted = 0;
|
||||
const response = new Response(
|
||||
new ReadableStream({
|
||||
pull(controller) {
|
||||
if (emitted >= maxChunks) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
emitted += 1;
|
||||
state.enqueuedBytes += chunk;
|
||||
controller.enqueue(new Uint8Array(chunk));
|
||||
},
|
||||
cancel() {
|
||||
state.canceled = true;
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
return { response, state };
|
||||
}
|
||||
|
||||
describe("pixverse video generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
expectExplicitVideoGenerationCapabilities(buildPixVerseVideoGenerationProvider());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Qa Lab tests cover server plugin behavior.
|
||||
import { once } from "node:events";
|
||||
// Qa Lab tests cover server plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { WebSocket } from "ws";
|
||||
import { readQaMockRequestCursor } from "../shared/debug-request-cursor.js";
|
||||
@@ -216,12 +217,7 @@ function expectOpenAiStreamingResponsesText(server: MockServer, body: Record<str
|
||||
return expectStreamingResponsesText(server, { model: "gpt-5.6-luna", ...body });
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-capitalized");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
// Qwen tests cover media understanding provider plugin behavior.
|
||||
import {
|
||||
createRequestCaptureJsonFetch,
|
||||
@@ -23,39 +24,6 @@ describe("qwen media understanding provider", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function oversizedJsonResponse(params: { chunkCount: number; chunkSize: number }): {
|
||||
response: Response;
|
||||
getReadCount: () => number;
|
||||
wasCanceled: () => boolean;
|
||||
} {
|
||||
const chunk = new Uint8Array(params.chunkSize);
|
||||
let readCount = 0;
|
||||
let canceled = false;
|
||||
return {
|
||||
response: new Response(
|
||||
new ReadableStream<Uint8Array>({
|
||||
pull(controller) {
|
||||
if (readCount >= params.chunkCount) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
readCount += 1;
|
||||
controller.enqueue(chunk);
|
||||
},
|
||||
cancel() {
|
||||
canceled = true;
|
||||
},
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
},
|
||||
),
|
||||
getReadCount: () => readCount,
|
||||
wasCanceled: () => canceled,
|
||||
};
|
||||
}
|
||||
|
||||
describe("describeQwenVideo", () => {
|
||||
it("builds the expected OpenAI-compatible video payload", async () => {
|
||||
const { fetchFn, getRequest } = createRequestCaptureJsonFetch({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Slack tests cover action runtime plugin behavior.
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
// Slack tests cover action runtime plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SlackActionContext } from "./action-runtime.js";
|
||||
import { handleSlackAction, slackActionRuntime } from "./action-runtime.js";
|
||||
@@ -90,12 +91,7 @@ describe("handleSlackAction", () => {
|
||||
return { cfg, context, hasRepliedRef };
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
expect(Array.isArray(value)).toBe(true);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Slack tests cover channel plugin behavior.
|
||||
import { createRuntimeEnv } from "openclaw/plugin-sdk/plugin-test-runtime";
|
||||
// Slack tests cover channel plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { slackPlugin } from "./channel.js";
|
||||
import { slackOutbound } from "./outbound-adapter.js";
|
||||
@@ -147,12 +148,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Slack tests cover interactions plugin behavior.
|
||||
import type { SlackShortcutMiddlewareArgs } from "@slack/bolt";
|
||||
// Slack tests cover interactions plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const enqueueSystemEventMock = vi.hoisted(() => vi.fn());
|
||||
@@ -347,12 +348,7 @@ function mockCallArg(mock: unknown, index: number, label: string, argIndex = 0):
|
||||
return call[argIndex];
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label-capitalized");
|
||||
|
||||
function hasLoneSurrogate(value: string): boolean {
|
||||
return Array.from(value).some((char) => {
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
type LookupFn,
|
||||
type SsrFPolicy,
|
||||
} from "openclaw/plugin-sdk/ssrf-runtime";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
resolveSlackAttachmentContent,
|
||||
@@ -186,12 +187,7 @@ function requireMockCall(mock: unknown, index: number, label: string): unknown[]
|
||||
return call;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function expectFetchCalledWithUrl(mock: unknown, expectedUrl: string): void {
|
||||
expect(requireMockCall(mock, 0, "fetch")[0]).toBe(expectedUrl);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Slack tests cover dispatch.preview fallback plugin behavior.
|
||||
import type { GetReplyOptions, ReplyPayload } from "openclaw/plugin-sdk/reply-runtime";
|
||||
// Slack tests cover dispatch.preview fallback plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const FINAL_REPLY_TEXT = "final answer";
|
||||
@@ -176,12 +177,7 @@ function requireCapturedItemEventHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Synology Chat tests cover channel.integration plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
buildChannelInboundEventContextMock,
|
||||
@@ -25,12 +26,7 @@ function makeStartContext<T>(cfg: T, accountId: string, abortSignal: AbortSignal
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireMockCall<TArgs extends unknown[]>(
|
||||
mock: { mock: { calls: TArgs[] } },
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Telegram tests cover action runtime plugin behavior.
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
import { resolveStorePath } from "openclaw/plugin-sdk/session-store-runtime";
|
||||
import { captureEnv } from "openclaw/plugin-sdk/test-env";
|
||||
// Telegram tests cover action runtime plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createOpenClawTestState, type OpenClawTestState } from "openclaw/plugin-sdk/test-state";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -256,12 +257,7 @@ type MockCallSource = {
|
||||
};
|
||||
};
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function mockCall(source: MockCallSource, callIndex: number, label: string) {
|
||||
const call = source.mock.calls[callIndex];
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Telegram tests cover bot native commands.session meta plugin behavior.
|
||||
import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
||||
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
|
||||
@@ -6,6 +5,8 @@ import { resolveChunkMode } from "openclaw/plugin-sdk/reply-dispatch-runtime";
|
||||
import { resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
||||
import type { ResolvedAgentRoute } from "openclaw/plugin-sdk/routing";
|
||||
import type { SessionEntry } from "openclaw/plugin-sdk/session-store-runtime";
|
||||
// Telegram tests cover bot native commands.session meta plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { TelegramNativeCommandDeps } from "./bot-native-command-deps.runtime.js";
|
||||
import {
|
||||
@@ -575,12 +576,7 @@ function requireValue<T>(value: T | null | undefined, label: string): T {
|
||||
return value;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function firstMockArg(mockFn: ReturnType<typeof vi.fn>, label: string, callIndex = 0): unknown {
|
||||
const call = mockFn.mock.calls.at(callIndex);
|
||||
|
||||
@@ -19,7 +19,7 @@ import type {
|
||||
} from "openclaw/plugin-sdk/plugin-state-runtime";
|
||||
import type { GetReplyOptions, MsgContext } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { withEnvAsync } from "openclaw/plugin-sdk/test-env";
|
||||
import { sanitizeTerminalText } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createRequireRecord, sanitizeTerminalText } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createTelegramNativeCommandTestDeps,
|
||||
@@ -386,12 +386,7 @@ function createDeferred<T = void>() {
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function expectRecordFields(
|
||||
value: unknown,
|
||||
|
||||
+2
-6
@@ -1,4 +1,5 @@
|
||||
// Telegram tests cover bot.mediaownloads media file path no file download plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
readRemoteMediaBufferSpy,
|
||||
@@ -39,12 +40,7 @@ function replyPayload(replySpy: ReturnType<typeof vi.fn>, index = 0): ReplyPaylo
|
||||
return payload as ReplyPayload;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record-short");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
} from "openclaw/plugin-sdk/session-store-runtime";
|
||||
import { appendSessionTranscriptMessageByIdentity } from "openclaw/plugin-sdk/session-transcript-runtime";
|
||||
import { mockPinnedHostnameResolution } from "openclaw/plugin-sdk/test-env";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createOpenClawTestState, type OpenClawTestState } from "openclaw/plugin-sdk/test-state";
|
||||
import {
|
||||
registerSessionBindingAdapter,
|
||||
@@ -344,12 +345,7 @@ type MockCallSource = {
|
||||
};
|
||||
};
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
expect(Array.isArray(value), label).toBe(true);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Telegram tests cover delivery.resolve media retry plugin behavior.
|
||||
import { GrammyError } from "grammy";
|
||||
import type { Message } from "grammy/types";
|
||||
import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
|
||||
// Telegram tests cover delivery.resolve media retry plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveMedia } from "./delivery.resolve-media.js";
|
||||
import type { TelegramContext } from "./types.js";
|
||||
@@ -243,12 +244,7 @@ function requireResolvedMedia(
|
||||
return result;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Telegram tests cover delivery.resolve media retry plugin behavior.
|
||||
import type { Message } from "grammy/types";
|
||||
import { sleepWithAbort } from "openclaw/plugin-sdk/runtime-env";
|
||||
// Telegram tests cover delivery.resolve media retry plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolveMedia } from "./delivery.resolve-media.js";
|
||||
import type { TelegramContext } from "./types.js";
|
||||
@@ -195,12 +196,7 @@ function requireResolvedMedia(
|
||||
return result;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
createPluginStateSyncKeyedStoreForTests,
|
||||
resetPluginStateStoreForTests,
|
||||
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { createRequireRecord, importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { markdownToTelegramHtml, telegramHtmlToPlainTextFallback } from "./format.js";
|
||||
import {
|
||||
@@ -365,12 +365,7 @@ function requireString(value: unknown, label: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectMediaSendCall(
|
||||
call: unknown[] | undefined,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Telegram tests cover webhook plugin behavior.
|
||||
import { createHash } from "node:crypto";
|
||||
import { once } from "node:events";
|
||||
import fs from "node:fs/promises";
|
||||
@@ -10,6 +9,8 @@ import {
|
||||
closeOpenClawStateDatabaseForTest,
|
||||
createChannelIngressQueueForTests as createChannelIngressQueue,
|
||||
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
// Telegram tests cover webhook plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { WEBHOOK_RATE_LIMIT_DEFAULTS } from "openclaw/plugin-sdk/webhook-ingress";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { buildTelegramApprovalCallbackData } from "./approval-callback-data.js";
|
||||
@@ -221,12 +222,7 @@ function resetTelegramWebhookMocks(): void {
|
||||
|
||||
type MockCallReader = { mock: { calls: unknown[][] } };
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function requireMockCall(mock: unknown, index: number, label: string): unknown[] {
|
||||
const call = (mock as MockCallReader).mock.calls.at(index);
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// Together tests cover video generation provider plugin behavior.
|
||||
import {
|
||||
getProviderHttpMocks,
|
||||
installProviderHttpMockCleanup,
|
||||
oversizedJsonResponse,
|
||||
requireFirstPostJsonRecordRequest as requireFirstPostJsonRequest,
|
||||
streamedJsonResponse,
|
||||
} from "openclaw/plugin-sdk/provider-http-test-mocks";
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
// Together tests cover video generation provider plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { postJsonRequestMock, fetchWithTimeoutMock } = getProviderHttpMocks();
|
||||
@@ -16,20 +20,7 @@ beforeAll(async () => {
|
||||
|
||||
installProviderHttpMockCleanup();
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function requireFirstPostJsonRequest(label: string): Record<string, unknown> {
|
||||
const [call] = postJsonRequestMock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return requireRecord(call[0], label);
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function streamingResponse(params: {
|
||||
body: string;
|
||||
@@ -48,49 +39,6 @@ function streamingResponse(params: {
|
||||
return new Response(stream, { headers: params.headers });
|
||||
}
|
||||
|
||||
function streamedJsonResponse(payload: unknown): Response {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(JSON.stringify(payload)));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}
|
||||
|
||||
// Drives an unbounded JSON body (>16 MiB, no Content-Length) so the bounded
|
||||
// reader has to cancel the stream instead of buffering it all. A hard ceiling
|
||||
// guards the test from hanging if the reader ever fails to cancel.
|
||||
function oversizedJsonResponse(): {
|
||||
response: Response;
|
||||
state: { canceled: boolean; enqueuedBytes: number };
|
||||
} {
|
||||
const state = { canceled: false, enqueuedBytes: 0 };
|
||||
const chunk = 1024 * 1024;
|
||||
const maxChunks = 64; // 64 MiB ceiling, 4x the 16 MiB cap.
|
||||
let emitted = 0;
|
||||
const response = new Response(
|
||||
new ReadableStream({
|
||||
pull(controller) {
|
||||
if (emitted >= maxChunks) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
emitted += 1;
|
||||
state.enqueuedBytes += chunk;
|
||||
controller.enqueue(new Uint8Array(chunk));
|
||||
},
|
||||
cancel() {
|
||||
state.canceled = true;
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
return { response, state };
|
||||
}
|
||||
|
||||
describe("together video generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
expectExplicitVideoGenerationCapabilities(buildTogetherVideoGenerationProvider());
|
||||
@@ -135,7 +83,7 @@ describe("together video generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledOnce();
|
||||
const request = requireFirstPostJsonRequest("Together request");
|
||||
const request = requireFirstPostJsonRequest(postJsonRequestMock, "Together request");
|
||||
expect(request.url).toBe("https://api.together.xyz/v2/videos");
|
||||
const body = requireRecord(request.body, "Together request body");
|
||||
expect(body.model).toBe("Wan-AI/Wan2.2-T2V-A14B");
|
||||
@@ -377,7 +325,7 @@ describe("together video generation provider", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const request = requireFirstPostJsonRequest("Together request");
|
||||
const request = requireFirstPostJsonRequest(postJsonRequestMock, "Together request");
|
||||
expect(request.url).toBe("https://api.together.xyz/v2/videos");
|
||||
});
|
||||
|
||||
@@ -410,7 +358,7 @@ describe("together video generation provider", () => {
|
||||
cfg: {},
|
||||
});
|
||||
|
||||
const request = requireFirstPostJsonRequest("Together request");
|
||||
const request = requireFirstPostJsonRequest(postJsonRequestMock, "Together request");
|
||||
const body = requireRecord(request.body, "Together request body");
|
||||
expect(body).not.toHaveProperty("seconds");
|
||||
});
|
||||
@@ -471,7 +419,7 @@ describe("together video generation provider", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const request = requireFirstPostJsonRequest("Together request");
|
||||
const request = requireFirstPostJsonRequest(postJsonRequestMock, "Together request");
|
||||
const body = requireRecord(request.body, "Together request body");
|
||||
const media = requireRecord(body.media, "Together video media payload");
|
||||
expect(body.model).toBe("Wan-AI/Wan2.2-I2V-A14B");
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Voice Call tests cover manager.notify plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createManagerHarness, FakeProvider } from "./manager.test-harness.js";
|
||||
|
||||
@@ -77,12 +78,7 @@ function requireFirstPlayTtsCall(provider: FakeProvider) {
|
||||
return call;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireSingleStartListeningCall(provider: FakeProvider) {
|
||||
expect(provider.startListeningCalls).toHaveLength(1);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Voice Call tests cover manager.restore plugin behavior.
|
||||
import type { OpenKeyedStoreOptions } from "openclaw/plugin-sdk/plugin-state-runtime";
|
||||
import {
|
||||
createPluginStateSyncKeyedStoreForTests,
|
||||
resetPluginStateStoreForTests,
|
||||
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
|
||||
// Voice Call tests cover manager.restore plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { VoiceCallConfigSchema } from "./config.js";
|
||||
import { CallManager } from "./manager.js";
|
||||
@@ -46,12 +47,7 @@ function requireSingleActiveCall(manager: CallManager) {
|
||||
return activeCall;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireSingleHangupCall(provider: FakeProvider) {
|
||||
expect(provider.hangupCalls).toHaveLength(1);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Voice Call tests cover runtime plugin behavior.
|
||||
import type { OpenClawConfig } from "openclaw/plugin-sdk/core";
|
||||
// Voice Call tests cover runtime plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { VoiceCallConfig } from "./config.js";
|
||||
import type { CoreConfig } from "./core-bridge.js";
|
||||
@@ -207,12 +208,7 @@ function createMockSessionRuntime(sessionStore: Record<string, unknown>) {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireRealtimeConsultToolHandler(): RealtimeConsultToolHandler {
|
||||
const registeredToolHandler = firstMockCall(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { bufferedOversizedJsonResponse as oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
// Vydra tests cover image generation provider plugin behavior.
|
||||
import { installPinnedHostnameTestHooks } from "openclaw/plugin-sdk/test-media-understanding";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -17,13 +18,6 @@ function fetchCall(fetchMock: ReturnType<typeof vi.fn>, index = 0): [string, Req
|
||||
return call as [string, RequestInit];
|
||||
}
|
||||
|
||||
function oversizedJsonResponse(): Response {
|
||||
return new Response(Buffer.alloc(16 * 1024 * 1024 + 1, 0x20), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
describe("vydra image-generation provider", () => {
|
||||
installPinnedHostnameTestHooks();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { bufferedOversizedJsonResponse as oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
// Vydra tests cover speech provider plugin behavior.
|
||||
import { installPinnedHostnameTestHooks } from "openclaw/plugin-sdk/test-media-understanding";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
@@ -9,12 +10,6 @@ describe("vydra speech provider", () => {
|
||||
const provider = buildVydraSpeechProvider();
|
||||
const originalVydraApiKey = process.env.VYDRA_API_KEY;
|
||||
|
||||
const oversizedJsonResponse = () =>
|
||||
new Response(Buffer.alloc(16 * 1024 * 1024 + 1, 0x20), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
if (originalVydraApiKey === undefined) {
|
||||
delete process.env.VYDRA_API_KEY;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Vydra tests cover video generation provider plugin behavior.
|
||||
import * as providerHttp from "openclaw/plugin-sdk/provider-http";
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import { bufferedOversizedJsonResponse as oversizedJsonResponse } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { installPinnedHostnameTestHooks } from "openclaw/plugin-sdk/test-media-understanding";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -19,13 +20,6 @@ function fetchCall(fetchMock: ReturnType<typeof vi.fn>, index: number) {
|
||||
return call;
|
||||
}
|
||||
|
||||
function oversizedJsonResponse(): Response {
|
||||
return new Response(Buffer.alloc(16 * 1024 * 1024 + 1, 0x20), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
describe("vydra video-generation provider", () => {
|
||||
installPinnedHostnameTestHooks();
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Whatsapp tests cover deliver reply plugin behavior.
|
||||
import type { WAMessage } from "baileys";
|
||||
import {
|
||||
createChannelPartialDeliveryError,
|
||||
@@ -8,6 +7,8 @@ import { listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbo
|
||||
import { PlatformMessageNotDispatchedError } from "openclaw/plugin-sdk/error-runtime";
|
||||
import { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS } from "openclaw/plugin-sdk/media-runtime";
|
||||
import { logVerbose } from "openclaw/plugin-sdk/runtime-env";
|
||||
// Whatsapp tests cover deliver reply plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { createWebSendApi } from "../inbound/send-api.js";
|
||||
import { normalizeWhatsAppSendResult } from "../inbound/send-result.js";
|
||||
@@ -110,12 +111,7 @@ function expectFirstSendMediaPayload(msg: AdmittedWebInboundMessage) {
|
||||
return requireRecord(mockCallArg(msg.platform.sendMedia, 0, 0, "sendMedia"), "sendMedia payload");
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label");
|
||||
|
||||
function mockCallArg(mock: unknown, callIndex: number, argIndex: number, label: string) {
|
||||
const call = (mock as MockWithCalls).mock.calls.at(callIndex);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Whatsapp tests cover inbound dispatch plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest";
|
||||
import { createTestWebInboundMessage } from "../../inbound/test-message.test-helper.js";
|
||||
|
||||
@@ -423,12 +424,7 @@ function getCapturedReplyOptions() {
|
||||
return (capturedDispatchParams as CapturedDispatchParams)?.replyOptions;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Whatsapp tests cover send api plugin behavior.
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
@@ -9,6 +8,8 @@ import {
|
||||
} from "openclaw/plugin-sdk/channel-inbound";
|
||||
import { listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbound";
|
||||
import { PlatformMessageNotDispatchedError } from "openclaw/plugin-sdk/error-runtime";
|
||||
// Whatsapp tests cover send api plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { prepareWhatsAppOutboundMedia } from "../outbound-media-contract.js";
|
||||
import { resolveWhatsAppOutboundMentions } from "./outbound-mentions.js";
|
||||
@@ -42,12 +43,7 @@ vi.mock("openclaw/plugin-sdk/media-runtime", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
type MockCallSource = {
|
||||
mock: {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
import {
|
||||
getProviderHttpMocks,
|
||||
installProviderHttpMockCleanup,
|
||||
oversizedJsonResponse,
|
||||
streamedJsonResponse,
|
||||
} from "openclaw/plugin-sdk/provider-http-test-mocks";
|
||||
import { expectExplicitVideoGenerationCapabilities } from "openclaw/plugin-sdk/provider-test-contracts";
|
||||
import type { VideoGenerationRequest } from "openclaw/plugin-sdk/video-generation";
|
||||
@@ -150,52 +152,6 @@ function streamedVideoResponse(bytes: string, contentType = "video/mp4"): Respon
|
||||
);
|
||||
}
|
||||
|
||||
function streamedJsonResponse(payload: unknown): Response {
|
||||
return new Response(
|
||||
new ReadableStream({
|
||||
start(controller) {
|
||||
controller.enqueue(new TextEncoder().encode(JSON.stringify(payload)));
|
||||
controller.close();
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
}
|
||||
|
||||
// Drives an unbounded JSON body (>16 MiB, no Content-Length) so the bounded
|
||||
// reader has to cancel the stream instead of buffering it all. The 1 MiB
|
||||
// chunks are emitted lazily on `pull`, and a hard ceiling guards the test from
|
||||
// hanging if the reader ever fails to cancel.
|
||||
function oversizedJsonResponse(): {
|
||||
response: Response;
|
||||
state: { canceled: boolean; enqueuedBytes: number };
|
||||
} {
|
||||
const state = { canceled: false, enqueuedBytes: 0 };
|
||||
const chunk = 1024 * 1024;
|
||||
// 64 MiB ceiling: 4x the 16 MiB cap, so the bounded reader must cancel long
|
||||
// before we run out of chunks.
|
||||
const maxChunks = 64;
|
||||
let emitted = 0;
|
||||
const response = new Response(
|
||||
new ReadableStream({
|
||||
pull(controller) {
|
||||
if (emitted >= maxChunks) {
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
emitted += 1;
|
||||
state.enqueuedBytes += chunk;
|
||||
controller.enqueue(new Uint8Array(chunk));
|
||||
},
|
||||
cancel() {
|
||||
state.canceled = true;
|
||||
},
|
||||
}),
|
||||
{ headers: { "content-type": "application/json" } },
|
||||
);
|
||||
return { response, state };
|
||||
}
|
||||
|
||||
describe("xai video generation provider", () => {
|
||||
it("declares explicit mode capabilities", () => {
|
||||
const provider = buildXaiVideoGenerationProvider();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// Zalouser tests cover channel.sendpayload plugin behavior.
|
||||
import {
|
||||
installChannelOutboundPayloadContractSuite,
|
||||
primeChannelOutboundSendMock,
|
||||
@@ -8,6 +7,8 @@ import {
|
||||
createMessageReceiptFromOutboundResults,
|
||||
verifyChannelMessageAdapterCapabilityProofs,
|
||||
} from "openclaw/plugin-sdk/channel-outbound";
|
||||
// Zalouser tests cover channel.sendpayload plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import "./accounts.test-mocks.js";
|
||||
import "./zalo-js.test-mocks.js";
|
||||
@@ -71,12 +72,7 @@ function requireZalouserMediaSender(
|
||||
return media;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireSendOptions(
|
||||
mockedSend: ReturnType<typeof vi.mocked<(typeof import("./send.js"))["sendMessageZalouser"]>>,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Zalouser tests cover monitor.account scope plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
|
||||
import "./monitor.send.test-mocks.js";
|
||||
@@ -18,12 +19,7 @@ import { startZaloListenerMock } from "./zalo-js.test-mocks.js";
|
||||
type ZaloJsModule = typeof import("./zalo-js.js");
|
||||
type ListenerParams = Parameters<ZaloJsModule["startZaloListener"]>[0];
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
describe("zalouser monitor pairing account scoping", () => {
|
||||
it("scopes DM pairing-store reads and pairing requests to accountId", async () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// Zalouser tests cover send plugin behavior.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createZalouserSendReceipt } from "./send-receipt.js";
|
||||
import {
|
||||
@@ -60,12 +61,7 @@ function sendFailure(error: string, threadId = "thread") {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Tests live model switching behavior in active agent command sessions. */
|
||||
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SessionEntry } from "../config/sessions.js";
|
||||
import { createUserTurnTranscriptRecorder } from "../sessions/user-turn-transcript.js";
|
||||
@@ -757,12 +758,7 @@ function setupAcpSession(): void {
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label-object");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/** Tests compaction safeguard summaries, quality audit, providers, and runtime settings. */
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { AgentMessage, StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import type { ExtensionAPI, ExtensionContext } from "openclaw/plugin-sdk/agent-sessions";
|
||||
import { createAssistantMessageEventStream, type Model } from "openclaw/plugin-sdk/llm";
|
||||
/** Tests compaction safeguard summaries, quality audit, providers, and runtime settings. */
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import {
|
||||
@@ -230,12 +231,7 @@ function latestMockCallArg(
|
||||
return mockCallArg(mock, mock.mock.calls.length - 1, argIndex);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error("expected record");
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-record");
|
||||
|
||||
function requireArray(value: unknown): unknown[] {
|
||||
if (!Array.isArray(value)) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import fs from "node:fs/promises";
|
||||
*/
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import { GatewayClientRequestError } from "../gateway/client.js";
|
||||
@@ -344,12 +345,7 @@ describe("before_tool_call loop detection behavior", () => {
|
||||
return result;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function requireArray(value: unknown, label: string): unknown[] {
|
||||
expect(Array.isArray(value)).toBe(true);
|
||||
@@ -2018,12 +2014,7 @@ describe("before_tool_call requireApproval handling", () => {
|
||||
let hookRunner: TestHookRunner;
|
||||
const mockCallGateway = vi.mocked(callGatewayTool);
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function requireHookCall(
|
||||
index: number,
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../config/config.js";
|
||||
import { setEmbeddedMode } from "../infra/embedded-mode.js";
|
||||
@@ -50,12 +51,7 @@ vi.mock("../logging/subsystem.js", async (importOriginal) => {
|
||||
const mockGetGlobalHookRunner = vi.mocked(getGlobalHookRunner);
|
||||
const mockCallGatewayTool = vi.mocked(callGatewayTool);
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label");
|
||||
|
||||
function requireApprovalRequestCall(label: string): {
|
||||
timeoutParams: Record<string, unknown>;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Covers provider plugin profiles, external CLI scoped discovery, persistence
|
||||
* rules, and external CLI bootstrap policy.
|
||||
*/
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ProviderExternalAuthProfile } from "../../plugins/types.js";
|
||||
import { resolveAgentCredentialMapFromStore } from "../agent-auth-credentials.js";
|
||||
@@ -46,12 +47,7 @@ function createUsableOAuthExpiry(): number {
|
||||
return Date.now() + 30 * 60 * 1000;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireProfile(store: AuthProfileStore, profileId: string): Record<string, unknown> {
|
||||
return requireRecord(store.profiles[profileId], profileId);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Covers denied prompts, agent-session resume, wait handling, direct fallback,
|
||||
* and elevated runtime handoff routing.
|
||||
*/
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("./tools/gateway.js", () => ({
|
||||
@@ -66,12 +67,7 @@ afterEach(() => {
|
||||
}
|
||||
});
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label");
|
||||
|
||||
function requireFirstMockCall(mock: unknown, label: string): unknown[] {
|
||||
const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.[0];
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
/**
|
||||
* Exec approval id routing tests.
|
||||
* Covers approval registration ids, follow-up idempotency, and approved
|
||||
* node/gateway invocation behavior.
|
||||
*/
|
||||
import crypto from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
loadExecApprovals,
|
||||
@@ -378,12 +379,7 @@ function mockNoApprovalRouteRegistration() {
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label");
|
||||
|
||||
function expectRecordFields(
|
||||
record: Record<string, unknown> | undefined,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Regression coverage for process-tool supervisor cancellation.
|
||||
* Verifies managed session cancellation, process-tree fallback, and registry state.
|
||||
*/
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { supervisorMock } = vi.hoisted(() => ({
|
||||
@@ -43,12 +44,7 @@ function createBackgroundSession(id: string, pid?: number) {
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectSessionState(sessionId: string, expected: { exited?: boolean }) {
|
||||
const session = requireRecord(getSession(sessionId), sessionId);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/** Tests CLI runner reliability paths for hooks, transcripts, failover, and reply ops. */
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
/** Tests CLI runner reliability paths for hooks, transcripts, failover, and reply ops. */
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createSolidPngBuffer } from "../../test/helpers/image-fixtures.js";
|
||||
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
|
||||
@@ -246,12 +247,7 @@ function buildPreparedContext(params?: {
|
||||
};
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function claudeInputStartedJson(data: string): string {
|
||||
const event = createClaudeInputStartedEvent(data);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Covers CLI session transcript loading and reseeding boundaries.
|
||||
import fs from "node:fs";
|
||||
import fsp from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { CURRENT_SESSION_VERSION } from "openclaw/plugin-sdk/agent-sessions";
|
||||
// Covers CLI session transcript loading and reseeding boundaries.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
|
||||
import { withEnvAsync } from "../../test-utils/env.js";
|
||||
@@ -82,12 +83,7 @@ function createOversizedSessionTranscript(rootDir: string, sessionId: string): s
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectMessageFields(value: unknown, expected: { role: string; content?: unknown }) {
|
||||
const message = requireRecord(value, "message");
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Covers CLI-backed attempt execution and session-binding persistence.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
// Covers CLI-backed attempt execution and session-binding persistence.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import {
|
||||
@@ -471,12 +472,7 @@ async function readTranscriptEntries<T extends { type?: string; message?: unknow
|
||||
return entries;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "label-not-object");
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
|
||||
+3
-7
@@ -1,8 +1,9 @@
|
||||
// End-to-end auth-profile rotation coverage for embedded runner retries.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { AssistantMessage } from "openclaw/plugin-sdk/llm";
|
||||
// End-to-end auth-profile rotation coverage for embedded runner retries.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { redactIdentifier } from "../logging/redact-identifier.js";
|
||||
@@ -522,12 +523,7 @@ async function withAgentWorkspace<T>(
|
||||
}
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be a record`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-record");
|
||||
|
||||
function requireLogRecord(
|
||||
records: ReadonlyArray<unknown>,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Coverage for deferred context-engine maintenance and transcript rewrite hooks.
|
||||
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ContextEngineRuntimeContext } from "../../context-engine/types.js";
|
||||
import { peekSystemEvents, resetSystemEventsForTest } from "../../infra/system-events.js";
|
||||
@@ -80,12 +81,7 @@ async function waitForAssertion(
|
||||
}
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label");
|
||||
|
||||
function firstMaintainParams(maintain: { mock: { calls: unknown[][] } }): Record<string, unknown> {
|
||||
return requireRecord(maintain.mock.calls[0]?.[0], "maintain params");
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Coverage for model-call diagnostic events around attempt stream functions.
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
// Coverage for model-call diagnostic events around attempt stream functions.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { useAutoCleanupTempDirTracker } from "../../../../test/helpers/temp-dir.js";
|
||||
import {
|
||||
@@ -88,12 +89,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`Expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object-capitalized");
|
||||
|
||||
function readRecordField(record: Record<string, unknown>, key: string, label: string) {
|
||||
const value = record[key];
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Coverage for context-engine bootstrap, assembly, and turn finalization.
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import type { AgentMessage } from "openclaw/plugin-sdk/agent-core";
|
||||
// Coverage for context-engine bootstrap, assembly, and turn finalization.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { HEARTBEAT_TRANSCRIPT_PROMPT } from "../../../auto-reply/heartbeat.js";
|
||||
import {
|
||||
@@ -80,12 +81,7 @@ async function readTrajectoryEvents(tempPaths: string[]): Promise<TrajectoryEven
|
||||
return hoisted.trajectoryEvents.filter((event) => event.workspaceDir === workspaceDir);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireRecords(value: unknown, label: string): Array<Record<string, unknown>> {
|
||||
expect(value, label).toBeInstanceOf(Array);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { expectDefined } from "@openclaw/normalization-core";
|
||||
import type { AgentMessage } from "openclaw/plugin-sdk/agent-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
sanitizeOpenAIResponsesReplayForStream,
|
||||
@@ -45,12 +46,7 @@ async function collectStreamEvents(stream: AsyncIterable<unknown>): Promise<unkn
|
||||
return events;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function requireAssistantMessage(message: AgentMessage | undefined): AssistantMessage {
|
||||
if (!message || message.role !== "assistant") {
|
||||
|
||||
@@ -5,6 +5,7 @@ import * as providerTransportStream from "@openclaw/ai/transports";
|
||||
// Stream resolution tests cover how embedded runs choose provider, boundary,
|
||||
// native Codex, or custom stream functions and pass auth/cache/signal options.
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { bindStreamLlmRuntime } from "../../llm/model-runtime-binding.js";
|
||||
import { streamSimple } from "../../llm/stream.js";
|
||||
@@ -77,14 +78,7 @@ function useNativeStreamFn(streamFn: StreamFn): StreamFn {
|
||||
return streamSimple as StreamFn;
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
// Test streams return their options/context as plain records; fail early if a
|
||||
// route returns an unexpected shape.
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
async function expectStreamResultRecord(
|
||||
result: ReturnType<StreamFn>,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { AgentEvent } from "openclaw/plugin-sdk/agent-core";
|
||||
// Tool handler tests cover tool lifecycle events, read-path diagnostics,
|
||||
// messaging tool capture, approvals, and emitted summaries.
|
||||
import type { AgentEvent } from "openclaw/plugin-sdk/agent-core";
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
onAgentEvent as registerAgentEventListener,
|
||||
@@ -247,10 +248,6 @@ function requireString(value: unknown, label: string): string {
|
||||
return value;
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
describe("update_plan progress events", () => {
|
||||
it("emits the typed full plan snapshot after a successful result", async () => {
|
||||
const { ctx, onAgentEvent } = createTestContext();
|
||||
@@ -296,12 +293,7 @@ describe("update_plan progress events", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object");
|
||||
|
||||
function expectRecordFields(value: unknown, label: string, expected: Record<string, unknown>) {
|
||||
const record = requireRecord(value, label);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Covers native hook relay registration, bridge invocation, and approval state.
|
||||
import { randomUUID } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import { createServer, request as httpRequest } from "node:http";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
// Covers native hook relay registration, bridge invocation, and approval state.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import type { SessionEntry } from "../../config/sessions.js";
|
||||
import { replaceSessionEntry } from "../../config/sessions/session-accessor.js";
|
||||
@@ -46,14 +47,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
// Relay bridge payloads cross a process boundary. Tests narrow unknown JSON
|
||||
// before making assertions so malformed bridge responses fail clearly.
|
||||
if (!isRecord(value)) {
|
||||
throw new Error(`Expected ${label} to be an object`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
const requireRecord = createRequireRecord("record", "expected-label-object-capitalized");
|
||||
|
||||
function readRecordField(record: Record<string, unknown>, key: string, label: string) {
|
||||
const value = record[key];
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Verifies fallback cooldown probe decisions and diagnostic records.
|
||||
import { randomUUID } from "node:crypto";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
// Verifies fallback cooldown probe decisions and diagnostic records.
|
||||
import { createRequireRecord } from "openclaw/plugin-sdk/test-fixtures";
|
||||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createDiagnosticLogRecordCapture } from "../logging/test-helpers/diagnostic-log-capture.js";
|
||||
@@ -202,12 +203,7 @@ function expectPrimaryProbeSuccess(
|
||||
});
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
const requireRecord = createRequireRecord("object", "expected-label");
|
||||
|
||||
function expectRecordWithFields(
|
||||
records: Array<Record<string, unknown>>,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user