spec icon indicating copy to clipboard operation
spec copied to clipboard

Change one policy fixture

Open expede opened this issue 3 months ago • 0 comments

It's possible that my brain is breaking down the problem incorrectly, but here's why I think we should change this fixture:

Here's the existing fixture (laid out differently so that it more easily fits on one line in this tiny box)

args: {
    "newsletters": {
        "recipients": [
            { "email": "[email protected]" },
            { "email": "[email protected]" }
        ]
    }
},
"policies": [
    // Policy #1
    [
        ["all", ".newsletters",
            ["any", ".recipients", ["==", ".email", "[email protected]"]]]
    ]
]

Let's break this down. I think the first step is where our understandings diverge:

// ["all", ".newsletters", ...]
args: {
    "newsletters": {
        "recipients": [                      // <= Outer map
            { "email": "[email protected]" },  // <---- inner array
            { "email": "[email protected]" } // <---- inner array
        ]                                    // <= Outer map
    }
},

newsletters has a single element, and running all on an array would grab each element in the array. For a map, it drops the keys and returns an array of the values. In this case, that would be the inner array (each email object).

I believe this behaviour to be consistent, since you can imagine cases like this:

args: {
    "newsletters": {
        "sale": { // Newsletter #1
            "recipients": [
                { "email": "[email protected]" },
            ]
        },
        "hiring": {  // Newsletter #2
            "recipients": [
                { "email": "[email protected]" },
                { "email": "[email protected]" }
            ]
        },
        "fundraising": {  // Newsletter #3
            "recipients": [
                { "email": "[email protected]" },
                { "email": "[email protected]" },
                { "carol": "[email protected]" }
            ]
        },
    }
}

Here, I think this more closely fits if we translate our predicate to English: "for all newsletters, ensure that some recipient has the email equal to [email protected]".

["all", ".newsletters", // for all .newsletters,
  ["any", ".recipients", // ensure that some recipient
    ["==", ".email", "[email protected]"]]] // has the .email equal to [email protected]

My guess is that anyone who's tests pass on the current fixture treat the map as the first element of an array by wrapping it. Doing so would break the "for each newsletter" logic when you have many named newsletters.

It's possible that we previously discussed this case and I've simply forgotten, but the above is my current understanding.

expede avatar Oct 13 '25 04:10 expede