diff --git a/httpd-client/tests/support/globalSetup.ts b/httpd-client/tests/support/globalSetup.ts index f16d729a0..d97b2a9f4 100644 --- a/httpd-client/tests/support/globalSetup.ts +++ b/httpd-client/tests/support/globalSetup.ts @@ -47,7 +47,7 @@ export default async function globalSetup(): Promise<() => void> { gitOptions: gitOptions["alice"], }); await palm.startHttpd(defaultHttpdPort); - await palm.startNode({ trackingPolicy: "track", trackingScope: "all" }); + await palm.startNode({ policy: "track", scope: "all" }); console.log("Creating source-browsing fixture"); await createSourceBrowsingFixture(peerManager, palm); diff --git a/tests/support/fixtures.ts b/tests/support/fixtures.ts index 208fc3a9a..07db15f58 100644 --- a/tests/support/fixtures.ts +++ b/tests/support/fixtures.ts @@ -310,10 +310,12 @@ export async function createSourceBrowsingFixture( gitOptions: gitOptions["bob"], }); const bobProjectPath = Path.join(bob.checkoutPath, "source-browsing"); - await alice.startNode(); - await bob.startNode(); - await alice.connect(palm); - await bob.connect(palm); + await alice.startNode({ connect: [palm.address] }); + await bob.startNode({ connect: [palm.address] }); + await alice.waitForEvent({ type: "peerConnected", nid: palm.nodeId }, 1000); + await palm.waitForEvent({ type: "peerConnected", nid: alice.nodeId }, 1000); + await bob.waitForEvent({ type: "peerConnected", nid: palm.nodeId }, 1000); + await palm.waitForEvent({ type: "peerConnected", nid: bob.nodeId }, 1000); await alice.git(["clone", sourceBrowsingDir], { cwd: alice.checkoutPath }); await alice.git(["checkout", "feature/branch"], { cwd: aliceProjectPath }); diff --git a/tests/support/globalSetup.ts b/tests/support/globalSetup.ts index de36ee991..bc6c7f840 100644 --- a/tests/support/globalSetup.ts +++ b/tests/support/globalSetup.ts @@ -51,7 +51,7 @@ export default async function globalSetup(): Promise<() => void> { gitOptions: gitOptions["alice"], }); await palm.startHttpd(defaultHttpdPort); - await palm.startNode({ trackingPolicy: "track", trackingScope: "all" }); + await palm.startNode({ policy: "track", scope: "all" }); console.log("Creating source-browsing fixture"); await createSourceBrowsingFixture(peerManager, palm); diff --git a/tests/support/peerManager.ts b/tests/support/peerManager.ts index 4400f4a35..ffab2f4ed 100644 --- a/tests/support/peerManager.ts +++ b/tests/support/peerManager.ts @@ -203,17 +203,6 @@ export class RadiclePeer { }; await execa("rad", ["auth", "--alias", name], { env }); - const config = await Fs.readFile( - Path.join(radHome, "config.json"), - "utf-8", - ); - const parsedConfig = NodeConfigSchema.parse(JSON.parse(config)); - parsedConfig.node.network = "test"; - await Fs.writeFile( - Path.join(radHome, "config.json"), - JSON.stringify(parsedConfig), - "utf-8", - ); const { stdout: nodeId } = await execa("rad", ["self", "--nid"], { env }); return new RadiclePeer({ @@ -265,27 +254,22 @@ export class RadiclePeer { this.#httpdBaseUrl = undefined; } - public async startNode(params?: { - trackingScope?: "trusted" | "all"; - trackingPolicy?: "track" | "block"; - }) { + public async startNode(nodeParams: Partial = {}) { const gitPort = await getPort(); const gitSocketAddr = `0.0.0.0:${gitPort}`; const listenPort = await getPort(); this.#listenSocketAddr = `0.0.0.0:${listenPort}`; + // We need to set the `config.json` file after creating the node identity and before starting it. + // Since we aren't able to pass these configuration options through the CLI. + await updateNodeConfig(this.#radHome, nodeParams); + const args = [ "--git-daemon", gitSocketAddr, "--listen", this.#listenSocketAddr, ]; - if (params?.trackingScope) { - args.push("--tracking-scope", params.trackingScope); - } - if (params?.trackingPolicy) { - args.push("--tracking-policy", params.trackingPolicy); - } this.#nodeProcess = this.spawn("radicle-node", args); @@ -353,23 +337,11 @@ export class RadiclePeer { } } - public async connect(remote: RadiclePeer) { - if (!remote.#listenSocketAddr) { + public get address(): string { + if (!this.#listenSocketAddr) { throw new Error("Remote node has no listen addr yet"); } - await this.rad( - ["node", "connect", `${remote.nodeId}@${remote.#listenSocketAddr}`], - { cwd: this.#radHome }, - ); - - await this.waitForEvent( - { type: "peerConnected", nid: remote.nodeId }, - 1000, - ); - await remote.waitForEvent( - { type: "peerConnected", nid: this.nodeId }, - 1000, - ); + return `${this.nodeId}@${this.#listenSocketAddr}`; } public uiUrl(): string { @@ -426,3 +398,18 @@ export class RadiclePeer { return childProcess; } } + +async function updateNodeConfig( + radHome: string, + nodeParams: Partial, +) { + const configPath = Path.join(radHome, "config.json"); + const config = await Fs.readFile(configPath, "utf-8"); + const nodeConfig = NodeConfigSchema.parse(JSON.parse(config)); + nodeConfig.node = { + ...nodeConfig.node, + network: "test", + ...nodeParams, + }; + await Fs.writeFile(configPath, JSON.stringify(nodeConfig), "utf-8"); +}