This commit is contained in:
Boki 2026-10-20 18:36:19 -04:00
parent 879e9b4228
commit c3cb36c8d6
51 changed files with 2290 additions and 1467 deletions

View file

@ -19,16 +19,16 @@ bun run check
The root build selects every buildable leaf workspace, including all stock services and the
native engine. `bun run build --dry=json` shows the actual Turbo task plan.
| Command | Scope |
| ------------------------ | ------------------------------------------------------------------------------------------- |
| `bun run build:libs` | Build shared libraries in dependency order |
| `bun run build --clean` | Force every workspace build without cached results |
| `bun run typecheck` | Check library, stock application, and tool source directly |
| `bun run test:contracts` | Compile positive and negative service-contract assertions |
| `bun run test:tooling` | Run workspace and service-consumer regression tests without infrastructure |
| `bun run test:integration` | Replay fixed prices through ingestion, storage, and the real native backtest engine |
| `bun run lint:check` | Lint stock applications, libraries, and tools with zero warnings allowed |
| `bun run check` | Run build, type checking, contract tests, tooling/integration tests, and lint; report every failed gate |
| Command | Scope |
| -------------------------- | ------------------------------------------------------------------------------------------------------- |
| `bun run build:libs` | Build shared libraries in dependency order |
| `bun run build --clean` | Force every workspace build without cached results |
| `bun run typecheck` | Check library, stock application, and tool source directly |
| `bun run test:contracts` | Compile positive and negative service-contract assertions |
| `bun run test:tooling` | Run workspace and service-consumer regression tests without infrastructure |
| `bun run test:integration` | Replay fixed prices through ingestion, storage, and the real native backtest engine |
| `bun run lint:check` | Lint stock applications, libraries, and tools with zero warnings allowed |
| `bun run check` | Run build, type checking, contract tests, tooling/integration tests, and lint; report every failed gate |
`check` exits nonzero if any gate fails. Type/lint errors are not suppressed or baselined.
The larger existing `bun run test` suite is separate:
@ -136,3 +136,69 @@ reads, missing data, duplicate/concurrent requests, failed persistence/rollback,
responsive requests/streams, worker crashes, deadlines, cancellation, and cleanup. SQL tests
use an in-process PostgreSQL emulator and the real transaction manager, not a live database.
Durable queued dispatch and recovery after an orchestrator crash remain follow-up work.
## HTTP access and secrets
HTTP services now fail closed unless server-side access tokens are configured. Use the
root `.env` (`.env.example` documents the settings) and set independent `STOCK_BOT_ADMIN_TOKEN` and
`STOCK_BOT_SERVICE_TOKEN` values (at least 32 characters; generate each with
`openssl rand -hex 32`). An optional distinct `STOCK_BOT_READ_TOKEN` permits read-only
access. The same service token must be available to internal HTTP clients and servers.
Never put these tokens in `VITE_*` settings, URLs, source files, or logs.
CLI clients use `Authorization: Bearer <token>`. The dashboard sign-in exchanges an
admin/read token for a signed one-hour HttpOnly, SameSite=Strict cookie; it does not store
the token in localStorage or include it in the bundle. Production cookies require HTTPS.
Read-only access cannot mutate data; all mutation/admin operations require admin/service
access. Internal services do not accept browser cookies. WebSocket upgrades authenticate
and validate browser Origin. Session-key rotation invalidates issued cookies; logout clears
the browser cookie (copied cookies remain valid until expiry or key rotation). This is an
operator-access boundary, not a multi-user identity/tenant system.
Dashboard/API URLs must be same-site for the strict cookie policy. In local development,
use matching hostnames (`localhost` for both, or `127.0.0.1` for both), not a mixture.
`STOCK_BOT_HTTP_HOST` defaults to `127.0.0.1`. Set it explicitly for containers. Set
`STOCK_BOT_ALLOWED_ORIGINS` to an exact comma-separated list of trusted frontend origins;
production same-origin requests are supported, and reverse-proxy deployments must include
the public HTTPS origin. Wildcard/null origins are rejected. For isolated local demos only,
`STOCK_BOT_AUTH_DISABLED=true` is allowed on a loopback development/test listener, never
in production. Health endpoints remain public. TLS termination and external rate limiting
belong at the deployment boundary; do not expose development services directly.
The root `.env` and `apps/stock/web-app/.env` are intentionally tracked for this private,
local-development repository. Other environment files remain ignored;
`bun run audit:secrets` rejects unexpected tracked environment files outside these two
explicit exceptions (WCAG excluded). It is not a complete secret scanner. Keep production
credentials out of these files. Committed values remain in Git history; rotate any real
credentials before sharing the repository or if access changes. Logging still redacts
sensitive fields, bearer tokens, credentialed URLs, and sensitive URL query parameters.
Development database/admin-UI Compose ports bind to loopback; existing containers must
be recreated for changed port bindings to take effect.
## Pipeline safety
Routine exchange/symbol/provider-mapping syncs are non-destructive. Legacy
`clearFirst: true` requests are rejected; scheduled exchange syncs no longer reset data.
The transactional sync paths share one checked-out PostgreSQL connection and one
transaction-scoped advisory lock. SQL errors roll back the whole batch and sync status,
and existing curated exchange/provider mappings are preserved. Do not add pooled
`query('BEGIN')` calls: use a transaction-scoped repository.
Reference-data reset is a separate admin maintenance operation. Send a JSON body to
`POST /api/pipeline/clear/postgresql` with an explicit `type` (`provider_mappings`,
`exchanges`, or `all`) and `confirmation: "DELETE STOCK REFERENCE DATA:<type>"`.
There is no default scope. A mapping-only reset deletes symbol-provider mappings only;
an exchange-only reset fails atomically if symbols still reference exchanges; `all`
deletes reference mappings, symbols, and exchanges in foreign-key order. These resets do
not delete backtest history, prices, or trading records. The dashboard requires typing
the matching confirmation. Generic queue access remains administrator-only.
`bun run test:native` is part of `bun run check`. The stochastic tests explicitly cover
warm-up (14-bar K plus 3-value D needs 16 bars), invalid periods, golden values, and
incremental/batch parity; no synthetic D values are produced before warm-up completes.
`bun run test:postgres` additionally requires `PIPELINE_TEST_DATABASE_URL` pointing to a
**disposable database whose name starts with `stock_bot_safety`**. It creates/drops isolated
test schemas and verifies real rollback, foreign-key constraints, idempotency, and competing
transaction locking. CI provisions that database and runs this additional gate. It is
separate from the infrastructure-free `check`; never point tests at production.