Skip to content

test(webhooks): keep the Bitbucket secret test off the network - #278

Closed
agentHits wants to merge 1 commit into
AgentHits-Devfrom
test/bitbucket-diffstat-no-network
Closed

agentHits wants to merge 1 commit into
AgentHits-Devfrom
test/bitbucket-diffstat-no-network

Conversation

@agentHits

Copy link
Copy Markdown
Collaborator

Зачем

Тест service-webhook-secret > checks a Bitbucket source with the service secret too ходил в настоящий api.bitbucket.org. Для источника Bitbucket обработчик вебхука деплоя запрашивает diffstat коммита (extractCommittedPaths в pages/api/deploy/[refreshToken].ts) с таймаутом 10 с, а fetch в файле ничем не подменялся. Если Bitbucket отвечал медленно, тест не укладывался в лимит vitest 5 с и ронял pr-check (unit) у PR, которые его не касались (последний раз у #273, повтор прошёл).

Что изменилось

Только тест, код панели не менялся.

  • Файл подменяет fetch на каждый тест ответом diffstat из одной страницы и снимает подмену после каждого теста (vi.stubGlobal / vi.unstubAllGlobals).
  • Тест Bitbucket дополнительно проверяет, что обработчик вызвал fetch один раз по адресу diffstat коммита, и что запрос с неверной подписью получает 401, не обращаясь к Bitbucket.

Проверки

Linux, Bun 1.4.4, Node 26.13.0 (VM):

  • Воспроизведение: api.bitbucket.org направлен на адрес, который не отвечает (--add-host api.bitbucket.org:10.255.255.1). До правки оба варианта теста (application и compose) падают по таймауту 5 с; после правки файл проходит за 0,3 с (92 из 92).
  • Без сети вовсе (--network none): 92 из 92, четыре прогона подряд.
  • bun run server:build, bun run typecheck, biome format и biome lint по файлу проходят.

🤖 Generated with Claude Code

`checks a Bitbucket source with the service secret too` went to the real
api.bitbucket.org: for a Bitbucket source the deploy webhook asks for the
pushed commit's diffstat, with a 10 s timeout, and nothing in the file
replaced `fetch`. On a slow answer the test outlasted vitest's 5 s limit and
failed `pr-check (unit)` on PRs that did not touch it (again on #273).

The file now stubs `fetch` for every test with a one-page diffstat and
removes the stub after each test. The Bitbucket test also checks that the
handler called it once, for the commit's diffstat URL, and that the request
with a wrong signature is refused without a second call.

Reproduced on Linux with api.bitbucket.org pointed at an address that never
answers: before, both variants (application, compose) time out at 5 s;
after, the file passes in 0.3 s, also with no network at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agentHits

Copy link
Copy Markdown
Collaborator Author

Закрываю как дубль #277: там та же подмена fetch для diffstat Bitbucket, только шире (проверки shouldDeploy и очереди, лимит ssh-теста, проверка нативного модуля ssh2). Воспроизведение из этого PR подтверждает исправление: при зависшем api.bitbucket.org старый тест падает по таймауту 5 с в обоих вариантах, с подменой fetch файл проходит за 0,3 с.

@agentHits agentHits closed this Nov 16, 2026
@agentHits
agentHits deleted the test/bitbucket-diffstat-no-network branch November 16, 2026 10:29
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.

1 participant