Skip to content

Commit 384b07b

Browse files
committed
rejig constant
1 parent d61db97 commit 384b07b

8 files changed

Lines changed: 45 additions & 44 deletions

File tree

ab-testing/config/lib/constants.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,4 @@ const MVT_COUNT = 1000;
1313
*/
1414
const MAX_SERVER_SIDE_TESTS = 20;
1515

16-
/**
17-
* The spaces used for test groups, each space covers the entire mvt space allowing for concurrent overlapping tests where necessary.
18-
* If this is increased, the fastly VCL configuration will need to be updated to match.
19-
*/
20-
const AUDIENCE_SPACES = ["A", "B", "C", "D", "E"] as const;
21-
22-
type AudienceSpaceId = (typeof AUDIENCE_SPACES)[number];
23-
24-
export {
25-
MVT_COUNT,
26-
MAX_SERVER_SIDE_TESTS,
27-
AUDIENCE_SPACES,
28-
type AudienceSpaceId,
29-
};
16+
export { MVT_COUNT, MAX_SERVER_SIDE_TESTS };

ab-testing/config/lib/fastly-subfield.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { deepEqual, equal, throws } from "node:assert";
22
import test from "node:test";
3-
import { AUDIENCE_SPACES } from "./constants.ts";
43
import {
54
parseFastlySubfield,
65
parseMVTValue,

ab-testing/config/lib/fastly-subfield.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AUDIENCE_SPACES } from "./constants.ts";
1+
import { AUDIENCE_SPACES } from "../types.ts";
22
import type { FastlyTestParams } from "./types.ts";
33

