microsoft / microsoft/FluidFramework

Duplicate Code: latestVersions CI logic in deprecated + vnext commands

Open
#26,560 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.9k
Forks
586
Avg merge
1d 15h
Merged PRs (30d)
146

Description

🔍 Duplicate Code Detected: latestVersions command logic

Analysis of commit 9c40c451c647cc3bd04d5191499f8ad13834d59a

Assignee: @copilot

Summary

Two CLI commands implement near-identical “latest minor version for major” decision logic and Azure DevOps ##vso[task.setvariable ...] output. One is already marked deprecated, but the duplication increases the risk of behavior drift (e.g., different filtering/sorting semantics) until the deprecated path is removed.

Duplication Details

Pattern: Same “find latest for major version” loop + ADO variable output
  • Severity: Medium

  • Occurrences: 2

  • Locations:

    • build-tools/packages/build-cli/src/commands/check/latestVersions.ts (approx lines 33–95)
    • build-tools/packages/build-cli/src/commands/vnext/check/latestVersions.ts (approx lines 46–109)
  • Code Sample (representative; same control-flow exists in both files):

for (const v of sortedByVersion) {
	const majorVersion: MajorVersion = semver.major(v /* or v.version */);

	// Since sortedByVersion is sorted, the first encountered version is the highest one
	if (majorVersion === inputMajorVersion) {
		if (v /* or v.version */ === versionInput.version) {
			this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]true`);
			this.log(`##vso[task.setvariable variable=majorVersion;isoutput=true]${majorVersion}`);
			return;
		}

		this.log(`##[warning]skipping deployment stage...`);
		this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]false`);
		this.log(`##vso[task.setvariable variable=majorVersion;isoutput=true]${majorVersion}`);
		return;
	}
}

this.log(`##[warning]No major version found corresponding to input version ${versionInput.version}`);
this.log(`##vso[task.setvariable variable=shouldDeploy;isoutput=true]false`);
this.log(`##vso[task.setvariable variable=majorVersion;isoutput=true]${inputMajorVersion}`);

Impact Analysis

  • Maintainability: Any future change to the policy (version filtering, tag sourcing, ADO variable naming) must be applied twice.
  • Bug Risk: Drift is already plausible (one command uses different mechanisms to retrieve/sort versions). Fixes or telemetry changes could land in only one path.
  • Code Bloat: ~60+ lines of logic duplicated.

Refactoring Recommendations

  1. Extract shared helper

    • Extract a pure helper (e.g., determineLatestMajorDeployDecision(...)) into build-tools/packages/build-cli/src/library/.
    • Return a structured result { shouldDeploy: boolean, majorVersion: number, latestVersionForMajor?: string }.
    • Both commands call the helper and only handle I/O (fetch versions, log ADO variables).
  2. Make deprecated command a thin wrapper

    • Since check:latestVersions is deprecated in favor of vnext:check:latestVersions, keep the deprecated command as an alias/wrapper that forwards to the vnext implementation (or reuses the extracted helper) to prevent divergence.

Implementation Checklist

  • Confirm intended behavioral parity between the two commands (inputs + sorting + filtering)
  • Extract shared helper and add unit coverage (existing vnext test can be reused)
  • Update both commands to call the helper
  • Ensure the deprecation message remains intact

Analysis Metadata

  • Analyzed Files: 2
  • Detection Method: Serena semantic + targeted pattern search
  • Commit: 9c40c451c647cc3bd04d5191499f8ad13834d59a
  • Analysis Date: 2026-02-26T08:06:29Z

AI generated by Duplicate Code Detector

To add this workflow in your repository, run gh aw add github/gh-aw/.github/workflows/duplicate-code-detector.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4. See usage guide.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing build-tools/packages/build-cli/src/commands/check/latestVersions.ts and build-tools/packages/build-cli/src/commands/vnext/check/latestVersions.ts, including their inputs, sorting, filtering, and deprecation behavior. Review the existing vnext test, then extract shared decision logic, update both commands, preserve the deprecation message, and verify unit coverage for equivalent deployment decisions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, cli, tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.