Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .github/workflows/Ci.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: npm run lint

- name: Test
run: npm test
run: npm run test:ci

- name: Upload coverage report
uses: actions/upload-artifact@v4
Expand All @@ -46,17 +46,41 @@ jobs:
path: coverage/
retention-days: 30

- name: npm audit — fail on high or critical
run: npm audit --audit-level=high --omit=dev

- name: Trivy — filesystem scan
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: fs
scan-ref: .
format: sarif
output: trivy-results.sarif
severity: HIGH,CRITICAL
exit-code: '1'
ignore-unfixed: true
trivyignores: .trivyignore.yaml

- name: Upload Trivy SARIF results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: trivy-results.sarif
category: trivy

- name: Hadolint — Dockerfile scan
uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: ./Dockerfile
format: sarif
output-file: hadolint-results.sarif
no-fail: true
no-fail: false
failure-threshold: error

- name: Upload Hadolint SARIF results
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: hadolint-results.sarif
category: hadolint
wait-for-processing: true
wait-for-processing: true
File renamed without changes.
File renamed without changes.
34 changes: 27 additions & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,36 @@ Semantic Release with conventional commits. Always use this format:

---

## Testing & QA

| Tool | Purpose | Notes |
|------|---------|-------|
| Jest | Unit + integration | `--runInBand` is required (SQLite tests share a single process); enforced via npm scripts |
| Supertest | HTTP integration | Used in `tests/integration/*.test.js` |
| ESLint flat config | Lint | Rules: `eqeqeq` (with `null` exception), `prefer-const`, `no-var`, `no-throw-literal`, `prefer-template`, `object-shorthand`, etc. |
| 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. |
Comment on lines +175 to +177

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.

**npm scripts:**
- `npm test` — fast unit + integration, no coverage
- `npm run test:unit` — unit only
- `npm run test:integration` — integration only
- `npm run test:ci` — what CI runs: `--coverage --ci`, gated by thresholds in `jest.config.js` (statements/lines/functions ≥ 90%, branches ≥ 75%)
- `npm run test:watch` — TDD loop
- `npm run lint`

When adding a test, prefer `tests/unit/` for pure-logic and a single repository, `tests/integration/` when you need the full Express app via Supertest. Keep `--runInBand` — SQLite + Jest will deadlock if you parallelize.

---

## GitHub Actions

The following workflows are in place (updated versions produced in last session):
The following workflows are in place:

- `ci.yml` — Lint and test on all PRs. Uses `actions/setup-node` to pin Node version, npm caching enabled.
- `release.yml` — Semantic release + Docker build and push to `ghcr.io/gogorichielab/ppcollection` on merge to main
- `hadolint.yml` — Dockerfile linting, `no-fail: false` so bad Dockerfiles block PRs
- `Auto-stale.yml` — Marks issues stale after 60 days, closes after 7 more
- `Auto-cleanup-feature-branches.yml` — Deletes merged codex/* and copilot/* branches after 2 days
- `codeql.yml` — Security scanning on PRs and weekly (new, added this session)
- `ci.yml` — On every PR to main: lint, test (with `--coverage --ci`), `npm audit` (high+ fails), Trivy fs scan (HIGH/CRITICAL fails, SARIF uploaded), Hadolint Dockerfile scan (`no-fail: false` — bad Dockerfiles block PRs; rule suppressions go inline in the Dockerfile via `# hadolint ignore=…`).
- `release.yml` — On merge to main: semantic-release dry-run produces a release PR; once merged, builds and pushes the multi-arch Docker image to `ghcr.io/gogorichielab/ppcollection` and tags the GitHub release.
- `maintenance.yml` — Daily 04:00 UTC + workflow_dispatch. Two jobs: (1) `actions/stale@v9` marks issues stale after 60 days / PRs after 30, closes after 7. (2) Deletes `codex/*` and `copilot/*` branches whose PR was merged ≥ 2 days ago.

---

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FROM ${NODE_IMAGE} AS deps

WORKDIR /app

# Keep native build dependencies in this stage only.
# Native build deps live only in this transient stage.
# hadolint ignore=DL3018
RUN apk upgrade --no-cache \
&& apk add --no-cache python3 make g++

Expand Down
22 changes: 21 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@ module.exports = [
sourceType: 'commonjs',
globals: {
...globals.node,
...globals.jest,
},
},
rules: {
'no-console': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
eqeqeq: ['error', 'always', { null: 'ignore' }],
'prefer-const': 'error',
'no-var': 'error',
'no-throw-literal': 'error',
'no-return-await': 'error',
'no-implicit-coercion': ['error', { boolean: false, number: true, string: true }],
'no-param-reassign': 'error',
curly: ['error', 'multi-line'],
'prefer-template': 'error',
'object-shorthand': 'error',
},
},
{
files: ['tests/**/*.js'],
languageOptions: {
globals: {
...globals.jest,
},
},
rules: {
'no-param-reassign': 'off',
},
},
{
Expand Down
17 changes: 16 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
module.exports = {
testEnvironment: 'node',
roots: ['<rootDir>/tests'],
testMatch: ['**/*.test.js']
testMatch: ['**/*.test.js'],
clearMocks: true,
restoreMocks: true,
coverageReporters: ['text-summary', 'lcov', 'html'],
collectCoverageFrom: [
'src/**/*.js',
'!src/server.js'
],
coverageThreshold: {
global: {
statements: 90,
branches: 75,
functions: 90,
lines: 90
}
}
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
"main": "src/server.js",
"scripts": {
"start": "node src/server.js",
"test": "jest --runInBand --coverage",
"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.
"test:ci": "jest --runInBand --coverage --ci",
"lint": "eslint src tests"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion src/features/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function createAuthService({ adminUser, settingsRepository }) {
return false;
}

return await bcrypt.compare(password, storedHash);
return bcrypt.compare(password, storedHash);
},

async changePassword(currentPassword, newPassword) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/firearms/firearms.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function createFirearmsController(firearmsService) {
downloadTemplate(req, res) {
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename="firearms-import-template.csv"');
res.send(CSV_HEADERS.join(',') + '\n');
res.send(`${CSV_HEADERS.join(',')}\n`);
},

importCsv(req, res) {
Expand Down
8 changes: 4 additions & 4 deletions src/public/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
return Object.entries(facets).every(([facet, values]) => {
if (!values.length) return true;

const rowValue = (row.getAttribute('data-' + facet) || '').toLowerCase();
const rowValue = (row.getAttribute(`data-${facet}`) || '').toLowerCase();

return values.includes(rowValue);
});
Expand Down Expand Up @@ -175,7 +175,7 @@
purchase_date.includes(searchTerm);
} else {
// Search in specific field
const fieldValue = (row.getAttribute('data-' + field) || '').toLowerCase();
const fieldValue = (row.getAttribute(`data-${field}`) || '').toLowerCase();
matchesSearch = fieldValue.includes(searchTerm);
}

Expand Down Expand Up @@ -212,8 +212,8 @@
const rowsArray = Array.from(tbody.rows);

rowsArray.sort((a, b) => {
const aValue = (a.getAttribute('data-' + key) || '').toLowerCase();
const bValue = (b.getAttribute('data-' + key) || '').toLowerCase();
const aValue = (a.getAttribute(`data-${key}`) || '').toLowerCase();
const bValue = (b.getAttribute(`data-${key}`) || '').toLowerCase();

if (aValue < bValue) return -1;
if (aValue > bValue) return 1;
Expand Down
Loading