Files
xinmi/internal/application/repository/agent_share_source_test.go
T
yawan f7fc992f57
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

48 lines
1.8 KiB
Go

package repository
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func TestGetShareByAgentIDAndSourceForTenantDisambiguatesSource(t *testing.T) {
db, err := gorm.Open(sqlite.Open("file:agent-share-source?mode=memory&cache=shared"), &gorm.Config{})
require.NoError(t, err)
statements := []string{
`CREATE TABLE agent_shares (
id TEXT PRIMARY KEY, agent_id TEXT, organization_id TEXT,
shared_by_user_id TEXT, source_tenant_id INTEGER, permission TEXT,
created_at DATETIME, updated_at DATETIME, deleted_at DATETIME
)`,
`CREATE TABLE organization_tenant_members (organization_id TEXT, tenant_id INTEGER)`,
`CREATE TABLE organizations (id TEXT PRIMARY KEY, deleted_at DATETIME)`,
`CREATE TABLE custom_agents (id TEXT, tenant_id INTEGER, deleted_at DATETIME)`,
`INSERT INTO organizations(id) VALUES ('org')`,
`INSERT INTO organization_tenant_members(organization_id, tenant_id) VALUES ('org', 7)`,
`INSERT INTO custom_agents(id, tenant_id) VALUES ('builtin-smart-reasoning', 42), ('builtin-smart-reasoning', 84)`,
`INSERT INTO agent_shares(id, agent_id, organization_id, source_tenant_id) VALUES
('share-42', 'builtin-smart-reasoning', 'org', 42),
('share-84', 'builtin-smart-reasoning', 'org', 84)`,
}
for _, statement := range statements {
require.NoError(t, db.Exec(statement).Error)
}
repo := &agentShareRepository{db: db}
share, err := repo.GetShareByAgentIDAndSourceForTenant(
context.Background(), 7, "builtin-smart-reasoning", 84,
)
require.NoError(t, err)
require.Equal(t, "share-84", share.ID)
require.Equal(t, uint64(84), share.SourceTenantID)
_, err = repo.GetShareByAgentIDAndSourceForTenant(
context.Background(), 8, "builtin-smart-reasoning", 84,
)
require.ErrorIs(t, err, ErrAgentShareNotFound)
}