Skip to content

Add regression tests for flake-schemas - #46

Merged
edolstra merged 2 commits into
mainfrom
tests
Oct 24, 2025
Merged

edolstra merged 2 commits into
mainfrom
tests

Conversation

@edolstra

@edolstra edolstra commented Oct 24, 2025 •

Copy link
Copy Markdown
Collaborator

This adds some basic regression tests for some flake schemas. It runs nix flake show --json and nix flake check and verifies that the output is as expected.

This PR also fixes a wrong what attribute for the formatter schema.

@coderabbitai

coderabbitai Bot commented Oct 24, 2025 •

Copy link
Copy Markdown

Walkthrough

This PR establishes comprehensive test infrastructure for Nix flake schemas. It modifies the CI workflow to run flake-based checks instead of formatting validation, updates the main flake's formatter schema descriptor from "package" to "formatter", adds test fixtures for multiple flake outputs (checks, packages, legacyPackages, nixos, schemas), provides test framework configuration, and includes development documentation.

Changes

Cohort / File(s) Summary
CI/Workflow Updates
\.github/workflows/check\.yml
Changed workflow step from "Check Nix formatting" to "Run tests"; replaced nixfmt check with nix flake check -L ./tests invocation.
Configuration & Documentation
\.gitignore, README\.md
Added .gitignore with *~ pattern for editor backup files; added Development section to README with test and formatting commands.
Schema Definition
flake\.nix
Modified formatterSchema.inventory mapping to change descriptor from what = "package" to what = "formatter" for formatter entries.
Test Framework
tests/flake\.nix
Added devShell and two checks: formatting check using treefmt with nixfmt-tree, and checkSchemas runner that validates test flakes offline using jq and wdiff with per-test output capture.
Checks Test Fixture
tests/checks\.json, tests/checks/flake\.nix
Added test output JSON and flake exposing hello checks for x86_64-linux and aarch64-linux architectures.
Packages Test Fixture
tests/packages\.json, tests/packages/flake\.nix
Added test output JSON and flake exporting hello packages for x86_64-linux and aarch64-linux.
LegacyPackages Test Fixture
tests/legacyPackages\.json, tests/legacyPackages/flake\.nix
Added test output JSON and flake defining legacyPackages structure with hello, pythonPackages (lxml, python), and foo attribute sets.
NixOS Test Fixture
tests/nixos\.json, tests/nixos/flake\.nix
Added test output JSON and flake defining nixosConfigurations.machine with minimal filesystem and boot configuration.
Schemas Test Fixture
tests/schemas\.json, tests/schemas/flake\.nix, tests/schemas\.check-err
Added test output JSON with schema definitions including bar and xyzzy with validation checks; added flake with inventory mapAttrs for schema metadata; added expected error output file.

Sequence Diagram

