feat: add agent coordination and automatic work completion
Add portable topics and surveys, decision approval history, execution plans, local Codex and Claude adapters, and general agent routing. Consolidate Plan and EPIC results through deterministic completion receipts, reviewed cancellation scope and recoverable reconciliation. Track the completed WRK-0001 and WRK-0002 records, protocol documentation, source manifests and delivery evidence. Validation: 117 tests including Modulith; GraalVM 25 native compilation, standalone smoke and ZIP/TAR verification on macOS ARM64; identical persisted context across JVM and native executions.
This commit is contained in:
@@ -30,7 +30,9 @@ class DiscussionMarkdownTest {
|
||||
assertThat(stored).contains("documentVersion: 2", "\n---\n\n" + prose).doesNotContain("\ntext:", "\\n");
|
||||
assertThat(new DiscussionService().list(root, "WRK-0001")).containsExactly(entry);
|
||||
var context = new VerificationService().context(root, "WRK-0001");
|
||||
assertThat(new VerificationService().markdown(context)).contains(prose, "### DSC-0001", "SUGGESTION").doesNotContain("text:", "\\n");
|
||||
String markdown = new VerificationService().markdown(context);
|
||||
String history = markdown.substring(markdown.indexOf("## Discussion history"), markdown.indexOf("## Discussion topics"));
|
||||
assertThat(history).contains(prose, "### DSC-0001", "SUGGESTION").doesNotContain("text:", "\\n");
|
||||
assertThat(context.discussionHistory().getFirst().text()).isEqualTo(prose);
|
||||
}
|
||||
@Test void legacyYamlRemainsReadableWithoutImplicitWrites() throws Exception {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class DiscussionRefinementTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int result = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return result;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
private Path work() { return root.resolve(".ai-engineering/works/WRK-0001-one"); }
|
||||
private void init() { ok("init", "--name", "Fixture"); ok("work", "create", "One", "--acceptance", "Continuity"); }
|
||||
@Test void legacyTopicViewDoesNotRewriteFilesAndSurveyAnswersKeepHistory() throws Exception {
|
||||
init(); byte[] original = Files.readAllBytes(work().resolve("work.md"));
|
||||
ok("topic", "list", "WRK-0001", "--format", "json"); assertThat(output).contains("main", "implicit");
|
||||
assertThat(Files.readAllBytes(work().resolve("work.md"))).isEqualTo(original);
|
||||
ok("discussion", "add", "WRK-0001", "--text", "Original idea");
|
||||
ok("topic", "create", "WRK-0001", "Rendering", "--source", "DSC-0001");
|
||||
ok("survey", "create", "WRK-0001", "--title", "Approach");
|
||||
ok("survey", "question", "WRK-0001", "SVY-0001", "--topic", "TOP-0001", "--text", "Which approach?", "--option", "Layers", "--option", "Single canvas", "--recommend", "1");
|
||||
assertThat(cli("work", "check", "WRK-0001")).isEqualTo(4);
|
||||
ok("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "2", "--text", "Initial answer");
|
||||
ok("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--text", "A third approach");
|
||||
ok("survey", "show", "WRK-0001", "SVY-0001", "--format", "json");
|
||||
assertThat(output).contains("Initial answer", "A third approach", "supersedes", "ANS-0001");
|
||||
ok("survey", "history", "WRK-0001", "SVY-0001", "--format", "json"); assertThat(output).contains("Initial answer");
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); String context = output;
|
||||
assertThat(context).contains("Rendering", "Which approach?", "A third approach", "\"outstandingQuestions\" : [ ]");
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); assertThat(output).isEqualTo(context);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void invalidSurveyInputAndCrossWorkReferencesHaveNoSideEffects() throws Exception {
|
||||
init(); ok("survey", "create", "WRK-0001", "--title", "Survey");
|
||||
byte[] before = Files.readAllBytes(work().resolve("surveys/SVY-0001.md"));
|
||||
assertThat(cli("survey", "question", "WRK-0001", "SVY-0001", "--text", "No suggestions")).isEqualTo(2);
|
||||
assertThat(cli("survey", "question", "WRK-0001", "SVY-0001", "--topic", "TOP-9999", "--text", "Wrong owner", "--option", "A")).isIn(2,3);
|
||||
assertThat(Files.readAllBytes(work().resolve("surveys/SVY-0001.md"))).isEqualTo(before);
|
||||
ok("survey", "question", "WRK-0001", "SVY-0001", "--text", "Choose", "--option", "A", "--option", "B");
|
||||
before = Files.readAllBytes(work().resolve("surveys/SVY-0001.md"));
|
||||
assertThat(cli("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "9")).isEqualTo(2);
|
||||
assertThat(cli("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "1", "--choice", "2")).isEqualTo(2);
|
||||
assertThat(Files.readAllBytes(work().resolve("surveys/SVY-0001.md"))).isEqualTo(before);
|
||||
ok("work", "create", "Two");
|
||||
assertThat(cli("survey", "show", "WRK-0002", "SVY-0001")).isEqualTo(3);
|
||||
}
|
||||
@Test void agentsContinuePersistedDiscussionAndCannotApproveDecisions() throws Exception {
|
||||
init(); ok("agent", "configure", "--adapter", "fixture-general", "--archive-policy", "reversible");
|
||||
ok("agent", "run", "WRK-0001", "--task", "Rendering: Compare approaches\nSaving: Preserve the format", "--request-id", "refine-one");
|
||||
ok("agent", "history", "WRK-0001", "--format", "json"); assertThat(output).contains("fixture-general", "COMPLETED");
|
||||
ok("survey", "list", "WRK-0001", "--format", "json"); assertThat(output).contains("SVY-0001", "QST-0001");
|
||||
ok("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "1", "--author", "fixture-human");
|
||||
Files.writeString(root.resolve("result.txt"), "Explicit test fixture observation\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Fixture observation");
|
||||
ok("agent", "configure", "--adapter", "fixture-reviewer", "--activity", "analyze");
|
||||
ok("agent", "run", "WRK-0001", "--activity", "analyze", "--task", "Review the fixture", "--request-id", "analyze-one");
|
||||
ok("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(output).contains("fixture-reviewer", "fixture-human", "DRAFT", "ARCHIVE", "ART-0001");
|
||||
ok("decision", "list", "WRK-0001", "--format", "json"); assertThat(output).contains("DRAFT").doesNotContain("ACCEPTED");
|
||||
String before = Files.readString(work().resolve("work.md"));
|
||||
ok("agent", "run", "WRK-0001", "--activity", "analyze", "--task", "Review the fixture", "--request-id", "analyze-one");
|
||||
assertThat(Files.readString(work().resolve("work.md"))).isEqualTo(before);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void unknownAdapterAndTamperedEvidenceAreRejectedBeforeApplication() throws Exception {
|
||||
init(); byte[] config = Files.readAllBytes(root.resolve(".ai-engineering/ai-engineering.yaml"));
|
||||
assertThat(cli("agent", "configure", "--adapter", "unknown")).isEqualTo(2);
|
||||
assertThat(Files.readAllBytes(root.resolve(".ai-engineering/ai-engineering.yaml"))).isEqualTo(config);
|
||||
ok("agent", "configure", "--adapter", "fixture-general", "--archive-policy", "reversible");
|
||||
ok("agent", "run", "WRK-0001", "--task", "Topic: An idea");
|
||||
Files.writeString(root.resolve("result.txt"), "Fixture\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Fixture");
|
||||
Files.writeString(work().resolve("artifacts/evidence/ART-0001/payload"), "Tampered");
|
||||
byte[] before = Files.readAllBytes(work().resolve("work.md"));
|
||||
assertThat(cli("agent", "run", "WRK-0001", "--activity", "analyze", "--task", "Analyze")).isEqualTo(4);
|
||||
assertThat(Files.readAllBytes(work().resolve("work.md"))).isEqualTo(before);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.discussion.DiscussionService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class DiscussionTextFileTest {
|
||||
@TempDir Path root;
|
||||
@TempDir Path drafts;
|
||||
private String output;
|
||||
private int cli(Path cwd, String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(cwd).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(root, args); assertThat(code).as(output).isZero(); }
|
||||
private void initialize() { ok("init", "--name", "Test"); ok("work", "create", "One"); }
|
||||
@Test void importsExactUtf8TextRelativeToInvocationDirectoryAndPersistsIndependently() throws Exception {
|
||||
initialize(); ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "Which approach?");
|
||||
String prose = "\n## Proposta — árvore 日本語\r\n\r\n- First limit\n- Second limit\n\n```yaml\n---\nkey: value\n```\n";
|
||||
Path file = Files.writeString(drafts.resolve("proposal.md"), prose);
|
||||
assertThat(cli(drafts, "--project", root.toString(), "discussion", "add", "WRK-0001", "--text-file", "proposal.md",
|
||||
"--author", "agent", "--kind", "SUGGESTION", "--responds-to", "DSC-0001")).as(output).isZero();
|
||||
assertThat(output).contains("documentVersion: 2", prose);
|
||||
var entries = new DiscussionService().list(root, "WRK-0001");
|
||||
assertThat(entries).hasSize(2); assertThat(entries.getLast().text()).isEqualTo(prose);
|
||||
assertThat(entries.getLast().author()).isEqualTo("agent"); assertThat(entries.getLast().respondsTo()).isEqualTo("DSC-0001");
|
||||
assertThat(Files.readString(file)).isEqualTo(prose); Files.delete(file);
|
||||
ok("work", "context", "WRK-0001"); assertThat(output).contains(prose);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void requiresExactlyOneTextSourceAndDoesNotAppendOnFailure() throws Exception {
|
||||
initialize(); Path file = Files.writeString(drafts.resolve("proposal.md"), "Proposal");
|
||||
assertThat(cli(root, "discussion", "add", "WRK-0001")).isEqualTo(2);
|
||||
assertThat(cli(root, "discussion", "add", "WRK-0001", "--text", "Inline", "--text-file", file.toString())).isEqualTo(2);
|
||||
assertThat(new DiscussionService().list(root, "WRK-0001")).isEmpty();
|
||||
}
|
||||
@Test void missingInvalidEmptyAndOversizedSourcesProduceUsefulFailures() throws Exception {
|
||||
initialize(); Path malformed = Files.write(drafts.resolve("malformed.md"), new byte[]{(byte) 0xc3, 0x28});
|
||||
Path empty = Files.writeString(drafts.resolve("empty.md"), " \n\t");
|
||||
Path large = Files.write(drafts.resolve("large.md"), new byte[1024 * 1024 + 1]);
|
||||
assertThat(cli(root, "discussion", "add", "WRK-0001", "--text-file", drafts.resolve("missing.md").toString())).isEqualTo(3);
|
||||
assertThat(output).contains("missing.md");
|
||||
for (Path input : List.of(drafts, malformed, empty, large))
|
||||
assertThat(cli(root, "discussion", "add", "WRK-0001", "--text-file", input.toString())).as(output).isEqualTo(2);
|
||||
assertThat(new DiscussionService().list(root, "WRK-0001")).isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class EpicSafetyTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
private Work work(String id) { return new WorkService().load(root, id); }
|
||||
private Path folder(String id) { return new WorkService().folder(root, id); }
|
||||
private void init() throws Exception {
|
||||
ok("init", "--name", "Safety");
|
||||
for (String name : new String[]{"Parent", "Child", "Other"}) ok("work", "create", name, "--acceptance", "Reviewed fixture result");
|
||||
Files.writeString(root.resolve("evidence.txt"), "Synthetic observation\n");
|
||||
}
|
||||
private void setup() {
|
||||
ok("epic", "configure", "WRK-0001", "--by", "agent", "--reason", "Coordinate");
|
||||
ok("epic", "link", "WRK-0001", "WRK-0002", "--by", "agent", "--reason", "Scope");
|
||||
authorize();
|
||||
}
|
||||
private void authorize() { ok("epic", "authorize", "WRK-0001", "--by", "fixture-owner", "--reason", "Explicit delegation for this scope", "--human-approved"); }
|
||||
private void complete(String id) {
|
||||
ok("artifact", "add", id, "--file", "evidence.txt", "--purpose", "Fixture evidence");
|
||||
String artifact = work(id).artifacts().getLast();
|
||||
ok("work", "complete", id, "--by", "fixture-owner", "--summary", "Reviewed fixture", "--human-approved",
|
||||
"--criterion", "1=" + artifact, "--no-integration-needed", "Disposable fixture");
|
||||
}
|
||||
@Test void changedChildScopeRequiresNewAuthorityBeforeAutomaticCompletion() throws Exception {
|
||||
init(); setup(); var initial = new EpicService().get(root, "WRK-0001").authorization();
|
||||
ok("work", "update", "WRK-0002", "--goal", "A newly reviewed scope"); complete("WRK-0002");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.OPEN);
|
||||
assertThat(cli("epic", "check", "WRK-0001")).isEqualTo(4); assertThat(output).contains("authorize");
|
||||
authorize(); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(new EpicService().get(root, "WRK-0001").authorization().scopeHash()).isNotEqualTo(initial.scopeHash());
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void questionsAndManualBlockedStatePreventAutomaticCompletion() throws Exception {
|
||||
init(); setup();
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "Is integration sufficient?");
|
||||
ok("work", "status", "WRK-0001", "BLOCKED"); complete("WRK-0002");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.BLOCKED);
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "RESPONSE", "--responds-to", "DSC-0001", "--text", "Reviewed in fixture");
|
||||
ok("work", "status", "WRK-0001", "ACTIVE");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED); assertThat(output).contains("COMPLETED");
|
||||
}
|
||||
@Test void emptyImportantSetCannotBeAuthorizedOrAutoCompleted() throws Exception {
|
||||
init(); ok("epic", "configure", "WRK-0001", "--by", "agent", "--reason", "No delivery yet");
|
||||
assertThat(cli("epic", "authorize", "WRK-0001", "--by", "owner", "--reason", "No children", "--human-approved")).isEqualTo(2);
|
||||
ok("epic", "reconcile", "WRK-0001"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.OPEN);
|
||||
assertThat(cli("epic", "check", "WRK-0001")).isEqualTo(4); assertThat(output).contains("important child");
|
||||
}
|
||||
@Test void explicitReopeningAllowsNewChildrenAndSuspendsOldAutomaticAuthority() throws Exception {
|
||||
init(); setup(); complete("WRK-0002");
|
||||
assertThat(cli("epic", "link", "WRK-0001", "WRK-0003", "--by", "agent", "--reason", "Late scope")).isEqualTo(2);
|
||||
ok("work", "reopen", "WRK-0001", "--by", "fixture-owner", "--reason", "Add another slice");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.ACTIVE);
|
||||
assertThat(new EpicService().get(root, "WRK-0001").authorization()).isNull();
|
||||
ok("epic", "link", "WRK-0001", "WRK-0003", "--by", "agent", "--reason", "Reviewed scope extension");
|
||||
complete("WRK-0003"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.ACTIVE);
|
||||
authorize(); assertThat(work("WRK-0001").completions()).hasSize(2); ok("project", "validate");
|
||||
}
|
||||
@Test void optionalChildReopeningDoesNotReopenACompletedEpic() throws Exception {
|
||||
init(); setup(); ok("epic", "link", "WRK-0001", "WRK-0003", "--by", "agent", "--reason", "Optional follow-up");
|
||||
ok("epic", "importance", "WRK-0001", "WRK-0003", "--optional", "--by", "owner", "--reason", "Not required"); authorize();
|
||||
complete("WRK-0003"); complete("WRK-0002");
|
||||
byte[] before = Files.readAllBytes(folder("WRK-0001").resolve("work.md"));
|
||||
ok("work", "reopen", "WRK-0003", "--by", "owner", "--reason", "Optional new evidence");
|
||||
assertThat(Files.readAllBytes(folder("WRK-0001").resolve("work.md"))).isEqualTo(before); ok("project", "validate");
|
||||
}
|
||||
@Test void policyHistoryTamperingIsDiagnosedBeforeChildCompletionWrites() throws Exception {
|
||||
init(); setup(); Files.writeString(folder("WRK-0001").resolve("epic/.history/WRK-0001/r0001.md"), "Tampered");
|
||||
ok("artifact", "add", "WRK-0002", "--file", "evidence.txt", "--purpose", "Fixture evidence");
|
||||
byte[] before = Files.readAllBytes(folder("WRK-0002").resolve("work.md"));
|
||||
assertThat(cli("work", "complete", "WRK-0002", "--by", "owner", "--summary", "Reviewed", "--human-approved",
|
||||
"--criterion", "1=ART-0001", "--no-integration-needed", "Fixture")).isEqualTo(4);
|
||||
assertThat(Files.readAllBytes(folder("WRK-0002").resolve("work.md"))).isEqualTo(before);
|
||||
assertThat(cli("project", "validate")).isEqualTo(4); assertThat(output).contains("history");
|
||||
}
|
||||
@Test void aPublishedAggregateReceiptIsReusedAfterInterruptedCompletion() throws Exception {
|
||||
init(); setup(); Work before = work("WRK-0001"); complete("WRK-0002");
|
||||
String receipt = work("WRK-0001").artifacts().getFirst();
|
||||
Documents.replaceFrontMatter(folder("WRK-0001").resolve("work.md"), before.reference("artifacts", receipt));
|
||||
ok("epic", "reconcile", "WRK-0001", "--requester", "resuming-agent");
|
||||
assertThat(work("WRK-0001").artifacts()).containsExactly(receipt); assertThat(work("WRK-0001").completions()).hasSize(1); ok("project", "validate");
|
||||
Files.writeString(folder("WRK-0001").resolve("artifacts/evidence/" + receipt + "/payload"), "Tampered receipt");
|
||||
assertThat(cli("work", "validate", "WRK-0001")).isEqualTo(4);
|
||||
}
|
||||
@Test void legacyCompletedWorkWithoutNewFieldsRetainsItsFrozenDigestAndBytes() throws Exception {
|
||||
init(); complete("WRK-0002"); Path file = folder("WRK-0002").resolve("work.md");
|
||||
String old = Files.readString(file).replaceAll("(?m)^epic: false\\n|^ origin: \"HUMAN\"\\n|^ delegation: null\\n", "");
|
||||
assertThat(old).doesNotContain("epic:", "origin:", "delegation:"); Files.writeString(file, old);
|
||||
ok("work", "validate", "WRK-0002"); ok("work", "context", "WRK-0002"); assertThat(Files.readString(file)).isEqualTo(old);
|
||||
}
|
||||
@Test void symlinkDefinitionDirectoryIsRefusedWithoutPublishingAnEpic() throws Exception {
|
||||
org.junit.jupiter.api.Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows"));
|
||||
init(); Path external = Files.createTempDirectory(root.getParent(), "aie-epic-external-");
|
||||
try {
|
||||
Files.createSymbolicLink(folder("WRK-0001").resolve("epic"), external);
|
||||
byte[] before = Files.readAllBytes(folder("WRK-0001").resolve("work.md"));
|
||||
assertThat(cli("epic", "configure", "WRK-0001", "--by", "agent", "--reason", "Unsafe")).isEqualTo(2);
|
||||
assertThat(Files.readAllBytes(folder("WRK-0001").resolve("work.md"))).isEqualTo(before);
|
||||
try (var files = Files.list(external)) { assertThat(files.toList()).isEmpty(); }
|
||||
} finally { Files.delete(folder("WRK-0001").resolve("epic")); Files.delete(external); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class EpicWorkflowTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { assertThat(cli(args)).as(output).isZero(); }
|
||||
private void init(int count) throws Exception {
|
||||
ok("init", "--name", "EPIC fixture");
|
||||
for (int i = 1; i <= count; i++) ok("work", "create", "Work " + i, "--acceptance", "Verified bounded delivery");
|
||||
Files.writeString(root.resolve("evidence.txt"), "Explicitly synthetic delivery evidence\n");
|
||||
}
|
||||
private void configure(String id, String mode) { ok("epic", "configure", id, "--mode", mode, "--by", "fixture-agent", "--reason", "Coordinate work"); }
|
||||
private void link(String epic, String child) { ok("epic", "link", epic, child, "--by", "fixture-agent", "--reason", "Decompose scope"); }
|
||||
private void authorize(String epic) { ok("epic", "authorize", epic, "--by", "fixture-owner", "--reason", "The important results satisfy these parent criteria", "--human-approved"); }
|
||||
private Work work(String id) { return new WorkService().load(root, id); }
|
||||
private Path folder(String id) { return new WorkService().folder(root, id); }
|
||||
private void complete(String id) {
|
||||
ok("artifact", "add", id, "--file", "evidence.txt", "--purpose", "Fixture result");
|
||||
int index = work(id).artifacts().size();
|
||||
ok("work", "complete", id, "--by", "fixture-owner", "--summary", "Reviewed fixture", "--human-approved",
|
||||
"--criterion", "1=ART-%04d".formatted(index), "--no-integration-needed", "Disposable fixture");
|
||||
}
|
||||
@Test void allChildrenAreImportantAndAutomaticCompletionHasSystemProvenance() throws Exception {
|
||||
init(3); configure("WRK-0001", "results"); link("WRK-0001", "WRK-0002"); link("WRK-0001", "WRK-0003"); authorize("WRK-0001");
|
||||
complete("WRK-0002"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.OPEN);
|
||||
assertThat(output).contains("WRK-0003", "epics");
|
||||
complete("WRK-0003"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
ok("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(output).contains("SYSTEM_EPIC", "\"humanApproved\" : false", "fixture-owner", "WRK-0002", "WRK-0003");
|
||||
String before = output; ok("work", "context", "WRK-0001", "--format", "json"); assertThat(output).isEqualTo(before);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void cancelledImportantWorkBlocksUntilExplicitPolicyReviewAndOptionalWorkMayStayOpen() throws Exception {
|
||||
init(4); configure("WRK-0001", "results");
|
||||
for (String child : List.of("WRK-0002", "WRK-0003", "WRK-0004")) link("WRK-0001", child);
|
||||
ok("epic", "importance", "WRK-0001", "WRK-0004", "--optional", "--by", "fixture-owner", "--reason", "Optional follow-up");
|
||||
authorize("WRK-0001"); complete("WRK-0002");
|
||||
ok("work", "status", "WRK-0003", "CANCELLED", "--by", "fixture-owner", "--reason", "Cannot deliver this scope");
|
||||
assertThat(cli("epic", "check", "WRK-0001", "--format", "json")).isEqualTo(4); assertThat(output).contains("WRK-0003", "CANCELLED");
|
||||
ok("epic", "importance", "WRK-0001", "WRK-0003", "--optional", "--by", "fixture-owner", "--reason", "Reviewed reduced scope");
|
||||
assertThat(work("WRK-0001").status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
authorize("WRK-0001"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(work("WRK-0004").status()).isEqualTo(Work.Status.OPEN); ok("project", "validate");
|
||||
}
|
||||
@Test void decompositionCanCloseWithChildrenStillOpenButNeverClosesAutomatically() throws Exception {
|
||||
init(2); configure("WRK-0001", "decomposition"); link("WRK-0001", "WRK-0002");
|
||||
ok("epic", "reconcile", "WRK-0001"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.OPEN);
|
||||
complete("WRK-0001"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(work("WRK-0002").status()).isEqualTo(Work.Status.OPEN); ok("project", "validate");
|
||||
}
|
||||
@Test void reopeningImportantDescendantReopensAncestorsAndRetainsCompletionHistory() throws Exception {
|
||||
init(3); configure("WRK-0001", "results"); configure("WRK-0002", "results");
|
||||
link("WRK-0002", "WRK-0003"); link("WRK-0001", "WRK-0002"); authorize("WRK-0001"); authorize("WRK-0002");
|
||||
complete("WRK-0003"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
ok("work", "archive", "WRK-0001", "--by", "fixture-owner", "--reason", "Retain delivery");
|
||||
ok("work", "reopen", "WRK-0003", "--by", "fixture-owner", "--reason", "New observation");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.ACTIVE); assertThat(work("WRK-0001").archived()).isFalse();
|
||||
assertThat(work("WRK-0002").status()).isEqualTo(Work.Status.ACTIVE); assertThat(work("WRK-0001").completions()).hasSize(1);
|
||||
complete("WRK-0003"); assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(work("WRK-0001").completions()).hasSize(2); ok("project", "validate");
|
||||
}
|
||||
@Test void cyclesMultipleParentsMissingChildrenAndUnapprovedPolicyAreRejected() throws Exception {
|
||||
init(3); configure("WRK-0001", "results"); configure("WRK-0002", "results"); link("WRK-0001", "WRK-0002");
|
||||
byte[] before = Files.readAllBytes(folder("WRK-0002").resolve("epic/WRK-0002.md"));
|
||||
assertThat(cli("epic", "link", "WRK-0002", "WRK-0001", "--by", "agent", "--reason", "Cycle")).isIn(2, 4);
|
||||
assertThat(Files.readAllBytes(folder("WRK-0002").resolve("epic/WRK-0002.md"))).isEqualTo(before);
|
||||
assertThat(cli("epic", "link", "WRK-0001", "WRK-9999", "--by", "agent", "--reason", "Missing")).isEqualTo(3);
|
||||
configure("WRK-0003", "results"); assertThat(cli("epic", "link", "WRK-0003", "WRK-0002", "--by", "agent", "--reason", "Two parents")).isIn(2, 4);
|
||||
assertThat(cli("epic", "authorize", "WRK-0001", "--by", "agent", "--reason", "No approval")).isEqualTo(2);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void reconciliationRecoversMissedPropagationAndRepeatedNotificationDoesNotRewrite() throws Exception {
|
||||
init(2); configure("WRK-0001", "results"); link("WRK-0001", "WRK-0002"); authorize("WRK-0001");
|
||||
Path parent = folder("WRK-0001").resolve("work.md"); byte[] before = Files.readAllBytes(parent);
|
||||
complete("WRK-0002");
|
||||
// Reconstruct the precise crash boundary: child committed, parent not yet written.
|
||||
Path evidence = folder("WRK-0001").resolve("artifacts/evidence");
|
||||
try (var paths = Files.walk(evidence)) { for (Path p : paths.sorted(Comparator.reverseOrder()).filter(p -> !p.equals(evidence)).toList()) Files.delete(p); }
|
||||
Files.write(parent, before);
|
||||
ok("next-actions", "WRK-0001", "--format", "json"); assertThat(output).contains("RECONCILE_EPIC");
|
||||
ok("epic", "reconcile", "WRK-0001", "--requester", "resuming-agent", "--request-id", "resume-one");
|
||||
assertThat(work("WRK-0001").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
byte[] completed = Files.readAllBytes(parent);
|
||||
ok("epic", "reconcile", "WRK-0001", "--requester", "resuming-agent", "--request-id", "resume-one");
|
||||
assertThat(Files.readAllBytes(parent)).isEqualTo(completed); assertThat(work("WRK-0001").completions()).hasSize(1);
|
||||
ok("project", "validate");
|
||||
}
|
||||
}
|
||||
@@ -59,10 +59,12 @@ class IntegrityTest {
|
||||
}
|
||||
@Test void lifecycleIsReversibleAndArtifactsAreWorkLocal() throws Exception {
|
||||
initWork(); ok("work", "create", "Two");
|
||||
ok("work", "status", "WRK-0001", "COMPLETED"); ok("work", "status", "WRK-0001", "ACTIVE");
|
||||
ok("work", "status", "WRK-0001", "CANCELLED");
|
||||
ok("work", "reopen", "WRK-0001", "--by", "owner", "--reason", "Resume investigation");
|
||||
Path source = Files.writeString(root.resolve("result.txt"), "Only first Work\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", source.toString(), "--purpose", "First only");
|
||||
ok("work", "context", "WRK-0002"); assertThat(lastOutput).doesNotContain("First only", "ART-0001");
|
||||
ok("work", "context", "WRK-0002", "--format", "json");
|
||||
assertThat(lastOutput).doesNotContain("First only").contains("\"artifacts\" : [ ]");
|
||||
ok("work", "show", "WRK-0001"); assertThat(lastOutput).contains("ACTIVE");
|
||||
}
|
||||
@Test void orphanFilesAndMissingWorkDirectoriesAreDiagnosed() throws Exception {
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.project.ProjectService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class LocalCliAcceptanceTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int result = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return result;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
@Test void realAdaptersAreDiscoverableWithoutRunningProviders() {
|
||||
ok("agent", "list", "--format", "json");
|
||||
assertThat(output).contains("codex-cli", "claude-cli", "fixture-general", "fixture-reviewer");
|
||||
}
|
||||
@Test void realExecutorConfigurationIsPortableBoundedAndDoesNotRequireAnInstalledCli() throws Exception {
|
||||
ok("init", "--name", "Test");
|
||||
ok("agent", "configure", "--adapter", "codex-cli", "--profile", "general", "--model", "default", "--timeout", "30");
|
||||
ok("agent", "configure", "--activity", "analyze", "--adapter", "claude-cli", "--profile", "reviewer");
|
||||
Path config = root.resolve(".ai-engineering/ai-engineering.yaml"); String before = Files.readString(config);
|
||||
assertThat(before).contains("codex-cli", "claude-cli", "timeoutSeconds: 30");
|
||||
assertThat(cli("agent", "configure", "--adapter", "codex-cli", "--timeout", "0")).isEqualTo(2);
|
||||
assertThat(cli("agent", "configure", "--adapter", "codex-cli", "--model", "--dangerous")).isEqualTo(2);
|
||||
assertThat(Files.readString(config)).isEqualTo(before); ok("project", "validate");
|
||||
}
|
||||
@Test void guidedInitPersistsGeneralAndSpecializationWithoutCallingAModel() {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
var input = new StringReader("1\ngeneral\ndefault\n60\n1\n3\nreviewer\ndefault\n90\n1\n");
|
||||
int code = new EngineeringCli(root, input).execute(new PrintWriter(out), new PrintWriter(err), "init", ".", "--name", "Guided", "--interactive");
|
||||
assertThat(code).as(err.toString()).isZero();
|
||||
var config = new ProjectService().load(root).agents();
|
||||
assertThat(config.general().adapter()).isEqualTo("codex-cli");
|
||||
assertThat(config.activities().get("analyze").adapter()).isEqualTo("claude-cli");
|
||||
assertThat(config.activities().get("analyze").profile()).isEqualTo("reviewer");
|
||||
}
|
||||
@Test void guidedInitWithoutConsoleNeverPublishesAPartialProject() {
|
||||
org.junit.jupiter.api.Assumptions.assumeTrue(System.console() == null);
|
||||
assertThat(cli("init", "--name", "No console", "--interactive")).isEqualTo(2);
|
||||
assertThat(output).contains("console"); assertThat(Files.exists(root.resolve(".ai-engineering"))).isFalse();
|
||||
}
|
||||
@Test void incompleteGuidedAnswersDoNotPublishAProject() {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root, new StringReader("1\ngeneral\n")).execute(new PrintWriter(out), new PrintWriter(err), "init", ".", "--name", "Incomplete", "--interactive");
|
||||
assertThat(code).isEqualTo(2); assertThat(err.toString()).contains("input ended");
|
||||
assertThat(Files.exists(root.resolve(".ai-engineering"))).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import net.intrepid.aiengineering.project.*;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import net.intrepid.aiengineering.decision.*;
|
||||
import net.intrepid.aiengineering.planning.*;
|
||||
import net.intrepid.aiengineering.verification.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class OperationalSafetyTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
private void init() { ok("init", "--name", "Test"); ok("work", "create", "One", "--acceptance", "A reproducible result"); }
|
||||
private Path folder() { return root.resolve(".ai-engineering/works/WRK-0001-one"); }
|
||||
private void artifact() throws Exception {
|
||||
Files.writeString(root.resolve("result.txt"), "Observed test run and command\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Result");
|
||||
}
|
||||
private String[] completion(String... extra) {
|
||||
var args = new ArrayList<>(List.of("work", "complete", "WRK-0001", "--by", "owner", "--summary", "Verified", "--human-approved"));
|
||||
args.addAll(List.of(extra)); return args.toArray(String[]::new);
|
||||
}
|
||||
private void accept(String id) {
|
||||
ok("decision", "accept", "WRK-0001", id, "--by", "owner", "--reason", "Explicit approval", "--human-approved");
|
||||
}
|
||||
private void decision() {
|
||||
ok("decision", "draft", "WRK-0001", "--title", "Approach", "--context", "Problem", "--approach", "A", "--rationale", "Reason");
|
||||
accept("DEC-0001");
|
||||
}
|
||||
@Test void onboardingPreservesLocalRulesBacksUpChangesAndDoesNotRewriteWork() throws Exception {
|
||||
init(); Path work = folder().resolve("work.md"); byte[] bytes = Files.readAllBytes(work);
|
||||
String original = "# Local rules\r\n\r\nDo not replace these.\r\n";
|
||||
Files.writeString(root.resolve("AGENTS.md"), original);
|
||||
Files.writeString(root.resolve(".ai-engineering/README.md"), "Old guide\n");
|
||||
var report = ProtocolGuide.install(root);
|
||||
assertThat(Files.readString(root.resolve("AGENTS.md"))).startsWith(original);
|
||||
assertThat(report.backups()).hasSize(2);
|
||||
assertThat(report.backups().stream().map(p -> Filespace.read(root.resolve(p)))).containsExactlyInAnyOrder(original, "Old guide\n");
|
||||
assertThat(Files.readAllBytes(work)).isEqualTo(bytes);
|
||||
assertThat(ProtocolGuide.install(root).updated()).isEmpty();
|
||||
Files.writeString(root.resolve("AGENTS.md"), "<!-- ai-engineering:start -->\nUnclosed block");
|
||||
assertThat(cli("onboard")).isEqualTo(4);
|
||||
assertThat(Files.readString(root.resolve("AGENTS.md"))).endsWith("Unclosed block");
|
||||
}
|
||||
@Test void malformedInstructionBlockDoesNotPublishNewProject() throws Exception {
|
||||
Files.writeString(root.resolve("AGENTS.md"), "<!-- ai-engineering:end -->");
|
||||
assertThat(cli("init", "--name", "Test")).isEqualTo(4);
|
||||
assertThat(Files.exists(root.resolve(".ai-engineering"))).isFalse();
|
||||
ok("guide"); assertThat(output).contains("agent entry point");
|
||||
}
|
||||
@Test void invalidOrPartialDiscoveryContractsAreDiagnosedAndOnboardingRepairsThem() throws Exception {
|
||||
init(); Path manifest = root.resolve(".ai-engineering/protocol.json"); String original = Files.readString(manifest);
|
||||
for (String corrupt : List.of("{broken", original.replace("\"schemaVersion\": 1", "\"schemaVersion\": 99"),
|
||||
original.replace("\"README.md\"", "\"../AGENTS.md\""), original + "{}")) {
|
||||
Files.writeString(manifest, corrupt);
|
||||
assertThat(cli("project", "validate")).as(output).isEqualTo(4);
|
||||
assertThat(cli("work", "context", "WRK-0001")).as(output).isEqualTo(4);
|
||||
}
|
||||
Files.delete(manifest); assertThat(cli("project", "validate")).isEqualTo(4);
|
||||
ok("onboard"); ok("project", "validate");
|
||||
assertThat(Files.readString(manifest)).isEqualTo(original);
|
||||
}
|
||||
@Test void planCyclesInvalidDependenciesAndMissingEvidenceLeaveNoRevision() {
|
||||
init(); ok("plan", "create", "WRK-0001", "--title", "Plan");
|
||||
ok("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "First");
|
||||
ok("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "Second", "--depends-on", "TSK-0001");
|
||||
String before = Filespace.read(folder().resolve("plans/PLN-0001.md"));
|
||||
assertThat(cli("plan", "step", "update", "WRK-0001", "PLN-0001", "TSK-0001", "--depends-on", "TSK-0002", "--by", "agent", "--reason", "Cycle")).isEqualTo(4);
|
||||
assertThat(output).contains("Cyclic");
|
||||
assertThat(cli("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "Bad", "--depends-on", "TSK-9999")).isEqualTo(4);
|
||||
assertThat(cli("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0001", "COMPLETED", "--by", "agent", "--reason", "No evidence")).isEqualTo(4);
|
||||
assertThat(Filespace.read(folder().resolve("plans/PLN-0001.md"))).isEqualTo(before);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void decisionChangesInvalidateExecutionUntilPlanIsReconsidered() throws Exception {
|
||||
init(); artifact(); decision(); ok("plan", "create", "WRK-0001", "--title", "Plan", "--decision", "DEC-0001");
|
||||
ok("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "First");
|
||||
ok("decision", "revise", "WRK-0001", "DEC-0001", "--by", "agent", "--reason", "New evidence"); accept("DEC-0002");
|
||||
assertThat(cli("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0001", "ACTIVE", "--by", "agent", "--reason", "Run")).isEqualTo(2);
|
||||
ok("plan", "update", "WRK-0001", "PLN-0001", "--decision", "DEC-0002", "--by", "agent", "--reason", "Reviewed against new decision");
|
||||
ok("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0001", "COMPLETED", "--by", "agent", "--reason", "Observed", "--evidence", "ART-0001");
|
||||
Files.writeString(folder().resolve("plans/.history/PLN-0001/r0001.md"), "Changed");
|
||||
assertThat(cli("work", "validate", "WRK-0001")).isEqualTo(4); assertThat(output).contains("history");
|
||||
}
|
||||
@Test void closureRequiresOwnedEvidenceAndCanonicalIntegrationOrAnExplanation() throws Exception {
|
||||
init(); artifact(); Path work = folder().resolve("work.md"); String before = Files.readString(work);
|
||||
assertThat(cli(completion("--criterion", "1=ART-9999", "--no-integration-needed", "Research only"))).isEqualTo(4);
|
||||
assertThat(cli(completion("--criterion", "1=ART-0001"))).isEqualTo(2);
|
||||
assertThat(cli(completion("--criterion", "1=ART-0001", "--integration", "../outside"))).isEqualTo(2);
|
||||
assertThat(cli(completion("--criterion", "1=ART-0001", "--integration", ".ai-engineering/README.md"))).isEqualTo(2);
|
||||
assertThat(Files.readString(work)).isEqualTo(before);
|
||||
Files.writeString(root.resolve("canonical.md"), "Maintained project knowledge\n");
|
||||
ok(completion("--criterion", "1=ART-0001", "--integration", "canonical.md"));
|
||||
var completed = new WorkService().load(root, "WRK-0001");
|
||||
assertThat(completed.completions().getLast().integrations().getFirst().sha256()).isEqualTo(Revisions.hash("Maintained project knowledge\n"));
|
||||
assertThat(cli("discussion", "add", "WRK-0001", "--text", "Silent edit")).isEqualTo(2);
|
||||
assertThat(cli("work", "update", "WRK-0001", "--goal", "Silent scope change")).isEqualTo(2);
|
||||
ok("work", "archive", "WRK-0001", "--by", "owner", "--reason", "Retain delivery");
|
||||
assertThat(cli("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Late edit")).isEqualTo(2);
|
||||
// Canonical project files can evolve after delivery; their captured hash is historical.
|
||||
Files.writeString(root.resolve("canonical.md"), "Next release\n"); ok("project", "validate");
|
||||
String current = Files.readString(work); Files.writeString(work, current.replace("goal: \"One\"", "goal: \"Altered outside CLI\""));
|
||||
assertThat(cli("work", "validate", "WRK-0001")).isEqualTo(4); assertThat(output).contains("scope");
|
||||
}
|
||||
@Test void legacyDraftAndWorkRemainReadableWithoutAutomaticRewrite() throws Exception {
|
||||
init(); ok("decision", "draft", "WRK-0001", "--title", "Legacy");
|
||||
Path work = folder().resolve("work.md");
|
||||
String legacyWork = Files.readString(work).replaceAll("(?m)^(plans|completions|events): \\[\\]\\n|^archived: false\\n", "");
|
||||
Files.writeString(work, legacyWork);
|
||||
Path path = folder().resolve("decisions/DEC-0001.md");
|
||||
var legacy = Documents.parse(Documents.json(new DecisionService().get(root, "WRK-0001", "DEC-0001")), tools.jackson.databind.node.ObjectNode.class);
|
||||
for (String field : List.of("text", "revision", "previousHash", "updatedAt", "updatedBy", "changeReason", "approvals", "revises", "supersededBy")) legacy.remove(field);
|
||||
String old = "---\n" + Documents.yaml(legacy).replaceFirst("^---\\s*\\n", "") + "---\n";
|
||||
Files.writeString(path, old);
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); assertThat(output).contains("Legacy", "DRAFT");
|
||||
ok("project", "validate");
|
||||
assertThat(Files.readString(path)).isEqualTo(old); assertThat(Files.readString(work)).isEqualTo(legacyWork);
|
||||
}
|
||||
@Test void pendingQuestionsAndDraftsBlockCompletionAndAppearInNextActions() throws Exception {
|
||||
init(); artifact(); ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "Unresolved?");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "Proposal");
|
||||
assertThat(cli("work", "check", "WRK-0001")).isEqualTo(4); assertThat(output).contains("questions", "draft");
|
||||
ok("next-actions", "WRK-0001", "--format", "json"); assertThat(output).contains("RESPOND", "REVIEW_DECISION");
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "RESPONSE", "--responds-to", "DSC-0001", "--text", "Answered");
|
||||
ok("decision", "reject", "WRK-0001", "DEC-0001", "--by", "owner", "--reason", "No formal DEC needed");
|
||||
ok("work", "check", "WRK-0001");
|
||||
ok(completion("--criterion", "1=ART-0001", "--no-integration-needed", "Research only"));
|
||||
assertThat(new VerificationService().context(root, "WRK-0001").work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class OperationalWorkflowTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
@Test void discoveryApprovalPlanningCompletionArchiveAndReopening() throws Exception {
|
||||
Files.writeString(root.resolve("AGENTS.md"), "# Project rules\n\nPreserve the game save.\n");
|
||||
ok("init", "--name", "Operational project");
|
||||
assertThat(Files.readString(root.resolve("AGENTS.md"))).startsWith("# Project rules\n\nPreserve the game save.\n")
|
||||
.contains(".ai-engineering/README.md", "ai-engineering:start");
|
||||
assertThat(Files.readString(root.resolve(".ai-engineering/README.md"))).contains("next-actions", "human-approved", "work context");
|
||||
assertThat(Files.exists(root.resolve(".ai-engineering/protocol.json"))).isTrue();
|
||||
String agents = Files.readString(root.resolve("AGENTS.md")); ok("onboard");
|
||||
assertThat(Files.readString(root.resolve("AGENTS.md"))).isEqualTo(agents);
|
||||
ok("guide", "--format", "json"); assertThat(output).contains("ai-engineering", "capabilities");
|
||||
ok("work", "create", "Deliver a small change", "--acceptance", "The result is reproducible");
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "Which scope?");
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "CONCLUSION", "--responds-to", "DSC-0001", "--text", "One small change");
|
||||
Path evidence = Files.writeString(root.resolve("result.txt"), "Verified fixture result\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", evidence.toString(), "--purpose", "Test result");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "Chosen approach", "--context", "Problem", "--approach", "Small change", "--rationale", "Bounded risk");
|
||||
assertThat(cli("decision", "accept", "WRK-0001", "DEC-0001", "--by", "owner", "--reason", "Agreed")).isEqualTo(2);
|
||||
ok("decision", "accept", "WRK-0001", "DEC-0001", "--by", "owner", "--reason", "Agreed", "--human-approved");
|
||||
assertThat(cli("decision", "update", "WRK-0001", "DEC-0001", "--title", "Overwrite accepted decision", "--by", "agent", "--reason", "Edit")).isEqualTo(2);
|
||||
ok("plan", "create", "WRK-0001", "--title", "Small delivery", "--decision", "DEC-0001");
|
||||
ok("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "Implement");
|
||||
ok("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "Validate", "--depends-on", "TSK-0001");
|
||||
assertThat(cli("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0002", "ACTIVE", "--by", "agent", "--reason", "Start")).isEqualTo(2);
|
||||
for (String step : new String[]{"TSK-0001", "TSK-0002"}) {
|
||||
ok("plan", "step", "status", "WRK-0001", "PLN-0001", step, "ACTIVE", "--by", "agent", "--reason", "Start step");
|
||||
ok("plan", "step", "status", "WRK-0001", "PLN-0001", step, "COMPLETED", "--by", "agent", "--reason", "Observed result", "--evidence", "ART-0001");
|
||||
}
|
||||
ok("plan", "status", "WRK-0001", "PLN-0001", "COMPLETED", "--by", "agent", "--reason", "Steps verified");
|
||||
ok("work", "check", "WRK-0001");
|
||||
assertThat(cli("work", "status", "WRK-0001", "COMPLETED")).isEqualTo(2);
|
||||
ok("work", "reconcile", "WRK-0001");
|
||||
ok("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(output).contains("COMPLETED", "PLN-0001", "TSK-0002", "SYSTEM_PLANS", "All required Plans completed", "protocolGuide");
|
||||
ok("decision", "history", "WRK-0001", "DEC-0001", "--format", "json"); assertThat(output).contains("DRAFT", "ACCEPTED");
|
||||
ok("plan", "history", "WRK-0001", "PLN-0001", "--format", "json"); assertThat(output).contains("Observed result");
|
||||
ok("work", "archive", "WRK-0001", "--by", "owner", "--reason", "Delivery recorded");
|
||||
assertThat(Files.exists(root.resolve(".ai-engineering/works/WRK-0001-deliver-a-small-change/decisions/DEC-0001.md"))).isTrue();
|
||||
ok("status", "--format", "json"); assertThat(output).contains("\"works\" : [ ]");
|
||||
ok("status", "--all", "--format", "json"); assertThat(output).contains("WRK-0001");
|
||||
ok("work", "reopen", "WRK-0001", "--by", "owner", "--reason", "New observation");
|
||||
ok("discussion", "add", "WRK-0001", "--text", "Continue with new evidence");
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); assertThat(output).contains("ACTIVE", "All required Plans completed", "New observation");
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void acceptedDecisionsCanBeSupersededWithoutLosingHistory() {
|
||||
ok("init", "--name", "Test"); ok("work", "create", "One");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "First", "--context", "Problem", "--approach", "A", "--rationale", "Reason");
|
||||
ok("decision", "accept", "WRK-0001", "DEC-0001", "--by", "owner", "--reason", "Agreed", "--human-approved");
|
||||
ok("decision", "revise", "WRK-0001", "DEC-0001", "--by", "agent", "--reason", "New evidence");
|
||||
ok("decision", "update", "WRK-0001", "DEC-0002", "--approach", "B", "--by", "agent", "--reason", "Alternative");
|
||||
ok("decision", "accept", "WRK-0001", "DEC-0002", "--by", "owner", "--reason", "Reconsidered", "--human-approved");
|
||||
ok("decision", "list", "WRK-0001", "--format", "json"); assertThat(output).contains("SUPERSEDED", "DEC-0002", "ACCEPTED");
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void revisionTamperingIsDiagnosedAndReadinessShowsPendingWork() throws Exception {
|
||||
ok("init", "--name", "Test"); ok("work", "create", "One");
|
||||
ok("next-actions", "WRK-0001", "--format", "json"); assertThat(output).contains("REFINE_SCOPE");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "First");
|
||||
ok("decision", "update", "WRK-0001", "DEC-0001", "--context", "Problem", "--by", "agent", "--reason", "Refinement");
|
||||
Path history = root.resolve(".ai-engineering/works/WRK-0001-one/decisions/.history/DEC-0001/r0001.md");
|
||||
Files.writeString(history, Files.readString(history) + "Tampered\n");
|
||||
assertThat(cli("work", "validate", "WRK-0001")).isEqualTo(4); assertThat(output).contains("history");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import net.intrepid.aiengineering.planning.*;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class PlanConsolidationSafetyTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { assertThat(cli(args)).as(output).isZero(); }
|
||||
private Work work() { return new WorkService().load(root, "WRK-0001"); }
|
||||
private Plan plan(String id) { return new PlanService().get(root, "WRK-0001", id); }
|
||||
private void init() throws Exception {
|
||||
ok("init", "--name", "Safety"); ok("work", "create", "Delivery", "--acceptance", "Recorded execution");
|
||||
Files.writeString(root.resolve("evidence.txt"), "Synthetic result\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", "evidence.txt", "--purpose", "Fixture result");
|
||||
}
|
||||
private void plan(String title, int steps) {
|
||||
ok("plan", "create", "WRK-0001", "--title", title);
|
||||
String id = work().plans().getLast();
|
||||
for (int i = 0; i < steps; i++) ok("plan", "step", "add", "WRK-0001", id, "--title", "Step " + i);
|
||||
}
|
||||
private void status(String plan, String step, String status) {
|
||||
ok("plan", "step", "status", "WRK-0001", plan, step, status, "--by", "fixture", "--reason", "Fixture result", "--evidence", "ART-0001");
|
||||
}
|
||||
@Test void cancelledStepRequiresScopeReviewAndRetainsHistory() throws Exception {
|
||||
init(); plan("One", 2); status("PLN-0001", "TSK-0001", "COMPLETED"); status("PLN-0001", "TSK-0002", "CANCELLED");
|
||||
assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(cli("plan", "status", "WRK-0001", "PLN-0001", "COMPLETED", "--by", "fixture", "--reason", "Try bypass")).isEqualTo(4);
|
||||
ok("plan", "exclude", "WRK-0001", "PLN-0001", "--step", "TSK-0002", "--by", "human", "--reason", "Explicit scope reduction");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(plan("PLN-0001").steps().getLast().status()).isEqualTo(Plan.Status.CANCELLED);
|
||||
assertThat(plan("PLN-0001").exclusions().getFirst().reason()).isEqualTo("Explicit scope reduction");
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void cancelledPlanNeedsReviewAndAnAllCancelledSetNeverCompletes() throws Exception {
|
||||
init(); plan("One", 1); plan("Two", 1);
|
||||
ok("plan", "status", "WRK-0001", "PLN-0002", "CANCELLED", "--by", "fixture", "--reason", "Deferred");
|
||||
status("PLN-0001", "TSK-0001", "COMPLETED"); assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
ok("plan", "exclude", "WRK-0001", "PLN-0002", "--by", "human", "--reason", "Reduced scope");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
ok("work", "reopen", "WRK-0001", "--by", "human", "--reason", "Another slice");
|
||||
ok("plan", "status", "WRK-0001", "PLN-0001", "CANCELLED", "--by", "human", "--reason", "Withdrawn");
|
||||
ok("plan", "exclude", "WRK-0001", "PLN-0001", "--by", "human", "--reason", "No delivered scope remains");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.ACTIVE); ok("project", "validate");
|
||||
}
|
||||
@Test void surveyAndDraftDecisionBlockUntilBothAreResolved() throws Exception {
|
||||
init(); plan("One", 1);
|
||||
ok("survey", "create", "WRK-0001", "--title", "Scope");
|
||||
ok("survey", "question", "WRK-0001", "SVY-0001", "--text", "Ready?", "--option", "Yes", "--option", "No");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "Approach", "--context", "Fixture", "--approach", "Small delivery", "--rationale", "Bounded");
|
||||
status("PLN-0001", "TSK-0001", "COMPLETED");
|
||||
ok("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "1");
|
||||
assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
ok("decision", "accept", "WRK-0001", "DEC-0001", "--by", "human", "--reason", "Approved", "--human-approved");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED); ok("project", "validate");
|
||||
}
|
||||
@Test void blockedWorkRequiresResumeAndReopeningLeavesTimeToCreateAnotherPlan() throws Exception {
|
||||
init(); plan("One", 1);
|
||||
ok("work", "status", "WRK-0001", "BLOCKED", "--by", "human", "--reason", "Wait");
|
||||
status("PLN-0001", "TSK-0001", "COMPLETED"); assertThat(work().status()).isEqualTo(Work.Status.BLOCKED);
|
||||
ok("work", "status", "WRK-0001", "ACTIVE", "--by", "human", "--reason", "Resume");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(cli("plan", "create", "WRK-0001", "--title", "Unreviewed new scope")).isEqualTo(2);
|
||||
ok("work", "reopen", "WRK-0001", "--by", "human", "--reason", "Next slice");
|
||||
ok("work", "reconcile", "WRK-0001"); assertThat(work().status()).isEqualTo(Work.Status.ACTIVE);
|
||||
plan("Two", 1); status("PLN-0002", "TSK-0001", "COMPLETED");
|
||||
assertThat(work().completions()).hasSize(2); ok("project", "validate");
|
||||
}
|
||||
@Test void freshCoordinatorRecoversPersistedLastStepAndPublishedReceipt() throws Exception {
|
||||
init(); plan("One", 1);
|
||||
// Model a crash after the low-level step write, before public coordination.
|
||||
new PlanService().stepStatus(root, "WRK-0001", "PLN-0001", "TSK-0001", Plan.Status.COMPLETED, "fixture", "Result", List.of("ART-0001"));
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); assertThat(work().status()).isEqualTo(Work.Status.OPEN);
|
||||
ok("work", "reconcile", "WRK-0001"); var delivered = work();
|
||||
// Model an interrupted receipt-to-completion publication using the real published receipt.
|
||||
var interrupted = new Work(delivered.schemaVersion(), delivered.id(), delivered.title(), delivered.description(), delivered.goal(), delivered.motivation(),
|
||||
delivered.constraints(), delivered.acceptanceCriteria(), Work.Status.OPEN, delivered.createdAt(), delivered.updatedAt(), delivered.author(), delivered.repositories(),
|
||||
delivered.discussions(), delivered.decisions(), delivered.artifacts(), delivered.plans(), List.of(), List.of(), false,
|
||||
delivered.topics(), delivered.surveys(), delivered.dispositions(), delivered.agentRuns(), delivered.epic());
|
||||
Documents.replaceFrontMatter(new WorkService().folder(root, delivered.id()).resolve("work.md"), interrupted);
|
||||
ok("work", "reconcile", "WRK-0001"); assertThat(work().artifacts()).isEqualTo(delivered.artifacts());
|
||||
assertThat(work().completions()).hasSize(1); ok("project", "validate");
|
||||
}
|
||||
@Test void tamperedEvidencePreventsTheStepWrite() throws Exception {
|
||||
init(); plan("One", 1);
|
||||
var evidence = new WorkService().folder(root, "WRK-0001").resolve("artifacts/evidence/ART-0001/payload");
|
||||
Files.writeString(evidence, "tampered\n"); int revision = plan("PLN-0001").revision();
|
||||
assertThat(cli("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0001", "COMPLETED", "--by", "fixture", "--reason", "Bad evidence", "--evidence", "ART-0001")).isEqualTo(4);
|
||||
assertThat(plan("PLN-0001").revision()).isEqualTo(revision);
|
||||
}
|
||||
@Test void planCompletionNotifiesTheAuthorizedEpicWithoutASecondHumanClosure() throws Exception {
|
||||
init(); ok("work", "create", "Parent", "--acceptance", "Child delivery");
|
||||
ok("epic", "configure", "WRK-0002", "--mode", "results", "--by", "human", "--reason", "Track result");
|
||||
plan("One", 1);
|
||||
ok("epic", "link", "WRK-0002", "WRK-0001", "--by", "human", "--reason", "Required delivery");
|
||||
ok("epic", "authorize", "WRK-0002", "--by", "human", "--reason", "Delegate aggregate completion", "--human-approved");
|
||||
status("PLN-0001", "TSK-0001", "COMPLETED");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(new WorkService().load(root, "WRK-0002").status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(new WorkService().load(root, "WRK-0002").completions().getLast().origin()).isEqualTo(Work.CompletionOrigin.SYSTEM_EPIC);
|
||||
assertThat(output).contains("WRK-0002", "SYSTEM_PLANS"); ok("project", "validate");
|
||||
}
|
||||
@Test void explicitPlanReopeningDoesNotImmediatelyCloseItAgain() throws Exception {
|
||||
init(); plan("One", 1); status("PLN-0001", "TSK-0001", "COMPLETED");
|
||||
ok("work", "reopen", "WRK-0001", "--by", "human", "--reason", "Revisit result");
|
||||
ok("plan", "status", "WRK-0001", "PLN-0001", "ACTIVE", "--by", "human", "--reason", "Replan");
|
||||
assertThat(plan("PLN-0001").status()).isEqualTo(Plan.Status.ACTIVE);
|
||||
status("PLN-0001", "TSK-0001", "OPEN"); status("PLN-0001", "TSK-0001", "COMPLETED");
|
||||
assertThat(work().completions()).hasSize(2); ok("project", "validate");
|
||||
}
|
||||
@Test void exclusionDoesNotSatisfyADependencyAndChangingReviewedContentInvalidatesIt() throws Exception {
|
||||
init(); plan("One", 2); plan("Keep open", 1);
|
||||
ok("plan", "step", "update", "WRK-0001", "PLN-0001", "TSK-0002", "--depends-on", "TSK-0001", "--by", "human", "--reason", "Dependency");
|
||||
status("PLN-0001", "TSK-0001", "CANCELLED");
|
||||
ok("plan", "exclude", "WRK-0001", "PLN-0001", "--step", "TSK-0001", "--by", "human", "--reason", "Scope reduction");
|
||||
assertThat(cli("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0002", "ACTIVE", "--by", "fixture", "--reason", "Unsatisfied dependency")).isEqualTo(2);
|
||||
status("PLN-0001", "TSK-0001", "OPEN"); status("PLN-0001", "TSK-0001", "CANCELLED");
|
||||
assertThat(plan("PLN-0001").excluded("TSK-0001")).isFalse();
|
||||
ok("work", "reconcile", "WRK-0001"); assertThat(output).contains("review cancelled scope");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import net.intrepid.aiengineering.planning.*;
|
||||
import net.intrepid.aiengineering.agent.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class PlanConsolidationTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { assertThat(cli(args)).as(output).isZero(); }
|
||||
private Work work() { return new WorkService().load(root, "WRK-0001"); }
|
||||
private Plan plan(String id) { return new PlanService().get(root, "WRK-0001", id); }
|
||||
private void init() throws Exception {
|
||||
ok("init", "--name", "Consolidation"); ok("work", "create", "Delivery");
|
||||
Files.writeString(root.resolve("evidence.txt"), "Synthetic verified result\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", "evidence.txt", "--purpose", "Fixture result");
|
||||
}
|
||||
private void addPlan(String title) { ok("plan", "create", "WRK-0001", "--title", title); }
|
||||
private void addStep(String plan) { ok("plan", "step", "add", "WRK-0001", plan, "--title", "Verify result", "--acceptance", "Fixture result recorded"); }
|
||||
private void done(String plan, String step) {
|
||||
ok("plan", "step", "status", "WRK-0001", plan, step, "COMPLETED", "--by", "fixture-agent", "--reason", "Verified fixture", "--evidence", "ART-0001");
|
||||
}
|
||||
@Test void lastStepConsolidatesPlanAndWorkAndReconciliationDoesNotRewrite() throws Exception {
|
||||
init(); addPlan("One"); addStep("PLN-0001"); addStep("PLN-0001");
|
||||
// An unregistered adapter configured through its real public registry must never be called.
|
||||
var poison = new AgentAdapter() {
|
||||
public String id() { return "must-not-run"; }
|
||||
public String classify(AgentContext context, String task) { throw new AssertionError("Model invoked"); }
|
||||
public AgentProposal propose(AgentContext context, Request request) { throw new AssertionError("Model invoked"); }
|
||||
};
|
||||
new AgentService(Map.of(poison.id(), poison)).configure(root, "general", poison.id(), "general", "default", null);
|
||||
done("PLN-0001", "TSK-0001"); assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
done("PLN-0001", "TSK-0002");
|
||||
assertThat(plan("PLN-0001").status()).isEqualTo(Plan.Status.COMPLETED);
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(work().completions().getLast().origin().name()).isEqualTo("SYSTEM_PLANS");
|
||||
assertThat(work().completions().getLast().humanApproved()).isFalse();
|
||||
assertThat(work().agentRuns()).isEmpty();
|
||||
String original = Files.readString(new WorkService().folder(root, work().id()).resolve("work.md"));
|
||||
ok("work", "reconcile", "WRK-0001", "--requester", "another-agent", "--request-id", "repeat");
|
||||
assertThat(Files.readString(new WorkService().folder(root, work().id()).resolve("work.md"))).isEqualTo(original);
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void anotherPlanKeepsWorkPendingAndReturnsItsIdentity() throws Exception {
|
||||
init(); addPlan("One"); addPlan("Two"); addStep("PLN-0001"); addStep("PLN-0002");
|
||||
done("PLN-0001", "TSK-0001");
|
||||
assertThat(plan("PLN-0001").status()).isEqualTo(Plan.Status.COMPLETED);
|
||||
assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
assertThat(output).contains("PLN-0002", "pending");
|
||||
done("PLN-0002", "TSK-0001"); assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
}
|
||||
@Test void noPlansAndEmptyPlansRemainOpenAndReadsNeverConsolidate() throws Exception {
|
||||
init(); ok("next-actions", "WRK-0001", "--format", "json");
|
||||
assertThat(output).doesNotContain("CHECK_COMPLETION").contains("CREATE_PLAN");
|
||||
ok("work", "reconcile", "WRK-0001"); assertThat(work().status()).isEqualTo(Work.Status.OPEN);
|
||||
addPlan("Empty"); ok("work", "reconcile", "WRK-0001");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.OPEN);
|
||||
assertThat(plan("PLN-0001").status()).isEqualTo(Plan.Status.OPEN);
|
||||
ok("work", "context", "WRK-0001", "--format", "json"); assertThat(output).contains("consolidation", "No steps");
|
||||
}
|
||||
@Test void unansweredDiscussionPreventsDeliveryUntilResponseArrives() throws Exception {
|
||||
init(); addPlan("One"); addStep("PLN-0001");
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "More scope?");
|
||||
done("PLN-0001", "TSK-0001");
|
||||
assertThat(plan("PLN-0001").status()).isEqualTo(Plan.Status.COMPLETED);
|
||||
assertThat(work().status()).isNotEqualTo(Work.Status.COMPLETED);
|
||||
ok("discussion", "add", "WRK-0001", "--kind", "RESPONSE", "--responds-to", "DSC-0001", "--text", "Scope is complete");
|
||||
assertThat(work().status()).isEqualTo(Work.Status.COMPLETED);
|
||||
ok("project", "validate");
|
||||
}
|
||||
}
|
||||
@@ -36,12 +36,16 @@ class ProcessContinuityTest {
|
||||
cliWithoutGit("init", "--name", "Simple Project");
|
||||
assertThat(cliWithoutGit("repo", "list", "--format", "json").strip()).isEqualTo("[ ]");
|
||||
cliWithoutGit("work", "create", "Continue application", "--goal", "Preserve local context");
|
||||
cliWithoutGit("discussion", "add", "WRK-0001", "--text", "A simple folder is a complete engineering project");
|
||||
Files.writeString(root.resolve("proposal.md"), "A simple folder is a complete engineering project\n\nRead from UTF-8.\n");
|
||||
cliWithoutGit("discussion", "add", "WRK-0001", "--text-file", "proposal.md");
|
||||
cliWithoutGit("artifact", "add", "WRK-0001", "--file", source.toString(), "--purpose", "Initial source evidence");
|
||||
cliWithoutGit("decision", "draft", "WRK-0001", "--title", "Pilot the protocol", "--evidence", "ART-0001");
|
||||
cliWithoutGit("work", "update", "WRK-0001", "--goal", "Continue from recorded evidence", "--constraint", "Keep existing sources",
|
||||
"--acceptance", "Context reloads in another process");
|
||||
String context = cliWithoutGit("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).isEqualTo(context)
|
||||
.contains("Preserve local context", "\"repositories\" : [ ]", "Initial source evidence", "Pilot the protocol");
|
||||
.contains("Continue from recorded evidence", "Keep existing sources", "Context reloads in another process",
|
||||
"Read from UTF-8.", "\"repositories\" : [ ]", "Initial source evidence", "Pilot the protocol");
|
||||
assertThat(cliWithoutGit("project", "validate", "--format", "json")).contains("\"valid\" : true");
|
||||
assertThat(Files.exists(root.resolve(".git"))).isFalse();
|
||||
assertThat(Files.readString(source)).isEqualTo("Existing project\n");
|
||||
@@ -67,4 +71,86 @@ class ProcessContinuityTest {
|
||||
.contains("agent-a", "runtime", "studio", "sha256", "DRAFT", "Continue across agents");
|
||||
assertThat(cli("project", "validate", "--format", "json")).contains("\"valid\" : true");
|
||||
}
|
||||
@Test void refinementContinuesBetweenTwoAdaptersInIndependentProcessesWithoutGit() throws Exception {
|
||||
cliWithoutGit("init", "--name", "Refinement", "--general-adapter", "fixture-general", "--archive-policy", "reversible");
|
||||
cliWithoutGit("work", "create", "Refine", "--acceptance", "Persisted continuity");
|
||||
cliWithoutGit("agent", "run", "WRK-0001", "--task", "Rendering: Compare layers\nSaving: Preserve the format", "--request-id", "refine");
|
||||
cliWithoutGit("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--choice", "1", "--author", "fixture-human");
|
||||
cliWithoutGit("survey", "answer", "WRK-0001", "SVY-0001", "QST-0001", "--text", "Refined direction", "--author", "fixture-human");
|
||||
Files.writeString(root.resolve("result.txt"), "Explicit deterministic fixture evidence\n");
|
||||
cliWithoutGit("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Fixture evidence");
|
||||
cliWithoutGit("agent", "configure", "--adapter", "fixture-reviewer", "--activity", "analyze");
|
||||
cliWithoutGit("agent", "run", "WRK-0001", "--activity", "analyze", "--task", "Review the recorded fixture", "--request-id", "review");
|
||||
cliWithoutGit("agent", "run", "WRK-0001", "--task", "summarize persisted state", "--request-id", "summary");
|
||||
String context = cliWithoutGit("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).isEqualTo(context)
|
||||
.contains("fixture-general", "fixture-reviewer", "Refined direction", "ANS-0001", "TOP-0002", "ARCHIVE", "DRAFT", "sourceHash");
|
||||
String markdown = cliWithoutGit("work", "context", "WRK-0001");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001")).isEqualTo(markdown).contains("Refined direction", "Previous answer");
|
||||
cliWithoutGit("project", "validate"); assertThat(Files.exists(root.resolve(".git"))).isFalse();
|
||||
}
|
||||
@Test void epicResultsPropagateAcrossIndependentProcessesWithoutModelsOrGit() throws Exception {
|
||||
cliWithoutGit("init", "--name", "EPIC continuity");
|
||||
for (String title : List.of("Parent", "Required slice", "Reconsidered slice"))
|
||||
cliWithoutGit("work", "create", title, "--acceptance", "Reviewed fixture delivery");
|
||||
cliWithoutGit("epic", "configure", "WRK-0001", "--by", "fixture-agent", "--reason", "Coordinate slices");
|
||||
for (String child : List.of("WRK-0002", "WRK-0003")) cliWithoutGit("epic", "link", "WRK-0001", child, "--by", "fixture-agent", "--reason", "Decomposition");
|
||||
cliWithoutGit("epic", "authorize", "WRK-0001", "--by", "fixture-owner", "--reason", "Reviewed aggregate criteria", "--human-approved");
|
||||
Files.writeString(root.resolve("result.txt"), "Synthetic delivery observation\n");
|
||||
cliWithoutGit("artifact", "add", "WRK-0002", "--file", "result.txt", "--purpose", "Fixture evidence");
|
||||
cliWithoutGit("work", "complete", "WRK-0002", "--by", "fixture-owner", "--summary", "Reviewed fixture", "--human-approved", "--criterion", "1=ART-0001", "--no-integration-needed", "Disposable fixture");
|
||||
cliWithoutGit("work", "status", "WRK-0003", "CANCELLED", "--by", "fixture-owner", "--reason", "Scope review needed");
|
||||
assertThat(cliWithoutGit("epic", "show", "WRK-0001", "--format", "json")).contains("CANCELLED", "WRK-0003");
|
||||
cliWithoutGit("epic", "importance", "WRK-0001", "WRK-0003", "--optional", "--by", "fixture-owner", "--reason", "Explicitly exclude this delivery");
|
||||
cliWithoutGit("epic", "authorize", "WRK-0001", "--by", "fixture-owner", "--reason", "Reviewed reduced scope", "--human-approved");
|
||||
String context = cliWithoutGit("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).isEqualTo(context)
|
||||
.contains("SYSTEM_EPIC", "\"humanApproved\" : false", "WRK-0002", "WRK-0003", "fixture-owner");
|
||||
String markdown = cliWithoutGit("work", "context", "WRK-0001");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001")).isEqualTo(markdown);
|
||||
cliWithoutGit("work", "reopen", "WRK-0002", "--by", "fixture-owner", "--reason", "New evidence");
|
||||
assertThat(cliWithoutGit("work", "show", "WRK-0001", "--format", "json")).contains("\"status\" : \"ACTIVE\"");
|
||||
cliWithoutGit("work", "complete", "WRK-0002", "--by", "fixture-owner", "--summary", "Reviewed new fixture", "--human-approved", "--criterion", "1=ART-0001", "--no-integration-needed", "Disposable fixture");
|
||||
Path work = root.resolve(".ai-engineering/works/WRK-0001-parent/work.md"); byte[] before = Files.readAllBytes(work);
|
||||
cliWithoutGit("epic", "reconcile", "WRK-0001", "--requester", "another-agent", "--request-id", "resumed");
|
||||
assertThat(Files.readAllBytes(work)).isEqualTo(before);
|
||||
cliWithoutGit("project", "validate"); assertThat(Files.exists(root.resolve(".git"))).isFalse();
|
||||
}
|
||||
@Test void guidedSetupSurvivesIndependentExecutionsWithoutProviderOrGitOnPath() throws Exception {
|
||||
Files.writeString(root.resolve("answers.txt"), "1\ngeneral\ndefault\n60\n1\n3\nreviewer\ndefault\n90\n1\n");
|
||||
cliWithoutGit("init", ".", "--name", "Guided process fixture", "--interactive", "--input-file", "answers.txt");
|
||||
String config = cliWithoutGit("project", "show", "--format", "json");
|
||||
assertThat(config).contains("codex-cli", "claude-cli", "reviewer", "timeoutSeconds");
|
||||
cliWithoutGit("work", "create", "Continue configured project");
|
||||
String first = cliWithoutGit("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).isEqualTo(first);
|
||||
cliWithoutGit("project", "validate");
|
||||
}
|
||||
@Test void portableEntryContractSupportsTheCompleteCycleAcrossIndependentProcesses() throws Exception {
|
||||
cliWithoutGit("init", "--name", "Agent-neutral continuity");
|
||||
assertThat(Files.readString(root.resolve("AGENTS.md"))).contains(".ai-engineering/README.md");
|
||||
assertThat(Files.readString(root.resolve(".ai-engineering/protocol.json"))).contains("next-actions", "capabilities");
|
||||
assertThat(cliWithoutGit("guide")).contains("human-approved", "canonical");
|
||||
cliWithoutGit("work", "create", "One delivery", "--acceptance", "Recorded result survives a fresh process");
|
||||
cliWithoutGit("decision", "draft", "WRK-0001", "--title", "Small approach", "--context", "Problem", "--approach", "A", "--rationale", "Bounded");
|
||||
cliWithoutGit("decision", "accept", "WRK-0001", "DEC-0001", "--by", "owner", "--reason", "Agreed", "--human-approved");
|
||||
cliWithoutGit("plan", "create", "WRK-0001", "--title", "Delivery", "--decision", "DEC-0001");
|
||||
cliWithoutGit("plan", "step", "add", "WRK-0001", "PLN-0001", "--title", "Verify fixture");
|
||||
Files.writeString(root.resolve("result.txt"), "Fixture executed independently\n");
|
||||
cliWithoutGit("artifact", "add", "WRK-0001", "--file", "result.txt", "--purpose", "Process fixture result");
|
||||
cliWithoutGit("plan", "step", "status", "WRK-0001", "PLN-0001", "TSK-0001", "COMPLETED", "--by", "agent", "--reason", "Read the independent result", "--evidence", "ART-0001");
|
||||
cliWithoutGit("plan", "status", "WRK-0001", "PLN-0001", "COMPLETED", "--by", "agent", "--reason", "Verified");
|
||||
cliWithoutGit("work", "reconcile", "WRK-0001", "--requester", "another-agent", "--request-id", "fresh-process");
|
||||
cliWithoutGit("work", "archive", "WRK-0001", "--by", "owner", "--reason", "Preserve history");
|
||||
String context = cliWithoutGit("work", "context", "WRK-0001", "--format", "json");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).isEqualTo(context)
|
||||
.contains("SYSTEM_PLANS", "ACCEPTED", "PLN-0001", "TSK-0001", "scopeHash", "\"archived\" : true");
|
||||
String markdown = cliWithoutGit("work", "context", "WRK-0001");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001")).isEqualTo(markdown);
|
||||
assertThat(cliWithoutGit("decision", "history", "WRK-0001", "DEC-0001", "--format", "json")).contains("DRAFT", "ACCEPTED");
|
||||
cliWithoutGit("work", "reopen", "WRK-0001", "--by", "owner", "--reason", "Continue with new observations");
|
||||
assertThat(cliWithoutGit("work", "context", "WRK-0001", "--format", "json")).contains("SYSTEM_PLANS", "Continue with new observations");
|
||||
cliWithoutGit("project", "validate");
|
||||
assertThat(Files.exists(root.resolve(".git"))).isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ class ProtocolIntegrationTest {
|
||||
init(); ok("repo", "add", "app", "--path", ".");
|
||||
assertThat(ok("repo", "list", "--format", "json").out()).contains("\"path\" : \".\"", "\"edit\" : false");
|
||||
ok("work", "create", "Improve application", "--repo", "app");
|
||||
var snapshots = new net.intrepid.aiengineering.work.WorkService().load(root, "WRK-0001").repositories();
|
||||
ok("work", "update", "WRK-0001", "--goal", "Refine the application scope");
|
||||
assertThat(new net.intrepid.aiengineering.work.WorkService().load(root, "WRK-0001").repositories()).isEqualTo(snapshots);
|
||||
String exported = ok("work", "context", "WRK-0001", "--format", "json").out();
|
||||
assertThat(exported).contains("\"repositoryId\" : \"app\"", "\"head\" : \"UNBORN\"");
|
||||
Path nested = Files.createDirectories(root.resolve("src/feature"));
|
||||
@@ -103,8 +106,15 @@ class ProtocolIntegrationTest {
|
||||
@Test void cliSmokeAndHelpForEveryCommand() {
|
||||
assertThat(ok("--version").out()).isEqualTo("ai-engineering 0.1.0\n");
|
||||
for (String command : new String[]{"", "init", "project", "project show", "project validate", "repo", "repo add", "repo list",
|
||||
"work", "work create", "work list", "work show", "work validate", "work context", "discussion", "discussion add",
|
||||
"discussion list", "discussion migrate", "decision", "decision draft", "artifact", "artifact add"}) {
|
||||
"work", "work create", "work update", "work list", "work show", "work validate", "work context", "discussion", "discussion add",
|
||||
"discussion list", "discussion migrate", "decision", "decision draft", "decision list", "decision show", "decision update",
|
||||
"decision accept", "decision reject", "decision revise", "decision history", "artifact", "artifact add",
|
||||
"onboard", "guide", "status", "next-actions", "work check", "work complete", "work archive", "work reopen", "work status",
|
||||
"plan", "plan create", "plan list", "plan show", "plan update", "plan status", "plan history", "plan step",
|
||||
"plan step add", "plan step update", "plan step status", "topic", "topic create", "topic list", "topic show", "topic update",
|
||||
"survey", "survey create", "survey question", "survey answer", "survey ask", "survey list", "survey show", "survey history",
|
||||
"discussion archive", "discussion restore", "agent", "agent list", "agent doctor", "agent configure", "agent run", "agent history", "agent show",
|
||||
"epic", "epic configure", "epic link", "epic unlink", "epic importance", "epic authorize", "epic show", "epic check", "epic history", "epic reconcile"}) {
|
||||
var args = new java.util.ArrayList<String>();
|
||||
if (!command.isEmpty()) args.addAll(java.util.List.of(command.split(" ")));
|
||||
args.add("--help"); assertThat(ok(args.toArray(String[]::new)).out()).contains("Usage:");
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.agent.*;
|
||||
import net.intrepid.aiengineering.discussion.*;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class RefinementSafetyTest {
|
||||
@TempDir Path root;
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out=new StringWriter(); var err=new StringWriter();
|
||||
int code=new EngineeringCli(root).execute(new PrintWriter(out),new PrintWriter(err),args); output=out+err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code=cli(args); assertThat(code).as(output).isZero(); }
|
||||
private void init() { ok("init","--name","Test"); ok("work","create","One"); }
|
||||
private Path work() { return root.resolve(".ai-engineering/works/WRK-0001-one"); }
|
||||
@Test void malformedBundleIsFullyPreflightedBeforeAnyMutation() throws Exception {
|
||||
init();
|
||||
AgentAdapter broken=new AgentAdapter() {
|
||||
public String id() { return "broken-fixture"; }
|
||||
public String classify(AgentContext context,String task) { return "refine"; }
|
||||
public AgentProposal propose(AgentContext context,Request request) {
|
||||
return new AgentProposal(id(),true,"A malformed fixture",List.of(new AgentProposal.TopicDraft("one","A valid first topic","",List.of("@request"))),
|
||||
List.of(new AgentProposal.SurveyDraft("Invalid later survey","",List.of(new AgentProposal.QuestionDraft("one","No suggestions",List.of(),false,null,List.of())))),List.of(),List.of(),null);
|
||||
}
|
||||
};
|
||||
var service=new AgentService(Map.of(broken.id(),broken)); service.configure(root,"general",broken.id(),"test","test",null);
|
||||
byte[] before=Files.readAllBytes(work().resolve("work.md"));
|
||||
assertThatThrownBy(()->service.run(root,"WRK-0001","Input",null,"human","malformed")).isInstanceOf(ProtocolException.class).hasMessageContaining("suggestions");
|
||||
assertThat(Files.readAllBytes(work().resolve("work.md"))).isEqualTo(before);
|
||||
assertThat(Files.exists(work().resolve("topics"))).isFalse(); assertThat(Files.exists(work().resolve("agent-runs"))).isFalse();
|
||||
}
|
||||
@Test void summaryFreshnessIsDerivedWithoutReinvokingAnAdapter() {
|
||||
init(); ok("agent","configure","--adapter","fixture-general");
|
||||
ok("agent","run","WRK-0001","--task","summarize current context","--request-id","summary");
|
||||
var service=new AgentService(); assertThat(service.views(root,"WRK-0001").getFirst().stale()).isFalse();
|
||||
ok("discussion","add","WRK-0001","--text","New fact");
|
||||
assertThat(service.views(root,"WRK-0001").getFirst().stale()).isTrue();
|
||||
assertThat(service.history(root,"WRK-0001")).hasSize(1);
|
||||
assertThat(cli("agent","run","WRK-0001","--task","Different task","--request-id","summary")).isEqualTo(2);
|
||||
}
|
||||
@Test void archiveRequiresPolicyAndEvidenceAndRestoreKeepsTheSource() throws Exception {
|
||||
init(); ok("discussion","add","WRK-0001","--kind","SUGGESTION","--text","A proposal");
|
||||
Files.writeString(root.resolve("fixture.txt"),"Synthetic observation\n");
|
||||
ok("artifact","add","WRK-0001","--file","fixture.txt","--purpose","Fixture evidence");
|
||||
assertThat(cli("discussion","archive","WRK-0001","DSC-0001","--reason","Reason","--evidence","ART-0001")).isEqualTo(2);
|
||||
ok("agent","configure","--adapter","fixture-general","--archive-policy","reversible");
|
||||
ok("discussion","archive","WRK-0001","DSC-0001","--reason","Rejected in fixture","--evidence","ART-0001");
|
||||
assertThat(new DispositionService().archived(root,"WRK-0001","DSC-0001")).isTrue();
|
||||
ok("discussion","restore","WRK-0001","DSC-0001","--reason","New evidence may change the conclusion");
|
||||
assertThat(new DispositionService().archived(root,"WRK-0001","DSC-0001")).isFalse();
|
||||
assertThat(new DiscussionService().list(root,"WRK-0001").getFirst().text()).isEqualTo("A proposal");
|
||||
ok("project","validate");
|
||||
}
|
||||
@Test void guidedQuestionsAcceptFreeTextAndChoicesWithoutAssumingRecommendations() throws Exception {
|
||||
init(); ok("survey","create","WRK-0001","--title","Guided");
|
||||
for(String question:List.of("Choose","Write")) ok("survey","question","WRK-0001","SVY-0001","--text",question,"--option","A","--option","B","--recommend","1");
|
||||
assertThat(new SurveyService().get(root,"WRK-0001","SVY-0001").pending()).hasSize(2);
|
||||
var out=new StringWriter(); var err=new StringWriter();
|
||||
int result=new EngineeringCli(root,new StringReader("2\ntext:My approach\n")).execute(new PrintWriter(out),new PrintWriter(err),"survey","ask","WRK-0001","SVY-0001","--author","fixture-human");
|
||||
assertThat(result).as(err.toString()).isZero(); assertThat(out.toString()).contains("1. A","2. B","All pending questions answered.");
|
||||
var survey=new SurveyService().get(root,"WRK-0001","SVY-0001");
|
||||
assertThat(survey.pending()).isEmpty(); assertThat(survey.latest("QST-0001").choices()).containsExactly("2");
|
||||
assertThat(survey.latest("QST-0002").text()).isEqualTo("My approach");
|
||||
}
|
||||
@Test void multipleSelectionsUtf8InputAndRevisionTamperingAreChecked() throws Exception {
|
||||
init(); ok("survey","create","WRK-0001","--title","Many");
|
||||
ok("survey","question","WRK-0001","SVY-0001","--text","Which?","--option","A","--option","B","--multiple");
|
||||
Files.writeString(root.resolve("answer.md"),"Outra proposta — contexto\r\n");
|
||||
ok("survey","answer","WRK-0001","SVY-0001","QST-0001","--choice","1","--choice","2","--text-file","answer.md");
|
||||
var latest=new SurveyService().get(root,"WRK-0001","SVY-0001").latest("QST-0001");
|
||||
assertThat(latest.text()).isEqualTo("Outra proposta — contexto\r\n"); assertThat(latest.choices()).containsExactly("1","2");
|
||||
Files.writeString(work().resolve("surveys/.history/SVY-0001/r0001.md"),"Tampered");
|
||||
assertThat(cli("work","validate","WRK-0001")).isEqualTo(4); assertThat(output).contains("history");
|
||||
}
|
||||
@Test void legacyWorkWithoutRefinementFieldsIsReadWithoutRewrite() throws Exception {
|
||||
init(); Path path=work().resolve("work.md");
|
||||
String old=Files.readString(path).replaceAll("(?m)^(topics|surveys|dispositions|agentRuns): \\[\\]\\n","");
|
||||
Files.writeString(path,old); ok("topic","list","WRK-0001"); ok("work","context","WRK-0001","--format","json");
|
||||
assertThat(Files.readString(path)).isEqualTo(old); ok("project","validate");
|
||||
}
|
||||
@Test void aTopicCannotBeUsedByAnotherWorkAndUnsafeRecordsFailValidation() throws Exception {
|
||||
init(); ok("topic","create","WRK-0001","Private"); ok("work","create","Two");
|
||||
assertThat(cli("discussion","add","WRK-0002","--topic","TOP-0001","--text","Wrong owner")).isIn(2,3);
|
||||
ok("survey","create","WRK-0001","--title","Unsafe");
|
||||
Path p=work().resolve("surveys/SVY-0001.md"); Files.writeString(p,Files.readString(p).replace("workId: \"WRK-0001\"","workId: \"WRK-0002\""));
|
||||
assertThat(cli("work","validate","WRK-0001")).isEqualTo(4); assertThat(output).contains("identity");
|
||||
}
|
||||
@Test void noninteractiveSurveyNeverWaitsForInput() {
|
||||
org.junit.jupiter.api.Assumptions.assumeTrue(System.console()==null);
|
||||
init(); ok("survey","create","WRK-0001","--title","Pending");
|
||||
ok("survey","question","WRK-0001","SVY-0001","--text","Which?","--option","A");
|
||||
assertThat(cli("survey","ask","WRK-0001","SVY-0001")).isEqualTo(2);
|
||||
assertThat(new SurveyService().get(root,"WRK-0001","SVY-0001").pending()).hasSize(1);
|
||||
}
|
||||
@Test void topicDirectorySymlinkCannotRedirectAgentPublication() throws Exception {
|
||||
org.junit.jupiter.api.Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows"));
|
||||
init(); ok("agent","configure","--adapter","fixture-general");
|
||||
Path outside=Files.createTempDirectory(root.getParent(),"aie-outside-");
|
||||
try {
|
||||
Files.createSymbolicLink(work().resolve("topics"),outside);
|
||||
byte[] before=Files.readAllBytes(work().resolve("work.md"));
|
||||
assertThat(cli("topic","create","WRK-0001","Unsafe")).isEqualTo(2);
|
||||
assertThat(Files.readAllBytes(work().resolve("work.md"))).isEqualTo(before);
|
||||
assertThat(cli("work","validate","WRK-0001")).isEqualTo(4);
|
||||
assertThat(cli("agent","run","WRK-0001","--task","Topic: Proposed idea")).isEqualTo(2);
|
||||
try(var paths=Files.list(outside)) { assertThat(paths.toList()).isEmpty(); }
|
||||
assertThat(Files.readAllBytes(work().resolve("work.md"))).isEqualTo(before);
|
||||
} finally { Files.delete(work().resolve("topics")); Files.delete(outside); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import net.intrepid.aiengineering.project.ProjectService;
|
||||
import net.intrepid.aiengineering.verification.VerificationService;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class WorkHexadecimalTest {
|
||||
@TempDir Path root;
|
||||
private final WorkService works = new WorkService();
|
||||
private String output;
|
||||
private void init() { new ProjectService().initialize(root, "Test"); }
|
||||
private Work create(String title) { return works.create(root, title, "", "Goal", "", List.of(), List.of(), List.of(), "human"); }
|
||||
private Path counter() { return root.resolve(".ai-engineering/works/.sequence.yaml"); }
|
||||
private void sequence(String yaml) throws Exception { Files.writeString(counter(), yaml); }
|
||||
private int cli(Path cwd, String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(cwd).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(root, args); assertThat(code).as(output).isZero(); }
|
||||
@Test void generatedWorksAdvanceThroughHexadecimalDigits() throws Exception {
|
||||
init(); var ids = new ArrayList<String>();
|
||||
for (int index = 1; index <= 16; index++) ids.add(create("Work " + index).id());
|
||||
assertThat(ids).containsExactly("WRK-0001", "WRK-0002", "WRK-0003", "WRK-0004", "WRK-0005", "WRK-0006", "WRK-0007", "WRK-0008",
|
||||
"WRK-0009", "WRK-000A", "WRK-000B", "WRK-000C", "WRK-000D", "WRK-000E", "WRK-000F", "WRK-0010");
|
||||
assertThat(Files.readString(counter())).contains("schemaVersion: 2", "lastWork: \"0010\"");
|
||||
assertThat(new VerificationService().project(root).valid()).isTrue();
|
||||
}
|
||||
@Test void hexadecimalWorkSupportsAllReferencesAndFreshContext() throws Exception {
|
||||
init(); sequence("schemaVersion: 1\nlastWork: 9\n");
|
||||
ok("work", "create", "Hex Work"); assertThat(output).contains("WRK-000A");
|
||||
for (int index = 1; index <= 10; index++) ok("discussion", "add", "WRK-000A", "--text", "Entry " + index);
|
||||
assertThat(output).contains("DSC-0010"); // Child counters retain their decimal convention.
|
||||
Path evidence = Files.writeString(root.resolve("evidence.txt"), "Observation\n");
|
||||
ok("artifact", "add", "WRK-000A", "--file", evidence.toString(), "--purpose", "Evidence");
|
||||
ok("decision", "draft", "WRK-000A", "--title", "Draft", "--evidence", "ART-0001");
|
||||
ok("work", "update", "WRK-000A", "--goal", "Refined hexadecimal Work");
|
||||
ok("work", "context", "WRK-000A", "--format", "json"); String context = output;
|
||||
Path nested = Files.createDirectories(root.resolve("src/feature"));
|
||||
assertThat(cli(nested, "work", "context", "WRK-000A", "--format", "json")).as(output).isZero();
|
||||
assertThat(output).isEqualTo(context).contains("Refined hexadecimal Work", "DSC-0010", "DEC-0001", "ART-0001");
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void legacyDecimalIdentifiersAndCounterRemainReadableWithoutRenaming() throws Exception {
|
||||
init(); Work first = create("Legacy"); Path oldFolder = works.folder(root, first.id());
|
||||
Path legacyFolder = oldFolder.resolveSibling("WRK-0010-legacy"); Files.move(oldFolder, legacyFolder);
|
||||
Path work = legacyFolder.resolve("work.md");
|
||||
Files.writeString(work, Files.readString(work).replace("WRK-0001", "WRK-0010"));
|
||||
byte[] originalWork = Files.readAllBytes(work);
|
||||
String legacySequence = "schemaVersion: 1\nlastWork: 10\n"; sequence(legacySequence);
|
||||
assertThat(new VerificationService().project(root).valid()).isTrue();
|
||||
assertThat(works.load(root, "WRK-0010").title()).isEqualTo("Legacy");
|
||||
assertThat(Files.readString(counter())).isEqualTo(legacySequence);
|
||||
assertThat(create("Next").id()).isEqualTo("WRK-0011");
|
||||
assertThat(Files.readAllBytes(work)).isEqualTo(originalWork);
|
||||
assertThat(Files.isDirectory(legacyFolder)).isTrue();
|
||||
assertThat(Files.readString(counter())).contains("schemaVersion: 2", "lastWork: \"0011\"");
|
||||
}
|
||||
@Test void legacyReservationStillProtectsRemovedWorkIdentifiers() throws Exception {
|
||||
init(); sequence("schemaVersion: 1\nlastWork: 16\n");
|
||||
assertThat(create("After removed legacy Works").id()).isEqualTo("WRK-0017");
|
||||
Path folder = works.folder(root, "WRK-0017"); Files.move(folder, root.resolve("removed-work"));
|
||||
assertThat(create("Next").id()).isEqualTo("WRK-0018");
|
||||
}
|
||||
@Test void listOrderIsNumericWhenTheHexadecimalWidthIncreases() throws Exception {
|
||||
init(); sequence("schemaVersion: 2\nlastWork: \"FFFE\"\n");
|
||||
assertThat(create("First").id()).isEqualTo("WRK-FFFF");
|
||||
assertThat(create("Second").id()).isEqualTo("WRK-10000");
|
||||
assertThat(works.list(root).stream().map(Work::id)).containsExactly("WRK-FFFF", "WRK-10000");
|
||||
assertThat(new VerificationService().project(root).valid()).isTrue();
|
||||
}
|
||||
@Test void exhaustedOrInvalidCountersCannotCreatePartialWorks() throws Exception {
|
||||
init();
|
||||
for (String yaml : List.of("schemaVersion: 2\nlastWork: \"FFFFFFFFF\"\n", "schemaVersion: 2\nlastWork: \"000a\"\n",
|
||||
"schemaVersion: 2\nlastWork: \"1000000000\"\n", "schemaVersion: 1\nlastWork: -1\n", "schemaVersion: 99\nlastWork: 1\n")) {
|
||||
sequence(yaml);
|
||||
assertThat(cli(root, "work", "create", "Must not exist")).as(output).isEqualTo(4);
|
||||
assertThat(Files.readString(counter())).isEqualTo(yaml);
|
||||
try (var files = Files.list(counter().getParent())) {
|
||||
assertThat(files.map(p -> p.getFileName().toString())).containsExactly(".sequence.yaml");
|
||||
}
|
||||
}
|
||||
}
|
||||
@Test void workIdentifierValidationAcceptsCanonicalHexOnly() {
|
||||
init();
|
||||
for (String invalid : List.of("WRK-000a", "WRK-000G", "WRK-0000", "WRK-1000000000", "WRK-0x01", "../WRK-000A"))
|
||||
assertThat(cli(root, "work", "show", invalid)).as(output).isEqualTo(2);
|
||||
assertThat(cli(root, "work", "show", "WRK-000A")).isEqualTo(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package net.intrepid.aiengineering;
|
||||
|
||||
import net.intrepid.aiengineering.cli.EngineeringCli;
|
||||
import net.intrepid.aiengineering.discussion.DiscussionService;
|
||||
import net.intrepid.aiengineering.work.WorkService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class WorkUpdateTest {
|
||||
@TempDir Path root;
|
||||
private final WorkService works = new WorkService();
|
||||
private String output;
|
||||
private int cli(String... args) {
|
||||
var out = new StringWriter(); var err = new StringWriter();
|
||||
int code = new EngineeringCli(root).execute(new PrintWriter(out), new PrintWriter(err), args);
|
||||
output = out + err.toString(); return code;
|
||||
}
|
||||
private void ok(String... args) { int code = cli(args); assertThat(code).as(output).isZero(); }
|
||||
private void initialize() {
|
||||
ok("init", "--name", "Test");
|
||||
ok("work", "create", "One", "--description", "Description", "--goal", "Original goal", "--motivation", "Motivation",
|
||||
"--constraint", "Original constraint", "--acceptance", "Original criterion", "--author", "creator");
|
||||
}
|
||||
@Test void updatesFieldsWithoutChangingIdentityHistoryOrOtherWorks() throws Exception {
|
||||
initialize(); ok("work", "create", "Two");
|
||||
ok("discussion", "add", "WRK-0001", "--text", "Preserve this discussion");
|
||||
Path source = Files.writeString(root.resolve("evidence.txt"), "Observation\n");
|
||||
ok("artifact", "add", "WRK-0001", "--file", source.toString(), "--purpose", "Evidence");
|
||||
ok("decision", "draft", "WRK-0001", "--title", "Draft", "--evidence", "ART-0001");
|
||||
ok("work", "status", "WRK-0001", "BLOCKED");
|
||||
var before = works.load(root, "WRK-0001"); var other = works.load(root, "WRK-0002"); Path folder = works.folder(root, before.id());
|
||||
byte[] discussion = Files.readAllBytes(folder.resolve("discussions/DSC-0001.md"));
|
||||
byte[] decision = Files.readAllBytes(folder.resolve("decisions/DEC-0001.md"));
|
||||
byte[] artifact = Files.readAllBytes(folder.resolve("artifacts/evidence/ART-0001/payload"));
|
||||
ok("work", "update", "WRK-0001", "--title", "Refined title", "--goal", "Refined goal", "--description", "New description",
|
||||
"--motivation", "New motivation", "--constraint", "One limit", "--constraint", "Another limit",
|
||||
"--acceptance", "One criterion", "--acceptance", "Another criterion", "--format", "json");
|
||||
var after = new WorkService().load(root, "WRK-0001");
|
||||
assertThat(after.title()).isEqualTo("Refined title"); assertThat(after.goal()).isEqualTo("Refined goal");
|
||||
assertThat(after.description()).isEqualTo("New description"); assertThat(after.motivation()).isEqualTo("New motivation");
|
||||
assertThat(after.constraints()).containsExactly("One limit", "Another limit");
|
||||
assertThat(after.acceptanceCriteria()).containsExactly("One criterion", "Another criterion");
|
||||
assertThat(after.id()).isEqualTo(before.id()); assertThat(after.author()).isEqualTo(before.author());
|
||||
assertThat(after.createdAt()).isEqualTo(before.createdAt()); assertThat(after.status()).isEqualTo(before.status());
|
||||
assertThat(after.repositories()).isEqualTo(before.repositories());
|
||||
assertThat(after.discussions()).isEqualTo(before.discussions()); assertThat(after.decisions()).isEqualTo(before.decisions());
|
||||
assertThat(after.artifacts()).isEqualTo(before.artifacts());
|
||||
assertThat(Instant.parse(after.updatedAt())).isAfter(Instant.parse(before.updatedAt()));
|
||||
assertThat(works.folder(root, after.id())).isEqualTo(folder);
|
||||
assertThat(works.load(root, "WRK-0002")).isEqualTo(other);
|
||||
assertThat(Files.readAllBytes(folder.resolve("discussions/DSC-0001.md"))).isEqualTo(discussion);
|
||||
assertThat(Files.readAllBytes(folder.resolve("decisions/DEC-0001.md"))).isEqualTo(decision);
|
||||
assertThat(Files.readAllBytes(folder.resolve("artifacts/evidence/ART-0001/payload"))).isEqualTo(artifact);
|
||||
assertThat(new DiscussionService().list(root, after.id()).getFirst().text()).isEqualTo("Preserve this discussion");
|
||||
ok("work", "context", "WRK-0001"); assertThat(output).contains("Refined goal", "Another criterion", "BLOCKED", "Preserve this discussion");
|
||||
ok("project", "validate");
|
||||
}
|
||||
@Test void omittedFieldsArePreservedAndIdenticalUpdatesDoNotRewrite() throws Exception {
|
||||
initialize(); var before = works.load(root, "WRK-0001");
|
||||
Path file = works.folder(root, before.id()).resolve("work.md");
|
||||
byte[] original = Files.readAllBytes(file);
|
||||
ok("work", "update", "WRK-0001", "--goal", "Original goal");
|
||||
assertThat(Files.readAllBytes(file)).isEqualTo(original); assertThat(works.load(root, before.id())).isEqualTo(before);
|
||||
ok("work", "update", "WRK-0001", "--description", "");
|
||||
var after = works.load(root, before.id());
|
||||
assertThat(after.description()).isEmpty(); assertThat(after.goal()).isEqualTo(before.goal());
|
||||
assertThat(after.constraints()).isEqualTo(before.constraints()); assertThat(after.acceptanceCriteria()).isEqualTo(before.acceptanceCriteria());
|
||||
assertThat(after.motivation()).isEqualTo(before.motivation());
|
||||
}
|
||||
@Test void listReplacementAndExplicitClearingAreDistinct() {
|
||||
initialize();
|
||||
ok("work", "update", "WRK-0001", "--constraint", "Replacement");
|
||||
assertThat(works.load(root, "WRK-0001").constraints()).containsExactly("Replacement");
|
||||
assertThat(works.load(root, "WRK-0001").acceptanceCriteria()).containsExactly("Original criterion");
|
||||
ok("work", "update", "WRK-0001", "--clear-constraints", "--clear-acceptance");
|
||||
assertThat(works.load(root, "WRK-0001").constraints()).isEmpty(); assertThat(works.load(root, "WRK-0001").acceptanceCriteria()).isEmpty();
|
||||
}
|
||||
@Test void invalidUpdatesFailWithoutPartialWrites() throws Exception {
|
||||
initialize(); Path file = works.folder(root, "WRK-0001").resolve("work.md"); byte[] original = Files.readAllBytes(file);
|
||||
for (String[] change : List.of(new String[]{}, new String[]{"--title", " "}, new String[]{"--goal", ""},
|
||||
new String[]{"--goal", "Must not persist", "--constraint", " "},
|
||||
new String[]{"--constraint", "Limit", "--clear-constraints"}, new String[]{"--acceptance", "Criterion", "--clear-acceptance"})) {
|
||||
var args = new java.util.ArrayList<>(List.of("work", "update", "WRK-0001")); args.addAll(List.of(change));
|
||||
assertThat(cli(args.toArray(String[]::new))).as(output).isEqualTo(2);
|
||||
assertThat(Files.readAllBytes(file)).isEqualTo(original);
|
||||
}
|
||||
assertThat(cli("work", "update", "WRK-9999", "--goal", "Missing")).isEqualTo(3);
|
||||
assertThat(cli("work", "update", "../escape", "--goal", "Unsafe")).isEqualTo(2);
|
||||
}
|
||||
@Test void metadataUpdatesPreserveExistingTrailingNotes() throws Exception {
|
||||
initialize(); Path file = works.folder(root, "WRK-0001").resolve("work.md");
|
||||
String notes = "\n## Local notes\r\n\r\nPreserve this text exactly.\r\n";
|
||||
Files.writeString(file, Files.readString(file) + notes);
|
||||
ok("work", "update", "WRK-0001", "--goal", "Updated goal");
|
||||
assertThat(Files.readString(file)).endsWith(notes);
|
||||
ok("discussion", "add", "WRK-0001", "--text", "A new reference");
|
||||
assertThat(Files.readString(file)).endsWith(notes);
|
||||
ok("work", "status", "WRK-0001", "ACTIVE"); assertThat(Files.readString(file)).endsWith(notes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package net.intrepid.aiengineering.agent;
|
||||
|
||||
import net.intrepid.aiengineering.agent.internal.LocalProcess;
|
||||
import net.intrepid.aiengineering.discussion.*;
|
||||
import net.intrepid.aiengineering.filesystem.*;
|
||||
import net.intrepid.aiengineering.project.*;
|
||||
import net.intrepid.aiengineering.work.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
class CliTransportTest {
|
||||
@TempDir Path root;
|
||||
private Path trace;
|
||||
private void init() throws Exception {
|
||||
new ProjectService().initialize(root, "Provider fixture");
|
||||
new WorkService().create(root, "One", "", "Portable state", "", List.of(), List.of("Continuity"), List.of(), "fixture-human");
|
||||
new DiscussionService().add(root, "WRK-0001", "Original context", DiscussionEntry.Kind.NOTE, "fixture-human", "main", null);
|
||||
trace = root.resolve("invocations.txt");
|
||||
}
|
||||
private LocalProcess process(String mode) throws Exception { return process(mode, Map.of()); }
|
||||
private LocalProcess process(String mode, Map<String,String> additions) throws Exception {
|
||||
String java = Path.of(System.getProperty("java.home"), "bin", "java").toString();
|
||||
String classes = Path.of(ProviderProcessFixture.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
|
||||
var commands = new HashMap<String,List<String>>();
|
||||
for (String provider : List.of("codex", "claude")) commands.put(provider, List.of(java, "-cp", classes, ProviderProcessFixture.class.getName(), mode, provider));
|
||||
var env = new HashMap<>(additions); env.put("AIE_TEST_TRACE", trace.toString()); return new LocalProcess(commands, env);
|
||||
}
|
||||
private AgentService service(String mode) throws Exception {
|
||||
var process = process(mode);
|
||||
return new AgentService(Map.of("codex-cli", new CliAgentAdapter("codex-cli", process), "claude-cli", new CliAgentAdapter("claude-cli", process)));
|
||||
}
|
||||
private void configure(AgentService service, String adapter, int seconds) { service.configure(root, "general", adapter, "general", "default", null, seconds); }
|
||||
private Path work() { return root.resolve(".ai-engineering/works/WRK-0001-one/work.md"); }
|
||||
private void cleaned() throws Exception {
|
||||
for (String line : Files.readAllLines(trace)) if (line.startsWith("cwd=")) {
|
||||
Path directory = Path.of(line.substring(4)); assertThat(directory).isNotEqualTo(root); assertThat(Files.exists(directory)).isFalse();
|
||||
}
|
||||
}
|
||||
@Test void bothProviderProtocolsUseStdinIsolatedArgumentsAndPersistPortableProvenance() throws Exception {
|
||||
init(); var service = service("success"); configure(service, "codex-cli", 5);
|
||||
service.configure(root, "analyze", "claude-cli", "reviewer", "fixture-model", null, 5);
|
||||
String task = "Summarize this ; $(touch SHOULD_NOT_EXIST)";
|
||||
var codex = service.run(root, "WRK-0001", task, "summarize", "requesting-agent", "codex");
|
||||
var claude = service.run(root, "WRK-0001", "Analyze recorded context", "analyze", "requesting-agent", "claude");
|
||||
assertThat(codex.result().fixture()).isFalse(); assertThat(codex.provenance().proposal().cliVersion()).isEqualTo("0.169.0");
|
||||
assertThat(claude.provenance().proposal().cliVersion()).isEqualTo("2.1.311");
|
||||
assertThat(claude.executor().profile()).isEqualTo("reviewer");
|
||||
String args = Files.readString(trace); assertThat(args).contains("--sandbox\nread-only", "--disable\nshell_tool", "--restricted", "--tools\n\n", "--model\nfixture-model").doesNotContain(task);
|
||||
assertThat(Files.exists(root.resolve("SHOULD_NOT_EXIST"))).isFalse(); cleaned();
|
||||
var fresh = service("success"); assertThat(fresh.history(root, "WRK-0001")).containsExactly(codex, claude);
|
||||
byte[] before = Files.readAllBytes(work()); assertThat(fresh.run(root, "WRK-0001", task, "summarize", "requesting-agent", "codex")).isEqualTo(codex);
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before);
|
||||
}
|
||||
@Test void naturalLanguageClassificationRoutesToSpecializationAndRecordsBothInvocations() throws Exception {
|
||||
init(); var service = service("success"); configure(service, "codex-cli", 5);
|
||||
service.configure(root, "summarize", "claude-cli", "synthesizer", "default", null, 5);
|
||||
var result = service.run(root, "WRK-0001", "What have we learned?", null, "agent", "natural");
|
||||
assertThat(result.activity()).isEqualTo("summarize"); assertThat(result.executor().adapter()).isEqualTo("claude-cli");
|
||||
assertThat(result.provenance().classification().transport()).isEqualTo("codex-cli");
|
||||
assertThat(result.provenance().proposal().transport()).isEqualTo("claude-cli"); cleaned();
|
||||
}
|
||||
@Test void invalidWireOutputAndWrongReferencesNeverPublishARun() throws Exception {
|
||||
init();
|
||||
for (String mode : List.of("bad-json", "unknown-field", "bad-reference")) for (String adapter : List.of("codex-cli", "claude-cli")) {
|
||||
var service = service(mode); configure(service, adapter, 5); byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "Bad provider", "summarize", "agent", mode + adapter)).isInstanceOf(ProtocolException.class);
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before); assertThat(new WorkService().load(root, "WRK-0001").agentRuns()).isEmpty(); cleaned();
|
||||
}
|
||||
}
|
||||
@Test void providerFailureDoesNotLeakStderrSecretsOrMutateTheWork() throws Exception {
|
||||
init(); var service = service("failure"); configure(service, "claude-cli", 5); byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "Fail", "summarize", "agent", "failure"))
|
||||
.isInstanceOf(ProtocolException.class).hasMessageContaining("authenticate").hasMessageNotContaining("sk-fixture-secret");
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before); cleaned();
|
||||
}
|
||||
@Test void timeoutTerminatesDescendantsAndCleansThePrivateWorkspace() throws Exception {
|
||||
init(); Path pidFile = root.resolve("child.pid"); var process = process("descendant", Map.of("AIE_TEST_PID", pidFile.toString()));
|
||||
var service = new AgentService(Map.of("codex-cli", new CliAgentAdapter("codex-cli", process))); configure(service, "codex-cli", 1);
|
||||
byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "Wait", "summarize", "agent", "timeout")).isInstanceOf(ProtocolException.class).hasMessageContaining("timed out");
|
||||
long pid = Long.parseLong(Files.readString(pidFile));
|
||||
for (int i = 0; i < 40 && ProcessHandle.of(pid).map(ProcessHandle::isAlive).orElse(false); i++) Thread.sleep(25);
|
||||
assertThat(ProcessHandle.of(pid).map(ProcessHandle::isAlive).orElse(false)).isFalse();
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before); cleaned();
|
||||
}
|
||||
@Test void oversizedOrInvalidUtf8OutputIsRejectedAndStructuredClaudeOutputIsRequired() throws Exception {
|
||||
init();
|
||||
for (String mode : List.of("flood", "bad-utf8", "missing-structured")) {
|
||||
var service = service(mode); configure(service, "claude-cli", 5); byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "Invalid", "summarize", "agent", mode)).isInstanceOf(ProtocolException.class);
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before); cleaned();
|
||||
}
|
||||
}
|
||||
@Test void codexFinalMessageCannotBeRedirectedThroughASymlink() throws Exception {
|
||||
org.junit.jupiter.api.Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows"));
|
||||
init(); Path original = Files.writeString(root.resolve("outside.json"), "Original");
|
||||
var process = process("symlink", Map.of("AIE_TEST_OUTSIDE", original.toString()));
|
||||
var service = new AgentService(Map.of("codex-cli", new CliAgentAdapter("codex-cli", process))); configure(service, "codex-cli", 5);
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "Symlink", "summarize", "agent", "symlink")).isInstanceOf(ProtocolException.class);
|
||||
assertThat(Files.readString(original)).isEqualTo("Original"); cleaned();
|
||||
}
|
||||
@Test void missingExecutableIsDiagnosedBeforePublication() throws Exception {
|
||||
init(); var process = new LocalProcess(Map.of("codex", List.of(root.resolve("absent-provider").toString())), Map.of());
|
||||
var service = new AgentService(Map.of("codex-cli", new CliAgentAdapter("codex-cli", process))); configure(service, "codex-cli", 5);
|
||||
byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> service.run(root, "WRK-0001", "No CLI", "summarize", "agent", "absent")).isInstanceOf(ProtocolException.class).hasMessageContaining("Cannot start");
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before);
|
||||
}
|
||||
@Test void independentJvmReloadsTheCanonicalRunWithoutAnyProviderInstalledOnItsPath() throws Exception {
|
||||
init(); var service = service("success"); configure(service, "codex-cli", 5);
|
||||
service.run(root, "WRK-0001", "Summarize", "summarize", "agent", "persisted");
|
||||
Path log = root.resolve("reloaded.json");
|
||||
var builder = new ProcessBuilder(Path.of(System.getProperty("java.home"), "bin", "java").toString(), "-jar", System.getProperty("cli.jar"), "--project", root.toString(), "work", "context", "WRK-0001", "--format", "json").redirectErrorStream(true).redirectOutput(log.toFile());
|
||||
builder.environment().put("PATH", root.resolve("no-tools").toString()); var child = builder.start();
|
||||
boolean done = child.waitFor(30, TimeUnit.SECONDS); if (!done) child.destroyForcibly();
|
||||
assertThat(done).isTrue(); assertThat(child.exitValue()).as(Files.readString(log)).isZero();
|
||||
assertThat(Files.readString(log)).contains("Subprocess fixture summary", "cliVersion", "0.169.0", "persisted", "requester");
|
||||
}
|
||||
@Test void clarificationCreatesSuggestionsAndHumanPendingQuestionsWhileUnknownActivityIsRejected() throws Exception {
|
||||
init(); var unknown = service("unknown-activity"); configure(unknown, "codex-cli", 5); byte[] before = Files.readAllBytes(work());
|
||||
assertThatThrownBy(() -> unknown.run(root, "WRK-0001", "Ambiguous", null, "agent", "unknown")).isInstanceOf(ProtocolException.class).hasMessageContaining("unsupported activity");
|
||||
assertThat(Files.readAllBytes(work())).isEqualTo(before);
|
||||
var service = service("clarify"); var run = service.run(root, "WRK-0001", "Ambiguous", null, "agent", "clarify");
|
||||
assertThat(run.activity()).isEqualTo("clarify"); var survey = new SurveyService().get(root, "WRK-0001", "SVY-0001");
|
||||
assertThat(survey.pending()).hasSize(1); assertThat(survey.questions().getFirst().options()).hasSize(2); assertThat(survey.answers()).isEmpty();
|
||||
}
|
||||
@Test void optionalTransportMetadataDoesNotChangeLegacyFixtureFingerprintsOrSerialization() throws Exception {
|
||||
init(); var service = new AgentService(); service.configure(root, "general", "fixture-general", "fixture", "deterministic", null);
|
||||
assertThat(Documents.json(new ProjectService().load(root))).doesNotContain("timeoutSeconds");
|
||||
var run = service.run(root, "WRK-0001", "summarize", "summarize", "agent", "legacy");
|
||||
assertThat(Documents.json(run)).doesNotContain("provenance"); assertThat(new AgentService().views(root, "WRK-0001").getFirst().stale()).isFalse();
|
||||
assertThat(new AgentService().context(root, "WRK-0001").previousRuns()).containsExactly(run);
|
||||
}
|
||||
@Test void essentialUserIdentityReachesTheProviderWithoutEnteringCanonicalProvenance() throws Exception {
|
||||
org.junit.jupiter.api.Assumptions.assumeTrue(System.getenv("USER") != null);
|
||||
init(); var process = process("identity", Map.of("AIE_TEST_EXPECTED_USER", System.getenv("USER")));
|
||||
var service = new AgentService(Map.of("claude-cli", new CliAgentAdapter("claude-cli", process))); configure(service, "claude-cli", 5);
|
||||
var run = service.run(root, "WRK-0001", "Summary", "summarize", "agent", "identity");
|
||||
assertThat(Documents.json(run.provenance())).doesNotContain(System.getenv("USER")); cleaned();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.intrepid.aiengineering.agent;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
/** Pure-JDK subprocess fixture: no provider installation, key or model call. */
|
||||
public final class ProviderProcessFixture {
|
||||
public static void main(String[] args) throws Exception {
|
||||
var values = List.of(args); String mode = args[0], provider = args[1];
|
||||
String trace = System.getenv("AIE_TEST_TRACE");
|
||||
if (trace != null) Files.writeString(Path.of(trace), "cwd=" + Path.of("").toAbsolutePath() + "\n" + String.join("\n", values) + "\n", StandardOpenOption.CREATE, StandardOpenOption.APPEND);
|
||||
if (values.contains("--version")) { System.out.println(provider.equals("codex") ? "codex-cli 0.169.0" : "2.1.311 (Claude Code)"); return; }
|
||||
if (values.contains("--help")) {
|
||||
System.out.println("--output-schema --output-last-message --ignore-user-config --ephemeral --sandbox --json-schema --tools --restricted --safe-mode --permission-prompts --no-session-persistence"); return;
|
||||
}
|
||||
if (mode.equals("sleeper")) { Thread.sleep(30_000); return; }
|
||||
if (mode.equals("timeout") || mode.equals("descendant")) {
|
||||
if (mode.equals("descendant")) {
|
||||
var child = new ProcessBuilder(Path.of(System.getProperty("java.home"), "bin", "java").toString(), "-cp", System.getProperty("java.class.path"), ProviderProcessFixture.class.getName(), "sleeper", provider).inheritIO().start();
|
||||
Files.writeString(Path.of(System.getenv("AIE_TEST_PID")), Long.toString(child.pid()));
|
||||
}
|
||||
Thread.sleep(30_000); return;
|
||||
}
|
||||
if (mode.equals("failure")) { System.err.println("Authentication failed: sk-fixture-secret-must-not-leak"); System.exit(7); }
|
||||
if (mode.equals("flood")) { System.out.print("X".repeat(1024 * 1024 + 8192)); return; }
|
||||
if (mode.equals("bad-utf8")) { System.out.write(new byte[]{(byte)0xC3, (byte)0x28}); return; }
|
||||
String input = new String(System.in.readAllBytes(), StandardCharsets.UTF_8);
|
||||
if (mode.equals("identity") && !Objects.equals(System.getenv("USER"), System.getenv("AIE_TEST_EXPECTED_USER")))
|
||||
throw new IllegalStateException("Required user identity was not forwarded");
|
||||
String schema = provider.equals("codex") ? Files.readString(Path.of(args[values.indexOf("--output-schema") + 1])) : args[values.indexOf("--json-schema") + 1];
|
||||
boolean classify = schema.contains("\"activity\"");
|
||||
String wire = classify ? "{\"schemaVersion\":1,\"activity\":\"summarize\"}"
|
||||
: "{\"schemaVersion\":1,\"summary\":\"Subprocess fixture summary for WRK-0001; source DSC-0001\",\"topics\":[],\"surveys\":[],\"entries\":[],\"dispositions\":[],\"decision\":null}";
|
||||
if (mode.equals("unknown-activity") && classify) wire = "{\"schemaVersion\":1,\"activity\":\"execute\"}";
|
||||
if (mode.equals("clarify")) wire = classify ? "{\"schemaVersion\":1,\"activity\":\"clarify\"}"
|
||||
: "{\"schemaVersion\":1,\"summary\":\"Needs human clarification\",\"topics\":[],\"surveys\":[{\"title\":\"Focus\",\"description\":\"Choose scope\",\"questions\":[{\"topic\":\"main\",\"text\":\"Which direction?\",\"options\":[\"Summary\",\"Alternative\"],\"multiple\":false,\"recommend\":\"1\",\"sources\":[\"DSC-0001\"]}]}],\"entries\":[],\"dispositions\":[],\"decision\":null}";
|
||||
if (mode.equals("bad-json")) wire = "{broken";
|
||||
if (mode.equals("unknown-field")) wire = wire.substring(0, wire.length() - 1) + ",\"humanApproved\":true}";
|
||||
if (mode.equals("bad-reference")) wire = "{\"schemaVersion\":1,\"summary\":\"Invalid source\",\"topics\":[{\"key\":\"new\",\"title\":\"Bad\",\"description\":\"\",\"sources\":[\"DSC-9999\"]}],\"surveys\":[],\"entries\":[],\"dispositions\":[],\"decision\":null}";
|
||||
if (provider.equals("codex")) {
|
||||
Path output = Path.of(args[values.indexOf("--output-last-message") + 1]);
|
||||
if (mode.equals("symlink")) Files.createSymbolicLink(output, Path.of(System.getenv("AIE_TEST_OUTSIDE")));
|
||||
else Files.writeString(output, wire);
|
||||
System.out.println("{\"type\":\"turn.completed\"}");
|
||||
} else {
|
||||
if (mode.equals("missing-structured")) System.out.println("{\"subtype\":\"success\",\"is_error\":false,\"result\":\"not structured\"}");
|
||||
else System.out.println("{\"subtype\":\"success\",\"is_error\":false,\"structured_output\":" + wire + "}");
|
||||
}
|
||||
if (!input.contains("WRK-0001")) throw new IllegalStateException("Fixture did not receive Work context");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user