Skip to content
This repository was archived by the owner on Aug 5, 2026. It is now read-only.

[CLOV-1868] Part 1: Add opt-in Nx analysis foundation - #4909

Merged
Vincent Liu (xiaogliu) merged 4 commits into
mainfrom
xiaogliu/implement-part-a
Jul 22, 2026
Merged

Vincent Liu (xiaogliu) merged 4 commits into
mainfrom
xiaogliu/implement-part-a

Conversation

@xiaogliu

@xiaogliu Vincent Liu (xiaogliu) commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds optional Nx project attribution to the adoption analysis engine:
    project discovery, file-to-project mapping, per-project metric buckets, and
    an (unassigned) bucket.
  • Keeps backpack-adoption-guard repository-wide: the GitHub Action does not
    enable Nx analysis and does not produce per-project summaries, thresholds, or
    blocking decisions.
  • Establishes the analysis foundation that PR [CLOV-1868]Part2: extract Backpack Adoption Analyzer #4915 moves into
    backpack-adoption-analyzer; the public Nx plugin will enable and consume
    the per-project capability separately.

Review order

PR 1 of 3. This introduces the opt-in Nx analysis foundation in the current
Guard codebase. PR #4915 extracts it into backpack-adoption-analyzer; the
public Nx plugin follows in PR 3.

Validation

  • Guard lint, test, typecheck, and bundle build
  • Nx project-attribution unit tests
  • Carhire whole-repository preview verification

Ports ds-analyser's NX project detection into backpack-adoption-guard
so a high-adoption project's improvement can no longer mask a
regression in a smaller project sharing the same repo. Adds per-project
adoption reporting (PR summary tables, Cortex payload) and makes the
guard fail when any individual NX project regresses past the threshold,
even if the repo-wide percentage is unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@xiaogliu Vincent Liu (xiaogliu) added the minor Non breaking change label Jul 20, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Ports NX project detection and per-project guard evaluation into backpack-adoption-guard, so adoption regressions in any single NX project can fail the guard even if the repo-wide percentage improves.

Changes:

  • Add NX workspace detection + project ownership attribution for analyzed files, including an (unassigned) bucket.
  • Evaluate guard status per NX project and combine with repo-wide guard result.
  • Emit per-project tables in the PR summary and lightweight per-project metrics in the Cortex payload; document v2 behavior change.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/backpack-adoption-guard/src/shared/types.ts Extend report/guard/metrics types to include optional per-project NX data.
packages/backpack-adoption-guard/src/guard/evaluate-guard.ts Add per-project guard evaluation and combined status logic.
packages/backpack-adoption-guard/src/guard/evaluate-guard-test.ts Add tests covering per-project guard evaluation and status combining.
packages/backpack-adoption-guard/src/analysis/nx-projects.ts New NX project discovery + longest-prefix resolution utilities.
packages/backpack-adoption-guard/src/analysis/nx-projects-test.ts Add filesystem-based tests for NX detection and resolution.
packages/backpack-adoption-guard/src/analysis/analyze-repository.ts Attribute each file’s results to an NX project bucket and return isNx/projects.
packages/backpack-adoption-guard/src/analysis/analyze-repository-test.ts Add tests ensuring repo totals match per-project totals and non-NX behavior is unchanged.
packages/backpack-adoption-guard/src/action/summary.ts Render per-project adoption tables in the GitHub step summary.
packages/backpack-adoption-guard/src/action/run.ts Include per-project metrics in output and combine guard statuses with per-project results.
packages/backpack-adoption-guard/src/action/run-test.ts Add test verifying per-project metrics are written for NX workspaces.
packages/backpack-adoption-guard/README.md Document per-project NX semantics and v2 migration/pass-fail behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@xiaogliu
Vincent Liu (xiaogliu) marked this pull request as ready for review July 20, 2026 03:08
- Count every matched file (including parse-error failures) toward its
  NX project's filesAnalyzed, so per-project totals stay in sync with
  the repo-wide filesAnalyzed even when analysis fails partway through.
- Only attach `projects` to the combined guard result when per-project
  evaluation actually produced entries, matching the optional typing
  and the documented non-NX behaviour.
- Fix finalizeBucket's stale docstring (no longer converts Set->array).
- Use dirname instead of join(path, "..") in the new NX test helper.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

