fix(plugins): accept weak catalog etags

This commit is contained in:
2026-09-01 12:17:31 +08:00
parent 5e8b7266c2
commit 38f2358db3
3 changed files with 88 additions and 1 deletions

View File

@@ -350,6 +350,34 @@ describe('Marketplace client and account cache', () => {
await expect(client.readCatalog({ limit: 10 })).resolves.toMatchObject({ stale: true, total: 1 });
});
it('accepts a weak composite ETag from compressed Marketplace responses and reuses it verbatim', async () => {
const pricingVersionId = '00000000-0000-0000-0000-000000000420';
const etag = `W/"plugins-2-tp-${pricingVersionId}"`;
const fetcher = vi.fn<typeof fetch>()
.mockResolvedValueOnce(response({ ...catalogPage, catalog_generation: 2 }, {}, {
ETag: etag,
'X-Plugin-Catalog-Generation': '2',
'X-Token-Point-Pricing-Version': pricingVersionId,
}))
.mockResolvedValueOnce(new Response(null, { status: 304 }));
const client = createMarketplaceClient({
fetchImpl: fetcher,
apiBaseUrl: 'https://square.example',
getAccessToken: async () => null,
subscribeSession: () => () => undefined,
});
await expect(client.readCatalog({ limit: 10 })).resolves.toMatchObject({
total: 1,
etag,
generation: 2,
pricingVersionId,
stale: false,
});
await expect(client.readCatalog({ limit: 10 })).resolves.toMatchObject({ etag, stale: false });
expect(fetcher.mock.calls[1]?.[1]?.headers).toMatchObject({ 'If-None-Match': etag });
});
it('refreshes download authentication at most once before accepting the artifact', async () => {
const archive = Buffer.from('signed-artifact');
const { grant } = signedGrant(archive);