home / skills / bdambrosio / cognitive_workbench / test-json-sql-sort

test-json-sql-sort skill

/src/saved_plans/test-json-sql-sort

This skill tests and explains SQL sort by implementing descending order on a papers collection and validating output.

npx playbooks add skill bdambrosio/cognitive_workbench --skill test-json-sql-sort

Review the files below or copy the command above to add this skill to your agents.

Files (2)
SKILL.md
354 B
---
name: test-json-sql-sort
description: Tests sort primitive (ORDER BY)
manual_only: true
---

# Test Sort Primitive

**Self-contained:** Creates test data internally

**Input:** Creates $papers collection (years: 2020, 2021, 2023, 2022)

**Operation:** Sort by year descending

**Expected Output:** $sorted collection ordered: 2023, 2022, 2021, 2020

Overview

This skill validates the sort primitive (ORDER BY) by running a focused test that creates its own data and asserts correct descending ordering. It is self-contained and requires no external fixtures. The test confirms that a collection of papers is ordered by year from newest to oldest.

How this skill works

The skill generates an internal $papers collection with four entries dated 2020, 2021, 2023, and 2022. It applies the sort operation to order the collection by the year field in descending order. The test compares the resulting $sorted collection to the expected sequence 2023, 2022, 2021, 2020 and fails if any position differs.

When to use it

  • When verifying that ORDER BY or equivalent sort primitives return correct descending results.
  • During unit testing of query engines, JSON-to-SQL mappers, or ORM sort implementations.
  • When adding or refactoring sort-related code paths and needing a quick regression check.
  • To validate ordering behavior in environments that generate or transform SQL/JSON queries.

Best practices

  • Keep the test self-contained: create all input data inside the test to avoid external dependencies.
  • Use a small, deterministic dataset with clear expected order to make failures obvious.
  • Make the expected ordering explicit and check sequence positions, not just set equality.
  • Run the test in isolation as part of CI to catch regressions in sorting logic early.

Example use cases

  • A developer modifies query translation logic and runs this test to ensure ORDER BY semantics remain intact.
  • A QA engineer adds this test to a suite to guard against regressions introduced by performance optimizations.
  • A library author uses the test to demonstrate correct descending sort behavior in documentation or examples.

FAQ

Does the test rely on external databases or fixtures?

No. The test is self-contained and creates the $papers collection internally.

What exact order is expected?

The expected $sorted order is years: 2023, 2022, 2021, 2020.