Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a structure hash to FeatureInspector #5949

Merged
merged 4 commits into from
Nov 29, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 19 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DEPENDENCIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ The following text applies to code linked from these dependencies:
[core-foundation-sys](https://github.com/servo/core-foundation-rs),
[core-foundation](https://github.com/servo/core-foundation-rs),
[cpufeatures](https://github.com/RustCrypto/utils),
[crypto-common](https://github.com/RustCrypto/traits),
[digest](https://github.com/RustCrypto/traits),
[dogear](https://github.com/mozilla/dogear),
[either](https://github.com/bluss/either),
Expand Down Expand Up @@ -522,7 +523,6 @@ The following text applies to code linked from these dependencies:
[num_cpus](https://github.com/seanmonstar/num_cpus),
[ohttp](https://github.com/martinthomson/ohttp),
[once_cell](https://github.com/matklad/once_cell),
[opaque-debug](https://github.com/RustCrypto/utils),
[openssl-macros](https://github.com/sfackler/rust-openssl),
[openssl-probe](https://github.com/alexcrichton/openssl-probe),
[openssl-src](https://github.com/alexcrichton/openssl-src-rs),
Expand Down
2 changes: 1 addition & 1 deletion components/nimbus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ url = "2.2"
rkv = { version = "0.17", optional = true }
jexl-eval = "0.2.2"
uuid = { version = "0.8", features = ["serde", "v4"]}
sha2 = "0.9"
sha2 = "^0.10"
hex = "0.4"
once_cell = "1"
uniffi = "0.24.1"
Expand Down
1 change: 1 addition & 0 deletions components/support/nimbus-fml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ cfg-if = "1.0.0"
console = "0.15.5"
lazy_static = "1.4"
email_address = { version = "0.2.4", features = ["serde"] }
sha2 = "^0.10"

[build-dependencies]
uniffi = { version = "0.24.1", features = ["build"], optional = true }
Expand Down
6 changes: 6 additions & 0 deletions components/support/nimbus-fml/src/client/inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl FmlFeatureInspector {
pub fn get_errors(&self, string: String) -> Option<Vec<FmlEditorError>> {
self.get_first_error(string).map(|e| vec![e])
}

pub fn get_structure_hash(&self) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely agree that "structure" isn't as clear as I'd like it to be

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Schema" does seem like a good alternative, since we use "definition" in other places

self.manifest
.get_structure_hash(&self.feature_id)
.unwrap_or_default()
}
}

impl FmlFeatureInspector {
Expand Down
18 changes: 18 additions & 0 deletions components/support/nimbus-fml/src/fml.udl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ interface FmlFeatureInspector {
// Returns the default JSON for the feature for this channel.
[Throws=FMLError]
JsonObject get_default_json();

// Returns a 8 digit hex hash of the structure of the feature.
//
// This is suitable for tracking over time.
//
// This is a truncated SHA256 hash which takes in to consideration
// the name and types of all the variables in this feature, and nested
// objects, as well as the variants of enums.
//
// It does not take into consideration the default values for this
// feature, ordering of fields or variables or enum variants, or
// documentation, so as to remain stable despite superficial changes
// to the feature's configuration.
//
// If this hash changes for a given feature then it is almost
// certain that the code which uses this configuration will also have
// changed.
string get_structure_hash();
};

dictionary FmlEditorError {
Expand Down
18 changes: 17 additions & 1 deletion components/support/nimbus-fml/src/intermediate_representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::defaults::{DefaultsMerger, DefaultsValidator};
use crate::error::FMLError::InvalidFeatureError;
use crate::error::{FMLError, Result};
use crate::frontend::{AboutBlock, FeatureMetadata};
use crate::structure::StructureValidator;
use crate::structure::{StructureHasher, StructureValidator};
use crate::util::loaders::FilePath;
use anyhow::{bail, Error, Result as AnyhowResult};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -456,6 +456,22 @@ impl FeatureManifest {

Ok(feature_def)
}

pub fn get_structure_hash(&self, feature_name: &str) -> Result<String> {
let (manifest, feature_def) = self
.find_feature(feature_name)
.ok_or_else(|| InvalidFeatureError(feature_name.to_string()))?;

Ok(manifest.feature_structure_hash(feature_def))
}
}

impl FeatureManifest {
pub(crate) fn feature_structure_hash(&self, feature_def: &FeatureDef) -> String {
let hasher = StructureHasher::new(&self.enum_defs, &self.obj_defs);
let hash = hasher.hash(feature_def) & 0xffffffff;
format!("{hash:x}")
}
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Default)]
Expand Down