MCPcopy
hub / github.com/coder/mux / LocalUnpackSSHRuntime

Class LocalUnpackSSHRuntime

src/node/runtime/SSHRuntime.syncContract.test.ts:103–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103class LocalUnpackSSHRuntime extends SSHRuntime {
104 readonly commands: string[] = [];
105
106 constructor(private readonly baseRepoPath: string) {
107 const config: SSHRuntimeConfig = {
108 host: "example.test",
109 srcBaseDir: "/remote/src",
110 };
111 super(config, createMockTransport(config));
112 }
113
114 override exec(command: string, options: ExecOptions): Promise<ExecStream> {
115 this.commands.push(command);
116 if (!command.includes("unpack-objects -r")) {
117 const result = spawnSync("sh", ["-c", command], {
118 cwd: options.cwd,
119 encoding: "utf8",
120 });
121 return Promise.resolve(
122 createExecStream(result.stdout || "", result.stderr || "", result.status ?? 1)
123 );
124 }
125
126 const chunks: Buffer[] = [];
127 let resolveExitCode: (exitCode: number) => void = noop;
128 const exitCode = new Promise<number>((resolve) => {
129 resolveExitCode = resolve;
130 });
131 let unpackRan = false;
132 const runUnpack = () => {
133 if (unpackRan) {
134 return;
135 }
136 unpackRan = true;
137 const result = spawnSync("git", ["-C", this.baseRepoPath, "unpack-objects", "-r"], {
138 input: Buffer.concat(chunks),
139 });
140 resolveExitCode(result.status ?? 1);
141 };
142
143 return Promise.resolve({
144 stdout: createTextStream(""),
145 stderr: createTextStream(""),
146 stdin: new WritableStream<Uint8Array>({
147 write(chunk) {
148 chunks.push(Buffer.from(chunk));
149 return Promise.resolve();
150 },
151 close() {
152 runUnpack();
153 return Promise.resolve();
154 },
155 abort() {
156 resolveExitCode(1);
157 return Promise.resolve();
158 },
159 }),
160 exitCode,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected