Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/cli/install-tool/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { NpmVersionResolver } from '../tools/node/resolver.ts';
import { NpmBaseInstallService } from '../tools/node/utils.ts';
import { PipVersionResolver } from '../tools/python/pip.ts';
import { PipBaseInstallService } from '../tools/python/utils.ts';
import { RubyInstallService } from '../tools/ruby/index.ts';
import {
RubyBaseInstallService,
RubyGemVersionResolver,
Expand All @@ -21,6 +22,7 @@ import {
resolveVersion,
uninstallTool,
} from './index.ts';
import { V2ToolInstallService } from './install-legacy-tool.service.ts';
import { ensurePaths, rootPath } from '~test/path.ts';

vi.mock('del');
Expand Down Expand Up @@ -119,6 +121,29 @@ describe('cli/install-tool/index', () => {
).toBeUndefined();
});

test('prefers a modern service over a v2 shell tool with the same name', async () => {
const script = rootPath('usr/local/containerbase/tools/v2/ruby.sh');
await fs.writeFile(script, '');
const proto = RubyInstallService.prototype;
vi.spyOn(proto, 'needsPrepare').mockReturnValue(false);
vi.spyOn(proto, 'needsInitialize').mockReturnValue(false);
vi.spyOn(proto, 'validate').mockResolvedValue(true);
vi.spyOn(proto, 'link').mockResolvedValue();
vi.spyOn(proto, 'postInstall').mockResolvedValue();
vi.spyOn(proto, 'test').mockResolvedValue();
const ruby = vi.spyOn(proto, 'install').mockResolvedValue();
const v2 = vi.spyOn(V2ToolInstallService.prototype, 'install');

try {
expect(await installTool('ruby', '3.4.11')).toBeUndefined();
} finally {
await fs.rm(script);
}

expect(ruby).toHaveBeenCalledExactlyOnceWith('3.4.11');
expect(v2).not.toHaveBeenCalled();
});

test('rethrows a failing test for a known pip tool', async () => {
// unlike the `dummy-*` tools above, `poetry` is in the `ResolverMap`, so
// its `--version` flag is expected to work
Expand Down
3 changes: 2 additions & 1 deletion src/cli/install-tool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ import { TOOL_VERSION_RESOLVER } from './tool-version-resolver.ts';

/**
* Creates a container with all install services, including a generic one for
* every v2 shell tool without its own service.
* every v2 shell tool. The generic ones are bound last, so a modern service
* wins over a custom v2 shell tool with the same name.
*/
async function prepareInstallContainer(): Promise<Container> {
logger.trace('preparing install container');
Expand Down
2 changes: 2 additions & 0 deletions src/cli/prepare-tool/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('cli/prepare-tool/index', () => {
.spyOn(RubyPrepareService.prototype, 'prepare')
.mockResolvedValue();
const v2 = vi.spyOn(V2ToolPrepareService.prototype, 'prepare');
// keep ruby unprepared, so later tests don't initialize it
vi.spyOn(PathService.prototype, 'setPrepared').mockResolvedValue();

try {
expect(await prepareTools(['ruby'])).toBeUndefined();
Expand Down
Loading