Skip to content

test(valkey): add a contract suite for the Valkey fake #4557

Closed

Description

@dan-petty

Problem or Motivation

The project fake fakeredis[valkey]==2.40.0 (pyproject.toml:113) answers unknown command 'eval', and valkey-py Lock.release() fails with unknown command 'evalsha', because lupa is not installed. Every valkey-py lock and every limits moving window uses Lua. The move of Service state into Valkey depends on both.

docs/TESTING.md:242 says that the Valkey fake "has no contract suite yet", and docs/TESTING.md:83 says "A fake without a contract suite does not merge".

Proposed Solution & Architectural Design

Target Subsystem

Workstation Caching & Valkey (tests: tests/, docs/TESTING.md).

Existing Tool Considered

fakeredis with lupa, and the Valkey release binary. A live Valkey in pytest is refused by the network block. Cost: about 80,000 tokens and 4 hours to build, about 5,000 tokens a month to keep, about 10,000 tokens to fix.

Acceptance Criteria

  • The suite passes against the fake, and against the real binary where the binary is on PATH, in the devcontainer and on the GitHub runner.
  • docs/TESTING.md:242 lists the Valkey fake as covered.
  • The pull request states the time that the suite adds to the test row.

Dependencies

None.

Source: #4517

Proposed design

Problem statement

The Valkey fake cannot answer Lua commands because lupa is absent. Every valkey-py lock and every limits moving window uses Lua. Tests of the move of Service state into Valkey fail. The project requires a contract suite for each fake. This change adds the lua extra and a contract suite for the Valkey fake.

Acceptance criteria

Requirement: Lua extra is installed

The test dependency declaration SHALL enable the lua extra of fakeredis[valkey]==2.40.0 so that lupa installs.

Scenario: The fake answers EVAL and EVALSHA

  • WHEN The test environment installs the dependencies from pyproject.toml.
  • THEN import lupa succeeds, and the Valkey fake answers EVAL and EVALSHA without unknown command.

Requirement: Contract suite runs both sides

The Valkey contract suite MUST run each case against the in-memory fake and against a real valkey-server binary when the binary is on PATH.

Scenario: The real binary is absent

  • WHEN valkey-server is not on PATH.
  • THEN The fake cases run and pass, and the real-server cases skip with a reason that names the missing binary.

Requirement: Contract cases cover Lua users

The contract suite MUST cover SET NX EX, EXAT, HINCRBY, ZADD trims, valkey-py Lock acquire, extend, owned(), release, and a limits moving-window hit.

Scenario: Each case matches on both sides

  • WHEN Each contract case runs against the fake and against the real binary.
  • THEN Both sides return the same result and leave the same stored state.

Requirement: Documentation marks the fake covered

docs/TESTING.md SHALL list the Valkey fake as covered by tests/valkey/test_valkey_contract.py and SHALL remove the statement that it has no contract suite.

Scenario: The testing guide names the suite

  • WHEN A reader opens the Valkey paragraph in docs/TESTING.md.
  • THEN The paragraph names the contract suite and no longer says has no contract suite yet.

Requirement: Pull request records the added time

The pull request body MUST state the measured seconds that the contract suite adds to the local test row.

Scenario: The author records the measurement

  • WHEN The pull request is opened.
  • THEN The body contains the measured added seconds and the command that measured them.

Existing Tool Considered

No alternatives check has run. fakeredis with the lua extra (lupa) covers EVAL and EVALSHA in the in-memory fake. The Valkey release binary covers the real server side. fakeredis lacks full parity with a real server. The suite therefore runs each case against both. If the project builds its own fake, the cost is about 80,000 tokens and 4 hours to build. It is about 5,000 tokens a month to keep and about 10,000 tokens to fix.

