Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/constants/UserMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,6 @@ export class UserPrompts {
return format('Failed to open conversion: {0}', errorMsg);
}

static failedToExecute(errorMsg: string): string {
return format('Failed to execute: {0}', errorMsg);
}

static readonly NO_PROJECT_FOLDER = 'No project folder found.';
static readonly NO_CODE_WORKSPACE_FILE =
'No .code-workspace file found. Run Execute first to generate the project.';
Expand Down
96 changes: 62 additions & 34 deletions src/copilot/MigrationLMTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4897,8 +4897,17 @@ class ConversionStoreTaskOutputTool implements vscode.LanguageModelTool<Conversi
const updatedTask = taskPlan2?.tasks.find((t) => t.id === taskId);
const actualStatus = updatedTask?.status || 'completed';

// Finalize once the last required task is stored, so the flow shows as converted
// ("Open in VS Code" enables) even when tasks are executed one at a time and the
// agent never calls migration_conversion_finalize.
let flowFinalized = false;
if (taskPlan2 && conversionService.areRequiredTasksComplete(flowId)) {
await completeFlowConversion(flowId, taskPlan2, logger);
flowFinalized = true;
}

logger.debug(
`[LMTool] migration_conversion_storeTaskOutput: stored output for task "${taskId}" in flow "${flowId}" (status: ${actualStatus})`
`[LMTool] migration_conversion_storeTaskOutput: stored output for task "${taskId}" in flow "${flowId}" (status: ${actualStatus}${flowFinalized ? ', flow finalized' : ''})`
);
TelemetryService.getInstance().logStep('conversion.task.completed', {
flowId,
Expand All @@ -4915,7 +4924,11 @@ class ConversionStoreTaskOutputTool implements vscode.LanguageModelTool<Conversi
success: true,
flowId,
taskId,
message: `Task "${taskId}" marked as ${actualStatus}. ${generatedFiles?.length || 0} files generated.`,
message:
`Task "${taskId}" marked as ${actualStatus}. ${generatedFiles?.length || 0} files generated.` +
(flowFinalized
? ' All required tasks are complete, so the flow conversion has been finalized.'
: ''),
})
),
]);
Expand Down Expand Up @@ -5063,6 +5076,52 @@ async function applyWorkflowMigrationMetadata(
return stamped;
}

/**
* Finalize a flow whose required tasks are complete: stamp workflow metadata,
* mark the flow converted (enables "Open in VS Code" on Home) and refresh Home.
* Safe to run more than once.
*/
async function completeFlowConversion(
flowId: string,
plan: ConversionTaskPlan,
logger: LoggingService
): Promise<number> {
// Deterministically stamp MigrationMetadata into every generated workflow.json.
// Machine-generated data — no agent involvement, no rejection/retry loop.
const stampedCount = await applyWorkflowMigrationMetadata(plan, logger);

// Mark the flow as completed
const flow = ConversionService.getInstance()
.getFlows()
.find((f) => f.id === flowId);
if (flow) {
flow.status = 'completed';
Comment thread
code-scannner marked this conversation as resolved.
Resolved
}

// Mark flow as fully converted in DiscoveryCacheService
try {
const { DiscoveryCacheService } = await import('../stages/discovery/DiscoveryCacheService');
await DiscoveryCacheService.getInstance().markFlowConverted(flowId);
} catch {
// Non-critical
}

// Clear executing flag and refresh flow group selector
try {
const { SourceFlowVisualizer } = await import('../views/discovery/SourceFlowVisualizer');
SourceFlowVisualizer.executingGroupIds.delete(flowId);
if (SourceFlowVisualizer.currentPanel) {
SourceFlowVisualizer.showFlowGroupSelector(
SourceFlowVisualizer.currentPanel.extensionUri
);
}
Comment thread
code-scannner marked this conversation as resolved.
Resolved
} catch {
// Non-critical
}

return stampedCount;
}

class ConversionFinalizeTool implements vscode.LanguageModelTool<ConversionFinalizeInput> {
async invoke(
options: vscode.LanguageModelToolInvocationOptions<ConversionFinalizeInput>,
Expand Down Expand Up @@ -5110,38 +5169,7 @@ class ConversionFinalizeTool implements vscode.LanguageModelTool<ConversionFinal
]);
}

// Deterministically stamp MigrationMetadata into every generated workflow.json.
// Machine-generated data — no agent involvement, no rejection/retry loop.
const stampedCount = await applyWorkflowMigrationMetadata(plan, logger);

