Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86d486fb69 | ||
|
|
b4b25551ff | ||
|
|
8a12f07703 | ||
|
|
a84bc7ed21 | ||
|
|
7524f943d2 | ||
|
|
4f182a22b6 | ||
|
|
34b38dd5d5 | ||
|
|
b2133fd25c | ||
|
|
179fad450d | ||
|
|
85b7b07f53 | ||
|
|
5ef661a06f | ||
|
|
408cd933f4 |
@@ -1,5 +1,40 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v0.29.0 — 2026-09-20 14:27
|
||||||
|
- **Ignore a job (ISS-047, part B).** A player can now dismiss an open job so it leaves the market permanently; new random jobs spawn in its place via the existing top-up logic (`spawnOpenPackages` counts 'open', so the market refills to 10 on the next tick). New terminal package status `'ignored'` added to the status union/enum in `lib/db/schema.ts`, `lib/game/state.ts`, `lib/openapi.ts` (PackageState.status) and the e2e-local interface copy in `e2e/right-pane.spec.ts`. No DB migration — the column is plain TEXT with no CHECK constraint. New action `ignorePackage` (`lib/game/actions.ts`) next to abandon: 404 unknown id, 409 unless open ("only open packages can be ignored"), otherwise flips status to 'ignored' — no body, no penalty, nothing else changes
|
||||||
|
- **New route.** `POST /api/packages/{id}/ignore` (`app/api/packages/[id]/ignore/route.ts`) — no body, mirrors the abandon route exactly (same performAction wrapper, full state snapshot on success). The 13th public endpoint: OpenAPI spec gains the path + 'ignored' in PackageState.status; `lib/openapi.test.ts` and `e2e/api.spec.ts` path lists updated twelve → thirteen
|
||||||
|
- **UI.** Each open-package row in the Jobs tab gains a small "Ignore" button beside the Load controls (`components/RightPane.tsx`, testid `ignore-{pkg.id}`, disabled while the pane action is busy, calls runAction with no body). Ignored rows vanish from the list automatically — the section filters status==='open'; no toast (deriveEvents untouched)
|
||||||
|
- Verified-safe consumers unchanged: expirePackages selects only open|loaded ('ignored' never expires), deliverPackages handles loaded/expired, RightPane filters 'open'
|
||||||
|
- Tests: unit — new `ignorePackage` block in `lib/game/actions.test.ts` (open → ignored with cash/planeId untouched; 409 for each of loaded/delivered/expired/abandoned/already-ignored; 404 unknown id), `lib/sim/engine.test.ts` terminal-statuses test gains an 'ignored' row, `lib/openapi.test.ts` status enum list gains 'ignored'. E2E — new "Ignore removes an open job from the list permanently" test in `e2e/right-pane.spec.ts`: hook-created package renders with an enabled Ignore button, UI click → /api/state shows 'ignored', row gone from `[data-testid="open-packages"]`, second API ignore 409s
|
||||||
|
- Verified: `tsc --noEmit` clean; unit suite green locally (325, was 318); `npx playwright test --list` = 47 tests in 13 files (was 46/13 — the new ignore test); e2e not run locally by design — CI verifies against an isolated stack
|
||||||
|
|
||||||
|
## v0.28.0 — 2026-09-20 13:55
|
||||||
|
- **Right pane reworked into tabs (ISS-047, part A).** The right pane now has a tab bar under the "Jobs & Market" heading with two tabs — `tab-jobs` ("Jobs", default-active) and `tab-planes-market` ("Planes market") (`components/RightPane.tsx`, new `.pane-tabs`/`.tab-btn` CSS in `app/globals.css`). The Jobs tab is the existing Packages section moved verbatim (content, testids and hover behavior unchanged); the Planes market tab holds the existing buy/sell rows (testids unchanged) plus a tech-spec panel per catalog type — one card (`plane-type-{model}`) with price, sell value (price × SELL_FRACTION), max payload in tonnes, cruise speed, fuel burn, max fuel and **max range**, ordered by price ascending. The inactive tab unmounts; the `cargoWeightFor`/`loadEligiblePlanes` exports are untouched
|
||||||
|
- **Five new plane types — progression ladder above the ATR starter (ISS-047).** CRJ-900 (€450k), Embraer E175 (€900k), Airbus A320-200 (€1.8M), Airbus A330-200 (€4.5M) and Boeing 777-300ER (€9M) added to `PLANE_TYPES` in `lib/game/catalog.ts` with the exact balance values from the issue (bigger tanks, faster airframes, more payload). Purely additive — everything downstream (buy validation, movement math, load validation, snapshot catalog) is data-driven via `PLANE_TYPES[model]`, so no endpoint or schema change; the OpenAPI spec and its e2e path list stay at twelve
|
||||||
|
- **Derived max range (ISS-047).** New pure `maxRangeKm(burnPerKm, emptyWeightKg, maxFuel)` in `lib/sim/movement.ts` — closed form of the weighted burn model solving `requiredFuelFor(d) = maxFuel`: `ln(1 + ρF/We)·(We + ρF)/(ρ·burnPerKm)` (reuses `FUEL_DENSITY_KG_PER_L`, guards We > 0, zero fuel → 0). ATR 72-600 full tank ≈ 4436 km. Display-only — the sim still does not model range exhaustion
|
||||||
|
- **Sell-plane cargo guard (ISS-047).** `sellPlane` (`lib/game/actions.ts`) now 409s with "cannot sell a plane carrying cargo" when the grounded plane has any `loaded`/`expired` packages bound to it — previously selling such a plane orphaned its cargo (packages stuck 'loaded' with a dangling planeId that could never deliver). Same query pattern as `loadPackage`; the last-plane and flying-plane guards are unchanged
|
||||||
|
- Tests: unit — new `lib/sim/movement.test.ts` block for `maxRangeKm` (ATR ≈ 4439 km ±5%, monotonic in tank size, inverse in burn rate, zero fuel → 0, We ≤ 0 throws), new `lib/game/catalog.test.ts` sanity file (positive specs + unique ids across all six types, atr72 is STARTER_MODEL), `lib/game/actions.test.ts` sellPlane gains a loaded-cargo 409 case (row left untouched). E2E — `e2e/right-pane.spec.ts`: the market test clicks `tab-planes-market` first and a new "Planes market tab lists all plane types with tech specs" test asserts six catalog entries via /api/state, the ATR card's name + range against an in-test mirror of `maxRangeKm`, and the Boeing 777 card with its €9M price; `e2e/toasts.spec.ts` clicks the tab before its market-buy flow; `e2e/panes.spec.ts` asserts both tab buttons render with Jobs default-active. No new endpoints — `lib/openapi.test.ts` untouched
|
||||||
|
- Verified: `tsc --noEmit` clean; unit suite green locally (318, was 311); `npx playwright test --list` = 46 tests in 13 files (was 45/13 — the new spec-panel test); e2e not run locally by design — CI verifies against an isolated stack
|
||||||
|
|
||||||
|
## v0.27.1 — 2026-09-20 13:16
|
||||||
|
- Right pane widened from 280px to 360px to match the left pane; toast stack offset adjusted to stay flush with the map's right edge (ISS-046).
|
||||||
|
|
||||||
|
## v0.27.0 — 2026-09-20 12:27
|
||||||
|
- **Packages now have real weight (ISS-045).** New `weight_kg REAL NOT NULL DEFAULT 2000` column on `packages` (`lib/db/schema.ts`, DDL + guarded `ALTER TABLE` migration in `lib/db/client.ts`; pre-existing rows backfill to the mid-range default). `generatePackage` draws it AFTER cargoCount: `UNIT_WEIGHT_KG[cargoType] × cargoCount × (0.7 + 0.6·rng())`, rounded to integer kg — one extra RNG draw per package, so the documented fixed draw order is now origin, dest, cargoType, cargoCount, weight jitter, [deadline window]. New tunable table `UNIT_WEIGHT_KG` in `lib/game/seed.ts` (Passengers 50 / Mail 60 / Perishables 70 / Electronics 40 / Auto parts 72 kg per passenger/pallet), chosen so every cargo type at MAX count × max jitter (1.3×) still fits the ATR alone and typical packages land ~400–2500 kg
|
||||||
|
- **Plane capacity is now max payload kg, not 6 slots (ISS-045).** `capacity` REMOVED from `PlaneType`/`CatalogEntry`/snapshot catalog; replaced by `maxPayloadKg` — ATR 72-600 = 4800 kg (`lib/game/catalog.ts`). Server load validation (`loadPackage`, `lib/game/actions.ts`) now sums `weightKg` over the plane's loaded+expired packages and 409s with `no payload room: the ATR 72-600 carries X/Y kg` when the new package doesn't fit; expired cargo still occupies its payload. Client mirrors it: `slotsUsedFor` → `cargoWeightFor(state, planeId)` (summed kg) in `components/RightPane.tsx`, and `loadEligiblePlanes` compares used + package weight ≤ catalog maxPayloadKg so the Load button state always matches what the server accepts
|
||||||
|
- **Payout now includes a per-kg part (ISS-045).** New `rewardFor(km, weightKg) = round(BASE_REWARD + REWARD_PER_KM·km + REWARD_PER_KG·weightKg)` with `REWARD_PER_KG = 0.5` (`lib/game/seed.ts`) — replaces the distance-only `rewardForDistanceKm`, which is deleted (no remaining callers). Typical hops stay in the ~€1–3k band
|
||||||
|
- **Loadout display shows tonnage (ISS-045).** Left-pane fleet rows now render `X.Xt / Y.Yt` (used/max payload, one decimal) instead of `n/6 pkgs`; the on-board block filter switches to weight-based. No new endpoints — OpenAPI only gains `PackageState.weightKg` and swaps `CatalogEntry.capacity` → `maxPayloadKg`, so the e2e path list stays at twelve
|
||||||
|
- **Test hook gains a forced weight (ISS-045).** `generatePackage` accepts an optional `weightKg` that skips the jitter RNG draw (same pattern as the v0.8.0 forced endpoints), and `POST /api/test/create-package` passes it through — so e2e flows that load several packages onto one plane stay under its payload deterministically instead of flaking on two heavy random draws (~13% would otherwise exceed 4800 kg). The hook is test-only (FLIGHT_TEST_HOOKS=1) and not part of the documented API, so the OpenAPI path list stays at twelve
|
||||||
|
- Tests: unit — `lib/game/seed.test.ts` (reward expectations → new formula incl. per-kg part; new balance-constraint test asserting every seeded package is a positive integer kg ≤ starter maxPayloadKg; forced-weight block), `lib/game/actions.test.ts` (loadPackage fill loop now inserts weights summing past maxPayloadKg → `/no payload room/`; expired-still-occupies reworked weight-based), `components/right-pane.test.ts` (`cargoWeightFor` sums + partial-payload eligibility case; CATALOG fixture drops capacity, gains maxPayloadKg), `lib/openapi.test.ts` (exact key lists for PackageState + CatalogEntry). Type-compat only: catalog fixtures in `deriveEvents`/`mapData` tests and the e2e interfaces. E2E — `e2e/right-pane.spec.ts` asserts `maxPayloadKg === 4800`; `e2e/panes.spec.ts` loadout regex → `/^\d+\.\dt \/ \d+\.\dt$/`; snapshot key lists in `app/api/state/route.test.ts` + `e2e/state.spec.ts` gain `weightKg`; the two multi-load tests in `e2e/actions.spec.ts` pass forced weights. Fuel math untouched — the refuel-forFlight exact-liter mirrors stay as-is
|
||||||
|
- Verified: `tsc --noEmit` clean; unit suite green locally (311, was 308); `npx playwright test --list` = 45 tests in 13 files (unchanged); e2e not run locally by design — CI verifies against an isolated stack
|
||||||
|
|
||||||
|
## v0.26.0 — 2026-09-20 11:28
|
||||||
|
- **Flight queue UI + map rendering (ISS-043, part 2).** Builds on the part-1 backend (`PlaneState.queue`, `POST /api/planes/{id}/queue` + `/queue/cancel`, auto-chain on landing) — no new endpoints, so the OpenAPI spec and its e2e path list are untouched
|
||||||
|
- **Dotted queue line on the map (ISS-043).** New pure builder `queuedRoutesGeoJson(planes, airportsByIcao)` in `lib/mapData.ts`: one LineString per FLYING plane with a non-empty queue, chaining `dest → queue[0] → …` — ONLY the not-yet-started legs (the active leg stays in the solid `routes-legs` layer). Reuses `greatCircleArc`, same feature/properties shape as `routesGeoJson` (`{planeId}`); arcs concatenated with the shared joint point dropped once; a plane is skipped, never guessed, when its dest or any queued ICAO is missing from the airport index. New GeoJSON source + line layer in `components/Map.tsx` — id `queue-routes`, muted slate `#64748b`, width 3, dotted via `'line-dasharray': [0.1, 1.5]` (distinct from the solid amber active leg and the `[2,2]` yellow hover dash), added after `routes-legs` but before the hover layers so a hovered trace still draws on top; pushed each poll in `applyDynamicRef` alongside the solid legs
|
||||||
|
- **Queue sub-section in the left pane's On board block (ISS-043).** Each on-board plane block now carries a "Queue" sub-section after its cargo rows: one row per queued leg (`queue-leg-{i}`) showing destination name + ICAO with a Cancel button (`queue-cancel-{i}` → `POST …/queue/cancel {index:i}`), plus an add control — airport `<select>` (`queue-add-dest`) + "Add to queue" button (`queue-add` → `POST …/queue {destIcao}`) reusing the pane's already-fetched `airportOptions` (no second `/api/airports` fetch); buttons disable on `actionsBusy`, add also disables until an airport is picked. The on-board block filter now ALSO includes planes with a non-empty queue, so a queued plane always shows its block even when grounded with nothing on board. Existing cargo-row testids/behavior (`onboard-package-*`, `fly-to-*`, `refuel-for-*`, `abandon-*`) unchanged
|
||||||
|
- Tests: unit — `lib/mapData.test.ts` gains a `queuedRoutesGeoJson` block mirroring the `routesGeoJson` tests (grounded plane with queue → nothing; flying with empty queue → nothing; flying with a 2-leg queue → one feature starting at DEST, passing through each queued airport exactly at the arc joints, ending at the last queued ICAO, length `n_legs × SEGMENTS + 1`; missing dest or queued ICAO → skipped; multiple planes → only qualifying ones draw). E2E — new `e2e/queue.spec.ts` (serial): (1) queue display + cancel through the real UI — load a package at EDDF, start leg 1 via the fly-to button, freeze mid-flight, add a leg via `queue-add-dest`/`queue-add`, assert `queue-leg-0` appears with its destination, cancel it and assert it's gone; (2) dotted map line — flying plane with one queued leg: fit to both endpoints and assert some rendered `queue-routes` segment starts within EPS of DEST and some ends within EPS of the queued airport ACROSS per-tile segments (plain-object mapping in-page per ORCHESTRATOR §6), no segment starts at the hub (the active leg is NOT in this layer) and every feature carries `planeId: plane-starter`; (3) auto-chain end-to-end — full tank, package EDDF→LEMD + queued return LEMD→EDDF, start leg 1, fast-forward at 1000× and assert the server AUTO-STARTS the chained leg (`status 'flying'` to EDDF with no manual dispatch) with the package already delivered (part-1 ordering: delivery before chaining); all three leave the starter grounded at EDDF for later specs
|
||||||
|
- Verified: `tsc --noEmit` clean; unit suite green locally (308, was 303); `npx playwright test --list` = 45 tests in 13 files (was 42/12 — the new queue spec); e2e not run locally by design — CI verifies against an isolated stack
|
||||||
|
|
||||||
## v0.25.0 — 2026-09-20 10:36
|
## v0.25.0 — 2026-09-20 10:36
|
||||||
- **Planes now hold a queue of upcoming flight legs (ISS-043, part 1 — backend).** One new column on `planes`: `queue TEXT NOT NULL DEFAULT '[]'` (`lib/db/schema.ts`, DDL + guarded `ALTER TABLE` migration in `lib/db/client.ts`) storing an ordered JSON array of ICAO strings = the legs NOT yet started. The active leg stays exactly as before (`destIcao` + `departureSimTime`); full path = `[locationIcao, destIcao, ...queue]`. No new table — queues are short, per-plane, always read/written whole
|
- **Planes now hold a queue of upcoming flight legs (ISS-043, part 1 — backend).** One new column on `planes`: `queue TEXT NOT NULL DEFAULT '[]'` (`lib/db/schema.ts`, DDL + guarded `ALTER TABLE` migration in `lib/db/client.ts`) storing an ordered JSON array of ICAO strings = the legs NOT yet started. The active leg stays exactly as before (`destIcao` + `departureSimTime`); full path = `[locationIcao, destIcao, ...queue]`. No new table — queues are short, per-plane, always read/written whole
|
||||||
- **Auto-chain on landing (ISS-043).** In `deliverPackages()` (`lib/sim/engine.ts`) a plane that arrives now reads its queue: if it holds legs AND fuel covers the first one (same `requiredFuelFor` feasibility rule as `/fly`), it immediately starts that leg from the arrival airport — stays `'flying'`, `departureSimTime` = the arrival instant, queue shortened. If fuel is short it grounds safely with the remaining queue kept intact for refuel + re-dispatch; an empty queue grounds exactly as before. Cargo delivery for the reached airport runs first and is unaffected by chaining. Ordering preserved on purpose: delivery runs BEFORE tickOnce's pause check (ISS-041), so a chained plane counts as still flying there — chaining never triggers the last-plane pause
|
- **Auto-chain on landing (ISS-043).** In `deliverPackages()` (`lib/sim/engine.ts`) a plane that arrives now reads its queue: if it holds legs AND fuel covers the first one (same `requiredFuelFor` feasibility rule as `/fly`), it immediately starts that leg from the arrival airport — stays `'flying'`, `departureSimTime` = the arrival instant, queue shortened. If fuel is short it grounds safely with the remaining queue kept intact for refuel + re-dispatch; an empty queue grounds exactly as before. Cargo delivery for the reached airport runs first and is unaffected by chaining. Ordering preserved on purpose: delivery runs BEFORE tickOnce's pause check (ISS-041), so a chained plane counts as still flying there — chaining never triggers the last-plane pause
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { ignorePackage, performAction } from '@/lib/game/actions';
|
||||||
|
|
||||||
|
// POST /api/packages/:id/ignore (v0.29.0, ISS-047 part B) — no body. Dismisses an OPEN job so it
|
||||||
|
// leaves the market permanently; the top-up logic spawns a replacement on the next tick. No penalty,
|
||||||
|
// nothing else changes. 404 unknown id; 409 unless open. On success returns the full state snapshot.
|
||||||
|
|
||||||
|
export async function POST(_req: Request, ctx: { params: Promise<{ id: string }> }) {
|
||||||
|
const { id } = await ctx.params;
|
||||||
|
return performAction((inst) => ignorePackage(inst, id));
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import { loadPackage, performAction } from '@/lib/game/actions';
|
import { loadPackage, performAction } from '@/lib/game/actions';
|
||||||
|
|
||||||
// POST /api/packages/:id/load (v0.12.0) — body { planeId: string }. Loads an OPEN
|
// POST /api/packages/:id/load (v0.12.0) — body { planeId: string }. Loads an OPEN
|
||||||
// package onto a GROUNDED plane at the package's origin with a free slot. 400
|
// package onto a GROUNDED plane at the package's origin with enough payload room
|
||||||
// missing/non-string planeId or unknown fields; 404 unknown package/plane id; 409
|
// for its weight (v0.27.0). 400 missing/non-string planeId or unknown fields; 404
|
||||||
// wrong package status, plane flying, plane not at the origin, no free slots. On
|
// unknown package/plane id; 409 wrong package status, plane flying, plane not at
|
||||||
// success returns the full state snapshot (package now "loaded" on that plane).
|
// the origin, no payload room. On success returns the full state snapshot
|
||||||
|
// (package now "loaded" on that plane).
|
||||||
|
|
||||||
export async function POST(req: Request, ctx: { params: Promise<{ id: string }> }) {
|
export async function POST(req: Request, ctx: { params: Promise<{ id: string }> }) {
|
||||||
const { id } = await ctx.params;
|
const { id } = await ctx.params;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('GET /api/state', () => {
|
|||||||
|
|
||||||
const packages = body.packages as Array<Record<string, unknown>>;
|
const packages = body.packages as Array<Record<string, unknown>>;
|
||||||
expect(packages.length).toBeGreaterThan(0);
|
expect(packages.length).toBeGreaterThan(0);
|
||||||
for (const key of ['id', 'originIcao', 'destIcao', 'reward', 'cargoType', 'deadlineSimTime', 'status']) {
|
for (const key of ['id', 'originIcao', 'destIcao', 'reward', 'cargoType', 'weightKg', 'deadlineSimTime', 'status']) {
|
||||||
expect(packages[0], `package.${key}`).toHaveProperty(key);
|
expect(packages[0], `package.${key}`).toHaveProperty(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -86,7 +86,7 @@ describe('GET /api/state', () => {
|
|||||||
expect(entry.maxFuel).toBe(type.maxFuel);
|
expect(entry.maxFuel).toBe(type.maxFuel);
|
||||||
expect(entry.burnPerKm).toBe(type.burnPerKm);
|
expect(entry.burnPerKm).toBe(type.burnPerKm);
|
||||||
expect(entry.speedKmh).toBe(type.speedKmh);
|
expect(entry.speedKmh).toBe(type.speedKmh);
|
||||||
expect(entry.capacity).toBe(type.capacity); // v0.12.0 slot capacity (ATR 72-600: 6)
|
expect(entry.maxPayloadKg).toBe(type.maxPayloadKg); // v0.27.0 payload kg (ATR 72-600: 4800)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Economy constants — the single source of truth stays lib/game/catalog.ts.
|
// Economy constants — the single source of truth stays lib/game/catalog.ts.
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import { tickNow } from '@/lib/sim/engine';
|
|||||||
// same gate, same conventions.
|
// same gate, same conventions.
|
||||||
//
|
//
|
||||||
// POST /api/test/create-package
|
// POST /api/test/create-package
|
||||||
// body { originIcao?: string, destIcao?: string, deadlineOffsetMs?: number }
|
// body { originIcao?: string, destIcao?: string, deadlineOffsetMs?: number, weightKg?: number }
|
||||||
// - ICACOs must exist in the airport dataset and differ (400 otherwise);
|
// - ICACOs must exist in the airport dataset and differ (400 otherwise);
|
||||||
// omitted endpoints are picked at random by generatePackage.
|
// omitted endpoints are picked at random by generatePackage.
|
||||||
// - deadlineOffsetMs defaults to a normal 6–72h game-time window (NOT the short
|
// - deadlineOffsetMs defaults to a normal 6–72h game-time window (NOT the short
|
||||||
// hook deadline of expire-package) — pass an explicit value to override.
|
// hook deadline of expire-package) — pass an explicit value to override.
|
||||||
|
// - weightKg (v0.27.0) forces the package weight instead of the RNG draw, so e2e
|
||||||
|
// flows that load several packages can stay under the plane's payload deterministically.
|
||||||
// Returns 201 + the created package row.
|
// Returns 201 + the created package row.
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
@@ -38,7 +40,7 @@ export async function POST(req: Request) {
|
|||||||
}
|
}
|
||||||
const input = body as Record<string, unknown>;
|
const input = body as Record<string, unknown>;
|
||||||
for (const key of Object.keys(input)) {
|
for (const key of Object.keys(input)) {
|
||||||
if (key !== 'originIcao' && key !== 'destIcao' && key !== 'deadlineOffsetMs') {
|
if (key !== 'originIcao' && key !== 'destIcao' && key !== 'deadlineOffsetMs' && key !== 'weightKg') {
|
||||||
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
|
return Response.json({ error: `unknown field "${key}"` }, { status: 400 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,6 +52,9 @@ export async function POST(req: Request) {
|
|||||||
if (input.deadlineOffsetMs !== undefined && (typeof input.deadlineOffsetMs !== 'number' || !Number.isFinite(input.deadlineOffsetMs))) {
|
if (input.deadlineOffsetMs !== undefined && (typeof input.deadlineOffsetMs !== 'number' || !Number.isFinite(input.deadlineOffsetMs))) {
|
||||||
return Response.json({ error: 'deadlineOffsetMs must be a finite number' }, { status: 400 });
|
return Response.json({ error: 'deadlineOffsetMs must be a finite number' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
if (input.weightKg !== undefined && (typeof input.weightKg !== 'number' || !Number.isFinite(input.weightKg) || input.weightKg <= 0)) {
|
||||||
|
return Response.json({ error: 'weightKg must be a positive finite number' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const inst = await getGameDb();
|
const inst = await getGameDb();
|
||||||
@@ -79,6 +84,7 @@ export async function POST(req: Request) {
|
|||||||
deadlineOffsetMs: input.deadlineOffsetMs as number | undefined,
|
deadlineOffsetMs: input.deadlineOffsetMs as number | undefined,
|
||||||
originIcao: input.originIcao as string | undefined,
|
originIcao: input.originIcao as string | undefined,
|
||||||
destIcao: input.destIcao as string | undefined,
|
destIcao: input.destIcao as string | undefined,
|
||||||
|
weightKg: input.weightKg as number | undefined,
|
||||||
});
|
});
|
||||||
await inst.db.insert(schema.packages).values(created);
|
await inst.db.insert(schema.packages).values(created);
|
||||||
await persist(inst);
|
await persist(inst);
|
||||||
|
|||||||
+67
-5
@@ -103,11 +103,11 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* v0.9.0 — single-screen 3-pane shell: left Assets / center map / right Jobs & Market.
|
/* v0.9.0 — single-screen 3-pane shell: left Assets / center map / right Jobs & Market.
|
||||||
ISS-021 (v0.20.0): left widened to 360px (it now carries the On board section), right
|
ISS-021 (v0.20.0): left widened to 360px (it now carries the On board section).
|
||||||
narrowed to 280px — total fixed width stays 640px, so the map column is unchanged. */
|
ISS-046 (v0.27.1): right widened to match left at 360px — total fixed width 720px, map column shrinks by 80px. */
|
||||||
.app-shell {
|
.app-shell {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 360px minmax(0, 1fr) 280px;
|
grid-template-columns: 360px minmax(0, 1fr) 360px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,12 +416,36 @@ body {
|
|||||||
gap: 6px;
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ISS-043 (v0.26.0) — flight-queue sub-section inside on-board blocks */
|
||||||
|
.queue-subsection {
|
||||||
|
margin-top: 8px;
|
||||||
|
padding-top: 6px;
|
||||||
|
border-top: 1px solid rgba(148, 163, 184, 0.2);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.queue-heading {
|
||||||
|
font-size: 11px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
color: #94a3b8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.queue-row {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
/* v0.17.0 — ISS-008: bottom-right toast stack (action errors + game events) */
|
/* v0.17.0 — ISS-008: bottom-right toast stack (action errors + game events) */
|
||||||
.toasts {
|
.toasts {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
bottom: 12px;
|
bottom: 12px;
|
||||||
/* 280px right pane + 12px inset — sits flush against the map's right edge, clear of the right pane */
|
/* 360px right pane + 12px inset — sits flush against the map's right edge, clear of the right pane */
|
||||||
right: 292px;
|
right: 372px;
|
||||||
z-index: 50; /* above map popups/controls and the app header */
|
z-index: 50; /* above map popups/controls and the app header */
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -483,3 +507,41 @@ body {
|
|||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* v0.28.0 (ISS-047) — right pane tabs (Jobs / Planes market) + per-type tech-spec cards */
|
||||||
|
.pane-tabs {
|
||||||
|
display: flex;
|
||||||
|
gap: 6px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-btn {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
border: 1px solid rgba(148, 163, 184, 0.4);
|
||||||
|
background: rgba(30, 41, 59, 0.9);
|
||||||
|
color: #e2e8f0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tab-btn[aria-selected='true'] {
|
||||||
|
background: rgba(56, 189, 248, 0.25);
|
||||||
|
border-color: rgba(56, 189, 248, 0.7);
|
||||||
|
color: #f8fafc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plane-type-card {
|
||||||
|
background: rgba(30, 41, 59, 0.6);
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 8px;
|
||||||
|
margin-bottom: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plane-type-name {
|
||||||
|
margin: 0 0 6px;
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #f1f5f9;
|
||||||
|
}
|
||||||
|
|||||||
+62
-8
@@ -9,7 +9,7 @@ import { formatCash, formatDeadlineRelative, formatFuel, formatSimClock } from '
|
|||||||
import { TIME_SCALES, scaleToSlider, sliderToScale } from '@/lib/timeScale';
|
import { TIME_SCALES, scaleToSlider, sliderToScale } from '@/lib/timeScale';
|
||||||
import { useGameAction } from '@/lib/useGameAction';
|
import { useGameAction } from '@/lib/useGameAction';
|
||||||
import { useSimClock } from '@/lib/useSimClock';
|
import { useSimClock } from '@/lib/useSimClock';
|
||||||
import { slotsUsedFor } from './RightPane';
|
import { cargoWeightFor } from './RightPane';
|
||||||
import type { HoverTarget } from './hoverTypes';
|
import type { HoverTarget } from './hoverTypes';
|
||||||
|
|
||||||
interface LeftPaneProps {
|
interface LeftPaneProps {
|
||||||
@@ -39,13 +39,12 @@ function planeLocation(p: PlaneState): string {
|
|||||||
return p.locationName;
|
return p.locationName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cargo loadout "n/capacity pkgs" — expired packages still occupy their slot.
|
// Cargo loadout "X.Xt / Y.Yt" (v0.27.0) — used/max payload in tonnes, one decimal;
|
||||||
|
// expired packages still occupy their payload.
|
||||||
function loadoutFor(state: StateSnapshot, p: PlaneState): string {
|
function loadoutFor(state: StateSnapshot, p: PlaneState): string {
|
||||||
const used = state.packages.filter(
|
const used = cargoWeightFor(state, p.id);
|
||||||
(pkg) => pkg.planeId === p.id && (pkg.status === 'loaded' || pkg.status === 'expired'),
|
const maxPayloadKg = state.catalog.find((e) => e.model === p.model)?.maxPayloadKg ?? PLANE_TYPES[p.model]?.maxPayloadKg ?? 0;
|
||||||
).length;
|
return `${(used / 1000).toFixed(1)}t / ${(maxPayloadKg / 1000).toFixed(1)}t`;
|
||||||
const capacity = state.catalog.find((e) => e.model === p.model)?.capacity ?? PLANE_TYPES[p.model]?.capacity ?? 0;
|
|
||||||
return `${used}/${capacity} pkgs`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ISS-001 — an optimistic slider value is cleared exactly when a rendered snapshot CONFIRMS it
|
// ISS-001 — an optimistic slider value is cleared exactly when a rendered snapshot CONFIRMS it
|
||||||
@@ -107,6 +106,10 @@ export default function LeftPane({ state, loading, error, onRefresh, applySnapsh
|
|||||||
// a sensible default (first grounded plane with fuel below max).
|
// a sensible default (first grounded plane with fuel below max).
|
||||||
const [refuelPlaneId, setRefuelPlaneId] = useState<string | null>(null);
|
const [refuelPlaneId, setRefuelPlaneId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// ISS-043 (v0.26.0): flight-queue "add" destination — one shared pick across every on-board
|
||||||
|
// block's queue-add select (the e2e fleet is a single plane; per-block state would be dead weight).
|
||||||
|
const [queueAddDestIcao, setQueueAddDestIcao] = useState<string | null>(null);
|
||||||
|
|
||||||
// ISS-010 (v0.18.0): one-time /api/airports fetch per page life — destination options for the
|
// ISS-010 (v0.18.0): one-time /api/airports fetch per page life — destination options for the
|
||||||
// Relocate section, sorted by name so e2e selection is stable. Same promise-ref pattern as Map.tsx;
|
// Relocate section, sorted by name so e2e selection is stable. Same promise-ref pattern as Map.tsx;
|
||||||
// on failure airportOptions stays null and the Relocate button simply remains disabled. Moved here
|
// on failure airportOptions stays null and the Relocate button simply remains disabled. Moved here
|
||||||
@@ -200,7 +203,11 @@ export default function LeftPane({ state, loading, error, onRefresh, applySnapsh
|
|||||||
// cargo or is mid-flight gets a block — its loaded/expired packages with fly-to-destination +
|
// cargo or is mid-flight gets a block — its loaded/expired packages with fly-to-destination +
|
||||||
// abandon controls, and flying planes show their current leg.
|
// abandon controls, and flying planes show their current leg.
|
||||||
const clockMs = state?.simState.clockMs ?? 0;
|
const clockMs = state?.simState.clockMs ?? 0;
|
||||||
const onboard = state ? state.planes.filter((p) => p.status === 'flying' || slotsUsedFor(state, p.id) > 0) : [];
|
// ISS-043 (v0.26.0): a plane with queued legs always shows its block too — the queue is the
|
||||||
|
// reason it's here even when grounded with nothing on board.
|
||||||
|
const onboard = state
|
||||||
|
? state.planes.filter((p) => p.status === 'flying' || cargoWeightFor(state, p.id) > 0 || (p.queue?.length ?? 0) > 0)
|
||||||
|
: [];
|
||||||
|
|
||||||
// ISS-023 (v0.21.0): Relocate — any GROUNDED plane can be repositioned to any airport via the
|
// ISS-023 (v0.21.0): Relocate — any GROUNDED plane can be repositioned to any airport via the
|
||||||
// existing fly endpoint (pure repositioning, no package needed since v0.12.0). Moved here from
|
// existing fly endpoint (pure repositioning, no package needed since v0.12.0). Moved here from
|
||||||
@@ -455,6 +462,53 @@ export default function LeftPane({ state, loading, error, onRefresh, applySnapsh
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
{/* ISS-043 (v0.26.0): flight queue — the not-yet-started legs with cancel, plus an
|
||||||
|
add control reusing this pane's already-fetched airport options (no second fetch). */}
|
||||||
|
<div className="queue-subsection">
|
||||||
|
<span className="queue-heading">Queue</span>
|
||||||
|
{plane.queue.map((icao, i) => (
|
||||||
|
<div key={`${icao}-${i}`} data-testid={`queue-leg-${i}`} className="queue-row">
|
||||||
|
<span className="contract-route">
|
||||||
|
{airportOptions?.find((a) => a.icao === icao)?.name ?? icao} ({icao})
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid={`queue-cancel-${i}`}
|
||||||
|
className="pane-btn"
|
||||||
|
disabled={actionsBusy}
|
||||||
|
onClick={() => void runAction(`/api/planes/${plane.id}/queue/cancel`, { index: i })}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
<div className="market-row">
|
||||||
|
<select
|
||||||
|
data-testid="queue-add-dest"
|
||||||
|
aria-label="Airport to add to the flight queue"
|
||||||
|
value={queueAddDestIcao ?? ''}
|
||||||
|
onChange={(e) => setQueueAddDestIcao(e.target.value || null)}
|
||||||
|
>
|
||||||
|
<option value="">Select an airport…</option>
|
||||||
|
{airportOptions?.map((a) => (
|
||||||
|
<option key={a.icao} value={a.icao}>
|
||||||
|
{a.name}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid="queue-add"
|
||||||
|
className="pane-btn"
|
||||||
|
disabled={actionsBusy || queueAddDestIcao === null}
|
||||||
|
onClick={() => {
|
||||||
|
if (queueAddDestIcao) void runAction(`/api/planes/${plane.id}/queue`, { destIcao: queueAddDestIcao });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Add to queue
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|||||||
+31
-1
@@ -8,7 +8,7 @@ import { DEFAULT_STYLE_ID, STYLES, STYLE_STORAGE_KEY, isStyleId, localAssetsAvai
|
|||||||
import type { GeoJsonFeatureCollection } from '../lib/airports';
|
import type { GeoJsonFeatureCollection } from '../lib/airports';
|
||||||
import type { StateSnapshot } from '../lib/game/state';
|
import type { StateSnapshot } from '../lib/game/state';
|
||||||
import type { HoverTarget } from './hoverTypes';
|
import type { HoverTarget } from './hoverTypes';
|
||||||
import { hoverRouteGeoJson, hoverTraceGeoJson, planesGeoJson, routesGeoJson, type AirportCoord, type PlaneFeatureProps } from '../lib/mapData';
|
import { hoverRouteGeoJson, hoverTraceGeoJson, planesGeoJson, queuedRoutesGeoJson, routesGeoJson, type AirportCoord, type PlaneFeatureProps } from '../lib/mapData';
|
||||||
import { weatherFor } from '../lib/weather';
|
import { weatherFor } from '../lib/weather';
|
||||||
import { approxLocalTime } from '../lib/localTime';
|
import { approxLocalTime } from '../lib/localTime';
|
||||||
|
|
||||||
@@ -28,6 +28,10 @@ const PLANES_GROUNDED_LAYER_ID = 'planes-grounded';
|
|||||||
const PLANES_FLYING_LAYER_ID = 'planes-flying';
|
const PLANES_FLYING_LAYER_ID = 'planes-flying';
|
||||||
const ROUTES_SOURCE_ID = 'routes';
|
const ROUTES_SOURCE_ID = 'routes';
|
||||||
const ROUTES_LEGS_LAYER_ID = 'routes-legs';
|
const ROUTES_LEGS_LAYER_ID = 'routes-legs';
|
||||||
|
// ISS-043 (v0.26.0): the dotted queue line — a flying plane's NOT-yet-started legs
|
||||||
|
// (dest → queue[0] → …) as their own source + layer, drawn under everything else dynamic.
|
||||||
|
const QUEUE_ROUTES_SOURCE_ID = 'queue-routes';
|
||||||
|
const QUEUE_ROUTES_LAYER_ID = 'queue-routes';
|
||||||
// ISS-002 (v0.15.0): top-most hover-highlight layers, added after the base layers so they
|
// ISS-002 (v0.15.0): top-most hover-highlight layers, added after the base layers so they
|
||||||
// render above them. Each starts filtered to match nothing; applyHoverRef drives the filters.
|
// render above them. Each starts filtered to match nothing; applyHoverRef drives the filters.
|
||||||
const PLANES_HIGHLIGHT_LAYER_ID = 'planes-highlight';
|
const PLANES_HIGHLIGHT_LAYER_ID = 'planes-highlight';
|
||||||
@@ -95,6 +99,11 @@ export default function FlightMap({ state, hovered, applySnapshot }: MapProps) {
|
|||||||
if (routesSource && airportsIndexRef.current) {
|
if (routesSource && airportsIndexRef.current) {
|
||||||
void routesSource.setData(routesGeoJson(st, airportsIndexRef.current));
|
void routesSource.setData(routesGeoJson(st, airportsIndexRef.current));
|
||||||
}
|
}
|
||||||
|
// ISS-043 (v0.26.0): the dotted queue line — same airport-index guard as the solid legs above.
|
||||||
|
const queueRoutesSource = map.getSource(QUEUE_ROUTES_SOURCE_ID) as maplibregl.GeoJSONSource | undefined;
|
||||||
|
if (queueRoutesSource && airportsIndexRef.current) {
|
||||||
|
void queueRoutesSource.setData(queuedRoutesGeoJson(st.planes, airportsIndexRef.current));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -357,6 +366,27 @@ export default function FlightMap({ state, hovered, applySnapshot }: MapProps) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// ISS-043 (v0.26.0): dotted queue line — added after routes-legs but BEFORE the hover
|
||||||
|
// layers so a hovered trace still draws on top of it. Muted slate + fine dots reads as
|
||||||
|
// "planned/future", distinct from the solid amber active leg and the [2,2] yellow hover dash.
|
||||||
|
if (!map.getSource(QUEUE_ROUTES_SOURCE_ID)) {
|
||||||
|
map.addSource(QUEUE_ROUTES_SOURCE_ID, {
|
||||||
|
type: 'geojson',
|
||||||
|
data: queuedRoutesGeoJson(stateRef.current?.planes ?? [], airportsIndexRef.current ?? new Map()),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!map.getLayer(QUEUE_ROUTES_LAYER_ID)) {
|
||||||
|
map.addLayer({
|
||||||
|
id: QUEUE_ROUTES_LAYER_ID,
|
||||||
|
type: 'line',
|
||||||
|
source: QUEUE_ROUTES_SOURCE_ID,
|
||||||
|
paint: {
|
||||||
|
'line-color': '#64748b', // muted slate — planned legs, not actively flying
|
||||||
|
'line-width': 3,
|
||||||
|
'line-dasharray': [0.1, 1.5], // dotted — distinct from solid legs and the [2,2] hover dash
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!map.getSource(PLANES_SOURCE_ID)) {
|
if (!map.getSource(PLANES_SOURCE_ID)) {
|
||||||
map.addSource(PLANES_SOURCE_ID, { type: 'geojson', data: planesGeoJson(stateRef.current) });
|
map.addSource(PLANES_SOURCE_ID, { type: 'geojson', data: planesGeoJson(stateRef.current) });
|
||||||
}
|
}
|
||||||
|
|||||||
+94
-12
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import type { PackageState, PlaneState, StateSnapshot } from '@/lib/game/state';
|
import type { PackageState, PlaneState, StateSnapshot } from '@/lib/game/state';
|
||||||
import { PLANE_TYPES } from '@/lib/game/catalog';
|
import { PLANE_TYPES, SELL_FRACTION } from '@/lib/game/catalog';
|
||||||
|
import { maxRangeKm } from '@/lib/sim/movement';
|
||||||
import { formatCash, formatDeadlineRelative } from '@/lib/format';
|
import { formatCash, formatDeadlineRelative } from '@/lib/format';
|
||||||
import { useGameAction } from '@/lib/useGameAction';
|
import { useGameAction } from '@/lib/useGameAction';
|
||||||
import type { HoverTarget } from './hoverTypes';
|
import type { HoverTarget } from './hoverTypes';
|
||||||
@@ -23,23 +24,25 @@ interface RightPaneProps {
|
|||||||
|
|
||||||
const planeName = (p: PlaneState): string => PLANE_TYPES[p.model]?.name ?? p.model;
|
const planeName = (p: PlaneState): string => PLANE_TYPES[p.model]?.name ?? p.model;
|
||||||
|
|
||||||
// Packages occupying a plane's slots — 'loaded' cargo plus 'expired' cargo, which
|
// Cargo weight (kg) occupying a plane's payload — 'loaded' cargo plus 'expired'
|
||||||
// keeps its slot until it is abandoned or the plane lands at its destination.
|
// cargo, which keeps its space until it is abandoned or the plane lands at its
|
||||||
export function slotsUsedFor(state: StateSnapshot, planeId: string): number {
|
// destination.
|
||||||
return state.packages.filter(
|
export function cargoWeightFor(state: StateSnapshot, planeId: string): number {
|
||||||
(p) => p.planeId === planeId && (p.status === 'loaded' || p.status === 'expired'),
|
return state.packages
|
||||||
).length;
|
.filter((p) => p.planeId === planeId && (p.status === 'loaded' || p.status === 'expired'))
|
||||||
|
.reduce((sum, p) => sum + p.weightKg, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Planes that can load `pkg` right now: GROUNDED at the package's origin with a
|
// Planes that can load `pkg` right now: GROUNDED at the package's origin with enough
|
||||||
// free slot (capacity from the snapshot catalog). The Load button is enabled iff
|
// payload room for it (maxPayloadKg from the snapshot catalog). The Load button is
|
||||||
// this list is non-empty; exactly one entry loads directly, several show a picker.
|
// enabled iff this list is non-empty; exactly one entry loads directly, several show a picker.
|
||||||
export function loadEligiblePlanes(state: StateSnapshot, pkg: PackageState): PlaneState[] {
|
export function loadEligiblePlanes(state: StateSnapshot, pkg: PackageState): PlaneState[] {
|
||||||
return state.planes.filter((p) => {
|
return state.planes.filter((p) => {
|
||||||
if (p.status !== 'available') return false;
|
if (p.status !== 'available') return false;
|
||||||
if (p.locationIcao !== pkg.originIcao) return false;
|
if (p.locationIcao !== pkg.originIcao) return false;
|
||||||
const capacity = state.catalog.find((e) => e.model === p.model)?.capacity ?? 0;
|
const maxPayloadKg = state.catalog.find((e) => e.model === p.model)?.maxPayloadKg ?? 0;
|
||||||
return slotsUsedFor(state, p.id) < capacity;
|
// Mirrors the server check in lib/game/actions.ts loadPackage.
|
||||||
|
return cargoWeightFor(state, p.id) + pkg.weightKg <= maxPayloadKg;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +120,9 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
const [buyModelId, setBuyModelId] = useState<string | null>(null);
|
const [buyModelId, setBuyModelId] = useState<string | null>(null);
|
||||||
const [sellPlaneId, setSellPlaneId] = useState<string | null>(null);
|
const [sellPlaneId, setSellPlaneId] = useState<string | null>(null);
|
||||||
|
|
||||||
|
// v0.28.0 (ISS-047): Jobs / Planes market tabs — the inactive tab's content unmounts.
|
||||||
|
const [activeTab, setActiveTab] = useState<'jobs' | 'planes'>('jobs');
|
||||||
|
|
||||||
// ISS-023 (v0.21.0): the Relocate row moved to the left pane — it belongs with everything else
|
// ISS-023 (v0.21.0): the Relocate row moved to the left pane — it belongs with everything else
|
||||||
// about our planes, not in the market. Its state + /api/airports fetch went with it.
|
// about our planes, not in the market. Its state + /api/airports fetch went with it.
|
||||||
// ISS-035 (v0.23.0): same for the Refuel-to-full row — its state + derived values moved to the
|
// ISS-035 (v0.23.0): same for the Refuel-to-full row — its state + derived values moved to the
|
||||||
@@ -148,6 +154,31 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
<aside data-testid="right-pane" className="pane right-pane">
|
<aside data-testid="right-pane" className="pane right-pane">
|
||||||
<h2 className="pane-title">Jobs & Market</h2>
|
<h2 className="pane-title">Jobs & Market</h2>
|
||||||
|
|
||||||
|
{/* v0.28.0 (ISS-047): Jobs / Planes market tabs — the inactive tab's content unmounts. */}
|
||||||
|
<div className="pane-tabs" role="tablist">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid="tab-jobs"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={activeTab === 'jobs'}
|
||||||
|
className="tab-btn"
|
||||||
|
onClick={() => setActiveTab('jobs')}
|
||||||
|
>
|
||||||
|
Jobs
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid="tab-planes-market"
|
||||||
|
role="tab"
|
||||||
|
aria-selected={activeTab === 'planes'}
|
||||||
|
className="tab-btn"
|
||||||
|
onClick={() => setActiveTab('planes')}
|
||||||
|
>
|
||||||
|
Planes market
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{activeTab === 'jobs' && (
|
||||||
<section className="pane-section">
|
<section className="pane-section">
|
||||||
<h3 className="pane-heading">Packages</h3>
|
<h3 className="pane-heading">Packages</h3>
|
||||||
{open.length === 0 ? (
|
{open.length === 0 ? (
|
||||||
@@ -179,6 +210,16 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
Load
|
Load
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
{/* ISS-047 part B (v0.29.0): dismiss the job — it leaves the market permanently, no penalty. */}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
data-testid={`ignore-${pkg.id}`}
|
||||||
|
className="pane-btn"
|
||||||
|
disabled={busy}
|
||||||
|
onClick={() => void runAction(`/api/packages/${pkg.id}/ignore`)}
|
||||||
|
>
|
||||||
|
Ignore
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="contract-sub">
|
<div className="contract-sub">
|
||||||
<span data-testid={`open-package-reward-${pkg.id}`}>{formatCash(pkg.reward)}</span>
|
<span data-testid={`open-package-reward-${pkg.id}`}>{formatCash(pkg.reward)}</span>
|
||||||
@@ -193,9 +234,11 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</section>
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* ISS-021 (v0.20.0): the On board section moved to the left pane (between Fleet and Time). */}
|
{/* ISS-021 (v0.20.0): the On board section moved to the left pane (between Fleet and Time). */}
|
||||||
|
|
||||||
|
{activeTab === 'planes' && (
|
||||||
<section className="pane-section">
|
<section className="pane-section">
|
||||||
<h3 className="pane-heading">Market</h3>
|
<h3 className="pane-heading">Market</h3>
|
||||||
|
|
||||||
@@ -259,7 +302,46 @@ export default function RightPane({ state, loading, applySnapshot, onHover, onEr
|
|||||||
|
|
||||||
{/* ISS-023 (v0.21.0): the Relocate row moved to the left pane's "Relocate" section. */}
|
{/* ISS-023 (v0.21.0): the Relocate row moved to the left pane's "Relocate" section. */}
|
||||||
{/* ISS-035 (v0.23.0): the Refuel-to-full row moved to the left pane's "Refuel" section, next to Relocate. */}
|
{/* ISS-035 (v0.23.0): the Refuel-to-full row moved to the left pane's "Refuel" section, next to Relocate. */}
|
||||||
|
|
||||||
|
{/* v0.28.0 (ISS-047): tech-spec panel per catalog type — progression order (price ascending).
|
||||||
|
All values come from the snapshot's catalog; max range is the weighted-model closed form. */}
|
||||||
|
{[...catalog].sort((a, b) => a.price - b.price).map((e) => (
|
||||||
|
<div key={e.model} className="plane-type-card" data-testid={`plane-type-${e.model}`}>
|
||||||
|
<h4 className="plane-type-name">{e.label}</h4>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Buy</span>
|
||||||
|
<strong>{formatCash(e.price)}</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Sell</span>
|
||||||
|
<strong>{formatCash(Math.round(e.price * SELL_FRACTION * 100) / 100)}</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Payload</span>
|
||||||
|
<strong>{(e.maxPayloadKg / 1000).toFixed(1)}t</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Cruise speed</span>
|
||||||
|
<strong>{e.speedKmh} km/h</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Fuel burn</span>
|
||||||
|
<strong>{e.burnPerKm} L/km</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Max fuel</span>
|
||||||
|
<strong>{e.maxFuel} L</strong>
|
||||||
|
</div>
|
||||||
|
<div className="stat-row">
|
||||||
|
<span>Max range</span>
|
||||||
|
<strong data-testid={`plane-type-range-${e.model}`}>
|
||||||
|
{Math.round(maxRangeKm(e.burnPerKm, e.emptyWeightKg, e.maxFuel))} km
|
||||||
|
</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</section>
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
{actionError && <p data-testid="right-error" className="pane-error">{actionError}</p>}
|
{actionError && <p data-testid="right-error" className="pane-error">{actionError}</p>}
|
||||||
</aside>
|
</aside>
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import { loadEligiblePlanes, slotsUsedFor } from './RightPane';
|
import { cargoWeightFor, loadEligiblePlanes } from './RightPane';
|
||||||
import type { PackageState, PlaneState, StateSnapshot } from '@/lib/game/state';
|
import type { PackageState, PlaneState, StateSnapshot } from '@/lib/game/state';
|
||||||
|
|
||||||
// v0.12.0 — the package-model picker rules: a plane can LOAD a package only while
|
// v0.12.0 (weight model v0.27.0) — the package-model picker rules: a plane can LOAD a
|
||||||
// it is GROUNDED at the package's origin with a free slot (capacity from the
|
// package only while it is GROUNDED at the package's origin with enough payload room for
|
||||||
// snapshot catalog; expired packages still occupy theirs). The Load button acts
|
// it (maxPayloadKg from the snapshot catalog; expired packages still occupy theirs). The
|
||||||
// directly on the single eligible plane, or shows a picker when several qualify.
|
// Load button acts directly on the single eligible plane, or shows a picker when several qualify.
|
||||||
|
|
||||||
const CATALOG = [
|
const CATALOG = [
|
||||||
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9_300, speedKmh: 510, capacity: 6 },
|
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9_300, speedKmh: 510, maxPayloadKg: 4_800 },
|
||||||
];
|
];
|
||||||
|
|
||||||
function plane(over: Partial<PlaneState> & Pick<PlaneState, 'id'>): PlaneState {
|
function plane(over: Partial<PlaneState> & Pick<PlaneState, 'id'>): PlaneState {
|
||||||
@@ -38,6 +38,7 @@ function pkg(over: Partial<PackageState> & Pick<PackageState, 'id'>): PackageSta
|
|||||||
reward: 1000,
|
reward: 1000,
|
||||||
cargoType: 'mail',
|
cargoType: 'mail',
|
||||||
cargoCount: 4,
|
cargoCount: 4,
|
||||||
|
weightKg: 1_000,
|
||||||
deadlineSimTime: 1_000_000,
|
deadlineSimTime: 1_000_000,
|
||||||
status: 'open',
|
status: 'open',
|
||||||
planeId: null,
|
planeId: null,
|
||||||
@@ -58,27 +59,27 @@ function snap(planes: PlaneState[], packages: PackageState[] = []): StateSnapsho
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('slotsUsedFor', () => {
|
describe('cargoWeightFor', () => {
|
||||||
it('counts loaded AND expired packages bound to the plane (both occupy a slot)', () => {
|
it('sums the weight of loaded AND expired packages bound to the plane (both occupy payload)', () => {
|
||||||
const s = snap(
|
const s = snap(
|
||||||
[plane({ id: 'p1' })],
|
[plane({ id: 'p1' })],
|
||||||
[
|
[
|
||||||
pkg({ id: 'a', status: 'loaded', planeId: 'p1' }),
|
pkg({ id: 'a', status: 'loaded', planeId: 'p1', weightKg: 800 }),
|
||||||
pkg({ id: 'b', status: 'expired', planeId: 'p1' }),
|
pkg({ id: 'b', status: 'expired', planeId: 'p1', weightKg: 500 }),
|
||||||
pkg({ id: 'c', status: 'open', planeId: null }), // not on any plane
|
pkg({ id: 'c', status: 'open', planeId: null, weightKg: 9_000 }), // not on any plane
|
||||||
pkg({ id: 'd', status: 'delivered', planeId: 'p1' }), // terminal — slot long freed
|
pkg({ id: 'd', status: 'delivered', planeId: 'p1', weightKg: 700 }), // terminal — payload long freed
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
expect(slotsUsedFor(s, 'p1')).toBe(2);
|
expect(cargoWeightFor(s, 'p1')).toBe(1_300);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is 0 for a plane with no bound cargo', () => {
|
it('is 0 for a plane with no bound cargo', () => {
|
||||||
expect(slotsUsedFor(snap([plane({ id: 'p1' })]), 'p1')).toBe(0);
|
expect(cargoWeightFor(snap([plane({ id: 'p1' })]), 'p1')).toBe(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('loadEligiblePlanes (Load button eligibility)', () => {
|
describe('loadEligiblePlanes (Load button eligibility)', () => {
|
||||||
it('includes only grounded planes at the package origin with a free slot', () => {
|
it('includes only grounded planes at the package origin with enough payload room', () => {
|
||||||
const s = snap([
|
const s = snap([
|
||||||
plane({ id: 'at-origin' }), // eligible
|
plane({ id: 'at-origin' }), // eligible
|
||||||
plane({ id: 'elsewhere', locationIcao: 'LEMD' }), // wrong airport
|
plane({ id: 'elsewhere', locationIcao: 'LEMD' }), // wrong airport
|
||||||
@@ -87,18 +88,23 @@ describe('loadEligiblePlanes (Load button eligibility)', () => {
|
|||||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' })).map((p) => p.id)).toEqual(['at-origin']);
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' })).map((p) => p.id)).toEqual(['at-origin']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('excludes a plane whose slots are full (capacity from the catalog)', () => {
|
it('a plane with partial payload can still load a package that fits', () => {
|
||||||
const packages = Array.from({ length: 6 }, (_, i) =>
|
const s = snap([plane({ id: 'partial' })], [pkg({ id: 'onboard', status: 'loaded', planeId: 'partial', weightKg: 3_000 })]);
|
||||||
pkg({ id: `fill-${i}`, status: 'loaded', planeId: 'full' }),
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' })).map((p) => p.id)).toEqual(['partial']); // 3000 + 1000 ≤ 4800
|
||||||
|
});
|
||||||
|
|
||||||
|
it('excludes a plane whose payload is full (maxPayloadKg from the catalog)', () => {
|
||||||
|
const packages = Array.from({ length: 4 }, (_, i) =>
|
||||||
|
pkg({ id: `fill-${i}`, status: 'loaded', planeId: 'full', weightKg: 1_200 }), // 4 × 1200 = 4800
|
||||||
);
|
);
|
||||||
const s = snap([plane({ id: 'full' })], packages);
|
const s = snap([plane({ id: 'full' })], packages);
|
||||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('a full plane with one slot freed by an expired package still counts as full', () => {
|
it('a plane at its limit with an expired package still counts as full', () => {
|
||||||
const packages = [
|
const packages = [
|
||||||
...Array.from({ length: 5 }, (_, i) => pkg({ id: `fill-${i}`, status: 'loaded', planeId: 'full' })),
|
...Array.from({ length: 4 }, (_, i) => pkg({ id: `fill-${i}`, status: 'loaded', planeId: 'full', weightKg: 960 })),
|
||||||
pkg({ id: 'exp', status: 'expired', planeId: 'full' }), // occupies its slot
|
pkg({ id: 'exp', status: 'expired', planeId: 'full', weightKg: 960 }), // occupies its payload — 5 × 960 = 4800
|
||||||
];
|
];
|
||||||
const s = snap([plane({ id: 'full' })], packages);
|
const s = snap([plane({ id: 'full' })], packages);
|
||||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
||||||
@@ -114,7 +120,7 @@ describe('loadEligiblePlanes (Load button eligibility)', () => {
|
|||||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('a plane with an unknown model has no capacity → never eligible', () => {
|
it('a plane with an unknown model has no maxPayloadKg in the catalog → never eligible', () => {
|
||||||
const s = snap([plane({ id: 'mystery', model: 'mystery' })]);
|
const s = snap([plane({ id: 'mystery', model: 'mystery' })]);
|
||||||
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
expect(loadEligiblePlanes(s, pkg({ id: 'x' }))).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|||||||
+16
-7
@@ -53,8 +53,16 @@ async function getState(page: Page): Promise<StateBody> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The e2e instance runs with FLIGHT_TEST_HOOKS=1 (docker-compose.yml) — the hook is live.
|
// The e2e instance runs with FLIGHT_TEST_HOOKS=1 (docker-compose.yml) — the hook is live.
|
||||||
async function createPackage(page: Page, from?: string, to?: string, deadlineOffsetMs?: number): Promise<StateBody['packages'][number]> {
|
// weightKg (v0.27.0) forces the package weight instead of the RNG draw, so flows that load
|
||||||
const res = await page.request.post('/api/test/create-package', { data: { originIcao: from, destIcao: to, deadlineOffsetMs } });
|
// several packages onto one plane stay under its payload deterministically.
|
||||||
|
async function createPackage(
|
||||||
|
page: Page,
|
||||||
|
from?: string,
|
||||||
|
to?: string,
|
||||||
|
deadlineOffsetMs?: number,
|
||||||
|
weightKg?: number,
|
||||||
|
): Promise<StateBody['packages'][number]> {
|
||||||
|
const res = await page.request.post('/api/test/create-package', { data: { originIcao: from, destIcao: to, deadlineOffsetMs, weightKg } });
|
||||||
expect(res.status()).toBe(201);
|
expect(res.status()).toBe(201);
|
||||||
return (await res.json()) as StateBody['packages'][number];
|
return (await res.json()) as StateBody['packages'][number];
|
||||||
}
|
}
|
||||||
@@ -240,9 +248,10 @@ test('abandon while grounded deducts exactly the formula penalty', async ({ page
|
|||||||
await flyHomeViaApi(page);
|
await flyHomeViaApi(page);
|
||||||
const before = await getState(page);
|
const before = await getState(page);
|
||||||
|
|
||||||
// Two packages at the hub — load both, abandon one through the UI.
|
// Two packages at the hub — load both, abandon one through the UI. Forced weights keep
|
||||||
const pkgA = await createPackage(page, HUB, 'LEMD', 24 * 3_600_000);
|
// the pair under the starter's payload (v0.27.0) so both loads are deterministic.
|
||||||
const pkgB = await createPackage(page, HUB, 'LEMD', 24 * 3_600_000);
|
const pkgA = await createPackage(page, HUB, 'LEMD', 24 * 3_600_000, 1_000);
|
||||||
|
const pkgB = await createPackage(page, HUB, 'LEMD', 24 * 3_600_000, 1_000);
|
||||||
for (const p of [pkgA, pkgB]) {
|
for (const p of [pkgA, pkgB]) {
|
||||||
const res = await page.request.post(`/api/packages/${p.id}/load`, { data: { planeId: 'plane-starter' } });
|
const res = await page.request.post(`/api/packages/${p.id}/load`, { data: { planeId: 'plane-starter' } });
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
@@ -282,8 +291,8 @@ test('expired packages deliver and abandon with no reward and no penalty', async
|
|||||||
// destination differs from A's so it stays bound on the plane at LEMD arrival and can
|
// destination differs from A's so it stays bound on the plane at LEMD arrival and can
|
||||||
// still be abandoned (an expired package whose dest matches the arrival airport is
|
// still be abandoned (an expired package whose dest matches the arrival airport is
|
||||||
// unbound by the tick instead).
|
// unbound by the tick instead).
|
||||||
const pkgA = await createPackage(page, HUB, 'LEMD', 10_000); // short game-time deadline
|
const pkgA = await createPackage(page, HUB, 'LEMD', 10_000, 1_000); // short game-time deadline; forced weights keep the pair under payload (v0.27.0)
|
||||||
const pkgB = await createPackage(page, HUB, 'EHAM', 10_000);
|
const pkgB = await createPackage(page, HUB, 'EHAM', 10_000, 1_000);
|
||||||
for (const p of [pkgA, pkgB]) {
|
for (const p of [pkgA, pkgB]) {
|
||||||
const res = await page.request.post(`/api/packages/${p.id}/load`, { data: { planeId: 'plane-starter' } });
|
const res = await page.request.post(`/api/packages/${p.id}/load`, { data: { planeId: 'plane-starter' } });
|
||||||
expect(res.ok()).toBeTruthy();
|
expect(res.ok()).toBeTruthy();
|
||||||
|
|||||||
+2
-1
@@ -13,7 +13,7 @@ test('GET /api/version returns the app version from package.json', async ({ page
|
|||||||
expect(body.version).toBe(pkg.version);
|
expect(body.version).toBe(pkg.version);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GET /api/openapi serves the spec with all twelve endpoints and the package.json version', async ({ page }) => {
|
test('GET /api/openapi serves the spec with all thirteen endpoints and the package.json version', async ({ page }) => {
|
||||||
const res = await page.request.get('/api/openapi');
|
const res = await page.request.get('/api/openapi');
|
||||||
expect(res.status()).toBe(200);
|
expect(res.status()).toBe(200);
|
||||||
expect(res.headers()['content-type']).toContain('application/json');
|
expect(res.headers()['content-type']).toContain('application/json');
|
||||||
@@ -26,6 +26,7 @@ test('GET /api/openapi serves the spec with all twelve endpoints and the package
|
|||||||
'/api/market/buy-plane',
|
'/api/market/buy-plane',
|
||||||
'/api/market/sell-plane',
|
'/api/market/sell-plane',
|
||||||
'/api/packages/{id}/abandon',
|
'/api/packages/{id}/abandon',
|
||||||
|
'/api/packages/{id}/ignore', // v0.29.0 (ISS-047 part B)
|
||||||
'/api/packages/{id}/load',
|
'/api/packages/{id}/load',
|
||||||
'/api/planes/{planeId}/fly',
|
'/api/planes/{planeId}/fly',
|
||||||
'/api/planes/{planeId}/queue',
|
'/api/planes/{planeId}/queue',
|
||||||
|
|||||||
+7
-2
@@ -62,10 +62,10 @@ test('left pane renders wallet, reputation and the starter fleet at Frankfurt',
|
|||||||
await expect(row).toContainText(truth.locationName);
|
await expect(row).toContainText(truth.locationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// v0.12.0 loadout: "n/capacity pkgs" (capacity from the snapshot catalog — ATR 72-600 = 6).
|
// v0.27.0 loadout: "X.Xt / Y.Yt" tonnage (used/max payload from the snapshot catalog — ATR 72-600 = 4.8t).
|
||||||
const loadout = page.getByTestId('plane-loadout-plane-starter');
|
const loadout = page.getByTestId('plane-loadout-plane-starter');
|
||||||
await expect(loadout).toBeVisible();
|
await expect(loadout).toBeVisible();
|
||||||
expect((await loadout.textContent()) ?? '').toMatch(/^\d+\/6 pkgs$/);
|
expect((await loadout.textContent()) ?? '').toMatch(/^\d+\.\dt \/ \d+\.\dt$/);
|
||||||
|
|
||||||
// Sim clock renders (UTC wall-clock of the game time).
|
// Sim clock renders (UTC wall-clock of the game time).
|
||||||
await expect(page.getByTestId('sim-clock')).toContainText(/UTC/);
|
await expect(page.getByTestId('sim-clock')).toContainText(/UTC/);
|
||||||
@@ -190,4 +190,9 @@ test('right pane placeholder exists with the Jobs & Market heading', async ({ pa
|
|||||||
const right = page.getByTestId('right-pane');
|
const right = page.getByTestId('right-pane');
|
||||||
await expect(right).toBeVisible();
|
await expect(right).toBeVisible();
|
||||||
await expect(right).toContainText('Jobs & Market');
|
await expect(right).toContainText('Jobs & Market');
|
||||||
|
|
||||||
|
// v0.28.0 (ISS-047): the Jobs / Planes market tab bar renders once a snapshot lands; Jobs is default-active.
|
||||||
|
await expect(page.getByTestId('tab-jobs'), 'the Jobs tab button appears').toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(page.getByTestId('tab-planes-market')).toBeVisible();
|
||||||
|
await expect(page.getByTestId('tab-jobs')).toHaveAttribute('aria-selected', 'true');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,384 @@
|
|||||||
|
import { test, expect, type Page } from '@playwright/test';
|
||||||
|
|
||||||
|
// v0.26.0 — ISS-043 part 2 (UI): the flight queue. A plane's not-yet-started legs show up in a
|
||||||
|
// Queue sub-section of its on-board block (add via airport select + button, cancel per leg), and
|
||||||
|
// a flying plane with queued legs draws them as a DOTTED line (`queue-routes` layer) chaining
|
||||||
|
// dest → queue[0] → … — the active leg stays in the solid `routes-legs` layer. Landing auto-starts
|
||||||
|
// the next queued leg server-side (part 1); test 3 exercises that chain end-to-end through the API.
|
||||||
|
|
||||||
|
const SCALE = 1000; // fastest sim speed (v0.14.0 ladder top) — keeps flights to seconds of real time
|
||||||
|
const HUB = 'EDDF'; // must match HUB_ICAO in lib/game/seed.ts
|
||||||
|
const DEST = 'LEMD'; // Madrid–Barajas — the typical long leg (~10 s at scale 1000)
|
||||||
|
const QUEUE = 'EHAM'; // Amsterdam — a third airport, distinct from hub and destination
|
||||||
|
|
||||||
|
interface PlaneState {
|
||||||
|
id: string;
|
||||||
|
status: 'available' | 'flying';
|
||||||
|
locationIcao: string;
|
||||||
|
destIcao: string | null;
|
||||||
|
queue: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PackageState {
|
||||||
|
id: string;
|
||||||
|
originIcao: string;
|
||||||
|
destIcao: string;
|
||||||
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
||||||
|
planeId: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface StateBody {
|
||||||
|
account: { cash: number; reputation: number };
|
||||||
|
simState: { clockMs: number; timeScale: number; paused: boolean };
|
||||||
|
planes: PlaneState[];
|
||||||
|
packages: PackageState[];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getState(page: Page): Promise<StateBody> {
|
||||||
|
const res = await page.request.get('/api/state');
|
||||||
|
expect(res.status()).toBe(200);
|
||||||
|
return (await res.json()) as StateBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function postSim(page: Page, body: unknown) {
|
||||||
|
return page.request.post('/api/sim', { data: body });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the time scale and VERIFY from the response that it stuck. ISS-041 also clears pause: a
|
||||||
|
// landing pauses the sim, so any fast-forward after one must resume it or the clock stays frozen.
|
||||||
|
async function setScale(page: Page, scale: number): Promise<void> {
|
||||||
|
const res = await page.request.post('/api/sim', { data: { timeScale: scale, paused: false } });
|
||||||
|
expect(res.status()).toBe(200);
|
||||||
|
const body = (await res.json()) as { timeScale: number };
|
||||||
|
expect(body.timeScale, `timeScale should be ${scale} after POST /api/sim`).toBe(scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leave the live instance in a sane state for the other specs (scale 1, running).
|
||||||
|
test.afterEach(async ({ page }) => {
|
||||||
|
const res = await postSim(page, { timeScale: 1, paused: false });
|
||||||
|
expect(res.status()).toBe(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Test hook (FLIGHT_TEST_HOOKS=1): create an open package on a known route.
|
||||||
|
async function createPackage(page: Page, fromIcao: string, toIcao: string): Promise<PackageState> {
|
||||||
|
const created = await page.request.post('/api/test/create-package', {
|
||||||
|
data: { originIcao: fromIcao, destIcao: toIcao, deadlineOffsetMs: 24 * 3_600_000 },
|
||||||
|
});
|
||||||
|
expect(created.status()).toBe(201);
|
||||||
|
return (await created.json()) as PackageState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Self-heal: let any in-flight leg finish, reposition plane-starter home via the API, and abandon
|
||||||
|
// leftover cargo so every test starts from the canonical state even after an interrupted run.
|
||||||
|
async function flyHomeViaApi(page: Page): Promise<void> {
|
||||||
|
let s = await getState(page);
|
||||||
|
let plane = s.planes.find((p) => p.id === 'plane-starter')!;
|
||||||
|
if (plane.status === 'flying' || plane.locationIcao !== HUB) {
|
||||||
|
// Fast-forward any leftover leg / repositioning flight (~20 s real time worst case at 1000×).
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
}
|
||||||
|
if (plane.status === 'flying') {
|
||||||
|
// While flying, locationIcao stays at the DEPARTURE airport — re-read state after landing.
|
||||||
|
await expect
|
||||||
|
.poll(async () => ((await getState(page)).planes.find((p) => p.id === 'plane-starter')?.status ?? ''), {
|
||||||
|
timeout: 240_000,
|
||||||
|
message: 'waiting for an in-flight plane-starter to land',
|
||||||
|
})
|
||||||
|
.toBe('available');
|
||||||
|
s = await getState(page);
|
||||||
|
plane = s.planes.find((p) => p.id === 'plane-starter')!;
|
||||||
|
}
|
||||||
|
if (plane.locationIcao !== HUB) {
|
||||||
|
// ISS-041: the landing above paused the sim — setScale clears pause so the return leg fast-forwards.
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
const res = await page.request.post(`/api/planes/${plane.id}/fly`, { data: { destIcao: HUB } });
|
||||||
|
expect(res.status()).toBe(200); // repositioning needs no package (v0.12.0 manual flight)
|
||||||
|
await expect
|
||||||
|
.poll(async () => ((await getState(page)).planes.find((p) => p.id === 'plane-starter')?.locationIcao ?? ''), {
|
||||||
|
timeout: 240_000,
|
||||||
|
message: 'waiting for plane-starter to land back at the hub',
|
||||||
|
})
|
||||||
|
.toBe(HUB);
|
||||||
|
}
|
||||||
|
// Abandon leftover loaded/expired packages (the baseline is captured AFTER this cleanup).
|
||||||
|
const s1 = await getState(page);
|
||||||
|
for (const pkg of s1.packages) {
|
||||||
|
if (pkg.planeId === 'plane-starter' && (pkg.status === 'loaded' || pkg.status === 'expired')) {
|
||||||
|
const res = await page.request.post(`/api/packages/${pkg.id}/abandon`);
|
||||||
|
expect(res.ok()).toBeTruthy();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForAirportCount(page: Page): Promise<void> {
|
||||||
|
const countEl = page.getByTestId('airport-count');
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const text = (await countEl.textContent()) ?? '';
|
||||||
|
const m = text.match(/(\d+)/);
|
||||||
|
return m ? parseInt(m[1], 10) : -1;
|
||||||
|
}).toBeGreaterThan(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rendered features of the given layers in the current viewport, [] until the map exists.
|
||||||
|
function renderedFeatures(
|
||||||
|
page: Page,
|
||||||
|
layers: string[],
|
||||||
|
): Promise<Array<{ type?: unknown; id?: unknown; properties?: unknown; geometry?: unknown }>> {
|
||||||
|
return page.evaluate((ls: string[]) => {
|
||||||
|
const m = (window as any).__flightMap;
|
||||||
|
if (!m) return [];
|
||||||
|
try {
|
||||||
|
// queryRenderedFeatures returns live GeoJSONFeature instances whose `geometry` is a lazy
|
||||||
|
// PROTOTYPE getter — Playwright's evaluate serialization copies only own enumerable props, so
|
||||||
|
// geometry silently vanishes across the page boundary. Map to plain objects IN-PAGE (ORCHESTRATOR §6).
|
||||||
|
return (m.queryRenderedFeatures(undefined, { layers: ls }) as Array<{
|
||||||
|
type?: unknown;
|
||||||
|
id?: unknown;
|
||||||
|
properties?: unknown;
|
||||||
|
geometry?: unknown;
|
||||||
|
}>).map((f) => ({
|
||||||
|
type: f.type,
|
||||||
|
id: f.id,
|
||||||
|
properties: f.properties,
|
||||||
|
geometry: f.geometry,
|
||||||
|
}));
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}, layers);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fit the map so all given airports are in-viewport — queryRenderedFeatures only returns features
|
||||||
|
// rendered inside the CURRENT viewport (same helper as e2e/hover.spec.ts).
|
||||||
|
async function fitToAirports(page: Page, icaos: string[]): Promise<void> {
|
||||||
|
const fc = (await (await page.request.get('/api/airports')).json()) as {
|
||||||
|
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
|
||||||
|
};
|
||||||
|
const points = icaos.map((icao) => {
|
||||||
|
const f = fc.features.find((x) => x.properties.icao === icao);
|
||||||
|
if (!f) throw new Error(`airport ${icao} not found in /api/airports`);
|
||||||
|
return [f.properties.lon, f.properties.lat] as [number, number];
|
||||||
|
});
|
||||||
|
await page.evaluate((pts: [number, number][]) => {
|
||||||
|
const m = (window as any).__flightMap;
|
||||||
|
if (!m) throw new Error('map not ready');
|
||||||
|
const lons = pts.map((p) => p[0]);
|
||||||
|
const lats = pts.map((p) => p[1]);
|
||||||
|
// duration 0 → instant camera jump, no animation to wait out.
|
||||||
|
m.fitBounds(
|
||||||
|
[
|
||||||
|
[Math.min(...lons), Math.min(...lats)],
|
||||||
|
[Math.max(...lons), Math.max(...lats)],
|
||||||
|
],
|
||||||
|
{ padding: 40, duration: 0 },
|
||||||
|
);
|
||||||
|
}, points);
|
||||||
|
// Give the renderer a beat after the camera jump before asserting on rendered features.
|
||||||
|
await page.waitForTimeout(300);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [lon, lat] of an airport from the same /api/airports dataset the map draws its lines from.
|
||||||
|
async function airportLonLat(page: Page, icao: string): Promise<[number, number]> {
|
||||||
|
const fc = (await (await page.request.get('/api/airports')).json()) as {
|
||||||
|
features: Array<{ properties: { icao: string; lat: number; lon: number } }>;
|
||||||
|
};
|
||||||
|
const f = fc.features.find((x) => x.properties.icao === icao);
|
||||||
|
if (!f) throw new Error(`airport ${icao} not found in /api/airports`);
|
||||||
|
return [f.properties.lon, f.properties.lat];
|
||||||
|
}
|
||||||
|
|
||||||
|
// MapLibre stores GeoJSON geometry in per-tile INTEGER grids and clips long lines across tiles, so
|
||||||
|
// queryRenderedFeatures returns ONE FEATURE PER TILE the line crosses with coordinates quantized to
|
||||||
|
// the grid — check endpoints ACROSS all segments with an EPS (same pattern as expectHoverRoute in
|
||||||
|
// e2e/hover.spec.ts). ~5 km: above worst-case quantization at any zoom, below the distance between
|
||||||
|
// any two EU airports.
|
||||||
|
const QUEUE_ROUTE_EPS_DEG = 0.05;
|
||||||
|
|
||||||
|
test.describe.configure({ mode: 'serial' }); // shared live DB — order matters within this file
|
||||||
|
|
||||||
|
test('queue display + cancel via UI (ISS-043 part 2)', async ({ page }) => {
|
||||||
|
test.setTimeout(300_000); // self-heal can take minutes after an interrupted run
|
||||||
|
await flyHomeViaApi(page); // deterministic: the starter sits grounded at EDDF
|
||||||
|
|
||||||
|
// Full tank before departure — keeps the long EDDF→LEMD leg fuel-feasible (same as tests 2 & 3).
|
||||||
|
const refuel = await page.request.post('/api/planes/plane-starter/refuel');
|
||||||
|
expect(refuel.status()).toBe(200);
|
||||||
|
|
||||||
|
const pkg = await createPackage(page, HUB, DEST);
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForAirportCount(page);
|
||||||
|
|
||||||
|
// LOAD via the UI (right-pane job list) — the starter is grounded at the package's origin.
|
||||||
|
const loadBtn = page.getByTestId(`load-${pkg.id}`);
|
||||||
|
await expect(loadBtn, 'Load button enabled for a package at the hub').toBeEnabled({ timeout: 15_000 });
|
||||||
|
await loadBtn.click();
|
||||||
|
const onboardRow = page.getByTestId(`onboard-package-${pkg.id}`);
|
||||||
|
await expect(onboardRow, 'loaded package appears in the On board section').toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// LeftPane's own /api/airports fetch populates the queue-add select — wait for it.
|
||||||
|
const addSelect = page.getByTestId('queue-add-dest');
|
||||||
|
await expect(addSelect.locator(`option[value="${QUEUE}"]`)).toHaveCount(1, { timeout: 15_000 });
|
||||||
|
|
||||||
|
// START leg 1 via the UI (fly-to button in the on-board block).
|
||||||
|
const flyBtn = page.getByTestId(`fly-to-${pkg.id}`);
|
||||||
|
await expect(flyBtn).toBeEnabled();
|
||||||
|
await flyBtn.click();
|
||||||
|
// The click fires the fly POST asynchronously — poll until it took effect server-side, then FREEZE
|
||||||
|
// immediately: at scale 1000 (left over from self-heal) the ~10 s leg would otherwise land under us.
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const p = (await getState(page)).planes.find((x) => x.id === 'plane-starter');
|
||||||
|
return !!p && p.status === 'flying' && p.destIcao === DEST;
|
||||||
|
}, { timeout: 15_000, message: 'waiting for the fly click to take effect (status "flying" + dest set)' }).toBe(true);
|
||||||
|
await postSim(page, { paused: true }); // pause-sim pattern: deterministic window for UI clicks
|
||||||
|
|
||||||
|
// ADD a leg to the queue via the UI. The button is disabled until an airport is selected…
|
||||||
|
const addButton = page.getByTestId('queue-add');
|
||||||
|
await expect(addButton).toBeDisabled();
|
||||||
|
await addSelect.selectOption(QUEUE);
|
||||||
|
await expect(addButton).toBeEnabled();
|
||||||
|
await addButton.click();
|
||||||
|
|
||||||
|
// …and the new leg appears as queue-leg-0 with its destination.
|
||||||
|
const legRow = page.getByTestId('queue-leg-0');
|
||||||
|
await expect(legRow, 'the queued leg appears in the Queue sub-section').toContainText(QUEUE, { timeout: 15_000 });
|
||||||
|
|
||||||
|
// CANCEL it via the UI and assert it's gone.
|
||||||
|
await page.getByTestId('queue-cancel-0').click();
|
||||||
|
await expect(page.getByTestId('queue-leg-0'), 'the cancelled leg is removed from the queue').toHaveCount(0, { timeout: 15_000 });
|
||||||
|
|
||||||
|
// Cleanup: resume + fast-forward to arrival at DEST (empty queue → plain landing), then fly home.
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const p = (await getState(page)).planes.find((x) => x.id === 'plane-starter');
|
||||||
|
return !!p && p.status === 'available' && p.locationIcao === DEST;
|
||||||
|
}, { timeout: 120_000, message: `waiting for plane-starter to land at ${DEST}` }).toBe(true);
|
||||||
|
|
||||||
|
// ISS-041: the arrival above paused the sim — setScale clears pause for the return leg.
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
const home = await page.request.post('/api/planes/plane-starter/fly', { data: { destIcao: HUB } });
|
||||||
|
expect(home.status()).toBe(200);
|
||||||
|
await expect.poll(async () => ((await getState(page)).planes.find((p) => p.id === 'plane-starter')?.locationIcao ?? ''), {
|
||||||
|
timeout: 120_000,
|
||||||
|
message: 'waiting for plane-starter to land back at the hub',
|
||||||
|
}).toBe(HUB);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('dotted queue line renders the queued path on the map (ISS-043 part 2)', async ({ page }) => {
|
||||||
|
test.setTimeout(300_000); // self-heal + one flight at scale 1000 + fly-home cleanup
|
||||||
|
await flyHomeViaApi(page);
|
||||||
|
|
||||||
|
// Full tank before departure — keeps the state canonical for whatever the cleanup does.
|
||||||
|
const refuel = await page.request.post('/api/planes/plane-starter/refuel');
|
||||||
|
expect(refuel.status()).toBe(200);
|
||||||
|
|
||||||
|
// Load + queue + fly via the API: a package EDDF→LEMD, one queued leg LEMD→EHAM (works while
|
||||||
|
// grounded — part 1), then start leg 1. The dotted line must show ONLY dest → queue[0].
|
||||||
|
const pkg = await createPackage(page, HUB, DEST);
|
||||||
|
const load = await page.request.post(`/api/packages/${pkg.id}/load`, { data: { planeId: 'plane-starter' } });
|
||||||
|
expect(load.status()).toBe(200);
|
||||||
|
const queueRes = await page.request.post('/api/planes/plane-starter/queue', { data: { destIcao: QUEUE } });
|
||||||
|
expect(queueRes.status()).toBe(200);
|
||||||
|
const flyRes = await page.request.post('/api/planes/plane-starter/fly', { data: { destIcao: DEST } });
|
||||||
|
expect(flyRes.status()).toBe(200);
|
||||||
|
// The endpoint's OWN post-action snapshot already shows the plane flying — no poll race.
|
||||||
|
const flyBody = (await flyRes.json()) as StateBody;
|
||||||
|
expect(flyBody.planes.find((p) => p.id === 'plane-starter')?.status).toBe('flying');
|
||||||
|
|
||||||
|
// Freeze mid-flight so the ~10 s leg can't land under us while we assert.
|
||||||
|
await postSim(page, { paused: true });
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
await waitForAirportCount(page);
|
||||||
|
// All line endpoints must be in-viewport for queryRenderedFeatures to see them.
|
||||||
|
await fitToAirports(page, [DEST, QUEUE]);
|
||||||
|
|
||||||
|
const destLL = await airportLonLat(page, DEST);
|
||||||
|
const queueLL = await airportLonLat(page, QUEUE);
|
||||||
|
const hubLL = await airportLonLat(page, HUB);
|
||||||
|
const near = (a: [number, number], b: [number, number]) =>
|
||||||
|
Math.abs(a[0] - b[0]) <= QUEUE_ROUTE_EPS_DEG && Math.abs(a[1] - b[1]) <= QUEUE_ROUTE_EPS_DEG;
|
||||||
|
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const feats = (await renderedFeatures(page, ['queue-routes'])) as Array<{
|
||||||
|
properties?: Record<string, unknown>;
|
||||||
|
geometry?: { type: string; coordinates: [number, number][] };
|
||||||
|
}>;
|
||||||
|
// Filter to real LineString segments — keeps this poll callback total (a throw inside
|
||||||
|
// expect.poll fails the test instantly instead of retrying). "None yet" → keep polling.
|
||||||
|
const segs = feats.filter(
|
||||||
|
(f): f is { properties?: Record<string, unknown>; geometry: { type: 'LineString'; coordinates: [number, number][] } } =>
|
||||||
|
!!f.geometry && f.geometry.type === 'LineString' && Array.isArray(f.geometry.coordinates) && f.geometry.coordinates.length >= 2,
|
||||||
|
);
|
||||||
|
if (!segs.length) return false;
|
||||||
|
// The line may be clipped into several per-tile segments — check the endpoints across all of them:
|
||||||
|
// some segment STARTS within EPS of DEST (the active leg's destination, NOT the plane's origin)…
|
||||||
|
const startsAtDest = segs.some((f) => near(f.geometry.coordinates[0], destLL));
|
||||||
|
// …and some ENDS within EPS of the queued airport.
|
||||||
|
const endsAtQueue = segs.some((f) => {
|
||||||
|
const c = f.geometry.coordinates;
|
||||||
|
return near(c[c.length - 1], queueLL);
|
||||||
|
});
|
||||||
|
// The active leg (HUB→DEST) must NOT be in this layer — no segment may start at the hub.
|
||||||
|
const noneStartsAtHub = !segs.some((f) => near(f.geometry.coordinates[0], hubLL));
|
||||||
|
// Every rendered feature belongs to plane-starter (the only queued plane).
|
||||||
|
const ownedByStarter = feats.every((f) => f.properties?.planeId === 'plane-starter');
|
||||||
|
return startsAtDest && endsAtQueue && noneStartsAtHub && ownedByStarter;
|
||||||
|
}, { timeout: 15_000, message: `waiting for the dotted queue line ${DEST} → ${QUEUE}` }).toBe(true);
|
||||||
|
|
||||||
|
// Cleanup: cancel the queued leg (so landing at DEST is a plain grounding), resume + fast-forward
|
||||||
|
// to arrival, then fly home.
|
||||||
|
const cancelRes = await page.request.post('/api/planes/plane-starter/queue/cancel', { data: { index: 0 } });
|
||||||
|
expect(cancelRes.status()).toBe(200);
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const p = (await getState(page)).planes.find((x) => x.id === 'plane-starter');
|
||||||
|
return !!p && p.status === 'available' && p.locationIcao === DEST;
|
||||||
|
}, { timeout: 120_000, message: `waiting for plane-starter to land at ${DEST}` }).toBe(true);
|
||||||
|
|
||||||
|
// ISS-041: the arrival above paused the sim — setScale clears pause for the return leg.
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
const home = await page.request.post('/api/planes/plane-starter/fly', { data: { destIcao: HUB } });
|
||||||
|
expect(home.status()).toBe(200);
|
||||||
|
await expect.poll(async () => ((await getState(page)).planes.find((p) => p.id === 'plane-starter')?.locationIcao ?? ''), {
|
||||||
|
timeout: 120_000,
|
||||||
|
message: 'waiting for plane-starter to land back at the hub',
|
||||||
|
}).toBe(HUB);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('landing auto-starts the next queued leg (ISS-043 chain end-to-end)', async ({ page }) => {
|
||||||
|
test.setTimeout(300_000); // self-heal + two chained legs at scale 1000
|
||||||
|
await flyHomeViaApi(page);
|
||||||
|
|
||||||
|
// Full tank so fuel covers the chained return leg (same feasibility rule as /fly).
|
||||||
|
const refuel = await page.request.post('/api/planes/plane-starter/refuel');
|
||||||
|
expect(refuel.status()).toBe(200);
|
||||||
|
|
||||||
|
// Package EDDF→LEMD + a queued return leg LEMD→EDDF, then start leg 1.
|
||||||
|
const pkg = await createPackage(page, HUB, DEST);
|
||||||
|
const load = await page.request.post(`/api/packages/${pkg.id}/load`, { data: { planeId: 'plane-starter' } });
|
||||||
|
expect(load.status()).toBe(200);
|
||||||
|
const queueRes = await page.request.post('/api/planes/plane-starter/queue', { data: { destIcao: HUB } });
|
||||||
|
expect(queueRes.status()).toBe(200);
|
||||||
|
const flyRes = await page.request.post('/api/planes/plane-starter/fly', { data: { destIcao: DEST } });
|
||||||
|
expect(flyRes.status()).toBe(200);
|
||||||
|
|
||||||
|
// Fast-forward (also clears any pause). On landing at DEST the server must AUTO-START the queued
|
||||||
|
// return leg — no manual dispatch. The chained state persists for the whole ~10 s return leg, so a
|
||||||
|
// poll can't miss it: status 'flying' with destIcao = the first (only) queued ICAO.
|
||||||
|
await setScale(page, SCALE);
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const p = (await getState(page)).planes.find((x) => x.id === 'plane-starter');
|
||||||
|
return !!p && p.status === 'flying' && p.destIcao === HUB;
|
||||||
|
}, { timeout: 120_000, message: `waiting for the auto-chained leg ${DEST} → ${HUB} to start` }).toBe(true);
|
||||||
|
|
||||||
|
// Cargo delivery ran BEFORE chaining (part 1 ordering) — the package is already delivered.
|
||||||
|
const s = await getState(page);
|
||||||
|
expect(s.packages.find((x) => x.id === pkg.id)?.status).toBe('delivered');
|
||||||
|
|
||||||
|
// Let the chained leg finish: it lands back at the hub, leaving the canonical onboarding state.
|
||||||
|
await expect.poll(async () => {
|
||||||
|
const p = (await getState(page)).planes.find((x) => x.id === 'plane-starter');
|
||||||
|
return !!p && p.status === 'available' && p.locationIcao === HUB;
|
||||||
|
}, { timeout: 120_000, message: `waiting for the chained leg to land back at ${HUB}` }).toBe(true);
|
||||||
|
});
|
||||||
+64
-3
@@ -28,7 +28,7 @@ interface PackageState {
|
|||||||
originName: string;
|
originName: string;
|
||||||
destName: string;
|
destName: string;
|
||||||
reward: number;
|
reward: number;
|
||||||
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned' | 'ignored'; // v0.29.0 (ISS-047 part B)
|
||||||
planeId: string | null;
|
planeId: string | null;
|
||||||
createdSimTime: number;
|
createdSimTime: number;
|
||||||
deadlineSimTime: number;
|
deadlineSimTime: number;
|
||||||
@@ -42,7 +42,7 @@ interface CatalogEntry {
|
|||||||
burnPerKm: number;
|
burnPerKm: number;
|
||||||
emptyWeightKg: number; // v0.16.0 weighted burn input
|
emptyWeightKg: number; // v0.16.0 weighted burn input
|
||||||
speedKmh: number;
|
speedKmh: number;
|
||||||
capacity: number;
|
maxPayloadKg: number; // v0.27.0 — replaces the v0.12.0 slot capacity
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StateBody {
|
interface StateBody {
|
||||||
@@ -151,6 +151,12 @@ function requiredFuelFor(burnPerKm: number, emptyWeightKg: number, maxFuel: numb
|
|||||||
return (emptyWeightKg / FUEL_DENSITY_KG_PER_L) * (Math.exp(k * FUEL_DENSITY_KG_PER_L * distanceKm) - 1);
|
return (emptyWeightKg / FUEL_DENSITY_KG_PER_L) * (Math.exp(k * FUEL_DENSITY_KG_PER_L * distanceKm) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mirrors maxRangeKm in lib/sim/movement.ts (v0.28.0): full-tank range under the weighted model.
|
||||||
|
function maxRangeKm(burnPerKm: number, emptyWeightKg: number, maxFuel: number): number {
|
||||||
|
const rho = FUEL_DENSITY_KG_PER_L;
|
||||||
|
return Math.log(1 + (rho * maxFuel) / emptyWeightKg) * ((emptyWeightKg + rho * maxFuel) / (rho * burnPerKm));
|
||||||
|
}
|
||||||
|
|
||||||
// Test hook (FLIGHT_TEST_HOOKS=1): create an open package on a known route.
|
// Test hook (FLIGHT_TEST_HOOKS=1): create an open package on a known route.
|
||||||
async function createPackage(page: Page, fromIcao: string, toIcao: string, deadlineOffsetMs?: number): Promise<PackageState> {
|
async function createPackage(page: Page, fromIcao: string, toIcao: string, deadlineOffsetMs?: number): Promise<PackageState> {
|
||||||
const created = await page.request.post('/api/test/create-package', {
|
const created = await page.request.post('/api/test/create-package', {
|
||||||
@@ -309,9 +315,12 @@ test('market buy/sell render with previews from the catalog in /api/state; left-
|
|||||||
const body = await getState(page); // authoritative catalog + economy constants (v0.10.0)
|
const body = await getState(page); // authoritative catalog + economy constants (v0.10.0)
|
||||||
expect(body.catalog.length).toBeGreaterThan(0);
|
expect(body.catalog.length).toBeGreaterThan(0);
|
||||||
const entry = body.catalog.find((e) => e.model === 'atr72')!;
|
const entry = body.catalog.find((e) => e.model === 'atr72')!;
|
||||||
expect(entry.capacity).toBe(6); // v0.12.0 slot capacity exposed in the snapshot
|
expect(entry.maxPayloadKg).toBe(4_800); // ATR 72-600 max payload (lib/game/catalog.ts)
|
||||||
|
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
// v0.28.0 (ISS-047): the market rows live in the Planes market tab — switch to it first.
|
||||||
|
await page.getByTestId('tab-planes-market').click();
|
||||||
|
|
||||||
// Buy: the model picker lists the catalog entry and the price preview is its full price.
|
// Buy: the model picker lists the catalog entry and the price preview is its full price.
|
||||||
const buyModel = page.getByTestId('market-buy-model');
|
const buyModel = page.getByTestId('market-buy-model');
|
||||||
await expect(buyModel).toBeVisible({ timeout: 15_000 });
|
await expect(buyModel).toBeVisible({ timeout: 15_000 });
|
||||||
@@ -425,3 +434,55 @@ test('on-board row Refuel tops up just enough for the package leg; left-pane but
|
|||||||
// Top the tank back up so later specs start with a full tank.
|
// Top the tank back up so later specs start with a full tank.
|
||||||
expect((await page.request.post('/api/planes/plane-starter/refuel')).status()).toBe(200);
|
expect((await page.request.post('/api/planes/plane-starter/refuel')).status()).toBe(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Ignore removes an open job from the list permanently (ISS-047 part B)', async ({ page }) => {
|
||||||
|
test.setTimeout(300_000); // self-heal can take minutes after an interrupted run
|
||||||
|
await flyHomeViaApi(page); // deterministic: the starter sits at EDDF
|
||||||
|
|
||||||
|
const nearest = await nearestToHub(page);
|
||||||
|
const pkg = await createPackage(page, HUB, nearest.icao, 24 * 3_600_000);
|
||||||
|
|
||||||
|
await page.goto('/');
|
||||||
|
const row = page.locator(`li[data-testid="open-package-${pkg.id}"]`);
|
||||||
|
await expect(row, 'the hook-created package appears in the list').toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// Ignore through the UI — the post-action snapshot lands immediately (no poll wait).
|
||||||
|
const ignoreBtn = page.getByTestId(`ignore-${pkg.id}`);
|
||||||
|
await expect(ignoreBtn, 'the row has an Ignore button').toBeEnabled();
|
||||||
|
await ignoreBtn.click();
|
||||||
|
|
||||||
|
// Server truth: the package is 'ignored'…
|
||||||
|
await expect
|
||||||
|
.poll(async () => (await getState(page)).packages.find((p) => p.id === pkg.id)?.status, {
|
||||||
|
timeout: 15_000,
|
||||||
|
message: 'waiting for the ignored status in /api/state',
|
||||||
|
})
|
||||||
|
.toBe('ignored');
|
||||||
|
|
||||||
|
// …and the row is gone from the open list (the section filters status==='open').
|
||||||
|
await expect(row).not.toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
// A second ignore attempt on the same id is a 409 — 'ignored' is terminal.
|
||||||
|
const again = await page.request.post(`/api/packages/${pkg.id}/ignore`);
|
||||||
|
expect(again.status()).toBe(409);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Planes market tab lists all plane types with tech specs', async ({ page }) => {
|
||||||
|
await page.goto('/');
|
||||||
|
const body = await getState(page); // authoritative catalog — v0.28.0 ships six types
|
||||||
|
expect(body.catalog.length).toBe(6);
|
||||||
|
|
||||||
|
await page.getByTestId('tab-planes-market').click();
|
||||||
|
|
||||||
|
// ATR card: name + full-tank range from the same closed form as lib/sim/movement.ts (v0.28.0).
|
||||||
|
const atr = body.catalog.find((e) => e.model === 'atr72')!;
|
||||||
|
await expect(page.getByTestId('plane-type-atr72'), 'the ATR card appears').toBeVisible({ timeout: 15_000 });
|
||||||
|
await expect(page.getByTestId('plane-type-atr72')).toContainText(atr.label);
|
||||||
|
const atrRange = Math.round(maxRangeKm(atr.burnPerKm, atr.emptyWeightKg, atr.maxFuel));
|
||||||
|
await expect(page.getByTestId('plane-type-range-atr72')).toContainText(`${atrRange} km`);
|
||||||
|
|
||||||
|
// Ladder sanity: the most expensive type (Boeing 777-300ER) is present with its €9M price.
|
||||||
|
const b777 = page.getByTestId('plane-type-b777');
|
||||||
|
await expect(b777).toBeVisible();
|
||||||
|
await expect(b777).toContainText(eur(9_000_000)); // lib/game/catalog.ts
|
||||||
|
});
|
||||||
|
|||||||
+1
-1
@@ -36,7 +36,7 @@ test('GET /api/state returns a seeded snapshot', async ({ page }) => {
|
|||||||
|
|
||||||
expect(Array.isArray(body.packages)).toBe(true);
|
expect(Array.isArray(body.packages)).toBe(true);
|
||||||
expect(body.packages.length).toBeGreaterThan(0);
|
expect(body.packages.length).toBeGreaterThan(0);
|
||||||
for (const key of ['id', 'originIcao', 'destIcao', 'reward', 'cargoType', 'deadlineSimTime', 'status']) {
|
for (const key of ['id', 'originIcao', 'destIcao', 'reward', 'cargoType', 'weightKg', 'deadlineSimTime', 'status']) {
|
||||||
expect(body.packages[0], `package.${key}`).toHaveProperty(key);
|
expect(body.packages[0], `package.${key}`).toHaveProperty(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ async function getState(page: Page): Promise<StateBody> {
|
|||||||
|
|
||||||
test('failed actions toast at the map right edge, clear of the right pane (inline error stays), and the Time section offers a notifications opt-in', async ({ page }) => {
|
test('failed actions toast at the map right edge, clear of the right pane (inline error stays), and the Time section offers a notifications opt-in', async ({ page }) => {
|
||||||
await page.goto('/');
|
await page.goto('/');
|
||||||
|
// v0.28.0 (ISS-047): the market rows live in the Planes market tab — switch to it first.
|
||||||
|
await page.getByTestId('tab-planes-market').click();
|
||||||
|
|
||||||
const buyModel = page.getByTestId('market-buy-model');
|
const buyModel = page.getByTestId('market-buy-model');
|
||||||
await expect(buyModel, 'the market section renders once the first snapshot lands').toBeVisible({ timeout: 15_000 });
|
await expect(buyModel, 'the market section renders once the first snapshot lands').toBeVisible({ timeout: 15_000 });
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS packages (
|
|||||||
reward REAL NOT NULL,
|
reward REAL NOT NULL,
|
||||||
cargo_type TEXT NOT NULL,
|
cargo_type TEXT NOT NULL,
|
||||||
cargo_count INTEGER NOT NULL,
|
cargo_count INTEGER NOT NULL,
|
||||||
|
weight_kg REAL NOT NULL DEFAULT 2000,
|
||||||
deadline_sim_time INTEGER NOT NULL,
|
deadline_sim_time INTEGER NOT NULL,
|
||||||
status TEXT NOT NULL,
|
status TEXT NOT NULL,
|
||||||
plane_id TEXT,
|
plane_id TEXT,
|
||||||
@@ -77,6 +78,10 @@ function migrateColumns(raw: RawSqlJsDatabase): void {
|
|||||||
if (!cols('planes').has('queue')) {
|
if (!cols('planes').has('queue')) {
|
||||||
raw.exec(`ALTER TABLE planes ADD COLUMN queue TEXT NOT NULL DEFAULT '[]'`);
|
raw.exec(`ALTER TABLE planes ADD COLUMN queue TEXT NOT NULL DEFAULT '[]'`);
|
||||||
}
|
}
|
||||||
|
// v0.27.0 (ISS-045): package weight — pre-existing rows backfill to a mid-range default.
|
||||||
|
if (!cols('packages').has('weight_kg')) {
|
||||||
|
raw.exec('ALTER TABLE packages ADD COLUMN weight_kg REAL NOT NULL DEFAULT 2000');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// v0.12.0 one-time migration: contracts world → packages world. Detected by the
|
// v0.12.0 one-time migration: contracts world → packages world. Detected by the
|
||||||
|
|||||||
+5
-1
@@ -37,10 +37,14 @@ export const packages = sqliteTable('packages', {
|
|||||||
reward: real('reward').notNull(),
|
reward: real('reward').notNull(),
|
||||||
cargoType: text('cargo_type').notNull(),
|
cargoType: text('cargo_type').notNull(),
|
||||||
cargoCount: integer('cargo_count').notNull(),
|
cargoCount: integer('cargo_count').notNull(),
|
||||||
|
// Package weight in kg (v0.27.0, ISS-045) — drives load validation (plane payload)
|
||||||
|
// and the per-kg part of the payout. Pre-existing rows backfill to the default.
|
||||||
|
weightKg: real('weight_kg').notNull().default(2000),
|
||||||
deadlineSimTime: integer('deadline_sim_time').notNull(),
|
deadlineSimTime: integer('deadline_sim_time').notNull(),
|
||||||
// 'expired' = an open OR loaded package whose deadline passed on a tick. Loaded
|
// 'expired' = an open OR loaded package whose deadline passed on a tick. Loaded
|
||||||
// expired packages keep occupying their slot, deliver no reward, and abandon free.
|
// expired packages keep occupying their slot, deliver no reward, and abandon free.
|
||||||
status: text('status', { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned'] }).notNull(),
|
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
||||||
|
status: text('status', { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned', 'ignored'] }).notNull(),
|
||||||
planeId: text('plane_id'),
|
planeId: text('plane_id'),
|
||||||
createdSimTime: integer('created_sim_time').notNull(),
|
createdSimTime: integer('created_sim_time').notNull(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { diffSnapshots } from './deriveEvents';
|
|||||||
// feature, unit-tested in node like advanceSimClock/fetchState.
|
// feature, unit-tested in node like advanceSimClock/fetchState.
|
||||||
|
|
||||||
const CATALOG = [
|
const CATALOG = [
|
||||||
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9300, speedKmh: 510, capacity: 6 },
|
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9300, speedKmh: 510, maxPayloadKg: 4800 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const basePlane = (id: string): PlaneState => ({
|
const basePlane = (id: string): PlaneState => ({
|
||||||
@@ -34,6 +34,7 @@ const basePackage = (id: string): PackageState => ({
|
|||||||
reward: 1234.5,
|
reward: 1234.5,
|
||||||
cargoType: 'mail',
|
cargoType: 'mail',
|
||||||
cargoCount: 2,
|
cargoCount: 2,
|
||||||
|
weightKg: 600,
|
||||||
deadlineSimTime: 0,
|
deadlineSimTime: 0,
|
||||||
status: 'open',
|
status: 'open',
|
||||||
planeId: null,
|
planeId: null,
|
||||||
|
|||||||
+58
-14
@@ -16,6 +16,7 @@ import {
|
|||||||
cancelQueuedLeg,
|
cancelQueuedLeg,
|
||||||
flyPlane,
|
flyPlane,
|
||||||
GameActionError,
|
GameActionError,
|
||||||
|
ignorePackage,
|
||||||
loadPackage,
|
loadPackage,
|
||||||
queueLeg,
|
queueLeg,
|
||||||
refuelPlane,
|
refuelPlane,
|
||||||
@@ -127,27 +128,27 @@ describe('loadPackage', () => {
|
|||||||
await expectActionError(loadPackage(inst, 'p-open', 'plane-starter'), 409, /at LEMD/);
|
await expectActionError(loadPackage(inst, 'p-open', 'plane-starter'), 409, /at LEMD/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rejects loading when the plane has no free slot (capacity from catalog)', async () => {
|
it('rejects loading when the plane has no payload room (maxPayloadKg from catalog)', async () => {
|
||||||
const inst = await freshDb('load-full.db');
|
const inst = await freshDb('load-full.db');
|
||||||
await insertOpenPackage(inst, 'p-new');
|
await insertOpenPackage(inst, 'p-new', { weightKg: 1_000 });
|
||||||
// Fill all atr72 slots with loaded cargo…
|
// Fill past maxPayloadKg with loaded cargo…
|
||||||
for (let i = 0; i < PLANE_TYPES.atr72.capacity; i++) {
|
const chunk = Math.floor(PLANE_TYPES.atr72.maxPayloadKg / 3) + 1; // 3 chunks > max
|
||||||
await insertOpenPackage(inst, `p-fill-${i}`, { status: 'loaded', planeId: 'plane-starter' });
|
for (let i = 0; i < 3; i++) {
|
||||||
|
await insertOpenPackage(inst, `p-fill-${i}`, { status: 'loaded', planeId: 'plane-starter', weightKg: chunk });
|
||||||
}
|
}
|
||||||
|
|
||||||
await expectActionError(loadPackage(inst, 'p-new', 'plane-starter'), 409, /no free slots/i);
|
await expectActionError(loadPackage(inst, 'p-new', 'plane-starter'), 409, /no payload room/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('counts expired packages as occupying their slot too', async () => {
|
it('counts expired packages as occupying their payload too', async () => {
|
||||||
const inst = await freshDb('load-expiredslot.db');
|
const inst = await freshDb('load-expiredslot.db');
|
||||||
await insertOpenPackage(inst, 'p-new');
|
await insertOpenPackage(inst, 'p-new', { weightKg: 1_000 });
|
||||||
// capacity − 1 loaded + 1 expired = full.
|
// Half + half (expired) leaves no room — each alone would fit.
|
||||||
for (let i = 0; i < PLANE_TYPES.atr72.capacity - 1; i++) {
|
const half = Math.floor(PLANE_TYPES.atr72.maxPayloadKg / 2) + 1;
|
||||||
await insertOpenPackage(inst, `p-fill-${i}`, { status: 'loaded', planeId: 'plane-starter' });
|
await insertOpenPackage(inst, 'p-loaded-half', { status: 'loaded', planeId: 'plane-starter', weightKg: half });
|
||||||
}
|
await insertOpenPackage(inst, 'p-expired-slot', { status: 'expired', planeId: 'plane-starter', weightKg: half });
|
||||||
await insertOpenPackage(inst, 'p-expired-slot', { status: 'expired', planeId: 'plane-starter' });
|
|
||||||
|
|
||||||
await expectActionError(loadPackage(inst, 'p-new', 'plane-starter'), 409, /no free slots/i);
|
await expectActionError(loadPackage(inst, 'p-new', 'plane-starter'), 409, /no payload room/i);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -374,6 +375,36 @@ describe('abandonPackage', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('ignorePackage', () => {
|
||||||
|
it('flips an open package to ignored — no penalty, nothing else changes', async () => {
|
||||||
|
const inst = await freshDb('ig-open.db');
|
||||||
|
await insertOpenPackage(inst, 'p-ig');
|
||||||
|
const cashBefore = (await inst.db.select().from(schema.account))[0].cash;
|
||||||
|
|
||||||
|
await ignorePackage(inst, 'p-ig');
|
||||||
|
|
||||||
|
const row = (await inst.db.select().from(schema.packages).where(eq(schema.packages.id, 'p-ig')))[0];
|
||||||
|
expect(row.status).toBe('ignored');
|
||||||
|
expect(row.planeId).toBeNull(); // was never bound
|
||||||
|
expect((await inst.db.select().from(schema.account))[0].cash).toBe(cashBefore); // no penalty
|
||||||
|
});
|
||||||
|
|
||||||
|
it.each(['loaded', 'delivered', 'expired', 'abandoned', 'ignored'] as const)(
|
||||||
|
'rejects a %s package with 409 (must be open)',
|
||||||
|
async (status) => {
|
||||||
|
const inst = await freshDb(`ig-${status}.db`);
|
||||||
|
await insertOpenPackage(inst, 'p-x', { status });
|
||||||
|
|
||||||
|
await expectActionError(ignorePackage(inst, 'p-x'), 409, new RegExp(status));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
it('rejects an unknown id with 404', async () => {
|
||||||
|
const inst = await freshDb('ig-unknown.db');
|
||||||
|
await expectActionError(ignorePackage(inst, 'nope'), 404);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('buyPlane', () => {
|
describe('buyPlane', () => {
|
||||||
it('deducts the full price and delivers a full-tank plane at the home base', async () => {
|
it('deducts the full price and delivers a full-tank plane at the home base', async () => {
|
||||||
const inst = await freshDb('buy-ok.db');
|
const inst = await freshDb('buy-ok.db');
|
||||||
@@ -440,6 +471,19 @@ describe('sellPlane', () => {
|
|||||||
await expectActionError(sellPlane(inst, 'plane-extra'), 409, /flying/);
|
await expectActionError(sellPlane(inst, 'plane-extra'), 409, /flying/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('rejects selling a grounded plane that still carries cargo with 409 (v0.28.0)', async () => {
|
||||||
|
const inst = await freshDb('sell-cargo.db');
|
||||||
|
await inst.db.insert(schema.planes).values({
|
||||||
|
id: 'plane-extra', model: 'atr72', status: 'available', fuel: 100, maxFuel: PLANE_TYPES.atr72.maxFuel,
|
||||||
|
locationIcao: HUB_ICAO, destIcao: null, lat: 50, lon: 8, departureSimTime: null,
|
||||||
|
});
|
||||||
|
await insertOpenPackage(inst, 'p-loaded', { status: 'loaded', planeId: 'plane-extra' });
|
||||||
|
|
||||||
|
await expectActionError(sellPlane(inst, 'plane-extra'), 409, /carrying cargo/);
|
||||||
|
const ids = (await inst.db.select().from(schema.planes)).map((p) => p.id);
|
||||||
|
expect(ids).toContain('plane-extra'); // row untouched — the cargo stays bound to a real plane
|
||||||
|
});
|
||||||
|
|
||||||
it('rejects selling the last remaining plane with 409', async () => {
|
it('rejects selling the last remaining plane with 409', async () => {
|
||||||
const inst = await freshDb('sell-last.db'); // only the starter exists
|
const inst = await freshDb('sell-last.db'); // only the starter exists
|
||||||
await expectActionError(sellPlane(inst, 'plane-starter'), 409, /last remaining/);
|
await expectActionError(sellPlane(inst, 'plane-starter'), 409, /last remaining/);
|
||||||
|
|||||||
+36
-10
@@ -20,7 +20,7 @@ import { HUB_ICAO } from './seed';
|
|||||||
// GameActionError carrying the HTTP status:
|
// GameActionError carrying the HTTP status:
|
||||||
// 404 — unknown entity id
|
// 404 — unknown entity id
|
||||||
// 409 — valid ids but the current state forbids the action (wrong package/plane
|
// 409 — valid ids but the current state forbids the action (wrong package/plane
|
||||||
// status, plane not at origin, no free slot, insufficient fuel/funds, last plane)
|
// status, plane not at origin, no payload room, insufficient fuel/funds, last plane)
|
||||||
// 400 — bad input that isn't an existence problem (unknown airport/model)
|
// 400 — bad input that isn't an existence problem (unknown airport/model)
|
||||||
|
|
||||||
export class GameActionError extends Error {
|
export class GameActionError extends Error {
|
||||||
@@ -43,8 +43,9 @@ async function airportByIcao(icao: string): Promise<{ icao: string; lat: number;
|
|||||||
// --- Load (POST /api/packages/:id/load {planeId}) ---
|
// --- Load (POST /api/packages/:id/load {planeId}) ---
|
||||||
|
|
||||||
// open → loaded, bound to the plane. The plane must be GROUNDED at the package's
|
// open → loaded, bound to the plane. The plane must be GROUNDED at the package's
|
||||||
// origin with a free slot (slots = packages 'loaded' or 'expired' on it — expired
|
// origin with enough payload room (v0.27.0: used kg = sum of weightKg over packages
|
||||||
// cargo keeps occupying its space until delivered/abandoned).
|
// 'loaded' or 'expired' on it — expired cargo keeps occupying its space until
|
||||||
|
// delivered/abandoned).
|
||||||
export async function loadPackage(inst: GameDb, packageId: string, planeId: string): Promise<void> {
|
export async function loadPackage(inst: GameDb, packageId: string, planeId: string): Promise<void> {
|
||||||
const [pkgRows, planeRows] = await Promise.all([
|
const [pkgRows, planeRows] = await Promise.all([
|
||||||
inst.db.select().from(schema.packages).where(eq(schema.packages.id, packageId)),
|
inst.db.select().from(schema.packages).where(eq(schema.packages.id, packageId)),
|
||||||
@@ -69,13 +70,12 @@ export async function loadPackage(inst: GameDb, packageId: string, planeId: stri
|
|||||||
|
|
||||||
const type = PLANE_TYPES[plane.model];
|
const type = PLANE_TYPES[plane.model];
|
||||||
if (!type) throw new Error(`unknown plane model ${plane.model}`); // → 500, cannot happen for seeded data
|
if (!type) throw new Error(`unknown plane model ${plane.model}`); // → 500, cannot happen for seeded data
|
||||||
const occupied = (
|
const occupied = await inst.db.select({ weightKg: schema.packages.weightKg }).from(schema.packages).where(
|
||||||
await inst.db.select().from(schema.packages).where(
|
and(inArray(schema.packages.status, ['loaded', 'expired']), eq(schema.packages.planeId, plane.id)),
|
||||||
and(inArray(schema.packages.status, ['loaded', 'expired']), eq(schema.packages.planeId, plane.id)),
|
);
|
||||||
)
|
const usedKg = occupied.reduce((sum, r) => sum + (r.weightKg ?? 0), 0);
|
||||||
).length;
|
if (usedKg + pkg.weightKg > type.maxPayloadKg) {
|
||||||
if (occupied >= type.capacity) {
|
throw new GameActionError(409, `no payload room: the ${type.name} carries ${Math.round(usedKg)}/${type.maxPayloadKg} kg`);
|
||||||
throw new GameActionError(409, `no free slots: the ${type.name} carries ${occupied}/${type.capacity} packages`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await inst.db.update(schema.packages)
|
await inst.db.update(schema.packages)
|
||||||
@@ -207,6 +207,23 @@ export async function abandonPackage(inst: GameDb, packageId: string): Promise<{
|
|||||||
return { penalty };
|
return { penalty };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- Ignore (POST /api/packages/:id/ignore) — ISS-047 part B ---
|
||||||
|
|
||||||
|
// Dismiss an OPEN job so it leaves the market permanently; no penalty, nothing else
|
||||||
|
// changes. The top-up logic (spawnOpenPackages counts 'open') refills the market with
|
||||||
|
// a new random package on the next tick. 404 unknown id; 409 unless open.
|
||||||
|
export async function ignorePackage(inst: GameDb, packageId: string): Promise<void> {
|
||||||
|
const pkgRows = await inst.db.select().from(schema.packages).where(eq(schema.packages.id, packageId));
|
||||||
|
const pkg = pkgRows[0];
|
||||||
|
if (!pkg) throw new GameActionError(404, `package ${packageId} not found`);
|
||||||
|
if (pkg.status !== 'open') {
|
||||||
|
throw new GameActionError(409, `package is ${pkg.status}, only open packages can be ignored`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await inst.db.update(schema.packages).set({ status: 'ignored' }).where(eq(schema.packages.id, packageId));
|
||||||
|
await persist(inst);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Market (POST /api/market/buy-plane {model}) ---
|
// --- Market (POST /api/market/buy-plane {model}) ---
|
||||||
|
|
||||||
// Buy a catalog model at full price; it arrives 'available' with a full tank at
|
// Buy a catalog model at full price; it arrives 'available' with a full tank at
|
||||||
@@ -255,6 +272,15 @@ export async function sellPlane(inst: GameDb, planeId: string): Promise<{ payout
|
|||||||
throw new GameActionError(409, `plane is ${plane.status}, only grounded planes can be sold`);
|
throw new GameActionError(409, `plane is ${plane.status}, only grounded planes can be sold`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// v0.28.0: selling a plane that still carries cargo would orphan it — the packages stay
|
||||||
|
// 'loaded'/'expired' with a dangling planeId and could never deliver (same query pattern as loadPackage).
|
||||||
|
const carrying = await inst.db.select({ id: schema.packages.id }).from(schema.packages).where(
|
||||||
|
and(inArray(schema.packages.status, ['loaded', 'expired']), eq(schema.packages.planeId, plane.id)),
|
||||||
|
);
|
||||||
|
if (carrying.length > 0) {
|
||||||
|
throw new GameActionError(409, `cannot sell a plane carrying cargo`);
|
||||||
|
}
|
||||||
|
|
||||||
const all = await inst.db.select().from(schema.planes);
|
const all = await inst.db.select().from(schema.planes);
|
||||||
if (all.length <= 1) throw new GameActionError(409, 'cannot sell the last remaining plane');
|
if (all.length <= 1) throw new GameActionError(409, 'cannot sell the last remaining plane');
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { PLANE_TYPES, STARTER_MODEL } from './catalog';
|
||||||
|
|
||||||
|
// v0.28.0 (ISS-047) — catalog sanity: the progression ladder must stay well-formed as types are added.
|
||||||
|
describe('PLANE_TYPES', () => {
|
||||||
|
it('every entry has positive specs and a unique id', () => {
|
||||||
|
const ids = Object.keys(PLANE_TYPES);
|
||||||
|
expect(new Set(ids).size).toBe(ids.length);
|
||||||
|
for (const t of Object.values(PLANE_TYPES)) {
|
||||||
|
expect(t.id, `${t.name} id`).toBeTruthy();
|
||||||
|
expect(t.price, `${t.name} price`).toBeGreaterThan(0);
|
||||||
|
expect(t.maxFuel, `${t.name} maxFuel`).toBeGreaterThan(0);
|
||||||
|
expect(t.burnPerKm, `${t.name} burnPerKm`).toBeGreaterThan(0);
|
||||||
|
expect(t.emptyWeightKg, `${t.name} emptyWeightKg`).toBeGreaterThan(0);
|
||||||
|
expect(t.speedKmh, `${t.name} speedKmh`).toBeGreaterThan(0);
|
||||||
|
expect(t.maxPayloadKg, `${t.name} maxPayloadKg`).toBeGreaterThan(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('atr72 is the starter model', () => {
|
||||||
|
expect(STARTER_MODEL).toBe('atr72');
|
||||||
|
expect(PLANE_TYPES[STARTER_MODEL]).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
+64
-5
@@ -16,8 +16,10 @@ export interface PlaneType {
|
|||||||
// Market price in € (v0.8.0): buying costs `price`, selling pays out
|
// Market price in € (v0.8.0): buying costs `price`, selling pays out
|
||||||
// SELL_FRACTION × price.
|
// SELL_FRACTION × price.
|
||||||
price: number;
|
price: number;
|
||||||
// Cargo slot capacity (v0.12.0): how many packages can be loaded on one plane.
|
// Max payload in kg (v0.27.0, ISS-045 — replaces the v0.12.0 slot count): total
|
||||||
capacity: number;
|
// package weight that can be loaded on one plane. ATR 72-600-class figure, tuned
|
||||||
|
// so every cargo type at max count × 1.3 jitter still fits alone (see UNIT_WEIGHT_KG).
|
||||||
|
maxPayloadKg: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PLANE_TYPES: Record<string, PlaneType> = {
|
export const PLANE_TYPES: Record<string, PlaneType> = {
|
||||||
@@ -31,7 +33,63 @@ export const PLANE_TYPES: Record<string, PlaneType> = {
|
|||||||
// €200k — with the starting cash of €20k and typical hop rewards (~€1–3k),
|
// €200k — with the starting cash of €20k and typical hop rewards (~€1–3k),
|
||||||
// a second ATR takes sustained play to afford, as intended for the MVP sink.
|
// a second ATR takes sustained play to afford, as intended for the MVP sink.
|
||||||
price: 200_000,
|
price: 200_000,
|
||||||
capacity: 6,
|
// ponytail: balance-tunable payload (kg) — every cargo type at max count × 1.3 jitter
|
||||||
|
// must stay below this so any single package fits alone; typical loads carry ~3–6 packages.
|
||||||
|
maxPayloadKg: 4_800,
|
||||||
|
},
|
||||||
|
// Progression ladder above the ATR starter (v0.28.0, ISS-047): bigger tanks, faster airframes,
|
||||||
|
// higher prices — everything downstream is data-driven via PLANE_TYPES[model]. Values are
|
||||||
|
// balance-tunable; keep maxPayloadKg ≥ every cargo type at max count × 1.3 jitter so any
|
||||||
|
// single package still fits alone (same rule as the ATR above).
|
||||||
|
crj900: {
|
||||||
|
id: 'crj900',
|
||||||
|
name: 'CRJ-900',
|
||||||
|
maxFuel: 8_000,
|
||||||
|
burnPerKm: 2.1,
|
||||||
|
emptyWeightKg: 17_500,
|
||||||
|
speedKmh: 830,
|
||||||
|
price: 450_000,
|
||||||
|
maxPayloadKg: 6_500,
|
||||||
|
},
|
||||||
|
e175: {
|
||||||
|
id: 'e175',
|
||||||
|
name: 'Embraer E175',
|
||||||
|
maxFuel: 9_500,
|
||||||
|
burnPerKm: 2.0,
|
||||||
|
emptyWeightKg: 23_000,
|
||||||
|
speedKmh: 840,
|
||||||
|
price: 900_000,
|
||||||
|
maxPayloadKg: 9_000,
|
||||||
|
},
|
||||||
|
a320: {
|
||||||
|
id: 'a320',
|
||||||
|
name: 'Airbus A320-200',
|
||||||
|
maxFuel: 12_000,
|
||||||
|
burnPerKm: 2.2,
|
||||||
|
emptyWeightKg: 41_000,
|
||||||
|
speedKmh: 845,
|
||||||
|
price: 1_800_000,
|
||||||
|
maxPayloadKg: 18_000,
|
||||||
|
},
|
||||||
|
a330: {
|
||||||
|
id: 'a330',
|
||||||
|
name: 'Airbus A330-200',
|
||||||
|
maxFuel: 20_000,
|
||||||
|
burnPerKm: 2.16,
|
||||||
|
emptyWeightKg: 95_000,
|
||||||
|
speedKmh: 910,
|
||||||
|
price: 4_500_000,
|
||||||
|
maxPayloadKg: 48_000,
|
||||||
|
},
|
||||||
|
b777: {
|
||||||
|
id: 'b777',
|
||||||
|
name: 'Boeing 777-300ER',
|
||||||
|
maxFuel: 30_000,
|
||||||
|
burnPerKm: 2.5,
|
||||||
|
emptyWeightKg: 130_000,
|
||||||
|
speedKmh: 920,
|
||||||
|
price: 9_000_000,
|
||||||
|
maxPayloadKg: 80_000,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -57,7 +115,8 @@ export interface CatalogEntry {
|
|||||||
// lib/sim/movement.ts with these + FUEL_DENSITY_KG_PER_L.
|
// lib/sim/movement.ts with these + FUEL_DENSITY_KG_PER_L.
|
||||||
emptyWeightKg: number;
|
emptyWeightKg: number;
|
||||||
speedKmh: number;
|
speedKmh: number;
|
||||||
capacity: number;
|
// Max payload in kg (v0.27.0) — total package weight that can be loaded on one plane.
|
||||||
|
maxPayloadKg: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The catalog as a flat array, one entry per plane type — the single source of
|
// The catalog as a flat array, one entry per plane type — the single source of
|
||||||
@@ -71,6 +130,6 @@ export function catalogEntries(): CatalogEntry[] {
|
|||||||
burnPerKm: t.burnPerKm,
|
burnPerKm: t.burnPerKm,
|
||||||
emptyWeightKg: t.emptyWeightKg,
|
emptyWeightKg: t.emptyWeightKg,
|
||||||
speedKmh: t.speedKmh,
|
speedKmh: t.speedKmh,
|
||||||
capacity: t.capacity,
|
maxPayloadKg: t.maxPayloadKg,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-9
@@ -9,8 +9,9 @@ import {
|
|||||||
generatePackage,
|
generatePackage,
|
||||||
HUB_ICAO,
|
HUB_ICAO,
|
||||||
mulberry32,
|
mulberry32,
|
||||||
|
REWARD_PER_KG,
|
||||||
REWARD_PER_KM,
|
REWARD_PER_KM,
|
||||||
rewardForDistanceKm,
|
rewardFor,
|
||||||
STARTING_CASH,
|
STARTING_CASH,
|
||||||
STARTING_REPUTATION,
|
STARTING_REPUTATION,
|
||||||
type SeedAirport,
|
type SeedAirport,
|
||||||
@@ -70,12 +71,26 @@ describe('buildSeed', () => {
|
|||||||
expect(new Set(seed.packages.map((c) => c.id)).size).toBe(seed.packages.length);
|
expect(new Set(seed.packages.map((c) => c.id)).size).toBe(seed.packages.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scales reward by haversine distance: round(500 + 2.5 * km)', () => {
|
it('applies the reward formula: round(500 + 2.5 * km + 0.5 * weightKg)', () => {
|
||||||
const seed = seedWith(42);
|
const seed = seedWith(42);
|
||||||
for (const c of seed.packages) {
|
for (const c of seed.packages) {
|
||||||
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
||||||
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
||||||
expect(c.reward).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon)));
|
expect(c.reward).toBe(
|
||||||
|
Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon) + REWARD_PER_KG * c.weightKg),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gives every package a positive integer weight that fits the starter plane alone (balance constraint)', () => {
|
||||||
|
const maxPayload = PLANE_TYPES[STARTER_MODEL].maxPayloadKg;
|
||||||
|
for (const seed of [seedWith(42), seedWith(7)]) {
|
||||||
|
for (const c of seed.packages) {
|
||||||
|
expect(Number.isInteger(c.weightKg)).toBe(true);
|
||||||
|
expect(c.weightKg).toBeGreaterThan(0);
|
||||||
|
// max count × max jitter (1.3×) must still fit the ATR alone — see UNIT_WEIGHT_KG.
|
||||||
|
expect(c.weightKg).toBeLessThanOrEqual(maxPayload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -106,9 +121,9 @@ describe('buildSeed', () => {
|
|||||||
expect(() => buildSeed({ airports: AIRPORTS.slice(0, 1), rng: mulberry32(42), nowMs: NOW })).toThrow();
|
expect(() => buildSeed({ airports: AIRPORTS.slice(0, 1), rng: mulberry32(42), nowMs: NOW })).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('rewardForDistanceKm applies the documented formula', () => {
|
it('rewardFor applies the documented formula', () => {
|
||||||
expect(rewardForDistanceKm(0)).toBe(BASE_REWARD);
|
expect(rewardFor(0, 0)).toBe(BASE_REWARD);
|
||||||
expect(rewardForDistanceKm(1000)).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * 1000));
|
expect(rewardFor(1000, 2_000)).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * 1000 + REWARD_PER_KG * 2_000));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -127,7 +142,9 @@ describe('generatePackage (shared seed/spawn builder)', () => {
|
|||||||
|
|
||||||
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
||||||
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
||||||
expect(c.reward).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon)));
|
expect(c.reward).toBe(
|
||||||
|
Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon) + REWARD_PER_KG * c.weightKg),
|
||||||
|
);
|
||||||
|
|
||||||
// Same 6–72h game-time deadline window as the seed.
|
// Same 6–72h game-time deadline window as the seed.
|
||||||
expect(c.deadlineSimTime).toBeGreaterThan(NOW + 6 * 3_600_000 - 1);
|
expect(c.deadlineSimTime).toBeGreaterThan(NOW + 6 * 3_600_000 - 1);
|
||||||
@@ -173,7 +190,9 @@ describe('generatePackage (shared seed/spawn builder)', () => {
|
|||||||
|
|
||||||
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
||||||
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
||||||
expect(c.reward).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon)));
|
expect(c.reward).toBe(
|
||||||
|
Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon) + REWARD_PER_KG * c.weightKg),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('destIcao forces the destination; origin stays random but distinct', () => {
|
it('destIcao forces the destination; origin stays random but distinct', () => {
|
||||||
@@ -189,7 +208,9 @@ describe('generatePackage (shared seed/spawn builder)', () => {
|
|||||||
|
|
||||||
const o = AIRPORTS[0]; // EDDF
|
const o = AIRPORTS[0]; // EDDF
|
||||||
const d = AIRPORTS[1]; // EHAM
|
const d = AIRPORTS[1]; // EHAM
|
||||||
expect(c.reward).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon)));
|
expect(c.reward).toBe(
|
||||||
|
Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon) + REWARD_PER_KG * c.weightKg),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is deterministic for a fixed RNG with forced endpoints', () => {
|
it('is deterministic for a fixed RNG with forced endpoints', () => {
|
||||||
@@ -212,4 +233,22 @@ describe('generatePackage (shared seed/spawn builder)', () => {
|
|||||||
expect(a).toEqual(b);
|
expect(a).toEqual(b);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('forced weight (v0.27.0 e2e hook)', () => {
|
||||||
|
it('weightKg forces the package weight and feeds the payout', () => {
|
||||||
|
const c = generatePackage({ id: 'c-w', airports: AIRPORTS, rng: mulberry32(42), nowMs: NOW, weightKg: 1_234 });
|
||||||
|
expect(c.weightKg).toBe(1_234);
|
||||||
|
|
||||||
|
const o = AIRPORTS.find((a) => a.icao === c.originIcao)!;
|
||||||
|
const d = AIRPORTS.find((a) => a.icao === c.destIcao)!;
|
||||||
|
expect(c.reward).toBe(Math.round(BASE_REWARD + REWARD_PER_KM * haversineKm(o.lat, o.lon, d.lat, d.lon) + REWARD_PER_KG * 1_234));
|
||||||
|
|
||||||
|
// Deterministic for a fixed RNG…
|
||||||
|
const again = generatePackage({ id: 'c-w', airports: AIRPORTS, rng: mulberry32(42), nowMs: NOW, weightKg: 1_234 });
|
||||||
|
expect(again).toEqual(c);
|
||||||
|
// …and the forced value consumes no RNG draw — the deadline lands where an unforced call's jitter would.
|
||||||
|
const unforced = generatePackage({ id: 'c-u', airports: AIRPORTS, rng: mulberry32(42), nowMs: NOW });
|
||||||
|
expect(c.deadlineSimTime).not.toBe(unforced.deadlineSimTime);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
+32
-9
@@ -50,6 +50,8 @@ export interface SeedPackage {
|
|||||||
reward: number;
|
reward: number;
|
||||||
cargoType: string;
|
cargoType: string;
|
||||||
cargoCount: number;
|
cargoCount: number;
|
||||||
|
// Package weight in kg (v0.27.0, ISS-045) — unit weight × count with ±30% jitter.
|
||||||
|
weightKg: number;
|
||||||
deadlineSimTime: number;
|
deadlineSimTime: number;
|
||||||
status: 'open';
|
status: 'open';
|
||||||
planeId: null;
|
planeId: null;
|
||||||
@@ -80,10 +82,12 @@ export const PACKAGE_COUNT_MAX = 12; // inclusive
|
|||||||
// count after expiries, so the job board never runs dry.
|
// count after expiries, so the job board never runs dry.
|
||||||
export const MARKET_TARGET_OPEN_PACKAGES = 10;
|
export const MARKET_TARGET_OPEN_PACKAGES = 10;
|
||||||
|
|
||||||
// Reward formula (v0.6.0 — deliberately simple; real revenue/cost modeling is a
|
// Reward formula (v0.6.0 distance part, deliberately simple; real revenue/cost
|
||||||
// later increment): reward = BASE_REWARD + REWARD_PER_KM * great-circle km.
|
// modeling is a later increment; v0.27.0 weight part): reward = BASE_REWARD +
|
||||||
|
// REWARD_PER_KM * great-circle km + REWARD_PER_KG * package weight kg.
|
||||||
export const BASE_REWARD = 500;
|
export const BASE_REWARD = 500;
|
||||||
export const REWARD_PER_KM = 2.5;
|
export const REWARD_PER_KM = 2.5;
|
||||||
|
export const REWARD_PER_KG = 0.5;
|
||||||
|
|
||||||
// Package deadlines: now + a plausible game-time window of 6–72 hours.
|
// Package deadlines: now + a plausible game-time window of 6–72 hours.
|
||||||
const DEADLINE_MIN_HOURS = 6;
|
const DEADLINE_MIN_HOURS = 6;
|
||||||
@@ -91,19 +95,33 @@ const DEADLINE_MAX_HOURS = 72;
|
|||||||
|
|
||||||
const CARGO_TYPES = ['Passengers', 'Mail', 'Perishables', 'Electronics', 'Auto parts'] as const;
|
const CARGO_TYPES = ['Passengers', 'Mail', 'Perishables', 'Electronics', 'Auto parts'] as const;
|
||||||
|
|
||||||
export function rewardForDistanceKm(km: number): number {
|
// ponytail: balance-tunable unit weights (kg per passenger/pallet). Chosen so every cargo
|
||||||
return Math.round(BASE_REWARD + REWARD_PER_KM * km);
|
// type at MAX count × max jitter (1.3×) still fits the ATR 72-600's payload alone, and
|
||||||
|
// typical packages land ~400–2500 kg — a normal flight carries roughly 3–6 by weight.
|
||||||
|
export const UNIT_WEIGHT_KG: Record<string, number> = {
|
||||||
|
Passengers: 50, // max 50 × 68 × 1.3 = 4420 < 4800
|
||||||
|
Mail: 60, // max 60 × 50 × 1.3 = 3900
|
||||||
|
Perishables: 70, // max 70 × 50 × 1.3 = 4550
|
||||||
|
Electronics: 40, // max 40 × 50 × 1.3 = 2600
|
||||||
|
'Auto parts': 72, // max 72 × 50 × 1.3 = 4680
|
||||||
|
};
|
||||||
|
|
||||||
|
export function rewardFor(km: number, weightKg: number): number {
|
||||||
|
return Math.round(BASE_REWARD + REWARD_PER_KM * km + REWARD_PER_KG * weightKg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shared package generator, used by BOTH the first-run seed and the runtime
|
// Shared package generator, used by BOTH the first-run seed and the runtime
|
||||||
// market spawn (v0.7.0) so spawned packages match seeded ones exactly: random
|
// market spawn (v0.7.0) so spawned packages match seeded ones exactly: random
|
||||||
// distinct airports from the dataset, distance-based reward, cargo flavor,
|
// distinct airports from the dataset, distance+weight-based reward, cargo flavor,
|
||||||
// deadline now + 6–72h game time (or now + deadlineOffsetMs when given — used by
|
// weight = unit weight × count with ±30% jitter (v0.27.0), deadline now + 6–72h
|
||||||
// the e2e test hook to force a near-term expiry). The RNG call order per package
|
// game time (or now + deadlineOffsetMs when given — used by the e2e test hook to
|
||||||
// is fixed: origin, dest, cargoType, cargoCount, [deadline window].
|
// force a near-term expiry). The RNG call order per package is fixed: origin,
|
||||||
|
// dest, cargoType, cargoCount, weight jitter, [deadline window].
|
||||||
// v0.8.0: originIcao/destIcao optionally FORCE an endpoint (spawn coverage rule +
|
// v0.8.0: originIcao/destIcao optionally FORCE an endpoint (spawn coverage rule +
|
||||||
// the e2e create-package hook); a forced endpoint consumes no RNG draws, so
|
// the e2e create-package hook); a forced endpoint consumes no RNG draws, so
|
||||||
// callers that omit both get byte-identical behavior to before.
|
// callers that omit both get byte-identical behavior to before.
|
||||||
|
// v0.27.0: weightKg optionally FORCES the package weight (e2e hook) — it skips the
|
||||||
|
// jitter draw, same pattern as forced endpoints.
|
||||||
export function generatePackage(input: {
|
export function generatePackage(input: {
|
||||||
id: string;
|
id: string;
|
||||||
airports: SeedAirport[];
|
airports: SeedAirport[];
|
||||||
@@ -112,6 +130,7 @@ export function generatePackage(input: {
|
|||||||
deadlineOffsetMs?: number;
|
deadlineOffsetMs?: number;
|
||||||
originIcao?: string;
|
originIcao?: string;
|
||||||
destIcao?: string;
|
destIcao?: string;
|
||||||
|
weightKg?: number;
|
||||||
}): SeedPackage {
|
}): SeedPackage {
|
||||||
const { airports, rng, nowMs } = input;
|
const { airports, rng, nowMs } = input;
|
||||||
if (airports.length < 2) throw new Error('package generation needs at least two airports');
|
if (airports.length < 2) throw new Error('package generation needs at least two airports');
|
||||||
@@ -143,6 +162,9 @@ export function generatePackage(input: {
|
|||||||
// Passengers up to the ATR 72's ~68 seats; other cargo in pallets.
|
// Passengers up to the ATR 72's ~68 seats; other cargo in pallets.
|
||||||
const cargoCount =
|
const cargoCount =
|
||||||
cargoType === 'Passengers' ? 1 + Math.floor(rng() * 68) : 1 + Math.floor(rng() * 50);
|
cargoType === 'Passengers' ? 1 + Math.floor(rng() * 68) : 1 + Math.floor(rng() * 50);
|
||||||
|
// Weight (v0.27.0): unit weight × count with ±30% jitter, integer kg — drawn AFTER
|
||||||
|
// cargoCount so the fixed RNG order above holds; a forced weightKg skips the draw.
|
||||||
|
const weightKg = input.weightKg ?? Math.round(UNIT_WEIGHT_KG[cargoType] * cargoCount * (0.7 + 0.6 * rng()));
|
||||||
const deadlineMs =
|
const deadlineMs =
|
||||||
input.deadlineOffsetMs ?? (DEADLINE_MIN_HOURS + rng() * (DEADLINE_MAX_HOURS - DEADLINE_MIN_HOURS)) * 3_600_000;
|
input.deadlineOffsetMs ?? (DEADLINE_MIN_HOURS + rng() * (DEADLINE_MAX_HOURS - DEADLINE_MIN_HOURS)) * 3_600_000;
|
||||||
|
|
||||||
@@ -150,9 +172,10 @@ export function generatePackage(input: {
|
|||||||
id: input.id,
|
id: input.id,
|
||||||
originIcao: origin.icao,
|
originIcao: origin.icao,
|
||||||
destIcao: dest.icao,
|
destIcao: dest.icao,
|
||||||
reward: rewardForDistanceKm(km),
|
reward: rewardFor(km, weightKg),
|
||||||
cargoType,
|
cargoType,
|
||||||
cargoCount,
|
cargoCount,
|
||||||
|
weightKg,
|
||||||
deadlineSimTime: Math.round(nowMs + deadlineMs),
|
deadlineSimTime: Math.round(nowMs + deadlineMs),
|
||||||
status: 'open',
|
status: 'open',
|
||||||
planeId: null,
|
planeId: null,
|
||||||
|
|||||||
+5
-1
@@ -50,8 +50,11 @@ export interface PackageState {
|
|||||||
reward: number;
|
reward: number;
|
||||||
cargoType: string;
|
cargoType: string;
|
||||||
cargoCount: number;
|
cargoCount: number;
|
||||||
|
// Package weight in kg (v0.27.0, ISS-045) — drives load validation + per-kg payout.
|
||||||
|
weightKg: number;
|
||||||
deadlineSimTime: number;
|
deadlineSimTime: number;
|
||||||
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned';
|
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
||||||
|
status: 'open' | 'loaded' | 'delivered' | 'expired' | 'abandoned' | 'ignored';
|
||||||
planeId: string | null;
|
planeId: string | null;
|
||||||
createdSimTime: number;
|
createdSimTime: number;
|
||||||
}
|
}
|
||||||
@@ -135,6 +138,7 @@ export async function getStateSnapshot(): Promise<StateSnapshot> {
|
|||||||
reward: p.reward,
|
reward: p.reward,
|
||||||
cargoType: p.cargoType,
|
cargoType: p.cargoType,
|
||||||
cargoCount: p.cargoCount,
|
cargoCount: p.cargoCount,
|
||||||
|
weightKg: p.weightKg,
|
||||||
deadlineSimTime: p.deadlineSimTime,
|
deadlineSimTime: p.deadlineSimTime,
|
||||||
status: p.status,
|
status: p.status,
|
||||||
planeId: p.planeId,
|
planeId: p.planeId,
|
||||||
|
|||||||
+65
-2
@@ -1,6 +1,6 @@
|
|||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from 'vitest';
|
||||||
import type { StateSnapshot } from './game/state';
|
import type { StateSnapshot } from './game/state';
|
||||||
import { planesGeoJson, routesGeoJson, hoverRouteGeoJson, hoverTraceGeoJson, greatCircleArc, ROUTE_ARC_SEGMENTS, type AirportCoord } from './mapData';
|
import { planesGeoJson, queuedRoutesGeoJson, routesGeoJson, hoverRouteGeoJson, hoverTraceGeoJson, greatCircleArc, ROUTE_ARC_SEGMENTS, type AirportCoord } from './mapData';
|
||||||
import { haversineKm } from './geo';
|
import { haversineKm } from './geo';
|
||||||
|
|
||||||
const AIRPORTS = new Map<string, AirportCoord>([
|
const AIRPORTS = new Map<string, AirportCoord>([
|
||||||
@@ -17,7 +17,7 @@ function snapshot(overrides: Partial<StateSnapshot> = {}): StateSnapshot {
|
|||||||
planes: [],
|
planes: [],
|
||||||
packages: [],
|
packages: [],
|
||||||
catalog: [
|
catalog: [
|
||||||
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9_300, speedKmh: 510, capacity: 6 },
|
{ model: 'atr72', label: 'ATR 72-600', price: 200_000, maxFuel: 6300, burnPerKm: 1.75, emptyWeightKg: 9_300, speedKmh: 510, maxPayloadKg: 4_800 },
|
||||||
],
|
],
|
||||||
fuelPricePerL: 0.8,
|
fuelPricePerL: 0.8,
|
||||||
sellFraction: 0.5,
|
sellFraction: 0.5,
|
||||||
@@ -140,6 +140,69 @@ describe('routesGeoJson (v0.12.0 — one line per flying plane\'s current leg)',
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('queuedRoutesGeoJson (ISS-043 v0.26.0 — dotted queue line: dest → queued legs only)', () => {
|
||||||
|
it('draws nothing for a grounded plane, even with a non-empty queue', () => {
|
||||||
|
const fc = queuedRoutesGeoJson(
|
||||||
|
[
|
||||||
|
{ id: 'p1', model: 'atr72', status: 'available', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: null, destName: null, departureSimTime: null, lat: 50.03, lon: 8.56, queue: ['EHAM'] },
|
||||||
|
],
|
||||||
|
AIRPORTS,
|
||||||
|
);
|
||||||
|
expect(fc.features).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('draws nothing for a flying plane with an empty queue', () => {
|
||||||
|
const fc = queuedRoutesGeoJson(
|
||||||
|
[
|
||||||
|
{ id: 'p1', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: 'EHAM', destName: 'A', departureSimTime: 0, lat: 51, lon: 9, queue: [] },
|
||||||
|
],
|
||||||
|
AIRPORTS,
|
||||||
|
);
|
||||||
|
expect(fc.features).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('flying plane with a 2-leg queue → one feature chaining dest → q0 → q1 with exact endpoints', () => {
|
||||||
|
const fc = queuedRoutesGeoJson(
|
||||||
|
[
|
||||||
|
// Active leg EDDF→EHAM stays in routesGeoJson; the queue line is ONLY EHAM → EDDV → LEMD.
|
||||||
|
{ id: 'p1', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: 'EHAM', destName: 'A', departureSimTime: 0, lat: 51, lon: 9, queue: ['EDDV', 'LEMD'] },
|
||||||
|
],
|
||||||
|
AIRPORTS,
|
||||||
|
);
|
||||||
|
expect(fc.features).toHaveLength(1);
|
||||||
|
expect(fc.features[0].properties).toEqual({ planeId: 'p1' });
|
||||||
|
const coords = fc.features[0].geometry.coordinates;
|
||||||
|
// Two concatenated arcs with the shared joint point dropped once: n_legs × SEGMENTS + 1 points.
|
||||||
|
expect(coords.length).toBe(2 * ROUTE_ARC_SEGMENTS + 1);
|
||||||
|
expect(coords[0]).toEqual([4.76, 52.31]); // starts at DEST (EHAM), not at the plane's origin
|
||||||
|
expect(coords[coords.length - 1]).toEqual([-3.56, 40.47]); // ends at the last queued airport (LEMD)
|
||||||
|
expect(coords[ROUTE_ARC_SEGMENTS]).toEqual([9.68, 52.46]); // joint point = first queued airport (EDDV), exact
|
||||||
|
});
|
||||||
|
|
||||||
|
it('skips a plane whose dest or a queued ICAO is missing from the airport index', () => {
|
||||||
|
const fc = queuedRoutesGeoJson(
|
||||||
|
[
|
||||||
|
{ id: 'p1', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: 'ZZZZ', destName: '?', departureSimTime: 0, lat: 51, lon: 9, queue: ['EHAM'] },
|
||||||
|
{ id: 'p2', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: 'EHAM', destName: 'A', departureSimTime: 0, lat: 51, lon: 9, queue: ['ZZZZ'] },
|
||||||
|
],
|
||||||
|
AIRPORTS,
|
||||||
|
);
|
||||||
|
expect(fc.features).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('one feature per qualifying plane — grounded and empty-queue planes draw nothing', () => {
|
||||||
|
const fc = queuedRoutesGeoJson(
|
||||||
|
[
|
||||||
|
{ id: 'p1', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EDDF', locationName: 'F', destIcao: 'EHAM', destName: 'A', departureSimTime: 0, lat: 51, lon: 9, queue: ['LEMD'] },
|
||||||
|
{ id: 'p2', model: 'atr72', status: 'flying', fuel: 1, maxFuel: 2, locationIcao: 'EHAM', locationName: 'A', destIcao: 'EDDV', destName: 'H', departureSimTime: 0, lat: 52.3, lon: 4.7, queue: [] },
|
||||||
|
{ id: 'p3', model: 'atr72', status: 'available', fuel: 1, maxFuel: 2, locationIcao: 'EDDV', locationName: 'H', destIcao: null, destName: null, departureSimTime: null, lat: 52.46, lon: 9.68, queue: ['LEMD'] },
|
||||||
|
],
|
||||||
|
AIRPORTS,
|
||||||
|
);
|
||||||
|
expect(fc.features.map((f) => f.properties.planeId)).toEqual(['p1']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('hoverRouteGeoJson (ISS-022/025/027 v0.22.0 — hover route trace)', () => {
|
describe('hoverRouteGeoJson (ISS-022/025/027 v0.22.0 — hover route trace)', () => {
|
||||||
it('returns an empty collection for the no-hover "" sentinel', () => {
|
it('returns an empty collection for the no-hover "" sentinel', () => {
|
||||||
expect(hoverRouteGeoJson('', '', AIRPORTS)).toEqual({ type: 'FeatureCollection', features: [] });
|
expect(hoverRouteGeoJson('', '', AIRPORTS)).toEqual({ type: 'FeatureCollection', features: [] });
|
||||||
|
|||||||
+29
-1
@@ -1,4 +1,4 @@
|
|||||||
import type { StateSnapshot } from './game/state';
|
import type { PlaneState, StateSnapshot } from './game/state';
|
||||||
import { formatFuel } from './format';
|
import { formatFuel } from './format';
|
||||||
import { positionAt } from './sim/movement';
|
import { positionAt } from './sim/movement';
|
||||||
|
|
||||||
@@ -164,3 +164,31 @@ export function routesGeoJson(
|
|||||||
}
|
}
|
||||||
return { type: 'FeatureCollection', features };
|
return { type: 'FeatureCollection', features };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ISS-043 (v0.26.0): the dotted queue line — one LineString per FLYING plane with a non-empty
|
||||||
|
// queue, chaining dest → queue[0] → … → queue[n−1]: ONLY the not-yet-started legs (the active
|
||||||
|
// leg locationIcao→dest stays in routesGeoJson's solid layer). Arcs are concatenated with the
|
||||||
|
// shared joint point dropped once. A plane is skipped — never guessed — when its dest or any
|
||||||
|
// queued ICAO is missing from the airport index; empty collection when nothing qualifies.
|
||||||
|
export function queuedRoutesGeoJson(
|
||||||
|
planes: PlaneState[],
|
||||||
|
airportsByIcao: ReadonlyMap<string, AirportCoord>,
|
||||||
|
): FeatureCollection<MapLineFeature> {
|
||||||
|
const features: MapLineFeature[] = [];
|
||||||
|
for (const p of planes) {
|
||||||
|
if (p.status !== 'flying' || !p.destIcao || p.queue.length === 0) continue;
|
||||||
|
const pts = [p.destIcao, ...p.queue].map((icao) => airportsByIcao.get(icao));
|
||||||
|
if (pts.some((c) => c === undefined)) continue; // an endpoint is missing from the dataset — skip
|
||||||
|
const coords: [number, number][] = [];
|
||||||
|
for (let i = 0; i < pts.length - 1; i++) {
|
||||||
|
const arc = greatCircleArc(pts[i]!, pts[i + 1]!);
|
||||||
|
coords.push(...(i === 0 ? arc : arc.slice(1))); // drop the duplicated joint point
|
||||||
|
}
|
||||||
|
features.push({
|
||||||
|
type: 'Feature',
|
||||||
|
geometry: { type: 'LineString', coordinates: coords },
|
||||||
|
properties: { planeId: p.id },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return { type: 'FeatureCollection', features };
|
||||||
|
}
|
||||||
|
|||||||
+6
-5
@@ -3,12 +3,13 @@ import { describe, expect, it } from 'vitest';
|
|||||||
import { openApiSpec } from './openapi';
|
import { openApiSpec } from './openapi';
|
||||||
|
|
||||||
describe('OpenAPI spec', () => {
|
describe('OpenAPI spec', () => {
|
||||||
it('documents exactly the twelve public endpoints (4 read + 8 player actions)', () => {
|
it('documents exactly the thirteen public endpoints (4 read + 9 player actions)', () => {
|
||||||
expect(Object.keys(openApiSpec.paths).sort()).toEqual([
|
expect(Object.keys(openApiSpec.paths).sort()).toEqual([
|
||||||
'/api/airports',
|
'/api/airports',
|
||||||
'/api/market/buy-plane',
|
'/api/market/buy-plane',
|
||||||
'/api/market/sell-plane',
|
'/api/market/sell-plane',
|
||||||
'/api/packages/{id}/abandon',
|
'/api/packages/{id}/abandon',
|
||||||
|
'/api/packages/{id}/ignore', // v0.29.0 (ISS-047 part B)
|
||||||
'/api/packages/{id}/load',
|
'/api/packages/{id}/load',
|
||||||
'/api/planes/{planeId}/fly',
|
'/api/planes/{planeId}/fly',
|
||||||
'/api/planes/{planeId}/queue', // v0.25.0 (ISS-043)
|
'/api/planes/{planeId}/queue', // v0.25.0 (ISS-043)
|
||||||
@@ -94,18 +95,17 @@ describe('OpenAPI spec', () => {
|
|||||||
const catalog = openApiSpec.components.schemas.CatalogEntry.properties;
|
const catalog = openApiSpec.components.schemas.CatalogEntry.properties;
|
||||||
expect(Object.keys(catalog).sort()).toEqual([
|
expect(Object.keys(catalog).sort()).toEqual([
|
||||||
'burnPerKm',
|
'burnPerKm',
|
||||||
'capacity',
|
|
||||||
'emptyWeightKg', // v0.16.0 weighted burn model input
|
'emptyWeightKg', // v0.16.0 weighted burn model input
|
||||||
'label',
|
'label',
|
||||||
'maxFuel',
|
'maxFuel',
|
||||||
|
'maxPayloadKg', // v0.27.0 (ISS-045) — replaces the v0.12.0 slot capacity
|
||||||
'model',
|
'model',
|
||||||
'price',
|
'price',
|
||||||
'speedKmh',
|
'speedKmh',
|
||||||
]);
|
]);
|
||||||
for (const key of ['burnPerKm', 'emptyWeightKg', 'maxFuel', 'price', 'speedKmh'] as const) {
|
for (const key of ['burnPerKm', 'emptyWeightKg', 'maxFuel', 'maxPayloadKg', 'price', 'speedKmh'] as const) {
|
||||||
expect(catalog[key].type, `CatalogEntry.${key}`).toBe('number');
|
expect(catalog[key].type, `CatalogEntry.${key}`).toBe('number');
|
||||||
}
|
}
|
||||||
expect(catalog.capacity.type).toBe('integer'); // v0.12.0 slot capacity
|
|
||||||
expect(catalog.model.type).toBe('string');
|
expect(catalog.model.type).toBe('string');
|
||||||
expect(catalog.label.type).toBe('string');
|
expect(catalog.label.type).toBe('string');
|
||||||
|
|
||||||
@@ -140,13 +140,14 @@ describe('OpenAPI spec', () => {
|
|||||||
'planeId',
|
'planeId',
|
||||||
'reward',
|
'reward',
|
||||||
'status',
|
'status',
|
||||||
|
'weightKg', // v0.27.0 (ISS-045) — package weight in kg
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const sim = openApiSpec.components.schemas.SimState.properties;
|
const sim = openApiSpec.components.schemas.SimState.properties;
|
||||||
expect(Object.keys(sim).sort()).toEqual(['clockMs', 'paused', 'timeScale']);
|
expect(Object.keys(sim).sort()).toEqual(['clockMs', 'paused', 'timeScale']);
|
||||||
|
|
||||||
const packageStatus = openApiSpec.components.schemas.PackageState.properties.status;
|
const packageStatus = openApiSpec.components.schemas.PackageState.properties.status;
|
||||||
expect(packageStatus.enum.sort()).toEqual(['abandoned', 'delivered', 'expired', 'loaded', 'open']);
|
expect(packageStatus.enum.sort()).toEqual(['abandoned', 'delivered', 'expired', 'ignored', 'loaded', 'open']); // v0.29.0 (ISS-047 part B)
|
||||||
});
|
});
|
||||||
|
|
||||||
it('describes POST /api/sim as SimControlsRequest → SimState with a 400 error shape', () => {
|
it('describes POST /api/sim as SimControlsRequest → SimState with a 400 error shape', () => {
|
||||||
|
|||||||
+33
-5
@@ -106,7 +106,7 @@ export const openApiSpec = {
|
|||||||
post: {
|
post: {
|
||||||
summary: 'Load a package onto a plane',
|
summary: 'Load a package onto a plane',
|
||||||
description:
|
description:
|
||||||
'Bind an OPEN package to a GROUNDED ("available") plane at the package\'s origin (v0.12.0). The plane needs a free slot — capacity per catalog model; expired packages still occupy theirs. The sim clock is ticked first, so the returned snapshot reflects current game time.',
|
'Bind an OPEN package to a GROUNDED ("available") plane at the package\'s origin (v0.12.0). The plane needs enough payload room for the package weight — maxPayloadKg per catalog model; expired packages still occupy theirs (v0.27.0). The sim clock is ticked first, so the returned snapshot reflects current game time.',
|
||||||
operationId: 'loadPackage',
|
operationId: 'loadPackage',
|
||||||
parameters: [
|
parameters: [
|
||||||
{ name: 'id', in: 'path', required: true, schema: { type: 'string' } },
|
{ name: 'id', in: 'path', required: true, schema: { type: 'string' } },
|
||||||
@@ -165,6 +165,31 @@ export const openApiSpec = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
'/api/packages/{id}/ignore': {
|
||||||
|
post: {
|
||||||
|
summary: 'Ignore an open job',
|
||||||
|
description:
|
||||||
|
'Dismiss an OPEN job so it leaves the market permanently (v0.29.0, ISS-047 part B). No penalty and nothing else changes — the top-up logic spawns a replacement on the next tick. No body.',
|
||||||
|
operationId: 'ignorePackage',
|
||||||
|
parameters: [
|
||||||
|
{ name: 'id', in: 'path', required: true, schema: { type: 'string' } },
|
||||||
|
],
|
||||||
|
responses: {
|
||||||
|
200: {
|
||||||
|
description: 'Ignored — full state snapshot (package "ignored", gone from the open list)',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/StateSnapshot' } } },
|
||||||
|
},
|
||||||
|
404: {
|
||||||
|
description: 'Unknown package id',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
409: {
|
||||||
|
description: 'Package not "open"',
|
||||||
|
content: { 'application/json': { schema: { $ref: '#/components/schemas/Error' } } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
'/api/planes/{planeId}/fly': {
|
'/api/planes/{planeId}/fly': {
|
||||||
post: {
|
post: {
|
||||||
summary: 'Fly a plane to an airport',
|
summary: 'Fly a plane to an airport',
|
||||||
@@ -461,9 +486,9 @@ export const openApiSpec = {
|
|||||||
burnPerKm: { type: 'number', description: 'Cruise fuel burn at a full tank, liters/km (v0.16.0 weighted model calibrates to this).' },
|
burnPerKm: { type: 'number', description: 'Cruise fuel burn at a full tank, liters/km (v0.16.0 weighted model calibrates to this).' },
|
||||||
emptyWeightKg: { type: 'number', description: 'Operating empty weight, kg — with burnPerKm and maxFuel it drives the v0.16.0 weight-proportional burn model.' },
|
emptyWeightKg: { type: 'number', description: 'Operating empty weight, kg — with burnPerKm and maxFuel it drives the v0.16.0 weight-proportional burn model.' },
|
||||||
speedKmh: { type: 'number', description: 'Cruise speed, km/h.' },
|
speedKmh: { type: 'number', description: 'Cruise speed, km/h.' },
|
||||||
capacity: { type: 'integer', description: 'Cargo slot capacity — packages that can be loaded on one plane (v0.12.0).' },
|
maxPayloadKg: { type: 'number', description: 'Max payload in kg — total package weight that can be loaded on one plane (v0.27.0, replaces the v0.12.0 slot count).' },
|
||||||
},
|
},
|
||||||
required: ['model', 'label', 'price', 'maxFuel', 'burnPerKm', 'emptyWeightKg', 'speedKmh', 'capacity'],
|
required: ['model', 'label', 'price', 'maxFuel', 'burnPerKm', 'emptyWeightKg', 'speedKmh', 'maxPayloadKg'],
|
||||||
},
|
},
|
||||||
AccountState: {
|
AccountState: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
@@ -498,7 +523,7 @@ export const openApiSpec = {
|
|||||||
LoadPackageRequest: {
|
LoadPackageRequest: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
planeId: { type: 'string', description: 'A GROUNDED ("available") plane at the package\'s origin with a free slot.' },
|
planeId: { type: 'string', description: 'A GROUNDED ("available") plane at the package\'s origin with enough payload room for it (v0.27.0).' },
|
||||||
},
|
},
|
||||||
required: ['planeId'],
|
required: ['planeId'],
|
||||||
},
|
},
|
||||||
@@ -618,10 +643,12 @@ export const openApiSpec = {
|
|||||||
reward: { type: 'number' },
|
reward: { type: 'number' },
|
||||||
cargoType: { type: 'string' },
|
cargoType: { type: 'string' },
|
||||||
cargoCount: { type: 'integer' },
|
cargoCount: { type: 'integer' },
|
||||||
|
weightKg: { type: 'number', description: 'Package weight in kg (v0.27.0) — drives load validation and the per-kg payout part.' },
|
||||||
deadlineSimTime: { type: 'integer', description: 'Sim-clock epoch ms (game time)' },
|
deadlineSimTime: { type: 'integer', description: 'Sim-clock epoch ms (game time)' },
|
||||||
// 'expired' = an open OR loaded package whose deadline passed on a tick;
|
// 'expired' = an open OR loaded package whose deadline passed on a tick;
|
||||||
// loaded expired packages keep their slot, deliver no reward, abandon free.
|
// loaded expired packages keep their slot, deliver no reward, abandon free.
|
||||||
status: { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned'] },
|
// 'ignored' (v0.29.0, ISS-047 part B) = a dismissed open job — terminal, leaves the market.
|
||||||
|
status: { enum: ['open', 'loaded', 'delivered', 'expired', 'abandoned', 'ignored'] },
|
||||||
planeId: { type: ['string', 'null'] },
|
planeId: { type: ['string', 'null'] },
|
||||||
createdSimTime: { type: 'integer' },
|
createdSimTime: { type: 'integer' },
|
||||||
},
|
},
|
||||||
@@ -634,6 +661,7 @@ export const openApiSpec = {
|
|||||||
'reward',
|
'reward',
|
||||||
'cargoType',
|
'cargoType',
|
||||||
'cargoCount',
|
'cargoCount',
|
||||||
|
'weightKg', // v0.27.0 (ISS-045) — package weight in kg
|
||||||
'deadlineSimTime',
|
'deadlineSimTime',
|
||||||
'status',
|
'status',
|
||||||
'planeId',
|
'planeId',
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ describe('expirePackages', () => {
|
|||||||
{ id: 'p-loaded-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
{ id: 'p-loaded-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'loaded', planeId: 'plane-starter', createdSimTime: T0 },
|
||||||
{ id: 'p-delivered-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'delivered', planeId: null, createdSimTime: T0 },
|
{ id: 'p-delivered-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'delivered', planeId: null, createdSimTime: T0 },
|
||||||
{ id: 'p-abandoned-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'abandoned', planeId: null, createdSimTime: T0 },
|
{ id: 'p-abandoned-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'abandoned', planeId: null, createdSimTime: T0 },
|
||||||
|
{ id: 'p-ignored-past', originIcao: 'EDDF', destIcao: 'LEMD', reward: 1, cargoType: 'Mail', cargoCount: 1, deadlineSimTime: clock - 1, status: 'ignored', planeId: null, createdSimTime: T0 },
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const n = await expirePackages(inst, clock);
|
const n = await expirePackages(inst, clock);
|
||||||
@@ -116,6 +117,7 @@ describe('expirePackages', () => {
|
|||||||
expect(byId.get('p-loaded-past')).toBe('expired'); // v0.12.0: loaded packages expire too (keep their slot)
|
expect(byId.get('p-loaded-past')).toBe('expired'); // v0.12.0: loaded packages expire too (keep their slot)
|
||||||
expect(byId.get('p-delivered-past')).toBe('delivered'); // terminal — never flips
|
expect(byId.get('p-delivered-past')).toBe('delivered'); // terminal — never flips
|
||||||
expect(byId.get('p-abandoned-past')).toBe('abandoned'); // terminal — never flips
|
expect(byId.get('p-abandoned-past')).toBe('abandoned'); // terminal — never flips
|
||||||
|
expect(byId.get('p-ignored-past')).toBe('ignored'); // v0.29.0 (ISS-047 part B) — terminal, never flips
|
||||||
});
|
});
|
||||||
|
|
||||||
it('a deadline exactly at the clock counts as expired', async () => {
|
it('a deadline exactly at the clock counts as expired', async () => {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
burnRateConstant,
|
burnRateConstant,
|
||||||
FUEL_DENSITY_KG_PER_L,
|
FUEL_DENSITY_KG_PER_L,
|
||||||
fuelAtWeighted,
|
fuelAtWeighted,
|
||||||
|
maxRangeKm,
|
||||||
positionAt,
|
positionAt,
|
||||||
progressAt,
|
progressAt,
|
||||||
requiredFuelFor,
|
requiredFuelFor,
|
||||||
@@ -164,3 +165,24 @@ describe('weighted burn model (v0.16.0)', () => {
|
|||||||
expect(fuelAtWeighted(TANK, BURN, WE, TANK, KM, progressAt(DEP, KM, SPEED, clock))).toBeGreaterThan(0);
|
expect(fuelAtWeighted(TANK, BURN, WE, TANK, KM, progressAt(DEP, KM, SPEED, clock))).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('maxRangeKm (v0.28.0)', () => {
|
||||||
|
it('ATR 72-600 full tank ≈ 4439 km (±5%)', () => {
|
||||||
|
const r = maxRangeKm(BURN, WE, TANK);
|
||||||
|
expect(r).toBeGreaterThan(4439 * 0.95);
|
||||||
|
expect(r).toBeLessThan(4439 * 1.05);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('increases with tank size and decreases with burn rate', () => {
|
||||||
|
expect(maxRangeKm(BURN, WE, TANK * 2)).toBeGreaterThan(maxRangeKm(BURN, WE, TANK));
|
||||||
|
expect(maxRangeKm(3, WE, TANK)).toBeLessThan(maxRangeKm(BURN, WE, TANK));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zero fuel → zero range', () => {
|
||||||
|
expect(maxRangeKm(BURN, WE, 0)).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects a non-positive empty weight', () => {
|
||||||
|
expect(() => maxRangeKm(BURN, 0, TANK)).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -118,3 +118,13 @@ export function requiredFuelFor(
|
|||||||
const rho = FUEL_DENSITY_KG_PER_L;
|
const rho = FUEL_DENSITY_KG_PER_L;
|
||||||
return (emptyWeightKg / rho) * (Math.exp(k * rho * distanceKm) - 1);
|
return (emptyWeightKg / rho) * (Math.exp(k * rho * distanceKm) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Max range from a FULL tank under the weighted model — solve requiredFuelFor(d) = maxFuel for d:
|
||||||
|
// (We/ρ)(e^{kρd} − 1) = F → d = ln(1 + ρF/We) · (We + ρF)/(ρ·burnPerKm).
|
||||||
|
// Returns raw km (call sites round); zero fuel gives exactly 0. Pure — display-only, the sim
|
||||||
|
// itself does not model range exhaustion (see fuelAtWeighted).
|
||||||
|
export function maxRangeKm(burnPerKm: number, emptyWeightKg: number, maxFuel: number): number {
|
||||||
|
if (!(emptyWeightKg > 0)) throw new Error('emptyWeightKg must be > 0');
|
||||||
|
const rho = FUEL_DENSITY_KG_PER_L;
|
||||||
|
return Math.log(1 + (rho * maxFuel) / emptyWeightKg) * ((emptyWeightKg + rho * maxFuel) / (rho * burnPerKm));
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "flight-ops",
|
"name": "flight-ops",
|
||||||
"version": "0.25.0",
|
"version": "0.29.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 3000",
|
"dev": "next dev -p 3000",
|
||||||
|
|||||||
Reference in New Issue
Block a user