Skip to content

Translator tester: running URL-specified translator(s) does not do what it is supposed to do (not awaiting translators to fully load) #20

@zoe-translates

Description

@zoe-translates

Context

The translator tester (accessible in the debug build of the connector extension) is supposed to run the tests for the translators specified on the URL.

This is used by the Selenium-driven test for pull requests in zotero/translators, but this test (most of the time) does not actually run:

https://github.com/zotero/translators/blob/3a9544d7b0b6fdcb6cdcbc8c08392f91d20d99b4/.ci/pull-request-check/selenium-test.js#L128-L130

The problem

I think the problem is that, when runURLSpecifiedTranslators() is called at the end of init(), most likely the translators have not been loaded into the global object translatorTestViewsToRun which is used by the function to identify the translator(s) to run:

async function runURLSpecifiedTranslators() {
const href = document.location.href;
let hashParams = href.split('#')[1];
if (!hashParams) return;
let translatorIDs = new Set(hashParams.split('translators=')[1].split(',').map(decodeURI));
let translatorTestViews = [];
for (let type in translatorTestViewsToRun) {
for (const translatorTestView of translatorTestViewsToRun[type]) {
if (translatorIDs.has(translatorTestView._translatorTester.translator.translatorID)) {
translatorTestViews.push(translatorTestView);

But the sequence of calls is like the following:

init() calls haveTranslators() which returns a promise that is not awaited/then-handled. (The following snippet is the call site, and itself is inside one big initialization loop waited for by await Promise.all(...) on Line 428.

// get translators, with code for unsupported translators
if(!viewerMode) {
let translators = await Zotero.Translators.getAllForType(translatorType, true);
haveTranslators(translators, translatorType);
}

Then the init() function runs its course, and makes the call to runURLSpecifiedTranslators() at the very end:

// Run translators specified in the hash params if any
runURLSpecifiedTranslators();
}
}

And by this time when runURLSpecifiedTranslators() accesses translatorTestViewsToRun, the haveTranslators() function likely has not been called (enough times) yet, so translatorTestViewsToRun is empty or incomplete.

Impact

Because of this, the following lines in runURLSpecifiedTranslators() are executed without the tests being actually run.

var elem = document.createElement('p');
elem.setAttribute('id', 'translator-tests-complete');
document.body.appendChild(elem);

That is to say, the page falsely reports that the tests passed by the URL are complete. This can even happen if the URL-passed translator ID is invalid.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions