mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-07 04:32:56 +00:00
chore(lint): enable object-shorthand (#81808)
* fix: narrow current-main core type guards * fix: preserve query and test guard narrowing * fix(copilot): align client options with sdk rename * test(sms): type fetch mocks * fix(sms): preserve numeric allowlist entries * test(sms): preserve pairing send count assertion --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -1097,7 +1097,6 @@ export function resolvePoolAcquire(params: AttemptParamsLike): {
|
||||
},
|
||||
options: {
|
||||
copilotHome: resolved.copilotHome,
|
||||
cwd: readString(params.cwd) ?? readString(params.workspaceDir),
|
||||
gitHubToken: resolved.authMode === "gitHubToken" ? resolved.gitHubToken : undefined,
|
||||
useLoggedInUser: resolved.authMode === "useLoggedInUser",
|
||||
},
|
||||
|
||||
@@ -66,7 +66,6 @@ function makeOptions(overrides: Partial<ClientCreateOptions> = {}): ClientCreate
|
||||
copilotHome: overrides.copilotHome ?? "copilot-home",
|
||||
useLoggedInUser: overrides.useLoggedInUser ?? true,
|
||||
gitHubToken: overrides.gitHubToken,
|
||||
cwd: overrides.cwd,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,9 @@ export interface PoolKey {
|
||||
|
||||
export interface ClientCreateOptions extends Omit<
|
||||
CopilotClientOptions,
|
||||
"baseDirectory" | "gitHubToken" | "useLoggedInUser" | "workingDirectory"
|
||||
"baseDirectory" | "workingDirectory" | "useLoggedInUser" | "gitHubToken"
|
||||
> {
|
||||
readonly copilotHome: string;
|
||||
readonly cwd?: string;
|
||||
readonly useLoggedInUser?: boolean;
|
||||
readonly gitHubToken?: string;
|
||||
}
|
||||
@@ -362,11 +361,10 @@ function normalizeClientCreateOptions(
|
||||
options: ClientCreateOptions,
|
||||
normalizedCopilotHome: string,
|
||||
): CopilotClientOptions {
|
||||
const { copilotHome: _copilotHome, cwd, ...clientOptions } = options;
|
||||
const { copilotHome: _copilotHome, ...clientOptions } = options;
|
||||
return {
|
||||
...clientOptions,
|
||||
baseDirectory: normalizedCopilotHome,
|
||||
workingDirectory: cwd,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -169,6 +169,19 @@ describe("SMS account config", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("coerces numeric allowFrom entries accepted by the config schema", () => {
|
||||
const parsed = SmsConfigSchema.parse({
|
||||
accountSid: "AC123",
|
||||
authToken: "token",
|
||||
fromNumber: "+15550001111",
|
||||
allowFrom: [15551234567],
|
||||
});
|
||||
|
||||
expect(resolveSmsAccount({ channels: { sms: parsed } })).toMatchObject({
|
||||
allowFrom: ["+15551234567"],
|
||||
});
|
||||
});
|
||||
|
||||
it("discovers env-only SMS credentials as the implicit default account", () => {
|
||||
process.env.TWILIO_ACCOUNT_SID = "AC-env";
|
||||
process.env.TWILIO_AUTH_TOKEN = "env-token";
|
||||
|
||||
@@ -24,13 +24,16 @@ function getChannelConfig(cfg: OpenClawConfig): SmsChannelConfig | undefined {
|
||||
return cfg?.channels?.[CHANNEL_ID] as SmsChannelConfig | undefined;
|
||||
}
|
||||
|
||||
function parseList(raw: string | string[] | undefined): string[] {
|
||||
function parseList(raw: unknown): string[] {
|
||||
if (!raw) {
|
||||
return [];
|
||||
}
|
||||
return (Array.isArray(raw) ? raw : normalizeStringEntries(raw.split(",")))
|
||||
.map((entry) => normalizeSmsAllowFrom(entry))
|
||||
.filter(Boolean);
|
||||
const entries = Array.isArray(raw)
|
||||
? raw
|
||||
: typeof raw === "string"
|
||||
? normalizeStringEntries(raw.split(","))
|
||||
: [raw];
|
||||
return entries.map((entry) => normalizeSmsAllowFrom(String(entry))).filter(Boolean);
|
||||
}
|
||||
|
||||
function parseTextChunkLimit(raw: unknown): number {
|
||||
|
||||
@@ -109,10 +109,12 @@ describe("dispatchSmsInboundEvent", () => {
|
||||
meta: undefined,
|
||||
});
|
||||
expect(sendSmsViaTwilio).toHaveBeenCalledOnce();
|
||||
expect(sendSmsViaTwilio.mock.calls[0]?.[0]).toMatchObject({
|
||||
to: "+15551234567",
|
||||
});
|
||||
expect(sendSmsViaTwilio.mock.calls[0]?.[0].text).toContain("PAIR123");
|
||||
expect(sendSmsViaTwilio).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
to: "+15551234567",
|
||||
text: expect.stringContaining("PAIR123"),
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("uses the canonical routed session key for authorized SMS turns", async () => {
|
||||
|
||||
@@ -30,16 +30,15 @@ type ProviderAuthWarmWorkerResult =
|
||||
};
|
||||
|
||||
function isWorkerInput(value: unknown): value is ProviderAuthWarmWorkerInput {
|
||||
if (!value || typeof value !== "object") {
|
||||
return false;
|
||||
}
|
||||
const record = value as Record<string, unknown>;
|
||||
return (
|
||||
value !== null &&
|
||||
typeof value === "object" &&
|
||||
"cfg" in value &&
|
||||
(!("runtimeAuthStores" in value) ||
|
||||
Array.isArray((value as { runtimeAuthStores?: unknown }).runtimeAuthStores)) &&
|
||||
(!("runtimeAuthLookups" in value) ||
|
||||
Array.isArray((value as { runtimeAuthLookups?: unknown }).runtimeAuthLookups)) &&
|
||||
(!("omitFalseProviderAuth" in value) ||
|
||||
typeof (value as { omitFalseProviderAuth?: unknown }).omitFalseProviderAuth === "boolean")
|
||||
"cfg" in record &&
|
||||
(!("runtimeAuthStores" in record) || Array.isArray(record.runtimeAuthStores)) &&
|
||||
(!("runtimeAuthLookups" in record) || Array.isArray(record.runtimeAuthLookups)) &&
|
||||
(!("omitFalseProviderAuth" in record) || typeof record.omitFalseProviderAuth === "boolean")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -245,9 +245,10 @@ interface ZodDummy {
|
||||
unwrap: () => z.ZodType;
|
||||
}
|
||||
function isUnwrappable(object: unknown): object is ZodDummy {
|
||||
if (!object || typeof object !== "object") {
|
||||
return false;
|
||||
}
|
||||
return (
|
||||
object !== null &&
|
||||
typeof object === "object" &&
|
||||
"unwrap" in object &&
|
||||
typeof (object as Record<string, unknown>).unwrap === "function" &&
|
||||
!(object instanceof z.ZodArray)
|
||||
|
||||
@@ -315,7 +315,7 @@ describe("Session Store Cache", () => {
|
||||
throw new Error("Expected cached entry");
|
||||
}
|
||||
expect(entry?.polluted).toBeUndefined();
|
||||
expect(Object.hasOwn(entry as SessionEntry, "__proto__")).toBe(true);
|
||||
expect(Object.hasOwn(entry as object, "__proto__")).toBe(true);
|
||||
expect(Object.prototype).not.toHaveProperty("polluted");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user