Skip to content

Check cross-template dependencies using liquid test YAML files#235

Open
BenjaminLangenakenSF wants to merge 6 commits intomainfrom
check_liquid_test_dependencies
Open

Check cross-template dependencies using liquid test YAML files#235
BenjaminLangenakenSF wants to merge 6 commits intomainfrom
check_liquid_test_dependencies

Conversation

@BenjaminLangenakenSF
Copy link
Contributor

@BenjaminLangenakenSF BenjaminLangenakenSF commented Dec 17, 2025

Description

Check cross-template dependencies using liquid test YAML files.
Currently only implemented for RTs.

Testing Instructions

Steps:

  1. You can copy/paste a reconciliation_texts folder into the repo for testing purposes
  2. Run check_liquid_test_dependencies in the terminal (Cursor can assist with this)

Author Checklist

  • Skip bumping the CLI version

Reviewer Checklist

  • PR has a clear title and description
  • Manually tested the changes that the PR introduces
  • Changes introduced are covered by tests of acceptable quality

@BenjaminLangenakenSF BenjaminLangenakenSF self-assigned this Dec 17, 2025
@BenjaminLangenakenSF BenjaminLangenakenSF added the feature request New feature or request label Dec 17, 2025
@coderabbitai
Copy link

coderabbitai bot commented Dec 17, 2025

Walkthrough

Adds two functions to lib/utils/fsUtils.js: findTemplatesWithLiquidTests() to enumerate templates with exact _liquid_test.yml files, and checkLiquidTestDependencies(targetHandle) to parse those YAML files' data subtrees for references. Adds Jest tests for both utilities and refactors several tests to use mkdtemp-based temp dirs.

Changes

Cohort / File(s) Summary
Core utility functions
lib/utils/fsUtils.js
Added findTemplatesWithLiquidTests() (scans reconciliation_texts for files ending exactly with _liquid_test.yml, excluding variant suffixes) and checkLiquidTestDependencies(targetHandle) (loads/parses those YAML files, searches data subtrees for references to the target handle). Updated exports.
CLI command
bin/cli.js
Imported fsUtils and added check-dependencies CLI command that requires --handle and prints templates that reference the handle using checkLiquidTestDependencies.
New tests — dependency detection
tests/lib/utils/checkLiquidTestDependencies.test.js
New Jest suite covering detection/no-detection cases, string/key matches in data, ignoring context/expectation, nested structures/arrays, multiple cases per file, skipping invalid YAML, and aggregation across templates.
New tests — template discovery
tests/lib/utils/findTemplatesWithLiquidTests.test.js
New Jest suite validating missing/empty dirs, exact _liquid_test.yml detection, exclusion of variant/uppercase-suffixed filenames, ignoring non-directory entries, and correct aggregation/sorting.
Test refactors — temp dir handling
tests/lib/templates/accountTemplates.test.js, tests/lib/templates/exportFiles.test.js, tests/lib/templates/reconciliationTexts.test.js, tests/lib/templates/sharedParts.test.js
Replaced hard-coded/CWD-relative temp dirs with fs.mkdtempSync repo-root-based temporary directories. Tests now compute paths from tempDir, use process.chdir in setup, and clean up with fs.rmSync in teardown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main feature: checking cross-template dependencies via liquid test YAML files.
Description check ✅ Passed The description covers the main objective and provides testing instructions, though it deviates from the template structure by omitting the 'Fixes' link section.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch check_liquid_test_dependencies

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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_dependencies uses 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: 10000 is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b45685 and fac6bae.

📒 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 findTemplatesWithLiquidTests function 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 findTemplatesWithLiquidTests function 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_dependencies across 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.

@BenjaminLangenakenSF BenjaminLangenakenSF force-pushed the check_liquid_test_dependencies branch 4 times, most recently from 25fa32f to 53b84c7 Compare January 20, 2026 15:51
Copy link

@coderabbitai coderabbitai bot left a 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.

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

Choose a reason for hiding this comment

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

Can you put this parameter as a camel case to be in line with all the other logic.

e.g. targetHandle

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 dangers of AI coding 😅

return results;
}

// Find all templates that have a dependency on the given handle.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you perhaps put this in a command?
This will make it easier to run in the GH action + testing can be done locally

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes, makes sense, added!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants