Skip to content

Commit 325dc64

Browse files
gjasnyclaude
andauthored
fix(datasource/aws-machine-image): return all AMI releases for minimumReleaseAge filtering (#43749)
* fix(datasource/aws-machine-image): return all AMI releases for minimumReleaseAge filtering Previously, _getReleases only returned the latest image in the releases array, which broke minimumReleaseAge filtering. When the latest AMI was too new, there were no older candidates to fall back to. Fixed by: - _getReleases now returns all matching AMIs as separate releases (sorted oldest→newest) - _getDigest simplified to read directly from the images array to ensure latest digest is still returned - Added reproducer test verifying all 3 images are returned This aligns with how other datasources (npm, PyPI, etc.) work — they return complete version history to allow minimumReleaseAge filtering to find an appropriately-aged candidate. Co-authored-by: Claude Code <claude@anthropic.com> * chore: apply suggestion * fixup! chore: apply suggestion --------- Co-authored-by: Claude Code <claude@anthropic.com>
1 parent 3e15fc2 commit 325dc64

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

lib/modules/datasource/aws-machine-image/index.spec.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ describe('modules/datasource/aws-machine-image/index', () => {
216216
expect(res).toStrictEqual(image3.Name);
217217
});
218218

219+
it('without newValue, with newest image missing a name to be null', async () => {
220+
const { Name, ...imageWithoutName } = image3;
221+
mockDescribeImagesCommand({ Images: [imageWithoutName] });
222+
const res = await getDigest({
223+
datasource,
224+
packageName: '[{"Name":"owner-id","Values":["602401143452"]}]',
225+
});
226+
expect(res).toBeNull();
227+
});
228+
219229
it('without newValue, with 3 matching image to return the newest image', async () => {
220230
mockDescribeImagesCommand(mock3Images);
221231
const res = await getDigest({
@@ -302,15 +312,27 @@ describe('modules/datasource/aws-machine-image/index', () => {
302312
});
303313
});
304314

305-
it('with 3 matching image to return the newest image', async () => {
315+
it('with 3 matching images returns all images as releases, not just the newest', async () => {
306316
mockDescribeImagesCommand(mock3Images);
307317
const res = await getPkgReleases({
308318
datasource,
309319
packageName:
310-
'[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["with 3 matching image to return the newest image"]}]',
320+
'[{"Name":"owner-id","Values":["602401143452"]},{"Name":"name","Values":["with 3 matching images returns all"]}]',
311321
});
312322
expect(res).toEqual({
313323
releases: [
324+
{
325+
isDeprecated: false,
326+
newDigest: image1.Name,
327+
releaseTimestamp: image1.CreationDate,
328+
version: image1.ImageId,
329+
},
330+
{
331+
isDeprecated: true,
332+
newDigest: image2.Name,
333+
releaseTimestamp: image2.CreationDate,
334+
version: image2.ImageId,
335+
},
314336
{
315337
isDeprecated: false,
316338
newDigest: image3.Name,

lib/modules/datasource/aws-machine-image/index.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,7 @@ export class AwsMachineImageDatasource extends Datasource {
141141
return null;
142142
}
143143

144-
const res = await this.getReleases({ packageName: serializedAmiFilter });
145-
return (
146-
res?.releases?.[0]?.newDigest ??
147-
/* v8 ignore next -- fallback when the AMI filter matches no image */ null
148-
); // TODO: needs test
144+
return images.at(-1)!.Name ?? null;
149145
}
150146

151147
override getDigest(
@@ -166,21 +162,17 @@ export class AwsMachineImageDatasource extends Datasource {
166162
packageName: serializedAmiFilter,
167163
}: GetReleasesConfig): Promise<ReleaseResult | null> {
168164
const images = await this.getSortedAwsMachineImages(serializedAmiFilter);
169-
const latestImage = images.at(-1);
170-
if (!latestImage?.ImageId) {
165+
if (!images.length || !images.at(-1)!.ImageId) {
171166
return null;
172167
}
173168
return {
174-
releases: [
175-
{
176-
version: latestImage.ImageId,
177-
releaseTimestamp: asTimestamp(latestImage.CreationDate),
178-
isDeprecated:
179-
Date.parse(latestImage.DeprecationTime ?? this.now.toString()) <
180-
this.now,
181-
newDigest: latestImage.Name,
182-
},
183-
],
169+
releases: images.map((image) => ({
170+
version: image.ImageId!,
171+
releaseTimestamp: asTimestamp(image.CreationDate),
172+
isDeprecated:
173+
Date.parse(image.DeprecationTime ?? this.now.toString()) < this.now,
174+
newDigest: image.Name,
175+
})),
184176
};
185177
}
186178

0 commit comments

Comments
 (0)