feat: add CLI env registry and release verification
This commit is contained in:
@@ -79,8 +79,10 @@ mvn -pl platform-parity exec:java -Dexec.mainClass="com.eip4.platform.parity.sel
|
|||||||
|
|
||||||
# EIP4 Agent CLI
|
# EIP4 Agent CLI
|
||||||
mvn -pl platform-cli package
|
mvn -pl platform-cli package
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env add --name local --base-url http://localhost:8084 --use
|
||||||
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --base-url http://localhost:8084
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --base-url http://localhost:8084
|
||||||
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai feature-package --task-id ait-xxx --change-set-id aics-xxx --output target/ai-runs/package.json
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai feature-package --task-id ait-xxx --change-set-id aics-xxx --output target/ai-runs/package.json
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar release verify --package-file target/ai-runs/package.json
|
||||||
```
|
```
|
||||||
|
|
||||||
## tools/
|
## tools/
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ EIP4 当前已经有实体、页面 schema、服务流、菜单、smoke、部署
|
|||||||
|
|
||||||
### P3:发布、回滚和环境治理
|
### P3:发布、回滚和环境治理
|
||||||
|
|
||||||
|
状态:进行中。
|
||||||
|
|
||||||
目标:
|
目标:
|
||||||
|
|
||||||
- CLI 扩展为环境管理和发布编排入口。
|
- CLI 扩展为环境管理和发布编排入口。
|
||||||
@@ -130,6 +132,13 @@ EIP4 当前已经有实体、页面 schema、服务流、菜单、smoke、部署
|
|||||||
- 生产写操作必须有显式环境、审批标记和部署包
|
- 生产写操作必须有显式环境、审批标记和部署包
|
||||||
- 发布失败能用结构化 evidence 回到本地修复链路
|
- 发布失败能用结构化 evidence 回到本地修复链路
|
||||||
|
|
||||||
|
源码级修订:
|
||||||
|
|
||||||
|
- 参考 NocoBase `env/status.ts` 和 `env-guard.ts`,`platform-cli` 新增本地 env registry/current env。
|
||||||
|
- 参考 NocoBase revision 创建前检查版本控制插件的思路,EIP4 后续 revision restore/diff 不能只依赖 JSON 快照,必须有发布系统能力检查。
|
||||||
|
- 新增 `eip4 release verify --package-file FILE`,先做离线发布前门禁,阻断未替换占位符和缺失本地 evidence 的功能包。
|
||||||
|
- 详细源码对照见 `docs/AI_AGENT_Nocobase_SOURCE_REVIEW.md`。
|
||||||
|
|
||||||
### P4:Typed Page Schema 和组件注册表
|
### P4:Typed Page Schema 和组件注册表
|
||||||
|
|
||||||
目标:
|
目标:
|
||||||
@@ -181,6 +190,6 @@ EIP4 应该借鉴的是边界和流程:
|
|||||||
| P0 | 完成 | `platform-ai` 主链路已提交 |
|
| P0 | 完成 | `platform-ai` 主链路已提交 |
|
||||||
| P1 | 第一版完成 | 已新增 `platform-cli` 和 Skills 规范骨架 |
|
| P1 | 第一版完成 | 已新增 `platform-cli` 和 Skills 规范骨架 |
|
||||||
| P2 | 第一版完成 | 已新增功能包快照、里程碑 revision、CLI 命令和持久化表 |
|
| P2 | 第一版完成 | 已新增功能包快照、里程碑 revision、CLI 命令和持久化表 |
|
||||||
| P3 | 待开始 | 依赖 P2 的功能包和版本模型 |
|
| P3 | 进行中 | 已开始 env registry/current env/cross-env guard/release verify |
|
||||||
| P4 | 待开始 | 依赖页面 schema 现状清理 |
|
| P4 | 待开始 | 依赖页面 schema 现状清理 |
|
||||||
| P5 | 待开始 | 依赖权限、审计、工具白名单成熟 |
|
| P5 | 待开始 | 依赖权限、审计、工具白名单成熟 |
|
||||||
|
|||||||
93
docs/AI_AGENT_Nocobase_SOURCE_REVIEW.md
Normal file
93
docs/AI_AGENT_Nocobase_SOURCE_REVIEW.md
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# NocoBase 源码级对照和 EIP4 修订
|
||||||
|
|
||||||
|
日期:2026-06-17
|
||||||
|
|
||||||
|
本文件补充 `docs/AI_AGENT_Nocobase_ADOPTION_PLAN.md` 的源码级依据。结论:EIP4 不照搬 NocoBase 的 TypeScript 插件运行时,但 P3 之后必须参考它的 CLI/env/revision/skills/tool-registry 边界,否则容易只做出“HTTP wrapper”,做不到可持续的 Agent 开发体系。
|
||||||
|
|
||||||
|
## 一、已抽样源码
|
||||||
|
|
||||||
|
| 主题 | NocoBase 源码 | 对 EIP4 的影响 |
|
||||||
|
|---|---|---|
|
||||||
|
| CLI env status | `packages/core/cli/src/commands/env/status.ts` | CLI 要有 env registry/current env/status,不应只靠 `--base-url` |
|
||||||
|
| 跨 env 确认 | `packages/core/cli/src/lib/env-guard.ts` | 显式选择非当前 env 时需要确认边界 |
|
||||||
|
| API client | `packages/core/cli/src/lib/api-client.ts` | CLI 请求应带结构化 env/token/role/header,后续不能散落在命令里 |
|
||||||
|
| runtime command registry | `packages/core/cli/src/generated/command-registry.ts` | 可根据运行时 API 生成命令,EIP4 后续可用 OpenAPI 生成安全 CLI |
|
||||||
|
| generic resource command | `packages/core/cli/src/lib/resource-command.ts` | CRUD 类命令应统一处理 JSON body、分页、过滤、错误输出 |
|
||||||
|
| plugin import/enable | `packages/core/cli/src/commands/plugin/import.ts`, `packages/core/cli/src/commands/plugin/enable.ts` | EIP4 的 FeaturePackage 后续也要区分导入、启用、发布和重启/刷新 |
|
||||||
|
| revision create | `packages/core/cli/src/commands/revision/create.ts` | revision 不能只是保存 JSON,发布前要检查版本控制能力是否可用 |
|
||||||
|
| skills install | `packages/core/cli/src/commands/skills/install.ts` | Skills 应由 CLI 安装/检查/更新,而不是只放仓库文档 |
|
||||||
|
| AI plugin server | `packages/plugins/@nocobase/plugin-ai/src/server/plugin.ts` | AI 功能要注册 tools、skills、MCP、AI employees、ACL snippet |
|
||||||
|
| FlowEngine | `packages/core/flow-engine/src/flowEngine.ts`, `packages/core/flow-engine/src/models/flowModel.tsx` | 页面 schema 需要演进到 typed model/action/event/resource registry |
|
||||||
|
|
||||||
|
## 二、对当前实现的校正
|
||||||
|
|
||||||
|
### P0-P2 是否做实
|
||||||
|
|
||||||
|
已做实:
|
||||||
|
|
||||||
|
- `platform-ai` 主链路有 Java 实现、JDBC/内存 store、DDL、Web API 和测试。
|
||||||
|
- `platform-cli` 是可运行 jar,不是伪命令。
|
||||||
|
- `FeaturePackage` 和 `Revision` 已有最小持久化模型。
|
||||||
|
|
||||||
|
但它还不是 NocoBase 级完整度:
|
||||||
|
|
||||||
|
- CLI 之前缺少 env registry/current env。
|
||||||
|
- revision 只是功能包快照,不是完整版本控制。
|
||||||
|
- Skills 只是仓库文档,没有 CLI 安装/检查/更新。
|
||||||
|
- AI tools/permissions/MCP/AI employee 还没有平台级注册。
|
||||||
|
- 页面配置还没有 typed FlowModel registry。
|
||||||
|
|
||||||
|
### 已按源码对照修订的 P3 第一批
|
||||||
|
|
||||||
|
- `platform-cli` 新增本地 env registry,默认保存到 `~/.eip4/eip4-cli.json`。
|
||||||
|
- 新增 `eip4 env add/list/use/current/status`。
|
||||||
|
- AI 命令支持 `--env`。
|
||||||
|
- 显式选择非当前 env 时必须加 `--yes`,避免误操作共享环境。
|
||||||
|
- 新增 `eip4 release verify --package-file FILE`,离线检查功能包是否具备本地门禁 evidence、人审标记、SQL/rollback,并阻断 `${...}` 占位符。
|
||||||
|
|
||||||
|
## 三、后续实现顺序
|
||||||
|
|
||||||
|
### P3-1:CLI env 和发布前治理
|
||||||
|
|
||||||
|
状态:进行中。
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- env registry/current env
|
||||||
|
- `release verify`
|
||||||
|
- package/revision 差异检查
|
||||||
|
- 生产环境默认只读
|
||||||
|
|
||||||
|
### P3-2:FeaturePackage 导出/导入
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- `.eip4pkg.json` 文件格式
|
||||||
|
- checksum
|
||||||
|
- import preview
|
||||||
|
- import 后不自动启用
|
||||||
|
|
||||||
|
### P3-3:Revision diff/restore
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- revision diff
|
||||||
|
- rollback plan
|
||||||
|
- rollback 只生成计划和 SQL,不默认执行生产写入
|
||||||
|
|
||||||
|
### P4:Typed UI Registry
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- typed page schema
|
||||||
|
- component/action/event registry
|
||||||
|
- AI 只能选择 registry 中允许的组件和动作
|
||||||
|
|
||||||
|
### P5:AI tools/skills/employee/ACL
|
||||||
|
|
||||||
|
目标:
|
||||||
|
|
||||||
|
- AI tool registry
|
||||||
|
- Skills CLI check/update
|
||||||
|
- AI Agent 权限和审计
|
||||||
|
- MCP 工具白名单
|
||||||
@@ -16,7 +16,13 @@
|
|||||||
4. 使用 CLI 探测环境:
|
4. 使用 CLI 探测环境:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --base-url http://localhost:8084
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env add \
|
||||||
|
--name local \
|
||||||
|
--base-url http://localhost:8084 \
|
||||||
|
--kind local \
|
||||||
|
--use
|
||||||
|
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status
|
||||||
```
|
```
|
||||||
|
|
||||||
5. 如果服务未启动,优先使用重新打包后的 jar:
|
5. 如果服务未启动,优先使用重新打包后的 jar:
|
||||||
@@ -31,4 +37,13 @@ JAVA_HOME=/opt/homebrew/opt/openjdk@21 mvn -pl platform-app -am install -DskipTe
|
|||||||
- 不在用户原始任务目录中直接改动或启动长时间任务,除非用户明确要求。
|
- 不在用户原始任务目录中直接改动或启动长时间任务,除非用户明确要求。
|
||||||
- 不把线上环境设置为默认写入目标。
|
- 不把线上环境设置为默认写入目标。
|
||||||
- 不跳过 JDK 版本检查。
|
- 不跳过 JDK 版本检查。
|
||||||
|
- 显式选择非当前 env 执行 AI 或发布类命令时,必须要求 `--yes` 或等效人工确认。
|
||||||
|
|
||||||
|
## 常用命令
|
||||||
|
|
||||||
|
```bash
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env list
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env current
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env use --name local
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar env status --all
|
||||||
|
```
|
||||||
|
|||||||
@@ -34,15 +34,22 @@ java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai revision \
|
|||||||
--output target/ai-runs/revision.json
|
--output target/ai-runs/revision.json
|
||||||
```
|
```
|
||||||
|
|
||||||
4. 确认部署包包含:
|
4. 运行离线发布校验:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar release verify \
|
||||||
|
--package-file target/ai-runs/feature-package.json
|
||||||
|
```
|
||||||
|
|
||||||
|
5. 确认部署包包含:
|
||||||
- manifest
|
- manifest
|
||||||
- SQL 草案
|
- SQL 草案
|
||||||
- rollback SQL
|
- rollback SQL
|
||||||
- 本地 apply evidence
|
- 本地 apply evidence
|
||||||
- smoke evidence
|
- smoke evidence
|
||||||
- repair evidence
|
- repair evidence
|
||||||
5. 确认部署包需要人工审批。
|
6. 确认部署包需要人工审批。
|
||||||
6. 如果包含 `${parentMenuId}` 等占位符,必须人工替换并复核。
|
7. 如果包含 `${parentMenuId}` 等占位符,必须人工替换并复核;`release verify` 默认会阻断这类包。
|
||||||
|
|
||||||
## 线上 bug 修复路径
|
## 线上 bug 修复路径
|
||||||
|
|
||||||
@@ -57,3 +64,4 @@ java -jar platform-cli/target/platform-cli-0.1.0-SNAPSHOT.jar ai revision \
|
|||||||
- 不让 Agent 默认直接写线上数据库。
|
- 不让 Agent 默认直接写线上数据库。
|
||||||
- 不绕过部署包和人审。
|
- 不绕过部署包和人审。
|
||||||
- 不把 smoke 失败的变更包交给发布流程。
|
- 不把 smoke 失败的变更包交给发布流程。
|
||||||
|
- 不发布 `release verify` 失败的功能包。
|
||||||
|
|||||||
@@ -23,10 +23,18 @@ public final class Eip4Cli {
|
|||||||
|
|
||||||
private final ObjectMapper objectMapper;
|
private final ObjectMapper objectMapper;
|
||||||
private final Eip4HttpClient httpClient;
|
private final Eip4HttpClient httpClient;
|
||||||
|
private final Eip4EnvStore envStore;
|
||||||
|
|
||||||
public Eip4Cli(Eip4HttpClient httpClient) {
|
public Eip4Cli(Eip4HttpClient httpClient) {
|
||||||
this.objectMapper = new ObjectMapper();
|
this.objectMapper = new ObjectMapper();
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
this.envStore = Eip4EnvStore.defaultStore(objectMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
Eip4Cli(Eip4HttpClient httpClient, Eip4EnvStore envStore) {
|
||||||
|
this.objectMapper = new ObjectMapper();
|
||||||
|
this.httpClient = httpClient;
|
||||||
|
this.envStore = envStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -46,6 +54,7 @@ public final class Eip4Cli {
|
|||||||
return switch (args[0]) {
|
return switch (args[0]) {
|
||||||
case "env" -> runEnv(args, out, err);
|
case "env" -> runEnv(args, out, err);
|
||||||
case "ai" -> runAi(args, out, err);
|
case "ai" -> runAi(args, out, err);
|
||||||
|
case "release" -> runRelease(args, out, err);
|
||||||
default -> fail(err, "Unknown command: " + args[0]);
|
default -> fail(err, "Unknown command: " + args[0]);
|
||||||
};
|
};
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
@@ -63,20 +72,186 @@ public final class Eip4Cli {
|
|||||||
printEnvHelp(out);
|
printEnvHelp(out);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (!"status".equals(args[1])) {
|
return switch (args[1]) {
|
||||||
return fail(err, "Unknown env command: " + args[1]);
|
case "add" -> runEnvAdd(args, out);
|
||||||
|
case "list" -> runEnvList(args, out);
|
||||||
|
case "use" -> runEnvUse(args, out);
|
||||||
|
case "current" -> runEnvCurrent(out);
|
||||||
|
case "status" -> runEnvStatus(args, out, err);
|
||||||
|
default -> fail(err, "Unknown env command: " + args[1]);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int runRelease(String[] args, PrintStream out, PrintStream err) throws IOException {
|
||||||
|
if (args.length < 2 || isHelp(args[1])) {
|
||||||
|
printReleaseHelp(out);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return switch (args[1]) {
|
||||||
|
case "verify" -> runReleaseVerify(args, out, err);
|
||||||
|
default -> fail(err, "Unknown release command: " + args[1]);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runReleaseVerify(String[] args, PrintStream out, PrintStream err) throws IOException {
|
||||||
Options options = Options.parse(args, 2);
|
Options options = Options.parse(args, 2);
|
||||||
String baseUrl = baseUrl(options);
|
Path packageFile = Path.of(requiredPart(options.single("package-file"), "package-file"));
|
||||||
|
JsonNode root = objectMapper.readTree(Files.readString(packageFile, StandardCharsets.UTF_8));
|
||||||
|
JsonNode deploymentPackage = root.has("deploymentPackage") ? root.path("deploymentPackage") : root;
|
||||||
|
List<String> blockers = new ArrayList<>();
|
||||||
|
List<String> warnings = new ArrayList<>();
|
||||||
|
|
||||||
|
if (!"READY_FOR_HUMAN_REVIEW".equals(text(deploymentPackage, "status"))) {
|
||||||
|
blockers.add("deploymentPackage.status 必须是 READY_FOR_HUMAN_REVIEW");
|
||||||
|
}
|
||||||
|
if (!deploymentPackage.path("requiresHumanApproval").asBoolean(false)) {
|
||||||
|
blockers.add("deploymentPackage.requiresHumanApproval 必须是 true");
|
||||||
|
}
|
||||||
|
if (!hasTextArrayItems(deploymentPackage.path("sqlStatements"))) {
|
||||||
|
blockers.add("sqlStatements 不能为空");
|
||||||
|
}
|
||||||
|
if (!hasTextArrayItems(deploymentPackage.path("rollbackSqlStatements"))) {
|
||||||
|
blockers.add("rollbackSqlStatements 不能为空");
|
||||||
|
}
|
||||||
|
if (!hasRunEvidence(deploymentPackage.path("runEvidence"), "LOCAL_APPLY", "PASSED")) {
|
||||||
|
blockers.add("缺少通过的 LOCAL_APPLY evidence");
|
||||||
|
}
|
||||||
|
if (!hasRunEvidence(deploymentPackage.path("runEvidence"), "SMOKE", "PASSED")) {
|
||||||
|
blockers.add("缺少通过的 SMOKE evidence");
|
||||||
|
}
|
||||||
|
if (containsPlaceholder(deploymentPackage.path("sqlStatements"))) {
|
||||||
|
blockers.add("sqlStatements 仍包含 ${...} 占位符,必须人工替换后再发布");
|
||||||
|
}
|
||||||
|
deploymentPackage.path("warnings").forEach(warning -> warnings.add(warning.asText()));
|
||||||
|
|
||||||
|
ObjectNode report = objectMapper.createObjectNode();
|
||||||
|
report.put("status", blockers.isEmpty() ? "PASSED" : "FAILED");
|
||||||
|
report.put("packageId", packageId(root, deploymentPackage));
|
||||||
|
report.put("taskId", text(deploymentPackage, "taskId"));
|
||||||
|
report.put("changeSetId", text(deploymentPackage, "changeSetId"));
|
||||||
|
ArrayNode blockerNodes = report.putArray("blockers");
|
||||||
|
blockers.forEach(blockerNodes::add);
|
||||||
|
ArrayNode warningNodes = report.putArray("warnings");
|
||||||
|
warnings.forEach(warningNodes::add);
|
||||||
|
|
||||||
|
if (options.has("json-output")) {
|
||||||
|
out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(report));
|
||||||
|
} else if (blockers.isEmpty()) {
|
||||||
|
out.println("Release package PASSED");
|
||||||
|
out.println("packageId: " + packageId(root, deploymentPackage));
|
||||||
|
if (!warnings.isEmpty()) {
|
||||||
|
out.println("warnings:");
|
||||||
|
warnings.forEach(warning -> out.println("- " + warning));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err.println("Release package FAILED");
|
||||||
|
blockers.forEach(blocker -> err.println("- " + blocker));
|
||||||
|
}
|
||||||
|
return blockers.isEmpty() ? 0 : 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnvAdd(String[] args, PrintStream out) throws IOException {
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
String name = requiredPart(options.single("name"), "name");
|
||||||
|
String baseUrl = Eip4EnvStore.normalizeBaseUrl(requiredPart(options.single("base-url"), "base-url"));
|
||||||
|
String kind = options.single("kind") == null ? "local" : options.single("kind");
|
||||||
|
Eip4EnvStore.EnvConfig env = Eip4EnvStore.normalize(new Eip4EnvStore.EnvConfig(name, kind, baseUrl));
|
||||||
|
envStore.saveEnv(env, options.has("use"));
|
||||||
|
out.println("Saved env: " + env.name());
|
||||||
|
out.println("baseUrl: " + env.baseUrl());
|
||||||
|
if (options.has("use")) {
|
||||||
|
out.println("currentEnv: " + env.name());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnvList(String[] args, PrintStream out) throws IOException {
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
List<Eip4EnvStore.EnvConfig> envs = envStore.listEnvs();
|
||||||
|
String current = envStore.currentEnvName();
|
||||||
|
if (options.has("json-output")) {
|
||||||
|
ObjectNode root = objectMapper.createObjectNode();
|
||||||
|
root.put("currentEnv", current);
|
||||||
|
ArrayNode array = root.putArray("envs");
|
||||||
|
for (Eip4EnvStore.EnvConfig env : envs) {
|
||||||
|
ObjectNode row = array.addObject();
|
||||||
|
row.put("name", env.name());
|
||||||
|
row.put("kind", env.kind());
|
||||||
|
row.put("baseUrl", env.baseUrl());
|
||||||
|
row.put("current", env.name().equals(current));
|
||||||
|
}
|
||||||
|
out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(root));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (envs.isEmpty()) {
|
||||||
|
out.println("No EIP4 envs configured. Add one with `eip4 env add --name local --base-url http://localhost:8084 --use`.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
out.println("CURRENT NAME KIND BASE_URL");
|
||||||
|
for (Eip4EnvStore.EnvConfig env : envs) {
|
||||||
|
out.println((env.name().equals(current) ? "*" : "-") + " "
|
||||||
|
+ env.name() + " " + env.kind() + " " + env.baseUrl());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnvUse(String[] args, PrintStream out) throws IOException {
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
String name = requiredPart(options.single("name"), "name");
|
||||||
|
Eip4EnvStore.EnvConfig env = envStore.useEnv(name);
|
||||||
|
out.println("currentEnv: " + env.name());
|
||||||
|
out.println("baseUrl: " + env.baseUrl());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnvCurrent(PrintStream out) throws IOException {
|
||||||
|
Eip4EnvStore.EnvConfig env = envStore.currentEnv().orElse(null);
|
||||||
|
if (env == null) {
|
||||||
|
out.println("No current EIP4 env configured.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
out.println("currentEnv: " + env.name());
|
||||||
|
out.println("kind: " + env.kind());
|
||||||
|
out.println("baseUrl: " + env.baseUrl());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int runEnvStatus(String[] args, PrintStream out, PrintStream err) throws IOException, InterruptedException {
|
||||||
|
Options options = Options.parse(args, 2);
|
||||||
|
if (options.has("all")) {
|
||||||
|
int exit = 0;
|
||||||
|
for (Eip4EnvStore.EnvConfig env : envStore.listEnvs()) {
|
||||||
|
int code = checkEnvStatus(env.name(), env.baseUrl(), out, err);
|
||||||
|
if (code != 0) {
|
||||||
|
exit = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (envStore.listEnvs().isEmpty()) {
|
||||||
|
out.println("No EIP4 envs configured.");
|
||||||
|
}
|
||||||
|
return exit;
|
||||||
|
}
|
||||||
|
CliTarget target = target(options);
|
||||||
|
return checkEnvStatus(target.envName(), target.baseUrl(), out, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int checkEnvStatus(String envName, String baseUrl, PrintStream out, PrintStream err)
|
||||||
|
throws IOException, InterruptedException {
|
||||||
URI uri = endpoint(baseUrl, "/v3/api-docs");
|
URI uri = endpoint(baseUrl, "/v3/api-docs");
|
||||||
Eip4HttpResponse response = httpClient.send("GET", uri, null);
|
Eip4HttpResponse response = httpClient.send("GET", uri, null);
|
||||||
if (!response.successful()) {
|
if (!response.successful()) {
|
||||||
err.println("EIP4 env NOT_READY");
|
err.println("EIP4 env NOT_READY");
|
||||||
|
if (!envName.isBlank()) {
|
||||||
|
err.println("env: " + envName);
|
||||||
|
}
|
||||||
err.println("baseUrl: " + baseUrl);
|
err.println("baseUrl: " + baseUrl);
|
||||||
err.println("status: " + response.statusCode());
|
err.println("status: " + response.statusCode());
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
out.println("EIP4 env READY");
|
out.println("EIP4 env READY");
|
||||||
|
if (!envName.isBlank()) {
|
||||||
|
out.println("env: " + envName);
|
||||||
|
}
|
||||||
out.println("baseUrl: " + baseUrl);
|
out.println("baseUrl: " + baseUrl);
|
||||||
out.println("apiDocs: " + uri);
|
out.println("apiDocs: " + uri);
|
||||||
return 0;
|
return 0;
|
||||||
@@ -98,6 +273,7 @@ public final class Eip4Cli {
|
|||||||
private int runAiAutoDevelop(String[] args, PrintStream out, PrintStream err)
|
private int runAiAutoDevelop(String[] args, PrintStream out, PrintStream err)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
Options options = Options.parse(args, 2);
|
Options options = Options.parse(args, 2);
|
||||||
|
ensureCrossEnvConfirmed(options);
|
||||||
ObjectNode request = buildAutoDevelopRequest(options);
|
ObjectNode request = buildAutoDevelopRequest(options);
|
||||||
String baseUrl = baseUrl(options);
|
String baseUrl = baseUrl(options);
|
||||||
Eip4HttpResponse response = httpClient.send(
|
Eip4HttpResponse response = httpClient.send(
|
||||||
@@ -110,6 +286,7 @@ public final class Eip4Cli {
|
|||||||
private int runAiFeaturePackage(String[] args, PrintStream out, PrintStream err)
|
private int runAiFeaturePackage(String[] args, PrintStream out, PrintStream err)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
Options options = Options.parse(args, 2);
|
Options options = Options.parse(args, 2);
|
||||||
|
ensureCrossEnvConfirmed(options);
|
||||||
String taskId = requiredPart(options.single("task-id"), "task-id");
|
String taskId = requiredPart(options.single("task-id"), "task-id");
|
||||||
String changeSetId = requiredPart(options.single("change-set-id"), "change-set-id");
|
String changeSetId = requiredPart(options.single("change-set-id"), "change-set-id");
|
||||||
Eip4HttpResponse response = httpClient.send(
|
Eip4HttpResponse response = httpClient.send(
|
||||||
@@ -123,6 +300,7 @@ public final class Eip4Cli {
|
|||||||
private int runAiRevision(String[] args, PrintStream out, PrintStream err)
|
private int runAiRevision(String[] args, PrintStream out, PrintStream err)
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
Options options = Options.parse(args, 2);
|
Options options = Options.parse(args, 2);
|
||||||
|
ensureCrossEnvConfirmed(options);
|
||||||
String taskId = requiredPart(options.single("task-id"), "task-id");
|
String taskId = requiredPart(options.single("task-id"), "task-id");
|
||||||
String packageId = requiredPart(options.single("package-id"), "package-id");
|
String packageId = requiredPart(options.single("package-id"), "package-id");
|
||||||
ObjectNode request = objectMapper.createObjectNode();
|
ObjectNode request = objectMapper.createObjectNode();
|
||||||
@@ -167,7 +345,7 @@ public final class Eip4Cli {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ObjectNode buildAutoDevelopRequest(Options options) {
|
private ObjectNode buildAutoDevelopRequest(Options options) throws IOException {
|
||||||
ObjectNode root = objectMapper.createObjectNode();
|
ObjectNode root = objectMapper.createObjectNode();
|
||||||
String baseUrl = baseUrl(options);
|
String baseUrl = baseUrl(options);
|
||||||
root.put("baseUrl", baseUrl);
|
root.put("baseUrl", baseUrl);
|
||||||
@@ -220,18 +398,42 @@ public final class Eip4Cli {
|
|||||||
node.put(jsonName, requiredPart(options.single(optionName), optionName));
|
node.put(jsonName, requiredPart(options.single(optionName), optionName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String baseUrl(Options options) {
|
private String baseUrl(Options options) throws IOException {
|
||||||
String value = options.single("base-url");
|
return target(options).baseUrl();
|
||||||
if (value == null || value.isBlank()) {
|
|
||||||
value = System.getenv("EIP4_BASE_URL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CliTarget target(Options options) throws IOException {
|
||||||
|
String explicitBaseUrl = options.single("base-url");
|
||||||
|
if (explicitBaseUrl != null && !explicitBaseUrl.isBlank()) {
|
||||||
|
return new CliTarget("", Eip4EnvStore.normalizeBaseUrl(explicitBaseUrl));
|
||||||
|
}
|
||||||
|
String envName = options.single("env");
|
||||||
|
if (envName != null && !envName.isBlank()) {
|
||||||
|
Eip4EnvStore.EnvConfig env = envStore.findEnv(envName)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("EIP4 env not found: " + envName));
|
||||||
|
return new CliTarget(env.name(), env.baseUrl());
|
||||||
|
}
|
||||||
|
Eip4EnvStore.EnvConfig current = envStore.currentEnv().orElse(null);
|
||||||
|
if (current != null) {
|
||||||
|
return new CliTarget(current.name(), current.baseUrl());
|
||||||
|
}
|
||||||
|
String value = System.getenv("EIP4_BASE_URL");
|
||||||
if (value == null || value.isBlank()) {
|
if (value == null || value.isBlank()) {
|
||||||
value = DEFAULT_BASE_URL;
|
value = DEFAULT_BASE_URL;
|
||||||
}
|
}
|
||||||
while (value.endsWith("/")) {
|
return new CliTarget("", Eip4EnvStore.normalizeBaseUrl(value));
|
||||||
value = value.substring(0, value.length() - 1);
|
}
|
||||||
|
|
||||||
|
private void ensureCrossEnvConfirmed(Options options) throws IOException {
|
||||||
|
String envName = options.single("env");
|
||||||
|
if (envName == null || envName.isBlank() || options.has("yes")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String current = envStore.currentEnvName();
|
||||||
|
if (!current.isBlank() && !current.equals(envName.trim())) {
|
||||||
|
throw new IllegalArgumentException("Refusing to target env `" + envName
|
||||||
|
+ "` while current env is `" + current + "`. Re-run with --yes to confirm.");
|
||||||
}
|
}
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private URI endpoint(String baseUrl, String path) {
|
private URI endpoint(String baseUrl, String path) {
|
||||||
@@ -265,6 +467,43 @@ public final class Eip4Cli {
|
|||||||
return value.isMissingNode() || value.isNull() ? "" : value.asText();
|
return value.isMissingNode() || value.isNull() ? "" : value.asText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean hasTextArrayItems(JsonNode node) {
|
||||||
|
return node.isArray() && node.size() > 0 && node.elements().hasNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean containsPlaceholder(JsonNode node) {
|
||||||
|
if (!node.isArray()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (JsonNode item : node) {
|
||||||
|
if (item.asText("").contains("${")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasRunEvidence(JsonNode runEvidence, String runType, String status) {
|
||||||
|
if (!runEvidence.isArray()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (JsonNode run : runEvidence) {
|
||||||
|
if (runType.equals(run.path("runType").asText()) && status.equals(run.path("status").asText())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String packageId(JsonNode root, JsonNode deploymentPackage) {
|
||||||
|
String id = text(root, "id");
|
||||||
|
if (!id.isBlank()) {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
String manifestId = deploymentPackage.path("manifest").path("packageId").asText("");
|
||||||
|
return manifestId == null ? "" : manifestId;
|
||||||
|
}
|
||||||
|
|
||||||
private int parseInt(String value, String name) {
|
private int parseInt(String value, String name) {
|
||||||
try {
|
try {
|
||||||
return Integer.parseInt(value);
|
return Integer.parseInt(value);
|
||||||
@@ -295,18 +534,35 @@ public final class Eip4Cli {
|
|||||||
EIP4 CLI
|
EIP4 CLI
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
eip4 env status [--base-url URL]
|
eip4 env add --name NAME --base-url URL [--kind local|http] [--use]
|
||||||
|
eip4 env list [--json-output]
|
||||||
|
eip4 env use --name NAME
|
||||||
|
eip4 env current
|
||||||
|
eip4 env status [--env NAME|--base-url URL|--all]
|
||||||
eip4 ai auto-develop --objective TEXT --feature-name NAME --table-name TABLE --entity-name NAME --template-id ID --menu-name NAME --field column:label:type[:length][:required]
|
eip4 ai auto-develop --objective TEXT --feature-name NAME --table-name TABLE --entity-name NAME --template-id ID --menu-name NAME --field column:label:type[:length][:required]
|
||||||
|
eip4 release verify --package-file FILE
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
EIP4_BASE_URL defaults the target service URL when --base-url is omitted.
|
Configured envs are stored in ~/.eip4/eip4-cli.json by default.
|
||||||
|
EIP4_CLI_HOME overrides the CLI home directory.
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printReleaseHelp(PrintStream out) {
|
||||||
|
out.println("""
|
||||||
|
Usage:
|
||||||
|
eip4 release verify --package-file FILE [--json-output]
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printEnvHelp(PrintStream out) {
|
private void printEnvHelp(PrintStream out) {
|
||||||
out.println("""
|
out.println("""
|
||||||
Usage:
|
Usage:
|
||||||
eip4 env status [--base-url URL]
|
eip4 env add --name NAME --base-url URL [--kind local|http] [--use]
|
||||||
|
eip4 env list [--json-output]
|
||||||
|
eip4 env use --name NAME
|
||||||
|
eip4 env current
|
||||||
|
eip4 env status [--env NAME|--base-url URL|--all]
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,15 +591,22 @@ public final class Eip4Cli {
|
|||||||
--package-id ID
|
--package-id ID
|
||||||
|
|
||||||
Optional:
|
Optional:
|
||||||
|
--env NAME
|
||||||
--base-url URL
|
--base-url URL
|
||||||
--max-repair-attempts N
|
--max-repair-attempts N
|
||||||
--no-deployment-package
|
--no-deployment-package
|
||||||
|
--yes
|
||||||
--output FILE
|
--output FILE
|
||||||
""");
|
""");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record CliTarget(String envName, String baseUrl) {
|
||||||
|
}
|
||||||
|
|
||||||
private static final class Options {
|
private static final class Options {
|
||||||
private final Map<String, List<String>> values = new LinkedHashMap<>();
|
private final Map<String, List<String>> values = new LinkedHashMap<>();
|
||||||
|
private static final List<String> BOOLEAN_OPTIONS = List.of(
|
||||||
|
"all", "json-output", "no-deployment-package", "use", "yes");
|
||||||
|
|
||||||
static Options parse(String[] args, int from) {
|
static Options parse(String[] args, int from) {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
@@ -356,7 +619,7 @@ public final class Eip4Cli {
|
|||||||
if (name.isBlank()) {
|
if (name.isBlank()) {
|
||||||
throw new IllegalArgumentException("Invalid option: " + arg);
|
throw new IllegalArgumentException("Invalid option: " + arg);
|
||||||
}
|
}
|
||||||
if ("no-deployment-package".equals(name)) {
|
if (BOOLEAN_OPTIONS.contains(name)) {
|
||||||
options.add(name, "true");
|
options.add(name, "true");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package com.eip4.platform.cli;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
final class Eip4EnvStore {
|
||||||
|
|
||||||
|
private static final int SCHEMA_VERSION = 1;
|
||||||
|
|
||||||
|
private final Path configPath;
|
||||||
|
private final ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
Eip4EnvStore(Path configPath, ObjectMapper objectMapper) {
|
||||||
|
this.configPath = configPath;
|
||||||
|
this.objectMapper = objectMapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Eip4EnvStore defaultStore(ObjectMapper objectMapper) {
|
||||||
|
String cliHome = System.getenv("EIP4_CLI_HOME");
|
||||||
|
Path home = cliHome == null || cliHome.isBlank()
|
||||||
|
? Path.of(System.getProperty("user.home"), ".eip4")
|
||||||
|
: Path.of(cliHome);
|
||||||
|
return new Eip4EnvStore(home.resolve("eip4-cli.json"), objectMapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
Config load() throws IOException {
|
||||||
|
if (!Files.exists(configPath)) {
|
||||||
|
return new Config(SCHEMA_VERSION, "", new LinkedHashMap<>());
|
||||||
|
}
|
||||||
|
String json = Files.readString(configPath, StandardCharsets.UTF_8);
|
||||||
|
if (json.isBlank()) {
|
||||||
|
return new Config(SCHEMA_VERSION, "", new LinkedHashMap<>());
|
||||||
|
}
|
||||||
|
Config config = objectMapper.readValue(json, Config.class);
|
||||||
|
return normalize(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveEnv(EnvConfig env, boolean use) throws IOException {
|
||||||
|
Config config = load();
|
||||||
|
Map<String, EnvConfig> envs = new LinkedHashMap<>(config.envs());
|
||||||
|
envs.put(env.name(), env);
|
||||||
|
String current = use || config.currentEnv().isBlank() ? env.name() : config.currentEnv();
|
||||||
|
save(new Config(SCHEMA_VERSION, current, envs));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<EnvConfig> listEnvs() throws IOException {
|
||||||
|
return List.copyOf(load().envs().values());
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<EnvConfig> findEnv(String name) throws IOException {
|
||||||
|
if (name == null || name.isBlank()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(load().envs().get(name.trim()));
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<EnvConfig> currentEnv() throws IOException {
|
||||||
|
Config config = load();
|
||||||
|
if (config.currentEnv().isBlank()) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(config.envs().get(config.currentEnv()));
|
||||||
|
}
|
||||||
|
|
||||||
|
String currentEnvName() throws IOException {
|
||||||
|
return load().currentEnv();
|
||||||
|
}
|
||||||
|
|
||||||
|
EnvConfig useEnv(String name) throws IOException {
|
||||||
|
String requested = name == null ? "" : name.trim();
|
||||||
|
Config config = load();
|
||||||
|
EnvConfig env = config.envs().get(requested);
|
||||||
|
if (env == null) {
|
||||||
|
throw new IllegalArgumentException("EIP4 env not found: " + requested);
|
||||||
|
}
|
||||||
|
save(new Config(SCHEMA_VERSION, requested, new LinkedHashMap<>(config.envs())));
|
||||||
|
return env;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void save(Config config) throws IOException {
|
||||||
|
if (configPath.getParent() != null) {
|
||||||
|
Files.createDirectories(configPath.getParent());
|
||||||
|
}
|
||||||
|
String json = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(normalize(config));
|
||||||
|
Files.writeString(configPath, json + System.lineSeparator(), StandardCharsets.UTF_8);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Config normalize(Config config) {
|
||||||
|
Map<String, EnvConfig> envs = new LinkedHashMap<>();
|
||||||
|
if (config != null && config.envs() != null) {
|
||||||
|
for (EnvConfig env : config.envs().values()) {
|
||||||
|
if (env == null || env.name() == null || env.name().isBlank()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
envs.put(env.name(), normalize(env));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String current = config == null || config.currentEnv() == null ? "" : config.currentEnv().trim();
|
||||||
|
if (!current.isBlank() && !envs.containsKey(current)) {
|
||||||
|
current = "";
|
||||||
|
}
|
||||||
|
return new Config(SCHEMA_VERSION, current, envs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static EnvConfig normalize(EnvConfig env) {
|
||||||
|
String name = required(env.name(), "name");
|
||||||
|
String kind = env.kind() == null || env.kind().isBlank() ? "local" : env.kind().trim();
|
||||||
|
String baseUrl = normalizeBaseUrl(required(env.baseUrl(), "baseUrl"));
|
||||||
|
return new EnvConfig(name, kind, baseUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String normalizeBaseUrl(String value) {
|
||||||
|
String out = value == null ? "" : value.trim();
|
||||||
|
while (out.endsWith("/")) {
|
||||||
|
out = out.substring(0, out.length() - 1);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String required(String value, String name) {
|
||||||
|
if (value == null || value.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Missing required env " + name);
|
||||||
|
}
|
||||||
|
return value.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
record Config(int schemaVersion, String currentEnv, Map<String, EnvConfig> envs) {
|
||||||
|
}
|
||||||
|
|
||||||
|
record EnvConfig(String name, String kind, String baseUrl) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,6 +35,30 @@ class Eip4CliTest {
|
|||||||
assertTrue(result.out().contains("EIP4 env READY"));
|
assertTrue(result.out().contains("EIP4 env READY"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void envCommandsPersistAndUseCurrentEnv() {
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
||||||
|
Eip4EnvStore store = tempStore();
|
||||||
|
|
||||||
|
CliResult add = run(store, client, "env", "add",
|
||||||
|
"--name", "local",
|
||||||
|
"--base-url", "http://localhost:8084/",
|
||||||
|
"--kind", "local",
|
||||||
|
"--use");
|
||||||
|
CliResult current = run(store, client, "env", "current");
|
||||||
|
CliResult list = run(store, client, "env", "list");
|
||||||
|
CliResult status = run(store, client, "env", "status");
|
||||||
|
|
||||||
|
assertEquals(0, add.code());
|
||||||
|
assertEquals(0, current.code());
|
||||||
|
assertEquals(0, list.code());
|
||||||
|
assertEquals(0, status.code());
|
||||||
|
assertTrue(current.out().contains("currentEnv: local"));
|
||||||
|
assertTrue(list.out().contains("* local local http://localhost:8084"));
|
||||||
|
assertEquals(URI.create("http://localhost:8084/v3/api-docs"), client.uri);
|
||||||
|
assertTrue(status.out().contains("env: local"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void autoDevelopBuildsRequestAndWritesResponse() throws Exception {
|
void autoDevelopBuildsRequestAndWritesResponse() throws Exception {
|
||||||
String response = """
|
String response = """
|
||||||
@@ -79,6 +103,47 @@ class Eip4CliTest {
|
|||||||
assertTrue(result.out().contains("applyStatus: PASSED"));
|
assertTrue(result.out().contains("applyStatus: PASSED"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void autoDevelopCanUseConfiguredEnv() {
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, """
|
||||||
|
{"status":"READY_FOR_HUMAN_REVIEW","taskId":"task-1","changeSetId":"cs-1"}
|
||||||
|
"""));
|
||||||
|
Eip4EnvStore store = tempStore();
|
||||||
|
run(store, client, "env", "add", "--name", "dev", "--base-url", "http://localhost:8093", "--use");
|
||||||
|
|
||||||
|
CliResult result = run(store, client,
|
||||||
|
"ai", "auto-develop",
|
||||||
|
"--env", "dev",
|
||||||
|
"--objective", "新增客户等级维护",
|
||||||
|
"--feature-name", "客户等级维护",
|
||||||
|
"--table-name", "EIP4AI_CUSTOMER_LEVEL",
|
||||||
|
"--entity-name", "客户等级",
|
||||||
|
"--template-id", "eip4ai-customer-level",
|
||||||
|
"--menu-name", "客户等级维护",
|
||||||
|
"--field", "NAME:名称:string:100:true");
|
||||||
|
|
||||||
|
assertEquals(0, result.code());
|
||||||
|
assertEquals(URI.create("http://localhost:8093/api/ai/features/auto-develop"), client.uri);
|
||||||
|
assertEquals("http://localhost:8093", client.body.path("baseUrl").asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void explicitCrossEnvRequiresYes() {
|
||||||
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
||||||
|
Eip4EnvStore store = tempStore();
|
||||||
|
run(store, client, "env", "add", "--name", "local", "--base-url", "http://localhost:8084", "--use");
|
||||||
|
run(store, client, "env", "add", "--name", "dev", "--base-url", "http://localhost:8093");
|
||||||
|
|
||||||
|
CliResult result = run(store, client,
|
||||||
|
"ai", "feature-package",
|
||||||
|
"--env", "dev",
|
||||||
|
"--task-id", "ait-1",
|
||||||
|
"--change-set-id", "aics-1");
|
||||||
|
|
||||||
|
assertEquals(1, result.code());
|
||||||
|
assertTrue(result.err().contains("Refusing to target env `dev`"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void autoDevelopRequiresAtLeastOneField() {
|
void autoDevelopRequiresAtLeastOneField() {
|
||||||
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
CapturingClient client = new CapturingClient(new Eip4HttpResponse(200, "{}"));
|
||||||
@@ -143,10 +208,74 @@ class Eip4CliTest {
|
|||||||
assertTrue(result.out().contains("packageId: aipkg-1"));
|
assertTrue(result.out().contains("packageId: aipkg-1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void releaseVerifyPassesReadyFeaturePackage() throws Exception {
|
||||||
|
Path file = tempDir.resolve("package.json");
|
||||||
|
Files.writeString(file, """
|
||||||
|
{
|
||||||
|
"id": "aipkg-1",
|
||||||
|
"deploymentPackage": {
|
||||||
|
"taskId": "ait-1",
|
||||||
|
"changeSetId": "aics-1",
|
||||||
|
"status": "READY_FOR_HUMAN_REVIEW",
|
||||||
|
"requiresHumanApproval": true,
|
||||||
|
"sqlStatements": ["insert into sys_page_schema values ('x')"],
|
||||||
|
"rollbackSqlStatements": ["delete from sys_page_schema where id = 'x'"],
|
||||||
|
"warnings": [],
|
||||||
|
"runEvidence": [
|
||||||
|
{"runType": "LOCAL_APPLY", "status": "PASSED"},
|
||||||
|
{"runType": "SMOKE", "status": "PASSED"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
CliResult result = run(new CapturingClient(new Eip4HttpResponse(200, "{}")),
|
||||||
|
"release", "verify", "--package-file", file.toString());
|
||||||
|
|
||||||
|
assertEquals(0, result.code());
|
||||||
|
assertTrue(result.out().contains("Release package PASSED"));
|
||||||
|
assertTrue(result.out().contains("packageId: aipkg-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void releaseVerifyBlocksSqlPlaceholders() throws Exception {
|
||||||
|
Path file = tempDir.resolve("package-with-placeholder.json");
|
||||||
|
Files.writeString(file, """
|
||||||
|
{
|
||||||
|
"deploymentPackage": {
|
||||||
|
"taskId": "ait-1",
|
||||||
|
"changeSetId": "aics-1",
|
||||||
|
"status": "READY_FOR_HUMAN_REVIEW",
|
||||||
|
"requiresHumanApproval": true,
|
||||||
|
"manifest": {"packageId": "aipkg-2"},
|
||||||
|
"sqlStatements": ["insert into sys_menu(parent_id) values ('${parentMenuId}')"],
|
||||||
|
"rollbackSqlStatements": ["delete from sys_menu where id = 'x'"],
|
||||||
|
"warnings": ["菜单 parentId 待替换"],
|
||||||
|
"runEvidence": [
|
||||||
|
{"runType": "LOCAL_APPLY", "status": "PASSED"},
|
||||||
|
{"runType": "SMOKE", "status": "PASSED"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""", StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
CliResult result = run(new CapturingClient(new Eip4HttpResponse(200, "{}")),
|
||||||
|
"release", "verify", "--package-file", file.toString());
|
||||||
|
|
||||||
|
assertEquals(2, result.code());
|
||||||
|
assertTrue(result.err().contains("Release package FAILED"));
|
||||||
|
assertTrue(result.err().contains("占位符"));
|
||||||
|
}
|
||||||
|
|
||||||
private CliResult run(CapturingClient client, String... args) {
|
private CliResult run(CapturingClient client, String... args) {
|
||||||
|
return run(tempStore(), client, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
private CliResult run(Eip4EnvStore store, CapturingClient client, String... args) {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
ByteArrayOutputStream err = new ByteArrayOutputStream();
|
||||||
int code = new Eip4Cli(client).run(
|
int code = new Eip4Cli(client, store).run(
|
||||||
args,
|
args,
|
||||||
new PrintStream(out, true, StandardCharsets.UTF_8),
|
new PrintStream(out, true, StandardCharsets.UTF_8),
|
||||||
new PrintStream(err, true, StandardCharsets.UTF_8));
|
new PrintStream(err, true, StandardCharsets.UTF_8));
|
||||||
@@ -156,6 +285,10 @@ class Eip4CliTest {
|
|||||||
err.toString(StandardCharsets.UTF_8));
|
err.toString(StandardCharsets.UTF_8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Eip4EnvStore tempStore() {
|
||||||
|
return new Eip4EnvStore(tempDir.resolve("eip4-cli.json"), objectMapper);
|
||||||
|
}
|
||||||
|
|
||||||
private final class CapturingClient implements Eip4HttpClient {
|
private final class CapturingClient implements Eip4HttpClient {
|
||||||
private final Eip4HttpResponse response;
|
private final Eip4HttpResponse response;
|
||||||
private int calls;
|
private int calls;
|
||||||
|
|||||||
Reference in New Issue
Block a user