Repository navigation
Commit 8aa77f8
fix(extract): a decorator with arguments but no path is not a route
Distilled from #1245 by Andrew Hundt (a slice of d15071c), with a
different rule than upstream chose.
Python's unittest.mock is used as a decorator:
@patch("subprocess.run")
def test_runs(self, run): ...
decorator_method_name maps a bare `patch` to the HTTP method PATCH, and
try_route_from_decorator_call accepts a receiver-less decorator call.
When extract_route_path_from_args then finds nothing path-shaped, the
function falls back to "/". So every mock-decorated test function became
a Route handler, PATCH "/", and every one of those was wrong.
Upstream fixed it with a has_receiver heuristic. That still admits
@mock.patch("os.getcwd") (it has a receiver) and would reject the bare
framework decorators Litestar and BlackSheep use, @get("/x"). The rule
here is about the arguments, not the callee: a decorator call that HAS
arguments but none of them path-shaped is not a route. The "/" default
survives only for a zero-argument call such as @app.route(), which is the
one case where "/" is what the framework means. No test on main relied on
the default for a call with non-path arguments; checked before changing
it.
RED before the fix:
extract_python_mock_patch_is_not_route
FAIL tests/test_extraction.c:4023: mocked->route_path is not NULL
extract_python_bare_decorator_route_rules
FAIL tests/test_extraction.c:4063: mocked->route_path is not NULL
The second test also pins the two shapes that must keep working: bare
@get("/health") still yields a GET route, and zero-argument @app.route()
still yields "/" ANY -- those assertions passed before the fix and after.
GREEN after: extraction 351 passed; extraction pipeline edge_types_probe
route_canon cross_repo infrascan lang_contract 754 passed, with the
CALLS-breadth contract at 54 languages / 0 failures. The single remaining
red in both runs is extract_spill_round_trip_keeps_every_field refusing to
spill onto a disk below its 10 GB floor -- this host, not this change.
Co-authored-by: Andrew Hundt <ATHundt@gmail.com>
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>1 parent 92abefa commit 8aa77f8
2 files changed
Lines changed: 81 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1591 | 1591 | | |
1592 | 1592 | | |
1593 | 1593 | | |
1594 | | - | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
1595 | 1599 | | |
1596 | 1600 | | |
1597 | 1601 | | |
| |||
1616 | 1620 | | |
1617 | 1621 | | |
1618 | 1622 | | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
1619 | 1626 | | |
1620 | 1627 | | |
1621 | 1628 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4001 | 4001 | | |
4002 | 4002 | | |
4003 | 4003 | | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
| 4016 | + | |
| 4017 | + | |
| 4018 | + | |
| 4019 | + | |
| 4020 | + | |
| 4021 | + | |
| 4022 | + | |
| 4023 | + | |
| 4024 | + | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
| 4043 | + | |
| 4044 | + | |
| 4045 | + | |
| 4046 | + | |
| 4047 | + | |
| 4048 | + | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
| 4052 | + | |
| 4053 | + | |
| 4054 | + | |
| 4055 | + | |
| 4056 | + | |
| 4057 | + | |
| 4058 | + | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
| 4069 | + | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
| 4073 | + | |
| 4074 | + | |
4004 | 4075 | | |
4005 | 4076 | | |
4006 | 4077 | | |
| |||
7926 | 7997 | | |
7927 | 7998 | | |
7928 | 7999 | | |
| 8000 | + | |
| 8001 | + | |
7929 | 8002 | | |
7930 | 8003 | | |
7931 | 8004 | | |
| |||
0 commit comments