Skip to content

qa: tighten lint/jest, gate CI with audit + Trivy + CodeQL, refresh docs - #347

Merged
gogorichie merged 8 commits into
mainfrom
claude/qa-cleanup-pass-04282026
Apr 28, 2026
Merged

gogorichie merged 8 commits into
mainfrom
claude/qa-cleanup-pass-04282026

Conversation

@gogorichie

Copy link
Copy Markdown
Member

Summary

QA tooling cleanup pass — separated out of PR #344 (the security audit) so the two scopes don't share a review.

Lint

  • ESLint flat config gains: eqeqeq (with null exception so == null checks stay), prefer-const, no-var, no-throw-literal, no-return-await, no-implicit-coercion (boolean exempt), no-param-reassign (off in tests), prefer-template, object-shorthand, curly multi-line.
  • Jest globals moved into a tests/** override so test globals don't leak into src.
  • Source fixes that fell out: dropped redundant await on bcrypt.compare, swapped a handful of + concats to template literals.

Jest

  • clearMocks: true, restoreMocks: true.
  • coverageReporters: ['text-summary', 'lcov', 'html'].
  • collectCoverageFrom scoped to src/**.
  • Global thresholds set: statements/lines/functions ≥ 90%, branches ≥ 75%. Measured at 91.7% / 91.7% / 92.9% / 78.4% on this branch.

npm scripts

  • Split into test, test:unit, test:integration, test:watch, test:ci. npm test no longer pays coverage cost; CI uses test:ci.

CI

  • npm audit --audit-level=high --omit=dev gate (fails build on high+ runtime CVEs).
  • Trivy fs scan: aquasecurity/trivy-action@v0.36.0, severity HIGH,CRITICAL, exit-code: 1, --ignore-unfixed, honors .trivyignore.yaml, SARIF uploaded to the security tab.
  • Hadolint flipped from no-fail: true to no-fail: false — the previous setting silently ignored Dockerfile findings despite the SARIF upload, contradicting what CLAUDE.md already documented.
  • New codeql.yml — security-and-quality query suite on PRs to main, pushes to main, and weekly Monday 06:17 UTC.
  • Workflow filenames lowercased (Ci.yml → ci.yml, etc.) to match the GitHub convention and CLAUDE.md.

Docs

  • CLAUDE.md "GitHub Actions" section listed four workflow files that don't exist (hadolint.yml, Auto-stale.yml, Auto-cleanup-feature-branches.yml, codeql.yml); replaced with the real four and what each one does.
  • New "Testing & QA" section documents npm scripts, the --runInBand SQLite constraint, and the coverage thresholds — so a future contributor knows why parallel-run breaks and what number to keep coverage above.

Risk

All four findings audited at low risk of breaking change. The two configs that can break CI (coverage thresholds, audit gates) were measured against the current state first: 0 high-severity runtime CVEs, coverage already exceeds every threshold by 3–17 pp.

Test plan

  • npm run lint — clean
  • npm test — 88/88 passing
  • npm run test:ci — 88/88 passing, all coverage thresholds met
  • npm audit --audit-level=high --omit=dev — 0 vulnerabilities
  • All four workflow YAMLs parse
  • On first CI run after merge, verify CodeQL, Trivy, npm audit, and Hadolint all execute and post SARIF where applicable

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn


Generated by Claude Code

claude added 4 commits April 28, 2026 01:48
ESLint: add eqeqeq (with `null` exception so `== null` checks stay),
prefer-const, no-var, no-throw-literal, no-return-await,
no-implicit-coercion (boolean exempt), no-param-reassign (off in
tests), prefer-template, object-shorthand, curly multi-line. Move
jest globals into a tests/** override block so tests don't leak into
src.

Jest: enable clearMocks + restoreMocks, expose lcov/html/text-summary
coverage reporters, scope collectCoverageFrom to src/**, and gate the
suite with global thresholds (statements/lines/functions ≥ 90%,
branches ≥ 75%) measured at 91.6% / 92% / 93% / 79.1% on this commit.

npm scripts: split `test` into `test`, `test:unit`, `test:integration`,
`test:ci` (the only one that runs --coverage --ci). Local `npm test`
stops paying coverage cost.

Source fixes from the new lint rules: drop redundant await on a
bcrypt.compare return, switch a handful of '+' string concats to
template literals.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
CI workflow gains three security gates that previously had no enforcement:
  - npm audit --audit-level=high --omit=dev (fails on high/critical
    runtime CVEs; dev deps excluded since they don't ship)
  - Trivy fs scan, severity HIGH/CRITICAL, exit-code 1, with
    --ignore-unfixed to avoid noise from upstream-pending advisories.
    Honors .trivyignore.yaml. SARIF results upload to the security tab.
  - Hadolint flips no-fail to false so bad Dockerfiles now actually
    block PRs (the previous setting silently ignored findings despite
    the SARIF upload). Matches what CLAUDE.md already claimed.

CI test step swaps `npm test` for `npm run test:ci` so coverage
thresholds gate the build.

New codeql.yml runs the security-and-quality query suite on PRs to
main, pushes to main, and weekly Monday 06:17 UTC.

Workflow filenames lowercased (Ci.yml -> ci.yml, etc.) to match the
GitHub convention and CLAUDE.md.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
The GitHub Actions list referenced four workflow files that don't
exist (hadolint.yml, Auto-stale.yml, Auto-cleanup-feature-branches.yml,
codeql.yml) and described hadolint as no-fail: false when reality was
no-fail: true. Replace with the actual four workflows and what each
one does.

Adds a Testing & QA section that documents npm scripts, the
--runInBand SQLite constraint, and the coverage thresholds — so a
future contributor knows why parallel-run breaks and what number to
keep coverage above.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
@github-advanced-security

Copy link
Copy Markdown
Contributor

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

claude added 4 commits April 28, 2026 14:57
Two CI failures on PR #347:

1. The repo has GitHub's default Code Scanning setup enabled, which
   conflicts with an advanced workflow file. CodeQL refused to upload
   SARIF: "CodeQL analyses from advanced configurations cannot be
   processed when the default setup is enabled." The default setup is
   already running JS analysis successfully, so the custom workflow is
   redundant. Delete codeql.yml.

2. Hadolint with no-fail: false surfaced DL3018 (pin versions in
   apk add) on the deps stage. Pinning Alpine apk patch versions is
   impractical — Alpine doesn't keep older patch versions in its repo,
   so a pinned line breaks the build the next time upstream rolls. The
   deps stage is transient (multi-stage build), so no apk packages
   reach the runtime image. Add .hadolint.yaml to ignore DL3018 with
   a comment explaining why.

CLAUDE.md updated: CodeQL row notes the default setup; ci.yml row
mentions the new .hadolint.yaml ignore file.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
The action wasn't auto-detecting the .hadolint.yaml in repo root, so
DL3018 (apk pin versions) still failed the build despite the ignore
file. Pass `config: ./.hadolint.yaml` so the rule list applies.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
The hadolint-action's `config:` input resolves relative paths against
the container root, not the workspace, so .hadolint.yaml at the repo
root wasn't picked up. Move the suppression to an inline `# hadolint
ignore=DL3018` comment immediately above the offending RUN — same
intent, no action-config plumbing.

Drop .hadolint.yaml and the now-unused `config:` flag from ci.yml.
Update CLAUDE.md note accordingly.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
Even with the inline `# hadolint ignore=DL3018` comment, the
hadolint-action wrapper kept failing on the warning. The action's
default failure-threshold is `info`, so any warning blocks. Set it to
`error` so only actual error-severity Dockerfile issues block PRs;
warnings still appear in the uploaded SARIF and in the security tab,
they just don't block.

Trim the inline comment block in the Dockerfile to a one-liner — the
rationale lives in this commit, not in the Dockerfile.

https://claude.ai/code/session_016wAgkh3Z8mcM1ZjGVKTKCn
@gogorichie
gogorichie marked this pull request as ready for review April 28, 2026 15:11
Copilot AI review requested due to automatic review settings April 28, 2026 15:11
@gogorichie
gogorichie merged commit b55e6ac into main Apr 28, 2026
8 checks passed

Copilot AI 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.

Pull request overview

This PR tightens the project’s QA posture by expanding ESLint/Jest configuration, restructuring npm test scripts, and hardening CI with additional security gates and updated documentation.

Changes:

  • Strengthen ESLint flat config rules and scope Jest globals to tests/**.
  • Split Jest scripts (unit/integration/CI) and enforce coverage thresholds in CI via test:ci.
  • Add/refresh CI workflows (audit + Trivy + Hadolint SARIF uploads), plus new Release and Maintenance workflows and updated CLAUDE.md documentation.

Reviewed changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/public/js/search.js Minor string concatenation cleanup (template literals for data-attrs).
src/features/firearms/firearms.controller.js Minor CSV template response formatting cleanup.
src/features/auth/auth.service.js Removes redundant return await for bcrypt compare.
package.json Splits test scripts into unit/integration/CI; makes npm test faster (no coverage).
jest.config.js Enables mock cleanup, coverage reporters, collection scope, and global thresholds.
eslint.config.js Adds stricter rules and moves Jest globals into a tests/** override.
Dockerfile Adjusts comments and adds an inline hadolint suppression.
CLAUDE.md Documents new Testing & QA and updates the workflows list/behavior notes.
.github/workflows/ci.yml Runs test:ci, gates with npm audit, adds Trivy + Hadolint scans with SARIF upload.
.github/workflows/release.yml Adds automated release PR + publish/tag/release + docker build/push + optional Pages deploy.
.github/workflows/maintenance.yml Adds stale management and merged branch cleanup automation.
Comments suppressed due to low confidence (2)

.github/workflows/ci.yml:69

  • The Upload Trivy SARIF step is if: always(), but if an earlier step fails (e.g., tests or npm audit) the Trivy scan step will be skipped, so trivy-results.sarif won't exist and this upload can fail/noise. Consider guarding the upload with a file existence check (e.g., hashFiles(...)) or making the scan step run under if: always()/continue-on-error and gating later.
    .github/workflows/ci.yml:86
  • The Upload Hadolint SARIF step is if: always() but the Hadolint scan step itself will be skipped if Trivy fails (or any prior step fails), leaving no hadolint-results.sarif to upload. Either guard this upload on the file existing / step outcome, or make the Hadolint scan run even when earlier steps fail so SARIF is consistently produced.

Comment thread package.json
"test": "jest --runInBand",
"test:unit": "jest --runInBand tests/unit",
"test:integration": "jest --runInBand tests/integration",
"test:watch": "jest --watch",

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

npm run test:watch runs Jest without --runInBand, but the repo docs (and the other test scripts here) indicate --runInBand is required due to SQLite tests sharing a single process. Consider adding --runInBand to the watch script as well (or narrowing watch to unit tests only) so the documented constraint is consistently enforced.

Suggested change
"test:watch": "jest --watch",
"test:watch": "jest --runInBand --watch",

Copilot uses AI. Check for mistakes.
Comment thread CLAUDE.md
Comment on lines +175 to +177
| Trivy + `.trivyignore.yaml` | Filesystem CVE scan in CI | Fails on HIGH/CRITICAL fixable issues |
| `npm audit` | Runtime dep CVE check in CI | `--audit-level=high --omit=dev` |
| CodeQL | SAST | Provided by GitHub's default Code Scanning setup (configured in repo Settings → Code security), not a workflow file in this repo. Runs on PRs and weekly. |

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

PR description mentions adding a new codeql.yml workflow, but this branch doesn't contain .github/workflows/codeql.yml and this doc now states CodeQL is handled via GitHub's default Code Scanning setup (not a workflow file). Please align the PR description and/or add the intended workflow so reviewers/users aren’t confused about how CodeQL is configured.

Copilot uses AI. Check for mistakes.
@github-actions

github-actions Bot commented May 2, 2026

Copy link
Copy Markdown
Contributor

This PR is included in version 2.0.0 🎉

@gogorichie
gogorichie deleted the claude/qa-cleanup-pass-04282026 branch May 13, 2026 01:59
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.

4 participants