Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
"description": {
"type": "string",
"description": "Explain how this value is being used"
},
"setPref": {
"type": "object",
"properties": {
"branch": {
"type": "string",
"enum": ["user", "default"],
},
"pref": {
"type": "string"
}
}
}
},
"required": ["type", "description"],
Expand Down
50 changes: 29 additions & 21 deletions components/support/nimbus-fml/src/backends/experimenter_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ use serde::{Deserialize, Serialize};
use crate::{
command_line::commands::GenerateExperimenterManifestCmd,
error::{FMLError, Result},
intermediate_representation::{FeatureDef, FeatureManifest, PropDef, TargetLanguage, TypeRef},
intermediate_representation::{
FeatureDef, FeatureManifest, GeckoPrefDef, PropDef, TargetLanguage, TypeRef,
},
};

pub(crate) type ExperimenterManifest = BTreeMap<String, ExperimenterFeature>;
Expand All @@ -36,6 +38,10 @@ pub(crate) struct ExperimenterFeatureProperty {
#[serde(rename = "enum")]
#[serde(skip_serializing_if = "Option::is_none")]
variants: Option<BTreeSet<String>>,

#[serde(rename = "setPref")]
#[serde(skip_serializing_if = "Option::is_none")]
set_pref: Option<GeckoPrefDef>,
}

impl TryFrom<FeatureManifest> for ExperimenterManifest {
Expand Down Expand Up @@ -71,30 +77,32 @@ impl FeatureManifest {
props.iter().try_for_each(|prop| -> Result<()> {
let typ = ExperimentManifestPropType::from(prop.typ()).to_string();

let yaml_prop = if let TypeRef::Enum(e) = prop.typ() {
let enum_def = self
.find_enum(&e)
.ok_or(FMLError::InternalError("Found enum with no definition"))?;

let variants = enum_def
.variants
.iter()
.map(|variant| variant.name())
.collect::<BTreeSet<String>>();

ExperimenterFeatureProperty {
variants: Some(variants),
description: prop.doc(),
property_type: typ,
let variants = match prop.typ() {
TypeRef::Enum(e) => {
let enum_def = self
.find_enum(&e)
.ok_or(FMLError::InternalError("Found enum with no definition"))?;

Some(
enum_def
.variants
.iter()
.map(|variant| variant.name())
.collect::<BTreeSet<String>>(),
)
}
} else {
_ => None,
};

map.insert(
prop.name(),
ExperimenterFeatureProperty {
variants: None,
variants,
description: prop.doc(),
property_type: typ,
}
};
map.insert(prop.name(), yaml_prop);
set_pref: prop.gecko_pref.clone(),
},
);
Ok(())
})?;
Ok(map)
Expand Down
48 changes: 48 additions & 0 deletions components/support/nimbus-fml/src/command_line/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,54 @@ mod test {
Ok(())
}

#[test]
fn test_generate_experimenter_gecko_prefs() -> Result<()> {
let tmpfile = NamedTempFile::new()?;
let cmd = create_experimenter_manifest_cmd("fixtures/fe/gecko-pref.yaml", tmpfile.path())?;
generate_experimenter_manifest(&cmd)?;

let manifest: serde_yaml::Value = serde_yaml::from_reader(&tmpfile)?;
println!("{:?}", manifest);

let variables = manifest
.get("gecko-nimbus-validation")
.unwrap()
.get("variables")
.unwrap();

fn assert_pref_var(
variable: &serde_yaml::Value,
expected_pref: &str,
expected_branch: &str,
) {
let pref_annotation = variable.get("setPref").unwrap();
let pref = pref_annotation.get("pref").unwrap().as_str().unwrap();
assert_eq!(pref, expected_pref);
let branch = pref_annotation.get("branch").unwrap().as_str().unwrap();
assert_eq!(branch, expected_branch);
}

assert_pref_var(
variables.get("test-preference-bool").unwrap(),
"gecko.nimbus.test.bool",
"default",
);

assert_pref_var(
variables.get("test-preference-int").unwrap(),
"gecko.nimbus.test.int",
"default",
);

assert_pref_var(
variables.get("test-preference-string").unwrap(),
"gecko.nimbus.test.string",
"default",
);

Ok(())
}

#[test]
fn test_validate_command() -> Result<()> {
let paths = MANIFEST_PATHS
Expand Down