Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4b3d1a8
Keep opened GitHub work items bound to their exact repository
brennanb2025 Oct 29, 2026
4d11b1f
Bind GitHub work item ownership through consumers and dispatch
brennanb2025 Oct 30, 2026
099e5d0
Keep empty mention lists from consuming selection keys
brennanb2025 Oct 30, 2026
81c83f4
Preserve GitHub action and consumer ownership across resource changes
brennanb2025 Oct 30, 2026
b212ba0
Exercise repository account updates through their production store ac…
brennanb2025 Oct 30, 2026
d9cf450
Exercise account publication and cache settlement through GitHub cons…
brennanb2025 Oct 30, 2026
15ff00a
Simplify fork PR contract verification
brennanb2025 Oct 31, 2026
d9680e4
Merge origin/main into fork PR identity branch
brennanb2025 Oct 31, 2026
b37b7b4
Make contract verification imports and clocks deterministic
brennanb2025 Oct 31, 2026
15793f6
Correct mobile task test fixtures and model types
brennanb2025 Oct 31, 2026
50d0203
Correct task recording fixtures and CI types
brennanb2025 Oct 31, 2026
94f0171
Correct task fixture types and static checks
brennanb2025 Oct 31, 2026
937641b
Consolidate replay test RPC imports
brennanb2025 Oct 31, 2026
f3dd6f6
Separate GitHub metadata imports from Linear hooks
brennanb2025 Oct 31, 2026
3d49c84
Scope mobile PR sidebar reads to the selected resource
brennanb2025 Oct 31, 2026
f2bee63
Separate desktop GitHub changes from phone updates
brennanb2025 Oct 31, 2026
0c73076
Fix relay authority probe census across topology cases
brennanb2025 Oct 31, 2026
ec3e5db
Repair repository owner proof fixtures and compiler allocation
brennanb2025 Oct 31, 2026
a311f1a
Preserve repository row observation in host lookup
brennanb2025 Oct 31, 2026
b390ab5
Seed metadata fixture before server-side store acquisition
brennanb2025 Oct 31, 2026
4d1cd3a
Preserve nullable fixture settings and discover mixed test types
brennanb2025 Oct 31, 2026
baa9887
Merge main into repository identity branch
brennanb2025 Oct 31, 2026
bac5082
Merge main into repository identity branch
brennanb2025 Oct 31, 2026
43ade10
Merge main into repository identity branch
brennanb2025 Nov 2, 2026
57871fe
Merge main into repository identity branch
brennanb2025 Nov 2, 2026
ce1f2cb
Merge main and preserve GitHub detail read intent
brennanb2025 Nov 2, 2026
b0d8d3d
Preserve GitHub detail argument types and optional capabilities
brennanb2025 Nov 2, 2026
fa44a08
Let keyed details queries own pending read replacement
brennanb2025 Nov 2, 2026
e5eada9
Repair GitHub RPC and relay test fixture boundaries
brennanb2025 Nov 2, 2026
c3c3e33
Verify expected GitHub account at repository execution capture
brennanb2025 Nov 2, 2026
12cf608
Preserve captured GitHub account expectations through client dispatch
brennanb2025 Nov 2, 2026
dff18b9
Retain observed runtime status after switching environments
brennanb2025 Nov 2, 2026
7c570f1
Merge main into fork pull request identity repair
brennanb2025 Nov 2, 2026
8991ba1
Fix account contract fixture types and RPC setup timing
brennanb2025 Nov 2, 2026
f17e9cc
Restore the negative-capability switch probe assertion
brennanb2025 Nov 2, 2026
b12b03a
Align account fixtures with runtime identity and configured origin
brennanb2025 Nov 2, 2026
89c7b8f
Consolidate details test imports
brennanb2025 Nov 2, 2026
8310b1d
Drop duplicate fork pull request identity tests
brennanb2025 Nov 2, 2026
d388639
Merge main into fork pull request identity repair
brennanb2025 Nov 2, 2026
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
149 changes: 149 additions & 0 deletions mobile/src/mobile-web-shell/bridge-host-github-requests.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import { afterEach, expect, it, vi } from 'vitest'
import { BridgeHostRequests } from './bridge-host-requests'
import { bridgeId, createFakeRpcClient, rpcSuccess } from './bridge-host-test-fakes'
import { BRIDGE_MAX_PENDING_REQUESTS } from './bridge/bridge-caps'
import { GITHUB_EXACT_WORK_ITEM_TARGET_RUNTIME_CAPABILITY as capability } from '../../../src/shared/source-control-runtime-capabilities'
import { classifyExactGitHubOperation } from '../../../src/shared/github/exact-work-item-operation'
import { createPageClient, INIT, GRANTS } from './bridge/bridge-page-client-test-harness'

