mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 02:00:19 +08:00
Scaffold the lark-cli sec subsystem: the `sec` command tree (install, run, stop, status, config init) and the internal/sec package that drives it. The bootstrap manifest is embedded at build time as JSON, mapping (platform, arch, region) to download URLs. The installer resolves the right artifact for the current host, downloads with optional SHA256 verification, extracts into versions/<version>/, swaps the `current` symlink atomically (copy on Windows), and writes state.json. `sec run` enables the binary as a user-level system service (launchd / systemd-user / registry+VBS) so the OS supervises restarts. After this first install, lark-sec-cli takes over its own upgrade lifecycle.
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package sec
|
|
|
|
import (
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestLoadBootstrap_DecodesAllPlatforms guards against the embedded
|
|
// manifest becoming malformed or losing an OS — both would break first
|
|
// install on whatever GOOS lost its entry.
|
|
func TestLoadBootstrap_DecodesAllPlatforms(t *testing.T) {
|
|
manifest, err := LoadBootstrap()
|
|
if err != nil {
|
|
t.Fatalf("LoadBootstrap: %v", err)
|
|
}
|
|
platforms := map[string]bool{}
|
|
for _, e := range manifest.Entries {
|
|
platforms[e.BuildPlatform] = true
|
|
if e.Version == "" {
|
|
t.Errorf("entry %s missing version", e.BuildPlatform)
|
|
}
|
|
if e.Extra.PipelineID == "" {
|
|
t.Errorf("entry %s missing extra.pipeline_id", e.BuildPlatform)
|
|
}
|
|
}
|
|
for _, want := range []string{"darwin", "linux", "win32"} {
|
|
if !platforms[want] {
|
|
t.Errorf("bootstrap missing platform %q", want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestLoadBootstrap_PickArtifactForCurrentHost ensures the embedded manifest
|
|
// resolves to a real URL for whatever platform the test runner is on, so a
|
|
// developer fixing this code locally can still smoke-test their changes.
|
|
func TestLoadBootstrap_PickArtifactForCurrentHost(t *testing.T) {
|
|
manifest, err := LoadBootstrap()
|
|
if err != nil {
|
|
t.Fatalf("LoadBootstrap: %v", err)
|
|
}
|
|
art, err := manifest.PickArtifact(runtime.GOOS, runtime.GOARCH, "cn")
|
|
if err != nil {
|
|
t.Fatalf("PickArtifact for %s/%s: %v", runtime.GOOS, runtime.GOARCH, err)
|
|
}
|
|
if !strings.HasPrefix(art.URL, "https://") {
|
|
t.Errorf("URL is not https: %q", art.URL)
|
|
}
|
|
if !strings.HasSuffix(art.URL, ".zip") {
|
|
t.Errorf("URL is not a .zip: %q", art.URL)
|
|
}
|
|
if art.BuildID == "" {
|
|
t.Error("BuildID is empty")
|
|
}
|
|
}
|