Skip to content

Commit 3e3dc63

Browse files
authored
ci: fix E2E tests (#3855)
The scheduled E2E runs have been red since 2 July. Two independent causes. ## The token Every failure was `ApifyApiError: User was not found or authentication token is not valid` (401), which looks like an expired secret but is not — the login succeeds every run. The harness read the token out of `~/.apify/auth.json`. Since [apify-cli#1197](apify/apify-cli#1197) the bundle distribution (what CI installs) stores the token in the OS keyring and strips it from that file — intended behaviour, as plaintext storage was the bug it fixed. The file still exists, so the `existsSync` guard passed, `getApifyToken()` returned `undefined`, and `process.env.APIFY_TOKEN ??= undefined` coerced it to the literal string `"undefined"`. That bogus token is what the API rejected. It landed within the `1.6.3` beta line (`beta.6` wrote `auth.json`, `beta.25` wrote the keyring), which is why it broke ~2 weeks before 1.7.0 shipped. - Pass `APIFY_TOKEN` from the existing secret, so the harness no longer reaches into the CLI's credential store. The beta CLI is still installed and exercised as before. - Throw a clear error when `auth.json` has no token, instead of silently yielding `"undefined"`. ## The demo store With the token fixed, PLATFORM actually ran its tests for the first time since 2 July — and `cheerio-robots-file` then failed on `429`s from `warehouse-theme-metal.myshopify.com`. The robots.txt behaviour under test was fine; the crawl never got off the ground, so `requestsFinished` was 0 and the precondition failed. The store rate-limits plain-HTTP clients from the platform's shared egress IP. The browser-driven tests on the same IP get through. The six tests crawling that store now go through `Actor.createProxyConfiguration()`.
1 parent b3c3ef2 commit 3e3dc63

8 files changed

Lines changed: 23 additions & 0 deletions

File tree

.github/workflows/test-e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ jobs:
8787
run: yarn test:e2e
8888
env:
8989
STORAGE_IMPLEMENTATION: ${{ matrix.storage }}
90+
# Provided explicitly: the CLI may store the token in the OS keyring, where the tests can't read it.
91+
APIFY_TOKEN: ${{ secrets.APIFY_SCRAPER_TESTS_API_TOKEN }}
9092
APIFY_HTTPBIN_TOKEN: ${{ secrets.APIFY_HTTPBIN_TOKEN }}
9193
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
9294
GITHUB_TOKEN: ${{ github.token }}

test/e2e/adaptive-playwright-robots-file/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ await Actor.init({
99
});
1010

1111
const crawler = new AdaptivePlaywrightCrawler({
12+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
13+
proxyConfiguration: await Actor.createProxyConfiguration(),
1214
maxRequestsPerCrawl: 10,
1315
respectRobotsTxtFile: true,
1416
onSkippedRequest: (args) => crawler.log.warningOnce(`Request ${args.url} was skipped, reason: ${args.reason}`),

test/e2e/cheerio-robots-file/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ await Actor.init({
99
});
1010

1111
const crawler = new CheerioCrawler({
12+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
13+
proxyConfiguration: await Actor.createProxyConfiguration(),
1214
maxRequestsPerCrawl: 10,
1315
respectRobotsTxtFile: true,
1416
});

test/e2e/playwright-introduction-guide/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ router.addDefaultHandler(async ({ request, page, enqueueLinks, log }) => {
8989
});
9090

9191
const crawler = new PlaywrightCrawler({
92+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
93+
proxyConfiguration: await Actor.createProxyConfiguration(),
9294
maxRequestsPerCrawl: 15, // so the test runs faster
9395
// Instead of the long requestHandler with
9496
// if clauses we provide a router instance.

test/e2e/playwright-robots-file/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ await Actor.init({
99
});
1010

1111
const crawler = new PlaywrightCrawler({
12+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
13+
proxyConfiguration: await Actor.createProxyConfiguration(),
1214
maxRequestsPerCrawl: 10,
1315
respectRobotsTxtFile: true,
1416
});

test/e2e/puppeteer-store-pagination-jquery/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const mainOptions = {
1111

1212
await Actor.main(async () => {
1313
const crawler = new PuppeteerCrawler({
14+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
15+
proxyConfiguration: await Actor.createProxyConfiguration(),
1416
maxRequestsPerCrawl: 10,
1517
preNavigationHooks: [
1618
async ({ page }, goToOptions) => {

test/e2e/puppeteer-store-pagination/actor/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ await Actor.init({
99
});
1010

1111
const crawler = new PuppeteerCrawler({
12+
// The store rate-limits the platform's shared egress IP, so crawl through a proxy.
13+
proxyConfiguration: await Actor.createProxyConfiguration(),
1214
maxRequestsPerCrawl: 10,
1315
preNavigationHooks: [
1416
async ({ page }, goToOptions) => {

test/e2e/tools.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,15 @@ export async function getApifyToken() {
339339
}
340340

341341
const { token } = await fs.readJSON(authPath);
342+
343+
// Newer CLI versions keep the token in the OS keyring, leaving auth.json without it.
344+
if (!token) {
345+
throw new Error(
346+
'Your Apify token is not stored in auth.json (the CLI likely saved it in the OS keyring). ' +
347+
'Set the "APIFY_TOKEN" environment variable, or re-run "apify login" with "APIFY_DISABLE_KEYRING=1".',
348+
);
349+
}
350+
342351
return token;
343352
}
344353

0 commit comments

Comments
 (0)