feat(availability): resource ordering strategies, and a real fix for the flaky suite
Strategies (task 06 debt, task 12 dependency) - ResourcePicker orders candidates; it deliberately does not choose. Only the engine knows which resource actually fits this slot and which was already taken by another role, and a strategy that picked would have to duplicate both checks - Four implementations behind a tagged iterator: first_available (name order, the previous behaviour and still the default because it is predictable), least_gap, least_loaded, same_as_previous - least_gap and least_loaded are deliberate opposites and both are correct; choosing between them is a business decision, so it lives in settings - same_as_previous lifts a course's preferred resource to the front and keeps everyone else behind it. A preference, not a filter: forcing the same operator would make the patient wait two weeks, which is worse than a different operator - Availability accepts course_uuid to supply that preference, closing the dependency task 12 recorded against task 06 - An unknown strategy falls back at search time but is rejected at save time. Stale settings must not stop bookings; a user typing a wrong value must not believe it took effect Test suite flake createUser() retries on a mobile-number collision — db_test is never reset and holds tens of thousands of users, so the random draw does collide. The failed INSERT closes the EntityManager, and the retry asked the container for it again, which hands back the *same closed instance*. So the retry threw, and every later test in that process inherited a dead manager. That is the intermittent "EntityManager is closed" on an unrelated, always-different test that made roughly half of full runs red and never reproduced in a subset. Resetting the registry gives a live manager back. UserCollisionRetryTest pins it by closing the manager on purpose. Two consecutive full runs are green: 1334 tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,8 @@ interface BookingMeta {
|
||||
booking_mode: 'slot' | 'service' | 'resource';
|
||||
/** گام جستجوی وقت در حالت منبعمحور — دقیقه */
|
||||
step_minutes?: number;
|
||||
/** ترتیب امتحانکردن منابع در حالت منبعمحور */
|
||||
resource_strategy?: string;
|
||||
buffer_minutes: number;
|
||||
}
|
||||
type BookingWindowUnit = 'day' | 'week' | 'month';
|
||||
@@ -559,6 +561,19 @@ export function WeeklyScheduleTab({ doctorUuid, clinicUuid, addresses, readOnly
|
||||
* درخواست اضافه روی هر بازکردن تنظیمات، برای چیزی که اکثر کلینیکها انتخابش
|
||||
* نمیکنند، هزینهٔ بیدلیل است.
|
||||
*/
|
||||
/** فهرست استراتژیها از سرور میآید، نه از فهرستی که در فرانت تکرار شود. */
|
||||
const strategiesQ = useQuery({
|
||||
queryKey: ['resource-strategies'],
|
||||
queryFn: () =>
|
||||
api.get<ApiResponse<{ code: string; label: string }[]>>(
|
||||
'/api/v1/appointment-settings/resource-strategies',
|
||||
),
|
||||
enabled: meta.booking_mode === 'resource',
|
||||
staleTime: 300_000,
|
||||
});
|
||||
|
||||
const strategies = strategiesQ.data?.data ?? [];
|
||||
|
||||
const readinessQ = useQuery({
|
||||
queryKey: ['resource-mode-readiness'],
|
||||
queryFn: async () => {
|
||||
@@ -796,6 +811,25 @@ export function WeeklyScheduleTab({ doctorUuid, clinicUuid, addresses, readOnly
|
||||
</div>
|
||||
)}
|
||||
|
||||
{meta.booking_mode === 'resource' && strategies.length > 0 && (
|
||||
<div className="space-y-1.5">
|
||||
<span className="text-sm text-[var(--text-2)]">ترتیب انتخاب منابع</span>
|
||||
<div className="max-w-md">
|
||||
<GlobalSearchableSelect
|
||||
value={meta.resource_strategy ?? 'first_available'}
|
||||
onChange={(v) =>
|
||||
setMeta(m => ({ ...m, resource_strategy: String(v ?? 'first_available') }))
|
||||
}
|
||||
options={strategies.map(s => ({ value: s.code, label: s.label }))}
|
||||
/>
|
||||
</div>
|
||||
<p className="text-xs text-[var(--text-3)] leading-relaxed">
|
||||
این فقط ترتیب امتحانکردن منابع را عوض میکند؛ اگر منبعی آزاد نباشد در هر
|
||||
حالت رد میشود و وقت از دست نمیرود.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{meta.booking_mode === 'resource' && (
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm text-[var(--text-2)]">گام جستجوی وقت</span>
|
||||
|
||||
Reference in New Issue
Block a user