Skip to content

Commit 1b05168

Browse files
hkaltaiclaude
andcommitted
refactor: one local cleanup helper for the upload and attach-only paths
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 956b966 commit 1b05168

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

  • packages/opencode/src/altimate/integrations

‎packages/opencode/src/altimate/integrations/core.ts‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,15 @@ async function syncReal(
11151115
steps.push({ label: l, ok: true })
11161116
onStep?.(l, true)
11171117
}
1118+
// Removes what is left of the credential on this machine once the workspace holds it; a failure is a warning naming the sync that retries it.
1119+
const purgeLocal = async (record: StoredProvider | undefined) => {
1120+
try {
1121+
await purgeCredentialSecrets(id, record, false)
1122+
await deleteSecret(id)
1123+
} catch (e) {
1124+
steps.push({ label: `${LOCAL_CLEANUP_FAILED_PREFIX}${e instanceof Error ? e.message : String(e)}. Run altimate integrations sync ${id} to remove it.`, ok: false })
1125+
}
1126+
}
11181127
const reportWorkspace = (w: NonNullable<UpsertResult["workspace"]>, sharedConnection = false, rewritten = sharedConnection, uploaded = true): SyncOutcome => {
11191128
// A shared connection that was rewritten stays reported as shared even when the attach after it fails.
11201129
if ("error" in w) return { id, result: "failed", reason: (uploaded ? ATTACH_FAILED_PREFIX : ATTACH_EXISTING_FAILED_PREFIX) + w.error + (rewritten ? ` ${SHARED_REWRITE_NOTE}` : ""), steps, ...(sharedConnection ? { shared: true as const } : {}) }
@@ -1146,14 +1155,7 @@ async function syncReal(
11461155
if (found.is_valid === false) return { id, result: "skipped", reason: INVALID_IN_WORKSPACE, steps: [] }
11471156
step("Connection already in the workspace")
11481157
// A synced record keeps no secret here; one left by an earlier cleanup that failed is removed now, which is what that failure told the user to run sync for.
1149-
if (known != null) {
1150-
try {
1151-
await purgeCredentialSecrets(id, store.providers[id], false)
1152-
await deleteSecret(id)
1153-
} catch (e) {
1154-
steps.push({ label: `${LOCAL_CLEANUP_FAILED_PREFIX}${e instanceof Error ? e.message : String(e)}. Run altimate integrations sync ${id} to remove it.`, ok: false })
1155-
}
1156-
}
1158+
if (known != null) await purgeLocal(store.providers[id])
11571159
return reportWorkspace(await attachToBoundWorkspace(cfg, id, found.id, visible.map((c) => c.id), share), found.privacy !== "private", false, false)
11581160
})
11591161
} catch (e) {
@@ -1220,13 +1222,8 @@ async function syncReal(
12201222
return { id, result: "failed", reason: [RECORD_WRITE_FAILED(e instanceof Error ? e.message : String(e), "Run sync again"), ...exposure.notes].join(" "), steps, ...(exposure.shared ? { shared: true as const } : {}) }
12211223
}
12221224
// The connection is in the workspace and accepted: no secret stays on this machine, the same as when it is connected there directly.
1223-
try {
1224-
await purgeCredentialSecrets(id, rec, false)
1225-
await deleteSecret(id)
1226-
} catch (e) {
1227-
// The workspace holds the connection and the record says so; only the local cleanup is left to redo, which running sync for this provider does.
1228-
steps.push({ label: `${LOCAL_CLEANUP_FAILED_PREFIX}${e instanceof Error ? e.message : String(e)}. Run altimate integrations sync ${id} to remove it.`, ok: false })
1229-
}
1225+
// The workspace holds the connection and the record says so; only the local cleanup is left to redo, which running sync for this provider does.
1226+
await purgeLocal(rec)
12301227
return reportWorkspace(res.workspace ?? { notLinked: true }, res.shared === true)
12311228
})
12321229
} catch (e) {

0 commit comments

Comments
 (0)