Unified · Split
| @@ -59,7 +59,10 @@ type RuntimeSourceStoreShape = { · 58 unmodified lines | ||
| 59 | 59 | }) => ReturnType<typeof removeSourceByIdWithDeps>; |
| 60 | 60 | persistSource: ( |
| 61 | 61 | source: Source, |
| 62 | − options?: { actorScopeId?: ScopeId | null }, | |
| 62 | + options?: { | |
| 63 | + actorScopeId?: ScopeId | null; | |
| 64 | + lastError?: string | null; | |
| 65 | + }, | |
| 63 | 66 | ) => ReturnType<typeof persistSourceWithDeps>; |
| 64 | 67 | }; |
| 65 | 68 | |
| @@ -136,6 +139,7 @@ export const persistSource = ( · 70 unmodified lines | ||
| 136 | 139 | source: Source, |
| 137 | 140 | options: { |
| 138 | 141 | actorScopeId?: ScopeId | null; |
| 142 | + lastError?: string | null; | |
| 139 | 143 | } = {}, |
| 140 | 144 | ): Effect.Effect< |
| 141 | 145 | Source, |
| @@ -70,6 +70,7 @@ export const persistSourceWithDeps = ( · 69 unmodified lines | ||
| 70 | 70 | source: Source, |
| 71 | 71 | options: { |
| 72 | 72 | actorScopeId?: ScopeId | null; |
| 73 | + lastError?: string | null; | |
| 73 | 74 | } = {}, |
| 74 | 75 | ): Effect.Effect<Source, Error, never> => |
| 75 | 76 | Effect.gen(function* () { |
| @@ -111,7 +112,10 @@ export const persistSourceWithDeps = ( · 35 unmodified lines | ||
| 111 | 112 | ...localScope.scopeState.sources, |
| 112 | 113 | [nextSource.id]: { |
| 113 | 114 | status: nextSource.status, |
| 114 | − lastError: existingSourceState?.lastError ?? null, | |
| 115 | + lastError: | |
| 116 | + options.lastError !== undefined | |
| 117 | + ? options.lastError | |
| 118 | + : existingSourceState?.lastError ?? null, | |
| 115 | 119 | sourceHash: existingSourceState?.sourceHash ?? null, |
| 116 | 120 | createdAt: existingSourceState?.createdAt ?? nextSource.createdAt, |
| 117 | 121 | updatedAt: nextSource.updatedAt, |
| @@ -4,6 +4,7 @@ import { · 3 unmodified lines | ||
| 4 | 4 | import { |
| 5 | 5 | NodeFileSystem, |
| 6 | 6 | } from "@effect/platform-node"; |
| 7 | +import { resolve } from "node:path"; | |
| 7 | 8 | import { |
| 8 | 9 | describe, |
| 9 | 10 | expect, |
| @@ -31,8 +32,11 @@ type BrokenStoredSource = { · 21 unmodified lines | ||
| 31 | 32 | readonly name: string; |
| 32 | 33 | }; |
| 33 | 34 | |
| 34 | −const makeBrokenSourcePlugin = () => { | |
| 35 | +const makeBrokenSourcePlugin = (input: { | |
| 36 | + syncErrorMessage?: string; | |
| 37 | +} = {}) => { | |
| 35 | 38 | const storage = new Map<string, BrokenStoredSource>(); |
| 39 | + const syncErrorMessage = input.syncErrorMessage ?? "sync boom"; | |
| 36 | 40 | |
| 37 | 41 | return defineExecutorSourcePlugin< |
| 38 | 42 | "broken", |
| @@ -98,7 +102,7 @@ const makeBrokenSourcePlugin = () => { · 59 unmodified lines | ||
| 98 | 102 | kind: "imported", |
| 99 | 103 | sync: () => |
| 100 | 104 | Effect.fail( |
| 101 | − runtimeEffectError("sources/operations.test", "sync boom"), | |
| 105 | + runtimeEffectError("sources/operations.test", syncErrorMessage), | |
| 102 | 106 | ), |
| 103 | 107 | invoke: () => |
| 104 | 108 | Effect.fail( |
| @@ -154,4 +158,66 @@ describe("source operations", () => { · 49 unmodified lines | ||
| 154 | 158 | expect(persisted.name).toBe("Broken Source"); |
| 155 | 159 | }).pipe(Effect.provide(NodeFileSystem.layer)), |
| 156 | 160 | ); |
| 161 | + | |
| 162 | + it.scoped("marks credential failures as auth_required and records the last sync error", () => | |
| 163 | + Effect.gen(function* () { | |
| 164 | + const fs = yield* FileSystem.FileSystem; | |
| 165 | + const workspaceRoot = yield* fs.makeTempDirectory({ | |
| 166 | + prefix: "executor-source-ops-auth-", | |
| 167 | + }); | |
| 168 | + | |
| 169 | + const executor = yield* Effect.acquireRelease( | |
| 170 | + createLocalExecutorEffect({ | |
| 171 | + localDataDir: ":memory:", | |
| 172 | + workspaceRoot, | |
| 173 | + plugins: [ | |
| 174 | + makeBrokenSourcePlugin({ | |
| 175 | + syncErrorMessage: | |
| 176 | + "GraphQL introspection requires credentials (status 403)", | |
| 177 | + }), | |
| 178 | + ] as const, | |
| 179 | + }), | |
| 180 | + (executor) => | |
| 181 | + Effect.promise(() => executor.close()).pipe( | |
| 182 | + Effect.orDie, | |
| 183 | + Effect.zipRight( | |
| 184 | + fs.remove(workspaceRoot, { | |
| 185 | + recursive: true, | |
| 186 | + force: true, | |
| 187 | + }), | |
| 188 | + ), | |
| 189 | + ), | |
| 190 | + ); | |
| 191 | + | |
| 192 | + const created = yield* executor.broken.createSource({ | |
| 193 | + name: "Protected Source", | |
| 194 | + }); | |
| 195 | + | |
| 196 | + expect(created.status).toBe("auth_required"); | |
| 197 | + | |
| 198 | + const persisted = yield* executor.broken.getSource(created.id); | |
| 199 | + | |
| 200 | + expect(persisted.status).toBe("auth_required"); | |
| 201 | + expect(persisted.name).toBe("Protected Source"); | |
| 202 | + | |
| 203 | + const inspection = yield* executor.sources.inspection.get(created.id); | |
| 204 | + | |
| 205 | + expect(inspection.source.status).toBe("auth_required"); | |
| 206 | + expect(inspection.toolCount).toBe(0); | |
| 207 | + expect(inspection.tools).toEqual([]); | |
| 208 | + | |
| 209 | + const workspaceState = JSON.parse( | |
| 210 | + yield* fs.readFileString( | |
| 211 | + resolve(workspaceRoot, ".executor", "state", "workspace-state.json"), | |
| 212 | + "utf8", | |
| 213 | + ), | |
| 214 | + ) as { | |
| 215 | + sources?: Record<string, { lastError?: string | null }>; | |
| 216 | + }; | |
| 217 | + | |
| 218 | + expect(workspaceState.sources?.[created.id]?.lastError).toBe( | |
| 219 | + "GraphQL introspection requires credentials (status 403)", | |
| 220 | + ); | |
| 221 | + }).pipe(Effect.provide(NodeFileSystem.layer)), | |
| 222 | + ); | |
| 157 | 223 | }); |
| @@ -36,6 +36,16 @@ const sourceOps = { · 35 unmodified lines | ||
| 36 | 36 | remove: operationErrors("sources.remove"), |
| 37 | 37 | } as const; |
| 38 | 38 | |
| 39 | +const syncFailureDetails = (cause: unknown): string => | |
| 40 | + cause instanceof Error ? cause.message : String(cause); | |
| 41 | + | |
| 42 | +const syncFailureStatus = (cause: unknown): Source["status"] => | |
| 43 | + /(?:status\s*(?:401|403)|unauthorized|forbidden|requires credentials|requires authentication|authentication required|authorization required|missing credential|missing credentials|oauth)/i.test( | |
| 44 | + syncFailureDetails(cause), | |
| 45 | + ) | |
| 46 | + ? "auth_required" | |
| 47 | + : "error"; | |
| 48 | + | |
| 39 | 49 | const syncArtifactsForSource = (input: { |
| 40 | 50 | store: ExecutorStateStoreShape; |
| 41 | 51 | sourceStore: Effect.Effect.Success<typeof RuntimeSourceStoreService>; |
| @@ -58,10 +68,12 @@ const syncArtifactsForSource = (input: { · 16 unmodified lines | ||
| 58 | 68 | onLeft: (error) => |
| 59 | 69 | Effect.gen(function* () { |
| 60 | 70 | if (input.source.enabled && input.source.status === "connected") { |
| 61 | − const erroredSource = yield* normalizeSourceForSave({ | |
| 71 | + const failedStatus = syncFailureStatus(error); | |
| 72 | + const lastError = syncFailureDetails(error); | |
| 73 | + const failedSource = yield* normalizeSourceForSave({ | |
| 62 | 74 | source: { |
| 63 | 75 | ...input.source, |
| 64 | − status: "error", | |
| 76 | + status: failedStatus, | |
| 65 | 77 | }, |
| 66 | 78 | now: Date.now(), |
| 67 | 79 | }).pipe( |
| @@ -75,12 +87,13 @@ const syncArtifactsForSource = (input: { · 7 unmodified lines | ||
| 75 | 87 | |
| 76 | 88 | yield* mapPersistenceError( |
| 77 | 89 | input.operation.child("source_error"), |
| 78 | − input.sourceStore.persistSource(erroredSource, { | |
| 90 | + input.sourceStore.persistSource(failedSource, { | |
| 79 | 91 | actorScopeId: input.actorScopeId, |
| 92 | + lastError, | |
| 80 | 93 | }), |
| 81 | 94 | ); |
| 82 | 95 | |
| 83 | − return erroredSource; | |
| 96 | + return failedSource; | |
| 84 | 97 | } |
| 85 | 98 | |
| 86 | 99 | return yield* input.operation.unknownStorage( |
| @@ -13,6 +13,7 @@ import { · 12 unmodified lines | ||
| 13 | 13 | import { NodeFileSystem } from "@effect/platform-node"; |
| 14 | 14 | import { describe, expect, it } from "@effect/vitest"; |
| 15 | 15 | import { assertTrue } from "@effect/vitest/utils"; |
| 16 | +import * as Data from "effect/Data"; | |
| 16 | 17 | import * as Effect from "effect/Effect"; |
| 17 | 18 | import * as Layer from "effect/Layer"; |
| 18 | 19 | import * as Schema from "effect/Schema"; |
| @@ -65,6 +66,13 @@ import { · 46 unmodified lines | ||
| 65 | 66 | } from "../../../sources/core/src/index"; |
| 66 | 67 | import { createMcpCatalogFragment } from "../../../../plugins/mcp/sdk/catalog"; |
| 67 | 68 | |
| 69 | +class MissingCredentialEnvVarError extends Data.TaggedError( | |
| 70 | + "MissingCredentialEnvVarError", | |
| 71 | +)<{ | |
| 72 | + readonly message: string; | |
| 73 | + readonly tokenEnvVar: string; | |
| 74 | +}> {} | |
| 75 | + | |
| 68 | 76 | const serverHttpPlugins = [ |
| 69 | 77 | graphqlHttpPlugin(), |
| 70 | 78 | googleDiscoveryHttpPlugin(), |
| @@ -493,9 +501,10 @@ const seedGithubOpenApiSourceInWorkspace = (input: { · 422 unmodified lines | ||
| 493 | 501 | const tokenEnvVar = input.credentialEnvVar ?? "GITHUB_TOKEN"; |
| 494 | 502 | const tokenValue = process.env[tokenEnvVar]; |
| 495 | 503 | if (!tokenValue) { |
| 496 | − return yield* Effect.fail( | |
| 497 | − new Error(`Missing token value in environment variable ${tokenEnvVar}`), | |
| 498 | − ); | |
| 504 | + return yield* new MissingCredentialEnvVarError({ | |
| 505 | + message: `Missing token value in environment variable ${tokenEnvVar}`, | |
| 506 | + tokenEnvVar, | |
| 507 | + }); | |
| 499 | 508 | } |
| 500 | 509 | |
| 501 | 510 | const existingSecrets = yield* input.client.local.listSecrets({}); |