-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathmollifierDecisionLabels.test.ts
More file actions
54 lines (48 loc) · 1.97 KB
/
Copy pathmollifierDecisionLabels.test.ts
File metadata and controls
54 lines (48 loc) · 1.97 KB
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
import { describe, expect, it } from "vitest";
import { decisionLabels } from "~/v3/mollifier/mollifierTelemetry.server";
// The cardinality guard. `org` is a bounded label (enrolled cohort is capped
// at <= 10 orgs operationally), so it may ONLY be attached when the org is
// enrolled. Attaching it for non-enrolled orgs would fan `mollifier.decisions`
// out across every org id in production — the high-cardinality blow-up these
// labels are explicitly designed to avoid.
describe("decisionLabels", () => {
it("always emits a bounded `enrolled` label (true/false)", () => {
expect(decisionLabels("pass_through", { enrolled: false })).toEqual({
outcome: "pass_through",
enrolled: "false",
});
expect(decisionLabels("pass_through", { enrolled: true, orgId: "org_1" })).toMatchObject({
enrolled: "true",
});
});
it("attaches the `org` label ONLY when enrolled — never for non-enrolled, even if orgId is passed", () => {
// Non-enrolled: orgId passed but MUST be dropped (cardinality guard).
expect(decisionLabels("pass_through", { enrolled: false, orgId: "org_unbounded" })).toEqual({
outcome: "pass_through",
enrolled: "false",
});
// Enrolled: org label present.
expect(
decisionLabels("mollify", { enrolled: true, orgId: "org_1", reason: "per_env_rate" }),
).toEqual({
outcome: "mollify",
enrolled: "true",
reason: "per_env_rate",
org: "org_1",
});
});
it("omits `org` when enrolled but no orgId is supplied", () => {
expect(decisionLabels("pass_through", { enrolled: true })).toEqual({
outcome: "pass_through",
enrolled: "true",
});
});
it("includes `reason` only when supplied", () => {
expect(decisionLabels("pass_through", { enrolled: true, orgId: "org_1" })).not.toHaveProperty(
"reason",
);
expect(
decisionLabels("shadow_log", { enrolled: false, reason: "per_env_rate" }),
).toMatchObject({ reason: "per_env_rate" });
});
});