@aviaratech/ai-delivery 0.3.25 → 0.3.27
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 +115 -14
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +1 -0
- package/dist/agent.js.map +1 -1
- package/dist/agentReadiness.test.js +61 -123
- package/dist/agentReadiness.test.js.map +1 -1
- package/dist/cli.js +121 -32
- package/dist/cli.js.map +1 -1
- package/dist/cliResult.js +1 -1
- package/dist/cliResult.js.map +1 -1
- package/dist/cliResult.test.js +18 -0
- package/dist/cliResult.test.js.map +1 -1
- package/dist/config/deliveryConfig.js +5 -1
- package/dist/config/deliveryConfig.js.map +1 -1
- package/dist/deliveryHealth.test.d.ts +1 -0
- package/dist/deliveryHealth.test.js +167 -0
- package/dist/deliveryHealth.test.js.map +1 -0
- package/dist/dispatch.d.ts +26 -2
- package/dist/dispatch.js +78 -7
- package/dist/dispatch.js.map +1 -1
- package/dist/fixtures/inertEntrypointChild.d.ts +1 -0
- package/dist/fixtures/inertEntrypointChild.js +62 -0
- package/dist/fixtures/inertEntrypointChild.js.map +1 -0
- package/dist/fixtures/inertEntrypoints.d.ts +49 -0
- package/dist/fixtures/inertEntrypoints.js +276 -0
- package/dist/fixtures/inertEntrypoints.js.map +1 -0
- package/dist/fixtures/inertTarget.d.ts +643 -0
- package/dist/fixtures/inertTarget.js +713 -0
- package/dist/fixtures/inertTarget.js.map +1 -0
- package/dist/fixtures/issue63.d.ts +68 -0
- package/dist/fixtures/issue63.js +272 -0
- package/dist/fixtures/issue63.js.map +1 -0
- package/dist/github/client.d.ts +2 -0
- package/dist/github/client.js +94 -12
- package/dist/github/client.js.map +1 -1
- package/dist/github/issueHistory.d.ts +40 -0
- package/dist/github/issueHistory.js +144 -0
- package/dist/github/issueHistory.js.map +1 -0
- package/dist/github/machineAuth.d.ts +9 -0
- package/dist/github/machineAuth.js +135 -0
- package/dist/github/machineAuth.js.map +1 -0
- package/dist/github/machineAuth.test.d.ts +1 -0
- package/dist/github/machineAuth.test.js +409 -0
- package/dist/github/machineAuth.test.js.map +1 -0
- package/dist/github/projectDelivery.d.ts +2 -0
- package/dist/github/projectDelivery.js +6 -0
- package/dist/github/projectDelivery.js.map +1 -1
- package/dist/github/relationships.d.ts +9 -2
- package/dist/github/relationships.js +6 -2
- package/dist/github/relationships.js.map +1 -1
- package/dist/investigationCompletion.test.d.ts +1 -0
- package/dist/investigationCompletion.test.js +728 -0
- package/dist/investigationCompletion.test.js.map +1 -0
- package/dist/issue.d.ts +24 -6
- package/dist/issue.js +169 -21
- package/dist/issue.js.map +1 -1
- package/dist/issue63History.test.d.ts +1 -0
- package/dist/issue63History.test.js +45 -0
- package/dist/issue63History.test.js.map +1 -0
- package/dist/issue63Routes.test.d.ts +1 -0
- package/dist/issue63Routes.test.js +153 -0
- package/dist/issue63Routes.test.js.map +1 -0
- package/dist/issueBlockerGuard.test.d.ts +1 -0
- package/dist/issueBlockerGuard.test.js +162 -0
- package/dist/issueBlockerGuard.test.js.map +1 -0
- package/dist/issueContract.d.ts +230 -0
- package/dist/issueContract.js +341 -0
- package/dist/issueContract.js.map +1 -0
- package/dist/issueContract.test.d.ts +27 -0
- package/dist/issueContract.test.js +314 -0
- package/dist/issueContract.test.js.map +1 -0
- package/dist/issueIntake.test.d.ts +1 -0
- package/dist/issueIntake.test.js +994 -0
- package/dist/issueIntake.test.js.map +1 -0
- package/dist/issueJournal.d.ts +1 -1
- package/dist/issueTracking.test.js +16 -8
- package/dist/issueTracking.test.js.map +1 -1
- package/dist/mcp/tools.d.ts +135 -11
- package/dist/mcp/tools.js +85 -33
- package/dist/mcp/tools.js.map +1 -1
- package/dist/pluginAuthProbe.d.ts +6 -0
- package/dist/pluginAuthProbe.js +53 -0
- package/dist/pluginAuthProbe.js.map +1 -0
- package/dist/pluginAuthProbe.test.d.ts +1 -0
- package/dist/pluginAuthProbe.test.js +66 -0
- package/dist/pluginAuthProbe.test.js.map +1 -0
- package/dist/pluginCredentials.test.d.ts +1 -0
- package/dist/pluginCredentials.test.js +277 -0
- package/dist/pluginCredentials.test.js.map +1 -0
- package/dist/pluginDoctor.test.d.ts +1 -0
- package/dist/pluginDoctor.test.js +627 -0
- package/dist/pluginDoctor.test.js.map +1 -0
- package/dist/pluginInstaller.d.ts +36 -0
- package/dist/pluginInstaller.js +231 -10
- package/dist/pluginInstaller.js.map +1 -1
- package/dist/pluginInstaller.test.js +29 -0
- package/dist/pluginInstaller.test.js.map +1 -1
- package/dist/pluginPackaging.test.js +23 -3
- package/dist/pluginPackaging.test.js.map +1 -1
- package/dist/pr.d.ts +70 -0
- package/dist/pr.js +290 -3
- package/dist/pr.js.map +1 -1
- package/dist/prAssociation.test.js +31 -0
- package/dist/prAssociation.test.js.map +1 -1
- package/dist/review.test.js +133 -0
- package/dist/review.test.js.map +1 -1
- package/dist/services/agentReadinessService.d.ts +9 -8
- package/dist/services/agentReadinessService.js +32 -224
- package/dist/services/agentReadinessService.js.map +1 -1
- package/dist/services/blockerGuardService.d.ts +17 -0
- package/dist/services/blockerGuardService.js +194 -0
- package/dist/services/blockerGuardService.js.map +1 -0
- package/dist/services/deliveryAdmission.js +22 -19
- package/dist/services/deliveryAdmission.js.map +1 -1
- package/dist/services/deliveryHealthService.d.ts +84 -0
- package/dist/services/deliveryHealthService.js +206 -0
- package/dist/services/deliveryHealthService.js.map +1 -0
- package/dist/services/worktreeRegistry.d.ts +84 -0
- package/dist/services/worktreeRegistry.js +265 -1
- package/dist/services/worktreeRegistry.js.map +1 -1
- package/dist/setup.test.js +97 -3
- package/dist/setup.test.js.map +1 -1
- package/dist/start.test.js +31 -3
- package/dist/start.test.js.map +1 -1
- package/dist/stdoutRegression.test.js +38 -8
- package/dist/stdoutRegression.test.js.map +1 -1
- package/dist/targetPolicyDiscovery.test.d.ts +1 -0
- package/dist/targetPolicyDiscovery.test.js +150 -0
- package/dist/targetPolicyDiscovery.test.js.map +1 -0
- package/dist/targetPolicyEntrypoints.test.d.ts +1 -0
- package/dist/targetPolicyEntrypoints.test.js +275 -0
- package/dist/targetPolicyEntrypoints.test.js.map +1 -0
- package/dist/targetPolicyLocal.test.d.ts +1 -0
- package/dist/targetPolicyLocal.test.js +707 -0
- package/dist/targetPolicyLocal.test.js.map +1 -0
- package/dist/targetPolicyRoutes.test.d.ts +1 -0
- package/dist/targetPolicyRoutes.test.js +298 -0
- package/dist/targetPolicyRoutes.test.js.map +1 -0
- package/dist/verification.js +48 -12
- package/dist/verification.js.map +1 -1
- package/dist/verificationGate.test.d.ts +1 -0
- package/dist/verificationGate.test.js +106 -0
- package/dist/verificationGate.test.js.map +1 -0
- package/dist/worktree.d.ts +6 -1
- package/dist/worktree.js +90 -3
- package/dist/worktree.js.map +1 -1
- package/dist/worktreeTransition.test.js +1 -1
- package/dist/worktreeTransition.test.js.map +1 -1
- package/package.json +1 -1
- package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
- package/plugins/ai-delivery/README.md +160 -1
- package/plugins/ai-delivery/plugin.json +1 -1
- package/plugins/ai-delivery/runtime/dist/cli.js +83 -49
- package/plugins/ai-delivery/runtime/package.json +1 -1
- package/plugins/ai-delivery/skills/intake-create/SKILL.md +45 -30
- package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +20 -0
|
@@ -0,0 +1,994 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { join, resolve } from 'node:path';
|
|
6
|
+
import { afterEach, test, vi } from 'vitest';
|
|
7
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
8
|
+
import { createAiDeliveryMcpServer } from './mcp/index.js';
|
|
9
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
10
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { createIssue, updateIssue, canonicalIssueBody } from './issue.js';
|
|
13
|
+
import { executeTool, startTrackedIssue } from './dispatch.js';
|
|
14
|
+
import { digestValue } from './delivery/common.js';
|
|
15
|
+
import { getAiDeliveryMcpTool } from './mcp/tools.js';
|
|
16
|
+
import { IssueFields, ReadyIssue, renderIssueBody, parseIssueBody, ISSUE_BODY_MARKER } from './issueContract.js';
|
|
17
|
+
import { syntheticDiscoveryConfig } from './fixtures/discovery.js';
|
|
18
|
+
afterEach(() => vi.restoreAllMocks());
|
|
19
|
+
const ready = () => IssueFields.parse({
|
|
20
|
+
title: 'Reject invalid widget identifiers before persistence',
|
|
21
|
+
issueType: 'Task',
|
|
22
|
+
points: 2,
|
|
23
|
+
problem: 'Malformed identifiers reach persistence.',
|
|
24
|
+
outcome: 'Reject malformed widget identifiers before persistence.',
|
|
25
|
+
acceptanceCriteria: [
|
|
26
|
+
{
|
|
27
|
+
behavior: 'An invalid identifier returns an error with zero persistence calls.',
|
|
28
|
+
verifiedBy: 'A portable mocked persistence regression test.',
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
outOfScope: ['Storage changes.'],
|
|
32
|
+
context: { components: ['widget'], files: [], evidence: [] },
|
|
33
|
+
});
|
|
34
|
+
function fixture() {
|
|
35
|
+
const live = {
|
|
36
|
+
number: 17,
|
|
37
|
+
id: 117,
|
|
38
|
+
node_id: 'ISSUE17',
|
|
39
|
+
title: ready().title,
|
|
40
|
+
body: renderIssueBody(ready()),
|
|
41
|
+
state: 'open',
|
|
42
|
+
created_at: '2026-01-01T00:00:00Z',
|
|
43
|
+
type: { name: 'Task' },
|
|
44
|
+
html_url: 'https://github.com/example/widget/issues/17',
|
|
45
|
+
};
|
|
46
|
+
const writes = [];
|
|
47
|
+
const comments = [];
|
|
48
|
+
const controls = {
|
|
49
|
+
role: 'author',
|
|
50
|
+
ignoreBody: false,
|
|
51
|
+
wrongCreateRepo: false,
|
|
52
|
+
driftAfterHistory: false,
|
|
53
|
+
created: true,
|
|
54
|
+
blockers: false,
|
|
55
|
+
trackingParent: false,
|
|
56
|
+
livePoints: 2,
|
|
57
|
+
projectMember: true,
|
|
58
|
+
projectArchived: false,
|
|
59
|
+
projectFailure: '',
|
|
60
|
+
journalFailure: false,
|
|
61
|
+
branchFailure: false,
|
|
62
|
+
closeAfterBranch: false,
|
|
63
|
+
blockAfterBranch: false,
|
|
64
|
+
};
|
|
65
|
+
const branchWrites = [];
|
|
66
|
+
const branches = [];
|
|
67
|
+
let points = 2;
|
|
68
|
+
let status = 'Queued';
|
|
69
|
+
const statusWrites = [];
|
|
70
|
+
const membershipWrites = [];
|
|
71
|
+
const optionId = () => ({ Queued: 'TODO', Active: 'ACTIVE', Waiting: 'BLOCKED', Shipped: 'DONE' })[status];
|
|
72
|
+
const values = () => [
|
|
73
|
+
{
|
|
74
|
+
issue_field_id: 101,
|
|
75
|
+
issue_field_name: 'Estimate',
|
|
76
|
+
data_type: 'single_select',
|
|
77
|
+
value: String(controls.livePoints),
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
const context = {
|
|
81
|
+
root: '/synthetic-non-git',
|
|
82
|
+
repo: { owner: 'example', repo: 'widget' },
|
|
83
|
+
config: syntheticDiscoveryConfig,
|
|
84
|
+
projectConfiguration: {
|
|
85
|
+
projectId: 'PROJECT',
|
|
86
|
+
projectNumber: 1,
|
|
87
|
+
title: 'Delivery',
|
|
88
|
+
writable: true,
|
|
89
|
+
pointsFieldId: 'POINTS',
|
|
90
|
+
priorityFieldId: 'PRIORITY',
|
|
91
|
+
statusFieldId: 'STATUS',
|
|
92
|
+
statusOptionIds: { Todo: 'TODO', 'In Progress': 'ACTIVE', Blocked: 'BLOCKED', Done: 'DONE' },
|
|
93
|
+
settings: {
|
|
94
|
+
number: 1,
|
|
95
|
+
title: 'Delivery',
|
|
96
|
+
statusField: 'Flow',
|
|
97
|
+
statuses: { Todo: 'Queued', 'In Progress': 'Active', Blocked: 'Waiting', Done: 'Shipped' },
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
clients: {
|
|
101
|
+
get role() {
|
|
102
|
+
return controls.role;
|
|
103
|
+
},
|
|
104
|
+
authenticatedAuthor: async () => ({ actorLogin: 'operator', credentialIdentity: 'user:1' }),
|
|
105
|
+
rest: {
|
|
106
|
+
issues: {
|
|
107
|
+
listSubIssues: async () => ({ data: controls.trackingParent ? [{ number: 18 }] : [] }),
|
|
108
|
+
get: async () => ({ data: { ...live } }),
|
|
109
|
+
listForRepo: async () => ({ data: controls.created ? [{ ...live }] : [] }),
|
|
110
|
+
create: async (input) => {
|
|
111
|
+
writes.push(input);
|
|
112
|
+
controls.created = true;
|
|
113
|
+
live.title = String(input.title);
|
|
114
|
+
live.body = String(input.body);
|
|
115
|
+
live.type = { name: String(input.type) };
|
|
116
|
+
return {
|
|
117
|
+
data: {
|
|
118
|
+
...live,
|
|
119
|
+
...(controls.wrongCreateRepo ? { html_url: 'https://github.com/other/widget/issues/17' } : {}),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
update: async (input) => {
|
|
124
|
+
writes.push(input);
|
|
125
|
+
if (!controls.ignoreBody && typeof input.body === 'string')
|
|
126
|
+
live.body = input.body;
|
|
127
|
+
if (typeof input.title === 'string')
|
|
128
|
+
live.title = input.title;
|
|
129
|
+
if (typeof input.type === 'string')
|
|
130
|
+
live.type = { name: input.type };
|
|
131
|
+
return { data: { ...live } };
|
|
132
|
+
},
|
|
133
|
+
listComments: async () => ({ data: comments }),
|
|
134
|
+
createComment: async (input) => {
|
|
135
|
+
const comment = {
|
|
136
|
+
id: 91 + comments.length,
|
|
137
|
+
body: input.body,
|
|
138
|
+
html_url: 'https://github.com/example/widget/issues/17#issuecomment-' + String(91 + comments.length),
|
|
139
|
+
user: { login: 'operator' },
|
|
140
|
+
issue_url: 'https://api.github.com/repos/example/widget/issues/17',
|
|
141
|
+
};
|
|
142
|
+
comments.push(comment);
|
|
143
|
+
if (controls.journalFailure)
|
|
144
|
+
throw new Error('Lost journal response');
|
|
145
|
+
return { data: comment };
|
|
146
|
+
},
|
|
147
|
+
getComment: async (input) => {
|
|
148
|
+
if (controls.driftAfterHistory)
|
|
149
|
+
live.body = 'Concurrent owner content';
|
|
150
|
+
return { data: comments.find((c) => c.id === input.comment_id) };
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
repos: { get: async () => ({ data: { default_branch: 'main', node_id: 'REPOSITORY' } }) },
|
|
154
|
+
git: { getRef: async () => ({ data: { object: { sha: 'a'.repeat(40) } } }) },
|
|
155
|
+
request: async (route, input) => {
|
|
156
|
+
if (route === 'GET /orgs/{org}/issue-fields')
|
|
157
|
+
return {
|
|
158
|
+
data: [
|
|
159
|
+
{
|
|
160
|
+
id: 101,
|
|
161
|
+
name: 'Estimate',
|
|
162
|
+
data_type: 'single_select',
|
|
163
|
+
options: ['1', '2', '4'].map((name) => ({ name })),
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
id: 102,
|
|
167
|
+
name: 'Urgency',
|
|
168
|
+
data_type: 'single_select',
|
|
169
|
+
options: ['High', 'Low'].map((name) => ({ name })),
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
};
|
|
173
|
+
if (route.startsWith('POST ')) {
|
|
174
|
+
const fields = input.issue_field_values;
|
|
175
|
+
points = Number(fields.find((f) => f.field_id === 101)?.value ?? points);
|
|
176
|
+
controls.livePoints = points;
|
|
177
|
+
return { data: values() };
|
|
178
|
+
}
|
|
179
|
+
if (route.startsWith('GET '))
|
|
180
|
+
return { data: values() };
|
|
181
|
+
throw new Error('Unexpected native request ' + route);
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
graphql: async (query, input) => {
|
|
185
|
+
if (query.includes('DeliveryIssueBranches'))
|
|
186
|
+
return {
|
|
187
|
+
repository: {
|
|
188
|
+
issue: {
|
|
189
|
+
linkedBranches: {
|
|
190
|
+
nodes: branches.map((branch) => ({
|
|
191
|
+
ref: {
|
|
192
|
+
name: branch.name,
|
|
193
|
+
target: { oid: branch.sha },
|
|
194
|
+
repository: { nameWithOwner: 'example/widget' },
|
|
195
|
+
},
|
|
196
|
+
})),
|
|
197
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
if (query.includes('DeliveryStartBranch')) {
|
|
203
|
+
const fields = input.input;
|
|
204
|
+
branchWrites.push(fields);
|
|
205
|
+
branches.push({ name: String(fields.name), sha: String(fields.oid) });
|
|
206
|
+
if (controls.closeAfterBranch)
|
|
207
|
+
live.state = 'closed';
|
|
208
|
+
if (controls.blockAfterBranch)
|
|
209
|
+
controls.blockers = true;
|
|
210
|
+
if (controls.branchFailure)
|
|
211
|
+
throw new Error('Lost branch response');
|
|
212
|
+
return { createLinkedBranch: { linkedBranch: { ref: { name: fields.name, target: { oid: fields.oid } } } } };
|
|
213
|
+
}
|
|
214
|
+
if (query.includes('blockedBy(first:'))
|
|
215
|
+
return {
|
|
216
|
+
repository: {
|
|
217
|
+
issue: {
|
|
218
|
+
parent: null,
|
|
219
|
+
blockedBy: {
|
|
220
|
+
nodes: controls.blockers
|
|
221
|
+
? [
|
|
222
|
+
{
|
|
223
|
+
id: 'ISSUE18',
|
|
224
|
+
number: 18,
|
|
225
|
+
title: 'Resolve prerequisite',
|
|
226
|
+
state: 'OPEN',
|
|
227
|
+
repository: { nameWithOwner: 'example/widget' },
|
|
228
|
+
},
|
|
229
|
+
]
|
|
230
|
+
: [],
|
|
231
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
if (query.includes('ProjectDeliveryItems'))
|
|
237
|
+
return {
|
|
238
|
+
organization: {
|
|
239
|
+
projectV2: {
|
|
240
|
+
items: {
|
|
241
|
+
nodes: [
|
|
242
|
+
{
|
|
243
|
+
id: 'OTHER',
|
|
244
|
+
isArchived: false,
|
|
245
|
+
content: { id: 'OTHER-ISSUE' },
|
|
246
|
+
fieldValueByName: { name: 'Queued', optionId: 'TODO' },
|
|
247
|
+
},
|
|
248
|
+
...(controls.projectMember
|
|
249
|
+
? [
|
|
250
|
+
{
|
|
251
|
+
id: 'ITEM17',
|
|
252
|
+
isArchived: controls.projectArchived,
|
|
253
|
+
content: { id: 'ISSUE17' },
|
|
254
|
+
fieldValueByName: { name: status, optionId: optionId() },
|
|
255
|
+
},
|
|
256
|
+
]
|
|
257
|
+
: []),
|
|
258
|
+
],
|
|
259
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
if (query.includes('AddProjectDeliveryItem')) {
|
|
265
|
+
membershipWrites.push(input);
|
|
266
|
+
assert.equal(input.projectId, 'PROJECT');
|
|
267
|
+
assert.equal(input.contentId, 'ISSUE17');
|
|
268
|
+
controls.projectMember = true;
|
|
269
|
+
return { addProjectV2ItemById: { item: { id: 'ITEM17' } } };
|
|
270
|
+
}
|
|
271
|
+
if (query.includes('UpdateProjectDeliveryStatus')) {
|
|
272
|
+
statusWrites.push(input);
|
|
273
|
+
assert.equal(input.projectId, 'PROJECT');
|
|
274
|
+
assert.equal(input.itemId, 'ITEM17');
|
|
275
|
+
assert.equal(input.fieldId, 'STATUS');
|
|
276
|
+
if (input.optionId === 'ACTIVE' && controls.projectFailure === 'before')
|
|
277
|
+
throw new Error('Project write failed');
|
|
278
|
+
status = input.optionId === 'TODO' ? 'Queued' : input.optionId === 'DONE' ? 'Shipped' : 'Active';
|
|
279
|
+
if (input.optionId === 'ACTIVE' && controls.projectFailure === 'after')
|
|
280
|
+
throw new Error('Lost Project response');
|
|
281
|
+
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'ITEM17' } } };
|
|
282
|
+
}
|
|
283
|
+
if (query.includes('ProjectDeliveryItemReadback'))
|
|
284
|
+
return {
|
|
285
|
+
node: {
|
|
286
|
+
id: 'ITEM17',
|
|
287
|
+
isArchived: false,
|
|
288
|
+
project: { id: 'PROJECT', number: 1 },
|
|
289
|
+
content: {
|
|
290
|
+
id: status === 'Active' && controls.projectFailure === 'readback' ? 'OTHER-ISSUE' : 'ISSUE17',
|
|
291
|
+
},
|
|
292
|
+
fieldValueByName: { name: status, optionId: optionId() },
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
throw new Error('Unexpected native query ' + query);
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
return {
|
|
300
|
+
context,
|
|
301
|
+
live,
|
|
302
|
+
writes,
|
|
303
|
+
comments,
|
|
304
|
+
controls,
|
|
305
|
+
branches,
|
|
306
|
+
branchWrites,
|
|
307
|
+
statusWrites,
|
|
308
|
+
membershipWrites,
|
|
309
|
+
getStatus: () => status,
|
|
310
|
+
setStatus: (value) => {
|
|
311
|
+
status = value;
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
test('native create validates first, writes canonical fields, reads back metadata and returns warnings', async () => {
|
|
316
|
+
const f = fixture();
|
|
317
|
+
await assert.rejects(createIssue(f.context, { ...ready(), openQuestions: ['Select behavior.'] }), /open-questions/u);
|
|
318
|
+
assert.equal(f.writes.length, 0);
|
|
319
|
+
const result = await createIssue(f.context, ready());
|
|
320
|
+
assert.equal(f.writes.length, 1);
|
|
321
|
+
assert.equal(result.body, renderIssueBody(ready()));
|
|
322
|
+
assert.equal(parseIssueBody(result.body, { title: result.created.title }).issue.points, 2);
|
|
323
|
+
assert.deepEqual(result.warnings, []);
|
|
324
|
+
assert.equal(f.getStatus(), 'Queued');
|
|
325
|
+
});
|
|
326
|
+
test('incomplete drafts write parked; reviewer-role writes and wrong native repository readback are refused', async () => {
|
|
327
|
+
const f = fixture();
|
|
328
|
+
await createIssue(f.context, { title: 'Investigate invalid widget identifiers', draft: true });
|
|
329
|
+
assert.equal(f.getStatus(), 'Queued');
|
|
330
|
+
assert.match(f.live.body, /Draft — parked/u);
|
|
331
|
+
f.controls.role = 'reviewer';
|
|
332
|
+
await assert.rejects(createIssue(f.context, ready()), /author role/u);
|
|
333
|
+
await assert.rejects(updateIssue(f.context, { issueNumber: 17, draft: true }), /author role/u);
|
|
334
|
+
const bad = fixture();
|
|
335
|
+
bad.controls.wrongCreateRepo = true;
|
|
336
|
+
await assert.rejects(createIssue(bad.context, ready()), /created but native tracking did not complete/u);
|
|
337
|
+
assert.equal(bad.writes.length, 1);
|
|
338
|
+
});
|
|
339
|
+
test('first legacy update retains exact history and full diff, then typed patches preserve unspecified fields', async () => {
|
|
340
|
+
const f = fixture();
|
|
341
|
+
const legacy = '## Problem\nMalformed identifiers reach persistence.\n## Outcome\nReject malformed identifiers.\n## Acceptance Criteria\n- [ ] Invalid identifiers return an error without persistence.\n## Verification\nA portable regression asserts no write.\n## Out of scope\n- Storage changes.\n## Scope\nwidget component\n';
|
|
342
|
+
f.live.body = legacy;
|
|
343
|
+
const result = await updateIssue(f.context, { issueNumber: 17 });
|
|
344
|
+
assert.equal(f.comments.length, 1);
|
|
345
|
+
assert.equal(result.conversion?.priorBody, legacy);
|
|
346
|
+
assert.match(result.conversion.diff, /^--- prior body\n\+\+\+ canonical body/u);
|
|
347
|
+
assert.match(f.comments[0].body, /Malformed identifiers reach persistence/u);
|
|
348
|
+
assert.equal(parseIssueBody(result.body, { title: result.title }).issue.legacyBody, legacy);
|
|
349
|
+
const patched = await updateIssue(f.context, {
|
|
350
|
+
issueNumber: 17,
|
|
351
|
+
outcome: 'Reject malformed identifiers with a typed error.',
|
|
352
|
+
preserveHistory: true,
|
|
353
|
+
});
|
|
354
|
+
assert.equal(parseIssueBody(patched.body, { title: patched.title }).issue.acceptanceCriteria.length, 1);
|
|
355
|
+
assert.equal(patched.conversion, undefined);
|
|
356
|
+
assert.equal(f.comments.length, 2);
|
|
357
|
+
});
|
|
358
|
+
test('legacy replacement updates preserve the actual previous body and diff for canonical and handwritten input', async () => {
|
|
359
|
+
const original = 'Original native legacy bytes, including unclassified operator context.\n';
|
|
360
|
+
for (const replacement of [renderIssueBody(ready()), 'Replacement handwritten context.\n']) {
|
|
361
|
+
const f = fixture();
|
|
362
|
+
f.live.body = original;
|
|
363
|
+
const result = await updateIssue(f.context, { issueNumber: 17, body: replacement, ...ready() });
|
|
364
|
+
assert.equal(f.comments.length, 1);
|
|
365
|
+
assert.ok(f.comments[0].body.includes(original));
|
|
366
|
+
assert.equal(result.conversion?.priorBody, original);
|
|
367
|
+
assert.ok(result.conversion.diff.includes('-' + original.trim()));
|
|
368
|
+
const preserved = parseIssueBody(result.body, { title: result.title }).issue.legacyBody;
|
|
369
|
+
assert.ok(preserved?.includes(original));
|
|
370
|
+
if (!replacement.startsWith(ISSUE_BODY_MARKER))
|
|
371
|
+
assert.ok(preserved?.includes(replacement));
|
|
372
|
+
assert.equal(result.conversion?.canonicalBody, result.body);
|
|
373
|
+
const patch = await updateIssue(f.context, {
|
|
374
|
+
issueNumber: 17,
|
|
375
|
+
outcome: 'Reject invalid input before persistence.',
|
|
376
|
+
});
|
|
377
|
+
assert.equal(patch.conversion, undefined);
|
|
378
|
+
assert.equal(f.comments.length, 1);
|
|
379
|
+
assert.equal(parseIssueBody(patch.body, { title: patch.title }).issue.legacyBody, preserved);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
test('validation, history drift and corrupted native update readback fail without a fabricated success', async () => {
|
|
383
|
+
const f = fixture();
|
|
384
|
+
await assert.rejects(updateIssue(f.context, { issueNumber: 17, openQuestions: ['Choose a policy.'] }), /open-questions/u);
|
|
385
|
+
assert.equal(f.writes.length, 0);
|
|
386
|
+
assert.equal(f.comments.length, 0);
|
|
387
|
+
f.controls.driftAfterHistory = true;
|
|
388
|
+
await assert.rejects(updateIssue(f.context, {
|
|
389
|
+
issueNumber: 17,
|
|
390
|
+
outcome: 'Reject malformed input before all writes.',
|
|
391
|
+
preserveHistory: true,
|
|
392
|
+
}), /content changed/u);
|
|
393
|
+
assert.equal(f.writes.length, 0);
|
|
394
|
+
const bad = fixture();
|
|
395
|
+
bad.controls.ignoreBody = true;
|
|
396
|
+
await assert.rejects(updateIssue(bad.context, { issueNumber: 17, outcome: 'Reject malformed input before all writes.' }), /update readback disagrees/u);
|
|
397
|
+
});
|
|
398
|
+
test('normal-start canonical retry body keeps exact intent markers through create/readiness', async () => {
|
|
399
|
+
const issue = ready();
|
|
400
|
+
const canonical = canonicalIssueBody(issue);
|
|
401
|
+
const footer = '\n\n<!-- ai-delivery-start-intent: ' +
|
|
402
|
+
digestValue({ intent: 'fixture' }) +
|
|
403
|
+
' -->\n<!-- ai-delivery-start: ' +
|
|
404
|
+
digestValue({ request: 'fixture' }) +
|
|
405
|
+
' -->';
|
|
406
|
+
const result = await createIssue(fixture().context, {
|
|
407
|
+
title: issue.title,
|
|
408
|
+
body: canonical + footer,
|
|
409
|
+
points: 2,
|
|
410
|
+
issueType: 'Task',
|
|
411
|
+
});
|
|
412
|
+
assert.equal(result.body, canonical + footer);
|
|
413
|
+
assert.deepEqual(parseIssueBody(result.body, { title: issue.title }).issue, issue);
|
|
414
|
+
});
|
|
415
|
+
test('actual normal-start creation and retry reuse the exact canonical body, branch and authored journal', async () => {
|
|
416
|
+
const f = fixture();
|
|
417
|
+
f.controls.created = false;
|
|
418
|
+
const request = getAiDeliveryMcpTool('issue_start').inputSchema.parse({
|
|
419
|
+
title: ready().title,
|
|
420
|
+
body: renderIssueBody(ready()),
|
|
421
|
+
issueType: 'Task',
|
|
422
|
+
points: 2,
|
|
423
|
+
requestId: 'issue68-normal-start',
|
|
424
|
+
});
|
|
425
|
+
const first = await startTrackedIssue(f.context, request);
|
|
426
|
+
assert.ok('issueNumber' in first);
|
|
427
|
+
assert.equal(first.issueNumber, 17);
|
|
428
|
+
assert.ok('reused' in first && first.reused === false);
|
|
429
|
+
const body = f.live.body;
|
|
430
|
+
assert.match(body, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
431
|
+
assert.match(body, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
432
|
+
assert.deepEqual(parseIssueBody(body, { title: f.live.title }).issue, ready());
|
|
433
|
+
assert.equal(f.branchWrites.length, 1);
|
|
434
|
+
assert.equal(f.branchWrites[0]?.clientMutationId, digestValue({ repository: 'example/widget', issueNumber: 17, name: 'issue/17', base: 'a'.repeat(40) }));
|
|
435
|
+
assert.equal(f.comments.length, 1);
|
|
436
|
+
const retry = await startTrackedIssue(f.context, request);
|
|
437
|
+
assert.ok('reused' in retry && retry.reused === true);
|
|
438
|
+
assert.equal(retry.issueNumber, 17);
|
|
439
|
+
assert.equal(f.writes.filter((input) => !('issue_number' in input)).length, 1);
|
|
440
|
+
assert.equal(f.branchWrites.length, 1);
|
|
441
|
+
assert.equal(f.comments.length, 1);
|
|
442
|
+
assert.equal(f.live.body, body);
|
|
443
|
+
await assert.rejects(startTrackedIssue(f.context, {
|
|
444
|
+
...request,
|
|
445
|
+
body: renderIssueBody({ ...ready(), outcome: 'A conflicting new outcome.' }),
|
|
446
|
+
}), /conflicts/u);
|
|
447
|
+
assert.equal(f.branchWrites.length, 1);
|
|
448
|
+
});
|
|
449
|
+
test('a history rewrite refuses to republish secret-bearing prior text', async () => {
|
|
450
|
+
const f = fixture();
|
|
451
|
+
f.live.body = 'An accidental fixture ' + ['gh', 'p_'].join('') + 'A'.repeat(24);
|
|
452
|
+
await assert.rejects(updateIssue(f.context, { issueNumber: 17, body: renderIssueBody(ready()), preserveHistory: true }), /secrets/u);
|
|
453
|
+
assert.equal(f.comments.length, 0);
|
|
454
|
+
assert.equal(f.writes.length, 0);
|
|
455
|
+
});
|
|
456
|
+
test('ordinary start checks typed Draft, Points and live eligibility before branch or journal mutation', async () => {
|
|
457
|
+
for (const [expected, change] of [
|
|
458
|
+
[
|
|
459
|
+
'draft',
|
|
460
|
+
(f) => {
|
|
461
|
+
f.live.body = renderIssueBody({ ...ready(), draft: true });
|
|
462
|
+
},
|
|
463
|
+
],
|
|
464
|
+
[
|
|
465
|
+
'points.sync',
|
|
466
|
+
(f) => {
|
|
467
|
+
f.controls.livePoints = 4;
|
|
468
|
+
},
|
|
469
|
+
],
|
|
470
|
+
[
|
|
471
|
+
'blocked',
|
|
472
|
+
(f) => {
|
|
473
|
+
f.controls.blockers = true;
|
|
474
|
+
},
|
|
475
|
+
],
|
|
476
|
+
[
|
|
477
|
+
'tracking-parent',
|
|
478
|
+
(f) => {
|
|
479
|
+
f.controls.trackingParent = true;
|
|
480
|
+
},
|
|
481
|
+
],
|
|
482
|
+
]) {
|
|
483
|
+
const f = fixture();
|
|
484
|
+
change(f);
|
|
485
|
+
await assert.rejects(startTrackedIssue(f.context, { issueNumber: 17 }), (error) => {
|
|
486
|
+
assert.ok(error instanceof Error);
|
|
487
|
+
const diagnostics = JSON.parse(error.message);
|
|
488
|
+
assert(diagnostics.failures.some((failure) => failure.code === expected && failure.field && failure.fixHint));
|
|
489
|
+
return true;
|
|
490
|
+
});
|
|
491
|
+
assert.equal(f.branchWrites.length, 0);
|
|
492
|
+
assert.equal(f.comments.length, 0);
|
|
493
|
+
assert.equal(f.writes.length, 0);
|
|
494
|
+
}
|
|
495
|
+
const f = fixture();
|
|
496
|
+
f.live.body = renderIssueBody({ ...ready(), outcome: 'Retain the Todo label when validation passes.' });
|
|
497
|
+
const first = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
498
|
+
assert.ok('reused' in first && first.reused === false);
|
|
499
|
+
assert.ok('reused' in (await startTrackedIssue(f.context, { issueNumber: 17 })));
|
|
500
|
+
assert.equal(f.branchWrites.length, 1);
|
|
501
|
+
assert.equal(f.comments.length, 1);
|
|
502
|
+
});
|
|
503
|
+
test('joined MCP start modes preserve ordinary input and reject mixed investigation or foreign repository calls before configuration', async () => {
|
|
504
|
+
const schema = getAiDeliveryMcpTool('issue_start').inputSchema;
|
|
505
|
+
assert(schema.safeParse({ issueNumber: 17, repo: 'example/widget' }).success);
|
|
506
|
+
assert(schema.safeParse({ body: renderIssueBody(ready()), title: ready().title, points: 2, issueType: 'Task' }).success);
|
|
507
|
+
for (const arguments_ of [
|
|
508
|
+
{ issueNumber: 17, expectedHeadSha: 'a'.repeat(40) },
|
|
509
|
+
{
|
|
510
|
+
issueNumber: 17,
|
|
511
|
+
investigationWorktree: '/fictional/issue-17',
|
|
512
|
+
expectedHeadSha: 'a'.repeat(40),
|
|
513
|
+
body: renderIssueBody(ready()),
|
|
514
|
+
},
|
|
515
|
+
])
|
|
516
|
+
assert.equal(schema.safeParse(arguments_).success, false);
|
|
517
|
+
await assert.rejects(executeTool('issue_start', { repo: 'foreign/widget', issueNumber: 17 }, { repo: 'example/widget', repoRoot: '/synthetic-non-git' }), /selectors disagree/u);
|
|
518
|
+
const finish = getAiDeliveryMcpTool('issue_finish').inputSchema;
|
|
519
|
+
assert(finish.safeParse({ issueNumber: 17, prNumber: 23 }).success);
|
|
520
|
+
assert.equal(finish.safeParse({ issueNumber: 17 }).success, false);
|
|
521
|
+
assert.equal(finish.safeParse({ issueNumber: 17, investigation: true, resultPath: '/fictional/result', prNumber: 23 }).success, false);
|
|
522
|
+
});
|
|
523
|
+
test('created readiness refusal returns exact retry markers through safe resume and original request retry', async () => {
|
|
524
|
+
const f = fixture();
|
|
525
|
+
f.controls.created = false;
|
|
526
|
+
f.controls.trackingParent = true;
|
|
527
|
+
const schema = getAiDeliveryMcpTool('issue_start').inputSchema;
|
|
528
|
+
const request = schema.parse({
|
|
529
|
+
title: ready().title,
|
|
530
|
+
body: renderIssueBody(ready()),
|
|
531
|
+
issueType: 'Task',
|
|
532
|
+
points: 2,
|
|
533
|
+
requestId: 'issue68-readiness-recovery',
|
|
534
|
+
});
|
|
535
|
+
const interrupted = await startTrackedIssue(f.context, request);
|
|
536
|
+
if (interrupted.status !== 'created-not-started')
|
|
537
|
+
assert.fail('Expected a known-created readiness refusal.');
|
|
538
|
+
assert.equal(interrupted.status, 'created-not-started');
|
|
539
|
+
const nativeBody = f.live.body;
|
|
540
|
+
assert.match(nativeBody, /ai-delivery-start-intent: sha256:[a-f0-9]{64}/u);
|
|
541
|
+
assert.match(nativeBody, /ai-delivery-start: sha256:[a-f0-9]{64}/u);
|
|
542
|
+
assert.equal(interrupted.safeResume.arguments.resumeCreated, undefined);
|
|
543
|
+
assert.equal('body' in interrupted.safeResume.arguments, false);
|
|
544
|
+
assert.equal(f.branchWrites.length, 0);
|
|
545
|
+
assert.equal(f.comments.length, 0);
|
|
546
|
+
assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
|
|
547
|
+
f.controls.trackingParent = false;
|
|
548
|
+
const resumed = await startTrackedIssue(f.context, schema.parse(interrupted.safeResume.arguments));
|
|
549
|
+
assert.ok('reused' in resumed && resumed.reused === false);
|
|
550
|
+
assert.equal(f.live.body, nativeBody);
|
|
551
|
+
const retry = await startTrackedIssue(f.context, request);
|
|
552
|
+
assert.ok('reused' in retry && retry.reused === true);
|
|
553
|
+
assert.equal(f.live.body, nativeBody);
|
|
554
|
+
assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
|
|
555
|
+
assert.equal(f.branchWrites.length, 1);
|
|
556
|
+
assert.equal(f.comments.length, 1);
|
|
557
|
+
});
|
|
558
|
+
test('actual compiled stdio MCP returns every Ready diagnostic before credentials and refuses a foreign caller repo', async () => {
|
|
559
|
+
const root = mkdtempSync(join(tmpdir(), 'issue-contract-stdio-'));
|
|
560
|
+
const transport = new StdioClientTransport({
|
|
561
|
+
command: process.execPath,
|
|
562
|
+
args: [resolve('dist/cli.js'), '--identity', 'host-author', '--repo', 'example/widget', 'mcp:serve'],
|
|
563
|
+
cwd: root,
|
|
564
|
+
stderr: 'pipe',
|
|
565
|
+
env: {
|
|
566
|
+
HOME: root,
|
|
567
|
+
PATH: process.env.PATH ?? '',
|
|
568
|
+
AI_DELIVERY_CONFIG: join(root, 'missing-config.json'),
|
|
569
|
+
LANG: 'en_US.UTF-8',
|
|
570
|
+
},
|
|
571
|
+
});
|
|
572
|
+
const client = new Client({ name: 'issue68-synthetic-client', version: '1.0.0' });
|
|
573
|
+
let spawnedPid = null;
|
|
574
|
+
let closeObserved = false;
|
|
575
|
+
try {
|
|
576
|
+
await client.connect(transport);
|
|
577
|
+
spawnedPid = transport.pid;
|
|
578
|
+
assert.ok(spawnedPid);
|
|
579
|
+
const original = transport.onclose;
|
|
580
|
+
transport.onclose = () => {
|
|
581
|
+
closeObserved = true;
|
|
582
|
+
original?.();
|
|
583
|
+
};
|
|
584
|
+
const listing = await client.listTools();
|
|
585
|
+
assert.ok(listing.tools.find((t) => t.name === 'issue_create')?.inputSchema.properties?.acceptanceCriteria);
|
|
586
|
+
const result = await client.callTool({
|
|
587
|
+
name: 'issue_create',
|
|
588
|
+
arguments: { ...ready(), points: 13, openQuestions: ['Select behavior.'] },
|
|
589
|
+
});
|
|
590
|
+
assert.equal(result.isError, true);
|
|
591
|
+
const content = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(result.content);
|
|
592
|
+
const diagnostic = z
|
|
593
|
+
.object({
|
|
594
|
+
contract: z.literal('ai-delivery.issue@1'),
|
|
595
|
+
failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() })),
|
|
596
|
+
})
|
|
597
|
+
.parse(JSON.parse(content[0].text));
|
|
598
|
+
assert.deepEqual(diagnostic.failures.map((f) => f.code).sort(), ['open-questions', 'points']);
|
|
599
|
+
assert.ok(diagnostic.failures.every((f) => f.field && f.fixHint));
|
|
600
|
+
for (const name of ['issue_create', 'issue_update']) {
|
|
601
|
+
const malformed = await client.callTool({
|
|
602
|
+
name,
|
|
603
|
+
arguments: {
|
|
604
|
+
...ready(),
|
|
605
|
+
...(name === 'issue_update' ? { issueNumber: 17 } : {}),
|
|
606
|
+
acceptanceCriteria: [{ behavior: ready().acceptanceCriteria[0].behavior }],
|
|
607
|
+
context: { components: 9 },
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
assert.equal(malformed.isError, true);
|
|
611
|
+
const blocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(malformed.content);
|
|
612
|
+
const failure = z
|
|
613
|
+
.object({
|
|
614
|
+
contract: z.literal('ai-delivery.issue@1'),
|
|
615
|
+
failures: z.array(z.object({ code: z.string(), field: z.string(), fixHint: z.string() })),
|
|
616
|
+
})
|
|
617
|
+
.parse(JSON.parse(blocks[0].text));
|
|
618
|
+
assert.deepEqual(failure.failures.map((f) => f.field).sort(), [
|
|
619
|
+
'acceptanceCriteria.0.verifiedBy',
|
|
620
|
+
'context.components',
|
|
621
|
+
]);
|
|
622
|
+
assert.ok(failure.failures.every((f) => f.code && f.fixHint));
|
|
623
|
+
assert.doesNotMatch(blocks[0].text, /missing-config/u);
|
|
624
|
+
const unknown = await client.callTool({
|
|
625
|
+
name,
|
|
626
|
+
arguments: {
|
|
627
|
+
...ready(),
|
|
628
|
+
...(name === 'issue_update' ? { issueNumber: 17 } : {}),
|
|
629
|
+
unexpectedField: 'Root field must be refused.',
|
|
630
|
+
context: { ...ready().context, unexpectedField: 'Nested field must be refused.' },
|
|
631
|
+
acceptanceCriteria: [{ ...ready().acceptanceCriteria[0], unexpectedField: 'Unknown criterion field.' }],
|
|
632
|
+
},
|
|
633
|
+
});
|
|
634
|
+
assert.equal(unknown.isError, true);
|
|
635
|
+
const unknownBlocks = z.array(z.object({ type: z.literal('text'), text: z.string() })).parse(unknown.content);
|
|
636
|
+
const unknownFailure = z
|
|
637
|
+
.object({
|
|
638
|
+
contract: z.literal('ai-delivery.issue@1'),
|
|
639
|
+
failures: z.array(z.object({ code: z.literal('field.unknown'), field: z.string(), fixHint: z.string() })),
|
|
640
|
+
})
|
|
641
|
+
.parse(JSON.parse(unknownBlocks[0].text));
|
|
642
|
+
assert.deepEqual(unknownFailure.failures.map((f) => f.field).sort(), [
|
|
643
|
+
'acceptanceCriteria.0',
|
|
644
|
+
'context',
|
|
645
|
+
'issue',
|
|
646
|
+
]);
|
|
647
|
+
assert.ok(unknownFailure.failures.every((f) => f.fixHint.length > 10));
|
|
648
|
+
assert.doesNotMatch(unknownBlocks[0].text, /unexpectedField|Nested field|Unknown criterion/u, 'Diagnostics do not echo untrusted keys or values.');
|
|
649
|
+
}
|
|
650
|
+
const foreign = await client.callTool({ name: 'issue_create', arguments: { ...ready(), repo: 'other/widget' } });
|
|
651
|
+
assert.equal(foreign.isError, true);
|
|
652
|
+
assert.match(JSON.stringify(foreign.content), /repository selectors disagree/u);
|
|
653
|
+
}
|
|
654
|
+
finally {
|
|
655
|
+
await client.close();
|
|
656
|
+
assert.equal(closeObserved, true, 'SDK spawned-child close event was actually observed');
|
|
657
|
+
rmSync(root, { recursive: true, force: true });
|
|
658
|
+
console.info(JSON.stringify({
|
|
659
|
+
fixture: 'issue68-compiled-stdio',
|
|
660
|
+
spawnedPid,
|
|
661
|
+
childCloseObserved: closeObserved,
|
|
662
|
+
syntheticRootRemoved: true,
|
|
663
|
+
}));
|
|
664
|
+
}
|
|
665
|
+
});
|
|
666
|
+
test('intake skill example is Ready and every CLI line has actual required options and an explicit identity', () => {
|
|
667
|
+
const skill = readFileSync(resolve('plugins/ai-delivery/skills/intake-create/SKILL.md'), 'utf8');
|
|
668
|
+
const json = /```json\n([\s\S]*?)\n```/u.exec(skill)?.[1];
|
|
669
|
+
assert.ok(json);
|
|
670
|
+
assert.ok(ReadyIssue.safeParse(JSON.parse(json)).success);
|
|
671
|
+
const root = mkdtempSync(join(tmpdir(), 'intake-cli-'));
|
|
672
|
+
try {
|
|
673
|
+
const fields = join(root, 'issue.json');
|
|
674
|
+
writeFileSync(fields, json);
|
|
675
|
+
for (const line of skill.split('\n').filter((line) => line.startsWith('ai-delivery '))) {
|
|
676
|
+
assert.match(line, /--identity host-author/u);
|
|
677
|
+
assert.match(line, /--repo example\/widget/u);
|
|
678
|
+
const argv = (line.match(/'[^']*'|[^\s]+/gu) ?? [])
|
|
679
|
+
.slice(1)
|
|
680
|
+
.map((token) => token.replace(/^'|'$/gu, ''))
|
|
681
|
+
.map((token) => token.replace('/owned/issue.json', fields));
|
|
682
|
+
const command = argv.find((token) => ['create', 'update', 'info', 'ready:check', 'start'].includes(token));
|
|
683
|
+
assert.ok(command);
|
|
684
|
+
assert.ok(argv.includes(command === 'create' ? '--title' : '--issue'));
|
|
685
|
+
const result = spawnSync(process.execPath, [resolve('dist/cli.js'), ...argv], {
|
|
686
|
+
cwd: root,
|
|
687
|
+
env: {
|
|
688
|
+
PATH: process.env.PATH ?? '',
|
|
689
|
+
HOME: root,
|
|
690
|
+
AI_DELIVERY_CONFIG: join(root, 'missing-config.json'),
|
|
691
|
+
LANG: 'en_US.UTF-8',
|
|
692
|
+
},
|
|
693
|
+
encoding: 'utf8',
|
|
694
|
+
});
|
|
695
|
+
assert.notEqual(result.status, 0);
|
|
696
|
+
assert.doesNotMatch(result.stderr, /unknown option|unknown command|required option/u);
|
|
697
|
+
assert.match(result.stderr, /missing-config|ENOENT|identity|configuration|config/iu);
|
|
698
|
+
}
|
|
699
|
+
const missing = spawnSync(process.execPath, [resolve('dist/cli.js'), '--identity', 'host-author', '--repo', 'example/widget', 'create'], { cwd: root, env: { HOME: root, PATH: process.env.PATH ?? '' }, encoding: 'utf8' });
|
|
700
|
+
assert.match(missing.stderr, /required option.*--title/u);
|
|
701
|
+
assert.ok(execFileSync(process.execPath, [resolve('dist/cli.js'), '--help'], {
|
|
702
|
+
env: { HOME: root, PATH: process.env.PATH ?? '' },
|
|
703
|
+
encoding: 'utf8',
|
|
704
|
+
}).includes('create'));
|
|
705
|
+
}
|
|
706
|
+
finally {
|
|
707
|
+
rmSync(root, { recursive: true, force: true });
|
|
708
|
+
}
|
|
709
|
+
assert.ok(skill.includes(ISSUE_BODY_MARKER));
|
|
710
|
+
assert.ok(!skill.includes('ai-delivery develop'));
|
|
711
|
+
});
|
|
712
|
+
test('explicit start changes Todo to the configured In Progress option and preserves unrelated items', async () => {
|
|
713
|
+
const f = fixture();
|
|
714
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
715
|
+
assert.ok('branch' in result);
|
|
716
|
+
assert.equal(f.getStatus(), 'Active');
|
|
717
|
+
assert.equal(f.statusWrites.length, 1);
|
|
718
|
+
assert.deepEqual(f.statusWrites[0], {
|
|
719
|
+
projectId: 'PROJECT',
|
|
720
|
+
itemId: 'ITEM17',
|
|
721
|
+
fieldId: 'STATUS',
|
|
722
|
+
optionId: 'ACTIVE',
|
|
723
|
+
});
|
|
724
|
+
assert.equal(f.comments.length, 1);
|
|
725
|
+
const retry = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
726
|
+
assert.ok('reused' in retry && retry.reused);
|
|
727
|
+
assert.equal(f.branchWrites.length, 1);
|
|
728
|
+
assert.equal(f.statusWrites.length, 1);
|
|
729
|
+
assert.equal(f.comments.length, 1);
|
|
730
|
+
});
|
|
731
|
+
test('explicit start adds missing membership only for its exact issue and accepts already active status', async () => {
|
|
732
|
+
for (const member of [true, false]) {
|
|
733
|
+
const f = fixture();
|
|
734
|
+
f.controls.projectMember = member;
|
|
735
|
+
if (member)
|
|
736
|
+
f.setStatus('Active');
|
|
737
|
+
assert.ok('branch' in (await startTrackedIssue(f.context, { issueNumber: 17 })));
|
|
738
|
+
assert.equal(f.getStatus(), 'Active');
|
|
739
|
+
assert.equal(f.membershipWrites.length, member ? 0 : 1);
|
|
740
|
+
assert.equal(f.statusWrites.length, member ? 0 : 1);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
test.each(['before', 'after', 'readback'])('existing start returns known-issue recovery for Project %s failure', async (failure) => {
|
|
744
|
+
const f = fixture();
|
|
745
|
+
f.controls.projectFailure = failure;
|
|
746
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
747
|
+
if (!('status' in result))
|
|
748
|
+
assert.fail('Project failure must not report successful start');
|
|
749
|
+
assert.equal(result.status, 'start-incomplete');
|
|
750
|
+
assert.equal(result.failure.phase, 'project-status');
|
|
751
|
+
assert.equal(result.safeResume.arguments.issueNumber, 17);
|
|
752
|
+
assert.equal(result.safeResume.arguments.repo, 'example/widget');
|
|
753
|
+
assert.equal(result.safeResume.arguments.branch, 'issue/17');
|
|
754
|
+
assert.equal(f.comments.length, 0);
|
|
755
|
+
f.controls.projectFailure = '';
|
|
756
|
+
const resumed = await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments));
|
|
757
|
+
assert.ok('reused' in resumed && resumed.reused);
|
|
758
|
+
assert.equal(f.getStatus(), 'Active');
|
|
759
|
+
assert.equal(f.branchWrites.length, 1);
|
|
760
|
+
assert.equal(f.comments.length, 1);
|
|
761
|
+
assert.equal(f.writes.length, 0);
|
|
762
|
+
assert.equal(f.statusWrites.length, failure === 'before' ? 2 : 1);
|
|
763
|
+
});
|
|
764
|
+
test.each(['branch', 'journal'])('existing start reconciles a lost %s response without duplicate mutations', async (failure) => {
|
|
765
|
+
const f = fixture();
|
|
766
|
+
f.controls.branchFailure = failure === 'branch';
|
|
767
|
+
f.controls.journalFailure = failure === 'journal';
|
|
768
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
769
|
+
if (!('status' in result))
|
|
770
|
+
assert.fail('An uncertain start must retain recovery');
|
|
771
|
+
assert.equal(result.status, 'start-incomplete');
|
|
772
|
+
f.controls.branchFailure = false;
|
|
773
|
+
f.controls.journalFailure = false;
|
|
774
|
+
assert.ok('reused' in (await startTrackedIssue(f.context, result.safeResume.arguments)));
|
|
775
|
+
assert.equal(f.branchWrites.length, 1);
|
|
776
|
+
assert.equal(f.comments.length, 1);
|
|
777
|
+
assert.equal(f.getStatus(), 'Active');
|
|
778
|
+
});
|
|
779
|
+
test('created start retains its exact issue recovery when Project synchronization fails', async () => {
|
|
780
|
+
const f = fixture();
|
|
781
|
+
f.controls.created = false;
|
|
782
|
+
f.controls.projectFailure = 'before';
|
|
783
|
+
const request = {
|
|
784
|
+
title: ready().title,
|
|
785
|
+
body: renderIssueBody(ready()),
|
|
786
|
+
issueType: 'Task',
|
|
787
|
+
points: 2,
|
|
788
|
+
requestId: 'project-recovery',
|
|
789
|
+
};
|
|
790
|
+
const result = await startTrackedIssue(f.context, request);
|
|
791
|
+
if (!('status' in result))
|
|
792
|
+
assert.fail('Expected created recovery');
|
|
793
|
+
assert.equal(result.status, 'created-not-started');
|
|
794
|
+
assert.equal(result.failure.phase, 'project-status');
|
|
795
|
+
f.controls.projectFailure = '';
|
|
796
|
+
assert.ok('reused' in (await startTrackedIssue(f.context, result.safeResume.arguments)));
|
|
797
|
+
assert.equal(f.branchWrites.length, 1);
|
|
798
|
+
assert.equal(f.comments.length, 1);
|
|
799
|
+
assert.equal(f.writes.filter((write) => !('issue_number' in write)).length, 1);
|
|
800
|
+
assert.equal(f.getStatus(), 'Active');
|
|
801
|
+
});
|
|
802
|
+
test.each(['closed', 'blocked', 'parked', 'archived'])('start recovery refuses current %s truth before Project or journal writes', async (state) => {
|
|
803
|
+
const f = fixture();
|
|
804
|
+
f.controls.branchFailure = true;
|
|
805
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
806
|
+
if (result.status !== 'start-incomplete')
|
|
807
|
+
assert.fail('Expected recovery');
|
|
808
|
+
f.controls.branchFailure = false;
|
|
809
|
+
if (state === 'closed')
|
|
810
|
+
f.live.state = 'closed';
|
|
811
|
+
if (state === 'blocked')
|
|
812
|
+
f.controls.blockers = true;
|
|
813
|
+
if (state === 'parked')
|
|
814
|
+
f.live.body = renderIssueBody({ ...ready(), draft: true });
|
|
815
|
+
if (state === 'archived')
|
|
816
|
+
f.controls.projectArchived = true;
|
|
817
|
+
const retry = await startTrackedIssue(f.context, result.safeResume.arguments).catch((error) => {
|
|
818
|
+
assert.ok(error instanceof Error);
|
|
819
|
+
return undefined;
|
|
820
|
+
});
|
|
821
|
+
assert.ok(retry === undefined || 'status' in retry, 'Current refusal must not report success');
|
|
822
|
+
assert.equal(f.branchWrites.length, 1);
|
|
823
|
+
assert.equal(f.statusWrites.length, 0);
|
|
824
|
+
assert.equal(f.comments.length, 0);
|
|
825
|
+
});
|
|
826
|
+
test.each(['closeAfterBranch', 'blockAfterBranch'])('start rechecks live eligibility after %s before changing the board', async (control) => {
|
|
827
|
+
const f = fixture();
|
|
828
|
+
f.controls[control] = true;
|
|
829
|
+
const result = await startTrackedIssue(f.context, { issueNumber: 17 });
|
|
830
|
+
assert.ok('status' in result);
|
|
831
|
+
assert.equal(f.statusWrites.length, 0);
|
|
832
|
+
assert.equal(f.comments.length, 0);
|
|
833
|
+
});
|
|
834
|
+
async function bindStartFixture(f) {
|
|
835
|
+
const settings = await import('./config/deliveryConfig.js');
|
|
836
|
+
const issues = await import('./issue.js');
|
|
837
|
+
vi.spyOn(settings, 'loadDeliverySettings').mockResolvedValue({
|
|
838
|
+
roles: { author: { identity: 'author', authSource: 'personal' }, reviewer: { identity: 'reviewer' } },
|
|
839
|
+
});
|
|
840
|
+
vi.spyOn(issues, 'loadDeliveryContext').mockResolvedValue(f.context);
|
|
841
|
+
}
|
|
842
|
+
test('MCP explicit start returns Project recovery and reuses the exact branch on retry', async () => {
|
|
843
|
+
const f = fixture();
|
|
844
|
+
await bindStartFixture(f);
|
|
845
|
+
f.controls.projectFailure = 'after';
|
|
846
|
+
const server = createAiDeliveryMcpServer({ repoRoot: '/unrelated' });
|
|
847
|
+
const client = new Client({ name: 'fictional-start-project', version: '1.0.0' });
|
|
848
|
+
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
|
849
|
+
try {
|
|
850
|
+
await server.connect(serverTransport);
|
|
851
|
+
await client.connect(clientTransport);
|
|
852
|
+
const call = async (arguments_) => {
|
|
853
|
+
const reply = await client.callTool({ name: 'issue_start', arguments: arguments_ });
|
|
854
|
+
assert.equal(reply.isError, undefined);
|
|
855
|
+
return JSON.parse(z.object({ content: z.array(z.object({ type: z.literal('text'), text: z.string() })) }).parse(reply).content[0]
|
|
856
|
+
.text);
|
|
857
|
+
};
|
|
858
|
+
const interrupted = await call({ repo: 'example/widget', issueNumber: 17 });
|
|
859
|
+
assert.equal(interrupted.status, 'start-incomplete');
|
|
860
|
+
assert.ok(interrupted.safeResume);
|
|
861
|
+
assert.equal(f.comments.length, 0);
|
|
862
|
+
f.controls.projectFailure = '';
|
|
863
|
+
const result = await call(interrupted.safeResume.arguments);
|
|
864
|
+
assert.equal(result.branch, 'issue/17');
|
|
865
|
+
assert.equal(result.issueNumber, 17);
|
|
866
|
+
assert.equal(f.getStatus(), 'Active');
|
|
867
|
+
assert.equal(f.statusWrites.length, 1);
|
|
868
|
+
assert.equal(f.branchWrites.length, 1);
|
|
869
|
+
assert.equal(f.comments.length, 1);
|
|
870
|
+
}
|
|
871
|
+
finally {
|
|
872
|
+
await client.close();
|
|
873
|
+
await server.close();
|
|
874
|
+
}
|
|
875
|
+
});
|
|
876
|
+
test.each(['success', 'failure'])('CLI explicit start shares Project transition and %s output', async (mode) => {
|
|
877
|
+
vi.resetModules();
|
|
878
|
+
const f = fixture();
|
|
879
|
+
await bindStartFixture(f);
|
|
880
|
+
if (mode === 'failure')
|
|
881
|
+
f.controls.projectFailure = 'before';
|
|
882
|
+
const argv = process.argv;
|
|
883
|
+
const exitCode = process.exitCode;
|
|
884
|
+
let stdout = '';
|
|
885
|
+
let completed = () => { };
|
|
886
|
+
const output = new Promise((resolve) => {
|
|
887
|
+
completed = resolve;
|
|
888
|
+
});
|
|
889
|
+
vi.spyOn(process.stdout, 'write').mockImplementation((value) => {
|
|
890
|
+
stdout += String(value);
|
|
891
|
+
if (String(value).startsWith('{'))
|
|
892
|
+
completed();
|
|
893
|
+
return true;
|
|
894
|
+
});
|
|
895
|
+
try {
|
|
896
|
+
process.exitCode = undefined;
|
|
897
|
+
process.argv = [process.execPath, 'ai-delivery', '--repo', 'example/widget', 'start', '--issue', '17'];
|
|
898
|
+
await import('./cli.js');
|
|
899
|
+
await output;
|
|
900
|
+
const result = JSON.parse(stdout);
|
|
901
|
+
if (mode === 'failure') {
|
|
902
|
+
assert.equal(result.status, 'start-incomplete');
|
|
903
|
+
assert.equal(result.safeResume?.arguments.issueNumber, 17);
|
|
904
|
+
assert.equal(process.exitCode, 1);
|
|
905
|
+
assert.equal(f.getStatus(), 'Queued');
|
|
906
|
+
assert.equal(f.comments.length, 0);
|
|
907
|
+
}
|
|
908
|
+
else {
|
|
909
|
+
assert.equal(result.branch, 'issue/17');
|
|
910
|
+
assert.equal(process.exitCode, undefined);
|
|
911
|
+
assert.equal(f.getStatus(), 'Active');
|
|
912
|
+
assert.equal(f.comments.length, 1);
|
|
913
|
+
}
|
|
914
|
+
assert.equal(f.branchWrites.length, 1);
|
|
915
|
+
assert.equal(f.statusWrites.length, 1);
|
|
916
|
+
}
|
|
917
|
+
finally {
|
|
918
|
+
process.argv = argv;
|
|
919
|
+
process.exitCode = exitCode;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
test('info and unrelated body edits never imply explicit activation', async () => {
|
|
923
|
+
const f = fixture();
|
|
924
|
+
const { issueInfo } = await import('./issue.js');
|
|
925
|
+
await issueInfo(f.context, 17);
|
|
926
|
+
await updateIssue(f.context, {
|
|
927
|
+
issueNumber: 17,
|
|
928
|
+
outcome: 'Reject invalid widgets while retaining deferred execution.',
|
|
929
|
+
});
|
|
930
|
+
assert.equal(f.getStatus(), 'Queued');
|
|
931
|
+
assert.equal(f.statusWrites.length, 0);
|
|
932
|
+
assert.equal(f.branchWrites.length, 0);
|
|
933
|
+
assert.equal(f.comments.length, 0);
|
|
934
|
+
});
|
|
935
|
+
test.each(['project-status', 'journal'])('created recovery after %s preserves a subsequent native park', async (phase) => {
|
|
936
|
+
const f = fixture();
|
|
937
|
+
f.controls.created = false;
|
|
938
|
+
f.controls.projectFailure = phase === 'project-status' ? 'before' : '';
|
|
939
|
+
f.controls.journalFailure = phase === 'journal';
|
|
940
|
+
const result = await startTrackedIssue(f.context, {
|
|
941
|
+
title: ready().title,
|
|
942
|
+
body: renderIssueBody(ready()),
|
|
943
|
+
issueType: 'Task',
|
|
944
|
+
points: 2,
|
|
945
|
+
requestId: 'parked-created-' + phase,
|
|
946
|
+
});
|
|
947
|
+
if (result.status !== 'created-not-started')
|
|
948
|
+
assert.fail('Expected known-created recovery');
|
|
949
|
+
assert.equal(result.failure.phase, phase);
|
|
950
|
+
f.controls.projectFailure = '';
|
|
951
|
+
f.controls.journalFailure = false;
|
|
952
|
+
await updateIssue(f.context, { issueNumber: 17, park: true });
|
|
953
|
+
const parkedBody = f.live.body;
|
|
954
|
+
const writesBeforeRetry = f.writes.length;
|
|
955
|
+
const statusWritesBeforeRetry = f.statusWrites.length;
|
|
956
|
+
const commentsBeforeRetry = f.comments.length;
|
|
957
|
+
const retry = await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments)).catch((error) => {
|
|
958
|
+
assert.ok(error instanceof Error);
|
|
959
|
+
return undefined;
|
|
960
|
+
});
|
|
961
|
+
assert.equal(f.live.body, parkedBody);
|
|
962
|
+
assert.equal(parseIssueBody(f.live.body, { title: f.live.title }).issue.draft, true);
|
|
963
|
+
assert.equal(f.getStatus(), 'Queued');
|
|
964
|
+
assert.ok(retry === undefined || retry.status !== undefined, 'Parked recovery must not succeed');
|
|
965
|
+
assert.equal(f.writes.length, writesBeforeRetry);
|
|
966
|
+
assert.equal(f.statusWrites.length, statusWritesBeforeRetry);
|
|
967
|
+
assert.equal(f.comments.length, commentsBeforeRetry);
|
|
968
|
+
assert.equal(f.branchWrites.length, 1);
|
|
969
|
+
});
|
|
970
|
+
test('created post-tracking recovery preserves later ready content without replaying tracking writes', async () => {
|
|
971
|
+
const f = fixture();
|
|
972
|
+
f.controls.created = false;
|
|
973
|
+
f.controls.projectFailure = 'before';
|
|
974
|
+
const result = await startTrackedIssue(f.context, {
|
|
975
|
+
title: ready().title,
|
|
976
|
+
body: renderIssueBody(ready()),
|
|
977
|
+
issueType: 'Task',
|
|
978
|
+
points: 2,
|
|
979
|
+
requestId: 'edited-created-recovery',
|
|
980
|
+
});
|
|
981
|
+
if (result.status !== 'created-not-started')
|
|
982
|
+
assert.fail('Expected known-created recovery');
|
|
983
|
+
f.controls.projectFailure = '';
|
|
984
|
+
await updateIssue(f.context, { issueNumber: 17, outcome: 'Deliver the revised current acceptance evidence.' });
|
|
985
|
+
const revised = f.live.body;
|
|
986
|
+
const writes = f.writes.length;
|
|
987
|
+
assert.ok('reused' in
|
|
988
|
+
(await startTrackedIssue(f.context, getAiDeliveryMcpTool('issue_start').inputSchema.parse(result.safeResume.arguments))));
|
|
989
|
+
assert.equal(f.live.body, revised);
|
|
990
|
+
assert.equal(f.writes.length, writes);
|
|
991
|
+
assert.equal(f.branchWrites.length, 1);
|
|
992
|
+
assert.equal(f.getStatus(), 'Active');
|
|
993
|
+
});
|
|
994
|
+
//# sourceMappingURL=issueIntake.test.js.map
|