@builder.io/ai-utils 0.75.1 → 0.75.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,6 +11,26 @@ export async function httpCheck(options) {
|
|
|
11
11
|
const method = "HEAD";
|
|
12
12
|
const redirect = isBrowser() ? "follow" : "manual";
|
|
13
13
|
const signal = controller.signal;
|
|
14
|
+
if (isBrowser() && testId === "git-host:http") {
|
|
15
|
+
// Mirror classifyBrowserHttpCheck({ reachabilityOnly: true }) in the Builder app.
|
|
16
|
+
// Third-party git hosts lack CORS; no-cors HEAD is enough to verify the host is reachable.
|
|
17
|
+
await fetchFn(target, { method, mode: "no-cors", signal });
|
|
18
|
+
clearTimeout(timeoutId);
|
|
19
|
+
const durationMs = Date.now() - startTime;
|
|
20
|
+
const hasHighLatency = durationMs > LATENCY_THRESHOLD_MS;
|
|
21
|
+
return {
|
|
22
|
+
source,
|
|
23
|
+
testId,
|
|
24
|
+
target,
|
|
25
|
+
passed: true,
|
|
26
|
+
durationMs,
|
|
27
|
+
errorCode: hasHighLatency ? "latency_high" : undefined,
|
|
28
|
+
metadata: {
|
|
29
|
+
reachabilityOnly: true,
|
|
30
|
+
latencyHigh: hasHighLatency,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
14
34
|
/**
|
|
15
35
|
* The custom fetch fn used in dev tools has proxy handling built-in, so no need
|
|
16
36
|
* for a custom dispatcher.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { httpCheck } from "./http-check.js";
|
|
3
|
+
describe("httpCheck", () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
vi.stubGlobal("window", { document: {} });
|
|
6
|
+
});
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
vi.unstubAllGlobals();
|
|
9
|
+
});
|
|
10
|
+
it("uses no-cors reachability-only for browser git-host:http checks", async () => {
|
|
11
|
+
const fetchFn = vi.fn().mockResolvedValue({ type: "opaque" });
|
|
12
|
+
const result = await httpCheck({
|
|
13
|
+
target: "https://github.com",
|
|
14
|
+
source: "local",
|
|
15
|
+
testId: "git-host:http",
|
|
16
|
+
fetchFn,
|
|
17
|
+
});
|
|
18
|
+
expect(fetchFn).toHaveBeenCalledWith("https://github.com", {
|
|
19
|
+
method: "HEAD",
|
|
20
|
+
mode: "no-cors",
|
|
21
|
+
signal: expect.any(AbortSignal),
|
|
22
|
+
});
|
|
23
|
+
expect(result.passed).toBe(true);
|
|
24
|
+
expect(result.metadata).toMatchObject({ reachabilityOnly: true });
|
|
25
|
+
});
|
|
26
|
+
});
|