Fix tests for tag removal and version behavior

- Fix upload response to return actual version (not requested version)
  when artifact already has a version in the package
- Update ref_count tests to use multiple packages (one version per
  artifact per package design constraint)
- Remove allow_public_internet references from upstream caching tests
- Update consistency check test to not assert global system health
- Add versions field to artifact schemas
- Fix dependencies resolution to handle removed tag constraint
This commit is contained in:
Mondo Diaz
2026-02-03 15:35:44 -06:00
parent 86c95bea2b
commit 308057784e
10 changed files with 148 additions and 102 deletions

View File

@@ -677,7 +677,7 @@ def resolve_dependencies(
else:
# Try to find artifact by version
resolved = _resolve_dependency_to_artifact(
db, project_name, package_name, ref, ref
db, project_name, package_name, ref
)
if not resolved:
raise DependencyNotFoundError(project_name, package_name, ref)

View File

@@ -3433,6 +3433,10 @@ def upload_artifact(
pkg_version = _create_or_update_version(
db, package.id, storage_result.sha256, detected_version, version_source, user_id
)
# Use the actual version from the returned record (may differ if artifact
# already had a version in this package)
detected_version = pkg_version.version
version_source = pkg_version.version_source
except HTTPException as e:
# Version conflict (409) - log but don't fail the upload
if e.status_code == 409:
@@ -4994,6 +4998,19 @@ def get_artifact(artifact_id: str, db: Session = Depends(get_db)):
if not artifact:
raise HTTPException(status_code=404, detail="Artifact not found")
# Get all versions referencing this artifact
versions_data = []
versions = db.query(PackageVersion).filter(PackageVersion.artifact_id == artifact_id).all()
for ver in versions:
package = db.query(Package).filter(Package.id == ver.package_id).first()
if package:
project = db.query(Project).filter(Project.id == package.project_id).first()
versions_data.append({
"version": ver.version,
"package_name": package.name,
"project_name": project.name if project else "unknown",
})
return ArtifactDetailResponse(
id=artifact.id,
sha256=artifact.id, # SHA256 hash is the artifact ID
@@ -5007,6 +5024,7 @@ def get_artifact(artifact_id: str, db: Session = Depends(get_db)):
created_by=artifact.created_by,
ref_count=artifact.ref_count,
format_metadata=artifact.format_metadata,
versions=versions_data,
)

View File

@@ -210,10 +210,10 @@ class ArtifactProvenanceResponse(BaseModel):
# Usage statistics
upload_count: int
# References
packages: List[Dict[str, Any]] # List of {project_name, package_name, tag_names}
tags: List[
packages: List[Dict[str, Any]] # List of {project_name, package_name, versions}
versions: List[
Dict[str, Any]
] # List of {project_name, package_name, tag_name, created_at}
] # List of {project_name, package_name, version, created_at}
# Upload history
uploads: List[Dict[str, Any]] # List of upload events
@@ -236,6 +236,7 @@ class ArtifactDetailResponse(BaseModel):
created_by: str
ref_count: int
format_metadata: Optional[Dict[str, Any]] = None
versions: List[Dict[str, Any]] = [] # List of {version, package_name, project_name}
class Config:
from_attributes = True
@@ -566,6 +567,7 @@ class ProjectStatsResponse(BaseModel):
project_id: str
project_name: str
package_count: int
version_count: int
artifact_count: int
total_size_bytes: int
upload_count: int
@@ -580,6 +582,7 @@ class PackageStatsResponse(BaseModel):
package_id: str
package_name: str
project_name: str
version_count: int
artifact_count: int
total_size_bytes: int
upload_count: int
@@ -598,6 +601,7 @@ class ArtifactStatsResponse(BaseModel):
storage_savings: int # (ref_count - 1) * size
projects: List[str] # Projects using this artifact
packages: List[str] # Packages using this artifact
versions: List[Dict[str, Any]] = [] # List of {version, package_name, project_name}
first_uploaded: Optional[datetime] = None
last_referenced: Optional[datetime] = None