Skip to content

fix(generation): Make order deterministic#177

Merged
loewenheim merged 4 commits intomainfrom
sebastian/generation-order
Oct 22, 2025
Merged

fix(generation): Make order deterministic#177
loewenheim merged 4 commits intomainfrom
sebastian/generation-order

Conversation

@loewenheim
Copy link
Contributor

Description

JS code generation relies on non-deprecated attributes being visited before deprecated ones for constant name generation, but this was never enforced. This causes tests to fail under Windows, where files are apparently listed in a different order.

Therefore, this PR makes the iteration order in JS code generation deterministic by sorting attributes by:

  1. What name the constant should have;
  2. Deprecation (non-deprecated first).

Python generation is unchanged; the problem isn't so critical there because constant names have already been generated and memoized at that point.

PR Checklist

  • I have run yarn test and verified that the tests pass.
  • I have run yarn generate && yarn format to generate and format code and docs.

JS code generation relies on non-deprecated attributes being visited
before deprecated ones for constant name generation, but this was never
enforced. This causes tests to fail under Windows, where files are
apparently listed in a different order.

Therefore, this PR makes the iteration order in JS code generation
deterministic by sorting attributes by:
1. What name the constant should have;
2. Deprecation (non-deprecated first).

Python generation is unchanged; the problem isn't so critical there
because constant names have already been generated and memoized at that
point.
@github-actions
Copy link

github-actions bot commented Oct 21, 2025

Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Fixes

- Make order deterministic ([#177](https://github.com/getsentry/sentry-conventions/pull/177))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 426722c

Comment on lines 57 to 62
const attributePath = path.join(attributesDir, file);
const attributeJson = JSON.parse(fs.readFileSync(attributePath, 'utf-8')) as AttributeJson;
const isDeprecated = !!attributeJson.deprecation;
const constantName = getConstantName(attributeJson.key, isDeprecated);

allAttributes.push({
allAttributesPartial.push({
file,

Choose a reason for hiding this comment

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

Bug: Calls to getConstantName are missing the required isDeprecated argument, which will cause a TypeScript compilation error.
(Severity: Critical 0.80 | Confidence: 1.00)

🔍 Detailed Analysis

The function signature for getConstantName was changed to require two parameters: key and isDeprecated. However, two call sites within the generateMetadataDict function were not updated to reflect this change. The calls getConstantName(key) and getConstantName(aliasKey) are both missing the required isDeprecated boolean argument. This discrepancy will cause a TypeScript compilation error during the build process (e.g., when running yarn generate), preventing the successful generation of attribute metadata.

💡 Suggested Fix

Update the two calls to getConstantName inside generateMetadataDict to provide the required second argument, isDeprecated. For the first call, you can destructure isDeprecated from attributeJson. For the alias mapping, the correct deprecation status needs to be determined and passed.

🤖 Prompt for AI Agent
Fix this bug. In scripts/generate_attributes.ts at lines 57-62: The function signature
for `getConstantName` was changed to require two parameters: `key` and `isDeprecated`.
However, two call sites within the `generateMetadataDict` function were not updated to
reflect this change. The calls `getConstantName(key)` and `getConstantName(aliasKey)`
are both missing the required `isDeprecated` boolean argument. This discrepancy will
cause a TypeScript compilation error during the build process (e.g., when running `yarn
generate`), preventing the successful generation of attribute metadata.

Did we get this right? 👍 / 👎 to inform future reviews.

lcian added a commit that referenced this pull request Oct 22, 2025
@lcian
Copy link
Member

lcian commented Oct 22, 2025

Thanks for taking care of this @loewenheim, I thought about doing this previously but at least on macos the files were always sorted in the same way, so I didn't think this would be an issue.
I've added some changes on top of this in #178 to satisfy the linter, feel free to incorporate them (I think you should be able to merge that branch into this one).

* changes on top of #177

* improve
@loewenheim
Copy link
Contributor Author

Thank you very much @lcian!

Copy link
Member

@lcian lcian left a comment

Choose a reason for hiding this comment

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

LGTM, I guess we can skip changelog for this one as it's an internal change in the codegen.

@loewenheim loewenheim merged commit a92447f into main Oct 22, 2025
5 of 7 checks passed
@loewenheim loewenheim deleted the sebastian/generation-order branch October 22, 2025 08:23
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