Skip to content

Commit 975e9f3

Browse files
committed
fix tests plus more simplification
1 parent 14e5df8 commit 975e9f3

File tree

6 files changed

+9
-52
lines changed

6 files changed

+9
-52
lines changed

apps/sim/app/api/schedules/execute/route.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
import type { NextRequest } from 'next/server'
77
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
88

9-
// Mock the preflight module before any imports to avoid cascade of db/schema imports
10-
vi.mock('@/lib/workflows/executor/preflight', () => ({
11-
preflightWorkflowEnvVars: vi.fn().mockResolvedValue(undefined),
12-
}))
13-
149
function createMockRequest(): NextRequest {
1510
const mockHeaders = new Map([
1611
['authorization', 'Bearer test-cron-secret'],

apps/sim/app/api/schedules/execute/route.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { db, workflow, workflowSchedule } from '@sim/db'
1+
import { db, workflowSchedule } from '@sim/db'
22
import { createLogger } from '@sim/logger'
33
import { tasks } from '@trigger.dev/sdk'
44
import { and, eq, isNull, lt, lte, not, or } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { verifyCronAuth } from '@/lib/auth/internal'
77
import { isTriggerDevEnabled } from '@/lib/core/config/feature-flags'
88
import { generateRequestId } from '@/lib/core/utils/request'
9-
import { preflightWorkflowEnvVars } from '@/lib/workflows/executor/preflight'
109
import { executeScheduleJob } from '@/background/schedule-execution'
1110

1211
export const dynamic = 'force-dynamic'
@@ -69,37 +68,6 @@ export async function GET(request: NextRequest) {
6968
failedCount: schedule.failedCount || 0,
7069
now: queueTime.toISOString(),
7170
scheduledFor: schedule.nextRunAt?.toISOString(),
72-
preflighted: true,
73-
}
74-
75-
const [workflowRecord] = await db
76-
.select({ userId: workflow.userId, workspaceId: workflow.workspaceId })
77-
.from(workflow)
78-
.where(eq(workflow.id, schedule.workflowId))
79-
.limit(1)
80-
81-
if (!workflowRecord?.userId || !workflowRecord.workspaceId) {
82-
logger.warn(
83-
`[${requestId}] Missing workflow metadata for preflight. Skipping execution.`,
84-
{ workflowId: schedule.workflowId }
85-
)
86-
return null
87-
}
88-
89-
try {
90-
await preflightWorkflowEnvVars({
91-
workflowId: schedule.workflowId,
92-
workspaceId: workflowRecord.workspaceId,
93-
envUserId: workflowRecord.userId,
94-
requestId,
95-
useDraftState: false,
96-
})
97-
} catch (error) {
98-
logger.error(
99-
`[${requestId}] Env preflight failed for workflow ${schedule.workflowId}. Skipping execution.`,
100-
{ error: error instanceof Error ? error.message : String(error) }
101-
)
102-
return null
10371
}
10472

10573
const handle = await tasks.trigger('schedule-execution', payload)

apps/sim/lib/execution/preprocessing.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ export interface PreprocessExecutionOptions {
124124
workspaceId?: string // If known, used for billing resolution
125125
loggingSession?: LoggingSession // If provided, will be used for error logging
126126
isResumeContext?: boolean // If true, allows fallback billing on resolution failure (for paused workflow resumes)
127-
useDraftState?: boolean // If true, use draft workflow state for preflight
127+
/** @deprecated No longer used - preflight always uses deployed state */
128+
useDraftState?: boolean
128129
envUserId?: string // Optional override for env var resolution user
129130
}
130131

@@ -167,7 +168,6 @@ export async function preprocessExecution(
167168
workspaceId: providedWorkspaceId,
168169
loggingSession: providedLoggingSession,
169170
isResumeContext = false,
170-
useDraftState = false,
171171
envUserId,
172172
} = options
173173

@@ -491,7 +491,6 @@ export async function preprocessExecution(
491491
workspaceId,
492492
envUserId: resolvedEnvUserId,
493493
requestId,
494-
useDraftState,
495494
})
496495
} catch (error) {
497496
const message = error instanceof Error ? error.message : 'Env var preflight failed'

apps/sim/lib/workflows/executor/preflight.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import {
44
ensureEnvVarsDecryptable,
55
getPersonalAndWorkspaceEnv,
66
} from '@/lib/environment/utils'
7-
import {
8-
loadDeployedWorkflowState,
9-
loadWorkflowFromNormalizedTables,
10-
} from '@/lib/workflows/persistence/utils'
7+
import { loadDeployedWorkflowState } from '@/lib/workflows/persistence/utils'
118
import { mergeSubblockState } from '@/stores/workflows/server-utils'
129

1310
const logger = createLogger('ExecutionPreflight')
@@ -17,22 +14,20 @@ export interface EnvVarPreflightOptions {
1714
workspaceId: string
1815
envUserId: string
1916
requestId?: string
20-
useDraftState?: boolean
2117
}
2218

2319
/**
2420
* Preflight env var checks to avoid scheduling executions that will fail.
21+
* Always uses deployed workflow state since preflight is only done for async
22+
* executions which always run on deployed state.
2523
*/
2624
export async function preflightWorkflowEnvVars({
2725
workflowId,
2826
workspaceId,
2927
envUserId,
3028
requestId,
31-
useDraftState = false,
3229
}: EnvVarPreflightOptions): Promise<void> {
33-
const workflowData = useDraftState
34-
? await loadWorkflowFromNormalizedTables(workflowId)
35-
: await loadDeployedWorkflowState(workflowId)
30+
const workflowData = await loadDeployedWorkflowState(workflowId)
3631

3732
if (!workflowData) {
3833
throw new Error('Workflow state not found')

apps/sim/socket/middleware/permissions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ describe('checkRolePermission', () => {
208208
{ operation: 'toggle-enabled', adminAllowed: true, writeAllowed: true, readAllowed: false },
209209
{ operation: 'update-parent', adminAllowed: true, writeAllowed: true, readAllowed: false },
210210
{
211-
operation: 'update-advanced-mode',
211+
operation: 'update-canonical-mode',
212212
adminAllowed: true,
213213
writeAllowed: true,
214214
readAllowed: false,

packages/testing/src/factories/permission.factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const BLOCK_OPERATIONS = {
259259
UPDATE_NAME: 'update-name',
260260
TOGGLE_ENABLED: 'toggle-enabled',
261261
UPDATE_PARENT: 'update-parent',
262-
UPDATE_ADVANCED_MODE: 'update-advanced-mode',
262+
UPDATE_CANONICAL_MODE: 'update-canonical-mode',
263263
TOGGLE_HANDLES: 'toggle-handles',
264264
} as const
265265

0 commit comments

Comments
 (0)