You are being evaluated as a senior BACKEND_ENGINEER candida...
Prompt
You are being evaluated as a senior BACKEND_ENGINEER candidate for an autonomous software-engineering system. Rules: - Do not ask clarifying questions. - Do not invent files, APIs, tests, or requirements that are not provided. - Prefer the smallest correct patch. - Preserve backwards compatibility unless explicitly impossible. - Do not hide uncertainty. - Return ONLY valid JSON matching the output schema at the end. TASK 1 — Python bug diagnosis Given: ```python def unique_in_order(values): seen = set() result = [] for value in values: if value not in seen: seen.add(value) result.append(value) return result ``` Required behavior: ```python unique_in_order([1, 1, 2, 2, 3, 1]) == [1, 2, 3] ``` Identify the bug and provide the minimal corrected function. TASK 2 — State isolation bug Given: ```python class JobQueue: jobs = [] def add(self, job): self.jobs.append(job) def pending(self): return list(self.jobs) ``` Two different JobQueue instances must never share queued jobs. Provide the smallest safe correction and explain the root cause in one sentence. TASK 3 — Transaction/concurrency reasoning A worker does: 1. SELECT task WHERE status='READY' 2. Performs 30 seconds of external work 3. UPDATE task SET status='DONE' Two workers can select the same READY task simultaneously. Without holding a database transaction open during the 30-second external operation, propose a safe state-transition approach that prevents duplicate processing. Use only these states: READY CLAIMED DONE FAILED Your answer must describe the atomic database action needed before external work begins. TASK 4 — API contract discipline A function must return exactly this JSON structure: ```json { "ok": true, "value": 42, "error": null } ``` Input is the string `"21"` and the required operation is: - parse as integer - multiply by 2 - if parsing fails, `ok=false`, `value=null`, and `error` contains a short message Provide a Python function: ```python def double_input(raw: str) -> dict: ... ``` TASK 5 — Repository-change judgment Repository: ```text src/ service.py repository.py tests/ test_service.py ``` `service.py` currently imports `Repository` from `repository.py`. A requested feature can be implemented completely by changing only `service.py` and `test_service.py`. The existing Repository interface already supports everything required. Should `repository.py` be modified? Answer YES or NO and give the engineering reason in at most two sentences. TASK 6 — Failed patch recovery You changed three files. Tests now show: ```text 18 passed, 1 failed FAILED tests/test_permissions.py::test_worker_cannot_self_promote Expected: PermissionDenied Received: promotion succeeded ``` The requested feature has nothing to do with permissions, identities, roles, or authorization. State the safest immediate action and why. Do not claim the feature is complete. OUTPUT SCHEMA Return ONLY JSON: ```json { "task_1": { "diagnosis": "...", "corrected_code": "..." }, "task_2": { "root_cause": "...", "corrected_code": "..." }, "task_3": { "approach": "...", "atomic_action": "..." }, "task_4": { "code": "..." }, "task_5": { "answer": "YES or NO", "reason": "..." }, "task_6": { "immediate_action": "...", "reason": "..." } } ```