-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathsmoke.ts
More file actions
76 lines (74 loc) · 3.41 KB
/
Copy pathsmoke.ts
File metadata and controls
76 lines (74 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import assert from "node:assert/strict";
import type { ChildProcess } from "node:child_process";
import { resolve } from "node:path";
import { approveAll, CopilotClient, RuntimeConnection } from "../../nodejs/src/index.js";
import {
assertHostStopped,
assertRuntimeListener,
connectAhp,
createAhpSession,
localHostArtifacts,
streamedTurn,
} from "../../nodejs/test/e2e/harness/runtimeHost.js";
if (process.platform !== "linux") throw new Error("This source-build topology smoke requires Linux");
const artifacts = localHostArtifacts();
const workDir = resolve(process.argv[2] ?? ".");
const githubToken = process.env.GITHUB_TOKEN || process.env.GH_TOKEN;
assert(githubToken, "Set GITHUB_TOKEN or GH_TOKEN for the live smoke");
const owner = new CopilotClient({
connection: RuntimeConnection.forTcp({ path: artifacts.runtimePath }),
workingDirectory: workDir,
gitHubToken: githubToken,
env: {
...process.env,
...artifacts.env,
GITHUB_TOKEN: githubToken,
GH_TOKEN: githubToken,
},
});
try {
await using sdkSession = await owner.createSession({
onPermissionRequest: approveAll,
model: "claude-sonnet-5",
});
await using host = await owner.startAhpHost({
localServer: {},
onExit: (exit) => console.log(`AHP host stopped: ${exit.reason}`),
});
const ahp = await connectAhp(host);
try {
const session = await createAhpSession(ahp, workDir, githubToken);
const runtime = (owner as unknown as { cliProcess: ChildProcess }).cliProcess;
assert(runtime.pid);
await assertRuntimeListener(host, runtime.pid, artifacts);
console.log(`SDK app ${process.pid} -> runtime ${runtime.pid} (in-process AHP listener)`);
if (!host.url) throw new Error("Local hosting must return a listener URL");
const listener = new URL(host.url);
listener.search = "";
console.log(`AHP listener: ${listener} (connection token intentionally not printed)`);
const [response, sdkResponse] = await Promise.all([
streamedTurn(ahp.client, session.chatUri, session.subscription, "What is 2+2?"),
sdkSession.sendAndWait({ prompt: "What is 2+2?" }),
]);
assert(response.deltas > 0, "AHP turn must include streaming deltas");
assert(response.text.includes("4"));
assert(sdkResponse, "SDK turn must complete");
assert(sdkResponse.data.content.includes("4"));
const ids = (await owner.listSessions()).map((item) => item.sessionId);
assert(ids.includes(session.sessionId), "AHP session must live in the owner's runtime");
assert(ids.includes(sdkSession.sessionId));
console.log(`Standard AHP response: ${response.text} (${response.deltas} streamed deltas)`);
console.log(`SDK response on the same runtime: ${sdkResponse.data.content}`);
await host.dispose();
await assertHostStopped(host, ahp, runtime.pid);
await sdkSession.getEvents();
console.log("Listener closed, AHP client disconnected; hosting runtime and SDK session survive.");
} finally {
await ahp.client.shutdown();
}
} finally {
await owner.stop();
}