// Mark the flow as completed
const flow = conversionService.getFlows().find((f) => f.id === flowId);
if (flow) {
flow.status = 'completed';
}

// Mark flow as fully converted in DiscoveryCacheService
try {
const { DiscoveryCacheService } =
await import('../stages/discovery/DiscoveryCacheService');
await DiscoveryCacheService.getInstance().markFlowConverted(flowId);
} catch {
// Non-critical
}

// Clear executing flag and refresh flow group selector
try {
const { SourceFlowVisualizer } =
await import('../views/discovery/SourceFlowVisualizer');
SourceFlowVisualizer.executingGroupIds.delete(flowId);
if (SourceFlowVisualizer.currentPanel) {
SourceFlowVisualizer.showFlowGroupSelector(
SourceFlowVisualizer.currentPanel.extensionUri
);
}
} catch {
// Non-critical
}
const stampedCount = await completeFlowConversion(flowId, plan, logger);

// Open conversion webview
void vscode.commands.executeCommand('logicAppsMigrationAgent.openConversionView');
Expand Down
14 changes: 14 additions & 0 deletions src/stages/conversion/ConversionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ export class ConversionService implements vscode.Disposable {
return this.state?.taskPlans[flowId];
}

/**
* Whether every required (non-optional) task in the flow's plan is completed
* or skipped, so the flow's conversion can be finalized.
*/
public areRequiredTasksComplete(flowId: string): boolean {
const tasks = this.getTaskPlan(flowId)?.tasks ?? [];
return (
tasks.length > 0 &&
tasks.every(
(task) => task.optional || task.status === 'completed' || task.status === 'skipped'
)
);
}

/**
* Set Execute All orchestration mode for a flow.
*/
Expand Down
98 changes: 98 additions & 0 deletions src/test/unit/conversion-step-button.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import * as assert from 'assert/strict';
import {
ConversionStepState,
renderConversionStepButton,
} from '../../views/discovery/ConversionStepButton';

const planned: ConversionStepState = {
flowId: 'order-flow',
isPlanned: true,
isTasksCreated: false,
isConverted: false,
isCreatingTasks: false,
isExecuting: false,
isBlockedByOtherFlow: false,
};

function step(overrides: Partial<ConversionStepState>): {
label: string;
action?: string;
disabled: boolean;
} {
const html = renderConversionStepButton({ ...planned, ...overrides });
return {
label: /<strong>([^<]*)<\/strong>/.exec(html)?.[1] ?? '',
action: /onclick="event\.stopPropagation\(\); (\w+)\('order-flow'\)"/.exec(html)?.[1],
disabled: /\sdisabled[\s>]/.test(html),
};
}

describe('Home Execute step', () => {
it('is named Execute and generates the conversion tasks once the flow is planned', () => {
assert.deepEqual(step({ isPlanned: false }), {
label: 'Execute',
action: undefined,
disabled: true,
});
assert.deepEqual(step({}), { label: 'Execute', action: 'convertFlow', disabled: false });
assert.deepEqual(step({ isCreatingTasks: true }), {
label: 'Executing...',
action: undefined,
disabled: true,
});
});

it('opens the generated tasks so they are executed from the task list', () => {
assert.deepEqual(step({ isTasksCreated: true }), {
label: 'Execute',
action: 'viewConversion',
disabled: false,
});
assert.deepEqual(step({ isTasksCreated: true, isExecuting: true }), {
label: 'Executing...',
action: undefined,
disabled: true,
});
assert.deepEqual(step({ isTasksCreated: true, isConverted: true }), {
label: '✓ Executed',
action: 'viewConversion',
disabled: false,
});
});

it('only blocks starting a flow while another flow is busy', () => {
assert.deepEqual(step({ isBlockedByOtherFlow: true }), {
label: 'Execute',
action: undefined,
disabled: true,
});
assert.deepEqual(step({ isBlockedByOtherFlow: true, isTasksCreated: true }), {
label: 'Execute',
action: 'viewConversion',
disabled: false,
});
});

it('never shows Create in any state', () => {
const flags = [
'isPlanned',
'isTasksCreated',
'isConverted',
'isCreatingTasks',
'isExecuting',
'isBlockedByOtherFlow',
] as const;
for (let mask = 0; mask < 2 ** flags.length; mask++) {
const overrides: Partial<Record<(typeof flags)[number], boolean>> = {};
flags.forEach((flag, i) => {
overrides[flag] = Math.floor(mask / 2 ** i) % 2 === 1;
});
const html = renderConversionStepButton({ ...planned, ...overrides });
assert.doesNotMatch(html, /creat/i, JSON.stringify(overrides));
assert.ok(
['Execute', 'Executing...', '✓ Executed'].includes(step(overrides).label),
JSON.stringify(overrides)
);
}
});
});
21 changes: 21 additions & 0 deletions src/test/unit/conversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,27 @@ describe('BizTalk Conversion stage', () => {
assert.deepEqual(completedFlows, [flow.id]);
});

