Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import * as fc from "fast-check";
import {
AssignmentEngine,
MeshCapacityTracker,
type MeshDescriptor,
type PeerInfo,
} from "../../src/index.js";
describe("AssignmentEngine scoring is deterministic", () => {
it("same input twice produces identical scores", () => {
fc.assert(
fc.property(
fc.array(
fc.tuple(
fc.string({ minLength: 1, maxLength: 6 }),
fc.integer({ min: 1, max: 100 }),
fc.integer({ min: 0, max: 5 })
),
{ minLength: 1, maxLength: 5 }
),
fc.integer({ min: 0, max: 5 }),
(entries, tierEligibility) => {
const seen = new Set<string>();
const meshes: MeshDescriptor[] = [];
const latencyMap = new Map<string, number>();
for (const [name, latency, tierFloor] of entries) {
if (seen.has(name)) continue;
seen.add(name);
meshes.push({ meshId: name, tierFloor });
latencyMap.set(name, latency);
}
if (meshes.length === 0) return;
const peer: PeerInfo = {
peerId: "p",
latencyMap,
tierEligibility,
capabilities: "STANDARD",
};
const tracker = new MeshCapacityTracker();
for (const m of meshes) tracker.recordMesh(m.meshId, 10);
const engine = new AssignmentEngine({ tracker });
const a = engine.score(peer, meshes);
const b = engine.score(peer, meshes);
expect(a.map((s) => s.score)).toEqual(
b.map((s) => s.score)
);
}
),
{ numRuns: 50 }
);
});
});