# abc-bench / task_aws_samples_serverless_test_samples__unicorn_reservation_apis - taskset: [abc-bench](https://harnessreport.com/tasks/abc-bench.md) - difficulty: hard - category: Infrastructure - language: - runnable from the site: no - agent timeout: 3600s ## Results by harness _none yet_ ## Instruction ``` You are a backend development expert. Please inspect the backend project located in the current directory, determine its programming language and architectural style, and then complete the following code implementation and environment setup tasks. Unicorn Reservation APIs – Backend Exercise You are restoring the FastAPI-based local stub that mirrors the Unicorn Reservation System. The service reads demo data into `InventoryStore` and exposes the `/locations`, `/list/{location}`, `/checkout`, and `/geturl` endpoints. Implement the missing logic so automated tests can interact with the local server exactly like the deployed AWS stack. InventoryStore requirements 1. `get_locations` must return a sorted list of unique `Location` values that currently exist in the in-memory `_unicorns` collection. The method must guard access with the provided threading lock. 2. `list_by_location(location, available_only)` must perform a case-insensitive comparison on the requested location, return shallow copies of every matching unicorn record, and optionally filter to entries whose `Status` equals `"AVAILABLE"` when `available_only` is true. 3. `reserve_unicorn(unicorn_name, reserved_for)` must locate a unicorn by name (case-insensitive), ensure it is marked `"AVAILABLE"`, update its `Status` to `"RESERVED"`, and set the `Reserved By` field to the provided name. Raise `ValueError` if the unicorn exists but is not available, and `KeyError` if no matching record exists. HTTP handler behavior 1. `GET /locations` must return `{"locations": [...]}` by delegating to `InventoryStore.get_locations()`. 2. `GET /list/{location}` must call `list_by_location`, honor the `available` query flag, ignore the `page_token` input, and respond with `{ "unicorn_list": [...], "page_token": "END" }`. Each list entry should include the same shape as stored in memory (`Name`, `Location`, `Status`, `Reserved By`). 3. `POST /checkout` receives form fields `unicorn` and `reserved_for`. Reject blank `reserved_for` values with HTTP 400, translate `KeyError` from the store into HTTP 404, translate `ValueError` into HTTP 400, and return a plaintext body of `"OK"` upon success. 4. `GET /geturl` must recreate the synthetic S3 presigned POST response used by the frontend. Build a UTC timestamp in `YYYYMMDDTHHMMSSZ` form, derive a `daily_prefix` (`YYYY/MM/DD`), and create an object key such as `"{daily_prefix}/unicorn_load_{timestamp}_{uuid4}.csv"`. The JSON payload must include the `url` pointing at `https://{DEFAULT_BUCKET}.s3.amazonaws.com` and a `fields` dictionary containing `key`, `x-amz-algorithm`, `x-amz-credential`, `x-amz-date`, `policy`, and `x-amz-signature` keys filled with deterministic strings that follow the original format (use the timestamp and randomly generated UUIDs just like the AWS Lambda implementation). Constraints and notes - Preserve the in-memory data contract so the front-end can rely on the `Reserved By` field even when a unicorn is available (use the placeholder `"- available -"`). - Keep the functions thread-safe by using the existing lock any time you read or mutate `_unicorns`. - Do not introduce pagination; always set `page_token` in responses to the literal string `"END"` for now. - Keep the external surface compatible with the AWS backend so integration and contract tests remain valid. Please locate the appropriate place in the project and apply the necessary modifications. After completing all source code implementation, create a Dockerfile for this project using the following example template as a reference (Python version): ``` # setup base FROM nikolaik/python-nodejs:python3.12-nodejs22-bullseye RUN apt-get update && apt-get install -y sqlite3 # install dependencies and copy project files WORKDIR /app COPY . /app/ RUN python3 -m pip install -r requirements.txt ENTRYPOINT ["python3", "app.py"] ``` Notes: 1. Ensure that all required project dependencies are properly installed inside the image. 2. The generated Dockerfile must successfully build and run the application. 3. The Dockerfile must be created in the root directory of the backend project, i.e `/app/aws-samples_serverless-test-samples/Dockerfile` ``` --- Harness Report runs agent harnesses from their GitHub repos on Harbor tasks and records every model call. Every page is also `.md` and `.json`; index: https://harnessreport.com/llms.txt · MCP: https://harnessreport.com/mcp