Skip to content

Feature/1681 reverse dependency lookup for deploy - #2547

Merged
JoernBerkefeld merged 26 commits into
developfrom
feature/1681-reverse-dependency-lookup-for-deploy
Oct 9, 2026
Merged

JoernBerkefeld merged 26 commits into
developfrom
feature/1681-reverse-dependency-lookup-for-deploy

Conversation

@yuliialikhyt

@yuliialikhyt yuliialikhyt commented Mar 14, 2026 •

Copy link
Copy Markdown
Collaborator

PR details

Introduced refresh option for assets. Added a function to lookup emails that are referencing the block.

Can be run after deploy or separately. Can refresh triggeredSends linked to an email, or if the user runs the function for a code block (asset-other or asset-block), then the function will lookup emails that are using the code block. The function refreshes emails on the business unit it's been invoked on.

Examples:

mcdev refresh SFMC/YL asset "34b29f13-3bb7-4365-963d-02f2c3d1629b"
mcdev refresh SFMC/_ParentBU_ asset "TEST_HTML_SHARED"    
mcdev d SFMC/YL asset "34b29f13-3bb7-4365-963d-02f2c3d1629b" --fromRetrieve --refresh
mcdev refresh SFMC/YL asset "GRANDCHILD"    

What changes did you make? (Give an overview)

Further details (optional)

Tested on a couple of different code blocks (htmlblock, buttonblock, freeformblock and other), on a Parent BU and on a child BU. Tested refresh of a shared block.

Retrieve of published journeys was not necessary, the existing functionality of _refreshTriggeredSend function already validates triggeredSend status. Also, journeys with a status Finishing are not accepting new contacts, but could be still sending emails.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • test scripts updated
  • Wiki updated (if applicable)

@yuliialikhyt
yuliialikhyt changed the base branch from main to develop March 14, 2026 10:26
@yuliialikhyt yuliialikhyt added the c/asset COMPONENT label Mar 14, 2026
@github-actions

github-actions Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

Coverage Report

Commit:889e3cc
Base: develop@5d57b39

Type Base This PR
Total Statements Coverage  76.27%  76.65%  (+0.38%)
Total Branches Coverage  73.76%  74.37%  (+0.61%)
Total Functions Coverage  86.73%  87.12%  (+0.39%)
Total Lines Coverage  76.27%  76.65%  (+0.38%)
Details (changed files):
File Statements Branches Functions Lines
lib/metadataTypes/Asset.js  85.55%  80.03%  94.64%  85.55%
lib/util/cache.js  86.79%  72.41%  100%  86.79%
lib/util/util.js  87.64%  78.76%  93.22%  87.64%

@yuliialikhyt
yuliialikhyt marked this pull request as ready for review March 22, 2026 11:00
@JoernBerkefeld
JoernBerkefeld requested a review from Copilot March 24, 2026 23:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the existing --refresh deploy behavior so that refreshing triggered send definitions also works when deploying/updating Content Builder blocks (and other non-email assets) by reverse-looking-up emails that reference those blocks.

Changes:

  • Replaces the post-deploy refresh hook to call a new Asset.refresh() entrypoint instead of refreshing only when the deployed asset is an email.
  • Adds reverse dependency lookup for blocks via an Asset query (MUSTCONTAIN) to find emails referencing the updated block, then refreshes related TriggeredSendDefinitions.
  • Updates/extends the test suite and mock REST/SOAP fixtures to cover the new refresh behavior and request patterns.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
lib/metadataTypes/Asset.js Implements Asset.refresh() and _findEmailsUsingBlock() and wires refresh into postDeployTasks()
@types/lib/metadataTypes/Asset.d.ts Updates typings to include new helper and refresh() return type
@types/lib/metadataTypes/Asset.d.ts.map Regenerated source map for updated typings
test/resourceFactory.js Extends request-to-fixture mapping to support MUSTCONTAIN query operator in POST body
test/type.asset.test.js Adds test case for deploying a block with refresh: true and validates request count
test/type.triggeredSend.test.js Extends expected refreshed triggered send keys and request count
test/type.journey.test.js Updates expected journey count and request count due to additional mocked interaction
test/resources/9999999/triggeredSendDefinition/retrieve-TriggeredSendStatusINdummy,Active-response.xml Adds an additional TriggeredSendDefinition result to mock “Active” retrieval
test/resources/9999999/triggeredSendDefinition/retrieve-CustomerKey=testExistingRefresh_triggeredSend-response.xml New SOAP fixture for retrieving a specific TriggeredSendDefinition by CustomerKey
test/resources/9999999/interaction/v1/interactions/key_testExisting_email_block_refresh/get-response.json New REST fixture for a specific published interaction containing the triggered send key
test/resources/9999999/interaction/v1/interactions/get-response-status=Published.json Extends published interaction listing to include the new interaction
test/resources/9999999/asset/v1/content/assets/query/post-response-contentMUSTCONTAINtestExisting_block_refresh.json New REST fixture for reverse lookup of emails referencing a block key
test/resources/9999999/asset/v1/content/assets/query/post-response-assetType.idIN219,220,221,222,223,224,225,226,227,228,230,232,240,241,242,243,244,245.json Extends existing asset query fixture to include the new email asset
test/resources/9999999/asset/v1/content/assets/334322/patch-response.json New REST fixture for patching the updated block asset
test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_block_refresh.asset-block-meta.json Adds mock deploy metadata for the test block asset
test/mockRoot/deploy/testInstance/testBU/asset/block/testExisting_block_refresh.asset-block-meta.html Adds mock deploy HTML content for the test block asset

