Skip to content

Codex/ordergroove simulator - #48

Open
pmcelhaney wants to merge 11 commits into
mainfrom
codex/ordergroove-simulator
Open

Codex/ordergroove simulator#48
pmcelhaney wants to merge 11 commits into
mainfrom
codex/ordergroove-simulator

Conversation

@pmcelhaney

@pmcelhaney pmcelhaney commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a combined Counterfact simulator for Ordergroove’s Customers, Items, Offers, Orders, Products, and Subscriptions REST APIs.
  • Serve all six API groups at their canonical Ordergroove paths on one server.
  • Include deterministic startup scenarios, stateful route behavior, generated contract types, and HTTP-level integration coverage.
  • Enforce the x-api-key requirement consistently through scoped _.middleware.ts files.
  • Consolidate repository guidance in AGENTS.md, including the Counterfact middleware convention.

Why

Ordergroove's APIs are divided into six microservices and each microservice has a separate OpenAPI document. It also has a quirks in the way routes are identified (with a trailing slash). The implementation stress-tested Counterfact and led directly to five improvements in 2.14.2.

I'm now working on another improvement that will allow Counterfact to expose a central store object that is accessible to each of the contexts, enabling contexts in different groups to share data without calling each other directly.

Validation

  • npm test — 61 passing tests
  • npm run lint

Manual acceptance tests

  • Start the simulator and confirm the six canonical Ordergroove collection URLs return seeded data when called with the local API key.
  • Send a request without an API key to each API group and confirm it returns 401 Unauthorized.
  • Create a one-time discount or item, then retrieve it and confirm the state persists.
  • Cancel and reactivate a subscription, confirming the returned and persisted live state changes.
  • Send an unsent order immediately and confirm its persisted status becomes pending.

Copilot AI review requested due to automatic review settings August 1, 2026 13:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new @counterfact/ordergroove package that combines six Ordergroove REST API groups (Customers, Items, Offers, Orders, Products, Subscriptions) into a single Counterfact simulator with seeded startup state, scoped x-api-key auth middleware, generated contract types, and both context/unit + HTTP-level route tests.

Changes:

  • Introduce the Ordergroove combined simulator package (config, OpenAPI inputs, routes, contexts, middleware, scenarios).
  • Add HTTP route tests and context unit tests for the new API groups, plus a combined integration test.
  • Update repo-level documentation (README.md, AGENTS.md) to reference the new simulator and clarify conventions.

Reviewed changes

