@attalabs/vinaya 0.44.0 → 0.47.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 +6 -4
- package/dist/checks/bin/check-body-bare-digits.js +262 -201
- package/dist/checks/bin/check-branch-topology.js +70 -23
- package/dist/checks/bin/check-brief-shape.js +262 -201
- package/dist/checks/bin/check-changeset-coverage.js +94 -16
- package/dist/checks/bin/check-ci-shard-coverage.js +3 -0
- package/dist/checks/bin/check-closes-n.js +157 -40
- package/dist/checks/bin/check-coherence.js +365 -251
- package/dist/checks/bin/check-dispatch-readiness.js +3654 -469
- package/dist/checks/bin/check-doc-claims.js +262 -201
- package/dist/checks/bin/check-doc-coverage-push.js +272 -202
- package/dist/checks/bin/check-doc-coverage.js +272 -202
- package/dist/checks/bin/check-doctrine-no-procedures.js +262 -201
- package/dist/checks/bin/check-doctrine-portability.js +262 -201
- package/dist/checks/bin/check-evidence-fresh.js +10138 -2126
- package/dist/checks/bin/check-exec-bits.js +3 -0
- package/dist/checks/bin/check-first-push-dispatch.js +330 -230
- package/dist/checks/bin/check-issue-milestone-attach.js +94 -16
- package/dist/checks/bin/check-issue-objectives-numbering.js +262 -201
- package/dist/checks/bin/check-issue-parts-coverage.js +94 -16
- package/dist/checks/bin/check-issue-surface-globs.js +1062 -242
- package/dist/checks/bin/check-issue-title-grammar.js +21 -5
- package/dist/checks/bin/check-no-disk-state.js +5 -1
- package/dist/checks/bin/check-pr-premise-reassert.js +22 -2
- package/dist/checks/bin/check-pr-report-density.js +5 -1
- package/dist/checks/bin/check-principal-test-plan-wait.js +282 -207
- package/dist/checks/bin/check-quoted-command.js +262 -201
- package/dist/checks/bin/check-reader-resolvable-prose.js +262 -201
- package/dist/checks/bin/check-registry-gates.js +131 -34
- package/dist/checks/bin/check-retired-vocabulary.js +262 -201
- package/dist/checks/bin/check-review-gate.js +262 -201
- package/dist/checks/bin/check-single-plan-pr.js +5 -1
- package/dist/checks/bin/check-surface-scope.js +136 -38
- package/dist/checks/bin/check-test-plan.js +282 -207
- package/dist/checks/bin/check-token-collection-wired.js +3 -0
- package/dist/checks/bin/check-workspace-escape.js +3 -0
- package/dist/checks/bin/verify-coherence.js +237 -148
- package/dist/checks/bin/verify-dispatch.js +870 -66
- package/dist/checks/bin/verify-docs.js +13 -6
- package/dist/harness.js +57 -10
- package/dist/index.js +16670 -7196
- package/dist/lib/pre-push-cache-test-run.js +4488 -2170
- package/dist/lib/pre-push-changed-files.js +251 -12
- package/dist/lib/pre-push-mode.js +69 -19
- package/dist/lib/pre-push-progress-dir.js +10265 -2853
- package/dist/lib/pre-push-record-tests.js +67 -19
- package/dist/lib/pre-push-select-tests.js +520 -222
- package/dist/lib/push-progress-observer.js +9176 -1757
- package/dist/process.js +2 -0
- package/dist/programs/archive.js +8948 -1547
- package/dist/programs/audit.js +9176 -1772
- package/dist/programs/check.js +9248 -1845
- package/dist/programs/commit-msg.js +8984 -1583
- package/dist/programs/dev-review-loop.js +15621 -7626
- package/dist/programs/dispatch.js +9977 -2726
- package/dist/programs/log-emit.js +9011 -1660
- package/dist/programs/log-selftest.js +8908 -1507
- package/dist/programs/log-send.js +9081 -1594
- package/dist/programs/pr-report.js +9477 -1820
- package/dist/programs/pr-snapshot.js +8916 -1515
- package/dist/programs/pr-verify-evidence.js +9482 -1825
- package/dist/programs/pr.js +11773 -4082
- package/dist/programs/review-post.js +11141 -3496
- package/dist/programs/review-status.js +8997 -1533
- package/dist/programs/run-engine.js +22149 -18798
- package/dist/programs/sync.js +9030 -1629
- package/dist/programs/task-brief.js +10234 -1827
- package/dist/programs/task-sweep.js +9267 -1621
- package/dist/programs/task-tools-serve.js +77141 -16659
- package/dist/programs/tokens.js +8966 -1565
- package/dist/programs/waiver.js +8983 -1582
- package/dist/types/harness/kernel/dev-process-socket/loader/load-process.d.ts +1 -1
- package/dist/types/harness/processes/vinaya-strict/tools/legacy-markers.d.ts +8 -0
- package/dist/types/harness/processes/vinaya-strict/tools/task-contract/brief-validation.d.ts +17 -10
- package/dist/types/harness/processes/vinaya-strict/tools/task-contract/objectives.d.ts +5 -6
- package/dist/types/harness/processes/vinaya-strict/tools/task-contract/premise-check.d.ts +14 -0
- package/dist/vinaya-strict/checks/registry.ts +2 -2
- package/dist/vinaya-strict/executing/developer/developer-doctrine-shape.test.ts +8 -0
- package/dist/vinaya-strict/executing/developer/developer-turn-result.ts +1 -1
- package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.test.ts +2 -2
- package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.ts +30 -20
- package/dist/vinaya-strict/executing/developer/reference.md +5 -3
- package/dist/vinaya-strict/integration/config/vinaya-config-section.ts +29 -7
- package/dist/vinaya-strict/integration/policies/vinaya-policies.ts +4 -4
- package/dist/vinaya-strict/integration/process/process-integration.ts +5 -1
- package/dist/vinaya-strict/process.yaml +6 -1
- package/dist/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
- package/dist/vinaya-strict/thinking/plan-reviewer/grants.yaml +19 -0
- package/dist/vinaya-strict/thinking/plan-reviewer/output.schema.json +388 -0
- package/dist/vinaya-strict/thinking/planner/doctrine.md +4 -1
- package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.test.ts +10 -2
- package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts +5 -1
- package/dist/vinaya-strict/thinking/planner/tools/open-issue.test.ts +198 -34
- package/dist/vinaya-strict/thinking/planner/tools/open-issue.ts +120 -193
- package/dist/vinaya-strict/thinking/planner/tools/planner-operations.test.ts +629 -15
- package/dist/vinaya-strict/thinking/planner/tools/planner-operations.ts +726 -62
- package/dist/vinaya-strict/thinking/planner/tools/planner-tools.test.ts +505 -5
- package/dist/vinaya-strict/thinking/planner/tools/planner-tools.ts +636 -21
- package/package.json +3 -2
- package/studio-standalone/apps/vinaya-studio/.next/BUILD_ID +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/build-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/.next/prerender-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.html +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/milestones/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/app/tasks/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/chunks/209.js +2 -2
- package/studio-standalone/apps/vinaya-studio/.next/server/chunks/951.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/middleware-build-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/pages/500.html +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/server/preview-props.json +3 -3
- package/studio-standalone/apps/vinaya-studio/.next/server/server-reference-manifest.json +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-c365f0ef8268ad13.js +1 -0
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/19-aa314f13784dcc58.js +4 -0
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{layout-dfa2186095e797bd.js → layout-f038e8deecb2bf5f.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/milestones/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{page-6ae258f663623b2a.js → page-7a06aa3cdd046fa8.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/tasks/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/css/8eb5ed5b65b9692e.css +1 -0
- package/studio-standalone/apps/vinaya-studio/log-follow.mjs +708 -93
- package/studio-standalone/apps/vinaya-studio/log-sync-folder-source.mjs +699 -84
- package/studio-standalone/apps/vinaya-studio/studio-server.mjs +4692 -3116
- package/vinaya-strict/artifacts/templates/brief-template.md +6 -0
- package/vinaya-strict/artifacts/templates/issue-rationale-template.md +7 -3
- package/vinaya-strict/artifacts/templates/pr-report-template.md +1 -1
- package/vinaya-strict/doctrine/contracts/planner-developer.md +4 -3
- package/vinaya-strict/doctrine/enforcement.md +4 -4
- package/vinaya-strict/doctrine/roles/principal.md +1 -1
- package/vinaya-strict/doctrine/state-machine.md +7 -2
- package/vinaya-strict/executing/developer/reference.md +5 -3
- package/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
- package/vinaya-strict/thinking/planner/doctrine.md +4 -1
- package/vinaya-strict/thinking/planner/reference.md +30 -9
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-23bea4cac9687151.js +0 -1
- package/studio-standalone/apps/vinaya-studio/.next/static/chunks/853-1d5548ff3a55a75f.js +0 -4
- package/studio-standalone/apps/vinaya-studio/.next/static/css/fb16828fc3128d4c.css +0 -1
- /package/studio-standalone/apps/vinaya-studio/.next/static/{_r9iZDxlkoek85d_3oaxL → bJrgAp9Kl4JsCUYkeAYez}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/.next/static/{_r9iZDxlkoek85d_3oaxL → bJrgAp9Kl4JsCUYkeAYez}/_ssgManifest.js +0 -0
|
@@ -1,15 +1,35 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
1
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { tmpdir } from 'node:os'
|
|
3
3
|
import { join } from 'node:path'
|
|
4
4
|
import { describe, expect, it } from 'vitest'
|
|
5
|
-
import {
|
|
5
|
+
import { draftFingerprint, type PlanDraft } from '@harness/workflow/tools/plan-draft/draft'
|
|
6
|
+
import { publishedIssueOf } from '@harness/workflow/tools/plan-draft/preview'
|
|
7
|
+
import { readPlanDraft, writePlanDraft } from '@harness/workflow/tools/plan-draft/store'
|
|
8
|
+
import {
|
|
9
|
+
emptyReviewState,
|
|
10
|
+
planReviewStatus,
|
|
11
|
+
taskHash,
|
|
12
|
+
writeReviewState
|
|
13
|
+
} from '@harness/workflow/tools/plan-review/coordinator'
|
|
14
|
+
import {
|
|
15
|
+
captureRefusal,
|
|
16
|
+
checkDocumentationSourcesDeliverable,
|
|
17
|
+
documentationEditMarkerPrefixes,
|
|
18
|
+
makeCheckError,
|
|
19
|
+
objectivesVersionMarkerPrefixes,
|
|
20
|
+
refuse
|
|
21
|
+
} from '@harness/workflow/tools/task-contract/forge/forge-write'
|
|
6
22
|
import {
|
|
7
23
|
type ObjectivesDeps,
|
|
8
24
|
type PlannerForge,
|
|
9
25
|
createIssue,
|
|
26
|
+
editDocumentation,
|
|
10
27
|
editIssue,
|
|
11
28
|
editObjectives,
|
|
12
29
|
printIssueSurface,
|
|
30
|
+
publishApprovedTasks,
|
|
31
|
+
publishedIssueDrift,
|
|
32
|
+
readStoredPlanReviewStatusWithDrift,
|
|
13
33
|
renderBrief
|
|
14
34
|
} from './planner-operations'
|
|
15
35
|
|
|
@@ -61,13 +81,25 @@ const createArgs = (file: string) => [
|
|
|
61
81
|
file
|
|
62
82
|
]
|
|
63
83
|
|
|
84
|
+
const plainArgs = (file: string) => ['--title', 'A backlog Issue', '--body-file', file]
|
|
85
|
+
|
|
64
86
|
describe('createIssue', () => {
|
|
65
|
-
it('
|
|
87
|
+
it('refuses a tranche-labelled create, naming plan_publish, and writes nothing', async () => {
|
|
66
88
|
const forge = stubForge()
|
|
67
89
|
const out = await withBody('body', (f) => createIssue({ ghArgs: createArgs(f) }, {}, forge))
|
|
90
|
+
expect(out.ok).toBe(false)
|
|
91
|
+
if (!out.ok) {
|
|
92
|
+
expect(out.findings.map((e) => e.check)).toEqual(['plan-publish-only'])
|
|
93
|
+
expect(out.findings[0]?.message).toContain('plan_publish')
|
|
94
|
+
}
|
|
95
|
+
expect(forge.calls).toEqual([])
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('writes a create that carries no tranche label, as before', async () => {
|
|
99
|
+
const forge = stubForge()
|
|
100
|
+
const out = await withBody('body', (f) => createIssue({ ghArgs: plainArgs(f) }, {}, forge))
|
|
68
101
|
expect(out).toMatchObject({ ok: true, written: true, url: 'https://example.test/issues/7' })
|
|
69
|
-
expect(forge.calls[0]).
|
|
70
|
-
expect(forge.calls[1]).toContain('--milestone M')
|
|
102
|
+
expect(forge.calls[0]).toContain('gh issue create')
|
|
71
103
|
})
|
|
72
104
|
|
|
73
105
|
it('validate-only runs the gates and writes nothing', async () => {
|
|
@@ -92,7 +124,7 @@ describe('createIssue', () => {
|
|
|
92
124
|
const seen: string[] = []
|
|
93
125
|
const forge = stubForge({ validate: async () => ({ errors: [warning], blocking: false, renderSkipped: null }) })
|
|
94
126
|
const out = await withBody('body', (f) =>
|
|
95
|
-
createIssue({ ghArgs: createArgs(f) }, { warning: (e) => seen.push(e.check) }, forge)
|
|
127
|
+
createIssue({ ghArgs: createArgs(f), validateOnly: true }, { warning: (e) => seen.push(e.check) }, forge)
|
|
96
128
|
)
|
|
97
129
|
expect(out.ok).toBe(true)
|
|
98
130
|
expect(seen).toEqual(['depends-on'])
|
|
@@ -104,17 +136,10 @@ describe('createIssue', () => {
|
|
|
104
136
|
if (!out.ok) expect(out.findings[0]?.check).toBe('forge-args')
|
|
105
137
|
})
|
|
106
138
|
|
|
107
|
-
it('returns the tranche-label failure as a finding, before the write', async () => {
|
|
108
|
-
const forge = stubForge({ ensureTrancheLabel: () => [finding('forge-fetch')] })
|
|
109
|
-
const out = await withBody('body', (f) => createIssue({ ghArgs: createArgs(f) }, {}, forge))
|
|
110
|
-
expect(out.ok).toBe(false)
|
|
111
|
-
expect(forge.calls).toEqual([])
|
|
112
|
-
})
|
|
113
|
-
|
|
114
139
|
it('returns a failed gh write as a refusal carrying the raw error', async () => {
|
|
115
140
|
const boom = new Error('gh exploded')
|
|
116
141
|
const forge = stubForge({ ghWrite: () => ({ ok: false, errors: [finding('forge-write')], cause: boom }) })
|
|
117
|
-
const out = await withBody('body', (f) => createIssue({ ghArgs:
|
|
142
|
+
const out = await withBody('body', (f) => createIssue({ ghArgs: plainArgs(f) }, {}, forge))
|
|
118
143
|
expect(out.ok).toBe(false)
|
|
119
144
|
if (!out.ok) {
|
|
120
145
|
expect(out.forgeError).toBe(boom)
|
|
@@ -250,6 +275,26 @@ describe('editObjectives with a stubbed forge', () => {
|
|
|
250
275
|
|
|
251
276
|
const addArgs = ['7', '--add', 'Second thing.', '--part', 'Part 2 (O2) — does more', '--reason', 'because']
|
|
252
277
|
|
|
278
|
+
it('skips the frozen-section check for its own write and posts the next comment on an Issue already carrying one', async () => {
|
|
279
|
+
const skips: boolean[] = []
|
|
280
|
+
const prior = {
|
|
281
|
+
body: `${objectivesVersionMarkerPrefixes()[0]}1 -->\nVersion: old`,
|
|
282
|
+
url: 'https://example.test/c/1',
|
|
283
|
+
author: 'someone'
|
|
284
|
+
}
|
|
285
|
+
const deps = stubDeps({
|
|
286
|
+
fetchIssue: () => ({ number: 7, body: issueBody, title: '[demo] 1 — A task', labels: [], comments: [prior] })
|
|
287
|
+
})
|
|
288
|
+
deps.forgeStub.frozenSectionChange = (_ref, _body, _retry, skip) => {
|
|
289
|
+
skips.push(skip === true)
|
|
290
|
+
return skip === true ? [] : [finding('issue-objectives-edit')]
|
|
291
|
+
}
|
|
292
|
+
const out = await editObjectives(addArgs, {}, deps)
|
|
293
|
+
expect(out).toMatchObject({ ok: true, url: 'https://example.test/comment' })
|
|
294
|
+
expect(skips).toEqual([true])
|
|
295
|
+
expect(deps.posted).toEqual([`${objectivesVersionMarkerPrefixes()[0]}2 -->`])
|
|
296
|
+
})
|
|
297
|
+
|
|
253
298
|
it('passes: writes the Issue, posts the audit comment and returns the link', async () => {
|
|
254
299
|
const deps = stubDeps()
|
|
255
300
|
const out = await editObjectives(addArgs, {}, deps)
|
|
@@ -289,6 +334,51 @@ describe('editObjectives with a stubbed forge', () => {
|
|
|
289
334
|
expect(deps.posted).toEqual([])
|
|
290
335
|
})
|
|
291
336
|
|
|
337
|
+
/** A frozen brief on the Issue, so the edit supersedes it; and a forge that records each body it writes. */
|
|
338
|
+
function frozenDeps(over: Partial<ObjectivesDeps> & { failRestore?: boolean } = {}) {
|
|
339
|
+
const bodies: string[] = []
|
|
340
|
+
const forge = stubForge({
|
|
341
|
+
ghWrite: (_cmd, args) => {
|
|
342
|
+
bodies.push(readFileSync(args[args.indexOf('--body-file') + 1] as string, 'utf8'))
|
|
343
|
+
if (over.failRestore && bodies.length > 1)
|
|
344
|
+
return { ok: false as const, errors: [finding('forge-write')], cause: undefined }
|
|
345
|
+
return { ok: true as const, url: 'https://example.test/issues/7' }
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
const deps = stubDeps({
|
|
349
|
+
forge,
|
|
350
|
+
fetchIssue: () => ({
|
|
351
|
+
number: 7,
|
|
352
|
+
body: issueBody,
|
|
353
|
+
title: '[demo] 1 — A task',
|
|
354
|
+
labels: ['vinaya/tranche:demo'],
|
|
355
|
+
comments: [{ body: '<!-- vinaya:brief:v1 -->\nBrief hash: abc\nold brief', author: 'someone' }] as never
|
|
356
|
+
}),
|
|
357
|
+
supersede: (async () => {
|
|
358
|
+
throw new Error('supersede refused')
|
|
359
|
+
}) as never,
|
|
360
|
+
...over
|
|
361
|
+
})
|
|
362
|
+
return { deps, bodies }
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
it('puts the previous Issue body back and posts no comment when the supersede fails', async () => {
|
|
366
|
+
const { deps, bodies } = frozenDeps()
|
|
367
|
+
await expect(editObjectives(addArgs, {}, deps)).rejects.toThrow('supersede refused')
|
|
368
|
+
expect(bodies).toHaveLength(2)
|
|
369
|
+
expect(bodies[0]).toContain('O2. Second thing.')
|
|
370
|
+
expect(bodies[1]).toBe(issueBody)
|
|
371
|
+
expect(deps.posted).toEqual([])
|
|
372
|
+
})
|
|
373
|
+
|
|
374
|
+
it('names both failures when the restore after a failed supersede also fails', async () => {
|
|
375
|
+
const { deps } = frozenDeps({ failRestore: true })
|
|
376
|
+
await expect(editObjectives(addArgs, {}, deps)).rejects.toThrow(
|
|
377
|
+
/supersede refused[\s\S]*Restoring Issue 7's previous body also failed/
|
|
378
|
+
)
|
|
379
|
+
expect(deps.posted).toEqual([])
|
|
380
|
+
})
|
|
381
|
+
|
|
292
382
|
it('returns a failed comment post as findings', async () => {
|
|
293
383
|
const deps = stubDeps({ postComment: () => refuse([finding('forge-comment')]) })
|
|
294
384
|
const out = await editObjectives(addArgs, {}, deps)
|
|
@@ -297,6 +387,219 @@ describe('editObjectives with a stubbed forge', () => {
|
|
|
297
387
|
})
|
|
298
388
|
})
|
|
299
389
|
|
|
390
|
+
describe('editDocumentation with a stubbed forge', () => {
|
|
391
|
+
const surface = ['## Surface', '', 'in: apps/cli/src/lib', 'out: apps/cli/src/commands'].join('\n')
|
|
392
|
+
const issueBody = [
|
|
393
|
+
'## Objectives',
|
|
394
|
+
'',
|
|
395
|
+
'O1. First thing.',
|
|
396
|
+
'',
|
|
397
|
+
surface,
|
|
398
|
+
'',
|
|
399
|
+
'## Parts',
|
|
400
|
+
'',
|
|
401
|
+
'Part 1 (O1) — does it',
|
|
402
|
+
'',
|
|
403
|
+
'## Documentation',
|
|
404
|
+
'',
|
|
405
|
+
'- `a/old.md` — what it governs (O1)',
|
|
406
|
+
'',
|
|
407
|
+
'## Test plan',
|
|
408
|
+
'',
|
|
409
|
+
'unit-tests-only',
|
|
410
|
+
''
|
|
411
|
+
].join('\n')
|
|
412
|
+
const newSection = '- `a/new.md` — what it governs (O1)'
|
|
413
|
+
const frozenComment = { body: '<!-- vinaya:brief:v1 -->\nBrief hash: abc\nold brief', url: 'u', author: 'someone' }
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* A frozen task Issue, a forge that records each body it writes and each
|
|
417
|
+
* body the gate is run on, and a gate that refuses a Documentation line a
|
|
418
|
+
* run could not match, with the write gate's own one-source rule.
|
|
419
|
+
*/
|
|
420
|
+
function documentationDeps(over: Partial<ObjectivesDeps> & { failRestore?: boolean; comments?: unknown[] } = {}) {
|
|
421
|
+
const bodies: string[] = []
|
|
422
|
+
const gated: string[] = []
|
|
423
|
+
const supersedes: unknown[] = []
|
|
424
|
+
const posted: { marker: string; body: string }[] = []
|
|
425
|
+
const forge = stubForge({
|
|
426
|
+
validate: async (body) => {
|
|
427
|
+
gated.push(body as string)
|
|
428
|
+
const r = checkDocumentationSourcesDeliverable(body as string)
|
|
429
|
+
return {
|
|
430
|
+
errors: r.errors.map((m) => makeCheckError('issue-content', m, 'fix it')),
|
|
431
|
+
blocking: r.status === 'fail',
|
|
432
|
+
renderSkipped: null
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
ghWrite: (_cmd, args) => {
|
|
436
|
+
bodies.push(readFileSync(args[args.indexOf('--body-file') + 1] as string, 'utf8'))
|
|
437
|
+
if (over.failRestore && bodies.length > 1)
|
|
438
|
+
return { ok: false as const, errors: [finding('forge-write')], cause: undefined }
|
|
439
|
+
return { ok: true as const, url: 'https://example.test/issues/7' }
|
|
440
|
+
}
|
|
441
|
+
})
|
|
442
|
+
const deps: ObjectivesDeps = {
|
|
443
|
+
forge,
|
|
444
|
+
requirePrincipal: () => {},
|
|
445
|
+
resolvePrincipals: () => ['someone'],
|
|
446
|
+
fetchIssue: () => ({
|
|
447
|
+
number: 7,
|
|
448
|
+
body: issueBody,
|
|
449
|
+
title: '[demo] 1 — A task',
|
|
450
|
+
labels: ['vinaya/tranche:demo'],
|
|
451
|
+
comments: (over.comments ?? [frozenComment]) as never
|
|
452
|
+
}),
|
|
453
|
+
supersede: (async (input: unknown) => {
|
|
454
|
+
supersedes.push(input)
|
|
455
|
+
return { commentUrl: 'https://example.test/brief-v2' }
|
|
456
|
+
}) as never,
|
|
457
|
+
postComment: (_kind, _ref, marker, body) => {
|
|
458
|
+
posted.push({ marker, body })
|
|
459
|
+
return 'https://example.test/record'
|
|
460
|
+
},
|
|
461
|
+
...over
|
|
462
|
+
}
|
|
463
|
+
return { deps, bodies, gated, supersedes, posted }
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
const input = (over: Partial<{ documentation: string; reason: string }> = {}) => ({
|
|
467
|
+
issue: 7,
|
|
468
|
+
documentation: newSection,
|
|
469
|
+
reason: 'the source moved',
|
|
470
|
+
...over
|
|
471
|
+
})
|
|
472
|
+
const marker = `${documentationEditMarkerPrefixes()[0]}`
|
|
473
|
+
|
|
474
|
+
it('writes the given section through the gate, leaves every other section, supersedes and posts one record', async () => {
|
|
475
|
+
const { deps, bodies, gated, supersedes, posted } = documentationDeps()
|
|
476
|
+
const out = await editDocumentation(input(), {}, deps)
|
|
477
|
+
expect(out).toEqual({
|
|
478
|
+
ok: true,
|
|
479
|
+
briefUrl: 'https://example.test/brief-v2',
|
|
480
|
+
recordUrl: 'https://example.test/record'
|
|
481
|
+
})
|
|
482
|
+
expect(bodies).toEqual([issueBody.replace('- `a/old.md` — what it governs (O1)', newSection)])
|
|
483
|
+
expect(gated).toEqual(bodies)
|
|
484
|
+
expect(supersedes).toEqual([{ tranche: 'demo', n: 1, supersede: { reason: 'the source moved' } }])
|
|
485
|
+
expect(posted).toEqual([
|
|
486
|
+
{
|
|
487
|
+
marker: `${marker}1 -->`,
|
|
488
|
+
body: [
|
|
489
|
+
'Previous:',
|
|
490
|
+
'- `a/old.md` — what it governs (O1)',
|
|
491
|
+
'',
|
|
492
|
+
'Now:',
|
|
493
|
+
newSection,
|
|
494
|
+
'',
|
|
495
|
+
'Reason: the source moved'
|
|
496
|
+
].join('\n')
|
|
497
|
+
}
|
|
498
|
+
])
|
|
499
|
+
expect(marker).not.toBe(objectivesVersionMarkerPrefixes()[0])
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
it('accepts the section with its heading and numbers the record after an earlier one', async () => {
|
|
503
|
+
const earlier = { body: `${marker}1 -->\nPrevious:`, url: 'r1', author: 'someone' }
|
|
504
|
+
const { deps, bodies, posted } = documentationDeps({ comments: [frozenComment, earlier] })
|
|
505
|
+
const out = await editDocumentation(input({ documentation: `## Documentation\n\n${newSection}\n` }), {}, deps)
|
|
506
|
+
expect(out.ok).toBe(true)
|
|
507
|
+
expect(bodies[0]).toContain(`## Documentation\n\n${newSection}\n\n## Test plan`)
|
|
508
|
+
expect(posted[0]?.marker).toBe(`${marker}2 -->`)
|
|
509
|
+
})
|
|
510
|
+
|
|
511
|
+
it('checks the Principal before the Issue is read', async () => {
|
|
512
|
+
let fetched = false
|
|
513
|
+
const { deps, bodies, posted } = documentationDeps({
|
|
514
|
+
requirePrincipal: () => refuse([finding('principal-only')]),
|
|
515
|
+
fetchIssue: () => {
|
|
516
|
+
fetched = true
|
|
517
|
+
throw new Error('unreachable')
|
|
518
|
+
}
|
|
519
|
+
})
|
|
520
|
+
const out = await editDocumentation(input(), {}, deps)
|
|
521
|
+
expect(out.ok).toBe(false)
|
|
522
|
+
if (!out.ok) expect(out.findings[0]?.check).toBe('principal-only')
|
|
523
|
+
expect(fetched).toBe(false)
|
|
524
|
+
expect(bodies).toEqual([])
|
|
525
|
+
expect(posted).toEqual([])
|
|
526
|
+
})
|
|
527
|
+
|
|
528
|
+
it('refuses an Issue with no frozen brief and names the ordinary Issue edit', async () => {
|
|
529
|
+
const { deps, bodies, supersedes, posted } = documentationDeps({ comments: [] })
|
|
530
|
+
const out = await editDocumentation(input(), {}, deps)
|
|
531
|
+
expect(out.ok).toBe(false)
|
|
532
|
+
if (!out.ok) {
|
|
533
|
+
expect(out.findings[0]?.check).toBe('documentation-not-frozen')
|
|
534
|
+
expect(out.findings[0]?.agent_recovery_prompt).toContain('task_issue_edit')
|
|
535
|
+
}
|
|
536
|
+
expect([bodies, supersedes, posted]).toEqual([[], [], []])
|
|
537
|
+
})
|
|
538
|
+
|
|
539
|
+
it('refuses an empty reason and a reason on two lines', async () => {
|
|
540
|
+
for (const reason of [' ', 'first line\nsecond line']) {
|
|
541
|
+
const { deps, bodies, supersedes, posted } = documentationDeps()
|
|
542
|
+
const out = await editDocumentation(input({ reason }), {}, deps)
|
|
543
|
+
expect(out.ok).toBe(false)
|
|
544
|
+
if (!out.ok) expect(out.findings[0]?.check).toBe('forge-args')
|
|
545
|
+
expect([bodies, supersedes, posted]).toEqual([[], [], []])
|
|
546
|
+
}
|
|
547
|
+
})
|
|
548
|
+
|
|
549
|
+
it('refuses a section the write gate refuses: a line with two code-spanned paths', async () => {
|
|
550
|
+
const { deps, bodies, gated, supersedes, posted } = documentationDeps()
|
|
551
|
+
const out = await editDocumentation(
|
|
552
|
+
input({ documentation: '- `a/one.md` and `a/two.md` — what they govern (O1)' }),
|
|
553
|
+
{},
|
|
554
|
+
deps
|
|
555
|
+
)
|
|
556
|
+
expect(out.ok).toBe(false)
|
|
557
|
+
if (!out.ok) expect(out.findings[0]?.message).toContain('own line')
|
|
558
|
+
expect(gated).toHaveLength(1)
|
|
559
|
+
expect([bodies, supersedes, posted]).toEqual([[], [], []])
|
|
560
|
+
})
|
|
561
|
+
|
|
562
|
+
it('refuses a section that would change another frozen section', async () => {
|
|
563
|
+
const { deps, bodies, posted } = documentationDeps()
|
|
564
|
+
const out = await editDocumentation(input({ documentation: `${newSection}\n## Surface\n\nin: x` }), {}, deps)
|
|
565
|
+
expect(out.ok).toBe(false)
|
|
566
|
+
expect([bodies, posted]).toEqual([[], []])
|
|
567
|
+
})
|
|
568
|
+
|
|
569
|
+
it('refuses a section that equals the one the Issue holds', async () => {
|
|
570
|
+
const { deps, bodies, posted } = documentationDeps()
|
|
571
|
+
const out = await editDocumentation(input({ documentation: '- `a/old.md` — what it governs (O1)' }), {}, deps)
|
|
572
|
+
expect(out.ok).toBe(false)
|
|
573
|
+
expect([bodies, posted]).toEqual([[], []])
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
it('puts the previous Issue body back and posts no record when the supersede fails', async () => {
|
|
577
|
+
const { deps, bodies, posted } = documentationDeps({
|
|
578
|
+
supersede: (async () => {
|
|
579
|
+
throw new Error('supersede refused')
|
|
580
|
+
}) as never
|
|
581
|
+
})
|
|
582
|
+
await expect(editDocumentation(input(), {}, deps)).rejects.toThrow('supersede refused')
|
|
583
|
+
expect(bodies).toHaveLength(2)
|
|
584
|
+
expect(bodies[0]).toContain(newSection)
|
|
585
|
+
expect(bodies[1]).toBe(issueBody)
|
|
586
|
+
expect(posted).toEqual([])
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
it('names both failures when the restore after a failed supersede also fails', async () => {
|
|
590
|
+
const { deps, posted } = documentationDeps({
|
|
591
|
+
failRestore: true,
|
|
592
|
+
supersede: (async () => {
|
|
593
|
+
throw new Error('supersede refused')
|
|
594
|
+
}) as never
|
|
595
|
+
})
|
|
596
|
+
await expect(editDocumentation(input(), {}, deps)).rejects.toThrow(
|
|
597
|
+
/supersede refused[\s\S]*Restoring Issue 7's previous body also failed[\s\S]*Documentation section/
|
|
598
|
+
)
|
|
599
|
+
expect(posted).toEqual([])
|
|
600
|
+
})
|
|
601
|
+
})
|
|
602
|
+
|
|
300
603
|
describe('refusal capture is fail-closed', () => {
|
|
301
604
|
it('turns a refusal deep in awaited work into findings, never a pass', async () => {
|
|
302
605
|
const r = await captureRefusal(async () => {
|
|
@@ -338,7 +641,33 @@ describe('renderBrief with a stubbed assembler', () => {
|
|
|
338
641
|
ok: true,
|
|
339
642
|
brief: 'BRIEF'
|
|
340
643
|
})) as never)
|
|
341
|
-
expect(out).toEqual({ ok: true, brief: 'BRIEF' })
|
|
644
|
+
expect(out).toEqual({ ok: true, brief: 'BRIEF', waiting: [] })
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
it('asks the tranche assembly for a preview and returns the waiting reasons beside the brief', async () => {
|
|
648
|
+
const seen: unknown[] = []
|
|
649
|
+
const out = await renderBrief({ trancheSlug: 't', taskId: '2', globs: ['g'] }, (async (...args: unknown[]) => {
|
|
650
|
+
seen.push(args)
|
|
651
|
+
return { ok: true, brief: 'BRIEF', issue: 5, waiting: ['depends on 1'] }
|
|
652
|
+
}) as never)
|
|
653
|
+
expect(out).toEqual({ ok: true, brief: 'BRIEF', waiting: ['depends on 1'] })
|
|
654
|
+
expect(seen).toEqual([['t', '2', ['g'], undefined, { preview: true }]])
|
|
655
|
+
})
|
|
656
|
+
|
|
657
|
+
it('renders a single Issue by its number alone through the Issue assembly, asking for a preview', async () => {
|
|
658
|
+
const seen: unknown[] = []
|
|
659
|
+
const out = await renderBrief(
|
|
660
|
+
{ issue: 42 },
|
|
661
|
+
(async () => {
|
|
662
|
+
throw new Error('the tranche assembly must not run')
|
|
663
|
+
}) as never,
|
|
664
|
+
(async (...args: unknown[]) => {
|
|
665
|
+
seen.push(args)
|
|
666
|
+
return { ok: true, brief: 'ISSUE BRIEF', issue: 42, waiting: [] }
|
|
667
|
+
}) as never
|
|
668
|
+
)
|
|
669
|
+
expect(out).toEqual({ ok: true, brief: 'ISSUE BRIEF', waiting: [] })
|
|
670
|
+
expect(seen).toEqual([[42, undefined, { preview: true }]])
|
|
342
671
|
})
|
|
343
672
|
|
|
344
673
|
it('returns the missing facts as a refusal', async () => {
|
|
@@ -357,3 +686,288 @@ describe('renderBrief with a stubbed assembler', () => {
|
|
|
357
686
|
).rejects.toThrow('forge down')
|
|
358
687
|
})
|
|
359
688
|
})
|
|
689
|
+
|
|
690
|
+
describe('publishApprovedTasks', () => {
|
|
691
|
+
const REVISION = 'a'.repeat(40)
|
|
692
|
+
const TRANCHE = 'demo'
|
|
693
|
+
const rationale = (edges: string) => `Boundary.\n\n**Dependency rationale** — ${edges}\n\n**Next** — x`
|
|
694
|
+
const plan = (): PlanDraft => ({
|
|
695
|
+
schemaVersion: 1,
|
|
696
|
+
tranche: TRANCHE,
|
|
697
|
+
revision: REVISION,
|
|
698
|
+
reviewQuestionVersion: 'q1',
|
|
699
|
+
tasks: [
|
|
700
|
+
{ number: 1, issue: null, title: 'First', body: rationale('`Depends-on: —`'), labels: ['b'] },
|
|
701
|
+
{ number: 2, issue: null, title: 'Second', body: rationale('`Depends-on: 1`'), labels: [] },
|
|
702
|
+
{ number: 3, issue: null, title: 'Third', body: rationale('`Depends-on: 2`'), labels: [] }
|
|
703
|
+
],
|
|
704
|
+
scope: [{ item: 'Alpha', disposition: { kind: 'delivered', task: 1 } }]
|
|
705
|
+
})
|
|
706
|
+
|
|
707
|
+
let dir = ''
|
|
708
|
+
const setup = (
|
|
709
|
+
approvedTasks: number[] = [1, 2, 3],
|
|
710
|
+
stored: PlanDraft = plan(),
|
|
711
|
+
principal: string | null = draftFingerprint(stored)
|
|
712
|
+
) => {
|
|
713
|
+
dir = mkdtempSync(join(tmpdir(), 'plan-publish-'))
|
|
714
|
+
writePlanDraft(dir, stored)
|
|
715
|
+
const round = {
|
|
716
|
+
round: 1,
|
|
717
|
+
fingerprint: draftFingerprint(stored),
|
|
718
|
+
agent: 'codex' as const,
|
|
719
|
+
scope: null,
|
|
720
|
+
review: {
|
|
721
|
+
schemaVersion: 1 as const,
|
|
722
|
+
draftFingerprint: draftFingerprint(stored),
|
|
723
|
+
questionVersion: 'q1',
|
|
724
|
+
revision: REVISION,
|
|
725
|
+
summary: 'reviewed',
|
|
726
|
+
answers: [],
|
|
727
|
+
findings: [],
|
|
728
|
+
confirmations: []
|
|
729
|
+
},
|
|
730
|
+
verdict: 'approved' as const,
|
|
731
|
+
approvedTasks,
|
|
732
|
+
taskHashes: Object.fromEntries(stored.tasks.map((t) => [String(t.number), taskHash(t)]))
|
|
733
|
+
}
|
|
734
|
+
writeReviewState(dir, {
|
|
735
|
+
...emptyReviewState(TRANCHE),
|
|
736
|
+
rounds: [round],
|
|
737
|
+
approvals: principal === null ? [] : [{ fingerprint: principal, afterRounds: 1 }]
|
|
738
|
+
})
|
|
739
|
+
return { runtimeDir: dir, readDraft: (t: string) => readPlanDraft(dir, t), roundLimit: 2 }
|
|
740
|
+
}
|
|
741
|
+
const cleanup = () => rmSync(dir, { recursive: true, force: true })
|
|
742
|
+
|
|
743
|
+
/** A forge that records each Issue written (title, body, labels) and each gate call, and numbers the Issues from 101. */
|
|
744
|
+
function recordingForge(over: Partial<PlannerForge> = {}) {
|
|
745
|
+
const written: { title: string; body: string; labels: string[] }[] = []
|
|
746
|
+
const gated: { draftTasks: unknown; body: string | null }[] = []
|
|
747
|
+
const forge = stubForge({
|
|
748
|
+
validate: async (body, _title, _labels, _retry, _n, _src, draftTasks) => {
|
|
749
|
+
gated.push({ draftTasks, body })
|
|
750
|
+
return { errors: [], blocking: false, renderSkipped: null }
|
|
751
|
+
},
|
|
752
|
+
ghWrite: (_cmd, args) => {
|
|
753
|
+
const at = (flag: string) => args.indexOf(flag)
|
|
754
|
+
written.push({
|
|
755
|
+
title: args[at('--title') + 1] as string,
|
|
756
|
+
body: readFileSync(args[at('--body-file') + 1] as string, 'utf8'),
|
|
757
|
+
labels: args.flatMap((a, i) => (a === '--label' ? [args[i + 1] as string] : []))
|
|
758
|
+
})
|
|
759
|
+
return { ok: true as const, url: `https://example.test/issues/${100 + written.length}` }
|
|
760
|
+
},
|
|
761
|
+
...over
|
|
762
|
+
})
|
|
763
|
+
return { forge, written, gated }
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
it('writes each approved task as its preview Issue in task order and records the numbers, keeping the approval', async () => {
|
|
767
|
+
const deps = setup()
|
|
768
|
+
const { forge, written, gated } = recordingForge()
|
|
769
|
+
const before = plan()
|
|
770
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
771
|
+
expect(out.ok).toBe(true)
|
|
772
|
+
if (!out.ok) return
|
|
773
|
+
expect(out.tasks.map((t) => [t.task, t.issue, t.alreadyPublished])).toEqual([
|
|
774
|
+
[1, 101, false],
|
|
775
|
+
[2, 102, false],
|
|
776
|
+
[3, 103, false]
|
|
777
|
+
])
|
|
778
|
+
expect(out.tasks[0]?.url).toBe('https://example.test/issues/101')
|
|
779
|
+
expect(written).toEqual(before.tasks.map((t) => publishedIssueOf(before, t)))
|
|
780
|
+
// a bare `Depends-on: 1` reaches the gate with the draft's whole task list
|
|
781
|
+
expect(gated).toHaveLength(3)
|
|
782
|
+
expect(gated[1]?.draftTasks).toEqual([
|
|
783
|
+
{ id: '1', issue: 101 },
|
|
784
|
+
{ id: '2', issue: null },
|
|
785
|
+
{ id: '3', issue: null }
|
|
786
|
+
])
|
|
787
|
+
const stored = readPlanDraft(dir, TRANCHE) as PlanDraft
|
|
788
|
+
expect(stored.tasks.map((t) => t.issue)).toEqual([101, 102, 103])
|
|
789
|
+
const status = planReviewStatus(deps, TRANCHE)
|
|
790
|
+
expect(status.ok && status.status.approved).toBe(true)
|
|
791
|
+
expect(status.ok && status.status.approvedTasks).toEqual([1, 2, 3])
|
|
792
|
+
cleanup()
|
|
793
|
+
})
|
|
794
|
+
|
|
795
|
+
it('writes only the named approved tasks', async () => {
|
|
796
|
+
const deps = setup()
|
|
797
|
+
const { forge, written } = recordingForge()
|
|
798
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE, tasks: [3, 1] }, {}, forge, dir, deps)
|
|
799
|
+
expect(out.ok && out.tasks.map((t) => t.task)).toEqual([1, 3])
|
|
800
|
+
expect(written.map((w) => w.title)).toEqual(['[demo] 1 — First', '[demo] 3 — Third'])
|
|
801
|
+
cleanup()
|
|
802
|
+
})
|
|
803
|
+
|
|
804
|
+
it('reports a task that already has an Issue number and never writes it a second time', async () => {
|
|
805
|
+
const stored = plan()
|
|
806
|
+
stored.tasks[0]!.issue = 55
|
|
807
|
+
const deps = setup([1, 2, 3], stored)
|
|
808
|
+
const { forge, written } = recordingForge()
|
|
809
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
810
|
+
expect(out.ok).toBe(true)
|
|
811
|
+
if (!out.ok) return
|
|
812
|
+
expect(out.tasks[0]).toEqual({ task: 1, issue: 55, url: null, alreadyPublished: true })
|
|
813
|
+
expect(written.map((w) => w.title)).toEqual(['[demo] 2 — Second', '[demo] 3 — Third'])
|
|
814
|
+
cleanup()
|
|
815
|
+
})
|
|
816
|
+
|
|
817
|
+
it('writes nothing when no draft is stored', async () => {
|
|
818
|
+
dir = mkdtempSync(join(tmpdir(), 'plan-publish-'))
|
|
819
|
+
const { forge, written } = recordingForge()
|
|
820
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, {
|
|
821
|
+
runtimeDir: dir,
|
|
822
|
+
readDraft: (t) => readPlanDraft(dir, t),
|
|
823
|
+
roundLimit: 2
|
|
824
|
+
})
|
|
825
|
+
expect(out.ok).toBe(false)
|
|
826
|
+
expect(!out.ok && out.findings[0]?.message).toContain('no draft is stored')
|
|
827
|
+
expect(written).toEqual([])
|
|
828
|
+
cleanup()
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
it('writes nothing when the stored draft’s current fingerprint is not approved', async () => {
|
|
832
|
+
const deps = setup()
|
|
833
|
+
const changed = plan()
|
|
834
|
+
changed.tasks[1]!.title = 'Second, revised'
|
|
835
|
+
writePlanDraft(dir, changed)
|
|
836
|
+
const { forge, written } = recordingForge()
|
|
837
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
838
|
+
expect(out.ok).toBe(false)
|
|
839
|
+
expect(!out.ok && out.findings[0]?.message).toContain('is not approved')
|
|
840
|
+
expect(written).toEqual([])
|
|
841
|
+
cleanup()
|
|
842
|
+
})
|
|
843
|
+
|
|
844
|
+
it('writes nothing when the Principal did not approve the reviewer-approved draft', async () => {
|
|
845
|
+
const deps = setup([1, 2, 3], plan(), null)
|
|
846
|
+
const { forge, written } = recordingForge()
|
|
847
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
848
|
+
expect(out.ok).toBe(false)
|
|
849
|
+
expect(!out.ok && out.findings[0]?.message).toContain('the Principal has not approved')
|
|
850
|
+
expect(written).toEqual([])
|
|
851
|
+
cleanup()
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
it('writes nothing when the Principal approved an earlier fingerprint only', async () => {
|
|
855
|
+
const deps = setup([1, 2, 3], plan(), `sha256:${'0'.repeat(64)}`)
|
|
856
|
+
const { forge, written } = recordingForge()
|
|
857
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
858
|
+
expect(out.ok).toBe(false)
|
|
859
|
+
expect(!out.ok && out.findings[0]?.message).toContain('earlier fingerprint does not apply')
|
|
860
|
+
expect(written).toEqual([])
|
|
861
|
+
cleanup()
|
|
862
|
+
})
|
|
863
|
+
|
|
864
|
+
it('writes nothing when a named task is not an approved task', async () => {
|
|
865
|
+
const deps = setup([1, 2])
|
|
866
|
+
const { forge, written } = recordingForge()
|
|
867
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE, tasks: [1, 3] }, {}, forge, dir, deps)
|
|
868
|
+
expect(out.ok).toBe(false)
|
|
869
|
+
expect(!out.ok && out.findings[0]?.message).toContain('task 3')
|
|
870
|
+
expect(written).toEqual([])
|
|
871
|
+
cleanup()
|
|
872
|
+
})
|
|
873
|
+
|
|
874
|
+
it('stops at a gate refusal and keeps the Issue numbers already recorded', async () => {
|
|
875
|
+
const deps = setup()
|
|
876
|
+
let calls = 0
|
|
877
|
+
const { forge, written } = recordingForge({
|
|
878
|
+
validate: async () => {
|
|
879
|
+
calls += 1
|
|
880
|
+
return calls === 2
|
|
881
|
+
? { errors: [finding('brief-shape')], blocking: true, renderSkipped: null }
|
|
882
|
+
: { errors: [], blocking: false, renderSkipped: null }
|
|
883
|
+
}
|
|
884
|
+
})
|
|
885
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
886
|
+
expect(out.ok).toBe(false)
|
|
887
|
+
if (out.ok) return
|
|
888
|
+
expect(out.findings[0]?.check).toBe('brief-shape')
|
|
889
|
+
expect(out.published.map((t) => [t.task, t.issue])).toEqual([[1, 101]])
|
|
890
|
+
expect(written).toHaveLength(1)
|
|
891
|
+
const stored = readPlanDraft(dir, TRANCHE) as PlanDraft
|
|
892
|
+
expect(stored.tasks.map((t) => t.issue)).toEqual([101, null, null])
|
|
893
|
+
const status = planReviewStatus(deps, TRANCHE)
|
|
894
|
+
expect(status.ok && status.status.approved).toBe(true)
|
|
895
|
+
cleanup()
|
|
896
|
+
})
|
|
897
|
+
|
|
898
|
+
it('stops when the Issue number cannot be read from the link, after recording the earlier ones', async () => {
|
|
899
|
+
const deps = setup()
|
|
900
|
+
let n = 0
|
|
901
|
+
const { forge } = recordingForge({
|
|
902
|
+
ghWrite: () => {
|
|
903
|
+
n += 1
|
|
904
|
+
return { ok: true as const, url: n === 1 ? 'https://example.test/issues/101' : 'https://example.test/nothing' }
|
|
905
|
+
}
|
|
906
|
+
})
|
|
907
|
+
const out = await publishApprovedTasks({ tranche: TRANCHE }, {}, forge, dir, deps)
|
|
908
|
+
expect(out.ok).toBe(false)
|
|
909
|
+
if (out.ok) return
|
|
910
|
+
expect(out.findings[0]?.message).toContain('could not be read')
|
|
911
|
+
const stored = readPlanDraft(dir, TRANCHE) as PlanDraft
|
|
912
|
+
expect(stored.tasks.map((t) => t.issue)).toEqual([101, null, null])
|
|
913
|
+
cleanup()
|
|
914
|
+
})
|
|
915
|
+
})
|
|
916
|
+
|
|
917
|
+
describe('the review status drift of published tasks', () => {
|
|
918
|
+
const REVISION = 'b'.repeat(40)
|
|
919
|
+
const draft = (): PlanDraft => ({
|
|
920
|
+
schemaVersion: 1,
|
|
921
|
+
tranche: 'demo',
|
|
922
|
+
revision: REVISION,
|
|
923
|
+
reviewQuestionVersion: 'q1',
|
|
924
|
+
tasks: [
|
|
925
|
+
{ number: 1, issue: 11, title: 'First', body: 'one\ntwo', labels: [] },
|
|
926
|
+
{ number: 2, issue: 12, title: 'Second', body: 'same', labels: [] },
|
|
927
|
+
{ number: 3, issue: 13, title: 'Third', body: 'third', labels: [] },
|
|
928
|
+
{ number: 4, issue: 14, title: 'Fourth', body: 'fourth', labels: [] },
|
|
929
|
+
{ number: 5, issue: null, title: 'Fifth', body: 'fifth', labels: [] }
|
|
930
|
+
],
|
|
931
|
+
scope: []
|
|
932
|
+
})
|
|
933
|
+
const live =
|
|
934
|
+
(d: PlanDraft, over: Record<number, { title?: string; body?: string } | 'unreadable'>) => (n: number) => {
|
|
935
|
+
const task = d.tasks.find((t) => t.issue === n) as PlanDraft['tasks'][number]
|
|
936
|
+
const o = over[task.number]
|
|
937
|
+
if (o === 'unreadable') throw new Error('gh could not read the Issue')
|
|
938
|
+
const expected = publishedIssueOf(d, task)
|
|
939
|
+
return { title: o?.title ?? expected.title, body: o?.body ?? expected.body }
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
it('lists an edited Issue as drifted, naming what differs, an unchanged one as matching, an unreadable one as unread', () => {
|
|
943
|
+
const d = draft()
|
|
944
|
+
const out = publishedIssueDrift(d, live(d, { 1: { body: 'edited' }, 3: { title: 'renamed' }, 4: 'unreadable' }))
|
|
945
|
+
expect(out.drifted).toEqual([
|
|
946
|
+
{ task: 1, issue: 11, differs: 'body' },
|
|
947
|
+
{ task: 3, issue: 13, differs: 'title' }
|
|
948
|
+
])
|
|
949
|
+
expect(out.matching).toEqual([2])
|
|
950
|
+
expect(out.unread.map((u) => [u.task, u.issue])).toEqual([[4, 14]])
|
|
951
|
+
})
|
|
952
|
+
|
|
953
|
+
it('names both when title and body differ, and ignores line endings', () => {
|
|
954
|
+
const d = draft()
|
|
955
|
+
const out = publishedIssueDrift(d, live(d, { 1: { body: 'one\r\ntwo' }, 2: { title: 'x', body: 'y' } }))
|
|
956
|
+
expect(out.drifted).toEqual([{ task: 2, issue: 12, differs: 'both' }])
|
|
957
|
+
expect(out.matching).toEqual([1, 3, 4])
|
|
958
|
+
})
|
|
959
|
+
|
|
960
|
+
it('is attached to the stored review status, which stays readable when an Issue is unreadable', () => {
|
|
961
|
+
const d = draft()
|
|
962
|
+
const dir = mkdtempSync(join(tmpdir(), 'plan-drift-'))
|
|
963
|
+
writePlanDraft(dir, d)
|
|
964
|
+
const deps = { runtimeDir: dir, readDraft: (t: string) => readPlanDraft(dir, t), roundLimit: 2 }
|
|
965
|
+
const out = readStoredPlanReviewStatusWithDrift('demo', deps, live(d, { 2: 'unreadable', 3: { body: 'x' } }))
|
|
966
|
+
expect(out.ok).toBe(true)
|
|
967
|
+
if (out.ok) {
|
|
968
|
+
expect(out.status.drift.drifted.map((x) => x.task)).toEqual([3])
|
|
969
|
+
expect(out.status.drift.unread.map((x) => x.task)).toEqual([2])
|
|
970
|
+
}
|
|
971
|
+
rmSync(dir, { recursive: true, force: true })
|
|
972
|
+
})
|
|
973
|
+
})
|