style: satisfy housekeeping biome gate

This commit is contained in:
Simo committed 2026-08-30 11:59:24 +02:00
1 parent d1160eb65a
commit 08358b8aa4
62 files changed
+2024 -773

No files matched your search

@@ -47,7 +47,9 @@ describe("People moderation commands", () => {
const command = commands.find((entry) => entry.id === id);
if (!command) throw new Error("command missing");
expect(command.requiresReason).toBe(true);
expect(confirmHousekeepingCommand(command, " ", "moderation")).toMatchObject({
expect(
confirmHousekeepingCommand(command, " ", "moderation"),
).toMatchObject({
ok: false,
error: { code: "VALIDATION" },
});
@@ -63,9 +65,7 @@ describe("People moderation commands", () => {
const created = createModerationCommands({
execute,
}) as unknown as readonly HousekeepingCommand<unknown, unknown>[];
const command = created.find(
(entry) => entry.id === "people.cfh.sanction",
);
const command = created.find((entry) => entry.id === "people.cfh.sanction");
if (!command) throw new Error("command missing");
expect(
command.input.safeParse({
@@ -106,16 +106,26 @@ describe("People moderation commands", () => {
it.each([
["people.cfh.resolve", { ticketId: 9, state: 2 }, "cfh.resolve"],
["people.ban.create", { userId: 7, reason: "spam", hours: 24, type: "account" }, "ban.create"],
[
"people.ban.create",
{ userId: 7, reason: "spam", hours: 24, type: "account" },
"ban.create",
],
["people.ban.lift", { id: 12 }, "ban.lift"],
["people.moderation.action", { action: "alert", userId: 7, message: "Stop" }, "moderation.action"],
[
"people.moderation.action",
{ action: "alert", userId: 7, message: "Stop" },
"moderation.action",
],
] as const)("delegates %s to %s", async (id, input, operation) => {
const execute = vi.fn(async (invocation) => ({
ok: true as const,
data: { before: null, after: null },
correlationId: invocation.correlationId,
}));
const created = createModerationCommands({ execute }) as unknown as readonly HousekeepingCommand<unknown, unknown>[];
const created = createModerationCommands({
execute,
}) as unknown as readonly HousekeepingCommand<unknown, unknown>[];
const command = created.find((entry) => entry.id === id);
if (!command) throw new Error("command missing");
const parsed = command.input.parse(input);
@@ -128,5 +128,6 @@ export function createModerationCommands(
] as const;
}
export const MODERATION_COMMANDS =
createModerationCommands(peopleMutationService);
export const MODERATION_COMMANDS = createModerationCommands(
peopleMutationService,
);
File diff suppressed because it is too large. Load diff
@@ -72,7 +72,10 @@ export function createSupportCommands(
id: "people.ticket.assign",
operation: "ticket.assign",
capability: ticketEdit,
input: z.object({ ticketId: positiveId, assigneeId: positiveId.nullable() }),
input: z.object({
ticketId: positiveId,
assigneeId: positiveId.nullable(),
}),
}),
command(service, {
id: "people.ticket.status",
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -288,9 +288,9 @@ describe("People primary route registration", () => {
HOUSEKEEPING_ROUTE_HANDLERS.map((handler) => handler.routeId),
).toEqual(expect.arrayContaining(expected));
expect(
(
HOUSEKEEPING_MANIFESTS as readonly HousekeepingDomainManifest[]
).flatMap((manifest) => manifest.routes.map((route) => route.id)),
(HOUSEKEEPING_MANIFESTS as readonly HousekeepingDomainManifest[]).flatMap(
(manifest) => manifest.routes.map((route) => route.id),
),
).toEqual(HOUSEKEEPING_ROUTE_HANDLERS.map((handler) => handler.routeId));
});
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -28,10 +28,7 @@ function context(granted: readonly string[]): HousekeepingCapabilityContext {
}
async function load(granted: readonly string[]) {
return PEOPLE_WIDGETS[0].load(
context(granted),
new AbortController().signal,
);
return PEOPLE_WIDGETS[0].load(context(granted), new AbortController().signal);
}
beforeEach(() => {
@@ -78,10 +75,10 @@ describe("People production queue widget", () => {
.mockResolvedValueOnce([[{ total: 3 }], []])
.mockResolvedValueOnce([[{ total: 4 }], []]);
const mixed = await load([
PERMS.MOD_TICKETS_VIEW,
PERMS.MOD_CFH_VIEW,
PERMS.MOD_BANS_VIEW,
]);
PERMS.MOD_TICKETS_VIEW,
PERMS.MOD_CFH_VIEW,
PERMS.MOD_BANS_VIEW,
]);
expect(mocks.fetchTicketQueueOpenCounts).toHaveBeenCalledTimes(1);
expect(mocks.execute).toHaveBeenCalledTimes(2);
expect(mixed).toMatchObject({
@@ -49,7 +49,9 @@ export interface PeopleSearchAdapters {
}
function boundedLimit(limit: number): number {
return Number.isFinite(limit) ? Math.min(25, Math.max(1, Math.trunc(limit))) : 25;
return Number.isFinite(limit)
? Math.min(25, Math.max(1, Math.trunc(limit)))
: 25;
}
function createProvider(
@@ -2,10 +2,7 @@ import "server-only";
import { eq } from "drizzle-orm";
import { Ban, type Db, SupportTickets, User } from "@/lib/db";
import type {
AuditEntry,
HousekeepingAuditWriter,
} from "@/lib/services/audit";
import type { AuditEntry, HousekeepingAuditWriter } from "@/lib/services/audit";
import type {
ModerationAction,
ModerationActionTransport,
@@ -55,10 +52,7 @@ export interface PeopleModerationMutationDependencies {
snapshot: PeopleModerationMutationSnapshot,
outcome: AuditOutcome,
) => AuditEntry;
readonly failure: (
code: HousekeepingErrorCode,
messageKey: string,
) => Error;
readonly failure: (code: HousekeepingErrorCode, messageKey: string) => Error;
readonly record: (input: unknown) => Record<string, unknown>;
readonly positiveInteger: (value: unknown) => number;
readonly nonNegativeInteger: (value: unknown) => number;
@@ -328,14 +322,7 @@ export function createPeopleModerationMutationExecutor(
},
};
await writeAudit(
auditEntry(
context,
operation,
"Ban",
banId,
snapshot,
"intent",
),
auditEntry(context, operation, "Ban", banId, snapshot, "intent"),
tx,
);
});
@@ -380,14 +367,7 @@ export function createPeopleModerationMutationExecutor(
await tx.delete(Ban).where(eq(Ban.id, id));
snapshot = { before: existing ?? null, after: null };
await writeAudit(
auditEntry(
context,
operation,
"Ban",
id,
snapshot,
"intent",
),
auditEntry(context, operation, "Ban", id, snapshot, "intent"),
tx,
);
});
@@ -11,10 +11,7 @@ import {
WebsiteTicketMessage,
WebsiteTicketTemplate,
} from "@/lib/db";
import type {
AuditEntry,
HousekeepingAuditWriter,
} from "@/lib/services/audit";
import type { AuditEntry, HousekeepingAuditWriter } from "@/lib/services/audit";
import type {
HousekeepingCapabilityContext,
HousekeepingErrorCode,
@@ -62,10 +59,7 @@ export interface PeopleSupportMutationDependencies {
snapshot: PeopleSupportMutationSnapshot,
outcome: AuditOutcome,
) => AuditEntry;
readonly failure: (
code: HousekeepingErrorCode,
messageKey: string,
) => Error;
readonly failure: (code: HousekeepingErrorCode, messageKey: string) => Error;
readonly record: (input: unknown) => Record<string, unknown>;
readonly positiveInteger: (value: unknown) => number;
readonly nonNegativeInteger: (value: unknown) => number;
@@ -74,9 +68,7 @@ export interface PeopleSupportMutationDependencies {
max: number,
required?: boolean,
) => string;
readonly canonicalTicketId: (
value: string | number | bigint,
) => bigint;
readonly canonicalTicketId: (value: string | number | bigint) => bigint;
readonly auditTargetId: (value: bigint) => number | undefined;
}
@@ -299,19 +291,14 @@ export function createPeopleSupportMutationExecutor(
}
async function executeHelpTicketMutation(
operation: Extract<
PeopleSupportMutationOperation,
`help-ticket.${string}`
>,
operation: Extract<PeopleSupportMutationOperation, `help-ticket.${string}`>,
input: unknown,
context: PeopleSupportMutationContext,
): Promise<PeopleSupportMutationSnapshot> {
const data = record(input);
let ticketId: bigint;
try {
ticketId = canonicalTicketId(
data.ticketId as string | number | bigint,
);
ticketId = canonicalTicketId(data.ticketId as string | number | bigint);
} catch {
throw failure("VALIDATION", "errors.housekeeping.validation");
}
@@ -354,11 +341,7 @@ export function createPeopleSupportMutationExecutor(
} else if (operation === "help-ticket.status") {
const status = normalizedText(data.status, 16);
const open =
status === "reopen"
? true
: status === "close"
? false
: null;
status === "reopen" ? true : status === "close" ? false : null;
if (open === null) {
throw failure("VALIDATION", "errors.housekeeping.validation");
}
@@ -35,10 +35,7 @@ const cfhQueueCapability = anyCapability(
PERMS.MODERATION_VIEW,
PERMS.MOD_CFH_VIEW,
);
const banQueueCapability = anyCapability(
PERMS.BANS_VIEW,
PERMS.MOD_BANS_VIEW,
);
const banQueueCapability = anyCapability(PERMS.BANS_VIEW, PERMS.MOD_BANS_VIEW);
const queueCapability = anyCapability(
...supportQueueCapability.slugs,
...cfhQueueCapability.slugs,
@@ -82,42 +79,44 @@ export function createPeopleQueueAggregateLoader(
export function createPeopleWidgets(
adapters: PeopleWidgetAdapters,
): readonly HousekeepingWidgetDefinition[] {
return [{
id: "people.queue",
owner: "people",
capability: queueCapability,
kind: "mandatory",
async load(context, signal) {
const authorization = authorizeHousekeeping(context, queueCapability);
if (!authorization.ok) return authorization;
try {
const queue = await adapters.queue(context, signal);
return ok(
{
tickets: satisfiesCapability(context, supportQueueCapability)
? queue.tickets
: 0,
helpTickets: satisfiesCapability(context, supportQueueCapability)
? queue.helpTickets
: 0,
cfh: satisfiesCapability(context, cfhQueueCapability)
? queue.cfh
: 0,
activeBans: satisfiesCapability(context, banQueueCapability)
? queue.activeBans
: 0,
},
authorization.correlationId,
);
} catch {
return fail(
"DEPENDENCY_UNAVAILABLE",
"errors.housekeeping.dependencyUnavailable",
authorization.correlationId,
);
}
return [
{
id: "people.queue",
owner: "people",
capability: queueCapability,
kind: "mandatory",
async load(context, signal) {
const authorization = authorizeHousekeeping(context, queueCapability);
if (!authorization.ok) return authorization;
try {
const queue = await adapters.queue(context, signal);
return ok(
{
tickets: satisfiesCapability(context, supportQueueCapability)
? queue.tickets
: 0,
helpTickets: satisfiesCapability(context, supportQueueCapability)
? queue.helpTickets
: 0,
cfh: satisfiesCapability(context, cfhQueueCapability)
? queue.cfh
: 0,
activeBans: satisfiesCapability(context, banQueueCapability)
? queue.activeBans
: 0,
},
authorization.correlationId,
);
} catch {
return fail(
"DEPENDENCY_UNAVAILABLE",
"errors.housekeeping.dependencyUnavailable",
authorization.correlationId,
);
}
},
},
}];
];
}
export const PEOPLE_WIDGETS = createPeopleWidgets({