-
Notifications
You must be signed in to change notification settings - Fork 12
Make auction creative rewriting optional #916
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
Open
ChristianPavilonis
wants to merge
6
commits into
main
Choose a base branch
from
feature/optional-creative-rewriting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b4e82e
Make auction creative rewriting optional
ChristianPavilonis 6fcbee0
Address creative rewriting review feedback
ChristianPavilonis f341a17
Merge branch 'main' into feature/optional-creative-rewriting
aram356 9456b95
Merge branch 'main' into feature/optional-creative-rewriting
aram356 ec6fb89
Merge branch 'main' into feature/optional-creative-rewriting
aram356 51a374d
Address creative rewriting review feedback
ChristianPavilonis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| //! Regression coverage for typed app-config environment overlays. | ||
|
|
||
| use std::fs; | ||
| use std::process::{Command, Output}; | ||
|
|
||
| use tempfile::TempDir; | ||
| use toml_edit::{DocumentMut, value}; | ||
|
|
||
| const LEGACY_CONFIG: &str = include_str!( | ||
| "../../trusted-server-integration-tests/fixtures/configs/trusted-server.integration.toml" | ||
| ); | ||
| const MANIFEST: &str = r#" | ||
| [app] | ||
| name = "trusted-server" | ||
|
|
||
| [adapters.axum.adapter] | ||
| crate = "crates/trusted-server-adapter-axum" | ||
|
|
||
| [adapters.axum.commands] | ||
| build = "echo" | ||
| deploy = "echo" | ||
| serve = "echo" | ||
|
|
||
| [stores.config] | ||
| ids = ["trusted_server_config"] | ||
|
|
||
| [stores.secrets] | ||
| ids = ["trusted_server_secrets"] | ||
| "#; | ||
| const REWRITE_ENV: &str = "TRUSTED_SERVER__AUCTION__REWRITE_CREATIVES"; | ||
|
|
||
| struct MigratedProject { | ||
| directory: TempDir, | ||
| config_path: std::path::PathBuf, | ||
| manifest_path: std::path::PathBuf, | ||
| } | ||
|
|
||
| fn migrated_legacy_project() -> MigratedProject { | ||
| let directory = tempfile::tempdir().expect("should create temporary config directory"); | ||
| let config_path = directory.path().join("trusted-server.toml"); | ||
| let manifest_path = directory.path().join("edgezero.toml"); | ||
| let mut document = LEGACY_CONFIG | ||
| .parse::<DocumentMut>() | ||
| .expect("should parse legacy integration config"); | ||
| document["auction"]["rewrite_creatives"] = value(true); | ||
| fs::write(&config_path, document.to_string()).expect("should write migrated config"); | ||
| fs::write(&manifest_path, MANIFEST).expect("should write test manifest"); | ||
| MigratedProject { | ||
| directory, | ||
| config_path, | ||
| manifest_path, | ||
| } | ||
| } | ||
|
|
||
| fn validate_with_overlay(project: &MigratedProject, raw_value: &str) -> Output { | ||
| Command::new(env!("CARGO_BIN_EXE_ts")) | ||
| .args(["config", "validate", "--manifest"]) | ||
| .arg(&project.manifest_path) | ||
| .arg("--app-config") | ||
| .arg(&project.config_path) | ||
| .current_dir(project.directory.path()) | ||
| .env(REWRITE_ENV, raw_value) | ||
| .output() | ||
| .expect("should run ts config validate") | ||
| } | ||
|
|
||
| #[test] | ||
| fn migrated_legacy_config_applies_rewrite_creatives_environment_override() { | ||
| let project = migrated_legacy_project(); | ||
| let output = Command::new(env!("CARGO_BIN_EXE_ts")) | ||
| .args(["config", "push", "--adapter", "axum", "--manifest"]) | ||
| .arg(&project.manifest_path) | ||
| .arg("--app-config") | ||
| .arg(&project.config_path) | ||
| .args(["--yes", "--no-diff"]) | ||
| .current_dir(project.directory.path()) | ||
| .env(REWRITE_ENV, "false") | ||
| .output() | ||
| .expect("should run ts config push"); | ||
|
|
||
| assert!( | ||
| output.status.success(), | ||
| "valid boolean overlay should push successfully: {}", | ||
| String::from_utf8_lossy(&output.stderr) | ||
| ); | ||
|
|
||
| let local_store_path = project | ||
| .directory | ||
| .path() | ||
| .join(".edgezero/local-config-trusted_server_config.json"); | ||
| let local_store: serde_json::Value = serde_json::from_str( | ||
| &fs::read_to_string(local_store_path).expect("should read pushed local config"), | ||
| ) | ||
| .expect("should parse local config store"); | ||
| let envelope_json = local_store | ||
| .as_object() | ||
| .and_then(|entries| entries.values().next()) | ||
| .and_then(serde_json::Value::as_str) | ||
| .expect("should contain a blob envelope"); | ||
| let envelope: serde_json::Value = | ||
| serde_json::from_str(envelope_json).expect("should parse blob envelope"); | ||
|
|
||
| assert_eq!( | ||
| envelope["data"]["auction"]["rewrite_creatives"], | ||
| serde_json::Value::Bool(false), | ||
| "pushed config should contain the environment override" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn migrated_legacy_config_default_rewrite_creatives_has_no_local_diff() { | ||
| let project = migrated_legacy_project(); | ||
| let push = Command::new(env!("CARGO_BIN_EXE_ts")) | ||
| .args(["config", "push", "--adapter", "axum", "--manifest"]) | ||
| .arg(&project.manifest_path) | ||
| .arg("--app-config") | ||
| .arg(&project.config_path) | ||
| .args(["--yes", "--no-diff"]) | ||
| .current_dir(project.directory.path()) | ||
| .output() | ||
| .expect("should run ts config push"); | ||
|
|
||
| assert!( | ||
| push.status.success(), | ||
| "default rewrite setting should push successfully: {}", | ||
| String::from_utf8_lossy(&push.stderr) | ||
| ); | ||
|
|
||
| let local_store_path = project | ||
| .directory | ||
| .path() | ||
| .join(".edgezero/local-config-trusted_server_config.json"); | ||
| let local_store: serde_json::Value = serde_json::from_str( | ||
| &fs::read_to_string(local_store_path).expect("should read pushed local config"), | ||
| ) | ||
| .expect("should parse local config store"); | ||
| let envelope_json = local_store | ||
| .as_object() | ||
| .and_then(|entries| entries.values().next()) | ||
| .and_then(serde_json::Value::as_str) | ||
| .expect("should contain a blob envelope"); | ||
| let envelope: serde_json::Value = | ||
| serde_json::from_str(envelope_json).expect("should parse blob envelope"); | ||
|
|
||
| assert!( | ||
| envelope["data"]["auction"] | ||
| .get("rewrite_creatives") | ||
| .is_none(), | ||
| "should omit the default rewrite setting from the pushed blob" | ||
| ); | ||
|
|
||
| let diff = Command::new(env!("CARGO_BIN_EXE_ts")) | ||
| .args([ | ||
| "config", | ||
| "diff", | ||
| "--adapter", | ||
| "axum", | ||
| "--local", | ||
| "--manifest", | ||
| ]) | ||
| .arg(&project.manifest_path) | ||
| .arg("--app-config") | ||
| .arg(&project.config_path) | ||
| .current_dir(project.directory.path()) | ||
| .output() | ||
| .expect("should run ts config diff"); | ||
|
|
||
| assert!( | ||
| diff.status.success(), | ||
| "default rewrite setting should have no local diff: {}", | ||
| String::from_utf8_lossy(&diff.stderr) | ||
| ); | ||
| assert!( | ||
| String::from_utf8_lossy(&diff.stderr).contains("# no changes"), | ||
| "diff should report no changes: {}", | ||
| String::from_utf8_lossy(&diff.stderr) | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn migrated_legacy_config_rejects_invalid_rewrite_creatives_environment_override() { | ||
| let project = migrated_legacy_project(); | ||
| let output = validate_with_overlay(&project, "not-a-boolean"); | ||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
|
|
||
| assert!( | ||
| !output.status.success(), | ||
| "invalid boolean overlay should fail validation" | ||
| ); | ||
| assert!( | ||
| stderr.contains(REWRITE_ENV) && stderr.contains("boolean"), | ||
| "error should identify the invalid boolean overlay: {stderr}" | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.