feat(studio): improve compiler reliability and AI diagnostics
Preserve structured diagnostics, source attribution, phase outcomes and revision context through compiler, Studio, LSP, MCP and JavaFX. Add project service discovery and resilient VS Code reconnection. Correct all eight reproduced PBS production failures in expression context, sibling executable bindings and nominal owner identity. Consolidate specs, lessons, immutable baseline evidence and the maintained source-to-guest qualification runner. Validation: required Gradle gate recorded 724 tests, with 711 passed and 13 skipped. Full corpus passed 168 compilation observations and 108 guest runs (104 successes and four deliberate faults); supplemental controls passed 42 compilations and 16 guest runs. TypeScript compilation, two Node discovery tests and discussion validation passed.
This commit is contained in:
@@ -8,7 +8,15 @@ import p.studio.core.shipper.CompilerBuildGateway;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import p.studio.compiler.source.diagnostics.CompilerDiagnosticProjection;
|
||||
import p.studio.compiler.source.diagnostics.SourceReference;
|
||||
import p.studio.compiler.exceptions.BuildException;
|
||||
import p.studio.api.diagnostic.StudioDiagnostic;
|
||||
import p.studio.core.shipper.CompilerBuildFailure;
|
||||
import p.studio.utilities.json.ImmutableJson;
|
||||
|
||||
public final class CompilerBuildGatewayAdapter implements CompilerBuildGateway {
|
||||
private final p.animation.GlyphBankLayoutSource layouts;
|
||||
@@ -18,12 +26,41 @@ public final class CompilerBuildGatewayAdapter implements CompilerBuildGateway {
|
||||
public CompilerBuildOutput compile(ProjectReference project, Consumer<String> logSink) {
|
||||
final var config = new BuilderPipelineConfig(false, project.rootPath().toString());
|
||||
var context=BuilderPipelineContext.fromConfig(config);context.glyphBankLayoutSource=layouts;
|
||||
var analysisId = UUID.randomUUID().toString();
|
||||
try {
|
||||
final var result = BuilderPipelineService.INSTANCE.build(
|
||||
context,
|
||||
LogAggregator.with(logSink));
|
||||
final var capabilities = new LinkedHashSet<>(
|
||||
result.compileResult().analysisSnapshot().irBackend()
|
||||
.getReservedMetadata().requiredCapabilities().asList());
|
||||
return new CompilerBuildOutput(result.bytecodeArtifactPath(), capabilities.stream().toList());
|
||||
var sources = SourceReference.snapshot(result.compileResult().analysisSnapshot().fileTable());
|
||||
var root = context.rootProjectPathCanon == null ? project.rootPath() : context.rootProjectPathCanon;
|
||||
var issues = CompilerDiagnosticProjection.issues(result.diagnostics(), sources,
|
||||
CompilerDiagnosticProjection.capturedText(context.fileTable), root, analysisId).stream().map(StudioDiagnostic::fromMap).toList();
|
||||
return new CompilerBuildOutput(result.bytecodeArtifactPath(), capabilities.stream().toList(), issues,
|
||||
inputContext(context, root, analysisId, sources));
|
||||
} catch (BuildException failure) {
|
||||
var root = context.rootProjectPathCanon == null ? project.rootPath() : context.rootProjectPathCanon;
|
||||
var issues = CompilerDiagnosticProjection.issues(failure.getDiagnostics(), failure.getSourceReferences(),
|
||||
CompilerDiagnosticProjection.capturedText(context.fileTable), root, analysisId).stream().map(StudioDiagnostic::fromMap).toList();
|
||||
var inputs = new java.util.LinkedHashMap<>(inputContext(context, root, analysisId, failure.getSourceReferences()));
|
||||
if (failure.getCause() != null) inputs.put("validationStatus", "failed");
|
||||
throw new CompilerBuildFailure(failure.getMessage(), issues, inputs, failure.hasDiagnosticPayload());
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> inputContext(BuilderPipelineContext context, java.nio.file.Path root, String analysisId,
|
||||
Map<Integer, SourceReference> sources) {
|
||||
var workspace = context.resolvedWorkspace;
|
||||
return ImmutableJson.fields("projectRoot", root.toString(), "analysisId", analysisId,
|
||||
"taskId", null, "operationId", null, "clientRequestId", null, "buildId", null, "queryId", null, "document", null,
|
||||
"inputs", CompilerDiagnosticProjection.inputs(sources, root), "inputCoverage", "compiler-inputs",
|
||||
"configuration", ImmutableJson.fields("languageId", workspace == null || workspace.frontendSpec() == null ? null : workspace.frontendSpec().getLanguageId(),
|
||||
"sdkVersion", workspace == null ? null : workspace.stdlib(), "target", workspace == null ? null : workspace.target().name(),
|
||||
"vmProfile", context.config.vmProfile(), "revisionAvailability", "not-recorded"),
|
||||
"coverage", "partial", "limitations", java.util.List.of(ImmutableJson.fields("code", "PACK_INPUT_REVISIONS_NOT_CAPTURED",
|
||||
"message", "Compiler source revisions do not identify all pack/assets inputs"),
|
||||
ImmutableJson.fields("code", "CONFIGURATION_REVISION_NOT_RECORDED", "message", "Configuration values are recorded without a manifest-byte revision")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import org.eclipse.lsp4j.services.*;
|
||||
import p.studio.api.automation.*;
|
||||
import p.studio.api.project.ProjectCatalog;
|
||||
import p.studio.core.language.LanguageQueryPort;
|
||||
import p.studio.core.language.LanguageQueryExecution;
|
||||
import p.studio.utilities.json.*;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.lsp.services.protocol.ExternalSourceLanguageServer;
|
||||
import org.eclipse.lsp4j.jsonrpc.Launcher;
|
||||
@@ -41,7 +43,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
|
||||
@Override public void endTask(TaskIdentity task) {
|
||||
items.remove(task);
|
||||
final var state = externalTasks.remove(task);
|
||||
final var state = externalTasks.get(task);
|
||||
if (state == null) return;
|
||||
final var workers = Executors.newCachedThreadPool();
|
||||
try (var socket = new Socket()) {
|
||||
@@ -60,13 +62,15 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
init.setInitializationOptions(Map.of("prometeuExternalConsumerId", state.consumer()));
|
||||
server.initialize(init).get(2, TimeUnit.SECONDS);
|
||||
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), null)).get(2, TimeUnit.SECONDS);
|
||||
externalTasks.remove(task, state);
|
||||
} finally { listening.cancel(true); }
|
||||
} catch (Exception failure) {
|
||||
// A closed project host has already released its registry. Other cleanup
|
||||
// failures are surfaced instead of silently reporting a successful task end.
|
||||
if (lifecycle.endpoint(state.binding()).isPresent())
|
||||
throw new IllegalStateException("Could not release task external sources", failure);
|
||||
} finally { workers.shutdownNow(); }
|
||||
externalTasks.remove(task, state);
|
||||
} finally { new LanguageQueryExecution("endTask", 10_000, 2_000).finishWorkers(workers); }
|
||||
}
|
||||
|
||||
private static class QuietClient implements LanguageClient {
|
||||
@@ -78,6 +82,24 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
}
|
||||
|
||||
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters) throws Exception {
|
||||
return query(task, operation, parameters, new LanguageQueryExecution(operation, 10_000, 2_000));
|
||||
}
|
||||
|
||||
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters,
|
||||
LanguageQueryExecution execution) throws Exception {
|
||||
try {
|
||||
var result = performQuery(task, operation, parameters, execution);
|
||||
if (execution.hasFailure()) throw execution.exception(AutomationFailure.Code.LANGUAGE_QUERY_CLEANUP_FAILED, "Language query cleanup failed", true);
|
||||
return result;
|
||||
} catch (IllegalArgumentException | ControlDeniedException failure) { throw failure; }
|
||||
catch (Exception failure) {
|
||||
recordFailure(execution, failure);
|
||||
throw execution.exception(AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE, "Language query failed", true);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> performQuery(TaskIdentity task, String operation, Map<String, Object> parameters,
|
||||
LanguageQueryExecution execution) throws Exception {
|
||||
if (!OPERATIONS.contains(operation)) throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "Unsupported language operation: " + operation);
|
||||
var context = knowledge.context(task.projectRoot());
|
||||
var primary = context.languages().stream().filter(ProjectKnowledge.Language::primary).findFirst().orElseThrow();
|
||||
@@ -85,7 +107,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
throw failure(AutomationFailure.Code.UNSUPPORTED_LANGUAGE, "Project language has no available LSP");
|
||||
var project = projects.openProject(context.projectRoot());
|
||||
var binding = LspLifecycleAdapter.context(project);
|
||||
var endpoint = lifecycle.endpoint(binding).orElseThrow(() -> failure(AutomationFailure.Code.INFRASTRUCTURE_FAILURE, "Project LSP is not running; reopen the project if its language changed"));
|
||||
var endpoint = lifecycle.endpoint(binding).orElseThrow(() -> failure(AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE, "Project LSP is not running; reopen the project if its language changed"));
|
||||
var params = mapper.valueToTree(parameters);
|
||||
CallHierarchyItem item = null;
|
||||
String uri = null;
|
||||
@@ -116,11 +138,14 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
}
|
||||
uri = document.toUri().toString();
|
||||
}
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
|
||||
long deadline = execution.deadlineNanos();
|
||||
if (System.nanoTime() >= deadline) throw new TimeoutException("Language query admission budget expired");
|
||||
var workers = Executors.newCachedThreadPool(r -> { var thread = new Thread(r, "studio-automation-lsp"); thread.setDaemon(true); return thread; });
|
||||
try (var socket = new Socket()) {
|
||||
if (!InetAddress.getByName(endpoint.host()).isLoopbackAddress()) throw failure(AutomationFailure.Code.INFRASTRUCTURE_FAILURE, "Project LSP endpoint is not local");
|
||||
socket.connect(new InetSocketAddress(endpoint.host(), endpoint.port()), 2000);
|
||||
execution.own(() -> { try { socket.close(); } catch (java.io.IOException ignored) {} });
|
||||
execution.own(workers::shutdownNow);
|
||||
if (!InetAddress.getByName(endpoint.host()).isLoopbackAddress()) throw failure(AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE, "Project LSP endpoint is not local");
|
||||
socket.connect(new InetSocketAddress(endpoint.host(), endpoint.port()), (int)Math.max(1, Math.min(2000, TimeUnit.NANOSECONDS.toMillis(deadline - System.nanoTime()))));
|
||||
var diagnostics = new CompletableFuture<List<Diagnostic>>();
|
||||
String expectedUri = uri;
|
||||
LanguageClient client = new LanguageClient() {
|
||||
@@ -137,6 +162,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
.setRemoteInterface(ExternalSourceLanguageServer.class).setInput(socket.getInputStream())
|
||||
.setOutput(socket.getOutputStream()).setExecutorService(workers).create();
|
||||
var listening = launcher.startListening();
|
||||
execution.own(() -> listening.cancel(true));
|
||||
final var server = launcher.getRemoteProxy();
|
||||
final var acquired = new HashSet<String>();
|
||||
boolean succeeded = false;
|
||||
@@ -144,12 +170,14 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
var initialize = new InitializeParams();
|
||||
initialize.setRootUri(binding.projectRoot().toUri().toString());
|
||||
initialize.setCapabilities(new ClientCapabilities());
|
||||
initialize.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true));
|
||||
initialize.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true,
|
||||
"prometeuDiagnosticAnalysis", Map.of("version", 1)));
|
||||
final var previous = externalTasks.get(task);
|
||||
initialize.setInitializationOptions(previous == null
|
||||
? Map.of("prometeuExternalPersistentConsumer", true)
|
||||
: Map.of("prometeuExternalConsumerId", previous.consumer(), "prometeuExternalPersistentConsumer", true));
|
||||
var capabilities = await(server.initialize(initialize), deadline).getCapabilities();
|
||||
execution.method("initialize");
|
||||
var capabilities = await(server.initialize(initialize), deadline, execution).getCapabilities();
|
||||
final var experimental = gson.toJsonTree(capabilities.getExperimental());
|
||||
if (experimental.isJsonObject() && experimental.getAsJsonObject().has("prometeuExternalConsumerId")) {
|
||||
final String consumer = experimental.getAsJsonObject().get("prometeuExternalConsumerId").getAsString();
|
||||
@@ -158,52 +186,69 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
server.initialized(new InitializedParams());
|
||||
requireCapability(operation, capabilities);
|
||||
List<Diagnostic> currentDiagnostics = List.of();
|
||||
Map<String, Object> analysis = Map.of();
|
||||
var rich = experimental.isJsonObject() ? experimental.getAsJsonObject().get("prometeuDiagnosticAnalysis") : null;
|
||||
boolean richAnalysis = rich != null && rich.isJsonObject() && rich.getAsJsonObject().has("version")
|
||||
&& rich.getAsJsonObject().get("version").getAsInt() == 1;
|
||||
String digest = source == null ? null : sha256(source);
|
||||
if (document != null) {
|
||||
// Fresh client overlay contains exactly the saved UTF-8 file. Wait for analysis before querying.
|
||||
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, primary.id(), 1, source)));
|
||||
currentDiagnostics = await(diagnostics, deadline);
|
||||
if (richAnalysis) {
|
||||
execution.method("prometeu/documentAnalysis");
|
||||
var retained = await(server.documentAnalysis(new ExternalSourceLanguageServer.DiagnosticAnalysisRequest(
|
||||
new VersionedTextDocumentIdentifier(uri, 1), digest)), deadline, execution);
|
||||
analysis = mapper.convertValue(mapper.readTree(gson.toJson(retained)), Map.class);
|
||||
}
|
||||
currentDiagnostics = await(diagnostics, deadline, execution);
|
||||
}
|
||||
Map<String, Object> externalRevision = Map.of();
|
||||
if (external) {
|
||||
final var request = new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri);
|
||||
source = await(server.revalidateExternalSource(request), deadline).text();
|
||||
var content = await(server.revalidateExternalSource(request), deadline, execution);
|
||||
source = content.text();
|
||||
externalRevision = mapper.convertValue(mapper.readTree(gson.toJson(content)), Map.class);
|
||||
externalRevision = new LinkedHashMap<>(externalRevision);
|
||||
externalRevision.remove("text");
|
||||
if (source.getBytes(java.nio.charset.StandardCharsets.UTF_8).length > 4 * 1024 * 1024)
|
||||
throw failure(AutomationFailure.Code.LIMIT_EXCEEDED, "External source exceeds 4 MiB");
|
||||
}
|
||||
execution.method(operation);
|
||||
var text = server.getTextDocumentService();
|
||||
var id = uri == null ? null : new TextDocumentIdentifier(uri);
|
||||
Object result = switch (operation) {
|
||||
case "readExternalSource" -> await(server.readExternalSource(
|
||||
new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri)), deadline);
|
||||
new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri)), deadline, execution);
|
||||
case "diagnostics" -> currentDiagnostics;
|
||||
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline);
|
||||
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline);
|
||||
case "signatureHelp" -> await(text.signatureHelp(new SignatureHelpParams(id, position(params.path("position"), source))), deadline);
|
||||
case "definition" -> await(text.definition(new DefinitionParams(id, position(params.path("position"), source))), deadline);
|
||||
case "references" -> await(text.references(new ReferenceParams(id, position(params.path("position"), source), new ReferenceContext(params.path("includeDeclaration").asBoolean(false)))), deadline);
|
||||
case "documentSymbols" -> await(text.documentSymbol(new DocumentSymbolParams(id)), deadline);
|
||||
case "workspaceSymbols" -> await(server.getWorkspaceService().symbol(new WorkspaceSymbolParams(params.path("query").asText(""))), deadline);
|
||||
case "prepareRename" -> await(text.prepareRename(new PrepareRenameParams(id, position(params.path("position"), source))), deadline);
|
||||
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "signatureHelp" -> await(text.signatureHelp(new SignatureHelpParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "definition" -> await(text.definition(new DefinitionParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "references" -> await(text.references(new ReferenceParams(id, position(params.path("position"), source), new ReferenceContext(params.path("includeDeclaration").asBoolean(false)))), deadline, execution);
|
||||
case "documentSymbols" -> await(text.documentSymbol(new DocumentSymbolParams(id)), deadline, execution);
|
||||
case "workspaceSymbols" -> await(server.getWorkspaceService().symbol(new WorkspaceSymbolParams(params.path("query").asText(""))), deadline, execution);
|
||||
case "prepareRename" -> await(text.prepareRename(new PrepareRenameParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "rename" -> {
|
||||
String name = params.path("newName").asText("");
|
||||
if (name.isBlank()) throw new IllegalArgumentException("newName is required");
|
||||
yield await(text.rename(new RenameParams(id, position(params.path("position"), source), name)), deadline);
|
||||
yield await(text.rename(new RenameParams(id, position(params.path("position"), source), name)), deadline, execution);
|
||||
}
|
||||
case "formatting" -> await(text.formatting(new DocumentFormattingParams(id, new FormattingOptions(4, true))), deadline);
|
||||
case "formatting" -> await(text.formatting(new DocumentFormattingParams(id, new FormattingOptions(4, true))), deadline, execution);
|
||||
case "codeActions" -> await(text.codeAction(new CodeActionParams(id,
|
||||
range(params.path("range"), source),
|
||||
new CodeActionContext(currentDiagnostics))), deadline);
|
||||
case "documentLinks" -> await(text.documentLink(new DocumentLinkParams(id)), deadline);
|
||||
case "foldingRanges" -> await(text.foldingRange(new FoldingRangeRequestParams(id)), deadline);
|
||||
new CodeActionContext(currentDiagnostics))), deadline, execution);
|
||||
case "documentLinks" -> await(text.documentLink(new DocumentLinkParams(id)), deadline, execution);
|
||||
case "foldingRanges" -> await(text.foldingRange(new FoldingRangeRequestParams(id)), deadline, execution);
|
||||
case "selectionRanges" -> {
|
||||
if (!params.path("positions").isArray() || params.path("positions").isEmpty()) throw new IllegalArgumentException("positions are required");
|
||||
var positions = new ArrayList<Position>();
|
||||
for (var p : params.path("positions")) positions.add(position(p, source));
|
||||
yield await(text.selectionRange(new SelectionRangeParams(id, positions)), deadline);
|
||||
yield await(text.selectionRange(new SelectionRangeParams(id, positions)), deadline, execution);
|
||||
}
|
||||
case "prepareCallHierarchy" -> await(text.prepareCallHierarchy(new CallHierarchyPrepareParams(id, position(params.path("position"), source))), deadline);
|
||||
case "incomingCalls" -> await(text.callHierarchyIncomingCalls(new CallHierarchyIncomingCallsParams(item)), deadline);
|
||||
case "outgoingCalls" -> await(text.callHierarchyOutgoingCalls(new CallHierarchyOutgoingCallsParams(item)), deadline);
|
||||
case "semanticTokens" -> await(text.semanticTokensFull(new SemanticTokensParams(id)), deadline);
|
||||
case "prepareCallHierarchy" -> await(text.prepareCallHierarchy(new CallHierarchyPrepareParams(id, position(params.path("position"), source))), deadline, execution);
|
||||
case "incomingCalls" -> await(text.callHierarchyIncomingCalls(new CallHierarchyIncomingCallsParams(item)), deadline, execution);
|
||||
case "outgoingCalls" -> await(text.callHierarchyOutgoingCalls(new CallHierarchyOutgoingCallsParams(item)), deadline, execution);
|
||||
case "semanticTokens" -> await(text.semanticTokensFull(new SemanticTokensParams(id)), deadline, execution);
|
||||
default -> throw new IllegalArgumentException("Unsupported operation");
|
||||
};
|
||||
var wire = mapper.readTree(gson.toJson(result));
|
||||
@@ -215,7 +260,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
acquired.removeAll(externalTasks.get(task).uris());
|
||||
for (String externalUri : returned) {
|
||||
await(server.retainExternalSource(new ExternalSourceLanguageServer.Request(
|
||||
externalTasks.get(task).consumer(), externalUri)), deadline);
|
||||
externalTasks.get(task).consumer(), externalUri)), deadline, execution);
|
||||
externalTasks.get(task).uris().add(externalUri);
|
||||
}
|
||||
}
|
||||
@@ -229,9 +274,23 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
if (operation.equals("prepareCallHierarchy") || operation.equals("incomingCalls") || operation.equals("outgoingCalls")) addItemIds(task, wire);
|
||||
var output = new LinkedHashMap<String, Object>();
|
||||
output.put("operation", operation); output.put("result", mapper.convertValue(wire, Object.class));
|
||||
if (document != null && !richAnalysis) {
|
||||
limitations.add("ANALYSIS_DETAILS_UNAVAILABLE");
|
||||
analysis = ImmutableJson.fields("analysisId", null, "issues", List.of(), "summary",
|
||||
DiagnosticPayloads.legacySummary("document"));
|
||||
}
|
||||
output.put("limitations", limitations);
|
||||
output.put("analysis", analysis);
|
||||
output.put("context", ImmutableJson.fields("projectRoot", context.projectRoot().toString(),
|
||||
"taskId", task.value(), "clientRequestId", null, "buildId", null, "queryId", execution.queryId(), "analysisId", analysis.get("analysisId"),
|
||||
"document", document == null ? null : ImmutableJson.fields("uri", uri, "version", 1, "sha256", digest),
|
||||
"inputs", analysis.getOrDefault("inputs", List.of()), "externalRevision", externalRevision,
|
||||
"inputCoverage", "partial", "configuration", analysis.getOrDefault("configuration", Map.of())));
|
||||
succeeded = true;
|
||||
return Collections.unmodifiableMap(output);
|
||||
} catch (Exception failure) {
|
||||
recordFailure(execution, failure);
|
||||
throw failure;
|
||||
} finally {
|
||||
if (!succeeded && !acquired.isEmpty() && externalTasks.containsKey(task)) {
|
||||
final var state = externalTasks.get(task);
|
||||
@@ -242,11 +301,39 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), acquiredUri))
|
||||
.get(500, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
} catch (Exception cleanupFailure) {
|
||||
execution.record(AutomationFailure.Code.LANGUAGE_QUERY_CLEANUP_FAILED, "Could not release query external sources", Map.of());
|
||||
} finally { if (interrupted) Thread.currentThread().interrupt(); }
|
||||
}
|
||||
listening.cancel(true);
|
||||
}
|
||||
} finally { workers.shutdownNow(); }
|
||||
} finally { execution.finishWorkers(workers); }
|
||||
}
|
||||
|
||||
private static String sha256(String text) throws java.security.NoSuchAlgorithmException {
|
||||
return HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256")
|
||||
.digest(text.getBytes(java.nio.charset.StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
private static void recordFailure(LanguageQueryExecution execution, Exception failure) {
|
||||
if (failure instanceof AutomationException domain) { execution.record(domain.failure()); return; }
|
||||
if (failure instanceof IllegalArgumentException || failure instanceof ControlDeniedException) return;
|
||||
var cause = failure instanceof ExecutionException && failure.getCause() != null ? failure.getCause() : failure;
|
||||
AutomationFailure.Code code;
|
||||
Map<String, Object> details = Map.of();
|
||||
if (cause instanceof TimeoutException || cause instanceof SocketTimeoutException) code = AutomationFailure.Code.LANGUAGE_QUERY_TIMEOUT;
|
||||
else if (cause instanceof InterruptedException || cause instanceof CancellationException) code = AutomationFailure.Code.LANGUAGE_QUERY_CANCELLED;
|
||||
else if (cause instanceof ConnectException || cause instanceof SocketException) code = AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE;
|
||||
else if (cause instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
||||
int rpc = response.getResponseError().getCode();
|
||||
details = ImmutableJson.fields("protocolCode", rpc, "reason", rpc == -32020 ? "ANALYSIS_REVISION_MISMATCH" : rpc == -32021 ? "ANALYSIS_UNAVAILABLE" : null);
|
||||
code = rpc == -32020 ? AutomationFailure.Code.LANGUAGE_QUERY_REVISION_MISMATCH
|
||||
: rpc == -32021 || rpc == -32603 ? AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE
|
||||
: AutomationFailure.Code.LANGUAGE_QUERY_PROTOCOL_FAILURE;
|
||||
} else if (cause instanceof org.eclipse.lsp4j.jsonrpc.JsonRpcException || cause instanceof com.google.gson.JsonParseException
|
||||
|| cause instanceof com.fasterxml.jackson.core.JsonProcessingException) code = AutomationFailure.Code.LANGUAGE_QUERY_PROTOCOL_FAILURE;
|
||||
else code = AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE;
|
||||
execution.record(code, "Language query failed: " + code.name(), details);
|
||||
}
|
||||
|
||||
private void rememberExternalUris(Set<String> uris, com.fasterxml.jackson.databind.JsonNode node) {
|
||||
@@ -336,7 +423,8 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
||||
if (node.isContainerNode()) for (var child : node) validateEdits(context, child);
|
||||
}
|
||||
|
||||
private static <T> T await(CompletableFuture<T> future, long deadline) throws Exception {
|
||||
private static <T> T await(CompletableFuture<T> future, long deadline, LanguageQueryExecution execution) throws Exception {
|
||||
execution.own(() -> future.cancel(true));
|
||||
try { return future.get(Math.max(1, deadline - System.nanoTime()), TimeUnit.NANOSECONDS); }
|
||||
catch (ExecutionException failure) {
|
||||
if (failure.getCause() instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
||||
|
||||
@@ -10,7 +10,9 @@ import java.util.Objects;
|
||||
|
||||
public final class LspLifecycleAdapter implements LspLifecyclePort {
|
||||
private final LspServerLifecycle lifecycle;
|
||||
private final java.util.Map<java.nio.file.Path, LspProjectContext> bindings = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
private record Binding(LspProjectContext context, String sessionId) {}
|
||||
private final com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||
private final java.util.Map<java.nio.file.Path, Binding> bindings = new java.util.concurrent.ConcurrentHashMap<>();
|
||||
|
||||
public LspLifecycleAdapter(LspServerLifecycle lifecycle) {
|
||||
this.lifecycle = Objects.requireNonNull(lifecycle, "lifecycle");
|
||||
@@ -19,15 +21,41 @@ public final class LspLifecycleAdapter implements LspLifecyclePort {
|
||||
@Override
|
||||
public void boot(ProjectReference project) {
|
||||
var binding = context(project);
|
||||
String sessionId = java.util.UUID.randomUUID().toString();
|
||||
lifecycle.bootServer(LspServerConfiguration.builder().endpoint(
|
||||
new p.studio.lsp.messages.LspServerEndpoint("127.0.0.1", 0)).build(), binding);
|
||||
bindings.put(project.rootPath().toAbsolutePath().normalize(), binding);
|
||||
try {
|
||||
var endpoint = lifecycle.endpoint(binding).orElseThrow(() -> new IllegalStateException("Project LSP endpoint unavailable"));
|
||||
var directory = java.nio.file.Files.createDirectories(binding.projectRoot().resolve(".studio"));
|
||||
var temporary = java.nio.file.Files.createTempFile(directory, "lsp-", ".tmp");
|
||||
try {
|
||||
mapper.writeValue(temporary.toFile(), java.util.Map.of(
|
||||
"schemaVersion", 1, "projectRoot", binding.projectRoot().toString(),
|
||||
"sessionId", sessionId, "processId", ProcessHandle.current().pid(),
|
||||
"host", endpoint.host(), "port", endpoint.port()));
|
||||
java.nio.file.Files.move(temporary, directory.resolve("lsp.json"),
|
||||
java.nio.file.StandardCopyOption.ATOMIC_MOVE, java.nio.file.StandardCopyOption.REPLACE_EXISTING);
|
||||
} finally { java.nio.file.Files.deleteIfExists(temporary); }
|
||||
bindings.put(project.rootPath().toAbsolutePath().normalize(), new Binding(binding, sessionId));
|
||||
} catch (Exception failure) {
|
||||
lifecycle.shutdownServer(binding);
|
||||
throw new IllegalStateException("Failed to publish project LSP endpoint", failure);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown(ProjectReference project) {
|
||||
var binding = bindings.remove(project.rootPath().toAbsolutePath().normalize());
|
||||
if (binding != null) lifecycle.shutdownServer(binding);
|
||||
if (binding == null) return;
|
||||
try {
|
||||
var file = binding.context().projectRoot().resolve(".studio/lsp.json");
|
||||
if (java.nio.file.Files.exists(file)
|
||||
&& binding.sessionId().equals(mapper.readTree(file.toFile()).path("sessionId").asText())) {
|
||||
java.nio.file.Files.deleteIfExists(file);
|
||||
}
|
||||
} catch (java.io.IOException failure) {
|
||||
throw new IllegalStateException("Failed to remove project LSP discovery", failure);
|
||||
} finally { lifecycle.shutdownServer(binding.context()); }
|
||||
}
|
||||
|
||||
static LspProjectContext context(ProjectReference project) {
|
||||
|
||||
@@ -89,6 +89,7 @@ public final class McpTaskTools {
|
||||
result.put("manifestPath", build.manifestPath() == null ? null : build.manifestPath().toString());
|
||||
result.set("emittedArtifacts", mapper.valueToTree(build.emittedArtifacts().stream().map(Path::toString).toList()));
|
||||
result.set("diagnostics", mapper.valueToTree(build.diagnostics()));
|
||||
build.diagnosticView().forEach((key, item) -> result.set(key, mapper.valueToTree(item)));
|
||||
var logs = result.putArray("logs");
|
||||
build.logs().forEach(log -> logs.addObject().put("source", log.source().name()).put("severity", log.severity().name())
|
||||
.put("message", log.message()).put("timestamp", log.timestamp().toString()));
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
final FutureTask<Void> submitted = new FutureTask<>(() -> {
|
||||
try {
|
||||
final R result = operation.call();
|
||||
if (transitionTerminal(OperationState.SUCCEEDED, summary)) {
|
||||
if (transitionTerminal(cancelledResult(result) ? OperationState.CANCELLED : OperationState.SUCCEEDED, summary)) {
|
||||
completion.complete(result);
|
||||
}
|
||||
} catch (Throwable failure) {
|
||||
@@ -84,6 +84,11 @@ public final class ExecutorOperationExecutor implements OperationExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean cancelledResult(Object result) {
|
||||
return result instanceof p.studio.api.automation.AutomationOutcome outcome && outcome.kind() == p.studio.api.automation.AutomationOutcome.Kind.CANCELLED
|
||||
|| result instanceof p.studio.api.shipper.ShipperPrepareResult build && build.status() == p.studio.api.shipper.ShipperPreparationStatus.CANCELLED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OperationId id() {
|
||||
return id;
|
||||
|
||||
@@ -57,6 +57,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -169,6 +174,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -260,6 +270,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -351,6 +366,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -383,7 +403,7 @@
|
||||
{
|
||||
"name": "studio_language_query",
|
||||
"authority": "task",
|
||||
"description": "Query project LSP capabilities using saved project files or task-owned read-only external sources. readExternalSource reads an external URI returned by definition; hover and definition can continue inside it. Returns refactoring proposals, never applies edits.",
|
||||
"description": "Query project LSP capabilities using saved project files or task-owned read-only external sources. readExternalSource reads an external URI returned by definition; hover and definition can continue inside it. Returns refactoring proposals, never applies edits. Adds analysis and context from the retained didOpen analysis negotiated with prometeuDiagnosticAnalysis v1. Includes saved-source SHA-256 and queryId. 10000 ms execution from admission plus 2000 ms cleanup; language failures use LANGUAGE_QUERY_* or LANGUAGE_SERVER_UNAVAILABLE. Capability fallback is limited with ANALYSIS_DETAILS_UNAVAILABLE. Never infer validity from an empty standard diagnostic array.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -530,7 +550,29 @@
|
||||
"const": "ok"
|
||||
},
|
||||
"value": {
|
||||
"type": "object"
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"analysis": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"issues": {
|
||||
"type": "array",
|
||||
"description": "Canonical immutable issues, at most 1024 whole issues and 1 MiB UTF-8 JSON. Explicit LIMIT_EXCEEDED with original counts when partial.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"description": "issueId, producer, original code/codeOrigin, templateId/templateParameters, checkId, severity, phase/stageId/failureKind, message, facts, explanation, semanticContext, origin, related, suggestedChecks, limitations."
|
||||
}
|
||||
},
|
||||
"summary": {
|
||||
"type": "object",
|
||||
"description": "scope=document|project|build; validationStatus=passed|rejected|failed|incomplete|not-evaluated|cancelled; nullable counts, stages and independent detail/revision coverage."
|
||||
}
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -558,6 +600,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -592,9 +639,110 @@
|
||||
}
|
||||
},
|
||||
"exampleValue": {
|
||||
"operation": "definition",
|
||||
"operation": "diagnostics",
|
||||
"result": [],
|
||||
"limitations": []
|
||||
"limitations": [],
|
||||
"analysis": {
|
||||
"analysisId": "analysis-example",
|
||||
"issues": [
|
||||
{
|
||||
"issueId": "analysis-example:0",
|
||||
"producer": {
|
||||
"component": "compiler-frontend",
|
||||
"owner": "compiler/pbs",
|
||||
"languageId": "pbs"
|
||||
},
|
||||
"code": "E_SEM_UNSUPPORTED_LOWERING",
|
||||
"codeOrigin": "producer",
|
||||
"templateId": "E_SEM_UNSUPPORTED_LOWERING",
|
||||
"templateParameters": {},
|
||||
"checkId": "pbs.lowering.call-resolution",
|
||||
"severity": "ERROR",
|
||||
"phase": "semantics",
|
||||
"stageId": "frontend",
|
||||
"failureKind": "program-rejection",
|
||||
"message": "Recorded callable could not be resolved",
|
||||
"facts": {},
|
||||
"explanation": {
|
||||
"id": "pbs.lowering.call-resolution",
|
||||
"summary": "Executable call lowering must identify an admitted callable using the actual resolution constraints.",
|
||||
"rule": "Executable call lowering must identify an admitted callable using the actual resolution constraints.",
|
||||
"availability": "available"
|
||||
},
|
||||
"semanticContext": {
|
||||
"availability": "partial",
|
||||
"facts": {
|
||||
"requestedSymbol": {
|
||||
"value": "data.value",
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"resolutionConstraints": {
|
||||
"value": "bool",
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"declaredTypes": {
|
||||
"value": [
|
||||
"int"
|
||||
],
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"expressionTypes": {
|
||||
"value": null,
|
||||
"availability": "not-recorded",
|
||||
"reason": "Not recorded by this detector"
|
||||
}
|
||||
}
|
||||
},
|
||||
"origin": {
|
||||
"uri": null,
|
||||
"span": null,
|
||||
"range": null,
|
||||
"availability": "unavailable"
|
||||
},
|
||||
"related": [],
|
||||
"suggestedChecks": [],
|
||||
"limitations": []
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"scope": "project",
|
||||
"validationStatus": "rejected",
|
||||
"counts": {
|
||||
"errors": 1,
|
||||
"warnings": 0,
|
||||
"infos": 0
|
||||
},
|
||||
"stages": [
|
||||
{
|
||||
"stageId": "analysis",
|
||||
"status": "rejected"
|
||||
}
|
||||
],
|
||||
"coverage": {
|
||||
"details": "complete",
|
||||
"revisions": "partial",
|
||||
"limitations": []
|
||||
}
|
||||
},
|
||||
"inputs": []
|
||||
},
|
||||
"context": {
|
||||
"projectRoot": "/projects/game",
|
||||
"taskId": "task-example",
|
||||
"queryId": "query-example",
|
||||
"analysisId": "analysis-example",
|
||||
"clientRequestId": null,
|
||||
"buildId": null,
|
||||
"document": {
|
||||
"uri": "file:///projects/game/src/main.pbs",
|
||||
"version": 1,
|
||||
"sha256": "0000000000000000000000000000000000000000000000000000000000000000"
|
||||
},
|
||||
"inputCoverage": "partial"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -664,6 +812,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -797,6 +950,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -900,6 +1058,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -991,6 +1154,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1082,6 +1250,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1182,6 +1355,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1273,6 +1451,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1374,6 +1557,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1537,6 +1725,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1643,6 +1836,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1679,7 +1877,7 @@
|
||||
{
|
||||
"name": "studio_operation_get",
|
||||
"authority": "task",
|
||||
"description": "Read a task-local operation by exactly one of operationId or clientRequestId, including known progress, typed result and image.",
|
||||
"description": "Read a task-local operation by exactly one of operationId or clientRequestId, including known progress, typed result and image. Worker completion (SUCCEEDED) is independent of build approval. Build result adds canonical issues, summary and context; usable buildId requires SUCCESS with all four stages passed. Cancellation remains CANCELLED; final results require workerTerminated.",
|
||||
"inputSchema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -1740,7 +1938,37 @@
|
||||
"const": "ok"
|
||||
},
|
||||
"value": {
|
||||
"type": "object"
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"result": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "null"
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"issues": {
|
||||
"type": "array",
|
||||
"description": "Canonical immutable issues, at most 1024 whole issues and 1 MiB UTF-8 JSON. Explicit LIMIT_EXCEEDED with original counts when partial.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"description": "issueId, producer, original code/codeOrigin, templateId/templateParameters, checkId, severity, phase/stageId/failureKind, message, facts, explanation, semanticContext, origin, related, suggestedChecks, limitations."
|
||||
}
|
||||
},
|
||||
"summary": {
|
||||
"type": "object",
|
||||
"description": "scope=document|project|build; validationStatus=passed|rejected|failed|incomplete|not-evaluated|cancelled; nullable counts, stages and independent detail/revision coverage."
|
||||
},
|
||||
"context": {
|
||||
"type": "object",
|
||||
"description": "projectRoot/taskId/operationId/clientRequestId/analysisId/buildId and actual-read input revisions; pack/assets coverage is explicit."
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1768,6 +1996,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1795,14 +2028,133 @@
|
||||
"operationId": "operation-advance"
|
||||
},
|
||||
"exampleValue": {
|
||||
"operationId": "operation-advance",
|
||||
"clientRequestId": "advance-example",
|
||||
"state": "RUNNING",
|
||||
"operationId": "operation-build",
|
||||
"clientRequestId": "build-example",
|
||||
"state": "SUCCEEDED",
|
||||
"workerTerminated": true,
|
||||
"progress": {
|
||||
"requestedFrames": 60,
|
||||
"completedFrames": 12
|
||||
"requestedFrames": null,
|
||||
"completedFrames": null
|
||||
},
|
||||
"result": null
|
||||
"failure": null,
|
||||
"result": {
|
||||
"kind": "build",
|
||||
"status": "FAILED",
|
||||
"buildId": null,
|
||||
"manifestPath": null,
|
||||
"emittedArtifacts": [],
|
||||
"diagnostics": [
|
||||
"Recorded callable could not be resolved"
|
||||
],
|
||||
"logs": [],
|
||||
"issues": [
|
||||
{
|
||||
"issueId": "analysis-example:0",
|
||||
"producer": {
|
||||
"component": "compiler-frontend",
|
||||
"owner": "compiler/pbs",
|
||||
"languageId": "pbs"
|
||||
},
|
||||
"code": "E_SEM_UNSUPPORTED_LOWERING",
|
||||
"codeOrigin": "producer",
|
||||
"templateId": "E_SEM_UNSUPPORTED_LOWERING",
|
||||
"templateParameters": {},
|
||||
"checkId": "pbs.lowering.call-resolution",
|
||||
"severity": "ERROR",
|
||||
"phase": "semantics",
|
||||
"stageId": "frontend",
|
||||
"failureKind": "program-rejection",
|
||||
"message": "Recorded callable could not be resolved",
|
||||
"facts": {},
|
||||
"explanation": {
|
||||
"id": "pbs.lowering.call-resolution",
|
||||
"summary": "Executable call lowering must identify an admitted callable using the actual resolution constraints.",
|
||||
"rule": "Executable call lowering must identify an admitted callable using the actual resolution constraints.",
|
||||
"availability": "available"
|
||||
},
|
||||
"semanticContext": {
|
||||
"availability": "partial",
|
||||
"facts": {
|
||||
"requestedSymbol": {
|
||||
"value": "data.value",
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"resolutionConstraints": {
|
||||
"value": "bool",
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"declaredTypes": {
|
||||
"value": [
|
||||
"int"
|
||||
],
|
||||
"availability": "available",
|
||||
"reason": null
|
||||
},
|
||||
"expressionTypes": {
|
||||
"value": null,
|
||||
"availability": "not-recorded",
|
||||
"reason": "Not recorded by this detector"
|
||||
}
|
||||
}
|
||||
},
|
||||
"origin": {
|
||||
"uri": null,
|
||||
"span": null,
|
||||
"range": null,
|
||||
"availability": "unavailable"
|
||||
},
|
||||
"related": [],
|
||||
"suggestedChecks": [],
|
||||
"limitations": []
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"scope": "build",
|
||||
"validationStatus": "rejected",
|
||||
"counts": {
|
||||
"errors": 1,
|
||||
"warnings": 0,
|
||||
"infos": 0
|
||||
},
|
||||
"stages": [
|
||||
{
|
||||
"stageId": "compiler-build",
|
||||
"status": "rejected"
|
||||
},
|
||||
{
|
||||
"stageId": "pack-validation",
|
||||
"status": "not-run"
|
||||
},
|
||||
{
|
||||
"stageId": "pack",
|
||||
"status": "not-run"
|
||||
},
|
||||
{
|
||||
"stageId": "manifest",
|
||||
"status": "not-run"
|
||||
}
|
||||
],
|
||||
"coverage": {
|
||||
"details": "complete",
|
||||
"revisions": "partial",
|
||||
"limitations": []
|
||||
}
|
||||
},
|
||||
"context": {
|
||||
"projectRoot": "/projects/game",
|
||||
"taskId": "task-example",
|
||||
"operationId": "operation-build",
|
||||
"clientRequestId": "build-example",
|
||||
"analysisId": "analysis-example",
|
||||
"buildId": null,
|
||||
"queryId": null,
|
||||
"document": null,
|
||||
"inputs": [],
|
||||
"coverage": "partial"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -1872,6 +2224,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -1965,6 +2322,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2075,6 +2437,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2168,6 +2535,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2259,6 +2631,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2350,6 +2727,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -2801,6 +3183,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -3279,6 +3666,11 @@
|
||||
"runtimeError": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
},
|
||||
"details": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"description": "Neutral component/operation/method/queryId, budgets, cleanup and workerTerminated; runtimeError remains native-runtime-only."
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -113,6 +113,47 @@ class DevDesktopTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test void explainedDiagnosticPaneExpandsFactsAndOpensCurrentReadOnlySource() throws Exception {
|
||||
var source = root.resolve("main.pbs"); Files.writeString(source, "fn x() {}\n");
|
||||
var digest = java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(Files.readAllBytes(source)));
|
||||
var value = new java.util.LinkedHashMap<>(p.studio.utilities.json.DiagnosticPayloads.issue("TEST_EXPLAINED", "ERROR", "Recorded detector failure"));
|
||||
value.put("checkId", "compiler.verify.ret-stack-height");
|
||||
value.put("explanation", java.util.Map.of("availability", "available", "summary", "RET must match the declared result slot count."));
|
||||
value.put("facts", java.util.Map.of("expectedHeight", 0, "actualHeight", 1));
|
||||
value.put("origin", java.util.Map.of("uri", source.toUri().toString(), "revision", digest, "range", java.util.Map.of("start", java.util.Map.of("line", 0, "character", 3), "end", java.util.Map.of("line", 0, "character", 4))));
|
||||
var pane = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane[1]; var window = new Stage[1];
|
||||
try {
|
||||
fx(() -> {
|
||||
pane[0] = new p.studio.ui.javafx.diagnostics.DiagnosticResultsPane(root);
|
||||
var view = p.studio.utilities.json.DiagnosticPayloads.view(java.util.List.of(value), "build", "failed", java.util.List.of(), "partial");
|
||||
pane[0].show(java.util.Map.of("issues", view.issues(), "summary", view.summary(), "context", java.util.Map.of()));
|
||||
window[0] = new Stage(); window[0].setTitle("Explained diagnostics desktop qualification");
|
||||
var scroll = new ScrollPane(pane[0]); scroll.setFitToWidth(true);
|
||||
window[0].setScene(new Scene(scroll, 1050, 900)); window[0].show();
|
||||
pane[0].getChildren().stream().filter(n -> n instanceof TitledPane).map(n -> (TitledPane)n).findFirst().orElseThrow().setExpanded(true); pane[0].applyCss(); pane[0].layout();
|
||||
var body = (VBox)pane[0].getChildren().stream().filter(n -> n instanceof TitledPane).map(n -> (TitledPane)n).findFirst().orElseThrow().getContent();
|
||||
assertTrue(body.getChildren().stream().filter(n -> n instanceof Label).anyMatch(n -> ((Label)n).getText().contains("RET")));
|
||||
body.getChildren().stream().filter(n -> n instanceof TitledPane && ((TitledPane)n).getText().equals("facts")).map(n -> (TitledPane)n).forEach(n -> n.setExpanded(true));
|
||||
pane[0].applyCss(); pane[0].layout();
|
||||
var image = window[0].getScene().snapshot(null); var pixels = image.getPixelReader();
|
||||
var buffer = new java.awt.image.BufferedImage((int)image.getWidth(), (int)image.getHeight(), java.awt.image.BufferedImage.TYPE_INT_ARGB);
|
||||
for (int y=0; y<buffer.getHeight(); y++) for (int x=0; x<buffer.getWidth(); x++) buffer.setRGB(x,y,pixels.getArgb(x,y));
|
||||
try { var path = Path.of("build/diagnostic-qualification/diagnostic-desktop.png"); Files.createDirectories(path.getParent()); javax.imageio.ImageIO.write(buffer,"png",path.toFile()); }
|
||||
catch (Exception error) { throw new RuntimeException(error); }
|
||||
body.getChildren().stream().filter(n -> n instanceof Button && ((Button)n).getText().equals("Open source")).map(n -> (Button)n).findFirst().orElseThrow().fire();
|
||||
});
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5); var opened = new java.util.concurrent.atomic.AtomicBoolean();
|
||||
while (!opened.get() && System.nanoTime() < deadline) {
|
||||
fx(() -> { for (var visible : javafx.stage.Window.getWindows()) if (visible instanceof Stage stage && stage.getTitle().startsWith("Current source")) {
|
||||
var viewer = (TextArea)((VBox)stage.getScene().getRoot()).getChildren().get(1);
|
||||
assertFalse(viewer.isEditable()); assertEquals("x", viewer.getSelectedText()); opened.set(true);
|
||||
} });
|
||||
if (!opened.get()) Thread.sleep(10);
|
||||
}
|
||||
assertTrue(opened.get(), "Source viewer opened with verified revision and selection");
|
||||
} finally { fx(() -> { for (var visible : java.util.List.copyOf(javafx.stage.Window.getWindows())) visible.hide(); }); }
|
||||
}
|
||||
|
||||
@Test void formsSaveFailurePreservesDraftAndReturnReadsExternalContent() throws Exception {
|
||||
var file = root.resolve("document.txt"); Files.writeString(file, "initial");
|
||||
fx(() -> {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package p.studio.app.compiler.fixture;
|
||||
|
||||
import p.studio.compiler.models.FrontendSpec;
|
||||
import p.studio.compiler.services.FrontendPhaseService;
|
||||
import p.studio.compiler.services.FrontendProvider;
|
||||
import p.studio.utilities.structures.ReadOnlySet;
|
||||
|
||||
public final class ControlledIrFrontend implements FrontendProvider {
|
||||
public static final String LANGUAGE_ID = "controlled-ir";
|
||||
|
||||
private final FrontendSpec specification = FrontendSpec.builder()
|
||||
.languageId(LANGUAGE_ID)
|
||||
.allowedExtensions(ReadOnlySet.from("synth"))
|
||||
.sourceRoots(ReadOnlySet.from("src"))
|
||||
.build();
|
||||
private final ControlledIrPhase compiler;
|
||||
|
||||
public ControlledIrFrontend() { this(false); }
|
||||
|
||||
public ControlledIrFrontend(boolean invalidRet) { this(invalidRet, false); }
|
||||
public ControlledIrFrontend(boolean invalidRet, boolean noInstructionOrigin) { compiler = new ControlledIrPhase(invalidRet, noInstructionOrigin); }
|
||||
|
||||
@Override
|
||||
public FrontendSpec specification() {
|
||||
return specification;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FrontendPhaseService compiler() {
|
||||
return compiler;
|
||||
}
|
||||
|
||||
public ControlledIrPhase syntheticCompiler() {
|
||||
return compiler;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package p.studio.app.compiler.fixture;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssueSink;
|
||||
import p.studio.compiler.messages.FrontendPhaseContext;
|
||||
import p.studio.compiler.models.IRBackend;
|
||||
import p.studio.compiler.models.IRBackendExecutableFunction;
|
||||
import p.studio.compiler.models.IRLifecycleCallableReference;
|
||||
import p.studio.compiler.models.IRLifecycleCallableRole;
|
||||
import p.studio.compiler.models.IRLifecycleDeclaration;
|
||||
import p.studio.compiler.models.IRLifecycleModuleDeclaration;
|
||||
import p.studio.compiler.services.FrontendPhaseService;
|
||||
import p.studio.compiler.source.Span;
|
||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||
import p.studio.compiler.source.identifiers.CallableId;
|
||||
import p.studio.compiler.source.identifiers.FileId;
|
||||
import p.studio.compiler.source.identifiers.ModuleId;
|
||||
import p.studio.compiler.source.tables.CallableSignatureRef;
|
||||
import p.studio.compiler.source.tables.ModuleReference;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
final class ControlledIrPhase implements FrontendPhaseService {
|
||||
private final AtomicBoolean invoked = new AtomicBoolean();
|
||||
private final boolean invalidRet;
|
||||
private final boolean noInstructionOrigin;
|
||||
|
||||
public ControlledIrPhase() { this(false); }
|
||||
|
||||
public ControlledIrPhase(boolean invalidRet) { this(invalidRet, false); }
|
||||
public ControlledIrPhase(boolean invalidRet, boolean noInstructionOrigin) { this.invalidRet = invalidRet; this.noInstructionOrigin = noInstructionOrigin; }
|
||||
|
||||
public boolean invoked() {
|
||||
return invoked.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IRBackend compile(
|
||||
final FrontendPhaseContext request,
|
||||
final DiagnosticSink diagnostics,
|
||||
final LogAggregator logs,
|
||||
final BuildingIssueSink issues) {
|
||||
invoked.set(true);
|
||||
for (var id : request.fileTable.identifiers()) request.fileTable.get(id).readBytes();
|
||||
|
||||
final var moduleId = new ModuleId(0);
|
||||
final var fileId = new FileId(0);
|
||||
final var callableId = new CallableId(0);
|
||||
final var span = new Span(fileId, 0, 1);
|
||||
final var operationSpan = noInstructionOrigin ? Span.none() : span;
|
||||
var instructions = new java.util.ArrayList<IRBackendExecutableFunction.Instruction>();
|
||||
if (!invalidRet) {
|
||||
instructions.add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.PUSH_I32, ModuleId.none(), "", null, null, null, "1", null, null, null, operationSpan));
|
||||
instructions.add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.JMP_IF_TRUE, ModuleId.none(), "", null, null, null, null, "join", null, null, operationSpan));
|
||||
}
|
||||
instructions.add(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.PUSH_I32, ModuleId.none(), "", null, null, null, "1", null, null, null, operationSpan));
|
||||
if (!invalidRet) instructions.add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.LABEL, ModuleId.none(), "", null, null, null, "join", null, null, null, operationSpan));
|
||||
instructions.add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"", null, null, operationSpan));
|
||||
final var frame = new IRBackendExecutableFunction(
|
||||
fileId,
|
||||
moduleId,
|
||||
"frame",
|
||||
callableId,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
ReadOnlyList.wrap(instructions),
|
||||
span);
|
||||
final var frameRoot = new IRLifecycleCallableReference(
|
||||
moduleId,
|
||||
fileId,
|
||||
callableId,
|
||||
IRLifecycleCallableRole.FRAME_ROOT,
|
||||
span);
|
||||
|
||||
return IRBackend.builder()
|
||||
.entryPointCallableName("frame")
|
||||
.entryPointModuleId(moduleId)
|
||||
.modulePool(ReadOnlyList.from(new ModuleReference("synth", ReadOnlyList.from("main"))))
|
||||
.callableSignatures(ReadOnlyList.from(
|
||||
new CallableSignatureRef(moduleId, "frame", 0, "() -> unit")))
|
||||
.executableFunctions(ReadOnlyList.from(frame))
|
||||
.lifecycleDeclaration(new IRLifecycleDeclaration(
|
||||
ReadOnlyList.from(new IRLifecycleModuleDeclaration(moduleId, ReadOnlyList.empty())),
|
||||
null,
|
||||
frameRoot))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@@ -98,6 +98,15 @@ class AutomationLspQueriesTest {
|
||||
assertTrue(symbols.toString().contains("renamed"), symbols.toString());
|
||||
assertFalse(symbols.toString().contains("helper"), symbols.toString());
|
||||
}
|
||||
@Test void validEmptyDocumentIsSuccessfulEvaluatedAnalysis() throws Exception {
|
||||
Files.writeString(source, "");
|
||||
Files.writeString(source.resolveSibling("mod.barrel"), "pub fn frame() -> void;\n");
|
||||
Files.writeString(source.resolveSibling("frame.pbs"), "[Frame] fn frame() -> void {}\n"); acquire();
|
||||
var reply = query("diagnostics", Map.of("uri", source.toUri().toString()));
|
||||
assertTrue(reply.path("result").isEmpty(), reply.toString()); assertTrue(reply.path("analysis").path("issues").isEmpty(), reply.toString());
|
||||
assertEquals("passed", reply.path("analysis").path("summary").path("validationStatus").asText());
|
||||
assertEquals(0, reply.path("analysis").path("summary").path("counts").path("errors").asInt());
|
||||
}
|
||||
@Test void proposalsDoNotWriteFilesAndQueriesCoverAdvertisedOperations() throws Exception {
|
||||
acquire();
|
||||
for (String operation : List.of("hover", "completion", "signatureHelp", "references", "prepareRename", "semanticTokens"))
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package p.studio.app.lsp;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.api.automation.*;
|
||||
import p.studio.app.operation.ExecutorOperationExecutor;
|
||||
import p.studio.core.language.*;
|
||||
import p.studio.core.project.*;
|
||||
import p.studio.core.session.DefaultAutomationSession;
|
||||
import p.studio.app.compiler.CompilerProjectKnowledge;
|
||||
import p.studio.lsp.api.LspServerLifecycle;
|
||||
import p.studio.lsp.messages.*;
|
||||
import p.studio.lsp.services.protocol.ExternalSourceLanguageServer;
|
||||
import org.eclipse.lsp4j.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.*;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
|
||||
import java.net.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/** Controlled protocol faults use real sockets; the stubborn child is an explicitly injected port. */
|
||||
class LanguageFailureContractTest {
|
||||
@TempDir Path root;
|
||||
@Test void protocolMechanismsBecomeNeutralFailuresAndLegacyFallbackStaysLimited() throws Exception {
|
||||
root = root.toRealPath(); var json = new ObjectMapper();
|
||||
Files.writeString(root.resolve("prometeu.json"), "{\"name\":\"fault\",\"version\":\"1\",\"language\":\"pbs\",\"stdlib\":\"1\",\"target\":\"Game\",\"dependencies\":[]}");
|
||||
var source = Files.createDirectories(root.resolve("src")).resolve("main.pbs"); Files.writeString(source, "fn x() -> int { return 1; }\n");
|
||||
var access = new ProjectAccessRegistry(); var catalog = new ProjectCatalogService(root.getParent(), json, new ProjectLocalStudioSetupStore(json));
|
||||
var knowledge = new CompilerProjectKnowledge(access, catalog, json);
|
||||
var faults = new LinkedHashMap<Integer, AutomationFailure.Code>();
|
||||
faults.put(-32020, AutomationFailure.Code.LANGUAGE_QUERY_REVISION_MISMATCH);
|
||||
faults.put(-32603, AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE);
|
||||
faults.put(-32099, AutomationFailure.Code.LANGUAGE_QUERY_PROTOCOL_FAILURE);
|
||||
faults.put(0, AutomationFailure.Code.LANGUAGE_QUERY_TIMEOUT);
|
||||
faults.put(1, null); // controlled standard-only server
|
||||
try (var threads = Executors.newCachedThreadPool()) {
|
||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(threads));
|
||||
var registration = access.register(root, authority::enterManual, () -> true, authority);
|
||||
authority.grant(false).toCompletableFuture().join(); var task = authority.acquire().task();
|
||||
try {
|
||||
for (var fault : faults.entrySet()) try (var listener = new ServerSocket(0, 8, InetAddress.getLoopbackAddress())) {
|
||||
var served = threads.submit(() -> {
|
||||
try (var socket = listener.accept()) {
|
||||
var clientRef = new AtomicReference<org.eclipse.lsp4j.services.LanguageClient>();
|
||||
var text = (org.eclipse.lsp4j.services.TextDocumentService)java.lang.reflect.Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{org.eclipse.lsp4j.services.TextDocumentService.class}, (proxy, method, args) -> {
|
||||
if (method.getName().equals("didOpen")) {
|
||||
var open = (DidOpenTextDocumentParams)args[0]; clientRef.get().publishDiagnostics(new PublishDiagnosticsParams(open.getTextDocument().getUri(), List.of()));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
var server = (ExternalSourceLanguageServer)java.lang.reflect.Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ExternalSourceLanguageServer.class}, (proxy, method, args) -> switch (method.getName()) {
|
||||
case "initialize" -> fault.getKey() == 0 ? new CompletableFuture<InitializeResult>()
|
||||
: fault.getKey() == 1 ? CompletableFuture.completedFuture(new InitializeResult(legacyCapabilities()))
|
||||
: CompletableFuture.failedFuture(new ResponseErrorException(new ResponseError(fault.getKey(), "controlled protocol failure", null)));
|
||||
case "getTextDocumentService" -> text;
|
||||
case "getWorkspaceService" -> new p.studio.lsp.services.protocol.PrometeuWorkspaceService();
|
||||
default -> null;
|
||||
});
|
||||
var launcher = new Launcher.Builder<org.eclipse.lsp4j.services.LanguageClient>().setLocalService(server)
|
||||
.setRemoteInterface(org.eclipse.lsp4j.services.LanguageClient.class).setInput(socket.getInputStream()).setOutput(socket.getOutputStream()).setExecutorService(threads).create();
|
||||
clientRef.set(launcher.getRemoteProxy()); launcher.startListening().get(5, TimeUnit.SECONDS);
|
||||
} catch (Exception ended) { /* Closing the client ends this controlled server. */ }
|
||||
});
|
||||
var endpoint = new LspServerEndpoint(InetAddress.getLoopbackAddress().getHostAddress(), listener.getLocalPort());
|
||||
var lifecycle = lifecycle(endpoint);
|
||||
var queries = new TaskLanguageQueries(access, new AutomationLspQueries(lifecycle, catalog, knowledge, json), 700, 500);
|
||||
var params = Map.<String, Object>of("uri", source.toUri().toString());
|
||||
if (fault.getValue() == null) {
|
||||
var reply = queries.query(root, task.value(), "diagnostics", params);
|
||||
assertTrue(reply.get("limitations").toString().contains("ANALYSIS_DETAILS_UNAVAILABLE"));
|
||||
assertTrue(reply.get("analysis").toString().contains("not-evaluated"));
|
||||
} else {
|
||||
var failure = assertThrows(AutomationException.class, () -> queries.query(root, task.value(), "diagnostics", params)).failure();
|
||||
assertEquals(fault.getValue(), failure.code()); assertTrue(failure.runtimeError().isEmpty());
|
||||
assertEquals(true, failure.details().get("workerTerminated")); assertNotNull(failure.details().get("queryId"));
|
||||
}
|
||||
served.get(3, TimeUnit.SECONDS);
|
||||
}
|
||||
var missing = new TaskLanguageQueries(access, new AutomationLspQueries(lifecycle(null), catalog, knowledge, json));
|
||||
assertEquals(AutomationFailure.Code.LANGUAGE_SERVER_UNAVAILABLE,
|
||||
assertThrows(AutomationException.class, () -> missing.query(root, task.value(), "diagnostics", Map.of("uri", source.toUri().toString()))).failure().code());
|
||||
} finally { authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.unsubscribe(); }
|
||||
}
|
||||
}
|
||||
@Test void cancellationAndCleanupFailuresHaveSeparateNeutralCodes() throws Exception {
|
||||
try (var workers = Executors.newCachedThreadPool()) {
|
||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(workers));
|
||||
var access = new ProjectAccessRegistry(); var registration = access.register(root, authority::enterManual, () -> true, authority);
|
||||
authority.grant(false).toCompletableFuture().join(); var task = authority.acquire().task();
|
||||
try {
|
||||
for (boolean cleanupFailure : List.of(false, true)) {
|
||||
var port = new LanguageQueryPort() {
|
||||
public void endTask(TaskIdentity identity) {}
|
||||
public Map<String, Object> query(TaskIdentity identity, String operation, Map<String, Object> parameters) { throw new AssertionError(); }
|
||||
public Map<String, Object> query(TaskIdentity identity, String operation, Map<String, Object> parameters, LanguageQueryExecution execution) {
|
||||
if (!cleanupFailure) throw new CancellationException("controlled cancellation");
|
||||
execution.own(() -> { throw new IllegalStateException("controlled cleanup failure"); });
|
||||
execution.cancel(); return Map.of();
|
||||
}
|
||||
};
|
||||
var queries = new TaskLanguageQueries(access, port);
|
||||
var error = assertThrows(AutomationException.class, () -> queries.query(root, task.value(), "diagnostics", Map.of())).failure();
|
||||
assertEquals(cleanupFailure ? AutomationFailure.Code.LANGUAGE_QUERY_CLEANUP_FAILED : AutomationFailure.Code.LANGUAGE_QUERY_CANCELLED, error.code());
|
||||
assertEquals(true, error.details().get("workerTerminated"));
|
||||
if (cleanupFailure) assertEquals("failed", error.details().get("cleanup"));
|
||||
assertEquals(ControlState.AGENT_WORKING, authority.snapshot().state());
|
||||
}
|
||||
} finally { authority.closeAsync().toCompletableFuture().get(5,TimeUnit.SECONDS); registration.unsubscribe(); }
|
||||
}
|
||||
}
|
||||
static ServerCapabilities legacyCapabilities() {
|
||||
var capabilities = new ServerCapabilities(); capabilities.setTextDocumentSync(TextDocumentSyncKind.Full); return capabilities;
|
||||
}
|
||||
static LspServerLifecycle lifecycle(LspServerEndpoint endpoint) {
|
||||
return new LspServerLifecycle() {
|
||||
public void bootServer(LspServerConfiguration config, LspProjectContext context) {}
|
||||
public void shutdownServer(LspProjectContext context) {}
|
||||
public Optional<LspServerEndpoint> endpoint(LspProjectContext context) { return Optional.ofNullable(endpoint); }
|
||||
};
|
||||
}
|
||||
@Test void delayedChildCleanupKeepsAdmissionAndPrimaryFailureUntilActualTermination() throws Exception {
|
||||
try (var threads = Executors.newCachedThreadPool()) {
|
||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(threads));
|
||||
var access = new ProjectAccessRegistry(); var registration = access.register(root, authority::enterManual, () -> true, authority);
|
||||
authority.grant(false).toCompletableFuture().join(); var task = authority.acquire().task();
|
||||
var childEntered = new CountDownLatch(1); var releaseChild = new CountDownLatch(1); var executionRef = new AtomicReference<LanguageQueryExecution>();
|
||||
var port = new LanguageQueryPort() {
|
||||
public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters) { throw new AssertionError(); }
|
||||
public void endTask(TaskIdentity task) {}
|
||||
public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters, LanguageQueryExecution execution) {
|
||||
executionRef.set(execution); var child = Executors.newSingleThreadExecutor();
|
||||
child.submit(() -> { childEntered.countDown(); boolean interrupted = false;
|
||||
while (true) try { releaseChild.await(); break; } catch (InterruptedException ignored) { interrupted = true; }
|
||||
if (interrupted) Thread.currentThread().interrupt();
|
||||
});
|
||||
try { assertTrue(childEntered.await(2, TimeUnit.SECONDS)); } catch (InterruptedException stopped) { Thread.currentThread().interrupt(); }
|
||||
execution.own(child::shutdownNow);
|
||||
execution.finishWorkers(child);
|
||||
execution.record(AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE, "late failure", Map.of());
|
||||
return Map.of("late", true);
|
||||
}
|
||||
};
|
||||
try {
|
||||
var queries = new TaskLanguageQueries(access, port, 150, 150);
|
||||
var call = threads.submit(() -> queries.query(root, task.value(), "diagnostics", Map.of()));
|
||||
assertTrue(childEntered.await(2, TimeUnit.SECONDS));
|
||||
var error = assertInstanceOf(AutomationException.class, assertThrows(ExecutionException.class, () -> call.get(2, TimeUnit.SECONDS)).getCause()).failure();
|
||||
assertEquals(AutomationFailure.Code.LANGUAGE_QUERY_TIMEOUT, error.code()); assertEquals(false, error.details().get("workerTerminated"));
|
||||
assertEquals(ControlResult.Status.BUSY, assertThrows(ControlDeniedException.class, () -> authority.submit(task, "successor", () -> null)).status());
|
||||
assertEquals(ControlState.AGENT_WORKING, authority.snapshot().state());
|
||||
releaseChild.countDown();
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(2);
|
||||
while (authority.snapshot().operation().state() != p.studio.api.operation.OperationState.CANCELLED && System.nanoTime() < deadline) Thread.onSpinWait();
|
||||
assertEquals(AutomationFailure.Code.LANGUAGE_QUERY_TIMEOUT, executionRef.get().exception(AutomationFailure.Code.LANGUAGE_QUERY_INTERNAL_FAILURE, "later", true).failure().code());
|
||||
} finally { releaseChild.countDown(); authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.unsubscribe(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package p.studio.app.lsp;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import p.studio.api.project.*;
|
||||
import p.studio.lsp.services.LspServerLifecycleImpl;
|
||||
import java.nio.file.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LspDiscoveryTest {
|
||||
@TempDir Path root;
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
ProjectReference project() { return new ProjectReference("app", "1.0", "pbs", 1, ProjectTarget.Game, root); }
|
||||
|
||||
@Test void publishesActualProjectEndpointAndRemovesItOnClose() throws Exception {
|
||||
var lifecycle = new LspServerLifecycleImpl();
|
||||
var adapter = new LspLifecycleAdapter(lifecycle);
|
||||
var project = project();
|
||||
adapter.boot(project);
|
||||
try {
|
||||
var data = mapper.readTree(root.resolve(".studio/lsp.json").toFile());
|
||||
assertEquals(1, data.path("schemaVersion").asInt());
|
||||
assertEquals(root.toRealPath().toString(), data.path("projectRoot").asText());
|
||||
assertEquals(ProcessHandle.current().pid(), data.path("processId").asLong());
|
||||
var endpoint = lifecycle.endpoint(LspLifecycleAdapter.context(project)).orElseThrow();
|
||||
assertEquals(endpoint.port(), data.path("port").asInt());
|
||||
assertEquals("127.0.0.1", data.path("host").asText());
|
||||
assertFalse(data.path("sessionId").asText().isBlank());
|
||||
} finally { adapter.shutdown(project); }
|
||||
assertFalse(Files.exists(root.resolve(".studio/lsp.json")));
|
||||
assertTrue(lifecycle.endpoint(LspLifecycleAdapter.context(project)).isEmpty());
|
||||
}
|
||||
|
||||
@Test void newSessionGetsFreshIdentityAndPortCanBeRediscovered() throws Exception {
|
||||
var adapter = new LspLifecycleAdapter(new LspServerLifecycleImpl());
|
||||
var project = project();
|
||||
adapter.boot(project);
|
||||
String first;
|
||||
try { first = mapper.readTree(root.resolve(".studio/lsp.json").toFile()).path("sessionId").asText(); }
|
||||
finally { adapter.shutdown(project); }
|
||||
adapter.boot(project);
|
||||
try { assertNotEquals(first, mapper.readTree(root.resolve(".studio/lsp.json").toFile()).path("sessionId").asText()); }
|
||||
finally { adapter.shutdown(project); }
|
||||
}
|
||||
|
||||
@Test void shutdownPreservesMetadataOwnedByAnotherSession() throws Exception {
|
||||
var adapter = new LspLifecycleAdapter(new LspServerLifecycleImpl());
|
||||
var project = project();
|
||||
adapter.boot(project);
|
||||
Files.writeString(root.resolve(".studio/lsp.json"), "{\"sessionId\":\"replacement\"}");
|
||||
adapter.shutdown(project);
|
||||
assertTrue(Files.readString(root.resolve(".studio/lsp.json")).contains("replacement"));
|
||||
}
|
||||
|
||||
@Test void failedPublicationRollsBackListeningServer() throws Exception {
|
||||
Files.writeString(root.resolve(".studio"), "blocked");
|
||||
var lifecycle = new LspServerLifecycleImpl();
|
||||
var adapter = new LspLifecycleAdapter(lifecycle);
|
||||
assertThrows(IllegalStateException.class, () -> adapter.boot(project()));
|
||||
assertTrue(lifecycle.endpoint(LspLifecycleAdapter.context(project())).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -375,6 +375,61 @@ class McpTaskToolsTest {
|
||||
error("INVALID_TASK", httpCall(client, server, reconnected, "studio_build_start", args().put("clientRequestId", "late")));
|
||||
} finally { lsp.shutdown(project); }
|
||||
}
|
||||
@Test void cancelledBuildCannotPublishSuccessOrUsableArtifactIdentityAfterLateReturn() throws Exception {
|
||||
acquire(); holdBuild = true;
|
||||
var receipt = value(call("studio_build_start", args().put("clientRequestId", "cancel-build")));
|
||||
assertTrue(buildEntered.await(2, TimeUnit.SECONDS));
|
||||
value(call("studio_operation_cancel", args().put("operationId", receipt.path("operationId").asText())));
|
||||
assertFalse(poll("cancel-build").path("workerTerminated").asBoolean()); buildGate.countDown();
|
||||
var result = completed("cancel-build");
|
||||
assertEquals("CANCELLED", result.path("state").asText()); assertEquals("CANCELLED", result.path("result").path("status").asText());
|
||||
assertEquals("cancelled", result.path("result").path("summary").path("validationStatus").asText()); assertTrue(result.path("result").path("buildId").isNull());
|
||||
assertEquals(ControlState.AGENT_WORKING, session.snapshot().state());
|
||||
}
|
||||
|
||||
@Test void controlledInvalidCommonIrRetAndJoinSurviveTheRealBuildGatewayAndAuthenticatedMcp() throws Exception {
|
||||
Files.writeString(root.resolve("prometeu.json"), "{\"name\":\"controlled\",\"version\":\"1\",\"language\":\"controlled-ir\",\"stdlib\":\"1\",\"target\":\"Game\",\"dependencies\":[]}");
|
||||
Files.createDirectories(root.resolve("src")); Files.writeString(root.resolve("src/probe.synth"), "x");
|
||||
var reports = mapper.createArrayNode();
|
||||
try (var packer = p.packer.Packer.bootstrap(mapper, ignored -> {})) {
|
||||
compose(new p.studio.core.shipper.StudioShipperService(new p.studio.app.compiler.CompilerBuildGatewayAdapter(), packer.workspaceService(), mapper, new ExecutorOperationExecutor(workers), access));
|
||||
try (var server = new LocalMcpServer(mapper, tools); var client = java.net.http.HttpClient.newHttpClient()) {
|
||||
server.start(); var credential = server.credentials().prepare(root); credential.activate(); httpAuthorization = "Bearer " + credential.secret();
|
||||
String connection = connect(client, server); session.grant(false).toCompletableFuture().join();
|
||||
task = value(httpCall(client, server, connection, "studio_control_acquire", rootOnly())).path("taskId").asText();
|
||||
for (var variant : List.of("ret", "join", "ret-no-origin")) {
|
||||
boolean ret = !variant.equals("join"), noOrigin = variant.endsWith("no-origin");
|
||||
var frontend = new p.studio.app.compiler.fixture.ControlledIrFrontend(ret, noOrigin);
|
||||
p.studio.compiler.FrontendRegistryService.register(frontend);
|
||||
try {
|
||||
String request = variant + "-fixture";
|
||||
value(httpCall(client, server, connection, "studio_build_start", args().put("clientRequestId", request)));
|
||||
var result = httpCompleted(client, server, connection, request); var build = result.path("result");
|
||||
assertEquals("FAILED", build.path("status").asText(), build.toString());
|
||||
assertEquals("failed", build.path("summary").path("validationStatus").asText());
|
||||
var issue = build.path("issues").get(0);
|
||||
assertEquals(ret ? "compiler.verify.ret-stack-height" : "compiler.verify.join-stack-height", issue.path("checkId").asText(), issue.toString());
|
||||
assertEquals("available", issue.path("explanation").path("availability").asText());
|
||||
assertEquals("irvm-function", issue.path("origin").path("verification").path("pcSpace").asText());
|
||||
assertEquals("byte", issue.path("origin").path("verification").path("pcUnit").asText());
|
||||
assertEquals("lowering-output", issue.path("origin").path("verification").path("validationPoint").asText());
|
||||
if (noOrigin) {
|
||||
assertTrue(issue.path("origin").path("uri").isNull()); assertTrue(issue.path("origin").path("range").isNull());
|
||||
assertEquals("no-source-span", issue.path("origin").path("attribution").path("absenceReason").asText());
|
||||
assertFalse(issue.path("related").isEmpty());
|
||||
} else assertEquals(root.resolve("src/probe.synth").toUri().toString(), issue.path("origin").path("uri").asText());
|
||||
assertTrue(issue.path("facts").has(ret ? "expectedHeight" : "existingHeight"));
|
||||
assertTrue(issue.path("facts").has(ret ? "actualHeight" : "incomingHeight"));
|
||||
reports.add(result);
|
||||
} finally { p.studio.compiler.FrontendRegistryService.unregister(frontend.specification().getLanguageId()); }
|
||||
}
|
||||
value(httpCall(client, server, connection, "studio_control_release", args()));
|
||||
}
|
||||
}
|
||||
var report = Path.of("build/diagnostic-qualification/controlled-backend.json"); Files.createDirectories(report.getParent());
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(report.toFile(), reports);
|
||||
}
|
||||
|
||||
String connect(java.net.http.HttpClient client, LocalMcpServer server) throws Exception {
|
||||
var initialize = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 1).put("method", "initialize");
|
||||
var params = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
||||
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
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. */
|
||||
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)); }
|
||||
}
|
||||
@@ -0,0 +1,451 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"cases": [
|
||||
{
|
||||
"id": "F1-local",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Control: method result materialized before comparison",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\nfn check() -> bool { let value=data.value(); return value!=0; }\n[Frame] fn frame() -> void { if !check() { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "35df5a71b9d508b20e8b293a769ba1397a3209d99246c39240e8788cda932990"
|
||||
},
|
||||
{
|
||||
"id": "F1-direct",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Method call compared directly in returned expression",
|
||||
"control": "F1-local",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\nfn check() -> bool { return data.value()!=0; }\n[Frame] fn frame() -> void { if !check() { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "382223b4c520762a93e3ee767255175adec8b24f69949b335c1a0030c9d75e61"
|
||||
},
|
||||
{
|
||||
"id": "F1-two-calls",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Two method calls as comparison operands",
|
||||
"control": "F1-local",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\nfn check() -> bool { return data.value()==data.value(); }\n[Frame] fn frame() -> void { if !check() { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "2e3da1c805c18b5cdc34ca372fae737804a9274205ef377ac21d5b0034d60c4f"
|
||||
},
|
||||
{
|
||||
"id": "F1-service-this",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Service receiver this inside a returned comparison",
|
||||
"control": "F1-service-local",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare service Probe { fn value() -> int { return 1; } fn check() -> bool { return this.value()!=0; } }\n[Frame] fn frame() -> void { if !Probe.check() { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "78a7ba39a880d9136b49f82ecbee7d409333c26861ff0a6b429ae6a55f08d089"
|
||||
},
|
||||
{
|
||||
"id": "F1-service-local",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Control: identical service call materialized before returned comparison",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare service Probe { fn value() -> int { return 1; } fn check() -> bool { let value=this.value(); return value!=0; } }\n[Frame] fn frame() -> void { if !Probe.check() { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "f07038dc6f42923a65b1df8c4d17aa61eb1714ae7907d82b87fcda9e6c4b73fb"
|
||||
},
|
||||
{
|
||||
"id": "F1-condition",
|
||||
"family": "call-comparison-return",
|
||||
"description": "Control: direct method comparison in an if condition",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\n[Frame] fn frame() -> void { if data.value()!=1 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "415d08d0155fc8e8b4e0df3c1eb47c0a6aa7bda6481fdc4f5024c14d0f70d014"
|
||||
},
|
||||
{
|
||||
"id": "F2-locals",
|
||||
"family": "nested-call-expression",
|
||||
"description": "Control: effectful call arguments stored in locals",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare global calls: int=0;\nfn next() -> int { calls+=1; return calls; }\nfn add(a: int,b: int) -> int { return a+b; }\n[Frame] fn frame() -> void { calls=0; let a=next(); let b=next(); let value=add(a,b); if value!=3 || calls!=2 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "1eb4dbd0bfa6fbc9e002793e6c23eefa80eb091d40ccf2253520b532b3420218"
|
||||
},
|
||||
{
|
||||
"id": "F2-arguments",
|
||||
"family": "nested-call-expression",
|
||||
"description": "Effectful call arguments evaluate once, left to right",
|
||||
"control": "F2-locals",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare global calls: int=0;\nfn next() -> int { calls+=1; return calls; }\nfn add(a: int,b: int) -> int { return a+b; }\n[Frame] fn frame() -> void { calls=0; let value=add(next(),next()); if value!=3 || calls!=2 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "b8713121ffe7afacdd9d4ad6046768ff4ad681b44fcc153f84a432f6df75717c"
|
||||
},
|
||||
{
|
||||
"id": "F2-expression",
|
||||
"family": "nested-call-expression",
|
||||
"description": "Effectful calls nested inside arithmetic argument",
|
||||
"control": "F2-locals",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare global calls: int=0;\nfn next() -> int { calls+=1; return calls; }\nfn add(a: int,b: int) -> int { return a+b; }\n[Frame] fn frame() -> void { calls=0; let value=add(next()+next(),next()); if value!=6 || calls!=3 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "c6ede06ecfad7bdd167b8f3afb849df362787484db1968f74b62c24909818073"
|
||||
},
|
||||
{
|
||||
"id": "F2-struct-method",
|
||||
"family": "nested-call-expression",
|
||||
"description": "Struct method used as another method argument",
|
||||
"control": "F2-locals",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare struct Probe() { fn value() -> int { return 1; } }\ndeclare global data: Probe = new Probe();\nfn add(a: int,b: int) -> int { return a+b; }\n[Frame] fn frame() -> void { let value=add(data.value(),data.value()); if value!=2 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "8ed2b002ef5c20f01ae09949dc0ae75c574cce782dbe27bd304b25fa94045894"
|
||||
},
|
||||
{
|
||||
"id": "F3-single-file",
|
||||
"family": "same-module-files",
|
||||
"description": "Control: function and caller in the same file",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "fn increment(value: int) -> int { return value+1; }\n[Frame] fn frame() -> void { let value=increment(2); if value!=3 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "aff9dbc6f5e3b67b713da29e7e20eb97913464bedcc5f858964ec110ed7b8c4a"
|
||||
},
|
||||
{
|
||||
"id": "F3-function",
|
||||
"family": "same-module-files",
|
||||
"description": "mod function called from another file",
|
||||
"control": "F3-single-file",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\nmod fn increment(value: int) -> int;\n",
|
||||
"src/helpers.pbs": "fn increment(value: int) -> int { return value+1; }\n",
|
||||
"src/main.pbs": "[Frame] fn frame() -> void { let value=increment(2); if value!=3 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "bcf9162dd44b7b7a50428e368789d10ab929301f382bae7c35cab06f1595c4b1"
|
||||
},
|
||||
{
|
||||
"id": "F3-global",
|
||||
"family": "same-module-files",
|
||||
"description": "mod global mutated from another file",
|
||||
"control": "F3-global-local",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\nmod global count;\n",
|
||||
"src/state.pbs": "declare global count: int=0;\n",
|
||||
"src/main.pbs": "[Frame] fn frame() -> void { count=4; if count!=4 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "89c0749385172457659ca2e337ebc368e349065626a815198c314a089d95fc34"
|
||||
},
|
||||
{
|
||||
"id": "F3-service",
|
||||
"family": "same-module-files",
|
||||
"description": "mod service called from another file",
|
||||
"control": "F3-service-local",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\nmod service Helper;\n",
|
||||
"src/helpers.pbs": "declare service Helper { fn value() -> int { return 3; } }\n",
|
||||
"src/main.pbs": "[Frame] fn frame() -> void { let value=Helper.value(); if value!=3 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "37b6c3b4c7d94d1f6f1cc258c84791fdd32c20ea38a88940b735fccf1c7f3b22"
|
||||
},
|
||||
{
|
||||
"id": "F3-global-local",
|
||||
"family": "same-module-files",
|
||||
"description": "Control: identical global and caller in the same file",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare global count: int=0;\n[Frame] fn frame() -> void { count=4; if count!=4 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "e175339cc069d0e14deb8e4e098b1310d877851f2415991ad65b446563aea924"
|
||||
},
|
||||
{
|
||||
"id": "F3-service-local",
|
||||
"family": "same-module-files",
|
||||
"description": "Control: identical service and caller in the same file",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "declare service Helper { fn value() -> int { return 3; } }\n[Frame] fn frame() -> void { let value=Helper.value(); if value!=3 { let failure=1/0; } }\n"
|
||||
},
|
||||
"sourceSha256": "387e15a0de25644a8862b6f88b74fc7839795e10c8736ebc5ada31670ffd79cb"
|
||||
},
|
||||
{
|
||||
"id": "F3-file-private",
|
||||
"family": "same-module-files",
|
||||
"description": "Negative control: function absent from barrel stays file-private",
|
||||
"control": "F3-function",
|
||||
"expectedCompile": "rejected",
|
||||
"expectedRuntime": "not_run",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/helpers.pbs": "fn increment(value: int) -> int { return value+1; }\n",
|
||||
"src/main.pbs": "[Frame] fn frame() -> void { let value=increment(2); }\n"
|
||||
},
|
||||
"sourceSha256": "b9359695e141c6fd14d5fbfcab68a8829ef4d87c3c7408dbc366465184ec2cfb"
|
||||
},
|
||||
{
|
||||
"id": "F4-distinct",
|
||||
"family": "homonymous-types",
|
||||
"description": "Types ARoomData/BRoomData; dependency=True; direct=False",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { A } from @caseapp:a;\nimport { B } from @caseapp:b;\n[Frame] fn frame() -> void { let value=A.value(); if value!=3 { let failure=1/0; } let other=B.value(); if other!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub service A;\nmod struct ARoomData;\n",
|
||||
"src/a/data.pbs": "declare struct ARoomData() { fn value() -> int { return 1; } }\n",
|
||||
"src/a/main.pbs": "import { B } from @caseapp:b;\ndeclare global room: ARoomData = new ARoomData();\ndeclare service A { fn value() -> int { let own=room.value(); let other=B.value(); return own+other; } }\n",
|
||||
"src/b/mod.barrel": "pub service B;\nmod struct BRoomData;\n",
|
||||
"src/b/data.pbs": "declare struct BRoomData() { fn value() -> int { return 2; } }\n",
|
||||
"src/b/main.pbs": "declare global room: BRoomData = new BRoomData();\ndeclare service B { fn value() -> int { return room.value(); } }\n"
|
||||
},
|
||||
"sourceSha256": "99c527e7749e4ea7c1cecce4063467e4f411b5481cdd641186975fee42299811"
|
||||
},
|
||||
{
|
||||
"id": "F4-same-no-dependency",
|
||||
"family": "homonymous-types",
|
||||
"description": "Types RoomData/RoomData; dependency=False; direct=False",
|
||||
"control": "F4-distinct",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { A } from @caseapp:a;\nimport { B } from @caseapp:b;\n[Frame] fn frame() -> void { let value=A.value(); if value!=1 { let failure=1/0; } let other=B.value(); if other!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub service A;\nmod struct RoomData;\n",
|
||||
"src/a/data.pbs": "declare struct RoomData() { fn value() -> int { return 1; } }\n",
|
||||
"src/a/main.pbs": "declare global room: RoomData = new RoomData();\ndeclare service A { fn value() -> int { let own=room.value(); return own; } }\n",
|
||||
"src/b/mod.barrel": "pub service B;\nmod struct RoomData;\n",
|
||||
"src/b/data.pbs": "declare struct RoomData() { fn value() -> int { return 2; } }\n",
|
||||
"src/b/main.pbs": "declare global room: RoomData = new RoomData();\ndeclare service B { fn value() -> int { return room.value(); } }\n"
|
||||
},
|
||||
"sourceSha256": "db3c59d1f4f618856ed554310e5774f60d64f70e9ed0b122a5ab57d4e9870ce5"
|
||||
},
|
||||
{
|
||||
"id": "F4-same-dependency",
|
||||
"family": "homonymous-types",
|
||||
"description": "Types RoomData/RoomData; dependency=True; direct=False",
|
||||
"control": "F4-distinct",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { A } from @caseapp:a;\nimport { B } from @caseapp:b;\n[Frame] fn frame() -> void { let value=A.value(); if value!=3 { let failure=1/0; } let other=B.value(); if other!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub service A;\nmod struct RoomData;\n",
|
||||
"src/a/data.pbs": "declare struct RoomData() { fn value() -> int { return 1; } }\n",
|
||||
"src/a/main.pbs": "import { B } from @caseapp:b;\ndeclare global room: RoomData = new RoomData();\ndeclare service A { fn value() -> int { let own=room.value(); let other=B.value(); return own+other; } }\n",
|
||||
"src/b/mod.barrel": "pub service B;\nmod struct RoomData;\n",
|
||||
"src/b/data.pbs": "declare struct RoomData() { fn value() -> int { return 2; } }\n",
|
||||
"src/b/main.pbs": "declare global room: RoomData = new RoomData();\ndeclare service B { fn value() -> int { return room.value(); } }\n"
|
||||
},
|
||||
"sourceSha256": "c4c624cb3556b8d05927ceda69e596482f4ec1d7b82f7f4ca7442483e2b8b831"
|
||||
},
|
||||
{
|
||||
"id": "F4-rename-a",
|
||||
"family": "homonymous-types",
|
||||
"description": "Types StartRoomData/RoomData; dependency=True; direct=False",
|
||||
"control": "F4-distinct",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { A } from @caseapp:a;\nimport { B } from @caseapp:b;\n[Frame] fn frame() -> void { let value=A.value(); if value!=3 { let failure=1/0; } let other=B.value(); if other!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub service A;\nmod struct StartRoomData;\n",
|
||||
"src/a/data.pbs": "declare struct StartRoomData() { fn value() -> int { return 1; } }\n",
|
||||
"src/a/main.pbs": "import { B } from @caseapp:b;\ndeclare global room: StartRoomData = new StartRoomData();\ndeclare service A { fn value() -> int { let own=room.value(); let other=B.value(); return own+other; } }\n",
|
||||
"src/b/mod.barrel": "pub service B;\nmod struct RoomData;\n",
|
||||
"src/b/data.pbs": "declare struct RoomData() { fn value() -> int { return 2; } }\n",
|
||||
"src/b/main.pbs": "declare global room: RoomData = new RoomData();\ndeclare service B { fn value() -> int { return room.value(); } }\n"
|
||||
},
|
||||
"sourceSha256": "6cab04b1fbc3724cec1670a11ab46a792e5b83ea1fb12b4bf80f98d178c1290e"
|
||||
},
|
||||
{
|
||||
"id": "F4-same-direct",
|
||||
"family": "homonymous-types",
|
||||
"description": "Types RoomData/RoomData; dependency=True; direct=True",
|
||||
"control": "F4-distinct",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { A } from @caseapp:a;\nimport { B } from @caseapp:b;\n[Frame] fn frame() -> void { let value=A.value(); if value!=3 { let failure=1/0; } let other=B.value(); if other!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub service A;\nmod struct RoomData;\n",
|
||||
"src/a/data.pbs": "declare struct RoomData() { fn value() -> int { return 1; } }\n",
|
||||
"src/a/main.pbs": "import { B } from @caseapp:b;\ndeclare global room: RoomData = new RoomData();\ndeclare service A { fn value() -> int { return room.value()+B.value(); } }\n",
|
||||
"src/b/mod.barrel": "pub service B;\nmod struct RoomData;\n",
|
||||
"src/b/data.pbs": "declare struct RoomData() { fn value() -> int { return 2; } }\n",
|
||||
"src/b/main.pbs": "declare global room: RoomData = new RoomData();\ndeclare service B { fn value() -> int { return room.value(); } }\n"
|
||||
},
|
||||
"sourceSha256": "79fc0901e3e60e7b50b83f5d10ba4e548bd57b0c83d281def25369cadb74633e"
|
||||
},
|
||||
{
|
||||
"id": "F4-public-aliases",
|
||||
"family": "homonymous-types",
|
||||
"description": "Two distinct nominal RoomData declarations imported with aliases",
|
||||
"control": "F4-distinct",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { RoomData as LeftData } from @caseapp:a;\nimport { RoomData as RightData } from @caseapp:b;\ndeclare global left: LeftData = new LeftData(1);\ndeclare global right: RightData = new RightData(2);\n[Frame] fn frame() -> void { let a=left.value(); let b=right.value(); if a!=1 || b!=2 { let failure=1/0; } }\n",
|
||||
"src/a/mod.barrel": "pub struct RoomData;\n",
|
||||
"src/a/main.pbs": "declare struct RoomData(number: int) { fn value() -> int { return this.number; } }\n",
|
||||
"src/b/mod.barrel": "pub struct RoomData;\n",
|
||||
"src/b/main.pbs": "declare struct RoomData(number: int) { fn value() -> int { return this.number; } }\n"
|
||||
},
|
||||
"sourceSha256": "9379bc7c71cd6c1ff287f5771a78590a2e25b8dead05e78c563ff25ee8d1c207"
|
||||
},
|
||||
{
|
||||
"id": "F5-shopvisit",
|
||||
"family": "imported-struct-construction",
|
||||
"description": "Imported ShopVisit, alias=None, positional=False",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { ShopVisit } from @caseapp:scene;\nimport { Link } from @caseapp:link;\ndeclare global scene: ShopVisit = new ShopVisit.make(10);\n[Frame] fn frame() -> void { let value=Link.read(scene); if value!=10 { let failure=1/0; } }\n",
|
||||
"src/scene/mod.barrel": "pub struct ShopVisit;\n",
|
||||
"src/scene/main.pbs": "declare struct ShopVisit(value: int) { ctor make(value: int) { this.value=value; } fn read() -> int { return this.value; } }\n",
|
||||
"src/link/mod.barrel": "pub service Link;\n",
|
||||
"src/link/main.pbs": "import { ShopVisit } from @caseapp:scene;\ndeclare service Link { fn read(scene: ShopVisit) -> int { return scene.read(); } }\n"
|
||||
},
|
||||
"sourceSha256": "5373eaa6bece79658cb4cbd74fecc47d7d2a5954eee1812576243155fecb4c38"
|
||||
},
|
||||
{
|
||||
"id": "F5-scene",
|
||||
"family": "imported-struct-construction",
|
||||
"description": "Imported Scene, alias=None, positional=False",
|
||||
"control": "F5-shopvisit",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { Scene } from @caseapp:scene;\nimport { Link } from @caseapp:link;\ndeclare global scene: Scene = new Scene.make(10);\n[Frame] fn frame() -> void { let value=Link.read(scene); if value!=10 { let failure=1/0; } }\n",
|
||||
"src/scene/mod.barrel": "pub struct Scene;\n",
|
||||
"src/scene/main.pbs": "declare struct Scene(value: int) { ctor make(value: int) { this.value=value; } fn read() -> int { return this.value; } }\n",
|
||||
"src/link/mod.barrel": "pub service Link;\n",
|
||||
"src/link/main.pbs": "import { Scene } from @caseapp:scene;\ndeclare service Link { fn read(scene: Scene) -> int { return scene.read(); } }\n"
|
||||
},
|
||||
"sourceSha256": "f84b4a4f6eb21100dfff74f26e4f453d4300d3e2dd79d70ee9b3992ed4c8d09f"
|
||||
},
|
||||
{
|
||||
"id": "F5-scene-alias",
|
||||
"family": "imported-struct-construction",
|
||||
"description": "Imported Scene, alias=WorldScene, positional=False",
|
||||
"control": "F5-shopvisit",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { Scene as WorldScene } from @caseapp:scene;\nimport { Link } from @caseapp:link;\ndeclare global scene: WorldScene = new WorldScene.make(10);\n[Frame] fn frame() -> void { let value=Link.read(scene); if value!=10 { let failure=1/0; } }\n",
|
||||
"src/scene/mod.barrel": "pub struct Scene;\n",
|
||||
"src/scene/main.pbs": "declare struct Scene(value: int) { ctor make(value: int) { this.value=value; } fn read() -> int { return this.value; } }\n",
|
||||
"src/link/mod.barrel": "pub service Link;\n",
|
||||
"src/link/main.pbs": "import { Scene } from @caseapp:scene;\ndeclare service Link { fn read(scene: Scene) -> int { return scene.read(); } }\n"
|
||||
},
|
||||
"sourceSha256": "0f53a73f0f969919df0ad0df8a93e5b8e8db552310b69d37cae0f3ff9d625959"
|
||||
},
|
||||
{
|
||||
"id": "F5-scene-positional",
|
||||
"family": "imported-struct-construction",
|
||||
"description": "Imported Scene, alias=None, positional=True",
|
||||
"control": "F5-shopvisit",
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "passed",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "import { Scene } from @caseapp:scene;\nimport { Link } from @caseapp:link;\ndeclare global scene: Scene = new Scene(10);\n[Frame] fn frame() -> void { let value=Link.read(scene); if value!=10 { let failure=1/0; } }\n",
|
||||
"src/scene/mod.barrel": "pub struct Scene;\n",
|
||||
"src/scene/main.pbs": "declare struct Scene(value: int) { ctor make(value: int) { this.value=value; } fn read() -> int { return this.value; } }\n",
|
||||
"src/link/mod.barrel": "pub service Link;\n",
|
||||
"src/link/main.pbs": "import { Scene } from @caseapp:scene;\ndeclare service Link { fn read(scene: Scene) -> int { return scene.read(); } }\n"
|
||||
},
|
||||
"sourceSha256": "65b3452b0e30037b1e744de8e36dc629f2f5d11f5fb97068566d1a4b38baaeb7"
|
||||
},
|
||||
{
|
||||
"id": "runtime-trap-control",
|
||||
"family": "harness-control",
|
||||
"description": "Deliberate guest fault proves frame assertions are executed",
|
||||
"control": null,
|
||||
"expectedCompile": "compiled",
|
||||
"expectedRuntime": "fault",
|
||||
"files": {
|
||||
"prometeu.json": "{\n \"name\": \"caseapp\",\n \"version\": \"1.0.0\",\n \"language\": \"pbs\",\n \"stdlib\": \"1\",\n \"target\": \"Game\",\n \"dependencies\": []\n}\n",
|
||||
"src/mod.barrel": "pub fn frame() -> void;\n",
|
||||
"src/main.pbs": "[Frame] fn frame() -> void { let failure=1/0; }\n"
|
||||
},
|
||||
"sourceSha256": "60013483001b50eb3e7f8a9360142ec5ab49f8ca56edf1d6b0ca5b32251510d9"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user