A preview system image installed makes the newest runtime its codename, not the highest API level
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
What is wrong
A preview system image installed makes the newest runtime its codename, not the highest API level
Where this came from
Confirmed in the bug bounty sweep tracked on #648 (finding 4). The reproduction was reproduced independently by the orchestrating session, the proposed fix confirmed green against the surrounding suite, and the finding re-confirmed against current main.
Spec
Area: src/drivers/android/index.ts (runtime ranking: lease default, defaultRuntime)
Severity: wrong device booted, silently, on a real host configuration — this
reporting machine itself has android-Baklava in
~/Library/Android/sdk/system-images/ beside android-36, android-36.1 and
android-37.0. simlock lease --platform android with no --os boots an
API 35 preview instead of 37.0, and simlock catalog /
getCatalog().defaultRuntime tell every caller and the console that Baklava
is the newest installed runtime — so an agent that trusts the catalog to pick a
valid --os, the stated purpose of that command (docs/CLI.md:1594), is
pointed at the preview. Same for --image-tag without --os.
Kind: defect — four doc lines state what "newest" means; the ranking
disagrees with all four.
Problem
#installedImages records each image's level as the android-<x> folder
suffix (index.ts:1602 separately reads AndroidVersion.ApiLevel into
sourceApiLevel precisely because the folder name is not always the level).
For the preview folder, the recorded level is the string "Baklava".
installedApiLevels (index.ts:2260) sorts that list with compareApiLevels
(index.ts:2280): Number(left) - Number(right), falling back to
localeCompare when either side is not a number. "Baklava" vs "37.0" is
NaN, so the text branch wins and any letter-starting name sorts after
every number. resolveSpec then takes levels.at(-1) (:808) and
listCatalog takes runtimes.at(-1) (:1253, and :1673 for the
--image-tag path) — both hand out "Baklava" as the newest.
The lines this breaks:
docs/CLI.md:217 `--os` defaults to the newest runtime already installed
docs/CLI.md:311 without `--os` the lease gets the newest API level that has one
docs/CLI.md:1594 which installed runtime is the default (the newest)
docs/CLIENT.md:352 `defaultRuntime` is the newest installed runtime
Range requests are unaffected: src/contract/os-range.ts parses a non-numeric
version to NaN and refuses it, so the gateway never routes a range to the
preview. This is the no---os default path and the catalog's own words about
itself.
Root cause
src/drivers/android/index.ts:2280 — compareApiLevels ranks API levels by
Number(name) and falls back to left.localeCompare(right), so a name the SDK
stores as a codename always outranks a number. It knows nothing about
sourceApiLevel, which the same file reads 680 lines earlier precisely because
the folder name is not always the level. The ranking, not the identity, is what
is wrong: "Baklava" is a legitimate name to list and to lease explicitly — it
is only wrong as the newest.
image-fit.ts:85 (for (const candidate of [image.sourceApiLevel, image.apiLevel])) already applies the correct rule elsewhere in the same
module: this file's own convention, missed at one call site.
Evidence
Test file: src/drivers/android/scratch-newest-image.test.ts
Test titles: gives a lease with no OS the highest API level installed, not the
preview folder whose name sorts last
names the highest API level installed as the catalog's default runtime
Command: pnpm exec vitest run --project unit \
src/drivers/android/scratch-newest-image.test.ts
AssertionError: expected 'Baklava' to be '37.0' // Object.is equality
Expected: "37.0"
Received: "Baklava"
❯ src/drivers/android/scratch-newest-image.test.ts:156:28 (resolveSpec)
❯ src/drivers/android/scratch-newest-image.test.ts:168:36 (defaultRuntime)
The fixture's source.properties is the verbatim content of the real
~/Library/Android/sdk/system-images/android-Baklava/google_apis/arm64-v8a/source.properties
on this machine (AndroidVersion.ApiLevel=35, AndroidVersion.CodeName=Baklava
— orchestrator confirmed the file exists with those values beside 36/36.1/37.0).
Honesty checks (the finder's, then the orchestrator's):
- Both failures are preceded by
expect(catalog.runtimes).toContain("Baklava")
and the same formodelRuntimes["Pixel 9"]— so the failure can only be about
ranking: the preview really is a listed candidate, not an omission. - Preview folder removed from the fixture: both tests pass — nothing else causes
it. - Fixture reversed (
AndroidVersion.ApiLevel=38): both tests pass against the
broken code while still asserting the preview is newest — so the tests do
not merely prefer numbers over letters; they fail exactly because the recorded
level is ignored. - Orchestrator: fix applied → new tests green and
index.test.tsgreen
(274 passed | 1 skipped), including its existingandroid-Baklavatest at
:4877, which pins that the preview still pairs with Pixel 9 and is still
namedBaklava; then the full drivers module: 21 files, 1229 tests green;
then the entire unit lane: 269 files, 7029 passed | 4 skipped. Source
reverted, both assertions re-confirmed red.
Proposed fix
src/drivers/android/index.ts:2260 — rank by the level the SDK recorded, keep
the folder suffix as the name:
function installedApiLevels(images: readonly SystemImage[]): string[] {
const rank = new Map(
images.map((image) => [
image.apiLevel,
/^\d/.test(image.apiLevel) ? image.apiLevel : (image.sourceApiLevel ?? image.apiLevel),
]),
);
return [...new Set(images.map((image) => image.apiLevel))].sort(
(left, right) =>
compareApiLevels(rank.get(left) ?? left, rank.get(right) ?? right) ||
left.localeCompare(right),
);
}
Verified above. No doc change needed — the four doc lines already describe this
behaviour.
Alternatives rejected
- Store
sourceApiLevelas the level itself — renames the runtime across the
catalog,--os,images[].runtimeandmodelRuntimes, and breaks the
existing pin atindex.test.ts:4885that the runtime is namedBaklava. - Pick the max with
contract/os-range.ts'scompareVersions—Baklavaparses
toNaNthere and would sort as the oldest, and it repeats the ranking in
three call sites instead of one. - A table of known codenames — invents a list the SDK owns and rots at the next
preview.
Risk
compareCatalogImages(index.ts:2272) sortsimages[].runtimewith the same
comparator, socatalog.imagesorder shifts (the preview moves next to API
35 — where it belongs). A reviewer should confirm no console or CLI snapshot
pinned the old order; the orchestrator's full-unit-lane run says none did.- Two previews side by side (
Baklava,Baklava-2, same recorded level) keep a
deterministic order via thelocaleComparetiebreak. resolveSpecwith an explicit--os Baklavastill resolves — the fix changes
only who is newest, never what is listable or leasable.
Written by an agent.
Written by an agent.
- Ngôn ngữ chính
- TypeScript
- Star
- 20
- Fork
- 2
- Merge trung bình
- 8 giờ 10 phút
- Pull request đã merge (30 ngày)
- 354
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của callstackincubator/simlock
-
bug:new
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
callstackincubator/simlock#871 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug:new
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
callstackincubator/simlock#817 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug:triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
callstackincubator/simlock#778 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
callstackincubator/simlock#639 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug:new flaky-test
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
callstackincubator/simlock#886 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của callstackincubator/simlock
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Automattic/data-liberation-agent#953 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
README に GitHub の組織のバッジを足すĐang mởdocumentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
funmary-app/funmary#399 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:curator enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
CassioDalla/Scrinalia#150 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
status: needs-triage v1-bug-bash
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
a2ui-project/a2ui#3533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend enhancement priority:P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
geolens-io/geolens#3310 ·
Maintainer thường phản hồi trong vòng 1 ngày