feat(studio): integrate project MCP setup and lifecycle
This commit is contained in:
@@ -15,38 +15,34 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class McpConnectionGuideTest {
|
||||
@TempDir Path root;
|
||||
@Test void exportsLiveProjectDescriptorWithoutGrantAndTracksRestartWithoutRetainingSecrets() throws Exception {
|
||||
@Test void preparationIsStableAndSeparateFromAuthority() throws Exception {
|
||||
var mapper = new ObjectMapper(); var projects = new ProjectAccessRegistry();
|
||||
try (var workers = Executors.newSingleThreadExecutor();
|
||||
var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of()))) {
|
||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(workers));
|
||||
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
||||
var guide = new McpConnectionGuide(server, projects, mapper);
|
||||
assertTrue(guide.endpoint().isEmpty());
|
||||
assertThrows(IllegalStateException.class, () -> guide.configuration(root));
|
||||
var notifications = new AtomicInteger();
|
||||
var subscription = guide.subscribe(notifications::incrementAndGet);
|
||||
server.start(); assertEquals(2, notifications.get());
|
||||
var descriptor = mapper.readTree(guide.configuration(root));
|
||||
assertEquals(server.connection().endpoint().toString(), descriptor.path("url").asText());
|
||||
assertEquals(root.toRealPath().toString(), descriptor.path("projectRoot").asText());
|
||||
// Do not put bearer credentials into assertion diagnostics.
|
||||
assertTrue(server.connection().authorizationHeader().equals(descriptor.path("headers").path("Authorization").asText()));
|
||||
assertFalse(guide.toString().contains(descriptor.path("headers").path("Authorization").asText()));
|
||||
var prepared = new AtomicInteger();
|
||||
var canonical = root.toRealPath();
|
||||
var guide = new McpConnectionGuide(server, projects, mapper, project -> {
|
||||
assertEquals(canonical, project); prepared.incrementAndGet();
|
||||
return new AgentIntegrationPreparation.Result(true, "Prepared; trust/reload once.");
|
||||
});
|
||||
assertEquals(AgentConnectionGuide.State.UNAVAILABLE, guide.state(root));
|
||||
var stable = guide.configuration(root);
|
||||
assertTrue(guide.prepare(root).ready()); assertEquals(1, prepared.get());
|
||||
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
||||
assertNull(authority.snapshot().task());
|
||||
server.start();
|
||||
assertEquals(AgentConnectionGuide.State.WAITING_FOR_ACCESS, guide.state(root));
|
||||
assertFalse(stable.contains("Bearer"));
|
||||
for (var instruction : List.of("studio_project_context", "studio_reference_read", "studio_control_acquire", "studio_control_release",
|
||||
"studio_language_query", "studio_build_start", "clientRequestId", "read-only", "restart", "native file writes"))
|
||||
assertTrue(descriptor.path("instructions").asText().contains(instruction));
|
||||
var old = server.connection(); server.close(); assertEquals(3, notifications.get()); assertTrue(guide.endpoint().isEmpty());
|
||||
server.start(); assertEquals(4, notifications.get());
|
||||
var fresh = mapper.readTree(guide.configuration(root));
|
||||
assertTrue(fresh.path("headers").path("Authorization").asText().equals(server.connection().authorizationHeader()));
|
||||
assertFalse(fresh.path("headers").path("Authorization").asText().equals(old.authorizationHeader()));
|
||||
assertTrue(stable.contains(instruction));
|
||||
server.close(); server.start(); assertEquals(stable, guide.configuration(root));
|
||||
assertThrows(AutomationException.class, () -> guide.configuration(root.resolve("unopened")));
|
||||
authority.closeAsync().toCompletableFuture().join();
|
||||
assertThrows(AutomationException.class, () -> guide.configuration(root));
|
||||
registration.close(); subscription.close(); server.close(); assertEquals(4, notifications.get());
|
||||
registration.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user