Files
star-map/e2e/route-plotting.spec.ts
T
SenrokaiandClaude Fable 5 68a919bd84 Route between stars, through the crossings a chosen range allows
The map could say where a star is and what is near it, and nothing about
getting from one to another. This adds the question and the answer: pick a
departure and a destination, choose how far a single crossing may be, and get
the chain — how many jumps, how far in total, and every star on the way, each
one a step you can fly to.

A jump link is not a feature of space. There are no corridors out there; a
link is a question asked of the catalogue, which is why the range is the
user's control rather than a constant. Two facts about that catalogue decide
what the answers look like, and both are stated in the code because they read
as defects otherwise. It is magnitude-limited, so it is dense around the Sun
and thins with distance — within 50 pc a 3 pc range links 99% of it into one
piece, while over the whole 250 pc reach the same range leaves most stars
alone. And a gap in it is a gap in what has been catalogued, not in what is
there.

That is why "no route" is not the end of the answer. Where no chain exists at
the range asked for, the panel says which range would open one — the chain
whose longest hop is as short as possible, found by the same search with the
cost of arriving somewhere being the worst hop taken rather than the sum — and
offers that number as a control to accept.

Departure defaults to wherever the view already is, so one field is usually
enough. Sol to Vega at 3 pc: four jumps, 10 pc, by way of Barnard's Star,
Struve 2398 B and HD 155876. Narrow it to 0.8 pc and it says 2.26 would reach.

The graph is drawn as one buffer of line segments and the route as a second,
brighter one over it, with the graph stepping back while a route is up: near
the Sun the links are a haze, and a thread through a bright cloud is not a
thread. Both fade out with the local layer, since from outside the Galaxy the
graph is a smear.

Two measurements shaped this. Asking the index for each star's neighbours in
turn — sixty-eight thousand sorted lists, thrown away — took eight seconds; the
grid now walks its own cells once and pairs them, which takes a quarter of one.
And the range control emits per pixel dragged, so the rebuild waits for the
hand to settle.

Three defects fixed on the way, all older than the routing:

hud-acquire animated with fill-mode `both`, which leaves its closing keyframe
applied for good — and that keyframe carries a clip-path. Every panel wearing
it has been clipping its own box ever since, so anything that had to escape
one was cut away and could not even be clicked. Nothing had needed to escape
until this panel's dropdown opened upward.

The routing fields returned nothing when typed into before the catalogue
finished loading, and stayed nothing until the next keystroke. The options are
derived from the query and the index together now, so they appear when the
second of the two arrives, whichever that is.

And a link was `3-7` walking one way and `7-3` walking the other, which is two
links to anything comparing them.

Verified: build clean, 571/571 unit, 9/9 end-to-end including two new specs —
one plotting Sol to Sirius, one narrowing the range until there is no route and
accepting the one it names — design detector clean, screenshots at 1440x900
and 390x844.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016jxMkwA2rbicdGxHosecYi
2026-08-20 18:39:22 +02:00

62 lines
2.8 KiB
TypeScript

import { expect, test } from '@playwright/test';
test.describe('Route plotting', () => {
test('chains one star to another through the crossings a chosen range allows', async ({ page }) => {
test.setTimeout(90_000);
await page.goto('/?stars=4000');
await expect(page.getByTestId('scene-canvas')).toBeVisible();
await page.getByRole('tab', { name: 'Routes' }).click();
// Sirius is 2.64 pc from the Sun, so the default 3 pc range crosses it in one.
await page.locator('#route-from').fill('Sol');
const departure = page.locator('#dock-panel-routes ul li button').first();
await expect(departure).toBeVisible({ timeout: 30_000 });
await departure.click();
await page.locator('#route-to').fill('Sirius');
const destination = page.locator('#dock-panel-routes ul li button').first();
await expect(destination).toBeVisible();
await destination.click();
await page.getByRole('button', { name: 'Plot route' }).click();
await expect(page.getByTestId('route-summary')).toHaveText(/1 jump · 2\.6\d pc/);
// The chain itself, departure first, each step a way to fly there.
const steps = page.getByTestId('route-steps').getByRole('button');
await expect(steps).toHaveCount(2);
await expect(steps.first()).toContainText('Sol');
await expect(steps.last()).toContainText('Sirius');
});
test('says what range a crossing would need, rather than only that there is none', async ({ page }) => {
test.setTimeout(90_000);
await page.goto('/?stars=4000');
await expect(page.getByTestId('scene-canvas')).toBeVisible();
await page.getByRole('tab', { name: 'Routes' }).click();
await page.locator('#route-from').fill('Sol');
const departure = page.locator('#dock-panel-routes ul li button').first();
await expect(departure).toBeVisible({ timeout: 30_000 });
await departure.click();
// Narrowed until nothing the catalogue holds is within reach of the Sun: its nearest
// neighbour is 1.30 pc away, so half a parsec strands it.
await page.locator('#route-range').fill('0.5');
await page.locator('#route-to').fill('Sirius');
const destination = page.locator('#dock-panel-routes ul li button').first();
await expect(destination).toBeVisible();
await destination.click();
await page.getByRole('button', { name: 'Plot route' }).click();
const summary = page.getByTestId('route-summary');
await expect(summary).toContainText('No route at this range', { timeout: 30_000 });
// And the answer, not just the refusal: the range that would open one, offered as a control.
const raise = summary.getByRole('button');
await expect(raise).toContainText(/pc would reach/);
await raise.click();
await expect(page.getByTestId('route-summary')).toContainText(/jump/, { timeout: 30_000 });
});
});