Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions front/lib/api/assistant/configuration/views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ async function listAgentIdsForAnalytics(auth: Authenticator) {

const REPORTING_ROLES = ["admin", "manager"] as const;

describe("getAgentConfigurationsForView, default ordering", () => {
it.each([
undefined,
2,
])("defaults to alphabetical ordering with limit=%s", async (limit) => {
const { authenticator } = await createResourceTest({});
const agentC = await AgentConfigurationFactory.createTestAgent(
authenticator,
{ name: "Ordering C" }
);
const agentB = await AgentConfigurationFactory.createTestAgent(
authenticator,
{ name: "Ordering B" }
);
const agentA = await AgentConfigurationFactory.createTestAgent(
authenticator,
{ name: "Ordering A" }
);

const agents = await getAgentConfigurationsForView({
auth: authenticator,
agentsGetView: "list",
variant: "light",
agentPrefix: "Ordering",
limit,
});

expect(agents.map((agent) => agent.sId)).toEqual(
[agentA.sId, agentB.sId, agentC.sId].slice(0, limit)
);
});
});

describe("getAgentConfigurationsForView, 'analytics' view", () => {
it.each(
REPORTING_ROLES
Expand Down
10 changes: 8 additions & 2 deletions front/lib/api/assistant/configuration/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ async function fetchGlobalAgentConfigurationForView(
return matchingGlobalAgents.filter((a) => a.status === "active");
}

/**
* @cc [owner:philipperolet,label:backend] default-agent-query-order
* Active-agent queries MUST default to name order when no sort is requested.
*/
async function fetchWorkspaceAgentConfigurationsWithoutActions(
auth: Authenticator,
{
Expand All @@ -171,7 +175,9 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(
omitHeavyAttributes?: boolean;
}
): Promise<AgentConfigurationModel[]> {
const sortStrategy = sort && sortStrategies[sort];
// Active names are unique per workspace; their (workspaceId, name) index can supply this
// default order without a separate sort or an ID tie-breaker.
const sortStrategy = sortStrategies[sort ?? "alphabetical"];

const baseWhereConditions = {
workspaceId: owner.id,
Expand All @@ -189,7 +195,7 @@ async function fetchWorkspaceAgentConfigurationsWithoutActions(

const baseAgentsSequelizeQuery = {
limit,
order: sortStrategy?.dbOrder,
order: sortStrategy.dbOrder,
...excludeAttributesFromSelect,
};

Expand Down
Loading