LibreChat/scripts/quality/shard.mts
lia-by-librechat[bot] 42219ec8e9
🚜 feat: Support Native PostgreSQL Tool Favorites (#18032)
* 🚜 feat: Support Native PostgreSQL Tool Favorites

* fix: Guard PostgreSQL Reconciliation and Connection Leases

* fix: Scope Favorites Erasure Fences to Deletion Attempts

* fix: Preserve Account Erasure Ownership Until Cancellation Completes

* fix: Reject Unsupported PostgreSQL Command Flags Before Connecting

* fix: Keep Command Validation Compatible With the TypeScript Target

* fix: Keep Migration Previews Read-Only and Preserve Erasure Recovery Identity

* fix: Fence Erasure Recovery Across Tenant and Ownership Changes

* fix: Isolate Migration Dependencies and Keep Mongo Scans Outside Transactions

* fix: Inject PostgreSQL Backend Factories at Composition Roots

* ci: Shard Complete Mutation Work Without Relaxing the Aggregate Gate

---------

Co-authored-by: Lia <lia@librechat.ai>
2026-11-11 12:07:07 -05:00

30 lines
1.1 KiB
TypeScript

export interface Shard {
index: number;
total: number;
}
export function parseShard(
value: string | undefined,
check: string | undefined,
): Shard | undefined {
if (value === undefined) return undefined;
if (check !== 'mutation') throw new Error('--shard is only allowed for mutation checks');
if (!/^[1-9]\d*\/[1-9]\d*$/u.test(value)) {
throw new Error('--shard must be INDEX/COUNT with positive integers and INDEX <= COUNT');
}
const [index, total] = value.split('/').map(Number);
if (!Number.isSafeInteger(index) || !Number.isSafeInteger(total) || index > total) {
throw new Error('--shard must be INDEX/COUNT with positive integers and INDEX <= COUNT');
}
return { index, total };
}
export function shardTargets<T extends { file: string; functions: readonly unknown[] }>(
targets: readonly T[],
shard?: Shard,
): readonly T[] {
if (!shard) return targets;
return [...targets]
.sort((a, b) => b.functions.length - a.functions.length || a.file.localeCompare(b.file))
.filter((_target, index) => index % shard.total === shard.index - 1);
}