Files
webstudio/packages/cli/scripts/release-smoke-registry.test.ts
Oleg Isonen 57d9ad14cd fix: Retry published CLI registry lookup (#6013)
## What changed

- Retry npm version and integrity resolution inside the CLI registry
smoke test.
- Keep retry timing injectable so the propagation race is covered by a
fast unit test.
- Preserve the final npm error when all registry attempts are exhausted.

## Why

CLI 0.286.0 was published successfully, but npm briefly exposed
integrity metadata while the exact version lookup still returned 404.
The post-publish smoke failed and the dependent docs publication job was
skipped.

The 0.286.0 documentation snapshot has been recovered directly on the
`docs` branch.

Ref #6007

## Verification

- [x] Regression test demonstrated failing before the implementation and
passing afterward
- [x] CLI registry/versioning tests: 3 passed
- [x] CLI typecheck
- [x] Formatting and diff checks
- [x] Documentation impact reviewed: no product-doc source change is
needed in this PR; the missed 0.286.0 snapshot was published separately
to `docs`
2026-08-05 22:03:26 +02:00

52 lines
1.4 KiB
TypeScript

import { expect, test, vi } from "vitest";
import { resolveRegistryTarget } from "./release-smoke-registry";
test("retries while an exact npm version is still propagating", async () => {
let versionAttempts = 0;
const readNpmJson = vi.fn(async (args: string[]) => {
if (args.includes("version")) {
versionAttempts += 1;
if (versionAttempts === 1) {
throw new Error("npm returned 404");
}
return "0.286.0";
}
return "sha512-integrity";
});
const delay = vi.fn(async () => {});
await expect(
resolveRegistryTarget("webstudio@0.286.0", {
attempts: 3,
delay,
readNpmJson,
})
).resolves.toEqual({
source: "registry",
version: "0.286.0",
installSpec: "webstudio@0.286.0",
integrity: "sha512-integrity",
});
expect(delay).toHaveBeenCalledOnce();
expect(readNpmJson).toHaveBeenCalledTimes(3);
});
test("reports the final registry error after retries are exhausted", async () => {
const readNpmJson = vi.fn(async () => {
throw new Error("npm returned 404");
});
const delay = vi.fn(async () => {});
await expect(
resolveRegistryTarget("webstudio@0.286.0", {
attempts: 2,
delay,
readNpmJson,
})
).rejects.toThrow(
"Could not resolve registry package webstudio@0.286.0 after 2 attempts: npm returned 404"
);
expect(delay).toHaveBeenCalledOnce();
expect(readNpmJson).toHaveBeenCalledTimes(2);
});