@clinebot/core 0.0.35 → 0.0.36
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/README.md +1 -2
- package/dist/ClineCore.d.ts +53 -39
- package/dist/ClineCore.d.ts.map +1 -1
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.d.ts.map +1 -1
- package/dist/account/rpc.d.ts +6 -6
- package/dist/account/rpc.d.ts.map +1 -1
- package/dist/cron/index.d.ts +6 -0
- package/dist/cron/index.d.ts.map +1 -0
- package/dist/cron/resource-limiter.d.ts +9 -0
- package/dist/cron/resource-limiter.d.ts.map +1 -0
- package/dist/cron/schedule-command-service.d.ts +10 -0
- package/dist/cron/schedule-command-service.d.ts.map +1 -0
- package/dist/cron/schedule-service.d.ts +100 -0
- package/dist/cron/schedule-service.d.ts.map +1 -0
- package/dist/cron/scheduler.d.ts +66 -0
- package/dist/cron/scheduler.d.ts.map +1 -0
- package/dist/cron/sqlite-schedule-store.d.ts +52 -0
- package/dist/cron/sqlite-schedule-store.d.ts.map +1 -0
- package/dist/extensions/config/agent-config-loader.d.ts +4 -3
- package/dist/extensions/config/agent-config-loader.d.ts.map +1 -1
- package/dist/extensions/config/runtime-commands.d.ts +1 -0
- package/dist/extensions/config/runtime-commands.d.ts.map +1 -1
- package/dist/extensions/config/user-instruction-config-loader.d.ts +1 -0
- package/dist/extensions/config/user-instruction-config-loader.d.ts.map +1 -1
- package/dist/extensions/context/agentic-compaction.d.ts +2 -2
- package/dist/extensions/context/agentic-compaction.d.ts.map +1 -1
- package/dist/extensions/context/compaction-shared.d.ts +5 -4
- package/dist/extensions/context/compaction-shared.d.ts.map +1 -1
- package/dist/extensions/context/compaction.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-config-loader.d.ts +9 -2
- package/dist/extensions/plugin/plugin-config-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-loader.d.ts +5 -3
- package/dist/extensions/plugin/plugin-loader.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-module-import.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-sandbox.d.ts +15 -2
- package/dist/extensions/plugin/plugin-sandbox.d.ts.map +1 -1
- package/dist/extensions/plugin/plugin-targeting.d.ts +7 -0
- package/dist/extensions/plugin/plugin-targeting.d.ts.map +1 -0
- package/dist/extensions/plugin-sandbox-bootstrap.js +211 -211
- package/dist/extensions/tools/definitions.d.ts +1 -1
- package/dist/extensions/tools/definitions.d.ts.map +1 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts +3 -1
- package/dist/extensions/tools/executors/apply-patch.d.ts.map +1 -1
- package/dist/extensions/tools/executors/search.d.ts +1 -1
- package/dist/extensions/tools/executors/search.d.ts.map +1 -1
- package/dist/extensions/tools/index.d.ts +2 -0
- package/dist/extensions/tools/index.d.ts.map +1 -1
- package/dist/extensions/tools/presets.d.ts +26 -43
- package/dist/extensions/tools/presets.d.ts.map +1 -1
- package/dist/extensions/tools/runtime.d.ts +25 -0
- package/dist/extensions/tools/runtime.d.ts.map +1 -0
- package/dist/extensions/tools/schemas.d.ts.map +1 -1
- package/dist/extensions/tools/team/team-tools.d.ts +1 -0
- package/dist/extensions/tools/team/team-tools.d.ts.map +1 -1
- package/dist/hooks/hook-file-hooks.d.ts +4 -1
- package/dist/hooks/hook-file-hooks.d.ts.map +1 -1
- package/dist/hooks/index.d.ts +0 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/subprocess.d.ts +8 -1
- package/dist/hooks/subprocess.d.ts.map +1 -1
- package/dist/hub/browser-websocket.d.ts +18 -0
- package/dist/hub/browser-websocket.d.ts.map +1 -0
- package/dist/hub/client.d.ts +45 -0
- package/dist/hub/client.d.ts.map +1 -0
- package/dist/hub/connect.d.ts +15 -0
- package/dist/hub/connect.d.ts.map +1 -0
- package/dist/hub/daemon-entry.d.ts +2 -0
- package/dist/hub/daemon-entry.d.ts.map +1 -0
- package/dist/hub/daemon-entry.js +1045 -0
- package/dist/hub/daemon.d.ts +5 -0
- package/dist/hub/daemon.d.ts.map +1 -0
- package/dist/hub/defaults.d.ts +13 -0
- package/dist/hub/defaults.d.ts.map +1 -0
- package/dist/hub/discovery.d.ts +29 -0
- package/dist/hub/discovery.d.ts.map +1 -0
- package/dist/hub/index.d.ts +15 -0
- package/dist/hub/index.d.ts.map +1 -0
- package/dist/hub/index.js +1044 -0
- package/dist/hub/native-transport.d.ts +17 -0
- package/dist/hub/native-transport.d.ts.map +1 -0
- package/dist/hub/runtime-handlers.d.ts +11 -0
- package/dist/hub/runtime-handlers.d.ts.map +1 -0
- package/dist/hub/server.d.ts +86 -0
- package/dist/hub/server.d.ts.map +1 -0
- package/dist/hub/session-client.d.ts +87 -0
- package/dist/hub/session-client.d.ts.map +1 -0
- package/dist/hub/start-shared-server.d.ts +19 -0
- package/dist/hub/start-shared-server.d.ts.map +1 -0
- package/dist/hub/transport.d.ts +8 -0
- package/dist/hub/transport.d.ts.map +1 -0
- package/dist/hub/ui-client.d.ts +44 -0
- package/dist/hub/ui-client.d.ts.map +1 -0
- package/dist/hub/workspace.d.ts +4 -0
- package/dist/hub/workspace.d.ts.map +1 -0
- package/dist/index.d.ts +26 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +498 -476
- package/dist/llms/configured-provider-registry.d.ts +28 -0
- package/dist/llms/configured-provider-registry.d.ts.map +1 -0
- package/dist/llms/provider-defaults.d.ts +27 -0
- package/dist/llms/provider-defaults.d.ts.map +1 -0
- package/dist/llms/provider-settings.d.ts +202 -0
- package/dist/llms/provider-settings.d.ts.map +1 -0
- package/dist/llms/runtime-config.d.ts +4 -0
- package/dist/llms/runtime-config.d.ts.map +1 -0
- package/dist/llms/runtime-registry.d.ts +20 -0
- package/dist/llms/runtime-registry.d.ts.map +1 -0
- package/dist/llms/runtime-types.d.ts +85 -0
- package/dist/llms/runtime-types.d.ts.map +1 -0
- package/dist/runtime/host.d.ts +1 -2
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/rules.d.ts +1 -0
- package/dist/runtime/rules.d.ts.map +1 -1
- package/dist/runtime/runtime-builder.d.ts.map +1 -1
- package/dist/runtime/runtime-host.d.ts +22 -24
- package/dist/runtime/runtime-host.d.ts.map +1 -1
- package/dist/runtime/runtime-oauth-token-manager.d.ts.map +1 -1
- package/dist/runtime/session-runtime.d.ts +1 -19
- package/dist/runtime/session-runtime.d.ts.map +1 -1
- package/dist/services/global-settings.d.ts +12 -0
- package/dist/services/global-settings.d.ts.map +1 -0
- package/dist/services/local-runtime-bootstrap.d.ts +9 -3
- package/dist/services/local-runtime-bootstrap.d.ts.map +1 -1
- package/dist/services/plugin-tools.d.ts +16 -0
- package/dist/services/plugin-tools.d.ts.map +1 -0
- package/dist/services/providers/local-provider-registry.d.ts +4 -4
- package/dist/services/providers/local-provider-registry.d.ts.map +1 -1
- package/dist/services/providers/local-provider-service.d.ts +13 -13
- package/dist/services/providers/local-provider-service.d.ts.map +1 -1
- package/dist/services/session-data.d.ts +1 -1
- package/dist/services/session-data.d.ts.map +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts +1 -1
- package/dist/services/storage/provider-settings-legacy-migration.d.ts.map +1 -1
- package/dist/services/telemetry/index.js +28 -15
- package/dist/services/workspace-manifest.d.ts +11 -0
- package/dist/services/workspace-manifest.d.ts.map +1 -1
- package/dist/session/persistence-service.d.ts +11 -23
- package/dist/session/persistence-service.d.ts.map +1 -1
- package/dist/session/session-manifest-store.d.ts +22 -0
- package/dist/session/session-manifest-store.d.ts.map +1 -0
- package/dist/session/session-row.d.ts +93 -0
- package/dist/session/session-row.d.ts.map +1 -0
- package/dist/session/session-service.d.ts +2 -102
- package/dist/session/session-service.d.ts.map +1 -1
- package/dist/session/subagent-session-manager.d.ts +36 -0
- package/dist/session/subagent-session-manager.d.ts.map +1 -0
- package/dist/session/team-persistence-store.d.ts +24 -0
- package/dist/session/team-persistence-store.d.ts.map +1 -0
- package/dist/transports/hub.d.ts +47 -0
- package/dist/transports/hub.d.ts.map +1 -0
- package/dist/transports/local.d.ts +10 -6
- package/dist/transports/local.d.ts.map +1 -1
- package/dist/transports/remote.d.ts +10 -0
- package/dist/transports/remote.d.ts.map +1 -0
- package/dist/transports/runtime-host-support.d.ts +3 -2
- package/dist/transports/runtime-host-support.d.ts.map +1 -1
- package/dist/types/chat-schema.d.ts +10 -12
- package/dist/types/chat-schema.d.ts.map +1 -1
- package/dist/types/config.d.ts +8 -7
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/provider-settings.d.ts +4 -5
- package/dist/types/provider-settings.d.ts.map +1 -1
- package/dist/types/session.d.ts +2 -1
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types.d.ts +8 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -6
- package/src/ClineCore.ts +68 -40
- package/src/account/index.ts +3 -3
- package/src/account/rpc.ts +12 -12
- package/src/cron/index.ts +5 -0
- package/src/cron/resource-limiter.ts +46 -0
- package/src/cron/schedule-command-service.ts +193 -0
- package/src/cron/schedule-service.ts +703 -0
- package/src/cron/scheduler.ts +637 -0
- package/src/cron/sqlite-schedule-store.ts +708 -0
- package/src/extensions/config/agent-config-loader.ts +17 -7
- package/src/extensions/config/runtime-commands.ts +6 -0
- package/src/extensions/config/user-instruction-config-loader.ts +1 -0
- package/src/extensions/context/agentic-compaction.ts +3 -3
- package/src/extensions/context/basic-compaction.ts +2 -2
- package/src/extensions/context/compaction-shared.ts +5 -4
- package/src/extensions/context/compaction.ts +3 -3
- package/src/extensions/plugin/plugin-config-loader.ts +17 -2
- package/src/extensions/plugin/plugin-loader.ts +48 -4
- package/src/extensions/plugin/plugin-module-import.ts +0 -2
- package/src/extensions/plugin/plugin-sandbox-bootstrap.ts +93 -39
- package/src/extensions/plugin/plugin-sandbox.ts +47 -27
- package/src/extensions/plugin/plugin-targeting.ts +32 -0
- package/src/extensions/tools/definitions.ts +30 -49
- package/src/extensions/tools/executors/apply-patch.ts +69 -80
- package/src/extensions/tools/executors/search.ts +195 -3
- package/src/extensions/tools/index.ts +10 -0
- package/src/extensions/tools/presets.ts +31 -46
- package/src/extensions/tools/runtime.ts +261 -0
- package/src/extensions/tools/schemas.ts +4 -2
- package/src/extensions/tools/team/team-tools.ts +21 -0
- package/src/hooks/hook-file-hooks.ts +8 -2
- package/src/hooks/index.ts +0 -7
- package/src/hooks/subprocess-runner.ts +1 -1
- package/src/hooks/subprocess.ts +9 -0
- package/src/hub/browser-websocket.ts +137 -0
- package/src/hub/client.ts +574 -0
- package/src/hub/connect.ts +156 -0
- package/src/hub/daemon-entry.ts +87 -0
- package/src/hub/daemon.ts +181 -0
- package/src/hub/defaults.ts +43 -0
- package/src/hub/discovery.ts +247 -0
- package/src/hub/index.ts +14 -0
- package/src/hub/native-transport.ts +31 -0
- package/src/hub/runtime-handlers.ts +140 -0
- package/src/hub/server.ts +1888 -0
- package/src/hub/session-client.ts +460 -0
- package/src/hub/start-shared-server.ts +58 -0
- package/src/hub/transport.ts +14 -0
- package/src/hub/ui-client.ts +122 -0
- package/src/hub/workspace.ts +19 -0
- package/src/index.ts +124 -68
- package/src/llms/configured-provider-registry.ts +193 -0
- package/src/llms/provider-defaults.ts +637 -0
- package/src/llms/provider-settings.ts +263 -0
- package/src/llms/runtime-config.ts +43 -0
- package/src/llms/runtime-registry.ts +171 -0
- package/src/llms/runtime-types.ts +121 -0
- package/src/runtime/host.ts +107 -269
- package/src/runtime/index.ts +1 -0
- package/src/runtime/rules.ts +12 -0
- package/src/runtime/runtime-builder.ts +24 -8
- package/src/runtime/runtime-host.ts +89 -61
- package/src/runtime/runtime-oauth-token-manager.ts +11 -15
- package/src/runtime/session-runtime.ts +0 -24
- package/src/services/global-settings.ts +122 -0
- package/src/services/local-runtime-bootstrap.ts +51 -13
- package/src/services/plugin-tools.ts +85 -0
- package/src/services/providers/local-provider-registry.ts +6 -6
- package/src/services/providers/local-provider-service.ts +42 -37
- package/src/services/session-data.ts +15 -9
- package/src/services/storage/provider-settings-legacy-migration.ts +6 -4
- package/src/services/storage/provider-settings-manager.ts +1 -1
- package/src/services/workspace-manifest.ts +18 -0
- package/src/session/file-session-service.ts +1 -1
- package/src/session/index.ts +6 -27
- package/src/session/persistence-service.ts +119 -504
- package/src/session/session-manifest-store.ts +158 -0
- package/src/session/session-row.ts +199 -0
- package/src/session/session-service.ts +17 -376
- package/src/session/session-team-coordination.ts +1 -1
- package/src/session/subagent-session-manager.ts +397 -0
- package/src/session/team-persistence-store.ts +176 -0
- package/src/transports/hub.ts +656 -0
- package/src/transports/local.ts +135 -40
- package/src/transports/remote.ts +26 -0
- package/src/transports/runtime-host-support.ts +63 -9
- package/src/types/chat-schema.ts +4 -5
- package/src/types/config.ts +8 -7
- package/src/types/provider-settings.ts +11 -7
- package/src/types/session.ts +2 -4
- package/src/types.ts +27 -1
- package/dist/hooks/persistent.d.ts +0 -64
- package/dist/hooks/persistent.d.ts.map +0 -1
- package/dist/runtime/rpc-runtime-ensure.d.ts +0 -65
- package/dist/runtime/rpc-runtime-ensure.d.ts.map +0 -1
- package/dist/runtime/rpc-spawn-lease.d.ts +0 -8
- package/dist/runtime/rpc-spawn-lease.d.ts.map +0 -1
- package/dist/session/rpc-session-service.d.ts +0 -16
- package/dist/session/rpc-session-service.d.ts.map +0 -1
- package/dist/session/sqlite-rpc-session-backend.d.ts +0 -31
- package/dist/session/sqlite-rpc-session-backend.d.ts.map +0 -1
- package/dist/transports/rpc.d.ts +0 -51
- package/dist/transports/rpc.d.ts.map +0 -1
- package/src/ClineCore.test.ts +0 -226
- package/src/account/cline-account-service.test.ts +0 -185
- package/src/account/featurebase-token.test.ts +0 -175
- package/src/account/rpc.test.ts +0 -63
- package/src/auth/bounded-ttl-cache.test.ts +0 -38
- package/src/auth/client.test.ts +0 -69
- package/src/auth/cline.test.ts +0 -267
- package/src/auth/codex.test.ts +0 -170
- package/src/auth/oca.test.ts +0 -340
- package/src/auth/server.test.ts +0 -287
- package/src/auth/utils.test.ts +0 -128
- package/src/extensions/config/agent-config-loader.test.ts +0 -236
- package/src/extensions/config/hooks-config-loader.test.ts +0 -20
- package/src/extensions/config/runtime-commands.test.ts +0 -115
- package/src/extensions/config/unified-config-file-watcher.test.ts +0 -196
- package/src/extensions/config/user-instruction-config-loader.test.ts +0 -246
- package/src/extensions/context/compaction.test.ts +0 -483
- package/src/extensions/mcp/config-loader.test.ts +0 -238
- package/src/extensions/mcp/manager.test.ts +0 -105
- package/src/extensions/plugin/plugin-config-loader.test.ts +0 -184
- package/src/extensions/plugin/plugin-loader.test.ts +0 -292
- package/src/extensions/plugin/plugin-sandbox.test.ts +0 -423
- package/src/extensions/tools/definitions.test.ts +0 -780
- package/src/extensions/tools/executors/bash.test.ts +0 -87
- package/src/extensions/tools/executors/editor.test.ts +0 -35
- package/src/extensions/tools/executors/file-read.test.ts +0 -125
- package/src/extensions/tools/model-tool-routing.test.ts +0 -86
- package/src/extensions/tools/presets.test.ts +0 -70
- package/src/extensions/tools/team/multi-agent.lifecycle.test.ts +0 -455
- package/src/extensions/tools/team/spawn-agent-tool.test.ts +0 -381
- package/src/extensions/tools/team/team-tools.test.ts +0 -918
- package/src/hooks/checkpoint-hooks.test.ts +0 -168
- package/src/hooks/hook-file-hooks.test.ts +0 -311
- package/src/hooks/persistent.ts +0 -661
- package/src/runtime/history.test.ts +0 -114
- package/src/runtime/host.test.ts +0 -230
- package/src/runtime/rpc-runtime-ensure.test.ts +0 -123
- package/src/runtime/rpc-runtime-ensure.ts +0 -659
- package/src/runtime/rpc-spawn-lease.test.ts +0 -81
- package/src/runtime/rpc-spawn-lease.ts +0 -156
- package/src/runtime/runtime-builder.team-persistence.test.ts +0 -245
- package/src/runtime/runtime-builder.test.ts +0 -615
- package/src/runtime/runtime-oauth-token-manager.test.ts +0 -137
- package/src/runtime/runtime-parity.test.ts +0 -143
- package/src/services/providers/local-provider-service.test.ts +0 -1062
- package/src/services/session-data.test.ts +0 -160
- package/src/services/storage/provider-settings-legacy-migration.test.ts +0 -424
- package/src/services/storage/provider-settings-manager.test.ts +0 -191
- package/src/services/telemetry/OpenTelemetryAdapter.test.ts +0 -157
- package/src/services/telemetry/OpenTelemetryProvider.test.ts +0 -326
- package/src/services/telemetry/TelemetryLoggerSink.test.ts +0 -42
- package/src/services/telemetry/TelemetryService.test.ts +0 -134
- package/src/services/telemetry/distinct-id.test.ts +0 -57
- package/src/services/workspace/file-indexer.d.ts +0 -11
- package/src/services/workspace/file-indexer.test.ts +0 -156
- package/src/services/workspace/mention-enricher.test.ts +0 -106
- package/src/session/persistence-service.test.ts +0 -300
- package/src/session/rpc-session-service.ts +0 -114
- package/src/session/session-service.team-persistence.test.ts +0 -48
- package/src/session/sqlite-rpc-session-backend.ts +0 -301
- package/src/transports/local.e2e.test.ts +0 -380
- package/src/transports/local.test.ts +0 -2559
- package/src/transports/rpc.test.ts +0 -82
- package/src/transports/rpc.ts +0 -665
package/src/auth/codex.test.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import {
|
|
3
|
-
getValidOpenAICodexCredentials,
|
|
4
|
-
normalizeOpenAICodexCredentials,
|
|
5
|
-
refreshOpenAICodexToken,
|
|
6
|
-
} from "./codex";
|
|
7
|
-
import type { OAuthCredentials } from "./types";
|
|
8
|
-
|
|
9
|
-
function toBase64Url(value: string): string {
|
|
10
|
-
return Buffer.from(value, "utf8").toString("base64url");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createJwt(payload: Record<string, unknown>): string {
|
|
14
|
-
return `${toBase64Url(JSON.stringify({ alg: "none", typ: "JWT" }))}.${toBase64Url(JSON.stringify(payload))}.sig`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function createCredentials(
|
|
18
|
-
overrides: Partial<OAuthCredentials> = {},
|
|
19
|
-
): OAuthCredentials {
|
|
20
|
-
return {
|
|
21
|
-
access: "access-old",
|
|
22
|
-
refresh: "refresh-old",
|
|
23
|
-
expires: 0,
|
|
24
|
-
accountId: "acct-old",
|
|
25
|
-
email: "old@example.com",
|
|
26
|
-
metadata: { provider: "openai-codex" },
|
|
27
|
-
...overrides,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe("auth/codex token lifecycle", () => {
|
|
32
|
-
afterEach(() => {
|
|
33
|
-
vi.unstubAllGlobals();
|
|
34
|
-
vi.restoreAllMocks();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("returns current credentials when not expired", async () => {
|
|
38
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(10_000);
|
|
39
|
-
const current = createCredentials({ expires: 400_000 });
|
|
40
|
-
const fetchMock = vi.fn();
|
|
41
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
42
|
-
|
|
43
|
-
const result = await getValidOpenAICodexCredentials(current);
|
|
44
|
-
expect(result).toBe(current);
|
|
45
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
46
|
-
nowSpy.mockRestore();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("refreshes expired credentials and preserves provider metadata", async () => {
|
|
50
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
51
|
-
const idToken = createJwt({
|
|
52
|
-
"https://api.openai.com/auth": { chatgpt_account_id: "acct-new" },
|
|
53
|
-
email: "new@example.com",
|
|
54
|
-
});
|
|
55
|
-
const accessToken = createJwt({
|
|
56
|
-
"https://api.openai.com/auth": { chatgpt_account_id: "acct-new" },
|
|
57
|
-
});
|
|
58
|
-
vi.stubGlobal(
|
|
59
|
-
"fetch",
|
|
60
|
-
vi.fn(
|
|
61
|
-
async () =>
|
|
62
|
-
new Response(
|
|
63
|
-
JSON.stringify({
|
|
64
|
-
access_token: accessToken,
|
|
65
|
-
refresh_token: "refresh-new",
|
|
66
|
-
expires_in: 3600,
|
|
67
|
-
email: "new@example.com",
|
|
68
|
-
id_token: idToken,
|
|
69
|
-
}),
|
|
70
|
-
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
71
|
-
),
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const current = createCredentials({ expires: 110_000 });
|
|
76
|
-
const result = await getValidOpenAICodexCredentials(current);
|
|
77
|
-
expect(result).toMatchObject({
|
|
78
|
-
access: accessToken,
|
|
79
|
-
refresh: "refresh-new",
|
|
80
|
-
accountId: "acct-new",
|
|
81
|
-
email: "new@example.com",
|
|
82
|
-
metadata: { provider: "openai-codex" },
|
|
83
|
-
});
|
|
84
|
-
nowSpy.mockRestore();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("returns null on invalid_grant refresh errors", async () => {
|
|
88
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
89
|
-
vi.stubGlobal(
|
|
90
|
-
"fetch",
|
|
91
|
-
vi.fn(
|
|
92
|
-
async () =>
|
|
93
|
-
new Response(
|
|
94
|
-
JSON.stringify({
|
|
95
|
-
error: "invalid_grant",
|
|
96
|
-
error_description: "token revoked",
|
|
97
|
-
}),
|
|
98
|
-
{
|
|
99
|
-
status: 400,
|
|
100
|
-
headers: { "Content-Type": "application/json" },
|
|
101
|
-
},
|
|
102
|
-
),
|
|
103
|
-
),
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const result = await getValidOpenAICodexCredentials(
|
|
107
|
-
createCredentials({ expires: 120_000 }),
|
|
108
|
-
);
|
|
109
|
-
expect(result).toBeNull();
|
|
110
|
-
nowSpy.mockRestore();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("keeps current credentials on non-invalid transient refresh failures when still valid", async () => {
|
|
114
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
115
|
-
vi.stubGlobal(
|
|
116
|
-
"fetch",
|
|
117
|
-
vi.fn(
|
|
118
|
-
async () =>
|
|
119
|
-
new Response(
|
|
120
|
-
JSON.stringify({
|
|
121
|
-
error: "server_error",
|
|
122
|
-
error_description: "try again",
|
|
123
|
-
}),
|
|
124
|
-
{
|
|
125
|
-
status: 500,
|
|
126
|
-
headers: { "Content-Type": "application/json" },
|
|
127
|
-
},
|
|
128
|
-
),
|
|
129
|
-
),
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
const current = createCredentials({ expires: 150_000 });
|
|
133
|
-
const result = await getValidOpenAICodexCredentials(current, {
|
|
134
|
-
refreshBufferMs: 60_000,
|
|
135
|
-
retryableTokenGraceMs: 30_000,
|
|
136
|
-
});
|
|
137
|
-
expect(result).toBe(current);
|
|
138
|
-
nowSpy.mockRestore();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("normalizes credentials by deriving accountId from access token", () => {
|
|
142
|
-
const accessToken = createJwt({
|
|
143
|
-
"https://api.openai.com/auth": { chatgpt_account_id: "acct-derived" },
|
|
144
|
-
});
|
|
145
|
-
const normalized = normalizeOpenAICodexCredentials({
|
|
146
|
-
access: accessToken,
|
|
147
|
-
refresh: "refresh",
|
|
148
|
-
expires: 1,
|
|
149
|
-
});
|
|
150
|
-
expect(normalized.accountId).toBe("acct-derived");
|
|
151
|
-
expect(normalized.metadata).toMatchObject({ provider: "openai-codex" });
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("refreshOpenAICodexToken throws when response is structurally invalid", async () => {
|
|
155
|
-
vi.stubGlobal(
|
|
156
|
-
"fetch",
|
|
157
|
-
vi.fn(
|
|
158
|
-
async () =>
|
|
159
|
-
new Response(JSON.stringify({ access_token: "only-access" }), {
|
|
160
|
-
status: 200,
|
|
161
|
-
headers: { "Content-Type": "application/json" },
|
|
162
|
-
}),
|
|
163
|
-
),
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
await expect(refreshOpenAICodexToken("refresh")).rejects.toThrow(
|
|
167
|
-
"Failed to refresh OpenAI Codex token",
|
|
168
|
-
);
|
|
169
|
-
});
|
|
170
|
-
});
|
package/src/auth/oca.test.ts
DELETED
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { getValidOcaCredentials } from "./oca";
|
|
3
|
-
import type { OAuthCredentials } from "./types";
|
|
4
|
-
|
|
5
|
-
function toBase64Url(value: string): string {
|
|
6
|
-
return Buffer.from(value, "utf8").toString("base64url");
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function createJwt(payload: Record<string, unknown>): string {
|
|
10
|
-
return `${toBase64Url(JSON.stringify({ alg: "none", typ: "JWT" }))}.${toBase64Url(JSON.stringify(payload))}.sig`;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function createCredentials(
|
|
14
|
-
overrides: Partial<OAuthCredentials> = {},
|
|
15
|
-
): OAuthCredentials {
|
|
16
|
-
return {
|
|
17
|
-
access: "access-old",
|
|
18
|
-
refresh: "refresh-old",
|
|
19
|
-
expires: 0,
|
|
20
|
-
accountId: "acct-old",
|
|
21
|
-
email: "old@example.com",
|
|
22
|
-
metadata: { provider: "oca", mode: "internal" },
|
|
23
|
-
...overrides,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe("auth/oca getValidOcaCredentials", () => {
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
vi.unstubAllGlobals();
|
|
30
|
-
vi.restoreAllMocks();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("returns current credentials when token is still fresh", async () => {
|
|
34
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(10_000);
|
|
35
|
-
const current = createCredentials({ expires: 400_000 });
|
|
36
|
-
const fetchMock = vi.fn();
|
|
37
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
38
|
-
|
|
39
|
-
const result = await getValidOcaCredentials(current);
|
|
40
|
-
expect(result).toBe(current);
|
|
41
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
42
|
-
nowSpy.mockRestore();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("refreshes an expired token after discovery", async () => {
|
|
46
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
47
|
-
const idToken = createJwt({
|
|
48
|
-
sub: "acct-new",
|
|
49
|
-
email: "new@example.com",
|
|
50
|
-
exp: 2_000_000_000,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const fetchMock = vi
|
|
54
|
-
.fn()
|
|
55
|
-
.mockImplementationOnce(
|
|
56
|
-
async () =>
|
|
57
|
-
new Response(
|
|
58
|
-
JSON.stringify({
|
|
59
|
-
token_endpoint: "https://idcs.example.com/oauth2/v1/token",
|
|
60
|
-
}),
|
|
61
|
-
{
|
|
62
|
-
status: 200,
|
|
63
|
-
headers: { "Content-Type": "application/json" },
|
|
64
|
-
},
|
|
65
|
-
),
|
|
66
|
-
)
|
|
67
|
-
.mockImplementationOnce(
|
|
68
|
-
async () =>
|
|
69
|
-
new Response(
|
|
70
|
-
JSON.stringify({
|
|
71
|
-
access_token: createJwt({
|
|
72
|
-
sub: "acct-new",
|
|
73
|
-
email: "new@example.com",
|
|
74
|
-
exp: 2_000_000_000,
|
|
75
|
-
}),
|
|
76
|
-
refresh_token: "refresh-new",
|
|
77
|
-
id_token: idToken,
|
|
78
|
-
}),
|
|
79
|
-
{ status: 200, headers: { "Content-Type": "application/json" } },
|
|
80
|
-
),
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
84
|
-
|
|
85
|
-
const result = await getValidOcaCredentials(
|
|
86
|
-
createCredentials({ expires: 101_000 }),
|
|
87
|
-
undefined,
|
|
88
|
-
{
|
|
89
|
-
config: {
|
|
90
|
-
internal: {
|
|
91
|
-
clientId: "client-1",
|
|
92
|
-
idcsUrl: "https://idcs.example.com",
|
|
93
|
-
scopes: "openid offline_access",
|
|
94
|
-
baseUrl: "https://oca.example.com",
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
expect(result).toMatchObject({
|
|
101
|
-
access: expect.any(String),
|
|
102
|
-
refresh: "refresh-new",
|
|
103
|
-
accountId: "acct-new",
|
|
104
|
-
email: "new@example.com",
|
|
105
|
-
metadata: {
|
|
106
|
-
provider: "oca",
|
|
107
|
-
mode: "internal",
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
expect(fetchMock).toHaveBeenCalledTimes(2);
|
|
111
|
-
nowSpy.mockRestore();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("returns null when refresh fails with invalid_grant", async () => {
|
|
115
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
116
|
-
const fetchMock = vi
|
|
117
|
-
.fn()
|
|
118
|
-
.mockImplementationOnce(
|
|
119
|
-
async () =>
|
|
120
|
-
new Response(
|
|
121
|
-
JSON.stringify({
|
|
122
|
-
token_endpoint: "https://idcs.invalid/oauth2/v1/token",
|
|
123
|
-
}),
|
|
124
|
-
{
|
|
125
|
-
status: 200,
|
|
126
|
-
headers: { "Content-Type": "application/json" },
|
|
127
|
-
},
|
|
128
|
-
),
|
|
129
|
-
)
|
|
130
|
-
.mockImplementationOnce(
|
|
131
|
-
async () =>
|
|
132
|
-
new Response(
|
|
133
|
-
JSON.stringify({
|
|
134
|
-
error: "invalid_grant",
|
|
135
|
-
error_description: "expired refresh token",
|
|
136
|
-
}),
|
|
137
|
-
{
|
|
138
|
-
status: 400,
|
|
139
|
-
headers: { "Content-Type": "application/json" },
|
|
140
|
-
},
|
|
141
|
-
),
|
|
142
|
-
);
|
|
143
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
144
|
-
|
|
145
|
-
const result = await getValidOcaCredentials(
|
|
146
|
-
createCredentials({ expires: 101_000 }),
|
|
147
|
-
undefined,
|
|
148
|
-
{
|
|
149
|
-
config: {
|
|
150
|
-
internal: {
|
|
151
|
-
clientId: "client-2",
|
|
152
|
-
idcsUrl: "https://idcs.invalid",
|
|
153
|
-
scopes: "openid offline_access",
|
|
154
|
-
baseUrl: "https://oca.example.com",
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
);
|
|
159
|
-
expect(result).toBeNull();
|
|
160
|
-
nowSpy.mockRestore();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("keeps current credentials on transient refresh failures when access token is still usable", async () => {
|
|
164
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
165
|
-
const fetchMock = vi
|
|
166
|
-
.fn()
|
|
167
|
-
.mockImplementationOnce(
|
|
168
|
-
async () =>
|
|
169
|
-
new Response(
|
|
170
|
-
JSON.stringify({
|
|
171
|
-
token_endpoint: "https://idcs.retry/oauth2/v1/token",
|
|
172
|
-
}),
|
|
173
|
-
{
|
|
174
|
-
status: 200,
|
|
175
|
-
headers: { "Content-Type": "application/json" },
|
|
176
|
-
},
|
|
177
|
-
),
|
|
178
|
-
)
|
|
179
|
-
.mockImplementationOnce(
|
|
180
|
-
async () =>
|
|
181
|
-
new Response(
|
|
182
|
-
JSON.stringify({
|
|
183
|
-
error: "server_error",
|
|
184
|
-
error_description: "temporary issue",
|
|
185
|
-
}),
|
|
186
|
-
{
|
|
187
|
-
status: 500,
|
|
188
|
-
headers: { "Content-Type": "application/json" },
|
|
189
|
-
},
|
|
190
|
-
),
|
|
191
|
-
);
|
|
192
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
193
|
-
|
|
194
|
-
const current = createCredentials({ expires: 150_000 });
|
|
195
|
-
const result = await getValidOcaCredentials(
|
|
196
|
-
current,
|
|
197
|
-
{
|
|
198
|
-
refreshBufferMs: 60_000,
|
|
199
|
-
retryableTokenGraceMs: 30_000,
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
config: {
|
|
203
|
-
internal: {
|
|
204
|
-
clientId: "client-3",
|
|
205
|
-
idcsUrl: "https://idcs.retry",
|
|
206
|
-
scopes: "openid offline_access",
|
|
207
|
-
baseUrl: "https://oca.example.com",
|
|
208
|
-
},
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
);
|
|
212
|
-
expect(result).toBe(current);
|
|
213
|
-
nowSpy.mockRestore();
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("re-discovers token endpoint shortly after discovery fallback errors", async () => {
|
|
217
|
-
const nowSpy = vi.spyOn(Date, "now").mockReturnValue(100_000);
|
|
218
|
-
const fetchMock = vi
|
|
219
|
-
.fn()
|
|
220
|
-
// first refresh: discovery fails and fallback endpoint is used
|
|
221
|
-
.mockImplementationOnce(async () => new Response(null, { status: 503 }))
|
|
222
|
-
.mockImplementationOnce(
|
|
223
|
-
async () =>
|
|
224
|
-
new Response(
|
|
225
|
-
JSON.stringify({
|
|
226
|
-
error: "server_error",
|
|
227
|
-
error_description: "temporary issue",
|
|
228
|
-
}),
|
|
229
|
-
{
|
|
230
|
-
status: 500,
|
|
231
|
-
headers: { "Content-Type": "application/json" },
|
|
232
|
-
},
|
|
233
|
-
),
|
|
234
|
-
)
|
|
235
|
-
// second refresh within fallback TTL: discovery should still be cached
|
|
236
|
-
.mockImplementationOnce(
|
|
237
|
-
async () =>
|
|
238
|
-
new Response(
|
|
239
|
-
JSON.stringify({
|
|
240
|
-
error: "server_error",
|
|
241
|
-
error_description: "temporary issue",
|
|
242
|
-
}),
|
|
243
|
-
{
|
|
244
|
-
status: 500,
|
|
245
|
-
headers: { "Content-Type": "application/json" },
|
|
246
|
-
},
|
|
247
|
-
),
|
|
248
|
-
)
|
|
249
|
-
// third refresh after fallback TTL: discovery should be retried
|
|
250
|
-
.mockImplementationOnce(
|
|
251
|
-
async () =>
|
|
252
|
-
new Response(
|
|
253
|
-
JSON.stringify({
|
|
254
|
-
token_endpoint: "https://idcs.fallback/oauth2/v2/token",
|
|
255
|
-
}),
|
|
256
|
-
{
|
|
257
|
-
status: 200,
|
|
258
|
-
headers: { "Content-Type": "application/json" },
|
|
259
|
-
},
|
|
260
|
-
),
|
|
261
|
-
)
|
|
262
|
-
.mockImplementationOnce(
|
|
263
|
-
async () =>
|
|
264
|
-
new Response(
|
|
265
|
-
JSON.stringify({
|
|
266
|
-
error: "server_error",
|
|
267
|
-
error_description: "temporary issue",
|
|
268
|
-
}),
|
|
269
|
-
{
|
|
270
|
-
status: 500,
|
|
271
|
-
headers: { "Content-Type": "application/json" },
|
|
272
|
-
},
|
|
273
|
-
),
|
|
274
|
-
);
|
|
275
|
-
vi.stubGlobal("fetch", fetchMock);
|
|
276
|
-
|
|
277
|
-
const current = createCredentials({ expires: 10_000_000 });
|
|
278
|
-
const providerOptions = {
|
|
279
|
-
config: {
|
|
280
|
-
internal: {
|
|
281
|
-
clientId: "client-fallback-ttl",
|
|
282
|
-
idcsUrl: "https://idcs.fallback",
|
|
283
|
-
scopes: "openid offline_access",
|
|
284
|
-
baseUrl: "https://oca.example.com",
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
const first = await getValidOcaCredentials(
|
|
290
|
-
current,
|
|
291
|
-
{ forceRefresh: true },
|
|
292
|
-
providerOptions,
|
|
293
|
-
);
|
|
294
|
-
expect(first).toBe(current);
|
|
295
|
-
|
|
296
|
-
nowSpy.mockReturnValue(200_000);
|
|
297
|
-
const second = await getValidOcaCredentials(
|
|
298
|
-
current,
|
|
299
|
-
{ forceRefresh: true },
|
|
300
|
-
providerOptions,
|
|
301
|
-
);
|
|
302
|
-
expect(second).toBe(current);
|
|
303
|
-
|
|
304
|
-
nowSpy.mockReturnValue(500_001);
|
|
305
|
-
const third = await getValidOcaCredentials(
|
|
306
|
-
current,
|
|
307
|
-
{ forceRefresh: true },
|
|
308
|
-
providerOptions,
|
|
309
|
-
);
|
|
310
|
-
expect(third).toBe(current);
|
|
311
|
-
|
|
312
|
-
expect(fetchMock).toHaveBeenCalledTimes(5);
|
|
313
|
-
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
314
|
-
1,
|
|
315
|
-
"https://idcs.fallback/.well-known/openid-configuration",
|
|
316
|
-
expect.objectContaining({ method: "GET" }),
|
|
317
|
-
);
|
|
318
|
-
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
319
|
-
2,
|
|
320
|
-
"https://idcs.fallback/oauth2/v1/token",
|
|
321
|
-
expect.objectContaining({ method: "POST" }),
|
|
322
|
-
);
|
|
323
|
-
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
324
|
-
3,
|
|
325
|
-
"https://idcs.fallback/oauth2/v1/token",
|
|
326
|
-
expect.objectContaining({ method: "POST" }),
|
|
327
|
-
);
|
|
328
|
-
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
329
|
-
4,
|
|
330
|
-
"https://idcs.fallback/.well-known/openid-configuration",
|
|
331
|
-
expect.objectContaining({ method: "GET" }),
|
|
332
|
-
);
|
|
333
|
-
expect(fetchMock).toHaveBeenNthCalledWith(
|
|
334
|
-
5,
|
|
335
|
-
"https://idcs.fallback/oauth2/v2/token",
|
|
336
|
-
expect.objectContaining({ method: "POST" }),
|
|
337
|
-
);
|
|
338
|
-
nowSpy.mockRestore();
|
|
339
|
-
});
|
|
340
|
-
});
|