π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(cli): say when an acceptance publishes to personal space (#21685)
Lobehub Coder014ecdbd7601
diff --git a/apps/cli/src/commands/acceptance/index.create.test.ts b/apps/cli/src/commands/acceptance/index.create.test.tsindex 9969a2fcc1a..6df226b1e80 100644--- a/apps/cli/src/commands/acceptance/index.create.test.ts+++ b/apps/cli/src/commands/acceptance/index.create.test.ts@@ -32,6 +32,9 @@ const jsonOutput = () => JSON.parse(String(output.mock.calls.at(-1)?.[0]));beforeEach(() => {vi.clearAllMocks();output = vi.spyOn(console, 'log').mockImplementation(() => {});+ // This repository declares a project in `.agents/acceptance/config.json`;+ // run outside it so only `--project` files an acceptance here.+ vi.spyOn(process, 'cwd').mockReturnValue(tmpdir());vi.mocked(getTrpcClient).mockResolvedValue({acceptance: {ensure: { mutate: ensure },diff --git a/apps/cli/src/commands/acceptance/project.ts b/apps/cli/src/commands/acceptance/project.tsindex d5c589f7c88..eeb5e6f86b3 100644--- a/apps/cli/src/commands/acceptance/project.ts+++ b/apps/cli/src/commands/acceptance/project.ts@@ -3,6 +3,7 @@ import path from 'node:path';import { TRPCClientError } from '@trpc/client';import type { TrpcClient } from '../../api/client';+import { resolveWorkspaceScope } from '../../api/workspace';import { log } from '../../utils/logger';import { findDeclaredProject } from './utils';@@ -26,6 +27,12 @@ export const projectEnsureInput = (project: AcceptanceProject | undefined) => {const isNotFound = (error: unknown) =>error instanceof TRPCClientError && error.data?.code === 'NOT_FOUND';+const isUnchosenPersonalScope = () => {+ const scope = resolveWorkspaceScope();+ if (scope.workspaceId || process.env.LOBEHUB_JWT) return false;+ return scope.source === 'personal' || scope.source === 'stale';+};+/*** The project a delivery is filed under when the caller says so: `--project`,* else the project the repository declares (see {@link projectEnsureInput} for@@ -64,11 +71,27 @@ export async function resolveAcceptanceProject(return;}+ // Only the acceptance's own workspace lets its members review it, so a+ // round published from personal space is the creator's alone β a terminal+ // that never chose a workspace looks like a teammate's missing permission.+ // Say so whether or not personal space happens to have the project. An+ // explicit `LOBEHUB_WORKSPACE_ID=personal` or a server-dispatched run (whose+ // scope the server sets) meant to be personal, so neither is told to change it.+ const warnPersonalScope = () => {+ if (!isUnchosenPersonalScope()) return false;+ log.warn(+ `${file} files acceptances under project "${declared.project}", but this command runs in your personal space, so workspace teammates cannot review this acceptance β only you can. To publish to the project's workspace instead, set LOBEHUB_WORKSPACE_ID=<workspace id> or run 'lh workspace use <workspace>'.`,+ );+ return true;+ };+try {const { data } = await client.project.find.query({ id: declared.project });+ warnPersonalScope();return { id: data.id, name: data.name, source: 'config' };} catch (error) {if (!isNotFound(error)) throw error;+ if (warnPersonalScope()) return;log.warn(`${file} files acceptances under project "${declared.project}", which this workspace does not have β publishing ungrouped.`,);diff --git a/apps/cli/src/commands/acceptance/run/index.schema.test.ts b/apps/cli/src/commands/acceptance/run/index.schema.test.tsindex 25ec75fa09e..527abfcd784 100644--- a/apps/cli/src/commands/acceptance/run/index.schema.test.ts+++ b/apps/cli/src/commands/acceptance/run/index.schema.test.ts@@ -21,6 +21,9 @@ describe('offline acceptance report commands', () => {process.exitCode = undefined;printed = [];vi.spyOn(console, 'log').mockImplementation((line) => printed.push(String(line)));+ // This repository declares a project in `.agents/acceptance/config.json`;+ // run outside it so the dry run does not look that project up.+ vi.spyOn(process, 'cwd').mockReturnValue(tmpdir());vi.mocked(getTrpcClient).mockRejectedValue(new Error('No account configured'));dir = await mkdtemp(path.join(tmpdir(), 'lh-offline-report-'));});diff --git a/apps/cli/src/commands/acceptance/run/ingest.project.test.ts b/apps/cli/src/commands/acceptance/run/ingest.project.test.tsindex d60fdef27a4..761f3cb8b82 100644--- a/apps/cli/src/commands/acceptance/run/ingest.project.test.ts+++ b/apps/cli/src/commands/acceptance/run/ingest.project.test.ts@@ -2,14 +2,18 @@ import { mkdir, writeFile } from 'node:fs/promises';import path from 'node:path';import { TRPCClientError } from '@trpc/client';-import { describe, expect, it, vi } from 'vitest';+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { resolveWorkspaceScope } from '../../../api/workspace';import { log } from '../../../utils/logger';import type * as VerifyHelpers from '../utils';import { usePublicationHarness } from './testUtils';vi.mock('../../../api/client', () => ({ getTrpcClient: vi.fn() }));-vi.mock('../../../api/workspace', () => ({ resolveWorkspaceId: vi.fn() }));+vi.mock('../../../api/workspace', () => ({+ resolveWorkspaceId: vi.fn(),+ resolveWorkspaceScope: vi.fn(),+}));vi.mock('../../../settings', () => ({ resolveServerUrl: vi.fn() }));vi.mock('../../../utils/uploadLocalFile', () => ({ uploadLocalFile: vi.fn() }));vi.mock('../utils', async (importOriginal) => ({@@ -26,6 +30,10 @@ describe('lh acceptance run ingest β project filing', () => {const h = usePublicationHarness();const { client, run } = h;+ beforeEach(() => {+ vi.mocked(resolveWorkspaceScope).mockReturnValue({ source: 'env', workspaceId: 'ws_team' });+ });+/** The report directory doubles as the repository root its adapter lives in. */const declareProject = async (config: unknown) => {await mkdir(path.join(h.dir, '.agents', 'acceptance'), { recursive: true });@@ -109,7 +117,7 @@ describe('lh acceptance run ingest β project filing', () => {await run('ingest', h.dir, '--json');expect(vi.mocked(log.warn)).toHaveBeenCalledWith(- expect.stringContaining('publishing ungrouped'),+ expect.stringContaining('which this workspace does not have'),);expect(client.acceptance.ensure.mutate.mock.calls[0][0]).not.toHaveProperty('fallbackProjectId',@@ -117,6 +125,66 @@ describe('lh acceptance run ingest β project filing', () => {expect(client.verify.createRun.mutate).toHaveBeenCalled();});+ it('names personal space as the reason when the declared project is not found there', async () => {+ await writeReport();+ await declareProject({ project: 'LOBE' });+ vi.stubEnv('LOBEHUB_JWT', '');+ vi.mocked(resolveWorkspaceScope).mockReturnValue({ source: 'personal' });+ client.project.find.query.mockRejectedValue(notFound());++ await run('ingest', h.dir, '--json');++ const warning = vi+ .mocked(log.warn)+ .mock.calls.map(([message]) => message)+ .join('\n');+ expect(warning).toContain('runs in your personal space');+ expect(warning).toContain('workspace teammates cannot review');+ expect(warning).toContain('LOBEHUB_WORKSPACE_ID');+ expect(client.verify.createRun.mutate).toHaveBeenCalled();+ });++ it('still names personal space when personal space has a project with the declared id', async () => {+ await writeReport();+ await declareProject({ project: 'LOBE' });+ vi.stubEnv('LOBEHUB_JWT', '');+ vi.mocked(resolveWorkspaceScope).mockReturnValue({ source: 'personal' });+ client.project.find.query.mockResolvedValue({ data: { id: 'prj_mine', name: 'Mine' } });++ await run('ingest', h.dir, '--json');++ expect(vi.mocked(log.warn)).toHaveBeenCalledWith(+ expect.stringContaining('workspace teammates cannot review'),+ );+ expect(client.acceptance.ensure.mutate).toHaveBeenCalledWith(+ expect.objectContaining({ fallbackProjectId: 'prj_mine' }),+ );+ });++ it.each([+ { name: 'an explicit personal scope', scope: { source: 'env' as const }, jwt: '' },+ {+ name: 'a server-dispatched personal run',+ scope: { source: 'personal' as const },+ jwt: 'op-token',+ },+ ])('does not tell $name to change its workspace', async ({ jwt, scope }) => {+ await writeReport();+ await declareProject({ project: 'LOBE' });+ vi.stubEnv('LOBEHUB_JWT', jwt);+ vi.mocked(resolveWorkspaceScope).mockReturnValue(scope);+ client.project.find.query.mockRejectedValue(notFound());++ await run('ingest', h.dir, '--json');++ expect(vi.mocked(log.warn)).toHaveBeenCalledWith(+ expect.stringContaining('which this workspace does not have'),+ );+ expect(vi.mocked(log.warn)).not.toHaveBeenCalledWith(+ expect.stringContaining('LOBEHUB_WORKSPACE_ID'),+ );+ });+it('ignores a malformed config instead of failing the round', async () => {await writeReport();await declareProject('{ "project": ');diff --git a/apps/cli/src/commands/acceptance/run/ingest.test.ts b/apps/cli/src/commands/acceptance/run/ingest.test.tsindex 4012609cf28..55524bbe86c 100644--- a/apps/cli/src/commands/acceptance/run/ingest.test.ts+++ b/apps/cli/src/commands/acceptance/run/ingest.test.ts@@ -36,10 +36,14 @@ vi.mock('../../../settings', () => ({describe('verify ingest-report β every run is an immutable acceptance round', () => {let consoleSpy: ReturnType<typeof vi.spyOn>;+ let cwdSpy: ReturnType<typeof vi.spyOn>;let dir: string;beforeEach(() => {consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});+ // This repository declares a project in `.agents/acceptance/config.json`;+ // run outside it so no suite files its acceptance under that project.+ cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(tmpdir());vi.stubEnv('LOBEHUB_WORKSPACE_ID', '');mockGetTrpcClient.mockResolvedValue(mockTrpcClient);const verify = mockTrpcClient.verify as Record<string, any>;@@ -62,6 +66,7 @@ describe('verify ingest-report β every run is an immutable acceptance round',afterEach(() => {consoleSpy.mockRestore();+ cwdSpy.mockRestore();vi.unstubAllEnvs();delete process.env.LOBEHUB_TOPIC_ID;rmSync(dir, { force: true, recursive: true });diff --git a/apps/cli/src/commands/acceptance/run/testUtils.ts b/apps/cli/src/commands/acceptance/run/testUtils.tsindex c84b6175498..a3ed8488294 100644--- a/apps/cli/src/commands/acceptance/run/testUtils.ts+++ b/apps/cli/src/commands/acceptance/run/testUtils.ts@@ -51,6 +51,9 @@ export const usePublicationHarness = () => {state.printed = [];vi.spyOn(console, 'log').mockImplementation((line) => state.printed.push(String(line)));vi.spyOn(log, 'warn').mockImplementation(() => {});+ // This repository declares a project in `.agents/acceptance/config.json`;+ // run outside it so a suite only sees the project it declares itself.+ vi.spyOn(process, 'cwd').mockReturnValue(tmpdir());vi.mocked(resolveServerUrl).mockReturnValue('https://app.lobehub.com');vi.mocked(getTrpcClient).mockResolvedValue(client as unknown as Awaited<ReturnType<typeof getTrpcClient>>,@@ -76,6 +79,7 @@ export const usePublicationHarness = () => {afterEach(async () => {process.exitCode = originalExitCode;vi.restoreAllMocks();+ vi.unstubAllEnvs();await rm(state.dir, { force: true, recursive: true });});