A platform for community discussion. Free, open, simple.
DEV: bump limits for AI reports (#41214)
Sam917adbf16194
diff --git a/plugins/discourse-workflows/config/locales/client.en.yml b/plugins/discourse-workflows/config/locales/client.en.ymlindex be0ebed742e..b4e50816c56 100644--- a/plugins/discourse-workflows/config/locales/client.en.yml+++ b/plugins/discourse-workflows/config/locales/client.en.yml@@ -397,6 +397,8 @@ en:editor_username: "Editor"include_raw: "Include raw"include_cooked: "Include cooked"+ body_character_limit: "Body character limit"+ body_character_limit_description: "Maximum number of characters to keep from raw and cooked post bodies. Keeps the first half and last half. Use 0 for no limit."query: "Query"query_description: "Filter query using PostsFilter syntax (e.g. category:support username:system order:latest)"query_placeholder: "Filter posts by category, tag, author, keywords, or other criteria"@@ -449,7 +451,7 @@ en:oldest_topic: "Oldest topics"likes: "Most liked"limit: "Limit"- limit_description: "Maximum number of posts to return (1-500, default 30)"+ limit_description: "Maximum number of posts to return (1-800, default 30)"offset: "Offset"advanced_filter: "Advanced filter"advanced_filter_description: "Additional PostsFilter query string appended to the configured filters"diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rbindex 8f6debd7b40..aeea0d854f4 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor/execution_store.rb@@ -4,7 +4,7 @@ module DiscourseWorkflowsclass Executorclass ExecutionStoreMAX_EXECUTION_DATA_SIZE = 5.megabytes- MAX_STEP_IO_SIZE = 128.kilobytes+ MAX_STEP_IO_SIZE = 1280.kilobytesMAX_STEP_STRING_BYTES = 16.kilobytesMAX_STEP_COLLECTION_SIZE = 50MAX_STEP_IO_DEPTH = 8diff --git a/plugins/discourse-workflows/lib/discourse_workflows/js_sandbox.rb b/plugins/discourse-workflows/lib/discourse_workflows/js_sandbox.rbindex befc5946b50..343acbf8795 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/js_sandbox.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/js_sandbox.rb@@ -3,8 +3,8 @@module DiscourseWorkflowsclass JsSandboxEVAL_TIMEOUT_MS = 100- MAX_INJECTED_JSON_BYTES = 1.megabyte- MAX_MEMORY_BYTES = 10.megabytes+ MAX_INJECTED_JSON_BYTES = 5.megabytes+ MAX_MEMORY_BYTES = 50.megabytesMARSHAL_STACK_DEPTH = 20attr_reader :js_context, :logdiff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rbindex fef63e1c4bb..37482011fef 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post/v1.rb@@ -20,7 +20,7 @@ module DiscourseWorkflowsPOST_TYPE_OPTIONS = %w[regular all first reply moderator_action small_action whisper].freezeORDER_OPTIONS = %w[latest oldest latest_topic oldest_topic likes].freezeDEFAULT_LIMIT = 30- MAX_LIMIT = 500+ MAX_LIMIT = 800def self.list_string_property(control: nil, hidden: false)property = {@@ -177,6 +177,16 @@ module DiscourseWorkflows},},},+ body_character_limit: {+ type: :integer,+ required: false,+ default: 0,+ display_options: {+ show: {+ operation: %w[get list],+ },+ },+ },created_after: list_string_property(hidden: true),created_before: list_string_property(hidden: true),topic_created_after: list_string_property(hidden: true),@@ -250,6 +260,8 @@ module DiscourseWorkflowstype: :integer,required: false,default: DEFAULT_LIMIT,+ min: 1,+ max: MAX_LIMIT,display_options: {show: {operation: ["list"],@@ -320,6 +332,8 @@ module DiscourseWorkflows"include_raw" => exec_ctx.get_node_parameter("include_raw", item_index, default: true),"include_cooked" =>exec_ctx.get_node_parameter("include_cooked", item_index, default: false),+ "body_character_limit" =>+ exec_ctx.get_node_parameter("body_character_limit", item_index, default: 0),"query" => exec_ctx.get_node_parameter("query", item_index),"created_after" => exec_ctx.get_node_parameter("created_after", item_index),"created_before" => exec_ctx.get_node_parameter("created_before", item_index),@@ -408,15 +422,7 @@ module DiscourseWorkflowsactor = exec_ctx.actor_from_parameter("actor_username", item_index)raise Discourse::InvalidAccess if !actor.guardian.can_see?(post)- {- post:- exec_ctx.serialize_post(- post,- guardian: actor.guardian,- include_raw: config["include_raw"],- include_cooked: config["include_cooked"],- ),- }+ { post: serialized_post(exec_ctx, post, guardian: actor.guardian, config: config) }enddef list_posts(exec_ctx, config, item_index)@@ -437,16 +443,45 @@ module DiscourseWorkflowsposts = filter.search.includes(:user, topic: %i[category tags])posts.map do |post|- {- post:- exec_ctx.serialize_post(- post,- guardian: actor.guardian,- include_raw: config["include_raw"],- include_cooked: config["include_cooked"],- ),- }+ { post: serialized_post(exec_ctx, post, guardian: actor.guardian, config: config) }+ end+ end++ def serialized_post(exec_ctx, post, guardian:, config:)+ data =+ exec_ctx.serialize_post(+ post,+ guardian: guardian,+ include_raw: config["include_raw"],+ include_cooked: config["include_cooked"],+ )++ truncate_body_fields(data, config["body_character_limit"])+ end++ def truncate_body_fields(data, limit)+ limit = bounded_integer(limit, default: 0, min: 0)+ return data if limit <= 0++ %i[raw cooked].each do |field|+ value = data[field]+ next if !value.is_a?(String) || value.length <= limit++ data[field] = truncate_middle(value, limit)+ data[:"#{field}_truncated"] = true+ data[:"#{field}_original_length"] = value.lengthend++ data+ end++ def truncate_middle(value, limit)+ return "" if limit <= 0++ head_length = (limit / 2.0).ceil+ tail_length = limit - head_length+ characters = value.each_char.to_a+ characters.first(head_length).join + characters.last(tail_length).joinenddef query_from_config(config)diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rbindex 303a22e7d2c..807da0bcc3f 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_spec.rb@@ -286,6 +286,53 @@ RSpec.describe DiscourseWorkflows::Nodes::Post::V1 doexpect(result["post"]).not_to have_key("cooked")end+ it "truncates selected body fields for get and list operations" do+ raw = "abcdefghijklmnopqrstuvwxyz" * 2+ post = Fabricate(:post, user: user, raw: raw, post_number: 1)+ limit = 12+ expected_truncation = ->(value) do+ value.each_char.first(limit / 2).join + value.each_char.to_a.last(limit / 2).join+ end+ expected_raw = expected_truncation.call(raw)+ expected_cooked = expected_truncation.call(post.cooked)++ get_result =+ execute_node(+ configuration: {+ "operation" => "get",+ "post_id" => post.id.to_s,+ "include_raw" => true,+ "include_cooked" => true,+ "body_character_limit" => limit.to_s,+ },+ item: item,+ )+ list_result =+ execute_node_output(+ configuration: {+ "operation" => "list",+ "topics" => post.topic_id.to_s,+ "include_raw" => true,+ "include_cooked" => true,+ "body_character_limit" => limit.to_s,+ "limit" => "10",+ },+ item: item,+ ).first++ expect(get_result["post"]).to include(+ "raw" => expected_raw,+ "raw_truncated" => true,+ "raw_original_length" => raw.length,+ "cooked" => expected_cooked,+ "cooked_truncated" => true,+ "cooked_original_length" => post.cooked.length,+ )+ expect(+ list_result.map { |output_item| output_item.dig("json", "post", "raw") },+ ).to contain_exactly(expected_raw)+ end+it "raises when the actor cannot see the post" dogroup = Fabricate(:group)private_category = Fabricate(:private_category, group: group)diff --git a/plugins/discourse-workflows/spec/services/discourse_workflows/node_type/list_spec.rb b/plugins/discourse-workflows/spec/services/discourse_workflows/node_type/list_spec.rbindex da5bdff04c6..9abf8c1b5ad 100644--- a/plugins/discourse-workflows/spec/services/discourse_workflows/node_type/list_spec.rb+++ b/plugins/discourse-workflows/spec/services/discourse_workflows/node_type/list_spec.rb@@ -59,9 +59,11 @@ RSpec.describe DiscourseWorkflows::NodeType::List do:editor_username,:include_raw,:include_cooked,+ :body_character_limit,:query,)expect(node_type.dig(:properties, :operation, :default)).to eq("create")+ expect(node_type.dig(:properties, :limit)).to include(default: 30, min: 1, max: 800)expect(node_type[:operations].map { |operation| operation[:value] }).to eq(%w[create edit get list],)