Comment thread lib/metadataTypes/Asset.js Resolved
Comment thread lib/metadataTypes/Asset.js Resolved
Comment thread lib/metadataTypes/Asset.js Resolved
Comment thread lib/metadataTypes/Asset.js Resolved
Comment thread lib/metadataTypes/Asset.js Resolved
@JoernBerkefeld

Copy link
Copy Markdown
Contributor

two things that caught my attention:

  1. so far, we run refresh on journeys and on triggered send. which, technically, your solution aims to do as well. however, you are now asking to run refresh with the asset key as reference in the command which shall then find relevant journeys. something similar was only possible via deploy --refresh up until now if im not mistaken. you are not refreshing the asset but the journey. maybe this is nothing bad but still worth thinking about.

  2. if i understood your logic correctly it finds emails that use the content block in question (not sure how exactly thats done tbh though). but what it doesnt do is recursively going through content blocks up to emails - or is it?
    if i ran mcdev refresh cred/bu -m asset:myChangedBlock, would it find email "fooBar" if fooBar loads block X which loads block Y which loads myChangedBlock: fooBar > X > Y > myChangedBlock

@JoernBerkefeld JoernBerkefeld added this to the 9.1.0 milestone Mar 25, 2026
@yuliialikhyt

Copy link
Copy Markdown
Collaborator Author

I've created a refresh function specifically for the Asset type. Journey and TriggeredSend already have similar functionality, no changes were necessary.

Initially, I considered retrieving published journeys as part of this, but I reverted that approach. I realized that the existing TriggeredSend refresh logic already checks whether a TriggeredSend linked to an email activity is Active. So, the process looks up email keys based on code block keys and then runs refresh on the active TriggeredSends associated with those emails.

The logic I've added:

Refresh command on asset:

  1. Cache assets and shared assets (since refresh only receives keys, nothing is cached initially; shared assets are mainly needed for code blocks)
  2. Iterate over the provided keys (these can be a mix of email keys and code block keys)
  3. Look up each key in the cached assets and determine whether it is an email or a code block
  4. If it's an email - add it to the refresh queue
  5. If it's a code block - store it separately and look up emails referencing it
  6. Run the existing logic to refresh TriggeredSends for those emails

Deploy with refresh:

Deploy as usual
Run refresh as part of postDeployTasks - the rest of the process is the same as above

To find emails referencing a content block, I used the POST /asset/v1/content/assets/query endpoint with a condition on the content property. It correctly resolves references even if the block is included via ContentBlockById or ContentBlockByName. The user can pass content block customerKeys as usual. But I see now that it returns some false positives, like when the key also happens to be a part of the word.

I'll refine the condition to something more specific, and add recursion to handle embedded blocks.

@yuliialikhyt

yuliialikhyt commented Mar 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

two things that caught my attention:

1. so far, we run refresh on journeys and on triggered send. which, technically, your solution aims to do as well. however, you are now asking to run refresh with the asset key as reference in the command which shall then find relevant journeys. something similar was only possible via deploy --refresh up until now if im not mistaken. you are not refreshing the asset but the journey. maybe this is nothing bad but still worth thinking about.

2. if i understood your logic correctly it finds emails that use the content block in question (not sure how exactly thats done tbh though). but what it doesnt do is recursively going through content blocks up to emails - or is it?
   if i ran `mcdev refresh cred/bu -m asset:myChangedBlock`, would it find email "fooBar" if fooBar loads block X which loads block Y which loads myChangedBlock: `fooBar > X > Y > myChangedBlock`

Added recursion to support embedded blocks 😊
Tested with

  • ContentBlockByKey("KEY")
  • ContentBlockByKey('KEY')
  • ContentBlockById("111")
  • ContentBlockById('111')
  • ContentBlockById(111)
  • ContentBlockByName(NAME)
  • ContentBlockByName("NAME")

@yuliialikhyt

Copy link
Copy Markdown
Collaborator Author

@JoernBerkefeld how do I get rid of this error? I can't see 8.4.0 milestone referenced in the PR
Sync Milestone from Issue / sync-milestone (pull_request)

@JoernBerkefeld

Copy link
Copy Markdown
Contributor