const params = { repo: 'id:clone', ownerRepo: { owner: 'fork', repo: 'widgets' } }
const envelope = {
executionHost: 'runtime:server',
expectedRuntimeSource: { sourceId: 'server', runtimeId: 's' }
}
const status = { runtimeId: 'desktop', capabilities: [capability] }
const frame = (id = bridgeId(1)) => ({
v: 1 as const,
type: 'request' as const,
id,
method: 'github.listLabels',
params,
envelope
})
const flush = async () => {
for (let i = 0; i < 6; i++) {
await Promise.resolve()
}
}
afterEach(() => vi.useRealTimers())
function hostRequests() {
const client = createFakeRpcClient()
const reply = vi.fn(),
error = vi.fn()
const requests = new BridgeHostRequests({
client,
isIdTaken: () => false,
sendReply: reply,
sendError: error,
capExceeded: (message) => new Error(message),
serveNative: async () => rpcSuccess('native', null),
readClientIdentity: () => 'phone'
})
return { client, requests, reply, error }
}
it('uses one unscoped first-hop probe, leaves final S distinct from D, and preserves unrelated optional calls', async () => {
const f = hostRequests()
f.requests.open(frame())
expect(f.client.requests[0].args).toMatchObject([
'status.get',
undefined,
{ beforeSend: expect.any(Function) }
])
expect(f.client.requests[0].args[2]).not.toHaveProperty('envelope')
f.client.requests[0].resolve(rpcSuccess('probe', status))
await flush()
expect(f.client.requests[1].args).toMatchObject(['github.listLabels', params, { envelope }])
f.client.requests[1].resolve(rpcSuccess('list', ['one']))
await flush()
expect(f.reply).toHaveBeenCalledWith(bridgeId(1), expect.objectContaining({ result: ['one'] }))
expect(f.client.stateListeners()).toBe(0)
for (const [index, fields] of [{}, { params }, { envelope }].entries()) {
f.requests.open({
v: 1,
type: 'request',
id: bridgeId(index + 2),
method: 'github.listLabels',
...fields
})
}
expect(f.client.requests.slice(2).map((request) => request.args)).toEqual([
['github.listLabels'],
['github.listLabels', params],
['github.listLabels', undefined, { envelope }]
])
f.requests.closeAll(false)
})
it('rejects malformed opt-in rather than silently forwarding as legacy', () => {
expect(() =>
classifyExactGitHubOperation('github.updateIssue', { ...params, ownerRepo: null }, envelope)
).toThrow()
const f = hostRequests()
f.requests.open({ ...frame(), params: { ...params, ownerRepo: { owner: '', repo: 'widgets' } } })
expect(f.client.requests).toEqual([])
expect(f.error).toHaveBeenCalledOnce()
expect(classifyExactGitHubOperation('github.listLabels', params, {})).toBeNull()
})
it('cancelled probes retain inFlight occupancy, release listeners immediately and cannot settle a reused id', async () => {
const f = hostRequests()
for (let i = 1; i <= BRIDGE_MAX_PENDING_REQUESTS; i++) {
f.requests.open(frame(bridgeId(i)))
f.requests.cancel(bridgeId(i))
}
expect(f.client.stateListeners()).toBe(0)
f.requests.open(frame(bridgeId(1)))
expect(f.error).toHaveBeenCalledWith(
bridgeId(1),
expect.objectContaining({ message: expect.stringContaining('over') })
)
const probes = [...f.client.requests]
for (const request of probes) {
request.resolve(rpcSuccess('probe', status))
}
await flush()
expect(f.client.requests).toHaveLength(BRIDGE_MAX_PENDING_REQUESTS)
expect(f.reply).not.toHaveBeenCalled()
f.requests.open(frame())
f.requests.open(frame()) // collision must not retire the original
expect(f.client.stateListeners()).toBe(1)
f.client.requests.at(-1)!.resolve(rpcSuccess('new-probe', status))
await flush()
expect(f.client.requests.at(-1)?.method).toBe('github.listLabels')
f.client.requests.at(-1)!.resolve(rpcSuccess('new-list', []))
await flush()
expect(f.reply).toHaveBeenCalledOnce()
expect(f.client.stateListeners()).toBe(0)
})
it('does not reset an explicitly spanning deadline during preparation', async () => {
vi.useFakeTimers()
const f = hostRequests()
f.requests.open({ ...frame(), options: { timeoutMs: 100, budgetSpansConnect: true } })
await vi.advanceTimersByTimeAsync(101)
f.client.requests[0].resolve(rpcSuccess('probe', status))
await flush()
expect(f.client.requests).toHaveLength(1)
expect(f.error).toHaveBeenCalledWith(
bridgeId(1),
expect.objectContaining({ message: expect.stringContaining('Timed out') })
)
expect(f.client.stateListeners()).toBe(0)
})
it('keeps a page callback local, preserves callback-only arity, and allocates no pending id when it throws', async () => {
const page = createPageClient()
page.deliver({ ...INIT, grants: { ...GRANTS, native: ['rpcEnvelope'] } })
const beforeSend = vi.fn(() => {
throw new Error('retired')
})
await expect(
page.client.sendRequest('github.listLabels', undefined, { beforeSend })
).rejects.toThrow('retired')
expect(page.frames().filter((message) => message.type === 'request')).toHaveLength(0)
const pending = page.client.sendRequest('status.get', undefined, { beforeSend: () => {} })
const request = page.frames().find((message) => message.type === 'request')
expect(request).not.toHaveProperty('options')
if (!request || !('id' in request)) {
throw new Error('missing request')
}
page.deliver({ v: 1, type: 'reply', id: request.id, payload: rpcSuccess('status', {}) })
await pending
page.client.close()
})
60 changes: 57 additions & 3 deletions mobile/src/mobile-web-shell/bridge-host-requests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import { classifyExactGitHubOperation } from '../../../src/shared/github/exact-work-item-operation'
import {
captureGitHubInvocation,
requireExactGitHubOperations,
githubOperationResponse
} from '../transport/github-target-invocation'
import { openRpcRequestBudget } from '../transport/rpc-request-budget'
import type { RpcClient } from '../transport/rpc-client'
import { markRpcDeliveryUnknown } from '../transport/rpc-delivery-ambiguity'
import type { RpcResponse } from '../transport/types'
Expand All @@ -10,7 +17,7 @@ import { substituteBridgePageClientIdentity } from './bridge/bridge-page-client-
type RequestMessage = Extract<BridgeClientMessage, { type: 'request' }>

