The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 14:15 UTC
fix(server): usage hubs with a host-less URL no longer vanish from Limits (#11368)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 14, 2026 at 09:31 UTC
6002c5c68c637de2cd2557bd6c40e46c153e39b1
2 files changed
+88
-2
apps/server/src/usage/UsageLimitSources.test.ts
new
+85
@@ -0,0 +1,85 @@
1
+import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2
+import { expect, it } from "@effect/vitest";
3
+import { ServerConfigStreamEvent, UsageLimitSourceId } from "@t3tools/contracts";
4
+import * as Effect from "effect/Effect";
5
+import * as Layer from "effect/Layer";
6
+import * as Schema from "effect/Schema";
7
+import { HttpClient } from "effect/http";
8
+
9
+import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
10
+import * as ServerSettings from "../serverSettings.ts";
11
+import * as UsageLimitSources from "./UsageLimitSources.ts";
12
+
13
+const encodeConfigEvent = Schema.encodeSync(ServerConfigStreamEvent);
14
+
15
+it.effect("keeps malformed source URLs encodable for config subscribers", () =>
16
+ Effect.gen(function* () {
17
+ const sources = yield* UsageLimitSources.make;
18
+ yield* sources.refresh;
19
+ const snapshots = yield* sources.current;
20
+ expect(snapshots.map((source) => source.label)).toEqual([
21
+ "local-hub",
22
+ "opaque-hub",
23
+ "Named hub",
24
+ "hub.test:8317",
25
+ "Usage limit source",
26
+ ]);
27
+ expect(() =>
28
+ encodeConfigEvent({
29
+ version: 1,
30
+ type: "usageLimitSourcesUpdated",
31
+ payload: { sources: snapshots },
32
+ }),
33
+ ).not.toThrow();
34
+ expect(snapshots.every((source) => source.error === "No management key configured.")).toBe(
35
+ true,
36
+ );
37
+ }).pipe(
38
+ Effect.provide([
39
+ ServerSettings.layerTest({
40
+ usageLimitSources: {
41
+ [UsageLimitSourceId.make("local-hub")]: {
42
+ kind: "cliproxy",
43
+ url: "localhost:8317",
44
+ managementKey: "",
45
+ enabled: true,
46
+ },
47
+ [UsageLimitSourceId.make("opaque-hub")]: {
48
+ kind: "cliproxy",
49
+ url: "file:///tmp/hub",
50
+ managementKey: "",
51
+ enabled: true,
52
+ },
53
+ [UsageLimitSourceId.make("named-hub")]: {
54
+ kind: "cliproxy",
55
+ url: "localhost:8317",
56
+ label: "Named hub",
57
+ managementKey: "",
58
+ enabled: true,
59
+ },
60
+ [UsageLimitSourceId.make("valid-hub")]: {
61
+ kind: "cliproxy",
62
+ url: "https://hub.test:8317",
63
+ managementKey: "",
64
+ enabled: true,
65
+ },
66
+ [UsageLimitSourceId.make(" ")]: {
67
+ kind: "cliproxy",
68
+ url: "localhost:8317",
69
+ managementKey: "",
70
+ enabled: true,
71
+ },
72
+ },
73
+ }),
74
+ Layer.mock(BackgroundPolicy.BackgroundPolicy)({
75
+ shouldRunScopeWork: () => Effect.succeed(false),
76
+ }),
77
+ Layer.succeed(
78
+ HttpClient.HttpClient,
79
+ HttpClient.make(() => Effect.die("Unexpected network request")),
80
+ ),
81
+ NodeCrypto.layer,
82
+ ]),
83
+ Effect.scoped,
84
+ ),
85
+);
apps/server/src/usage/UsageLimitSources.ts
+3
-2
@@ -53,10 +53,11 @@ export class UsageLimitSources extends Context.Service<
53
54
function sourceLabel(id: string, config: UsageLimitSourceConfig): string {
55
if (config.label) return config.label;
56
+ const fallback = id.trim() || "Usage limit source";
57
try {
57
- return new URL(config.url).host;
58
+ return new URL(config.url).host || fallback;
59
} catch {
59
- return id;
60
+ return fallback;
61
}
62
}
63