File size: 2,180 Bytes
fcf8749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function verify() {
    console.log("--- Synergy & Relay Logic Verification ---");

    try {
        // 1. Fetch search candidate
        const trucks = await prisma.truck.findMany({ include: { deliveries: true, owner: true } });
        if (trucks.length < 2) {
            console.error("Need at least 2 trucks for testing.");
            return;
        }

        const truckA = trucks[0];
        const truckB = trucks[1];
        const hub = await prisma.virtualHub.findFirst();

        if (!hub) {
            console.error("No VirtualHub found. Please seed the database.");
            return;
        }

        console.log(`Testing with TruckA: ${truckA.licensePlate}, TruckB: ${truckB.licensePlate}, Hub: ${hub.name}`);

        // Mocking the search logic check (Material Compatibility)
        const cargoA = truckA.deliveries[0]?.cargoType || 'Food';
        const cargoB = truckB.deliveries[0]?.cargoType || 'Chemicals';

        const isChemicalA = cargoA.toLowerCase().includes('chemical');
        const isFoodPharmaB = cargoB.toLowerCase().includes('food') || cargoB.toLowerCase().includes('pharma');
        const safetyViolation = (isChemicalA && isFoodPharmaB);

        console.log(`Safety Violation Check (${cargoA} vs ${cargoB}): ${safetyViolation}`);

        // Mocking Accept logic (OTP and RelayNode)
        const otpCode = Math.floor(100000 + Math.random() * 900000).toString();
        console.log(`Generated OTP: ${otpCode}`);

        // Driver Relay Rule Check
        const workloadA = (truckA.owner.totalDistanceKm || 0) + (truckA.owner.totalHoursWorked || 0);
        const workloadB = (truckB.owner.totalDistanceKm || 0) + (truckB.owner.totalHoursWorked || 0);
        console.log(`Workload A: ${workloadA}, Workload B: ${workloadB}`);
        console.log(`Winner (Long Segment): ${workloadA >= workloadB ? truckA.owner.name : truckB.owner.name}`);

        console.log("Verification Logic: PASSED");

    } catch (err) {
        console.error("Verification failed:", err);
    } finally {
        await prisma.$disconnect();
    }
}

verify();