Files
renovate/lib/modules/manager/pep621/artifacts.spec.ts
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

144 lines
4.2 KiB
TypeScript

import { codeBlock } from 'common-tags';
import upath from 'upath';
import { mockDeep } from 'vitest-mock-extended';
import { mockExecAll } from '~test/exec-util.ts';
import { fs } from '~test/util.ts';
import { GlobalConfig } from '../../../config/global.ts';
import type {
InternalGlobalConfigOptions,
RepoGlobalConfig,
} from '../../../config/types.ts';
import { getPkgReleases as _getPkgReleases } from '../../datasource/index.ts';
import type { UpdateArtifactsConfig } from '../types.ts';
import { updateArtifacts } from './artifacts.ts';
vi.mock('../../../util/fs/index.ts');
vi.mock('../../datasource/index.ts', () => mockDeep());
const getPkgReleases = vi.mocked(_getPkgReleases);
const config: UpdateArtifactsConfig = {};
const adminConfig: RepoGlobalConfig & InternalGlobalConfigOptions = {
localDir: upath.join('/tmp/github/some/repo'),
cacheDir: upath.join('/tmp/cache'),
containerbaseDir: upath.join('/tmp/cache/containerbase'),
binarySource: 'global',
};
describe('modules/manager/pep621/artifacts', () => {
describe('updateArtifacts()', () => {
it('return null if all processors returns are empty', async () => {
const updatedDeps = [
{
packageName: 'dep1',
},
];
const result = await updateArtifacts({
packageFileName: 'pyproject.toml',
newPackageFileContent: '',
config,
updatedDeps,
});
expect(result).toBeNull();
});
it('return artifact error if newPackageFile content is not valid', async () => {
const updatedDeps = [
{
packageName: 'dep1',
},
];
const result = await updateArtifacts({
packageFileName: 'pyproject.toml',
newPackageFileContent: '--test string--',
config,
updatedDeps,
});
expect(result).toEqual([
{
artifactError: { stderr: 'Failed to parse new package file content' },
},
]);
});
it('return processor result', async () => {
const execSnapshots = mockExecAll();
GlobalConfig.set({
...adminConfig,
binarySource: 'docker',
dockerSidecarImage: 'ghcr.io/renovatebot/base-image',
});
fs.getSiblingFileName.mockReturnValueOnce('pdm.lock');
fs.readLocalFile.mockResolvedValueOnce('old test content');
fs.readLocalFile.mockResolvedValueOnce('new test content');
// python
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '3.7.1' },
{ version: '3.8.1' },
{ version: '3.11.2' },
],
});
// pdm
getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v2.6.1' }, { version: 'v2.5.0' }],
});
const updatedDeps = [{ packageName: 'dep1' }];
const result = await updateArtifacts({
packageFileName: 'pyproject.toml',
newPackageFileContent: codeBlock`
[project]
name = "pdm"
dynamic = ["version"]
requires-python = "<3.9"
`,
config: {},
updatedDeps,
});
expect(result).toEqual([
{
file: {
contents: 'new test content',
path: 'pdm.lock',
type: 'addition',
},
},
]);
expect(execSnapshots).toMatchObject([
{
cmd: 'docker pull ghcr.io/renovatebot/base-image',
options: {},
},
{
cmd: 'docker ps --filter name=renovate_sidecar -aq',
options: {},
},
{
cmd:
'docker run --rm --name=renovate_sidecar --label=renovate_child ' +
'-v "/tmp/github/some/repo":"/tmp/github/some/repo" ' +
'-v "/tmp/cache":"/tmp/cache" ' +
'-e CI ' +
'-e CONTAINERBASE_CACHE_DIR ' +
'-w "/tmp/github/some/repo" ' +
'ghcr.io/renovatebot/base-image ' +
"bash -l -c '" +
'install-tool python 3.8.1 ' +
'&& ' +
'install-tool pdm v2.5.0 ' +
'&& ' +
'pdm update --no-sync --update-eager dep1' +
"'",
options: {
cwd: '/tmp/github/some/repo',
env: {
CONTAINERBASE_CACHE_DIR: '/tmp/cache/containerbase',
},
},
},
]);
});
});
});