fix: minFileVersion/maxFileVersion incorrect matching (#603)

This commit is contained in:
Nerivec
2024-11-18 20:48:25 +01:00
committed by GitHub
parent 8c5a10ed98
commit 63b969db86
2 changed files with 74 additions and 2 deletions

View File

@@ -151,8 +151,8 @@ export function findMatchImage(
(i) => (i) =>
i.imageType === image.imageType && i.imageType === image.imageType &&
i.manufacturerCode === image.manufacturerCode && i.manufacturerCode === image.manufacturerCode &&
(!i.minFileVersion || image.fileVersion >= i.minFileVersion) && extraMetas.minFileVersion === i.minFileVersion &&
(!i.maxFileVersion || image.fileVersion <= i.maxFileVersion) && extraMetas.maxFileVersion === i.maxFileVersion &&
i.modelId === extraMetas.modelId && i.modelId === extraMetas.modelId &&
(!(i.manufacturerName && extraMetas.manufacturerName) || primitivesArrayEquals(i.manufacturerName, extraMetas.manufacturerName)), (!(i.manufacturerName && extraMetas.manufacturerName) || primitivesArrayEquals(i.manufacturerName, extraMetas.manufacturerName)),
); );

View File

@@ -21,6 +21,7 @@ import {
IMAGE_V14_1_METAS, IMAGE_V14_1_METAS,
IMAGE_V14_2, IMAGE_V14_2,
IMAGE_V14_2_METAS, IMAGE_V14_2_METAS,
IMAGES_TEST_DIR,
PREV_IMAGES_TEST_DIR_PATH, PREV_IMAGES_TEST_DIR_PATH,
useImage, useImage,
withExtraMetas, withExtraMetas,
@@ -442,6 +443,77 @@ Text after end tag`);
]); ]);
}); });
it('success with newer than current but minFileVersion keeps both', async () => {
filePaths = [useImage(IMAGE_V13_1), useImage(IMAGE_V14_1)];
const newContext = withBody(
`Text before start tag \`\`\`json [{"fileName":"ZLinky_router_v14.ota", "minFileVersion": 16783874}] \`\`\` Text after end tag`,
);
// @ts-expect-error mock
await checkOtaPR(github, core, newContext);
expect(readManifestSpy).toHaveBeenCalledTimes(2);
expect(addImageToBaseSpy).toHaveBeenCalledTimes(2);
expect(addImageToPrevSpy).toHaveBeenCalledTimes(0);
expect(writeManifestSpy).toHaveBeenCalledTimes(2);
expect(writeManifestSpy).toHaveBeenCalledWith(common.BASE_INDEX_MANIFEST_FILENAME, [
withExtraMetas(IMAGE_V13_1_METAS, {
// @ts-expect-error override
url: `https://github.com/Koenkk/zigbee-OTA/raw/master/${common.BASE_IMAGES_DIR}/${IMAGES_TEST_DIR}/${IMAGE_V13_1}`,
}),
withExtraMetas(IMAGE_V14_1_METAS, {minFileVersion: 16783874}),
]);
expect(writeManifestSpy).toHaveBeenCalledWith(common.PREV_INDEX_MANIFEST_FILENAME, []);
});
it('success with newer than current but maxFileVersion keeps both', async () => {
filePaths = [useImage(IMAGE_V13_1), useImage(IMAGE_V14_1)];
const newContext = withBody(
`Text before start tag \`\`\`json [{"fileName":"ZLinky_router_v13.ota", "maxFileVersion": 16783873}] \`\`\` Text after end tag`,
);
// @ts-expect-error mock
await checkOtaPR(github, core, newContext);
expect(readManifestSpy).toHaveBeenCalledTimes(2);
expect(addImageToBaseSpy).toHaveBeenCalledTimes(2);
expect(addImageToPrevSpy).toHaveBeenCalledTimes(0);
expect(writeManifestSpy).toHaveBeenCalledTimes(2);
expect(writeManifestSpy).toHaveBeenCalledWith(common.BASE_INDEX_MANIFEST_FILENAME, [
withExtraMetas(IMAGE_V13_1_METAS, {
// @ts-expect-error override
url: `https://github.com/Koenkk/zigbee-OTA/raw/master/${common.BASE_IMAGES_DIR}/${IMAGES_TEST_DIR}/${IMAGE_V13_1}`,
maxFileVersion: 16783873,
}),
IMAGE_V14_1_METAS,
]);
expect(writeManifestSpy).toHaveBeenCalledWith(common.PREV_INDEX_MANIFEST_FILENAME, []);
});
it('success with newer than current but maxFileVersion/minFileVersion keeps both', async () => {
filePaths = [useImage(IMAGE_V13_1), useImage(IMAGE_V14_1)];
const newContext = withBody(
`Text before start tag \`\`\`json [{"fileName":"ZLinky_router_v13.ota", "maxFileVersion": 16783873},{"fileName":"ZLinky_router_v14.ota", "minFileVersion": 16783874}] \`\`\` Text after end tag`,
);
// @ts-expect-error mock
await checkOtaPR(github, core, newContext);
expect(readManifestSpy).toHaveBeenCalledTimes(2);
expect(addImageToBaseSpy).toHaveBeenCalledTimes(2);
expect(addImageToPrevSpy).toHaveBeenCalledTimes(0);
expect(writeManifestSpy).toHaveBeenCalledTimes(2);
expect(writeManifestSpy).toHaveBeenCalledWith(common.BASE_INDEX_MANIFEST_FILENAME, [
withExtraMetas(IMAGE_V13_1_METAS, {
// @ts-expect-error override
url: `https://github.com/Koenkk/zigbee-OTA/raw/master/${common.BASE_IMAGES_DIR}/${IMAGES_TEST_DIR}/${IMAGE_V13_1}`,
maxFileVersion: 16783873,
}),
withExtraMetas(IMAGE_V14_1_METAS, {minFileVersion: 16783874}),
]);
expect(writeManifestSpy).toHaveBeenCalledWith(common.PREV_INDEX_MANIFEST_FILENAME, []);
});
it('failure with invalid extra metas', async () => { it('failure with invalid extra metas', async () => {
filePaths = [useImage(IMAGE_V14_1)]; filePaths = [useImage(IMAGE_V14_1)];
const newContext = withBody(`Text before start tag \`\`\`json {"manufacturerName": "myManuf"} \`\`\` Text after end tag`); const newContext = withBody(`Text before start tag \`\`\`json {"manufacturerName": "myManuf"} \`\`\` Text after end tag`);