@defrex/autobuild 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/SPEC.md +107 -10
- package/docs/agent-runtimes.md +1 -1
- package/docs/architecture.md +62 -22
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +285 -5
- package/docs/forges.md +1 -0
- package/docs/operator-api.md +19 -8
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +44 -6
- package/docs/remote-store-protocol.md +19 -6
- package/docs/restacking.md +12 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +6 -0
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +1 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +1 -0
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch.ts +9 -3
- package/packages/core/src/cli/help.ts +11 -4
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repository-status.ts +37 -2
- package/packages/core/src/cli/status.ts +8 -0
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/watch.ts +2 -0
- package/packages/core/src/config/live.ts +4 -0
- package/packages/core/src/config/profiles.ts +96 -0
- package/packages/core/src/config/ready-assignee.ts +43 -11
- package/packages/core/src/config/roles.ts +33 -10
- package/packages/core/src/config/schema.ts +166 -24
- package/packages/core/src/events/compatibility.ts +3 -1
- package/packages/core/src/events/forge-degradation-policy.ts +16 -2
- package/packages/core/src/events/payloads.ts +8 -0
- package/packages/core/src/events/policy.ts +1 -0
- package/packages/core/src/events/repository.ts +17 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +73 -124
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/node-parent.ts +2 -0
- package/packages/core/src/kernel/read-facts.ts +9 -1
- package/packages/core/src/kernel/reducer.ts +18 -1
- package/packages/core/src/kernel/ticket-preparation.ts +4 -1
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +1 -1
- package/packages/core/src/operator/registry.ts +25 -5
- package/packages/core/src/operator/sandbox-host.ts +3 -0
- package/packages/core/src/operator/tickets.ts +15 -3
- package/packages/core/src/plugin-sdk/index.ts +4 -0
- package/packages/core/src/ports/forge/create.ts +6 -0
- package/packages/core/src/ports/forge/github-transport.ts +40 -3
- package/packages/core/src/ports/forge/github.ts +12 -1
- package/packages/core/src/ports/forge/workspace-ancestry.ts +60 -0
- package/packages/core/src/ports/forge-failure.ts +31 -2
- package/packages/core/src/ports/runner/routing.ts +66 -5
- package/packages/core/src/ports/tickets/assignees.ts +54 -0
- package/packages/core/src/ports/tickets/contract.ts +164 -4
- package/packages/core/src/ports/tickets/create.ts +17 -3
- package/packages/core/src/ports/tickets/github-fake.ts +18 -2
- package/packages/core/src/ports/tickets/github.ts +247 -29
- package/packages/core/src/ports/tickets/hosted-index.ts +1 -0
- package/packages/core/src/ports/tickets/operations.ts +6 -1
- package/packages/core/src/ports/tickets/tree.ts +12 -2
- package/packages/core/src/ports/tickets/update.ts +6 -2
- package/packages/core/src/ports/types.ts +33 -3
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +9 -0
- package/packages/core/src/processes/build-child.ts +28 -7
- package/packages/core/src/processes/build-execution-state.ts +4 -1
- package/packages/core/src/processes/build-runner.ts +15 -1
- package/packages/core/src/processes/dispatcher.ts +98 -18
- package/packages/core/src/processes/harvest-child.ts +4 -0
- package/packages/core/src/processes/harvest-runner.ts +5 -0
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +15 -1
- package/packages/core/src/store/reducer-value-shapes.json +3119 -2926
- package/packages/core/src/store/remote/client.ts +21 -8
- package/packages/core/src/store/remote/index.ts +4 -0
- package/packages/core/src/store/remote/protocol.ts +7 -0
- package/packages/core/src/store/remote/released-clients.json +11 -0
- package/packages/core/src/store/remote/released-reducer-values/1.7.0.json +27366 -0
- package/packages/core/src/store/remote/released-reducer-values/index.ts +2 -0
- package/packages/core/src/store/repo-state-events.ts +1 -0
- package/packages/core/src/store/types.ts +11 -0
- package/packages/core/src/testing/dispatch-read-budget.ts +84 -58
- package/packages/core/src/testing/index.ts +2 -0
- package/packages/core/src/testing/reduced-read-budget.ts +72 -9
- package/skills/guide/SKILL.md +116 -21
- package/skills/guide/references/operator-api.md +19 -8
- package/skills/guide/references/plugin-authoring.md +44 -6
- package/skills/guide/references/remote-store-protocol.md +19 -6
- package/skills/guide/references/restacking.md +12 -7
- package/skills/operate/SKILL.md +29 -3
- package/skills/tickets/SKILL.md +18 -2
- package/templates/hosted-service/package.json +2 -2
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { selectAccount, type Accounts, type SelectedAccount } from '../../config/accounts'
|
|
2
|
+
import { profileRoles } from '../../config/profiles'
|
|
2
3
|
/**
|
|
3
4
|
* Eager runtime/model/args role resolution (SPEC §9, §16.1). Primary
|
|
4
5
|
* fields and the ordered alternate list inherit independently from the
|
|
5
6
|
* reserved `[roles.default]` entry. A declared role list, including `[]`,
|
|
6
7
|
* replaces the inherited list wholesale; each entry overlays that concrete
|
|
7
8
|
* role's effective primary axes and is validated at construction.
|
|
9
|
+
*
|
|
10
|
+
* Profiles (`[profiles.<name>]`) are resolved eagerly here too. A profile entry
|
|
11
|
+
* for role R overlays its declared fields on `[roles.R]` (or on nothing when R
|
|
12
|
+
* is undeclared) and then inherits from `[roles.default]` like any role, so an
|
|
13
|
+
* omitted field falls back to `[roles.R]`, then default. `profile(name)` walks
|
|
14
|
+
* the same candidate keys against profile entries and repository roles
|
|
15
|
+
* together, so alias precedence is identical with and without a profile.
|
|
8
16
|
*/
|
|
9
17
|
import type { AgentRunner } from '../types'
|
|
10
18
|
import { serves, type RuntimeRegistration, type RuntimeRegistry } from './runtime'
|
|
@@ -60,6 +68,14 @@ export class RuntimeConfigError extends Error {
|
|
|
60
68
|
export interface RuntimeResolver {
|
|
61
69
|
/** Resolve the earliest declared role/alias, otherwise `[roles.default]`. */
|
|
62
70
|
resolve(role: string, ...aliases: string[]): ResolvedRole
|
|
71
|
+
/** The resolver for one configured profile, or `undefined` when no profile
|
|
72
|
+
* by that name is configured. A profile resolver has no profiles itself. */
|
|
73
|
+
profile(name: string): RuntimeResolver | undefined
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** One `[profiles.<name>]` table as the resolver needs it. */
|
|
77
|
+
export interface RuntimeProfileSpec {
|
|
78
|
+
roles: Record<string, RuntimeSpec>
|
|
63
79
|
}
|
|
64
80
|
|
|
65
81
|
function runtimeNames(registry: RuntimeRegistry): string {
|
|
@@ -215,12 +231,28 @@ function resolveRole(
|
|
|
215
231
|
}
|
|
216
232
|
}
|
|
217
233
|
|
|
234
|
+
/** Walk the candidate keys in order; `default` and no declared key both fall
|
|
235
|
+
* back. Shared by repository and profile resolvers so they cannot drift. */
|
|
236
|
+
function walk(
|
|
237
|
+
keys: readonly string[],
|
|
238
|
+
lookup: (key: string) => ResolvedRole | undefined,
|
|
239
|
+
fallback: ResolvedRole,
|
|
240
|
+
): ResolvedRole {
|
|
241
|
+
for (const key of keys) {
|
|
242
|
+
if (key === 'default') return fallback
|
|
243
|
+
const resolved = lookup(key)
|
|
244
|
+
if (resolved !== undefined) return resolved
|
|
245
|
+
}
|
|
246
|
+
return fallback
|
|
247
|
+
}
|
|
248
|
+
|
|
218
249
|
/** Build and eagerly validate the complete role resolver. */
|
|
219
250
|
export function createRuntimeResolver(
|
|
220
251
|
registry: RuntimeRegistry,
|
|
221
252
|
roles: Record<string, RuntimeSpec>,
|
|
222
253
|
policySessionBudgetSeconds = 3600,
|
|
223
254
|
accounts: Accounts = {},
|
|
255
|
+
profiles: Record<string, RuntimeProfileSpec> = {},
|
|
224
256
|
): RuntimeResolver {
|
|
225
257
|
const problems: string[] = []
|
|
226
258
|
const defaultSpec = roles.default ?? {}
|
|
@@ -249,17 +281,46 @@ export function createRuntimeResolver(
|
|
|
249
281
|
if (resolved !== undefined) resolvedRoles[role] = resolved
|
|
250
282
|
}
|
|
251
283
|
|
|
284
|
+
const resolvedProfiles = new Map<string, Record<string, ResolvedRole>>()
|
|
285
|
+
for (const name of Object.keys(profiles)) {
|
|
286
|
+
const entries = profiles[name]!.roles
|
|
287
|
+
const overlaid = profileRoles(roles, entries)
|
|
288
|
+
const resolved: Record<string, ResolvedRole> = Object.create(null)
|
|
289
|
+
for (const role of Object.keys(entries)) {
|
|
290
|
+
// The schema refuses a profile `default` entry; never let one through.
|
|
291
|
+
if (role === 'default') continue
|
|
292
|
+
const result = resolveRole(
|
|
293
|
+
overlaid[role]!,
|
|
294
|
+
defaultSpec,
|
|
295
|
+
policySessionBudgetSeconds,
|
|
296
|
+
registry,
|
|
297
|
+
`[profiles.${name}.roles.${role}]`,
|
|
298
|
+
problems,
|
|
299
|
+
accounts,
|
|
300
|
+
)
|
|
301
|
+
if (result !== undefined) resolved[role] = result
|
|
302
|
+
}
|
|
303
|
+
resolvedProfiles.set(name, resolved)
|
|
304
|
+
}
|
|
305
|
+
|
|
252
306
|
if (problems.length > 0) throw new RuntimeConfigError(problems)
|
|
253
307
|
const fallback = resolvedDefault!
|
|
308
|
+
const base = (key: string) => resolvedRoles[key]
|
|
254
309
|
|
|
255
310
|
return {
|
|
256
311
|
resolve(role: string, ...aliases: string[]): ResolvedRole {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
312
|
+
return walk([role, ...aliases], base, fallback)
|
|
313
|
+
},
|
|
314
|
+
profile(name: string): RuntimeResolver | undefined {
|
|
315
|
+
const entries = resolvedProfiles.get(name)
|
|
316
|
+
if (entries === undefined) return undefined
|
|
317
|
+
const lookup = (key: string) => entries[key] ?? base(key)
|
|
318
|
+
return {
|
|
319
|
+
resolve(role: string, ...aliases: string[]): ResolvedRole {
|
|
320
|
+
return walk([role, ...aliases], lookup, fallback)
|
|
321
|
+
},
|
|
322
|
+
profile: () => undefined,
|
|
261
323
|
}
|
|
262
|
-
return fallback
|
|
263
324
|
},
|
|
264
325
|
}
|
|
265
326
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { TicketsConfig } from '../../config/schema'
|
|
3
|
+
import type { TicketSource } from '../types'
|
|
4
|
+
|
|
5
|
+
/** GitHub's documented maximum assignees per issue. */
|
|
6
|
+
export const MAX_TICKET_ASSIGNEES = 10
|
|
7
|
+
|
|
8
|
+
export const ticketAssigneesSchema = z
|
|
9
|
+
.array(
|
|
10
|
+
z
|
|
11
|
+
.string()
|
|
12
|
+
.refine((value) => value.trim().length > 0, 'assignee must not be blank')
|
|
13
|
+
.refine((value) => value === value.trim(), 'assignee must not have surrounding whitespace'),
|
|
14
|
+
)
|
|
15
|
+
.max(MAX_TICKET_ASSIGNEES, `at most ${MAX_TICKET_ASSIGNEES} assignees`)
|
|
16
|
+
|
|
17
|
+
/** A write naming assignees reached a source that cannot store them. */
|
|
18
|
+
export class TicketAssigneesUnsupported extends Error {
|
|
19
|
+
constructor(readonly source: string) {
|
|
20
|
+
super(`${source} ticket source cannot store assignees; nothing was written`)
|
|
21
|
+
this.name = 'TicketAssigneesUnsupported'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Refuse before any write: a present `assignees` (including `[]`) needs the capability. */
|
|
26
|
+
export function refuseUnsupportedAssignees(
|
|
27
|
+
source: Pick<TicketSource, 'name' | 'assignees'>,
|
|
28
|
+
patch: { assignees?: unknown },
|
|
29
|
+
): void {
|
|
30
|
+
if (patch.assignees !== undefined && !source.assignees)
|
|
31
|
+
throw new TicketAssigneesUnsupported(source.name)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Parse a CLI comma list such as `alice,me`; an empty value yields `[]`. */
|
|
35
|
+
export function parseAssigneesFlag(value: string, flag = '--assignees'): string[] {
|
|
36
|
+
const entries = value
|
|
37
|
+
.split(',')
|
|
38
|
+
.map((part) => part.trim())
|
|
39
|
+
.filter((part) => part.length > 0)
|
|
40
|
+
const result = ticketAssigneesSchema.safeParse(entries)
|
|
41
|
+
if (!result.success)
|
|
42
|
+
throw new Error(`${flag}: ${result.error.issues.map((issue) => issue.message).join('; ')}`)
|
|
43
|
+
return result.data
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The assignees a create sends: explicit ones replace the configured
|
|
47
|
+
* `[tickets].createAssignee` default; undefined sends none. */
|
|
48
|
+
export function creationAssignees(
|
|
49
|
+
tickets: Pick<TicketsConfig, 'createAssignee'>,
|
|
50
|
+
explicit?: string[],
|
|
51
|
+
): string[] | undefined {
|
|
52
|
+
if (explicit !== undefined) return explicit
|
|
53
|
+
return tickets.createAssignee !== undefined ? [tickets.createAssignee] : undefined
|
|
54
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createTicket, updateTicket, moveTicket, changeBlockers } from './operations'
|
|
2
2
|
import { normalizeIssueLinks, TicketIssueLinksUnsupported } from './issue-links'
|
|
3
|
-
import { TicketPriorityUnsupported } from './priority'
|
|
3
|
+
import { TicketPriorityUnsupported, urgentFirst } from './priority'
|
|
4
|
+
import { TicketAssigneesUnsupported } from './assignees'
|
|
4
5
|
import { compatibleTicketSource } from './tree'
|
|
5
6
|
import { TicketRevisionConflict } from './revision'
|
|
6
7
|
import { describe, expect, test } from 'bun:test'
|
|
@@ -16,15 +17,24 @@ import type {
|
|
|
16
17
|
TicketPage,
|
|
17
18
|
} from '../types'
|
|
18
19
|
|
|
19
|
-
/** Shared assertion also used by negative controls for declared capabilities.
|
|
20
|
+
/** Shared assertion also used by negative controls for declared capabilities.
|
|
21
|
+
* `filed` holds the matching tickets' ids, oldest filed first. `oldest` windows
|
|
22
|
+
* the source's dispatch order; `newest` windows newest filed first. */
|
|
20
23
|
export async function assertTicketPage(
|
|
21
24
|
source: TicketSource,
|
|
22
25
|
criteria: TicketCriteria,
|
|
23
26
|
page: TicketPage,
|
|
24
27
|
full: Awaited<ReturnType<TicketSource['listReady']>>,
|
|
28
|
+
filed: readonly string[],
|
|
25
29
|
): Promise<void> {
|
|
30
|
+
expect([...filed].sort()).toEqual(full.tickets.map((ticket) => ticket.ref.id).sort())
|
|
26
31
|
const actual = await source.listPage!(criteria, page)
|
|
27
|
-
const ordered =
|
|
32
|
+
const ordered =
|
|
33
|
+
page.order === 'newest'
|
|
34
|
+
? [...filed].reverse().map((id) => full.tickets.find((ticket) => ticket.ref.id === id)!)
|
|
35
|
+
: source.priority
|
|
36
|
+
? urgentFirst(full.tickets)
|
|
37
|
+
: full.tickets
|
|
28
38
|
const offset = page.offset ?? 0
|
|
29
39
|
expect(actual).toEqual({
|
|
30
40
|
tickets: ordered.slice(offset, offset + page.limit),
|
|
@@ -72,6 +82,9 @@ export interface TicketSourceContractHarness {
|
|
|
72
82
|
* explicitly configured scratch project. */
|
|
73
83
|
afterCreate?: (ticket: Ticket, idempotencyKey: string) => Promise<void> | void
|
|
74
84
|
cleanup?: () => Promise<void>
|
|
85
|
+
/** Minimum spacing between creates for this source to record distinct
|
|
86
|
+
* filing times; defaults to 5 ms. */
|
|
87
|
+
filingIntervalMs?: number
|
|
75
88
|
/** Links a source reports on every ticket without being asked, such as a
|
|
76
89
|
* GitHub issue's own `closes` link. They are expected beside the written
|
|
77
90
|
* links and stay when the written links are cleared. */
|
|
@@ -211,6 +224,9 @@ export function describeTicketSourceContract(
|
|
|
211
224
|
{ state: harness.states.ready, labels: [] },
|
|
212
225
|
]) {
|
|
213
226
|
const full = await source.listReady(criteria)
|
|
227
|
+
// No fixture ticket is urgent, so the listing is filing order with
|
|
228
|
+
// the source's own tie-break; the urgent test below owns ordering.
|
|
229
|
+
const filed = full.tickets.map((ticket) => ticket.ref.id)
|
|
214
230
|
for (const order of [undefined, 'oldest', 'newest'] as const)
|
|
215
231
|
for (const window of [
|
|
216
232
|
{ limit: 2 },
|
|
@@ -219,12 +235,81 @@ export function describeTicketSourceContract(
|
|
|
219
235
|
{ limit: 0 },
|
|
220
236
|
]) {
|
|
221
237
|
const page = { ...window, ...(order ? { order } : {}) }
|
|
222
|
-
await assertTicketPage(source, criteria, page, full)
|
|
238
|
+
await assertTicketPage(source, criteria, page, full, filed)
|
|
223
239
|
}
|
|
224
240
|
}
|
|
225
241
|
})
|
|
226
242
|
})
|
|
227
243
|
|
|
244
|
+
test('native pages order urgent dispatch first and newest filed first when declared', async () => {
|
|
245
|
+
await withTicketSource(factory, async (harness) => {
|
|
246
|
+
const source = harness.source
|
|
247
|
+
if (!source.listPage || !source.priority) return
|
|
248
|
+
const label = await freshLabel(harness, 'page-urgent')
|
|
249
|
+
// n1, u2, n3, u4, n5 in filing order; u2 and u4 are urgent.
|
|
250
|
+
const filed: string[] = []
|
|
251
|
+
for (let i = 1; i <= 5; i++) {
|
|
252
|
+
if (i > 1) await Bun.sleep(harness.filingIntervalMs ?? 5)
|
|
253
|
+
const urgent = i % 2 === 0
|
|
254
|
+
const ticket = await createTracked(
|
|
255
|
+
harness,
|
|
256
|
+
{
|
|
257
|
+
title: contractTicketTitle('page-urgent'),
|
|
258
|
+
body: CONTRACT_TICKET_BODY,
|
|
259
|
+
labels: [label],
|
|
260
|
+
...(urgent ? { priority: 'urgent' as const } : {}),
|
|
261
|
+
},
|
|
262
|
+
{ state: harness.states.ready },
|
|
263
|
+
)
|
|
264
|
+
filed.push(ticket.ref.id)
|
|
265
|
+
}
|
|
266
|
+
const [n1, u2, n3, u4, n5] = filed as [string, string, string, string, string]
|
|
267
|
+
const dispatch = [u2, u4, n1, n3, n5]
|
|
268
|
+
const newest = [n5, u4, n3, u2, n1]
|
|
269
|
+
// The fixture separates newest filed first from reversed dispatch order.
|
|
270
|
+
expect(newest).not.toEqual([...dispatch].reverse())
|
|
271
|
+
for (const criteria of [
|
|
272
|
+
{ labels: [label] },
|
|
273
|
+
{ state: harness.states.ready, labels: [label] },
|
|
274
|
+
]) {
|
|
275
|
+
const full = await source.listReady(criteria)
|
|
276
|
+
for (const order of [undefined, 'oldest', 'newest'] as const) {
|
|
277
|
+
const expected = order === 'newest' ? newest : dispatch
|
|
278
|
+
for (const limit of [1, 2, 3]) {
|
|
279
|
+
const seen: string[] = []
|
|
280
|
+
for (let offset = 0; offset < expected.length; offset += limit) {
|
|
281
|
+
const page = await source.listPage(criteria, {
|
|
282
|
+
limit,
|
|
283
|
+
offset,
|
|
284
|
+
...(order ? { order } : {}),
|
|
285
|
+
})
|
|
286
|
+
expect(page.total).toBe(expected.length)
|
|
287
|
+
expect(page.diagnostics).toEqual(full.diagnostics)
|
|
288
|
+
expect(page.tickets).toHaveLength(Math.min(limit, expected.length - offset))
|
|
289
|
+
seen.push(...page.tickets.map((ticket) => ticket.ref.id))
|
|
290
|
+
}
|
|
291
|
+
expect(seen).toEqual(expected)
|
|
292
|
+
expect(new Set(seen).size).toBe(expected.length)
|
|
293
|
+
const past = await source.listPage(criteria, {
|
|
294
|
+
limit,
|
|
295
|
+
offset: expected.length,
|
|
296
|
+
...(order ? { order } : {}),
|
|
297
|
+
})
|
|
298
|
+
expect(past.tickets).toEqual([])
|
|
299
|
+
expect(past.total).toBe(expected.length)
|
|
300
|
+
}
|
|
301
|
+
await assertTicketPage(
|
|
302
|
+
source,
|
|
303
|
+
criteria,
|
|
304
|
+
{ limit: expected.length, ...(order ? { order } : {}) },
|
|
305
|
+
full,
|
|
306
|
+
filed,
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
})
|
|
312
|
+
|
|
228
313
|
test('bounded state counts agree with listed states when declared', async () => {
|
|
229
314
|
await withTicketSource(factory, async (harness) => {
|
|
230
315
|
const source = harness.source
|
|
@@ -431,6 +516,81 @@ export function describeTicketSourceContract(
|
|
|
431
516
|
})
|
|
432
517
|
})
|
|
433
518
|
|
|
519
|
+
test('assignees are read when declared and refused otherwise', async () => {
|
|
520
|
+
await withTicketSource(factory, async (harness) => {
|
|
521
|
+
const source = harness.source
|
|
522
|
+
const ready = harness.states.ready
|
|
523
|
+
if (!source.assignees) {
|
|
524
|
+
for (const assignees of [['someone'], []]) {
|
|
525
|
+
const title = contractTicketTitle('refused assignees')
|
|
526
|
+
const refusedCreate = await createTicket(source, {
|
|
527
|
+
title,
|
|
528
|
+
body: CONTRACT_TICKET_BODY,
|
|
529
|
+
state: ready,
|
|
530
|
+
assignees,
|
|
531
|
+
}).catch((error: unknown) => error)
|
|
532
|
+
expect(refusedCreate).toBeInstanceOf(TicketAssigneesUnsupported)
|
|
533
|
+
expect((refusedCreate as TicketAssigneesUnsupported).source).toBe(source.name)
|
|
534
|
+
const refusedProxy = await compatibleTicketSource(source)
|
|
535
|
+
.create({ title, body: CONTRACT_TICKET_BODY, assignees }, { state: ready })
|
|
536
|
+
.catch((error: unknown) => error)
|
|
537
|
+
expect(refusedProxy).toBeInstanceOf(TicketAssigneesUnsupported)
|
|
538
|
+
expect(
|
|
539
|
+
(await source.listReady({ state: ready })).tickets.some((t) => t.title === title),
|
|
540
|
+
).toBe(false)
|
|
541
|
+
}
|
|
542
|
+
const created = await createTracked(
|
|
543
|
+
harness,
|
|
544
|
+
{ title: contractTicketTitle('unassigned'), body: CONTRACT_TICKET_BODY },
|
|
545
|
+
{ state: ready },
|
|
546
|
+
)
|
|
547
|
+
expect(created).not.toHaveProperty('assignees')
|
|
548
|
+
expect(await compatibleTicketSource(source).get(created.ref.id)).not.toHaveProperty(
|
|
549
|
+
'assignees',
|
|
550
|
+
)
|
|
551
|
+
for (const assignees of [['someone'], []]) {
|
|
552
|
+
const refusedUpdate = await updateTicket(source, created.ref.id, {
|
|
553
|
+
title: 'not written',
|
|
554
|
+
assignees,
|
|
555
|
+
}).catch((error: unknown) => error)
|
|
556
|
+
expect(refusedUpdate).toBeInstanceOf(TicketAssigneesUnsupported)
|
|
557
|
+
expect((refusedUpdate as TicketAssigneesUnsupported).source).toBe(source.name)
|
|
558
|
+
}
|
|
559
|
+
if (source.mutateIfRevision) {
|
|
560
|
+
const refusedGuarded = await updateTicket(
|
|
561
|
+
source,
|
|
562
|
+
created.ref.id,
|
|
563
|
+
{ assignees: [] },
|
|
564
|
+
false,
|
|
565
|
+
created.revision,
|
|
566
|
+
).catch((error: unknown) => error)
|
|
567
|
+
expect(refusedGuarded).toBeInstanceOf(TicketAssigneesUnsupported)
|
|
568
|
+
}
|
|
569
|
+
const unchanged = await source.get(created.ref.id)
|
|
570
|
+
expect(unchanged?.revision).toBe(created.revision)
|
|
571
|
+
expect(unchanged?.title).toBe(created.title)
|
|
572
|
+
return
|
|
573
|
+
}
|
|
574
|
+
// A declaring source returns the set on every read, empty when unassigned.
|
|
575
|
+
const created = await createTracked(
|
|
576
|
+
harness,
|
|
577
|
+
{ title: contractTicketTitle('assignees'), body: CONTRACT_TICKET_BODY, assignees: [] },
|
|
578
|
+
{ state: ready },
|
|
579
|
+
)
|
|
580
|
+
expect(created.assignees).toEqual([])
|
|
581
|
+
expect((await source.get(created.ref.id))?.assignees).toEqual([])
|
|
582
|
+
await updateTicket(source, created.ref.id, { assignees: [] })
|
|
583
|
+
const read = await source.get(created.ref.id)
|
|
584
|
+
expect(read?.assignees).toEqual([])
|
|
585
|
+
expect(read?.revision).toBe(created.revision)
|
|
586
|
+
expect(
|
|
587
|
+
(await source.listReady({ state: ready })).tickets.find(
|
|
588
|
+
(t) => t.ref.id === created.ref.id,
|
|
589
|
+
)?.assignees,
|
|
590
|
+
).toEqual([])
|
|
591
|
+
})
|
|
592
|
+
})
|
|
593
|
+
|
|
434
594
|
test('urgent priority persists when declared and is refused otherwise', async () => {
|
|
435
595
|
await withTicketSource(factory, async (harness) => {
|
|
436
596
|
const source = harness.source
|
|
@@ -20,6 +20,7 @@ import { GitHubTicketSource } from './github'
|
|
|
20
20
|
import { FileGitHubValidatorStore } from './github-validators'
|
|
21
21
|
import {
|
|
22
22
|
createGitHubFetchTransport,
|
|
23
|
+
githubCredentialRequirement,
|
|
23
24
|
githubTokenSource,
|
|
24
25
|
resolveGitHubToken,
|
|
25
26
|
type GitHubRequest,
|
|
@@ -29,7 +30,10 @@ import { normalizeGitRemoteUrl } from '../../kernel/origin'
|
|
|
29
30
|
import { HostedTicketSource, hostedTicketPolicy } from './remote'
|
|
30
31
|
import { ticketLifecycle } from './lifecycle'
|
|
31
32
|
import { normalizeServiceURL } from '../../connection'
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
assertCreateAssigneeSupported,
|
|
35
|
+
assertReadyAssigneeSupported,
|
|
36
|
+
} from '../../config/ready-assignee'
|
|
33
37
|
|
|
34
38
|
function reason(error: unknown): string {
|
|
35
39
|
return error instanceof Error ? error.message : String(error)
|
|
@@ -54,6 +58,9 @@ async function rawTicketSource(
|
|
|
54
58
|
exec?: Exec
|
|
55
59
|
/** GitHub API seam for the github source; defaults to the fetch transport. */
|
|
56
60
|
transport?: GitHubRequest
|
|
61
|
+
/** Process label: the github source's default transport refuses requests
|
|
62
|
+
* without a credential. Absent, `AB_GITHUB_REQUIRE_CREDENTIAL` decides. */
|
|
63
|
+
requireCredential?: string
|
|
57
64
|
} = {},
|
|
58
65
|
): Promise<TicketSource> {
|
|
59
66
|
const exec = options.exec ?? spawnExec
|
|
@@ -155,7 +162,12 @@ async function rawTicketSource(
|
|
|
155
162
|
`[tickets].source = "github" needs an origin on github.com; origin is ${origin}`,
|
|
156
163
|
)
|
|
157
164
|
return new GitHubTicketSource({
|
|
158
|
-
transport:
|
|
165
|
+
transport:
|
|
166
|
+
options.transport ??
|
|
167
|
+
createGitHubFetchTransport({
|
|
168
|
+
token: githubTokenSource(env),
|
|
169
|
+
requireCredential: githubCredentialRequirement(env, options.requireCredential),
|
|
170
|
+
}),
|
|
159
171
|
repository: coordinates,
|
|
160
172
|
lifecycle: ticketLifecycle(config),
|
|
161
173
|
readyLabels: config.readyLabels ?? ['autobuild'],
|
|
@@ -236,7 +248,9 @@ export async function createTicketSource(
|
|
|
236
248
|
// Plugins load after config parse, so the capability is checked here, on
|
|
237
249
|
// the constructed source, rather than in the schema.
|
|
238
250
|
const owner = plugins?.ticketSources.get(config.source)?.owner
|
|
239
|
-
|
|
251
|
+
const plugin = owner?.kind === 'plugin' ? owner.name : undefined
|
|
252
|
+
assertReadyAssigneeSupported(config, source, plugin)
|
|
253
|
+
assertCreateAssigneeSupported(config, source, plugin)
|
|
240
254
|
return compatibleTicketSource(source)
|
|
241
255
|
}
|
|
242
256
|
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
* adapter read of those fails a test with a 404.
|
|
15
15
|
* Identity routes answer for the requesting credential: `GET user` returns
|
|
16
16
|
* its login (or 403 for `transportAs(null)`), and the assignee-check route
|
|
17
|
-
* answers 204 for `assignable` logins.
|
|
17
|
+
* answers 204 for `assignable` logins. Issue create and edit set the
|
|
18
|
+
* `assignees` they name, silently dropping any login that is not `assignable`,
|
|
19
|
+
* or every one under `dropAssignees`, as GitHub does without push access.
|
|
18
20
|
*
|
|
19
21
|
* UI-style mutators simulate what people do on GitHub outside the adapter.
|
|
20
22
|
*/
|
|
@@ -141,6 +143,9 @@ export class FakeGitHubIssues {
|
|
|
141
143
|
/** Simulates a token without push access: GitHub silently drops label
|
|
142
144
|
* changes on issue create and edit. */
|
|
143
145
|
dropLabels = false
|
|
146
|
+
/** Simulates a token without push access: GitHub silently drops assignee
|
|
147
|
+
* changes on issue create and edit. */
|
|
148
|
+
dropAssignees = false
|
|
144
149
|
/** When false, UI labelling leaves `updated_at` untouched. */
|
|
145
150
|
labelsBumpUpdatedAt = true
|
|
146
151
|
searchLagMs: number
|
|
@@ -803,10 +808,18 @@ export class FakeGitHubIssues {
|
|
|
803
808
|
}
|
|
804
809
|
}
|
|
805
810
|
|
|
811
|
+
/** The assignees an edit leaves: the requested assignable logins, or the
|
|
812
|
+
* current set unchanged under `dropAssignees`. */
|
|
813
|
+
private assigned(requested: string[], current: string[]): string[] {
|
|
814
|
+
if (this.dropAssignees) return current
|
|
815
|
+
return [...new Set(requested)].filter((login) => this.assignable.has(login.toLowerCase()))
|
|
816
|
+
}
|
|
817
|
+
|
|
806
818
|
private createIssue(body: unknown): { json: unknown; status: number } {
|
|
807
|
-
const input = body as { title?: string; body?: string; labels?: string[] }
|
|
819
|
+
const input = body as { title?: string; body?: string; labels?: string[]; assignees?: string[] }
|
|
808
820
|
if (!input?.title) throw new GitHubApiError(422, 'Validation Failed', { message: 'title' })
|
|
809
821
|
const issue = this.insert(input.title, input.body ?? null, [])
|
|
822
|
+
if (input.assignees !== undefined) issue.assignees = this.assigned(input.assignees, [])
|
|
810
823
|
if (!this.dropLabels)
|
|
811
824
|
for (const name of input.labels ?? []) {
|
|
812
825
|
const label = this.ensureLabel(name)
|
|
@@ -825,8 +838,11 @@ export class FakeGitHubIssues {
|
|
|
825
838
|
labels?: string[]
|
|
826
839
|
state?: 'open' | 'closed'
|
|
827
840
|
state_reason?: string | null
|
|
841
|
+
assignees?: string[]
|
|
828
842
|
}
|
|
829
843
|
if (input.title !== undefined) issue.title = input.title
|
|
844
|
+
if (input.assignees !== undefined)
|
|
845
|
+
issue.assignees = this.assigned(input.assignees, issue.assignees)
|
|
830
846
|
if (input.body !== undefined) issue.body = input.body
|
|
831
847
|
if (input.labels !== undefined && !this.dropLabels) {
|
|
832
848
|
const next = input.labels.map((name) => this.ensureLabel(name).name)
|