@syllm/brickly-test-host 0.11.0 → 0.12.0
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 +17 -1
- package/dist/host.cjs +576 -14
- package/dist/index.cjs +484 -13
- package/dist/sources.lst +1 -0
- package/index.d.ts +157 -93
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -24214,14 +24214,14 @@ var require_varint = __commonJS({
|
|
|
24214
24214
|
"../../node_modules/@bufbuild/protobuf/dist/commonjs/wire/varint.js"(exports2) {
|
|
24215
24215
|
"use strict";
|
|
24216
24216
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
24217
|
-
exports2.varint64read =
|
|
24217
|
+
exports2.varint64read = varint64read2;
|
|
24218
24218
|
exports2.varint64write = varint64write;
|
|
24219
24219
|
exports2.int64FromString = int64FromString2;
|
|
24220
24220
|
exports2.int64ToString = int64ToString2;
|
|
24221
24221
|
exports2.uInt64ToString = uInt64ToString2;
|
|
24222
24222
|
exports2.varint32write = varint32write;
|
|
24223
|
-
exports2.varint32read =
|
|
24224
|
-
function
|
|
24223
|
+
exports2.varint32read = varint32read2;
|
|
24224
|
+
function varint64read2() {
|
|
24225
24225
|
const buf = this.buf;
|
|
24226
24226
|
let pos = this.pos;
|
|
24227
24227
|
let lo = 0;
|
|
@@ -24380,7 +24380,7 @@ var require_varint = __commonJS({
|
|
|
24380
24380
|
bytes.push(1);
|
|
24381
24381
|
}
|
|
24382
24382
|
}
|
|
24383
|
-
function
|
|
24383
|
+
function varint32read2() {
|
|
24384
24384
|
let b = this.buf[this.pos++];
|
|
24385
24385
|
if ((b & 128) === 0) {
|
|
24386
24386
|
this.assertBounds();
|
|
@@ -34648,7 +34648,9 @@ var require_brick_storage = __commonJS({
|
|
|
34648
34648
|
// src/index.ts
|
|
34649
34649
|
var index_exports = {};
|
|
34650
34650
|
__export(index_exports, {
|
|
34651
|
+
HostDriver: () => HostDriver,
|
|
34651
34652
|
HostTestControl: () => HostTestControl,
|
|
34653
|
+
createHostDriver: () => createHostDriver,
|
|
34652
34654
|
spawnTestHost: () => spawnTestHost,
|
|
34653
34655
|
startTestHost: () => startTestHost
|
|
34654
34656
|
});
|
|
@@ -36422,6 +36424,45 @@ var import_grpc_js2 = __toESM(require_src3());
|
|
|
36422
36424
|
var import_grpc_js = __toESM(require_src3());
|
|
36423
36425
|
|
|
36424
36426
|
// ../../node_modules/@bufbuild/protobuf/dist/esm/wire/varint.js
|
|
36427
|
+
function varint64read() {
|
|
36428
|
+
const buf = this.buf;
|
|
36429
|
+
let pos = this.pos;
|
|
36430
|
+
let lo = 0;
|
|
36431
|
+
let hi = 0;
|
|
36432
|
+
for (let shift = 0; shift < 28; shift += 7) {
|
|
36433
|
+
const b = buf[pos++];
|
|
36434
|
+
lo |= (b & 127) << shift;
|
|
36435
|
+
if ((b & 128) == 0) {
|
|
36436
|
+
this.pos = pos;
|
|
36437
|
+
this.assertBounds();
|
|
36438
|
+
this.varint64Lo = lo;
|
|
36439
|
+
this.varint64Hi = hi;
|
|
36440
|
+
return;
|
|
36441
|
+
}
|
|
36442
|
+
}
|
|
36443
|
+
const middleByte = buf[pos++];
|
|
36444
|
+
lo |= (middleByte & 15) << 28;
|
|
36445
|
+
hi = (middleByte & 112) >> 4;
|
|
36446
|
+
if ((middleByte & 128) == 0) {
|
|
36447
|
+
this.pos = pos;
|
|
36448
|
+
this.assertBounds();
|
|
36449
|
+
this.varint64Lo = lo;
|
|
36450
|
+
this.varint64Hi = hi;
|
|
36451
|
+
return;
|
|
36452
|
+
}
|
|
36453
|
+
for (let shift = 3; shift <= 31; shift += 7) {
|
|
36454
|
+
const b = buf[pos++];
|
|
36455
|
+
hi |= (b & 127) << shift;
|
|
36456
|
+
if ((b & 128) == 0) {
|
|
36457
|
+
this.pos = pos;
|
|
36458
|
+
this.assertBounds();
|
|
36459
|
+
this.varint64Lo = lo;
|
|
36460
|
+
this.varint64Hi = hi;
|
|
36461
|
+
return;
|
|
36462
|
+
}
|
|
36463
|
+
}
|
|
36464
|
+
throw new Error("invalid varint");
|
|
36465
|
+
}
|
|
36425
36466
|
var TWO_PWR_32_DBL = 4294967296;
|
|
36426
36467
|
function int64FromString(dec) {
|
|
36427
36468
|
const minus = dec[0] === "-";
|
|
@@ -36496,6 +36537,40 @@ var decimalFrom1e7WithLeadingZeros = (digit1e7) => {
|
|
|
36496
36537
|
const partial = String(digit1e7);
|
|
36497
36538
|
return "0000000".slice(partial.length) + partial;
|
|
36498
36539
|
};
|
|
36540
|
+
function varint32read() {
|
|
36541
|
+
let b = this.buf[this.pos++];
|
|
36542
|
+
if ((b & 128) === 0) {
|
|
36543
|
+
this.assertBounds();
|
|
36544
|
+
return b;
|
|
36545
|
+
}
|
|
36546
|
+
let result = b & 127;
|
|
36547
|
+
b = this.buf[this.pos++];
|
|
36548
|
+
result |= (b & 127) << 7;
|
|
36549
|
+
if ((b & 128) === 0) {
|
|
36550
|
+
this.assertBounds();
|
|
36551
|
+
return result;
|
|
36552
|
+
}
|
|
36553
|
+
b = this.buf[this.pos++];
|
|
36554
|
+
result |= (b & 127) << 14;
|
|
36555
|
+
if ((b & 128) === 0) {
|
|
36556
|
+
this.assertBounds();
|
|
36557
|
+
return result;
|
|
36558
|
+
}
|
|
36559
|
+
b = this.buf[this.pos++];
|
|
36560
|
+
result |= (b & 127) << 21;
|
|
36561
|
+
if ((b & 128) === 0) {
|
|
36562
|
+
this.assertBounds();
|
|
36563
|
+
return result;
|
|
36564
|
+
}
|
|
36565
|
+
b = this.buf[this.pos++];
|
|
36566
|
+
result |= (b & 15) << 28;
|
|
36567
|
+
for (let readBytes = 5; (b & 128) !== 0 && readBytes < 10; readBytes++)
|
|
36568
|
+
b = this.buf[this.pos++];
|
|
36569
|
+
if ((b & 128) !== 0)
|
|
36570
|
+
throw new Error("invalid varint");
|
|
36571
|
+
this.assertBounds();
|
|
36572
|
+
return result >>> 0;
|
|
36573
|
+
}
|
|
36499
36574
|
|
|
36500
36575
|
// ../../node_modules/@bufbuild/protobuf/dist/esm/proto-int64.js
|
|
36501
36576
|
var protoInt64 = /* @__PURE__ */ makeInt64Support();
|
|
@@ -36998,6 +37073,206 @@ function varint32Size(value) {
|
|
|
36998
37073
|
return 4;
|
|
36999
37074
|
return 5;
|
|
37000
37075
|
}
|
|
37076
|
+
var BinaryReader = class {
|
|
37077
|
+
constructor(buf, decodeUtf8 = getTextEncoding().decodeUtf8) {
|
|
37078
|
+
this.decodeUtf8 = decodeUtf8;
|
|
37079
|
+
this.varint64Lo = 0;
|
|
37080
|
+
this.varint64Hi = 0;
|
|
37081
|
+
this.varint64 = varint64read;
|
|
37082
|
+
this.uint32 = varint32read;
|
|
37083
|
+
this.buf = buf;
|
|
37084
|
+
this.len = buf.length;
|
|
37085
|
+
this.pos = 0;
|
|
37086
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
37087
|
+
}
|
|
37088
|
+
/**
|
|
37089
|
+
* Reads a tag - field number and wire type. Tags are uint32 varints; values
|
|
37090
|
+
* that do not fit in uint32 are rejected.
|
|
37091
|
+
*/
|
|
37092
|
+
tag() {
|
|
37093
|
+
const start = this.pos;
|
|
37094
|
+
const tag = this.uint32();
|
|
37095
|
+
const bytesRead = this.pos - start;
|
|
37096
|
+
if (bytesRead > 5 || bytesRead == 5 && this.buf[this.pos - 1] > 15) {
|
|
37097
|
+
throw new Error("illegal tag: varint overflows uint32");
|
|
37098
|
+
}
|
|
37099
|
+
const fieldNo = tag >>> 3;
|
|
37100
|
+
const wireType = tag & 7;
|
|
37101
|
+
if (fieldNo <= 0 || wireType > 5) {
|
|
37102
|
+
throw new Error("illegal tag: field no " + fieldNo + " wire type " + wireType);
|
|
37103
|
+
}
|
|
37104
|
+
return [fieldNo, wireType];
|
|
37105
|
+
}
|
|
37106
|
+
/**
|
|
37107
|
+
* Skip one element and return the skipped data.
|
|
37108
|
+
*
|
|
37109
|
+
* When skipping StartGroup, provide the tags field number to check for
|
|
37110
|
+
* matching field number in the EndGroup tag. Recursion into nested groups
|
|
37111
|
+
* is guarded by the `recursionLimit` argument: When the limit is reached,
|
|
37112
|
+
* this method throws.
|
|
37113
|
+
*/
|
|
37114
|
+
skip(wireType, fieldNo, recursionLimit = 100) {
|
|
37115
|
+
let start = this.pos;
|
|
37116
|
+
switch (wireType) {
|
|
37117
|
+
case WireType.Varint:
|
|
37118
|
+
while (this.buf[this.pos++] & 128) {
|
|
37119
|
+
}
|
|
37120
|
+
break;
|
|
37121
|
+
// @ts-ignore TS7029: Fallthrough case in switch -- ignore instead of expect-error for compiler settings without noFallthroughCasesInSwitch: true
|
|
37122
|
+
case WireType.Bit64:
|
|
37123
|
+
this.pos += 4;
|
|
37124
|
+
case WireType.Bit32:
|
|
37125
|
+
this.pos += 4;
|
|
37126
|
+
break;
|
|
37127
|
+
case WireType.LengthDelimited:
|
|
37128
|
+
let len = this.uint32();
|
|
37129
|
+
this.pos += len;
|
|
37130
|
+
break;
|
|
37131
|
+
case WireType.StartGroup:
|
|
37132
|
+
if (recursionLimit <= 0) {
|
|
37133
|
+
throw new Error("maximum recursion depth reached");
|
|
37134
|
+
}
|
|
37135
|
+
for (; ; ) {
|
|
37136
|
+
const [fn, wt] = this.tag();
|
|
37137
|
+
if (wt === WireType.EndGroup) {
|
|
37138
|
+
if (fieldNo !== void 0 && fn !== fieldNo) {
|
|
37139
|
+
throw new Error("invalid end group tag");
|
|
37140
|
+
}
|
|
37141
|
+
break;
|
|
37142
|
+
}
|
|
37143
|
+
this.skip(wt, fn, recursionLimit - 1);
|
|
37144
|
+
}
|
|
37145
|
+
break;
|
|
37146
|
+
default:
|
|
37147
|
+
throw new Error("cant skip wire type " + wireType);
|
|
37148
|
+
}
|
|
37149
|
+
this.assertBounds();
|
|
37150
|
+
return this.buf.subarray(start, this.pos);
|
|
37151
|
+
}
|
|
37152
|
+
/**
|
|
37153
|
+
* Throws error if position in byte array is out of range.
|
|
37154
|
+
*/
|
|
37155
|
+
assertBounds() {
|
|
37156
|
+
if (this.pos > this.len)
|
|
37157
|
+
throw new RangeError("premature EOF");
|
|
37158
|
+
}
|
|
37159
|
+
/**
|
|
37160
|
+
* Read a `int32` field, a signed 32 bit varint.
|
|
37161
|
+
*/
|
|
37162
|
+
int32() {
|
|
37163
|
+
return this.uint32() | 0;
|
|
37164
|
+
}
|
|
37165
|
+
/**
|
|
37166
|
+
* Read a `sint32` field, a signed, zigzag-encoded 32-bit varint.
|
|
37167
|
+
*/
|
|
37168
|
+
sint32() {
|
|
37169
|
+
let zze = this.uint32();
|
|
37170
|
+
return zze >>> 1 ^ -(zze & 1);
|
|
37171
|
+
}
|
|
37172
|
+
/**
|
|
37173
|
+
* Read a `int64` field, a signed 64-bit varint.
|
|
37174
|
+
*/
|
|
37175
|
+
int64() {
|
|
37176
|
+
this.varint64();
|
|
37177
|
+
return protoInt64.dec(this.varint64Lo, this.varint64Hi);
|
|
37178
|
+
}
|
|
37179
|
+
/**
|
|
37180
|
+
* Read a `uint64` field, an unsigned 64-bit varint.
|
|
37181
|
+
*/
|
|
37182
|
+
uint64() {
|
|
37183
|
+
this.varint64();
|
|
37184
|
+
return protoInt64.uDec(this.varint64Lo, this.varint64Hi);
|
|
37185
|
+
}
|
|
37186
|
+
/**
|
|
37187
|
+
* Read a `sint64` field, a signed, zig-zag-encoded 64-bit varint.
|
|
37188
|
+
*/
|
|
37189
|
+
sint64() {
|
|
37190
|
+
this.varint64();
|
|
37191
|
+
let lo = this.varint64Lo;
|
|
37192
|
+
let hi = this.varint64Hi;
|
|
37193
|
+
let s = -(lo & 1);
|
|
37194
|
+
lo = (lo >>> 1 | (hi & 1) << 31) ^ s;
|
|
37195
|
+
hi = hi >>> 1 ^ s;
|
|
37196
|
+
return protoInt64.dec(lo, hi);
|
|
37197
|
+
}
|
|
37198
|
+
/**
|
|
37199
|
+
* Read a `bool` field, a variant.
|
|
37200
|
+
*/
|
|
37201
|
+
bool() {
|
|
37202
|
+
const b = this.buf[this.pos];
|
|
37203
|
+
if (b < 128) {
|
|
37204
|
+
this.pos++;
|
|
37205
|
+
return b !== 0;
|
|
37206
|
+
}
|
|
37207
|
+
this.varint64();
|
|
37208
|
+
return this.varint64Lo !== 0 || this.varint64Hi !== 0;
|
|
37209
|
+
}
|
|
37210
|
+
/**
|
|
37211
|
+
* Read a `fixed32` field, an unsigned, fixed-length 32-bit integer.
|
|
37212
|
+
*/
|
|
37213
|
+
fixed32() {
|
|
37214
|
+
return this.view.getUint32((this.pos += 4) - 4, true);
|
|
37215
|
+
}
|
|
37216
|
+
/**
|
|
37217
|
+
* Read a `sfixed32` field, a signed, fixed-length 32-bit integer.
|
|
37218
|
+
*/
|
|
37219
|
+
sfixed32() {
|
|
37220
|
+
return this.view.getInt32((this.pos += 4) - 4, true);
|
|
37221
|
+
}
|
|
37222
|
+
/**
|
|
37223
|
+
* Read a `fixed64` field, an unsigned, fixed-length 64 bit integer.
|
|
37224
|
+
*/
|
|
37225
|
+
fixed64() {
|
|
37226
|
+
return protoInt64.uDec(this.sfixed32(), this.sfixed32());
|
|
37227
|
+
}
|
|
37228
|
+
/**
|
|
37229
|
+
* Read a `fixed64` field, a signed, fixed-length 64-bit integer.
|
|
37230
|
+
*/
|
|
37231
|
+
sfixed64() {
|
|
37232
|
+
return protoInt64.dec(this.sfixed32(), this.sfixed32());
|
|
37233
|
+
}
|
|
37234
|
+
/**
|
|
37235
|
+
* Read a `float` field, 32-bit floating point number.
|
|
37236
|
+
*/
|
|
37237
|
+
float() {
|
|
37238
|
+
return this.view.getFloat32((this.pos += 4) - 4, true);
|
|
37239
|
+
}
|
|
37240
|
+
/**
|
|
37241
|
+
* Read a `double` field, a 64-bit floating point number.
|
|
37242
|
+
*/
|
|
37243
|
+
double() {
|
|
37244
|
+
return this.view.getFloat64((this.pos += 8) - 8, true);
|
|
37245
|
+
}
|
|
37246
|
+
/**
|
|
37247
|
+
* Read a `bytes` field, length-delimited arbitrary data.
|
|
37248
|
+
*/
|
|
37249
|
+
bytes() {
|
|
37250
|
+
let len = this.uint32(), start = this.pos;
|
|
37251
|
+
this.pos += len;
|
|
37252
|
+
this.assertBounds();
|
|
37253
|
+
return this.buf.subarray(start, start + len);
|
|
37254
|
+
}
|
|
37255
|
+
/**
|
|
37256
|
+
* Read a `string` field, length-delimited data converted to UTF-8 text. If
|
|
37257
|
+
* `strict` is true, throw on invalid UTF-8 instead of substituting U+FFFD.
|
|
37258
|
+
*/
|
|
37259
|
+
string(strict) {
|
|
37260
|
+
const bytes = this.bytes();
|
|
37261
|
+
const len = bytes.length;
|
|
37262
|
+
if (len <= ASCII_MAX_LENGTH) {
|
|
37263
|
+
const codes = new Array(len);
|
|
37264
|
+
for (let i = 0; i < len; i++) {
|
|
37265
|
+
const byte = bytes[i];
|
|
37266
|
+
if (byte > 127) {
|
|
37267
|
+
return this.decodeUtf8(bytes, strict);
|
|
37268
|
+
}
|
|
37269
|
+
codes[i] = byte;
|
|
37270
|
+
}
|
|
37271
|
+
return String.fromCharCode.apply(String, codes);
|
|
37272
|
+
}
|
|
37273
|
+
return this.decodeUtf8(bytes, strict);
|
|
37274
|
+
}
|
|
37275
|
+
};
|
|
37001
37276
|
function assertInt32(arg) {
|
|
37002
37277
|
if (typeof arg == "string") {
|
|
37003
37278
|
arg = Number(arg);
|
|
@@ -37096,6 +37371,17 @@ function toBrickGrpcStatus(error) {
|
|
|
37096
37371
|
metadata
|
|
37097
37372
|
};
|
|
37098
37373
|
}
|
|
37374
|
+
function unpackBrickError(error) {
|
|
37375
|
+
const bin = error.metadata?.get("grpc-status-details-bin")[0];
|
|
37376
|
+
if (!bin) return void 0;
|
|
37377
|
+
const bytes = typeof bin === "string" ? Buffer.from(bin, "utf8") : bin;
|
|
37378
|
+
for (const item of decodeRpcStatus(bytes)) {
|
|
37379
|
+
if (item.typeUrl === BRICK_ERROR_TYPE_URL || item.typeUrl.endsWith("BrickError")) {
|
|
37380
|
+
return import_error.BrickError.decode(item.value);
|
|
37381
|
+
}
|
|
37382
|
+
}
|
|
37383
|
+
return void 0;
|
|
37384
|
+
}
|
|
37099
37385
|
function registeredDetail(code, error) {
|
|
37100
37386
|
const extra = error && typeof error === "object" && "detail" in error && error.detail && typeof error.detail === "object" ? error.detail : {};
|
|
37101
37387
|
const text = (key, fallback) => typeof extra[key] === "string" ? extra[key] : fallback;
|
|
@@ -37266,6 +37552,19 @@ function encodeRpcStatus(code, message, details) {
|
|
|
37266
37552
|
}
|
|
37267
37553
|
return Buffer.from(writer.finish());
|
|
37268
37554
|
}
|
|
37555
|
+
function decodeRpcStatus(bytes) {
|
|
37556
|
+
const reader = new BinaryReader(bytes);
|
|
37557
|
+
const details = [];
|
|
37558
|
+
while (reader.pos < reader.len) {
|
|
37559
|
+
const tag = reader.uint32();
|
|
37560
|
+
const field = tag >>> 3;
|
|
37561
|
+
if (field === 3) details.push(import_any.Any.decode(reader, reader.uint32()));
|
|
37562
|
+
else if (field === 1) reader.int32();
|
|
37563
|
+
else if (field === 2) reader.string();
|
|
37564
|
+
else reader.skip(tag & 7);
|
|
37565
|
+
}
|
|
37566
|
+
return details;
|
|
37567
|
+
}
|
|
37269
37568
|
|
|
37270
37569
|
// ../../src/main/runtime/transport/connector-interact-relay.ts
|
|
37271
37570
|
function relayConnectorInteract(call, openInteract) {
|
|
@@ -40413,19 +40712,30 @@ var HostGrpcServer = class {
|
|
|
40413
40712
|
});
|
|
40414
40713
|
this.server.addService(
|
|
40415
40714
|
import_resource.ResourceServiceService,
|
|
40416
|
-
createResourceServiceImplementation(
|
|
40715
|
+
createResourceServiceImplementation(
|
|
40716
|
+
this.resources,
|
|
40717
|
+
this.spawns,
|
|
40718
|
+
this.resourceContext,
|
|
40719
|
+
this.helperAccess
|
|
40720
|
+
)
|
|
40417
40721
|
);
|
|
40418
40722
|
this.server.addService(
|
|
40419
40723
|
import_event.EventServiceService,
|
|
40420
40724
|
createEventServiceImplementation(this.events, this.spawns, () => this.eventRouter)
|
|
40421
40725
|
);
|
|
40422
|
-
this.server.addService(
|
|
40726
|
+
this.server.addService(
|
|
40727
|
+
import_storage.StorageServiceService,
|
|
40728
|
+
createStorageServiceImplementation(this.storage, this.spawns)
|
|
40729
|
+
);
|
|
40423
40730
|
this.server.addService(
|
|
40424
40731
|
import_brick_storage.BrickStorageServiceService,
|
|
40425
40732
|
createBrickStorageServiceImplementation(() => this.brickStorageService, this.spawns)
|
|
40426
40733
|
);
|
|
40427
40734
|
this.server.addService(import_system.SystemServiceService, createSystemServiceImplementation(this.spawns));
|
|
40428
|
-
this.server.addService(
|
|
40735
|
+
this.server.addService(
|
|
40736
|
+
import_window.WindowServiceService,
|
|
40737
|
+
createWindowServiceImplementation(this.windows, this.spawns)
|
|
40738
|
+
);
|
|
40429
40739
|
this.server.addService(
|
|
40430
40740
|
import_connector.BrickConnectorServiceService,
|
|
40431
40741
|
createConnectorServiceImplementation(this.connector, this.spawns)
|
|
@@ -40483,6 +40793,10 @@ var HostGrpcServer = class {
|
|
|
40483
40793
|
getHandle(runtimeHandleId) {
|
|
40484
40794
|
return this.handles.get(runtimeHandleId);
|
|
40485
40795
|
}
|
|
40796
|
+
/** 已注册 runtime 句柄快照(测试驱动面用,只读)。 */
|
|
40797
|
+
listHandles() {
|
|
40798
|
+
return [...this.handles.values()];
|
|
40799
|
+
}
|
|
40486
40800
|
async listen(host = "127.0.0.1", port = 0) {
|
|
40487
40801
|
assertLoopbackHost(host);
|
|
40488
40802
|
if (this.started) {
|
|
@@ -40490,13 +40804,17 @@ var HostGrpcServer = class {
|
|
|
40490
40804
|
return this.endpoint;
|
|
40491
40805
|
}
|
|
40492
40806
|
const bound = await new Promise((resolve2, reject) => {
|
|
40493
|
-
this.server.bindAsync(
|
|
40494
|
-
|
|
40495
|
-
|
|
40496
|
-
|
|
40807
|
+
this.server.bindAsync(
|
|
40808
|
+
`${host}:${port}`,
|
|
40809
|
+
import_grpc_js12.ServerCredentials.createInsecure(),
|
|
40810
|
+
(error, boundPort) => {
|
|
40811
|
+
if (error) {
|
|
40812
|
+
reject(error);
|
|
40813
|
+
return;
|
|
40814
|
+
}
|
|
40815
|
+
resolve2(`${host}:${boundPort}`);
|
|
40497
40816
|
}
|
|
40498
|
-
|
|
40499
|
-
});
|
|
40817
|
+
);
|
|
40500
40818
|
});
|
|
40501
40819
|
this.endpoint = bound;
|
|
40502
40820
|
this.started = true;
|
|
@@ -40701,6 +41019,157 @@ async function startTestHost(options = {}) {
|
|
|
40701
41019
|
};
|
|
40702
41020
|
}
|
|
40703
41021
|
|
|
41022
|
+
// ../../src/main/runtime/transport/test-host/drive.ts
|
|
41023
|
+
var CANNED_UI_METHODS = [
|
|
41024
|
+
"createBrowserWindow",
|
|
41025
|
+
"callWindow",
|
|
41026
|
+
"closeWindow",
|
|
41027
|
+
"forceCloseWindow",
|
|
41028
|
+
"listWindows",
|
|
41029
|
+
"sendToChild",
|
|
41030
|
+
"replyToChild",
|
|
41031
|
+
"emitToChild"
|
|
41032
|
+
];
|
|
41033
|
+
var HostDriver = class {
|
|
41034
|
+
constructor(testHost) {
|
|
41035
|
+
this.testHost = testHost;
|
|
41036
|
+
}
|
|
41037
|
+
cannedUi = /* @__PURE__ */ new Map();
|
|
41038
|
+
uiCallLog = [];
|
|
41039
|
+
uiHandlerInstalled = false;
|
|
41040
|
+
/** 再铸一套 spawn 凭据(依赖 invoke 等需要多个 runtime 的用例)。 */
|
|
41041
|
+
spawn(input) {
|
|
41042
|
+
const credentials2 = this.testHost.host.createSpawn({
|
|
41043
|
+
brickId: input.brickId,
|
|
41044
|
+
instanceId: input.instanceId,
|
|
41045
|
+
origin: input.origin ?? "development",
|
|
41046
|
+
version: input.version ?? "0.0.0"
|
|
41047
|
+
});
|
|
41048
|
+
const record = this.testHost.host.spawns.get(credentials2.spawnId);
|
|
41049
|
+
return {
|
|
41050
|
+
...credentials2,
|
|
41051
|
+
brickId: record?.brickId ?? input.brickId,
|
|
41052
|
+
instanceId: record?.instanceId ?? credentials2.spawnId
|
|
41053
|
+
};
|
|
41054
|
+
}
|
|
41055
|
+
/** 已注册 runtime 句柄快照(测试等待/断言用)。 */
|
|
41056
|
+
runtimes() {
|
|
41057
|
+
return this.testHost.host.listHandles().map((handle) => ({
|
|
41058
|
+
spawnId: handle.runtimeHandleId,
|
|
41059
|
+
brickId: handle.brickId,
|
|
41060
|
+
instanceId: handle.instanceId
|
|
41061
|
+
}));
|
|
41062
|
+
}
|
|
41063
|
+
/** 等待 runtime 完成注册,拿到 host→runtime 通道句柄。 */
|
|
41064
|
+
async waitHandle(spawnId, timeoutMs = 1e4) {
|
|
41065
|
+
const id = spawnId ?? this.testHost.spawnCredentials.spawnId;
|
|
41066
|
+
const deadline = Date.now() + timeoutMs;
|
|
41067
|
+
while (Date.now() < deadline) {
|
|
41068
|
+
const handle = this.testHost.host.getHandle(id);
|
|
41069
|
+
if (handle) return handle;
|
|
41070
|
+
await sleep(40);
|
|
41071
|
+
}
|
|
41072
|
+
throw new Error(`\u7B49\u5F85 runtime \u6CE8\u518C\u8D85\u65F6\uFF1AspawnId=${id}`);
|
|
41073
|
+
}
|
|
41074
|
+
/** host→runtime 单向 invoke;错误按 brick 码结构化返回而不抛出。 */
|
|
41075
|
+
async invoke(input) {
|
|
41076
|
+
try {
|
|
41077
|
+
const handle = await this.waitHandle(input.spawnId, input.timeoutMs);
|
|
41078
|
+
const result = await handle.channel.invoke(
|
|
41079
|
+
{ commandId: input.commandId, input: jsToBrickValue(input.input ?? null) },
|
|
41080
|
+
{ deadlineMs: input.timeoutMs }
|
|
41081
|
+
);
|
|
41082
|
+
return { ok: true, result: brickValueToJs(result.result) };
|
|
41083
|
+
} catch (error) {
|
|
41084
|
+
return { ok: false, error: serializeError(error) };
|
|
41085
|
+
}
|
|
41086
|
+
}
|
|
41087
|
+
/** host→runtime interact 批量模式:open → closeInput → 收 events 与 final。 */
|
|
41088
|
+
async interact(input) {
|
|
41089
|
+
try {
|
|
41090
|
+
const handle = await this.waitHandle(input.spawnId, input.timeoutMs);
|
|
41091
|
+
const signal = input.timeoutMs ? AbortSignal.timeout(input.timeoutMs) : void 0;
|
|
41092
|
+
const { events, result } = await handle.channel.stream(
|
|
41093
|
+
input.commandId,
|
|
41094
|
+
jsToBrickValue(input.input ?? null),
|
|
41095
|
+
{ signal }
|
|
41096
|
+
);
|
|
41097
|
+
return { ok: true, events: events.map(brickValueToJs), result: brickValueToJs(result) };
|
|
41098
|
+
} catch (error) {
|
|
41099
|
+
return { ok: false, error: serializeError(error) };
|
|
41100
|
+
}
|
|
41101
|
+
}
|
|
41102
|
+
/** 往指定 runtime 推 domain event(经真 HostEventBus 投递到订阅流)。 */
|
|
41103
|
+
async pushEvent(input) {
|
|
41104
|
+
const spawnId = input.spawnId ?? this.testHost.spawnCredentials.spawnId;
|
|
41105
|
+
const record = this.testHost.host.spawns.get(spawnId);
|
|
41106
|
+
const instanceId = record?.instanceId ?? spawnId;
|
|
41107
|
+
this.testHost.host.events.publishTo(
|
|
41108
|
+
instanceId,
|
|
41109
|
+
input.topic,
|
|
41110
|
+
jsToBrickValue(input.payload ?? null)
|
|
41111
|
+
);
|
|
41112
|
+
}
|
|
41113
|
+
/**
|
|
41114
|
+
* 注册 UI 方法罐头响应(重复注册后者覆盖前者)。
|
|
41115
|
+
* method 取 HostUiHandler 方法名,如 createBrowserWindow / callWindow。
|
|
41116
|
+
*/
|
|
41117
|
+
setUiResponse(method, result) {
|
|
41118
|
+
if (!CANNED_UI_METHODS.includes(method)) {
|
|
41119
|
+
throw new Error(`\u672A\u77E5 UI \u65B9\u6CD5\uFF1A${method}\uFF08\u53EF\u9009\uFF1A${CANNED_UI_METHODS.join(", ")}\uFF09`);
|
|
41120
|
+
}
|
|
41121
|
+
this.cannedUi.set(method, result);
|
|
41122
|
+
if (!this.uiHandlerInstalled) {
|
|
41123
|
+
this.installUiHandler();
|
|
41124
|
+
this.uiHandlerInstalled = true;
|
|
41125
|
+
}
|
|
41126
|
+
}
|
|
41127
|
+
/** UI handler 被调记录(按序),/reset 清空。 */
|
|
41128
|
+
uiCalls() {
|
|
41129
|
+
return [...this.uiCallLog];
|
|
41130
|
+
}
|
|
41131
|
+
/** 清驱动面状态:罐头响应与 UI 调用记录(不动 storage/故障规则,那些归 control)。 */
|
|
41132
|
+
reset() {
|
|
41133
|
+
this.cannedUi.clear();
|
|
41134
|
+
this.uiCallLog.length = 0;
|
|
41135
|
+
}
|
|
41136
|
+
installUiHandler() {
|
|
41137
|
+
const dispatch = (method, args) => {
|
|
41138
|
+
this.uiCallLog.push({ method, args, at: Date.now() });
|
|
41139
|
+
if (!this.cannedUi.has(method)) {
|
|
41140
|
+
throw new Error(`UI \u65B9\u6CD5 ${method} \u672A\u6CE8\u518C\u7F50\u5934\u54CD\u5E94`);
|
|
41141
|
+
}
|
|
41142
|
+
return this.cannedUi.get(method);
|
|
41143
|
+
};
|
|
41144
|
+
const handler = {
|
|
41145
|
+
createBrowserWindow: (...args) => dispatch("createBrowserWindow", args),
|
|
41146
|
+
callWindow: (...args) => dispatch("callWindow", args),
|
|
41147
|
+
closeWindow: (...args) => dispatch("closeWindow", args),
|
|
41148
|
+
forceCloseWindow: (...args) => dispatch("forceCloseWindow", args),
|
|
41149
|
+
listWindows: (...args) => dispatch("listWindows", args),
|
|
41150
|
+
sendToChild: (...args) => dispatch("sendToChild", args),
|
|
41151
|
+
replyToChild: (...args) => dispatch("replyToChild", args),
|
|
41152
|
+
emitToChild: (...args) => dispatch("emitToChild", args)
|
|
41153
|
+
};
|
|
41154
|
+
this.testHost.host.setUiHandler(handler);
|
|
41155
|
+
}
|
|
41156
|
+
};
|
|
41157
|
+
function createHostDriver(testHost) {
|
|
41158
|
+
return new HostDriver(testHost);
|
|
41159
|
+
}
|
|
41160
|
+
function serializeError(error) {
|
|
41161
|
+
const serviceError = error;
|
|
41162
|
+
const brick = unpackBrickError(serviceError);
|
|
41163
|
+
return {
|
|
41164
|
+
brickCode: brick?.code,
|
|
41165
|
+
message: serviceError?.message ?? String(error),
|
|
41166
|
+
grpcStatus: serviceError?.code
|
|
41167
|
+
};
|
|
41168
|
+
}
|
|
41169
|
+
function sleep(ms) {
|
|
41170
|
+
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
41171
|
+
}
|
|
41172
|
+
|
|
40704
41173
|
// src/spawn.ts
|
|
40705
41174
|
var import_node_child_process = require("node:child_process");
|
|
40706
41175
|
var import_node_path7 = require("node:path");
|
|
@@ -40799,7 +41268,9 @@ function waitForExit(child, timeoutMs) {
|
|
|
40799
41268
|
}
|
|
40800
41269
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40801
41270
|
0 && (module.exports = {
|
|
41271
|
+
HostDriver,
|
|
40802
41272
|
HostTestControl,
|
|
41273
|
+
createHostDriver,
|
|
40803
41274
|
spawnTestHost,
|
|
40804
41275
|
startTestHost
|
|
40805
41276
|
});
|
package/dist/sources.lst
CHANGED
|
@@ -207,6 +207,7 @@
|
|
|
207
207
|
..\..\src\main\runtime\transport\runtime-channel.ts
|
|
208
208
|
..\..\src\main\runtime\transport\spawn-registry.ts
|
|
209
209
|
..\..\src\main\runtime\transport\test-host\control.ts
|
|
210
|
+
..\..\src\main\runtime\transport\test-host\drive.ts
|
|
210
211
|
..\..\src\main\runtime\transport\test-host\main.ts
|
|
211
212
|
..\..\src\main\runtime\transport\test-host\start.ts
|
|
212
213
|
..\..\src\main\runtime\transport\tokens.ts
|