Add versioned Markdown discussion documents with legacy YAML reading and explicit migration that backs up originals and preserves semantic history. Render readable discussion and decision prose in Markdown context, document compatibility, and extend native smoke coverage for migration. Validated with 29 passing tests, macOS ARM64 native smoke, and context-preserving migration of the Zelda pilot Work.
115 lines
7.5 KiB
Java
115 lines
7.5 KiB
Java
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.nio.file.*;
|
|
import java.io.*;
|
|
import static org.assertj.core.api.Assertions.*;
|
|
|
|
class ProtocolIntegrationTest {
|
|
@TempDir Path root;
|
|
record Result(int code, String out, String err) {}
|
|
Result run(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);
|
|
return new Result(code, out.toString(), err.toString());
|
|
}
|
|
Result ok(String... args) {
|
|
var r = run(root, args);
|
|
assertThat(r.code()).as(r.err()).isZero(); return r;
|
|
}
|
|
void init() { ok("init", "--name", "Test Project"); }
|
|
void repository(String name) throws Exception {
|
|
Path path = Files.createDirectory(root.resolve(name));
|
|
var process = new ProcessBuilder("git", "init", path.toString()).redirectErrorStream(true).start();
|
|
process.getInputStream().readAllBytes(); assertThat(process.waitFor()).isZero();
|
|
ok("repo", "add", name, "--path", name);
|
|
}
|
|
@Test void portableMultiRepositoryContinuity() throws Exception {
|
|
init(); repository("runtime"); repository("studio");
|
|
ok("work", "create", "Improve scene editor", "--goal", "Portable rendering", "--repo", "runtime", "--repo", "studio",
|
|
"--constraint", "No web server", "--acceptance", "Context reloads");
|
|
ok("discussion", "add", "WRK-0001", "--kind", "QUESTION", "--text", "Evaluate Canvas rendering?");
|
|
ok("discussion", "add", "WRK-0001", "--kind", "CONCLUSION", "--text", "Evaluate layered Canvas first");
|
|
ok("decision", "draft", "WRK-0001", "--title", "Use layered Canvas");
|
|
Path evidence = Files.writeString(root.resolve("evidence.txt"), "Rendering experiment: 60 fps\n");
|
|
ok("artifact", "add", "WRK-0001", "--file", evidence.toString(), "--purpose", "Rendering evidence");
|
|
String before = ok("work", "context", "WRK-0001").out();
|
|
Path nested = Files.createDirectories(root.resolve("studio/src/editor"));
|
|
var fresh = run(nested, "work", "context", "WRK-0001");
|
|
assertThat(fresh.code()).as(fresh.err()).isZero();
|
|
assertThat(fresh.out()).isEqualTo(before).contains("Portable rendering", "No web server", "Context reloads",
|
|
"Evaluate Canvas rendering?", "Use layered Canvas", "DRAFT", "Rendering evidence", "runtime", "studio", "OPEN");
|
|
assertThat(ok("work", "context", "WRK-0001", "--format", "json").out()).contains("\"schemaVersion\"", "sha256");
|
|
ok("project", "validate"); ok("work", "validate", "WRK-0001");
|
|
assertThat(Files.exists(root.resolve(".git"))).isFalse();
|
|
}
|
|
@Test void independentWorksAndDeterministicExports() {
|
|
init(); ok("work", "create", "One"); ok("work", "create", "Two");
|
|
ok("discussion", "add", "WRK-0001", "--text", "Only one");
|
|
assertThat(ok("work", "list", "--format", "json").out()).contains("WRK-0001", "WRK-0002");
|
|
assertThat(ok("work", "context", "WRK-0002").out()).doesNotContain("Only one");
|
|
assertThat(ok("work", "context", "WRK-0001").out()).isEqualTo(ok("work", "context", "WRK-0001").out());
|
|
}
|
|
@Test void singleGitRepositoryCanShareTheEngineeringProjectRoot() throws Exception {
|
|
var git = new ProcessBuilder("git", "init", root.toString()).redirectErrorStream(true).start();
|
|
git.getInputStream().readAllBytes(); assertThat(git.waitFor()).isZero();
|
|
Path source = Files.writeString(root.resolve("main.txt"), "Existing application source\n");
|
|
byte[] gitConfig = Files.readAllBytes(root.resolve(".git/config"));
|
|
init(); ok("repo", "add", "app", "--path", ".");
|
|
assertThat(ok("repo", "list", "--format", "json").out()).contains("\"path\" : \".\"", "\"edit\" : false");
|
|
ok("work", "create", "Improve application", "--repo", "app");
|
|
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"));
|
|
var fresh = run(nested, "work", "context", "WRK-0001", "--format", "json");
|
|
assertThat(fresh.code()).as(fresh.err()).isZero(); assertThat(fresh.out()).isEqualTo(exported);
|
|
ok("project", "validate");
|
|
assertThat(Files.readString(source)).isEqualTo("Existing application source\n");
|
|
assertThat(Files.readAllBytes(root.resolve(".git/config"))).isEqualTo(gitConfig);
|
|
assertThat(run(root, "repo", "add", "duplicate", "--path", "./.").code()).isEqualTo(2);
|
|
}
|
|
@Test void protocolStorageCannotBeRegisteredAsASourceRepository() {
|
|
init();
|
|
assertThat(run(root, "repo", "add", "protocol", "--path", ".ai-engineering").code()).isEqualTo(2);
|
|
}
|
|
@Test void invalidIdentifiersMissingResourcesAndNoOverwrite() throws Exception {
|
|
init();
|
|
assertThat(run(root, "init", "--name", "Again").code()).isEqualTo(2);
|
|
assertThat(run(root, "work", "show", "../../escape").code()).isEqualTo(2);
|
|
assertThat(run(root, "work", "show", "WRK-9999").code()).isEqualTo(3);
|
|
assertThat(run(root, "repo", "add", "missing", "--path", "missing").code()).isEqualTo(3);
|
|
assertThat(run(root, "repo", "add", "escape", "--path", "../escape").code()).isEqualTo(2);
|
|
org.junit.jupiter.api.Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows"), "Symlink fixtures need OS support");
|
|
Path outside = Files.createTempDirectory("aie-outside-");
|
|
Files.createSymbolicLink(root.resolve("escape"), outside);
|
|
assertThat(run(root, "repo", "add", "escape", "--path", "escape").code()).isEqualTo(2);
|
|
}
|
|
@Test void validationDetectsMissingDecisionArtifactAndDuplicateWork() throws Exception {
|
|
init(); ok("work", "create", "One");
|
|
ok("decision", "draft", "WRK-0001", "--title", "Draft");
|
|
Path work = root.resolve(".ai-engineering/works/WRK-0001-one");
|
|
Files.delete(work.resolve("decisions/DEC-0001.md"));
|
|
assertThat(run(root, "work", "validate", "WRK-0001").code()).isEqualTo(4);
|
|
Files.createDirectory(root.resolve(".ai-engineering/works/WRK-0001-copy"));
|
|
Files.copy(work.resolve("work.md"), root.resolve(".ai-engineering/works/WRK-0001-copy/work.md"));
|
|
assertThat(run(root, "project", "validate").code()).isEqualTo(4);
|
|
}
|
|
@Test void invalidConfigurationIsDiagnosed() throws Exception {
|
|
init(); Files.writeString(root.resolve(".ai-engineering/ai-engineering.yaml"), "schemaVersion: 999\n");
|
|
assertThat(run(root, "project", "validate").code()).isEqualTo(4);
|
|
}
|
|
@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"}) {
|
|
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:");
|
|
}
|
|
assertThat(run(root, "--unknown").code()).isEqualTo(2);
|
|
}
|
|
}
|