feat(studio): show executed source diagnostics in UI2
Capture bounded compiler inputs by revision and PBX identity, consume Play v2 faults and retain static diagnostic excerpts across failed preparation. Integrate the UI2 panel, qualification evidence and regression tests without adding an editor.
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package p.studio.api.execution;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/** Static presentation values: no editor document, live path or source-opening port. */
|
||||
public record ExecutionDiagnostic(RuntimeDiagnostic fault, Excerpt excerpt) {
|
||||
public record Excerpt(String buildId, String logicalPath, String sourceKind, String revision,
|
||||
int line, int column, String text, boolean truncated, String availability) { }
|
||||
public ExecutionDiagnostic { Objects.requireNonNull(fault); Objects.requireNonNull(excerpt); }
|
||||
}
|
||||
@@ -13,6 +13,11 @@ public interface ExecutionSession extends AutoCloseable {
|
||||
|
||||
void beginPreparationCycle();
|
||||
|
||||
default void prepareSources(String runId, ExecutionSources sources) { }
|
||||
default void admitSources(String runId, String programSha256) { }
|
||||
default void discardCandidate(String runId) { }
|
||||
default void recordDiagnostic(RuntimeDiagnostic diagnostic) { }
|
||||
|
||||
void transitionToPrepareFailed();
|
||||
|
||||
void transitionToConnecting();
|
||||
|
||||
@@ -3,9 +3,11 @@ package p.studio.api.execution;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public record ExecutionSnapshot(ExecutionState state, List<ExecutionLogEntry> logs) {
|
||||
public record ExecutionSnapshot(ExecutionState state, List<ExecutionLogEntry> logs, List<ExecutionDiagnostic> diagnostics) {
|
||||
public ExecutionSnapshot(ExecutionState state, List<ExecutionLogEntry> logs) { this(state, logs, List.of()); }
|
||||
public ExecutionSnapshot {
|
||||
Objects.requireNonNull(state, "state");
|
||||
logs = List.copyOf(Objects.requireNonNull(logs, "logs"));
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package p.studio.api.execution;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
|
||||
/** Bounded immutable input of one compilation, consumed by interactive execution. */
|
||||
public record ExecutionSources(String buildId, String programSha256, Map<Integer, Source> sources) {
|
||||
public static final int MAX_FILE_BYTES = 4 * 1024 * 1024;
|
||||
public static final int MAX_FILES = 1024;
|
||||
public static final int MAX_CAPTURE_BYTES = 16 * 1024 * 1024;
|
||||
public static final ExecutionSources EMPTY = new ExecutionSources("", "", Map.of());
|
||||
|
||||
public record Source(int fileId, int projectId, String path, String logicalPath,
|
||||
String kind, String sha256, String text) {
|
||||
public Source {
|
||||
if (fileId < 0 || projectId < 0) throw new IllegalArgumentException("Invalid source identity");
|
||||
Objects.requireNonNull(path); Objects.requireNonNull(logicalPath); Objects.requireNonNull(kind);
|
||||
Objects.requireNonNull(sha256); Objects.requireNonNull(text);
|
||||
if (!Set.of("source","dependency","sdk","generated").contains(kind))
|
||||
throw new IllegalArgumentException("Invalid execution source kind");
|
||||
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
|
||||
if (bytes.length > MAX_FILE_BYTES || !digest(bytes).equals(sha256))
|
||||
throw new IllegalArgumentException("Invalid execution source size/revision");
|
||||
}
|
||||
}
|
||||
|
||||
public ExecutionSources {
|
||||
Objects.requireNonNull(buildId); Objects.requireNonNull(programSha256); Objects.requireNonNull(sources);
|
||||
if (!programSha256.isEmpty() && !programSha256.matches("[0-9a-f]{64}"))
|
||||
throw new IllegalArgumentException("Invalid program identity");
|
||||
if (sources.size() > MAX_FILES) throw new IllegalArgumentException("Execution source count limit");
|
||||
long bytes = buildId.getBytes(StandardCharsets.UTF_8).length + programSha256.length() + 16L;
|
||||
if (bytes > MAX_CAPTURE_BYTES) throw new IllegalArgumentException("Execution source capture metadata limit");
|
||||
for (var e : sources.entrySet()) {
|
||||
var s = Objects.requireNonNull(e.getValue());
|
||||
if (e.getKey() != s.fileId()) throw new IllegalArgumentException("Mismatched source ID");
|
||||
bytes += s.text().getBytes(StandardCharsets.UTF_8).length + s.path().getBytes(StandardCharsets.UTF_8).length
|
||||
+ s.logicalPath().getBytes(StandardCharsets.UTF_8).length + 128L;
|
||||
if (bytes > MAX_CAPTURE_BYTES) throw new IllegalArgumentException("Execution source capture byte limit");
|
||||
}
|
||||
sources = Map.copyOf(sources);
|
||||
}
|
||||
|
||||
public static String digest(byte[] bytes) {
|
||||
try { return HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes)); }
|
||||
catch (java.security.NoSuchAlgorithmException impossible) { throw new IllegalStateException(impossible); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package p.studio.api.execution;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import p.studio.api.values.ValueMaps;
|
||||
|
||||
/** Machine facts of a single authenticated Play execution, independent of JavaFX. */
|
||||
public record RuntimeDiagnostic(String runId, String programSha256, String kind, String message,
|
||||
Long pc, Long code, Long opcode, Span span, boolean truncated,
|
||||
Map<String, Object> facts) {
|
||||
public static RuntimeDiagnostic failure(String runId, String kind, String message) {
|
||||
byte[] bytes=message.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
||||
boolean truncated=bytes.length>8192;
|
||||
if(truncated) {
|
||||
int end=8192;
|
||||
while((bytes[end]&0xc0)==0x80)end--;
|
||||
message=new String(bytes,0,end,java.nio.charset.StandardCharsets.UTF_8);
|
||||
}
|
||||
return new RuntimeDiagnostic(runId,"",kind,message,null,null,null,null,truncated,Map.of());
|
||||
}
|
||||
public record Span(long fileId, long start, long end) {
|
||||
public Span { if (fileId < 0 || fileId > 0xffff_ffffL || start < 0 || end < start || end > 0xffff_ffffL)
|
||||
throw new IllegalArgumentException("Invalid source span"); }
|
||||
}
|
||||
public RuntimeDiagnostic {
|
||||
Objects.requireNonNull(runId); Objects.requireNonNull(programSha256); Objects.requireNonNull(kind); Objects.requireNonNull(message);
|
||||
if (!runId.matches("[0-9a-f]{32}") || (!programSha256.isEmpty() && !programSha256.matches("[0-9a-f]{64}")))
|
||||
throw new IllegalArgumentException("Invalid execution identity");
|
||||
if (pc != null && (pc < 0 || pc > 0xffff_ffffL)) throw new IllegalArgumentException("Invalid PC");
|
||||
facts = ValueMaps.object(facts == null ? Map.of() : facts);
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,14 @@ public record ShipperPrepareResult(
|
||||
List<String> diagnostics,
|
||||
List<StudioDiagnostic> issues,
|
||||
Map<String, Object> summary,
|
||||
Map<String, Object> context) {
|
||||
Map<String, Object> context,
|
||||
p.studio.api.execution.ExecutionSources executionSources) {
|
||||
public ShipperPrepareResult(ShipperPreparationStatus status, List<ShipperLogEntry> logs, Path manifestPath,
|
||||
List<Path> emittedArtifacts, List<String> diagnostics, List<StudioDiagnostic> issues,
|
||||
Map<String, Object> summary, Map<String, Object> context) {
|
||||
this(status, logs, manifestPath, emittedArtifacts, diagnostics, issues, summary, context,
|
||||
p.studio.api.execution.ExecutionSources.EMPTY);
|
||||
}
|
||||
public ShipperPrepareResult(ShipperPreparationStatus status, List<ShipperLogEntry> logs, Path manifestPath,
|
||||
List<Path> emittedArtifacts, List<String> diagnostics) {
|
||||
this(status, logs, manifestPath, emittedArtifacts, diagnostics, List.of(), DiagnosticValues.legacySummary("build"), Map.of());
|
||||
@@ -28,6 +35,7 @@ public record ShipperPrepareResult(
|
||||
emittedArtifacts = List.copyOf(Objects.requireNonNull(emittedArtifacts, "emittedArtifacts"));
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
issues = List.copyOf(issues); summary = ValueMaps.object(summary); context = ValueMaps.object(context);
|
||||
Objects.requireNonNull(executionSources);
|
||||
}
|
||||
|
||||
public Map<String, Object> diagnosticView() {
|
||||
@@ -36,7 +44,11 @@ public record ShipperPrepareResult(
|
||||
|
||||
public ShipperPrepareResult withContext(Map<String, Object> additions) {
|
||||
var merged = new java.util.LinkedHashMap<>(context); merged.putAll(additions);
|
||||
return new ShipperPrepareResult(status, logs, manifestPath, emittedArtifacts, diagnostics, issues, summary, merged);
|
||||
return new ShipperPrepareResult(status, logs, manifestPath, emittedArtifacts, diagnostics, issues, summary, merged, executionSources);
|
||||
}
|
||||
|
||||
public ShipperPrepareResult withExecutionSources(p.studio.api.execution.ExecutionSources sources) {
|
||||
return new ShipperPrepareResult(status, logs, manifestPath, emittedArtifacts, diagnostics, issues, summary, context, sources);
|
||||
}
|
||||
|
||||
public ShipperPrepareResult asCancelled() {
|
||||
|
||||
Reference in New Issue
Block a user