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:
+64
-2
@@ -22,6 +22,11 @@ public final class DefaultExecutionSession implements ExecutionSession {
|
||||
private final CopyOnWriteArrayList<Consumer<ExecutionSnapshot>> listeners = new CopyOnWriteArrayList<>();
|
||||
private ExecutionState state = ExecutionState.IDLE;
|
||||
private long nextSequence = 1L;
|
||||
private p.studio.api.execution.ExecutionSources retained = p.studio.api.execution.ExecutionSources.EMPTY;
|
||||
private p.studio.api.execution.ExecutionSources candidate = p.studio.api.execution.ExecutionSources.EMPTY;
|
||||
private String retainedRun = "", candidateRun = "";
|
||||
private boolean closed, retainedAcceptsDiagnostics;
|
||||
private p.studio.api.execution.ExecutionDiagnostic lastDiagnostic, attemptDiagnostic;
|
||||
|
||||
@Override
|
||||
public ExecutionSnapshot snapshot() {
|
||||
@@ -39,7 +44,56 @@ public final class DefaultExecutionSession implements ExecutionSession {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginPreparationCycle() { publish(transitionLocked(ExecutionState.PREPARING, true)); }
|
||||
public void beginPreparationCycle() {
|
||||
synchronized (monitor) {
|
||||
if (closed) throw new IllegalStateException("Execution session is closed");
|
||||
retainedAcceptsDiagnostics = false;
|
||||
candidate = p.studio.api.execution.ExecutionSources.EMPTY; candidateRun = ""; attemptDiagnostic = null;
|
||||
}
|
||||
publish(transitionLocked(ExecutionState.PREPARING, true));
|
||||
}
|
||||
|
||||
@Override public void prepareSources(String runId, p.studio.api.execution.ExecutionSources sources) {
|
||||
synchronized (monitor) { if (closed) return; candidateRun = runId; candidate = Objects.requireNonNull(sources); }
|
||||
}
|
||||
|
||||
@Override public void admitSources(String runId, String programSha256) {
|
||||
synchronized (monitor) {
|
||||
if (closed) throw new IllegalStateException("Execution session is closed");
|
||||
if (!candidateRun.equals(runId)) throw new IllegalStateException("Stale execution source admission");
|
||||
if (!candidate.programSha256().isEmpty() && !candidate.programSha256().equals(programSha256))
|
||||
throw new IllegalStateException("Loaded program does not match captured compilation");
|
||||
retained = candidate; retainedRun = runId; candidate = p.studio.api.execution.ExecutionSources.EMPTY;
|
||||
candidateRun = ""; lastDiagnostic = null; attemptDiagnostic = null;
|
||||
retainedAcceptsDiagnostics = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void discardCandidate(String runId) {
|
||||
synchronized (monitor) {
|
||||
if (candidateRun.equals(runId)) { candidateRun = ""; candidate = p.studio.api.execution.ExecutionSources.EMPTY; }
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void recordDiagnostic(p.studio.api.execution.RuntimeDiagnostic diagnostic) {
|
||||
final p.studio.api.execution.ExecutionSources source;
|
||||
synchronized (monitor) {
|
||||
if (retainedAcceptsDiagnostics && diagnostic.runId().equals(retainedRun)) source = retained;
|
||||
else if (diagnostic.runId().equals(candidateRun)) source = candidate;
|
||||
else return;
|
||||
}
|
||||
var resolved = ExecutionExcerpts.resolve(diagnostic, source);
|
||||
final ExecutionSnapshot snapshot;
|
||||
synchronized (monitor) {
|
||||
if (retainedAcceptsDiagnostics && diagnostic.runId().equals(retainedRun)) {
|
||||
if (lastDiagnostic == null) lastDiagnostic = resolved;
|
||||
} else if (diagnostic.runId().equals(candidateRun)) {
|
||||
if (attemptDiagnostic == null) attemptDiagnostic = resolved;
|
||||
} else return;
|
||||
snapshot = snapshotLocked();
|
||||
}
|
||||
publish(snapshot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transitionToPrepareFailed() { publish(transitionLocked(ExecutionState.PREPARE_FAILED, false)); }
|
||||
@@ -102,6 +156,11 @@ public final class DefaultExecutionSession implements ExecutionSession {
|
||||
transitionToStopped();
|
||||
}
|
||||
listeners.clear();
|
||||
synchronized (monitor) {
|
||||
closed = true; retainedAcceptsDiagnostics = false;
|
||||
retained = candidate = p.studio.api.execution.ExecutionSources.EMPTY;
|
||||
retainedRun = candidateRun = ""; lastDiagnostic = attemptDiagnostic = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void appendLog(ExecutionLogSource source, ExecutionLogSeverity severity, String message, Instant timestamp) {
|
||||
@@ -130,7 +189,10 @@ public final class DefaultExecutionSession implements ExecutionSession {
|
||||
}
|
||||
|
||||
private ExecutionSnapshot snapshotLocked() {
|
||||
return new ExecutionSnapshot(state, List.copyOf(logs));
|
||||
var diagnostics = new ArrayList<p.studio.api.execution.ExecutionDiagnostic>(2);
|
||||
if (attemptDiagnostic != null) diagnostics.add(attemptDiagnostic);
|
||||
if (lastDiagnostic != null) diagnostics.add(lastDiagnostic);
|
||||
return new ExecutionSnapshot(state, List.copyOf(logs), diagnostics);
|
||||
}
|
||||
|
||||
private static void ensureTransitionAllowed(ExecutionState current, ExecutionState next) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package p.studio.core.execution;
|
||||
|
||||
import p.studio.api.execution.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/** Resolves immutable consumed input on the service thread, never the FX thread. */
|
||||
final class ExecutionExcerpts {
|
||||
private ExecutionExcerpts() { }
|
||||
static ExecutionDiagnostic resolve(RuntimeDiagnostic fault, ExecutionSources capture) {
|
||||
var unavailable = new ExecutionDiagnostic.Excerpt(capture.buildId(), "", "", "", 0, 0, "", false, "no-span");
|
||||
if (fault.span() == null) return new ExecutionDiagnostic(fault, unavailable);
|
||||
String reason = "program-not-confirmed";
|
||||
if (!capture.programSha256().isEmpty() && capture.programSha256().equals(fault.programSha256())) {
|
||||
var source = fault.span().fileId() > Integer.MAX_VALUE ? null : capture.sources().get((int)fault.span().fileId());
|
||||
reason = "source-not-captured";
|
||||
if (source != null) {
|
||||
reason = "invalid-span";
|
||||
byte[] bytes = source.text().getBytes(StandardCharsets.UTF_8);
|
||||
if (fault.span().end() <= bytes.length) {
|
||||
try {
|
||||
String prefix = decode(bytes, 0, (int)fault.span().start());
|
||||
decode(bytes, (int)fault.span().start(), (int)(fault.span().end() - fault.span().start()));
|
||||
String text = source.text(); int focus = prefix.length();
|
||||
int line = 1 + (int) prefix.chars().filter(c -> c == '\n').count();
|
||||
int column = focus - prefix.lastIndexOf('\n');
|
||||
int lo = focus;
|
||||
for (int i = 0; i < 4 && lo > 0; i++) {
|
||||
int newline = text.lastIndexOf('\n', lo - 1);
|
||||
lo = newline < 0 ? 0 : newline;
|
||||
}
|
||||
if (lo > 0 && text.charAt(lo) == '\n') lo++;
|
||||
int hi = focus;
|
||||
for (int i = 0; i < 4 && hi < text.length(); i++) {
|
||||
int newline = text.indexOf('\n', hi);
|
||||
hi = newline < 0 ? text.length() : newline + 1;
|
||||
}
|
||||
int boundedLo = Math.max(lo, focus - 1024), boundedHi = Math.min(hi, focus + 3072);
|
||||
if (boundedLo > 0 && boundedLo < text.length() && Character.isLowSurrogate(text.charAt(boundedLo))) boundedLo--;
|
||||
if (boundedHi < text.length() && boundedHi > 0 && Character.isLowSurrogate(text.charAt(boundedHi))) boundedHi--;
|
||||
String excerpt = text.substring(boundedLo, boundedHi);
|
||||
while (excerpt.getBytes(StandardCharsets.UTF_8).length > 8192)
|
||||
excerpt = excerpt.substring(0, excerpt.offsetByCodePoints(excerpt.length(), -1));
|
||||
boolean truncated = boundedLo != lo || boundedHi != hi || excerpt.length() != boundedHi - boundedLo;
|
||||
return new ExecutionDiagnostic(fault, new ExecutionDiagnostic.Excerpt(capture.buildId(), source.logicalPath(),
|
||||
source.kind(), source.sha256(), line, column, excerpt, truncated, "available"));
|
||||
} catch (java.nio.charset.CharacterCodingException invalidBoundary) { /* Do not fabricate a location. */ }
|
||||
}
|
||||
}
|
||||
}
|
||||
return new ExecutionDiagnostic(fault, new ExecutionDiagnostic.Excerpt(capture.buildId(), "", "", "", 0, 0, "", false, reason));
|
||||
}
|
||||
|
||||
private static String decode(byte[] bytes, int offset, int count) throws java.nio.charset.CharacterCodingException {
|
||||
return StandardCharsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(bytes, offset, count)).toString();
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -22,6 +22,7 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
private Attempt attempt;
|
||||
private boolean closed;
|
||||
private static final class Attempt {
|
||||
final String runId=java.util.UUID.randomUUID().toString().replace("-","");
|
||||
final ManualLease lease;
|
||||
volatile RuntimeConnection connection;
|
||||
volatile OperationHandle<ExecutionSnapshot> play;
|
||||
@@ -45,6 +46,7 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
}
|
||||
Attempt a=new Attempt(access.enterExecution(project.rootPath()));attempt=a;
|
||||
a.lease.onProjectClose(()->stopAttempt(a));session.beginPreparationCycle();
|
||||
session.prepareSources(a.runId,ExecutionSources.EMPTY);
|
||||
try{a.play=operations.submit("Play "+project.name(),()->start(a));
|
||||
a.play.termination().whenComplete((v,f)->{synchronized(monitor){
|
||||
if(a.connection==null){if(a.stopping)stoppedWithoutProcess(a);release(a);}
|
||||
@@ -61,13 +63,21 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
ShipperPrepareResult prepared=a.preparation.completion().toCompletableFuture().join();
|
||||
a.preparation.termination().toCompletableFuture().join();
|
||||
if(a.stopping)return session.snapshot();
|
||||
if(!prepared.success()){session.transitionToPrepareFailed();return session.snapshot();}
|
||||
if(!prepared.success()){
|
||||
session.recordDiagnostic(RuntimeDiagnostic.failure(a.runId,"preparation",prepared.diagnostics().isEmpty()?"Preparation failed":prepared.diagnostics().toString()));
|
||||
session.transitionToPrepareFailed();return session.snapshot();
|
||||
}
|
||||
session.prepareSources(a.runId, prepared.executionSources());
|
||||
session.transitionToConnecting();
|
||||
RuntimeConnection connection=runtime.start(project,setup,
|
||||
log->session.appendRuntimeLog(log.severity(),log.message(),log.timestamp()),options);
|
||||
log->{synchronized(monitor){if(attempt==a&&!closed)session.appendRuntimeLog(log.severity(),log.message(),log.timestamp());}},
|
||||
options,a.runId,prepared.executionSources(),diagnostic->{synchronized(monitor){
|
||||
if(attempt==a&&!closed)session.recordDiagnostic(diagnostic);
|
||||
}});
|
||||
synchronized(monitor){a.connection=connection;}
|
||||
connection.completion().whenComplete((code,failure)->exited(a,connection,code,failure));
|
||||
if(a.stopping){connection.stopAsync().join();return session.snapshot();}
|
||||
session.admitSources(a.runId,connection.verifiedProgramSha256());
|
||||
boolean paused=a.pauseOnReady;
|
||||
if(paused)connection.pause().join();
|
||||
connection.startExecution().join();
|
||||
@@ -80,6 +90,8 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
} catch(Throwable failure){
|
||||
Throwable cause=cause(failure);
|
||||
synchronized(monitor){
|
||||
if(attempt==a&&!closed&&!a.stopping)session.recordDiagnostic(RuntimeDiagnostic.failure(a.runId,
|
||||
session.snapshot().state()==ExecutionState.PREPARING?"preparation":"connection",message(cause)));
|
||||
if(attempt==a&&a.connection==null){
|
||||
if(a.stopping){/* Actual worker termination owns the final state and lease. */}
|
||||
else {log("Play failed: "+message(cause));
|
||||
@@ -91,6 +103,7 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
OperationHandle<ShipperPrepareResult> preparation=a.preparation;
|
||||
if(preparation!=null)try{preparation.termination().toCompletableFuture().join();}catch(CompletionException|CancellationException ignored){}
|
||||
a.preparation=null;
|
||||
session.discardCandidate(a.runId);
|
||||
}
|
||||
return session.snapshot();
|
||||
}
|
||||
@@ -153,7 +166,11 @@ final class InteractiveExecutionController implements ExecutionController {
|
||||
if(a.connection!=connection)return;a.connection=null;
|
||||
if(attempt==a){
|
||||
if(failure==null&&code!=null&&code==0)session.transitionToStopped();
|
||||
else {log("Runtime ended: "+(failure==null?"exit "+code:message(cause(failure))));session.transitionToRuntimeFailed();}
|
||||
else {
|
||||
String detail=failure==null?"exit "+code:message(cause(failure));
|
||||
session.recordDiagnostic(RuntimeDiagnostic.failure(a.runId,"connection",detail));
|
||||
log("Runtime ended: "+detail);session.transitionToRuntimeFailed();
|
||||
}
|
||||
}
|
||||
if(a.play==null||a.play.termination().toCompletableFuture().isDone())release(a);
|
||||
else a.play.termination().whenComplete((v,f)->release(a));
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface RuntimeConnection extends AutoCloseable {
|
||||
CompletableFuture<Integer> completion();
|
||||
default String verifiedProgramSha256() { return ""; }
|
||||
|
||||
default CompletableFuture<Void> startExecution() { return CompletableFuture.completedFuture(null); }
|
||||
default CompletableFuture<Void> pause() { return CompletableFuture.failedFuture(new UnsupportedOperationException("Pause unavailable")); }
|
||||
|
||||
@@ -11,6 +11,11 @@ public interface RuntimeGateway {
|
||||
Consumer<RuntimeLogEntry> logs) throws Exception;
|
||||
|
||||
default boolean interactive() {return false;}
|
||||
default RuntimeConnection start(ProjectReference project, ProjectLocalStudioSetup setup,
|
||||
Consumer<RuntimeLogEntry> logs, p.studio.api.execution.PlayOptions options, String runId,
|
||||
p.studio.api.execution.ExecutionSources sources, Consumer<p.studio.api.execution.RuntimeDiagnostic> diagnostics) throws Exception {
|
||||
return start(project, setup, logs, options);
|
||||
}
|
||||
default RuntimeConnection start(ProjectReference project, ProjectLocalStudioSetup setup,
|
||||
Consumer<RuntimeLogEntry> logs,p.studio.api.execution.PlayOptions options) throws Exception {
|
||||
if(options.disposableSave())throw new UnsupportedOperationException("Disposable Play unavailable");
|
||||
|
||||
@@ -44,6 +44,7 @@ public final class DefaultTaskTools implements TaskTools {
|
||||
GuestTests.PRODUCTION.equals(entry.getValue().context().getOrDefault("targetId", GuestTests.PRODUCTION)));
|
||||
String candidateId = UUID.randomUUID().toString();
|
||||
var result = shipper.prepareNow(catalog.openProject(data.task.projectRoot()), new BuildSelection(selected, candidateId), ignored -> {})
|
||||
.withExecutionSources(p.studio.api.execution.ExecutionSources.EMPTY)
|
||||
.withContext(Map.of("targetId", selected));
|
||||
if (Thread.currentThread().isInterrupted() || record.handle != null && record.handle.snapshot().state() == OperationState.CANCELLED) result = result.asCancelled();
|
||||
if (result.success() && !Thread.currentThread().isInterrupted()) {
|
||||
|
||||
@@ -19,7 +19,12 @@ public interface CompilerBuildGateway {
|
||||
}
|
||||
|
||||
record CompilerBuildOutput(Path bytecodeArtifact, List<String> requiredCapabilities,
|
||||
List<StudioDiagnostic> issues, Map<String, Object> context) {
|
||||
List<StudioDiagnostic> issues, Map<String, Object> context,
|
||||
p.studio.api.execution.ExecutionSources executionSources) {
|
||||
public CompilerBuildOutput(Path bytecodeArtifact, List<String> requiredCapabilities,
|
||||
List<StudioDiagnostic> issues, Map<String, Object> context) {
|
||||
this(bytecodeArtifact, requiredCapabilities, issues, context, p.studio.api.execution.ExecutionSources.EMPTY);
|
||||
}
|
||||
public CompilerBuildOutput(Path bytecodeArtifact, List<String> requiredCapabilities) {
|
||||
this(bytecodeArtifact, requiredCapabilities, List.of(), Map.of());
|
||||
}
|
||||
@@ -27,6 +32,7 @@ public interface CompilerBuildGateway {
|
||||
bytecodeArtifact = bytecodeArtifact == null ? null : bytecodeArtifact.toAbsolutePath().normalize();
|
||||
requiredCapabilities = List.copyOf(requiredCapabilities);
|
||||
issues = List.copyOf(issues); context = p.studio.api.values.ValueMaps.object(context);
|
||||
executionSources = java.util.Objects.requireNonNull(executionSources);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public final class StudioShipperService implements Shipper, SavedProjectPreparat
|
||||
final Path stagedRoot = stage;
|
||||
return new ShipperPrepareResult(result.status(), result.logs(), destination.resolve(stagedRoot.relativize(result.manifestPath())),
|
||||
result.emittedArtifacts().stream().map(p -> destination.resolve(stagedRoot.relativize(p))).toList(),
|
||||
result.diagnostics(), result.issues(), result.summary(), result.context()).withContext(java.util.Map.of("buildProvenance", provenance));
|
||||
result.diagnostics(), result.issues(), result.summary(), result.context(), result.executionSources()).withContext(java.util.Map.of("buildProvenance", provenance));
|
||||
} catch (java.util.concurrent.CancellationException cancelled) {
|
||||
return ShipperPrepareResult.failed(List.of(), List.of("Test build cancelled before publication")).asCancelled();
|
||||
} catch (IOException | RuntimeException failure) {
|
||||
@@ -145,7 +145,7 @@ public final class StudioShipperService implements Shipper, SavedProjectPreparat
|
||||
}}
|
||||
checkCancelled();packer.publishWorkspaceFiles(new p.packer.messages.PublishWorkspaceFilesRequest(new PackerProjectContext(project.name(),project.rootPath()),java.util.UUID.randomUUID().toString(),edits));
|
||||
Path build=project.rootPath().resolve("build");return new ShipperPrepareResult(result.status(),result.logs(),build.resolve("manifest.json"),
|
||||
result.emittedArtifacts().stream().map(p->build.resolve(candidate.relativize(p))).toList(),result.diagnostics(),result.issues(),result.summary(),result.context());
|
||||
result.emittedArtifacts().stream().map(p->build.resolve(candidate.relativize(p))).toList(),result.diagnostics(),result.issues(),result.summary(),result.context(),result.executionSources());
|
||||
});
|
||||
}catch(Exception failure) {
|
||||
if(Thread.currentThread().isInterrupted()||failure instanceof java.util.concurrent.CancellationException)return ShipperPrepareResult.failed(List.of(),List.of("Production build cancelled before publication")).asCancelled();
|
||||
@@ -225,7 +225,8 @@ public final class StudioShipperService implements Shipper, SavedProjectPreparat
|
||||
current = "manifest"; stages.put(current, "running"); checkCancelled();
|
||||
var manifest = writeManifest(project, build, outputRoot, logs, sink); checkCancelled(); stages.put(current, "passed");
|
||||
AssetBuildQualification.write(mapper,outputRoot,capacity);
|
||||
return finish(ShipperPreparationStatus.SUCCESS, logs, manifest, artifacts, issues, stages, inputs, "passed");
|
||||
return finish(ShipperPreparationStatus.SUCCESS, logs, manifest, artifacts, issues, stages, inputs, "passed")
|
||||
.withExecutionSources(build.executionSources());
|
||||
} catch (java.util.concurrent.CancellationException cancelled) {
|
||||
stages.put(current, "cancelled");
|
||||
return finish(ShipperPreparationStatus.CANCELLED, logs, null, List.of(), issues, stages, inputs, "cancelled");
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
package p.studio.core.execution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.api.execution.*;
|
||||
import java.util.Map;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ExecutionDiagnosticsTest {
|
||||
private static final String RUN = "1".repeat(32), NEXT = "2".repeat(32), SHA = "a".repeat(64);
|
||||
private static final String TEXT = "// á 😀\r\nfn crash() { let value = 1 / 0; }\n";
|
||||
private static ExecutionSources sources() {
|
||||
return new ExecutionSources("build", SHA, Map.of(7, new ExecutionSources.Source(7, 0, "/virtual/source.pbs", "@generated/main.pbs", "generated",
|
||||
ExecutionSources.digest(TEXT.getBytes(StandardCharsets.UTF_8)), TEXT)));
|
||||
}
|
||||
private static RuntimeDiagnostic fault(String run, String sha, int start, int end) {
|
||||
return new RuntimeDiagnostic(run, sha, "vm_trap", "division by zero", 1L, 2L, 3L,
|
||||
new RuntimeDiagnostic.Span(7, start, end), false, Map.of());
|
||||
}
|
||||
@Test void retainedExecutionSurvivesFailedPreparationAndLateCallbacksCannotReplaceIt() {
|
||||
var session = new DefaultExecutionSession();session.beginPreparationCycle();
|
||||
session.prepareSources(RUN, sources()); session.admitSources(RUN, SHA);
|
||||
session.transitionToConnecting();session.transitionToRunning();
|
||||
int offset = TEXT.substring(0,TEXT.indexOf("1 / 0")).getBytes(StandardCharsets.UTF_8).length;
|
||||
session.recordDiagnostic(fault(RUN,SHA,offset,offset+5));session.transitionToRuntimeFailed();
|
||||
var first = session.snapshot().diagnostics().getFirst();
|
||||
assertEquals(2, first.excerpt().line());assertTrue(first.excerpt().text().contains("1 / 0"));
|
||||
assertEquals("available",first.excerpt().availability());
|
||||
session.beginPreparationCycle();session.prepareSources(NEXT, sources());session.discardCandidate(NEXT);session.transitionToPrepareFailed();
|
||||
assertEquals(first,session.snapshot().diagnostics().getFirst());
|
||||
session.recordDiagnostic(fault(NEXT,SHA,0,1));assertEquals(1,session.snapshot().diagnostics().size());
|
||||
session.beginPreparationCycle();session.prepareSources(NEXT,sources());session.admitSources(NEXT,SHA);
|
||||
assertTrue(session.snapshot().diagnostics().isEmpty());
|
||||
session.recordDiagnostic(fault(RUN,SHA,offset,offset+5));assertTrue(session.snapshot().diagnostics().isEmpty());
|
||||
session.close();session.recordDiagnostic(fault(NEXT,SHA,0,1));assertTrue(session.snapshot().diagnostics().isEmpty());
|
||||
}
|
||||
@Test void digestAndUtf8BoundariesMustMatchBeforeShowingLocation() {
|
||||
var session=new DefaultExecutionSession();session.prepareSources(RUN,sources());
|
||||
assertThrows(IllegalStateException.class,()->session.admitSources(RUN,"b".repeat(64)));
|
||||
assertEquals("program-not-confirmed",ExecutionExcerpts.resolve(fault(RUN,"b".repeat(64),0,1),sources()).excerpt().availability());
|
||||
int inside = TEXT.indexOf('á');
|
||||
assertEquals("invalid-span",ExecutionExcerpts.resolve(fault(RUN,SHA,inside+1,inside+2),sources()).excerpt().availability());
|
||||
assertThrows(IllegalArgumentException.class,()->new ExecutionSources.Source(0,0,"x","x","source",SHA,TEXT));
|
||||
}
|
||||
@Test void excerptsStayWithinSevenLinesAndEightKiBAndKeepTheFaultInView() {
|
||||
String text="before\n".repeat(8)+"😀".repeat(4000)+"1 / 0"+"é".repeat(10000)+"\r\n"+"after\n".repeat(8);
|
||||
var sources=new ExecutionSources("build",SHA,Map.of(7,new ExecutionSources.Source(7,0,"/virtual/x","@generated/x","generated",
|
||||
ExecutionSources.digest(text.getBytes(StandardCharsets.UTF_8)),text)));
|
||||
int offset=text.substring(0,text.indexOf("1 / 0")).getBytes(StandardCharsets.UTF_8).length;
|
||||
var resolved=ExecutionExcerpts.resolve(fault(RUN,SHA,offset,offset+5),sources).excerpt();
|
||||
assertEquals("available",resolved.availability());assertEquals(9,resolved.line());assertEquals(8001,resolved.column());
|
||||
assertTrue(resolved.text().contains("1 / 0"));assertTrue(resolved.truncated());
|
||||
assertTrue(resolved.text().lines().count()<=7);assertTrue(resolved.text().getBytes(StandardCharsets.UTF_8).length<=8192);
|
||||
assertFalse(resolved.text().contains("\ufffd"));
|
||||
}
|
||||
}
|
||||
+18
@@ -37,6 +37,24 @@ class InteractiveExecutionControllerTest {
|
||||
private RuntimeGateway gateway(Connection connection){return (p,s,l)->connection;}
|
||||
private ProjectReference project(){return new ProjectReference("Game","1","pbs",1,ProjectTarget.Game,root);}
|
||||
|
||||
@Test void failedCaptureCannotLaunchAnotherRuntimeOrEraseThePreviousDiagnostic() {
|
||||
var ops=new ControlledOperations();var state=new DefaultExecutionSession();var connection=new Connection();
|
||||
var launches=new java.util.concurrent.atomic.AtomicInteger();var builds=new java.util.concurrent.atomic.AtomicInteger();
|
||||
Shipper preparation=(p,l)->{
|
||||
if(builds.incrementAndGet()>1)throw new IllegalStateException("Execution source capture unavailable: capture byte limit");
|
||||
return done(new ShipperPrepareResult(ShipperPreparationStatus.SUCCESS,List.of(),root.resolve("manifest.json"),List.of(),List.of()));
|
||||
};
|
||||
RuntimeGateway runtime=(p,s,l)->{launches.incrementAndGet();return connection;};
|
||||
var controller=new InteractiveExecutionController(project(),ProjectLocalStudioSetup.defaults(),state,preparation,runtime,ops,new ProjectAccessRegistry(),PlayOptions.PERSISTENT);
|
||||
controller.play();ops.last.finish();connection.exit.completeExceptionally(new java.io.IOException("previous execution fault"));
|
||||
var previous=state.snapshot().diagnostics().getFirst();
|
||||
controller.play();ops.last.finish();
|
||||
assertEquals(1,launches.get());assertEquals(ExecutionState.PREPARE_FAILED,state.snapshot().state());
|
||||
assertEquals("preparation",state.snapshot().diagnostics().getFirst().fault().kind());
|
||||
assertTrue(state.snapshot().diagnostics().getFirst().fault().message().contains("capture byte limit"));
|
||||
assertEquals(previous,state.snapshot().diagnostics().getLast());assertFalse(controller.ownsExecution());
|
||||
}
|
||||
|
||||
@Test void buildAndLaunchReceiveTheSameFrozenEffectiveRuntime(){
|
||||
var ops=new ControlledOperations();var state=new DefaultExecutionSession();var connection=new Connection();
|
||||
var effective=new ProjectLocalStudioSetup("global-runtime",null);
|
||||
|
||||
Reference in New Issue
Block a user