| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import { test } from "node:test"; |
| import assert from "node:assert/strict"; |
|
|
| import { summariseActivePairings } from "../evolution/shadow-core.ts"; |
|
|
| test("summariseActivePairings: empty input → empty output", () => { |
| assert.deepEqual(summariseActivePairings([]), []); |
| }); |
|
|
| test("summariseActivePairings: single pairing → one row with null timestamps when createdAt absent", () => { |
| const out = summariseActivePairings([ |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_a" }, |
| ]); |
| assert.deepEqual(out, [ |
| { |
| activeVariantId: "v_active_a", |
| sampleCount: 3, |
| firstSampleAt: null, |
| lastSampleAt: null, |
| }, |
| ]); |
| }); |
|
|
| test("summariseActivePairings: multiple pairings sorted by descending count", () => { |
| const out = summariseActivePairings([ |
| { activeVariantId: "v_active_b" }, |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_b" }, |
| ]); |
| assert.deepEqual(out, [ |
| { |
| activeVariantId: "v_active_a", |
| sampleCount: 3, |
| firstSampleAt: null, |
| lastSampleAt: null, |
| }, |
| { |
| activeVariantId: "v_active_b", |
| sampleCount: 2, |
| firstSampleAt: null, |
| lastSampleAt: null, |
| }, |
| ]); |
| }); |
|
|
| test("summariseActivePairings: ties broken by lexicographic variant id", () => { |
| |
| |
| |
| |
| const out = summariseActivePairings([ |
| { activeVariantId: "v_zzz" }, |
| { activeVariantId: "v_aaa" }, |
| { activeVariantId: "v_zzz" }, |
| { activeVariantId: "v_aaa" }, |
| ]); |
| assert.equal(out.length, 2); |
| assert.equal(out[0]!.activeVariantId, "v_aaa"); |
| assert.equal(out[1]!.activeVariantId, "v_zzz"); |
| }); |
|
|
| test("summariseActivePairings: caller cannot mutate the input array", () => { |
| |
| |
| const rows = Object.freeze([ |
| { activeVariantId: "v_active_a" }, |
| { activeVariantId: "v_active_b" }, |
| ]); |
| const out = summariseActivePairings(rows); |
| assert.equal(out.length, 2); |
| }); |
|
|
| test("summariseActivePairings: tracks first/last sample timestamps per pairing", () => { |
| |
| |
| |
| |
| const out = summariseActivePairings([ |
| { activeVariantId: "v_a", createdAt: new Date("2026-01-03T00:00:00Z") }, |
| { activeVariantId: "v_a", createdAt: new Date("2026-01-01T00:00:00Z") }, |
| { activeVariantId: "v_a", createdAt: new Date("2026-01-02T00:00:00Z") }, |
| { activeVariantId: "v_b", createdAt: new Date("2026-01-04T00:00:00Z") }, |
| ]); |
| assert.equal(out[0]!.activeVariantId, "v_a"); |
| assert.equal( |
| out[0]!.firstSampleAt!.toISOString(), |
| "2026-01-01T00:00:00.000Z", |
| ); |
| assert.equal( |
| out[0]!.lastSampleAt!.toISOString(), |
| "2026-01-03T00:00:00.000Z", |
| ); |
| assert.equal(out[1]!.activeVariantId, "v_b"); |
| assert.equal( |
| out[1]!.firstSampleAt!.toISOString(), |
| "2026-01-04T00:00:00.000Z", |
| ); |
| assert.equal( |
| out[1]!.lastSampleAt!.toISOString(), |
| "2026-01-04T00:00:00.000Z", |
| ); |
| }); |
|
|
| test("summariseActivePairings: rows missing createdAt do not corrupt the timestamps", () => { |
| |
| |
| const out = summariseActivePairings([ |
| { activeVariantId: "v_a", createdAt: new Date("2026-01-02T00:00:00Z") }, |
| { activeVariantId: "v_a" }, |
| { activeVariantId: "v_a", createdAt: null }, |
| ]); |
| assert.equal(out[0]!.sampleCount, 3); |
| assert.equal( |
| out[0]!.firstSampleAt!.toISOString(), |
| "2026-01-02T00:00:00.000Z", |
| ); |
| assert.equal( |
| out[0]!.lastSampleAt!.toISOString(), |
| "2026-01-02T00:00:00.000Z", |
| ); |
| }); |
|
|