Files
dingtalk-workspace-cli/pkg/editiontest/contract.go
T
wxianfeng 93d6fdb17e feat: edition layer for Wukong overlay; promote shared code to pkg/
Introduce a build-time edition hook so downstream overlays (e.g. Wukong)
can customize auth UX, config dir, static server list, visible products,
and extra root commands while keeping the default open-source behavior.

- Add pkg/edition (defaults) and pkg/editiontest contract tests; Makefile
  target edition-test; CI job edition-tests.
- Root: optional RegisterExtraCommands with tool caller adapter; inject
  static servers to skip market discovery when configured; deduplicate
  top-level commands so overlay wins; extend hideNonDirectRuntimeCommands
  with edition VisibleProducts and static commands (recovery/schema/mcp).
- Auth/config: gate login subcommand and auth login hints for embedded
  editions; optional token auto-purge; edition ConfigDir override.
- version: human-readable multi-line output plus JSON with edition,
  architecture, build, commit.
- Relocate internal/{config,convert,validate} to pkg/; add pkg/cli and
  pkg/cmdutil (flags/time helpers).
- CI: optional notify-downstream job (GitLab trigger via secrets) on main
  push; open_source_policy_test adjusted for new layout.

Secrets (repo settings): WUKONG_TRIGGER_TOKEN, WUKONG_TRIGGER_URL — optional;
if unset, downstream step is skipped.

Made-with: Cursor
2026-03-31 15:29:21 +08:00

89 lines
2.5 KiB
Go

// Copyright 2026 Alibaba Group
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package editiontest provides contract-test helpers that any edition.Hooks
// implementation (open-source or overlay) must satisfy. It lives in a
// non-_test package so external modules can import and run these checks.
package editiontest
import (
"testing"
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
)
// RunContractTests validates that the supplied Hooks implementation
// satisfies the behavioural contract required by the open-source core.
// Call this from both the open-source test suite and any overlay's tests.
func RunContractTests(t *testing.T, h *edition.Hooks) {
t.Helper()
if h == nil {
t.Fatal("Hooks must not be nil")
}
t.Run("Name", func(t *testing.T) {
if h.Name == "" {
t.Error("Hooks.Name must be non-empty")
}
})
t.Run("ConfigDir", func(t *testing.T) {
if h.ConfigDir != nil {
dir := h.ConfigDir()
if dir == "" {
t.Error("ConfigDir() must return a non-empty path when set")
}
}
})
t.Run("MergeHeaders_preserves_base", func(t *testing.T) {
if h.MergeHeaders == nil {
return
}
base := map[string]string{"x-test": "value"}
merged := h.MergeHeaders(base)
if merged == nil {
t.Fatal("MergeHeaders must return a non-nil map")
}
if merged["x-test"] != "value" {
t.Error("MergeHeaders must preserve base headers")
}
})
t.Run("StaticServers_non_empty_when_set", func(t *testing.T) {
if h.StaticServers == nil {
return
}
servers := h.StaticServers()
if len(servers) == 0 {
t.Error("StaticServers() must return at least one server when set")
}
for i, s := range servers {
if s.ID == "" || s.Endpoint == "" {
t.Errorf("StaticServers()[%d]: ID and Endpoint must be non-empty", i)
}
}
})
t.Run("VisibleProducts_non_empty_when_set", func(t *testing.T) {
if h.VisibleProducts == nil {
return
}
products := h.VisibleProducts()
if len(products) == 0 {
t.Error("VisibleProducts() must return at least one product when set")
}
})
}