Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65a7280805 |
@@ -1,5 +0,0 @@
|
||||
---
|
||||
category: Added
|
||||
---
|
||||
|
||||
- **Sheet floating images** — supports creating or replacing a floating image directly from a local file with `create-float-image --file` and `update-float-image --file`, while retaining the existing `--src` workflow.
|
||||
@@ -54,8 +54,6 @@ The format is inspired by [Keep a Changelog](https://keepachangelog.com/) and th
|
||||
|
||||
- **Sheet revision changesets** — adds read-only commands for querying the current workbook revision and reviewing Agent-readable changes between revisions, with guidance for distinguishing revisions from saved history versions and safely selecting rollback targets.
|
||||
|
||||
- **Sheet floating images** — supports creating or replacing a floating image directly from a local file with `create-float-image --file` and `update-float-image --file`, while retaining the existing `--src` workflow.
|
||||
|
||||
### Changed
|
||||
|
||||
- **AiSearch and Contact shortcuts** (#1083) — adds strict people search and reviewed unified results; people results must use the live-reviewed `person` source, and exact mobile lookups normalize accepted formatting before calling the dedicated mobile interface. Agent/public discovery keeps `contact +list-roles`, `contact +list-roster-fields`, `contact +get-roster`, and incomplete Live routes unavailable rather than publishing ambiguous results, while the historical Contact CLI commands retain legacy MCP execution and real error propagation. The legacy role-list projection preserves the service's reviewed null placeholder without exposing that ambiguous row through Agent Result contracts.
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
class DingtalkWorkspaceCliBeta < Formula
|
||||
desc "Automate DingTalk workspace tasks from the terminal (beta channel)"
|
||||
homepage "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli"
|
||||
version "1.0.60-beta.2"
|
||||
version "1.0.60-beta.1"
|
||||
license "Apache-2.0"
|
||||
keg_only "it is the beta channel and conflicts with dingtalk-workspace-cli"
|
||||
|
||||
on_macos do
|
||||
if Hardware::CPU.arm?
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.2/dws-darwin-arm64.tar.gz"
|
||||
sha256 "e7776807f0664cbf0d0728cc236f2415c0981eb8d6557a897d2eeee708641b1d"
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.1/dws-darwin-arm64.tar.gz"
|
||||
sha256 "8ef11c79b5c86ec275dd82334232e7582f9e2ba99a66307d7681e42e8f53767b"
|
||||
else
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.2/dws-darwin-amd64.tar.gz"
|
||||
sha256 "3004474df3cfb529719348f02c9f2f39afa88f0fca469fe8303a9ebe0f3a0034"
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.1/dws-darwin-amd64.tar.gz"
|
||||
sha256 "67612f1dac735984b026c7f8a0dc057beec4cdd029f0a97798bf90aa923eb2d3"
|
||||
end
|
||||
end
|
||||
|
||||
on_linux do
|
||||
if Hardware::CPU.arm?
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.2/dws-linux-arm64.tar.gz"
|
||||
sha256 "6386885d10f149c8c555031dda4cf07bf34e1e9daad61d4cd948b92d3c7b7bad"
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.1/dws-linux-arm64.tar.gz"
|
||||
sha256 "67a8d4f4e0a7d22a9cc53cb91d8c97ecd1152665ce669f68560d86cec5987dd2"
|
||||
else
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.2/dws-linux-amd64.tar.gz"
|
||||
sha256 "5c94c2af269d2fe5a79a400d4fa3af267a86d6ab21b01a24ede1d29514a6eaef"
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.1/dws-linux-amd64.tar.gz"
|
||||
sha256 "a5fae548b495842779df4291cbcf06d8a2e5ddddf68a41cad1bab1e5c64a1d59"
|
||||
end
|
||||
end
|
||||
|
||||
resource "skills" do
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.2/dws-skills.zip"
|
||||
sha256 "c3bd917f1b44a978ba2a9fbe95c5d0910ccf75f870f1c9b0dc356262ab1080c5"
|
||||
url "https://github.com/DingTalk-Real-AI/dingtalk-workspace-cli/releases/download/v1.0.60-beta.1/dws-skills.zip"
|
||||
sha256 "9fe12683139a626d32a801dd44158a698f142b61339282e0fc24d4e3a5e97e87"
|
||||
end
|
||||
|
||||
def install
|
||||
|
||||
@@ -1,57 +1,7 @@
|
||||
{
|
||||
"generated_at": "2026-08-24T20:14:49.172788",
|
||||
"count": 437,
|
||||
"generated_at": "2026-08-24T12:22:05.108140",
|
||||
"count": 426,
|
||||
"results": [
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "agoal",
|
||||
"command": "+contract-fields",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、字段数组和每项稳定 id;本地 keyword 覆盖字段标识、编码、标题、分类和类型,支持已知非空与保证零命中。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "agoal",
|
||||
"command": "+obj-template-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、result 数组、稳定模板 ID 及 page/pageSize/totalCount;不虚构 cursor。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "agoal",
|
||||
"command": "+report-statistics-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、content 数组和每项稳定 templateId;关键词同时支持已知非空与合法零命中。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "agoal",
|
||||
"command": "+report-submit-detail",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、嵌套稳定用户身份及 page/pageSize/totalCount;下游忽略 keyword,因此做有界全量遍历、本地过滤、停滞/重复/总数变化失败与人员字段最小投影。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "agoal",
|
||||
"command": "+user-rules",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、content 对象、rules 数组和稳定 ruleId;本地精确 ruleId 选择器支持已知非空与保证零命中。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "aisearch",
|
||||
@@ -2523,254 +2473,137 @@
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+create",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "创建后提取稳定 unifiedAppId,并以同一 ID 读回名称及请求字段;只有精确核验通过才返回成功。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+credentials-get",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格要求 success、稳定 unifiedAppId、非空客户端标识和非空 secret;Result 将密钥路径声明为敏感。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+delete",
|
||||
"risk": "high-risk-write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "删除前读回稳定 appKey,删除后按该选择器有界遍历全部页并证明同一 unifiedAppId 不再存在。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+disable",
|
||||
"risk": "high-risk-write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "停用后按同一 unifiedAppId 读回并要求 appStatus=disabled。",
|
||||
"availability": "available"
|
||||
"risk": "write",
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+enable",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "启用后按同一 unifiedAppId 读回并要求 appStatus=normal。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+event-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、事件数组、每项稳定 eventCode 与游标终止证据;明确返回可用事件目录及订阅状态,并拒绝坏元素与伪空结果。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+event-subscribe",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空值与重复 eventCode,写后有界遍历订阅列表并逐项精确读回。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+get",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空响应、缺失 success 和空业务对象,并要求读回 unifiedAppId 与请求精确一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、应用数组、稳定 unifiedAppId 与游标终止证据;投影当前页并保留可续翻 meta.pagination。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+member-add",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空值和重复 userId,校验写终态后按稳定 userId 逐项精确读回,并要求 memberType 与请求角色一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+member-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、成员数组和每项稳定 userId;新增本地精确 userId 选择器以证明已知非空与保证零命中。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+member-remove",
|
||||
"risk": "high-risk-write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空值和重复 userId,校验写终态后读取完整成员数组,并逐项证明目标稳定 userId 已不存在。",
|
||||
"availability": "available"
|
||||
"risk": "write",
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+permission-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、权限数组、每项稳定 scopeValue 与游标终止证据,拒绝坏元素和伪空结果。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+robot-config",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空配置,写后按同一 unifiedAppId 读取机器人对象并精确比较全部请求标量字段。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+robot-disable",
|
||||
"risk": "high-risk-write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "要求写终态成功并读回 robotStatus=UNCONFIGURED;不虚构保留配置或可直接恢复语义。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+robot-enable",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "要求写终态成功并按同一 unifiedAppId 读回 robotStatus=ONLINE。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+robot-get",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证非空机器人配置对象,并要求读回 unifiedAppId 与请求精确一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+update",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "要求至少一个更新字段,写入后按同一 unifiedAppId 精确读回所有请求字段。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+version-check-approval",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "只执行 precheckOnly,严格绑定应用与版本身份,并保留可执行后续动作的 pending 结果。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"service": "devapp",
|
||||
"command": "+version-create",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "创建回执必须含稳定 versionId,随后以 unifiedAppId/versionId 双身份读取详情并核验请求字段;live fixture 通过删除临时父应用清理。",
|
||||
"availability": "available"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+version-get",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证非空版本对象,并要求 unifiedAppId 和 versionId 同时与请求精确一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+version-list",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证 success、版本数组、每项稳定 versionId 与游标终止证据。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+version-status",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证非空发布状态对象,并要求 unifiedAppId 和 versionId 同时与请求精确一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "write",
|
||||
"service": "devapp",
|
||||
"command": "+webapp-config",
|
||||
"risk": "write",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "拒绝空更新,写入后按同一 unifiedAppId 读取网页配置并精确比较全部请求字段。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
"suite": "read",
|
||||
"service": "devapp",
|
||||
"command": "+webapp-get",
|
||||
"risk": "read",
|
||||
"status": "reviewed_available",
|
||||
"disposition": "semantic_adapter",
|
||||
"semantic_delta": "严格验证非空网页配置对象,并要求读回 unifiedAppId 与请求精确一致。",
|
||||
"availability": "available"
|
||||
"status": "real-ok"
|
||||
},
|
||||
{
|
||||
"suite": "semantic",
|
||||
|
||||
@@ -148,7 +148,7 @@ var paramAliasCompleteCommands = map[string][]string{
|
||||
"contact +resolve-dept": {"contact", "+resolve-dept", "--name", "Fixture Dept"},
|
||||
"contact +search-user": {"contact", "+search-user", "--query", "Fixture User"},
|
||||
"contact dept list-children": {"contact", "dept", "list-children", "--dept", "1"},
|
||||
"contact user profile get": {"contact", "user", "profile", "get", "--staff-id", "user-1", "--fields", "name,userId"},
|
||||
"contact user profile get": {"contact", "user", "profile", "get", "--staff-id", "user-1"},
|
||||
"dev app get": {"dev", "app", "get", "--unified-app-id", "app-1"},
|
||||
"devdoc article search": {"devdoc", "article", "search", "--query", "fixture", "--page", "2", "--size", "7"},
|
||||
"ding +receiver-status": {"ding", "+receiver-status", "--ding-id", "ding-1"},
|
||||
@@ -237,106 +237,52 @@ var paramAliasCompleteCommands = map[string][]string{
|
||||
// param_concepts.json: inactive candidate templates are ignored, while every
|
||||
// command becomes mandatory as soon as one of its reviewed aliases is active.
|
||||
var paramAliasCandidateCompleteCommands = map[string][]string{
|
||||
"aisearch": {"aisearch", "--query", "Fixture User", "--dimension", "name"},
|
||||
"aisearch +search-person": {"aisearch", "+search-person", "--query", "Fixture User", "--dimensions", "name"},
|
||||
"aisearch behavior": {"aisearch", "behavior", "--queries", "fixture", "--types", "im", "--behavior-type", "send", "--chat-scope", "Fixture Group", "--direction", "我->Fixture User", "--time-range", "本周"},
|
||||
"aisearch enterprise": {"aisearch", "enterprise", "--queries", "fixture", "--types", "document", "--time-range", "本周"},
|
||||
"aisearch person": {"aisearch", "person", "--query", "Fixture User", "--dimension", "name"},
|
||||
"contact +by-mobile": {"contact", "+by-mobile", "--mobile", "13800138000"},
|
||||
"contact +list-dept-members": {"contact", "+list-dept-members", "--depts", "1,2"},
|
||||
"contact +list-followings": {"contact", "+list-followings", "--open-id", "open-fixture-1"},
|
||||
"contact +list-role-members": {"contact", "+list-role-members", "--id", "12345"},
|
||||
"contact +lookup": {"contact", "+lookup", "--name", "Fixture User"},
|
||||
"contact +org": {"contact", "+org", "--name", "Fixture User"},
|
||||
"contact +search-mobile": {"contact", "+search-mobile", "--mobile", "13800138000"},
|
||||
"contact +team": {"contact", "+team", "--name", "Fixture User"},
|
||||
"contact account create": {"contact", "account", "create", "--login-id", "fixture-login", "--org-user-name", "Fixture User", "--dept-ids", "1,2"},
|
||||
"contact account update": {"contact", "account", "update", "--user-id", "user-1", "--org-user-name", "Fixture User", "--depts", `[{"deptId":1}]`, "--avatar-file-id", "file-1", "--yes"},
|
||||
"contact dept create": {"contact", "dept", "create", "--name", "Fixture Dept", "--parent", "1", "--create-dept-group", "--yes"},
|
||||
"contact dept get-info": {"contact", "dept", "get-info", "--dept", "1"},
|
||||
"contact dept list-members": {"contact", "dept", "list-members", "--depts", "1,2"},
|
||||
"contact dept search": {"contact", "dept", "search", "--query", "Fixture Dept"},
|
||||
"contact dept update": {"contact", "dept", "update", "--dept", "2", "--name", "Fixture Dept", "--parent", "1", "--yes"},
|
||||
"contact label get": {"contact", "label", "get", "--names", "Fixture Role"},
|
||||
"contact org create": {"contact", "org", "create", "--org-name", "Fixture Org", "--creator-username", "Fixture Creator"},
|
||||
"contact user dismission search": {"contact", "user", "dismission", "search", "--depts", "1,2", "--start", "2026-03-01", "--end", "2026-03-31", "--page", "2", "--limit", "7"},
|
||||
"contact user get": {"contact", "user", "get", "--ids", "user-1,user-2"},
|
||||
"contact user invite": {"contact", "user", "invite", "--org-user-mobile", "13800138000", "--org-user-name", "Fixture User", "--depts", `[{"deptId":1}]`},
|
||||
"contact user search": {"contact", "user", "search", "--query", "Fixture User"},
|
||||
"contact user search-mobile": {"contact", "user", "search-mobile", "--mobile", "13800138000"},
|
||||
"contact user update": {"contact", "user", "update", "--user-id", "user-1", "--org-user-name", "Fixture User", "--depts", `[{"deptId":1}]`, "--yes"},
|
||||
"contact user update-ownness": {"contact", "user", "update-ownness", "--user-id", "user-1", "--ownness-text", "Fixture Status", "--yes"},
|
||||
"contact user update-self": {"contact", "user", "update-self", "--avatar-file-id", "file-1", "--nick", "Fixture Nick", "--yes"},
|
||||
"devdoc +search-docs": {"devdoc", "+search-docs", "--query", "fixture", "--page", "2", "--size", "7"},
|
||||
"hrbrain +get-pool": {"hrbrain", "+get-pool", "--pool-code", "pool-1"},
|
||||
"hrbrain +list-pool-employees": {"hrbrain", "+list-pool-employees", "--pool-code", "pool-1", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain +list-pools": {"hrbrain", "+list-pools", "--keyword", "fixture", "--labels", "label-a,label-b", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain +profile-career": {"hrbrain", "+profile-career", "--work-no", "work-1"},
|
||||
"hrbrain +profile-labels": {"hrbrain", "+profile-labels", "--staff-ids", "work-1,work-2", "--all-label"},
|
||||
"hrbrain +profile-metadata": {"hrbrain", "+profile-metadata", "--work-no", "work-1"},
|
||||
"hrbrain +profile-performance": {"hrbrain", "+profile-performance", "--work-no", "work-1"},
|
||||
"hrbrain +query-profile": {"hrbrain", "+query-profile", "--work-no", "work-1", "--data-queries", `[{"modelCode":"basic","fields":["name"]}]`},
|
||||
"hrbrain +search-employees": {"hrbrain", "+search-employees", "--keyword", "fixture", "--dept-name", "Fixture Dept", "--position-name", "Engineer", "--job-level", "P7", "--pool-code", "pool-1", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain +search-employees-structured": {"hrbrain", "+search-employees-structured", "--origin-json", `{"rules":[],"combinator":"and"}`, "--fields", `[{"label":"name","value":"name"}]`, "--order-by", "name", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain profile career": {"hrbrain", "profile", "career", "--work-no", "work-1"},
|
||||
"hrbrain profile labels": {"hrbrain", "profile", "labels", "--staff-ids", "work-1,work-2", "--all-label"},
|
||||
"hrbrain profile metadata": {"hrbrain", "profile", "metadata", "--work-no", "work-1"},
|
||||
"hrbrain profile performance": {"hrbrain", "profile", "performance", "--work-no", "work-1"},
|
||||
"hrbrain profile query": {"hrbrain", "profile", "query", "--work-no", "work-1", "--data-queries", `[{"modelCode":"basic","fields":["name"]}]`},
|
||||
"hrbrain search employees": {"hrbrain", "search", "employees", "--keyword", "fixture", "--dept-name", "Fixture Dept", "--position-name", "Engineer", "--job-level", "P7", "--pool-code", "pool-1", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain search employees-structured": {"hrbrain", "search", "employees-structured", "--origin-json", `{"rules":[],"combinator":"and"}`, "--fields", `[{"label":"name","value":"name"}]`, "--order-by", "name", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain talent-pool detail": {"hrbrain", "talent-pool", "detail", "--pool-code", "pool-1"},
|
||||
"hrbrain talent-pool employees": {"hrbrain", "talent-pool", "employees", "--pool-code", "pool-1", "--page", "2", "--page-size", "7"},
|
||||
"hrbrain talent-pool list": {"hrbrain", "talent-pool", "list", "--keyword", "fixture", "--labels", "label-a,label-b", "--page", "2", "--page-size", "7"},
|
||||
"pat +browser-policy": {"pat", "+browser-policy", "--enabled=false", "--agent-code", "fixture-agent", "--dry-run"},
|
||||
"pat browser-policy": {"pat", "browser-policy", "--enabled=false", "--agentCode", "fixture-agent"},
|
||||
"pat chmod": {"pat", "chmod", "--product", "calendar", "--products", "aitable", "--domain", "chat", "--domains", "mail", "--grant-type", "session", "--session-id", "session-1", "--recommend", "--agentCode", "fixture-agent", "--dry-run"},
|
||||
"attendance +check-record": {"attendance", "+check-record", "--users", "user-1,user-2", "--start", "2026-03-10 00:00:00", "--end", "2026-03-10 23:59:59"},
|
||||
"attendance +get-adjustment-rule": {"attendance", "+get-adjustment-rule", "--adjustment-id", "adjustment-1"},
|
||||
"attendance +get-approve-template": {"attendance", "+get-approve-template", "--type", "leave"},
|
||||
"attendance +get-checkin-record": {"attendance", "+get-checkin-record", "--operator-corp-id", "corp-1", "--operator-staff-id", "staff-operator", "--staff-ids", "staff-1,staff-2", "--start", "2026-03-10 00:00:00", "--end", "2026-03-10 23:59:59"},
|
||||
"attendance +get-leave-records": {"attendance", "+get-leave-records", "--user", "user-1", "--start", "2026-03-01", "--end", "2026-03-31", "--leave-code", "annual_leave"},
|
||||
"attendance +get-overtime-rule": {"attendance", "+get-overtime-rule", "--overtime-id", "overtime-1"},
|
||||
"attendance +get-schedule": {"attendance", "+get-schedule", "--users", "user-1,user-2", "--start", "2026-03-10", "--end", "2026-03-11"},
|
||||
"attendance +get-self-setting": {"attendance", "+get-self-setting", "--user", "user-1", "--setting-scene", "checkRemind"},
|
||||
"attendance +get-summary": {"attendance", "+get-summary", "--user", "user-1", "--date", "2026-03-10", "--stats-type", "week"},
|
||||
"attendance +list-approve": {"attendance", "+list-approve", "--users", "user-1,user-2", "--types", "leave", "--start", "2026-03-01", "--end", "2026-03-31"},
|
||||
"attendance +query-report-data": {"attendance", "+query-report-data", "--users", "user-1,user-2", "--columns", "attendance_days,late_count", "--start", "2026-03-01", "--end", "2026-03-31"},
|
||||
"attendance +search-adjustment-rule": {"attendance", "+search-adjustment-rule", "--query", "fixture", "--page", "2", "--limit", "7"},
|
||||
"attendance +search-class": {"attendance", "+search-class", "--filter-type", "name", "--query", "fixture"},
|
||||
"attendance +search-group": {"attendance", "+search-group", "--type", "FIXED"},
|
||||
"attendance +search-overtime-rule": {"attendance", "+search-overtime-rule", "--query", "fixture", "--page", "2", "--limit", "7"},
|
||||
"ding +list": {"ding", "+list", "--cursor", "0", "--type", "ALL"},
|
||||
"ding +recall-personal": {"ding", "+recall-personal", "--id", "ding-1", "--yes"},
|
||||
"ding +send-personal": {"ding", "+send-personal", "--users", appFixtureCurrentDOpenID, "--content", "fixture", "--yes"},
|
||||
"mail +contact-list": {"mail", "+contact-list", "--email", "fixture@example.com", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +folder-list": {"mail", "+folder-list", "--email", "fixture@example.com", "--folder", "folder-1"},
|
||||
"mail +message": {"mail", "+message", "--email", "fixture@example.com", "--id", "message-1"},
|
||||
"mail +messages": {"mail", "+messages", "--email", "fixture@example.com", "--ids", "message-1,message-2"},
|
||||
"mail +recent-mail": {"mail", "+recent-mail", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +search-mail": {"mail", "+search-mail", "--query", "fixture", "--size", "7", "--cursor", "cursor-1"},
|
||||
"mail +template-list": {"mail", "+template-list", "--email", "fixture@example.com", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +thread": {"mail", "+thread", "--email", "fixture@example.com", "--id", "thread-1"},
|
||||
"mail +thread-list": {"mail", "+thread-list", "--email", "fixture@example.com", "--folder", "folder-1", "--cursor", "cursor-1"},
|
||||
"mail +triage": {"mail", "+triage", "--query", "fixture", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +unread-mail": {"mail", "+unread-mail", "--size", "7", "--cursor", "cursor-1"},
|
||||
"mail +user-search": {"mail", "+user-search", "--keyword", "fixture", "--cursor", "cursor-1"},
|
||||
"markdown create": {"markdown", "create", "--content", "# Fixture", "--name", "fixture.md", "--space-id", "space-1"},
|
||||
"markdown diff": {"markdown", "diff", "--node", "node-1", "--version", "1", "--version2", "2", "--context", "3"},
|
||||
"markdown fetch": {"markdown", "fetch", "--node", "node-1", "--space-id", "space-1", "--output", "/tmp/dws-markdown-fixture.md"},
|
||||
"markdown overwrite": {"markdown", "overwrite", "--node", "node-1", "--content", "# Fixture", "--name", "fixture.md", "--space-id", "space-1", "--yes"},
|
||||
"markdown patch": {"markdown", "patch", "--node", "node-1", "--pattern", "old", "--content", "new", "--regex", "--space-id", "space-1", "--yes"},
|
||||
"oa +list-cc": {"oa", "+list-cc", "--page", "2"},
|
||||
"oa +list-executed": {"oa", "+list-executed", "--limit", "7", "--page", "2"},
|
||||
"oa +list-forms": {"oa", "+list-forms", "--cursor", "2"},
|
||||
"oa +list-pending": {"oa", "+list-pending", "--start", "1773072000000", "--end", "1773158399000", "--page", "2"},
|
||||
"oa +list-submitted": {"oa", "+list-submitted", "--page", "2"},
|
||||
"oa +my-initiated": {"oa", "+my-initiated", "--page", "2"},
|
||||
"report +outbox-list": {"report", "+outbox-list", "--size", "7"},
|
||||
"report +report-latest": {"report", "+report-latest", "--keyword", "Fixture", "--start", "2026-03-01T00:00:00+08:00", "--end", "2026-03-10T00:00:00+08:00"},
|
||||
"report +template-search": {"report", "+template-search", "--query", "fixture"},
|
||||
"sheet +list-sheets": {"sheet", "+list-sheets", "--node", "node-1"},
|
||||
"sheet +read": {"sheet", "+read", "--node", "node-1", "--sheet-id", "Sheet1"},
|
||||
"attendance +check-record": {"attendance", "+check-record", "--users", "user-1,user-2", "--start", "2026-03-10 00:00:00", "--end", "2026-03-10 23:59:59"},
|
||||
"attendance +get-adjustment-rule": {"attendance", "+get-adjustment-rule", "--adjustment-id", "adjustment-1"},
|
||||
"attendance +get-approve-template": {"attendance", "+get-approve-template", "--type", "leave"},
|
||||
"attendance +get-checkin-record": {"attendance", "+get-checkin-record", "--operator-corp-id", "corp-1", "--operator-staff-id", "staff-operator", "--staff-ids", "staff-1,staff-2", "--start", "2026-03-10 00:00:00", "--end", "2026-03-10 23:59:59"},
|
||||
"attendance +get-leave-records": {"attendance", "+get-leave-records", "--user", "user-1", "--start", "2026-03-01", "--end", "2026-03-31", "--leave-code", "annual_leave"},
|
||||
"attendance +get-overtime-rule": {"attendance", "+get-overtime-rule", "--overtime-id", "overtime-1"},
|
||||
"attendance +get-schedule": {"attendance", "+get-schedule", "--users", "user-1,user-2", "--start", "2026-03-10", "--end", "2026-03-11"},
|
||||
"attendance +get-self-setting": {"attendance", "+get-self-setting", "--user", "user-1", "--setting-scene", "checkRemind"},
|
||||
"attendance +get-summary": {"attendance", "+get-summary", "--user", "user-1", "--date", "2026-03-10", "--stats-type", "week"},
|
||||
"attendance +list-approve": {"attendance", "+list-approve", "--users", "user-1,user-2", "--types", "leave", "--start", "2026-03-01", "--end", "2026-03-31"},
|
||||
"attendance +query-report-data": {"attendance", "+query-report-data", "--users", "user-1,user-2", "--columns", "attendance_days,late_count", "--start", "2026-03-01", "--end", "2026-03-31"},
|
||||
"attendance +search-adjustment-rule": {"attendance", "+search-adjustment-rule", "--query", "fixture", "--page", "2", "--limit", "7"},
|
||||
"attendance +search-class": {"attendance", "+search-class", "--filter-type", "name", "--query", "fixture"},
|
||||
"attendance +search-group": {"attendance", "+search-group", "--type", "FIXED"},
|
||||
"attendance +search-overtime-rule": {"attendance", "+search-overtime-rule", "--query", "fixture", "--page", "2", "--limit", "7"},
|
||||
"ding +list": {"ding", "+list", "--cursor", "0", "--type", "ALL"},
|
||||
"ding +recall-personal": {"ding", "+recall-personal", "--id", "ding-1", "--yes"},
|
||||
"ding +send-personal": {"ding", "+send-personal", "--users", appFixtureCurrentDOpenID, "--content", "fixture", "--yes"},
|
||||
"mail +contact-list": {"mail", "+contact-list", "--email", "fixture@example.com", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +folder-list": {"mail", "+folder-list", "--email", "fixture@example.com", "--folder", "folder-1"},
|
||||
"mail +message": {"mail", "+message", "--email", "fixture@example.com", "--id", "message-1"},
|
||||
"mail +messages": {"mail", "+messages", "--email", "fixture@example.com", "--ids", "message-1,message-2"},
|
||||
"mail +recent-mail": {"mail", "+recent-mail", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +search-mail": {"mail", "+search-mail", "--query", "fixture", "--size", "7", "--cursor", "cursor-1"},
|
||||
"mail +template-list": {"mail", "+template-list", "--email", "fixture@example.com", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +thread": {"mail", "+thread", "--email", "fixture@example.com", "--id", "thread-1"},
|
||||
"mail +thread-list": {"mail", "+thread-list", "--email", "fixture@example.com", "--folder", "folder-1", "--cursor", "cursor-1"},
|
||||
"mail +triage": {"mail", "+triage", "--query", "fixture", "--limit", "7", "--cursor", "cursor-1"},
|
||||
"mail +unread-mail": {"mail", "+unread-mail", "--size", "7", "--cursor", "cursor-1"},
|
||||
"mail +user-search": {"mail", "+user-search", "--keyword", "fixture", "--cursor", "cursor-1"},
|
||||
"markdown create": {"markdown", "create", "--content", "# Fixture", "--name", "fixture.md", "--space-id", "space-1"},
|
||||
"markdown diff": {"markdown", "diff", "--node", "node-1", "--version", "1", "--version2", "2", "--context", "3"},
|
||||
"markdown fetch": {"markdown", "fetch", "--node", "node-1", "--space-id", "space-1", "--output", "/tmp/dws-markdown-fixture.md"},
|
||||
"markdown overwrite": {"markdown", "overwrite", "--node", "node-1", "--content", "# Fixture", "--name", "fixture.md", "--space-id", "space-1", "--yes"},
|
||||
"markdown patch": {"markdown", "patch", "--node", "node-1", "--pattern", "old", "--content", "new", "--regex", "--space-id", "space-1", "--yes"},
|
||||
"oa +list-cc": {"oa", "+list-cc", "--page", "2"},
|
||||
"oa +list-executed": {"oa", "+list-executed", "--limit", "7", "--page", "2"},
|
||||
"oa +list-forms": {"oa", "+list-forms", "--cursor", "2"},
|
||||
"oa +list-pending": {"oa", "+list-pending", "--start", "1773072000000", "--end", "1773158399000", "--page", "2"},
|
||||
"oa +list-submitted": {"oa", "+list-submitted", "--page", "2"},
|
||||
"oa +my-initiated": {"oa", "+my-initiated", "--page", "2"},
|
||||
"report +outbox-list": {"report", "+outbox-list", "--size", "7"},
|
||||
"report +report-latest": {"report", "+report-latest", "--keyword", "Fixture", "--start", "2026-03-01T00:00:00+08:00", "--end", "2026-03-10T00:00:00+08:00"},
|
||||
"report +template-search": {"report", "+template-search", "--query", "fixture"},
|
||||
"sheet +list-sheets": {"sheet", "+list-sheets", "--node", "node-1"},
|
||||
"sheet +read": {"sheet", "+read", "--node", "node-1", "--sheet-id", "Sheet1"},
|
||||
|
||||
"minutes +detail": {"minutes", "+detail", "--ids", "u1,u2"},
|
||||
"minutes +latest": {"minutes", "+latest", "--keyword", "fixture"},
|
||||
@@ -1084,14 +1030,14 @@ func assertParamAliasCannotBypassConfirmation(t *testing.T, aliasArgs []string)
|
||||
}
|
||||
}
|
||||
|
||||
// TestCrossPlatformCoverageReviewedProductTemplatedParamAliasesCannotBypassConfirmation
|
||||
// TestCrossPlatformCoverageEightProductTemplatedParamAliasesCannotBypassConfirmation
|
||||
// exercises every distinct reviewed mutating complete-command template in the
|
||||
// reviewed product expansions. The fixture gate already proves every
|
||||
// eight-product Shortcut expansion. The fixture gate already proves every
|
||||
// alias resolves through PreParse; this gate removes the confirmation flag
|
||||
// from one active alias invocation per distinct template and requires the
|
||||
// runtime boundary to stop it before the first transport call. An explicit
|
||||
// --dry-run is a reviewed preview path and must not carry a bypass flag.
|
||||
func TestCrossPlatformCoverageReviewedProductTemplatedParamAliasesCannotBypassConfirmation(t *testing.T) {
|
||||
func TestCrossPlatformCoverageEightProductTemplatedParamAliasesCannotBypassConfirmation(t *testing.T) {
|
||||
concepts, err := cli.LoadParamConcepts()
|
||||
if err != nil {
|
||||
t.Fatalf("LoadParamConcepts() error = %v", err)
|
||||
@@ -1105,8 +1051,7 @@ func TestCrossPlatformCoverageReviewedProductTemplatedParamAliasesCannotBypassCo
|
||||
}
|
||||
product, _, _ := strings.Cut(fixture.Command, " ")
|
||||
switch product {
|
||||
case "attendance", "mail", "oa", "ding", "report", "sheet", "whiteboard", "markdown",
|
||||
"aisearch", "contact", "live", "devdoc", "hrbrain", "pat":
|
||||
case "attendance", "mail", "oa", "ding", "report", "sheet", "whiteboard", "markdown":
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -740,7 +740,6 @@ func (r *runtimeRunner) executeInvocation(ctx context.Context, endpoint string,
|
||||
"mcp_tool_error",
|
||||
"MCP tool returned a business error; check tool parameters and refer to skill documentation.",
|
||||
invocation.CanonicalProduct,
|
||||
invocation.Tool,
|
||||
diag,
|
||||
)
|
||||
logBusinessError(r.transport.FileLogger, serverFailureReason(mcpErr, "mcp_tool_error"), invocation, callResult.Content, diag)
|
||||
@@ -766,7 +765,6 @@ func (r *runtimeRunner) executeInvocation(ctx context.Context, endpoint string,
|
||||
"business_error",
|
||||
"The API returned a business-level error. Check required parameters and values.",
|
||||
invocation.CanonicalProduct,
|
||||
invocation.Tool,
|
||||
diag,
|
||||
)
|
||||
logBusinessError(r.transport.FileLogger, serverFailureReason(classifiedErr, "business_error"), invocation, callResult.Content, diag)
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSheetFloatImageLocalFileFinalSchema(t *testing.T) {
|
||||
payload := schemaContractPayloadForBoundCanonicals(t, NewRootCommand(),
|
||||
"sheet.create_float_image",
|
||||
"sheet.update_float_image",
|
||||
)
|
||||
|
||||
create := payload.Tools["sheet.create_float_image"]
|
||||
if create == nil {
|
||||
t.Fatal("missing sheet.create_float_image")
|
||||
}
|
||||
if create["interface_mode"] != "mcp" {
|
||||
t.Fatalf("create interface mode = %#v", create["interface_mode"])
|
||||
}
|
||||
createRef, _ := create["interface_ref"].(map[string]any)
|
||||
if createRef["product_id"] != "sheet" || createRef["rpc_name"] != "create_float_image" {
|
||||
t.Fatalf("create interface ref = %#v", createRef)
|
||||
}
|
||||
createDryRun, _ := create["dry_run"].(map[string]any)
|
||||
if createDryRun["preview_kind"] != "request" {
|
||||
t.Fatalf("create dry-run = %#v", createDryRun)
|
||||
}
|
||||
if remoteReads, exists := createDryRun["remote_reads"]; exists && remoteReads != false {
|
||||
t.Fatalf("create dry-run remote_reads = %#v", remoteReads)
|
||||
}
|
||||
createParameters, _ := create["parameters"].(map[string]any)
|
||||
file, _ := createParameters["file"].(map[string]any)
|
||||
src, _ := createParameters["src"].(map[string]any)
|
||||
if file["required"] != false || file["required_when"] != "exactly one of --file or --src must be provided" {
|
||||
t.Fatalf("create --file metadata = %#v", file)
|
||||
}
|
||||
if schemaContractString(file["property"]) != "" {
|
||||
t.Fatalf("create --file leaked an RPC property: %#v", file["property"])
|
||||
}
|
||||
if src["required"] != false || schemaContractString(src["required_when"]) != "" || src["property"] != "src" {
|
||||
t.Fatalf("create --src compatibility metadata = %#v", src)
|
||||
}
|
||||
assertSchemaContractConstraintGroup(t, create, "mutually_exclusive", []string{"file", "src"})
|
||||
assertSchemaContractConstraintGroup(t, create, "require_one_of", []string{"file", "src"})
|
||||
|
||||
update := payload.Tools["sheet.update_float_image"]
|
||||
if update == nil {
|
||||
t.Fatal("missing sheet.update_float_image")
|
||||
}
|
||||
updateDryRun, _ := update["dry_run"].(map[string]any)
|
||||
if update["interface_mode"] != "mcp" || updateDryRun["preview_kind"] != "request" {
|
||||
t.Fatalf("update interface/dry-run = %#v/%#v", update["interface_mode"], updateDryRun)
|
||||
}
|
||||
updateParameters, _ := update["parameters"].(map[string]any)
|
||||
updateFile, _ := updateParameters["file"].(map[string]any)
|
||||
if schemaContractString(updateFile["property"]) != "" {
|
||||
t.Fatalf("update --file leaked an RPC property: %#v", updateParameters["file"])
|
||||
}
|
||||
assertSchemaContractConstraintGroup(t, update, "mutually_exclusive", []string{"file", "src"})
|
||||
assertSchemaContractConstraintGroup(t, update, "require_one_of", []string{"file", "src", "range", "width", "height", "offset-x", "offset-y"})
|
||||
|
||||
root := NewRootCommand()
|
||||
for _, cliPath := range []string{"sheet create-float-image", "sheet update-float-image"} {
|
||||
command := exactCommandForTest(root, cliPath)
|
||||
if command == nil || command.Flags().Lookup("file") == nil {
|
||||
t.Fatalf("%s has no executable --file flag", cliPath)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,12 +16,12 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
publicShortcutCount = 436
|
||||
publicShortcutCount = 425
|
||||
// schemaPublishedShortcutCount counts every delivered *.shortcut_* tool,
|
||||
// including reviewed hidden compatibility and unavailable contracts.
|
||||
schemaPublishedShortcutCount = 493
|
||||
schemaPublishedShortcutCount = 482
|
||||
// publiclyDeliveredShortcutCount is the public-catalog subset of that surface.
|
||||
publiclyDeliveredShortcutCount = 436
|
||||
publiclyDeliveredShortcutCount = 425
|
||||
)
|
||||
|
||||
func TestDeliverySchemaCoversOrExactlyExcludesEveryPublicShortcutContract(t *testing.T) {
|
||||
|
||||
@@ -20,50 +20,18 @@ import (
|
||||
)
|
||||
|
||||
type serverFailureClass struct {
|
||||
message string
|
||||
reason string
|
||||
origin string
|
||||
stage string
|
||||
hint string
|
||||
actions []string
|
||||
operation string
|
||||
retryable *bool
|
||||
message string
|
||||
reason string
|
||||
origin string
|
||||
stage string
|
||||
hint string
|
||||
actions []string
|
||||
}
|
||||
|
||||
func classifyServerFailure(message, serverKey, tool string, diag apperrors.ServerDiagnostics) (serverFailureClass, bool) {
|
||||
func classifyServerFailure(message string, diag apperrors.ServerDiagnostics) (serverFailureClass, bool) {
|
||||
code := strings.ToUpper(strings.TrimSpace(diag.ServerErrorCode))
|
||||
detail := strings.ToLower(strings.TrimSpace(diag.TechnicalDetail))
|
||||
text := strings.ToLower(strings.TrimSpace(message))
|
||||
combined := text + " " + detail
|
||||
|
||||
if code == "999" &&
|
||||
(strings.Contains(combined, "nullpointerexception") || strings.Contains(combined, "system error")) {
|
||||
classified := serverFailureClass{
|
||||
message: message,
|
||||
reason: "upstream_internal_error",
|
||||
origin: "dingtalk_api",
|
||||
stage: "upstream_execution",
|
||||
hint: "上游服务发生内部异常;请保留 Trace ID 和 Server Code,确认操作结果后再决定是否重试。",
|
||||
actions: []string{
|
||||
"检查目标资源的当前状态,确认本次操作是否已经生效",
|
||||
"状态未确认前不要直接重试写操作",
|
||||
"持续失败时携带 Trace ID 和 Server Code 联系服务端排查",
|
||||
},
|
||||
}
|
||||
if strings.EqualFold(strings.TrimSpace(serverKey), "todo") &&
|
||||
strings.EqualFold(strings.TrimSpace(tool), "create_personal_todo") {
|
||||
retryable := false
|
||||
classified.operation = "todo/create_personal_todo"
|
||||
classified.retryable = &retryable
|
||||
classified.hint = "待办服务发生内部异常,创建结果未知;请先查询是否已创建相同待办,再决定是否重试。"
|
||||
classified.actions = []string{
|
||||
"查询近期由自己创建的待办,核对标题、执行人和截止时间",
|
||||
"确认没有创建成功后再重新提交",
|
||||
"持续失败时携带 Trace ID 和 Server Code 联系服务端排查",
|
||||
}
|
||||
}
|
||||
return classified, true
|
||||
}
|
||||
|
||||
if code == "NETWORK_ERROR" ||
|
||||
strings.Contains(detail, "statuscode.unavailable") ||
|
||||
@@ -106,7 +74,6 @@ func newServerFailureAPIError(
|
||||
fallbackReason string,
|
||||
fallbackHint string,
|
||||
serverKey string,
|
||||
tool string,
|
||||
diag apperrors.ServerDiagnostics,
|
||||
) error {
|
||||
opts := []apperrors.Option{
|
||||
@@ -117,7 +84,7 @@ func newServerFailureAPIError(
|
||||
apperrors.WithActions("运行 dws doctor 检查登录态、网络和本地环境;持续失败时保留 Trace ID 和 Server Code"),
|
||||
apperrors.WithServerDiag(diag),
|
||||
}
|
||||
if classified, ok := classifyServerFailure(message, serverKey, tool, diag); ok {
|
||||
if classified, ok := classifyServerFailure(message, diag); ok {
|
||||
message = classified.message
|
||||
opts = append(opts,
|
||||
apperrors.WithReason(classified.reason),
|
||||
@@ -126,12 +93,6 @@ func newServerFailureAPIError(
|
||||
apperrors.WithHint(classified.hint),
|
||||
apperrors.WithActions(classified.actions...),
|
||||
)
|
||||
if classified.operation != "" {
|
||||
opts = append(opts, apperrors.WithOperation(classified.operation))
|
||||
}
|
||||
if classified.retryable != nil {
|
||||
opts = append(opts, apperrors.WithRetryable(*classified.retryable))
|
||||
}
|
||||
}
|
||||
return apperrors.NewAPI(message, opts...)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ func TestCrossPlatformCoverageServerFailureClassifierBackendMetadataUnavailable(
|
||||
"business_error",
|
||||
"check parameters",
|
||||
"im",
|
||||
"list_conversations",
|
||||
apperrors.ServerDiagnostics{
|
||||
TraceID: "trace-local",
|
||||
ServerErrorCode: "NETWORK_ERROR",
|
||||
@@ -67,7 +66,6 @@ func TestCrossPlatformCoverageServerFailureClassifierRequiredConversationID(t *t
|
||||
"business_error",
|
||||
"check parameters",
|
||||
"chat",
|
||||
"send_message",
|
||||
apperrors.ServerDiagnostics{ServerErrorCode: "1001"},
|
||||
)
|
||||
var typed *apperrors.Error
|
||||
@@ -82,74 +80,12 @@ func TestCrossPlatformCoverageServerFailureClassifierRequiredConversationID(t *t
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageServerFailureClassifierTodoCreateUpstreamInternalError(t *testing.T) {
|
||||
serverSaysRetryable := true
|
||||
err := newServerFailureAPIError(
|
||||
"[UNCLASSIFIED] system error: java.lang.NullPointerException (operation: todo/create_personal_todo)",
|
||||
"business_error",
|
||||
"The API returned a business-level error. Check required parameters and values.",
|
||||
"todo",
|
||||
"create_personal_todo",
|
||||
apperrors.ServerDiagnostics{
|
||||
TraceID: "trace-todo-create",
|
||||
ServerErrorCode: "999",
|
||||
ServerRetryable: &serverSaysRetryable,
|
||||
},
|
||||
)
|
||||
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) {
|
||||
t.Fatalf("error = %T, want *errors.Error", err)
|
||||
}
|
||||
if typed.Reason != "upstream_internal_error" || typed.Origin != "dingtalk_api" || typed.FailureStage != "upstream_execution" {
|
||||
t.Fatalf("classification = reason %q origin %q stage %q", typed.Reason, typed.Origin, typed.FailureStage)
|
||||
}
|
||||
if typed.Operation != "todo/create_personal_todo" {
|
||||
t.Fatalf("operation = %q, want todo/create_personal_todo", typed.Operation)
|
||||
}
|
||||
if typed.ExecutionStarted != nil {
|
||||
t.Fatalf("execution_started = %v, want unknown", typed.ExecutionStarted)
|
||||
}
|
||||
if !typed.RetryableSet || typed.Retryable {
|
||||
t.Fatalf("retryability = (%v, %v), want explicit false", typed.RetryableSet, typed.Retryable)
|
||||
}
|
||||
if typed.ServerDiag.TraceID != "trace-todo-create" || typed.ServerDiag.ServerErrorCode != "999" {
|
||||
t.Fatalf("diagnostics = %#v", typed.ServerDiag)
|
||||
}
|
||||
if strings.Contains(strings.ToLower(typed.Hint), "parameter") || !strings.Contains(typed.Hint, "创建结果未知") {
|
||||
t.Fatalf("hint = %q", typed.Hint)
|
||||
}
|
||||
for _, action := range typed.Actions {
|
||||
if strings.Contains(action, "dws doctor") || strings.Contains(action, "登录") || strings.Contains(action, "网络") {
|
||||
t.Fatalf("misleading action = %q", action)
|
||||
}
|
||||
}
|
||||
|
||||
payload := multiProfileErrorPayload(err)
|
||||
for key, want := range map[string]any{
|
||||
"reason": "upstream_internal_error",
|
||||
"origin": "dingtalk_api",
|
||||
"stage": "upstream_execution",
|
||||
"retryable": false,
|
||||
"trace_id": "trace-todo-create",
|
||||
"server_error_code": "999",
|
||||
} {
|
||||
if got := payload[key]; got != want {
|
||||
t.Errorf("payload[%q] = %#v, want %#v", key, got, want)
|
||||
}
|
||||
}
|
||||
if _, ok := payload["execution_started"]; ok {
|
||||
t.Fatalf("payload must keep execution_started unknown: %#v", payload)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageServerFailureClassifierUnknownFallsBack(t *testing.T) {
|
||||
err := newServerFailureAPIError(
|
||||
"business error: success=false",
|
||||
"business_error",
|
||||
"check parameters",
|
||||
"im",
|
||||
"list_conversations",
|
||||
apperrors.ServerDiagnostics{},
|
||||
)
|
||||
var typed *apperrors.Error
|
||||
@@ -170,7 +106,6 @@ func TestCrossPlatformCoverageServerFailureReasonUsesTypedClassification(t *test
|
||||
"business_error",
|
||||
"check parameters",
|
||||
"im",
|
||||
"list_conversations",
|
||||
apperrors.ServerDiagnostics{ServerErrorCode: "NETWORK_ERROR"},
|
||||
)
|
||||
if got := serverFailureReason(err, "business_error"); got != "backend_dependency_unavailable" {
|
||||
@@ -188,7 +123,6 @@ func TestCrossPlatformCoverageMultiProfileErrorPayloadPreservesFailureSemantics(
|
||||
"business_error",
|
||||
"check parameters",
|
||||
"im",
|
||||
"list_conversations",
|
||||
apperrors.ServerDiagnostics{
|
||||
TraceID: "trace-multi",
|
||||
ServerErrorCode: "NETWORK_ERROR",
|
||||
@@ -290,58 +224,3 @@ func TestCrossPlatformCoverageExecuteInvocationClassifiesObservedMCPMetadataFail
|
||||
t.Fatalf("execution_started must remain unknown: %v", typed.ExecutionStarted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageExecuteInvocationClassifiesTodoCreateUpstreamInternalError(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var request struct {
|
||||
ID int `json:"id"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Errorf("decode request: %v", err)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"jsonrpc": "2.0",
|
||||
"id": request.ID,
|
||||
"result": map[string]any{
|
||||
"structuredContent": map[string]any{
|
||||
"success": false,
|
||||
"code": "999",
|
||||
"trace_id": "trace-todo-replay",
|
||||
"errorMsg": "[UNCLASSIFIED] system error: java.lang.NullPointerException (operation: todo/create_personal_todo)",
|
||||
},
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := transport.NewClient(server.Client())
|
||||
client.TrustedDomains = []string{strings.TrimPrefix(server.URL, "http://")}
|
||||
runner := &runtimeRunner{
|
||||
transport: client,
|
||||
globalFlags: &GlobalFlags{Token: "local-test-token"},
|
||||
}
|
||||
_, err := runner.executeInvocation(context.Background(), server.URL, executor.Invocation{
|
||||
CanonicalProduct: "todo",
|
||||
Tool: "create_personal_todo",
|
||||
CanonicalPath: "todo.create_personal_todo",
|
||||
Params: map[string]any{
|
||||
"PersonalTodoCreateVO": map[string]any{
|
||||
"subject": "fixture",
|
||||
"executorIds": []string{"user-1"},
|
||||
},
|
||||
},
|
||||
})
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) {
|
||||
t.Fatalf("executeInvocation() error = %T %v, want typed API error", err, err)
|
||||
}
|
||||
if typed.Reason != "upstream_internal_error" || typed.Operation != "todo/create_personal_todo" {
|
||||
t.Fatalf("classification = reason %q operation %q", typed.Reason, typed.Operation)
|
||||
}
|
||||
if !typed.RetryableSet || typed.Retryable || typed.ExecutionStarted != nil {
|
||||
t.Fatalf("failure semantics = retryable(%v,%v) execution_started=%v", typed.RetryableSet, typed.Retryable, typed.ExecutionStarted)
|
||||
}
|
||||
if typed.ServerDiag.TraceID != "trace-todo-replay" || typed.ServerDiag.ServerErrorCode != "999" {
|
||||
t.Fatalf("diagnostics = %#v", typed.ServerDiag)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,102 +10,6 @@ package cli
|
||||
// generatedParamAliases is the per-command parameter-alias table reduced from
|
||||
// the reviewed concept dictionary. Each entry binds one runnable Cobra leaf.
|
||||
var generatedParamAliases = []ParamAliasEntry{
|
||||
{
|
||||
CLIPath: "aisearch",
|
||||
Aliases: map[string]string{
|
||||
"dimensions": "dimension",
|
||||
"person-dimension": "dimension",
|
||||
"person-name": "query",
|
||||
"person-query": "query",
|
||||
"search-by": "dimension",
|
||||
"search-dimension": "dimension",
|
||||
"search-term": "query",
|
||||
},
|
||||
Blocked: []string{"action-type", "behavior-type", "category", "chat-scope", "department-id", "direction", "employee-number", "field", "job-number", "mobile", "open-dingtalk-id", "phone-number", "queries", "search-types", "time-range", "types", "user-id"},
|
||||
Ambiguous: []string{"department", "duty", "employee", "id", "phone", "position", "scope", "target"},
|
||||
},
|
||||
{
|
||||
CLIPath: "aisearch +search-person",
|
||||
Aliases: map[string]string{
|
||||
"dimension": "dimensions",
|
||||
"keyword": "query",
|
||||
"keywords": "query",
|
||||
"person-dimension": "dimensions",
|
||||
"person-name": "query",
|
||||
"person-query": "query",
|
||||
"q": "query",
|
||||
"search-by": "dimensions",
|
||||
"search-dimension": "dimensions",
|
||||
"search-term": "query",
|
||||
"search-word": "query",
|
||||
},
|
||||
Blocked: []string{"action-type", "behavior-type", "category", "chat-scope", "department-id", "direction", "employee-number", "field", "ids", "job-number", "mobile", "name", "open-dingtalk-id", "phone-number", "position-id", "queries", "search-types", "subject", "text", "time-range", "title", "type", "types", "user-id"},
|
||||
Ambiguous: []string{"department", "duty", "employee", "id", "phone", "position", "scope", "target"},
|
||||
},
|
||||
{
|
||||
CLIPath: "aisearch behavior",
|
||||
Aliases: map[string]string{
|
||||
"action-type": "behavior-type",
|
||||
"activity-type": "behavior-type",
|
||||
"behavior-action": "behavior-type",
|
||||
"chat-name": "chat-scope",
|
||||
"content-queries": "queries",
|
||||
"content-query": "queries",
|
||||
"content-types": "types",
|
||||
"conversation-name": "chat-scope",
|
||||
"date-range": "time-range",
|
||||
"group-name": "chat-scope",
|
||||
"im-scope": "chat-scope",
|
||||
"interaction-direction": "direction",
|
||||
"interaction-flow": "direction",
|
||||
"message-flow": "direction",
|
||||
"period": "time-range",
|
||||
"resource-types": "types",
|
||||
"search-categories": "types",
|
||||
"search-period": "time-range",
|
||||
"search-terms": "queries",
|
||||
"search-type-list": "types",
|
||||
"time-window": "time-range",
|
||||
"topic-queries": "queries",
|
||||
"topics": "queries",
|
||||
},
|
||||
Blocked: []string{"chat-id", "conversation-id", "created-at", "dimension", "dimensions", "document-id", "end", "file-id", "from", "group-id", "natural-language", "node-id", "open-conversation-id", "open-dingtalk-id", "question", "receiver", "sender", "since", "start", "to", "until", "update", "updated-at", "user-id", "write"},
|
||||
Ambiguous: []string{"action", "actor", "category", "chat", "conversation", "date", "destination", "group", "range", "scope", "source", "target", "time", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "aisearch enterprise",
|
||||
Aliases: map[string]string{
|
||||
"content-queries": "queries",
|
||||
"content-query": "queries",
|
||||
"content-types": "types",
|
||||
"date-range": "time-range",
|
||||
"period": "time-range",
|
||||
"resource-types": "types",
|
||||
"search-categories": "types",
|
||||
"search-period": "time-range",
|
||||
"search-terms": "queries",
|
||||
"search-type-list": "types",
|
||||
"time-window": "time-range",
|
||||
"topic-queries": "queries",
|
||||
"topics": "queries",
|
||||
},
|
||||
Blocked: []string{"action-type", "behavior-type", "chat-scope", "created-at", "dimension", "dimensions", "direction", "document-id", "end", "file-id", "from", "group-name", "node-id", "open-dingtalk-id", "receiver", "sender", "since", "start", "to", "until", "update", "updated-at", "user-id", "write"},
|
||||
Ambiguous: []string{"category", "date", "natural-language", "question", "range", "scope", "source", "time", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "aisearch person",
|
||||
Aliases: map[string]string{
|
||||
"dimensions": "dimension",
|
||||
"person-dimension": "dimension",
|
||||
"person-name": "query",
|
||||
"person-query": "query",
|
||||
"search-by": "dimension",
|
||||
"search-dimension": "dimension",
|
||||
"search-term": "query",
|
||||
},
|
||||
Blocked: []string{"action-type", "behavior-type", "category", "chat-scope", "department-id", "direction", "employee-number", "field", "ids", "job-number", "mobile", "open-dingtalk-id", "phone-number", "position-id", "queries", "search-types", "time-range", "types", "user-id"},
|
||||
Ambiguous: []string{"department", "duty", "employee", "id", "phone", "position", "scope", "target"},
|
||||
},
|
||||
{
|
||||
CLIPath: "aitable +advperm-disable",
|
||||
Aliases: map[string]string{
|
||||
@@ -4224,13 +4128,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"conversation-ids", "dest-conversation-id", "group-id", "group-ids", "group-name", "id", "name", "open-conversation-ids", "source", "src-conversation-id", "target"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +by-mobile",
|
||||
Aliases: map[string]string{
|
||||
"org-user-mobile": "mobile",
|
||||
},
|
||||
Blocked: []string{"email", "login-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +dept-members",
|
||||
Aliases: map[string]string{
|
||||
@@ -4251,23 +4148,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"department-id", "dept", "dept-id", "name", "query"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +list-followings",
|
||||
Aliases: map[string]string{
|
||||
"open-dingtalk-id": "open-id",
|
||||
"open-dingtalkid": "open-id",
|
||||
},
|
||||
Blocked: []string{"email", "mobile", "name", "open-dingtalk-ids", "phone", "query", "staff-id", "user-id", "userid"},
|
||||
Ambiguous: []string{"id", "person", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +list-role-members",
|
||||
Aliases: map[string]string{
|
||||
"label-id": "id",
|
||||
"role-id": "id",
|
||||
},
|
||||
Blocked: []string{"dept", "dept-id", "ids", "names", "staff-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +list-sub-depts",
|
||||
Aliases: map[string]string{
|
||||
@@ -4279,28 +4159,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"department-ids", "dept-ids", "depts", "name", "query"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +lookup",
|
||||
Aliases: map[string]string{
|
||||
"employee-name": "name",
|
||||
"flower-name": "name",
|
||||
"person-name": "name",
|
||||
"staff-name": "name",
|
||||
"user-name": "name",
|
||||
},
|
||||
Blocked: []string{"department-id", "dept", "dept-id", "org-name", "role-name"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +org",
|
||||
Aliases: map[string]string{
|
||||
"employee-name": "name",
|
||||
"flower-name": "name",
|
||||
"person-name": "name",
|
||||
"staff-name": "name",
|
||||
"user-name": "name",
|
||||
},
|
||||
Blocked: []string{"department-id", "dept", "dept-id", "org-name", "role-name"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +resolve-dept",
|
||||
Aliases: map[string]string{
|
||||
@@ -4312,13 +4170,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"subject", "text", "title"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +search-mobile",
|
||||
Aliases: map[string]string{
|
||||
"org-user-mobile": "mobile",
|
||||
},
|
||||
Blocked: []string{"email", "login-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +search-user",
|
||||
Aliases: map[string]string{
|
||||
@@ -4329,65 +4180,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"name", "subject", "text", "title"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact +team",
|
||||
Aliases: map[string]string{
|
||||
"employee-name": "name",
|
||||
"flower-name": "name",
|
||||
"person-name": "name",
|
||||
"staff-name": "name",
|
||||
"user-name": "name",
|
||||
},
|
||||
Blocked: []string{"department-id", "dept", "dept-id", "org-name", "role-name"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact account create",
|
||||
Aliases: map[string]string{
|
||||
"account-login-id": "login-id",
|
||||
"department-ids": "dept-ids",
|
||||
"depts": "dept-ids",
|
||||
"email-address": "email",
|
||||
"employee-name": "org-user-name",
|
||||
"login-account": "login-id",
|
||||
"mail-address": "email",
|
||||
"mobile": "org-user-mobile",
|
||||
"organization-user-name": "org-user-name",
|
||||
"staff-name": "org-user-name",
|
||||
},
|
||||
Blocked: []string{"creator-username", "department-id", "department-memberships-json", "dept", "dept-id", "depts-json", "name", "nick", "org-name", "query", "staff-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact account update",
|
||||
Aliases: map[string]string{
|
||||
"department-assignments-json": "depts",
|
||||
"department-memberships-json": "depts",
|
||||
"employee-name": "org-user-name",
|
||||
"organization-user-name": "org-user-name",
|
||||
"profile-image-file-id": "avatar-file-id",
|
||||
"staff-id": "user-id",
|
||||
"staff-name": "org-user-name",
|
||||
"uid": "user-id",
|
||||
"user": "user-id",
|
||||
},
|
||||
Blocked: []string{"at-user-ids", "creator-username", "department-id", "department-ids", "dept", "dept-id", "dept-ids", "file", "name", "node-id", "org-name", "ownness-text", "parent", "parent-id", "to-user", "user-ids", "users"},
|
||||
Ambiguous: []string{"manager", "owner-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept create",
|
||||
Aliases: map[string]string{
|
||||
"new-parent-dept-id": "parent",
|
||||
"parent-department-id": "parent",
|
||||
"parent-dept-id": "parent",
|
||||
},
|
||||
Blocked: []string{"department-ids", "dept", "dept-id", "dept-ids", "depts"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept get-info",
|
||||
Aliases: map[string]string{
|
||||
"department-id": "dept",
|
||||
},
|
||||
Blocked: []string{"department", "department-ids", "depts", "parent", "parent-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept list-children",
|
||||
Aliases: map[string]string{
|
||||
@@ -4398,180 +4190,18 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"department-ids", "depts", "name", "query"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept list-members",
|
||||
Aliases: map[string]string{
|
||||
"department-ids": "depts",
|
||||
},
|
||||
Blocked: []string{"department-id", "dept", "name", "query"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept search",
|
||||
Aliases: map[string]string{
|
||||
"keywords": "query",
|
||||
"q": "query",
|
||||
"search-word": "query",
|
||||
},
|
||||
Blocked: []string{"subject", "text", "title"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact dept update",
|
||||
Aliases: map[string]string{
|
||||
"new-parent-dept-id": "parent",
|
||||
"parent-department-id": "parent",
|
||||
"parent-dept-id": "parent",
|
||||
"target-department-id": "dept",
|
||||
"target-dept-id": "dept",
|
||||
},
|
||||
Blocked: []string{"department-ids", "depts"},
|
||||
Ambiguous: []string{"department", "target-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact label get",
|
||||
Aliases: map[string]string{
|
||||
"label-names": "names",
|
||||
"role-names": "names",
|
||||
},
|
||||
Blocked: []string{"dept-id", "id", "label-id", "role-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact label list-members",
|
||||
Blocked: []string{"dept", "dept-id", "ids", "names", "staff-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact org create",
|
||||
Aliases: map[string]string{
|
||||
"company-name": "org-name",
|
||||
"corp-name": "org-name",
|
||||
"creator-name": "creator-username",
|
||||
"founder-name": "creator-username",
|
||||
"organization-name": "org-name",
|
||||
},
|
||||
Blocked: []string{"login-id", "user-id"},
|
||||
Ambiguous: []string{"name"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user dismission search",
|
||||
Aliases: map[string]string{
|
||||
"begin": "start",
|
||||
"current-page": "page",
|
||||
"department-ids": "depts",
|
||||
"dept-ids": "depts",
|
||||
"employee-name": "name",
|
||||
"end-date": "end",
|
||||
"end-time": "end",
|
||||
"flower-name": "name",
|
||||
"from": "start",
|
||||
"from-date": "start",
|
||||
"max-result": "limit",
|
||||
"max-results": "limit",
|
||||
"max-time": "end",
|
||||
"min-time": "start",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"page-size": "limit",
|
||||
"per-page": "limit",
|
||||
"person-name": "name",
|
||||
"since": "start",
|
||||
"size": "limit",
|
||||
"staff-name": "name",
|
||||
"start-date": "start",
|
||||
"start-time": "start",
|
||||
"take": "limit",
|
||||
"time-max": "end",
|
||||
"time-min": "start",
|
||||
"top": "limit",
|
||||
"user-name": "name",
|
||||
},
|
||||
Blocked: []string{"count", "cursor", "date", "department-id", "department-memberships-json", "dept", "dept-id", "dept-list-json", "offset", "page-index", "page-token", "query", "time"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user get",
|
||||
Aliases: map[string]string{
|
||||
"member-user-ids": "ids",
|
||||
"staff-ids": "ids",
|
||||
"users": "ids",
|
||||
},
|
||||
Blocked: []string{"at-user-ids", "staff-id", "uid", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user invite",
|
||||
Aliases: map[string]string{
|
||||
"department-assignments-json": "depts",
|
||||
"department-memberships-json": "depts",
|
||||
"employee-name": "org-user-name",
|
||||
"mobile": "org-user-mobile",
|
||||
"organization-user-name": "org-user-name",
|
||||
"staff-name": "org-user-name",
|
||||
},
|
||||
Blocked: []string{"creator-username", "department-id", "department-ids", "dept", "dept-id", "dept-ids", "email", "login-id", "nick", "org-name", "parent", "parent-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user profile get",
|
||||
Aliases: map[string]string{
|
||||
"field-code-list": "fields",
|
||||
"field-codes": "fields",
|
||||
"id": "staff-id",
|
||||
"ids": "staff-id",
|
||||
"profile-fields": "fields",
|
||||
"roster-fields": "fields",
|
||||
"uid": "staff-id",
|
||||
"user": "staff-id",
|
||||
"user-id": "staff-id",
|
||||
"userid": "staff-id",
|
||||
},
|
||||
Blocked: []string{"at-user-ids", "name", "output-fields", "staff-ids", "to-user", "user-ids", "users"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user search",
|
||||
Aliases: map[string]string{
|
||||
"keywords": "query",
|
||||
"q": "query",
|
||||
"search-word": "query",
|
||||
},
|
||||
Blocked: []string{"subject", "text", "title"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user search-mobile",
|
||||
Aliases: map[string]string{
|
||||
"org-user-mobile": "mobile",
|
||||
},
|
||||
Blocked: []string{"email", "login-id", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user update",
|
||||
Aliases: map[string]string{
|
||||
"department-assignments-json": "depts",
|
||||
"department-memberships-json": "depts",
|
||||
"employee-name": "org-user-name",
|
||||
"organization-user-name": "org-user-name",
|
||||
"staff-id": "user-id",
|
||||
"staff-name": "org-user-name",
|
||||
"uid": "user-id",
|
||||
"user": "user-id",
|
||||
},
|
||||
Blocked: []string{"at-user-ids", "creator-username", "department-id", "department-ids", "dept", "dept-id", "dept-ids", "name", "nick", "org-name", "parent", "parent-id", "to-user", "user-ids", "users"},
|
||||
Ambiguous: []string{"manager", "owner-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user update-ownness",
|
||||
Aliases: map[string]string{
|
||||
"personal-status": "ownness-text",
|
||||
"staff-id": "user-id",
|
||||
"status": "ownness-text",
|
||||
"status-text": "ownness-text",
|
||||
"uid": "user-id",
|
||||
"user": "user-id",
|
||||
"id": "staff-id",
|
||||
"ids": "staff-id",
|
||||
"uid": "staff-id",
|
||||
"user": "staff-id",
|
||||
"user-id": "staff-id",
|
||||
"userid": "staff-id",
|
||||
},
|
||||
Blocked: []string{"at-user-ids", "name", "to-user", "user-ids", "users"},
|
||||
},
|
||||
{
|
||||
CLIPath: "contact user update-self",
|
||||
Aliases: map[string]string{
|
||||
"profile-image-file-id": "avatar-file-id",
|
||||
},
|
||||
Blocked: []string{"file", "name", "node-id", "org-user-name", "ownness-text", "user-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "dev app get",
|
||||
Aliases: map[string]string{
|
||||
@@ -4583,26 +4213,18 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
{
|
||||
CLIPath: "devdoc article search",
|
||||
Aliases: map[string]string{
|
||||
"current-page": "page",
|
||||
"keywords": "query",
|
||||
"limit": "size",
|
||||
"max-result": "size",
|
||||
"max-results": "size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"page-number": "page",
|
||||
"page-size": "size",
|
||||
"per-page": "size",
|
||||
"q": "query",
|
||||
"query-text": "query",
|
||||
"results-per-page": "size",
|
||||
"search-term": "query",
|
||||
"search-word": "query",
|
||||
"take": "size",
|
||||
"top": "size",
|
||||
"current-page": "page",
|
||||
"limit": "size",
|
||||
"max-result": "size",
|
||||
"max-results": "size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"page-size": "size",
|
||||
"per-page": "size",
|
||||
"take": "size",
|
||||
"top": "size",
|
||||
},
|
||||
Blocked: []string{"context", "count", "cursor", "doc-id", "document-id", "error-code", "error-message", "file-id", "name", "next-cursor", "next-token", "node-id", "offset", "page-index", "page-token", "request-id", "space-id", "subject", "text", "title", "total", "trace-id", "workspace-id"},
|
||||
Ambiguous: []string{"id", "type"},
|
||||
Blocked: []string{"count", "cursor", "page-index", "page-token"},
|
||||
},
|
||||
{
|
||||
CLIPath: "ding +list",
|
||||
@@ -6730,166 +6352,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"knowledge-base-id", "limit", "page-size", "part-size", "size", "space", "wiki-workspace-id", "workspace", "workspace-id"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain profile career",
|
||||
Aliases: map[string]string{
|
||||
"employee-no": "work-no",
|
||||
"employee-number": "work-no",
|
||||
"staff-no": "work-no",
|
||||
},
|
||||
Blocked: []string{"employee-id", "end", "end-date", "job-level", "position", "staff-id", "staff-ids", "start", "start-date", "user-id", "work-nos", "year"},
|
||||
Ambiguous: []string{"date", "employee", "id", "name", "time", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain profile labels",
|
||||
Aliases: map[string]string{
|
||||
"all-labels": "all-label",
|
||||
"employee-nos": "staff-ids",
|
||||
"staff-nos": "staff-ids",
|
||||
"work-nos": "staff-ids",
|
||||
},
|
||||
Blocked: []string{"employee-id", "employee-ids", "employee-no", "staff-id", "staff-no", "user-id", "user-ids", "work-no"},
|
||||
Ambiguous: []string{"employee", "id", "label", "name", "tag", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain profile metadata",
|
||||
Aliases: map[string]string{
|
||||
"employee-no": "work-no",
|
||||
"employee-number": "work-no",
|
||||
"staff-no": "work-no",
|
||||
},
|
||||
Blocked: []string{"data-queries", "employee-id", "model-code", "module", "section", "staff-id", "staff-ids", "user-id", "work-nos"},
|
||||
Ambiguous: []string{"employee", "field", "id", "name", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain profile performance",
|
||||
Aliases: map[string]string{
|
||||
"employee-no": "work-no",
|
||||
"employee-number": "work-no",
|
||||
"staff-no": "work-no",
|
||||
},
|
||||
Blocked: []string{"cycle", "employee-id", "end", "end-date", "rating", "score", "staff-id", "staff-ids", "start", "start-date", "user-id", "work-nos", "year"},
|
||||
Ambiguous: []string{"date", "employee", "id", "level", "name", "time", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain profile query",
|
||||
Aliases: map[string]string{
|
||||
"employee-no": "work-no",
|
||||
"employee-number": "work-no",
|
||||
"module-queries": "data-queries",
|
||||
"profile-queries": "data-queries",
|
||||
"staff-no": "work-no",
|
||||
},
|
||||
Blocked: []string{"data-query", "employee-id", "model-code", "module", "section", "staff-id", "staff-ids", "user-id", "work-nos"},
|
||||
Ambiguous: []string{"employee", "field", "id", "name", "query", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain search employees",
|
||||
Aliases: map[string]string{
|
||||
"current-page": "page",
|
||||
"department-name": "dept-name",
|
||||
"job-title": "position-name",
|
||||
"keywords": "keyword",
|
||||
"limit": "page-size",
|
||||
"max-result": "page-size",
|
||||
"max-results": "page-size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"per-page": "page-size",
|
||||
"position-level": "job-level",
|
||||
"q": "keyword",
|
||||
"query": "keyword",
|
||||
"search-word": "keyword",
|
||||
"size": "page-size",
|
||||
"take": "page-size",
|
||||
"talent-pool-code": "pool-code",
|
||||
"top": "page-size",
|
||||
},
|
||||
Blocked: []string{"count", "cursor", "data-queries", "department-id", "dept-id", "employee-id", "order-by", "origin-json", "page-index", "page-token", "pool-id", "staff-id", "staff-ids", "subject", "talent-pool-id", "text", "user-id", "work-no"},
|
||||
Ambiguous: []string{"code", "department", "grade", "id", "level", "name", "pool", "position", "title", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain search employees-structured",
|
||||
Aliases: map[string]string{
|
||||
"criteria-json": "origin-json",
|
||||
"current-page": "page",
|
||||
"filter-json": "origin-json",
|
||||
"limit": "page-size",
|
||||
"max-result": "page-size",
|
||||
"max-results": "page-size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"per-page": "page-size",
|
||||
"result-fields-json": "fields",
|
||||
"return-fields-json": "fields",
|
||||
"search-json": "origin-json",
|
||||
"size": "page-size",
|
||||
"sort-by": "order-by",
|
||||
"sort-fields": "order-by",
|
||||
"take": "page-size",
|
||||
"top": "page-size",
|
||||
},
|
||||
Blocked: []string{"count", "cursor", "department-name", "dept-name", "field-name", "job-level", "keyword", "operator", "operators", "page-index", "page-token", "pool-code", "position-name", "query", "staff-ids", "work-no"},
|
||||
Ambiguous: []string{"criteria", "field", "filter", "id", "name", "order", "sort", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain search fields",
|
||||
Blocked: []string{"dept-name", "field-name", "job-level", "keyword", "operator", "operators", "order-by", "origin-json", "page", "page-size", "pool-code", "position-name", "query", "staff-ids", "work-no"},
|
||||
Ambiguous: []string{"criteria", "field", "filter", "id", "name", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain talent-pool detail",
|
||||
Aliases: map[string]string{
|
||||
"talent-pool-code": "pool-code",
|
||||
},
|
||||
Blocked: []string{"creator", "employee-id", "keyword", "labels", "page", "page-size", "pool-id", "query", "staff-ids", "talent-pool-id", "work-no"},
|
||||
Ambiguous: []string{"code", "id", "name", "pool", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain talent-pool employees",
|
||||
Aliases: map[string]string{
|
||||
"current-page": "page",
|
||||
"limit": "page-size",
|
||||
"max-result": "page-size",
|
||||
"max-results": "page-size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"per-page": "page-size",
|
||||
"size": "page-size",
|
||||
"take": "page-size",
|
||||
"talent-pool-code": "pool-code",
|
||||
"top": "page-size",
|
||||
},
|
||||
Blocked: []string{"count", "creator", "cursor", "dept-name", "employee-id", "job-level", "keyword", "labels", "page-index", "page-token", "pool-id", "position-name", "query", "staff-ids", "talent-pool-id", "work-no"},
|
||||
Ambiguous: []string{"code", "id", "name", "pool", "status"},
|
||||
},
|
||||
{
|
||||
CLIPath: "hrbrain talent-pool list",
|
||||
Aliases: map[string]string{
|
||||
"current-page": "page",
|
||||
"keywords": "keyword",
|
||||
"label-list": "labels",
|
||||
"limit": "page-size",
|
||||
"max-result": "page-size",
|
||||
"max-results": "page-size",
|
||||
"page-no": "page",
|
||||
"page-num": "page",
|
||||
"per-page": "page-size",
|
||||
"q": "keyword",
|
||||
"query": "keyword",
|
||||
"search-word": "keyword",
|
||||
"size": "page-size",
|
||||
"take": "page-size",
|
||||
"top": "page-size",
|
||||
},
|
||||
Blocked: []string{"count", "cursor", "employee-id", "name", "page-index", "page-token", "pool-code", "pool-id", "staff-ids", "subject", "talent-pool-id", "text", "title", "user-id", "work-no"},
|
||||
Ambiguous: []string{"code", "creator-id", "id", "label-name", "pool", "type", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "live stream list",
|
||||
Blocked: []string{"anchor-id", "conversation-id", "cover-url", "create", "creator-id", "cursor", "end", "end-live", "end-time", "from", "group-id", "keyword", "limit", "live-id", "offset", "order", "page", "page-size", "page-token", "playback", "query", "record", "room-id", "size", "sort", "start", "start-live", "start-time", "state", "status", "stream-id", "title", "to", "user-id"},
|
||||
Ambiguous: []string{"date", "id", "owner", "time", "type", "user"},
|
||||
},
|
||||
{
|
||||
CLIPath: "mail +contact-list",
|
||||
Aliases: map[string]string{
|
||||
@@ -7995,42 +7457,6 @@ var generatedParamAliases = []ParamAliasEntry{
|
||||
},
|
||||
Blocked: []string{"name", "subject", "text", "title"},
|
||||
},
|
||||
{
|
||||
CLIPath: "pat +browser-policy",
|
||||
Aliases: map[string]string{
|
||||
"allow-browser": "enabled",
|
||||
"browser-enabled": "enabled",
|
||||
"open-browser": "enabled",
|
||||
},
|
||||
Blocked: []string{"api-scope", "app-id", "app-key", "app-secret", "block-browser", "browser-disabled", "deny-browser", "disable-browser", "domain", "domains", "grant-mode", "grant-type", "oauth-scope", "permission", "permissions", "product", "products", "recommend", "recommended", "scope", "scopes", "session-id"},
|
||||
Ambiguous: []string{"agent", "agent-id", "browser", "mode", "policy", "state", "value"},
|
||||
},
|
||||
{
|
||||
CLIPath: "pat browser-policy",
|
||||
Aliases: map[string]string{
|
||||
"allow-browser": "enabled",
|
||||
"browser-enabled": "enabled",
|
||||
"open-browser": "enabled",
|
||||
},
|
||||
Blocked: []string{"api-scope", "app-id", "app-key", "app-secret", "block-browser", "browser-disabled", "deny-browser", "disable-browser", "domain", "domains", "grant-mode", "grant-type", "oauth-scope", "permission", "permissions", "product", "products", "recommend", "recommended", "scope", "scopes", "session-id"},
|
||||
Ambiguous: []string{"agent", "agent-id", "browser", "mode", "policy", "state", "value"},
|
||||
},
|
||||
{
|
||||
CLIPath: "pat chmod",
|
||||
Aliases: map[string]string{
|
||||
"authorization-mode": "grant-type",
|
||||
"authorization-session-id": "session-id",
|
||||
"domain-code": "domain",
|
||||
"domain-codes": "domains",
|
||||
"grant-mode": "grant-type",
|
||||
"pat-session-id": "session-id",
|
||||
"product-code": "product",
|
||||
"product-codes": "products",
|
||||
"recommended": "recommend",
|
||||
},
|
||||
Blocked: []string{"all", "all-scopes", "allow-browser", "api-scope", "app-id", "app-key", "app-secret", "browser-enabled", "browser-policy", "confirm", "confirmed", "disable-browser", "force", "oauth-scope", "open-browser", "permission", "permission-scope", "permission-scopes", "permissions", "scope", "scopes"},
|
||||
Ambiguous: []string{"action", "agent", "agent-id", "id", "mode", "resource", "service", "services", "session", "type"},
|
||||
},
|
||||
{
|
||||
CLIPath: "report +inbox-list",
|
||||
Aliases: map[string]string{
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -96,14 +96,7 @@ func init() {
|
||||
registerRequireOneOf("sheet.update_cond_format", "ranges", "condition", "cell-style", "data-bar-style")
|
||||
registerRequireOneOf("sheet.update_dimension", "hidden", "pixel-size")
|
||||
registerRequireOneOf("sheet.update_filter_view", "name", "range", "criteria")
|
||||
RegisterRuntimeSchemaConstraints("sheet.create_float_image", RuntimeSchemaConstraints{
|
||||
MutuallyExclusive: [][]string{{"file", "src"}},
|
||||
RequireOneOf: [][]string{{"file", "src"}},
|
||||
})
|
||||
RegisterRuntimeSchemaConstraints("sheet.update_float_image", RuntimeSchemaConstraints{
|
||||
MutuallyExclusive: [][]string{{"file", "src"}},
|
||||
RequireOneOf: [][]string{{"file", "src", "range", "width", "height", "offset-x", "offset-y"}},
|
||||
})
|
||||
registerRequireOneOf("sheet.update_float_image", "src", "range", "width", "height", "offset-x", "offset-y")
|
||||
registerRequireOneOf("sheet.update_sheet", "name", "index", "hidden", "frozen-row-count", "frozen-column-count", "tab-color")
|
||||
registerRequireOneOf("sheet.import", "folder-token", "workspace")
|
||||
registerRequireOneOf("wiki.search_wikiSpaces", "query", "type")
|
||||
|
||||
@@ -554,7 +554,6 @@ var reviewedSchemaParameterMappingExclusions = map[string]string{
|
||||
"sheet.chart_update --properties": "Reviewed unpinned adapter: sheet.chart_update has no singular pinned interface_ref; --properties is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.chart_update --sheet-id": "Reviewed unpinned adapter: sheet.chart_update has no singular pinned interface_ref; --sheet-id is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.create_cond_format --condition": "one aggregate JSON flag selects one of multiple mutually exclusive RPC condition properties",
|
||||
"sheet.create_float_image --file": "local Sheet upload input used to obtain a resourceUrl before create_float_image",
|
||||
"sheet.create_pivot_table --properties": "Reviewed unpinned adapter: sheet.create_pivot_table has no singular pinned interface_ref; --properties is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.create_pivot_table --source": "Reviewed unpinned adapter: sheet.create_pivot_table has no singular pinned interface_ref; --source is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.create_pivot_table --target-position": "Reviewed unpinned adapter: sheet.create_pivot_table has no singular pinned interface_ref; --target-position is a CLI wrapper input and does not publish a direct interface property.",
|
||||
@@ -647,7 +646,6 @@ var reviewedSchemaParameterMappingExclusions = map[string]string{
|
||||
"sheet.ungroup_dimension --range": "Reviewed unpinned adapter: sheet.ungroup_dimension has no singular pinned interface_ref; --range is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.ungroup_dimension --sheet-id": "Reviewed unpinned adapter: sheet.ungroup_dimension has no singular pinned interface_ref; --sheet-id is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.update_cond_format --condition": "one aggregate JSON flag selects one of multiple mutually exclusive RPC condition properties",
|
||||
"sheet.update_float_image --file": "local Sheet upload input used to obtain a resourceUrl before update_float_image",
|
||||
"sheet.update_pivot_table --pivot-table-id": "Reviewed unpinned adapter: sheet.update_pivot_table has no singular pinned interface_ref; --pivot-table-id is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.update_pivot_table --properties": "Reviewed unpinned adapter: sheet.update_pivot_table has no singular pinned interface_ref; --properties is a CLI wrapper input and does not publish a direct interface property.",
|
||||
"sheet.update_pivot_table --sheet-id": "Reviewed unpinned adapter: sheet.update_pivot_table has no singular pinned interface_ref; --sheet-id is a CLI wrapper input and does not publish a direct interface property.",
|
||||
|
||||
@@ -15,21 +15,18 @@ func newFloatImageCmds() []*cobra.Command {
|
||||
|
||||
浮动图片悬浮于单元格之上,不占用单元格内容,可自由定位和调整大小。
|
||||
|
||||
直接传 --file 可在一个命令中上传本地图片并创建浮动图片。
|
||||
已经通过 media-upload 获得 resourceUrl 时,也可以改传 --src;--file 与 --src 二选一。
|
||||
使用流程:
|
||||
1. 先通过 media-upload 上传本地图片获取 resourceUrl
|
||||
2. 再通过 create-float-image 将图片以浮动方式放置到工作表上
|
||||
|
||||
--range 指定浮动图片锚定的单元格位置,使用 A1 表示法(如 A1、B3)。
|
||||
--width / --height 为必填,单位像素,必须为正整数。
|
||||
--offset-x / --offset-y 可选,表示相对锚点单元格左上角的偏移量(像素),默认 0。`,
|
||||
Example: ` # 直接从本地文件创建
|
||||
dws sheet create-float-image --node NODE_ID --sheet-id SHEET_ID \
|
||||
--file ./chart.png --range A1 --width 400 --height 300
|
||||
|
||||
# 高级用法:先上传图片获取 resourceUrl
|
||||
Example: ` # 先上传图片获取 resourceUrl
|
||||
dws sheet media-upload --node NODE_ID --file ./chart.png
|
||||
# 输出: resourceUrl: /core/api/resources/img/xxxx...
|
||||
|
||||
# 再通过 --src 创建浮动图片
|
||||
# 再创建浮动图片(--src 传入 media-upload 返回的 resourceUrl)
|
||||
dws sheet create-float-image --node NODE_ID --sheet-id SHEET_ID \
|
||||
--src "/core/api/resources/img/xxxx..." --range A1 --width 400 --height 300
|
||||
|
||||
@@ -37,11 +34,7 @@ func newFloatImageCmds() []*cobra.Command {
|
||||
dws sheet create-float-image --node NODE_ID --sheet-id SHEET_ID \
|
||||
--src "/core/api/resources/img/xxxx..." --range B2 --width 200 --height 150 --offset-x 10 --offset-y 20`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if err := validateRequiredFlags(cmd, "node", "sheet-id", "range"); err != nil {
|
||||
return err
|
||||
}
|
||||
filePath, src, err := validateFloatImageCreateInput(cmd)
|
||||
if err != nil {
|
||||
if err := validateRequiredFlags(cmd, "node", "sheet-id", "src", "range"); err != nil {
|
||||
return err
|
||||
}
|
||||
width, err := cmd.Flags().GetInt("width")
|
||||
@@ -61,6 +54,7 @@ func newFloatImageCmds() []*cobra.Command {
|
||||
toolArgs := map[string]any{
|
||||
"nodeId": mustGetFlag(cmd, "node"),
|
||||
"sheetId": mustGetFlag(cmd, "sheet-id"),
|
||||
"src": mustGetFlag(cmd, "src"),
|
||||
"range": mustGetFlag(cmd, "range"),
|
||||
"width": width,
|
||||
"height": height,
|
||||
@@ -79,11 +73,7 @@ func newFloatImageCmds() []*cobra.Command {
|
||||
}
|
||||
toolArgs["offsetY"] = oy
|
||||
}
|
||||
if filePath != "" {
|
||||
return runFloatImageFileMode(cmd, "create_float_image", filePath, toolArgs)
|
||||
}
|
||||
toolArgs["src"] = src
|
||||
return callMCPToolContext(cmd.Context(), "create_float_image", toolArgs)
|
||||
return callMCPTool("create_float_image", toolArgs)
|
||||
},
|
||||
}
|
||||
DeclareLeafMetadata(createFloatImageCmd, LeafSpec{
|
||||
@@ -99,30 +89,26 @@ func newFloatImageCmds() []*cobra.Command {
|
||||
CLIPath: "sheet create-float-image",
|
||||
PrimaryCLIPath: "sheet create-float-image",
|
||||
},
|
||||
Description: "从本地文件或已上传的 resourceUrl 创建浮动图片。",
|
||||
DryRun: &contract.DryRunSpec{PreviewKind: "request", RemoteReads: false},
|
||||
Description: "创建浮动图片(src 必须来自 media-upload 的 resourceUrl)。",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "mcp",
|
||||
Availability: "available",
|
||||
Ref: &contract.InterfaceRefSpec{ProductID: "sheet", RPCName: "create_float_image"},
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "从本地文件或已上传的 resourceUrl 创建浮动图片。",
|
||||
AgentSummary: "创建浮动图片(src 必须来自 media-upload 的 resourceUrl)。",
|
||||
UseWhen: []string{"需要在单元格上方悬浮图片、不占用单元格内容时"},
|
||||
AvoidWhen: []string{"单元格内嵌图片用 write-image;更新/删除浮动图用 update/delete-float-image"},
|
||||
Examples: []string{"dws sheet create-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --src \"/core/api/resources/img/...\" --range A1 --width 400 --height 300"},
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "node", Property: "nodeId"},
|
||||
{Name: "file", Required: boolPtr(false), RequiredWhen: "exactly one of --file or --src must be provided"},
|
||||
{Name: "src", Property: "src", Required: boolPtr(false)},
|
||||
},
|
||||
},
|
||||
})
|
||||
createFloatImageCmd.Flags().String("node", "", "表格文档 ID 或 URL (必填)")
|
||||
createFloatImageCmd.Flags().String("sheet-id", "", "工作表 ID 或名称 (必填)")
|
||||
createFloatImageCmd.Flags().String("file", "", "本地图片文件路径,与 --src 二选一")
|
||||
createFloatImageCmd.Flags().String("src", "", "通过 media-upload 获取的 resourceUrl,与 --file 二选一")
|
||||
createFloatImageCmd.Flags().String("src", "", "图片资源路径,通过 media-upload 获取的 resourceUrl (必填)")
|
||||
createFloatImageCmd.Flags().String("range", "", "锚点单元格,A1 表示法,如 A1、B3 (必填)")
|
||||
createFloatImageCmd.Flags().Int("width", 0, "图片宽度,像素 (必填)")
|
||||
createFloatImageCmd.Flags().Int("height", 0, "图片高度,像素 (必填)")
|
||||
@@ -231,8 +217,8 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
Short: "更新浮动图片属性",
|
||||
Long: `更新钉钉表格指定工作表中浮动图片的属性。
|
||||
|
||||
可直接传 --file 上传本地图片并替换浮动图片,也可传已上传图片的 --src。
|
||||
至少需要传入一个更新字段(--file / --src / --range / --width / --height / --offset-x / --offset-y),且 --file 与 --src 不能同时使用。
|
||||
可更新的属性包括:图片资源路径(src)、锚点位置、尺寸、偏移量。
|
||||
至少需要传入一个更新字段(--src / --range / --width / --height / --offset-x / --offset-y)。
|
||||
floatImageId 可通过 list-float-images 获取。`,
|
||||
Example: ` # 移动浮动图片到新位置
|
||||
dws sheet update-float-image --node NODE_ID --sheet-id SHEET_ID --float-image-id FI_ID --range C5
|
||||
@@ -240,15 +226,10 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
# 调整尺寸
|
||||
dws sheet update-float-image --node NODE_ID --sheet-id SHEET_ID --float-image-id FI_ID --width 600 --height 400
|
||||
|
||||
# 直接用本地文件替换图片
|
||||
dws sheet update-float-image --node NODE_ID --sheet-id SHEET_ID --float-image-id FI_ID \
|
||||
--file ./replacement.png
|
||||
|
||||
# 高级用法:用 media-upload 返回的 resourceUrl 替换图片
|
||||
# 替换图片(需先 media-upload 新图片获取 resourceUrl)
|
||||
dws sheet update-float-image --node NODE_ID --sheet-id SHEET_ID --float-image-id FI_ID \
|
||||
--src "/core/api/resources/img/xxxx..."`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
fileChanged := cmd.Flags().Changed("file")
|
||||
srcChanged := cmd.Flags().Changed("src")
|
||||
rangeChanged := cmd.Flags().Changed("range")
|
||||
widthChanged := cmd.Flags().Changed("width")
|
||||
@@ -256,17 +237,8 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
oxChanged := cmd.Flags().Changed("offset-x")
|
||||
oyChanged := cmd.Flags().Changed("offset-y")
|
||||
|
||||
if !fileChanged && !srcChanged && !rangeChanged && !widthChanged && !heightChanged && !oxChanged && !oyChanged {
|
||||
return fmt.Errorf("%s", floatImageUpdateFieldsError)
|
||||
}
|
||||
filePath, src, err := validateFloatImageUpdateInput(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if fileChanged {
|
||||
if err := validateRequiredFlags(cmd, "node", "sheet-id", "float-image-id"); err != nil {
|
||||
return err
|
||||
}
|
||||
if !srcChanged && !rangeChanged && !widthChanged && !heightChanged && !oxChanged && !oyChanged {
|
||||
return fmt.Errorf("--src、--range、--width、--height、--offset-x、--offset-y 至少必须提供一个")
|
||||
}
|
||||
|
||||
toolArgs := map[string]any{
|
||||
@@ -275,7 +247,7 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
"floatImageId": mustGetFlag(cmd, "float-image-id"),
|
||||
}
|
||||
if srcChanged {
|
||||
toolArgs["src"] = src
|
||||
toolArgs["src"], _ = cmd.Flags().GetString("src")
|
||||
}
|
||||
if rangeChanged {
|
||||
toolArgs["range"], _ = cmd.Flags().GetString("range")
|
||||
@@ -308,10 +280,7 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
}
|
||||
toolArgs["offsetY"] = oy
|
||||
}
|
||||
if fileChanged {
|
||||
return runFloatImageFileMode(cmd, "update_float_image", filePath, toolArgs)
|
||||
}
|
||||
return callMCPToolContext(cmd.Context(), "update_float_image", toolArgs)
|
||||
return callMCPTool("update_float_image", toolArgs)
|
||||
},
|
||||
}
|
||||
DeclareLeafMetadata(updateFloatImageCmd, LeafSpec{
|
||||
@@ -328,7 +297,6 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
PrimaryCLIPath: "sheet update-float-image",
|
||||
},
|
||||
Description: "更新浮动图片锚点、尺寸、偏移或资源路径。",
|
||||
DryRun: &contract.DryRunSpec{PreviewKind: "request", RemoteReads: false},
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "mcp",
|
||||
Availability: "available",
|
||||
@@ -342,15 +310,12 @@ floatImageId 可通过 list-float-images 获取。`,
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "node", Property: "nodeId"},
|
||||
{Name: "file", Required: boolPtr(false)},
|
||||
{Name: "src", Property: "src", Required: boolPtr(false)},
|
||||
},
|
||||
},
|
||||
})
|
||||
updateFloatImageCmd.Flags().String("node", "", "表格文档 ID 或 URL (必填)")
|
||||
updateFloatImageCmd.Flags().String("sheet-id", "", "工作表 ID 或名称 (必填)")
|
||||
updateFloatImageCmd.Flags().String("float-image-id", "", "浮动图片 ID (必填)")
|
||||
updateFloatImageCmd.Flags().String("file", "", "用于替换浮动图片的本地图片路径,与 --src 不能同时使用")
|
||||
updateFloatImageCmd.Flags().String("src", "", "新的图片资源路径,通过 media-upload 获取的 resourceUrl")
|
||||
updateFloatImageCmd.Flags().String("range", "", "新的锚点单元格,A1 表示法")
|
||||
updateFloatImageCmd.Flags().Int("width", 0, "新的图片宽度,像素")
|
||||
|
||||
@@ -1,333 +0,0 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
const (
|
||||
floatImageCreateInputError = "--file 与 --src 必须且只能提供一个"
|
||||
floatImageUpdateInputError = "--file 与 --src 不能同时提供"
|
||||
floatImageUpdateFieldsError = "--file、--src、--range、--width、--height、--offset-x、--offset-y 至少必须提供一个"
|
||||
floatImagePlannedResource = "<resourceUrl-after-upload>"
|
||||
floatImageUploadTimeout = 5 * time.Minute
|
||||
)
|
||||
|
||||
type floatImageLocalFile struct {
|
||||
file *os.File
|
||||
path string
|
||||
name string
|
||||
mimeType string
|
||||
size int64
|
||||
}
|
||||
|
||||
type floatImageUploadInfo struct {
|
||||
uploadURL string
|
||||
resourceID string
|
||||
resourceURL string
|
||||
}
|
||||
|
||||
func validateFloatImageCreateInput(cmd *cobra.Command) (string, string, error) {
|
||||
filePath, _ := cmd.Flags().GetString("file")
|
||||
src, _ := cmd.Flags().GetString("src")
|
||||
if cmd.Flags().Changed("file") && strings.TrimSpace(filePath) == "" {
|
||||
return "", "", fmt.Errorf("--file 不能为空")
|
||||
}
|
||||
hasFile := strings.TrimSpace(filePath) != ""
|
||||
hasSrc := strings.TrimSpace(src) != ""
|
||||
if hasFile == hasSrc {
|
||||
return "", "", fmt.Errorf("%s", floatImageCreateInputError)
|
||||
}
|
||||
return filePath, src, nil
|
||||
}
|
||||
|
||||
func validateFloatImageUpdateInput(cmd *cobra.Command) (string, string, error) {
|
||||
filePath, _ := cmd.Flags().GetString("file")
|
||||
src, _ := cmd.Flags().GetString("src")
|
||||
if cmd.Flags().Changed("file") && cmd.Flags().Changed("src") {
|
||||
return "", "", fmt.Errorf("%s", floatImageUpdateInputError)
|
||||
}
|
||||
if cmd.Flags().Changed("file") && strings.TrimSpace(filePath) == "" {
|
||||
return "", "", fmt.Errorf("--file 不能为空")
|
||||
}
|
||||
return filePath, src, nil
|
||||
}
|
||||
|
||||
func runFloatImageFileMode(cmd *cobra.Command, toolName, filePath string, toolArgs map[string]any) error {
|
||||
local, err := openFloatImageLocalFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer local.file.Close()
|
||||
|
||||
if deps.Caller.DryRun() {
|
||||
return printFloatImageFileDryRun(toolName, toolArgs, local)
|
||||
}
|
||||
ctx := cmd.Context()
|
||||
if ctx == nil {
|
||||
ctx = context.Background()
|
||||
}
|
||||
|
||||
jsonMode := strings.EqualFold(strings.TrimSpace(deps.Caller.Format()), "json")
|
||||
if !jsonMode {
|
||||
deps.Out.PrintInfo(fmt.Sprintf("[1/3] 获取浮动图片上传凭证 (%s, %d bytes)...", local.name, local.size))
|
||||
}
|
||||
uploadInfo, err := resolveFloatImageUploadInfo(ctx, toolArgs["nodeId"], local)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !jsonMode {
|
||||
deps.Out.PrintKeyValue("resourceId", uploadInfo.resourceID)
|
||||
deps.Out.PrintKeyValue("resourceUrl", uploadInfo.resourceURL)
|
||||
deps.Out.PrintInfo("[2/3] 上传本地图片...")
|
||||
}
|
||||
client := newFloatImageUploadClient()
|
||||
if err := putFloatImageFileWithClient(ctx, client, uploadInfo.uploadURL, local); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !jsonMode {
|
||||
deps.Out.PrintInfo("[3/3] 提交浮动图片变更...")
|
||||
}
|
||||
toolArgs["src"] = uploadInfo.resourceURL
|
||||
if err := callMCPToolContext(ctx, toolName, toolArgs); err != nil {
|
||||
return fmt.Errorf("图片已上传(resourceId=%s,resourceUrl=%s),但浮动图片操作失败;已有重试可能造成重复创建或更新,请先用 list/get/UI 核验后再重试: %w", uploadInfo.resourceID, uploadInfo.resourceURL, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func openFloatImageLocalFile(path string) (*floatImageLocalFile, error) {
|
||||
return openFloatImageLocalFileWith(path, os.Stat, os.Open)
|
||||
}
|
||||
|
||||
func openFloatImageLocalFileWith(path string, stat func(string) (os.FileInfo, error), open func(string) (*os.File, error)) (*floatImageLocalFile, error) {
|
||||
info, err := stat(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无法读取 --file %q: %w", path, err)
|
||||
}
|
||||
if err := validateFloatImageFileInfo(info); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
file, err := open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无法打开 --file %q: %w", path, err)
|
||||
}
|
||||
openedInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
_ = file.Close()
|
||||
return nil, fmt.Errorf("无法读取已打开的 --file %q: %w", path, err)
|
||||
}
|
||||
if err := validateFloatImageFileInfo(openedInfo); err != nil {
|
||||
_ = file.Close()
|
||||
return nil, err
|
||||
}
|
||||
return &floatImageLocalFile{
|
||||
file: file,
|
||||
path: path,
|
||||
name: filepath.Base(path),
|
||||
mimeType: inferMimeType(filepath.Base(path)),
|
||||
size: openedInfo.Size(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func validateFloatImageFileInfo(info os.FileInfo) error {
|
||||
if !info.Mode().IsRegular() {
|
||||
return fmt.Errorf("--file 必须是普通文件")
|
||||
}
|
||||
if info.Size() <= 0 {
|
||||
return fmt.Errorf("--file 不能为空文件")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printFloatImageFileDryRun(toolName string, toolArgs map[string]any, local *floatImageLocalFile) error {
|
||||
arguments := make(map[string]any, len(toolArgs)+1)
|
||||
for key, value := range toolArgs {
|
||||
arguments[key] = value
|
||||
}
|
||||
arguments["src"] = floatImagePlannedResource
|
||||
stages := []string{"validate_local_file", "get_upload_credentials", "upload_file", toolName}
|
||||
if strings.EqualFold(strings.TrimSpace(deps.Caller.Format()), "json") {
|
||||
return deps.Out.PrintJSON(map[string]any{
|
||||
"dry_run": true,
|
||||
"executed": false,
|
||||
"tool": toolName,
|
||||
"arguments": arguments,
|
||||
"local_file": map[string]any{
|
||||
"path": local.path, "name": local.name, "mime_type": local.mimeType, "size": local.size,
|
||||
},
|
||||
"stages": stages,
|
||||
})
|
||||
}
|
||||
deps.Out.PrintKeyValue("操作", "上传本地图片并提交浮动图片变更")
|
||||
deps.Out.PrintKeyValue("文件", local.path)
|
||||
deps.Out.PrintKeyValue("名称", local.name)
|
||||
deps.Out.PrintKeyValue("类型", local.mimeType)
|
||||
deps.Out.PrintKeyValue("大小", fmt.Sprintf("%d bytes", local.size))
|
||||
deps.Out.PrintKeyValue("Tool", toolName)
|
||||
deps.Out.PrintKeyValue("阶段", strings.Join(stages, " -> "))
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveFloatImageUploadInfo(ctx context.Context, nodeID any, local *floatImageLocalFile) (floatImageUploadInfo, error) {
|
||||
result, err := deps.Caller.CallTool(ctx, "doc", "get_doc_attachment_upload_info", map[string]any{
|
||||
"nodeId": nodeID,
|
||||
"fileName": local.name,
|
||||
"fileSize": float64(local.size),
|
||||
"mimeType": local.mimeType,
|
||||
})
|
||||
if err != nil {
|
||||
return floatImageUploadInfo{}, WrapError(err)
|
||||
}
|
||||
return parseFloatImageUploadInfo(result)
|
||||
}
|
||||
|
||||
func parseFloatImageUploadInfo(result *edition.ToolResult) (floatImageUploadInfo, error) {
|
||||
if result == nil {
|
||||
return floatImageUploadInfo{}, invalidFloatImageCredentialError()
|
||||
}
|
||||
text := ""
|
||||
for _, content := range result.Content {
|
||||
if content.Type == "text" && strings.TrimSpace(content.Text) != "" {
|
||||
text = content.Text
|
||||
break
|
||||
}
|
||||
}
|
||||
if text == "" {
|
||||
return floatImageUploadInfo{}, invalidFloatImageCredentialError()
|
||||
}
|
||||
type credential struct {
|
||||
UploadURL string `json:"uploadUrl"`
|
||||
ResourceID string `json:"resourceId"`
|
||||
ResourceURL string `json:"resourceUrl"`
|
||||
}
|
||||
var envelope struct {
|
||||
credential
|
||||
Result *credential `json:"result"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(text), &envelope); err != nil {
|
||||
return floatImageUploadInfo{}, invalidFloatImageCredentialError()
|
||||
}
|
||||
parsed := envelope.credential
|
||||
if envelope.Result != nil {
|
||||
parsed = *envelope.Result
|
||||
}
|
||||
parsed.UploadURL = strings.TrimSpace(parsed.UploadURL)
|
||||
parsed.ResourceID = strings.TrimSpace(parsed.ResourceID)
|
||||
parsed.ResourceURL = strings.TrimSpace(parsed.ResourceURL)
|
||||
if parsed.UploadURL == "" || !validFloatImageResourceID(parsed.ResourceID) || !validFloatImageResourceURL(parsed.ResourceURL) {
|
||||
return floatImageUploadInfo{}, invalidFloatImageCredentialError()
|
||||
}
|
||||
if err := validateFloatImageUploadURL(parsed.UploadURL); err != nil {
|
||||
return floatImageUploadInfo{}, err
|
||||
}
|
||||
return floatImageUploadInfo{uploadURL: parsed.UploadURL, resourceID: parsed.ResourceID, resourceURL: parsed.ResourceURL}, nil
|
||||
}
|
||||
|
||||
func invalidFloatImageCredentialError() error {
|
||||
return &CLIError{
|
||||
Code: CodeMCPToolError,
|
||||
Message: "获取浮动图片上传凭证失败:响应格式无效",
|
||||
Suggestion: "请重试;若持续失败,请检查 doc/get_doc_attachment_upload_info 服务",
|
||||
Operation: "doc/get_doc_attachment_upload_info",
|
||||
}
|
||||
}
|
||||
|
||||
func validFloatImageResourceID(value string) bool {
|
||||
return value != "" && len(value) <= 4096 && strings.IndexFunc(value, unicode.IsControl) < 0
|
||||
}
|
||||
|
||||
func validFloatImageResourceURL(value string) bool {
|
||||
if value == "" || len(value) > 8192 || strings.IndexFunc(value, unicode.IsControl) >= 0 || !strings.HasPrefix(value, "/") || strings.HasPrefix(value, "//") {
|
||||
return false
|
||||
}
|
||||
parsed, err := url.Parse(value)
|
||||
return err == nil && parsed.Host == "" && parsed.RawQuery == "" && parsed.Fragment == ""
|
||||
}
|
||||
|
||||
// Keep this policy aligned with internal/transport.Client.isEndpointTrusted.
|
||||
// It stays Sheet-private in V1 so local-file float-image support does not
|
||||
// refactor the shared transport boundary selected by unrelated products.
|
||||
func validateFloatImageUploadURL(rawURL string) error {
|
||||
parsed, err := url.Parse(rawURL)
|
||||
if err != nil || !parsed.IsAbs() || parsed.Host == "" || parsed.User != nil || parsed.Fragment != "" {
|
||||
return invalidFloatImageUploadURLError()
|
||||
}
|
||||
if strings.EqualFold(parsed.Scheme, "https") {
|
||||
return nil
|
||||
}
|
||||
if !strings.EqualFold(parsed.Scheme, "http") || os.Getenv("DWS_ALLOW_HTTP_ENDPOINTS") != "1" || !isFloatImageLoopbackHost(parsed.Hostname()) {
|
||||
return invalidFloatImageUploadURLError()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isFloatImageLoopbackHost(host string) bool {
|
||||
return host == "localhost" || host == "127.0.0.1" || host == "::1"
|
||||
}
|
||||
|
||||
func invalidFloatImageUploadURLError() error {
|
||||
return &CLIError{
|
||||
Code: CodeInvalidParam,
|
||||
Message: "浮动图片上传地址无效或不受信任",
|
||||
Suggestion: "上传地址必须是 HTTPS;本地开发仅允许显式开启的 loopback HTTP",
|
||||
Operation: "sheet/float-image-upload",
|
||||
}
|
||||
}
|
||||
|
||||
func newFloatImageUploadClient() *http.Client {
|
||||
return &http.Client{
|
||||
Timeout: floatImageUploadTimeout,
|
||||
CheckRedirect: func(*http.Request, []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// This intentionally does not reuse doc.defaultHTTPPutFile or localio.PutFile:
|
||||
// both have incompatible retry/status/host behavior, and the Doc helper can
|
||||
// copy a signed URL or response body into errors. Keep this fixed-message PUT
|
||||
// until a shared secure-upload contract can replace all upload implementations.
|
||||
func putFloatImageFileWithClient(ctx context.Context, client *http.Client, rawURL string, local *floatImageLocalFile) error {
|
||||
if client == nil {
|
||||
return fmt.Errorf("浮动图片文件上传失败:HTTP 客户端不可用")
|
||||
}
|
||||
if _, err := local.file.Seek(0, io.SeekStart); err != nil {
|
||||
return fmt.Errorf("浮动图片文件上传失败:无法读取本地文件")
|
||||
}
|
||||
request, err := http.NewRequestWithContext(ctx, http.MethodPut, rawURL, local.file)
|
||||
if err != nil {
|
||||
return fmt.Errorf("浮动图片文件上传失败:无法创建请求")
|
||||
}
|
||||
request.ContentLength = local.size
|
||||
request.Header.Set("Content-Type", local.mimeType)
|
||||
response, err := client.Do(request)
|
||||
if err != nil {
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return fmt.Errorf("浮动图片文件上传已取消: %w", ctxErr)
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) || os.IsTimeout(err) {
|
||||
return fmt.Errorf("浮动图片文件上传失败:已超过传输时限")
|
||||
}
|
||||
return fmt.Errorf("浮动图片文件上传失败:网络请求失败")
|
||||
}
|
||||
defer response.Body.Close()
|
||||
_, _ = io.Copy(io.Discard, io.LimitReader(response.Body, 64<<10))
|
||||
if response.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("浮动图片文件上传失败:HTTP %d", response.StatusCode)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
//go:build darwin || linux || freebsd || openbsd || netbsd || dragonfly
|
||||
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageFIFORejectedBeforeOpen(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "image.fifo")
|
||||
if err := syscall.Mkfifo(path, 0o600); err != nil {
|
||||
t.Fatalf("mkfifo: %v", err)
|
||||
}
|
||||
if _, err := openFloatImageLocalFile(path); err == nil || !strings.Contains(err.Error(), "普通文件") {
|
||||
t.Fatalf("FIFO error = %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1,695 +0,0 @@
|
||||
package helpers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/testseam"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type floatImageToolCall struct {
|
||||
product string
|
||||
tool string
|
||||
args map[string]any
|
||||
}
|
||||
|
||||
type floatImageTestCaller struct {
|
||||
dryRun bool
|
||||
format string
|
||||
calls []floatImageToolCall
|
||||
call func(context.Context, string, string, map[string]any, int) (*edition.ToolResult, error)
|
||||
}
|
||||
|
||||
func (c *floatImageTestCaller) CallTool(ctx context.Context, product, tool string, args map[string]any) (*edition.ToolResult, error) {
|
||||
copyArgs := make(map[string]any, len(args))
|
||||
for key, value := range args {
|
||||
copyArgs[key] = value
|
||||
}
|
||||
index := len(c.calls)
|
||||
c.calls = append(c.calls, floatImageToolCall{product: product, tool: tool, args: copyArgs})
|
||||
if c.call != nil {
|
||||
return c.call(ctx, product, tool, args, index)
|
||||
}
|
||||
return floatImageTextResult(`{"floatImage":{"id":"fi-1"}}`), nil
|
||||
}
|
||||
|
||||
func (c *floatImageTestCaller) Format() string {
|
||||
if c.format == "" {
|
||||
return "json"
|
||||
}
|
||||
return c.format
|
||||
}
|
||||
|
||||
func (c *floatImageTestCaller) DryRun() bool { return c.dryRun }
|
||||
func (*floatImageTestCaller) Fields() string { return "" }
|
||||
func (*floatImageTestCaller) JQ() string { return "" }
|
||||
|
||||
type floatImageRoundTripFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
func (fn floatImageRoundTripFunc) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||
return fn(request)
|
||||
}
|
||||
|
||||
func floatImageTextResult(text string) *edition.ToolResult {
|
||||
return &edition.ToolResult{Content: []edition.ContentBlock{{Type: "text", Text: text}}}
|
||||
}
|
||||
|
||||
func floatImageCredentialResult(uploadURL string, nested bool) *edition.ToolResult {
|
||||
credential := map[string]any{
|
||||
"uploadUrl": uploadURL, "resourceId": "rid-1", "resourceUrl": "/core/api/resources/img/rid-1",
|
||||
}
|
||||
payload := any(credential)
|
||||
if nested {
|
||||
payload = map[string]any{"result": credential}
|
||||
}
|
||||
raw, _ := json.Marshal(payload)
|
||||
return floatImageTextResult(string(raw))
|
||||
}
|
||||
|
||||
func floatImageCommandForTest(t *testing.T, name string) *cobra.Command {
|
||||
t.Helper()
|
||||
for _, command := range newFloatImageCmds() {
|
||||
if command.Name() == name {
|
||||
return command
|
||||
}
|
||||
}
|
||||
t.Fatalf("missing float-image command %s", name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func setFloatImageFlags(t *testing.T, command *cobra.Command, values map[string]string) {
|
||||
t.Helper()
|
||||
for name, value := range values {
|
||||
if err := command.Flags().Set(name, value); err != nil {
|
||||
t.Fatalf("set --%s: %v", name, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func installFloatImageDeps(t *testing.T, caller *floatImageTestCaller, output io.Writer) {
|
||||
t.Helper()
|
||||
if output == nil {
|
||||
output = io.Discard
|
||||
}
|
||||
testseam.Swap(t, &deps, &Deps{Caller: caller, Out: NewFormatterWithWriters(output, io.Discard)})
|
||||
previousArgs := os.Args
|
||||
os.Args = []string{"dws", "sheet"}
|
||||
t.Cleanup(func() { os.Args = previousArgs })
|
||||
}
|
||||
|
||||
func writeFloatImageFixture(t *testing.T, name, content string) string {
|
||||
t.Helper()
|
||||
path := filepath.Join(t.TempDir(), name)
|
||||
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
||||
t.Fatalf("write fixture: %v", err)
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func openFloatImageFixture(t *testing.T, path string) *floatImageLocalFile {
|
||||
t.Helper()
|
||||
local, err := openFloatImageLocalFile(path)
|
||||
if err != nil {
|
||||
t.Fatalf("open fixture: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = local.file.Close() })
|
||||
return local
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageInputValidation(t *testing.T) {
|
||||
create := floatImageCommandForTest(t, "create-float-image")
|
||||
if _, _, err := validateFloatImageCreateInput(create); err == nil || !strings.Contains(err.Error(), floatImageCreateInputError) {
|
||||
t.Fatalf("missing create input error = %v", err)
|
||||
}
|
||||
setFloatImageFlags(t, create, map[string]string{"file": "a.png", "src": "/img/a"})
|
||||
if _, _, err := validateFloatImageCreateInput(create); err == nil || !strings.Contains(err.Error(), floatImageCreateInputError) {
|
||||
t.Fatalf("conflicting create input error = %v", err)
|
||||
}
|
||||
createEmptyFile := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, createEmptyFile, map[string]string{"file": " ", "src": "/img/a"})
|
||||
if _, _, err := validateFloatImageCreateInput(createEmptyFile); err == nil || !strings.Contains(err.Error(), "--file 不能为空") {
|
||||
t.Fatalf("empty create file error = %v", err)
|
||||
}
|
||||
|
||||
fileOnly := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, fileOnly, map[string]string{"file": " a.png "})
|
||||
if file, src, err := validateFloatImageCreateInput(fileOnly); err != nil || file != " a.png " || src != "" {
|
||||
t.Fatalf("file-only input = %q/%q/%v", file, src, err)
|
||||
}
|
||||
srcOnly := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, srcOnly, map[string]string{"src": " /img/a "})
|
||||
if file, src, err := validateFloatImageCreateInput(srcOnly); err != nil || file != "" || src != " /img/a " {
|
||||
t.Fatalf("src-only input = %q/%q/%v", file, src, err)
|
||||
}
|
||||
|
||||
updateBoth := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, updateBoth, map[string]string{"file": "a.png", "src": "/img/a"})
|
||||
if _, _, err := validateFloatImageUpdateInput(updateBoth); err == nil || !strings.Contains(err.Error(), floatImageUpdateInputError) {
|
||||
t.Fatalf("conflicting update input error = %v", err)
|
||||
}
|
||||
updateEmptyFile := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, updateEmptyFile, map[string]string{"file": " "})
|
||||
if _, _, err := validateFloatImageUpdateInput(updateEmptyFile); err == nil || !strings.Contains(err.Error(), "--file 不能为空") {
|
||||
t.Fatalf("empty update file error = %v", err)
|
||||
}
|
||||
updateSrc := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, updateSrc, map[string]string{"src": ""})
|
||||
if file, src, err := validateFloatImageUpdateInput(updateSrc); err != nil || file != "" || src != "" {
|
||||
t.Fatalf("src update compatibility = %q/%q/%v", file, src, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageLocalFileValidation(t *testing.T) {
|
||||
validPath := writeFloatImageFixture(t, "chart.png", "png-data")
|
||||
local, err := openFloatImageLocalFile(validPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.name != "chart.png" || local.mimeType != "image/png" || local.size != int64(len("png-data")) {
|
||||
t.Fatalf("local metadata = %#v", local)
|
||||
}
|
||||
_ = local.file.Close()
|
||||
|
||||
if _, err := openFloatImageLocalFile(filepath.Join(t.TempDir(), "missing.png")); err == nil || !strings.Contains(err.Error(), "无法读取") {
|
||||
t.Fatalf("missing file error = %v", err)
|
||||
}
|
||||
if _, err := openFloatImageLocalFile(t.TempDir()); err == nil || !strings.Contains(err.Error(), "普通文件") {
|
||||
t.Fatalf("directory error = %v", err)
|
||||
}
|
||||
emptyPath := writeFloatImageFixture(t, "empty.png", "")
|
||||
if _, err := openFloatImageLocalFile(emptyPath); err == nil || !strings.Contains(err.Error(), "不能为空文件") {
|
||||
t.Fatalf("empty error = %v", err)
|
||||
}
|
||||
|
||||
validInfo, err := os.Stat(validPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
statValid := func(string) (os.FileInfo, error) { return validInfo, nil }
|
||||
openFailure := errors.New("open sentinel")
|
||||
if _, err := openFloatImageLocalFileWith(validPath, statValid, func(string) (*os.File, error) { return nil, openFailure }); !errors.Is(err, openFailure) {
|
||||
t.Fatalf("open error = %v", err)
|
||||
}
|
||||
closed, err := os.Open(validPath)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_ = closed.Close()
|
||||
if _, err := openFloatImageLocalFileWith(validPath, statValid, func(string) (*os.File, error) { return closed, nil }); err == nil || !strings.Contains(err.Error(), "已打开") {
|
||||
t.Fatalf("opened stat error = %v", err)
|
||||
}
|
||||
if _, err := openFloatImageLocalFileWith(validPath, statValid, func(string) (*os.File, error) { return os.Open(t.TempDir()) }); err == nil || !strings.Contains(err.Error(), "普通文件") {
|
||||
t.Fatalf("descriptor type error = %v", err)
|
||||
}
|
||||
if _, err := openFloatImageLocalFileWith(validPath, statValid, func(string) (*os.File, error) { return os.Open(emptyPath) }); err == nil || !strings.Contains(err.Error(), "不能为空文件") {
|
||||
t.Fatalf("descriptor size error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageCredentialParsingAndURLPolicy(t *testing.T) {
|
||||
invalidResults := []*edition.ToolResult{
|
||||
nil,
|
||||
{},
|
||||
{Content: []edition.ContentBlock{{Type: "image", Text: "credential-secret"}}},
|
||||
floatImageTextResult("{"),
|
||||
floatImageTextResult(`{"uploadUrl":"https://upload.invalid/signed-secret","resourceId":"rid"}`),
|
||||
floatImageTextResult(`{"uploadUrl":"https://upload.invalid/signed-secret","resourceId":"bad\nvalue","resourceUrl":"/core/api/resources/img/rid"}`),
|
||||
floatImageTextResult(`{"uploadUrl":"https://upload.invalid/signed-secret","resourceId":"rid","resourceUrl":"https://resource.invalid/rid"}`),
|
||||
floatImageTextResult(`{"uploadUrl":"http://example.com/signed-secret","resourceId":"rid","resourceUrl":"/core/api/resources/img/rid"}`),
|
||||
}
|
||||
t.Setenv("DWS_ALLOW_HTTP_ENDPOINTS", "")
|
||||
for index, result := range invalidResults {
|
||||
_, err := parseFloatImageUploadInfo(result)
|
||||
if err == nil {
|
||||
t.Fatalf("invalid result %d succeeded", index)
|
||||
}
|
||||
if strings.Contains(err.Error(), "signed-secret") || strings.Contains(err.Error(), "credential-secret") {
|
||||
t.Fatalf("invalid result %d leaked secret: %v", index, err)
|
||||
}
|
||||
}
|
||||
|
||||
top := floatImageTextResult(`{"uploadUrl":"https://upload.invalid/path?signature=secret","resourceId":"rid-top","resourceUrl":"/core/api/resources/img/top"}`)
|
||||
info, err := parseFloatImageUploadInfo(top)
|
||||
if err != nil || info.resourceID != "rid-top" || info.resourceURL != "/core/api/resources/img/top" {
|
||||
t.Fatalf("top-level credential = %#v, %v", info, err)
|
||||
}
|
||||
nested := &edition.ToolResult{Content: []edition.ContentBlock{
|
||||
{Type: "text", Text: " "},
|
||||
{Type: "image", Text: "ignored"},
|
||||
{Type: "text", Text: `{"result":{"uploadUrl":"https://upload.invalid/nested","resourceId":"rid-nested","resourceUrl":"/core/api/resources/img/nested"}}`},
|
||||
}}
|
||||
info, err = parseFloatImageUploadInfo(nested)
|
||||
if err != nil || info.resourceID != "rid-nested" {
|
||||
t.Fatalf("nested credential = %#v, %v", info, err)
|
||||
}
|
||||
|
||||
for _, value := range []string{"", "//host/path", "/path?secret=x", "/path#fragment", "/bad\npath"} {
|
||||
if validFloatImageResourceURL(value) {
|
||||
t.Errorf("resource URL %q unexpectedly valid", value)
|
||||
}
|
||||
}
|
||||
if !validFloatImageResourceURL("/core/api/resources/img/ok") || validFloatImageResourceID("") || validFloatImageResourceID("bad\x1bvalue") {
|
||||
t.Fatal("resource identifier validation mismatch")
|
||||
}
|
||||
|
||||
for _, rawURL := range []string{"not a URL", "/relative", "https://user:pass@example.com/path", "https://example.com/path#fragment", "ftp://example.com/path", "http://example.com/path"} {
|
||||
if err := validateFloatImageUploadURL(rawURL); err == nil {
|
||||
t.Errorf("upload URL %q unexpectedly valid", rawURL)
|
||||
}
|
||||
}
|
||||
if err := validateFloatImageUploadURL("https://example.com/path?signature=secret"); err != nil {
|
||||
t.Fatalf("HTTPS URL rejected: %v", err)
|
||||
}
|
||||
t.Setenv("DWS_ALLOW_HTTP_ENDPOINTS", "1")
|
||||
for _, rawURL := range []string{"http://localhost/path", "http://127.0.0.1/path", "http://[::1]/path"} {
|
||||
if err := validateFloatImageUploadURL(rawURL); err != nil {
|
||||
t.Errorf("loopback URL %q rejected: %v", rawURL, err)
|
||||
}
|
||||
}
|
||||
if err := validateFloatImageUploadURL("http://192.0.2.1/path"); err == nil || isFloatImageLoopbackHost("not-an-ip") || isFloatImageLoopbackHost("127.0.0.2") {
|
||||
t.Fatalf("non-loopback policy mismatch: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageHTTPPut(t *testing.T) {
|
||||
path := writeFloatImageFixture(t, "chart.png", "streamed-image")
|
||||
|
||||
t.Run("nil client", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
if err := putFloatImageFileWithClient(context.Background(), nil, "https://upload.invalid", local); err == nil {
|
||||
t.Fatal("nil client succeeded")
|
||||
}
|
||||
})
|
||||
t.Run("closed file", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
_ = local.file.Close()
|
||||
if err := putFloatImageFileWithClient(context.Background(), http.DefaultClient, "https://upload.invalid", local); err == nil || !strings.Contains(err.Error(), "无法读取本地文件") {
|
||||
t.Fatalf("closed file error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("invalid request", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
if err := putFloatImageFileWithClient(context.Background(), http.DefaultClient, ":", local); err == nil || !strings.Contains(err.Error(), "无法创建请求") {
|
||||
t.Fatalf("request error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("transport secret redacted", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
client := &http.Client{Transport: floatImageRoundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
return nil, errors.New("transport signed-secret https://upload.invalid")
|
||||
})}
|
||||
err := putFloatImageFileWithClient(context.Background(), client, "https://upload.invalid/signed-secret", local)
|
||||
if err == nil || strings.Contains(err.Error(), "signed-secret") || !strings.Contains(err.Error(), "网络请求失败") {
|
||||
t.Fatalf("transport error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("cancel", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
client := &http.Client{Transport: floatImageRoundTripFunc(func(request *http.Request) (*http.Response, error) {
|
||||
return nil, request.Context().Err()
|
||||
})}
|
||||
err := putFloatImageFileWithClient(ctx, client, "https://upload.invalid/path", local)
|
||||
if !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("cancel error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("client deadline", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
client := &http.Client{Transport: floatImageRoundTripFunc(func(*http.Request) (*http.Response, error) {
|
||||
return nil, context.DeadlineExceeded
|
||||
})}
|
||||
err := putFloatImageFileWithClient(context.Background(), client, "https://upload.invalid/path", local)
|
||||
if err == nil || !strings.Contains(err.Error(), "超过传输时限") {
|
||||
t.Fatalf("deadline error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("non-200 body redacted", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) {
|
||||
response.WriteHeader(http.StatusForbidden)
|
||||
_, _ = io.WriteString(response, "response-body-secret")
|
||||
}))
|
||||
defer server.Close()
|
||||
err := putFloatImageFileWithClient(context.Background(), server.Client(), server.URL+"/signed-secret", local)
|
||||
if err == nil || !strings.Contains(err.Error(), "HTTP 403") || strings.Contains(err.Error(), "response-body-secret") || strings.Contains(err.Error(), "signed-secret") {
|
||||
t.Fatalf("status error = %v", err)
|
||||
}
|
||||
})
|
||||
t.Run("stream success", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
var method, contentType, body string
|
||||
var contentLength int64
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
method = request.Method
|
||||
contentType = request.Header.Get("Content-Type")
|
||||
contentLength = request.ContentLength
|
||||
raw, _ := io.ReadAll(request.Body)
|
||||
body = string(raw)
|
||||
response.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
if err := putFloatImageFileWithClient(context.Background(), server.Client(), server.URL, local); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if method != http.MethodPut || contentType != "image/png" || contentLength != int64(len("streamed-image")) || body != "streamed-image" {
|
||||
t.Fatalf("request = %s %s %d %q", method, contentType, contentLength, body)
|
||||
}
|
||||
})
|
||||
t.Run("redirect not followed", func(t *testing.T) {
|
||||
local := openFloatImageFixture(t, path)
|
||||
destinationCalls := 0
|
||||
destination := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) { destinationCalls++ }))
|
||||
defer destination.Close()
|
||||
source := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) {
|
||||
response.Header().Set("Location", destination.URL+"/location-secret")
|
||||
response.WriteHeader(http.StatusFound)
|
||||
}))
|
||||
defer source.Close()
|
||||
client := newFloatImageUploadClient()
|
||||
if client.Timeout != floatImageUploadTimeout {
|
||||
t.Fatalf("timeout = %v", client.Timeout)
|
||||
}
|
||||
err := putFloatImageFileWithClient(context.Background(), client, source.URL, local)
|
||||
if err == nil || !strings.Contains(err.Error(), "HTTP 302") || strings.Contains(err.Error(), "location-secret") || destinationCalls != 0 {
|
||||
t.Fatalf("redirect error/calls = %v/%d", err, destinationCalls)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageDryRun(t *testing.T) {
|
||||
path := writeFloatImageFixture(t, "chart.png", "image")
|
||||
for _, format := range []string{"json", "table"} {
|
||||
t.Run(format, func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{dryRun: true, format: format}
|
||||
var output bytes.Buffer
|
||||
installFloatImageDeps(t, caller, &output)
|
||||
command := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{
|
||||
"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80",
|
||||
})
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("dry-run remote calls = %d", len(caller.calls))
|
||||
}
|
||||
if format == "json" {
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(output.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("decode dry-run: %v; output=%s", err, output.String())
|
||||
}
|
||||
arguments, _ := payload["arguments"].(map[string]any)
|
||||
if payload["tool"] != "create_float_image" || arguments["src"] != floatImagePlannedResource || payload["dry_run"] != true || payload["executed"] != false {
|
||||
t.Fatalf("dry-run payload = %#v", payload)
|
||||
}
|
||||
if _, exists := payload["preview_kind"]; exists {
|
||||
t.Fatalf("request preview unexpectedly declares preview_kind: %#v", payload)
|
||||
}
|
||||
} else if !strings.Contains(output.String(), "validate_local_file -> get_upload_credentials -> upload_file -> create_float_image") {
|
||||
t.Fatalf("pretty dry-run = %s", output.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
for _, format := range []string{"json", "table"} {
|
||||
t.Run("update-"+format, func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{dryRun: true, format: format}
|
||||
var output bytes.Buffer
|
||||
installFloatImageDeps(t, caller, &output)
|
||||
command := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{
|
||||
"node": "node-1", "sheet-id": "sheet-1", "float-image-id": "fi-1", "file": path, "width": "120",
|
||||
})
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("update dry-run remote calls = %d", len(caller.calls))
|
||||
}
|
||||
if format == "json" {
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(output.Bytes(), &payload); err != nil {
|
||||
t.Fatalf("decode update dry-run: %v; output=%s", err, output.String())
|
||||
}
|
||||
arguments, _ := payload["arguments"].(map[string]any)
|
||||
if payload["tool"] != "update_float_image" || arguments["src"] != floatImagePlannedResource || arguments["floatImageId"] != "fi-1" || payload["dry_run"] != true || payload["executed"] != false {
|
||||
t.Fatalf("update dry-run payload = %#v", payload)
|
||||
}
|
||||
} else if !strings.Contains(output.String(), "validate_local_file -> get_upload_credentials -> upload_file -> update_float_image") {
|
||||
t.Fatalf("update pretty dry-run = %s", output.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageCommandWorkflows(t *testing.T) {
|
||||
path := writeFloatImageFixture(t, "chart.png", "command-image")
|
||||
t.Setenv("DWS_ALLOW_HTTP_ENDPOINTS", "1")
|
||||
|
||||
t.Run("create src", func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
command := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{
|
||||
"node": "node-1", "sheet-id": "sheet-1", "src": "/core/api/resources/img/existing", "range": "A1", "width": "100", "height": "80",
|
||||
})
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 1 || caller.calls[0].product != "sheet" || caller.calls[0].tool != "create_float_image" || caller.calls[0].args["src"] != "/core/api/resources/img/existing" {
|
||||
t.Fatalf("src calls = %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("create and update file", func(t *testing.T) {
|
||||
var uploadBodies []string
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, request *http.Request) {
|
||||
raw, _ := io.ReadAll(request.Body)
|
||||
uploadBodies = append(uploadBodies, string(raw))
|
||||
response.WriteHeader(http.StatusOK)
|
||||
}))
|
||||
defer server.Close()
|
||||
for _, commandName := range []string{"create-float-image", "update-float-image"} {
|
||||
t.Run(commandName, func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{call: func(_ context.Context, product, tool string, _ map[string]any, index int) (*edition.ToolResult, error) {
|
||||
if index == 0 {
|
||||
if product != "doc" || tool != "get_doc_attachment_upload_info" {
|
||||
t.Fatalf("credential route = %s/%s", product, tool)
|
||||
}
|
||||
return floatImageCredentialResult(server.URL+"/signed-secret", commandName == "update-float-image"), nil
|
||||
}
|
||||
return floatImageTextResult(`{"floatImage":{"id":"fi-ok"}}`), nil
|
||||
}}
|
||||
var output bytes.Buffer
|
||||
installFloatImageDeps(t, caller, &output)
|
||||
command := floatImageCommandForTest(t, commandName)
|
||||
flags := map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path}
|
||||
if commandName == "create-float-image" {
|
||||
flags["range"], flags["width"], flags["height"] = "A1", "100", "80"
|
||||
} else {
|
||||
flags["float-image-id"], flags["width"] = "fi-1", "120"
|
||||
}
|
||||
setFloatImageFlags(t, command, flags)
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 2 || caller.calls[1].product != "sheet" || caller.calls[1].tool != strings.ReplaceAll(commandName, "-", "_") {
|
||||
t.Fatalf("workflow calls = %#v", caller.calls)
|
||||
}
|
||||
if caller.calls[0].args["fileName"] != "chart.png" || caller.calls[0].args["mimeType"] != "image/png" || caller.calls[1].args["src"] != "/core/api/resources/img/rid-1" {
|
||||
t.Fatalf("workflow args = %#v", caller.calls)
|
||||
}
|
||||
var payload map[string]any
|
||||
if err := json.Unmarshal(output.Bytes(), &payload); err != nil || payload["floatImage"] == nil {
|
||||
t.Fatalf("final output = %s, %v", output.String(), err)
|
||||
}
|
||||
})
|
||||
}
|
||||
if len(uploadBodies) != 2 || uploadBodies[0] != "command-image" || uploadBodies[1] != "command-image" {
|
||||
t.Fatalf("upload bodies = %#v", uploadBodies)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("pretty progress", func(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) { response.WriteHeader(http.StatusOK) }))
|
||||
defer server.Close()
|
||||
caller := &floatImageTestCaller{format: "table", call: func(_ context.Context, _, _ string, _ map[string]any, index int) (*edition.ToolResult, error) {
|
||||
if index == 0 {
|
||||
return floatImageCredentialResult(server.URL, false), nil
|
||||
}
|
||||
return floatImageTextResult(`{"floatImage":{"id":"fi-pretty"}}`), nil
|
||||
}}
|
||||
var output bytes.Buffer
|
||||
installFloatImageDeps(t, caller, &output)
|
||||
command := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80"})
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, marker := range []string{"[1/3]", "resourceId", "[2/3]", "[3/3]"} {
|
||||
if !strings.Contains(output.String(), marker) {
|
||||
t.Fatalf("pretty output missing %q: %s", marker, output.String())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("validation and local error", func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
create := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, create, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "range": "A1", "width": "100", "height": "80"})
|
||||
if err := create.RunE(create, nil); err == nil || !strings.Contains(err.Error(), floatImageCreateInputError) {
|
||||
t.Fatalf("create validation = %v", err)
|
||||
}
|
||||
missing := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, missing, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": filepath.Join(t.TempDir(), "missing.png"), "range": "A1", "width": "100", "height": "80"})
|
||||
if err := missing.RunE(missing, nil); err == nil || !strings.Contains(err.Error(), "无法读取") {
|
||||
t.Fatalf("local error = %v", err)
|
||||
}
|
||||
update := floatImageCommandForTest(t, "update-float-image")
|
||||
if err := update.RunE(update, nil); err == nil || !strings.Contains(err.Error(), floatImageUpdateFieldsError) {
|
||||
t.Fatalf("update fields error = %v", err)
|
||||
}
|
||||
conflict := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, conflict, map[string]string{"file": path, "src": "/img/a"})
|
||||
if err := conflict.RunE(conflict, nil); err == nil || !strings.Contains(err.Error(), floatImageUpdateInputError) {
|
||||
t.Fatalf("update conflict = %v", err)
|
||||
}
|
||||
missingIdentity := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, missingIdentity, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path})
|
||||
if err := missingIdentity.RunE(missingIdentity, nil); err == nil || !strings.Contains(err.Error(), "float-image-id") || len(caller.calls) != 0 {
|
||||
t.Fatalf("update identity error/calls = %v/%d", err, len(caller.calls))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("credential and put failures", func(t *testing.T) {
|
||||
credentialCause := errors.New("credential transport")
|
||||
caller := &floatImageTestCaller{call: func(context.Context, string, string, map[string]any, int) (*edition.ToolResult, error) {
|
||||
return nil, credentialCause
|
||||
}}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
command := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80"})
|
||||
if err := command.RunE(command, nil); !errors.Is(err, credentialCause) {
|
||||
t.Fatalf("credential error = %v", err)
|
||||
}
|
||||
|
||||
secret := "credential-response-secret"
|
||||
malformed := &floatImageTestCaller{call: func(context.Context, string, string, map[string]any, int) (*edition.ToolResult, error) {
|
||||
return floatImageTextResult(secret), nil
|
||||
}}
|
||||
installFloatImageDeps(t, malformed, io.Discard)
|
||||
command = floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80"})
|
||||
if err := command.RunE(command, nil); err == nil || strings.Contains(err.Error(), secret) {
|
||||
t.Fatalf("malformed credential error = %v", err)
|
||||
}
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) {
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
_, _ = io.WriteString(response, "put-body-secret")
|
||||
}))
|
||||
defer server.Close()
|
||||
putCaller := &floatImageTestCaller{call: func(context.Context, string, string, map[string]any, int) (*edition.ToolResult, error) {
|
||||
return floatImageCredentialResult(server.URL+"/signed-secret", false), nil
|
||||
}}
|
||||
installFloatImageDeps(t, putCaller, io.Discard)
|
||||
command = floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80"})
|
||||
if err := command.RunE(command, nil); err == nil || len(putCaller.calls) != 1 || strings.Contains(err.Error(), "put-body-secret") || strings.Contains(err.Error(), "signed-secret") {
|
||||
t.Fatalf("put error/calls = %v/%d", err, len(putCaller.calls))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("partial final failure", func(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(response http.ResponseWriter, _ *http.Request) { response.WriteHeader(http.StatusOK) }))
|
||||
defer server.Close()
|
||||
finalCause := errors.New("final operation sentinel")
|
||||
caller := &floatImageTestCaller{call: func(_ context.Context, _, _ string, _ map[string]any, index int) (*edition.ToolResult, error) {
|
||||
if index == 0 {
|
||||
return floatImageCredentialResult(server.URL+"/signed-secret", false), nil
|
||||
}
|
||||
return nil, finalCause
|
||||
}}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
command := floatImageCommandForTest(t, "create-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "file": path, "range": "A1", "width": "100", "height": "80"})
|
||||
err := command.RunE(command, nil)
|
||||
if !errors.Is(err, finalCause) || !strings.Contains(err.Error(), "resourceId=rid-1") || !strings.Contains(err.Error(), "list/get/UI") || strings.Contains(err.Error(), "signed-secret") {
|
||||
t.Fatalf("partial failure = %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update move only", func(t *testing.T) {
|
||||
caller := &floatImageTestCaller{}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
command := floatImageCommandForTest(t, "update-float-image")
|
||||
setFloatImageFlags(t, command, map[string]string{"node": "node-1", "sheet-id": "sheet-1", "float-image-id": "fi-1", "range": "C5"})
|
||||
if err := command.RunE(command, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 1 || caller.calls[0].args["range"] != "C5" {
|
||||
t.Fatalf("move-only calls = %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageResolveFloatImageUploadInfo(t *testing.T) {
|
||||
path := writeFloatImageFixture(t, "chart.webp", "webp")
|
||||
local := openFloatImageFixture(t, path)
|
||||
caller := &floatImageTestCaller{call: func(ctx context.Context, product, tool string, args map[string]any, _ int) (*edition.ToolResult, error) {
|
||||
if ctx == nil || product != "doc" || tool != "get_doc_attachment_upload_info" {
|
||||
t.Fatalf("route/context = %s/%s/%v", product, tool, ctx)
|
||||
}
|
||||
if args["nodeId"] != "node-1" || args["fileName"] != "chart.webp" || args["mimeType"] != "image/webp" || args["fileSize"] != float64(4) {
|
||||
t.Fatalf("credential args = %#v", args)
|
||||
}
|
||||
return floatImageCredentialResult("https://upload.invalid/path", false), nil
|
||||
}}
|
||||
installFloatImageDeps(t, caller, io.Discard)
|
||||
info, err := resolveFloatImageUploadInfo(context.Background(), "node-1", local)
|
||||
if err != nil || info.resourceID != "rid-1" {
|
||||
t.Fatalf("resolve info = %#v/%v", info, err)
|
||||
}
|
||||
|
||||
cause := fmt.Errorf("timeout synthetic")
|
||||
caller.call = func(context.Context, string, string, map[string]any, int) (*edition.ToolResult, error) {
|
||||
return nil, cause
|
||||
}
|
||||
if _, err := resolveFloatImageUploadInfo(context.Background(), "node-1", local); !errors.Is(err, cause) {
|
||||
t.Fatalf("resolve error = %v", err)
|
||||
}
|
||||
|
||||
cancelled, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
caller.call = func(ctx context.Context, _ string, _ string, _ map[string]any, _ int) (*edition.ToolResult, error) {
|
||||
if !errors.Is(ctx.Err(), context.Canceled) {
|
||||
t.Fatalf("credential context error = %v", ctx.Err())
|
||||
}
|
||||
return nil, ctx.Err()
|
||||
}
|
||||
if _, err := resolveFloatImageUploadInfo(cancelled, "node-1", local); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("cancelled credential error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageFloatImageUploadDeadlineDocumented(t *testing.T) {
|
||||
client := newFloatImageUploadClient()
|
||||
if client.Timeout != 5*time.Minute || client.CheckRedirect == nil {
|
||||
t.Fatalf("upload client = %#v", client)
|
||||
}
|
||||
}
|
||||
+18
-64
@@ -96,10 +96,7 @@ func newTodoCommand() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
executorsStr := mustGetFlag(cmd, "executors")
|
||||
executorIds, err := parseRequiredTodoIDs("executors", executorsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
executorIds := parseExecutorIds(executorsStr)
|
||||
toolArgs := map[string]any{
|
||||
"PersonalTodoCreateVO": map[string]any{
|
||||
"subject": flagOrFallback(cmd, "title", "subject", "content"),
|
||||
@@ -114,11 +111,9 @@ func newTodoCommand() *cobra.Command {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["dueTime"] = ms
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("priority"); v != "" {
|
||||
n, err := parseTodoPriority(v)
|
||||
if err != nil {
|
||||
return err
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["priority"] = n
|
||||
}
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["priority"] = n
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("recurrence"); v != "" {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["recurrence"] = v
|
||||
@@ -159,7 +154,7 @@ func newTodoCommand() *cobra.Command {
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "due", Property: "PersonalTodoCreateVO.dueTime"},
|
||||
{Name: "executors", Property: "PersonalTodoCreateVO.executorIds", Description: "执行者 userId 列表;逗号分隔,解析后至少包含一个非空值"},
|
||||
{Name: "executors", Property: "PersonalTodoCreateVO.executorIds"},
|
||||
{Name: "priority", Property: "PersonalTodoCreateVO.priority"},
|
||||
{Name: "recurrence", Property: "PersonalTodoCreateVO.recurrence"},
|
||||
{Name: "title", Property: "PersonalTodoCreateVO.subject"},
|
||||
@@ -195,10 +190,7 @@ func newTodoCommand() *cobra.Command {
|
||||
}
|
||||
}
|
||||
executorsStr := mustGetFlag(cmd, "executors")
|
||||
executorIds, err := parseRequiredTodoIDs("executors", executorsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
executorIds := parseExecutorIds(executorsStr)
|
||||
toolArgs := map[string]any{
|
||||
"PersonalTodoCreateVO": map[string]any{
|
||||
"subject": flagOrFallback(cmd, "title", "subject", "content"),
|
||||
@@ -214,11 +206,9 @@ func newTodoCommand() *cobra.Command {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["dueTime"] = ms
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("priority"); v != "" {
|
||||
n, err := parseTodoPriority(v)
|
||||
if err != nil {
|
||||
return err
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["priority"] = n
|
||||
}
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["priority"] = n
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("recurrence"); v != "" {
|
||||
toolArgs["PersonalTodoCreateVO"].(map[string]any)["recurrence"] = v
|
||||
@@ -259,7 +249,7 @@ func newTodoCommand() *cobra.Command {
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "due", Property: "PersonalTodoCreateVO.dueTime"},
|
||||
{Name: "executors", Property: "PersonalTodoCreateVO.executorIds", Description: "执行者 userId 列表;逗号分隔,解析后至少包含一个非空值"},
|
||||
{Name: "executors", Property: "PersonalTodoCreateVO.executorIds"},
|
||||
{Name: "parent-id", Property: "PersonalTodoCreateVO.parentId"},
|
||||
{Name: "priority", Property: "PersonalTodoCreateVO.priority"},
|
||||
{Name: "recurrence", Property: "PersonalTodoCreateVO.recurrence"},
|
||||
@@ -386,11 +376,9 @@ func newTodoCommand() *cobra.Command {
|
||||
inner["dueTime"] = ms
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("priority"); v != "" {
|
||||
n, err := parseTodoPriority(v)
|
||||
if err != nil {
|
||||
return err
|
||||
if n, err := strconv.Atoi(v); err == nil {
|
||||
inner["priority"] = n
|
||||
}
|
||||
inner["priority"] = n
|
||||
}
|
||||
if v, _ := cmd.Flags().GetString("done"); v != "" {
|
||||
inner["isDone"] = v == "true"
|
||||
@@ -642,10 +630,7 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
return err
|
||||
}
|
||||
executorsStr := mustGetFlag(cmd, "executors")
|
||||
executorIds, err := parseRequiredTodoIDs("executors", executorsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
executorIds := parseExecutorIds(executorsStr)
|
||||
return callMCPTool("add_task_executors", map[string]any{
|
||||
"todoExecutorsAddRequest": map[string]any{
|
||||
"taskId": mustGetFlag(cmd, "task-id"),
|
||||
@@ -687,7 +672,7 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
},
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "executors", Property: "todoExecutorsAddRequest.executorIds", Description: "执行者 userId 列表;逗号分隔,解析后至少包含一个非空值"},
|
||||
{Name: "executors", Property: "todoExecutorsAddRequest.executorIds"},
|
||||
{Name: "task-id", Property: "todoExecutorsAddRequest.taskId"},
|
||||
},
|
||||
},
|
||||
@@ -703,10 +688,7 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
return err
|
||||
}
|
||||
executorsStr := mustGetFlag(cmd, "executors")
|
||||
executorIds, err := parseRequiredTodoIDs("executors", executorsStr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
executorIds := parseExecutorIds(executorsStr)
|
||||
return callMCPTool("remove_task_executors", map[string]any{
|
||||
"todoExecutorsRemoveRequest": map[string]any{
|
||||
"taskId": mustGetFlag(cmd, "task-id"),
|
||||
@@ -747,7 +729,7 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
},
|
||||
},
|
||||
Parameters: []contract.ParamDecl{
|
||||
{Name: "executors", Property: "todoExecutorsRemoveRequest.executorIds", Description: "执行者 userId 列表;逗号分隔,解析后至少包含一个非空值"},
|
||||
{Name: "executors", Property: "todoExecutorsRemoveRequest.executorIds"},
|
||||
{Name: "task-id", Property: "todoExecutorsRemoveRequest.taskId"},
|
||||
},
|
||||
},
|
||||
@@ -1207,14 +1189,14 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
}
|
||||
|
||||
todoTaskCreateCmd.Flags().String("title", "", "待办标题 (必填)")
|
||||
todoTaskCreateCmd.Flags().String("executors", "", "执行者 userId 列表,逗号分隔且至少一个非空值 (必填)")
|
||||
todoTaskCreateCmd.Flags().String("executors", "", "执行者 userId 列表 (必填)")
|
||||
todoTaskCreateCmd.Flags().String("due", "", "截止时间 ISO-8601 (如 2026-03-10T18:00:00+08:00)")
|
||||
todoTaskCreateCmd.Flags().String("priority", "", "优先级: 10低/20普通/30较高/40紧急")
|
||||
todoTaskCreateCmd.Flags().String("recurrence", "", "循环待办 (需先设置 --due); 格式: DTSTART:20260320T100000Z\\nRRULE:FREQ=DAILY;INTERVAL=1")
|
||||
|
||||
todoTaskCreateSubCmd.Flags().String("parent-id", "", "父待办任务 ID (必填)")
|
||||
todoTaskCreateSubCmd.Flags().String("title", "", "子待办标题 (必填)")
|
||||
todoTaskCreateSubCmd.Flags().String("executors", "", "执行者 userId 列表,逗号分隔且至少一个非空值 (必填)")
|
||||
todoTaskCreateSubCmd.Flags().String("executors", "", "执行者 userId 列表 (必填)")
|
||||
todoTaskCreateSubCmd.Flags().String("due", "", "截止时间 ISO-8601 (如 2026-03-10T18:00:00+08:00)")
|
||||
todoTaskCreateSubCmd.Flags().String("priority", "", "优先级: 10低/20普通/30较高/40紧急")
|
||||
todoTaskCreateSubCmd.Flags().String("recurrence", "", "循环待办 (需先设置 --due); 格式: DTSTART:20260320T100000Z\\nRRULE:FREQ=DAILY;INTERVAL=1")
|
||||
@@ -1253,9 +1235,9 @@ reset-reminder 写入的提醒规则。提醒写命令的成功响应只能作
|
||||
_ = todoTaskCmd.PersistentFlags().MarkHidden("remind-at")
|
||||
|
||||
todoTaskAddExecutorCmd.Flags().String("task-id", "", "待办任务 ID (必填)")
|
||||
todoTaskAddExecutorCmd.Flags().String("executors", "", "执行者 userId 列表,逗号分隔且至少一个非空值 (必填)")
|
||||
todoTaskAddExecutorCmd.Flags().String("executors", "", "执行者 userId 列表 (必填)")
|
||||
todoTaskRemoveExecutorCmd.Flags().String("task-id", "", "待办任务 ID (必填)")
|
||||
todoTaskRemoveExecutorCmd.Flags().String("executors", "", "执行者 userId 列表,逗号分隔且至少一个非空值 (必填)")
|
||||
todoTaskRemoveExecutorCmd.Flags().String("executors", "", "执行者 userId 列表 (必填)")
|
||||
todoTaskAddParticipantCmd.Flags().String("task-id", "", "待办任务 ID (必填)")
|
||||
todoTaskAddParticipantCmd.Flags().String("participants", "", "参与人 userId 列表 (必填)")
|
||||
todoTaskRemoveParticipantCmd.Flags().String("task-id", "", "待办任务 ID (必填)")
|
||||
@@ -1911,34 +1893,6 @@ func parseExecutorIds(s string) []string {
|
||||
return ids
|
||||
}
|
||||
|
||||
func parseRequiredTodoIDs(flagName, value string) ([]string, error) {
|
||||
ids := parseExecutorIds(value)
|
||||
if len(ids) > 0 {
|
||||
return ids, nil
|
||||
}
|
||||
return nil, apperrors.NewValidation(
|
||||
fmt.Sprintf("--%s 至少需要一个非空 userId", flagName),
|
||||
apperrors.WithReason("invalid_"+strings.ReplaceAll(flagName, "-", "_")),
|
||||
apperrors.WithHint(fmt.Sprintf("使用 --%s <USER_ID>[,<USER_ID>...] 指定至少一个执行人", flagName)),
|
||||
apperrors.WithExecutionStarted(false),
|
||||
apperrors.WithRetryable(false),
|
||||
)
|
||||
}
|
||||
|
||||
func parseTodoPriority(value string) (int, error) {
|
||||
priority, err := strconv.Atoi(strings.TrimSpace(value))
|
||||
if err == nil {
|
||||
return priority, nil
|
||||
}
|
||||
return 0, apperrors.NewValidation(
|
||||
"--priority 必须是整数",
|
||||
apperrors.WithReason("invalid_priority"),
|
||||
apperrors.WithHint("常用优先级映射:10=低、20=普通、30=较高、40=紧急"),
|
||||
apperrors.WithExecutionStarted(false),
|
||||
apperrors.WithRetryable(false),
|
||||
)
|
||||
}
|
||||
|
||||
type todoLocalFileMeta struct {
|
||||
LocalPath string
|
||||
FileName string
|
||||
|
||||
@@ -6,11 +6,8 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
||||
)
|
||||
|
||||
func executeTodoEdge(t *testing.T, caller *scriptedToolCaller, args ...string) error {
|
||||
@@ -47,11 +44,9 @@ func TestCrossPlatformCoverageTodoCreateAndListCommandEdges(t *testing.T) {
|
||||
errorCases := [][]string{
|
||||
{"task", "create", "--title", "x", "--executors", "u", "--remind-at", validDate},
|
||||
{"task", "create", "--title", "x", "--executors", "u", "--due", "bad"},
|
||||
{"task", "create", "--title", "x", "--executors", "u", "--priority", "bad"},
|
||||
{"task", "create-sub", "--title", "x", "--executors", "u", "--parent-id", "abc"},
|
||||
{"task", "create-sub", "--title", "x", "--executors", "u", "--parent-id", "1", "--remind-at", validDate},
|
||||
{"task", "create-sub", "--title", "x", "--executors", "u", "--parent-id", "1", "--due", "bad"},
|
||||
{"task", "create-sub", "--title", "x", "--executors", "u", "--parent-id", "1", "--priority", "bad"},
|
||||
{"task", "list", "--role-types", "invalid"},
|
||||
{"task", "list", "--plan-finish-date-start", "bad"},
|
||||
{"task", "list", "--plan-finish-date-end", "bad"},
|
||||
@@ -64,8 +59,9 @@ func TestCrossPlatformCoverageTodoCreateAndListCommandEdges(t *testing.T) {
|
||||
|
||||
validCases := [][]string{
|
||||
{"task", "create", "--title", "x", "--executors", "u1,u2", "--due", validDate, "--priority", "40", "--recurrence", "daily"},
|
||||
{"task", "create", "--subject", "x", "--executors", "u", "--priority", "20"},
|
||||
{"task", "create", "--subject", "x", "--executors", "u", "--priority", "bad"},
|
||||
{"task", "create-sub", "--content", "x", "--executors", "u", "--parent-id", "1", "--due", validDate, "--priority", "40", "--recurrence", "daily"},
|
||||
{"task", "create-sub", "--title", "x", "--executors", "u", "--parent-id", "1", "--priority", "bad"},
|
||||
{"task", "list", "--size", "bad"},
|
||||
{"task", "list", "--status", "true", "--priority", "40,bad", "--role-types", "creator,executor", "--plan-finish-date-start", validDate, "--plan-finish-date-end", validDate},
|
||||
}
|
||||
@@ -79,63 +75,6 @@ func TestCrossPlatformCoverageTodoCreateAndListCommandEdges(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageTodoRejectsEmptyExecutorCSVAndNonNumericPriorityBeforeCall(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
reason string
|
||||
args []string
|
||||
}{
|
||||
{name: "create empty executors", reason: "invalid_executors", args: []string{"task", "create", "--title", "x", "--executors", ",,,"}},
|
||||
{name: "create-sub empty executors", reason: "invalid_executors", args: []string{"task", "create-sub", "--parent-id", "1", "--title", "x", "--executors", " , , "}},
|
||||
{name: "add empty executors", reason: "invalid_executors", args: []string{"task", "add-executor", "--task-id", "1", "--executors", ",,,"}},
|
||||
{name: "remove empty executors", reason: "invalid_executors", args: []string{"task", "remove-executor", "--task-id", "1", "--executors", ",,,"}},
|
||||
{name: "create nonnumeric priority", reason: "invalid_priority", args: []string{"task", "create", "--title", "x", "--executors", "u", "--priority", "normal"}},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
caller := &scriptedToolCaller{}
|
||||
err := executeTodoEdge(t, caller, test.args...)
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) || typed.Reason != test.reason {
|
||||
t.Fatalf("error = %T %v, want reason %q", err, err, test.reason)
|
||||
}
|
||||
if typed.ExecutionStarted == nil || *typed.ExecutionStarted {
|
||||
t.Fatalf("execution_started = %v, want false", typed.ExecutionStarted)
|
||||
}
|
||||
if caller.calls != 0 {
|
||||
t.Fatalf("invalid input made %d MCP call(s)", caller.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageTodoCreateAcceptsNumericPriority(t *testing.T) {
|
||||
for _, priority := range []string{"20", "25"} {
|
||||
t.Run(priority, func(t *testing.T) {
|
||||
caller := &scriptedToolCaller{}
|
||||
if err := executeTodoEdge(t, caller, "task", "create", "--title", "x", "--executors", "u", "--priority", priority); err != nil {
|
||||
t.Fatalf("create priority %s: %v", priority, err)
|
||||
}
|
||||
if caller.calls != 1 || caller.tool != "create_personal_todo" {
|
||||
t.Fatalf("calls = %d tool = %q", caller.calls, caller.tool)
|
||||
}
|
||||
request, ok := caller.args["PersonalTodoCreateVO"].(map[string]any)
|
||||
if !ok || request["priority"] != mustTodoAtoi(t, priority) {
|
||||
t.Fatalf("request = %#v, want priority %s", caller.args, priority)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mustTodoAtoi(t *testing.T, value string) int {
|
||||
t.Helper()
|
||||
parsed, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
t.Fatalf("parse %q: %v", value, err)
|
||||
}
|
||||
return parsed
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageTodoSimpleCommandValidationAndSuccessEdges(t *testing.T) {
|
||||
errorCases := [][]string{
|
||||
{"task", "create"},
|
||||
@@ -204,7 +143,6 @@ func TestCrossPlatformCoverageTodoUpdateReminderAndDetailEdges(t *testing.T) {
|
||||
errorCases := [][]string{
|
||||
{"task", "update", "--task-id", "1", "--remind-at", validDate},
|
||||
{"task", "update", "--task-id", "1", "--due", "bad"},
|
||||
{"task", "update", "--task-id", "1", "--priority", "bad"},
|
||||
{"task", "add-reminder", "--task-id", "1", "--base-time", "customTime", "--reminder-time-stamp", "bad"},
|
||||
{"task", "reset-reminder", "--task-id", "1", "--reminder-rules", `[{"baseTime":"customTime","reminderTimeStamp":"bad"}]`},
|
||||
{"task", "reset-reminder", "--task-id", "1", "--reminder-rules", `not-json`},
|
||||
@@ -217,6 +155,7 @@ func TestCrossPlatformCoverageTodoUpdateReminderAndDetailEdges(t *testing.T) {
|
||||
}
|
||||
validCases := [][]string{
|
||||
{"task", "update", "--task-id", "1", "--title", "new", "--due", validDate, "--priority", "40", "--done", "true"},
|
||||
{"task", "update", "--task-id", "1", "--priority", "bad"},
|
||||
{"task", "add-reminder", "--task-id", "1", "--base-time", "dueTime", "--due-date-offset", "-10"},
|
||||
{"task", "add-reminder", "--task-id", "1", "--base-time", "customTime", "--reminder-time-stamp", validDate},
|
||||
}
|
||||
|
||||
@@ -1,750 +0,0 @@
|
||||
// Copyright 2026 Alibaba Group
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
// Package agoal declares reviewed shortcuts for DingTalk Agoal. The public
|
||||
// surface intentionally stays smaller than the atomic helper surface: only
|
||||
// reads with strict response contracts and safe live proof are available.
|
||||
package agoal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd/contract"
|
||||
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/output"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
)
|
||||
|
||||
const productAgoal = "agoal"
|
||||
|
||||
var agoalLoadLocation = time.LoadLocation
|
||||
|
||||
func agoalResponseError(operation, reason, message string) error {
|
||||
return apperrors.NewAPI(message,
|
||||
apperrors.WithOperation(operation),
|
||||
apperrors.WithOrigin("mcp"),
|
||||
apperrors.WithFailureStage("response_validation"),
|
||||
apperrors.WithRetryable(false),
|
||||
apperrors.WithReason(reason),
|
||||
)
|
||||
}
|
||||
|
||||
func requireAgoalSuccess(data map[string]any, operation string) (map[string]any, error) {
|
||||
if len(data) == 0 {
|
||||
return nil, agoalResponseError(operation, "empty_tool_response", "服务返回空响应,无法证明查询成功或结果确实为空")
|
||||
}
|
||||
rawSuccess, present := data["success"]
|
||||
if !present {
|
||||
return nil, agoalResponseError(operation, "missing_success", "响应缺少 success 布尔终态")
|
||||
}
|
||||
success, ok := rawSuccess.(bool)
|
||||
if !ok {
|
||||
return nil, agoalResponseError(operation, "malformed_success", "响应 success 字段不是布尔值")
|
||||
}
|
||||
if !success {
|
||||
message, _ := data["message"].(string)
|
||||
if strings.TrimSpace(message) == "" {
|
||||
message = "服务明确返回 success=false"
|
||||
}
|
||||
return nil, agoalResponseError(operation, "remote_failure", message)
|
||||
}
|
||||
for _, key := range []string{"error", "errorCode", "error_code"} {
|
||||
if value, found := data[key]; found && value != nil && strings.TrimSpace(fmt.Sprint(value)) != "" && fmt.Sprint(value) != "0" {
|
||||
return nil, agoalResponseError(operation, "conflicting_error", fmt.Sprintf("响应 success 与 %s 错误字段冲突", key))
|
||||
}
|
||||
}
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func requireAgoalList(data map[string]any, operation string, value any, idKeys ...string) ([]map[string]any, error) {
|
||||
items, ok := value.([]any)
|
||||
if !ok {
|
||||
return nil, agoalResponseError(operation, "malformed_collection", "成功响应的业务集合不是数组")
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for index, raw := range items {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
return nil, agoalResponseError(operation, "malformed_item", fmt.Sprintf("业务集合第 %d 项不是对象", index))
|
||||
}
|
||||
if agoalFirstString(item, idKeys...) == "" {
|
||||
return nil, agoalResponseError(operation, "missing_item_id", fmt.Sprintf("业务集合第 %d 项缺少稳定身份字段", index))
|
||||
}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func agoalFirstString(item map[string]any, keys ...string) string {
|
||||
for _, key := range keys {
|
||||
if value, ok := item[key].(string); ok && strings.TrimSpace(value) != "" {
|
||||
return strings.TrimSpace(value)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func agoalNonNegativeInt(value any) (int, bool) {
|
||||
switch typed := value.(type) {
|
||||
case int:
|
||||
return typed, typed >= 0
|
||||
case int64:
|
||||
if typed < 0 || int64(int(typed)) != typed {
|
||||
return 0, false
|
||||
}
|
||||
return int(typed), true
|
||||
case float64:
|
||||
if typed < 0 || math.Trunc(typed) != typed || typed > float64(^uint(0)>>1) {
|
||||
return 0, false
|
||||
}
|
||||
return int(typed), true
|
||||
case json.Number:
|
||||
parsed, err := typed.Int64()
|
||||
if err != nil || parsed < 0 || int64(int(parsed)) != parsed {
|
||||
return 0, false
|
||||
}
|
||||
return int(parsed), true
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
}
|
||||
|
||||
func agoalReadSafety() contract.SafetySpec {
|
||||
return contract.SafetySpec{Effect: "read", Risk: "low", Confirmation: "not_required", Idempotency: "idempotent"}
|
||||
}
|
||||
|
||||
func agoalUnavailableSafety(write bool) contract.SafetySpec {
|
||||
if write {
|
||||
return contract.SafetySpec{Effect: "destructive", Risk: "high", Confirmation: "user_required", Idempotency: "unknown"}
|
||||
}
|
||||
return agoalReadSafety()
|
||||
}
|
||||
|
||||
func agoalListResult(collection, description string, paged bool, sensitivePaths ...string) *contract.ResultSpec {
|
||||
properties := map[string]any{
|
||||
"count": map[string]any{"type": "integer", "description": "当前结果中的业务记录数量"},
|
||||
collection: map[string]any{
|
||||
"type": "array", "description": description,
|
||||
"items": map[string]any{"type": "object", "description": "经稳定身份验证的 Agoal 业务记录", "additionalProperties": true},
|
||||
},
|
||||
}
|
||||
required := []string{"count", collection}
|
||||
if paged {
|
||||
properties["page"] = map[string]any{"type": "integer", "description": "服务端确认的当前页码"}
|
||||
properties["pageSize"] = map[string]any{"type": "integer", "description": "服务端确认的当前页容量"}
|
||||
properties["totalCount"] = map[string]any{"type": "integer", "description": "服务端确认的全部匹配记录数"}
|
||||
required = append(required, "page", "pageSize", "totalCount")
|
||||
}
|
||||
schema, _ := json.Marshal(map[string]any{
|
||||
"type": "object", "description": description, "additionalProperties": false,
|
||||
"properties": properties, "required": required,
|
||||
})
|
||||
return &contract.ResultSpec{
|
||||
Outcomes: []contract.ResultOutcome{contract.ResultOutcomeSuccess, contract.ResultOutcomeFailure},
|
||||
DataSchema: schema,
|
||||
SensitivePaths: append([]string(nil), sensitivePaths...),
|
||||
}
|
||||
}
|
||||
|
||||
var ReportStatisticsList = shortcut.Shortcut{
|
||||
Service: productAgoal,
|
||||
Command: "+report-statistics-list",
|
||||
Product: productAgoal,
|
||||
Description: "查询周月报规则提交统计",
|
||||
Intent: "当你要盘点周报或月报规则的按时、迟交、未提交汇总,或按规则关键词定位统计项时使用;返回严格验证的统计列表。",
|
||||
Risk: shortcut.RiskRead,
|
||||
Safety: agoalReadSafety(),
|
||||
Contract: corecmd.ContractDecl{
|
||||
Identity: contract.ToolIdentitySpec{
|
||||
ProductID: productAgoal, Name: "shortcut_report_statistics_list",
|
||||
CanonicalPath: "agoal.shortcut_report_statistics_list", CLIPath: "agoal +report-statistics-list", PrimaryCLIPath: "agoal +report-statistics-list",
|
||||
},
|
||||
Description: "查询周月报规则提交统计",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "composite", Availability: "available",
|
||||
Reason: "Reviewed Agoal adapter validates the terminal success marker, collection type, every stable templateId, and the legal empty result before unified output.",
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "查询周月报规则提交统计",
|
||||
UseWhen: []string{"当你要盘点周报或月报规则的按时、迟交、未提交汇总,或按规则关键词定位统计项时使用;返回严格验证的统计列表。"},
|
||||
AvoidWhen: []string{"需要查看某一规则下的人员级提交详情时不要使用;该能力尚未完成隐私与分页闭环"},
|
||||
Examples: []string{"dws agoal +report-statistics-list --keyword <KEYWORD>"},
|
||||
},
|
||||
Result: agoalListResult("statistics", "周月报规则提交统计记录", false,
|
||||
"statistics.title", "statistics.lastModifier", "statistics.content.name"),
|
||||
},
|
||||
Flags: []shortcut.Flag{{Name: "keyword", Type: shortcut.FlagString, Desc: "规则名称关键词;传入保证不匹配的关键词可得到合法空集合"}},
|
||||
Execute: func(rt *shortcut.RuntimeContext) error {
|
||||
params := map[string]any{}
|
||||
if rt.Changed("keyword") {
|
||||
params["keyword"] = rt.Str("keyword")
|
||||
}
|
||||
raw, err := rt.CallMCPData(productAgoal, "list_report_statistics", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := requireAgoalSuccess(raw, "agoal/list_report_statistics"); err != nil {
|
||||
return err
|
||||
}
|
||||
items, err := requireAgoalList(raw, "agoal/list_report_statistics", raw["content"], "templateId")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return rt.Output(map[string]any{"count": len(items), "statistics": items})
|
||||
},
|
||||
}
|
||||
|
||||
var ObjectTemplateList = shortcut.Shortcut{
|
||||
Service: productAgoal,
|
||||
Command: "+obj-template-list",
|
||||
Product: productAgoal,
|
||||
Description: "分页查询 Agoal 目标模板",
|
||||
Intent: "当你要盘点或按关键词查找 Agoal 目标模板,并查看服务端确认的页码、页容量和总数时使用;不会修改模板。",
|
||||
Risk: shortcut.RiskRead,
|
||||
Safety: agoalReadSafety(),
|
||||
Contract: corecmd.ContractDecl{
|
||||
Identity: contract.ToolIdentitySpec{
|
||||
ProductID: productAgoal, Name: "shortcut_obj_template_list",
|
||||
CanonicalPath: "agoal.shortcut_obj_template_list", CLIPath: "agoal +obj-template-list", PrimaryCLIPath: "agoal +obj-template-list",
|
||||
},
|
||||
Description: "分页查询 Agoal 目标模板",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "composite", Availability: "available",
|
||||
Reason: "Reviewed Agoal adapter validates success, result array, stable template IDs, and explicit page/pageSize/totalCount facts without inventing cursor pagination.",
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "分页查询 Agoal 目标模板",
|
||||
UseWhen: []string{"当你要盘点或按关键词查找 Agoal 目标模板,并查看服务端确认的页码、页容量和总数时使用;不会修改模板。"},
|
||||
AvoidWhen: []string{"需要新增或覆盖更新模板时不要使用;写能力尚未具备安全回滚合同"},
|
||||
Examples: []string{"dws agoal +obj-template-list --keyword <KEYWORD> --page 1 --page-size 20"},
|
||||
},
|
||||
Result: agoalListResult("templates", "Agoal 目标模板查询结果", true,
|
||||
"templates.title", "templates.creator", "templates.dimensions.title"),
|
||||
},
|
||||
Flags: []shortcut.Flag{
|
||||
{Name: "keyword", Type: shortcut.FlagString, Desc: "模板关键词;传入保证不匹配的关键词可得到合法空集合"},
|
||||
{Name: "page", Type: shortcut.FlagInt, Default: "1", Desc: "页码,必须大于等于 1"},
|
||||
{Name: "page-size", Type: shortcut.FlagInt, Default: "20", Desc: "每页数量,必须在 1 到 100 之间"},
|
||||
},
|
||||
Constraints: []shortcut.Constraint{
|
||||
{Kind: shortcut.ConstraintCustom, Flags: []string{"page"}, Description: "页码,必须大于等于 1"},
|
||||
{Kind: shortcut.ConstraintCustom, Flags: []string{"page-size"}, Description: "每页数量,必须在 1 到 100 之间"},
|
||||
},
|
||||
Validate: func(rt *shortcut.RuntimeContext) error {
|
||||
if rt.Int("page") < 1 {
|
||||
return apperrors.NewValidation("--page 必须大于等于 1")
|
||||
}
|
||||
if size := rt.Int("page-size"); size < 1 || size > 100 {
|
||||
return apperrors.NewValidation("--page-size 必须在 1 到 100 之间")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Execute: func(rt *shortcut.RuntimeContext) error {
|
||||
wantPage := rt.Int("page")
|
||||
wantSize := rt.Int("page-size")
|
||||
params := map[string]any{"page": wantPage, "pageSize": wantSize}
|
||||
if rt.Changed("keyword") {
|
||||
params["keyword"] = rt.Str("keyword")
|
||||
}
|
||||
raw, err := rt.CallMCPData(productAgoal, "list_obj_template", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := requireAgoalSuccess(raw, "agoal/list_obj_template"); err != nil {
|
||||
return err
|
||||
}
|
||||
content, ok := raw["content"].(map[string]any)
|
||||
if !ok {
|
||||
return agoalResponseError("agoal/list_obj_template", "malformed_business_result", "成功响应 content 不是分页对象")
|
||||
}
|
||||
items, err := requireAgoalList(raw, "agoal/list_obj_template", content["result"], "id", "templateId")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
page, pageOK := agoalNonNegativeInt(content["page"])
|
||||
pageSize, pageSizeOK := agoalNonNegativeInt(content["pageSize"])
|
||||
total, totalOK := agoalNonNegativeInt(content["totalCount"])
|
||||
if !pageOK || !pageSizeOK || !totalOK {
|
||||
return agoalResponseError("agoal/list_obj_template", "malformed_pagination", "分页响应缺少非负整数 page/pageSize/totalCount")
|
||||
}
|
||||
if page != wantPage || pageSize != wantSize {
|
||||
return agoalResponseError("agoal/list_obj_template", "pagination_mismatch", "服务端分页回显与请求不一致")
|
||||
}
|
||||
if total < len(items) {
|
||||
return agoalResponseError("agoal/list_obj_template", "impossible_total", "totalCount 小于当前页记录数")
|
||||
}
|
||||
return rt.Output(map[string]any{
|
||||
"count": len(items), "templates": items,
|
||||
"page": page, "pageSize": pageSize, "totalCount": total,
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
var ContractFields = shortcut.Shortcut{
|
||||
Service: productAgoal, Command: "+contract-fields", Product: productAgoal,
|
||||
Description: "查询经营合约字段配置",
|
||||
Intent: "当你要查看当前组织可用的经营合约字段,或按字段 ID、编码、标题、分类、类型精确定位配置时使用;不会修改合约。",
|
||||
Risk: shortcut.RiskRead,
|
||||
Safety: agoalReadSafety(),
|
||||
Contract: corecmd.ContractDecl{
|
||||
Identity: contract.ToolIdentitySpec{
|
||||
ProductID: productAgoal, Name: "shortcut_contract_fields",
|
||||
CanonicalPath: "agoal.shortcut_contract_fields", CLIPath: "agoal +contract-fields", PrimaryCLIPath: "agoal +contract-fields",
|
||||
},
|
||||
Description: "查询并严格筛选经营合约字段配置",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "composite", Availability: "available",
|
||||
Reason: "Reviewed adapter requires success, an explicit content array, and a stable id on every field; the optional keyword is applied locally across reviewed scalar field metadata so known and guaranteed-zero cases are provable.",
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "查询经营合约字段配置",
|
||||
UseWhen: []string{"当你要查看当前组织可用的经营合约字段,或按字段 ID、编码、标题、分类、类型精确定位配置时使用;不会修改合约。"},
|
||||
AvoidWhen: []string{"查询具体经营合约不要使用;当前合约列表和详情缺少非空安全 fixture"},
|
||||
Examples: []string{"dws agoal +contract-fields --keyword <KEYWORD>"},
|
||||
},
|
||||
Result: agoalListResult("fields", "经营合约字段配置", false),
|
||||
},
|
||||
Flags: []shortcut.Flag{{Name: "keyword", Type: shortcut.FlagString, Desc: "字段 ID、编码、标题、分类或类型关键词;本地大小写不敏感筛选"}},
|
||||
Execute: func(rt *shortcut.RuntimeContext) error {
|
||||
raw, err := rt.CallMCPData(productAgoal, "list_op_contract_fields", map[string]any{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := requireAgoalSuccess(raw, "agoal/list_op_contract_fields"); err != nil {
|
||||
return err
|
||||
}
|
||||
fields, err := requireAgoalList(raw, "agoal/list_op_contract_fields", raw["content"], "id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fields = filterAgoalItems(fields, rt.Str("keyword"), "id", "code", "title", "category", "type")
|
||||
return rt.Output(map[string]any{"count": len(fields), "fields": fields})
|
||||
},
|
||||
}
|
||||
|
||||
var UserRules = shortcut.Shortcut{
|
||||
Service: productAgoal, Command: "+user-rules", Product: productAgoal,
|
||||
Description: "查询用户 Agoal 规则周期",
|
||||
Intent: "当你要查看本人或指定用户可见的 Agoal 规则及周期,或按稳定 ruleId 精确确认某项规则时使用。",
|
||||
Risk: shortcut.RiskRead,
|
||||
Safety: agoalReadSafety(),
|
||||
Contract: corecmd.ContractDecl{
|
||||
Identity: contract.ToolIdentitySpec{
|
||||
ProductID: productAgoal, Name: "shortcut_user_rules",
|
||||
CanonicalPath: "agoal.shortcut_user_rules", CLIPath: "agoal +user-rules", PrimaryCLIPath: "agoal +user-rules",
|
||||
},
|
||||
Description: "查询用户规则周期并可按稳定 ruleId 精确筛选",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "composite", Availability: "available",
|
||||
Reason: "Reviewed adapter requires success, a content object, an explicit rules array, and stable rule IDs; the optional rule-id filter is local exact equality and provides a guaranteed-zero proof path.",
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "查询用户 Agoal 规则周期",
|
||||
UseWhen: []string{"当你要查看本人或指定用户可见的 Agoal 规则及周期,或按稳定 ruleId 精确确认某项规则时使用。"},
|
||||
AvoidWhen: []string{"需要目标正文时使用 +user-objectives;该目标列表当前缺少非空安全 fixture"},
|
||||
Examples: []string{"dws agoal +user-rules --rule-id <RULE_ID>"},
|
||||
},
|
||||
Result: agoalListResult("rules", "用户可见的 Agoal 规则与周期", false,
|
||||
"rules.ruleName", "rules.periodFilter.currentPeriods.nameCn", "rules.periodFilter.historyPeriods.nameCn"),
|
||||
},
|
||||
Flags: []shortcut.Flag{
|
||||
{Name: "user-id", Type: shortcut.FlagString, Desc: "可选用户稳定 ID;省略时查询本人"},
|
||||
{Name: "rule-id", Type: shortcut.FlagString, Desc: "可选稳定 ruleId;Shortcut 在严格验证完整数组后做精确等值筛选"},
|
||||
},
|
||||
Execute: func(rt *shortcut.RuntimeContext) error {
|
||||
params := map[string]any{}
|
||||
if rt.Changed("user-id") {
|
||||
params["dingUserId"] = rt.Str("user-id")
|
||||
}
|
||||
raw, err := rt.CallMCPData(productAgoal, "get_user_rules", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := requireAgoalSuccess(raw, "agoal/get_user_rules"); err != nil {
|
||||
return err
|
||||
}
|
||||
content, ok := raw["content"].(map[string]any)
|
||||
if !ok {
|
||||
return agoalResponseError("agoal/get_user_rules", "malformed_business_result", "成功响应 content 不是规则对象")
|
||||
}
|
||||
rules, err := requireAgoalList(raw, "agoal/get_user_rules", content["rules"], "id")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wantRule := strings.TrimSpace(rt.Str("rule-id"))
|
||||
if wantRule != "" {
|
||||
filtered := make([]map[string]any, 0, 1)
|
||||
for _, rule := range rules {
|
||||
if agoalFirstString(rule, "id") == wantRule {
|
||||
filtered = append(filtered, rule)
|
||||
}
|
||||
}
|
||||
rules = filtered
|
||||
}
|
||||
return rt.Output(map[string]any{"count": len(rules), "rules": rules})
|
||||
},
|
||||
}
|
||||
|
||||
var ReportSubmitDetail = shortcut.Shortcut{
|
||||
Service: productAgoal, Command: "+report-submit-detail", Product: productAgoal,
|
||||
Description: "分页查询周月报人员提交详情",
|
||||
Intent: "当你要按周月报规则、提交状态、日期或人员关键词查看具体人员提交详情时使用;返回严格验证的人员身份和页码事实。",
|
||||
Risk: shortcut.RiskRead,
|
||||
Safety: agoalReadSafety(),
|
||||
Contract: corecmd.ContractDecl{
|
||||
Identity: contract.ToolIdentitySpec{
|
||||
ProductID: productAgoal, Name: "shortcut_report_submit_detail",
|
||||
CanonicalPath: "agoal.shortcut_report_submit_detail", CLIPath: "agoal +report-submit-detail", PrimaryCLIPath: "agoal +report-submit-detail",
|
||||
},
|
||||
Description: "分页查询周月报人员提交详情",
|
||||
Interface: &contract.InterfaceSpec{
|
||||
Mode: "composite", Availability: "available",
|
||||
Reason: "Reviewed adapter requires success, a paged content object, an explicit result array, stable nested user identity on every row, exact page/pageSize echo, and a valid totalCount. Because the lower keyword is ignored, keyword queries use one bounded full traversal with total consistency, duplicate, stall, and page-limit guards before local filtering; only reviewed personnel fields are projected and declared sensitive.",
|
||||
},
|
||||
Selection: contract.SelectionSpec{
|
||||
AgentSummary: "分页查询周月报人员提交详情",
|
||||
UseWhen: []string{"当你要按周月报规则、提交状态、日期或人员关键词查看具体人员提交详情时使用;返回严格验证的人员身份和页码事实。"},
|
||||
AvoidWhen: []string{"只需规则级汇总时使用 +report-statistics-list;不要把人员级原始结果写入审计文档"},
|
||||
Examples: []string{"dws agoal +report-submit-detail --template-id <TEMPLATE_ID> --submit-state NOT_SUBMITTED --page 1 --page-size 20"},
|
||||
},
|
||||
Result: agoalListResult("submissions", "周月报人员提交详情", true,
|
||||
"submissions.reportId", "submissions.user.dingUserId", "submissions.user.id", "submissions.user.name", "submissions.user.workNo"),
|
||||
},
|
||||
Flags: []shortcut.Flag{
|
||||
{Name: "template-id", Type: shortcut.FlagString, Desc: "周月报规则模板稳定 ID", Required: true},
|
||||
{Name: "submit-state", Type: shortcut.FlagString, Desc: "提交状态", Required: true, Enum: []string{"ON_TIME", "LATE", "NOT_SUBMITTED"}},
|
||||
{Name: "query-date", Type: shortcut.FlagString, Desc: "可选 ISO-8601 日期或时间"},
|
||||
{Name: "keyword", Type: shortcut.FlagString, Desc: "可选人员名称关键词;可用于保证零命中"},
|
||||
{Name: "page", Type: shortcut.FlagInt, Default: "1", Desc: "页码,必须大于等于 1"},
|
||||
{Name: "page-size", Type: shortcut.FlagInt, Default: "20", Desc: "每页数量,必须在 1 到 100 之间"},
|
||||
},
|
||||
Constraints: []shortcut.Constraint{
|
||||
{Kind: shortcut.ConstraintCustom, Flags: []string{"page"}, Description: "页码,必须大于等于 1"},
|
||||
{Kind: shortcut.ConstraintCustom, Flags: []string{"page-size"}, Description: "每页数量,必须在 1 到 100 之间"},
|
||||
},
|
||||
Validate: func(rt *shortcut.RuntimeContext) error {
|
||||
if rt.Int("page") < 1 {
|
||||
return apperrors.NewValidation("--page 必须大于等于 1")
|
||||
}
|
||||
if size := rt.Int("page-size"); size < 1 || size > 100 {
|
||||
return apperrors.NewValidation("--page-size 必须在 1 到 100 之间")
|
||||
}
|
||||
if rt.Changed("query-date") {
|
||||
if _, err := normalizeAgoalQueryDate(rt.Str("query-date")); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Execute: func(rt *shortcut.RuntimeContext) error {
|
||||
wantPage, wantSize := rt.Int("page"), rt.Int("page-size")
|
||||
baseParams := map[string]any{
|
||||
"templateId": rt.Str("template-id"), "submitState": strings.ToUpper(rt.Str("submit-state")),
|
||||
}
|
||||
if rt.Changed("query-date") {
|
||||
// Validate has already accepted this exact immutable Cobra value.
|
||||
queryDate, _ := normalizeAgoalQueryDate(rt.Str("query-date"))
|
||||
baseParams["queryDate"] = queryDate
|
||||
}
|
||||
keyword := strings.TrimSpace(rt.Str("keyword"))
|
||||
if keyword == "" {
|
||||
items, total, err := readAgoalSubmissionPage(rt, baseParams, wantPage, wantSize)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return rt.Output(map[string]any{"count": len(items), "submissions": items, "page": wantPage, "pageSize": wantSize, "totalCount": total})
|
||||
}
|
||||
all, err := readAllAgoalSubmissions(rt, baseParams)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
filtered := filterAgoalSubmissions(all, keyword)
|
||||
start := len(filtered)
|
||||
pageOffset := wantPage - 1
|
||||
if pageOffset <= len(filtered)/wantSize {
|
||||
start = pageOffset * wantSize
|
||||
}
|
||||
end := start + wantSize
|
||||
if end > len(filtered) {
|
||||
end = len(filtered)
|
||||
}
|
||||
items := filtered[start:end]
|
||||
return rt.Output(map[string]any{"count": len(items), "submissions": items, "page": wantPage, "pageSize": wantSize, "totalCount": len(filtered)})
|
||||
},
|
||||
}
|
||||
|
||||
const (
|
||||
agoalSubmissionReadPageSize = 100
|
||||
agoalSubmissionMaxPages = 20
|
||||
)
|
||||
|
||||
func readAgoalSubmissionPage(rt *shortcut.RuntimeContext, baseParams map[string]any, page, pageSize int) ([]map[string]any, int, error) {
|
||||
params := make(map[string]any, len(baseParams)+2)
|
||||
for key, value := range baseParams {
|
||||
params[key] = value
|
||||
}
|
||||
params["page"] = page
|
||||
params["pageSize"] = pageSize
|
||||
raw, err := rt.CallMCPData(productAgoal, "get_submit_detail", params)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if _, err := requireAgoalSuccess(raw, "agoal/get_submit_detail"); err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
content, ok := raw["content"].(map[string]any)
|
||||
if !ok {
|
||||
return nil, 0, agoalResponseError("agoal/get_submit_detail", "malformed_business_result", "成功响应 content 不是分页对象")
|
||||
}
|
||||
items, err := requireAgoalSubmissionList(content["result"])
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
gotPage, pageOK := agoalNonNegativeInt(content["page"])
|
||||
gotSize, sizeOK := agoalNonNegativeInt(content["pageSize"])
|
||||
total, totalOK := agoalNonNegativeInt(content["totalCount"])
|
||||
if !pageOK || !sizeOK || !totalOK {
|
||||
return nil, 0, agoalResponseError("agoal/get_submit_detail", "malformed_pagination", "分页响应缺少非负整数 page/pageSize/totalCount")
|
||||
}
|
||||
if gotPage != page || gotSize != pageSize {
|
||||
return nil, 0, agoalResponseError("agoal/get_submit_detail", "pagination_mismatch", "服务端分页回显与请求不一致")
|
||||
}
|
||||
if total < len(items) {
|
||||
return nil, 0, agoalResponseError("agoal/get_submit_detail", "impossible_total", "totalCount 小于当前页记录数")
|
||||
}
|
||||
return items, total, nil
|
||||
}
|
||||
|
||||
func readAllAgoalSubmissions(rt *shortcut.RuntimeContext, baseParams map[string]any) ([]map[string]any, error) {
|
||||
all := make([]map[string]any, 0)
|
||||
seen := map[string]bool{}
|
||||
wantTotal := -1
|
||||
for page := 1; page <= agoalSubmissionMaxPages; page++ {
|
||||
items, total, err := readAgoalSubmissionPage(rt, baseParams, page, agoalSubmissionReadPageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if wantTotal < 0 {
|
||||
wantTotal = total
|
||||
} else if total != wantTotal {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "pagination_total_changed", "分页遍历期间 totalCount 发生变化")
|
||||
}
|
||||
for _, item := range items {
|
||||
identity := agoalSubmissionIdentity(item)
|
||||
if seen[identity] {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "pagination_duplicate", "分页遍历出现重复人员提交身份")
|
||||
}
|
||||
seen[identity] = true
|
||||
all = append(all, item)
|
||||
}
|
||||
if len(all) == wantTotal {
|
||||
return all, nil
|
||||
}
|
||||
if len(items) == 0 {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "pagination_stall", "尚有记录时服务返回空页,分页无法推进")
|
||||
}
|
||||
}
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "readback_page_limit", "人员提交详情超过有界分页上限")
|
||||
}
|
||||
|
||||
func agoalSubmissionIdentity(item map[string]any) string {
|
||||
if reportID := agoalFirstString(item, "reportId"); reportID != "" {
|
||||
return "report:" + reportID
|
||||
}
|
||||
user, _ := item["user"].(map[string]any)
|
||||
return "user:" + agoalFirstString(user, "dingUserId", "id")
|
||||
}
|
||||
|
||||
func filterAgoalSubmissions(items []map[string]any, keyword string) []map[string]any {
|
||||
keyword = strings.ToLower(strings.TrimSpace(keyword))
|
||||
if keyword == "" {
|
||||
return items
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, item := range items {
|
||||
user, _ := item["user"].(map[string]any)
|
||||
if strings.Contains(strings.ToLower(agoalFirstString(user, "name")), keyword) {
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func filterAgoalItems(items []map[string]any, keyword string, keys ...string) []map[string]any {
|
||||
keyword = strings.ToLower(strings.TrimSpace(keyword))
|
||||
if keyword == "" {
|
||||
return items
|
||||
}
|
||||
out := make([]map[string]any, 0, len(items))
|
||||
for _, item := range items {
|
||||
for _, key := range keys {
|
||||
value, ok := item[key].(string)
|
||||
if ok && strings.Contains(strings.ToLower(value), keyword) {
|
||||
out = append(out, item)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func requireAgoalSubmissionList(value any) ([]map[string]any, error) {
|
||||
rawItems, ok := value.([]any)
|
||||
if !ok {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "malformed_collection", "成功响应 result 不是数组")
|
||||
}
|
||||
out := make([]map[string]any, 0, len(rawItems))
|
||||
for index, raw := range rawItems {
|
||||
item, ok := raw.(map[string]any)
|
||||
if !ok {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "malformed_item", fmt.Sprintf("人员提交详情第 %d 项不是对象", index))
|
||||
}
|
||||
user, ok := item["user"].(map[string]any)
|
||||
if !ok || agoalFirstString(user, "dingUserId", "id") == "" {
|
||||
return nil, agoalResponseError("agoal/get_submit_detail", "missing_item_id", fmt.Sprintf("人员提交详情第 %d 项缺少稳定用户身份", index))
|
||||
}
|
||||
projectedUser := map[string]any{}
|
||||
for _, key := range []string{"dingUserId", "id", "name", "workNo"} {
|
||||
if value, found := user[key]; found {
|
||||
projectedUser[key] = value
|
||||
}
|
||||
}
|
||||
projected := map[string]any{"user": projectedUser}
|
||||
for _, key := range []string{"reportId", "publishTime"} {
|
||||
if value, found := item[key]; found {
|
||||
projected[key] = value
|
||||
}
|
||||
}
|
||||
out = append(out, projected)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func normalizeAgoalQueryDate(value string) (string, error) {
|
||||
value = strings.TrimSpace(value)
|
||||
if parsed, err := time.Parse("2006-01-02", value); err == nil {
|
||||
return parsed.Format("2006-01-02"), nil
|
||||
}
|
||||
if parsed, err := time.Parse(time.RFC3339, value); err == nil {
|
||||
location, loadErr := agoalLoadLocation("Asia/Shanghai")
|
||||
if loadErr != nil {
|
||||
location = time.FixedZone("CST", 8*60*60)
|
||||
}
|
||||
return parsed.In(location).Format("2006-01-02"), nil
|
||||
}
|
||||
return "", apperrors.NewValidation("--query-date 必须是 YYYY-MM-DD 或 RFC3339 时间")
|
||||
}
|
||||
|
||||
type unavailableAgoalSpec struct {
|
||||
command string
|
||||
description string
|
||||
intent string
|
||||
tool string
|
||||
flags []shortcut.Flag
|
||||
write bool
|
||||
reason string
|
||||
}
|
||||
|
||||
func agoalStringFlag(name, description string, required bool) shortcut.Flag {
|
||||
return shortcut.Flag{Name: name, Type: shortcut.FlagString, Desc: description, Required: required}
|
||||
}
|
||||
|
||||
func unavailableAgoalShortcut(spec unavailableAgoalSpec) shortcut.Shortcut {
|
||||
flagNames := make([]string, 0, len(spec.flags))
|
||||
for _, flag := range spec.flags {
|
||||
flagNames = append(flagNames, flag.Name)
|
||||
}
|
||||
unavailable := func(*shortcut.RuntimeContext) error {
|
||||
return apperrors.NewValidation("该 Agoal Shortcut 当前 unavailable:" + spec.reason)
|
||||
}
|
||||
return shortcut.Shortcut{
|
||||
Service: productAgoal, Command: spec.command, Product: productAgoal,
|
||||
Description: spec.description, Intent: spec.intent,
|
||||
Risk: func() shortcut.Risk {
|
||||
if spec.write {
|
||||
return shortcut.RiskHighWrite
|
||||
}
|
||||
return shortcut.RiskRead
|
||||
}(),
|
||||
Safety: agoalUnavailableSafety(spec.write),
|
||||
Flags: spec.flags,
|
||||
Hidden: true,
|
||||
Availability: shortcut.AvailabilityUnavailable,
|
||||
Constraints: []shortcut.Constraint{{
|
||||
Kind: shortcut.ConstraintCustom, Flags: flagNames,
|
||||
Description: "该命令保持 unavailable,直到文档化的安全验证前置条件满足",
|
||||
}},
|
||||
SemanticDelta: "Atomic route " + spec.tool + " remains unavailable: " + spec.reason,
|
||||
Validate: unavailable,
|
||||
Execute: unavailable,
|
||||
}
|
||||
}
|
||||
|
||||
var unavailableAgoalSpecs = []unavailableAgoalSpec{
|
||||
{command: "+strategy-list", description: "按范围查询战略解码", intent: "按部门或个人范围查询战略解码列表。", tool: "list_strategy_decodings", flags: []shortcut.Flag{
|
||||
{Name: "scope-type", Type: shortcut.FlagString, Desc: "范围类型", Required: true, Enum: []string{"DEPT", "PERSONAL"}},
|
||||
agoalStringFlag("scope-id", "部门或人员稳定 ID", true),
|
||||
}, reason: "exact+raw 在当前可访问 PERSONAL 与 DEPT 范围均仅返回显式空数组,缺少已知非空 fixture"},
|
||||
{command: "+strategy-get", description: "查询战略解码详情", intent: "按 profileId 查询单个战略解码。", tool: "get_strategy_decoding_detail", flags: []shortcut.Flag{
|
||||
agoalStringFlag("profile-id", "战略解码稳定 ID", true),
|
||||
}, reason: "raw 对不存在 profileId 返回 null 且无 success 终态,列表又无非空 fixture,无法绑定稳定身份"},
|
||||
{command: "+strategy-update", description: "覆盖更新战略解码", intent: "基于旧数据覆盖更新战略解码。", tool: "update_strategy_decoding", write: true, flags: []shortcut.Flag{
|
||||
agoalStringFlag("profile-id", "战略解码稳定 ID", true), agoalStringFlag("content", "完整实体 JSON 数组", true),
|
||||
}, reason: "raw 仅完成 dry-run payload;没有可读旧值 fixture、全字段精确读回与恢复闭环"},
|
||||
{command: "+contract-list", description: "按范围查询经营合约", intent: "按部门或个人范围查询经营合约列表。", tool: "list_op_contracts", flags: []shortcut.Flag{
|
||||
{Name: "scope-type", Type: shortcut.FlagString, Desc: "范围类型", Required: true, Enum: []string{"DEPT", "PERSONAL"}},
|
||||
agoalStringFlag("scope-id", "部门或人员稳定 ID", true),
|
||||
}, reason: "exact+raw 在当前可访问 PERSONAL 与 DEPT 范围均仅返回显式空数组,缺少已知非空 fixture"},
|
||||
{command: "+contract-get", description: "查询经营合约详情", intent: "按 contractId 查询单个经营合约。", tool: "get_op_contract_detail", flags: []shortcut.Flag{
|
||||
agoalStringFlag("contract-id", "经营合约稳定 ID", true),
|
||||
}, reason: "raw 对不存在 contractId 返回 null 且无 success 终态,列表又无非空 fixture,无法绑定稳定身份"},
|
||||
{command: "+contract-update", description: "覆盖更新经营合约", intent: "基于旧数据覆盖经营合约全部维度。", tool: "update_op_contract", write: true, flags: []shortcut.Flag{
|
||||
agoalStringFlag("contract-id", "经营合约稳定 ID", true), agoalStringFlag("dimensions", "完整维度 JSON 数组", true),
|
||||
}, reason: "raw 仅完成 dry-run payload;没有可读旧值 fixture、全字段精确读回与恢复闭环"},
|
||||
{command: "+scorecard-get", description: "查询计分卡详情", intent: "按部门与周期查询计分卡。", tool: "get_score_card_detail", flags: []shortcut.Flag{
|
||||
agoalStringFlag("selected-time", "ISO-8601 周期起始时间", true), agoalStringFlag("dept-id", "部门稳定 ID", true),
|
||||
}, reason: "exact+raw 对可访问部门和多个受控周期均返回 null 且无 success 终态,缺少非空计分卡 fixture"},
|
||||
{command: "+scorecard-entity-get", description: "查询计分卡实体详情", intent: "按计分卡与实体 ID 查询详情。", tool: "get_score_card_entity_detail", flags: []shortcut.Flag{
|
||||
agoalStringFlag("sc-id", "计分卡稳定 ID", true), agoalStringFlag("entity-id", "实体稳定 ID", true),
|
||||
}, reason: "raw 对不存在计分卡/实体双 ID 返回 null 且无 success 终态,无法取得可安全读取的双 ID fixture"},
|
||||
{command: "+scorecard-update", description: "覆盖更新计分卡", intent: "基于旧数据覆盖更新计分卡内容。", tool: "update_score_card", write: true, flags: []shortcut.Flag{
|
||||
agoalStringFlag("dept-id", "部门稳定 ID", true), agoalStringFlag("selected-time", "ISO-8601 周期起始时间", true), agoalStringFlag("id", "计分卡稳定 ID", true),
|
||||
{Name: "tracking-period-type", Type: shortcut.FlagString, Desc: "跟踪周期", Required: true, Enum: []string{"MONTHLY", "QUARTERLY"}},
|
||||
agoalStringFlag("content", "完整计分卡 JSON 数组", true),
|
||||
}, reason: "raw 仅完成 dry-run payload;没有可读计分卡 fixture、全字段精确读回与恢复闭环"},
|
||||
{command: "+user-objectives", description: "查询用户目标", intent: "按用户、规则与周期查询目标。", tool: "list_user_objectives", flags: []shortcut.Flag{
|
||||
agoalStringFlag("user-id", "人员稳定 ID", true), agoalStringFlag("rule-id", "规则稳定 ID", true), agoalStringFlag("period-ids", "周期 ID CSV", true),
|
||||
}, reason: "exact+raw 使用当前用户及全部可见规则/周期均只返回显式空数组,缺少已知非空目标 fixture"},
|
||||
{command: "+obj-template-upsert", description: "新增或覆盖更新目标模板", intent: "新增目标模板或基于旧数据覆盖更新模板。", tool: "create_or_update_obj_template", write: true, flags: []shortcut.Flag{
|
||||
agoalStringFlag("template-id", "更新时的模板稳定 ID", false), agoalStringFlag("title", "新增时的模板标题", false), agoalStringFlag("dimensions", "完整维度 JSON", true),
|
||||
{Name: "objective-weight", Type: shortcut.FlagBool, Desc: "是否启用目标权重"},
|
||||
{Name: "dimension-weight", Type: shortcut.FlagBool, Desc: "是否启用维度权重"},
|
||||
{Name: "compute-by-weight", Type: shortcut.FlagBool, Desc: "维度是否参与计算"},
|
||||
}, reason: "raw 仅完成 dry-run payload;原子面无模板删除或版本恢复,无法验证 create/update 终态与零残留"},
|
||||
}
|
||||
|
||||
func init() {
|
||||
contract.RegisterProductDecl(contract.ProductDecl{
|
||||
ID: productAgoal,
|
||||
Selection: contract.ProductSelectionDecl{
|
||||
AgentSummary: "查询钉钉 Agoal 的周月报统计、人员提交详情、合约字段、用户规则与目标模板;其余能力按安全证据逐步开放",
|
||||
UseWhen: []string{"用户明确处理钉钉 Agoal、战略解码、经营合约、计分卡、周月报统计或目标模板时使用"},
|
||||
AvoidWhen: []string{"用户处理 Lark OKR 的 Objective、Key Result、Progress 或 Alignment 时不要使用;两者数据模型和平台不同"},
|
||||
},
|
||||
})
|
||||
items := []shortcut.Shortcut{ReportStatisticsList, ObjectTemplateList, ContractFields, UserRules, ReportSubmitDetail}
|
||||
for _, spec := range unavailableAgoalSpecs {
|
||||
items = append(items, unavailableAgoalShortcut(spec))
|
||||
}
|
||||
for index := range items {
|
||||
if items[index].Availability != shortcut.AvailabilityUnavailable {
|
||||
items[index].OutputRollout = output.RolloutUnifiedActive
|
||||
}
|
||||
}
|
||||
shortcut.Register(items...)
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
// Copyright 2026 Alibaba Group
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
package agoal
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/testseam"
|
||||
)
|
||||
|
||||
func TestCrossPlatformCoverageAgoalScalarAndProjectionEdges(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
value any
|
||||
want int
|
||||
ok bool
|
||||
}{
|
||||
{name: "int", value: 3, want: 3, ok: true},
|
||||
{name: "negative int", value: -1, want: -1},
|
||||
{name: "int64", value: int64(4), want: 4, ok: true},
|
||||
{name: "negative int64", value: int64(-1)},
|
||||
{name: "float", value: float64(5), want: 5, ok: true},
|
||||
{name: "negative float", value: float64(-1)},
|
||||
{name: "fraction", value: 1.5},
|
||||
{name: "huge float", value: math.MaxFloat64},
|
||||
{name: "json number", value: json.Number("6"), want: 6, ok: true},
|
||||
{name: "bad json number", value: json.Number("1.5")},
|
||||
{name: "negative json number", value: json.Number("-1")},
|
||||
{name: "wrong type", value: "7"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, ok := agoalNonNegativeInt(tc.value)
|
||||
if got != tc.want || ok != tc.ok {
|
||||
t.Fatalf("agoalNonNegativeInt(%#v) = (%d,%v), want (%d,%v)", tc.value, got, ok, tc.want, tc.ok)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
items := []map[string]any{{"id": "one", "name": "Known"}}
|
||||
if got := filterAgoalItems(items, "", "name"); len(got) != 1 {
|
||||
t.Fatalf("empty item filter = %#v", got)
|
||||
}
|
||||
if got := filterAgoalSubmissions(items, ""); len(got) != 1 {
|
||||
t.Fatalf("empty submission filter = %#v", got)
|
||||
}
|
||||
if got := agoalSubmissionIdentity(map[string]any{"user": map[string]any{"id": "user"}}); got != "user:user" {
|
||||
t.Fatalf("fallback identity = %q", got)
|
||||
}
|
||||
|
||||
for _, bad := range []any{
|
||||
nil,
|
||||
[]any{"bad"},
|
||||
[]any{map[string]any{"user": "bad"}},
|
||||
[]any{map[string]any{"user": map[string]any{"name": "missing identity"}}},
|
||||
} {
|
||||
if _, err := requireAgoalSubmissionList(bad); err == nil {
|
||||
t.Fatalf("malformed submission list accepted: %#v", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalDateNormalizationEdges(t *testing.T) {
|
||||
if got, err := normalizeAgoalQueryDate(" 2026-08-24 "); err != nil || got != "2026-08-24" {
|
||||
t.Fatalf("date normalization = %q, %v", got, err)
|
||||
}
|
||||
if got, err := normalizeAgoalQueryDate("2026-08-24T01:00:00Z"); err != nil || got != "2026-08-24" {
|
||||
t.Fatalf("RFC3339 normalization = %q, %v", got, err)
|
||||
}
|
||||
testseam.Swap(t, &agoalLoadLocation, func(string) (*time.Location, error) {
|
||||
return nil, errors.New("fixture location failure")
|
||||
})
|
||||
if got, err := normalizeAgoalQueryDate("2026-08-24T18:00:00Z"); err != nil || got != "2026-08-25" {
|
||||
t.Fatalf("fallback timezone normalization = %q, %v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalLeafFailureWiring(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
args []string
|
||||
tool string
|
||||
response map[string]any
|
||||
}{
|
||||
{name: "report transport", declaration: ReportStatisticsList, tool: "list_report_statistics"},
|
||||
{name: "report failure", declaration: ReportStatisticsList, tool: "list_report_statistics", response: map[string]any{"success": false}},
|
||||
{name: "report conflicting error", declaration: ReportStatisticsList, tool: "list_report_statistics", response: map[string]any{"success": true, "errorCode": "DENIED", "content": []any{}}},
|
||||
{name: "report missing success", declaration: ReportStatisticsList, tool: "list_report_statistics", response: map[string]any{"content": []any{}}},
|
||||
{name: "report malformed items", declaration: ReportStatisticsList, tool: "list_report_statistics", response: map[string]any{"success": true, "content": []any{"bad"}}},
|
||||
{name: "template transport", declaration: ObjectTemplateList, tool: "list_obj_template"},
|
||||
{name: "template failure", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": false}},
|
||||
{name: "template conflicting error", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": true, "errorCode": "DENIED", "content": map[string]any{}}},
|
||||
{name: "template missing success", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"content": map[string]any{}}},
|
||||
{name: "template content", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": true, "content": []any{}}},
|
||||
{name: "template items", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": true, "content": map[string]any{"result": "bad", "page": 1, "pageSize": 20, "totalCount": 0}}},
|
||||
{name: "template pagination", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": true, "content": map[string]any{"result": []any{}, "page": "1", "pageSize": 20, "totalCount": 0}}},
|
||||
{name: "template page mismatch", declaration: ObjectTemplateList, tool: "list_obj_template", response: map[string]any{"success": true, "content": map[string]any{"result": []any{}, "page": 2, "pageSize": 20, "totalCount": 0}}},
|
||||
{name: "fields transport", declaration: ContractFields, tool: "list_op_contract_fields"},
|
||||
{name: "fields failure", declaration: ContractFields, tool: "list_op_contract_fields", response: map[string]any{"success": false}},
|
||||
{name: "fields conflicting error", declaration: ContractFields, tool: "list_op_contract_fields", response: map[string]any{"success": true, "errorCode": "DENIED", "content": []any{}}},
|
||||
{name: "fields missing success", declaration: ContractFields, tool: "list_op_contract_fields", response: map[string]any{"content": []any{}}},
|
||||
{name: "fields items", declaration: ContractFields, tool: "list_op_contract_fields", response: map[string]any{"success": true, "content": []any{"bad"}}},
|
||||
{name: "rules transport", declaration: UserRules, tool: "get_user_rules"},
|
||||
{name: "rules failure", declaration: UserRules, tool: "get_user_rules", response: map[string]any{"success": false}},
|
||||
{name: "rules conflicting error", declaration: UserRules, tool: "get_user_rules", response: map[string]any{"success": true, "errorCode": "DENIED", "content": map[string]any{}}},
|
||||
{name: "rules missing success", declaration: UserRules, tool: "get_user_rules", response: map[string]any{"content": map[string]any{}}},
|
||||
{name: "rules content", declaration: UserRules, tool: "get_user_rules", response: map[string]any{"success": true, "content": []any{}}},
|
||||
{name: "rules items", declaration: UserRules, tool: "get_user_rules", response: map[string]any{"success": true, "content": map[string]any{"rules": []any{"bad"}}}},
|
||||
{name: "submission transport", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail"},
|
||||
{name: "submission failure", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": false}},
|
||||
{name: "submission conflicting error", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": true, "errorCode": "DENIED", "content": map[string]any{}}},
|
||||
{name: "submission missing success", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"content": map[string]any{}}},
|
||||
{name: "submission content", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": true, "content": []any{}}},
|
||||
{name: "submission items", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": true, "content": map[string]any{"result": "bad", "page": 1, "pageSize": 20, "totalCount": 0}}},
|
||||
{name: "submission pagination", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": true, "content": map[string]any{"result": []any{}, "page": "1", "pageSize": 20, "totalCount": 0}}},
|
||||
{name: "submission size mismatch", declaration: ReportSubmitDetail, args: []string{"--template-id", "template", "--submit-state", "ON_TIME"}, tool: "get_submit_detail", response: map[string]any{"success": true, "content": map[string]any{"result": []any{}, "page": 1, "pageSize": 21, "totalCount": 0}}},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{}
|
||||
if tc.response != nil {
|
||||
caller.responses = map[string][]map[string]any{tc.tool: {tc.response}}
|
||||
}
|
||||
if err := runAgoalCoverage(t, tc.declaration, caller, tc.args...); err == nil {
|
||||
t.Fatal("failure fixture was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_user_rules": {{"success": true, "content": map[string]any{"rules": []any{map[string]any{"id": "rule"}}}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, UserRules, caller); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalBoundedPaginationAndDateExecution(t *testing.T) {
|
||||
responses := make([]map[string]any, 0, agoalSubmissionMaxPages)
|
||||
for page := 1; page <= agoalSubmissionMaxPages; page++ {
|
||||
responses = append(responses, map[string]any{"success": true, "content": map[string]any{
|
||||
"page": page, "pageSize": agoalSubmissionReadPageSize, "totalCount": agoalSubmissionMaxPages + 1,
|
||||
"result": []any{map[string]any{"reportId": "report-" + json.Number(string(rune('A'+page-1))).String(), "user": map[string]any{"id": "user"}}},
|
||||
}})
|
||||
}
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{"get_submit_detail": responses}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, caller,
|
||||
"--template-id", "template", "--submit-state", "ON_TIME", "--keyword", "known"); err == nil {
|
||||
t.Fatal("bounded pagination limit was accepted as complete")
|
||||
}
|
||||
|
||||
scanFailure := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"content": map[string]any{}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, scanFailure,
|
||||
"--template-id", "template", "--submit-state", "ON_TIME", "--keyword", "known"); err == nil {
|
||||
t.Fatal("scan page validation failure was accepted")
|
||||
}
|
||||
|
||||
dateCaller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": 20, "totalCount": 0, "result": []any{},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, dateCaller,
|
||||
"--template-id", "template", "--submit-state", "ON_TIME", "--query-date", "2026-08-24T01:00:00Z"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := dateCaller.calls[0].params["queryDate"]; got != "2026-08-24" {
|
||||
t.Fatalf("queryDate = %#v", got)
|
||||
}
|
||||
|
||||
laterPage := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 1,
|
||||
"result": []any{map[string]any{"reportId": "report", "user": map[string]any{"id": "user", "name": "Different"}}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, laterPage,
|
||||
"--template-id", "template", "--submit-state", "ON_TIME", "--keyword", "missing", "--page", "2"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
maximumPage := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 1,
|
||||
"result": []any{map[string]any{"reportId": "report", "user": map[string]any{"id": "user", "name": "Different"}}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, maximumPage,
|
||||
"--template-id", "template", "--submit-state", "ON_TIME", "--keyword", "missing",
|
||||
"--page", strconv.Itoa(int(^uint(0)>>1))); err != nil {
|
||||
t.Fatalf("maximum page must project an empty local page without overflowing: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -1,434 +0,0 @@
|
||||
// Copyright 2026 Alibaba Group
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
package agoal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd"
|
||||
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/helpers"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/output"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type agoalCoverageCall struct {
|
||||
tool string
|
||||
params map[string]any
|
||||
}
|
||||
|
||||
type agoalCoverageCaller struct {
|
||||
responses map[string][]map[string]any
|
||||
calls []agoalCoverageCall
|
||||
}
|
||||
|
||||
func (c *agoalCoverageCaller) CallTool(_ context.Context, _, tool string, params map[string]any) (*edition.ToolResult, error) {
|
||||
c.calls = append(c.calls, agoalCoverageCall{tool: tool, params: params})
|
||||
queue := c.responses[tool]
|
||||
if len(queue) == 0 {
|
||||
return nil, errors.New("unexpected agoal coverage call: " + tool)
|
||||
}
|
||||
payload := queue[0]
|
||||
c.responses[tool] = queue[1:]
|
||||
encoded, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &edition.ToolResult{Content: []edition.ContentBlock{{Type: "text", Text: string(encoded)}}}, nil
|
||||
}
|
||||
|
||||
func (*agoalCoverageCaller) Format() string { return "json" }
|
||||
func (*agoalCoverageCaller) DryRun() bool { return false }
|
||||
func (*agoalCoverageCaller) Fields() string { return "" }
|
||||
func (*agoalCoverageCaller) JQ() string { return "" }
|
||||
|
||||
func runAgoalCoverage(t *testing.T, declaration shortcut.Shortcut, caller *agoalCoverageCaller, args ...string) error {
|
||||
t.Helper()
|
||||
helpers.InitDeps(caller)
|
||||
root := &cobra.Command{Use: "dws", SilenceErrors: true, SilenceUsage: true}
|
||||
root.PersistentFlags().Bool("yes", false, "")
|
||||
root.PersistentFlags().Bool("dry-run", false, "")
|
||||
root.PersistentFlags().String("format", "json", "")
|
||||
service := &cobra.Command{Use: productAgoal}
|
||||
service.AddCommand(corecmd.New(shortcut.FromShortcut(declaration)))
|
||||
root.AddCommand(service)
|
||||
root.SetOut(io.Discard)
|
||||
root.SetErr(io.Discard)
|
||||
root.SetIn(strings.NewReader(""))
|
||||
root.SetArgs(append([]string{productAgoal, declaration.Command}, args...))
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
func agoalRegistered(command string) (shortcut.Shortcut, bool) {
|
||||
for _, item := range shortcut.All() {
|
||||
if item.Service == productAgoal && item.Command == command {
|
||||
return item, true
|
||||
}
|
||||
}
|
||||
return shortcut.Shortcut{}, false
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalStrictResponseValidation(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
data map[string]any
|
||||
}{
|
||||
{name: "empty", data: nil},
|
||||
{name: "missing success", data: map[string]any{"content": []any{}}},
|
||||
{name: "wrong success", data: map[string]any{"success": "true", "content": []any{}}},
|
||||
{name: "explicit failure", data: map[string]any{"success": false, "content": []any{}}},
|
||||
{name: "conflicting error", data: map[string]any{"success": true, "errorCode": "DENIED", "content": []any{}}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := requireAgoalSuccess(tc.data, "agoal/test"); err == nil {
|
||||
t.Fatal("malformed response was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
value any
|
||||
}{
|
||||
{name: "missing collection", value: nil},
|
||||
{name: "wrong collection", value: map[string]any{}},
|
||||
{name: "bad element", value: []any{"bad"}},
|
||||
{name: "missing id", value: []any{map[string]any{"title": "template"}}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := requireAgoalList(map[string]any{"success": true}, "agoal/test", tc.value, "id"); err == nil {
|
||||
t.Fatal("malformed collection was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalPublicReadsUseExactToolsAndShapes(t *testing.T) {
|
||||
t.Run("report nonempty", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_report_statistics": {{"success": true, "content": []any{map[string]any{"templateId": "template"}}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportStatisticsList, caller, "--keyword", "weekly"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "list_report_statistics", params: map[string]any{"keyword": "weekly"}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report legal zero", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_report_statistics": {{"success": true, "content": []any{}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportStatisticsList, caller, "--keyword", "guaranteed-zero"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("template nonempty page", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_obj_template": {{"success": true, "content": map[string]any{
|
||||
"page": 2, "pageSize": 5, "totalCount": 6,
|
||||
"result": []any{map[string]any{"id": "template"}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ObjectTemplateList, caller, "--keyword", "target", "--page", "2", "--page-size", "5"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "list_obj_template", params: map[string]any{"keyword": "target", "page": 2, "pageSize": 5}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("template rejects false pagination", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_obj_template": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": 20, "totalCount": 0,
|
||||
"result": []any{map[string]any{"id": "impossible"}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ObjectTemplateList, caller); err == nil {
|
||||
t.Fatal("impossible pagination total was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalResidualReads(t *testing.T) {
|
||||
t.Run("contract fields known and guaranteed zero", func(t *testing.T) {
|
||||
items := []map[string]any{{"id": "field-1", "code": "revenue", "title": "Revenue"}}
|
||||
if got := filterAgoalItems(items, "revenue", "id", "code", "title"); len(got) != 1 {
|
||||
t.Fatalf("known field projection = %#v", got)
|
||||
}
|
||||
if got := filterAgoalItems(items, "guaranteed-zero", "id", "code", "title"); len(got) != 0 {
|
||||
t.Fatalf("zero field projection = %#v", got)
|
||||
}
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_op_contract_fields": {{"success": true, "content": []any{items[0]}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ContractFields, caller, "--keyword", "revenue"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "list_op_contract_fields", params: map[string]any{}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("user rules exact filter", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_user_rules": {{"success": true, "content": map[string]any{
|
||||
"rules": []any{map[string]any{"id": "rule-1", "ruleName": "Rule"}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, UserRules, caller, "--user-id", "user", "--rule-id", "rule-1"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "get_user_rules", params: map[string]any{"dingUserId": "user"}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
zero := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_user_rules": {{"success": true, "content": map[string]any{
|
||||
"rules": []any{map[string]any{"id": "rule-1"}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, UserRules, zero, "--rule-id", "guaranteed-zero"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report submission page and privacy identity", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": 20, "totalCount": 1,
|
||||
"result": []any{map[string]any{"reportId": nil, "user": map[string]any{"dingUserId": "user"}}},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "NOT_SUBMITTED", "--page", "1", "--page-size", "20"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "get_submit_detail", params: map[string]any{
|
||||
"templateId": "template", "submitState": "NOT_SUBMITTED", "page": 1, "pageSize": 20,
|
||||
}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report keyword scans then filters locally", func(t *testing.T) {
|
||||
items := []map[string]any{
|
||||
{"reportId": "report-1", "user": map[string]any{"dingUserId": "user-1", "name": "Known Person"}},
|
||||
{"reportId": "report-2", "user": map[string]any{"dingUserId": "user-2", "name": "Another Person"}},
|
||||
}
|
||||
if got := filterAgoalSubmissions(items, "known"); len(got) != 1 {
|
||||
t.Fatalf("known submission projection = %#v", got)
|
||||
}
|
||||
if got := filterAgoalSubmissions(items, "guaranteed-zero"); len(got) != 0 {
|
||||
t.Fatalf("zero submission projection = %#v", got)
|
||||
}
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": map[string]any{
|
||||
"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2,
|
||||
"result": []any{items[0], items[1]},
|
||||
}}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "NOT_SUBMITTED", "--keyword", "guaranteed-zero", "--page", "1", "--page-size", "20"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []agoalCoverageCall{{tool: "get_submit_detail", params: map[string]any{
|
||||
"templateId": "template", "submitState": "NOT_SUBMITTED", "page": 1, "pageSize": agoalSubmissionReadPageSize,
|
||||
}}}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report keyword scan rejects duplicate pages", func(t *testing.T) {
|
||||
item := map[string]any{"reportId": "report-1", "user": map[string]any{"id": "user-1", "name": "Known"}}
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {
|
||||
{"success": true, "content": map[string]any{"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2, "result": []any{item}}},
|
||||
{"success": true, "content": map[string]any{"page": 2, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2, "result": []any{item}}},
|
||||
},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "NOT_SUBMITTED", "--keyword", "known"); err == nil {
|
||||
t.Fatal("duplicate submission pagination was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report keyword scan rejects changing total", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {
|
||||
{"success": true, "content": map[string]any{"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2, "result": []any{map[string]any{"reportId": "report-1", "user": map[string]any{"id": "user-1", "name": "Known"}}}}},
|
||||
{"success": true, "content": map[string]any{"page": 2, "pageSize": agoalSubmissionReadPageSize, "totalCount": 3, "result": []any{map[string]any{"reportId": "report-2", "user": map[string]any{"id": "user-2", "name": "Known"}}}}},
|
||||
},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "NOT_SUBMITTED", "--keyword", "known"); err == nil {
|
||||
t.Fatal("changing pagination total was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report keyword scan rejects stalled page", func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {
|
||||
{"success": true, "content": map[string]any{"page": 1, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2, "result": []any{map[string]any{"reportId": "report-1", "user": map[string]any{"id": "user-1", "name": "Known"}}}}},
|
||||
{"success": true, "content": map[string]any{"page": 2, "pageSize": agoalSubmissionReadPageSize, "totalCount": 2, "result": []any{}}},
|
||||
},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "NOT_SUBMITTED", "--keyword", "known"); err == nil {
|
||||
t.Fatal("stalled pagination was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("report projection drops unreviewed personnel fields", func(t *testing.T) {
|
||||
items, err := requireAgoalSubmissionList([]any{map[string]any{
|
||||
"reportId": "report", "unreviewed": "drop",
|
||||
"user": map[string]any{"id": "user", "name": "Known", "email": "drop"},
|
||||
}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, found := items[0]["unreviewed"]; found {
|
||||
t.Fatal("unreviewed submission field was projected")
|
||||
}
|
||||
user := items[0]["user"].(map[string]any)
|
||||
if _, found := user["email"]; found {
|
||||
t.Fatal("unreviewed personnel field was projected")
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
content map[string]any
|
||||
}{
|
||||
{name: "missing stable user", content: map[string]any{"page": 1, "pageSize": 20, "totalCount": 1, "result": []any{map[string]any{"user": map[string]any{"name": "x"}}}}},
|
||||
{name: "page mismatch", content: map[string]any{"page": 2, "pageSize": 20, "totalCount": 0, "result": []any{}}},
|
||||
{name: "impossible total", content: map[string]any{"page": 1, "pageSize": 20, "totalCount": 0, "result": []any{map[string]any{"user": map[string]any{"id": "user"}}}}},
|
||||
} {
|
||||
t.Run("report rejects "+tc.name, func(t *testing.T) {
|
||||
caller := &agoalCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_submit_detail": {{"success": true, "content": tc.content}},
|
||||
}}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail,
|
||||
caller, "--template-id", "template", "--submit-state", "ON_TIME", "--page", "1", "--page-size", "20"); err == nil {
|
||||
t.Fatal("malformed submission page was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalInvalidInputMakesZeroCalls(t *testing.T) {
|
||||
for _, args := range [][]string{{"--page", "0"}, {"--page-size", "0"}, {"--page-size", "101"}} {
|
||||
caller := &agoalCoverageCaller{}
|
||||
err := runAgoalCoverage(t, ObjectTemplateList, caller, args...)
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) {
|
||||
t.Fatalf("invalid args %v error = %#v", args, err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("invalid args %v called MCP: %#v", args, caller.calls)
|
||||
}
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
{"--template-id", "template", "--submit-state", "ON_TIME", "--page", "0"},
|
||||
{"--template-id", "template", "--submit-state", "ON_TIME", "--page-size", "101"},
|
||||
{"--template-id", "template", "--submit-state", "ON_TIME", "--query-date", "not-a-date"},
|
||||
} {
|
||||
caller := &agoalCoverageCaller{}
|
||||
if err := runAgoalCoverage(t, ReportSubmitDetail, caller, args...); err == nil {
|
||||
t.Fatalf("invalid submission args %v were accepted", args)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("invalid submission args %v called MCP: %#v", args, caller.calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalReviewedInventory(t *testing.T) {
|
||||
total := 0
|
||||
public := 0
|
||||
unavailable := 0
|
||||
for _, item := range shortcut.All() {
|
||||
if item.Service != productAgoal {
|
||||
continue
|
||||
}
|
||||
total++
|
||||
if item.Availability == shortcut.AvailabilityUnavailable {
|
||||
unavailable++
|
||||
if !item.Hidden || shortcut.InPublicCatalog(item.Service, item.Command) {
|
||||
t.Errorf("unavailable %s must remain hidden/non-public", item.Command)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if shortcut.InPublicCatalog(item.Service, item.Command) {
|
||||
public++
|
||||
if item.Hidden || item.Availability != shortcut.AvailabilityAvailable {
|
||||
t.Errorf("public %s visibility/availability = %v/%q", item.Command, item.Hidden, item.Availability)
|
||||
}
|
||||
if item.OutputRollout != output.RolloutUnifiedActive {
|
||||
t.Errorf("public %s rollout = %q", item.Command, item.OutputRollout)
|
||||
}
|
||||
if item.Contract.Result == nil || item.Contract.Interface == nil || strings.TrimSpace(item.Contract.Description) == "" {
|
||||
t.Errorf("public %s has incomplete Contract/Result", item.Command)
|
||||
}
|
||||
if item.Safety.Effect == "" || item.Safety.Risk == "" || item.Safety.Confirmation == "" || item.Safety.Idempotency == "" {
|
||||
t.Errorf("public %s has incomplete Safety", item.Command)
|
||||
}
|
||||
}
|
||||
}
|
||||
if total != 16 || public != 5 || unavailable != 11 {
|
||||
t.Fatalf("agoal inventory total/public/unavailable = %d/%d/%d, want 16/5/11", total, public, unavailable)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageAgoalUnavailableCommandsMakeZeroCalls(t *testing.T) {
|
||||
for _, spec := range unavailableAgoalSpecs {
|
||||
declaration, found := agoalRegistered(spec.command)
|
||||
if !found {
|
||||
t.Fatalf("registered unavailable command missing: %s", spec.command)
|
||||
}
|
||||
args := make([]string, 0)
|
||||
for _, flag := range declaration.Flags {
|
||||
if !flag.Required {
|
||||
continue
|
||||
}
|
||||
args = append(args, "--"+flag.Name)
|
||||
switch flag.Name {
|
||||
case "scope-type":
|
||||
args = append(args, "PERSONAL")
|
||||
case "tracking-period-type":
|
||||
args = append(args, "MONTHLY")
|
||||
case "submit-state":
|
||||
args = append(args, "ON_TIME")
|
||||
default:
|
||||
if flag.Type != shortcut.FlagBool {
|
||||
args = append(args, "fixture")
|
||||
}
|
||||
}
|
||||
}
|
||||
caller := &agoalCoverageCaller{}
|
||||
err := runAgoalCoverage(t, declaration, caller, args...)
|
||||
if err == nil || !strings.Contains(err.Error(), spec.reason) {
|
||||
t.Errorf("%s unavailable error = %v", spec.command, err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Errorf("%s unavailable command called MCP: %#v", spec.command, caller.calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
|
||||
// Service packages — each registers its shortcuts from init().
|
||||
_ "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut/agoal"
|
||||
_ "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut/aisearch"
|
||||
_ "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut/aitable"
|
||||
_ "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut/attendance"
|
||||
|
||||
+276
-1164
File diff suppressed because it is too large
Load Diff
@@ -1,742 +0,0 @@
|
||||
// Copyright 2026 Alibaba Group
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
package devapp
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/helpers"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func devAppSuccessResult(values map[string]any) map[string]any {
|
||||
return map[string]any{"success": true, "result": values}
|
||||
}
|
||||
|
||||
func devAppSuccessList(key string, items []any, more bool, cursor string) map[string]any {
|
||||
result := map[string]any{"success": true, key: items, "hasMore": more}
|
||||
if cursor != "" {
|
||||
result["nextCursor"] = cursor
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppChangedStrictHelpers(t *testing.T) {
|
||||
if devAppContainers(nil) != nil {
|
||||
t.Fatal("nil response unexpectedly produced containers")
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
value any
|
||||
want bool
|
||||
}{
|
||||
{nil, false}, {false, false}, {true, true},
|
||||
{float64(0), false}, {float64(200), false}, {float64(500), true},
|
||||
{"", false}, {"ok", false}, {"SUCCESS", false}, {"denied", true},
|
||||
{map[string]any{}, false}, {map[string]any{"code": 1}, true},
|
||||
{[]any{}, false}, {[]any{"error"}, true}, {struct{}{}, true},
|
||||
} {
|
||||
if got := devAppErrorValue(tc.value); got != tc.want {
|
||||
t.Fatalf("devAppErrorValue(%#v)=%v, want %v", tc.value, got, tc.want)
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := requireDevAppSuccess(map[string]any{
|
||||
"success": true, "result": map[string]any{"versionStatus": "FAILED"},
|
||||
}, "devapp/test"); err != nil {
|
||||
t.Fatalf("successful query with failed business state was rejected: %v", err)
|
||||
}
|
||||
if !devAppOnlyEnvelopeFields(map[string]any{"success": true, "result": map[string]any{}}) {
|
||||
t.Fatal("known envelope was not recognized")
|
||||
}
|
||||
if devAppOnlyEnvelopeFields(map[string]any{"success": true, "business": true}) {
|
||||
t.Fatal("business field was treated as envelope-only")
|
||||
}
|
||||
if _, err := requireDevAppObject(map[string]any{"success": true, "result": map[string]any{}}, "devapp/test"); err == nil {
|
||||
t.Fatal("empty business object was accepted")
|
||||
}
|
||||
|
||||
object := map[string]any{"id": "actual", "name": "actual"}
|
||||
if err := requireDevAppIdentity(object, "devapp/test", map[string]string{"ignored": ""}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := requireDevAppIdentity(object, "devapp/test", map[string]string{"missing": "wanted"}); err == nil {
|
||||
t.Fatal("missing identity was accepted")
|
||||
}
|
||||
if err := requireDevAppIdentity(object, "devapp/test", map[string]string{"id": "wanted"}); err == nil {
|
||||
t.Fatal("mismatched identity was accepted")
|
||||
}
|
||||
if err := requireDevAppFields(object, "devapp/test", map[string]any{"missing": "wanted"}); err == nil {
|
||||
t.Fatal("missing readback field was accepted")
|
||||
}
|
||||
if err := requireDevAppFields(object, "devapp/test", map[string]any{"name": "wanted"}); err == nil {
|
||||
t.Fatal("mismatched readback field was accepted")
|
||||
}
|
||||
if err := requireDevAppFields(object, "devapp/test", map[string]any{"name": "actual"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := requireDevAppStringField(object, "devapp/test", "wanted", "missing"); err == nil {
|
||||
t.Fatal("missing string field was accepted")
|
||||
}
|
||||
|
||||
deep := map[string]any{"success": true, "content": map[string]any{
|
||||
"result": map[string]any{"hasMore": true, "nextCursor": " next "},
|
||||
}}
|
||||
projection, err := devAppListProjection(deep, "items", nil, "devapp/test")
|
||||
if err != nil || projection["nextCursor"] != "next" {
|
||||
t.Fatalf("deep pagination projection=%#v err=%v", projection, err)
|
||||
}
|
||||
if _, err := devAppListProjection(map[string]any{"success": false}, "items", nil, "devapp/test"); err == nil {
|
||||
t.Fatal("failed list envelope was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppChangedReadAndListExecutors(t *testing.T) {
|
||||
t.Run("list all filters and projection", func(t *testing.T) {
|
||||
item := map[string]any{
|
||||
"unified_app_id": "app", "appName": "name", "clientId": "client",
|
||||
"agent_id": "agent", "app_status": "normal", "modified_time": "now",
|
||||
}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app": {devAppSuccessList("apps", []any{item}, true, "next")},
|
||||
}}
|
||||
err := runDevAppCoverage(t, ListApp, caller,
|
||||
"--name", "name", "--app-key", "client", "--app-group-id", "7",
|
||||
"--creator", "owner", "--robot-name", "robot", "--develop-type", "2",
|
||||
"--filter-cool-app", "1", "--sort-type", "gmt_modified", "--sort-order", "desc",
|
||||
"--cursor", "cursor", "--page-size", "9")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := map[string]any{
|
||||
"name": "name", "appKey": "client", "appGroupId": 7, "creator": "owner",
|
||||
"robotName": "robot", "developType": 2, "filterCoolApp": 1,
|
||||
"sortType": "gmt_modified", "sortOrder": "desc", "cursor": "cursor", "pageSize": 9,
|
||||
}
|
||||
if len(caller.calls) != 1 || !reflect.DeepEqual(caller.calls[0].params, want) {
|
||||
t.Fatalf("list params=%#v, want %#v", caller.calls, want)
|
||||
}
|
||||
badPage := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app": {{"success": true, "list": []any{map[string]any{"unifiedAppId": "app"}}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, ListApp, badPage); err == nil {
|
||||
t.Fatal("list without terminal pagination evidence was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
tool string
|
||||
args []string
|
||||
result map[string]any
|
||||
}{
|
||||
{"get", GetApp, "get_dev_app", []string{"--unified-app-id", "app"}, map[string]any{"unifiedAppId": "app", "name": "app"}},
|
||||
{"webapp", WebappGet, "get_extension_webapp_config", []string{"--unified-app-id", "app"}, map[string]any{"unifiedAppId": "app", "homepageUrl": "https://example.invalid"}},
|
||||
{"robot", RobotGet, "get_extension_robot_config", []string{"--unified-app-id", "app"}, map[string]any{"unifiedAppId": "app", "robotStatus": "ONLINE"}},
|
||||
{"version", VersionGet, "get_dev_app_version_detail", []string{"--unified-app-id", "app", "--version-id", "version"}, map[string]any{"unifiedAppId": "app", "versionId": "version"}},
|
||||
{"precheck", VersionCheckApproval, "publish_dev_app_version", []string{"--unified-app-id", "app", "--version-id", "version"}, map[string]any{"unifiedAppId": "app", "versionId": "version", "approvalRequired": false}},
|
||||
{"status", VersionStatus, "get_dev_app_version_status", []string{"--unified-app-id", "app", "--version-id", "version"}, map[string]any{"unifiedAppId": "app", "versionId": "version", "status": "PUBLISHED"}},
|
||||
{"status failed", VersionStatus, "get_dev_app_version_status", []string{"--unified-app-id", "app", "--version-id", "version"}, map[string]any{"unifiedAppId": "app", "versionId": "version", "versionStatus": "FAILED"}},
|
||||
{"status expired", VersionStatus, "get_dev_app_version_status", []string{"--unified-app-id", "app", "--version-id", "version"}, map[string]any{"unifiedAppId": "app", "versionId": "version", "versionStatus": "EXPIRED"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{tc.tool: {devAppSuccessResult(tc.result)}}}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, tc.args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("read transport and identity failure", func(t *testing.T) {
|
||||
if err := runDevAppCoverage(t, GetApp, &devAppCoverageCaller{}, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("transport failure was accepted")
|
||||
}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "other"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, GetApp, caller, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("wrong object identity was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("permission list", func(t *testing.T) {
|
||||
item := map[string]any{
|
||||
"permissionCode": "scope", "permissionName": "name", "interfaceName": "api",
|
||||
"auth_status": "AUTHED", "scope_type": "APP",
|
||||
}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app_permissions": {devAppSuccessList("permissions", []any{item}, false, "")},
|
||||
}}
|
||||
err := runDevAppCoverage(t, PermissionList, caller,
|
||||
"--unified-app-id", "app", "--keyword", "word", "--scope-value", "scope",
|
||||
"--auth-status", "authed", "--scope-type", "app", "--api-status", "OPEN")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, ok := permissionListFirst(item, "missing"); ok {
|
||||
t.Fatal("missing permission field unexpectedly resolved")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("member list success and failures", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app_members": {devAppSuccessList("members", []any{map[string]any{"userId": "user"}}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, MemberList, caller, "--unified-app-id", "app", "--user-id", " user "); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, MemberList, &devAppCoverageCaller{}, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("member transport failure was accepted")
|
||||
}
|
||||
bad := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app_members": {{"success": true, "members": "bad"}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, MemberList, bad, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("malformed member list was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
tool string
|
||||
args []string
|
||||
key string
|
||||
item map[string]any
|
||||
}{
|
||||
{"events", EventList, "list_dev_app_events", []string{"--unified-app-id", "app", "--keyword", "event"}, "events", map[string]any{"event_code": "event", "event_name": "name", "subscribe_status": "ON", "modified_time": "now"}},
|
||||
{"versions", VersionList, "list_dev_app_versions", []string{"--unified-app-id", "app"}, "versions", map[string]any{"version_id": "version", "version_name": "1", "versionStatus": "READY", "remark": "desc", "create_time": "now"}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
tc.tool: {devAppSuccessList(tc.key, []any{tc.item}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, tc.args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
if _, ok := eventListFirst(map[string]any{}, "missing"); ok {
|
||||
t.Fatal("missing event field unexpectedly resolved")
|
||||
}
|
||||
if _, ok := versionListFirst(map[string]any{}, "missing"); ok {
|
||||
t.Fatal("missing version field unexpectedly resolved")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppChangedWriteExecutors(t *testing.T) {
|
||||
t.Run("create all fields and failure branches", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"create_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{
|
||||
"unifiedAppId": "app", "name": "created", "desc": "desc", "iconMediaId": "icon",
|
||||
})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, CreateApp, caller,
|
||||
"--name", "created", "--desc", "desc", "--icon-media-id", "icon", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, CreateApp, &devAppCoverageCaller{}, "--name", "created", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, CreateApp, &devAppCoverageCaller{}, "--name", "created", "--yes"); err == nil {
|
||||
t.Fatal("create transport failure was accepted")
|
||||
}
|
||||
for name, responses := range map[string]map[string][]map[string]any{
|
||||
"receipt object missing": {"create_dev_app": {{"success": true, "result": map[string]any{}}}},
|
||||
"resource id missing": {"create_dev_app": {devAppSuccessResult(map[string]any{"name": "created"})}},
|
||||
"readback failure": {
|
||||
"create_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
},
|
||||
"name mismatch": {
|
||||
"create_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "name": "other"})},
|
||||
},
|
||||
"description mismatch": {
|
||||
"create_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "name": "created", "desc": "other"})},
|
||||
},
|
||||
"icon mismatch": {
|
||||
"create_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "name": "created", "iconMediaId": "other"})},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
args := []string{"--name", "created", "--yes"}
|
||||
if strings.Contains(name, "description") {
|
||||
args = append(args, "--desc", "desc")
|
||||
}
|
||||
if strings.Contains(name, "icon") {
|
||||
args = append(args, "--icon-media-id", "icon")
|
||||
}
|
||||
if err := runDevAppCoverage(t, CreateApp, &devAppCoverageCaller{responses: responses}, args...); err == nil {
|
||||
t.Fatal("invalid create sequence was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update all fields and dry run", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"update_dev_app": {map[string]any{"success": true}},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{
|
||||
"unifiedAppId": "app", "name": "new", "desc": "desc", "iconMediaId": "icon",
|
||||
})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, UpdateApp, caller,
|
||||
"--unified-app-id", "app", "--name", "new", "--desc", "desc", "--icon-media-id", "icon", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, UpdateApp, &devAppCoverageCaller{},
|
||||
"--unified-app-id", "app", "--name", "new", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
bad := &devAppCoverageCaller{responses: map[string][]map[string]any{"update_dev_app": {map[string]any{"success": true}}}}
|
||||
if err := runDevAppCoverage(t, UpdateApp, bad, "--unified-app-id", "app", "--name", "new", "--yes"); err == nil {
|
||||
t.Fatal("update readback failure was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete guards and bounded readback", func(t *testing.T) {
|
||||
if err := runDevAppCoverage(t, DeleteApp, &devAppCoverageCaller{}, "--unified-app-id", "app", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := verifyDeletedDevApp(shortcut.RuntimeContextForTest(&cobra.Command{Use: "+delete"}, DeleteApp), "app", ""); err == nil {
|
||||
t.Fatal("delete verification without selector was accepted")
|
||||
}
|
||||
missingSelector := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, missingSelector, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete without appKey was accepted")
|
||||
}
|
||||
writeFailure := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appKey": "key"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, writeFailure, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete transport failure was accepted")
|
||||
}
|
||||
stillPresent := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appKey": "key"})},
|
||||
"delete_dev_app": {map[string]any{"success": true}},
|
||||
"list_dev_app": {devAppSuccessList("list", []any{map[string]any{"unifiedAppId": "app"}}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, stillPresent, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete with present readback was accepted")
|
||||
}
|
||||
stalled := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appKey": "key"})},
|
||||
"delete_dev_app": {map[string]any{"success": true}},
|
||||
"list_dev_app": {
|
||||
devAppSuccessList("list", []any{map[string]any{"unifiedAppId": "other"}}, true, "same"),
|
||||
devAppSuccessList("list", []any{map[string]any{"unifiedAppId": "other"}}, true, "same"),
|
||||
},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, stalled, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete stalled pagination was accepted")
|
||||
}
|
||||
malformed := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appKey": "key"})},
|
||||
"delete_dev_app": {map[string]any{"success": true}},
|
||||
"list_dev_app": {{"success": true, "list": "bad", "hasMore": false}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, malformed, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete malformed readback was accepted")
|
||||
}
|
||||
badPage := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appKey": "key"})},
|
||||
"delete_dev_app": {map[string]any{"success": true}},
|
||||
"list_dev_app": {{"success": true, "list": []any{map[string]any{"unifiedAppId": "other"}}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, badPage, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("delete pagination without termination was accepted")
|
||||
}
|
||||
pages := make([]map[string]any, 0, devAppMaxReadbackPages)
|
||||
for page := 0; page < devAppMaxReadbackPages; page++ {
|
||||
pages = append(pages, devAppSuccessList("list", []any{map[string]any{"unifiedAppId": "other"}}, true, "cursor-"+string(rune('a'+page))))
|
||||
}
|
||||
pageLimitCaller := &devAppCoverageCaller{responses: map[string][]map[string]any{"list_dev_app": pages}}
|
||||
helpers.InitDeps(pageLimitCaller)
|
||||
if err := verifyDeletedDevApp(shortcut.RuntimeContextForTest(&cobra.Command{Use: "+delete"}, DeleteApp), "app", "key"); err == nil {
|
||||
t.Fatal("delete verification page limit was accepted")
|
||||
}
|
||||
helpers.InitDeps(&devAppCoverageCaller{})
|
||||
if err := verifyDeletedDevApp(shortcut.RuntimeContextForTest(&cobra.Command{Use: "+delete"}, DeleteApp), "app", "key"); err == nil {
|
||||
t.Fatal("delete verification transport failure was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("credentials require client id", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app_credentials": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appSecret": "secret"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, GetCredentials, caller, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("credential without client id was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("webapp all fields and failures", func(t *testing.T) {
|
||||
args := []string{"--unified-app-id", "app", "--h5-page-type", "H5", "--homepage-url", "https://example.invalid/h5", "--pc-homepage-url", "https://example.invalid/pc", "--omp-url", "https://example.invalid/omp", "--yes"}
|
||||
resource := map[string]any{"unifiedAppId": "app", "h5PageType": "H5", "homepageUrl": "https://example.invalid/h5", "pcHomepageUrl": "https://example.invalid/pc", "ompUrl": "https://example.invalid/omp"}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_webapp_config": {map[string]any{"success": true}},
|
||||
"get_extension_webapp_config": {devAppSuccessResult(resource)},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, WebappConfig, caller, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, WebappConfig, &devAppCoverageCaller{}, "--unified-app-id", "app", "--homepage-url", "https://example.invalid", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, WebappConfig, &devAppCoverageCaller{}, args...); err == nil {
|
||||
t.Fatal("webapp write failure was accepted")
|
||||
}
|
||||
badRead := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_webapp_config": {map[string]any{"success": true}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, WebappConfig, badRead, args...); err == nil {
|
||||
t.Fatal("webapp readback failure was accepted")
|
||||
}
|
||||
mismatch := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_webapp_config": {map[string]any{"success": true}},
|
||||
"get_extension_webapp_config": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "h5PageType": "other"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, WebappConfig, mismatch, "--unified-app-id", "app", "--h5-page-type", "H5", "--yes"); err == nil {
|
||||
t.Fatal("webapp mismatch was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppChangedRobotEventAndVersionBranches(t *testing.T) {
|
||||
t.Run("robot validate and all fields", func(t *testing.T) {
|
||||
for _, args := range [][]string{
|
||||
{"--unified-app-id", "app", "--skills", "skill", "--yes"},
|
||||
{"--unified-app-id", "app", "--add-scope=false", "--yes"},
|
||||
} {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "skills": []any{"skill"}, "addScope": false})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, caller, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
args := []string{"--unified-app-id", "app", "--name", "bot", "--brief", "brief", "--desc", "desc", "--icon-media-id", "icon", "--outgoing-url", "https://example.invalid/out", "--event-callback-url", "https://example.invalid/event", "--mode", "STREAM", "--skills", "skill", "--add-scope=false", "--disable-ssl-verify=false", "--yes"}
|
||||
resource := map[string]any{"unifiedAppId": "app", "name": "bot", "brief": "brief", "desc": "desc", "iconMediaId": "icon", "outgoingUrl": "https://example.invalid/out", "eventCallbackUrl": "https://example.invalid/event", "mode": "STREAM", "skills": []string{"skill"}, "addScope": false, "disableSSLVerify": false}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(resource)},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, caller, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, RobotConfig, &devAppCoverageCaller{}, "--unified-app-id", "app", "--name", "bot", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, RobotConfig, &devAppCoverageCaller{}, args...); err == nil {
|
||||
t.Fatal("robot write failure was accepted")
|
||||
}
|
||||
badRead := &devAppCoverageCaller{responses: map[string][]map[string]any{"set_extension_robot_config": {map[string]any{"success": true}}}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, badRead, args...); err == nil {
|
||||
t.Fatal("robot readback failure was accepted")
|
||||
}
|
||||
mismatch := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "name": "other"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, mismatch, "--unified-app-id", "app", "--name", "bot", "--yes"); err == nil {
|
||||
t.Fatal("robot mismatch was accepted")
|
||||
}
|
||||
boolMismatch := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "addScope": true})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, boolMismatch, "--unified-app-id", "app", "--add-scope=false", "--yes"); err == nil {
|
||||
t.Fatal("robot boolean mismatch was accepted")
|
||||
}
|
||||
skillsMismatch := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "skills": []string{"other"}})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotConfig, skillsMismatch, "--unified-app-id", "app", "--skills", "skill", "--yes"); err == nil {
|
||||
t.Fatal("robot skills mismatch was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("status previews and readback failures", func(t *testing.T) {
|
||||
if err := runDevAppCoverage(t, EnableApp, &devAppCoverageCaller{}, "--unified-app-id", "app", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
readFailure := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"enable_dev_app": {map[string]any{"success": true}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EnableApp, readFailure, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("app status readback failure was accepted")
|
||||
}
|
||||
mismatch := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"enable_dev_app": {map[string]any{"success": true}},
|
||||
"get_dev_app": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "appStatus": "disabled"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EnableApp, mismatch, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("app status mismatch was accepted")
|
||||
}
|
||||
if err := runDevAppCoverage(t, RobotEnable, &devAppCoverageCaller{}, "--unified-app-id", "app", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
robotReadFailure := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"enable_dev_app_robot": {map[string]any{"success": true}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, RobotEnable, robotReadFailure, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("robot status readback failure was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("member mutations validate receipts and exact readback", func(t *testing.T) {
|
||||
member := map[string]any{"userId": "user", "memberType": "DEVELOPER"}
|
||||
add := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"add_dev_app_members": {{"success": true}},
|
||||
"list_dev_app_members": {devAppSuccessList("members", []any{member}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, MemberAdd, add,
|
||||
"--unified-app-id", "app", "--user-ids", " user ", "--member-type", " DEVELOPER ", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(add.calls) != 2 || add.calls[0].tool != "add_dev_app_members" ||
|
||||
!reflect.DeepEqual(add.calls[0].params["userIds"], []string{"user"}) ||
|
||||
add.calls[0].params["memberType"] != "DEVELOPER" || add.calls[1].tool != "list_dev_app_members" {
|
||||
t.Fatalf("member add calls=%#v", add.calls)
|
||||
}
|
||||
|
||||
remove := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"remove_dev_app_members": {{"success": true}},
|
||||
"list_dev_app_members": {devAppSuccessList("members", []any{map[string]any{"userId": "owner", "memberType": "OWNER"}}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, MemberRemove, remove,
|
||||
"--unified-app-id", "app", "--user-ids", "user", "--member-type", "DEVELOPER", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(remove.calls) != 2 || remove.calls[0].tool != "remove_dev_app_members" || remove.calls[1].tool != "list_dev_app_members" {
|
||||
t.Fatalf("member remove calls=%#v", remove.calls)
|
||||
}
|
||||
|
||||
for _, declaration := range []shortcut.Shortcut{MemberAdd, MemberRemove} {
|
||||
unconfirmed := &devAppCoverageCaller{}
|
||||
if err := runDevAppCoverage(t, declaration, unconfirmed,
|
||||
"--unified-app-id", "app", "--user-ids", "user", "--member-type", "DEVELOPER"); err == nil {
|
||||
t.Fatalf("%s succeeded without confirmation", declaration.Command)
|
||||
}
|
||||
if len(unconfirmed.calls) != 0 {
|
||||
t.Fatalf("%s made remote calls before confirmation: %#v", declaration.Command, unconfirmed.calls)
|
||||
}
|
||||
dryRun := &devAppCoverageCaller{}
|
||||
if err := runDevAppCoverage(t, declaration, dryRun,
|
||||
"--unified-app-id", "app", "--user-ids", "user", "--member-type", "DEVELOPER", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(dryRun.calls) != 0 {
|
||||
t.Fatalf("%s dry-run made remote calls: %#v", declaration.Command, dryRun.calls)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("member mutations reject invalid input and false success", func(t *testing.T) {
|
||||
for _, values := range [][]string{nil, {""}, {"user", "user"}} {
|
||||
if _, err := validatedDevAppValues(values, "--user-ids"); err == nil {
|
||||
t.Fatalf("invalid member IDs accepted: %#v", values)
|
||||
}
|
||||
}
|
||||
if _, err := validatedDevAppMemberType(" "); err == nil {
|
||||
t.Fatal("blank member type was accepted")
|
||||
}
|
||||
if got, err := validatedDevAppMemberType(" DEVELOPER "); err != nil || got != "DEVELOPER" {
|
||||
t.Fatalf("normalized member type=%q err=%v", got, err)
|
||||
}
|
||||
for _, args := range [][]string{
|
||||
{"--unified-app-id", "app", "--user-ids", "user,user", "--member-type", "DEVELOPER", "--yes"},
|
||||
{"--unified-app-id", "app", "--user-ids", "user", "--member-type", " ", "--yes"},
|
||||
} {
|
||||
caller := &devAppCoverageCaller{}
|
||||
if err := runDevAppCoverage(t, MemberAdd, caller, args...); err == nil {
|
||||
t.Fatalf("invalid member arguments accepted: %#v", args)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("invalid member arguments made calls: %#v", caller.calls)
|
||||
}
|
||||
}
|
||||
|
||||
baseArgs := []string{"--unified-app-id", "app", "--user-ids", "user", "--member-type", "DEVELOPER", "--yes"}
|
||||
badAddResponses := []map[string][]map[string]any{
|
||||
{},
|
||||
{"add_dev_app_members": {{"success": false}}},
|
||||
{"add_dev_app_members": {{"success": true}}},
|
||||
{"add_dev_app_members": {{"success": true}}, "list_dev_app_members": {{"success": true, "members": "bad"}}},
|
||||
{"add_dev_app_members": {{"success": true}}, "list_dev_app_members": {devAppSuccessList("members", []any{map[string]any{"userId": "other", "memberType": "DEVELOPER"}}, false, "")}},
|
||||
{"add_dev_app_members": {{"success": true}}, "list_dev_app_members": {devAppSuccessList("members", []any{map[string]any{"userId": "user"}}, false, "")}},
|
||||
{"add_dev_app_members": {{"success": true}}, "list_dev_app_members": {devAppSuccessList("members", []any{map[string]any{"userId": "user", "memberType": "OWNER"}}, false, "")}},
|
||||
{"add_dev_app_members": {{"success": true}}, "list_dev_app_members": {devAppSuccessList("members", []any{
|
||||
map[string]any{"userId": "user", "memberType": "DEVELOPER"},
|
||||
map[string]any{"userId": "user", "memberType": "DEVELOPER"},
|
||||
}, false, "")}},
|
||||
}
|
||||
for index, responses := range badAddResponses {
|
||||
if err := runDevAppCoverage(t, MemberAdd, &devAppCoverageCaller{responses: responses}, baseArgs...); err == nil {
|
||||
t.Fatalf("member add false success case %d was accepted", index)
|
||||
}
|
||||
}
|
||||
|
||||
removeStillPresent := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"remove_dev_app_members": {{"success": true}},
|
||||
"list_dev_app_members": {devAppSuccessList("members", []any{
|
||||
map[string]any{"userId": "user", "memberType": "DEVELOPER"},
|
||||
}, false, "")},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, MemberRemove, removeStillPresent, baseArgs...); err == nil {
|
||||
t.Fatal("member remove accepted target still present")
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
writeTool string
|
||||
status any
|
||||
}{
|
||||
{"enable missing status", RobotEnable, "enable_dev_app_robot", nil},
|
||||
{"disable wrong status", RobotDisable, "disable_dev_app_robot", "ONLINE"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
resource := map[string]any{"unifiedAppId": "app"}
|
||||
if tc.status != nil {
|
||||
resource["robotStatus"] = tc.status
|
||||
}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
tc.writeTool: {map[string]any{"success": true}},
|
||||
"get_extension_robot_config": {devAppSuccessResult(resource)},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, "--unified-app-id", "app", "--yes"); err == nil {
|
||||
t.Fatal("invalid robot status was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("event validation and readback failures", func(t *testing.T) {
|
||||
for _, values := range [][]string{nil, {""}, {"event", "event"}} {
|
||||
if _, err := validatedDevAppValues(values, "--event-codes"); err == nil {
|
||||
t.Fatalf("invalid event values accepted: %#v", values)
|
||||
}
|
||||
}
|
||||
if got, err := validatedDevAppValues([]string{" event "}, "--event-codes"); err != nil || !reflect.DeepEqual(got, []string{"event"}) {
|
||||
t.Fatalf("normalized event values=%#v err=%v", got, err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, &devAppCoverageCaller{}, "--unified-app-id", "app", "--event-codes", "event", "--yes"); err == nil {
|
||||
t.Fatal("event write failure was accepted")
|
||||
}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, &devAppCoverageCaller{}, "--unified-app-id", "app", "--event-codes", "event", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, listResponses := range map[string][]map[string]any{
|
||||
"transport": nil,
|
||||
"malformed": {{"success": true, "list": "bad", "hasMore": false}},
|
||||
"projection": {devAppSuccessList("list", []any{map[string]any{"eventCode": "other"}}, true, "")},
|
||||
"stalled": {devAppSuccessList("list", []any{map[string]any{"eventCode": "other"}}, true, "same")},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"subscribe_dev_app_events": {map[string]any{"success": true}},
|
||||
"list_dev_app_events": listResponses,
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, caller, "--unified-app-id", "app", "--event-codes", "event", "--yes"); err == nil {
|
||||
t.Fatal("invalid event readback was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
stalled := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"subscribe_dev_app_events": {map[string]any{"success": true}},
|
||||
"list_dev_app_events": {
|
||||
devAppSuccessList("list", []any{map[string]any{"eventCode": "other"}}, true, "same"),
|
||||
devAppSuccessList("list", []any{map[string]any{"eventCode": "other"}}, true, "same"),
|
||||
},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, stalled, "--unified-app-id", "app", "--event-codes", "event", "--yes"); err == nil {
|
||||
t.Fatal("stalled event cursor was accepted")
|
||||
}
|
||||
pages := make([]map[string]any, 0, devAppMaxReadbackPages)
|
||||
for page := 0; page < devAppMaxReadbackPages; page++ {
|
||||
pages = append(pages, devAppSuccessList("list", []any{map[string]any{"eventCode": "other"}}, true, "cursor-"+string(rune('a'+page))))
|
||||
}
|
||||
pageLimit := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"subscribe_dev_app_events": {map[string]any{"success": true}},
|
||||
"list_dev_app_events": pages,
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, pageLimit, "--unified-app-id", "app", "--event-codes", "event", "--yes"); err == nil {
|
||||
t.Fatal("event readback page limit was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("version create all fields and failures", func(t *testing.T) {
|
||||
args := []string{"--unified-app-id", "app", "--version", "1.0", "--desc", "desc", "--yes"}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"create_dev_app_version": {devAppSuccessResult(map[string]any{"versionId": "version"})},
|
||||
"get_dev_app_version_detail": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "versionId": "version", "version": "1.0", "desc": "desc"})},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, VersionCreate, caller, args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, VersionCreate, &devAppCoverageCaller{}, "--unified-app-id", "app", "--desc", "desc", "--dry-run"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runDevAppCoverage(t, VersionCreate, &devAppCoverageCaller{}, args...); err == nil {
|
||||
t.Fatal("version write failure was accepted")
|
||||
}
|
||||
for name, responses := range map[string]map[string][]map[string]any{
|
||||
"receipt object": {"create_dev_app_version": {{"success": true, "result": map[string]any{}}}},
|
||||
"missing id": {"create_dev_app_version": {devAppSuccessResult(map[string]any{"version": "1.0"})}},
|
||||
"readback": {"create_dev_app_version": {devAppSuccessResult(map[string]any{"versionId": "version"})}},
|
||||
"version mismatch": {
|
||||
"create_dev_app_version": {devAppSuccessResult(map[string]any{"versionId": "version"})},
|
||||
"get_dev_app_version_detail": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "versionId": "version", "version": "other"})},
|
||||
},
|
||||
"description mismatch": {
|
||||
"create_dev_app_version": {devAppSuccessResult(map[string]any{"versionId": "version"})},
|
||||
"get_dev_app_version_detail": {devAppSuccessResult(map[string]any{"unifiedAppId": "app", "versionId": "version", "version": "1.0", "desc": "other"})},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if err := runDevAppCoverage(t, VersionCreate, &devAppCoverageCaller{responses: responses}, args...); err == nil {
|
||||
t.Fatal("invalid version create sequence was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("list pagination projection failures", func(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
declaration shortcut.Shortcut
|
||||
tool string
|
||||
args []string
|
||||
key string
|
||||
idKey string
|
||||
}{
|
||||
{PermissionList, "list_dev_app_permissions", []string{"--unified-app-id", "app"}, "permissions", "scopeValue"},
|
||||
{EventList, "list_dev_app_events", []string{"--unified-app-id", "app"}, "events", "eventCode"},
|
||||
{VersionList, "list_dev_app_versions", []string{"--unified-app-id", "app"}, "versions", "versionId"},
|
||||
} {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
tc.tool: {{"success": true, tc.key: []any{map[string]any{tc.idKey: "id"}}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, tc.args...); err == nil {
|
||||
t.Fatalf("%s accepted missing pagination", tc.declaration.Command)
|
||||
}
|
||||
}
|
||||
malformedEvent := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"list_dev_app_events": {{"success": true, "events": "bad", "hasMore": false}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EventList, malformedEvent, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("malformed event collection was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,527 +0,0 @@
|
||||
// Copyright 2026 Alibaba Group
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
|
||||
package devapp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd"
|
||||
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/helpers"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/output"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/shortcut"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type devAppCoverageCall struct {
|
||||
tool string
|
||||
params map[string]any
|
||||
}
|
||||
|
||||
type devAppCoverageCaller struct {
|
||||
responses map[string][]map[string]any
|
||||
calls []devAppCoverageCall
|
||||
}
|
||||
|
||||
func (c *devAppCoverageCaller) CallTool(_ context.Context, _, tool string, params map[string]any) (*edition.ToolResult, error) {
|
||||
c.calls = append(c.calls, devAppCoverageCall{tool: tool, params: params})
|
||||
queue := c.responses[tool]
|
||||
if len(queue) == 0 {
|
||||
return nil, errors.New("unexpected devapp coverage call: " + tool)
|
||||
}
|
||||
payload := queue[0]
|
||||
c.responses[tool] = queue[1:]
|
||||
encoded, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &edition.ToolResult{Content: []edition.ContentBlock{{Type: "text", Text: string(encoded)}}}, nil
|
||||
}
|
||||
|
||||
func (*devAppCoverageCaller) Format() string { return "json" }
|
||||
func (*devAppCoverageCaller) DryRun() bool { return false }
|
||||
func (*devAppCoverageCaller) Fields() string { return "" }
|
||||
func (*devAppCoverageCaller) JQ() string { return "" }
|
||||
|
||||
func runDevAppCoverage(t *testing.T, declaration shortcut.Shortcut, caller *devAppCoverageCaller, args ...string) error {
|
||||
t.Helper()
|
||||
helpers.InitDeps(caller)
|
||||
root := &cobra.Command{Use: "dws", SilenceErrors: true, SilenceUsage: true}
|
||||
root.PersistentFlags().Bool("yes", false, "")
|
||||
root.PersistentFlags().Bool("dry-run", false, "")
|
||||
root.PersistentFlags().String("format", "json", "")
|
||||
service := &cobra.Command{Use: "devapp"}
|
||||
service.AddCommand(corecmd.New(shortcut.FromShortcut(declaration)))
|
||||
root.AddCommand(service)
|
||||
root.SetOut(io.Discard)
|
||||
root.SetErr(io.Discard)
|
||||
root.SetIn(strings.NewReader(""))
|
||||
root.SetArgs(append([]string{"devapp", declaration.Command}, args...))
|
||||
return root.Execute()
|
||||
}
|
||||
|
||||
func runDevAppUnifiedCoverage(t *testing.T, declaration shortcut.Shortcut, caller *devAppCoverageCaller, args ...string) ([]byte, error) {
|
||||
t.Helper()
|
||||
helpers.InitDeps(caller)
|
||||
ctx, _ := output.WithResultStore(context.Background())
|
||||
root := &cobra.Command{Use: "dws", SilenceErrors: true, SilenceUsage: true}
|
||||
root.SetContext(ctx)
|
||||
root.PersistentFlags().Bool("yes", false, "")
|
||||
root.PersistentFlags().Bool("dry-run", false, "")
|
||||
root.PersistentFlags().String("format", "json", "")
|
||||
service := &cobra.Command{Use: "devapp"}
|
||||
service.AddCommand(corecmd.New(shortcut.FromShortcut(declaration)))
|
||||
root.AddCommand(service)
|
||||
var stdout bytes.Buffer
|
||||
root.SetOut(&stdout)
|
||||
root.SetErr(io.Discard)
|
||||
root.SetIn(strings.NewReader(""))
|
||||
root.PersistentPostRunE = func(executed *cobra.Command, _ []string) error {
|
||||
_, _, err := output.EmitStoredResult(executed)
|
||||
return err
|
||||
}
|
||||
root.SetArgs(append([]string{"devapp", declaration.Command}, args...))
|
||||
if err := root.Execute(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return stdout.Bytes(), nil
|
||||
}
|
||||
|
||||
func devAppRegistered(command string) (shortcut.Shortcut, bool) {
|
||||
for _, item := range shortcut.All() {
|
||||
if item.Service == "devapp" && item.Command == command {
|
||||
return item, true
|
||||
}
|
||||
}
|
||||
return shortcut.Shortcut{}, false
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppStrictResponseValidation(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
data map[string]any
|
||||
}{
|
||||
{name: "empty", data: nil},
|
||||
{name: "missing success", data: map[string]any{"list": []any{}}},
|
||||
{name: "wrong success type", data: map[string]any{"success": "true", "list": []any{}}},
|
||||
{name: "explicit failure", data: map[string]any{"success": false, "list": []any{}}},
|
||||
{name: "conflicting error", data: map[string]any{"success": true, "errorCode": "DENIED", "list": []any{}}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := listAppProject(tc.data); err == nil {
|
||||
t.Fatal("malformed response was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
data map[string]any
|
||||
}{
|
||||
{name: "missing collection", data: map[string]any{"success": true, "hasMore": false}},
|
||||
{name: "wrong collection type", data: map[string]any{"success": true, "list": map[string]any{}, "hasMore": false}},
|
||||
{name: "bad element", data: map[string]any{"success": true, "list": []any{"bad"}, "hasMore": false}},
|
||||
{name: "missing stable id", data: map[string]any{"success": true, "list": []any{map[string]any{"name": "app"}}, "hasMore": false}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := listAppProject(tc.data); err == nil {
|
||||
t.Fatal("malformed collection was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
valid := []map[string]any{{"unifiedAppId": "app"}}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
data map[string]any
|
||||
}{
|
||||
{name: "missing pagination", data: map[string]any{"success": true}},
|
||||
{name: "wrong has more type", data: map[string]any{"success": true, "hasMore": "false"}},
|
||||
{name: "cursor without has more", data: map[string]any{"success": true, "nextCursor": "next"}},
|
||||
{name: "more without cursor", data: map[string]any{"success": true, "hasMore": true}},
|
||||
{name: "wrong cursor type", data: map[string]any{"success": true, "hasMore": true, "nextCursor": 1}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if _, err := devAppListProjection(tc.data, "apps", valid, "devapp/test"); err == nil {
|
||||
t.Fatal("malformed pagination was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppConfirmationAndValidationPrecedeCalls(t *testing.T) {
|
||||
writes := []struct {
|
||||
declaration shortcut.Shortcut
|
||||
args []string
|
||||
}{
|
||||
{CreateApp, []string{"--name", "app"}},
|
||||
{UpdateApp, []string{"--unified-app-id", "app", "--name", "new"}},
|
||||
{DeleteApp, []string{"--unified-app-id", "app"}},
|
||||
{EnableApp, []string{"--unified-app-id", "app"}},
|
||||
{DisableApp, []string{"--unified-app-id", "app"}},
|
||||
{WebappConfig, []string{"--unified-app-id", "app", "--homepage-url", "https://example.invalid"}},
|
||||
{RobotConfig, []string{"--unified-app-id", "app", "--name", "bot"}},
|
||||
{RobotEnable, []string{"--unified-app-id", "app"}},
|
||||
{RobotDisable, []string{"--unified-app-id", "app"}},
|
||||
{EventSubscribe, []string{"--unified-app-id", "app", "--event-codes", "event.one"}},
|
||||
{VersionCreate, []string{"--unified-app-id", "app", "--desc", "version"}},
|
||||
}
|
||||
for _, tc := range writes {
|
||||
t.Run(tc.declaration.Command, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{}
|
||||
err := runDevAppCoverage(t, tc.declaration, caller, tc.args...)
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) || typed.Reason != "confirmation_required" {
|
||||
t.Fatalf("unconfirmed error = %#v, want confirmation_required", err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("unconfirmed command called MCP: %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
declaration shortcut.Shortcut
|
||||
args []string
|
||||
}{
|
||||
{UpdateApp, []string{"--unified-app-id", "app", "--yes"}},
|
||||
{WebappConfig, []string{"--unified-app-id", "app", "--yes"}},
|
||||
{RobotConfig, []string{"--unified-app-id", "app", "--yes"}},
|
||||
{EventSubscribe, []string{"--unified-app-id", "app", "--event-codes", "event.one,event.one", "--yes"}},
|
||||
} {
|
||||
caller := &devAppCoverageCaller{}
|
||||
err := runDevAppCoverage(t, tc.declaration, caller, tc.args...)
|
||||
var typed *apperrors.Error
|
||||
if !errors.As(err, &typed) || typed.Reason == "confirmation_required" {
|
||||
t.Fatalf("invalid input error = %#v", err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Fatalf("invalid input called MCP: %#v", caller.calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppResidualAdapters(t *testing.T) {
|
||||
t.Run("credentials require stable identity client and secret", func(t *testing.T) {
|
||||
valid := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app_credentials": {{"success": true, "result": map[string]any{
|
||||
"unifiedAppId": "app", "appKey": "client", "appSecret": "secret",
|
||||
}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, GetCredentials, valid, "--unified-app-id", "app"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
missingSecret := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app_credentials": {{"success": true, "result": map[string]any{
|
||||
"unifiedAppId": "app", "appKey": "client",
|
||||
}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, GetCredentials, missingSecret, "--unified-app-id", "app"); err == nil {
|
||||
t.Fatal("credential response without a secret was accepted")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("credentials unified data matches declared sensitive paths", func(t *testing.T) {
|
||||
declaration, ok := devAppRegistered("+credentials-get")
|
||||
if !ok || declaration.OutputRollout != output.RolloutUnifiedActive {
|
||||
t.Fatalf("registered credentials shortcut is not unified: found=%t rollout=%q", ok, declaration.OutputRollout)
|
||||
}
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app_credentials": {{"success": true, "result": map[string]any{
|
||||
"unifiedAppId": "app", "appKey": "client", "appSecret": "test-app-secret",
|
||||
"clientSecret": "test-client-secret", "secret": "test-secret",
|
||||
}}},
|
||||
}}
|
||||
encoded, err := runDevAppUnifiedCoverage(t, declaration, caller, "--unified-app-id", "app")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var envelope map[string]any
|
||||
if err := json.Unmarshal(encoded, &envelope); err != nil {
|
||||
t.Fatalf("unified output is not JSON: %v", err)
|
||||
}
|
||||
data, ok := envelope["data"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("unified output data type = %T, want object", envelope["data"])
|
||||
}
|
||||
if _, nested := data["result"]; nested {
|
||||
t.Fatal("credential business object is nested under data.result; declared sensitive paths would miss it")
|
||||
}
|
||||
for _, path := range declaration.Contract.Result.SensitivePaths {
|
||||
if value, present := data[path]; !present || strings.TrimSpace(fmt.Sprint(value)) == "" {
|
||||
t.Fatalf("declared sensitive path %q does not resolve to a non-empty data field", path)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("member projector supports known and guaranteed zero", func(t *testing.T) {
|
||||
members := []any{
|
||||
map[string]any{"userId": "user-1", "memberType": "OWNER"},
|
||||
map[string]any{"userId": "user-2", "memberType": "DEVELOPER"},
|
||||
}
|
||||
if got := projectDevAppMembers(members, "user-1"); len(got) != 1 || got[0]["userId"] != "user-1" {
|
||||
t.Fatalf("known member projection = %#v", got)
|
||||
}
|
||||
if got := projectDevAppMembers(members, "guaranteed-missing"); len(got) != 0 {
|
||||
t.Fatalf("zero member projection = %#v", got)
|
||||
}
|
||||
for _, bad := range []map[string]any{
|
||||
{"success": true, "members": []any{"bad"}},
|
||||
{"success": true, "members": []any{map[string]any{"name": "missing-id"}}},
|
||||
} {
|
||||
if _, _, err := requireDevAppCollection(bad, "devapp/list_dev_app_members", []string{"userId"}, "members"); err == nil {
|
||||
t.Fatalf("malformed member response accepted: %#v", bad)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
args []string
|
||||
responses map[string][]map[string]any
|
||||
wantTools []string
|
||||
}{
|
||||
{
|
||||
name: "robot config", declaration: RobotConfig,
|
||||
args: []string{"--unified-app-id", "app", "--name", "bot", "--mode", "STREAM", "--yes"},
|
||||
responses: map[string][]map[string]any{
|
||||
"set_extension_robot_config": {{"success": true}},
|
||||
"get_extension_robot_config": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "name": "bot", "mode": "STREAM"}}},
|
||||
},
|
||||
wantTools: []string{"set_extension_robot_config", "get_extension_robot_config"},
|
||||
},
|
||||
{
|
||||
name: "robot enable", declaration: RobotEnable,
|
||||
args: []string{"--unified-app-id", "app", "--yes"},
|
||||
responses: map[string][]map[string]any{
|
||||
"enable_dev_app_robot": {{"success": true}},
|
||||
"get_extension_robot_config": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "robotStatus": "ONLINE"}}},
|
||||
},
|
||||
wantTools: []string{"enable_dev_app_robot", "get_extension_robot_config"},
|
||||
},
|
||||
{
|
||||
name: "robot disable", declaration: RobotDisable,
|
||||
args: []string{"--unified-app-id", "app", "--yes"},
|
||||
responses: map[string][]map[string]any{
|
||||
"disable_dev_app_robot": {{"success": true}},
|
||||
"get_extension_robot_config": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "robotStatus": "UNCONFIGURED"}}},
|
||||
},
|
||||
wantTools: []string{"disable_dev_app_robot", "get_extension_robot_config"},
|
||||
},
|
||||
{
|
||||
name: "event subscribe", declaration: EventSubscribe,
|
||||
args: []string{"--unified-app-id", "app", "--event-codes", "event.one", "--yes"},
|
||||
responses: map[string][]map[string]any{
|
||||
"subscribe_dev_app_events": {{"success": true}},
|
||||
"list_dev_app_events": {{"success": true, "list": []any{map[string]any{"eventCode": "event.one"}}, "hasMore": false}},
|
||||
},
|
||||
wantTools: []string{"subscribe_dev_app_events", "list_dev_app_events"},
|
||||
},
|
||||
{
|
||||
name: "version create", declaration: VersionCreate,
|
||||
args: []string{"--unified-app-id", "app", "--desc", "snapshot", "--yes"},
|
||||
responses: map[string][]map[string]any{
|
||||
"create_dev_app_version": {{"success": true, "result": map[string]any{"versionId": "version"}}},
|
||||
"get_dev_app_version_detail": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "versionId": "version", "desc": "snapshot"}}},
|
||||
},
|
||||
wantTools: []string{"create_dev_app_version", "get_dev_app_version_detail"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: tc.responses}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, tc.args...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
gotTools := make([]string, 0, len(caller.calls))
|
||||
for _, call := range caller.calls {
|
||||
gotTools = append(gotTools, call.tool)
|
||||
}
|
||||
if !reflect.DeepEqual(gotTools, tc.wantTools) {
|
||||
t.Fatalf("tools = %#v, want %#v", gotTools, tc.wantTools)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("event false receipt is rejected by readback", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"subscribe_dev_app_events": {{"success": true}},
|
||||
"list_dev_app_events": {{"success": true, "list": []any{}, "hasMore": false}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, EventSubscribe, caller, "--unified-app-id", "app", "--event-codes", "event.one", "--yes"); err == nil {
|
||||
t.Fatal("event subscription without exact readback was accepted")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppWritesUseExactReadback(t *testing.T) {
|
||||
t.Run("create", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"create_dev_app": {{"success": true, "result": map[string]any{"unifiedAppId": "app"}}},
|
||||
"get_dev_app": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "name": "created"}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, CreateApp, caller, "--name", "created", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []devAppCoverageCall{
|
||||
{tool: "create_dev_app", params: map[string]any{"name": "created"}},
|
||||
{tool: "get_dev_app", params: map[string]any{"unifiedAppId": "app"}},
|
||||
}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update mismatch fails", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"update_dev_app": {{"success": true}},
|
||||
"get_dev_app": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "name": "old"}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, UpdateApp, caller, "--unified-app-id", "app", "--name", "new", "--yes"); err == nil {
|
||||
t.Fatal("write/readback mismatch was accepted")
|
||||
}
|
||||
if len(caller.calls) != 2 || caller.calls[0].tool != "update_dev_app" || caller.calls[1].tool != "get_dev_app" {
|
||||
t.Fatalf("calls = %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
declaration shortcut.Shortcut
|
||||
writeTool string
|
||||
status string
|
||||
}{
|
||||
{name: "enable", declaration: EnableApp, writeTool: "enable_dev_app", status: "normal"},
|
||||
{name: "disable", declaration: DisableApp, writeTool: "disable_dev_app", status: "disabled"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
tc.writeTool: {{"success": true}},
|
||||
"get_dev_app": {{"success": true, "result": map[string]any{
|
||||
"unifiedAppId": "app", "appStatus": tc.status,
|
||||
}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, tc.declaration, caller, "--unified-app-id", "app", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 2 || caller.calls[0].tool != tc.writeTool || caller.calls[1].tool != "get_dev_app" {
|
||||
t.Fatalf("calls = %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("webapp config", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"set_extension_webapp_config": {{"success": true}},
|
||||
"get_extension_webapp_config": {{"success": true, "result": map[string]any{
|
||||
"unifiedAppId": "app", "homepageUrl": "https://example.invalid",
|
||||
}}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, WebappConfig, caller, "--unified-app-id", "app", "--homepage-url", "https://example.invalid", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(caller.calls) != 2 || caller.calls[0].tool != "set_extension_webapp_config" || caller.calls[1].tool != "get_extension_webapp_config" {
|
||||
t.Fatalf("calls = %#v", caller.calls)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete pre-read and absence", func(t *testing.T) {
|
||||
caller := &devAppCoverageCaller{responses: map[string][]map[string]any{
|
||||
"get_dev_app": {{"success": true, "result": map[string]any{"unifiedAppId": "app", "appKey": "key"}}},
|
||||
"delete_dev_app": {{"success": true}},
|
||||
"list_dev_app": {{"success": true, "list": []any{}, "hasMore": false}},
|
||||
}}
|
||||
if err := runDevAppCoverage(t, DeleteApp, caller, "--unified-app-id", "app", "--yes"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
want := []devAppCoverageCall{
|
||||
{tool: "get_dev_app", params: map[string]any{"unifiedAppId": "app"}},
|
||||
{tool: "delete_dev_app", params: map[string]any{"unifiedAppId": "app"}},
|
||||
{tool: "list_dev_app", params: map[string]any{"appKey": "key", "pageSize": 20}},
|
||||
}
|
||||
if !reflect.DeepEqual(caller.calls, want) {
|
||||
t.Fatalf("calls = %#v, want %#v", caller.calls, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppReviewedInventory(t *testing.T) {
|
||||
public := 0
|
||||
unavailable := 0
|
||||
total := 0
|
||||
for _, item := range shortcut.All() {
|
||||
if item.Service != "devapp" {
|
||||
continue
|
||||
}
|
||||
total++
|
||||
if item.Availability == shortcut.AvailabilityUnavailable {
|
||||
unavailable++
|
||||
if !item.Hidden || item.CompatibilityVisible || shortcut.InPublicCatalog(item.Service, item.Command) {
|
||||
t.Errorf("unavailable %s visibility/public = hidden=%v compatibility=%v public=%v",
|
||||
item.Command, item.Hidden, item.CompatibilityVisible, shortcut.InPublicCatalog(item.Service, item.Command))
|
||||
}
|
||||
if strings.TrimSpace(devAppUnavailableReasons[item.Command]) == "" {
|
||||
t.Errorf("unavailable %s lacks concrete reason", item.Command)
|
||||
}
|
||||
if !item.Contract.Empty() {
|
||||
t.Errorf("hidden unavailable %s must not publish an incomplete Contract", item.Command)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if shortcut.InPublicCatalog(item.Service, item.Command) {
|
||||
public++
|
||||
if item.Hidden || item.Availability != shortcut.AvailabilityAvailable {
|
||||
t.Errorf("public %s visibility/availability = %v/%q", item.Command, item.Hidden, item.Availability)
|
||||
}
|
||||
if item.OutputRollout != output.RolloutUnifiedActive {
|
||||
t.Errorf("public %s rollout = %q", item.Command, item.OutputRollout)
|
||||
}
|
||||
if item.Contract.Result == nil || item.Contract.Interface == nil || item.Contract.Description == "" {
|
||||
t.Errorf("public %s has incomplete Contract/Result", item.Command)
|
||||
}
|
||||
if item.Safety.Effect == "" || item.Safety.Risk == "" || item.Safety.Confirmation == "" || item.Safety.Idempotency == "" {
|
||||
t.Errorf("public %s has incomplete Safety", item.Command)
|
||||
}
|
||||
}
|
||||
}
|
||||
if total != 30 || public != 25 || unavailable != 5 {
|
||||
t.Fatalf("devapp inventory total/public/unavailable = %d/%d/%d, want 30/25/5", total, public, unavailable)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageDevAppUnavailableCommandsMakeZeroCalls(t *testing.T) {
|
||||
for command, reason := range devAppUnavailableReasons {
|
||||
declaration, found := devAppRegistered(command)
|
||||
if !found {
|
||||
t.Fatalf("registered unavailable command missing: %s", command)
|
||||
}
|
||||
args := []string{}
|
||||
for _, flag := range declaration.Flags {
|
||||
if !flag.Required {
|
||||
continue
|
||||
}
|
||||
args = append(args, "--"+flag.Name)
|
||||
if flag.Type != shortcut.FlagBool {
|
||||
args = append(args, "fixture")
|
||||
}
|
||||
}
|
||||
caller := &devAppCoverageCaller{}
|
||||
err := runDevAppCoverage(t, declaration, caller, args...)
|
||||
if err == nil || !strings.Contains(err.Error(), reason) {
|
||||
t.Errorf("%s unavailable error = %v", command, err)
|
||||
}
|
||||
if len(caller.calls) != 0 {
|
||||
t.Errorf("%s unavailable command called MCP: %#v", command, caller.calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,15 +32,12 @@ func TestDevAppListProjectionPreservesPaginationEvidence(t *testing.T) {
|
||||
name string
|
||||
data map[string]any
|
||||
}{
|
||||
{name: "top level", data: map[string]any{"success": true, "hasMore": true, "nextCursor": "next"}},
|
||||
{name: "nested result", data: map[string]any{"success": true, "result": map[string]any{"hasMore": true, "nextCursor": "next"}}},
|
||||
{name: "exhausted", data: map[string]any{"success": true, "hasMore": false}},
|
||||
{name: "top level", data: map[string]any{"hasMore": true, "nextCursor": "next"}},
|
||||
{name: "nested result", data: map[string]any{"result": map[string]any{"hasMore": true, "nextCursor": "next"}}},
|
||||
{name: "exhausted", data: map[string]any{"hasMore": false}},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got, err := devAppListProjection(tc.data, "items", items, "devapp/test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got := devAppListProjection(tc.data, "items", items)
|
||||
if got["hasMore"] != devAppPaginationCandidates(tc.data)[len(devAppPaginationCandidates(tc.data))-1]["hasMore"] && tc.name == "nested result" {
|
||||
t.Fatalf("hasMore not preserved: %#v", got)
|
||||
}
|
||||
@@ -55,23 +52,14 @@ func TestDevAppListProjectionPreservesPaginationEvidence(t *testing.T) {
|
||||
if got := devAppPaginationCandidates(nil); got != nil {
|
||||
t.Fatalf("nil candidates=%#v", got)
|
||||
}
|
||||
deep := map[string]any{"content": map[string]any{"success": true, "result": map[string]any{"hasMore": true, "nextCursor": "deep"}}}
|
||||
if got, err := devAppListProjection(deep, "items", nil, "devapp/test"); err != nil || got["nextCursor"] != "deep" {
|
||||
deep := map[string]any{"content": map[string]any{"result": map[string]any{"hasMore": true, "nextCursor": "deep"}}}
|
||||
if got := devAppListProjection(deep, "items", nil); got["nextCursor"] != "deep" {
|
||||
t.Fatalf("deep projection=%#v", got)
|
||||
}
|
||||
deeper := map[string]any{"success": true, "content": map[string]any{"result": map[string]any{"data": map[string]any{"hasMore": true, "nextCursor": "deeper"}}}}
|
||||
if got, err := devAppListProjection(deeper, "items", nil, "devapp/test"); err != nil || got["nextCursor"] != "deeper" {
|
||||
t.Fatalf("deeper projection=%#v", got)
|
||||
}
|
||||
cyclic := map[string]any{"success": true}
|
||||
cyclic["content"] = cyclic
|
||||
if got := devAppPaginationCandidates(cyclic); len(got) != 13 {
|
||||
t.Fatalf("cyclic candidate walk length=%d, want bounded length 13", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFrameworkPaginatedShortcutExecutionMovesCursorToMeta(t *testing.T) {
|
||||
caller := &paginationCaller{text: `{"content":{"success":true,"result":{"hasMore":true,"nextCursor":"next","list":[]}}}`}
|
||||
caller := &paginationCaller{text: `{"content":{"result":{"hasMore":true,"nextCursor":"next","list":[]}}}`}
|
||||
helpers.InitDepsForTest(t, caller)
|
||||
helpers.GetFormatter().SetWriters(&bytes.Buffer{}, &bytes.Buffer{})
|
||||
for _, tc := range []struct {
|
||||
|
||||
@@ -12,16 +12,10 @@ import (
|
||||
|
||||
func TestDevAppShortcutsRollOutPerTerminalCommand(t *testing.T) {
|
||||
active := map[string]bool{
|
||||
"+list": true, "+get": true, "+create": true, "+update": true,
|
||||
"+delete": true, "+enable": true, "+disable": true, "+webapp-get": true,
|
||||
"+webapp-config": true,
|
||||
"+permission-list": true, "+version-list": true,
|
||||
"+list": true, "+get": true, "+webapp-get": true,
|
||||
"+permission-list": true, "+event-list": true, "+version-list": true,
|
||||
"+robot-get": true, "+version-get": true,
|
||||
"+version-check-approval": true, "+version-status": true,
|
||||
"+credentials-get": true, "+member-list": true,
|
||||
"+member-add": true, "+member-remove": true,
|
||||
"+robot-config": true, "+robot-enable": true, "+robot-disable": true,
|
||||
"+event-list": true, "+event-subscribe": true, "+version-create": true,
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, item := range shortcut.All() {
|
||||
@@ -48,7 +42,7 @@ func TestDevAppShortcutsRollOutPerTerminalCommand(t *testing.T) {
|
||||
t.Errorf("active pilot shortcut %s is not registered", name)
|
||||
}
|
||||
}
|
||||
for _, paginated := range []string{"+list", "+permission-list", "+version-list"} {
|
||||
for _, paginated := range []string{"+list", "+permission-list", "+event-list", "+version-list"} {
|
||||
if !seen[paginated] {
|
||||
t.Errorf("paginated shortcut %s is not registered", paginated)
|
||||
}
|
||||
|
||||
@@ -6,11 +6,6 @@ package shortcut
|
||||
// command discovery and skill generation.
|
||||
func generatedPublicShortcutCatalog() map[string]struct{} {
|
||||
return map[string]struct{}{
|
||||
"agoal\u0000+contract-fields": {},
|
||||
"agoal\u0000+obj-template-list": {},
|
||||
"agoal\u0000+report-statistics-list": {},
|
||||
"agoal\u0000+report-submit-detail": {},
|
||||
"agoal\u0000+user-rules": {},
|
||||
"aisearch\u0000+search-person": {},
|
||||
"aitable\u0000+advperm-disable": {},
|
||||
"aitable\u0000+advperm-enable": {},
|
||||
@@ -259,25 +254,19 @@ func generatedPublicShortcutCatalog() map[string]struct{} {
|
||||
"contact\u0000+search-user": {},
|
||||
"contact\u0000+team": {},
|
||||
"devapp\u0000+create": {},
|
||||
"devapp\u0000+credentials-get": {},
|
||||
"devapp\u0000+delete": {},
|
||||
"devapp\u0000+disable": {},
|
||||
"devapp\u0000+enable": {},
|
||||
"devapp\u0000+event-list": {},
|
||||
"devapp\u0000+event-subscribe": {},
|
||||
"devapp\u0000+get": {},
|
||||
"devapp\u0000+list": {},
|
||||
"devapp\u0000+member-add": {},
|
||||
"devapp\u0000+member-list": {},
|
||||
"devapp\u0000+member-remove": {},
|
||||
"devapp\u0000+permission-list": {},
|
||||
"devapp\u0000+robot-config": {},
|
||||
"devapp\u0000+robot-disable": {},
|
||||
"devapp\u0000+robot-enable": {},
|
||||
"devapp\u0000+robot-get": {},
|
||||
"devapp\u0000+update": {},
|
||||
"devapp\u0000+version-check-approval": {},
|
||||
"devapp\u0000+version-create": {},
|
||||
"devapp\u0000+version-get": {},
|
||||
"devapp\u0000+version-list": {},
|
||||
"devapp\u0000+version-status": {},
|
||||
|
||||
@@ -336,23 +336,6 @@ func (rt *RuntimeContext) Output(payload any) error {
|
||||
return output.WriteCommandPayload(rt.cmd, payload, output.FormatJSON)
|
||||
}
|
||||
|
||||
// OutputForTool stores a once-fetched MCP payload while retaining the tool name
|
||||
// for product-specific outcome normalization. It is intended for composite
|
||||
// shortcuts that must validate stable identity or collection shape before the
|
||||
// shared renderer sees the response; callers must not use it to issue a second
|
||||
// business request.
|
||||
func (rt *RuntimeContext) OutputForTool(tool string, payload any) error {
|
||||
if output.UsesUnifiedResult(rt.cmd) {
|
||||
return output.StoreResult(rt.cmd.Context(), rt.resultForPayload(tool, payload))
|
||||
}
|
||||
if output.CommandRollout(rt.cmd) == output.RolloutDualValidate {
|
||||
if err := validateShadowResult(rt.resultForPayload(tool, payload)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return output.WriteCommandPayload(rt.cmd, payload, output.FormatJSON)
|
||||
}
|
||||
|
||||
func (rt *RuntimeContext) storePayload(tool string, payload any) error {
|
||||
return output.StoreResult(rt.cmd.Context(), rt.resultForPayload(tool, payload))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
apperrors "github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/errors"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/helpers"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/output"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/testseam"
|
||||
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -232,53 +231,3 @@ func TestFrameworkShortcutUnifiedOutputAndProjectionEdges(t *testing.T) {
|
||||
t.Fatalf("devapp result=%s", got.Outcome())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrossPlatformCoverageRuntimeOutputForToolRollouts(t *testing.T) {
|
||||
t.Run("unified", func(t *testing.T) {
|
||||
ctx, _ := output.WithResultStore(context.Background())
|
||||
cmd := &cobra.Command{Use: "+get"}
|
||||
cmd.SetContext(ctx)
|
||||
output.SetCommandRollout(cmd, output.RolloutUnifiedActive)
|
||||
rt := RuntimeContextForTest(cmd, Shortcut{Service: "devapp", Command: "+get", Safety: contract.SafetySpec{Effect: "read"}})
|
||||
if err := rt.OutputForTool("get_dev_app", map[string]any{"success": true, "result": map[string]any{"unifiedAppId": "app"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("dual validate", func(t *testing.T) {
|
||||
cmd := &cobra.Command{Use: "+get"}
|
||||
cmd.SetContext(context.Background())
|
||||
cmd.SetOut(&bytes.Buffer{})
|
||||
output.SetCommandRollout(cmd, output.RolloutDualValidate)
|
||||
rt := RuntimeContextForTest(cmd, Shortcut{Service: "devapp", Command: "+get", Safety: contract.SafetySpec{Effect: "read"}})
|
||||
if err := rt.OutputForTool("get_dev_app", map[string]any{"success": true, "result": map[string]any{"unifiedAppId": "app"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("dual validate failure", func(t *testing.T) {
|
||||
testseam.Swap(t, &validateShadowResult, func(output.CommandResult) error { return context.Canceled })
|
||||
cmd := &cobra.Command{Use: "+get"}
|
||||
cmd.SetContext(context.Background())
|
||||
output.SetCommandRollout(cmd, output.RolloutDualValidate)
|
||||
rt := RuntimeContextForTest(cmd, Shortcut{Service: "devapp", Command: "+get", Safety: contract.SafetySpec{Effect: "read"}})
|
||||
if err := rt.OutputForTool("get_dev_app", map[string]any{"success": true}); !errors.Is(err, context.Canceled) {
|
||||
t.Fatalf("dual validation error=%v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("legacy", func(t *testing.T) {
|
||||
cmd := &cobra.Command{Use: "+get"}
|
||||
cmd.SetContext(context.Background())
|
||||
var stdout bytes.Buffer
|
||||
cmd.SetOut(&stdout)
|
||||
output.SetCommandRollout(cmd, output.RolloutLegacyOnly)
|
||||
rt := RuntimeContextForTest(cmd, Shortcut{Service: "sample", Command: "+get", Safety: contract.SafetySpec{Effect: "read"}})
|
||||
if err := rt.OutputForTool("get", map[string]any{"id": "item"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(stdout.String(), `"id"`) {
|
||||
t.Fatalf("legacy output=%q", stdout.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -73,12 +73,6 @@ var hrbrainSemanticCatalogJSON []byte
|
||||
//go:embed semantic_catalog_pat.json
|
||||
var patSemanticCatalogJSON []byte
|
||||
|
||||
//go:embed semantic_catalog_devapp.json
|
||||
var devAppSemanticCatalogJSON []byte
|
||||
|
||||
//go:embed semantic_catalog_agoal.json
|
||||
var agoalSemanticCatalogJSON []byte
|
||||
|
||||
type semanticCatalogFile struct {
|
||||
Version int `json:"version"`
|
||||
Service string `json:"service"`
|
||||
@@ -119,8 +113,6 @@ var reviewedSemanticCatalog = mustLoadSemanticCatalogs(
|
||||
devdocSemanticCatalogJSON,
|
||||
hrbrainSemanticCatalogJSON,
|
||||
patSemanticCatalogJSON,
|
||||
devAppSemanticCatalogJSON,
|
||||
agoalSemanticCatalogJSON,
|
||||
)
|
||||
|
||||
func mustLoadSemanticCatalogs(sources ...[]byte) map[string]semanticCatalogRecord {
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"service": "agoal",
|
||||
"default_availability": "available",
|
||||
"shortcuts": {
|
||||
"+report-statistics-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、content 数组和每项稳定 templateId;关键词同时支持已知非空与合法零命中。","risk":"read","public":true,"reviewed":true},
|
||||
"+obj-template-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、result 数组、稳定模板 ID 及 page/pageSize/totalCount;不虚构 cursor。","risk":"read","public":true,"reviewed":true},
|
||||
"+strategy-list": {"disposition":"schema_leaf","semantic_delta":"exact+raw 在可访问 PERSONAL/DEPT 范围均仅为空,缺少已知非空 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+strategy-get": {"disposition":"schema_leaf","semantic_delta":"不存在 ID 的 raw 响应为无 success 的 null,且列表无非空 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+strategy-update": {"disposition":"schema_leaf","semantic_delta":"仅通过 raw dry-run;缺少旧值、全字段读回和恢复。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+contract-list": {"disposition":"schema_leaf","semantic_delta":"exact+raw 在可访问 PERSONAL/DEPT 范围均仅为空,缺少已知非空 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+contract-fields": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、字段数组和每项稳定 id;本地 keyword 覆盖字段标识、编码、标题、分类和类型,支持已知非空与保证零命中。","risk":"read","public":true,"reviewed":true},
|
||||
"+contract-get": {"disposition":"schema_leaf","semantic_delta":"不存在 ID 的 raw 响应为无 success 的 null,且列表无非空 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+contract-update": {"disposition":"schema_leaf","semantic_delta":"仅通过 raw dry-run;缺少旧值、全字段读回和恢复。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+scorecard-get": {"disposition":"schema_leaf","semantic_delta":"可访问部门与多个周期的 exact+raw 均返回无 success 的 null。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+scorecard-entity-get": {"disposition":"schema_leaf","semantic_delta":"不存在双 ID 的 raw 响应为无 success 的 null,缺少安全实体 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+scorecard-update": {"disposition":"schema_leaf","semantic_delta":"仅通过 raw dry-run;缺少计分卡旧值、全字段读回和恢复。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+user-rules": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、content 对象、rules 数组和稳定 ruleId;本地精确 ruleId 选择器支持已知非空与保证零命中。","risk":"read","public":true,"reviewed":true},
|
||||
"+user-objectives": {"disposition":"schema_leaf","semantic_delta":"当前用户全部可见规则/周期的 exact+raw 均只为空,缺少非空 fixture。","risk":"read","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+report-submit-detail": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、嵌套稳定用户身份及 page/pageSize/totalCount;下游忽略 keyword,因此做有界全量遍历、本地过滤、停滞/重复/总数变化失败与人员字段最小投影。","risk":"read","public":true,"reviewed":true},
|
||||
"+obj-template-upsert": {"disposition":"schema_leaf","semantic_delta":"仅通过 raw dry-run;无删除或版本恢复,无法验证 upsert 终态与零残留。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
{
|
||||
"version": 1,
|
||||
"service": "devapp",
|
||||
"default_availability": "available",
|
||||
"shortcuts": {
|
||||
"+list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、应用数组、稳定 unifiedAppId 与游标终止证据;投影当前页并保留可续翻 meta.pagination。","risk":"read","public":true,"reviewed":true},
|
||||
"+get": {"disposition":"semantic_adapter","semantic_delta":"拒绝空响应、缺失 success 和空业务对象,并要求读回 unifiedAppId 与请求精确一致。","risk":"read","public":true,"reviewed":true},
|
||||
"+create": {"disposition":"semantic_adapter","semantic_delta":"创建后提取稳定 unifiedAppId,并以同一 ID 读回名称及请求字段;只有精确核验通过才返回成功。","risk":"write","public":true,"reviewed":true},
|
||||
"+update": {"disposition":"semantic_adapter","semantic_delta":"要求至少一个更新字段,写入后按同一 unifiedAppId 精确读回所有请求字段。","risk":"write","public":true,"reviewed":true},
|
||||
"+delete": {"disposition":"semantic_adapter","semantic_delta":"删除前读回稳定 appKey,删除后按该选择器有界遍历全部页并证明同一 unifiedAppId 不再存在。","risk":"high-risk-write","public":true,"reviewed":true},
|
||||
"+enable": {"disposition":"semantic_adapter","semantic_delta":"启用后按同一 unifiedAppId 读回并要求 appStatus=normal。","risk":"write","public":true,"reviewed":true},
|
||||
"+disable": {"disposition":"semantic_adapter","semantic_delta":"停用后按同一 unifiedAppId 读回并要求 appStatus=disabled。","risk":"high-risk-write","public":true,"reviewed":true},
|
||||
"+credentials-get": {"disposition":"semantic_adapter","semantic_delta":"严格要求 success、稳定 unifiedAppId、非空客户端标识和非空 secret;Result 将密钥路径声明为敏感。","risk":"read","public":true,"reviewed":true},
|
||||
"+webapp-get": {"disposition":"semantic_adapter","semantic_delta":"严格验证非空网页配置对象,并要求读回 unifiedAppId 与请求精确一致。","risk":"read","public":true,"reviewed":true},
|
||||
"+webapp-config": {"disposition":"semantic_adapter","semantic_delta":"拒绝空更新,写入后按同一 unifiedAppId 读取网页配置并精确比较全部请求字段。","risk":"write","public":true,"reviewed":true},
|
||||
"+permission-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、权限数组、每项稳定 scopeValue 与游标终止证据,拒绝坏元素和伪空结果。","risk":"read","public":true,"reviewed":true},
|
||||
"+permission-add": {"disposition":"schema_leaf","semantic_delta":"下游缺少逐项终态回执与按 scopeValue 精确读回验证,执行入口保持 unavailable。","risk":"write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+permission-remove": {"disposition":"schema_leaf","semantic_delta":"下游缺少逐项终态回执与按 scopeValue 精确读回验证,执行入口保持 unavailable。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+member-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、成员数组和每项稳定 userId;新增本地精确 userId 选择器以证明已知非空与保证零命中。","risk":"read","public":true,"reviewed":true},
|
||||
"+member-add": {"disposition":"semantic_adapter","semantic_delta":"拒绝空值和重复 userId,校验写终态后按稳定 userId 逐项精确读回,并要求 memberType 与请求角色一致。","risk":"write","public":true,"reviewed":true},
|
||||
"+member-remove": {"disposition":"semantic_adapter","semantic_delta":"拒绝空值和重复 userId,校验写终态后读取完整成员数组,并逐项证明目标稳定 userId 已不存在。","risk":"high-risk-write","public":true,"reviewed":true},
|
||||
"+security-config": {"disposition":"schema_leaf","semantic_delta":"整组覆盖写入缺少读取旧值、精确写回和恢复原配置的安全闭环,执行入口保持 unavailable。","risk":"write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+robot-get": {"disposition":"semantic_adapter","semantic_delta":"严格验证非空机器人配置对象,并要求读回 unifiedAppId 与请求精确一致。","risk":"read","public":true,"reviewed":true},
|
||||
"+robot-config": {"disposition":"semantic_adapter","semantic_delta":"拒绝空配置,写后按同一 unifiedAppId 读取机器人对象并精确比较全部请求标量字段。","risk":"write","public":true,"reviewed":true},
|
||||
"+robot-enable": {"disposition":"semantic_adapter","semantic_delta":"要求写终态成功并按同一 unifiedAppId 读回 robotStatus=ONLINE。","risk":"write","public":true,"reviewed":true},
|
||||
"+robot-disable": {"disposition":"semantic_adapter","semantic_delta":"要求写终态成功并读回 robotStatus=UNCONFIGURED;不虚构保留配置或可直接恢复语义。","risk":"high-risk-write","public":true,"reviewed":true},
|
||||
"+event-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、事件数组、每项稳定 eventCode 与游标终止证据;明确返回可用事件目录及订阅状态,并拒绝坏元素与伪空结果。","risk":"read","public":true,"reviewed":true},
|
||||
"+event-subscribe": {"disposition":"semantic_adapter","semantic_delta":"拒绝空值与重复 eventCode,写后有界遍历订阅列表并逐项精确读回。","risk":"write","public":true,"reviewed":true},
|
||||
"+event-unsubscribe": {"disposition":"schema_leaf","semantic_delta":"缺少可恢复的稳定订阅 fixture 与逐项退订读回,执行入口保持 unavailable。","risk":"high-risk-write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+version-create": {"disposition":"semantic_adapter","semantic_delta":"创建回执必须含稳定 versionId,随后以 unifiedAppId/versionId 双身份读取详情并核验请求字段;live fixture 通过删除临时父应用清理。","risk":"write","public":true,"reviewed":true},
|
||||
"+version-list": {"disposition":"semantic_adapter","semantic_delta":"严格验证 success、版本数组、每项稳定 versionId 与游标终止证据。","risk":"read","public":true,"reviewed":true},
|
||||
"+version-get": {"disposition":"semantic_adapter","semantic_delta":"严格验证非空版本对象,并要求 unifiedAppId 和 versionId 同时与请求精确一致。","risk":"read","public":true,"reviewed":true},
|
||||
"+version-check-approval": {"disposition":"semantic_adapter","semantic_delta":"只执行 precheckOnly,严格绑定应用与版本身份,并保留可执行后续动作的 pending 结果。","risk":"read","public":true,"reviewed":true},
|
||||
"+version-publish": {"disposition":"schema_leaf","semantic_delta":"可能进入审批或线上生效,缺少安全测试租户与回滚合同,执行入口保持 unavailable。","risk":"write","availability":"unavailable","public":false,"reviewed":true},
|
||||
"+version-status": {"disposition":"semantic_adapter","semantic_delta":"严格验证非空发布状态对象,并要求 unifiedAppId 和 versionId 同时与请求精确一致。","risk":"read","public":true,"reviewed":true}
|
||||
}
|
||||
}
|
||||
@@ -1,798 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Opt-in, real-data release evidence gate for the Dev -> DevApp -> Agoal
|
||||
# Shortcut delivery group. The current worktree binary supplies both exact
|
||||
# `+shortcut` leaves and their owning atomic command trees. Raw responses and
|
||||
# stable IDs stay in a repository-external temporary directory; stdout contains
|
||||
# only PII-free PASS labels and aggregate facts.
|
||||
|
||||
repo_root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
dws_bin=${DWS_SHORTCUT_GATE_BIN:-"$repo_root/dws"}
|
||||
selected_product=${1:-all}
|
||||
|
||||
case "$selected_product" in
|
||||
all | dev | devapp | agoal) ;;
|
||||
*)
|
||||
echo "usage: $0 [all|dev|devapp|agoal]" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ ${DWS_SHORTCUT_LIVE_GATE:-} != 1 ]]; then
|
||||
echo "set DWS_SHORTCUT_LIVE_GATE=1 to authorize the real-data dual-layer gate" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [[ $selected_product == all || $selected_product == devapp ]]; then
|
||||
if [[ ! -t 0 ]]; then
|
||||
echo "the DevApp live gate requires an interactive terminal for explicit write and cleanup confirmation" >&2
|
||||
exit 2
|
||||
fi
|
||||
read -r -p "This gate creates, changes, and deletes isolated DevApp fixtures. Type RUN to authorize the writes and cleanup: " live_confirmation
|
||||
if [[ $live_confirmation != RUN ]]; then
|
||||
echo "live gate authorization declined" >&2
|
||||
exit 2
|
||||
fi
|
||||
fi
|
||||
if [[ ! -x $dws_bin ]]; then
|
||||
echo "current worktree binary is missing; run make build first" >&2
|
||||
exit 2
|
||||
fi
|
||||
command -v jq >/dev/null 2>&1 || {
|
||||
echo "jq is required" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
member_user_id=""
|
||||
member_type=${DWS_DEVAPP_E2E_MEMBER_TYPE:-DEVELOPER}
|
||||
if [[ $selected_product == all || $selected_product == devapp ]]; then
|
||||
member_user_id_file=${DWS_DEVAPP_E2E_MEMBER_USER_ID_FILE:-}
|
||||
if [[ -z $member_user_id_file || ! -f $member_user_id_file ]]; then
|
||||
echo "set DWS_DEVAPP_E2E_MEMBER_USER_ID_FILE to a private file containing one safe test-account userId" >&2
|
||||
exit 2
|
||||
fi
|
||||
IFS= read -r member_user_id <"$member_user_id_file" || true
|
||||
[[ -n $member_user_id ]] || {
|
||||
echo "the private DevApp member fixture is empty" >&2
|
||||
exit 2
|
||||
}
|
||||
[[ -n $member_type ]] || {
|
||||
echo "DWS_DEVAPP_E2E_MEMBER_TYPE must not be empty" >&2
|
||||
exit 2
|
||||
}
|
||||
fi
|
||||
|
||||
evidence_dir=$(mktemp -d "${TMPDIR:-/tmp}/dws-shortcut-dual-live.XXXXXX")
|
||||
exact_app_id=""
|
||||
exact_app_name=""
|
||||
raw_app_id=""
|
||||
raw_app_name=""
|
||||
|
||||
fail() {
|
||||
echo "FAIL $1 (secure response retained only until trap cleanup)" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
run_json() {
|
||||
local label=$1
|
||||
local output=$2
|
||||
shift 2
|
||||
if ! "$@" --format json >"$output" 2>"$output.stderr"; then
|
||||
fail "$label"
|
||||
fi
|
||||
jq -e . "$output" >/dev/null 2>&1 || fail "$label: non-JSON response"
|
||||
}
|
||||
|
||||
assert_jq() {
|
||||
local label=$1
|
||||
local expression=$2
|
||||
shift 2
|
||||
jq -e "$expression" "$@" >/dev/null 2>&1 || fail "$label"
|
||||
}
|
||||
|
||||
pass() {
|
||||
printf 'PASS %s\n' "$1"
|
||||
}
|
||||
|
||||
assert_public_surface() {
|
||||
local product=$1
|
||||
local expected=$2
|
||||
local actual
|
||||
actual=$(jq -r --arg product "$product" '.results[] | select(.service == $product) | .command' "$repo_root/docs/shortcut-public-catalog.json" | LC_ALL=C sort)
|
||||
expected=$(printf '%s\n' "$expected" | sed '/^$/d' | LC_ALL=C sort)
|
||||
[[ $actual == "$expected" ]] || fail "$product public catalog differs from the exhaustive live matrix"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
set +e
|
||||
if [[ -n $exact_app_id ]]; then
|
||||
"$dws_bin" devapp +delete --unified-app-id "$exact_app_id" --yes --format json >/dev/null 2>&1
|
||||
fi
|
||||
if [[ -n $raw_app_id ]]; then
|
||||
"$dws_bin" dev app delete --unified-app-id "$raw_app_id" --confirm-name "$raw_app_name" --yes --format json >/dev/null 2>&1
|
||||
fi
|
||||
rm -rf "$evidence_dir"
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
run_dev_gate() {
|
||||
# Dev owns routing/documentation only and registers no Shortcut leaves.
|
||||
assert_public_surface dev ""
|
||||
pass "DEV-INVENTORY public=0 fully-unlocked=0 hardened-blocked=0 routed=4 platform-unavailable=1"
|
||||
}
|
||||
|
||||
expect_confirmation() {
|
||||
local label=$1
|
||||
local output=$2
|
||||
shift 2
|
||||
local status=0
|
||||
# The outer gate intentionally requires a TTY for one explicit RUN
|
||||
# authorization. The command under test must not inherit that TTY here:
|
||||
# otherwise its own confirmation prompt blocks instead of returning the
|
||||
# machine-readable confirmation_required result that proves zero writes.
|
||||
"$@" --format json </dev/null >"$output" 2>"$output.stderr" || status=$?
|
||||
[[ $status -ne 0 ]] || fail "$label: unconfirmed command unexpectedly succeeded"
|
||||
jq -e '.ok == false and .error.type == "validation" and .error.subtype == "confirmation_required"' "$output" >/dev/null 2>&1 || fail "$label: missing confirmation_required"
|
||||
}
|
||||
|
||||
run_devapp_gate() {
|
||||
assert_public_surface devapp "+create
|
||||
+credentials-get
|
||||
+delete
|
||||
+disable
|
||||
+enable
|
||||
+event-list
|
||||
+event-subscribe
|
||||
+get
|
||||
+list
|
||||
+member-add
|
||||
+member-list
|
||||
+member-remove
|
||||
+permission-list
|
||||
+robot-config
|
||||
+robot-disable
|
||||
+robot-enable
|
||||
+robot-get
|
||||
+update
|
||||
+version-check-approval
|
||||
+version-create
|
||||
+version-get
|
||||
+version-list
|
||||
+version-status
|
||||
+webapp-config
|
||||
+webapp-get"
|
||||
local nonce="DWS-GUARANTEED-ZERO-8F3D2C4A"
|
||||
local suffix="$(date +%s)-$$"
|
||||
exact_app_name="DWS-E2E-EXACT-$suffix"
|
||||
raw_app_name="DWS-E2E-RAW-$suffix"
|
||||
local exact_updated_name="DWS-E2E-UPDATED-$suffix"
|
||||
local raw_updated_name="DWS-E2E-RAW-UPDATED-$suffix"
|
||||
local bot_raw="DWS-E2E-BOT-RAW-$suffix"
|
||||
local bot_exact="DWS-E2E-BOT-EXACT-$suffix"
|
||||
local event_raw="bpms_task_change"
|
||||
local event_exact="$event_raw"
|
||||
|
||||
run_json "devapp create guard before exact query" "$evidence_dir/devapp-create-guard-before-exact.json" \
|
||||
"$dws_bin" devapp +list --name "$exact_app_name" --page-size 20
|
||||
run_json "devapp create guard before raw query" "$evidence_dir/devapp-create-guard-before-raw.json" \
|
||||
"$dws_bin" dev app list --name "$exact_app_name" --page-size 20
|
||||
expect_confirmation "devapp +create confirmation" "$evidence_dir/devapp-create-confirm.json" \
|
||||
"$dws_bin" devapp +create --name "$exact_app_name"
|
||||
run_json "devapp create guard after exact query" "$evidence_dir/devapp-create-guard-after-exact.json" \
|
||||
"$dws_bin" devapp +list --name "$exact_app_name" --page-size 20
|
||||
run_json "devapp create guard after raw query" "$evidence_dir/devapp-create-guard-after-raw.json" \
|
||||
"$dws_bin" dev app list --name "$exact_app_name" --page-size 20
|
||||
assert_jq "devapp +create confirmation zero-call state" '
|
||||
(input) as $br | (input) as $ae | (input) as $ar |
|
||||
.data.count == 0 and ($br.data.items | length) == 0 and
|
||||
$ae.data.count == 0 and ($ar.data.items | length) == 0
|
||||
' "$evidence_dir/devapp-create-guard-before-exact.json" "$evidence_dir/devapp-create-guard-before-raw.json" \
|
||||
"$evidence_dir/devapp-create-guard-after-exact.json" "$evidence_dir/devapp-create-guard-after-raw.json"
|
||||
|
||||
run_json "devapp exact create" "$evidence_dir/devapp-create-exact.json" \
|
||||
"$dws_bin" devapp +create --name "$exact_app_name" --desc "dual-live-exact" --yes
|
||||
exact_app_id=$(jq -er '.data.unifiedAppId | select(type == "string" and length > 0)' "$evidence_dir/devapp-create-exact.json") || fail "devapp exact create stable ID"
|
||||
assert_jq "devapp exact create terminal receipt" '.ok == true and .outcome == "success" and .data.verified == true and .data.action == "create"' "$evidence_dir/devapp-create-exact.json"
|
||||
run_json "devapp exact create raw readback" "$evidence_dir/devapp-create-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" --arg name "$exact_app_name" '.ok == true and .outcome == "success" and .data.unifiedAppId == $id and .data.name == $name' "$evidence_dir/devapp-create-exact-raw-readback.json" >/dev/null || fail "devapp exact create raw readback"
|
||||
|
||||
run_json "devapp raw create" "$evidence_dir/devapp-create-raw.json" \
|
||||
"$dws_bin" dev app create --name "$raw_app_name" --desc "dual-live-raw" --yes
|
||||
raw_app_id=$(jq -er '.data.unifiedAppId | select(type == "string" and length > 0)' "$evidence_dir/devapp-create-raw.json") || fail "devapp raw create stable ID"
|
||||
assert_jq "devapp raw create terminal receipt" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-create-raw.json"
|
||||
run_json "devapp raw create exact readback" "$evidence_dir/devapp-create-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +get --unified-app-id "$raw_app_id"
|
||||
jq -e --arg id "$raw_app_id" --arg name "$raw_app_name" '.ok == true and .outcome == "success" and .data.unifiedAppId == $id and .data.name == $name' "$evidence_dir/devapp-create-raw-exact-readback.json" >/dev/null || fail "devapp raw create exact readback"
|
||||
pass "DEVAPP +create confirm0/exact+raw terminal-receipt/stable-ID readback"
|
||||
|
||||
run_json "devapp guard snapshot app" "$evidence_dir/devapp-guard-app-before.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot webapp" "$evidence_dir/devapp-guard-webapp-before.json" \
|
||||
"$dws_bin" dev app webapp get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot robot" "$evidence_dir/devapp-guard-robot-before.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot events" "$evidence_dir/devapp-guard-events-before.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --page-size 100
|
||||
run_json "devapp guard snapshot versions" "$evidence_dir/devapp-guard-versions-before.json" \
|
||||
"$dws_bin" dev app version list --unified-app-id "$exact_app_id" --page-size 100
|
||||
|
||||
expect_confirmation "devapp +update confirmation" "$evidence_dir/devapp-update-confirm.json" \
|
||||
"$dws_bin" devapp +update --unified-app-id "$exact_app_id" --name "guard-must-not-write"
|
||||
expect_confirmation "devapp +delete confirmation" "$evidence_dir/devapp-delete-confirm.json" \
|
||||
"$dws_bin" devapp +delete --unified-app-id "$exact_app_id"
|
||||
expect_confirmation "devapp +enable confirmation" "$evidence_dir/devapp-enable-confirm.json" \
|
||||
"$dws_bin" devapp +enable --unified-app-id "$exact_app_id"
|
||||
expect_confirmation "devapp +disable confirmation" "$evidence_dir/devapp-disable-confirm.json" \
|
||||
"$dws_bin" devapp +disable --unified-app-id "$exact_app_id"
|
||||
expect_confirmation "devapp +webapp-config confirmation" "$evidence_dir/devapp-webapp-confirm.json" \
|
||||
"$dws_bin" devapp +webapp-config --unified-app-id "$exact_app_id" --homepage-url "https://example.invalid/guard"
|
||||
expect_confirmation "devapp +robot-config confirmation" "$evidence_dir/devapp-robot-config-confirm.json" \
|
||||
"$dws_bin" devapp +robot-config --unified-app-id "$exact_app_id" --name "guard-must-not-write" --mode STREAM
|
||||
expect_confirmation "devapp +robot-enable confirmation" "$evidence_dir/devapp-robot-enable-confirm.json" \
|
||||
"$dws_bin" devapp +robot-enable --unified-app-id "$exact_app_id"
|
||||
expect_confirmation "devapp +robot-disable confirmation" "$evidence_dir/devapp-robot-disable-confirm.json" \
|
||||
"$dws_bin" devapp +robot-disable --unified-app-id "$exact_app_id"
|
||||
expect_confirmation "devapp +event-subscribe confirmation" "$evidence_dir/devapp-event-confirm.json" \
|
||||
"$dws_bin" devapp +event-subscribe --unified-app-id "$exact_app_id" --event-codes "$event_exact"
|
||||
expect_confirmation "devapp +version-create confirmation" "$evidence_dir/devapp-version-create-confirm.json" \
|
||||
"$dws_bin" devapp +version-create --unified-app-id "$exact_app_id" --desc "guard-must-not-write"
|
||||
|
||||
run_json "devapp guard snapshot app after" "$evidence_dir/devapp-guard-app-after.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot webapp after" "$evidence_dir/devapp-guard-webapp-after.json" \
|
||||
"$dws_bin" dev app webapp get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot robot after" "$evidence_dir/devapp-guard-robot-after.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp guard snapshot events after" "$evidence_dir/devapp-guard-events-after.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --page-size 100
|
||||
run_json "devapp guard snapshot versions after" "$evidence_dir/devapp-guard-versions-after.json" \
|
||||
"$dws_bin" dev app version list --unified-app-id "$exact_app_id" --page-size 100
|
||||
assert_jq "devapp all public write confirmations preserve raw state" '
|
||||
(input) as $aa | (input) as $wb | (input) as $wa | (input) as $rb | (input) as $ra |
|
||||
(input) as $eb | (input) as $ea | (input) as $vb | (input) as $va |
|
||||
[.data.unifiedAppId,.data.name,.data.desc,.data.appStatus] == [$aa.data.unifiedAppId,$aa.data.name,$aa.data.desc,$aa.data.appStatus] and
|
||||
$wb.data == $wa.data and $rb.data == $ra.data and
|
||||
([$eb.data.events[].eventCode] | sort) == ([$ea.data.events[].eventCode] | sort) and
|
||||
([$vb.data.items[].versionId] | sort) == ([$va.data.items[].versionId] | sort)
|
||||
' "$evidence_dir/devapp-guard-app-before.json" "$evidence_dir/devapp-guard-app-after.json" \
|
||||
"$evidence_dir/devapp-guard-webapp-before.json" "$evidence_dir/devapp-guard-webapp-after.json" \
|
||||
"$evidence_dir/devapp-guard-robot-before.json" "$evidence_dir/devapp-guard-robot-after.json" \
|
||||
"$evidence_dir/devapp-guard-events-before.json" "$evidence_dir/devapp-guard-events-after.json" \
|
||||
"$evidence_dir/devapp-guard-versions-before.json" "$evidence_dir/devapp-guard-versions-after.json"
|
||||
|
||||
run_json "devapp exact list known" "$evidence_dir/devapp-list-known-exact.json" \
|
||||
"$dws_bin" devapp +list --name "$exact_app_name" --page-size 20
|
||||
run_json "devapp raw list known" "$evidence_dir/devapp-list-known-raw.json" \
|
||||
"$dws_bin" dev app list --name "$exact_app_name" --page-size 20
|
||||
run_json "devapp exact list zero" "$evidence_dir/devapp-list-zero-exact.json" \
|
||||
"$dws_bin" devapp +list --name "$nonce" --page-size 20
|
||||
run_json "devapp raw list zero" "$evidence_dir/devapp-list-zero-raw.json" \
|
||||
"$dws_bin" dev app list --name "$nonce" --page-size 20
|
||||
jq -e --arg id "$exact_app_id" '
|
||||
(input) as $raw | (input) as $ze | (input) as $zr |
|
||||
.ok == true and .outcome == "success" and .data.count == 1 and .data.apps[0].unifiedAppId == $id and
|
||||
$raw.ok == true and $raw.outcome == "success" and ($raw.data.items | length) == 1 and $raw.data.items[0].unifiedAppId == $id and
|
||||
$ze.ok == true and $ze.data.count == 0 and ($ze.data.apps | length) == 0 and
|
||||
$zr.ok == true and ($zr.data.items | length) == 0 and
|
||||
.meta.pagination.endpoint_exhausted == true and $raw.meta.pagination.endpoint_exhausted == true and
|
||||
$ze.meta.pagination.endpoint_exhausted == true and $zr.meta.pagination.endpoint_exhausted == true
|
||||
' "$evidence_dir/devapp-list-known-exact.json" "$evidence_dir/devapp-list-known-raw.json" \
|
||||
"$evidence_dir/devapp-list-zero-exact.json" "$evidence_dir/devapp-list-zero-raw.json" >/dev/null || fail "devapp +list dual known/zero alignment"
|
||||
pass "DEVAPP +list exact+raw known-nonempty/guaranteed-zero stable-ID/cursor termination"
|
||||
|
||||
run_json "devapp exact get" "$evidence_dir/devapp-get-exact.json" \
|
||||
"$dws_bin" devapp +get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp raw get" "$evidence_dir/devapp-get-raw.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" '(input) as $raw | .ok == true and .data.unifiedAppId == $id and $raw.ok == true and $raw.data.unifiedAppId == $id and .data.appKey == $raw.data.appKey' "$evidence_dir/devapp-get-exact.json" "$evidence_dir/devapp-get-raw.json" >/dev/null || fail "devapp +get dual object read"
|
||||
pass "DEVAPP +get exact+raw stable-application-ID object alignment"
|
||||
|
||||
run_json "devapp raw update" "$evidence_dir/devapp-update-raw.json" \
|
||||
"$dws_bin" dev app update --unified-app-id "$exact_app_id" --name "$raw_updated_name" --desc "raw-update" --yes
|
||||
assert_jq "devapp raw update terminal receipt" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-update-raw.json"
|
||||
run_json "devapp raw update exact readback" "$evidence_dir/devapp-update-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" --arg name "$raw_updated_name" '.ok == true and .data.unifiedAppId == $id and .data.name == $name and .data.desc == "raw-update"' "$evidence_dir/devapp-update-raw-exact-readback.json" >/dev/null || fail "devapp raw update exact readback"
|
||||
run_json "devapp exact update" "$evidence_dir/devapp-update-exact.json" \
|
||||
"$dws_bin" devapp +update --unified-app-id "$exact_app_id" --name "$exact_updated_name" --desc "exact-update" --yes
|
||||
assert_jq "devapp exact update terminal receipt" '.ok == true and .outcome == "success" and .data.verified == true and .data.action == "update"' "$evidence_dir/devapp-update-exact.json"
|
||||
run_json "devapp exact update raw readback" "$evidence_dir/devapp-update-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" --arg name "$exact_updated_name" '.ok == true and .data.unifiedAppId == $id and .data.name == $name and .data.desc == "exact-update"' "$evidence_dir/devapp-update-exact-raw-readback.json" >/dev/null || fail "devapp exact update raw readback"
|
||||
pass "DEVAPP +update confirm0/exact+raw terminal-receipt/key-field readback"
|
||||
|
||||
run_json "devapp raw disable" "$evidence_dir/devapp-disable-raw.json" \
|
||||
"$dws_bin" dev app disable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp raw disable exact readback" "$evidence_dir/devapp-disable-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp raw disable terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-disable-raw.json"
|
||||
assert_jq "devapp raw disable exact state" '(.data.appStatus | ascii_downcase) == "disabled"' "$evidence_dir/devapp-disable-raw-exact-readback.json"
|
||||
run_json "devapp exact enable" "$evidence_dir/devapp-enable-exact.json" \
|
||||
"$dws_bin" devapp +enable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp exact enable raw readback" "$evidence_dir/devapp-enable-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp exact enable terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-enable-exact.json"
|
||||
assert_jq "devapp exact enable raw state" '(.data.appStatus | ascii_downcase) == "normal"' "$evidence_dir/devapp-enable-exact-raw-readback.json"
|
||||
run_json "devapp exact disable" "$evidence_dir/devapp-disable-exact.json" \
|
||||
"$dws_bin" devapp +disable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp exact disable raw readback" "$evidence_dir/devapp-disable-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp exact disable terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-disable-exact.json"
|
||||
assert_jq "devapp exact disable raw state" '(.data.appStatus | ascii_downcase) == "disabled"' "$evidence_dir/devapp-disable-exact-raw-readback.json"
|
||||
run_json "devapp raw enable" "$evidence_dir/devapp-enable-raw.json" \
|
||||
"$dws_bin" dev app enable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp raw enable exact readback" "$evidence_dir/devapp-enable-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp raw enable terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-enable-raw.json"
|
||||
assert_jq "devapp raw enable exact state" '(.data.appStatus | ascii_downcase) == "normal"' "$evidence_dir/devapp-enable-raw-exact-readback.json"
|
||||
pass "DEVAPP +disable confirm0/exact+raw terminal-receipt/disabled readback/restored"
|
||||
pass "DEVAPP +enable confirm0/exact+raw terminal-receipt/normal readback"
|
||||
|
||||
run_json "devapp exact credentials" "$evidence_dir/devapp-credentials-exact.json" \
|
||||
"$dws_bin" devapp +credentials-get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp raw credentials" "$evidence_dir/devapp-credentials-raw.json" \
|
||||
"$dws_bin" dev app credentials get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.unifiedAppId == $id and
|
||||
(.data.appKey | type) == "string" and (.data.appKey | length) > 0 and
|
||||
(.data.appSecret | type) == "string" and (.data.appSecret | length) > 0 and
|
||||
$raw.ok == true and $raw.data.unifiedAppId == $id and
|
||||
.data.appKey == $raw.data.appKey and .data.appSecret == $raw.data.appSecret
|
||||
' "$evidence_dir/devapp-credentials-exact.json" "$evidence_dir/devapp-credentials-raw.json" >/dev/null || fail "devapp +credentials-get dual object read"
|
||||
pass "DEVAPP +credentials-get exact+raw stable-app/client/one-nonempty-secret alignment"
|
||||
|
||||
run_json "devapp raw webapp config" "$evidence_dir/devapp-webapp-config-raw.json" \
|
||||
"$dws_bin" dev app webapp config --unified-app-id "$exact_app_id" --homepage-url "https://example.invalid/raw" --yes
|
||||
run_json "devapp raw webapp exact readback" "$evidence_dir/devapp-webapp-config-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +webapp-get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp raw webapp terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-webapp-config-raw.json"
|
||||
assert_jq "devapp raw webapp exact readback" '.data.homepageUrl == "https://example.invalid/raw"' "$evidence_dir/devapp-webapp-config-raw-exact-readback.json"
|
||||
run_json "devapp exact webapp config" "$evidence_dir/devapp-webapp-config-exact.json" \
|
||||
"$dws_bin" devapp +webapp-config --unified-app-id "$exact_app_id" --homepage-url "https://example.invalid/exact" --yes
|
||||
run_json "devapp exact webapp raw readback" "$evidence_dir/devapp-webapp-config-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app webapp get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp exact webapp terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-webapp-config-exact.json"
|
||||
assert_jq "devapp exact webapp raw readback" '.data.homepageUrl == "https://example.invalid/exact"' "$evidence_dir/devapp-webapp-config-exact-raw-readback.json"
|
||||
pass "DEVAPP +webapp-config confirm0/exact+raw terminal-receipt/URL readback"
|
||||
run_json "devapp exact webapp get final" "$evidence_dir/devapp-webapp-get-exact.json" \
|
||||
"$dws_bin" devapp +webapp-get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp raw webapp get final" "$evidence_dir/devapp-webapp-get-raw.json" \
|
||||
"$dws_bin" dev app webapp get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" '(input) as $raw | .data.unifiedAppId == $id and $raw.data.unifiedAppId == $id and .data.homepageUrl == $raw.data.homepageUrl' "$evidence_dir/devapp-webapp-get-exact.json" "$evidence_dir/devapp-webapp-get-raw.json" >/dev/null || fail "devapp +webapp-get dual object read"
|
||||
pass "DEVAPP +webapp-get exact+raw stable-app/key-field object alignment"
|
||||
|
||||
run_json "devapp member raw known" "$evidence_dir/devapp-member-known-raw.json" \
|
||||
"$dws_bin" dev app member list --unified-app-id "$exact_app_id"
|
||||
run_json "devapp member exact known" "$evidence_dir/devapp-member-known-exact.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id"
|
||||
run_json "devapp member exact zero" "$evidence_dir/devapp-member-zero-exact.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id" --user-id "$nonce"
|
||||
jq -e --arg nonce "$nonce" '
|
||||
(input) as $raw | (input) as $zero |
|
||||
.ok == true and .data.count > 0 and $raw.ok == true and ($raw.data.members | type) == "array" and
|
||||
([.data.members[].userId] | sort) == ([$raw.data.members[].userId] | sort) and
|
||||
$zero.ok == true and $zero.data.count == 0 and ($zero.data.members | length) == 0 and
|
||||
([$raw.data.members[].userId] | index($nonce)) == null
|
||||
' "$evidence_dir/devapp-member-known-exact.json" "$evidence_dir/devapp-member-known-raw.json" "$evidence_dir/devapp-member-zero-exact.json" >/dev/null || fail "devapp +member-list adapter alignment"
|
||||
pass "DEVAPP +member-list exact local-ID-filter+raw full-set known/guaranteed-zero stable-member alignment"
|
||||
|
||||
run_json "devapp member fixture exact before" "$evidence_dir/devapp-member-fixture-before-exact.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id" --user-id "$member_user_id"
|
||||
run_json "devapp member fixture raw before" "$evidence_dir/devapp-member-fixture-before-raw.json" \
|
||||
"$dws_bin" dev app member list --unified-app-id "$exact_app_id"
|
||||
jq -e --arg user "$member_user_id" '(input) as $raw | .data.count == 0 and (.data.members | length) == 0 and ([$raw.data.members[].userId] | index($user)) == null' \
|
||||
"$evidence_dir/devapp-member-fixture-before-exact.json" "$evidence_dir/devapp-member-fixture-before-raw.json" >/dev/null || fail "devapp member fixture initially absent"
|
||||
|
||||
expect_confirmation "devapp +member-add confirmation" "$evidence_dir/devapp-member-add-confirm.json" \
|
||||
"$dws_bin" devapp +member-add --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type"
|
||||
expect_confirmation "devapp +member-remove confirmation" "$evidence_dir/devapp-member-remove-confirm.json" \
|
||||
"$dws_bin" devapp +member-remove --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type"
|
||||
run_json "devapp member fixture exact after guards" "$evidence_dir/devapp-member-fixture-after-guards-exact.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id" --user-id "$member_user_id"
|
||||
run_json "devapp member fixture raw after guards" "$evidence_dir/devapp-member-fixture-after-guards-raw.json" \
|
||||
"$dws_bin" dev app member list --unified-app-id "$exact_app_id"
|
||||
jq -e --arg user "$member_user_id" '(input) as $raw | .data.count == 0 and (.data.members | length) == 0 and ([$raw.data.members[].userId] | index($user)) == null' \
|
||||
"$evidence_dir/devapp-member-fixture-after-guards-exact.json" "$evidence_dir/devapp-member-fixture-after-guards-raw.json" >/dev/null || fail "devapp member confirmations made no writes"
|
||||
|
||||
run_json "devapp member exact add" "$evidence_dir/devapp-member-add-exact.json" \
|
||||
"$dws_bin" devapp +member-add --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type" --yes
|
||||
run_json "devapp member exact add raw readback" "$evidence_dir/devapp-member-add-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app member list --unified-app-id "$exact_app_id"
|
||||
jq -e --arg type "$member_type" '.ok == true and .outcome == "success" and .data.verified == true and .data.action == "member_add" and .data.resource.count == 1 and .data.resource.memberType == $type' \
|
||||
"$evidence_dir/devapp-member-add-exact.json" >/dev/null || fail "devapp member exact add terminal"
|
||||
jq -e --arg user "$member_user_id" --arg type "$member_type" '([.data.members[] | select(.userId == $user and .memberType == $type)] | length) == 1' \
|
||||
"$evidence_dir/devapp-member-add-exact-raw-readback.json" >/dev/null || fail "devapp member exact add raw stable-ID role readback"
|
||||
|
||||
run_json "devapp member raw remove" "$evidence_dir/devapp-member-remove-raw.json" \
|
||||
"$dws_bin" dev app member remove --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type" --yes
|
||||
run_json "devapp member raw remove exact readback" "$evidence_dir/devapp-member-remove-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id" --user-id "$member_user_id"
|
||||
assert_jq "devapp member raw remove terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-member-remove-raw.json"
|
||||
assert_jq "devapp member raw remove exact absence" '.ok == true and .data.count == 0 and (.data.members | length) == 0' "$evidence_dir/devapp-member-remove-raw-exact-readback.json"
|
||||
|
||||
run_json "devapp member raw add" "$evidence_dir/devapp-member-add-raw.json" \
|
||||
"$dws_bin" dev app member add --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type" --yes
|
||||
run_json "devapp member raw add exact readback" "$evidence_dir/devapp-member-add-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +member-list --unified-app-id "$exact_app_id" --user-id "$member_user_id"
|
||||
assert_jq "devapp member raw add terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-member-add-raw.json"
|
||||
jq -e --arg user "$member_user_id" --arg type "$member_type" \
|
||||
'.ok == true and .data.count == 1 and .data.members[0].userId == $user and .data.members[0].memberType == $type' \
|
||||
"$evidence_dir/devapp-member-add-raw-exact-readback.json" >/dev/null || fail "devapp member raw add exact stable-ID role readback"
|
||||
|
||||
run_json "devapp member exact remove" "$evidence_dir/devapp-member-remove-exact.json" \
|
||||
"$dws_bin" devapp +member-remove --unified-app-id "$exact_app_id" --user-ids "$member_user_id" --member-type "$member_type" --yes
|
||||
run_json "devapp member exact remove raw readback" "$evidence_dir/devapp-member-remove-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app member list --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp member exact remove terminal" '.ok == true and .outcome == "success" and .data.verified == true and .data.action == "member_remove"' \
|
||||
"$evidence_dir/devapp-member-remove-exact.json"
|
||||
jq -e --arg user "$member_user_id" '([.data.members[].userId] | index($user)) == null' \
|
||||
"$evidence_dir/devapp-member-remove-exact-raw-readback.json" >/dev/null || fail "devapp member exact remove raw absence"
|
||||
pass "DEVAPP +member-add/+member-remove confirm0/exact+raw terminal-receipt/stable-ID role/absence readback"
|
||||
|
||||
run_json "devapp permission exact known" "$evidence_dir/devapp-permission-known-exact.json" \
|
||||
"$dws_bin" devapp +permission-list --unified-app-id "$exact_app_id" --page-size 20
|
||||
run_json "devapp permission raw known" "$evidence_dir/devapp-permission-known-raw.json" \
|
||||
"$dws_bin" dev app permission list --unified-app-id "$exact_app_id" --page-size 20
|
||||
run_json "devapp permission exact zero" "$evidence_dir/devapp-permission-zero-exact.json" \
|
||||
"$dws_bin" devapp +permission-list --unified-app-id "$exact_app_id" --keyword "$nonce" --page-size 20
|
||||
run_json "devapp permission raw zero" "$evidence_dir/devapp-permission-zero-raw.json" \
|
||||
"$dws_bin" dev app permission list --unified-app-id "$exact_app_id" --keyword "$nonce" --page-size 20
|
||||
assert_jq "devapp permission dual known/zero alignment" '
|
||||
(input) as $raw | (input) as $ze | (input) as $zr |
|
||||
.ok == true and .data.count > 0 and $raw.ok == true and ($raw.data.items | length) > 0 and
|
||||
([.data.permissions[].scopeValue] | sort) == ([$raw.data.items[].scopeValue] | sort) and
|
||||
$ze.ok == true and $ze.data.count == 0 and ($ze.data.permissions | length) == 0 and
|
||||
$zr.ok == true and ($zr.data.items | length) == 0 and
|
||||
.meta.pagination.endpoint_exhausted == $raw.meta.pagination.endpoint_exhausted and
|
||||
$ze.meta.pagination.endpoint_exhausted == true and $zr.meta.pagination.endpoint_exhausted == true
|
||||
' "$evidence_dir/devapp-permission-known-exact.json" "$evidence_dir/devapp-permission-known-raw.json" \
|
||||
"$evidence_dir/devapp-permission-zero-exact.json" "$evidence_dir/devapp-permission-zero-raw.json"
|
||||
pass "DEVAPP +permission-list exact+raw known-nonempty/guaranteed-zero stable-scope/cursor alignment"
|
||||
|
||||
run_json "devapp robot exact initial" "$evidence_dir/devapp-robot-get-exact.json" \
|
||||
"$dws_bin" devapp +robot-get --unified-app-id "$exact_app_id"
|
||||
run_json "devapp robot raw initial" "$evidence_dir/devapp-robot-get-raw.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
jq -e --arg id "$exact_app_id" '(input) as $raw | .data.unifiedAppId == $id and $raw.data.unifiedAppId == $id and .data.robotStatus == $raw.data.robotStatus' "$evidence_dir/devapp-robot-get-exact.json" "$evidence_dir/devapp-robot-get-raw.json" >/dev/null || fail "devapp +robot-get initial dual object"
|
||||
pass "DEVAPP +robot-get exact+raw stable-app/status object alignment"
|
||||
|
||||
run_json "devapp robot raw config" "$evidence_dir/devapp-robot-config-raw.json" \
|
||||
"$dws_bin" dev app robot config --unified-app-id "$exact_app_id" --name "$bot_raw" --brief "dual-live-raw" --desc "dual-live-raw" --mode STREAM --add-scope --yes
|
||||
run_json "devapp robot raw config exact readback" "$evidence_dir/devapp-robot-config-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +robot-get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot raw config terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-robot-config-raw.json"
|
||||
jq -e --arg name "$bot_raw" '.data.name == $name and .data.mode == "STREAM"' "$evidence_dir/devapp-robot-config-raw-exact-readback.json" >/dev/null || fail "devapp robot raw config exact readback"
|
||||
run_json "devapp robot exact config" "$evidence_dir/devapp-robot-config-exact.json" \
|
||||
"$dws_bin" devapp +robot-config --unified-app-id "$exact_app_id" --name "$bot_exact" --brief "dual-live-exact" --desc "dual-live-exact" --mode STREAM --yes
|
||||
run_json "devapp robot exact config raw readback" "$evidence_dir/devapp-robot-config-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot exact config terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-robot-config-exact.json"
|
||||
jq -e --arg name "$bot_exact" '.data.name == $name and .data.mode == "STREAM"' "$evidence_dir/devapp-robot-config-exact-raw-readback.json" >/dev/null || fail "devapp robot exact config raw readback"
|
||||
pass "DEVAPP +robot-config confirm0/exact+raw terminal-receipt/config-field readback"
|
||||
|
||||
run_json "devapp robot raw enable" "$evidence_dir/devapp-robot-enable-raw.json" \
|
||||
"$dws_bin" dev app robot enable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp robot raw enable exact readback" "$evidence_dir/devapp-robot-enable-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +robot-get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot raw enable terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-robot-enable-raw.json"
|
||||
assert_jq "devapp robot raw enable exact state" '.data.robotStatus == "ONLINE"' "$evidence_dir/devapp-robot-enable-raw-exact-readback.json"
|
||||
run_json "devapp robot exact disable" "$evidence_dir/devapp-robot-disable-exact.json" \
|
||||
"$dws_bin" devapp +robot-disable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp robot exact disable raw readback" "$evidence_dir/devapp-robot-disable-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot exact disable terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-robot-disable-exact.json"
|
||||
assert_jq "devapp robot exact disable raw state" '.data.robotStatus == "UNCONFIGURED"' "$evidence_dir/devapp-robot-disable-exact-raw-readback.json"
|
||||
run_json "devapp robot raw reconfigure" "$evidence_dir/devapp-robot-reconfigure-raw.json" \
|
||||
"$dws_bin" dev app robot config --unified-app-id "$exact_app_id" --name "$bot_raw" --brief "dual-live-raw" --mode STREAM --yes
|
||||
run_json "devapp robot exact enable" "$evidence_dir/devapp-robot-enable-exact.json" \
|
||||
"$dws_bin" devapp +robot-enable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp robot exact enable raw readback" "$evidence_dir/devapp-robot-enable-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app robot get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot exact enable terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-robot-enable-exact.json"
|
||||
assert_jq "devapp robot exact enable raw state" '.data.robotStatus == "ONLINE"' "$evidence_dir/devapp-robot-enable-exact-raw-readback.json"
|
||||
run_json "devapp robot raw disable" "$evidence_dir/devapp-robot-disable-raw.json" \
|
||||
"$dws_bin" dev app robot disable --unified-app-id "$exact_app_id" --yes
|
||||
run_json "devapp robot raw disable exact readback" "$evidence_dir/devapp-robot-disable-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +robot-get --unified-app-id "$exact_app_id"
|
||||
assert_jq "devapp robot raw disable terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-robot-disable-raw.json"
|
||||
assert_jq "devapp robot raw disable exact state" '.data.robotStatus == "UNCONFIGURED"' "$evidence_dir/devapp-robot-disable-raw-exact-readback.json"
|
||||
pass "DEVAPP +robot-enable confirm0/exact+raw terminal-receipt/ONLINE readback"
|
||||
pass "DEVAPP +robot-disable confirm0/exact+raw terminal-receipt/UNCONFIGURED readback"
|
||||
|
||||
run_json "devapp event raw subscribe" "$evidence_dir/devapp-event-subscribe-raw.json" \
|
||||
"$dws_bin" dev app event subscribe --unified-app-id "$exact_app_id" --event-codes "$event_raw" --yes
|
||||
run_json "devapp event raw subscribe exact replay" "$evidence_dir/devapp-event-subscribe-raw-exact-replay.json" \
|
||||
"$dws_bin" devapp +event-subscribe --unified-app-id "$exact_app_id" --event-codes "$event_raw" --yes
|
||||
run_json "devapp event raw subscribe raw readback" "$evidence_dir/devapp-event-subscribe-raw-readback.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --keyword "$event_raw" --page-size 100
|
||||
assert_jq "devapp event raw subscribe terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-event-subscribe-raw.json"
|
||||
assert_jq "devapp event raw subscribe exact replay" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-event-subscribe-raw-exact-replay.json"
|
||||
jq -e --arg code "$event_raw" '(.data.events | length) == 1 and .data.events[0].eventCode == $code' "$evidence_dir/devapp-event-subscribe-raw-readback.json" >/dev/null || fail "devapp event raw subscribe readback"
|
||||
run_json "devapp event exact subscribe" "$evidence_dir/devapp-event-subscribe-exact.json" \
|
||||
"$dws_bin" devapp +event-subscribe --unified-app-id "$exact_app_id" --event-codes "$event_exact" --yes
|
||||
run_json "devapp event exact subscribe raw readback" "$evidence_dir/devapp-event-subscribe-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --keyword "$event_exact" --page-size 100
|
||||
assert_jq "devapp event exact subscribe terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-event-subscribe-exact.json"
|
||||
jq -e --arg code "$event_exact" '(.data.events | length) == 1 and .data.events[0].eventCode == $code' "$evidence_dir/devapp-event-subscribe-exact-raw-readback.json" >/dev/null || fail "devapp event exact subscribe raw readback"
|
||||
pass "DEVAPP +event-subscribe confirm0/exact+raw terminal-receipt/eventCode readback"
|
||||
|
||||
run_json "devapp event exact known" "$evidence_dir/devapp-event-list-known-exact.json" \
|
||||
"$dws_bin" devapp +event-list --unified-app-id "$exact_app_id" --keyword "$event_exact" --page-size 100
|
||||
run_json "devapp event raw known" "$evidence_dir/devapp-event-list-known-raw.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --keyword "$event_exact" --page-size 100
|
||||
run_json "devapp event exact zero" "$evidence_dir/devapp-event-list-zero-exact.json" \
|
||||
"$dws_bin" devapp +event-list --unified-app-id "$exact_app_id" --keyword "$nonce" --page-size 100
|
||||
run_json "devapp event raw zero" "$evidence_dir/devapp-event-list-zero-raw.json" \
|
||||
"$dws_bin" dev app event list --unified-app-id "$exact_app_id" --keyword "$nonce" --page-size 100
|
||||
jq -e --arg code "$event_exact" '(input) as $raw | (input) as $ze | (input) as $zr |
|
||||
.ok == true and .data.count == 1 and .data.events[0].eventCode == $code and
|
||||
$raw.ok == true and ($raw.data.events | length) == 1 and $raw.data.events[0].eventCode == $code and
|
||||
.meta.pagination.endpoint_exhausted == true and $raw.meta.pagination.endpoint_exhausted == true and
|
||||
$ze.ok == true and $ze.data.count == 0 and ($ze.data.events | length) == 0 and
|
||||
$zr.ok == true and ($zr.data.events | length) == 0 and
|
||||
$ze.meta.pagination.endpoint_exhausted == true and $zr.meta.pagination.endpoint_exhausted == true' \
|
||||
"$evidence_dir/devapp-event-list-known-exact.json" "$evidence_dir/devapp-event-list-known-raw.json" \
|
||||
"$evidence_dir/devapp-event-list-zero-exact.json" "$evidence_dir/devapp-event-list-zero-raw.json" >/dev/null || fail "devapp +event-list dual known/zero alignment"
|
||||
pass "DEVAPP +event-list exact+raw known-nonempty/guaranteed-zero stable-event/cursor alignment"
|
||||
|
||||
run_json "devapp version exact zero before" "$evidence_dir/devapp-version-zero-exact.json" \
|
||||
"$dws_bin" devapp +version-list --unified-app-id "$exact_app_id" --page-size 100
|
||||
run_json "devapp version raw zero before" "$evidence_dir/devapp-version-zero-raw.json" \
|
||||
"$dws_bin" dev app version list --unified-app-id "$exact_app_id" --page-size 100
|
||||
assert_jq "devapp version guaranteed zero fixture" '(input) as $raw | .data.count == 0 and (.data.versions | length) == 0 and ($raw.data.items | length) == 0 and .meta.pagination.endpoint_exhausted == true and $raw.meta.pagination.endpoint_exhausted == true' "$evidence_dir/devapp-version-zero-exact.json" "$evidence_dir/devapp-version-zero-raw.json"
|
||||
run_json "devapp version raw create" "$evidence_dir/devapp-version-create-raw.json" \
|
||||
"$dws_bin" dev app version create --unified-app-id "$exact_app_id" --desc "dual-live-raw" --yes
|
||||
local raw_version_id
|
||||
raw_version_id=$(jq -er '.data.versionId | select(type == "string" and length > 0)' "$evidence_dir/devapp-version-create-raw.json") || fail "devapp raw version create stable ID"
|
||||
assert_jq "devapp raw version create terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-version-create-raw.json"
|
||||
run_json "devapp raw version exact readback" "$evidence_dir/devapp-version-create-raw-exact-readback.json" \
|
||||
"$dws_bin" devapp +version-get --unified-app-id "$exact_app_id" --version-id "$raw_version_id"
|
||||
jq -e --arg app "$exact_app_id" --arg version "$raw_version_id" '.ok == true and .data.unifiedAppId == $app and .data.versionId == $version' "$evidence_dir/devapp-version-create-raw-exact-readback.json" >/dev/null || fail "devapp raw version exact readback"
|
||||
run_json "devapp version exact create" "$evidence_dir/devapp-version-create-exact.json" \
|
||||
"$dws_bin" devapp +version-create --unified-app-id "$exact_app_id" --desc "dual-live-exact" --yes
|
||||
local exact_version_id
|
||||
exact_version_id=$(jq -er '.data.resource.versionId | select(type == "string" and length > 0)' "$evidence_dir/devapp-version-create-exact.json") || fail "devapp exact version create stable ID"
|
||||
assert_jq "devapp exact version create terminal" '.ok == true and .outcome == "success" and .data.verified == true' "$evidence_dir/devapp-version-create-exact.json"
|
||||
run_json "devapp exact version raw readback" "$evidence_dir/devapp-version-create-exact-raw-readback.json" \
|
||||
"$dws_bin" dev app version get --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
jq -e --arg app "$exact_app_id" --arg version "$exact_version_id" '.ok == true and .data.unifiedAppId == $app and .data.versionId == $version' "$evidence_dir/devapp-version-create-exact-raw-readback.json" >/dev/null || fail "devapp exact version raw readback"
|
||||
pass "DEVAPP +version-create confirm0/exact+raw terminal-receipt/app+version-ID readback"
|
||||
|
||||
local version_aligned=false
|
||||
for _ in 1 2 3 4 5; do
|
||||
run_json "devapp version exact known" "$evidence_dir/devapp-version-known-exact.json" \
|
||||
"$dws_bin" devapp +version-list --unified-app-id "$exact_app_id" --page-size 100
|
||||
run_json "devapp version raw known" "$evidence_dir/devapp-version-known-raw.json" \
|
||||
"$dws_bin" dev app version list --unified-app-id "$exact_app_id" --page-size 100
|
||||
if jq -e --arg raw_version "$raw_version_id" --arg exact_version "$exact_version_id" '
|
||||
(input) as $raw |
|
||||
.data.count >= 1 and
|
||||
([.data.versions[].versionId] | index($raw_version)) != null and
|
||||
([.data.versions[].versionId] | index($exact_version)) != null and
|
||||
([.data.versions[].versionId] | sort) == ([$raw.data.items[].versionId] | sort) and
|
||||
.meta.pagination.endpoint_exhausted == true and $raw.meta.pagination.endpoint_exhausted == true
|
||||
' "$evidence_dir/devapp-version-known-exact.json" "$evidence_dir/devapp-version-known-raw.json" >/dev/null 2>&1; then
|
||||
version_aligned=true
|
||||
break
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
if [[ $version_aligned != true ]]; then
|
||||
jq -n -c --arg raw_version "$raw_version_id" --arg exact_version "$exact_version_id" \
|
||||
--slurpfile exact "$evidence_dir/devapp-version-known-exact.json" \
|
||||
--slurpfile raw "$evidence_dir/devapp-version-known-raw.json" '{
|
||||
diagnostic:"DEVAPP-VERSION-LIST",
|
||||
exact_count:$exact[0].data.count,
|
||||
exact_items:($exact[0].data.versions|length),
|
||||
raw_items:($raw[0].data.items|length),
|
||||
ids_equal:(([$exact[0].data.versions[].versionId]|sort)==([$raw[0].data.items[].versionId]|sort)),
|
||||
raw_version_visible:(([$exact[0].data.versions[].versionId]|index($raw_version))!=null),
|
||||
exact_version_visible:(([$exact[0].data.versions[].versionId]|index($exact_version))!=null),
|
||||
exact_pagination_type:($exact[0].meta.pagination|type),
|
||||
raw_pagination_type:($raw[0].meta.pagination|type),
|
||||
exact_exhausted:$exact[0].meta.pagination.endpoint_exhausted,
|
||||
raw_exhausted:$raw[0].meta.pagination.endpoint_exhausted
|
||||
}' >&2
|
||||
fail "devapp version known alignment"
|
||||
fi
|
||||
pass "DEVAPP +version-list exact+raw known-nonempty/empty-fixture-zero stable-version/cursor alignment"
|
||||
|
||||
run_json "devapp version exact get" "$evidence_dir/devapp-version-get-exact.json" \
|
||||
"$dws_bin" devapp +version-get --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
run_json "devapp version raw get" "$evidence_dir/devapp-version-get-raw.json" \
|
||||
"$dws_bin" dev app version get --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
jq -e --arg app "$exact_app_id" --arg version "$exact_version_id" '(input) as $raw | .data.unifiedAppId == $app and .data.versionId == $version and $raw.data.unifiedAppId == $app and $raw.data.versionId == $version' "$evidence_dir/devapp-version-get-exact.json" "$evidence_dir/devapp-version-get-raw.json" >/dev/null || fail "devapp +version-get dual object"
|
||||
pass "DEVAPP +version-get exact+raw stable-app+version-ID object alignment"
|
||||
|
||||
run_json "devapp version exact approval" "$evidence_dir/devapp-version-approval-exact.json" \
|
||||
"$dws_bin" devapp +version-check-approval --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
run_json "devapp version raw approval" "$evidence_dir/devapp-version-approval-raw.json" \
|
||||
"$dws_bin" dev app version check-approval --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
jq -e --arg app "$exact_app_id" --arg version "$exact_version_id" '(input) as $raw | (.outcome == "success" or .outcome == "pending") and .data.unifiedAppId == $app and .data.versionId == $version and ($raw.outcome == "success" or $raw.outcome == "pending") and $raw.data.unifiedAppId == $app and $raw.data.versionId == $version' "$evidence_dir/devapp-version-approval-exact.json" "$evidence_dir/devapp-version-approval-raw.json" >/dev/null || fail "devapp +version-check-approval dual object"
|
||||
pass "DEVAPP +version-check-approval exact+raw stable-app+version-ID pending/terminal alignment"
|
||||
|
||||
run_json "devapp version exact status" "$evidence_dir/devapp-version-status-exact.json" \
|
||||
"$dws_bin" devapp +version-status --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
run_json "devapp version raw status" "$evidence_dir/devapp-version-status-raw.json" \
|
||||
"$dws_bin" dev app version status --unified-app-id "$exact_app_id" --version-id "$exact_version_id"
|
||||
jq -e --arg app "$exact_app_id" --arg version "$exact_version_id" '(input) as $raw | (.outcome == "success" or .outcome == "pending") and .data.unifiedAppId == $app and .data.versionId == $version and ($raw.outcome == "success" or $raw.outcome == "pending") and $raw.data.unifiedAppId == $app and $raw.data.versionId == $version' "$evidence_dir/devapp-version-status-exact.json" "$evidence_dir/devapp-version-status-raw.json" >/dev/null || fail "devapp +version-status dual object"
|
||||
pass "DEVAPP +version-status exact+raw stable-app+version-ID status alignment"
|
||||
|
||||
run_json "devapp raw delete" "$evidence_dir/devapp-delete-raw.json" \
|
||||
"$dws_bin" dev app delete --unified-app-id "$raw_app_id" --confirm-name "$raw_app_name" --yes
|
||||
assert_jq "devapp raw delete terminal" '.ok == true and .outcome == "success"' "$evidence_dir/devapp-delete-raw.json"
|
||||
run_json "devapp raw delete exact absence" "$evidence_dir/devapp-delete-raw-exact-absence.json" \
|
||||
"$dws_bin" devapp +list --name "$raw_app_name" --page-size 20
|
||||
run_json "devapp raw delete raw absence" "$evidence_dir/devapp-delete-raw-raw-absence.json" \
|
||||
"$dws_bin" dev app list --name "$raw_app_name" --page-size 20
|
||||
assert_jq "devapp raw delete dual absence" '(input) as $raw | .data.count == 0 and (.data.apps | length) == 0 and ($raw.data.items | length) == 0' "$evidence_dir/devapp-delete-raw-exact-absence.json" "$evidence_dir/devapp-delete-raw-raw-absence.json"
|
||||
raw_app_id=""
|
||||
|
||||
run_json "devapp exact delete" "$evidence_dir/devapp-delete-exact.json" \
|
||||
"$dws_bin" devapp +delete --unified-app-id "$exact_app_id" --yes
|
||||
assert_jq "devapp exact delete terminal" '.ok == true and .outcome == "success" and .data.verified == true and .data.action == "delete"' "$evidence_dir/devapp-delete-exact.json"
|
||||
run_json "devapp exact delete exact absence" "$evidence_dir/devapp-delete-exact-exact-absence.json" \
|
||||
"$dws_bin" devapp +list --name "$exact_updated_name" --page-size 20
|
||||
run_json "devapp exact delete raw absence" "$evidence_dir/devapp-delete-exact-raw-absence.json" \
|
||||
"$dws_bin" dev app list --name "$exact_updated_name" --page-size 20
|
||||
assert_jq "devapp exact delete dual absence" '(input) as $raw | .data.count == 0 and (.data.apps | length) == 0 and ($raw.data.items | length) == 0' "$evidence_dir/devapp-delete-exact-exact-absence.json" "$evidence_dir/devapp-delete-exact-raw-absence.json"
|
||||
exact_app_id=""
|
||||
pass "DEVAPP +delete confirm0/exact+raw terminal-receipt/dual absence cleanup"
|
||||
|
||||
pass "DEVAPP-INVENTORY public=25 dual-layer-pass=25 unavailable=5 cleanup=zero-residual"
|
||||
}
|
||||
|
||||
run_agoal_gate() {
|
||||
assert_public_surface agoal "+contract-fields
|
||||
+obj-template-list
|
||||
+report-statistics-list
|
||||
+report-submit-detail
|
||||
+user-rules"
|
||||
local nonce="DWS-GUARANTEED-ZERO-8F3D2C4A"
|
||||
local future_date="2099-12-31"
|
||||
|
||||
run_json "agoal report statistics exact known" "$evidence_dir/agoal-report-known-exact.json" \
|
||||
"$dws_bin" agoal +report-statistics-list
|
||||
run_json "agoal report statistics raw known" "$evidence_dir/agoal-report-known-raw.json" \
|
||||
"$dws_bin" agoal report list-statistics
|
||||
assert_jq "agoal report statistics known alignment" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count > 0 and
|
||||
$raw.success == true and ($raw.content | type) == "array" and
|
||||
(.data.count == ($raw.content | length)) and
|
||||
([.data.statistics[].templateId] | sort) == ([$raw.content[].templateId] | sort)
|
||||
' "$evidence_dir/agoal-report-known-exact.json" "$evidence_dir/agoal-report-known-raw.json"
|
||||
run_json "agoal report statistics exact zero" "$evidence_dir/agoal-report-zero-exact.json" \
|
||||
"$dws_bin" agoal +report-statistics-list --keyword "$nonce"
|
||||
run_json "agoal report statistics raw zero" "$evidence_dir/agoal-report-zero-raw.json" \
|
||||
"$dws_bin" agoal report list-statistics --keyword "$nonce"
|
||||
assert_jq "agoal report statistics zero alignment" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count == 0 and
|
||||
(.data.statistics | type) == "array" and (.data.statistics | length) == 0 and
|
||||
$raw.success == true and ($raw.content | type) == "array" and ($raw.content | length) == 0
|
||||
' "$evidence_dir/agoal-report-zero-exact.json" "$evidence_dir/agoal-report-zero-raw.json"
|
||||
pass "AGOAL +report-statistics-list exact+raw known-nonempty/guaranteed-zero stable-template alignment"
|
||||
|
||||
run_json "agoal template exact known" "$evidence_dir/agoal-template-known-exact.json" \
|
||||
"$dws_bin" agoal +obj-template-list --page 1 --page-size 20
|
||||
run_json "agoal template raw known" "$evidence_dir/agoal-template-known-raw.json" \
|
||||
"$dws_bin" agoal obj-template list --page 1 --page-size 20
|
||||
assert_jq "agoal template known alignment" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count > 0 and
|
||||
$raw.success == true and ($raw.content.result | type) == "array" and
|
||||
.data.page == $raw.content.page and .data.pageSize == $raw.content.pageSize and
|
||||
.data.totalCount == $raw.content.totalCount and
|
||||
([.data.templates[] | (.id // .templateId)] | sort) ==
|
||||
([$raw.content.result[] | (.id // .templateId)] | sort)
|
||||
' "$evidence_dir/agoal-template-known-exact.json" "$evidence_dir/agoal-template-known-raw.json"
|
||||
run_json "agoal template exact zero" "$evidence_dir/agoal-template-zero-exact.json" \
|
||||
"$dws_bin" agoal +obj-template-list --keyword "$nonce" --page 1 --page-size 20
|
||||
run_json "agoal template raw zero" "$evidence_dir/agoal-template-zero-raw.json" \
|
||||
"$dws_bin" agoal obj-template list --keyword "$nonce" --page 1 --page-size 20
|
||||
assert_jq "agoal template zero alignment" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count == 0 and .data.totalCount == 0 and
|
||||
(.data.templates | type) == "array" and (.data.templates | length) == 0 and
|
||||
$raw.success == true and ($raw.content.result | type) == "array" and
|
||||
($raw.content.result | length) == 0 and $raw.content.totalCount == 0 and
|
||||
.data.page == $raw.content.page and .data.pageSize == $raw.content.pageSize
|
||||
' "$evidence_dir/agoal-template-zero-exact.json" "$evidence_dir/agoal-template-zero-raw.json"
|
||||
pass "AGOAL +obj-template-list exact+raw known-nonempty/guaranteed-zero stable-ID/page alignment"
|
||||
|
||||
run_json "agoal contract fields raw" "$evidence_dir/agoal-fields-raw.json" \
|
||||
"$dws_bin" agoal contract fields
|
||||
local field_id
|
||||
field_id=$(jq -er '.content[0].id | select(type == "string" and length > 0)' "$evidence_dir/agoal-fields-raw.json") || fail "agoal contract fields raw fixture"
|
||||
run_json "agoal contract fields exact known" "$evidence_dir/agoal-fields-known-exact.json" \
|
||||
"$dws_bin" agoal +contract-fields --keyword "$field_id"
|
||||
run_json "agoal contract fields exact zero" "$evidence_dir/agoal-fields-zero-exact.json" \
|
||||
"$dws_bin" agoal +contract-fields --keyword "$nonce"
|
||||
jq -e --arg field_id "$field_id" --arg nonce "$nonce" '
|
||||
(input) as $zero | (input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count == 1 and
|
||||
.data.fields[0].id == $field_id and
|
||||
$zero.ok == true and $zero.outcome == "success" and $zero.data.count == 0 and
|
||||
($zero.data.fields | length) == 0 and
|
||||
$raw.success == true and ($raw.content | type) == "array" and ($raw.content | length) > 0 and
|
||||
([$raw.content[].id] | index($field_id)) != null and
|
||||
([$raw.content[] | [.id,.code,.title,.category,.type] | map(select(type == "string")) | join(" ") | ascii_downcase] |
|
||||
map(contains($nonce | ascii_downcase)) | any) == false
|
||||
' "$evidence_dir/agoal-fields-known-exact.json" "$evidence_dir/agoal-fields-zero-exact.json" "$evidence_dir/agoal-fields-raw.json" >/dev/null 2>&1 || fail "agoal contract fields adapter alignment"
|
||||
pass "AGOAL +contract-fields exact local-filter+raw full-set known/guaranteed-zero stable-ID alignment"
|
||||
|
||||
run_json "agoal user rules raw" "$evidence_dir/agoal-rules-raw.json" \
|
||||
"$dws_bin" agoal user rules
|
||||
local rule_id
|
||||
rule_id=$(jq -er '.content.rules[0].id | select(type == "string" and length > 0)' "$evidence_dir/agoal-rules-raw.json") || fail "agoal user rules raw fixture"
|
||||
run_json "agoal user rules exact known" "$evidence_dir/agoal-rules-known-exact.json" \
|
||||
"$dws_bin" agoal +user-rules --rule-id "$rule_id"
|
||||
run_json "agoal user rules exact zero" "$evidence_dir/agoal-rules-zero-exact.json" \
|
||||
"$dws_bin" agoal +user-rules --rule-id "$nonce"
|
||||
jq -e --arg rule_id "$rule_id" --arg nonce "$nonce" '
|
||||
(input) as $zero | (input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count == 1 and .data.rules[0].id == $rule_id and
|
||||
$zero.ok == true and $zero.outcome == "success" and $zero.data.count == 0 and
|
||||
($zero.data.rules | length) == 0 and
|
||||
$raw.success == true and ($raw.content.rules | type) == "array" and ($raw.content.rules | length) > 0 and
|
||||
([$raw.content.rules[].id] | index($rule_id)) != null and
|
||||
([$raw.content.rules[].id] | index($nonce)) == null
|
||||
' "$evidence_dir/agoal-rules-known-exact.json" "$evidence_dir/agoal-rules-zero-exact.json" "$evidence_dir/agoal-rules-raw.json" >/dev/null 2>&1 || fail "agoal user rules adapter alignment"
|
||||
pass "AGOAL +user-rules exact local-filter+raw full-set known/guaranteed-zero stable-rule alignment"
|
||||
|
||||
local template_id=""
|
||||
local submit_state=""
|
||||
while IFS= read -r candidate_template; do
|
||||
for candidate_state in ON_TIME LATE NOT_SUBMITTED; do
|
||||
run_json "agoal submission raw fixture scan" "$evidence_dir/agoal-submit-scan.json" \
|
||||
"$dws_bin" agoal report submit-detail --template-id "$candidate_template" --submit-state "$candidate_state" --page 1 --page-size 20 --timeout 60
|
||||
if jq -e '.success == true and (.content.result | type) == "array" and (.content.result | length) > 0' "$evidence_dir/agoal-submit-scan.json" >/dev/null; then
|
||||
template_id=$candidate_template
|
||||
submit_state=$candidate_state
|
||||
cp "$evidence_dir/agoal-submit-scan.json" "$evidence_dir/agoal-submit-known-raw.json"
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done < <(jq -r '.content[].templateId' "$evidence_dir/agoal-report-known-raw.json")
|
||||
[[ -n $template_id && -n $submit_state ]] || fail "agoal submission known-nonempty fixture"
|
||||
run_json "agoal submission exact known" "$evidence_dir/agoal-submit-known-exact.json" \
|
||||
"$dws_bin" agoal +report-submit-detail --template-id "$template_id" --submit-state "$submit_state" --page 1 --page-size 20 --timeout 60
|
||||
assert_jq "agoal submission known alignment" '
|
||||
(input) as $raw |
|
||||
def stable_id: (.reportId // .user.dingUserId // .user.id);
|
||||
.ok == true and .outcome == "success" and .data.count > 0 and
|
||||
.data.page == $raw.content.page and .data.pageSize == $raw.content.pageSize and
|
||||
.data.totalCount == $raw.content.totalCount and
|
||||
([.data.submissions[] | stable_id] | sort) == ([$raw.content.result[] | stable_id] | sort)
|
||||
' "$evidence_dir/agoal-submit-known-exact.json" "$evidence_dir/agoal-submit-known-raw.json"
|
||||
run_json "agoal submission exact guaranteed zero" "$evidence_dir/agoal-submit-zero-exact.json" \
|
||||
"$dws_bin" agoal +report-submit-detail --template-id "$template_id" --submit-state ON_TIME --query-date "$future_date" --page 1 --page-size 20 --timeout 60
|
||||
run_json "agoal submission raw guaranteed zero" "$evidence_dir/agoal-submit-zero-raw.json" \
|
||||
"$dws_bin" agoal report submit-detail --template-id "$template_id" --submit-state ON_TIME --query-date "$future_date" --page 1 --page-size 20 --timeout 60
|
||||
assert_jq "agoal submission guaranteed zero alignment" '
|
||||
(input) as $raw |
|
||||
.ok == true and .outcome == "success" and .data.count == 0 and .data.totalCount == 0 and
|
||||
(.data.submissions | type) == "array" and (.data.submissions | length) == 0 and
|
||||
$raw.success == true and ($raw.content.result | type) == "array" and
|
||||
($raw.content.result | length) == 0 and $raw.content.totalCount == 0 and
|
||||
.data.page == $raw.content.page and .data.pageSize == $raw.content.pageSize
|
||||
' "$evidence_dir/agoal-submit-zero-exact.json" "$evidence_dir/agoal-submit-zero-raw.json"
|
||||
pass "AGOAL +report-submit-detail exact+raw known-nonempty/future guaranteed-zero stable-user/page alignment"
|
||||
|
||||
pass "AGOAL-INVENTORY public=5 dual-layer-pass=5 unavailable=11"
|
||||
}
|
||||
|
||||
if [[ $selected_product == all || $selected_product == dev ]]; then
|
||||
run_dev_gate
|
||||
fi
|
||||
if [[ $selected_product == all || $selected_product == devapp ]]; then
|
||||
# Added below after the Agoal proof block so product execution remains
|
||||
# Dev -> DevApp -> Agoal when `all` is selected.
|
||||
run_devapp_gate
|
||||
fi
|
||||
if [[ $selected_product == all || $selected_product == agoal ]]; then
|
||||
run_agoal_gate
|
||||
fi
|
||||
@@ -40,8 +40,6 @@ SEMANTIC_PATHS = [
|
||||
ROOT / "internal" / "shortcut" / "semantic_catalog_devdoc.json",
|
||||
ROOT / "internal" / "shortcut" / "semantic_catalog_hrbrain.json",
|
||||
ROOT / "internal" / "shortcut" / "semantic_catalog_pat.json",
|
||||
ROOT / "internal" / "shortcut" / "semantic_catalog_devapp.json",
|
||||
ROOT / "internal" / "shortcut" / "semantic_catalog_agoal.json",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -19,172 +19,17 @@ trap cleanup EXIT HUP INT TERM
|
||||
|
||||
git -C "$ROOT" diff --no-ext-diff --find-renames --name-status "$merge_base" "$head" >"$tmp_root/status"
|
||||
|
||||
normalize_notes() {
|
||||
awk '
|
||||
/^[[:space:]]*$/ && !started { next }
|
||||
{ started = 1; lines[++count] = $0 }
|
||||
END {
|
||||
while (count > 0 && lines[count] ~ /^[[:space:]]*$/) count--
|
||||
for (line_no = 1; line_no <= count; line_no++) print lines[line_no]
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
extract_release_notes() {
|
||||
git -C "$ROOT" show "$1:CHANGELOG.md" |
|
||||
awk -v heading="## [$2] - " '
|
||||
index($0, heading) == 1 { found = 1; next }
|
||||
found && /^## / { exit }
|
||||
found { print }
|
||||
'
|
||||
}
|
||||
|
||||
release_heading() {
|
||||
git -C "$ROOT" show "$1:CHANGELOG.md" |
|
||||
awk -v heading="## [$2] - " 'index($0, heading) == 1 { print }'
|
||||
}
|
||||
|
||||
changelog_without_release_notes() {
|
||||
git -C "$ROOT" show "$1:CHANGELOG.md" |
|
||||
awk -v heading="## [$2] - " '
|
||||
index($0, heading) == 1 { print; skipped = 1; next }
|
||||
skipped && /^## / { skipped = 0 }
|
||||
!skipped { print }
|
||||
'
|
||||
}
|
||||
|
||||
# A pre-tag beta amendment must preserve the original seal verbatim except for
|
||||
# appending newly archived fragment bodies to their existing categories. These
|
||||
# helpers canonicalize the renderer's category format before comparing it.
|
||||
canonicalize_fragment_notes() {
|
||||
awk '
|
||||
BEGIN { order[1] = "Added"; order[2] = "Changed"; order[3] = "Deprecated"; order[4] = "Removed"; order[5] = "Fixed"; order[6] = "Security" }
|
||||
function trim(value) {
|
||||
sub(/^[\n]+/, "", value)
|
||||
sub(/[\n]+$/, "", value)
|
||||
return value
|
||||
}
|
||||
function flush() {
|
||||
if (category == "") return
|
||||
value = trim(body)
|
||||
if (value == "" || seen[category]++) invalid = 1
|
||||
blocks[category] = value
|
||||
category = ""
|
||||
body = ""
|
||||
}
|
||||
/^### / {
|
||||
flush()
|
||||
candidate = substr($0, 5)
|
||||
if (candidate !~ /^(Added|Changed|Deprecated|Removed|Fixed|Security)$/) {
|
||||
invalid = 1
|
||||
next
|
||||
}
|
||||
category = candidate
|
||||
next
|
||||
}
|
||||
{
|
||||
if (category == "") {
|
||||
if ($0 !~ /^[[:space:]]*$/) invalid = 1
|
||||
next
|
||||
}
|
||||
body = body $0 "\n"
|
||||
}
|
||||
END {
|
||||
flush()
|
||||
if (invalid) exit 1
|
||||
for (i = 1; i <= 6; i++) {
|
||||
category = order[i]
|
||||
if (category in blocks) printf "### %s\n\n%s\n\n", category, blocks[category]
|
||||
}
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
|
||||
merge_canonical_fragment_notes() {
|
||||
awk '
|
||||
BEGIN { order[1] = "Added"; order[2] = "Changed"; order[3] = "Deprecated"; order[4] = "Removed"; order[5] = "Fixed"; order[6] = "Security" }
|
||||
function trim(value) {
|
||||
sub(/^[\n]+/, "", value)
|
||||
sub(/[\n]+$/, "", value)
|
||||
return value
|
||||
}
|
||||
function flush() {
|
||||
if (category == "") return
|
||||
value = trim(body)
|
||||
if (value == "") invalid = 1
|
||||
if (part == 1) before[category] = value
|
||||
else if (part == 2) addition[category] = value
|
||||
else invalid = 1
|
||||
category = ""
|
||||
body = ""
|
||||
}
|
||||
FNR == 1 {
|
||||
if (started) flush()
|
||||
started = 1
|
||||
part++
|
||||
}
|
||||
/^### / {
|
||||
flush()
|
||||
category = substr($0, 5)
|
||||
if (category !~ /^(Added|Changed|Deprecated|Removed|Fixed|Security)$/) invalid = 1
|
||||
next
|
||||
}
|
||||
{ body = body $0 "\n" }
|
||||
END {
|
||||
flush()
|
||||
if (invalid || part != 2) exit 1
|
||||
for (i = 1; i <= 6; i++) {
|
||||
category = order[i]
|
||||
if (!(category in before) && !(category in addition)) continue
|
||||
printf "### %s\n\n", category
|
||||
if (category in before) printf "%s\n\n", before[category]
|
||||
if (category in addition) printf "%s\n\n", addition[category]
|
||||
}
|
||||
}
|
||||
' "$1" "$2"
|
||||
}
|
||||
|
||||
archive_changed=false
|
||||
if awk -F '\t' '{ for (field = 2; field <= NF; field++) if ($field ~ /^\.changes\/released\//) found = 1 } END { exit !found }' "$tmp_root/status"; then
|
||||
archive_changed=true
|
||||
fi
|
||||
|
||||
if [ "$archive_changed" = true ]; then
|
||||
new_release_version="$(git -C "$ROOT" diff --no-ext-diff --unified=0 "$merge_base" "$head" -- CHANGELOG.md | sed -n 's/^+## \[\([0-9][0-9.]*\(-beta\.[1-9][0-9]*\)\{0,1\}\)\] - .*/\1/p')"
|
||||
new_release_version_count="$(printf '%s\n' "$new_release_version" | sed '/^$/d' | wc -l | tr -d '[:space:]')"
|
||||
archival_mode=seal
|
||||
if [ "$new_release_version_count" -eq 1 ]; then
|
||||
release_version="$new_release_version"
|
||||
else
|
||||
# An amendment keeps the existing heading. Derive the one allowed target
|
||||
# from the literal archive directory, then verify every move below.
|
||||
release_version="$(awk -F '\t' '$1 == "R100" && NF == 3 && $3 ~ /^\.changes\/released\// { path = $3; sub(/^\.changes\/released\//, "", path); sub(/\/.*/, "", path); print path }' "$tmp_root/status" | sort -u)"
|
||||
[ "$(printf '%s\n' "$release_version" | sed '/^$/d' | wc -l | tr -d '[:space:]')" -eq 1 ] || {
|
||||
printf '%s\n' 'error: release-fragment archival requires exactly one newly added versioned CHANGELOG section or one untagged beta amendment target' >&2
|
||||
exit 1
|
||||
}
|
||||
printf '%s\n' "$release_version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+-beta\.[1-9][0-9]*$' || {
|
||||
printf '%s\n' 'error: only an existing beta CHANGELOG section may receive a pre-tag fragment amendment' >&2
|
||||
exit 1
|
||||
}
|
||||
base_heading="$(release_heading "$merge_base" "$release_version")"
|
||||
head_heading="$(release_heading "$head" "$release_version")"
|
||||
[ "$(printf '%s\n' "$base_heading" | sed '/^$/d' | wc -l | tr -d '[:space:]')" -eq 1 ] && [ "$base_heading" = "$head_heading" ] || {
|
||||
printf '%s\n' 'error: beta fragment amendment requires one unchanged pre-existing CHANGELOG heading' >&2
|
||||
exit 1
|
||||
}
|
||||
changelog_without_release_notes "$merge_base" "$release_version" >"$tmp_root/base-changelog-without-amendment"
|
||||
changelog_without_release_notes "$head" "$release_version" >"$tmp_root/head-changelog-without-amendment"
|
||||
if ! cmp -s "$tmp_root/base-changelog-without-amendment" "$tmp_root/head-changelog-without-amendment"; then
|
||||
printf '%s\n' 'error: beta fragment amendment may change only its existing beta CHANGELOG section' >&2
|
||||
exit 1
|
||||
fi
|
||||
if git -C "$ROOT" rev-parse --verify --quiet "refs/tags/v$release_version^{commit}" >/dev/null; then
|
||||
printf 'error: beta fragment amendment is forbidden after tag v%s exists\n' "$release_version" >&2
|
||||
exit 1
|
||||
fi
|
||||
archival_mode=beta-amendment
|
||||
fi
|
||||
release_version="$(git -C "$ROOT" diff --no-ext-diff --unified=0 "$merge_base" "$head" -- CHANGELOG.md | sed -n 's/^+## \[\([0-9][0-9.]*\(-beta\.[1-9][0-9]*\)\{0,1\}\)\] - .*/\1/p')"
|
||||
[ "$(printf '%s\n' "$release_version" | sed '/^$/d' | wc -l | tr -d '[:space:]')" -eq 1 ] || {
|
||||
printf '%s\n' 'error: release-fragment archival requires exactly one newly added versioned CHANGELOG section' >&2
|
||||
exit 1
|
||||
}
|
||||
# The archive directory is matched as a literal prefix, never as a regex:
|
||||
# interpolating the version into one would make `.` match any character, so
|
||||
# `1.0.1-beta.1` would also admit `.changes/released/1x0x1-betaX1/` and break
|
||||
@@ -202,7 +47,7 @@ if [ "$archive_changed" = true ]; then
|
||||
{ invalid = 1 }
|
||||
END { exit !(changelog && moved > 0 && !invalid) }
|
||||
' "$tmp_root/status"; then
|
||||
printf '%s\n' 'error: release fragments must be unchanged R100 moves from .changes/<name>.md to .changes/released/<new-version>/<name>.md in the matching release-seal or untagged beta-amendment PR' >&2
|
||||
printf '%s\n' 'error: release fragments must be unchanged R100 moves from .changes/<name>.md to .changes/released/<new-version>/<name>.md in the matching release-seal PR' >&2
|
||||
exit 1
|
||||
fi
|
||||
source_changes="$tmp_root/source-changes"
|
||||
@@ -218,25 +63,17 @@ if [ "$archive_changed" = true ]; then
|
||||
esac
|
||||
done
|
||||
"$ROOT/scripts/release/render-release-fragments.sh" "$source_changes" >"$tmp_root/expected-notes"
|
||||
if [ "$archival_mode" = beta-amendment ]; then
|
||||
extract_release_notes "$merge_base" "$release_version" >"$tmp_root/base-notes"
|
||||
extract_release_notes "$head" "$release_version" >"$tmp_root/head-notes"
|
||||
if ! canonicalize_fragment_notes "$tmp_root/base-notes" >"$tmp_root/base-notes.canonical" ||
|
||||
! canonicalize_fragment_notes "$tmp_root/expected-notes" >"$tmp_root/amendment-notes.canonical" ||
|
||||
! merge_canonical_fragment_notes "$tmp_root/base-notes.canonical" "$tmp_root/amendment-notes.canonical" >"$tmp_root/expected-notes.merged" ||
|
||||
! canonicalize_fragment_notes "$tmp_root/head-notes" >"$tmp_root/actual-notes.canonical"; then
|
||||
printf '%s\n' 'error: beta fragment amendment requires canonical rendered fragment categories' >&2
|
||||
exit 1
|
||||
fi
|
||||
normalize_notes "$tmp_root/expected-notes.merged" >"$tmp_root/expected-notes.normalized"
|
||||
normalize_notes "$tmp_root/actual-notes.canonical" >"$tmp_root/actual-notes.normalized"
|
||||
else
|
||||
extract_release_notes "$head" "$release_version" >"$tmp_root/actual-section"
|
||||
case "$release_version" in
|
||||
*-beta.*)
|
||||
cp "$tmp_root/actual-section" "$tmp_root/actual-notes"
|
||||
;;
|
||||
*)
|
||||
git -C "$ROOT" show "$head:CHANGELOG.md" |
|
||||
awk -v heading="## [$release_version] - " '
|
||||
index($0, heading) == 1 { found = 1; next }
|
||||
found && /^## / { exit }
|
||||
found { print }
|
||||
' >"$tmp_root/actual-section"
|
||||
case "$release_version" in
|
||||
*-beta.*)
|
||||
cp "$tmp_root/actual-section" "$tmp_root/actual-notes"
|
||||
;;
|
||||
*)
|
||||
stable_beta="$(sed -n 's/^### Changes since `\(v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*-beta\.[1-9][0-9]*\)`$/\1/p' "$tmp_root/actual-section")"
|
||||
[ "$(printf '%s\n' "$stable_beta" | sed '/^$/d' | wc -l | tr -d '[:space:]')" -eq 1 ] || {
|
||||
printf '%s\n' 'error: stable release-seal with archived fragments requires exactly one ### Changes since `vX.Y.Z-beta.N` boundary' >&2
|
||||
@@ -251,13 +88,22 @@ if [ "$archive_changed" = true ]; then
|
||||
found { print }
|
||||
/^### Changes since `v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*-beta\.[1-9][0-9]*`$/ { found = 1 }
|
||||
' "$tmp_root/actual-section" >"$tmp_root/actual-notes"
|
||||
;;
|
||||
esac
|
||||
normalize_notes "$tmp_root/expected-notes" >"$tmp_root/expected-notes.normalized"
|
||||
normalize_notes "$tmp_root/actual-notes" >"$tmp_root/actual-notes.normalized"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
normalize_notes() {
|
||||
awk '
|
||||
/^[[:space:]]*$/ && !started { next }
|
||||
{ started = 1; lines[++count] = $0 }
|
||||
END {
|
||||
while (count > 0 && lines[count] ~ /^[[:space:]]*$/) count--
|
||||
for (line_no = 1; line_no <= count; line_no++) print lines[line_no]
|
||||
}
|
||||
' "$1"
|
||||
}
|
||||
normalize_notes "$tmp_root/expected-notes" >"$tmp_root/expected-notes.normalized"
|
||||
normalize_notes "$tmp_root/actual-notes" >"$tmp_root/actual-notes.normalized"
|
||||
if ! cmp -s "$tmp_root/expected-notes.normalized" "$tmp_root/actual-notes.normalized"; then
|
||||
printf '%s\n' 'error: release CHANGELOG section does not exactly match the rendered active release fragments' >&2
|
||||
printf '%s\n' 'error: release-seal CHANGELOG section does not exactly match the rendered active release fragments' >&2
|
||||
diff -u "$tmp_root/expected-notes.normalized" "$tmp_root/actual-notes.normalized" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -43,14 +43,13 @@ cli_version: ">=1.0.15"
|
||||
|
||||
| 服务 | shortcut 数 | multi skill |
|
||||
|---|---:|---|
|
||||
| `agoal` | 5 | `—` |
|
||||
| `aisearch` | 1 | `—` |
|
||||
| `aitable` | 100 | `dingtalk-aitable` |
|
||||
| `attendance` | 8 | `dingtalk-misc` |
|
||||
| `calendar` | 27 | `dingtalk-calendar` |
|
||||
| `chat` | 98 | `dingtalk-chat` |
|
||||
| `contact` | 13 | `dingtalk-contact` |
|
||||
| `devapp` | 25 | `dingtalk-misc` |
|
||||
| `devapp` | 19 | `dingtalk-misc` |
|
||||
| `ding` | 1 | `dingtalk-misc` |
|
||||
| `doc` | 45 | `dingtalk-doc` |
|
||||
| `drive` | 28 | `dingtalk-drive` |
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
| 清空 / 排序 / 填充 / 复制移动区域 | `range clear` / `range sort` / `range fill` / `range copy-to` / `range move-to` | [sheet-range-operations](sheet/sheet-range-operations.md) | 用读写组合模拟服务端原子操作 |
|
||||
| 合并、冻结、分组、行高列宽 | `sheet info` + 结构命令 | [sheet-workbook](sheet/sheet-workbook.md)、[sheet-dimension-operations](sheet/sheet-dimension-operations.md) | 从 `range read` / CSV 空值推断结构 |
|
||||
| 多个原子写操作组合 | `batch-update` | [sheet-batch-operations](sheet/sheet-batch-operations.md) | 多次独立调用导致半成品 |
|
||||
| 图片写入单元格 / 浮动图片 | `write-image` / `create-float-image --file` | [sheet-media-image](sheet/sheet-media-image.md) | 用 `range update` 写图片 |
|
||||
| 图片写入单元格 / 浮动图片 | `write-image` / `media-upload` + `create-float-image` | [sheet-media-image](sheet/sheet-media-image.md) | 用 `range update` 写图片 |
|
||||
| 条件高亮 / 标红 / 数据条 / 色阶 | `cond-format` | [sheet-conditional-format](sheet/sheet-conditional-format.md) | 用静态 `set-style` 冒充条件格式 |
|
||||
| 单元格评论 / 批注 / @人讨论 | `comment list/create/reply/update/delete` | [sheet-comment](sheet/sheet-comment.md) | 把评论内容写进单元格值 |
|
||||
| 查询当前 revision / 复核两个 revision 间的编辑 | `revision-get` / `changeset-get` | [sheet-revision-changeset](sheet/sheet-revision-changeset.md) | 把 revision 当历史快照 version,或把前向 change 当成当前最终值 |
|
||||
@@ -80,7 +80,7 @@
|
||||
| [sheet-dimension-operations](sheet/sheet-dimension-operations.md) | 行列增删移动、属性设置与分组。当用户说"插入行/列"、"删除行/列"、"隐藏/显示行列"、"设行高/列宽"、"移动行/列"、"追加空行/空列"、"创建/取消行列分组"、"新建分组并设为折叠/展开"时使用。命令:`insert-dimension`/`delete-dimension`/`update-dimension`/`move-dimension`/`add-dimension`/`group-dimension`/`ungroup-dimension` |
|
||||
| [sheet-style-format](sheet/sheet-style-format.md) | 单元格样式与合并。当用户说"设样式"、"改颜色/字体/对齐"、"数字格式(百分比/货币/日期)"、"合并/取消合并"时使用。纯样式/批量样式走 `set-style`;写值同时设置少量 cell 样式可用 `range update` 的 `cellStyles`。命令:`range set-style`/`range batch-set-style`/`merge-cells`/`unmerge-cells` |
|
||||
| [sheet-dropdown](sheet/sheet-dropdown.md) | 下拉列表管理。当用户说"设置下拉"、"下拉选项"、"删除下拉"时使用。命令:`set-dropdown`/`get-dropdown`/`delete-dropdown` |
|
||||
| [sheet-media-image](sheet/sheet-media-image.md) | 附件上传与图片。当用户说"上传附件"、"写入图片到单元格"、"浮动图片"时使用。单元格图片用 `write-image`(禁止 `range update`);浮动图片优先用 `create-float-image --file`,已有 resourceUrl 时用 `--src`。命令:`media-upload`/`write-image`/`create-float-image`/`get-float-image`/`list-float-images`/`update-float-image`/`delete-float-image` |
|
||||
| [sheet-media-image](sheet/sheet-media-image.md) | 附件上传与图片。当用户说"上传附件"、"写入图片到单元格"、"浮动图片"时使用。单元格图片用 `write-image`(禁止 `range update`);浮动图片需先 `media-upload` 再 `create-float-image`。命令:`media-upload`/`write-image`/`create-float-image`/`get-float-image`/`list-float-images`/`update-float-image`/`delete-float-image` |
|
||||
| [sheet-filter](sheet/sheet-filter.md) | 全局筛选。当用户说"筛选"、"过滤"、"只看某些行"(未说"筛选视图")时使用。禁止用"删除不符合条件的行"代替筛选。命令:`filter get`/`create`/`delete`/`update`/`clear-criteria`/`sort` |
|
||||
| [sheet-filter-view](sheet/sheet-filter-view.md) | 筛选视图(个人化,不影响协作者)。当用户明确说"筛选视图"时使用,与全局筛选相互独立。命令:`filter-view list`/`create`/`update`/`delete`/`info`/`update-criteria`/`delete-criteria`/`list-criteria`/`get-criteria` |
|
||||
| [sheet-conditional-format](sheet/sheet-conditional-format.md) | 条件格式规则。触发词:标红/标黄/高亮/突出/标记/数据条/色阶/颜色随数据变 → **强制**走条件格式,禁止 `range set-style` 静态样式替代。命令:`cond-format list`/`create`/`update`/`delete` |
|
||||
@@ -237,7 +237,7 @@ Flags:
|
||||
| "搜索公式文本" | `dws sheet find --node <nodeId或URL> --sheet-id <sheetId> --query "<公式片段>" --match-formula` |
|
||||
| "正则搜索 / 不区分大小写" | `dws sheet find --node <nodeId或URL> --sheet-id <sheetId> --query "<regexp>" --use-regexp --match-case=false` |
|
||||
| "插入图片到单元格" | `dws sheet write-image --node <nodeId或URL> --sheet-id <sheetId> --range A1 --file <图片路径>` |
|
||||
| "创建浮动图片" | `dws sheet create-float-image --node <nodeId或URL> --sheet-id <sheetId> --file <图片路径> --range A1 --width <宽> --height <高>` |
|
||||
| "创建浮动图片" | 先 `dws sheet media-upload --node <nodeId或URL> --file <图片路径>` 获取 `resourceUrl`,再 `dws sheet create-float-image --node <nodeId或URL> --sheet-id <sheetId> --src "<resourceUrl>" --range A1 --width <宽> --height <高>` |
|
||||
|
||||
## URL 与 ID 前置
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
### 浮动图片
|
||||
|
||||
用户说"浮动图片/悬浮图片/在表格上放一张图/加个浮动的图":
|
||||
- 创建浮动图片 → `create-float-image --file <本地图片>`;已有 `resourceUrl` 时可改用 `--src`
|
||||
- 创建浮动图片 → 先 `media-upload` 上传图片获取 `resourceUrl`,再 `create-float-image`
|
||||
- 浮动图片悬浮于单元格之上,不占用单元格内容,与 `write-image`(写入单元格内部的图片)不同
|
||||
|
||||
用户说"查看浮动图片/有哪些浮动图片/浮动图片列表":
|
||||
@@ -71,11 +71,7 @@ Flags:
|
||||
Usage:
|
||||
dws sheet create-float-image [flags]
|
||||
Example:
|
||||
# 直接上传本地图片并创建浮动图片
|
||||
dws sheet create-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--file ./chart.png --range A1 --width 400 --height 300
|
||||
|
||||
# 高级用法:先上传图片获取 resourceUrl
|
||||
# 先上传图片获取 resourceUrl
|
||||
dws sheet media-upload --node <NODE_ID> --file ./chart.png
|
||||
# 输出: resourceUrl: /core/api/resources/img/xxxx...
|
||||
|
||||
@@ -89,8 +85,7 @@ Example:
|
||||
Flags:
|
||||
--node string 表格文档 ID 或 URL (必填)
|
||||
--sheet-id string 工作表 ID 或名称 (必填)
|
||||
--file string 本地图片文件路径,与 --src 二选一
|
||||
--src string 图片资源路径,通过 media-upload 获取的 resourceUrl,与 --file 二选一
|
||||
--src string 图片资源路径,通过 media-upload 获取的 resourceUrl (必填)
|
||||
--range string 锚点单元格,A1 表示法,如 A1、B3 (必填)
|
||||
--width int 图片宽度,像素,正整数 (必填)
|
||||
--height int 图片高度,像素,正整数 (必填)
|
||||
@@ -99,8 +94,7 @@ Flags:
|
||||
```
|
||||
|
||||
浮动图片悬浮于单元格之上,不占用单元格内容,可自由定位和调整大小。
|
||||
- `--file` 与 `--src` 必须且只能提供一个;`--file` 会在命令内完成凭证获取、文件上传和浮动图片创建
|
||||
- `--src` 必须是 `media-upload` 返回的 `resourceUrl`(格式为 `/core/api/resources/img/...`),不能直接传外部 URL;需要自定义上传名称/MIME 时使用这个高级两步流程
|
||||
- `--src` 必须是 `media-upload` 返回的 `resourceUrl`(格式为 `/core/api/resources/img/...`),不能直接传外部 URL
|
||||
- `--range` 使用 A1 表示法指定锚点单元格(如 `A1`、`B3`),支持带工作表前缀(如 `Sheet1!A1`)
|
||||
- `--width` / `--height` 为必填,单位像素,必须为正整数
|
||||
- `--offset-x` / `--offset-y` 表示相对锚点单元格左上角的偏移量(像素),默认 0,不能为负数
|
||||
@@ -144,18 +138,13 @@ Example:
|
||||
# 调整尺寸
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> --width 600 --height 400
|
||||
|
||||
# 直接用本地图片替换
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> \
|
||||
--file ./replacement.png
|
||||
|
||||
# 高级用法:通过已上传的 resourceUrl 替换
|
||||
# 替换图片(需先 media-upload 新图片获取 resourceUrl)
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> \
|
||||
--src "/core/api/resources/img/xxxx..."
|
||||
Flags:
|
||||
--node string 表格文档 ID 或 URL (必填)
|
||||
--sheet-id string 工作表 ID 或名称 (必填)
|
||||
--float-image-id string 浮动图片 ID (必填)
|
||||
--file string 用于替换浮动图片的本地图片路径,与 --src 不能同时使用
|
||||
--src string 新的图片资源路径,通过 media-upload 获取的 resourceUrl
|
||||
--range string 新的锚点单元格,A1 表示法
|
||||
--width int 新的图片宽度,像素
|
||||
@@ -164,7 +153,7 @@ Flags:
|
||||
--offset-y int 新的垂直偏移量,像素
|
||||
```
|
||||
|
||||
更新浮动图片的属性,`--file` / `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少传入一个;`--file` 与 `--src` 不能同时使用。
|
||||
更新浮动图片的属性,`--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少传入一个。
|
||||
`--float-image-id` 可通过 `list-float-images` 获取。
|
||||
|
||||
### 删除浮动图片
|
||||
@@ -221,16 +210,6 @@ dws sheet range update --node <NODE_ID> --sheet-id <SHEET_ID> --range "A1:B1" \
|
||||
dws sheet range update --node <NODE_ID> --sheet-id <SHEET_ID> --range "A2:A2" \
|
||||
--values '[[{"type":"text","text":"MacBook Pro"}]]' -f json
|
||||
dws sheet write-image --node <NODE_ID> --sheet-id <SHEET_ID> --range B2:B2 --file ./macbook.png --width 150 --height 100 -f json
|
||||
|
||||
# ── 工作流 11: 创建或替换浮动图片 ──
|
||||
|
||||
# 从本地图片直接创建
|
||||
dws sheet create-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--file ./chart.png --range A1 --width 400 --height 300 -f json
|
||||
|
||||
# 从本地图片直接替换已有浮动图
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--float-image-id <FI_ID> --file ./replacement.png -f json
|
||||
```
|
||||
|
||||
## 上下文传递
|
||||
@@ -253,11 +232,11 @@ dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
- `write-image` 会自动完成图片上传并写入目标单元格,无需手动拆分步骤
|
||||
- ★ 向表格单元格中写入图片必须使用 `write-image`,禁止使用 `range update`。`range update` 不支持图片对象
|
||||
- `write-image` 与 `media-upload` 的区别:`media-upload` 仅上传附件到表格获取 resourceId;`write-image` 在上传后还会将图片写入指定单元格
|
||||
- `create-float-image --file` 可直接输入本地图片;仅在需要 `--name` / `--mime-type` 覆盖或复用既有资源时,先用 `media-upload` 获取 `resourceUrl` 再传 `--src`
|
||||
- `create-float-image` 创建浮动图片前必须先通过 `media-upload` 上传图片获取 `resourceUrl`,再将其作为 `--src` 传入。`--src` 的格式为 `/core/api/resources/img/...`,不能直接传外部 URL
|
||||
- `create-float-image` 的 `--range` 使用 A1 表示法指定锚点单元格(如 `A1`、`B3`),支持带工作表前缀(如 `Sheet1!A1`)
|
||||
- `create-float-image` 的 `--width` / `--height` 为必填,单位像素,必须为正整数;`--offset-x` / `--offset-y` 可选,默认 0,不能为负数
|
||||
- `write-image`(单元格内嵌图片)vs `create-float-image`(浮动图片):`write-image` 将图片写入单元格内部,占据单元格内容;`create-float-image` 创建悬浮于单元格之上的浮动图片,不占用单元格内容,可自由调整位置和大小
|
||||
- ★ **浮动图片用 `create-float-image` 不用 `write-image`**:两者用途不同——`write-image` 写入单元格内部,`create-float-image` 创建悬浮于单元格之上的浮动图片;优先直接传 `--file`
|
||||
- `update-float-image` 的 `--file` / `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少必须提供一个,且 `--file` 与 `--src` 不能同时使用
|
||||
- ★ **浮动图片用 `create-float-image` 不用 `write-image`**:两者用途不同——`write-image` 写入单元格内部,`create-float-image` 创建悬浮于单元格之上的浮动图片;`--src` 必须来自 `media-upload` 的 `resourceUrl`
|
||||
- `update-float-image` 的 `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少必须提供一个
|
||||
- `list-float-images` 返回 `floatImages` 数组和 `totalCount`,每个元素包含 `id`(用于后续 get / update / delete)
|
||||
- `delete-float-image` 操作不可恢复,删除后图片将从工作表中移除
|
||||
|
||||
@@ -25,25 +25,19 @@
|
||||
| Shortcut | 风险 | 适用场景 |
|
||||
|---|---|---|
|
||||
| `dws devapp +create` | write | 创建开放平台企业内部应用 |
|
||||
| `dws devapp +credentials-get` | read | 读取开放平台应用凭证 |
|
||||
| `dws devapp +delete` | high-risk-write | 删除开放平台企业内部应用(不可逆) |
|
||||
| `dws devapp +disable` | high-risk-write | 停用开放平台企业内部应用 |
|
||||
| `dws devapp +enable` | write | 启用开放平台企业内部应用 |
|
||||
| `dws devapp +event-list` | read | 查询应用可用事件目录与订阅状态 |
|
||||
| `dws devapp +event-subscribe` | write | 订阅应用事件回调 |
|
||||
| `dws devapp +event-list` | read | 查询应用已订阅的事件列表 |
|
||||
| `dws devapp +get` | read | 查询开放平台企业内部应用详情 |
|
||||
| `dws devapp +list` | read | 查询开放平台企业内部应用列表 |
|
||||
| `dws devapp +member-add` | write | 添加开放平台应用成员 |
|
||||
| `dws devapp +member-list` | read | 查询开放平台应用成员 |
|
||||
| `dws devapp +member-remove` | high-risk-write | 移除开放平台应用成员 |
|
||||
| `dws devapp +permission-list` | read | 查询开放平台应用权限列表 |
|
||||
| `dws devapp +robot-config` | write | 创建或更新现有应用的机器人配置(upsert) |
|
||||
| `dws devapp +robot-disable` | high-risk-write | 停用现有应用的机器人能力 |
|
||||
| `dws devapp +robot-enable` | write | 启用现有应用机器人能力(纯启用,无需配置字段) |
|
||||
| `dws devapp +robot-get` | read | 查询现有应用的机器人配置 |
|
||||
| `dws devapp +update` | write | 修改开放平台企业内部应用基础信息 |
|
||||
| `dws devapp +version-check-approval` | read | 预检版本发布是否需要审批(不实际发布) |
|
||||
| `dws devapp +version-create` | write | 基于当前配置创建应用新版本 |
|
||||
| `dws devapp +version-get` | read | 查询指定版本详情 |
|
||||
| `dws devapp +version-list` | read | 分页查询应用版本列表 |
|
||||
| `dws devapp +version-status` | read | 查询版本发布/审批状态 |
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
| 清空 / 排序 / 填充 / 复制移动区域 | `range clear` / `range sort` / `range fill` / `range copy-to` / `range move-to` | [sheet-range-operations](sheet/sheet-range-operations.md) | 用读写组合模拟服务端原子操作 |
|
||||
| 合并、冻结、分组、行高列宽 | `sheet info` + 结构命令 | [sheet-workbook](sheet/sheet-workbook.md)、[sheet-dimension-operations](sheet/sheet-dimension-operations.md) | 从 `range read` / CSV 空值推断结构 |
|
||||
| 多个原子写操作组合 | `batch-update` | [sheet-batch-operations](sheet/sheet-batch-operations.md) | 多次独立调用导致半成品 |
|
||||
| 图片写入单元格 / 浮动图片 | `write-image` / `create-float-image --file` | [sheet-media-image](sheet/sheet-media-image.md) | 用 `range update` 写图片 |
|
||||
| 图片写入单元格 / 浮动图片 | `write-image` / `media-upload` + `create-float-image` | [sheet-media-image](sheet/sheet-media-image.md) | 用 `range update` 写图片 |
|
||||
| 条件高亮 / 标红 / 数据条 / 色阶 | `cond-format` | [sheet-conditional-format](sheet/sheet-conditional-format.md) | 用静态 `set-style` 冒充条件格式 |
|
||||
| 单元格评论 / 批注 / @人讨论 | `comment list/create/reply/update/delete` | [sheet-comment](sheet/sheet-comment.md) | 把评论内容写进单元格值 |
|
||||
| 查询当前 revision / 复核两个 revision 间的编辑 | `revision-get` / `changeset-get` | [sheet-revision-changeset](sheet/sheet-revision-changeset.md) | 把 revision 当历史快照 version,或把前向 change 当成当前最终值 |
|
||||
@@ -80,7 +80,7 @@
|
||||
| [sheet-dimension-operations](sheet/sheet-dimension-operations.md) | 行列增删移动、属性设置与分组。当用户说"插入行/列"、"删除行/列"、"隐藏/显示行列"、"设行高/列宽"、"移动行/列"、"追加空行/空列"、"创建/取消行列分组"、"新建分组并设为折叠/展开"时使用。命令:`insert-dimension`/`delete-dimension`/`update-dimension`/`move-dimension`/`add-dimension`/`group-dimension`/`ungroup-dimension` |
|
||||
| [sheet-style-format](sheet/sheet-style-format.md) | 单元格样式与合并。当用户说"设样式"、"改颜色/字体/对齐"、"数字格式(百分比/货币/日期)"、"合并/取消合并"时使用。纯样式/批量样式走 `set-style`;写值同时设置少量 cell 样式可用 `range update` 的 `cellStyles`。命令:`range set-style`/`range batch-set-style`/`merge-cells`/`unmerge-cells` |
|
||||
| [sheet-dropdown](sheet/sheet-dropdown.md) | 下拉列表管理。当用户说"设置下拉"、"下拉选项"、"删除下拉"时使用。命令:`set-dropdown`/`get-dropdown`/`delete-dropdown` |
|
||||
| [sheet-media-image](sheet/sheet-media-image.md) | 附件上传与图片。当用户说"上传附件"、"写入图片到单元格"、"浮动图片"时使用。单元格图片用 `write-image`(禁止 `range update`);浮动图片优先用 `create-float-image --file`,已有 resourceUrl 时用 `--src`。命令:`media-upload`/`write-image`/`create-float-image`/`get-float-image`/`list-float-images`/`update-float-image`/`delete-float-image` |
|
||||
| [sheet-media-image](sheet/sheet-media-image.md) | 附件上传与图片。当用户说"上传附件"、"写入图片到单元格"、"浮动图片"时使用。单元格图片用 `write-image`(禁止 `range update`);浮动图片需先 `media-upload` 再 `create-float-image`。命令:`media-upload`/`write-image`/`create-float-image`/`get-float-image`/`list-float-images`/`update-float-image`/`delete-float-image` |
|
||||
| [sheet-filter](sheet/sheet-filter.md) | 全局筛选。当用户说"筛选"、"过滤"、"只看某些行"(未说"筛选视图")时使用。禁止用"删除不符合条件的行"代替筛选。命令:`filter get`/`create`/`delete`/`update`/`clear-criteria`/`sort` |
|
||||
| [sheet-filter-view](sheet/sheet-filter-view.md) | 筛选视图(个人化,不影响协作者)。当用户明确说"筛选视图"时使用,与全局筛选相互独立。命令:`filter-view list`/`create`/`update`/`delete`/`info`/`update-criteria`/`delete-criteria`/`list-criteria`/`get-criteria` |
|
||||
| [sheet-conditional-format](sheet/sheet-conditional-format.md) | 条件格式规则。触发词:标红/标黄/高亮/突出/标记/数据条/色阶/颜色随数据变 → **强制**走条件格式,禁止 `range set-style` 静态样式替代。命令:`cond-format list`/`create`/`update`/`delete` |
|
||||
@@ -237,7 +237,7 @@ Flags:
|
||||
| "搜索公式文本" | `dws sheet find --node <nodeId或URL> --sheet-id <sheetId> --query "<公式片段>" --match-formula` |
|
||||
| "正则搜索 / 不区分大小写" | `dws sheet find --node <nodeId或URL> --sheet-id <sheetId> --query "<regexp>" --use-regexp --match-case=false` |
|
||||
| "插入图片到单元格" | `dws sheet write-image --node <nodeId或URL> --sheet-id <sheetId> --range A1 --file <图片路径>` |
|
||||
| "创建浮动图片" | `dws sheet create-float-image --node <nodeId或URL> --sheet-id <sheetId> --file <图片路径> --range A1 --width <宽> --height <高>` |
|
||||
| "创建浮动图片" | 先 `dws sheet media-upload --node <nodeId或URL> --file <图片路径>` 获取 `resourceUrl`,再 `dws sheet create-float-image --node <nodeId或URL> --sheet-id <sheetId> --src "<resourceUrl>" --range A1 --width <宽> --height <高>` |
|
||||
|
||||
## URL 与 ID 前置
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
### 浮动图片
|
||||
|
||||
用户说"浮动图片/悬浮图片/在表格上放一张图/加个浮动的图":
|
||||
- 创建浮动图片 → `create-float-image --file <本地图片>`;已有 `resourceUrl` 时可改用 `--src`
|
||||
- 创建浮动图片 → 先 `media-upload` 上传图片获取 `resourceUrl`,再 `create-float-image`
|
||||
- 浮动图片悬浮于单元格之上,不占用单元格内容,与 `write-image`(写入单元格内部的图片)不同
|
||||
|
||||
用户说"查看浮动图片/有哪些浮动图片/浮动图片列表":
|
||||
@@ -71,11 +71,7 @@ Flags:
|
||||
Usage:
|
||||
dws sheet create-float-image [flags]
|
||||
Example:
|
||||
# 直接上传本地图片并创建浮动图片
|
||||
dws sheet create-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--file ./chart.png --range A1 --width 400 --height 300
|
||||
|
||||
# 高级用法:先上传图片获取 resourceUrl
|
||||
# 先上传图片获取 resourceUrl
|
||||
dws sheet media-upload --node <NODE_ID> --file ./chart.png
|
||||
# 输出: resourceUrl: /core/api/resources/img/xxxx...
|
||||
|
||||
@@ -89,8 +85,7 @@ Example:
|
||||
Flags:
|
||||
--node string 表格文档 ID 或 URL (必填)
|
||||
--sheet-id string 工作表 ID 或名称 (必填)
|
||||
--file string 本地图片文件路径,与 --src 二选一
|
||||
--src string 图片资源路径,通过 media-upload 获取的 resourceUrl,与 --file 二选一
|
||||
--src string 图片资源路径,通过 media-upload 获取的 resourceUrl (必填)
|
||||
--range string 锚点单元格,A1 表示法,如 A1、B3 (必填)
|
||||
--width int 图片宽度,像素,正整数 (必填)
|
||||
--height int 图片高度,像素,正整数 (必填)
|
||||
@@ -99,8 +94,7 @@ Flags:
|
||||
```
|
||||
|
||||
浮动图片悬浮于单元格之上,不占用单元格内容,可自由定位和调整大小。
|
||||
- `--file` 与 `--src` 必须且只能提供一个;`--file` 会在命令内完成凭证获取、文件上传和浮动图片创建
|
||||
- `--src` 必须是 `media-upload` 返回的 `resourceUrl`(格式为 `/core/api/resources/img/...`),不能直接传外部 URL;需要自定义上传名称/MIME 时使用这个高级两步流程
|
||||
- `--src` 必须是 `media-upload` 返回的 `resourceUrl`(格式为 `/core/api/resources/img/...`),不能直接传外部 URL
|
||||
- `--range` 使用 A1 表示法指定锚点单元格(如 `A1`、`B3`),支持带工作表前缀(如 `Sheet1!A1`)
|
||||
- `--width` / `--height` 为必填,单位像素,必须为正整数
|
||||
- `--offset-x` / `--offset-y` 表示相对锚点单元格左上角的偏移量(像素),默认 0,不能为负数
|
||||
@@ -144,18 +138,13 @@ Example:
|
||||
# 调整尺寸
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> --width 600 --height 400
|
||||
|
||||
# 直接用本地图片替换
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> \
|
||||
--file ./replacement.png
|
||||
|
||||
# 高级用法:通过已上传的 resourceUrl 替换
|
||||
# 替换图片(需先 media-upload 新图片获取 resourceUrl)
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> --float-image-id <FI_ID> \
|
||||
--src "/core/api/resources/img/xxxx..."
|
||||
Flags:
|
||||
--node string 表格文档 ID 或 URL (必填)
|
||||
--sheet-id string 工作表 ID 或名称 (必填)
|
||||
--float-image-id string 浮动图片 ID (必填)
|
||||
--file string 用于替换浮动图片的本地图片路径,与 --src 不能同时使用
|
||||
--src string 新的图片资源路径,通过 media-upload 获取的 resourceUrl
|
||||
--range string 新的锚点单元格,A1 表示法
|
||||
--width int 新的图片宽度,像素
|
||||
@@ -164,7 +153,7 @@ Flags:
|
||||
--offset-y int 新的垂直偏移量,像素
|
||||
```
|
||||
|
||||
更新浮动图片的属性,`--file` / `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少传入一个;`--file` 与 `--src` 不能同时使用。
|
||||
更新浮动图片的属性,`--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少传入一个。
|
||||
`--float-image-id` 可通过 `list-float-images` 获取。
|
||||
|
||||
### 删除浮动图片
|
||||
@@ -221,16 +210,6 @@ dws sheet range update --node <NODE_ID> --sheet-id <SHEET_ID> --range "A1:B1" \
|
||||
dws sheet range update --node <NODE_ID> --sheet-id <SHEET_ID> --range "A2:A2" \
|
||||
--values '[[{"type":"text","text":"MacBook Pro"}]]' -f json
|
||||
dws sheet write-image --node <NODE_ID> --sheet-id <SHEET_ID> --range B2:B2 --file ./macbook.png --width 150 --height 100 -f json
|
||||
|
||||
# ── 工作流 11: 创建或替换浮动图片 ──
|
||||
|
||||
# 从本地图片直接创建
|
||||
dws sheet create-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--file ./chart.png --range A1 --width 400 --height 300 -f json
|
||||
|
||||
# 从本地图片直接替换已有浮动图
|
||||
dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
--float-image-id <FI_ID> --file ./replacement.png -f json
|
||||
```
|
||||
|
||||
## 上下文传递
|
||||
@@ -253,11 +232,11 @@ dws sheet update-float-image --node <NODE_ID> --sheet-id <SHEET_ID> \
|
||||
- `write-image` 会自动完成图片上传并写入目标单元格,无需手动拆分步骤
|
||||
- ★ 向表格单元格中写入图片必须使用 `write-image`,禁止使用 `range update`。`range update` 不支持图片对象
|
||||
- `write-image` 与 `media-upload` 的区别:`media-upload` 仅上传附件到表格获取 resourceId;`write-image` 在上传后还会将图片写入指定单元格
|
||||
- `create-float-image --file` 可直接输入本地图片;仅在需要 `--name` / `--mime-type` 覆盖或复用既有资源时,先用 `media-upload` 获取 `resourceUrl` 再传 `--src`
|
||||
- `create-float-image` 创建浮动图片前必须先通过 `media-upload` 上传图片获取 `resourceUrl`,再将其作为 `--src` 传入。`--src` 的格式为 `/core/api/resources/img/...`,不能直接传外部 URL
|
||||
- `create-float-image` 的 `--range` 使用 A1 表示法指定锚点单元格(如 `A1`、`B3`),支持带工作表前缀(如 `Sheet1!A1`)
|
||||
- `create-float-image` 的 `--width` / `--height` 为必填,单位像素,必须为正整数;`--offset-x` / `--offset-y` 可选,默认 0,不能为负数
|
||||
- `write-image`(单元格内嵌图片)vs `create-float-image`(浮动图片):`write-image` 将图片写入单元格内部,占据单元格内容;`create-float-image` 创建悬浮于单元格之上的浮动图片,不占用单元格内容,可自由调整位置和大小
|
||||
- ★ **浮动图片用 `create-float-image` 不用 `write-image`**:两者用途不同——`write-image` 写入单元格内部,`create-float-image` 创建悬浮于单元格之上的浮动图片;优先直接传 `--file`
|
||||
- `update-float-image` 的 `--file` / `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少必须提供一个,且 `--file` 与 `--src` 不能同时使用
|
||||
- ★ **浮动图片用 `create-float-image` 不用 `write-image`**:两者用途不同——`write-image` 写入单元格内部,`create-float-image` 创建悬浮于单元格之上的浮动图片;`--src` 必须来自 `media-upload` 的 `resourceUrl`
|
||||
- `update-float-image` 的 `--src` / `--range` / `--width` / `--height` / `--offset-x` / `--offset-y` 至少必须提供一个
|
||||
- `list-float-images` 返回 `floatImages` 数组和 `totalCount`,每个元素包含 `id`(用于后续 get / update / delete)
|
||||
- `delete-float-image` 操作不可恢复,删除后图片将从工作表中移除
|
||||
|
||||
@@ -351,79 +351,6 @@ This release promotes the sealed `+"`v1.0.1-beta.1`"+` contents to stable.
|
||||
}
|
||||
}
|
||||
|
||||
func TestReleaseFragmentPolicyAcceptsOnlyUntaggedCanonicalBetaAmendments(t *testing.T) {
|
||||
newAmendmentRepo := func(t *testing.T) (*changelogGateRepo, string) {
|
||||
t.Helper()
|
||||
repo := newChangelogGateRepo(t)
|
||||
sealBase := repo.sealFragmentInto(t, "1.0.1-beta.1")
|
||||
if output, err := repo.runFragmentPolicy(t, sealBase, "HEAD"); err != nil {
|
||||
t.Fatalf("release fragment policy rejected initial beta seal: %v\noutput:\n%s", err, output)
|
||||
}
|
||||
changelogGateWrite(t, repo.root, ".changes/1235-sheet.md", "---\ncategory: Added\n---\n\n- Sheet accepts local float image files.\n", 0o644)
|
||||
repo.commit(t, "merge post-seal beta fragment")
|
||||
return repo, strings.TrimSpace(changelogGateGit(t, repo.root, "rev-parse", "HEAD"))
|
||||
}
|
||||
|
||||
stageCanonicalAmendment := func(t *testing.T, repo *changelogGateRepo) {
|
||||
t.Helper()
|
||||
changelogGateWrite(t, repo.root, "CHANGELOG.md", `# Changelog
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.1-beta.1] - 2026-07-17
|
||||
|
||||
### Added
|
||||
|
||||
- Chat reply mentions.
|
||||
|
||||
- Sheet accepts local float image files.
|
||||
|
||||
## [1.0.0] - 2026-07-01
|
||||
|
||||
### Added
|
||||
|
||||
- Initial release.
|
||||
`, 0o644)
|
||||
archiveDir := filepath.Join(repo.root, ".changes", "released", "1.0.1-beta.1")
|
||||
if err := os.Rename(filepath.Join(repo.root, ".changes", "1235-sheet.md"), filepath.Join(archiveDir, "1235-sheet.md")); err != nil {
|
||||
t.Fatalf("Rename beta amendment fragment: %v", err)
|
||||
}
|
||||
repo.commit(t, "amend untagged beta release notes")
|
||||
}
|
||||
|
||||
t.Run("accepts exact pre-tag merge", func(t *testing.T) {
|
||||
repo, amendmentBase := newAmendmentRepo(t)
|
||||
stageCanonicalAmendment(t, repo)
|
||||
|
||||
if output, err := repo.runFragmentPolicy(t, amendmentBase, "HEAD"); err != nil {
|
||||
t.Fatalf("release fragment policy rejected canonical beta amendment: %v\noutput:\n%s", err, output)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects tagged beta", func(t *testing.T) {
|
||||
repo, amendmentBase := newAmendmentRepo(t)
|
||||
stageCanonicalAmendment(t, repo)
|
||||
changelogGateGit(t, repo.root, "tag", "v1.0.1-beta.1")
|
||||
|
||||
output, err := repo.runFragmentPolicy(t, amendmentBase, "HEAD")
|
||||
if err == nil || !strings.Contains(output, "forbidden after tag v1.0.1-beta.1 exists") {
|
||||
t.Fatalf("tagged beta amendment passed: err=%v\noutput:\n%s", err, output)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("rejects rewritten sealed prose", func(t *testing.T) {
|
||||
repo, amendmentBase := newAmendmentRepo(t)
|
||||
stageCanonicalAmendment(t, repo)
|
||||
changelogGateWrite(t, repo.root, "CHANGELOG.md", strings.Replace(changelogGateSealedRelease, "Chat reply mentions.", "Rewritten sealed note.", 1), 0o644)
|
||||
repo.commit(t, "rewrite sealed beta prose")
|
||||
|
||||
output, err := repo.runFragmentPolicy(t, amendmentBase, "HEAD")
|
||||
if err == nil || !strings.Contains(output, "does not exactly match") {
|
||||
t.Fatalf("rewritten beta amendment passed: err=%v\noutput:\n%s", err, output)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestReleaseFragmentPolicyRejectsInvalidActiveFragmentAndWrongArchiveVersion(t *testing.T) {
|
||||
t.Run("invalid active fragment", func(t *testing.T) {
|
||||
repo := newChangelogGateRepo(t)
|
||||
|
||||
Reference in New Issue
Block a user