docs(gateway): gateway 剩余文件注释改中文(逐行 1:1,代码零字节改动)
主人 2026-10-03 拍板「注释一律中文」;gateway 至此整包注释中文化完成(本会话共 3 批: 已推库 16 个文件 + 本批剩余文件)。 校验:机械校验(非注释改动行)= 空;剥注释后代码文本逐行比对全等(不一致文件数 0); 全树 go test ./... 58 包 ok / 0 FAIL;交叉编译绿。
This commit is contained in:
1 parent
91e8d7a029
commit
074ffc4ebf
73 files changed
+2529
-2529
No files matched your search
@@ -14,9 +14,9 @@ import (
|
||||
"git.yeij.top/AskaEth/Cyrene_v2/internal/db"
|
||||
)
|
||||
|
||||
// newFileDB creates a real SQLite database file at dir/<name>, migrates it, and
|
||||
// closes the handle, returning the file path. The gateway backup/restore
|
||||
// endpoints open their own connections, so the handle is not held open here.
|
||||
// newFileDB 在 dir/<name> 创建真实 SQLite 数据库文件、迁移它、
|
||||
// 然后关闭句柄,返回文件路径。网关的备份/恢复端点
|
||||
// 会自己打开连接,因此这里不保持句柄打开。
|
||||
func newFileDB(t *testing.T, dir, name string) string {
|
||||
t.Helper()
|
||||
path := filepath.Join(dir, name)
|
||||
@@ -35,7 +35,7 @@ func newFileDB(t *testing.T, dir, name string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
// --- revoke-keys -------------------------------------------------------------
|
||||
// --- system.revoke_keys(吊销全部密钥) -------------------------------------
|
||||
|
||||
func TestAdminRevokeAllKeys(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -68,7 +68,7 @@ func TestAdminRevokeAllKeys(t *testing.T) {
|
||||
|
||||
func TestAdminRevokeAllKeysUnwired(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no Users store
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // 无 Users store
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/system/revoke-keys", nil, tok)
|
||||
if resp.StatusCode != http.StatusInternalServerError {
|
||||
@@ -77,13 +77,13 @@ func TestAdminRevokeAllKeysUnwired(t *testing.T) {
|
||||
wantErrorShape(t, body)
|
||||
}
|
||||
|
||||
// --- rotate-jwt --------------------------------------------------------------
|
||||
// --- system.rotate_jwt(轮换 JWT) -----------------------------------------
|
||||
|
||||
func TestAdminRotateJWT(t *testing.T) {
|
||||
t.Parallel()
|
||||
jwt := auth.New(config.AuthConfig{JWTSecret: testSecret})
|
||||
_, ts, _ := buildEnv(t, cfgDefault(), Deps{Auth: jwt})
|
||||
// The route is owner-only; verify an agent with the current secret passes.
|
||||
// 该路由仅 owner;验证持有当前秘密的 agent 能通过。
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
newSecret := strings.Repeat("Z", 40)
|
||||
@@ -102,11 +102,11 @@ func TestAdminRotateJWT(t *testing.T) {
|
||||
if !res.Rotated || res.Note == "" {
|
||||
t.Fatalf("res = %+v, want rotated with note", res)
|
||||
}
|
||||
// The pre-rotation token no longer verifies.
|
||||
// 轮换前的 token 不再通过校验。
|
||||
if _, err := jwt.Verify(tok); err == nil {
|
||||
t.Fatal("pre-rotation token still verifies after RotateSecret")
|
||||
}
|
||||
// The new secret is never echoed back in the body, nor is a short one accepted.
|
||||
// 新秘密绝不在响应体里回显,过短的也不会被接受。
|
||||
if strings.Contains(string(body), newSecret) {
|
||||
t.Fatalf("new secret leaked in response body: %s", body)
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestAdminRotateJWTShortSecret(t *testing.T) {
|
||||
t.Fatalf("status = %d, want 400 (body=%s)", resp.StatusCode, body)
|
||||
}
|
||||
wantErrorShape(t, body)
|
||||
// The previous secret stays intact after a rejected rotation.
|
||||
// 被拒绝的轮换之后,原秘密保持不变。
|
||||
if _, err := jwt.Verify(tok); err != nil {
|
||||
t.Fatalf("token invalid after rejected rotation: %v", err)
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func TestAdminRotateJWTMissingSecret(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// --- backup ------------------------------------------------------------------
|
||||
// --- system.backup(备份) --------------------------------------------------
|
||||
|
||||
func TestAdminBackupProducesFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -176,7 +176,7 @@ func TestAdminBackupProducesFile(t *testing.T) {
|
||||
|
||||
func TestAdminBackupUnwired(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no DatabasePath
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // 无 DatabasePath
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/system/backup", nil, tok)
|
||||
if resp.StatusCode != http.StatusInternalServerError {
|
||||
@@ -185,7 +185,7 @@ func TestAdminBackupUnwired(t *testing.T) {
|
||||
wantErrorShape(t, body)
|
||||
}
|
||||
|
||||
// --- restore -----------------------------------------------------------------
|
||||
// --- system.restore(恢复) -------------------------------------------------
|
||||
|
||||
func TestAdminRestoreReplacesAndPreBacksUp(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -193,9 +193,9 @@ func TestAdminRestoreReplacesAndPreBacksUp(t *testing.T) {
|
||||
dbPath := newFileDB(t, dir, "cyrene.db")
|
||||
backupSrc := newFileDB(t, dir, "backup.db")
|
||||
|
||||
// Make the backup source clearly different from the live db by appending a
|
||||
// marker. Restore only copies bytes and never opens the source, so the marker
|
||||
// survives into the replaced live file and proves the swap happened.
|
||||
// 通过追加一个标记,让备份源与活的 db 明显不同。
|
||||
// 恢复只复制字节、绝不打开源,因此该标记会
|
||||
// 存活进被替换的活文件,证明替换确实发生过。
|
||||
srcFile, err := os.OpenFile(backupSrc, os.O_WRONLY|os.O_APPEND, 0o644)
|
||||
if err != nil {
|
||||
t.Fatalf("open backup source: %v", err)
|
||||
@@ -214,7 +214,7 @@ func TestAdminRestoreReplacesAndPreBacksUp(t *testing.T) {
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{DatabasePath: dbPath})
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
|
||||
// No pre-existing backups yet.
|
||||
// 此时尚无既有备份。
|
||||
before, _ := filepath.Glob(filepath.Join(dir, "backup-*.db"))
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/system/restore",
|
||||
map[string]any{"path": backupSrc}, tok)
|
||||
@@ -232,13 +232,13 @@ func TestAdminRestoreReplacesAndPreBacksUp(t *testing.T) {
|
||||
if !res.Restored || res.Note == "" {
|
||||
t.Fatalf("res = %+v, want restored with note", res)
|
||||
}
|
||||
// The current DB was snapshotted before the replace (a new backup appeared).
|
||||
// 当前 DB 在替换前已被快照(出现了一个新备份)。
|
||||
after, _ := filepath.Glob(filepath.Join(dir, "backup-*.db"))
|
||||
if len(after) != len(before)+1 {
|
||||
t.Fatalf("backup count before=%d after=%d, want one more pre-restore snapshot", len(before), len(after))
|
||||
}
|
||||
// The live DB was replaced with the backup source's bytes, so it now carries
|
||||
// the marker and differs from its pre-restore content.
|
||||
// 活 DB 已被替换为备份源的字节,因此它现在携带
|
||||
// 该标记,与恢复前的内容不同。
|
||||
liveAfter, err := os.ReadFile(dbPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read live db after: %v", err)
|
||||
@@ -253,8 +253,8 @@ func TestAdminRestoreReplacesAndPreBacksUp(t *testing.T) {
|
||||
|
||||
func TestAdminRestoreRejectsTraversal(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir := t.TempDir() // data dir
|
||||
outside := t.TempDir() // a sibling directory, outside the data dir
|
||||
dir := t.TempDir() // 数据目录
|
||||
outside := t.TempDir() // 兄弟目录,位于数据目录之外
|
||||
dbPath := newFileDB(t, dir, "cyrene.db")
|
||||
outsideBackup := newFileDB(t, outside, "outside.db")
|
||||
|
||||
@@ -287,7 +287,7 @@ func TestAdminRestoreRejectsMissingFile(t *testing.T) {
|
||||
|
||||
func TestAdminRestoreUnwired(t *testing.T) {
|
||||
t.Parallel()
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // no DatabasePath
|
||||
_, ts, jwt := buildEnv(t, cfgDefault(), Deps{}) // 无 DatabasePath
|
||||
tok := signAny(t, jwt, "acct", auth.RoleOwner)
|
||||
resp, body := doReq(t, http.MethodPost, ts.URL+"/api/v1/admin/system/restore",
|
||||
map[string]any{"path": "x"}, tok)
|
||||
|
||||
Reference in new issue
Block a user