Skip to content

test-agent: FIFO test comment contradicts the assertions and the implementation #20

@joewalker

Description

@joewalker

Observed behavior

In src/agents/__test__/test-agent.test.ts, the should return preset results in FIFO order test has an inline comment that contradicts both the assertions immediately below it and the implementation in src/agents/test.ts:

agent.setNextInvokeResult(first, second);

// FIFO: second is returned first (pop from end)
expect(await agent.invoke('prompt2')).toStrictEqual(first);
expect(await agent.invoke('prompt1')).toStrictEqual(second);

The comment claims FIFO means "second is returned first (pop from end)", but:

  • FIFO (first-in-first-out) means the first inserted result is returned first.
  • The assertions correctly verify that: the first invoke returns first, the second invoke returns second.
  • TestAgent.invoke uses this.#results.shift(), which removes from the front of the array, not the end.

So the test name and the assertions are correct; only the comment is wrong. The comment also misnames the prompts ('prompt2' is passed on the first invoke, 'prompt1' on the second) which adds to the confusion. The same swap on the prompt strings appears intentional only if the reader believed the misleading comment.

Expected behavior

The comment should describe the actual behaviour, for example:

// FIFO: first inserted is returned first (shift from front)
expect(await agent.invoke('prompt1')).toStrictEqual(first);
expect(await agent.invoke('prompt2')).toStrictEqual(second);

Minimal reproduction

Read src/agents/__test__/test-agent.test.ts lines 17 to 27. The behaviour is correct; only the comment is wrong, which makes the test confusing on first read.

Suggested fix

  1. Replace the comment with an accurate description (FIFO: first inserted is returned first (shift from front)).
  2. Swap the prompt string arguments ('prompt1' first, then 'prompt2') so they line up with the order they are submitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    S4Clean-ups or nits with low behavioral riskbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions