@defrex/autobuild 1.5.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 +192 -24
- package/docs/agent-runtimes.md +1 -1
- package/docs/answering-blocked-builds.md +7 -4
- package/docs/architecture.md +100 -32
- package/docs/configuration-overview.md +10 -0
- package/docs/configuration.md +340 -10
- package/docs/dispatcher.md +2 -2
- package/docs/forges.md +1 -0
- package/docs/glossary.md +1 -1
- package/docs/operating.md +1 -1
- package/docs/operator-api.md +33 -10
- package/docs/operator-surfaces.md +6 -3
- package/docs/plugin-authoring.md +48 -6
- package/docs/remote-store-protocol.md +33 -10
- package/docs/restacking.md +16 -7
- package/docs/ticket-sources.md +34 -6
- package/docs/tickets.md +7 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/workspaces.md +1 -1
- package/package.json +3 -3
- package/packages/core/src/cli/attention.ts +3 -0
- package/packages/core/src/cli/binary-direct.ts +1 -0
- package/packages/core/src/cli/dashboard/model.ts +14 -4
- package/packages/core/src/cli/dashboard/poll.ts +14 -0
- package/packages/core/src/cli/dashboard/render.ts +3 -0
- package/packages/core/src/cli/dispatch-frontend.ts +10 -14
- package/packages/core/src/cli/dispatch-preflight.ts +5 -1
- package/packages/core/src/cli/dispatch-repository-feed.ts +145 -109
- package/packages/core/src/cli/dispatch-tickets.ts +47 -0
- package/packages/core/src/cli/dispatch-upgrade-controller.ts +3 -0
- package/packages/core/src/cli/dispatch.ts +377 -101
- package/packages/core/src/cli/help.ts +15 -6
- package/packages/core/src/cli/init-validation.ts +14 -1
- package/packages/core/src/cli/repo-lease.ts +225 -0
- package/packages/core/src/cli/repository-status.ts +40 -3
- package/packages/core/src/cli/status.ts +21 -13
- package/packages/core/src/cli/ticket.ts +22 -4
- package/packages/core/src/cli/wait.ts +4 -1
- package/packages/core/src/cli/watch.ts +17 -4
- 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 +204 -26
- package/packages/core/src/events/catalog.ts +2 -0
- 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 +23 -0
- package/packages/core/src/events/policy.ts +3 -0
- package/packages/core/src/events/repository.ts +19 -0
- package/packages/core/src/kernel/__snapshots__/reducer-accumulator-shapes.json +267 -352
- package/packages/core/src/kernel/build-creation.ts +29 -0
- package/packages/core/src/kernel/dispatch-capacity.ts +134 -30
- package/packages/core/src/kernel/engine.ts +13 -6
- package/packages/core/src/kernel/forge-health.ts +47 -0
- package/packages/core/src/kernel/generators/build-log.ts +9 -0
- package/packages/core/src/kernel/guarded-forge.ts +76 -18
- package/packages/core/src/kernel/incremental-fixtures.ts +1 -0
- package/packages/core/src/kernel/janitor-failure.ts +85 -5
- package/packages/core/src/kernel/leaf-restack-state.ts +4 -2
- package/packages/core/src/kernel/log-index.ts +1 -1
- package/packages/core/src/kernel/node-landing.ts +2 -1
- 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-registry.ts +6 -1
- package/packages/core/src/kernel/reducer.ts +75 -4
- package/packages/core/src/kernel/ticket-preparation.ts +15 -8
- package/packages/core/src/operator/protocol.ts +10 -0
- package/packages/core/src/operator/query.ts +16 -13
- 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 +35 -7
- 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 +37 -3
- package/packages/core/src/ports/workspace/commit-preservation.ts +28 -12
- package/packages/core/src/ports/workspace/git-worktree.ts +3 -1
- package/packages/core/src/ports/workspace/harvest-execution.ts +4 -2
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +12 -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 +17 -2
- package/packages/core/src/processes/dispatcher.ts +329 -59
- package/packages/core/src/processes/execution-no-progress.ts +2 -0
- package/packages/core/src/processes/harvest-child.ts +8 -2
- package/packages/core/src/processes/harvest-execution-state.ts +104 -0
- package/packages/core/src/processes/harvest-runner.ts +251 -17
- package/packages/core/src/processes/repo-view.ts +2 -0
- package/packages/core/src/scenarios/harness.ts +160 -36
- package/packages/core/src/store/reduced-reads.ts +10 -0
- package/packages/core/src/store/reducer-value-shapes.json +3339 -2898
- 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 +22 -0
- package/packages/core/src/store/remote/released-reducer-values/1.6.0.json +27173 -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 +4 -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 +411 -11
- package/skills/guide/SKILL.md +166 -35
- package/skills/guide/references/operator-api.md +33 -10
- package/skills/guide/references/plugin-authoring.md +48 -6
- package/skills/guide/references/remote-store-protocol.md +33 -10
- package/skills/guide/references/restacking.md +16 -7
- package/skills/operate/SKILL.md +79 -14
- package/skills/tickets/SKILL.md +22 -4
- package/templates/hosted-service/package.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* shelling `gh`.
|
|
8
8
|
*/
|
|
9
9
|
import { z } from 'zod'
|
|
10
|
-
import { ForgeFailure, isForgeFailure } from '../forge-failure'
|
|
10
|
+
import { ForgeCredentialMissing, ForgeFailure, isForgeFailure } from '../forge-failure'
|
|
11
11
|
import { spawnExec } from '../workspace/git-worktree'
|
|
12
12
|
|
|
13
13
|
export interface GitHubRequestOpts {
|
|
@@ -58,6 +58,8 @@ export class GitHubApiError extends Error {
|
|
|
58
58
|
message: string,
|
|
59
59
|
body?: unknown,
|
|
60
60
|
readonly headers: Record<string, string> = {},
|
|
61
|
+
/** Why the request went out without a credential, when it did. */
|
|
62
|
+
readonly unauthenticated?: string,
|
|
61
63
|
) {
|
|
62
64
|
super(message)
|
|
63
65
|
this.name = 'GitHubApiError'
|
|
@@ -106,14 +108,32 @@ export type GitHubTokenSource =
|
|
|
106
108
|
/** Minimum interval between two invocations of a token resolver. */
|
|
107
109
|
export const CREDENTIAL_MISS_TTL_MS = 60_000
|
|
108
110
|
|
|
111
|
+
/** Marks a process environment whose GitHub API requests must carry a
|
|
112
|
+
* credential. Remote workspace providers set it for every guest process. */
|
|
113
|
+
export const GITHUB_REQUIRE_CREDENTIAL_ENV = 'AB_GITHUB_REQUIRE_CREDENTIAL'
|
|
114
|
+
|
|
115
|
+
/** The process label a transport names when it refuses an anonymous request:
|
|
116
|
+
* an explicit label, else a generic one when the environment carries
|
|
117
|
+
* {@link GITHUB_REQUIRE_CREDENTIAL_ENV}, else none (anonymous allowed). */
|
|
118
|
+
export function githubCredentialRequirement(
|
|
119
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
120
|
+
label?: string,
|
|
121
|
+
): string | undefined {
|
|
122
|
+
if (label !== undefined) return label
|
|
123
|
+
return env[GITHUB_REQUIRE_CREDENTIAL_ENV] === '1' ? 'remote guest process' : undefined
|
|
124
|
+
}
|
|
125
|
+
|
|
109
126
|
/** Production transport: token-authenticated fetch against api.github.com.
|
|
110
127
|
* Callers pass a literal token or a resolver such as
|
|
111
128
|
* {@link githubTokenSource}; no `Authorization` header is sent when neither
|
|
112
|
-
* yields one
|
|
129
|
+
* yields one — unless `requireCredential` names the process, in which case a
|
|
130
|
+
* request that would go out anonymously throws {@link ForgeCredentialMissing}
|
|
131
|
+
* before anything is sent. */
|
|
113
132
|
export function createGitHubFetchTransport(opts: {
|
|
114
133
|
token?: GitHubTokenSource
|
|
115
134
|
apiBase?: string
|
|
116
135
|
now?: () => number
|
|
136
|
+
requireCredential?: string
|
|
117
137
|
}): GitHubRequest {
|
|
118
138
|
const source = opts.token
|
|
119
139
|
const now = opts.now ?? Date.now
|
|
@@ -162,6 +182,15 @@ export function createGitHubFetchTransport(opts: {
|
|
|
162
182
|
return async (method, path, request = {}) => {
|
|
163
183
|
const credential = await resolveToken()
|
|
164
184
|
const token = credential.token
|
|
185
|
+
// `in` for the same strictNullChecks reason as the anonymous error below.
|
|
186
|
+
const missReason =
|
|
187
|
+
token === undefined || token === ''
|
|
188
|
+
? 'reason' in credential
|
|
189
|
+
? credential.reason
|
|
190
|
+
: 'no GitHub credential was available'
|
|
191
|
+
: undefined
|
|
192
|
+
if (missReason !== undefined && opts.requireCredential !== undefined)
|
|
193
|
+
throw new ForgeCredentialMissing(opts.requireCredential, missReason)
|
|
165
194
|
let url = /^https:\/\//i.test(path) ? path : `${base}/${path.replace(/^\/+/, '')}`
|
|
166
195
|
if (request.query !== undefined) {
|
|
167
196
|
const params = new URLSearchParams(request.query)
|
|
@@ -232,6 +261,7 @@ export function createGitHubFetchTransport(opts: {
|
|
|
232
261
|
`${githubErrorMessage(response.status, json, text)}${anonymous}`,
|
|
233
262
|
json,
|
|
234
263
|
headerMap,
|
|
264
|
+
missReason,
|
|
235
265
|
)
|
|
236
266
|
}
|
|
237
267
|
return {
|
|
@@ -422,7 +452,14 @@ export function classifyGitHubFailure(error: unknown, now = Date.now()): unknown
|
|
|
422
452
|
if (isForgeFailure(error)) return error
|
|
423
453
|
const resetAt = githubRateLimitUntil(error, now)
|
|
424
454
|
const message = error instanceof Error ? error.message : String(error)
|
|
425
|
-
if (resetAt)
|
|
455
|
+
if (resetAt) {
|
|
456
|
+
const unauthenticated = error instanceof GitHubApiError ? error.unauthenticated : undefined
|
|
457
|
+
return new ForgeFailure(message, {
|
|
458
|
+
kind: 'rate-limited',
|
|
459
|
+
resetAt,
|
|
460
|
+
...(unauthenticated ? { unauthenticated } : {}),
|
|
461
|
+
})
|
|
462
|
+
}
|
|
426
463
|
const code = error && typeof error === 'object' && 'code' in error ? error.code : undefined
|
|
427
464
|
if (
|
|
428
465
|
(error instanceof GitHubApiError && error.status >= 500) ||
|
|
@@ -55,6 +55,7 @@ import {
|
|
|
55
55
|
GitHubApiError,
|
|
56
56
|
classifyGitHubFailure,
|
|
57
57
|
createGitHubFetchTransport,
|
|
58
|
+
githubCredentialRequirement,
|
|
58
59
|
githubTokenSource,
|
|
59
60
|
restPlanLimitation,
|
|
60
61
|
type GitHubRequest,
|
|
@@ -765,6 +766,10 @@ export class GitHubForge implements Forge {
|
|
|
765
766
|
* Defaults to `MERGEABILITY_RETRY_DELAYS_MS` (7 re-queries, ~30 s);
|
|
766
767
|
* tests inject `[0, 0]` or all-zero schedules so no test sleeps. */
|
|
767
768
|
mergeabilityRetryDelaysMs?: number[]
|
|
769
|
+
/** Process label: the default transport refuses to send a request
|
|
770
|
+
* without a credential. Absent, the environment's
|
|
771
|
+
* `AB_GITHUB_REQUIRE_CREDENTIAL` marker decides. */
|
|
772
|
+
requireCredential?: string
|
|
768
773
|
} = {},
|
|
769
774
|
) {
|
|
770
775
|
this.now = opts.now ?? Date.now
|
|
@@ -775,7 +780,13 @@ export class GitHubForge implements Forge {
|
|
|
775
780
|
// stored login, probed lazily through this adapter's exec seam on the
|
|
776
781
|
// first request. A request that still goes out anonymously carries the
|
|
777
782
|
// miss reason in its error, so nothing is probed at construction time.
|
|
778
|
-
const
|
|
783
|
+
const requireCredential = githubCredentialRequirement(this.env, opts.requireCredential)
|
|
784
|
+
const transport =
|
|
785
|
+
opts.transport ??
|
|
786
|
+
createGitHubFetchTransport({
|
|
787
|
+
token: this.token,
|
|
788
|
+
...(requireCredential !== undefined ? { requireCredential } : {}),
|
|
789
|
+
})
|
|
779
790
|
this.transport = async (...args) =>
|
|
780
791
|
guardedForgeRequest(async () => {
|
|
781
792
|
const context = forgeRequestContext()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { gitOid } from '../../events/payloads'
|
|
2
|
+
import type { Forge } from '../types'
|
|
3
|
+
import type { Exec } from '../workspace/git-worktree'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A remote guest has no forge credential, so the GitHub `compare` request
|
|
7
|
+
* behind `isCommitAncestor` would go out anonymously and spend the shared
|
|
8
|
+
* sandbox address's unauthenticated quota. The guest's workspace is a full
|
|
9
|
+
* clone with an already-authorized Git read channel, so ancestry is proven
|
|
10
|
+
* there instead: `merge-base --is-ancestor`, fetching both commits by SHA once
|
|
11
|
+
* when either object is missing. Every other member passes through unchanged.
|
|
12
|
+
* It makes no forge API request and no Store read.
|
|
13
|
+
*/
|
|
14
|
+
export function withWorkspaceAncestry(
|
|
15
|
+
forge: Forge,
|
|
16
|
+
deps: { exec: Exec; workspacePath: string },
|
|
17
|
+
): Forge {
|
|
18
|
+
const isAncestor = (ancestor: string, descendant: string) =>
|
|
19
|
+
deps.exec(['git', 'merge-base', '--is-ancestor', ancestor, descendant], {
|
|
20
|
+
cwd: deps.workspacePath,
|
|
21
|
+
})
|
|
22
|
+
const isCommitAncestor = async (ancestor: string, descendant: string): Promise<boolean> => {
|
|
23
|
+
if (!gitOid.safeParse(ancestor).success || !gitOid.safeParse(descendant).success)
|
|
24
|
+
throw new Error('invalid ancestry OID')
|
|
25
|
+
let result = await isAncestor(ancestor, descendant)
|
|
26
|
+
if (result.exitCode === 0) return true
|
|
27
|
+
if (result.exitCode === 1) return false
|
|
28
|
+
const fetched = await deps.exec(
|
|
29
|
+
[
|
|
30
|
+
'git',
|
|
31
|
+
'fetch',
|
|
32
|
+
'--no-tags',
|
|
33
|
+
'--no-write-fetch-head',
|
|
34
|
+
'--refmap=',
|
|
35
|
+
'origin',
|
|
36
|
+
ancestor,
|
|
37
|
+
descendant,
|
|
38
|
+
],
|
|
39
|
+
{ cwd: deps.workspacePath },
|
|
40
|
+
)
|
|
41
|
+
if (fetched.exitCode !== 0)
|
|
42
|
+
throw new Error(
|
|
43
|
+
`workspace ancestry fetch failed (exit ${fetched.exitCode}): ${fetched.stderr.trim()}`,
|
|
44
|
+
)
|
|
45
|
+
result = await isAncestor(ancestor, descendant)
|
|
46
|
+
if (result.exitCode === 0) return true
|
|
47
|
+
if (result.exitCode === 1) return false
|
|
48
|
+
throw new Error(
|
|
49
|
+
`workspace ancestry check failed (exit ${result.exitCode}): ${result.stderr.trim()}`,
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
return new Proxy(forge, {
|
|
53
|
+
get(target, key) {
|
|
54
|
+
// Capability-preserving: a forge without ancestry proof keeps none.
|
|
55
|
+
if (key === 'isCommitAncestor' && target.isCommitAncestor) return isCommitAncestor
|
|
56
|
+
const value = Reflect.get(target, key, target)
|
|
57
|
+
return typeof value === 'function' ? value.bind(target) : value
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
2
|
/** Additive plugin API: recognizable across separately loaded SDK copies. */
|
|
3
3
|
export type ForgeFailureDetails =
|
|
4
|
-
| {
|
|
4
|
+
| {
|
|
5
|
+
kind: 'rate-limited'
|
|
6
|
+
resetAt: string
|
|
7
|
+
/** Set when the limited request carried no credential: why it went out
|
|
8
|
+
* anonymously. Such a limit belongs to the caller's network address, not
|
|
9
|
+
* to the dispatcher's credential, so it never pauses the repository. */
|
|
10
|
+
unauthenticated?: string
|
|
11
|
+
}
|
|
5
12
|
| { kind: 'transient'; retry: 'retryable' }
|
|
6
13
|
|
|
7
14
|
export class ForgeFailure extends Error {
|
|
@@ -28,11 +35,33 @@ export function isForgeFailure(error: unknown): error is ForgeFailure {
|
|
|
28
35
|
const details = value.details
|
|
29
36
|
return (
|
|
30
37
|
!!details &&
|
|
31
|
-
((details.kind === 'rate-limited' &&
|
|
38
|
+
((details.kind === 'rate-limited' &&
|
|
39
|
+
z.iso.datetime().safeParse(details.resetAt).success &&
|
|
40
|
+
(details.unauthenticated === undefined ||
|
|
41
|
+
(typeof details.unauthenticated === 'string' && details.unauthenticated.length > 0))) ||
|
|
32
42
|
(details.kind === 'transient' && details.retry === 'retryable'))
|
|
33
43
|
)
|
|
34
44
|
}
|
|
35
45
|
|
|
46
|
+
/** A GitHub API request refused before sending because the process has no
|
|
47
|
+
* credential where one is required (a remote guest, or a hosted backend). It
|
|
48
|
+
* is deliberately not a `ForgeFailure`: it is neither a rate limit nor
|
|
49
|
+
* transient, and retrying cannot succeed without a credential. */
|
|
50
|
+
export class ForgeCredentialMissing extends Error {
|
|
51
|
+
readonly credential = 'GITHUB_TOKEN or GH_TOKEN' as const
|
|
52
|
+
constructor(
|
|
53
|
+
readonly process: string,
|
|
54
|
+
readonly reason: string,
|
|
55
|
+
) {
|
|
56
|
+
super(
|
|
57
|
+
`${process}: GitHub API request refused — no GitHub credential (${reason}). ` +
|
|
58
|
+
'Provide GITHUB_TOKEN or GH_TOKEN to this process; remote guests receive no forge ' +
|
|
59
|
+
'credential, so their GitHub API work must run kernel-side.',
|
|
60
|
+
)
|
|
61
|
+
this.name = 'ForgeCredentialMissing'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
36
65
|
export interface ForgeRejectionDetails {
|
|
37
66
|
/** Human-readable forge name, e.g. `GitHub`. */
|
|
38
67
|
forge: string
|
|
@@ -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
|