← run

lc-02-buried-routes

1.000
3/3 tests· long-context
Challenge · difficulty 1/5
# Service-route resolver

Below is a read-only snapshot of our internal `mesh/` package — 8 service-routing
modules. Each module defines its own `ROUTES_NN` table mapping upstream status codes to the
downstream service that handles them.

Your task: implement `solution.py` with a function

```python
def resolve(code: int) -> str:
    ...
```

that reproduces **exactly the routing table defined in module `svc_04`** (the
`ROUTES_04` dict). For a status code present in that table, return its service name;
for any other code, return `"unknown"`.

Rules:
- Use the table from `svc_04` ONLY. The other modules are decoys with different tables.
- Do NOT import from the snapshot (it is not packaged). Inline the mapping you need.
- Return the literal string `"unknown"` for unrouted codes.

The snapshot follows.

---

# ============================ svc_00.py ============================
"""Service routing for the svc_00 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_00 = {
    1110: 'zephyr-beacon-61',
    1949: 'flint-harbor-86',
    1475: 'flint-lattice-46',
    1081: 'verde-gateway-91',
    1013: 'verde-forge-48',
    1670: 'cobalt-lattice-93',
    1330: 'ivory-prism-74',
    1811: 'harbor-beacon-53',
    1415: 'loom-anchor-60',
    1640: 'onyx-conduit-30',
}


def resolve_00(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_00.get(code, "unknown")


def is_routed_00(code: int) -> bool:
    return code in ROUTES_00


# ============================ svc_01.py ============================
"""Service routing for the svc_01 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_01 = {
    1887: 'dusk-spindle-17',
    1810: 'kelp-cipher-43',
    1479: 'quartz-broker-45',
    1382: 'yarrow-prism-59',
    1936: 'slate-gateway-32',
    1754: 'ivory-gateway-20',
    1807: 'zephyr-quorum-74',
    1322: 'nimbus-gateway-72',
    1628: 'harbor-spindle-14',
    1862: 'dusk-cascade-85',
}


