Skip to content

[NU-2140] Enricher mocking #7982

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
wants to merge 22 commits into
base: staging
Choose a base branch
from
Open

[NU-2140] Enricher mocking #7982

wants to merge 22 commits into from

Conversation

raphaelsolarski
Copy link
Contributor

@raphaelsolarski raphaelsolarski commented Apr 23, 2025

Describe your changes

Checklist before merge

  • Related issue ID is placed at the beginning of PR title in [brackets] (can be GH issue or Nu Jira issue)
  • Code is cleaned from temporary changes and commented out lines
  • Parts of the code that are not easy to understand are documented in the code
  • Changes are covered by automated tests
  • Showcase in dev-application.conf added to demonstrate the feature
  • Documentation added or updated
  • Added entry in Changelog.md describing the change from the perspective of a public distribution user
  • Added MigrationGuide.md entry in the appropriate subcategory if introducing a breaking change
  • Verify that PR will be squashed during merge

Copy link
Contributor

github-actions bot commented Apr 30, 2025

created: #8057
⚠️ Be careful! Snapshot changes are not necessarily the cause of the error. Check the logs.

@raphaelsolarski
Copy link
Contributor Author

Screenshot 2025-05-07 at 11 13 28
Screenshot 2025-05-07 at 11 13 52
Screenshot 2025-05-07 at 11 14 35

Copy link
Member

Choose a reason for hiding this comment

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

Why it is changed if we hide this feature behind feature flag?

const EXPRESSION_TEXT_PATH = `${MOCKED_OUTPUT_IN_NODE_FIELD_NAME}.${MOCK_EXPRESSION_PARAMETER_NAME}.expression`;

const MOCK_EXPRESSION_HINT_TEXT =
"If provided the expression will be evaluated in tests instead of invoking real enricher behaviour (e.g. instead of calling a service/database).\n\n" +
Copy link
Member

Choose a reason for hiding this comment

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

It sounds a little bit complex, maybe simpler:
"If you provide this expression, the real service won't be invoked during tests. Instead, the result of the evaluation will be used."

@@ -43,6 +48,8 @@ import shapeless.syntax.typeable._

object NodeCompiler {

val MockExpressionParameterName: ParameterName = ParameterName("mockExpression")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe let's use $mockExpression to avoid some collision

@@ -1019,6 +1022,28 @@ class InterpreterSpec extends AnyFunSuite with Matchers {
result shouldBe Collections.singletonMap("bool", false)
}

test("invokes enricher with mocked output in live mode") {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I have two problems with this:

  1. By reading the test case title I don't know what do you expect. The real enriched should be invoked or no?
  2. I see that the real enricher wasn't invoked. Instead the mocked value was returned. We wanted to mock enrichers only in tests :) Maybe I misunderstand something?

@@ -208,6 +209,15 @@ object node {
override def parameters: List[NodeParameter] = service.parameters
}

sealed trait EnricherMockedOutput
Copy link
Member

Choose a reason for hiding this comment

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

When we talked about that I rather thought about something like:

EnricherTestingConfiguration(componentBehaviour: EnricherTestingBehaviour) 

sealed trait EnricherTestingBehaviour
object EnricherTestingBehaviour {
  case class ReturnMockedValue(outputValueExpression: Expression) extends EnricherTestingBehaviour
  case object InvokeRealService extends EnricherTestingBehaviour
}

and having InvokeRealService as a default.

Thanks to EnricherTestingBehaviour envelope, we could add something more next to componentBehaviour.

But after we talk about further changes around testcases, I think that we should go into totally different, YAGNI approach and not invent this structure at all, because it shows that we have to be prepared for many evolutions of this structure.

BTW, I now see that this architectural decision about keeping test cases data in scenario graph will cause many scenario migrations which will be shown in the scenario history.

LSS: Let's remove this sealed trait.


return (
<ExpressionTestResults fieldName={MOCK_EXPRESSION_PARAMETER_NAME} resultsToShow={testResultsState.testResultsToShow}>
<EditableEditor
Copy link
Member

Choose a reason for hiding this comment

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

Currently, we are in the middle in the migration to Json template | Expression combination of editors in almost all places. So far, we did it conservatively, only in places where at the end, json is processed somehow, but there is the plan to use this approach almost everywhere. Let's use this combination here as well.

): NodeCompilationResult[compiledgraph.service.ServiceRef] = {
compileService(n.service, ctx, Some(outputVar))
): NodeCompilationResult[EnricherCompilationResult] = {
val serviceCompilationResult = compileService(n.service, ctx, Some(outputVar))
Copy link
Member

Choose a reason for hiding this comment

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

I think that we should have somethink like

(runtimeMode, mockedOutput) match {
  case (Test, Some(...) => compileMockExpression
  case _ => compileService 
}

See next comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client client main fe docs ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants