mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 17:44:45 +00:00
test: guard support helper assertions
This commit is contained in:
@@ -98,7 +98,9 @@ function createDeferred(): { promise: Promise<void>; resolve: () => void } {
|
||||
}
|
||||
|
||||
function expectRecordFields(record: unknown, expected: Record<string, unknown>) {
|
||||
expect(record).toBeDefined();
|
||||
if (!record || typeof record !== "object") {
|
||||
throw new Error("Expected record");
|
||||
}
|
||||
const actual = record as Record<string, unknown>;
|
||||
for (const [key, value] of Object.entries(expected)) {
|
||||
expect(actual[key]).toEqual(value);
|
||||
@@ -136,7 +138,9 @@ function findMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<str
|
||||
}
|
||||
|
||||
function expectMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<string, unknown>) {
|
||||
expect(findMockCallFields(mock, expected)).toBeDefined();
|
||||
if (!findMockCallFields(mock, expected)) {
|
||||
throw new Error(`Expected mock call ${JSON.stringify(expected)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function expectNoMockCallFields(mock: ReturnType<typeof vi.fn>, expected: Record<string, unknown>) {
|
||||
|
||||
@@ -336,7 +336,6 @@ describe("acp translator stable lifecycle handlers", () => {
|
||||
const result = await agent.resumeSession(createResumeSessionRequest("agent:main:work"));
|
||||
|
||||
expect(result.modes?.currentModeId).toBe("adaptive");
|
||||
expect(result.configOptions).toBeDefined();
|
||||
if (!result.configOptions) {
|
||||
throw new Error("expected resume session config options");
|
||||
}
|
||||
|
||||
@@ -139,9 +139,11 @@ function configOptions(value: unknown) {
|
||||
|
||||
function expectConfigOption(options: unknown, id: string, fields: Record<string, unknown>) {
|
||||
const option = configOptions(options).find((candidate) => candidate.id === id);
|
||||
expect(option, `config option ${id}`).toBeDefined();
|
||||
if (!option) {
|
||||
throw new Error(`Expected config option ${id}`);
|
||||
}
|
||||
for (const [field, value] of Object.entries(fields)) {
|
||||
expect(option?.[field]).toEqual(value);
|
||||
expect(option[field]).toEqual(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -592,7 +592,6 @@ describe("commands registry args", () => {
|
||||
};
|
||||
|
||||
const args = parseCommandArgs(command, "set foo bar baz");
|
||||
expect(args).toBeDefined();
|
||||
if (!args) {
|
||||
throw new Error("Expected parsed command args");
|
||||
}
|
||||
|
||||
@@ -236,7 +236,6 @@ async function expectNextRunUsesTargetSession(
|
||||
const runParams = params.runEmbeddedPiAgentMock.mock.calls[0]?.[0] as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
expect(runParams).toBeDefined();
|
||||
if (!runParams) {
|
||||
throw new Error("expected embedded PI agent call params");
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ function expectAuditRecord(
|
||||
|
||||
function requireFirstMockCall(mock: unknown, label: string): unknown[] {
|
||||
const call = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls?.[0];
|
||||
expect(call).toBeDefined();
|
||||
if (!call) {
|
||||
throw new Error(`missing ${label} call`);
|
||||
}
|
||||
|
||||
@@ -80,8 +80,10 @@ function makePluginRegistry(overrides: Partial<PluginRegistry> = {}): PluginRegi
|
||||
|
||||
function callArg<T>(mock: { mock: { calls: unknown[][] } }, index = 0, _type?: (value: T) => T): T {
|
||||
const call = mock.mock.calls[index];
|
||||
expect(call).toBeDefined();
|
||||
return call?.[0] as T;
|
||||
if (!call) {
|
||||
throw new Error(`Expected mock call ${index}`);
|
||||
}
|
||||
return call[0] as T;
|
||||
}
|
||||
|
||||
function expectExternalCatalogInstallCall(index = 0) {
|
||||
|
||||
@@ -24,7 +24,9 @@ vi.mock("./channel-resolution.js", () => ({
|
||||
|
||||
function mockCallArg(mock: { mock: { calls: unknown[][] } }, index = 0): unknown {
|
||||
const call = mock.mock.calls[index];
|
||||
expect(call).toBeDefined();
|
||||
if (!call) {
|
||||
throw new Error(`Expected mock call ${index}`);
|
||||
}
|
||||
return call[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,6 @@ function requireMatchingRecord(
|
||||
const record = item as Record<string, unknown>;
|
||||
return Object.entries(fields).every(([key, value]) => Object.is(record[key], value));
|
||||
});
|
||||
expect(found).toBeDefined();
|
||||
if (!found) {
|
||||
throw new Error(`missing ${label}`);
|
||||
}
|
||||
@@ -104,7 +103,6 @@ function requireMatchingRecord(
|
||||
function requireFirstMockCallArg(mock: unknown, label: string) {
|
||||
const calls = (mock as { mock?: { calls?: unknown[][] } }).mock?.calls;
|
||||
const call = calls?.[0];
|
||||
expect(call).toBeDefined();
|
||||
if (!call) {
|
||||
throw new Error(`missing ${label} call`);
|
||||
}
|
||||
|
||||
@@ -553,7 +553,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
||||
});
|
||||
|
||||
const shellWrapperCall = requireMacExecHostCall(shellWrapperInvoke.runViaMacAppExecHost);
|
||||
expect(shellWrapperCall.approvals).toBeDefined();
|
||||
if (shellWrapperCall.approvals === undefined) {
|
||||
throw new Error("Expected shell-wrapper approvals");
|
||||
}
|
||||
expect(shellWrapperCall.request?.command).toEqual([
|
||||
"/bin/sh",
|
||||
"-lc",
|
||||
@@ -621,7 +623,9 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
|
||||
const canonicalCwd = fs.realpathSync(tmp);
|
||||
expect(invoke.runCommand).not.toHaveBeenCalled();
|
||||
const macHostCall = requireMacExecHostCall(invoke.runViaMacAppExecHost);
|
||||
expect(macHostCall.approvals).toBeDefined();
|
||||
if (macHostCall.approvals === undefined) {
|
||||
throw new Error("Expected Mac host approvals");
|
||||
}
|
||||
expect(macHostCall.request?.command).toEqual(["env", "sh", "-c", "echo SAFE"]);
|
||||
expect(macHostCall.request?.rawCommand).toBe('env sh -c "echo SAFE"');
|
||||
expect(macHostCall.request?.cwd).toBe(canonicalCwd);
|
||||
|
||||
@@ -284,7 +284,6 @@ describe("channel-streaming", () => {
|
||||
name: "write",
|
||||
args: { path: "/tmp/demo/index.html" },
|
||||
});
|
||||
expect(progressLine).toBeDefined();
|
||||
if (!progressLine) {
|
||||
throw new Error("expected tool progress draft line");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ describe("createOpencodeCatalogApiKeyAuthMethod", () => {
|
||||
expect(method.label).toBe("OpenCode Go catalog");
|
||||
expect(method.hint).toBe("Shared API key for Zen + Go catalogs");
|
||||
expect(method.kind).toBe("api_key");
|
||||
expect(method.wizard).toBeDefined();
|
||||
if (!method.wizard) {
|
||||
throw new Error("expected OpenCode auth method to include wizard metadata");
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
}
|
||||
|
||||
function requirePayload(payload: Record<string, unknown> | undefined): Record<string, unknown> {
|
||||
expect(payload).toBeDefined();
|
||||
if (!payload) {
|
||||
throw new Error("expected captured payload");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user