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

VACMS-13852: Creates EntityEvent Subscriber. #14337

Conversation

ndouglas
Copy link
Contributor

@ndouglas ndouglas commented Jul 12, 2023

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.
    image

  • On the Tugboat Environment:

    • Banners
      • create and save a banner node as draft. Recent log messages should indicate that it would not have triggered a content release.
      • Open and save a banner node as published. Recent log messages should indicate that it would have triggered a content release.
      • Edit a published banner banner node as draft. Recent log messages should indicate that it would NOT have triggered a content release.
      • Edit a published banner banner node as published. Recent log messages should indicate that it would have triggered a content release.
    • VAMC System Alert
      • create a VAMC system alert and don't publish it. Recent log messages should indicate that it would NOT have triggered a content release.
      • Edit a VAMC system alert to change its description and PUBLISH it. Recent log messages should indicate that it would have triggered a content release.
      • Edit a VAMC system alert to change its description and leave it published. Recent log messages should indicate that it would have triggered a content release.
      • Edit a VAMC system alert to change its description and UNPUBLISH it. Recent log messages should indicate that it would have triggered a content release.
      • Edit a VAMC system alert to change its description and leave it unpublished. Recent log messages should indicate that it would NOT have triggered a content release.
    • Facility Status
      • Edit a VAMC facility and change its status and publish. Recent log messages should indicate that it would have triggered a content release.
      • Edit a VAMC facility and change its status description and publish. Recent log messages should indicate that it would have triggered a content release.
      • Edit a VAMC facility and change nothing and publish. Recent log messages should indicate no content release.

Followup Items

  • replace "exception occurred" with "N/A" in the log messages.

@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 12, 2023 22:14 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 13:43 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 14:24 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 17:37 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 17:59 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 19:21 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 13, 2023 20:37 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 14, 2023 18:14 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 14, 2023 18:20 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 14, 2023 18:52 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 14, 2023 20:07 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 17, 2023 13:17 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 17, 2023 13:32 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 17, 2023 16:31 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 25, 2023 15:03 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 25, 2023 15:38 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 25, 2023 18:33 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 25, 2023 19:59 Destroyed
@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 26, 2023 14:40 Destroyed
Comment on lines -5 to -9
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 }
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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);
Copy link
Contributor Author

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 🙂

Copy link
Contributor

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 .

Copy link
Contributor Author

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 😰

Copy link
Contributor

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)';
Copy link
Contributor Author

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.

Comment on lines -65 to +71
$this->config = ['hash_salt' => 'SCVSPZNSKKK5XCRJ1WLE'];
$this->config = [
'hash_salt' => 'SCVSPZNSKKK5XCRJ1WLE',
// This is temporary. See #14338.
'va_gov_environment' => [
'environment' => 'staging',
],
];
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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 😁

Copy link
Contributor Author

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.

Copy link
Contributor

@swirtSJW swirtSJW left a 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;
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooh this is a hard one. It is like one of those photos that you can see two ways
image

I read it one time as Strategy Verbose, Never
then read it again as Strategy, Verbose Never

unfortunately 'STRATEGY_NEVER_VERBOSE' suffers from the same problem and is no better. So I will have to get over it ;)

Copy link
Contributor Author

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);
Copy link
Contributor

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 .

Copy link
Contributor

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.

Copy link
Contributor

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?

@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 27, 2023 00:15 Destroyed
@ndouglas ndouglas marked this pull request as ready for review July 27, 2023 13:11
@swirtSJW
Copy link
Contributor

Related comment from the other issue #14495 (comment)

@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 27, 2023 14:35 Destroyed
@swirtSJW
Copy link
Contributor

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.

@swirtSJW
Copy link
Contributor

@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.

image

@ndouglas
Copy link
Contributor Author

ndouglas commented Jul 27, 2023

@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. if ($isModerated) { $result['isDraft'] = $this->isDraft; }) in multiple places.

It might be better if I say "N/A" for each of those values. That's really what is implied there.

@swirtSJW
Copy link
Contributor

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"

swirtSJW
swirtSJW previously approved these changes Jul 27, 2023
Copy link
Contributor

@swirtSJW swirtSJW left a comment

Choose a reason for hiding this comment

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

Banner create: Pass
image

Banner publish: Pass
image

System banner : Pass
image

VAMC Facility: passed
image

This all tests out for me @ndouglas

Really nice work. Thank you for undertaking it.

@va-cms-bot va-cms-bot temporarily deployed to Tugboat July 27, 2023 21:19 Destroyed
@ndouglas ndouglas merged commit 058a9ce into department-of-veterans-affairs:main Jul 27, 2023
15 checks passed
tjheffner pushed a commit to tjheffner/va.gov-cms that referenced this pull request Jul 28, 2023
…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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants