Files
renovate/lib/modules/manager/mix/artifacts.spec.ts
Sebastian Poxhofer 4b4d14ec00 feat(manager): pass extracted constraints to updateArtifacts (#45826)
* feat(manager): pass extracted constraints to updateArtifacts

`extractedConstraints` were collected during extraction but only ever read
by `fetch.ts` for the lookup. At artifact time every manager had to derive
the same tool constraints a second time, and when the updated package file
no longer carried the constraint there was nothing to fall back to.

`generateBranchConfig()` now merges the `extractedConstraints` of all
upgrades of a branch onto the branch config, which reaches `updateArtifacts()`
through `patchConfigForArtifactsUpdate()`. `UpdateArtifactsConfig` declares
the field and documents what it contains.

The new `resolveToolConstraint()` helper implements the ladder once:
user `constraints` > an optional artifact-time derivation > the extracted
value. The derivation is ranked above the extracted value on purpose: it
reads the package files as the branch changed them, so poetry (python is an
updatable dependency there), composer, pipenv (`pipenv` can be a dev
package) and pep621 (`requires-python` is an updatable dependency) would
otherwise regress to a stale constraint. pipenv, pep621 uv/pdm, poetry and
composer are migrated to the helper and keep their derivation.

Behaviour change: these managers now use the extract-time constraint as a
last resort instead of running unconstrained, for example on lock file
maintenance where pipenv deletes `Pipfile.lock` before deriving.

`execute-post-upgrade-commands.ts` is unaffected: it reads
`upgrade.constraints` per upgrade, and the extracted values are kept in a
separate field rather than folded into `constraints`, so post-upgrade task
tool constraints still come from user config only.

Not migrated, because their constraints are never extracted, so the
fallback would be dead code: bundler (`ruby`/`bundler`), pixi (`pixi`),
pep621 uv (`required-version`) and npm's node ladder, whose last step
already reads `package.json` engines.

* refactor(manager): resolve tool constraints through resolveToolConstraint()

Every manager now obtains the constraint of a tool it runs through
`resolveToolConstraint()` instead of reading `config.constraints` itself, so
the precedence "user config, then a value derived from the updated files, then
the constraints collected during extraction" applies everywhere. The helper
treats an empty string as not set at every step and accepts the
`PostUpdateConfig` shape, whose `constraints` may be `null`.

Behaviour changes that go beyond the new fallback to extracted constraints:

- `mix` applies its hardcoded erlang default only after the extracted
  constraint, so an erlang version collected at extraction can win over it.
- `kustomize` decides `HELM_EXPERIMENTAL_OCI` from the fully resolved helm
  constraint; `generateHelmEnvs()` takes that value instead of the config.
- `npm` (yarn): an upgrade of yarn without a new value now consults the user
  constraint before deriving one from package.json or the lock file.
- The "Using <tool> constraint from config" debug lines in bundler, composer,
  copier and pip-compile are gone, as the helper is the only reader of the
  config now.

Helpers that read the config synchronously became async: bundler
`getBundlerConstraint()`, copier `getPythonVersionConstraint()` and
`getCopierVersionConstraint()`, pip-compile `get*VersionConstraint()` and
`getToolVersionConstraint()`, gomod `deriveGoToolchainConstraints()` and
`getUpdateImportPathCmds()`, mise `getMiseLockToolConstraints()`. composer
`getPhpConstraint()` is removed.

Each converted manager has a test showing the extracted constraint reaching
the executed tool, and, where a derive callback exists, that the derived value
still wins over it.

* refactor(linters): add prefer-resolve-tool-constraint rule

Reports member reads and destructuring of `constraints` and
`extractedConstraints` from a manager config in `lib/modules/manager/**`, so
that tool constraints are resolved through `resolveToolConstraint()` in
`lib/modules/manager/util.ts` only. Writes and the same properties on package
files, which extraction has to populate, are not reported. The helper itself
and spec files are exempt in `.oxlintrc.json`.

* refactor(manager): inline thin resolveToolConstraint wrappers

Drop copier/utils.ts and the pip-compile getPipToolsVersionConstraint /
getUvVersionConstraint helpers, which only forwarded to
resolveToolConstraint(). Callers now call it directly.

* docs(development): note lock file maintenance in tool constraints section

* refactor(manager): address review on tool constraint resolution

composer only runs extractConstraints() when a user constraint is missing,
via Lazy. UpdateArtifactsConfig no longer re-declares constraints and
extractedConstraints, which ToolConstraintsConfig already provides.
2026-09-14 11:09:07 +00:00

707 lines
22 KiB
TypeScript

import upath from 'upath';
import { mockDeep } from 'vitest-mock-extended';
import { envMock, mockExecAll } from '~test/exec-util.ts';
import { hostRules } from '~test/host-rules.ts';
import { env, fs, logger } from '~test/util.ts';
import { GlobalConfig } from '../../../config/global.ts';
import type {
InternalGlobalConfigOptions,
RepoGlobalConfig,
} from '../../../config/types.ts';
import type { ConstraintName } from '../../../util/exec/types.ts';
import { getPkgReleases as _getPkgReleases } from '../../datasource/index.ts';
import type { UpdateArtifactsConfig } from '../types.ts';
import { updateArtifacts } from './index.ts';
vi.mock('../../../util/exec/env.ts');
vi.mock('../../../util/fs/index.ts');
vi.mock('../../datasource/index.ts', () => mockDeep());
const getPkgReleases = vi.mocked(_getPkgReleases);
const adminConfig: RepoGlobalConfig & InternalGlobalConfigOptions = {
// `join` fixes Windows CI
localDir: upath.join('/tmp/github/some/repo'),
cacheDir: upath.join('/tmp/cache'),
containerbaseDir: upath.join('/tmp/cache/containerbase'),
binarySource: 'global',
};
// support install mode
process.env.CONTAINERBASE = 'true';
const config: UpdateArtifactsConfig = {};
const constraints: Partial<Record<ConstraintName, string>> = {
erlang: '25.0.0.0',
elixir: 'v1.13.4',
};
describe('modules/manager/mix/artifacts', () => {
beforeEach(() => {
env.getChildProcessEnv.mockReturnValue(envMock.basic);
GlobalConfig.set(adminConfig);
});
afterEach(() => {
GlobalConfig.reset();
});
it('returns null if no mix.lock found', async () => {
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '',
config,
}),
).resolves.toBeNull();
});
it('returns null if no updatedDeps were provided', async () => {
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [],
newPackageFileContent: '',
config,
}),
).resolves.toBeNull();
});
it('returns null if updatedDeps is empty', async () => {
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '',
config,
}),
).resolves.toBeNull();
});
it('returns null if unchanged', async () => {
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
const execSnapshots = mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '',
config,
}),
).resolves.toBeNull();
expect(execSnapshots).toMatchObject([
{
cmd: 'mix deps.update plug',
options: { cwd: '/tmp/github/some/repo' },
},
]);
});
it('returns null when trying to use lockFileMaintenance with no mix.lock file', async () => {
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.localPathExists.mockResolvedValueOnce(false);
fs.findLocalSiblingOrParent.mockResolvedValueOnce(null);
fs.writeLocalFile.mockClear(); // Clear the mock to ensure we can check if it's called
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config: { ...config, isLockFileMaintenance: true },
}),
).resolves.toBeNull();
expect(fs.writeLocalFile).not.toHaveBeenCalled();
});
it('returns null if no updatedDeps and no lockFileMaintenance', async () => {
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config,
}),
).resolves.toBeNull();
});
it('returns null if using lockFileMaintenance in umbrella project', async () => {
fs.getSiblingFileName.mockReturnValueOnce('apps/foo/mix.lock');
fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
await expect(
updateArtifacts({
packageFileName: 'apps/foo/mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config: { ...config, isLockFileMaintenance: true },
}),
).resolves.toBeNull();
expect(logger.logger.debug).toHaveBeenCalledWith(
'Cannot use lockFileMaintenance in an umbrella project, see https://docs.renovatebot.com/modules/manager/mix/#lockFileMaintenance',
);
});
it('uses productLinks.documentation in lockFileMaintenance umbrella log URL', async () => {
GlobalConfig.set({
...adminConfig,
productLinks: { documentation: 'https://custom.example.com/' },
});
fs.getSiblingFileName.mockReturnValueOnce('apps/foo/mix.lock');
fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
await expect(
updateArtifacts({
packageFileName: 'apps/foo/mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config: { ...config, isLockFileMaintenance: true },
}),
).resolves.toBeNull();
expect(logger.logger.debug).toHaveBeenCalledWith(
'Cannot use lockFileMaintenance in an umbrella project, see https://custom.example.com/modules/manager/mix/#lockFileMaintenance',
);
});
it('returns updated mix.lock', async () => {
GlobalConfig.set({
...adminConfig,
binarySource: 'docker',
dockerSidecarImage: 'ghcr.io/renovatebot/base-image',
});
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
// erlang
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '22.3.4.26' },
{ version: '23.1.1.0' },
{ version: '24.3.4.1' },
{ version: '24.3.4.2' },
{ version: '25.0.0.0' },
],
});
// elixir
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: 'v1.8.2' },
{ version: 'v1.13.3' },
{ version: 'v1.13.4' },
],
});
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config,
}),
).resolves.toEqual([
{
file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' },
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'docker pull ghcr.io/renovatebot/base-image' },
{ cmd: 'docker ps --filter name=renovate_sidecar -aq' },
{
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 erlang 25.0.0.0 && install-tool elixir v1.13.4 && mix deps.update plug'",
options: { cwd: '/tmp/github/some/repo' },
},
]);
});
it('uses constraints on install mode', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config: {
...config,
constraints: { erlang: '26.0.0', elixir: '1.14.5' },
},
}),
).resolves.toEqual([
{
file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' },
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 26.0.0' },
{ cmd: 'install-tool elixir 1.14.5' },
{ cmd: 'mix deps.update plug' },
]);
});
it('falls back to the extracted erlang and elixir constraints', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
// erlang
getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '24.3.4.1' }, { version: '26.2.5.4' }],
});
await updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config: {
...config,
extractedConstraints: { erlang: '24.3.4.1', elixir: '1.14.5' },
},
});
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 24.3.4.1' },
{ cmd: 'install-tool elixir 1.14.5' },
{ cmd: 'mix deps.update plug' },
]);
});
it('authenticates to private repositories in updated dependencies', async () => {
GlobalConfig.set({
...adminConfig,
binarySource: 'docker',
dockerSidecarImage: 'ghcr.io/renovatebot/base-image',
});
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
hostRules.add({
matchHost: 'https://hex.pm/api/repos/renovate_test/',
token: 'valid_test_token',
});
// erlang
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '22.3.4.26' },
{ version: '23.1.1.0' },
{ version: '24.3.4.1' },
{ version: '24.3.4.2' },
{ version: '25.0.0.0' },
],
});
// elixir
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: 'v1.8.2' },
{ version: 'v1.13.3' },
{ version: 'v1.13.4' },
],
});
const result = await updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [
{
depName: 'private_package',
packageName: 'private_package:renovate_test',
},
{
depName: 'other_package',
packageName: 'other_package:unauthorized_organization',
},
],
newPackageFileContent: '{}',
config,
});
expect(result).toEqual([
{
file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' },
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'docker ps --filter name=renovate_sidecar -aq' },
{
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 erlang 25.0.0.0 && install-tool elixir v1.13.4 && " +
'mix hex.organization auth renovate_test --key valid_test_token && ' +
"mix deps.update private_package other_package'",
options: { cwd: '/tmp/github/some/repo' },
},
]);
});
it('authenticates to private repositories configured in hostRules', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
hostRules.add({
matchHost: 'https://hex.pm/api/repos/an_organization/',
token: 'an_organization_token',
});
// unauthorized_organization token missing
hostRules.add({
matchHost: 'https://hex.pm/api/repos/unauthorized_organization/',
});
hostRules.add({
matchHost: 'https://hex.pm/api/repos/other_organization/',
token: 'other_org_token',
});
hostRules.add({
matchHost: 'https://hex.pm/api/repos/does_not_match_org/packages/',
token: 'does_not_match_org_token',
});
hostRules.add({
matchHost: 'https://example.com/api/repos/also_does_not_match_org/',
});
hostRules.add({ matchHost: 'hex.pm' });
// erlang
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: '22.3.4.26' },
{ version: '23.1.1.0' },
{ version: '24.3.4.1' },
{ version: '24.3.4.2' },
{ version: '25.0.0.0' },
],
});
// elixir
getPkgReleases.mockResolvedValueOnce({
releases: [
{ version: 'v1.8.2' },
{ version: 'v1.13.3' },
{ version: 'v1.13.4' },
],
});
const result = await updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'some_package' }],
newPackageFileContent: '{}',
config,
});
expect(result).toEqual([
{
file: { type: 'addition', path: 'mix.lock', contents: 'New mix.lock' },
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 25.0.0.0' },
{ cmd: 'install-tool elixir v1.13.4' },
{
cmd: 'mix hex.organization auth an_organization --key an_organization_token',
},
{
cmd: 'mix hex.organization auth other_organization --key other_org_token',
},
{ cmd: 'mix deps.update some_package' },
]);
});
it('quotes an organization value containing shell metacharacters', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
const execSnapshots = mockExecAll();
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
// a broad host rule matching all of hex.pm, as opposed to one scoped to
// a specific organization's repo URL
hostRules.add({ matchHost: 'hex.pm', token: 'secret_token' });
// erlang
getPkgReleases.mockResolvedValueOnce({
releases: [{ version: '25.0.0.0' }],
});
// elixir
getPkgReleases.mockResolvedValueOnce({
releases: [{ version: 'v1.13.4' }],
});
await updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [
{
depName: 'private_package',
// organization value as it would be parsed from an attacker-controlled
// `organization: "..."` field in mix.exs
packageName: 'private_package:evil --key leaked_or_arbitrary',
},
],
newPackageFileContent: '{}',
config,
});
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 25.0.0.0' },
{ cmd: 'install-tool elixir v1.13.4' },
{
cmd: "mix hex.organization auth 'evil --key leaked_or_arbitrary' --key secret_token",
},
{ cmd: 'mix deps.update private_package' },
]);
});
it('returns updated mix.lock in subdir', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.getSiblingFileName.mockReturnValueOnce('subdir/mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
const execSnapshots = mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'subdir/mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config: { ...config, constraints },
}),
).resolves.toEqual([
{
file: {
path: 'subdir/mix.lock',
type: 'addition',
contents: 'New mix.lock',
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 25.0.0.0' },
{ cmd: 'install-tool elixir v1.13.4' },
{
cmd: 'mix deps.update plug',
options: { cwd: '/tmp/github/some/repo/subdir' },
},
]);
});
it('returns updated mix.lock in umbrella project', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.getSiblingFileName.mockReturnValueOnce('apps/foo/mix.lock');
fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
const execSnapshots = mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'apps/foo/mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config: { ...config, constraints },
}),
).resolves.toEqual([
{
file: {
path: 'mix.lock',
type: 'addition',
contents: 'New mix.lock',
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 25.0.0.0' },
{ cmd: 'install-tool elixir v1.13.4' },
{
cmd: 'mix deps.update plug',
options: { cwd: '/tmp/github/some/repo' },
},
]);
});
it('supports lockFileMaintenance', async () => {
GlobalConfig.set({ ...adminConfig, binarySource: 'install' });
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('New mix.lock');
const execSnapshots = mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config: {
...config,
constraints,
isLockFileMaintenance: true,
},
}),
).resolves.toEqual([
{
file: {
path: 'mix.lock',
type: 'addition',
contents: 'New mix.lock',
},
},
]);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool erlang 25.0.0.0' },
{ cmd: 'install-tool elixir v1.13.4' },
{
cmd: 'mix deps.get',
options: { cwd: '/tmp/github/some/repo' },
},
]);
});
it('lockFileMaintenance returns null if unchanged', async () => {
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
fs.readLocalFile.mockResolvedValueOnce('Old mix.lock');
mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [],
newPackageFileContent: '{}',
config: { ...config, isLockFileMaintenance: true },
}),
).resolves.toBeNull();
});
it('catches write errors', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.writeLocalFile.mockImplementationOnce(() => {
throw new Error('not found');
});
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config,
}),
).resolves.toEqual([
{ artifactError: { fileName: 'mix.lock', stderr: 'not found' } },
]);
});
it('catches exec errors', async () => {
fs.readLocalFile.mockResolvedValueOnce('Current mix.lock');
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
mockExecAll(new Error('exec-error'));
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config,
}),
).resolves.toEqual([
{ artifactError: { fileName: 'mix.lock', stderr: 'exec-error' } },
]);
});
it('detects read errors', async () => {
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.localPathExists.mockResolvedValueOnce(true);
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config,
}),
).resolves.toEqual([
{
artifactError: {
fileName: 'mix.lock',
stderr: 'Error reading mix.lock',
},
},
]);
});
it('detects read errors (umbrella)', async () => {
fs.getSiblingFileName.mockReturnValueOnce('apps/foo/mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.localPathExists.mockResolvedValueOnce(false);
fs.findLocalSiblingOrParent.mockResolvedValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.localPathExists.mockResolvedValueOnce(true);
await expect(
updateArtifacts({
packageFileName: 'apps/foo/mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: '{}',
config,
}),
).resolves.toEqual([
{
artifactError: {
fileName: 'mix.lock',
stderr: 'Error reading mix.lock',
},
},
]);
});
it("handles updates and doesn't try to create mix.lock file if it doesn't exist", async () => {
fs.getSiblingFileName.mockReturnValueOnce('mix.lock');
fs.readLocalFile.mockResolvedValueOnce(null);
fs.localPathExists.mockResolvedValueOnce(false);
fs.findLocalSiblingOrParent.mockResolvedValueOnce(null);
const execSnapshots = mockExecAll();
await expect(
updateArtifacts({
packageFileName: 'mix.exs',
updatedDeps: [{ depName: 'plug' }],
newPackageFileContent: 'New mix.exs',
config,
}),
).resolves.toBeNull();
expect(execSnapshots).toHaveLength(0);
expect(fs.writeLocalFile).toHaveBeenCalledExactlyOnceWith(
'mix.exs',
'New mix.exs',
);
});
});