Skip to content

Commit 1f26f7f

Browse files
icecrasher321claude
andcommitted
refactor: remove four uncalled billing and large-value helpers
Each was checked by hand across every file type, including barrel re-exports and string references, rather than taken from a static analyzer. `isUserMemberOfOrganization` has no reference anywhere. `reapplyPaidOrgJoinBillingForExistingMember` only ever ran from two lock-ordering tests. The transaction-enlisted form it delegated to is what the subscription webhooks call and what those tests actually assert on, so they now drive it directly. The assertions are unchanged: the wrapper contributed a transaction, an organization lock and a membership existence check, none of which appear in the recorded operations. `replaceLargeValueReferences` and `replaceLargeValueReferencesWithClient` are both thin wrappers over `replaceLargeValueReferenceKeysWithClient`, which execution logging, human-in-the-loop resume and the trace backfill all still call. The single test covering a wrapper now composes the key collection itself and targets that live helper. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 91efd36 commit 1f26f7f

4 files changed

Lines changed: 36 additions & 107 deletions

File tree

apps/sim/lib/billing/organizations/lock-order.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ vi.mock('@/lib/billing/storage/payer-transfer', () => ({
3434
}))
3535

3636
import {
37-
reapplyPaidOrgJoinBillingForExistingMember,
37+
reapplyPaidOrgJoinBillingForExistingMemberTx,
3838
restoreUserProSubscription,
3939
transferOrganizationOwnership,
4040
withInvitationSafeOrganizationAccessMutation,
@@ -113,9 +113,8 @@ describe('paid-org join billing lock ordering', () => {
113113

114114
it('locks the personal subscription before mutating userStats', async () => {
115115
const { tx, ops } = createRecordingTx()
116-
dbChainMockFns.transaction.mockImplementation(async (cb: (t: unknown) => unknown) => cb(tx))
117116

118-
await reapplyPaidOrgJoinBillingForExistingMember('user-1', 'org-1')
117+
await reapplyPaidOrgJoinBillingForExistingMemberTx(tx as DbOrTx, 'user-1', 'org-1')
119118

120119
const firstUserStatsUpdate = ops.findIndex((o) => o.op === 'update' && o.table === userStats)
121120
const subscriptionLock = ops.findIndex((o) => o.op === 'lock' && o.table === subscriptionTable)
@@ -127,9 +126,8 @@ describe('paid-org join billing lock ordering', () => {
127126

128127
it('still locks an already-paused personal Pro so a concurrent restore cannot pass it', async () => {
129128
const { tx, ops } = createRecordingTx({ ...GENERIC_ROW, cancelAtPeriodEnd: true })
130-
dbChainMockFns.transaction.mockImplementation(async (cb: (t: unknown) => unknown) => cb(tx))
131129

132-
await reapplyPaidOrgJoinBillingForExistingMember('user-1', 'org-1')
130+
await reapplyPaidOrgJoinBillingForExistingMemberTx(tx as DbOrTx, 'user-1', 'org-1')
133131

134132
expect(ops.some((op) => op.op === 'lock' && op.table === subscriptionTable)).toBe(true)
135133
})

apps/sim/lib/billing/organizations/membership.ts

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -882,34 +882,6 @@ async function applyPaidOrgJoinBillingTx(
882882
return actions
883883
}
884884

885-
/**
886-
* Re-applies paid-org join billing for a user who is already a member of
887-
* the organization. Used on re-upgrade after a dormant transition: members
888-
* kept their org membership but had their personal Pro subscriptions
889-
* restored (`cancelAtPeriodEnd=false`) during the cancel/downgrade. When
890-
* the org becomes paid again, those Pros must be re-paused so the user
891-
* isn't double-billed.
892-
*
893-
* No-op when the org has no active Team/Enterprise subscription.
894-
*/
895-
export async function reapplyPaidOrgJoinBillingForExistingMember(
896-
userId: string,
897-
organizationId: string
898-
): Promise<PaidOrgJoinBillingActions> {
899-
return db.transaction(async (tx) => {
900-
await acquireOrganizationMutationLock(tx, organizationId)
901-
const [existingMembership] = await tx
902-
.select({ id: member.id })
903-
.from(member)
904-
.where(and(eq(member.userId, userId), eq(member.organizationId, organizationId)))
905-
.limit(1)
906-
if (!existingMembership) {
907-
return { proUsageSnapshotted: false, proCancelledAtPeriodEnd: false }
908-
}
909-
return reapplyPaidOrgJoinBillingForExistingMemberTx(tx, userId, organizationId)
910-
})
911-
}
912-
913885
/**
914886
* Transaction-enlisted variant used by subscription webhooks. Keeping the
915887
* subscription upsert, effective-limit update, provisioning completion, and
@@ -2077,23 +2049,6 @@ export async function isSoleOwnerOfPaidOrganization(userId: string): Promise<{
20772049
}
20782050
}
20792051

2080-
export async function isUserMemberOfOrganization(
2081-
userId: string,
2082-
organizationId: string
2083-
): Promise<{ isMember: boolean; role?: string; memberId?: string }> {
2084-
const [memberRecord] = await db
2085-
.select({ id: member.id, role: member.role })
2086-
.from(member)
2087-
.where(and(eq(member.userId, userId), eq(member.organizationId, organizationId)))
2088-
.limit(1)
2089-
2090-
if (memberRecord) {
2091-
return { isMember: true, role: memberRecord.role, memberId: memberRecord.id }
2092-
}
2093-
2094-
return { isMember: false }
2095-
}
2096-
20972052
/**
20982053
* Get user's current organization membership (if any).
20992054
*/

apps/sim/lib/execution/payloads/large-value-metadata.test.ts

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
* @vitest-environment node
33
*/
44

5+
import { db } from '@sim/db'
56
import { executionLargeValueDependencies, executionLargeValueReferences } from '@sim/db/schema'
67
import { dbChainMockFns, resetDbChainMock } from '@sim/testing'
78
import { eq, notInArray } from 'drizzle-orm'
89
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
910
import {
1011
addLargeValueReference,
12+
collectLargeValueReferenceKeys,
1113
MAX_LARGE_VALUE_REFERENCES_PER_SCOPE,
1214
pruneLargeValueMetadata,
1315
registerLargeValueOwner,
14-
replaceLargeValueReferences,
16+
replaceLargeValueReferenceKeysWithClient,
1517
} from '@/lib/execution/payloads/large-value-metadata'
1618

1719
function largeValueKey(id: string, executionId = 'source-execution'): string {
@@ -205,42 +207,44 @@ describe('large value metadata', () => {
205207
const otherWorkspaceKey =
206208
'execution/workspace-2/workflow-1/source-execution/large-value-lv_abcdefghijkl.json'
207209

208-
await replaceLargeValueReferences(
210+
const value = {
211+
a: {
212+
__simLargeValueRef: true,
213+
version: 1,
214+
id: 'lv_abcdefghijkl',
215+
kind: 'json',
216+
size: 123,
217+
key: matchingKey,
218+
},
219+
duplicate: {
220+
__simLargeValueRef: true,
221+
version: 1,
222+
id: 'lv_abcdefghijkl',
223+
kind: 'json',
224+
size: 123,
225+
key: matchingKey,
226+
},
227+
ignored: {
228+
__simLargeValueRef: true,
229+
version: 1,
230+
id: 'lv_abcdefghijkl',
231+
kind: 'json',
232+
size: 123,
233+
key: otherWorkspaceKey,
234+
},
235+
}
236+
237+
await replaceLargeValueReferenceKeysWithClient(
238+
db,
209239
{
210240
workspaceId: 'workspace-1',
211241
workflowId: 'workflow-1',
212242
executionId: 'execution-2',
213243
source: 'execution_log',
214244
},
215-
{
216-
a: {
217-
__simLargeValueRef: true,
218-
version: 1,
219-
id: 'lv_abcdefghijkl',
220-
kind: 'json',
221-
size: 123,
222-
key: matchingKey,
223-
},
224-
duplicate: {
225-
__simLargeValueRef: true,
226-
version: 1,
227-
id: 'lv_abcdefghijkl',
228-
kind: 'json',
229-
size: 123,
230-
key: matchingKey,
231-
},
232-
ignored: {
233-
__simLargeValueRef: true,
234-
version: 1,
235-
id: 'lv_abcdefghijkl',
236-
kind: 'json',
237-
size: 123,
238-
key: otherWorkspaceKey,
239-
},
240-
}
245+
collectLargeValueReferenceKeys(value, 'workspace-1')
241246
)
242247

243-
expect(dbChainMockFns.transaction).toHaveBeenCalledOnce()
244248
expect(dbChainMockFns.delete).toHaveBeenCalledOnce()
245249
expect(eq).toHaveBeenCalledWith(executionLargeValueReferences.source, 'execution_log')
246250
expect(dbChainMockFns.values).toHaveBeenCalledWith([

apps/sim/lib/execution/payloads/large-value-metadata.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,6 @@ export async function registerLargeValueOwner(
227227
return true
228228
}
229229

230-
export async function replaceLargeValueReferencesWithClient(
231-
client: LargeValueMetadataClient,
232-
scope: LargeValueReferenceScope,
233-
value: unknown
234-
): Promise<void> {
235-
if (!scope.workspaceId || !scope.executionId) {
236-
return
237-
}
238-
239-
await replaceLargeValueReferenceKeysWithClient(
240-
client,
241-
scope,
242-
collectLargeValueReferenceKeys(value, scope.workspaceId)
243-
)
244-
}
245-
246230
export async function replaceLargeValueReferenceKeysWithClient(
247231
client: LargeValueMetadataClient,
248232
scope: LargeValueReferenceScope,
@@ -359,18 +343,6 @@ export async function addLargeValueReference(
359343
.onConflictDoNothing()
360344
}
361345

362-
export async function replaceLargeValueReferences(
363-
scope: LargeValueReferenceScope,
364-
value: unknown
365-
): Promise<void> {
366-
const referenceKeys = scope.workspaceId
367-
? collectLargeValueReferenceKeys(value, scope.workspaceId)
368-
: []
369-
await dbFor('exec').transaction(async (tx) => {
370-
await replaceLargeValueReferenceKeysWithClient(tx, scope, referenceKeys)
371-
})
372-
}
373-
374346
export async function markLargeValuesDeleted(
375347
keys: string[],
376348
dbClient: LargeValueMetadataClient = db

0 commit comments

Comments
 (0)