Files
PaperClipAI/ui
DottaandClaude Opus 5.5 792c17aac7 fix(ui): freeze the clock in the persisted PR-read cache test (#21147)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The board UI saves approved reads to local storage. A reload can
then show them at once.
> - The test `bounds saved PR reads and retains their original age
through later saves` checks the limit of 100 saved PR reads.
> - The test reads `Date.now()` one time and uses that value as the
cache clock. Then `seed()` writes the session and company list with the
real clock.
> - If the real clock moves 1 ms or more between these two steps, the
saved session has a time in the future. The cache correctly rejects that
session, so it restores no data.
> - This failed CI 5 times in 48 hours on 5 unrelated pull requests.
Each failure was `expected [] to have a length of 100 but got +0`.
> - This pull request freezes the clock in that test, as the sibling
tests in the same file already do.
> - The benefit is a deterministic test, and no more unrelated red CI
runs.

## Linked Issues or Issue Description

**What happened?**
The UI test `ui/src/lib/persisted-query-cache.test.ts > persisted read
cache > bounds saved PR reads and retains their original age through
later saves` failed in CI 5 times in 48 hours on 5 unrelated branches.
The error was `AssertionError: expected [] to have a length of 100 but
got +0` at line 82.

**Expected behavior**
The test passes on every run, independent of machine load.

**Steps to reproduce**
1. Start two CPU busy loops (`node -e 'while(true){}'`).
2. Run `pnpm --filter @paperclipai/ui exec vitest run
src/lib/persisted-query-cache.test.ts -t "bounds saved PR reads"` 30
times, two at a time.
3. Before this change: 0 pass, 30 fail, all at line 82.

Root cause: the test injects a fixed clock (`now`) into the cache, but
`seed()` calls `setQueryData` without `updatedAt`. TanStack Query then
uses the real `Date.now()`. When the real clock passes the fixed clock,
`fresh()` sees a session read from the future. The flush then does not
save the session, and the restore aborts. The product code is correct.
The test clock was not consistent.

## What Changed

- Call `vi.useFakeTimers()` at the start of `bounds saved PR reads and
retains their original age through later saves`. `Date.now()` is now
frozen, so the seeded reads and the injected clock agree. The other
clock-driven tests in this file already do this.
- Call `vi.useFakeTimers()` in `discards snapshots after %s changes`. It
had the same race. There, the race did not fail the test, but it let the
test pass without the discard path under test.

## Verification

- Deterministic red/green: I added a real 5 ms sleep (`Atomics.wait`)
after `let now = Date.now()` in a temporary copy of the test. Without
the fix: `expected [] to have a length of 100 but got +0`. With the fix:
pass. I removed the temporary copies.
- Loop under load (two CPU busy loops, two parallel vitest processes, 30
runs each):
  - Before: 0 pass, 30 fail (all at `persisted-query-cache.test.ts:82`).
  - After: 30 pass, 0 fail.
- Full file: `pnpm --filter @paperclipai/ui exec vitest run
src/lib/persisted-query-cache.test.ts`: 54 passed.

## Risks

- Low risk. The change is test-only. Fake timers are reset in the
existing `afterEach` (`vi.useRealTimers()`).

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, file edit) and reasoning.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 11:17:56 -06:00
..
…

@paperclipai/ui

Published static assets for the Paperclip board UI.

What gets published

The npm package contains the production build under dist/. It does not ship the UI source tree or workspace-only dependencies.

Storybook

Storybook config, stories, and fixtures live under ui/storybook/.

pnpm --filter @paperclipai/ui storybook
pnpm --filter @paperclipai/ui build-storybook

Typical use

Install the package, then serve or copy the built files from node_modules/@paperclipai/ui/dist.

Editor dependency identity

Keep the root and workspace overrides for @codemirror/state, @codemirror/view, and @lezer/common aligned. CodeMirror requires shared extension identity, while Lezer parsers and syntax highlighters require shared NodeProp IDs. Multiple Lezer copies can crash code-block highlighting with tags is not iterable. src/lib/codemirror-single-instance.test.ts checks the installed dependency graph and highlights sample code through the editor's real language dependencies. GitHub Actions owns regeneration of pnpm-lock.yaml.