chore(lint): replace any with unknown or typed shapes in tests

- DB introspection tests: introduce local RawDb alias for casts
  that poke into the private .db handle.
- IPC handler tests: introduce IpcHandler alias matching the
  registerHandle signature (event + unknown args).
- selective-ipc / session-management: narrow handler and data
  params to unknown or the minimum shape the code reads.
This commit is contained in:
ZacharyZhang-NY committed 2026-04-17 01:45:00 -04:00
1 parent d42d895f2a
commit 0d044aeee8
9 files changed
+82 -34

No files matched your search

@@ -293,8 +293,8 @@ describe("Auto Task Assignment", () => {
shared.db.saveAgent({ id: backendId, companyId: shared.companyId, name: "Backend Dev", role: "Backend", title: "Backend", connectorId: "codex_local", status: "active", capabilities: "backend", budgetMonthlyUsd: 100 });
shared.db.saveAgent({ id: frontendId, companyId: shared.companyId, name: "Frontend Dev", role: "Frontend", title: "Frontend", connectorId: "codex_local", status: "active", capabilities: "frontend", budgetMonthlyUsd: 100 });
// Exhaust budgets by recording spending via direct SQL (since finishRun would need a real run)
(shared.db as any).db.prepare("update agents set spent_monthly_usd = 100 where id = ?").run(backendId);
(shared.db as any).db.prepare("update agents set spent_monthly_usd = 100 where id = ?").run(frontendId);
(shared.db as unknown as { db: { prepare: (sql: string) => { run: (...args: unknown[]) => void } } }).db.prepare("update agents set spent_monthly_usd = 100 where id = ?").run(backendId);
(shared.db as unknown as { db: { prepare: (sql: string) => { run: (...args: unknown[]) => void } } }).db.prepare("update agents set spent_monthly_usd = 100 where id = ?").run(frontendId);
const taskId = shared.db.saveTask({ companyId: shared.companyId, title: "No budget task", description: "Test", priority: "low", status: "todo" });
const result = shared.db.autoAssignTask(taskId, shared.companyId);
+16 -7
View File
@@ -27,6 +27,15 @@ import { AppDatabase } from "../../src/main/database";
import { createSessionManagementService } from "../../src/main/session-management-service";
import type { ConnectorId } from "../../src/shared/types";
type RawDb = {
db: {
prepare: (sql: string) => {
run: (...args: unknown[]) => void;
get: (...args: unknown[]) => unknown;
};
};
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
@@ -165,7 +174,7 @@ function createAndStartRun(
}
// Set agent status to "running" to simulate active execution
(db as any).db
(db as unknown as RawDb).db
.prepare("UPDATE agents SET status = 'running' WHERE id = ?")
.run(opts.agentId);
@@ -184,19 +193,19 @@ function verifyDbConsistency(db: AppDatabase): {
orphanedCheckouts: number;
} {
const runningRuns = (
(db as any).db
(db as unknown as RawDb).db
.prepare("SELECT count(*) as cnt FROM runs WHERE status = 'running'")
.get() as { cnt: number }
).cnt;
const runningAgents = (
(db as any).db
(db as unknown as RawDb).db
.prepare("SELECT count(*) as cnt FROM agents WHERE status = 'running'")
.get() as { cnt: number }
).cnt;
const orphanedCheckouts = (
(db as any).db
(db as unknown as RawDb).db
.prepare(
`SELECT count(*) as cnt FROM tasks t
LEFT JOIN runs r ON t.checkout_run_id = r.id
@@ -284,7 +293,7 @@ describe("Process Recovery -- Worker Crash Detection", () => {
});
// Verify lock is held before crash
const taskBefore = (db as any).db
const taskBefore = (db as unknown as RawDb).db
.prepare(
"SELECT checkout_run_id FROM tasks WHERE id = ?",
)
@@ -330,7 +339,7 @@ describe("Process Recovery -- Worker Crash Detection", () => {
});
// Verify workspace is locked before crash
const wsBefore = (db as any).db
const wsBefore = (db as unknown as RawDb).db
.prepare(
"SELECT lock_holder_run_id FROM workspaces WHERE id = ?",
)
@@ -340,7 +349,7 @@ describe("Process Recovery -- Worker Crash Detection", () => {
simulateWorkerCrash(db);
// Verify workspace lock is released
const wsAfter = (db as any).db
const wsAfter = (db as unknown as RawDb).db
.prepare(
"SELECT lock_holder_run_id FROM workspaces WHERE id = ?",
)
+14 -5
View File
@@ -14,6 +14,15 @@ vi.mock("electron", () => ({
import { AppDatabase, STALE_LOCK_TIMEOUT_MS } from "../../src/main/database";
type RawDb = {
db: {
prepare: (sql: string) => {
run: (...args: unknown[]) => void;
get: (...args: unknown[]) => unknown;
};
};
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
@@ -150,7 +159,7 @@ describe("CAS checkout", () => {
const taskId = createTestTask(db, companyId, null, workspaceId);
// Manually set task to in_progress
(db as any).db.prepare("UPDATE tasks SET status = 'in_progress' WHERE id = ?").run(taskId);
(db as unknown as RawDb).db.prepare("UPDATE tasks SET status = 'in_progress' WHERE id = ?").run(taskId);
const { id: runId } = db.createRun({
companyId,
@@ -193,7 +202,7 @@ describe("CAS checkout", () => {
unattributedCost: false,
});
const row = (db as any).db
const row = (db as unknown as RawDb).db
.prepare("SELECT checkout_run_id, execution_locked_at FROM tasks WHERE id = ?")
.get(taskId) as { checkout_run_id: string | null; execution_locked_at: string | null };
@@ -222,7 +231,7 @@ describe("CAS checkout", () => {
// Deleting the agent triggers cancelRunForDeletion for active runs
db.deleteAgent(agentId, companyId);
const row = (db as any).db
const row = (db as unknown as RawDb).db
.prepare("SELECT checkout_run_id, execution_locked_at FROM tasks WHERE id = ?")
.get(taskId) as { checkout_run_id: string | null; execution_locked_at: string | null };
@@ -249,7 +258,7 @@ describe("CAS checkout", () => {
// Backdate execution_locked_at to 20 minutes ago
const backdated = new Date(Date.now() - 20 * 60 * 1000).toISOString();
(db as any).db
(db as unknown as RawDb).db
.prepare("UPDATE tasks SET execution_locked_at = ? WHERE id = ?")
.run(backdated, taskId);
@@ -262,7 +271,7 @@ describe("CAS checkout", () => {
const task = db.getTask(taskId);
expect(task.status).toBe("todo");
const row = (db as any).db
const row = (db as unknown as RawDb).db
.prepare("SELECT checkout_run_id, execution_locked_at FROM tasks WHERE id = ?")
.get(taskId) as { checkout_run_id: string | null; execution_locked_at: string | null };
+9 -2
View File
@@ -2,11 +2,18 @@ import { mkdtemp, rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { IpcMainInvokeEvent } from "electron";
import type { DesktopResult } from "@shared/contracts";
import { IPC_CHANNELS } from "@shared/contracts";
import { AppDatabase } from "../../src/main/database";
import { registerCoreAdminHandlers } from "../../src/main/ipc-core-admin-handlers";
import { createThreadIntegration } from "../../src/main/thread-integration";
type IpcHandler = (
event: IpcMainInvokeEvent,
...args: unknown[]
) => Promise<DesktopResult<unknown>> | DesktopResult<unknown>;
const tempDirs: string[] = [];
async function createTempDir(prefix: string) {
@@ -109,7 +116,7 @@ describe("company mode switching", () => {
expect(db.getTask(taskId).requiresUserReview).toBe(true);
expect(db.getApprovalRecord(approvalId).state).toBe("pending");
const handlers = new Map<string, (...args: any[]) => any>();
const handlers = new Map<string, IpcHandler>();
registerCoreAdminHandlers({
registerHandle: (channel, handler) => {
handlers.set(channel, handler);
@@ -130,7 +137,7 @@ describe("company mode switching", () => {
throw new Error("saveCompany handler was not registered.");
}
const result = await saveCompany(null, {
const result = await saveCompany(null as unknown as IpcMainInvokeEvent, {
id: companyId,
name: "Mode Switch Co",
description: "Execution mode cleanup",
+13 -4
View File
@@ -14,6 +14,15 @@ vi.mock("electron", () => ({
import { AppDatabase, STALE_LOCK_TIMEOUT_MS } from "../../src/main/database";
type RawDb = {
db: {
prepare: (sql: string) => {
run: (...args: unknown[]) => void;
get: (...args: unknown[]) => unknown;
};
};
};
// ---------------------------------------------------------------------------
// Helpers
// ---------------------------------------------------------------------------
@@ -230,7 +239,7 @@ describe("Edge Case: Concurrent Task Checkout (D-05.1)", () => {
db.releaseTaskLock(taskId, runIdA);
// Verify lock fields are cleared
const row = (db as any).db
const row = (db as unknown as RawDb).db
.prepare("SELECT checkout_run_id, execution_locked_at FROM tasks WHERE id = ?")
.get(taskId) as { checkout_run_id: string | null; execution_locked_at: string | null };
expect(row.checkout_run_id).toBeNull();
@@ -266,7 +275,7 @@ describe("Edge Case: Concurrent Task Checkout (D-05.1)", () => {
expect(db.checkoutTask(taskId, runIdA)).toBe(true);
// Backdate execution_locked_at to well past the stale timeout
(db as any).db
(db as unknown as RawDb).db
.prepare("UPDATE tasks SET execution_locked_at = '2020-01-01T00:00:00Z' WHERE id = ?")
.run(taskId);
@@ -276,7 +285,7 @@ describe("Edge Case: Concurrent Task Checkout (D-05.1)", () => {
expect(recovered[0].companyId).toBe(companyId);
// Checkout fields should be cleared
const row = (db as any).db
const row = (db as unknown as RawDb).db
.prepare("SELECT checkout_run_id, execution_locked_at FROM tasks WHERE id = ?")
.get(taskId) as { checkout_run_id: string | null; execution_locked_at: string | null };
expect(row.checkout_run_id).toBeNull();
@@ -302,7 +311,7 @@ describe("Edge Case: Concurrent Task Checkout (D-05.1)", () => {
expect(db.checkoutTask(taskId, runIdA)).toBe(true);
// Backdate to make stale
(db as any).db
(db as unknown as RawDb).db
.prepare("UPDATE tasks SET execution_locked_at = '2020-01-01T00:00:00Z' WHERE id = ?")
.run(taskId);
+9 -2
View File
@@ -2,10 +2,17 @@ import { mkdtemp, rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { IpcMainInvokeEvent } from "electron";
import type { DesktopResult } from "@shared/contracts";
import { IPC_CHANNELS } from "@shared/contracts";
import { AppDatabase } from "../../src/main/database";
import { registerCoreAgentGraphHandlers } from "../../src/main/ipc-core-agent-graph-handlers";
type IpcHandler = (
event: IpcMainInvokeEvent,
...args: unknown[]
) => Promise<DesktopResult<unknown>> | DesktopResult<unknown>;
const tempDirs: string[] = [];
async function createTempDir(prefix: string) {
@@ -60,7 +67,7 @@ describe("ipc-core-agent-graph-handlers model enforcement", () => {
budgetMonthlyUsd: 250,
});
const handlers = new Map<string, (...args: any[]) => any>();
const handlers = new Map<string, IpcHandler>();
registerCoreAgentGraphHandlers({
registerHandle: (channel, handler) => {
handlers.set(channel, handler);
@@ -77,7 +84,7 @@ describe("ipc-core-agent-graph-handlers model enforcement", () => {
throw new Error("saveAgent handler was not registered.");
}
const result = await saveAgent(null, {
const result = await saveAgent(null as unknown as IpcMainInvokeEvent, {
id: agentId,
companyId,
name: "CEO",
+9 -2
View File
@@ -2,10 +2,17 @@ import { mkdtemp, rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { IpcMainInvokeEvent } from "electron";
import type { DesktopResult } from "@shared/contracts";
import { IPC_CHANNELS } from "@shared/contracts";
import { AppDatabase } from "../../src/main/database";
import { registerCoreAdminHandlers } from "../../src/main/ipc-core-admin-handlers";
type IpcHandler = (
event: IpcMainInvokeEvent,
...args: unknown[]
) => Promise<DesktopResult<unknown>> | DesktopResult<unknown>;
const tempDirs: string[] = [];
async function createTempDir(prefix: string) {
@@ -24,7 +31,7 @@ describe("ipc-core-admin-handlers connector saves", () => {
const db = new AppDatabase(profileDir);
db.init();
const handlers = new Map<string, (...args: any[]) => any>();
const handlers = new Map<string, IpcHandler>();
registerCoreAdminHandlers({
registerHandle: (channel, handler) => {
handlers.set(channel, handler);
@@ -43,7 +50,7 @@ describe("ipc-core-admin-handlers connector saves", () => {
throw new Error("saveConnector handler was not registered.");
}
const result = await saveConnector(null, {
const result = await saveConnector(null as unknown as IpcMainInvokeEvent, {
id: "claude_compatible",
command: "claude",
model: "model-alpha,model-beta,model-gamma",
+8 -8
View File
@@ -141,17 +141,17 @@ async function handleGranularBatch(
events: GranularEventEntry[],
deps: {
companyId: string | null;
getTask: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: any }>;
getRun: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: any }>;
getApproval: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: any }>;
getAgent: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: any }>;
patchTask: (task: any) => void;
getTask: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: unknown }>;
getRun: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: unknown }>;
getApproval: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: unknown }>;
getAgent: (input: { companyId: string; id: string }) => Promise<{ ok: boolean; data?: unknown }>;
patchTask: (task: unknown) => void;
removeTask: (id: string) => void;
patchRun: (run: any) => void;
patchRun: (run: unknown) => void;
removeRun: (id: string) => void;
patchApproval: (approval: any) => void;
patchApproval: (approval: unknown) => void;
removeApproval: (id: string) => void;
patchAgent: (agent: any) => void;
patchAgent: (agent: unknown) => void;
refreshBadges: () => Promise<void>;
fullRefresh: () => void;
},
+2 -2
View File
@@ -736,8 +736,8 @@ describe("wiring integration", () => {
function simulateRunFinishedSessionWiring(
sessionService: ReturnType<typeof createMockSessionService>,
db: {
getActiveTaskSession: (...args: any[]) => any;
getActiveTaskSession: (...args: unknown[]) => { id: string; taskId: string; runCount: number; totalInputTokens: number; totalOutputTokens: number } | null;
},
task: { id: string } | null,
event: { inputTokens: number | null; outputTokens: number | null; runId: string },