No clue, will have to take another look. But that's not important. If the "required" actions ran successfully we are good.

Gimme a few more days for this. I'm working on something BIG right now and will get back to mcdev task afterwards :)

@JoernBerkefeld

Copy link
Copy Markdown
Contributor

That said, could you open a bug ticket for that error pls?

@yuliialikhyt yuliialikhyt self-assigned this Apr 1, 2026
@JoernBerkefeld JoernBerkefeld removed this from the 9.1.0 milestone Apr 1, 2026
@github-actions github-actions Bot added this to the 9.1.0 milestone Apr 1, 2026
Updated warning message to specify that the milestone may be closed or deleted.
@JoernBerkefeld JoernBerkefeld added the PRIORITY used for professional service clients label May 31, 2026
…r-deploy

# Conflicts:
#	@types/lib/metadataTypes/Asset.d.ts
#	@types/lib/metadataTypes/Asset.d.ts.map
#	lib/metadataTypes/Asset.js
#	test/resources/9999999/asset/v1/content/assets/query/post-response-assetType.idIN219,220,221,222,223,224,225,226,227,228,230,232,240,241,242,243,244,245.json
#	test/type.journey.test.js
@JoernBerkefeld
JoernBerkefeld added this pull request to stack #2676 October 8, 2026 08:21
@JoernBerkefeld
JoernBerkefeld removed this pull request from stack #2676 October 8, 2026 12:44
@JoernBerkefeld

Copy link
Copy Markdown
Contributor

looks like this is finally getting merged @yuliialikhyt
thank you for your patience.

JoernBerkefeld and others added 5 commits October 8, 2026 22:14
Broaden Content Builder candidate searches to function names, then verify exact literal keys, IDs and full folder-path names locally. Accept either quote style, whitespace and optional arguments without admitting identifier prefixes or dynamic expressions.

Inspect nested views, slots and blocks and fetch full assets only when query content is absent. Preserve recursive traversal and customer-key deduplication. Add seven regression cases and document the literal-only limitation; pagination and refresh contracts are handled separately.

Co-authored-by: Cursor <[email protected]>
Request ascending asset IDs and restart shard-limited pagination with the original dependency predicate AND an advancing greater-than ID cursor. Never replace the dependency filter with a cursor-only query that could refresh unrelated emails.

Fail explicitly when a shard error has no usable advancing cursor, and rethrow query failures instead of returning partially collected results. Add complete-predicate pagination assertions, unrelated beyond-cursor controls and first-page/partial-result failure regressions.

Co-authored-by: Cursor <[email protected]>
Require an explicit asset-key array before caching. An empty selection, missing email legacy IDs or no valid matching triggered sends returns an empty result without falling through to refresh-all semantics. Retain the approved undefined cache arguments.

Let discovery and refresh exceptions reach existing command/deploy error handling instead of reporting a successful no-op. Add success, empty-selection, omitted-key, discovery/refresh failure and deploy-semantic regressions. Document that a failed post-deploy refresh does not roll back asset deployment.

Co-authored-by: Cursor <[email protected]>
Validate complete dependency OR and cursor AND predicates in the fixture router instead of blindly routing the right operand. Filter nested content and cursor candidates honestly and reject malformed predicates.

Exercise real triggered-send discovery, validation and refresh transport for exactly two dependent emails and two JOURNEY sends. Exclude unrelated and inactive controls and assert every pause, publish and restart operation. Add C-to-B-to-A traversal, cycle termination, duplicate candidate and multiply reachable email assertions; strengthen deploy integration to exact SOAP targets.

Verification: zero-warning lint and TypeScript checks passed; all 54 test files completed in serial fresh processes with 581 passing and 25 pending. Combined npm test exits zero without a Mocha end event and remains a separately reported cross-suite limitation.
Co-authored-by: Cursor <[email protected]>
Pin project Mocha to 11.8.0 for hbenl adapter compatibility and remove the null mochaPath override so the adapter resolves the local package.

Initialize normal mock test options before loading deploy fixtures in the explicit asset refresh suite. This keeps logfile transports disabled when the suite runs independently and prevents mock-fs file descriptor 3 from colliding with the adapter IPC channel after filesystem restoration. Assert noLogFile remains enabled.

Verified installed hbenl 2.14.4 worker: 606 discovered, 581 passed, 25 skipped, zero failures, finished delivered. Full npm test, lint:fix, lint and TypeScript validation passed. No runtime API changes.
@JoernBerkefeld
JoernBerkefeld merged commit 6a6bdca into develop Oct 9, 2026
7 checks passed
@JoernBerkefeld
JoernBerkefeld deleted the feature/1681-reverse-dependency-lookup-for-deploy branch October 9, 2026 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/asset COMPONENT PRIORITY used for professional service clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] reverse dependency lookup for deploy --refresh [TASK] investigate minimum scope / permissions required to run mcdev

3 participants