Skip to content

feat(nix-checks): add ent-codegen-drift-check + ent-lint-check - #1221

Merged
kalbasit merged 3 commits into
mainfrom
feat-nix-checks-ent-codegen-drift-lint
May 23, 2026
Merged

kalbasit merged 3 commits into
mainfrom
feat-nix-checks-ent-codegen-drift-lint

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

Adds two new derivations to the nix checks tree, both of which feed into
nix flake check:

  • ent-codegen-drift-check materializes the source tree, runs
    go generate ./ent/..., and fails the build if any committed file
    under ./ent differs after regeneration. Uses proxyVendor = true
    because Ents tool dependency (entgo.io/ent/cmd/ent) is not vendored.
  • ent-lint-check builds and runs cmd/ent-lint --root . and fails
    if any [FAIL] lines appear in the output.

Drive-by fixes:

  • Update vendor hash to match the post-cleanup go.sum (pre-existing
    drift after the sqlc removal).
  • Drop the now-broken cp -r db $out/share/ncps/db from postInstall;
    the db/ tree no longer exists.
  • Add ent/*.go, ent/<generated-pkg>/**/*.go, and
    migrations/**/*.sql to treefmt-nixs global excludes so the
    formatter cannot fight the Ent generator or invalidate atlas.sum.

Marks tasks 13.1 and 13.2 complete in the migrate-to-ent-and-atlas
change.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels May 21, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces CI checks for Ent codegen drift and linting, updates the Nix package's vendor hash, and excludes generated Ent and Atlas files from the formatter. Feedback was provided to optimize the CI check derivations by removing unnecessary inherited dependencies and to improve the formatter's exclusion patterns for better maintainability and to avoid accidentally excluding hand-written files like ent/generate.go.

