Skip to content
Merged
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
51 changes: 51 additions & 0 deletions packages/plugins/openapi/src/sdk/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,57 @@ layer(TestLayer)("OpenAPI Plugin", (it) => {
}),
);

it.effect("addSpec without credentialTargetScope defaults to the source's scope", () =>
// Regression: config-sync calls addSpec without ever setting
// credentialTargetScope. Before the fix, any source with a
// header secret in executor.jsonc errored with
// "credentialTargetScope is required when adding direct OpenAPI
// credentials" the moment the daemon started.
Effect.gen(function* () {
const httpClient = yield* HttpClient.HttpClient;
const clientLayer = Layer.succeed(HttpClient.HttpClient, httpClient);

const executor = yield* createExecutor(
makeTestConfig({
plugins: [
openApiPlugin({ httpClientLayer: clientLayer }),
memorySecretsPlugin(),
] as const,
}),
);

yield* executor.secrets.set(
new SetSecretInput({
id: SecretId.make("config-sync-token"),
scope: ScopeId.make(TEST_SCOPE),
name: "Config-sync token",
value: "secret-from-jsonc",
}),
);

yield* executor.openapi.addSpec({
spec: specJson,
scope: TEST_SCOPE,
namespace: "default_target_scope",
baseUrl: "",
headers: {
Authorization: { secretId: "config-sync-token", prefix: "Bearer " },
},
});

const bindings = yield* executor.openapi.listSourceBindings(
"default_target_scope",
TEST_SCOPE,
);
expect(bindings).toHaveLength(1);
expect(bindings[0]).toMatchObject({
scopeId: ScopeId.make(TEST_SCOPE),
slot: "header:authorization",
value: { kind: "secret", secretId: SecretId.make("config-sync-token") },
});
}),
);

it.effect("fails clearly when a secret is missing", () =>
Effect.gen(function* () {
const httpClient = yield* HttpClient.HttpClient;
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/openapi/src/sdk/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,11 @@ export const openApiPlugin = definePlugin((options?: OpenApiPluginOptions) => {
queryParams: config.queryParams,
specFetchCredentials: config.specFetchCredentials,
oauth2: config.oauth2,
credentialTargetScope: config.credentialTargetScope,
// Default to the source's own scope. refreshSource and editSource
// do the same; without this, config-sync's addSpec — which never
// passes the field — fails with "credentialTargetScope is
// required" the moment the jsonc declares any header secret.
credentialTargetScope: config.credentialTargetScope ?? config.scope,
});
});

Expand Down
Loading