Repository navigation
Conversation
WalkthroughThis 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
Sequence DiagramsequenceDiagram
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
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
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Comment |
753a27a to
7ef3f3b
Compare
There was a problem hiding this comment.
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 ./testsTo apply formatting, run the following:
-+bash
nix develop ./tests -c treefmttests/legacyPackages/flake.nix (1)
20-24: Consider enabling the error-handling test cases.The commented-out
fail1andfail2cases would provide valuable test coverage for error conditions. The FIXME indicates these don't work withnix flake checkyet.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
--legacyflag is used in thenix flake showcommand. 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
⛔ Files ignored due to path filters (6)
tests/checks/flake.lockis excluded by!**/*.locktests/flake.lockis excluded by!**/*.locktests/legacyPackages/flake.lockis excluded by!**/*.locktests/nixos/flake.lockis excluded by!**/*.locktests/packages/flake.lockis excluded by!**/*.locktests/schemas/flake.lockis 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
.gitignoreconventions..github/workflows/check.yml (1)
20-22: LGTM!The workflow correctly switches from formatting validation to running the new test suite. The
-Lflag 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, andleaf. Theschemas.unknownentry 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.isValidValuecondition (fooDef.value != 456) is deliberately designed to fail forfoo.xyzzy, which corresponds to the expected error message intests/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.isValidValuecondition intests/schemas/flake.nix(line 19), wherefoo.xyzzyhasvalue = 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
derivationNameincludes 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.lockexists in the repository (698 bytes) and contains properly formatted JSON with valid nixpkgs lock metadata. The reference intests/flake.nixcorrectly reads this file viabuiltins.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.lockexists in the repository and is part of the active test harness (confirmed viatests/checks.json). The--offlinemode intests/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--offlinemode cannot generate lock files without network access. The original concern is already resolved by the current design.
| # 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"; |
There was a problem hiding this comment.
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)?
This adds some basic regression tests for some flake schemas. It runs
nix flake show --jsonandnix flake checkand verifies that the output is as expected.This PR also fixes a wrong
whatattribute for theformatterschema.