@openvcs/sdk 0.2.3 → 0.2.4
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.
- package/README.md +30 -1
- package/lib/init.d.ts +2 -0
- package/lib/init.js +6 -3
- package/lib/runtime/contracts.d.ts +45 -0
- package/lib/runtime/contracts.js +4 -0
- package/lib/runtime/dispatcher.d.ts +16 -0
- package/lib/runtime/dispatcher.js +133 -0
- package/lib/runtime/errors.d.ts +5 -0
- package/lib/runtime/errors.js +26 -0
- package/lib/runtime/host.d.ts +10 -0
- package/lib/runtime/host.js +48 -0
- package/lib/runtime/index.d.ts +9 -0
- package/lib/runtime/index.js +166 -0
- package/lib/runtime/transport.d.ts +14 -0
- package/lib/runtime/transport.js +72 -0
- package/lib/types/host.d.ts +57 -0
- package/lib/types/host.js +4 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.js +22 -0
- package/lib/types/plugin.d.ts +56 -0
- package/lib/types/plugin.js +4 -0
- package/lib/types/protocol.d.ts +77 -0
- package/lib/types/protocol.js +13 -0
- package/lib/types/vcs.d.ts +459 -0
- package/lib/types/vcs.js +4 -0
- package/package.json +14 -1
- package/src/lib/init.ts +6 -3
- package/src/lib/runtime/contracts.ts +52 -0
- package/src/lib/runtime/dispatcher.ts +185 -0
- package/src/lib/runtime/errors.ts +27 -0
- package/src/lib/runtime/host.ts +72 -0
- package/src/lib/runtime/index.ts +201 -0
- package/src/lib/runtime/transport.ts +93 -0
- package/src/lib/types/host.ts +71 -0
- package/src/lib/types/index.ts +7 -0
- package/src/lib/types/plugin.ts +110 -0
- package/src/lib/types/protocol.ts +97 -0
- package/src/lib/types/vcs.ts +579 -0
- package/test/init.test.js +25 -0
- package/test/runtime.test.js +118 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const assert = require("node:assert/strict");
|
|
2
|
+
const { EventEmitter } = require("node:events");
|
|
3
|
+
const test = require("node:test");
|
|
4
|
+
|
|
5
|
+
const { createPluginRuntime } = require("../lib/runtime");
|
|
6
|
+
const {
|
|
7
|
+
parseFramedMessages,
|
|
8
|
+
serializeFramedMessage,
|
|
9
|
+
} = require("../lib/runtime/transport");
|
|
10
|
+
|
|
11
|
+
function createRuntimeHarness(options) {
|
|
12
|
+
const stdin = new EventEmitter();
|
|
13
|
+
const chunks = [];
|
|
14
|
+
const stdout = {
|
|
15
|
+
write(chunk) {
|
|
16
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const runtime = createPluginRuntime(options);
|
|
21
|
+
runtime.start({ stdin, stdout });
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
async request(message) {
|
|
25
|
+
stdin.emit("data", serializeFramedMessage(message));
|
|
26
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
27
|
+
const parsed = parseFramedMessages(Buffer.concat(chunks));
|
|
28
|
+
chunks.length = 0;
|
|
29
|
+
return parsed.messages;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test("createPluginRuntime answers plugin.initialize with inferred capabilities", async () => {
|
|
35
|
+
const harness = createRuntimeHarness({});
|
|
36
|
+
|
|
37
|
+
const messages = await harness.request({
|
|
38
|
+
jsonrpc: "2.0",
|
|
39
|
+
id: 1,
|
|
40
|
+
method: "plugin.initialize",
|
|
41
|
+
params: {},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
assert.deepEqual(messages, [
|
|
45
|
+
{
|
|
46
|
+
jsonrpc: "2.0",
|
|
47
|
+
id: 1,
|
|
48
|
+
result: {
|
|
49
|
+
protocol_version: 1,
|
|
50
|
+
implements: {
|
|
51
|
+
plugin: true,
|
|
52
|
+
vcs: false,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("createPluginRuntime uses plugin defaults and host notifications", async () => {
|
|
60
|
+
const harness = createRuntimeHarness({
|
|
61
|
+
plugin: {
|
|
62
|
+
async "plugin.init"(_params, context) {
|
|
63
|
+
context.host.info("ready");
|
|
64
|
+
return null;
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const messages = await harness.request({
|
|
70
|
+
jsonrpc: "2.0",
|
|
71
|
+
id: 2,
|
|
72
|
+
method: "plugin.init",
|
|
73
|
+
params: {},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
assert.deepEqual(messages, [
|
|
77
|
+
{
|
|
78
|
+
jsonrpc: "2.0",
|
|
79
|
+
method: "host.log",
|
|
80
|
+
params: {
|
|
81
|
+
level: "info",
|
|
82
|
+
target: "openvcs.plugin",
|
|
83
|
+
message: "ready",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
jsonrpc: "2.0",
|
|
88
|
+
id: 2,
|
|
89
|
+
result: null,
|
|
90
|
+
},
|
|
91
|
+
]);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("createPluginRuntime reports missing methods as plugin failures", async () => {
|
|
95
|
+
const harness = createRuntimeHarness({});
|
|
96
|
+
|
|
97
|
+
const messages = await harness.request({
|
|
98
|
+
jsonrpc: "2.0",
|
|
99
|
+
id: 3,
|
|
100
|
+
method: "vcs.get_caps",
|
|
101
|
+
params: {},
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
assert.deepEqual(messages, [
|
|
105
|
+
{
|
|
106
|
+
jsonrpc: "2.0",
|
|
107
|
+
id: 3,
|
|
108
|
+
error: {
|
|
109
|
+
code: -32001,
|
|
110
|
+
message: "method 'vcs.get_caps' is not implemented",
|
|
111
|
+
data: {
|
|
112
|
+
code: "rpc-method-not-found",
|
|
113
|
+
message: "method 'vcs.get_caps' is not implemented",
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
]);
|
|
118
|
+
});
|