Skip to content

fix(super-filtro): auditoria exaustiva — 12 bugs corrigidos + BUG-14 base64#471

Merged
adm01-debug merged 7 commits into
mainfrom
fix/super-filtro-bug-audit-2026-05-26
May 26, 2026
Merged

fix(super-filtro): auditoria exaustiva — 12 bugs corrigidos + BUG-14 base64#471
adm01-debug merged 7 commits into
mainfrom
fix/super-filtro-bug-audit-2026-05-26

Conversation

@adm01-debug
Copy link
Copy Markdown
Owner

@adm01-debug adm01-debug commented May 26, 2026

Auditoria Exaustiva — Super Filtro

Varredura minuciosa de 20 tarefas nos 6 arquivos do modulo Super Filtro (/filtros).
12 bugs corrigidos + 1 bug emergencial (BUG-14 base64 corrompido).


Resumo dos Bugs

Bug Severidade Descricao
BUG-01 CRITICO Double-filter: fuzzy + substring matava resultados validos
BUG-02 CRITICO clearSingleFilter("priceRange") setava [] causando crash downstream
BUG-14 CRITICO product-sorting.ts commitado como base64 (ilegivel/nao-compilavel)
BUG-03 ALTO inStock ignorava variacoes — produtos em estoque excluidos
BUG-04 ALTO parseInt truncava precos decimais da URL (15.99 virava 15)
BUG-05 ALTO activeFiltersSummary faltava 11 tipos: chips invisiveis no header
BUG-06 MEDIO Voice agent: sort "popularity" nao tinha case em sortProducts
BUG-07 MEDIO FilterPanel: SORT_OPTIONS importado de @/hooks/products (fonte errada)
BUG-13 MEDIO product-sorting.ts sem case "popularity" (mesmo que BUG-06)
BUG-11 BAIXO defaultAdvancedFilters.priceRange [0,1000] inconsistente com [0,9999]
BUG-12 BAIXO Dead code: appliedFilters declarado mas nunca consumido

Arquivos Alterados

  • src/utils/product-sorting.ts — BUG-06, BUG-13, BUG-14
  • src/constants/filters.ts — BUG-11
  • src/components/filters/FilterPanel.tsx — BUG-07
  • src/pages/filters/useFiltersPageState.ts — BUG-01, BUG-02, BUG-03, BUG-04, BUG-05, BUG-12
  • docs/SUPER_FILTRO_BUG_AUDIT_2026-05-26.md — documentacao completa

KPIs Antes x Depois

Metrica Antes Depois
Bugs criticos 3 0
Chips de filtro visiveis 11/22 22/22
Busca fuzzy para termos parciais FALHA OK
clearSingleFilter seguro CRASH OK
inStock considera variacoes NAO SIM
Precos decimais preservados na URL NAO SIM
product-sorting.ts legivel base64 TypeScript

Checklist de Review

  • Verificar comportamento fuzzy search com query parcial (ex: "sqz" deve trazer "Squeeze")
  • Testar clearSingleFilter("priceRange") — deve voltar para [0, 9999]
  • Confirmar chips de filtro no header para: tecnicas, tags, preco, estoque, etc.
  • Confirmar comando de voz "ordenar por popularidade" aplica a ordenacao correta
  • Build CI verde (detect-base64-content.yml nao deve disparar)

Documentacao completa: docs/SUPER_FILTRO_BUG_AUDIT_2026-05-26.md


Summary by cubic

Fixed 12 Super Filtro bugs and recovered a corrupted sorting file, making search, filters, and sorting reliable again.

  • Bug Fixes
    • Search: removed fuzzy+substring double filtering; preserved decimal prices from URL with parseFloat.
    • Filters: clearSingleFilter('priceRange') resets to [0, 9999] with type‑safe resets for search/numbers; inStock checks variations; header chips include 11 missing types; default advanced priceRange aligned to [0, 9999]; removed unused appliedFilters state.
    • Sorting & UI: restored src/utils/product-sorting.ts from base64; added "popularity" alias to best-seller-promo; FilterPanel now imports SORT_OPTIONS from @/constants/filters.

Written for commit 9c69470. Summary will update on new commits. Review in cubic

… BUG-06+13 keep popularity alias

BUG-14 (🔴 CRÍTICO): previous commit stored base64 text as file content
instead of actual TypeScript. Re-commit with proper source.

BUG-06+13 (🟡 MÉDIO): alias case 'popularity' → falls through to
best-seller-promo so voice agent sort command works end-to-end.
…[0,9999]

BUG-11 (🟢 BAIXO): defaultAdvancedFilters used [0,1000] while the main
defaultFilters and all filter logic used 9999 as the "no upper limit"
sentinel. Inconsistency could cause unexpected filtering when
AdvancedFilterState is applied to the Super Filtro pipeline.
BUG-07 (🟡 MÉDIO): FilterPanel imported SORT_OPTIONS from "@/hooks/products"
which could expose a different (stale/partial) list than the header's
Select dropdown.  Single source of truth: @/constants/filters — same
module consumed by FiltersPage.tsx.
BUG-01 (🔴 CRÍTICO): fuzzy search double-filter — substring filter now
guarded by !hasFuzzySearch. Queries like "sqz" matching "Squeeze" via
fuzzy were being dropped by the subsequent exact .includes() pass.

BUG-02 (🔴 CRÍTICO): clearSingleFilter('priceRange') set [] instead of
[0,9999]. Added explicit branch before the generic Array.isArray fallback.
Also added explicit branch for 'search' (string, not boolean/array).
Added number fallback (→ 0) for minStock.

BUG-03 (🟠 ALTO): inStock filter only checked product.stock aggregate;
products with stock=0 but variations in stock were incorrectly excluded.
Now mirrors minStock logic: checks variations first.

