finos / finos/architecture-as-code

Unreferenced nodes declared as prefixItems alternatives are never reported

Closed
#3,069 0 comments 0 reactions 1 assignee Claimed by @YoofiTT96 View on GitHub
Dominant language
TypeScript
Stars
399
Forks
138
Avg merge
2d 14h
Merged PRs (30d)
37

Description

## Bug Report

`pattern-nodes-must-be-referenced` warns when a pattern declares a node that no relationship and no decision names. Such a node can never appear in an architecture, so it is either unfinished work or a leftover.

Its selector reads bare `prefixItems` entries only:

```
$.properties.nodes.prefixItems[*].properties.unique-id.const
```

A node declared inside `prefixItems[i].oneOf` or `prefixItems[i].anyOf` has its `unique-id` one level deeper, so the selector never reaches it. The rule cannot warn about an alternative, whatever its state.

### Steps to Reproduce:
1. Write a pattern with `webapp` and `database` connected, plus one `prefixItems` entry holding the alternatives `redis` and `memcached`.
2. Do not reference either alternative from any relationship or decision.
3. Run `calm validate`.

### Expected Result:
A warning for `redis` and one for `memcached`, as the rule already gives for an unreferenced bare node.

### Actual Result:
Nothing is reported.

| Declaration | Warns today |
|---|---|
| a bare `prefixItems` entry | yes |
| an alternative in `prefixItems[i].oneOf` or `.anyOf` | no |

### Note
A decision references its alternatives through `choices[].nodes`, which sits under `relationship-type`, and the rule's function reads every string under `relationship-type`. So an alternative that a decision offers is already counted as referenced. Widening the selector therefore warns only about an alternative that nothing offers and nothing connects.

### Environment:
`shared` (`@finos/calm-shared`), `src/spectral/rules-pattern.ts`. Reproduced on `main` at `0034591f`.

### Additional Context:
Found while scoping #2859. It is a defect in the `prefixItems` model and needs no `items` catalog to reproduce, so it is filed and fixed separately from that work.

The fix is `warn` severity and can add a warning to a pattern that is clean today. No pattern in this repository is affected.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.