feat(studio): integrate project MCP setup and lifecycle
Intrepid/Prometeu/Studio/pipeline/pr-master This commit looks good
Test / Build skipped: 15, passed: 926
Intrepid/Prometeu/Studio/pipeline/head This commit looks good

This commit is contained in:
2026-09-29 19:24:28 +01:00
parent 97cf5e1919
commit d0737df0ac
48 changed files with 2048 additions and 225 deletions
@@ -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();
}
}
}