finos / finos/architecture-as-code
Interfaces on a prefixItems alternative are never checked, and interfaces are pooled across alternatives
- Dominant language
- TypeScript
- Stars
- 399
- Forks
- 138
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 37
Description
## Bug Report
A `prefixItems` entry can hold a `oneOf` or an `anyOf` array. Each entry in that array is an alternative, and each alternative is a node.
`interface-id-exists-on-node` builds its list of nodes from `$.properties.nodes.prefixItems[*]`. That query returns the entry, not the alternatives inside it. The rule then does two things wrong.
It identifies the entry by the first alternative's `unique-id`. A reference to any other alternative matches nothing, so the rule returns early and checks nothing.
For the first alternative it does match, it gathers interfaces from every alternative in the entry. The interfaces are pooled, so a reference to one alternative can name an interface that belongs to another and pass.
### Steps to Reproduce:
1. Write a pattern with one `prefixItems` entry holding two alternatives. Give `cache` the interface `port-a` and `queue` the interface `port-b`.
2. Add a connects relationship from `webapp` to `cache`, asking for interface `port-b`.
3. Run `calm validate`.
### Expected Result:
An error. `port-b` belongs to `queue`, not to `cache`.
### Actual Result:
No error. The same silence occurs for every combination:
| Relationship asks for | Result today |
|---|---|
| `cache` interface `port-a` (correct) | no message |
| `cache` interface `port-b` (wrong) | no message |
| `queue` interface `port-b` (correct) | no message |
| `queue` interface `port-a` (wrong) | no message |
No alternative in an entry is checked at all.
### Fix
Build the node list from individual alternatives rather than from the entry. Each alternative then carries its own id and its own interfaces, so the pooling and the first-alternative match both disappear.
### Environment:
`shared` (`@finos/calm-shared`), `src/spectral/functions/pattern/interface-id-exists-on-node.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.
This fix can reject a pattern that `calm validate` accepts today. No pattern in this repository is affected.
Contributor guide
Assessment
This issue has not been assessed yet.