Skip to content

CLI quản lý accounts: auth login --add, auth list (tĩnh), auth remove #2

Closed

Description

@longphamdev

CLI quản lý accounts

What to build

Quản lý nhiều account từ CLI, end-to-end: login thêm acc mà không ghi đè acc cũ, xem danh sách, xóa acc.

  • zcode-proxy auth login <provider> --add: chạy OAuth như cũ nhưng thêm account (upsert theo account key) thay vì ghi đè primary. In ra id + label của account vừa thêm.
  • zcode-proxy auth list: bảng thông tin tĩnh — id, label, userId (che bớt giữa), có phải primary không, addedAt, tokenExpiresAt (decode JWT exp/age;JWT start-plan không có exp → hiện iat + age). Không có cột status/quota — status runtime thuộc pool (ticket 2a), quota thuộc poller (ticket 4); cột đó thêm ở ticket 4.
  • zcode-proxy auth remove <id>: xóa 1 account (không được xóa acc cuối nếu làm mất khả năng serve — hỏi xác nhận), re-point primary nếu cần.
  • auth logout giữ nguyên behavior cũ: chỉ xóa primary account.
  • --add phải dùng đúng lockfile protocol của store (acquire → read latest → modify → write → release) — acc thêm từ CLI khác phải thấy được bởi server đang chạy qua hot-reload.

Acceptance criteria

  • auth login --add 2 acc khác nhau → store có 2 entries, primary là acc mới nhất
  • auth login --add 2 lần cùng 1 acc → upsert, không duplicate
  • auth login (không --add) giữ behavior cũ: ghi đè primary
  • auth list hiện đúng thông tin tĩnh, không leak credential (userId che bớt, không in apiKey)
  • auth remove <id> xóa đúng 1 acc, primary re-point, acc khác nguyên vẹn
  • auth logout chỉ xóa primary
  • Thêm acc bằng CLI trong khi server chạy → server dùng được acc mới mà không restart (hot-reload)

Activity

  1. longphamdev commented on Nov 9, 2026

    @longphamdev
    OwnerAuthor

    Implementation constraint (merge-order + API):

  2. longphamdev commented on Nov 9, 2026

    @longphamdev
    OwnerAuthor

    Đóng nhầm — reopen ngay (xem comment sau).

  3. longphamdev commented on Nov 9, 2026

    @longphamdev
    OwnerAuthor

    #2 hoàn thành. Commit 0445f2d (merged to master).

    Acceptance:

    • ✅ auth login --add: dùng saveAccount trực tiếp (không facade), output ADDED/UPDATED theo dedupe userId, hỗ trợ --label
    • ✅ auth remove <id|label>: primary removal re-point rõ ràng; acc cuối cần --yes; unknown id → error + exit 1
    • ✅ auth logout: chỉ xóa primary (facade behavior giữ nguyên)
    • ✅ auth list (Per-account quota poller + /quota schema {accounts, aggregate, legacy} #6) verified qua CLI subprocess thật
    • ✅ Subprocess tests: real bun run src/index.ts trên temp store — masking, không credential trên stdout, refusal cases, primary re-point, loadCredential() resolution
    • ✅ Pool hot-add test: CLI process ghi store → pool nhận trong sync timer, acc mới tham gia rotation

    Suite: local 1230/0, container 1231/0 (merged master).

    Docs: docs/multi-account.md — cách thêm acc, strategy, states, bảng lỗi→hành động, giới hạn đã chấp nhận (async job không failover, single-acc pass-through).

    E2E 2 acc thật: chưa chạy được — acc thứ hai quota rỗng (đã xác nhận trước đó). Việc claim tay trên web là việc của mày; auto-claim multi-acc vẫn nằm ngoài plan. Khi acc thứ hai có quota, chạy: vài request qua proxy + xem phân phối và header x-zcode-account (debug on).

  4. longphamdev commented on Nov 9, 2026

    @longphamdev
    OwnerAuthor

    Đủ acceptance. Chuỗi multi-account: #1 #3 #4 #5 #6 #2 — tất cả closed. Docs tại docs/multi-account.md.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions