Skip to content

Commit 6a537f8

Browse files
ScottN-PVclaude
andcommitted
fix(web): update everything includes npm-installed servers again
The npm registry check sent Effect tracing headers, which made the browser send a CORS preflight that registry.npmjs.org rejects. The failed check read as "not published", so every CLI/npm server was left out of the run. Closes #18690 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 701fc83 commit 6a537f8

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { AtomRegistry } from "effect/reactivity";
2+
import * as AsyncResult from "effect/reactivity/AsyncResult";
3+
import { afterAll, afterEach, describe, expect, it, vi } from "vite-plus/test";
4+
5+
import { npmReleasePublishedAtom } from "./npmRelease";
6+
7+
const version = "0.0.46-nightly.20261012.3021";
8+
9+
// FetchHttpClient reads globalThis.fetch once and keeps it, so every test shares this mock.
10+
const fetchMock = vi.fn<typeof fetch>();
11+
vi.stubGlobal("fetch", fetchMock);
12+
13+
async function settledCheck() {
14+
const atom = npmReleasePublishedAtom(version);
15+
const registry = AtomRegistry.make();
16+
const unmount = registry.mount(atom);
17+
try {
18+
await vi.waitFor(() => {
19+
const result = registry.get(atom);
20+
expect(AsyncResult.isInitial(result) || result.waiting).toBe(false);
21+
});
22+
return registry.get(atom);
23+
} finally {
24+
unmount();
25+
registry.dispose();
26+
}
27+
}
28+
29+
describe("npmReleasePublishedAtom", () => {
30+
afterEach(() => {
31+
fetchMock.mockReset();
32+
});
33+
34+
afterAll(() => {
35+
vi.unstubAllGlobals();
36+
});
37+
38+
it("checks npm without tracing headers, so the browser skips the preflight npm rejects", async () => {
39+
fetchMock.mockImplementation(async () => Response.json({ version }));
40+
41+
const result = await settledCheck();
42+
43+
expect(fetchMock).toHaveBeenCalledTimes(1);
44+
const request = new Request(fetchMock.mock.calls[0]?.[0] ?? "", fetchMock.mock.calls[0]?.[1]);
45+
expect(request.url).toBe(`https://registry.npmjs.org/t3/${version}`);
46+
expect(request.headers.get("traceparent")).toBeNull();
47+
expect(request.headers.get("b3")).toBeNull();
48+
expect(AsyncResult.getOrElse(result, () => false)).toBe(true);
49+
});
50+
51+
it("reports a version npm does not have as unpublished", async () => {
52+
fetchMock.mockImplementation(async () => new Response(null, { status: 404 }));
53+
54+
const result = await settledCheck();
55+
56+
expect(AsyncResult.isSuccess(result)).toBe(true);
57+
expect(AsyncResult.getOrElse(result, () => true)).toBe(false);
58+
});
59+
60+
it("leaves a failed first check unknown, which callers read as unpublished", async () => {
61+
fetchMock.mockRejectedValue(new TypeError("Failed to fetch"));
62+
63+
const result = await settledCheck();
64+
65+
expect(AsyncResult.isFailure(result)).toBe(true);
66+
expect(AsyncResult.getOrElse(result, () => false)).toBe(false);
67+
});
68+
});

‎apps/web/src/state/npmRelease.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AsyncResult, Atom } from "effect/reactivity";
88
* registry errors stay unknown. Both re-check every few minutes, so a release
99
* that lands later shows up without a reload.
1010
*/
11-
const npmReleasePublishedAtom = Atom.family((version: string) =>
11+
export const npmReleasePublishedAtom = Atom.family((version: string) =>
1212
Atom.make(
1313
Effect.gen(function* () {
1414
const response = yield* HttpClient.get(
@@ -21,7 +21,11 @@ const npmReleasePublishedAtom = Atom.family((version: string) =>
2121
return typeof body === "object" && body !== null && "version" in body
2222
? body.version === version
2323
: false;
24-
}).pipe(Effect.provide(FetchHttpClient.layer)),
24+
}).pipe(
25+
// Tracing headers would make the browser send a CORS preflight, which npm rejects.
26+
Effect.provideService(HttpClient.TracerPropagationEnabled, false),
27+
Effect.provide(FetchHttpClient.layer),
28+
),
2529
).pipe(
2630
Atom.withRefresh("5 minutes"),
2731
Atom.keepAlive,

0 commit comments

Comments
 (0)