runa/vscode/integration/server.test.ts

53 lines
1.9 KiB
TypeScript
Raw Normal View History

import assert from "node:assert/strict";
import test from "node:test";
import { ImageClient } from "../src/client";
import { control, spawnCounter, startImage } from "./server";
test("TypeScript inspection shares the real Rust image across clients and reconnects", async (t) => {
const image = await startImage();
t.after(() => image.stop());
const actorRef = await spawnCounter(image.address);
const reference = { type: "actor_ref", data: actorRef };
const payload = {
type: "record",
data: {
nested: {
type: "list",
data: [reference, { type: "integer", data: -9223372036854775808n }],
},
},
};
assert.deepEqual(
await control(image.address, {
operation: "send",
parameters: { actor_ref: actorRef, message: payload },
}),
{ version: 3, request_id: "integration-control", result: { Ok: { kind: "acknowledged" } } },
);
const failures: Error[] = [];
const disconnected = (error?: Error) => {
if (error) failures.push(error);
};
const first = await ImageClient.connect(image.address, disconnected);
t.after(() => first.close());
const [snapshot] = await first.listActors();
assert.ok(snapshot);
assert.equal(snapshot.actor_ref, actorRef);
assert.deepEqual(snapshot.state, { type: "integer", data: 9223372036854775807n });
assert.deepEqual(snapshot.queued, [payload]);
assert.equal(snapshot.reserved, null);
first.close();
const second = await ImageClient.connect(image.address, disconnected);
t.after(() => second.close());
assert.deepEqual(await second.inspectActor(actorRef), snapshot);
// Reading from the extension must not drain the shared runtime event queue.
const events = await control(image.address, { operation: "get_events" });
assert.deepEqual(events, {
version: 3,
request_id: "integration-control",
result: { Ok: { kind: "events", data: [{ event: "spawned", data: { actor_ref: actorRef } }] } },
});
assert.deepEqual(failures, []);
});