Commit Graph

64 Commits

Author SHA1 Message Date
Sebastian Poxhofer 05e1271376 test: use expect().resolves instead of awaiting inside expect (#45672)
Enables the vitest/prefer-expect-resolves oxlint rule and applies its
autofix across the spec suite.
2026-09-04 10:40:46 +00:00
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
Jamie Tanna 5b1749983c feat: always set CI=true for subprocesses
As noted in #43761, we had recently set `CI=true` for the Renovate and
Containerbase orgs on Mend-hosted apps due to a pnpm v11 requirement:

    ERR_PNPM_ABORTED_REMOVE_MODULES_DIR_NO_TTY  Aborted removal of
      modules directory due to no TTY

    If you are running pnpm in CI, set the CI environment variable to
      "true", or set "confirmModulesPurge" to "false".

Similarly in #43606, it was noted that we should do this for `mise lock`
to mark the workspace as "trusted".

Although we went with a different situation, there will be cases where
this is useful for tools being executed, for instance when we invoke `yarn`.

We also make sure to keep our documentation up-to-date as we add to the
specific overrides.

With help from Claude Sonnet and Opus to:

- perform some of the mechanical updates as part of this change
- ensure that the Docker sidecar always has `hardcodedProcessEnv` passed
  into it
- catch a needed change to `exposeAllEnv` handling

Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io>
Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-24 17:21:24 +01:00
Jamie Tanna b017c7548a fix(exec/docker): single-quote the sidecar bash command
When executing commands for `binarySource=docker`, we have two areas
that a command could have shell expansion/injection:

- on the host (when constructing the `bash -l -c`)
- in the container (when running a manager-specific command)

When constructing the host's command, we previously would escape the
`"`, which allows Bash syntax for `${VAR}` and `$(...)` syntax inside
it.

While managers use `quote()` to make the inputs safer, the use of `"`
around that would not provide any protection, and lead to cases where
the `quote()` could be expanded on the host, before `docker run`
executes.

After recent changes to each manager - and removal of `shell: true` -
this doesn't seem to be exploitable, but this hardens it further.

Additionally, we never escaped `\`, so a value containing `\"` produces
a command that `shlex.split` rejects, and the update fails rather than
running.

Instead, we can quote the whole `-c` argument with `quote()`, which
round-trips through both `shlex.split` - the default, no-shell path - and
a real shell.

This removes the `lgtm [js/incomplete-sanitization]` suppression as
we're now correctly sanitising this.

Note this doesn't remove the need for the managers to quote their own
values, as the second area above is still a real shell.

Co-authored-by: Claude Opus 5 <jamie.tanna+claude-code@mend.io>
2026-08-07 14:25:42 +01:00
Jamie Tanna c9cec1affb fix(manager/gomod): quote module path in import path update command
To prevent the possibility of a Go module name including
shell metacharacters (which is unlikely, but potentially possible
through a well-crafted payload), which could lead to command execution,
we can make sure they are quoted appropriately.

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-08-07 14:22:55 +01:00
Jamie Tanna 0e6429b13e refactor(types): document localDir isn't a globalOnly option (#44635)
* refactor(types): document `localDir` isn't a `globalOnly` option

To make sure that it's clear when reviewing `GlobalConfig`, as well as
working with our types, we can move the `localDir` definition into a
separate type.

* fixup! refactor(types): document `localDir` isn't a `globalOnly` option

* fixup! refactor(types): document `localDir` isn't a `globalOnly` option

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! refactor(types): document `localDir` isn't a `globalOnly` option

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

* fixup! refactor(types): document `localDir` isn't a `globalOnly` option

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>

---------

Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
2026-07-20 08:07:17 +00:00
Jamie Tanna 68cb7c71d5 test: ensure we set binarySource=global (#43382)
* test: ensure we set `binarySource=global`

As part of future changes, we'll correctly return the default value from
`GlobalConfig.get`, instead of `undefined` if no default is provided in
the `get` call.

As `binarySource=install` is the default, this then leads to these tests
failing, as they're intended to run with `binarySource=global`.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>

* fixup! test: ensure we set `binarySource=global`

* fixup! fixup! test: ensure we set `binarySource=global`

---------

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
2026-05-15 15:40:22 +00:00
Jamie Tanna 1054439929 refactor(gomod): extract deriveGoToolchainConstraints function (#42956)
As part of future changes, we'll introduce additional constraints that
may take priority, so we should ensure we have coverage of the existing
logic.

Co-authored-by: Claude Sonnet 4.6 <jamie.tanna+claude-code@mend.io>
2026-04-28 08:05:11 +00:00
Michael Kriese 440e353145 chore: use ts extension (#42300) 2026-04-01 07:46:34 +00:00
Jamie Tanna 2d1e57532f refactor(types): rename lockFile to fileName in ArtifactError (#41631)
As `fileName` makes more sense (as it's not always a lock file we're
updating).

Also, if you set `fileName`, it would never actually output the
filename.

This renames the usages of `lockFile` to `fileName`.

Co-authored-by: Claude Sonnet 4.5 <jamie.tanna+github-copilot@mend.io>
2026-03-10 09:57:31 +00:00
Roger Coll ab409e951f fix(gomod): add -modfile flag for non-default go.mod filenames (#41640)
* fix(gomod): add -modfile flag for non-default go.mod filenames

When using managerFilePatterns to manage non-standard go.mod files
(e.g. tools.mod), the go commands (get, mod tidy, mod vendor) now
include the -modfile flag so they operate on the correct module file
instead of defaulting to go.mod in the working directory

* Update lib/modules/manager/gomod/artifacts.ts

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* Update lib/modules/manager/gomod/artifacts.ts

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>

* use string templates

---------

Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
2026-03-05 11:53:42 +00:00
Tobias dda653f55a test(manager/gomod): use real hostRules implementation in tests (#41515)
chore(manager/gomod): use real hostRules implementation in tests
2026-02-26 12:37:28 +00:00
Sergei Zharinov 9d857c1f68 refactor(lint): Organize imports with biome (#40966) 2026-02-06 13:40:01 +00:00
Michael Kriese cd0426babd feat(sidecar): use renovatebot/base-image instead of containerbase/sidecar (#40772)
* feat(sidecar): use `renovatebot/base-image` instead of `containerbase/sidecar`

* refactor: simplify sidecar handling

* test: fixup

* docs: fixup
2026-01-29 10:05:24 +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
Mike Glazer 8557157edb feat: add support for go:generate directives in gomod (#39163)
* feat: add support for go:generate directives in gomod

This change adds a `goGenerate` postUpdateOption which enables
running `go generate ./...` after a dependency update.

Frequently when dependencies are brought in via tools or using
vendored code, and those dependencies are used for go:generate
instructions, we want to update the generated code after the dependency
has been updated.

Adding this as a postUpdateCommand wasn't really satisfactory since that
necessarily requires making a change in two spots (one in the allowed
commands, one in the postUpdateCommand). The other reason this was
undesirable was it would cause generate to run after every dependency
update, regardless of language.

* Updates

* Update fixes

* Self PR

* Fix docs link

* Trying to find the right path

* Fix

* Add deleted

* Fix

* And fix test...

* docs: tweak wording for `goGenerate`

* fix(types): don't default GlobalConfig

In a future change, `GlobalConfig.get` will correctly pull in the
defaults.

---------

Co-authored-by: Jamie Tanna <jamie.tanna@mend.io>
2025-12-12 12:43:54 +00:00
Jan Kaluza b50ee3d29f fix(gomod): Search the parent directories for "vendor" directory. (#37910)
gomod: Search the parent directories for "vendor" directory.

When the golang workspaces are used, the `go work vendor` generates
the `vendor` and `go.work.sum` files in the same directory where
the `go.work` exists - it means in the parent directory of `go.mod`
files.

The current code does not handle this behaviour correctly - it only
searches for the `vendor` directory next to the `go.mod` file.

In this commit, the code is extended to use `findLocalSiblingOrParent`
function to search for the `vendor` directory the very same way as
we currently search for the `go.work` file.

The code is also extended to search for the `go.work.sum` next to the
`go.work` file.

Related: https://github.com/renovatebot/renovate/discussions/37653

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
Co-authored-by: Jamie Tanna <jamie.tanna@mend.io>
2025-10-06 10:04:47 +00:00
Michael Kriese dd186a1359 fix(gomod): skip -d flag for go >=1.18 (#37428) 2025-08-11 10:47:47 +00:00
Sergei Zharinov 7c79c11285 fix: Always use default import from upath and semver-stable (#37325) 2025-08-05 11:01:45 +00:00
Michael Kriese 19c115c813 test: cleanup (#34785) 2025-03-13 17:52:09 +00:00
Michael Kriese 4f60a8b7fe test: mock git globally (#34783) 2025-03-13 15:48:02 +00:00
Trim21 ae56cbb26a fix(manager/gomod): perfer to use go version defined as toolchain to update artifacts (#34564)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2025-03-13 09:03:38 +00:00
Michael Kriese ec6631c9f7 fix(gomod): read contraints from new go.mod (#34655) 2025-03-06 11:55:27 +00:00
Michael Kriese 1644d9cb18 test: migrate more to vitest (#34500) 2025-02-26 15:45:17 +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
Omer Cohen aa0c7d284b feat(manager/gomod): option to always run go mod vendor (#33066)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-12-20 13:20:17 +00:00
Ed Harrod 894250d392 chore(manager/gomod): Update go version to 1.23.3 in tests/examples (#32514)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2024-11-13 15:45:18 +00:00
Dean Lindqvist Todevski 5f21e17398 feat(gomod): Add gomodSkipVendor postUpdateOption (#30025)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-07-10 21:29:12 +00:00
Chance Zibolski 381fa55753 feat(gomod): Support go work vendor (#29216) 2024-06-11 10:24:02 +00:00
Sergei Zharinov cc5f68ed73 feat(gomod): Notify extra packages updated by "go get" (#28938)
Signed-off-by: Quentin BERTRAND <contact@quentinbertrand.fr>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Quentin BERTRAND <contact@quentinbertrand.fr>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Miles Budnek <miles.budnek@fortra.com>
Co-authored-by: Alex Kessock <akessock@gmail.com>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Florian Greinacher <florian.greinacher@siemens.com>
Co-authored-by: ddovile <71456312+ddovile@users.noreply.github.com>
Co-authored-by: Dovile Dikoviciute <Dovile.Dikoviciute@bentley.com>
Co-authored-by: lstoeferle <48953604+lstoeferle@users.noreply.github.com>
Co-authored-by: Stéphane Goetz <onigoetz@onigoetz.ch>
2024-05-27 12:48:58 +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
Rhys Arkins 36e2b328bb chore: update types reference 2023-08-15 11:31:15 +02:00
Rhys Arkins c7832e55f8 feat!: remove BUILDPACK env support 2023-07-04 19:21:52 +02:00
RahulGautamSingh aa14b777c0 feat!: replace dockerImagePrefix with dockerSidecarImage (#22708)
Closes #21217

BREAKING CHANGE: dockerImagePrefix is now replaced by dockerSidecarImage
2023-07-04 19:21:52 +02:00
RahulGautamSingh 0b36f97bd3 refactor: replace as with partial/satisfies (#21982) 2023-05-08 06:36:40 +00:00
Michael Kriese 9f01274911 fix(fs): remove regex path validation (#21871) 2023-04-28 12:31:32 +00:00
Jorge Silva 91812d025d feat(manager/gomod): add goGetDirs option (#20156)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
2023-04-18 04:55:28 +00:00
Maxime Brunet 7b627e3900 fix(gomod): skip updating import path for incompatible versions (#20812) 2023-03-14 05:09:15 +00:00
Rhys Arkins 0f86d313da chore: fix artifacts tests 2023-03-10 09:34:40 +01:00
Michael Kriese ec4b17b8b6 feat(config)!: default dockerImagePrefix to containerbase (#20150)
Sidecar containers will now use `containerbase/` prefix instead of `renovate/` prefix.

BREAKING CHANGE: containerbase/ account used for sidecar containers instead of renovate/
2023-03-10 09:34:40 +01:00
Maxime Brunet 14019fed16 feat(gomod): enable gomodUpdateImportPaths for gopkg.in (#20743) 2023-03-04 08:32:04 +00:00
Tobias Kongsvik a340830ee6 fix(gomod): Use correct major version to update go import paths (#20140)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2023-02-23 11:23:40 +00:00
RahulGautamSingh 0f51c9f524 test: replace as with partial (#20511) 2023-02-21 10:46:29 +00:00
Tobias 9669ba320f fix(gomod): Commit updated go.mod when only go.mod changes (#20372)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
2023-02-13 14:32:59 +01:00
Alexander Birkner fbceff1397 feat(gomod): support -e option (#20199)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2023-02-07 14:00:16 +01:00
RahulGautamSingh fbb81b0623 test: replace as with partial (#20241)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2023-02-06 15:10:24 +00:00
Michael Kriese c25b02e856 feat(manager/gomod): dynamic golang install 🎉 (#19104) 2022-11-25 18:11:37 +01:00
Sergei Zharinov 3c56aeca17 refactor(tests): Use codeBlock tagged literal (#18916) 2022-11-15 08:35:36 +00:00
RahulGautamSingh c56588eaba refactor: convert PlatformmId to union (#18458) 2022-11-01 14:46:09 +00:00