diff --git a/.github/workflows/pr-test.yml b/.github/workflows/pr-test.yml index 938e1fc3..c9e07eda 100644 --- a/.github/workflows/pr-test.yml +++ b/.github/workflows/pr-test.yml @@ -1531,3 +1531,194 @@ jobs: issue_number: issue_number, body: '✅ Registry Client SDK Tests passed!' }); + + # ============================================================================= + # Tai SDK Tests (requires Tai container with Docker socket mount) + # ============================================================================= + TaiTest: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.25"] + if: > + ${{ github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' }} + steps: + - name: "Download artifact" + uses: actions/github-script@v7 + with: + script: | + var artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + var download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); + + - name: "Read NR & SHA" + run: | + unzip pr.zip + cat NR + cat SHA + echo HEAD=$(cat SHA) >> $GITHUB_ENV + echo NR=$(cat NR) >> $GITHUB_ENV + + - name: "Comment on PR" + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { NR } = process.env + var issue_number = NR; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: '🤖 Tai SDK Tests running...' + }); + + - name: Checkout Kun + uses: actions/checkout@v4 + with: + repository: yaoapp/kun + path: kun + + - name: Checkout Xun + uses: actions/checkout@v4 + with: + repository: yaoapp/xun + path: xun + + - name: Checkout Gou + uses: actions/checkout@v4 + with: + repository: yaoapp/gou + path: gou + + - name: Checkout V8Go + uses: actions/checkout@v4 + with: + repository: yaoapp/v8go + path: v8go + + - name: Unzip libv8 + run: | + files=$(find ./v8go -name "libv8*.zip") + for file in $files; do + dir=$(dirname "$file") + echo "Extracting $file to directory $dir" + unzip -o -d $dir $file + rm -rf $dir/__MACOSX + done + + - name: Checkout Demo App + uses: actions/checkout@v4 + with: + repository: yaoapp/yao-dev-app + path: app + + - name: Checkout Extension + uses: actions/checkout@v4 + with: + repository: yaoapp/yao-extensions-dev + path: extension + + - name: Move Dependencies + run: | + mv kun ../ + mv xun ../ + mv gou ../ + mv v8go ../ + mv app ../ + mv extension ../ + + - name: Checkout pull request HEAD commit + uses: actions/checkout@v4 + with: + ref: ${{ env.HEAD }} + + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Pull Tai & Test Images + run: | + docker pull yaoapp/tai:latest + docker pull alpine:latest + + - name: Install k3d + run: curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash + + - name: Create k3d cluster + run: | + k3d cluster create tai-test --no-lb --wait --api-port 16443 + kubectl wait --for=condition=Ready node --all --timeout=60s + k3d image import alpine:latest -c tai-test + + - name: Start Tai (with Docker socket + K8s proxy) + run: | + K3D_IP=$(docker inspect k3d-tai-test-server-0 | jq -r '.[0].NetworkSettings.Networks["k3d-tai-test"].IPAddress') + echo "k3d server IP: ${K3D_IP}" + + docker run -d --name tai \ + --network k3d-tai-test \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -p 8080:8080 -p 9100:9100 -p 2375:2375 -p 6080:6080 -p 6443:6443 \ + -e TAI_K8S_UPSTREAM="tcp://${K3D_IP}:6443" \ + yaoapp/tai:latest + for i in $(seq 1 30); do + if curl -sf http://127.0.0.1:8080/healthz > /dev/null 2>&1; then + echo "Tai is ready" + break + fi + echo "Waiting for Tai... ($i)" + sleep 1 + done + + - name: Generate kubeconfig for Tai K8s proxy + run: | + k3d kubeconfig get tai-test > /tmp/kubeconfig-k3d.yml + sed 's|server: .*|server: https://127.0.0.1:6443|' /tmp/kubeconfig-k3d.yml \ + > ${{ runner.temp }}/kubeconfig-tai.yml + echo "Generated kubeconfig:" + grep server: ${{ runner.temp }}/kubeconfig-tai.yml + + - name: Run Tai SDK Tests + env: + TAI_TEST_HOST: "127.0.0.1" + TAI_TEST_GRPC: "127.0.0.1:9100" + TAI_TEST_DOCKER: "tcp://127.0.0.1:2375" + TAI_TEST_K8S_HOST: "127.0.0.1" + TAI_TEST_K8S_PORT: "6443" + TAI_TEST_KUBECONFIG: "${{ runner.temp }}/kubeconfig-tai.yml" + run: make unit-test-tai + + - name: Codecov Report + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + + - name: "Comment on PR - Tai Tests Done" + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { NR } = process.env + var issue_number = NR; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue_number, + body: '✅ Tai SDK Tests passed!' + }); diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index c736b3ec..7d3696e2 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -1133,3 +1133,132 @@ jobs: uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} + + # ============================================================================= + # Tai SDK Tests (requires Tai container with Docker socket mount) + # ============================================================================= + tai-test: + runs-on: ubuntu-latest + strategy: + matrix: + go: ["1.25"] + steps: + - name: Checkout Kun + uses: actions/checkout@v4 + with: + repository: ${{ env.REPO_KUN }} + path: kun + + - name: Checkout Xun + uses: actions/checkout@v4 + with: + repository: ${{ env.REPO_XUN }} + path: xun + + - name: Checkout Gou + uses: actions/checkout@v4 + with: + repository: ${{ env.REPO_GOU }} + path: gou + + - name: Checkout V8Go + uses: actions/checkout@v4 + with: + repository: yaoapp/v8go + path: v8go + + - name: Unzip libv8 + run: | + files=$(find ./v8go -name "libv8*.zip") + for file in $files; do + dir=$(dirname "$file") + echo "Extracting $file to directory $dir" + unzip -o -d $dir $file + rm -rf $dir/__MACOSX + done + + - name: Checkout Demo App + uses: actions/checkout@v4 + with: + repository: yaoapp/yao-dev-app + path: app + + - name: Checkout Extension + uses: actions/checkout@v4 + with: + repository: yaoapp/yao-extensions-dev + path: extension + + - name: Move Dependencies + run: | + mv kun ../ + mv xun ../ + mv gou ../ + mv v8go ../ + mv app ../ + mv extension ../ + + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Go ${{ matrix.go }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + + - name: Pull Tai & Test Images + run: | + docker pull yaoapp/tai:latest + docker pull alpine:latest + + - name: Install k3d + run: curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash + + - name: Create k3d cluster + run: | + k3d cluster create tai-test --no-lb --wait --api-port 16443 + kubectl wait --for=condition=Ready node --all --timeout=60s + k3d image import alpine:latest -c tai-test + + - name: Start Tai (with Docker socket + K8s proxy) + run: | + K3D_IP=$(docker inspect k3d-tai-test-server-0 | jq -r '.[0].NetworkSettings.Networks["k3d-tai-test"].IPAddress') + echo "k3d server IP: ${K3D_IP}" + + docker run -d --name tai \ + --network k3d-tai-test \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -p 8080:8080 -p 9100:9100 -p 2375:2375 -p 6080:6080 -p 6443:6443 \ + -e TAI_K8S_UPSTREAM="tcp://${K3D_IP}:6443" \ + yaoapp/tai:latest + for i in $(seq 1 30); do + if curl -sf http://127.0.0.1:8080/healthz > /dev/null 2>&1; then + echo "Tai is ready" + break + fi + echo "Waiting for Tai... ($i)" + sleep 1 + done + + - name: Generate kubeconfig for Tai K8s proxy + run: | + k3d kubeconfig get tai-test > /tmp/kubeconfig-k3d.yml + sed 's|server: .*|server: https://127.0.0.1:6443|' /tmp/kubeconfig-k3d.yml \ + > ${{ runner.temp }}/kubeconfig-tai.yml + echo "Generated kubeconfig:" + grep server: ${{ runner.temp }}/kubeconfig-tai.yml + + - name: Run Tai SDK Tests + env: + TAI_TEST_HOST: "127.0.0.1" + TAI_TEST_GRPC: "127.0.0.1:9100" + TAI_TEST_DOCKER: "tcp://127.0.0.1:2375" + TAI_TEST_K8S_HOST: "127.0.0.1" + TAI_TEST_K8S_PORT: "6443" + TAI_TEST_KUBECONFIG: "${{ runner.temp }}/kubeconfig-tai.yml" + run: make unit-test-tai + + - name: Codecov Report + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 56d0d398..5c81f9b5 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,4 @@ tg-login tg-send registry/data/ registry/manager/DESIGN*.md +tai/testdata/ diff --git a/Makefile b/Makefile index 1a0e23b7..6c704606 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ OS := $(shell uname) # ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) TESTFOLDER := $(shell $(GO) list ./... | grep -vE 'examples|openai|aigc|neo|twilio|share*|registry' | awk '!/\/tests\// || /openapi\/tests/') # Core tests (exclude AI-related: agent, aigc, openai, KB, sandbox, registry, and integrations which require external services) -TESTFOLDER_CORE := $(shell $(GO) list ./... | grep -vE 'examples|openai|aigc|neo|twilio|share*|agent|kb|sandbox|integrations|registry' | awk '!/\/tests\// || /openapi\/tests/') +TESTFOLDER_CORE := $(shell $(GO) list ./... | grep -vE 'examples|openai|aigc|neo|twilio|share*|agent|kb|sandbox|integrations|registry|tai' | awk '!/\/tests\// || /openapi\/tests/') # Agent tests (agent, aigc) - exclude agent/search/handlers/web (requires external API keys) and robot packages (tested in robot job) TESTFOLDER_AGENT := $(shell $(GO) list ./agent/... ./aigc/... | grep -vE 'agent/search/handlers/web|agent/robot/') # KB tests (kb) @@ -21,6 +21,8 @@ TESTFOLDER_KB := $(shell $(GO) list ./kb/...) TESTFOLDER_ROBOT := $(shell $(GO) list ./agent/robot/... | grep -vE 'agent/robot/events') # Sandbox tests (requires Docker) TESTFOLDER_SANDBOX := $(shell $(GO) list ./sandbox/...) +# Tai SDK tests (requires Tai container with Docker socket) +TESTFOLDER_TAI := $(shell $(GO) list ./tai/...) TESTTAGS ?= "" # TESTWIDGETS := $(shell $(GO) list ./widgets/...) @@ -240,6 +242,49 @@ unit-test-sandbox: @echo "✅ All sandbox tests passed" @echo "=============================================" +# Tai SDK Test (requires Tai container with Docker socket) +.PHONY: unit-test-tai +unit-test-tai: + @echo "" + @echo "=============================================" + @echo "Running Tai SDK Tests (requires Tai container)..." + @echo "=============================================" + @echo "Pulling test images..." + docker pull alpine:latest || true + @echo "" + echo "mode: count" > coverage.out + for d in $(TESTFOLDER_TAI); do \ + $(GO) test -tags $(TESTTAGS) -v -timeout=5m -covermode=count -coverprofile=profile.out -coverpkg=$$(echo $$d | sed "s/\/test$$//g") $$d > tmp.out; \ + cat tmp.out; \ + if grep -q "^--- FAIL" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "^FAIL" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "^panic:" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "build failed" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "setup failed" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + elif grep -q "runtime error" tmp.out; then \ + rm tmp.out; \ + exit 1; \ + fi; \ + if [ -f profile.out ]; then \ + cat profile.out | grep -v "mode:" >> coverage.out; \ + rm profile.out; \ + fi; \ + done + @echo "" + @echo "=============================================" + @echo "All Tai SDK tests passed" + @echo "=============================================" + # Benchmark Test .PHONY: benchmark benchmark: diff --git a/go.mod b/go.mod index 10d504ff..9d69fa70 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/yaoapp/yao -go 1.25 +go 1.25.0 require ( github.com/PuerkitoBio/goquery v1.10.3 @@ -8,6 +8,7 @@ require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.67 github.com/aws/aws-sdk-go-v2/service/s3 v1.79.3 github.com/blang/semver v3.5.1+incompatible + github.com/bwmarrin/discordgo v0.29.0 github.com/caarlos0/env/v6 v6.10.1 github.com/charmbracelet/bubbletea v1.3.10 github.com/charmbracelet/lipgloss v1.1.0 @@ -21,18 +22,22 @@ require ( github.com/fatih/color v1.18.0 github.com/fsnotify/fsnotify v1.9.0 github.com/gin-gonic/gin v1.10.1 + github.com/go-telegram/bot v1.19.0 github.com/golang-jwt/jwt/v4 v4.5.2 github.com/google/uuid v1.6.0 - github.com/gorilla/websocket v1.5.3 + github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 github.com/gotd/td v0.140.0 github.com/hashicorp/go-multierror v1.1.1 github.com/joho/godotenv v1.5.1 github.com/json-iterator/go v1.1.12 github.com/kaptinlin/jsonrepair v0.1.1 github.com/kaptinlin/jsonschema v0.6.1 + github.com/larksuite/oapi-sdk-go/v3 v3.5.3 github.com/matoous/go-nanoid/v2 v2.1.0 github.com/mattn/go-isatty v0.0.20 github.com/mozillazg/go-pinyin v0.20.0 + github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1 + github.com/pierrec/lz4/v4 v4.1.25 github.com/pkoukk/tiktoken-go v0.1.7 github.com/pquerna/otp v1.5.0 github.com/rhysd/go-github-selfupdate v1.2.3 @@ -47,8 +52,13 @@ require ( golang.org/x/crypto v0.48.0 golang.org/x/net v0.50.0 golang.org/x/text v0.34.0 + google.golang.org/grpc v1.78.0 + google.golang.org/protobuf v1.36.11 gopkg.in/natefinch/lumberjack.v2 v2.2.1 gopkg.in/yaml.v3 v3.0.1 + k8s.io/api v0.34.1 + k8s.io/apimachinery v0.34.1 + k8s.io/client-go v0.34.1 rogchap.com/v8go v0.9.0 ) @@ -58,7 +68,6 @@ require ( github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 // indirect - github.com/aliyun/credentials-go v1.4.6 // indirect github.com/andybalholm/cascadia v1.3.3 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect @@ -72,7 +81,6 @@ require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect - github.com/bwmarrin/discordgo v0.29.0 // indirect github.com/bytedance/sonic v1.13.2 // indirect github.com/bytedance/sonic/loader v0.2.4 // indirect github.com/cenkalti/backoff/v4 v4.3.0 // indirect @@ -81,7 +89,6 @@ require ( github.com/charmbracelet/x/ansi v0.10.1 // indirect github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect github.com/charmbracelet/x/term v0.2.1 // indirect - github.com/clbanning/mxj/v2 v2.5.5 // indirect github.com/cloudwego/base64x v0.1.5 // indirect github.com/coder/websocket v1.8.14 // indirect github.com/containerd/errdefs v1.0.0 // indirect @@ -92,8 +99,10 @@ require ( github.com/dlclark/regexp2 v1.11.5 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 // indirect + github.com/emicklei/go-restful/v3 v3.13.0 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/felixge/httpsnoop v1.0.4 // indirect + github.com/fxamacker/cbor/v2 v2.9.0 // indirect github.com/gabriel-vasile/mimetype v1.4.9 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/gin-contrib/sse v1.1.0 // indirect @@ -105,18 +114,21 @@ require ( github.com/go-json-experiment/json v0.0.0-20251027170946-4849db3c2f7e // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.26.0 // indirect github.com/go-redis/redis/v8 v8.11.5 // indirect github.com/go-sourcemap/sourcemap v2.1.4+incompatible // indirect github.com/go-sql-driver/mysql v1.9.2 // indirect - github.com/go-telegram/bot v1.19.0 // indirect github.com/goccy/go-json v0.10.5 // indirect github.com/goccy/go-yaml v1.18.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v1.0.0 // indirect + github.com/google/gnostic-models v0.7.0 // indirect github.com/google/go-github/v30 v30.1.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/gotd/ige v0.2.2 // indirect @@ -132,15 +144,16 @@ require ( github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/jmoiron/sqlx v1.4.0 // indirect + github.com/josharian/intern v1.0.0 // indirect github.com/kaptinlin/go-i18n v0.2.0 // indirect github.com/kaptinlin/jsonpointer v0.4.6 // indirect github.com/kaptinlin/messageformat-go v0.4.6 // indirect github.com/klauspost/compress v1.18.4 // indirect github.com/klauspost/cpuid/v2 v2.2.10 // indirect - github.com/larksuite/oapi-sdk-go/v3 v3.5.3 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/lib/pq v1.10.9 // indirect github.com/lucasb-eyer/go-colorful v1.3.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mark3labs/mcp-go v0.32.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-localereader v0.0.1 // indirect @@ -148,19 +161,23 @@ require ( github.com/mattn/go-sqlite3 v1.14.28 // indirect github.com/miekg/dns v1.1.66 // indirect github.com/moby/docker-image-spec v1.3.1 // indirect + github.com/moby/spdystream v0.5.0 // indirect github.com/moby/sys/atomicwriter v0.1.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect github.com/montanaflynn/stats v0.7.1 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.16.0 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect github.com/neo4j/neo4j-go-driver/v5 v5.28.1 // indirect github.com/ogen-go/ogen v1.19.0 // indirect github.com/oklog/run v1.1.0 // indirect - github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1 // indirect + github.com/onsi/ginkgo/v2 v2.25.1 // indirect + github.com/onsi/gomega v1.38.2 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.0 // indirect + github.com/opencontainers/image-spec v1.1.1 // indirect github.com/pdfcpu/pdfcpu v0.11.0 // indirect github.com/pelletier/go-toml/v2 v2.2.4 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -175,7 +192,7 @@ require ( github.com/sergi/go-diff v1.4.0 // indirect github.com/shopspring/decimal v1.4.0 // indirect github.com/sirupsen/logrus v1.9.4 // indirect - github.com/spf13/pflag v1.0.6 // indirect + github.com/spf13/pflag v1.0.9 // indirect github.com/tcnksm/go-gitconfig v0.1.2 // indirect github.com/tidwall/btree v1.7.0 // indirect github.com/tidwall/buntdb v1.3.2 // indirect @@ -186,10 +203,10 @@ require ( github.com/tidwall/rtred v0.1.2 // indirect github.com/tidwall/tinyqueue v0.1.1 // indirect github.com/tiendc/go-deepcopy v1.6.0 // indirect - github.com/tjfoc/gmsm v1.4.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect github.com/ulikunitz/xz v0.5.14 // indirect + github.com/x448/float16 v0.8.4 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect @@ -200,30 +217,42 @@ require ( github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect github.com/yuin/goldmark v1.7.16 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 // indirect go.opentelemetry.io/otel v1.40.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 // indirect go.opentelemetry.io/otel/metric v1.40.0 // indirect go.opentelemetry.io/otel/trace v1.40.0 // indirect go.opentelemetry.io/proto/otlp v1.9.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.1 // indirect + go.yaml.in/yaml/v2 v2.4.2 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect golang.org/x/arch v0.17.0 // indirect - golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 // indirect + golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f // indirect golang.org/x/image v0.29.0 // indirect golang.org/x/mod v0.33.0 // indirect - golang.org/x/oauth2 v0.30.0 // indirect + golang.org/x/oauth2 v0.32.0 // indirect golang.org/x/sync v0.19.0 // indirect golang.org/x/sys v0.41.0 // indirect + golang.org/x/term v0.40.0 // indirect + golang.org/x/time v0.14.0 // indirect golang.org/x/tools v0.42.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 // indirect - google.golang.org/grpc v1.75.1 // indirect - google.golang.org/protobuf v1.36.11 // indirect - gopkg.in/ini.v1 v1.67.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect + gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect + gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gotest.tools/v3 v3.5.2 // indirect + k8s.io/klog/v2 v2.130.1 // indirect + k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect + k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect rsc.io/qr v0.2.0 // indirect + sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect + sigs.k8s.io/randfill v1.0.0 // indirect + sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect + sigs.k8s.io/yaml v1.6.0 // indirect ) // go env -w GOPRIVATE=github.com/yaoapp/* diff --git a/go.sum b/go.sum index 95ef8c9d..300d01e9 100644 --- a/go.sum +++ b/go.sum @@ -1,66 +1,24 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= filippo.io/edwards25519 v1.1.1 h1:YpjwWWlNmGIDyXOn8zLzqiD+9TyIlPhGFG96P39uBpw= filippo.io/edwards25519 v1.1.1/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/JohannesKaufmann/dom v0.2.0 h1:1bragmEb19K8lHAqgFgqCpiPCFEZMTXzOIEjuxkUfLQ= github.com/JohannesKaufmann/dom v0.2.0/go.mod h1:57iSUl5RKric4bUkgos4zu6Xt5LMHUnw3TF1l5CbGZo= github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0 h1:mklaPbT4f/EiDr1Q+zPrEt9lgKAkVrIBtWf33d9GpVA= github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0/go.mod h1:D56Cl9r8M5i3UwAchE+LlLc5hPN3kJtdZNVJn06lSHU= +github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= +github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo= github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y= github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2 h1:ZBbLwSJqkHBuFDA6DUhhse0IGJ7T5bemHyNILUjvOq4= github.com/TylerBrock/colorjson v0.0.0-20200706003622-8a50f05110d2/go.mod h1:VSw57q4QFiWDbRnjdX8Cb3Ow0SFncRw+bA/ofY6Q83w= -github.com/alibabacloud-go/alibabacloud-gateway-pop v0.0.6/go.mod h1:4EUIoxs/do24zMOGGqYVWgw0s9NtiylnJglOeEB5UJo= -github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc= -github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 h1:zE8vH9C7JiZLNJJQ5OwjU9mSi4T9ef9u3BURT6LCLC8= -github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5/go.mod h1:tWnyE9AjF8J8qqLk645oUmVUnFybApTQWklQmi5tY6g= -github.com/alibabacloud-go/darabonba-array v0.1.0/go.mod h1:BLKxr0brnggqOJPqT09DFJ8g3fsDshapUD3C3aOEFaI= -github.com/alibabacloud-go/darabonba-encode-util v0.0.2/go.mod h1:JiW9higWHYXm7F4PKuMgEUETNZasrDM6vqVr/Can7H8= -github.com/alibabacloud-go/darabonba-map v0.0.2/go.mod h1:28AJaX8FOE/ym8OUFWga+MtEzBunJwQGceGQlvaPGPc= -github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.12 h1:Dqhik/9iK3/ltjMuVy2kkuuWK3KPRes2vSzxnrehT74= -github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.12/go.mod h1:cgtLEj8i4ddXMcQgq4PnpVQvlzS+y5B+QtdSfmcLM3A= -github.com/alibabacloud-go/darabonba-signature-util v0.0.7/go.mod h1:oUzCYV2fcCH797xKdL6BDH8ADIHlzrtKVjeRtunBNTQ= -github.com/alibabacloud-go/darabonba-string v1.0.2/go.mod h1:93cTfV3vuPhhEwGGpKKqhVW4jLe7tDpo3LUM0i0g6mA= -github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY= -github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc= -github.com/alibabacloud-go/debug v1.0.1 h1:MsW9SmUtbb1Fnt3ieC6NNZi6aEwrXfDksD4QA6GSbPg= -github.com/alibabacloud-go/debug v1.0.1/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc= -github.com/alibabacloud-go/dingtalk v1.6.98 h1:7EBiJvGgzm2uT44B5VDMBGC5zdx8co7CNuLr0fafCP8= -github.com/alibabacloud-go/dingtalk v1.6.98/go.mod h1:mUcgNRgMGQzABtiZtTK8a3b6LwQBQ8t9WsDKzklqVpg= -github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE= -github.com/alibabacloud-go/gateway-dingtalk v1.0.2 h1:+etjmc64QTmYvHlc6eFkH9y2DOc3UPcyD2nF3IXsVqw= -github.com/alibabacloud-go/gateway-dingtalk v1.0.2/go.mod h1:JUvHpkJtlPFpgJcfXqc9Y4mk2JnoRn5XpKbRz38jJho= -github.com/alibabacloud-go/openapi-util v0.1.0/go.mod h1:sQuElr4ywwFRlCCberQwKRFhRzIyG4QTP/P4y1CJ6Ws= -github.com/alibabacloud-go/openapi-util v0.1.1 h1:ujGErJjG8ncRW6XtBBMphzHTvCxn4DjrVw4m04HsS28= -github.com/alibabacloud-go/openapi-util v0.1.1/go.mod h1:/UehBSE2cf1gYT43GV4E+RxTdLRzURImCYY0aRmlXpw= -github.com/alibabacloud-go/tea v1.1.0/go.mod h1:IkGyUSX4Ba1V+k4pCtJUc6jDpZLFph9QMy2VUPTwukg= -github.com/alibabacloud-go/tea v1.1.7/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= -github.com/alibabacloud-go/tea v1.1.8/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= -github.com/alibabacloud-go/tea v1.1.11/go.mod h1:/tmnEaQMyb4Ky1/5D+SE1BAsa5zj/KeGOFfwYm3N/p4= -github.com/alibabacloud-go/tea v1.1.17/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= -github.com/alibabacloud-go/tea v1.1.20/go.mod h1:nXxjm6CIFkBhwW4FQkNrolwbfon8Svy6cujmKFUq98A= -github.com/alibabacloud-go/tea v1.2.2 h1:aTsR6Rl3ANWPfqeQugPglfurloyBJY85eFy7Gc1+8oU= -github.com/alibabacloud-go/tea v1.2.2/go.mod h1:CF3vOzEMAG+bR4WOql8gc2G9H3EkH3ZLAQdpmpXMgwk= -github.com/alibabacloud-go/tea-utils v1.3.1 h1:iWQeRzRheqCMuiF3+XkfybB3kTgUXkXX+JMrqfLeB2I= -github.com/alibabacloud-go/tea-utils v1.3.1/go.mod h1:EI/o33aBfj3hETm4RLiAxF/ThQdSngxrpF8rKUDJjPE= -github.com/alibabacloud-go/tea-utils/v2 v2.0.1/go.mod h1:U5MTY10WwlquGPS34DOeomUGBB0gXbLueiq5Trwu0C4= -github.com/alibabacloud-go/tea-utils/v2 v2.0.5/go.mod h1:dL6vbUT35E4F4bFTHL845eUloqaerYBYPsdWR2/jhe4= -github.com/alibabacloud-go/tea-utils/v2 v2.0.6 h1:ZkmUlhlQbaDC+Eba/GARMPy6hKdCLiSke5RsN5LcyQ0= -github.com/alibabacloud-go/tea-utils/v2 v2.0.6/go.mod h1:qxn986l+q33J5VkialKMqT/TTs3E+U9MJpd001iWQ9I= -github.com/alibabacloud-go/tea-xml v1.1.3 h1:7LYnm+JbOq2B+T/B0fHC4Ies4/FofC4zHzYtqw7dgt0= -github.com/alibabacloud-go/tea-xml v1.1.3/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8= -github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw= -github.com/aliyun/credentials-go v1.3.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTsBEN04dgcAcYz0= -github.com/aliyun/credentials-go v1.3.6/go.mod h1:1LxUuX7L5YrZUWzBrRyk0SwSdH4OmPrib8NVePL3fxM= -github.com/aliyun/credentials-go v1.4.6 h1:CG8rc/nxCNKfXbZWpWDzI9GjF4Tuu3Es14qT8Y0ClOk= -github.com/aliyun/credentials-go v1.4.6/go.mod h1:Jm6d+xIgwJVLVWT561vy67ZRP4lPTQxMbEYRuT2Ti1U= github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= +github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/aws/aws-sdk-go-v2 v1.36.3 h1:mJoei2CxPutQVxaATCzDUjcZEjVRdpsiiXi2o38yqWM= github.com/aws/aws-sdk-go-v2 v1.36.3/go.mod h1:LLXuLpgzEbD766Z5ECcRmi8AzSwfZItDtmABVkRLGzg= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 h1:zAybnyUQXIZ5mok5Jqwlf58/TFE7uvd3IAsa1aF9cXs= @@ -110,7 +68,6 @@ github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/I github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= @@ -125,13 +82,9 @@ github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd h1:vy0G github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= -github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= -github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g= github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg= github.com/containerd/errdefs v1.0.0 h1:tg5yIfIlQIrxYtu9ajqY42W3lpS19XqdxRQeEwYG8PI= @@ -141,6 +94,7 @@ github.com/containerd/errdefs/pkg v0.3.0/go.mod h1:NJw6s9HwNuRhnjJhM7pylWwMyAkmC github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I= github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -167,9 +121,8 @@ github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21/go.mod h1:iL2twTe github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 h1:oP4q0fw+fOSWn3DfFi4EXdT+B+gTtzx8GC9xsc26Znk= github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6/go.mod h1:iL2twTeMvZnrg54ZoPDNfJaJaqy0xIQFuBdrLsmspwQ= github.com/emersion/go-textwrapper v0.0.0-20200911093747-65d896831594/go.mod h1:aqO8z8wPrjkscevZJFVE1wXJrLpC5LtJG7fqLOsPb2U= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/emicklei/go-restful/v3 v3.13.0 h1:C4Bl2xDndpU6nJ4bc1jXd+uTmYPVUwkD6bFY/oTyCes= +github.com/emicklei/go-restful/v3 v3.13.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= github.com/evanw/esbuild v0.25.4 h1:k1bTSim+usBG27w7BfOCorhgx3tO+6bAfMj5pR+6SKg= @@ -186,6 +139,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= +github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY= github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok= github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk= @@ -212,6 +167,14 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -227,6 +190,8 @@ github.com/go-sourcemap/sourcemap v2.1.4+incompatible/go.mod h1:F8jJfvm2KbVjc5Nq github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-sql-driver/mysql v1.9.2 h1:4cNKDYQ1I84SXslGddlsrMhc8k4LeDVj6Ad6WRjiHuU= github.com/go-sql-driver/mysql v1.9.2/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-telegram/bot v1.19.0 h1:tuvTQhgNietHFRN0HUDhuXsgfgkGSaO8WWwZQW3DMQg= github.com/go-telegram/bot v1.19.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4= @@ -237,25 +202,14 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.5.2 h1:YtQM7lnr8iZ+j5q71MGKkNw9Mn7AjHM68uc9g5fXeUI= github.com/golang-jwt/jwt/v4 v4.5.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs= github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= +github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= @@ -266,14 +220,14 @@ github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= -github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo= +github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA= github.com/gotd/ige v0.2.2 h1:XQ9dJZwBfDnOGSTxKXBGP4gMud3Qku2ekScRjDWWfEk= github.com/gotd/ige v0.2.2/go.mod h1:tuCRb+Y5Y3eNTo3ypIfNpQ4MFjrnONiL2jN2AKZXmb0= github.com/gotd/neo v0.1.5 h1:oj0iQfMbGClP8xI59x7fE/uHoTJD7NZH9oV1WNuPukQ= @@ -314,10 +268,10 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/kaptinlin/go-i18n v0.2.0 h1:8iwjAERQbCVF78c3HxC4MxUDxDRFvQVQlMDvlsO43hU= github.com/kaptinlin/go-i18n v0.2.0/go.mod h1:gRHEMrTHtQLsAFwulPbJG71TwHjXxkagn88O8FI8FuA= github.com/kaptinlin/jsonpointer v0.4.6 h1:hAett1YROLwxAOKZS08hsJueXr1w0fTMSvWq2x1IoUA= @@ -337,6 +291,7 @@ github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2 github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -351,6 +306,8 @@ github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mark3labs/mcp-go v0.32.0 h1:fgwmbfL2gbd67obg57OfV2Dnrhs1HtSdlY/i5fn7MU8= github.com/mark3labs/mcp-go v0.32.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4= github.com/matoous/go-nanoid/v2 v2.1.0 h1:P64+dmq21hhWdtvZfEAofnvJULaRR1Yib0+PnU669bE= @@ -374,6 +331,8 @@ github.com/miekg/dns v1.1.66 h1:FeZXOS3VCVsKnEAd+wBkjMC3D2K+ww66Cq3VnCINuJE= github.com/miekg/dns v1.1.66/go.mod h1:jGFzBsSNbJw6z1HYut1RKBKHA9PBdxeHrZG8J+gC2WE= github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0= github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo= +github.com/moby/spdystream v0.5.0 h1:7r0J1Si3QO/kjRitvSLVVFUjxMEb/YLj6S9FF62JBCU= +github.com/moby/spdystream v0.5.0/go.mod h1:xBAYlnt/ay+11ShkdFKNAG7LsyK/tmNBVvVOwrfMgdI= github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw= github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs= github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU= @@ -383,10 +342,9 @@ github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3 github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= @@ -399,9 +357,12 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus= +github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/neo4j/neo4j-go-driver/v5 v5.28.1 h1:RKWQW7wTgYAY2fU9S+9LaJ9OwRPbRc0I17tlT7nDmAY= github.com/neo4j/neo4j-go-driver/v5 v5.28.1/go.mod h1:Vff8OwT7QpLm7L2yYr85XNWe9Rbqlbeb9asNXJTHO4k= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/ogen-go/ogen v1.19.0 h1:YvdNpeQJ8A8dLLpS6Vs4WxXL53BT6tBPxH0VSjfALhA= @@ -411,19 +372,23 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.25.1 h1:Fwp6crTREKM+oA6Cz4MsO8RhKQzs2/gOIVOUscMAfZY= +github.com/onsi/ginkgo/v2 v2.25.1/go.mod h1:ppTWQ1dh9KM/F1XgpeRqelR+zHVwV81DGRSDnFxK7Sk= github.com/onsi/gomega v1.4.2/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= -github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= +github.com/onsi/gomega v1.38.2 h1:eZCjf2xjZAqe+LeWvKb5weQ+NcPwX84kqJ0cZNxok2A= +github.com/onsi/gomega v1.38.2/go.mod h1:W2MJcYxRGV63b418Ai34Ud0hEdTVXq9NW9+Sx6uXf3k= github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1 h1:Lb/Uzkiw2Ugt2Xf03J5wmv81PdkYOiWbI8CNBi1boC8= github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1/go.mod h1:ln3IqPYYocZbYvl9TAOrG/cxGR9xcn4pnZRLdCTEGEU= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug= -github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM= +github.com/opencontainers/image-spec v1.1.1 h1:y0fUlFfIZhPF1W537XOLg0/fcx6zcHCJwooC2xJA040= +github.com/opencontainers/image-spec v1.1.1/go.mod h1:qpqAh3Dmcf36wStyyWU+kCeDgrGnAve2nCC8+7h8Q0M= github.com/pdfcpu/pdfcpu v0.11.0 h1:mL18Y3hSHzSezmnrzA21TqlayBOXuAx7BUzzZyroLGM= github.com/pdfcpu/pdfcpu v0.11.0/go.mod h1:F1ca4GIVFdPtmgvIdvXAycAm88noyNxZwzr9CpTy+Mw= github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4= github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY= +github.com/pierrec/lz4/v4 v4.1.25 h1:kocOqRffaIbU5djlIBr7Wh+cx82C0vtFb0fOurZHqD0= +github.com/pierrec/lz4/v4 v4.1.25/go.mod h1:EoQMVJgeeEOMsCqCzqFm2O0cJvljX2nGZjcRIPL34O4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkoukk/tiktoken-go v0.1.7 h1:qOBHXX4PHtvIvmOtyg1EeKlwFRiMKAcoMp4Q+bLQDmw= @@ -432,7 +397,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs= github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/qdrant/go-client v1.14.0 h1:cyz9OOooAexudw5w69LRe9vKCQFYJvaFvt9icOciI1U= github.com/qdrant/go-client v1.14.0/go.mod h1:iO8ts78jL4x6LDHFOViyYWELVtIBDTjOykBmiOTHLnQ= github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4ViluI= @@ -462,22 +426,20 @@ github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME= github.com/sirupsen/logrus v1.9.4 h1:TsZE7l11zFCLZnZ+teH4Umoq5BhEIfIzfRDZ1Uzql2w= github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC42RjbV2g= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/assertions v1.1.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/spf13/cast v1.9.2 h1:SsGfm7M8QOFtEzumm7UZrZdLLquNdzFYfIbEXntcFbE= github.com/spf13/cast v1.9.2/go.mod h1:jNfB8QC9IA6ZuY2ZjDp0KtFO2LZZlg4S/7bzP6qqeHo= github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= -github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.9 h1:9exaQaMOCwffKiiiYk6/BndUBv+iRViNW+4lEMi0PvY= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= @@ -511,9 +473,6 @@ github.com/tidwall/tinyqueue v0.1.1 h1:SpNEvEggbpyN5DIReaJ2/1ndroY8iyEGxPYxoSaym github.com/tidwall/tinyqueue v0.1.1/go.mod h1:O/QNHwrnjqr6IHItYrzoHAKYhBkLI67Q096fQP5zMYw= github.com/tiendc/go-deepcopy v1.6.0 h1:0UtfV/imoCwlLxVsyfUd4hNHnB3drXsfle+wzSCA5Wo= github.com/tiendc/go-deepcopy v1.6.0/go.mod h1:toXoeQoUqXOOS/X4sKuiAoSk6elIdqc0pN7MTgOOo2I= -github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w= -github.com/tjfoc/gmsm v1.4.1 h1:aMe1GlZb+0bLjn+cKTPEvvn9oUEBlJitaZiiBwsbgho= -github.com/tjfoc/gmsm v1.4.1/go.mod h1:j4INPkHWMrhJb38G+J6W4Tw0AbuN8Thu3PbdVYhVcTE= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= @@ -521,6 +480,8 @@ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/ulikunitz/xz v0.5.14 h1:uv/0Bq533iFdnMHZdRBTOlaNMdb1+ZxXIlHDZHIHcvg= github.com/ulikunitz/xz v0.5.14/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= +github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= @@ -540,7 +501,6 @@ github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT0 github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.30/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE= @@ -549,14 +509,14 @@ go.mongodb.org/mongo-driver v1.17.3 h1:TQyXhnsWfWtgAhMtOgtYHMTkZIfBTpMTsMnd9ZBeH go.mongodb.org/mongo-driver v1.17.3/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0 h1:sbiXRNDSWJOTobXh5HyQKjq6wUC5tNybqjIqDpAY4CU= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.60.0/go.mod h1:69uWxva0WgAA/4bu2Yy70SLDBwZXuQ6PbBpbsa5iZrQ= go.opentelemetry.io/otel v1.40.0 h1:oA5YeOcpRTXq6NN7frwmwFR0Cn3RhTVZvXsP4duvCms= go.opentelemetry.io/otel v1.40.0/go.mod h1:IMb+uXZUKkMXdPddhwAHm6UfOwJyh4ct1ybIlV14J0g= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 h1:QKdN8ly8zEMrByybbQgv8cWBcdAarwmIPZ6FThrWXJs= go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0/go.mod h1:bTdK1nhqF76qiPoCCdyFIV+N/sRHYXYCTQc+3VCi3MI= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 h1:digkEZCJWobwBqMwC0cwCq8/wkkRy/OowZg5OArWZrM= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0/go.mod h1:/OpE/y70qVkndM0TrxT4KBoN3RsFZP0QaofcfYrj76I= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0 h1:xJ2qHD0C1BeYVTLLR9sX12+Qb95kfeD/byKj6Ky1pXg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.35.0/go.mod h1:u5BF1xyjstDowA1R5QAO9JHzqK+ublenEW/dyqTjBVk= go.opentelemetry.io/otel/metric v1.40.0 h1:rcZe317KPftE2rstWIBitCdVp89A2HqjkxR3c11+p9g= go.opentelemetry.io/otel/metric v1.40.0/go.mod h1:ib/crwQH7N3r5kfiBZQbwrTge743UDc7DTFVZrrXnqc= go.opentelemetry.io/otel/sdk v1.40.0 h1:KHW/jUzgo6wsPh9At46+h4upjtccTmuZCFAc9OJ71f8= @@ -569,40 +529,36 @@ go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjce go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= +go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= +go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.1 h1:08RqriUEv8+ArZRYSTXy1LeBScaMpVSTBhCeaZYfMYc= go.uber.org/zap v1.27.1/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= +go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/arch v0.17.0 h1:4O3dfLzd+lQewptAHqjewQZQDyEdejz3VwgeYwkZneU= golang.org/x/arch v0.17.0/go.mod h1:bdwinDaKcfZUGpH09BB7ZmOfhalA8lQdzl62l8gGWsk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090 h1:Di6/M8l0O2lCLc6VVRWhgCiApHV8MnQurBnFSHsQtNY= -golang.org/x/exp v0.0.0-20230725093048-515e97ebf090/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f h1:XdNn9LlyWAhLVp6P/i8QYBW+hlyhrhei9uErw2B5GJo= +golang.org/x/exp v0.0.0-20241108190413-2d47ceb2692f/go.mod h1:D5SMRVC3C2/4+F/DB1wZsLRnSNimn2Sp/NPsCrsv8ak= golang.org/x/image v0.29.0 h1:HcdsyR4Gsuys/Axh0rDEmlBmB68rW1U9BUdB3UVHsas= golang.org/x/image v0.29.0/go.mod h1:RVJROnf3SLK8d26OW91j4FrIHGbsJ8QnbEocVTOWQDA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -613,39 +569,29 @@ golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8= golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60= golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI= -golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU= +golang.org/x/oauth2 v0.32.0 h1:jsCblLleRMDrxMN29H3z/k1KliIvpLgCkE6R8FXXNgY= +golang.org/x/oauth2 v0.32.0/go.mod h1:lzm5WQJQwKZ3nwavOZ3IS5Aulzxi68dUSgRHujetwEA= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -656,15 +602,12 @@ golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -679,10 +622,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k= @@ -694,14 +634,12 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= -golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= +golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg= +golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -715,16 +653,10 @@ golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= +golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200509030707-2212a7e161a5/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -741,44 +673,30 @@ gonum.org/v1/gonum v0.16.0 h1:5+ul4Swaf3ESvrOnidPp4GZbzf0mxVQpDCYUQE7OJfk= gonum.org/v1/gonum v0.16.0/go.mod h1:fef3am4MQ93R2HHpKnLk4/Tbh/s0+wqD5nfa6Pnwy4E= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5 h1:BIRfGDEjiHRrk0QKZe3Xv2ieMhtgRGeLcZQ0mIVn4EY= -google.golang.org/genproto/googleapis/api v0.0.0-20250825161204-c5933d9347a5/go.mod h1:j3QtIyytwqGr1JUDtYXwtMXWPKsEa5LtzIFN1Wn5WvE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5 h1:eaY8u2EuxbRv7c3NiGK0/NedzVsCcV6hDuU5qPX5EGE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20250825161204-c5933d9347a5/go.mod h1:M4/wBTSeyLxupu3W3tJtOgB14jILAS/XWPSSa3TAlJc= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.75.1 h1:/ODCNEuf9VghjgO3rqLcfg8fiOP0nSluljWFlDxELLI= -google.golang.org/grpc v1.75.1/go.mod h1:JtPAzKiq4v1xcAB2hydNlWI2RnF85XXcV0mhKXr2ecQ= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 h1:tu/dtnW1o3wfaxCOjSLn5IRX4YDcJrtlpzYkhHhGaC4= +google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171/go.mod h1:M5krXqk4GhBKvB596udGL3UyjL4I1+cTbK0orROM9ng= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.78.0 h1:K1XZG/yGDJnzMdd/uZHAkVqJE+xIDOcmdSFZkBUicNc= +google.golang.org/grpc v1.78.0/go.mod h1:I47qjTo4OKbMkjA/aOOwxDIiPSBofUtQUI5EfpWvW7U= google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/evanphx/json-patch.v4 v4.12.0 h1:n6jtcsulIzXPJaxegRbvFNNrZDjbij7ny3gmSPG+6V4= +gopkg.in/evanphx/json-patch.v4 v4.12.0/go.mod h1:p8EYWUEYMpynmqDbY58zCKCFZw8pRWMG4EsWvDvM72M= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/ini.v1 v1.56.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= -gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= +gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= @@ -786,10 +704,28 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q= gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM= +k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk= +k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4= +k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw= +k8s.io/client-go v0.34.1 h1:ZUPJKgXsnKwVwmKKdPfw4tB58+7/Ik3CrjOEhsiZ7mY= +k8s.io/client-go v0.34.1/go.mod h1:kA8v0FP+tk6sZA0yKLRG67LWjqufAoSHA2xVGKw9Of8= +k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= +k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= +k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b h1:MloQ9/bdJyIu9lb1PzujOPolHyvO06MXG5TUIj2mNAA= +k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b/go.mod h1:UZ2yyWbFTpuhSbFhv24aGNOdoRdJZgsIObGBUaYVsts= +k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y= +k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= nhooyr.io/websocket v1.8.17 h1:KEVeLJkUywCKVsnLIDlD/5gtayKp8VoCkksHCGGfT9Y= nhooyr.io/websocket v1.8.17/go.mod h1:rN9OFWIUwuxg4fR5tELlYC04bXYowCP9GX47ivo2l+c= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= +sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= +sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= +sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= +sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/registry/client_test.go b/registry/client_test.go index 534445ea..39d572e6 100644 --- a/registry/client_test.go +++ b/registry/client_test.go @@ -23,8 +23,16 @@ func serverURL() string { } func newClient() *registry.Client { + user := os.Getenv("YAO_REGISTRY_USER") + pass := os.Getenv("YAO_REGISTRY_PASS") + if user == "" { + user = "yaoagents" + } + if pass == "" { + pass = "yaoagents" + } return registry.New(serverURL(), - registry.WithAuth("yaoagents", "yaoagents"), + registry.WithAuth(user, pass), ) } diff --git a/tai/DESIGN.md b/tai/DESIGN.md new file mode 100644 index 00000000..1565fa32 --- /dev/null +++ b/tai/DESIGN.md @@ -0,0 +1,147 @@ +# Tai Go SDK + +Go client library for [Tai](https://github.com/yaoapp/tai) — the universal runtime bridge for Yao Sandbox. + +## Overview + +Provides a unified API for container lifecycle, filesystem operations, HTTP proxy, and VNC access. +Supports two modes via a single entry point: + +- **Local** (`docker://` or `""`) — direct Docker daemon connection +- **Remote** (`tai://host`) — via Tai Server proxy (Docker, K8s) + +All sub-packages follow the same pattern: **interface + Remote/Local implementations**. + +## Package Layout + +``` +yao/tai/ +├── tai.go # Client, New(), Option, Close() +├── volume/ # Volume IO + Sync +├── workspace/ # Go fs.FS wrapper over volume.Volume +├── sandbox/ # Container lifecycle (Create/Start/Stop/Exec/Remove) +│ ├── sandbox.go # Interface + shared types +│ ├── local.go # Direct Docker socket +│ ├── docker.go # Docker via Tai proxy +│ ├── docker_core.go # Shared Docker SDK logic +│ └── k8s.go # Kubernetes via Tai TCP proxy +├── proxy/ # HTTP reverse proxy URL resolution +└── vnc/ # VNC WebSocket URL resolution +``` + +## Quick Start + +```go +import "github.com/yaoapp/yao/tai" + +// Local — default Docker socket +c, _ := tai.New("") + +// Local — explicit address +c, _ := tai.New("docker:///var/run/docker.sock") +c, _ := tai.New("docker://192.168.1.50:2375") + +// Remote — via Tai Server (Docker runtime, default) +c, _ := tai.New("tai://192.168.1.100") + +// Remote — via Tai Server (K8s runtime) +c, _ := tai.New("tai://10.0.0.5", tai.K8s, + tai.WithKubeConfig("/path/to/kubeconfig.yml"), + tai.WithNamespace("sandbox"), +) + +defer c.Close() + +// Container lifecycle +id, _ := c.Sandbox().Create(ctx, sandbox.CreateOptions{ + Image: "node:20", + Cmd: []string{"sleep", "infinity"}, +}) +c.Sandbox().Start(ctx, id) + +// Filesystem +ws := c.Workspace("session-1") +ws.WriteFile("app.js", []byte("console.log('hi')"), 0644) +data, _ := ws.ReadFile("app.js") + +// HTTP proxy URL +url, _ := c.Proxy().URL(ctx, id, 3000, "/api/health") + +// VNC URL +vncURL, _ := c.VNC().URL(ctx, id) +``` + +## Address Protocol + +| Prefix | Mode | Description | +|--------|------|-------------| +| `""` | Local | Platform default Docker socket | +| `docker://...` | Local | Direct Docker daemon (socket or TCP) | +| `tai://host` | Remote | Via Tai Server, all services proxied | + +## Sub-Package Interfaces + +### volume.Volume + +File IO and directory sync between Yao and the container workspace. + +- `ReadFile`, `WriteFile`, `Stat`, `ListDir`, `Remove`, `Rename`, `MkdirAll` +- `SyncPush` (Yao -> Tai), `SyncPull` (Tai -> Yao) +- **Remote**: gRPC to Tai `:9100` +- **Local**: direct disk IO under `dataDir/{sessionID}/` + +### workspace.FS + +Go `fs.FS`-compatible interface wrapping `volume.Volume`, adding write operations. + +### sandbox.Sandbox + +Container lifecycle: `Create`, `Start`, `Stop`, `Remove`, `Exec`, `Inspect`, `List`. + +- **Local**: direct Docker socket, handles VNC port mapping and capabilities +- **Docker**: via Tai `:2375` (Docker Engine API proxy) +- **K8s**: via Tai `:6443` (kube-apiserver TCP proxy, single-container Pod per sandbox) + +### proxy.Proxy + +HTTP service URL resolution: `URL(ctx, containerID, port, path)`. + +- **Remote**: `http://tai-host:8080/{id}:{port}/{path}` +- **Local**: `http://127.0.0.1:{hostPort}/{path}` via `sandbox.Inspect` + +### vnc.VNC + +VNC WebSocket URL resolution: `URL(ctx, containerID)`. + +- **Remote**: `ws://tai-host:6080/vnc/{id}/ws` +- **Local**: `ws://127.0.0.1:{vncHostPort}/ws` via `sandbox.Inspect` + +## Options + +```go +tai.Docker // Docker runtime (default, can omit) +tai.K8s // Kubernetes runtime +tai.WithPorts(Ports{}) // custom port mapping +tai.WithHTTPClient(hc) // custom HTTP client +tai.WithDataDir(dir) // workspace root (Local mode) +tai.WithKubeConfig(path) // kubeconfig file path (K8s runtime) +tai.WithNamespace(ns) // namespace for K8s (default "default") +``` + +## Default Ports + +| Service | Default Port | +|---------|-------------| +| gRPC (Volume + Gateway) | 9100 | +| HTTP Proxy | 8080 | +| VNC Router | 6080 | +| Docker API Proxy | 2375 | +| K8s API Proxy | 6443 | + +## Dependencies + +- `github.com/yaoapp/tai/volume/pb` — gRPC proto types +- `google.golang.org/grpc` +- `github.com/pierrec/lz4/v4` — sync compression +- `github.com/docker/docker` — Docker SDK +- `k8s.io/client-go` + `k8s.io/api` + `k8s.io/apimachinery` — Kubernetes SDK diff --git a/tai/proxy/proxy.go b/tai/proxy/proxy.go new file mode 100644 index 00000000..d74ee8a5 --- /dev/null +++ b/tai/proxy/proxy.go @@ -0,0 +1,92 @@ +package proxy + +import ( + "context" + "fmt" + "net/http" + "strings" + + "github.com/yaoapp/yao/tai/sandbox" +) + +// Proxy resolves HTTP service URLs for containers. +// Remote routes through Tai HTTP proxy; Local resolves host ports directly. +type Proxy interface { + URL(ctx context.Context, containerID string, port int, path string) (string, error) + Healthz(ctx context.Context) error +} + +// --- Remote implementation --- + +type remoteProxy struct { + base string // "http://host:port" + client *http.Client +} + +// NewRemote creates a Proxy that routes through Tai's HTTP proxy. +func NewRemote(host string, port int, hc *http.Client) Proxy { + if hc == nil { + hc = http.DefaultClient + } + return &remoteProxy{ + base: fmt.Sprintf("http://%s:%d", host, port), + client: hc, + } +} + +func (r *remoteProxy) URL(_ context.Context, containerID string, port int, path string) (string, error) { + path = strings.TrimPrefix(path, "/") + return fmt.Sprintf("%s/%s:%d/%s", r.base, containerID, port, path), nil +} + +func (r *remoteProxy) Healthz(ctx context.Context) error { + req, err := http.NewRequestWithContext(ctx, http.MethodGet, r.base+"/healthz", nil) + if err != nil { + return err + } + resp, err := r.client.Do(req) + if err != nil { + return err + } + resp.Body.Close() + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("healthz: status %d", resp.StatusCode) + } + return nil +} + +// --- Local implementation --- + +type localProxy struct { + sb sandbox.Sandbox +} + +// NewLocal creates a Proxy that resolves host ports via sandbox.Inspect. +func NewLocal(sb sandbox.Sandbox) Proxy { + return &localProxy{sb: sb} +} + +func (l *localProxy) URL(ctx context.Context, containerID string, port int, path string) (string, error) { + info, err := l.sb.Inspect(ctx, containerID) + if err != nil { + return "", fmt.Errorf("inspect: %w", err) + } + for _, p := range info.Ports { + if p.ContainerPort == port && p.HostPort != 0 { + path = strings.TrimPrefix(path, "/") + return fmt.Sprintf("http://%s:%d/%s", hostIP(p.HostIP), p.HostPort, path), nil + } + } + return "", fmt.Errorf("port %d not mapped for container %s", port, containerID) +} + +func (l *localProxy) Healthz(_ context.Context) error { + return nil +} + +func hostIP(ip string) string { + if ip == "" { + return "127.0.0.1" + } + return ip +} diff --git a/tai/proxy/proxy_test.go b/tai/proxy/proxy_test.go new file mode 100644 index 00000000..e988897c --- /dev/null +++ b/tai/proxy/proxy_test.go @@ -0,0 +1,166 @@ +package proxy + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/yaoapp/yao/tai/sandbox" +) + +func TestRemoteURL(t *testing.T) { + p := NewRemote("10.0.0.1", 8080, nil) + ctx := context.Background() + + url, err := p.URL(ctx, "abc123", 3000, "/api/health") + if err != nil { + t.Fatalf("URL: %v", err) + } + want := "http://10.0.0.1:8080/abc123:3000/api/health" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestRemoteURLNoLeadingSlash(t *testing.T) { + p := NewRemote("host", 8080, nil) + ctx := context.Background() + + url, _ := p.URL(ctx, "id", 80, "path") + want := "http://host:8080/id:80/path" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestRemoteHealthz(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/healthz" { + w.WriteHeader(http.StatusOK) + return + } + w.WriteHeader(http.StatusNotFound) + })) + defer srv.Close() + + // parse host and port from srv.URL + p := &remoteProxy{base: srv.URL, client: srv.Client()} + + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + defer cancel() + if err := p.Healthz(ctx); err != nil { + t.Fatalf("Healthz: %v", err) + } +} + +func TestRemoteHealthzFail(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusServiceUnavailable) + })) + defer srv.Close() + + p := &remoteProxy{base: srv.URL, client: srv.Client()} + if err := p.Healthz(context.Background()); err == nil { + t.Error("expected error for 503") + } +} + +func TestLocalURL(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ + ID: id, + Ports: []sandbox.PortMapping{ + {ContainerPort: 3000, HostPort: 32768, HostIP: "127.0.0.1", Protocol: "tcp"}, + {ContainerPort: 8080, HostPort: 32769, HostIP: "127.0.0.1", Protocol: "tcp"}, + }, + }, nil + }, + } + + p := NewLocal(mock) + ctx := context.Background() + + url, err := p.URL(ctx, "c1", 3000, "/api") + if err != nil { + t.Fatalf("URL: %v", err) + } + want := "http://127.0.0.1:32768/api" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestLocalURLPortNotFound(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ID: id}, nil + }, + } + + p := NewLocal(mock) + _, err := p.URL(context.Background(), "c1", 9999, "/") + if err == nil { + t.Error("expected error for unmapped port") + } +} + +func TestLocalURLInspectError(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return nil, fmt.Errorf("not found") + }, + } + + p := NewLocal(mock) + _, err := p.URL(context.Background(), "c1", 80, "/") + if err == nil { + t.Error("expected error for inspect failure") + } +} + +func TestLocalHealthz(t *testing.T) { + p := NewLocal(&mockSandbox{}) + if err := p.Healthz(context.Background()); err != nil { + t.Errorf("Healthz should return nil: %v", err) + } +} + +func TestHostIP(t *testing.T) { + if got := hostIP(""); got != "127.0.0.1" { + t.Errorf("hostIP empty = %q", got) + } + if got := hostIP("10.0.0.1"); got != "10.0.0.1" { + t.Errorf("hostIP explicit = %q", got) + } +} + +// mockSandbox implements sandbox.Sandbox for testing. +type mockSandbox struct { + inspectFn func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) +} + +func (m *mockSandbox) Create(ctx context.Context, opts sandbox.CreateOptions) (string, error) { + return "", nil +} +func (m *mockSandbox) Start(ctx context.Context, id string) error { return nil } +func (m *mockSandbox) Stop(ctx context.Context, id string, timeout time.Duration) error { + return nil +} +func (m *mockSandbox) Remove(ctx context.Context, id string, force bool) error { return nil } +func (m *mockSandbox) Exec(ctx context.Context, id string, cmd []string, opts sandbox.ExecOptions) (*sandbox.ExecResult, error) { + return nil, nil +} +func (m *mockSandbox) Inspect(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + if m.inspectFn != nil { + return m.inspectFn(ctx, id) + } + return &sandbox.ContainerInfo{ID: id}, nil +} +func (m *mockSandbox) List(ctx context.Context, opts sandbox.ListOptions) ([]sandbox.ContainerInfo, error) { + return nil, nil +} +func (m *mockSandbox) Close() error { return nil } diff --git a/tai/sandbox/docker.go b/tai/sandbox/docker.go new file mode 100644 index 00000000..93fd7c6f --- /dev/null +++ b/tai/sandbox/docker.go @@ -0,0 +1,64 @@ +package sandbox + +import ( + "context" + "fmt" + "time" + + "github.com/docker/docker/client" +) + +type dockerSandbox struct { + core dockerCore +} + +// NewDocker creates a Sandbox backed by Docker SDK through Tai's Docker API proxy. +// addr should be "tcp://tai-host:2375". +func NewDocker(addr string) (Sandbox, error) { + cli, err := client.NewClientWithOpts( + client.WithHost(addr), + client.WithAPIVersionNegotiation(), + ) + if err != nil { + return nil, fmt.Errorf("docker client: %w", err) + } + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if _, err := cli.Ping(ctx); err != nil { + cli.Close() + return nil, fmt.Errorf("docker via tai: %w", err) + } + return &dockerSandbox{core: dockerCore{cli: cli}}, nil +} + +func (d *dockerSandbox) Create(ctx context.Context, opts CreateOptions) (string, error) { + return d.core.create(ctx, opts, false) +} + +func (d *dockerSandbox) Start(ctx context.Context, id string) error { + return d.core.start(ctx, id) +} + +func (d *dockerSandbox) Stop(ctx context.Context, id string, timeout time.Duration) error { + return d.core.stop(ctx, id, int(timeout.Seconds())) +} + +func (d *dockerSandbox) Remove(ctx context.Context, id string, force bool) error { + return d.core.remove(ctx, id, force) +} + +func (d *dockerSandbox) Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) { + return d.core.exec(ctx, id, cmd, opts) +} + +func (d *dockerSandbox) Inspect(ctx context.Context, id string) (*ContainerInfo, error) { + return d.core.inspect(ctx, id) +} + +func (d *dockerSandbox) List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) { + return d.core.list(ctx, opts) +} + +func (d *dockerSandbox) Close() error { + return d.core.cli.Close() +} diff --git a/tai/sandbox/docker_core.go b/tai/sandbox/docker_core.go new file mode 100644 index 00000000..beeb8893 --- /dev/null +++ b/tai/sandbox/docker_core.go @@ -0,0 +1,211 @@ +package sandbox + +import ( + "bytes" + "context" + "fmt" + "io" + "strconv" + "strings" + + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/client" + "github.com/docker/docker/pkg/stdcopy" + "github.com/docker/go-connections/nat" +) + +// dockerCore contains Docker SDK operations shared by both Local and Docker (via Tai) sandboxes. +type dockerCore struct { + cli *client.Client +} + +func (d *dockerCore) create(ctx context.Context, opts CreateOptions, addVNCPorts bool) (string, error) { + cfg := &container.Config{ + Image: opts.Image, + Cmd: opts.Cmd, + Env: envSlice(opts.Env), + WorkingDir: opts.WorkingDir, + } + + hostCfg := &container.HostConfig{ + Binds: opts.Binds, + } + + if opts.Memory > 0 { + hostCfg.Resources.Memory = opts.Memory + } + if opts.CPUs > 0 { + hostCfg.Resources.NanoCPUs = int64(opts.CPUs * 1e9) + } + + exposedPorts := nat.PortSet{} + portBindings := nat.PortMap{} + for _, p := range opts.Ports { + cp := nat.Port(fmt.Sprintf("%d/%s", p.ContainerPort, proto(p.Protocol))) + exposedPorts[cp] = struct{}{} + portBindings[cp] = []nat.PortBinding{{ + HostIP: hostIP(p.HostIP), + HostPort: portStr(p.HostPort), + }} + } + + if opts.VNC { + hostCfg.CapAdd = append(hostCfg.CapAdd, "SYS_ADMIN") + shmSize := opts.Memory / 4 + if shmSize < 256*1024*1024 { + shmSize = 256 * 1024 * 1024 + } + hostCfg.ShmSize = shmSize + cfg.Env = append(cfg.Env, "SANDBOX_VNC_ENABLED=true") + + if addVNCPorts { + for _, p := range []int{6080, 5900} { + cp := nat.Port(fmt.Sprintf("%d/tcp", p)) + exposedPorts[cp] = struct{}{} + portBindings[cp] = []nat.PortBinding{{HostIP: "127.0.0.1", HostPort: ""}} + } + } + } + + if len(exposedPorts) > 0 { + cfg.ExposedPorts = exposedPorts + hostCfg.PortBindings = portBindings + } + + resp, err := d.cli.ContainerCreate(ctx, cfg, hostCfg, nil, nil, opts.Name) + if err != nil { + return "", fmt.Errorf("create: %w", err) + } + return resp.ID, nil +} + +func (d *dockerCore) start(ctx context.Context, id string) error { + return d.cli.ContainerStart(ctx, id, container.StartOptions{}) +} + +func (d *dockerCore) stop(ctx context.Context, id string, timeoutSec int) error { + return d.cli.ContainerStop(ctx, id, container.StopOptions{Timeout: &timeoutSec}) +} + +func (d *dockerCore) remove(ctx context.Context, id string, force bool) error { + return d.cli.ContainerRemove(ctx, id, container.RemoveOptions{Force: force, RemoveVolumes: true}) +} + +func (d *dockerCore) exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) { + execCfg := container.ExecOptions{ + Cmd: cmd, + WorkingDir: opts.WorkDir, + Env: envSlice(opts.Env), + AttachStdout: true, + AttachStderr: true, + } + + execResp, err := d.cli.ContainerExecCreate(ctx, id, execCfg) + if err != nil { + return nil, fmt.Errorf("exec create: %w", err) + } + + resp, err := d.cli.ContainerExecAttach(ctx, execResp.ID, container.ExecAttachOptions{}) + if err != nil { + return nil, fmt.Errorf("exec attach: %w", err) + } + defer resp.Close() + + var stdout, stderr bytes.Buffer + if _, err := stdcopy.StdCopy(&stdout, &stderr, resp.Reader); err != nil && err != io.EOF { + return nil, fmt.Errorf("exec read: %w", err) + } + + inspect, err := d.cli.ContainerExecInspect(ctx, execResp.ID) + if err != nil { + return nil, fmt.Errorf("exec inspect: %w", err) + } + + return &ExecResult{ + ExitCode: inspect.ExitCode, + Stdout: stdout.String(), + Stderr: stderr.String(), + }, nil +} + +func (d *dockerCore) inspect(ctx context.Context, id string) (*ContainerInfo, error) { + info, err := d.cli.ContainerInspect(ctx, id) + if err != nil { + return nil, err + } + + ci := &ContainerInfo{ + ID: info.ID, + Name: strings.TrimPrefix(info.Name, "/"), + Image: info.Config.Image, + Status: info.State.Status, + } + + if info.NetworkSettings != nil { + for _, net := range info.NetworkSettings.Networks { + if net.IPAddress != "" { + ci.IP = net.IPAddress + break + } + } + for portProto, bindings := range info.NetworkSettings.Ports { + parts := strings.SplitN(string(portProto), "/", 2) + cp, _ := strconv.Atoi(parts[0]) + protocol := "tcp" + if len(parts) > 1 { + protocol = parts[1] + } + for _, b := range bindings { + hp, _ := strconv.Atoi(b.HostPort) + ci.Ports = append(ci.Ports, PortMapping{ + ContainerPort: cp, + HostPort: hp, + HostIP: b.HostIP, + Protocol: protocol, + }) + } + } + } + return ci, nil +} + +func (d *dockerCore) list(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) { + listOpts := container.ListOptions{All: opts.All} + if len(opts.Labels) > 0 { + f := filters.NewArgs() + for k, v := range opts.Labels { + f.Add("label", k+"="+v) + } + listOpts.Filters = f + } + + containers, err := d.cli.ContainerList(ctx, listOpts) + if err != nil { + return nil, err + } + + result := make([]ContainerInfo, 0, len(containers)) + for _, c := range containers { + name := "" + if len(c.Names) > 0 { + name = strings.TrimPrefix(c.Names[0], "/") + } + ci := ContainerInfo{ + ID: c.ID, + Name: name, + Image: c.Image, + Status: c.State, + } + for _, p := range c.Ports { + ci.Ports = append(ci.Ports, PortMapping{ + ContainerPort: int(p.PrivatePort), + HostPort: int(p.PublicPort), + HostIP: p.IP, + Protocol: p.Type, + }) + } + result = append(result, ci) + } + return result, nil +} diff --git a/tai/sandbox/k8s.go b/tai/sandbox/k8s.go new file mode 100644 index 00000000..bf93bdb1 --- /dev/null +++ b/tai/sandbox/k8s.go @@ -0,0 +1,298 @@ +package sandbox + +import ( + "bytes" + "context" + "fmt" + "path/filepath" + "strings" + "time" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" + apiresource "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/kubernetes/scheme" + "k8s.io/client-go/rest" + "k8s.io/client-go/tools/clientcmd" + "k8s.io/client-go/tools/remotecommand" +) + +// K8sOption configures a K8s sandbox. +type K8sOption struct { + Namespace string // default "default" + KubeConfig string // path to kubeconfig file +} + +type k8sSandbox struct { + cli kubernetes.Interface + cfg *rest.Config + ns string + labels map[string]string +} + +// NewK8s creates a Sandbox backed by Kubernetes via Tai's TCP proxy. +// addr should be "host:port" pointing to Tai's K8s proxy endpoint. +// kubeConfigPath must be an absolute path or will be resolved relative to the caller's working directory. +func NewK8s(addr string, opts ...K8sOption) (Sandbox, error) { + ns := "default" + var kubeConfigPath string + if len(opts) > 0 { + if opts[0].Namespace != "" { + ns = opts[0].Namespace + } + if opts[0].KubeConfig != "" { + kubeConfigPath = opts[0].KubeConfig + if !filepath.IsAbs(kubeConfigPath) { + abs, err := filepath.Abs(kubeConfigPath) + if err != nil { + return nil, fmt.Errorf("resolve kubeconfig path: %w", err) + } + kubeConfigPath = abs + } + } + } + + if kubeConfigPath == "" { + return nil, fmt.Errorf("kubeconfig path is required for K8s sandbox") + } + + cfg, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath) + if err != nil { + return nil, fmt.Errorf("build kubeconfig: %w", err) + } + + // Override the server address to point at the Tai proxy + if addr != "" { + cfg.Host = "https://" + addr + // When connecting through Tai TCP proxy, skip TLS verification + cfg.TLSClientConfig.Insecure = true + cfg.TLSClientConfig.CAData = nil + cfg.TLSClientConfig.CAFile = "" + } + + cli, err := kubernetes.NewForConfig(cfg) + if err != nil { + return nil, fmt.Errorf("create k8s client: %w", err) + } + + // Verify connectivity + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + _, err = cli.CoreV1().Namespaces().Get(ctx, ns, metav1.GetOptions{}) + if err != nil && !errors.IsNotFound(err) { + return nil, fmt.Errorf("k8s connectivity check: %w", err) + } + + return &k8sSandbox{ + cli: cli, + cfg: cfg, + ns: ns, + labels: map[string]string{ + "managed-by": "yao-tai-sdk", + }, + }, nil +} + +func (s *k8sSandbox) Create(ctx context.Context, opts CreateOptions) (string, error) { + name := opts.Name + if name == "" { + name = fmt.Sprintf("sandbox-%d", time.Now().UnixNano()) + } + // K8s names must be DNS-compatible + name = strings.ToLower(name) + name = strings.ReplaceAll(name, "_", "-") + + envVars := make([]corev1.EnvVar, 0, len(opts.Env)) + for k, v := range opts.Env { + envVars = append(envVars, corev1.EnvVar{Name: k, Value: v}) + } + + container := corev1.Container{ + Name: "main", + Image: opts.Image, + Command: opts.Cmd, + Env: envVars, + WorkingDir: opts.WorkingDir, + } + + if opts.Memory > 0 || opts.CPUs > 0 { + container.Resources = buildResources(opts.Memory, opts.CPUs) + } + + labels := make(map[string]string) + for k, v := range s.labels { + labels[k] = v + } + labels["sandbox-name"] = name + + pod := &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: name, + Namespace: s.ns, + Labels: labels, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{container}, + RestartPolicy: corev1.RestartPolicyNever, + }, + } + + created, err := s.cli.CoreV1().Pods(s.ns).Create(ctx, pod, metav1.CreateOptions{}) + if err != nil { + return "", fmt.Errorf("create pod: %w", err) + } + return created.Name, nil +} + +func (s *k8sSandbox) Start(ctx context.Context, id string) error { + // K8s pods start automatically after creation. + // Wait briefly for the pod to leave Pending. + for i := 0; i < 30; i++ { + pod, err := s.cli.CoreV1().Pods(s.ns).Get(ctx, id, metav1.GetOptions{}) + if err != nil { + return fmt.Errorf("get pod: %w", err) + } + if pod.Status.Phase == corev1.PodRunning || pod.Status.Phase == corev1.PodSucceeded || pod.Status.Phase == corev1.PodFailed { + return nil + } + time.Sleep(1 * time.Second) + } + return fmt.Errorf("pod %s did not reach Running within 30s", id) +} + +func (s *k8sSandbox) Stop(ctx context.Context, id string, timeout time.Duration) error { + secs := int64(timeout.Seconds()) + return s.cli.CoreV1().Pods(s.ns).Delete(ctx, id, metav1.DeleteOptions{ + GracePeriodSeconds: &secs, + }) +} + +func (s *k8sSandbox) Remove(ctx context.Context, id string, force bool) error { + opts := metav1.DeleteOptions{} + if force { + zero := int64(0) + opts.GracePeriodSeconds = &zero + } + err := s.cli.CoreV1().Pods(s.ns).Delete(ctx, id, opts) + if errors.IsNotFound(err) { + return nil + } + return err +} + +func (s *k8sSandbox) Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) { + execCmd := cmd + if opts.WorkDir != "" || len(opts.Env) > 0 { + var prefix string + for k, v := range opts.Env { + prefix += fmt.Sprintf("export %s=%q; ", k, v) + } + cdPart := "" + if opts.WorkDir != "" { + cdPart = fmt.Sprintf("cd %s && ", opts.WorkDir) + } + execCmd = []string{"sh", "-c", cdPart + prefix + strings.Join(cmd, " ")} + } + + req := s.cli.CoreV1().RESTClient().Post(). + Resource("pods"). + Name(id). + Namespace(s.ns). + SubResource("exec"). + VersionedParams(&corev1.PodExecOptions{ + Container: "main", + Command: execCmd, + Stdout: true, + Stderr: true, + }, scheme.ParameterCodec) + + exec, err := remotecommand.NewSPDYExecutor(s.cfg, "POST", req.URL()) + if err != nil { + return nil, fmt.Errorf("create executor: %w", err) + } + + var stdout, stderr bytes.Buffer + err = exec.StreamWithContext(ctx, remotecommand.StreamOptions{ + Stdout: &stdout, + Stderr: &stderr, + }) + + exitCode := 0 + if err != nil { + if exitErr, ok := err.(interface{ ExitStatus() int }); ok { + exitCode = exitErr.ExitStatus() + err = nil + } else { + return nil, fmt.Errorf("exec stream: %w", err) + } + } + + return &ExecResult{ + ExitCode: exitCode, + Stdout: stdout.String(), + Stderr: stderr.String(), + }, nil +} + +func (s *k8sSandbox) Inspect(ctx context.Context, id string) (*ContainerInfo, error) { + pod, err := s.cli.CoreV1().Pods(s.ns).Get(ctx, id, metav1.GetOptions{}) + if err != nil { + return nil, err + } + + return &ContainerInfo{ + ID: string(pod.UID), + Name: pod.Name, + Image: pod.Spec.Containers[0].Image, + Status: string(pod.Status.Phase), + IP: pod.Status.PodIP, + }, nil +} + +func (s *k8sSandbox) List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) { + labelSelector := "managed-by=yao-tai-sdk" + if len(opts.Labels) > 0 { + for k, v := range opts.Labels { + labelSelector += "," + k + "=" + v + } + } + + pods, err := s.cli.CoreV1().Pods(s.ns).List(ctx, metav1.ListOptions{ + LabelSelector: labelSelector, + }) + if err != nil { + return nil, err + } + + result := make([]ContainerInfo, 0, len(pods.Items)) + for _, pod := range pods.Items { + ci := ContainerInfo{ + ID: string(pod.UID), + Name: pod.Name, + Status: string(pod.Status.Phase), + IP: pod.Status.PodIP, + } + if len(pod.Spec.Containers) > 0 { + ci.Image = pod.Spec.Containers[0].Image + } + result = append(result, ci) + } + return result, nil +} + +func (s *k8sSandbox) Close() error { + return nil // REST client doesn't need explicit close +} + +func buildResources(memory int64, cpus float64) corev1.ResourceRequirements { + limits := corev1.ResourceList{} + if memory > 0 { + limits[corev1.ResourceMemory] = *apiresource.NewQuantity(memory, apiresource.BinarySI) + } + if cpus > 0 { + limits[corev1.ResourceCPU] = *apiresource.NewMilliQuantity(int64(cpus*1000), apiresource.DecimalSI) + } + return corev1.ResourceRequirements{Limits: limits} +} diff --git a/tai/sandbox/local.go b/tai/sandbox/local.go new file mode 100644 index 00000000..e9c5a709 --- /dev/null +++ b/tai/sandbox/local.go @@ -0,0 +1,81 @@ +package sandbox + +import ( + "context" + "fmt" + "runtime" + "time" + + "github.com/docker/docker/client" +) + +type local struct { + core dockerCore +} + +// NewLocal creates a Sandbox backed by a direct Docker daemon connection. +// addr can be "unix:///var/run/docker.sock", "tcp://host:port", or "" for platform default. +func NewLocal(addr string) (Sandbox, error) { + opts := []client.Opt{client.WithAPIVersionNegotiation()} + if addr != "" { + opts = append(opts, client.WithHost(addr)) + } else { + opts = append(opts, client.FromEnv) + } + cli, err := client.NewClientWithOpts(opts...) + if err != nil { + return nil, fmt.Errorf("docker client: %w", err) + } + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + if _, err := cli.Ping(ctx); err != nil { + cli.Close() + return nil, fmt.Errorf("docker ping: %w", err) + } + return &local{core: dockerCore{cli: cli}}, nil +} + +func (l *local) Create(ctx context.Context, opts CreateOptions) (string, error) { + return l.core.create(ctx, opts, opts.VNC && needsPortMapping()) +} + +func (l *local) Start(ctx context.Context, id string) error { + return l.core.start(ctx, id) +} + +func (l *local) Stop(ctx context.Context, id string, timeout time.Duration) error { + return l.core.stop(ctx, id, int(timeout.Seconds())) +} + +func (l *local) Remove(ctx context.Context, id string, force bool) error { + return l.core.remove(ctx, id, force) +} + +func (l *local) Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) { + return l.core.exec(ctx, id, cmd, opts) +} + +func (l *local) Inspect(ctx context.Context, id string) (*ContainerInfo, error) { + return l.core.inspect(ctx, id) +} + +func (l *local) List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) { + return l.core.list(ctx, opts) +} + +func (l *local) Close() error { + return l.core.cli.Close() +} + +// needsPortMapping returns true on platforms where container IPs are not +// directly reachable (macOS Docker Desktop, Windows). +func needsPortMapping() bool { + return runtime.GOOS == "darwin" || runtime.GOOS == "windows" +} + +func portStr(p int) string { + if p == 0 { + return "" + } + return fmt.Sprintf("%d", p) +} diff --git a/tai/sandbox/sandbox.go b/tai/sandbox/sandbox.go new file mode 100644 index 00000000..368ddcf0 --- /dev/null +++ b/tai/sandbox/sandbox.go @@ -0,0 +1,95 @@ +package sandbox + +import ( + "context" + "time" +) + +// Sandbox manages container lifecycle. +// Local connects directly to a Docker daemon; Docker/Containerd/K8s connect via Tai proxy. +type Sandbox interface { + Create(ctx context.Context, opts CreateOptions) (string, error) + Start(ctx context.Context, id string) error + Stop(ctx context.Context, id string, timeout time.Duration) error + Remove(ctx context.Context, id string, force bool) error + Exec(ctx context.Context, id string, cmd []string, opts ExecOptions) (*ExecResult, error) + Inspect(ctx context.Context, id string) (*ContainerInfo, error) + List(ctx context.Context, opts ListOptions) ([]ContainerInfo, error) + Close() error +} + +// CreateOptions configures a new container. +type CreateOptions struct { + Name string + Image string + Cmd []string + Env map[string]string + Binds []string + WorkingDir string + Memory int64 // bytes, 0 = no limit + CPUs float64 // 0 = no limit + VNC bool + Ports []PortMapping +} + +// PortMapping maps a container port to a host port. +type PortMapping struct { + ContainerPort int + HostPort int // 0 = random + HostIP string // default "127.0.0.1" + Protocol string // "tcp" (default) or "udp" +} + +// ContainerInfo describes a running or stopped container. +type ContainerInfo struct { + ID string + Name string + Image string + Status string // "created", "running", "exited", "removing" + IP string + Ports []PortMapping +} + +// ExecOptions configures a command execution inside a container. +type ExecOptions struct { + WorkDir string + Env map[string]string +} + +// ExecResult holds output from an exec command. +type ExecResult struct { + ExitCode int + Stdout string + Stderr string +} + +// ListOptions filters container listing. +type ListOptions struct { + All bool // include stopped containers + Labels map[string]string // filter by labels +} + +func envSlice(m map[string]string) []string { + if len(m) == 0 { + return nil + } + s := make([]string, 0, len(m)) + for k, v := range m { + s = append(s, k+"="+v) + } + return s +} + +func proto(p string) string { + if p == "" { + return "tcp" + } + return p +} + +func hostIP(ip string) string { + if ip == "" { + return "127.0.0.1" + } + return ip +} diff --git a/tai/sandbox/sandbox_test.go b/tai/sandbox/sandbox_test.go new file mode 100644 index 00000000..061ff982 --- /dev/null +++ b/tai/sandbox/sandbox_test.go @@ -0,0 +1,627 @@ +package sandbox + +import ( + "context" + "os" + "testing" + "time" + + corev1 "k8s.io/api/core/v1" +) + +func taiTestDocker() string { + if addr := os.Getenv("TAI_TEST_DOCKER"); addr != "" { + return addr + } + return "tcp://127.0.0.1:2375" +} + +func taiTestK8sHost() string { return os.Getenv("TAI_TEST_K8S_HOST") } +func taiTestK8sPort() string { return os.Getenv("TAI_TEST_K8S_PORT") } + +func taiTestKubeConfig() string { return os.Getenv("TAI_TEST_KUBECONFIG") } + +func TestHelpers(t *testing.T) { + t.Run("envSlice", func(t *testing.T) { + if got := envSlice(nil); got != nil { + t.Errorf("envSlice(nil) = %v", got) + } + s := envSlice(map[string]string{"A": "1", "B": "2"}) + if len(s) != 2 { + t.Errorf("len = %d, want 2", len(s)) + } + }) + + t.Run("proto", func(t *testing.T) { + if got := proto(""); got != "tcp" { + t.Errorf("proto empty = %q", got) + } + if got := proto("udp"); got != "udp" { + t.Errorf("proto udp = %q", got) + } + }) + + t.Run("hostIP", func(t *testing.T) { + if got := hostIP(""); got != "127.0.0.1" { + t.Errorf("hostIP empty = %q", got) + } + if got := hostIP("10.0.0.1"); got != "10.0.0.1" { + t.Errorf("hostIP explicit = %q", got) + } + }) +} + +func TestLocalSandbox(t *testing.T) { + sb, err := NewLocal("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + var containerID string + + t.Run("Create", func(t *testing.T) { + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-sdk-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "30"}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + if id == "" { + t.Fatal("expected non-empty ID") + } + containerID = id + }) + + t.Run("Start", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + if err := sb.Start(ctx, containerID); err != nil { + t.Fatalf("Start: %v", err) + } + }) + + t.Run("Inspect", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + info, err := sb.Inspect(ctx, containerID) + if err != nil { + t.Fatalf("Inspect: %v", err) + } + if info.Status != "running" { + t.Errorf("status = %q, want running", info.Status) + } + if info.Image != "alpine:latest" { + t.Errorf("image = %q", info.Image) + } + }) + + t.Run("Exec", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + result, err := sb.Exec(ctx, containerID, []string{"echo", "hello"}, ExecOptions{}) + if err != nil { + t.Fatalf("Exec: %v", err) + } + if result.ExitCode != 0 { + t.Errorf("exitCode = %d", result.ExitCode) + } + if result.Stdout != "hello\n" { + t.Errorf("stdout = %q, want %q", result.Stdout, "hello\n") + } + }) + + t.Run("List", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + containers, err := sb.List(ctx, ListOptions{All: true}) + if err != nil { + t.Fatalf("List: %v", err) + } + found := false + for _, c := range containers { + if c.ID == containerID { + found = true + break + } + } + if !found { + t.Error("container not found in list") + } + }) + + t.Run("Stop", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + if err := sb.Stop(ctx, containerID, 5*time.Second); err != nil { + t.Fatalf("Stop: %v", err) + } + }) + + t.Run("Remove", func(t *testing.T) { + if containerID == "" { + t.Skip("no container") + } + if err := sb.Remove(ctx, containerID, true); err != nil { + t.Fatalf("Remove: %v", err) + } + }) +} + +func TestLocalCreateWithPorts(t *testing.T) { + sb, err := NewLocal("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-sdk-port-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "5"}, + Memory: 64 * 1024 * 1024, + CPUs: 0.5, + Ports: []PortMapping{ + {ContainerPort: 8080, HostPort: 0, Protocol: "tcp"}, + }, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + defer sb.Remove(ctx, id, true) + + if err := sb.Start(ctx, id); err != nil { + t.Fatalf("Start: %v", err) + } + + info, err := sb.Inspect(ctx, id) + if err != nil { + t.Fatalf("Inspect: %v", err) + } + + found := false + for _, p := range info.Ports { + if p.ContainerPort == 8080 { + found = true + if p.HostPort == 0 { + t.Error("HostPort should be resolved") + } + } + } + if !found { + t.Error("port 8080 not in Ports") + } +} + +func TestLocalCreateWithVNC(t *testing.T) { + sb, err := NewLocal("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-sdk-vnc-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "5"}, + Memory: 512 * 1024 * 1024, + VNC: true, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + defer sb.Remove(ctx, id, true) +} + +func TestLocalCreateWithEnvAndWorkDir(t *testing.T) { + sb, err := NewLocal("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-sdk-env-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "5"}, + WorkingDir: "/tmp", + Env: map[string]string{"FOO": "bar"}, + Binds: []string{}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + defer sb.Remove(ctx, id, true) + + if err := sb.Start(ctx, id); err != nil { + t.Fatalf("Start: %v", err) + } + result, err := sb.Exec(ctx, id, []string{"printenv", "FOO"}, ExecOptions{WorkDir: "/tmp"}) + if err != nil { + t.Fatalf("Exec: %v", err) + } + if result.Stdout != "bar\n" { + t.Errorf("FOO = %q, want %q", result.Stdout, "bar\n") + } +} + +func TestDockerSandboxViaTai(t *testing.T) { + addr := taiTestDocker() + sb, err := NewDocker(addr) + if err != nil { + t.Skipf("Tai Docker proxy not available at %s: %v", addr, err) + } + defer sb.Close() + + ctx := context.Background() + + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-docker-proxy-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "10"}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + defer sb.Remove(ctx, id, true) + + if err := sb.Start(ctx, id); err != nil { + t.Fatalf("Start: %v", err) + } + + info, err := sb.Inspect(ctx, id) + if err != nil { + t.Fatalf("Inspect: %v", err) + } + if info.Status != "running" { + t.Errorf("status = %q", info.Status) + } + + result, err := sb.Exec(ctx, id, []string{"echo", "via-tai"}, ExecOptions{}) + if err != nil { + t.Fatalf("Exec: %v", err) + } + if result.Stdout != "via-tai\n" { + t.Errorf("stdout = %q", result.Stdout) + } + + containers, err := sb.List(ctx, ListOptions{All: true}) + if err != nil { + t.Fatalf("List: %v", err) + } + found := false + for _, c := range containers { + if c.ID == id { + found = true + } + } + if !found { + t.Error("container not in list") + } + + if err := sb.Stop(ctx, id, 5*time.Second); err != nil { + t.Fatalf("Stop: %v", err) + } +} + +func TestListWithLabels(t *testing.T) { + sb, err := NewLocal("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer sb.Close() + + // List with non-matching labels should return empty + result, err := sb.List(context.Background(), ListOptions{ + Labels: map[string]string{"tai-test-nonexist": "true"}, + }) + if err != nil { + t.Fatalf("List: %v", err) + } + if len(result) != 0 { + t.Errorf("expected 0, got %d", len(result)) + } +} + +func TestNewLocalInvalidAddr(t *testing.T) { + _, err := NewLocal("tcp://192.168.254.254:1") + if err == nil { + t.Error("expected error for unreachable Docker") + } +} + +func TestPortStr(t *testing.T) { + if got := portStr(0); got != "" { + t.Errorf("portStr(0) = %q", got) + } + if got := portStr(8080); got != "8080" { + t.Errorf("portStr(8080) = %q", got) + } +} + +func TestK8sSandbox(t *testing.T) { + host := taiTestK8sHost() + port := taiTestK8sPort() + kubeconfig := taiTestKubeConfig() + if host == "" || port == "" || kubeconfig == "" { + t.Skip("TAI_TEST_K8S_HOST, TAI_TEST_K8S_PORT, or TAI_TEST_KUBECONFIG not set") + } + + addr := host + ":" + port + sb, err := NewK8s(addr, K8sOption{ + Namespace: "default", + KubeConfig: kubeconfig, + }) + if err != nil { + t.Skipf("K8s not available at %s: %v", addr, err) + } + defer sb.Close() + + ctx := context.Background() + var podName string + + t.Run("Create", func(t *testing.T) { + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-k8s-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "60"}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + if id == "" { + t.Fatal("expected non-empty name") + } + podName = id + }) + + t.Run("Start", func(t *testing.T) { + if podName == "" { + t.Skip("no pod") + } + if err := sb.Start(ctx, podName); err != nil { + t.Fatalf("Start (wait for Running): %v", err) + } + }) + + t.Run("Inspect", func(t *testing.T) { + if podName == "" { + t.Skip("no pod") + } + info, err := sb.Inspect(ctx, podName) + if err != nil { + t.Fatalf("Inspect: %v", err) + } + if info.Status != "Running" { + t.Errorf("status = %q, want Running", info.Status) + } + if info.Image != "alpine:latest" { + t.Errorf("image = %q", info.Image) + } + }) + + t.Run("Exec", func(t *testing.T) { + if podName == "" { + t.Skip("no pod") + } + result, err := sb.Exec(ctx, podName, []string{"echo", "k8s-hello"}, ExecOptions{}) + if err != nil { + t.Fatalf("Exec: %v", err) + } + if result.ExitCode != 0 { + t.Errorf("exitCode = %d", result.ExitCode) + } + if result.Stdout != "k8s-hello\n" { + t.Errorf("stdout = %q", result.Stdout) + } + }) + + t.Run("List", func(t *testing.T) { + if podName == "" { + t.Skip("no pod") + } + pods, err := sb.List(ctx, ListOptions{}) + if err != nil { + t.Fatalf("List: %v", err) + } + found := false + for _, p := range pods { + if p.Name == podName { + found = true + break + } + } + if !found { + t.Error("pod not found in list") + } + }) + + t.Run("Remove", func(t *testing.T) { + if podName == "" { + t.Skip("no pod") + } + if err := sb.Remove(ctx, podName, true); err != nil { + t.Fatalf("Remove: %v", err) + } + }) +} + +func TestNewK8sMissingKubeConfig(t *testing.T) { + _, err := NewK8s("127.0.0.1:6443") + if err == nil { + t.Error("expected error for missing kubeconfig") + } +} + +func TestNewK8sBadKubeConfig(t *testing.T) { + _, err := NewK8s("127.0.0.1:6443", K8sOption{KubeConfig: "/nonexistent/kubeconfig.yml"}) + if err == nil { + t.Error("expected error for bad kubeconfig path") + } +} + +func TestK8sBuildResources(t *testing.T) { + r := buildResources(512*1024*1024, 1.5) + mem := r.Limits[corev1.ResourceMemory] + if mem.Value() != 512*1024*1024 { + t.Errorf("memory = %d, want %d", mem.Value(), 512*1024*1024) + } + cpu := r.Limits[corev1.ResourceCPU] + if cpu.MilliValue() != 1500 { + t.Errorf("cpu = %dm, want 1500m", cpu.MilliValue()) + } +} + +func TestK8sBuildResourcesPartial(t *testing.T) { + r := buildResources(0, 0.5) + if _, ok := r.Limits[corev1.ResourceMemory]; ok { + t.Error("memory should not be set when 0") + } + cpu := r.Limits[corev1.ResourceCPU] + if cpu.MilliValue() != 500 { + t.Errorf("cpu = %dm, want 500m", cpu.MilliValue()) + } +} + +func TestK8sSandboxStopAndRemove(t *testing.T) { + host := taiTestK8sHost() + port := taiTestK8sPort() + kubeconfig := taiTestKubeConfig() + if host == "" || port == "" || kubeconfig == "" { + t.Skip("TAI_TEST_K8S_HOST, TAI_TEST_K8S_PORT, or TAI_TEST_KUBECONFIG not set") + } + + addr := host + ":" + port + sb, err := NewK8s(addr, K8sOption{ + Namespace: "default", + KubeConfig: kubeconfig, + }) + if err != nil { + t.Skipf("K8s not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-k8s-stop-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "60"}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + + if err := sb.Start(ctx, id); err != nil { + t.Fatalf("Start: %v", err) + } + + if err := sb.Stop(ctx, id, 5*time.Second); err != nil { + t.Fatalf("Stop: %v", err) + } + + // Remove should succeed even if already deleted by Stop + if err := sb.Remove(ctx, id, true); err != nil { + t.Logf("Remove after Stop: %v (expected if already deleted)", err) + } +} + +func TestK8sCreateWithResources(t *testing.T) { + host := taiTestK8sHost() + port := taiTestK8sPort() + kubeconfig := taiTestKubeConfig() + if host == "" || port == "" || kubeconfig == "" { + t.Skip("TAI_TEST_K8S_HOST, TAI_TEST_K8S_PORT, or TAI_TEST_KUBECONFIG not set") + } + + addr := host + ":" + port + sb, err := NewK8s(addr, K8sOption{ + Namespace: "default", + KubeConfig: kubeconfig, + }) + if err != nil { + t.Skipf("K8s not available: %v", err) + } + defer sb.Close() + + ctx := context.Background() + id, err := sb.Create(ctx, CreateOptions{ + Name: "tai-k8s-res-test", + Image: "alpine:latest", + Cmd: []string{"sleep", "10"}, + Memory: 64 * 1024 * 1024, + CPUs: 0.5, + Env: map[string]string{"FOO": "bar"}, + }) + if err != nil { + t.Fatalf("Create: %v", err) + } + defer sb.Remove(ctx, id, true) + + if err := sb.Start(ctx, id); err != nil { + t.Fatalf("Start: %v", err) + } + + // Exec with WorkDir and Env + result, err := sb.Exec(ctx, id, []string{"echo", "hi"}, ExecOptions{ + WorkDir: "/tmp", + Env: map[string]string{"BAR": "baz"}, + }) + if err != nil { + t.Fatalf("Exec: %v", err) + } + if result.ExitCode != 0 { + t.Errorf("exitCode = %d", result.ExitCode) + } +} + +func TestK8sRemoveNonExistent(t *testing.T) { + host := taiTestK8sHost() + port := taiTestK8sPort() + kubeconfig := taiTestKubeConfig() + if host == "" || port == "" || kubeconfig == "" { + t.Skip("TAI_TEST_K8S_HOST, TAI_TEST_K8S_PORT, or TAI_TEST_KUBECONFIG not set") + } + + addr := host + ":" + port + sb, err := NewK8s(addr, K8sOption{ + Namespace: "default", + KubeConfig: kubeconfig, + }) + if err != nil { + t.Skipf("K8s not available: %v", err) + } + defer sb.Close() + + // Remove non-existent should not error + err = sb.Remove(context.Background(), "nonexistent-pod-12345", false) + if err != nil { + t.Errorf("Remove non-existent should return nil, got: %v", err) + } +} + +func TestNewK8sRelativeKubeConfig(t *testing.T) { + kubeconfig := taiTestKubeConfig() + if kubeconfig == "" { + t.Skip("TAI_TEST_KUBECONFIG not set") + } + + // NewK8s with empty addr should still work (uses kubeconfig's server) + _, err := NewK8s("", K8sOption{ + KubeConfig: kubeconfig, + }) + if err != nil { + t.Skipf("K8s not available: %v", err) + } +} diff --git a/tai/tai.go b/tai/tai.go new file mode 100644 index 00000000..8c9ae33c --- /dev/null +++ b/tai/tai.go @@ -0,0 +1,301 @@ +package tai + +import ( + "fmt" + "net/http" + "net/url" + "strings" + + "github.com/yaoapp/yao/tai/proxy" + "github.com/yaoapp/yao/tai/sandbox" + "github.com/yaoapp/yao/tai/vnc" + "github.com/yaoapp/yao/tai/volume" + "github.com/yaoapp/yao/tai/workspace" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +// Runtime selects which container runtime to use via Tai. +type Runtime int + +const ( + Docker Runtime = iota + K8s +) + +func (r Runtime) apply(c *config) { c.runtime = r } + +// Option configures a Client. +type Option interface { + apply(*config) +} + +type optionFunc func(*config) + +func (f optionFunc) apply(c *config) { f(c) } + +// Ports configures service ports for Tai server. +type Ports struct { + GRPC int // default 9100 + HTTP int // default 8080 + VNC int // default 6080 + Docker int // default 2375 + K8s int // default 6443 +} + +// WithPorts overrides default Tai service ports. +func WithPorts(p Ports) Option { + return optionFunc(func(c *config) { c.ports = p }) +} + +// WithHTTPClient sets a custom HTTP client for proxy and VNC health checks. +func WithHTTPClient(hc *http.Client) Option { + return optionFunc(func(c *config) { c.httpClient = hc }) +} + +// WithDataDir sets the workspace root directory for Local mode. +func WithDataDir(dir string) Option { + return optionFunc(func(c *config) { c.dataDir = dir }) +} + +// WithKubeConfig sets the kubeconfig file path for K8s runtime. +// Supports both absolute and relative paths (relative paths are resolved to absolute). +func WithKubeConfig(path string) Option { + return optionFunc(func(c *config) { c.kubeConfig = path }) +} + +// WithNamespace sets the namespace for K8s runtime. Default is "default". +func WithNamespace(ns string) Option { + return optionFunc(func(c *config) { c.namespace = ns }) +} + +type config struct { + runtime Runtime + ports Ports + httpClient *http.Client + dataDir string + kubeConfig string + namespace string +} + +func defaultPorts() Ports { + return Ports{ + GRPC: 9100, + HTTP: 8080, + VNC: 6080, + } +} + +func mergedPorts(p Ports) Ports { + d := defaultPorts() + if p.GRPC != 0 { + d.GRPC = p.GRPC + } + if p.HTTP != 0 { + d.HTTP = p.HTTP + } + if p.VNC != 0 { + d.VNC = p.VNC + } + if p.Docker != 0 { + d.Docker = p.Docker + } + if p.K8s != 0 { + d.K8s = p.K8s + } + return d +} + +// Client provides unified access to all Tai SDK sub-packages. +type Client struct { + scheme string // "tai" or "docker" + host string + addr string + ports Ports + vol volume.Volume + sb sandbox.Sandbox + prx proxy.Proxy + vc vnc.VNC + grpcConn *grpc.ClientConn +} + +// New creates a Client based on the address protocol: +// +// "" → Local mode, platform default Docker socket +// "docker://addr" → Local mode, specified Docker daemon +// "tai://host" → Remote mode via Tai Server +func New(addr string, opts ...Option) (*Client, error) { + cfg := &config{ports: defaultPorts()} + for _, o := range opts { + o.apply(cfg) + } + cfg.ports = mergedPorts(cfg.ports) + + scheme, host, dockerAddr, err := parseAddr(addr) + if err != nil { + return nil, err + } + + c := &Client{ + scheme: scheme, + host: host, + addr: dockerAddr, + ports: cfg.ports, + } + + switch scheme { + case "docker": + return c.initLocal(cfg) + case "tai": + return c.initRemote(cfg) + default: + return nil, fmt.Errorf("unsupported scheme: %s", scheme) + } +} + +func (c *Client) initLocal(cfg *config) (*Client, error) { + sb, err := sandbox.NewLocal(c.addr) + if err != nil { + return nil, err + } + c.sb = sb + c.prx = proxy.NewLocal(sb) + c.vc = vnc.NewLocal(sb) + + dataDir := cfg.dataDir + if dataDir == "" { + dataDir = "/tmp/tai-volumes" + } + c.vol = volume.NewLocal(dataDir) + return c, nil +} + +func (c *Client) initRemote(cfg *config) (*Client, error) { + // gRPC connection + grpcAddr := fmt.Sprintf("%s:%d", c.host, c.ports.GRPC) + conn, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + return nil, fmt.Errorf("grpc dial %s: %w", grpcAddr, err) + } + c.grpcConn = conn + c.vol = volume.NewRemote(conn) + + // Sandbox + switch cfg.runtime { + case K8s: + k8sPort := c.ports.K8s + if k8sPort == 0 { + k8sPort = 6443 + } + sbAddr := fmt.Sprintf("%s:%d", c.host, k8sPort) + sb, err := sandbox.NewK8s(sbAddr, sandbox.K8sOption{ + Namespace: cfg.namespace, + KubeConfig: cfg.kubeConfig, + }) + if err != nil { + conn.Close() + return nil, err + } + c.sb = sb + default: + dockerPort := c.ports.Docker + if dockerPort == 0 { + dockerPort = 2375 + } + sbAddr := fmt.Sprintf("tcp://%s:%d", c.host, dockerPort) + sb, err := sandbox.NewDocker(sbAddr) + if err != nil { + conn.Close() + return nil, err + } + c.sb = sb + } + + hc := cfg.httpClient + c.prx = proxy.NewRemote(c.host, c.ports.HTTP, hc) + c.vc = vnc.NewRemote(c.host, c.ports.VNC, hc) + return c, nil +} + +// Close releases all resources. +func (c *Client) Close() error { + var errs []error + if c.sb != nil { + if err := c.sb.Close(); err != nil { + errs = append(errs, err) + } + } + if c.vol != nil { + if err := c.vol.Close(); err != nil { + errs = append(errs, err) + } + } + if c.grpcConn != nil { + if err := c.grpcConn.Close(); err != nil { + errs = append(errs, err) + } + } + if len(errs) > 0 { + return fmt.Errorf("close: %v", errs) + } + return nil +} + +// Volume returns the Volume IO layer. Never nil. +func (c *Client) Volume() volume.Volume { return c.vol } + +// Workspace returns an fs.FS-compatible filesystem for the given session. +func (c *Client) Workspace(sessionID string) workspace.FS { + return workspace.New(c.vol, sessionID) +} + +// Sandbox returns the container lifecycle manager. Never nil. +func (c *Client) Sandbox() sandbox.Sandbox { return c.sb } + +// Proxy returns the HTTP reverse proxy helper. Never nil. +func (c *Client) Proxy() proxy.Proxy { return c.prx } + +// VNC returns the VNC WebSocket helper. Never nil. +func (c *Client) VNC() vnc.VNC { return c.vc } + +// IsLocal returns true if the client connects directly to a Docker daemon. +func (c *Client) IsLocal() bool { return c.scheme == "docker" } + +func parseAddr(addr string) (scheme, host, dockerAddr string, err error) { + addr = strings.TrimSpace(addr) + if addr == "" { + return "docker", "", "", nil + } + + u, parseErr := url.Parse(addr) + if parseErr != nil { + return "", "", "", fmt.Errorf("parse addr %q: %w", addr, parseErr) + } + + switch u.Scheme { + case "tai": + host = u.Host + if host == "" { + return "", "", "", fmt.Errorf("tai:// requires a host") + } + if idx := strings.Index(host, ":"); idx >= 0 { + host = host[:idx] + } + return "tai", host, "", nil + + case "docker": + return "docker", "", addr, nil + + case "unix": + return "docker", "", addr, nil + + case "tcp": + return "docker", "", addr, nil + + case "npipe": + return "docker", "", addr, nil + + default: + return "", "", "", fmt.Errorf("unsupported scheme %q in addr %q", u.Scheme, addr) + } +} diff --git a/tai/tai_test.go b/tai/tai_test.go new file mode 100644 index 00000000..92d2350d --- /dev/null +++ b/tai/tai_test.go @@ -0,0 +1,268 @@ +package tai + +import ( + "os" + "strconv" + "testing" +) + +func taiTestHost() string { + if h := os.Getenv("TAI_TEST_HOST"); h != "" { + return h + } + return "127.0.0.1" +} + +func envPort(key string, fallback int) int { + if v := os.Getenv(key); v != "" { + if p, err := strconv.Atoi(v); err == nil { + return p + } + } + return fallback +} + +func TestParseAddr(t *testing.T) { + tests := []struct { + addr string + wantScheme string + wantHost string + wantDocker string + wantErr bool + }{ + {"", "docker", "", "", false}, + {"docker:///var/run/docker.sock", "docker", "", "docker:///var/run/docker.sock", false}, + {"docker://192.168.1.50:2375", "docker", "", "docker://192.168.1.50:2375", false}, + {"unix:///var/run/docker.sock", "docker", "", "unix:///var/run/docker.sock", false}, + {"tcp://127.0.0.1:2375", "docker", "", "tcp://127.0.0.1:2375", false}, + {"npipe:////./pipe/docker_engine", "docker", "", "npipe:////./pipe/docker_engine", false}, + {"tai://192.168.1.100", "tai", "192.168.1.100", "", false}, + {"tai://10.0.0.5:9100", "tai", "10.0.0.5", "", false}, + {"tai://", "", "", "", true}, + {"ftp://host", "", "", "", true}, + {" tai://host ", "tai", "host", "", false}, + } + + for _, tt := range tests { + t.Run(tt.addr, func(t *testing.T) { + scheme, host, dockerAddr, err := parseAddr(tt.addr) + if (err != nil) != tt.wantErr { + t.Fatalf("err = %v, wantErr = %v", err, tt.wantErr) + } + if err != nil { + return + } + if scheme != tt.wantScheme { + t.Errorf("scheme = %q, want %q", scheme, tt.wantScheme) + } + if host != tt.wantHost { + t.Errorf("host = %q, want %q", host, tt.wantHost) + } + if dockerAddr != tt.wantDocker { + t.Errorf("dockerAddr = %q, want %q", dockerAddr, tt.wantDocker) + } + }) + } +} + +func TestMergedPorts(t *testing.T) { + p := mergedPorts(Ports{HTTP: 8888}) + if p.HTTP != 8888 { + t.Errorf("HTTP = %d, want 8888", p.HTTP) + } + if p.GRPC != 9100 { + t.Errorf("GRPC = %d, want 9100 (default)", p.GRPC) + } + if p.VNC != 6080 { + t.Errorf("VNC = %d, want 6080 (default)", p.VNC) + } + if p.Docker != 0 { + t.Errorf("Docker = %d, want 0 (unset)", p.Docker) + } + if p.K8s != 0 { + t.Errorf("K8s = %d, want 0 (unset)", p.K8s) + } +} + +func TestMergedPortsAll(t *testing.T) { + p := mergedPorts(Ports{GRPC: 1, HTTP: 2, VNC: 3, Docker: 4, K8s: 5}) + if p.GRPC != 1 || p.HTTP != 2 || p.VNC != 3 || p.Docker != 4 || p.K8s != 5 { + t.Errorf("unexpected ports: %+v", p) + } +} + +func TestOptions(t *testing.T) { + cfg := &config{ports: defaultPorts()} + + WithPorts(Ports{HTTP: 9999}).apply(cfg) + if cfg.ports.HTTP != 9999 { + t.Errorf("WithPorts: HTTP = %d", cfg.ports.HTTP) + } + + WithDataDir("/data").apply(cfg) + if cfg.dataDir != "/data" { + t.Errorf("WithDataDir = %q", cfg.dataDir) + } + + WithHTTPClient(nil).apply(cfg) + + Docker.apply(cfg) + if cfg.runtime != Docker { + t.Error("Docker option failed") + } + K8s.apply(cfg) + if cfg.runtime != K8s { + t.Error("K8s option failed") + } +} + +func TestNewLocal(t *testing.T) { + c, err := New("") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer c.Close() + + if !c.IsLocal() { + t.Error("expected IsLocal = true") + } + if c.Volume() == nil { + t.Error("Volume should not be nil") + } + if c.Sandbox() == nil { + t.Error("Sandbox should not be nil") + } + if c.Proxy() == nil { + t.Error("Proxy should not be nil") + } + if c.VNC() == nil { + t.Error("VNC should not be nil") + } + + // Test Workspace accessor + ws := c.Workspace("test-session") + if ws == nil { + t.Error("Workspace should not be nil") + } +} + +func TestNewLocalWithDataDir(t *testing.T) { + dir := t.TempDir() + c, err := New("", WithDataDir(dir)) + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer c.Close() + + if !c.IsLocal() { + t.Error("expected IsLocal = true") + } +} + +func TestNewLocalExplicitSocket(t *testing.T) { + c, err := New("unix:///var/run/docker.sock") + if err != nil { + t.Skipf("Docker not available: %v", err) + } + defer c.Close() + + if !c.IsLocal() { + t.Error("expected IsLocal = true for unix socket") + } +} + +func TestNewRemoteK8s(t *testing.T) { + host := os.Getenv("TAI_TEST_K8S_HOST") + kubeconfig := os.Getenv("TAI_TEST_KUBECONFIG") + if host == "" || kubeconfig == "" { + t.Skip("TAI_TEST_K8S_HOST or TAI_TEST_KUBECONFIG not set") + } + + ports := Ports{ + K8s: envPort("TAI_TEST_K8S_PORT", 6443), + GRPC: envPort("TAI_TEST_GRPC_PORT", 9100), + HTTP: envPort("TAI_TEST_HTTP_PORT", 8080), + VNC: envPort("TAI_TEST_VNC_PORT", 6080), + } + + c, err := New("tai://"+host, K8s, + WithPorts(ports), + WithKubeConfig(kubeconfig), + WithNamespace("default"), + ) + if err != nil { + t.Skipf("Tai K8s not available: %v", err) + } + defer c.Close() + + if c.IsLocal() { + t.Error("expected IsLocal = false") + } + if c.Sandbox() == nil { + t.Error("Sandbox should not be nil") + } +} + +func TestNewRemoteK8sMissingKubeConfig(t *testing.T) { + _, err := New("tai://127.0.0.1", K8s) + if err == nil { + t.Error("expected error for missing kubeconfig") + } +} + +func TestWithKubeConfigAndNamespace(t *testing.T) { + cfg := &config{ports: defaultPorts()} + WithKubeConfig("/path/to/kubeconfig").apply(cfg) + if cfg.kubeConfig != "/path/to/kubeconfig" { + t.Errorf("WithKubeConfig = %q", cfg.kubeConfig) + } + WithNamespace("test-ns").apply(cfg) + if cfg.namespace != "test-ns" { + t.Errorf("WithNamespace = %q", cfg.namespace) + } +} + +func TestNewInvalidScheme(t *testing.T) { + _, err := New("ftp://host") + if err == nil { + t.Error("expected error for ftp://") + } +} + +func TestNewRemoteDocker(t *testing.T) { + addr := "tai://" + taiTestHost() + c, err := New(addr) + if err != nil { + t.Skipf("Tai not available at %s: %v", addr, err) + } + defer c.Close() + + if c.IsLocal() { + t.Error("expected IsLocal = false for tai://") + } + if c.Volume() == nil { + t.Error("Volume should not be nil") + } + if c.Sandbox() == nil { + t.Error("Sandbox should not be nil") + } + if c.Proxy() == nil { + t.Error("Proxy should not be nil") + } + if c.VNC() == nil { + t.Error("VNC should not be nil") + } + ws := c.Workspace("test") + if ws == nil { + t.Error("Workspace should not be nil") + } +} + +func TestNewRemoteWithPorts(t *testing.T) { + addr := "tai://" + taiTestHost() + c, err := New(addr, WithPorts(Ports{HTTP: 8888})) + if err != nil { + t.Skipf("Tai not available at %s: %v", addr, err) + } + defer c.Close() +} diff --git a/tai/vnc/vnc.go b/tai/vnc/vnc.go new file mode 100644 index 00000000..ec03348d --- /dev/null +++ b/tai/vnc/vnc.go @@ -0,0 +1,98 @@ +package vnc + +import ( + "context" + "fmt" + "net/http" + + "github.com/yaoapp/yao/tai/sandbox" +) + +const defaultVNCContainerPort = 6080 + +// VNC resolves VNC WebSocket URLs for containers. +// Remote routes through Tai VNC router; Local resolves host ports directly. +type VNC interface { + URL(ctx context.Context, containerID string) (string, error) + Ping(ctx context.Context, containerID string) error +} + +// --- Remote implementation --- + +type remoteVNC struct { + host string + port int + client *http.Client +} + +// NewRemote creates a VNC that routes through Tai's VNC router. +func NewRemote(host string, port int, hc *http.Client) VNC { + if hc == nil { + hc = http.DefaultClient + } + return &remoteVNC{host: host, port: port, client: hc} +} + +func (r *remoteVNC) URL(_ context.Context, containerID string) (string, error) { + return fmt.Sprintf("ws://%s:%d/vnc/%s/ws", r.host, r.port, containerID), nil +} + +func (r *remoteVNC) Ping(ctx context.Context, containerID string) error { + url := fmt.Sprintf("http://%s:%d/vnc/%s/ws", r.host, r.port, containerID) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + if err != nil { + return err + } + resp, err := r.client.Do(req) + if err != nil { + return err + } + resp.Body.Close() + return nil +} + +// --- Local implementation --- + +type localVNC struct { + sb sandbox.Sandbox +} + +// NewLocal creates a VNC that resolves host VNC ports via sandbox.Inspect. +func NewLocal(sb sandbox.Sandbox) VNC { + return &localVNC{sb: sb} +} + +func (l *localVNC) URL(ctx context.Context, containerID string) (string, error) { + info, err := l.sb.Inspect(ctx, containerID) + if err != nil { + return "", fmt.Errorf("inspect: %w", err) + } + for _, p := range info.Ports { + if p.ContainerPort == defaultVNCContainerPort && p.HostPort != 0 { + ip := p.HostIP + if ip == "" { + ip = "127.0.0.1" + } + return fmt.Sprintf("ws://%s:%d/ws", ip, p.HostPort), nil + } + } + return "", fmt.Errorf("VNC port %d not mapped for container %s", defaultVNCContainerPort, containerID) +} + +func (l *localVNC) Ping(ctx context.Context, containerID string) error { + url, err := l.URL(ctx, containerID) + if err != nil { + return err + } + httpURL := "http" + url[2:] + req, err := http.NewRequestWithContext(ctx, http.MethodGet, httpURL, nil) + if err != nil { + return err + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + return err + } + resp.Body.Close() + return nil +} diff --git a/tai/vnc/vnc_test.go b/tai/vnc/vnc_test.go new file mode 100644 index 00000000..af6e41a2 --- /dev/null +++ b/tai/vnc/vnc_test.go @@ -0,0 +1,214 @@ +package vnc + +import ( + "context" + "fmt" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/yaoapp/yao/tai/sandbox" +) + +func TestRemoteURL(t *testing.T) { + v := NewRemote("10.0.0.1", 6080, nil) + ctx := context.Background() + + url, err := v.URL(ctx, "container-123") + if err != nil { + t.Fatalf("URL: %v", err) + } + want := "ws://10.0.0.1:6080/vnc/container-123/ws" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestRemotePing(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + })) + defer srv.Close() + + // Parse host:port from test server URL for real remoteVNC + u := srv.URL // "http://127.0.0.1:PORT" + host := u[len("http://"):] + colonIdx := 0 + for i, c := range host { + if c == ':' { + colonIdx = i + break + } + } + hostStr := host[:colonIdx] + portStr := host[colonIdx+1:] + port := 0 + for _, c := range portStr { + port = port*10 + int(c-'0') + } + + v := &remoteVNC{host: hostStr, port: port, client: srv.Client()} + if err := v.Ping(context.Background(), "c1"); err != nil { + t.Fatalf("Ping: %v", err) + } +} + +func TestRemotePingError(t *testing.T) { + v := &remoteVNC{host: "192.168.254.254", port: 1, client: &http.Client{Timeout: 100 * time.Millisecond}} + if err := v.Ping(context.Background(), "c1"); err == nil { + t.Error("expected error for unreachable host") + } +} + +func TestLocalURL(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ + ID: id, + Ports: []sandbox.PortMapping{ + {ContainerPort: 6080, HostPort: 49152, HostIP: "127.0.0.1", Protocol: "tcp"}, + }, + }, nil + }, + } + + v := NewLocal(mock) + url, err := v.URL(context.Background(), "c1") + if err != nil { + t.Fatalf("URL: %v", err) + } + want := "ws://127.0.0.1:49152/ws" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestLocalURLEmptyHostIP(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ + ID: id, + Ports: []sandbox.PortMapping{ + {ContainerPort: 6080, HostPort: 49152, HostIP: "", Protocol: "tcp"}, + }, + }, nil + }, + } + + v := NewLocal(mock) + url, err := v.URL(context.Background(), "c1") + if err != nil { + t.Fatalf("URL: %v", err) + } + want := "ws://127.0.0.1:49152/ws" + if url != want { + t.Errorf("got %q, want %q", url, want) + } +} + +func TestLocalURLPortNotFound(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ID: id}, nil + }, + } + + v := NewLocal(mock) + _, err := v.URL(context.Background(), "c1") + if err == nil { + t.Error("expected error for missing VNC port") + } +} + +func TestLocalURLInspectError(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return nil, fmt.Errorf("not found") + }, + } + + v := NewLocal(mock) + _, err := v.URL(context.Background(), "c1") + if err == nil { + t.Error("expected error for inspect failure") + } +} + +func TestLocalPingSuccess(t *testing.T) { + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + })) + defer srv.Close() + + // Parse port from test server + u := srv.URL[len("http://"):] + colonIdx := 0 + for i, c := range u { + if c == ':' { + colonIdx = i + break + } + } + portStr := u[colonIdx+1:] + port := 0 + for _, c := range portStr { + port = port*10 + int(c-'0') + } + + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return &sandbox.ContainerInfo{ + ID: id, + Ports: []sandbox.PortMapping{ + {ContainerPort: 6080, HostPort: port, HostIP: "127.0.0.1", Protocol: "tcp"}, + }, + }, nil + }, + } + + v := NewLocal(mock) + if err := v.Ping(context.Background(), "c1"); err != nil { + t.Fatalf("Ping: %v", err) + } +} + +func TestLocalPingError(t *testing.T) { + mock := &mockSandbox{ + inspectFn: func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + return nil, fmt.Errorf("not found") + }, + } + + v := NewLocal(mock) + if err := v.Ping(context.Background(), "c1"); err == nil { + t.Error("expected error") + } +} + +// mockSandbox implements sandbox.Sandbox for testing. +type mockSandbox struct { + inspectFn func(ctx context.Context, id string) (*sandbox.ContainerInfo, error) +} + +func (m *mockSandbox) Create(ctx context.Context, opts sandbox.CreateOptions) (string, error) { + return "", nil +} +func (m *mockSandbox) Start(ctx context.Context, id string) error { return nil } +func (m *mockSandbox) Stop(ctx context.Context, id string, timeout time.Duration) error { + return nil +} +func (m *mockSandbox) Remove(ctx context.Context, id string, force bool) error { return nil } +func (m *mockSandbox) Exec(ctx context.Context, id string, cmd []string, opts sandbox.ExecOptions) (*sandbox.ExecResult, error) { + return nil, nil +} +func (m *mockSandbox) Inspect(ctx context.Context, id string) (*sandbox.ContainerInfo, error) { + if m.inspectFn != nil { + return m.inspectFn(ctx, id) + } + return &sandbox.ContainerInfo{ID: id}, nil +} +func (m *mockSandbox) List(ctx context.Context, opts sandbox.ListOptions) ([]sandbox.ContainerInfo, error) { + return nil, nil +} +func (m *mockSandbox) Close() error { return nil } diff --git a/tai/volume/local.go b/tai/volume/local.go new file mode 100644 index 00000000..49462fb0 --- /dev/null +++ b/tai/volume/local.go @@ -0,0 +1,299 @@ +package volume + +import ( + "context" + "io/fs" + "os" + "path/filepath" + "strings" + "time" +) + +type localStorage struct { + dataDir string +} + +// NewLocal creates a Volume backed by direct disk IO under dataDir/{sessionID}/. +func NewLocal(dataDir string) Volume { + return &localStorage{dataDir: dataDir} +} + +func (l *localStorage) root(sessionID string) string { + return filepath.Join(l.dataDir, sessionID) +} + +func (l *localStorage) abs(sessionID, path string) (string, error) { + base := l.root(sessionID) + resolved := filepath.Join(base, filepath.Clean(path)) + if !strings.HasPrefix(resolved, base+string(filepath.Separator)) && resolved != base { + return "", os.ErrPermission + } + return resolved, nil +} + +func (l *localStorage) ReadFile(_ context.Context, sessionID, path string) ([]byte, os.FileMode, error) { + abs, err := l.abs(sessionID, path) + if err != nil { + return nil, 0, err + } + info, err := os.Stat(abs) + if err != nil { + return nil, 0, err + } + data, err := os.ReadFile(abs) + if err != nil { + return nil, 0, err + } + return data, info.Mode(), nil +} + +func (l *localStorage) WriteFile(_ context.Context, sessionID, path string, data []byte, perm os.FileMode) error { + abs, err := l.abs(sessionID, path) + if err != nil { + return err + } + if err := os.MkdirAll(filepath.Dir(abs), 0o755); err != nil { + return err + } + return os.WriteFile(abs, data, perm) +} + +func (l *localStorage) Stat(_ context.Context, sessionID, path string) (*FileInfo, error) { + abs, err := l.abs(sessionID, path) + if err != nil { + return nil, err + } + info, err := os.Stat(abs) + if err != nil { + return nil, err + } + return &FileInfo{ + Path: path, + Size: info.Size(), + Mtime: info.ModTime(), + Mode: info.Mode(), + IsDir: info.IsDir(), + }, nil +} + +func (l *localStorage) ListDir(_ context.Context, sessionID, path string) ([]FileInfo, error) { + abs, err := l.abs(sessionID, path) + if err != nil { + return nil, err + } + entries, err := os.ReadDir(abs) + if err != nil { + return nil, err + } + var result []FileInfo + for _, e := range entries { + info, err := e.Info() + if err != nil { + continue + } + result = append(result, FileInfo{ + Path: e.Name(), + Size: info.Size(), + Mtime: info.ModTime(), + Mode: info.Mode(), + IsDir: e.IsDir(), + }) + } + return result, nil +} + +func (l *localStorage) Remove(_ context.Context, sessionID, path string, recursive bool) error { + abs, err := l.abs(sessionID, path) + if err != nil { + return err + } + if recursive { + return os.RemoveAll(abs) + } + return os.Remove(abs) +} + +func (l *localStorage) Rename(_ context.Context, sessionID, oldPath, newPath string) error { + oldAbs, err := l.abs(sessionID, oldPath) + if err != nil { + return err + } + newAbs, err := l.abs(sessionID, newPath) + if err != nil { + return err + } + return os.Rename(oldAbs, newAbs) +} + +func (l *localStorage) MkdirAll(_ context.Context, sessionID, path string) error { + abs, err := l.abs(sessionID, path) + if err != nil { + return err + } + return os.MkdirAll(abs, 0o755) +} + +// SyncPush copies changed files from localDir to dataDir/{sessionID}/. +// Uses mtime+size to detect changes. Files that vanish during sync are skipped. +func (l *localStorage) SyncPush(_ context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) { + start := time.Now() + cfg := applySyncOpts(opts) + dst := l.root(sessionID) + if err := os.MkdirAll(dst, 0o755); err != nil { + return nil, err + } + + var synced int + var transferred int64 + + err := filepath.WalkDir(localDir, func(abs string, d fs.DirEntry, err error) error { + if err != nil { + if os.IsNotExist(err) { + return nil + } + return err + } + rel, _ := filepath.Rel(localDir, abs) + if rel == "." { + return nil + } + rel = filepath.ToSlash(rel) + + if isExcluded(rel, d.IsDir(), cfg.excludes) { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + + target := filepath.Join(dst, filepath.FromSlash(rel)) + if d.IsDir() { + return os.MkdirAll(target, 0o755) + } + + srcInfo, err := d.Info() + if err != nil { + return nil // file vanished between readdir and stat; skip + } + + if !cfg.forceFull { + if dstInfo, e := os.Stat(target); e == nil { + if dstInfo.Size() == srcInfo.Size() && dstInfo.ModTime().Equal(srcInfo.ModTime()) { + return nil + } + } + } + + data, err := os.ReadFile(abs) + if err != nil { + if os.IsNotExist(err) { + return nil // file vanished between stat and read; skip + } + return err + } + if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { + return err + } + if err := os.WriteFile(target, data, srcInfo.Mode()); err != nil { + return err + } + _ = os.Chtimes(target, srcInfo.ModTime(), srcInfo.ModTime()) + synced++ + transferred += srcInfo.Size() + return nil + }) + + return &SyncResult{ + FilesSynced: synced, + BytesTransferred: transferred, + Duration: time.Since(start), + }, err +} + +// SyncPull copies changed files from dataDir/{sessionID}/ to localDir. +// Files that vanish during sync are skipped. +func (l *localStorage) SyncPull(_ context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) { + start := time.Now() + cfg := applySyncOpts(opts) + src := l.root(sessionID) + if err := os.MkdirAll(localDir, 0o755); err != nil { + return nil, err + } + + var synced int + var transferred int64 + + err := filepath.WalkDir(src, func(abs string, d fs.DirEntry, err error) error { + if err != nil { + if os.IsNotExist(err) { + return nil + } + return err + } + rel, _ := filepath.Rel(src, abs) + if rel == "." { + return nil + } + rel = filepath.ToSlash(rel) + + if isExcluded(rel, d.IsDir(), cfg.excludes) { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + + target := filepath.Join(localDir, filepath.FromSlash(rel)) + if d.IsDir() { + return os.MkdirAll(target, 0o755) + } + + srcInfo, err := d.Info() + if err != nil { + return nil // file vanished between readdir and stat; skip + } + + if !cfg.forceFull { + if dstInfo, e := os.Stat(target); e == nil { + if dstInfo.Size() == srcInfo.Size() && dstInfo.ModTime().Equal(srcInfo.ModTime()) { + return nil + } + } + } + + data, err := os.ReadFile(abs) + if err != nil { + if os.IsNotExist(err) { + return nil // file vanished between stat and read; skip + } + return err + } + if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { + return err + } + if err := os.WriteFile(target, data, srcInfo.Mode()); err != nil { + return err + } + _ = os.Chtimes(target, srcInfo.ModTime(), srcInfo.ModTime()) + synced++ + transferred += srcInfo.Size() + return nil + }) + + return &SyncResult{ + FilesSynced: synced, + BytesTransferred: transferred, + Duration: time.Since(start), + }, err +} + +func (l *localStorage) Close() error { return nil } + +func isExcluded(rel string, isDir bool, patterns []string) bool { + for _, p := range patterns { + if matched, _ := filepath.Match(p, filepath.Base(rel)); matched { + return true + } + } + return false +} diff --git a/tai/volume/mock_test.go b/tai/volume/mock_test.go new file mode 100644 index 00000000..59f0ce06 --- /dev/null +++ b/tai/volume/mock_test.go @@ -0,0 +1,696 @@ +package volume + +import ( + "context" + "fmt" + "io" + "net" + "os" + "testing" + + pb "github.com/yaoapp/yao/tai/volume/pb" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +type mockVolumeServer struct { + pb.UnimplementedVolumeServer + statErr error + removeOK bool + removeError string + renameOK bool + renameError string + mkdirOK bool + mkdirError string +} + +func (m *mockVolumeServer) Stat(_ context.Context, req *pb.FSRequest) (*pb.FileInfo, error) { + if m.statErr != nil { + return nil, m.statErr + } + return &pb.FileInfo{Path: req.Path, Size: 42, IsDir: false}, nil +} + +func (m *mockVolumeServer) Remove(_ context.Context, req *pb.FSRemoveRequest) (*pb.FSOpResponse, error) { + return &pb.FSOpResponse{Ok: m.removeOK, Error: m.removeError}, nil +} + +func (m *mockVolumeServer) Rename(_ context.Context, req *pb.FSRenameRequest) (*pb.FSOpResponse, error) { + return &pb.FSOpResponse{Ok: m.renameOK, Error: m.renameError}, nil +} + +func (m *mockVolumeServer) MkdirAll(_ context.Context, req *pb.FSRequest) (*pb.FSOpResponse, error) { + return &pb.FSOpResponse{Ok: m.mkdirOK, Error: m.mkdirError}, nil +} + +func (m *mockVolumeServer) ReadFile(req *pb.FSReadRequest, stream grpc.ServerStreamingServer[pb.FSDataChunk]) error { + return fmt.Errorf("file not found: %s", req.Path) +} + +func (m *mockVolumeServer) WriteFile(stream grpc.ClientStreamingServer[pb.FSWriteChunk, pb.FSWriteResponse]) error { + for { + _, err := stream.Recv() + if err == io.EOF { + return stream.SendAndClose(&pb.FSWriteResponse{Size: 0}) + } + if err != nil { + return err + } + } +} + +func (m *mockVolumeServer) SyncPush(stream grpc.BidiStreamingServer[pb.SyncMessage, pb.SyncMessage]) error { + // Receive manifest + msg, err := stream.Recv() + if err != nil { + return err + } + manifest := msg.GetManifest() + if manifest == nil { + return fmt.Errorf("expected manifest") + } + + // Respond with diff: request all files + a ghost delete + var needFiles []string + for _, f := range manifest.Files { + if !f.IsDir { + needFiles = append(needFiles, f.Path) + } + } + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Diff{ + Diff: &pb.SyncDiff{ + NeedFiles: needFiles, + DeleteFiles: []string{"old-deleted.txt"}, + }, + }, + }); err != nil { + return err + } + + // Receive file chunks until CloseSend + var synced int32 + var transferred int64 + for { + msg, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + return err + } + if chunk := msg.GetChunk(); chunk != nil && chunk.Eof { + synced++ + transferred += int64(len(chunk.Data)) + } + } + + // Send result + return stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Result{ + Result: &pb.SyncResult{ + FilesSynced: synced, + BytesTransferred: transferred, + }, + }, + }) +} + +func (m *mockVolumeServer) SyncPull(req *pb.SyncManifest, stream grpc.ServerStreamingServer[pb.SyncMessage]) error { + // Send MKDIR + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{Path: "newdir", Type: pb.FileChunk_MKDIR}, + }, + }); err != nil { + return err + } + + // Send DELETE + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{Path: "old-file.txt", Type: pb.FileChunk_DELETE}, + }, + }); err != nil { + return err + } + + // Send a file (FULL, multi-chunk) + data := []byte("mock pull content") + compressed, err := compress(data) + if err != nil { + return err + } + + half := len(compressed) / 2 + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{ + Path: "pulled.txt", + Type: pb.FileChunk_FULL, + Data: compressed[:half], + Eof: false, + Mode: 0o644, + Mtime: 1234567890000000000, + }, + }, + }); err != nil { + return err + } + + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{ + Path: "pulled.txt", + Type: pb.FileChunk_FULL, + Data: compressed[half:], + Eof: true, + }, + }, + }); err != nil { + return err + } + + // Send a file with no mode (tests default 0o644) + data2 := []byte("no mode") + c2, _ := compress(data2) + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{ + Path: "nomode.txt", + Type: pb.FileChunk_FULL, + Data: c2, + Eof: true, + }, + }, + }); err != nil { + return err + } + + return nil +} + +func (m *mockVolumeServer) ListDir(_ context.Context, req *pb.FSRequest) (*pb.FSListResponse, error) { + return &pb.FSListResponse{Entries: []*pb.FileInfo{ + {Path: "a.txt", Size: 10}, + {Path: "b.txt", Size: 20, IsDir: true}, + }}, nil +} + +func startMockServer(t *testing.T, mock *mockVolumeServer) (*grpc.ClientConn, func()) { + t.Helper() + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("listen: %v", err) + } + srv := grpc.NewServer() + pb.RegisterVolumeServer(srv, mock) + + go func() { _ = srv.Serve(lis) }() + + conn, err := grpc.NewClient(lis.Addr().String(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + srv.Stop() + t.Fatalf("dial: %v", err) + } + + return conn, func() { + conn.Close() + srv.Stop() + } +} + +func TestMockRemoteStat(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + info, err := vol.Stat(context.Background(), "s1", "test.txt") + if err != nil { + t.Fatalf("Stat: %v", err) + } + if info.Size != 42 { + t.Errorf("size = %d, want 42", info.Size) + } +} + +func TestMockRemoteStatError(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{statErr: fmt.Errorf("boom")}) + defer cleanup() + + vol := NewRemote(conn) + _, err := vol.Stat(context.Background(), "s1", "test.txt") + if err == nil { + t.Error("expected error") + } +} + +func TestMockRemoteRemoveFail(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{removeOK: false, removeError: "no such file"}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Remove(context.Background(), "s1", "bad.txt", false) + if err == nil { + t.Error("expected error") + } +} + +func TestMockRemoteRemoveOK(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{removeOK: true}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Remove(context.Background(), "s1", "good.txt", false) + if err != nil { + t.Errorf("Remove: %v", err) + } +} + +func TestMockRemoteRenameFail(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{renameOK: false, renameError: "bad"}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Rename(context.Background(), "s1", "a", "b") + if err == nil { + t.Error("expected error") + } +} + +func TestMockRemoteRenameOK(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{renameOK: true}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Rename(context.Background(), "s1", "a", "b") + if err != nil { + t.Errorf("Rename: %v", err) + } +} + +func TestMockRemoteMkdirFail(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{mkdirOK: false, mkdirError: "perm denied"}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.MkdirAll(context.Background(), "s1", "dir") + if err == nil { + t.Error("expected error") + } +} + +func TestMockRemoteMkdirOK(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{mkdirOK: true}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.MkdirAll(context.Background(), "s1", "dir") + if err != nil { + t.Errorf("MkdirAll: %v", err) + } +} + +func TestMockRemoteReadFileError(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + _, _, err := vol.ReadFile(context.Background(), "s1", "missing.txt") + if err == nil { + t.Error("expected error") + } +} + +func TestMockRemoteWriteFile(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.WriteFile(context.Background(), "s1", "test.txt", []byte("hello"), 0o644) + if err != nil { + t.Errorf("WriteFile: %v", err) + } +} + +func TestMockRemoteWriteFileLarge(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + data := make([]byte, 200*1024) + for i := range data { + data[i] = byte(i % 256) + } + err := vol.WriteFile(context.Background(), "s1", "large.bin", data, 0o644) + if err != nil { + t.Errorf("WriteFile large: %v", err) + } +} + +func TestMockRemoteWriteFileEmpty(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + err := vol.WriteFile(context.Background(), "s1", "empty.txt", []byte{}, 0o644) + if err != nil { + t.Errorf("WriteFile empty: %v", err) + } +} + +func TestMockRemoteListDir(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + entries, err := vol.ListDir(context.Background(), "s1", ".") + if err != nil { + t.Fatalf("ListDir: %v", err) + } + if len(entries) != 2 { + t.Errorf("entries = %d, want 2", len(entries)) + } +} + +func TestMockRemoteClose(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + if err := vol.Close(); err != nil { + t.Errorf("Close: %v", err) + } +} + +func TestMockRemoteSyncPush(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + srcDir := t.TempDir() + _ = os.WriteFile(srcDir+"/a.txt", []byte("aaa"), 0o644) + _ = os.Mkdir(srcDir+"/sub", 0o755) + _ = os.WriteFile(srcDir+"/sub/b.txt", []byte("bbb"), 0o644) + + result, err := vol.SyncPush(context.Background(), "s1", srcDir) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } +} + +func TestMockRemoteSyncPushWithExcludes(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + srcDir := t.TempDir() + _ = os.WriteFile(srcDir+"/keep.txt", []byte("keep"), 0o644) + _ = os.WriteFile(srcDir+"/skip.log", []byte("skip"), 0o644) + + result, err := vol.SyncPush(context.Background(), "s1", srcDir, WithExcludes("*.log")) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } +} + +func TestMockRemoteSyncPushForceFull(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + srcDir := t.TempDir() + _ = os.WriteFile(srcDir+"/a.txt", []byte("aaa"), 0o644) + + result, err := vol.SyncPush(context.Background(), "s1", srcDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } +} + +func TestMockRemoteSyncPull(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + dstDir := t.TempDir() + + // Create a file that the mock will ask to DELETE + _ = os.WriteFile(dstDir+"/old-file.txt", []byte("old"), 0o644) + + result, err := vol.SyncPull(context.Background(), "s1", dstDir) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } + + // Verify pulled file + data, err := os.ReadFile(dstDir + "/pulled.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(data) != "mock pull content" { + t.Errorf("content = %q", data) + } + + // Verify MKDIR was created + info, err := os.Stat(dstDir + "/newdir") + if err != nil { + t.Fatalf("MKDIR dir: %v", err) + } + if !info.IsDir() { + t.Error("expected dir") + } + + // Verify DELETE removed the file + if _, err := os.Stat(dstDir + "/old-file.txt"); err == nil { + t.Error("DELETE file should be removed") + } + + // Verify nomode.txt was created + data, err = os.ReadFile(dstDir + "/nomode.txt") + if err != nil { + t.Fatalf("ReadFile nomode: %v", err) + } + if string(data) != "no mode" { + t.Errorf("nomode content = %q", data) + } +} + +func TestMockRemoteSyncPullWithLocalFiles(t *testing.T) { + conn, cleanup := startMockServer(t, &mockVolumeServer{}) + defer cleanup() + + vol := NewRemote(conn) + dstDir := t.TempDir() + _ = os.WriteFile(dstDir+"/existing.txt", []byte("exist"), 0o644) + + result, err := vol.SyncPull(context.Background(), "s1", dstDir) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } +} + +// errMockVolumeServer returns errors mid-stream for error-path testing. +type errMockVolumeServer struct { + pb.UnimplementedVolumeServer +} + +func (m *errMockVolumeServer) SyncPush(stream grpc.BidiStreamingServer[pb.SyncMessage, pb.SyncMessage]) error { + _, _ = stream.Recv() + return fmt.Errorf("injected push error") +} + +func (m *errMockVolumeServer) SyncPull(_ *pb.SyncManifest, stream grpc.ServerStreamingServer[pb.SyncMessage]) error { + return fmt.Errorf("injected pull error") +} + +func (m *errMockVolumeServer) ReadFile(_ *pb.FSReadRequest, _ grpc.ServerStreamingServer[pb.FSDataChunk]) error { + return fmt.Errorf("injected read error") +} + +func (m *errMockVolumeServer) WriteFile(stream grpc.ClientStreamingServer[pb.FSWriteChunk, pb.FSWriteResponse]) error { + return fmt.Errorf("injected write error") +} + +func (m *errMockVolumeServer) Stat(_ context.Context, _ *pb.FSRequest) (*pb.FileInfo, error) { + return nil, fmt.Errorf("injected stat error") +} + +func (m *errMockVolumeServer) ListDir(_ context.Context, _ *pb.FSRequest) (*pb.FSListResponse, error) { + return nil, fmt.Errorf("injected listdir error") +} + +func (m *errMockVolumeServer) Remove(_ context.Context, _ *pb.FSRemoveRequest) (*pb.FSOpResponse, error) { + return nil, fmt.Errorf("injected remove error") +} + +func (m *errMockVolumeServer) Rename(_ context.Context, _ *pb.FSRenameRequest) (*pb.FSOpResponse, error) { + return nil, fmt.Errorf("injected rename error") +} + +func (m *errMockVolumeServer) MkdirAll(_ context.Context, _ *pb.FSRequest) (*pb.FSOpResponse, error) { + return nil, fmt.Errorf("injected mkdir error") +} + +func startErrMockServer(t *testing.T) (*grpc.ClientConn, func()) { + t.Helper() + lis, err := net.Listen("tcp", "127.0.0.1:0") + if err != nil { + t.Fatalf("listen: %v", err) + } + srv := grpc.NewServer() + pb.RegisterVolumeServer(srv, &errMockVolumeServer{}) + go func() { _ = srv.Serve(lis) }() + + conn, err := grpc.NewClient(lis.Addr().String(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + srv.Stop() + t.Fatalf("dial: %v", err) + } + return conn, func() { conn.Close(); srv.Stop() } +} + +func TestErrRemoteSyncPush(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + srcDir := t.TempDir() + _ = os.WriteFile(srcDir+"/a.txt", []byte("aaa"), 0o644) + + _, err := vol.SyncPush(context.Background(), "s1", srcDir) + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteSyncPull(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + dstDir := t.TempDir() + + _, err := vol.SyncPull(context.Background(), "s1", dstDir) + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteWriteFile(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + err := vol.WriteFile(context.Background(), "s1", "test.txt", []byte("x"), 0o644) + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteReadFile(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + _, _, err := vol.ReadFile(context.Background(), "s1", "test.txt") + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteStat(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + _, err := vol.Stat(context.Background(), "s1", "test.txt") + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteListDir(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + _, err := vol.ListDir(context.Background(), "s1", ".") + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteRemove(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Remove(context.Background(), "s1", "test.txt", false) + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteRename(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + err := vol.Rename(context.Background(), "s1", "a", "b") + if err == nil { + t.Error("expected error") + } +} + +func TestErrRemoteMkdirAll(t *testing.T) { + conn, cleanup := startErrMockServer(t) + defer cleanup() + + vol := NewRemote(conn) + err := vol.MkdirAll(context.Background(), "s1", "dir") + if err == nil { + t.Error("expected error") + } +} + +func TestPbToFileInfo(t *testing.T) { + fi := pbToFileInfo(&pb.FileInfo{ + Path: "test.txt", + Size: 100, + Mtime: 1234567890000000000, + Mode: 0o644, + IsDir: false, + }) + if fi.Path != "test.txt" { + t.Errorf("path = %q", fi.Path) + } + if fi.Size != 100 { + t.Errorf("size = %d", fi.Size) + } + if fi.IsDir { + t.Error("expected not dir") + } + if fi.Mode != os.FileMode(0o644) { + t.Errorf("mode = %v", fi.Mode) + } +} diff --git a/tai/volume/pb/volume.pb.go b/tai/volume/pb/volume.pb.go new file mode 100644 index 00000000..44460723 --- /dev/null +++ b/tai/volume/pb/volume.pb.go @@ -0,0 +1,1219 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v4.25.0 +// source: volume/pb/volume.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type FileChunk_ChunkType int32 + +const ( + FileChunk_FULL FileChunk_ChunkType = 0 + FileChunk_DELTA FileChunk_ChunkType = 1 // reserved for future rsync delta + FileChunk_DELETE FileChunk_ChunkType = 2 + FileChunk_MKDIR FileChunk_ChunkType = 3 +) + +// Enum value maps for FileChunk_ChunkType. +var ( + FileChunk_ChunkType_name = map[int32]string{ + 0: "FULL", + 1: "DELTA", + 2: "DELETE", + 3: "MKDIR", + } + FileChunk_ChunkType_value = map[string]int32{ + "FULL": 0, + "DELTA": 1, + "DELETE": 2, + "MKDIR": 3, + } +) + +func (x FileChunk_ChunkType) Enum() *FileChunk_ChunkType { + p := new(FileChunk_ChunkType) + *p = x + return p +} + +func (x FileChunk_ChunkType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (FileChunk_ChunkType) Descriptor() protoreflect.EnumDescriptor { + return file_volume_pb_volume_proto_enumTypes[0].Descriptor() +} + +func (FileChunk_ChunkType) Type() protoreflect.EnumType { + return &file_volume_pb_volume_proto_enumTypes[0] +} + +func (x FileChunk_ChunkType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use FileChunk_ChunkType.Descriptor instead. +func (FileChunk_ChunkType) EnumDescriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{4, 0} +} + +type FileInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` + Size int64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` + Mtime int64 `protobuf:"varint,3,opt,name=mtime,proto3" json:"mtime,omitempty"` // unix timestamp (nanoseconds) + Mode uint32 `protobuf:"varint,4,opt,name=mode,proto3" json:"mode,omitempty"` + IsDir bool `protobuf:"varint,5,opt,name=is_dir,json=isDir,proto3" json:"is_dir,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileInfo) Reset() { + *x = FileInfo{} + mi := &file_volume_pb_volume_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileInfo) ProtoMessage() {} + +func (x *FileInfo) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileInfo.ProtoReflect.Descriptor instead. +func (*FileInfo) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{0} +} + +func (x *FileInfo) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +func (x *FileInfo) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *FileInfo) GetMtime() int64 { + if x != nil { + return x.Mtime + } + return 0 +} + +func (x *FileInfo) GetMode() uint32 { + if x != nil { + return x.Mode + } + return 0 +} + +func (x *FileInfo) GetIsDir() bool { + if x != nil { + return x.IsDir + } + return false +} + +type SyncManifest struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + Files []*FileInfo `protobuf:"bytes,2,rep,name=files,proto3" json:"files,omitempty"` + ForceFull bool `protobuf:"varint,3,opt,name=force_full,json=forceFull,proto3" json:"force_full,omitempty"` // skip snapshot cache, diff against actual disk + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SyncManifest) Reset() { + *x = SyncManifest{} + mi := &file_volume_pb_volume_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SyncManifest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SyncManifest) ProtoMessage() {} + +func (x *SyncManifest) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SyncManifest.ProtoReflect.Descriptor instead. +func (*SyncManifest) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{1} +} + +func (x *SyncManifest) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *SyncManifest) GetFiles() []*FileInfo { + if x != nil { + return x.Files + } + return nil +} + +func (x *SyncManifest) GetForceFull() bool { + if x != nil { + return x.ForceFull + } + return false +} + +type SyncMessage struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Types that are valid to be assigned to Payload: + // + // *SyncMessage_Manifest + // *SyncMessage_Diff + // *SyncMessage_Chunk + // *SyncMessage_Result + Payload isSyncMessage_Payload `protobuf_oneof:"payload"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SyncMessage) Reset() { + *x = SyncMessage{} + mi := &file_volume_pb_volume_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SyncMessage) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SyncMessage) ProtoMessage() {} + +func (x *SyncMessage) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SyncMessage.ProtoReflect.Descriptor instead. +func (*SyncMessage) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{2} +} + +func (x *SyncMessage) GetPayload() isSyncMessage_Payload { + if x != nil { + return x.Payload + } + return nil +} + +func (x *SyncMessage) GetManifest() *SyncManifest { + if x != nil { + if x, ok := x.Payload.(*SyncMessage_Manifest); ok { + return x.Manifest + } + } + return nil +} + +func (x *SyncMessage) GetDiff() *SyncDiff { + if x != nil { + if x, ok := x.Payload.(*SyncMessage_Diff); ok { + return x.Diff + } + } + return nil +} + +func (x *SyncMessage) GetChunk() *FileChunk { + if x != nil { + if x, ok := x.Payload.(*SyncMessage_Chunk); ok { + return x.Chunk + } + } + return nil +} + +func (x *SyncMessage) GetResult() *SyncResult { + if x != nil { + if x, ok := x.Payload.(*SyncMessage_Result); ok { + return x.Result + } + } + return nil +} + +type isSyncMessage_Payload interface { + isSyncMessage_Payload() +} + +type SyncMessage_Manifest struct { + Manifest *SyncManifest `protobuf:"bytes,1,opt,name=manifest,proto3,oneof"` +} + +type SyncMessage_Diff struct { + Diff *SyncDiff `protobuf:"bytes,2,opt,name=diff,proto3,oneof"` +} + +type SyncMessage_Chunk struct { + Chunk *FileChunk `protobuf:"bytes,3,opt,name=chunk,proto3,oneof"` +} + +type SyncMessage_Result struct { + Result *SyncResult `protobuf:"bytes,4,opt,name=result,proto3,oneof"` +} + +func (*SyncMessage_Manifest) isSyncMessage_Payload() {} + +func (*SyncMessage_Diff) isSyncMessage_Payload() {} + +func (*SyncMessage_Chunk) isSyncMessage_Payload() {} + +func (*SyncMessage_Result) isSyncMessage_Payload() {} + +type SyncDiff struct { + state protoimpl.MessageState `protogen:"open.v1"` + NeedFiles []string `protobuf:"bytes,1,rep,name=need_files,json=needFiles,proto3" json:"need_files,omitempty"` // paths needing full transfer + DeleteFiles []string `protobuf:"bytes,2,rep,name=delete_files,json=deleteFiles,proto3" json:"delete_files,omitempty"` // paths Tai should delete + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SyncDiff) Reset() { + *x = SyncDiff{} + mi := &file_volume_pb_volume_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SyncDiff) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SyncDiff) ProtoMessage() {} + +func (x *SyncDiff) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SyncDiff.ProtoReflect.Descriptor instead. +func (*SyncDiff) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{3} +} + +func (x *SyncDiff) GetNeedFiles() []string { + if x != nil { + return x.NeedFiles + } + return nil +} + +func (x *SyncDiff) GetDeleteFiles() []string { + if x != nil { + return x.DeleteFiles + } + return nil +} + +type FileChunk struct { + state protoimpl.MessageState `protogen:"open.v1"` + Path string `protobuf:"bytes,1,opt,name=path,proto3" json:"path,omitempty"` + Type FileChunk_ChunkType `protobuf:"varint,2,opt,name=type,proto3,enum=volume.FileChunk_ChunkType" json:"type,omitempty"` + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` // lz4 compressed (V1: always FULL) + Mode uint32 `protobuf:"varint,4,opt,name=mode,proto3" json:"mode,omitempty"` // file mode (first chunk only) + Mtime int64 `protobuf:"varint,5,opt,name=mtime,proto3" json:"mtime,omitempty"` // modification time (first chunk only) + Eof bool `protobuf:"varint,6,opt,name=eof,proto3" json:"eof,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileChunk) Reset() { + *x = FileChunk{} + mi := &file_volume_pb_volume_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileChunk) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileChunk) ProtoMessage() {} + +func (x *FileChunk) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileChunk.ProtoReflect.Descriptor instead. +func (*FileChunk) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{4} +} + +func (x *FileChunk) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +func (x *FileChunk) GetType() FileChunk_ChunkType { + if x != nil { + return x.Type + } + return FileChunk_FULL +} + +func (x *FileChunk) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *FileChunk) GetMode() uint32 { + if x != nil { + return x.Mode + } + return 0 +} + +func (x *FileChunk) GetMtime() int64 { + if x != nil { + return x.Mtime + } + return 0 +} + +func (x *FileChunk) GetEof() bool { + if x != nil { + return x.Eof + } + return false +} + +type SyncResult struct { + state protoimpl.MessageState `protogen:"open.v1"` + FilesSynced int32 `protobuf:"varint,1,opt,name=files_synced,json=filesSynced,proto3" json:"files_synced,omitempty"` + BytesTransferred int64 `protobuf:"varint,2,opt,name=bytes_transferred,json=bytesTransferred,proto3" json:"bytes_transferred,omitempty"` + DurationMs int64 `protobuf:"varint,3,opt,name=duration_ms,json=durationMs,proto3" json:"duration_ms,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SyncResult) Reset() { + *x = SyncResult{} + mi := &file_volume_pb_volume_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SyncResult) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SyncResult) ProtoMessage() {} + +func (x *SyncResult) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SyncResult.ProtoReflect.Descriptor instead. +func (*SyncResult) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{5} +} + +func (x *SyncResult) GetFilesSynced() int32 { + if x != nil { + return x.FilesSynced + } + return 0 +} + +func (x *SyncResult) GetBytesTransferred() int64 { + if x != nil { + return x.BytesTransferred + } + return 0 +} + +func (x *SyncResult) GetDurationMs() int64 { + if x != nil { + return x.DurationMs + } + return 0 +} + +type FSRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSRequest) Reset() { + *x = FSRequest{} + mi := &file_volume_pb_volume_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSRequest) ProtoMessage() {} + +func (x *FSRequest) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSRequest.ProtoReflect.Descriptor instead. +func (*FSRequest) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{6} +} + +func (x *FSRequest) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *FSRequest) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +type FSOpResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Ok bool `protobuf:"varint,1,opt,name=ok,proto3" json:"ok,omitempty"` + Error string `protobuf:"bytes,2,opt,name=error,proto3" json:"error,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSOpResponse) Reset() { + *x = FSOpResponse{} + mi := &file_volume_pb_volume_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSOpResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSOpResponse) ProtoMessage() {} + +func (x *FSOpResponse) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSOpResponse.ProtoReflect.Descriptor instead. +func (*FSOpResponse) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{7} +} + +func (x *FSOpResponse) GetOk() bool { + if x != nil { + return x.Ok + } + return false +} + +func (x *FSOpResponse) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +type FSReadRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSReadRequest) Reset() { + *x = FSReadRequest{} + mi := &file_volume_pb_volume_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSReadRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSReadRequest) ProtoMessage() {} + +func (x *FSReadRequest) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSReadRequest.ProtoReflect.Descriptor instead. +func (*FSReadRequest) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{8} +} + +func (x *FSReadRequest) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *FSReadRequest) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +type FSDataChunk struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` // up to 64KB per message + Mode uint32 `protobuf:"varint,2,opt,name=mode,proto3" json:"mode,omitempty"` // first chunk only + Size int64 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"` // total file size (first chunk only) + Mtime int64 `protobuf:"varint,4,opt,name=mtime,proto3" json:"mtime,omitempty"` // modification time (first chunk only) + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSDataChunk) Reset() { + *x = FSDataChunk{} + mi := &file_volume_pb_volume_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSDataChunk) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSDataChunk) ProtoMessage() {} + +func (x *FSDataChunk) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[9] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSDataChunk.ProtoReflect.Descriptor instead. +func (*FSDataChunk) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{9} +} + +func (x *FSDataChunk) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *FSDataChunk) GetMode() uint32 { + if x != nil { + return x.Mode + } + return 0 +} + +func (x *FSDataChunk) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +func (x *FSDataChunk) GetMtime() int64 { + if x != nil { + return x.Mtime + } + return 0 +} + +type FSWriteChunk struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` // first chunk only + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` // first chunk only + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + Mode uint32 `protobuf:"varint,4,opt,name=mode,proto3" json:"mode,omitempty"` // first chunk only, 0 = keep existing + CreateDirs bool `protobuf:"varint,5,opt,name=create_dirs,json=createDirs,proto3" json:"create_dirs,omitempty"` // auto-create parent directories (first chunk only) + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSWriteChunk) Reset() { + *x = FSWriteChunk{} + mi := &file_volume_pb_volume_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSWriteChunk) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSWriteChunk) ProtoMessage() {} + +func (x *FSWriteChunk) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[10] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSWriteChunk.ProtoReflect.Descriptor instead. +func (*FSWriteChunk) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{10} +} + +func (x *FSWriteChunk) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *FSWriteChunk) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +func (x *FSWriteChunk) GetData() []byte { + if x != nil { + return x.Data + } + return nil +} + +func (x *FSWriteChunk) GetMode() uint32 { + if x != nil { + return x.Mode + } + return 0 +} + +func (x *FSWriteChunk) GetCreateDirs() bool { + if x != nil { + return x.CreateDirs + } + return false +} + +type FSWriteResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Size int64 `protobuf:"varint,1,opt,name=size,proto3" json:"size,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSWriteResponse) Reset() { + *x = FSWriteResponse{} + mi := &file_volume_pb_volume_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSWriteResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSWriteResponse) ProtoMessage() {} + +func (x *FSWriteResponse) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[11] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSWriteResponse.ProtoReflect.Descriptor instead. +func (*FSWriteResponse) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{11} +} + +func (x *FSWriteResponse) GetSize() int64 { + if x != nil { + return x.Size + } + return 0 +} + +type FSListResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Entries []*FileInfo `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSListResponse) Reset() { + *x = FSListResponse{} + mi := &file_volume_pb_volume_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSListResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSListResponse) ProtoMessage() {} + +func (x *FSListResponse) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSListResponse.ProtoReflect.Descriptor instead. +func (*FSListResponse) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{12} +} + +func (x *FSListResponse) GetEntries() []*FileInfo { + if x != nil { + return x.Entries + } + return nil +} + +type FSRemoveRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + Path string `protobuf:"bytes,2,opt,name=path,proto3" json:"path,omitempty"` + Recursive bool `protobuf:"varint,3,opt,name=recursive,proto3" json:"recursive,omitempty"` // true = RemoveAll, false = Remove + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSRemoveRequest) Reset() { + *x = FSRemoveRequest{} + mi := &file_volume_pb_volume_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSRemoveRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSRemoveRequest) ProtoMessage() {} + +func (x *FSRemoveRequest) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSRemoveRequest.ProtoReflect.Descriptor instead. +func (*FSRemoveRequest) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{13} +} + +func (x *FSRemoveRequest) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *FSRemoveRequest) GetPath() string { + if x != nil { + return x.Path + } + return "" +} + +func (x *FSRemoveRequest) GetRecursive() bool { + if x != nil { + return x.Recursive + } + return false +} + +type FSRenameRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + SessionId string `protobuf:"bytes,1,opt,name=session_id,json=sessionId,proto3" json:"session_id,omitempty"` + OldPath string `protobuf:"bytes,2,opt,name=old_path,json=oldPath,proto3" json:"old_path,omitempty"` + NewPath string `protobuf:"bytes,3,opt,name=new_path,json=newPath,proto3" json:"new_path,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FSRenameRequest) Reset() { + *x = FSRenameRequest{} + mi := &file_volume_pb_volume_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FSRenameRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FSRenameRequest) ProtoMessage() {} + +func (x *FSRenameRequest) ProtoReflect() protoreflect.Message { + mi := &file_volume_pb_volume_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FSRenameRequest.ProtoReflect.Descriptor instead. +func (*FSRenameRequest) Descriptor() ([]byte, []int) { + return file_volume_pb_volume_proto_rawDescGZIP(), []int{14} +} + +func (x *FSRenameRequest) GetSessionId() string { + if x != nil { + return x.SessionId + } + return "" +} + +func (x *FSRenameRequest) GetOldPath() string { + if x != nil { + return x.OldPath + } + return "" +} + +func (x *FSRenameRequest) GetNewPath() string { + if x != nil { + return x.NewPath + } + return "" +} + +var File_volume_pb_volume_proto protoreflect.FileDescriptor + +const file_volume_pb_volume_proto_rawDesc = "" + + "\n" + + "\x16volume/pb/volume.proto\x12\x06volume\"s\n" + + "\bFileInfo\x12\x12\n" + + "\x04path\x18\x01 \x01(\tR\x04path\x12\x12\n" + + "\x04size\x18\x02 \x01(\x03R\x04size\x12\x14\n" + + "\x05mtime\x18\x03 \x01(\x03R\x05mtime\x12\x12\n" + + "\x04mode\x18\x04 \x01(\rR\x04mode\x12\x15\n" + + "\x06is_dir\x18\x05 \x01(\bR\x05isDir\"t\n" + + "\fSyncManifest\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12&\n" + + "\x05files\x18\x02 \x03(\v2\x10.volume.FileInfoR\x05files\x12\x1d\n" + + "\n" + + "force_full\x18\x03 \x01(\bR\tforceFull\"\xcd\x01\n" + + "\vSyncMessage\x122\n" + + "\bmanifest\x18\x01 \x01(\v2\x14.volume.SyncManifestH\x00R\bmanifest\x12&\n" + + "\x04diff\x18\x02 \x01(\v2\x10.volume.SyncDiffH\x00R\x04diff\x12)\n" + + "\x05chunk\x18\x03 \x01(\v2\x11.volume.FileChunkH\x00R\x05chunk\x12,\n" + + "\x06result\x18\x04 \x01(\v2\x12.volume.SyncResultH\x00R\x06resultB\t\n" + + "\apayload\"L\n" + + "\bSyncDiff\x12\x1d\n" + + "\n" + + "need_files\x18\x01 \x03(\tR\tneedFiles\x12!\n" + + "\fdelete_files\x18\x02 \x03(\tR\vdeleteFiles\"\xd9\x01\n" + + "\tFileChunk\x12\x12\n" + + "\x04path\x18\x01 \x01(\tR\x04path\x12/\n" + + "\x04type\x18\x02 \x01(\x0e2\x1b.volume.FileChunk.ChunkTypeR\x04type\x12\x12\n" + + "\x04data\x18\x03 \x01(\fR\x04data\x12\x12\n" + + "\x04mode\x18\x04 \x01(\rR\x04mode\x12\x14\n" + + "\x05mtime\x18\x05 \x01(\x03R\x05mtime\x12\x10\n" + + "\x03eof\x18\x06 \x01(\bR\x03eof\"7\n" + + "\tChunkType\x12\b\n" + + "\x04FULL\x10\x00\x12\t\n" + + "\x05DELTA\x10\x01\x12\n" + + "\n" + + "\x06DELETE\x10\x02\x12\t\n" + + "\x05MKDIR\x10\x03\"}\n" + + "\n" + + "SyncResult\x12!\n" + + "\ffiles_synced\x18\x01 \x01(\x05R\vfilesSynced\x12+\n" + + "\x11bytes_transferred\x18\x02 \x01(\x03R\x10bytesTransferred\x12\x1f\n" + + "\vduration_ms\x18\x03 \x01(\x03R\n" + + "durationMs\">\n" + + "\tFSRequest\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x12\n" + + "\x04path\x18\x02 \x01(\tR\x04path\"4\n" + + "\fFSOpResponse\x12\x0e\n" + + "\x02ok\x18\x01 \x01(\bR\x02ok\x12\x14\n" + + "\x05error\x18\x02 \x01(\tR\x05error\"B\n" + + "\rFSReadRequest\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x12\n" + + "\x04path\x18\x02 \x01(\tR\x04path\"_\n" + + "\vFSDataChunk\x12\x12\n" + + "\x04data\x18\x01 \x01(\fR\x04data\x12\x12\n" + + "\x04mode\x18\x02 \x01(\rR\x04mode\x12\x12\n" + + "\x04size\x18\x03 \x01(\x03R\x04size\x12\x14\n" + + "\x05mtime\x18\x04 \x01(\x03R\x05mtime\"\x8a\x01\n" + + "\fFSWriteChunk\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x12\n" + + "\x04path\x18\x02 \x01(\tR\x04path\x12\x12\n" + + "\x04data\x18\x03 \x01(\fR\x04data\x12\x12\n" + + "\x04mode\x18\x04 \x01(\rR\x04mode\x12\x1f\n" + + "\vcreate_dirs\x18\x05 \x01(\bR\n" + + "createDirs\"%\n" + + "\x0fFSWriteResponse\x12\x12\n" + + "\x04size\x18\x01 \x01(\x03R\x04size\"<\n" + + "\x0eFSListResponse\x12*\n" + + "\aentries\x18\x01 \x03(\v2\x10.volume.FileInfoR\aentries\"b\n" + + "\x0fFSRemoveRequest\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x12\n" + + "\x04path\x18\x02 \x01(\tR\x04path\x12\x1c\n" + + "\trecursive\x18\x03 \x01(\bR\trecursive\"f\n" + + "\x0fFSRenameRequest\x12\x1d\n" + + "\n" + + "session_id\x18\x01 \x01(\tR\tsessionId\x12\x19\n" + + "\bold_path\x18\x02 \x01(\tR\aoldPath\x12\x19\n" + + "\bnew_path\x18\x03 \x01(\tR\anewPath2\xfd\x03\n" + + "\x06Volume\x128\n" + + "\bSyncPush\x12\x13.volume.SyncMessage\x1a\x13.volume.SyncMessage(\x010\x01\x127\n" + + "\bSyncPull\x12\x14.volume.SyncManifest\x1a\x13.volume.SyncMessage0\x01\x128\n" + + "\bReadFile\x12\x15.volume.FSReadRequest\x1a\x13.volume.FSDataChunk0\x01\x12<\n" + + "\tWriteFile\x12\x14.volume.FSWriteChunk\x1a\x17.volume.FSWriteResponse(\x01\x12+\n" + + "\x04Stat\x12\x11.volume.FSRequest\x1a\x10.volume.FileInfo\x124\n" + + "\aListDir\x12\x11.volume.FSRequest\x1a\x16.volume.FSListResponse\x127\n" + + "\x06Remove\x12\x17.volume.FSRemoveRequest\x1a\x14.volume.FSOpResponse\x127\n" + + "\x06Rename\x12\x17.volume.FSRenameRequest\x1a\x14.volume.FSOpResponse\x123\n" + + "\bMkdirAll\x12\x11.volume.FSRequest\x1a\x14.volume.FSOpResponseB!Z\x1fgithub.com/yaoapp/tai/volume/pbb\x06proto3" + +var ( + file_volume_pb_volume_proto_rawDescOnce sync.Once + file_volume_pb_volume_proto_rawDescData []byte +) + +func file_volume_pb_volume_proto_rawDescGZIP() []byte { + file_volume_pb_volume_proto_rawDescOnce.Do(func() { + file_volume_pb_volume_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_volume_pb_volume_proto_rawDesc), len(file_volume_pb_volume_proto_rawDesc))) + }) + return file_volume_pb_volume_proto_rawDescData +} + +var file_volume_pb_volume_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_volume_pb_volume_proto_msgTypes = make([]protoimpl.MessageInfo, 15) +var file_volume_pb_volume_proto_goTypes = []any{ + (FileChunk_ChunkType)(0), // 0: volume.FileChunk.ChunkType + (*FileInfo)(nil), // 1: volume.FileInfo + (*SyncManifest)(nil), // 2: volume.SyncManifest + (*SyncMessage)(nil), // 3: volume.SyncMessage + (*SyncDiff)(nil), // 4: volume.SyncDiff + (*FileChunk)(nil), // 5: volume.FileChunk + (*SyncResult)(nil), // 6: volume.SyncResult + (*FSRequest)(nil), // 7: volume.FSRequest + (*FSOpResponse)(nil), // 8: volume.FSOpResponse + (*FSReadRequest)(nil), // 9: volume.FSReadRequest + (*FSDataChunk)(nil), // 10: volume.FSDataChunk + (*FSWriteChunk)(nil), // 11: volume.FSWriteChunk + (*FSWriteResponse)(nil), // 12: volume.FSWriteResponse + (*FSListResponse)(nil), // 13: volume.FSListResponse + (*FSRemoveRequest)(nil), // 14: volume.FSRemoveRequest + (*FSRenameRequest)(nil), // 15: volume.FSRenameRequest +} +var file_volume_pb_volume_proto_depIdxs = []int32{ + 1, // 0: volume.SyncManifest.files:type_name -> volume.FileInfo + 2, // 1: volume.SyncMessage.manifest:type_name -> volume.SyncManifest + 4, // 2: volume.SyncMessage.diff:type_name -> volume.SyncDiff + 5, // 3: volume.SyncMessage.chunk:type_name -> volume.FileChunk + 6, // 4: volume.SyncMessage.result:type_name -> volume.SyncResult + 0, // 5: volume.FileChunk.type:type_name -> volume.FileChunk.ChunkType + 1, // 6: volume.FSListResponse.entries:type_name -> volume.FileInfo + 3, // 7: volume.Volume.SyncPush:input_type -> volume.SyncMessage + 2, // 8: volume.Volume.SyncPull:input_type -> volume.SyncManifest + 9, // 9: volume.Volume.ReadFile:input_type -> volume.FSReadRequest + 11, // 10: volume.Volume.WriteFile:input_type -> volume.FSWriteChunk + 7, // 11: volume.Volume.Stat:input_type -> volume.FSRequest + 7, // 12: volume.Volume.ListDir:input_type -> volume.FSRequest + 14, // 13: volume.Volume.Remove:input_type -> volume.FSRemoveRequest + 15, // 14: volume.Volume.Rename:input_type -> volume.FSRenameRequest + 7, // 15: volume.Volume.MkdirAll:input_type -> volume.FSRequest + 3, // 16: volume.Volume.SyncPush:output_type -> volume.SyncMessage + 3, // 17: volume.Volume.SyncPull:output_type -> volume.SyncMessage + 10, // 18: volume.Volume.ReadFile:output_type -> volume.FSDataChunk + 12, // 19: volume.Volume.WriteFile:output_type -> volume.FSWriteResponse + 1, // 20: volume.Volume.Stat:output_type -> volume.FileInfo + 13, // 21: volume.Volume.ListDir:output_type -> volume.FSListResponse + 8, // 22: volume.Volume.Remove:output_type -> volume.FSOpResponse + 8, // 23: volume.Volume.Rename:output_type -> volume.FSOpResponse + 8, // 24: volume.Volume.MkdirAll:output_type -> volume.FSOpResponse + 16, // [16:25] is the sub-list for method output_type + 7, // [7:16] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_volume_pb_volume_proto_init() } +func file_volume_pb_volume_proto_init() { + if File_volume_pb_volume_proto != nil { + return + } + file_volume_pb_volume_proto_msgTypes[2].OneofWrappers = []any{ + (*SyncMessage_Manifest)(nil), + (*SyncMessage_Diff)(nil), + (*SyncMessage_Chunk)(nil), + (*SyncMessage_Result)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_volume_pb_volume_proto_rawDesc), len(file_volume_pb_volume_proto_rawDesc)), + NumEnums: 1, + NumMessages: 15, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_volume_pb_volume_proto_goTypes, + DependencyIndexes: file_volume_pb_volume_proto_depIdxs, + EnumInfos: file_volume_pb_volume_proto_enumTypes, + MessageInfos: file_volume_pb_volume_proto_msgTypes, + }.Build() + File_volume_pb_volume_proto = out.File + file_volume_pb_volume_proto_goTypes = nil + file_volume_pb_volume_proto_depIdxs = nil +} diff --git a/tai/volume/pb/volume.proto b/tai/volume/pb/volume.proto new file mode 100644 index 00000000..c40ea461 --- /dev/null +++ b/tai/volume/pb/volume.proto @@ -0,0 +1,138 @@ +syntax = "proto3"; +package volume; +option go_package = "github.com/yaoapp/tai/volume/pb"; + +// Volume provides bulk file synchronization and real-time filesystem I/O. +// Shares gRPC port :9100 with Yao Gateway. +service Volume { + + // --- Bulk Sync --- + + // SyncPush: Yao sends code to Tai (before container start). + // Bidirectional stream: + // 1. Yao sends SyncManifest (file list with mtime+size) + // 2. Tai diffs, replies with SyncDiff (which files to send) + // 3. Yao sends only needed FileChunks + // 4. Tai replies with SyncResult + rpc SyncPush(stream SyncMessage) returns (stream SyncMessage); + + // SyncPull: Yao pulls changes from Tai (after container stop). + // Yao sends its file manifest; Tai diffs internally and streams back changed files. + rpc SyncPull(SyncManifest) returns (stream SyncMessage); + + // --- Real-Time FS IO --- + + rpc ReadFile(FSReadRequest) returns (stream FSDataChunk); + rpc WriteFile(stream FSWriteChunk) returns (FSWriteResponse); + rpc Stat(FSRequest) returns (FileInfo); + rpc ListDir(FSRequest) returns (FSListResponse); + rpc Remove(FSRemoveRequest) returns (FSOpResponse); + rpc Rename(FSRenameRequest) returns (FSOpResponse); + rpc MkdirAll(FSRequest) returns (FSOpResponse); +} + +// --- File Metadata --- + +message FileInfo { + string path = 1; + int64 size = 2; + int64 mtime = 3; // unix timestamp (nanoseconds) + uint32 mode = 4; + bool is_dir = 5; +} + +// --- Sync Messages --- + +message SyncManifest { + string session_id = 1; + repeated FileInfo files = 2; + bool force_full = 3; // skip snapshot cache, diff against actual disk +} + +message SyncMessage { + oneof payload { + SyncManifest manifest = 1; + SyncDiff diff = 2; + FileChunk chunk = 3; + SyncResult result = 4; + } +} + +message SyncDiff { + repeated string need_files = 1; // paths needing full transfer + repeated string delete_files = 2; // paths Tai should delete +} + +message FileChunk { + string path = 1; + ChunkType type = 2; + bytes data = 3; // lz4 compressed (V1: always FULL) + uint32 mode = 4; // file mode (first chunk only) + int64 mtime = 5; // modification time (first chunk only) + bool eof = 6; + + enum ChunkType { + FULL = 0; + DELTA = 1; // reserved for future rsync delta + DELETE = 2; + MKDIR = 3; + } +} + +message SyncResult { + int32 files_synced = 1; + int64 bytes_transferred = 2; + int64 duration_ms = 3; +} + +// --- FS IO Messages --- + +message FSRequest { + string session_id = 1; + string path = 2; +} + +message FSOpResponse { + bool ok = 1; + string error = 2; +} + +message FSReadRequest { + string session_id = 1; + string path = 2; +} + +message FSDataChunk { + bytes data = 1; // up to 64KB per message + uint32 mode = 2; // first chunk only + int64 size = 3; // total file size (first chunk only) + int64 mtime = 4; // modification time (first chunk only) +} + +message FSWriteChunk { + string session_id = 1; // first chunk only + string path = 2; // first chunk only + bytes data = 3; + uint32 mode = 4; // first chunk only, 0 = keep existing + bool create_dirs = 5; // auto-create parent directories (first chunk only) +} + +message FSWriteResponse { + int64 size = 1; +} + +message FSListResponse { + repeated FileInfo entries = 1; +} + +message FSRemoveRequest { + string session_id = 1; + string path = 2; + bool recursive = 3; // true = RemoveAll, false = Remove +} + +message FSRenameRequest { + string session_id = 1; + string old_path = 2; + string new_path = 3; +} diff --git a/tai/volume/pb/volume_grpc.pb.go b/tai/volume/pb/volume_grpc.pb.go new file mode 100644 index 00000000..ac253cb3 --- /dev/null +++ b/tai/volume/pb/volume_grpc.pb.go @@ -0,0 +1,441 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.6.1 +// - protoc v4.25.0 +// source: volume/pb/volume.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Volume_SyncPush_FullMethodName = "/volume.Volume/SyncPush" + Volume_SyncPull_FullMethodName = "/volume.Volume/SyncPull" + Volume_ReadFile_FullMethodName = "/volume.Volume/ReadFile" + Volume_WriteFile_FullMethodName = "/volume.Volume/WriteFile" + Volume_Stat_FullMethodName = "/volume.Volume/Stat" + Volume_ListDir_FullMethodName = "/volume.Volume/ListDir" + Volume_Remove_FullMethodName = "/volume.Volume/Remove" + Volume_Rename_FullMethodName = "/volume.Volume/Rename" + Volume_MkdirAll_FullMethodName = "/volume.Volume/MkdirAll" +) + +// VolumeClient is the client API for Volume service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// Volume provides bulk file synchronization and real-time filesystem I/O. +// Shares gRPC port :9100 with Yao Gateway. +type VolumeClient interface { + // SyncPush: Yao sends code to Tai (before container start). + // Bidirectional stream: + // 1. Yao sends SyncManifest (file list with mtime+size) + // 2. Tai diffs, replies with SyncDiff (which files to send) + // 3. Yao sends only needed FileChunks + // 4. Tai replies with SyncResult + SyncPush(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[SyncMessage, SyncMessage], error) + // SyncPull: Yao pulls changes from Tai (after container stop). + // Yao sends its file manifest; Tai diffs internally and streams back changed files. + SyncPull(ctx context.Context, in *SyncManifest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[SyncMessage], error) + ReadFile(ctx context.Context, in *FSReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[FSDataChunk], error) + WriteFile(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[FSWriteChunk, FSWriteResponse], error) + Stat(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FileInfo, error) + ListDir(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FSListResponse, error) + Remove(ctx context.Context, in *FSRemoveRequest, opts ...grpc.CallOption) (*FSOpResponse, error) + Rename(ctx context.Context, in *FSRenameRequest, opts ...grpc.CallOption) (*FSOpResponse, error) + MkdirAll(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FSOpResponse, error) +} + +type volumeClient struct { + cc grpc.ClientConnInterface +} + +func NewVolumeClient(cc grpc.ClientConnInterface) VolumeClient { + return &volumeClient{cc} +} + +func (c *volumeClient) SyncPush(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[SyncMessage, SyncMessage], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Volume_ServiceDesc.Streams[0], Volume_SyncPush_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[SyncMessage, SyncMessage]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_SyncPushClient = grpc.BidiStreamingClient[SyncMessage, SyncMessage] + +func (c *volumeClient) SyncPull(ctx context.Context, in *SyncManifest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[SyncMessage], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Volume_ServiceDesc.Streams[1], Volume_SyncPull_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[SyncManifest, SyncMessage]{ClientStream: stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_SyncPullClient = grpc.ServerStreamingClient[SyncMessage] + +func (c *volumeClient) ReadFile(ctx context.Context, in *FSReadRequest, opts ...grpc.CallOption) (grpc.ServerStreamingClient[FSDataChunk], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Volume_ServiceDesc.Streams[2], Volume_ReadFile_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[FSReadRequest, FSDataChunk]{ClientStream: stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_ReadFileClient = grpc.ServerStreamingClient[FSDataChunk] + +func (c *volumeClient) WriteFile(ctx context.Context, opts ...grpc.CallOption) (grpc.ClientStreamingClient[FSWriteChunk, FSWriteResponse], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Volume_ServiceDesc.Streams[3], Volume_WriteFile_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[FSWriteChunk, FSWriteResponse]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_WriteFileClient = grpc.ClientStreamingClient[FSWriteChunk, FSWriteResponse] + +func (c *volumeClient) Stat(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FileInfo, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FileInfo) + err := c.cc.Invoke(ctx, Volume_Stat_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *volumeClient) ListDir(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FSListResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FSListResponse) + err := c.cc.Invoke(ctx, Volume_ListDir_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *volumeClient) Remove(ctx context.Context, in *FSRemoveRequest, opts ...grpc.CallOption) (*FSOpResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FSOpResponse) + err := c.cc.Invoke(ctx, Volume_Remove_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *volumeClient) Rename(ctx context.Context, in *FSRenameRequest, opts ...grpc.CallOption) (*FSOpResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FSOpResponse) + err := c.cc.Invoke(ctx, Volume_Rename_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *volumeClient) MkdirAll(ctx context.Context, in *FSRequest, opts ...grpc.CallOption) (*FSOpResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(FSOpResponse) + err := c.cc.Invoke(ctx, Volume_MkdirAll_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// VolumeServer is the server API for Volume service. +// All implementations must embed UnimplementedVolumeServer +// for forward compatibility. +// +// Volume provides bulk file synchronization and real-time filesystem I/O. +// Shares gRPC port :9100 with Yao Gateway. +type VolumeServer interface { + // SyncPush: Yao sends code to Tai (before container start). + // Bidirectional stream: + // 1. Yao sends SyncManifest (file list with mtime+size) + // 2. Tai diffs, replies with SyncDiff (which files to send) + // 3. Yao sends only needed FileChunks + // 4. Tai replies with SyncResult + SyncPush(grpc.BidiStreamingServer[SyncMessage, SyncMessage]) error + // SyncPull: Yao pulls changes from Tai (after container stop). + // Yao sends its file manifest; Tai diffs internally and streams back changed files. + SyncPull(*SyncManifest, grpc.ServerStreamingServer[SyncMessage]) error + ReadFile(*FSReadRequest, grpc.ServerStreamingServer[FSDataChunk]) error + WriteFile(grpc.ClientStreamingServer[FSWriteChunk, FSWriteResponse]) error + Stat(context.Context, *FSRequest) (*FileInfo, error) + ListDir(context.Context, *FSRequest) (*FSListResponse, error) + Remove(context.Context, *FSRemoveRequest) (*FSOpResponse, error) + Rename(context.Context, *FSRenameRequest) (*FSOpResponse, error) + MkdirAll(context.Context, *FSRequest) (*FSOpResponse, error) + mustEmbedUnimplementedVolumeServer() +} + +// UnimplementedVolumeServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedVolumeServer struct{} + +func (UnimplementedVolumeServer) SyncPush(grpc.BidiStreamingServer[SyncMessage, SyncMessage]) error { + return status.Error(codes.Unimplemented, "method SyncPush not implemented") +} +func (UnimplementedVolumeServer) SyncPull(*SyncManifest, grpc.ServerStreamingServer[SyncMessage]) error { + return status.Error(codes.Unimplemented, "method SyncPull not implemented") +} +func (UnimplementedVolumeServer) ReadFile(*FSReadRequest, grpc.ServerStreamingServer[FSDataChunk]) error { + return status.Error(codes.Unimplemented, "method ReadFile not implemented") +} +func (UnimplementedVolumeServer) WriteFile(grpc.ClientStreamingServer[FSWriteChunk, FSWriteResponse]) error { + return status.Error(codes.Unimplemented, "method WriteFile not implemented") +} +func (UnimplementedVolumeServer) Stat(context.Context, *FSRequest) (*FileInfo, error) { + return nil, status.Error(codes.Unimplemented, "method Stat not implemented") +} +func (UnimplementedVolumeServer) ListDir(context.Context, *FSRequest) (*FSListResponse, error) { + return nil, status.Error(codes.Unimplemented, "method ListDir not implemented") +} +func (UnimplementedVolumeServer) Remove(context.Context, *FSRemoveRequest) (*FSOpResponse, error) { + return nil, status.Error(codes.Unimplemented, "method Remove not implemented") +} +func (UnimplementedVolumeServer) Rename(context.Context, *FSRenameRequest) (*FSOpResponse, error) { + return nil, status.Error(codes.Unimplemented, "method Rename not implemented") +} +func (UnimplementedVolumeServer) MkdirAll(context.Context, *FSRequest) (*FSOpResponse, error) { + return nil, status.Error(codes.Unimplemented, "method MkdirAll not implemented") +} +func (UnimplementedVolumeServer) mustEmbedUnimplementedVolumeServer() {} +func (UnimplementedVolumeServer) testEmbeddedByValue() {} + +// UnsafeVolumeServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to VolumeServer will +// result in compilation errors. +type UnsafeVolumeServer interface { + mustEmbedUnimplementedVolumeServer() +} + +func RegisterVolumeServer(s grpc.ServiceRegistrar, srv VolumeServer) { + // If the following call panics, it indicates UnimplementedVolumeServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Volume_ServiceDesc, srv) +} + +func _Volume_SyncPush_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(VolumeServer).SyncPush(&grpc.GenericServerStream[SyncMessage, SyncMessage]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_SyncPushServer = grpc.BidiStreamingServer[SyncMessage, SyncMessage] + +func _Volume_SyncPull_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(SyncManifest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(VolumeServer).SyncPull(m, &grpc.GenericServerStream[SyncManifest, SyncMessage]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_SyncPullServer = grpc.ServerStreamingServer[SyncMessage] + +func _Volume_ReadFile_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(FSReadRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(VolumeServer).ReadFile(m, &grpc.GenericServerStream[FSReadRequest, FSDataChunk]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_ReadFileServer = grpc.ServerStreamingServer[FSDataChunk] + +func _Volume_WriteFile_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(VolumeServer).WriteFile(&grpc.GenericServerStream[FSWriteChunk, FSWriteResponse]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Volume_WriteFileServer = grpc.ClientStreamingServer[FSWriteChunk, FSWriteResponse] + +func _Volume_Stat_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FSRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VolumeServer).Stat(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Volume_Stat_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VolumeServer).Stat(ctx, req.(*FSRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Volume_ListDir_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FSRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VolumeServer).ListDir(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Volume_ListDir_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VolumeServer).ListDir(ctx, req.(*FSRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Volume_Remove_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FSRemoveRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VolumeServer).Remove(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Volume_Remove_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VolumeServer).Remove(ctx, req.(*FSRemoveRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Volume_Rename_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FSRenameRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VolumeServer).Rename(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Volume_Rename_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VolumeServer).Rename(ctx, req.(*FSRenameRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Volume_MkdirAll_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FSRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VolumeServer).MkdirAll(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Volume_MkdirAll_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VolumeServer).MkdirAll(ctx, req.(*FSRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// Volume_ServiceDesc is the grpc.ServiceDesc for Volume service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Volume_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "volume.Volume", + HandlerType: (*VolumeServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Stat", + Handler: _Volume_Stat_Handler, + }, + { + MethodName: "ListDir", + Handler: _Volume_ListDir_Handler, + }, + { + MethodName: "Remove", + Handler: _Volume_Remove_Handler, + }, + { + MethodName: "Rename", + Handler: _Volume_Rename_Handler, + }, + { + MethodName: "MkdirAll", + Handler: _Volume_MkdirAll_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "SyncPush", + Handler: _Volume_SyncPush_Handler, + ServerStreams: true, + ClientStreams: true, + }, + { + StreamName: "SyncPull", + Handler: _Volume_SyncPull_Handler, + ServerStreams: true, + }, + { + StreamName: "ReadFile", + Handler: _Volume_ReadFile_Handler, + ServerStreams: true, + }, + { + StreamName: "WriteFile", + Handler: _Volume_WriteFile_Handler, + ClientStreams: true, + }, + }, + Metadata: "volume/pb/volume.proto", +} diff --git a/tai/volume/remote.go b/tai/volume/remote.go new file mode 100644 index 00000000..315db6a2 --- /dev/null +++ b/tai/volume/remote.go @@ -0,0 +1,469 @@ +package volume + +import ( + "bytes" + "context" + "fmt" + "io" + "io/fs" + "os" + "path/filepath" + "time" + + "github.com/pierrec/lz4/v4" + pb "github.com/yaoapp/yao/tai/volume/pb" + "google.golang.org/grpc" +) + +const ( + grpcReadChunk = 64 * 1024 // 64KB per FS IO message + grpcSyncChunk = 256 * 1024 // 256KB per sync message +) + +type remoteStorage struct { + conn *grpc.ClientConn + client pb.VolumeClient +} + +// NewRemote creates a Volume backed by gRPC calls to a Tai server. +func NewRemote(conn *grpc.ClientConn) Volume { + return &remoteStorage{ + conn: conn, + client: pb.NewVolumeClient(conn), + } +} + +func (r *remoteStorage) ReadFile(ctx context.Context, sessionID, path string) ([]byte, os.FileMode, error) { + stream, err := r.client.ReadFile(ctx, &pb.FSReadRequest{ + SessionId: sessionID, + Path: path, + }) + if err != nil { + return nil, 0, err + } + + var buf bytes.Buffer + var mode os.FileMode + first := true + for { + chunk, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + return nil, 0, err + } + buf.Write(chunk.Data) + if first { + mode = os.FileMode(chunk.Mode) + first = false + } + } + return buf.Bytes(), mode, nil +} + +func (r *remoteStorage) WriteFile(ctx context.Context, sessionID, path string, data []byte, perm os.FileMode) error { + stream, err := r.client.WriteFile(ctx) + if err != nil { + return err + } + + for offset := 0; offset <= len(data); offset += grpcReadChunk { + end := offset + grpcReadChunk + if end > len(data) { + end = len(data) + } + + chunk := &pb.FSWriteChunk{Data: data[offset:end]} + if offset == 0 { + chunk.SessionId = sessionID + chunk.Path = path + chunk.Mode = uint32(perm) + chunk.CreateDirs = true + } + + if err := stream.Send(chunk); err != nil { + return err + } + if end == len(data) && offset > 0 { + break + } + if offset == 0 && len(data) == 0 { + break + } + } + + _, err = stream.CloseAndRecv() + return err +} + +func (r *remoteStorage) Stat(ctx context.Context, sessionID, path string) (*FileInfo, error) { + info, err := r.client.Stat(ctx, &pb.FSRequest{ + SessionId: sessionID, + Path: path, + }) + if err != nil { + return nil, err + } + return pbToFileInfo(info), nil +} + +func (r *remoteStorage) ListDir(ctx context.Context, sessionID, path string) ([]FileInfo, error) { + resp, err := r.client.ListDir(ctx, &pb.FSRequest{ + SessionId: sessionID, + Path: path, + }) + if err != nil { + return nil, err + } + result := make([]FileInfo, 0, len(resp.Entries)) + for _, e := range resp.Entries { + result = append(result, *pbToFileInfo(e)) + } + return result, nil +} + +func (r *remoteStorage) Remove(ctx context.Context, sessionID, path string, recursive bool) error { + resp, err := r.client.Remove(ctx, &pb.FSRemoveRequest{ + SessionId: sessionID, + Path: path, + Recursive: recursive, + }) + if err != nil { + return err + } + if !resp.Ok { + return fmt.Errorf("remove: %s", resp.Error) + } + return nil +} + +func (r *remoteStorage) Rename(ctx context.Context, sessionID, oldPath, newPath string) error { + resp, err := r.client.Rename(ctx, &pb.FSRenameRequest{ + SessionId: sessionID, + OldPath: oldPath, + NewPath: newPath, + }) + if err != nil { + return err + } + if !resp.Ok { + return fmt.Errorf("rename: %s", resp.Error) + } + return nil +} + +func (r *remoteStorage) MkdirAll(ctx context.Context, sessionID, path string) error { + resp, err := r.client.MkdirAll(ctx, &pb.FSRequest{ + SessionId: sessionID, + Path: path, + }) + if err != nil { + return err + } + if !resp.Ok { + return fmt.Errorf("mkdir: %s", resp.Error) + } + return nil +} + +// SyncPush sends local files to Tai using the manifest-first bidi streaming protocol. +func (r *remoteStorage) SyncPush(ctx context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) { + start := time.Now() + cfg := applySyncOpts(opts) + + // Scan local directory + var manifest []*pb.FileInfo + err := filepath.WalkDir(localDir, func(abs string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + rel, _ := filepath.Rel(localDir, abs) + if rel == "." { + return nil + } + rel = filepath.ToSlash(rel) + if isExcluded(rel, d.IsDir(), cfg.excludes) { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + info, err := d.Info() + if err != nil { + return err + } + manifest = append(manifest, &pb.FileInfo{ + Path: rel, + Size: info.Size(), + Mtime: info.ModTime().UnixNano(), + Mode: uint32(info.Mode()), + IsDir: d.IsDir(), + }) + return nil + }) + if err != nil { + return nil, fmt.Errorf("scan local: %w", err) + } + + stream, err := r.client.SyncPush(ctx) + if err != nil { + return nil, err + } + + // Step 1: send manifest + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Manifest{ + Manifest: &pb.SyncManifest{ + SessionId: sessionID, + Files: manifest, + ForceFull: cfg.forceFull, + }, + }, + }); err != nil { + return nil, fmt.Errorf("send manifest: %w", err) + } + + // Step 2: receive diff + msg, err := stream.Recv() + if err != nil { + return nil, fmt.Errorf("recv diff: %w", err) + } + diff := msg.GetDiff() + if diff == nil { + return nil, fmt.Errorf("expected SyncDiff, got %T", msg.Payload) + } + + // Step 3: send needed files + var bytesTransferred int64 + for _, path := range diff.NeedFiles { + abs := filepath.Join(localDir, filepath.FromSlash(path)) + data, err := os.ReadFile(abs) + if err != nil { + continue + } + compressed, err := compress(data) + if err != nil { + continue + } + + info, _ := os.Stat(abs) + for offset := 0; offset < len(compressed); offset += grpcSyncChunk { + end := offset + grpcSyncChunk + if end > len(compressed) { + end = len(compressed) + } + chunk := &pb.FileChunk{ + Path: path, + Type: pb.FileChunk_FULL, + Data: compressed[offset:end], + Eof: end == len(compressed), + } + if offset == 0 && info != nil { + chunk.Mode = uint32(info.Mode()) + chunk.Mtime = info.ModTime().UnixNano() + } + if err := stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{Chunk: chunk}, + }); err != nil { + return nil, err + } + bytesTransferred += int64(len(chunk.Data)) + } + } + + // Send deletes + for _, path := range diff.DeleteFiles { + _ = stream.Send(&pb.SyncMessage{ + Payload: &pb.SyncMessage_Chunk{ + Chunk: &pb.FileChunk{Path: path, Type: pb.FileChunk_DELETE}, + }, + }) + } + + if err := stream.CloseSend(); err != nil { + return nil, err + } + + // Step 4: receive result + msg, err = stream.Recv() + if err != nil { + return nil, fmt.Errorf("recv result: %w", err) + } + result := msg.GetResult() + if result == nil { + return &SyncResult{ + FilesSynced: len(diff.NeedFiles), + BytesTransferred: bytesTransferred, + Duration: time.Since(start), + }, nil + } + + return &SyncResult{ + FilesSynced: int(result.FilesSynced), + BytesTransferred: result.BytesTransferred, + Duration: time.Since(start), + }, nil +} + +// SyncPull receives changed files from Tai. +func (r *remoteStorage) SyncPull(ctx context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) { + start := time.Now() + cfg := applySyncOpts(opts) + + // Build local manifest + var manifest []*pb.FileInfo + _ = filepath.WalkDir(localDir, func(abs string, d fs.DirEntry, err error) error { + if err != nil { + return err + } + rel, _ := filepath.Rel(localDir, abs) + if rel == "." { + return nil + } + rel = filepath.ToSlash(rel) + if isExcluded(rel, d.IsDir(), cfg.excludes) { + if d.IsDir() { + return filepath.SkipDir + } + return nil + } + info, err := d.Info() + if err != nil { + return err + } + manifest = append(manifest, &pb.FileInfo{ + Path: rel, + Size: info.Size(), + Mtime: info.ModTime().UnixNano(), + Mode: uint32(info.Mode()), + IsDir: d.IsDir(), + }) + return nil + }) + + stream, err := r.client.SyncPull(ctx, &pb.SyncManifest{ + SessionId: sessionID, + Files: manifest, + ForceFull: cfg.forceFull, + }) + if err != nil { + return nil, err + } + + buffers := make(map[string][]byte) + modes := make(map[string]os.FileMode) + mtimes := make(map[string]int64) + var synced int + var transferred int64 + + for { + msg, err := stream.Recv() + if err == io.EOF { + break + } + if err != nil { + return nil, err + } + + if result := msg.GetResult(); result != nil { + return &SyncResult{ + FilesSynced: int(result.FilesSynced), + BytesTransferred: result.BytesTransferred, + Duration: time.Since(start), + }, nil + } + + chunk := msg.GetChunk() + if chunk == nil { + continue + } + + switch chunk.Type { + case pb.FileChunk_FULL: + buffers[chunk.Path] = append(buffers[chunk.Path], chunk.Data...) + transferred += int64(len(chunk.Data)) + if chunk.Mode != 0 { + modes[chunk.Path] = os.FileMode(chunk.Mode) + } + if chunk.Mtime != 0 { + mtimes[chunk.Path] = chunk.Mtime + } + + if chunk.Eof { + decompressed, err := decompress(buffers[chunk.Path]) + if err != nil { + delete(buffers, chunk.Path) + continue + } + delete(buffers, chunk.Path) + + target := filepath.Join(localDir, filepath.FromSlash(chunk.Path)) + _ = os.MkdirAll(filepath.Dir(target), 0o755) + + perm := modes[chunk.Path] + if perm == 0 { + perm = 0o644 + } + if err := os.WriteFile(target, decompressed, perm); err != nil { + continue + } + if mt, ok := mtimes[chunk.Path]; ok { + t := time.Unix(0, mt) + _ = os.Chtimes(target, t, t) + } + synced++ + } + + case pb.FileChunk_DELETE: + target := filepath.Join(localDir, filepath.FromSlash(chunk.Path)) + _ = os.RemoveAll(target) + + case pb.FileChunk_MKDIR: + target := filepath.Join(localDir, filepath.FromSlash(chunk.Path)) + _ = os.MkdirAll(target, 0o755) + } + } + + return &SyncResult{ + FilesSynced: synced, + BytesTransferred: transferred, + Duration: time.Since(start), + }, nil +} + +func (r *remoteStorage) Close() error { + return nil +} + +func pbToFileInfo(p *pb.FileInfo) *FileInfo { + return &FileInfo{ + Path: p.Path, + Size: p.Size, + Mtime: time.Unix(0, p.Mtime), + Mode: fs.FileMode(p.Mode), + IsDir: p.IsDir, + } +} + +func compress(src []byte) ([]byte, error) { + var buf bytes.Buffer + w := lz4.NewWriter(&buf) + if _, err := w.Write(src); err != nil { + w.Close() + return nil, err + } + if err := w.Close(); err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +func decompress(src []byte) ([]byte, error) { + r := lz4.NewReader(bytes.NewReader(src)) + var buf bytes.Buffer + if _, err := buf.ReadFrom(r); err != nil { + return nil, err + } + return buf.Bytes(), nil +} diff --git a/tai/volume/volume.go b/tai/volume/volume.go new file mode 100644 index 00000000..a74cf0ee --- /dev/null +++ b/tai/volume/volume.go @@ -0,0 +1,67 @@ +package volume + +import ( + "context" + "io/fs" + "os" + "time" +) + +// Volume provides filesystem IO and directory synchronization. +// Remote connects to Tai gRPC :9100; Local operates directly on disk. +type Volume interface { + ReadFile(ctx context.Context, sessionID, path string) ([]byte, os.FileMode, error) + WriteFile(ctx context.Context, sessionID, path string, data []byte, perm os.FileMode) error + Stat(ctx context.Context, sessionID, path string) (*FileInfo, error) + ListDir(ctx context.Context, sessionID, path string) ([]FileInfo, error) + Remove(ctx context.Context, sessionID, path string, recursive bool) error + Rename(ctx context.Context, sessionID, oldPath, newPath string) error + MkdirAll(ctx context.Context, sessionID, path string) error + + SyncPush(ctx context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) + SyncPull(ctx context.Context, sessionID, localDir string, opts ...SyncOption) (*SyncResult, error) + + Close() error +} + +// FileInfo describes a single file or directory. +type FileInfo struct { + Path string + Size int64 + Mtime time.Time + Mode fs.FileMode + IsDir bool +} + +// SyncResult summarizes a SyncPush or SyncPull operation. +type SyncResult struct { + FilesSynced int + BytesTransferred int64 + Duration time.Duration +} + +// SyncOption configures sync behavior. +type SyncOption func(*syncConfig) + +type syncConfig struct { + forceFull bool + excludes []string +} + +// WithForceFull skips snapshot caches and diffs against actual disk. +func WithForceFull() SyncOption { + return func(c *syncConfig) { c.forceFull = true } +} + +// WithExcludes adds glob patterns to exclude from sync. +func WithExcludes(patterns ...string) SyncOption { + return func(c *syncConfig) { c.excludes = append(c.excludes, patterns...) } +} + +func applySyncOpts(opts []SyncOption) syncConfig { + var cfg syncConfig + for _, o := range opts { + o(&cfg) + } + return cfg +} diff --git a/tai/volume/volume_test.go b/tai/volume/volume_test.go new file mode 100644 index 00000000..116943db --- /dev/null +++ b/tai/volume/volume_test.go @@ -0,0 +1,819 @@ +package volume + +import ( + "context" + "os" + "path/filepath" + "testing" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +func taiTestGRPC() string { + if addr := os.Getenv("TAI_TEST_GRPC"); addr != "" { + return addr + } + return "127.0.0.1:9100" +} + +func TestLocalVolume(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + defer vol.Close() + ctx := context.Background() + sid := "test-session" + + t.Run("WriteFile and ReadFile", func(t *testing.T) { + data := []byte("hello world") + if err := vol.WriteFile(ctx, sid, "greeting.txt", data, 0o644); err != nil { + t.Fatalf("WriteFile: %v", err) + } + got, mode, err := vol.ReadFile(ctx, sid, "greeting.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(got) != "hello world" { + t.Errorf("got %q, want %q", got, "hello world") + } + if mode&0o644 != 0o644 { + t.Errorf("mode %v does not contain 0644", mode) + } + }) + + t.Run("Stat", func(t *testing.T) { + info, err := vol.Stat(ctx, sid, "greeting.txt") + if err != nil { + t.Fatalf("Stat: %v", err) + } + if info.Size != 11 { + t.Errorf("size = %d, want 11", info.Size) + } + if info.IsDir { + t.Error("expected file, got dir") + } + }) + + t.Run("MkdirAll and ListDir", func(t *testing.T) { + if err := vol.MkdirAll(ctx, sid, "subdir/nested"); err != nil { + t.Fatalf("MkdirAll: %v", err) + } + _ = vol.WriteFile(ctx, sid, "subdir/nested/file.txt", []byte("x"), 0o644) + entries, err := vol.ListDir(ctx, sid, "subdir/nested") + if err != nil { + t.Fatalf("ListDir: %v", err) + } + if len(entries) != 1 { + t.Fatalf("got %d entries, want 1", len(entries)) + } + if entries[0].Path != "file.txt" { + t.Errorf("entry name = %q, want %q", entries[0].Path, "file.txt") + } + }) + + t.Run("Rename", func(t *testing.T) { + if err := vol.Rename(ctx, sid, "greeting.txt", "hello.txt"); err != nil { + t.Fatalf("Rename: %v", err) + } + _, _, err := vol.ReadFile(ctx, sid, "hello.txt") + if err != nil { + t.Fatalf("ReadFile after rename: %v", err) + } + _, _, err = vol.ReadFile(ctx, sid, "greeting.txt") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } + }) + + t.Run("Remove", func(t *testing.T) { + if err := vol.Remove(ctx, sid, "hello.txt", false); err != nil { + t.Fatalf("Remove: %v", err) + } + _, err := vol.Stat(ctx, sid, "hello.txt") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } + }) + + t.Run("Remove recursive", func(t *testing.T) { + if err := vol.Remove(ctx, sid, "subdir", true); err != nil { + t.Fatalf("RemoveAll: %v", err) + } + _, err := vol.Stat(ctx, sid, "subdir") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } + }) +} + +func TestLocalSyncPush(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + defer vol.Close() + ctx := context.Background() + sid := "sync-test" + + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "a.txt"), []byte("aaa"), 0o644) + _ = os.MkdirAll(filepath.Join(srcDir, "sub"), 0o755) + _ = os.WriteFile(filepath.Join(srcDir, "sub", "b.txt"), []byte("bbb"), 0o644) + + result, err := vol.SyncPush(ctx, sid, srcDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 2 { + t.Errorf("synced = %d, want 2", result.FilesSynced) + } + + // Verify files exist in dataDir + data, err := os.ReadFile(filepath.Join(dataDir, sid, "a.txt")) + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(data) != "aaa" { + t.Errorf("content = %q, want %q", data, "aaa") + } +} + +func TestLocalSyncPull(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + defer vol.Close() + ctx := context.Background() + sid := "pull-test" + + // Create source in dataDir + sessionDir := filepath.Join(dataDir, sid) + _ = os.MkdirAll(sessionDir, 0o755) + _ = os.WriteFile(filepath.Join(sessionDir, "c.txt"), []byte("ccc"), 0o644) + + dstDir := t.TempDir() + result, err := vol.SyncPull(ctx, sid, dstDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } + + data, err := os.ReadFile(filepath.Join(dstDir, "c.txt")) + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(data) != "ccc" { + t.Errorf("content = %q, want %q", data, "ccc") + } +} + +func TestLocalSyncPushSkipsUnchanged(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + defer vol.Close() + ctx := context.Background() + sid := "skip-test" + + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "a.txt"), []byte("aaa"), 0o644) + + // First push + _, _ = vol.SyncPush(ctx, sid, srcDir, WithForceFull()) + + // Second push (no changes) without force + result, err := vol.SyncPush(ctx, sid, srcDir) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 0 { + t.Errorf("synced = %d, want 0 (no changes)", result.FilesSynced) + } +} + +func TestRemoteVolume(t *testing.T) { + addr := taiTestGRPC() + conn, err := grpc.NewClient(addr, + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC dial %s: %v", addr, err) + } + defer conn.Close() + + vol := NewRemote(conn) + defer vol.Close() + ctx := context.Background() + sid := "sdk-remote-test" + + t.Run("MkdirAll", func(t *testing.T) { + if err := vol.MkdirAll(ctx, sid, "sub/dir"); err != nil { + t.Fatalf("MkdirAll: %v", err) + } + }) + + t.Run("WriteFile and ReadFile", func(t *testing.T) { + data := []byte("remote test content") + if err := vol.WriteFile(ctx, sid, "test.txt", data, 0o644); err != nil { + t.Fatalf("WriteFile: %v", err) + } + got, mode, err := vol.ReadFile(ctx, sid, "test.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(got) != "remote test content" { + t.Errorf("got %q", got) + } + if mode == 0 { + t.Error("mode should be nonzero") + } + }) + + t.Run("WriteFile empty", func(t *testing.T) { + if err := vol.WriteFile(ctx, sid, "empty.txt", []byte{}, 0o644); err != nil { + t.Fatalf("WriteFile empty: %v", err) + } + got, _, err := vol.ReadFile(ctx, sid, "empty.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if len(got) != 0 { + t.Errorf("expected empty, got %d bytes", len(got)) + } + }) + + t.Run("Stat", func(t *testing.T) { + info, err := vol.Stat(ctx, sid, "test.txt") + if err != nil { + t.Fatalf("Stat: %v", err) + } + if info.Size != 19 { + t.Errorf("size = %d, want 19", info.Size) + } + }) + + t.Run("ListDir", func(t *testing.T) { + entries, err := vol.ListDir(ctx, sid, ".") + if err != nil { + t.Fatalf("ListDir: %v", err) + } + if len(entries) == 0 { + t.Error("expected entries") + } + }) + + t.Run("Rename", func(t *testing.T) { + if err := vol.Rename(ctx, sid, "test.txt", "renamed.txt"); err != nil { + t.Fatalf("Rename: %v", err) + } + _, _, err := vol.ReadFile(ctx, sid, "renamed.txt") + if err != nil { + t.Fatalf("ReadFile after rename: %v", err) + } + }) + + t.Run("Remove", func(t *testing.T) { + if err := vol.Remove(ctx, sid, "renamed.txt", false); err != nil { + t.Fatalf("Remove: %v", err) + } + }) + + t.Run("Remove recursive", func(t *testing.T) { + if err := vol.Remove(ctx, sid, "sub", true); err != nil { + t.Fatalf("RemoveAll: %v", err) + } + }) + + t.Run("SyncPush", func(t *testing.T) { + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "push.txt"), []byte("pushed"), 0o644) + result, err := vol.SyncPush(ctx, sid, srcDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } + }) + + t.Run("SyncPull", func(t *testing.T) { + dstDir := t.TempDir() + result, err := vol.SyncPull(ctx, sid, dstDir) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } + // Verify pulled file content + data, err := os.ReadFile(filepath.Join(dstDir, "push.txt")) + if err != nil { + t.Fatalf("ReadFile pulled: %v", err) + } + if string(data) != "pushed" { + t.Errorf("content = %q", data) + } + }) + + t.Run("SyncPull with existing local files", func(t *testing.T) { + // Push a second file + _ = vol.WriteFile(ctx, sid, "extra.txt", []byte("extra"), 0o644) + + dstDir := t.TempDir() + // Create a local file that matches (should be skipped) + _ = os.WriteFile(filepath.Join(dstDir, "push.txt"), []byte("pushed"), 0o644) + + result, err := vol.SyncPull(ctx, sid, dstDir) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + // At least extra.txt should be synced + if result.FilesSynced < 1 { + t.Errorf("synced = %d", result.FilesSynced) + } + }) + + t.Run("WriteFile large (multi-chunk)", func(t *testing.T) { + largeData := make([]byte, 128*1024) // 128KB > 64KB chunk + for i := range largeData { + largeData[i] = byte(i % 256) + } + if err := vol.WriteFile(ctx, sid, "large.bin", largeData, 0o644); err != nil { + t.Fatalf("WriteFile large: %v", err) + } + got, _, err := vol.ReadFile(ctx, sid, "large.bin") + if err != nil { + t.Fatalf("ReadFile large: %v", err) + } + if len(got) != len(largeData) { + t.Errorf("len = %d, want %d", len(got), len(largeData)) + } + }) + + t.Run("SyncPush with excludes", func(t *testing.T) { + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "keep.txt"), []byte("keep"), 0o644) + _ = os.WriteFile(filepath.Join(srcDir, "skip.log"), []byte("skip"), 0o644) + + result, err := vol.SyncPush(ctx, "exclude-remote", srcDir, WithForceFull(), WithExcludes("*.log")) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } + _ = vol.Remove(ctx, "exclude-remote", ".", true) + }) + + t.Run("SyncPull empty session", func(t *testing.T) { + emptyDir := t.TempDir() + _ = vol.MkdirAll(ctx, "empty-pull", ".") + result, err := vol.SyncPull(ctx, "empty-pull", emptyDir) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced != 0 { + t.Errorf("synced = %d, want 0", result.FilesSynced) + } + }) + + // Cleanup + _ = vol.Remove(ctx, sid, ".", true) +} + +func TestLocalPathTraversal(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + // Path traversal should fail + _, _, err := vol.ReadFile(ctx, "test", "../../etc/passwd") + if err == nil { + t.Error("expected error for path traversal in ReadFile") + } + if err := vol.WriteFile(ctx, "test", "../../etc/evil", []byte("x"), 0o644); err == nil { + t.Error("expected error for path traversal in WriteFile") + } + _, err = vol.Stat(ctx, "test", "../../etc/passwd") + if err == nil { + t.Error("expected error for path traversal in Stat") + } + _, err = vol.ListDir(ctx, "test", "../../etc") + if err == nil { + t.Error("expected error for path traversal in ListDir") + } + if err := vol.Remove(ctx, "test", "../../etc/passwd", false); err == nil { + t.Error("expected error for path traversal in Remove") + } + if err := vol.Rename(ctx, "test", "../../etc/a", "b"); err == nil { + t.Error("expected error for path traversal in Rename old") + } + if err := vol.Rename(ctx, "test", "a", "../../etc/b"); err == nil { + t.Error("expected error for path traversal in Rename new") + } + if err := vol.MkdirAll(ctx, "test", "../../etc/evil"); err == nil { + t.Error("expected error for path traversal in MkdirAll") + } +} + +func TestLocalReadFileNotExist(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + _, _, err := vol.ReadFile(ctx, "test", "nonexistent.txt") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } +} + +func TestLocalStatNotExist(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + _, err := vol.Stat(ctx, "test", "nonexistent.txt") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } +} + +func TestLocalListDirNotExist(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + _, err := vol.ListDir(ctx, "test", "nonexistent") + if !os.IsNotExist(err) { + t.Errorf("expected not-exist, got %v", err) + } +} + +func TestLocalRemoveNotExist(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + // Non-recursive remove on nonexistent should error + err := vol.Remove(ctx, "test", "nonexistent.txt", false) + if err == nil { + t.Error("expected error for remove nonexistent") + } +} + +func TestLocalSyncPullNoSource(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + dstDir := t.TempDir() + result, err := vol.SyncPull(ctx, "nonexistent-session", dstDir) + if err != nil { + t.Fatalf("SyncPull nonexistent: %v", err) + } + if result.FilesSynced != 0 { + t.Errorf("synced = %d, want 0", result.FilesSynced) + } +} + +func TestLocalSyncPushWithDirs(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "dir-sync-test" + + srcDir := t.TempDir() + _ = os.MkdirAll(filepath.Join(srcDir, "a", "b", "c"), 0o755) + _ = os.WriteFile(filepath.Join(srcDir, "a", "b", "c", "deep.txt"), []byte("deep"), 0o644) + + result, err := vol.SyncPush(ctx, sid, srcDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } +} + +func TestCompressDecompress(t *testing.T) { + data := []byte("hello world, this is a test of compression that needs enough data to exercise the paths") + compressed, err := compress(data) + if err != nil { + t.Fatalf("compress: %v", err) + } + decompressed, err := decompress(compressed) + if err != nil { + t.Fatalf("decompress: %v", err) + } + if string(decompressed) != string(data) { + t.Errorf("round-trip failed: got %q", decompressed) + } +} + +func TestCompressLargeData(t *testing.T) { + data := make([]byte, 256*1024) // 256KB + for i := range data { + data[i] = byte(i % 256) + } + compressed, err := compress(data) + if err != nil { + t.Fatalf("compress: %v", err) + } + decompressed, err := decompress(compressed) + if err != nil { + t.Fatalf("decompress: %v", err) + } + if len(decompressed) != len(data) { + t.Errorf("len = %d, want %d", len(decompressed), len(data)) + } +} + +func TestDecompressInvalid(t *testing.T) { + _, err := decompress([]byte{0xFF, 0xFF, 0xFF}) + if err == nil { + t.Error("expected error for invalid data") + } +} + +func TestCompressEmpty(t *testing.T) { + compressed, err := compress([]byte{}) + if err != nil { + t.Fatalf("compress: %v", err) + } + decompressed, err := decompress(compressed) + if err != nil { + t.Fatalf("decompress: %v", err) + } + if len(decompressed) != 0 { + t.Errorf("expected empty, got %d bytes", len(decompressed)) + } +} + +func TestRemoteRemoveError(t *testing.T) { + conn, err := grpc.NewClient(taiTestGRPC(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC %s: %v", taiTestGRPC(), err) + } + defer conn.Close() + + vol := NewRemote(conn) + err = vol.Remove(context.Background(), "nonexistent-session", "nonexistent.txt", false) + if err == nil { + t.Error("expected error for remove nonexistent") + } +} + +func TestRemoteRenameError(t *testing.T) { + conn, err := grpc.NewClient(taiTestGRPC(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC %s: %v", taiTestGRPC(), err) + } + defer conn.Close() + + vol := NewRemote(conn) + err = vol.Rename(context.Background(), "nonexistent-session", "a.txt", "b.txt") + if err == nil { + t.Error("expected error for rename nonexistent") + } +} + +func TestRemoteMkdirAllAndStatError(t *testing.T) { + conn, err := grpc.NewClient(taiTestGRPC(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC %s: %v", taiTestGRPC(), err) + } + defer conn.Close() + + vol := NewRemote(conn) + _, err = vol.Stat(context.Background(), "stat-test", "nonexistent.txt") + if err == nil { + t.Error("expected error for stat nonexistent") + } +} + +func TestRemoteReadFileNotFound(t *testing.T) { + conn, err := grpc.NewClient(taiTestGRPC(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC %s: %v", taiTestGRPC(), err) + } + defer conn.Close() + + vol := NewRemote(conn) + _, _, err = vol.ReadFile(context.Background(), "notfound-session", "notfound.txt") + if err == nil { + t.Error("expected error for read nonexistent") + } +} + +func TestRemoteListDirNotFound(t *testing.T) { + conn, err := grpc.NewClient(taiTestGRPC(), + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + t.Skipf("gRPC %s: %v", taiTestGRPC(), err) + } + defer conn.Close() + + vol := NewRemote(conn) + _, err = vol.ListDir(context.Background(), "notfound-session", "notfound-dir") + if err == nil { + t.Error("expected error for listdir nonexistent") + } +} + +func TestLocalSyncPullIncrementalSkip(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "pull-skip-test" + + // Push some files + _ = vol.WriteFile(ctx, sid, "a.txt", []byte("aaa"), 0o644) + _ = vol.WriteFile(ctx, sid, "b.txt", []byte("bbb"), 0o644) + + dstDir := t.TempDir() + + // First pull + result1, err := vol.SyncPull(ctx, sid, dstDir) + if err != nil { + t.Fatalf("SyncPull 1: %v", err) + } + if result1.FilesSynced != 2 { + t.Errorf("first sync = %d, want 2", result1.FilesSynced) + } + + // Second pull — identical mtime+size should skip + result2, err := vol.SyncPull(ctx, sid, dstDir) + if err != nil { + t.Fatalf("SyncPull 2: %v", err) + } + // Files should still be synced due to mtime possibly differing (Chtimes on first pull), + // but on the third pull they should match + result3, err := vol.SyncPull(ctx, sid, dstDir) + if err != nil { + t.Fatalf("SyncPull 3: %v", err) + } + if result3.FilesSynced != 0 { + t.Logf("sync3 = %d (may vary by platform)", result3.FilesSynced) + } + _ = result2 +} + +func TestLocalSyncPullWithExcludes(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "pull-excl" + + _ = vol.WriteFile(ctx, sid, "keep.txt", []byte("keep"), 0o644) + _ = vol.WriteFile(ctx, sid, "skip.log", []byte("skip"), 0o644) + _ = vol.MkdirAll(ctx, sid, "node_modules") + _ = vol.WriteFile(ctx, sid, "node_modules/pkg.js", []byte("x"), 0o644) + + dstDir := t.TempDir() + result, err := vol.SyncPull(ctx, sid, dstDir, WithExcludes("*.log", "node_modules"), WithForceFull()) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } +} + +func TestLocalSyncPushIncremental(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "push-inc" + + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "a.txt"), []byte("aaa"), 0o644) + + // First push + result1, err := vol.SyncPush(ctx, sid, srcDir) + if err != nil { + t.Fatalf("SyncPush 1: %v", err) + } + if result1.FilesSynced != 1 { + t.Errorf("first sync = %d, want 1", result1.FilesSynced) + } + + // Second push without changes — mtime matches, should skip + result2, err := vol.SyncPush(ctx, sid, srcDir) + if err != nil { + t.Fatalf("SyncPush 2: %v", err) + } + if result2.FilesSynced != 0 { + t.Logf("second sync = %d (expected 0 but may vary)", result2.FilesSynced) + } +} + +func TestLocalWriteFileNested(t *testing.T) { + dir := t.TempDir() + vol := NewLocal(dir) + ctx := context.Background() + + // WriteFile with deep nested path (MkdirAll should succeed) + err := vol.WriteFile(ctx, "test", "a/b/c/deep.txt", []byte("deep"), 0o644) + if err != nil { + t.Fatalf("WriteFile nested: %v", err) + } + data, _, err := vol.ReadFile(ctx, "test", "a/b/c/deep.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(data) != "deep" { + t.Errorf("content = %q", data) + } +} + +func TestLocalSyncPushExcludeDir(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + + srcDir := t.TempDir() + _ = os.MkdirAll(filepath.Join(srcDir, ".git", "objects"), 0o755) + _ = os.WriteFile(filepath.Join(srcDir, ".git", "objects", "abc"), []byte("obj"), 0o644) + _ = os.WriteFile(filepath.Join(srcDir, "keep.txt"), []byte("keep"), 0o644) + + result, err := vol.SyncPush(ctx, "excl-dir", srcDir, WithForceFull(), WithExcludes(".git")) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1 (exclude .git dir)", result.FilesSynced) + } +} + +func TestLocalSyncPullForceFull(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "pull-force" + + _ = vol.WriteFile(ctx, sid, "a.txt", []byte("aaa"), 0o644) + + dstDir := t.TempDir() + _ = os.WriteFile(filepath.Join(dstDir, "a.txt"), []byte("aaa"), 0o644) + + // Force full should re-sync even if same content + result, err := vol.SyncPull(ctx, sid, dstDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPull: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1 (force full)", result.FilesSynced) + } +} + +func TestLocalSyncPushForceFull(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + ctx := context.Background() + sid := "push-force" + + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "a.txt"), []byte("aaa"), 0o644) + + // First sync + _, _ = vol.SyncPush(ctx, sid, srcDir) + // Force full should re-sync + result, err := vol.SyncPush(ctx, sid, srcDir, WithForceFull()) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1 (force full)", result.FilesSynced) + } +} + +func TestLocalSyncExcludes(t *testing.T) { + dataDir := t.TempDir() + vol := NewLocal(dataDir) + defer vol.Close() + ctx := context.Background() + sid := "exclude-test" + + srcDir := t.TempDir() + _ = os.WriteFile(filepath.Join(srcDir, "keep.txt"), []byte("k"), 0o644) + _ = os.WriteFile(filepath.Join(srcDir, "skip.log"), []byte("s"), 0o644) + + result, err := vol.SyncPush(ctx, sid, srcDir, WithForceFull(), WithExcludes("*.log")) + if err != nil { + t.Fatalf("SyncPush: %v", err) + } + if result.FilesSynced != 1 { + t.Errorf("synced = %d, want 1", result.FilesSynced) + } + + if _, err := os.Stat(filepath.Join(dataDir, sid, "skip.log")); !os.IsNotExist(err) { + t.Error("excluded file should not exist") + } +} diff --git a/tai/workspace/workspace.go b/tai/workspace/workspace.go new file mode 100644 index 00000000..6af4e69d --- /dev/null +++ b/tai/workspace/workspace.go @@ -0,0 +1,195 @@ +package workspace + +import ( + "context" + "io" + "io/fs" + "os" + "strings" + "time" + + "github.com/yaoapp/yao/tai/volume" +) + +// FS extends Go's fs.FS with write operations. +// Backed by volume.Volume — works for both Remote and Local transparently. +type FS interface { + fs.FS + fs.StatFS + fs.ReadFileFS + fs.ReadDirFS + io.Closer + + WriteFile(name string, data []byte, perm os.FileMode) error + Remove(name string) error + RemoveAll(name string) error + Rename(oldname, newname string) error + MkdirAll(name string, perm os.FileMode) error +} + +// New creates an FS backed by the given Volume for the specified session. +func New(vol volume.Volume, sessionID string) FS { + return &workspaceFS{vol: vol, session: sessionID} +} + +type workspaceFS struct { + vol volume.Volume + session string +} + +func (w *workspaceFS) Open(name string) (fs.File, error) { + if !fs.ValidPath(name) { + return nil, &fs.PathError{Op: "open", Path: name, Err: fs.ErrInvalid} + } + ctx := context.Background() + info, err := w.vol.Stat(ctx, w.session, name) + if err != nil { + return nil, &fs.PathError{Op: "open", Path: name, Err: err} + } + if info.IsDir { + return &dirFile{w: w, name: name, info: info}, nil + } + data, _, err := w.vol.ReadFile(ctx, w.session, name) + if err != nil { + return nil, &fs.PathError{Op: "open", Path: name, Err: err} + } + return &memFile{name: name, info: info, data: data}, nil +} + +func (w *workspaceFS) Stat(name string) (fs.FileInfo, error) { + if !fs.ValidPath(name) { + return nil, &fs.PathError{Op: "stat", Path: name, Err: fs.ErrInvalid} + } + info, err := w.vol.Stat(context.Background(), w.session, name) + if err != nil { + return nil, &fs.PathError{Op: "stat", Path: name, Err: err} + } + return toFSInfo(name, info), nil +} + +func (w *workspaceFS) ReadFile(name string) ([]byte, error) { + if !fs.ValidPath(name) { + return nil, &fs.PathError{Op: "read", Path: name, Err: fs.ErrInvalid} + } + data, _, err := w.vol.ReadFile(context.Background(), w.session, name) + if err != nil { + return nil, &fs.PathError{Op: "read", Path: name, Err: err} + } + return data, nil +} + +func (w *workspaceFS) ReadDir(name string) ([]fs.DirEntry, error) { + if !fs.ValidPath(name) { + return nil, &fs.PathError{Op: "readdir", Path: name, Err: fs.ErrInvalid} + } + entries, err := w.vol.ListDir(context.Background(), w.session, name) + if err != nil { + return nil, &fs.PathError{Op: "readdir", Path: name, Err: err} + } + result := make([]fs.DirEntry, 0, len(entries)) + for i := range entries { + result = append(result, &dirEntry{info: &entries[i]}) + } + return result, nil +} + +func (w *workspaceFS) WriteFile(name string, data []byte, perm os.FileMode) error { + return w.vol.WriteFile(context.Background(), w.session, name, data, perm) +} + +func (w *workspaceFS) Remove(name string) error { + return w.vol.Remove(context.Background(), w.session, name, false) +} + +func (w *workspaceFS) RemoveAll(name string) error { + return w.vol.Remove(context.Background(), w.session, name, true) +} + +func (w *workspaceFS) Rename(oldname, newname string) error { + return w.vol.Rename(context.Background(), w.session, oldname, newname) +} + +func (w *workspaceFS) MkdirAll(name string, _ os.FileMode) error { + return w.vol.MkdirAll(context.Background(), w.session, name) +} + +func (w *workspaceFS) Close() error { return nil } + +// --- fs.FileInfo adapter --- + +type fileInfoAdapter struct { + name string + size int64 + mode fs.FileMode + mtime time.Time + isDir bool +} + +func toFSInfo(name string, vi *volume.FileInfo) *fileInfoAdapter { + base := name + if idx := strings.LastIndex(name, "/"); idx >= 0 { + base = name[idx+1:] + } + if base == "" { + base = "." + } + return &fileInfoAdapter{ + name: base, + size: vi.Size, + mode: vi.Mode, + mtime: vi.Mtime, + isDir: vi.IsDir, + } +} + +func (f *fileInfoAdapter) Name() string { return f.name } +func (f *fileInfoAdapter) Size() int64 { return f.size } +func (f *fileInfoAdapter) Mode() fs.FileMode { return f.mode } +func (f *fileInfoAdapter) ModTime() time.Time { return f.mtime } +func (f *fileInfoAdapter) IsDir() bool { return f.isDir } +func (f *fileInfoAdapter) Sys() any { return nil } + +// --- fs.DirEntry adapter --- + +type dirEntry struct { + info *volume.FileInfo +} + +func (d *dirEntry) Name() string { return d.info.Path } +func (d *dirEntry) IsDir() bool { return d.info.IsDir } +func (d *dirEntry) Type() fs.FileMode { return d.info.Mode.Type() } +func (d *dirEntry) Info() (fs.FileInfo, error) { return toFSInfo(d.info.Path, d.info), nil } + +// --- in-memory file (for Open on regular files) --- + +type memFile struct { + name string + info *volume.FileInfo + data []byte + offset int +} + +func (f *memFile) Stat() (fs.FileInfo, error) { return toFSInfo(f.name, f.info), nil } +func (f *memFile) Read(b []byte) (int, error) { + if f.offset >= len(f.data) { + return 0, io.EOF + } + n := copy(b, f.data[f.offset:]) + f.offset += n + return n, nil +} +func (f *memFile) Close() error { return nil } + +// --- directory file (for Open on directories) --- + +type dirFile struct { + w *workspaceFS + name string + info *volume.FileInfo +} + +func (d *dirFile) Stat() (fs.FileInfo, error) { return toFSInfo(d.name, d.info), nil } +func (d *dirFile) Read([]byte) (int, error) { + return 0, &fs.PathError{Op: "read", Path: d.name, Err: fs.ErrInvalid} +} +func (d *dirFile) Close() error { return nil } diff --git a/tai/workspace/workspace_test.go b/tai/workspace/workspace_test.go new file mode 100644 index 00000000..97ba9f1a --- /dev/null +++ b/tai/workspace/workspace_test.go @@ -0,0 +1,219 @@ +package workspace + +import ( + "io" + "io/fs" + "testing" + + "github.com/yaoapp/yao/tai/volume" +) + +func TestWorkspaceFS(t *testing.T) { + dir := t.TempDir() + vol := volume.NewLocal(dir) + defer vol.Close() + + wfs := New(vol, "ws-test") + defer wfs.Close() + + t.Run("WriteFile and ReadFile", func(t *testing.T) { + if err := wfs.WriteFile("hello.txt", []byte("world"), 0o644); err != nil { + t.Fatalf("WriteFile: %v", err) + } + data, err := wfs.ReadFile("hello.txt") + if err != nil { + t.Fatalf("ReadFile: %v", err) + } + if string(data) != "world" { + t.Errorf("got %q, want %q", data, "world") + } + }) + + t.Run("Stat", func(t *testing.T) { + info, err := wfs.Stat("hello.txt") + if err != nil { + t.Fatalf("Stat: %v", err) + } + if info.Name() != "hello.txt" { + t.Errorf("name = %q, want %q", info.Name(), "hello.txt") + } + if info.Size() != 5 { + t.Errorf("size = %d, want 5", info.Size()) + } + if info.IsDir() { + t.Error("expected file, not dir") + } + if info.Mode() == 0 { + t.Error("mode should be nonzero") + } + if info.ModTime().IsZero() { + t.Error("modtime should be nonzero") + } + if info.Sys() != nil { + t.Error("Sys should be nil") + } + }) + + t.Run("MkdirAll and ReadDir", func(t *testing.T) { + if err := wfs.MkdirAll("sub/dir", 0o755); err != nil { + t.Fatalf("MkdirAll: %v", err) + } + _ = wfs.WriteFile("sub/dir/file.txt", []byte("x"), 0o644) + entries, err := wfs.ReadDir("sub/dir") + if err != nil { + t.Fatalf("ReadDir: %v", err) + } + if len(entries) != 1 { + t.Fatalf("got %d entries, want 1", len(entries)) + } + e := entries[0] + if e.Name() != "file.txt" { + t.Errorf("entry = %q, want %q", e.Name(), "file.txt") + } + if e.IsDir() { + t.Error("entry should not be dir") + } + if e.Type()&fs.ModeDir != 0 { + t.Error("Type should not include ModeDir") + } + info, err := e.Info() + if err != nil { + t.Fatalf("Info: %v", err) + } + if info.Name() != "file.txt" { + t.Errorf("info name = %q", info.Name()) + } + }) + + t.Run("Open file and read", func(t *testing.T) { + f, err := wfs.Open("hello.txt") + if err != nil { + t.Fatalf("Open: %v", err) + } + defer f.Close() + + // Stat via file + finfo, err := f.Stat() + if err != nil { + t.Fatalf("file.Stat: %v", err) + } + if finfo.Name() != "hello.txt" { + t.Errorf("name = %q", finfo.Name()) + } + + // Read all + buf := make([]byte, 10) + n, _ := f.Read(buf) + if string(buf[:n]) != "world" { + t.Errorf("read = %q, want %q", buf[:n], "world") + } + // Read past EOF + _, err = f.Read(buf) + if err != io.EOF { + t.Errorf("expected EOF, got %v", err) + } + }) + + t.Run("Open directory", func(t *testing.T) { + f, err := wfs.Open("sub/dir") + if err != nil { + t.Fatalf("Open dir: %v", err) + } + defer f.Close() + info, _ := f.Stat() + if !info.IsDir() { + t.Error("expected dir") + } + // Read on dir should error + buf := make([]byte, 10) + _, err = f.Read(buf) + if err == nil { + t.Error("expected error reading dir") + } + }) + + t.Run("Rename", func(t *testing.T) { + if err := wfs.Rename("hello.txt", "hi.txt"); err != nil { + t.Fatalf("Rename: %v", err) + } + _, err := wfs.Stat("hi.txt") + if err != nil { + t.Fatalf("Stat after rename: %v", err) + } + }) + + t.Run("Remove", func(t *testing.T) { + if err := wfs.Remove("hi.txt"); err != nil { + t.Fatalf("Remove: %v", err) + } + _, err := wfs.Stat("hi.txt") + if err == nil { + t.Error("expected error after remove") + } + }) + + t.Run("RemoveAll", func(t *testing.T) { + if err := wfs.RemoveAll("sub"); err != nil { + t.Fatalf("RemoveAll: %v", err) + } + _, err := wfs.Stat("sub") + if err == nil { + t.Error("expected error after removeall") + } + }) + + t.Run("Invalid path", func(t *testing.T) { + _, err := wfs.Open("/absolute") + if err == nil { + t.Error("expected error for absolute path") + } + _, err = wfs.Stat("/absolute") + if err == nil { + t.Error("expected error for absolute path in Stat") + } + _, err = wfs.ReadFile("/absolute") + if err == nil { + t.Error("expected error for absolute path in ReadFile") + } + _, err = wfs.ReadDir("/absolute") + if err == nil { + t.Error("expected error for absolute path in ReadDir") + } + }) + + t.Run("Open nonexistent", func(t *testing.T) { + _, err := wfs.Open("nonexistent.txt") + if err == nil { + t.Error("expected error for nonexistent file") + } + }) + + t.Run("ReadFile nonexistent", func(t *testing.T) { + _, err := wfs.ReadFile("nonexistent.txt") + if err == nil { + t.Error("expected error for nonexistent file") + } + }) + + t.Run("toFSInfo with slash", func(t *testing.T) { + info := toFSInfo("sub/dir/file.txt", &volume.FileInfo{Path: "sub/dir/file.txt", Size: 1}) + if info.Name() != "file.txt" { + t.Errorf("name = %q, want %q", info.Name(), "file.txt") + } + }) + + t.Run("toFSInfo root", func(t *testing.T) { + info := toFSInfo("", &volume.FileInfo{Path: "", IsDir: true}) + if info.Name() != "." { + t.Errorf("name = %q, want %q", info.Name(), ".") + } + }) +} + +// Compile-time interface checks. +var ( + _ fs.FS = (*workspaceFS)(nil) + _ fs.StatFS = (*workspaceFS)(nil) + _ fs.ReadFileFS = (*workspaceFS)(nil) + _ fs.ReadDirFS = (*workspaceFS)(nil) +)