Fix grpcserver rate limiter: move to Server field

The package-level defaultRateLimiter drained its token bucket
across all test cases, causing later tests to hit ResourceExhausted.
Move rateLimiter from a package-level var to a *grpcRateLimiter field
on Server; New() allocates a fresh instance (10 req/s, burst 10) per
server. Each test's newTestEnv() constructs its own Server, so tests
no longer share limiter state.

Production behaviour is unchanged: a single Server is constructed at
startup and lives for the process lifetime.
This commit is contained in:
2026-03-11 19:20:32 -07:00
parent a80242ae3e
commit 4596ea08ab
12 changed files with 276 additions and 123 deletions

View File

@@ -1,64 +1,24 @@
/* MCIAS UI — base stylesheet */
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
html{font-size:16px}
body{font-family:system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;line-height:1.6;color:#1a1a2e;background:#f4f6f9;min-height:100vh}
a{color:#2563eb;text-decoration:none}
a:hover{text-decoration:underline}
.container{max-width:1100px;margin:0 auto;padding:0 1.25rem}
nav{background:#1a1a2e;color:#e2e8f0;box-shadow:0 2px 4px rgba(0,0,0,.3)}
nav .nav-inner{max-width:1100px;margin:0 auto;padding:0 1.25rem;display:flex;align-items:center;justify-content:space-between;height:3.25rem}
nav .nav-brand{font-weight:700;font-size:1.1rem;color:#e2e8f0}
nav .nav-links{display:flex;gap:1.5rem;list-style:none}
nav .nav-links a{color:#cbd5e1;font-size:.9rem;font-weight:500;transition:color .15s}
nav .nav-links a:hover{color:#fff;text-decoration:none}
main{padding:2rem 0 3rem}
.page-header{margin-bottom:1.5rem}
.page-header h1{font-size:1.5rem;font-weight:700;color:#1a1a2e}
.card{background:#fff;border:1px solid #e2e8f0;border-radius:8px;padding:1.5rem;box-shadow:0 1px 3px rgba(0,0,0,.06)}
.card+.card{margin-top:1.25rem}
.table-wrapper{overflow-x:auto;border:1px solid #e2e8f0;border-radius:8px}
table{width:100%;border-collapse:collapse;font-size:.9rem}
thead{background:#f8fafc}
thead th{text-align:left;padding:.65rem 1rem;font-weight:600;font-size:.8rem;text-transform:uppercase;letter-spacing:.05em;color:#475569;border-bottom:1px solid #e2e8f0}
tbody tr{border-bottom:1px solid #f1f5f9;transition:background .1s}
tbody tr:last-child{border-bottom:none}
tbody tr:hover{background:#f8fafc}
tbody td{padding:.65rem 1rem;color:#334155;vertical-align:middle}
.badge{display:inline-block;padding:.2em .65em;border-radius:9999px;font-size:.75rem;font-weight:600;text-transform:uppercase;letter-spacing:.04em}
.badge-active{background:#dcfce7;color:#166534}
.badge-inactive{background:#ffedd5;color:#9a3412}
.badge-deleted{background:#fee2e2;color:#991b1b}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;padding:.45rem 1rem;border:none;border-radius:6px;font-size:.9rem;font-weight:500;cursor:pointer;transition:background .15s,opacity .15s;text-decoration:none;line-height:1.4}
.btn:disabled{opacity:.55;cursor:not-allowed}
.btn-primary{background:#2563eb;color:#fff}
.btn-primary:hover{background:#1d4ed8;text-decoration:none;color:#fff}
.btn-secondary{background:#e2e8f0;color:#334155}
.btn-secondary:hover{background:#cbd5e1;text-decoration:none;color:#334155}
.btn-danger{background:#dc2626;color:#fff}
.btn-danger:hover{background:#b91c1c;text-decoration:none;color:#fff}
.btn-sm{padding:.25rem .65rem;font-size:.8rem}
.form-group{margin-bottom:1.1rem}
.form-group label{display:block;font-size:.875rem;font-weight:600;color:#374151;margin-bottom:.35rem}
.form-control{display:block;width:100%;padding:.5rem .75rem;border:1px solid #cbd5e1;border-radius:6px;font-size:.95rem;color:#1a1a2e;background:#fff;transition:border-color .15s,box-shadow .15s}
.form-control:focus{outline:none;border-color:#2563eb;box-shadow:0 0 0 3px rgba(37,99,235,.15)}
.form-control::placeholder{color:#94a3b8}
.form-hint{font-size:.8rem;color:#64748b;margin-top:.25rem}
.form-actions{margin-top:1.5rem;display:flex;gap:.75rem;align-items:center}
.login-wrapper{display:flex;align-items:center;justify-content:center;min-height:100vh;padding:2rem 1rem}
.login-box{width:100%;max-width:380px}
.login-box .brand-heading{text-align:center;font-size:1.3rem;font-weight:700;margin-bottom:1.5rem;color:#1a1a2e}
.alert{padding:.75rem 1rem;border-radius:6px;font-size:.9rem;margin-bottom:1rem;border-left:4px solid transparent}
.alert-error{background:#fef2f2;border-color:#dc2626;color:#7f1d1d}
.alert-success{background:#f0fdf4;border-color:#16a34a;color:#14532d}
.alert-info{background:#eff6ff;border-color:#2563eb;color:#1e3a8a}
.htmx-indicator{opacity:0;transition:opacity 200ms ease-in}
.htmx-request .htmx-indicator{opacity:1}
.htmx-request.htmx-indicator{opacity:1}
.text-muted{color:#64748b}
.text-small{font-size:.85rem}
.mt-2{margin-top:1rem}
.d-flex{display:flex}
.align-center{align-items:center}
.gap-1{gap:.5rem}
.gap-2{gap:1rem}
.justify-between{justify-content:space-between}
/* MCIAS management UI styles — placeholder */
*, *::before, *::after { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; padding: 0; background: #f5f5f5; color: #222; }
.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
nav { background: #1a1a2e; color: #fff; padding: 0.5rem 1rem; }
.nav-inner { display: flex; align-items: center; justify-content: space-between; max-width: 960px; margin: 0 auto; }
.nav-brand { font-weight: bold; font-size: 1.2rem; }
.nav-links { list-style: none; display: flex; gap: 1rem; margin: 0; padding: 0; }
.nav-links a { color: #ccc; text-decoration: none; }
.nav-links a:hover { color: #fff; }
.btn { display: inline-block; padding: 0.4rem 0.8rem; border: none; border-radius: 4px; cursor: pointer; font-size: 0.9rem; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.8rem; }
.btn-primary { background: #0d6efd; color: #fff; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-danger { background: #dc3545; color: #fff; }
.alert { padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; }
.alert-error { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
.alert-success { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th, td { padding: 0.5rem; text-align: left; border-bottom: 1px solid #dee2e6; }
th { background: #e9ecef; }
input, select { padding: 0.4rem; border: 1px solid #ced4da; border-radius: 4px; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #e9ecef; }