Skip to main content
This course teaches the mental model behind Simile HCL before it asks you to memorize syntax. Each lesson ends with a multiple-choice check. Choose an answer before opening the explanation.

1. Start with the contract boundary

OpenAPI describes the HTTP contract: routes, operation IDs, request schemas, response statuses, media types, and response schemas. Simile HCL describes public behavior that cannot be proved from those schemas alone.
createOrder must exactly match an OpenAPI operationId. The HCL cannot invent a route or choose a status that OpenAPI does not declare. Question 1. Where should a required JSON request field be defined?
  • A. In the OpenAPI request schema
  • B. In a behavior block
  • C. In a scenario
A. OpenAPI owns the HTTP shape. HCL may refine behavior, but it does not replace the contract.
Question 2. What happens if response.status = 201 is not declared by that OpenAPI operation?
  • A. Simile silently adds it
  • B. Compilation fails
  • C. Simile changes it to 200
B. Cross-source contradictions fail before the service starts.

2. Name reachable outcomes

An outcome is one concrete result the operation can publicly produce.
when.path is a JSON Pointer into Simile’s normalized request document. Multiple when blocks are combined with logical AND: all predicates must match. The body is provider-authored and must validate against the OpenAPI response schema for the selected status and media type. Question 3. Two when blocks appear in one outcome. When is it eligible?
  • A. When either predicate matches
  • B. When both predicates match
  • C. Only when a scenario selects it
B. Conditions within one outcome are conjunctive.

3. Reuse error families

An error_set collects named outcomes that many operations can share. Attach it to one behavior or apply it by OpenAPI tag.
Use protocol_error for failures discovered by the protocol adapter—malformed JSON, unsupported media types, authentication failure—not for an ordinary domain outcome. Question 4. A card is valid JSON but the provider declines it. Which construct fits?
  • A. protocol_error
  • B. A named outcome, possibly in an error_set
  • C. A stochastic fault
B. Decline is a service result. Protocol errors describe failures at the request/transport boundary.

4. Use scenarios for exact tests

A scenario is an opaque, deterministic test control. It can select named outcomes and inject named environmental faults for several operations.
For a long-running service, select it when the process starts:
For a one-shot operation, select it on run:
Public request conditions can still trigger the same outcome without a scenario. A scenario exists so a test can request one case directly and repeatably, especially when the real provider decision is intentionally private. Question 5. Does a scenario describe the provider’s internal decision tree?
  • A. Yes
  • B. No; it names a public test case and its observable result
  • C. Only in verbose mode
B. Scenarios preserve the public behavior while hiding private rules and thresholds.
Question 6. What does simile start inttegro --scenario payment_declines do?
  • A. Activates that scenario for the lifetime of the server process
  • B. Applies it only to the first request
  • C. Rewrites the registered configuration
A. The selection is process-wide for that invocation and does not mutate the registry.

5. Model effects without vendors

Backends name supporting systems. Effects attach consequences to committed operations. Async units describe actions that run outside the response-critical path.
Use queue, not SQS; db, not PostgreSQL; cache, not Redis. The emulator needs the capability, not a leak of the production implementation. The synchronous database action commits and checkpoints before delivery. The named queue action dispatches afterwards, so it does not add response latency. Question 7. Which backend declaration is portable?
  • A. backend "db" "orders" {}
  • B. backend "postgres" "orders" {}
  • C. backend "rds" "orders" {}
A. Backend kinds deliberately describe provider-neutral capabilities.

6. Separate service results from environmental faults

A domain error is a deterministic outcome. A fault changes how an otherwise valid operation is delivered: delay, disconnection, or another environmental disruption.
Catalog faults bring their own descriptions and sensible defaults. Custom faults may provide a description explicitly. Question 8. A request commits successfully, but the caller never receives the response. Is that an outcome or a fault?
  • A. Outcome
  • B. Fault
  • C. Protocol error
B. The service result exists; delivery was disrupted after commit.

7. Bound stochastic testing

Fault profiles opt a service into controlled random environmental failures.
Parameter and domain errors are never randomized. A profile can activate only environmental faults. Probability, cooldown, and maximum consecutive activations keep stochastic testing useful instead of hostile. Question 9. May a profile randomly return payment_method_declined for a valid payment method?
  • A. Yes
  • B. No
  • C. Only with a seed
B. Domain outcomes require a matching public condition or an explicit scenario.

8. Compose and compile the service

The service block connects the listener, OpenAPI source, and HCL modules.
Compilation resolves every operation ID, outcome, backend, async declaration, scenario, and fault before a listener binds. Human-readable descriptions are stored in the compiled artifact for simile describe; they never influence behavior.
Question 10. What is the runtime authority for a registered service?
  • A. The original files at their old paths
  • B. The compiled artifact installed in the registry revision
  • C. The current working directory
B. Registration is a compiled, immutable snapshot. describe reads that same artifact.

9. Capstone

You need a test that creates an order, forces a public requires_payment result, persists the committed order, queues follow-up work, and independently tests a response lost after commit. Which design is sound today?
  • A. Put every rule and vendor name into one large scenario
  • B. Define HTTP shapes in OpenAPI; define the named outcome, effect, and async unit in HCL; use one scenario to select the outcome and another to inject the environmental fault
  • C. Return a random valid response and let the client infer what happened
B. Each unit owns one concern, and their composition expresses a larger public behavior without exposing private implementation details.
Continue with the language specification for normative syntax, the glossary for terms, or Configuration to assemble a real service.