@revoengine/cli 1.0.28 → 1.0.30
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 +160 -3
- package/dist/src/automation-contract.generated.d.ts +742 -0
- package/dist/src/automation-contract.generated.js +1021 -0
- package/dist/src/cli.js +9 -1
- package/dist/src/client.d.ts +28 -4
- package/dist/src/client.js +60 -0
- package/dist/src/commands/component.js +52 -22
- package/dist/src/commands/env.js +1 -1
- package/dist/src/commands/index.d.ts +2 -0
- package/dist/src/commands/index.js +2 -0
- package/dist/src/commands/studio.d.ts +3 -0
- package/dist/src/commands/studio.js +114 -0
- package/dist/src/commands/terminal-browser-human-input.d.ts +11 -0
- package/dist/src/commands/terminal-browser-human-input.js +44 -0
- package/dist/src/commands/terminal-browser-interaction.d.ts +25 -0
- package/dist/src/commands/terminal-browser-interaction.js +56 -0
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +151 -0
- package/dist/src/commands/terminal-browser-live-protocol.js +177 -0
- package/dist/src/commands/terminal-browser-live-transport.d.ts +41 -0
- package/dist/src/commands/terminal-browser-live-transport.js +206 -0
- package/dist/src/commands/terminal-browser-live.d.ts +114 -0
- package/dist/src/commands/terminal-browser-live.js +455 -0
- package/dist/src/commands/terminal-browser-observation.d.ts +10 -0
- package/dist/src/commands/terminal-browser-observation.js +27 -0
- package/dist/src/commands/terminal-browser-page-input.d.ts +8 -0
- package/dist/src/commands/terminal-browser-page-input.js +94 -0
- package/dist/src/commands/terminal-browser-profile-preferences.d.ts +37 -0
- package/dist/src/commands/terminal-browser-profile-preferences.js +136 -0
- package/dist/src/commands/terminal-browser-profile.d.ts +52 -0
- package/dist/src/commands/terminal-browser-profile.js +447 -0
- package/dist/src/commands/terminal-browser.d.ts +28 -1
- package/dist/src/commands/terminal-browser.js +401 -55
- package/dist/src/commands/terminal-policy.js +2 -0
- package/dist/src/commands/terminal-public-web-proxy.d.ts +14 -0
- package/dist/src/commands/terminal-public-web-proxy.js +141 -0
- package/dist/src/commands/terminal-public-web.d.ts +11 -0
- package/dist/src/commands/terminal-public-web.js +99 -0
- package/dist/src/commands/terminal.d.ts +1 -0
- package/dist/src/commands/terminal.js +92 -9
- package/dist/src/commands/tests.d.ts +3 -0
- package/dist/src/commands/tests.js +236 -0
- package/dist/src/component-element-validation.d.ts +8 -0
- package/dist/src/component-element-validation.js +79 -0
- package/dist/src/component-lifecycle.d.ts +3 -0
- package/dist/src/component-lifecycle.js +17 -0
- package/dist/src/component-lock.d.ts +17 -12
- package/dist/src/component-lock.js +51 -6
- package/dist/src/component-manifests.js +3 -0
- package/dist/src/component-source-validation.d.ts +5 -0
- package/dist/src/component-source-validation.js +27 -0
- package/dist/src/env-sync.js +64 -9
- package/dist/src/native-tests.d.ts +61 -0
- package/dist/src/native-tests.js +20 -0
- package/dist/src/request-contract.d.ts +39 -0
- package/dist/src/request-contract.js +138 -0
- package/dist/src/resource-syncs/agent-sync.js +47 -7
- package/dist/src/resource-syncs/automation-input.d.ts +7 -0
- package/dist/src/resource-syncs/automation-input.js +38 -0
- package/dist/src/resource-syncs/database-table-sync.js +8 -8
- package/dist/src/resource-syncs/endpoint-sync.js +20 -14
- package/dist/src/resource-syncs/event-sync.d.ts +2 -1
- package/dist/src/resource-syncs/event-sync.js +49 -21
- package/dist/src/resource-syncs/group-sync.js +8 -3
- package/dist/src/resource-syncs/job-template-sync.js +75 -28
- package/dist/src/resource-syncs/role-group-sync.js +8 -0
- package/dist/src/resource-syncs/runtime-definition-validation.d.ts +14 -0
- package/dist/src/resource-syncs/runtime-definition-validation.js +153 -0
- package/dist/src/resource-syncs/schedule-sync.d.ts +2 -1
- package/dist/src/resource-syncs/schedule-sync.js +17 -4
- package/dist/src/test-workspace.d.ts +33 -0
- package/dist/src/test-workspace.js +156 -0
- package/dist/src/types.d.ts +8 -2
- package/dist/src/ui.js +12 -0
- package/dist/src/update-notifier.d.ts +1 -1
- package/package.json +5 -3
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type FieldChange } from '../diff-details.ts';
|
|
2
2
|
import type { RevoClient } from '../client.ts';
|
|
3
|
+
import type { AutomationRuntimeInputFields } from '../types.ts';
|
|
3
4
|
export declare const EVENTS_DIRECTORY = "Events";
|
|
4
5
|
export declare const EVENT_MANIFEST_FILE = "event.json";
|
|
5
|
-
export type EventManifest = {
|
|
6
|
+
export type EventManifest = AutomationRuntimeInputFields & {
|
|
6
7
|
kind: 'event';
|
|
7
8
|
stableKey: string;
|
|
8
9
|
name: string;
|
|
@@ -3,13 +3,14 @@ import { describeFieldChanges } from "../diff-details.js";
|
|
|
3
3
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
4
4
|
import { NULL_CATEGORY_KEY, normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
5
5
|
import { readJsonFile, sanitizeSegment } from "../utils.js";
|
|
6
|
+
import { AUTOMATION_INPUT_FIELDS, automationInputError, automationInputHashFields, readAutomationInput } from "./automation-input.js";
|
|
6
7
|
import { findManifestFiles, isRecord, localTargetPath, mapWithConcurrency, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
7
8
|
export const EVENTS_DIRECTORY = 'Events';
|
|
8
9
|
export const EVENT_MANIFEST_FILE = 'event.json';
|
|
9
10
|
const EVENT_TRANSPORT_FIELDS = new Set([
|
|
10
11
|
'jobEventId', 'eventId', 'id', 'name', 'category', 'desc', 'description', 'active', 'type',
|
|
11
12
|
'targetType', 'targetId', 'targetVersion', 'targetConfig', 'filter', 'version', 'metadata',
|
|
12
|
-
'metaData', 'resourceMetadata', 'topic', 'custom', 'deletedAt', 'deletedBy', 'createdAt', 'createdBy',
|
|
13
|
+
'metaData', 'resourceMetadata', 'topic', 'custom', 'input', 'inputMode', 'deletedAt', 'deletedBy', 'createdAt', 'createdBy',
|
|
13
14
|
'lastUpdateAt', 'lastUpdateBy', 'updatedAt', 'updatedBy', 'history', 'jobEventHistory',
|
|
14
15
|
]);
|
|
15
16
|
function eventIdOf(record) {
|
|
@@ -102,7 +103,10 @@ function validManifest(value, stableKeyName) {
|
|
|
102
103
|
if (value.extensions !== undefined && !isRecord(value.extensions)) {
|
|
103
104
|
return false;
|
|
104
105
|
}
|
|
105
|
-
if (value.extensions !== undefined && Object.keys(value.extensions).
|
|
106
|
+
if (value.extensions !== undefined && Object.keys(value.extensions).some((field) => !AUTOMATION_INPUT_FIELDS.has(field))) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
if (automationInputError(value, true)) {
|
|
106
110
|
return false;
|
|
107
111
|
}
|
|
108
112
|
return readConfiguredResourceMetadataStableKey(value, stableKeyName) === value.stableKey;
|
|
@@ -123,18 +127,42 @@ function manifestFromRecord(input) {
|
|
|
123
127
|
active: record.active === true,
|
|
124
128
|
custom: record.custom,
|
|
125
129
|
type: String(record.type || ''),
|
|
130
|
+
...readAutomationInput(record),
|
|
126
131
|
...(record.filter === undefined ? {} : { filter: canonicalValue(record.filter) }),
|
|
127
132
|
target: { type: 'JOB_TEMPLATE', jobTemplateStableKey },
|
|
128
133
|
...(Object.keys(extensions).length > 0 ? { extensions } : {}),
|
|
129
134
|
};
|
|
130
135
|
}
|
|
131
|
-
|
|
132
|
-
return
|
|
136
|
+
function eventHashShape(manifest, extensions) {
|
|
137
|
+
return {
|
|
133
138
|
kind: 'event', stableKey: manifest.stableKey, name: manifest.name, category: manifest.category ?? null,
|
|
134
139
|
description: manifest.description ?? '', metadata: canonicalValue(manifest.metadata), custom: manifest.custom, type: manifest.type,
|
|
135
|
-
filter: canonicalValue(manifest.filter ?? null), target: manifest.target, extensions: canonicalValue(
|
|
140
|
+
filter: canonicalValue(manifest.filter ?? null), target: manifest.target, extensions: canonicalValue(extensions),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function unsupportedEventExtensions(manifest) {
|
|
144
|
+
return Object.fromEntries(Object.entries(manifest.extensions || {}).filter(([field]) => !AUTOMATION_INPUT_FIELDS.has(field)));
|
|
145
|
+
}
|
|
146
|
+
export function hashEventContent(manifest) {
|
|
147
|
+
return hashStable({
|
|
148
|
+
...eventHashShape(manifest, unsupportedEventExtensions(manifest)),
|
|
149
|
+
...automationInputHashFields(manifest, true),
|
|
136
150
|
});
|
|
137
151
|
}
|
|
152
|
+
/** Recognize an old lock representation without discarding any live non-default input. */
|
|
153
|
+
function legacyEventBaselineHash(manifest, layout) {
|
|
154
|
+
const fields = Object.keys(layout.extensions || {}).filter(field => AUTOMATION_INPUT_FIELDS.has(field));
|
|
155
|
+
if (fields.length === 0)
|
|
156
|
+
return undefined;
|
|
157
|
+
const input = readAutomationInput(manifest, true);
|
|
158
|
+
if (Object.keys(automationInputHashFields(manifest, true)).some(field => !fields.includes(field)))
|
|
159
|
+
return undefined;
|
|
160
|
+
const extensions = {
|
|
161
|
+
...unsupportedEventExtensions(manifest),
|
|
162
|
+
...Object.fromEntries(fields.map(field => [field, input[field]])),
|
|
163
|
+
};
|
|
164
|
+
return hashStable({ content: hashStable(eventHashShape(manifest, extensions)), active: manifest.active });
|
|
165
|
+
}
|
|
138
166
|
export function hashPortableEvent(manifest) {
|
|
139
167
|
return hashStable({ content: hashEventContent(manifest), active: manifest.active });
|
|
140
168
|
}
|
|
@@ -191,6 +219,8 @@ function emptyPlanCounts() {
|
|
|
191
219
|
};
|
|
192
220
|
}
|
|
193
221
|
function diffEvents(desired, current) {
|
|
222
|
+
const desiredInput = readAutomationInput(desired, true);
|
|
223
|
+
const currentInput = readAutomationInput(current, true);
|
|
194
224
|
const fields = [
|
|
195
225
|
['name', desired.name, current.name],
|
|
196
226
|
['category', desired.category ?? null, current.category ?? null],
|
|
@@ -200,7 +230,9 @@ function diffEvents(desired, current) {
|
|
|
200
230
|
['type', desired.type, current.type],
|
|
201
231
|
['filter', desired.filter ?? null, current.filter ?? null],
|
|
202
232
|
['target.jobTemplateStableKey', desired.target.jobTemplateStableKey, current.target.jobTemplateStableKey],
|
|
203
|
-
['
|
|
233
|
+
['input', desiredInput.input, currentInput.input],
|
|
234
|
+
['inputMode', desiredInput.inputMode, currentInput.inputMode],
|
|
235
|
+
['extensions', unsupportedEventExtensions(desired), unsupportedEventExtensions(current)],
|
|
204
236
|
];
|
|
205
237
|
return fields
|
|
206
238
|
.filter(([, left, right]) => hashStable(left) !== hashStable(right))
|
|
@@ -257,13 +289,15 @@ export async function buildEventsPlan(input) {
|
|
|
257
289
|
const manifest = entry.manifest;
|
|
258
290
|
if (!validManifest(manifest, input.stableKeyName)) {
|
|
259
291
|
const unsupportedExtensions = isRecord(manifest) && isRecord(manifest.extensions)
|
|
260
|
-
? Object.keys(manifest.extensions).sort()
|
|
292
|
+
? Object.keys(manifest.extensions).filter((field) => !AUTOMATION_INPUT_FIELDS.has(field)).sort()
|
|
261
293
|
: [];
|
|
294
|
+
const inputError = isRecord(manifest) ? automationInputError(manifest, true) : undefined;
|
|
262
295
|
const reason = unsupportedExtensions.length > 0
|
|
263
296
|
? `unsupported extension fields: ${unsupportedExtensions.join(', ')}`
|
|
264
|
-
:
|
|
265
|
-
|
|
266
|
-
|
|
297
|
+
: inputError ? inputError
|
|
298
|
+
: isRecord(manifest) && manifest.custom === undefined
|
|
299
|
+
? 'missing custom classifier; re-pull the Event from its source or add custom: true/false explicitly'
|
|
300
|
+
: 'invalid manifest';
|
|
267
301
|
blockers.push(`Invalid Event manifest ${path.relative(projectRoot, entry.manifestPath)}: ${reason}.`);
|
|
268
302
|
items.push({ status: 'conflict', name: isRecord(manifest) && nonEmptyString(manifest.name) ? manifest.name : path.basename(entry.manifestPath), reason, blocked: true });
|
|
269
303
|
continue;
|
|
@@ -407,7 +441,7 @@ export async function buildEventsPlan(input) {
|
|
|
407
441
|
}
|
|
408
442
|
consumedTargets.add(stableKey);
|
|
409
443
|
const current = targets[0];
|
|
410
|
-
const fieldChanges = describeFieldChanges(desired, current.manifest, diffEvents(desired, current.manifest));
|
|
444
|
+
const fieldChanges = describeFieldChanges({ ...desired, ...readAutomationInput(desired, true) }, current.manifest, diffEvents(desired, current.manifest));
|
|
411
445
|
const currentHash = current.hash;
|
|
412
446
|
const baselineHash = lock.events[stableKey]?.environments[input.envName]?.remoteHash;
|
|
413
447
|
const currentContentHash = current.contentHash;
|
|
@@ -429,10 +463,10 @@ export async function buildEventsPlan(input) {
|
|
|
429
463
|
else if (!baselineHash) {
|
|
430
464
|
items.push({ status: 'missing-lock', ...common, fieldChanges, currentHash, changedFields: diffEvents(desired, current.manifest), reason: `missing ${input.envName} lock baseline` });
|
|
431
465
|
}
|
|
432
|
-
else if (currentHash === baselineHash) {
|
|
466
|
+
else if (currentHash === baselineHash || legacyEventBaselineHash(current.manifest, desired) === baselineHash) {
|
|
433
467
|
items.push({ status: 'safe-update', ...common, fieldChanges, currentHash, baselineHash, changedFields: diffEvents(desired, current.manifest), reason: 'local manifest changed; target matches lock baseline' });
|
|
434
468
|
}
|
|
435
|
-
else if (common.desiredHash === baselineHash) {
|
|
469
|
+
else if (common.desiredHash === baselineHash || legacyEventBaselineHash(desired, desired) === baselineHash) {
|
|
436
470
|
items.push({ status: 'remote-changed', ...common, fieldChanges, currentHash, baselineHash, changedFields: diffEvents(desired, current.manifest), reason: 'target changed; local manifest matches lock baseline' });
|
|
437
471
|
}
|
|
438
472
|
else {
|
|
@@ -475,9 +509,8 @@ export async function buildEventsPlan(input) {
|
|
|
475
509
|
};
|
|
476
510
|
}
|
|
477
511
|
function buildEventCreatePayload(manifest, targetId) {
|
|
478
|
-
const extensions = writableEventExtensions(manifest.extensions);
|
|
479
512
|
return {
|
|
480
|
-
...
|
|
513
|
+
...readAutomationInput(manifest, true),
|
|
481
514
|
name: manifest.name,
|
|
482
515
|
...(manifest.category === undefined || manifest.category === null ? {} : { category: manifest.category }),
|
|
483
516
|
active: false,
|
|
@@ -491,9 +524,8 @@ function buildEventCreatePayload(manifest, targetId) {
|
|
|
491
524
|
};
|
|
492
525
|
}
|
|
493
526
|
function buildEventUpdatePayload(manifest, targetId, version) {
|
|
494
|
-
const extensions = writableEventExtensions(manifest.extensions);
|
|
495
527
|
return {
|
|
496
|
-
...
|
|
528
|
+
...readAutomationInput(manifest, true),
|
|
497
529
|
name: manifest.name,
|
|
498
530
|
category: manifest.category ?? null,
|
|
499
531
|
desc: manifest.description ?? '',
|
|
@@ -506,10 +538,6 @@ function buildEventUpdatePayload(manifest, targetId, version) {
|
|
|
506
538
|
version,
|
|
507
539
|
};
|
|
508
540
|
}
|
|
509
|
-
function writableEventExtensions(extensions) {
|
|
510
|
-
return canonicalValue(Object.fromEntries(Object.entries(extensions || {})
|
|
511
|
-
.filter(([key]) => !EVENT_TRANSPORT_FIELDS.has(key))));
|
|
512
|
-
}
|
|
513
541
|
function workspaceEventsByStableKey(cwd, stableKeyName) {
|
|
514
542
|
const events = new Map();
|
|
515
543
|
for (const entry of readWorkspaceEvents(cwd)) {
|
|
@@ -4,10 +4,12 @@ import { ownerFromPrincipal, resolveSystemAccount } from "./account-principal.js
|
|
|
4
4
|
import { describeFieldChanges, formatDiffValue } from "../diff-details.js";
|
|
5
5
|
import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
|
|
6
6
|
import { readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "../resource-metadata.js";
|
|
7
|
+
import { validateUserMetadata } from "../request-contract.js";
|
|
7
8
|
import { readJsonFile, sanitizeSegment } from "../utils.js";
|
|
8
9
|
import { findManifestFiles, isRecord, localTargetPath, mapWithConcurrency, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
9
10
|
export const GROUPS_DIRECTORY = 'Groups';
|
|
10
11
|
export const GROUP_MANIFEST_FILE = 'group.json';
|
|
12
|
+
const GROUP_MANIFEST_FIELDS = new Set(['kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'owner']);
|
|
11
13
|
function groupIdOf(record) {
|
|
12
14
|
return String(record.groupId || record.id || '');
|
|
13
15
|
}
|
|
@@ -115,6 +117,10 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
115
117
|
if (!isRecord(manifest)) {
|
|
116
118
|
return ['manifest must be a JSON object'];
|
|
117
119
|
}
|
|
120
|
+
const unsupportedFields = Object.keys(manifest).filter((key) => !GROUP_MANIFEST_FIELDS.has(key)).sort();
|
|
121
|
+
if (unsupportedFields.length > 0) {
|
|
122
|
+
errors.push(`unsupported manifest fields: ${unsupportedFields.join(', ')}`);
|
|
123
|
+
}
|
|
118
124
|
if (manifest.kind !== 'group'
|
|
119
125
|
|| typeof manifest.stableKey !== 'string'
|
|
120
126
|
|| !manifest.stableKey.trim()
|
|
@@ -135,9 +141,8 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
135
141
|
|| manifest.owner.type === 'service-account' && typeof manifest.owner.stableKey === 'string' && !!manifest.owner.stableKey.trim()))) {
|
|
136
142
|
errors.push('owner must contain a Service Account stableKey or a System reference');
|
|
137
143
|
}
|
|
138
|
-
if (isRecord(manifest.metadata)
|
|
139
|
-
errors.push(
|
|
140
|
-
}
|
|
144
|
+
if (isRecord(manifest.metadata))
|
|
145
|
+
errors.push(...validateUserMetadata(manifest.metadata));
|
|
141
146
|
const metadataStableKey = isRecord(manifest.metadata)
|
|
142
147
|
? readConfiguredResourceMetadataStableKey(manifest, stableKeyName)
|
|
143
148
|
: null;
|
|
@@ -6,10 +6,11 @@ import { describeFieldChanges } from "../diff-details.js";
|
|
|
6
6
|
import { hashStable, readComponentLock, writeComponentLock } from "../component-lock.js";
|
|
7
7
|
import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata } from "../resource-metadata.js";
|
|
8
8
|
import { readJsonFile, sanitizeSegment } from "../utils.js";
|
|
9
|
+
import { canonicalJobRuntimeOptionDefaults, jobTemplateDefinitionErrors } from "./runtime-definition-validation.js";
|
|
10
|
+
import { requestContractDefaults } from "../request-contract.js";
|
|
9
11
|
import { findManifestFiles, isRecord, localTargetPath, mapWithConcurrency, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
10
12
|
export const JOB_TEMPLATES_DIRECTORY = 'JobTemplates';
|
|
11
13
|
export const JOB_TEMPLATE_MANIFEST_FILE = 'job-template.json';
|
|
12
|
-
const DEFAULT_JOB_TEMPLATE_MEMORY_MB = 256;
|
|
13
14
|
function canonicalValue(value) {
|
|
14
15
|
if (Array.isArray(value))
|
|
15
16
|
return value.map((item) => canonicalValue(item));
|
|
@@ -26,15 +27,13 @@ function canonicalJobTemplateInputs(value) {
|
|
|
26
27
|
return {};
|
|
27
28
|
return canonicalValue(value);
|
|
28
29
|
}
|
|
29
|
-
function canonicalJobTemplateOptions(value, inputs) {
|
|
30
|
+
function canonicalJobTemplateOptions(value, inputs, normalizeDefaults = true) {
|
|
30
31
|
const canonical = canonicalValue(value);
|
|
31
32
|
if (!isRecord(canonical))
|
|
32
|
-
return canonical;
|
|
33
|
-
const normalized = { ...canonical };
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
if (normalized.memory === DEFAULT_JOB_TEMPLATE_MEMORY_MB)
|
|
37
|
-
delete normalized.memory;
|
|
33
|
+
return normalizeDefaults && canonical === null ? undefined : canonical;
|
|
34
|
+
const normalized = normalizeDefaults ? canonicalJobRuntimeOptionDefaults(canonical) : { ...canonical };
|
|
35
|
+
// Historical hashes that stripped explicit memory cannot prove the same live
|
|
36
|
+
// definition: missing memory follows input overlays, then the isolate default.
|
|
38
37
|
const canonicalInputs = canonicalJobTemplateInputs(inputs);
|
|
39
38
|
const inputIsEmpty = isRecord(normalized.input) && Object.keys(normalized.input).length === 0;
|
|
40
39
|
const inputDuplicatesLegacyInputs = inputs !== undefined
|
|
@@ -109,9 +108,6 @@ function isOptionalString(value, { nullable = false } = {}) {
|
|
|
109
108
|
function isOptionalRecord(value, { nullable = false } = {}) {
|
|
110
109
|
return value === undefined || (nullable && value === null) || isRecord(value);
|
|
111
110
|
}
|
|
112
|
-
function isOptionalFiniteNumber(value) {
|
|
113
|
-
return value === undefined || (typeof value === 'number' && Number.isFinite(value));
|
|
114
|
-
}
|
|
115
111
|
function hasValidJobTemplateComponent(value) {
|
|
116
112
|
return isRecord(value)
|
|
117
113
|
&& hasOnlyKeys(value, new Set(['stableKey', 'pinnedDigest']))
|
|
@@ -143,9 +139,8 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
143
139
|
if (!isOptionalString(manifest.description)) {
|
|
144
140
|
return false;
|
|
145
141
|
}
|
|
146
|
-
if (!
|
|
142
|
+
if (manifest.timeout !== undefined && (typeof manifest.timeout !== 'number' || !Number.isFinite(manifest.timeout)))
|
|
147
143
|
return false;
|
|
148
|
-
}
|
|
149
144
|
if (!isOptionalRecord(manifest.options, { nullable: true })) {
|
|
150
145
|
return false;
|
|
151
146
|
}
|
|
@@ -161,6 +156,8 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
161
156
|
if (!hasValidJobTemplateMigration(manifest.migration)) {
|
|
162
157
|
return false;
|
|
163
158
|
}
|
|
159
|
+
if (jobTemplateDefinitionErrors(manifest).length > 0)
|
|
160
|
+
return false;
|
|
164
161
|
return readConfiguredResourceMetadataStableKey(manifest, stableKeyName) === manifest.stableKey;
|
|
165
162
|
}
|
|
166
163
|
async function componentStableKey(input) {
|
|
@@ -174,7 +171,7 @@ async function componentStableKey(input) {
|
|
|
174
171
|
return readConfiguredResourceMetadataStableKey(component || {}, input.stableKeyName);
|
|
175
172
|
}
|
|
176
173
|
function manifestFromRecord(record, stableKey, componentKey, stableKeyName) {
|
|
177
|
-
|
|
174
|
+
const manifest = {
|
|
178
175
|
kind: 'job-template',
|
|
179
176
|
stableKey,
|
|
180
177
|
name: String(record.name || ''),
|
|
@@ -186,6 +183,10 @@ function manifestFromRecord(record, stableKey, componentKey, stableKeyName) {
|
|
|
186
183
|
...(record.options === undefined ? {} : { options: canonicalValue(record.options) }),
|
|
187
184
|
...(record.inputs === undefined ? {} : { inputs: canonicalValue(record.inputs) }),
|
|
188
185
|
};
|
|
186
|
+
const errors = jobTemplateDefinitionErrors(manifest);
|
|
187
|
+
if (errors.length > 0)
|
|
188
|
+
throw new Error(`Job template "${stableKey}" has invalid backend definition: ${errors.join('; ')}.`);
|
|
189
|
+
return manifest;
|
|
189
190
|
}
|
|
190
191
|
async function withRecordPrincipal(client, record, manifest, stableKeyName, compare, preferLegacy = false) {
|
|
191
192
|
if (!compare) {
|
|
@@ -211,6 +212,11 @@ async function targetPrincipalId(client, manifest, stableKeyName, target) {
|
|
|
211
212
|
...(target?.executionPolicy && target.executionPolicy.mode !== 'INHERIT' ? { executionPolicy: { mode: 'INHERIT' } } : {}) };
|
|
212
213
|
}
|
|
213
214
|
function buildCreatePayload(manifest, componentId) {
|
|
215
|
+
const hasLegacyInput = isRecord(manifest.inputs) && Object.keys(manifest.inputs).length > 0;
|
|
216
|
+
// An absent/null options envelope is expanded before the backend legacy alias
|
|
217
|
+
// is applied. Make that alias explicit so the requested template input survives creation.
|
|
218
|
+
const options = manifest.options == null && hasLegacyInput
|
|
219
|
+
? { input: canonicalValue(manifest.inputs) } : canonicalValue(manifest.options);
|
|
214
220
|
return {
|
|
215
221
|
name: manifest.name,
|
|
216
222
|
...(manifest.category === undefined ? {} : { category: manifest.category }),
|
|
@@ -219,7 +225,7 @@ function buildCreatePayload(manifest, componentId) {
|
|
|
219
225
|
componentId,
|
|
220
226
|
...(manifest.component.pinnedDigest ? { componentDigest: manifest.component.pinnedDigest } : {}),
|
|
221
227
|
...(manifest.timeout === undefined ? {} : { timeout: manifest.timeout }),
|
|
222
|
-
...(
|
|
228
|
+
...(options === undefined ? {} : { options }),
|
|
223
229
|
...(manifest.inputs === undefined ? {} : { inputs: canonicalValue(manifest.inputs) }),
|
|
224
230
|
};
|
|
225
231
|
}
|
|
@@ -233,13 +239,18 @@ function buildUpdatePayload(manifest, componentId, version) {
|
|
|
233
239
|
componentDigest: manifest.component.pinnedDigest ?? null,
|
|
234
240
|
componentVersion: null,
|
|
235
241
|
...(manifest.timeout === undefined ? {} : { timeout: manifest.timeout }),
|
|
236
|
-
|
|
242
|
+
options: isRecord(manifest.options) ? canonicalValue(manifest.options) : {},
|
|
237
243
|
...(manifest.inputs === undefined ? {} : { inputs: canonicalValue(manifest.inputs) }),
|
|
238
244
|
version,
|
|
239
245
|
};
|
|
240
246
|
}
|
|
241
247
|
export function hashPortableJobTemplate(manifest) {
|
|
242
|
-
|
|
248
|
+
return jobTemplateDefinitionHash(manifest, true);
|
|
249
|
+
}
|
|
250
|
+
function jobTemplateDefinitionHash(manifest, normalizeDefaults) {
|
|
251
|
+
const options = canonicalJobTemplateOptions(manifest.options, manifest.inputs, normalizeDefaults);
|
|
252
|
+
const rawInputs = canonicalJobTemplateInputs(manifest.inputs);
|
|
253
|
+
const inputs = normalizeDefaults && isRecord(rawInputs) && Object.keys(rawInputs).length === 0 ? undefined : rawInputs;
|
|
243
254
|
return hashStable({
|
|
244
255
|
kind: 'job-template',
|
|
245
256
|
stableKey: manifest.stableKey,
|
|
@@ -250,9 +261,10 @@ export function hashPortableJobTemplate(manifest) {
|
|
|
250
261
|
component: { ...manifest.component },
|
|
251
262
|
...(manifest.executionPrincipal ? { executionPrincipal: manifest.executionPrincipal } : {}),
|
|
252
263
|
...(manifest.executionPolicy ? { executionPolicy: manifest.executionPolicy } : {}),
|
|
253
|
-
...(
|
|
264
|
+
...(normalizeDefaults ? { timeout: manifest.timeout ?? requestContractDefaults.job.timeout }
|
|
265
|
+
: manifest.timeout === undefined ? {} : { timeout: manifest.timeout }),
|
|
254
266
|
...(options === undefined ? {} : { options }),
|
|
255
|
-
...(
|
|
267
|
+
...(inputs === undefined ? {} : { inputs }),
|
|
256
268
|
});
|
|
257
269
|
}
|
|
258
270
|
function diffJobTemplates(desired, target) {
|
|
@@ -265,13 +277,13 @@ function diffJobTemplates(desired, target) {
|
|
|
265
277
|
['component.pinnedDigest', desired.component.pinnedDigest, target.component.pinnedDigest],
|
|
266
278
|
...(desired.executionPrincipal ? [['executionPrincipal', desired.executionPrincipal, target.executionPrincipal]] : []),
|
|
267
279
|
...(desired.executionPolicy ? [['executionPolicy', desired.executionPolicy, target.executionPolicy]] : []),
|
|
268
|
-
['timeout', desired.timeout, target.timeout],
|
|
280
|
+
['timeout', desired.timeout ?? requestContractDefaults.job.timeout, target.timeout ?? requestContractDefaults.job.timeout],
|
|
269
281
|
[
|
|
270
282
|
'options',
|
|
271
283
|
canonicalJobTemplateOptions(desired.options, desired.inputs),
|
|
272
284
|
canonicalJobTemplateOptions(target.options, target.inputs),
|
|
273
285
|
],
|
|
274
|
-
['inputs', canonicalJobTemplateInputs(desired.inputs), canonicalJobTemplateInputs(target.inputs)],
|
|
286
|
+
['inputs', canonicalJobTemplateInputs(desired.inputs) ?? {}, canonicalJobTemplateInputs(target.inputs) ?? {}],
|
|
275
287
|
];
|
|
276
288
|
return fields
|
|
277
289
|
.filter(([, desiredValue, targetValue]) => (hashStable({ value: desiredValue }) !== hashStable({ value: targetValue })))
|
|
@@ -333,8 +345,10 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
333
345
|
const localByKey = new Map();
|
|
334
346
|
for (const entry of localEntries) {
|
|
335
347
|
if (!validateManifest(entry.manifest, input.stableKeyName)) {
|
|
336
|
-
|
|
337
|
-
|
|
348
|
+
const errors = isRecord(entry.manifest) ? jobTemplateDefinitionErrors(entry.manifest) : [];
|
|
349
|
+
const reason = errors.length > 0 ? errors.join('; ') : 'invalid job-template manifest';
|
|
350
|
+
blockers.push(`Invalid job-template manifest ${path.relative(projectRoot, entry.manifestPath)}: ${reason}.`);
|
|
351
|
+
items.push({ status: 'conflict', name: path.basename(path.dirname(entry.manifestPath)), reason });
|
|
338
352
|
continue;
|
|
339
353
|
}
|
|
340
354
|
localByKey.set(entry.manifest.stableKey, [...(localByKey.get(entry.manifest.stableKey) || []), entry]);
|
|
@@ -514,10 +528,10 @@ export async function buildJobTemplatesPlan(input) {
|
|
|
514
528
|
else if (desiredHash === target.hash) {
|
|
515
529
|
items.push({ status: 'clean', stableKey: desired.stableKey, name: desired.name, desiredHash, currentHash: target.hash, ...dependencyDetails });
|
|
516
530
|
}
|
|
517
|
-
else if (target.hash === baseline) {
|
|
531
|
+
else if (target.hash === baseline || jobTemplateDefinitionHash(target.manifest, false) === baseline) {
|
|
518
532
|
items.push({ status: 'safe-update', stableKey: desired.stableKey, name: desired.name, desiredHash, currentHash: target.hash, baselineHash: baseline, reason: 'local manifest changed; target matches lock baseline', ...dependencyDetails, ...changeDetails });
|
|
519
533
|
}
|
|
520
|
-
else if (desiredHash === baseline) {
|
|
534
|
+
else if (desiredHash === baseline || jobTemplateDefinitionHash(desired, false) === baseline) {
|
|
521
535
|
items.push({ status: 'remote-changed', stableKey: desired.stableKey, name: desired.name, desiredHash, currentHash: target.hash, baselineHash: baseline, reason: 'target changed; local manifest matches lock baseline', ...dependencyDetails, ...changeDetails });
|
|
522
536
|
}
|
|
523
537
|
else {
|
|
@@ -630,7 +644,8 @@ export async function pullJobTemplatesToWorkspace(input) {
|
|
|
630
644
|
if (existing && !input.force) {
|
|
631
645
|
const localHash = hashPortableJobTemplate(existing.manifest);
|
|
632
646
|
const baseline = lock.jobTemplates[manifest.stableKey];
|
|
633
|
-
if (localHash !== hash && (!baseline || localHash !== baseline.sourceHash
|
|
647
|
+
if (localHash !== hash && (!baseline || localHash !== baseline.sourceHash
|
|
648
|
+
&& jobTemplateDefinitionHash(existing.manifest, false) !== baseline.sourceHash)) {
|
|
634
649
|
throw new Error(`Cannot pull job-template "${manifest.stableKey}": local manifest changed since the lock baseline. Re-run with --force.`);
|
|
635
650
|
}
|
|
636
651
|
}
|
|
@@ -790,7 +805,9 @@ export async function pushJobTemplates(input) {
|
|
|
790
805
|
const createdId = jobTemplateIdOf(created);
|
|
791
806
|
if (!createdId)
|
|
792
807
|
throw new Error('create response did not include jobTemplateId');
|
|
793
|
-
|
|
808
|
+
let verified = unwrapData(await input.client.getJobTemplate(createdId));
|
|
809
|
+
if (jobTemplateIdOf(verified) !== createdId)
|
|
810
|
+
throw new Error('created job template identity changed before verification');
|
|
794
811
|
const verifiedStableKey = readConfiguredResourceMetadataStableKey(verified, input.stableKeyName);
|
|
795
812
|
if (!verifiedStableKey)
|
|
796
813
|
throw new Error(`created job template is missing ${input.stableKeyName}`);
|
|
@@ -799,7 +816,37 @@ export async function pushJobTemplates(input) {
|
|
|
799
816
|
const verifiedComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
|
|
800
817
|
if (!verifiedComponentKey)
|
|
801
818
|
throw new Error(`created job template references a component without ${input.stableKeyName}`);
|
|
802
|
-
|
|
819
|
+
let verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, verifiedStableKey, verifiedComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal || prepared.manifest.executionPolicy), Boolean(prepared.manifest.executionPrincipal));
|
|
820
|
+
const desiredMemory = isRecord(prepared.manifest.options) ? prepared.manifest.options.memory : undefined;
|
|
821
|
+
if (hashPortableJobTemplate(verifiedManifest) !== prepared.desiredHash
|
|
822
|
+
&& (desiredMemory === undefined || desiredMemory === null || desiredMemory === 0)) {
|
|
823
|
+
// Create coerces missing/null/0 memory to 256. The existing update API
|
|
824
|
+
// preserves it, so restore the complete desired options before accepting
|
|
825
|
+
// the new target. Concurrent changes must fail even under --force.
|
|
826
|
+
if (typeof created.version !== 'number' || verified.version !== created.version)
|
|
827
|
+
throw new Error('created job template changed before restoring desired options');
|
|
828
|
+
const createdComponentKey = await componentStableKey({ client: input.client, record: created, stableKeyName: input.stableKeyName });
|
|
829
|
+
if (!createdComponentKey)
|
|
830
|
+
throw new Error(`create response dependency is missing ${input.stableKeyName}`);
|
|
831
|
+
const createdManifest = await withRecordPrincipal(input.client, created, manifestFromRecord(created, stableKey, createdComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal || prepared.manifest.executionPolicy), Boolean(prepared.manifest.executionPrincipal));
|
|
832
|
+
if (hashPortableJobTemplate(createdManifest) !== hashPortableJobTemplate(verifiedManifest))
|
|
833
|
+
throw new Error('created job template changed before restoring desired options');
|
|
834
|
+
const latestLocal = readWorkspaceJobTemplates(input.cwd).find(entry => entry.manifest.stableKey === stableKey);
|
|
835
|
+
if (!latestLocal || hashPortableJobTemplate(latestLocal.manifest) !== prepared.desiredHash)
|
|
836
|
+
throw new Error('desired manifest changed before restoring created job template options');
|
|
837
|
+
await input.client.updateJobTemplate(createdId, {
|
|
838
|
+
...buildUpdatePayload(prepared.manifest, prepared.componentId, created.version),
|
|
839
|
+
...await targetPrincipalId(input.client, prepared.manifest, input.stableKeyName, verified),
|
|
840
|
+
});
|
|
841
|
+
verified = unwrapData(await input.client.getJobTemplate(createdId));
|
|
842
|
+
const restoredStableKey = readConfiguredResourceMetadataStableKey(verified, input.stableKeyName);
|
|
843
|
+
if (restoredStableKey !== stableKey)
|
|
844
|
+
throw new Error(`restored target is missing or changed ${input.stableKeyName}`);
|
|
845
|
+
const restoredComponentKey = await componentStableKey({ client: input.client, record: verified, stableKeyName: input.stableKeyName });
|
|
846
|
+
if (!restoredComponentKey)
|
|
847
|
+
throw new Error(`restored target dependency is missing ${input.stableKeyName}`);
|
|
848
|
+
verifiedManifest = await withRecordPrincipal(input.client, verified, manifestFromRecord(verified, restoredStableKey, restoredComponentKey, input.stableKeyName), input.stableKeyName, Boolean(prepared.manifest.executionPrincipal || prepared.manifest.executionPolicy), Boolean(prepared.manifest.executionPrincipal));
|
|
849
|
+
}
|
|
803
850
|
if (hashPortableJobTemplate(verifiedManifest) !== prepared.desiredHash) {
|
|
804
851
|
throw new Error('created job template did not match desired portable hash');
|
|
805
852
|
}
|
|
@@ -2,10 +2,12 @@ import path from 'node:path';
|
|
|
2
2
|
import { describeFieldChanges } from "../diff-details.js";
|
|
3
3
|
import { hashStable, readComponentLock, writeComponentLock, } from "../component-lock.js";
|
|
4
4
|
import { normalizeStableKeyValue, readConfiguredResourceMetadataStableKey, sanitizeUserMetadata, } from "../resource-metadata.js";
|
|
5
|
+
import { validateUserMetadata } from "../request-contract.js";
|
|
5
6
|
import { readJsonFile, sanitizeSegment } from "../utils.js";
|
|
6
7
|
import { findManifestFiles, isRecord, localTargetPath, mapWithConcurrency, removeRelocatedManifest, requireProjectLayout, stableKeySuffix, toPortableRelativePath, unwrapData, writePulledManifest, } from "./util.js";
|
|
7
8
|
export const ROLE_GROUPS_DIRECTORY = 'RoleGroups';
|
|
8
9
|
export const ROLE_GROUP_MANIFEST_FILE = 'role-group.json';
|
|
10
|
+
const ROLE_GROUP_MANIFEST_FIELDS = new Set(['kind', 'stableKey', 'name', 'category', 'description', 'metadata', 'roles']);
|
|
9
11
|
function roleGroupIdOf(record) {
|
|
10
12
|
return String(record.roleGroupId || record.id || '');
|
|
11
13
|
}
|
|
@@ -98,6 +100,10 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
98
100
|
if (!isRecord(manifest)) {
|
|
99
101
|
return ['manifest must be a JSON object'];
|
|
100
102
|
}
|
|
103
|
+
const unsupportedFields = Object.keys(manifest).filter((key) => !ROLE_GROUP_MANIFEST_FIELDS.has(key)).sort();
|
|
104
|
+
if (unsupportedFields.length > 0) {
|
|
105
|
+
errors.push(`unsupported manifest fields: ${unsupportedFields.join(', ')}`);
|
|
106
|
+
}
|
|
101
107
|
if (manifest.kind !== 'role-group'
|
|
102
108
|
|| typeof manifest.stableKey !== 'string'
|
|
103
109
|
|| !manifest.stableKey.trim()
|
|
@@ -112,6 +118,8 @@ function validateManifest(manifest, stableKeyName) {
|
|
|
112
118
|
if (manifest.description !== undefined && typeof manifest.description !== 'string') {
|
|
113
119
|
errors.push('description must be a string or omitted');
|
|
114
120
|
}
|
|
121
|
+
if (isRecord(manifest.metadata))
|
|
122
|
+
errors.push(...validateUserMetadata(manifest.metadata));
|
|
115
123
|
const metadataStableKey = isRecord(manifest.metadata)
|
|
116
124
|
? readConfiguredResourceMetadataStableKey(manifest, stableKeyName)
|
|
117
125
|
: null;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Matches the Endpoint DTO transform, so accepted normalized routes also verify on readback. */
|
|
2
|
+
export declare function normalizeEndpointPath(value: string): string;
|
|
3
|
+
/** Endpoint create and update normalize nullable/zero memory and result references. */
|
|
4
|
+
export declare function canonicalEndpointOptionDefaults(value: Record<string, unknown> | undefined): {
|
|
5
|
+
[x: string]: unknown;
|
|
6
|
+
} | undefined;
|
|
7
|
+
/** Job create/update materialize nullable concurrency fields and the complete retry policy. */
|
|
8
|
+
export declare function canonicalJobRuntimeOptionDefaults(value: Record<string, unknown>): {
|
|
9
|
+
[x: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
/** Request DTO constraints plus the API's local static guard and schema-binding policy. */
|
|
12
|
+
export declare function endpointDefinitionErrors(manifest: Record<string, unknown>): string[];
|
|
13
|
+
/** The runtime normalizes nullable option containers, then validates effective retry backoff. */
|
|
14
|
+
export declare function jobTemplateDefinitionErrors(manifest: Record<string, unknown>): string[];
|