sequenceDiagram
    participant GH as GitHub Actions
    participant Check as nix flake check
    participant Tests as tests/flake.nix
    participant Format as formatting check
    participant Schema as checkSchemas check
    participant Offline as offline nix store
    participant JSON as test .json files

    GH->>Check: nix flake check -L ./tests
    Check->>Tests: evaluate checks
    
    rect rgb(200, 220, 255)
    Note over Format,Tests: Formatting Validation (x86_64-linux)
    Tests->>Format: run treefmt + nixfmt-tree
    end
    
    rect rgb(220, 200, 255)
    Note over Schema,JSON: Schema Validation (per-test)
    Tests->>Schema: iterate over test flakes
    Schema->>Offline: fetch nixpkgs lock (offline mode)
    Schema->>JSON: load tests/*.json
    Schema->>Schema: nix flake show → .json
    Schema->>Schema: nix flake check (offline)
    Schema->>Schema: jq diff vs expected
    Schema->>Schema: capture .check-err if failed
    end
    
    Schema->>Check: report results
    Check->>GH: pass/fail
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Multiple files of varying complexity: test fixtures (JSON structures, minimal logic), new Nix flake expressions with moderate logic density (offline test execution, jq filtering), CI workflow change, and schema definition updates. Review requires verification of test data consistency, correct schema mapping, offline invocation correctness, and proper error capture patterns across heterogeneous test types.

Poem

🐰 Hop, hop, the tests now flow,
Flake checks validate each schema so,
From packages to configs, all arranged,
With offline builds—no network exchange!
Format and schemas in harmony dance,
What used to be "package" now takes a new stance!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add regression tests for flake-schemas" accurately describes the dominant and primary change in this changeset. The vast majority of the changes involve adding new test infrastructure: multiple test configuration files (checks.json, legacyPackages.json, nixos.json, packages.json, schemas.json), corresponding flake configurations under the tests directory, test data files, and CI workflow modifications to run these tests. The supporting changes to README.md, .gitignore, and flake.nix all facilitate or document the new test suite. The title is concise, clear, and specific enough that a reviewer scanning commit history would immediately understand the intent.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch tests

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

@edolstra
edolstra force-pushed the tests branch 5 times, most recently from 753a27a to 7ef3f3b Compare October 24, 2025 16:46
@edolstra
edolstra marked this pull request as ready for review October 24, 2025 17:34

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 (4)
README.md (1)

64-74: Add language identifiers to code blocks.

The Development section is a helpful addition. However, the code blocks should specify their language for better rendering and syntax highlighting.

Apply this diff:

 ## Development
 
 After making changes to `flake-schemas`, be sure to run the tests:
-```
+```bash
 nix flake check -L ./tests

To apply formatting, run the following:
- +bash
nix develop ./tests -c treefmt

tests/legacyPackages/flake.nix (1)

20-24: Consider enabling the error-handling test cases.

The commented-out fail1 and fail2 cases would provide valuable test coverage for error conditions. The FIXME indicates these don't work with nix flake check yet.

Would you like me to help investigate why these test cases aren't working, or should this be tracked separately?

tests/flake.nix (2)

3-4: Document the custom Nix dependency.

The FIXME comment indicates this uses a custom Nix fork with flake-schemas support. Consider documenting this requirement in the README or test documentation so developers understand why the regular Nix won't work yet.


56-56: Document or remove the --legacy flag.

The --legacy flag is used in the nix flake show command. Document what this flag does and why it's needed for the test, or verify if it's still necessary with the custom Nix fork being used.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 26b5002 and d68d191.

⛔ Files ignored due to path filters (6)
  • tests/checks/flake.lock is excluded by !**/*.lock
  • tests/flake.lock is excluded by !**/*.lock
  • tests/legacyPackages/flake.lock is excluded by !**/*.lock
  • tests/nixos/flake.lock is excluded by !**/*.lock
  • tests/packages/flake.lock is excluded by !**/*.lock
  • tests/schemas/flake.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • .github/workflows/check.yml (1 hunks)
  • .gitignore (1 hunks)
  • README.md (1 hunks)
  • flake.nix (1 hunks)
  • tests/checks.json (1 hunks)
  • tests/checks/flake.nix (1 hunks)
  • tests/flake.nix (1 hunks)
  • tests/legacyPackages.json (1 hunks)
  • tests/legacyPackages/flake.nix (1 hunks)
  • tests/nixos.json (1 hunks)
  • tests/nixos/flake.nix (1 hunks)
  • tests/packages.json (1 hunks)
  • tests/packages/flake.nix (1 hunks)
  • tests/schemas.check-err (1 hunks)
  • tests/schemas.json (1 hunks)
  • tests/schemas/flake.nix (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.18.1)
README.md

67-67: Fenced code blocks should have a language specified

(MD040, fenced-code-language)


72-72: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: flake-check
🔇 Additional comments (16)
.gitignore (1)

1-1: Standard editor backup pattern looks good.

The *~ pattern appropriately targets editor backup files (common in Vim and Emacs), aligning with project hygiene best practices for regression test infrastructure.

Note: Ensure a trailing newline is present at the end of the file, as per standard .gitignore conventions.

.github/workflows/check.yml (1)

20-22: LGTM!

The workflow correctly switches from formatting validation to running the new test suite. The -L flag will provide detailed build logs, which is helpful for debugging test failures in CI.

flake.nix (1)

182-182: LGTM! Improved semantic accuracy.

Changing the descriptor from "package" to "formatter" better reflects the actual purpose of formatter outputs. This aligns with how other schema types (e.g., "app", "template", "CI test") use specific descriptors rather than generic ones.

tests/schemas.json (1)

1-22: LGTM! Well-structured test fixture.

