refactor: consolidate remaining coercion helpers (#122020)

This commit is contained in:
Peter Steinberger
2026-08-11 10:22:01 -07:00
committed by GitHub
parent 24bbb416b5
commit cad77fb39c
234 changed files with 1210 additions and 1572 deletions
+11 -7
View File
@@ -1,4 +1,4 @@
import { asOptionalObjectRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
import { asRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
// Feishu helper module supports card test helpers behavior.
import { expect } from "vitest";
@@ -10,6 +10,10 @@ function asArray(value: unknown): unknown[] {
return Array.isArray(value) ? value : [];
}
function readFeishuObjectRecord(value: unknown): Record<string, unknown> | undefined {
return value !== null && typeof value === "object" ? asRecord(value) : undefined;
}
export function expectFirstSentCardUsesFillWidthOnly(sendCardMock: {
mock: { calls: unknown[][] };
}) {
@@ -33,17 +37,17 @@ export function expectFirstSentCardUsesFillWidthOnly(sendCardMock: {
export function expectSentCardHasP2pAction(sendCardMock: MockCalls) {
const hasP2pAction = sendCardMock.mock.calls.some(([arg]) => {
const card = asOptionalObjectRecord(asOptionalObjectRecord(arg)?.card);
const body = asOptionalObjectRecord(card?.body);
const card = readFeishuObjectRecord(readFeishuObjectRecord(arg)?.card);
const body = readFeishuObjectRecord(card?.body);
return asArray(body?.elements).some((element) => {
const elementRecord = asOptionalObjectRecord(element);
const elementRecord = readFeishuObjectRecord(element);
if (elementRecord?.tag !== "action") {
return false;
}
return asArray(elementRecord.actions).some((action) => {
const actionRecord = asOptionalObjectRecord(action);
const value = asOptionalObjectRecord(actionRecord?.value);
const command = asOptionalObjectRecord(value?.c);
const actionRecord = readFeishuObjectRecord(action);
const value = readFeishuObjectRecord(actionRecord?.value);
const command = readFeishuObjectRecord(value?.c);
return command?.t === "p2p";
});
});