Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
- Write code for readers ranging from junior developers to experienced maintainers. Prefer straightforward control flow, descriptive names, and explicit intermediate steps over terse, clever, or densely composed syntax.
- Keep functions cohesive and small enough to understand without tracing unrelated state. Extract a well-named local or helper when it reveals intent, but do not fragment a simple operation across unnecessary abstractions.
- Make behavior and ownership visible in the code. Avoid hidden side effects, ambiguous Boolean parameters, unexplained constants, and conditionals whose meaning must be reconstructed by the reader.
- Explain why non-obvious behavior is necessary, especially for security, protocol, concurrency, lifecycle, compatibility, and accessibility constraints. Place concise comments near the relevant code, keep them current, and do not narrate statements that are already clear.
- Explain non-obvious intent and tradeoffs in the source files, not only in pull requests, commit messages, or external documentation. Place concise comments beside the relevant security, protocol, concurrency, lifecycle, compatibility, accessibility, and performance decisions, including the invariants future changes must preserve.
- For performance-sensitive code, explain what work or allocation is avoided and any ownership, parallel-request safety, bounded-retention, or cleanup requirements. Distinguish reduced allocation/GC pressure from guaranteed lower resident memory; keep environment-specific benchmark results in tests or documentation rather than presenting them as source-code guarantees.
- Review comments when changing behavior: update or remove stale explanations, prefer clear names and control flow for obvious operations, and avoid line-by-line narration or mandatory comments on every helper.
- Prefer readability over micro-optimization. Use a less obvious implementation only when measurements or a hard platform constraint justify it, and document the reason and invariant that future changes must preserve.
- Make tests readable specifications: use behavior-focused names, arrange setup and assertions clearly, and favor expected outcomes over implementation details.
- Prefer the .NET platform and `System.Text.Json` over new dependencies. Justify added packages by concrete functionality or risk reduction.
Expand Down
8 changes: 7 additions & 1 deletion .github/instructions/dotnet.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ applyTo: "**/*.{cs,csproj,sln,props,targets}"
- Map reserved management routes before the dispatcher fallback, keep management edits in a domain service, and require strong revision ETags on every management write.
- Keep management API, dashboard, OpenAPI document, and Swagger UI exposure independently configurable. OpenAPI must describe only reserved management operations, never runtime-defined mock routes.
- Represent the active document, revision, persistence status, and endpoint registry as one immutable configuration snapshot and publish replacements atomically.
- Reuse only unchanged immutable response bytes and ordered headers by stable endpoint ID. Keep fresh runtime endpoints and limiter permits on every applied replacement; never retain prior registries or extra UTF-16 bodies merely for reuse.
- Route every runtime or management configuration mutation through `ConfigurationState`; do not publish routes independently of the active document and revision.
- Load persisted configuration before serving requests, fail startup for required malformed or invalid files, and save by replacing a flushed same-directory temporary file.
- Capture one configuration snapshot per save and clear its dirty state only when that revision is still current.
Expand All @@ -31,13 +32,18 @@ applyTo: "**/*.{cs,csproj,sln,props,targets}"
protection. Existing settings, rotations, and explicit opt-outs take precedence over the deployment value.
Invalid keys, unreadable settings, or failed persistence fail startup without exposing secrets.
- Use cancellation tokens for asynchronous I/O and propagate them through application boundaries.
- Publish the predecoded API-key digest with its security revision and enforcement flag. Verify requests using independent bounded stack buffers, clear scratch storage, preserve constant-time comparison, and never cache plaintext request keys.
- Use UTC timestamps through `TimeProvider` where behavior depends on time.
- Use source-generated `System.Text.Json` contexts for application-owned request, response, and persistence types.
- Document public C# contracts with XML documentation comments. Cover parameters, return values, exceptions, wire semantics, concurrency guarantees, and persistence behavior when they are not obvious from the signature; use `<inheritdoc/>` when a contract is inherited.
- Do not add narration to trivial private helpers. Use implementation comments only for invariants, security decisions, protocol constraints, or reasoning the code cannot express clearly.
- Do not add narration to trivial private helpers. Use implementation comments for reasoning the code cannot express clearly, including invariants, security decisions, protocol constraints, and performance tradeoffs. Explain pooled/shared/stack storage ownership, concurrent-use safety, retention, and cleanup where relevant; do not imply that fewer allocations guarantee lower resident memory.
- Give every management operation a stable OpenAPI operation ID, concise summary, request-body metadata, typed success responses, and applicable problem responses. Document strong `If-Match` requirements in the operation description and test the generated document.
- Return problem details for management API errors and avoid exposing exceptions or filesystem details.
- Design concurrent statistics structures with bounded memory and test their rollover and contention behavior.
- Keep dashboard deltas opt-in and absolute, with SSE sequence/base guards and full baselines after resets,
reconnects, or missed frames. Retain one shared frame without replay history; preserve legacy full delivery
and keep comparison/serialization locks off the recording path.
- Keep minute buckets and counters contiguous value types. Access stored elements and atomic fields by reference; avoid struct copies or readonly defensive copies that bypass volatile reads or discard updates.
- Account for every matched dispatch exactly once, including delay cancellation. Failed attempts retain the
selected response status, or no status before response selection, and contribute zero completed bytes.
Keep intentional connection aborts distinct and preserve logical-request retry coalescing.
Expand Down
6 changes: 5 additions & 1 deletion .github/instructions/frontend.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ applyTo: "src/MockAPI/wwwroot/**/*.{js,html,css},tests/{frontend,browser}/**/*.j
- Keep event, timer, request, and subscription lifecycles visible. Co-locate setup with cleanup where practical, and explain ordering or stale-update protections when they are not apparent from the control flow.
- Dispose page-owned controllers on non-persisted `pagehide`, not `beforeunload` (which also fires for downloads). Suspend synchronization for back-forward cached pages and resume it on persisted `pageshow`.
- Use one `/__mockapi/api/dashboard/events` stream for configuration and statistics. Poll only for recovery or unsupported SSE; abort work while hidden and reject obsolete responses. Cache endpoint definitions in memory by revision, never in browser storage. Preserve endpoint row controls during statistics-only updates.
- Opt the dashboard into interval statistics deltas. Maintain its sequenced stream baseline independently
of HTTP refreshes, apply absolute updates immutably, and recover sequence gaps without aborting commands.
Retain Statistics rows and UTC-minute chart columns, bound their caches, and dispose removed listeners
while preserving focus, scroll, and current tooltip data.
- Route management requests through `dashboard-management.js`. Configuration commands pass an explicit captured ETag; editor drafts and confirmations keep their reviewed revision despite live updates. Keep the single-flight guard through the authoritative refresh, surface failures, and never automatically replay rejected writes.
- Consume the synchronizer's explicit completed/failed/inactive refresh result at the command boundary. Background recovery may continue after failure, but a command must not treat a failed or interrupted refresh as successful.
- Serve scripts and styles with private, content-validated caching; keep dashboard HTML and administrative data non-storable. Do not use immutable caching for unversioned asset URLs.
- Add JSDoc to every exported function, factory, and reusable exported value. Document parameters, return shapes, callbacks, lifecycle, side effects, thrown errors, and discriminated result variants where applicable.
- Prefer reusable `@typedef` contracts for shared object shapes. Keep annotations specific enough to help editors and reviewers; do not use `Object` when a meaningful shape is known.
- Keep shared endpoint, configuration, management-problem, and statistics wire shapes in `dashboard-core.js`, aligned with the backend's nullable and omitted fields. Keep named controller/lifecycle types in their owning modules and reuse shared contracts rather than duplicating payload shapes.
- Declare required DOM IDs with their expected HTML tags through `getDashboardElements`; the lookup validates markup and infers precise control types. Preserve concrete element and request-entry types through generic helpers. Keep narrowing assertions at validated or statically owned DOM/JSON boundaries rather than casting whole controllers.
- Do not require comments on trivial private helpers. Add concise comments only for accessibility behavior, synchronization invariants, storage fallbacks, security boundaries, or non-obvious browser behavior.
- Do not require comments on trivial private helpers. Add concise source comments for non-obvious accessibility behavior, synchronization invariants, storage fallbacks, security boundaries, browser behavior, or performance tradeoffs. Explain node reuse and listener/cache ownership when they affect cleanup, current data, focus, or scroll preservation; update those explanations with the behavior.
- Keep pure transformation logic in importable modules with direct Vitest coverage. Inject browser APIs into stateful controllers when doing so makes lifecycle and failure behavior deterministic to test.
- Preserve WCAG 2.2 AA contrast, keyboard access, focus order, dialog semantics, reduced-motion behavior, and light, dark, and high-contrast states.
- Gate side-by-side dashboard panels on the measured command-group width, including gaps; never wrap command groups within a column. Fall back to stacked without overwriting the saved layout preference. Keep endpoint search compact and the collapse control aligned with the first filter row.
Expand Down
22 changes: 22 additions & 0 deletions docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ methods remain unchanged. These are global runtime rules, not new endpoint confi
remains independent and unchanged. Validation responses are counted against the matched endpoint without retaining
the request content.