def resolve_01(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_01.get(code, "unknown")


def is_routed_01(code: int) -> bool:
    return code in ROUTES_01


# ============================ svc_02.py ============================
"""Service routing for the svc_02 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_02 = {
    1645: 'tundra-vault-53',
    1775: 'onyx-relay-26',
    1519: 'amber-relay-90',
    1679: 'kelp-harbor-75',
    1092: 'jade-atlas-59',
    1550: 'pyrite-warden-36',
    1028: 'mica-warden-33',
    1599: 'pyrite-lattice-40',
    1641: 'tundra-relay-71',
    1123: 'willow-lattice-91',
}


def resolve_02(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_02.get(code, "unknown")


def is_routed_02(code: int) -> bool:
    return code in ROUTES_02


# ============================ svc_03.py ============================
"""Service routing for the svc_03 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_03 = {
    1682: 'dusk-gateway-49',
    1602: 'pyrite-prism-27',
    1571: 'verde-lattice-66',
    1156: 'xenon-vault-42',
    1219: 'willow-prism-44',
    1370: 'loom-anchor-83',
    1764: 'quartz-prism-93',
    1676: 'quartz-relay-35',
    1677: 'onyx-vault-93',
    1236: 'jade-beacon-29',
}


def resolve_03(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_03.get(code, "unknown")


def is_routed_03(code: int) -> bool:
    return code in ROUTES_03


# ============================ svc_04.py ============================
"""Service routing for the svc_04 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_04 = {
    1402: 'mica-lattice-97',
    1604: 'jade-lattice-34',
    1310: 'dusk-broker-38',
    1210: 'ivory-prism-21',
    1263: 'amber-warden-15',
    1366: 'yarrow-vault-11',
    1880: 'mica-spindle-49',
    1597: 'slate-lattice-78',
    1198: 'mica-broker-93',
    1626: 'cobalt-quorum-63',
}


def resolve_04(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_04.get(code, "unknown")


def is_routed_04(code: int) -> bool:
    return code in ROUTES_04


# ============================ svc_05.py ============================
"""Service routing for the svc_05 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_05 = {
    1257: 'umber-spindle-28',
    1899: 'cobalt-beacon-93',
    1069: 'kelp-prism-58',
    1837: 'willow-vault-16',
    1203: 'flint-relay-83',
    1938: 'onyx-atlas-52',
    1395: 'garnet-beacon-46',
    1543: 'dusk-spindle-69',
    1576: 'garnet-anchor-19',
    1320: 'kelp-spindle-22',
}


def resolve_05(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_05.get(code, "unknown")


def is_routed_05(code: int) -> bool:
    return code in ROUTES_05


# ============================ svc_06.py ============================
"""Service routing for the svc_06 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_06 = {
    1188: 'mica-anchor-74',
    1485: 'umber-quorum-17',
    1581: 'onyx-vault-31',
    1149: 'onyx-cipher-34',
    1801: 'umber-gateway-37',
    1732: 'willow-cascade-76',
    1532: 'cobalt-anchor-36',
    1131: 'slate-warden-12',
    1508: 'flint-conduit-84',
    1079: 'slate-cascade-67',
}


def resolve_06(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_06.get(code, "unknown")


def is_routed_06(code: int) -> bool:
    return code in ROUTES_06


# ============================ svc_07.py ============================
"""Service routing for the svc_07 edge cluster.

Auto-generated from the service mesh manifest. Maps upstream status codes to the
downstream service that should handle the retry/escalation for that code.
"""

ROUTES_07 = {
    1773: 'slate-spindle-43',
    1927: 'cobalt-lattice-15',
    1051: 'nimbus-vault-87',
    1715: 'ivory-lattice-62',
    1198: 'umber-cipher-47',
    1906: 'ember-beacon-28',
    1397: 'verde-relay-17',
    1657: 'basal-beacon-91',
    1164: 'rill-atlas-93',
    1580: 'dusk-atlas-29',
}


def resolve_07(code: int) -> str:
    """Return the handling service for a status code, or "unknown" if unrouted."""
    return ROUTES_07.get(code, "unknown")


def is_routed_07(code: int) -> bool:
    return code in ROUTES_07

tests/test_resolve.py
from solution import resolve


def test_routes_from_the_needle_module():
    # every code in module svc_04's ROUTES_04 table resolves to its service
    assert resolve(1402) == 'mica-lattice-97'
    assert resolve(1604) == 'jade-lattice-34'
    assert resolve(1310) == 'dusk-broker-38'
    assert resolve(1210) == 'ivory-prism-21'
    assert resolve(1263) == 'amber-warden-15'
    assert resolve(1366) == 'yarrow-vault-11'
    assert resolve(1880) == 'mica-spindle-49'
    assert resolve(1597) == 'slate-lattice-78'
    assert resolve(1198) == 'mica-broker-93'
    assert resolve(1626) == 'cobalt-quorum-63'


def test_unrouted_code_is_unknown():
    assert resolve(1000) == "unknown"      # in no module's table


def test_decoy_module_code_is_unknown():
    # 1013 appears in a DIFFERENT module's table but not in svc_04 -> unknown
    assert resolve(1013) == "unknown"
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.
Proposed solution


To solve this problem, we need to create a function that routes status codes to specific services based on a predefined mapping from a specific module. The function should return the corresponding service name for a given status code if it exists in the mapping, otherwise, it should return "unknown".

### Approach
1. **Extract the Routing Table**: We focus on the routing table from the `svc_04` module, which contains specific status codes and their corresponding service names.
2. **Define the Mapping**: We create a dictionary that mirrors the `ROUTES_04` from `svc_04.py` to map each status code to its respective service.
3. **Implement the Function**: The function `resolve` will take an integer status code, check against our predefined dictionary, and return the corresponding service name or "unknown" if the code is not found.

### Solution Code

```python
def resolve(code: int) -> str:
    routes = {
        1402: 'mica-lattice-97',
        1604: 'jade-lattice-34',
        1310: 'dusk-broker-38',
        1210: 'ivory-prism-21',
        1263: 'amber-warden-15',
        1366: 'yarrow-vault-11',
        1880: 'mica-spindle-49',
        1597: 'slate-lattice-78',
        1198: 'mica-broker-93',
        1626: 'cobalt-quorum-63',
    }
    return routes.get(code, "unknown")
```

### Explanation
- **Dictionary Definition**: The dictionary `routes` is defined within the `resolve` function to map each status code to its corresponding service name as specified in `svc_04`.
- **Lookup Mechanism**: The function uses the `get` method of the dictionary to check if the provided status code exists in the dictionary. If it does, the corresponding service name is returned. If not, the default value "unknown" is returned.

This approach ensures that we efficiently route status codes to the correct services using a direct lookup, providing an optimal solution to the problem.

Test output (stdout)

...                                                                      [100%]
3 passed in 0.01s
Reasoning (chain-of-thought)

Okay, I need to solve this problem where I have to write a Python function called resolve that takes an integer code and returns a string representing the service name based on the routing table from svc_04. If the code isn't in that table, it should return "unknown".

First, I should look at the provided modules. Each module has a dictionary like ROUTES_00, ROUTES_01, etc. My task is to focus only on svc_04's ROUTES_04. So I need to extract that mapping.

Looking at svc_04.py, the ROUTES_04 dictionary has the following key-value pairs:
1402: 'mica-lattice-97',
1604: 'jade-lattice-34',
1310: 'dusk-broker-38',
1210: 'ivory-prism-21',
1263: 'amber-warden-15',
1366: 'yarrow-vault-11',
1880: 'mica-spindle-49',
1597: 'slate-lattice-78',
1198: 'mica-broker-93',
1626: 'cobalt-quorum-63'

So I need to create a similar dictionary in my solution. The function should check if the code is a key in this dictionary. If it is, return the corresponding value; else, return "unknown".

I can't import anything from the snapshot, so I have to inline the mapping. That means I'll define the dictionary directly inside the resolve function or in the solution file.

So the plan is:

1. Create a dictionary in the solution that mirrors ROUTES_04.
2. The resolve function will take the code as input.
3. Use the get method of the dictionary to return the service name or "unknown" if the code isn't found.

Wait, how about the function's structure? The function needs to be named resolve, take code as an int, and return a string.

So in solution.py, I'll define the dictionary first, then the function.

Let me write that out.

First, define the routes inside the function or outside? It's better to define it inside the function if it's only used there, but since the function is called once, it's more efficient to have it inside. Alternatively, define it outside for clarity. Either way works.

But in Python, it's common to define constants outside functions, but for a small dictionary, it's fine either way.

So in the code, I'll write:

def resolve(code: int) -> str:
    routes = {
        1402: 'mica-lattice-97',
        1604: 'jade-lattice-34',
        1310: 'dusk-broker-38',
        1210: 'ivory-prism-21',
        1263: 'amber-warden-15',
        1366: 'yarrow-vault-11',
        1880: 'mica-spindle-49',
        1597: 'slate-lattice-78',
        1198: 'mica-broker-93',
        1626: 'cobalt-quorum-63',
    }
    return routes.get(code, "unknown")

Wait, but looking back, the keys are all integers, so that should work.

Testing this function with some examples:

For code 1402, it should return 'mica-lattice-97'.
For code 1210, 'ivory-prism-21'.
For a code not in the dictionary, like 404, it returns 'unknown'.

Yes, that should cover it.

I think that's all. So the solution is to create the dictionary as shown and use the get method with a default of "unknown".