The repo-wide `pnpm typecheck` runs a bare `tsc` against the root
tsconfig (target es5, no downlevelIteration) before running each
package's own typecheck target. Iterating a Set directly with
for...of isn't allowed under that config (TS2802); collect the
project names into an array first, matching the Array.from(new
Set(...)) pattern already used elsewhere in this package.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@xiaogliu Vincent Liu (xiaogliu) changed the title Split Backpack Adoption Guard by NX project Split Backpack Adoption Guard into analyzer, action, and NX plugin Jul 21, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@xiaogliu Vincent Liu (xiaogliu) changed the title Split Backpack Adoption Guard into analyzer, action, and NX plugin Add Nx project-level Backpack Adoption Guard Jul 21, 2026
@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@skyscanner-backpack-bot

Copy link
Copy Markdown
Contributor

@xiaogliu Vincent Liu (xiaogliu) changed the title Add Nx project-level Backpack Adoption Guard [CLOV-1868] Part 1: Add Nx project-level Backpack Adoption Guard Jul 22, 2026

@wpe1arhy Iris Li (wpe1arhy) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.
Title says Add Nx project-level support, but the description says Removes it. Worth fixing before merge.

@xiaogliu Vincent Liu (xiaogliu) changed the title [CLOV-1868] Part 1: Add Nx project-level Backpack Adoption Guard [CLOV-1868] Part 1: Scope Backpack Adoption Guard to repository-wide analysis Jul 22, 2026
@xiaogliu Vincent Liu (xiaogliu) changed the title [CLOV-1868] Part 1: Scope Backpack Adoption Guard to repository-wide analysis [CLOV-1868] Part 1: Add opt-in Nx analysis foundation Jul 22, 2026
@xiaogliu

Copy link
Copy Markdown
Contributor Author

LGTM. Title says Add Nx project-level support, but the description says Removes it. Worth fixing before merge.

👍 update description and let the title more clear.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@xiaogliu
Vincent Liu (xiaogliu) merged commit 13df1c0 into main Jul 22, 2026
15 checks passed
@xiaogliu
Vincent Liu (xiaogliu) deleted the xiaogliu/implement-part-a branch July 22, 2026 03:47
Vincent Liu (xiaogliu) added a commit that referenced this pull request Jul 22, 2026
* Split Backpack Adoption Guard by NX project

Ports ds-analyser's NX project detection into backpack-adoption-guard
so a high-adoption project's improvement can no longer mask a
regression in a smaller project sharing the same repo. Adds per-project
adoption reporting (PR summary tables, Cortex payload) and makes the
guard fail when any individual NX project regresses past the threshold,
even if the repo-wide percentage is unchanged.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Address Copilot review feedback on PR #4909

- Count every matched file (including parse-error failures) toward its
  NX project's filesAnalyzed, so per-project totals stay in sync with
  the repo-wide filesAnalyzed even when analysis fails partway through.
- Only attach `projects` to the combined guard result when per-project
  evaluation actually produced entries, matching the optional typing
  and the documented non-NX behaviour.
- Fix finalizeBucket's stale docstring (no longer converts Set->array).
- Use dirname instead of join(path, "..") in the new NX test helper.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Fix React19 typecheck failure in evaluateProjectGuards

The repo-wide `pnpm typecheck` runs a bare `tsc` against the root
tsconfig (target es5, no downlevelIteration) before running each
package's own typecheck target. Iterating a Set directly with
for...of isn't allowed under that config (TS2802); collect the
project names into an array first, matching the Array.from(new
Set(...)) pattern already used elsewhere in this package.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Limit adoption guard to repository metrics

* Split analysis/guard logic into backpack-adoption-analyzer package

Extracts the pure JSX-analysis engine and pass/fail guard-decision
logic (ported from ds-analyser) out of backpack-adoption-guard into a
new @skyscanner/backpack-adoption-analyzer package with no
@actions/core or GitHub-Actions-specific dependencies. This lets the
same core logic be reused by a future NX plugin without pulling in
the action's git-worktree/step-summary/env-var-reading concerns.

backpack-adoption-guard now depends on the analyzer as a workspace
package (TS-source-only, no dist/, consumed via pnpm workspace
linking like libs/backpack-storybook-host) and only handles the
GitHub Action orchestration: inputs, git worktree checkout, step
summary rendering, and exit codes. No behaviour change — verified by
inspecting dist/index.js to confirm esbuild inlined the analyzer's
source, and all 40 existing tests pass unchanged across both
packages.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

* Keep Nx guard helpers in adoption analyzer

* Sync adoption analyzer with ds-analyser visual usage rules

* Document analyzer bundling constraint

---------

Co-authored-by: Vincent Liu <[email protected]>
Co-authored-by: Claude Sonnet 5 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

minor Non breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants