Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2704831
Implement public API for Aspire extension and add fetchAppHostsOnce m…
LittleLittleCloud May 29, 2026
91dc92d
Merge remote-tracking branch 'upstream/main' into pr-17705-csdk
adamint Jun 1, 2026
a030a21
Add Aspire test run DCP leases
adamint Jun 1, 2026
33dcde3
Clean lease notifications after release
adamint Jun 1, 2026
0e68f5b
Address Aspire extension API review feedback
adamint Jun 1, 2026
8d8861b
Harden Aspire test run lease integration
adamint Jun 1, 2026
12f2768
Refactor Aspire API to use DCP server for test run session management
LittleLittleCloud Jun 1, 2026
45487b5
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud Jun 2, 2026
2129f65
Refactor AspireDcpServer constructor to remove unused app parameter a…
LittleLittleCloud Jun 2, 2026
fdbba30
Update API function signatures to use inline arrow functions for DCP …
LittleLittleCloud Jun 2, 2026
c8739a3
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud Jun 3, 2026
b918206
Fix extension test failures by returning full E2E API from activate
LittleLittleCloud Jun 3, 2026
5ca3d02
Refactor Aspire extension API: consolidate resource command functions…
LittleLittleCloud Jun 3, 2026
b9a3118
Fix stopRunSession cleanup and remove redundant closeLeaseNotificatio…
LittleLittleCloud Jun 3, 2026
d6666bc
Merge branch 'main' into u/xiaoyun/aspireC#DK
LittleLittleCloud Jun 10, 2026
1321ec5
Enhance resource command handling and error logging in DCP server and…
LittleLittleCloud Jun 10, 2026
9939510
Remove terminalProvider parameter from createExtensionApi function ca…
LittleLittleCloud Jun 10, 2026
9fb1d95
Refactor process termination logic in AppHostDataRepository for clarity
LittleLittleCloud Jun 10, 2026
79b9dbe
Refactor DCP server and test run session manager for improved session…
LittleLittleCloud Jun 15, 2026
bbdefca
Refactor AspireDcpServer and TestRunSessionManager for improved clari…
LittleLittleCloud Jun 15, 2026
4d1ce6e
Fix test run session DCP credentials
adamint Jun 17, 2026
03f2ff5
Merge remote-tracking branch 'upstream/main' into copilot/pr-17705-fix
adamint Jun 17, 2026
8dbae32
Fix VS Code extension API lifecycle issues
adamint Jun 19, 2026
0131c76
Handle selected test comment permission failures
adamint Jun 19, 2026
778aea1
Merge upstream/main into PR 17705 fixes
adamint Jun 19, 2026
08fabc5
Grant issue comment permission to CI tests workflow
adamint Jun 19, 2026
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
154 changes: 154 additions & 0 deletions extension/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import * as path from 'path';
import { AppHostDataRepository, ResourceJson } from './views/AppHostDataRepository';
import { AspireTerminalProvider } from './utils/AspireTerminalProvider';
import { spawnCliProcess } from './debugger/languages/cli';
import { AcquiredTestRunSession, TestRunSessionAcquireOptions } from './dcp/TestRunSessionManager';
import AspireDcpServer from './dcp/AspireDcpServer';

/**
* Public API exported by the Aspire extension for consumption by other extensions (e.g. C# Dev Kit).
*/
export interface AspireExtensionApi {
/**
* Fetches all currently running AppHosts with their resources.
* Performs a fresh CLI call independent of panel/polling state.
*/
getRunningAppHosts(): Promise<AppHostInfo[]>
Comment thread
adamint marked this conversation as resolved.
Resolved

/**
* Stops a running resource by name.
* Resolves when the CLI command completes.
*/
stopResource(resourceName: string, appHostPath: string): Promise<void>

/**
* Starts a stopped resource by name.
* Resolves when the CLI command completes.
*/
startResource(resourceName: string, appHostPath: string): Promise<void>

/**
* Acquires DCP connection environment for a test process that starts an AppHost in-process.
*/
acquireTestRunSession(options: TestRunSessionAcquireOptions): AcquiredTestRunSession

/**
* Releases a test-run DCP lease and stops resources started through it.
*/
releaseTestRunSession(id: string): Promise<void>
}

