agl 42.2.2 → 43.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +16 -0
- package/dist_serve/bundle.js +6697 -5287
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +29 -29
- package/dist_serve/bundle.js.third-party-notices.txt +29 -29
- package/dist_serve/third-party-notices.md +597 -8
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +114 -16
- package/dist_ts/aglapi/interfaces.d.ts +30 -0
- package/dist_ts/aglapi/interfaces.js +7 -1
- package/dist_ts/classes.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +12 -1
- package/dist_ts/classes.cli.js +10 -1
- package/dist_ts/classes.controller.d.ts +41 -11
- package/dist_ts/classes.controller.js +224 -48
- package/dist_ts/classes.harnessoperationmanager.d.ts +44 -0
- package/dist_ts/classes.harnessoperationmanager.js +15 -10
- package/dist_ts/classes.mcpclient.d.ts +5 -0
- package/dist_ts/classes.mcpclient.js +15 -3
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
- package/dist_ts/classes.mcpcontrollerhost.js +14 -2
- package/dist_ts/classes.mcptools.d.ts +4 -3
- package/dist_ts/classes.mcptools.js +20 -1
- package/dist_ts/classes.mcpvalidation.js +4 -1
- package/dist_ts/classes.ticketstore.d.ts +71 -3
- package/dist_ts/classes.ticketstore.js +299 -12
- package/dist_ts/classes.validation.d.ts +2 -0
- package/dist_ts/classes.validation.js +27 -5
- package/dist_ts/driver/classes.directreports.d.ts +23 -3
- package/dist_ts/driver/classes.directreports.js +59 -2
- package/dist_ts/driver/classes.drivereventrelay.js +3 -2
- package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
- package/dist_ts/driver/functions.driverinstructions.js +12 -3
- package/dist_ts/driver/functions.drivertools.d.ts +4 -0
- package/dist_ts/driver/functions.drivertools.js +8 -2
- package/dist_ts/fleet/classes.boardpump.d.ts +53 -3
- package/dist_ts/fleet/classes.boardpump.js +237 -32
- package/dist_ts/fleet/classes.claudeworkers.d.ts +10 -3
- package/dist_ts/fleet/classes.claudeworkers.js +43 -19
- package/dist_ts/fleet/classes.codexworkers.d.ts +5 -3
- package/dist_ts/fleet/classes.codexworkers.js +26 -9
- package/dist_ts/fleet/classes.deploymonitor.d.ts +253 -0
- package/dist_ts/fleet/classes.deploymonitor.js +821 -0
- package/dist_ts/fleet/classes.gitfacts.d.ts +61 -0
- package/dist_ts/fleet/classes.gitfacts.js +125 -0
- package/dist_ts/fleet/classes.releasereconciler.d.ts +51 -0
- package/dist_ts/fleet/classes.releasereconciler.js +101 -0
- package/dist_ts/fleet/classes.service.d.ts +13 -1
- package/dist_ts/fleet/classes.service.js +76 -7
- package/dist_ts/fleet/classes.ticketeffects.d.ts +13 -0
- package/dist_ts/fleet/classes.ticketeffects.js +42 -8
- package/dist_ts/fleet/classes.workers.d.ts +10 -3
- package/dist_ts/fleet/classes.workers.js +18 -3
- package/dist_ts/fleet/functions.controllerbuild.d.ts +23 -0
- package/dist_ts/fleet/functions.controllerbuild.js +75 -0
- package/dist_ts/fleet/functions.deployprobes.d.ts +39 -0
- package/dist_ts/fleet/functions.deployprobes.js +82 -0
- package/dist_ts/fleet/functions.deployvalidation.d.ts +27 -0
- package/dist_ts/fleet/functions.deployvalidation.js +43 -0
- package/dist_ts/fleet/functions.release.d.ts +2 -1
- package/dist_ts/fleet/functions.release.js +32 -5
- package/dist_ts/fleet/functions.releasefacts.d.ts +45 -0
- package/dist_ts/fleet/functions.releasefacts.js +68 -0
- package/dist_ts/fleet/functions.validation.d.ts +3 -3
- package/dist_ts/fleet/functions.validation.js +4 -7
- package/dist_ts/fleet/functions.watchprobes.js +7 -9
- package/dist_ts/fleet/functions.workervalidation.js +4 -3
- package/dist_ts/fleet/interfaces.workers.d.ts +30 -3
- package/dist_ts/fleet/interfaces.workers.js +14 -1
- package/dist_ts/functions.deploycli.d.ts +33 -0
- package/dist_ts/functions.deploycli.js +155 -0
- package/dist_ts/functions.mcpdeploytools.d.ts +13 -0
- package/dist_ts/functions.mcpdeploytools.js +16 -0
- package/dist_ts/functions.mcptickettools.d.ts +54 -0
- package/dist_ts/functions.mcptickettools.js +8 -7
- package/dist_ts/functions.ticketautolabels.d.ts +2 -0
- package/dist_ts/functions.ticketautolabels.js +9 -3
- package/dist_ts/functions.ticketcli.d.ts +16 -2
- package/dist_ts/functions.ticketcli.js +105 -27
- package/dist_ts/functions.ticketvalidation.d.ts +55 -0
- package/dist_ts/functions.ticketvalidation.js +26 -8
- package/dist_ts_interfaces/deployments.d.ts +241 -0
- package/dist_ts_interfaces/deployments.js +5 -6
- package/dist_ts_interfaces/fleet.d.ts +12 -0
- package/dist_ts_interfaces/fleetworkers.d.ts +21 -1
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/mcprequests.d.ts +3 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.directreports.d.ts +58 -6
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.tickets.d.ts +25 -5
- package/dist_ts_interfaces/requests.tickets.js +2 -2
- package/dist_ts_interfaces/tickets.d.ts +71 -6
- package/dist_ts_interfaces/tickets.js +34 -6
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +7 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +14 -1
- package/dist_ts_migration/index.d.ts +2 -0
- package/dist_ts_migration/index.js +3 -1
- package/dist_ts_migration/v41_ticketclosedcolumn.d.ts +20 -0
- package/dist_ts_migration/v41_ticketclosedcolumn.js +118 -0
- package/dist_ts_migration/v41_ticketlinkrepos.d.ts +24 -0
- package/dist_ts_migration/v41_ticketlinkrepos.js +101 -0
- package/package.json +6 -2
- package/readme.md +306 -36
- package/third-party-notices.md +597 -8
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +113 -15
- package/ts/aglapi/interfaces.ts +6 -0
- package/ts/classes.authstore.ts +13 -0
- package/ts/classes.cli.ts +9 -0
- package/ts/classes.controller.ts +238 -59
- package/ts/classes.harnessoperationmanager.ts +20 -14
- package/ts/classes.mcpclient.ts +17 -2
- package/ts/classes.mcpcontrollerhost.ts +15 -1
- package/ts/classes.mcptools.ts +21 -2
- package/ts/classes.mcpvalidation.ts +2 -0
- package/ts/classes.ticketstore.ts +312 -13
- package/ts/classes.validation.ts +28 -4
- package/ts/driver/classes.directreports.ts +58 -3
- package/ts/driver/classes.drivereventrelay.ts +2 -1
- package/ts/driver/functions.driverinstructions.ts +11 -2
- package/ts/driver/functions.drivertools.ts +10 -2
- package/ts/fleet/classes.boardpump.ts +235 -28
- package/ts/fleet/classes.claudeworkers.ts +36 -15
- package/ts/fleet/classes.codexworkers.ts +24 -7
- package/ts/fleet/classes.deploymonitor.ts +854 -0
- package/ts/fleet/classes.gitfacts.ts +135 -0
- package/ts/fleet/classes.releasereconciler.ts +103 -0
- package/ts/fleet/classes.service.ts +81 -8
- package/ts/fleet/classes.ticketeffects.ts +38 -6
- package/ts/fleet/classes.workers.ts +19 -5
- package/ts/fleet/functions.controllerbuild.ts +84 -0
- package/ts/fleet/functions.deployprobes.ts +84 -0
- package/ts/fleet/functions.deployvalidation.ts +50 -0
- package/ts/fleet/functions.release.ts +32 -3
- package/ts/fleet/functions.releasefacts.ts +91 -0
- package/ts/fleet/functions.validation.ts +3 -6
- package/ts/fleet/functions.watchprobes.ts +6 -8
- package/ts/fleet/functions.workervalidation.ts +3 -2
- package/ts/fleet/interfaces.workers.ts +23 -3
- package/ts/functions.deploycli.ts +151 -0
- package/ts/functions.mcpdeploytools.ts +18 -0
- package/ts/functions.mcptickettools.ts +7 -6
- package/ts/functions.ticketautolabels.ts +10 -2
- package/ts/functions.ticketcli.ts +100 -24
- package/ts/functions.ticketvalidation.ts +26 -7
- package/ts_interfaces/deployments.ts +194 -0
- package/ts_interfaces/fleet.ts +17 -2
- package/ts_interfaces/fleetworkers.ts +20 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/mcprequests.ts +3 -0
- package/ts_interfaces/requests.directreports.ts +52 -8
- package/ts_interfaces/requests.tickets.ts +20 -4
- package/ts_interfaces/requests.ts +6 -1
- package/ts_interfaces/tickets.ts +53 -6
- package/ts_migration/classes.documentmigrationrunner.ts +15 -0
- package/ts_migration/index.ts +2 -0
- package/ts_migration/v41_ticketclosedcolumn.ts +106 -0
- package/ts_migration/v41_ticketlinkrepos.ts +91 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements.deployments.ts +1066 -0
- package/ts_web/elements.directreport.ts +2 -2
- package/ts_web/elements.directreportsession.ts +5 -5
- package/ts_web/elements.harnesscontrollerapp.ts +179 -13
- package/ts_web/elements.makedirectreport.ts +444 -0
- package/ts_web/elements.nativesession.ts +29 -1
- package/ts_web/elements.ticketboard.ts +74 -18
- package/ts_web/functions.deployments.ts +225 -0
- package/ts_web/functions.sessionchat.ts +2 -0
|
@@ -29,6 +29,8 @@ import { controllerMcpFleetMethods, type TControllerMcpFleetTypedRequest } from
|
|
|
29
29
|
import type { IFleetOperation } from '../ts_interfaces/fleet.js';
|
|
30
30
|
import { controllerMcpTicketMethods, type TControllerMcpTicketTypedRequest } from '../ts_interfaces/requests.tickets.js';
|
|
31
31
|
import type { IReq_ControllerMcpSessionFeedAcknowledge, IReq_ControllerMcpSessionFeedList } from '../ts_interfaces/sessionfeed.js';
|
|
32
|
+
import { controllerMcpDeployMethods, type TControllerMcpDeployMethod, type TControllerMcpDeployTypedRequest } from '../ts_interfaces/deployments.js';
|
|
33
|
+
import { deployErrorCodes } from './fleet/classes.deploymonitor.js';
|
|
32
34
|
import { readTicketRevisionConflict, ticketErrorMessages, type TTicketOperation, type TTicketRequest, type TTicketResponse } from '../ts_interfaces/tickets.js';
|
|
33
35
|
import { ticketOperation } from './functions.ticketvalidation.js';
|
|
34
36
|
import { controllerFailureJournal } from './classes.failurejournal.js';
|
|
@@ -88,6 +90,8 @@ import {
|
|
|
88
90
|
export interface IControllerMcpPrivateApi {
|
|
89
91
|
fleetWorkers?: (method: string, request: Record<string, unknown>, signal: AbortSignal) => Promise<TFleetWorkerResponse<TFleetWorkerAction>>;
|
|
90
92
|
fleet?: (method: string, request: Record<string, unknown>, signal: AbortSignal) => Promise<IFleetOperation>;
|
|
93
|
+
/** Deploy status, history, a probe now and release state for the local owner (`agl deploy`, `agl release status`). */
|
|
94
|
+
deploy?: (method: TControllerMcpDeployMethod, request: Record<string, unknown>, signal: AbortSignal) => Promise<unknown>;
|
|
91
95
|
/** The session feed for the local owner; each call verifies the owner capability it carries. */
|
|
92
96
|
sessionFeed?: {
|
|
93
97
|
list(request: IReq_ControllerMcpSessionFeedList['request'], signal: AbortSignal): Promise<IReq_ControllerMcpSessionFeedList['response']>;
|
|
@@ -238,7 +242,7 @@ class ControllerMcpBoundedTypedRouter extends plugins.typedrequest.TypedRouter {
|
|
|
238
242
|
// returned the `{}` the client sent (an error, a handler that returns nothing), so the host restores it here.
|
|
239
243
|
if (response.response === null) (response as plugins.typedrequestInterfaces.ITypedRequest).response = {};
|
|
240
244
|
if (typeof response.method === 'string' && (response.method.startsWith('agl.mcp.configuration.')
|
|
241
|
-
|| response.method.startsWith('agl.mcp.ticket.') || response.method.startsWith('agl.mcp.fleet.'))) {
|
|
245
|
+
|| response.method.startsWith('agl.mcp.ticket.') || response.method.startsWith('agl.mcp.fleet.') || response.method.startsWith('agl.mcp.deploy.'))) {
|
|
242
246
|
// TypedRequest normally echoes the request. The owner capability must not travel back in
|
|
243
247
|
// that echo, including on rejected operations.
|
|
244
248
|
const request = response.request as Record<string, unknown>;
|
|
@@ -292,6 +296,9 @@ const safeTypedResponseError = (
|
|
|
292
296
|
if (methodArg.startsWith('agl.mcp.configuration.') && (configurationErrorCodes as readonly unknown[]).includes(code)) {
|
|
293
297
|
return new plugins.typedrequest.TypedResponseError(errorArg.message, { code });
|
|
294
298
|
}
|
|
299
|
+
if (methodArg.startsWith('agl.mcp.deploy.') && (deployErrorCodes as readonly unknown[]).includes(code)) {
|
|
300
|
+
return new plugins.typedrequest.TypedResponseError(errorArg.message.slice(0, 1024), { code });
|
|
301
|
+
}
|
|
295
302
|
if (typeof code === 'string' && /^[a-z0-9_]{1,64}$/.test(code)) {
|
|
296
303
|
const messages: Record<string, string> = {
|
|
297
304
|
...ticketErrorMessages,
|
|
@@ -664,6 +671,13 @@ export class ControllerMcpHost {
|
|
|
664
671
|
return this.options.api.fleet(method, request as unknown as Record<string, unknown>, tools?.abortSignal ?? new AbortController().signal);
|
|
665
672
|
})));
|
|
666
673
|
}
|
|
674
|
+
for (const method of controllerMcpDeployMethods) {
|
|
675
|
+
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<TControllerMcpDeployTypedRequest>(method,
|
|
676
|
+
async (request, tools) => run(method, async () => {
|
|
677
|
+
if (!this.options.api.deploy) throw new Error('Deploy API is unavailable.');
|
|
678
|
+
return this.options.api.deploy(method, request as unknown as Record<string, unknown>, tools?.abortSignal ?? new AbortController().signal) as never;
|
|
679
|
+
})));
|
|
680
|
+
}
|
|
667
681
|
routerArg.addTypedHandler(new plugins.typedrequest.TypedHandler<IReq_ControllerMcpSessionFeedList>(
|
|
668
682
|
'agl.mcp.sessionfeed.list', async (requestArg, toolsArg) => run('agl.mcp.sessionfeed.list', async () => {
|
|
669
683
|
if (!this.options.api.sessionFeed) throw new Error('Session feed API is unavailable.');
|
package/ts/classes.mcptools.ts
CHANGED
|
@@ -23,6 +23,7 @@ import type { IAglMcpUpgradeRefusal, IAglMcpUpgradeRequest } from './classes.mcp
|
|
|
23
23
|
import { jobToolDefinitions, jobWaitToolDefinition, waitForJob } from './functions.mcpjobtools.js';
|
|
24
24
|
import { ticketToolDefinitions } from './functions.mcptickettools.js';
|
|
25
25
|
import { fleetToolDefinitions } from './functions.mcpfleettools.js';
|
|
26
|
+
import { deployToolDefinitions } from './functions.mcpdeploytools.js';
|
|
26
27
|
import { withLocalConfigurationOwner } from './functions.configurationowner.js';
|
|
27
28
|
import { McpWorkerCaller, workerCallerEnrollmentToolName } from './classes.mcpworkercaller.js';
|
|
28
29
|
import { ticketClientErrorMessages } from '../ts_interfaces/tickets.js';
|
|
@@ -70,6 +71,7 @@ export const aglMcpToolNames = [
|
|
|
70
71
|
'ticket_comment',
|
|
71
72
|
'ticket_link',
|
|
72
73
|
'ticket_question_ask',
|
|
74
|
+
'ticket_unlink',
|
|
73
75
|
'fleet_land',
|
|
74
76
|
'fleet_release',
|
|
75
77
|
'fleet_tooling',
|
|
@@ -90,6 +92,10 @@ export const aglMcpToolNames = [
|
|
|
90
92
|
'fleet_worker_status',
|
|
91
93
|
'fleet_watch',
|
|
92
94
|
'fleet_worker_native_message',
|
|
95
|
+
'deploy_status',
|
|
96
|
+
'deploy_history',
|
|
97
|
+
'deploy_probe',
|
|
98
|
+
'release_status',
|
|
93
99
|
] as const;
|
|
94
100
|
|
|
95
101
|
interface IAglMcpToolResult {
|
|
@@ -123,7 +129,7 @@ export interface IAglMcpToolsOptions {
|
|
|
123
129
|
| 'messageSession'
|
|
124
130
|
| 'readSessionScratchpad'
|
|
125
131
|
| 'updateSessionScratchpad'
|
|
126
|
-
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker'>>;
|
|
132
|
+
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy'>>;
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
const maximumIdentifierBytes = 1024;
|
|
@@ -356,7 +362,7 @@ export class AglMcpTools {
|
|
|
356
362
|
| 'messageSession'
|
|
357
363
|
| 'readSessionScratchpad'
|
|
358
364
|
| 'updateSessionScratchpad'
|
|
359
|
-
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker'>>;
|
|
365
|
+
> & Partial<Pick<ControllerMcpClient, 'ticket' | 'fleet' | 'fleetStart' | 'fleetStatus' | 'fleetWorker' | 'deploy'>>;
|
|
360
366
|
private readonly withFleetOwner: <T>(operation: (token: string) => Promise<T>) => Promise<T>;
|
|
361
367
|
private readonly onControllerUpgraded?: IAglMcpToolsOptions['onControllerUpgraded'];
|
|
362
368
|
private readonly workerCaller?: McpWorkerCaller;
|
|
@@ -598,6 +604,7 @@ export class AglMcpTools {
|
|
|
598
604
|
this.registerTicketTools(serverArg, registeredTools);
|
|
599
605
|
this.registerFleetTools(serverArg, registeredTools);
|
|
600
606
|
this.registerFleetWorkerTools(serverArg, registeredTools);
|
|
607
|
+
this.registerDeployTools(serverArg, registeredTools);
|
|
601
608
|
} catch (errorArg) {
|
|
602
609
|
const failedTools: plugins.RegisteredTool[] = [];
|
|
603
610
|
const rollbackErrors: unknown[] = [];
|
|
@@ -667,6 +674,18 @@ export class AglMcpTools {
|
|
|
667
674
|
}
|
|
668
675
|
}
|
|
669
676
|
|
|
677
|
+
private registerDeployTools(server: InstanceType<typeof plugins.McpServer>, registered: plugins.RegisteredTool[]): void {
|
|
678
|
+
for (const definition of deployToolDefinitions) {
|
|
679
|
+
registered.push(server.registerTool<plugins.z.ZodType, plugins.z.ZodType>(definition.name, {
|
|
680
|
+
description: definition.description, inputSchema: definition.inputSchema,
|
|
681
|
+
annotations: { readOnlyHint: definition.readOnly, destructiveHint: false, openWorldHint: true },
|
|
682
|
+
}, async (input, extra) => this.runToolCall(extra, async () => this.withFleetOwner(async (ownerToken) => {
|
|
683
|
+
if (!this.client.deploy) throw new Error('Deploy API is unavailable.');
|
|
684
|
+
return this.client.deploy(definition.operation, { ...input as Record<string, unknown>, ownerToken } as never, extra.signal);
|
|
685
|
+
}))));
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
670
689
|
private registerJobTools(
|
|
671
690
|
serverArg: InstanceType<typeof plugins.McpServer>,
|
|
672
691
|
registeredToolsArg: plugins.RegisteredTool[],
|
|
@@ -27,6 +27,7 @@ import * as plugins from './plugins.js';
|
|
|
27
27
|
import { assertMcpTicketRequest } from './functions.ticketvalidation.js';
|
|
28
28
|
import { assertFleetWireRequest } from './fleet/functions.validation.js';
|
|
29
29
|
import { assertSessionFeedWireRequest } from './functions.sessionfeedvalidation.js';
|
|
30
|
+
import { assertFleetDeployWireRequest } from './fleet/functions.deployvalidation.js';
|
|
30
31
|
|
|
31
32
|
const maximumIdBytes = 1024;
|
|
32
33
|
const maximumModelPartBytes = 512;
|
|
@@ -142,6 +143,7 @@ const assertMethodRequest = (
|
|
|
142
143
|
if (methodArg === 'agl.mcp.sessionfeed.list' || methodArg === 'agl.mcp.sessionfeed.acknowledge') {
|
|
143
144
|
return assertSessionFeedWireRequest(methodArg, requestArg);
|
|
144
145
|
}
|
|
146
|
+
if (methodArg.startsWith('agl.mcp.deploy.')) return assertFleetDeployWireRequest(methodArg, requestArg);
|
|
145
147
|
if (methodArg.startsWith('agl.mcp.configuration.')) {
|
|
146
148
|
// The authority validates the master document itself; this admits the request's shape.
|
|
147
149
|
const required: Partial<Record<TControllerMcpMethod, string[]>> = {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
type ITicketChanges, type ITicketCreate, type ITicketFilters, type ITicketMove, type ITicketPerson, type ITicketQuestion,
|
|
5
5
|
type TTicketLink, type TTicketOperation, type TTicketRequest, type TTicketResponse,
|
|
6
6
|
type TTicketFleetEvent, type ITicketFleetEventResult, type ITicketComment, type TTicketData, type ITicketOpenQuestion,
|
|
7
|
-
type ITicketDetail, type ITicketGet, ticketHistoryPage,
|
|
7
|
+
type ITicketDetail, type ITicketGet, type ITicketAsk, type ITicketMaintenanceWindow, ticketHistoryPage,
|
|
8
8
|
} from '../ts_interfaces/tickets.js';
|
|
9
9
|
import {
|
|
10
10
|
TicketModel, TicketBoardModel, TicketCommentModel, TicketActivityModel, TicketQuestionModel, TicketFleetEventModel,
|
|
@@ -15,7 +15,7 @@ import { ticketAutoLabelsFor } from './functions.ticketautolabels.js';
|
|
|
15
15
|
type TTicketStored = NonNullable<Awaited<ReturnType<typeof TicketModel.exact.findStoredOne>>>;
|
|
16
16
|
type TSession = plugins.nosqldb.SmartdataSession;
|
|
17
17
|
const workerColumns = new Set(['ready', 'in_progress', 'needs_input', 'review']);
|
|
18
|
-
const mutableOperations = new Set<TTicketOperation>(['create', 'update', 'move', 'comment', 'link', 'ask', 'answer']);
|
|
18
|
+
const mutableOperations = new Set<TTicketOperation>(['create', 'update', 'move', 'comment', 'link', 'unlink', 'ask', 'answer']);
|
|
19
19
|
/**
|
|
20
20
|
* Activity records a history page reads at a time, newest first: a page reads at most this many records beyond the
|
|
21
21
|
* entries it returns, whatever its `limit`, so a page cut by the byte budget does not read `limit` records.
|
|
@@ -72,13 +72,180 @@ export const ticketAssignedTo = (ticketArg: TTicketData, actorArg: ITicketActor)
|
|
|
72
72
|
export const ticketCanEdit = (ticketArg: TTicketData, actorArg: ITicketActor): boolean => (
|
|
73
73
|
actorArg.role !== 'worker' || (ticketAssignedTo(ticketArg, actorArg) && workerColumns.has(ticketArg.columnId))
|
|
74
74
|
);
|
|
75
|
+
/** The links that hold code or a release (AGL-909). */
|
|
76
|
+
const ticketCodeLinkKinds: ReadonlySet<TTicketLink['kind']> = new Set(['branch', 'commit', 'release']);
|
|
77
|
+
/**
|
|
78
|
+
* A deploy ticket, one with a deploy plan, holds no code or release (AGL-909): the release that made it done would end
|
|
79
|
+
* its plan with the owner's go told to nobody. The store refuses such a link on it, and fleet's land and release refuse
|
|
80
|
+
* the ticket before they push or publish.
|
|
81
|
+
*/
|
|
82
|
+
export const ticketDeployPlanRefusesLink = (ticketArg: Pick<TTicketData, 'deployPlan'>, kindArg: TTicketLink['kind']): boolean => (
|
|
83
|
+
ticketArg.deployPlan !== undefined && ticketCodeLinkKinds.has(kindArg)
|
|
84
|
+
);
|
|
85
|
+
/** A ticket that plans no deploy: a done one, or one that holds code or a release (such a link, or a place in review or landed). */
|
|
86
|
+
const ticketTakesNoDeployPlan = (ticketArg: TTicketData): boolean => (
|
|
87
|
+
['review', 'landed', ...ticketDoneColumns].includes(ticketArg.columnId) || ticketArg.links.some((linkArg) => ticketCodeLinkKinds.has(linkArg.kind))
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
export interface ITicketStoreOptions {
|
|
91
|
+
/**
|
|
92
|
+
* Resolves the repository a release plan names to the `org/name` fleet discovery knows, or throws. It runs before the
|
|
93
|
+
* ticket transaction opens, never inside it.
|
|
94
|
+
*/
|
|
95
|
+
resolveReleasePlanRepo?: (repoArg: string, signalArg?: AbortSignal) => Promise<string>;
|
|
96
|
+
/** The tickets the deploy monitor last found undeployed, read as they are when a ticket is shown. */
|
|
97
|
+
undeployedTickets?: () => ReadonlySet<string>;
|
|
98
|
+
/**
|
|
99
|
+
* The deploy target an id names, as a maintenance window or a deploy plan needs it, or throws when the Configuration
|
|
100
|
+
* master names none. It runs before the ticket transaction opens.
|
|
101
|
+
*/
|
|
102
|
+
deployTarget?: (idArg: string, signalArg?: AbortSignal) => Promise<ITicketDeployTargetFacts>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** What a maintenance window or a deploy plan needs to know of a deploy target. */
|
|
106
|
+
export interface ITicketDeployTargetFacts {
|
|
107
|
+
id: string;
|
|
108
|
+
name: string;
|
|
109
|
+
environment?: string;
|
|
110
|
+
/** When its deploys may run: any time, in a maintenance window, or (the AGL controller) when no session is busy. */
|
|
111
|
+
deployWhen: 'anytime' | 'window' | 'idle';
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* The owner's question a deploy plan asks (AGL-909), its options in the order `ticketDeployPlanOptions` names: deploy now,
|
|
116
|
+
* in the next maintenance window (the controller: when no session is busy), hold.
|
|
117
|
+
*/
|
|
118
|
+
export const ticketDeployPlanQuestion = (targetArg: ITicketDeployTargetFacts, versionArg: string): Omit<ITicketAsk, 'ticketId'> => ({
|
|
119
|
+
question: `Deploy ${targetArg.name} ${versionArg}${targetArg.environment ? ` to ${targetArg.environment}` : ''}?`,
|
|
120
|
+
options: [
|
|
121
|
+
{ label: 'Deploy now', description: targetArg.deployWhen === 'idle' ? 'Upgrade it now: agl upgrade stops the busy sessions and continues them afterwards.'
|
|
122
|
+
: targetArg.deployWhen === 'window' ? 'Deploy now, outside a maintenance window: its downtime happens now.' : 'Deploy it now.' },
|
|
123
|
+
targetArg.deployWhen === 'idle'
|
|
124
|
+
? { label: 'When no session is busy', description: 'Upgrade it once no session is busy.' }
|
|
125
|
+
: { label: 'In the next window', description: 'Deploy it inside the next maintenance window planned for it.' },
|
|
126
|
+
{ label: 'Hold', description: 'Do not deploy it; plan the deploy again to ask anew.' },
|
|
127
|
+
],
|
|
128
|
+
multiSelect: false, allowCustom: false,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
/** A window's time as the owner's question names it: UTC, to the minute. */
|
|
132
|
+
const windowTime = (fromArg: string, toArg: string): string => {
|
|
133
|
+
const from = fromArg.slice(0, 16).replace('T', ' ');
|
|
134
|
+
const to = toArg.slice(0, 16).replace('T', ' ');
|
|
135
|
+
return `${from}–${from.slice(0, 10) === to.slice(0, 10) ? to.slice(11) : to} UTC`;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The owner's question a maintenance window the driver proposes asks (AGL-909), its options in the order
|
|
140
|
+
* `ticketWindowOptions` names: approve, decline. The owner's own window asks nothing and counts at once.
|
|
141
|
+
*/
|
|
142
|
+
export const ticketWindowQuestion = (targetsArg: ITicketDeployTargetFacts[], windowArg: ITicketMaintenanceWindow): Omit<ITicketAsk, 'ticketId'> => ({
|
|
143
|
+
question: `Hold a maintenance window ${windowTime(windowArg.from, windowArg.to)} for ${targetsArg
|
|
144
|
+
.map((targetArg) => `${targetArg.name}${targetArg.environment ? ` (${targetArg.environment})` : ''}`).join(', ')}?`,
|
|
145
|
+
options: [
|
|
146
|
+
{ label: 'Approve', description: 'Deploys that wait for a maintenance window may run in it.' },
|
|
147
|
+
{ label: 'Decline', description: 'It does not count: nothing deploys in it, and the driver may propose another.' },
|
|
148
|
+
],
|
|
149
|
+
multiSelect: false, allowCustom: false,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
/** A request as the transaction applies it: a deploy plan, and a window the driver proposes, carry the owner's question. */
|
|
153
|
+
type TResolvedRequest<TMethod extends TTicketOperation> = TTicketRequest<TMethod> & {
|
|
154
|
+
deployQuestion?: Omit<ITicketAsk, 'ticketId'>;
|
|
155
|
+
windowQuestion?: Omit<ITicketAsk, 'ticketId'>;
|
|
156
|
+
};
|
|
75
157
|
|
|
76
158
|
export class TicketStore {
|
|
77
159
|
constructor(
|
|
78
160
|
private readonly onChanged?: (revisionArg: number, ticketIdsArg: string[]) => void,
|
|
79
161
|
private readonly observer?: (observationArg: ITicketObservation) => void,
|
|
162
|
+
private readonly options: ITicketStoreOptions = {},
|
|
80
163
|
) {}
|
|
81
164
|
|
|
165
|
+
/**
|
|
166
|
+
* What a request plans, resolved before the transaction opens (AGL-909): a release plan's and an `affects` link's
|
|
167
|
+
* repository as fleet discovery knows it, a maintenance window's targets, and a deploy plan's target and the question
|
|
168
|
+
* it asks the owner. Only the driver and the owner plan.
|
|
169
|
+
*/
|
|
170
|
+
private async resolvePlans<TMethod extends TTicketOperation>(methodArg: TMethod, requestArg: TTicketRequest<TMethod>,
|
|
171
|
+
actorArg: ITicketActor | undefined, signalArg?: AbortSignal): Promise<TResolvedRequest<TMethod>> {
|
|
172
|
+
const request = await this.resolveReleasePlan(methodArg, requestArg, actorArg, signalArg);
|
|
173
|
+
if (methodArg !== 'create' && methodArg !== 'update') return request;
|
|
174
|
+
const fields = (methodArg === 'create' ? request : (request as TTicketRequest<'update'>).changes) as Pick<ITicketChanges, 'maintenanceWindow' | 'deployPlan'>;
|
|
175
|
+
const target = async (idArg: string, codeArg: 'ticket_window_invalid' | 'ticket_deploy_plan_invalid'): Promise<ITicketDeployTargetFacts> => {
|
|
176
|
+
if (!this.options.deployTarget) return { id: idArg, name: idArg, deployWhen: 'anytime' };
|
|
177
|
+
try { return await this.options.deployTarget(idArg, signalArg); }
|
|
178
|
+
catch (errorArg) { throw new TicketError(codeArg, `${ticketErrorMessages[codeArg]} ${errorArg instanceof Error ? errorArg.message : ''}`.trim()); }
|
|
179
|
+
};
|
|
180
|
+
let resolved: TResolvedRequest<TMethod> = request;
|
|
181
|
+
const window = fields.maintenanceWindow;
|
|
182
|
+
if (window !== undefined) {
|
|
183
|
+
if (actorArg?.role === 'worker') throw new TicketError('ticket_window_forbidden', ticketErrorMessages.ticket_window_forbidden);
|
|
184
|
+
if (window !== null) {
|
|
185
|
+
if (Date.parse(window.to) <= Date.now()) {
|
|
186
|
+
throw new TicketError('ticket_window_invalid', `${ticketErrorMessages.ticket_window_invalid} It ended at ${window.to}.`);
|
|
187
|
+
}
|
|
188
|
+
const facts: ITicketDeployTargetFacts[] = [];
|
|
189
|
+
for (const id of window.targets) {
|
|
190
|
+
const fact = await target(id, 'ticket_window_invalid');
|
|
191
|
+
if (fact.deployWhen === 'idle') {
|
|
192
|
+
throw new TicketError('ticket_window_invalid', `${id} is the AGL controller, which needs no window: it is upgraded when no session is busy.`);
|
|
193
|
+
}
|
|
194
|
+
facts.push(fact);
|
|
195
|
+
}
|
|
196
|
+
const normalized: ITicketMaintenanceWindow = { from: new Date(window.from).toISOString(), to: new Date(window.to).toISOString(), targets: [...window.targets] };
|
|
197
|
+
resolved = (methodArg === 'create' ? { ...resolved, maintenanceWindow: normalized }
|
|
198
|
+
: { ...resolved, changes: { ...(resolved as TTicketRequest<'update'>).changes, maintenanceWindow: normalized } }) as TResolvedRequest<TMethod>;
|
|
199
|
+
// A window the driver proposes waits for the owner's go; the owner's own counts at once.
|
|
200
|
+
if (actorArg?.role !== 'owner') resolved = { ...resolved, windowQuestion: ticketWindowQuestion(facts, normalized) };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const plan = fields.deployPlan;
|
|
204
|
+
if (plan !== undefined) {
|
|
205
|
+
if (actorArg?.role === 'worker') throw new TicketError('ticket_deploy_plan_forbidden', ticketErrorMessages.ticket_deploy_plan_forbidden);
|
|
206
|
+
resolved = { ...resolved, deployQuestion: ticketDeployPlanQuestion(await target(plan.target, 'ticket_deploy_plan_invalid'), plan.version) };
|
|
207
|
+
}
|
|
208
|
+
return resolved;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A request whose release plan or affects link names its repository as fleet discovery knows it; checked before the transaction. */
|
|
212
|
+
private async resolveReleasePlan<TMethod extends TTicketOperation>(methodArg: TMethod, requestArg: TTicketRequest<TMethod>,
|
|
213
|
+
actorArg: ITicketActor | undefined, signalArg?: AbortSignal): Promise<TTicketRequest<TMethod>> {
|
|
214
|
+
if (methodArg === 'unlink') {
|
|
215
|
+
// Evidence is append-only for the driver: it removes a wrong `affects` link; code and release links are the owner's.
|
|
216
|
+
const link = (requestArg as TTicketRequest<'unlink'>).link;
|
|
217
|
+
if (actorArg?.role === 'worker' || (actorArg?.role === 'driver' && link.kind !== 'affects')) {
|
|
218
|
+
throw new TicketError('ticket_unlink_forbidden', ticketErrorMessages.ticket_unlink_forbidden);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (methodArg === 'link' && (requestArg as TTicketRequest<'link'>).link.kind === 'release' && actorArg?.role !== 'owner') {
|
|
222
|
+
// A release is the remote's tag: fleet links it from the tag, and only the owner links one by hand.
|
|
223
|
+
throw new TicketError('ticket_release_link_forbidden', ticketErrorMessages.ticket_release_link_forbidden);
|
|
224
|
+
}
|
|
225
|
+
if (methodArg === 'link' || methodArg === 'unlink') {
|
|
226
|
+
// An `affects` link names its repository as `link` stores it, whichever way the caller names it.
|
|
227
|
+
const link = (requestArg as TTicketRequest<'link'>).link;
|
|
228
|
+
if (link.kind !== 'affects' || !this.options.resolveReleasePlanRepo) return requestArg;
|
|
229
|
+
try { return { ...requestArg, link: { ...link, repo: await this.options.resolveReleasePlanRepo(link.repo, signalArg) } }; }
|
|
230
|
+
catch (errorArg) {
|
|
231
|
+
throw new TicketError('ticket_affects_invalid', `${ticketErrorMessages.ticket_affects_invalid} ${errorArg instanceof Error ? errorArg.message : ''}`.trim());
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const plan = methodArg === 'create' ? (requestArg as ITicketCreate).releasePlan
|
|
235
|
+
: methodArg === 'update' ? (requestArg as TTicketRequest<'update'>).changes.releasePlan : undefined;
|
|
236
|
+
if (plan === undefined) return requestArg;
|
|
237
|
+
if (actorArg?.role === 'worker') throw new TicketError('ticket_release_plan_forbidden', ticketErrorMessages.ticket_release_plan_forbidden);
|
|
238
|
+
if (plan === null || !this.options.resolveReleasePlanRepo) return requestArg;
|
|
239
|
+
let repo: string;
|
|
240
|
+
try { repo = await this.options.resolveReleasePlanRepo(plan.repo, signalArg); }
|
|
241
|
+
catch (errorArg) {
|
|
242
|
+
throw new TicketError('ticket_release_plan_invalid', `${ticketErrorMessages.ticket_release_plan_invalid} ${errorArg instanceof Error ? errorArg.message : ''}`.trim());
|
|
243
|
+
}
|
|
244
|
+
const resolved = { ...plan, repo };
|
|
245
|
+
return (methodArg === 'create' ? { ...requestArg, releasePlan: resolved }
|
|
246
|
+
: { ...requestArg, changes: { ...(requestArg as TTicketRequest<'update'>).changes, releasePlan: resolved } }) as TTicketRequest<TMethod>;
|
|
247
|
+
}
|
|
248
|
+
|
|
82
249
|
/** `originArg` names the native session whose own output the event mirrors; observers see it on the changes. */
|
|
83
250
|
public async applyFleetEvent(eventArg: TTicketFleetEvent, signalArg?: AbortSignal, originArg?: string): Promise<ITicketFleetEventResult> {
|
|
84
251
|
const event = ticketFleetEventSchema.parse(eventArg);
|
|
@@ -123,8 +290,12 @@ export class TicketStore {
|
|
|
123
290
|
: ticketReleaseLink(event);
|
|
124
291
|
await this.perform('link', { ticketId: event.ticketKey, link }, event.actor, transactionArg,
|
|
125
292
|
now, board.sequence + 1, revision, track);
|
|
126
|
-
|
|
127
|
-
|
|
293
|
+
// A ticket moves to released on its first release; the release of another of its repositories is linked where it stands.
|
|
294
|
+
const stands = (await TicketModel.exact.findStoredOne({ id: event.ticketKey }, { session: transactionArg }))?.ticket.columnId;
|
|
295
|
+
if (event.kind !== 'released' || stands !== 'released') {
|
|
296
|
+
await this.perform('move', { ticketId: event.ticketKey, columnId: event.kind }, event.actor, transactionArg,
|
|
297
|
+
now, board.sequence + 1, revision, track);
|
|
298
|
+
}
|
|
128
299
|
}
|
|
129
300
|
let comment: ITicketComment | undefined;
|
|
130
301
|
if (event.body !== undefined) {
|
|
@@ -156,7 +327,10 @@ export class TicketStore {
|
|
|
156
327
|
return committed;
|
|
157
328
|
}
|
|
158
329
|
|
|
159
|
-
/**
|
|
330
|
+
/**
|
|
331
|
+
* Every open question with its ticket's key and project, oldest first. A question whose ticket is gone or done is left
|
|
332
|
+
* out: a done ticket asks nobody.
|
|
333
|
+
*/
|
|
160
334
|
public async openQuestions(signalArg?: AbortSignal): Promise<ITicketOpenQuestion[]> {
|
|
161
335
|
const questions: ITicketQuestion[] = [];
|
|
162
336
|
let after: string | undefined;
|
|
@@ -178,7 +352,7 @@ export class TicketStore {
|
|
|
178
352
|
}
|
|
179
353
|
return structuredClone(questions.flatMap((questionArg) => {
|
|
180
354
|
const ticket = tickets.get(questionArg.ticketId);
|
|
181
|
-
return ticket ? [{ ticketKey: ticket.key, project: ticket.project, question: questionArg }] : [];
|
|
355
|
+
return ticket && !ticketDoneColumns.includes(ticket.columnId) ? [{ ticketKey: ticket.key, project: ticket.project, question: questionArg }] : [];
|
|
182
356
|
})).sort((leftArg, rightArg) => leftArg.question.createdAt.localeCompare(rightArg.question.createdAt));
|
|
183
357
|
}
|
|
184
358
|
|
|
@@ -213,7 +387,7 @@ export class TicketStore {
|
|
|
213
387
|
throw new TicketError('ticket_identity_required', ticketErrorMessages.ticket_identity_required);
|
|
214
388
|
}
|
|
215
389
|
const actor = actorArg === undefined ? undefined : ticketActorSchema.parse(actorArg);
|
|
216
|
-
const request = assertTicketRequest(methodArg, requestArg);
|
|
390
|
+
const request = await this.resolvePlans(methodArg, assertTicketRequest(methodArg, requestArg), actor, signalArg);
|
|
217
391
|
const session = TicketBoardModel.collection.smartdataDb.createSession();
|
|
218
392
|
let committed: { response: unknown; revision: number; ticketIds: string[] } | undefined;
|
|
219
393
|
let track: ITicketTrack | undefined;
|
|
@@ -330,7 +504,8 @@ export class TicketStore {
|
|
|
330
504
|
|
|
331
505
|
private visible(ticketArg: TTicketData, actorArg: ITicketActor | undefined, trackArg: ITicketTrack): ITicket {
|
|
332
506
|
return { ...structuredClone(ticketArg), revision: ticketArg.revision ?? 0,
|
|
333
|
-
autoLabels: ticketAutoLabelsFor(ticketArg, { openQuestions: trackArg.openQuestions.get(ticketArg.id) ?? 0
|
|
507
|
+
autoLabels: ticketAutoLabelsFor(ticketArg, { openQuestions: trackArg.openQuestions.get(ticketArg.id) ?? 0,
|
|
508
|
+
undeployed: this.options.undeployedTickets?.().has(ticketArg.key) ?? false }), permissions: {
|
|
334
509
|
edit: actorArg !== undefined && ticketCanEdit(ticketArg, actorArg),
|
|
335
510
|
move: actorArg !== undefined && ticketCanEdit(ticketArg, actorArg), comment: actorArg !== undefined,
|
|
336
511
|
createChild: actorArg !== undefined && ticketArg.kind !== 'subtask',
|
|
@@ -355,6 +530,52 @@ export class TicketStore {
|
|
|
355
530
|
}
|
|
356
531
|
}
|
|
357
532
|
|
|
533
|
+
/** Asks the owner a deploy plan's question on the ticket, numbered `numberArg`; the transaction that sets the plan asks it. */
|
|
534
|
+
/** Asks the owner the question a deploy plan or a proposed window resolved to, in the ticket's transaction. */
|
|
535
|
+
private async askOwner(ticketIdArg: string, numberArg: number, askArg: Omit<ITicketAsk, 'ticketId'> | undefined,
|
|
536
|
+
codeArg: 'ticket_deploy_plan_invalid' | 'ticket_window_invalid', actorArg: ITicketActor, nowArg: string, sessionArg: TSession): Promise<ITicketQuestion> {
|
|
537
|
+
const ask = askArg;
|
|
538
|
+
if (!ask) throw new TicketError(codeArg, ticketErrorMessages[codeArg]);
|
|
539
|
+
const question: ITicketQuestion = { id: `Q${numberArg}`, ticketId: ticketIdArg, kind: 'question', question: ask.question,
|
|
540
|
+
options: (ask.options ?? []).map((optionArg, indexArg) => ({ id: String(indexArg + 1), label: optionArg.label,
|
|
541
|
+
...(optionArg.description === undefined ? {} : { description: optionArg.description }) })),
|
|
542
|
+
multiSelect: ask.multiSelect ?? false, allowCustom: ask.allowCustom ?? false, askedBy: actorArg, createdAt: nowArg, status: 'open' };
|
|
543
|
+
const inserted = await TicketQuestionModel.exact.insert({ id: `${ticketIdArg}:${question.id}`, ticketId: ticketIdArg, status: 'open', question },
|
|
544
|
+
{ session: sessionArg });
|
|
545
|
+
if (inserted.status === 'conflict') throw new Error('Ticket question identity conflict.');
|
|
546
|
+
return question;
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* The evidence a column requires (AGL-916): review a branch, landed a branch or commit, released a release link. Checked
|
|
551
|
+
* when a ticket moves into the column and when a link is removed, so tickets closed by hand before stay readable.
|
|
552
|
+
*/
|
|
553
|
+
private requireEvidence(ticketArg: TTicketData, columnArg: TTicketData['columnId']): void {
|
|
554
|
+
if (columnArg === 'review' && !ticketArg.links.some((linkArg) => linkArg.kind === 'branch')) {
|
|
555
|
+
throw new TicketError('ticket_review_branch_required', ticketErrorMessages.ticket_review_branch_required);
|
|
556
|
+
}
|
|
557
|
+
if (columnArg === 'landed' && !ticketArg.links.some((linkArg) => linkArg.kind === 'branch' || linkArg.kind === 'commit')) {
|
|
558
|
+
throw new TicketError('ticket_landed_evidence_required', ticketErrorMessages.ticket_landed_evidence_required);
|
|
559
|
+
}
|
|
560
|
+
if (columnArg === 'released' && !ticketArg.links.some((linkArg) => linkArg.kind === 'release')) {
|
|
561
|
+
throw new TicketError('ticket_released_evidence_required', ticketErrorMessages.ticket_released_evidence_required);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* A deploy plan is a ticket of its own (AGL-909): one that holds code or a release would end its plan as done once
|
|
567
|
+
* released, and a done one asks nobody.
|
|
568
|
+
*/
|
|
569
|
+
private requireDeployTicket(ticketArg: TTicketData): void {
|
|
570
|
+
if (!ticketTakesNoDeployPlan(ticketArg)) return;
|
|
571
|
+
throw new TicketError('ticket_deploy_plan_invalid', `${ticketArg.key} plans no deploy: it holds code or a release (a branch, commit or release link, `
|
|
572
|
+
+ 'or a place in review, landed or released) or is closed. Plan the deploy on a ticket of its own.');
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
private holdsEvidence(ticketArg: TTicketData, columnArg: TTicketData['columnId']): boolean {
|
|
576
|
+
try { this.requireEvidence(ticketArg, columnArg); return true; } catch { return false; }
|
|
577
|
+
}
|
|
578
|
+
|
|
358
579
|
private requireReview(ticketArg: TTicketData): void {
|
|
359
580
|
if (ticketArg.columnId === 'review' && !ticketArg.links.some((linkArg) => linkArg.kind === 'branch')) {
|
|
360
581
|
throw new TicketError('ticket_review_branch_required', 'Review requires a linked branch with its full commit sha.');
|
|
@@ -470,6 +691,17 @@ export class TicketStore {
|
|
|
470
691
|
...(cut ? { historyBefore: activity[0]!.id } : {}) };
|
|
471
692
|
}
|
|
472
693
|
|
|
694
|
+
/** One question of a ticket, as stored; undefined when the ticket asked none by that id. One document read. */
|
|
695
|
+
public async question(ticketIdArg: string, questionIdArg: string): Promise<ITicketQuestion | undefined> {
|
|
696
|
+
const stored = await TicketQuestionModel.exact.findStoredOne({ id: `${ticketIdArg}:${questionIdArg}` });
|
|
697
|
+
return stored ? structuredClone(TicketQuestionModel.exact.toPersisted(stored).question) : undefined;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/** The board's revision, which every ticket change moves; 0 before the board exists. One document read. */
|
|
701
|
+
public async boardRevision(): Promise<number> {
|
|
702
|
+
return (await TicketBoardModel.exact.findStoredOne({ id: 'global' }))?.revision ?? 0;
|
|
703
|
+
}
|
|
704
|
+
|
|
473
705
|
/**
|
|
474
706
|
* A ticket with its whole history and all its questions, read in one transaction without the rest of the board.
|
|
475
707
|
* The board pump reads a ticket this way only when its revision moved.
|
|
@@ -540,13 +772,26 @@ export class TicketStore {
|
|
|
540
772
|
description: input.description ?? '', ...(input.parentId ? { parentId: input.parentId } : {}), columnId,
|
|
541
773
|
order: await TicketModel.exact.count({ 'ticket.columnId': columnId }, { session: sessionArg }),
|
|
542
774
|
priority: input.priority ?? 'normal', ...(input.assignee ? { assignee: input.assignee } : {}), labels: input.labels ?? [], links: [],
|
|
775
|
+
...(input.releasePlan ? { releasePlan: input.releasePlan } : {}),
|
|
776
|
+
...(input.maintenanceWindow ? { maintenanceWindow: input.maintenanceWindow } : {}),
|
|
543
777
|
source: { kind: actorArg.role === 'owner' ? 'owner_words' : actorArg.role, text: input.sourceText ?? input.description ?? input.title,
|
|
544
778
|
actor: actorArg, attachments: input.attachments ?? [] }, createdBy: actorArg, updatedBy: actorArg, createdAt: nowArg, updatedAt: nowArg };
|
|
545
779
|
await this.parent(ticket, sessionArg);
|
|
546
|
-
this.
|
|
780
|
+
if (input.deployPlan) this.requireDeployTicket(ticket);
|
|
781
|
+
this.requireEvidence(ticket, columnId);
|
|
782
|
+
// A deploy plan, and a window the driver proposes, ask the owner in the same transaction; each names its question.
|
|
783
|
+
const resolved = requestArg as TResolvedRequest<'create'>;
|
|
784
|
+
const question = input.deployPlan ? await this.askOwner(id, 1, resolved.deployQuestion, 'ticket_deploy_plan_invalid', actorArg, nowArg, sessionArg) : undefined;
|
|
785
|
+
if (input.deployPlan && question) ticket.deployPlan = { target: input.deployPlan.target, version: input.deployPlan.version, questionId: question.id };
|
|
786
|
+
const windowQuestion = ticket.maintenanceWindow && resolved.windowQuestion
|
|
787
|
+
? await this.askOwner(id, question ? 2 : 1, resolved.windowQuestion, 'ticket_window_invalid', actorArg, nowArg, sessionArg) : undefined;
|
|
788
|
+
if (ticket.maintenanceWindow && windowQuestion) ticket.maintenanceWindow = { ...ticket.maintenanceWindow, questionId: windowQuestion.id };
|
|
547
789
|
const result = await TicketModel.exact.insert({ id, ticket }, { session: sessionArg });
|
|
548
790
|
if (result.status === 'conflict') throw new Error('Global ticket sequence conflict.');
|
|
549
|
-
|
|
791
|
+
const [first, second] = [question, windowQuestion].filter((questionArg): questionArg is ITicketQuestion => questionArg !== undefined);
|
|
792
|
+
await this.activity(ticket, actorArg, sessionArg, 'created', { ticket: { after: ticket }, ...(first ? { question: { after: first } } : {}) },
|
|
793
|
+
nowArg, revisionArg, trackArg);
|
|
794
|
+
if (second) await this.activity(ticket, actorArg, sessionArg, 'asked', { question: { after: second } }, nowArg, revisionArg, trackArg);
|
|
550
795
|
trackArg.ticketIds.push(id);
|
|
551
796
|
return { ticket: await this.shown(ticket, actorArg, sessionArg, trackArg) };
|
|
552
797
|
}
|
|
@@ -641,10 +886,43 @@ export class TicketStore {
|
|
|
641
886
|
throw new TicketError('ticket_assignment_forbidden', 'Only the driver or owner may assign tickets.');
|
|
642
887
|
}
|
|
643
888
|
if (changes.labels?.some(isTicketAutoLabel)) throw new TicketError('ticket_label_reserved', ticketErrorMessages.ticket_label_reserved);
|
|
644
|
-
const { assignee, parentId, ...fields } = changes;
|
|
889
|
+
const { assignee, parentId, releasePlan, maintenanceWindow, deployPlan, ...fields } = changes;
|
|
645
890
|
Object.assign(ticket, fields);
|
|
646
891
|
if (assignee === null) delete ticket.assignee;
|
|
647
892
|
else if (assignee !== undefined) ticket.assignee = assignee;
|
|
893
|
+
if (releasePlan === null) delete ticket.releasePlan;
|
|
894
|
+
else if (releasePlan !== undefined) ticket.releasePlan = releasePlan;
|
|
895
|
+
const isOpen = async (questionIdArg: string | undefined) => questionIdArg !== undefined && (await TicketQuestionModel.exact.findStoredOne(
|
|
896
|
+
{ id: `${ticketId}:${questionIdArg}` }, { session: sessionArg }))?.status === 'open';
|
|
897
|
+
// A window waiting for the owner's go neither changes nor goes, and the same window again is no change; once
|
|
898
|
+
// answered, a window set again asks anew when the driver sets it and counts at once when the owner does.
|
|
899
|
+
const held = ticket.maintenanceWindow;
|
|
900
|
+
const sameWindow = maintenanceWindow && held && maintenanceWindow.from === held.from && maintenanceWindow.to === held.to
|
|
901
|
+
&& JSON.stringify(maintenanceWindow.targets) === JSON.stringify(held.targets);
|
|
902
|
+
const windowWaiting = maintenanceWindow !== undefined && await isOpen(held?.questionId);
|
|
903
|
+
if (windowWaiting && !sameWindow) throw new TicketError('ticket_window_waiting', ticketErrorMessages.ticket_window_waiting);
|
|
904
|
+
let askedWindow: ITicketQuestion | undefined;
|
|
905
|
+
if (maintenanceWindow === null && !windowWaiting) delete ticket.maintenanceWindow;
|
|
906
|
+
else if (maintenanceWindow && !windowWaiting) {
|
|
907
|
+
const windowQuestion = (requestArg as TResolvedRequest<'update'>).windowQuestion;
|
|
908
|
+
askedWindow = windowQuestion ? await this.askOwner(ticketId, (await this.questions(ticketId, sessionArg)).length + 1, windowQuestion,
|
|
909
|
+
'ticket_window_invalid', actorArg, nowArg, sessionArg) : undefined;
|
|
910
|
+
ticket.maintenanceWindow = { from: maintenanceWindow.from, to: maintenanceWindow.to, targets: [...maintenanceWindow.targets],
|
|
911
|
+
...(askedWindow ? { questionId: askedWindow.id } : {}) };
|
|
912
|
+
}
|
|
913
|
+
let asked: ITicketQuestion | undefined;
|
|
914
|
+
if (deployPlan) this.requireDeployTicket(ticket);
|
|
915
|
+
// A plan once asked holds the owner's decision on its target and version: it never moves to another, nor goes, for
|
|
916
|
+
// anyone, or the pump would ask again what the owner decided. Dropping it is closing its ticket. The same plan again
|
|
917
|
+
// is no change while the question waits, and asks anew once the owner answered.
|
|
918
|
+
if (deployPlan && ticket.deployPlan && (deployPlan.target !== ticket.deployPlan.target || deployPlan.version !== ticket.deployPlan.version)) {
|
|
919
|
+
throw new TicketError('ticket_deploy_plan_fixed', ticketErrorMessages.ticket_deploy_plan_fixed);
|
|
920
|
+
}
|
|
921
|
+
if (deployPlan && !await isOpen(ticket.deployPlan?.questionId)) {
|
|
922
|
+
asked = await this.askOwner(ticketId, (await this.questions(ticketId, sessionArg)).length + 1, (requestArg as TResolvedRequest<'update'>).deployQuestion,
|
|
923
|
+
'ticket_deploy_plan_invalid', actorArg, nowArg, sessionArg);
|
|
924
|
+
ticket.deployPlan = { target: deployPlan.target, version: deployPlan.version, questionId: asked.id };
|
|
925
|
+
}
|
|
648
926
|
if (parentId === null) delete ticket.parentId;
|
|
649
927
|
else if (parentId !== undefined) ticket.parentId = parentId;
|
|
650
928
|
await this.parent(ticket, sessionArg);
|
|
@@ -654,20 +932,41 @@ export class TicketStore {
|
|
|
654
932
|
...(afterArg ? { id: { $gt: afterArg } } : {}) }, sort: { id: 1 }, limit: 500, session: sessionArg }));
|
|
655
933
|
for (const child of children) this.requireParent(child.ticket, ticket);
|
|
656
934
|
}
|
|
657
|
-
|
|
658
|
-
|
|
935
|
+
const [first, second] = [asked, askedWindow].filter((questionArg): questionArg is ITicketQuestion => questionArg !== undefined);
|
|
936
|
+
const saved = await this.save(current, ticket, actorArg, sessionArg, 'updated', nowArg, trackArg, revisionArg, first ? { question: { after: first } } : {});
|
|
937
|
+
if (second) await this.activity(saved, actorArg, sessionArg, 'asked', { question: { after: second } }, nowArg, revisionArg, trackArg);
|
|
938
|
+
return { ticket: await this.shown(saved, actorArg, sessionArg, trackArg) };
|
|
659
939
|
}
|
|
660
940
|
if (methodArg === 'link') {
|
|
661
941
|
const link = (requestArg as { link: TTicketLink }).link;
|
|
942
|
+
if (ticketDeployPlanRefusesLink(ticket, link.kind)) {
|
|
943
|
+
throw new TicketError('ticket_deploy_plan_link_forbidden', ticketErrorMessages.ticket_deploy_plan_link_forbidden);
|
|
944
|
+
}
|
|
662
945
|
if (!ticket.links.some((existingArg) => JSON.stringify(existingArg) === JSON.stringify(link))) ticket.links.push(link);
|
|
663
946
|
return { ticket: await this.shown(await this.save(current, ticket, actorArg, sessionArg, 'linked', nowArg, trackArg, revisionArg),
|
|
664
947
|
actorArg, sessionArg, trackArg) };
|
|
665
948
|
}
|
|
949
|
+
if (methodArg === 'unlink') {
|
|
950
|
+
const link = (requestArg as { link: TTicketLink }).link;
|
|
951
|
+
const index = ticket.links.findIndex((existingArg) => plugins.util.isDeepStrictEqual(existingArg, link));
|
|
952
|
+
if (index < 0) throw new TicketError('ticket_link_not_found', ticketErrorMessages.ticket_link_not_found);
|
|
953
|
+
const before = structuredClone(ticket);
|
|
954
|
+
ticket.links.splice(index, 1);
|
|
955
|
+
// A link is refused only when it is the evidence the column holds: a ticket that lacked it before (one moved by
|
|
956
|
+
// hand before AGL-916) may still drop a wrong `affects` link.
|
|
957
|
+
if (this.holdsEvidence(before, ticket.columnId) && !this.holdsEvidence(ticket, ticket.columnId)) this.requireEvidence(ticket, ticket.columnId);
|
|
958
|
+
return { ticket: await this.shown(await this.save(current, ticket, actorArg, sessionArg, 'unlinked', nowArg, trackArg, revisionArg),
|
|
959
|
+
actorArg, sessionArg, trackArg) };
|
|
960
|
+
}
|
|
666
961
|
const input = requestArg as ITicketMove;
|
|
667
962
|
if (actorArg.role === 'worker' && !workerColumns.has(input.columnId)) {
|
|
668
963
|
throw new TicketError('ticket_worker_column', 'Workers may move only to ready, in_progress, needs_input and review; only driver or owner may land or release.');
|
|
669
964
|
}
|
|
670
965
|
if (input.beforeTicketId === ticketId) throw new TicketError('ticket_move_anchor_invalid', 'A ticket cannot be moved before itself.');
|
|
966
|
+
// A move into a column brings the column's evidence (AGL-916); one already there may be reordered as it is.
|
|
967
|
+
if (ticket.columnId !== input.columnId) this.requireEvidence(ticket, input.columnId);
|
|
968
|
+
// Landed code ships with the tag that holds it: closing its ticket would drop it from release and deploy tracking.
|
|
969
|
+
if (ticket.columnId === 'landed' && input.columnId === 'closed') throw new TicketError('ticket_closed_landed', ticketErrorMessages.ticket_closed_landed);
|
|
671
970
|
const destination = (await this.columnTickets(input.columnId, sessionArg)).filter((recordArg) => recordArg.id !== ticketId)
|
|
672
971
|
.sort((leftArg, rightArg) => leftArg.ticket.order - rightArg.ticket.order);
|
|
673
972
|
const index = input.beforeTicketId === undefined ? destination.length : destination.findIndex((recordArg) => recordArg.id === input.beforeTicketId);
|