Validation reuses bounded byte buffers and reads JSON tokens without building a document tree.
All rented buffers are cleared before being returned to the pool, including after failed or cancelled reads.
These are internal allocation optimizations; payload limits, accepted JSON, and error responses are unchanged.

The test blade and all portable request exports provide optional illustrative JSON samples for
`POST`, `PUT`, and `PATCH`. Trailhead inventory reservation routes use a SKU, quantity, and warehouse;
shipping creation routes use a service, parcel weight, and line items. Other routes use a general
Expand Down Expand Up @@ -190,6 +194,24 @@ and API description edits. File persistence writes and flushes a temporary file
atomically replaces the configured path. Blob persistence uploads the complete deterministic document as one
replacement operation. Concurrent saves are serialized and converge on the latest active revision.

File saves, Blob uploads, and unfiltered native exports stream the canonical bytes of one captured
immutable snapshot without first copying the complete document. Public snapshot exports still return
independent byte arrays; filtered native exports and generated formats retain their existing serialization.

Every applied replacement still validates the complete candidate and creates fresh runtime endpoint
instances. For matching stable endpoint IDs, compilation reuses unchanged immutable UTF-8 response
bodies and ordered header projections, including the pre-limit success response. Body comparison
uses bounded stack storage rather than retaining a second UTF-16 copy. Route and metadata edits can
reuse wire data, but status, content type, reason phrase, and delay always come from the new definition.
Rate-limit permits are never shared between revisions: every successful configuration replacement
starts fresh limiters, as before. Rejected or stale candidates leave the active snapshot and its
limiter state untouched. The reuse index is owned by the snapshot, not an unbounded cross-revision cache.

Single-endpoint management mutation responses deserialize only the selected endpoint from the applied
snapshot's canonical JSON. Unrelated endpoint bodies are skipped without materialization. Returned
data stays detached, with canonical header ordering and body text; complete candidate validation,
atomic publication, ETags, and autosave behavior are unchanged.

If automatic saving fails, changes remain active but unsaved. The dashboard displays an error and enables
**Retry save**; the management API returns a `500` `autosave-failed` problem with the current ETag.
Retry persistence through **Retry save** or `POST /__mockapi/api/configuration/save` with that ETag, not by
Expand Down
6 changes: 6 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ pnpm run test:site
pnpm run test:browser:smoke
```

The site tests check that common-use card headings, descriptions, and links align across desktop
widths and enlarged text, while narrow viewports retain naturally sized, stacked cards.
The hero's Docker Hub version badge uses the same Shields.io source as the README and links to the
published image. Browser tests stub the badge service and verify keyboard access and an accessible
link name even when the image cannot load.

`pnpm run validate:dependency-security` audits pnpm and direct and transitive NuGet
dependencies. Dependency findings are warning-only: the reports remain visible,
but builds and validation continue even when vulnerabilities are found.
Expand Down
Loading