it('is ready to finalize once every required task is done, even with optional tasks pending', async () => {
const flow = await prepareConversion();
const conversion = ConversionService.getInstance();
assert.equal(conversion.areRequiredTasksComplete(flow.id), false);
await conversion.storeTaskOutput(flow.id, 'convert-schemas-and-map', {
completedAt: generatedAt,
summary: 'convert-schemas-and-map completed.',
});
await conversion.updateTask(flow.id, 'generate-workflow', { status: 'failed' });
assert.equal(conversion.areRequiredTasksComplete(flow.id), false);
for (const taskId of ['generate-workflow', 'test-workflows']) {
await conversion.storeTaskOutput(flow.id, taskId, {
completedAt: generatedAt,
summary: `${taskId} completed.`,
});
}
assert.equal(conversion.getTaskPlan(flow.id)?.tasks[3].status, 'pending');
assert.equal(conversion.areRequiredTasksComplete(flow.id), true);
assert.equal(conversion.areRequiredTasksComplete('flow-without-tasks'), false);
});

it('stops interrupted execution without losing previously completed tasks', async () => {
const flow = await prepareConversion();
const conversion = ConversionService.getInstance();
Expand Down
79 changes: 79 additions & 0 deletions src/views/discovery/ConversionStepButton.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Execute step on the Home flow cards.
*
* A single Execute step covers conversion: on a planned flow it generates the
* conversion tasks and opens the task list, where each task (or Execute All)
* is executed.
*
* @module views/discovery/ConversionStepButton
*/

export interface ConversionStepState {
readonly flowId: string;
readonly isPlanned: boolean;
readonly isTasksCreated: boolean;
readonly isConverted: boolean;
readonly isCreatingTasks: boolean;
readonly isExecuting: boolean;
readonly isBlockedByOtherFlow: boolean;
}

function stepLabel(text: string): string {
return `<span class="step-label"><strong>${text}</strong><small>Conversion Tasks</small></span>`;
}

function disabledStep(text: string, title?: string): string {
const titleAttr = title ? ` title="${title}"` : '';
return `<button class="btn btn-step btn-disabled" disabled${titleAttr}>${stepLabel(text)}</button>`;
}

function actionStep(
text: string,
style: 'btn-primary' | 'btn-done',
action: 'convertFlow' | 'viewConversion',
flowId: string,
title: string
): string {
return `<button class="btn btn-step ${style}" onclick="event.stopPropagation(); ${action}('${flowId}')" title="${title}">${stepLabel(text)}</button>`;
}

/**
* Render the Execute step. It keeps the Execute name in every state, like
* Analyse → ✓ Analysed and Plan → ✓ Planned.
*/
export function renderConversionStepButton(state: ConversionStepState): string {
if (!state.isPlanned) {
return disabledStep('Execute', 'Plan first');
}
if (state.isCreatingTasks || state.isExecuting) {
return disabledStep('Executing...');
}
Comment thread
code-scannner marked this conversation as resolved.
Resolved
if (state.isConverted) {
return actionStep(
'✓ Executed',
'btn-done',
'viewConversion',
state.flowId,
'View conversion tasks'
);
}
if (state.isTasksCreated) {
return actionStep(
'Execute',
'btn-primary',
'viewConversion',
state.flowId,
'Open the conversion tasks to execute them'
);
}
if (state.isBlockedByOtherFlow) {
return disabledStep('Execute', 'Another flow is in progress');
}
return actionStep(
'Execute',
'btn-primary',
'convertFlow',
Comment thread
code-scannner marked this conversation as resolved.
Resolved
state.flowId,
'Generate the conversion tasks, then execute them from the task list'
);
}
Loading
Loading