Skip to content

Commit 4a316ee

Browse files
fix(shared): an empty leftover list subkey does not conflict with a Policy value
Not Configured clears a list policy's values but can leave its Clients or AllowedDrivers subkey behind, which refused a Policy JSON value deployed later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6ddd40a commit 4a316ee

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎packages/shared/src/managedPolicyFile.test.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,16 @@ describe("readManagedPolicy", () => {
197197
yield* win32({}, policyKey([text("Policy", "{ not json")])),
198198
"does not match the policy schema",
199199
);
200-
assert.include(
201-
yield* win32({}, policyKey([text("Policy", policy), text("Organization", "Example")])),
202-
"both a Policy value and Group Policy settings",
200+
for (const both of [
201+
policyKey([text("Policy", policy), text("Organization", "Example")]),
202+
policyKey([text("Policy", policy)], { Clients: { desktop: 1 } }),
203+
]) {
204+
assert.include(yield* win32({}, both), "both a Policy value and Group Policy settings");
205+
}
206+
// Not Configured clears a list policy's values but can leave its empty subkey behind.
207+
assert.equal(
208+
yield* win32({}, policyKey([text("Policy", policy)], { Clients: {} })),
209+
WINDOWS_POLICY_KEY,
203210
);
204211
}),
205212
);

‎packages/shared/src/managedPolicyFile.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,15 @@ const readPlatformPolicy = Effect.fnUntraced(function* (
537537
if (root === undefined) return undefined;
538538
const json = root.values.find((value) => value.name.toLowerCase() === "policy");
539539
if (json !== undefined) {
540-
if (root.values.length > 1 || root.subkeys.length > 0) {
540+
// Not Configured clears a list policy's values but can leave its empty subkey behind.
541+
let templateSettings = root.values.length > 1;
542+
for (const subkey of root.subkeys) {
543+
if (templateSettings) break;
544+
const child = yield* readKey(`${WINDOWS_POLICY_SUBKEY}\\${subkey}`);
545+
templateSettings =
546+
child !== undefined && (child.values.length > 0 || child.subkeys.length > 0);
547+
}
548+
if (templateSettings) {
541549
return yield* refuse(
542550
"it holds both a Policy value and Group Policy settings; deploy the policy one way",
543551
);

0 commit comments

Comments
 (0)