The Session list read the full snapshot of every change request a listed Session binds: up to 100 check contexts, reviewers, review threads, and linked issues each, all in one GraphQL document per host. GitHub ends a request after 10 seconds of processing, so about 30 bound pull requests made every list read fail. Opening a Session whose change request the list already watched read nothing until the next regular poll. The forge registry now watches a change request at two levels. A brief holds the title, state, draft flag, mergeability, review decision, and combined check outcome. A watched change request is polled for its snapshot while it has a snapshot watcher and for its brief otherwise, with one fetch in flight per forge and level. Providers read briefs through the optional fetchBriefs; forge-github reads them from scalars and statusCheckRollup.state, briefBatchSize (50) pull requests per query. The Session list watches briefs and names the state it already holds, so a merged change request is not read again and a list that reopens in the same process waits for the interval. The Session panel and the review page ask for a status no older than statusMaxAgeMs (10 seconds) when they start to show a change request.
119 lines
5.2 KiB
TypeScript
119 lines
5.2 KiB
TypeScript
import { Context, Service } from '@deepseek-ai/cordis'
|
|
import ForgeService from '@deepseek-ai/dsh-experimental-forge'
|
|
import type { ForgeCommandRule } from '@deepseek-ai/dsh-experimental-forge-session'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { GH_COMMANDS } from '../src/commands.ts'
|
|
import * as ForgeGitHub from '../src/index.ts'
|
|
|
|
let ctx: Context | undefined
|
|
|
|
afterEach(async () => {
|
|
await ctx?.fiber.dispose()
|
|
ctx = undefined
|
|
})
|
|
|
|
/** Command rules registered with {@link RecordingForgeSession} whose registering fiber is live. */
|
|
const registered = new Set<ForgeCommandRule>()
|
|
|
|
/** A `forgeSession` service that records command rule registrations in {@link registered}. */
|
|
class RecordingForgeSession extends Service {
|
|
constructor(ctx: Context) {
|
|
super(ctx, 'forgeSession')
|
|
}
|
|
|
|
registerCommands(rule: ForgeCommandRule): () => void {
|
|
const dispose = this.ctx.effect(() => {
|
|
registered.add(rule)
|
|
return () => { registered.delete(rule) }
|
|
})
|
|
return () => void dispose()
|
|
}
|
|
}
|
|
|
|
async function forge(): Promise<Context> {
|
|
ctx = new Context()
|
|
await ctx.plugin(ForgeService)
|
|
return ctx
|
|
}
|
|
|
|
describe('forge-github plugin', () => {
|
|
it('registers the GitHub provider for the configured hosts', async () => {
|
|
const context = await forge()
|
|
await context.plugin(ForgeGitHub, { hosts: ['github.com', 'ghe.corp.example'] })
|
|
|
|
expect(context.forge.changeRequestFromUrl('https://github.com/octo/demo/pull/1')).toEqual({
|
|
repository: { forge: 'github', host: 'github.com', owner: 'octo', name: 'demo' },
|
|
number: 1,
|
|
})
|
|
expect(context.forge.repositoryFromRemote('[email protected]:team/svc.git')).toEqual({ forge: 'github', host: 'ghe.corp.example', owner: 'team', name: 'svc' })
|
|
})
|
|
|
|
it('serves github.com by default', async () => {
|
|
const context = await forge()
|
|
await context.plugin(ForgeGitHub, {})
|
|
|
|
expect(context.forge.repositoryFromRemote('https://github.com/octo/demo.git')).toBeDefined()
|
|
expect(context.forge.repositoryFromRemote('https://ghe.corp.example/team/svc.git')).toBeUndefined()
|
|
})
|
|
|
|
it('offers the three viewer lists on its hosts, 50 pull requests per read by default', async () => {
|
|
const context = await forge()
|
|
await context.plugin(ForgeGitHub, { hosts: ['github.com', 'ghe.corp.example'] })
|
|
|
|
expect(context.forge.viewerSources()).toEqual([{
|
|
forge: 'github', hosts: ['github.com', 'ghe.corp.example'], filters: new Set(['review-requested', 'authored', 'involved']), maxItems: 50,
|
|
}])
|
|
})
|
|
|
|
it('registers the gh commands with forge-session while both run', async () => {
|
|
const context = await forge()
|
|
await context.plugin(RecordingForgeSession)
|
|
const fiber = context.plugin(ForgeGitHub, {})
|
|
await fiber
|
|
|
|
expect([...registered]).toEqual([GH_COMMANDS])
|
|
await fiber.dispose()
|
|
expect(registered.size).toBe(0)
|
|
})
|
|
|
|
it('unregisters the provider when its fiber is disposed', async () => {
|
|
const context = await forge()
|
|
const fiber = context.plugin(ForgeGitHub, {})
|
|
await fiber
|
|
|
|
await fiber.dispose()
|
|
|
|
expect(context.forge.changeRequestFromUrl('https://github.com/octo/demo/pull/1')).toBeUndefined()
|
|
})
|
|
|
|
it.each([
|
|
[{ ghCommand: ' ' }, 'forge-github: ghCommand must not be empty'],
|
|
[{ hosts: [] }, 'forge-github: hosts must list at least one host'],
|
|
[{ hosts: ['https://github.com'] }, 'forge-github: invalid host "https://github.com"'],
|
|
[{ timeoutMs: 0 }, 'forge-github: timeoutMs must be a positive integer no greater than 2147483647'],
|
|
[{ timeoutMs: 2_147_483_648 }, 'forge-github: timeoutMs must be a positive integer no greater than 2147483647'],
|
|
[{ timeoutMs: 1.5 }, 'forge-github: timeoutMs must be a positive integer no greater than 2147483647'],
|
|
[{ maxOutputBytes: 1.5 }, 'forge-github: maxOutputBytes must be a positive safe integer'],
|
|
[{ maxOutputBytes: 0 }, 'forge-github: maxOutputBytes must be a positive safe integer'],
|
|
[{ maxOutputBytes: Number.MAX_SAFE_INTEGER + 1 }, 'forge-github: maxOutputBytes must be a positive safe integer'],
|
|
[{ maxCommits: 0 }, 'forge-github: maxCommits must be a positive safe integer'],
|
|
[{ maxCommits: 2.5 }, 'forge-github: maxCommits must be a positive safe integer'],
|
|
[{ maxReviewThreads: 0 }, 'forge-github: maxReviewThreads must be a positive safe integer'],
|
|
[{ maxReviewThreads: 2.5 }, 'forge-github: maxReviewThreads must be a positive safe integer'],
|
|
[{ briefBatchSize: 0 }, 'forge-github: briefBatchSize must be a positive safe integer'],
|
|
[{ briefBatchSize: 2.5 }, 'forge-github: briefBatchSize must be a positive safe integer'],
|
|
[{ maxViewerItems: 0 }, 'forge-github: maxViewerItems must be a positive safe integer'],
|
|
[{ maxViewerItems: 101 }, 'forge-github: maxViewerItems must be no greater than 100'],
|
|
])('rejects %j at load', async (config, message) => {
|
|
const context = await forge()
|
|
|
|
await expect(context.plugin(ForgeGitHub, config)).rejects.toThrow(message)
|
|
})
|
|
|
|
it('does not apply timer limits to the output byte budget', async () => {
|
|
const context = await forge()
|
|
await context.plugin(ForgeGitHub, { maxOutputBytes: 2_147_483_648 })
|
|
expect(context.forge.repositoryFromRemote('https://github.com/octo/demo.git')).toBeDefined()
|
|
})
|
|
})
|