-
Notifications
You must be signed in to change notification settings - Fork 69
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
VACMS-13852: Creates EntityEvent Subscriber. #14337
VACMS-13852: Creates EntityEvent Subscriber. #14337
Conversation
…Entity-Event-Subscriber
…Entity-Event-Subscriber
…Entity-Event-Subscriber
…Entity-Event-Subscriber
…Entity-Event-Subscriber
…Entity-Event-Subscriber
va_gov_build_trigger.entity_event_subscriber: | ||
class: Drupal\va_gov_build_trigger\EventSubscriber\EntityEventSubscriber | ||
arguments: ['@va_gov_build_trigger.build_requester', '@va_gov.build_trigger.environment_discovery'] | ||
tags: | ||
- { name: event_subscriber } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR replaces the EntityEventSubscriber residing in va_gov_build_trigger
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EntityEvent Strategy plugins encapsulate the logic for responding to entity events. This is so that we can switch out the "Tugboat" behavior for the "Prod" behavior, or insert a new behavior ("VerboseFalse") that will always refuse to trigger a content release, but will log what would have happened on prod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This entity event strategy is active locally and on Tugboat. It never releases content (consistently with our desires), but performs the same calculations and logs the results of those calculations.
The intention is to resolve #14495.
$strategy = $this->strategyPluginManager->getStrategy($strategyId); | ||
if ($strategy->shouldTriggerContentRelease($node)) { | ||
$reason = $strategy->getReasonMessage($node); | ||
$this->request->submitRequest($reason); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Request service uses the same underlying machinery as the current system. See here: https://github.com/department-of-veterans-affairs/va.gov-cms/blob/main/docroot/modules/custom/va_gov_content_release/src/Request/Request.php
So if the strategy says to release, the system should release 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all very readable and easy to follow .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of the groundwork was laid already, but the effective change in this PR is to shift the content release logic into bundle classes and out of the entity event subscriber.
The main reason I want to do that is not because the existing code is bad, but because of all of the inline checks that are needed to make the code safe. For instance if ($node->original && $node->original instanceof NodeInterface && $node->original->hasField('...')) { ... }
.
So I'm working on traits for bundle classes so that we can hopefully do all of the logic in one place, test it, and then use tested code elsewhere in the system, with the hope of lowering the "pucker factor" when we make content release-related changes.
Of course, the pucker factor for this PR is fairly high 😰
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the pucker factor is high, but I feel good that it is becoming easier to test and validate in all environs.
$environment = $settings->get('va_gov_environment')['environment']; | ||
$environment = $settings->get('va_gov_environment')['environment'] ?? '(no value provided)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The specific reason for this change is to prevent exceptions with messages like "Invalid Environment: ", which isn't immediately clear.
$this->config = ['hash_salt' => 'SCVSPZNSKKK5XCRJ1WLE']; | ||
$this->config = [ | ||
'hash_salt' => 'SCVSPZNSKKK5XCRJ1WLE', | ||
// This is temporary. See #14338. | ||
'va_gov_environment' => [ | ||
'environment' => 'staging', | ||
], | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indirectly triggers the Environment Discovery service, which needs this data to be set. If not, it'll throw an exception. #14338 involves updating this service to use the new system, which should make this test more concise, more reliable, less problematic, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an almost exact clone of the tests for the existing EntityEventSubscriber -- just modified slightly to account for the changes in API. They all pass. But that doesn't guarantee that the old tests are correct, or the new tests are sufficient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to leave a human breadcrumb that changes to one needs to be made in the other so they remain clone-ish?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hoping to get this merged before that becomes an issue 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an ugly test and probably not that valuable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is looking good/amazing. Thanks for taking this all on. A couple questions and comments.
* @return string | ||
* The reason message. | ||
*/ | ||
public function getReasonMessage(VaNodeInterface $node) : string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -39,8 +39,8 @@ public function getStrategyId() : string { | |||
$environment = $this->environmentDiscovery->getEnvironment(); | |||
return match (TRUE) { | |||
$environment->isBrd() => static::STRATEGY_ON_DEMAND, | |||
$environment->isTugboat() => static::STRATEGY_NEVER, | |||
$environment->isLocalDev() => static::STRATEGY_NEVER, | |||
$environment->isTugboat() => static::STRATEGY_VERBOSE_NEVER, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was staring at those constant names earlier trying to think of something better, heh.
$strategy = $this->strategyPluginManager->getStrategy($strategyId); | ||
if ($strategy->shouldTriggerContentRelease($node)) { | ||
$reason = $strategy->getReasonMessage($node); | ||
$this->request->submitRequest($reason); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is all very readable and easy to follow .
docroot/modules/custom/va_gov_content_release/src/Strategy/Plugin/StrategyPluginBase.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes the pucker factor is high, but I feel good that it is becoming easier to test and validate in all environs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to leave a human breadcrumb that changes to one needs to be made in the other so they remain clone-ish?
tests/phpunit/va_gov_content_types/unit/Traits/ContentReleaseTriggerTraitTest.php
Show resolved
Hide resolved
Related comment from the other issue #14495 (comment) |
…Entity-Event-Subscriber
The code looks fantastic. I added some more QA steps, but have not run through them yet, but I plan to after I get back from a dentist apt. |
@ndouglas While testing the save of a system full width banner, I notices this in the log message. Do we want these showing as exceptions. They are really just fields or properties that can not be assessed on this particular content type. |
@swirtSJW Yeah, that's intentional on my part (though debatable). I wanted to make the logic of retrieving and displaying these details as simple as possible, to avoid having the same logic (e.g. It might be better if I say "N/A" for each of those values. That's really what is implied there. |
That version seems less alarming and more informative. Or "Not available" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all tests out for me @ndouglas
Really nice work. Thank you for undertaking it.
058a9ce
into
department-of-veterans-affairs:main
…affairs#14337) * VACMS-13852: Creates EntityEvent Subscriber. * Tweaks to prevent test failures. * Yeah, no clue what I'm going to do here. * Test all event types. * Adds unit test coverage for LocalFilesystemBuildFileTest. * Test coverage. * Fix trait. * IsFacilityTraitTest. * Ignore coverage on plugin managers and plugin base classes. * Unit tests for the OnDemand entity event strategy plugin. * Make internal logic a little more consistent. * Disable current Entity Event Subscriber 👀 * Adds VerboseFalse entity event strategy plugin. * Oops, my plugins didn't have a logger 😧 * Adds mocks for OnDemand test. * Tests for VerboseFalse. * ContentReleaseTriggerTrait::hasTriggeringChanges() did the Bad Thing™ * D'oh. * Fixes test. * Fix tests. * VerboseFalse and tests. * Specify an exception occurred when getting a node detail threw. * Further tweaks. * Ugh, I'm an idiot. * Updates to VerboseFalse and VerboseFalseTest to support better debugging messages. * Removes bypass from test. * 'exception occurred' => 'Not Applicable'
Description
Closes #13852.
Closes #14495 as well.
I removed the service declaration for the current entity event subscriber to see what (if anything) breaks.
I did a direct port of Cameron's tests for the current version of EntityEventSubscriber. After some work to adjust for different types, all of them pass... which makes me deeply suspicious. I've been careful, and have even done partial copies of these tests, but that still seems really unexpectedly fortunate.
I think I'm going to add a couple more test suites to test from a few different angles to see if I can tease out any weird corner cases. I might add an extended test suite for facility/banner updates etc because I'm not sure unit tests can really account for all of the weirdness in Drupal.
QA Steps (more probably forthcoming)
Automated tests pass.
On the Tugboat Environment:
draft
. Recent log messages should indicate that it would not have triggered a content release.banner
node aspublished
. Recent log messages should indicate that it would have triggered a content release.banner
node asdraft
. Recent log messages should indicate that it would NOT have triggered a content release.banner
node aspublished
. Recent log messages should indicate that it would have triggered a content release.Followup Items