Skip to content

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 utilities in lib/utils/fsUtils.jsfindTemplatesWithLiquidTests() to list templates containing exact _liquid_test.yml files and checkLiquidTestDependencies(target_handle) to parse those YAMLs for references. Adds Jest suites for both utilities and refactors multiple tests to use repo-root temporary directories.

Changes

Cohort / File(s) Summary
Core utility functions
lib/utils/fsUtils.js
Added findTemplatesWithLiquidTests() to enumerate handles under reconciliation_texts with files ending exactly _liquid_test.yml (excluding variant suffixes) and checkLiquidTestDependencies(target_handle) which parses those YAML files (yaml) to detect references within data. Export list updated.
New tests — dependency detection
tests/lib/utils/checkLiquidTestDependencies.test.js
New Jest suite covering: no matches, string/key matches in data, exclusion of context/expectation, scans only templates with liquid tests, multiple cases per file, nested structures/arrays, skipping invalid YAML, unique aggregation across templates.
New tests — template discovery
tests/lib/utils/findTemplatesWithLiquidTests.test.js
New Jest suite covering: empty/missing dirs, detection of exact _liquid_test.yml files, exclusion of variant/uppercase-suffixed filenames, ignoring non-directory entries and templates without tests, isolation from other template dirs, aggregation and 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 repo-root-based temporary directories via fs.mkdtempSync; tests compute per-test paths from repoRoot, use process.chdir in setup, and clean up with fs.rmSync (recursive/force). beforeEach/afterEach adjusted.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

  • Check template dependencies #213 — Implements YAML-based discovery and dependency checking of liquid-test files, matching the issue's dependency-detection objective.
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is missing the required 'Fixes #' issue link and lacks detailed summary of changes in the Description section. Add a 'Fixes #' line linking to the related issue and provide a more detailed summary of the changes (new functions, imports, test coverage) in the Description section.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding functionality to check cross-template dependencies using liquid test YAML files, which aligns with the core implementation of findTemplatesWithLiquidTests and checkLiquidTestDependencies utilities.
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

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.

…specific liquid test files (RT templates only for now)
@BenjaminLangenakenSF BenjaminLangenakenSF force-pushed the check_liquid_test_dependencies branch from 376f02d to 80e535c Compare January 20, 2026 13:25
@BenjaminLangenakenSF BenjaminLangenakenSF force-pushed the check_liquid_test_dependencies branch 2 times, most recently from d18c406 to 9a36f99 Compare January 20, 2026 15:48
…, exportFiles, reconciliationTexts, and sharedParts tests. This change improves isolation and cleanup of test environments.
@BenjaminLangenakenSF BenjaminLangenakenSF force-pushed the check_liquid_test_dependencies branch 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.

Comment on lines +359 to +410
// 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;
}
Copy link

@coderabbitai coderabbitai bot Jan 20, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Copy link
Contributor Author

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.

Copy link

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.

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