Repository navigation
serve the citation e2e tests from a local mock of the citation services - #19290
Conversation
A citation test that saw neither results nor an error re-probed only the service's host root, which can answer while the lookup's own endpoint or redirect target hangs. In run 40377299047 doi.org answered the probe in milliseconds while its CSL content negotiation (a 302 to data.crosscite.org) and api.datacite.org's search both sat on the rsession's download for R's full 60s timeout, so a DataCite outage failed the shard instead of skipping. The tests now re-probe the exact request the rsession made (mirrored from the panmirror modules), following redirects and reading the body, and treat a 5xx/429 like a hang. The verdict replaces the host's cached entry so later guards skip too. The search tests share the wait with the DOI inserts, so a search that hangs skips the same way. A harness spec covers the classification against a local server.
The PubMed search is two requests: esearch for the ids, then esummary for their records, and the dialog shows nothing until both answer. A ServiceRequest can now name the request the rsession makes next from its response body, and the probe follows the chain under one timeout.
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
The rsession's DOI, Crossref, DataCite and PubMed lookups now read their base
URLs from the rstudio.{doi,crossref,datacite,pubmed}_url options, so the
citations spec can point them at a loopback mock answering from captured
fixtures. This replaces re-probing the live services, which can't tell a slow
service from a stuck product.
gtritchie
left a comment
There was a problem hiding this comment.
Moving these tests off the live services makes sense, and the run 40447537582 analysis makes the case well. Notes inline, roughly in priority order:
- URLs reach
download.file()unescaped (pre-existing for DOIs; this PR routes the new option values through the same string). - The mock is gated on
sessionsRunLocally(), which doesn't quite answer "can the rsession reach this machine's loopback". - Nothing checks the fixtures against the live services anymore.
- Smaller: options set on remote sessions that can't reach the mock,
afterAllwhen the mock never started, trailing slash in the base URL, failure-path coverage, option names spread across files, and no test forserviceBaseUrl().
| } | ||
| } | ||
|
|
||
| std::string serviceBaseUrl(const std::string& option, const std::string& defaultUrl) |
There was a problem hiding this comment.
The URL built from this ends up in download.file('<url>' ...) (src/cpp/session/SessionAsyncDownloadFile.cpp:144) without escaping, so a ' in the option value breaks the R command.
The DOI has the same problem, and that predates this PR. The DOI panel passes the trimmed search text straight to fetchCSL, and panmirror's Wiley pattern (10.1002/[^\s]+) accepts a quote anyway. I checked: the command built for 10.1002/it's fails parse() with "unexpected symbol".
Escaping the URL with string_utils::singleQuotedStrEscape in asyncDownloadFile, the way the user agent already is, would cover both.
There was a problem hiding this comment.
Fixed in 28c7507: asyncDownloadFile() now escapes the URL, and the header values too, with singleQuotedStrEscape(). It isn't only typed input: the Crossref, DataCite and PubMed panels also call fetchCSL with the DOI from a search result. Added an e2e test that looks up 10.1002/it's against the mock and expects "No data for this DOI could be found." rather than the parse error.
|
|
||
| std::string serviceBaseUrl(const std::string& option, const std::string& defaultUrl) | ||
| { | ||
| std::string url = r::options::getOption<std::string>(option, defaultUrl, false); |
There was a problem hiding this comment.
Every caller formats %s/%s, so a value with a trailing slash produces a double slash. For example, options(rstudio.doi_url = "http://127.0.0.1:N/doi/") requests /doi//10.3133/93888, which the mock answers with a 404 (I ran it against the mock). optionsCall() never adds a trailing slash, so this only affects someone setting the option from the console, but stripping a trailing / here is cheap.
There was a problem hiding this comment.
Fixed in f69352b: serviceBaseUrl() strips trailing slashes, and a value that's only slashes falls back to the default.
| std::string serviceBaseUrl(const std::string& option, const std::string& defaultUrl) | ||
| { | ||
| std::string url = r::options::getOption<std::string>(option, defaultUrl, false); | ||
| return url.empty() ? defaultUrl : url; |
There was a problem hiding this comment.
Minor: nothing tests the unset/empty-string fallback. The e2e suite always sets valid URLs, so a regression here would send production lookups to an empty host without any test noticing. (Non-string values are already handled: getOption logs and returns the default.)
There was a problem hiding this comment.
Added SessionPanmirrorUtilsTests.cpp in f69352b. It checks that unset, '' and '/' fall back to the default, that a set value is used, and that trailing slashes are dropped.
| const char * const kCrossrefWorks = "works"; | ||
|
|
||
| // kCrossrefApiHost, unless the rstudio.crossref_url option overrides it. | ||
| std::string crossrefApiHost(); |
There was a problem hiding this comment.
Only Crossref gets an accessor. DOI, DataCite and PubMed call serviceBaseUrl() inline, so the four option names are string literals in four .cpp files. A typo in one silently falls back to the live host, and the e2e tests would quietly start hitting the real service again. Declaring the option names next to the kXxxHost constants, or giving all four an accessor like this one, would keep them together.
There was a problem hiding this comment.
| services = await CitationServiceMock.start(); | ||
| // The mock listens on this machine's loopback, which only an rsession on | ||
| // this machine can reach. | ||
| servicesReachable = sessionsRunLocally(mode, externalServerUrl()); |
There was a problem hiding this comment.
sessionsRunLocally() was written to answer "can the stack dump see the rsession processes", which isn't quite "can the rsession reach this machine's loopback". Consider a localhost URL that forwards into a container (docker run -p 8787:8787 with PW_RSTUDIO_SERVER_URL=http://localhost:8787): it passes this check, but the rsession's 127.0.0.1 is the container's, so the network-backed tests fail instead of skipping.
None of the documented setups do this, so it's hypothetical. A probe from inside the session would answer the actual question, though: a download.file() of the mock URL from R, along the lines of the in-session probes in utils/connections.ts.
There was a problem hiding this comment.
I'd keep the static check. The two approaches only disagree when the session is local but can't reach this machine's loopback: your port-forwarded container, or a session whose environment sends loopback requests through a proxy. In the proxy case on CI, a probe-gated skip would quietly skip every network-backed test, and the coverage this PR restores would disappear without a red run. In the container case the failure is loud and easy to trace, since every network test reports the same unreachable mock.
| try { | ||
| await consoleActions.executeInConsole(RESET_CITATION_SERVICE_OPTIONS, { wait: true }); | ||
| } finally { | ||
| await services.close(); |
There was a problem hiding this comment.
If beforeAll fails before the mock starts, services is undefined here, so this throws a TypeError on top of the real failure. Playwright still reports the original error, so it's noise rather than masking, but services?.close() avoids it.
There was a problem hiding this comment.
Done in 92a1d92 (services?.close()). The options reset is also skipped when the mock was never reachable.
| await consoleActions.executeInConsole('unlink("references.bib")', { wait: true }); | ||
| // any leftover so each test's bib assertions start from a clean file. The | ||
| // same command (re)points the session's citation lookups at the mock. | ||
| await consoleActions.executeInConsole(`unlink("references.bib"); ${services.optionsCall()}`, { wait: true }); |
There was a problem hiding this comment.
This runs even when servicesReachable is false. So on a remote server, the user's session gets rstudio.*_url pointed at an unreachable loopback port before every test, including the ones that don't touch the network. If afterAll doesn't get to run (worker killed, console wedged), Insert Citation stays broken in that session until R restarts. Setting the options only when servicesReachable is true would avoid that.
There was a problem hiding this comment.
Done in 92a1d92: beforeEach sets the options only when the mock is reachable, and afterAll only resets them then.
| await citation.open(); | ||
| const searchBox = await citation.selectSource(CITATION_SOURCES.datacite); | ||
| await citation.search(searchBox, searchTerm); | ||
| await expect(citation.searchError).toHaveText('An error occurred while searching DataCite.', { timeout: 30000 }); |
There was a problem hiding this comment.
Good to have the failure path covered at last. It only covers DataCite, though. DOI and PubMed failures go through separate code in the rsession (doiFetchCSL, and the nested pubMedRequest calls in pubMedSearch), and a regression that leaves either stuck on "Searching..." would pass. Parameterizing this over the services would cover them.
There was a problem hiding this comment.
92a1d92 runs the failure test for every source: DOI, Crossref, DataCite, PubMed, and PubMed with only the nested esummary leg failing (fail() now takes an optional resource). Crossref's panel has no service-specific error text, so that case expects the catch-all "An unknown error occurred. Please try again."
| @@ -0,0 +1,945 @@ | |||
| { | |||
There was a problem hiding this comment.
This trades the flakiness for a blind spot: nothing checks anymore that the live services still return what these fixtures say. If DataCite changes its JSON:API shape, or doi.org stops honoring the CSL Accept header, users' lookups break while this suite stays green. There's also no script to re-capture the fixtures.
Could we keep an opt-in live run (env-gated, leaving the options unset so the session uses the real services), or check in the capture script so the fixtures can be refreshed?
There was a problem hiding this comment.
Added an opt-in live run in 2c1b642: PW_CITATION_LIVE=1 leaves the options unset, so the session uses the real services, and skips the failure-injection tests (documented in the e2e README). Run today, everything passes except searches DataCite. That one fails on the ranking drift that currently has main red (a new record pushed the "bobolink" matches past the first five rows), not on a change in the services' responses. It's manual, so it only catches drift when someone runs it.
A quote in a DOI (typed, or carried by a Crossref/DataCite/PubMed result) ended the R string literal, so the lookup failed to parse.
Also unit-tests serviceBaseUrl()'s fallback to the live service.
…er each service's failure path
The Insert Citation e2e tests looked up DOIs and ran searches against the live doi.org, Crossref, DataCite and PubMed services. They skipped when a host was unreachable, and this PR first tried to also skip when a lookup hung by re-probing the exact request afterwards. That can't separate a slow service from a stuck product: in this PR's own run 40447537582, a DataCite search sat in the rsession for 30s while the test's re-probe of the identical request answered in 9.4s (2.6s on the retry), so the Linux Desktop shard failed on DataCite's latency.
So this takes the live services out of the tests instead:
rstudio.doi_url,rstudio.crossref_url,rstudio.datacite_url,rstudio.pubmed_url-- falling back to the real services (serviceBaseUrl()inSessionPanmirrorUtils, unit-tested inSessionPanmirrorUtilsTests.cpp). These sit alongside the existingrstudio.crossref_emailandrstudio.pubmed_api_keyoptions, and are read per request, so setting them from the console takes effect immediately.utils/citation-services.tsis a loopback HTTP mock of the four services, answering fromfixtures/citation-services.json(responses captured from the live services and trimmed). It keeps the contract the DOI lookup depends on -- CSL only for a request that negotiates for it withAccept: application/vnd.citationstyles.csl+json-- and can fail a service, or one of its resources, on demand.citations.test.tspoints the session at the mock before each test and drops the reachability gates and the re-probe/skip logic. New tests check that a failing service shows the dialog's error line for each source (and for PubMed's second, esummary leg), which the live services never let us exercise. Against a remote server, whose rsession can't reach this machine's loopback, the network-backed tests skip and the session's options are left alone.PW_CITATION_LIVE=1runs the same tests against the live services instead, to check that the fixtures still match what those services answer; the failure-injection tests skip.CITATION_SERVICE_REQUESTS,reprobeRequest(),CITATION_SERVICE_HOSTS), their harness spec, and the now-unusedInsertCitationDialog.searchStatusare removed.Also fixed along the way:
asyncDownloadFile()spliced the URL and header values into the child R process'sdownload.file()call unescaped. A quote in a DOI -- typed into the dialog, or carried by a Crossref/DataCite/PubMed result -- ended the string literal, so the lookup failed to parse. Both are now escaped withsingleQuotedStrEscape(), and a new test looks up10.1002/it's.Verified locally with
npm run test:desktop-dev -- tests/panes/editor/citations.test.ts: all 17 citation tests pass. WithPW_CITATION_LIVE=1, everything butsearches DataCitepasses; that one fails on DataCite's current ranking drift (the same failure main has right now), not on a change in the responses. The rsession gtests pass.No issue: test infrastructure (the options are an undocumented test hook), plus the escaping fix above, which came up in review.