AnyEvent-MCP
view release on metacpan or search on metacpan
t/e30_fs_remote.t view on Meta::CPAN
command => [@base, "$dir/alias"], env => \%env,
);
$r = call $aliased, workdirs => {};
my ($alias_id) = keys %{$r->{structuredContent}{workdirs}};
ok $alias_id != 1 && $r->{structuredContent}{resolved_workdirs}{$alias_id} eq "$dir/work"
&& $r->{structuredContent}{workdirs}{$alias_id} eq "$dir/alias",
"remote workdir identity retains the logical symlink while mounts use its physical target";
$r = call $aliased, "file-read" => { path => "renamed" };
ok !$r->{isError} && MIME::Base64::decode_base64 ($r->{structuredContent}{data}) eq "written\n",
"physically resolved remote workdir is usable for subsequent operations";
$aliased->close;
mkdir "$dir/alternate" or die $!;
unlink "$dir/alias" or die $!;
symlink "$dir/alternate", "$dir/alias" or die $!;
my $moved_alias = AnyEvent::MCP::Client::JSONL->new (
command => [@base[0..5], "-h", "mock2", "-e", "$dir/rsh", "--bwrap", "$dir/bwrap", "$dir/alias"],
env => \%env,
);
$r = call $moved_alias, workdirs => {};
is $r->{structuredContent}{workdirs}{$alias_id}, "$dir/alias",
"identical logical workdir gets the same ID even when its physical target differs between hosts";
is $r->{structuredContent}{resolved_workdirs}{$alias_id}, "$dir/alternate",
"remote host independently resolves the physical workdir used for mounts";
$moved_alias->close;
my $direct = AnyEvent::MCP::Client::JSONL->new (
command => [@base[0..5], "-h", "mock", "-e", "$dir/rsh", "--sandbox=none", "$dir/work"],
env => \%env,
);
$r = call $direct, "file-read" => { path => "renamed" };
ok !$r->{isError} && MIME::Base64::decode_base64 ($r->{structuredContent}{data}) eq "written\n",
"remote unsandboxed mode works";
$direct->close;
my $auto = AnyEvent::MCP::Client::JSONL->new (
command => [@base[0..5], "-h", "mock", "-e", "$dir/rsh",
"--sandbox=auto", "--bwrap", "$dir/does-not-exist", "$dir/work"],
env => \%env,
);
$r = call $auto, "file-read" => { path => "renamed" };
ok !$r->{isError} && MIME::Base64::decode_base64 ($r->{structuredContent}{data}) eq "written\n",
"remote sandbox=auto falls back to full-authority mode when bwrap is absent";
$auto->close;
put "$dir/broken-bwrap", "#!$^X\nexit 19;\n";
chmod 0700, "$dir/broken-bwrap" or die $!;
my $broken = AnyEvent::MCP::Client::JSONL->new (
command => [@base[0..5], "-h", "mock", "-e", "$dir/rsh",
"--sandbox=auto", "--bwrap", "$dir/broken-bwrap", "$dir/work"],
env => \%env,
);
$r = call $broken, "file-read" => { path => "renamed" };
ok $r->{isError}, "remote sandbox=auto does not fall back when bwrap is present but fails";
$broken->close;
my $unicode_workdir = "$dir/work-\x{e4}\x{1f431}";
my $unicode_home = "$dir/home-\x{e4}";
my $file = "name-\x{1f431}";
my ($raw_workdir, $raw_home, $raw_file) = ($unicode_workdir, $unicode_home, $file);
utf8::encode $_ for $raw_workdir, $raw_home, $raw_file;
mkdir $raw_workdir or die $!;
mkdir $raw_home or die $!;
put "$raw_workdir/$raw_file", "unicode paths\n";
my $unicode_bin = "$dir/bin-\x{e4}\x{1f431}";
my $raw_bin = $unicode_bin;
utf8::encode $raw_bin;
mkdir $raw_bin or die $!;
put "$raw_bin/git", "#!$^X\nprint 'raw git output';\n";
chmod 0700, "$raw_bin/git" or die $!;
open my $cfg, ">>:raw", "$dir/config/anyevent-mcp/global.ini" or die $!;
my $config_text = "[program mcp-fs]\nprepend-path = $unicode_bin\nexecutable.git = $unicode_bin/git\n"
. "mount-try.unicode = ro:$unicode_bin\nenv.unicode = MCP_TEST_UNICODE=value-\x{e4}\x{1f431}\nenv.raw = MCP_TEST_RAW\n";
utf8::encode $config_text;
print {$cfg} $config_text;
close $cfg or die $!;
my %unicode_env = (%env, HOME => $raw_home, MCP_TEST_RAW => "\xff");
my $unicode_client = AnyEvent::MCP::Client::JSONL->new (
command => [@base, $raw_workdir], env => \%unicode_env,
);
$r = call $unicode_client, workdirs => {};
ok (grep $_ eq $unicode_workdir, values %{$r->{structuredContent}{resolved_workdirs}}),
"remote startup probe decodes explicitly encoded Unicode workdir";
$r = call $unicode_client, "file-read" => { path => $file };
ok !$r->{isError} && MIME::Base64::decode_base64 ($r->{structuredContent}{data}) eq "unicode paths\n",
"remote sandbox and worker accept Unicode workdir and filename";
$r = call $unicode_client, "vcs-status" => { backend => "git", files => [$file] };
ok !$r->{isError} && $r->{structuredContent}{stdout} eq "raw git output",
"remote VCS preserves discovered executable bytes and Unicode pathspec";
ok index (get ("$dir/mounts.log"), "--ro-bind-try\t$raw_bin\t$raw_bin\n") >= 0,
"Unicode configured mount is transmitted as UTF-8 path bytes";
$r = call $unicode_client, exec => {
argv => [$^X, "-e",
'binmode STDOUT; print "$ENV{PATH}\n$ENV{MCP_TEST_UNICODE}\n", unpack "H*", $ENV{MCP_TEST_RAW}'],
reason => "Configured Unicode and inherited raw environment",
};
my ($path_env, $unicode_env_value, $raw_env_value) = split /\n/, $r->{structuredContent}{stdout};
ok !$r->{isError} && index ($path_env, "$unicode_bin:") == 0,
"configured Unicode prepend-path is encoded for sandbox environment";
ok $unicode_env_value eq "value-\x{e4}\x{1f431}",
"configured Unicode environment value reaches subprocess as UTF-8";
ok $raw_env_value eq "ff" && -e "$dir/raw-env.log"
&& get ("$dir/raw-env.log") eq "ff",
"inherited non-UTF-8 environment value is not transcoded";
$r = call $unicode_client, exec => {
argv => [$^X, "-e", 'binmode STDOUT; print $ENV{HOME}'],
reason => "Unicode HOME inside remote sandbox",
};
ok !$r->{isError} && $r->{structuredContent}{stdout} eq $unicode_home,
"remote sandbox passes Unicode HOME as UTF-8 bytes";
ok index (get ("$dir/passwd"), ":Sandbox:$raw_home:/bin/sh") >= 0,
"remote synthetic passwd stores the UTF-8 HOME bytes";
$r = call $unicode_client, exec => {
argv => [$^X, "-e", 'binmode STDIN; local $/; print unpack "H*", <STDIN>'],
stdin => MIME::Base64::encode_base64 ("\xff\0\x80", ""),
stdin_encoding => "base64", reason => "Raw stdin must remain binary",
};
ok !$r->{isError} && $r->{structuredContent}{stdout} eq "ff0080",
"remote subprocess input remains unchanged binary data";
$unicode_client->close;
my $unicode_direct = AnyEvent::MCP::Client::JSONL->new (
command => [@base[0..5], "-h", "mock", "-e", "$dir/rsh",
"--sandbox=none", $raw_workdir],
env => \%unicode_env,
);
$r = call $unicode_direct, exec => {
argv => [$^X, "-MCwd", "-e", 'binmode STDOUT; print Cwd::getcwd'],
reason => "Unicode workdir through unsandboxed remote chdir",
};
ok !$r->{isError} && $r->{structuredContent}{stdout} eq $unicode_workdir,
"remote unsandboxed execution encodes Unicode workdir for chdir";
$unicode_direct->close;
( run in 0.366 second using v1.01-cache-2.11-cpan-234fa220139 )