Skip to content

Commit

Permalink
fix: minFileVersion/maxFileVersion incorrect matching (#603)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerivec authored Nov 18, 2024
1 parent 8c5a10e commit 63b969d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ export function findMatchImage(
(i) =>
i.imageType === image.imageType &&
i.manufacturerCode === image.manufacturerCode &&
(!i.minFileVersion || image.fileVersion >= i.minFileVersion) &&
(!i.maxFileVersion || image.fileVersion <= i.maxFileVersion) &&
extraMetas.minFileVersion === i.minFileVersion &&
extraMetas.maxFileVersion === i.maxFileVersion &&
i.modelId === extraMetas.modelId &&
(!(i.manufacturerName && extraMetas.manufacturerName) || primitivesArrayEquals(i.manufacturerName, extraMetas.manufacturerName)),
);
Expand Down
72 changes: 72 additions & 0 deletions tests/ghw_check_ota_pr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
IMAGE_V14_1_METAS,
IMAGE_V14_2,
IMAGE_V14_2_METAS,
IMAGES_TEST_DIR,
PREV_IMAGES_TEST_DIR_PATH,
useImage,
withExtraMetas,
Expand Down Expand Up @@ -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 () => {
filePaths = [useImage(IMAGE_V14_1)];
const newContext = withBody(`Text before start tag \`\`\`json {"manufacturerName": "myManuf"} \`\`\` Text after end tag`);
Expand Down

0 comments on commit 63b969d

Please sign in to comment.