assertPolicy = allegedPolicy => {
  if (allegedPolicy === undefined) {
    return;
  }
  const policy = Object(allegedPolicy);
  assert(
    allegedPolicy === policy && !Array.isArray(policy),
    `policy must be an object, got ${allegedPolicy}`,
  );

  const { resources, entry, defaultAttenuator, ...extra } = policy;
  assert(
    keys(extra).length === 0,
    `policy must not have extra properties, got ${q(keys(extra))}`,
  );

  assert(
    typeof resources === 'object' && resources !== null && !isArray(resources),
    `policy.resources must be an object, got ${q(resources)}`,
  );
  assert(
    !defaultAttenuator || typeof defaultAttenuator === 'string',
    `policy.defaultAttenuator must be a string, got ${q(defaultAttenuator)}`,
  );

  assertPackagePolicy(entry, `policy.entry`);

  for (const [key, value] of entries(resources)) {
    assertPackagePolicy(value, `policy.resources["${key}"]`);
  }
}
This asserts (i.e., throws) that `allegedPolicy` is a valid `Policy`

It also moonlights as a type guard.

@param {unknown} allegedPolicy - Alleged `Policy` to test
@returns {asserts allegedPolicy is (SomePolicy | undefined)}