@aviaratech/ai-delivery 0.3.25 → 0.3.26
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 +104 -9
- 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/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 +1 -0
- package/dist/dispatch.js +47 -4
- 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 +22 -6
- package/dist/issue.js +152 -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 +649 -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 +238 -1
- package/dist/pr.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 +30 -3
- package/dist/start.test.js.map +1 -1
- package/dist/stdoutRegression.test.js +36 -6
- package/dist/stdoutRegression.test.js.map +1 -1
- 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,713 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, unlinkSync, writeFileSync, } from 'node:fs';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { basename, join } from 'node:path';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
7
|
+
import { onTestFinished, vi } from 'vitest';
|
|
8
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
9
|
+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
|
|
10
|
+
import * as githubClients from '../github/client.js';
|
|
11
|
+
import { IssueFields, renderIssueBody } from '../issueContract.js';
|
|
12
|
+
import { digestBytes, digestValue } from '../delivery/common.js';
|
|
13
|
+
import { createAiDeliveryMcpServer } from '../mcp/index.js';
|
|
14
|
+
import { syntheticDiscoveryClients } from './discovery.js';
|
|
15
|
+
export const fixtureFields = IssueFields.parse({
|
|
16
|
+
title: 'Reject invalid widget identifiers before persistence',
|
|
17
|
+
issueType: 'Task',
|
|
18
|
+
points: 2,
|
|
19
|
+
problem: 'Invalid widget identifiers currently reach persistence.',
|
|
20
|
+
outcome: 'Reject invalid identifiers before any persistence call.',
|
|
21
|
+
acceptanceCriteria: [
|
|
22
|
+
{
|
|
23
|
+
behavior: 'Invalid identifiers return an error with zero persistence calls.',
|
|
24
|
+
verifiedBy: 'Synthetic port regression test; node consumer-trap.cjs and npm run trap are inert verification prose.',
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
outOfScope: ['Storage format changes.'],
|
|
28
|
+
context: { components: ['Widget validation'], files: [], evidence: [] },
|
|
29
|
+
});
|
|
30
|
+
/** All Git operations act on an owned fictional consumer and ignore host Git configuration. */
|
|
31
|
+
export function fixtureGit(root, ...args) {
|
|
32
|
+
return execFileSync('git', ['-c', 'core.hooksPath=/dev/null', '-c', 'core.fsmonitor=false', '-c', 'credential.helper=', '-C', root, ...args], {
|
|
33
|
+
encoding: 'utf8',
|
|
34
|
+
timeout: 5_000,
|
|
35
|
+
maxBuffer: 64 * 1024,
|
|
36
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
37
|
+
env: {
|
|
38
|
+
PATH: process.env.PATH,
|
|
39
|
+
HOME: tmpdir(),
|
|
40
|
+
GIT_CONFIG_NOSYSTEM: '1',
|
|
41
|
+
GIT_CONFIG_GLOBAL: '/dev/null',
|
|
42
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
43
|
+
GIT_AUTHOR_NAME: 'Fictional Operator',
|
|
44
|
+
GIT_AUTHOR_EMAIL: 'operator@example.invalid',
|
|
45
|
+
GIT_COMMITTER_NAME: 'Fictional Operator',
|
|
46
|
+
GIT_COMMITTER_EMAIL: 'operator@example.invalid',
|
|
47
|
+
},
|
|
48
|
+
}).trim();
|
|
49
|
+
}
|
|
50
|
+
let fixtureOwner;
|
|
51
|
+
/** Only these external HTTP/authentication ports are replaced. No resolver or owner is mocked. */
|
|
52
|
+
export function inertTarget(signal, registerDisposal = (cleanup) => onTestFinished(cleanup)) {
|
|
53
|
+
assert.equal(fixtureOwner, undefined, 'The previous fixture must finish disposal before another owns global ports');
|
|
54
|
+
signal?.throwIfAborted();
|
|
55
|
+
const base = realpathSync(mkdtempSync(join(tmpdir(), 'ai-delivery-inert-target-')));
|
|
56
|
+
const owned = lstatSync(base);
|
|
57
|
+
const owner = Symbol('inert-target');
|
|
58
|
+
fixtureOwner = owner;
|
|
59
|
+
const shutdown = new AbortController();
|
|
60
|
+
const fixtureSignal = signal === undefined ? shutdown.signal : AbortSignal.any([shutdown.signal, signal]);
|
|
61
|
+
const activeCalls = new Set();
|
|
62
|
+
const connections = new Set();
|
|
63
|
+
const userPath = join(base, 'user.json');
|
|
64
|
+
const previousConfig = process.env.AI_DELIVERY_CONFIG;
|
|
65
|
+
let configInstalled = false;
|
|
66
|
+
let restoreClients;
|
|
67
|
+
const restoreGlobals = () => {
|
|
68
|
+
assert.equal(fixtureOwner, owner, "A disposed fixture must not restore another fixture's globals");
|
|
69
|
+
try {
|
|
70
|
+
restoreClients?.();
|
|
71
|
+
if (configInstalled) {
|
|
72
|
+
assert.equal(process.env.AI_DELIVERY_CONFIG, userPath, 'Fixture configuration ownership changed');
|
|
73
|
+
if (previousConfig === undefined)
|
|
74
|
+
delete process.env.AI_DELIVERY_CONFIG;
|
|
75
|
+
else
|
|
76
|
+
process.env.AI_DELIVERY_CONFIG = previousConfig;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
finally {
|
|
80
|
+
fixtureOwner = undefined;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
try {
|
|
84
|
+
const observations = [];
|
|
85
|
+
const root = join(base, 'consumer');
|
|
86
|
+
const sentinel = join(base, 'policy-executed');
|
|
87
|
+
mkdirSync(root);
|
|
88
|
+
fixtureGit(root, 'init', '-q', '-b', 'main');
|
|
89
|
+
fixtureGit(root, 'remote', 'add', 'origin', 'https://github.com/example/widget.git');
|
|
90
|
+
writeFileSync(join(root, '.gitignore'), '.worktrees/\n.issue-cli/\n');
|
|
91
|
+
writeFileSync(join(root, 'change.ts'), 'export const fictional = true;\n');
|
|
92
|
+
const payload = (marker) => `import {writeFileSync} from 'node:fs';writeFileSync(${JSON.stringify(sentinel)},JSON.stringify({marker:${JSON.stringify(marker)},module:import.meta.url}),{flag:'wx'});export const deliverySettings={};\n`;
|
|
93
|
+
const tracked = payload('tracked'), edited = payload('edited');
|
|
94
|
+
writeFileSync(join(root, 'ai-delivery.policy.mjs'), tracked);
|
|
95
|
+
fixtureGit(root, 'add', '.');
|
|
96
|
+
fixtureGit(root, 'commit', '-qm', 'Owned inert consumer');
|
|
97
|
+
const head = fixtureGit(root, 'rev-parse', 'HEAD');
|
|
98
|
+
const tree = fixtureGit(root, 'rev-parse', 'HEAD^{tree}');
|
|
99
|
+
fixtureGit(root, 'update-ref', 'refs/remotes/origin/main', head);
|
|
100
|
+
writeFileSync(userPath, JSON.stringify({
|
|
101
|
+
schemaVersion: 'ai-delivery.user@1',
|
|
102
|
+
roles: {
|
|
103
|
+
author: { authSource: 'personal', identity: 'author', credentialEnv: { token: 'FICTIONAL_AUTHOR_TOKEN' } },
|
|
104
|
+
reviewer: {
|
|
105
|
+
identity: 'reviewer',
|
|
106
|
+
credentialEnv: {
|
|
107
|
+
appId: 'FICTIONAL_REVIEW_APP',
|
|
108
|
+
installationId: 'FICTIONAL_REVIEW_INSTALL',
|
|
109
|
+
privateKeyPath: 'FICTIONAL_REVIEW_KEY',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
checkoutRoots: [base],
|
|
114
|
+
project: 1,
|
|
115
|
+
pointsField: 'Estimate',
|
|
116
|
+
priorityField: 'Urgency',
|
|
117
|
+
statusField: 'Flow',
|
|
118
|
+
statuses: { blocked: 'Waiting', done: 'Shipped', inProgress: 'Active', todo: 'Queued' },
|
|
119
|
+
issueTypes: ['Task'],
|
|
120
|
+
}), { mode: 0o600 });
|
|
121
|
+
process.env.AI_DELIVERY_CONFIG = userPath;
|
|
122
|
+
configInstalled = true;
|
|
123
|
+
const calls = [];
|
|
124
|
+
const record = (name, input = null) => {
|
|
125
|
+
calls.push({ name, input });
|
|
126
|
+
};
|
|
127
|
+
const state = {
|
|
128
|
+
title: fixtureFields.title,
|
|
129
|
+
body: renderIssueBody(fixtureFields),
|
|
130
|
+
issueState: 'open',
|
|
131
|
+
points: '2',
|
|
132
|
+
priority: 'High',
|
|
133
|
+
projectOption: 'STATUS-0',
|
|
134
|
+
linked: true,
|
|
135
|
+
published: true,
|
|
136
|
+
draft: false,
|
|
137
|
+
prTitle: 'Reject invalid widget identifiers',
|
|
138
|
+
prBody: 'Closes #17',
|
|
139
|
+
merged: false,
|
|
140
|
+
closedCount: 0,
|
|
141
|
+
reviewDecision: 'APPROVED',
|
|
142
|
+
mergeAckLost: false,
|
|
143
|
+
};
|
|
144
|
+
const artifactContent = {
|
|
145
|
+
authorIdentity: 'author',
|
|
146
|
+
reviewerIdentity: 'reviewer',
|
|
147
|
+
checks: ['Synthetic focused regression'],
|
|
148
|
+
diffScopeHash: digestValue(['change.ts']),
|
|
149
|
+
elapsedMs: 1,
|
|
150
|
+
findings: [],
|
|
151
|
+
head: { sha: head, tree },
|
|
152
|
+
issueNumber: 17,
|
|
153
|
+
prNumber: 23,
|
|
154
|
+
readOnly: true,
|
|
155
|
+
requestedEffort: 'xhigh',
|
|
156
|
+
requestedModel: 'gpt-6-astra',
|
|
157
|
+
effectiveEffort: 'unknown',
|
|
158
|
+
effectiveModel: 'unknown',
|
|
159
|
+
schemaVersion: 'ai-delivery.review-artifact@1',
|
|
160
|
+
summary: 'Fictional independent review.',
|
|
161
|
+
verdict: 'approve',
|
|
162
|
+
};
|
|
163
|
+
const artifact = { ...artifactContent, artifactId: digestValue(artifactContent) };
|
|
164
|
+
const artifactPath = join(base, 'review.json');
|
|
165
|
+
writeFileSync(artifactPath, JSON.stringify(artifact), { mode: 0o600 });
|
|
166
|
+
const reviewBody = `${artifact.summary}\n\n<!-- ai-delivery-review-artifact: ${artifact.artifactId} -->\n<!-- ai-delivery-review-artifact-data: ${Buffer.from(JSON.stringify(artifact)).toString('base64url')} -->`;
|
|
167
|
+
const review = {
|
|
168
|
+
id: 99,
|
|
169
|
+
user: { login: 'reviewer[bot]', id: 99, type: 'Bot' },
|
|
170
|
+
state: 'APPROVED',
|
|
171
|
+
commit_id: head,
|
|
172
|
+
body: reviewBody,
|
|
173
|
+
html_url: 'https://github.com/example/widget/pull/23#pullrequestreview-99',
|
|
174
|
+
};
|
|
175
|
+
const reviews = [review];
|
|
176
|
+
const comments = [];
|
|
177
|
+
const addComment = (id, body, app = false) => {
|
|
178
|
+
const comment = {
|
|
179
|
+
id,
|
|
180
|
+
body,
|
|
181
|
+
html_url: `https://github.com/example/widget/issues/17#issuecomment-${id}`,
|
|
182
|
+
issue_url: 'https://api.github.com/repos/example/widget/issues/17',
|
|
183
|
+
created_at: new Date(Date.now() + 1000).toISOString(),
|
|
184
|
+
user: app ? { id: 99, login: 'reviewer[bot]', type: 'Bot' } : { id: 42, login: 'operator', type: 'User' },
|
|
185
|
+
};
|
|
186
|
+
comments.push(comment);
|
|
187
|
+
return comment;
|
|
188
|
+
};
|
|
189
|
+
const issue = (number = 17) => ({
|
|
190
|
+
number,
|
|
191
|
+
id: 100 + number,
|
|
192
|
+
node_id: `ISSUE${number}`,
|
|
193
|
+
title: state.title,
|
|
194
|
+
body: state.body,
|
|
195
|
+
state: state.issueState,
|
|
196
|
+
state_reason: state.issueState === 'closed' ? 'completed' : null,
|
|
197
|
+
html_url: `https://github.com/example/widget/issues/${number}`,
|
|
198
|
+
created_at: '2026-01-01T00:00:00Z',
|
|
199
|
+
updated_at: '2026-01-02T00:00:00Z',
|
|
200
|
+
labels: [],
|
|
201
|
+
type: { name: 'Task' },
|
|
202
|
+
});
|
|
203
|
+
const pr = () => ({
|
|
204
|
+
number: 23,
|
|
205
|
+
node_id: 'PR23',
|
|
206
|
+
changed_files: 1,
|
|
207
|
+
title: state.prTitle,
|
|
208
|
+
body: state.prBody,
|
|
209
|
+
html_url: 'https://github.com/example/widget/pull/23',
|
|
210
|
+
state: state.merged ? 'closed' : 'open',
|
|
211
|
+
draft: state.draft,
|
|
212
|
+
merged: state.merged,
|
|
213
|
+
merge_commit_sha: state.merged ? 'c'.repeat(40) : null,
|
|
214
|
+
mergeable: true,
|
|
215
|
+
mergeable_state: 'clean',
|
|
216
|
+
head: { sha: head, ref: 'issue/17', repo: { full_name: 'example/widget' } },
|
|
217
|
+
base: { sha: head, ref: 'main', repo: { full_name: 'example/widget' } },
|
|
218
|
+
user: { login: 'operator' },
|
|
219
|
+
});
|
|
220
|
+
const fields = () => [
|
|
221
|
+
{
|
|
222
|
+
issue_field_id: 101,
|
|
223
|
+
issue_field_name: 'Estimate',
|
|
224
|
+
data_type: 'single_select',
|
|
225
|
+
value: state.points,
|
|
226
|
+
single_select_option: { name: state.points },
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
issue_field_id: 102,
|
|
230
|
+
issue_field_name: 'Urgency',
|
|
231
|
+
data_type: 'single_select',
|
|
232
|
+
value: state.priority,
|
|
233
|
+
single_select_option: { name: state.priority },
|
|
234
|
+
},
|
|
235
|
+
];
|
|
236
|
+
const item = () => ({
|
|
237
|
+
id: 'ITEM17',
|
|
238
|
+
isArchived: false,
|
|
239
|
+
project: { id: 'PROJECT-1', number: 1 },
|
|
240
|
+
content: { __typename: 'Issue', id: 'ISSUE17' },
|
|
241
|
+
fieldValueByName: {
|
|
242
|
+
__typename: 'ProjectV2ItemFieldSingleSelectValue',
|
|
243
|
+
optionId: state.projectOption,
|
|
244
|
+
name: ['Queued', 'Active', 'Waiting', 'Shipped'][Number(state.projectOption.slice(-1))],
|
|
245
|
+
field: { id: 'STATUS-FIELD', name: 'Flow' },
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
const rest = {
|
|
249
|
+
request: async (route, input = {}) => {
|
|
250
|
+
record(route, input);
|
|
251
|
+
if (route === 'GET /orgs/{org}/issue-fields')
|
|
252
|
+
return {
|
|
253
|
+
data: [
|
|
254
|
+
{
|
|
255
|
+
id: 101,
|
|
256
|
+
name: 'Estimate',
|
|
257
|
+
data_type: 'single_select',
|
|
258
|
+
options: ['1', '2', '4'].map((name) => ({ name })),
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: 102,
|
|
262
|
+
name: 'Urgency',
|
|
263
|
+
data_type: 'single_select',
|
|
264
|
+
options: ['High', 'Low'].map((name) => ({ name })),
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
};
|
|
268
|
+
if (route === 'POST /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values') {
|
|
269
|
+
const values = input.issue_field_values;
|
|
270
|
+
for (const value of values) {
|
|
271
|
+
if (value.field_id === 101)
|
|
272
|
+
state.points = value.value;
|
|
273
|
+
if (value.field_id === 102)
|
|
274
|
+
state.priority = value.value;
|
|
275
|
+
}
|
|
276
|
+
return { data: fields() };
|
|
277
|
+
}
|
|
278
|
+
if (route === 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values')
|
|
279
|
+
return { data: fields() };
|
|
280
|
+
if (route.includes('rules'))
|
|
281
|
+
return { data: [] };
|
|
282
|
+
throw new Error(`Unexpected synthetic REST route: ${route}`);
|
|
283
|
+
},
|
|
284
|
+
repos: {
|
|
285
|
+
get: async (input) => {
|
|
286
|
+
record('repos.get', input);
|
|
287
|
+
return {
|
|
288
|
+
data: { node_id: 'REPO', full_name: 'example/widget', default_branch: 'main', permissions: { push: true } },
|
|
289
|
+
};
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
git: {
|
|
293
|
+
getRef: async (input) => {
|
|
294
|
+
record('git.getRef', input);
|
|
295
|
+
return { data: { ref: `refs/${input.ref}`, object: { type: 'commit', sha: head } } };
|
|
296
|
+
},
|
|
297
|
+
getCommit: async (input) => {
|
|
298
|
+
record('git.getCommit', input);
|
|
299
|
+
return { data: { sha: head, tree: { sha: tree } } };
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
issues: {
|
|
303
|
+
get: async (input) => {
|
|
304
|
+
record('issues.get', input);
|
|
305
|
+
return { data: issue() };
|
|
306
|
+
},
|
|
307
|
+
create: async (input) => {
|
|
308
|
+
record('issues.create', input);
|
|
309
|
+
state.title = input.title;
|
|
310
|
+
state.body = input.body;
|
|
311
|
+
return { data: issue() };
|
|
312
|
+
},
|
|
313
|
+
update: async (input) => {
|
|
314
|
+
record('issues.update', input);
|
|
315
|
+
if (input.title !== undefined)
|
|
316
|
+
state.title = input.title;
|
|
317
|
+
if (input.body !== undefined)
|
|
318
|
+
state.body = input.body;
|
|
319
|
+
if (input.state !== undefined) {
|
|
320
|
+
state.issueState = input.state;
|
|
321
|
+
if (input.state === 'closed')
|
|
322
|
+
state.closedCount++;
|
|
323
|
+
}
|
|
324
|
+
return { data: issue() };
|
|
325
|
+
},
|
|
326
|
+
listForRepo: async (input) => {
|
|
327
|
+
record('issues.listForRepo', input);
|
|
328
|
+
return { data: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()] };
|
|
329
|
+
},
|
|
330
|
+
listLabelsForRepo: async () => ({ data: [] }),
|
|
331
|
+
listSubIssues: async () => ({ data: [] }),
|
|
332
|
+
listComments: async (input) => {
|
|
333
|
+
record('issues.listComments', input);
|
|
334
|
+
return { data: comments };
|
|
335
|
+
},
|
|
336
|
+
createComment: async (input) => {
|
|
337
|
+
record('issues.createComment', input);
|
|
338
|
+
return { data: addComment(101 + comments.length, input.body) };
|
|
339
|
+
},
|
|
340
|
+
getComment: async (input) => {
|
|
341
|
+
record('issues.getComment', input);
|
|
342
|
+
return { data: comments.find((comment) => comment.id === input.comment_id) };
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
search: {
|
|
346
|
+
issuesAndPullRequests: async (input) => {
|
|
347
|
+
record('search.issuesAndPullRequests', input);
|
|
348
|
+
return {
|
|
349
|
+
data: {
|
|
350
|
+
total_count: 2,
|
|
351
|
+
incomplete_results: false,
|
|
352
|
+
items: input.page === 2 ? [issue(18)] : input.page === 3 ? [] : [issue()],
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
pulls: {
|
|
358
|
+
get: async (input) => {
|
|
359
|
+
record('pulls.get', input);
|
|
360
|
+
return { data: pr() };
|
|
361
|
+
},
|
|
362
|
+
list: async (input) => {
|
|
363
|
+
record('pulls.list', input);
|
|
364
|
+
return { data: state.published ? [pr()] : [] };
|
|
365
|
+
},
|
|
366
|
+
listFiles: async (input) => {
|
|
367
|
+
record('pulls.listFiles', input);
|
|
368
|
+
return { data: [{ filename: 'change.ts' }] };
|
|
369
|
+
},
|
|
370
|
+
create: async (input) => {
|
|
371
|
+
record('pulls.create', input);
|
|
372
|
+
state.published = true;
|
|
373
|
+
state.draft = input.draft;
|
|
374
|
+
state.prTitle = input.title;
|
|
375
|
+
state.prBody = input.body;
|
|
376
|
+
return { data: pr() };
|
|
377
|
+
},
|
|
378
|
+
update: async (input) => {
|
|
379
|
+
record('pulls.update', input);
|
|
380
|
+
if (input.draft !== undefined)
|
|
381
|
+
state.draft = input.draft;
|
|
382
|
+
return { data: pr() };
|
|
383
|
+
},
|
|
384
|
+
createReview: async (input) => {
|
|
385
|
+
record('pulls.createReview', input);
|
|
386
|
+
assert.equal(input.commit_id, head);
|
|
387
|
+
review.body = input.body;
|
|
388
|
+
reviews.push(review);
|
|
389
|
+
return { data: review };
|
|
390
|
+
},
|
|
391
|
+
listReviews: async (input) => {
|
|
392
|
+
record('pulls.listReviews', input);
|
|
393
|
+
return { data: reviews };
|
|
394
|
+
},
|
|
395
|
+
getReview: async (input) => {
|
|
396
|
+
record('pulls.getReview', input);
|
|
397
|
+
return { data: review };
|
|
398
|
+
},
|
|
399
|
+
merge: async (input) => {
|
|
400
|
+
record('pulls.merge', input);
|
|
401
|
+
assert.equal(input.sha, head);
|
|
402
|
+
state.merged = true;
|
|
403
|
+
if (state.mergeAckLost) {
|
|
404
|
+
state.mergeAckLost = false;
|
|
405
|
+
throw new Error('Synthetic lost merge acknowledgement');
|
|
406
|
+
}
|
|
407
|
+
return { data: { merged: true, sha: 'c'.repeat(40) } };
|
|
408
|
+
},
|
|
409
|
+
},
|
|
410
|
+
};
|
|
411
|
+
const graphql = async (query, variables = {}) => {
|
|
412
|
+
record(query.match(/(?:query|mutation)\s+(\w+)/u)?.[1] ?? 'relationships', variables);
|
|
413
|
+
if (query.includes('ProjectDeliveryItems'))
|
|
414
|
+
return {
|
|
415
|
+
organization: {
|
|
416
|
+
projectV2: {
|
|
417
|
+
id: 'PROJECT-1',
|
|
418
|
+
items: { nodes: [item()], pageInfo: { hasNextPage: false, endCursor: null } },
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
};
|
|
422
|
+
if (query.includes('UpdateProjectDeliveryStatus')) {
|
|
423
|
+
state.projectOption = String(variables.optionId);
|
|
424
|
+
return { updateProjectV2ItemFieldValue: { projectV2Item: { id: 'ITEM17' } } };
|
|
425
|
+
}
|
|
426
|
+
if (query.includes('ProjectDeliveryItemReadback'))
|
|
427
|
+
return { node: item() };
|
|
428
|
+
if (query.includes('DeliveryStartBranch')) {
|
|
429
|
+
state.linked = true;
|
|
430
|
+
return { createLinkedBranch: { linkedBranch: { ref: { name: 'issue/17', target: { oid: head } } } } };
|
|
431
|
+
}
|
|
432
|
+
if (query.includes('DeliveryIssueBranches'))
|
|
433
|
+
return {
|
|
434
|
+
repository: {
|
|
435
|
+
issue: {
|
|
436
|
+
linkedBranches: {
|
|
437
|
+
nodes: state.linked
|
|
438
|
+
? [
|
|
439
|
+
{
|
|
440
|
+
ref: {
|
|
441
|
+
name: 'issue/17',
|
|
442
|
+
target: { oid: head },
|
|
443
|
+
repository: { nameWithOwner: 'example/widget' },
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
]
|
|
447
|
+
: [],
|
|
448
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
if (query.includes('DeliveryClosingIssues'))
|
|
454
|
+
return {
|
|
455
|
+
repository: {
|
|
456
|
+
nameWithOwner: 'example/widget',
|
|
457
|
+
pullRequest: {
|
|
458
|
+
id: 'PR23',
|
|
459
|
+
number: 23,
|
|
460
|
+
closingIssuesReferences: {
|
|
461
|
+
nodes: [{ number: 17, repository: { nameWithOwner: 'example/widget' } }],
|
|
462
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
if (query.includes('DeliveryReviewAccess'))
|
|
468
|
+
return {
|
|
469
|
+
repository: {
|
|
470
|
+
pullRequest: {
|
|
471
|
+
headRefOid: head,
|
|
472
|
+
reviews: {
|
|
473
|
+
nodes: reviews.map((value) => ({
|
|
474
|
+
id: String(value.id),
|
|
475
|
+
fullDatabaseId: value.id,
|
|
476
|
+
author: value.user,
|
|
477
|
+
authorCanPushToRepository: true,
|
|
478
|
+
commit: { oid: head },
|
|
479
|
+
state: value.state,
|
|
480
|
+
})),
|
|
481
|
+
pageInfo: { hasNextPage: false, endCursor: null },
|
|
482
|
+
},
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
};
|
|
486
|
+
if (query.includes('DeliveryReviewDecision'))
|
|
487
|
+
return { repository: { pullRequest: { headRefOid: head, reviewDecision: state.reviewDecision } } };
|
|
488
|
+
if (query.includes('IssueClosureReadback'))
|
|
489
|
+
return {
|
|
490
|
+
repository: {
|
|
491
|
+
issue: {
|
|
492
|
+
number: 17,
|
|
493
|
+
repository: { nameWithOwner: 'example/widget' },
|
|
494
|
+
state: state.issueState.toUpperCase(),
|
|
495
|
+
stateReason: state.issueState === 'closed' ? 'COMPLETED' : null,
|
|
496
|
+
duplicateOf: null,
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
};
|
|
500
|
+
if (query.includes('blockedBy(first:'))
|
|
501
|
+
return {
|
|
502
|
+
repository: {
|
|
503
|
+
issue: { parent: null, blockedBy: { nodes: [], pageInfo: { hasNextPage: false, endCursor: null } } },
|
|
504
|
+
},
|
|
505
|
+
};
|
|
506
|
+
return syntheticDiscoveryClients().graphql(query, variables);
|
|
507
|
+
};
|
|
508
|
+
const clientsSpy = vi.spyOn(githubClients, 'createDeliveryGitHubClients').mockImplementation(async (input) => ({
|
|
509
|
+
role: input.role,
|
|
510
|
+
authSource: input.role === 'author' ? 'personal' : 'app',
|
|
511
|
+
authenticatedAuthor: async () => {
|
|
512
|
+
record('authenticatedAuthor');
|
|
513
|
+
return { actorLogin: 'operator', credentialIdentity: 'user:42' };
|
|
514
|
+
},
|
|
515
|
+
appActorLogin: async () => {
|
|
516
|
+
record('appActorLogin');
|
|
517
|
+
return 'reviewer[bot]';
|
|
518
|
+
},
|
|
519
|
+
rest,
|
|
520
|
+
graphql,
|
|
521
|
+
}));
|
|
522
|
+
restoreClients = () => clientsSpy.mockRestore();
|
|
523
|
+
const target = join(root, '.worktrees', 'issue-17');
|
|
524
|
+
const worktree = () => {
|
|
525
|
+
fixtureSignal.throwIfAborted();
|
|
526
|
+
fixtureGit(root, 'worktree', 'add', '-b', 'issue/17', target, head);
|
|
527
|
+
mkdirSync(join(root, '.issue-cli'), { recursive: true });
|
|
528
|
+
writeFileSync(join(root, '.issue-cli', 'worktrees.json'), JSON.stringify({ worktrees: [] }));
|
|
529
|
+
state.published = false;
|
|
530
|
+
return target;
|
|
531
|
+
};
|
|
532
|
+
const policy = (kind, selected = root) => {
|
|
533
|
+
fixtureSignal.throwIfAborted();
|
|
534
|
+
assert.equal(readFileSync(join(selected, 'ai-delivery.policy.mjs'), 'utf8'), tracked);
|
|
535
|
+
assert.equal(fixtureGit(selected, 'show', 'HEAD:ai-delivery.policy.mjs'), tracked.trim());
|
|
536
|
+
assert.equal(fixtureGit(selected, 'show', ':ai-delivery.policy.mjs'), tracked.trim());
|
|
537
|
+
// Positive controls run the SAME payload as the target under the SAME environment in fresh children.
|
|
538
|
+
for (const [name, bytes] of kind === 'tracked'
|
|
539
|
+
? [['tracked', tracked]]
|
|
540
|
+
: [
|
|
541
|
+
['tracked', tracked],
|
|
542
|
+
['edited', edited],
|
|
543
|
+
]) {
|
|
544
|
+
const control = join(base, `control-${name}.mjs`);
|
|
545
|
+
writeFileSync(control, bytes);
|
|
546
|
+
execFileSync(process.execPath, [control], { env: process.env, timeout: 5_000, maxBuffer: 64 * 1024 });
|
|
547
|
+
const readback = JSON.parse(readFileSync(sentinel, 'utf8'));
|
|
548
|
+
assert.deepEqual(readback, { marker: name, module: pathToFileURL(control).href });
|
|
549
|
+
observations.push({
|
|
550
|
+
control: name,
|
|
551
|
+
module: control,
|
|
552
|
+
payloadDigest: digestBytes(Buffer.from(bytes)),
|
|
553
|
+
passed: true,
|
|
554
|
+
});
|
|
555
|
+
unlinkSync(sentinel);
|
|
556
|
+
}
|
|
557
|
+
if (kind === 'edited')
|
|
558
|
+
writeFileSync(join(selected, 'ai-delivery.policy.mjs'), edited);
|
|
559
|
+
assert.equal(fixtureGit(selected, 'status', '--porcelain'), kind === 'edited' ? 'M ai-delivery.policy.mjs' : '');
|
|
560
|
+
observations.push({
|
|
561
|
+
policyState: kind,
|
|
562
|
+
selected,
|
|
563
|
+
indexedDigest: digestBytes(Buffer.from(tracked)),
|
|
564
|
+
headDigest: digestBytes(Buffer.from(tracked)),
|
|
565
|
+
worktreeDigest: digestBytes(Buffer.from(kind === 'edited' ? edited : tracked)),
|
|
566
|
+
});
|
|
567
|
+
};
|
|
568
|
+
const assertInert = () => assert.equal(existsSync(sentinel), false, 'A public route imported consumer policy');
|
|
569
|
+
const connect = async (extra = {}) => {
|
|
570
|
+
fixtureSignal.throwIfAborted();
|
|
571
|
+
const closing = new AbortController();
|
|
572
|
+
const connectionSignal = AbortSignal.any([
|
|
573
|
+
fixtureSignal,
|
|
574
|
+
closing.signal,
|
|
575
|
+
...(extra.signal === undefined ? [] : [extra.signal]),
|
|
576
|
+
]);
|
|
577
|
+
const server = createAiDeliveryMcpServer({ repoRoot: root, ...extra, signal: connectionSignal }, activeCalls);
|
|
578
|
+
const client = new Client({ name: 'inert-target-fixture', version: '1' });
|
|
579
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
580
|
+
const call = async (name, args) => {
|
|
581
|
+
connectionSignal.throwIfAborted();
|
|
582
|
+
const response = await client.callTool({ name, arguments: { repo: 'example/widget', ...args } }, undefined, {
|
|
583
|
+
signal: connectionSignal,
|
|
584
|
+
});
|
|
585
|
+
connectionSignal.throwIfAborted();
|
|
586
|
+
const text = response.content[0]?.text ?? '';
|
|
587
|
+
observations.push({ publicTool: name, arguments: args, isError: response.isError === true, text });
|
|
588
|
+
assertInert();
|
|
589
|
+
return { response, text, value: response.isError ? undefined : JSON.parse(text) };
|
|
590
|
+
};
|
|
591
|
+
let closed;
|
|
592
|
+
const connection = {
|
|
593
|
+
call,
|
|
594
|
+
close: () => {
|
|
595
|
+
closed ??= (async () => {
|
|
596
|
+
closing.abort();
|
|
597
|
+
await Promise.allSettled(activeCalls);
|
|
598
|
+
try {
|
|
599
|
+
await client.close();
|
|
600
|
+
}
|
|
601
|
+
finally {
|
|
602
|
+
await server.close();
|
|
603
|
+
}
|
|
604
|
+
})();
|
|
605
|
+
return closed;
|
|
606
|
+
},
|
|
607
|
+
};
|
|
608
|
+
connections.add(connection);
|
|
609
|
+
try {
|
|
610
|
+
await server.connect(st);
|
|
611
|
+
await client.connect(ct);
|
|
612
|
+
connectionSignal.throwIfAborted();
|
|
613
|
+
return connection;
|
|
614
|
+
}
|
|
615
|
+
catch (error) {
|
|
616
|
+
await connection.close();
|
|
617
|
+
throw error;
|
|
618
|
+
}
|
|
619
|
+
};
|
|
620
|
+
let cleaned = false;
|
|
621
|
+
const cleanup = () => {
|
|
622
|
+
if (cleaned)
|
|
623
|
+
return;
|
|
624
|
+
assert.equal(activeCalls.size, 0, 'Owned tool handlers must settle before fixture removal');
|
|
625
|
+
cleaned = true;
|
|
626
|
+
const inert = !existsSync(sentinel);
|
|
627
|
+
try {
|
|
628
|
+
const current = lstatSync(base);
|
|
629
|
+
assert.equal(current.isSymbolicLink(), false);
|
|
630
|
+
assert.equal(realpathSync(base), base);
|
|
631
|
+
assert.equal(current.dev, owned.dev);
|
|
632
|
+
assert.equal(current.ino, owned.ino);
|
|
633
|
+
assert.equal(fixtureGit(root, 'rev-parse', '--git-common-dir'), '.git');
|
|
634
|
+
const worktrees = fixtureGit(root, 'worktree', 'list', '--porcelain')
|
|
635
|
+
.split('\n')
|
|
636
|
+
.filter((line) => line.startsWith('worktree '));
|
|
637
|
+
assert.ok(worktrees.every((line) => line.slice(9).startsWith(`${base}/`)), 'Cleanup requires owned worktrees');
|
|
638
|
+
rmSync(base, { recursive: true });
|
|
639
|
+
assert.equal(existsSync(base), false);
|
|
640
|
+
const evidence = process.env.AI_DELIVERY_INERT_EVIDENCE_DIR;
|
|
641
|
+
if (evidence)
|
|
642
|
+
writeFileSync(join(evidence, `${basename(base)}.json`), JSON.stringify({
|
|
643
|
+
head,
|
|
644
|
+
tree,
|
|
645
|
+
observations,
|
|
646
|
+
externalPortCalls: calls,
|
|
647
|
+
policyInert: inert,
|
|
648
|
+
ownedCleanup: true,
|
|
649
|
+
}) + '\n', { flag: 'wx', mode: 0o600 });
|
|
650
|
+
assert.equal(inert, true, 'A public route imported consumer policy');
|
|
651
|
+
}
|
|
652
|
+
finally {
|
|
653
|
+
restoreGlobals();
|
|
654
|
+
}
|
|
655
|
+
};
|
|
656
|
+
let disposal;
|
|
657
|
+
const dispose = (connection) => {
|
|
658
|
+
if (connection !== undefined)
|
|
659
|
+
connections.add(connection);
|
|
660
|
+
disposal ??= (async () => {
|
|
661
|
+
shutdown.abort();
|
|
662
|
+
await Promise.allSettled(activeCalls);
|
|
663
|
+
try {
|
|
664
|
+
const closures = await Promise.allSettled([...connections].map((ownedConnection) => ownedConnection.close()));
|
|
665
|
+
const failed = closures.find((result) => result.status === 'rejected');
|
|
666
|
+
if (failed?.status === 'rejected')
|
|
667
|
+
throw failed.reason;
|
|
668
|
+
}
|
|
669
|
+
finally {
|
|
670
|
+
cleanup();
|
|
671
|
+
}
|
|
672
|
+
})();
|
|
673
|
+
return disposal;
|
|
674
|
+
};
|
|
675
|
+
registerDisposal(() => dispose(undefined));
|
|
676
|
+
return {
|
|
677
|
+
signal: fixtureSignal,
|
|
678
|
+
base,
|
|
679
|
+
root,
|
|
680
|
+
head,
|
|
681
|
+
tree,
|
|
682
|
+
target,
|
|
683
|
+
sentinel,
|
|
684
|
+
artifact,
|
|
685
|
+
artifactPath,
|
|
686
|
+
state,
|
|
687
|
+
calls,
|
|
688
|
+
comments,
|
|
689
|
+
reviews,
|
|
690
|
+
rest,
|
|
691
|
+
graphql,
|
|
692
|
+
addComment,
|
|
693
|
+
policy,
|
|
694
|
+
worktree,
|
|
695
|
+
connect,
|
|
696
|
+
assertInert,
|
|
697
|
+
dispose,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
catch (error) {
|
|
701
|
+
try {
|
|
702
|
+
const current = lstatSync(base);
|
|
703
|
+
assert.equal(current.dev, owned.dev);
|
|
704
|
+
assert.equal(current.ino, owned.ino);
|
|
705
|
+
rmSync(base, { recursive: true });
|
|
706
|
+
}
|
|
707
|
+
finally {
|
|
708
|
+
restoreGlobals();
|
|
709
|
+
}
|
|
710
|
+
throw error;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
//# sourceMappingURL=inertTarget.js.map
|