Skip to content

Making sure that the nvm stored attributes are ordered by endpoint#1686

Open
brdandu wants to merge 1 commit intoproject-chip:masterfrom
brdandu:bug/nvmKeyShiftsIncorrectly/ZAPP-1690
Open

Making sure that the nvm stored attributes are ordered by endpoint#1686
brdandu wants to merge 1 commit intoproject-chip:masterfrom
brdandu:bug/nvmKeyShiftsIncorrectly/ZAPP-1690

Conversation

@brdandu
Copy link
Collaborator

@brdandu brdandu commented Feb 13, 2026

JIRA: ZAPP-1690

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @brdandu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses the need for consistent and predictable ordering of NVM stored attributes, particularly when generating token headers. By implementing deterministic ORDER BY clauses in database queries and adding robust unit tests, it ensures that attributes are always presented in a logical sequence, improving the reliability and maintainability of the token generation process.

Highlights

  • Deterministic Attribute Ordering: Introduced a deterministic ordering for attributes retrieved by selectTokenAttributesForEndpoint based on cluster and attribute manufacturer codes, cluster name, and attribute code.
  • Refined Global Attribute Ordering: Adjusted the ordering logic in selectAllUserTokenAttributes to ensure singletons are listed first, followed by non-singletons grouped by endpoint identifier, and then by cluster and attribute details.
  • Comprehensive Unit Testing: Added two new unit tests in test/tokens.test.js to rigorously validate the new attribute ordering logic for both selectAllUserTokenAttributes and selectTokenAttributesForEndpoint.
  • Token Header Validation: Enhanced an existing test to verify that the generated token header's identifier section correctly reflects the endpoint-ordered attributes.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src-electron/db/query-attribute.js
    • Added a new ORDER BY clause to selectTokenAttributesForEndpoint to sort by cluster and attribute details.
    • Modified the ORDER BY clause in selectAllUserTokenAttributes to prioritize singletons, then endpoint, and then cluster/attribute details.
  • test/tokens.test.js
    • Imported queryAttribute and queryPackage modules.
    • Added a test to verify selectAllUserTokenAttributes returns attributes ordered by endpoint.
    • Added a test to verify selectTokenAttributesForEndpoint returns attributes in deterministic cluster/attribute order.
    • Updated the 'Test tokens header generation' test to assert that generated token headers maintain endpoint ordering.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces ordering to SQL queries for NVM stored attributes to ensure a deterministic output, which is a solid improvement for consistency. The changes are well-supported by new unit and integration tests that verify the new ordering logic. I have one suggestion to improve the readability of one of the new tests, but overall the changes are good.

Comment on lines +131 to +149
const prev = perEndpoint[i - 1]
const curr = perEndpoint[i]
const cmpClusterMfg =
(prev.clusterMfgCode ?? 0) - (curr.clusterMfgCode ?? 0)
if (cmpClusterMfg !== 0) {
expect(cmpClusterMfg).toBeLessThanOrEqual(0)
continue
}
const cmpMfg = (prev.mfgCode ?? 0) - (curr.mfgCode ?? 0)
if (cmpMfg !== 0) {
expect(cmpMfg).toBeLessThanOrEqual(0)
continue
}
const cmpName = (prev.clusterName || '').localeCompare(
curr.clusterName || ''
)
expect(cmpName).toBeLessThanOrEqual(0)
if (prev.clusterName !== curr.clusterName) continue
expect(prev.code ?? 0).toBeLessThanOrEqual(curr.code ?? 0)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The logic to check the sorting is correct, but it can be simplified for better readability and maintainability. The current implementation uses a pattern of expect().toBeLessThanOrEqual(0) followed by a check for inequality, which is a bit convoluted. A more direct approach would be to check for inequality and then assert that the order is strictly "less than". This makes the intent of the test clearer.

      const prev = perEndpoint[i - 1]
      const curr = perEndpoint[i]
      const cmpClusterMfg =
        (prev.clusterMfgCode ?? 0) - (curr.clusterMfgCode ?? 0)
      if (cmpClusterMfg !== 0) {
        expect(cmpClusterMfg).toBeLessThan(0)
        continue
      }
      const cmpMfg = (prev.mfgCode ?? 0) - (curr.mfgCode ?? 0)
      if (cmpMfg !== 0) {
        expect(cmpMfg).toBeLessThan(0)
        continue
      }
      const cmpName = (prev.clusterName || '').localeCompare(
        curr.clusterName || ''
      )
      if (cmpName !== 0) {
        expect(cmpName).toBeLessThan(0)
        continue
      }
      expect(prev.code ?? 0).toBeLessThanOrEqual(curr.code ?? 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