Skip to content

Conversation

@delphine-demeulenaere
Copy link
Contributor

@delphine-demeulenaere delphine-demeulenaere commented Jan 21, 2026

Description

The CLI reads the YAML file as a string. When we run tests and define a pattern, those tests can include an alias, but the anchor was defined in a different section that gets filtered out when running the tests.

Testing Instructions

Steps to reproduce the behavior:

silverfin run-test -f <firm_id> -h <handle> --pattern "pattern"

Include a template test pattern that makes use of an alias in the Liquid test.

image

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

@delphine-demeulenaere delphine-demeulenaere self-assigned this Jan 21, 2026
@delphine-demeulenaere delphine-demeulenaere added the bug Something isn't working label Jan 21, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 21, 2026

Walkthrough

Adds YAML anchor/alias preservation to pattern-based test filtering in lib/liquidTestRunner.js, introduces internal utilities for finding and extracting anchors/aliases, updates package.json version to 1.52.1, and adds a corresponding CHANGELOG.md entry dated 21/01/2026.

Changes

Cohort / File(s) Summary
Changelog & Version
CHANGELOG.md, package.json
Added changelog entry for v1.52.1 and bumped version from 1.52.0 → 1.52.1.
Test runner — YAML anchor/alias handling
lib/liquidTestRunner.js
Added internal helpers findAnchorDefinitions(), findAliasReferences(), extractAnchorBlocks() and enhanced filterTestsByPattern() to detect alias references in filtered output and prepend missing anchor definition blocks to preserve YAML validity.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and doesn't clearly specify what the bug is or what was fixed. Revise the title to be more specific, e.g., 'Fix YAML anchor filtering in pattern-based test execution' or similar.
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The description explains the issue and provides testing instructions, but lacks a clear 'Fixes #' reference and doesn't explicitly describe the solution implemented.

✏️ 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: 2

🤖 Fix all issues with AI agents
In `@CHANGELOG.md`:
- Around line 5-7: Fix typos in the CHANGELOG entry for version header "##
[1.52.1] (21/01/2026)" by correcting "conatin" to "contain", adding the missing
space between the inline code and the word "command" so "`silverfin run-test`
command" reads correctly, and add the missing comma on the line describing how
to enable it so the sentence reads "To enable it, run `silverfin run-test -p
\"string pattern\" -h template_handle`".

In `@lib/liquidTestRunner.js`:
- Around line 176-195: The current logic prepends whole test blocks from
extractAnchorBlocks into filteredContent, which reintroduces excluded tests and
breaks line tracking; change extractAnchorBlocks (and its call site) to return
only the anchor node definitions (or directly inline the resolved anchor nodes
into the matching tests found by findAliasReferences) rather than full test
blocks pulled from testContent/indexes, and when you insert those anchor
snippets update lineAdjustments (which currently only maps orderedMatchingTests)
to include mappings for any added lines so error locations remain correct;
alternatively, if you prefer server-side enforcement, modify the payload sent to
the backend to include the filtering pattern or explicit test names instead of
sending all tests so the server will not execute injected blocks.

CHANGELOG.md Outdated
Comment on lines 5 to 7
## [1.52.1] (21/01/2026)
In this version we are introducing Liquid batch/pattern testing. An extra option was added to the `silverfin run-test`command to run all tests which conatin a common string.
To enable it run `silverfin run-test -p "string pattern" -h template_handle`
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix typos in the 1.52.1 entry.
Line 6 has “conatin” and a missing space in “run-test`command”; Line 7 is missing a comma.

✏️ Proposed fix
- In this version we are introducing Liquid batch/pattern testing. An extra option was added to the `silverfin run-test`command to run all tests which conatin a common string.
- To enable it run `silverfin run-test -p "string pattern" -h template_handle`
+ In this version we are introducing Liquid batch/pattern testing. An extra option was added to the `silverfin run-test` command to run all tests which contain a common string.
+ To enable it, run `silverfin run-test -p "string pattern" -h template_handle`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
## [1.52.1] (21/01/2026)
In this version we are introducing Liquid batch/pattern testing. An extra option was added to the `silverfin run-test`command to run all tests which conatin a common string.
To enable it run `silverfin run-test -p "string pattern" -h template_handle`
## [1.52.1] (21/01/2026)
In this version we are introducing Liquid batch/pattern testing. An extra option was added to the `silverfin run-test` command to run all tests which contain a common string.
To enable it, run `silverfin run-test -p "string pattern" -h template_handle`
🤖 Prompt for AI Agents
In `@CHANGELOG.md` around lines 5 - 7, Fix typos in the CHANGELOG entry for
version header "## [1.52.1] (21/01/2026)" by correcting "conatin" to "contain",
adding the missing space between the inline code and the word "command" so
"`silverfin run-test` command" reads correctly, and add the missing comma on the
line describing how to enable it so the sentence reads "To enable it, run
`silverfin run-test -p \"string pattern\" -h template_handle`".

