Launch the JavaFX 2 project shell on Java 25 with an interactive viewport, managed Play lifecycle and project mutation guards. Preserve headless/MCP and save compatibility, and qualify exact runtime executable bundles. Separate unit JaCoCo gates from opt-in integration suites and use the internal Pong fixture for the headless visual pilot. Move maintenance and native conformance tools into tooling; retain the VS Code extension and update current navigation links. Validation: tooling make verify passed, including 1064 Studio unit tests, JaCoCo thresholds and 22 headless integration tests.
163 lines
13 KiB
Java
163 lines
13 KiB
Java
package p.studio.app.mcp;
|
|
|
|
import com.fasterxml.jackson.databind.*;
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.api.io.TempDir;
|
|
import p.studio.app.compiler.*;
|
|
import p.studio.app.lsp.*;
|
|
import p.studio.app.operation.ExecutorOperationExecutor;
|
|
import p.studio.core.project.*;
|
|
import p.studio.core.session.*;
|
|
import p.studio.core.language.*;
|
|
import p.studio.core.shipper.*;
|
|
import p.studio.lsp.services.LspServerLifecycleImpl;
|
|
import p.studio.ui.javafx.workspaces.dev.DevWorkspaceProjection;
|
|
import java.net.http.*;
|
|
import java.nio.file.*;
|
|
import java.util.*;
|
|
import java.util.concurrent.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
/** Frozen sources, production compiler/packer/LSP, authenticated loopback MCP. No runtime execution. */
|
|
@org.junit.jupiter.api.Tag("integration")
|
|
class StructuredDiagnosticsIntegrationTest {
|
|
@TempDir Path temporary;
|
|
final ObjectMapper json = new ObjectMapper();
|
|
@Test void frozenCorrectedCorpusAndControlsKeepFactsRevisionsAndCanonicalViews() throws Exception {
|
|
byte[] corpus = getClass().getResourceAsStream("/diagnostics/cases.json").readAllBytes();
|
|
assertEquals("0ad291942af21e990f5cae3348a5be368dee865aa2843ba0d0effd1a9136cb87", sha(corpus));
|
|
var required = Set.of("F1-direct", "F1-two-calls", "F1-service-this", "F3-function", "F3-global", "F3-service", "F4-same-dependency", "F4-same-direct");
|
|
var reports = json.createArrayNode();
|
|
for (var example : json.readTree(corpus).path("cases")) {
|
|
String name = example.path("id").asText();
|
|
if (!required.contains(name) && !name.equals("F1-local") && !name.equals("F3-file-private")) continue;
|
|
Path root = Files.createDirectory(temporary.resolve(name)).toRealPath();
|
|
var files = example.path("files").fields();
|
|
while (files.hasNext()) {
|
|
var file = files.next(); var path = root.resolve(file.getKey());
|
|
Files.createDirectories(path.getParent()); Files.writeString(path, file.getValue().asText());
|
|
}
|
|
Path source = root.resolve("src/main.pbs");
|
|
assertEquals(example.path("files").path("src/main.pbs").asText(), Files.readString(source));
|
|
var access = new ProjectAccessRegistry();
|
|
var catalog = new ProjectCatalogService(temporary, json, new ProjectLocalStudioSetupStore(json));
|
|
var project = catalog.openProject(root);
|
|
var lifecycle = new LspServerLifecycleImpl(); var lsp = new LspLifecycleAdapter(lifecycle);
|
|
try (var workers = Executors.newCachedThreadPool(); var packer = p.packer.Packer.bootstrap(json, ignored -> {})) {
|
|
var operations = new ExecutorOperationExecutor(workers);
|
|
var session = new DefaultAutomationSession(root, operations);
|
|
var registration = access.register(root, session::enterManual, () -> !session.snapshot().closed(), session);
|
|
lsp.boot(project);
|
|
try {
|
|
var shipper = new StudioShipperService(new CompilerBuildGatewayAdapter(), packer.workspaceService(), json, operations, access);
|
|
var tasks = new DefaultTaskTools(access, catalog, shipper, Optional.empty());
|
|
var language = new TaskLanguageQueries(access, new AutomationLspQueries(lifecycle, catalog, new CompilerProjectKnowledge(access, catalog, json), json));
|
|
var handlers = new LinkedHashMap<>(McpTaskTools.handlers(tasks, json, false)); handlers.putAll(McpLanguageTools.handlers(language, json));
|
|
try (var server = new LocalMcpServer(json, new McpToolRegistry(new McpToolCatalog(json), json, handlers)); var client = HttpClient.newHttpClient()) {
|
|
server.start(); var credential = server.credentials().prepare(root); credential.activate();
|
|
String authorization = "Bearer " + credential.secret();
|
|
var init = json.createObjectNode().put("jsonrpc", "2.0").put("id", "init").put("method", "initialize");
|
|
var params = init.putObject("params").put("protocolVersion", "2025-06-18"); params.putObject("capabilities");
|
|
params.putObject("clientInfo").put("name", "diagnostic-qualification").put("version", "1");
|
|
String connection = post(client, server, authorization, null, init).headers().firstValue("Mcp-Session-Id").orElseThrow();
|
|
post(client, server, authorization, connection, json.createObjectNode().put("jsonrpc", "2.0").put("method", "notifications/initialized"));
|
|
assertTrue(session.grant(false).toCompletableFuture().join().success());
|
|
var args = json.createObjectNode().put("projectRoot", root.toString());
|
|
String task = call(client, server, authorization, connection, "studio_control_acquire", args).path("taskId").asText(); args.put("taskId", task);
|
|
var request = args.deepCopy().put("operation", "diagnostics"); request.putObject("parameters").put("uri", source.toUri().toString());
|
|
var query = call(client, server, authorization, connection, "studio_language_query", request);
|
|
var analysis = query.path("analysis"); assertFalse(analysis.path("analysisId").asText().isBlank(), query.toString());
|
|
assertEquals(sha(Files.readAllBytes(source)), query.path("context").path("document").path("sha256").asText());
|
|
assertEquals(analysis.path("analysisId"), query.path("context").path("analysisId"));
|
|
assertTrue(analysis.path("inputs").size() > 0);
|
|
for (var standard : query.path("result")) {
|
|
var detail = standard.path("data").path("prometeu");
|
|
assertEquals(analysis.path("analysisId"), detail.path("analysisId"));
|
|
assertTrue(detail.path("issueId").asText().startsWith(analysis.path("analysisId").asText() + ":"));
|
|
}
|
|
var buildArgs = args.deepCopy().put("clientRequestId", name);
|
|
var receipt = call(client, server, authorization, connection, "studio_build_start", buildArgs);
|
|
JsonNode operation; long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(20);
|
|
do {
|
|
operation = call(client, server, authorization, connection, "studio_operation_get", buildArgs);
|
|
if (operation.path("workerTerminated").asBoolean()) break;
|
|
Thread.sleep(5);
|
|
} while (System.nanoTime() < deadline);
|
|
assertTrue(operation.path("workerTerminated").asBoolean(), operation.toString());
|
|
assertEquals(receipt.path("operationId"), operation.path("operationId"));
|
|
var build = operation.path("result");
|
|
assertEquals(operation.path("operationId"), build.path("context").path("operationId"));
|
|
assertEquals(task, build.path("context").path("taskId").asText());
|
|
var ui = json.readTree(json.writeValueAsString(DevWorkspaceProjection.from(session.snapshot()).diagnosticResult()));
|
|
for (var key : List.of("issues", "summary", "context")) assertEquals(build.path(key), ui.path(key), name + " UI/MCP " + key);
|
|
if (name.equals("F3-file-private")) {
|
|
assertEquals("FAILED", build.path("status").asText(), build.toString());
|
|
assertTrue(build.path("buildId").isNull());
|
|
assertExplained(name, build.path("issues")); assertExplained(name, analysis.path("issues"));
|
|
assertNotEquals("passed", build.path("summary").path("validationStatus").asText());
|
|
} else {
|
|
assertEquals("SUCCESS", build.path("status").asText(), build.toString());
|
|
assertEquals("passed", build.path("summary").path("validationStatus").asText());
|
|
assertEquals("passed", analysis.path("summary").path("validationStatus").asText());
|
|
}
|
|
reports.addObject().put("case", name).put("primaryDocumentSha256", sha(Files.readAllBytes(source))).put("frozenProjectSourceSha256", example.path("sourceSha256").asText())
|
|
.set("language", query);
|
|
var reportCase = (ObjectNode)reports.get(reports.size()-1);
|
|
reportCase.set("operation", operation);
|
|
reportCase.put("harnessConfiguration", "Existing Studio cartridge app_id adoption; frozen PBS/barrel sources unchanged");
|
|
var originalFiles = example.path("files").fields();
|
|
while (originalFiles.hasNext()) {
|
|
var original = originalFiles.next();
|
|
if (original.getKey().endsWith(".pbs") || original.getKey().endsWith(".barrel"))
|
|
assertEquals(original.getValue().asText(), Files.readString(root.resolve(original.getKey())), name + original.getKey());
|
|
}
|
|
var artifacts = reportCase.putArray("artifactProvenance");
|
|
if (Files.isDirectory(root.resolve("build"))) try (var paths = Files.walk(root.resolve("build"))) {
|
|
for (var artifact : paths.filter(Files::isRegularFile).sorted().toList())
|
|
artifacts.addObject().put("path", root.relativize(artifact).toString()).put("sha256", sha(Files.readAllBytes(artifact)));
|
|
}
|
|
if (name.equals("F1-local")) {
|
|
var empty = source.resolveSibling("empty.pbs"); Files.writeString(empty, "");
|
|
var emptyRequest = args.deepCopy().put("operation", "diagnostics"); emptyRequest.putObject("parameters").put("uri", empty.toUri().toString());
|
|
var emptyReply = call(client, server, authorization, connection, "studio_language_query", emptyRequest);
|
|
assertTrue(emptyReply.path("analysis").path("issues").isEmpty(), emptyReply.toString());
|
|
assertEquals("passed", emptyReply.path("analysis").path("summary").path("validationStatus").asText());
|
|
assertEquals(sha(new byte[0]), emptyReply.path("context").path("document").path("sha256").asText());
|
|
reportCase.set("validEmptyDocumentControl", emptyReply);
|
|
}
|
|
call(client, server, authorization, connection, "studio_control_release", args);
|
|
}
|
|
} finally { session.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.unsubscribe(); lsp.shutdown(project); }
|
|
}
|
|
}
|
|
assertEquals(10, reports.size());
|
|
var report = Path.of("build/diagnostic-qualification/frozen-corpus.json"); Files.createDirectories(report.getParent());
|
|
json.writerWithDefaultPrettyPrinter().writeValue(report.toFile(), reports);
|
|
}
|
|
void assertExplained(String name, JsonNode issues) {
|
|
assertFalse(issues.isEmpty(), name);
|
|
boolean found = false;
|
|
for (var issue : issues) if (issue.path("checkId").asText().startsWith("pbs.")) {
|
|
assertEquals("available", issue.path("explanation").path("availability").asText(), issue.toString());
|
|
assertFalse(issue.path("semanticContext").path("facts").isEmpty(), issue.toString()); found = true;
|
|
}
|
|
assertTrue(found, name + issues);
|
|
}
|
|
JsonNode call(HttpClient client, LocalMcpServer server, String auth, String connection, String name, ObjectNode args) throws Exception {
|
|
var body = json.createObjectNode().put("jsonrpc", "2.0").put("id", UUID.randomUUID().toString()).put("method", "tools/call");
|
|
body.putObject("params").put("name", name).set("arguments", args);
|
|
var result = json.readTree(post(client, server, auth, connection, body).body()).path("result");
|
|
assertFalse(result.path("isError").asBoolean(), result.toString()); return result.path("structuredContent").path("value");
|
|
}
|
|
HttpResponse<String> post(HttpClient client, LocalMcpServer server, String auth, String connection, JsonNode body) throws Exception {
|
|
var request = HttpRequest.newBuilder(server.connection().endpoint()).timeout(java.time.Duration.ofSeconds(15))
|
|
.header("Authorization", auth).header("Content-Type", "application/json").header("Accept", "application/json, text/event-stream")
|
|
.header("MCP-Protocol-Version", "2025-06-18");
|
|
if (connection != null) request.header("Mcp-Session-Id", connection);
|
|
var response = client.send(request.POST(HttpRequest.BodyPublishers.ofString(body.toString())).build(), HttpResponse.BodyHandlers.ofString());
|
|
assertTrue(response.statusCode() == 200 || response.statusCode() == 202, response.body()); return response;
|
|
}
|
|
static String sha(byte[] bytes) throws Exception { return HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(bytes)); }
|
|
}
|