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: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ AZURE_CUSTOM_DOMAIN_VALIDATION_METHOD=CNAME
# MockAPI Dashboard credentials. Leave blank if keeping it publicly accessible
AZURE_DASHBOARD_USERNAME=
AZURE_DASHBOARD_PASSWORD=

# Optional initial X-MockAPI-Key: 32-256 ASCII letters, digits, hyphens, or underscores.
# Existing persisted security settings take precedence.
AZURE_MOCKAPI_KEY=
2 changes: 1 addition & 1 deletion .github/agents/refactoring.agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Only recommend work supported by concrete evidence such as:
- missing or ambiguous public contract metadata that prevents generated documentation, static tooling, or focused contract tests from describing supported behavior;
- measured startup, throughput, memory, image-size, or interaction latency regressions.

Do not treat line count, small bounded `O(n)` loops, ordinary collection allocation, or stylistic preference as sufficient evidence. MockAPI supports at most 25 endpoint definitions, so optimize endpoint scans only when large payloads, repeated passes, duplicated policy, or measurements justify the change. Do not introduce pooling, caching, indexing, frameworks, or dependencies without demonstrating a net benefit under repository limits.
Do not treat line count, small bounded `O(n)` loops, ordinary collection allocation, or stylistic preference as sufficient evidence. MockAPI has no endpoint-count cap, but configurations remain bounded by the 4 MiB UTF-8 document-size limit. Evaluate endpoint scans with representative large configurations and optimize only when repeated passes, duplicated policy, or measurements justify the change. Do not introduce pooling, caching, indexing, frameworks, or dependencies without demonstrating a net benefit under repository limits.

## Invariants

