routesim 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. routesim-0.0.1/LICENSE +202 -0
  2. routesim-0.0.1/PKG-INFO +185 -0
  3. routesim-0.0.1/README.md +168 -0
  4. routesim-0.0.1/pyproject.toml +34 -0
  5. routesim-0.0.1/setup.cfg +4 -0
  6. routesim-0.0.1/src/routesim/__init__.py +25 -0
  7. routesim-0.0.1/src/routesim/audit/__init__.py +5 -0
  8. routesim-0.0.1/src/routesim/audit/sampler.py +138 -0
  9. routesim-0.0.1/src/routesim/audit/shadow.py +198 -0
  10. routesim-0.0.1/src/routesim/cli_core.py +332 -0
  11. routesim-0.0.1/src/routesim/config/__init__.py +28 -0
  12. routesim-0.0.1/src/routesim/config/fragment.py +84 -0
  13. routesim-0.0.1/src/routesim/config/loader.py +225 -0
  14. routesim-0.0.1/src/routesim/config/model.py +226 -0
  15. routesim-0.0.1/src/routesim/engine/__init__.py +33 -0
  16. routesim-0.0.1/src/routesim/engine/directives.py +155 -0
  17. routesim-0.0.1/src/routesim/engine/evaluate.py +951 -0
  18. routesim-0.0.1/src/routesim/engine/fs.py +135 -0
  19. routesim-0.0.1/src/routesim/engine/location.py +171 -0
  20. routesim-0.0.1/src/routesim/engine/request.py +115 -0
  21. routesim-0.0.1/src/routesim/engine/server_select.py +161 -0
  22. routesim-0.0.1/src/routesim/engine/trace.py +168 -0
  23. routesim-0.0.1/src/routesim/engine/uri.py +185 -0
  24. routesim-0.0.1/src/routesim/engine/variables.py +150 -0
  25. routesim-0.0.1/src/routesim/equiv/__init__.py +27 -0
  26. routesim-0.0.1/src/routesim/equiv/behaviour.py +375 -0
  27. routesim-0.0.1/src/routesim/equiv/classify.py +294 -0
  28. routesim-0.0.1/src/routesim/equiv/corpus.py +273 -0
  29. routesim-0.0.1/src/routesim/equiv/output.py +169 -0
  30. routesim-0.0.1/src/routesim/equiv/run.py +203 -0
  31. routesim-0.0.1/src/routesim/trafficlight.py +96 -0
  32. routesim-0.0.1/src/routesim.egg-info/PKG-INFO +185 -0
  33. routesim-0.0.1/src/routesim.egg-info/SOURCES.txt +48 -0
  34. routesim-0.0.1/src/routesim.egg-info/dependency_links.txt +1 -0
  35. routesim-0.0.1/src/routesim.egg-info/entry_points.txt +3 -0
  36. routesim-0.0.1/src/routesim.egg-info/requires.txt +4 -0
  37. routesim-0.0.1/src/routesim.egg-info/top_level.txt +1 -0
  38. routesim-0.0.1/tests/test_audit.py +96 -0
  39. routesim-0.0.1/tests/test_cli_core.py +182 -0
  40. routesim-0.0.1/tests/test_equiv.py +520 -0
  41. routesim-0.0.1/tests/test_error_page.py +133 -0
  42. routesim-0.0.1/tests/test_fs_outcomes.py +183 -0
  43. routesim-0.0.1/tests/test_if_map.py +62 -0
  44. routesim-0.0.1/tests/test_internal_limit_except.py +68 -0
  45. routesim-0.0.1/tests/test_location.py +71 -0
  46. routesim-0.0.1/tests/test_normalization.py +146 -0
  47. routesim-0.0.1/tests/test_proxy_edges.py +153 -0
  48. routesim-0.0.1/tests/test_proxy_pass.py +141 -0
  49. routesim-0.0.1/tests/test_rewrite_return.py +212 -0
  50. routesim-0.0.1/tests/test_server_select.py +76 -0
