discourse/lib/plugin/metadata.rb
Sérgio Saquetim 726fc21187
DEV: Enforce deprecation-free tests for preinstalled plugins/themes (#36445)
This PR implements stricter deprecation handling that enforces
deprecation-free tests for core and preinstalled plugins, while allowing
custom (non-preinstalled) plugins and themes to have deprecations
without causing test failures.

### Key Changes

#### CI Workflow Improvements
- Split plugin system tests into separate CI targets: `core-plugins`,
`official-plugins`, and `chat`
- Enhance `bin/turbo_rspec` to accept comma-separated exclude patterns
via `--exclude-pattern`
- Simplify workflow configuration with default `shell: bash` and
consolidated environment variables

#### Plugin Classification & Detection
- Centralize official plugins list in `config/official_plugins.json` for
unified backend and frontend access
- Detect preinstalled plugins by checking for absence of `.git`
directory
- Add `isOfficial` and `isPreinstalled` metadata flags to plugin info
- Add `data-preinstalled` and `data-official` attributes to all plugin
and theme script tags for runtime identification

#### Deprecation Source Tracking
- Track deprecation sources (core, plugin, or theme) through template
map and resolver to attribute deprecations correctly
- Improve `source-identifier.js` to detect admin UI plugin files in both
development and production environments
- Add source information to deprecation messages for better debugging

#### Test Infrastructure
- Modify `raise-on-deprecation` test helper to skip errors for custom
(non-preinstalled) plugins and themes
- Add `EMBER_RAISE_ON_DEPRECATION` environment variable to control
deprecation throwing behavior in Rails tests
- Automatically set `EMBER_RAISE_ON_DEPRECATION` for core and
preinstalled plugin/theme specs in `rails_helper.rb`
- Improve deprecation summary output for system specs with test/spec
origin tracking

#### Deprecation Workflow Enhancements
- Add `dont-throw` handler for selective deprecation bypassing in test
fixtures without raising errors
- Add `dont-count` handler for preventing deprecation counting in
specific scenarios (e.g., test fixtures)

#### Deprecation Fixes
- Fix pending deprecations across core plugins (chat, data-explorer,
discourse-subscriptions, gamification, house-ads, reactions,
rss-polling, styleguide)
- Update import paths and remove deprecated patterns
- Migrate deprecated Handlebars templates to JavaScript API

### Testing Strategy

With these changes:
- **Core and preinstalled plugins** must pass all tests without any
deprecations
- **Custom plugins and themes** can have deprecations without failing
tests
- Test fixtures can use `dont-throw` and `dont-count` handlers when
testing deprecation behavior itself
- System specs automatically configure deprecation enforcement based on
test file location

---------

Co-authored-by: David Taylor <david@taylorhq.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
2025-12-16 17:48:29 -03:00

63 lines
1.3 KiB
Ruby

# frozen_string_literal: true
# loaded really early
module Plugin
end
class Plugin::Metadata
# from config/official_plugins.json
OFFICIAL_PLUGINS =
Set.new(JSON.load_file(File.join(Rails.root, "config", "official_plugins.json")))
FIELDS = %i[name about version authors contact_emails url required_version meta_topic_id label]
attr_accessor(*FIELDS)
MAX_FIELD_LENGTHS = {
name: 75,
about: 350,
authors: 200,
contact_emails: 200,
url: 500,
label: 20,
}
def meta_topic_id=(value)
@meta_topic_id =
begin
Integer(value)
rescue StandardError
nil
end
end
def self.parse(text)
metadata = self.new
text.each_line { |line| break unless metadata.parse_line(line) }
metadata
end
def official?
OFFICIAL_PLUGINS.include?(name)
end
def parse_line(line)
line = line.strip
unless line.empty?
return false unless line[0] == "#"
attribute, *value = line[1..-1].split(":")
value = value.join(":")
attribute = attribute.strip.gsub(/ /, "_").to_sym
if FIELDS.include?(attribute)
self.public_send(
"#{attribute}=",
value.strip.truncate(MAX_FIELD_LENGTHS[attribute] || 1000),
)
end
end
true
end
end