-
Notifications
You must be signed in to change notification settings - Fork 1
Check cross-template dependencies using liquid test YAML files #235
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughAdds two utilities in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
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.
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.
…specific liquid test files (RT templates only for now)
376f02d to
80e535c
Compare
d18c406 to
9a36f99
Compare
…orresponding test case
…, exportFiles, reconciliationTexts, and sharedParts tests. This change improves isolation and cleanup of test environments.
25fa32f to
53b84c7
Compare
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.
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.
| // Find all templates with liquid test YAML files in reconciliation_texts directories | ||
| // Only matches files whose basename ends with exactly `_liquid_test.yml` | ||
| // Also excludes files with extra suffixes like `_TY21_liquid_test.yml`, `_TY23_liquid_test.yml`, etc. | ||
| // Returns an array of template handles that have liquid test files | ||
| function findTemplatesWithLiquidTests() { | ||
| const results = []; | ||
| const folderPath = path.join(process.cwd(), FOLDERS.reconciliationText); | ||
|
|
||
| if (!fs.existsSync(folderPath)) { | ||
| return results; | ||
| } | ||
|
|
||
| const templateDirs = fs.readdirSync(folderPath); | ||
| for (const handle of templateDirs) { | ||
| const templateDir = path.join(folderPath, handle); | ||
| const stats = fs.statSync(templateDir); | ||
| if (!stats.isDirectory()) { | ||
| continue; | ||
| } | ||
|
|
||
| const testsDir = path.join(templateDir, "tests"); | ||
| if (!fs.existsSync(testsDir)) { | ||
| continue; | ||
| } | ||
|
|
||
| const testFiles = fs.readdirSync(testsDir); | ||
| for (const fileName of testFiles) { | ||
| // Match files ending with exactly `_liquid_test.yml` (no extra suffix) | ||
| // Pattern: any handle followed by `_liquid_test.yml`, but exclude variants with extra suffixes like `_TY21`, `_TY23` | ||
| const mainPattern = /^(.+)_liquid_test\.yml$/; | ||
| const match = fileName.match(mainPattern); | ||
|
|
||
| if (match) { | ||
| const fileHandle = match[1]; | ||
| // Exclude files with variant suffixes (e.g., `_TY21`, `_TY23`, etc.) | ||
| // These patterns typically have uppercase letters followed by digits before `_liquid_test` | ||
| const variantPattern = /_[A-Z]{2,}\d+$/; // Matches patterns like `_TY21`, `_TY23`, `_TY2021`, etc. | ||
| if (variantPattern.test(fileHandle)) { | ||
| continue; // Skip variant files | ||
| } | ||
|
|
||
| // Add the handle to results (avoid duplicates) | ||
| if (!results.includes(handle)) { | ||
| results.push(handle); | ||
| } | ||
| break; // Found liquid test file for this template, move to next template | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return results; | ||
| } |
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.
Ensure test filename matches the template handle.
checkLiquidTestDependencies later assumes the file is ${handle}_liquid_test.yml. If a template contains a differently named _liquid_test.yml, this function will still include the handle, but dependency scanning will skip it, leading to missed dependencies. Consider enforcing a name match here (or pass the actual file name forward).
🔧 Proposed fix
if (match) {
const fileHandle = match[1];
+ if (fileHandle !== handle) {
+ continue;
+ }
// Exclude files with variant suffixes (e.g., `_TY21`, `_TY23`, etc.)
// These patterns typically have uppercase letters followed by digits before `_liquid_test`
const variantPattern = /_[A-Z]{2,}\d+$/; // Matches patterns like `_TY21`, `_TY23`, `_TY2021`, etc.🤖 Prompt for AI Agents
In `@lib/utils/fsUtils.js` around lines 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.
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.
We should always make sure to use the handle in the yaml file, so no additional logic needed here.
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.
@BenjaminLangenakenSF, understood! I've noted that convention for future reference.
✏️ Learnings added
Learnt from: BenjaminLangenakenSF
Repo: silverfin/silverfin-cli PR: 235
File: lib/utils/fsUtils.js:359-410
Timestamp: 2026-01-20T16:12:40.533Z
Learning: In the Silverfin CLI codebase, liquid test YAML filenames should always match the template handle (e.g., for a template with handle "my_template", the test file should be named "my_template_liquid_test.yml").
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
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