Commit Graph

42 Commits

Author SHA1 Message Date
Sebastian Poxhofer fbedd41e82 test: replace env operation with vi.stubEnv() (#45490)
* test: replace manual process.env mutation with vi.stubEnv

Enable Vitest's `unstubEnvs` so env stubs are reverted automatically
before every test, and convert the manual `process.env.X = ...` /
`delete process.env.X` pairs in specs to `vi.stubEnv()`.

This removes the hand-written `afterEach` cleanup blocks and the
`const OLD_ENV = process.env` / `process.env = { ...OLD_ENV }`
save-restore dance, which silently leaked state between tests when a
test set a variable without a matching delete.

Left as-is (incompatible with `unstubEnvs`, which unstubs before each
test, not after):
- module top-level env writes (cocoapods, gomod, post-update, pip-compile
  and bundler artifacts specs)
- `beforeAll` env writes -- the two in `util/http` moved to `beforeEach`

* test: stop asserting on ambient environment variables

Three specs asserted on values that the surrounding environment can
override, so they only passed on a machine that happened not to set them:

- `util/exec/env`: `getChildProcessEnv()` forwards every entry of
  `basicEnvVars`, but the spec only seeded a subset. Any other forwarded
  variable that was set ambiently (e.g. a lowercase `http_proxy`) leaked
  into the `toEqual` assertion. Clear all of them first.
- `util/git/index`: `process.env.GIT_SSH_COMMAND` deliberately overrides
  the default that the two env-inheritance tests assert on. Clear it.
- `logger/pretty-stdout`: the colorized level strings are built at import
  time, so the `beforeEach` setting `FORCE_COLOR` could never affect them
  -- it was dead code, and the test silently assumed a terminal without
  colour support. Derive the expectation the same way the module does.

* test(datasource/nuget): use a throwaway cache dir for nupkg downloads

The `determine source URL from nupkg` tests do not mock the filesystem,
so they really wrote downloaded packages into a fixed `/tmp/cache` path.
That fails wherever the system tmpdir is not writable, and two checkouts
running the suite at once would share the same directory.

Use `tmp.dir({ unsafeCleanup: true })` and clean it up afterwards, which
is the pattern the other specs that touch disk already use.

* feat(lint): add renovate/prefer-stub-env rule

Enforces in specs what the migration to `vi.stubEnv` established:

- assigning to or deleting `process.env.X` inside `beforeEach`, `afterEach`,
  `it` or `test` is reported, with a fixer that rewrites it to `vi.stubEnv()`
- module scope, `describe` bodies and `beforeAll` / `afterAll` are left alone:
  `unstubEnvs` reverts stubs *before* each test, so a stub created there is
  gone by the time the first test runs, and those must keep assigning directly
- replacing the `process.env` object is reported everywhere and never fixed.
  `vi.stubEnv()` captures the original object when the worker starts, so after
  a reassignment its deletes silently target the old object

The rule found 28 further violations in specs the earlier sweep missed, since
that one was anchored on `delete process.env`. Twelve were auto-fixed; the
rest replaced `process.env` wholesale and are now `clearEnv()` from test/util.

`util/exec/index.spec.ts` opts out with a comment: it asserts on the whole
child env, and `vi.stubEnv()` cannot express that because it maps `PROD`,
`DEV` and `SSR` onto '' instead of deleting them.
2026-08-28 09:26:20 +00:00
Sergei Zharinov b8809cedb5 fix(http): fallback to github hostType for GHE platform endpoint (#42287)
* fix(http): fallback to github hostType for GHE platform endpoint

When running against GitHub Enterprise Server, datasources not listed
in GITHUB_API_USING_HOST_TYPES (e.g. github-digest) fail to authenticate
because the existing fallback only covers api.github.com URLs.

This adds a host-matching fallback: when the active platform is github
and the request URL targets the same host as the configured endpoint,
credentials from the github hostType rule are applied.

* Refactor

* Fix
2026-03-31 17:07:43 +00:00
Sergei Zharinov 930cf6633c refactor: Rewrite imports with .ts extensions (#40700)
fix: Additional vi.mock path corrections and prettier formatting
2026-01-26 22:48:17 +00:00
Jamie Tanna f84305d7bf feat(hostRules): auto-wire a hostRule for api.github.com (#38733)
feat(hostRules): automagically use host rules for any `api.github.com` lookups

As noted in #38732, the Typst datasource performs API calls to the
GitHub APIs, but as we do not have explicit datasource mapping for the
API calls (via `GITHUB_API_USING_HOST_TYPES`), we end up sending
unauthenticated API calls, which then can result in rate limits.

We had previously attempted to fix this in #30490, for a different
datasource, and there are likely other datasources impacted.

To simplify this, we can auto-wire any `https://api.github.com/` API
calls with the `hostType: github` hostRule, when matching against the
hostname from the `url`.

This also adds a note to deprecate the usage of
`GITHUB_API_USING_HOST_TYPES`, unless it's explicitly needed.

Closes #38953.
2025-11-04 17:10:58 +00:00
Jamie Tanna 4a04436307 test(hostrules/github): add clearer precedence examples (#38961)
As part of #38953, we are changing the way that host rules work for
GitHub.com, and automagically wiring them in for datasources that
interact with `github.com`.

To do this, we should first provide a clearer definition of how host
rules should work, especially when there may be conflicting sources of
tokens, or where we may be on GitHub Enterprise Server vs GitHub.com.
2025-10-31 09:07:13 +00:00
Johannes Feichtner 68a66a05a9 feat(bitbucket-server): add support for changelogs (#34569) 2025-04-09 09:45:32 +00:00
Yohei Ueki 7d46cf7d42 fix(host-rules): respect hostRules.enabled=false even when noAuth=true (#35048) 2025-03-31 09:20:21 +00:00
Michael Kriese 997c23502e test: migrate to vitest (#34475)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2025-02-26 09:35:54 +00:00
Zigmas Bitinas c0af153b5e fix(http): allow overwriting default Renovate headers (#33907) 2025-01-29 14:18:51 +00:00
RahulGautamSingh 2eb7c76027 feat(http)!: remove dnsCache option (#29449)
BREAKING CHANGE: dnsCache is now removed
2024-07-25 15:28:16 +02:00
Rhys Arkins 4bfd0f304e fix: Revert "feat: Limit HTTP concurrency and frequency by default" (#27765) 2024-03-07 08:01:34 +00:00
Sergei Zharinov 147d38a2a4 feat: Limit HTTP concurrency and frequency by default (#27621) 2024-03-05 14:50:09 +00:00
François db9d485227 feat(config): implement custom header field inside HostRules (#26225) 2024-01-17 09:22:19 +00:00
Sergei Zharinov 383bc11d4c refactor(http): Separate search and apply of host rules (#26067) 2023-12-01 12:00:20 +00:00
Michael Kriese 8c78b5a733 fix(keep-alive): use camlcase for option name (#26018) 2023-11-28 22:31:18 +00:00
Sergei Zharinov b69416ce17 refactor(prettier): Force trailing commas (#25631) 2023-11-07 15:50:29 +00:00
Michael Kriese 84a97a62fa test(perf): improve test speed (#24323) 2023-09-08 11:40:04 +00:00
Yun Lai 667f137081 feat: add options to host rules to enable mTLS calls to host (#24155)
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2023-09-06 12:02:34 +00:00
Michael Kriese 69f7240640 feat(datasource): add gitea-tags datasource (#24083) 2023-08-25 14:12:36 +00:00
Sergei Zharinov ce41717678 refactor(http): Fix coverage (#23004)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2023-06-28 11:55:26 +02:00
RahulGautamSingh c56588eaba refactor: convert PlatformmId to union (#18458) 2022-11-01 14:46:09 +00:00
Rhys Arkins 9bc8b05af3 feat: http keepalives (#17582) 2022-09-02 12:32:34 +02:00
Michael Kriese aabb3abf9a feat(http): use own dns cache (#17574) 2022-09-01 15:23:46 +00:00
Michael Kriese 13574419ba feat(http): support dns cache (#17533) 2022-08-31 11:49:54 +00:00
Michael Kriese 0316a5e62d test: use jest v29 (#17151) 2022-08-16 14:22:29 +02:00
Michael Kriese 637585c5fd feat(http): extend stats (#15104) 2022-04-14 10:47:06 +01:00
Michael Kriese 64f5bd5f03 test: enforce lint style rules (#15085) 2022-04-12 14:49:49 +00:00
Richard Versteeg 000142e5d5 feat(changelogs): Add github-changelog and gitlab-changelog hosttypes (#13695)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-02-02 10:20:51 +00:00
Richard Versteeg 599958a56b fix(bitbucket-tags): Add hostType and fallback for bitbucket-tags datasource (#13697) 2022-01-20 20:16:17 +00:00
Richard Versteeg c3783171c2 fix(gitlab-packages): Add missing hostType for datasource calls (#13696)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2022-01-20 19:55:10 +00:00
Maksim 1f86b71fd5 refactor: constants (#11690) 2021-10-06 07:43:32 +02:00
Michael Kriese 28222bf762 fix: do not fallback if explicit auth is configured (#11760)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2021-09-15 15:13:17 +00:00
Michael Kriese 8785f70b93 fix(core/http): fallback to github /gitlab hosttype (#11605)
* fix(core/http): fallback to github /gitlab hosttype

* fix: remove generic host rule

* Update lib/util/http/index.ts

Co-authored-by: Rhys Arkins <rhys@arkins.net>
2021-09-06 21:07:52 +02:00
Sergei Zharinov 5f4b9f9a3a test: Fix test descriptions and enforce it via new linting rule (#11285) 2021-08-18 05:46:56 +00:00
Michael Kriese 3c7546f7cd test: simplify nock handling (#10170) 2021-05-27 14:13:31 +02:00
Sergei Zharinov ce51f05cef feat(test): Detect test utils callers and simplify helpers (#9707) 2021-04-26 16:15:03 +02:00
Michael Kriese 607b151f0e feat(http): support custom auth types (#9053) 2021-03-09 19:25:18 +01:00
Rhys Arkins 4d349b4608 test: add missing httpMock.reset (#8836) 2021-02-24 11:31:59 +01:00
Rhys Arkins 00a08225b9 refactor: use ls-lint (#7956) 2020-12-11 13:29:43 +01:00
Michael Kriese bbea59939e feat: add http2 option (#6957) 2020-08-11 11:53:23 +02:00
Michael Kriese 5815f75f13 feat(internal): migrate to got v11 (#6725)
Co-authored-by: Jamie Magee <JamieMagee@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2020-07-22 20:15:48 +02:00
Michael Kriese 76d8574581 chore(internal): fix http coverage (#6746) 2020-07-14 09:51:27 +02:00