Mock-Server Parity¶
The local mock Hub is a development adapter, not a second implementation of production business rules. Environment-independent behavior belongs in src/hub/lib/ and must be imported by both server.js and tests/mock-server.js.
Parity Inventory¶
| Behavior | Production location | Mock location | Parity strategy |
|---|---|---|---|
| Workload visibility and runtime counts | Hub status responses | Mock status responses | Shared lib/workload-state.js functions and fixture tests |
| Update count filtering | Background and batch status | Mock online status | Shared serviceUpdateCount function |
| Policy and reserved names | lib/policy.js |
lib/policy.js |
Shared policy module |
| Host/config validation | Route and config stores | Mostly static fixtures | Reuse pure validators when mock input becomes editable |
| Response transformations | Route modules | handleApi branches |
Add representative contract fixtures before extraction |
| Authorization and CSRF | Express middleware | Simulated users only | Production authorization tests remain authoritative; mock must not claim enforcement |
| Streaming and timestamps | Agent/SSE integrations | Synthetic streams | Match required fields, not volatile values |
| PVE and external services | Real clients | Scenario fixtures | Keep adapters separate and test response schemas |
Rules¶
- Do not import the production Express application into the mock server.
- Do not copy pure filtering, normalization, validation, or risk logic into the mock.
- Add shared fixture tests whenever a response field depends on extracted logic.
- Keep infrastructure access, timers, synthetic data, and transport simulation inside their respective adapters.
- Treat a production route addition as requiring either a mock route or an explicit documented exclusion.
Current Contract Coverage¶
tests/workload-state.test.js verifies local-image filtering, internal-service exclusion, service identifier precedence, Podman Names arrays, pod membership suppression, infrastructure pod exclusion, and running/down counts. Both production and mock status paths consume the same implementation, so those fields cannot drift independently.
tests/route-parity.test.js derives the production route inventory from the route modules and mock coverage from the actual handleApi path branches. CI fails when a production route is missing from the mock without a reasoned exclusion, when an exclusion becomes stale, when a mutating route lacks CSRF protection, role middleware, or an audit identifier without a documented trust-boundary exception, or when audit identifiers are reused. The mock implements configuration dry-run validation; exclusions are limited to first-use setup and agent artifact or certificate-enrollment flows that the development adapter cannot safely emulate.