* feat(forge): let providers declare their hosts, names, sign-in, and review decisions Prepare the forge contract for a second provider: - ForgeProvider lists the hosts it serves and names itself (label, changeRequestNoun); registering a provider that lists a host another registered provider lists throws, so each URL has at most one provider. ctx.forge.describe(forge) returns the family's ForgeDescription. - ForgeReadiness carries the sign-in command, which the panel's sign-in banner shows instead of building `gh auth login` for the github family. - ForgeReviewData lists the review decisions the host lets the reader record; the review dialog offers only those instead of hardcoding the GitHub rule that a pull request's author may only comment. - ForgeReviewThread.original may name a later commit the host carried the thread to while its lines stayed unchanged. - The changes view names the code host and its word for a change request from the entry's ForgeDescription instead of hardcoding GitHub and PR. The GitHub provider declares its configured hosts, GitHub, pull requests, `gh auth login --hostname <host>`, and reads viewerDidAuthor for the review decisions. Upgrade guide: forge-provider-hosts. * feat(forge-gitlab): read GitLab merge requests through the GitLab CLI Add the experimental forge-gitlab provider. It serves the configured GitLab hosts through glab: status batches over GraphQL, head-pinned patches from merge request diff versions, commit listings, merge bases, pipeline jobs, closing issues, and review threads mapped from REST discussions, including outdated threads' hunks. The forge bundle composes the provider, disabled by default. * feat(forge-gitlab): write GitLab reviews, retry pipelines, request reviews, and rebase The GitLab provider now writes through glab as well as reading: comments start discussions at positions derived from the head's diff version, pending replies and comments are draft notes that a review publishes with its summary and review state, and approving checks the head through GitLab's sha parameter. Review reads carry the signed-in user's rights from GraphQL, their draft notes as the pending review, and the decisions GitLab lets them record. Snapshots name the head pipeline as every job's rerun, offer rebase as the branch update, and follow GitLab's permissions for reruns and review requests. updateBranch's contract now states how a provider whose host takes no expected head checks it. * feat(forge): let forge providers register the commands that bind change requests forge-session no longer recognizes gh commands by itself. A provider now registers a declarative ForgeCommandRule through ctx.forgeSession.registerCommands: its executable, creation and reference subcommands, change request page path, JSON URL members, declared options, and a pure select that maps one parsed reference command to a URL or a read-only lookup. forge-github registers gh and forge-gitlab registers glab, which adds glab mr create, view, update, and checkout, including numbers with -R: a full project URL binds directly, and other repository forms resolve through glab mr view in the call's shell. forge-session keeps the shared parts: the literal shell tokenizer, option parsing, output reading, lookups, and the projection. The forgeChangeRequests state version derives from the recognized rules, so a changed rule set refolds every Session, including commands that ran before the provider loaded. Ending a registration keeps its rule recognized until restart, so unloading providers at shutdown does not rewrite every checkpoint. * refactor(forge-gitlab): publish the GitLab provider as @deepseek-ai/dsh-forge-gitlab New experimental packages omit the experimental prefix so that promotion keeps their npm name. Register the directory in EXPERIMENTAL_PACKAGE_NAME_EXCEPTIONS instead of growing the legacy prefixed list, and rename every dependency, configuration row, path mapping, and document that names the package. * fix(forge-gitlab): keep review writes, comment positions, and reads within GitLab's facts and the limits - After GitLab refuses a publication, read the drafts again: delete them only when all remain, since GitLab can publish them before it refuses the summary, and report the outcome as unknown otherwise. A rollback that leaves drafts reports how many may remain. - Place comments on files GitLab collapsed through the diff compared from their texts, and let a file's new path name it over another file's old path after chained renames. - Keep the final newline of raw file reads. - Apply maxOutputBytes to the complete review result, and report a read whose rights stop early or skip a discussion's later notes as truncated. - Serve a version over maxCachedVersionBytes without keeping it. - Resolve uploaded avatars GitLab names by their path on the host. - Schedule bounded reads through p-limit. * fix(forge-session): run lookups only for live command rules and keep the projection registered - Reference lookups use the rules of live registrations, so a disposed provider's rule still folds but starts no gh or glab process. - A failed re-registration registers the projection again with the earlier rules, so clients keep its view; an error is logged only when that fails too. - Document the startup re-registration, test that the checkpointed state version survives a real Loader start, shutdown, and restart, and record that starting without a provider removes the bindings only its commands made. - Describe the changes view's pending review and single comment without naming GitHub, which keeps its own rule in forge-github, and render registerCommands as code in the generated service reference. * fix(forge-bundle): name GitLab merge requests in the bundle description The bundle now follows GitLab merge requests as well as GitHub pull requests, so the description's first sentence in every locale names both kinds of change request. * feat(forge): bind the change requests that gh api and glab api requests name Models often read a merge request through `glab api` or a pull request through `gh api` instead of `glab mr view` or `gh pr view`, which left the change request unbound. A command rule now declares raw API request subcommands beside its reference subcommands, each group with its own options, since `-f` is a value of `gh api` and a flag of `gh pr checkout`. An API request binds, as referenced, only the change request its REST path names, such as `projects/group%2Fapp/merge_requests/7/changes` or `repos/octo/demo/pulls/7/files`; its output is not read, since one request can list many change requests. A path whose host the command names binds directly, and one without a host, or with the current repository's placeholders, resolves through the CLI's view command in the call's shell. The gh and glab rules move to version 2. * docs(forge): add forge-gitlab and the forge-session peers to the module graph Regenerate docs/module-graph for the renamed GitLab provider and the optional forge-session peer of both providers. * test(web): refresh the forge bundle description in the recommended plugin catalog The creation recommendation recording carries every recommended plugin's description; refresh it for the forge bundle description that now names GitLab merge requests and the glab sign-in. * chore(forge-gitlab): carry the 0.2.2-rc.3 release version and move upgrade guides to v0.2.2-rc.3
115 lines
6.7 KiB
TypeScript
115 lines
6.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { compileRules } from '@deepseek-ai/dsh-experimental-forge-session/src/commands.ts'
|
|
import { GLAB_COMMANDS } from '../src/commands.ts'
|
|
|
|
const rules = compileRules([GLAB_COMMANDS])
|
|
|
|
describe('glab command rule', () => {
|
|
const url = 'https://gitlab.example/group/sub/demo/-/merge_requests/42'
|
|
|
|
it.each([
|
|
`glab mr view ${url}`,
|
|
`glab mr checkout '${url}/diffs?view=inline'`,
|
|
`glab mr update '${url}#note_7' --ready --label bug`,
|
|
'glab mr view 42 -R https://gitlab.example/group/sub/demo',
|
|
'glab mr view 42 --repo=https://gitlab.example/group/sub/demo.git -F json',
|
|
'glab mr checkout -Rhttps://gitlab.example/group/sub/demo/ 42 --branch review',
|
|
'glab mr update 42 --title "Fix it" --draft -R https://gitlab.example/group/sub/demo',
|
|
])('names the merge request of %s', (command) => {
|
|
expect(rules.named(command)).toEqual([{ url, lookup: null, rule: 'glab', kind: 'reference' }])
|
|
})
|
|
|
|
it('keeps a plain http project URL', () => {
|
|
expect(rules.named('glab mr view 3 -R http://gitlab.local:8080/team/app')).toEqual([
|
|
{ url: 'http://gitlab.local:8080/team/app/-/merge_requests/3', lookup: null, rule: 'glab', kind: 'reference' },
|
|
])
|
|
})
|
|
|
|
it('looks up the other repository forms through glab in the same environment', () => {
|
|
expect(rules.named('glab mr view 42 -R group/sub/demo --comments 2>&1 | tail -40')).toEqual([
|
|
{ url: null, lookup: 'env glab mr view 42 --repo group/sub/demo --output json --jq .web_url', rule: 'glab', kind: 'reference' },
|
|
])
|
|
expect(rules.named('GITLAB_HOST=gitlab.example glab mr update 42 -R [email protected]:group/demo.git --ready')).toEqual([
|
|
{
|
|
url: null,
|
|
lookup: String.raw`env GITLAB_HOST\=gitlab.example glab mr view 42 --repo git\@gitlab.example\:group/demo.git --output json --jq .web_url`,
|
|
rule: 'glab', kind: 'reference',
|
|
},
|
|
])
|
|
expect(rules.named('glab mr view 42 -R https://gitlab.example/group/../demo')).toEqual([
|
|
{ url: null, lookup: String.raw`env glab mr view 42 --repo https\://gitlab.example/group/../demo --output json --jq .web_url`, rule: 'glab', kind: 'reference' },
|
|
])
|
|
})
|
|
|
|
it.each([
|
|
'glab mr view 42',
|
|
'glab mr view feature-branch -R group/demo',
|
|
'glab mr view 1 2 -R group/demo',
|
|
'glab mr view 42 --unknown -R group/demo',
|
|
'glab mr list -R group/demo',
|
|
'glab mr view https://gitlab.example/group/demo/-/issues/42',
|
|
])('names nothing for unsupported or ambiguous input: %s', (command) => {
|
|
expect(rules.named(command)).toEqual([])
|
|
})
|
|
|
|
it('reads the merge request URLs that glab prints', () => {
|
|
const evidence = rules.evidence('glab mr create --fill --yes')
|
|
expect(evidence).toEqual({ urls: 'created', pushes: false, named: [], rules: ['glab'] })
|
|
const created = ['Creating merge request for feat into main in group/sub/demo', '', '!42 Fix it (feat)', ` ${url}`].join('\n')
|
|
expect(evidence === undefined ? [] : rules.printed(created, evidence)).toEqual([url])
|
|
const viewed = ['title:\tFix it', 'number:\t42', `url:\t${url}`, '--', 'Follows https://gitlab.example/group/sub/demo/-/merge_requests/41'].join('\n')
|
|
expect(rules.printed(viewed, { urls: 'referenced', pushes: false, named: [], rules: ['glab'] })).toEqual([url])
|
|
const json = JSON.stringify({ iid: 42, web_url: url, author: { web_url: 'https://gitlab.example/octo' } })
|
|
expect(rules.printed(json, { urls: 'referenced', pushes: false, named: [], rules: ['glab'] })).toEqual([url])
|
|
expect(rules.lookupUrl(`${url}\n`, 'glab')).toBe(url)
|
|
})
|
|
|
|
describe('glab api', () => {
|
|
const merge = (host: string, number: number) => `https://${host}/LegGasai/jyc-test/-/merge_requests/${number}`
|
|
|
|
it.each([
|
|
['glab api --hostname gitlab.deepseek.com "projects/LegGasai%2Fjyc-test/merge_requests/3" 2>&1 | head -c 6000', merge('gitlab.deepseek.com', 3)],
|
|
['glab api --hostname gitlab.deepseek.com projects/LegGasai%2Fjyc-test/merge_requests/3/changes', merge('gitlab.deepseek.com', 3)],
|
|
["glab api '/api/v4/projects/LegGasai%2Fjyc-test/merge_requests/4/notes?per_page=100' --hostname=gitlab.example --paginate", merge('gitlab.example', 4)],
|
|
['glab api -X POST -f body=LGTM -H "Accept: application/json" --hostname gitlab.example projects/LegGasai%2Fjyc-test/merge_requests/5/notes',
|
|
merge('gitlab.example', 5)],
|
|
['glab api https://gitlab.example:8443/api/v4/projects/LegGasai%2Fjyc-test/merge_requests/6', merge('gitlab.example:8443', 6)],
|
|
])('names the merge request a REST path names: %s', (command, url) => {
|
|
expect(rules.named(command)).toEqual([{ url, lookup: null, rule: 'glab', kind: 'api-request' }])
|
|
})
|
|
|
|
it('looks up a path without a host through glab, in the current repository for its placeholders', () => {
|
|
expect(rules.named('glab api projects/group%2Fsub%2Fapp/merge_requests/7')).toEqual([
|
|
{ url: null, lookup: 'env glab mr view 7 --repo group/sub/app --output json --jq .web_url', rule: 'glab', kind: 'api-request' },
|
|
])
|
|
expect(rules.named('glab api projects/:fullpath/merge_requests/7/diffs')).toEqual([
|
|
{ url: null, lookup: 'env glab mr view 7 --output json --jq .web_url', rule: 'glab', kind: 'api-request' },
|
|
])
|
|
})
|
|
|
|
it.each([
|
|
'glab api --hostname gitlab.example projects/group%2Fapp/merge_requests',
|
|
'glab api --hostname gitlab.example projects/1680/merge_requests/3',
|
|
'glab api --hostname gitlab.example projects/group%E0%2Fapp/merge_requests/3',
|
|
'glab api --hostname gitlab.example projects/group%2F..%2Fapp/merge_requests/3',
|
|
'glab api --hostname https://gitlab.example projects/group%2Fapp/merge_requests/3',
|
|
'glab api --hostname gitlab.example projects/group%2Fapp/issues/3',
|
|
'glab api --hostname gitlab.example projects/group%2Fapp/merge_requests/99999999999999999999',
|
|
'glab api --bogus projects/group%2Fapp/merge_requests/3',
|
|
'glab api graphql -f query=x',
|
|
'glab api projects/group%2Fapp/merge_requests/3 projects/group%2Fapp/merge_requests/4',
|
|
])('names nothing for %s', (command) => {
|
|
expect(rules.named(command)).toEqual([])
|
|
})
|
|
|
|
it('binds the named merge request without reading the output, which can list others', () => {
|
|
const command = 'glab api --hostname gitlab.example projects/LegGasai%2Fjyc-test/merge_requests/3'
|
|
const evidence = rules.evidence(command)
|
|
expect(evidence).toEqual({ urls: 'referenced', pushes: false, named: [merge('gitlab.example', 3)], rules: [] })
|
|
const listed = JSON.stringify([{ iid: 4, web_url: merge('gitlab.example', 4) }])
|
|
expect(evidence === undefined ? undefined : rules.printed(listed, evidence)).toEqual([])
|
|
expect(rules.evidence('glab api --hostname gitlab.example projects/LegGasai%2Fjyc-test/merge_requests')).toBeUndefined()
|
|
})
|
|
})
|
|
})
|