compose real headless runtime with task build and lifecycle
This commit is contained in:
@@ -56,7 +56,7 @@ class McpTaskToolsTest {
|
||||
}
|
||||
@AfterEach void close() throws Exception {
|
||||
buildGate.countDown();
|
||||
if (runtime != null) runtime.gate.countDown();
|
||||
if (runtime != null) { runtime.gate.countDown(); runtime.shutdownGate.complete(null); }
|
||||
session.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||
workers.shutdownNow();
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class McpTaskToolsTest {
|
||||
JsonNode completed(String request) throws Exception {
|
||||
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
|
||||
JsonNode result;
|
||||
do { result = poll(request); if (!List.of("RUNNING", "PENDING").contains(result.path("state").asText())) return result; Thread.sleep(5); }
|
||||
do { result = poll(request); if (result.path("workerTerminated").asBoolean()) return result; Thread.sleep(5); }
|
||||
while (System.nanoTime() < deadline);
|
||||
fail("Operation did not finish: " + result); return null;
|
||||
}
|
||||
@@ -156,6 +156,34 @@ class McpTaskToolsTest {
|
||||
assertEquals(ControlState.AGENT_WORKING, session.snapshot().state());
|
||||
}
|
||||
|
||||
@Test void resetAllowsOnlyExplicitRebootOfTheSameKnownBuild() throws Exception {
|
||||
acquire(); String build = buildAndBoot();
|
||||
var original = runtime;
|
||||
error("BUSY", call("studio_headless_boot", args().put("buildId", build)));
|
||||
value(call("studio_headless_reset", args()));
|
||||
error("BUILD_NOT_FOUND", call("studio_headless_boot", args().put("buildId", "unknown")));
|
||||
value(call("studio_headless_boot", args().put("buildId", build)));
|
||||
assertSame(original, runtime);
|
||||
assertEquals(TaskTools.HeadlessAction.BOOT, runtime.lastAction);
|
||||
error("BUSY", call("studio_headless_boot", args().put("buildId", build)));
|
||||
}
|
||||
|
||||
@Test void rebuildWaitsForShutdownAcknowledgementBeforeTouchingArtifacts() throws Exception {
|
||||
acquire(); String build = buildAndBoot();
|
||||
runtime.shutdownGate = new CompletableFuture<>();
|
||||
failBuild = true;
|
||||
value(call("studio_build_start", args().put("clientRequestId", "blocked-rebuild")));
|
||||
assertTrue(runtime.shutdownEntered.await(2, TimeUnit.SECONDS));
|
||||
assertEquals(1, builds.get());
|
||||
assertFalse(poll("blocked-rebuild").path("workerTerminated").asBoolean());
|
||||
error("BUSY", call("studio_headless_boot", args().put("buildId", build)));
|
||||
runtime.shutdownGate.complete(null);
|
||||
assertEquals("FAILED", completed("blocked-rebuild").path("result").path("status").asText());
|
||||
assertEquals(2, builds.get());
|
||||
error("BUILD_NOT_FOUND", call("studio_headless_boot", args().put("buildId", build)));
|
||||
assertEquals(ControlState.AGENT_WORKING, session.snapshot().state());
|
||||
}
|
||||
|
||||
@Test void cancellationPreservesKnownProgressAndReclaimWaitsForWorkerTermination() throws Exception {
|
||||
acquire(); buildAndBoot(); runtime.hold = true;
|
||||
String operation = value(call("studio_headless_advance", args().put("clientRequestId", "long").put("frames", 50))).path("operationId").asText();
|
||||
@@ -354,18 +382,22 @@ class McpTaskToolsTest {
|
||||
final String id = UUID.randomUUID().toString(), build;
|
||||
final AtomicInteger advances = new AtomicInteger();
|
||||
final CountDownLatch entered = new CountDownLatch(1), gate = new CountDownLatch(1);
|
||||
final CountDownLatch shutdownEntered = new CountDownLatch(1);
|
||||
CompletableFuture<Void> shutdownGate = CompletableFuture.completedFuture(null);
|
||||
TaskTools.HeadlessAction lastAction;
|
||||
volatile boolean stopped, hold, cancelled;
|
||||
volatile AutomationOutcome.Kind kind = AutomationOutcome.Kind.SUCCEEDED;
|
||||
Map<String, Object> input;
|
||||
FakeRuntime(String build) { this.build = build; }
|
||||
public String sessionId() { return id; }
|
||||
public void cancel() { cancelled = true; }
|
||||
public CompletionStage<Void> shutdown() { stopped = true; return CompletableFuture.completedFuture(null); }
|
||||
public CompletionStage<Void> shutdown() { shutdownEntered.countDown(); return shutdownGate.thenRun(() -> stopped = true); }
|
||||
public long maxFramesPerAdvance() { return 600; }
|
||||
CanonicalCapture capture(long logical) { return new CanonicalCapture(id, build, logical, 900, 1, 1, 1,
|
||||
Base64.getDecoder().decode("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aK1kAAAAASUVORK5CYII=")); }
|
||||
public TaskTools.HeadlessReply call(TaskTools.HeadlessAction action, Map<String, Object> input) {
|
||||
this.input = input;
|
||||
lastAction = action;
|
||||
return new TaskTools.HeadlessReply(Map.of("sessionId", id), action == TaskTools.HeadlessAction.CAPTURE ? capture(5) : null);
|
||||
}
|
||||
public AutomationOutcome advance(long frames, Consumer<TrackedOperation.Progress> progress) {
|
||||
|
||||
Reference in New Issue
Block a user