Files
ai_academy/internal/sandbox/remote_snapshot_test.go
T
runny 7ec21f35b0 chore: 初始化仓库,导入项目基线代码
Academy v0.8.3 完整代码基线:Go 后端(internal/cmd/cli/mcp-server/docreader)、
Vue 前端(frontend)、数据库迁移(migrations)、部署编排(docker/helm/deploy)与文档。
今日开发的培训推送管理改动随后单独提交。
2026-11-16 18:12:23 +08:00

66 lines
1.8 KiB
Go

package sandbox
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestSnapshotManagerFromDetectsCapability(t *testing.T) {
t.Run("client implementing the interface is returned", func(t *testing.T) {
client := newFakeRemoteClient(SandboxTypeCube)
client.capabilities.SupportsSnapshots = true
mgr, ok := SnapshotManagerFrom(client)
require.True(t, ok)
require.NotNil(t, mgr)
})
t.Run("client without snapshot support is rejected", func(t *testing.T) {
client := &noSnapshotClient{}
mgr, ok := SnapshotManagerFrom(client)
require.False(t, ok)
require.Nil(t, mgr)
})
t.Run("interface without SupportsSnapshots is rejected", func(t *testing.T) {
client := newFakeRemoteClient(SandboxTypeCube)
client.capabilities.SupportsSnapshots = false
mgr, ok := SnapshotManagerFrom(client)
require.False(t, ok, "embedding snapshot methods must not override a false capability flag")
require.Nil(t, mgr)
})
}
func TestFakeSnapshotRoundTrip(t *testing.T) {
ctx := context.Background()
client := newFakeRemoteClient(SandboxTypeCube)
ref, err := client.CreateSnapshot(ctx, "sb-1", "academy-sk-abc-g1")
require.NoError(t, err)
require.NotEmpty(t, ref.ID)
list, err := client.ListSnapshots(ctx, "sb-1")
require.NoError(t, err)
require.Len(t, list, 1)
require.Equal(t, ref.ID, list[0].ID)
// Deleting twice must be idempotent: a missing snapshot is not an error.
require.NoError(t, client.DeleteSnapshot(ctx, ref.ID))
require.NoError(t, client.DeleteSnapshot(ctx, ref.ID))
list, err = client.ListSnapshots(ctx, "sb-1")
require.NoError(t, err)
require.Empty(t, list)
}
// noSnapshotClient implements RemoteSandboxClient without the snapshot methods,
// so SnapshotManagerFrom must reject it.
type noSnapshotClient struct{ RemoteSandboxClient }