mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-28 13:26:04 -06:00
test: guard command mock calls
This commit is contained in:
@@ -369,7 +369,7 @@ describe("deliverAgentCommandResult", () => {
|
||||
|
||||
expect(runtime.log).toHaveBeenCalledTimes(1);
|
||||
expect(
|
||||
JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls[0]?.[0])),
|
||||
JSON.parse(String((runtime.log as ReturnType<typeof vi.fn>).mock.calls.at(0)?.[0])),
|
||||
).toEqual({
|
||||
payloads: [
|
||||
{
|
||||
|
||||
@@ -381,7 +381,7 @@ describe("agentCommand", () => {
|
||||
);
|
||||
|
||||
expect(pluginRegistryMocks.ensurePluginRegistryLoaded).toHaveBeenCalledOnce();
|
||||
const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls[0]?.[0];
|
||||
const registryLoad = pluginRegistryMocks.ensurePluginRegistryLoaded.mock.calls.at(0)?.[0];
|
||||
expect(registryLoad?.scope).toBe("all");
|
||||
expect(registryLoad?.config).toBeTypeOf("object");
|
||||
expect(registryLoad?.activationSourceConfig).toBeTypeOf("object");
|
||||
|
||||
@@ -128,7 +128,7 @@ describe("agents delete command", () => {
|
||||
await agentsDeleteCommand({ id: "ops", force: true, json: true }, runtime);
|
||||
|
||||
expect(gatewayMocks.callGateway).toHaveBeenCalledOnce();
|
||||
const gatewayCall = gatewayMocks.callGateway.mock.calls[0]?.[0];
|
||||
const gatewayCall = gatewayMocks.callGateway.mock.calls.at(0)?.[0];
|
||||
expect(gatewayCall?.method).toBe("agents.delete");
|
||||
expect(gatewayCall?.params).toEqual({ agentId: "ops", deleteFiles: true });
|
||||
expect(gatewayCall?.requiredMethods).toEqual(["agents.delete"]);
|
||||
|
||||
@@ -43,7 +43,7 @@ async function writeIdentityFile(workspace: string, lines: string[]) {
|
||||
}
|
||||
|
||||
function getWrittenMainIdentity() {
|
||||
const [written] = configMocks.writeConfigFile.mock.calls[0] ?? [];
|
||||
const [written] = configMocks.writeConfigFile.mock.calls.at(0) ?? [];
|
||||
if (!written) {
|
||||
throw new Error("expected written agent config");
|
||||
}
|
||||
|
||||
@@ -461,7 +461,10 @@ describe("applyAuthChoiceLoadedPluginProvider", () => {
|
||||
const result = await applyAuthChoiceLoadedPluginProvider(buildParams());
|
||||
|
||||
expect(ensureOnboardingPluginInstalled).toHaveBeenCalledOnce();
|
||||
const [installParams] = ensureOnboardingPluginInstalled.mock.calls[0];
|
||||
const [installParams] = ensureOnboardingPluginInstalled.mock.calls.at(0) ?? [];
|
||||
if (installParams === undefined) {
|
||||
throw new Error("expected plugin install params");
|
||||
}
|
||||
expect(installParams.entry?.pluginId).toBe("local-provider-plugin");
|
||||
expect(installParams.entry?.label).toBe(LOCAL_PROVIDER_LABEL);
|
||||
expect(installParams.workspaceDir).toBe("/tmp/workspace");
|
||||
|
||||
@@ -45,7 +45,7 @@ describe("warnIfModelConfigLooksOff", () => {
|
||||
expect(loadModelCatalog).not.toHaveBeenCalled();
|
||||
expect(ensureAuthProfileStore).toHaveBeenCalledOnce();
|
||||
expect(listProfilesForProvider).toHaveBeenCalledOnce();
|
||||
const [profileStore, providerId] = listProfilesForProvider.mock.calls[0] as unknown as [
|
||||
const [profileStore, providerId] = listProfilesForProvider.mock.calls.at(0) as unknown as [
|
||||
AuthProfileStore,
|
||||
string,
|
||||
];
|
||||
|
||||
@@ -125,7 +125,7 @@ describe("resolvePreferredProviderForAuthChoice", () => {
|
||||
}),
|
||||
).resolves.toBe("demo-provider");
|
||||
expect(resolvePluginProviders).toHaveBeenCalledOnce();
|
||||
const [pluginProviderOptions] = resolvePluginProviders.mock.calls[0] as unknown as [
|
||||
const [pluginProviderOptions] = resolvePluginProviders.mock.calls.at(0) as unknown as [
|
||||
ResolvePluginProvidersOptions,
|
||||
];
|
||||
expect(pluginProviderOptions?.mode).toBe("setup");
|
||||
|
||||
@@ -339,7 +339,7 @@ describe("channels command", () => {
|
||||
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Test helper lets assertions ascribe written config shape.
|
||||
function getWrittenConfig<T>(): T {
|
||||
expect(configMocks.writeConfigFile).toHaveBeenCalledTimes(1);
|
||||
const [config] = configMocks.writeConfigFile.mock.calls[0] ?? [];
|
||||
const [config] = configMocks.writeConfigFile.mock.calls.at(0) ?? [];
|
||||
if (config === undefined) {
|
||||
throw new Error("expected written channel config");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ function logLine(params: { module: string; message: string }) {
|
||||
}
|
||||
|
||||
function readJsonPayload() {
|
||||
return JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
|
||||
return JSON.parse(String(runtime.log.mock.calls.at(0)?.[0])) as {
|
||||
file: string;
|
||||
channel: string;
|
||||
lines: Array<{ message: string }>;
|
||||
|
||||
@@ -243,7 +243,7 @@ describe("channelsStatusCommand SecretRef fallback flow", () => {
|
||||
|
||||
expect(errors.join("\n")).toContain("Gateway not reachable");
|
||||
expect(mocks.resolveCommandConfigWithSecrets).toHaveBeenCalledOnce();
|
||||
const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls[0]?.[0];
|
||||
const configResolutionRequest = mocks.resolveCommandConfigWithSecrets.mock.calls.at(0)?.[0];
|
||||
expect(configResolutionRequest?.commandName).toBe("channels status");
|
||||
expect(configResolutionRequest?.mode).toBe("read_only_status");
|
||||
expect(
|
||||
|
||||
Reference in New Issue
Block a user