π€― 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
β¨ feat(verify): add deleteRun so `lh verify run delete` can remove a published session (#16391)
Arvin Xued8ecfff839a
diff --git a/apps/cli/src/commands/verify.test.ts b/apps/cli/src/commands/verify.test.tsindex 84e2d0439ca..810bbdf0991 100644--- a/apps/cli/src/commands/verify.test.ts+++ b/apps/cli/src/commands/verify.test.ts@@ -11,6 +11,7 @@ const { mockTrpcClient } = vi.hoisted(() => ({mockTrpcClient: {verify: {createRubric: { mutate: vi.fn() },+ deleteRun: { mutate: vi.fn() },getRubric: { query: vi.fn() },getSkillBundle: { query: vi.fn() },updateRubric: { mutate: vi.fn() },@@ -94,6 +95,34 @@ describe('verify rubric config commands', () => {});});+describe('verify run delete command', () => {+ let consoleSpy: ReturnType<typeof vi.spyOn>;++ beforeEach(() => {+ consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});+ mockGetTrpcClient.mockResolvedValue(mockTrpcClient);+ mockTrpcClient.verify.deleteRun.mutate.mockReset().mockResolvedValue({+ id: 'run-1',+ success: true,+ });+ });++ afterEach(() => consoleSpy.mockRestore());++ const run = async (args: string[]) => {+ const program = new Command();+ program.exitOverride();+ registerVerifyCommand(program);+ await program.parseAsync(['node', 'lh', 'verify', ...args]);+ };++ it('deletes the run without prompting when --yes is passed', async () => {+ await run(['run', 'delete', 'run-1', '--yes']);++ expect(mockTrpcClient.verify.deleteRun.mutate).toHaveBeenCalledWith({ verifyRunId: 'run-1' });+ });+});+describe('verify evidence upload command', () => {let exitSpy: ReturnType<typeof vi.spyOn>;diff --git a/apps/cli/src/commands/verify.ts b/apps/cli/src/commands/verify.tsindex 7f2d5e14ae6..dfc5c22da2f 100644--- a/apps/cli/src/commands/verify.ts+++ b/apps/cli/src/commands/verify.ts@@ -571,6 +571,27 @@ export function registerVerifyCommand(program: Command) {console.log(JSON.stringify(item, null, 2));});+ run+ .command('delete <runId>')+ .description('Delete a verification session (cascades its results, evidence and report)')+ .option('-y, --yes', 'Skip the confirmation prompt')+ .option('--json [fields]', 'Output JSON')+ .action(async (runId: string, options: { json?: boolean | string; yes?: boolean }) => {+ const client = await getTrpcClient();+ if (!options.yes) {+ const ok = await confirm(+ `Delete run ${pc.bold(runId)} and all its results, evidence and report? This cannot be undone.`,+ );+ if (!ok) return void console.log('Aborted.');+ }+ const result = await client.verify.deleteRun.mutate({ verifyRunId: runId });+ if (options.json !== undefined) {+ outputJson(result, typeof options.json === 'string' ? options.json : undefined);+ return;+ }+ console.log(`${pc.green('β')} Deleted run ${pc.bold(result.id)}`);+ });+// ββββββββββββ result (check result entity) ββββββββββββconst result = verify.command('result').description('Check results (verify_check_results)');diff --git a/apps/server/src/routers/lambda/__tests__/verify.test.ts b/apps/server/src/routers/lambda/__tests__/verify.test.tsindex 25972c04b63..94aa674fa86 100644--- a/apps/server/src/routers/lambda/__tests__/verify.test.ts+++ b/apps/server/src/routers/lambda/__tests__/verify.test.ts@@ -5,6 +5,7 @@ import { FileService } from '@/server/services/file';const modelMocks = vi.hoisted(() => ({createEvidence: vi.fn(),+ deleteRun: vi.fn(),findRunByOperation: vi.fn(),findRunById: vi.fn(),findResultById: vi.fn(),@@ -26,6 +27,7 @@ vi.mock('@/database/models/verifyCheckResult', () => ({vi.mock('@/database/models/verifyRun', () => ({VerifyRunModel: vi.fn(() => ({+ delete: modelMocks.deleteRun,findByOperation: modelMocks.findRunByOperation,findById: modelMocks.findRunById,})),@@ -92,6 +94,28 @@ describe('verifyRouter', () => {});});+ describe('deleteRun', () => {+ it("rejects a run outside the caller's scope before deleting", async () => {+ modelMocks.findRunById.mockResolvedValueOnce(undefined);++ await expect(createCaller().deleteRun({ verifyRunId: 'other-user-run' })).rejects.toThrow(+ 'Verification run not found',+ );++ expect(modelMocks.findRunById).toHaveBeenCalledWith('other-user-run');+ expect(modelMocks.deleteRun).not.toHaveBeenCalled();+ });++ it('deletes a run the caller owns and returns its id', async () => {+ modelMocks.findRunById.mockResolvedValueOnce({ id: 'run-1' });++ const res = await createCaller().deleteRun({ verifyRunId: 'run-1' });++ expect(modelMocks.deleteRun).toHaveBeenCalledWith('run-1');+ expect(res).toEqual({ id: 'run-1', success: true });+ });+ });+describe('submitCheckEvidence', () => {it("rejects a run outside the caller's scope before upserting", async () => {modelMocks.findRunById.mockResolvedValueOnce(undefined);diff --git a/apps/server/src/routers/lambda/verify.ts b/apps/server/src/routers/lambda/verify.tsindex 0e65a79342c..61d50599fa1 100644--- a/apps/server/src/routers/lambda/verify.ts+++ b/apps/server/src/routers/lambda/verify.ts@@ -445,6 +445,17 @@ export const verifyRouter = router({.input(verifyRunIdInputSchema).query(async ({ ctx, input }) => ctx.runModel.findById(input.verifyRunId)),+ // Delete a whole verification session: the run row cascades to its check+ // results (β their evidence) and its report via the schema FKs, so one delete+ // tears down the published bundle. Ownership-scoped: resolveVerifyRun 404s a+ // run that isn't the caller's before we touch it.+ deleteRun: verifyProcedure.input(verifyRunIdInputSchema).mutation(async ({ ctx, input }) => {+ const run = await resolveVerifyRun(ctx, input.verifyRunId);++ await ctx.runModel.delete(run.id);+ return { id: run.id, success: true };+ }),+listRuns: verifyProcedure.query(async ({ ctx }) => ctx.runModel.query()),listResultsByRun: verifyProcedure.input(verifyRunIdInputSchema).query(async ({ ctx, input }) => {