Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Version and deprecate workflow nodes (#44556)

Régis Hanol529cfb1d7f25
diff --git a/.skills/discourse-workflow-nodes/SKILL.md b/.skills/discourse-workflow-nodes/SKILL.md
index 0fce8d371c8..e2b5cd685f5 100644
--- a/.skills/discourse-workflow-nodes/SKILL.md
+++ b/.skills/discourse-workflow-nodes/SKILL.md
@@ -44,6 +44,18 @@ DiscourseEvent.trigger(:topic_status_updated, topic, status, enabled, acting_use
Trigger nodes receive it as a trailing hash: `def initialize(topic, status, enabled, payload = {})` and read `payload[:acting_user]`. Specs that assert exact event params must include `{ acting_user: ... }`.
+## Breaking output changes
+
+Renaming or removing an output key, or changing its meaning, breaks saved workflows. Ship a new version instead; additive keys can go in the existing version.
+
+- Freeze V1 and mark it, after `description(...)`: `deprecated(superseded_by: "2.0", changes: { "editor" => "actor" })`.
+- The shared `node_descriptions.<identifier>` locale describes the latest version. If it no longer fits V1, add `description_key: "discourse_workflows.node_descriptions.<identifier>_v1"` to `deprecated(...)` with V1's text; V2 does not inherit it.
+- `class V2 < V1` in `v2.rb`, calling `description(superclass.description.merge(version: "2.0", output_contracts: [{ schema: V2_OUTPUT_SCHEMA }]))`, then override `output` / `execute` or a private `serialize_*` helper.
+- Core nodes self-register; plugin nodes need `register_discourse_workflows_node(...::V2)` next to V1.
+- Services resolve the saved version with `NodeData.node_type(node)`, never a hard-coded `V1`.
+- Deprecated versions keep running for saved workflows, are hidden from the palette and AI catalog, and show an editor notice with an Upgrade action. Remove them after a deprecation window.
+- Spec both: `match_node_output_schema(Foo::V1)` pins the old keys, `match_node_output_schema(Foo::V2)` the new ones.
+
## Output conventions
- URLs are absolute (`Discourse.base_url + ...`, `full_url`). Keep existing relative keys such as `post_url`.
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js
index 2b44898b07e..98353106f04 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/rete-editor.js
@@ -893,6 +893,7 @@ export class ReteEditorBridge {
reteNode.label !== newLabel ||
reteNode.width !== newWidth ||
reteNode.height !== newHeight ||
+ reteNode.workflowData.typeVersion !== nodeData.typeVersion ||
JSON.stringify(reteNode.workflowData.configuration) !==
JSON.stringify(nodeData.configuration);
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/workflow-node.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/workflow-node.gjs
index a86e727aba4..61316c645b0 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/workflow-node.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/canvas/workflow-node.gjs
@@ -25,6 +25,7 @@ import {
nodeDescription,
nodeLabel,
} from "../../../lib/workflows/node-utils.js";
+import { deprecationMessage } from "../node/deprecation-notice.gjs";
import CanvasHoverToolbar from "./hover-toolbar.gjs";
function resolveType(workflowsNodeTypes, node) {
@@ -388,6 +389,18 @@ export default class WorkflowNode extends Component {
</:content>
</DTooltip>
{{/if}}
+
+ {{#if this.resolvedNodeType.deprecation}}
+ <DTooltip
+ class="workflow-rete-node__deprecated-badge"
+ @content={{deprecationMessage this.resolvedNodeType.deprecation}}
+ @identifier="workflow-node-deprecated"
+ >
+ <:trigger>
+ {{dIcon "arrow-up"}}
+ </:trigger>
+ </DTooltip>
+ {{/if}}
</div>
<div class="workflow-rete-node__outputs">
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
index 824a63992cb..1b003f4882c 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/editor/index.gjs
@@ -516,6 +516,7 @@ export default class WorkflowsEditor extends Component {
options
),
onRemove: () => this.removeNodes([clientId]),
+ onUpgrade: () => this.upgradeNode(clientId),
},
})
.finally(() => {
@@ -783,6 +784,30 @@ export default class WorkflowsEditor extends Component {
return this.handleSubmit(options);
}
+ @action
+ async upgradeNode(clientId) {
+ const nodes = this.formApi
+ .get("nodes")
+ .map((n) =>
+ n.clientId === clientId
+ ? { ...n, typeVersion: nodeTypeVersion(this.#nodeTypeFor(n)) }
+ : n
+ );
+ this.formApi.set("nodes", nodes);
+
+ try {
+ await this.handleSubmit({ throwOnError: true });
+ } catch {
+ return;
+ }
+
+ if (this.isDestroying) {
+ return;
+ }
+
+ this.editNode(clientId);
+ }
+
@action
replaceTrigger(clientId, nodeType) {
this.#captureUndo();
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/configurator.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/configurator.gjs
index 279deb86f25..d89e93d7728 100644
--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/configurator.gjs
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/configurator.gjs
@@ -45,6 +45,7 @@ import PropertyEngineConfigurator from "../configurators/property-engine.gjs";
import InputContext from "../context/input.gjs";
import OutputContext from "../context/output.gjs";
import { takenNodeNames } from "../editor/node-factory.js";
+import DeprecationNotice from "./deprecation-notice.gjs";
import LivePreview from "./live-preview.gjs";
function credentialSlotLabel(slot) {
@@ -417,6 +418,12 @@ export default class NodeConfigurator extends Component {
this.args.model.session.clearEditingContext();
}
+ @action
+ upgradeNode() {
+ this.handleClose();
+ this.args.model.onUpgrade();
+ }
+
@action
async executeStep() {
try {
@@ -605,6 +612,10 @@ export default class NodeConfigurator extends Component {
}}</span>
</div>
{{/if}}
+ <DeprecationNotice
+ @deprecation={{this.resolvedNodeType.deprecation}}
+ @onUpgrade={{this.upgradeNode}}
+ />
<div
class={{dConcatClass
"workflows-configurator-modal__columns"
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/deprecation-notice.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/deprecation-notice.gjs
new file mode 100644
index 00000000000..6d03ac9f17a
--- /dev/null
+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/node/deprecation-notice.gjs
@@ -0,0 +1,36 @@
+import DButton from "discourse/ui-kit/d-button";
+import DFlashMessage from "discourse/ui-kit/d-flash-message";
+import { i18n } from "discourse-i18n";
+
+export function deprecationMessage(deprecation) {
+ const changes = Object.entries(deprecation.changes || {})
+ .map(([from, to]) => `${from} → ${to}`)
+ .join(", ");
+
+ const notice = i18n("discourse_workflows.node_deprecated.notice", {
+ changes,
+ });
+ if (!deprecation.notice_key) {
+ return notice;
+ }
+
+ return `${notice} ${i18n(deprecation.notice_key)}`;
+}
+
+const DeprecationNotice = <template>
+ {{#if @deprecation}}
+ <div class="workflows-deprecation-notice">
+ <DFlashMessage
+ @flash={{deprecationMessage @deprecation}}
+ @type="warning"
+ />
+ <DButton
+ class="btn-small workflows-deprecation-notice__upgrade"
+ @action={{@onUpgrade}}
+ @label="discourse_workflows.node_deprecated.upgrade"
+ />
+ </div>
+ {{/if}}
+</template>;
+
+export default DeprecationNotice;
diff --git a/plugins/discourse-workflows/app/jobs/regular/discourse_workflows/author_with_ai.rb b/plugins/discourse-workflows/app/jobs/regular/discourse_workflows/author_with_ai.rb
index 9ab30391f38..d316c86fe41 100644
--- a/plugins/discourse-workflows/app/jobs/regular/discourse_workflows/author_with_ai.rb
+++ b/plugins/discourse-workflows/app/jobs/regular/discourse_workflows/author_with_ai.rb
@@ -12,6 +12,7 @@ module Jobs
"For generic requests like 'when someone posts' or 'when anyone posts', trigger:post_created covers all regular posts, including first posts and replies. Do not ask to distinguish replies from topic starters unless the request explicitly says replies only or new topics only.",
"trigger:topic_closed exposes only the closed topic under topic.*. When a closed-topic workflow needs a first-post link, add action:topic with operation get and topic_id ={{ $json.topic.id }} immediately after the trigger. Use the exact fields returned by workflow_validate_patch for any first-post author data; do not assume post.trust_level is available.",
"Do not ask whether trust level is available for trigger:post_created or trigger:post_edited; it is available as user.trust_level.",
+ "A graph context node with a deprecation entry runs an older version whose output differs from the node catalog. deprecation.changes maps each key of that version to the catalog key holding the same data; for example { \"user\" => \"actor\" } means user.* on that node is whoever acted. Use that node's own keys. You cannot change a node's version; if the newer version is needed, ask the user to click Upgrade on the node.",
"Do not generate fallback chains for undocumented author aliases; use the exact post.* fields from the node catalog output_contracts.",
"trigger:user_added_to_group and trigger:user_removed_from_group expose the affected user under user.*, the selected group under group.*, and event metadata under membership.*. Use user.username for the affected username and membership.action to distinguish added vs removed if needed.",
"trigger:user_created and trigger:user_updated expose the affected user under user.* only, including user.username, user.trust_level, user.staged, and user.created_at. They do not expose a post or topic object. They also fire for staged users (accounts auto-created by incoming email or invites); to skip those, add condition:filter on user.staged equals false after the trigger.",
diff --git a/plugins/discourse-workflows/app/services/discourse_workflows/execution/check_stale_topics.rb b/plugins/discourse-workflows/app/services/discourse_workflows/execution/check_stale_topics.rb
index 491fac60e21..240565316d5 100644
--- a/plugins/discourse-workflows/app/services/discourse_workflows/execution/check_stale_topics.rb
+++ b/plugins/discourse-workflows/app/services/discourse_workflows/execution/check_stale_topics.rb
@@ -19,7 +19,7 @@ module DiscourseWorkflows
def process_stale_trigger_nodes(stale_trigger_nodes:)
stale_trigger_nodes.each do |published_trigger|
items =
- DiscourseWorkflows::Nodes::StaleTopic::V1.trigger_data_for(
+ NodeData.node_type(published_trigger.trigger_node).trigger_data_for(
DiscourseWorkflows::TriggerNodeContext.from_published_trigger(published_trigger),
)
next if items.empty?
diff --git a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_post_button.rb b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_post_button.rb
index 0e5a84b11ed..7da857ae7e4 100644
--- a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_post_button.rb
+++ b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_post_button.rb
@@ -65,7 +65,7 @@ module DiscourseWorkflows
def enqueue_workflow(published_trigger:, post:, guardian:)
DiscourseWorkflows::TriggerDispatcher.enqueue(
published_trigger,
- trigger_data: DiscourseWorkflows::Nodes::PostButton::V1.new(post).output,
+ trigger_data: NodeData.node_type(published_trigger.trigger_node).new(post).output,
user_id: guardian.user.id,
)
end
diff --git a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_topic_admin_button.rb b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_topic_admin_button.rb
index 233346d1d9d..b18794e2703 100644
--- a/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_topic_admin_button.rb
+++ b/plugins/discourse-workflows/app/services/discourse_workflows/workflow/trigger_topic_admin_button.rb
@@ -35,7 +35,7 @@ module DiscourseWorkflows
def enqueue_workflow(published_trigger:, topic:, guardian:)
DiscourseWorkflows::TriggerDispatcher.enqueue(
published_trigger,
- trigger_data: DiscourseWorkflows::Nodes::TopicAdminButton::V1.new(topic).output,
+ trigger_data: NodeData.node_type(published_trigger.trigger_node).new(topic).output,
user_id: guardian.user.id,
)
end
diff --git a/plugins/discourse-workflows/assets/stylesheets/common/canvas/canvas.scss b/plugins/discourse-workflows/assets/stylesheets/common/canvas/canvas.scss
index eb2ae8cc30b..43a54f33898 100644
--- a/plugins/discourse-workflows/assets/stylesheets/common/canvas/canvas.scss
+++ b/plugins/discourse-workflows/assets/stylesheets/common/canvas/canvas.scss
@@ -383,6 +383,28 @@
}
}
+ &__deprecated-badge {
+ position: absolute;
+ top: -6px;
+ left: -6px;
+ width: 20px;
+ height: 20px;
+ border-radius: 50%;
+ background: var(--tertiary);
+ color: var(--secondary);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ pointer-events: all;
+ padding: 0;
+ border: 2px solid var(--secondary);
+
+ .d-icon {
+ width: 10px;
+ height: 10px;
+ }
+ }
+
&__issues-title {
padding: var(--space-1) var(--space-2) var(--space-half);
font-size: var(--font-down-2);
diff --git a/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator-modal.scss b/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator-modal.scss
index e85b3c1b136..91e95e6a83b 100644
--- a/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator-modal.scss
+++ b/plugins/discourse-workflows/assets/stylesheets/common/configurator/configurator-modal.scss
@@ -247,6 +247,18 @@
}
}
+ .workflows-deprecation-notice {
+ display: flex;
+ align-items: center;
+ gap: var(--space-2);
+ padding: var(--space-2) var(--space-3);
+
+ .alert {
+ flex: 1;
+ margin: 0;
+ }
+ }
+
&__columns.is-unavailable {
pointer-events: none;
opacity: 0.5;
diff --git a/plugins/discourse-workflows/config/locales/client.en.yml b/plugins/discourse-workflows/config/locales/client.en.yml
index b3cbce8368c..fcb4d725163 100644
--- a/plugins/discourse-workflows/config/locales/client.en.yml
+++ b/plugins/discourse-workflows/config/locales/client.en.yml
@@ -54,6 +54,10 @@ en:
node_unavailable:
default: "This node is currently unavailable"
short: "Unavailable"
+ node_deprecated:
+ notice: "A newer version of this node is available. Its output changes: %{changes}. Expressions using the old keys must be updated after upgrading."
+ upgrade: "Upgrade"
+ topic_v1: "Posts now use a smaller shape: author details such as trust_level, name, avatar_template, admin and staff moved to user, and fields such as topic_archetype, wiki, hidden, edit_reason and reads were removed."
node_issues:
title: "Configuration issues"
required: "%{label} is required"
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_details.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_details.rb
index d12e4409e35..fad843a59e3 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_details.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_node_details.rb
@@ -73,6 +73,7 @@ module DiscourseWorkflows
name: node["name"],
type: node["type"],
type_version: node["typeVersion"],
+ deprecation: DiscourseWorkflows::NodeData.node_type(node)&.deprecation,
parameters: DiscourseWorkflows::NodeData.parameters(node),
incoming: connections_where("target_node_id", node_id, "source_node_id"),
outgoing: connections_where("source_node_id", node_id, "target_node_id"),
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/event_listener.rb b/plugins/discourse-workflows/lib/discourse_workflows/event_listener.rb
index 8bf874fa1d6..c83f9409dc3 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/event_listener.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/event_listener.rb
@@ -6,28 +6,34 @@ module DiscourseWorkflows
return unless SiteSetting.enable_discourse_workflows
return if WorkflowDependency.active_node_types.exclude?(trigger_class.identifier)
+ published_triggers =
+ WorkflowDependency
+ .cached_published_triggers(trigger_class.identifier)
+ .select do |published_trigger|
+ NodeData.type_version(published_trigger.trigger_node) == trigger_class.version
+ end
+ return if published_triggers.empty?
+
trigger = trigger_class.from_event(event_name, *args)
return unless trigger.valid?
trigger_data = nil
user_id = trigger.user_id if trigger.respond_to?(:user_id)
- WorkflowDependency
- .cached_published_triggers(trigger_class.identifier)
- .each do |published_trigger|
- next if !trigger.matches?(TriggerNodeContext.from_published_trigger(published_trigger))
+ published_triggers.each do |published_trigger|
+ next if !trigger.matches?(TriggerNodeContext.from_published_trigger(published_trigger))
- TriggerDispatcher.enqueue(
- published_trigger,
- trigger_data: (trigger_data ||= trigger.output),
- user_id: user_id,
- )
- rescue => e
- Rails.logger.error(
- "discourse-workflows: trigger #{trigger_class.identifier} failed " \
- "for workflow #{published_trigger.workflow_id}: #{e.message}",
- )
- end
+ TriggerDispatcher.enqueue(
+ published_trigger,
+ trigger_data: (trigger_data ||= trigger.output),
+ user_id: user_id,
+ )
+ rescue => e
+ Rails.logger.error(
+ "discourse-workflows: trigger #{trigger_class.identifier} failed " \
+ "for workflow #{published_trigger.workflow_id}: #{e.message}",
+ )
+ end
rescue => e
Rails.logger.error(
"discourse-workflows: trigger #{trigger_class.identifier} failed: #{e.message}",
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_data.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_data.rb
index 691da8ebdb1..fa9f08b382c 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_data.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_data.rb
@@ -22,6 +22,10 @@ module DiscourseWorkflows
WorkflowDocument.node_type_version(node) || Registry::DEFAULT_VERSION
end
+ def node_type(node)
+ Registry.find_node_type(read(node, "type"), version: type_version(node))
+ end
+
def webhook_id(node)
WorkflowDocument.node_webhook_id(node)
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
index 84aeb7f8adb..b573ca3e071 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_type.rb
@@ -124,6 +124,18 @@ module DiscourseWorkflows
end
end
+ def self.deprecated(superseded_by:, changes: {}, description_key: nil, notice_key: nil)
+ @deprecation = { superseded_by:, changes:, description_key:, notice_key: }.compact.freeze
+ end
+
+ def self.deprecation
+ @deprecation
+ end
+
+ def self.deprecated?
+ deprecation.present?
+ end
+
def self.identifier
description.fetch(:name) { raise NotImplementedError }
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_type_descriptor.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_type_descriptor.rb
index 48f15cb6249..911c5a97c7b 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_type_descriptor.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_type_descriptor.rb
@@ -52,7 +52,8 @@ module DiscourseWorkflows
end
def description_key
- description[:description_key] || "#{DEFAULT_I18N_PREFIX}.node_descriptions.#{identifier}"
+ deprecation&.dig(:description_key) || description[:description_key] ||
+ "#{DEFAULT_I18N_PREFIX}.node_descriptions.#{identifier}"
end
def group
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/node_type_serializer.rb b/plugins/discourse-workflows/lib/discourse_workflows/node_type_serializer.rb
index 9b96003d589..b337aac297e 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/node_type_serializer.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/node_type_serializer.rb
@@ -67,6 +67,7 @@ module DiscourseWorkflows
output_contracts: serializable_output_contracts(klass),
output_schema_resolver: klass.output_schema_resolver,
palette_visible: klass.palette_visible?,
+ deprecation: klass.deprecation,
previewable: klass.previewable?,
available: klass.available?,
unavailable_reason_key: (klass.unavailable_reason_key unless klass.available?),
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/workflow_graph_validator.rb b/plugins/discourse-workflows/lib/discourse_workflows/workflow_graph_validator.rb
index e95389d4590..2c559f90019 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/workflow_graph_validator.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/workflow_graph_validator.rb
@@ -328,8 +328,24 @@ module DiscourseWorkflows
end
def resolve_type_version(node_data, existing)
- existing&.dig("typeVersion").presence || node_data[:typeVersion].presence ||
- implicit_type_version(node_data, existing) || DiscourseWorkflows::Registry::DEFAULT_VERSION
+ stored_version = existing&.dig("typeVersion").presence
+ return upgraded_type_version(node_data, existing) || stored_version if stored_version
+
+ node_data[:typeVersion].presence || implicit_type_version(node_data, existing) ||
+ DiscourseWorkflows::Registry::DEFAULT_VERSION
+ end
+
+ def upgraded_type_version(node_data, existing)
+ requested_version = node_data[:typeVersion].presence
+ return if requested_version.nil? || existing["type"] != node_data[:type]
+ return if requested_version == existing["typeVersion"]
+
+ node_type =
+ DiscourseWorkflows::Registry.find_node_type(node_data[:type], version: requested_version)
+ return if node_type.nil? || node_type.deprecated?
+ return if Gem::Version.new(requested_version) <= Gem::Version.new(existing["typeVersion"])
+
+ requested_version
end
def implicit_type_version(node_data, existing)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb
index 9df2411983d..e08b87c3b90 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_node_catalog_spec.rb
@@ -72,6 +72,19 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowNodeCatalog do
expect(invoke_tool([hidden_node_type])).to include(nodes: [], unknown_types: [hidden_node_type])
end
+ it "returns the latest version for types with deprecated versions" do
+ register_versioned_workflow_nodes(
+ "action:catalog_deprecation_test",
+ v1_deprecation: {
+ superseded_by: "2.0",
+ },
+ )
+
+ result = invoke_tool(["action:catalog_deprecation_test"])
+
+ expect(result[:nodes].pluck(:version)).to eq(["2.0"])
+ end
+
it "includes Code node runtime notes" do
code_node = invoke_tool(["action:code"])[:nodes].first
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/event_listener_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/event_listener_spec.rb
index 5c2937ffdbc..9dabd2e0360 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/event_listener_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/event_listener_spec.rb
@@ -639,10 +639,75 @@ RSpec.describe DiscourseWorkflows::EventListener do
expect(enqueued_trigger_node_ids).to contain_exactly("user-search-trigger")
end
- def create_published_workflow(trigger_node_id, trigger_type, configuration: {})
+ describe "versioned triggers" do
+ let(:event_name) { :event_listener_versioned_trigger_test }
+ let(:plugin) { Plugin::Instance.new }
+
+ let(:v1) do
+ Class.new(DiscourseWorkflows::NodeType) do
+ description(
+ name: "trigger:event_listener_versioned_test",
+ version: "1.0",
+ event: :event_listener_versioned_trigger_test,
+ )
+
+ def initialize(payload, *)
+ super(parameters: {})
+ @payload = payload
+ end
+
+ def output
+ { "editor" => @payload }
+ end
+ end
+ end
+
+ let(:v2) do
+ Class.new(v1) do
+ description(superclass.description.merge(version: "2.0"))
+
+ def output
+ { "actor" => @payload }
+ end
+ end
+ end
+
+ before do
+ DiscourseWorkflows.node_registration_ready = true
+ plugin.register_discourse_workflows_node(v1)
+ plugin.register_discourse_workflows_node(v2)
+ end
+
+ after do
+ DiscourseEvent.all_off(event_name)
+ unregister_workflow_nodes(v1, v2)
+ end
+
+ it "dispatches each saved trigger with the output of its own version" do
+ create_published_workflow("v1-trigger", "trigger:event_listener_versioned_test")
+ create_published_workflow(
+ "v2-trigger",
+ "trigger:event_listener_versioned_test",
+ type_version: "2.0",
+ )
+
+ DiscourseEvent.trigger(event_name, "alice")
+
+ expect(enqueued_trigger_node_ids).to contain_exactly("v1-trigger", "v2-trigger")
+ expect(trigger_data_for("v1-trigger")).to eq("editor" => "alice")
+ expect(trigger_data_for("v2-trigger")).to eq("actor" => "alice")
+ end
+ end
+
+ def create_published_workflow(
+ trigger_node_id,
+ trigger_type,
+ configuration: {},
+ type_version: "1.0"
+ )
graph =
build_workflow_graph do |g|
- g.node trigger_node_id, trigger_type, configuration: configuration
+ g.node trigger_node_id, trigger_type, configuration:, type_version:
end
workflow = Fabricate(:discourse_workflows_workflow, created_by: user, published: true, **graph)
DiscourseWorkflows::WorkflowDependencyIndexer.call(workflow)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_descriptor_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_descriptor_spec.rb
index 7c77c0124eb..f28c8402ac0 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_descriptor_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_descriptor_spec.rb
@@ -36,6 +36,18 @@ RSpec.describe DiscourseWorkflows::NodeTypeDescriptor do
"discourse_workflows.node_descriptions.trigger:test_event",
)
end
+
+ it "uses the deprecated version's own key without leaking it to its successor" do
+ v1 =
+ Class.new(DiscourseWorkflows::NodeType) do
+ description(name: "trigger:test_event")
+ deprecated(superseded_by: "2.0", description_key: "discourse_workflows.old_event")
+ end
+ v2 = Class.new(v1) { description(superclass.description.merge(version: "2.0")) }
+
+ expect(v1.description_key).to eq("discourse_workflows.old_event")
+ expect(v2.description_key).to eq("discourse_workflows.node_descriptions.trigger:test_event")
+ end
end
describe "#i18n_prefix" do
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb
index 423d2d71bf5..922628e9574 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/node_type_serializer_spec.rb
@@ -104,5 +104,33 @@ RSpec.describe DiscourseWorkflows::NodeTypeSerializer do
expect(version[:palette_visible]).to eq(false)
expect(version[:output_contracts].pluck(:mode)).to eq(%i[passthrough passthrough])
end
+
+ it "serializes the deprecation of superseded versions" do
+ register_versioned_workflow_nodes(
+ "action:serializer_deprecation_test",
+ v1_deprecation: {
+ superseded_by: "2.0",
+ changes: {
+ "editor" => "actor",
+ },
+ notice_key: "discourse_workflows.node_deprecated.topic_v1",
+ },
+ )
+
+ serialized =
+ described_class.new(
+ identifier: "action:serializer_deprecation_test",
+ available_versions: %w[1.0 2.0],
+ ).to_h
+
+ expect(serialized.dig(:versions, "1.0", :deprecation)).to eq(
+ superseded_by: "2.0",
+ changes: {
+ "editor" => "actor",
+ },
+ notice_key: "discourse_workflows.node_deprecated.topic_v1",
+ )
+ expect(serialized.dig(:versions, "2.0")).not_to have_key(:deprecation)
+ end
end
end
diff --git a/plugins/discourse-workflows/spec/services/discourse_workflows/workflow/action/populate_graph_spec.rb b/plugins/discourse-workflows/spec/services/discourse_workflows/workflow/action/populate_graph_spec.rb
index 45f4eb4833b..d0b36efa20a 100644
--- a/plugins/discourse-workflows/spec/services/discourse_workflows/workflow/action/populate_graph_spec.rb
+++ b/plugins/discourse-workflows/spec/services/discourse_workflows/workflow/action/populate_graph_spec.rb
@@ -282,18 +282,7 @@ RSpec.describe DiscourseWorkflows::Workflow::Action::PopulateGraph do
context "when a node type has multiple versions" do
it "uses the latest version for new nodes without a submitted typeVersion" do
- v1 =
- Class.new(DiscourseWorkflows::NodeType) do
- description(name: "action:populate_versioned_test", version: "1.0")
- end
- v2 =
- Class.new(DiscourseWorkflows::NodeType) do
- description(name: "action:populate_versioned_test", version: "2.0")
- end
-
- DiscoursePluginRegistry.register_discourse_workflows_node(v1, Plugin::Instance.new)
- DiscoursePluginRegistry.register_discourse_workflows_node(v2, Plugin::Instance.new)
- DiscourseWorkflows::Registry.reset_indexes!
+ register_versioned_workflow_nodes("action:populate_versioned_test")
result =
described_class.call(
@@ -307,23 +296,10 @@ RSpec.describe DiscourseWorkflows::Workflow::Action::PopulateGraph do
expect(result).to eq(true)
expect(workflow.reload.nodes.first["typeVersion"]).to eq("2.0")
- ensure
- unregister_workflow_nodes(v1, v2)
end
it "keeps an existing versionless node on the default version" do
- v1 =
- Class.new(DiscourseWorkflows::NodeType) do
- description(name: "action:populate_versionless_test", version: "1.0")
- end
- v2 =
- Class.new(DiscourseWorkflows::NodeType) do
- description(name: "action:populate_versionless_test", version: "2.0")
- end
- plugin = Plugin::Instance.new
- DiscoursePluginRegistry.register_discourse_workflows_node(v1, plugin)
- DiscoursePluginRegistry.register_discourse_workflows_node(v2, plugin)
- DiscourseWorkflows::Registry.reset_indexes!
+ register_versioned_workflow_nodes("action:populate_versionless_test")
workflow.update!(
nodes: [
{
@@ -350,8 +326,34 @@ RSpec.describe DiscourseWorkflows::Workflow::Action::PopulateGraph do
expect(result).to eq(true)
expect(workflow.reload.nodes.first["typeVersion"]).to eq("1.0")
- ensure
- unregister_workflow_nodes(v1, v2)
+ end
+
+ it "upgrades an existing node only to a newer non-deprecated version" do
+ register_versioned_workflow_nodes(
+ "action:populate_upgrade_test",
+ v1_deprecation: {
+ superseded_by: "2.0",
+ },
+ )
+ node = { "id" => "node-1", "type" => "action:populate_upgrade_test", "name" => "Node" }
+ save = ->(type_version, type = node["type"]) do
+ described_class.call(
+ workflow:,
+ nodes_data: [node.merge("type" => type, "typeVersion" => type_version)],
+ connections_data: {
+ },
+ )
+ workflow.reload.nodes.first["typeVersion"]
+ end
+ workflow.update!(nodes: [node.merge("typeVersion" => "1.0")], connections: {})
+
+ expect(save.call("9.0")).to eq("1.0")
+ expect(save.call("2.0")).to eq("2.0")
+ expect(save.call("1.0")).to eq("2.0")
+
+ register_versioned_workflow_nodes("action:populate_upgrade_other_test")
+ workflow.update!(nodes: [node.merge("typeVersion" => "1.0")], connections: {})
+ expect(save.call("2.0", "action:populate_upgrade_other_test")).to eq("1.0")
end
end
diff --git a/plugins/discourse-workflows/spec/support/workflow_graph_builder.rb b/plugins/discourse-workflows/spec/support/workflow_graph_builder.rb
index 7f291e4a68f..868320c98e7 100644
--- a/plugins/discourse-workflows/spec/support/workflow_graph_builder.rb
+++ b/plugins/discourse-workflows/spec/support/workflow_graph_builder.rb
@@ -16,7 +16,8 @@ module DiscourseWorkflows
credentials: {},
webhook_id: nil,
position: nil,
- configuration: {}
+ configuration: {},
+ type_version: "1.0"
)
configuration = configuration.deep_stringify_keys
webhook_id ||=
@@ -35,7 +36,7 @@ module DiscourseWorkflows
node = {
"id" => id,
"type" => type,
- "typeVersion" => "1.0",
+ "typeVersion" => type_version,
"name" => name || id.to_s.humanize,
"position" => position || { "x" => @position_counter * 220, "y" => 0 },
"parameters" => split["parameters"],
diff --git a/plugins/discourse-workflows/spec/support/workflow_node_registry_helpers.rb b/plugins/discourse-workflows/spec/support/workflow_node_registry_helpers.rb
index fba3aa89d2e..72ea7d604b9 100644
--- a/plugins/discourse-workflows/spec/support/workflow_node_registry_helpers.rb
+++ b/plugins/discourse-workflows/spec/support/workflow_node_registry_helpers.rb
@@ -2,6 +2,21 @@
module DiscourseWorkflows
module WorkflowNodeRegistryHelpers
+ def register_versioned_workflow_nodes(identifier, v1_deprecation: nil)
+ v1 =
+ Class.new(NodeType) do
+ description(name: identifier, version: "1.0")
+ deprecated(**v1_deprecation) if v1_deprecation
+ end
+ v2 = Class.new(v1) { description(superclass.description.merge(version: "2.0")) }
+ (@registered_workflow_nodes ||= []).push(v1, v2)
+ [v1, v2].each do |node_class|
+ DiscourseWorkflows.register_node(node_class, Plugin::Instance.new)
+ end
+ Registry.reset_indexes!
+ [v1, v2]
+ end
+
def unregister_workflow_nodes(*node_classes)
references = node_classes.compact.flat_map { |node_class| [node_class, node_class.name] }
DiscoursePluginRegistry._raw_discourse_workflows_nodes.reject! do |entry|
@@ -13,4 +28,9 @@ module DiscourseWorkflows
end
end
-RSpec.configure { |config| config.include DiscourseWorkflows::WorkflowNodeRegistryHelpers }
+RSpec.configure do |config|
+ config.include DiscourseWorkflows::WorkflowNodeRegistryHelpers
+ config.after do
+ unregister_workflow_nodes(*@registered_workflow_nodes) if @registered_workflow_nodes
+ end
+end
diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/deprecation-notice-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/deprecation-notice-test.gjs
new file mode 100644
index 00000000000..ea74ceff1b5
--- /dev/null
+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/deprecation-notice-test.gjs
@@ -0,0 +1,66 @@
+import { click, render } from "@ember/test-helpers";
+import { module, test } from "qunit";
+import { setupRenderingTest } from "discourse/tests/helpers/component-test";
+import { i18n } from "discourse-i18n";
+import DeprecationNotice from "discourse/plugins/discourse-workflows/admin/components/workflows/node/deprecation-notice";
+
+const DEPRECATION = {
+ changes: { editor: "actor", user: "author" },
+ superseded_by: "2.0",
+};
+
+module(
+ "Integration | Component | workflows deprecation notice",
+ function (hooks) {
+ setupRenderingTest(hooks);
+
+ test("lists the output changes of the newer version", async function (assert) {
+ await render(
+ <template><DeprecationNotice @deprecation={{DEPRECATION}} /></template>
+ );
+
+ assert.dom(".workflows-deprecation-notice .alert").hasText(
+ i18n("discourse_workflows.node_deprecated.notice", {
+ changes: "editor → actor, user → author",
+ })
+ );
+ });
+
+ test("appends the translated notice", async function (assert) {
+ const deprecation = {
+ ...DEPRECATION,
+ notice_key: "discourse_workflows.node_deprecated.topic_v1",
+ };
+
+ await render(
+ <template><DeprecationNotice @deprecation={{deprecation}} /></template>
+ );
+
+ assert
+ .dom(".workflows-deprecation-notice .alert")
+ .includesText(i18n("discourse_workflows.node_deprecated.topic_v1"));
+ });
+
+ test("upgrades the node", async function (assert) {
+ const upgrade = () => assert.step("upgrade");
+
+ await render(
+ <template>
+ <DeprecationNotice
+ @deprecation={{DEPRECATION}}
+ @onUpgrade={{upgrade}}
+ />
+ </template>
+ );
+ await click(".workflows-deprecation-notice__upgrade");
+
+ assert.verifySteps(["upgrade"]);
+ });
+
+ test("renders nothing for current versions", async function (assert) {
+ await render(<template><DeprecationNotice /></template>);
+
+ assert.dom(".workflows-deprecation-notice").doesNotExist();
+ });
+ }
+);
diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/editor-save-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/editor-save-test.gjs
index d08f31aafe0..7fe77cb688a 100644
--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/editor-save-test.gjs
+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/editor-save-test.gjs
@@ -5,11 +5,17 @@ import WorkflowsEditor from "discourse/plugins/discourse-workflows/admin/compone
import WorkflowNode from "discourse/plugins/discourse-workflows/admin/models/workflow-node";
let editor;
+let editedNodes;
class TestEditor extends WorkflowsEditor {
constructor() {
super(...arguments);
editor = this;
+ editedNodes = [];
+ }
+
+ editNode(clientId) {
+ editedNodes.push(clientId);
}
<template></template>
@@ -76,4 +82,34 @@ module("Integration | Component | workflows editor saves", function (hooks) {
assert.strictEqual(saves[1].nodes[0].configuration.message, "Y");
});
+
+ test("upgradeNode is not undoable", async function (assert) {
+ const { workflow, saves } = savingWorkflow([
+ { clientId: "n1", type: "action:log", name: "Log", typeVersion: "1.0" },
+ ]);
+ await renderEditor(workflow);
+
+ const upgrading = editor.upgradeNode("n1");
+ await waitUntil(() => saves.length === 1);
+ saves[0].resolve();
+ await upgrading;
+
+ assert.false(editor.undoManager.hasPendingCapture);
+ assert.deepEqual(editedNodes, ["n1"]);
+ });
+
+ test("upgradeNode does not reopen the node once the editor is destroyed", async function (assert) {
+ const { workflow, saves } = savingWorkflow([
+ { clientId: "n1", type: "action:log", name: "Log", typeVersion: "1.0" },
+ ]);
+ await renderEditor(workflow);
+
+ const upgrading = editor.upgradeNode("n1");
+ await waitUntil(() => saves.length === 1);
+ await render(<template></template>);
+ saves[0].resolve();
+ await upgrading;
+
+ assert.deepEqual(editedNodes, []);
+ });
});
diff --git a/plugins/discourse-workflows/test/javascripts/unit/components/workflows/canvas/canvas-bridge-test.js b/plugins/discourse-workflows/test/javascripts/unit/components/workflows/canvas/canvas-bridge-test.js
index 4211b94de87..012752a4a29 100644
--- a/plugins/discourse-workflows/test/javascripts/unit/components/workflows/canvas/canvas-bridge-test.js
+++ b/plugins/discourse-workflows/test/javascripts/unit/components/workflows/canvas/canvas-bridge-test.js
@@ -123,6 +123,31 @@ module("Unit | Canvas Bridge", function (hooks) {
bridge.destroy();
});
+ test("syncState re-renders a node whose typeVersion changed", async function (assert) {
+ const bridge = await createReteEditor(container, {
+ callbacks: noopCallbacks(),
+ nodeTypes: NODE_TYPES,
+ });
+ const node = {
+ clientId: "n1",
+ type: "trigger:manual",
+ typeVersion: "1.0",
+ position: { x: 0, y: 0 },
+ };
+ await bridge.syncState([node], []);
+
+ const updated = [];
+ const update = bridge.area.update.bind(bridge.area);
+ bridge.area.update = (type, id) => {
+ updated.push(id);
+ return update(type, id);
+ };
+ await bridge.syncState([{ ...node, typeVersion: "2.0" }], []);
+
+ assert.deepEqual(updated, ["n1"]);
+ bridge.destroy();
+ });
+
test("canvas drag selects nodes inside the selection rectangle", async function (assert) {
let selectionRect;
const bridge = await createReteEditor(container, {