routesim-0.0.1/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.4
2
+ Name: routesim
3
+ Version: 0.0.1
4
+ Summary: A high-fidelity nginx routing simulator: predict how a request flows through an nginx config without deploying it.
5
+ Author: Romatrix Labs
6
+ License: Apache-2.0
7
+ Classifier: License :: OSI Approved :: Apache Software License
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Topic :: System :: Networking
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: crossplane>=0.5.8
14
+ Provides-Extra: dev
15
+ Requires-Dist: pytest>=7; extra == "dev"
16
+ Dynamic: license-file
17
+
18
+ # routesim
19
+
20
+ **A high-fidelity nginx routing simulator.** Predict how a request flows through
21
+ an nginx config — which `server` block, which `location`, the full
22
+ rewrite/return chain, and the final upstream + URI — *without deploying
23
+ anything*.
24
+
25
+ ```
26
+ $ routesim explain -c nginx.conf -r "GET /api/v2/users -H Host:api.example.com"
27
+
28
+ SERVER
29
+ → line 14 server_name api.example.com
30
+ LOCATION
31
+ → location /api/ (line 24)
32
+ rule: longest prefix
33
+ OUTCOME
34
+ PROXY → http://api_pool/v2/users
35
+ URI to backend: /v2/users
36
+ ```
37
+
38
+ ```
39
+ $ routesim audit -c nginx.conf
40
+
41
+ [warning] regex-shadow location /api/ (server line 20)
42
+ paths under '/api/' matching location ~ \.php$ are handled by the regex,
43
+ not this prefix (use `^~ /api/` to suppress regex matching)
44
+ example: /api/probe.php -> location ~ \.php$
45
+ ```
46
+
47
+ ```
48
+ $ trafficlight diff old.conf new.conf
49
+
50
+ Analyzed 90 requests · 100.0% match-edge coverage (9/9 match edges)
51
+
52
+ ✗ D3 location /api/
53
+ upstream uri path changed / -> /api/
54
+ 17 requests affected, 15 distinct shapes
55
+ witness: GET /api/ Host: shop.example.com
56
+
57
+ ✗ D12 location /admin/
58
+ behaviour-bearing directive dropped auth_request subrequest authorisation -> (dropped)
59
+ 10 requests affected
60
+
61
+ 13 divergences · 7 critical · 3 high · 1 medium · 2 low · exit 1
62
+ ```
63
+
64
+ ## `trafficlight diff` — will this change route traffic differently?
65
+
66
+ A config diff is readable. Its *effect* is not. `nginx -t` checks syntax,
67
+ linters check style, policy engines check declared intent — none of them
68
+ evaluate behaviour.
69
+
70
+ `trafficlight diff` generates a request corpus from the **union** of two
71
+ configs, resolves every request against both, and classifies each difference
72
+ D1–D12 by severity ([TAXONOMY.md](TAXONOMY.md)). It exits non-zero at or above
73
+ `--gate` (default: high), so it drops into CI unchanged — `action.yml` in this
74
+ package is a ready GitHub Action.
75
+
76
+ Two things it will not do:
77
+
78
+ - **It will not say "no divergences."** It says *"no divergences across 90
79
+ requests covering 100% of match edges"*. The corpus is what makes the claim
80
+ checkable, coverage is a proxy for adequacy rather than a proof of it, and
81
+ match edges no request reached are listed rather than folded into the pass.
82
+ - **It will not guess.** `auth_request`, `mirror`, `sub_filter`, `*_by_lua_*` —
83
+ directives whose effect cannot be statically evaluated are reported under
84
+ **Not verified**, on both sides. Removing one is D12 and Critical, because
85
+ the size of that change is unknown and scoring it as equivalent would be
86
+ wrong in the only way that matters.
87
+
88
+ It also accepts the config you actually have: most nginx configuration is an
89
+ `include` fragment, and one parsed standalone is a grammar error. Fragments are
90
+ wrapped in the shallowest context that parses, and the report names what it
91
+ invented — a verdict derived from a synthesised `server` block describes the
92
+ wrapped configuration, not the file as deployed.
93
+
94
+ `trafficlight` and `routesim` are the same code: `trafficlight diff` is
95
+ `routesim equiv`, and both dispatch into one engine. Two front doors, one model
96
+ of nginx location precedence.
97
+
98
+ ## Why you can trust the answer
99
+
100
+ **100% agreement with real nginx 1.28.3 on every comparable request: 21,455
101
+ over 310 configs, 300 of them random and held out, and 3,294 over 128
102
+ real-world configs taken from public GitHub repositories.**
103
+
104
+ That is not a claim about careful coding. Every semantic here was ground-truthed
105
+ by firing the same request at both this simulator and a real nginx and comparing
106
+ what the backend actually received. Several behaviours were *discovered* that
107
+ way rather than implemented from the docs — URI normalization before matching,
108
+ `auto_redirect`, the `proxy_pass` junction-slash rules, and the
109
+ `valid_unparsed_uri` raw-forwarding rule.
110
+
111
+ The most recent fidelity bugs were found in December 2026 by the real-world
112
+ configs -- `internal` locations and `limit_except` -- and are written up, with
113
+ their ground-truthing, in the fidelity report, together with two defects in the
114
+ test harness itself that could have made a run report 100% over fewer requests
115
+ than it claimed. Every number above was re-measured after those fixes.
116
+
117
+ ## What it models
118
+
119
+ The 90% of nginx that causes real incidents:
120
+
121
+ - **`server` / `listen` / `server_name` selection** with correct precedence:
122
+ exact → longest leading-wildcard → longest trailing-wildcard → first regex →
123
+ default server.
124
+ - **`location` matching** with full precedence: `=` → `^~` (which suppresses
125
+ regex) → regex in source order → longest prefix. *This is where most
126
+ shadowed-route bugs live.*
127
+ - **`rewrite`** (`last` / `break` / `redirect` / `permanent`, the 10-cycle
128
+ limit), **`return`**, **`try_files`**, and **`proxy_pass` URI semantics** —
129
+ the trailing-slash prefix substitution is a top-5 real-world footgun and is
130
+ modeled exactly.
131
+ - **URI normalization** exactly as nginx does it *before* matching:
132
+ percent-decoding, slash-merging, `.`/`..` resolution, and 400 on traversal
133
+ above root. This is a security surface: prefix restrictions that look
134
+ airtight often aren't.
135
+ - **`error_page`** — including the rule that catches everyone: without `=` the
136
+ original status is *preserved* and only the body comes from the handler.
137
+ - **Named locations** (`@name`), reachable only by internal redirect, and
138
+ **`internal`** locations, which answer an outside request with 404.
139
+ - **`limit_except`**: a method it does not list is refused by a `deny all`
140
+ block before the location's own `return` runs. Rules that depend on the
141
+ client address are reported, not guessed.
142
+ - **`auto_redirect`**, **`map`**, basic **`if`**, upstream resolution.
143
+
144
+ The parser is not hand-rolled: routesim builds on
145
+ [crossplane](https://github.com/nginxinc/crossplane), nginx's own config parser.
146
+ The engineering is in the decision engine on top of the AST.
147
+
148
+ ## Install
149
+
150
+ ```bash
151
+ pip install routesim
152
+ # or, from source:
153
+ pip install git+https://github.com/romatrix-labs/routesim
154
+ ```
155
+
156
+ ## Commands
157
+
158
+ | Command | What it does |
159
+ |---|---|
160
+ | `routesim explain -c CONF -r "GET /path -H Host:x"` | Trace one request: server → location → transform chain → outcome. `--json` for machine output. |
161
+ | `routesim audit -c CONF` | Find shadowed / unreachable routes. Exits non-zero on findings — CI-friendly. |
162
+ | `trafficlight diff OLD.conf NEW.conf` | Behavioural diff of two configs, classified D1–D12. `--gate` sets the blocking severity; `--json` emits a report with a witness request per finding. Also `routesim equiv`. |
163
+ | `routesim parse -c CONF` | Dump the normalized config model as JSON. |
164
+
165
+ ## Not modelled
166
+
167
+ Filesystem-dependent outcomes are reported as unresolved by default: the CLI
168
+ has no filesystem to consult. From Python, `try_files`, static files and
169
+ directory indexes can be resolved against a declared set of directories
170
+ (`routesim.engine.fs.VirtualFS`); `alias`, `autoindex` and roots built from
171
+ variables are still declined. `-f`/`-d` `if` tests are marked *unknown* and
172
+ their branch skipped. Also not modelled: `sub_filter`, per-address `listen`
173
+ binding, and access rules that depend on the client address.
174
+
175
+ `trafficlight diff` declares these rather than guessing at them: anything it
176
+ could not evaluate appears under **Not verified** in the report, and is never
177
+ counted as evidence of equivalence.
178
+
179
+ ## Licence
180
+
181
+ Apache-2.0.
182
+
183
+ This package is the open core of a larger private system. The differential
184
+ harness that produces the fidelity number above, the benchmark, and the
185
+ post-migration equivalence audit are not part of this distribution.
@@ -0,0 +1,168 @@
1
+ # routesim
2
+
3
+ **A high-fidelity nginx routing simulator.** Predict how a request flows through
4
+ an nginx config — which `server` block, which `location`, the full
5
+ rewrite/return chain, and the final upstream + URI — *without deploying
6
+ anything*.
7
+
8
+ ```
9
+ $ routesim explain -c nginx.conf -r "GET /api/v2/users -H Host:api.example.com"
10
+
11
+ SERVER
12
+ → line 14 server_name api.example.com
13
+ LOCATION
14
+ → location /api/ (line 24)
15
+ rule: longest prefix
16
+ OUTCOME
17
+ PROXY → http://api_pool/v2/users
18
+ URI to backend: /v2/users
19
+ ```
20
+
21
+ ```
22
+ $ routesim audit -c nginx.conf
23
+
24
+ [warning] regex-shadow location /api/ (server line 20)
25
+ paths under '/api/' matching location ~ \.php$ are handled by the regex,
26
+ not this prefix (use `^~ /api/` to suppress regex matching)
27
+ example: /api/probe.php -> location ~ \.php$
28
+ ```
29
+
30
+ ```
31
+ $ trafficlight diff old.conf new.conf
32
+
33
+ Analyzed 90 requests · 100.0% match-edge coverage (9/9 match edges)
34
+
35
+ ✗ D3 location /api/
36
+ upstream uri path changed / -> /api/
37
+ 17 requests affected, 15 distinct shapes
38
+ witness: GET /api/ Host: shop.example.com
39
+
40
+ ✗ D12 location /admin/
41
+ behaviour-bearing directive dropped auth_request subrequest authorisation -> (dropped)
42
+ 10 requests affected
43
+
44
+ 13 divergences · 7 critical · 3 high · 1 medium · 2 low · exit 1
45
+ ```
46
+
47
+ ## `trafficlight diff` — will this change route traffic differently?
48
+
49
+ A config diff is readable. Its *effect* is not. `nginx -t` checks syntax,
50
+ linters check style, policy engines check declared intent — none of them
51
+ evaluate behaviour.
52
+
53
+ `trafficlight diff` generates a request corpus from the **union** of two
54
+ configs, resolves every request against both, and classifies each difference
55
+ D1–D12 by severity ([TAXONOMY.md](TAXONOMY.md)). It exits non-zero at or above
56
+ `--gate` (default: high), so it drops into CI unchanged — `action.yml` in this
57
+ package is a ready GitHub Action.
58
+
59
+ Two things it will not do:
60
+
61
+ - **It will not say "no divergences."** It says *"no divergences across 90
62
+ requests covering 100% of match edges"*. The corpus is what makes the claim
63
+ checkable, coverage is a proxy for adequacy rather than a proof of it, and
64
+ match edges no request reached are listed rather than folded into the pass.
65
+ - **It will not guess.** `auth_request`, `mirror`, `sub_filter`, `*_by_lua_*` —
66
+ directives whose effect cannot be statically evaluated are reported under
67
+ **Not verified**, on both sides. Removing one is D12 and Critical, because
68
+ the size of that change is unknown and scoring it as equivalent would be
69
+ wrong in the only way that matters.
70
+
71
+ It also accepts the config you actually have: most nginx configuration is an
72
+ `include` fragment, and one parsed standalone is a grammar error. Fragments are
73
+ wrapped in the shallowest context that parses, and the report names what it
74
+ invented — a verdict derived from a synthesised `server` block describes the
75
+ wrapped configuration, not the file as deployed.
76
+
77
+ `trafficlight` and `routesim` are the same code: `trafficlight diff` is
78
+ `routesim equiv`, and both dispatch into one engine. Two front doors, one model
79
+ of nginx location precedence.
80
+
81
+ ## Why you can trust the answer
82
+
83
+ **100% agreement with real nginx 1.28.3 on every comparable request: 21,455
84
+ over 310 configs, 300 of them random and held out, and 3,294 over 128
85
+ real-world configs taken from public GitHub repositories.**
86
+
87
+ That is not a claim about careful coding. Every semantic here was ground-truthed
88
+ by firing the same request at both this simulator and a real nginx and comparing
89
+ what the backend actually received. Several behaviours were *discovered* that
90
+ way rather than implemented from the docs — URI normalization before matching,
91
+ `auto_redirect`, the `proxy_pass` junction-slash rules, and the
92
+ `valid_unparsed_uri` raw-forwarding rule.
93
+
94
+ The most recent fidelity bugs were found in December 2026 by the real-world
95
+ configs -- `internal` locations and `limit_except` -- and are written up, with
96
+ their ground-truthing, in the fidelity report, together with two defects in the
97
+ test harness itself that could have made a run report 100% over fewer requests
98
+ than it claimed. Every number above was re-measured after those fixes.
99
+
100
+ ## What it models
101
+
102
+ The 90% of nginx that causes real incidents:
103
+
104
+ - **`server` / `listen` / `server_name` selection** with correct precedence:
105
+ exact → longest leading-wildcard → longest trailing-wildcard → first regex →
106
+ default server.
107
+ - **`location` matching** with full precedence: `=` → `^~` (which suppresses
108
+ regex) → regex in source order → longest prefix. *This is where most
109
+ shadowed-route bugs live.*
110
+ - **`rewrite`** (`last` / `break` / `redirect` / `permanent`, the 10-cycle
111
+ limit), **`return`**, **`try_files`**, and **`proxy_pass` URI semantics** —
112
+ the trailing-slash prefix substitution is a top-5 real-world footgun and is
113
+ modeled exactly.
114
+ - **URI normalization** exactly as nginx does it *before* matching:
115
+ percent-decoding, slash-merging, `.`/`..` resolution, and 400 on traversal
116
+ above root. This is a security surface: prefix restrictions that look
117
+ airtight often aren't.
118
+ - **`error_page`** — including the rule that catches everyone: without `=` the
119
+ original status is *preserved* and only the body comes from the handler.
120
+ - **Named locations** (`@name`), reachable only by internal redirect, and
121
+ **`internal`** locations, which answer an outside request with 404.
122
+ - **`limit_except`**: a method it does not list is refused by a `deny all`
123
+ block before the location's own `return` runs. Rules that depend on the
124
+ client address are reported, not guessed.
125
+ - **`auto_redirect`**, **`map`**, basic **`if`**, upstream resolution.
126
+
127
+ The parser is not hand-rolled: routesim builds on
128
+ [crossplane](https://github.com/nginxinc/crossplane), nginx's own config parser.
129
+ The engineering is in the decision engine on top of the AST.
130
+
131
+ ## Install
132
+
133
+ ```bash
134
+ pip install routesim
135
+ # or, from source:
136
+ pip install git+https://github.com/romatrix-labs/routesim
137
+ ```
138
+
139
+ ## Commands
140
+
141
+ | Command | What it does |
142
+ |---|---|
143
+ | `routesim explain -c CONF -r "GET /path -H Host:x"` | Trace one request: server → location → transform chain → outcome. `--json` for machine output. |
144
+ | `routesim audit -c CONF` | Find shadowed / unreachable routes. Exits non-zero on findings — CI-friendly. |
145
+ | `trafficlight diff OLD.conf NEW.conf` | Behavioural diff of two configs, classified D1–D12. `--gate` sets the blocking severity; `--json` emits a report with a witness request per finding. Also `routesim equiv`. |
146
+ | `routesim parse -c CONF` | Dump the normalized config model as JSON. |
147
+
148
+ ## Not modelled
149
+
150
+ Filesystem-dependent outcomes are reported as unresolved by default: the CLI
151
+ has no filesystem to consult. From Python, `try_files`, static files and
152
+ directory indexes can be resolved against a declared set of directories
153
+ (`routesim.engine.fs.VirtualFS`); `alias`, `autoindex` and roots built from
154
+ variables are still declined. `-f`/`-d` `if` tests are marked *unknown* and
155
+ their branch skipped. Also not modelled: `sub_filter`, per-address `listen`
156
+ binding, and access rules that depend on the client address.
157
+
158
+ `trafficlight diff` declares these rather than guessing at them: anything it
159
+ could not evaluate appears under **Not verified** in the report, and is never
160
+ counted as evidence of equivalence.
161
+
162
+ ## Licence
163
+
164
+ Apache-2.0.
165
+
166
+ This package is the open core of a larger private system. The differential
167
+ harness that produces the fidelity number above, the benchmark, and the
168
+ post-migration equivalence audit are not part of this distribution.
@@ -0,0 +1,34 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "routesim"
7
+ version = "0.0.1"
8
+ description = "A high-fidelity nginx routing simulator: predict how a request flows through an nginx config without deploying it."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Romatrix Labs" }]
13
+ classifiers = [
14
+ "License :: OSI Approved :: Apache Software License",
15
+ "Programming Language :: Python :: 3",
16
+ "Topic :: System :: Networking",
17
+ ]
18
+ dependencies = [
19
+ "crossplane>=0.5.8",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = ["pytest>=7"]
24
+
25
+ [project.scripts]
26
+ routesim = "routesim.cli_core:main"
27
+ trafficlight = "routesim.trafficlight:main"
28
+
29
+ [tool.setuptools.packages.find]
30
+ where = ["src"]
31
+
32
+ [tool.pytest.ini_options]
33
+ testpaths = ["tests"]
34
+ addopts = "-q"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2026 Romatrix Labs
3
+ """routesim -- a high-fidelity nginx routing simulator.
4
+
5
+ Predict how a request flows through an nginx config (which server block, which
6
+ location, the full rewrite/return chain, and the final upstream + URI) without
7
+ deploying anything.
8
+ """
9
+
10
+ from .config import Config, ConfigError, load_file, load_string
11
+ from .engine import Request, Trace, evaluate, parse_request
12
+
13
+ __version__ = "0.0.1"
14
+
15
+ __all__ = [
16
+ "Config",
17
+ "ConfigError",
18
+ "Request",
19
+ "Trace",
20
+ "evaluate",
21
+ "load_file",
22
+ "load_string",
23
+ "parse_request",
24
+ "__version__",
25
+ ]
@@ -0,0 +1,5 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright (c) 2026 Romatrix Labs
3
+ from .shadow import Finding, audit_config
4
+
5
+ __all__ = ["Finding", "audit_config"]