From b4e3e42572532eadf3fcae48ca10c1760c26add8 Mon Sep 17 00:00:00 2001 From: l1shen <648952316@qq.com> Date: Wed, 14 Oct 2026 17:03:10 +0800 Subject: [PATCH] fix(team): accept omitted system_created in team responses --- .../commands/team/index.cli.test.ts | 1 - src/application/commands/team/shared.test.ts | 28 +++++++++++++++---- src/application/commands/team/shared.ts | 10 ++----- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/application/commands/team/index.cli.test.ts b/src/application/commands/team/index.cli.test.ts index 9b1fcc92..496537d3 100644 --- a/src/application/commands/team/index.cli.test.ts +++ b/src/application/commands/team/index.cli.test.ts @@ -33,7 +33,6 @@ const teamsResponse = { id: "team-2", name: "beta", role: "member", - system_created: false, }, ], }; diff --git a/src/application/commands/team/shared.test.ts b/src/application/commands/team/shared.test.ts index 3330a1d1..8f3c341b 100644 --- a/src/application/commands/team/shared.test.ts +++ b/src/application/commands/team/shared.test.ts @@ -112,7 +112,7 @@ describe("listMemberTeams", () => { ]); }); - test("rejects a team item missing the required role or system_created field", async () => { + test("rejects a team item missing the required role", async () => { const missingRole = await expectCliUserError(listMemberTeams( testAccount, createRequestContext({ @@ -122,16 +122,34 @@ describe("listMemberTeams", () => { }), )); expect(missingRole.key).toBe("errors.team.invalidResponse"); + }); - const missingSystemCreated = await expectCliUserError(listMemberTeams( + test("accepts a team without the system_created marker", async () => { + const teams = await listMemberTeams( testAccount, createRequestContext({ - fetcher: async () => new Response(JSON.stringify({ + fetcher: async () => Response.json({ teams: [{ id: "team-1", name: "acme", role: "creator" }], - })), + }), + }), + ); + + expect(teams).toEqual([ + { id: "team-1", name: "acme", role: "creator", systemCreated: false }, + ]); + }); + + test.each([null, "false", 0])("rejects an invalid system_created marker: %p", async (systemCreated) => { + const error = await expectCliUserError(listMemberTeams( + testAccount, + createRequestContext({ + fetcher: async () => Response.json({ + teams: [{ id: "team-1", name: "acme", role: "creator", system_created: systemCreated }], + }), }), )); - expect(missingSystemCreated.key).toBe("errors.team.invalidResponse"); + + expect(error.key).toBe("errors.team.invalidResponse"); }); test("returns an empty list when the account has no teams", async () => { diff --git a/src/application/commands/team/shared.ts b/src/application/commands/team/shared.ts index 377ed966..54816be4 100644 --- a/src/application/commands/team/shared.ts +++ b/src/application/commands/team/shared.ts @@ -4,17 +4,13 @@ import type { AuthAccount } from "../../schemas/auth.ts"; import { z } from "zod"; import { probeOo, requestOo } from "../shared/oo-request.ts"; -// One team the current account belongs to. The membership listing always -// carries `role` (exactly `creator` or `member`; any other value is treated as -// a plain membership) and `system_created`, which marks the team the backend -// provisions for every account (at most one at a time, and it cannot be -// deleted). Both fields are always present in the response, so both are -// required — a missing one is a malformed response, not a defaulted value. +// The backend may omit system_created for teams that were not provisioned +// automatically. const teamResponseItemSchema = z.object({ id: z.string().min(1), name: z.string().min(1), role: z.string(), - system_created: z.boolean(), + system_created: z.boolean().default(false), }); // `GET /v1/me/teams` wraps the memberships in a `teams` array. The array is