Skip to content

Commit bcd8081

Browse files
authored
Merge branch 'main' into alert-autofix-1
2 parents 15f96dd + cb9c08d commit bcd8081

17 files changed

Lines changed: 709 additions & 487 deletions
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Functional Tests
2+
permissions:
3+
contents: read
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
environment:
9+
description: 'Environment to run tests against'
10+
required: true
11+
default: 'dev'
12+
type: choice
13+
options:
14+
- dev
15+
- staging
16+
test_pattern:
17+
description: 'Test pattern to run (optional)'
18+
required: false
19+
default: ''
20+
type: string
21+
22+
jobs:
23+
functional-tests:
24+
environment: ${{ inputs.environment }}
25+
runs-on: ubuntu-latest
26+
timeout-minutes: 30
27+
28+
steps:
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
- name: Setup Node.js
33+
uses: volta-cli/action@v4
34+
35+
- name: Install dependencies
36+
run: npm ci --no-audit
37+
38+
- name: Build project
39+
run: npm run build --if-present
40+
41+
- name: Run functional tests
42+
run: |
43+
if [ -n "${{ inputs.test_pattern }}" ]; then
44+
npm run test:functional -- --reporter=verbose --reporter=github-actions --testNamePattern="${{ inputs.test_pattern }}"
45+
else
46+
npm run test:functional
47+
fi
48+
env:
49+
VITE_ATHENA_CLIENT_ID: ${{ secrets.VITE_ATHENA_CLIENT_ID }}
50+
VITE_ATHENA_CLIENT_SECRET: ${{ secrets.VITE_ATHENA_CLIENT_SECRET }}
51+
VITE_ATHENA_DEPLOYMENT_ID: ${{ secrets.VITE_ATHENA_DEPLOYMENT_ID }}
52+
VITE_ATHENA_AFFILIATE: ${{ secrets.VITE_ATHENA_AFFILIATE }}
53+
VITE_OAUTH_ISSUER: ${{ secrets.VITE_OAUTH_ISSUER }}
54+
55+
- name: Upload test results
56+
if: always()
57+
uses: actions/upload-artifact@v4
58+
with:
59+
name: functional-test-results-${{ inputs.environment }}
60+
path: |
61+
**/*test-results*
62+
**/*coverage*
63+
retention-days: 30
64+
65+
- name: Report test summary
66+
if: always()
67+
run: |
68+
echo "## Functional Test Results" >> $GITHUB_STEP_SUMMARY
69+
echo "- Environment: ${{ inputs.environment }}" >> $GITHUB_STEP_SUMMARY
70+
echo "- Test pattern: ${{ inputs.test_pattern || 'All tests' }}" >> $GITHUB_STEP_SUMMARY
71+
echo "- Status: ${{ job.status }}" >> $GITHUB_STEP_SUMMARY

.github/workflows/nodejs.yml

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,35 @@ on:
88

99
jobs:
1010
build:
11-
environment: dev
1211
runs-on: ubuntu-latest
1312
steps:
14-
- uses: actions/checkout@v4
15-
- uses: volta-cli/action@v4
16-
- run: npm ci --no-audit
17-
- run: npm run lint --if-present
18-
- run: npm run prettier:check --if-present
19-
- run: npm test
20-
env:
21-
VITE_ATHENA_CLIENT_ID: ${{ secrets.VITE_ATHENA_CLIENT_ID }}
22-
VITE_ATHENA_CLIENT_SECRET: ${{ secrets.VITE_ATHENA_CLIENT_SECRET }}
23-
VITE_ATHENA_DEPLOYMENT_ID: ${{ secrets.VITE_ATHENA_DEPLOYMENT_ID }}
24-
VITE_ATHENA_AFFILIATE: ${{ secrets.VITE_ATHENA_AFFILIATE }}
25-
VITE_OAUTH_ISSUER: ${{ secrets.VITE_OAUTH_ISSUER }}
26-
- run: npm run build --if-present
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: volta-cli/action@v4
18+
19+
- name: Install dependencies
20+
run: npm ci --no-audit
21+
22+
- name: Run linting
23+
run: npm run lint --if-present
24+
25+
- name: Check code formatting
26+
run: npm run prettier:check --if-present
27+
28+
- name: Run unit tests
29+
run: npm run test:unit
30+
31+
- name: Build project
32+
run: npm run build --if-present
33+
34+
- name: Upload test results
35+
if: always()
36+
uses: actions/upload-artifact@v4
37+
with:
38+
name: unit-test-results
39+
path: |
40+
**/*test-results*
41+
**/*coverage*
42+
retention-days: 7

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "athena-protobufs"]
2+
path = athena-protobufs
3+
url = https://github.com/crispthinking/athena-protobufs.git

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Pre-commit configuration for athena-nodejs-client
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
repos:
5+
# General file checks
6+
- repo: https://github.com/pre-commit/pre-commit-hooks
7+
rev: v4.5.0
8+
hooks:
9+
- id: trailing-whitespace
10+
- id: end-of-file-fixer
11+
- id: check-yaml
12+
- id: check-added-large-files
13+
- id: check-json
14+
exclude: ^samples/
15+
- id: check-merge-conflict
16+
17+
# Node.js/npm hooks
18+
- repo: local
19+
hooks:
20+
# Run all linting checks
21+
- id: lint-all
22+
name: Lint All (ESLint + Prettier + TypeScript)
23+
entry: npm run lint:all
24+
language: system
25+
pass_filenames: false
26+
always_run: true
27+
28+
# Global settings
29+
default_stages: [pre-commit]
30+
fail_fast: true

