test: guard agent runner null helpers

This commit is contained in:
Peter Steinberger
2026-05-11 21:22:57 +01:00
parent 50f51a71cb
commit f56fae7b1e
6 changed files with 15 additions and 15 deletions

View File

@@ -30,6 +30,7 @@ vi.mock("../plugins/provider-runtime.js", () => ({
vi.mock("./models-config.providers.js", () => ({
applyNativeStreamingUsageCompat: (providers: unknown) => providers,
enforceSourceManagedProviderSecrets: ({ providers }: { providers: unknown }) => providers,
normalizeProviderCatalogModelsForConfig: (providers: unknown) => providers,
normalizeProviders: ({ providers }: { providers: unknown }) => providers,
resolveImplicitProviders: async ({
explicitProviders,
@@ -272,8 +273,6 @@ function expectCopilotProviderFromPlan(
? (JSON.parse(plan.contents) as { providers?: Record<string, unknown> })
: {};
const provider = parsed.providers?.["github-copilot"];
expect(provider).not.toBeNull();
expect(typeof provider).toBe("object");
if (provider === null || typeof provider !== "object") {
throw new Error("Expected GitHub Copilot provider config");
}

View File

@@ -93,8 +93,9 @@ function callArg(mock: { mock: { calls: unknown[][] } }, callIndex: number, argI
function fetchInit(fetchMock: { mock: { calls: unknown[][] } }, callIndex = 0): RequestInit {
const init = callArg(fetchMock, callIndex, 1);
expect(typeof init).toBe("object");
expect(init).not.toBeNull();
if (!init || typeof init !== "object") {
throw new Error(`expected fetch init for call ${callIndex}`);
}
return init as RequestInit;
}

View File

@@ -52,8 +52,9 @@ type MockCallSource = {
};
function requireRecord(value: unknown, label: string): Record<string, unknown> {
expect(value, label).toBeTypeOf("object");
expect(value, label).not.toBeNull();
if (!value || typeof value !== "object") {
throw new Error(`expected ${label}`);
}
return value as Record<string, unknown>;
}

View File

@@ -74,8 +74,9 @@ async function invokeWrappedTestStream(
}
function requireRecord(value: unknown, label: string): Record<string, unknown> {
expect(value, label).toBeTypeOf("object");
expect(value, label).not.toBeNull();
if (!value || typeof value !== "object") {
throw new Error(`expected ${label}`);
}
return value as Record<string, unknown>;
}

View File

@@ -209,8 +209,6 @@ describe("before_tool_call loop detection behavior", () => {
}
function requireRecord(value: unknown, label: string): Record<string, unknown> {
expect(typeof value).toBe("object");
expect(value).not.toBeNull();
if (typeof value !== "object" || value === null) {
throw new Error(`${label} was not an object`);
}
@@ -649,8 +647,6 @@ describe("before_tool_call requireApproval handling", () => {
const mockCallGateway = vi.mocked(callGatewayTool);
function requireRecord(value: unknown, label: string): Record<string, unknown> {
expect(typeof value).toBe("object");
expect(value).not.toBeNull();
if (typeof value !== "object" || value === null) {
throw new Error(`${label} was not an object`);
}

View File

@@ -75,9 +75,11 @@ describe("compactSkillPaths", () => {
});
const locationMatch = prompt.match(/<location>([^<]+)<\/location>/);
expect(locationMatch).not.toBeNull();
expect(locationMatch![1]).toContain("~/");
expect(locationMatch![1]).toContain("\\literal-skill");
if (!locationMatch) {
throw new Error("expected prompt location tag");
}
expect(locationMatch[1]).toContain("~/");
expect(locationMatch[1]).toContain("\\literal-skill");
});
it("preserves paths outside home directory", () => {