diff --git a/Cargo.toml b/Cargo.toml index 23c5a16..ead00bc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "pks" -version = "0.2.16" +version = "0.2.17" edition = "2021" description = "Welcome! Please see https://github.com/rubyatscale/pks for more information!" license = "MIT" diff --git a/README.md b/README.md index 56cf2a4..58b90dd 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Instructions: - Confirm the output of `git diff` is empty - Please file an issue if it's not! + # New to Rust? Me too! This is my first Rust project, so I'd love to have feedback, advice, and contributions! @@ -155,6 +156,32 @@ enforcement_globs_ignore: reason: "The other dependency violations are fine as those packs will be absorbed into this one." ``` +## "check" error messages +The error messages resulting from running `pks check` can be customized with mustache-style interpolation. The available +variables are: +- violation_name +- referencing_pack_name +- defining_pack_name +- constant_name +- reference_location +- referencing_pack_relative_yml + +Layer violations also have +- defining_layer +- referencing_layer + +Example: +packwerk.yml +```yml +checker_overrides: + folder_privacy_error_template: "{{reference_location}} {{violation_name}} / Product Service Privacy Violation: `{{constant_name}}` belongs to the `{{defining_pack_name}}` product service, which is not visible to `{{referencing_pack_name}}` as it is a different product service. See https://go/pks-folder-privacy" + layer_error_template: "{{reference_location}}Layer violation: `{{constant_name}}` belongs to `{{defining_pack_name}}` (whose layer is `{{defining_layer}}`) cannot be accessed from `{{referencing_pack_name}}` (whose layer is `{{referencing_layer}}`). See https://go/pks-layer" + visibility_error_template: "{{reference_location}}Visibility violation: `{{constant_name}}` belongs to `{{defining_pack_name}}`, which is not visible to `{{referencing_pack_name}}`. See https://go/pks-visibility" + privacy_error_template: "{{reference_location}}Privacy violation: `{{constant_name}}` is private to `{{defining_pack_name}}`, but referenced from `{{referencing_pack_name}}`. See https://go/pks-privacy" + dependency_error_template: "{{reference_location}}Dependency violation: `{{constant_name}}` belongs to `{{defining_pack_name}}`, but `{{referencing_pack_relative_yml}}` does not specify a dependency on `{{defining_pack_name}}`. See https://go/pks-dependency" +``` + + # Benchmarks See [BENCHMARKS.md](https://github.com/rubyatscale/pks/blob/main/BENCHMARKS.md) diff --git a/src/packs/configuration.rs b/src/packs/configuration.rs index f269dee..c1f11ad 100644 --- a/src/packs/configuration.rs +++ b/src/packs/configuration.rs @@ -180,35 +180,64 @@ fn build_violation_checker_configuration( violation_checker_overrides: Option<&CheckerOverrides>, ) -> HashMap { let mut checker_configurations = HashMap::new(); - checker_configurations.insert( - CheckerType::Dependency, - CheckerConfiguration::new(CheckerType::Dependency), - ); - checker_configurations.insert( - CheckerType::Privacy, - CheckerConfiguration::new(CheckerType::Privacy), - ); - checker_configurations.insert( - CheckerType::Layer, - CheckerConfiguration::new(CheckerType::Layer), - ); - checker_configurations.insert( - CheckerType::Visibility, - CheckerConfiguration::new(CheckerType::Visibility), - ); - let mut checker_configuration = + let mut folder_privacy_checker_configuration = CheckerConfiguration::new(CheckerType::FolderPrivacy); + let mut privacy_checker_configuration = + CheckerConfiguration::new(CheckerType::Privacy); + let mut dependency_checker_configuration = + CheckerConfiguration::new(CheckerType::Dependency); + let mut layer_checker_configuration = + CheckerConfiguration::new(CheckerType::Layer); + let mut visibility_checker_configuration = + CheckerConfiguration::new(CheckerType::Visibility); + if let Some(violation_checker_overrides) = violation_checker_overrides { if let Some(error_template) = violation_checker_overrides .folder_privacy_error_template .clone() { - checker_configuration.override_error_template = + folder_privacy_checker_configuration.override_error_template = + Some(error_template); + } + if let Some(error_template) = + violation_checker_overrides.privacy_error_template.clone() + { + privacy_checker_configuration.override_error_template = + Some(error_template); + } + if let Some(error_template) = + violation_checker_overrides.layer_error_template.clone() + { + layer_checker_configuration.override_error_template = + Some(error_template); + } + if let Some(error_template) = violation_checker_overrides + .visibility_error_template + .clone() + { + visibility_checker_configuration.override_error_template = + Some(error_template); + } + if let Some(error_template) = violation_checker_overrides + .dependency_error_template + .clone() + { + dependency_checker_configuration.override_error_template = Some(error_template); } } + checker_configurations.insert( + CheckerType::FolderPrivacy, + folder_privacy_checker_configuration, + ); + checker_configurations + .insert(CheckerType::Dependency, dependency_checker_configuration); + checker_configurations + .insert(CheckerType::Privacy, privacy_checker_configuration); + checker_configurations + .insert(CheckerType::Layer, layer_checker_configuration); checker_configurations - .insert(CheckerType::FolderPrivacy, checker_configuration); + .insert(CheckerType::Visibility, visibility_checker_configuration); checker_configurations } diff --git a/src/packs/raw_configuration.rs b/src/packs/raw_configuration.rs index a4ba40c..5f1b3f2 100644 --- a/src/packs/raw_configuration.rs +++ b/src/packs/raw_configuration.rs @@ -80,6 +80,10 @@ pub(crate) struct RawConfiguration { pub struct CheckerOverrides { /// Mustache style error message template pub folder_privacy_error_template: Option, + pub privacy_error_template: Option, + pub layer_error_template: Option, + pub visibility_error_template: Option, + pub dependency_error_template: Option, } pub(crate) fn get(absolute_root: &Path) -> anyhow::Result { diff --git a/tests/check_test.rs b/tests/check_test.rs index acc582a..4d30714 100644 --- a/tests/check_test.rs +++ b/tests/check_test.rs @@ -8,6 +8,29 @@ pub fn stripped_output(output: Vec) -> String { String::from_utf8_lossy(&strip_ansi_escapes::strip(output)).to_string() } +#[test] +fn test_check_with_privacy_dependency_error_template_overrides( +) -> Result<(), Box> { + let output = Command::cargo_bin("pks")? + .arg("--project-root") + .arg("tests/fixtures/privacy_violation_overrides") + .arg("--debug") + .arg("check") + .assert() + .failure() + .get_output() + .stdout + .clone(); + + let stripped_output = stripped_output(output); + + assert!(stripped_output.contains("2 violation(s) detected:")); + assert!(stripped_output.contains("packs/foo/app/services/foo.rb:3:4\nDependency violation: `::Bar` belongs to `packs/bar`, but `packs/foo/package.yml` does not specify a dependency on `packs/bar`. See https://go/pks-dependency")); + assert!(stripped_output.contains("packs/foo/app/services/foo.rb:3:4\nPrivacy violation: `::Bar` is private to `packs/bar`, but referenced from `packs/foo`. See https://go/pks-privacy")); + + common::teardown(); + Ok(()) +} #[test] fn test_check() -> Result<(), Box> { let output = Command::cargo_bin("pks")? diff --git a/tests/fixtures/layer_violations_with_overrides/config/initializers/inflections.rb b/tests/fixtures/layer_violations_with_overrides/config/initializers/inflections.rb new file mode 100644 index 0000000..298d891 --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/config/initializers/inflections.rb @@ -0,0 +1,6 @@ +ActiveSupport::Inflector.inflections do |do_not_couple_implementation_to_this_string| + do_not_couple_implementation_to_this_string.acronym 'API' + + # Using single vs double quotes inconsistently + do_not_couple_implementation_to_this_string.acronym "CSV" +end diff --git a/tests/fixtures/layer_violations_with_overrides/package.yml b/tests/fixtures/layer_violations_with_overrides/package.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/app/services/feature_flags.rb b/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/app/services/feature_flags.rb new file mode 100644 index 0000000..a188413 --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/app/services/feature_flags.rb @@ -0,0 +1,2 @@ +# feature_flags, a utility pack, should not rely on Payments, a product pack +Payments diff --git a/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/package.yml b/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/package.yml new file mode 100644 index 0000000..4eb30be --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/packs/feature_flags/package.yml @@ -0,0 +1,2 @@ +enforce_layers: true +layer: utilities diff --git a/tests/fixtures/layer_violations_with_overrides/packs/payments/app/services/payments.rb b/tests/fixtures/layer_violations_with_overrides/packs/payments/app/services/payments.rb new file mode 100644 index 0000000..21b7f1d --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/packs/payments/app/services/payments.rb @@ -0,0 +1,2 @@ +module Payments +end diff --git a/tests/fixtures/layer_violations_with_overrides/packs/payments/package.yml b/tests/fixtures/layer_violations_with_overrides/packs/payments/package.yml new file mode 100644 index 0000000..1bc210b --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/packs/payments/package.yml @@ -0,0 +1,2 @@ +enforce_layers: true +layer: product diff --git a/tests/fixtures/layer_violations_with_overrides/packwerk.yml b/tests/fixtures/layer_violations_with_overrides/packwerk.yml new file mode 100644 index 0000000..66f3408 --- /dev/null +++ b/tests/fixtures/layer_violations_with_overrides/packwerk.yml @@ -0,0 +1,32 @@ +# See: Setting up the configuration file +# https://github.com/Shopify/packwerk/blob/main/USAGE.md#setting-up-the-configuration-file + +# List of patterns for folder paths to include +# include: +# - "**/*.{rb,rake,erb}" + +# List of patterns for folder paths to exclude +# exclude: +# - "{bin,node_modules,script,tmp,vendor}/**/*" + +# Patterns to find package configuration files +# package_paths: "**/" + +# List of custom associations, if any +# custom_associations: +# - "cache_belongs_to" + +# Whether or not you want the cache enabled (disabled by default) +cache: false + +# Where you want the cache to be stored (default below) +# cache_directory: 'tmp/cache/packwerk' + +layers: + - tooling + - deprecated + - product + - utilities + +checker_overrides: + layer_error_template: "{{reference_location}}Layer violation: `{{constant_name}}` belongs to `{{defining_pack_name}}` (whose layer is `{{defining_layer}}`) cannot be accessed from `{{referencing_pack_name}}` (whose layer is `{{referencing_layer}}`). See https://go/pks-layer" diff --git a/tests/fixtures/privacy_violation_overrides/app/company_data/widget.rb b/tests/fixtures/privacy_violation_overrides/app/company_data/widget.rb new file mode 100644 index 0000000..d37a8b7 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/app/company_data/widget.rb @@ -0,0 +1,3 @@ +module Company + class Widget end +end diff --git a/tests/fixtures/privacy_violation_overrides/app/services/some_root_class.rb b/tests/fixtures/privacy_violation_overrides/app/services/some_root_class.rb new file mode 100644 index 0000000..5bce9a9 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/app/services/some_root_class.rb @@ -0,0 +1 @@ +class SomeRootClass; end diff --git a/tests/fixtures/privacy_violation_overrides/frontend/ui_helper.rb b/tests/fixtures/privacy_violation_overrides/frontend/ui_helper.rb new file mode 100644 index 0000000..ea2e91c --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/frontend/ui_helper.rb @@ -0,0 +1,5 @@ +module UiHelper + def self.help + "I'm a helper" + end +end \ No newline at end of file diff --git a/tests/fixtures/privacy_violation_overrides/node_modules/file.rb b/tests/fixtures/privacy_violation_overrides/node_modules/file.rb new file mode 100644 index 0000000..bc56c4d --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/node_modules/file.rb @@ -0,0 +1 @@ +Foo diff --git a/tests/fixtures/privacy_violation_overrides/node_modules/subfolder/file.rb b/tests/fixtures/privacy_violation_overrides/node_modules/subfolder/file.rb new file mode 100644 index 0000000..f5a029b --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/node_modules/subfolder/file.rb @@ -0,0 +1 @@ +# some ignored file diff --git a/tests/fixtures/privacy_violation_overrides/package.yml b/tests/fixtures/privacy_violation_overrides/package.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/privacy_violation_overrides/packs/bar/app/models/concerns/some_concern.rb b/tests/fixtures/privacy_violation_overrides/packs/bar/app/models/concerns/some_concern.rb new file mode 100644 index 0000000..f2e00d0 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/bar/app/models/concerns/some_concern.rb @@ -0,0 +1 @@ +module SomeConcern; end diff --git a/tests/fixtures/privacy_violation_overrides/packs/bar/app/services/bar.rb b/tests/fixtures/privacy_violation_overrides/packs/bar/app/services/bar.rb new file mode 100644 index 0000000..227e5ab --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/bar/app/services/bar.rb @@ -0,0 +1,3 @@ +module Bar + def bar; end +end diff --git a/tests/fixtures/privacy_violation_overrides/packs/bar/package.yml b/tests/fixtures/privacy_violation_overrides/packs/bar/package.yml new file mode 100644 index 0000000..a473d63 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/bar/package.yml @@ -0,0 +1 @@ +enforce_privacy: true diff --git a/tests/fixtures/privacy_violation_overrides/packs/baz/app/services/baz.rb b/tests/fixtures/privacy_violation_overrides/packs/baz/app/services/baz.rb new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/privacy_violation_overrides/packs/baz/package.yml b/tests/fixtures/privacy_violation_overrides/packs/baz/package.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo.rb b/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo.rb new file mode 100644 index 0000000..c815fb9 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo.rb @@ -0,0 +1,9 @@ +module Foo + def calls_bar_without_a_stated_dependency + ::Bar + end + + def calls_baz_with_a_stated_dependency + Baz + end +end diff --git a/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo/bar.rb b/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo/bar.rb new file mode 100644 index 0000000..2c7d20a --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/foo/app/services/foo/bar.rb @@ -0,0 +1,5 @@ +# This defines ::Foo::Bar, which is different than ::Bar +module Foo + module Bar + end +end diff --git a/tests/fixtures/privacy_violation_overrides/packs/foo/app/views/foo.erb b/tests/fixtures/privacy_violation_overrides/packs/foo/app/views/foo.erb new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/foo/app/views/foo.erb @@ -0,0 +1 @@ + diff --git a/tests/fixtures/privacy_violation_overrides/packs/foo/package.yml b/tests/fixtures/privacy_violation_overrides/packs/foo/package.yml new file mode 100644 index 0000000..1922c4d --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packs/foo/package.yml @@ -0,0 +1,4 @@ +enforce_dependencies: true +enforce_privacy: true +dependencies: +- packs/baz diff --git a/tests/fixtures/privacy_violation_overrides/packwerk.yml b/tests/fixtures/privacy_violation_overrides/packwerk.yml new file mode 100644 index 0000000..cfa6d36 --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/packwerk.yml @@ -0,0 +1,30 @@ +# See: Setting up the configuration file +# https://github.com/Shopify/packwerk/blob/main/USAGE.md#setting-up-the-configuration-file + +# List of patterns for folder paths to include +# include: +# - "**/*.{rb,rake,erb}" + +# List of patterns for folder paths to exclude +# exclude: +# - "{bin,node_modules,script,tmp,vendor}/**/*" + +# Patterns to find package configuration files +# package_paths: "**/" + +# List of custom associations, if any +# custom_associations: +# - "cache_belongs_to" + +# Whether or not you want the cache enabled (disabled by default) +cache: false + +autoload_roots: + app/company_data: "::Company" + +# Where you want the cache to be stored (default below) +# cache_directory: 'tmp/cache/packwerk' + +checker_overrides: + privacy_error_template: "{{reference_location}}Privacy violation: `{{constant_name}}` is private to `{{defining_pack_name}}`, but referenced from `{{referencing_pack_name}}`. See https://go/pks-privacy" + dependency_error_template: "{{reference_location}}Dependency violation: `{{constant_name}}` belongs to `{{defining_pack_name}}`, but `{{referencing_pack_relative_yml}}` does not specify a dependency on `{{defining_pack_name}}`. See https://go/pks-dependency" \ No newline at end of file diff --git a/tests/fixtures/privacy_violation_overrides/script/my_script.rb b/tests/fixtures/privacy_violation_overrides/script/my_script.rb new file mode 100644 index 0000000..8188d5f --- /dev/null +++ b/tests/fixtures/privacy_violation_overrides/script/my_script.rb @@ -0,0 +1 @@ +# some ruby script diff --git a/tests/fixtures/visibility_violations_with_overrides/package.yml b/tests/fixtures/visibility_violations_with_overrides/package.yml new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/baz/app/services/baz.rb b/tests/fixtures/visibility_violations_with_overrides/packs/baz/app/services/baz.rb new file mode 100644 index 0000000..7d7e3a3 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/baz/app/services/baz.rb @@ -0,0 +1,5 @@ +module Baz + def sumpn + Foo.nothing + end +end \ No newline at end of file diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/baz/package.yml b/tests/fixtures/visibility_violations_with_overrides/packs/baz/package.yml new file mode 100644 index 0000000..703bc55 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/baz/package.yml @@ -0,0 +1,2 @@ +dependencies: + - packs/foos/foo diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/foo.rb b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/foo.rb new file mode 100644 index 0000000..6a9a1ec --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/foo.rb @@ -0,0 +1,4 @@ +module Foo + def self.nothing + end +end diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/other_foo.rb b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/other_foo.rb new file mode 100644 index 0000000..7c89b49 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/app/services/other_foo.rb @@ -0,0 +1,5 @@ +module OtherFoo + def calls_bar_without_a_stated_dependency + ::Bar + end +end diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/package.yml b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/package.yml new file mode 100644 index 0000000..f37bf9c --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/foo/package.yml @@ -0,0 +1,4 @@ +enforce_visibility: true +visible_to: + - packs/foos/too + diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/app/services/ref_foo.rb b/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/app/services/ref_foo.rb new file mode 100644 index 0000000..f1f9848 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/app/services/ref_foo.rb @@ -0,0 +1,5 @@ +module Too + def sumpn + Foo.nothing + end +end \ No newline at end of file diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/package.yml b/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/package.yml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/too/package.yml @@ -0,0 +1 @@ + diff --git a/tests/fixtures/visibility_violations_with_overrides/packs/foos/zoo/package.yml b/tests/fixtures/visibility_violations_with_overrides/packs/foos/zoo/package.yml new file mode 100644 index 0000000..703bc55 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packs/foos/zoo/package.yml @@ -0,0 +1,2 @@ +dependencies: + - packs/foos/foo diff --git a/tests/fixtures/visibility_violations_with_overrides/packwerk.yml b/tests/fixtures/visibility_violations_with_overrides/packwerk.yml new file mode 100644 index 0000000..2b50e10 --- /dev/null +++ b/tests/fixtures/visibility_violations_with_overrides/packwerk.yml @@ -0,0 +1,25 @@ +# See: Setting up the configuration file +# https://github.com/Shopify/packwerk/blob/main/USAGE.md#setting-up-the-configuration-file + +# List of patterns for folder paths to include +# include: +# - "**/*.{rb,rake,erb}" + +# List of patterns for folder paths to exclude +# exclude: +# - "{bin,node_modules,script,tmp,vendor}/**/*" + +# Patterns to find package configuration files +# package_paths: "**/" + +# List of custom associations, if any +# custom_associations: +# - "cache_belongs_to" + +# Whether or not you want the cache enabled (disabled by default) +cache: false + +# Where you want the cache to be stored (default below) +# cache_directory: 'tmp/cache/packwerk' +checker_overrides: + visibility_error_template: "{{reference_location}}Visibility violation: `{{constant_name}}` belongs to `{{defining_pack_name}}`, which is not visible to `{{referencing_pack_name}}`. See https://go/pks-visibility" diff --git a/tests/folder_privacy_test.rs b/tests/folder_privacy_test.rs index 355235f..3f72f32 100644 --- a/tests/folder_privacy_test.rs +++ b/tests/folder_privacy_test.rs @@ -19,7 +19,7 @@ fn test_check() -> Result<(), Box> { } #[test] -fn test_check_with_overrides() -> Result<(), Box> { +fn test_check_with_error_template_overrides() -> Result<(), Box> { Command::cargo_bin("pks")? .arg("--project-root") .arg("tests/fixtures/folder_privacy_violations_with_overrides") diff --git a/tests/layer_violations_test.rs b/tests/layer_violations_test.rs index 16c431d..8795dec 100644 --- a/tests/layer_violations_test.rs +++ b/tests/layer_violations_test.rs @@ -2,6 +2,29 @@ use assert_cmd::prelude::*; use std::{error::Error, process::Command}; mod common; + +#[test] +fn test_check_with_error_template_overrides() -> Result<(), Box> { + let output = Command::cargo_bin("pks")? + .arg("--project-root") + .arg("tests/fixtures/layer_violations_with_overrides") + .arg("--debug") + .arg("check") + .assert() + .failure() + .get_output() + .stdout + .clone(); + + let stripped_output = + String::from_utf8_lossy(&strip_ansi_escapes::strip(output)).to_string(); + + assert!(stripped_output.contains("1 violation(s) detected:")); + assert!(stripped_output.contains("packs/feature_flags/app/services/feature_flags.rb:2:0\nLayer violation: `::Payments` belongs to `packs/payments` (whose layer is `product`) cannot be accessed from `packs/feature_flags` (whose layer is `utilities`). See https://go/pks-layer")); + + common::teardown(); + Ok(()) +} #[test] fn test_check() -> Result<(), Box> { let output = Command::cargo_bin("pks")? diff --git a/tests/visibility_test.rs b/tests/visibility_test.rs index 03e7d84..df43e8a 100644 --- a/tests/visibility_test.rs +++ b/tests/visibility_test.rs @@ -2,6 +2,32 @@ use assert_cmd::prelude::*; use std::{error::Error, process::Command}; mod common; + +#[test] +fn test_check_with_visibility_violation_template_overrides( +) -> Result<(), Box> { + let output = Command::cargo_bin("pks")? + .arg("--project-root") + .arg("tests/fixtures/visibility_violations_with_overrides") + .arg("--debug") + .arg("check") + .assert() + .failure() + .get_output() + .stdout + .clone(); + + let stripped_output = + String::from_utf8_lossy(&strip_ansi_escapes::strip(output)).to_string(); + + assert!(stripped_output.contains("1 violation(s) detected:")); + dbg!(&stripped_output); + assert!(stripped_output.contains("detected:\npacks/baz/app/services/baz.rb:3:4\nVisibility violation: `::Foo` belongs to `packs/foos/foo`, which is not visible to `packs/baz`. See https://go/pks-visibility")); + + common::teardown(); + Ok(()) +} + #[test] fn test_check() -> Result<(), Box> { let output = Command::cargo_bin("pks")?