README.md

Lines changed: 83 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,79 @@ Athena is a gRPC-based image classification service designed for CSAM (Child Sex
1616

1717
# Contributing
1818

19+
## Code Quality and Pre-commit Hooks
20+
21+
This project uses pre-commit hooks to ensure code quality and consistency. The hooks run linting, formatting, and type checking before each commit.
22+
23+
### Setting up Pre-commit Hooks
24+
25+
1. **Install pre-commit** (if not already installed):
26+
```sh
27+
uvx pre-commit --help
28+
```
29+
Or install globally:
30+
```sh
31+
uv tool install pre-commit
32+
```
33+
34+
2. **Install the hooks**:
35+
```sh
36+
uvx pre-commit install
37+
```
38+
39+
3. **Run all quality checks manually**:
40+
```sh
41+
npm run lint:all
42+
```
43+
44+
### What the Pre-commit Hooks Check
45+
46+
- **ESLint**: Code quality and style issues
47+
- **Prettier**: Code formatting consistency
48+
- **TypeScript**: Type checking and compilation
49+
- **File checks**: Trailing whitespace, file endings, large files, etc.
50+
- **Submodule status**: Ensures submodules are properly tracked
51+
52+
### Manual Quality Checks
53+
54+
You can run individual checks manually:
55+
56+
```sh
57+
# Run ESLint
58+
npm run lint
59+
60+
# Check Prettier formatting
61+
npm run prettier:check
62+
63+
# Fix Prettier formatting
64+
npm run prettier
65+
66+
# TypeScript type checking
67+
npx tsc --noEmit
68+
69+
# Run all checks at once
70+
npm run lint:all
71+
```
72+
1973
## Updating the Protobuf definitions
2074

21-
Protobufs are stored in the [@crispthinking/athena-protobuffs](https://github.com/crispthinking/athena-protobufs) repository.
75+
Protobufs are stored as a git submodule from the [@crispthinking/athena-protobufs](https://github.com/crispthinking/athena-protobufs.git) repository.
2276

23-
To update the protobuf definitions for client generation, run:
24-
`git subtree pull --prefix=athena-protobufs https://github.com/crispthinking/athena-protobufs.git <sha> --squash`
77+
To update the protobuf definitions for client generation:
78+
79+
1. **Update the submodule to the latest version:**
80+
```sh
81+
git submodule update --remote athena-protobufs
82+
```
83+
84+
2. **Or update to a specific commit:**
85+
```sh
86+
cd athena-protobufs
87+
git checkout <commit-sha>
88+
cd ..
89+
git add athena-protobufs
90+
git commit -m "Update protobuf definitions to <commit-sha>"
91+
```
2592

2693
## Regenerating the TypeScript gRPC Client
2794

@@ -36,6 +103,11 @@ This project uses [`@protobuf-ts/plugin`](https://github.com/timostamm/protobuf-
36103
```
37104

38105
2. **Run the following command to regenerate the client and types:**
106+
```sh
107+
npm run codegen
108+
```
109+
110+
Or manually with:
39111
```sh
40112
npx protoc \
41113
--plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts \
@@ -49,9 +121,15 @@ This project uses [`@protobuf-ts/plugin`](https://github.com/timostamm/protobuf-
49121
- The main client will be in `src/athena/athena.grpc-client.ts`.
50122
- Message types and enums are in `src/athena/athena.ts`.
51123

124+
3. **Format the generated code:**
125+
```sh
126+
npm run prettier
127+
```
128+
52129
### Notes
53-
- If you add or change proto files, rerun the above command to keep the TypeScript client in sync.
130+
- If you update proto files in the submodule, rerun `npm run codegen` to keep the TypeScript client in sync.
54131
- If you see TypeScript errors about missing modules, ensure your `tsconfig.json` includes the `src/athena` directory and restart your IDE/tsserver.
132+
- The generated files are automatically formatted by the pre-commit hooks, but you can run `npm run prettier` manually if needed.
55133

56134
---
57135

@@ -65,4 +143,4 @@ curl -LsSf https://astral.sh/uv/install.sh | sh
65143
uv sync
66144
cd docs
67145
make html
68-
The built documentation will be available in docs/build/html/index.html.
146+
The built documentation will be available in docs/build/html/index.html.

__tests__/functional/448x448.jpg

4.53 KB
Loading

__tests__/functional/578x478.jpg

24.7 KB
Loading

0 commit comments

Comments
 (0)