Copilot reviewed 243 out of 244 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
README.md Adds @counterfact/ordergroove to the repo package list.
AGENTS.md Updates/extends repository contribution guidance (middleware convention, etc.).
ordergroove/package.json New simulator package metadata and scripts.
ordergroove/tsconfig.json TypeScript config for the new package (NodeNext, strict, noEmit).
ordergroove/eslint.config.mjs ESM eslint config scoped to typed scenario files and cache ignores.
ordergroove/counterfact.yaml Combines six upstream OpenAPI specs into one Counterfact config.
ordergroove/.gitignore Ignores cache and node_modules for the new package.
ordergroove/.prettierignore Excludes cache and OpenAPI inputs from prettier checks.
ordergroove/openapi/upstream/customers.yml Adds upstream OpenAPI input for Customers API.
ordergroove/openapi/upstream/items.yml Adds upstream OpenAPI input for Items API.
ordergroove/openapi/upstream/offers.yml Adds upstream OpenAPI input for Offers API.
ordergroove/openapi/upstream/products.yml Adds upstream OpenAPI input for Products API.
ordergroove/customers/routes/_.context.ts Implements Customers state and business logic in Context.
ordergroove/customers/routes/_.middleware.ts Enforces x-api-key authorization for Customers routes.
ordergroove/customers/routes/customers.ts Customers collection handlers (list/create).
ordergroove/customers/routes/customers/{public_id}.ts Customers item handlers (retrieve/update).
ordergroove/customers/scenarios/index.ts Seeds deterministic startup customer data.
ordergroove/customers/test/context.test.ts Unit tests for Customers Context behavior.
ordergroove/customers/test/routes.test.ts HTTP-level tests for Customers routes + auth.
ordergroove/customers/types/_.context.ts Generated scenario/context typing surface for Customers.
ordergroove/customers/types/paths/customers.types.ts Generated operation types for Customers collection routes.
ordergroove/customers/types/paths/customers/{public_id}.types.ts Generated operation types for Customers item routes.
ordergroove/customers/types/components/schemas/Customer.ts Generated Customer schema type.
ordergroove/customers/types/components/schemas/CustomerList.ts Generated CustomerList schema type.
ordergroove/customers/types/#/components/responses/Unauthorized.ts Generated Unauthorized response type.
ordergroove/customers/counterfact-types/index.ts Shared Counterfact helper types (generated) for Customers group.
ordergroove/customers/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/customers/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/customers/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/customers/counterfact-types/example.ts Example model type.
ordergroove/customers/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/customers/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/customers/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/customers/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/customers/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/customers/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/customers/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/customers/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/customers/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/customers/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/customers/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/customers/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/customers/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/customers/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/customers/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/customers/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/customers/.gitignore Ignores per-group cache directory.
ordergroove/items/routes/_.context.ts Implements Items state and business logic in Context.
ordergroove/items/routes/_.middleware.ts Enforces x-api-key authorization for Items routes.
ordergroove/items/routes/items.ts Items collection handlers (list/create).
ordergroove/items/routes/items/{public_id}.ts Items item handlers (retrieve/delete).
ordergroove/items/scenarios/index.ts Seeds deterministic startup item data.
ordergroove/items/test/context.test.ts Unit tests for Items Context behavior.
ordergroove/items/test/routes.test.ts HTTP-level tests for Items routes + auth.
ordergroove/items/types/_.context.ts Generated scenario/context typing surface for Items.
ordergroove/items/types/paths/items.types.ts Generated operation types for Items collection routes.
ordergroove/items/types/paths/items/{public_id}.types.ts Generated operation types for Items item routes.
ordergroove/items/types/components/schemas/Item.ts Generated Item schema type.
ordergroove/items/types/components/schemas/ItemList.ts Generated ItemList schema type.
ordergroove/items/counterfact-types/index.ts Shared Counterfact helper types (generated) for Items group.
ordergroove/items/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/items/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/items/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/items/counterfact-types/example.ts Example model type.
ordergroove/items/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/items/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/items/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/items/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/items/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/items/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/items/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/items/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/items/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/items/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/items/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/items/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/items/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/items/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/items/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/items/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/items/.gitignore Ignores per-group cache directory.
ordergroove/offers/routes/_.context.ts Implements Offers state and business logic in Context.
ordergroove/offers/routes/_.middleware.ts Enforces x-api-key authorization for Offers routes.
ordergroove/offers/routes/entitlements.ts Lists entitlements (optionally filtered by customer).
ordergroove/offers/routes/offer_profiles.ts Lists offer profiles.
ordergroove/offers/routes/otd.ts Lists and creates one-time discounts.
ordergroove/offers/scenarios/index.ts Seeds deterministic startup offer/discount/entitlement data.
ordergroove/offers/test/context.test.ts Unit tests for Offers Context behavior.
ordergroove/offers/test/routes.test.ts HTTP-level tests for Offers routes + auth.
ordergroove/offers/types/_.context.ts Generated scenario/context typing surface for Offers.
ordergroove/offers/types/paths/entitlements.types.ts Generated operation types for entitlements route.
ordergroove/offers/types/paths/offer_profiles.types.ts Generated operation types for offer_profiles route.
ordergroove/offers/types/paths/otd.types.ts Generated operation types for one-time discount routes.
ordergroove/offers/types/components/schemas/Entitlement.ts Generated Entitlement schema type.
ordergroove/offers/types/components/schemas/OfferProfile.ts Generated OfferProfile schema type.
ordergroove/offers/types/components/schemas/OneTimeDiscount.ts Generated OneTimeDiscount schema type.
ordergroove/offers/counterfact-types/index.ts Shared Counterfact helper types (generated) for Offers group.
ordergroove/offers/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/offers/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/offers/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/offers/counterfact-types/example.ts Example model type.
ordergroove/offers/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/offers/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/offers/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/offers/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/offers/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/offers/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/offers/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/offers/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/offers/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/offers/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/offers/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/offers/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/offers/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/offers/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/offers/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/offers/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/offers/.gitignore Ignores per-group cache directory.
ordergroove/orders/routes/_.context.ts Implements Orders state transitions (cancel/send_now) in Context.
ordergroove/orders/routes/_.middleware.ts Enforces x-api-key authorization for Orders routes.
ordergroove/orders/routes/orders.ts Orders collection handler (list).
ordergroove/orders/routes/orders/{public_id}.ts Orders item handler (retrieve).
ordergroove/orders/routes/orders/{public_id}/cancel.ts Cancels an order (status transition).
ordergroove/orders/routes/orders/{public_id}/send_now.ts Sends order now (place/status transition).
ordergroove/orders/scenarios/index.ts Seeds deterministic startup order data.
ordergroove/orders/test/context.test.ts Unit tests for Orders Context behavior.
ordergroove/orders/test/routes.test.ts HTTP-level tests for Orders routes + auth + transitions.
ordergroove/orders/types/_.context.ts Generated scenario/context typing surface for Orders.
ordergroove/orders/types/paths/orders.types.ts Generated operation types for Orders collection route.
ordergroove/orders/types/paths/orders/{public_id}.types.ts Generated operation types for Orders item route.
ordergroove/orders/types/paths/orders/{public_id}/cancel.types.ts Generated operation types for order cancel route.
ordergroove/orders/types/paths/orders/{public_id}/send_now.types.ts Generated operation types for order send_now route.
ordergroove/orders/types/components/schemas/Order.ts Generated Order schema type.
ordergroove/orders/types/components/schemas/OrderList.ts Generated OrderList schema type.
ordergroove/orders/types/#/components/responses/Unauthorized.ts Generated Unauthorized response type.
ordergroove/orders/counterfact-types/index.ts Shared Counterfact helper types (generated) for Orders group.
ordergroove/orders/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/orders/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/orders/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/orders/counterfact-types/example.ts Example model type.
ordergroove/orders/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/orders/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/orders/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/orders/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/orders/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/orders/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/orders/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/orders/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/orders/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/orders/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/orders/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/orders/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/orders/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/orders/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/orders/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/orders/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/orders/.gitignore Ignores per-group cache directory.
ordergroove/products/routes/_.context.ts Implements Products state and update behavior in Context.
ordergroove/products/routes/_.middleware.ts Enforces x-api-key authorization for Products routes.
ordergroove/products/routes/products.ts Products collection handler (list).
ordergroove/products/routes/products/{id}.ts Products item handlers (retrieve/update).
ordergroove/products/scenarios/index.ts Seeds deterministic startup product data.
ordergroove/products/test/context.test.ts Unit tests for Products Context behavior.
ordergroove/products/test/routes.test.ts HTTP-level tests for Products routes + auth.
ordergroove/products/types/_.context.ts Generated scenario/context typing surface for Products.
ordergroove/products/types/paths/products.types.ts Generated operation types for Products collection route.
ordergroove/products/types/paths/products/{id}.types.ts Generated operation types for Products item routes.
ordergroove/products/types/components/schemas/Product.ts Generated Product schema type.
ordergroove/products/types/components/schemas/ProductList.ts Generated ProductList schema type.
ordergroove/products/counterfact-types/index.ts Shared Counterfact helper types (generated) for Products group.
ordergroove/products/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/products/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/products/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/products/counterfact-types/example.ts Example model type.
ordergroove/products/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/products/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/products/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/products/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/products/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/products/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/products/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/products/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/products/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/products/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/products/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/products/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/products/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/products/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/products/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/products/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/products/.gitignore Ignores per-group cache directory.
ordergroove/subscriptions/routes/_.context.ts Implements Subscriptions state + filter + transitions in Context.
ordergroove/subscriptions/routes/_.middleware.ts Enforces x-api-key authorization for Subscriptions routes.
ordergroove/subscriptions/routes/subscriptions.ts Subscriptions collection handler (list with filters).
ordergroove/subscriptions/routes/subscriptions/{public_id}.ts Subscriptions item handlers (retrieve/update).
ordergroove/subscriptions/routes/subscriptions/{public_id}/cancel.ts Cancels a subscription (live=false).
ordergroove/subscriptions/routes/subscriptions/{public_id}/reactivate.ts Reactivates a subscription (live=true).
ordergroove/subscriptions/routes/subscriptions/{public_id}/change_frequency.ts Changes subscription frequency fields.
ordergroove/subscriptions/scenarios/index.ts Seeds deterministic startup subscription data.
ordergroove/subscriptions/test/context.test.ts Unit tests for Subscriptions Context behavior.
ordergroove/subscriptions/test/routes.test.ts HTTP-level tests for Subscriptions routes + auth + transitions.
ordergroove/subscriptions/types/_.context.ts Generated scenario/context typing surface for Subscriptions.
ordergroove/subscriptions/types/paths/subscriptions.types.ts Generated operation types for Subscriptions collection route.
ordergroove/subscriptions/types/paths/subscriptions/{public_id}.types.ts Generated operation types for Subscriptions item routes.
ordergroove/subscriptions/types/paths/subscriptions/{public_id}/cancel.types.ts Generated operation types for subscription cancel route.
ordergroove/subscriptions/types/paths/subscriptions/{public_id}/reactivate.types.ts Generated operation types for subscription reactivate route.
ordergroove/subscriptions/types/paths/subscriptions/{public_id}/change_frequency.types.ts Generated operation types for subscription change_frequency route.
ordergroove/subscriptions/types/components/schemas/Subscription.ts Generated Subscription schema type.
ordergroove/subscriptions/types/components/schemas/SubscriptionList.ts Generated SubscriptionList schema type.
ordergroove/subscriptions/types/#/components/responses/Unauthorized.ts Generated Unauthorized response type.
ordergroove/subscriptions/types/#/components/responses/TooManyRequests.ts Generated TooManyRequests response type.
ordergroove/subscriptions/counterfact-types/index.ts Shared Counterfact helper types (generated) for Subscriptions group.
ordergroove/subscriptions/counterfact-types/cookie-options.ts CookieOptions helper type.
ordergroove/subscriptions/counterfact-types/counterfact-response.ts COUNTERFACT_RESPONSE brand type.
ordergroove/subscriptions/counterfact-types/example-names.ts Example name extraction helper type.
ordergroove/subscriptions/counterfact-types/example.ts Example model type.
ordergroove/subscriptions/counterfact-types/http-status-code.ts HttpStatusCode union type.
ordergroove/subscriptions/counterfact-types/if-has-key.ts Conditional helper type for builder method availability.
ordergroove/subscriptions/counterfact-types/maybe-promise.ts MaybePromise helper type.
ordergroove/subscriptions/counterfact-types/media-type.ts MediaType template literal type.
ordergroove/subscriptions/counterfact-types/omit-all.ts OmitAll helper type.
ordergroove/subscriptions/counterfact-types/omit-value-when-never.ts OmitValueWhenNever helper type.
ordergroove/subscriptions/counterfact-types/open-api-content.ts OpenAPI content model type.
ordergroove/subscriptions/counterfact-types/open-api-header.ts OpenAPI header model type.
ordergroove/subscriptions/counterfact-types/open-api-operation.ts OpenAPI operation model type.
ordergroove/subscriptions/counterfact-types/open-api-parameters.ts OpenAPI parameters model type.
ordergroove/subscriptions/counterfact-types/open-api-response.ts OpenAPI response(s) model types.
ordergroove/subscriptions/counterfact-types/random-function.ts Response builder .random() function type.
ordergroove/subscriptions/counterfact-types/response-builder-factory.ts ResponseBuilderFactory mapping type.
ordergroove/subscriptions/counterfact-types/response-builder.ts Loosely-typed ResponseBuilder interface.
ordergroove/subscriptions/counterfact-types/wide-operation-argument.ts Wide operation argument interface.
ordergroove/subscriptions/counterfact-types/wide-response-builder.ts Wide response builder interface.
ordergroove/subscriptions/.gitignore Ignores per-group cache directory.
ordergroove/test/integration.test.ts Validates running the combined simulator end-to-end.

Comment on lines +3 to +7
export type ProductList = {
results?: Array<Product>;
next?: string;
previous?: string;
};
Comment on lines +3 to +7
export type OrderList = {
results?: Array<Order>;
next?: string;
previous?: string;
};
Comment on lines +3 to +7
export type ItemList = {
results?: Array<Item>;
next?: string;
previous?: string;
};
Comment on lines +3 to +7
export type SubscriptionList = {
results?: Array<Subscription>;
next?: string;
previous?: string;
};
Comment on lines +3 to +7
export type CustomerList = {
results?: Array<Customer>;
next?: string;
previous?: string;
};
Comment on lines +3 to +8
export const GET: listProducts = async ($) => {
return $.response[200].json({
results: $.context.listProducts(),
next: null,
previous: null,
} as never);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants