HTTP service that accepts a job (list of shell tasks with optional requires dependencies), sorts them into a valid execution order, and returns either sorted JSON or a bash script.
Greenfield project in this repository.
In scope: topological sort, input validation (Ecto), JSON + bash output, OpenAPI spec(would be a plus), Docker-compose local setup, tests.
Out of scope: executing shell commands, persistence, auth, job queues.
flowchart LR
Client -->|POST /api/sort| Router
Router --> Validation
Validation --> Sorter
Sorter -->|sorted tasks| JSON
Sorter -->|sorted tasks| Bash
Implementation details (algorithm choice, error shapes, endpoint naming, etc.) go in DECISIONS.md as each phase is completed.
-
mix new . --app task_resolver - Dependencies:
bandit,plug,ecto(changeset validation only),jason,credo - Supervision tree starting Bandit on port 4000
- Create empty
DECISIONS.md
- Contract Validation: Ecto embedded schema for task input (
name,command, optionalrequires). - Graph & Sorting: Model tasks as a dependency graph (DAG) and implement topological sort in
lib/task_resolver/core/sorter.ex. - Error Handling: Detect schema errors, cycles, duplicate names, and broken dependencies; return
{:error, reason}tuples. - Tests: Unit & contract tests for valid payloads, challenge example, cycles, unknown deps, and edge cases.
- Entry point:
TaskResolver.resolve_tasks/1gluesJobValidator→Sorterinto a single call for the future HTTP layer.
-
POST /resolvevia Plug router (seeDECISIONS.mdfor the endpoint naming choice). - Content negotiation via
Acceptheader:application/json(or*/*) → sorted tasks JSONtext/plainortext/x-shellscript→ bash script with shebang.
- Handle error mapping (map core
{:error, reason}to appropriate HTTP status codes: 400, 406, 415, 422). - OpenAPI specification (
docs/openapi.yaml). - Integration tests: 200 vs error codes, both output formats.
- Local-oriented
Dockerfile&docker-compose.ymlfor quick running. -
README.md— local setup, Docker-compose setup, curl examples. - Complete
DECISIONS.md— design choices and trade-offs. -
mix format+mix credo --strict.
| Artifact | Purpose |
|---|---|
| Working repo | Runnable app with tests |
README.md |
Setup and run instructions (local + Docker) |
DECISIONS.md |
Design choices and trade-offs, updated incrementally |
PLAN.md |
This high-level roadmap |
- Challenge example returns correct order in JSON and bash
- Invalid inputs (schema errors, cycles, bad codes) return correct error statuses
-
mix testpasses - App runs locally (
mix run --no-halt) and viadocker-compose up - OpenAPI spec is available/generated
- README and DECISIONS.md are complete