Skip to content

Commit 72f0cde

Browse files
feat: make dfx info replica-port pocketic-incompatible (#4056)
1 parent 90d18e9 commit 72f0cde

File tree

9 files changed

+82
-25
lines changed

9 files changed

+82
-25
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
# UNRELEASED
44

5+
### feat!: `dfx info pocketic-config-port`
6+
7+
Due to the incompatibility between the APIs on the replica port and the PocketIC port, `dfx info replica-port`
8+
no longer works with PocketIC, and the PocketIC port is provided by a new command, `dfx info pocketic-config-port`.
9+
510
### test: adds playwright test for svelte `dfx new` project
611

712
The first of a suite of baseline tests to automate testing starter projects. Makes sure they are compatible with other dfx or asset canister changes.

docs/cli-reference/dfx-info.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ dfx info [type] [flag]
1414

1515
These are the types of information that the `dfx info` command can display.
1616

17-
| Information | Description |
18-
|--------------------|--------------------------------------------------------------------------------------------------------------------|
19-
| candid-ui-url | The URL of the Candid UI canister. |
20-
| networks-json-path | Path to network definition file networks.json. |
21-
| replica-port | The listening port of the replica. |
22-
| replica-rev | The revision of the bundled replica. |
23-
| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". |
24-
| webserver-port | The local webserver port. |
17+
| Information | Description |
18+
|----------------------|--------------------------------------------------------------------------------------------------------------------|
19+
| candid-ui-url | The URL of the Candid UI canister. |
20+
| networks-json-path | Path to network definition file networks.json. |
21+
| replica-port | The listening port of the replica. |
22+
| pocketic-config-port | The listening port of PocketIC. |
23+
| replica-rev | The revision of the bundled replica. |
24+
| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". |
25+
| webserver-port | The local webserver port. |
2526

2627
## Options
2728

e2e/tests-dfx/create.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ function textual_decode() {
416416
# base64 encode the actual canister id
417417
CANISTER_ID_BASE64="$(textual_decode "${CANISTER_ID}" | xxd -r -p | base64)"
418418
# fetch topology from PocketIC server
419-
TOPOLOGY="$(curl "http://127.0.0.1:$(dfx info replica-port)/instances/0/read/topology")"
419+
TOPOLOGY="$(curl "http://127.0.0.1:$(dfx info pocketic-config-port)/instances/0/read/topology")"
420420
echo "${TOPOLOGY}"
421421
# find application subnet id in the topology
422422
for subnet_id in $(echo "${TOPOLOGY}" | jq '.subnet_configs | keys[]')

e2e/tests-dfx/info.bash

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,22 @@ teardown() {
1515
}
1616

1717
@test "displays the replica port" {
18-
assert_command_fail dfx info replica-port
19-
assert_contains "No replica port found"
20-
21-
dfx_start
22-
assert_command dfx info replica-port
2318
if [[ "$USE_POCKETIC" ]]
2419
then
20+
assert_command_fail dfx info pocketic-config-port
21+
assert_contains "No PocketIC port found"
22+
dfx_start
23+
assert_command_fail dfx info replica-port
24+
assert_contains "The running server is PocketIC"
25+
assert_command dfx info pocketic-config-port
2526
assert_eq "$(get_pocketic_port)"
2627
else
28+
assert_command_fail dfx info replica-port
29+
assert_contains "No replica port found"
30+
dfx_start
31+
assert_command_fail dfx info pocketic-config-port
32+
assert_contains "The running server is a native replica"
33+
assert_command dfx info replica-port
2734
assert_eq "$(get_replica_port)"
2835
fi
2936
}

e2e/tests-dfx/start.bash

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,11 @@ teardown() {
283283
jq ".local.replica.port=$replica_port" "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"
284284

285285
dfx_start
286-
287-
assert_command dfx info replica-port
286+
if [[ "$USE_POCKETIC" ]]; then
287+
assert_command dfx info pocketic-config-port
288+
else
289+
assert_command dfx info replica-port
290+
fi
288291
assert_eq "$replica_port"
289292
}
290293

src/dfx-core/src/config/model/local_server_descriptor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use std::net::SocketAddr;
1818
use std::path::{Path, PathBuf};
1919
use time::OffsetDateTime;
2020

21+
use super::replica_config::CachedReplicaConfig;
22+
2123
#[derive(Deserialize, Serialize, Debug)]
2224
pub struct NetworkMetadata {
2325
pub created: OffsetDateTime,
@@ -394,6 +396,12 @@ impl LocalServerDescriptor {
394396
None => Ok(None),
395397
}
396398
}
399+
400+
pub fn is_pocketic(&self) -> Result<Option<bool>, StructuredFileError> {
401+
Ok(self
402+
.effective_config()?
403+
.map(|cfg| matches!(cfg.config, CachedReplicaConfig::PocketIc { .. })))
404+
}
397405
}
398406

399407
/// Reads a port number from a file.

src/dfx/src/commands/info/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod pocketic_config_port;
12
mod replica_port;
23
mod webserver_port;
34
use crate::commands::info::{replica_port::get_replica_port, webserver_port::get_webserver_port};
@@ -10,21 +11,24 @@ use crate::Environment;
1011
use anyhow::{bail, Context};
1112
use clap::{Parser, Subcommand};
1213
use dfx_core::config::model::dfinity::NetworksConfig;
14+
use pocketic_config_port::get_pocketic_config_port;
1315

1416
#[derive(Subcommand, Clone, Debug)]
1517
enum InfoType {
1618
/// Show the URL of the Candid UI canister
1719
CandidUiUrl,
1820
/// Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened".
1921
SecurityPolicy,
20-
/// Show the port of the local replica
21-
ReplicaPort,
22+
/// Show the port of the local IC API/HTTP gateway
23+
WebserverPort,
2224
/// Show the revision of the replica shipped with this dfx binary
2325
ReplicaRev,
24-
/// Show the port of the webserver
25-
WebserverPort,
2626
/// Show the path to network configuration file
2727
NetworksJsonPath,
28+
/// Show the port the replica is using, if it is running
29+
ReplicaPort,
30+
/// Show the port that PocketIC is using, if it is running
31+
PocketicConfigPort,
2832
}
2933

3034
#[derive(Parser)]
@@ -54,6 +58,7 @@ pub fn exec(env: &dyn Environment, opts: InfoOpts) -> DfxResult {
5458
ic_asset::security_policy::SecurityPolicy::Standard.to_json5_str()
5559
}
5660
InfoType::ReplicaPort => get_replica_port(env)?,
61+
InfoType::PocketicConfigPort => get_pocketic_config_port(env)?,
5762
InfoType::ReplicaRev => info::replica_rev().to_string(),
5863
InfoType::WebserverPort => get_webserver_port(env)?,
5964
InfoType::NetworksJsonPath => NetworksConfig::new()?
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use anyhow::bail;
2+
use dfx_core::network::provider::{create_network_descriptor, LocalBindDetermination};
3+
4+
use crate::lib::{environment::Environment, error::DfxResult};
5+
6+
pub(crate) fn get_pocketic_config_port(env: &dyn Environment) -> DfxResult<String> {
7+
let network_descriptor = create_network_descriptor(
8+
env.get_config()?,
9+
env.get_networks_config(),
10+
None,
11+
None,
12+
LocalBindDetermination::AsConfigured,
13+
)?;
14+
let local = network_descriptor.local_server_descriptor()?;
15+
match local.is_pocketic()? {
16+
Some(true) => {}
17+
Some(false) => bail!("The running server is a native replica, not PocketIC"),
18+
None => bail!("No PocketIC port found"),
19+
}
20+
let logger = None;
21+
if let Some(port) = local.get_running_pocketic_port(logger)? {
22+
Ok(format!("{}", port))
23+
} else {
24+
bail!("No PocketIC port found");
25+
}
26+
}

src/dfx/src/commands/info/replica_port.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ pub(crate) fn get_replica_port(env: &dyn Environment) -> DfxResult<String> {
1111
None,
1212
LocalBindDetermination::AsConfigured,
1313
)?;
14-
14+
let local = network_descriptor.local_server_descriptor()?;
15+
match local.is_pocketic()? {
16+
Some(false) => {}
17+
Some(true) => bail!("The running server is PocketIC, not a native replica"),
18+
None => bail!("No replica port found"),
19+
}
1520
let logger = None;
16-
if let Some(port) = network_descriptor
17-
.local_server_descriptor()?
18-
.get_running_replica_port(logger)?
19-
{
21+
if let Some(port) = local.get_running_replica_port(logger)? {
2022
Ok(format!("{}", port))
2123
} else {
2224
bail!("No replica port found");

0 commit comments

Comments
 (0)