routeros: ordering convention from mktxp patterns (#67) #134

Merged
ginjiruu merged 2 commits from routeros-ordering-convention into master 2026-11-17 21:47:27 +00:00
Owner

Closes the missing piece of #67: the ordering convention, written down, plus the one renderer behavior worth stealing from akpw/mktxp.

Premise correction first (full analysis in docs/routeros/notes/2026-11-17-mktxp-patterns.md): mktxp is not a Go apply CLI — it is a Python exporter/GitOps toolkit whose rsc module does live /export -> normalize -> format/split, device-to-git only. It never applies, so it never solved ordering-on-apply; its answer is "the device's export order is the record." That stance validates two of our choices (copy ordered menus verbatim; keep tooling comment-opaque) and contributes one mechanism we lacked.

Code (routeros/render):

  • render.py: ORDERED_MENUS constant (mktxp's whitelist sorter.py:19-34 plus /interface/bridge/filter, which mktxp misses despite the provider placing there) and normalize() now merges menu blocks and sorts menus outside it by a fixed key ladder. gate.sh before/after compares (and the future #72 diffs) lose address-list/list-member jitter; the .full.rsc render still never reorders (byte-identity check intact).
  • gate-selftest.sh: no-device unit check — swapped unordered lines normalize equal, swapped firewall rules normalize different, ladder order pinned.

Docs: docs/routeros/README.md gains the #67 convention section (declared order = device order = render order; place_before rejected; move_items as gate-proven janitor; comments stay comma-free import keys with step-10 numbers deferred to #69, where planned_values first needs a total order); notes file carries all path:line citations.

Verification: python3 -m py_compile, bash -n, and the new selftest check run green (printed "normalize: unordered sorts, ordered copies ok"); device selftest cases unchanged (firewall is an ordered menu, so the reorder case still fails the gate by the same path). Nothing here touches *.tf roots: merging has zero live effect; the normalize change only widens gate.sh tolerance of export jitter between renders.

mktxp verdict for #71: nothing to borrow (never writes to a device). For #72: vendoring mktxp rsc split stays the lazy alternative; this port keeps us dependency-free.

Closes the missing piece of #67: the ordering convention, written down, plus the one renderer behavior worth stealing from akpw/mktxp. **Premise correction first** (full analysis in docs/routeros/notes/2026-11-17-mktxp-patterns.md): mktxp is not a Go apply CLI — it is a Python exporter/GitOps toolkit whose rsc module does live /export -> normalize -> format/split, device-to-git only. It never applies, so it never solved ordering-on-apply; its answer is "the device's export order is the record." That stance validates two of our choices (copy ordered menus verbatim; keep tooling comment-opaque) and contributes one mechanism we lacked. **Code** (routeros/render): - render.py: ORDERED_MENUS constant (mktxp's whitelist sorter.py:19-34 plus /interface/bridge/filter, which mktxp misses despite the provider placing there) and normalize() now merges menu blocks and sorts menus outside it by a fixed key ladder. gate.sh before/after compares (and the future #72 diffs) lose address-list/list-member jitter; the .full.rsc render still never reorders (byte-identity check intact). - gate-selftest.sh: no-device unit check — swapped unordered lines normalize equal, swapped firewall rules normalize different, ladder order pinned. **Docs**: docs/routeros/README.md gains the #67 convention section (declared order = device order = render order; place_before rejected; move_items as gate-proven janitor; comments stay comma-free import keys with step-10 numbers deferred to #69, where planned_values first needs a total order); notes file carries all path:line citations. **Verification**: python3 -m py_compile, bash -n, and the new selftest check run green (printed "normalize: unordered sorts, ordered copies ok"); device selftest cases unchanged (firewall is an ordered menu, so the reorder case still fails the gate by the same path). Nothing here touches *.tf roots: merging has zero live effect; the normalize change only widens gate.sh tolerance of export jitter between renders. mktxp verdict for #71: nothing to borrow (never writes to a device). For #72: vendoring `mktxp rsc split` stays the lazy alternative; this port keeps us dependency-free.
normalize() merges menu blocks and sorts menus outside ORDERED_MENUS by
a fixed key ladder (akpw/mktxp sorter), so gate.sh compares and the #72
backstop are jitter-free; ordered menus copy verbatim and the selftest
swap case still fails the gate (no-device unit check added). ORDERED_MENUS
is the whitelist plus /interface/bridge/filter, which mktxp misses.

docs: convention section in docs/routeros/README.md (declared order =
device order = render order, place_before rejected, move_items janitor,
comments stay import keys with numbers deferred to #69) and the full
mktxp analysis in docs/routeros/notes/2026-11-17-mktxp-patterns.md.
- render.py: normalize sorts only SORTABLE_MENUS; every other menu (dns
  static, queue simple, routing filter, bridge nat, ipsec policy, anything
  unclassified) is copied in export order. TYPE_PATH menus must be
  classified or render.py refuses to load.
- _norm_sort_key: whole-token keys (interface= no longer matches
  in-interface=, list= no longer matches address-list=), escaped quotes.
- gate-selftest: dns static swap must survive normalize; SC2181.
- sim/ordering/run.sh: 15-rule chain on a CHR; reorder = one move_items
  update with every .id kept, insert/delete touch one rule, renumber is
  comment-only, out-of-band move shows in plan. PASS 2026-11-17.
- docs: convention updated with the sim table; mktxp notes gain the
  exporter/connection-layer review (section 7).
Author
Owner

Update 9521fe4: normalize now sorts an allowlist (SORTABLE_MENUS) and copies everything else, so dns static / queue simple / routing filter / bridge nat / ipsec policy reorders stay visible to the gate; TYPE_PATH menus must be classified. Sort-key regex fixed (interface= matched in-interface=, list= matched address-list=). Reorder demo: routeros/sim/ordering/run.sh, PASS on CHR 7.25.1 with the lab provider fork: reorder = one move_items update with every .id kept, insert/delete touch one rule, step-10 renumber is comment-only, an out-of-band move shows up in plan and is repaired. Table in docs/routeros/README.md. mktxp exporter-side review in notes section 7; monitoring follow-up is #139.

Update 9521fe4: normalize now sorts an allowlist (SORTABLE_MENUS) and copies everything else, so dns static / queue simple / routing filter / bridge nat / ipsec policy reorders stay visible to the gate; TYPE_PATH menus must be classified. Sort-key regex fixed (interface= matched in-interface=, list= matched address-list=). Reorder demo: routeros/sim/ordering/run.sh, PASS on CHR 7.25.1 with the lab provider fork: reorder = one move_items update with every .id kept, insert/delete touch one rule, step-10 renumber is comment-only, an out-of-band move shows up in plan and is repaired. Table in docs/routeros/README.md. mktxp exporter-side review in notes section 7; monitoring follow-up is #139.
ginjiruu force-pushed routeros-ordering-convention from 9521fe448e to 037157415c 2026-11-17 21:47:25 +00:00 Compare
ginjiruu merged commit 3c30070436 into master 2026-11-17 21:47:27 +00:00
ginjiruu deleted branch routeros-ordering-convention 2026-11-17 21:47:27 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/iac!134
No description provided.