Skip to content

Add deterministic coverage for clipboard extractItems - #1472

Merged
marcuscastelo merged 3 commits into
rc/v0.16.0from
copilot/add-unit-tests-extract-items
Mar 24, 2026
Merged

marcuscastelo merged 3 commits into
rc/v0.16.0from
copilot/add-unit-tests-extract-items

Conversation

Copilot AI commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

extractItems is responsible for normalizing clipboard payloads into items while regenerating item IDs. This adds focused domain-level coverage for the three supported payload shapes so regressions in extraction and ID regeneration are caught early.

  • Coverage added for all payload variants

    • single UnifiedItem payload
    • Meal payload with multiple items
    • Recipe payload with multiple items
  • ID regeneration behavior verified

    • asserts extracted items receive regenerated IDs instead of reusing source IDs
    • checks the current codebase ID generation shape (Math.round(Math.random() * 1000000)) with deterministic mocks
    • verifies extracted items preserve their non-ID content
  • Test structure

    • adds a dedicated clipboard domain test file alongside existing clipboard tests
    • uses small fixture helpers to keep payload setup readable across item, meal, and recipe cases
vi.spyOn(Math, 'random')
  .mockReturnValueOnce(0.111111)
  .mockReturnValueOnce(0.222222)

const extractedItems = ClipboardPayloadExt.extractItems(payload)

expect(extractedItems).toEqual([
  { ...items[0], id: 111111 },
  { ...items[1], id: 222222 },
])

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • test.supabase.co
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development /home/REDACTED/work/macroflows/macroflows/node_modules/.pnpm/tinypool@1.1.1/node_modules/tinypool/dist/entry/process.js tems (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development /home/REDACTED/work/macroflows/macroflows/node_modules/.pnpm/tinypool@1.1.1/node_modules/tinypool/dist/entry/process.js ame rgo/bin/git credential.usern/bin/sh (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --conditions node --conditions development /home/REDACTED/work/macroflows/macroflows/node_modules/.pnpm/tinypool@1.1.1/node_modules/tinypool/dist/entry/process.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>The extractItems method lacks test coverage. This is a critical function that extracts and regenerates IDs for items from different payload types. Add tests to verify:</issue_title>
<issue_description>reportedBy: github-copilot.v1/refine-github-issue

Task: Add unit tests for extractItems to cover all payload types

Title:
Add unit tests for extractItems covering single items, meal items, and recipe items; verify ID regeneration.

Description:
The extractItems method extracts items and regenerates IDs for items coming from different payload types (single item, meal items, recipe items). This function is critical and currently lacks test coverage. We need deterministic tests that validate behavior across payload shapes and ensure IDs are regenerated correctly (no collisions, correct new ID format expected by the codebase).

Motivation:
Unit tests will prevent regressions in the item extraction logic and ensure downstream code is working with correctly-regenerated IDs.

Acceptance Criteria:

  • Add tests for single-item extraction: the returned item has a newly generated ID and preserved content.
  • Add tests for meal items (multiple items): all extracted items receive new unique IDs; original items array structure is handled correctly.
  • Add tests for recipe items (multiple items): same verification as meal items.
  • Test(s) assert that regenerated IDs conform to the expected format/structure used by the codebase.
  • Tests added to the appropriate test file(s) and pass in CI.

Files / Scope:

  • Unit tests should be added alongside existing tests for related modules (e.g., src/modules/.../clipboard or the module where extractItems is implemented). Update/choose the test file path consistent with repository test organization.

Additional Context / Notes:

  • See original PR discussion: (reference: PR 1319 comments)
  • If helpful, include fixtures for the different payload types to keep tests readable and robust.
    </issue_description>

<agent_instructions>pnpm check always green</agent_instructions>

Comments on the Issue (you are @copilot in this section)


⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.

@vercel

vercel Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
macroflows Ready Ready Preview, Comment Mar 24, 2026 9:46pm

Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/marcuscastelo/macroflows/sessions/c8e8e26f-0883-4b65-9528-8780066ef999
Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
Agent-Logs-Url: https://github.com/marcuscastelo/macroflows/sessions/c8e8e26f-0883-4b65-9528-8780066ef999
Copilot AI changed the title [WIP] Add unit tests for extractItems to cover all payload types Add deterministic coverage for clipboard extractItems Mar 24, 2026
Copilot AI requested a review from marcuscastelo March 24, 2026 21:44
@marcuscastelo
marcuscastelo marked this pull request as ready for review March 24, 2026 21:47
Copilot AI review requested due to automatic review settings March 24, 2026 21:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds deterministic unit tests for ClipboardPayloadExt.extractItems, which normalizes different clipboard payload shapes into a flat Item[] while regenerating IDs. This improves domain-level regression protection around clipboard extraction behavior.

Changes:

  • Added focused extractItems tests for all supported payload variants (single Item, Meal, Recipe).
  • Verified regenerated IDs are produced (vs reusing source IDs) using deterministic Math.random mocks.
  • Asserted extracted items preserve non-ID content and do not mutate source payload content.

@marcuscastelo
marcuscastelo merged commit 98d06c6 into rc/v0.16.0 Mar 24, 2026
11 checks passed
@marcuscastelo
marcuscastelo deleted the copilot/add-unit-tests-extract-items branch March 24, 2026 23:02

This branch was successfully deployed

1 active deployment
Preview — de8c6976 Deployed Mar 24, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants