|
| 1 | +# Quality Guidelines |
| 2 | + |
| 3 | +> Code quality standards for backend development. |
| 4 | +
|
| 5 | +--- |
| 6 | + |
| 7 | +## Overview |
| 8 | + |
| 9 | +<!-- |
| 10 | +Document your project's quality standards here. |
| 11 | +
|
| 12 | +Questions to answer: |
| 13 | +- What patterns are forbidden? |
| 14 | +- What linting rules do you enforce? |
| 15 | +- What are your testing requirements? |
| 16 | +- What code review standards apply? |
| 17 | +--> |
| 18 | + |
| 19 | +(To be filled by the team) |
| 20 | + |
| 21 | +--- |
| 22 | + |
| 23 | +## Forbidden Patterns |
| 24 | + |
| 25 | +<!-- Patterns that should never be used and why --> |
| 26 | + |
| 27 | +(To be filled by the team) |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +## Required Patterns |
| 32 | + |
| 33 | +<!-- Patterns that must always be used --> |
| 34 | + |
| 35 | +### Scenario: Dispatch-Only Account Gates |
| 36 | + |
| 37 | +#### 1. Scope / Trigger |
| 38 | + |
| 39 | +- Trigger: adding or changing account flags that control whether an account may receive new proxied requests. |
| 40 | +- This is a cross-layer contract because the flag is stored in DB, exposed by admin API, synced into runtime state, and shown in the UI. |
| 41 | + |
| 42 | +#### 2. Signatures |
| 43 | + |
| 44 | +- Runtime flag: `auth.Account.DispatchPaused int32`. |
| 45 | +- Admin API: `POST /api/admin/accounts/:id/enable` with `{"enabled": boolean}`. |
| 46 | +- Database setter: `SetAccountEnabled(ctx context.Context, id int64, enabled bool) error`. |
| 47 | + |
| 48 | +#### 3. Contracts |
| 49 | + |
| 50 | +- `enabled=true`: account is eligible for normal scheduler/dispatch selection if all existing health, cooldown, usage, API-key, and concurrency gates also pass. |
| 51 | +- `enabled=false`: account is excluded from scheduler/dispatch selection only. |
| 52 | +- `enabled=false` must not block RT refresh, AT refresh, manual refresh, token cache writes, testing, usage probes, recovery probes, import/export, auto-clean, account list visibility, credential updates, or existing `locked` semantics. |
| 53 | +- `locked` is separate and means auto-clean protection; do not reuse it as a dispatch gate. |
| 54 | + |
| 55 | +#### 4. Validation & Error Matrix |
| 56 | + |
| 57 | +- Invalid `:id` -> `400` with the existing admin error response helper. |
| 58 | +- Malformed JSON body -> `400`. |
| 59 | +- Database update failure -> `500`. |
| 60 | +- Nonexistent IDs follow the existing account flag setter behavior unless the setter is explicitly changed across all account flag endpoints. |
| 61 | + |
| 62 | +#### 5. Good/Base/Bad Cases |
| 63 | + |
| 64 | +- Good: `IsAvailable()` and `fastSchedulerSnapshot()` both reject `DispatchPaused`. |
| 65 | +- Base: disabled accounts still appear in `ListAccounts` and can be manually refreshed. |
| 66 | +- Bad: filtering `enabled=false` inside `ListActive`, `parallelRefreshAll`, usage probes, recovery probes, or clean-up paths. |
| 67 | + |
| 68 | +#### 6. Tests Required |
| 69 | + |
| 70 | +- Scheduler tests proving disabled accounts are skipped by both normal and fast scheduler paths. |
| 71 | +- Regression tests proving disabled accounts still participate in usage probes, recovery probes, and auto-clean. |
| 72 | +- Database tests proving new accounts default to enabled and can be toggled. |
| 73 | + |
| 74 | +#### 7. Wrong vs Correct |
| 75 | + |
| 76 | +Wrong: |
| 77 | +```go |
| 78 | +// This hides disabled accounts from refresh, probes, UI, and clean-up. |
| 79 | +SELECT ... FROM accounts WHERE enabled = true |
| 80 | +``` |
| 81 | + |
| 82 | +Correct: |
| 83 | +```go |
| 84 | +// Load all non-deleted accounts and apply the enabled gate only in dispatch selection. |
| 85 | +SELECT ..., COALESCE(enabled, true) FROM accounts WHERE status <> 'deleted' |
| 86 | +``` |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Testing Requirements |
| 91 | + |
| 92 | +<!-- What level of testing is expected --> |
| 93 | + |
| 94 | +(To be filled by the team) |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Code Review Checklist |
| 99 | + |
| 100 | +<!-- What reviewers should check --> |
| 101 | + |
| 102 | +(To be filled by the team) |
0 commit comments