fix(tests): Use unique test run IDs and add S3 cleanup in test helpers to avoid cross-run conflicts

This commit is contained in:
2025-11-27 12:41:38 +00:00
parent 58a21a6bbb
commit eb91a3f75b
5 changed files with 151 additions and 49 deletions

View File

@@ -6,7 +6,7 @@
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { tapNodeTools } from '@git.zone/tstest/tapbundle_serverside';
import { SmartRegistry } from '../ts/index.js';
import { createTestRegistry, createTestTokens, createPythonWheel, createPythonSdist } from './helpers/registry.js';
import { createTestRegistry, createTestTokens, createPythonWheel, createPythonSdist, generateTestRunId } from './helpers/registry.js';
import type { IRequestContext, IResponse } from '../ts/core/interfaces.core.js';
import * as http from 'http';
import * as url from 'url';
@@ -24,6 +24,10 @@ let pipHome: string;
let hasPip = false;
let hasTwine = false;
// Unique test run ID to avoid conflicts between test runs
const testRunId = generateTestRunId();
const testPackageName = `test-pypi-pkg-${testRunId}`;
/**
* Create HTTP server wrapper around SmartRegistry
*/
@@ -347,9 +351,8 @@ tap.test('PyPI CLI: should upload wheel with twine', async () => {
return;
}
const packageName = 'test-pypi-pkg';
const version = '1.0.0';
const wheelPath = await createTestWheelFile(packageName, version, testDir);
const wheelPath = await createTestWheelFile(testPackageName, version, testDir);
expect(fs.existsSync(wheelPath)).toEqual(true);
@@ -369,9 +372,7 @@ tap.test('PyPI CLI: should verify package in simple index', async () => {
return;
}
const packageName = 'test-pypi-pkg';
const response = await fetch(`${registryUrl}/pypi/simple/${packageName}/`);
const response = await fetch(`${registryUrl}/pypi/simple/${testPackageName}/`);
expect(response.status).toEqual(200);
const html = await response.text();
@@ -384,9 +385,8 @@ tap.test('PyPI CLI: should upload sdist with twine', async () => {
return;
}
const packageName = 'test-pypi-pkg';
const version = '1.1.0';
const sdistPath = await createTestSdistFile(packageName, version, testDir);
const sdistPath = await createTestSdistFile(testPackageName, version, testDir);
expect(fs.existsSync(sdistPath)).toEqual(true);
@@ -406,9 +406,7 @@ tap.test('PyPI CLI: should list all versions in simple index', async () => {
return;
}
const packageName = 'test-pypi-pkg';
const response = await fetch(`${registryUrl}/pypi/simple/${packageName}/`);
const response = await fetch(`${registryUrl}/pypi/simple/${testPackageName}/`);
expect(response.status).toEqual(200);
const html = await response.text();
@@ -422,14 +420,12 @@ tap.test('PyPI CLI: should get JSON metadata', async () => {
return;
}
const packageName = 'test-pypi-pkg';
const response = await fetch(`${registryUrl}/pypi/pypi/${packageName}/json`);
const response = await fetch(`${registryUrl}/pypi/pypi/${testPackageName}/json`);
expect(response.status).toEqual(200);
const metadata = await response.json();
expect(metadata.info).toBeDefined();
expect(metadata.info.name).toEqual(packageName);
expect(metadata.info.name).toEqual(testPackageName);
expect(metadata.releases).toBeDefined();
expect(metadata.releases['1.0.0']).toBeDefined();
});
@@ -445,7 +441,7 @@ tap.test('PyPI CLI: should download package with pip', async () => {
// Download (not install) the package
const result = await runPipCommand(
`download test-pypi-pkg==1.0.0 --dest "${downloadDir}" --no-deps`,
`download ${testPackageName}==1.0.0 --dest "${downloadDir}" --no-deps`,
testDir
);
console.log('pip download output:', result.stdout);
@@ -457,14 +453,17 @@ tap.test('PyPI CLI: should download package with pip', async () => {
});
tap.test('PyPI CLI: should search for packages via API', async () => {
const packageName = 'test-pypi-pkg';
if (!hasTwine) {
console.log('Skipping - twine not available (no packages uploaded)');
return;
}
// Use the JSON API to search/list
const response = await fetch(`${registryUrl}/pypi/pypi/${packageName}/json`);
const response = await fetch(`${registryUrl}/pypi/pypi/${testPackageName}/json`);
expect(response.status).toEqual(200);
const metadata = await response.json();
expect(metadata.info.name).toEqual(packageName);
expect(metadata.info.name).toEqual(testPackageName);
});
tap.test('PyPI CLI: should fail upload without auth', async () => {
@@ -473,9 +472,9 @@ tap.test('PyPI CLI: should fail upload without auth', async () => {
return;
}
const packageName = 'unauth-pkg';
const unauthPkgName = `unauth-pkg-${testRunId}`;
const version = '1.0.0';
const wheelPath = await createTestWheelFile(packageName, version, testDir);
const wheelPath = await createTestWheelFile(unauthPkgName, version, testDir);
// Create a pypirc without proper credentials
const badPypircPath = path.join(testDir, '.bad-pypirc');