Skip to content

Production #743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 252 commits into
base: main
Choose a base branch
from
Open

Production #743

wants to merge 252 commits into from

Conversation

philipbrembeck
Copy link
Contributor

@philipbrembeck philipbrembeck commented Mar 27, 2025

Summary by Sourcery

Refactor and improve the ingredients classification process with enhanced error handling, worker-based processing, and dependency updates

New Features:

  • Added a worker-based approach for ingredient classification to improve performance
  • Implemented fallback mechanism for translation failures
  • Added concurrency scripts for development workflows

Enhancements:

  • Improved error handling in translation process
  • Moved sophisticated ingredient matching to a separate worker thread
  • Updated project dependencies to latest versions
  • Simplified translation error management

CI:

  • Added concurrently script for running multiple development checks
  • Improved lint and test script integration

Tests:

  • Updated unit tests to reflect new error handling behavior
  • Added more robust test scenarios for translation failures

Chores:

  • Updated package.json scripts
  • Upgraded NestJS and related dependencies
  • Cleaned up OpenAPI specification
  • Updated Dockerfile to use corepack

dependabot bot and others added 30 commits November 18, 2024 04:01
Bumps [eslint](https://github.com/eslint/eslint) from 9.14.0 to 9.15.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v9.14.0...v9.15.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-9.15.0

build(deps-dev): Bump eslint from 9.14.0 to 9.15.0
Bumps [cross-spawn](https://github.com/moxystudio/node-cross-spawn) from 7.0.3 to 7.0.5.
- [Changelog](https://github.com/moxystudio/node-cross-spawn/blob/master/CHANGELOG.md)
- [Commits](moxystudio/node-cross-spawn@v7.0.3...v7.0.5)

---
updated-dependencies:
- dependency-name: cross-spawn
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…cross-spawn-7.0.5

build(deps): Bump cross-spawn from 7.0.3 to 7.0.5
Bumps [@nestjs/swagger](https://github.com/nestjs/swagger) from 8.0.5 to 8.0.7.
- [Release notes](https://github.com/nestjs/swagger/releases)
- [Changelog](https://github.com/nestjs/swagger/blob/master/.release-it.json)
- [Commits](nestjs/swagger@8.0.5...8.0.7)

---
updated-dependencies:
- dependency-name: "@nestjs/swagger"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/swagger-8.0.7

build(deps): Bump @nestjs/swagger from 8.0.5 to 8.0.7
Bumps [@nestjs/testing](https://github.com/nestjs/nest/tree/HEAD/packages/testing) from 10.4.7 to 10.4.8.
- [Release notes](https://github.com/nestjs/nest/releases)
- [Commits](https://github.com/nestjs/nest/commits/v10.4.8/packages/testing)

---
updated-dependencies:
- dependency-name: "@nestjs/testing"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/testing-10.4.8

build(deps-dev): Bump @nestjs/testing from 10.4.7 to 10.4.8
Bumps [@nestjs/platform-express](https://github.com/nestjs/nest/tree/HEAD/packages/platform-express) from 10.4.7 to 10.4.8.
- [Release notes](https://github.com/nestjs/nest/releases)
- [Commits](https://github.com/nestjs/nest/commits/v10.4.8/packages/platform-express)

---
updated-dependencies:
- dependency-name: "@nestjs/platform-express"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/platform-express-10.4.8

build(deps): Bump @nestjs/platform-express from 10.4.7 to 10.4.8
Bumps [@nestjs/core](https://github.com/nestjs/nest/tree/HEAD/packages/core) from 10.4.7 to 10.4.8.
- [Release notes](https://github.com/nestjs/nest/releases)
- [Commits](https://github.com/nestjs/nest/commits/v10.4.8/packages/core)

---
updated-dependencies:
- dependency-name: "@nestjs/core"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/core-10.4.8

build(deps): Bump @nestjs/core from 10.4.7 to 10.4.8
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 8.14.0 to 8.15.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.15.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/parser-8.15.0

build(deps-dev): Bump @typescript-eslint/parser from 8.14.0 to 8.15.0
Bumps [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) from 17.13.1 to 17.13.2.
- [Release notes](https://github.com/eslint-community/eslint-plugin-n/releases)
- [Changelog](https://github.com/eslint-community/eslint-plugin-n/blob/master/CHANGELOG.md)
- [Commits](eslint-community/eslint-plugin-n@v17.13.1...v17.13.2)

---
updated-dependencies:
- dependency-name: eslint-plugin-n
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-plugin-n-17.13.2

build(deps-dev): Bump eslint-plugin-n from 17.13.1 to 17.13.2
Bumps [@nestjs/cli](https://github.com/nestjs/nest-cli) from 10.4.7 to 10.4.8.
- [Release notes](https://github.com/nestjs/nest-cli/releases)
- [Changelog](https://github.com/nestjs/nest-cli/blob/master/.release-it.json)
- [Commits](nestjs/nest-cli@10.4.7...10.4.8)

---
updated-dependencies:
- dependency-name: "@nestjs/cli"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/cli-10.4.8

build(deps-dev): Bump @nestjs/cli from 10.4.7 to 10.4.8
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 8.14.0 to 8.15.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.15.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/eslint-plugin-8.15.0

build(deps-dev): Bump @typescript-eslint/eslint-plugin from 8.14.0 to 8.15.0
Bumps [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) from 17.13.2 to 17.14.0.
- [Release notes](https://github.com/eslint-community/eslint-plugin-n/releases)
- [Changelog](https://github.com/eslint-community/eslint-plugin-n/blob/master/CHANGELOG.md)
- [Commits](eslint-community/eslint-plugin-n@v17.13.2...v17.14.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-n
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-plugin-n-17.14.0

build(deps-dev): Bump eslint-plugin-n from 17.13.2 to 17.14.0
Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.6.3 to 5.7.2.
- [Release notes](https://github.com/microsoft/TypeScript/releases)
- [Changelog](https://github.com/microsoft/TypeScript/blob/main/azure-pipelines.release.yml)
- [Commits](microsoft/TypeScript@v5.6.3...v5.7.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-5.7.2

build(deps-dev): Bump typescript from 5.6.3 to 5.7.2
Bumps [axios](https://github.com/axios/axios) from 1.7.7 to 1.7.8.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v1.7.7...v1.7.8)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…axios-1.7.8

build(deps): Bump axios from 1.7.7 to 1.7.8
Bumps [eslint-plugin-promise](https://github.com/eslint-community/eslint-plugin-promise) from 7.1.0 to 7.2.1.
- [Release notes](https://github.com/eslint-community/eslint-plugin-promise/releases)
- [Changelog](https://github.com/eslint-community/eslint-plugin-promise/blob/main/CHANGELOG.md)
- [Commits](eslint-community/eslint-plugin-promise@v7.1.0...v7.2.1)

---
updated-dependencies:
- dependency-name: eslint-plugin-promise
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-plugin-promise-7.2.1

build(deps-dev): Bump eslint-plugin-promise from 7.1.0 to 7.2.1
Bumps [@nestjs/common](https://github.com/nestjs/nest/tree/HEAD/packages/common) from 10.4.8 to 10.4.9.
- [Release notes](https://github.com/nestjs/nest/releases)
- [Commits](https://github.com/nestjs/nest/commits/v10.4.9/packages/common)

---
updated-dependencies:
- dependency-name: "@nestjs/common"
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs/common-10.4.9

build(deps): Bump @nestjs/common from 10.4.8 to 10.4.9
kodiakhq bot and others added 12 commits March 13, 2025 03:55
…eslint-import-resolver-typescript-3.8.6

build(deps-dev): Bump eslint-import-resolver-typescript from 3.8.5 to 3.8.6
Bumps [eslint-import-resolver-typescript](https://github.com/import-js/eslint-import-resolver-typescript) from 3.8.6 to 3.8.7.
- [Release notes](https://github.com/import-js/eslint-import-resolver-typescript/releases)
- [Changelog](https://github.com/import-js/eslint-import-resolver-typescript/blob/master/CHANGELOG.md)
- [Commits](import-js/eslint-import-resolver-typescript@v3.8.6...v3.8.7)

---
updated-dependencies:
- dependency-name: eslint-import-resolver-typescript
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-import-resolver-typescript-3.8.7

build(deps-dev): Bump eslint-import-resolver-typescript from 3.8.6 to 3.8.7
Bumps [@types/express](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/express) from 5.0.0 to 5.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/express)

---
updated-dependencies:
- dependency-name: "@types/express"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
…types/express-5.0.1

build(deps-dev): Bump @types/express from 5.0.0 to 5.0.1
Bumps [nestjs-pino](https://github.com/iamolegga/nestjs-pino) from 4.3.1 to 4.4.0.
- [Release notes](https://github.com/iamolegga/nestjs-pino/releases)
- [Commits](iamolegga/nestjs-pino@4.3.1...4.4.0)

---
updated-dependencies:
- dependency-name: nestjs-pino
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…nestjs-pino-4.4.0

build(deps): Bump nestjs-pino from 4.3.1 to 4.4.0
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 8.26.1 to 8.27.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.27.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/eslint-plugin-8.27.0

build(deps-dev): Bump @typescript-eslint/eslint-plugin from 8.26.1 to 8.27.0
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 8.26.1 to 8.28.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.28.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/parser-8.28.0

build(deps-dev): Bump @typescript-eslint/parser from 8.26.1 to 8.28.0
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

sourcery-ai bot commented Mar 27, 2025

Reviewer's Guide by Sourcery

This pull request updates dependencies, implements multi-threading for ingredient processing, improves error handling, and updates the Dockerfile to use bun.

Sequence diagram for ingredient processing with worker thread

sequenceDiagram
  participant Controller
  participant WorkerThread

  Controller->>Controller: Receives ingredients
  Controller->>WorkerThread: Sends ingredients for processing
  activate WorkerThread
  WorkerThread->>WorkerThread: Categorizes ingredients (vegan, not vegan, etc.)
  WorkerThread-->>Controller: Returns categorized ingredients
  deactivate WorkerThread
  Controller->>Controller: Sends response
Loading

File-Level Changes

Change Details Files
Updated dependencies in pnpm-lock.yaml to their latest versions.
  • Updated @nestjs/axios from 3.1.2 to 3.1.3
  • Updated @nestjs/common from 10.4.7 to 10.4.15
  • Updated @nestjs/config from 3.3.0 to 3.3.0
  • Updated @nestjs/core from 10.4.7 to 10.4.15
  • Updated @nestjs/platform-express from 10.4.7 to 10.4.15
  • Updated @nestjs/swagger from 8.0.5 to 8.1.1
  • Updated @nestjs/terminus from 10.2.3 to 11.0.0
  • Updated axios from 1.7.7 to 1.8.3
  • Updated dotenv from 16.4.5 to 16.4.7
  • Updated express from 4.21.1 to 4.21.2
  • Updated express-rate-limit from 7.4.1 to 7.5.0
  • Updated nestjs-pino from 4.1.0 to 4.4.0
  • Updated @nestjs/cli from 10.4.7 to 11.0.5
  • Updated @nestjs/schematics from 10.2.3 to 11.0.2
  • Updated @nestjs/testing from 10.4.7 to 10.4.15
  • Updated @types/express from 5.0.0 to 5.0.1
  • Updated @typescript-eslint/eslint-plugin from 8.14.0 to 8.27.0
  • Updated @typescript-eslint/parser from 8.14.0 to 8.28.0
  • Updated eslint from 9.14.0 to 9.22.0
pnpm-lock.yaml
Implemented multi-threading to improve ingredient processing performance.
  • Added a new worker file ingredient.worker.ts to handle ingredient categorization in a separate thread.
  • Utilized the worker_threads module to spawn a worker for processing ingredients.
  • Modified the getIngredients method in IngredientsV1Controller to use the worker for categorizing ingredients.
  • Removed the sophisticatedMatch method from IngredientsV1Controller as it is now part of the worker thread.
  • Added logic to handle worker errors and exit codes.
  • Updated the controller to handle translation failures more gracefully, proceeding with untranslated ingredients and logging a warning.
src/ingredients/v1/ingredients.controller.ts
src/ingredients/v1/ingredient.worker.ts
Improved error handling and logging for translation and back-translation failures.
  • Replaced the Service Unavailable error response with a warning log and continued processing with untranslated ingredients.
  • Added a warning log for back-translation failures and continued processing with untranslated results.
  • Removed the 503 status code from the OpenAPI documentation.
src/ingredients/v1/ingredients.controller.ts
OpenAPI.yaml
Updated the Dockerfile to use bun and enable corepack.
  • Added RUN npm i -g corepack@latest to install corepack.
  • Added RUN corepack enable to enable corepack.
  • Changed start:prod script to use bun dist/main.js.
Dockerfile

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +168 to 177
const translatedNotVegan = backTranslated.slice(
0,
notVeganResult.length
);
const translatedMaybeNotVegan = backTranslated.slice(
notVeganResult.length,
notVeganResult.length + maybeNotVeganResult.length
);
veganResult = backTranslated.slice(
const translatedVegan = backTranslated.slice(
notVeganResult.length + maybeNotVeganResult.length,
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider refactoring translation slicing logic.

Extracting the slicing logic into a helper or clearly documenting the boundaries might reduce the risk of off-by-one errors and improve maintainability.

Suggested implementation:

private slicePart(text: string, start: number, length?: number): string {
  return length !== undefined ? text.slice(start, start + length) : text.slice(start);
}

// (existing class code)
          const translatedNotVegan = this.slicePart(backTranslated, 0, notVeganResult.length);
          const translatedMaybeNotVegan = this.slicePart(backTranslated, notVeganResult.length, maybeNotVeganResult.length);
          const translatedVegan = this.slicePart(backTranslated, notVeganResult.length + maybeNotVeganResult.length, veganResult.length);
          const translatedUnknown = this.slicePart(backTranslated, notVeganResult.length + maybeNotVeganResult.length + veganResult.length);

@@ -24,6 +24,7 @@ paths:
description: Internal Server Error.
tags:
- Grades
Copy link

Choose a reason for hiding this comment

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

suggestion: Avoid duplicate tags in the OpenAPI definitions.

Duplicate tag entries (e.g. for Grades, Product, and Ingredients) may lead to redundant sections in generated documentation. Consider deduplicating the tag entries to simplify maintenance.

Suggested implementation:

      tags:
        - Grades

      tags:
        - Product

const res = mockResponse();
translationService.translateText.mockRejectedValueOnce(
new Error("Translate timed out")
);

await controller.getIngredients("ingredient", res, true);
await controller.getIngredients("tofu,milk,sugar", res, true);
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Add tests for the worker thread logic

Since the ingredient categorization logic has been moved to a worker thread, it's crucial to have tests that specifically target this new implementation. Consider adding tests that cover various scenarios, including edge cases and error handling within the worker itself.

Suggested implementation:

describe("Worker thread logic", () => {
  it("should process ingredients via the worker thread and return success", async () => {
    const res = mockResponse();
    // Simulate a successful worker processing result.
    // If additional mocking is needed for the worker thread communication, add those here.
    await controller.getIngredients("tofu,milk,sugar", res, true);

    expect(res.status).toHaveBeenCalledWith(HttpStatus.OK);
    expect(res.send).toHaveBeenCalledWith(
      expect.objectContaining({
        code: "OK",
        status: "200",
        message: "Success",
        data: expect.any(Object)
      })
    );
  });

  it("should handle errors in worker thread and return service unavailable", async () => {
    const res = mockResponse();
    // Simulate an error scenario in the worker thread logic.
    // You may want to configure mock responses for worker thread errors here.
    await controller.getIngredients("faulty,ingredients", res, true);

    expect(res.status).toHaveBeenCalledWith(HttpStatus.SERVICE_UNAVAILABLE);
    expect(res.send).toHaveBeenCalledWith(
      expect.objectContaining({
        code: expect.any(String),
        message: expect.stringContaining("error")
      })
    );
  });
});

If your worker thread logic requires additional mocking (for example, using a specific worker pool or inter-thread communication library), make sure to import and configure these mocks appropriately at the top of the test file.

maybeNotVeganResult,
veganResult,
unknownResult,
} = await this.runWorker(response);
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider replacing the worker thread with an in-process categorization utility to reduce complexity, as the matching logic is not computationally intensive enough to warrant a separate thread and doing so simplifies the code flow while maintaining functionality .

Consider if the added asynchronicity truly brings a measurable benefit. Since the matching logic isn’t very heavy, you can reduce complexity by replacing the worker thread with a simple, in‑process categorization utility. For example:

```ts
private categorizeIngredients(ingredients: string[]): {
  notVeganResult: string[];
  maybeNotVeganResult: string[];
  veganResult: string[];
  unknownResult: string[];
} {
  return {
    notVeganResult: ingredients.filter((item) => this.sophisticatedMatch(item, this.isNotVegan)),
    maybeNotVeganResult: ingredients.filter(
      (item) =>
        !this.sophisticatedMatch(item, this.isNotVegan) &&
        this.sophisticatedMatch(item, this.isMaybeNotVegan)
    ),
    veganResult: ingredients.filter((item) => this.sophisticatedMatch(item, this.isVegan)),
    unknownResult: ingredients.filter(
      (item) =>
        !this.sophisticatedMatch(item, this.isNotVegan) &&
        !this.sophisticatedMatch(item, this.isMaybeNotVegan) &&
        !this.sophisticatedMatch(item, this.isVegan)
    ),
  };
}

Then in your controller, replace the worker invocation:

// Replace this:
// const { notVeganResult, maybeNotVeganResult, veganResult, unknownResult } = await this.runWorker(response);

// With:
const { notVeganResult, maybeNotVeganResult, veganResult, unknownResult } = this.categorizeIngredients(response);

This maintains all functionality while simplifying the flow and reducing complexity.

function sophisticatedMatch(ingredient: string, list: string[]): boolean {
const normalizedIngredient = ingredient.toLowerCase().replace(/\s+/g, "");

if (list.includes(normalizedIngredient)) return true;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (list.includes(normalizedIngredient)) return true;
if (list.includes(normalizedIngredient)) {


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

Comment on lines +9 to +10
if (list.some((item) => wordBoundaryRegex.test(item.replace(/\s+/g, ""))))
return true;
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Use block braces for ifs, whiles, etc. (use-braces)

Suggested change
if (list.some((item) => wordBoundaryRegex.test(item.replace(/\s+/g, ""))))
return true;
if (list.some((item) => wordBoundaryRegex.test(item.replace(/\s+/g, "")))) {
return true;
}


ExplanationIt is recommended to always use braces and create explicit statement blocks.

Using the allowed syntax to just write a single statement can lead to very confusing
situations, especially where subsequently a developer might add another statement
while forgetting to add the braces (meaning that this wouldn't be included in the condition).

dependabot bot and others added 2 commits April 1, 2025 03:28
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 8.27.0 to 8.29.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.29.0/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  dependency-version: 8.29.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/eslint-plugin-8.29.0

build(deps-dev): Bump @typescript-eslint/eslint-plugin from 8.27.0 to 8.29.0
dependabot bot and others added 2 commits April 1, 2025 03:29
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 29.2.6 to 29.3.1.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md)
- [Commits](kulshekhar/ts-jest@v29.2.6...v29.3.1)

---
updated-dependencies:
- dependency-name: ts-jest
  dependency-version: 29.3.1
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…ts-jest-29.3.1

build(deps-dev): Bump ts-jest from 29.2.6 to 29.3.1
dependabot bot and others added 2 commits April 1, 2025 03:30
Bumps [axios](https://github.com/axios/axios) from 0.21.4 to 1.8.4.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](axios/axios@v0.21.4...v1.8.4)

---
updated-dependencies:
- dependency-name: axios
  dependency-version: 1.8.4
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
…axios-1.8.4

build(deps): Bump axios from 0.21.4 to 1.8.4
dependabot bot and others added 2 commits April 2, 2025 03:12
Bumps [eslint-plugin-n](https://github.com/eslint-community/eslint-plugin-n) from 17.16.2 to 17.17.0.
- [Release notes](https://github.com/eslint-community/eslint-plugin-n/releases)
- [Changelog](https://github.com/eslint-community/eslint-plugin-n/blob/master/CHANGELOG.md)
- [Commits](eslint-community/eslint-plugin-n@v17.16.2...v17.17.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-n
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…eslint-plugin-n-17.17.0

build(deps-dev): Bump eslint-plugin-n from 17.16.2 to 17.17.0
dependabot bot and others added 2 commits April 2, 2025 03:12
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 8.28.0 to 8.29.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v8.29.0/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
…typescript-eslint/parser-8.29.0

build(deps-dev): Bump @typescript-eslint/parser from 8.28.0 to 8.29.0
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