Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/generatets/main-generatets.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error {
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n")
fmt.Fprintf(&buf, "export interface MockRpcClient {\n")
fmt.Fprintf(&buf, " mockWshRpcCall(client: WshClient, command: string, data: any, opts?: RpcOpts): Promise<any>;\n")
fmt.Fprintf(&buf, " mockWshRpcStream(client: WshClient, command: string, data: any, opts?: RpcOpts): AsyncGenerator<any, void, boolean>;\n")
fmt.Fprintf(&buf, "}\n\n")
fmt.Fprintf(&buf, "let mockClient: MockRpcClient = null;\n\n")
fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient): void {\n")
fmt.Fprintf(&buf, " mockClient = client;\n")
fmt.Fprintf(&buf, "}\n\n")
Comment on lines +119 to +122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Allow callers to clear the installed mock.

After setMockRpcClient(...) runs once, there is no supported way to restore the real RPC path. Since every generated command reads the same module-level mockClient, a test/dev mock can leak into later calls for the rest of the session.

Suggested generator change
-	fmt.Fprintf(&buf, "let mockClient: MockRpcClient = null;\n\n")
-	fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient): void {\n")
+	fmt.Fprintf(&buf, "let mockClient: MockRpcClient | null = null;\n\n")
+	fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient | null): void {\n")
 	fmt.Fprintf(&buf, "    mockClient = client;\n")
 	fmt.Fprintf(&buf, "}\n\n")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fmt.Fprintf(&buf, "let mockClient: MockRpcClient = null;\n\n")
fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient): void {\n")
fmt.Fprintf(&buf, " mockClient = client;\n")
fmt.Fprintf(&buf, "}\n\n")
fmt.Fprintf(&buf, "let mockClient: MockRpcClient | null = null;\n\n")
fmt.Fprintf(&buf, "export function setMockRpcClient(client: MockRpcClient | null): void {\n")
fmt.Fprintf(&buf, " mockClient = client;\n")
fmt.Fprintf(&buf, "}\n\n")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/generatets/main-generatets.go` around lines 119 - 122, The generated
module currently exposes a module-level mockClient and a setter
setMockRpcClient(client: MockRpcClient) but offers no way to restore the real
RPC client, causing test mocks to leak; update the generation to allow clearing
the mock by either (A) changing setMockRpcClient to accept MockRpcClient | null
and assign mockClient = client, or (B) add an explicit clearMockRpcClient():
void that sets mockClient = null; update any references to mockClient usage
accordingly so callers can restore the real RPC path by passing null or calling
clearMockRpcClient (refer to symbols mockClient and setMockRpcClient).

orderedKeys := utilfn.GetOrderedMapKeys(declMap)
fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n")
fmt.Fprintf(&buf, "class RpcApiType {\n")
Expand Down
Loading
Loading