926724a279
A worker now opens the same directory the primary is in, unless told otherwise.
Resolution: explicit spawn cwd → per-profile config cwd → the primary's cwd
(auto-detected from the bridge_spawn caller's PID via lsof -d cwd) → the daemon's
cwd. Never $HOME.
Mechanism (found by live probe, corrects the earlier assumption): an agent.start
pane does NOT inherit its tab's or workspace's cwd — it starts in $HOME. herdr's
agent.start honours an (undocumented) cwd param, so the resolved cwd is threaded
onto agent.start {cwd} (both tab and pane placement), not tab.create.
Surfaces: bridge_spawn {cwd?} + auto-detect via ConnectionIdentity.resolve (peer
PID) + ProcessCwdLookup (lsof); REST POST /workers ?cwd= / body cwd; per-profile
'cwd:' config. Validated live: explicit cwd → worker rooted there; no cwd over
REST → daemon cwd, not $HOME. Also clears the ccs folder-trust prompt when the
project dir is already trusted (see docs/Worker-Startup-and-Trust.md).
47 lines
1.7 KiB
Java
47 lines
1.7 KiB
Java
package dev.ltms.bridged.mcp;
|
|
|
|
import dev.ltms.bridged.herdr.FakeHerdr;
|
|
import dev.ltms.bridged.herdr.PaneLocator;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
/** Connection → caller-identity resolution, with the OS peer-PID lookup faked. */
|
|
class ConnectionIdentityTest {
|
|
|
|
private final FakeHerdr herdr = new FakeHerdr();
|
|
|
|
private ConnectionIdentity with(PeerPidLookup pids) {
|
|
return new ConnectionIdentity(new PaneLocator(herdr), pids);
|
|
}
|
|
|
|
@Test
|
|
void resolvesWorkerFromLoopbackPeerPid() {
|
|
assertEquals("term_a", with(_ -> FakeHerdr.WORKER_PID).callerTerminal("127.0.0.1", 55555));
|
|
}
|
|
|
|
@Test
|
|
void nullForOffHostCaller() {
|
|
// A non-loopback peer can't be an on-host worker → treat as primary/unknown.
|
|
assertNull(with(_ -> FakeHerdr.WORKER_PID).callerTerminal("10.0.0.9", 55555));
|
|
}
|
|
|
|
@Test
|
|
void nullWhenPidOwnsNoPane() {
|
|
// e.g. the primary — its PID maps to no worker pane.
|
|
assertNull(with(_ -> 999_999).callerTerminal("127.0.0.1", 55555));
|
|
}
|
|
|
|
@Test
|
|
void resolvesTheCallersPidAndCwd() {
|
|
// CB-112: the primary maps to no pane, but its PID and cwd are still readable.
|
|
ConnectionIdentity id = new ConnectionIdentity(
|
|
new PaneLocator(herdr), _ -> 999_999, pid -> pid == 999_999 ? "/main/project" : null);
|
|
ConnectionIdentity.Caller c = id.resolve("127.0.0.1", 55555);
|
|
assertNull(c.terminal(), "the primary owns no worker pane");
|
|
assertEquals(999_999, c.pid());
|
|
assertEquals("/main/project", id.cwdForPid(c.pid()), "the primary's cwd is resolvable from its PID");
|
|
assertNull(id.cwdForPid(-1), "no cwd for an unresolved PID");
|
|
}
|
|
}
|