Skip to content

Conversation

@TomIsion
Copy link

@TomIsion TomIsion commented Nov 16, 2025

Description

When add input history more than MAX_HISTORY_LENGTH, cause pre() fail, because currentIndex = MAX_HISTORY_LENGTH + 1:

function prev(currentInput: JSONContent) {
  let index = currentIndex;

  if (index === inputHistory.length) {
    setPendingInput(currentInput);
  }

  if (index > 0 && index <= inputHistory.length) {
    setCurrentIndex((prevState) => prevState - 1);
    return inputHistory[index - 1];
  }
}

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • The relevant tests, if any, have been updated or created

Screen recording or screenshot

[ When applicable, please include a short screen recording or screenshot - this makes it much easier for us as contributors to review and understand your changes. See this PR as a good example. ]

Tests

add useInputHistory.test.ts to test this cause: History eviction (MAX_HISTORY_LENGTH)


Summary by cubic

Fixes input history navigation when history exceeds MAX_HISTORY_LENGTH. Prevents prev/next replace failures by clamping currentIndex.

  • Bug Fixes
    • Clamp currentIndex to MAX_HISTORY_LENGTH when adding a new item and slice history to the max length.
    • Added tests covering eviction at MAX_HISTORY_LENGTH, navigation (prev/next), duplicate handling, and edge cases.

Written for commit ef260b9. Summary will update automatically on new commits.

@TomIsion TomIsion requested a review from a team as a code owner November 16, 2025 08:53
@TomIsion TomIsion requested review from tingwai and removed request for a team November 16, 2025 08:53
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 16, 2025
@github-actions
Copy link

github-actions bot commented Nov 16, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@TomIsion
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="gui/src/hooks/test/useInputHistory.test.ts">

<violation number="1" location="gui/src/hooks/test/useInputHistory.test.ts:305">
`nextRef.current()` returns the pending input when you move forward from the last stored history entry, but this test asserts it is `undefined`, so it will fail whenever the hook returns the stored pending input. Update the expectation to match the hook&#39;s behavior.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

act(() => {
result.current.prevRef.current(emptyJsonContent());
const content = result.current.prevRef.current(emptyJsonContent());
expect(content).toBeUndefined(); // Should not crash
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextRef.current() returns the pending input when you move forward from the last stored history entry, but this test asserts it is undefined, so it will fail whenever the hook returns the stored pending input. Update the expectation to match the hook's behavior.

Prompt for AI agents
Address the following comment on gui/src/hooks/test/useInputHistory.test.ts at line 305:

<comment>`nextRef.current()` returns the pending input when you move forward from the last stored history entry, but this test asserts it is `undefined`, so it will fail whenever the hook returns the stored pending input. Update the expectation to match the hook&#39;s behavior.</comment>

<file context>
@@ -0,0 +1,370 @@
+      act(() =&gt; {
+        result.current.prevRef.current(emptyJsonContent());
+        const content = result.current.prevRef.current(emptyJsonContent());
+        expect(content).toBeUndefined(); // Should not crash
+      });
+
</file context>
Suggested change
expect(content).toBeUndefined(); // Should not crash
expect(content).toEqual(emptyJsonContent());
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant