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:
tanshanshan
2026-05-31 17:46:10 +08:00
committed by GitHub
parent 724160b7eb
commit 425a4ab2f2
9 changed files with 40 additions and 26 deletions

View File

@@ -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",
},

View File

@@ -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,
};
}

View File

@@ -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,
};
}

View File

@@ -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";

View File

@@ -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 {

View File

@@ -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 () => {

View File

@@ -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")
);
}

View File

@@ -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)

View File

@@ -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");
});