// Suppress cancelled requests’ late replies so an id the page abandoned cannot receive an old answer.
type PendingRequest = { live: boolean }
type PendingRequest = { live: boolean; retire?: () => void }

export type BridgeHostRequestDeps = {
client: RpcClient
Expand Down Expand Up @@ -46,12 +53,13 @@ export class BridgeHostRequests {
return false
}
record.live = false
record.retire?.()
this.pending.delete(id)
return true
}

// Replay the exact argument arity for the golden recorder. Fence native requests here; native subscriptions are fenced separately in handleSubscribe.
private forward(message: RequestMessage): Promise<RpcResponse> {
private forward(message: RequestMessage, record: PendingRequest): Promise<RpcResponse> {
const { client } = this.deps
if (isBridgeNativeMethod(message.method)) {
return this.deps.serveNative(message.id, message.method, message.params)
Expand All @@ -65,6 +73,10 @@ export class BridgeHostRequests {
message.envelope === undefined
? message.options
: { ...message.options, envelope: message.envelope }
const bound = classifyExactGitHubOperation(message.method, params, message.envelope)
if (bound) {
return this.forwardExact(message, params, record)
}
if (options !== undefined) {
return client.sendRequest(message.method, params, options)
}
Expand All @@ -73,6 +85,47 @@ export class BridgeHostRequests {
: client.sendRequest(message.method)
}

private async forwardExact(
message: RequestMessage,
params: unknown,
record: PendingRequest
): Promise<RpcResponse> {
const { client } = this.deps
const invocation = captureGitHubInvocation(
client,
() => record.live && this.pending.get(message.id) === record
)
record.retire = invocation.retire
const options = { timeoutMs: 30_000, ...message.options }
const budget = openRpcRequestBudget(options)
const remaining = () => {
if (budget.deadline === null) {
return options.timeoutMs
}
const ms = budget.deadline - Date.now()
if (ms <= 0) {
throw new Error('Timed out confirming the executing Orca server.')
}
return ms
}
try {
// This is the native first hop, not the final executionHost named by the operation.
const status = await invocation.status({ ...options, timeoutMs: remaining() })
requireExactGitHubOperations(status)
invocation.assertCurrent()
return githubOperationResponse(
await client.sendRequest(message.method, params, {
...options,
timeoutMs: remaining(),
envelope: message.envelope,
beforeSend: invocation.assertCurrent
})
)
} finally {
invocation.retire()
}
}

open(message: RequestMessage): void {
const { id } = message
// Refuse a colliding newcomer without settling the existing request under that id.
Expand All @@ -88,7 +141,7 @@ export class BridgeHostRequests {
this.pending.set(id, record)
let answer: Promise<RpcResponse>
try {
answer = this.forward(message)
answer = this.forward(message, record)
} catch (error) {
this.settle(id, record)
this.deps.sendError(id, error)
Expand All @@ -114,6 +167,7 @@ export class BridgeHostRequests {
closeAll(notify: boolean): void {
for (const [id, record] of this.pending) {
record.live = false
record.retire?.()
// Use delivery-unknown because desktop execution may have happened; definite failure would invite unsafe retry.
if (notify) {
this.deps.sendError(id, markRpcDeliveryUnknown(new BridgeHostDisposedError()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ export function readBridgeRpcEnvelope(
export function readBridgeRequestFrameOptions(
requestOptions: SendRequestOptions | undefined,
hasGrant: HasGrant
): { options?: Omit<SendRequestOptions, 'envelope'>; envelope?: RpcEnvelopeFields } {
): { options?: Omit<SendRequestOptions, 'envelope' | 'beforeSend'>; envelope?: RpcEnvelopeFields } {
if (requestOptions === undefined) {
return {}
}
const { envelope: fields, ...options } = requestOptions
const { envelope: fields, beforeSend: _beforeSend, ...options } = requestOptions
const envelope = readBridgeRpcEnvelope(fields, hasGrant)
return {
...(fields !== undefined && Object.keys(options).length === 0 ? {} : { options }),
...(Object.keys(options).length === 0 && (fields !== undefined || _beforeSend !== undefined)
? {}
: { options }),
...(envelope === undefined ? {} : { envelope })
}
}
1 change: 1 addition & 0 deletions mobile/src/mobile-web-shell/bridge/bridge-rpc-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export function createBridgeRpcClient(options: BridgeRpcClientOptions): BridgeRp
}
const [method, params, requestOptions] = args
return new Promise<RpcResponse>((resolve, reject) => {
requestOptions?.beforeSend?.()
const frameOptions = readBridgeRequestFrameOptions(requestOptions, hasGrant)
const id = nextId()
requests.open(id, { resolve, reject })
Expand Down
2 changes: 2 additions & 0 deletions mobile/src/session/github-pr-read-reply-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ const workItemSchema = z
.looseObject({
id: prText('id'),
number: prCount('number'),
prRepo: prRepoIdentity('prRepo'),
type: salvagedOptional('type', z.enum(['issue', 'pr'] as const)),
state: salvagedOptional('state', z.enum(PR_STATE)),
title: prText('title'),
Expand Down Expand Up @@ -228,6 +229,7 @@ const workItemSchema = z
: {
id: item.id,
type: item.type,
prRepo: item.prRepo,
number: item.number,
title: item.title ?? '',
state: item.state,
Expand Down
50 changes: 39 additions & 11 deletions mobile/src/session/github-pr-rpc.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { RpcClient } from '../transport/rpc-client'
import { withGitHubTargetOperation } from '../tasks/github-work-item-operation'
import { requireGitHubWorkItemTargetDetails } from '../../../src/shared/github/work-item-target'
import type { PRCheckDetail, PRCheckRunDetails } from '../../../src/shared/github/check-types'
import type { GitHubAssignableUser, PRInfo } from '../../../src/shared/github/pull-request-types'
import type { GitHubWorkItemDetails } from '../../../src/shared/github/work-item-types'
Expand Down Expand Up @@ -126,20 +129,45 @@ function resolveGithubPrForBranchOutcome(outcome: GitHubPrForBranchOutcome | nul
return outcome.kind === 'found' ? outcome.pr : null
}

export function fetchWorkItemDetails(
client: RpcOperationSender,
export async function fetchWorkItemDetails(
client: RpcClient,
worktreeId: string,
args: { prNumber: number }
args: { prNumber: number; prRepo?: GitHubPrRepoSlug | null }
): Promise<GitHubPrReadOutcome<GitHubWorkItemDetails | null>> {
return settleGithubPrRead(githubPrWorkItemDetailsRead, () =>
githubPrWorkItemDetailsRead.request(
client,
githubPrRequestParams(githubPrWorkItemDetailsRead.operation.method, worktreeId, {
number: args.prNumber,
type: 'pr'
})
)
const params = githubPrRequestParams(githubPrWorkItemDetailsRead.operation.method, worktreeId, {
number: args.prNumber,
type: 'pr'
})
const outcome = await settleGithubPrRead(githubPrWorkItemDetailsRead, () =>
args.prRepo
? withGitHubTargetOperation({
client,
params: { repo: mobileRepoSelectorFromWorktreeId(worktreeId) },
ownerRepo: args.prRepo,
read: true,
send: (selected, exact, options) =>
githubPrWorkItemDetailsRead.request(selected, { ...params, ...exact }, options)
})
: githubPrWorkItemDetailsRead.request(client, params)
)
if (outcome.ok && args.prRepo) {
try {
return {
ok: true,
result: requireGitHubWorkItemTargetDetails(outcome.result, {
repository: args.prRepo,
type: 'pr',
number: args.prNumber
})
}
} catch (error) {
return {
ok: false,
error: error instanceof Error ? error.message : 'Unable to load pull request details.'
}
}
}
return outcome
}

export function fetchPRChecks(
Expand Down
Loading