Skip to content

Commit eda729a

Browse files
committed
fix: format windows path to POSIX
1 parent 6054949 commit eda729a

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

src/lib/docker/dockerService.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,5 +1031,39 @@ describe('DockerService', () => {
10311031
expect.objectContaining({ cwd: network.path }),
10321032
);
10331033
});
1034+
1035+
it('should map windows paths to posix paths', () => {
1036+
// Mock Windows-style absolute paths.
1037+
const lnd = lndNodes[0] as LndNode;
1038+
const windowsPath = `C:\\Users\\username\\.polar\\networks\\${network.id}\\volumes\\lnd\\${lnd.name}`;
1039+
1040+
const tlsCertPath = `${windowsPath}\\tls.cert`;
1041+
const macaroonPath = `${windowsPath}\\data\\chain\\bitcoin\\regtest\\admin.macaroon`;
1042+
1043+
lnd.paths.tlsCert = tlsCertPath;
1044+
lnd.paths.adminMacaroon = macaroonPath;
1045+
1046+
network.simulation = {
1047+
activity: [
1048+
{
1049+
id: 0,
1050+
source: lndNodes[0].name,
1051+
destination: eclairNodes[0].name,
1052+
intervalSecs: 60,
1053+
amountMsat: 1000,
1054+
},
1055+
],
1056+
status: Status.Stopped,
1057+
};
1058+
1059+
const simJson = dockerService.constructSimJson(network);
1060+
1061+
const lndNode = simJson.nodes.find(n => n.id === lnd.name);
1062+
expect(lndNode).toBeDefined();
1063+
expect(lndNode?.cert).toBe(`/home/simln/.lnd/${lnd.name}/tls.cert`);
1064+
expect(lndNode?.macaroon).toBe(
1065+
`/home/simln/.lnd/${lnd.name}/data/chain/bitcoin/regtest/admin.macaroon`,
1066+
);
1067+
});
10341068
});
10351069
});

src/lib/docker/dockerService.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,15 @@ class DockerService implements DockerLibrary {
405405
* @param network the network to start
406406
*/
407407
constructSimJson(network: Network) {
408+
// Helper function to convert Windows paths to POSIX path format.
409+
const getPosixPath = (path: string) => {
410+
// Normalize to POSIX separators for Windows paths.
411+
const norm = path.replace(/\\/g, '/');
412+
413+
const parts = norm.split('volumes/');
414+
415+
return parts[parts.length - 1];
416+
};
408417
const simJson: {
409418
nodes: SimulationNodeConfig[];
410419
activity: ActivityConfig[];
@@ -439,9 +448,9 @@ class DockerService implements DockerLibrary {
439448
const lnd = node as LndNode;
440449
simNode = {
441450
id: lnd.name,
442-
macaroon: `/home/simln/.${lnd.paths.adminMacaroon.split('volumes/').pop()}`,
451+
macaroon: `/home/simln/.${getPosixPath(lnd.paths.adminMacaroon)}`,
443452
address: `https://host.docker.internal:${lnd.ports.grpc}`,
444-
cert: `/home/simln/.${lnd.paths.tlsCert.split('volumes/').pop()}`,
453+
cert: `/home/simln/.${getPosixPath(lnd.paths.tlsCert)}`,
445454
};
446455
break;
447456

@@ -460,13 +469,9 @@ class DockerService implements DockerLibrary {
460469
simNode = {
461470
id: cln.name,
462471
address: `host.docker.internal:${cln.ports.grpc}`,
463-
ca_cert: `/home/simln/.${cln.paths.tlsCert?.split('volumes/').pop()}`,
464-
client_cert: `/home/simln/.${cln.paths.tlsClientCert
465-
?.split('volumes/')
466-
.pop()}`,
467-
client_key: `/home/simln/.${cln.paths.tlsClientKey
468-
?.split('volumes/')
469-
.pop()}`,
472+
ca_cert: `/home/simln/.${getPosixPath(cln.paths.tlsCert!)}`,
473+
client_cert: `/home/simln/.${getPosixPath(cln.paths.tlsClientCert!)}`,
474+
client_key: `/home/simln/.${getPosixPath(cln.paths.tlsClientKey!)}`,
470475
};
471476
break;
472477

@@ -475,10 +480,8 @@ class DockerService implements DockerLibrary {
475480
simNode = {
476481
id: litd.name,
477482
address: `host.docker.internal:${litd.ports.grpc}`,
478-
cert: `/home/simln/.${litd.paths.tlsCert.split('volumes/').pop()}`,
479-
macaroon: `/home/simln/.${litd.paths.adminMacaroon
480-
.split('volumes/')
481-
.pop()}`,
483+
cert: `/home/simln/.${getPosixPath(litd.paths.tlsCert)}`,
484+
macaroon: `/home/simln/.${getPosixPath(litd.paths.adminMacaroon)}`,
482485
};
483486
break;
484487
}

0 commit comments

Comments
 (0)