Files
nr-flow-validator/justfile
T
david f95e8b8ecb Flat-structure generator + Rego guards, rename Laser & Fog to DJ Booth
Closes #1.

Generator (scripts/flow2json.py):
- Emit all nodes at top level with z field (no wrapped tabs)
- Set icon: "" on ui-button to avoid Dashboard 2.0 prependIcon TypeError
- Set z field on ui-* widgets so they render in Dashboard 2.0 SPA
- Use ui-text label from spec, not name

Policy (policy/flow.rego) — 9 new deny rules:
- deny_wrapped_tab: tab with internal nodes[] (nodered 5.0 bug)
- deny_missing_wires: missing or non-array wires (Flow.js rewireNode crash)
- deny_no_autoconnect: mqtt-broker must reconnect
- deny_invalid_protocol: protocolVersion must be 3/4/5
- deny_unused_broker: broker declared but never referenced
- Plus deny_broker_port / deny_group_ref / deny_page_ref / deny_wire_ref refinements

Flow (zigbee-monitor.*):
- 22-node flat flow: button-in → btn-filter → 4 parallel plug-outs
- 4 ui-text widgets + ui-button for permit-join (60s)
- Renamed plug: "Laser & Fog" → "DJ Booth" (matches z2m friendly_name)

Repo hygiene:
- justfile: fix host IP 192.168.9.147 → 192.168.81.147, /ui → /dashboard
- README.md: document 8 generation invariants and rule table

Verified end-to-end: publishing {"action":"single"} on
zigbee2mqtt/Door Button triggers {"state":"TOGGLE"} on all four
.../set topics including the renamed DJ Booth.

462/462 conftest tests pass.
2026-06-30 23:16:17 -07:00

82 lines
2.5 KiB
Makefile

# nr-flow-validator — Declarative Node-RED flows with conftest validation
set export
# Default: generate a flow, validate, and show results
default: validate
# ---- Flow generation ----
# Generate Node-RED flow JSON from a YAML spec
generate FLOW="zigbee-monitor":
@echo "=== Generating {{FLOW}} ==="
python3 scripts/flow2json.py flows/{{FLOW}}.yaml > output/{{FLOW}}.json
@echo "Wrote output/{{FLOW}}.json"
# Generate all flows
generate-all:
@for f in flows/*.yaml; do \
name=$(basename "$f" .yaml); \
just generate "$name"; \
done
# ---- Validation ----
# Validate a generated flow against Rego policies
validate FLOW="zigbee-monitor": generate
@echo "=== Validating {{FLOW}} ==="
conftest test output/{{FLOW}}.json -p policy/ --namespace nodered --no-color
# Validate all flows
validate-all:
@for f in output/*.json; do \
echo "=== Validating $(basename "$f") ==="; \
conftest test "$$f" -p policy/ --namespace nodered --no-color; \
done
# ---- Deployment ----
# Deploy flow to Node-RED instance
deploy FLOW="zigbee-monitor" HOST="http://192.168.81.147:1880": generate validate
@echo "=== Deploying {{FLOW}} to {{HOST}} ==="
curl -s -o /dev/null -w "HTTP %{http_code}" \
-X POST {{HOST}}/flows \
-H "Content-Type: application/json" \
-H "Node-RED-Deployment-Type: full" \
-d @output/{{FLOW}}.json
@echo ""
# Quick deploy (skip validation)
deploy-quick FLOW="zigbee-monitor" HOST="http://192.168.81.147:1880": generate
@echo "=== Quick deploy {{FLOW}} to {{HOST}} ==="
curl -s -o /dev/null -w "HTTP %{http_code}" \
-X POST {{HOST}}/flows \
-H "Content-Type: application/json" \
-H "Node-RED-Deployment-Type: full" \
-d @output/{{FLOW}}.json
@echo ""
# ---- Viewing ----
# Fetch and display current flows from Node-RED
pull HOST="http://192.168.81.147:1880":
curl -s {{HOST}}/flows | python3 -m json.tool
# Open dashboard in browser
dashboard:
xdg-open http://192.168.81.147:1880/dashboard 2>/dev/null || open http://192.168.81.147:1880/dashboard 2>/dev/null || echo "Open: http://192.168.81.147:1880/dashboard"
# ---- Development ----
# Watch for changes and re-validate
watch FLOW="zigbee-monitor":
@while true; do \
inotifywait -q -e modify flows/{{FLOW}}.yaml policy/*.rego; \
clear; just validate {{FLOW}}; \
done
# Create a new flow from template
new NAME:
@cp flows/zigbee-monitor.yaml flows/{{NAME}}.yaml
@echo "Created flows/{{NAME}}.yaml — edit and run 'just validate {{NAME}}'"