Skip to content

Conversation

@anthony-murphy-agent
Copy link
Contributor

Summary

  • Add dynamicWeightGenerator.ts with createWeightedAsyncGeneratorWithDynamicWeights
  • Enable generator weights to be functions that receive state and return a weight
  • This allows weights to vary based on the current test state

The standard createWeightedAsyncGenerator from stochastic-test-utils only supports static numeric weights. This enhancement enables dynamic weighting based on runtime conditions like container attach state.

Test plan

  • local-server-stress-tests pass
  • No breaking changes to existing behavior (weights can still be static numbers)

🤖 Generated with Claude Code

…ights

Enable generator weights to be functions that receive state and return a
weight, instead of only supporting static numeric weights. This allows
weights to vary based on the current test state.

Co-Authored-By: anthony-murphy <anthony.murphy@microsoft.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@anthony-murphy-agent
Copy link
Contributor Author

Azure Pipelines commands (copy and post separately, limit of 10 at a time):

/azp run Build - api-markdown-documenter, Build - benchmark-tool, Build - build-common, Build - build-tools, Build - client packages, Build - common-utils, Build - eslint-config-fluid, Build - eslint-plugin-fluid, Build - protocol-definitions, Build site
/azp run Build - test-tools, repo-policy-check, server-gitrest, server-gitssh, server-historian, server-routerlicious

@anthony-murphy
Copy link
Contributor

/azp run Build - api-markdown-documenter, Build - benchmark-tool, Build - build-common, Build - build-tools, Build - client packages, Build - common-utils, Build - eslint-config-fluid, Build - eslint-plugin-fluid, Build - protocol-definitions, Build site

@anthony-murphy
Copy link
Contributor

/azp run Build - test-tools, repo-policy-check, server-gitrest, server-gitssh, server-historian, server-routerlicious

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

1 similar comment
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
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 adds infrastructure for dynamic weight functions in weighted random generators for the local-server-stress-tests package. Currently, the stochastic-test-utils library only supports static numeric weights, but this enhancement enables weights that can be computed dynamically based on runtime test state.

Changes:

  • Introduces dynamicWeightGenerator.ts with support for both static and dynamic (function-based) weights
  • Updates baseModel.ts to use the new dynamic weight generator instead of the static one from stochastic-test-utils
  • Maintains full backward compatibility - existing code with static weights continues to work

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/test/local-server-stress-tests/src/dynamicWeightGenerator.ts New module implementing createWeightedAsyncGeneratorWithDynamicWeights, a variant of the stochastic-test-utils function that evaluates weight functions dynamically at runtime
packages/test/local-server-stress-tests/src/baseModel.ts Updated to use the new dynamic weight generator, with type changes from AsyncWeights to DynamicAsyncWeights

* evaluated at runtime with the current state.
*
* @param weights - Array of [generator, weight, acceptanceCondition?] tuples where
* weight can be a number or a function (state) =\> number
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The arrow in the JSDoc comment is escaped with a backslash. Remove the backslash so it renders correctly as (state) => number instead of (state) =\> number.

Suggested change
* weight can be a number or a function (state) =\> number
* weight can be a number or a function (state) => number

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! However, the backslash escape is actually required here. The project uses TSDoc and has an ESLint rule (tsdoc/syntax) that requires the > character to be escaped to avoid confusion with HTML tags. If I remove the backslash, the build fails with:

tsdoc-escape-greater-than: The ">" character should be escaped using a backslash to avoid confusion with an HTML tag

So the escaped version =\> is correct for TSDoc, even though it may look slightly odd in the rendered documentation.

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