mirror of
https://github.com/larksuite/cli.git
synced 2026-07-07 17:45:15 +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.
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package sec
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestSaveLoadState_Roundtrip(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "state.json")
|
|
|
|
in := &State{
|
|
Version: "1.2.3",
|
|
BuildID: "build-42",
|
|
InstalledAt: time.Date(2026, 5, 18, 12, 0, 0, 0, time.UTC),
|
|
BinaryPath: "/tmp/lark-sec-cli",
|
|
}
|
|
if err := SaveState(path, in); err != nil {
|
|
t.Fatalf("SaveState: %v", err)
|
|
}
|
|
got, err := LoadState(path)
|
|
if err != nil {
|
|
t.Fatalf("LoadState: %v", err)
|
|
}
|
|
if got == nil {
|
|
t.Fatal("LoadState returned nil")
|
|
}
|
|
if got.Version != in.Version || got.BuildID != in.BuildID || got.BinaryPath != in.BinaryPath {
|
|
t.Errorf("roundtrip mismatch: got=%+v want=%+v", got, in)
|
|
}
|
|
if !got.InstalledAt.Equal(in.InstalledAt) {
|
|
t.Errorf("InstalledAt mismatch: got=%v want=%v", got.InstalledAt, in.InstalledAt)
|
|
}
|
|
}
|
|
|
|
func TestLoadState_AbsentFile(t *testing.T) {
|
|
got, err := LoadState(filepath.Join(t.TempDir(), "missing.json"))
|
|
if err != nil {
|
|
t.Fatalf("expected nil error for missing file, got %v", err)
|
|
}
|
|
if got != nil {
|
|
t.Errorf("expected nil state for missing file, got %+v", got)
|
|
}
|
|
}
|