@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/index.d.ts CHANGED
@@ -1,93 +1,157 @@
1
- /**
2
- * @syllm/brickly-test-host 对外类型面(手写维护,与 dist/index.cjs 对齐)。
3
- * 内部实现类型不外露;host 字段为不透明引用。
4
- */
5
- import type { ChildProcess } from 'node:child_process'
6
-
7
- export interface SpawnCredentials {
8
- spawnId: string
9
- bootstrapToken: string
10
- runtimeToHostToken: string
11
- hostToRuntimeToken: string
12
- }
13
-
14
- export interface SetFaultInput {
15
- /** 完整 gRPC 方法路径,如 /brickly.runtime.v1.BrickStorageService/KvGet */
16
- path: string
17
- /** Brick 错误码,如 BRICK_STORAGE_NOT_FOUND */
18
- brickCode: string
19
- message?: string
20
- /** 命中次数,默认 1 */
21
- count?: number
22
- }
23
-
24
- export type SetFaultRequest = SetFaultInput
25
-
26
- export interface FaultRule {
27
- path: string
28
- brickCode: string
29
- message: string
30
- remaining: number
31
- }
32
-
33
- export interface RecordedCall {
34
- path: string
35
- at: number
36
- }
37
-
38
- export declare class HostTestControl {
39
- readonly interceptor: unknown
40
- setFault(input: SetFaultInput): void
41
- clearFaults(): void
42
- recordedCalls(): RecordedCall[]
43
- /** 清空故障规则与录制(不清 storage 数据) */
44
- reset(): void
45
- }
46
-
47
- export interface StartTestHostOptions {
48
- brickId?: string
49
- /** 自定义 storage 实现;默认内存版 */
50
- storage?: unknown
51
- /** 内存 storage 生效配额(MB),默认 50 */
52
- quotaMB?: number
53
- }
54
-
55
- export interface TestHost {
56
- /** 真宿主 gRPC 服务实例(内部类型;跨进程消费者用 spawnTestHost) */
57
- readonly host: unknown
58
- readonly control: HostTestControl
59
- readonly endpoint: string
60
- readonly spawnCredentials: SpawnCredentials
61
- close(): Promise<void>
62
- }
63
-
64
- /** 进程内装配真宿主 + 控制面(Node 测试用)。 */
65
- export declare function startTestHost(options?: StartTestHostOptions): Promise<TestHost>
66
-
67
- /** 宿主进程 stdout 首行就绪 JSON(spawn 协议契约)。 */
68
- export interface SpawnedHostInfo {
69
- /** gRPC 数据面地址,如 127.0.0.1:50051 */
70
- dataEndpoint: string
71
- /** 控制面 HTTP 地址,如 127.0.0.1:50052 */
72
- controlEndpoint: string
73
- runtimeToHostToken: string
74
- }
75
-
76
- export interface SpawnTestHostOptions {
77
- /** 宿主 bundle 路径,默认包内 dist/host.cjs */
78
- hostBundlePath?: string
79
- nodeExecutable?: string
80
- readyTimeoutMs?: number
81
- exitTimeoutMs?: number
82
- }
83
-
84
- export interface SpawnedTestHost extends SpawnedHostInfo {
85
- readonly process: ChildProcess
86
- setFault(input: SetFaultRequest): Promise<void>
87
- reset(): Promise<void>
88
- recordedCalls(): Promise<RecordedCall[]>
89
- close(): Promise<void>
90
- }
91
-
92
- /** 拉起 dist/host.cjs 子进程并提供控制面客户端。 */
93
- export declare function spawnTestHost(options?: SpawnTestHostOptions): Promise<SpawnedTestHost>
1
+ /**
2
+ * @syllm/brickly-test-host 对外类型面(手写维护,与 dist/index.cjs 对齐)。
3
+ * 内部实现类型不外露;host 字段为不透明引用。
4
+ */
5
+ import type { ChildProcess } from 'node:child_process'
6
+
7
+ export interface SpawnCredentials {
8
+ spawnId: string
9
+ bootstrapToken: string
10
+ runtimeToHostToken: string
11
+ hostToRuntimeToken: string
12
+ }
13
+
14
+ export interface SetFaultInput {
15
+ /** 完整 gRPC 方法路径,如 /brickly.runtime.v1.BrickStorageService/KvGet */
16
+ path: string
17
+ /** Brick 错误码,如 BRICK_STORAGE_NOT_FOUND */
18
+ brickCode: string
19
+ message?: string
20
+ /** 命中次数,默认 1 */
21
+ count?: number
22
+ }
23
+
24
+ export type SetFaultRequest = SetFaultInput
25
+
26
+ export interface FaultRule {
27
+ path: string
28
+ brickCode: string
29
+ message: string
30
+ remaining: number
31
+ }
32
+
33
+ export interface RecordedCall {
34
+ path: string
35
+ at: number
36
+ }
37
+
38
+ export declare class HostTestControl {
39
+ readonly interceptor: unknown
40
+ setFault(input: SetFaultInput): void
41
+ clearFaults(): void
42
+ recordedCalls(): RecordedCall[]
43
+ /** 清空故障规则与录制(不清 storage 数据) */
44
+ reset(): void
45
+ }
46
+
47
+ export interface StartTestHostOptions {
48
+ brickId?: string
49
+ /** 自定义 storage 实现;默认内存版 */
50
+ storage?: unknown
51
+ /** 内存 storage 生效配额(MB),默认 50 */
52
+ quotaMB?: number
53
+ }
54
+
55
+ export interface TestHost {
56
+ /** 真宿主 gRPC 服务实例(内部类型;跨进程消费者用 spawnTestHost) */
57
+ readonly host: unknown
58
+ readonly control: HostTestControl
59
+ readonly endpoint: string
60
+ readonly spawnCredentials: SpawnCredentials
61
+ close(): Promise<void>
62
+ }
63
+
64
+ /** 进程内装配真宿主 + 控制面(Node 测试用)。 */
65
+ export declare function startTestHost(options?: StartTestHostOptions): Promise<TestHost>
66
+
67
+ /** 宿主进程 stdout 首行就绪 JSON(spawn 协议契约)。 */
68
+ export interface SpawnedHostInfo {
69
+ /** gRPC 数据面地址,如 127.0.0.1:50051 */
70
+ dataEndpoint: string
71
+ /** 控制面 HTTP 地址,如 127.0.0.1:50052 */
72
+ controlEndpoint: string
73
+ runtimeToHostToken: string
74
+ }
75
+
76
+ export interface SpawnTestHostOptions {
77
+ /** 宿主 bundle 路径,默认包内 dist/host.cjs */
78
+ hostBundlePath?: string
79
+ nodeExecutable?: string
80
+ readyTimeoutMs?: number
81
+ exitTimeoutMs?: number
82
+ }
83
+
84
+ export interface SpawnedTestHost extends SpawnedHostInfo {
85
+ readonly process: ChildProcess
86
+ setFault(input: SetFaultRequest): Promise<void>
87
+ reset(): Promise<void>
88
+ recordedCalls(): Promise<RecordedCall[]>
89
+ close(): Promise<void>
90
+ }
91
+
92
+ /** 拉起 dist/host.cjs 子进程并提供控制面客户端。 */
93
+ export declare function spawnTestHost(options?: SpawnTestHostOptions): Promise<SpawnedTestHost>
94
+
95
+ // —— 驱动面(host→runtime):进程内消费者用 createHostDriver;
96
+ // 外部语言走 HTTP 控制面 /spawn /invoke /interact /events/push /ui-handler ——
97
+
98
+ export interface DriveSpawnInput {
99
+ brickId: string
100
+ instanceId?: string
101
+ origin?: 'development' | 'installed' | 'review' | 'platform'
102
+ version?: string
103
+ }
104
+
105
+ export interface DriveSpawnResult extends SpawnCredentials {
106
+ brickId: string
107
+ instanceId: string
108
+ }
109
+
110
+ export interface DriveInvokeInput {
111
+ /** 缺省用首个 spawn */
112
+ spawnId?: string
113
+ commandId: string
114
+ input?: unknown
115
+ timeoutMs?: number
116
+ }
117
+
118
+ export type DriveInteractInput = DriveInvokeInput
119
+
120
+ export interface DriveError {
121
+ brickCode?: string
122
+ message: string
123
+ grpcStatus?: number
124
+ }
125
+
126
+ export interface DriveInvokeResult {
127
+ ok: boolean
128
+ result?: unknown
129
+ error?: DriveError
130
+ }
131
+
132
+ export interface DriveInteractResult {
133
+ ok: boolean
134
+ events?: unknown[]
135
+ result?: unknown
136
+ error?: DriveError
137
+ }
138
+
139
+ export interface UiCallRecord {
140
+ method: string
141
+ args: unknown[]
142
+ at: number
143
+ }
144
+
145
+ export declare class HostDriver {
146
+ spawn(input: DriveSpawnInput): DriveSpawnResult
147
+ runtimes(): Array<{ spawnId: string; brickId: string; instanceId: string }>
148
+ invoke(input: DriveInvokeInput): Promise<DriveInvokeResult>
149
+ interact(input: DriveInteractInput): Promise<DriveInteractResult>
150
+ pushEvent(input: { spawnId?: string; topic: string; payload?: unknown }): Promise<void>
151
+ setUiResponse(method: string, result: unknown): void
152
+ uiCalls(): UiCallRecord[]
153
+ reset(): void
154
+ }
155
+
156
+ /** 创建 host→runtime 驱动器(进程内测试用)。 */
157
+ export declare function createHostDriver(testHost: TestHost): HostDriver
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@syllm/brickly-test-host",
3
- "version": "0.11.0",
4
- "description": "Brickly 真宿主测试工件:HostGrpcServer + 控制面(故障注入/请求录制),供各端 SDK 契约测试使用",
3
+ "version": "0.12.0",
4
+ "description": "Brickly 真宿主测试工件:HostGrpcServer + 控制面(故障注入/请求录制/host→runtime 驱动面),供各端 SDK 契约测试使用",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.cjs",