Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(brain): close two gaps CodeRabbit found in my own regression tests\n\nBoth findings are correct, and both are about tests I added in the previous\ncommit rather than about the product.\n\n1. The empty-message test only covered the FIRST-load (destructive) branch, so\n a truthiness regression in the WARNING branch would still have passed the\n suite. My own mutation had hidden this: I reverted BOTH branches at once, so\n the single test was enough to fail it. Reverting only the warning branch is\n the sharper mutation and it passed. Added a refresh-failure case with\n `new Error('')` asserting the warning variant with the graph still visible.\n\n Revert-proof: with ONLY the warning branch back on truthiness, ONLY the new\n test fails and the first-load one passes. The two branches are now\n independently covered rather than jointly.\n\n2. The overlapping-load test could pass VACUOUSLY. If the refresh event never\n started a second load, resolving the first would render a graph with no\n warning and both final assertions would be satisfied for the wrong reason.\n Added the precondition — two calls made and an alert present — before\n resolving the older call.\n\n Demonstrated rather than assumed: with the `memory-tree-completed` listener\n disabled, the test PASSES without the precondition and FAILS with it (3\n failures versus 4, the difference being exactly this test).\n\n6/6 green, sources restored, typecheck clean.\n

M3gA-Mind6f9445ee13e0
diff --git a/app/src/pages/__tests__/Brain.errorRecovery.test.tsx b/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
index 88025da23f..11c83d1979 100644
--- a/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
+++ b/app/src/pages/__tests__/Brain.errorRecovery.test.tsx
@@ -252,6 +252,33 @@ describe('Brain graph — transient failure recovery', () => {
});
});
+ it('still warns when a REFRESH failure carries an empty message', async () => {
+ // The sibling test covers an empty message on the FIRST load, which is the
+ // destructive branch. This covers the warning branch, and the two need
+ // separate cases: a truthiness regression in only one of them would
+ // otherwise slip through on the strength of the other.
+ graphExportMock.mockResolvedValueOnce(makeGraph(5)).mockRejectedValue(new Error(''));
+
+ await act(async () => {
+ renderWithProviders(<Brain />, { initialEntries: ['/?tab=graph'] });
+ });
+ await waitFor(() => {
+ expect(screen.getByTestId('memory-graph')).toHaveTextContent('nodes:5');
+ });
+
+ await act(async () => {
+ window.dispatchEvent(new Event('openhuman:memory-tree-completed'));
+ });
+
+ await waitFor(() => {
+ const alert = document.querySelector('[data-slot="alert"]');
+ expect(alert).not.toBeNull();
+ expect(alert).toHaveAttribute('data-variant', 'warning');
+ });
+ // And the stale graph is still there, as in the non-empty case.
+ expect(screen.getByTestId('memory-graph')).toHaveTextContent('nodes:5');
+ });
+
it('does not warn when an older load succeeds after a newer one failed', async () => {
// Two `load()` calls overlap and share `graph`/`error`: the initial one and
// one started by `memory-tree-completed`. If the NEWER fails while the
@@ -278,6 +305,15 @@ describe('Brain graph — transient failure recovery', () => {
window.dispatchEvent(new Event('openhuman:memory-tree-completed'));
});
+ // Assert the PRECONDITION before resolving anything. Without this the test
+ // passes vacuously: if the event never started a second load, resolving the
+ // first would render a graph with no warning and the final assertions would
+ // be satisfied for entirely the wrong reason.
+ await waitFor(() => {
+ expect(graphExportMock).toHaveBeenCalledTimes(2);
+ expect(document.querySelector('[data-slot="alert"]')).not.toBeNull();
+ });
+
// Now the older, superseded call finally succeeds.
await act(async () => {
resolveFirst(makeGraph(4));