|
11 | 11 | - Front-end builds flow through Turbo: `npm run build` executes `turbo run build`, and `npm run lint` fans out ESLint across all workspaces. |
12 | 12 |
|
13 | 13 | ## Coding Style & Naming Conventions |
| 14 | +- **Write code as if the same person authored the entire codebase**—consistency is paramount. |
| 15 | +- **Favor functional, declarative style**: use `map`, `reduce`, `filter`, and list comprehensions in Python; avoid nested `if` statements and `for` loops when a functional alternative is cleaner. |
| 16 | +- **Concise but readable**: code should be terse yet easily maintainable by a human developer—no unnecessary verbosity, but no cryptic one-liners either. |
14 | 17 | - Python follows PEP 8 with 4-space indentation—format via `black` and keep typing clean with `mypy` (both listed in `requirements.dev.txt`). |
15 | 18 | - Use snake_case for modules/functions (e.g., `modules/pricing/rate.py`) and PascalCase for classes; mirror existing mapper naming in `modules/connectors`. |
16 | 19 | - TypeScript and React code are formatted with Prettier (`npm run format`) and linted through `packages/eslint-config-custom`; prefer 2-space indentation and explicit exports. |
| 20 | +- **Frontend**: don't reinvent the wheel—follow existing separation of concerns: `lib/` for logic, `types/` for types (use regenerate scripts), reusable components in `ui/`, same concise functional style. |
17 | 21 |
|
18 | 22 | ## Testing Guidelines |
19 | 23 | - Activate the environment with `source bin/activate-env` before invoking tests. |
20 | | -- Run `./bin/run-server-tests` for the API suites; carrier adapters must stay on Python's `unittest` with canonical files like `test_rate.py` and classes shaped as `Test<Carrier><Feature>`. |
21 | | -- Validate connectors via `python -m unittest discover -v -f modules/connectors/<carrier>/tests`, and guard SDK changes with `./bin/run-sdk-tests`; include the debug prints and tuple assertions mandated in `CARRIER_INTEGRATION_GUIDE.md`. |
| 24 | +- **Always run tests from the repository root**. |
| 25 | +- **Always take inspiration from existing tests**—match the coding style of the project. |
| 26 | +- **We do NOT use pytest anywhere in the stack**: |
| 27 | + - Carrier integrations: native Python `unittest` |
| 28 | + - Server/Django: Django tests via `karrio` (manage.py wrapper) |
| 29 | +- **Carrier integration tests**: follow the style in `./bin/run-sdk-tests`—run from root: |
| 30 | + ```bash |
| 31 | + ./bin/run-sdk-tests # runs all SDK and connector tests |
| 32 | + python -m unittest discover -v -f modules/connectors/<carrier>/tests # single carrier |
| 33 | + ``` |
| 34 | +- **Server/Django module tests**: follow the style in `./bin/run-server-tests`—run from root: |
| 35 | + ```bash |
| 36 | + ./bin/run-server-tests # runs all server tests |
| 37 | + karrio test --failfast karrio.server.<module>.tests # single module |
| 38 | + ``` |
| 39 | +- Carrier adapters must stay on Python's `unittest` with canonical files like `test_rate.py` and classes shaped as `Test<Carrier><Feature>`. |
| 40 | +- Follow carrier testing templates and style in `CARRIER_INTEGRATION_GUIDE.md`. |
| 41 | + |
| 42 | +### Test Writing Style |
| 43 | +- **Avoid multiple single-field assertions**—prefer comprehensive comparisons. |
| 44 | +- **Use `assertNoErrors` utility** where it makes sense to validate clean responses. |
| 45 | +- **Single `assertDictEqual` or `assertListEqual`** with full API response data comparison: |
| 46 | + - Use `mock.ANY` for dynamic fields like `id`, `dates`, `timestamps`. |
| 47 | +- **Carrier tests**: follow the same principles using templates in `CARRIER_INTEGRATION_GUIDE.md`. |
22 | 48 |
|
23 | 49 | ## Commit & Pull Request Guidelines |
24 | 50 | - Keep commits focused and follow the short `type: summary` style already used (`fix:`, `feat:`, `chore:`); reference issues with `refs #123` or `fixes #123`. |
|
28 | 54 | ## Configuration Tips |
29 | 55 | - Workspace-specific `.env` files drive local overrides; duplicate provided templates and never commit secrets. |
30 | 56 | - Use `./bin/create-new-env` when you need a fresh sample configuration, and load additional variables through Docker compose overrides or CI secrets to keep builds reproducible. |
| 57 | + |
| 58 | +## Carrier Integration Reference |
| 59 | + |
| 60 | +- **Always consult `CARRIER_INTEGRATION_GUIDE.md`** when working with carrier integrations—it contains the canonical patterns, file structures, and testing requirements for all connector work. |
0 commit comments