Files
prometeu-studio/prometeu-app/src/test/java/p/studio/app/acp/CodexAcpSmokeTest.java
T
bquarkz ae7d01aa99
Test / Tests and coverage
Intrepid/Prometeu/Studio/pipeline/head This commit looks good
feat(studio): add AI workspace with Codex ACP integration
2026-11-23 03:11:33 +00:00

55 lines
3.6 KiB
Java

package p.studio.app.acp;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import p.studio.api.ai.*;
import java.nio.file.*;
import java.util.*;
import java.util.concurrent.*;
import static org.junit.jupiter.api.Assertions.*;
/** Explicit live gate. Uses the user's existing ChatGPT session; never runs in ordinary tests. */
class CodexAcpSmokeTest {
@TempDir Path project;
private AcpSettings settings(){
String executable=System.getProperty("studio.test.codexAcp","");
return executable.isBlank()?new p.studio.core.project.preferences.JsonAgentSettingsStore(
Path.of(System.getProperty("user.home"),".prometeu-studio","ai-settings.json"),new ObjectMapper()).load()
:new AcpSettings(executable,List.of());
}
@Test void existingChatGptLoginCanAnswerThroughThePinnedAdapter()throws Exception {
var c=new CodexAcpConnection(project,new ObjectMapper());
var output=new CopyOnWriteArrayList<String>();c.events(e->{if(e.kind()==AgentConnection.Kind.TEXT)output.add(e.text());});
try{
c.connect(settings()).toCompletableFuture().get(40,TimeUnit.SECONDS);
long end=System.nanoTime()+TimeUnit.SECONDS.toNanos(20);
while(c.status().state()!=AgentConnection.State.READY&&System.nanoTime()<end)Thread.sleep(50);
assertEquals(AgentConnection.State.READY,c.status().state(),"Existing ChatGPT login must be recognized; smoke never opens browser login");
String session=c.newSession().toCompletableFuture().get(40,TimeUnit.SECONDS);
assertEquals("end_turn",c.prompt(session,"Responda apenas OK. Não use ferramentas, não leia nem altere arquivos, não execute comandos.")
.completion().toCompletableFuture().get(120,TimeUnit.SECONDS));
assertFalse(String.join("",output).isBlank());
try(var files=Files.list(project)){assertEquals(0,files.count(),"Minimal conversation must not alter project files");}
}finally{c.closeAsync().toCompletableFuture().get(25,TimeUnit.SECONDS);}
assertEquals(AgentConnection.State.CLOSED,c.status().state());
System.out.println("Live Codex ACP: initialized v1, existing ChatGPT login recognized, workspace-write session answered, project unchanged, owned process tree stopped.");
}
@Test void sameGlobalInstallationConnectsFromTheSelectedExistingProject()throws Exception {
String root=System.getProperty("studio.test.codexProject","");
org.junit.jupiter.api.Assumptions.assumeFalse(root.isBlank(),"Optional existing-project connection qualification");
assertTrue(Files.isDirectory(Path.of(root)));
var c=new CodexAcpConnection(Path.of(root),new ObjectMapper());
try{
c.connect(settings()).toCompletableFuture().get(40,TimeUnit.SECONDS);
long end=System.nanoTime()+TimeUnit.SECONDS.toNanos(20);
while(c.status().state()!=AgentConnection.State.READY&&System.nanoTime()<end)Thread.sleep(50);
assertEquals(AgentConnection.State.READY,c.status().state());
assertFalse(c.newSession().toCompletableFuture().get(40,TimeUnit.SECONDS).isBlank());
// No prompt or tools are sent to the real project.
}finally{c.closeAsync().toCompletableFuture().get(25,TimeUnit.SECONDS);}
assertEquals(AgentConnection.State.CLOSED,c.status().state());
System.out.println("Live existing-project ACP: same global configuration, existing ChatGPT login, project cwd session created, no prompt/tools, owned processes stopped.");
}
}