|
| 1 | +import java.nio.file.Files; |
| 2 | +import java.nio.file.Path; |
| 3 | + |
1 | 4 | import airhacks.zsmith.agent.boundary.Agent; |
| 5 | +import airhacks.zsmith.configuration.control.ZCfg; |
2 | 6 | import airhacks.zsmith.subagent.control.SubAgentTool; |
3 | 7 |
|
4 | | -void main() { |
| 8 | +void main() throws Exception { |
5 | 9 | var child = new Agent("researcher", "You are a research assistant."); |
6 | 10 | var tool = new SubAgentTool(child); |
7 | 11 |
|
@@ -35,4 +39,34 @@ void main() { |
35 | 39 | var result = shallowTool.execute(new org.json.JSONObject().put("task", "test")); |
36 | 40 | assert result.contains("Error") && result.contains("depth") |
37 | 41 | : "expected depth error but got: " + result; |
| 42 | + |
| 43 | + // adaptive parallel: first run sequential, subsequent runs parallel |
| 44 | + var sandboxHome = Files.createTempDirectory("zsmith-subagent-test"); |
| 45 | + var originalHome = System.getProperty("user.home"); |
| 46 | + System.setProperty("user.home", sandboxHome.toString()); |
| 47 | + try { |
| 48 | + var firstRunChild = new Agent("first-run-probe", "test"); |
| 49 | + var firstRunTool = new SubAgentTool(firstRunChild); |
| 50 | + |
| 51 | + var markerPath = Path.of(sandboxHome.toString(), "." + ZCfg.APP_NAME, |
| 52 | + "first-run-probe", ".first_run_completed"); |
| 53 | + Files.deleteIfExists(markerPath); |
| 54 | + |
| 55 | + // runParallel=true but no marker yet → sequential |
| 56 | + assert !firstRunTool.parallel() |
| 57 | + : "expected parallel()=false on first run (no marker)"; |
| 58 | + |
| 59 | + // simulate completion of a first successful run |
| 60 | + Files.createDirectories(markerPath.getParent()); |
| 61 | + Files.writeString(markerPath, ""); |
| 62 | + assert firstRunTool.parallel() |
| 63 | + : "expected parallel()=true once marker exists"; |
| 64 | + |
| 65 | + // sequential override always wins, even with marker |
| 66 | + var sequentialTool = new SubAgentTool(firstRunChild, false); |
| 67 | + assert !sequentialTool.parallel() |
| 68 | + : "expected parallel()=false when runParallel=false regardless of marker"; |
| 69 | + } finally { |
| 70 | + System.setProperty("user.home", originalHome); |
| 71 | + } |
38 | 72 | } |
0 commit comments