Comment on lines +176 to +195
// Check for alias references in the filtered content and add missing anchor definitions
const aliasReferences = findAliasReferences(filteredContent);
if (aliasReferences.length > 0) {
// Find anchors that are defined in the filtered content
const definedAnchors = new Set();
const anchorPattern = /&([a-zA-Z_][a-zA-Z0-9_]*)/g;
let match;
while ((match = anchorPattern.exec(filteredContent)) !== null) {
definedAnchors.add(match[1]);
}

// Find aliases that reference anchors not in the filtered content
const missingAnchors = aliasReferences.filter((alias) => !definedAnchors.has(alias));

if (missingAnchors.length > 0) {
// Extract the test blocks containing the missing anchors
const anchorBlocks = extractAnchorBlocks(testContent, missingAnchors, indexes);
if (anchorBlocks) {
filteredContent = anchorBlocks + "\n\n" + filteredContent;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "liquidTestRunner.js" | head -20

Repository: silverfin/silverfin-cli

Length of output: 92


🏁 Script executed:

cd lib && wc -l liquidTestRunner.js

Repository: silverfin/silverfin-cli

Length of output: 90


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '170,200p'

Repository: silverfin/silverfin-cli

Length of output: 1477


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '195,250p'

Repository: silverfin/silverfin-cli

Length of output: 1947


🏁 Script executed:

ast-grep --pattern 'function extractAnchorBlocks($_) { $$$}'

Repository: silverfin/silverfin-cli

Length of output: 49


🏁 Script executed:

rg -n "extractAnchorBlocks" lib/liquidTestRunner.js

Repository: silverfin/silverfin-cli

Length of output: 229


🏁 Script executed:

rg -n "function extractAnchorBlocks" lib/

Repository: silverfin/silverfin-cli

Length of output: 163


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '84,150p'

Repository: silverfin/silverfin-cli

Length of output: 2495


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '1,83p' | tail -40

Repository: silverfin/silverfin-cli

Length of output: 1474


🏁 Script executed:

rg -n "filterTestsByPattern" lib/liquidTestRunner.js

Repository: silverfin/silverfin-cli

Length of output: 286


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '250,350p'

Repository: silverfin/silverfin-cli

Length of output: 4065


🏁 Script executed:

rg -n "lineAdjustments" lib/liquidTestRunner.js

Repository: silverfin/silverfin-cli

Length of output: 849


🏁 Script executed:

rg -n "test_line" lib/liquidTestRunner.js

Repository: silverfin/silverfin-cli

Length of output: 124


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '294,310p'

Repository: silverfin/silverfin-cli

Length of output: 596


🏁 Script executed:

rg -n "SF\." lib/liquidTestRunner.js | head -20

Repository: silverfin/silverfin-cli

Length of output: 336


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '420,470p'

Repository: silverfin/silverfin-cli

Length of output: 2497


🏁 Script executed:

rg -n "pattern" lib/liquidTestRunner.js | head -30

Repository: silverfin/silverfin-cli

Length of output: 1497


🏁 Script executed:

rg -n "createTestRun\|createPreviewRun" lib/ -A 5

Repository: silverfin/silverfin-cli

Length of output: 49


🏁 Script executed:

fd "*.js" lib/ -o | xargs grep -l "createTestRun\|createPreviewRun" | head -5

Repository: silverfin/silverfin-cli

Length of output: 183


🏁 Script executed:

find lib -name "*.js" -type f | head -20

Repository: silverfin/silverfin-cli

Length of output: 570


🏁 Script executed:

rg -n "createTestRun" lib/

Repository: silverfin/silverfin-cli

Length of output: 306


🏁 Script executed:

cat -n lib/api/sfApi.js | sed -n '407,450p'

Repository: silverfin/silverfin-cli

Length of output: 1784


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '550,565p'

Repository: silverfin/silverfin-cli

Length of output: 774


🏁 Script executed:

cat -n lib/liquidTestRunner.js | sed -n '116,125p'

Repository: silverfin/silverfin-cli

Length of output: 420


Pattern filtering is undermined by prepending full test blocks containing unmatched tests.

The extractAnchorBlocks function (line 117) returns entire test blocks, not just anchor definitions. These blocks come from tests that don't match the filter pattern and are prepended to filteredContent (line 194). Since no pattern information is passed to the backend API (lines 294-298 send only template, tests, and mode), the server executes all test blocks in the YAML—including those injected for anchor resolution. This reintroduces excluded tests and defeats the filtering guarantee.

Additionally, lineAdjustments only contains mappings for orderedMatchingTests (lines 202-208), so tests from injected anchor blocks lack proper line tracking, potentially causing incorrect error reporting.

Consider instead inlining referenced anchor nodes into matching tests or implementing server-side test filtering by name.

🤖 Prompt for AI Agents
In `@lib/liquidTestRunner.js` around lines 176 - 195, The current logic prepends
whole test blocks from extractAnchorBlocks into filteredContent, which
reintroduces excluded tests and breaks line tracking; change extractAnchorBlocks
(and its call site) to return only the anchor node definitions (or directly
inline the resolved anchor nodes into the matching tests found by
findAliasReferences) rather than full test blocks pulled from
testContent/indexes, and when you insert those anchor snippets update
lineAdjustments (which currently only maps orderedMatchingTests) to include
mappings for any added lines so error locations remain correct; alternatively,
if you prefer server-side enforcement, modify the payload sent to the backend to
include the filtering pattern or explicit test names instead of sending all
tests so the server will not execute injected blocks.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants