|
| 1 | +// The two global write routes used to carry their own copy of "which keys are graced" and "which |
| 2 | +// keys are derived". A new graced group would then need an edit in three places, and missing one |
| 3 | +// means an unstamped flip or a stamp written straight from a request body. Both routes now derive |
| 4 | +// both answers from the group table, and these tests pin that. Pure, no containers. |
| 5 | +import { describe, expect, it } from "vitest"; |
| 6 | +import { FEATURE_FLAG, lockedFlagsInPayload } from "~/v3/featureFlags"; |
| 7 | +import { touchesGracedGroup, withoutDerivedKeys } from "~/v3/featureFlags.server"; |
| 8 | + |
| 9 | +describe("touchesGracedGroup — decides whether a save needs the stamped path", () => { |
| 10 | + it("is true for a mint-kind change", () => { |
| 11 | + expect(touchesGracedGroup({ [FEATURE_FLAG.runOpsMintKind]: "runOpsId" })).toBe(true); |
| 12 | + }); |
| 13 | + |
| 14 | + it("is true for a shard-list change", () => { |
| 15 | + expect(touchesGracedGroup({ [FEATURE_FLAG.runOpsMintShardSet]: "a,b" })).toBe(true); |
| 16 | + }); |
| 17 | + |
| 18 | + it("is false for an ordinary flag, which writes directly", () => { |
| 19 | + expect(touchesGracedGroup({ [FEATURE_FLAG.mollifierEnabled]: true })).toBe(false); |
| 20 | + expect(touchesGracedGroup({})).toBe(false); |
| 21 | + }); |
| 22 | + |
| 23 | + it("is false when only a DERIVED key is present", () => { |
| 24 | + // A body carrying only a stamp changes no group. Treating it as a flip would let a caller |
| 25 | + // reset a cutover clock without touching the value the clock dates. |
| 26 | + expect(touchesGracedGroup({ [FEATURE_FLAG.runOpsMintKindPrev]: "cuid" })).toBe(false); |
| 27 | + expect(touchesGracedGroup({ [FEATURE_FLAG.runOpsMintShardSetPrev]: "a" })).toBe(false); |
| 28 | + }); |
| 29 | + |
| 30 | + it("covers every graced primary, so a new group needs no route edit", () => { |
| 31 | + // The routes no longer name these keys. If a group is added and this list is not, the next |
| 32 | + // assertion fails rather than the group silently skipping the stamp. |
| 33 | + const gracedPrimaries = [FEATURE_FLAG.runOpsMintKind, FEATURE_FLAG.runOpsMintShardSet]; |
| 34 | + for (const key of gracedPrimaries) { |
| 35 | + expect(touchesGracedGroup({ [key]: "x" })).toBe(true); |
| 36 | + } |
| 37 | + // Every key the strip removes belongs to a group whose primary is one of the above. |
| 38 | + const derived = Object.keys( |
| 39 | + withoutDerivedKeys({ |
| 40 | + [FEATURE_FLAG.runOpsMintKindPrev]: "cuid", |
| 41 | + [FEATURE_FLAG.runOpsMintKindFlippedAt]: "t", |
| 42 | + [FEATURE_FLAG.runOpsMintShardSetPrev]: "a", |
| 43 | + [FEATURE_FLAG.runOpsMintShardSetFlippedAt]: "t", |
| 44 | + } as Record<string, unknown>) |
| 45 | + ); |
| 46 | + expect(derived).toEqual([]); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +describe("withoutDerivedKeys — a stamp is never taken from a request body", () => { |
| 51 | + it("strips both stamps and keeps everything else", () => { |
| 52 | + const out = withoutDerivedKeys({ |
| 53 | + [FEATURE_FLAG.runOpsMintKind]: "runOpsId", |
| 54 | + [FEATURE_FLAG.runOpsMintKindPrev]: "spoofed", |
| 55 | + [FEATURE_FLAG.runOpsMintKindFlippedAt]: "1999-01-01T00:00:00.000Z", |
| 56 | + [FEATURE_FLAG.runOpsMintShardSet]: "a,b", |
| 57 | + [FEATURE_FLAG.runOpsMintShardSetPrev]: "spoofed", |
| 58 | + [FEATURE_FLAG.runOpsMintShardSetFlippedAt]: "1999-01-01T00:00:00.000Z", |
| 59 | + [FEATURE_FLAG.mollifierEnabled]: true, |
| 60 | + } as Record<string, unknown>); |
| 61 | + |
| 62 | + expect(out).toEqual({ |
| 63 | + [FEATURE_FLAG.runOpsMintKind]: "runOpsId", |
| 64 | + [FEATURE_FLAG.runOpsMintShardSet]: "a,b", |
| 65 | + [FEATURE_FLAG.mollifierEnabled]: true, |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + it("does not mutate its input", () => { |
| 70 | + const input = { [FEATURE_FLAG.runOpsMintKindPrev]: "cuid" } as Record<string, unknown>; |
| 71 | + withoutDerivedKeys(input); |
| 72 | + expect(input[FEATURE_FLAG.runOpsMintKindPrev]).toBe("cuid"); |
| 73 | + }); |
| 74 | +}); |
| 75 | + |
| 76 | +describe("lockedFlagsInPayload — what the global page refuses", () => { |
| 77 | + it("refuses a locked flag on managed cloud, where the page never offers one", () => { |
| 78 | + const refused = lockedFlagsInPayload( |
| 79 | + [FEATURE_FLAG.taskEventRepository, FEATURE_FLAG.mollifierEnabled], |
| 80 | + true |
| 81 | + ); |
| 82 | + expect(refused).toEqual([FEATURE_FLAG.taskEventRepository]); |
| 83 | + }); |
| 84 | + |
| 85 | + it("refuses the mint-shard pins, which are per-org only", () => { |
| 86 | + expect(lockedFlagsInPayload([FEATURE_FLAG.runOpsMintShard], true)).toEqual([ |
| 87 | + FEATURE_FLAG.runOpsMintShard, |
| 88 | + ]); |
| 89 | + expect(lockedFlagsInPayload([FEATURE_FLAG.runOpsMintShardEnvPins], true)).toEqual([ |
| 90 | + FEATURE_FLAG.runOpsMintShardEnvPins, |
| 91 | + ]); |
| 92 | + }); |
| 93 | + |
| 94 | + it("refuses a grace stamp, which the server owns", () => { |
| 95 | + expect(lockedFlagsInPayload([FEATURE_FLAG.runOpsMintShardSetFlippedAt], true)).toEqual([ |
| 96 | + FEATURE_FLAG.runOpsMintShardSetFlippedAt, |
| 97 | + ]); |
| 98 | + }); |
| 99 | + |
| 100 | + it("allows the shard list, because that is the page's ramp lever", () => { |
| 101 | + expect(lockedFlagsInPayload([FEATURE_FLAG.runOpsMintShardSet], true)).toEqual([]); |
| 102 | + }); |
| 103 | + |
| 104 | + it("refuses nothing when not managed cloud, where an admin may unlock and edit", () => { |
| 105 | + expect(lockedFlagsInPayload([FEATURE_FLAG.taskEventRepository], false)).toEqual([]); |
| 106 | + }); |
| 107 | + |
| 108 | + it("refuses nothing for an empty payload", () => { |
| 109 | + expect(lockedFlagsInPayload([], true)).toEqual([]); |
| 110 | + }); |
| 111 | +}); |
0 commit comments