Skip to content

Commit 351d372

Browse files
committed
test(service-automation): a reconnect landing during the refused listing keeps its grant
Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2c4eada commit 351d372

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎packages/services/service-automation/src/connector-mcp-authorization-door.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,16 @@ function mcpStandIn(lists = false) {
161161
refuse: new Set<string>(),
162162
/** What the next listings answer, in order (then `200`): a `403` is thrown as the real provider throws it. */
163163
listingAnswers: [] as number[],
164+
/** Run before a listing answers (e.g. another replica's reconnect landing meanwhile). */
165+
beforeListingAnswer: undefined as undefined | (() => Promise<void>),
164166
};
165167
const factory: ConnectorProviderFactory = async (ctx) => {
166168
state.materialized.push(ctx);
167169
if (lists) {
168170
const listed = await callWithBorrowedCredential(ctx.credentialHandle!, async (auth) => {
169171
const token = auth.type === 'bearer' ? auth.token : '';
170172
state.listedWith.push(token);
173+
await state.beforeListingAnswer?.();
171174
return { status: state.listingAnswers.shift() ?? 200 };
172175
}, {});
173176
if (listed.status === 403) {
@@ -455,6 +458,21 @@ describe('ADR-0143 D4 — a borrowed token refused at tool discovery is its conn
455458
await expect(dispatch('org_a')).rejects.toMatchObject({ status: 503, message: expect.stringContaining("needs to be reconnected for organization 'org_a'") });
456459
});
457460

461+
it('a reconnect that landed while the refused token was listing keeps its fresh grant; the instance retries', async () => {
462+
const { engine, provider, connect, ql } = await boot([notion()], { lists: true });
463+
provider.state.listingAnswers.push(403);
464+
// Another replica's reconnect: the row is a new connect by the time the refusal is recorded.
465+
provider.state.beforeListingAnswer = async () => {
466+
provider.state.beforeListingAnswer = undefined;
467+
const [row] = await rowsOf(ql);
468+
await ql.update(CONNECTOR_CONNECTION_OBJECT, { id: row.id, connected_at: '2999-01-01T00:00:00.000Z' }, { context: SYSTEM } as never);
469+
};
470+
await (await connect()).done();
471+
expect(provider.state.listedWith).toHaveLength(1);
472+
expect(await connectionOf(engine, ADMIN_A)).toMatchObject({ status: 'connected' });
473+
expect(engine.getConnectorDegradedReason('notion')).toContain("refused the token of organization 'org_a' while it listed its tools (HTTP 403); it retries");
474+
});
475+
458476
it('CONTROL: a client_credentials token the instance mints itself keeps the client secret\'s attribution', async () => {
459477
const { engine, provider } = await boot([notion({
460478
grant: 'client_credentials', clientId: 'notion-app', tokenUrl: `${mcp.base}/auth/token`, credentialRef: SECRET_REF,

0 commit comments

Comments
 (0)