Skip to content

Commit b77bf17

Browse files
committed
sync: route the fork's WSL marketplace read through the new runner
v1.4.190 makes runWslProcess the one chokepoint for wsl.exe (stablyai#15903, stablyai#15923) and runProcess the one chokepoint for child processes (stablyai#15746), and both are now ratcheted. The fork's live-plugin-marketplace WSL source still called execFile('wsl.exe', buildWslExecArgs(...)) directly, which broke five checks from one cause: - child-process-import-boundary: a direct node:child_process import, and the offender count 153 over its 152 ceiling - wsl-invocation-boundary (unit and package (windows)): a direct wsl.exe spawn - skill-discovery-wsl-plugins: upstream's test mocks runWslProcess and expects two calls; the fork's execFile bypassed the mock, so the scan consumed the metadata frames and parseWslSkillDiscoveryOutput rejected record kind F - the feature's own WSL tests, which mocked child_process Adopt the sibling reader's migrated shape (loginPath 'none', shell 'bash', maxOutputBytes, throw on non-zero or timeout) — the payload is that reader's and stays bash. The runner takes the script unencoded, so the test's base64 decode is gone; the --exec assertion is replaced by one on the spec the fork now owns, since --exec and payload transport moved into the runner.
1 parent 8e1c5b5 commit b77bf17

2 files changed

Lines changed: 47 additions & 52 deletions

File tree

‎src/main/skills/fork-live-plugin-marketplaces/live-plugin-marketplace-sources-wsl.test.ts‎

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import type { WslResult } from '../../wsl/wsl-runner'
12
import { beforeEach, describe, expect, it, vi } from 'vitest'
23

3-
const execFileMock = vi.hoisted(() => vi.fn())
4+
const runWslProcessMock = vi.hoisted(() => vi.fn())
45

5-
vi.mock('node:child_process', () => ({ execFile: execFileMock }))
6+
vi.mock('../../wsl/wsl-runner', () => ({ runWslProcess: runWslProcessMock }))
67

78
import { discoverLiveClaudePluginSkillSourcesInWsl } from './live-plugin-marketplace-sources-wsl'
89

@@ -27,15 +28,12 @@ function absent(index: number): string {
2728
return record('F', String(index), '0', '')
2829
}
2930

30-
function queueResponse(callIndex: number, stdout: string): void {
31-
execFileMock.mockImplementationOnce(() => {
32-
queueMicrotask(() => {
33-
const callback = execFileMock.mock.calls[callIndex]?.[3] as
34-
| ((error: Error | null, stdout: string) => void)
35-
| undefined
36-
callback?.(null, stdout)
37-
})
38-
})
31+
function wslResult(stdout: string): WslResult {
32+
return { environmentResolved: true, code: 0, stdout, stderr: '', timedOut: false }
33+
}
34+
35+
function queueResponse(_callIndex: number, stdout: string): void {
36+
runWslProcessMock.mockResolvedValueOnce(wslResult(stdout))
3937
}
4038

4139
function metadataResponse(
@@ -67,9 +65,7 @@ function directoryMarketplaces(): string {
6765
}
6866

6967
function decodeScript(callIndex: number): string {
70-
const args = execFileMock.mock.calls[callIndex]?.[1] as string[]
71-
const encoded = /printf %s '([^']+)'/.exec(args[5] ?? '')?.[1]
72-
return Buffer.from(encoded ?? '', 'base64').toString('utf8')
68+
return (runWslProcessMock.mock.calls[callIndex]?.[0].script as string | undefined) ?? ''
7369
}
7470

7571
function decodeMetadataPaths(callIndex: number): string[] {
@@ -87,7 +83,7 @@ function discover(): Promise<{ path: string }[]> {
8783
}
8884

8985
describe('live Claude plugin skill sources in WSL', () => {
90-
beforeEach(() => execFileMock.mockReset())
86+
beforeEach(() => runWslProcessMock.mockReset())
9187

9288
it('batches known_marketplaces.json into the metadata read and stops at one call without a directory marketplace', async () => {
9389
queueResponse(
@@ -104,7 +100,7 @@ describe('live Claude plugin skill sources in WSL', () => {
104100

105101
const roots = await discover()
106102

107-
expect(execFileMock).toHaveBeenCalledTimes(1)
103+
expect(runWslProcessMock).toHaveBeenCalledTimes(1)
108104
// the module slices this batch by position, so order is part of the contract
109105
expect(decodeMetadataPaths(0)).toEqual([
110106
`${HOME_DIR}/.claude/plugins/installed_plugins.json`,
@@ -122,7 +118,7 @@ describe('live Claude plugin skill sources in WSL', () => {
122118

123119
const roots = await discover()
124120

125-
expect(execFileMock).toHaveBeenCalledTimes(2)
121+
expect(runWslProcessMock).toHaveBeenCalledTimes(2)
126122
expect(roots.map((root) => root.path)).toEqual([`${LIVE_DIR}/skills`])
127123
})
128124

@@ -172,29 +168,32 @@ describe('live Claude plugin skill sources in WSL', () => {
172168
expect(decodeScript(1)).toContain(
173169
`'/home/alice/AI Agent/quirk'\\''s marketplace/.claude-plugin/marketplace.json'`
174170
)
175-
expect(execFileMock.mock.calls[1]?.[1]).not.toContain(LIVE_DIR)
171+
expect(runWslProcessMock.mock.calls[1]?.[0].args).toBeUndefined()
176172
})
177173

178-
it('invokes wsl.exe with --exec so the guest never expands the script', async () => {
174+
it('runs through the WSL runner as a bash script that needs no login PATH', async () => {
179175
queueResponse(0, metadataResponse(null))
180176

181177
await discover()
182178

183-
const args = execFileMock.mock.calls[0]?.[1] as string[]
184-
expect(args.slice(0, 5)).toEqual(['-d', 'Ubuntu', '--exec', 'bash', '-c'])
185-
expect(args).not.toContain('--')
179+
// Why assert the spec, not an argv: the runner owns --exec and the payload
180+
// transport now, and picking either per call site is what it exists to stop.
181+
expect(runWslProcessMock.mock.calls[0]?.[0]).toMatchObject({
182+
distro: 'Ubuntu',
183+
loginPath: 'none',
184+
shell: 'bash'
185+
})
186186
})
187187

188188
it('keeps the cached root when the manifest read fails', async () => {
189189
queueResponse(0, metadataResponse(directoryMarketplaces()))
190-
execFileMock.mockImplementationOnce(() => {
191-
queueMicrotask(() => {
192-
const callback = execFileMock.mock.calls[1]?.[3] as
193-
| ((error: Error | null, stdout: string) => void)
194-
| undefined
195-
callback?.(new Error('wsl.exe timed out'), '')
196-
})
197-
})
190+
runWslProcessMock.mockResolvedValueOnce({
191+
environmentResolved: true,
192+
code: null,
193+
stdout: '',
194+
stderr: '',
195+
timedOut: true
196+
} satisfies WslResult)
198197

199198
const roots = await discover()
200199

‎src/main/skills/fork-live-plugin-marketplaces/live-plugin-marketplace-sources-wsl.ts‎

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { execFile } from 'node:child_process'
21
import { posix as pathPosix } from 'node:path'
3-
import { buildWslExecArgs } from '../../../shared/wsl-login-shell-command'
2+
import { runWslProcess } from '../../wsl/wsl-runner'
43
import {
54
buildWslClaudePluginMetadataCommand,
65
parseWslClaudePluginMetadataOutput
@@ -17,28 +16,25 @@ import {
1716
} from './live-plugin-marketplace-registry'
1817

1918
const WSL_METADATA_TIMEOUT_MS = 5_000
20-
const WSL_METADATA_MAX_BUFFER_BYTES = 32 * 1024 * 1024
19+
const WSL_METADATA_MAX_OUTPUT_BYTES = 32 * 1024 * 1024
2120

22-
function executeWslMetadataRead(distro: string, command: string): Promise<string> {
23-
return new Promise((resolve, reject) => {
24-
execFile(
25-
'wsl.exe',
26-
buildWslExecArgs(distro, ['bash', '-c', command]),
27-
{
28-
encoding: 'utf8',
29-
maxBuffer: WSL_METADATA_MAX_BUFFER_BYTES,
30-
timeout: WSL_METADATA_TIMEOUT_MS,
31-
windowsHide: true
32-
},
33-
(error, stdout) => {
34-
if (error) {
35-
reject(error)
36-
return
37-
}
38-
resolve(stdout)
39-
}
40-
)
21+
async function executeWslMetadataRead(distro: string, script: string): Promise<string> {
22+
// Why bash: the payload is the sibling metadata reader's, authored for bash.
23+
const result = await runWslProcess({
24+
distro,
25+
// 'none': base64/printf/stat over $HOME paths, no bare tool to find.
26+
loginPath: 'none',
27+
script,
28+
shell: 'bash',
29+
30+
timeoutMs: WSL_METADATA_TIMEOUT_MS,
31+
maxOutputBytes: WSL_METADATA_MAX_OUTPUT_BYTES
4132
})
33+
// Truncated-but-well-formed output would otherwise parse as real metadata.
34+
if (result.code !== 0 || result.timedOut) {
35+
throw new Error('live-plugin-marketplace-sources-wsl-read-failed')
36+
}
37+
return result.stdout
4238
}
4339

4440
async function readMetadataInDistro(

0 commit comments

Comments
 (0)