export interface AppHostInfo {
/** Absolute path to the AppHost project or source file. */
appHostPath: string
/** Process ID of the running AppHost. */
pid: number
/** Dashboard URL, if available. */
dashboardUrl: string | null
/** Resources managed by this AppHost. */
resources: ResourceInfo[]
}

export interface ResourceInfo {
/** Internal resource name as defined in the AppHost. */
name: string
/** Display name for the resource. */
displayName: string | null
/** Resource type (e.g. "Project", "Container"). */
resourceType: string
/** Current state (e.g. "Running", "Stopped", "Building"). */
state: string | null
/** Project path (.csproj) if this is a project resource, extracted from properties["project.path"]. */
projectPath: string | null
/** Endpoint URLs exposed by the resource. */
endpoints: { name: string | null; url: string }[]
/** Absolute path to the AppHost that owns this resource. */
appHostPath: string
}

/**
* Creates the public API object backed by the given data repository.
*/
export function createAspireExtensionApi(dataRepository: AppHostDataRepository, terminalProvider: AspireTerminalProvider, dcpServer: {
acquireTestRunSession: (options: TestRunSessionAcquireOptions) => AcquiredTestRunSession,
releaseTestRunSession: (id: string) => Promise<void>
}): AspireExtensionApi {
return {
async getRunningAppHosts(): Promise<AppHostInfo[]> {
const appHosts = await dataRepository.fetchAppHostsOnce();
return appHosts.map(appHost => ({
appHostPath: appHost.appHostPath,
pid: appHost.appHostPid,
dashboardUrl: appHost.dashboardUrl,
resources: (appHost.resources ?? []).map(r => mapResource(r, appHost.appHostPath)),
}));
},

async stopResource(resourceName: string, appHostPath: string): Promise<void> {
return executeResourceCommand(terminalProvider, resourceName, appHostPath, 'stop');
},

async startResource(resourceName: string, appHostPath: string): Promise<void> {
return executeResourceCommand(terminalProvider, resourceName, appHostPath, 'start');
},

acquireTestRunSession: (options) => dcpServer.acquireTestRunSession(options),
releaseTestRunSession: (id) => dcpServer.releaseTestRunSession(id),
};
}

function mapResource(resource: ResourceJson, appHostPath: string): ResourceInfo {
return {
name: resource.name,
displayName: resource.displayName,
resourceType: resource.resourceType,
state: resource.state,
projectPath: resource.properties?.['project.path'] ?? null,
endpoints: (resource.urls ?? [])
.filter(u => !u.isInternal)
.map(u => ({ name: u.name, url: u.url })),
appHostPath,
};
}

async function executeResourceCommand(terminalProvider: AspireTerminalProvider, resourceName: string, appHostPath: string, commandName: 'start' | 'stop'): Promise<void> {
const trimmedAppHostPath = appHostPath.trim();
if (!trimmedAppHostPath || !path.isAbsolute(trimmedAppHostPath)) {
throw new Error('appHostPath must be a non-empty absolute path');
}

const cliPath = await terminalProvider.getAspireCliExecutablePath();
const args = ['resource', resourceName, commandName, '--apphost', trimmedAppHostPath];
return new Promise<void>((resolve, reject) => {
let stdout = '';
let stderr = '';
let settled = false;

spawnCliProcess(terminalProvider, cliPath, args, {
Comment thread
LittleLittleCloud marked this conversation as resolved.
Resolved
noExtensionVariables: true,
stdoutCallback: (data) => { stdout += data; },
stderrCallback: (data) => { stderr += data; },
exitCallback: (code) => {
if (settled) {
return;
}

settled = true;
if (code === 0) {
resolve();
} else {
const output = (stderr || stdout).trim();
reject(new Error(`aspire resource ${commandName} exited with code ${code}${output ? `: ${output}` : ''}`));
}
},
errorCallback: (error) => {
if (settled) {
return;
}

settled = true;
reject(error);
},
});
});
}
Loading
Loading