Check cross-template dependencies using liquid test YAML files#235
Check cross-template dependencies using liquid test YAML files#235BenjaminLangenakenSF wants to merge 6 commits intomainfrom
Conversation
WalkthroughAdds two functions to Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
lib/utils/fsUtils.js (2)
418-476: Consider renaming to camelCase for consistency.The function
check_liquid_test_dependenciesuses snake_case naming, which is inconsistent with the rest of the codebase where camelCase is used (e.g.,findTemplatesWithLiquidTests,getAllTemplatesOfAType,listSharedPartsUsedInTemplate).Apply this diff to rename the function:
-function check_liquid_test_dependencies(target_handle) { +function checkLiquidTestDependencies(targetHandle) { const dependentHandles = []; const allHandlesWithTests = findTemplatesWithLiquidTests(); // Recursively check if target_handle appears in the data subtree const containsHandle = (obj, handle) => {And update the export and parameter name:
- check_liquid_test_dependencies, + checkLiquidTestDependencies,
453-453: Add documentation explaining the increased maxAliasCount setting.The
maxAliasCount: 10000is intentionally set higher than the default (100) to support parsing of legitimate liquid test YAML files—this was increased from 1000 in a prior fix when real test files exceeded that limit. While the security concern regarding YAML bombs is valid, the risk is mitigated here since these files are internal tests, not untrusted input.Consider adding an inline comment explaining this trade-off (e.g.,
// maxAliasCount increased to 10000 to support liquid test files with many reusable YAML anchors).
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
lib/utils/fsUtils.js(3 hunks)tests/lib/utils/checkLiquidTestDependencies.test.js(1 hunks)tests/lib/utils/findTemplatesWithLiquidTests.test.js(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/lib/utils/findTemplatesWithLiquidTests.test.js (1)
lib/utils/fsUtils.js (6)
fs(1-1)require(4-4)path(2-2)templateDir(373-373)handle(239-239)handle(267-267)
tests/lib/utils/checkLiquidTestDependencies.test.js (1)
lib/utils/fsUtils.js (4)
fs(1-1)require(4-4)path(2-2)templateDir(373-373)
🔇 Additional comments (3)
tests/lib/utils/findTemplatesWithLiquidTests.test.js (1)
1-196: LGTM! Comprehensive test coverage.The test suite thoroughly validates the
findTemplatesWithLiquidTestsfunction across multiple scenarios including empty directories, variant file exclusion, directory filtering, and edge cases. The setup and teardown logic properly isolates each test using temporary directories.lib/utils/fsUtils.js (1)
359-410: LGTM! Well-implemented template discovery.The
findTemplatesWithLiquidTestsfunction correctly identifies templates with liquid test files, properly excludes variant suffixes (e.g.,_TY21,_AB123), and handles edge cases like non-directory entries. The regex patterns are appropriate for the use case.tests/lib/utils/checkLiquidTestDependencies.test.js (1)
1-403: LGTM! Excellent test coverage for dependency checking.The test suite comprehensively validates
check_liquid_test_dependenciesacross numerous scenarios including:
- Detection of handle references in data as both keys and values
- Proper scoping to only the data subtree (excluding context and expectation)
- Handling of nested structures and arrays
- Graceful error handling for invalid YAML
- Multiple test cases and uniqueness validation
The tests provide strong confidence in the implementation's correctness.
Note: If the function is renamed to
checkLiquidTestDependencies(as suggested in the implementation review), remember to update the test imports and calls accordingly.
25fa32f to
53b84c7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@lib/utils/fsUtils.js`:
- Around line 359-410: The function findTemplatesWithLiquidTests currently adds
a template handle when any *_liquid_test.yml exists in its tests dir, but that
file's basename (fileHandle) may not equal the template handle, causing
checkLiquidTestDependencies (which expects `${handle}_liquid_test.yml`) to miss
dependencies; change the logic in findTemplatesWithLiquidTests to only add the
template handle when the matched fileHandle exactly equals the directory handle
(i.e., require fileHandle === handle), or alternatively return/preserve the
actual test filename so checkLiquidTestDependencies can use it—update the code
paths around findTemplatesWithLiquidTests (references:
findTemplatesWithLiquidTests, fileHandle, handle, checkLiquidTestDependencies)
accordingly to ensure the filename and handle are consistent.
lib/utils/fsUtils.js
Outdated
| // Currently only checks reconciliation texts (excludes account templates). | ||
| // @param {string} target_handle - The handle to search for in other templates' test files | ||
| // @returns {Array<string>} Array of handles that depend on the target_handle | ||
| function checkLiquidTestDependencies(target_handle) { |
There was a problem hiding this comment.
Can you put this parameter as a camel case to be in line with all the other logic.
e.g. targetHandle
There was a problem hiding this comment.
The dangers of AI coding 😅
| return results; | ||
| } | ||
|
|
||
| // Find all templates that have a dependency on the given handle. |
There was a problem hiding this comment.
Could you perhaps put this in a command?
This will make it easier to run in the GH action + testing can be done locally
There was a problem hiding this comment.
Ah yes, makes sense, added!
…specific liquid test files (RT templates only for now)
…orresponding test case
…, exportFiles, reconciliationTexts, and sharedParts tests. This change improves isolation and cleanup of test environments.
1920642 to
23a0648
Compare
Description
Check cross-template dependencies using liquid test YAML files.
Currently only implemented for RTs.
Testing Instructions
Steps:
reconciliation_textsfolder into the repo for testing purposescheck_liquid_test_dependenciesin the terminal (Cursor can assist with this)Author Checklist
Reviewer Checklist