This test data correctly models the expected schema inventory output format, including the nested children structure and metadata fields like what, shortDescription, and leaf. The schemas.unknown entry is a good addition for testing handling of unrecognized schema types.

tests/legacyPackages/flake.nix (1)

1-18: LGTM! Comprehensive test coverage.

The test flake effectively covers key legacyPackages scenarios:

  • Direct package references
  • Recursive derivation enumeration with recurseForDerivations
  • Non-recursive attribute sets
tests/schemas/flake.nix (1)

1-34: LGTM! Clever test design for validation checks.

This test flake effectively validates the schema evaluation check mechanism. The evalChecks.isValidValue condition (fooDef.value != 456) is deliberately designed to fail for foo.xyzzy, which corresponds to the expected error message in tests/schemas.check-err. This ensures the validation framework correctly catches and reports failed checks.

tests/schemas.check-err (1)

1-1: LGTM! Expected error message for validation test.

This expected error output correctly corresponds to the failing evalChecks.isValidValue condition in tests/schemas/flake.nix (line 19), where foo.xyzzy has value = 456.

tests/nixos.json (1)

1-14: LGTM! NixOS configuration test fixture.

The test data correctly models the expected output structure for NixOS configurations. Note that the derivationName includes a date-based version component (20251022), which may require updates if the nixpkgs version is changed in the corresponding test flake.

tests/packages.json (1)

1-22: LGTM! Well-structured test fixture.

The JSON structure correctly represents a packages flake output with architecture-specific entries and appropriate metadata fields (derivationName, shortDescription, what, leaf).

tests/checks.json (1)

1-22: LGTM! Appropriate test fixture for checks output.

The structure correctly represents a checks flake output, with the "what" field appropriately set to "CI test" to distinguish it from package outputs.

tests/legacyPackages.json (1)

1-43: LGTM! Comprehensive test fixture for nested package structures.

This fixture appropriately tests the more complex legacyPackages output type with nested attribute sets (pythonPackages), mixed types (package and unknown), and the recurseForDerivations convention.

tests/packages/flake.nix (1)

1-10: Consistent test flake structure.

This test flake follows the same pattern as checks/flake.nix, appropriately exposing packages instead of checks. The same flake.lock verification concern applies here.

tests/flake.nix (2)

16-29: LGTM! Clean formatting check implementation.

The formatting check correctly uses treefmt with nixfmt-tree and serves double duty as the default dev shell, which is a nice ergonomic choice.


52-69: Retract the review comment—schemas.check-err exists in the test suite.

The review claims "no such files are included in this PR," but tests/schemas.check-err exists and handles expected error output for the schemas test. Of the 5 test files (checks, legacyPackages, nixos, packages, schemas), only schemas has an error expectation file—which is correct. The loop logic properly enforces this: tests without .check-err files must pass, and schemas will compare actual errors against its .check-err file. No changes needed.

Likely an incorrect or invalid review comment.

tests/nixos/flake.nix (1)

1-19: The flake.lock file already exists and is valid.

The review comment incorrectly claims the file is missing. The file tests/nixos/flake.lock exists in the repository (698 bytes) and contains properly formatted JSON with valid nixpkgs lock metadata. The reference in tests/flake.nix correctly reads this file via builtins.readFile ./nixos/flake.lock. No changes are required.

Likely an incorrect or invalid review comment.

tests/checks/flake.nix (1)

1-10: No issues found. Lock files are properly committed and the test setup is correct.

Verification confirms that tests/checks/flake.lock exists in the repository and is part of the active test harness (confirmed via tests/checks.json). The --offline mode in tests/flake.nix (lines 56, 59) is specifically designed to work with pre-existing lock files, which are committed to the repository. This is the correct architectural approach since --offline mode cannot generate lock files without network access. The original concern is already resolved by the current design.

Comment thread tests/flake.nix Resolved
Comment on lines +20 to +24
# FIXME: doesn't work with `nix flake check` yet.
#legacyPackages.x86_64-linux.fail1 =
# assert false;
# 123;
#legacyPackages.x86_64-linux.fail2 = throw "not supported";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once nix flake check is fixed to support this, is this expected to fail similar to the failed "schema check" stuff (i.e. tests/schemas.check-err)?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants