Repository navigation
feat: add inject-message action for testing deployed flows - #441
Conversation
andypalmi
left a comment
There was a problem hiding this comment.
Thanks, this reads well and the test coverage is great. A few things:
Undeployed changes downstream
_getInjectTargetErroronly checkschangedon the target node. If a node further down the flow has undeployed edits, the runtime runs the old version and the agent reads debug output that doesn't match the editor. Should we check downstream too?- Two options I can see: refuse when
RED.nodes.dirty()is true (simple, but an edit on an unrelated tab also blocks it), or walkRED.nodes.getAllDownstreamNodes(node)and checkchangedon those. I'd lean towards downstream, also followinglink out(link mode) andlink callinto theirlink innodes, sincegetAllDownstreamNodesstops at link nodes. What do you think, and would you refuse or return a warning listing the changed nodes?
Topic in the audit entry
3. summarizeMsg logs the topic value itself, while the rest of the summary keeps to types only. Topics can carry identifying data (e.g. customers/acme/orders). Do we need the value there? properties.topic already records its type.
Policy check failure (follow-up)
4. getAutoDeployPolicy() returns false when forge can't be reached, so an outage shows up as INJECT_NOT_ALLOWED and the agent asks the user to enable a setting that may already be on. Deploy has the same behaviour.
5. Would a follow-up make sense where the check returns three states (allowed, not allowed, check failed), still failing closed? Inject would return something like POLICY_CHECK_FAILED, and /deploy-policy something like { autoDeploy: false, checkFailed: true } mapped to a new DEPLOY_POLICY_UNAVAILABLE code in the editor. Happy to open an issue for it.
No, this is no different to a user injecting a fully deployed inject against a locally modified flow. I do this myself - I inject knowing the debug will be generated from what the server has so I can use the output to correct downstream code. Perhaps a later iteration could adopt a parameter to ensure downstream is deployed (or workspace is not dirty) if desired. Also, it would never cover things like link-separated or mqtt-separated flows on a workspace so has limited benefits. Lets K.I.S.S for now. I wouldnt be against the AI knowing (via signals/skills) that the workspace is dirty so it can inform the user that the editor does not match server (so inject may not produce what they think) however this is base node-red knowledge!
Needed - no, but thought it would be useful for audit purposes. Should we remove?
If we are happy to move forward then yes please - raise as follow ups @andypalmi |
Description
Adds
automation/inject-message, which lets an agent push a test message into a deployed node and read the result back from the debug sidebar. It no longer has to add an inject node, deploy, and ask the user to click it. Part of #427.automation/inject-messagetakes{ id, msg? }. It refuses unknown nodes, nodes with no input port (inject, link in, config nodes), disabled nodes and tabs, nodes inside a subflow definition, and nodes with undeployed changes, since the runtime would otherwise use its old copy. These checks only give the agent a useful error. The runtime does the enforcing.POST /nr-assistant/injectneedswritepermission. On every call it checks the team's AI Flow Deploy setting throughgetAutoDeployPolicy(), with no caching. If that check fails, the route treats the setting as off. When the setting is off it returnsinjected: falsewith the new codeINJECT_NOT_ALLOWED, and nothing is delivered. Otherwise it looks the node up withRED.nodes.getNode, replaces any_msgidwith a new one, callsnode.receive(), and returns{ injected: true, msgid }.nr-assistant.injectaudit event with the node id, type, name,zand flow name, plus the msgid and a summary of the msg: property types, topic and size, never values. The flow name comes fromNR_FLOW_NAME, so on older Node-RED versions it is left out and forge falls back to the flow id.Testing
Tested end to end on a local instance through the MCP tool:
INJECT_NOT_ALLOWED.{ payload: 21 }into a function that doubles the payload gave42at the downstream debug node.nullwent through the same way.Notes
_msgid, so the agent can't match its message by msgid yet. FlowFuse/engineering#571 looks at a hooks-based trace to fix that.Related Issue(s)
Checklist
flowforge.yml?FlowFuse/helmto update ConfigMap TemplateFlowFuse/CloudProjectto update values for Staging/ProductionLabels
area:migrationlabel