Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions apps/web/src/trpc/commands/setup-new/index.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions apps/web/src/trpc/commands/setup-new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
buildAutomationRecommendationFingerprint,
enqueueAutomationRecommendationInitialRun,
enqueueAutomationRecommendations,
resolveSetupAutomationReportTarget,
} from '@roomote/sdk/server';
import {
buildRecommendedDeploymentModelConfig,
Expand Down Expand Up @@ -106,6 +107,7 @@ import {
AUTOMATION_RECOMMENDATIONS_CATALOG_VERSION,
AUTOMATION_RECOMMENDATION_CATALOG,
ALL_REPOSITORIES,
isConfiguredAutomationTarget,
} from '@roomote/types';

import type { UserAuthSuccess } from '@/types';
Expand Down Expand Up @@ -2611,6 +2613,9 @@ async function applySetupRecommendationInTx(
const existing = recommendation.automationId
? await getCustomAutomationById(recommendation.automationId, tx)
: null;
const reportTarget = enabled
? await resolveSetupAutomationReportTarget(auth.userId, tx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reportTarget is resolved before the existing-target guard below. That resolver probes chat DMs; the Slack and Teams probes can open/create a direct-message conversation. Re-enabling a recommendation that already has an explicit destination therefore creates unrelated DM channels (and makes external calls while holding the recommendation transaction lock) even though the result is discarded at line 2628. Resolve the fallback only when the existing target is absent or unconfigured.

: null;
const automation = existing
? await updateCustomAutomation(
existing.id,
Expand All @@ -2620,7 +2625,9 @@ async function applySetupRecommendationInTx(
enabled,
scheduleMode: candidate.template.scheduleMode,
environmentId: ALL_REPOSITORIES,
target: {},
target: isConfiguredAutomationTarget(existing.target)
? existing.target
: (reportTarget ?? {}),
},
tx,
)
Expand All @@ -2631,7 +2638,7 @@ async function applySetupRecommendationInTx(
enabled,
scheduleMode: candidate.template.scheduleMode,
environmentId: ALL_REPOSITORIES,
target: {},
target: reportTarget ?? {},
createdByUserId: auth.userId,
},
tx,
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export {
type AutomationRecommendationInitialRunJob,
type AutomationSignalPrefetchJob,
} from './lib/automation-recommendations';
export { resolveSetupAutomationReportTarget } from './lib/setup-automation-delivery';
export {
recordLlmUsage,
type RecordLlmUsageInput,
Expand Down
173 changes: 173 additions & 0 deletions packages/sdk/src/server/lib/setup-automation-delivery.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading