# minimal reproduction: a worked example

Canonical page: https://vibe-coding-101.brighteng.org/c/repro/#before-and-after

## The problem

A report says the last item disappears from every page of results. Reduce it to an array with one item and a requested page size of one. The expected result is that one item; the actual result is an empty array.

## Prompt to paste

Create a minimal reproduction for this bug. Record the input, expected result, and actual result before changing the implementation.

## Before

The slice end subtracts one even though JavaScript excludes the end index already. The smallest input reveals the mismatch without a router, UI, network request, or large fixture.

## After

Write the failing assertion before changing the endpoint. Use start + size as the exclusive end. Keep the minimal case as a regression check and add a partial last page to cover the neighboring boundary.

## Run the check

Save the following code as repro.mjs and run `node --test repro.mjs` with Node.js 22.12 or later.

```js
import test from 'node:test';
import assert from 'node:assert/strict';

function before(items, start, size) {
  return items.slice(start, start + size - 1);
}

function after(items, start, size) {
  return items.slice(start, start + size);
}

test('one item and a page size of one reproduce the report', () => {
  const actual = before(['book'], 0, 1);
  assert.deepEqual(actual, []);
  assert.throws(() => assert.deepEqual(actual, ['book']), { code: 'ERR_ASSERTION' });
});

test('the fix keeps the minimal case and neighboring boundaries', () => {
  assert.deepEqual(after(['book'], 0, 1), ['book']);
  assert.deepEqual(after(['a', 'b', 'c'], 0, 2), ['a', 'b']);
  assert.deepEqual(after(['a', 'b', 'c'], 2, 2), ['c']);
  assert.deepEqual(after([], 0, 1), []);
});
```

## Expected result

The exact one-item input returns [] before and [book] afterward. The comparison captures the original assertion failure and checks a full first page, a partial final page, and an empty list.

## Limits

A minimal reproduction must still retain the cause. Do not remove the concurrency, permissions, version, or environment that triggers the real bug just to make the example smaller. This example assumes nonnegative integer start and size values; it does not define API validation or pagination across a changing dataset. Record the command and runtime alongside the input.

## Sources

- [Stack Overflow: Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example): Minimal, complete, reproducible examples and explicit expected behavior.
- [MDN: Array.prototype.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice): The end index is excluded from the returned slice.

Sources checked: 2026-10-11. These are original illustrative examples with automated checks. Human editorial approval is not recorded. Policy: https://vibe-coding-101.brighteng.org/editorial/
