Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

1.0 KB
Raw Blame
import type { IndexDefinition, IndexOptions } from 'mongoose';
import messageSchema from './message';

describe('Subagent task indexes', () => {
  it('streams newest child-task candidates in index order', () => {
    const indexes = messageSchema.indexes() as Array<[IndexDefinition, IndexOptions]>;
    expect(indexes).toContainEqual([
      { user: 1, conversationId: 1, createdAt: -1, _id: -1 },
      expect.objectContaining({ name: 'subagent_thread_latest_message' }),
    ]);
  });

  it('indexes bounded terminal lookups by parent run and recency', () => {
    const indexes = messageSchema.indexes() as Array<[IndexDefinition, IndexOptions]>;
    expect(indexes).toContainEqual([
      {
        user: 1,
        'subagentTask.parentRunId': 1,
        'subagentTask.status': 1,
        updatedAt: -1,
        _id: -1,
      },
      expect.objectContaining({
        name: 'subagent_parent_run_status_updated',
        partialFilterExpression: { 'subagentTask.parentRunId': { $exists: true } },
      }),
    ]);
  });
});