Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(codeartifact): add UpdatePackageVersionsStatus and DisposePackageVersions (#6435)

Priamo Germosen3053b35b84b9
diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.md
index 66e5cfb1a6..892883073a 100644
--- a/docs/services/codeartifact.md
+++ b/docs/services/codeartifact.md
@@ -48,6 +48,8 @@ behind them yet.
| `ListPackageVersions` | Lists a package's versions with status, revision, and origin, paginated and sorted most recently published first; `defaultDisplayVersion` is `dist-tags.latest` for npm, the most recently published version otherwise. |
| `GetPackageVersionReadme` | Returns the readme text for a package version; `npm`, `pypi`, and `nuget` only, matching AWS's own restriction for this action. |
| `CopyPackageVersions` | Copies one or more versions of a package from one repository to another in the same domain. |
+| `UpdatePackageVersionsStatus` | Moves one or more versions of a package to `Published`, `Unlisted`, or `Archived`; all-or-nothing per call, with `versionRevisions`/`expectedStatus` as optional preconditions. |
+| `DisposePackageVersions` | Permanently deletes a package version's assets and sets its status to `Disposed`; irreversible, and shares `UpdatePackageVersionsStatus`'s all-or-nothing batch semantics. |
| `TagResource` | Adds or updates tags on a domain or repository ARN. |
| `UntagResource` | Removes tags by key from a domain or repository ARN. |
| `ListTagsForResource` | Lists the tags on a domain or repository ARN. |
@@ -254,12 +256,21 @@ state.
that is not the caller's own account looks up that account's domain/repository with no
trust-policy or permissions-policy enforcement, consistent with Floci's IAM enforcement being
opt-in elsewhere, but worth knowing if you rely on domain-sharing semantics.
-- **Package management beyond publish/describe/get-asset/list-assets/list-versions isn't
- implemented.** `ListPackages`, `DeletePackageVersions`, `DisposePackageVersions`, and
- `UpdatePackageVersionsStatus` don't exist yet; the only way to move a version from `Unfinished`
- to `Published` today is a follow-up `PublishPackageVersion` call that omits the `unfinished`
- flag. Every version `ListPackageVersions` reports is `Published` or `Unfinished` for this same
- reason: nothing yet produces `Unlisted`, `Archived`, or `Disposed`.
+- **`ListPackages` and `DeletePackageVersions` aren't implemented.** Every other package-version
+ lifecycle action is: a version can be moved to `Unlisted`/`Archived`/`Published` with
+ `UpdatePackageVersionsStatus`, or to `Disposed` (assets permanently deleted) with
+ `DisposePackageVersions`. The only way to move a version out of `Unfinished` today is still
+ either a follow-up `PublishPackageVersion` call that omits the `unfinished` flag, or
+ `UpdatePackageVersionsStatus` itself.
+- **A container-backed (`maven`/`npm`/`pypi`/`nuget`) version's status override does not survive a
+ Floci restart.** It's kept in memory only, for the same reason the byte-count and readme
+ bookkeeping those formats already need are: the sidecar content it describes doesn't survive a
+ restart either (no volume attached, removed on shutdown), so persisting the override alone would
+ leave it answering for a version that, after a restart, no longer exists anywhere real. A
+ restart effectively un-disposes/un-archives every container-backed version back to `Published`
+ (or, for one `DisposePackageVersions` already deleted the real assets of, back to not existing at
+ all once the sidecar itself restarts empty). `generic`'s status has no such gap: it's stored
+ directly on the version's own persisted record.
- **`CopyPackageVersions` has no full cross-call rollback on a mid-copy sidecar failure.**
(`generic`, `maven`, `npm`, `pypi`, and `nuget` are all supported — matching real AWS, which
places no `format` restriction on this action at all, unlike `PublishPackageVersion`'s own
diff --git a/docs/services/index.md b/docs/services/index.md
index 3ccce6325c..62011ff94e 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -124,7 +124,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AWS Backup](backup.md) | `/backup-vaults/*`, `/logically-air-gapped-backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 35 |
| [AWS FIS](fis.md) | `/experimentTemplates/*`, `/experiments/*`, `/actions/*`, `/targetResourceTypes/*`, `/safetyLevers/*`, `/tags/*` | REST JSON | 26 |
| [CodeGuru Reviewer](codegurureviewer.md) | `/associations`, `/associations/{associationArn}`, `/tags/*` | REST JSON | 7 |
-| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/package`, `/v1/package/version*`, `/v1/tag*`, `/v1/authorization-token`, `/codeartifact/maven/*`, `/codeartifact/npm/*`, `/codeartifact/pypi/*` | REST JSON | 33 |
+| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/package`, `/v1/package/version*`, `/v1/tag*`, `/v1/authorization-token`, `/codeartifact/maven/*`, `/codeartifact/npm/*`, `/codeartifact/pypi/*` | REST JSON | 35 |
| [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*` | REST XML | 50 |
| [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 27 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 22 |
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/Digests.java b/src/main/java/io/github/hectorvent/floci/core/common/Digests.java
index a07226f223..69a3c27a96 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/Digests.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/Digests.java
@@ -19,6 +19,11 @@ public final class Digests {
}
}
+ /** The MD5 digest of {@code data} as lowercase hex. */
+ public static String md5Hex(byte[] data) {
+ return HexFormat.of().formatHex(md5(data));
+ }
+
public static byte[] sha1(byte[] data) {
try {
return MessageDigest.getInstance("SHA-1").digest(data);
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java
index f43536c83e..83ba89248c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java
@@ -541,6 +541,58 @@ public class CodeArtifactController {
return ok(response);
}
+ @POST
+ @Path("/v1/package/versions/update_status")
+ public Response updatePackageVersionsStatus(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("format") String format,
+ @QueryParam("namespace") String namespace,
+ @QueryParam("package") String packageName, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(region,
+ domain, domainOwner, repository, format, namespace, packageName,
+ readStringArray(req.get("versions"), "versions"), readStringMap(req.get("versionRevisions")),
+ req.path("expectedStatus").asText(null), req.path("targetStatus").asText(null));
+ return ok(packageVersionStatusChangeResponse(result));
+ }
+
+ @POST
+ @Path("/v1/package/versions/dispose")
+ public Response disposePackageVersions(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("format") String format,
+ @QueryParam("namespace") String namespace,
+ @QueryParam("package") String packageName, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.disposePackageVersions(region, domain,
+ domainOwner, repository, format, namespace, packageName,
+ readStringArray(req.get("versions"), "versions"), readStringMap(req.get("versionRevisions")),
+ req.path("expectedStatus").asText(null));
+ return ok(packageVersionStatusChangeResponse(result));
+ }
+
+ private ObjectNode packageVersionStatusChangeResponse(CodeArtifactService.PackageVersionStatusChangeResult
+ result) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ObjectNode successfulVersions = response.putObject("successfulVersions");
+ result.successfulVersions().forEach((version, outcome) -> {
+ ObjectNode node = successfulVersions.putObject(version);
+ node.put("revision", outcome.revision());
+ node.put("status", outcome.status());
+ });
+ ObjectNode failedVersions = response.putObject("failedVersions");
+ result.failedVersions().forEach((version, failure) -> {
+ ObjectNode node = failedVersions.putObject(version);
+ node.put("errorCode", failure.errorCode());
+ node.put("errorMessage", failure.errorMessage());
+ });
+ return response;
+ }
+
// -------------------------------------------------------------------- tags
@POST
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenController.java
index 42719cbe12..5ed767262c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenController.java
@@ -65,6 +65,26 @@ public class CodeArtifactMavenController {
}
MavenRequestScope scope = requireScope(headers, domain, repository);
Optional<String[]> coordinate = parseNamespaceAndPackageName(gav);
+ // Raised by hectorvent's review: a real mvn deploy to a coordinate
+ // updatePackageVersionsStatus/disposePackageVersions left Archived or Disposed must be
+ // refused outright, the same way PublishPackageVersion already refuses it for the generic
+ // format, not accepted and then have forgetContainerBackedStatusOverride below silently
+ // un-block it afterward. Checked before the real write, not after; the version element is
+ // null for a bare maven-metadata.xml PUT (see this coordinate's own javadoc), which never
+ // represents a specific version to block either way. The returned revision (or null) is
+ // held onto below: raised by Greptile's review, a concurrent status change landing between
+ // this check and the clear below must not be erased by it (see
+ // CodeArtifactService#forgetContainerBackedStatusOverrideIfUnchanged's own javadoc).
+ String beforeRevision = null;
+ if (coordinate.filter(c -> c[2] != null).isPresent()) {
+ String[] c = coordinate.get();
+ try {
+ beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(scope.region(), domain,
+ scope.owner(), repository, "maven", c[0], c[1], c[2]);
+ } catch (AwsException e) {
+ return Response.status(409).entity(e.getMessage()).build();
+ }
+ }
// Snapshotted before the real write, not after: see
// CodeArtifactService#currentContainerBackedPackageFence's own javadoc for why the order
// matters.
@@ -74,17 +94,31 @@ public class CodeArtifactMavenController {
if (outcome.wroteNewContent()) {
coordinate.ifPresent(c -> service.recordContainerBackedAssetBytes(scope.region(), domain, scope.owner(),
repository, "maven", c[0], c[1], content.length, fenceSnapshot.get()));
+ // Found by Qodo review: a real mvn deploy to a coordinate updatePackageVersionsStatus/
+ // disposePackageVersions previously archived or disposed would still have its fresh
+ // content blocked by that stale override, since nothing before this cleared it for a
+ // native publish the way copyPackageVersions now does for its own overwrite path. The
+ // version element is null for a bare maven-metadata.xml PUT (see this coordinate's own
+ // javadoc), which never represents a specific version to clear an override for anyway.
+ // By this point the guard above has already refused an Archived/Disposed coordinate,
+ // so the only override left to clear here is Unlisted (or none), and only if it is
+ // still exactly what the guard above saw.
+ String beforeRevisionFinal = beforeRevision;
+ coordinate.filter(c -> c[2] != null).ifPresent(c -> service.forgetContainerBackedStatusOverrideIfUnchanged(
+ scope.region(), domain, scope.owner(), repository, "maven", c[0], c[1], c[2],
+ beforeRevisionFinal));
}
return Response.status(outcome.status()).build();
}
/**
* Splits a GAV path ({@code <groupId-as-slashes>/<artifactId>/<version>/<filename>}, the real
- * Maven repository layout) into CodeArtifact's Maven namespace (dot-joined groupId) and
- * package name (artifactId), the inverse of what {@code ReposiliteSidecarClient}'s own
- * namespace/packageName-aware methods already build. Only ever used for byte accounting, a
- * side channel that must never fail a publish that would otherwise succeed, so a path with too
- * few segments to be a well-formed GAV is reported as unknown rather than thrown.
+ * Maven repository layout) into CodeArtifact's Maven namespace (dot-joined groupId), package
+ * name (artifactId), and version: the inverse of what {@code ReposiliteSidecarClient}'s own
+ * namespace/packageName-aware methods already build. The namespace/packageName pair is used
+ * for byte accounting, a side channel that must never fail a publish that would otherwise
+ * succeed, so a path with too few segments to be a well-formed GAV is reported as unknown
+ * rather than thrown.
*
* <p>{@code maven-metadata.xml} (and its {@code .sha1}/{@code .md5}/{@code .sha256} checksum
* siblings) needs its own rule, not the ordinary one below: every real {@code mvn deploy} also
@@ -94,23 +128,27 @@ public class CodeArtifactMavenController {
* alone can't tell the two apart; the filename itself can, and already does, via
* {@link #isMavenMetadataFile}. Once that is known, the artifactId is always the segment
* directly before it, no version segment in between, so this takes one fewer trailing segment
- * than the ordinary rule does. A versioned snapshot's own {@code .../<version>/
- * maven-metadata.xml} is the one real path this still gets slightly wrong, reading the version
+ * than the ordinary rule does, and the returned version is {@code null} rather than guessed.
+ * A versioned snapshot's own {@code .../<version>/maven-metadata.xml} is the one real path
+ * this still gets slightly wrong for the namespace/packageName pair, reading the version
* string itself as the package name instead of skipping over it; accepted rather than chased
- * further, since this is a byte count summed at the domain level only (never read back by
- * package), and this one rare case still adds its real byte count to the right total under a
- * harmless, if misnamed, bucket nothing else will ever look up by that name.
+ * further, since that pair is only ever used for a byte count summed at the domain level
+ * (never read back by package), and this one rare case still adds its real byte count to the
+ * right total under a harmless, if misnamed, bucket nothing else will ever look up by that
+ * name. The version element has no such approximation to make: it is {@code null} exactly
+ * when there genuinely is no version in the path.
*/
private static Optional<String[]> parseNamespaceAndPackageName(String gav) {
String[] segments = gav.split("/");
- int packageNameIndex = isMavenMetadataFile(segments[segments.length - 1])
- ? segments.length - 2 : segments.length - 3;
+ boolean metadataFile = isMavenMetadataFile(segments[segments.length - 1]);
+ int packageNameIndex = metadataFile ? segments.length - 2 : segments.length - 3;
if (packageNameIndex < 1) {
return Optional.empty();
}
String packageName = segments[packageNameIndex];
String namespace = String.join(".", Arrays.asList(segments).subList(0, packageNameIndex));
- return Optional.of(new String[] {namespace, packageName});
+ String version = metadataFile ? null : segments[packageNameIndex + 1];
+ return Optional.of(new String[] {namespace, packageName, version});
}
private static boolean isMavenMetadataFile(String filename) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
index 3dbeb66350..8591b2a4f9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlane.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.codeartifact;
+import com.fasterxml.jackson.core.exc.StreamConstraintsException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
@@ -285,7 +286,8 @@ public class CodeArtifactNpmDataPlane {
}
String backendBaseUrl = readyResult.result();
vertx.<RepublishCheck>executeBlocking(promise ->
- promise.complete(checkRepublish(backendBaseUrl, npmRequest, path)),
+ promise.complete(checkRepublish(backendBaseUrl, npmRequest, path,
+ scope)),
false)
.onComplete(checkResult -> {
if (context.response().closed()) {
@@ -294,7 +296,28 @@ public class CodeArtifactNpmDataPlane {
}
RepublishCheck check = checkResult.succeeded() ? checkResult.result()
: new RepublishCheck(false, 0L,
- packageIdentityFromPath(npmRequest.rest()), Map.of());
+ packageIdentityFromPath(npmRequest.rest()), Map.of(),
+ null, Map.of());
+ // Raised by hectorvent's review: a real npm publish to a
+ // coordinate updatePackageVersionsStatus/
+ // disposePackageVersions left Archived or Disposed must be
+ // refused outright, the same way PublishPackageVersion
+ // already refuses it for the generic format, not accepted
+ // and then have forgetContainerBackedStatusOverride below
+ // silently un-block it afterward. Checked ahead of the
+ // idempotent-republish shortcut too: that shortcut only
+ // ever matches when Verdaccio's own stored content is
+ // still byte-identical, which archiving (unlike disposing)
+ // never changes, and the User Guide draws no
+ // byte-identical exception for either status.
+ if (check.blockedMessage() != null) {
+ context.response().putHeader("Content-Type", "application/json")
+ .setStatusCode(409)
+ .end("{\"error\":\"forbidden\",\"reason\":\""
+ + check.blockedMessage() + "\"}");
+ finish.run();
+ return;
+ }
if (check.confirmed()) {
// "ok" is a message string in a real Verdaccio response
// (e.g. "created new package"), not a boolean; matching
@@ -333,7 +356,8 @@ public class CodeArtifactNpmDataPlane {
reopened.result(), scope, npmRequest.domain(),
npmRequest.repository(), check.identity(),
check.totalAttachmentBytes(), fenceSnapshot,
- check.readmeByVersion());
+ check.readmeByVersion(),
+ check.beforeRevisionByVersion());
});
});
});
@@ -442,25 +466,83 @@ public class CodeArtifactNpmDataPlane {
* into {@code ""}, the same empty-string answer pypi's own upload path already records when
* twine sends no {@code description} field, so a published version without a readme is never
* mistaken for one that was never published at all.
+ *
+ * <p>{@code blockedMessage} is non-null exactly when some version in the envelope is Archived
+ * or Disposed (see {@link CodeArtifactService#requireContainerBackedVersionNotArchivedOrDisposed}),
+ * found while this check already has every version in hand; the caller refuses the whole
+ * publish on it rather than reaching {@code confirmed} or forwarding anything, since the User
+ * Guide blocks both statuses unconditionally, byte-identical content included.
+ *
+ * <p>{@code beforeRevisionByVersion} carries what {@link
+ * CodeArtifactService#requireContainerBackedVersionNotArchivedOrDisposed} returned for each
+ * version while that same guard ran (the same key set as {@code readmeByVersion}, minus any
+ * version a {@code blockedMessage} short-circuited before its own turn); the caller passes it
+ * straight into {@link CodeArtifactService#forgetContainerBackedStatusOverrideIfUnchanged} once
+ * its own forward succeeds, so a status change that lands after this check ran is never erased
+ * (Greptile review).
*/
private record RepublishCheck(boolean confirmed, long totalAttachmentBytes, PackageIdentity identity,
- Map<String, String> readmeByVersion) {}
+ Map<String, String> readmeByVersion, String blockedMessage, Map<String, String> beforeRevisionByVersion) {}
- private RepublishCheck checkRepublish(String backendBaseUrl, NpmRequest npmRequest, String spoolPath) {
+ private RepublishCheck checkRepublish(String backendBaseUrl, NpmRequest npmRequest, String spoolPath,
+ AuthorizationTokenScope scope) {
PackageIdentity identity = packageIdentityFromPath(npmRequest.rest());
NpmPublishEnvelopeScanner.Envelope envelope;
try (InputStream in = new BufferedInputStream(Files.newInputStream(Path.of(spoolPath)))) {
envelope = NpmPublishEnvelopeScanner.scan(in);
+ } catch (StreamConstraintsException e) {
+ LOG.debugv(e, "Publish for {0}/{1} is not a confirmable republish: {2}",
+ npmRequest.domain(), npmRequest.repository(), e.getMessage());
+ // Raised by Greptile's review: forwarding unconditionally on any scan failure, as
+ // the catch block below still does for anything else, would also skip the
+ // Archived/Disposed guard entirely for a publish that failed only
+ // NpmPublishEnvelopeScanner#scan's own stricter limit (an oversized readme, see
+ // NpmPublishEnvelopeScanner#scanLeniently's own javadoc), not because anything is
+ // actually wrong with it; StreamConstraintsException is specifically that case, not
+ // genuinely malformed JSON (a plain JsonParseException, handled below exactly as
+ // before). That second, far-more-tolerant pass recovers just the version names so the
+ // guard can still run; if even that fails, there is no safe way left to know what
+ // this publish names, so it is refused outright instead of silently forwarded with no
+ // guard having run.
+ Set<String> versionsFromLenientScan;
+ try (InputStream in = new BufferedInputStream(Files.newInputStream(Path.of(spoolPath)))) {
+ versionsFromLenientScan = NpmPublishEnvelopeScanner.scanLeniently(in).versions().keySet();
+ } catch (IOException lenientFailure) {
+ return new RepublishCheck(false, 0L, identity, Map.of(),
+ "Could not determine which version(s) this publish names.", Map.of());
+ }
+ for (String version : versionsFromLenientScan) {
+ try {
+ service.requireContainerBackedVersionNotArchivedOrDisposed(scope.region(), npmRequest.domain(),
+ scope.owner(), npmRequest.repository(), "npm", identity.namespace(),
+ identity.packageName(), version);
+ } catch (AwsException blocked) {
+ return new RepublishCheck(false, 0L, identity, Map.of(), blocked.getMessage(), Map.of());
+ }
+ }
+ return new RepublishCheck(false, 0L, identity, Map.of(), null, Map.of());
} catch (IOException e) {
LOG.debugv(e, "Publish for {0}/{1} is not a confirmable republish: {2}",
npmRequest.domain(), npmRequest.repository(), e.getMessage());
- return new RepublishCheck(false, 0L, identity, Map.of());
+ return new RepublishCheck(false, 0L, identity, Map.of(), null, Map.of());
}
long totalAttachmentBytes = envelope.attachments().values().stream()
.mapToLong(NpmPublishEnvelopeScanner.Attachment::size)
.sum();
Map<String, String> readmeByVersion = new HashMap<>();
envelope.versions().forEach((version, v) -> readmeByVersion.put(version, v.readme()));
+ Map<String, String> beforeRevisionByVersion = new HashMap<>();
+ for (String version : readmeByVersion.keySet()) {
+ try {
+ String beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(scope.region(),
+ npmRequest.domain(), scope.owner(), npmRequest.repository(), "npm", identity.namespace(),
+ identity.packageName(), version);
+ beforeRevisionByVersion.put(version, beforeRevision);
+ } catch (AwsException e) {
+ return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion, e.getMessage(),
+ beforeRevisionByVersion);
+ }
+ }
Optional<JsonNode> storedDocument;
try {
storedDocument = verdaccioClient.fetchPackageDocument(backendBaseUrl, identity.namespace(),
@@ -468,25 +550,30 @@ public class CodeArtifactNpmDataPlane {
} catch (IllegalStateException e) {
LOG.warnv(e, "Could not check {0}/{1} for an existing match before publishing: {2}",
npmRequest.domain(), npmRequest.repository(), e.getMessage());
- return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion);
+ return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion, null,
+ beforeRevisionByVersion);
}
if (storedDocument.isEmpty() || !isConfirmedRepublish(envelope, storedDocument.get(), identity)) {
- return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion);
+ return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion, null,
+ beforeRevisionByVersion);
}
for (NpmPublishEnvelopeScanner.Version version : envelope.versions().values()) {
try {
Optional<String> stored = verdaccioClient.storedTarballIntegrity(backendBaseUrl,
identity.namespace(), identity.packageName(), tarballFilename(version.tarball()));
if (stored.isEmpty() || !stored.get().equals(version.integrity())) {
- return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion);
+ return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion, null,
+ beforeRevisionByVersion);
}
} catch (IllegalStateException e) {
LOG.warnv(e, "Could not verify the stored tarball of {0}/{1} before publishing: {2}",
npmRequest.domain(), npmRequest.repository(), e.getMessage());
- return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion);
+ return new RepublishCheck(false, totalAttachmentBytes, identity, readmeByVersion, null,
+ beforeRevisionByVersion);
}
}
- return new RepublishCheck(true, totalAttachmentBytes, identity, readmeByVersion);
+ return new RepublishCheck(true, totalAttachmentBytes, identity, readmeByVersion, null,
+ beforeRevisionByVersion);
}
private static boolean isConfirmedRepublish(NpmPublishEnvelopeScanner.Envelope envelope, JsonNode stored,
@@ -581,7 +668,7 @@ public class CodeArtifactNpmDataPlane {
private void forwardSpooled(RoutingContext context, String backendBaseUrl, String backendPath,
ReadStream<Buffer> body, AuthorizationTokenScope scope, String domain, String repository,
PackageIdentity identity, long totalAttachmentBytes, long fenceSnapshot,
- Map<String, String> readmeByVersion) {
+ Map<String, String> readmeByVersion, Map<String, String> beforeRevisionByVersion) {
URI backend = URI.create(backendBaseUrl);
RequestOptions options = new RequestOptions()
.setHost(backend.getHost())
@@ -639,6 +726,19 @@ public class CodeArtifactNpmDataPlane {
service.recordPublishedPackageVersionReadme(scope.region(), domain,
scope.owner(), repository, "npm", identity.namespace(),
identity.packageName(), version, readme, fenceSnapshot));
+ // Found by Qodo review: readmeByVersion's own keys are every version in
+ // this publish envelope, independent of whether any of them actually
+ // carried a readme, so reusing it here clears a stale Archived/Disposed
+ // override for exactly the versions this publish just wrote real content
+ // for, the same way the Maven/pypi native publish paths now do. Cleared
+ // only if still unchanged since checkRepublish's own guard ran (Greptile
+ // review): a status change that landed while the forward was in flight
+ // must not be erased by this.
+ readmeByVersion.keySet().forEach(version ->
+ service.forgetContainerBackedStatusOverrideIfUnchanged(scope.region(), domain,
+ scope.owner(), repository, "npm", identity.namespace(),
+ identity.packageName(), version,
+ beforeRevisionByVersion.get(version)));
}
promise.complete();
}, false).onComplete(result -> {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetController.java
index f3331d5ca5..834aea35df 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNuGetController.java
@@ -197,6 +197,39 @@ public class CodeArtifactNuGetController {
String packageName = nuspec.id().toLowerCase(Locale.ROOT);
String version = NuGetVersions.normalize(nuspec.version());
+ // Raised by hectorvent's review: a real dotnet nuget push to a coordinate
+ // updatePackageVersionsStatus/disposePackageVersions left Archived or Disposed must be
+ // refused outright, the same way PublishPackageVersion already refuses it for the generic
+ // format, not accepted and then have forgetContainerBackedStatusOverride below silently
+ // un-block it afterward. Checked before even the existence check below, let alone the real
+ // write, the same way CodeArtifactNpmDataPlane's own guard already runs ahead of its
+ // byte-identical shortcut (Greptile review: an archived coordinate re-pushed byte-identical
+ // must still be refused, not quietly accepted as "nothing changed").
+ String beforeRevision;
+ try {
+ beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(handle.region(), domain,
+ handle.owner(), repository, "nuget", null, packageName, version);
+ } catch (AwsException e) {
+ return Response.status(409).entity(e.getMessage()).build();
+ }
+
+ // Raised by Greptile's review: DisposePackageVersions holds CodeArtifactService's own
+ // lock for its whole call, and its container-backed asset deletion (see
+ // CodeArtifactService#deleteContainerBackedVersionAssets) acquires this exact same
+ // per-repository BaGetter lock from inside that hold. Calling any synchronized
+ // CodeArtifactService method (recordContainerBackedAssetBytes/
+ // forgetContainerBackedStatusOverride below) from inside this lock, as both used to, would
+ // let a push and a concurrent dispose of the same version each wait forever on the other's
+ // lock. Neither call needs this lock at all: BaGetter's own content is already finalized by
+ // the time forwardPush below returns, so both bookkeeping calls run after this block
+ // releases it instead. currentContainerBackedPackageFence is exempt from this concern: it
+ // is deliberately lock-free (see its own javadoc), not a synchronized CodeArtifactService
+ // method, so taking the snapshot before entering the lock changes nothing it protects
+ // against.
+ long fenceSnapshot = service.currentContainerBackedPackageFence(handle.region(), domain, handle.owner(),
+ repository, "nuget", null, packageName);
+ Response response;
+ boolean pushSucceeded;
// The exact same lock BagetterSidecarClient#deletePackage takes for this repository, not
// a private one: without sharing it, a DeletePackage racing this push could still list
// its versions before this push lands and miss it, the one case a private lock here
@@ -211,21 +244,23 @@ public class CodeArtifactNuGetController {
.entity("A package with this id and version already exists.")
.build();
}
-
- // Snapshotted before the real write, not after: see
- // CodeArtifactService#currentContainerBackedPackageFence's own javadoc for why the
- // order matters.
- long fenceSnapshot = service.currentContainerBackedPackageFence(handle.region(), domain, handle.owner(),
- repository, "nuget", null, packageName);
- Response response = forwardPush(handle.baseUrl(), contentType, content);
- boolean pushSucceeded = response.getStatus() == 200 || response.getStatus() == 201
+ response = forwardPush(handle.baseUrl(), contentType, content);
+ pushSucceeded = response.getStatus() == 200 || response.getStatus() == 201
|| response.getStatus() == 202;
- if (pushSucceeded) {
- service.recordContainerBackedAssetBytes(handle.region(), domain, handle.owner(), repository,
- "nuget", null, packageName, nupkgBytes.length, fenceSnapshot);
- }
- return response;
}
+ if (pushSucceeded) {
+ service.recordContainerBackedAssetBytes(handle.region(), domain, handle.owner(), repository,
+ "nuget", null, packageName, nupkgBytes.length, fenceSnapshot);
+ // Found by Qodo review: a real dotnet nuget push that republishes a coordinate an
+ // earlier updatePackageVersionsStatus/disposePackageVersions call left Archived or
+ // Disposed would otherwise still have its fresh content blocked by that stale
+ // override, the same gap closed for Maven/npm/pypi's own native publish paths. Cleared
+ // only if still unchanged since the guard above ran (Greptile review): a status change
+ // that landed while forwardPush was in flight must not be erased by this.
+ service.forgetContainerBackedStatusOverrideIfUnchanged(handle.region(), domain, handle.owner(),
+ repository, "nuget", null, packageName, version, beforeRevision);
+ }
+ return response;
}
/**
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiController.java
index 5b16f303d3..785d85135f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiController.java
@@ -169,9 +169,42 @@ public class CodeArtifactPypiController {
if (packageName == null || packageName.isBlank() || file.isEmpty()) {
return Response.status(400).entity("Upload must include name and content fields.").build();
}
+ // Raised by Greptile's review: pypiserver files an upload under the identity its own
+ // filename embeds, not under whatever this form's name/version fields happen to say
+ // (PypiserverSidecarClient#filenameEmbedsVersion's own javadoc explains why that
+ // boundary check, not these fields, is the real source of truth). Everything below this
+ // point, the Archived/Disposed guard included, runs against these fields; a mismatched
+ // version field would let the guard see an unrelated, harmless coordinate while the real
+ // upload still lands under whatever the filename actually names.
+ if (version != null && !version.isBlank()
+ && !PypiserverSidecarClient.filenameEmbedsVersion(file.get().filename(), packageName, version)) {
+ return Response.status(400)
+ .entity("The upload's name and version fields do not match its filename.")
+ .build();
+ }
Object lock = uploadLocks.computeIfAbsent(handle.repoId(), k -> new Object());
synchronized (lock) {
+ // Raised by hectorvent's review: a real twine upload to a coordinate
+ // updatePackageVersionsStatus/disposePackageVersions left Archived or Disposed must be
+ // refused outright, the same way PublishPackageVersion already refuses it for the
+ // generic format, not accepted and then have forgetContainerBackedStatusOverride below
+ // silently un-block it afterward. Checked ahead of the byte-identical shortcut right
+ // below too, not just the real write: archiving leaves the stored bytes themselves
+ // unchanged, so a byte-identical re-upload of an archived version would otherwise
+ // short-circuit to 200 before ever reaching this guard (Greptile review). A
+ // missing/blank version is the same case the override-clearing call below already
+ // skips: no coordinate to block either way.
+ String beforeRevision = null;
+ if (version != null && !version.isBlank()) {
+ try {
+ beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(handle.region(),
+ domain, handle.owner(), repository, "pypi", null, packageName, version);
+ } catch (AwsException e) {
+ return Response.status(409).entity(e.getMessage()).build();
+ }
+ }
+
Optional<byte[]> existing = existingFileContent(handle.baseUrl(), packageName, file.get().filename());
if (existing.isPresent()) {
if (Arrays.equals(existing.get(), file.get().content())) {
@@ -193,6 +226,17 @@ public class CodeArtifactPypiController {
if (uploadSucceeded) {
service.recordContainerBackedAssetBytes(handle.region(), domain, handle.owner(), repository,
"pypi", null, packageName, file.get().content().length, fenceSnapshot);
+ // Found by Qodo review: a real twine upload that republishes a coordinate an
+ // earlier updatePackageVersionsStatus/disposePackageVersions call left Archived or
+ // Disposed would otherwise still have its fresh content blocked by that stale
+ // override. A missing/blank version is the same case the readme capture below
+ // already skips: no coordinate to clear an override for. Cleared only if still
+ // unchanged since the guard above ran (Greptile review): a status change that
+ // landed while forwardUpload was in flight must not be erased by this.
+ if (version != null && !version.isBlank()) {
+ service.forgetContainerBackedStatusOverrideIfUnchanged(handle.region(), domain, handle.owner(),
+ repository, "pypi", null, packageName, version, beforeRevision);
+ }
}
// Only for a real new publish, never the byte-identical-retry short-circuit above
// (nothing new was written there either): the "description" field is the real PyPI
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
index c94953e9d4..bbc6c6fae7 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
@@ -46,6 +46,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
@@ -53,6 +54,8 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
@ApplicationScoped
public class CodeArtifactService implements Resettable {
@@ -97,6 +100,17 @@ public class CodeArtifactService implements Resettable {
/** The real {@code PackageVersionOriginType} wire enum. Floci never ingests from an external
* connection, so every version {@link #listPackageVersions} ever reports is {@code INTERNAL}. */
private static final Set<String> ORIGIN_TYPES = Set.of("INTERNAL", "EXTERNAL", "UNKNOWN");
+ /** {@code UpdatePackageVersionsStatusRequest.targetStatus}'s own documented valid values:
+ * {@code Unfinished} is deliberately excluded (see {@link #updatePackageVersionsStatus}'s own
+ * javadoc), and {@code Disposed}/{@code Deleted} each have their own separate action instead. */
+ private static final Set<String> UPDATE_TARGET_STATUSES = Set.of("Published", "Unlisted", "Archived");
+ /** {@code UpdatePackageVersionsStatusRequest.expectedStatus}'s own documented valid values. */
+ private static final Set<String> UPDATE_EXPECTED_STATUSES =
+ Set.of("Published", "Unlisted", "Archived", "Unfinished");
+ /** {@code DisposePackageVersionsRequest.expectedStatus}'s own documented valid values: wider
+ * than {@link #UPDATE_EXPECTED_STATUSES} by exactly {@code Disposed} itself. */
+ private static final Set<String> DISPOSE_EXPECTED_STATUSES =
+ Set.of("Published", "Unlisted", "Archived", "Unfinished", "Disposed");
private static final Logger LOG = Logger.getLogger(CodeArtifactService.class);
@@ -117,11 +131,13 @@ public class CodeArtifactService implements Resettable {
// documented 5 GB AWS quota rather than duplicating the constant.
static final long MAX_ASSET_FILE_SIZE_BYTES = 5L * 1024 * 1024 * 1024;
private static final int MAX_ASSETS_PER_PACKAGE_VERSION = 350;
- // AWS's own wire model: CopyPackageVersionsRequest.versions has "Array Members: Maximum
- // number of 100 items." Applied the same way to versionRevisions, the alternate way of
- // naming the same set of versions to copy.
- private static final int MAX_COPY_VERSIONS_PER_CALL = 100;
- // CopyPackageVersionsRequest.versionRevisions' map value: "Maximum length of 50."
+ // AWS's own wire model: every batch package-version action's own PackageVersionList shape
+ // (CopyPackageVersionsRequest.versions, UpdatePackageVersionsStatusRequest.versions,
+ // DisposePackageVersionsRequest.versions) has "Array Members: Maximum number of 100 items."
+ // Applied the same way to versionRevisions, the alternate way of naming the same set of
+ // versions.
+ private static final int MAX_PACKAGE_VERSIONS_PER_BATCH_CALL = 100;
+ // Each batch action's own versionRevisions map value: "Maximum length of 50."
private static final int MAX_REVISION_LENGTH = 50;
private static final int MAX_DOMAINS_PER_ACCOUNT = 10;
private static final int MAX_REPOSITORIES_PER_DOMAIN = 1000;
@@ -137,10 +153,10 @@ public class CodeArtifactService implements Resettable {
public record PackageVersionAssetResult(PackageAsset asset, String packageVersionRevision) {}
public record PackageVersionReadmeResult(String format, String namespace, String packageName, String version,
String versionRevision, String readme) {}
- public record PackageVersionCopyOutcome(String revision, String status) {}
- public record PackageVersionCopyFailure(String errorCode, String errorMessage) {}
- public record CopyPackageVersionsResult(Map<String, PackageVersionCopyOutcome> successfulVersions,
- Map<String, PackageVersionCopyFailure> failedVersions) {}
+ public record SuccessfulPackageVersionInfo(String revision, String status) {}
+ public record PackageVersionError(String errorCode, String errorMessage) {}
+ public record CopyPackageVersionsResult(Map<String, SuccessfulPackageVersionInfo> successfulVersions,
+ Map<String, PackageVersionError> failedVersions) {}
public record AssetSummary(String name, long size, Map<String, String> hashes) {}
public record PackageVersionAssetsListResult(String format, String namespace, String packageName,
String version, String versionRevision, List<AssetSummary> assets, String nextToken) {}
@@ -199,6 +215,61 @@ public class CodeArtifactService implements Resettable {
// describes would leave it answering for a version that, after a restart, no longer exists
// anywhere real.
private final ConcurrentHashMap<String, String> packageVersionReadmes = new ConcurrentHashMap<>();
+ // Keyed the same way as packageVersionReadmes (packageVersionKey), and in memory only for the
+ // identical reason: a container-backed version's status/revision override describes content
+ // that lives in the sidecar container itself (or, once Disposed, used to), which does not
+ // survive a Floci restart either. generic needs no equivalent of this at all; its status and
+ // revision already live directly on its own packageVersions record. Absent here means
+ // "Published" (every container-backed version's implicit starting status; see
+ // describeContainerBackedPackageVersion's own javadoc for why nothing ever lands one in
+ // Unfinished the way a generic publish deliberately can) with its usual synthesized revision,
+ // the same default {@link #listPackageVersions} and {@link #describeContainerBackedPackageVersion}
+ // already assumed before this existed.
+ private final ConcurrentHashMap<String, PackageVersionStatusOverride>
+ containerBackedPackageVersionStatusOverrides = new ConcurrentHashMap<>();
+ // containerBackedPackageVersionStatusOverrides' own keys are each one version's full escaped
+ // packageVersionKey, which namespace/package/version segments containing ':' or '\' make
+ // lossy to split back apart into "does this key belong to package X" (see escapeKeySegment's
+ // own javadoc on why that escaping exists at all). This side index answers that question
+ // directly instead: which raw version strings have an override, kept under the package's own
+ // (version-free) key, so listPackageVersions can still report a version whose real sidecar
+ // content Disposed already deleted (so the sidecar itself no longer lists it at all) without
+ // ever parsing a stored key back into parts.
+ private final ConcurrentHashMap<String, Set<String>> containerBackedOverriddenVersionsByPackage =
+ new ConcurrentHashMap<>();
+
+ /**
+ * {@code publishedEpochSeconds} is carried forward from whichever value was already true for
+ * this version the first time it ever got an override (read from the sidecar's own {@link
+ * RepositorySidecarManager#listPackageVersions} before anything happened to change its
+ * status), not re-derived on every later transition: once {@code Disposed}, the sidecar no
+ * longer has the version at all to ask, and even for {@code Archived}/{@code Unlisted} (whose
+ * assets are not deleted), AWS's own definition of "package version revision" as covering a
+ * version's metadata, not just its bytes, means its original publish time should not appear to
+ * change just because a later status change happened to re-derive it from a sidecar that
+ * coincidentally still has the same files.
+ */
+ /**
+ * {@code pendingAssetNames} is the container-backed dispose counterpart to {@link
+ * #applyGenericStatusChange}'s own per-asset {@code assets} map bookkeeping: every asset
+ * still known to need real deletion for this version, updated right after each one's own
+ * delete succeeds (see {@link #deleteContainerBackedVersionAssets}'s own javadoc). Always
+ * {@code List.of()} for a non-disposing override (Archived/Unlisted/Published) or the
+ * implicit default {@link #currentContainerBackedVersionStatus} synthesizes, never {@code
+ * null}: there is nothing pending to track outside an actual dispose.
+ *
+ * <p>Raised by Greptile's review: {@code VerdaccioSidecarClient#deletePackageVersionAsset}'s
+ * own real npm unpublish protocol (confirmed live, see its own javadoc) removes a version
+ * from the packument <em>before</em> deleting its tarball, since Verdaccio's tarball-delete
+ * endpoint requires the fresh revision token only the packument update produces; that
+ * ordering cannot be reversed. Once that update lands, {@link
+ * RepositorySidecarManager#listPackageVersionAssetNames} can no longer answer "what is left
+ * to delete" for npm at all, even moments later, so a sidecar failure on the tarball delete
+ * itself used to leave a retry seeing nothing pending and reporting success with the real
+ * tarball still on disk. This field is what a retry now consults instead.
+ */
+ private record PackageVersionStatusOverride(String status, String revision, Long publishedEpochSeconds,
+ List<String> pendingAssetNames) {}
@Inject
public CodeArtifactService(StorageFactory storageFactory, RegionResolver regionResolver, EmulatorConfig config,
@@ -453,6 +524,20 @@ public class CodeArtifactService implements Resettable {
.filter(k -> k.startsWith(ownerScopedOriginPrefix))
.toList()
.forEach(packageVersionReadmes::remove);
+ // Same reasoning, same prefix, for the status overrides updatePackageVersionsStatus/
+ // disposePackageVersions write: a repository recreated under this same name must not
+ // inherit a previous Disposed/Archived/Unlisted override for a version with the same
+ // coordinates, and the per-package side index that names which versions have one must be
+ // cleaned up right alongside it so the two never drift apart (see
+ // writeContainerBackedStatusOverride's own javadoc).
+ containerBackedPackageVersionStatusOverrides.keySet().stream()
+ .filter(k -> k.startsWith(ownerScopedOriginPrefix))
+ .toList()
+ .forEach(containerBackedPackageVersionStatusOverrides::remove);
+ containerBackedOverriddenVersionsByPackage.keySet().stream()
+ .filter(k -> k.startsWith(ownerScopedOriginPrefix))
+ .toList()
+ .forEach(containerBackedOverriddenVersionsByPackage::remove);
return r;
}
@@ -725,7 +810,25 @@ public class CodeArtifactService implements Resettable {
String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);
CodeArtifactPackageVersion pv = packageVersions.getForAccount(owner, key).orElse(null);
- if (pv != null && "Published".equals(pv.getStatus())) {
+ // The User Guide draws an explicit, asymmetric line here: Archived ("you cannot use a
+ // package manager or build tool to re-publish an Archived package version because it is
+ // still present in the repository") and Disposed ("the package version can no longer be
+ // used because the assets have been deleted") are both unconditionally blocked, with no
+ // byte-identical exception stated for either, unlike DeletePackageVersions, whose own doc
+ // explicitly says the freed coordinate can be "freely re-published." Without this check,
+ // the fallthrough below would treat either status exactly like a brand new version and
+ // let a publish silently resurrect it, undoing updatePackageVersionsStatus/
+ // disposePackageVersions.
+ if (pv != null && ("Archived".equals(pv.getStatus()) || "Disposed".equals(pv.getStatus()))) {
+ throw conflict("Package version '" + version + "' of package '" + packageName + "' is "
+ + pv.getStatus() + " and cannot be republished.", version, "package-version");
+ }
+ // Unlisted only hides a version from listings; its assets stay downloadable and the User
+ // Guide never says republishing it is blocked the way it does for Archived/Disposed. Folds
+ // it into the same idempotent-replay rule as Published (reject new content, allow an exact
+ // byte-identical retry) rather than the Unfinished fallthrough below, which would otherwise
+ // let it be rebuilt as though no version existed there at all.
+ if (pv != null && ("Published".equals(pv.getStatus()) || "Unlisted".equals(pv.getStatus()))) {
// AWS's idempotency rule ("Overwriting package assets" in CodeArtifact's packages
// overview) is not scoped to Unfinished versions, and the terminal publish call (the
// one that finishes a version, or a single-shot generic publish that's Published
@@ -735,11 +838,13 @@ public class CodeArtifactService implements Resettable {
PackageAsset existingAsset = pv.getAssets().get(assetName);
if (existingAsset == null) {
throw conflict("Package version '" + version + "' of package '" + packageName + "' is already "
- + "Published; no additional assets can be uploaded to it.", version, "package-version");
+ + pv.getStatus() + "; no additional assets can be uploaded to it.", version,
+ "package-version");
}
- // Throws on a genuine mismatch; a Published version can never transition to anything
- // else via republish, so the match/no-stored-hash distinction contentMatchesExisting
- // returns doesn't matter here the way it does for the Unfinished path below.
+ // Throws on a genuine mismatch; neither Published nor Unlisted can transition to
+ // anything else via republish, so the match/no-stored-hash distinction
+ // contentMatchesExisting returns doesn't matter here the way it does for the
+ // Unfinished path below.
contentMatchesExisting(existingAsset, assetName, version, packageName, actualSha256);
// Only rewrites when the actual disk bytes don't check out: an intact retry (the
// overwhelmingly common case) must stay a true no-op that needs no write capacity at
@@ -896,7 +1001,8 @@ public class CodeArtifactService implements Resettable {
pageAssets.add(new AssetSummary(assetName, content.length, computeHashes(content)));
}
page = new PaginatedResult<>(pageAssets, namePage.nextToken());
- revision = synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version);
+ revision = currentContainerBackedVersionStatus(owner, region, domain, repository, format, namespace,
+ packageName, version, repoId).revision();
} else {
String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);
CodeArtifactPackageVersion pv = packageVersions.getForAccount(owner, key)
@@ -992,14 +1098,33 @@ public class CodeArtifactService implements Resettable {
} finally {
manager.endUse(repoId);
}
- if (raw.isEmpty() && !hasOriginConfig) {
+ // Disposed deletes a version's real sidecar content, so the sidecar's own listing
+ // (raw, above) stops naming it at all; overridesByVersion is this emulator's only
+ // remaining record that the version ever existed, and AWS's own documented behavior
+ // is that ListPackageVersions still reports a disposed version (status=Disposed) with
+ // status=Disposed, not silently drop it the moment its assets are gone.
+ Map<String, PackageVersionStatusOverride> overridesByVersion = containerBackedOverridesForPackage(owner,
+ region, domain, repository, format, namespace, packageName);
+ if (raw.isEmpty() && overridesByVersion.isEmpty() && !hasOriginConfig) {
throw notFound("Package '" + packageName + "' was not found.", packageName, "package");
}
- entries = raw.stream()
- .map(v -> new PackageVersionEntry(v.version(),
- synthesizeContainerBackedRevision(format, repoId, namespace, packageName, v.version()),
- "Published", v.publishedTime() == null ? null : v.publishedTime().getEpochSecond()))
- .toList();
+ Set<String> coveredVersions = raw.stream().map(RepositorySidecarManager.PackageVersionTimestamp::version)
+ .collect(Collectors.toSet());
+ Stream<PackageVersionEntry> fromSidecar = raw.stream().map(v -> {
+ PackageVersionStatusOverride override = overridesByVersion.get(v.version());
+ if (override != null) {
+ return new PackageVersionEntry(v.version(), override.revision(), override.status(),
+ override.publishedEpochSeconds());
+ }
+ return new PackageVersionEntry(v.version(),
+ synthesizeContainerBackedRevision(format, repoId, namespace, packageName, v.version()),
+ "Published", v.publishedTime() == null ? null : v.publishedTime().getEpochSecond());
+ });
+ Stream<PackageVersionEntry> disposedOnly = overridesByVersion.entrySet().stream()
+ .filter(e -> !coveredVersions.contains(e.getKey()))
+ .map(e -> new PackageVersionEntry(e.getKey(), e.getValue().revision(), e.getValue().status(),
+ e.getValue().publishedEpochSeconds()));
+ entries = Stream.concat(fromSidecar, disposedOnly).toList();
preferredDisplayVersion = manager.preferredDisplayVersion(repoId, domain, repository, namespace,
packageName).orElse(null);
} else {
@@ -1058,7 +1183,7 @@ public class CodeArtifactService implements Resettable {
/**
* AWS documents Maven and PyPI's {@code defaultDisplayVersion} as simply "the most recently
* published package version," and this codebase's own research found no stated rule at all
- * for {@code generic} or {@code nuget} — applying the same fallback to those two is the
+ * for {@code generic} or {@code nuget}: applying the same fallback to those two is the
* best-justified inference available, not an AWS-confirmed rule for them specifically. Only
* {@code Published} versions are eligible: an {@code Unfinished} one was never actually
* completed, so it can never be "the" default to show. {@code null} when nothing qualifies
@@ -1069,8 +1194,8 @@ public class CodeArtifactService implements Resettable {
* second tie-break computed here that disagreed with the cursor's could list one version
* first while naming a different one the default. Reusing the cursor also means a sidecar
* that could not supply a timestamp for any version (so every {@code publishedEpochSeconds}
- * is {@code null}) still gets a deterministic default — whichever {@code Published} version
- * the cursor's own tie-break puts first — instead of reporting none at all.
+ * is {@code null}) still gets a deterministic default, whichever {@code Published} version
+ * the cursor's own tie-break puts first, instead of reporting none at all.
*/
private static String mostRecentlyPublishedVersion(List<PackageVersionEntry> entries) {
return entries.stream()
@@ -1080,23 +1205,779 @@ public class CodeArtifactService implements Resettable {
.orElse(null);
}
+ public record PackageVersionStatusChangeResult(Map<String, SuccessfulPackageVersionInfo> successfulVersions,
+ Map<String, PackageVersionError> failedVersions) {}
+
+ /**
+ * Updates one or more versions of a package to {@code Published}, {@code Unlisted}, or {@code
+ * Archived} (confirmed against the API reference's own restriction on {@code targetStatus}:
+ * {@code Unfinished} is deliberately excluded, matching the User Guide's own note that "once
+ * published, a package version cannot be moved back to the Unfinished state"). To reach {@code
+ * Disposed}, use {@link #disposePackageVersions} instead; this and that one share every other
+ * rule through {@link #applyPackageVersionStatusChange}, confirmed against the User Guide's own
+ * worked examples ("Update package version status", "Disposing of package versions") rather
+ * than assumed from the shared {@code PackageVersionError} error-code enum alone, since that
+ * enum is reused across several batch package-version actions and not every code it lists
+ * applies to these two ({@code ALREADY_EXISTS} is {@code CopyPackageVersions}' own "destination
+ * already has this version" outcome, which neither of these actions has an equivalent of):
+ * <ul>
+ * <li>A requested version that does not exist fails {@code NOT_FOUND}.
+ * <li>{@code versionRevisions}, if given, fails a version whose current revision does not
+ * match with {@code MISMATCHED_REVISION}.
+ * <li>{@code expectedStatus}, if given, fails a version whose current status does not match
+ * with {@code MISMATCHED_STATUS}.
+ * <li>A version whose current status is already {@code Disposed} fails {@code NOT_ALLOWED}:
+ * the User Guide is explicit that "you cannot move a package version from Disposed to
+ * Archived, Unlisted, or Published, ... the only action that can be taken on a package version
+ * that has been disposed is for it to be deleted."
+ * <li>The whole call is all-or-nothing, documented as the current (but not contractually
+ * guaranteed) behavior: "if one or more versions cannot have their status changed, all other
+ * versions will be skipped. ... either all versions are updated successfully or no versions
+ * are updated." Every version that would otherwise have succeeded is reported {@code SKIPPED}
+ * rather than partially applied.
+ * </ul>
+ *
+ * <p>{@code synchronized} for the same reason every other package-mutating method here is: a
+ * concurrent publish, dispose, or another status update racing the same version must never
+ * interleave with this method's own read-then-write.
+ */
+ public synchronized PackageVersionStatusChangeResult updatePackageVersionsStatus(String region, String domain,
+ String domainOwner, String repository, String format, String namespace, String packageName,
+ List<String> versions, Map<String, String> versionRevisions, String expectedStatus,
+ String targetStatus) {
+ if (targetStatus == null || !UPDATE_TARGET_STATUSES.contains(targetStatus)) {
+ throw validation("targetStatus must be one of " + UPDATE_TARGET_STATUSES + ".");
+ }
+ if (expectedStatus != null && !UPDATE_EXPECTED_STATUSES.contains(expectedStatus)) {
+ throw validation("expectedStatus must be one of " + UPDATE_EXPECTED_STATUSES + ".");
+ }
+ return applyPackageVersionStatusChange(region, domain, domainOwner, repository, format, namespace,
+ packageName, "updating the status of", versions, versionRevisions, expectedStatus, targetStatus,
+ false);
+ }
+
+ /**
+ * Deletes the real assets of one or more versions of a package and sets their status to
+ * {@code Disposed}, sharing every other rule with {@link #updatePackageVersionsStatus} through
+ * {@link #applyPackageVersionStatusChange} (see that method's own javadoc for the full list).
+ * {@code Disposed} has its own, wider valid set for {@code expectedStatus} than {@code
+ * UpdatePackageVersionsStatus} allows (confirmed against the API reference: {@code Archived |
+ * Disposed | Published | Unfinished | Unlisted}, where {@code UpdatePackageVersionsStatusRequest}
+ * has no {@code Disposed} at all), unlike that action, which can never encounter a version
+ * already at its own target status, disposing one that is already {@code Disposed} is a
+ * meaningful (if pointless) case for a caller to probe for with {@code expectedStatus=Disposed}
+ * before trying again with a different one, even though the attempt itself still fails {@code
+ * NOT_ALLOWED} (disposing something already disposed changes nothing a second deletion could
+ * ever improve on).
+ *
+ * <p>{@code synchronized} for the same reason {@link #updatePackageVersionsStatus} is.
+ */
+ public synchronized PackageVersionStatusChangeResult disposePackageVersions(String region, String domain,
+ String domainOwner, String repository, String format, String namespace, String packageName,
+ List<String> versions, Map<String, String> versionRevisions, String expectedStatus) {
+ if (expectedStatus != null && !DISPOSE_EXPECTED_STATUSES.contains(expectedStatus)) {
+ throw validation("expectedStatus must be one of " + DISPOSE_EXPECTED_STATUSES + ".");
+ }
+ return applyPackageVersionStatusChange(region, domain, domainOwner, repository, format, namespace,
+ packageName, "disposing", versions, versionRevisions, expectedStatus, "Disposed", true);
+ }
+
+ private PackageVersionStatusChangeResult applyPackageVersionStatusChange(String region, String domain,
+ String domainOwner, String repository, String format, String namespace, String packageName,
+ String action, List<String> versions, Map<String, String> versionRevisions, String expectedStatus,
+ String targetStatus, boolean disposing) {
+ validatePackageCoordinates(format, namespace, packageName, action);
+ requireNonBlank(domain, "domain");
+ requireNonBlank(repository, "repository");
+ if (versions == null || versions.isEmpty()) {
+ throw validation("versions is required and must specify at least one version.");
+ }
+ if (versions.size() > MAX_PACKAGE_VERSIONS_PER_BATCH_CALL) {
+ throw validation("A single call can process at most " + MAX_PACKAGE_VERSIONS_PER_BATCH_CALL
+ + " versions.");
+ }
+ List<String> requestedVersions = List.copyOf(new LinkedHashSet<>(versions));
+ for (String version : requestedVersions) {
+ validatePackageToken("packageVersion", version);
+ }
+ Map<String, String> revisions = versionRevisions == null ? Map.of() : versionRevisions;
+ for (Map.Entry<String, String> entry : revisions.entrySet()) {
+ String expectedRevision = entry.getValue();
+ if (expectedRevision == null || expectedRevision.length() > MAX_REVISION_LENGTH
+ || !VERSION_REVISION_VALUE.matcher(expectedRevision).matches()) {
+ throw validation("versionRevisions['" + entry.getKey() + "'] must be 1-" + MAX_REVISION_LENGTH
+ + " characters with no whitespace.");
+ }
+ }
+ String owner = effectiveOwner(domainOwner);
+ requireRepository(owner, repositoryKey(region, domain, repository), repository);
+
+ if (CONTAINER_BACKED_FORMATS.contains(format)) {
+ return applyContainerBackedStatusChange(region, domain, owner, repository, format, namespace,
+ packageName, requestedVersions, revisions, expectedStatus, targetStatus, disposing);
+ }
+ return applyGenericStatusChange(region, domain, owner, repository, format, namespace, packageName,
+ requestedVersions, revisions, expectedStatus, targetStatus, disposing);
+ }
+
+ /**
+ * The one check shared by every requested version in both {@link #updatePackageVersionsStatus}
+ * and {@link #disposePackageVersions}, for either storage branch: {@code null} means the
+ * version is eligible to actually change; a non-null result is the exact failure to report
+ * (and, per the all-or-nothing rule both actions document, the reason every other
+ * otherwise-eligible version in the same call gets downgraded to {@code SKIPPED} instead).
+ *
+ * <p>Raised by Greptile's review: an already-{@code Disposed} version used to fail {@code
+ * NOT_ALLOWED} unconditionally, including a retry of {@code DisposePackageVersions} itself.
+ * For the container-backed branch (see {@link #applyContainerBackedStatusChange}'s own
+ * javadoc), the override is written {@code Disposed} before its real assets are deleted, so a
+ * sidecar failing partway through left no way to ever finish that cleanup or repair a stale
+ * {@code maven-metadata.xml}: every retry hit this exact same unconditional block first.
+ * {@code targetStatus} is {@code "Disposed"} if and only if this check is running inside
+ * {@link #disposePackageVersions} (confirmed against {@link #UPDATE_TARGET_STATUSES}, which
+ * never includes it), so re-disposing an already-disposed version is let through as the
+ * idempotent cleanup retry it actually is; {@link #updatePackageVersionsStatus} keeps the
+ * unconditional block exactly as the User Guide describes {@code Disposed} ("the package
+ * version can no longer be used") for every other target status.
+ */
+ private static PackageVersionError checkStatusTransitionAllowed(String currentStatus, String currentRevision,
+ String version, Map<String, String> revisions, String expectedStatus, String targetStatus) {
+ if ("Disposed".equals(currentStatus) && !"Disposed".equals(targetStatus)) {
+ return new PackageVersionError("NOT_ALLOWED", "Package version " + version + " has already been "
+ + "disposed and its status can no longer be changed");
+ }
+ String expectedRevision = revisions.get(version);
+ if (expectedRevision != null && !expectedRevision.equals(currentRevision)) {
+ return new PackageVersionError("MISMATCHED_REVISION", "current revision: " + currentRevision
+ + ", expected revision: " + expectedRevision);
+ }
+ if (expectedStatus != null && !expectedStatus.equals(currentStatus)) {
+ return new PackageVersionError("MISMATCHED_STATUS", "current status: " + currentStatus
+ + ", expected status: " + expectedStatus);
+ }
+ return null;
+ }
+
+ /**
+ * The {@code generic} branch of {@link #applyPackageVersionStatusChange}: reads and writes
+ * {@code packageVersions} directly, the same store {@link #publishPackageVersion} and {@link
+ * #copyPackageVersions} already use. For {@link #disposePackageVersions}, every asset's bytes
+ * are deleted the same way {@link #deletePackage} already deletes a whole package's worth, and
+ * the version's own {@code assets} map is cleared, before its status and revision are updated,
+ * matching the User Guide's own description of {@code Disposed} ("the assets of the package
+ * version will be permanently deleted") rather than leaving the bytes in place with only the
+ * status changed.
+ *
+ * <p>Raised by Greptile's review: the status/revision write used to run only after every
+ * asset's delete succeeded, so a failure partway through left the record reading
+ * {@code Published} (or whatever it was before) with its full original asset list, even
+ * though some of those assets' real bytes were already gone. {@code Disposed} is now written
+ * first, the same ordering {@link #applyContainerBackedStatusChange} already uses and for the
+ * identical reason (see that method's own javadoc): downloads are blocked immediately, and
+ * each asset is removed from the record's own {@code assets} map right after its own delete
+ * succeeds, not batched at the end, so a later failure leaves this record naming only the
+ * assets genuinely still there. A retry (see {@link #checkStatusTransitionAllowed}'s own
+ * javadoc for why a dispose retry is let through at all) then only has those left to finish.
+ */
+ private PackageVersionStatusChangeResult applyGenericStatusChange(String region, String domain, String owner,
+ String repository, String format, String namespace, String packageName, List<String> requestedVersions,
+ Map<String, String> revisions, String expectedStatus, String targetStatus, boolean disposing) {
+ Map<String, PackageVersionError> failures = new LinkedHashMap<>();
+ List<String> pending = new ArrayList<>();
+ Map<String, CodeArtifactPackageVersion> byVersion = new LinkedHashMap<>();
+ for (String version : requestedVersions) {
+ String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);
+ CodeArtifactPackageVersion pv = packageVersions.getForAccount(owner, key).orElse(null);
+ if (pv == null) {
+ failures.put(version, new PackageVersionError("NOT_FOUND", "Could not find version " + version));
+ continue;
+ }
+ PackageVersionError failure = checkStatusTransitionAllowed(pv.getStatus(), pv.getRevision(), version,
+ revisions, expectedStatus, targetStatus);
+ if (failure != null) {
+ failures.put(version, failure);
+ continue;
+ }
+ byVersion.put(version, pv);
+ pending.add(version);
+ }
+ if (!failures.isEmpty()) {
+ for (String version : pending) {
+ failures.put(version, new PackageVersionError("SKIPPED", "Version " + version + " is skipped"));
+ }
+ return new PackageVersionStatusChangeResult(Map.of(), failures);
+ }
+
+ Map<String, SuccessfulPackageVersionInfo> successes = new LinkedHashMap<>();
+ for (String version : pending) {
+ CodeArtifactPackageVersion pv = byVersion.get(version);
+ String key = packageVersionKey(region, domain, repository, format, namespace, packageName, version);
+ if (disposing) {
+ // Written before deleting below, not after (see this method's own javadoc for
+ // why): a failure partway through the loop below must never leave this record
+ // reading as more intact (its old status, every asset still listed) than it now
+ // really is.
+ pv.setStatus(targetStatus);
+ pv.setRevision(newRevision());
+ packageVersions.putForAccount(owner, key, pv);
+ // Unlike deletePackage's own best-effort cleanup, this record is not removed:
+ // disposePackageVersions keeps it around with a Disposed status for
+ // DescribePackageVersion to keep answering, so a failed delete here must not be
+ // swallowed the way deletePackage's already-unreachable leftover bytes can be:
+ // reporting success while clearing the asset map would permanently orphan bytes
+ // this version's own record can no longer point back to.
+ Map<String, PackageAsset> remaining = new LinkedHashMap<>(pv.getAssets());
+ for (PackageAsset asset : pv.getAssets().values()) {
+ deleteAssetContent(owner, key, asset.getName());
+ // Removed one at a time, and re-saved after each, so a later asset's delete
+ // failing leaves this record naming only the assets genuinely still there,
+ // letting a retry pick up exactly where this one stopped.
+ remaining.remove(asset.getName());
+ pv.setAssets(Map.copyOf(remaining));
+ packageVersions.putForAccount(owner, key, pv);
+ }
+ } else {
+ pv.setStatus(targetStatus);
+ // Raised by Greptile's review: UPDATE_TARGET_STATUSES allows targeting Published
+ // from Unfinished (nothing here or in checkStatusTransitionAllowed blocks it), the
+ // real way a version with no publishedTime at all finalizes through this action
+ // rather than through publishPackageVersion's own normal path, which already sets
+ // it on the same condition. Left unset, the version sorts as though never
+ // published (behind every real release in packageVersionSortCursor's own
+ // ordering) and may never become defaultDisplayVersion.
+ if ("Published".equals(targetStatus) && pv.getPublishedTime() == null) {
+ pv.setPublishedTime(Instant.now().getEpochSecond());
+ }
+ pv.setRevision(newRevision());
+ packageVersions.putForAccount(owner, key, pv);
+ }
+ successes.put(version, new SuccessfulPackageVersionInfo(pv.getRevision(), pv.getStatus()));
+ }
+ return new PackageVersionStatusChangeResult(successes, Map.of());
+ }
+
+ /**
+ * The container-backed branch of {@link #applyPackageVersionStatusChange}: {@link
+ * RepositorySidecarManager#listPackageVersions} is fetched exactly once up front (rather than
+ * once per requested version) both to check which requested versions are real and to capture
+ * each one's publish time, reused by {@link #currentContainerBackedVersionStatus}'s own default
+ * once this call writes an override for it. For {@link #disposePackageVersions}, every one of
+ * the version's real assets is deleted through {@link RepositorySidecarManager#listPackageVersionAssetNames}/
+ * {@link RepositorySidecarManager#deletePackageVersionAsset}, the only primitives this sidecar
+ * interface exposes for it; no client needed a new method of its own.
+ */
+ private PackageVersionStatusChangeResult applyContainerBackedStatusChange(String region, String domain,
+ String owner, String repository, String format, String namespace, String packageName,
+ List<String> requestedVersions, Map<String, String> revisions, String expectedStatus,
+ String targetStatus, boolean disposing) {
+ String repoId = ensureFormatContainerId(format, region, domain, owner, repository);
+ RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
+ .orElseThrow(() -> notFound("Package '" + packageName + "' was not found.", packageName, "package"));
+ List<RepositorySidecarManager.PackageVersionTimestamp> raw;
+ try {
+ raw = manager.listPackageVersions(repoId, domain, repository, namespace, packageName);
+ } catch (UnsupportedOperationException e) {
+ throw new AwsException("InternalServerException", "Changing " + format + " package version status is "
+ + "not yet supported by this emulator.", 500);
+ }
+ // Built with a plain loop, not Collectors.toMap: a sidecar that could not supply a
+ // timestamp for one of its versions (see listPackageVersions's own handling of this same
+ // possibility) reports a null publishedTime, and Map.merge, which toMap uses internally,
+ // throws NullPointerException on a null value. Keyed by the normalized version (see
+ // normalizedContainerBackedVersion, raised again by Greptile's review): BaGetter's own
+ // listing can spell a NuGet version differently than a caller's own request does, and the
+ // override side index below already normalizes on write, so comparing both against the
+ // same normalized form below is what actually keeps existence/override matching
+ // consistent with GetPackageVersionAsset's own normalized lookup.
+ Map<String, Instant> realPublishedTimes = new LinkedHashMap<>();
+ for (RepositorySidecarManager.PackageVersionTimestamp v : raw) {
+ realPublishedTimes.put(normalizedContainerBackedVersion(format, v.version()), v.publishedTime());
+ }
+ Map<String, PackageVersionStatusOverride> overridesByVersion = containerBackedOverridesForPackage(owner,
+ region, domain, repository, format, namespace, packageName);
+
+ Map<String, PackageVersionError> failures = new LinkedHashMap<>();
+ List<String> pending = new ArrayList<>();
+ Map<String, Long> pendingPublishedEpochSeconds = new LinkedHashMap<>();
+ for (String version : requestedVersions) {
+ String matchVersion = normalizedContainerBackedVersion(format, version);
+ boolean existsNow = realPublishedTimes.containsKey(matchVersion)
+ || overridesByVersion.containsKey(matchVersion);
+ if (!existsNow) {
+ failures.put(version, new PackageVersionError("NOT_FOUND", "Could not find version " + version));
+ continue;
+ }
+ PackageVersionStatusOverride override = overridesByVersion.get(matchVersion);
+ String currentStatus = override != null ? override.status() : "Published";
+ String currentRevision = override != null ? override.revision()
+ : synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version);
+ PackageVersionError failure = checkStatusTransitionAllowed(currentStatus, currentRevision, version,
+ revisions, expectedStatus, targetStatus);
+ if (failure != null) {
+ failures.put(version, failure);
+ continue;
+ }
+ Long publishedEpochSeconds;
+ if (override != null) {
+ publishedEpochSeconds = override.publishedEpochSeconds();
+ } else {
+ Instant publishedTime = realPublishedTimes.get(matchVersion);
+ publishedEpochSeconds = publishedTime == null ? null : publishedTime.getEpochSecond();
+ }
+ pendingPublishedEpochSeconds.put(version, publishedEpochSeconds);
+ pending.add(version);
+ }
+ if (!failures.isEmpty()) {
+ for (String version : pending) {
+ failures.put(version, new PackageVersionError("SKIPPED", "Version " + version + " is skipped"));
+ }
+ return new PackageVersionStatusChangeResult(Map.of(), failures);
+ }
+
+ Map<String, SuccessfulPackageVersionInfo> successes = new LinkedHashMap<>();
+ for (String version : pending) {
+ List<String> assetNames = List.of();
+ if (disposing) {
+ String matchVersion = normalizedContainerBackedVersion(format, version);
+ PackageVersionStatusOverride existing = overridesByVersion.get(matchVersion);
+ if (existing != null && "Disposed".equals(existing.status())) {
+ // A retry of a previously partially-failed dispose (see
+ // PackageVersionStatusOverride's own javadoc for why the sidecar's own
+ // listing can no longer answer this for npm specifically): reuse exactly
+ // what is still known to need cleanup rather than asking the sidecar again.
+ assetNames = existing.pendingAssetNames();
+ } else {
+ try {
+ assetNames = manager.listPackageVersionAssetNames(repoId, domain, repository, namespace,
+ packageName, version);
+ } catch (UnsupportedOperationException e) {
+ throw new AwsException("InternalServerException", "Disposing a package version of this "
+ + "format is not yet supported by this emulator.", 500);
+ }
+ }
+ }
+ PackageVersionStatusOverride updated = new PackageVersionStatusOverride(targetStatus, newRevision(),
+ pendingPublishedEpochSeconds.get(version), assetNames);
+ // Written before deleting below, not after: a sidecar failing partway through this
+ // version's own asset deletions (the one real way this loop can throw) would otherwise
+ // leave it marked Published with some assets already gone. There is no cheap way to
+ // roll a partial sidecar delete back (unlike copyContainerBackedPackageVersions's own
+ // write path, which can restore a destination's original bytes because it never
+ // deletes more than it is about to replace), so this can't promise every earlier
+ // version in the same batch rolls back too, only that this exact version never reads
+ // as more intact than it now really is.
+ writeContainerBackedStatusOverride(owner, region, domain, repository, format, namespace, packageName,
+ version, updated);
+ if (disposing) {
+ deleteContainerBackedVersionAssets(manager, repoId, owner, region, domain, repository, format,
+ namespace, packageName, version, assetNames);
+ }
+ successes.put(version, new SuccessfulPackageVersionInfo(updated.revision(), updated.status()));
+ }
+ return new PackageVersionStatusChangeResult(successes, Map.of());
+ }
+
+ /**
+ * {@link #disposePackageVersions}'s real deletion for a container-backed version: every asset
+ * name {@link RepositorySidecarManager#listPackageVersionAssetNames} still reports (the version
+ * has not been disposed yet at the point this runs, so these are genuinely all still there) is
+ * fetched (to measure its real size) and then deleted one at a time through {@link
+ * RepositorySidecarManager#deletePackageVersionAsset}, the same primitive {@code
+ * DeletePackageVersionAsset} itself already uses for one asset at a time. The bytes freed are
+ * subtracted from {@link #containerBackedAssetBytes}'s own package-level total, floored at 0:
+ * without this, {@code DescribeDomain}'s {@code assetSizeBytes} would keep counting a disposed
+ * version's bytes forever, the same way {@link #recordContainerBackedAssetBytes} already
+ * accounts for every container-backed publish adding to that same total. This runs inside
+ * {@link #disposePackageVersions}'s own {@code synchronized} call, unlike that method's own
+ * fence-checked accounting, so no separate race guard is needed here. {@link
+ * RepositorySidecarManager#recordVersionDisposed} runs last, once every asset is confirmed
+ * gone, for a sidecar (Maven) whose own native listing can otherwise keep naming a version
+ * whose assets no longer exist.
+ *
+ * <p>Raised by Greptile's review: every asset's size used to be measured immediately before
+ * deleting that exact asset, interleaved one at a time. {@code PypiserverSidecarClient}'s own
+ * {@code deletePackageVersionAsset} removes every file sharing the same raw package name and
+ * version in one call (confirmed live, the same quirk {@link #copyContainerBackedPackageVersions}'s
+ * own write path already works around), so deleting a release's first file could silently
+ * delete a sibling too; that sibling's own turn in this same loop then measured 0 bytes for
+ * content already gone, undercounting what {@link #containerBackedAssetBytes} subtracts below.
+ * Every asset is now measured in its own pass, before any of them are deleted, exactly like
+ * that same write path's own two-phase ordering.
+ *
+ * <p>Raised again by Greptile's review, once a dispose retry (see {@link
+ * #checkStatusTransitionAllowed}'s own javadoc) became possible: subtracting the whole
+ * batch's bytes only after every delete (and the metadata update after that) succeeded meant a
+ * failure partway through lost the freed bytes of every asset already genuinely deleted before
+ * it, since a retry's own fresh {@link RepositorySidecarManager#listPackageVersionAssetNames}
+ * call never lists them again to measure a second time. Each asset's own measured size is now
+ * subtracted right after that exact asset's own delete call returns, so a later failure (in a
+ * sibling's delete, or in {@link RepositorySidecarManager#recordVersionDisposed} itself) never
+ * loses bytes this method already knows for certain are gone.
+ *
+ * <p>Raised a third time by Greptile's review: {@code assetNames} is now the caller's own
+ * (the one real way to still know, for npm specifically, see {@code
+ * PackageVersionStatusOverride}'s own javadoc) rather than this method re-listing it fresh,
+ * and the override's {@code pendingAssetNames} is updated right after each asset's own
+ * delete succeeds, not just {@link #containerBackedAssetBytes}: a later asset's delete
+ * failing must leave that field naming only what is genuinely still real, the same per-item
+ * bookkeeping {@link #applyGenericStatusChange} already does for its own in-memory
+ * {@code assets} map.
+ */
+ private void deleteContainerBackedVersionAssets(RepositorySidecarManager manager, String repoId, String owner,
+ String region, String domain, String repository, String format, String namespace, String packageName,
+ String version, List<String> assetNames) {
+ Map<String, Long> sizeByAssetName = new LinkedHashMap<>();
+ for (String assetName : assetNames) {
+ sizeByAssetName.put(assetName, manager.fetchPackageVersionAsset(repoId, domain, repository, namespace,
+ packageName, version, assetName).map(bytes -> (long) bytes.length).orElse(0L));
+ }
+ String key = ownerScopedKey(owner, packageKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName)));
+ List<String> remaining = new ArrayList<>(assetNames);
+ for (String assetName : assetNames) {
+ manager.deletePackageVersionAsset(repoId, domain, repository, namespace, packageName, version,
+ assetName);
+ remaining.remove(assetName);
+ recordPendingAssetNames(owner, region, domain, repository, format, namespace, packageName, version,
+ List.copyOf(remaining));
+ long freedBytes = sizeByAssetName.get(assetName);
+ if (freedBytes > 0) {
+ containerBackedAssetBytes.computeIfPresent(key, (k, existing) -> Math.max(0, existing - freedBytes));
+ }
+ }
+ manager.recordVersionDisposed(repoId, namespace, packageName, version);
+ }
+
+ /**
+ * {@link #deleteContainerBackedVersionAssets}'s own per-asset update of {@code
+ * pendingAssetNames} alone, leaving the override's {@code status}/{@code revision}/{@code
+ * publishedEpochSeconds} exactly as they already are. A no-op if no override exists for this
+ * version at all, which should never happen for either of this method's own callers (both
+ * write one, with {@code disposing} true, immediately before calling it).
+ */
+ private void recordPendingAssetNames(String owner, String region, String domain, String repository,
+ String format, String namespace, String packageName, String version, List<String> remaining) {
+ String key = packageVersionKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName), normalizedContainerBackedVersion(format, version));
+ PackageVersionStatusOverride current =
+ containerBackedPackageVersionStatusOverrides.get(ownerScopedKey(owner, key));
+ if (current == null) {
+ return;
+ }
+ writeContainerBackedStatusOverride(owner, region, domain, repository, format, namespace, packageName,
+ version, new PackageVersionStatusOverride(current.status(), current.revision(),
+ current.publishedEpochSeconds(), remaining));
+ }
+
+ /**
+ * {@code GetPackageVersionAsset} for a version with a status of {@code Archived} or {@code
+ * Disposed} must 404 even though, for {@code Archived}, the bytes are still physically
+ * present: confirmed against the User Guide's own worked example of an upstream fetch hitting
+ * a package version with one of these two statuses in the upstream repository ("the response
+ * will be 404 (Not Found) because the assets of package versions in those two statuses are
+ * not downloadable"), which states the restriction as a property of the status itself, not
+ * something specific to the upstream path the example happens to illustrate it with. {@code
+ * Unlisted} is deliberately not checked here: the User Guide draws it out explicitly as the
+ * one status that still allows a normal download ("if the Unlisted package version is already
+ * referenced in an npm package-lock.json file, it can still be downloaded and installed").
+ *
+ * <p><b>Known gap, not fixed here (flagged by Qodo review on the PR that added {@code
+ * DisposePackageVersions}):</b> this only guards {@code GetPackageVersionAsset} itself. The
+ * native per-format data planes ({@code CodeArtifactMavenController}'s GAV path, {@code
+ * CodeArtifactNpmDataPlane}'s tarball route, {@code CodeArtifactPypiController}'s raw
+ * filename-only download route, {@code CodeArtifactNuGetController}'s content route) proxy
+ * straight to each sidecar and never consult this override at all, for any purpose, so a
+ * plain {@code pip install}/{@code npm install}/{@code mvn} fetch against an Archived version
+ * can still download it. Fixing this means threading status awareness into four independently
+ * shaped native protocols (pypi's own download route does not even carry a version in its
+ * URL, only a filename, unlike the other three), a feature-family-sized gap closer to Package
+ * Groups than a quick patch, tracked in the private design memo, not silently dropped.
+ */
+ private static void requireAssetDownloadable(String status, String version) {
+ if ("Archived".equals(status) || "Disposed".equals(status)) {
+ throw notFound("Package version '" + version + "' was not found.", version, "package-version");
+ }
+ }
+
+ /**
+ * A container-backed version "exists" if either the sidecar itself still has it, or Floci
+ * holds a status override for it: once {@code DisposePackageVersions} deletes a version's
+ * real sidecar content, {@link RepositorySidecarManager#packageVersionExists} alone would
+ * start reporting it gone, even though AWS's own documented behavior is that a disposed
+ * version keeps answering {@code DescribePackageVersion} (just with a {@code Disposed}
+ * status and no assets) rather than ever reverting to a plain 404 as if it had never existed.
+ *
+ * <p>The override lookup normalizes through {@link #accountingPackageName} and {@link
+ * #normalizedContainerBackedVersion}, the sidecar call does not: this mirrors how {@link
+ * #recordPublishedPackageVersionReadme} already keys its own per-version, container-backed-only
+ * bookkeeping, so a pypi/nuget package (or NuGet version) addressed under two case-,
+ * punctuation-, or numeric-equivalent spellings (which the real sidecar itself treats as the
+ * same package/version) still finds the one override either spelling wrote, while the sidecar
+ * call itself is left to each client's own normalization against the real container.
+ */
+ private boolean containerBackedVersionExists(RepositorySidecarManager manager, String owner, String region,
+ String domain, String repository, String format, String namespace, String packageName, String version,
+ String repoId) {
+ String key = packageVersionKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName), normalizedContainerBackedVersion(format, version));
+ return containerBackedPackageVersionStatusOverrides.containsKey(ownerScopedKey(owner, key))
+ || manager.packageVersionExists(repoId, domain, repository, namespace, packageName, version);
+ }
+
+ /**
+ * A container-backed version's current status and revision: whatever {@link
+ * #updatePackageVersionsStatus}/{@link #disposePackageVersions} last recorded for it, or, for
+ * a version neither has ever touched, the implicit {@code Published} status every
+ * container-backed version starts in (nothing here ever lands one in {@code Unfinished} the
+ * way a generic publish deliberately can, since a real {@code mvn deploy}/{@code npm
+ * publish}/{@code twine upload} only ever lands a version by completing it in one shot) with
+ * its usual coordinate-derived {@link #synthesizeContainerBackedRevision}. Callers that also
+ * need to know whether the version exists at all check that separately with {@link
+ * #containerBackedVersionExists} first; this always returns a value either way.
+ */
+ private PackageVersionStatusOverride currentContainerBackedVersionStatus(String owner, String region,
+ String domain, String repository, String format, String namespace, String packageName, String version,
+ String repoId) {
+ String key = packageVersionKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName), normalizedContainerBackedVersion(format, version));
+ PackageVersionStatusOverride override =
+ containerBackedPackageVersionStatusOverrides.get(ownerScopedKey(owner, key));
+ if (override != null) {
+ return override;
+ }
+ return new PackageVersionStatusOverride("Published",
+ synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version), null, List.of());
+ }
+
+ /**
+ * Writes one version's status override, keeping {@link #containerBackedPackageVersionStatusOverrides}
+ * and its {@link #containerBackedOverriddenVersionsByPackage} side index in sync: every writer
+ * goes through this rather than touching either map directly, so the two can never drift apart.
+ */
+ private void writeContainerBackedStatusOverride(String owner, String region, String domain, String repository,
+ String format, String namespace, String packageName, String version,
+ PackageVersionStatusOverride override) {
+ String accountingName = accountingPackageName(format, packageName);
+ String normalizedVersion = normalizedContainerBackedVersion(format, version);
+ String versionKey = ownerScopedKey(owner,
+ packageVersionKey(region, domain, repository, format, namespace, accountingName,
+ normalizedVersion));
+ containerBackedPackageVersionStatusOverrides.put(versionKey, override);
+ String packageKey = ownerScopedKey(owner, packageKey(region, domain, repository, format, namespace,
+ accountingName));
+ containerBackedOverriddenVersionsByPackage.computeIfAbsent(packageKey, k -> ConcurrentHashMap.newKeySet())
+ .add(normalizedVersion);
+ }
+
+ /**
+ * Removes one version's status override, the counterpart to {@link
+ * #writeContainerBackedStatusOverride}: {@link #copyContainerBackedPackageVersions} calls this
+ * after successfully overwriting a destination version's real content, and {@link
+ * #forgetContainerBackedStatusOverride} exposes it to every native publish path, so a status
+ * an earlier {@link #updatePackageVersionsStatus}/{@link #disposePackageVersions} call
+ * recorded for whatever used to be at that coordinate doesn't keep describing (and, through
+ * {@link #requireAssetDownloadable}, blocking downloads of) the content that just replaced it.
+ * A version with no override to begin with is a no-op, matching every other removal here.
+ */
+ private void clearContainerBackedStatusOverride(String owner, String region, String domain, String repository,
+ String format, String namespace, String packageName, String version) {
+ String accountingName = accountingPackageName(format, packageName);
+ String normalizedVersion = normalizedContainerBackedVersion(format, version);
+ String versionKey = ownerScopedKey(owner,
+ packageVersionKey(region, domain, repository, format, namespace, accountingName,
+ normalizedVersion));
+ containerBackedPackageVersionStatusOverrides.remove(versionKey);
+ String packageKey = ownerScopedKey(owner, packageKey(region, domain, repository, format, namespace,
+ accountingName));
+ Set<String> versions = containerBackedOverriddenVersionsByPackage.get(packageKey);
+ if (versions != null) {
+ versions.remove(normalizedVersion);
+ }
+ }
+
+ /**
+ * Found by Qodo review, as a remaining half of the same finding its own copy-side fix (see
+ * {@link #clearContainerBackedStatusOverride}'s javadoc) only partly closed: {@code
+ * copyContainerBackedPackageVersions} clears a stale override on its own overwrite path, but
+ * nothing cleared one for a <em>native</em> publish, a real {@code mvn deploy}/{@code npm
+ * publish}/twine upload/{@code dotnet nuget push} that successfully republishes a coordinate
+ * an earlier {@link #updatePackageVersionsStatus}/{@link #disposePackageVersions} call left
+ * Archived or Disposed. Each native proxy controller (Maven, npm, pypi, nuget) calls this
+ * right alongside its own existing {@link #recordContainerBackedAssetBytes} call, for the
+ * exact same "a real write just happened" signal, whenever it has a specific version to name;
+ * {@code CodeArtifactMavenController}'s own bare {@code maven-metadata.xml} PUT has none
+ * (see its own GAV-parsing javadoc) and skips this entirely, since that path never represents
+ * one specific version's content changing.
+ */
+ public synchronized void forgetContainerBackedStatusOverride(String region, String domain, String domainOwner,
+ String repository, String format, String namespace, String packageName, String version) {
+ String owner = effectiveOwner(domainOwner);
+ clearContainerBackedStatusOverride(owner, region, domain, repository, format, namespace, packageName,
+ version);
+ }
+
+ /**
+ * Raised by hectorvent's review of this same PR: {@link #forgetContainerBackedStatusOverride}
+ * only ever ran <em>after</em> each native proxy controller's real sidecar write already
+ * succeeded, which cleared an Archived/Disposed override once Reposilite/Verdaccio/pypiserver/
+ * BaGetter had already accepted (and written) the republished content, exactly the outcome
+ * {@link #publishPackageVersion}'s own Archived/Disposed block exists to prevent for the
+ * generic format. The User Guide draws no byte-identical exception for either status the way
+ * it does for a plain idempotent retry of a {@code Published}/{@code Unlisted} version (see
+ * {@link #publishPackageVersion}'s own javadoc), so this is unconditional, independent of
+ * whether the incoming content happens to match what is already there.
+ *
+ * <p>Each native proxy controller calls this first, before issuing its own real write, so a
+ * blocked coordinate is refused outright rather than accepted and then silently un-blocked;
+ * {@code CodeArtifactMavenController}'s bare {@code maven-metadata.xml} PUT has no specific
+ * version to check against (see its own GAV-parsing javadoc) and skips this entirely, the same
+ * case {@link #forgetContainerBackedStatusOverride} already skips it for.
+ *
+ * <p>Returns the override's own revision if one exists at this exact moment, or {@code null}
+ * if none does; a caller whose own real write later succeeds passes whichever came back here
+ * straight into {@link #forgetContainerBackedStatusOverrideIfUnchanged}, not this class's own
+ * unconditional {@link #forgetContainerBackedStatusOverride} (see that method's own javadoc for
+ * why the distinction matters).
+ */
+ public synchronized String requireContainerBackedVersionNotArchivedOrDisposed(String region, String domain,
+ String domainOwner, String repository, String format, String namespace, String packageName,
+ String version) {
+ String owner = effectiveOwner(domainOwner);
+ String key = packageVersionKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName), normalizedContainerBackedVersion(format, version));
+ PackageVersionStatusOverride override =
+ containerBackedPackageVersionStatusOverrides.get(ownerScopedKey(owner, key));
+ if (override != null && ("Archived".equals(override.status()) || "Disposed".equals(override.status()))) {
+ throw conflict("Package version '" + version + "' of package '" + packageName + "' is "
+ + override.status() + " and cannot be republished.", version, "package-version");
+ }
+ return override == null ? null : override.revision();
+ }
+
+ /**
+ * Raised by Greptile's review of this same PR: a native publish's own check, real sidecar
+ * write, and override clear are three separate calls (necessarily, since the real write sits
+ * in between and this class's own lock cannot be held across it), so a concurrent {@link
+ * #updatePackageVersionsStatus}/{@link #disposePackageVersions} call that lands strictly
+ * between the check and the clear writes a brand new override this publish never saw, only for
+ * the unconditional {@link #forgetContainerBackedStatusOverride} to erase it afterward,
+ * silently undoing a status change its own caller had already been told succeeded.
+ *
+ * <p>{@code expectedRevisionOrNull} is whatever {@link
+ * #requireContainerBackedVersionNotArchivedOrDisposed} returned when the caller's own guard
+ * check ran, right before its real write: a revision changes on every single status write
+ * ({@link #applyContainerBackedStatusChange} always calls {@link #newRevision} for it, even
+ * when the target status repeats one already in effect), so comparing the override's current
+ * revision against that snapshot, inside this one {@code synchronized} call, with no other
+ * synchronized method able to interleave in between the comparison and the clear, tells
+ * apart "nothing touched it since my guard ran" (safe to clear the stale pre-existing entry,
+ * restoring the version to its real freshly-written content) from "something else just wrote a
+ * newer one" (leave it alone, whatever it now says is more current than what this publish knew
+ * about). Lands as a no-op either way once nothing is left to compare: a caller with
+ * {@code expectedRevisionOrNull == null} whose own version still has no override at all
+ * finds nothing changed and nothing to clear.
+ *
+ * <p>Raised by Greptile's review: leaving a newer override alone is correct for the override
+ * itself, but a concurrent {@link #disposePackageVersions} landing in that same gap already
+ * deleted this version's real sidecar content before the caller's own write restored it; the
+ * override staying {@code Disposed} is no longer enough on its own to keep that promise, since
+ * a native per-format download route (the documented gap in {@code requireAssetDownloadable}'s
+ * own javadoc) consults real sidecar content directly, never this override. When the override
+ * changed to specifically {@code Disposed} (not just any newer value), this now also re-runs
+ * {@link #deleteContainerBackedVersionAssets} for the exact same version, undoing what the
+ * caller's own write just restored and leaving the version exactly as disposal's own caller
+ * was already told it would be: real, byte-accounted content included.
+ */
+ public synchronized void forgetContainerBackedStatusOverrideIfUnchanged(String region, String domain,
+ String domainOwner, String repository, String format, String namespace, String packageName,
+ String version, String expectedRevisionOrNull) {
+ String owner = effectiveOwner(domainOwner);
+ String key = packageVersionKey(region, domain, repository, format, namespace,
+ accountingPackageName(format, packageName), normalizedContainerBackedVersion(format, version));
+ PackageVersionStatusOverride current =
+ containerBackedPackageVersionStatusOverrides.get(ownerScopedKey(owner, key));
+ String currentRevision = current == null ? null : current.revision();
+ if (Objects.equals(currentRevision, expectedRevisionOrNull)) {
+ clearContainerBackedStatusOverride(owner, region, domain, repository, format, namespace, packageName,
+ version);
+ return;
+ }
+ if (current != null && "Disposed".equals(current.status())) {
+ String repoId = ensureFormatContainerId(format, region, domain, owner, repository);
+ RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
+ .orElseThrow(() -> notFound("Package '" + packageName + "' was not found.", packageName,
+ "package"));
+ // Fresh, since the content to undo here is whatever the caller's own write just
+ // restored, which the disposal that wrote this override could never itself have
+ // known to list.
+ List<String> freshAssetNames;
+ try {
+ freshAssetNames = manager.listPackageVersionAssetNames(repoId, domain, repository, namespace,
+ packageName, version);
+ } catch (UnsupportedOperationException e) {
+ throw new AwsException("InternalServerException", "Disposing a package version of this format "
+ + "is not yet supported by this emulator.", 500);
+ }
+ // Raised by Greptile's review: this fresh listing is not reliable on its own either.
+ // A disposal running concurrently with this exact publish can itself be mid-cleanup
+ // right now: for npm specifically, its own packument-removal half (see
+ // VerdaccioSidecarClient#deletePackageVersionAsset's own javadoc) can already have
+ // landed while its tarball-delete half is still failing, which makes this same fresh
+ // listing go blind to a tarball that disposal's own pendingAssetNames still correctly
+ // names as real. Overwriting pendingAssetNames with only this fresh list would lose
+ // that name outright; the union of both is what a cleanup here, or whatever
+ // DisposePackageVersions retry comes after it, actually needs to finish.
+ Set<String> assetNamesToClean = new LinkedHashSet<>(current.pendingAssetNames());
+ assetNamesToClean.addAll(freshAssetNames);
+ List<String> combinedAssetNames = List.copyOf(assetNamesToClean);
+ recordPendingAssetNames(owner, region, domain, repository, format, namespace, packageName, version,
+ combinedAssetNames);
+ deleteContainerBackedVersionAssets(manager, repoId, owner, region, domain, repository, format,
+ namespace, packageName, version, combinedAssetNames);
+ }
+ }
+
+ /**
+ * Every version of one package that has a status override, by normalized version string (see
+ * {@link #normalizedContainerBackedVersion}): the set
+ * {@link #containerBackedOverriddenVersionsByPackage} tracks names the versions, and each is
+ * then looked up individually in {@link #containerBackedPackageVersionStatusOverrides} itself.
+ * Empty for a package nothing has ever called {@link #updatePackageVersionsStatus} or {@link
+ * #disposePackageVersions} on, which is every container-backed package before this existed.
+ */
+ private Map<String, PackageVersionStatusOverride> containerBackedOverridesForPackage(String owner, String region,
+ String domain, String repository, String format, String namespace, String packageName) {
+ String accountingName = accountingPackageName(format, packageName);
+ Set<String> versions = containerBackedOverriddenVersionsByPackage.get(ownerScopedKey(owner,
+ packageKey(region, domain, repository, format, namespace, accountingName)));
+ if (versions == null || versions.isEmpty()) {
+ return Map.of();
+ }
+ Map<String, PackageVersionStatusOverride> result = new LinkedHashMap<>();
+ for (String version : versions) {
+ String versionKey = ownerScopedKey(owner,
+ packageVersionKey(region, domain, repository, format, namespace, accountingName, version));
+ PackageVersionStatusOverride override = containerBackedPackageVersionStatusOverrides.get(versionKey);
+ if (override != null) {
+ result.put(version, override);
+ }
+ }
+ return result;
+ }
+
/**
* Unlike {@code GetPackageVersionAsset}, real CodeArtifact's {@code DescribePackageVersion}
* response has no asset listing at all (confirmed against the wire model: {@code
* PackageVersionDescription} has no such member; enumerating a version's files is {@link
* #listPackageVersionAssets}'s job, a separate action). All this needs
- * from a sidecar is a yes/no answer to "does this exact version exist," which is cheap for
+ * from a sidecar (beyond the status override {@link #currentContainerBackedVersionStatus}
+ * already resolves) is a yes/no answer to "does this exact version exist," which is cheap for
* every one of the three: Verdaccio's packument already lists every version it holds,
* Reposilite's own details API answers directory existence the same way {@link
* #ensureFormatContainerId}'s readiness probe already relies on, and pypiserver's per-project
* JSON listing already groups files by version the same way {@code deletePackage} already
* reads it.
*
- * <p>A sidecar-backed version is always reported {@code Published}: nothing here ever leaves
- * one in {@code Unfinished}, the way a generic publish deliberately can, since a real {@code
- * mvn deploy}/{@code npm publish}/{@code twine upload} only ever lands a version by completing
- * it in one shot.
- *
* <p>Namespace is validated through the same shared {@link #validatePackageCoordinates} every
* other package-level operation already uses, rather than a one-off maven-only check: a pypi
* version genuinely has no namespace, so a caller-supplied one must be rejected outright, not
@@ -1109,10 +1990,13 @@ public class CodeArtifactService implements Resettable {
RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
.orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version"));
- if (!manager.packageVersionExists(repoId, domain, repository, namespace, packageName, version)) {
+ if (!containerBackedVersionExists(manager, owner, region, domain, repository, format, namespace, packageName,
+ version, repoId)) {
throw notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version");
}
+ PackageVersionStatusOverride state = currentContainerBackedVersionStatus(owner, region, domain, repository,
+ format, namespace, packageName, version, repoId);
CodeArtifactPackageVersion pv = new CodeArtifactPackageVersion();
pv.setDomainName(domain);
pv.setDomainOwner(owner);
@@ -1122,8 +2006,8 @@ public class CodeArtifactService implements Resettable {
pv.setNamespace(namespace);
pv.setPackageName(packageName);
pv.setVersion(version);
- pv.setStatus("Published");
- pv.setRevision(synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version));
+ pv.setStatus(state.status());
+ pv.setRevision(state.revision());
return pv;
}
@@ -1287,6 +2171,14 @@ public class CodeArtifactService implements Resettable {
.filter(k -> k.startsWith(ownerScopedReadmePrefix))
.toList()
.forEach(packageVersionReadmes::remove);
+ // Same prefix, same reasoning, for updatePackageVersionsStatus/disposePackageVersions'
+ // own per-version overrides; the side index is removed outright rather than
+ // prefix-scanned since its own key is exactly ownerScopedKey(owner, accountingKey).
+ containerBackedPackageVersionStatusOverrides.keySet().stream()
+ .filter(k -> k.startsWith(ownerScopedReadmePrefix))
+ .toList()
+ .forEach(containerBackedPackageVersionStatusOverrides::remove);
+ containerBackedOverriddenVersionsByPackage.remove(ownerScopedKey(owner, accountingKey));
} else {
List<CodeArtifactPackageVersion> versions = genericPackageVersions(region, domain, owner, repository,
format, namespace, packageName);
@@ -1419,6 +2311,7 @@ public class CodeArtifactService implements Resettable {
CodeArtifactPackageVersion pv = packageVersions.getForAccount(owner, key)
.orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
+ "' was not found.", version, "package-version"));
+ requireAssetDownloadable(pv.getStatus(), version);
if (packageVersionRevision != null && !packageVersionRevision.equals(pv.getRevision())) {
throw notFound("Package version '" + version + "' was not found at revision '"
+ packageVersionRevision + "'.", version, "package-version");
@@ -1443,14 +2336,22 @@ public class CodeArtifactService implements Resettable {
throw validation("namespace is required when requesting an asset from a maven package version.");
}
String repoId = ensureFormatContainerId(format, region, domain, owner, repository);
- String revision = synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version);
+ RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
+ .orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
+ + "' was not found.", version, "package-version"));
+ // No separate existence check needed here the way describeContainerBackedPackageVersion
+ // needs one: fetchPackageVersionAsset's own empty result already 404s a version that never
+ // existed at all (see below), and requireAssetDownloadable below already blocks a version
+ // this emulator knows is Archived/Disposed purely from the override map, with no sidecar
+ // round trip required to tell the two cases apart.
+ PackageVersionStatusOverride state = currentContainerBackedVersionStatus(owner, region, domain, repository,
+ format, namespace, packageName, version, repoId);
+ String revision = state.revision();
if (packageVersionRevision != null && !packageVersionRevision.equals(revision)) {
throw notFound("Package version '" + version + "' was not found at revision '"
+ packageVersionRevision + "'.", version, "package-version");
}
- RepositorySidecarManager manager = sidecarRegistry.forFormat(format)
- .orElseThrow(() -> notFound("Package version '" + version + "' of package '" + packageName
- + "' was not found.", version, "package-version"));
+ requireAssetDownloadable(state.status(), version);
byte[] content = manager.fetchPackageVersionAsset(repoId, domain, repository, namespace, packageName,
version, assetName)
.orElseThrow(() -> notFound("Asset '" + assetName + "' was not found on package version '"
@@ -1515,7 +2416,7 @@ public class CodeArtifactService implements Resettable {
* their own sidecar (see {@link #copyContainerBackedPackageVersions}). Matches real AWS,
* which does not restrict this action's {@code format} the way it restricts {@link
* #publishPackageVersion}'s to {@code generic} alone (confirmed against the wire model:
- * {@code CopyPackageVersionsRequest.format}'s own doc carries no such restriction) — every
+ * {@code CopyPackageVersionsRequest.format}'s own doc carries no such restriction): every
* container-backed format publishes straight to its own sidecar and keeps no {@code
* packageVersions} record this could otherwise read from or write to, so each needed the
* same per-sidecar fetch-then-republish shape {@code GetPackageVersionAsset}'s own bridge
@@ -1552,7 +2453,7 @@ public class CodeArtifactService implements Resettable {
* own {@code expectedStatus} parameter, which {@code CopyPackageVersionsRequest} has no
* equivalent of, or {@code PublishPackageVersion}'s origin-configuration check, which the User
* Guide's own definition of the "Publish" origin control scopes to direct publish "using
- * package managers or similar tools" — a mechanism {@code CopyPackageVersions} is not) — this
+ * package managers or similar tools", a mechanism {@code CopyPackageVersions} is not), this
* never produces any of the three, rather than guessing at a condition AWS never actually
* documents for this action.
*
@@ -1564,7 +2465,7 @@ public class CodeArtifactService implements Resettable {
* #newRevision()}, never the source's): the User Guide's own definition of "package version
* revision" is explicit that "each time a package version is updated, a new package version
* revision is created," and landing a version in a repository it previously had no record in
- * is such an update at the destination — the same reason {@link #publishPackageVersion}
+ * is such an update at the destination, the same reason {@link #publishPackageVersion}
* always mints its own rather than ever accepting a caller-supplied one. An identical-content
* no-op (see above) is correctly the opposite case: nothing was updated at the destination, so
* its existing revision, whatever it already was, is left untouched. {@code maven}'s
@@ -1596,8 +2497,8 @@ public class CodeArtifactService implements Resettable {
// against the raw caller-supplied count, before any deduplication below, so a request
// that only looks small after collapsing repeats still gets rejected.
int rawRequestedCount = hasVersions ? versions.size() : versionRevisions.size();
- if (rawRequestedCount > MAX_COPY_VERSIONS_PER_CALL) {
- throw validation("A single CopyPackageVersions call can copy at most " + MAX_COPY_VERSIONS_PER_CALL
+ if (rawRequestedCount > MAX_PACKAGE_VERSIONS_PER_BATCH_CALL) {
+ throw validation("A single CopyPackageVersions call can copy at most " + MAX_PACKAGE_VERSIONS_PER_BATCH_CALL
+ " versions.");
}
// A duplicate requested version (whether from a caller-supplied repeat in versions, or
@@ -1641,7 +2542,7 @@ public class CodeArtifactService implements Resettable {
hasRevisions, allowOverwrite);
}
- Map<String, PackageVersionCopyFailure> failures = new LinkedHashMap<>();
+ Map<String, PackageVersionError> failures = new LinkedHashMap<>();
List<String> pendingCopies = new ArrayList<>();
Map<String, CodeArtifactPackageVersion> sourceByVersion = new LinkedHashMap<>();
for (String version : requestedVersions) {
@@ -1649,14 +2550,27 @@ public class CodeArtifactService implements Resettable {
version);
CodeArtifactPackageVersion sourcePv = packageVersions.getForAccount(owner, sourceKey).orElse(null);
if (sourcePv == null) {
- failures.put(version, new PackageVersionCopyFailure("NOT_FOUND", "Could not find version "
+ failures.put(version, new PackageVersionError("NOT_FOUND", "Could not find version "
+ version));
continue;
}
+ // Raised by Greptile's review: disposePackageVersions clears a generic version's
+ // assets but keeps its record around (so DescribePackageVersion keeps answering, the
+ // same reason the Disposed-destination check below exists), so a disposed source still
+ // passes the null check above with an empty asset map. Copying it, with
+ // allowOverwrite=true against a healthy destination, would otherwise overwrite that
+ // destination's real content and status with the disposed source's empty one while
+ // reporting success. Checked before the revision/content comparisons below, the same
+ // order checkStatusTransitionAllowed already checks Disposed in.
+ if ("Disposed".equals(sourcePv.getStatus())) {
+ failures.put(version, new PackageVersionError("NOT_ALLOWED", "Package version " + version
+ + " has already been disposed at the source and cannot be copied"));
+ continue;
+ }
if (hasRevisions) {
String expectedRevision = versionRevisions.get(version);
if (!sourcePv.getRevision().equals(expectedRevision)) {
- failures.put(version, new PackageVersionCopyFailure("MISMATCHED_REVISION",
+ failures.put(version, new PackageVersionError("MISMATCHED_REVISION",
"current revision: " + sourcePv.getRevision() + ", expected revision: "
+ expectedRevision));
continue;
@@ -1666,6 +2580,17 @@ public class CodeArtifactService implements Resettable {
packageName, version);
CodeArtifactPackageVersion destPv = packageVersions.getForAccount(owner, destKey).orElse(null);
if (destPv != null) {
+ // Raised by hectorvent's review, matching copyContainerBackedPackageVersions's own
+ // Disposed-destination guard: applyGenericStatusChange clears a disposed version's
+ // assets but keeps its record around (so DescribePackageVersion keeps answering),
+ // which means packageVersionContentMatches below can never see a match against an
+ // emptied asset map, and without this check the plain-overwrite branch would
+ // resurrect a destination the User Guide says "can no longer be used."
+ if ("Disposed".equals(destPv.getStatus())) {
+ failures.put(version, new PackageVersionError("NOT_ALLOWED", "Package version " + version
+ + " has already been disposed at the destination and cannot be republished"));
+ continue;
+ }
if (packageVersionContentMatches(sourcePv, destPv)) {
// Identical in both repositories already: AWS's own documented behavior is to
// treat this as an already-successful no-op, not copied and not listed in
@@ -1674,7 +2599,7 @@ public class CodeArtifactService implements Resettable {
continue;
}
if (!allowOverwrite) {
- failures.put(version, new PackageVersionCopyFailure("ALREADY_EXISTS",
+ failures.put(version, new PackageVersionError("ALREADY_EXISTS",
"Version " + version + " already exists"));
continue;
}
@@ -1685,7 +2610,7 @@ public class CodeArtifactService implements Resettable {
if (!failures.isEmpty()) {
for (String version : pendingCopies) {
- failures.put(version, new PackageVersionCopyFailure("SKIPPED", "Version " + version
+ failures.put(version, new PackageVersionError("SKIPPED", "Version " + version
+ " was skipped"));
}
return new CopyPackageVersionsResult(Map.of(), failures);
@@ -1701,12 +2626,12 @@ public class CodeArtifactService implements Resettable {
verifiedContentByVersion.put(version, verifyAndReadSourceAssets(owner, sourceByVersion.get(version)));
}
- Map<String, PackageVersionCopyOutcome> successes = new LinkedHashMap<>();
+ Map<String, SuccessfulPackageVersionInfo> successes = new LinkedHashMap<>();
for (String version : pendingCopies) {
CodeArtifactPackageVersion copied = copyGenericPackageVersionAssets(owner, region, domain,
destinationRepository, format, namespace, packageName, version, sourceByVersion.get(version),
verifiedContentByVersion.get(version));
- successes.put(version, new PackageVersionCopyOutcome(copied.getRevision(), copied.getStatus()));
+ successes.put(version, new SuccessfulPackageVersionInfo(copied.getRevision(), copied.getStatus()));
}
return new CopyPackageVersionsResult(successes, Map.of());
}
@@ -1753,7 +2678,7 @@ public class CodeArtifactService implements Resettable {
String sourceRepoId = ensureFormatContainerId(format, region, domain, owner, sourceRepository);
String destRepoId = ensureFormatContainerId(format, region, domain, owner, destinationRepository);
- Map<String, PackageVersionCopyFailure> failures = new LinkedHashMap<>();
+ Map<String, PackageVersionError> failures = new LinkedHashMap<>();
List<String> pendingCopies = new ArrayList<>();
Map<String, List<String>> sourceAssetNamesByVersion = new LinkedHashMap<>();
Map<String, List<String>> destAssetNamesByVersion = new LinkedHashMap<>();
@@ -1761,21 +2686,46 @@ public class CodeArtifactService implements Resettable {
for (String version : requestedVersions) {
if (!manager.packageVersionExists(sourceRepoId, domain, sourceRepository, namespace, packageName,
version)) {
- failures.put(version, new PackageVersionCopyFailure("NOT_FOUND", "Could not find version "
+ failures.put(version, new PackageVersionError("NOT_FOUND", "Could not find version "
+ version));
continue;
}
+ // Raised by Greptile's review: a Maven dispose failing partway through its own
+ // asset-deletion loop (see deleteContainerBackedVersionAssets's own javadoc)
+ // leaves the override reading Disposed while real files genuinely still remain
+ // in the version's own directory, so packageVersionExists above alone cannot
+ // tell a healthy source apart from a partly-disposed one. Checked against the
+ // override directly, the same way the generic path's own source-side guard
+ // already does, before this version's real files are ever listed or copied.
+ PackageVersionStatusOverride sourceOverride = currentContainerBackedVersionStatus(owner, region,
+ domain, sourceRepository, format, namespace, packageName, version, sourceRepoId);
+ if ("Disposed".equals(sourceOverride.status())) {
+ failures.put(version, new PackageVersionError("NOT_ALLOWED", "Package version " + version
+ + " has already been disposed at the source and cannot be copied"));
+ continue;
+ }
if (hasRevisions) {
String expectedRevision = versionRevisions.get(version);
- String actualRevision = synthesizeContainerBackedRevision(format, sourceRepoId, namespace,
- packageName, version);
+ String actualRevision = sourceOverride.revision();
if (!actualRevision.equals(expectedRevision)) {
- failures.put(version, new PackageVersionCopyFailure("MISMATCHED_REVISION",
+ failures.put(version, new PackageVersionError("MISMATCHED_REVISION",
"current revision: " + actualRevision + ", expected revision: "
+ expectedRevision));
continue;
}
}
+ // Checked regardless of destExists below: disposing a version deletes its real
+ // sidecar content, so a disposed destination coordinate almost always has
+ // destExists == false by the time anything copies into it again, even though the
+ // User Guide is explicit that Disposed "can no longer be used" and can never move
+ // to Published (the status this copy's own response would otherwise claim for it).
+ PackageVersionStatusOverride destOverride = currentContainerBackedVersionStatus(owner, region,
+ domain, destinationRepository, format, namespace, packageName, version, destRepoId);
+ if ("Disposed".equals(destOverride.status())) {
+ failures.put(version, new PackageVersionError("NOT_ALLOWED", "Package version " + version
+ + " has already been disposed at the destination and cannot be republished"));
+ continue;
+ }
List<String> sourceAssetNames = manager.listPackageVersionAssetNames(sourceRepoId, domain,
sourceRepository, namespace, packageName, version);
boolean destExists = manager.packageVersionExists(destRepoId, domain, destinationRepository,
@@ -1792,7 +2742,7 @@ public class CodeArtifactService implements Resettable {
continue;
}
if (!allowOverwrite) {
- failures.put(version, new PackageVersionCopyFailure("ALREADY_EXISTS",
+ failures.put(version, new PackageVersionError("ALREADY_EXISTS",
"Version " + version + " already exists"));
continue;
}
@@ -1808,7 +2758,7 @@ public class CodeArtifactService implements Resettable {
if (!failures.isEmpty()) {
for (String version : pendingCopies) {
- failures.put(version, new PackageVersionCopyFailure("SKIPPED", "Version " + version
+ failures.put(version, new PackageVersionError("SKIPPED", "Version " + version
+ " was skipped"));
}
return new CopyPackageVersionsResult(Map.of(), failures);
@@ -1832,7 +2782,7 @@ public class CodeArtifactService implements Resettable {
verifiedContentByVersion.put(version, contentByAsset);
}
- Map<String, PackageVersionCopyOutcome> successes = new LinkedHashMap<>();
+ Map<String, SuccessfulPackageVersionInfo> successes = new LinkedHashMap<>();
for (String version : pendingCopies) {
List<String> destAssetNames = destAssetNamesByVersion.getOrDefault(version, List.of());
Map<String, byte[]> originalContent = new LinkedHashMap<>();
@@ -1893,8 +2843,16 @@ public class CodeArtifactService implements Resettable {
}
copyCapturedReadmeIfApplicable(region, domain, owner, sourceRepository, destinationRepository, format,
namespace, packageName, version);
+ // Drops any status override left over from whatever used to be at this destination
+ // coordinate (an Archived version this copy's allowOverwrite just replaced, most
+ // concretely): the response below reports Published, and a stale override would
+ // otherwise keep describing (and keep requireAssetDownloadable blocking downloads of)
+ // content that no longer matches what is now really there. A destination that
+ // never had an override is an inexpensive no-op (see that method's own javadoc).
+ clearContainerBackedStatusOverride(owner, region, domain, destinationRepository, format, namespace,
+ packageName, version);
String revision = synthesizeContainerBackedRevision(format, destRepoId, namespace, packageName, version);
- successes.put(version, new PackageVersionCopyOutcome(revision, "Published"));
+ successes.put(version, new SuccessfulPackageVersionInfo(revision, "Published"));
}
return new CopyPackageVersionsResult(successes, Map.of());
}
@@ -2135,7 +3093,7 @@ public class CodeArtifactService implements Resettable {
* <p>Neither npm nor pypi can be answered live from the sidecar itself, confirmed directly
* rather than assumed for either one. npm: a real npm client's publish envelope does carry a
* per-version {@code readme} (confirmed against a real captured publish fixture), but
- * Verdaccio's own packument response does not echo it back — checked against a live Verdaccio
+ * Verdaccio's own packument response does not echo it back, checked against a live Verdaccio
* container, which hoists {@code readme} to the top level only, for the single
* most-recently-published version, truncated to 64K, exactly like real npmjs.org's own
* documented response shape; the per-version field in a GET response simply does not exist.
@@ -2173,7 +3131,8 @@ public class CodeArtifactService implements Resettable {
String owner = effectiveOwner(domainOwner);
requireRepository(owner, repositoryKey(region, domain, repository), repository);
String repoId = ensureFormatContainerId(format, region, domain, owner, repository);
- String revision = synthesizeContainerBackedRevision(format, repoId, namespace, packageName, version);
+ String revision = currentContainerBackedVersionStatus(owner, region, domain, repository, format, namespace,
+ packageName, version, repoId).revision();
if ("nuget".equals(format)) {
String readme = sidecarRegistry.forFormat(format)
.flatMap(manager -> manager.fetchPackageVersionReadme(repoId, domain, repository, namespace,
@@ -2220,7 +3179,7 @@ public class CodeArtifactService implements Resettable {
*
* <p>{@code packageFenceSnapshot} is whatever {@link #currentContainerBackedPackageFence}
* returned when the proxy called it, right before issuing the real write this call reports the
- * readme of — the exact same snapshot the proxy already takes to call
+ * readme of, the exact same snapshot the proxy already takes to call
* {@link #recordContainerBackedAssetBytes}. Without comparing it here too, a publish's readme
* capture that runs on a delayed callback (npm's own, off the event loop) after a concurrent
* {@link #deletePackage} or native unpublish has already removed this package would resurrect
@@ -2365,6 +3324,8 @@ public class CodeArtifactService implements Resettable {
containerBackedAssetBytes.clear();
containerBackedPackageDeletionFence.clear();
packageVersionReadmes.clear();
+ containerBackedPackageVersionStatusOverrides.clear();
+ containerBackedOverriddenVersionsByPackage.clear();
authorizationTokens.clear();
if (inMemory) {
memoryAssetStore.clear();
@@ -2596,6 +3557,15 @@ public class CodeArtifactService implements Resettable {
.filter(k -> k.startsWith(readmePrefix))
.toList()
.forEach(packageVersionReadmes::remove);
+ // Same key/prefix, same reasoning: a native unpublish removed this package's real sidecar
+ // content directly, so any status override updatePackageVersionsStatus/
+ // disposePackageVersions previously recorded for one of its versions would otherwise keep
+ // describing a package that, as far as the sidecar is concerned, no longer exists at all.
+ containerBackedPackageVersionStatusOverrides.keySet().stream()
+ .filter(k -> k.startsWith(readmePrefix))
+ .toList()
+ .forEach(containerBackedPackageVersionStatusOverrides::remove);
+ containerBackedOverriddenVersionsByPackage.remove(ownerScopedKey);
}
/**
@@ -2632,6 +3602,21 @@ public class CodeArtifactService implements Resettable {
return packageName;
}
+ /**
+ * Raised by Greptile's review of this PR: the override map's own key building left {@code
+ * version} exactly as the caller spelled it, while {@link BagetterSidecarClient}'s own version
+ * matching (see {@link #synthesizeContainerBackedRevision}'s own javadoc) already treats two
+ * equivalent NuGet spellings (AWS's own worked example, {@code 1.00} and {@code 1.0.0}) as the
+ * same stored version. Without this, archiving one spelling left the other still resolving to
+ * the implicit {@code Published} default everywhere an override is read, exactly like
+ * {@link #accountingPackageName} already normalizes the package name half of the same key for
+ * pypi/nuget; this is its version-string counterpart, applied only for {@code nuget} since
+ * Maven/npm/pypi match the literal version string with no such aliasing to account for.
+ */
+ private static String normalizedContainerBackedVersion(String format, String version) {
+ return "nuget".equals(format) ? NuGetVersions.normalize(version) : version;
+ }
+
private int domainCountForAccount(String owner, String region) {
return domains.scanForAccount(owner, k -> k.startsWith(region + "::")).size();
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/NpmPublishEnvelopeScanner.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/NpmPublishEnvelopeScanner.java
index 6967dd71ff..ee1653a80a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/NpmPublishEnvelopeScanner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/NpmPublishEnvelopeScanner.java
@@ -53,6 +53,29 @@ final class NpmPublishEnvelopeScanner {
.build())
.build();
+ /**
+ * Raised by Greptile's review: {@link CodeArtifactNpmDataPlane#checkRepublish}'s own
+ * Archived/Disposed guard needs to know which versions a publish names even when {@link
+ * #FACTORY}'s own stricter limit throws, the real way a legitimate publish whose per-version
+ * {@code readme} exceeds {@code maxStringLength} (1,000,000 characters is generous for
+ * almost any real README, but not unbounded) reaches that catch block. Jackson's own
+ * {@code maxStringLength} enforcement happens while the tokenizer itself scans a string
+ * token to find its end, during {@code nextToken()}, not lazily when a caller later reads
+ * its value, so there is no way to skip past an oversized field with {@link #FACTORY}'s own
+ * limit still in force; only a parse with a higher one can get past it at all. This ceiling
+ * is still bounded, not unlimited, specifically so a truly pathological payload still fails
+ * both this and {@link #FACTORY}'s own parse and is rejected outright by the caller rather
+ * than silently forwarded with no guard having run at all.
+ */
+ private static final JsonFactory LENIENT_FACTORY = JsonFactory.builder()
+ .enable(StreamReadFeature.STRICT_DUPLICATE_DETECTION)
+ .streamReadConstraints(StreamReadConstraints.builder()
+ .maxNestingDepth(32)
+ .maxNumberLength(1_000_000)
+ .maxStringLength(64_000_000)
+ .build())
+ .build();
+
@FunctionalInterface
private interface FieldHandler {
void accept(String fieldName) throws IOException;
@@ -69,7 +92,25 @@ final class NpmPublishEnvelopeScanner {
}
static Envelope scan(InputStream in) throws IOException {
- try (JsonParser parser = FACTORY.createParser(in)) {
+ return scan(in, FACTORY);
+ }
+
+ /**
+ * {@link #LENIENT_FACTORY}'s own fallback parse, for a caller ({@link
+ * CodeArtifactNpmDataPlane#checkRepublish}) that still needs {@code versions()}' own key set
+ * once {@link #scan} itself has already thrown; see that factory's own javadoc for why a
+ * second, more tolerant pass is the only way to recover it at all. Its {@code readme} and
+ * {@code attachments} are not meant to be trusted the way {@link #scan}'s own result is (the
+ * whole reason this parse exists is that {@link #scan} itself refused to vouch for one of
+ * those same fields), so a caller must only ever read {@code versions().keySet()} from this,
+ * never anything else about the Envelope it returns.
+ */
+ static Envelope scanLeniently(InputStream in) throws IOException {
+ return scan(in, LENIENT_FACTORY);
+ }
+
+ private static Envelope scan(InputStream in, JsonFactory factory) throws IOException {
+ try (JsonParser parser = factory.createParser(in)) {
NpmPublishEnvelopeScanner scanner = new NpmPublishEnvelopeScanner(parser);
scanner.parseEnvelope();
return scanner.envelope();
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
index afa0c6d72e..740de7d2e4 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/PypiserverSidecarClient.java
@@ -538,8 +538,19 @@ public class PypiserverSidecarClient implements RepositorySidecarManager {
* at version {@code 2.0} produces {@code foo-1.0-bar-2.0.tar.gz}, and the text {@code -1.0-}
* inside that name would otherwise look like a complete, valid version {@code 1.0} to a
* caller who asked for the wrong one.
+ *
+ * <p>Not {@code private} for exactly one other reason (Greptile's review of this PR):
+ * {@code CodeArtifactPypiController#upload} calls this on the way in, the opposite direction
+ * from every other caller here. pypiserver itself files an upload under the identity this
+ * same boundary logic derives from its filename, never from the multipart form's own
+ * {@code name}/{@code version} fields; those fields are only ever used, until this check
+ * existed, to pick which coordinate the Archived/Disposed guard and the override-clearing
+ * call afterward run against. A form whose fields name an unrelated (unused, never
+ * Archived/Disposed) coordinate while the real filename matches a disposed one would let the
+ * guard see the harmless coordinate, the real upload land under the disposed one regardless,
+ * and the override-clearing call afterward operate on the wrong version too.
*/
- private static boolean filenameEmbedsVersion(String assetName, String packageName, String version) {
+ static boolean filenameEmbedsVersion(String assetName, String packageName, String version) {
String normalizedPackageName = normalizePackageName(packageName);
String marker = "-" + version;
for (int idx = assetName.indexOf(marker); idx >= 0; idx = assetName.indexOf(marker, idx + 1)) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
index b7463f097c..ceaf912e9b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClient.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.core.common.XmlParser;
import jakarta.enterprise.context.ApplicationScoped;
@@ -54,6 +55,14 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
/** Real Maven metadata's own documented {@code lastUpdated} shape: UTC, {@code yyyyMMddHHmmss}. */
private static final DateTimeFormatter METADATA_TIMESTAMP = DateTimeFormatter.ofPattern("yyyyMMddHHmmss")
.withZone(ZoneOffset.UTC);
+ /**
+ * The two checksum extensions a real {@code mvn deploy} always PUTs alongside {@code
+ * maven-metadata.xml} itself (confirmed against a real deploy's own request log): SHA-1 and
+ * MD5, Maven's two long-standing defaults. SHA-256/SHA-512 are a newer, still-optional addition
+ * no client this repository's own integration tests exercise ever sends, so neither is handled
+ * by {@link #recordVersionDisposed}'s own checksum upkeep.
+ */
+ private static final List<String> METADATA_CHECKSUM_EXTENSIONS = List.of("sha1", "md5");
private final ReposiliteSidecarManager manager;
private final ObjectMapper mapper;
@@ -469,6 +478,201 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
deployArtifact(repositoryContainerId, gav, metadata.build().getBytes(StandardCharsets.UTF_8));
}
+ /**
+ * {@link #recordVersionAvailable}'s dispose-time counterpart (found missing by Qodo review on
+ * the PR that added {@code DisposePackageVersions}): without this, a disposed Maven version's
+ * real asset files are gone from its own version directory, but {@code mvn}/{@code gradle}
+ * resolving dependencies straight against the artifact-level {@code maven-metadata.xml} (not
+ * through this emulator's own {@code ListPackageVersions}, which already reads the override
+ * store and correctly stops reporting it) would keep seeing it listed as available. Removes
+ * {@code version} from the metadata's own {@code versions} list and recomputes {@code latest}/
+ * {@code release} from whatever remains, in the same append order the metadata already
+ * preserves: the list is never re-sorted, so its last surviving entry is still the most
+ * recently deployed one, exactly the same invariant {@link #recordVersionAvailable} relies on
+ * when adding to it. A metadata file that would end up with no versions left is deleted
+ * outright rather than written back empty, matching how a package that never had a version
+ * published has no metadata file at all. A missing metadata file, or one that never named this
+ * version to begin with (both possible if this is called more than once, or for a version
+ * recorded before {@code maven-metadata.xml} existed), is a no-op either way.
+ *
+ * <p>Raised by Greptile's review: both the DELETE below (when no version is left to list) and
+ * the rewrite ({@link #deployArtifact}) ignored whatever Reposilite actually answered, so a
+ * disposal could report success while the metadata on disk still named the just-deleted
+ * version. Checked against the exact same {@code IllegalStateException}-on-failure convention
+ * {@link #deletePackageVersionAsset} already uses for the asset deletes this runs after (see
+ * {@code CodeArtifactService#deleteContainerBackedVersionAssets}'s own javadoc for why this
+ * runs last): a thrown exception here propagates the same way a failed asset delete already
+ * does, rather than this method silently reporting a metadata update that never actually took.
+ *
+ * <p>Also raised by Greptile's review: a real {@code mvn deploy} always PUTs {@code
+ * maven-metadata.xml.sha1}/{@code .md5} right alongside the metadata file itself, so this
+ * method's own server-side rewrite (or removal) of the metadata content must carry those two
+ * checksum siblings along with it ({@link #METADATA_CHECKSUM_EXTENSIONS}): left untouched, a
+ * Maven client verifying the checksum of the metadata it just fetched would see it disagree
+ * with content this method itself just changed underneath it.
+ *
+ * <p>Raised again by Greptile's review, once a dispose retry (see {@code
+ * CodeArtifactService#checkStatusTransitionAllowed}'s own javadoc) became possible: a retry
+ * whose first attempt already finished the metadata rewrite or removal, but then failed on
+ * exactly a checksum write or delete, used to hit one of the two early returns below and
+ * report success without ever repairing that stale checksum, since neither {@code existing}
+ * being empty nor {@code version} being already absent from it means the checksums are
+ * actually right. Both early-return branches now repair the checksums too, every time, not
+ * just on the one call that happened to also touch the metadata itself.
+ *
+ * <p>Raised again by Greptile's review: {@link #fetchArtifact} itself returns {@code empty()}
+ * for every non-200 response, 500/503 included, the same conflation {@link
+ * #deleteArtifactIfPresent}'s own existence check already had fixed for it. A transient read
+ * failure here looked identical to "the metadata file genuinely does not exist," which would
+ * delete the checksums and report a successful disposal while the metadata on disk still
+ * named the version this was supposed to remove. Reads the metadata through a dedicated check
+ * that only takes the empty branch on a confirmed 404, throwing on anything else, the same
+ * convention {@link #deleteArtifactIfPresent}'s own HEAD check already uses.
+ *
+ * <p>Known, documented gap left out of scope (also raised by Greptile's review): this
+ * method's own read-modify-write of {@code maven-metadata.xml} has no lock around it, so a
+ * concurrent {@link #recordVersionAvailable} (a native {@code mvn deploy} adding a different
+ * version to the same artifact) that reads the file between this method's own read and write
+ * can have its update silently overwritten by this call's stale copy, or removed outright if
+ * this call's own last-version branch deletes the file instead. This is not new: {@link
+ * #recordVersionAvailable} already has the identical unlocked read-modify-write shape on its
+ * own, so two concurrent deploys of different versions to the same artifact can already lose
+ * one's update today, with no disposal involved at all. This method is simply a second
+ * caller that inherits that same pre-existing hole rather than one that introduces it.
+ * Coordinating every writer of this one file (a lock keyed by repository and artifact,
+ * shared across every caller) is a real fix, just not one scoped to adding {@code
+ * DisposePackageVersions} itself; tracked separately rather than folded in here.
+ */
+ @Override
+ public void recordVersionDisposed(String repositoryContainerId, String namespace, String packageName,
+ String version) {
+ String gav = artifactMetadataGav(namespace, packageName);
+ Optional<FetchedArtifact> existing = fetchArtifactConfirmingMissing(repositoryContainerId, gav);
+ if (existing.isEmpty()) {
+ for (String extension : METADATA_CHECKSUM_EXTENSIONS) {
+ deleteArtifactIfPresent(repositoryContainerId, gav + "." + extension);
+ }
+ return;
+ }
+ String xml = new String(existing.get().content(), StandardCharsets.UTF_8);
+ List<String> versions = new ArrayList<>(XmlParser.extractAll(xml, "version"));
+ if (!versions.remove(version)) {
+ writeMetadataChecksum(repositoryContainerId, gav + ".sha1", Digests.sha1Hex(existing.get().content()));
+ writeMetadataChecksum(repositoryContainerId, gav + ".md5", Digests.md5Hex(existing.get().content()));
+ return;
+ }
+ String baseUrl = manager.ensureReady();
+ if (versions.isEmpty()) {
+ HttpRequest request = authenticated(baseUrl, repositoryContainerId, gav).DELETE().build();
+ HttpResponse<Void> response = send(request, BodyHandlers.discarding());
+ if (response.statusCode() != 200) {
+ throw new IllegalStateException("Could not remove " + packageName + "'s maven-metadata.xml from "
+ + "the Reposilite sidecar after disposing its last version " + version
+ + ": upstream returned " + response.statusCode());
+ }
+ for (String extension : METADATA_CHECKSUM_EXTENSIONS) {
+ deleteArtifactIfPresent(repositoryContainerId, gav + "." + extension);
+ }
+ return;
+ }
+ String groupId = XmlParser.extractFirst(xml, "groupId", namespace);
+ String artifactId = XmlParser.extractFirst(xml, "artifactId", packageName);
+ String latest = versions.get(versions.size() - 1);
+ String release = null;
+ for (int i = versions.size() - 1; i >= 0; i--) {
+ if (!versions.get(i).endsWith("-SNAPSHOT")) {
+ release = versions.get(i);
+ break;
+ }
+ }
+ XmlBuilder metadata = new XmlBuilder().start("metadata")
+ .elem("groupId", groupId)
+ .elem("artifactId", artifactId)
+ .start("versioning")
+ .elem("latest", latest)
+ .elem("release", release)
+ .start("versions");
+ for (String v : versions) {
+ metadata.elem("version", v);
+ }
+ metadata.end("versions")
+ .elem("lastUpdated", METADATA_TIMESTAMP.format(Instant.now()))
+ .end("versioning")
+ .end("metadata");
+ byte[] metadataBytes = metadata.build().getBytes(StandardCharsets.UTF_8);
+ DeployOutcome outcome = deployArtifact(repositoryContainerId, gav, metadataBytes);
+ if (!outcome.wroteNewContent()) {
+ throw new IllegalStateException("Could not update " + packageName + "'s maven-metadata.xml on the "
+ + "Reposilite sidecar after disposing version " + version + ": upstream returned "
+ + outcome.status());
+ }
+ writeMetadataChecksum(repositoryContainerId, gav + ".sha1", Digests.sha1Hex(metadataBytes));
+ writeMetadataChecksum(repositoryContainerId, gav + ".md5", Digests.md5Hex(metadataBytes));
+ }
+
+ /** {@link #recordVersionDisposed}'s own checksum-rewrite counterpart to {@link #deployArtifact}. */
+ /**
+ * Raised by Greptile's review: {@code wroteNewContent()} is {@code false} both for a genuine
+ * failure and for {@link #deployArtifact}'s own idempotent short-circuit (the checksum
+ * already on the sidecar matches {@code hex} byte for byte, so nothing needed to be sent at
+ * all), and checking it alone could not tell the two apart. A disposal retry whose {@code
+ * .sha1} write already landed on an earlier attempt, but then failed on {@code .md5}, would
+ * see that already-correct {@code .sha1} hit this exact short-circuit every time, getting
+ * flagged as a failure that stopped the retry before it ever reached {@code .md5} again. Only
+ * the real HTTP status is checked now, the same success codes {@link #deployArtifact} itself
+ * already treats as success.
+ */
+ private void writeMetadataChecksum(String repositoryContainerId, String checksumGav, String hex) {
+ DeployOutcome outcome = deployArtifact(repositoryContainerId, checksumGav,
+ hex.getBytes(StandardCharsets.UTF_8));
+ if (outcome.status() != 200 && outcome.status() != 201) {
+ throw new IllegalStateException("Could not update checksum " + checksumGav + " on the Reposilite "
+ + "sidecar: upstream returned " + outcome.status());
+ }
+ }
+
+ /**
+ * {@link #recordVersionDisposed}'s own checksum-removal counterpart, for the case where the
+ * metadata file itself is removed outright rather than rewritten. A checksum that was never
+ * there to begin with (a client that only ever pushed one of the two, or a sidecar restored
+ * from a snapshot older than this method) is a no-op, the same tolerance {@link
+ * #recordVersionDisposed} already extends to a metadata file missing version to begin with.
+ *
+ * <p>Checks existence with a HEAD first rather than guessing at a "not found" status for the
+ * DELETE itself: confirmed against a real Reposilite instance, deleting a path that was never
+ * there returns 500, not 404, so treating 404 as the tolerated case (as an earlier version of
+ * this method did) still threw on the common case of a checksum a real {@code mvn deploy}
+ * simply never pushed.
+ *
+ * <p>Raised by Greptile's review: {@link #artifactExists} itself treats every non-200 HEAD
+ * response as "absent," 500/503 included, which would let a genuine sidecar failure here look
+ * identical to a confirmed-missing checksum and silently skip the delete instead of surfacing
+ * it. This checks the HEAD status directly instead, so only a confirmed 404 is tolerated as
+ * absent; anything else (a real error, not a clean answer either way) throws, the same
+ * {@code IllegalStateException}-on-failure convention this method's own DELETE already uses,
+ * so a caller can tell a skipped-because-confirmed-gone checksum apart from one this could not
+ * even check.
+ */
+ private void deleteArtifactIfPresent(String repositoryContainerId, String gav) {
+ String baseUrl = manager.ensureReady();
+ HttpRequest headRequest = authenticated(baseUrl, repositoryContainerId, gav)
+ .method("HEAD", BodyPublishers.noBody()).build();
+ int headStatus = send(headRequest, BodyHandlers.discarding()).statusCode();
+ if (headStatus == 404) {
+ return;
+ }
+ if (headStatus != 200) {
+ throw new IllegalStateException("Could not check whether " + gav + " exists on the Reposilite "
+ + "sidecar before deleting it: upstream returned " + headStatus);
+ }
+ HttpRequest request = authenticated(baseUrl, repositoryContainerId, gav).DELETE().build();
+ HttpResponse<Void> response = send(request, BodyHandlers.discarding());
+ if (response.statusCode() != 200) {
+ throw new IllegalStateException("Could not delete " + gav + " from the Reposilite sidecar: upstream "
+ + "returned " + response.statusCode());
+ }
+ }
+
private static String artifactMetadataGav(String namespace, String packageName) {
return namespace.replace('.', '/') + "/" + packageName + "/maven-metadata.xml";
}
@@ -712,6 +916,28 @@ public class ReposiliteSidecarClient implements RepositorySidecarManager {
return fetchArtifact(manager.ensureReady(), repoId, gav);
}
+ /**
+ * {@link #recordVersionDisposed}'s own counterpart to {@link #fetchArtifact}: that method's
+ * {@code empty()} is not safe to read as "confirmed absent" everywhere, since it also means
+ * "any non-200," 500/503 included. This only takes the empty branch on an actual 404,
+ * throwing on anything else so a transient read failure is surfaced rather than treated as
+ * the file never having existed.
+ */
+ private Optional<FetchedArtifact> fetchArtifactConfirmingMissing(String repositoryContainerId, String gav) {
+ String baseUrl = manager.ensureReady();
+ HttpRequest request = authenticated(baseUrl, repositoryContainerId, gav).GET().build();
+ HttpResponse<byte[]> response = send(request, BodyHandlers.ofByteArray());
+ if (response.statusCode() == 404) {
+ return Optional.empty();
+ }
+ if (response.statusCode() != 200) {
+ throw new IllegalStateException("Could not read " + gav + " from the Reposilite sidecar: upstream "
+ + "returned " + response.statusCode());
+ }
+ String contentType = response.headers().firstValue("Content-Type").orElse("application/octet-stream");
+ return Optional.of(new FetchedArtifact(response.body(), contentType));
+ }
+
private Optional<FetchedArtifact> fetchArtifact(String baseUrl, String repoId, String gav) {
HttpRequest request = authenticated(baseUrl, repoId, gav).GET().build();
HttpResponse<byte[]> response = send(request, BodyHandlers.ofByteArray());
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/RepositorySidecarManager.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/RepositorySidecarManager.java
index 881260e80a..dec946a69b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/codeartifact/RepositorySidecarManager.java
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/RepositorySidecarManager.java
@@ -236,6 +236,19 @@ public interface RepositorySidecarManager {
default void endUse(String repositoryContainerId) {
}
+ /**
+ * Called once per version, after every one of its assets has already been removed through
+ * {@link #deletePackageVersionAsset}, for a sidecar whose own native listing can name a
+ * version somewhere other than the per-version assets {@link #listPackageVersionAssetNames}
+ * already enumerates: Maven's artifact-level {@code maven-metadata.xml}, which {@code
+ * ReposiliteSidecarClient} overrides this to rewrite. Default is a no-op: a sidecar with no
+ * such separate listing (every format {@code DisposePackageVersions} supports besides Maven)
+ * already has nothing left to say the version ever existed once its assets are gone.
+ */
+ default void recordVersionDisposed(String repositoryContainerId, String namespace, String packageName,
+ String version) {
+ }
+
/**
* This format's own preferred "default display" version for a package, independent of publish
* recency, for {@code ListPackageVersions}' {@code defaultDisplayVersion}. {@code empty()} by
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactAssetPersistenceTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactAssetPersistenceTest.java
index cff34bcd49..0f52219c51 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactAssetPersistenceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactAssetPersistenceTest.java
@@ -30,6 +30,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.logging.LogRecord;
import java.util.stream.Stream;
@@ -455,6 +456,102 @@ class CodeArtifactAssetPersistenceTest {
assertEquals("ResourceNotFoundException", gone.getErrorCode());
}
+ /**
+ * Qodo review finding on the PR that added {@code DisposePackageVersions}: unlike {@code
+ * deletePackage} (whose version record is already gone by the time its own best-effort asset
+ * cleanup runs, so a failure there can never be reached again), a disposed version's record
+ * is kept around: {@code DescribePackageVersion} must keep answering for it. The dispose path
+ * used to catch and log a failed delete the same way {@code deletePackage} does, then still
+ * mark the version Disposed and clear its asset map regardless, permanently orphaning bytes
+ * that record could no longer point back to. The same {@link DirectoryNotEmptyException} trick
+ * as {@link #deletingAnAssetsBytesFailingStillRemovesTheVersionRecordAndCleansUpTheOtherAsset}
+ * forces a real delete failure.
+ *
+ * <p>Raised again by Greptile's review: this now also proves the status write itself runs
+ * <em>before</em> the delete, not after (see {@code applyGenericStatusChange}'s own javadoc).
+ * The version reads {@code Disposed} (blocking downloads immediately) rather than staying
+ * {@code Published} with a broken asset still reachable, even though this one real asset's
+ * own delete never actually succeeded.
+ */
+ @Test
+ void disposePackageVersionsPropagatesAFailedAssetDeletionInsteadOfReportingSuccess(@TempDir Path dir)
+ throws IOException {
+ CodeArtifactService service = newService(dir);
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ byte[] content = "v1".getBytes(StandardCharsets.UTF_8);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "false", content);
+
+ Path assetFile;
+ try (Stream<Path> paths = Files.walk(dir.resolve("codeartifact-assets"))) {
+ assetFile = paths.filter(Files::isRegularFile).filter(p -> matchesContent(p, content))
+ .findFirst().orElseThrow();
+ }
+ Files.delete(assetFile);
+ Files.createDirectory(assetFile);
+ Files.createFile(assetFile.resolve("not-empty"));
+
+ UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> service.disposePackageVersions(
+ REGION, "dom", null, "repo", "generic", "ns", "pkg", List.of("1.0.0"), null, null));
+ assertTrue(e.getCause() instanceof DirectoryNotEmptyException, "expected the real delete failure to "
+ + "propagate rather than being swallowed, got cause: " + e.getCause());
+
+ CodeArtifactPackageVersion pv = service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "pkg", "1.0.0");
+ assertEquals("Disposed", pv.getStatus(), "the status write runs before the delete, so a failed delete "
+ + "must still leave the version blocked rather than reading as the untouched Published it no "
+ + "longer really is");
+ assertEquals(1, pv.getAssets().size(), "the one asset whose own delete failed is never removed from the "
+ + "record (only a successfully deleted asset is), but is still unreachable through downloads "
+ + "now that the version itself reads Disposed");
+ AwsException blocked = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom",
+ null, "repo", "generic", "ns", "pkg", "1.0.0", "a.txt", null));
+ assertEquals("ResourceNotFoundException", blocked.getErrorCode());
+ }
+
+ /**
+ * Raised by Greptile's review: proves the per-asset bookkeeping, not just the upfront status
+ * write above. With two assets, one whose delete succeeds and one whose delete then fails,
+ * the record must name only the one that genuinely never got deleted, not the one already
+ * gone, so a retry (now let through for an already-{@code Disposed} version, see {@code
+ * checkStatusTransitionAllowed}'s own javadoc) picks up exactly where this attempt stopped.
+ */
+ @Test
+ void disposePackageVersionsRemovesEachAssetFromTheRecordRightAfterItsOwnSuccessfulDelete(@TempDir Path dir)
+ throws IOException {
+ CodeArtifactService service = newService(dir);
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ byte[] contentA = "content of a".getBytes(StandardCharsets.UTF_8);
+ byte[] contentB = "content of b".getBytes(StandardCharsets.UTF_8);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(contentA), "true", contentA);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "b.txt",
+ Digests.sha256Hex(contentB), "true", contentB);
+
+ Path assetFileA;
+ Path assetFileB;
+ try (Stream<Path> paths = Files.walk(dir.resolve("codeartifact-assets"))) {
+ List<Path> files = paths.filter(Files::isRegularFile).toList();
+ assetFileA = files.stream().filter(p -> matchesContent(p, contentA)).findFirst().orElseThrow();
+ assetFileB = files.stream().filter(p -> matchesContent(p, contentB)).findFirst().orElseThrow();
+ }
+ Files.delete(assetFileB);
+ Files.createDirectory(assetFileB);
+ Files.createFile(assetFileB.resolve("not-empty"));
+
+ assertThrows(UncheckedIOException.class, () -> service.disposePackageVersions(REGION, "dom", null, "repo",
+ "generic", "ns", "my-pkg", List.of("1.0.0"), null, null));
+
+ assertFalse(Files.exists(assetFileA), "the asset whose own delete succeeded must still be gone");
+ CodeArtifactPackageVersion pv = service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "my-pkg", "1.0.0");
+ assertEquals("Disposed", pv.getStatus());
+ assertEquals(Set.of("b.txt"), pv.getAssets().keySet(), "only the asset whose delete never actually "
+ + "succeeded should still be named in the record");
+ }
+
private static boolean matchesContent(Path file, byte[] expected) {
try {
return Arrays.equals(Files.readAllBytes(file), expected);
@@ -467,7 +564,7 @@ class CodeArtifactAssetPersistenceTest {
* Found by Qodo review: {@code copyPackageVersions} used to read and write each version's
* assets inline inside its own commit loop, so a later version's corrupted source bytes
* would be discovered only after an earlier, otherwise-valid version in the same batch was
- * already committed to the destination — the per-call all-or-nothing contract AWS documents
+ * already committed to the destination, the per-call all-or-nothing contract AWS documents
* for the caller-visible failure codes, silently broken for this emulator-internal one.
* Every pending version's source assets are now verified against their persisted hashes
* before any version in the batch has anything written to the destination at all.
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
index 3c5dc41d6a..7ab3b714ed 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactMavenDockerIntegrationTest.java
@@ -632,6 +632,43 @@ class CodeArtifactMavenDockerIntegrationTest {
+ defaultDisplayVersion);
}
+ /**
+ * A throwaway groupId/artifactId, not {@link #GAV}: disposing it is destructive (the real
+ * assets are gone afterward), and must not disturb the artifact every other test in this class
+ * shares. Confirms the whole real round trip: {@code DisposePackageVersions} deletes the real
+ * jar/pom through Reposilite's own asset-delete endpoint, a subsequent fetch 404s, and
+ * {@code ListPackageVersions} still reports the version, by status {@code Disposed} alone,
+ * since the real sidecar listing no longer names it at all once its content is gone.
+ */
+ @Test
+ @Order(23)
+ void disposePackageVersionsDeletesTheRealReposiliteAssetsAndKeepsListingTheVersionAsDisposed() {
+ byte[] content = "dispose-me-bytes".getBytes(StandardCharsets.UTF_8);
+ given().header("Authorization", "Bearer " + bearerToken).body(content)
+ .put("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/com/example/disposeme/1.0.0/disposeme-1.0.0.jar")
+ .then().statusCode(200);
+
+ given().contentType("application/json").header("Authorization", AUTH)
+ .body("{\"versions\":[\"1.0.0\"]}")
+ .post("/v1/package/versions/dispose?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
+ + "&namespace=com.example&package=disposeme")
+ .then().statusCode(200)
+ .body("successfulVersions['1.0.0'].status", equalTo("Disposed"))
+ .body("failedVersions.size()", equalTo(0));
+
+ given().header("Authorization", "Bearer " + bearerToken)
+ .get("/codeartifact/maven/" + DOMAIN + "/" + REPO + "/com/example/disposeme/1.0.0/disposeme-1.0.0.jar")
+ .then().statusCode(404);
+
+ given().header("Authorization", AUTH)
+ .post("/v1/package/versions?domain=" + DOMAIN + "&repository=" + REPO + "&format=maven"
+ + "&namespace=com.example&package=disposeme&status=Disposed")
+ .then().statusCode(200)
+ .body("versions.size()", equalTo(1))
+ .body("versions[0].version", equalTo("1.0.0"))
+ .body("versions[0].status", equalTo("Disposed"));
+ }
+
/**
* A throwaway groupId/artifactId, not {@link #GAV}: deleting it exercises Reposilite's real
* directory delete (confirmed live before this was built: a single {@code DELETE} on the
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlaneTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlaneTest.java
index 8f3ccec635..203416acf2 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlaneTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactNpmDataPlaneTest.java
@@ -41,10 +41,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.when;
@@ -332,6 +336,130 @@ class CodeArtifactNpmDataPlaneTest {
assertEquals(true, upstreamReceivedPut.get());
}
+ /**
+ * Qodo review finding: a real npm publish that republishes a coordinate an earlier
+ * updatePackageVersionsStatus/disposePackageVersions call left Archived or Disposed must not
+ * leave that override standing over the fresh content this publish just forwarded.
+ */
+ @Test
+ void aPublishOfANewVersionClearsAnyStaleStatusOverrideForThatVersion() throws Exception {
+ upstream = vertx.createHttpServer()
+ .requestHandler(request -> request.response().setStatusCode(201).end())
+ .listen(0, "127.0.0.1")
+ .toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
+
+ CodeArtifactService service = mock(CodeArtifactService.class);
+ when(service.resolveAuthorizationToken("good-token", DOMAIN))
+ .thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
+ when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
+ .thenReturn(NPM_REPOSITORY_ID);
+ VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
+ when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
+ .thenReturn("http://127.0.0.1:" + upstream.actualPort());
+ startDataPlane(service, verdaccioClient);
+
+ HttpResponse response = put("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg", "good-token",
+ publishEnvelope("my-pkg", "1.0.0", "my-pkg-1.0.0.tgz",
+ "fresh bytes".getBytes(StandardCharsets.UTF_8)));
+
+ assertEquals(201, response.statusCode());
+ verify(service).forgetContainerBackedStatusOverrideIfUnchanged(eq("us-east-1"), eq(DOMAIN),
+ eq("000000000000"), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"), isNull());
+ }
+
+ /**
+ * hectorvent's review of this PR: the fix above only cleared a stale Archived/Disposed
+ * override after Verdaccio had already accepted the republished content, which the User
+ * Guide rules out unconditionally for both statuses. The publish must now be refused before it
+ * ever reaches Verdaccio.
+ */
+ @Test
+ void aPublishToAnArchivedOrDisposedVersionIsRejectedWithoutForwarding() throws Exception {
+ AtomicReference<Boolean> upstreamReceivedPut = new AtomicReference<>(false);
+ upstream = vertx.createHttpServer()
+ .requestHandler(request -> {
+ if (request.method() == HttpMethod.PUT) {
+ upstreamReceivedPut.set(true);
+ }
+ request.response().setStatusCode(201).end();
+ })
+ .listen(0, "127.0.0.1")
+ .toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
+
+ CodeArtifactService service = mock(CodeArtifactService.class);
+ when(service.resolveAuthorizationToken("good-token", DOMAIN))
+ .thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
+ when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
+ .thenReturn(NPM_REPOSITORY_ID);
+ doThrow(new AwsException("ConflictException", "Package version '1.0.0' of package 'my-pkg' is Archived "
+ + "and cannot be republished.", 409))
+ .when(service).requireContainerBackedVersionNotArchivedOrDisposed(eq("us-east-1"), eq(DOMAIN),
+ eq("000000000000"), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"));
+ VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
+ when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
+ .thenReturn("http://127.0.0.1:" + upstream.actualPort());
+ startDataPlane(service, verdaccioClient);
+
+ HttpResponse response = put("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg", "good-token",
+ publishEnvelope("my-pkg", "1.0.0", "my-pkg-1.0.0.tgz",
+ "fresh bytes".getBytes(StandardCharsets.UTF_8)));
+
+ assertEquals(409, response.statusCode());
+ assertEquals(false, upstreamReceivedPut.get());
+ verify(service, never()).forgetContainerBackedStatusOverrideIfUnchanged(any(), any(), any(), any(), any(),
+ any(), any(), any(), any());
+ }
+
+ /**
+ * Raised by Greptile's review: a real publish whose per-version {@code readme} exceeds
+ * {@code NpmPublishEnvelopeScanner}'s own stricter 1,000,000-character limit makes {@code
+ * checkRepublish}'s primary scan throw, the one case that used to forward unconditionally
+ * with no guard having run at all (nothing before this fix recovered the version names any
+ * other way). The lenient fallback scan must still let the guard see this exact version and
+ * refuse it, the same as a normal publish envelope already does.
+ */
+ @Test
+ void aPublishWhoseReadmeOverflowsTheStrictScanStillRunsTheGuard() throws Exception {
+ AtomicReference<Boolean> upstreamReceivedPut = new AtomicReference<>(false);
+ upstream = vertx.createHttpServer()
+ .requestHandler(request -> {
+ if (request.method() == HttpMethod.PUT) {
+ upstreamReceivedPut.set(true);
+ }
+ request.response().setStatusCode(201).end();
+ })
+ .listen(0, "127.0.0.1")
+ .toCompletionStage().toCompletableFuture().get(2, TimeUnit.SECONDS);
+
+ CodeArtifactService service = mock(CodeArtifactService.class);
+ when(service.resolveAuthorizationToken("good-token", DOMAIN))
+ .thenReturn(Optional.of(new AuthorizationTokenScope("000000000000", "us-east-1")));
+ when(service.ensureFormatContainerId("npm", "us-east-1", DOMAIN, "000000000000", REPOSITORY))
+ .thenReturn(NPM_REPOSITORY_ID);
+ doThrow(new AwsException("ConflictException", "Package version '1.0.0' of package 'my-pkg' is Disposed "
+ + "and cannot be republished.", 409))
+ .when(service).requireContainerBackedVersionNotArchivedOrDisposed(eq("us-east-1"), eq(DOMAIN),
+ eq("000000000000"), eq(REPOSITORY), eq("npm"), isNull(), eq("my-pkg"), eq("1.0.0"));
+ VerdaccioSidecarClient verdaccioClient = mock(VerdaccioSidecarClient.class);
+ when(verdaccioClient.ensureReady(eq(NPM_REPOSITORY_ID), anyString()))
+ .thenReturn("http://127.0.0.1:" + upstream.actualPort());
+ startDataPlane(service, verdaccioClient);
+
+ byte[] content = "fresh bytes".getBytes(StandardCharsets.UTF_8);
+ String oversizedReadme = "x".repeat(1_000_001);
+ String envelope = "{\"name\":\"my-pkg\",\"versions\":{\"1.0.0\":{\"name\":\"my-pkg\",\"version\":\"1.0.0\","
+ + "\"readme\":\"" + oversizedReadme + "\",\"dist\":{\"tarball\":\"http://ignored/my-pkg-1.0.0.tgz\","
+ + "\"integrity\":\"" + integrity(content) + "\"}}},\"_attachments\":{\"my-pkg-1.0.0.tgz\":{"
+ + "\"content_type\":\"application/octet-stream\",\"data\":\""
+ + Base64.getEncoder().encodeToString(content) + "\",\"length\":" + content.length + "}}}";
+
+ HttpResponse response = put("/codeartifact/npm/" + DOMAIN + "/" + REPOSITORY + "/my-pkg", "good-token",
+ envelope);
+
+ assertEquals(409, response.statusCode());
+ assertEquals(false, upstreamReceivedPut.get());
+ }
+
/**
* The identity used to look up an existing match comes from the URL the publish was sent to,
* not the envelope's own {@code name} field. A mismatched body must not be checked against
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiControllerTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiControllerTest.java
index 8d832c2bd5..c551deae52 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiControllerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiControllerTest.java
@@ -30,9 +30,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isNull;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
@@ -353,6 +358,99 @@ class CodeArtifactPypiControllerTest {
assertTrue(receivedBody.get().contains("new content"));
}
+ /**
+ * Qodo review finding: a real twine upload that republishes a coordinate an earlier
+ * updatePackageVersionsStatus/disposePackageVersions call left Archived or Disposed must not
+ * leave that override standing over the fresh content this upload just forwarded.
+ */
+ @Test
+ void uploadWithAVersionFieldClearsAnyStaleStatusOverrideAfterForwardingSucceeds() {
+ backend.createContext("/simple/my-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
+ backend.createContext("/", exchange -> respond(exchange, 200, "text/plain", ""));
+ byte[] body = multipartWithFileAndVersion("boundary123", "my-pkg", "1.0.0", "my_pkg-1.0.0.tar.gz",
+ "new content");
+
+ Response response = controller.upload(
+ headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY, body);
+
+ assertEquals(200, response.getStatus());
+ verify(service).forgetContainerBackedStatusOverrideIfUnchanged(any(), eq(DOMAIN), any(), eq(REPOSITORY),
+ eq("pypi"), isNull(), eq("my-pkg"), eq("1.0.0"), isNull());
+ }
+
+ /**
+ * Raised by Greptile's review: pypiserver files an upload under the identity its own filename
+ * embeds, never under whatever the form's own name/version fields say. A version field naming
+ * an unrelated coordinate (one that is not Archived/Disposed) while the real filename embeds
+ * a different version must be refused outright, not let the guard check the harmless
+ * coordinate while the real upload lands under the mismatched one regardless.
+ */
+ @Test
+ void uploadRejectsAVersionFieldThatDoesNotMatchTheFilename() {
+ AtomicBoolean uploadReceived = new AtomicBoolean();
+ backend.createContext("/simple/my-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
+ backend.createContext("/", exchange -> {
+ uploadReceived.set(true);
+ respond(exchange, 200, "text/plain", "");
+ });
+ byte[] body = multipartWithFileAndVersion("boundary123", "my-pkg", "9.9.9", "my_pkg-1.0.0.tar.gz",
+ "new content");
+
+ Response response = controller.upload(
+ headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY, body);
+
+ assertEquals(400, response.getStatus());
+ assertEquals(false, uploadReceived.get());
+ verify(service, never()).requireContainerBackedVersionNotArchivedOrDisposed(any(), any(), any(), any(),
+ any(), any(), any(), any());
+ }
+
+ /**
+ * hectorvent's review of this PR: the fix above only cleared a stale Archived/Disposed
+ * override after the sidecar had already accepted the republished content, which the User
+ * Guide rules out unconditionally for both statuses. The upload must now be refused before it
+ * ever reaches pypiserver.
+ */
+ @Test
+ void uploadRejectsAnArchivedOrDisposedVersionWithoutForwarding() {
+ AtomicBoolean uploadReceived = new AtomicBoolean();
+ backend.createContext("/simple/my-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
+ backend.createContext("/", exchange -> {
+ uploadReceived.set(true);
+ respond(exchange, 200, "text/plain", "");
+ });
+ doThrow(new AwsException("ConflictException", "Package version '1.0.0' of package 'my-pkg' is Disposed "
+ + "and cannot be republished.", 409))
+ .when(service).requireContainerBackedVersionNotArchivedOrDisposed(any(), eq(DOMAIN), any(),
+ eq(REPOSITORY), eq("pypi"), isNull(), eq("my-pkg"), eq("1.0.0"));
+ byte[] body = multipartWithFileAndVersion("boundary123", "my-pkg", "1.0.0", "my_pkg-1.0.0.tar.gz",
+ "new content");
+
+ Response response = controller.upload(
+ headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY, body);
+
+ assertEquals(409, response.getStatus());
+ assertEquals(false, uploadReceived.get());
+ verify(service, never()).recordContainerBackedAssetBytes(any(), any(), any(), any(), any(), any(), any(),
+ anyLong(), anyLong());
+ }
+
+ /** A missing version field, same as the readme capture right below it, has no coordinate to clear. */
+ @Test
+ void uploadWithNoVersionFieldNeverClearsAnyStatusOverride() {
+ backend.createContext("/simple/my-pkg/", exchange -> respond(exchange, 404, "text/plain", ""));
+ backend.createContext("/", exchange -> respond(exchange, 200, "text/plain", ""));
+ byte[] body = multipartWithFile("boundary123", "my-pkg", "my_pkg-1.0.tar.gz", "new content");
+
+ controller.upload(headers("Bearer good", "multipart/form-data; boundary=boundary123"), DOMAIN, REPOSITORY,
+ body);
+
+ verify(service, never()).forgetContainerBackedStatusOverrideIfUnchanged(any(), any(), any(), any(), any(),
+ any(), any(), any(), any());
+ verify(service, never()).requireContainerBackedVersionNotArchivedOrDisposed(any(), any(), any(), any(),
+ any(), any(), any(), any());
+ }
+
@Test
void uploadFailsClosedWhenTheExistenceCheckCannotReachTheBackend() {
// Nothing listens on this port: the existence check's own connect attempt fails, which
@@ -451,6 +549,22 @@ class CodeArtifactPypiControllerTest {
return body.getBytes(StandardCharsets.UTF_8);
}
+ private static byte[] multipartWithFileAndVersion(String boundary, String packageName, String version,
+ String filename, String content) {
+ String body = "--" + boundary + "\r\n"
+ + "Content-Disposition: form-data; name=\"name\"\r\n\r\n"
+ + packageName + "\r\n"
+ + "--" + boundary + "\r\n"
+ + "Content-Disposition: form-data; name=\"version\"\r\n\r\n"
+ + version + "\r\n"
+ + "--" + boundary + "\r\n"
+ + "Content-Disposition: form-data; name=\"content\"; filename=\"" + filename + "\"\r\n"
+ + "Content-Type: application/octet-stream\r\n\r\n"
+ + content + "\r\n"
+ + "--" + boundary + "--\r\n";
+ return body.getBytes(StandardCharsets.UTF_8);
+ }
+
private static void respond(com.sun.net.httpserver.HttpExchange exchange, int status, String contentType,
String body) throws java.io.IOException {
respond(exchange, status, contentType, body.getBytes(StandardCharsets.UTF_8));
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java
index 6619550b0f..2b787b9936 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactPypiDockerIntegrationTest.java
@@ -751,7 +751,7 @@ class CodeArtifactPypiDockerIntegrationTest {
byte[] content = ("many-versions-sdist-bytes-" + i).getBytes(StandardCharsets.UTF_8);
given().header("Authorization", "Bearer " + bearerToken)
.contentType("multipart/form-data; boundary=boundary123")
- .body(twineUploadBody("boundary123", packageName, filename, content))
+ .body(twineUploadBody("boundary123", packageName, version, filename, content, null))
.post("/codeartifact/pypi/" + DOMAIN + "/" + REPO + "/")
.then().statusCode(200);
}
@@ -851,7 +851,7 @@ class CodeArtifactPypiDockerIntegrationTest {
* {@code name} and the {@code content} file part, so the rest are included for realism only.
*/
private static byte[] twineUploadBody(String boundary, String packageName, String filename, byte[] content) {
- return twineUploadBody(boundary, packageName, filename, content, null);
+ return twineUploadBody(boundary, packageName, "1.0.0", filename, content, null);
}
/**
@@ -861,6 +861,19 @@ class CodeArtifactPypiDockerIntegrationTest {
*/
private static byte[] twineUploadBody(String boundary, String packageName, String filename, byte[] content,
String description) {
+ return twineUploadBody(boundary, packageName, "1.0.0", filename, content, description);
+ }
+
+ /**
+ * Full shape, with an explicit {@code version} field: every other overload above hardcodes
+ * {@code 1.0.0}, which happens to match every other test's own fixed filename in this class,
+ * but {@code CodeArtifactPypiController#upload} now checks the version field against the
+ * real filename (Greptile's review of this PR), so a caller whose filename embeds a different
+ * version (see {@link #listPackageVersionsFetchesManyVersionsPublishTimesCorrectly}'s own
+ * loop) must pass the matching one here instead.
+ */
+ private static byte[] twineUploadBody(String boundary, String packageName, String version, String filename,
+ byte[] content, String description) {
String preamble = "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\":action\"\r\n\r\n"
+ "file_upload\r\n"
@@ -872,7 +885,7 @@ class CodeArtifactPypiDockerIntegrationTest {
+ packageName + "\r\n"
+ "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"version\"\r\n\r\n"
- + "1.0.0\r\n"
+ + version + "\r\n"
+ "--" + boundary + "\r\n"
+ "Content-Disposition: form-data; name=\"filetype\"\r\n\r\n"
+ "sdist\r\n"
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
index f6f1506599..9086dd1cab 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactServiceTest.java
@@ -33,12 +33,18 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -46,10 +52,12 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -2308,6 +2316,46 @@ class CodeArtifactServiceTest {
any());
}
+ /**
+ * Raised by Greptile's review: a Maven dispose failing partway through its own asset-deletion
+ * loop leaves the source override reading {@code Disposed} while real files genuinely still
+ * remain in the version's own directory, so {@code packageVersionExists} alone cannot tell a
+ * healthy source apart from a partly-disposed one. With {@code allowOverwrite=true}, copying
+ * that partly-disposed source over a healthy destination must still be refused, not replace
+ * the destination's real content with the incomplete release and report {@code Published}.
+ */
+ @Test
+ void copyPackageVersionsFailsNotAllowedWhenTheMavenSourceIsPartlyDisposed() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository src = service.createRepository(REGION, "dom", null, "src", null, null, Map.of());
+ CodeArtifactRepository dst = service.createRepository(REGION, "dom", null, "dst", null, null, Map.of());
+ String srcRepoId = src.getSidecarContainerIds().get("maven");
+ String dstRepoId = dst.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar", "a-1.0.pom"));
+ doThrow(new IllegalStateException("sidecar unreachable"))
+ .when(reposiliteClient).deletePackageVersionAsset(eq(srcRepoId), eq("dom"), eq("src"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.pom"));
+ assertThrows(IllegalStateException.class, () -> service.disposePackageVersions(REGION, "dom", null, "src",
+ "maven", "com.example", "a", List.of("1.0"), null, null));
+ // The pom's delete never actually succeeded, so it is still genuinely there.
+ when(reposiliteClient.packageVersionExists(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(true);
+ when(reposiliteClient.packageVersionExists(eq(dstRepoId), eq("dom"), eq("dst"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(true);
+
+ CodeArtifactService.CopyPackageVersionsResult result = service.copyPackageVersions(REGION, "dom", null,
+ "src", "dst", "maven", "com.example", "a", List.of("1.0"), null, true, false);
+
+ assertTrue(result.successfulVersions().isEmpty());
+ assertEquals("NOT_ALLOWED", result.failedVersions().get("1.0").errorCode());
+ verify(reposiliteClient, never()).copyPackageVersionAsset(any(), any(), any(), any(), any(), any(), any(),
+ any(), any(), any());
+ }
+
@Test
void copyPackageVersionsFailsNotFoundForAMavenVersionMissingFromTheSource() {
service.createDomain(REGION, "dom", null, Map.of());
@@ -2712,6 +2760,59 @@ class CodeArtifactServiceTest {
assertEquals("ALREADY_EXISTS", result.failedVersions().get("1.0.0").errorCode());
}
+ /**
+ * Raised by hectorvent's review of this PR, matching copyContainerBackedPackageVersions's own
+ * Disposed-destination guard: disposePackageVersions empties a generic version's asset map but
+ * keeps its record (so DescribePackageVersion keeps answering), so without a dedicated check an
+ * allowOverwrite copy would have nothing to compare against, fall through as though the
+ * destination were simply a different version, and resurrect a coordinate the User Guide says
+ * "can no longer be used."
+ */
+ @Test
+ void copyPackageVersionsFailsNotAllowedWhenTheDestinationIsAlreadyDisposed() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "src", null, null, Map.of());
+ service.createRepository(REGION, "dom", null, "dst", null, null, Map.of());
+ publishGeneric("src", "my-pkg", "1.0.0", "source-bytes".getBytes(StandardCharsets.UTF_8));
+ publishGeneric("dst", "my-pkg", "1.0.0", "different-bytes".getBytes(StandardCharsets.UTF_8));
+ service.disposePackageVersions(REGION, "dom", null, "dst", "generic", "ns", "my-pkg", List.of("1.0.0"), null,
+ null);
+
+ CodeArtifactService.CopyPackageVersionsResult result = service.copyPackageVersions(REGION, "dom", null,
+ "src", "dst", "generic", "ns", "my-pkg", List.of("1.0.0"), null, true, false);
+
+ assertTrue(result.successfulVersions().isEmpty());
+ assertEquals("NOT_ALLOWED", result.failedVersions().get("1.0.0").errorCode());
+ }
+
+ /**
+ * Raised by Greptile's review: {@code disposePackageVersions} empties a generic version's
+ * asset map but keeps its record around, the same reason the destination-side guard above
+ * exists. Without a matching guard on the source, copying a disposed source with
+ * {@code allowOverwrite=true} over a healthy destination would overwrite that destination's
+ * real content and status with the disposed source's empty one while reporting success,
+ * destroying assets the disposal never touched.
+ */
+ @Test
+ void copyPackageVersionsFailsNotAllowedWhenTheSourceIsAlreadyDisposed() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "src", null, null, Map.of());
+ service.createRepository(REGION, "dom", null, "dst", null, null, Map.of());
+ publishGeneric("src", "my-pkg", "1.0.0", "source-bytes".getBytes(StandardCharsets.UTF_8));
+ publishGeneric("dst", "my-pkg", "1.0.0", "healthy-bytes".getBytes(StandardCharsets.UTF_8));
+ service.disposePackageVersions(REGION, "dom", null, "src", "generic", "ns", "my-pkg", List.of("1.0.0"), null,
+ null);
+
+ CodeArtifactService.CopyPackageVersionsResult result = service.copyPackageVersions(REGION, "dom", null,
+ "src", "dst", "generic", "ns", "my-pkg", List.of("1.0.0"), null, true, false);
+
+ assertTrue(result.successfulVersions().isEmpty());
+ assertEquals("NOT_ALLOWED", result.failedVersions().get("1.0.0").errorCode());
+ PackageVersionAssetResult stillHealthy = service.getPackageVersionAsset(REGION, "dom", null, "dst",
+ "generic", "ns", "my-pkg", "1.0.0", "a.txt", null);
+ assertEquals("healthy-bytes", new String(stillHealthy.asset().getContent(), StandardCharsets.UTF_8));
+ }
+
@Test
void copyPackageVersionsOverwritesADifferentExistingVersionWhenAllowOverwriteIsTrue() {
service.createDomain(REGION, "dom", null, Map.of());
@@ -3625,6 +3726,815 @@ class CodeArtifactServiceTest {
assertEquals("ValidationException", badOriginType.getErrorCode());
}
+ // ------------------------------------- updatePackageVersionsStatus / disposePackageVersions
+
+ @Test
+ void updatePackageVersionsStatusArchivesAGenericVersionAndChangesItsRevision() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+ // Captured as a plain string, not the live CodeArtifactPackageVersion object: the test
+ // storage backend hands back the same mutable instance on every read, so holding onto the
+ // object itself would see it change underneath this assertion once the update below
+ // mutates it in place.
+ String revisionBeforeUpdate = service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "my-pkg", "1.0.0").getRevision();
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, null, "Archived");
+
+ assertEquals(1, result.successfulVersions().size());
+ assertEquals("Archived", result.successfulVersions().get("1.0.0").status());
+ assertNotEquals(revisionBeforeUpdate, result.successfulVersions().get("1.0.0").revision());
+ assertTrue(result.failedVersions().isEmpty());
+ assertEquals("Archived", service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "my-pkg", "1.0.0").getStatus());
+ }
+
+ /**
+ * Raised by Greptile's review: {@code UPDATE_TARGET_STATUSES} allows targeting {@code
+ * Published} from {@code Unfinished} (nothing in {@code checkStatusTransitionAllowed} blocks
+ * it), the real way a version can finalize through this action instead of through {@code
+ * publishPackageVersion}'s own normal path, which already sets {@code publishedTime} on the
+ * identical condition. Left unset, the version would sort as though never published at all.
+ */
+ @Test
+ void updatePackageVersionsStatusSetsPublishedTimeWhenFinalizingAnUnfinishedGenericVersion() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ byte[] content = "a".getBytes(StandardCharsets.UTF_8);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "true", content);
+ assertEquals("Unfinished", service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "my-pkg", "1.0.0").getStatus());
+ assertNull(service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", "1.0.0")
+ .getPublishedTime());
+
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "generic", "ns", "my-pkg",
+ List.of("1.0.0"), null, null, "Published");
+
+ assertNotNull(service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns", "my-pkg",
+ "1.0.0").getPublishedTime());
+ }
+
+ @Test
+ void updatePackageVersionsStatusSkipsEveryOtherwiseEligibleVersionWhenOneFails() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0", "9.9.9"), null, null, "Archived");
+
+ assertTrue(result.successfulVersions().isEmpty());
+ assertEquals("NOT_FOUND", result.failedVersions().get("9.9.9").errorCode());
+ assertEquals("SKIPPED", result.failedVersions().get("1.0.0").errorCode());
+ // Confirms the all-or-nothing rule actually held: 1.0.0 would have succeeded on its own.
+ assertEquals("Published", service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "my-pkg", "1.0.0").getStatus());
+ }
+
+ @Test
+ void updatePackageVersionsStatusFailsMismatchedRevisionAndMismatchedStatus() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+
+ CodeArtifactService.PackageVersionStatusChangeResult revisionMismatch = service.updatePackageVersionsStatus(
+ REGION, "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"),
+ Map.of("1.0.0", "not-the-real-revision"), null, "Archived");
+ assertEquals("MISMATCHED_REVISION", revisionMismatch.failedVersions().get("1.0.0").errorCode());
+
+ CodeArtifactService.PackageVersionStatusChangeResult statusMismatch = service.updatePackageVersionsStatus(
+ REGION, "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, "Unlisted",
+ "Archived");
+ assertEquals("MISMATCHED_STATUS", statusMismatch.failedVersions().get("1.0.0").errorCode());
+ assertTrue(statusMismatch.failedVersions().get("1.0.0").errorMessage().contains("current status: Published"));
+ }
+
+ @Test
+ void updatePackageVersionsStatusCannotMoveAwayFromDisposed() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+ service.disposePackageVersions(REGION, "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"),
+ null, null);
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, null, "Unlisted");
+
+ assertEquals("NOT_ALLOWED", result.failedVersions().get("1.0.0").errorCode());
+ }
+
+ /**
+ * Raised by Greptile's review: the batch actions' own existence/override matching used the
+ * raw requested version string, so archiving a NuGet version and then calling
+ * {@code UpdatePackageVersionsStatus} again with an equivalent spelling (AWS's own worked
+ * example, {@code 1.00} and {@code 1.0.0}) found the version real but missed its override,
+ * silently defaulting to {@code Published} and failing {@code MISMATCHED_STATUS} against an
+ * {@code expectedStatus=Archived} that was, in reality, already true.
+ */
+ @Test
+ void updatePackageVersionsStatusMatchesAnEquivalentNuGetVersionSpellingAgainstAnExistingOverride() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("nuget");
+ when(bagetterClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
+ .thenReturn(List.of(new RepositorySidecarManager.PackageVersionTimestamp("1.0.0",
+ Instant.ofEpochSecond(1000))));
+
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "nuget", null, "my-pkg",
+ List.of("1.0.0"), null, null, "Archived");
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "nuget", null, "my-pkg", List.of("1.00"), null, "Archived", "Unlisted");
+
+ assertEquals("Unlisted", result.successfulVersions().get("1.00").status());
+ }
+
+ @Test
+ void updatePackageVersionsStatusRejectsUnfinishedDisposedOrDeletedAsTargetStatus() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ for (String badTarget : List.of("Unfinished", "Disposed", "Deleted", "NotAStatus")) {
+ AwsException e = assertThrows(AwsException.class, () -> service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, null, badTarget));
+ assertEquals("ValidationException", e.getErrorCode());
+ }
+ }
+
+ @Test
+ void updatePackageVersionsStatusRejectsDisposedAsExpectedStatusButDisposeAcceptsIt() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+
+ AwsException e = assertThrows(AwsException.class, () -> service.updatePackageVersionsStatus(REGION, "dom",
+ null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, "Disposed", "Archived"));
+ assertEquals("ValidationException", e.getErrorCode());
+
+ // DisposePackageVersionsRequest.expectedStatus's own wider valid set accepts "Disposed"
+ // itself (confirmed against the API reference): the version isn't actually Disposed yet,
+ // so this still fails, but on the per-version MISMATCHED_STATUS check, not request
+ // validation.
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, "Disposed");
+ assertEquals("MISMATCHED_STATUS", result.failedVersions().get("1.0.0").errorCode());
+ }
+
+ @Test
+ void updatePackageVersionsStatusRequiresVersionsAndCapsAtOneHundred() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+
+ AwsException missing = assertThrows(AwsException.class, () -> service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", List.of(), null, null, "Archived"));
+ assertEquals("ValidationException", missing.getErrorCode());
+
+ List<String> tooMany = IntStream.range(0, 101).mapToObj(i -> "1.0." + i).toList();
+ AwsException overLimit = assertThrows(AwsException.class, () -> service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "generic", "ns", "my-pkg", tooMany, null, null, "Archived"));
+ assertEquals("ValidationException", overLimit.getErrorCode());
+ }
+
+ @Test
+ void disposePackageVersionsDeletesGenericAssetBytesAndBlocksFurtherDownload() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ publishGeneric("repo", "my-pkg", "1.0.0", "a".getBytes(StandardCharsets.UTF_8));
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, null);
+
+ assertEquals("Disposed", result.successfulVersions().get("1.0.0").status());
+ AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null,
+ "repo", "generic", "ns", "my-pkg", "1.0.0", "a.txt", null));
+ assertEquals("ResourceNotFoundException", e.getErrorCode());
+ // DescribePackageVersion still answers for a disposed version (per the User Guide: "To
+ // view information about a disposed package version, use DescribePackageVersion"), it
+ // just reports no assets left.
+ CodeArtifactPackageVersion described = service.describePackageVersion(REGION, "dom", null, "repo", "generic",
+ "ns", "my-pkg", "1.0.0");
+ assertEquals("Disposed", described.getStatus());
+ assertTrue(described.getAssets().isEmpty());
+ }
+
+ /**
+ * A sidecar that cannot supply a timestamp for one of its versions reports it as a {@code
+ * null} {@code publishedTime} (the same possibility {@code listPackageVersions} itself
+ * already handles); building the per-call publish-time lookup with {@code Collectors.toMap}
+ * would throw a {@code NullPointerException} on that null value (it uses {@code Map.merge}
+ * internally, which rejects one), so this must still succeed.
+ */
+ @Test
+ void updatePackageVersionsStatusSucceedsWhenTheSidecarHasNoTimestampForTheVersion() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(new RepositorySidecarManager.PackageVersionTimestamp("1.0", null)));
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "maven", "com.example", "a", List.of("1.0"), null, null, "Archived");
+
+ assertEquals("Archived", result.successfulVersions().get("1.0").status());
+ assertTrue(result.failedVersions().isEmpty());
+ }
+
+ @Test
+ void updatePackageVersionsStatusArchivesAMavenVersionThroughTheSidecarOverrideAndGetAssetIsBlocked() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a.jar"))).thenReturn(Optional.of("jar-bytes".getBytes(StandardCharsets.UTF_8)));
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "maven", "com.example", "a", List.of("1.0"), null, null, "Archived");
+ assertEquals("Archived", result.successfulVersions().get("1.0").status());
+
+ CodeArtifactService.ListPackageVersionsResult listed = service.listPackageVersions(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "Archived", null, null, null, null);
+ assertEquals(1, listed.versions().size());
+ assertEquals("Archived", listed.versions().get(0).status());
+
+ AwsException e = assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "1.0", "a.jar", null));
+ assertEquals("ResourceNotFoundException", e.getErrorCode());
+ verify(reposiliteClient, never()).fetchPackageVersionAsset(any(), any(), any(), any(), any(), any(), any());
+ }
+
+ @Test
+ void disposePackageVersionsDeletesEveryRealAssetAndKeepsListingTheVersionAsDisposed() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar", "a-1.0.pom"));
+
+ CodeArtifactService.PackageVersionStatusChangeResult result = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "maven", "com.example", "a", List.of("1.0"), null, null);
+ assertEquals("Disposed", result.successfulVersions().get("1.0").status());
+ verify(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"));
+ verify(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.pom"));
+
+ // The sidecar no longer lists the disposed version at all (its content is gone), yet
+ // ListPackageVersions still reports it, by status=Disposed, from the override alone.
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of());
+ CodeArtifactService.ListPackageVersionsResult listed = service.listPackageVersions(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "Disposed", null, null, null, null);
+ assertEquals(1, listed.versions().size());
+ assertEquals("1.0", listed.versions().get(0).version());
+ assertEquals("Disposed", listed.versions().get(0).status());
+ }
+
+ /**
+ * Raised by Greptile's review: {@code applyContainerBackedStatusChange} writes the override
+ * {@code Disposed} before deleting any real assets, so a sidecar failure partway through that
+ * deletion loop left the version Disposed with some assets still real, and the unconditional
+ * {@code NOT_ALLOWED} on an already-{@code Disposed} version meant no further
+ * {@code DisposePackageVersions} call could ever finish that cleanup. A retry targeting
+ * {@code Disposed} again must now succeed and delete whatever the sidecar still lists.
+ *
+ * <p>Also proves Greptile's own follow-up finding on that same fix: the jar's bytes, freed by
+ * the first (overall failed) attempt, must still count against {@code
+ * DescribeDomain.assetSizeBytes} once the retry finishes the pom, not just the pom's own bytes
+ * freed by the retry itself; {@link #deleteContainerBackedVersionAssets} subtracts each
+ * asset's bytes right after that asset's own delete, not batched at the end, specifically so a
+ * failure between two deletes never loses the first one's already-freed bytes.
+ */
+ @Test
+ void disposePackageVersionsRetriesAfterAPartialAssetDeletionFailureAndFinishesCleanup() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ recordBytes("dom", "repo", "maven", "com.example", "a", 100L);
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar", "a-1.0.pom"));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(new byte[40]));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.pom"))).thenReturn(Optional.of(new byte[25]));
+ doThrow(new IllegalStateException("sidecar unreachable"))
+ .when(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.pom"));
+
+ assertThrows(IllegalStateException.class, () -> service.disposePackageVersions(REGION, "dom", null, "repo",
+ "maven", "com.example", "a", List.of("1.0"), null, null));
+ // The override already reads Disposed (written before the failed delete), so downloads
+ // are already blocked even though the pom never actually got deleted.
+ assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null));
+ verify(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"));
+ assertEquals(60L, service.describeDomain(REGION, "dom", null).assetSizeBytes());
+
+ // The sidecar recovers; its own listing now only names the pom (the jar's delete already
+ // completed on the first attempt), the same self-correcting signal a real retry relies on.
+ doNothing().when(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.pom"));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.pom"));
+
+ CodeArtifactService.PackageVersionStatusChangeResult retry = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "maven", "com.example", "a", List.of("1.0"), null, null);
+
+ assertEquals("Disposed", retry.successfulVersions().get("1.0").status());
+ // Twice in total across both attempts: the first one threw (counted on the mock
+ // regardless), the retry's own call is the one that actually finished the delete.
+ verify(reposiliteClient, times(2)).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.pom"));
+ assertEquals(35L, service.describeDomain(REGION, "dom", null).assetSizeBytes());
+ }
+
+ /**
+ * Raised by Greptile's review: unlike Maven, an npm disposal retry cannot rely on a fresh
+ * {@code listPackageVersionAssetNames} call to tell it what is still left to delete.
+ * {@code VerdaccioSidecarClient#deletePackageVersionAsset} removes the version from the
+ * packument before the tarball delete even runs (Verdaccio's own real two-step unpublish,
+ * confirmed live, see that method's own javadoc), so once that update lands, a fresh listing
+ * can never again answer "what is left:" it already reads empty, exactly as simulated here by
+ * re-stubbing it to return nothing after the first (failed) attempt. The retry must still
+ * finish deleting the tarball, which it can only do by reading the override's own {@code
+ * pendingAssetNames} instead of asking the sidecar again.
+ */
+ @Test
+ void disposePackageVersionsRetriesAnNpmTarballDeleteEvenAfterTheSidecarsOwnListingGoesEmpty() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("npm");
+ when(verdaccioClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
+ .thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0.0", Instant.ofEpochSecond(1000))));
+ when(verdaccioClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"))).thenReturn(List.of("my-pkg-1.0.0.tgz"));
+ doThrow(new IllegalStateException("sidecar unreachable"))
+ .when(verdaccioClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+
+ assertThrows(IllegalStateException.class, () -> service.disposePackageVersions(REGION, "dom", null, "repo",
+ "npm", null, "my-pkg", List.of("1.0.0"), null, null));
+
+ // Simulates exactly what Greptile's review describes: Verdaccio's own packument update
+ // already landed, so a fresh listing now reads empty even though the tarball itself
+ // never actually got deleted.
+ when(verdaccioClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"))).thenReturn(List.of());
+ doNothing().when(verdaccioClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+
+ CodeArtifactService.PackageVersionStatusChangeResult retry = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "npm", null, "my-pkg", List.of("1.0.0"), null, null);
+
+ assertEquals("Disposed", retry.successfulVersions().get("1.0.0").status());
+ // Twice in total across both attempts: the first one threw (counted on the mock
+ // regardless), the retry's own call is the one that actually finished the delete.
+ verify(verdaccioClient, times(2)).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+ }
+
+ @Test
+ void disposePackageVersionsRejectsAnExpectedStatusUpdateDoesNotAllow() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+
+ AwsException e = assertThrows(AwsException.class, () -> service.disposePackageVersions(REGION, "dom", null,
+ "repo", "generic", "ns", "my-pkg", List.of("1.0.0"), null, "NotAStatus"));
+ assertEquals("ValidationException", e.getErrorCode());
+ }
+
+ /**
+ * Qodo review finding on this PR: {@code DescribeDomain.assetSizeBytes} kept counting a
+ * container-backed version's bytes forever after disposal, since the per-package running
+ * total was never reduced when its real sidecar assets were deleted.
+ */
+ @Test
+ void disposePackageVersionsReducesTheDomainAssetSizeByTheRealDeletedBytes() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ recordBytes("dom", "repo", "maven", "com.example", "a", 100L);
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar"));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(new byte[40]));
+
+ service.disposePackageVersions(REGION, "dom", null, "repo", "maven", "com.example", "a", List.of("1.0"),
+ null, null);
+
+ assertEquals(60L, service.describeDomain(REGION, "dom", null).assetSizeBytes());
+ }
+
+ /**
+ * Raised by Greptile's review: {@code PypiserverSidecarClient#deletePackageVersionAsset}
+ * removes every file sharing the same raw package name and version in one call (confirmed
+ * live, the same quirk {@code copyContainerBackedPackageVersions}'s own write path already
+ * works around), so a release's second file could already be gone by the time the old
+ * interleaved fetch-then-delete loop got to measuring it, undercounting the bytes {@code
+ * DescribeDomain.assetSizeBytes} should have freed. Both assets are now measured before
+ * either is deleted, so the collateral deletion below (simulated by having the sdist's own
+ * delete flip the wheel's fetch to empty, exactly like the real sidecar's own side effect)
+ * no longer loses its byte count.
+ */
+ @Test
+ void disposePackageVersionsMeasuresEveryAssetBeforeDeletingAnyOfThemSoACollateralDeleteDoesNotLoseItsBytes() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("pypi");
+ recordBytes("dom", "repo", "pypi", null, "my-pkg", 100L);
+ when(pypiserverClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
+ .thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(pypiserverClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0"))).thenReturn(List.of("my-pkg-1.0.tar.gz", "my_pkg-1.0-py3-none-any.whl"));
+ AtomicBoolean sdistDeleted = new AtomicBoolean();
+ when(pypiserverClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
+ eq("1.0"), eq("my-pkg-1.0.tar.gz"))).thenReturn(Optional.of(new byte[40]));
+ when(pypiserverClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
+ eq("1.0"), eq("my_pkg-1.0-py3-none-any.whl"))).thenAnswer(invocation ->
+ sdistDeleted.get() ? Optional.empty() : Optional.of(new byte[25]));
+ doAnswer(invocation -> {
+ sdistDeleted.set(true);
+ return null;
+ }).when(pypiserverClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0"), eq("my-pkg-1.0.tar.gz"));
+
+ service.disposePackageVersions(REGION, "dom", null, "repo", "pypi", null, "my-pkg", List.of("1.0"), null,
+ null);
+
+ assertEquals(35L, service.describeDomain(REGION, "dom", null).assetSizeBytes());
+ }
+
+ /**
+ * Qodo review finding on this PR: {@code ListPackageVersionAssets} and {@code
+ * GetPackageVersionReadme} still computed a container-backed version's revision with the raw,
+ * coordinate-derived {@code synthesizeContainerBackedRevision} formula, disagreeing with the
+ * fresh revision {@code updatePackageVersionsStatus}/{@code DescribePackageVersion}/{@code
+ * ListPackageVersions} report once a status override exists for that version.
+ */
+ @Test
+ void listPackageVersionAssetsAndGetPackageVersionReadmeAgreeWithTheOverrideRevisionAfterArchiving() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("npm");
+ when(verdaccioClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
+ .thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0.0", Instant.ofEpochSecond(1000))));
+ when(verdaccioClient.packageVersionExists(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
+ eq("1.0.0"))).thenReturn(true);
+ when(verdaccioClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
+ eq("1.0.0"))).thenReturn(List.of("my-pkg-1.0.0.tgz"));
+ when(verdaccioClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg"),
+ eq("1.0.0"), eq("my-pkg-1.0.0.tgz"))).thenReturn(Optional.of("tgz-bytes".getBytes(
+ StandardCharsets.UTF_8)));
+ recordReadme("dom", "repo", "npm", null, "my-pkg", "1.0.0", "hello");
+
+ CodeArtifactService.PackageVersionStatusChangeResult changed = service.updatePackageVersionsStatus(REGION,
+ "dom", null, "repo", "npm", null, "my-pkg", List.of("1.0.0"), null, null, "Archived");
+ String overrideRevision = changed.successfulVersions().get("1.0.0").revision();
+
+ CodeArtifactService.PackageVersionAssetsListResult assets = service.listPackageVersionAssets(REGION, "dom",
+ null, "repo", "npm", null, "my-pkg", "1.0.0", null, null);
+ assertEquals(overrideRevision, assets.versionRevision());
+
+ CodeArtifactService.PackageVersionReadmeResult readme = service.getPackageVersionReadme(REGION, "dom", null,
+ "repo", "npm", null, "my-pkg", "1.0.0");
+ assertEquals(overrideRevision, readme.versionRevision());
+ }
+
+ /**
+ * Qodo review finding on this PR: copying new content over a destination version that an
+ * earlier {@code updatePackageVersionsStatus} had archived left the old override in place,
+ * so the fresh content this copy just wrote would still read back as Archived and {@code
+ * GetPackageVersionAsset} would keep 404ing on it, contradicting the copy's own response
+ * (which reports Published).
+ */
+ @Test
+ void copyPackageVersionsClearsAStaleArchivedOverrideAtTheDestinationAndUnblocksDownload() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository src = service.createRepository(REGION, "dom", null, "src", null, null, Map.of());
+ CodeArtifactRepository dst = service.createRepository(REGION, "dom", null, "dst", null, null, Map.of());
+ String srcRepoId = src.getSidecarContainerIds().get("maven");
+ String dstRepoId = dst.getSidecarContainerIds().get("maven");
+ byte[] newJar = "new-jar-bytes".getBytes(StandardCharsets.UTF_8);
+ byte[] oldJar = "old-jar-bytes".getBytes(StandardCharsets.UTF_8);
+ when(reposiliteClient.packageVersionExists(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(true);
+ when(reposiliteClient.packageVersionExists(eq(dstRepoId), eq("dom"), eq("dst"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(true);
+ when(reposiliteClient.listPackageVersionAssetNames(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar"));
+ when(reposiliteClient.listPackageVersionAssetNames(eq(dstRepoId), eq("dom"), eq("dst"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar"));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(srcRepoId), eq("dom"), eq("src"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(newJar));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(dstRepoId), eq("dom"), eq("dst"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(oldJar));
+ when(reposiliteClient.listPackageVersions(eq(dstRepoId), eq("dom"), eq("dst"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ service.updatePackageVersionsStatus(REGION, "dom", null, "dst", "maven", "com.example", "a", List.of("1.0"),
+ null, null, "Archived");
+ assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null, "dst", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null));
+
+ CodeArtifactService.CopyPackageVersionsResult result = service.copyPackageVersions(REGION, "dom", null,
+ "src", "dst", "maven", "com.example", "a", List.of("1.0"), null, true, false);
+
+ assertTrue(result.failedVersions().isEmpty());
+ assertEquals("Published", result.successfulVersions().get("1.0").status());
+ PackageVersionAssetResult downloaded = service.getPackageVersionAsset(REGION, "dom", null, "dst", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null);
+ assertEquals(oldJar.length, downloaded.asset().getSize());
+ }
+
+ /**
+ * Qodo review's remaining half of the same finding: {@code copyContainerBackedPackageVersions}
+ * clears a stale override on its own overwrite path, but nothing cleared one for a native
+ * publish: every container-backed proxy controller (Maven, npm, pypi, nuget) now calls
+ * {@code forgetContainerBackedStatusOverride} right alongside its existing byte-accounting
+ * call once a native publish actually writes something. This proves the shared primitive those
+ * four call sites all delegate to.
+ */
+ @Test
+ void forgetContainerBackedStatusOverrideClearsItAndUnblocksDownload() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of("jar-bytes".getBytes(
+ StandardCharsets.UTF_8)));
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "maven", "com.example", "a",
+ List.of("1.0"), null, null, "Archived");
+ assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null));
+
+ service.forgetContainerBackedStatusOverride(REGION, "dom", null, "repo", "maven", "com.example", "a", "1.0");
+
+ PackageVersionAssetResult downloaded = service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null);
+ assertEquals("jar-bytes".getBytes(StandardCharsets.UTF_8).length, downloaded.asset().getSize());
+ }
+
+ /**
+ * Raised by hectorvent's review of this PR: {@code forgetContainerBackedStatusOverride} above
+ * only ever clears an Archived/Disposed override after a native proxy controller's real
+ * sidecar write already succeeded, which would let a package-manager republish silently
+ * resurrect either status. Every native proxy controller now calls this guard first, before
+ * issuing that write, and must see it refuse exactly the two statuses the User Guide blocks
+ * unconditionally: Published, Unlisted, and a coordinate with no override at all must all
+ * sail through untouched.
+ */
+ @Test
+ void requireContainerBackedVersionNotArchivedOrDisposedBlocksOnlyThoseTwoStatuses() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000)),
+ new RepositorySidecarManager.PackageVersionTimestamp("2.0", Instant.ofEpochSecond(1000)),
+ new RepositorySidecarManager.PackageVersionTimestamp("3.0", Instant.ofEpochSecond(1000))));
+
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "maven", "com.example", "a",
+ List.of("1.0"), null, null, "Archived");
+ AwsException archivedError = assertThrows(AwsException.class,
+ () -> service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null, "repo",
+ "maven", "com.example", "a", "1.0"));
+ assertEquals("ConflictException", archivedError.getErrorCode());
+
+ service.disposePackageVersions(REGION, "dom", null, "repo", "maven", "com.example", "a", List.of("2.0"),
+ null, null);
+ AwsException disposedError = assertThrows(AwsException.class,
+ () -> service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null, "repo",
+ "maven", "com.example", "a", "2.0"));
+ assertEquals("ConflictException", disposedError.getErrorCode());
+
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "maven", "com.example", "a",
+ List.of("3.0"), null, null, "Unlisted");
+ assertDoesNotThrow(() -> service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "3.0"));
+
+ assertDoesNotThrow(() -> service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "4.0-never-touched"));
+ }
+
+ /**
+ * Raised by Greptile's review: {@code requireContainerBackedVersionNotArchivedOrDisposed}'s
+ * guard, the real sidecar write, and this call are necessarily three separate steps (the
+ * write sits in between, with no lock held across it), so a concurrent
+ * {@code disposePackageVersions} landing in that gap already deleted the real content before
+ * the publish's own write restored it. Leaving the override alone (it correctly already does)
+ * is not enough on its own: a native per-format download route never consults the override at
+ * all, so the restored bytes stayed live even with the override still reading {@code
+ * Disposed}. This must now also undo that restoration by re-running the real asset deletion.
+ */
+ @Test
+ void forgetContainerBackedStatusOverrideIfUnchangedRedeletesRestoredAssetsWhenAConcurrentDisposeWonTheRace() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ // The publish's own guard ran first, before anything (the real write or the race) has
+ // happened yet: no override exists, so this is the snapshot it carries into its own
+ // later forgetContainerBackedStatusOverrideIfUnchanged call.
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ String beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "1.0");
+ assertNull(beforeRevision);
+
+ // A concurrent dispose lands in the gap between that guard and the publish's own real
+ // write landing. Nothing is stubbed to list any assets yet, so this dispose finds (and
+ // deletes) nothing real, the same as if the publish's write genuinely had not landed yet.
+ service.disposePackageVersions(REGION, "dom", null, "repo", "maven", "com.example", "a", List.of("1.0"),
+ null, null);
+
+ // The publish's own write now lands after the dispose already finished, restoring real
+ // content the sidecar reports back from here on.
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar"));
+ when(reposiliteClient.fetchPackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"))).thenReturn(Optional.of(new byte[10]));
+
+ service.forgetContainerBackedStatusOverrideIfUnchanged(REGION, "dom", null, "repo", "maven",
+ "com.example", "a", "1.0", beforeRevision);
+
+ verify(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"), eq("a-1.0.jar"));
+ assertThrows(AwsException.class, () -> service.getPackageVersionAsset(REGION, "dom", null, "repo", "maven",
+ "com.example", "a", "1.0", "a-1.0.jar", null));
+ }
+
+ /**
+ * Raised by Greptile's review of the fix above: the restored asset names were only ever
+ * recorded into the override's own {@code pendingAssetNames} as each one's own delete
+ * succeeded, never upfront before the first attempt. A failure on the very first restored
+ * asset's delete therefore left {@code pendingAssetNames} exactly as the already-completed
+ * disposal before it left it, almost always empty, so a later {@code DisposePackageVersions}
+ * retry saw nothing pending and reported success with the restored file still real.
+ */
+ @Test
+ void forgetContainerBackedStatusOverrideIfUnchangedSavesRestoredAssetNamesBeforeDeletingSoARetryCanFinish() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("maven");
+ when(reposiliteClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"))).thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0", Instant.ofEpochSecond(1000))));
+ String beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null,
+ "repo", "maven", "com.example", "a", "1.0");
+ service.disposePackageVersions(REGION, "dom", null, "repo", "maven", "com.example", "a", List.of("1.0"),
+ null, null);
+
+ // The publish's own write restores real content after the dispose above already
+ // finished, but this attempt to undo it fails on the restored asset's own delete.
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of("a-1.0.jar"));
+ doThrow(new IllegalStateException("sidecar unreachable"))
+ .when(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.jar"));
+ assertThrows(IllegalStateException.class, () -> service.forgetContainerBackedStatusOverrideIfUnchanged(
+ REGION, "dom", null, "repo", "maven", "com.example", "a", "1.0", beforeRevision));
+
+ // The sidecar recovers; a fresh listing now reads empty (the same ambiguous signal a
+ // real Reposilite instance could give here), so only the override's own saved
+ // pendingAssetNames can tell a retry the restored file is still real.
+ when(reposiliteClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), eq("com.example"),
+ eq("a"), eq("1.0"))).thenReturn(List.of());
+ doNothing().when(reposiliteClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.jar"));
+
+ CodeArtifactService.PackageVersionStatusChangeResult retry = service.disposePackageVersions(REGION, "dom",
+ null, "repo", "maven", "com.example", "a", List.of("1.0"), null, null);
+
+ assertEquals("Disposed", retry.successfulVersions().get("1.0").status());
+ verify(reposiliteClient, times(2)).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"),
+ eq("com.example"), eq("a"), eq("1.0"), eq("a-1.0.jar"));
+ }
+
+ /**
+ * Raised by Greptile's review of the fix above, for npm specifically: once a concurrent
+ * disposal's own packument-removal half has already landed (Verdaccio's real two-step
+ * unpublish, see {@code VerdaccioSidecarClient#deletePackageVersionAsset}'s own javadoc), a
+ * fresh {@code listPackageVersionAssetNames} call goes blind to the tarball even though that
+ * disposal's own {@code pendingAssetNames} still correctly names it (its own tarball delete
+ * is what actually failed). Overwriting {@code pendingAssetNames} with only the fresh
+ * (now-empty) list here would lose that name outright; the union of both must still name the
+ * tarball for cleanup.
+ */
+ @Test
+ void forgetContainerBackedStatusOverrideIfUnchangedMergesTheFreshListingWithWhatTheOverrideAlreadyKnows() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ CodeArtifactRepository created = service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ String repoId = created.getSidecarContainerIds().get("npm");
+ when(verdaccioClient.listPackageVersions(eq(repoId), eq("dom"), eq("repo"), isNull(), eq("my-pkg")))
+ .thenReturn(List.of(
+ new RepositorySidecarManager.PackageVersionTimestamp("1.0.0", Instant.ofEpochSecond(1000))));
+ String beforeRevision = service.requireContainerBackedVersionNotArchivedOrDisposed(REGION, "dom", null,
+ "repo", "npm", null, "my-pkg", "1.0.0");
+ when(verdaccioClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"))).thenReturn(List.of("my-pkg-1.0.0.tgz"));
+ doThrow(new IllegalStateException("sidecar unreachable"))
+ .when(verdaccioClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+ assertThrows(IllegalStateException.class, () -> service.disposePackageVersions(REGION, "dom", null, "repo",
+ "npm", null, "my-pkg", List.of("1.0.0"), null, null));
+
+ // Verdaccio's own packument no longer lists the version at all (its removal half of the
+ // two-step unpublish already landed, even though the tarball delete above failed), so a
+ // fresh listing now reads empty, exactly the ambiguous signal Greptile's review describes.
+ when(verdaccioClient.listPackageVersionAssetNames(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"))).thenReturn(List.of());
+ doNothing().when(verdaccioClient).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+
+ service.forgetContainerBackedStatusOverrideIfUnchanged(REGION, "dom", null, "repo", "npm", null, "my-pkg",
+ "1.0.0", beforeRevision);
+
+ // Twice in total: the setup dispose above threw (counted on the mock regardless), this
+ // call's own redispose is the one that actually finishes deleting the tarball.
+ verify(verdaccioClient, times(2)).deletePackageVersionAsset(eq(repoId), eq("dom"), eq("repo"), isNull(),
+ eq("my-pkg"), eq("1.0.0"), eq("my-pkg-1.0.0.tgz"));
+ }
+
+ /**
+ * Qodo review finding on this PR: a generic {@code publishPackageVersion} treated every
+ * existing version whose status was not Published (including Disposed and Archived) exactly
+ * like a brand new or Unfinished one, letting a publish silently resurrect a version the
+ * User Guide says can never move back to Published once either status applies.
+ */
+ @Test
+ void publishPackageVersionRejectsRepublishOfADisposedOrArchivedGenericVersion() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ byte[] content = "v1".getBytes(StandardCharsets.UTF_8);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "archived-pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "false", content);
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "generic", "ns", "archived-pkg",
+ List.of("1.0.0"), null, null, "Archived");
+ AwsException archivedError = assertThrows(AwsException.class, () -> service.publishPackageVersion(REGION,
+ "dom", null, "repo", "generic", "ns", "archived-pkg", "1.0.0", "a.txt", Digests.sha256Hex(content),
+ "false", content));
+ assertEquals("ConflictException", archivedError.getErrorCode());
+
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "disposed-pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "false", content);
+ service.disposePackageVersions(REGION, "dom", null, "repo", "generic", "ns", "disposed-pkg",
+ List.of("1.0.0"), null, null);
+ AwsException disposedError = assertThrows(AwsException.class, () -> service.publishPackageVersion(REGION,
+ "dom", null, "repo", "generic", "ns", "disposed-pkg", "1.0.0", "a.txt", Digests.sha256Hex(content),
+ "false", content));
+ assertEquals("ConflictException", disposedError.getErrorCode());
+ }
+
+ /**
+ * Unlisted only hides a version from listings, and the User Guide never says republishing it
+ * is blocked the way it does for Archived/Disposed, so this folds into the same
+ * idempotent-replay rule Published already has: an exact byte-identical retry is a no-op, but
+ * genuinely different content is still rejected, rather than silently rebuilding it as though
+ * no version existed there at all (which the Unfinished fallthrough would otherwise do).
+ */
+ @Test
+ void publishPackageVersionReplaysAnUnlistedVersionIdempotentlyButRejectsDifferentContent() {
+ service.createDomain(REGION, "dom", null, Map.of());
+ service.createRepository(REGION, "dom", null, "repo", null, null, Map.of());
+ byte[] content = "v1".getBytes(StandardCharsets.UTF_8);
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "false", content);
+ service.updatePackageVersionsStatus(REGION, "dom", null, "repo", "generic", "ns", "pkg", List.of("1.0.0"),
+ null, null, "Unlisted");
+
+ service.publishPackageVersion(REGION, "dom", null, "repo", "generic", "ns", "pkg", "1.0.0", "a.txt",
+ Digests.sha256Hex(content), "false", content);
+ CodeArtifactPackageVersion pv = service.describePackageVersion(REGION, "dom", null, "repo", "generic", "ns",
+ "pkg", "1.0.0");
+ assertEquals("Unlisted", pv.getStatus());
+
+ byte[] different = "v2".getBytes(StandardCharsets.UTF_8);
+ AwsException e = assertThrows(AwsException.class, () -> service.publishPackageVersion(REGION, "dom", null,
+ "repo", "generic", "ns", "pkg", "1.0.0", "a.txt", Digests.sha256Hex(different), "false", different));
+ assertEquals("ConflictException", e.getErrorCode());
+ }
+
// --------------------------------------------- NuGet revision normalization
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClientTest.java b/src/test/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClientTest.java
index 3a2169bfe6..7de469bbc3 100644
--- a/src/test/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClientTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/codeartifact/ReposiliteSidecarClientTest.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpServer;
+import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.XmlParser;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -22,14 +23,17 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicReference;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
@@ -784,6 +788,439 @@ class ReposiliteSidecarClientTest {
assertEquals("1.0", XmlParser.extractFirst(xml, "release", null));
}
+ /**
+ * {@link io.github.hectorvent.floci.services.codeartifact.ReposiliteSidecarClient#recordVersionDisposed}'s
+ * dispose-time counterpart to {@link #recordVersionAvailableAppendsToExistingVersionsAndAdvancesReleaseForANonSnapshot}:
+ * removing a non-latest version must leave {@code latest}/{@code release} exactly as they
+ * were, since the metadata's own append-order list is untouched past the removed entry.
+ */
+ @Test
+ void recordVersionDisposedRemovesTheVersionAndLeavesLatestAndReleaseUntouchedWhenItWasNeitherOne() {
+ settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
+ server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>2.0</latest><release>2.0</release><versions><version>1.0</version>"
+ + "<version>2.0</version></versions><lastUpdated>20260101000000</lastUpdated></versioning>"
+ + "</metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ AtomicReference<byte[]> putBody = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else if (metadataPath.equals(exchange.getRequestURI().getPath())) {
+ putBody.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ } else {
+ // This context path-matches the checksum siblings this emulator now also
+ // rewrites alongside the metadata file itself (see
+ // ReposiliteSidecarClient#recordVersionDisposed), so only the exact metadata
+ // path's own PUT is captured into putBody.
+ respond(exchange, 200, "");
+ }
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ String xml = new String(putBody.get(), StandardCharsets.UTF_8);
+ assertEquals(List.of("2.0"), XmlParser.extractAll(xml, "version"));
+ assertEquals("2.0", XmlParser.extractFirst(xml, "latest", null));
+ assertEquals("2.0", XmlParser.extractFirst(xml, "release", null));
+ }
+
+ /**
+ * Removing the current {@code latest}/{@code release} version itself must recompute both from
+ * whatever remains, in the same append order the metadata already preserves: the last
+ * surviving entry becomes the new {@code latest}, and the last surviving non-{@code -SNAPSHOT}
+ * entry becomes the new {@code release} (here, that is the same entry since neither remaining
+ * version is a snapshot).
+ */
+ @Test
+ void recordVersionDisposedRecomputesLatestAndReleaseWhenTheDisposedVersionWasTheLatest() {
+ settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
+ server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>3.0</latest><release>3.0</release><versions><version>1.0</version>"
+ + "<version>2.0</version><version>3.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ AtomicReference<byte[]> putBody = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else if (metadataPath.equals(exchange.getRequestURI().getPath())) {
+ putBody.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ } else {
+ // This context path-matches the checksum siblings this emulator now also
+ // rewrites alongside the metadata file itself (see
+ // ReposiliteSidecarClient#recordVersionDisposed), so only the exact metadata
+ // path's own PUT is captured into putBody.
+ respond(exchange, 200, "");
+ }
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "3.0");
+
+ String xml = new String(putBody.get(), StandardCharsets.UTF_8);
+ assertEquals(List.of("1.0", "2.0"), XmlParser.extractAll(xml, "version"));
+ assertEquals("2.0", XmlParser.extractFirst(xml, "latest", null));
+ assertEquals("2.0", XmlParser.extractFirst(xml, "release", null));
+ }
+
+ /**
+ * {@code release} skips back past a surviving {@code -SNAPSHOT} entry to the last real release,
+ * the same rule {@link #recordVersionAvailableLeavesTheExistingReleaseUntouchedForASnapshotVersion}
+ * already proves for the add path.
+ */
+ @Test
+ void recordVersionDisposedSkipsASnapshotWhenRecomputingRelease() {
+ settingsBody.set("{\"repositories\":[{\"id\":\"dom--repo\",\"visibility\":\"PUBLIC\",\"redeployment\":false}]}");
+ server.createContext("/api/settings/domain/maven", exchange -> respond(exchange, 200, settingsBody.get()));
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>2.0-SNAPSHOT</latest><release>1.0</release><versions><version>1.0</version>"
+ + "<version>2.0-SNAPSHOT</version></versions><lastUpdated>20260101000000</lastUpdated>"
+ + "</versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ AtomicReference<byte[]> putBody = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else if (metadataPath.equals(exchange.getRequestURI().getPath())) {
+ putBody.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ } else {
+ // This context path-matches the checksum siblings this emulator now also
+ // rewrites alongside the metadata file itself (see
+ // ReposiliteSidecarClient#recordVersionDisposed), so only the exact metadata
+ // path's own PUT is captured into putBody.
+ respond(exchange, 200, "");
+ }
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ String xml = new String(putBody.get(), StandardCharsets.UTF_8);
+ assertEquals(List.of("2.0-SNAPSHOT"), XmlParser.extractAll(xml, "version"));
+ assertEquals("2.0-SNAPSHOT", XmlParser.extractFirst(xml, "latest", null));
+ assertNull(XmlParser.extractFirst(xml, "release", null), "no real release survives, so release must be "
+ + "omitted rather than naming a snapshot");
+ }
+
+ /**
+ * Raised by Greptile's review: a real {@code mvn deploy} always also PUTs {@code
+ * maven-metadata.xml.sha1}/{@code .md5}, so {@link
+ * io.github.hectorvent.floci.services.codeartifact.ReposiliteSidecarClient#recordVersionDisposed}'s
+ * own rewrite of the metadata must carry fresh checksums of whatever it just wrote, not leave
+ * the pre-dispose checksums standing over content that no longer matches them.
+ */
+ @Test
+ void recordVersionDisposedRewritesTheSha1AndMd5ChecksumsToMatchTheNewMetadata() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>2.0</latest><release>2.0</release><versions><version>1.0</version>"
+ + "<version>2.0</version></versions><lastUpdated>20260101000000</lastUpdated></versioning>"
+ + "</metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ AtomicReference<byte[]> putBody = new AtomicReference<>();
+ AtomicReference<byte[]> sha1Body = new AtomicReference<>();
+ AtomicReference<byte[]> md5Body = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else if (metadataPath.equals(exchange.getRequestURI().getPath())) {
+ putBody.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> {
+ sha1Body.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ });
+ server.createContext(metadataPath + ".md5", exchange -> {
+ md5Body.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ assertEquals(Digests.sha1Hex(putBody.get()), new String(sha1Body.get(), StandardCharsets.UTF_8));
+ assertEquals(Digests.md5Hex(putBody.get()), new String(md5Body.get(), StandardCharsets.UTF_8));
+ }
+
+ /** The counterpart to the rewrite case above: the metadata PUT itself failing must not be swallowed. */
+ @Test
+ void recordVersionDisposedThrowsWhenTheMetadataRewriteItselfFails() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>2.0</latest><release>2.0</release><versions><version>1.0</version>"
+ + "<version>2.0</version></versions><lastUpdated>20260101000000</lastUpdated></versioning>"
+ + "</metadata>";
+ server.createContext("/dom--repo/com/example/a/maven-metadata.xml", exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ respond(exchange, 500, "");
+ }
+ });
+
+ assertThrows(IllegalStateException.class,
+ () -> client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0"));
+ }
+
+ /**
+ * Greptile's review again: {@link
+ * io.github.hectorvent.floci.services.codeartifact.ReposiliteSidecarClient#recordVersionDisposed}
+ * also removes the two checksum siblings when the metadata file itself is removed outright
+ * (every version disposed), not just the metadata file.
+ */
+ @Test
+ void recordVersionDisposedDeletesTheChecksumSiblingsWhenTheMetadataFileIsDeleted() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ List<String> deletedPaths = new CopyOnWriteArrayList<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ deletedPaths.add(exchange.getRequestURI().getPath());
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> {
+ // deleteArtifactIfPresent checks existence with a HEAD first; only the real DELETE
+ // that follows is the one this test cares about recording.
+ if ("DELETE".equals(exchange.getRequestMethod())) {
+ deletedPaths.add(exchange.getRequestURI().getPath());
+ }
+ respond(exchange, 200, "");
+ });
+ server.createContext(metadataPath + ".md5", exchange -> {
+ if ("DELETE".equals(exchange.getRequestMethod())) {
+ deletedPaths.add(exchange.getRequestURI().getPath());
+ }
+ respond(exchange, 200, "");
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ assertThat(deletedPaths, containsInAnyOrder(metadataPath, metadataPath + ".sha1", metadataPath + ".md5"));
+ }
+
+ /** A checksum sibling missing entirely (never pushed, or a sidecar restored from an older snapshot) is a no-op. */
+ @Test
+ void recordVersionDisposedToleratesAMissingChecksumSiblingOnDelete() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> respond(exchange, 404, ""));
+ server.createContext(metadataPath + ".md5", exchange -> respond(exchange, 404, ""));
+
+ assertDoesNotThrow(() -> client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0"));
+ }
+
+ /**
+ * Raised by Greptile's review: a HEAD failing with something other than a confirmed 404 (a
+ * genuine sidecar error, not a clean "it's not there" answer) must not be treated the same as
+ * a confirmed-absent checksum; silently skipping the delete there would report a successful
+ * disposal while the sidecar's own real error was never surfaced or retried.
+ */
+ @Test
+ void recordVersionDisposedThrowsWhenTheChecksumExistenceCheckFails() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> respond(exchange, 500, ""));
+ server.createContext(metadataPath + ".md5", exchange -> respond(exchange, 200, ""));
+
+ assertThrows(IllegalStateException.class,
+ () -> client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0"));
+ }
+
+ /**
+ * Raised by Greptile's review: a retry whose first attempt already deleted the metadata file
+ * itself, but then failed on exactly a checksum delete, used to hit the {@code existing.isEmpty()}
+ * early return and report success leaving that checksum behind, since there was no metadata
+ * left for it to compare against. The checksum siblings are now cleaned up on this path too.
+ */
+ @Test
+ void recordVersionDisposedCleansUpLingeringChecksumsEvenWhenTheMetadataFileIsAlreadyGone() {
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ List<String> deletedPaths = new CopyOnWriteArrayList<>();
+ server.createContext(metadataPath, exchange -> respond(exchange, 404, ""));
+ server.createContext(metadataPath + ".sha1", exchange -> {
+ // deleteArtifactIfPresent checks existence with a HEAD first; only the real DELETE
+ // that follows is the one this test cares about recording.
+ if ("DELETE".equals(exchange.getRequestMethod())) {
+ deletedPaths.add(exchange.getRequestURI().getPath());
+ }
+ respond(exchange, 200, "");
+ });
+ server.createContext(metadataPath + ".md5", exchange -> {
+ if ("DELETE".equals(exchange.getRequestMethod())) {
+ deletedPaths.add(exchange.getRequestURI().getPath());
+ }
+ respond(exchange, 200, "");
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ assertThat(deletedPaths, containsInAnyOrder(metadataPath + ".sha1", metadataPath + ".md5"));
+ }
+
+ /**
+ * Raised by Greptile's review: {@code fetchArtifact} itself returns empty for every non-200
+ * response, 500 included, which must not be read as "the metadata file is confirmed gone."
+ * A transient read failure here must surface, not silently report a successful disposal while
+ * the metadata on disk still lists the version this was supposed to remove.
+ */
+ @Test
+ void recordVersionDisposedThrowsWhenTheMetadataReadFails() {
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ server.createContext(metadataPath, exchange -> respond(exchange, 500, ""));
+
+ assertThrows(IllegalStateException.class,
+ () -> client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0"));
+ }
+
+ /**
+ * A metadata file that would end up naming no versions at all is deleted outright, matching
+ * how a package that never had a version published has no metadata file at all.
+ */
+ @Test
+ void recordVersionDisposedDeletesTheMetadataFileWhenNoVersionsAreLeft() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ AtomicReference<String> deletedMethod = new AtomicReference<>();
+ server.createContext("/dom--repo/com/example/a/maven-metadata.xml", exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ deletedMethod.set(exchange.getRequestMethod());
+ respond(exchange, 200, "");
+ }
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "1.0");
+
+ assertEquals("DELETE", deletedMethod.get());
+ }
+
+ /**
+ * A version the metadata never named to begin with (already removed by an earlier call, or
+ * disposed before {@code maven-metadata.xml} ever existed) leaves the metadata itself
+ * untouched: nothing is written back to that exact path.
+ *
+ * <p>Raised by Greptile's review: this same early return used to skip the checksum siblings
+ * too, so a retry whose first attempt removed the version but then failed on exactly the
+ * checksum write never got another chance to repair it. The checksums are now repaired every
+ * time this returns here, idempotently (the metadata content itself did not change), not just
+ * the one call that happened to also rewrite the metadata.
+ */
+ @Test
+ void recordVersionDisposedIsANoOpWhenTheMetadataNeverNamedTheVersion() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ AtomicReference<String> writeMethod = new AtomicReference<>();
+ AtomicReference<byte[]> sha1Body = new AtomicReference<>();
+ AtomicReference<byte[]> md5Body = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else if (metadataPath.equals(exchange.getRequestURI().getPath())) {
+ writeMethod.set(exchange.getRequestMethod());
+ respond(exchange, 200, "");
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> {
+ sha1Body.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ });
+ server.createContext(metadataPath + ".md5", exchange -> {
+ md5Body.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ });
+
+ client.recordVersionDisposed("dom--repo", "com.example", "a", "9.9");
+
+ assertNull(writeMethod.get(), "expected no PUT/DELETE of the metadata file itself");
+ assertEquals(Digests.sha1Hex(existing.getBytes(StandardCharsets.UTF_8)),
+ new String(sha1Body.get(), StandardCharsets.UTF_8));
+ assertEquals(Digests.md5Hex(existing.getBytes(StandardCharsets.UTF_8)),
+ new String(md5Body.get(), StandardCharsets.UTF_8));
+ }
+
+ /**
+ * Raised by Greptile's review: {@code deployArtifact}'s own idempotent short-circuit (the
+ * checksum already on the sidecar matches byte for byte, so nothing is actually sent) also
+ * reports {@code wroteNewContent() == false}, the exact same signal a genuine failure gives.
+ * A disposal retry whose {@code .sha1} already landed on an earlier attempt, but then failed
+ * on {@code .md5}, must not treat that already-correct, unchanged {@code .sha1} as a failure
+ * all over again: that would stop the retry before it ever reached {@code .md5} a second
+ * time, getting stuck on the one checksum that was already fine.
+ */
+ @Test
+ void recordVersionDisposedRepairsTheRemainingChecksumEvenWhenTheOtherAlreadyMatches() {
+ String existing = "<metadata><groupId>com.example</groupId><artifactId>a</artifactId><versioning>"
+ + "<latest>1.0</latest><release>1.0</release><versions><version>1.0</version></versions>"
+ + "<lastUpdated>20260101000000</lastUpdated></versioning></metadata>";
+ String metadataPath = "/dom--repo/com/example/a/maven-metadata.xml";
+ String correctSha1 = Digests.sha1Hex(existing.getBytes(StandardCharsets.UTF_8));
+ AtomicReference<byte[]> md5Body = new AtomicReference<>();
+ server.createContext(metadataPath, exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, existing);
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".sha1", exchange -> {
+ // Already correct: a GET returns exactly what the retry is about to compute and PUT,
+ // so deployArtifact's own existingArtifactMatches short-circuits (200, wroteNewContent
+ // false) without ever reaching a real PUT here.
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 200, correctSha1);
+ } else {
+ respond(exchange, 200, "");
+ }
+ });
+ server.createContext(metadataPath + ".md5", exchange -> {
+ if ("GET".equals(exchange.getRequestMethod())) {
+ respond(exchange, 404, "");
+ } else {
+ md5Body.set(exchange.getRequestBody().readAllBytes());
+ respond(exchange, 200, "");
+ }
+ });
+
+ assertDoesNotThrow(() -> client.recordVersionDisposed("dom--repo", "com.example", "a", "9.9"));
+
+ assertEquals(Digests.md5Hex(existing.getBytes(StandardCharsets.UTF_8)),
+ new String(md5Body.get(), StandardCharsets.UTF_8));
+ }
+
private static void respond(HttpExchange exchange, int status, String body) throws IOException {
byte[] bytes = body.getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(status, bytes.length);