Refactor updating enterprise policies#321
Conversation
1rneh
commented
Jan 8, 2026
- Refactor updating remote policies
- Fix merging policies of a combined provider when remote policies are updated
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
| ); | ||
|
|
||
| if (!isValid) { | ||
| continue; |
There was a problem hiding this comment.
This will cause the policy to be removed because it doesn't go in parsedPolicies, unclear if that is what you want.
There was a problem hiding this comment.
Good point! I didn't change that behavior. But let's re-think this :)
We have two options when encountering invalid parameters:
- Policy is currently active: We can remove the policy or keep it active with unchanged parameters. I think I prefer the latter. It's seems more intentional. In both ways we can warn in the logs about invalid parameters.
- Policy is currently inactive: Do nothing.
There was a problem hiding this comment.
This function is only called during initialization though so the policy cannot already be active here. The question is what happens later when the policies are updated if this invalid policy isn't listed in _parsedPolicies. It looks to me like you don't want it in _parsedPolicies because that would then cause us to try to call an onRemove handler for the policy even though we haven't actually applied it.
There was a problem hiding this comment.
Yes, it's also to avoid calling the onRemove callback when it's not applied. Additionally we probably want to avoid removing a valid policy if a remote policy update includes that policy with invalid parameters.
Instead we could add another property valid : true/false to each policy entry in _parsedPolicies and take that into account when activating/updating policies.
…emote-policies-update
This comment was marked as outdated.
This comment was marked as outdated.
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
| }, | ||
|
|
||
| get status() { | ||
| return this._status; |
There was a problem hiding this comment.
Given how error prone updating _status is, maybe we can add some sanity checks here for inconsistent status?
There was a problem hiding this comment.
Why is _status error prone?
There was a problem hiding this comment.
IIRC part of the review pointed out mistakes in updating _status. So the idea is to add some checks/assertions here to make catching any bugs easier, by checking if _status matches with the state of the rest of the object?
(I have not had a look at the PR yet so this may be invalid) From past experience I ran several times in regressions I introduced with remote fetching that broke some policies. So I think we should try and run with both, but maybe not right now, and maybe we'd like to scope them in a flagged suite, maybe |
From an offline conversation with @mkaply: Tests under |
…or-remote-policies-update
|
This PR is growing and entails quite a lot of entangled changes and therefore difficult to split into multiple patches:
Note: |
toolkit/components/enterprisepolicies/tests/browser/remote/browser_remote_policies_diffing.js
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
| ); | ||
|
|
||
| if (!isValid) { | ||
| continue; |
There was a problem hiding this comment.
This function is only called during initialization though so the policy cannot already be active here. The question is what happens later when the policies are updated if this invalid policy isn't listed in _parsedPolicies. It looks to me like you don't want it in _parsedPolicies because that would then cause us to try to call an onRemove handler for the policy even though we haven't actually applied it.
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
toolkit/components/enterprisepolicies/EnterprisePoliciesParent.sys.mjs
Outdated
Show resolved
Hide resolved
mkaply
left a comment
There was a problem hiding this comment.
I've asked some questions and made a few suggestions, but assuming this pasts the tests (and you've addressed Mossop's questions), this seems good.
toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.sys.mjs
Show resolved
Hide resolved
...t/components/enterprisepolicies/tests/browser/remote/browser_remote_policies_missing_live.js
Show resolved
Hide resolved
…or-remote-policies-update
…or-remote-policies-update