Skip to content

Commit 841c34d

Browse files
committed
chore(cleanup): cascade-remove use cases, helpers, and mocks orphaned by deleted Copilot commands
1 parent 2889452 commit 841c34d

44 files changed

Lines changed: 31 additions & 3095 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/sim/app/api/v1/middleware.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const rateLimiter = new RateLimiter()
4040
* `defineV2JsonRoute` and rate-limited through `v2RateLimits`. Add a member only
4141
* when a route actually passes it to `checkRateLimit` / `authenticateRequest`.
4242
*/
43-
export type ApiEndpoint =
43+
type ApiEndpoint =
4444
| 'logs'
4545
| 'logs-detail'
4646
| 'workflows'
@@ -84,7 +84,7 @@ export interface RateLimitResult {
8484
error?: string
8585
}
8686

87-
export interface AuthorizedRequest {
87+
interface AuthorizedRequest {
8888
requestId: string
8989
userId: string
9090
rateLimit: RateLimitResult

‎apps/sim/lib/api/server/routes/internal-request.ts‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

‎apps/sim/lib/api/server/routes/v2-json-route.test.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class TestLockedError extends HttpError {
2525
vi.mock('@/lib/api/server/routes/v2-api-key-auth', () => v2ApiKeyAuthModuleMock)
2626
vi.mock('@/lib/core/rate-limiter', () => v2RateLimiterModuleMock)
2727

28-
import { markInternalRequest } from '@/lib/api/server/routes/internal-request'
2928
import type { V2ApiKeyAuthContext } from '@/lib/api/server/routes/v2-api-key-auth'
3029
import {
3130
admitOptionalV2Request,
@@ -207,21 +206,6 @@ describe('defineV2JsonRoute', () => {
207206
expect(response.headers.get('Cache-Control')).toBe('private, no-store')
208207
})
209208

210-
it('authenticates but never rate-limits a request the server marked as its own', async () => {
211-
// The embedded CLI and the agent-cli engines dispatch to these handlers in-process;
212-
// the IP bucket and the per-key limits exist for callers on the wire, and a chat
213-
// turn's tool calls all land on one key (dev 2026-09-03: grep hit the limit).
214-
const internal = request()
215-
markInternalRequest(internal)
216-
217-
const response = await createHandler()(internal)
218-
219-
expect(response.status).toBe(201)
220-
expect(v2RouteMocks.authenticate).toHaveBeenCalledTimes(1)
221-
expect(v2RouteMocks.preauthRate).not.toHaveBeenCalled()
222-
expect(v2RouteMocks.operationRate).not.toHaveBeenCalled()
223-
})
224-
225209
it('fails closed before authentication when the IP bucket cannot admit the request', async () => {
226210
v2RouteMocks.preauthRate.mockResolvedValueOnce({
227211
allowed: false,

‎apps/sim/lib/api/server/routes/v2-json-route.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
methodMatchesContract,
1010
requireJsonRouteDefinition,
1111
} from '@/lib/api/server/routes/definition'
12-
import { isInternalRequest } from '@/lib/api/server/routes/internal-request'
1312
import type {
1413
JsonApiRouteContract,
1514
JsonNextRouteHandler,
@@ -358,12 +357,7 @@ async function admitAuthenticatedV2Request(
358357
throw error
359358
}
360359

361-
// The server's own requests (embedded CLI, agent-cli engines) are authenticated like
362-
// any other but never rate limited: the buckets exist for callers on the wire, and a
363-
// chat turn's tool calls all land on one key. See `internal-request.ts`.
364-
const limited = isInternalRequest(request)
365-
? null
366-
: await rateLimitPolicy.enforce(request, auth, operation)
360+
const limited = await rateLimitPolicy.enforce(request, auth, operation)
367361
return limited ? { success: false, response: limited } : { success: true, auth }
368362
}
369363

@@ -397,7 +391,7 @@ async function admitRateLimitedV2Request(
397391
setRequestAuth(describePrincipalAuth(principal))
398392
return { success: true, auth: { principal } }
399393
}
400-
const preAuthResponse = isInternalRequest(request) ? null : await enforceV2PreAuthIpLimit(request)
394+
const preAuthResponse = await enforceV2PreAuthIpLimit(request)
401395
if (preAuthResponse) return { success: false, response: preAuthResponse }
402396
return admitAuthenticatedV2Request(request, operation, authPolicy, rateLimitPolicy)
403397
}
@@ -437,7 +431,7 @@ export async function admitOptionalV2Request(
437431
): Promise<{ success: true; auth?: V2AdmissionAuth } | { success: false; response: NextResponse }> {
438432
if (isCopilotRequest(request))
439433
return admitRateLimitedV2Request(request, operation, authPolicy, rateLimitPolicy, useCase)
440-
const preAuthResponse = isInternalRequest(request) ? null : await enforceV2PreAuthIpLimit(request)
434+
const preAuthResponse = await enforceV2PreAuthIpLimit(request)
441435
if (preAuthResponse) return { success: false, response: preAuthResponse }
442436
if (!hasV2Credential(request.headers)) return { success: true }
443437
return admitAuthenticatedV2Request(request, operation, authPolicy, rateLimitPolicy)

‎apps/sim/lib/billing/core/account-billing-snapshot.test.ts‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎apps/sim/lib/billing/core/account-billing-snapshot.ts‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎apps/sim/lib/billing/core/usage.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,15 @@ export async function ensureUserStatsExists(userId: string): Promise<void> {
220220
.onConflictDoNothing({ target: userStats.userId })
221221
}
222222

223-
export interface ResolvedUserUsageData {
223+
interface ResolvedUserUsageData {
224224
usage: UsageData
225225
subscription: HighestPrioritySubscription
226226
/** The personal balance from the same user-stats row used to calculate usage. */
227227
personalCreditBalance: number
228228
}
229229

230230
/** Resolves comprehensive usage and the subscription that determined its billing scope. */
231-
export async function getResolvedUserUsageData(
231+
async function getResolvedUserUsageData(
232232
userId: string,
233233
executor: DbClient = db
234234
): Promise<ResolvedUserUsageData> {

‎apps/sim/lib/core/security/csp.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function getS3EndpointSources(
7272
return [origin, `${url.protocol}//*.${url.host}`]
7373
}
7474

75-
export interface CSPDirectives {
75+
interface CSPDirectives {
7676
'default-src'?: string[]
7777
'script-src'?: string[]
7878
'style-src'?: string[]
@@ -208,7 +208,7 @@ const STATIC_FRAME_SRC = [
208208
] as const
209209

210210
// Build-time CSP directives (for next.config.ts)
211-
export const buildTimeCSPDirectives: CSPDirectives = {
211+
const buildTimeCSPDirectives: CSPDirectives = {
212212
'default-src': ["'self'"],
213213
'script-src': [...STATIC_SCRIPT_SRC],
214214
'style-src': ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'],

‎apps/sim/lib/credential-groups/application/context.ts‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,10 @@
11
import { getWorkspaceOwnerSubscriptionAccess } from '@/lib/billing/core/workspace-access'
22
import { OrchestrationError } from '@/lib/core/orchestration/types'
33
import type { CredentialGroupApplicationContext } from '@/lib/credential-groups/application/authorization'
4-
import {
5-
isCredentialGroupsAvailable,
6-
resolveCredentialGroupsAvailability,
7-
} from '@/lib/credential-groups/availability'
8-
import {
9-
loadCredentialGroupCredentialListContext,
10-
loadWorkspaceAccountsCredentialListContext,
11-
} from '@/lib/credential-groups/credentials'
4+
import { isCredentialGroupsAvailable } from '@/lib/credential-groups/availability'
5+
import { loadCredentialGroupCredentialListContext } from '@/lib/credential-groups/credentials'
126
import { loadActiveWorkspaceApplicationContext } from '@/lib/workspaces/application/workspace-context'
137

14-
export async function requireCredentialGroupsAvailable(workspaceId: string): Promise<void> {
15-
const ownerBilling = await getWorkspaceOwnerSubscriptionAccess(workspaceId)
16-
const availability = await resolveCredentialGroupsAvailability({
17-
organizationId: ownerBilling.organizationId,
18-
ownerBilling,
19-
})
20-
if (!availability.available) {
21-
const message =
22-
availability.reason === 'enterprise_plan_required'
23-
? 'Credential Groups are not available. Enterprise plan required.'
24-
: 'Credential Groups are not available'
25-
throw new OrchestrationError('forbidden', message)
26-
}
27-
}
28-
298
export async function requireCredentialGroupSettingsAvailable(workspaceId: string): Promise<void> {
309
const ownerBilling = await getWorkspaceOwnerSubscriptionAccess(workspaceId)
3110
if (
@@ -52,15 +31,6 @@ export async function resolveCredentialGroupContext(
5231
return { ...(await resolveCredentialGroupWorkspaceContext(group.workspaceId)), ...group }
5332
}
5433

55-
export async function resolveWorkspaceAccountsContext(
56-
workspaceId: string
57-
): Promise<CredentialGroupApplicationContext> {
58-
const workspace = await resolveCredentialGroupWorkspaceContext(workspaceId)
59-
const group = await loadWorkspaceAccountsCredentialListContext(workspaceId)
60-
if (!group) throw new OrchestrationError('not_found', 'Connected accounts are not configured')
61-
return { ...workspace, ...group }
62-
}
63-
6434
export async function resolveCredentialGroupSettingsContext(
6535
credentialGroupId: string,
6636
assertedWorkspaceId: string

‎apps/sim/lib/credential-groups/credentials.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ export async function loadCredentialGroupCredentialListContext(
191191
return loadCredentialGroupContext(eq(credentialGroup.id, credentialGroupId))
192192
}
193193

194-
/** Loads the workspace's single accounts container without decrypting provider settings. */
195-
export async function loadWorkspaceAccountsCredentialListContext(
196-
workspaceId: string
197-
): Promise<CredentialGroupCredentialListContext | null> {
198-
return loadCredentialGroupContext(eq(credentialGroup.workspaceId, workspaceId))
199-
}
200-
201194
async function loadCredentialGroupContext(
202195
scope: SQL
203196
): Promise<CredentialGroupCredentialListContext | null> {

0 commit comments

Comments
 (0)