Expand Down
26 changes: 20 additions & 6 deletions .github/instructions/configuration.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ applyTo: "{config,schemas}/**/*.json"
- Reject unknown properties unless a versioned compatibility decision deliberately permits them.
- Keep endpoint IDs stable UUIDs and method arrays non-empty and unique.
- Keep endpoint descriptions optional freeform text bounded to 4,000 characters and preserve their whitespace through round trips.
- For Trailhead sample endpoints, use two labeled plain-text sections in the existing `description`:
`Description:` first and `Technical implementation:` second, separated by a blank line.
Explain the business scenario before the mock's HTTP behavior and limitations; do not require this format for custom endpoints.
- Keep optional `apiDescriptions` keyed by case-sensitive first-segment paths, independent of endpoint membership.
Bound metadata to 25 groups and 4,000 characters per description; preserve whitespace and ordinal key ordering.
Endpoint deletion never removes metadata. Built-in merges add missing descriptions atomically but preserve
Expand All @@ -22,12 +25,23 @@ applyTo: "{config,schemas}/**/*.json"
- Keep rolling-window rate limits optional, restricted to terminal `429` responses, and configured with a `2xx` pre-limit response.
- Reject control characters and server-controlled or hop-by-hop headers.
- Keep response bodies as raw strings; do not normalize JSON-shaped payload text.
- Apply practical, tested limits to documents, endpoints, methods, headers, and bodies.
- Apply practical, tested size limits to documents and endpoint fields, methods, headers, and bodies.
Do not impose an endpoint-count limit on configuration documents, merges, or bulk selections.
- Keep schema validation and semantic validation distinct. The semantic layer owns cross-record method/path conflicts and reserved-route checks.
- Keep serialization deterministic and verify generated configuration against the checked-in schema.
- Keep the built-in example document as a checked-in, schema-valid embedded resource. Expose it read-only and activate it only through the normal validated, ETag-protected merge path.
- Keep the built-in example cohesive under `/ctp` (Contoso Theme Parks), with fictional park, attraction,
reservation, and wait-time fixtures and clearly labeled `/ctp/demo-faults/` routes. Explain static behavior
and make advertised links resolvable. Preserve the original seven example IDs when changing their routes
so previously loaded examples require the normal reviewed conflict/force merge instead of duplication.
- Copy all three Trailhead sample files (AOAI, inventory, and shipping) into the container build stage
and embed them unchanged in the application. Keep development-container path filters and packaging
tests aligned with the sample catalog. Embedding a sample must not activate it or seed persisted data.
- Compose the built-in example from all three checked-in, schema-valid `trailhead-aoai.json`,
`trailhead-inventory.json`, and `trailhead-shipping.json` embedded resources (41 endpoints).
Keep those files as the single source of definitions.
Expose the combined example read-only and activate it only through the validated, ETag-protected merge path.
- Keep the Trailhead Supply examples cohesive under `/aoai`, `/inventory`, and `/shipping`, with assistant, stock, reservation,
shipment, tracking, and clearly labeled demo-faults fixtures. Explain static behavior, preserve stable IDs,
and reserve sample HEAD support for one HEAD-only `/<api>/health` endpoint per API, returning an empty 200.
Inspection endpoints use GET only; sample health routes retain mock API-key protection
and do not replace the public application health probes.
Make advertised links resolvable. Never automatically delete or rewrite existing saved endpoints.
Apply the document-size limit and all semantic validation to the complete merge, including unrelated endpoints.
Keep the independent API-description limit at 25 groups.
- Any contract change must update the schema, models, source-generated JSON metadata, examples, management API/dashboard behavior, documentation, and tests together. Use the `mock-endpoint-change` skill.
4 changes: 4 additions & 0 deletions .github/instructions/dotnet.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ applyTo: "**/*.{cs,csproj,sln,props,targets}"
Apply configured administrator credentials to Security Settings, but permit setup when administration is anonymous.
Keep security persistence separate from endpoint configuration, activate only after a successful save,
and require the independent current strong security ETag for writes. Never export a key or its hash.
- Accept an optional deployment key through `MockApi__ApiKey` (32-256 ASCII letters, digits, hyphens, or
underscores). Seed only a missing security document, persist its SHA-256 hash before activation, and enable
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.
- 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.
Expand Down
12 changes: 11 additions & 1 deletion .github/instructions/frontend.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ applyTo: "src/MockAPI/wwwroot/**/*.{js,html,css},tests/{frontend,browser}/**/*.j
- Keep endpoint table selection/filter/group-local sort state in `dashboard-endpoint-table.js`, draft and captured-revision state in `dashboard-editor-dialog.js`, test-request batches and focus restoration in `dashboard-test-blade.js`, and statistics/request-log scope and rendering in `dashboard-statistics.js`. Keep management commands and confirmations in the entrypoint.
- Show all filtered endpoints without pagination in a vertically scrollable table with sticky headers.
Keep API groups alphabetical regardless of operation sort; default operations to ascending path order.
Provide a page-local collapse/expand-all group control for the current filtered result. Preserve
hidden groups' state and endpoint selection, keep individual toggles, and start new groups expanded.
Disable the bulk group control when no groups match; mixed state offers collapse-all.
Keep per-API selection checkboxes scoped to filtered endpoints, including collapsed groups; show
partial selection and synchronize with row and table-wide selection without clearing hidden selections.
Display group-relative paths before
the information button and operation name; retain complete paths for configuration, filtering, and requests.
- Keep API description drafts and captured revisions in `dashboard-api-description.js`; the endpoint table owns
group and endpoint information buttons. Use `bindDashboardTooltip` in `dashboard-dom.js` and the shared
information-button/popover styles for endpoint descriptions and test-blade help, with hover/focus previews
and caller-owned Escape dismissal and close cleanup. Close previews
when the pointer leaves the information button, including when it moves onto the preview.
Keep the shared CSS and placement height caps aligned at 400px and 60% of the viewport, further
bounded by available space above or below the trigger.
Preserve description casing and whitespace; use text nodes, never evaluate or inject configured content as HTML.
Render standalone `Description:` and `Technical implementation:` lines as bold text in information previews,
without interpreting other text as HTML or Markdown.
Endpoint information buttons open the existing endpoint editor. Group identity remains the
case-sensitive first path segment, and live updates must not replace an open draft's revision.
- Keep security Settings and the memory-only mock key in `dashboard-api-security.js`; rely on the management
Expand All @@ -27,7 +36,8 @@ applyTo: "src/MockAPI/wwwroot/**/*.{js,html,css},tests/{frontend,browser}/**/*.j
failed status checks show unknown protection rather than assuming protection is off.
Never persist that key in browser storage or attach it to management calls, exports, or redirect targets.
Exported requests reference caller-supplied variables; endpoint tests attach the key only after same-origin validation.
- Prefill editable illustrative JSON bodies and JSON request content types for POST, PUT, and PATCH in the test blade; use a reservation-specific sample for the built-in reservation routes. Samples are not schemas and do not imply business-field validation. Preserve deliberate edits and cleared fields across method changes. Never block malformed or missing bodies locally: display the backend's actual validation response. Keep request samples transient, not in endpoint configuration or browser storage.
Accept both generated and deployment-supplied keys: 32-256 ASCII letters, digits, hyphens, or underscores.
- Prefill editable illustrative JSON bodies and JSON request content types for POST, PUT, and PATCH in the test blade; use Trailhead inventory reservation and shipping samples for their respective built-in routes, aligned with portable exports. Samples are not schemas and do not imply business-field validation. Preserve deliberate edits and cleared fields across method changes. Never block malformed or missing bodies locally: display the backend's actual validation response. Keep request samples transient, not in endpoint configuration or browser storage.
- Give feature controllers explicit inputs, callbacks, and disposal. Use `dashboard-dom.js` event scopes for controller-owned listeners and separate scopes for replaceable rows/charts; delegate header-row removal rather than retaining removed rows. Invalidate asynchronous completions when an editor or blade closes, reopens, or is disposed.
- Prefer descriptive state and handler names, early returns, and named intermediate values. Avoid nested ternaries, implicit coercion tricks, dense expression chains, and large anonymous callbacks when explicit steps make the behavior easier to teach and review.
- 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.
Expand Down
8 changes: 6 additions & 2 deletions .github/skills/mock-endpoint-change/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ Use this skill when a change affects what an endpoint definition means or how it
## Required Evidence

