diff --git a/README.md b/README.md index bcb0f9e..e8a0e63 100644 --- a/README.md +++ b/README.md @@ -15,22 +15,30 @@ Plugins are grouped into workspaces under `workspaces//`, one per plugin f Requirements: Node.js 22 or 24, Yarn 4 (bundled in `.yarn/releases`), and Docker for local development. ```sh -yarn install -yarn tsc # type check -yarn lint # lint all packages -yarn test # unit tests -yarn build # type check and build every package -yarn start # run workspaces/ locally, see its README +yarn install # once, from here +yarn tsc # type check +yarn lint # lint all packages +yarn test # unit tests +yarn build # type check and build every package ``` -All workspaces share one Yarn project at the repository root (one `package.json` and `yarn.lock`). +All workspaces share one Yarn project at the repository root — one `package.json` and one `yarn.lock` — but each workspace is its own entry point for running the app. To run one locally, go into it: + +```sh +cd workspaces/ownership-matcher +yarn start +``` ## Repository structure ``` .changeset/ changesets for versioning workspaces// - plugins/* one directory per package + package.json workspace entry point, nests packages/* and plugins/* + packages/app dev frontend, private, never published + packages/backend dev backend, private, never published + plugins/* one directory per published package + scripts/start.js `yarn start` — database, then the two dev packages app-config.yaml configuration for local development docker-compose.yml services for local development examples/ sample catalog data @@ -39,4 +47,4 @@ workspaces// ## Adding a plugin -Run `yarn new`, pick a template, and move the generated package into `workspaces//plugins/`. Run `yarn backstage-cli repo fix --publish` to add the metadata needed for publishing. `yarn start ` runs the `dev/` entry points of the plugins whose plugin ID matches the workspace name, so name the workspace after the plugin ID. +Run `yarn new`, pick a template, and move the generated package into `workspaces//plugins/`. Run `yarn backstage-cli repo fix --publish` to add the metadata needed for publishing. A new workspace needs its own `package.json` nesting `packages/*` and `plugins/*`, plus a `packages/app` and `packages/backend` to run it — the root glob only reaches `workspaces/*`. diff --git a/package.json b/package.json index 7ee76b1..b5022ec 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,6 @@ "node": "22 || 24" }, "scripts": { - "start": "node scripts/start.js", "tsc": "tsc", "tsc:full": "tsc --skipLibCheck false --incremental false", "build": "yarn tsc && backstage-cli repo build --all", @@ -22,6 +21,8 @@ }, "workspaces": { "packages": [ + "workspaces/*", + "workspaces/*/packages/*", "workspaces/*/plugins/*" ] }, diff --git a/tsconfig.json b/tsconfig.json index 304e222..c67b337 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,9 @@ { "extends": "@backstage/cli/config/tsconfig.json", "include": [ + "workspaces/*/packages/*/src", "workspaces/*/plugins/*/src", "workspaces/*/plugins/*/config.d.ts", - "workspaces/*/plugins/*/dev", "workspaces/*/plugins/*/migrations" ], "exclude": ["node_modules"], diff --git a/workspaces/ownership-matcher/README.md b/workspaces/ownership-matcher/README.md index f356b45..ea8209c 100644 --- a/workspaces/ownership-matcher/README.md +++ b/workspaces/ownership-matcher/README.md @@ -42,20 +42,80 @@ See [Statuses](plugins/ownership-matcher-backend/docs/statuses.md) and [Escalati ## Local development -From the repository root: +From this directory: ```sh -yarn start ownership-matcher # or `yarn start` while this is the only workspace +yarn start ``` -This starts Postgres in Docker (`docker-compose.yml`, `127.0.0.1:54321`) and the `dev/` entry points: +This starts Postgres in Docker (`docker-compose.yml`, `127.0.0.1:54321`) and the two dev packages: -- frontend: http://localhost:3000, with the catalog, notifications, org and signals plugins -- backend: http://127.0.0.1:7007, with catalog, auth, permissions, events, notifications, signals and ownership-matcher +- `packages/app` — frontend on http://localhost:3000, with the catalog, notifications, org and signals plugins +- `packages/backend` — backend on http://127.0.0.1:7007, with catalog, auth, permissions, events, notifications, signals and ownership-matcher -Configuration is in `app-config.yaml`, plus an optional gitignored `app-config.local.yaml`. You are signed in as a guest, permissions are allow-all, and the catalog is loaded from `examples/`. The first scan runs 30 seconds after startup and flags the two sample components with a bad owner. +Configuration is in `app-config.yaml`, plus an optional gitignored `app-config.local.yaml`. You are signed in as a guest, permissions are allow-all, and the first scan runs 30 seconds after startup. -The Bitbucket Server and Microsoft Graph modules need real credentials, so the dev backend doesn't install them. To try one, configure it in `app-config.local.yaml` and add it in `plugins/ownership-matcher-backend/dev/index.ts`. +You land on a sign-in page — pick **Guest**. Without an identity every request goes out unauthenticated and the plugin reports "you are not an administrator" and "you are not a member of any groups" rather than a 401, so if you ever see those two messages together, check that you are actually signed in. + +If `yarn start` fails with `Bind for 0.0.0.0:54321 failed: port is already allocated`, another project on the machine holds the database port — `docker compose ls -a` names it. The dev app also binds `127.0.0.1:7008`; if that is taken, the backend refuses to start and names the port. + +### How the sample catalog is wired + +The catalog is not read off disk. On startup the backend copies `examples/` into a temporary directory and serves it over HTTP on `127.0.0.1:7008` as a mock SCM server, and `app-config.yaml` declares an `integrations.*` entry for that host. Backstage only accepts its built-in integration types, so the mock borrows one (`MOCK_SCM_TYPE` in `packages/backend/src/scm/MockScmProvider.ts`) and serves its URL shape; nothing talks to a real server. Two things follow, and the plugin needs both: + +- Every entity gets a `url:` `backstage.io/managed-by-location`. A `file:` location has no integration behind it, so `ScmRegistry` short-circuits before any provider is consulted — with one, entities route to a provider. +- A dev-only SCM provider (`packages/backend/src/scm/`) registers for that integration type. It supplies synthetic commit history, so `top-contributor` can score, and in-memory pull requests whose merge writes the new owner back into the served copy. + +Each top-level directory under `examples/` is a mock repository, which is what lets a pull request rewrite one component's `catalog-info.yaml` without touching the others. The copy is recreated on every start, so a completed demo does not leave the catalog already fixed. + +Nothing under `packages/` ships — both are `private` — and every plugin publishes `dist` only. + +### What the sample data gives you + +The signed-in guest is `user:default/guest`, a member of `team-example` and `team-data` — so the `?team=` selector has something to switch between — and of `dept-example` with a job title matching the escalation `titlePatterns`, which is what opens the lead-only views. `dave` leads the other department, so not every escalation in the catalog is yours. + +After the first scan: + +| View | Shows | +| ----------- | ----------------------------------------------------------------------------------------------------------------- | +| Dashboard | three open cases and a confidence distribution spread over four buckets | +| Entities | the nine failing entities, across Component, API and Resource | +| Proposals | six, three `pending` and three `possible_owner`, from 0.125 to 0.85 | +| Unresolved | six rows: two Components, two APIs, two Resources, under both failing checks — the `kind` facet has three chips | +| Scans | the startup scan, plus any you trigger | +| Pending | `orphaned-service` on `team-example` and `etl-pipeline` on `team-data` | +| My Teams | the same two, seen as the department lead | +| Escalations | empty until you reject `placeholder-owner-library` — that case escalates to `dept-example` and lands on the guest | +| History | fills up as you accept and reject | + +The scores are not arbitrary. With the default weights (`top-contributor` 0.5, `org-proximity` 0.3) and a system owner scoring 0.6, the commit fixtures in `packages/backend/src/scm/fixtures.ts` produce a team that both owns the system and wrote most of the code (0.725), a contested repo (0.5375 against 0.3125), a component with a system but no commits (0.225) and one with neither (nothing at all, so the case goes `unresolved`). + +### Walking a case from accepted to closed + +The deadline-checker sweep raises pull requests and reconciles their outcome. It runs every 15 minutes, which is fine in production and too slow to watch, so drive it by hand: + +```sh +T=$(curl -s http://localhost:7007/api/auth/guest/refresh | jq -r .backstageIdentity.token) +sweep() { curl -s -X POST -H "Authorization: Bearer $T" \ + http://localhost:7007/api/ownership-matcher/.backstage/scheduler/v1/tasks/ownership-matcher-deadline-checker/trigger; } +``` + +Then, accepting `orphaned-service` in the UI: + +1. the case goes `accepted`; +2. `sweep` — one pass raises the pull request against the mock host **and** merges it, writing the new owner into the served `catalog-info.yaml`; +3. the catalog re-reads that file within 30 seconds (`catalog.processingInterval`); +4. the next scan closes the case as `ownership_changed`. + +The merge is immediate on purpose. `MERGE_AFTER_MS` in `packages/backend/src/index.ts` is `0` because a single sweep raises the PR and reconciles it in the same pass: a PR with any delay at all is still open at its only reconciliation, and `PR_RECONCILE_INTERVAL_MS` then puts the next check an hour out, stranding the case in `accepted`. Raise the constant if you want to see the open-PR state in the UI, and expect to wait out that hour. + +`POST /api/ownership-matcher/scans/trigger` runs a scan without waiting for the daily schedule. The same scheduler endpoint drives proposal expiry: `ownershipMatcher.proposals.expirationMinutes` is 10, so a proposal left alone for ten minutes reaches `expired` on the next sweep. + +Two statuses stay out of reach here. `to_archive` needs an escalation action and `cancelled` needs a proposal to be superseded; both depend on the escalation clock, whose `timeoutDays` has no minute-level override. + +Outside production the `/leadership/*` endpoints accept `?asUser=`, which is the quickest way to check the lead-only views as somebody else — for example `user:default/alice`, who leads nothing. + +The Bitbucket Server and Microsoft Graph modules need real credentials, so the dev backend doesn't install them. To try one, configure it in `app-config.local.yaml` and add it in `packages/backend/src/index.ts`. ## Integration tests diff --git a/workspaces/ownership-matcher/app-config.yaml b/workspaces/ownership-matcher/app-config.yaml index c162ff2..1ab90b2 100644 --- a/workspaces/ownership-matcher/app-config.yaml +++ b/workspaces/ownership-matcher/app-config.yaml @@ -1,9 +1,16 @@ -# Configuration for `yarn start` (the plugins' dev/ entry points). Not used by the -# published packages. `yarn start` also loads app-config.local.yaml next to this -# file if it exists (gitignored), for local overrides. +# Configuration for this workspace's `yarn start` (packages/app and +# packages/backend). Not used by the published packages. scripts/start.js also +# loads app-config.local.yaml next to this file if it exists (gitignored). app: title: ownership-matcher dev app baseUrl: http://localhost:3000 + # Enables the app plugin's own sign-in page, which offers the `guest` + # provider. Without a sign-in page the app renders with no identity, every + # request goes out unauthenticated, and catalog, notifications and + # ownership-matcher all answer 401 — which the UI surfaces as "you are not an + # administrator" and "you are not a member of any groups". + extensions: + - sign-in-page:app organization: name: Development @@ -31,21 +38,70 @@ backend: auth: providers: - guest: {} + guest: + # The provider defaults to user:development/guest, which examples/root/org.yaml + # does not define, so sign-in falls back to a token with no group + # ownership refs and every "my teams" view renders empty. Point it at the + # sample user instead, so the guest inherits group:default/team-example. + userEntityRef: user:default/guest permission: enabled: true +# Mock SCM server, not a real one. The dev backend serves a throwaway copy of +# examples/ on 127.0.0.1:7008 (packages/backend/src/devScmServer.ts), and this +# entry is what makes two things work at once: Backstage's URL reader can read +# the catalog files, and ownership-matcher's ScmRegistry can route an entity's +# managed-by-location to the mock SCM provider registered for this type. +# Backstage only accepts its built-in integration types, so the mock borrows +# this one and its URL shape; the key cannot be renamed to something generic. +# Without an integration for the host the registry short-circuits and no +# provider is ever consulted. +integrations: + bitbucketServer: + - host: 127.0.0.1:7008 + # Explicit because the default is https:///rest/api/1.0. + apiBaseUrl: http://127.0.0.1:7008/rest/api/1.0 + catalog: + # Dev-only: a merged pull request writes the new owner into the served copy + # of examples/, and the case only closes once the catalog has re-read it. + # The 10-minute default would leave it looking stuck. + processingInterval: + seconds: 30 rules: - allow: [Component, System, API, Resource, Location, User, Group] locations: - - type: file - target: ../../examples/entities.yaml - - type: file - target: ../../examples/org.yaml + # Everything else is reached from this one document. The port is fixed by + # DEV_SCM_PORT in packages/backend/src/devScmServer.ts. + - type: url + target: http://127.0.0.1:7008/projects/dev/repos/root/browse/root.yaml ownershipMatcher: + # The dev SCM provider ignores the token, but ScmRegistry only hands a host + # config to a provider that has one, and the real providers refuse writes + # without it — so the shape is kept honest here. + scm: + hosts: + - host: 127.0.0.1:7008 + writeToken: dev-token checks: orphaned: placeholderValues: [unknown] + proposals: + # Documented as "meant for testing": without it a proposal expires after + # `expirationDays` and `expired` is unreachable in a sitting. Expiry only + # fires on a deadline-checker sweep, so nothing expires behind your back + # until the next one runs. + autoExpiry: true + expirationMinutes: 10 + # Enabled so the escalation-driven views are reachable: without this key + # escalation is off, every case with no candidates goes straight to + # unresolved, and /leadership/stats never reports a leader. The title + # pattern matches the guest user's spec.profile.title in examples/root/org.yaml. + escalation: + levels: + - groupFilter: Group:department + timeoutDays: 7 + titlePatterns: ['^Head of '] + fallbackActors: ['user:default/guest'] diff --git a/workspaces/ownership-matcher/docker-compose.yml b/workspaces/ownership-matcher/docker-compose.yml index af5a772..8070e93 100644 --- a/workspaces/ownership-matcher/docker-compose.yml +++ b/workspaces/ownership-matcher/docker-compose.yml @@ -1,5 +1,5 @@ name: backstage-plugins -# Postgres for the development backend, started by `yarn start`. ownership-matcher's +# Postgres for packages/backend, started by this workspace's `yarn start`. ownership-matcher's # migrations use Postgres-only features, so SQLite isn't an option. services: db: @@ -7,7 +7,7 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres - # `docker compose up --wait` (run by `yarn start`) waits for this, so the + # `docker compose up --wait` (run by scripts/start.js) waits for this, so the # backend doesn't start before Postgres accepts connections. healthcheck: test: ['CMD-SHELL', 'pg_isready -U postgres -h 127.0.0.1'] diff --git a/workspaces/ownership-matcher/examples/analytics-bucket/catalog-info.yaml b/workspaces/ownership-matcher/examples/analytics-bucket/catalog-info.yaml new file mode 100644 index 0000000..7299d2c --- /dev/null +++ b/workspaces/ownership-matcher/examples/analytics-bucket/catalog-info.yaml @@ -0,0 +1,10 @@ +# orphaned check fails. Third kind on the Unresolved tab, so its `kind` facet +# shows three chips with a count above one. +apiVersion: backstage.io/v1alpha1 +kind: Resource +metadata: + name: analytics-bucket + description: Placeholder owner and no parent system +spec: + type: s3-bucket + owner: unknown diff --git a/workspaces/ownership-matcher/examples/docs-portal/catalog-info.yaml b/workspaces/ownership-matcher/examples/docs-portal/catalog-info.yaml new file mode 100644 index 0000000..c36170a --- /dev/null +++ b/workspaces/ownership-matcher/examples/docs-portal/catalog-info.yaml @@ -0,0 +1,14 @@ +# orphaned check fails and there are no commits in +# packages/backend/src/scm/fixtures.ts, so org-proximity is the only strategy that scores it: +# 0.3 * 0.6 / (0.5 + 0.3) = 0.225, below the 0.4 notification threshold. This +# is the component that keeps `possible_owner` reachable. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: docs-portal + description: Placeholder owner, a parent system, and nobody committing to it +spec: + type: website + lifecycle: experimental + owner: unknown + system: internal-tools diff --git a/workspaces/ownership-matcher/examples/entities.yaml b/workspaces/ownership-matcher/examples/entities.yaml deleted file mode 100644 index 31bbb7e..0000000 --- a/workspaces/ownership-matcher/examples/entities.yaml +++ /dev/null @@ -1,32 +0,0 @@ -# Sample catalog for the development backend. The components cover the -# cases ownership-matcher looks at: a valid owner, an owner that doesn't exist -# in the catalog and a placeholder owner. -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: owned-service - description: Owned by a team that exists in the catalog -spec: - type: service - lifecycle: production - owner: group:default/team-example ---- -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: orphaned-service - description: Owned by a team that doesn't exist in the catalog -spec: - type: service - lifecycle: production - owner: group:default/team-that-was-disbanded ---- -apiVersion: backstage.io/v1alpha1 -kind: Component -metadata: - name: placeholder-owner-library - description: Owned by a placeholder value -spec: - type: library - lifecycle: experimental - owner: unknown diff --git a/workspaces/ownership-matcher/examples/etl-pipeline/catalog-info.yaml b/workspaces/ownership-matcher/examples/etl-pipeline/catalog-info.yaml new file mode 100644 index 0000000..817f31f --- /dev/null +++ b/workspaces/ownership-matcher/examples/etl-pipeline/catalog-info.yaml @@ -0,0 +1,13 @@ +# orphaned check fails, and both strategies point at team-data — the signed-in +# user's *second* team. Accepting here instead of on orphaned-service is what +# exercises the `?team=` selector on the user-facing tabs. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: etl-pipeline + description: Owned by a placeholder value, committed to by the data team +spec: + type: service + lifecycle: production + owner: unknown + system: data-platform diff --git a/workspaces/ownership-matcher/examples/legacy-batch-job/catalog-info.yaml b/workspaces/ownership-matcher/examples/legacy-batch-job/catalog-info.yaml new file mode 100644 index 0000000..5c3aeb5 --- /dev/null +++ b/workspaces/ownership-matcher/examples/legacy-batch-job/catalog-info.yaml @@ -0,0 +1,11 @@ +# No system and no commits, so neither strategy finds a candidate: this is the +# one that keeps the "Unresolved" tab populated. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: legacy-batch-job + description: Placeholder owner and no parent system, so no candidates are found +spec: + type: service + lifecycle: deprecated + owner: unknown diff --git a/workspaces/ownership-matcher/examples/legacy-queue/catalog-info.yaml b/workspaces/ownership-matcher/examples/legacy-queue/catalog-info.yaml new file mode 100644 index 0000000..1efb00c --- /dev/null +++ b/workspaces/ownership-matcher/examples/legacy-queue/catalog-info.yaml @@ -0,0 +1,9 @@ +# zombie check fails. +apiVersion: backstage.io/v1alpha1 +kind: Resource +metadata: + name: legacy-queue + description: Owned by a team that doesn't exist in the catalog +spec: + type: queue + owner: group:default/team-that-was-disbanded diff --git a/workspaces/ownership-matcher/examples/org.yaml b/workspaces/ownership-matcher/examples/org.yaml deleted file mode 100644 index 9a03023..0000000 --- a/workspaces/ownership-matcher/examples/org.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Sample organization for the development backend. -apiVersion: backstage.io/v1alpha1 -kind: Group -metadata: - name: team-example - title: Example Team -spec: - type: team - children: [] - members: - - guest ---- -apiVersion: backstage.io/v1alpha1 -kind: User -metadata: - name: guest -spec: - profile: - displayName: Guest User - email: guest@example.com - memberOf: - - team-example diff --git a/workspaces/ownership-matcher/examples/orphaned-service/catalog-info.yaml b/workspaces/ownership-matcher/examples/orphaned-service/catalog-info.yaml new file mode 100644 index 0000000..d7ad8ce --- /dev/null +++ b/workspaces/ownership-matcher/examples/orphaned-service/catalog-info.yaml @@ -0,0 +1,13 @@ +# zombie check fails, and the system owner is the signed-in user's team, so the +# proposal shows up on the user-facing "Pending" tab. This is the component to +# accept when walking the accept -> PR -> merge -> closed lifecycle. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: orphaned-service + description: Owned by a team that doesn't exist in the catalog +spec: + type: service + lifecycle: production + owner: group:default/team-that-was-disbanded + system: commerce-platform diff --git a/workspaces/ownership-matcher/examples/owned-service/catalog-info.yaml b/workspaces/ownership-matcher/examples/owned-service/catalog-info.yaml new file mode 100644 index 0000000..f3ac5a7 --- /dev/null +++ b/workspaces/ownership-matcher/examples/owned-service/catalog-info.yaml @@ -0,0 +1,12 @@ +# Passes every check: the control case that proves a healthy entity is not +# flagged. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: owned-service + description: Owned by a team that exists in the catalog +spec: + type: service + lifecycle: production + owner: group:default/team-example + system: commerce-platform diff --git a/workspaces/ownership-matcher/examples/payments-api/catalog-info.yaml b/workspaces/ownership-matcher/examples/payments-api/catalog-info.yaml new file mode 100644 index 0000000..3aee992 --- /dev/null +++ b/workspaces/ownership-matcher/examples/payments-api/catalog-info.yaml @@ -0,0 +1,15 @@ +# orphaned check fails, no system and no commits: nothing scores it, so it +# lands on the Unresolved tab as an API rather than a Component. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: payments-api + description: Placeholder owner and no parent system +spec: + type: openapi + lifecycle: production + owner: unknown + definition: | + openapi: 3.0.0 + info: { title: Payments, version: '1.0' } + paths: {} diff --git a/workspaces/ownership-matcher/examples/placeholder-owner-library/catalog-info.yaml b/workspaces/ownership-matcher/examples/placeholder-owner-library/catalog-info.yaml new file mode 100644 index 0000000..5b13ff0 --- /dev/null +++ b/workspaces/ownership-matcher/examples/placeholder-owner-library/catalog-info.yaml @@ -0,0 +1,12 @@ +# orphaned check fails, and the proposal goes to the other team — visible on +# the admin "Proposals" tab. Rejecting it escalates up to dept-example. +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: placeholder-owner-library + description: Owned by a placeholder value +spec: + type: library + lifecycle: experimental + owner: unknown + system: internal-tools diff --git a/workspaces/ownership-matcher/examples/root/org.yaml b/workspaces/ownership-matcher/examples/root/org.yaml new file mode 100644 index 0000000..adccd48 --- /dev/null +++ b/workspaces/ownership-matcher/examples/root/org.yaml @@ -0,0 +1,148 @@ +# Sample organization for the development backend. Shaped so `yarn start` has +# something to show in every view: +# +# - `guest` is the signed-in user (auth.providers.guest.userEntityRef in +# app-config.yaml points at it). It belongs to two teams, so the `?team=` +# selector on the user-facing tabs has something to switch between. +# - `guest` also sits in dept-example with a job title matching the escalation +# `titlePatterns`, which is what makes `/leadership/stats` report +# `isLeader: true` and unlocks the "My Teams" and "Escalations" tabs. It +# leads dept-example only — `dave` leads dept-operations, so not every +# escalation in the catalog is one of yours. +# - team-platform exists so the admin views show proposals for a team the +# signed-in user is *not* in, and so a rejection there escalates up to +# dept-example, i.e. to `guest`. +# +# `memberOf` is written as a full `group:default/...` ref on purpose: +# ContributorService only counts memberships in that form, so the short name a +# hand-written fixture would normally use scores nothing in top-contributor. +# +# `alice`, `bob` and `carol` are the commit authors in +# packages/backend/src/scm/fixtures.ts. None of them is +# `guest`: `guest` is a member of a department as well, and `top-contributor` +# counts every group a contributor belongs to, so commits of theirs would +# propose ownership to a department. +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: dept-example + title: Example Department +spec: + type: department + children: + - team-example + - team-platform +--- +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: dept-operations + title: Operations Department +spec: + type: department + children: + - team-data +--- +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: team-example + title: Example Team +spec: + type: team + parent: dept-example + children: [] + members: + - guest + - bob +--- +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: team-platform + title: Platform Team +spec: + type: team + parent: dept-example + children: [] + members: + - alice +--- +apiVersion: backstage.io/v1alpha1 +kind: Group +metadata: + name: team-data + title: Data Team +spec: + type: team + parent: dept-operations + children: [] + members: + - guest + - carol +--- +apiVersion: backstage.io/v1alpha1 +kind: User +metadata: + name: guest +spec: + profile: + displayName: Guest User + email: guest@example.com + # Matched against ownershipMatcher.escalation.levels[].titlePatterns. + title: Head of Engineering + memberOf: + - group:default/team-example + - group:default/team-data + - group:default/dept-example +--- +apiVersion: backstage.io/v1alpha1 +kind: User +metadata: + name: alice +spec: + profile: + displayName: Alice Example + email: alice@example.com + title: Software Engineer + memberOf: + - group:default/team-platform +--- +apiVersion: backstage.io/v1alpha1 +kind: User +metadata: + name: bob +spec: + profile: + displayName: Bob Example + email: bob@example.com + title: Software Engineer + memberOf: + - group:default/team-example +--- +apiVersion: backstage.io/v1alpha1 +kind: User +metadata: + name: carol +spec: + profile: + displayName: Carol Example + email: carol@example.com + title: Data Engineer + memberOf: + - group:default/team-data +--- +# Leads the other department, so the escalations raised there are somebody +# else's — which is what makes the "Escalations" tab a filtered view rather +# than a list of everything. +apiVersion: backstage.io/v1alpha1 +kind: User +metadata: + name: dave +spec: + profile: + displayName: Dave Example + email: dave@example.com + title: Head of Operations + memberOf: + - group:default/dept-operations diff --git a/workspaces/ownership-matcher/examples/root/root.yaml b/workspaces/ownership-matcher/examples/root/root.yaml new file mode 100644 index 0000000..a482dc6 --- /dev/null +++ b/workspaces/ownership-matcher/examples/root/root.yaml @@ -0,0 +1,31 @@ +# Root document of the dev catalog. `startDevScmServer` serves a writable +# copy of this directory over HTTP, and app-config.yaml points +# `catalog.locations` at this one file; everything else is reached from here. +# +# Each top-level directory beside this one is a mock repository, so every +# component gets its own `catalog-info.yaml` at its own +# `backstage.io/managed-by-location` — which is what lets the dev SCM provider +# raise a pull request against one component without rewriting the others. +# +# Targets are relative to this file, which lives at +# /projects/dev/repos/root/browse/root.yaml: `./x` is another file in the root +# repo, and `../..//browse/x` is a file in a sibling repo. +apiVersion: backstage.io/v1alpha1 +kind: Location +metadata: + name: dev-catalog-root + description: Every entity the dev app loads +spec: + targets: + - ./org.yaml + - ./systems.yaml + - ../../owned-service/browse/catalog-info.yaml + - ../../orphaned-service/browse/catalog-info.yaml + - ../../placeholder-owner-library/browse/catalog-info.yaml + - ../../docs-portal/browse/catalog-info.yaml + - ../../legacy-batch-job/browse/catalog-info.yaml + - ../../etl-pipeline/browse/catalog-info.yaml + - ../../payments-api/browse/catalog-info.yaml + - ../../search-api/browse/catalog-info.yaml + - ../../analytics-bucket/browse/catalog-info.yaml + - ../../legacy-queue/browse/catalog-info.yaml diff --git a/workspaces/ownership-matcher/examples/root/systems.yaml b/workspaces/ownership-matcher/examples/root/systems.yaml new file mode 100644 index 0000000..c67c4ba --- /dev/null +++ b/workspaces/ownership-matcher/examples/root/systems.yaml @@ -0,0 +1,27 @@ +# The systems the components belong to. They live in the root repo rather than +# in a component's, because `org-proximity` reads the *system's* owner to find +# a candidate — without a system owner it finds none, every case goes straight +# to `unresolved`, and the proposal-driven views stay empty. +apiVersion: backstage.io/v1alpha1 +kind: System +metadata: + name: commerce-platform + description: Owned by the signed-in user's team +spec: + owner: group:default/team-example +--- +apiVersion: backstage.io/v1alpha1 +kind: System +metadata: + name: internal-tools + description: Owned by a team the signed-in user is not in +spec: + owner: group:default/team-platform +--- +apiVersion: backstage.io/v1alpha1 +kind: System +metadata: + name: data-platform + description: Owned by the signed-in user's *other* team +spec: + owner: group:default/team-data diff --git a/workspaces/ownership-matcher/examples/search-api/catalog-info.yaml b/workspaces/ownership-matcher/examples/search-api/catalog-info.yaml new file mode 100644 index 0000000..fd167c3 --- /dev/null +++ b/workspaces/ownership-matcher/examples/search-api/catalog-info.yaml @@ -0,0 +1,15 @@ +# zombie check fails this time — the Unresolved tab needs more than one +# failing check behind the rows, not just more than one kind. +apiVersion: backstage.io/v1alpha1 +kind: API +metadata: + name: search-api + description: Owned by a team that doesn't exist in the catalog +spec: + type: openapi + lifecycle: experimental + owner: group:default/team-that-was-disbanded + definition: | + openapi: 3.0.0 + info: { title: Search, version: '1.0' } + paths: {} diff --git a/workspaces/ownership-matcher/package.json b/workspaces/ownership-matcher/package.json new file mode 100644 index 0000000..1f00623 --- /dev/null +++ b/workspaces/ownership-matcher/package.json @@ -0,0 +1,24 @@ +{ + "name": "@internal/ownership-matcher", + "version": "0.1.0", + "private": true, + "description": "Workspace entry point: the ownership-matcher packages and the dev app that runs them", + "workspaces": { + "packages": [ + "packages/*", + "plugins/*" + ] + }, + "scripts": { + "start": "node scripts/start.js" + }, + "repository": { + "type": "git", + "url": "https://github.com/stepstone-tech/backstage-plugins.git", + "directory": "workspaces/ownership-matcher" + }, + "devDependencies": { + "@backstage/cli": "^0.36.6", + "@backstage/cli-defaults": "^0.1.6" + } +} diff --git a/workspaces/ownership-matcher/packages/app/.eslintrc.js b/workspaces/ownership-matcher/packages/app/.eslintrc.js new file mode 100644 index 0000000..1bb986e --- /dev/null +++ b/workspaces/ownership-matcher/packages/app/.eslintrc.js @@ -0,0 +1,17 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/workspaces/ownership-matcher/packages/app/package.json b/workspaces/ownership-matcher/packages/app/package.json new file mode 100644 index 0000000..99a3c51 --- /dev/null +++ b/workspaces/ownership-matcher/packages/app/package.json @@ -0,0 +1,41 @@ +{ + "name": "app", + "version": "0.0.0", + "private": true, + "description": "Development app for the ownership-matcher workspace. Not published.", + "backstage": { + "role": "frontend" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test", + "clean": "backstage-cli package clean" + }, + "dependencies": { + "@backstage/cli": "^0.36.6", + "@backstage/core-components": "^0.18.14", + "@backstage/frontend-defaults": "^0.5.6", + "@backstage/frontend-plugin-api": "^0.18.1", + "@backstage/plugin-app-react": "^0.2.8", + "@backstage/plugin-catalog": "^2.0.9", + "@backstage/plugin-notifications": "^0.6.0", + "@backstage/plugin-org": "^0.7.9", + "@backstage/plugin-signals": "^0.0.35", + "@backstage/ui": "^0.18.0", + "@material-ui/core": "^4.9.13", + "@material-ui/icons": "^4.9.1", + "@stepstone-tech/backstage-plugin-ownership-matcher": "workspace:^", + "react": "^18.0.2", + "react-dom": "^18.0.2", + "react-router-dom": "^6.21.1" + }, + "devDependencies": { + "@types/react": "^18.0.0", + "@types/react-dom": "^18.0.0" + }, + "files": [ + "dist" + ] +} diff --git a/workspaces/ownership-matcher/packages/app/public/index.html b/workspaces/ownership-matcher/packages/app/public/index.html new file mode 100644 index 0000000..ee2ae7c --- /dev/null +++ b/workspaces/ownership-matcher/packages/app/public/index.html @@ -0,0 +1,17 @@ + + + + + + + + <%= config.getOptionalString('app.title') ?? 'Backstage' %> + + + +
+ + diff --git a/workspaces/ownership-matcher/plugins/ownership-matcher/dev/index.tsx b/workspaces/ownership-matcher/packages/app/src/App.tsx similarity index 52% rename from workspaces/ownership-matcher/plugins/ownership-matcher/dev/index.tsx rename to workspaces/ownership-matcher/packages/app/src/App.tsx index f26cc8b..15cae76 100644 --- a/workspaces/ownership-matcher/plugins/ownership-matcher/dev/index.tsx +++ b/workspaces/ownership-matcher/packages/app/src/App.tsx @@ -14,21 +14,28 @@ * limitations under the License. */ -/* - * Development app for ownership-matcher, started with `yarn start` at the - * repository root together with the backend's dev/index.ts. See the workspace - * README. - */ -import { createDevApp } from '@backstage/frontend-dev-utils'; +import { createApp } from '@backstage/frontend-defaults'; import catalogPlugin from '@backstage/plugin-catalog/alpha'; import notificationsPlugin from '@backstage/plugin-notifications/alpha'; import orgPlugin from '@backstage/plugin-org/alpha'; import signalsPlugin from '@backstage/plugin-signals/alpha'; -import plugin from '../src/alpha'; +import ownershipMatcherPlugin from '@stepstone-tech/backstage-plugin-ownership-matcher/alpha'; -createDevApp({ +/* + * No sign-in page is declared here on purpose. The app plugin already ships + * `sign-in-page:app`, which offers the `guest` provider, and `app.extensions` + * in app-config.yaml enables it explicitly. + * + * Do not add a custom one under pluginId 'app': SignInPageBlueprint derives its + * extension id from the plugin id, so it collides with the built-in and is + * dropped as a duplicate (`EXTENSION_IGNORED`). The app then renders with no + * sign-in page at all, every request goes out unauthenticated, and the catalog, + * notifications and ownership-matcher all answer 401 — which the UI reports as + * "you are not an administrator" rather than as an auth failure. + */ +export default createApp({ features: [ - plugin, + ownershipMatcherPlugin, catalogPlugin, notificationsPlugin, orgPlugin, diff --git a/workspaces/ownership-matcher/packages/app/src/index.tsx b/workspaces/ownership-matcher/packages/app/src/index.tsx new file mode 100644 index 0000000..e41423f --- /dev/null +++ b/workspaces/ownership-matcher/packages/app/src/index.tsx @@ -0,0 +1,22 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import '@backstage/cli/asset-types'; +import ReactDOM from 'react-dom/client'; +import '@backstage/ui/css/styles.css'; +import app from './App'; + +ReactDOM.createRoot(document.getElementById('root')!).render(app.createRoot()); diff --git a/workspaces/ownership-matcher/packages/backend/.eslintrc.js b/workspaces/ownership-matcher/packages/backend/.eslintrc.js new file mode 100644 index 0000000..1bb986e --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/.eslintrc.js @@ -0,0 +1,17 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); diff --git a/workspaces/ownership-matcher/packages/backend/package.json b/workspaces/ownership-matcher/packages/backend/package.json new file mode 100644 index 0000000..cea749d --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/package.json @@ -0,0 +1,41 @@ +{ + "name": "backend", + "version": "0.0.0", + "private": true, + "description": "Development backend for the ownership-matcher workspace. Not published.", + "main": "dist/index.cjs.js", + "types": "src/index.ts", + "backstage": { + "role": "backend" + }, + "scripts": { + "start": "backstage-cli package start", + "build": "backstage-cli package build", + "lint": "backstage-cli package lint", + "test": "backstage-cli package test --runInBand --forceExit", + "clean": "backstage-cli package clean" + }, + "dependencies": { + "@backstage/backend-defaults": "^0.18.0", + "@backstage/backend-plugin-api": "^1.10.1", + "@backstage/plugin-auth-backend": "^0.30.1", + "@backstage/plugin-auth-backend-module-guest-provider": "^0.2.23", + "@backstage/plugin-catalog-backend": "^4.0.0", + "@backstage/plugin-events-backend": "^0.6.6", + "@backstage/plugin-notifications-backend": "^0.6.9", + "@backstage/plugin-permission-backend": "^0.7.16", + "@backstage/plugin-permission-backend-module-allow-all-policy": "^0.2.23", + "@backstage/plugin-signals-backend": "^0.3.19", + "@stepstone-tech/backstage-plugin-ownership-matcher-backend": "workspace:^", + "@stepstone-tech/backstage-plugin-ownership-matcher-node": "workspace:^", + "pg": "^8.11.3" + }, + "devDependencies": { + "@backstage/backend-test-utils": "^1.11.7", + "@backstage/cli": "^0.36.6", + "yaml": "^2.8.2" + }, + "files": [ + "dist" + ] +} diff --git a/workspaces/ownership-matcher/packages/backend/src/devScmServer.test.ts b/workspaces/ownership-matcher/packages/backend/src/devScmServer.test.ts new file mode 100644 index 0000000..abbd59c --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/devScmServer.test.ts @@ -0,0 +1,121 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createServer } from 'node:http'; +import { mkdtemp, mkdir, readFile, writeFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { + rawUrlPath, + startDevScmServer, + type DevScmServer, +} from './devScmServer'; + +const ORIGINAL = 'kind: Component\n'; + +async function makeSourceDir(): Promise { + const dir = await mkdtemp(join(tmpdir(), 'dev-catalog-src-')); + await mkdir(join(dir, 'a'), { recursive: true }); + await writeFile(join(dir, 'a', 'catalog-info.yaml'), ORIGINAL, 'utf8'); + return dir; +} + +describe('startDevScmServer', () => { + const started: DevScmServer[] = []; + + async function start(opts: { sourceDir: string; port?: number }) { + const server = await startDevScmServer({ port: 0, ...opts }); + started.push(server); + return server; + } + + afterEach(async () => { + await Promise.all(started.splice(0).map(s => s.close())); + }); + + it('serves a file from a fresh copy of the source directory', async () => { + const sourceDir = await makeSourceDir(); + const server = await start({ sourceDir }); + + const res = await fetch( + `${server.url}${rawUrlPath('a', 'catalog-info.yaml')}`, + ); + + expect(res.status).toBe(200); + await expect(res.text()).resolves.toBe(ORIGINAL); + // The copy is writable and separate from the source. + expect(server.rootDir).not.toBe(sourceDir); + await expect( + readFile(join(server.rootDir, 'a', 'catalog-info.yaml'), 'utf8'), + ).resolves.toBe(ORIGINAL); + }); + + it('resets the copy on every start, discarding earlier writes', async () => { + const sourceDir = await makeSourceDir(); + const first = await start({ sourceDir }); + await writeFile( + join(first.rootDir, 'a', 'catalog-info.yaml'), + 'kind: Tampered\n', + 'utf8', + ); + await first.close(); + + const second = await start({ sourceDir }); + const res = await fetch( + `${second.url}${rawUrlPath('a', 'catalog-info.yaml')}`, + ); + + await expect(res.text()).resolves.toBe(ORIGINAL); + }); + + it('404s for an unknown path', async () => { + const server = await start({ sourceDir: await makeSourceDir() }); + + await expect( + fetch(`${server.url}${rawUrlPath('a', 'nope.yaml')}`).then(r => r.status), + ).resolves.toBe(404); + await expect( + fetch(`${server.url}/nope.yaml`).then(r => r.status), + ).resolves.toBe(404); + }); + + it('404s for a path that escapes the served directory', async () => { + const server = await start({ sourceDir: await makeSourceDir() }); + + const res = await fetch( + `${server.url}/rest/api/1.0/projects/dev/repos/a/raw/..%2F..%2Fetc%2Fpasswd`, + ); + + expect(res.status).toBe(404); + }); + + it('refuses to start when the port is taken, naming the port', async () => { + const blocker = createServer(); + const port: number = await new Promise(resolve => + blocker.listen(0, '127.0.0.1', () => + resolve((blocker.address() as { port: number }).port), + ), + ); + + try { + await expect( + startDevScmServer({ sourceDir: await makeSourceDir(), port }), + ).rejects.toThrow(String(port)); + } finally { + await new Promise(resolve => blocker.close(resolve)); + } + }); +}); diff --git a/workspaces/ownership-matcher/packages/backend/src/devScmServer.ts b/workspaces/ownership-matcher/packages/backend/src/devScmServer.ts new file mode 100644 index 0000000..b586b64 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/devScmServer.ts @@ -0,0 +1,168 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createServer, type Server, type ServerResponse } from 'node:http'; +import { cp, readFile, rm } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join, resolve, sep } from 'node:path'; + +/** + * Project key every mock repository lives under. The served URLs follow the + * URL shape of the integration type the dev host is configured as (see + * `MOCK_SCM_TYPE`): Backstage's URL reader for that type claims every read on + * the host and rewrites the target to `/projects//repos//raw/`. + */ +export const DEV_PROJECT_KEY = 'dev'; + +/** + * Port the dev SCM server listens on. 3000 and 7007 are taken by `yarn start` + * and 54321 by the workspace's Postgres, so this is a fourth fixed port — + * `examples/root/root.yaml` and `app-config.yaml` both hardcode it. + */ +export const DEV_SCM_PORT = 7008; + +/** The repository holding `root.yaml` and `org.yaml` — everything that is not a component. */ +export const ROOT_REPO_SLUG = 'root'; + +/** API path the catalog's URL reader fetches a file through. */ +export function rawUrlPath(repoSlug: string, filePath: string): string { + return `/rest/api/1.0/projects/${DEV_PROJECT_KEY}/repos/${repoSlug}/raw/${filePath}`; +} + +/** Browse URL a catalog location points at, i.e. the entity's `managed-by-location`. */ +export function browseUrl( + baseUrl: string, + repoSlug: string, + filePath: string, +): string { + return `${baseUrl}/projects/${DEV_PROJECT_KEY}/repos/${repoSlug}/browse/${filePath}`; +} + +/** + * Absolute path of a file inside a mock repository, or `undefined` when the + * repo slug or the path would escape the served directory. The one mapping + * rule: a top-level directory of the served copy is a repository. + */ +export function repoFilePath( + rootDir: string, + repoSlug: string, + filePath: string, +): string | undefined { + if (!repoSlug || repoSlug.includes('/') || repoSlug.includes('\\')) { + return undefined; + } + const base = resolve(rootDir); + const target = resolve(base, repoSlug, filePath); + return target === base || target.startsWith(base + sep) ? target : undefined; +} + +/** A running dev SCM server. `rootDir` is the writable copy it serves. */ +export interface DevScmServer { + /** Origin to build catalog locations from, e.g. `http://127.0.0.1:7008`. */ + url: string; + rootDir: string; + close(): Promise; +} + +const RAW_PATH = + /^\/rest\/api\/1\.0\/projects\/([^/]+)\/repos\/([^/]+)\/raw\/(.+)$/; + +/** + * Serve a throwaway copy of `sourceDir` over HTTP, so the dev catalog's + * entities get a `url:` `managed-by-location` that an SCM provider can route. + * + * The copy is recreated on every start: a previous run's demo writes the fixed + * owner back into it, and a second `yarn start` reading those would find + * nothing left to flag. + */ +export async function startDevScmServer(opts: { + sourceDir: string; + port: number; +}): Promise { + // Named after the port, not randomised: the port is the server's identity + // (two of these cannot run at once anyway), and a predictable path is what + // lets you `cat` the served file while walking a case. + const rootDir = join(tmpdir(), `ownership-matcher-dev-catalog-${opts.port}`); + await rm(rootDir, { recursive: true, force: true }); + await cp(opts.sourceDir, rootDir, { recursive: true }); + + const server = createServer((req, res) => { + void serve(rootDir, req.url ?? '', res); + }); + + const port = await listen(server, opts.port); + + return { + url: `http://127.0.0.1:${port}`, + rootDir, + close: () => new Promise(done => server.close(() => done())), + }; +} + +async function serve( + rootDir: string, + url: string, + res: ServerResponse, +): Promise { + const match = RAW_PATH.exec(url.split('?')[0]); + let file: string | undefined; + if (match && decodeSegment(match[1]) === DEV_PROJECT_KEY) { + const repoSlug = decodeSegment(match[2]); + const filePath = decodeSegment(match[3]); + if (repoSlug !== undefined && filePath !== undefined) { + file = repoFilePath(rootDir, repoSlug, filePath); + } + } + + const content = file + ? await readFile(file, 'utf8').catch(() => undefined) + : undefined; + if (content === undefined) { + res.writeHead(404, { 'content-type': 'text/plain' }); + res.end('not found'); + return; + } + res.writeHead(200, { 'content-type': 'text/plain; charset=utf-8' }); + res.end(content); +} + +function decodeSegment(value: string): string | undefined { + try { + return decodeURIComponent(value); + } catch { + return undefined; + } +} + +function listen(server: Server, port: number): Promise { + return new Promise((ok, fail) => { + server.once('error', (err: NodeJS.ErrnoException) => { + fail( + err.code === 'EADDRINUSE' + ? new Error( + `The dev SCM server cannot bind 127.0.0.1:${port} — something already holds it. ` + + `Find it with: lsof -nP -iTCP:${port} -sTCP:LISTEN`, + { cause: err }, + ) + : err, + ); + }); + server.listen(port, '127.0.0.1', () => { + const address = server.address(); + ok(typeof address === 'object' && address ? address.port : port); + }); + }); +} diff --git a/workspaces/ownership-matcher/packages/backend/src/index.ts b/workspaces/ownership-matcher/packages/backend/src/index.ts new file mode 100644 index 0000000..7a468c8 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/index.ts @@ -0,0 +1,102 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * Development backend for ownership-matcher, started by the workspace's + * `yarn start` (scripts/start.js -> `backstage-cli repo start`). + * + * It runs the plugin against the sample catalog in the workspace's examples/ + * directory, with guest sign-in and an allow-all permission policy, and uses + * the Postgres from the workspace's docker-compose.yml. Configuration lives in the workspace's app-config.yaml. See its README. + * + * The catalog is not read off disk: a throwaway copy of examples/ is served + * over HTTP first, so every component gets a `url:` managed-by-location that + * the dev SCM provider below can route. That provider is what gives + * top-contributor commits to score and turns an accepted proposal into a pull + * request that merges itself back into the served copy. + */ + +import { createBackend } from '@backstage/backend-defaults'; +import { resolvePackagePath } from '@backstage/backend-plugin-api'; +import { DEV_SCM_PORT, startDevScmServer } from './devScmServer'; +import { createDevScmModule } from './scm/module'; + +/** + * How long a dev pull request stays open before it merges itself. + * + * Zero on purpose. One deadline-checker sweep raises the PR and reconciles it + * in the same pass, so a PR with any delay at all is still open at its only + * reconciliation — and `PR_RECONCILE_INTERVAL_MS` then puts the next check an + * hour out, which strands the case in `accepted`. Merging immediately lets a + * single sweep close the loop. Raise this to watch the open state in the UI, + * and expect to wait out that hour. + */ +const MERGE_AFTER_MS = 0; + +async function main() { + // Must be up before the backend starts: the catalog reads its root location + // from this server during initialisation. + const catalog = await startDevScmServer({ + // Not `__dirname`: it moves between dev and a bundled build. This package + // sits at /packages/backend, so the sample catalog is two up. + sourceDir: resolvePackagePath('backend', '..', '..', 'examples'), + port: DEV_SCM_PORT, + }); + console.log(`[dev] serving the example catalog on ${catalog.url}`); + + const backend = createBackend(); + + backend.add(import('@backstage/plugin-auth-backend')); + backend.add(import('@backstage/plugin-auth-backend-module-guest-provider')); + + backend.add(import('@backstage/plugin-catalog-backend')); + backend.add(import('@backstage/plugin-events-backend')); + + backend.add(import('@backstage/plugin-permission-backend')); + backend.add( + import('@backstage/plugin-permission-backend-module-allow-all-policy'), + ); + + backend.add(import('@backstage/plugin-notifications-backend')); + backend.add(import('@backstage/plugin-signals-backend')); + + backend.add( + import('@stepstone-tech/backstage-plugin-ownership-matcher-backend'), + ); + backend.add( + createDevScmModule({ + rootDir: catalog.rootDir, + host: new URL(catalog.url).host, + mergeAfterMs: MERGE_AFTER_MS, + }), + ); + // The Bitbucket Server and MS Graph e-mail modules need real credentials, so + // they are not installed here. To try one, configure it in the workspace's + // app-config.local.yaml (gitignored, loaded by `yarn start`), add the package + // to this package.json and install it: + // backend.add( + // import( + // '@stepstone-tech/backstage-plugin-ownership-matcher-backend-module-bitbucket-server' + // ), + // ); + + backend.start(); +} + +main().catch(error => { + console.error(error); + process.exit(1); +}); diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.test.ts b/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.test.ts new file mode 100644 index 0000000..667d640 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.test.ts @@ -0,0 +1,210 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { mkdtemp, mkdir, readFile, writeFile } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { + isScmError, + type ScmRepoRef, +} from '@stepstone-tech/backstage-plugin-ownership-matcher-node'; +import { MockPrStore } from './MockPrStore'; + +const REPO: ScmRepoRef = { + type: 'gitServer', + host: '127.0.0.1:7008', + path: 'dev/orphaned-service', + webUrl: 'http://127.0.0.1:7008/projects/dev/repos/orphaned-service/browse', +}; + +const ORIGINAL = 'spec:\n owner: unknown\n'; +const FIXED = 'spec:\n owner: group:default/team-example\n'; + +let now = 1_000_000; + +async function makeStore(mergeAfterMs = 60_000) { + const rootDir = await mkdtemp(join(tmpdir(), 'mock-pr-store-')); + await mkdir(join(rootDir, 'orphaned-service'), { recursive: true }); + await writeFile( + join(rootDir, 'orphaned-service', 'catalog-info.yaml'), + ORIGINAL, + 'utf8', + ); + return { + rootDir, + store: new MockPrStore({ rootDir, mergeAfterMs, now: () => now }), + }; +} + +/** Branch, commit and open a PR, the way PrCreationService does. */ +async function raisePr(store: MockPrStore, branch = 'ownership/fix') { + await store.createBranch(REPO, branch, 'main'); + const file = await store.readFile(REPO, 'catalog-info.yaml', branch); + await store.commitFile(REPO, 'catalog-info.yaml', { + content: FIXED, + message: 'set owner', + branch, + revision: file!.revision, + }); + return store.createPullRequest(REPO, { + title: 'Set owner', + description: 'why', + fromBranch: branch, + toBranch: 'main', + }); +} + +describe('MockPrStore', () => { + beforeEach(() => { + now = 1_000_000; + }); + + it('reads a file from rootDir with a revision', async () => { + const { store } = await makeStore(); + + const file = await store.readFile(REPO, 'catalog-info.yaml', 'main'); + + expect(file?.content).toBe(ORIGINAL); + expect(file?.revision).toEqual(expect.any(String)); + await expect( + store.readFile(REPO, 'nope.yaml', 'main'), + ).resolves.toBeUndefined(); + }); + + it('reports the default branch and an unknown repo', async () => { + const { store } = await makeStore(); + + await expect(store.getDefaultBranch(REPO)).resolves.toBe('main'); + await expect(store.createBranch(REPO, 'b', 'main')).resolves.toBe( + 'created', + ); + await expect(store.createBranch(REPO, 'b', 'main')).resolves.toBe('exists'); + }); + + it('commitFile with a stale revision throws ScmError kind conflict', async () => { + const { store } = await makeStore(); + await store.createBranch(REPO, 'b', 'main'); + + const failure = await store + .commitFile(REPO, 'catalog-info.yaml', { + content: FIXED, + message: 'set owner', + branch: 'b', + revision: 'stale', + }) + .catch(err => err); + + expect(isScmError(failure)).toBe(true); + expect(failure.kind).toBe('conflict'); + }); + + it('rejects a commit path that escapes rootDir', async () => { + const { store } = await makeStore(); + await store.createBranch(REPO, 'b', 'main'); + + const failure = await store + .commitFile(REPO, '../../../etc/passwd', { + content: 'pwned', + message: 'nope', + branch: 'b', + }) + .catch(err => err); + + expect(isScmError(failure)).toBe(true); + expect(failure.kind).toBe('invalid'); + }); + + it('createPullRequest returns created, then reused for the same source branch', async () => { + const { store } = await makeStore(); + + const first = await raisePr(store); + const second = await store.createPullRequest(REPO, { + title: 'Set owner', + description: 'why', + fromBranch: 'ownership/fix', + toBranch: 'main', + }); + + expect(first.status).toBe('created'); + expect(second.status).toBe('reused'); + expect(second.pr.id).toBe(first.pr.id); + await expect( + store.findOpenPullRequest(REPO, 'ownership/fix'), + ).resolves.toEqual(first.pr); + }); + + it('getPullRequest reports open before mergeAfterMs and merged after', async () => { + const { store } = await makeStore(60_000); + const { pr } = await raisePr(store); + + now += 59_000; + await expect(store.getPullRequest(REPO, pr.id)).resolves.toMatchObject({ + state: 'open', + }); + + now += 2_000; + const merged = await store.getPullRequest(REPO, pr.id); + + expect(merged?.state).toBe('merged'); + expect(merged?.closedAt).toBeInstanceOf(Date); + await expect( + store.findOpenPullRequest(REPO, 'ownership/fix'), + ).resolves.toBeUndefined(); + }); + + it('merging writes the branch content back into rootDir', async () => { + const { store, rootDir } = await makeStore(60_000); + const { pr } = await raisePr(store); + const onDisk = () => + readFile(join(rootDir, 'orphaned-service', 'catalog-info.yaml'), 'utf8'); + + await expect(onDisk()).resolves.toBe(ORIGINAL); + + now += 61_000; + await store.getPullRequest(REPO, pr.id); + + await expect(onDisk()).resolves.toBe(FIXED); + }); + + it('resolves reviewers without a directory', async () => { + const { store } = await makeStore(); + + await expect( + store.resolveReviewer(REPO, 'alice@example.com'), + ).resolves.toBe('alice@example.com'); + await expect( + store.getDefaultReviewers(REPO, { fromBranch: 'b', toBranch: 'main' }), + ).resolves.toEqual([]); + }); + + it('updates an open pull request only when something differs', async () => { + const { store } = await makeStore(); + const { pr } = await raisePr(store); + + await expect( + store.updatePullRequest(REPO, pr, { + title: 'Set owner', + description: 'why', + }), + ).resolves.toBe('unchanged'); + await expect( + store.updatePullRequest(REPO, pr, { + title: 'Set owner (updated)', + description: 'why', + }), + ).resolves.toBe('updated'); + }); +}); diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.ts b/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.ts new file mode 100644 index 0000000..c4ddd89 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/MockPrStore.ts @@ -0,0 +1,290 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createHash } from 'node:crypto'; +import { mkdir, readFile, writeFile } from 'node:fs/promises'; +import { dirname } from 'node:path'; +import { + ScmError, + type ScmFile, + type ScmPullRequest, + type ScmPullRequestCapability, + type ScmPullRequestRef, + type ScmRepoRef, +} from '@stepstone-tech/backstage-plugin-ownership-matcher-node'; +import { repoFilePath } from '../devScmServer'; +import { repoSlugOf } from './MockScmProvider'; + +/** The only branch that exists on disk. Everything else lives in memory. */ +const DEFAULT_BRANCH = 'main'; + +/** @see MockPrStore */ +export interface MockPrStoreOptions { + /** The dev SCM server's writable copy. Merges land here. */ + rootDir: string; + /** How long a pull request stays open before it merges itself. */ + mergeAfterMs: number; + /** Injectable clock, so the merge delay can be stepped through in tests. */ + now?: () => number; +} + +interface MockedPullRequest extends ScmPullRequestRef { + repo: ScmRepoRef; + fromBranch: string; + toBranch: string; + title: string; + description: string; + reviewers: string[]; + createdAt: Date; + state: 'open' | 'merged'; + closedAt?: Date; +} + +/** + * Pull requests that live in memory and merge themselves after a delay. + * + * The point of the delay is that the merge is not simulated: when it fires, + * the branch's content is written over the file in the served copy of + * `examples/`, the catalog re-reads it, and the case closes as + * `ownership_changed` for the same reason it would against a real SCM. + */ +export class MockPrStore implements ScmPullRequestCapability { + /** `#` → path → content. The default branch is not in here; it is on disk. */ + private readonly branches = new Map>(); + private readonly pullRequests = new Map(); + private readonly now: () => number; + private nextId = 1; + + constructor(private readonly options: MockPrStoreOptions) { + this.now = options.now ?? Date.now; + } + + async getDefaultBranch(_repo: ScmRepoRef): Promise { + return DEFAULT_BRANCH; + } + + async readFile( + repo: ScmRepoRef, + path: string, + branch: string, + ): Promise { + const onBranch = this.branches.get(branchKey(repo, branch))?.get(path); + if (onBranch !== undefined) return toFile(onBranch); + + const content = await readFile(this.fileOf(repo, path), 'utf8').catch( + () => undefined, + ); + return content === undefined ? undefined : toFile(content); + } + + async createBranch( + repo: ScmRepoRef, + name: string, + _startPoint: string, + ): Promise<'created' | 'exists'> { + const key = branchKey(repo, name); + if (this.branches.has(key)) return 'exists'; + // Empty: a file not committed on the branch still reads through to disk, + // which is what branching off the default branch means here. + this.branches.set(key, new Map()); + return 'created'; + } + + async commitFile( + repo: ScmRepoRef, + path: string, + opts: { + content: string; + message: string; + branch: string; + revision?: string; + }, + ): Promise { + // Checked before anything else: `path` reaches this from a parsed URL, and + // a merge later writes it straight into the served directory. + this.fileOf(repo, path); + + const current = await this.readFile(repo, path, opts.branch); + if (opts.revision === undefined) { + if (current) { + throw new ScmError( + 'conflict', + `${path} already exists on ${opts.branch}; pass a revision to update it`, + ); + } + } else if (!current) { + throw new ScmError( + 'conflict', + `${path} does not exist on ${opts.branch}`, + ); + } else if (current.revision !== opts.revision) { + throw new ScmError( + 'conflict', + `${path} on ${opts.branch} moved on since revision ${opts.revision}`, + ); + } + + const key = branchKey(repo, opts.branch); + const branch = this.branches.get(key) ?? new Map(); + branch.set(path, opts.content); + this.branches.set(key, branch); + } + + async findOpenPullRequest( + repo: ScmRepoRef, + fromBranch: string, + ): Promise { + for (const pr of this.pullRequests.values()) { + if (pr.repo.path !== repo.path || pr.fromBranch !== fromBranch) continue; + const settled = await this.settle(pr); + if (settled.state === 'open') return { id: pr.id, url: pr.url }; + } + return undefined; + } + + async getPullRequest( + _repo: ScmRepoRef, + id: string, + ): Promise { + const pr = this.pullRequests.get(id); + if (!pr) return undefined; + const settled = await this.settle(pr); + return { + id: settled.id, + url: settled.url, + state: settled.state, + createdAt: settled.createdAt, + ...(settled.closedAt ? { closedAt: settled.closedAt } : {}), + }; + } + + async createPullRequest( + repo: ScmRepoRef, + opts: { + title: string; + description: string; + fromBranch: string; + toBranch: string; + reviewers?: string[]; + }, + ): Promise<{ status: 'created' | 'reused'; pr: ScmPullRequestRef }> { + const existing = await this.findOpenPullRequest(repo, opts.fromBranch); + if (existing) return { status: 'reused', pr: existing }; + + const id = String(this.nextId++); + const pr: MockedPullRequest = { + id, + url: `${repo.webUrl.replace(/\/browse$/, '')}/pull-requests/${id}`, + repo, + fromBranch: opts.fromBranch, + toBranch: opts.toBranch, + title: opts.title, + description: opts.description, + reviewers: [...(opts.reviewers ?? [])], + createdAt: new Date(this.now()), + state: 'open', + }; + this.pullRequests.set(id, pr); + return { status: 'created', pr: { id: pr.id, url: pr.url } }; + } + + async updatePullRequest( + _repo: ScmRepoRef, + ref: ScmPullRequestRef, + desired: { title: string; description: string; addReviewers?: string[] }, + ): Promise<'updated' | 'unchanged'> { + const pr = this.pullRequests.get(ref.id); + if (!pr) throw new ScmError('not-found', `No pull request ${ref.id}`); + + const added = (desired.addReviewers ?? []).filter( + r => !pr.reviewers.includes(r), + ); + if ( + pr.title === desired.title && + pr.description === desired.description && + added.length === 0 + ) { + return 'unchanged'; + } + pr.title = desired.title; + pr.description = desired.description; + pr.reviewers.push(...added); + return 'updated'; + } + + /** No user directory here: the e-mail address is the reviewer id. */ + async resolveReviewer( + _repo: ScmRepoRef, + email: string, + ): Promise { + return email; + } + + async getDefaultReviewers( + _repo: ScmRepoRef, + _opts: { fromBranch: string; toBranch: string }, + ): Promise { + return []; + } + + /** Absolute path of `path` in `repo`, or an `invalid` ScmError if it escapes the served copy. */ + private fileOf(repo: ScmRepoRef, path: string): string { + const slug = repoSlugOf(repo.path); + const file = slug + ? repoFilePath(this.options.rootDir, slug, path) + : undefined; + if (!file) { + throw new ScmError( + 'invalid', + `${repo.path}/${path} is not a dev catalog file`, + ); + } + return file; + } + + /** + * Merge the pull request if its delay has elapsed. Called on every read, + * so the state advances exactly when something asks for it — which is what + * `PrReconciliationService` does on its loop. + */ + private async settle(pr: MockedPullRequest): Promise { + if (pr.state !== 'open') return pr; + if (this.now() - pr.createdAt.getTime() < this.options.mergeAfterMs) { + return pr; + } + + const branch = this.branches.get(branchKey(pr.repo, pr.fromBranch)); + for (const [path, content] of branch ?? []) { + const file = this.fileOf(pr.repo, path); + await mkdir(dirname(file), { recursive: true }); + await writeFile(file, content, 'utf8'); + } + pr.state = 'merged'; + pr.closedAt = new Date(this.now()); + return pr; + } +} + +function branchKey(repo: ScmRepoRef, branch: string): string { + return `${repo.path}#${branch}`; +} + +function toFile(content: string): ScmFile { + return { + content, + revision: createHash('sha256').update(content).digest('hex').slice(0, 12), + }; +} diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.test.ts b/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.test.ts new file mode 100644 index 0000000..d273917 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.test.ts @@ -0,0 +1,157 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { mockServices } from '@backstage/backend-test-utils'; +import type { + ScmClient, + ScmProviderContext, +} from '@stepstone-tech/backstage-plugin-ownership-matcher-node'; +import { readFileSync } from 'node:fs'; +import { resolve } from 'node:path'; +import { parseAllDocuments } from 'yaml'; +import { MOCK_SCM_TYPE, MockScmProvider } from './MockScmProvider'; +import { COMMIT_AUTHORS } from './fixtures'; + +const HOST = '127.0.0.1:7008'; + +function makeClient(): ScmClient { + const provider = new MockScmProvider({ + rootDir: '/tmp/does-not-matter', + host: HOST, + mergeAfterMs: 1000, + }); + const ctx = { + integration: { type: MOCK_SCM_TYPE }, + logger: mockServices.logger.mock(), + fetch: globalThis.fetch, + } as unknown as ScmProviderContext; + return provider.createClient(ctx); +} + +describe('MockScmProvider', () => { + it('serves the configured integration type', () => { + expect( + new MockScmProvider({ rootDir: '/tmp', host: HOST, mergeAfterMs: 0 }) + .type, + ).toBe(MOCK_SCM_TYPE); + }); + + it('parses a served catalog-info URL into a repo and path', () => { + const location = makeClient().parseLocation( + `http://${HOST}/projects/dev/repos/orphaned-service/browse/catalog-info.yaml`, + ); + + expect(location).toEqual({ + repo: { + type: MOCK_SCM_TYPE, + host: HOST, + path: 'dev/orphaned-service', + webUrl: `http://${HOST}/projects/dev/repos/orphaned-service/browse`, + }, + path: 'catalog-info.yaml', + }); + }); + + it('returns undefined for a URL on another host', () => { + expect( + makeClient().parseLocation( + 'http://example.com/projects/dev/repos/a/browse/catalog-info.yaml', + ), + ).toBeUndefined(); + }); + + it('returns undefined for a non-catalog-info path', () => { + // org.yaml and root.yaml are served from the same host; they are not + // component locations and must not resolve to a repo. + expect( + makeClient().parseLocation( + `http://${HOST}/projects/dev/repos/root/browse/org.yaml`, + ), + ).toBeUndefined(); + }); + + it('returns undefined for a URL it cannot parse at all', () => { + expect(makeClient().parseLocation('not a url')).toBeUndefined(); + expect( + makeClient().parseLocation(`http://${HOST}/something/else`), + ).toBeUndefined(); + }); +}); + +describe('MockScmProvider history', () => { + const repo = { + type: MOCK_SCM_TYPE, + host: HOST, + path: 'dev/orphaned-service', + webUrl: `http://${HOST}/projects/dev/repos/orphaned-service/browse`, + }; + + it('returns commits for a known repo, newest first, capped at limit', async () => { + const history = makeClient().history!; + expect(history).toBeDefined(); + + const all = await history.getCommits(repo, { limit: 100 }); + const capped = await history.getCommits(repo, { limit: 3 }); + + expect(all.length).toBe(COMMIT_AUTHORS[repo.path].length); + expect(all.map(c => c.author.email)).toEqual( + COMMIT_AUTHORS[repo.path].map(a => a.email), + ); + expect(capped).toEqual(all.slice(0, 3)); + expect(new Set(all.map(c => c.id)).size).toBe(all.length); + }); + + it('returns an empty array for a repo with no fixture', async () => { + await expect( + makeClient().history!.getCommits( + { ...repo, path: 'dev/legacy-batch-job' }, + { limit: 25 }, + ), + ).resolves.toEqual([]); + }); + + it('returns author emails that exist in the sample org', () => { + const orgYaml = readFileSync( + resolve(__dirname, '../../../../examples/root/org.yaml'), + 'utf8', + ); + const userNames = parseAllDocuments(orgYaml) + .map(doc => doc.toJS() as { kind: string; metadata: { name: string } }) + .filter(doc => doc?.kind === 'User') + .map(doc => doc.metadata.name); + + const emails = Object.values(COMMIT_AUTHORS).flatMap(authors => + authors.map(a => a.email), + ); + expect(emails.length).toBeGreaterThan(0); + for (const email of new Set(emails)) { + // ContributorService matches a commit author to a catalog user by the + // local part of the address, so a typo here silently scores nothing. + expect(userNames).toContain(email.split('@')[0]); + } + }); + + it('gives one repo a dominant team and another a two-team spread', () => { + const counts = (path: string) => + new Set(COMMIT_AUTHORS[path].map(a => a.email)).size; + + expect(counts('dev/orphaned-service')).toBeGreaterThan(1); + expect(counts('dev/placeholder-owner-library')).toBeGreaterThan(1); + // The no-commits component is what makes `possible_owner` reachable: + // org-proximity alone scores it 0.3 * 0.6 / (0.5 + 0.3) = 0.225. + expect(COMMIT_AUTHORS['dev/docs-portal']).toBeUndefined(); + }); +}); diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.ts b/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.ts new file mode 100644 index 0000000..018b483 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/MockScmProvider.ts @@ -0,0 +1,148 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { + ScmClient, + ScmCommit, + ScmFileLocation, + ScmHistoryCapability, + ScmProvider, + ScmProviderContext, + ScmRepoRef, +} from '@stepstone-tech/backstage-plugin-ownership-matcher-node'; +import { DEV_PROJECT_KEY } from '../devScmServer'; +import { MockPrStore } from './MockPrStore'; +import { COMMIT_AUTHORS } from './fixtures'; + +/** + * The integration type the dev SCM server's host is configured as. Backstage + * only accepts its built-in integration types, so the mock borrows one; nothing + * here talks to a real server. + */ +export const MOCK_SCM_TYPE = 'bitbucketServer'; + +/** The only file name that is a component's catalog location. */ +const CATALOG_INFO = 'catalog-info.yaml'; + +const BROWSE_PATH = /^\/projects\/([^/]+)\/repos\/([^/]+)\/browse\/(.+)$/; + +/** @see MockScmProvider */ +export interface MockScmProviderOptions { + /** The dev SCM server's writable copy, from `startDevScmServer`. */ + rootDir: string; + /** Host the catalog is served on, e.g. `127.0.0.1:7008`. */ + host: string; + /** How long a pull request stays open before it merges itself. */ + mergeAfterMs: number; +} + +/** + * `http:///projects/dev/repos//browse/catalog-info.yaml` → the + * component's file location. Anything else — another host, `org.yaml`, a + * string that is not a URL at all — is `undefined` rather than an error: the + * same registry resolves users and groups, and a throw there kills the scan. + */ +export function parseDevLocation( + url: string, + host: string, +): ScmFileLocation | undefined { + let parsed: URL; + try { + parsed = new URL(url); + } catch { + return undefined; + } + if (parsed.host !== host) return undefined; + + const match = BROWSE_PATH.exec(parsed.pathname); + if (!match) return undefined; + + let projectKey: string; + let repoSlug: string; + let path: string; + try { + [projectKey, repoSlug, path] = match.slice(1, 4).map(decodeURIComponent); + } catch { + return undefined; + } + if (projectKey !== DEV_PROJECT_KEY || path !== CATALOG_INFO) return undefined; + + return { + repo: { + type: MOCK_SCM_TYPE, + host, + path: `${projectKey}/${repoSlug}`, + webUrl: `${parsed.origin}/projects/${projectKey}/repos/${repoSlug}/browse`, + }, + path, + }; +} + +/** + * Commit history straight out of `fixtures.ts`. A repo with no fixture has no + * commits, which is how a component is kept out of `top-contributor`'s reach. + */ +const mockHistory: ScmHistoryCapability = { + async getCommits( + repo: ScmRepoRef, + opts: { limit: number }, + ): Promise { + const slug = repoSlugOf(repo.path); + const authors = slug ? COMMIT_AUTHORS[repo.path] ?? [] : []; + return authors + .slice(0, opts.limit) + .map((author, index) => ({ id: `${slug}-${index + 1}`, author })); + }, +}; + +/** `dev/orphaned-service` → `orphaned-service`; anything else is not a dev repo. */ +export function repoSlugOf(repoPath: string): string | undefined { + const parts = repoPath.split('/'); + return parts.length === 2 && parts[0] === DEV_PROJECT_KEY && parts[1] + ? parts[1] + : undefined; +} + +/** + * Dev-only SCM provider for the catalog served by `startDevScmServer`. + * + * It registers for `MOCK_SCM_TYPE`, the integration type the served host is + * configured as. No real provider for that type is installed in the dev + * backend, so there is no collision. Nothing here talks to a network: history + * is a fixture and pull requests live in memory. + */ +export class MockScmProvider implements ScmProvider { + readonly type = MOCK_SCM_TYPE; + + /** One store for the whole provider: pull requests must outlive a client. */ + private readonly prStore: MockPrStore; + + constructor(private readonly options: MockScmProviderOptions) { + this.prStore = new MockPrStore({ + rootDir: options.rootDir, + mergeAfterMs: options.mergeAfterMs, + }); + } + + createClient(_ctx: ScmProviderContext): ScmClient { + const { host } = this.options; + return { + parseLocation: url => parseDevLocation(url, host), + history: mockHistory, + pullRequests: this.prStore, + }; + } +} diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/fixtures.ts b/workspaces/ownership-matcher/packages/backend/src/scm/fixtures.ts new file mode 100644 index 0000000..f4291a4 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/fixtures.ts @@ -0,0 +1,63 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** A commit author. The local part of the address must name a User in the workspace's examples/root/org.yaml. */ +export interface CommitAuthor { + email: string; + name: string; +} + +const BOB: CommitAuthor = { email: 'bob@example.com', name: 'Bob Example' }; +const ALICE: CommitAuthor = { + email: 'alice@example.com', + name: 'Alice Example', +}; +const CAROL: CommitAuthor = { + email: 'carol@example.com', + name: 'Carol Example', +}; + +const times = (count: number, author: CommitAuthor): CommitAuthor[] => + Array.from({ length: count }, () => author); + +/** + * Synthetic commit history per repository, newest first, keyed by + * `ScmRepoRef.path`. + * + * `top-contributor` scores a team at its share of the commits, so the shape of + * these lists is what gives the dev app a spread of confidence scores rather + * than one value everywhere. With the default weights (top-contributor 0.5, + * org-proximity 0.3) and a system owner scoring 0.6: + * + * - `orphaned-service` — 8/10 to team-example, which also owns its system: + * (0.5 * 0.8 + 0.3 * 0.6) / 0.8 = 0.725. Well over the 0.4 notification + * threshold, so it reaches `pending` on the user-facing tab. + * - `placeholder-owner-library` — an even split. team-platform owns its + * system, so it lands at 0.5375 (`pending`, admin tab) while team-example + * reaches only 0.3125 (`possible_owner`). The contested case. + * - `etl-pipeline` — all team-data, which also owns its system: 0.85, the + * `pending` proposal on the signed-in user's *second* team. + * - `docs-portal` — deliberately absent: with no commits, org-proximity alone + * scores its system owner 0.225, which is `possible_owner`. + * - `legacy-batch-job` — absent and without a system, so nothing scores it at + * all and the case goes `unresolved`. + */ +export const COMMIT_AUTHORS: Record = { + 'dev/orphaned-service': [...times(8, BOB), ...times(2, ALICE)], + 'dev/placeholder-owner-library': [...times(5, ALICE), ...times(5, BOB)], + 'dev/owned-service': times(4, BOB), + 'dev/etl-pipeline': times(6, CAROL), +}; diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/module.test.ts b/workspaces/ownership-matcher/packages/backend/src/scm/module.test.ts new file mode 100644 index 0000000..deb02a5 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/module.test.ts @@ -0,0 +1,45 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { mockServices, startTestBackend } from '@backstage/backend-test-utils'; +import { ownershipMatcherPlugin } from '@stepstone-tech/backstage-plugin-ownership-matcher-backend'; +import { createDevScmModule } from './module'; +import { MOCK_SCM_TYPE } from './MockScmProvider'; + +describe('createDevScmModule', () => { + it('registers the mock provider with the ownership-matcher plugin', async () => { + const logger = mockServices.logger.mock(); + + await startTestBackend({ + features: [ + ownershipMatcherPlugin, + createDevScmModule({ + rootDir: '/tmp/ownership-matcher-dev-catalog-test', + host: '127.0.0.1:7008', + mergeAfterMs: 1000, + }), + logger.factory, + ], + }); + + expect(logger.info).toHaveBeenCalledWith( + `Ownership-matcher SCM providers: ${MOCK_SCM_TYPE}`, + ); + expect(logger.warn).not.toHaveBeenCalledWith( + expect.stringMatching(/No ownership-matcher SCM provider/), + ); + }); +}); diff --git a/workspaces/ownership-matcher/packages/backend/src/scm/module.ts b/workspaces/ownership-matcher/packages/backend/src/scm/module.ts new file mode 100644 index 0000000..31d38b3 --- /dev/null +++ b/workspaces/ownership-matcher/packages/backend/src/scm/module.ts @@ -0,0 +1,44 @@ +/* + * Copyright 2026 The Stepstone Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createBackendModule } from '@backstage/backend-plugin-api'; +import { ownershipMatcherScmExtensionPoint } from '@stepstone-tech/backstage-plugin-ownership-matcher-node'; +import { + MockScmProvider, + type MockScmProviderOptions, +} from './MockScmProvider'; + +/** + * Registers the dev SCM provider with the ownership-matcher plugin. + * + * A factory rather than a ready-made module, because the provider is bound to + * the dev SCM server's temporary directory and port, which only exist once + * `startDevScmServer` has run. + */ +export function createDevScmModule(options: MockScmProviderOptions) { + return createBackendModule({ + pluginId: 'ownership-matcher', + moduleId: 'dev-scm', + register(env) { + env.registerInit({ + deps: { scm: ownershipMatcherScmExtensionPoint }, + async init({ scm }) { + scm.addProvider(new MockScmProvider(options)); + }, + }); + }, + }); +} diff --git a/workspaces/ownership-matcher/plugins/ownership-matcher-backend/README.md b/workspaces/ownership-matcher/plugins/ownership-matcher-backend/README.md index b237221..bc01e26 100644 --- a/workspaces/ownership-matcher/plugins/ownership-matcher-backend/README.md +++ b/workspaces/ownership-matcher/plugins/ownership-matcher-backend/README.md @@ -98,4 +98,4 @@ Escalation endpoints exist only when `escalation` is configured. The UI uses onl ## Development -Run `yarn start` from the repository root; see the [workspace README](../../README.md#local-development). +Run `yarn start` from the workspace root; see the [workspace README](../../README.md#local-development). diff --git a/workspaces/ownership-matcher/plugins/ownership-matcher-backend/dev/index.ts b/workspaces/ownership-matcher/plugins/ownership-matcher-backend/dev/index.ts deleted file mode 100644 index 74f591e..0000000 --- a/workspaces/ownership-matcher/plugins/ownership-matcher-backend/dev/index.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2026 The Stepstone Group - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Development backend for ownership-matcher, started with `yarn start` at the - * repository root (`backstage-cli repo start --plugin ownership-matcher`). - * - * It runs the plugin against the sample catalog in the workspace's examples/ - * directory, with guest sign-in and an allow-all permission policy, and uses - * the Postgres from the workspace's docker-compose.yml. Configuration lives in - * workspaces/ownership-matcher/app-config.yaml. See the workspace README. - */ - -import { createBackend } from '@backstage/backend-defaults'; - -const backend = createBackend(); - -backend.add(import('@backstage/plugin-auth-backend')); -backend.add(import('@backstage/plugin-auth-backend-module-guest-provider')); - -backend.add(import('@backstage/plugin-catalog-backend')); -backend.add(import('@backstage/plugin-events-backend')); - -backend.add(import('@backstage/plugin-permission-backend')); -backend.add( - import('@backstage/plugin-permission-backend-module-allow-all-policy'), -); - -backend.add(import('@backstage/plugin-notifications-backend')); -backend.add(import('@backstage/plugin-signals-backend')); - -backend.add(import('../src')); -// The Bitbucket Server and MS Graph e-mail modules need real credentials, so -// they are not installed here. To try one, configure it in the workspace's -// app-config.local.yaml (gitignored, loaded by `yarn start`) and add it with a -// relative import, since the modules depend on this package and not the other -// way round: -// backend.add( -// import('../../ownership-matcher-backend-module-bitbucket-server/src'), -// ); - -backend.start(); diff --git a/workspaces/ownership-matcher/plugins/ownership-matcher/package.json b/workspaces/ownership-matcher/plugins/ownership-matcher/package.json index aa4d570..65d1af6 100644 --- a/workspaces/ownership-matcher/plugins/ownership-matcher/package.json +++ b/workspaces/ownership-matcher/plugins/ownership-matcher/package.json @@ -66,11 +66,7 @@ }, "devDependencies": { "@backstage/cli": "^0.36.6", - "@backstage/dev-utils": "^1.1.27", - "@backstage/frontend-dev-utils": "^0.1.6", "@backstage/plugin-catalog": "^2.0.9", - "@backstage/plugin-notifications": "^0.6.0", - "@backstage/plugin-org": "^0.7.9", "@backstage/plugin-signals": "^0.0.35", "@backstage/test-utils": "^1.7.22", "@testing-library/dom": "^10.0.0", diff --git a/workspaces/ownership-matcher/plugins/ownership-matcher/src/alpha.tsx b/workspaces/ownership-matcher/plugins/ownership-matcher/src/alpha.tsx index 7504369..383d184 100644 --- a/workspaces/ownership-matcher/plugins/ownership-matcher/src/alpha.tsx +++ b/workspaces/ownership-matcher/plugins/ownership-matcher/src/alpha.tsx @@ -21,6 +21,8 @@ import { FrontendPlugin, } from '@backstage/frontend-plugin-api'; import { discoveryApiRef, fetchApiRef } from '@backstage/core-plugin-api'; +import AssignmentIndIcon from '@material-ui/icons/AssignmentInd'; +import GroupAddIcon from '@material-ui/icons/GroupAdd'; import { compatWrapper, convertLegacyRouteRef, @@ -46,6 +48,8 @@ export const ownershipMatcherApi = ApiBlueprint.make({ export const ownershipMatcherPage = PageBlueprint.make({ params: { path: '/ownership-matcher', + title: 'Ownership Matcher', + icon: , // Child pages render their own /
; suppress the redundant // new-frontend PluginHeader. noHeader: true, @@ -67,6 +71,8 @@ export const userOwnershipPage = PageBlueprint.make({ name: 'user-proposals', params: { path: '/my-ownership-proposals', + title: 'My Ownership Proposals', + icon: , // Component renders its own /
; suppress the redundant // new-frontend PluginHeader. noHeader: true, diff --git a/scripts/start.js b/workspaces/ownership-matcher/scripts/start.js similarity index 52% rename from scripts/start.js rename to workspaces/ownership-matcher/scripts/start.js index fc83052..3acd6aa 100644 --- a/scripts/start.js +++ b/workspaces/ownership-matcher/scripts/start.js @@ -16,40 +16,22 @@ */ /* - * Local development for one workspace: `yarn start [workspace]`. + * `yarn start` for this workspace. * - * Starts the workspace's Postgres (workspaces//docker-compose.yml, if - * present), then the dev/ entry points of its plugins with - * `backstage-cli repo start --plugin `, using the workspace's - * app-config.yaml and, if it exists, app-config.local.yaml. Passing --config - * turns off Backstage's own app-config.local.yaml lookup, so it's added here. + * Starts the workspace's Postgres (docker-compose.yml), then packages/app and + * packages/backend with `backstage-cli repo start`, using this workspace's + * app-config.yaml and, if it exists, app-config.local.yaml. * - * The workspace name doubles as the plugin ID that --plugin matches. With a - * single workspace the argument can be left out. + * The wrapper exists for two reasons: ownership-matcher's migrations use + * Postgres-only features, so the database has to be up first; and passing + * --config turns off Backstage's own app-config.local.yaml lookup, so it has to + * be added back here by absolute path. */ const { spawnSync, spawn } = require('node:child_process'); const fs = require('node:fs'); const path = require('node:path'); -const root = path.resolve(__dirname, '..'); -const workspacesDir = path.join(root, 'workspaces'); -const available = fs - .readdirSync(workspacesDir, { withFileTypes: true }) - .filter(entry => entry.isDirectory()) - .map(entry => entry.name); - -const workspace = - process.argv[2] ?? (available.length === 1 ? available[0] : undefined); -if (!workspace || !available.includes(workspace)) { - console.error( - `Usage: yarn start \nAvailable workspaces: ${available.join( - ', ', - )}`, - ); - process.exit(1); -} - -const workspaceDir = path.join(workspacesDir, workspace); +const workspaceDir = path.resolve(__dirname, '..'); const composeFile = path.join(workspaceDir, 'docker-compose.yml'); if (fs.existsSync(composeFile)) { @@ -68,11 +50,10 @@ const configArgs = ['app-config.yaml', 'app-config.local.yaml'] .filter(file => fs.existsSync(file)) .flatMap(file => ['--config', file]); -const child = spawn( - 'yarn', - ['backstage-cli', 'repo', 'start', '--plugin', workspace, ...configArgs], - { cwd: root, stdio: 'inherit' }, -); +const child = spawn('yarn', ['backstage-cli', 'repo', 'start', ...configArgs], { + cwd: workspaceDir, + stdio: 'inherit', +}); for (const signal of ['SIGINT', 'SIGTERM']) { process.on(signal, () => child.kill(signal)); } diff --git a/yarn.lock b/yarn.lock index adbfcc2..ead7c96 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1425,30 +1425,6 @@ __metadata: languageName: node linkType: hard -"@backstage/app-defaults@npm:^1.7.12": - version: 1.7.12 - resolution: "@backstage/app-defaults@npm:1.7.12" - dependencies: - "@backstage/core-app-api": "npm:^1.20.5" - "@backstage/core-components": "npm:^0.18.14" - "@backstage/core-plugin-api": "npm:^1.12.10" - "@backstage/frontend-plugin-api": "npm:^0.18.1" - "@backstage/plugin-permission-react": "npm:^0.5.5" - "@backstage/theme": "npm:^0.7.3" - "@material-ui/core": "npm:^4.12.2" - "@material-ui/icons": "npm:^4.9.1" - peerDependencies: - "@types/react": ^17.0.0 || ^18.0.0 - react: ^17.0.0 || ^18.0.0 - react-dom: ^17.0.0 || ^18.0.0 - react-router-dom: ^6.30.2 - peerDependenciesMeta: - "@types/react": - optional: true - checksum: 10/aaccea07f53ed1ddd5900ba7123fa6e61a477f2ddf190b2cb7c437aee62c098417db434be1c1a403febef72e16327522595fefe21f61bb4ac19066c9f44ca8c4 - languageName: node - linkType: hard - "@backstage/backend-app-api@npm:^1.7.4": version: 1.7.4 resolution: "@backstage/backend-app-api@npm:1.7.4" @@ -2300,34 +2276,6 @@ __metadata: languageName: node linkType: hard -"@backstage/dev-utils@npm:^1.1.27": - version: 1.1.27 - resolution: "@backstage/dev-utils@npm:1.1.27" - dependencies: - "@backstage/app-defaults": "npm:^1.7.12" - "@backstage/catalog-model": "npm:^1.10.1" - "@backstage/core-app-api": "npm:^1.20.5" - "@backstage/core-components": "npm:^0.18.14" - "@backstage/core-plugin-api": "npm:^1.12.10" - "@backstage/integration-react": "npm:^1.2.22" - "@backstage/plugin-catalog-react": "npm:^3.2.3" - "@backstage/theme": "npm:^0.7.3" - "@backstage/ui": "npm:^0.18.0" - "@material-ui/core": "npm:^4.12.2" - "@material-ui/icons": "npm:^4.9.1" - react-use: "npm:^17.2.4" - peerDependencies: - "@types/react": ^17.0.0 || ^18.0.0 - react: ^17.0.0 || ^18.0.0 - react-dom: ^17.0.0 || ^18.0.0 - react-router-dom: ^6.30.2 - peerDependenciesMeta: - "@types/react": - optional: true - checksum: 10/7254e81d47aa1ea0e0875cf610fe13288e4188935596618608845c2ec83276b2381e7e7972b56c8e18f95d1df87d734df0e503d8f877212ad5047c341854936d - languageName: node - linkType: hard - "@backstage/errors@npm:^1.3.1, @backstage/errors@npm:^1.3.2": version: 1.3.2 resolution: "@backstage/errors@npm:1.3.2" @@ -2423,26 +2371,6 @@ __metadata: languageName: node linkType: hard -"@backstage/frontend-dev-utils@npm:^0.1.6": - version: 0.1.6 - resolution: "@backstage/frontend-dev-utils@npm:0.1.6" - dependencies: - "@backstage/frontend-defaults": "npm:^0.5.6" - "@backstage/frontend-plugin-api": "npm:^0.18.1" - "@backstage/plugin-app": "npm:^0.5.3" - "@backstage/ui": "npm:^0.18.0" - peerDependencies: - "@types/react": ^17.0.0 || ^18.0.0 - react: ^17.0.0 || ^18.0.0 - react-dom: ^17.0.0 || ^18.0.0 - react-router-dom: ^6.30.2 - peerDependenciesMeta: - "@types/react": - optional: true - checksum: 10/76861bcee2f805aa95dda34a2c595cfa3df45937fb042997bf2a5e26ee21b364954ec6a66b12c76ea5d9573173abb11f0c3f112d50d601fd4ee9feb6989009e3 - languageName: node - linkType: hard - "@backstage/frontend-plugin-api@npm:^0.18.1, @backstage/frontend-plugin-api@npm:^0.18.2": version: 0.18.2 resolution: "@backstage/frontend-plugin-api@npm:0.18.2" @@ -4432,6 +4360,15 @@ __metadata: languageName: node linkType: hard +"@internal/ownership-matcher@workspace:workspaces/ownership-matcher": + version: 0.0.0-use.local + resolution: "@internal/ownership-matcher@workspace:workspaces/ownership-matcher" + dependencies: + "@backstage/cli": "npm:^0.36.6" + "@backstage/cli-defaults": "npm:^0.1.6" + languageName: unknown + linkType: soft + "@internationalized/date@npm:^3.12.0, @internationalized/date@npm:^3.12.1, @internationalized/date@npm:^3.12.4": version: 3.12.4 resolution: "@internationalized/date@npm:3.12.4" @@ -7535,7 +7472,7 @@ __metadata: languageName: unknown linkType: soft -"@stepstone-tech/backstage-plugin-ownership-matcher@workspace:workspaces/ownership-matcher/plugins/ownership-matcher": +"@stepstone-tech/backstage-plugin-ownership-matcher@workspace:^, @stepstone-tech/backstage-plugin-ownership-matcher@workspace:workspaces/ownership-matcher/plugins/ownership-matcher": version: 0.0.0-use.local resolution: "@stepstone-tech/backstage-plugin-ownership-matcher@workspace:workspaces/ownership-matcher/plugins/ownership-matcher" dependencies: @@ -7544,13 +7481,9 @@ __metadata: "@backstage/core-compat-api": "npm:^0.5.15" "@backstage/core-components": "npm:^0.18.14" "@backstage/core-plugin-api": "npm:^1.12.10" - "@backstage/dev-utils": "npm:^1.1.27" - "@backstage/frontend-dev-utils": "npm:^0.1.6" "@backstage/frontend-plugin-api": "npm:^0.18.1" "@backstage/plugin-catalog": "npm:^2.0.9" "@backstage/plugin-catalog-react": "npm:^3.2.3" - "@backstage/plugin-notifications": "npm:^0.6.0" - "@backstage/plugin-org": "npm:^0.7.9" "@backstage/plugin-permission-common": "npm:^0.9.11" "@backstage/plugin-permission-react": "npm:^0.5.5" "@backstage/plugin-signals": "npm:^0.0.35" @@ -8463,6 +8396,15 @@ __metadata: languageName: node linkType: hard +"@types/react-dom@npm:^18": + version: 18.3.7 + resolution: "@types/react-dom@npm:18.3.7" + peerDependencies: + "@types/react": ^18.0.0 + checksum: 10/317569219366d487a3103ba1e5e47154e95a002915fdcf73a44162c48fe49c3a57fcf7f57fc6979e70d447112681e6b13c6c3c1df289db8b544df4aab2d318f3 + languageName: node + linkType: hard + "@types/react-redux@npm:^7.1.20": version: 7.1.34 resolution: "@types/react-redux@npm:7.1.34" @@ -10115,6 +10057,31 @@ __metadata: languageName: node linkType: hard +"app@workspace:workspaces/ownership-matcher/packages/app": + version: 0.0.0-use.local + resolution: "app@workspace:workspaces/ownership-matcher/packages/app" + dependencies: + "@backstage/cli": "npm:^0.36.6" + "@backstage/core-components": "npm:^0.18.14" + "@backstage/frontend-defaults": "npm:^0.5.6" + "@backstage/frontend-plugin-api": "npm:^0.18.1" + "@backstage/plugin-app-react": "npm:^0.2.8" + "@backstage/plugin-catalog": "npm:^2.0.9" + "@backstage/plugin-notifications": "npm:^0.6.0" + "@backstage/plugin-org": "npm:^0.7.9" + "@backstage/plugin-signals": "npm:^0.0.35" + "@backstage/ui": "npm:^0.18.0" + "@material-ui/core": "npm:^4.9.13" + "@material-ui/icons": "npm:^4.9.1" + "@stepstone-tech/backstage-plugin-ownership-matcher": "workspace:^" + "@types/react": "npm:^18.0.0" + "@types/react-dom": "npm:^18.0.0" + react: "npm:^18.0.2" + react-dom: "npm:^18.0.2" + react-router-dom: "npm:^6.21.1" + languageName: unknown + linkType: soft + "append-field@npm:^1.0.0": version: 1.0.0 resolution: "append-field@npm:1.0.0" @@ -10608,6 +10575,29 @@ __metadata: languageName: node linkType: hard +"backend@workspace:workspaces/ownership-matcher/packages/backend": + version: 0.0.0-use.local + resolution: "backend@workspace:workspaces/ownership-matcher/packages/backend" + dependencies: + "@backstage/backend-defaults": "npm:^0.18.0" + "@backstage/backend-plugin-api": "npm:^1.10.1" + "@backstage/backend-test-utils": "npm:^1.11.7" + "@backstage/cli": "npm:^0.36.6" + "@backstage/plugin-auth-backend": "npm:^0.30.1" + "@backstage/plugin-auth-backend-module-guest-provider": "npm:^0.2.23" + "@backstage/plugin-catalog-backend": "npm:^4.0.0" + "@backstage/plugin-events-backend": "npm:^0.6.6" + "@backstage/plugin-notifications-backend": "npm:^0.6.9" + "@backstage/plugin-permission-backend": "npm:^0.7.16" + "@backstage/plugin-permission-backend-module-allow-all-policy": "npm:^0.2.23" + "@backstage/plugin-signals-backend": "npm:^0.3.19" + "@stepstone-tech/backstage-plugin-ownership-matcher-backend": "workspace:^" + "@stepstone-tech/backstage-plugin-ownership-matcher-node": "workspace:^" + pg: "npm:^8.11.3" + yaml: "npm:^2.8.2" + languageName: unknown + linkType: soft + "backo2@npm:^1.0.2": version: 1.0.2 resolution: "backo2@npm:1.0.2"