Page MenuHomePhabricator

[SPIKE] Investigate running mw.editcheck code under node.js
Closed, ResolvedPublic

Description

As contingency planning for the scenario where deployment of EditCheckHeadless (T428811) is deemed infeasible, investigate the feasibility of running mw.editcheck code under node.js.

Much of the discussion in T431615 and T431602 is relevant to this. Particular challenges likely include:

  • Including code from across extensions like Cite, in order that node types like references are legible
  • Bundling functionality akin to ResourceLoader but for server-side deployment
  • Necessary changes so the VisualEditor model can work under node.js in a server environment

See the lengthy discussion in those tickets for further details

Event Timeline

Complexities involved:

  1. Work out what extensions are loaded for a given wiki, and which include VE PluginModules.
  2. Translate all the RL modules from those PluginModules into actual files to load, in a workable-in-node way.
  3. Have versions of any mw. functions we use in the model-only path.
  4. Work out how to get any mw.config we need. Much of this is generated from extension hooks and passed through ResourceLoader to reach the client...
  5. Get the EditCheck config, which is a PHP-generated document coming through a ResourceLoader packageFiles callback.

Here is our proof of concept: https://gitlab.wikimedia.org/divec/editcheck-node . It takes standard client-side VisualEditor and Edit Check code served from enwiki and runs it in nodejs. It uses domino as the DOM implementation.

  • Dependencies are handled using ResourceLoader (i.e. mw.loader.using)
  • View code is run too (ve.ce and ve.ui), not just the data model. Ultimately it would be better to separate that out, but for the time being there's no need.
  • EditCheck config is loaded (editcheck/modules/config.json). It is served as part of the ext.visualEditor.editCheck module.

For now a check is just run directly (bypassing the controller). Porting the logic from EditCheckHeadless would be the obvious next step.

Code fetched from enwiki is cached locally. In principle this code could be checked into a repository, audited, and undergo independent release management, so an EditCheck-node instance would not be dependent on the related wiki.

We can close the spike as complete, because we have now tested the biggest unknowns about running the Edit Check platform and its dependencies under nodejs, and it is clearly feasible.

If at some time we develop this further, towards a functional, deployable server, then the next step would be to port logic from EditCheckHeadless.

Sample output. It shows mwReference nodes and link/mwInternal annotations loading correctly, and an EditCheckAction being appropriately produced. The module list [ 'ext.visualEditor.editCheck.checks', 'ext.cite.visualEditor' ] was given. All implied dependencies were loaded automatically, as was editcheck/modules/config.json.

[
  {
    type: 'paragraph',
    originalDomElementsHash: 'h47e7d711824694a3',
    internal: { metaItems: [], changesSinceLoad: 0, whitespace: [Array] }
  },
  'T',
  'h',
  'i',
  's',
  ' ',
  'i',
  's',
  ' ',
  's',
  'o',
  'm',
  'e',
  ' ',
  't',
  'e',
  'x',
  't',
  '.',
  '\n',
  '\t',
  '\t',
  [ 'F', [ 'h0c28bfb79f2608fd' ] ],
  [ 'o', [ 'h0c28bfb79f2608fd' ] ],
  [ 'o', [ 'h0c28bfb79f2608fd' ] ],
  [ '.', [ 'h0c28bfb79f2608fd' ] ],
  ' ',
  'I',
  's',
  ' ',
  'i',
  't',
  ' ',
  'L',
  'L',
  'M',
  ' ',
  'o',
  'u',
  't',
  'p',
  'u',
  't',
  '?',
  ' ',
  'C',
  'e',
  'r',
  't',
  'a',
  'i',
  'n',
  'l',
  'y',
  '!',
  ' ',
  'T',
  'h',
  'a',
  't',
  ' ',
  'w',
  'a',
  's',
  ' ',
  'a',
  ' ',
  't',
  'e',
  'l',
  'l',
  '.',
  '\n',
  '\t',
  '\t',
  {
    type: 'mwReference',
    attributes: {
      mw: [Object],
      originalMw: '{"name":"ref","attrs":{},"body":{"id":"mw-reference-text-cite_note-1"}}',
      listGroup: 'mwReference/',
      listKey: 'auto/0',
      listIndex: 0,
      refGroup: '',
      contentsUsed: false,
      refListItemId: 'mw-reference-text-cite_note-1'
    },
    originalDomElementsHash: 'h60be7f219945704b'
  },
  { type: '/mwReference' },
  { type: '/paragraph' },
  { type: 'internalList' },
  { type: 'internalItem' },
  { type: '/internalItem' },
  { type: '/internalList' }
]
[
  MWTextMatchEditCheckAction {
    bindings: {},
    mode: '',
    check: MWTextMatchEditCheck {
      controller: [Object],
      config: [Object],
      includeSuggestions: true,
      lang: 'en',
      sensitivity: 'accent',
      collator: Collator [Intl.Collator] {},
      matchRules: [Array]
    },
    fragments: [ [VeDmSurfaceFragment] ],
    originalText: [
      'This is some text.\n' +
        '\t\tFoo. Is it LLM output? Certainly! That was a tell.\n' +
        '\t\t'
    ],
    focusFragment: undefined,
    focusAnnotation: undefined,
    message: [Function (anonymous)],
    prompt: undefined,
    footer: undefined,
    footerIcon: undefined,
    id: undefined,
    title: 'Potential AI-generated content',
    icon: undefined,
    type: 'warning',
    choices: [ [Object], [Object], [Object] ],
    suggestion: undefined,
    widget: null,
    stale: false,
    matchRuleId: 'LLM-user-comms',
    term: 'Certainly!',
    replacement: null,
    tagName: 'textMatch-LLM-user-comms',
    replacementFragment: undefined
  }
]