Unit tests for the task activity limit and cursor rules

Open Beginner friendly
#738 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
95/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
backend, testing

Research direction

Read app/packages/core/src/work/task-activity.ts, the limits in app/packages/contracts/src/work.ts, and the pattern in app/tests/app/search-core.test.ts. Add the specified cases to app/tests/app/task-activity-window-core.test.ts, then run the provided Docker test command and repository checks. Done means the tests pass with no production changes.

Written by the indexing model from the issue text.

Description

good first issue

Context

A task's activity list (#488) is paged by limit and an opaque before cursor. The rule is strict on purpose: a limit outside 1 to 50 or a cursor that is not exactly what an earlier page returned is refused, never clamped. A client that sends limit=500 must learn it is wrong, not silently get 50. The rule lives in two small pure functions that are only exercised through the API suite, which needs a database.

Found on main at 75df7fffd: nothing in app/tests names activityWindow.

Files

  • app/packages/core/src/work/task-activity.ts
    • encodeActivityCursor(position) (line 14) and the private decodeActivityCursor (line 16): a base64url JSON { t: <timestamp with 6 fractional digits>Z, i: <uuid> }.
    • activityWindow(query) (line 29): limit 1 to 50, 30 when omitted; before optional.
    • The limits come from TASK_ACTIVITY_PAGE in app/packages/contracts/src/work.ts (line 73).
  • Errors are InvalidInputError with code INVALID_CURSOR for a bad cursor (app/packages/core/src/access/errors.ts).
  • Pattern to copy: app/tests/app/search-core.test.ts (pure functions, refusal(code) helper with assert.throws). Import the two functions from ../../packages/core/src/work/task-activity.js if @flux/core does not re-export them.

Checked before filing: a draft of the cases below passed against main at cb25512e6 in the test image, so the tests describe today's behaviour and need no production change.

Acceptance criteria

  • A new file app/tests/app/task-activity-window-core.test.ts covers:
    • no query and an empty query give { limit: 30, before: null };
    • limit 1 and 50 are accepted; 0, 51, 1.5, -1 and NaN are refused with InvalidInputError (not clamped);
    • a cursor made by encodeActivityCursor round-trips into the same { position, id };
    • refused with code INVALID_CURSOR: an empty string, a string with characters outside base64url, a valid base64url string that is not JSON, JSON with a wrong timestamp shape (three fractional digits), JSON with an i that is not a UUID, and a non-string before.
  • No production code changes. A failing case that shows a real bug gets its own issue.
  • The tests pass, and the repository checks stay green.

How to check

docker build --file docker/Dockerfile --target test --tag flux-unit app
docker run --rm --network none flux-unit node_modules/.bin/tsx --test tests/app/task-activity-window-core.test.ts
docker image rm flux-unit
python3 scripts/check_agent_setup.py
git diff --check

See CONTRIBUTING for the fork and PR steps. Put Closes #<this issue> in the PR description.

Dominant language
TypeScript
Stars
3
Forks
0
Avg merge
11h 54m
Merged PRs (30d)
371

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ColdPhase/flux

All issues in ColdPhase/flux

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.