BUG-04 (🟠 ALTO): parseInt truncated decimal prices from URL params
(e.g. "15.99" → 15). Changed to parseFloat for priceRange parsing.
minStock stays parseInt since stock is always an integer.

BUG-05 (🟠 ALTO): activeFiltersSummary missing 11 filter types. Chips in
the header bar were invisible for: techniques, tags, priceRange, minStock,
inStock, isKit, featured, isNew, hasPersonalization,
hasCommercialPackaging, search.

BUG-12 (🟢 BAIXO): appliedFilters/setAppliedFilters removed — state was
declared, exported, but never read by any consumer, causing unnecessary
re-renders on every filter change.
Copilot AI review requested due to automatic review settings May 26, 2026 17:05
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

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

Project Deployment Actions Updated (UTC)
we-dream-big Ready Ready Preview, Comment May 26, 2026 5:06pm

@supabase
Copy link
Copy Markdown

supabase Bot commented May 26, 2026

This pull request has been ignored for the connected project doufsxqlfjyuvxuezpln because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@adm01-debug, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 39 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd27fe6f-bc52-4fbd-9481-6351efdfb723

📥 Commits

Reviewing files that changed from the base of the PR and between e58395a and 9c69470.

📒 Files selected for processing (5)
  • docs/SUPER_FILTRO_BUG_AUDIT_2026-05-26.md
  • src/components/filters/FilterPanel.tsx
  • src/constants/filters.ts
  • src/pages/filters/useFiltersPageState.ts
  • src/utils/product-sorting.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/super-filtro-bug-audit-2026-05-26

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs an “exhaustive audit” of the Super Filtro module (/filtros) and applies a set of fixes aimed at correcting filtering/sorting behavior, preventing state corruption when clearing filters, and restoring consistency across UI filter chips and sort options.

Changes:

  • Fixes filtering logic issues (URL price parsing with decimals, inStock considering variations, avoiding fuzzy + substring double-filtering, safer single-filter clearing).
  • Fixes sorting issues (restores readable product-sorting.ts, adds popularity alias handling, and unifies SORT_OPTIONS source).
  • Adds documentation of the audit and fixes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/utils/product-sorting.ts Adds popularity alias handling for sorting (voice agent compatibility) and restores readable TS content.
src/pages/filters/useFiltersPageState.ts Fixes several filter behaviors: URL parsing for price decimals, fuzzy/substr interaction, in-stock filtering for variations, active filter chips, and clearSingleFilter sentinels.
src/constants/filters.ts Aligns advanced default priceRange sentinel to [0, 9999] for consistency with filtering logic.
src/components/filters/FilterPanel.tsx Switches SORT_OPTIONS import to @/constants/filters to keep a single source of truth.
docs/SUPER_FILTRO_BUG_AUDIT_2026-05-26.md Adds a detailed audit write-up and bug fix record.
Comments suppressed due to low confidence (1)

src/utils/product-sorting.ts:76

  • Foi adicionado suporte a sortBy="popularity" (alias de best-seller-promo), mas os testes existentes de sortProducts (Vitest) parecem cobrir apenas as opções expostas em SORT_OPTIONS. Para evitar regressão futura (ex: alguém alterar best-seller-promo e esquecer o alias), vale adicionar um teste unitário específico garantindo que popularity ordena igual ao modo esperado.
    // FIX-06+13: "popularity" era mapeado no voice agent mas nao tinha case aqui.
    // Adicionado alias para best-seller-promo (semanticamente equivalente).
    case "best-seller-promo":
    case "popularity":
      products.sort((a, b) => {
        const map = options?.promoSalesMap;
        const aCount = map?.get(a.id) || 0;
        const bCount = map?.get(b.id) || 0;
        if (bCount !== aCount) return bCount - aCount;
        return a.name.localeCompare(b.name);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 71 to +76
const pMin = get('priceMin');
const pMax = get('priceMax');
if (pMin || pMax) f.priceRange = [pMin ? parseInt(pMin) : 0, pMax ? parseInt(pMax) : 9999];
// FIX-04: usar parseFloat para preservar centavos (ex: "15.99" → 15.99, não 15)
if (pMin || pMax) f.priceRange = [pMin ? parseFloat(pMin) : 0, pMax ? parseFloat(pMax) : 9999];
const ms = get('minStock');
if (ms) f.minStock = parseInt(ms);
if (ms) f.minStock = parseInt(ms); // minStock é sempre inteiro — parseInt ok
Comment on lines +292 to 296
// FIX-01: filtro de busca substring só aplica quando NÃO há fuzzy search ativo.
// Antes, o substring filter rodava SEMPRE, eliminando resultados fuzzy corretos
// (ex: "sqz" encontrava "Squeeze" via fuzzy, mas .includes("sqz") === false matava o item).
if (filters.search && !hasFuzzySearch) {
const s = filters.search.toLowerCase();
Comment on lines +604 to +612
// FIX-02: priceRange precisa de valor sentinela [0,9999], não [] (que causaria crash downstream).
else if (key === 'priceRange')
setFilters({ ...filters, priceRange: [0, 9999] });
// FIX-02 (cont): search é string, não boolean nem array.
else if (key === 'search')
setFilters({ ...filters, search: '' });
else if (Array.isArray(filters[key])) setFilters({ ...filters, [key]: [] });
else if (typeof filters[key] === 'boolean') setFilters({ ...filters, [key]: false });
else if (typeof filters[key] === 'number') setFilters({ ...filters, [key]: 0 });
@adm01-debug adm01-debug merged commit af3bb9e into main May 26, 2026
44 of 49 checks passed
@adm01-debug adm01-debug deleted the fix/super-filtro-bug-audit-2026-05-26 branch May 26, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants