Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mwApiPath (to mwActionApiPath), mwRestApiPath, mwModulePath and mwWikiPath parameters + fix regression of test render template #1939

Merged
merged 14 commits into from
Nov 13, 2023

Conversation

VadimKovalenkoSNF
Copy link
Collaborator

@VadimKovalenkoSNF VadimKovalenkoSNF commented Oct 30, 2023

Fixes #1935
Depends on #1944

List of fixes:

  1. Comment out VisualEditor capabilities check and tests. It should be enabled back once https://phabricator.wikimedia.org/T350117 is unblocked.
  2. Partially comment out error checking in checkApiAvailability till the issue with VE is resolved.
  3. Fixed regressions around mwApiPath, mwRestApiPath, mwModulePath, mwWikiPath. Updated base director methods.
  4. Renamed mwApiPath to mwActionApiPath.
  5. Explicitly set { mwWikiPath: '/' } in the tests to prevent default wiki/ path to assigning. Default value of mwWikiPath is the empty string as per discussion in [REGRESSION?] API end-point detection does not take care properly of command line argument #1935 (comment) Default wikiPath is 'wiki/' as it was before.

❗ Important - this will probably affect receipts in the zimfarm because --mwWikiPath='/' is obligated param for the Mediawiki wikis now.

Check this command as an example: npm start -- --mwUrl=https://en.wikipedia.org --adminEmail=mail@mail.com --articleList=Canada --mwWikiPath=/.

See #1935 (comment) for more details.
^ Upd: this is no longer valid, mwWikiPath can be default 'wiki/'

  1. Refactored regression with test/testAllRenders.ts - fixed renderer handling across e2e tests, fixed issue with non-removed test zim files, added optional render list that is useful for wikis that do not support all renders from RENDERERS_LIST
  2. Optimized src/renderers/renderer.builder.ts to meet Codecov requirements.
  3. Fixed Mediawiki setters side effects when they received undefined parameters.

Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 25 lines in your changes are missing coverage. Please review.

Comparison is base (87333d0) 75.43% compared to head (99842b0) 73.27%.
Report is 2 commits behind head on main.

❗ Current head 99842b0 differs from pull request most recent head d3b0125. Consider uploading reports for the commit d3b0125 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1939      +/-   ##
==========================================
- Coverage   75.43%   73.27%   -2.16%     
==========================================
  Files          37       39       +2     
  Lines        2984     3106     +122     
  Branches      653      687      +34     
==========================================
+ Hits         2251     2276      +25     
- Misses        633      711      +78     
- Partials      100      119      +19     
Files Coverage Δ
src/mwoffliner.lib.ts 74.72% <100.00%> (ø)
src/parameterList.ts 100.00% <ø> (ø)
src/util/builders/url/base.director.ts 85.00% <100.00%> (+0.78%) ⬆️
src/Downloader.ts 68.56% <66.66%> (+1.19%) ⬆️
src/MediaWiki.ts 85.84% <85.36%> (+1.76%) ⬆️
src/renderers/renderer.builder.ts 34.00% <60.00%> (-18.09%) ⬇️
src/sanitize-argument.ts 8.08% <33.33%> (ø)

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@VadimKovalenkoSNF VadimKovalenkoSNF marked this pull request as ready for review November 3, 2023 09:36
@VadimKovalenkoSNF VadimKovalenkoSNF changed the title Refactor mwApiPath and mwWikiPath parameters Refactor mwApiPath, mwRestApiPath, mwModulePath and mwWikiPath parameters + fix regression of test render template Nov 3, 2023
@kelson42
Copy link
Collaborator

kelson42 commented Nov 3, 2023

  • Comment out VisualEditor capabilities check and tests. It should be enabled back once https://phabricator.wikimedia.org/T350117 is unblocked.

  • Partially comment out error checking in checkApiAvailability till the issue with VE is resolved.

This PR has nothing to do with VE, as such nothing regarding VE should normaly be inside... and for sure not https://phabricator.wikimedia.org/T350117 which has really nothing to do with this ticket.

Copy link
Collaborator

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes to do only.

src/util/builders/url/base.director.ts Outdated Show resolved Hide resolved
@@ -175,13 +176,13 @@ class Downloader {
this.baseUrl = basicURLDirector.buildDownloaderBaseUrl([
{ condition: await MediaWiki.hasWikimediaMobileApi(), value: MediaWiki.WikimediaMobileApiUrl.href },
{ condition: await MediaWiki.hasWikimediaDesktopApi(), value: MediaWiki.WikimediaDesktopApiUrl.href },
{ condition: await MediaWiki.hasVisualEditorApi(), value: MediaWiki.visualEditorApiUrl.href },
// { condition: await MediaWiki.hasVisualEditorApi(), value: MediaWiki.visualEditorApiUrl.href },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 - create a PR to deactivate visualeditor
2 - create a ticket requesting reintroducing it once the phabricator ist fix and rolled out
3 - put links between all of this so things are understandable

Only the VisualEditor autodetection should be deactivated

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, this PR has been merged - #1941
Ticket about reintroducing VE - #1940

rimraf.sync(`./${outFiles[0].testId}`)
})
break
case 'VisaulEditor':
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/mwoffliner.lib.ts Outdated Show resolved Hide resolved
@VadimKovalenkoSNF VadimKovalenkoSNF force-pushed the I1935-rollback-mw-api-configs branch from 69654c6 to aa979c1 Compare November 6, 2023 12:54
@VadimKovalenkoSNF VadimKovalenkoSNF changed the title Refactor mwApiPath, mwRestApiPath, mwModulePath and mwWikiPath parameters + fix regression of test render template Refactor mwApiPath (to mwActionApiPath), mwRestApiPath, mwModulePath and mwWikiPath parameters + fix regression of test render template Nov 6, 2023
@benoit74
Copy link
Contributor

benoit74 commented Nov 7, 2023

I like the fact that you completely removed --mwApiPath CLI param. Reusing it for the REST endpoint (as it is currently done in main branch) was an extremely breaking change from my PoV.

This CLI changes are somehow a breaking change (we cannot set --mwApiPath anymore) but at least we will get a clear error instead of very weird things when the parameter was finally used for something else.

Good job!

@VadimKovalenkoSNF
Copy link
Collaborator Author

Thank you, @benoit74 , but I want to emphasize that mwApiPath was renamed to mwActionApiPath. Full list of param definitions can be found in src/parameterList.ts. Moreover, mwWikiPath is obligated now (this basically was introduced in this PR) for scraping wikimedia wikis correctly and mwWikiPath and mwActionApiPath are necessary for 3rd party wikis, see #1935 (comment) for more details.

@VadimKovalenkoSNF VadimKovalenkoSNF force-pushed the I1935-rollback-mw-api-configs branch 2 times, most recently from 99842b0 to c2f2b87 Compare November 9, 2023 12:37
Copy link
Collaborator

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI does not pass

@VadimKovalenkoSNF
Copy link
Collaborator Author

CI does not pass

Because of the regression described in #1943

@@ -13,7 +13,7 @@ describe('Styles', () => {

test('Stylesheet downloading', async () => {
const { articleDetailXId } = RedisStore
const { downloader } = await setupScrapeClasses() // en wikipedia
const { downloader } = await setupScrapeClasses({ mwWikiPath: '/' }) // en wikipedia
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only test against Wikimedia Web site, so why not setting this once for all? Why it's not the default value in setupScrapeClasses()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this issue.


return outFiles
}

export async function testAllRenders(parameters: Parameters, callback) {
export async function testAllRenders(parameters: Parameters, callback, optionalRenderesList?: Array<string>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming of the method is not appropriate anymore, it's not "all" Renders.

I would recommend to:

  • Rename this to TestRenders()
  • Create testAllRenders() with RENDERERS_LIST as argument list for then redirecting to TestRenders()

It's somehow concerning to have e2e tests not running on all renders as this is a basic requirement... but here there is maybe a special use case...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored.

@@ -39,7 +40,7 @@ describe('forceRender', () => {
expect(redisScan.stdout).toEqual('')
})

test('Scrape article from bm.wikipedia.org should throw error when using VisualEditor render', async () => {
test.skip('Scrape article from bm.wikipedia.org should throw error when using VisualEditor render', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why skipping? Actually it should not throw an error, it should work perfectly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

src/MediaWiki.ts Outdated

private initApiURLDirector() {
// TODO: this.webUrl probably shouldn't accept hardcoded 'wiki/' param, check test/e2e/extra.e2e.test.ts
this.webUrl = this.baseUrlDirector.buildURL('wiki/')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, here the mwWikiPath value should be taken

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored this. Also, 'wiki/' value is default again.

@VadimKovalenkoSNF VadimKovalenkoSNF force-pushed the I1935-rollback-mw-api-configs branch from c2f2b87 to d3b0125 Compare November 10, 2023 16:00
@VadimKovalenkoSNF
Copy link
Collaborator Author

VadimKovalenkoSNF commented Nov 12, 2023

@kelson42 It looks like the root cause was not with treating wikiPath for the third-party wikis, but rather how mwActionApPathi (ex mwApiPath) is set - it should not contain the forward slash at the beginning, because we build API endpoint on top of baseUrl.href in Mediawiki which already contains forward slash at the end.

Check this JS snippet:

const url = 'https://en.wikipedia.org'
console.log(new URL(url).href) // "https://en.wikipedia.org/" 

Forward slash at the end of href prohibits building the correct URL for wikis like https://minecraft.wiki/: it will be like https://minecraft.wiki//api.php?action=... which is wrong (note two forward slashes before api.php/). So in such cases, the receipt should be changed. Here is a minified version of article scraping when using changes from this PR:
npm start -- --adminEmail="contact@kiwix.org" --customZimDescription="Minecraft is a sandbox construction video game." --mwActionApiPath="api.php" --mwModulePath="/load.php" --mwUrl="https://minecraft.wiki/" --mwWikiPath="/" --articleList="Enchanting" --verbose

By using this command, the action API URL to get wiki site info will be correct:
https://minecraft.wiki/api.php?action=query&meta=siteinfo&format=json&formatversion=2&siprop=general%7Cnamespaces%7Cstatistics%7Cvariables%7Ccategory%7Cwikidesc

So I brought back the default 'wiki/' param for Mediawiki.webUrl. It is using only there and nowhere else.

@kelson42 kelson42 merged commit 99da4fd into main Nov 13, 2023
3 of 4 checks passed
@kelson42 kelson42 deleted the I1935-rollback-mw-api-configs branch November 13, 2023 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REGRESSION?] API end-point detection does not take care properly of command line argument
3 participants