@defrex/autobuild 0.13.0 → 1.0.0-beta.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 +5 -3
- package/SPEC.md +673 -99
- package/bin/ab-dispatch-kernel.ts +4 -6
- package/docs/architecture.md +322 -75
- package/docs/assets/headline-wide.png +0 -0
- package/docs/configuration.md +112 -12
- package/docs/hosted-service.md +20 -2
- package/docs/integration-tree.md +117 -0
- package/docs/landing-policy.md +150 -0
- package/docs/mcp.md +24 -0
- package/docs/migration-1.0.md +68 -0
- package/docs/operator-api.md +20 -9
- package/docs/remote-store-protocol.md +114 -9
- package/docs/remote-ticket-protocol.md +26 -5
- package/docs/restacking.md +79 -0
- package/docs/setup.md +49 -6
- package/docs/ticket-dependencies.md +69 -0
- package/docs/ticket-migration.md +8 -0
- package/package.json +4 -3
- package/packages/core/src/cli/attention.ts +40 -163
- package/packages/core/src/cli/build-control.ts +75 -55
- package/packages/core/src/cli/bulk-control.ts +3 -2
- package/packages/core/src/cli/context.ts +68 -78
- package/packages/core/src/cli/dashboard/actions.ts +6 -3
- package/packages/core/src/cli/dashboard/landing-display.ts +6 -0
- package/packages/core/src/cli/dashboard/live.ts +5 -0
- package/packages/core/src/cli/dashboard/model.ts +178 -40
- package/packages/core/src/cli/dashboard/poll.ts +15 -9
- package/packages/core/src/cli/dashboard/refresh.ts +176 -0
- package/packages/core/src/cli/dashboard/render.ts +78 -28
- package/packages/core/src/cli/dashboard/repository-poll.ts +57 -0
- package/packages/core/src/cli/dashboard/selection.ts +7 -1
- package/packages/core/src/cli/dashboard/tree.ts +107 -0
- package/packages/core/src/cli/dispatch-frontend.ts +173 -169
- package/packages/core/src/cli/dispatch-process.ts +14 -7
- package/packages/core/src/cli/dispatch-repository-feed.ts +196 -0
- package/packages/core/src/cli/dispatch.ts +397 -214
- package/packages/core/src/cli/dispatcher-liveness.ts +41 -21
- package/packages/core/src/cli/harvest.ts +71 -39
- package/packages/core/src/cli/help.ts +49 -32
- package/packages/core/src/cli/historical-build-state.ts +27 -0
- package/packages/core/src/cli/init-validation.ts +43 -2
- package/packages/core/src/cli/keyboard.ts +6 -0
- package/packages/core/src/cli/landings.ts +18 -0
- package/packages/core/src/cli/main.ts +52 -18
- package/packages/core/src/cli/mcp.ts +9 -0
- package/packages/core/src/cli/pr-attachments.ts +10 -13
- package/packages/core/src/cli/pr-summary-publication.ts +27 -60
- package/packages/core/src/cli/pr-summary.ts +43 -13
- package/packages/core/src/cli/publication-settlement.ts +177 -21
- package/packages/core/src/cli/repository-status.ts +49 -2
- package/packages/core/src/cli/status.ts +133 -36
- package/packages/core/src/cli/terminal-restore.ts +54 -0
- package/packages/core/src/cli/terminal.ts +16 -2
- package/packages/core/src/cli/terminals.ts +121 -219
- package/packages/core/src/cli/ticket-editor.ts +10 -3
- package/packages/core/src/cli/ticket.ts +115 -20
- package/packages/core/src/cli/upgrade-commit.ts +4 -0
- package/packages/core/src/cli/upgrade-compatibility.ts +2 -2
- package/packages/core/src/cli/upgrade-landing.ts +69 -0
- package/packages/core/src/cli/upgrade.ts +16 -0
- package/packages/core/src/cli/wait.ts +194 -91
- package/packages/core/src/cli/watch.ts +111 -109
- package/packages/core/src/config/landing.ts +22 -0
- package/packages/core/src/config/live.ts +1 -0
- package/packages/core/src/config/pipeline-source.ts +4 -3
- package/packages/core/src/config/schema.ts +3 -0
- package/packages/core/src/events/catalog.ts +48 -3
- package/packages/core/src/events/payloads.ts +295 -6
- package/packages/core/src/events/repository.ts +38 -3
- package/packages/core/src/integration/harness.ts +11 -2
- package/packages/core/src/kernel/__snapshots__/reducer-registry.test.ts.snap +3330 -119
- package/packages/core/src/kernel/auto-merge-default.ts +1 -0
- package/packages/core/src/kernel/auto-merge.ts +29 -4
- package/packages/core/src/kernel/build-identity.ts +94 -0
- package/packages/core/src/kernel/change-presence.ts +179 -0
- package/packages/core/src/kernel/dispatch-status.ts +17 -1
- package/packages/core/src/kernel/dispatcher-liveness.ts +10 -4
- package/packages/core/src/kernel/engine.ts +89 -2
- package/packages/core/src/kernel/generators/build-log.ts +23 -0
- package/packages/core/src/kernel/generators/leaf-restack-log.ts +110 -0
- package/packages/core/src/kernel/generators/node-restack-log.ts +94 -0
- package/packages/core/src/kernel/generators/repository-journals.ts +25 -3
- package/packages/core/src/kernel/harvest.ts +25 -23
- package/packages/core/src/kernel/integration-completeness.ts +81 -0
- package/packages/core/src/kernel/integration-landing.ts +263 -0
- package/packages/core/src/kernel/integration-stack.ts +36 -0
- package/packages/core/src/kernel/integration-state.ts +135 -0
- package/packages/core/src/kernel/landing-policy.ts +47 -0
- package/packages/core/src/kernel/landing-publication.ts +41 -0
- package/packages/core/src/kernel/landing-readiness.ts +67 -0
- package/packages/core/src/kernel/landing-state.ts +96 -0
- package/packages/core/src/kernel/leaf-restack-completion.ts +24 -0
- package/packages/core/src/kernel/leaf-restack-state.ts +73 -0
- package/packages/core/src/kernel/log-index-value.ts +38 -0
- package/packages/core/src/kernel/log-index.ts +35 -5
- package/packages/core/src/kernel/node-landing.ts +439 -0
- package/packages/core/src/kernel/node-parent.ts +184 -0
- package/packages/core/src/kernel/node-restack-state.ts +191 -0
- package/packages/core/src/kernel/node-restack-transaction.ts +210 -0
- package/packages/core/src/kernel/node-restack.ts +274 -0
- package/packages/core/src/kernel/read-facts.ts +704 -0
- package/packages/core/src/kernel/reconcile-head.ts +51 -0
- package/packages/core/src/kernel/reconcile-restack.ts +560 -0
- package/packages/core/src/kernel/reducer-registry.ts +153 -3
- package/packages/core/src/kernel/reducer.ts +121 -6
- package/packages/core/src/kernel/repository-attention.ts +179 -0
- package/packages/core/src/kernel/service-facts.ts +135 -0
- package/packages/core/src/kernel/snapshot-parent.ts +33 -0
- package/packages/core/src/kernel/terminal-guard.ts +133 -0
- package/packages/core/src/ontology.ts +9 -1
- package/packages/core/src/operator/annotations.ts +12 -0
- package/packages/core/src/operator/control.ts +11 -6
- package/packages/core/src/operator/index.ts +6 -0
- package/packages/core/src/operator/landings.ts +35 -0
- package/packages/core/src/operator/presentation.ts +1 -0
- package/packages/core/src/operator/protocol.ts +12 -3
- package/packages/core/src/operator/query.ts +40 -21
- package/packages/core/src/operator/read-view.ts +4 -13
- package/packages/core/src/operator/registry.ts +48 -19
- package/packages/core/src/operator/requests.ts +3 -22
- package/packages/core/src/operator/sandbox.ts +10 -9
- package/packages/core/src/operator/tickets.ts +57 -11
- package/packages/core/src/plugin-sdk/index.ts +13 -0
- package/packages/core/src/ports/forge/contract.ts +91 -3
- package/packages/core/src/ports/forge/fake.ts +142 -4
- package/packages/core/src/ports/forge/git-rewrite.ts +232 -0
- package/packages/core/src/ports/forge/github-readiness.ts +421 -0
- package/packages/core/src/ports/forge/github.ts +631 -35
- package/packages/core/src/ports/forge/local-git.ts +119 -5
- package/packages/core/src/ports/forge/readiness.ts +99 -0
- package/packages/core/src/ports/tickets/contract.ts +41 -0
- package/packages/core/src/ports/tickets/create.ts +8 -1
- package/packages/core/src/ports/tickets/fake.ts +32 -1
- package/packages/core/src/ports/tickets/file-codec.ts +7 -0
- package/packages/core/src/ports/tickets/file.ts +18 -1
- package/packages/core/src/ports/tickets/hosted-index.ts +2 -0
- package/packages/core/src/ports/tickets/linear.ts +124 -4
- package/packages/core/src/ports/tickets/migration.ts +25 -1
- package/packages/core/src/ports/tickets/operations.ts +7 -2
- package/packages/core/src/ports/tickets/remote-protocol.ts +19 -0
- package/packages/core/src/ports/tickets/remote.ts +10 -1
- package/packages/core/src/ports/tickets/revision.ts +3 -1
- package/packages/core/src/ports/tickets/tree.ts +148 -0
- package/packages/core/src/ports/tickets/update.ts +15 -2
- package/packages/core/src/ports/types.ts +135 -5
- package/packages/core/src/ports/workspace/git-worktree.ts +2 -1
- package/packages/core/src/ports/workspace/provider-capabilities.ts +1 -1
- package/packages/core/src/ports/workspace/vercel-sandbox.ts +60 -3
- package/packages/core/src/processes/build-child.ts +6 -6
- package/packages/core/src/processes/build-runner.ts +586 -87
- package/packages/core/src/processes/dispatch-failure-budget.ts +5 -4
- package/packages/core/src/processes/dispatcher-selectors.ts +15 -9
- package/packages/core/src/processes/dispatcher.ts +2239 -357
- package/packages/core/src/processes/execution-no-progress.ts +46 -1
- package/packages/core/src/processes/harvest-execution-state.ts +15 -9
- package/packages/core/src/processes/harvest-runner.ts +34 -70
- package/packages/core/src/processes/harvest.ts +38 -15
- package/packages/core/src/processes/infrastructure-failure-budget.ts +13 -15
- package/packages/core/src/processes/orchestrator-tick.ts +2 -2
- package/packages/core/src/processes/publication-loss.ts +35 -21
- package/packages/core/src/processes/publication-state.ts +30 -5
- package/packages/core/src/processes/repo-view.ts +244 -1130
- package/packages/core/src/processes/tick-publication.ts +110 -0
- package/packages/core/src/store/adapter.ts +23 -0
- package/packages/core/src/store/build-scope.ts +35 -0
- package/packages/core/src/store/contract.ts +909 -0
- package/packages/core/src/store/digest.ts +52 -4
- package/packages/core/src/store/local/schema.ts +26 -13
- package/packages/core/src/store/local/store.ts +296 -55
- package/packages/core/src/store/memory.ts +181 -30
- package/packages/core/src/store/phase-session.ts +34 -0
- package/packages/core/src/store/reduced-reads.ts +240 -0
- package/packages/core/src/store/reducer-value-shapes.json +18323 -0
- package/packages/core/src/store/reducer-value-validation.ts +96 -0
- package/packages/core/src/store/reducer-values.ts +145 -0
- package/packages/core/src/store/remote/client.ts +85 -0
- package/packages/core/src/store/remote/compatibility.ts +21 -9
- package/packages/core/src/store/remote/index.ts +19 -0
- package/packages/core/src/store/remote/protocol.ts +27 -0
- package/packages/core/src/store/remote/version.ts +3 -1
- package/packages/core/src/store/repo-state-events.ts +3 -1
- package/packages/core/src/store/repo-tick.ts +72 -0
- package/packages/core/src/store/session-handle.ts +34 -0
- package/packages/core/src/store/snapshots.ts +10 -0
- package/packages/core/src/store/subscribe.ts +1 -1
- package/packages/core/src/store/ticket-assets.ts +4 -4
- package/packages/core/src/store/types.ts +71 -6
- package/packages/core/src/testing/dispatch-read-budget.ts +215 -0
- package/packages/core/src/testing/index.ts +10 -0
- package/packages/core/src/testing/reduced-read-budget.ts +502 -0
- package/packages/core/src/testing/refresh-scheduler.ts +32 -0
- package/skills/guide/SKILL.md +116 -62
- package/skills/guide/references/integration-tree.md +117 -0
- package/skills/guide/references/landing-policy.md +150 -0
- package/skills/guide/references/migration-1.0.md +68 -0
- package/skills/guide/references/operator-api.md +13 -6
- package/skills/guide/references/plugin-authoring.md +34 -0
- package/skills/guide/references/remote-store-protocol.md +114 -9
- package/skills/guide/references/remote-ticket-protocol.md +26 -5
- package/skills/guide/references/restacking.md +79 -0
- package/skills/guide/references/setup.md +49 -6
- package/skills/guide/references/ticket-dependencies.md +69 -0
- package/skills/guide/references/ticket-migration.md +8 -0
- package/skills/operate/SKILL.md +55 -5
- package/skills/reconcile/SKILL.md +55 -48
- package/skills/spec/SKILL.md +67 -1
- package/skills/tickets/SKILL.md +55 -2
- package/templates/autobuild.toml +3 -0
- package/templates/hosted-service/package.json +2 -2
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import type { GitHubRequest } from './github-transport'
|
|
3
|
+
import { readinessChecks, type ForgeReadinessCheck, type ForgeReadinessInput } from './readiness'
|
|
4
|
+
|
|
5
|
+
const access =
|
|
6
|
+
'Grant Metadata:read and Administration:read for inspection (classic private repositories: repo scope); Contents:write is separately required for publication.'
|
|
7
|
+
const ruleSchema = z.object({
|
|
8
|
+
type: z.string().min(1),
|
|
9
|
+
ruleset_id: z.number().int().positive().optional(),
|
|
10
|
+
parameters: z.unknown().optional(),
|
|
11
|
+
})
|
|
12
|
+
const rulesetSchema = z.object({
|
|
13
|
+
id: z.number().int(),
|
|
14
|
+
target: z.enum(['branch', 'tag', 'push']),
|
|
15
|
+
enforcement: z.enum(['active', 'disabled', 'evaluate']),
|
|
16
|
+
bypass_actors: z
|
|
17
|
+
.array(
|
|
18
|
+
z.object({
|
|
19
|
+
actor_type: z.string(),
|
|
20
|
+
actor_id: z.number().nullable(),
|
|
21
|
+
bypass_mode: z.enum(['always', 'pull_request', 'exempt']),
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
.optional(),
|
|
25
|
+
conditions: z
|
|
26
|
+
.object({ ref_name: z.object({ include: z.array(z.string()), exclude: z.array(z.string()) }) })
|
|
27
|
+
.optional(),
|
|
28
|
+
rules: z.array(ruleSchema),
|
|
29
|
+
})
|
|
30
|
+
type Ruleset = z.infer<typeof rulesetSchema>
|
|
31
|
+
const classicSchema = z.object({
|
|
32
|
+
pattern: z.string(),
|
|
33
|
+
allowsForcePushes: z.boolean(),
|
|
34
|
+
restrictsPushes: z.boolean(),
|
|
35
|
+
requiresLinearHistory: z.boolean(),
|
|
36
|
+
isAdminEnforced: z.boolean(),
|
|
37
|
+
lockBranch: z.boolean(),
|
|
38
|
+
blocksCreations: z.boolean(),
|
|
39
|
+
requiresApprovingReviews: z.boolean(),
|
|
40
|
+
requiresStatusChecks: z.boolean(),
|
|
41
|
+
requiresCommitSignatures: z.boolean(),
|
|
42
|
+
requiresDeployments: z.boolean(),
|
|
43
|
+
bypassForcePushAllowances: z.object({ totalCount: z.number().int().nonnegative() }),
|
|
44
|
+
})
|
|
45
|
+
type Classic = z.infer<typeof classicSchema>
|
|
46
|
+
type Applicability = 'yes' | 'no' | 'unknown'
|
|
47
|
+
|
|
48
|
+
/** Deliberately small subset of GitHub fnmatch: literals and trailing /**.
|
|
49
|
+
* Everything else stays uncertain; never use a regex approximation as proof. */
|
|
50
|
+
export function patternMatches(pattern: string, name: string, defaultRef: string): Applicability {
|
|
51
|
+
if (pattern === '~ALL') return 'yes'
|
|
52
|
+
if (pattern === '~DEFAULT_BRANCH') return name === defaultRef ? 'yes' : 'no'
|
|
53
|
+
if (!/[?*[\\]/.test(pattern)) return pattern === name ? 'yes' : 'no'
|
|
54
|
+
if (pattern.endsWith('/**') && !/[?*[\\]/.test(pattern.slice(0, -3)))
|
|
55
|
+
return name.startsWith(pattern.slice(0, -2)) ? 'yes' : 'no'
|
|
56
|
+
return 'unknown'
|
|
57
|
+
}
|
|
58
|
+
/** Whether some future name in a namespace can be selected. Literal exceptions
|
|
59
|
+
* inside the namespace count, even when no such ref exists yet. */
|
|
60
|
+
export function patternOverlaps(
|
|
61
|
+
pattern: string,
|
|
62
|
+
prefix: string,
|
|
63
|
+
defaultRef: string,
|
|
64
|
+
): Applicability {
|
|
65
|
+
if (pattern === '~ALL') return 'yes'
|
|
66
|
+
if (pattern === '~DEFAULT_BRANCH') return defaultRef.startsWith(prefix) ? 'yes' : 'no'
|
|
67
|
+
if (!/[?*[\\]/.test(pattern)) return pattern.startsWith(prefix) ? 'yes' : 'no'
|
|
68
|
+
const literal = pattern.split(/[?*[\\]/)[0]!
|
|
69
|
+
if (!prefix.startsWith(literal) && !literal.startsWith(prefix)) return 'no'
|
|
70
|
+
if (pattern.endsWith('/**') && !/[?*[\\]/.test(pattern.slice(0, -3))) return 'yes'
|
|
71
|
+
return 'unknown'
|
|
72
|
+
}
|
|
73
|
+
function any(values: Applicability[]): Applicability {
|
|
74
|
+
return values.includes('yes') ? 'yes' : values.includes('unknown') ? 'unknown' : 'no'
|
|
75
|
+
}
|
|
76
|
+
function applies(
|
|
77
|
+
set: Ruleset,
|
|
78
|
+
value: string,
|
|
79
|
+
defaultRef: string,
|
|
80
|
+
namespace = false,
|
|
81
|
+
): Applicability {
|
|
82
|
+
if (set.target === 'push') return 'yes'
|
|
83
|
+
if (set.target !== 'branch') return 'no'
|
|
84
|
+
if (!set.conditions) return 'unknown'
|
|
85
|
+
const conditions = set.conditions.ref_name
|
|
86
|
+
const match = namespace ? patternOverlaps : patternMatches
|
|
87
|
+
const include = any(conditions.include.map((pattern) => match(pattern, value, defaultRef)))
|
|
88
|
+
if (include === 'no') return 'no'
|
|
89
|
+
if (!namespace) {
|
|
90
|
+
const exclude = any(
|
|
91
|
+
conditions.exclude.map((pattern) => patternMatches(pattern, value, defaultRef)),
|
|
92
|
+
)
|
|
93
|
+
if (exclude === 'yes') return 'no'
|
|
94
|
+
return exclude === 'unknown' ? 'unknown' : include
|
|
95
|
+
}
|
|
96
|
+
// An exclusion of the entire prefix proves disjointness. Partial exclusions
|
|
97
|
+
// cannot prove that all future names are exempt.
|
|
98
|
+
if (conditions.exclude.some((pattern) => pattern === '~ALL' || pattern === `${value}**`))
|
|
99
|
+
return 'no'
|
|
100
|
+
if (conditions.exclude.every((pattern) => patternOverlaps(pattern, value, defaultRef) === 'no'))
|
|
101
|
+
return include
|
|
102
|
+
// Literal exclusions remove finitely many names. A supported recursive
|
|
103
|
+
// include still restricts infinitely many names in the owned namespace.
|
|
104
|
+
const literalExclusions = conditions.exclude.every((pattern) => !/[?*[\\~]/.test(pattern))
|
|
105
|
+
if (literalExclusions) {
|
|
106
|
+
for (const pattern of conditions.include) {
|
|
107
|
+
if (patternOverlaps(pattern, value, defaultRef) !== 'yes') continue
|
|
108
|
+
if (pattern === '~ALL' || pattern.endsWith('/**')) return 'yes'
|
|
109
|
+
const concrete = pattern === '~DEFAULT_BRANCH' ? defaultRef : pattern
|
|
110
|
+
if (
|
|
111
|
+
conditions.exclude.every(
|
|
112
|
+
(exclude) => patternMatches(exclude, concrete, defaultRef) === 'no',
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
return 'yes'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return 'unknown'
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function inspectGitHubReadiness(opts: {
|
|
122
|
+
request: GitHubRequest
|
|
123
|
+
owner: string
|
|
124
|
+
name: string
|
|
125
|
+
input: ForgeReadinessInput
|
|
126
|
+
}): Promise<ForgeReadinessCheck[]> {
|
|
127
|
+
const { request } = opts
|
|
128
|
+
const root = `repos/${encodeURIComponent(opts.owner)}/${encodeURIComponent(opts.name)}`
|
|
129
|
+
const checks = readinessChecks('unknown', `Inspection incomplete. ${access}`)
|
|
130
|
+
const set = (
|
|
131
|
+
key: ForgeReadinessCheck['check'],
|
|
132
|
+
status: ForgeReadinessCheck['status'],
|
|
133
|
+
detail: string,
|
|
134
|
+
) => {
|
|
135
|
+
const check = checks.find((item) => item.check === key)!
|
|
136
|
+
check.status = status
|
|
137
|
+
check.detail = detail
|
|
138
|
+
}
|
|
139
|
+
async function get<T>(
|
|
140
|
+
path: string,
|
|
141
|
+
schema: z.ZodType<T>,
|
|
142
|
+
query?: Record<string, string>,
|
|
143
|
+
): Promise<T> {
|
|
144
|
+
const response = await request('GET', path, query ? { query } : undefined)
|
|
145
|
+
if (response.status < 200 || response.status >= 300) throw new Error('GitHub inspection failed')
|
|
146
|
+
return schema.parse(response.json)
|
|
147
|
+
}
|
|
148
|
+
async function pages<T>(
|
|
149
|
+
path: string,
|
|
150
|
+
schema: z.ZodType<T>,
|
|
151
|
+
query: Record<string, string> = {},
|
|
152
|
+
): Promise<T[]> {
|
|
153
|
+
const result: T[] = []
|
|
154
|
+
for (let page = 1; ; page++) {
|
|
155
|
+
const batch = await get(path, z.array(schema), {
|
|
156
|
+
...query,
|
|
157
|
+
per_page: '100',
|
|
158
|
+
page: String(page),
|
|
159
|
+
})
|
|
160
|
+
result.push(...batch)
|
|
161
|
+
if (batch.length < 100) return result
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
let write: boolean | undefined
|
|
165
|
+
let defaultRef: string | undefined
|
|
166
|
+
try {
|
|
167
|
+
const repo = await get(root, z.record(z.string(), z.unknown()))
|
|
168
|
+
for (const key of ['squash', 'rebase'] as const) {
|
|
169
|
+
const parsed = z.boolean().safeParse(repo[`allow_${key}_merge`])
|
|
170
|
+
if (parsed.success)
|
|
171
|
+
set(key, parsed.data ? 'pass' : 'fail', `GitHub allow_${key}_merge is ${parsed.data}.`)
|
|
172
|
+
}
|
|
173
|
+
const permissions = z.object({ push: z.boolean() }).safeParse(repo.permissions)
|
|
174
|
+
write = permissions.success ? permissions.data.push : undefined
|
|
175
|
+
const branch = z.string().min(1).safeParse(repo.default_branch)
|
|
176
|
+
defaultRef = branch.success ? `refs/heads/${branch.data}` : undefined
|
|
177
|
+
} catch {
|
|
178
|
+
/* Independent policy reads can still provide useful evidence. */
|
|
179
|
+
}
|
|
180
|
+
if (write === false)
|
|
181
|
+
for (const key of ['build-refs', 'node-refs', 'archive-refs'] as const)
|
|
182
|
+
set(
|
|
183
|
+
key,
|
|
184
|
+
'fail',
|
|
185
|
+
'The authenticated forge identity lacks repository push permission; grant Contents:write.',
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
let classic: Classic[] | undefined
|
|
189
|
+
try {
|
|
190
|
+
classic = []
|
|
191
|
+
let cursor: string | null = null
|
|
192
|
+
const seen = new Set<string>()
|
|
193
|
+
for (;;) {
|
|
194
|
+
const response = await request('POST', 'graphql', {
|
|
195
|
+
body: {
|
|
196
|
+
query: `query($owner: String!, $name: String!, $cursor: String) { repository(owner: $owner, name: $name) { branchProtectionRules(first: 100, after: $cursor) { nodes { pattern allowsForcePushes restrictsPushes requiresLinearHistory isAdminEnforced lockBranch blocksCreations requiresApprovingReviews requiresStatusChecks requiresCommitSignatures requiresDeployments bypassForcePushAllowances { totalCount } } pageInfo { hasNextPage endCursor } } } }`,
|
|
197
|
+
variables: { owner: opts.owner, name: opts.name, cursor },
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
if (response.status < 200 || response.status >= 300)
|
|
201
|
+
throw new Error('GraphQL inspection failed')
|
|
202
|
+
const envelope = z
|
|
203
|
+
.object({
|
|
204
|
+
errors: z.array(z.unknown()).optional(),
|
|
205
|
+
data: z
|
|
206
|
+
.object({
|
|
207
|
+
repository: z.object({
|
|
208
|
+
branchProtectionRules: z.object({
|
|
209
|
+
nodes: z.array(classicSchema),
|
|
210
|
+
pageInfo: z.object({
|
|
211
|
+
hasNextPage: z.boolean(),
|
|
212
|
+
endCursor: z.string().nullable(),
|
|
213
|
+
}),
|
|
214
|
+
}),
|
|
215
|
+
}),
|
|
216
|
+
})
|
|
217
|
+
.optional(),
|
|
218
|
+
})
|
|
219
|
+
.parse(response.json)
|
|
220
|
+
if (envelope.errors?.length || !envelope.data) throw new Error('Incomplete classic inventory')
|
|
221
|
+
const connection = envelope.data.repository.branchProtectionRules
|
|
222
|
+
classic.push(...connection.nodes)
|
|
223
|
+
if (!connection.pageInfo.hasNextPage) break
|
|
224
|
+
cursor = connection.pageInfo.endCursor
|
|
225
|
+
if (!cursor || seen.has(cursor)) throw new Error('Incomplete classic pagination')
|
|
226
|
+
seen.add(cursor)
|
|
227
|
+
}
|
|
228
|
+
} catch {
|
|
229
|
+
classic = undefined
|
|
230
|
+
}
|
|
231
|
+
let sets: Ruleset[] | undefined
|
|
232
|
+
try {
|
|
233
|
+
const inventory = await pages(
|
|
234
|
+
`${root}/rulesets`,
|
|
235
|
+
z.object({ id: z.number().int(), enforcement: z.enum(['active', 'disabled', 'evaluate']) }),
|
|
236
|
+
{ includes_parents: 'true' },
|
|
237
|
+
)
|
|
238
|
+
sets = []
|
|
239
|
+
for (const item of inventory) {
|
|
240
|
+
if (item.enforcement !== 'active') continue
|
|
241
|
+
const detail = await get(`${root}/rulesets/${item.id}`, rulesetSchema, {
|
|
242
|
+
includes_parents: 'true',
|
|
243
|
+
})
|
|
244
|
+
if (detail.enforcement === 'active') sets.push(detail)
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
sets = undefined
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
for (const [key, prefix] of [
|
|
251
|
+
['build-refs', 'refs/heads/ab/'],
|
|
252
|
+
['node-refs', 'refs/heads/ab-node/'],
|
|
253
|
+
] as const) {
|
|
254
|
+
if (write === false) continue
|
|
255
|
+
let unknown = write !== true || !classic || !sets || !defaultRef
|
|
256
|
+
let blocked = false
|
|
257
|
+
const details: string[] = []
|
|
258
|
+
if (classic) {
|
|
259
|
+
const overlaps = classic.filter(
|
|
260
|
+
(rule) =>
|
|
261
|
+
patternOverlaps(rule.pattern, prefix.slice(11), defaultRef?.slice(11) ?? '') !== 'no',
|
|
262
|
+
)
|
|
263
|
+
for (const rule of overlaps) {
|
|
264
|
+
const overlap = patternOverlaps(rule.pattern, prefix.slice(11), defaultRef?.slice(11) ?? '')
|
|
265
|
+
if (overlap === 'unknown' || overlaps.length > 1 || rule.restrictsPushes) unknown = true
|
|
266
|
+
else if (!rule.isAdminEnforced || rule.bypassForcePushAllowances.totalCount > 0)
|
|
267
|
+
unknown = true
|
|
268
|
+
else if (!rule.allowsForcePushes || rule.lockBranch) {
|
|
269
|
+
blocked = true
|
|
270
|
+
details.push(
|
|
271
|
+
`Classic protection ${rule.pattern} forbids force pushes or locks publication.`,
|
|
272
|
+
)
|
|
273
|
+
} else if (
|
|
274
|
+
rule.blocksCreations ||
|
|
275
|
+
rule.requiresApprovingReviews ||
|
|
276
|
+
rule.requiresStatusChecks ||
|
|
277
|
+
rule.requiresCommitSignatures ||
|
|
278
|
+
rule.requiresDeployments
|
|
279
|
+
)
|
|
280
|
+
unknown = true
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
for (const rule of sets ?? []) {
|
|
284
|
+
const appliesTo = applies(rule, prefix, defaultRef ?? '', true)
|
|
285
|
+
if (appliesTo === 'no') continue
|
|
286
|
+
// Actor/team/app membership is not inferred from repository write access.
|
|
287
|
+
// PR-only bypasses never authorize a direct push.
|
|
288
|
+
const directBypass = rule.bypass_actors?.some((actor) => actor.bypass_mode !== 'pull_request')
|
|
289
|
+
const restrictions = rule.rules.filter(
|
|
290
|
+
(item) => item.type !== 'deletion' && item.type !== 'required_linear_history',
|
|
291
|
+
)
|
|
292
|
+
if (!restrictions.length) continue
|
|
293
|
+
if (appliesTo === 'unknown' || rule.bypass_actors === undefined || directBypass) {
|
|
294
|
+
unknown = true
|
|
295
|
+
continue
|
|
296
|
+
}
|
|
297
|
+
if (
|
|
298
|
+
restrictions.some((item) =>
|
|
299
|
+
['non_fast_forward', 'update', 'creation', 'pull_request'].includes(item.type),
|
|
300
|
+
)
|
|
301
|
+
) {
|
|
302
|
+
blocked = true
|
|
303
|
+
details.push(`Active ruleset ${rule.id} restricts direct publication or force pushes.`)
|
|
304
|
+
} else unknown = true // Content-dependent and future rule types cannot prove publication.
|
|
305
|
+
}
|
|
306
|
+
set(
|
|
307
|
+
key,
|
|
308
|
+
blocked ? 'fail' : unknown ? 'unknown' : 'pass',
|
|
309
|
+
blocked
|
|
310
|
+
? details.join(' ')
|
|
311
|
+
: unknown
|
|
312
|
+
? `Cannot prove publication and force-push permission throughout ${prefix}. ${access}`
|
|
313
|
+
: `Repository push permission and complete policy inventory permit rewrites throughout ${prefix}.`,
|
|
314
|
+
)
|
|
315
|
+
}
|
|
316
|
+
if (write !== false)
|
|
317
|
+
set(
|
|
318
|
+
'archive-refs',
|
|
319
|
+
'unknown',
|
|
320
|
+
`GitHub branch protection APIs do not establish publication permission for non-head refs/autobuild/archive/. ${access} Manually verify this ref domain without creating or overwriting probe archives.`,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
try {
|
|
324
|
+
// Matching refs returns the complete array and has no pagination parameters.
|
|
325
|
+
// A full response can contain 100+ refs, so the paginated helper would loop.
|
|
326
|
+
const nodes = await get(
|
|
327
|
+
`${root}/git/matching-refs/heads/ab-node/`,
|
|
328
|
+
z.array(z.object({ ref: z.string() })),
|
|
329
|
+
)
|
|
330
|
+
const targets = [
|
|
331
|
+
opts.input.rootBranch,
|
|
332
|
+
...nodes.map((node) => {
|
|
333
|
+
if (!node.ref.startsWith('refs/heads/ab-node/')) throw new Error('Unexpected target ref')
|
|
334
|
+
return node.ref.slice(11)
|
|
335
|
+
}),
|
|
336
|
+
]
|
|
337
|
+
let uncertain = !classic || !sets || !defaultRef
|
|
338
|
+
const missing: string[] = []
|
|
339
|
+
let rootFence: boolean | undefined
|
|
340
|
+
for (const branch of new Set(targets)) {
|
|
341
|
+
const active = await pages(`${root}/rules/branches/${encodeURIComponent(branch)}`, ruleSchema)
|
|
342
|
+
const matches = (classic ?? []).filter(
|
|
343
|
+
(rule) => patternMatches(rule.pattern, branch, defaultRef?.slice(11) ?? '') !== 'no',
|
|
344
|
+
)
|
|
345
|
+
if (
|
|
346
|
+
matches.some(
|
|
347
|
+
(rule) => patternMatches(rule.pattern, branch, defaultRef?.slice(11) ?? '') === 'unknown',
|
|
348
|
+
)
|
|
349
|
+
)
|
|
350
|
+
uncertain = true
|
|
351
|
+
let linear = active.some((rule) => rule.type === 'required_linear_history')
|
|
352
|
+
let protection: z.infer<typeof protectionSchema> | undefined
|
|
353
|
+
if (matches.length) {
|
|
354
|
+
protection = await get(
|
|
355
|
+
`${root}/branches/${encodeURIComponent(branch)}/protection`,
|
|
356
|
+
protectionSchema,
|
|
357
|
+
)
|
|
358
|
+
linear ||= protection.required_linear_history.enabled
|
|
359
|
+
}
|
|
360
|
+
if ((matches.length || active.length) && !linear) missing.push(branch)
|
|
361
|
+
if (branch === opts.input.rootBranch && classic && sets && defaultRef) {
|
|
362
|
+
rootFence = !!(
|
|
363
|
+
protection?.enforce_admins.enabled &&
|
|
364
|
+
protection.required_status_checks?.strict &&
|
|
365
|
+
protection.required_status_checks.contexts.length +
|
|
366
|
+
protection.required_status_checks.checks.length >
|
|
367
|
+
0
|
|
368
|
+
)
|
|
369
|
+
for (const check of active) {
|
|
370
|
+
if (check.type !== 'required_status_checks') continue
|
|
371
|
+
const parameters = z
|
|
372
|
+
.object({
|
|
373
|
+
strict_required_status_checks_policy: z.boolean(),
|
|
374
|
+
required_status_checks: z.array(z.object({ context: z.string() })),
|
|
375
|
+
})
|
|
376
|
+
.safeParse(check.parameters)
|
|
377
|
+
if (!parameters.success) {
|
|
378
|
+
if (rootFence !== true) rootFence = undefined
|
|
379
|
+
continue
|
|
380
|
+
}
|
|
381
|
+
if (
|
|
382
|
+
!parameters.data.strict_required_status_checks_policy ||
|
|
383
|
+
!parameters.data.required_status_checks.length
|
|
384
|
+
)
|
|
385
|
+
continue
|
|
386
|
+
const rule = sets.find((rule) => rule.id === check.ruleset_id)
|
|
387
|
+
if (!rule || rule.bypass_actors === undefined) {
|
|
388
|
+
if (rootFence !== true) rootFence = undefined
|
|
389
|
+
} else if (rule.bypass_actors.length === 0) rootFence = true
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
set(
|
|
394
|
+
'linear-history',
|
|
395
|
+
missing.length ? 'fail' : uncertain ? 'unknown' : 'pass',
|
|
396
|
+
missing.length
|
|
397
|
+
? `Protected targets missing Require linear history: ${missing.join(', ')}.`
|
|
398
|
+
: uncertain
|
|
399
|
+
? `Protected target inventory incomplete. ${access}`
|
|
400
|
+
: 'All protected root/node targets require linear history; unprotected targets impose no recommendation.',
|
|
401
|
+
)
|
|
402
|
+
if (rootFence !== undefined)
|
|
403
|
+
set(
|
|
404
|
+
'root-freshness',
|
|
405
|
+
rootFence ? 'pass' : 'fail',
|
|
406
|
+
rootFence
|
|
407
|
+
? `Root ${opts.input.rootBranch} enforces strict nonempty checks for all actors: fenced landing.`
|
|
408
|
+
: `Root ${opts.input.rootBranch} does not enforce strict nonempty checks for all actors: best-effort landing.`,
|
|
409
|
+
)
|
|
410
|
+
} catch {
|
|
411
|
+
/* No vacuous success on incomplete target or policy reads. */
|
|
412
|
+
}
|
|
413
|
+
return checks
|
|
414
|
+
}
|
|
415
|
+
const protectionSchema = z.object({
|
|
416
|
+
required_linear_history: z.object({ enabled: z.boolean() }),
|
|
417
|
+
enforce_admins: z.object({ enabled: z.boolean() }),
|
|
418
|
+
required_status_checks: z
|
|
419
|
+
.object({ strict: z.boolean(), contexts: z.array(z.string()), checks: z.array(z.unknown()) })
|
|
420
|
+
.nullable(),
|
|
421
|
+
})
|