44
const validateValue = (value: string | number, allowedColons: number): void => {

ab-testing/config/lib/shuffled-space.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { type AudienceSpaceId } from "./constants.ts";
1+
import { type AudienceSpaceId } from "../types.ts";
22

33
/**
44
* A shuffled space of MVTs for each audience space, storing the MVTs in a random order here is easier than trying to deterministically calculate a pseudorandom order each time we need to allocate MVTs for a test group.

ab-testing/config/scripts/build/calculate-mvt-updates.test.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ test("calculateSpaceUpdates - handles empty audience space and tests", () => {
8282
const emptyAudienceSpace = new Map<string, FastlyTestParams>();
8383
const emptyTests: ABTest[] = [];
8484

85-
const result = calculateSpaceUpdates(emptyAudienceSpace, emptyTests);
85+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, emptyTests);
8686

8787
equal(result.size, 0);
8888
equal(deleteTestGroupSpy.mock.callCount(), 0);
@@ -99,7 +99,7 @@ test("calculateSpaceUpdates - adds new test groups correctly", () => {
9999
}),
100100
];
101101

102-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
102+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
103103

104104
// Should have 2 MVT entries (one for each group)
105105
equal(result.size, 2);
@@ -137,7 +137,7 @@ test("calculateSpaceUpdates - removes tests no longer present", () => {
137137
}),
138138
];
139139

140-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
140+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
141141

142142
// Should only have entries for test1
143143
const testNames = new Set(
@@ -166,7 +166,7 @@ test("calculateSpaceUpdates - resizes existing test groups", () => {
166166
}),
167167
];
168168

169-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
169+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
170170

171171
// Should have 4 MVT entries total (2 per group)
172172
equal(result.size, 4);
@@ -189,7 +189,7 @@ test("calculateSpaceUpdates - handles fractional audience sizes correctly", () =
189189
}),
190190
];
191191

192-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
192+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
193193

194194
// With 0.004 audience size and 2 groups, each group gets 0.002 * 1000 = 2 MVTs
195195
equal(result.size, 4); // 2 * 2 groups
@@ -208,7 +208,7 @@ test("calculateSpaceUpdates - handles single group test", () => {
208208
}),
209209
];
210210

211-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
211+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
212212

213213
// All audience size goes to the single group
214214
equal(result.size, 2); // 0.002 * 1000 = 2 MVTs
@@ -234,7 +234,7 @@ test("calculateSpaceUpdates - handles multiple tests", () => {
234234
}),
235235
];
236236

237-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
237+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
238238

239239
// test1: 2 MVTs (1 per group), test2: 1 MVT = 3 total
240240
equal(result.size, 3);
@@ -263,7 +263,7 @@ test("calculateSpaceUpdates - preserves expiration dates", () => {
263263
}),
264264
];
265265

266-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
266+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
267267

268268
const entry = result.get("mvt:0");
269269
equal(entry?.exp, Math.floor(new Date(expirationDate).getTime() / 1000));
@@ -283,7 +283,7 @@ test("calculateSpaceUpdates - handles client-side tests", () => {
283283
}),
284284
];
285285

286-
const result = calculateSpaceUpdates(emptyAudienceSpace, tests);
286+
const result = calculateSpaceUpdates("A", emptyAudienceSpace, tests);
287287

288288
const entry = result.get("mvt:0");
289289
equal(entry?.type, "client");
@@ -475,7 +475,7 @@ test("calculateSpaceUpdates - resizes middle test with adjacent tests", () => {
475475
}),
476476
];
477477

478-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
478+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
479479

480480
// Should have 14 MVT entries total (4 + 6 + 4)
481481
equal(result.size, 14);
@@ -559,7 +559,7 @@ test("calculateSpaceUpdates - shrinks middle test with adjacent tests", () => {
559559
}),
560560
];
561561

562-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
562+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
563563

564564
// Should have 10 MVT entries total (4 + 2 + 4)
565565
equal(result.size, 10);
@@ -611,7 +611,7 @@ test("calculateSpaceUpdates - dividing tests into non integer group sizes should
611611
}),
612612
];
613613

614-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
614+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
615615

616616
// Should have 198 MVT entries total
617617
equal(result.size, 198);
@@ -686,7 +686,7 @@ test("calculateSpaceUpdates - handles insufficient MVTs when resizing middle tes
686686
// This should throw an error because there aren't enough available MVTs
687687
// to resize test2 from 4 MVTs to 20 MVTs (needs 16 additional MVTs but only 6 are available)
688688
throws(
689-
() => calculateSpaceUpdates(existingAudienceSpace, tests),
689+
() => calculateSpaceUpdates("A", existingAudienceSpace, tests),
690690
Error,
691691
"Not enough available MVTs for test commercial-test2:control",
692692
);
@@ -710,7 +710,7 @@ test("calculateSpaceUpdates - updates expiration date for existing test", () =>
710710
}),
711711
];
712712

713-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
713+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
714714

715715
// Check that all entries have the updated expiration date
716716
const controlEntry = result.get("mvt:0");
@@ -756,7 +756,7 @@ test("calculateSpaceUpdates - handles status change from ON to OFF by removing t
756756
}),
757757
];
758758

759-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
759+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
760760

761761
// Should only have entries for test1
762762
const testNames = new Set(
@@ -793,7 +793,7 @@ test("calculateSpaceUpdates - handles status change from OFF to ON by adding tes
793793
}),
794794
];
795795

796-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
796+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
797797

798798
// Should have entries for both tests
799799
const testNames = new Set(
@@ -827,7 +827,7 @@ test("calculateSpaceUpdates - updates both expiration and size simultaneously",
827827
}),
828828
];
829829

830-
const result = calculateSpaceUpdates(existingAudienceSpace, tests);
830+
const result = calculateSpaceUpdates("A", existingAudienceSpace, tests);
831831

832832
// Should have 4 MVT entries (2 per group) instead of 2
833833
equal(result.size, 4);

ab-testing/config/scripts/build/calculate-mvt-updates.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import {
2-
AUDIENCE_SPACES,
3-
type AudienceSpaceId,
4-
MVT_COUNT,
5-
} from "../../lib/constants.ts";
1+
import { MVT_COUNT } from "../../lib/constants.ts";
62
import type {
73
AllSpace,
84
AudienceSpace,
95
FastlyTestParams,
106
} from "../../lib/types.ts";
11-
import type { ABTest } from "../../types.ts";
7+
import {
8+
AUDIENCE_SPACES,
9+
type AudienceSpaceId,
10+
type ABTest,
11+
} from "../../types.ts";
1212
import { TestGroupMVTManager } from "./test-group-mvt-manager.ts";
1313

1414
const getTestGroupName = (

ab-testing/config/scripts/build/test-group-mvt-manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { type AudienceSpaceId, MVT_COUNT } from "../../lib/constants.ts";
1+
import { MVT_COUNT } from "../../lib/constants.ts";
22
import { shuffledSpace } from "../../lib/shuffled-space.ts";
33
import type { AudienceSpace } from "../../lib/types.ts";
4+
import type { AudienceSpaceId } from "../../types.ts";
45

56
/**
67
* A class to manage MVTs for test groups in a test space.

ab-testing/config/types.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { type AudienceSpaceId } from "./lib/constants.ts";
2-
31
type FastlyTestParams = { name: string; type: string; exp: number };
42

53
type AudienceSpace = Map<string, FastlyTestParams>;
@@ -24,6 +22,14 @@ type Year = `${number}${number}${number}${number}`;
2422
type Month = `${number}${number}`;
2523
type Day = `${number}${number}`;
2624

25+
/**
26+
* The spaces used for test groups, each space covers the entire mvt space allowing for concurrent overlapping tests where necessary.
27+
* If this is increased, the fastly VCL configuration will need to be updated to match.
28+
*/
29+
const AUDIENCE_SPACES = ["A", "B", "C", "D", "E"] as const;
30+
31+
type AudienceSpaceId = (typeof AUDIENCE_SPACES)[number];
32+
2733
type ABTest = {
2834
/** Name of the AB test */
2935
name: TestName;
@@ -69,4 +75,12 @@ type ABTest = {
6975
shouldReportToOphan?: () => boolean;
7076
};
7177

72-
export type { ABTest, FastlyTestParams, AudienceSpace, AllSpace };
78+
export { AUDIENCE_SPACES };
79+
80+
export type {
81+
ABTest,
82+
FastlyTestParams,
83+
AudienceSpace,
84+
AllSpace,
85+
AudienceSpaceId,
86+
};

0 commit comments

Comments
 (0)