- Checked-in examples validate against the schema.
- The `/ctp` Contoso Theme Parks examples retain stable IDs, resolve advertised lookup and redirect
links, document static reservation behavior, and migrate older examples only after explicit conflict review.
- The Trailhead Supply AOAI, inventory, and shipping examples retain stable IDs, resolve advertised resource
links, and document static business behavior. Their combined built-in example preserves unrelated
endpoints and metadata, includes all 41 sample endpoints without an endpoint-count cap, enforces document-size limits atomically,
and changes conflicts only after explicit review.
- Each sample API has one HEAD-only `/<api>/health` mock returning an empty 200; inspection calls are GET-only.
Sample health mocks retain instance API-key protection and are separate from public application health probes.
- Application-generated configuration validates against the schema and round-trips deterministically.
- Semantic conflicts produce actionable errors and leave the active snapshot unchanged.
- A runtime-created or edited endpoint is invocable immediately without process restart.
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/devcontainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ on:
- "MockAPI.slnx"
- "src/**"
- "tests/MockAPI.Tests/**"
- "config/mockapi.json"
- "config/trailhead-aoai.json"
- "config/trailhead-inventory.json"
- "config/trailhead-shipping.json"
- "scripts/install-git-hooks.cjs"
- "scripts/lib/pnpm-lock-registry.cjs"
- "start.sh"
Expand Down Expand Up @@ -51,7 +53,7 @@ jobs:
docker exec --user vscode mockapi-devcontainer bash .devcontainer/setup.sh
docker exec --user vscode mockapi-devcontainer bash -lc 'node --version; pnpm --version; pwsh --version; dotnet --version'
docker exec --detach --user vscode mockapi-devcontainer bash -lc './start.sh --action run > /tmp/mockapi.log 2>&1'
curl --retry 60 --retry-connrefused --retry-delay 1 --fail http://127.0.0.1:5080/health/ready
curl --retry 60 --retry-all-errors --retry-delay 1 --retry-max-time 120 --max-time 5 --fail http://127.0.0.1:5080/health/ready
curl --fail http://127.0.0.1:5080/__mockapi/ > /dev/null
- name: Capture startup diagnostics
if: failure()
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ COPY src/MockAPI/MockAPI.csproj src/MockAPI/
RUN dotnet restore src/MockAPI/MockAPI.csproj --source "$NUGET_SOURCE" -p:PublishAot=true

COPY src/MockAPI/ src/MockAPI/
COPY config/mockapi.json config/
COPY config/trailhead-aoai.json config/trailhead-inventory.json config/trailhead-shipping.json config/
RUN dotnet publish src/MockAPI/MockAPI.csproj --configuration Release --no-restore --output /app/publish -p:PublishAot=true -p:TreatWarningsAsErrors=true

# ---------------------------------------------------------------------
Expand Down
Loading