Key questions

  • How does the Valkey fake get Lua support?: Add the lua extra to the pinned fakeredis[valkey] dependency. This installs lupa with the test dependencies. Do not write a Lua shim. (best practice) [sources: pyproject.toml:113, docs/TESTING.md:242, tests/support/fakes/valkey.py]
    • Chosen: fakeredis lua extra. fakeredis documents the extra, and it installs the missing lupa at the pinned version.
    • Rejected: Build a Lua shim. It duplicates a maintained library and carries the 80,000-token build cost.
    • Rejected: Run a live Valkey in pytest. The test network block refuses a live service.
  • Where does the Valkey contract suite live?: Put it in tests/valkey/test_valkey_contract.py. The name follows the contract-suite convention and stays beside the Valkey tests. (best practice) [sources: docs/TESTING.md, tests/commands/test_valkey.py]
    • Chosen: tests/valkey/test_valkey_contract.py. It follows the naming of the other fake contract suites and stays beside the Valkey tests.
    • Rejected: tests/support/fakes/test_valkey_contract.py. The support checks keep test modules out of tests/support/.
  • How does the suite find the real Valkey server?: Use shutil.which("valkey-server") to find the binary. Start it on a loopback port for the real cases. Skip those cases with a named reason when the binary is absent. Do not add a new pin to tools.lock. (best practice) [sources: docs/TESTING.md:83, src/devops_cli/tools_lock/tools.lock]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-12: not-applicable.
Class: test, no search.
Tool: none found.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/test
    scope/valkey
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/valkey. The (valkey) scope of the title gives the scope.
    • Priority: P2-Medium. The project rule requires a contract suite before the fake merges, but this is not a blocking defect.
    • Value: Medium. It unblocks the Service state move into Valkey by making the fake trustworthy.
    • Effort: Medium. Adding a dependency, writing six-plus test cases, wiring a real-binary skip, and updating docs takes about four hours.
    • Related: refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317, which asks for a different change. Both concern the Valkey fake and contract suites, but #1317 refactors the seam architecture while the candidate adds a specific test suite for the fake.
  4. added
    priority/p2-medium
    on Nov 11, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 5f75d25 (see proposed design in issue body).

  7. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-12. A person decides what this means for the item. The check changes no label and closes no issue.

  8. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 19, 2026
  9. dan-petty commented on Nov 19, 2026

    @dan-petty
    OwnerAuthor

    Design correction: the suite replays a record, pytest starts no valkey-server

    The body tells pytest to start a real valkey-server from PATH and to skip the real cases when the binary is missing. That design breaks four rules of docs/TESTING.md:

    • Line 75: a test of src/ starts no system program.
    • Line 76: every other real tool goes to a contract suite that replays recorded transcripts, or to a row of devops ci.
    • Line 78: a test must not skip based on host state.
    • Line 87: every fake has a contract suite that runs against the fake and against the real implementation over recorded responses or a real local tool, never a live service.

    Also, the hermetic floor (lines 264 and 278) fails a connect to a loopback port that the test process did not bind. And valkey-server is not on PATH in the devcontainer or on a stock GitHub runner, so the first acceptance criterion cannot pass as written.

    Decided design. It follows the Docker engine contract suite (tests/docker/test_engine_contract.py, docs/TESTING.md line 284):

    1. tests/support/valkey_scenarios.py holds the shared scenarios: SET NX EX, SET EXAT, HINCRBY, ZADD with a trim, valkey-py Lock acquire, extend, owned() and release, and Lua through register_script (EVALSHA, with the NOSCRIPT fallback to EVAL).
    2. tests/support/valkey_recording.py records each request and reply through a proxy in front of a real valkey-server on loopback, outside pytest. It keeps the server version and the valkey-py version.
    3. tests/support/valkey_replay.py (RecordedValkey) replays the record on a socket that the test binds. A request that is not the next recorded one gets an error reply.
    4. tests/valkey/test_valkey_contract.py runs each scenario over the fake and over a real valkey-py client on RecordedValkey. Both sides must give the same result. A record of a different valkey-py version fails the suite. Nothing skips.
    5. The test pin becomes fakeredis[lua,valkey]==2.40.0, so lupa (MIT, maintained) installs and the fake answers EVAL and EVALSHA.

    The limits moving-window case stays out. limits is not a dependency of this repository today (no entry in uv.lock). #4563 adds limits, and it adds that case to this suite.

  10. added
    status/in-review
    and removed
    status/in-progress
    on Nov 19, 2026
  11. removed
    status/in-review
    owner/agent
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/valkeysource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions