@jskit-ai/http-web 0.2.20 → 0.2.21
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/http-web",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jskit test"
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"./locales/en.json": "./locales/en.json"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@jskit-ai/resource-crud-core": "0.1.
|
|
50
|
+
"@jskit-ai/resource-crud-core": "0.1.204"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@jskit-ai/http-runtime": "0.2.
|
|
54
|
-
"@jskit-ai/kernel": "0.2.
|
|
55
|
-
"@jskit-ai/realtime": "0.2.
|
|
56
|
-
"@jskit-ai/shell-web": "0.2.
|
|
53
|
+
"@jskit-ai/http-runtime": "0.2.13",
|
|
54
|
+
"@jskit-ai/kernel": "0.2.13",
|
|
55
|
+
"@jskit-ai/realtime": "0.2.19",
|
|
56
|
+
"@jskit-ai/shell-web": "0.2.16",
|
|
57
57
|
"@tanstack/vue-query": "^5.90.5",
|
|
58
58
|
"vue": "^3.5.13",
|
|
59
59
|
"vue-router": "^5.0.4",
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { setImmediate as nextTurn } from "node:timers/promises";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { QueryClient, QueryObserver } from "@tanstack/vue-query";
|
|
5
|
+
import { shouldRetryTransientQueryFailure, transientQueryRetryDelay } from "@jskit-ai/kernel/shared/support";
|
|
6
|
+
|
|
7
|
+
import { configureHttpWebClient } from "../src/client/lib/httpClient.js";
|
|
8
|
+
|
|
9
|
+
// The QueryClient defaults every JSKIT app installs (agent-docs patterns/*-foundation/example/src/main.js).
|
|
10
|
+
function appQueryClient() {
|
|
11
|
+
return new QueryClient({
|
|
12
|
+
defaultOptions: {
|
|
13
|
+
queries: {
|
|
14
|
+
refetchOnWindowFocus: false,
|
|
15
|
+
refetchOnReconnect: true,
|
|
16
|
+
retry: shouldRetryTransientQueryFailure,
|
|
17
|
+
retryDelay: transientQueryRetryDelay
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Observes one read as a screen does and moves the mocked clock until it fails the way shell-web's request recovery
|
|
25
|
+
* reports it (error, no fetch in flight): the moment the recovery banner appears.
|
|
26
|
+
*/
|
|
27
|
+
async function timeToRecoveryBanner(t, queryClient, queryFn) {
|
|
28
|
+
t.mock.timers.enable({ apis: ["setTimeout", "Date"] });
|
|
29
|
+
const startedAt = Date.now();
|
|
30
|
+
const observer = new QueryObserver(queryClient, { queryKey: ["unreachable-read"], queryFn });
|
|
31
|
+
let failed = null;
|
|
32
|
+
const unsubscribe = observer.subscribe((result) => {
|
|
33
|
+
if (result.status === "error" && result.fetchStatus === "idle") failed ??= Date.now() - startedAt;
|
|
34
|
+
});
|
|
35
|
+
try {
|
|
36
|
+
while (failed === null) {
|
|
37
|
+
for (let turn = 0; turn < 4; turn += 1) await nextTurn();
|
|
38
|
+
if (failed !== null) break;
|
|
39
|
+
assert.ok(Date.now() - startedAt < 60_000, "The read never failed");
|
|
40
|
+
t.mock.timers.tick(50);
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
unsubscribe();
|
|
44
|
+
queryClient.clear();
|
|
45
|
+
}
|
|
46
|
+
return failed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
test("one unreachable safe read makes three requests and reaches request recovery in three seconds", async (t) => {
|
|
50
|
+
let requests = 0;
|
|
51
|
+
const client = configureHttpWebClient({
|
|
52
|
+
fetchImpl: async () => {
|
|
53
|
+
requests += 1;
|
|
54
|
+
throw new TypeError("Failed to fetch");
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
t.after(() => configureHttpWebClient());
|
|
58
|
+
|
|
59
|
+
const elapsedMs = await timeToRecoveryBanner(t, appQueryClient(), () => client.request("/api/projects"));
|
|
60
|
+
|
|
61
|
+
// The HTTP client retries the safe read twice, one and two seconds apart; the query does not retry it again.
|
|
62
|
+
const outcome = `${requests} requests, request recovery after ${elapsedMs} ms`;
|
|
63
|
+
assert.equal(requests, 3, outcome);
|
|
64
|
+
assert.ok(elapsedMs >= 3_000 && elapsedMs < 3_100, outcome);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("a query read the HTTP client does not retry keeps the query's own transient retries", async (t) => {
|
|
68
|
+
let requests = 0;
|
|
69
|
+
const client = configureHttpWebClient({
|
|
70
|
+
fetchImpl: async (url) => {
|
|
71
|
+
if (url === "/api/session") {
|
|
72
|
+
return new Response(JSON.stringify({ csrfToken: "csrf" }), { headers: { "content-type": "application/json" } });
|
|
73
|
+
}
|
|
74
|
+
requests += 1;
|
|
75
|
+
return new Response(JSON.stringify({ error: "Temporarily unavailable." }), {
|
|
76
|
+
status: 503,
|
|
77
|
+
headers: { "content-type": "application/json" }
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
t.after(() => configureHttpWebClient());
|
|
82
|
+
|
|
83
|
+
const elapsedMs = await timeToRecoveryBanner(t, appQueryClient(), () =>
|
|
84
|
+
client.request("/api/search", { method: "POST", body: { text: "query" } }));
|
|
85
|
+
|
|
86
|
+
// The client never repeats a POST, so the query's two retries are the only ones. TanStack Query counts failures
|
|
87
|
+
// from zero, so transientQueryRetryDelay gives each of them one second.
|
|
88
|
+
const outcome = `${requests} requests, failed after ${elapsedMs} ms`;
|
|
89
|
+
assert.equal(requests, 3, outcome);
|
|
90
|
+
assert.ok(elapsedMs >= 2_000 && elapsedMs < 2_100, outcome);
|
|
91
|
+
});
|