diff --git a/tests/integration/chroot-package-managers.test.ts b/tests/integration/chroot-package-managers.test.ts index 54de5c0f..bed977dc 100644 --- a/tests/integration/chroot-package-managers.test.ts +++ b/tests/integration/chroot-package-managers.test.ts @@ -349,4 +349,63 @@ describe('Chroot Package Manager Support', () => { expect(result.stdout).toContain('module test'); }, 120000); }); + + // ---------- Package Installation ---------- + describe('Package Installation', () => { + test('should install a Python package via pip and verify import', async () => { + const result = await runner.runWithSudo( + 'PIPDIR=$(mktemp -d) && ' + + 'pip3 install --no-cache-dir --target $PIPDIR requests 2>&1 && ' + + 'PYTHONPATH=$PIPDIR python3 -c "import requests; print(requests.__version__)" && ' + + 'rm -rf $PIPDIR', + { + allowDomains: ['pypi.org', 'files.pythonhosted.org'], + logLevel: 'debug', + timeout: 120000, + } + ); + + expect(result).toSucceed(); + const lines = result.stdout.split('\n').map(l => l.trim()).filter(l => l.length > 0); + const lastLine = lines[lines.length - 1] || ''; + expect(lastLine).toMatch(/^\d+\.\d+\.\d+$/); + }, 180000); + + test('should install an npm package and verify require', async () => { + const result = await runner.runWithSudo( + 'NPMDIR=$(mktemp -d) && cd $NPMDIR && npm init -y 2>&1 && ' + + 'npm install chalk@4 2>&1 && ' + + 'NODE_PATH=$NPMDIR/node_modules node -e "require(\'chalk\')" && echo "npm_install_ok" && ' + + 'rm -rf $NPMDIR', + { + allowDomains: ['registry.npmjs.org'], + logLevel: 'debug', + timeout: 120000, + } + ); + + expect(result).toSucceed(); + expect(result.stdout).toContain('npm_install_ok'); + }, 180000); + + test('should build a Rust project with a dependency via cargo', async () => { + const result = await runner.runWithSudo( + 'TESTDIR=$(mktemp -d) && cd $TESTDIR && ' + + 'CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse ' + + 'cargo init --name awftest 2>&1 && ' + + 'echo \'cfg-if = "1"\' >> Cargo.toml && ' + + 'CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse ' + + 'cargo build 2>&1 && echo "cargo_build_ok"; ' + + 'EC=$?; rm -rf $TESTDIR; exit $EC', + { + allowDomains: ['crates.io', 'static.crates.io', 'index.crates.io'], + logLevel: 'debug', + timeout: 120000, + } + ); + + expect(result).toSucceed(); + expect(result.stdout).toContain('cargo_build_ok'); + }, 180000); + }); });