WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
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
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
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package workbench
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/models/embedding"
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
type usageEmbedding struct{ calls int }
|
||||
|
||||
func (m *usageEmbedding) Embed(context.Context, string) ([]float32, error) {
|
||||
m.calls++
|
||||
return []float32{1, 2}, nil
|
||||
}
|
||||
func (m *usageEmbedding) BatchEmbed(_ context.Context, texts []string) ([][]float32, error) {
|
||||
m.calls++
|
||||
out := make([][]float32, len(texts))
|
||||
for i := range out {
|
||||
out[i] = []float32{1, 2}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
func (m *usageEmbedding) BatchEmbedWithPool(ctx context.Context, model embedding.Embedder, texts []string) ([][]float32, error) {
|
||||
return model.BatchEmbed(ctx, texts)
|
||||
}
|
||||
func (*usageEmbedding) GetModelID() string { return "embedding" }
|
||||
func (*usageEmbedding) GetModelName() string { return "embedding model" }
|
||||
func (*usageEmbedding) GetDimensions() int { return 2 }
|
||||
|
||||
func TestAuxiliaryUsageRecordsUnitsOnceWithoutInventedBilling(t *testing.T) {
|
||||
s := sqliteWorkbench(t)
|
||||
ctx := workbenchContext(7, "alice", types.TenantRoleContributor)
|
||||
raw := &usageEmbedding{}
|
||||
model := s.WrapEmbedding(raw)
|
||||
if _, err := model.BatchEmbedWithPool(ctx, model, []string{"主题", "练习"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var rows []Usage
|
||||
if err := s.db.Find(&rows).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if raw.calls != 1 || len(rows) != 1 {
|
||||
t.Fatalf("double counted: calls=%d rows=%d", raw.calls, len(rows))
|
||||
}
|
||||
r := rows[0]
|
||||
if r.TenantID != 7 || r.OwnerID != "alice" || r.Points != 0 || r.InputTokens != 0 || r.OutputTokens != 0 {
|
||||
t.Fatalf("wrong attribution or invented charge: %+v", r)
|
||||
}
|
||||
if r.Metadata["input_characters"] != float64(4) || r.Metadata["input_texts"] != float64(2) || r.Metadata["billing_status"] != "provider_usage_unavailable" {
|
||||
t.Fatalf("missing measured units: %+v", r.Metadata)
|
||||
}
|
||||
var n int64
|
||||
if err := s.db.Model(&Transaction{}).Count(&n).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Fatal("auxiliary metrics created an unsupported debit")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user