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
48 changes: 24 additions & 24 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@agent-relay/integration-prompts": "^10.6.4",
"@agent-relay/sdk": "^10.6.4",
"@relayfile/relay-helpers": "^0.4.6",
"@relayfile/sdk": "^0.10.32",
"@relayfile/sdk": "0.10.34",
"@relayflows/core": "^1.0.3",
"agent-relay": "^10.6.4",
"proper-lockfile": "^4.1.2",
Expand Down
10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export type {
} from './safety/factory-scope'
export {
canonicalMountPaths,
createResourceSubscriptionsSdkClient,
createWorkspaceScopedEventClient,
deliveryTargetsFor,
eventPathGlobsForIntegration,
Expand All @@ -236,6 +237,8 @@ export {
linearScopePredicates,
normalizeChangePath,
relayfileSdkPathFiltersFor,
ResourceSubscriptionsUnavailableError,
isResourceSubscriptionsUnavailable,
parseSlackThreadReply,
slackThreadReplyGlob,
slackListenDms,
Expand All @@ -262,6 +265,13 @@ export type {
WorkspaceScopedEventClientOptions,
WorkspaceScopedSubscribeOptions,
ChangeEvent as SubscriptionChangeEvent,
AcceptedResourceDelivery,
ResourceDeliveryClaim,
ResourceSubscription,
ResourceSubscriptionInput,
ResourceSubscriptionsClient,
ResourceSubscriptionsSdk,
ResourceSubscriptionsSdkClientOptions,
} from './subscriptions'
export type {
Capability,
Expand Down
164 changes: 163 additions & 1 deletion src/mount/relayfile-cloud-mount-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { describe, expect, it, vi } from 'vitest'
import { CloudAuthError, type CloudSession, type StoredAuth } from '@agent-relay/cloud'
import type { ChangeEvent, OperationStatusResponse } from '@relayfile/sdk'
import type {
AcceptDurableSubscriptionDeliveryInput,
ChangeEvent,
ClaimDurableSubscriptionDeliveriesInput,
CreateOrRenewDurableResourceSubscriptionInput,
OperationStatusResponse,
} from '@relayfile/sdk'
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
Expand Down Expand Up @@ -56,6 +62,14 @@ class FakeRelayFileClient implements RelayFileClientLike {
readonly getEventsCalls: Array<{ workspaceId: string; opts?: { cursor?: string; limit?: number; provider?: string; last?: number } }> = []
readonly listLastNChangesCalls: Array<{ limit: number; context?: { workspaceId: string } }> = []
readonly getOpCalls: Array<{ workspaceId: string; opId: string }> = []
readonly createSubscriptionCalls: CreateOrRenewDurableResourceSubscriptionInput[] = []
readonly claimDeliveryCalls: ClaimDurableSubscriptionDeliveriesInput[] = []
readonly acceptDeliveryCalls: AcceptDurableSubscriptionDeliveryInput[] = []
readonly cancelSubscriptionCalls: Array<{
workspaceId: string
subscriptionId: string
options?: { signal?: AbortSignal }
}> = []
getSyncStatus?: RelayFileClientLike['getSyncStatus']
treePageSize?: number

Expand Down Expand Up @@ -181,6 +195,80 @@ class FakeRelayFileClient implements RelayFileClientLike {
}
}

async createOrRenewDurableResourceSubscription(input: CreateOrRenewDurableResourceSubscriptionInput) {
this.createSubscriptionCalls.push(input)
return {
id: 'sub-1',
ownerId: 'configured-factory-agent',
subscriberId: input.subscriberId,
provider: input.provider,
resourceRef: input.resourceRef,
eventTypes: input.eventTypes,
terminalEventTypes: input.terminalEventTypes ?? [],
intent: input.intent ?? null,
status: 'active' as const,
createdAt: '2026-07-21T00:00:00.000Z',
updatedAt: '2026-07-21T00:00:00.000Z',
expiresAt: '2026-12-31T00:00:00.000Z',
retiredAt: null,
}
}

async claimDurableSubscriptionDeliveries(input: ClaimDurableSubscriptionDeliveriesInput) {
this.claimDeliveryCalls.push(input)
return {
deliveries: [{
id: 'delivery-1',
claimToken: 'claim-token-1',
subscriptionId: 'sub-1',
ownerId: 'configured-factory-agent',
subscriberId: 'factory-babysitter:uuid-1',
provider: 'github',
resourceRef: '/github/repos/AgentWorkforce__pear/pulls/by-id/1.json',
event: {
id: 'event-1',
type: 'pull_request.closed',
path: '/github/repos/AgentWorkforce__pear/pulls/by-id/1.json',
revision: '2',
origin: 'github',
provider: 'github',
correlationId: 'corr-1',
timestamp: '2026-07-21T00:00:00.000Z',
},
terminal: true,
status: 'claimed' as const,
createdAt: '2026-07-21T00:00:00.000Z',
claimedAt: '2026-07-21T00:00:01.000Z',
claimLeaseExpiresAt: '2026-07-21T00:01:01.000Z',
acceptedAt: null,
}],
}
}

async acceptDurableSubscriptionDelivery(input: AcceptDurableSubscriptionDeliveryInput) {
this.acceptDeliveryCalls.push(input)
if (input.claimToken !== 'claim-token-1') {
throw Object.assign(new Error('delivery claim mismatch'), { status: 409 })
}
const claimed = (await this.claimDurableSubscriptionDeliveries({ workspaceId: input.workspaceId })).deliveries[0]!
return {
delivery: {
...claimed,
claimToken: null,
status: 'accepted' as const,
acceptedAt: '2026-07-21T00:00:02.000Z',
},
}
}

async cancelDurableResourceSubscription(
workspaceId: string,
subscriptionId: string,
options?: { signal?: AbortSignal },
) {
this.cancelSubscriptionCalls.push({ workspaceId, subscriptionId, options })
}

async getToken() {
return 'relayfile-token'
}
Expand Down Expand Up @@ -680,6 +768,80 @@ describe('RelayfileCloudMountClient', () => {
expect(cloudSessionProvider).toHaveBeenCalledTimes(2)
})

it('adapts durable resource subscriptions through the canonical Relayfile SDK methods', async () => {
const fake = new FakeRelayFileClient()
const mount = new RelayfileCloudMountClient({ workspaceId: 'rw_test', client: fake })

const client = mount.resourceSubscriptions!
await expect(client.createOrRenew('rw_test', {
provider: 'github',
resourceRef: '/github/repos/AgentWorkforce__pear/pulls/by-id/1.json',
eventTypes: ['pull_request_review_comment.created'],
terminalEventTypes: ['pull_request.closed'],
subscriberId: 'factory-babysitter:uuid-1',
ttlSeconds: 3600,
})).resolves.toMatchObject({ subscriptionId: 'sub-1', ownerId: 'configured-factory-agent' })
await expect(client.claimDeliveryClaims('rw_test')).resolves.toEqual([expect.objectContaining({
deliveryId: 'delivery-1',
claimToken: 'claim-token-1',
terminal: true,
})])
await expect(client.acceptDelivery('rw_test', { deliveryId: 'delivery-1', claimToken: 'wrong-token' }))
.rejects.toMatchObject({ status: 409 })
await expect(client.acceptDelivery('rw_test', { deliveryId: 'delivery-1', claimToken: 'claim-token-1' }))
.resolves.toEqual({ deliveryId: 'delivery-1', subscriptionId: 'sub-1', terminal: true })
await client.cancel('rw_test', { subscriptionId: 'sub-1' })

expect(fake.createSubscriptionCalls).toEqual([expect.objectContaining({
workspaceId: 'rw_test',
provider: 'github',
resourceRef: '/github/repos/AgentWorkforce__pear/pulls/by-id/1.json',
eventTypes: ['pull_request_review_comment.created'],
terminalEventTypes: ['pull_request.closed'],
subscriberId: 'factory-babysitter:uuid-1',
ttlSeconds: 3600,
})])
expect(fake.claimDeliveryCalls[0]).toMatchObject({ workspaceId: 'rw_test' })
expect(fake.acceptDeliveryCalls).toEqual([
expect.objectContaining({ workspaceId: 'rw_test', deliveryId: 'delivery-1', claimToken: 'wrong-token' }),
expect.objectContaining({ workspaceId: 'rw_test', deliveryId: 'delivery-1', claimToken: 'claim-token-1' }),
])
expect(fake.cancelSubscriptionCalls).toEqual([
expect.objectContaining({ workspaceId: 'rw_test', subscriptionId: 'sub-1' }),
])
})

it('fails closed for non-claimed SDK deliveries and forwards lifecycle cancellation', async () => {
const fake = new FakeRelayFileClient()
fake.claimDurableSubscriptionDeliveries = vi.fn(async (input) => ({
deliveries: [{
...(await new FakeRelayFileClient().claimDurableSubscriptionDeliveries(input)).deliveries[0]!,
claimToken: null,
status: 'pending' as const,
}],
}))
const malformed = new RelayfileCloudMountClient({
workspaceId: 'rw_test',
client: fake,
})
await expect(malformed.resourceSubscriptions!.claimDeliveryClaims('rw_test'))
.rejects.toThrow(/without a live claim/u)

const controller = new AbortController()
const cancelledSdk = new FakeRelayFileClient()
const claim = vi.spyOn(cancelledSdk, 'claimDurableSubscriptionDeliveries')
const cancelled = new RelayfileCloudMountClient({
workspaceId: 'rw_test',
client: cancelledSdk,
resourceSubscriptionSignal: controller.signal,
})
await cancelled.resourceSubscriptions!.claimDeliveryClaims('rw_test')
expect(claim).toHaveBeenCalledWith(expect.objectContaining({
workspaceId: 'rw_test',
signal: controller.signal,
}))
})

it('coalesces concurrent shared session resolutions for relayfile token refresh', async () => {
const setup = {
joinWorkspace: vi.fn(async () => ({
Expand Down
Loading