Skip to content

⚡ Bolt: Optimize listing audit engine findings lookup#60

Closed
projectamazonph wants to merge 1 commit into
mainfrom
bolt-optimize-listing-audit-lookups-14346817668686831647
Closed

⚡ Bolt: Optimize listing audit engine findings lookup#60
projectamazonph wants to merge 1 commit into
mainfrom
bolt-optimize-listing-audit-lookups-14346817668686831647

Conversation

@projectamazonph

@projectamazonph projectamazonph commented Jul 19, 2026

Copy link
Copy Markdown
Owner

This PR optimizes the listing audit scoring engine's comparison logic.

💡 What: Changed the nested lookup pattern from O(NM) linear search (array.find()) to O(N + M) using Map-based indexing.
🎯 Why: In interactive scenarios, comparing student findings with scenario reference findings iteratively via inner linear lookups is highly inefficient. Mapping the reference items by field key once allows O(1) constant-time lookup.
📊 Impact: Eliminates redundant loops, reducing complexity from O(N
M) to O(N + M) and making the grading logic extremely fast.
🔬 Measurement: Verified with a newly implemented unit test suite src/engine/listing-audit/engine.test.ts showing all 3 tests passing.


PR created automatically by Jules for task 14346817668686831647 started by @projectamazonph

Summary by CodeRabbit

  • Bug Fixes

    • Improved listing-audit finding matching for more consistent accuracy and severity scoring.
  • Tests

    • Added coverage for successful and unsuccessful listing audits.
    • Added validation for automatically generated findings, including titles and bullet points.

- Convert reference findings array to Map in findingsAccuracy and severityCalibration to avoid O(N*M) nested scans.
- Implemented comprehensive engine.test.ts suite for listing audit grading.

Co-authored-by: projectamazonph <286085559+projectamazonph@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The listing-audit engine now indexes reference findings by field for accuracy and severity checks. New Vitest tests cover successful and failed grading scenarios and verify generated findings include title and bullets.

Changes

Listing audit engine

Layer / File(s) Summary
Reference finding indexing
src/engine/listing-audit/engine.ts
findingsAccuracy and severityCalibration use field-keyed maps instead of repeated find lookups.
Listing audit test coverage
src/engine/listing-audit/engine.test.ts
Adds tests for matching and missing-input grading results and generated title and bullet findings.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: optimizing listing audit engine findings lookup with a more efficient indexing approach.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-optimize-listing-audit-lookups-14346817668686831647

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/engine/listing-audit/engine.test.ts`:
- Around line 28-35: Replace all em dashes in the affected test fixture strings,
including the product title and bullets around the referenced sections, with
commas or parentheses while preserving the fixture’s meaning and assertions.

In `@src/engine/listing-audit/engine.ts`:
- Around line 86-91: Update the reference-finding indexes in the main audit
matching logic and severityCalibration so duplicate ListingAuditFinding entries
for the same field are preserved, matching the previous ref.find behavior by
retaining the first finding or indexing fields as arrays. Add a regression case
in engine.test.ts covering duplicate reviews findings produced by
generateAutoFindings and verifying accuracy and severity results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e93c545f-c232-419e-9c5f-a48f41f6cc06

📥 Commits

Reviewing files that changed from the base of the PR and between 78f1931 and f61cb6e.

📒 Files selected for processing (2)
  • src/engine/listing-audit/engine.test.ts
  • src/engine/listing-audit/engine.ts

Comment on lines +28 to +35
title: 'Bamboo Cutting Board with Deep Juice Groove — Eco-Friendly Kitchen Chopping Board for Vegetables, Meat, Cheese | Large 16x12 inch with Non-Slip Feet | Durable, Dishwasher Safe',
bullets: [
'DEEP JUICE GROOVE — Catches liquids from meat, fruit, and vegetables. No more countertop spills.',
'ECO-FRIENDLY BAMBOO — Sustainably sourced, naturally antibacterial. Lasts longer than plastic.',
'LARGE 16x12 INCH — Fits a whole meal prep. Reversible design doubles your workspace.',
'NON-SLIP FEET — Stays put on the counter. No more chasing the board while chopping.',
'DISHWASHER SAFE — Easy cleanup. Oil monthly with food-grade mineral oil for best results.',
],

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace em dashes in the test fixtures.

These new title and bullet strings contain em dashes. Replace them with commas or parentheses.

As per coding guidelines: “Do not use emojis in code or commit messages, and do not use em-dashes. Use periods, commas, or parentheses instead.”

Also applies to: 63-70

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/engine/listing-audit/engine.test.ts` around lines 28 - 35, Replace all em
dashes in the affected test fixture strings, including the product title and
bullets around the referenced sections, with commas or parentheses while
preserving the fixture’s meaning and assertions.

Source: Coding guidelines

Comment on lines +86 to +91
// Bolt optimization: Map reference findings by field to replace O(N*M) nested lookups with O(1) lookups
const refMap = new Map(ref.map((f) => [f.field, f]));

let truePositives = 0;
for (const sf of student) {
const match = ref.find((rf) => rf.field === sf.field);
const match = refMap.get(sf.field);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve duplicate reference findings when indexing.

ListingAuditFinding.field is not unique, and generateAutoFindings can produce two reviews findings when both review count and rating are below their thresholds. new Map(ref.map(...)) keeps only the last entry, changing the previous ref.find(...) behavior and potentially producing incorrect accuracy and severity scores.

Retain the first finding per field or index each field to an array, and add a regression case in src/engine/listing-audit/engine.test.ts.

Proposed fix
-  const refMap = new Map(ref.map((f) => [f.field, f]));
+  const refMap = new Map<ListingAuditFinding['field'], ListingAuditFinding>();
+  for (const finding of ref) {
+    if (!refMap.has(finding.field)) {
+      refMap.set(finding.field, finding);
+    }
+  }

Apply the same indexing logic in severityCalibration.

Also applies to: 110-116

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/engine/listing-audit/engine.ts` around lines 86 - 91, Update the
reference-finding indexes in the main audit matching logic and
severityCalibration so duplicate ListingAuditFinding entries for the same field
are preserved, matching the previous ref.find behavior by retaining the first
finding or indexing fields as arrays. Add a regression case in engine.test.ts
covering duplicate reviews findings produced by generateAutoFindings and
verifying accuracy and severity results.

@projectamazonph

Copy link
Copy Markdown
Owner Author

Closing as duplicate of #43 — same optimization (Array.find → Map in listing-audit's engine.ts), but #43 builds the map once at the call site and passes it down instead of rebuilding it separately in each function. Keeping #43 as the more complete version. See #48.

@google-labs-jules

Copy link
Copy Markdown
Contributor

Closing as duplicate of #43 — same optimization (Array.find → Map in listing-audit's engine.ts), but #43 builds the map once at the call site and passes it down instead of rebuilding it separately in each function. Keeping #43 as the more complete version. See #48.

Understood. Acknowledging that this work is duplicate/obsolete in favor of #43, and stopping work on this task.

projectamazonph added a commit that referenced this pull request Jul 20, 2026
…T-01) (#43)

Squash-merged via audit follow-up. Chosen over duplicates #37/#60 (see #48).
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.

1 participant