@aifabrix/builder 2.58.0 → 2.59.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.
Files changed (84) hide show
  1. package/lib/agent-kit/codex-app-server.js +44 -0
  2. package/lib/agent-kit/init.js +4 -17
  3. package/lib/agent-kit/session-report.js +15 -10
  4. package/lib/agent-kit/setup-auth.js +131 -0
  5. package/lib/agent-kit/setup-context.js +118 -0
  6. package/lib/agent-kit/setup-github.js +70 -0
  7. package/lib/agent-kit/setup-managed.js +79 -0
  8. package/lib/agent-kit/setup-process.js +42 -0
  9. package/lib/agent-kit/setup-session.js +53 -0
  10. package/lib/agent-kit/setup-state.js +52 -0
  11. package/lib/agent-kit/setup-workspace.js +113 -0
  12. package/lib/agent-kit/setup.js +84 -0
  13. package/lib/agent-kit/start.js +4 -3
  14. package/lib/agent-kit/tmux-sessions.js +20 -3
  15. package/lib/api/dev.api.js +1 -1
  16. package/lib/api/miso-health.api.js +26 -0
  17. package/lib/api/types/dev.types.js +3 -3
  18. package/lib/app/deploy.js +0 -102
  19. package/lib/cli/index.js +4 -0
  20. package/lib/cli/setup-dev-path-commands.js +4 -0
  21. package/lib/cli/setup-dev.js +7 -4
  22. package/lib/cli/setup-help.js +86 -0
  23. package/lib/cli/setup-onboarding.js +37 -0
  24. package/lib/cli/setup-utility-repair.js +7 -5
  25. package/lib/commands/agent-kit-help.js +21 -7
  26. package/lib/commands/agent-kit-sessions.js +126 -0
  27. package/lib/commands/agent-kit-setup.js +44 -0
  28. package/lib/commands/agent-kit.js +5 -79
  29. package/lib/commands/dev-init.js +21 -23
  30. package/lib/commands/dev-refresh.js +2 -2
  31. package/lib/commands/governance-verify-external.js +12 -5
  32. package/lib/commands/repair-datasource.js +9 -9
  33. package/lib/commands/repair.js +45 -8
  34. package/lib/commands/upload-qualification-client.js +56 -11
  35. package/lib/commands/upload-qualification-poll.js +51 -22
  36. package/lib/commands/wizard-dataplane.js +16 -52
  37. package/lib/datasource/datasource-validate-summary.js +8 -5
  38. package/lib/datasource/sync-defaults.js +53 -0
  39. package/lib/deployment/installation/azure-infra-stage.js +10 -0
  40. package/lib/deployment/installation/azure-preflight.js +13 -2
  41. package/lib/deployment/installation/azure-readiness.js +24 -2
  42. package/lib/deployment/installation/environment-auth.js +60 -20
  43. package/lib/deployment/installation/environment-stage.js +9 -5
  44. package/lib/deployment/installation/infra-catalog.js +8 -2
  45. package/lib/deployment/installation/infra-manifest.js +5 -0
  46. package/lib/deployment/installation/registry-auth-mode.js +33 -10
  47. package/lib/deployment/marketplace-environment.js +26 -1
  48. package/lib/generator/index.js +23 -12
  49. package/lib/integration-definition/apply.js +2 -2
  50. package/lib/internal/fs-real-sync.js +4 -1
  51. package/lib/programmatic/bearer-auth.js +3 -62
  52. package/lib/programmatic/builder-api-startup.js +51 -0
  53. package/lib/programmatic/builder-miso-runtime.js +167 -0
  54. package/lib/programmatic/openapi-descriptions.js +3 -3
  55. package/lib/programmatic/openapi-schema-descriptions-core.js +3 -3
  56. package/lib/programmatic/openapi-spec.js +2 -1
  57. package/lib/programmatic/route-handler-map.js +3 -2
  58. package/lib/schema/environment-deploy-request.schema.json +1 -1
  59. package/lib/schema/external-datasource.schema.json +20 -5
  60. package/lib/schema/infra-parameter.schema.json +1 -1
  61. package/lib/schema/infra.parameter.yaml +2 -1
  62. package/lib/schema/infrastructure-schema.json +145 -1
  63. package/lib/schema/installation-environment.schema.json +1 -1
  64. package/lib/schema/wizard-config.schema.json +1 -1
  65. package/lib/utils/config-paths.js +24 -29
  66. package/lib/utils/config-registry-preference.js +13 -6
  67. package/lib/utils/dev-init-ssh-merge.js +5 -4
  68. package/lib/utils/dev-user-groups.js +2 -1
  69. package/lib/utils/docker-daemon-tls-ca.js +2 -2
  70. package/lib/utils/error-formatters/validation-errors.js +25 -5
  71. package/lib/utils/help-builder.js +4 -3
  72. package/lib/utils/token-manager.js +29 -36
  73. package/package.json +3 -2
  74. package/templates/agent-kit/instructions/AGENTKIT.md +39 -2
  75. package/templates/agent-kit/instructions/root.AGENTS.md +40 -1
  76. package/templates/agent-kit/skills/shared/hosts.md +23 -5
  77. package/templates/agent-kit/workspace/README.md +14 -1
  78. package/templates/applications/builder-api/application.yaml +1 -1
  79. package/templates/applications/dataplane/application.yaml +1 -1
  80. package/templates/applications/dataplane/env.template +1 -1
  81. package/templates/applications/miso-controller/application.yaml +1 -1
  82. package/templates/applications/miso-controller/env.template +1 -1
  83. package/templates/external-system/external-datasource.yaml.hbs +7 -6
  84. package/templates/marketplace/main.json +438 -80
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Repair external integration config: fix drift between config and files on disk.
2
+ * Repair application documentation and external integration configuration drift.
3
3
  *
4
4
  * Aligns application.yaml with actual system/datasource files, fixes system key mismatch,
5
5
  * creates missing externalIntegration block, extracts rbac.yaml from system when needed,
6
6
  * and regenerates the deployment manifest.
7
7
  *
8
- * @fileoverview Repair external integration drift
8
+ * @fileoverview Repair application README or external integration drift
9
9
  * @author AI Fabrix Team
10
10
  * @version 2.0.0
11
11
  */
@@ -13,6 +13,10 @@
13
13
  'use strict';
14
14
 
15
15
  const fs = require('fs');
16
+ const path = require('path');
17
+ const { generateReadmeMd } = require('../app/readme');
18
+ const { backupIntegrationFile } = require('../utils/integration-file-backup');
19
+ const { trackRepairWrite } = require('./repair-changed-files');
16
20
  const { detectAppType } = require('../utils/paths');
17
21
  const { resolveApplicationConfigPath } = require('../utils/app-config-resolver');
18
22
  const { loadConfigFile, isYamlPath } = require('../utils/config-format');
@@ -43,7 +47,7 @@ function loadConfigAndDiscover(appPath, configPath) {
43
47
  * Validates repair inputs and resolves app path and config path.
44
48
  * @param {string} appName - Application name
45
49
  * @param {Object} options - Command options (auth)
46
- * @returns {Promise<{ appPath: string, configPath: string, dryRun: boolean, authOption: string|undefined }>}
50
+ * @returns {Promise<{ appPath: string, configPath: string, dryRun: boolean, authOption: string|undefined, isExternal: boolean }>}
47
51
  */
48
52
  async function validateAndResolveRepairPaths(appName, options) {
49
53
  if (!appName || typeof appName !== 'string') throw new Error('App name is required');
@@ -52,10 +56,42 @@ async function validateAndResolveRepairPaths(appName, options) {
52
56
  throw new Error('Option --auth must be a string');
53
57
  }
54
58
  const { appPath, isExternal } = await detectAppType(appName, options);
55
- if (!isExternal) throw new Error(`App '${appName}' is not an external integration`);
59
+ if (!isExternal) validateApplicationRepairOptions(appName, options);
56
60
  const configPath = resolveApplicationConfigPath(appPath);
57
61
  if (!fs.existsSync(configPath)) throw new Error(`Application config not found: ${configPath}`);
58
- return { appPath, configPath, dryRun, authOption };
62
+ return { appPath, configPath, dryRun, authOption, isExternal };
63
+ }
64
+
65
+ /** Validate the documentation-only repair supported for normal applications. */
66
+ function validateApplicationRepairOptions(appName, options) {
67
+ const integrationOptions = ['all', 'api', 'auth', 'rbac', 'expose', 'sync', 'test',
68
+ 'splitDatasources', 'rbacPreset', 'authWebhook', 'authSync'];
69
+ if (!options.doc || integrationOptions.some(key => options[key] !== undefined && options[key] !== false && options[key] !== null)) {
70
+ throw new Error(`App '${appName}' is not an external integration. Normal applications support repair --doc only (with --dry-run or --no-backup).`);
71
+ }
72
+ }
73
+
74
+ /** Regenerate a normal application's README using its current local configuration. */
75
+ function repairApplicationReadme(appName, appPath, configPath, backupCtx) {
76
+ const variables = loadConfigFile(configPath);
77
+ const content = generateReadmeMd(appName, { ...variables, ...variables.app });
78
+ const readmePath = path.join(appPath, 'README.md');
79
+ trackRepairWrite(readmePath, backupCtx);
80
+ if (!backupCtx.dryRun) {
81
+ backupIntegrationFile(readmePath, backupCtx);
82
+ fs.writeFileSync(readmePath, content, { mode: 0o644, encoding: 'utf8' });
83
+ }
84
+ return {
85
+ updated: true,
86
+ applicationReadme: true,
87
+ actionsPerformed: true,
88
+ readmeRegenerated: true,
89
+ manifestRegenerated: false,
90
+ changes: ['Regenerated README.md from application configuration'],
91
+ changedFiles: backupCtx.dryRun ? backupCtx.wouldChangeFiles : backupCtx.changedFiles,
92
+ backupPaths: backupCtx.backupPaths,
93
+ warnings: []
94
+ };
59
95
  }
60
96
 
61
97
  /**
@@ -79,17 +115,18 @@ function createRepairBackupContext(options, dryRun) {
79
115
  }
80
116
 
81
117
  /**
82
- * Repairs external integration config: syncs files, aligns keys, creates rbac, regenerates manifest
118
+ * Repairs external integration config or regenerates a normal application's README.
83
119
  * @async
84
120
  * @param {string} appName - Application/integration name
85
121
  * @param {Object} [options] - Options
86
122
  * @param {boolean} [options.dryRun] - If true, only report changes; do not write
87
- * @param {boolean} [options.doc] - If true, regenerate README.md from deployment manifest
123
+ * @param {boolean} [options.doc] - Regenerate README.md from application config or integration deployment manifest
88
124
  * @returns {Promise<Object>}
89
125
  */
90
126
  async function repairExternalIntegration(appName, options = {}) {
91
- const { appPath, configPath, dryRun, authOption } = await validateAndResolveRepairPaths(appName, options);
127
+ const { appPath, configPath, dryRun, authOption, isExternal } = await validateAndResolveRepairPaths(appName, options);
92
128
  const { backupPaths, backupCtx } = createRepairBackupContext(options, dryRun);
129
+ if (!isExternal) return repairApplicationReadme(appName, appPath, configPath, backupCtx);
93
130
  const loaded = loadConfigAndDiscover(appPath, configPath);
94
131
  return runRepairExternalIntegration({
95
132
  appName,
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @fileoverview Resumable Dataplane qualification upload: accept, --wait/--no-wait, poll, resume.
3
- * Mirrors dev-host-ops.js's job id + wait/no-wait contract (plan 191.0 task 1). Never invents
3
+ * Mirrors dev-host-ops.js's job id + wait/no-wait contract. Never invents
4
4
  * qualification truth — accept/poll surface exactly what Dataplane returns.
5
5
  * @author AI Fabrix Team
6
6
  * @version 1.0.0
@@ -12,13 +12,38 @@ const logger = require('../utils/logger');
12
12
  const { formatSuccessLine, formatWarningLine } = require('../utils/cli-test-layout-chalk');
13
13
  const { formatApiError } = require('../utils/api-error-handler');
14
14
  const { uploadApplicationViaPipelineWithAuthRetry } = require('../utils/pipeline-upload-auth-retry');
15
- const { pollQualificationJobUntilTerminal } = require('./upload-qualification-poll');
15
+ const { pollQualificationJobUntilTerminal, requireQualificationSuccess,
16
+ isTransientQualificationPollError } = require('./upload-qualification-poll');
16
17
  const { createQualificationPollHandlers } = require('../utils/qualification-poll-ui');
17
18
 
19
+ function isAmbiguousAcceptance(error) {
20
+ const status = error?.response?.status || error?.statusCode || error?.status;
21
+ const code = error?.cause?.code || error?.code;
22
+ return isTransientQualificationPollError(status) || (!status && (
23
+ error instanceof TypeError || ['AbortError', 'TimeoutError'].includes(error?.name) ||
24
+ ['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'EAI_AGAIN', 'ENOTFOUND',
25
+ 'ECONNABORTED', 'UND_ERR_CONNECT_TIMEOUT'].includes(code)
26
+ ));
27
+ }
28
+
29
+ async function submitQualificationUpload(dataplaneUrl, authConfig, payload, systemKey, options) {
30
+ for (let attempt = 0; attempt < 2; attempt += 1) {
31
+ try {
32
+ const res = await uploadApplicationViaPipelineWithAuthRetry(
33
+ dataplaneUrl, authConfig, payload, systemKey, options
34
+ );
35
+ if (res?.success !== false || !isTransientQualificationPollError(res.status) || attempt === 1) {
36
+ return res;
37
+ }
38
+ } catch (error) {
39
+ if (!isAmbiguousAcceptance(error) || attempt === 1) throw error;
40
+ }
41
+ }
42
+ }
43
+
18
44
  /**
19
- * Ctrl-C / disconnect during polling must detach without corrupting truth (plan 191.0 task 4):
20
- * the qualification job keeps running on Dataplane regardless of whether this CLI process exits.
21
- * This only makes that safe fact visible, printing the resume command before exiting 130.
45
+ * Ctrl-C detaches from status following without asserting an unobserved job outcome.
46
+ * Prints the resume command before exiting 130.
22
47
  * @param {string} jobId
23
48
  * @param {string} systemKey
24
49
  * @returns {() => void} Call to remove the listeners once polling finishes normally.
@@ -27,7 +52,7 @@ function registerUploadInterruptHint(jobId, systemKey) {
27
52
  const onSignal = () => {
28
53
  logger.log(
29
54
  formatWarningLine(
30
- `Interrupted — upload job ${jobId} is still running, unaffected. Resume with: aifabrix upload ${systemKey} --resume ${jobId}`
55
+ `Stopped following upload job ${jobId}; its current outcome is unknown. Resume with: aifabrix upload ${systemKey} --resume ${jobId}`
31
56
  )
32
57
  );
33
58
  process.exit(130);
@@ -52,12 +77,24 @@ function registerUploadInterruptHint(jobId, systemKey) {
52
77
  * @returns {Promise<{jobId: string, state: string, resumed: boolean, candidateFingerprint: string}>}
53
78
  */
54
79
  async function acceptQualificationUpload(dataplaneUrl, authConfig, payload, systemKey, options = {}) {
55
- const res = await uploadApplicationViaPipelineWithAuthRetry(dataplaneUrl, authConfig, payload, systemKey, {
56
- ...options,
57
- async: true
58
- });
80
+ let res;
81
+ try {
82
+ res = await submitQualificationUpload(dataplaneUrl, authConfig, payload, systemKey, {
83
+ ...options,
84
+ async: true
85
+ });
86
+ } catch (error) {
87
+ if (!isAmbiguousAcceptance(error)) throw error;
88
+ const unknown = new Error('Upload acceptance outcome is unknown. Rerun the same upload command to recover the job.');
89
+ unknown.cause = error;
90
+ unknown.statusCode = error?.response?.status || error?.statusCode || error?.status;
91
+ throw unknown;
92
+ }
59
93
  if (res?.success === false) {
60
- const err = new Error(formatApiError(res, dataplaneUrl));
94
+ const ambiguous = isTransientQualificationPollError(res.status);
95
+ const err = new Error(ambiguous
96
+ ? 'Upload acceptance outcome is unknown. Rerun the same upload command to recover the job.'
97
+ : formatApiError(res, dataplaneUrl));
61
98
  const status = Number(res.status || res.statusCode);
62
99
  err.statusCode = status >= 400 && status < 600 ? status : 400;
63
100
  throw err;
@@ -107,6 +144,14 @@ async function resumeQualificationUpload(dataplaneUrl, authConfig, jobId, system
107
144
  */
108
145
  async function runQualificationUpload(dataplaneUrl, authConfig, payload, systemKey, options = {}) {
109
146
  const accepted = await acceptQualificationUpload(dataplaneUrl, authConfig, payload, systemKey, options);
147
+ if (accepted.state === 'completed' || accepted.state === 'failed') {
148
+ requireQualificationSuccess(accepted);
149
+ return {
150
+ ...accepted,
151
+ candidateFingerprint: accepted.result?.candidateFingerprint,
152
+ terminal: accepted
153
+ };
154
+ }
110
155
  const wait = options.wait !== false;
111
156
  if (!wait) {
112
157
  if (options.json) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @fileoverview Poll a Dataplane qualification (publish) job until terminal (plan 191.0 task 1).
2
+ * @fileoverview Poll a Dataplane qualification job while retaining resumable identity.
3
3
  * Never invents success and never marks the candidate failed just because the CLI stopped polling —
4
4
  * timing out returns a resumable jobId instead.
5
5
  * @author AI Fabrix Team
@@ -13,7 +13,7 @@ const { formatApiError } = require('../utils/api-error-handler');
13
13
 
14
14
  const POLL_INTERVAL_MS = 3000;
15
15
  const POLL_TIMEOUT_MS = 30 * 60 * 1000;
16
- const TRANSIENT_HTTP_STATUSES = new Set([502, 503, 504]);
16
+ const TRANSIENT_HTTP_STATUSES = new Set([429, 502, 503, 504]);
17
17
  const MAX_TRANSIENT_POLL_ERRORS = 20;
18
18
 
19
19
  const GOVERNANCE_SCENARIOS_MISSING = 'GOVERNANCE_SCENARIOS_MISSING';
@@ -46,6 +46,17 @@ function formatQualificationJobFailure(job) {
46
46
  };
47
47
  }
48
48
 
49
+ /** Throw only for an authoritative stored failure, retaining the original job. */
50
+ function requireQualificationSuccess(job) {
51
+ if (job.state !== 'failed') return;
52
+ const failure = formatQualificationJobFailure(job);
53
+ const err = new Error(failure.message);
54
+ err.jobId = job.jobId;
55
+ err.job = job;
56
+ err.skipDoctor = failure.userFacing;
57
+ throw err;
58
+ }
59
+
49
60
  /**
50
61
  * @param {number|string} status
51
62
  * @returns {boolean}
@@ -54,6 +65,35 @@ function isTransientQualificationPollError(status) {
54
65
  return TRANSIENT_HTTP_STATUSES.has(Number(status));
55
66
  }
56
67
 
68
+ /** Preserve the accepted identity without asserting a business outcome. */
69
+ function unavailableJob(jobId, message) {
70
+ const error = new Error(
71
+ `${message} Job ${jobId}: status unavailable. Resume with: aifabrix upload <systemKey> --resume ${jobId}`
72
+ );
73
+ error.jobId = jobId;
74
+ error.resumable = true;
75
+ return error;
76
+ }
77
+
78
+ /** Normalize transport exceptions so returned HTTP errors and throws share retries. */
79
+ async function readQualificationJob(dataplaneUrl, authConfig, jobId) {
80
+ try {
81
+ return await getPublishJobStatus(dataplaneUrl, authConfig, jobId);
82
+ } catch (error) {
83
+ const status = error?.response?.status || error?.statusCode || error?.status;
84
+ const code = error?.cause?.code || error?.code;
85
+ const network = ['ECONNRESET', 'ECONNREFUSED', 'ETIMEDOUT', 'EAI_AGAIN',
86
+ 'ENOTFOUND', 'ECONNABORTED', 'UND_ERR_CONNECT_TIMEOUT'].includes(code) ||
87
+ error instanceof TypeError || ['AbortError', 'TimeoutError'].includes(error?.name);
88
+ if (isTransientQualificationPollError(status) || (!status && network)) {
89
+ return { success: false, status: status || 503 };
90
+ }
91
+ const failure = unavailableJob(jobId, 'Unable to check upload progress.');
92
+ failure.statusCode = status;
93
+ throw failure;
94
+ }
95
+ }
96
+
57
97
  /**
58
98
  * @param {string} dataplaneUrl
59
99
  * @param {Object} authConfig
@@ -64,19 +104,19 @@ function isTransientQualificationPollError(status) {
64
104
  async function fetchQualificationJobWithRetry(dataplaneUrl, authConfig, jobId, pollUi = {}) {
65
105
  const started = Date.now();
66
106
  for (let attempt = 0; attempt <= MAX_TRANSIENT_POLL_ERRORS; attempt += 1) {
67
- const res = await getPublishJobStatus(dataplaneUrl, authConfig, jobId);
107
+ const res = await readQualificationJob(dataplaneUrl, authConfig, jobId);
68
108
  if (res?.success !== false) {
69
109
  return res.data;
70
110
  }
71
111
  if (!isTransientQualificationPollError(res.status)) {
72
- const err = new Error(formatApiError(res, dataplaneUrl));
112
+ const err = unavailableJob(jobId, formatApiError(res, dataplaneUrl));
73
113
  const status = Number(res.status);
74
114
  err.statusCode = status >= 400 && status < 600 ? status : 400;
75
115
  throw err;
76
116
  }
77
117
  if (attempt >= MAX_TRANSIENT_POLL_ERRORS) {
78
- throw new Error(
79
- `The upload service returned HTTP ${res.status} repeatedly while waiting for job ${jobId}.`
118
+ throw unavailableJob(
119
+ jobId, `The upload service returned HTTP ${res.status} repeatedly.`
80
120
  );
81
121
  }
82
122
  if (typeof pollUi.onTransientError === 'function') {
@@ -84,13 +124,13 @@ async function fetchQualificationJobWithRetry(dataplaneUrl, authConfig, jobId, p
84
124
  }
85
125
  await sleep(POLL_INTERVAL_MS);
86
126
  }
87
- throw new Error(`Failed to check upload job ${jobId} after transient retries`);
127
+ throw unavailableJob(jobId, 'Status retries exhausted.');
88
128
  }
89
129
 
90
130
  /**
91
131
  * Poll a Dataplane qualification job to terminal state (completed|failed). The timeout only
92
132
  * bounds how long *this CLI process* waits — Dataplane keeps running the job regardless; timing
93
- * out returns a resumable jobId, never a fabricated failure (plan 191.0 task 4).
133
+ * out returns a resumable jobId, never a fabricated failure.
94
134
  * @param {string} dataplaneUrl
95
135
  * @param {Object} authConfig
96
136
  * @param {string} jobId
@@ -112,25 +152,13 @@ async function pollQualificationJobUntilTerminal(
112
152
  if (typeof pollUi.onPollProgress === 'function') {
113
153
  pollUi.onPollProgress(job);
114
154
  }
115
- if (job.state === 'failed') {
116
- const failure = formatQualificationJobFailure(job);
117
- const err = new Error(failure.message);
118
- err.jobId = jobId;
119
- err.job = job;
120
- err.skipDoctor = failure.userFacing;
121
- throw err;
122
- }
155
+ requireQualificationSuccess(job);
123
156
  if (job.state === 'completed') {
124
157
  return job;
125
158
  }
126
159
  await sleep(POLL_INTERVAL_MS);
127
160
  }
128
- const timeoutErr = new Error(
129
- `Timed out waiting for upload job ${jobId}. It is still running — resume with: aifabrix upload <systemKey> --resume ${jobId}`
130
- );
131
- timeoutErr.jobId = jobId;
132
- timeoutErr.resumable = true;
133
- throw timeoutErr;
161
+ throw unavailableJob(jobId, 'Timed out waiting for upload progress.');
134
162
  }
135
163
 
136
164
  module.exports = {
@@ -139,5 +167,6 @@ module.exports = {
139
167
  isTransientQualificationPollError,
140
168
  fetchQualificationJobWithRetry,
141
169
  formatQualificationJobFailure,
170
+ requireQualificationSuccess,
142
171
  pollQualificationJobUntilTerminal
143
172
  };
@@ -4,43 +4,11 @@
4
4
  * @version 2.0.0
5
5
  */
6
6
 
7
- const chalk = require('chalk');
8
7
  const logger = require('../utils/logger');
9
8
  const { formatProgress, formatSuccessLine } = require('../utils/cli-test-layout-chalk');
10
9
  const { getDataplaneUrl } = require('../datasource/deploy');
11
- const { listEnvironmentApplications } = require('../api/environments.api');
12
10
 
13
- /**
14
- * Find dataplane service application key from environment applications list
15
- * @async
16
- * @function findDataplaneServiceAppKey
17
- * @param {string} controllerUrl - Controller URL
18
- * @param {string} environment - Environment key
19
- * @param {Object} authConfig - Authentication configuration
20
- * @returns {Promise<string|null>} Dataplane service appKey or null if not found
21
- */
22
- // eslint-disable-next-line complexity
23
- async function findDataplaneServiceAppKey(controllerUrl, environment, authConfig) {
24
- try {
25
- const response = await listEnvironmentApplications(controllerUrl, environment, authConfig, { pageSize: 100 });
26
- if (!response.success || !response.data) return null;
27
- const applications = response.data.data || response.data || [];
28
- for (const app of applications) {
29
- const appKey = app.key || app.id;
30
- if (!appKey) continue;
31
- const keyLower = appKey.toLowerCase();
32
- const appType = app.configuration?.type || app.type;
33
- const nameLower = (app.displayName || app.name || '').toLowerCase();
34
- if (keyLower === 'dataplane' || keyLower.includes('dataplane') || (appType === 'service' && nameLower.includes('dataplane'))) {
35
- return appKey;
36
- }
37
- }
38
- return null;
39
- } catch (error) {
40
- logger.log(chalk.gray(` Could not list applications: ${error.message}`));
41
- return null;
42
- }
43
- }
11
+ const DATAPLANE_APPLICATION_KEY = 'dataplane';
44
12
 
45
13
  /**
46
14
  * Check if error is a "Not Found" error
@@ -65,7 +33,7 @@ function createDataplaneNotFoundError() {
65
33
  }
66
34
 
67
35
  /**
68
- * Try to get dataplane URL using fallback app key
36
+ * Get dataplane URL from the canonical controller application key.
69
37
  * @async
70
38
  * @param {string} controllerUrl - Controller URL
71
39
  * @param {string} environment - Environment key
@@ -73,18 +41,23 @@ function createDataplaneNotFoundError() {
73
41
  * @returns {Promise<string>} Dataplane URL
74
42
  * @throws {Error} If dataplane URL cannot be retrieved
75
43
  */
76
- async function tryFallbackDataplaneUrl(controllerUrl, environment, authConfig, silent) {
44
+ async function getExactDataplaneUrl(controllerUrl, environment, authConfig, silent) {
77
45
  try {
78
- const fallbackUrl = await getDataplaneUrl(controllerUrl, 'dataplane', environment, authConfig);
46
+ const dataplaneUrl = await getDataplaneUrl(
47
+ controllerUrl,
48
+ DATAPLANE_APPLICATION_KEY,
49
+ environment,
50
+ authConfig
51
+ );
79
52
  if (!silent) {
80
- logger.log(formatSuccessLine(`Dataplane URL: ${fallbackUrl}`));
53
+ logger.log(formatSuccessLine(`Dataplane URL: ${dataplaneUrl}`));
81
54
  }
82
- return fallbackUrl;
83
- } catch (fallbackError) {
84
- if (isNotFoundError(fallbackError)) {
55
+ return dataplaneUrl;
56
+ } catch (error) {
57
+ if (isNotFoundError(error)) {
85
58
  throw createDataplaneNotFoundError();
86
59
  }
87
- throw fallbackError;
60
+ throw error;
88
61
  }
89
62
  }
90
63
 
@@ -105,15 +78,7 @@ async function discoverDataplaneUrl(controllerUrl, environment, authConfig, opts
105
78
  logger.log(formatProgress('Getting dataplane URL from controller...'));
106
79
  }
107
80
  try {
108
- const dataplaneAppKey = await findDataplaneServiceAppKey(controllerUrl, environment, authConfig);
109
- if (dataplaneAppKey) {
110
- const dataplaneUrl = await getDataplaneUrl(controllerUrl, dataplaneAppKey, environment, authConfig);
111
- if (!silent) {
112
- logger.log(formatSuccessLine(`Dataplane URL: ${dataplaneUrl}`));
113
- }
114
- return dataplaneUrl;
115
- }
116
- return await tryFallbackDataplaneUrl(controllerUrl, environment, authConfig, silent);
81
+ return await getExactDataplaneUrl(controllerUrl, environment, authConfig, silent);
117
82
  } catch (error) {
118
83
  if (error.message.includes('Could not discover dataplane URL')) {
119
84
  throw error;
@@ -126,6 +91,5 @@ async function discoverDataplaneUrl(controllerUrl, environment, authConfig, opts
126
91
  }
127
92
 
128
93
  module.exports = {
129
- discoverDataplaneUrl,
130
- findDataplaneServiceAppKey
94
+ discoverDataplaneUrl
131
95
  };
@@ -74,17 +74,20 @@ function summarizeSyncLine(sync) {
74
74
  if (!sync || typeof sync !== 'object') {
75
75
  return 'Not configured';
76
76
  }
77
- const parts = [];
77
+ const disabled = sync.enabled === false;
78
+ const parts = [disabled ? 'disabled' : sync.enabled === true ? 'enabled' : 'enabled (legacy default)'];
79
+ if (sync.schedule) {
80
+ parts.push(`${disabled ? 'retained schedule' : 'scheduled'} ${JSON.stringify(sync.schedule)}`);
81
+ } else {
82
+ parts.push('manual-only');
83
+ }
78
84
  if (sync.mode) {
79
85
  parts.push(String(sync.mode));
80
86
  }
81
87
  if (sync.batchSize !== undefined && sync.batchSize !== null) {
82
88
  parts.push(`batch size ${sync.batchSize}`);
83
89
  }
84
- if (sync.schedule) {
85
- parts.push(`schedule ${JSON.stringify(sync.schedule)}`);
86
- }
87
- return parts.length ? parts.join(', ') : 'Present';
90
+ return parts.join(', ');
88
91
  }
89
92
 
90
93
  /**
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Datasource synchronization defaults for newly authored sync blocks.
3
+ * @fileoverview Keeps default creation separate from preservation decisions.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ const DEFAULT_DATASOURCE_SYNC = Object.freeze({
9
+ enabled: true,
10
+ mode: 'pull',
11
+ schedule: '@monthly',
12
+ batchSize: 500
13
+ });
14
+
15
+ const DATASOURCE_SYNC_MODES = new Set(['pull', 'push', 'bidirectional']);
16
+
17
+ /**
18
+ * @param {Record<string, unknown>} [overrides]
19
+ * @returns {Record<string, unknown>}
20
+ */
21
+ function createDefaultDatasourceSync(overrides = {}) {
22
+ return { ...DEFAULT_DATASOURCE_SYNC, ...overrides };
23
+ }
24
+
25
+ /**
26
+ * Resolve sync for a newly materialized BID datasource.
27
+ * An explicit datasource block is preserved exactly, including no schedule.
28
+ * @param {Record<string, unknown>} datasource
29
+ * @param {Record<string, unknown>} bidSync
30
+ * @returns {unknown}
31
+ */
32
+ function resolveAuthoredDatasourceSync(datasource, bidSync) {
33
+ if (Object.prototype.hasOwnProperty.call(datasource, 'sync')) {
34
+ const explicit = datasource.sync;
35
+ return explicit && typeof explicit === 'object' ? { ...explicit } : explicit;
36
+ }
37
+ const overrides = {};
38
+ for (const key of ['enabled', 'schedule', 'batchSize']) {
39
+ if (Object.prototype.hasOwnProperty.call(bidSync, key)) {
40
+ overrides[key] = bidSync[key];
41
+ }
42
+ }
43
+ if (DATASOURCE_SYNC_MODES.has(String(bidSync.mode))) {
44
+ overrides.mode = bidSync.mode;
45
+ }
46
+ return createDefaultDatasourceSync(overrides);
47
+ }
48
+
49
+ module.exports = {
50
+ DEFAULT_DATASOURCE_SYNC,
51
+ createDefaultDatasourceSync,
52
+ resolveAuthoredDatasourceSync
53
+ };
@@ -50,6 +50,16 @@ async function applyAccessOptions(doc, input, deps) {
50
50
  if (input.preset !== undefined) {
51
51
  doc.preset = { ...doc.preset, value: normalizePreset(input.preset), source: 'cli' };
52
52
  }
53
+ // The template sizes compute and PostgreSQL from capacityProfile, and the workspace already
54
+ // records a preset with the same values. Deriving one from the other keeps a single source:
55
+ // an installation cannot end up recording preset 'm' while deploying 's'.
56
+ if (doc.parameters.capacityProfile) {
57
+ doc.parameters.capacityProfile = {
58
+ ...doc.parameters.capacityProfile,
59
+ value: normalizePreset(doc.preset.value),
60
+ source: 'workspacePreset'
61
+ };
62
+ }
53
63
  applyLicenseOptions(doc, input);
54
64
  const enabled = input.allowMyIp || doc.allowMyIp.value === true;
55
65
  if (!enabled) {
@@ -127,10 +127,21 @@ function assertDeploymentAuthority(doc, acr, az) {
127
127
  if (!hasPermission(az, subscriptionScope, DEPLOYMENT_WRITE)) {
128
128
  throw new Error(`The signed-in Azure account cannot create deployments in subscription ${doc.subscriptionId.value}`);
129
129
  }
130
- if (isAdminAcrAuth(doc)) return;
130
+ // Checked separately, because they are different permissions on different resources.
131
+ //
132
+ // Credential mode used to return here and skip both. That was wrong for the first one: the
133
+ // installation still needs Contributor granted in the resource group it is creating, and
134
+ // skipping the check hid the fact that the grant was being skipped too. The controller then
135
+ // could not create anything, and the failure surfaced three layers away as "Environment 'dev'
136
+ // has no recorded placement".
131
137
  if (doc.parameters.deployRoleAssignments.value !== false && !hasPermission(az, subscriptionScope, ROLE_ASSIGNMENT_WRITE)) {
132
- throw new Error(`The signed-in Azure account cannot create role assignments in subscription ${doc.subscriptionId.value}; ask for Owner or User Access Administrator, or set parameters.deployRoleAssignments.value to false when roles already exist, or use --acr-auth credentials with a pair saved by "aifabrix dev set-registry"`);
138
+ throw new Error(`The signed-in Azure account cannot create role assignments in subscription ${doc.subscriptionId.value}; ask for Owner or User Access Administrator, or set parameters.deployRoleAssignments.value to false when roles already exist`);
133
139
  }
140
+ // The AcrPull grant reaches into the registry's own resource group, which a customer
141
+ // installation cannot touch at all. Credential mode does not request it, so do not require
142
+ // permission for it.
143
+ if (isAdminAcrAuth(doc)) return;
144
+ if (doc.parameters.deployRegistryRoleAssignment?.value === false) return;
134
145
  if (!hasPermission(az, acr.id, ROLE_ASSIGNMENT_WRITE)) {
135
146
  throw new Error(`The signed-in Azure account cannot assign AcrPull on registry ${doc.acrName.value}; ask for Owner or User Access Administrator on that registry, or use --acr-auth credentials with a pair saved by "aifabrix dev set-registry"`);
136
147
  }
@@ -82,14 +82,36 @@ function verifyRuntimeImagePull(doc, az) {
82
82
  }
83
83
  }
84
84
 
85
+ /**
86
+ * Attempts allowed for Miso readiness, at 10-second intervals.
87
+ *
88
+ * Miso runs first-time onboarding inside startup, and on Azure that onboarding is normally
89
+ * interrupted once — the template applies post-Key-Vault app settings and restarts the site — so
90
+ * the retry runs too. A clean installation was measured taking 720 seconds to pass its warm-up
91
+ * probe, and ce-10 was failed at 300 by the old default of 30 attempts.
92
+ *
93
+ * Reporting `readiness did not pass` for a healthy installation is worse than waiting: it leaves
94
+ * `controllerUrl` unrecorded, and `--stage dev` then refuses with "Shared infrastructure is not
95
+ * deployed for this workspace" on infrastructure that is deployed and serving.
96
+ *
97
+ * 180 attempts is 30 minutes, matching WEBSITES_CONTAINER_START_TIME_LIMIT. Keycloak keeps the
98
+ * shorter default: it does not run onboarding, and it is already up by the time Miso answers.
99
+ */
100
+ const MISO_READINESS_ATTEMPTS = 180;
101
+
85
102
  /**
86
103
  * Waits for Miso and Keycloak to start after pulling their images.
87
104
  * @param {Object} doc - Infra manifest with outputs
88
- * @param {Function} probe - probeHttps(baseUrl, path, label)
105
+ * @param {Function} probe - probeHttps(baseUrl, path, label, attempts)
89
106
  * @returns {Promise<void>}
90
107
  */
91
108
  async function waitForApplications(doc, probe) {
92
- await probe(doc.outputs.webAppUrl.value, '/api/v1/health/readiness', 'Miso');
109
+ await probe(
110
+ doc.outputs.webAppUrl.value,
111
+ '/api/v1/health/readiness',
112
+ 'Miso',
113
+ MISO_READINESS_ATTEMPTS
114
+ );
93
115
  const realmUrl = doc.outputs.keycloakRealmUrl.value;
94
116
  if (typeof realmUrl !== 'string' || !realmUrl.startsWith('https://')) {
95
117
  throw new Error('ARM output keycloakRealmUrl is not a valid HTTPS URL');