Skip to content

Commit cd025d1

Browse files
committed
test(actor_card): Fix misleading truncation test + add real coverage
The original "renders every property without truncation" test created 15 properties and sat inside the 20-field no-truncation window — the name implied truncation coverage that wasn't actually being exercised. - Renamed to "renders all input fields when count is within MAX_INPUT_SCHEMA_TEXT_FIELDS". - Added a separate test that puts MAX_INPUT_SCHEMA_TEXT_FIELDS + 5 properties through and asserts: * the last in-window field is rendered * the first overflow field is NOT rendered * the " ... (+5 more)" suffix appears - Dropped the negative regex assertion against `/Input schema \(\d+ of \d+\)/` — asserted a format the code never produces. Per review on #737.
1 parent e538171 commit cd025d1

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

tests/unit/utils.actor_card.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Actor } from 'apify-client';
22
import { describe, expect, it } from 'vitest';
33

4+
import { MAX_INPUT_SCHEMA_TEXT_FIELDS } from '../../src/const.js';
45
import type { ActorStoreList } from '../../src/types.js';
56
import { formatActorToActorCard, formatActorToStructuredCard } from '../../src/utils/actor_card.js';
67

@@ -613,14 +614,26 @@ describe('formatActorToActorCard inputSchema rendering', () => {
613614
expect(result).toContain('- **Input fields:** url: string, maxResults?: number');
614615
});
615616

616-
it('renders every property without truncation so structured output and text stay in sync', () => {
617+
it(`renders all input fields when count is within MAX_INPUT_SCHEMA_TEXT_FIELDS (${MAX_INPUT_SCHEMA_TEXT_FIELDS})`, () => {
617618
const properties: Record<string, { type: string }> = {};
618-
for (let i = 0; i < 15; i++) properties[`field${i}`] = { type: 'string' };
619+
for (let i = 0; i < MAX_INPUT_SCHEMA_TEXT_FIELDS; i++) properties[`field${i}`] = { type: 'string' };
619620
const actor = { ...mockActorStoreList, inputSchema: { type: 'object' as const, properties } } as ActorStoreList;
620621
const result = formatActorToActorCard(actor);
621622
expect(result).toContain('field0?: string');
622-
expect(result).toContain('field14?: string');
623-
expect(result).not.toMatch(/Input schema \(\d+ of \d+\)/);
623+
expect(result).toContain(`field${MAX_INPUT_SCHEMA_TEXT_FIELDS - 1}?: string`);
624+
expect(result).not.toMatch(/\(\+\d+ more\)/);
625+
});
626+
627+
it(`truncates to MAX_INPUT_SCHEMA_TEXT_FIELDS and appends "... (+N more)" when count exceeds the cap`, () => {
628+
const overflow = 5;
629+
const total = MAX_INPUT_SCHEMA_TEXT_FIELDS + overflow;
630+
const properties: Record<string, { type: string }> = {};
631+
for (let i = 0; i < total; i++) properties[`field${i}`] = { type: 'string' };
632+
const actor = { ...mockActorStoreList, inputSchema: { type: 'object' as const, properties } } as ActorStoreList;
633+
const result = formatActorToActorCard(actor);
634+
expect(result).toContain(`field${MAX_INPUT_SCHEMA_TEXT_FIELDS - 1}?: string`);
635+
expect(result).not.toContain(`field${MAX_INPUT_SCHEMA_TEXT_FIELDS}?: string`);
636+
expect(result).toContain(` ... (+${overflow} more)`);
624637
});
625638

626639
it('joins mixed-type property arrays with `|`', () => {

0 commit comments

Comments
 (0)