Comment thread nix/checks/flake-module.nix Resolved
Comment thread nix/checks/flake-module.nix Resolved
Comment thread nix/formatter/flake-module.nix Resolved
This was referenced May 21, 2026
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from 74f8df5 to bae8e7f Compare May 22, 2026 21:42
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from b61c139 to da2e2de Compare May 22, 2026 21:42
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from bae8e7f to 74f0b82 Compare May 22, 2026 21:54
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from da2e2de to 2a5b056 Compare May 22, 2026 21:54
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from 74f0b82 to 3f8d9aa Compare May 22, 2026 23:02
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from 2a5b056 to b58ba2f Compare May 22, 2026 23:02
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from 3f8d9aa to 6df93cb Compare May 22, 2026 23:16
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from b58ba2f to 03b777f Compare May 22, 2026 23:16
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from 6df93cb to f540788 Compare May 22, 2026 23:28
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from 03b777f to 7cf61e7 Compare May 22, 2026 23:28
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit
kalbasit force-pushed the chore-delete-sqlc-dbmate-filesystem-and-nix branch from f540788 to bd57a59 Compare May 22, 2026 23:54
@kalbasit
kalbasit force-pushed the feat-nix-checks-ent-codegen-drift-lint branch from 7cf61e7 to 56eadca Compare May 22, 2026 23:54
kalbasit added a commit that referenced this pull request May 22, 2026
ent/generate.go is hand-written (carries the //go:generate directive)
but the broad ent/*.go exclusion swept it into the codegen-only group.
Add an explicit !ent/generate.go negation so it stays formattable
without re-introducing diff loops against the codegen drift check.

Addresses gemini-code-assist comment on PR #1221 (PRRT_kwDONV6tZs6D3zlq).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@kalbasit

Copy link
Copy Markdown
Owner Author

Automated stack merge failed during the rebase step. The merge-stack label has been removed from all PRs in the stack. Please resolve conflicts locally, push, and re-apply the label on the top-most PR to retry. Run: https://github.com/kalbasit/ncps/actions/runs/26326665317

Adds two new derivations to the nix checks tree, both of which feed into
`nix flake check`:

- `ent-codegen-drift-check` materializes the source tree, runs
  `go generate ./ent/...`, and fails the build if any committed file
  under `./ent` differs after regeneration. Uses `proxyVendor = true`
  because Ents `tool` dependency (entgo.io/ent/cmd/ent) is not vendored.
- `ent-lint-check` builds and runs `cmd/ent-lint --root .` and fails
  if any `[FAIL]` lines appear in the output.

Drive-by fixes:

- Update vendor hash to match the post-cleanup go.sum (pre-existing
  drift after the sqlc removal).
- Drop the now-broken `cp -r db $out/share/ncps/db` from postInstall;
  the `db/` tree no longer exists.
- Add `ent/*.go`, `ent/<generated-pkg>/**/*.go`, and
  `migrations/**/*.sql` to treefmt-nixs global excludes so the
  formatter cannot fight the Ent generator or invalidate atlas.sum.

Marks tasks 13.1 and 13.2 complete in the migrate-to-ent-and-atlas
change.

@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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nix/checks/flake-module.nix`:
- Around line 92-97: The buildPhase for the ent-lint-check currently runs the
pipeline "./ent-lint --root . | tee ent-lint.out" without pipefail, which can
hide a failing ent-lint exit status; update the ent-lint-check buildPhase (the
pipeline invocation in the buildPhase) to enable pipefail before running the
pipeline (e.g. run "set -o pipefail" in the buildPhase shell context) so the
pipeline returns a non-zero status when ent-lint fails and the derivation fails
immediately.
- Around line 69-72: Update the ent codegen and lint checks so untracked
generated files and lint failures can't be masked: after running git diff
--exit-code ./ent/ also check for untracked files under ent (e.g., run git
ls-files --others --exclude-standard -- ent/ and fail if any output) and combine
both results to return non-zero when codegen drift exists; and ensure the
ent-lint invocation preserves failures by enabling pipefail (e.g., set -o
pipefail before running ./ent-lint --root . | tee ent-lint.out or run the lint
command and capture its exit status directly) so any non-zero exit from
./ent-lint causes the check to fail even if tee succeeds.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d3c9502e-fdb7-42e0-9f31-a85f1d8248c6

📥 Commits

Reviewing files that changed from the base of the PR and between 2e5330d and 8da44e9.

📒 Files selected for processing (3)
  • nix/checks/flake-module.nix
  • nix/formatter/flake-module.nix
  • openspec/changes/migrate-to-ent-and-atlas/tasks.md

Comment thread nix/checks/flake-module.nix Resolved
Comment thread nix/checks/flake-module.nix Resolved

@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.

♻️ Duplicate comments (2)
nix/checks/flake-module.nix (2)

92-97: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

ent-lint failures can be masked by tee without pipefail.

The pipeline can return success from tee even when ./ent-lint fails.

💡 Suggested fix
+              set -o pipefail
               ./ent-lint --root . | tee ent-lint.out
#!/bin/bash
set -e

echo "Without pipefail:"
if ( false | tee /dev/null >/dev/null ); then
  echo "masked failure"
else
  echo "pipeline failed"
fi

set -o pipefail
echo "With pipefail:"
if ( false | tee /dev/null >/dev/null ); then
  echo "pipeline succeeded"
else
  echo "producer failure propagated"
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nix/checks/flake-module.nix` around lines 92 - 97, The ent-lint invocation
piped into tee can mask failures because the shell may report tee's exit status
instead of ent-lint's; ensure the producer failure is propagated by enabling
pipefail or by checking ent-lint's exit explicitly. Update the block that runs
"./ent-lint --root . | tee ent-lint.out" to either run "set -o pipefail" earlier
in the script (so the pipeline fails if ent-lint fails) or replace the pipeline
with a command that captures the exit status (e.g., run "./ent-lint --root . |
tee ent-lint.out; lint_status=${PIPESTATUS[0]}; if [ \"$lint_status\" -ne 0 ];
then echo 'ent-lint failed' >&2; exit 1; fi"), referencing the "./ent-lint
--root .", "tee ent-lint.out", and the subsequent "grep -q '^\[FAIL\]'
ent-lint.out" logic so the rest of the check behaves correctly.

69-72: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Codegen drift check misses untracked generated files.

git diff --exit-code ./ent/ won’t catch newly created untracked files under ent/, so drift can false-pass.

💡 Suggested fix
-              if ! git diff --exit-code ./ent/; then
+              if [ -n "$(git status --porcelain --untracked-files=all -- ./ent/)" ]; then
+                git diff -- ./ent/ || true
                 echo "ent/ codegen is out of date — run 'go generate ./ent/...' and commit the result." >&2
                 exit 1
               fi
#!/bin/bash
set -euo pipefail
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
cd "$tmp"

git init -q
mkdir -p ent
printf '%s\n' '// baseline' > ent/a.go
git add -A
git -c [email protected] -c user.name=ci commit -q -m baseline

printf '%s\n' '// newly generated' > ent/b.go

echo "git diff result:"
if git diff --exit-code -- ./ent/ >/dev/null; then
  echo "PASS (diff missed untracked file)"
else
  echo "FAIL (diff caught change)"
fi

echo "git status porcelain:"
git status --porcelain --untracked-files=all -- ./ent/
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nix/checks/flake-module.nix` around lines 69 - 72, The check uses "if ! git
diff --exit-code ./ent/; then" which misses newly created untracked files;
replace that condition with a git status porcelain check that includes untracked
files (for example test whether "git status --porcelain --untracked-files=all --
./ent/" returns non-empty) and fail when it does, keeping the existing error
message and exit code so any modified or untracked files under ent/ cause the
same error path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@nix/checks/flake-module.nix`:
- Around line 92-97: The ent-lint invocation piped into tee can mask failures
because the shell may report tee's exit status instead of ent-lint's; ensure the
producer failure is propagated by enabling pipefail or by checking ent-lint's
exit explicitly. Update the block that runs "./ent-lint --root . | tee
ent-lint.out" to either run "set -o pipefail" earlier in the script (so the
pipeline fails if ent-lint fails) or replace the pipeline with a command that
captures the exit status (e.g., run "./ent-lint --root . | tee ent-lint.out;
lint_status=${PIPESTATUS[0]}; if [ \"$lint_status\" -ne 0 ]; then echo 'ent-lint
failed' >&2; exit 1; fi"), referencing the "./ent-lint --root .", "tee
ent-lint.out", and the subsequent "grep -q '^\[FAIL\]' ent-lint.out" logic so
the rest of the check behaves correctly.
- Around line 69-72: The check uses "if ! git diff --exit-code ./ent/; then"
which misses newly created untracked files; replace that condition with a git
status porcelain check that includes untracked files (for example test whether
"git status --porcelain --untracked-files=all -- ./ent/" returns non-empty) and
fail when it does, keeping the existing error message and exit code so any
modified or untracked files under ent/ cause the same error path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 92d5739f-9f75-43db-8144-75e0fd8046bc

📥 Commits

Reviewing files that changed from the base of the PR and between 8da44e9 and 875df41.

📒 Files selected for processing (2)
  • .github/workflows/ci.yml
  • nix/checks/flake-module.nix

@codecov

codecov Bot commented May 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 5.50%. Comparing base (2e5330d) to head (875df41).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #1221   +/-   ##
=====================================
  Coverage   5.50%   5.50%           
=====================================
  Files          6       6           
  Lines        400     400           
=====================================
  Hits          22      22           
  Misses       374     374           
  Partials       4       4           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

enhancement New feature or request go Pull requests that update go code merge-stack size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant