CLI sorts Feature options fewest-first, against spec

Aperta Adatta ai principianti
#755 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
typescript
Ambito
cli

Direzione di ricerca

Inizia in devcontainers/cli, in src/spec-configuration/containerFeaturesOrder.ts, concentrandoti su optionsCompareTo e sull’ordinamento in base al numero di opzioni. Esegui il test esistente per l’ordine dei container-features in src/test/container-features/containerFeaturesOrder.test.ts con il fixture configs/feature-dependencies/dependsOn/local-with-options, quindi aggiorna l’ordine previsto in modo che il maggior numero di opzioni definite dall’utente venga prima.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Note on repo choice: Per the devcontainers/cli CONTRIBUTING guide, issues concerning the CLI should be filed in this spec repository, so I've opened it here even though it's about devcontainers/cli behavior. Please let me know if you'd prefer it moved to the devcontainers/cli repo instead.

Summary

When sorting Features within an installation round, the spec says Features are ordered by the greatest number of user-defined options first, but containerFeaturesOrder.ts orders by the fewest options first.

Specification

Features spec — Definition: Round Stable Sort:

Greatest number of user-defined options (note omitting an option will default that value to the Feature's default value and is not considered a user-defined option)

Implementation

optionsCompareTo returns aKeys.length - bKeys.length, which is negative when a has fewer options, so the Feature with fewer options sorts earlier:

https://github.com/devcontainers/cli/blob/f683c29f64a20109b4453e5149807e390ff65133/src/spec-configuration/containerFeaturesOrder.ts#L123-L125

This is the option tiebreaker for every source type (OCI, file-path, direct-tarball, legacy).

Test evidence

The existing test valid dependsOn with round sorting based on options (fixture configs/feature-dependencies/dependsOn/local-with-options) pins the fewest-first behavior — the ./b variant with {} (zero options) is expected first, ahead of the two-option variants:

https://github.com/devcontainers/cli/blob/f683c29f64a20109b4453e5149807e390ff65133/src/test/container-features/containerFeaturesOrder.test.ts#L135-L209

So the implementation and its tests are internally consistent; only the behavior disagrees with the spec.

Proposed fix

Sort by the greatest option count to match the spec (bKeys.length - aKeys.length), with the fixture/expected order updated accordingly. This changes the install order of the same Feature requested with differing option sets within a round.

Lingua principale
Nessun dato sulla lingua
Stelle
5.7k
Fork
497
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di devcontainers/spec

Tutte le issue di devcontainers/spec

Issue simili

Altre issue su CLI

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.