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
11 changes: 8 additions & 3 deletions linux-features/shared-app-server-socket/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
const IDENT = "[A-Za-z_$][\\w$]*";

function findTransportSymbols(source) {
const classMatch = source.match(new RegExp(`var (${IDENT})=class\\{kind=\\\`websocket\\\``));
const classMatch = source.match(
new RegExp(
`var (${IDENT})=class\\{options;kind=\\\`websocket\\\`;logger=${IDENT}\\.${IDENT}\\(\\\`AppServerTransportSshWebsocket\\\`\\)`,
),
);
const selectionLogIndex = source.indexOf("selected app-server transport");
if (classMatch == null || selectionLogIndex < 0 || classMatch.index >= selectionLogIndex) return null;

Expand Down Expand Up @@ -65,7 +69,7 @@ function applySharedAppServerSocketPatch(source) {
}
const factorySource = source.slice(factoryStart, factoryEnd);
const localFallbackPattern = new RegExp(
`(if\\(${symbols.namespace}\\.(${IDENT})\\(e\\.hostConfig\\)\\)return [^;]+;)(let (${IDENT})=(${IDENT})\\(e\\.hostConfig\\);return \\4\\?)`,
`(if\\(${symbols.namespace}\\.(${IDENT})\\(e\\.hostConfig\\)\\)return new (${IDENT})\\(\\{hostConfig:e\\.hostConfig,repoRoot:e\\.repoRoot,resourcesPath:e\\.resourcesPath,defaultOriginator:e\\.defaultOriginator\\}\\);)(?=let (${IDENT})=(${IDENT})\\(e\\.hostConfig\\);if\\(\\4\\)\\{)`,
);
const localFallbackMatch = factorySource.match(localFallbackPattern);
if (localFallbackMatch == null) {
Expand All @@ -77,7 +81,8 @@ function applySharedAppServerSocketPatch(source) {

const patchedFactory = factorySource.replace(
localFallbackPattern,
`$1if(process.env.CODEX_LINUX_APP_SERVER_BRIDGE_SOCKET&&e.hostConfig.kind===\`local\`)return new CodexLinuxSharedAppServerSocketTransport(process.env.CODEX_LINUX_APP_SERVER_BRIDGE_SOCKET);$3`,
(match) =>
`${match}if(process.env.CODEX_LINUX_APP_SERVER_BRIDGE_SOCKET&&e.hostConfig.kind===\`local\`)return new CodexLinuxSharedAppServerSocketTransport(process.env.CODEX_LINUX_APP_SERVER_BRIDGE_SOCKET);`,
);
return source.slice(0, factoryStart) + classSource + patchedFactory + source.slice(factoryEnd);
}
Expand Down
23 changes: 20 additions & 3 deletions linux-features/shared-app-server-socket/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,14 @@ async function closeServer(server) {

function syntheticBundle() {
return [
"var Ky=class{kind=`websocket`;proxyStreams=new Set;supportsReconnect(){return!0}",
"var Ky=class{options;kind=`websocket`;logger=r.i(`AppServerTransportSshWebsocket`);proxyStreams=new Set;supportsReconnect(){return!0}",
"async connect(){let t={current:null},r=new n.zn(Fy,{perMessageDeflate:!1,createConnection:()=>",
"(t.current=this.createSshProxyStream(),t.current)});return n.Ln(r,{onPongTimeout:()=>r.terminate()}),new n.Rn(r)}};",
"function n6(e){let t=Jy(e.hostConfig);if(t)return Z.info(`selected app-server transport`),new Ky(t);",
"if(e.transportKind===`remote-control`)return new Remote(e);",
"if(n.io(e.hostConfig))return new Wsl(e);",
"let r=r6(e.hostConfig);return r?new n.Fn({websocketUrl:r}):new n.Nn(e)}function afterFactory(){}",
"if(n.io(e.hostConfig))return new Wsl({hostConfig:e.hostConfig,repoRoot:e.repoRoot,resourcesPath:e.resourcesPath,defaultOriginator:e.defaultOriginator});",
"let r=r6(e.hostConfig);if(r){e.desktopAuthAppServerClient;let t=p8(e.hostConfig,r);return new n.Fn({hostConfig:e.hostConfig,websocketUrl:r,getWebsocketProtocols:void 0,...t==null?{}:{socksProxyUrl:t}})}",
"return new n.Nn({hostConfig:e.hostConfig,repoRoot:e.repoRoot,resourcesPath:e.resourcesPath,defaultOriginator:e.defaultOriginator})}function afterFactory(){}",
].join("");
}

Expand Down Expand Up @@ -243,6 +244,22 @@ test("patch leaves unsupported bundle shapes unchanged with a warning", () => {
assert.match(warnings.join("\n"), /shared app-server socket/i);
});

test("patch rejects the previous SSH transport class shape", () => {
const source = syntheticBundle().replace(
"class{options;kind=`websocket`;logger=r.i(`AppServerTransportSshWebsocket`);",
"class{kind=`websocket`;",
);
const warnings = [];
const originalWarn = console.warn;
console.warn = (...args) => warnings.push(args.join(" "));
try {
assert.equal(applySharedAppServerSocketPatch(source), source);
} finally {
console.warn = originalWarn;
}
assert.match(warnings.join("\n"), /SSH WebSocket transport/);
});

test("descriptor is optional and targets the main bundle", () => {
assert.deepEqual(
descriptors.map(({ id, phase, ciPolicy }) => [id, phase, ciPolicy]),
Expand Down