A platform for community discussion. Free, open, simple.
DEV: Make JavaScript deprecation reports compact and actionable (#42997)
Martin Brennan05efed9db59c
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 188761a1002..121bbfd1216 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -71,6 +71,7 @@ jobs:LOAD_PLUGINS: ${{ (matrix.target == 'core-plugins' || matrix.target == 'official-plugins' || matrix.target == 'plugins' || matrix.target == 'chat') && '1' || '0' }}QUNIT_REUSE_BUILD: 1PLAYWRIGHT_BROWSERS_PATH: /home/discourse/.cache/ms-playwright+ DEPRECATION_REPORT_GROUP: ${{ matrix.build_type }}-${{ matrix.target }}strategy:fail-fast: false@@ -345,6 +346,24 @@ jobs:CHECKOUT_TIMEOUT: 10run: LD_PRELOAD="$RUBY_ALLOCATOR" RAILS_ENABLE_TEST_LOG=1 RAILS_TEST_LOG_LEVEL=error bin/turbo_rspec --format documentation tmp/themes/*/spec/system themes/*/spec/system+ - name: Prepare JS deprecation reports+ if: always() && (matrix.build_type == 'frontend' || matrix.build_type == 'system')+ run: |+ # Replace stale results even when a rerun produces no report files.+ if ! compgen -G 'tmp/deprecation-reports/*.json' > /dev/null; then+ mkdir -p tmp/deprecation-reports+ printf '%s\n' '{"format":1,"files":[],"unresolved":[]}' > "tmp/deprecation-reports/${DEPRECATION_REPORT_GROUP}-empty.json"+ fi++ - name: Upload JS deprecation reports+ uses: actions/upload-artifact@v7+ if: always() && (matrix.build_type == 'frontend' || matrix.build_type == 'system')+ with:+ name: deprecation-reports-${{ matrix.build_type }}-${{ matrix.target }}+ overwrite: true+ if-no-files-found: error+ path: tmp/deprecation-reports/*.json+- name: Upload failed system test artifactsuses: actions/upload-artifact@v7if: always() && matrix.build_type == 'system'@@ -377,6 +396,49 @@ jobs:name: flaky-test-reports-${{ matrix.build_type }}-${{ matrix.target }}path: tmp/turbo_rspec_flaky_tests-${{ matrix.build_type }}-${{ matrix.target }}-${{ job.check_run_id }}.json+ deprecation-report:+ name: JS deprecation report+ if: always() && github.repository == 'discourse/discourse' && needs.build.result != 'skipped'+ runs-on: ubuntu-latest+ needs: build+ permissions:+ actions: read+ contents: read+ steps:+ - name: Check for JS deprecation reports+ id: check-artifacts+ env:+ GH_TOKEN: ${{ github.token }}+ run: |+ artifact_ids=$(gh api "repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts?per_page=100" --jq '.artifacts[] | select(.name | startswith("deprecation-reports-")) | .id')+ if [ -n "$artifact_ids" ]; then+ echo "exists=true" >> "$GITHUB_OUTPUT"+ fi++ - uses: actions/checkout@v7+ if: steps.check-artifacts.outputs.exists == 'true'+ with:+ fetch-depth: 1++ - uses: actions/download-artifact@v7+ if: steps.check-artifacts.outputs.exists == 'true'+ with:+ pattern: deprecation-reports-*+ path: tmp/deprecation-report-parts+ merge-multiple: true++ - name: Build combined JS deprecation report+ if: steps.check-artifacts.outputs.exists == 'true'+ run: node frontend/discourse/lib/deprecation-report-cli.js merge tmp/js-deprecation-report.json tmp/deprecation-report-parts/*.json++ - name: Upload combined JS deprecation report+ uses: actions/upload-artifact@v7+ if: steps.check-artifacts.outputs.exists == 'true'+ with:+ name: js-deprecation-report+ path: tmp/js-deprecation-report.json+ overwrite: true+merge:if: github.repository == 'discourse/discourse' && github.ref == 'refs/heads/main'runs-on: ubuntu-latestdiff --git a/frontend/asset-processor/deprecation-report.test.mjs b/frontend/asset-processor/deprecation-report.test.mjsnew file mode 100644index 00000000000..5f34cbb73ff--- /dev/null+++ b/frontend/asset-processor/deprecation-report.test.mjs@@ -0,0 +1,397 @@+/* eslint-disable qunit/require-expect */+import fs from "node:fs";+import os from "node:os";+import path from "node:path";+import { SourceMapGenerator } from "source-map-js";+import { afterEach, expect, test } from "vitest";+import deprecationReport from "../discourse/lib/deprecation-report.js";++const {+ DeprecationStackResolver,+ buildReport,+ mergeReports,+ parseStack,+ renderReportSummary,+} = deprecationReport;++let temporaryDirectory;++afterEach(() => {+ if (temporaryDirectory) {+ fs.rmSync(temporaryDirectory, { recursive: true, force: true });+ temporaryDirectory = null;+ }+});++function addSource(generator, generatedLine, source, originalLine, code) {+ generator.addMapping({+ generated: { line: generatedLine, column: 0 },+ original: { line: originalLine, column: 0 },+ source,+ });+ generator.setSourceContent(+ source,+ `${"\n".repeat(originalLine - 1)}${code}\n`+ );+}++test("builds an actionable compact report from browser stacks", () => {+ temporaryDirectory = fs.mkdtempSync(+ path.join(os.tmpdir(), "discourse-deprecation-report-")+ );+ const sourceMap = new SourceMapGenerator({ file: "bundle.js" });+ addSource(+ sourceMap,+ 1,+ "frontend/discourse/app/lib/deprecated.js",+ 10,+ "deprecated(message, options);"+ );+ addSource(+ sourceMap,+ 2,+ "frontend/discourse/app/models/user.js",+ 427,+ "get groups() {}"+ );+ addSource(+ sourceMap,+ 3,+ "discourse/plugins/poll/discourse/components/poll.gjs",+ 71,+ "return user.groups;"+ );+ addSource(+ sourceMap,+ 4,+ "discourse/plugins/poll/component/poll-test.gjs",+ 12,+ 'test("shows a poll");'+ );+ fs.writeFileSync(+ path.join(temporaryDirectory, "bundle.js.map"),+ sourceMap.toString()+ );++ const report = buildReport({+ group: "frontend-plugins",+ entries: [+ {+ id: "discourse.user.groups",+ origin: "poll",+ count: 2,+ stack: [+ "Error",+ " at deprecated (http://localhost/bundle.js:1:1)",+ " at get groups (http://localhost/bundle.js:2:1)",+ " at Poll.groups (http://localhost/bundle.js:3:1)",+ ].join("\n"),+ testStack: " at test (http://localhost/bundle.js:4:1)",+ },+ ],+ totals: { "discourse.user.groups": 3 },+ totalsByOrigin: { poll: { "discourse.user.groups": 3 } },+ resolver: new DeprecationStackResolver({+ mapRoots: [temporaryDirectory],+ }),+ });++ expect(report).toEqual({+ format: 1,+ files: [+ {+ file: "plugins/poll/assets/javascripts/discourse/components/poll.gjs",+ deprecations: [+ {+ id: "discourse.user.groups",+ line: 71,+ code: "return user.groups;",+ count: 2,+ origins: { poll: 2 },+ groups: ["frontend-plugins"],+ specCount: 1,+ specs: ["plugins/poll/test/javascripts/component/poll-test.gjs:12"],+ },+ ],+ },+ ],+ unresolved: [+ {+ id: "discourse.user.groups",+ count: 1,+ origins: { poll: 1 },+ groups: ["frontend-plugins"],+ specCount: 0,+ specs: [],+ },+ ],+ });+ expect(JSON.stringify(report)).not.toContain("stack");+});++test.each([1, 2])(+ "keeps a deprecation unresolved when an unmapped frame precedes its source at stack position %i",+ (position) => {+ temporaryDirectory = fs.mkdtempSync(+ path.join(os.tmpdir(), "discourse-deprecation-report-")+ );+ const sourceMap = new SourceMapGenerator({ file: "bundle.js" });+ addSource(+ sourceMap,+ 1,+ path.resolve(import.meta.dirname, "../discourse/app/lib/deprecated.js"),+ 10,+ "deprecated(message, options);"+ );+ addSource(+ sourceMap,+ 2,+ path.resolve(import.meta.dirname, "../discourse/app/models/user.js"),+ 427,+ "get groups() {}"+ );+ addSource(+ sourceMap,+ 3,+ path.resolve(+ import.meta.dirname,+ "../discourse/app/components/example.gjs"+ ),+ 20,+ "pluginCallback();"+ );+ addSource(+ sourceMap,+ 4,+ path.resolve(+ import.meta.dirname,+ "../discourse/tests/integration/components/example-test.gjs"+ ),+ 12,+ 'test("renders the component");'+ );+ fs.writeFileSync(+ path.join(temporaryDirectory, "bundle.js.map"),+ sourceMap.toString()+ );+ const frames = [+ " at deprecated (http://localhost/bundle.js:1:1)",+ " at get groups (http://localhost/bundle.js:2:1)",+ " at Example.render (http://localhost/bundle.js:3:1)",+ " at test (http://localhost/bundle.js:4:1)",+ ];+ frames.splice(+ position,+ 0,+ " at pluginCallback (http://localhost/plugin.js:1:1)"+ );++ const report = buildReport({+ group: "frontend-plugins",+ entries: [+ {+ id: "discourse.user.groups",+ origin: "example-plugin",+ count: 3,+ stack: frames.join("\n"),+ },+ ],+ resolver: new DeprecationStackResolver({+ mapRoots: [temporaryDirectory],+ }),+ });++ expect(report.files).toEqual([]);+ expect(report.unresolved).toEqual([+ {+ id: "discourse.user.groups",+ count: 3,+ origins: { "example-plugin": 3 },+ groups: ["frontend-plugins"],+ specCount: 1,+ specs: [+ "frontend/discourse/tests/integration/components/example-test.gjs:12",+ ],+ },+ ]);+ }+);++test("resolves plugin admin source maps to the admin JavaScript directory", () => {+ temporaryDirectory = fs.mkdtempSync(+ path.join(os.tmpdir(), "discourse-deprecation-report-")+ );+ const sourceMap = new SourceMapGenerator({ file: "admin.js" });+ addSource(+ sourceMap,+ 1,+ "discourse/plugins/automation/admin/components/automation-enabled-toggle.gjs",+ 10,+ "user.groups;"+ );+ fs.writeFileSync(+ path.join(temporaryDirectory, "admin.js.map"),+ sourceMap.toString()+ );++ const resolver = new DeprecationStackResolver({+ mapRoots: [temporaryDirectory],+ });+ const frame = resolver.resolveFrame({+ fn: "toggle",+ url: "http://localhost/admin.js",+ line: 1,+ column: 1,+ });++ expect(frame).toMatchObject({+ file: "plugins/automation/admin/assets/javascripts/admin/components/automation-enabled-toggle.gjs",+ line: 10,+ resolved: true,+ });+});++test("keeps direct call-site attribution separate from caller attribution", () => {+ temporaryDirectory = fs.mkdtempSync(+ path.join(os.tmpdir(), "discourse-deprecation-report-")+ );+ const sourceMap = new SourceMapGenerator({ file: "bundle.js" });+ addSource(+ sourceMap,+ 1,+ "frontend/discourse/app/lib/deprecated.js",+ 10,+ "deprecated(message, options);"+ );+ addSource(+ sourceMap,+ 2,+ "discourse/plugins/example/discourse/initializers/legacy.js.es6",+ 5,+ "deprecated(message, options);"+ );+ addSource(+ sourceMap,+ 3,+ "discourse/plugins/example/discourse/initializers/loader.js",+ 20,+ "loadLegacy();"+ );+ fs.writeFileSync(+ path.join(temporaryDirectory, "bundle.js.map"),+ sourceMap.toString()+ );+ const entry = {+ id: "discourse.es6-extension",+ origin: "example",+ stack: [+ " at deprecated (http://localhost/bundle.js:1:1)",+ " at legacy (http://localhost/bundle.js:2:1)",+ " at loader (http://localhost/bundle.js:3:1)",+ ].join("\n"),+ };++ const report = buildReport({+ entries: [+ { ...entry, count: 2, reportAtCallSite: true },+ { ...entry, count: 1 },+ ],+ resolver: new DeprecationStackResolver({ mapRoots: [temporaryDirectory] }),+ });++ expect(+ report.files.map(({ file, deprecations }) => ({+ file,+ count: deprecations[0].count,+ }))+ ).toEqual([+ {+ file: "plugins/example/assets/javascripts/discourse/initializers/legacy.js.es6",+ count: 2,+ },+ {+ file: "plugins/example/assets/javascripts/discourse/initializers/loader.js",+ count: 1,+ },+ ]);+ expect(report.unresolved).toEqual([]);+});++test("merges compact reports and renders the shared summary", () => {+ const first = {+ format: 1,+ files: [+ {+ file: "frontend/discourse/app/models/user.js",+ deprecations: [+ {+ id: "discourse.user.groups",+ line: 10,+ code: "user.groups;",+ count: 2,+ origins: { core: 2 },+ groups: ["frontend-core"],+ specCount: 1,+ specs: ["frontend/discourse/tests/unit/user-test.js:20"],+ },+ ],+ },+ ],+ unresolved: [],+ };+ const second = {+ format: 1,+ files: [+ {+ file: "frontend/discourse/app/models/user.js",+ deprecations: [+ {+ id: "discourse.user.groups",+ line: 10,+ code: "user.groups;",+ count: 1,+ origins: { chat: 1 },+ groups: ["system-chat"],+ specCount: 1,+ specs: ["plugins/chat/spec/system/user_spec.rb:8"],+ },+ ],+ },+ ],+ unresolved: [],+ };++ const merged = mergeReports([first, second]);+ const deprecation = merged.files[0].deprecations[0];+ expect(deprecation.count).toBe(3);+ expect(deprecation.origins).toEqual({ chat: 1, core: 2 });+ expect(deprecation.groups).toEqual(["frontend-core", "system-chat"]);+ expect(deprecation.specCount).toBe(2);++ const summary = renderReportSummary(merged);+ expect(summary).toContain("| discourse.user.groups | 3 |");+ expect(summary).toContain(+ "| discourse.user.groups | frontend/discourse/app/models/user.js:10 | 3 | 2 |"+ );+});++test("parses Chrome and Firefox stack frames", () => {+ expect(+ parseStack(+ " at run (http://localhost/assets/app.js:10:2)\nnext@http://localhost/assets/app.js:20:3"+ )+ ).toEqual([+ {+ fn: "run",+ url: "http://localhost/assets/app.js",+ line: 10,+ column: 2,+ },+ {+ fn: "next",+ url: "http://localhost/assets/app.js",+ line: 20,+ column: 3,+ },+ ]);+});diff --git a/frontend/asset-processor/testem-reporter.test.mjs b/frontend/asset-processor/testem-reporter.test.mjsnew file mode 100644index 00000000000..83980214f57--- /dev/null+++ b/frontend/asset-processor/testem-reporter.test.mjs@@ -0,0 +1,35 @@+/* eslint-disable qunit/require-expect */+import { createRequire } from "node:module";+import { afterEach, expect, test, vi } from "vitest";++const require = createRequire(import.meta.url);++afterEach(() => vi.unstubAllGlobals());++test("count-only updates preserve deprecation details and the highest count", () => {+ vi.stubGlobal("fetch", vi.fn().mockResolvedValue({}));+ const { reporter: Reporter } = require("../discourse/testem.js");+ const reporter = new Reporter(true, { write() {} }, { get() {} });+ const detail = {+ key: "browser-deprecation",+ id: "reported.deprecation",+ origin: "core",+ stack: "source stack",+ module: "Unit | Lib | example",+ testName: "example test",+ testStack: "test stack",+ count: 1,+ };++ reporter.reportMetadata("deprecation-details", { details: [{ ...detail }] });+ reporter.reportMetadata("deprecation-details", {+ details: [{ key: detail.key, count: 3 }],+ });+ reporter.reportMetadata("deprecation-details", {+ details: [{ key: detail.key, count: 2 }],+ });++ expect([...reporter.deprecationDetails.values()]).toEqual([+ { ...detail, count: 3 },+ ]);+});diff --git a/frontend/discourse/app/lib/deprecated.js b/frontend/discourse/app/lib/deprecated.jsindex 67f7dc5714a..d2f1c15ae78 100644--- a/frontend/discourse/app/lib/deprecated.js+++ b/frontend/discourse/app/lib/deprecated.js@@ -30,6 +30,7 @@ let emberDeprecationSilencer;* @param {String} [options.id] A unique identifier for this deprecation. This should be namespaced by dots (e.g. discourse.my_deprecation)* @param {String} [options.since] The Discourse version this deprecation was introduced in* @param {String} [options.url] A URL which provides more detail about the deprecation+ * @param {boolean} [options.reportAtCallSite] Attribute test reports to the code calling deprecated(), rather than its caller. Defaults to `false`* @param {boolean} [options.raiseError] Raise an error when this deprecation is triggered. Defaults to `false`*/export default function deprecated(msg, options = {}) {diff --git a/frontend/discourse/lib/deprecation-report-cli.js b/frontend/discourse/lib/deprecation-report-cli.jsnew file mode 100755index 00000000000..d49a041caa1--- /dev/null+++ b/frontend/discourse/lib/deprecation-report-cli.js@@ -0,0 +1,47 @@+#!/usr/bin/env node+"use strict";++const fs = require("fs");+const path = require("path");+const {+ mergeReports,+ renderReportSummary,+} = require("./deprecation-report-format");++const REPO_ROOT = path.resolve(__dirname, "..", "..", "..");+const [command, outputFile, ...args] = process.argv.slice(2);++function writeReport(report) {+ fs.mkdirSync(path.dirname(outputFile), { recursive: true });+ fs.writeFileSync(outputFile, `${JSON.stringify(report, null, 2)}\n`);++ const relativePath = path.relative(REPO_ROOT, outputFile);+ process.stdout.write(+ `${renderReportSummary(report, { reportLocation: `\`${relativePath}\`` })}\n`+ );++ if (process.env.GITHUB_ACTIONS && process.env.GITHUB_STEP_SUMMARY) {+ fs.appendFileSync(+ process.env.GITHUB_STEP_SUMMARY,+ `${renderReportSummary(report, {+ reportLocation: "the `js-deprecation-report` artifact",+ })}\n`+ );+ }+}++if (command === "build") {+ const { buildReport } = require("./deprecation-report");+ const payload = JSON.parse(fs.readFileSync(0, "utf8"));+ writeReport(buildReport({ ...payload, group: args[0] }));+} else if (command === "merge" && args.length > 0) {+ const reports = args.map((file) => JSON.parse(fs.readFileSync(file, "utf8")));+ writeReport(mergeReports(reports));+} else {+ process.stderr.write(+ "Usage:\n" ++ " deprecation-report-cli.js build <output-file> <group> < entries.json\n" ++ " deprecation-report-cli.js merge <output-file> <report.json...>\n"+ );+ process.exitCode = 1;+}diff --git a/frontend/discourse/lib/deprecation-report-format.js b/frontend/discourse/lib/deprecation-report-format.jsnew file mode 100644index 00000000000..7394e85309d--- /dev/null+++ b/frontend/discourse/lib/deprecation-report-format.js@@ -0,0 +1,322 @@+"use strict";++const FORMAT_VERSION = 1;+const MAX_SITE_SPECS = 10;++function increment(map, key, count) {+ map.set(key, (map.get(key) || 0) + count);+}++function newAggregate({ id, file = null, line = null, code = null }) {+ return {+ id,+ file,+ line,+ code,+ count: 0,+ origins: new Map(),+ groups: new Set(),+ specs: new Set(),+ specCount: 0,+ };+}++function addOccurrence(aggregate, occurrence, group) {+ aggregate.count += occurrence.count;+ increment(aggregate.origins, occurrence.origin, occurrence.count);+ aggregate.groups.add(group);++ if (occurrence.spec && !aggregate.specs.has(occurrence.spec)) {+ aggregate.specs.add(occurrence.spec);+ aggregate.specCount++;+ }+}++function addSerializedAggregate(aggregate, serialized) {+ aggregate.count += serialized.count || 0;+ for (const [origin, count] of Object.entries(serialized.origins || {})) {+ increment(aggregate.origins, origin, count);+ }+ for (const group of serialized.groups || []) {+ aggregate.groups.add(group);+ }+ for (const spec of serialized.specs || []) {+ aggregate.specs.add(spec);+ }+ aggregate.specCount += serialized.specCount || serialized.specs?.length || 0;+}++function serializeAggregate(aggregate) {+ const result = {+ id: aggregate.id,+ count: aggregate.count,+ origins: Object.fromEntries(+ Array.from(aggregate.origins.entries()).sort(([left], [right]) =>+ left.localeCompare(right)+ )+ ),+ groups: Array.from(aggregate.groups).sort(),+ specCount: Math.max(aggregate.specCount, aggregate.specs.size),+ specs: Array.from(aggregate.specs).sort().slice(0, MAX_SITE_SPECS),+ };++ if (aggregate.line !== null) {+ result.line = aggregate.line;+ }+ if (aggregate.code) {+ result.code = aggregate.code;+ }++ return result;+}++class ReportAccumulator {+ #sites = new Map();+ #unresolved = new Map();++ addOccurrence(occurrence, group) {+ if (!occurrence.site) {+ this.#addUnresolved(occurrence, group);+ return;+ }++ const { file, line, code } = occurrence.site;+ const key = `${file}\u0000${occurrence.id}\u0000${line}`;+ let aggregate = this.#sites.get(key);+ if (!aggregate) {+ aggregate = newAggregate({ id: occurrence.id, file, line, code });+ this.#sites.set(key, aggregate);+ }+ addOccurrence(aggregate, occurrence, group);+ }++ reconcileTotals(group, totals, totalsByOrigin) {+ const accountedById = new Map();+ const accountedByOrigin = new Map();++ for (const aggregate of [+ ...this.#sites.values(),+ ...this.#unresolved.values(),+ ]) {+ increment(accountedById, aggregate.id, aggregate.count);+ for (const [origin, count] of aggregate.origins) {+ increment(accountedByOrigin, `${origin}\u0000${aggregate.id}`, count);+ }+ }++ for (const [origin, originTotals] of Object.entries(totalsByOrigin || {})) {+ for (const [id, total] of Object.entries(originTotals)) {+ const missing =+ total - (accountedByOrigin.get(`${origin}\u0000${id}`) || 0);+ if (missing > 0) {+ this.#addUnresolved(+ { id, count: missing, origin, spec: null },+ group+ );+ increment(accountedById, id, missing);+ }+ }+ }++ for (const [id, total] of Object.entries(totals || {})) {+ const missing = total - (accountedById.get(id) || 0);+ if (missing > 0) {+ this.#addUnresolved(+ { id, count: missing, origin: "unknown", spec: null },+ group+ );+ }+ }+ }++ addReport(report) {+ validateReport(report);++ for (const fileEntry of report.files) {+ for (const deprecation of fileEntry.deprecations) {+ const key = `${fileEntry.file}\u0000${deprecation.id}\u0000${deprecation.line}`;+ let aggregate = this.#sites.get(key);+ if (!aggregate) {+ aggregate = newAggregate({+ id: deprecation.id,+ file: fileEntry.file,+ line: deprecation.line,+ code: deprecation.code,+ });+ this.#sites.set(key, aggregate);+ }+ addSerializedAggregate(aggregate, deprecation);+ }+ }++ for (const deprecation of report.unresolved || []) {+ let aggregate = this.#unresolved.get(deprecation.id);+ if (!aggregate) {+ aggregate = newAggregate({ id: deprecation.id });+ this.#unresolved.set(deprecation.id, aggregate);+ }+ addSerializedAggregate(aggregate, deprecation);+ }+ }++ toReport() {+ const byFile = new Map();++ for (const site of this.#sites.values()) {+ if (!byFile.has(site.file)) {+ byFile.set(site.file, []);+ }+ byFile.get(site.file).push(serializeAggregate(site));+ }++ const files = Array.from(byFile, ([file, deprecations]) => ({+ file,+ deprecations: deprecations.sort(+ (left, right) =>+ (left.line || 0) - (right.line || 0) ||+ left.id.localeCompare(right.id)+ ),+ })).sort((left, right) => left.file.localeCompare(right.file));++ return {+ format: FORMAT_VERSION,+ files,+ unresolved: Array.from(+ this.#unresolved.values(),+ serializeAggregate+ ).sort((left, right) => left.id.localeCompare(right.id)),+ };+ }++ #addUnresolved(occurrence, group) {+ let aggregate = this.#unresolved.get(occurrence.id);+ if (!aggregate) {+ aggregate = newAggregate({ id: occurrence.id });+ this.#unresolved.set(occurrence.id, aggregate);+ }+ addOccurrence(aggregate, occurrence, group);+ }+}++function validateReport(report) {+ if (report?.format !== FORMAT_VERSION || !Array.isArray(report.files)) {+ throw new Error("Unsupported deprecation report format");+ }+}++function mergeReports(reports) {+ const accumulator = new ReportAccumulator();+ for (const report of reports) {+ accumulator.addReport(report);+ }+ return accumulator.toReport();+}++function reportTotals(report) {+ const totals = new Map();+ const origins = new Map();+ const all = [+ ...report.files.flatMap((entry) => entry.deprecations),+ ...(report.unresolved || []),+ ];++ for (const deprecation of all) {+ increment(totals, deprecation.id, deprecation.count);+ for (const [origin, count] of Object.entries(deprecation.origins || {})) {+ increment(origins, `${origin}\u0000${deprecation.id}`, count);+ }+ }++ return { totals, origins };+}++function markdownTable(headers, rows) {+ const escape = (value) => String(value).replaceAll("|", "\\|");+ let output = `| ${headers.map(escape).join(" | ")} |\n`;+ output += `| ${headers.map(() => "---").join(" | ")} |\n`;+ for (const row of rows) {+ output += `| ${row.map(escape).join(" | ")} |\n`;+ }+ return output;+}++function renderReportSummary(+ report,+ { detailLimit = 25, reportLocation } = {}+) {+ validateReport(report);+ const { totals, origins } = reportTotals(report);++ if (totals.size === 0) {+ return "### JS deprecations\n\nNo deprecations logged.\n";+ }++ let output =+ "### ⚠️ JS deprecations\n\nTest run completed with deprecations:\n\n";+ output += markdownTable(+ ["id", "count"],+ Array.from(totals.entries())+ .sort(([left], [right]) => left.localeCompare(right))+ .map(([id, count]) => [id, count])+ );++ if (origins.size > 0) {+ output += "\nDeprecations by test origin:\n\n";+ output += markdownTable(+ ["origin", "id", "count"],+ Array.from(origins.entries())+ .map(([key, count]) => [...key.split("\u0000"), count])+ .sort(+ ([leftOrigin, leftId], [rightOrigin, rightId]) =>+ leftOrigin.localeCompare(rightOrigin) ||+ leftId.localeCompare(rightId)+ )+ );+ }++ const sites = report.files+ .flatMap(({ file, deprecations }) =>+ deprecations.map((deprecation) => ({ file, ...deprecation }))+ )+ .sort(+ (left, right) =>+ right.count - left.count ||+ left.file.localeCompare(right.file) ||+ left.line - right.line+ );++ if (sites.length > 0) {+ output += `\nTop ${Math.min(detailLimit, sites.length)} deprecated call sites:\n\n`;+ output += markdownTable(+ ["id", "call site", "count", "specs"],+ sites+ .slice(0, detailLimit)+ .map(({ id, file, line, count, specCount }) => [+ id,+ `${file}:${line}`,+ count,+ specCount,+ ])+ );+ }++ if (report.unresolved?.length > 0) {+ output += "\nUnresolved deprecations:\n\n";+ output += markdownTable(+ ["id", "count"],+ report.unresolved.map(({ id, count }) => [id, count])+ );+ }++ if (reportLocation) {+ output += `\nFull report: ${reportLocation}\n`;+ }++ return output;+}++module.exports = {+ ReportAccumulator,+ mergeReports,+ renderReportSummary,+};diff --git a/frontend/discourse/lib/deprecation-report.js b/frontend/discourse/lib/deprecation-report.jsnew file mode 100644index 00000000000..88318b91a6d--- /dev/null+++ b/frontend/discourse/lib/deprecation-report.js@@ -0,0 +1,372 @@+"use strict";++const fs = require("fs");+const path = require("path");+const { SourceMapConsumer } = require("source-map-js");+const {+ ReportAccumulator,+ mergeReports,+ renderReportSummary,+} = require("./deprecation-report-format");++const REPO_ROOT = path.resolve(__dirname, "..", "..", "..");+const MAP_ROOTS = [+ path.join(REPO_ROOT, "frontend", "discourse", "dist", "assets", "map"),+ path.join(REPO_ROOT, "app", "assets", "generated"),+];+const PLUMBING_PATTERNS = [+ /\/app\/lib\/deprecated\.js$/,+ /\/app\/lib\/source-identifier\.js$/,+ /\/tests\/helpers\/deprecation-counter\.js$/,+ /\/tests\/helpers\/raise-on-deprecation\.js$/,+ /\/ember-source\/.*\/deprecate\.js$/,+ /\/@ember\/debug\//,+];+const DEPRECATION_WRAPPER_PATTERN = /(^|\/)app\/lib\/deprecated\.js$/;+const TEST_FILE_PATTERN = /\/(tests?|spec)\/.*-test\.(js|gjs|ts|gts)$/;+const MAX_RESOLVED_FRAMES = 60;++function normalizeFile(file) {+ if (!file) {+ return null;+ }++ const normalized = file.replaceAll("\\", "/").replace(/^\.\//, "");+ const pluginMatch = normalized.match(+ /(?:^|\/)discourse\/plugins\/([^/]+)\/(.+)$/+ );++ if (pluginMatch) {+ const [, plugin, rest] = pluginMatch;+ const candidates = [+ `plugins/${plugin}/assets/javascripts/${rest}`,+ `plugins/${plugin}/admin/assets/javascripts/${rest}`,+ `plugins/${plugin}/test/javascripts/${rest}`,+ ];++ return (+ candidates.find((candidate) =>+ fs.existsSync(path.join(REPO_ROOT, candidate))+ ) || candidates[0]+ );+ }++ return normalized;+}++function normalizeMappedSource(source, mapPath) {+ const normalized = source+ .replace(/^webpack:\/\/[^/]*\//, "")+ .replaceAll("\\", "/");+ const absolute = path.isAbsolute(normalized)+ ? normalized+ : path.resolve(path.dirname(mapPath), normalized);+ const relative = path.relative(REPO_ROOT, absolute);++ return normalizeFile(relative.startsWith("..") ? absolute : relative);+}++class SourceMap {+ #consumer;+ #mapPath;++ constructor(json, mapPath) {+ this.#consumer = new SourceMapConsumer(json);+ this.#mapPath = mapPath;+ }++ originalPositionFor(line, column) {+ let original;+ let approximate = false;++ for (let back = 0; back <= 10 && line - back >= 1; back++) {+ original = this.#consumer.originalPositionFor({+ line: line - back,+ column: back === 0 ? column - 1 : Number.MAX_SAFE_INTEGER,+ bias: SourceMapConsumer.GREATEST_LOWER_BOUND,+ });++ if (original.source) {+ approximate = back > 0;+ break;+ }+ }++ if (!original?.source) {+ return null;+ }++ const source = this.#consumer.sourceContentFor(original.source, true);+ const code = source?.split("\n")[original.line - 1];++ return {+ file: normalizeMappedSource(original.source, this.#mapPath),+ line: original.line,+ column: original.column + 1,+ code: code === undefined ? null : code.trim().slice(0, 200),+ approximate,+ };+ }+}++class SourceMapIndex {+ #byBasename;+ #cache = new Map();+ #mapRoots;++ constructor(mapRoots = MAP_ROOTS) {+ this.#mapRoots = mapRoots;+ }++ forScript(scriptBasename) {+ if (this.#cache.has(scriptBasename)) {+ return this.#cache.get(scriptBasename);+ }++ const mapPath = this.#index().get(`${scriptBasename}.map`);+ let sourceMap = null;++ if (mapPath) {+ try {+ sourceMap = new SourceMap(+ JSON.parse(fs.readFileSync(mapPath, "utf8")),+ mapPath+ );+ } catch {+ sourceMap = null;+ }+ }++ this.#cache.set(scriptBasename, sourceMap);+ return sourceMap;+ }++ #index() {+ if (this.#byBasename) {+ return this.#byBasename;+ }++ this.#byBasename = new Map();+ for (const root of this.#mapRoots) {+ this.#walk(root);+ }+ return this.#byBasename;+ }++ #walk(directory, depth = 0) {+ if (depth > 6) {+ return;+ }++ let entries;+ try {+ entries = fs.readdirSync(directory, { withFileTypes: true });+ } catch {+ return;+ }++ for (const entry of entries) {+ const fullPath = path.join(directory, entry.name);+ if (entry.isDirectory()) {+ this.#walk(fullPath, depth + 1);+ } else if (entry.name.endsWith(".map")) {+ this.#byBasename.set(entry.name, fullPath);+ }+ }+ }+}++const STACK_FRAME_PATTERNS = [+ /^\s*at\s+(?<fn>.*?)\s+\((?<url>.*?):(?<line>\d+):(?<column>\d+)\)$/,+ /^\s*at\s+(?<url>.*?):(?<line>\d+):(?<column>\d+)$/,+ /^(?<fn>.*?)@(?<url>.*?):(?<line>\d+):(?<column>\d+)$/,+];++function parseStack(stack) {+ if (!stack) {+ return [];+ }++ const frames = [];++ for (const rawLine of stack.split("\n")) {+ const line = rawLine.trim();+ if (!line || line.startsWith("Error")) {+ continue;+ }++ for (const pattern of STACK_FRAME_PATTERNS) {+ const match = line.match(pattern);+ if (match) {+ frames.push({+ fn: match.groups.fn || null,+ url: match.groups.url,+ line: parseInt(match.groups.line, 10),+ column: parseInt(match.groups.column, 10),+ });+ break;+ }+ }+ }++ return frames;+}++function scriptBasenameFor(url) {+ try {+ return path.basename(new URL(url).pathname);+ } catch {+ return path.basename(url.split(/[?#]/)[0]);+ }+}++function isPlumbing(file) {+ return PLUMBING_PATTERNS.some((pattern) => pattern.test(`/${file}`));+}++function ownFrames(frames) {+ return frames.filter(+ (frame) =>+ frame.resolved &&+ !isPlumbing(frame.file) &&+ !frame.file.includes("node_modules/")+ );+}++class DeprecationStackResolver {+ #index;++ constructor({ mapRoots = MAP_ROOTS } = {}) {+ this.#index = new SourceMapIndex(mapRoots);+ }++ resolveFrame(frame) {+ const sourceMap = this.#index.forScript(scriptBasenameFor(frame.url));+ const original = sourceMap?.originalPositionFor(frame.line, frame.column);++ if (!original) {+ return {+ function: frame.fn,+ file: scriptBasenameFor(frame.url),+ line: frame.line,+ column: frame.column,+ resolved: false,+ };+ }++ return {+ function: frame.fn,+ ...original,+ resolved: true,+ };+ }++ resolveStack(stack, { maxFrames = MAX_RESOLVED_FRAMES } = {}) {+ return parseStack(stack)+ .slice(0, maxFrames)+ .map((frame) => this.resolveFrame(frame));+ }++ resolve(entry) {+ const frames = this.resolveStack(entry.stack);+ const owned = ownFrames(frames);+ const viaWrapper = frames.some(+ (frame) => frame.resolved && DEPRECATION_WRAPPER_PATTERN.test(frame.file)+ );+ const callers =+ viaWrapper && !entry.reportAtCallSite ? owned.slice(1) : owned;+ const candidate = callers[0];+ // An unmapped frame may be the actual caller, so don't attribute its+ // deprecation to a later frame just because that frame has a source map.+ const site =+ candidate &&+ frames+ .slice(0, frames.indexOf(candidate))+ .every((frame) => frame.resolved)+ ? candidate+ : null;+ const stackTestFrame = callers.find((frame) =>+ TEST_FILE_PATTERN.test(`/${frame.file}`)+ );+ const declaredTestFrame = this.resolveStack(entry.testStack, {+ maxFrames: 20,+ }).find(+ (frame) => frame.resolved && TEST_FILE_PATTERN.test(`/${frame.file}`)+ );+ const suppliedTest = entry.test || {};+ const testFile = suppliedTest.file+ ? normalizeFile(suppliedTest.file)+ : declaredTestFrame?.file || stackTestFrame?.file || null;+ const testLine =+ suppliedTest.callSiteLine ||+ suppliedTest.declarationLine ||+ stackTestFrame?.line ||+ declaredTestFrame?.line ||+ null;++ return {+ id: entry.id,+ count: entry.count || 1,+ origin: entry.origin || "unknown",+ site,+ spec: testFile+ ? `${testFile}${testLine ? `:${testLine}` : ""}`+ : suppliedTest.name || entry.testName || null,+ };+ }+}++function rawEntryKey(entry) {+ return [+ entry.id,+ entry.reportAtCallSite === true,+ entry.origin,+ entry.module,+ entry.testName,+ entry.test?.file,+ entry.test?.name,+ entry.stack,+ ].join("\u0000");+}++function mergeRawEntries(entries) {+ const merged = new Map();++ for (const entry of entries) {+ const key = rawEntryKey(entry);+ const existing = merged.get(key);++ if (existing) {+ existing.count += entry.count || 1;+ } else {+ merged.set(key, { ...entry, count: entry.count || 1 });+ }+ }++ return merged.values();+}++function buildReport({+ group,+ entries,+ totals = {},+ totalsByOrigin = {},+ resolver = new DeprecationStackResolver(),+}) {+ const accumulator = new ReportAccumulator();++ for (const entry of mergeRawEntries(entries)) {+ accumulator.addOccurrence(resolver.resolve(entry), group);+ }++ accumulator.reconcileTotals(group, totals, totalsByOrigin);+ return accumulator.toReport();+}++module.exports = {+ DeprecationStackResolver,+ buildReport,+ mergeReports,+ parseStack,+ renderReportSummary,+};diff --git a/frontend/discourse/package.json b/frontend/discourse/package.jsonindex c33f7c3a926..1ce1d5258bb 100644--- a/frontend/discourse/package.json+++ b/frontend/discourse/package.json@@ -174,6 +174,7 @@"qunit-dom": "^3.6.0","rolldown": "1.2.7","sinon": "^22.1.0",+ "source-map-js": "^1.2.1","testem": "^3.20.2","tracked-built-ins": "^4.1.2","typescript": "^6.0.3",diff --git a/frontend/discourse/testem.js b/frontend/discourse/testem.jsindex a2c64fbfd82..3d8b33a5daa 100644--- a/frontend/discourse/testem.js+++ b/frontend/discourse/testem.js@@ -1,7 +1,12 @@const TapReporter = require("testem/lib/reporters/tap_reporter");const fs = require("fs");+const path = require("path");const displayUtils = require("testem/lib/utils/displayutils");const colors = require("@colors/colors/safe");+const {+ buildReport,+ renderReportSummary,+} = require("./lib/deprecation-report");require("./patch-testem-output")();require("./patch-testem-browser-watchdog")();@@ -13,10 +18,34 @@ const sandboxDisabled =(process.env.DISCOURSE_DISABLE_BROWSER_SANDBOX || "").toLowerCase());+const REPO_ROOT = path.resolve(__dirname, "..", "..");++/**+ * Label identifying which CI run group produced a report, so the artifacts of a+ * single workflow run stay distinguishable.+ *+ * @returns {string}+ */+function deprecationReportGroup() {+ const explicit = process.env.DEPRECATION_REPORT_GROUP;+ if (explicit) {+ return explicit.replace(/[^\w.-]+/g, "-");+ }++ if (process.env.THEME_TEST_PAGES) {+ return "frontend-themes";+ } else if (process.env.PLUGIN_TARGETS) {+ return "frontend-plugins";+ }++ return "frontend-core";+}+class Reporter extends TapReporter {failReports = [];deprecationCounts = new Map();deprecationCountsByOrigin = new Map();+ deprecationDetails = new Map();constructor() {super(...arguments);@@ -45,6 +74,17 @@ class Reporter extends TapReporter {const originMap = this.deprecationCountsByOrigin.get(originKey);const originCount = originMap.get(id) || 0;originMap.set(id, originCount + 1);+ } else if (tag === "deprecation-details") {+ // Entries are reported when first seen and re-reported when their count+ // grows, so the highest count wins.+ for (const detail of metadata.details || []) {+ const existing = this.deprecationDetails.get(detail.key);+ if (!existing) {+ this.deprecationDetails.set(detail.key, detail);+ } else if (detail.count > existing.count) {+ existing.count = detail.count;+ }+ }} else if (tag === "summary-line") {this.out.write(`\n${metadata.message}\n`);} else {@@ -128,108 +168,74 @@ class Reporter extends TapReporter {}}- generateDeprecationTable() {- const maxIdLength = Math.max(- ...Array.from(this.deprecationCounts.keys()).map((k) => k.length)- );-- let msg = this.buildTableHeader(["id", "count"], [maxIdLength, 5]);-- for (const [id, count] of this.deprecationCounts.entries()) {- const countString = count.toString();- msg += `| ${id.padEnd(maxIdLength)} | ${countString.padStart(5)} |\n`;- }-- return msg;- }-- generateDeprecationsByOriginTable() {- const allDeprecationIds = this.collectAllDeprecationIds();- const maxIdLength = Math.max(- ...Array.from(allDeprecationIds).map((id) => id.length)- );- const origins = Array.from(this.deprecationCountsByOrigin.keys()).sort();- const maxOriginLength = Math.max(...origins.map((o) => o.length), 6);-- let msg = this.buildTableHeader(- ["origin", "id", "count"],- [maxOriginLength, maxIdLength, 5]- );-- for (const origin of origins) {- const originMap = this.deprecationCountsByOrigin.get(origin);- const sortedIds = Array.from(originMap.keys()).sort();-- for (const id of sortedIds) {- const count = originMap.get(id);- const countString = count.toString();- msg += `| ${origin.padEnd(maxOriginLength)} | ${id.padEnd(maxIdLength)} | ${countString.padStart(5)} |\n`;- }- }-- return msg;- }-- collectAllDeprecationIds() {- const allIds = new Set();- for (const originMap of this.deprecationCountsByOrigin.values()) {- for (const id of originMap.keys()) {- allIds.add(id);- }- }- return allIds;- }-- buildTableHeader(columnNames, columnWidths) {- let header = "| ";- let separator = "| ";-- for (let i = 0; i < columnNames.length; i++) {- const name = columnNames[i];- const width = columnWidths[i];- header += `${name.padEnd(width)} | `;- separator += `${"".padEnd(width, "-")} | `;- }-- return header + "\n" + separator + "\n";- }-reportDeprecations() {- if (this.deprecationCounts.size === 0) {+ if (+ this.deprecationCounts.size === 0 &&+ this.deprecationDetails.size === 0+ ) {this.out.write("\n[Deprecation Counter] No deprecations logged\n\n");return;}- const table = this.generateDeprecationTable();- let deprecationMessage =- "[Deprecation Counter] Test run completed with deprecations:\n\n" + table;-- let originTable = null;- if (this.deprecationCountsByOrigin.size > 0) {- originTable = this.generateDeprecationsByOriginTable();- deprecationMessage += "\nDeprecations by test origin:\n\n" + originTable;+ const report = this.writeDeprecationReport();+ if (!report) {+ return;}- this.writeGitHubSummary(table, originTable);- this.out.write(`\n${deprecationMessage}\n\n`);- }+ this.out.write(+ `\n${renderReportSummary(report.document, {+ reportLocation: `\`${report.path}\``,+ })}\n`+ );- writeGitHubSummary(table, originTable) {- if (!process.env.GITHUB_ACTIONS || !process.env.GITHUB_STEP_SUMMARY) {- return;+ if (process.env.GITHUB_ACTIONS && process.env.GITHUB_STEP_SUMMARY) {+ fs.appendFileSync(+ process.env.GITHUB_STEP_SUMMARY,+ `${renderReportSummary(report.document, {+ reportLocation: "the `js-deprecation-report` artifact",+ })}\n`+ );}+ }- let jobSummary =- "### ⚠️ JS Deprecations\n\nTest run completed with deprecations:\n\n";- jobSummary += table;-- if (originTable) {- jobSummary += "\n\nDeprecations by test origin:\n\n" + originTable;+ /**+ * Writes the machine-readable report which pairs every deprecation with the+ * spec that triggered it and the source location it came from.+ *+ * @returns {?{path: string, document: Object}}+ */+ writeDeprecationReport() {+ const group = deprecationReportGroup();+ const dir =+ process.env.DEPRECATION_REPORT_DIR ||+ path.join(REPO_ROOT, "tmp", "deprecation-reports");++ let document;+ try {+ document = buildReport({+ group,+ entries: Array.from(this.deprecationDetails.values()),+ totals: Object.fromEntries(this.deprecationCounts),+ totalsByOrigin: Object.fromEntries(+ Array.from(this.deprecationCountsByOrigin, ([origin, counts]) => [+ origin,+ Object.fromEntries(counts),+ ])+ ),+ });+ } catch (error) {+ this.out.write(+ `\n[Deprecation Counter] Failed to build detailed report: ${error}\n`+ );+ return null;}- jobSummary += "\n\n";+ fs.mkdirSync(dir, { recursive: true });++ const file = path.join(dir, `${group}-${process.pid}.json`);+ fs.writeFileSync(file, `${JSON.stringify(document, null, 2)}\n`);- fs.appendFileSync(process.env.GITHUB_STEP_SUMMARY, jobSummary);+ return { path: path.relative(REPO_ROOT, file), document };}finish() {diff --git a/frontend/discourse/tests/helpers/deprecation-counter.js b/frontend/discourse/tests/helpers/deprecation-counter.jsindex f1dfc8bc4f0..69c7f8181c0 100644--- a/frontend/discourse/tests/helpers/deprecation-counter.js+++ b/frontend/discourse/tests/helpers/deprecation-counter.js@@ -13,6 +13,15 @@ import { isRailsTesting, isTesting } from "discourse/lib/environment";*/const skipCountIds = new Set();+// Detailed per-occurrence records are deduplicated and capped so a noisy+// deprecation in a hot code path can't blow up memory or the reporter payload.+const MAX_DETAIL_ENTRIES = 2000;+// Repeated stacks consume capture time without filling the detail-entry cap.+const MAX_STACK_CAPTURES = 10000;+// Deep enough to get past the runloop and computed-property machinery which sits+// between a deprecated getter and the code that actually called it.+const MAX_STACK_FRAMES = 60;+/*** Marks a deprecation ID to be skipped when counting deprecations during tests.* This is useful when you want to temporarily ignore specific deprecations@@ -55,19 +64,33 @@ export function restoreCountingDeprecation(id) {export default class DeprecationCounter {counts = new Map();+ details = new Map();#origin = null;+ #qunit = null;+ #countsChanged = new Set();+ #instanceId = crypto.randomUUID();+ #stackCaptures = 0;get hasDeprecations() {return this.counts.size > 0;}- start(origin) {+ start(origin, qunit) {+ this.startDiscourseHandler(origin, qunit);+ this.startEmberHandler();+ }++ startDiscourseHandler(origin, qunit) {this.#origin = origin;+ this.#qunit = qunit;- registerDeprecationHandler(this.handleEmberDeprecation);registerDiscourseDeprecationHandler(this.handleDiscourseDeprecation);}+ startEmberHandler() {+ registerDeprecationHandler(this.handleEmberDeprecation);+ }+shouldCount(id) {return (!skipCountIds.has(id) &&@@ -92,14 +115,16 @@ export default class DeprecationCounter {const id = options?.id || "discourse.(unknown)";if (this.shouldCount(id)) {- this.incrementCount(id);+ this.incrementCount(id, options?.reportAtCallSite === true);}}- incrementCount(id) {+ incrementCount(id, reportAtCallSite = false) {const existingCount = this.counts.get(id) || 0;this.counts.set(id, existingCount + 1);+ this.recordDetail(id, reportAtCallSite);+if (window.Testem) {reportDeprecationToTestem(id, this.#origin);}@@ -109,6 +134,83 @@ export default class DeprecationCounter {}}+ /**+ * Captures the call stack and the surrounding test context for a deprecation,+ * so the CI report can point at both the spec and the deprecated call site.+ * Identical occurrences are collapsed into a single entry with a count.+ */+ recordDetail(id, reportAtCallSite = false) {+ if (this.#stackCaptures >= MAX_STACK_CAPTURES) {+ return;+ }++ this.#stackCaptures++;+ const stack = captureStack();+ const currentTest = this.#qunit?.config?.current;+ const key = [+ this.#instanceId,+ reportAtCallSite,+ id,+ this.#origin,+ currentTest?.module?.name,+ currentTest?.testName,+ stack,+ ].join("\u0000");++ const existing = this.details.get(key);+ if (existing) {+ existing.count++;+ this.#countsChanged.add(key);+ } else {+ if (this.details.size >= MAX_DETAIL_ENTRIES) {+ return;+ }++ const detail = {+ key,+ id,+ reportAtCallSite,+ origin: this.#origin,+ module: currentTest?.module?.name,+ testName: currentTest?.testName,+ testStack: currentTest?.stack,+ stack,+ count: 1,+ };++ this.details.set(key, detail);++ // Reported straight away rather than batched: a deprecation raised outside a+ // test is followed by no `testDone`, and an end-of-run flush races the+ // browser teardown.+ if (window.Testem) {+ reportDeprecationDetailsToTestem([detail]);+ }+ }++ if (isRailsTesting()) {+ // System specs identify the spec themselves.+ // eslint-disable-next-line no-console+ console.log(+ `deprecation_detail:${JSON.stringify({ id, stack, reportAtCallSite })}`+ );+ }+ }++ /**+ * Hands over entries whose count has grown since they were first reported, so+ * the reporter can correct the totals it already holds.+ *+ * @returns {Object[]}+ */+ takeUpdatedCounts() {+ const updated = Array.from(this.#countsChanged, (key) =>+ this.details.get(key)+ );+ this.#countsChanged.clear();+ return updated.filter(Boolean).map(({ key, count }) => ({ key, count }));+ }+generateTable() {const idColumn = "id";const countColumn = "count";@@ -136,6 +238,17 @@ export default class DeprecationCounter {}}+function captureStack() {+ const previousLimit = Error.stackTraceLimit;++ // Browsers default to a handful of frames, which never reaches the caller.+ Error.stackTraceLimit = MAX_STACK_FRAMES;+ const { stack } = new Error();+ Error.stackTraceLimit = previousLimit;++ return stack || "";+}+function reportDeprecationToTestem(id, origin) {window.Testem.useCustomAdapter(function (socket) {socket.emit("test-metadata", "increment-deprecation", {@@ -145,20 +258,43 @@ function reportDeprecationToTestem(id, origin) {});}+function reportDeprecationDetailsToTestem(details) {+ window.Testem.useCustomAdapter(function (socket) {+ socket.emit("test-metadata", "deprecation-details", { details });+ });+}+export function setupDeprecationCounter({ QUnit, origin } = {}) {const deprecationCounter = new DeprecationCounter();// for system specsif (isRailsTesting()) {- deprecationCounter.start(origin);+ deprecationCounter.start(origin, QUnit);return;}if (QUnit) {- // for QUnit tests- QUnit.begin(() => deprecationCounter.start(origin));+ // The counter has to see a deprecation before the handler which raises on+ // it, or anything that raises goes unrecorded and the suites which must stay+ // deprecation-free report nothing at all. Discourse handlers run in+ // registration order and Ember's run in reverse, so the counter registers+ // ahead of `configureRaiseOnDeprecation` for one and behind it for the+ // other.+ deprecationCounter.startDiscourseHandler(origin, QUnit);+ QUnit.begin(() => deprecationCounter.startEmberHandler());++ const flushCounts = () => {+ const updated = deprecationCounter.takeUpdatedCounts();+ if (window.Testem && updated.length > 0) {+ reportDeprecationDetailsToTestem(updated);+ }+ };++ QUnit.testDone(flushCounts);QUnit.done(() => {+ flushCounts();+if (window.Testem) {return;} else if (deprecationCounter.hasDeprecations) {diff --git a/frontend/discourse/tests/unit/lib/deprecated-test.js b/frontend/discourse/tests/unit/lib/deprecated-test.jsindex ad9d2838b6c..e46d7c30670 100644--- a/frontend/discourse/tests/unit/lib/deprecated-test.js+++ b/frontend/discourse/tests/unit/lib/deprecated-test.js@@ -51,7 +51,7 @@ module("Unit | Utility | deprecated", function (hooks) {);assert.deepEqual(this.counterStub.args[0],- ["discourse.(unknown)"],+ ["discourse.(unknown)", false],"incrementCount is called with the correct arguments");});@@ -77,7 +77,7 @@ module("Unit | Utility | deprecated", function (hooks) {);assert.deepEqual(this.counterStub.args[0],- ["discourse.my_deprecation_id"],+ ["discourse.my_deprecation_id", false],"incrementCount is called with the correct arguments");});@@ -107,7 +107,7 @@ module("Unit | Utility | deprecated", function (hooks) {);assert.deepEqual(this.counterStub.args[0],- ["discourse.my_deprecation_id"],+ ["discourse.my_deprecation_id", false],"incrementCount is called with the correct arguments");});@@ -128,7 +128,7 @@ module("Unit | Utility | deprecated", function (hooks) {);assert.deepEqual(this.counterStub.args[0],- ["discourse.my_deprecation_id"],+ ["discourse.my_deprecation_id", false],"incrementCount is called with the correct arguments");});diff --git a/frontend/discourse/tests/unit/lib/deprecation-counter-test.js b/frontend/discourse/tests/unit/lib/deprecation-counter-test.jsnew file mode 100644index 00000000000..dbc736b78ca--- /dev/null+++ b/frontend/discourse/tests/unit/lib/deprecation-counter-test.js@@ -0,0 +1,175 @@+import { setupTest } from "ember-qunit";+import { module, test } from "qunit";+import sinon from "sinon";+import { setEnvironment } from "discourse/lib/environment";+import DeprecationCounter from "discourse/tests/helpers/deprecation-counter";++module("Unit | Lib | deprecation-counter", function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.sandbox = sinon.createSandbox();+ this.sandbox.stub(window, "Testem").value(undefined);+ this.log = this.sandbox.stub(console, "log");+ this.count = this.sandbox.stub(console, "count");+ setEnvironment("test");+ });++ hooks.afterEach(function () {+ setEnvironment("qunit-testing");+ this.sandbox.restore();+ });++ test("preserves call-site attribution in browser and system spec details", function (assert) {+ const reported = [];+ window.Testem = {+ useCustomAdapter(callback) {+ callback({+ emit(event, tag, payload) {+ if (tag === "deprecation-details") {+ reported.push(...payload.details);+ }+ },+ });+ },+ };+ const counter = new DeprecationCounter();++ for (const reportAtCallSite of [true, false]) {+ counter.handleDiscourseDeprecation("Example", {+ id: "example.deprecation",+ reportAtCallSite,+ });+ }++ assert.deepEqual(+ reported.map((detail) => detail.reportAtCallSite),+ [true, false],+ "browser details keep distinct attribution modes for the same stack"+ );+ assert.deepEqual(+ this.log.args.map(+ ([message]) =>+ JSON.parse(message.slice("deprecation_detail:".length))+ .reportAtCallSite+ ),+ [true, false],+ "system spec logs preserve the attribution mode"+ );+ });++ test("keeps counting after exhausting the stack capture budget", function (assert) {+ const counter = new DeprecationCounter();+ const capture = this.sandbox+ .stub(window, "Error")+ .callsFake(() => ({ stack: "repeated stack" }));+ capture.resetHistory();++ try {+ for (let i = 0; i < 10005; i++) {+ counter.incrementCount("repeated.deprecation");+ }+ counter.incrementCount("later.deprecation");+ } finally {+ capture.restore();+ }++ assert.strictEqual(capture.callCount, 10000, "stack captures are bounded");+ assert.strictEqual(+ this.log.callCount,+ 10000,+ "details are only emitted within the capture budget"+ );+ assert.strictEqual(+ this.count.callCount,+ 10006,+ "every occurrence is still reported to system specs"+ );+ assert.strictEqual(+ counter.counts.get("repeated.deprecation"),+ 10005,+ "repeated warnings continue to be counted"+ );+ assert.strictEqual(+ counter.counts.get("later.deprecation"),+ 1,+ "new warnings continue to be counted"+ );+ });++ test("keeps details from separate counters distinct outside a test", function (assert) {+ setEnvironment("qunit-testing");+ const reported = [];+ window.Testem = {+ useCustomAdapter(callback) {+ callback({+ emit(event, tag, { details }) {+ reported.push(...details.map((detail) => ({ ...detail })));+ },+ });+ },+ };+ const counters = [new DeprecationCounter(), new DeprecationCounter()];++ for (const counter of counters) {+ for (let i = 0; i < 3; i++) {+ counter.recordDetail("parallel.deprecation");+ }+ }++ assert.strictEqual(+ reported.length,+ 2,+ "each counter reports one new entry"+ );+ assert.strictEqual(+ reported[0].stack,+ reported[1].stack,+ "both counters capture the same stack"+ );+ assert.notStrictEqual(+ reported[0].key,+ reported[1].key,+ "separate counters report distinct keys"+ );+ assert.deepEqual(+ counters.flatMap((counter) => counter.takeUpdatedCounts()),+ reported.map(({ key }) => ({ key, count: 3 })),+ "updates contain only each counter's original key and cumulative count"+ );+ assert.deepEqual(+ counters.flatMap((counter) => counter.takeUpdatedCounts()),+ [],+ "unchanged counts are not sent again"+ );+ });++ test("reports system spec details for every occurrence of the same stack", function (assert) {+ const counter = new DeprecationCounter();++ for (let i = 0; i < 50; i++) {+ counter.incrementCount("repeated.deprecation");+ }++ const details = this.log.args.map(([message]) =>+ JSON.parse(message.slice("deprecation_detail:".length))+ );++ assert.strictEqual(this.count.callCount, 50, "every occurrence is counted");+ assert.strictEqual(+ details.length,+ 50,+ "every occurrence has source details"+ );+ assert.true(+ details.every(({ id }) => id === "repeated.deprecation"),+ "details identify the repeated deprecation"+ );+ assert.true(details[0].stack.length > 0, "the source stack is captured");+ assert.strictEqual(+ new Set(details.map(({ stack }) => stack)).size,+ 1,+ "all occurrences come from the same stack"+ );+ });+});diff --git a/lib/asset_processor.rb b/lib/asset_processor.rbindex 640de813a2f..95b1245391e 100644--- a/lib/asset_processor.rb+++ b/lib/asset_processor.rb@@ -41,6 +41,7 @@ class AssetProcessor"The file '#{file_path}' uses the deprecated `.js.es6` extension. Use `.js` instead.",{id: "discourse.es6-extension",+ reportAtCallSite: true,url: "https://meta.discourse.org/t/398894",});diff --git a/lib/turbo_tests/base_formatter.rb b/lib/turbo_tests/base_formatter.rbindex a1d728f61a4..4baf4634818 100644--- a/lib/turbo_tests/base_formatter.rb+++ b/lib/turbo_tests/base_formatter.rb@@ -1,4 +1,6 @@# frozen_string_literal: true+require "open3"+RSpec::Support.require_rspec_core "formatters/base_text_formatter"RSpec::Support.require_rspec_core "formatters/console_codes"@@ -10,7 +12,12 @@ module TurboTestsoutput_slowest_examples(timings) if timings.present?totals_by_id, totals_by_origin = aggregate_js_deprecations(notification.examples)- output_js_deprecations(totals_by_id, totals_by_origin) if totals_by_id.present?++ if totals_by_id.present?+ summary = write_js_deprecation_report(notification.examples, totals_by_id, totals_by_origin)+ summary ||= fallback_js_deprecation_summary(totals_by_id, totals_by_origin)+ output.puts "\n#{summary}\n"+ endsuper(notification)end@@ -41,69 +48,81 @@ module TurboTests[totals_by_id, totals_by_origin]end- def output_js_deprecations(totals_by_id, totals_by_origin)- output.puts "\n[Deprecation Counter] Test run completed with deprecations:\n\n"-- deprecations_table = generate_deprecations_table(totals_by_id)- output.puts deprecations_table-- origin_table = nil- if totals_by_origin.any?- origin_table = generate_deprecations_by_origin_table(totals_by_origin)- output.puts "\nDeprecations by spec origin:\n\n"- output.puts origin_table- end-- write_github_summary(deprecations_table, origin_table)+ # Label identifying which CI run group produced a report, so the artifacts of+ # a single workflow run stay distinguishable.+ def js_deprecation_report_group+ ENV["DEPRECATION_REPORT_GROUP"].presence&.gsub(/[^\w.-]+/, "-") || "system"end- def generate_deprecations_table(totals_by_id)- max_id_length = totals_by_id.keys.map(&:length).max+ # Pairs each collected JS deprecation with the spec that triggered it and,+ # via the frontend sourcemaps, the original call site it came from.+ def write_js_deprecation_report(examples, totals_by_id, totals_by_origin)+ entries =+ examples.flat_map do |example|+ details = example.metadata[:js_deprecation_details]+ next [] if details.blank?++ location = example.location_rerun_argument.presence || example.location+ test_file, _, test_line = location.rpartition(":")++ details.map do |detail|+ {+ id: detail["id"],+ count: 1,+ origin: extract_origin_from_example(example) || "unknown",+ stack: detail["stack"],+ reportAtCallSite: detail["reportAtCallSite"],+ test: {+ module: nil,+ name: example.full_description,+ file: test_file,+ declarationLine: test_line.to_i,+ callSiteLine: nil,+ callSiteCode: nil,+ },+ }+ end+ end- headers = ["id".ljust(max_id_length), "count".rjust(5)]- rows = totals_by_id.map { |id, count| [id.ljust(max_id_length), count.to_s.rjust(5)] }+ group = js_deprecation_report_group+ dir =+ ENV["DEPRECATION_REPORT_DIR"].presence || Rails.root.join("tmp/deprecation-reports").to_s+ FileUtils.mkdir_p(dir)+ report_path = File.join(dir, "#{group}-#{Process.pid}.json")++ payload = { entries:, totals: totals_by_id, totalsByOrigin: totals_by_origin }+ cli = Rails.root.join("frontend/discourse/lib/deprecation-report-cli.js").to_s+ summary, stderr, status =+ Open3.capture3("node", cli, "build", report_path, group, stdin_data: payload.to_json)++ unless status.success?+ reason = status.signaled? ? "signal #{status.termsig}" : "exit status #{status.exitstatus}"+ output.puts "\n[Deprecation Counter] Failed to build detailed report (#{reason})."+ output.puts stderr if stderr.present?+ return nil+ end- build_markdown_table(headers, rows)+ output.puts stderr if stderr.present?+ summary+ rescue StandardError => e+ output.puts "\n[Deprecation Counter] Failed to build detailed report: #{e.message}\n"+ nilend- def generate_deprecations_by_origin_table(totals_by_origin)- all_ids = totals_by_origin.values.flat_map(&:keys).uniq- max_id_length = all_ids.map(&:length).max- origins = totals_by_origin.keys.sort- max_origin_length = [origins.map(&:length).max, 6].max+ def fallback_js_deprecation_summary(totals_by_id, totals_by_origin)+ summary = +"[Deprecation Counter] Test run completed with deprecations:\n\n"+ summary << "| id | count |\n| --- | --- |\n"+ totals_by_id.sort.each { |id, count| summary << "| #{id} | #{count} |\n" }- headers = ["origin".ljust(max_origin_length), "id".ljust(max_id_length), "count".rjust(5)]- rows = []-- origins.each do |origin|- origin_deprecations = totals_by_origin[origin]- sorted_ids = origin_deprecations.keys.sort-- sorted_ids.each do |id|- count = origin_deprecations[id]- rows += [[origin.ljust(max_origin_length), id.ljust(max_id_length), count.to_s.rjust(5)]]+ if totals_by_origin.any?+ summary << "\nDeprecations by spec origin:\n\n"+ summary << "| origin | id | count |\n| --- | --- | --- |\n"+ totals_by_origin.sort.each do |origin, counts|+ counts.sort.each { |id, count| summary << "| #{origin} | #{id} | #{count} |\n" }endend- build_markdown_table(headers, rows)- end-- def build_markdown_table(headers, rows)- table = "| #{headers.join(" | ")} |\n"- table += "| #{headers.map { |h| "-" * h.length }.join(" | ")} |\n"- rows.each { |row| table += "| #{row.join(" | ")} |\n" }- table- end-- def write_github_summary(deprecations_table, origin_table)- return unless ENV["GITHUB_ACTIONS"] && ENV["GITHUB_STEP_SUMMARY"]-- summary = "### ⚠️ JS Deprecations\n\nTest run completed with deprecations:\n\n"- summary += deprecations_table- summary += "\n\nDeprecations by spec origin:\n\n#{origin_table}" if origin_table- summary += "\n\n"-- File.write(ENV["GITHUB_STEP_SUMMARY"], summary)+ summaryenddef extract_origin_from_example(example)diff --git a/lib/turbo_tests/json_example.rb b/lib/turbo_tests/json_example.rbindex a43e04f59f0..ffcb9a650d4 100644--- a/lib/turbo_tests/json_example.rb+++ b/lib/turbo_tests/json_example.rb@@ -19,6 +19,7 @@ module TurboTestsextra_failure_lines: @rspec_example.metadata[:extra_failure_lines],run_duration_ms: @rspec_example.metadata[:run_duration_ms],js_deprecations: @rspec_example.metadata[:js_deprecations],+ js_deprecation_details: @rspec_example.metadata[:js_deprecation_details],rerun_file_path: @rspec_example.metadata[:rerun_file_path],active_record_debug_logs: @rspec_example.metadata[:active_record_debug_logs],perf: @rspec_example.metadata[:perf],diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex da4bbc8c9a2..807f2f022b8 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -641,6 +641,9 @@ importers:sinon:specifier: ^22.1.0version: 22.1.0+ source-map-js:+ specifier: ^1.2.1+ version: 1.2.1testem:specifier: ^3.20.2diff --git a/spec/lib/asset_processor_spec.rb b/spec/lib/asset_processor_spec.rbindex 74614d9aea9..1d6c42987ff 100644--- a/spec/lib/asset_processor_spec.rb+++ b/spec/lib/asset_processor_spec.rb@@ -1,6 +1,14 @@# frozen_string_literal: trueRSpec.describe AssetProcessor do+ describe ".append_es6_deprecation" do+ it "attributes the warning to the file using the deprecated extension" do+ result = described_class.append_es6_deprecation("export default {};", "legacy.js.es6")++ expect(result).to include('id: "discourse.es6-extension"', "reportAtCallSite: true")+ end+ end+def entrypoint(result, name)result.values.find { |chunk| chunk["name"] == name }enddiff --git a/spec/lib/ember_deprecations_spec.rb b/spec/lib/ember_deprecations_spec.rbnew file mode 100644index 00000000000..10f0a4d2ca2--- /dev/null+++ b/spec/lib/ember_deprecations_spec.rb@@ -0,0 +1,25 @@+# frozen_string_literal: true++require_relative "../support/system/ember_deprecations"++RSpec.describe EmberDeprecations do+ describe ".record_details" do+ it "records valid unexpected deprecation details" do+ metadata = { expected_js_deprecations: ["expected.deprecation"] }+ logs = [+ {+ message:+ 'deprecation_detail:{"id":"reported.deprecation","stack":"stack","reportAtCallSite":true}',+ },+ { message: 'deprecation_detail:{"id":"expected.deprecation","stack":"stack"}' },+ { message: "deprecation_detail:not-json" },+ ]++ described_class.record_details(logs, metadata)++ expect(metadata[:js_deprecation_details]).to eq(+ [{ "id" => "reported.deprecation", "stack" => "stack", "reportAtCallSite" => true }],+ )+ end+ end+enddiff --git a/spec/lib/turbo_tests/base_formatter_spec.rb b/spec/lib/turbo_tests/base_formatter_spec.rbnew file mode 100644index 00000000000..788702c745d--- /dev/null+++ b/spec/lib/turbo_tests/base_formatter_spec.rb@@ -0,0 +1,114 @@+# frozen_string_literal: true++RSpec.describe TurboTests::BaseFormatter do+ describe "#dump_summary" do+ let(:output) { StringIO.new }+ let(:formatter) { described_class.new(output) }+ let(:examples) do+ [+ instance_double(+ RSpec::Core::Example,+ metadata: {+ rerun_file_path: Rails.root.join("spec/system/example_spec.rb").to_s,+ js_deprecations: {+ "example.deprecation" => 2,+ },+ },+ ),+ instance_double(+ RSpec::Core::Example,+ metadata: {+ rerun_file_path: Rails.root.join("plugins/example/spec/system/example_spec.rb").to_s,+ js_deprecations: {+ "example.deprecation" => 1,+ },+ },+ ),+ ]+ end+ let(:notification) do+ instance_double(+ RSpec::Core::Notifications::SummaryNotification,+ examples:,+ fully_formatted: "RSpec summary",+ )+ end++ it "prints the detailed summary when report generation succeeds" do+ status = instance_double(Process::Status, success?: true)+ allow(Open3).to receive(:capture3).and_return(["Detailed summary", "", status])++ formatter.dump_summary(notification, nil)++ expect(output.string).to eq("\nDetailed summary\nRSpec summary\n")+ end++ it "keeps the test filename and line together for shared examples and fallback locations" do+ status = instance_double(Process::Status, success?: true)+ payload = nil+ allow(Open3).to receive(:capture3) do |*args, stdin_data:|+ payload = JSON.parse(stdin_data)+ ["Detailed summary", "", status]+ end++ [+ ["./spec/system/topics_spec.rb:75", "./spec/system/topics_spec.rb", 75],+ [nil, "./spec/support/shared_examples.rb", 40],+ ].each do |rerun_location, expected_file, expected_line|+ example =+ instance_double(+ RSpec::Core::Example,+ full_description: "Topics shared example",+ location: "./spec/support/shared_examples.rb:40",+ location_rerun_argument: rerun_location,+ metadata: {+ rerun_file_path: Rails.root.join("spec/system/topics_spec.rb").to_s,+ js_deprecations: {+ "example.deprecation" => 1,+ },+ js_deprecation_details: [{ "id" => "example.deprecation", "stack" => "stack" }],+ },+ )+ allow(notification).to receive(:examples).and_return([example])++ formatter.dump_summary(notification, nil)++ expect(payload.fetch("entries").sole.fetch("test")).to include(+ "file" => expected_file,+ "declarationLine" => expected_line,+ )+ end+ end++ it "prints the exit status, error and totals when report generation fails" do+ status = instance_double(Process::Status, success?: false, signaled?: false, exitstatus: 1)+ allow(Open3).to receive(:capture3).and_return(["", "Report command failed", status])++ formatter.dump_summary(notification, nil)++ expect(output.string).to include(+ "Failed to build detailed report (exit status 1).",+ "Report command failed",+ "| example.deprecation | 3 |",+ "| core | example.deprecation | 2 |",+ "| example | example.deprecation | 1 |",+ "RSpec summary",+ )+ end++ it "prints the launch error and totals when the report command cannot start" do+ allow(Open3).to receive(:capture3).and_raise(Errno::ENOENT, "node")++ formatter.dump_summary(notification, nil)++ expect(output.string).to include(+ "Failed to build detailed report:",+ "node",+ "| example.deprecation | 3 |",+ "| core | example.deprecation | 2 |",+ "| example | example.deprecation | 1 |",+ "RSpec summary",+ )+ end+ end+enddiff --git a/spec/rails_helper.rb b/spec/rails_helper.rbindex 13aba0c0b34..7462495ae5a 100644--- a/spec/rails_helper.rb+++ b/spec/rails_helper.rb@@ -298,6 +298,7 @@ RSpec.configure do |config|expect(deprecation_error).to be_nil, deprecation_errorEmberDeprecations.record_counts($playwright_logger&.logs, example.metadata)+ EmberDeprecations.record_details($playwright_logger&.logs, example.metadata)page.execute_script("if (typeof MessageBus !== 'undefined') { MessageBus.stop(); }")diff --git a/spec/support/system/ember_deprecations.rb b/spec/support/system/ember_deprecations.rbindex 72ae24afc17..70ed2fddc26 100644--- a/spec/support/system/ember_deprecations.rb+++ b/spec/support/system/ember_deprecations.rb@@ -61,4 +61,27 @@ module EmberDeprecationsdeprecations[deprecation_id] += 1endend++ # Collect the JS call stack captured for each distinct deprecation, so the CI+ # report can point at the code which needs fixing rather than just a count.+ def self.record_details(logs, metadata)+ expected = metadata[:expected_js_deprecations] || []++ logs&.each do |log|+ payload = log[:message][/^deprecation_detail:(\{.*\})$/m, 1]+ next if payload.nil?++ detail =+ begin+ JSON.parse(payload)+ rescue JSON::ParserError+ next+ end++ next if expected.include?(detail["id"])++ details = metadata[:js_deprecation_details] ||= []+ details << detail+ end+ endenddiff --git a/spec/support/system/playwright_logger.rb b/spec/support/system/playwright_logger.rbindex 196b37f6ea1..b85dfb078d5 100644--- a/spec/support/system/playwright_logger.rb+++ b/spec/support/system/playwright_logger.rb@@ -45,7 +45,9 @@ class PlaywrightLoggerif (log[:message].include?("Failed to load resource: net::ERR_CONNECTION_REFUSED") &&(log[:message].include?("uploads") || log[:message].include?("images"))- ) || log[:message].include?("favicon.ico")+ ) || log[:message].include?("favicon.ico") ||+ # Machine-readable stacks for the deprecation report, not for humans.+ log[:message].start_with?("deprecation_detail:")nextend