Repository navigation
feat(gateway): an iOS lease is routed by the modes each worker serves #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b072f82
chore: merge task/1651 into task/1652 (#1652)
V3RON ad4fb68
test: an iOS lease through a gateway is routed by mode (#1652)
V3RON 1a875b0
feat(gateway): an iOS lease is routed by the modes each worker serves…
V3RON 0fb3902
test: a worker's relayed MODE_UNAVAILABLE before a progress push is c…
V3RON ee9994b
feat(gateway): a worker's MODE_UNAVAILABLE before a progress push lea…
V3RON 79a32cd
test: the merged iOS catalog carries the union of the workers' modes …
V3RON 9379959
feat(gateway): the merged iOS catalog carries the union of the worker…
V3RON d358451
docs(gateway): routing by iOS mode in the routing page, the console r…
V3RON 951c943
test: the console has a text for the mode-unavailable gateway reason …
V3RON 36de4f6
refactor(gateway): the mode row and the slim fields of the merged cat…
V3RON 7b063a0
refactor(gateway): the physical row of the table is its own function …
V3RON bd1c77f
docs: the manual and the flow name no file the repo test refuses (#1652)
V3RON a817b84
test(gateway): a mode only a non-serving worker could take is NO_CAPA…
V3RON eead807
docs(gateway): the catalog's iOS modes line lists the modes served ac…
V3RON 7b7dd81
docs(adr): ADR 0082 is Accepted now the feature is merging (#1652)
V3RON 177b8c6
Merge remote-tracking branch 'origin/task/1651' into task/1652
V3RON 19c347e
docs(adr): ADR 0082 has one index row, Accepted (#1652)
V3RON File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
docs/internal/adr/0082-a-worker-may-serve-only-some-ios-device-modes.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { SimlockError } from "../contract/index.js"; | ||
| import { createRoutingPolicy } from "./routing.js"; | ||
| import { | ||
| catalogFixture, | ||
| grantFixture, | ||
| physicalDeviceFixture, | ||
| ScriptedWorkerClient, | ||
| statusFixture, | ||
| } from "./test-support.js"; | ||
| import { buildFleet, connectWorker, REQUEST, requestOptions, tick } from "./test-fleet.js"; | ||
|
|
||
| type Modes = ("slim" | "full")[]; | ||
|
|
||
| interface WorkerSpec { | ||
| /** why: absent is a worker that sends no `modes` field: it serves both. */ | ||
| readonly modes?: Modes; | ||
| readonly baseline?: "slim" | "full"; | ||
| readonly physical?: true; | ||
| } | ||
|
|
||
| function fleet(specs: Readonly<Record<string, WorkerSpec>>) { | ||
| const made = buildFleet(); | ||
| const clients: Record<string, ScriptedWorkerClient> = {}; | ||
| for (const [id, spec] of Object.entries(specs)) { | ||
| const client = new ScriptedWorkerClient(); | ||
| client.requestLeaseQueue.push({ grant: grantFixture(), kind: "grant" }); | ||
| clients[id] = client; | ||
| made.directory.add(id, client); | ||
| connectWorker(made.workers, id); | ||
| made.workers.refresh(id, { | ||
| capacity: statusFixture().capacity, | ||
| catalog: catalogFixture([ | ||
| { | ||
| models: ["iPhone 17"], | ||
| platform: "ios", | ||
| runtimes: ["26.0"], | ||
| ...(spec.modes === undefined ? {} : { modes: spec.modes }), | ||
| }, | ||
| ]).platforms, | ||
| ...(spec.physical === true ? { devices: [physicalDeviceFixture("dev_p", "ready")] } : {}), | ||
| ...(spec.baseline === undefined | ||
| ? {} | ||
| : { | ||
| baselines: [ | ||
| { | ||
| mode: spec.baseline, | ||
| model: "iPhone 17", | ||
| name: "b", | ||
| osVersion: "26.0", | ||
| platform: "ios" as const, | ||
| savedAt: "2026-11-02T13:10:00Z", | ||
| version: 1, | ||
| }, | ||
| ], | ||
| }), | ||
| }); | ||
| } | ||
| return { ...made, clients }; | ||
| } | ||
|
|
||
| // why: the coordinator's tests, split by subject; they build the fleet from its test-support files, which index.ts does not export. | ||
| describe("FleetLeaseCoordinator routes an iOS lease by the modes each worker serves (ADR 0082 §4)", () => { | ||
| it("routes an iOS lease through a gateway by mode: a named or baseline mode goes only to a worker that serves it, and the lease fails at once when none does", async () => { | ||
| const cases: { | ||
| label: string; | ||
| request: { | ||
| baseline?: string; | ||
| mode?: "slim" | "full"; | ||
| physical?: boolean; | ||
| model?: string; | ||
| osVersion?: string; | ||
| }; | ||
| workers: Record<string, WorkerSpec>; | ||
| routedTo?: string; | ||
| rejected?: string; | ||
| }[] = [ | ||
| { | ||
| label: "--mode full, one slim-only worker", | ||
| request: { mode: "full" }, | ||
| workers: { wrk_a: { modes: ["slim"] } }, | ||
| rejected: | ||
| 'No worker serves full iOS simulators; ask for a slim one (--mode slim, or mode: "slim")', | ||
| }, | ||
| { | ||
| label: "slim-only plus a worker serving both", | ||
| request: { mode: "full" }, | ||
| workers: { wrk_a: { modes: ["slim"] }, wrk_b: { modes: ["slim", "full"] } }, | ||
| routedTo: "wrk_b", | ||
| }, | ||
| { | ||
| label: "slim-only plus a worker with no modes field", | ||
| request: { mode: "full" }, | ||
| workers: { wrk_a: { modes: ["slim"] }, wrk_b: {} }, | ||
| routedTo: "wrk_b", | ||
| }, | ||
| { | ||
| label: "--mode slim, one full-only worker", | ||
| request: { mode: "slim" }, | ||
| workers: { wrk_a: { modes: ["full"] } }, | ||
| rejected: | ||
| 'No worker serves slim iOS simulators; ask for a full one (--mode full, or mode: "full")', | ||
| }, | ||
| { | ||
| label: "no mode, only a slim-only worker", | ||
| request: {}, | ||
| workers: { wrk_a: { modes: ["slim"] } }, | ||
| routedTo: "wrk_a", | ||
| }, | ||
| { | ||
| label: "a full baseline on a slim-only worker", | ||
| request: { baseline: "b" }, | ||
| workers: { wrk_a: { baseline: "full", modes: ["slim"] } }, | ||
| rejected: 'Baseline "b" is full, and no worker that holds it serves full iOS simulators', | ||
| }, | ||
| { | ||
| label: "--physical to a slim-only worker", | ||
| request: { mode: "full", model: "iPhone 15 Pro", osVersion: "18.4", physical: true }, | ||
| workers: { wrk_a: { modes: ["slim"], physical: true } }, | ||
| routedTo: "wrk_a", | ||
| }, | ||
| ]; | ||
|
|
||
| for (const { label, request, workers: specs, routedTo, rejected } of cases) { | ||
| const { clients, coordinator } = fleet(specs); | ||
| const outcome = await Promise.race([ | ||
| coordinator.request({ ...REQUEST, ...request }, requestOptions()).then( | ||
| () => "granted", | ||
| (error: unknown) => error, | ||
| ), | ||
| tick().then(() => "waiting"), | ||
| ]); | ||
| const received = Object.entries(clients) | ||
| .filter(([, client]) => client.lastRequestLeaseInput !== undefined) | ||
| .map(([id]) => id); | ||
| if (rejected !== undefined) { | ||
| expect(outcome, label).toMatchObject({ | ||
| code: "MODE_UNAVAILABLE", | ||
| details: { mode: request.mode ?? "full", platform: "ios", served: [] }, | ||
| message: rejected, | ||
| }); | ||
| expect(received, label).toEqual([]); | ||
| } else { | ||
| expect(outcome, label).toBe("granted"); | ||
| expect(received, label).toEqual([routedTo]); | ||
| } | ||
| } | ||
|
|
||
| const { workers } = fleet({ wrk_a: { modes: ["slim"] }, wrk_b: {} }); | ||
| expect( | ||
| createRoutingPolicy("warm-then-free").explain({ ...REQUEST, mode: "full" }, workers.views()), | ||
| ).toMatchObject([ | ||
| { filter: { reason: "mode-unavailable" }, workerId: "wrk_a" }, | ||
| { workerId: "wrk_b" }, | ||
| ]); | ||
| }); | ||
|
|
||
| it("walks on to another worker when a worker answers MODE_UNAVAILABLE before a progress push, and gives the caller the worker's own refusal when none is left", async () => { | ||
| const refusal = new SimlockError( | ||
| "MODE_UNAVAILABLE", | ||
| "domain", | ||
| "This worker does not serve full iOS simulators", | ||
| { mode: "full", platform: "ios", served: ["slim"] }, | ||
| ); | ||
|
|
||
| // why: both views are stale, with no `modes` field, so only the worker's own refusal says it serves slim alone. | ||
| const both = fleet({ wrk_a: {}, wrk_b: {} }); | ||
| both.clients["wrk_a"]?.requestLeaseQueue.splice(0, 1, { error: refusal, kind: "error" }); | ||
| const granted = await both.coordinator.request({ ...REQUEST, mode: "full" }, requestOptions()); | ||
|
|
||
| expect(granted.lease.worker?.id).toBe("wrk_b"); | ||
| expect(both.directory.catalogRefreshCalls).toEqual(["wrk_a"]); | ||
|
|
||
| const alone = fleet({ wrk_a: {} }); | ||
| alone.clients["wrk_a"]?.requestLeaseQueue.splice(0, 1, { error: refusal, kind: "error" }); | ||
| const outcome = await Promise.race([ | ||
| alone.coordinator.request({ ...REQUEST, mode: "full" }, requestOptions()).then( | ||
| () => "granted", | ||
| (error: unknown) => error, | ||
| ), | ||
| tick().then(() => "waiting"), | ||
| ]); | ||
|
|
||
| expect(outcome).toMatchObject({ | ||
| code: "MODE_UNAVAILABLE", | ||
| details: { mode: "full", platform: "ios", served: ["slim"] }, | ||
| message: "This worker does not serve full iOS simulators", | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move
minto 97, or keep protocol-96 clients away frommode-unavailable.The range keeps
min: 89, so protocol-96 clients still negotiate with this gateway. This PR adds"mode-unavailable"to the waiting-request reason enum (src/contract/lease-schemas.ts) and to the CLI label map (src/cli/commands/list.ts). A protocol-96 CLI built from the base revision rejects that value when it parseslist requests. The gateway can send it for a queued request's worker entry.The contract rule requires moving
minwithmaxunless a side-by-side compatibility path stays in place. The inspected code has no such path. Choose one of the following:minto 97. Protocol-96 clients then fail athellowithPROTOCOL_VERSION_UNSUPPORTED.mode-unavailablefrom protocol-96 clients, so they never receive a value their schema rejects.Source: Coding guidelines