The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.
JavaScript
Harden audit findings and FIRMS zoom behavior (#77)
OsintMeThat2f66b0154c4b
diff --git a/README.md b/README.mdindex 4e90849..330a068 100644--- a/README.md+++ b/README.md@@ -303,6 +303,12 @@ Then commit `packaging/updates.json`. That file is what`browser_specific_settings.gecko.update_url` points at, served raw from `main`,and Firefox re-reads it about once a day — so a release that changed theextension is not delivered to Firefox users until it lands on the branch.+After that manifest PR is merged, verify the public manifest, asset URL and+signed bytes together:++```bash+python3 scripts/sign_extension.py --verify-release+```Two rules the script enforces rather than trusts:diff --git a/docs/IMAGERY_PROVIDERS.md b/docs/IMAGERY_PROVIDERS.mdindex 9c96f56..ef2289a 100644--- a/docs/IMAGERY_PROVIDERS.md+++ b/docs/IMAGERY_PROVIDERS.md@@ -341,7 +341,7 @@ meter, no free-allowance box and no eco threshold. Nothing about it is billed.| Asking | WMS `GetMap` in EPSG:3857 — the projection the tile grid is already in, so a tile is its own square and nothing is reprojected || Live | `fires_viirs_24 / _48 / _72 / _7`, and the same for `fires_viirs_snpp`, `fires_viirs_noaa20` and `fires_modis` || History | the same layer names without the suffix, dated with `TIME=from/to`, up to **31 days** per request |-| Zoom ceiling | z14. FIRMS draws a fixed symbol per detection and VIIRS resolves 375 m; deeper is a screen of overlapping marks, and the route refuses it |+| Zoom ceiling | source tiles stop at z14. Deeper views reuse the z14 tile with nearest-neighbour scaling, keeping each detection visible as a square without another NASA request || Allowance | 5,000 requests per 10 minutes, and a long range counts as several. Nothing polls, and a layer that is off asks for nothing || Caching | none on disk. The live layers are what is burning now (upstream refreshes every 15 minutes) and a cached fire is a lie with a timestamp; the browser holds one for 5 minutes |diff --git a/docs/RELEASE_NOTES.md b/docs/RELEASE_NOTES.mdindex b01e1cd..be2547c 100644--- a/docs/RELEASE_NOTES.md+++ b/docs/RELEASE_NOTES.md@@ -22,7 +22,8 @@ work as before, including the Google basemap.release.- Stack overlays that need no key: borders, roads, railways, power lines, seamarks and GPS traces. Add NASA FIRMS fire detections (with a free FIRMS key in- Settings) and VIIRS night lights for a day you pick.+ Settings) and VIIRS night lights for a day you pick. FIRMS detections remain+ visible as enlarged squares when you zoom past their native detail.- Filter the pins drawn on the map by kind and by folder.- Open the map in several tabs. The view is in the address, two tabs can share onecamera, and a point saved or a grid swept in one appears at once in the others.diff --git a/docs/UI.md b/docs/UI.mdindex d792cce..127f40e 100644--- a/docs/UI.md+++ b/docs/UI.md@@ -1298,9 +1298,9 @@ what is burning now (the last 24, 48 or 72 hours, or the week) and what wasburning on a given day (any range back through the archive, up to 31 days).Which instrument and which stretch of time are chosen in the row itself. Itneeds a key, and says so with the reason rather than failing on the first tile;-a key pasted into Settings is picked up on the way back to the map. The-detections stop being drawn past z14, where FIRMS's fixed symbol per detection-stops meaning one detection.+a key pasted into Settings is picked up on the way back to the map. Source+tiles stop at z14. Farther in, the map enlarges their pixels into visible+squares instead of hiding the detections or asking NASA for invented detail.**The reference layers** are key-less and each is simply on or off: Esri'sborders (country, region, district, with names) and roads, Open Infrastructurediff --git a/frontend/e2e/app.fixture.js b/frontend/e2e/app.fixture.jsindex 13fc98f..b520231 100644--- a/frontend/e2e/app.fixture.js+++ b/frontend/e2e/app.fixture.js@@ -680,6 +680,7 @@ export async function installAppFixture(page, options = {}) {const unexpected = [];const labelTiles = [];const captures = [];+ const placeWrites = [];const proofSaves = [];const fixtureSavedIndex = options.savedIndex ?? savedIndex;const fixtureProofIndex = options.proofIndex ?? [];@@ -925,9 +926,9 @@ export async function installAppFixture(page, options = {}) {};await page.addInitScript((caseId) => {- localStorage.setItem('azimut:lastCase', caseId);+ if (caseId) localStorage.setItem('azimut:lastCase', caseId);localStorage.setItem('azimut:theme', 'dark');- }, CASE_ID);+ }, options.lastCase === undefined ? CASE_ID : options.lastCase);await page.route('**/*', async (route) => {const request = route.request();@@ -1820,6 +1821,16 @@ export async function installAppFixture(page, options = {}) {tiles_upscaled: 0,});}+ if (caseId && path === `/api/cases/${caseId}/satellite/place` && request.method() === 'POST') {+ const payload = request.postDataJSON();+ placeWrites.push({ caseId, ...payload });+ return json(route, {+ id: `place-${placeWrites.length}`,+ type: 'place',+ label: 'Saved place',+ attrs: payload,+ });+ }if (path === `/api/cases/${CASE_ID}/proofs` && request.method() === 'POST') {const payload = request.postDataJSON();proofSaves.push(payload);@@ -1931,6 +1942,7 @@ export async function installAppFixture(page, options = {}) {return {captures,+ placeWrites,labelTiles,widgetLoads,gridWrites,diff --git a/frontend/e2e/satellite-windows.spec.js b/frontend/e2e/satellite-windows.spec.jsindex bf4d868..a33796d 100644--- a/frontend/e2e/satellite-windows.spec.js+++ b/frontend/e2e/satellite-windows.spec.js@@ -87,6 +87,31 @@ test('hands a second window the view the first one is showing', async ({ page, cawait second.close();});+test('binds a detached window to its parent case, not shared last-case storage', async ({ page, context }) => {+ const cases = [+ { id: 'browser-test', name: 'Case A', scratch: false, entities: [], links: [], folders: [] },+ { id: 'case-b', name: 'Case B', scratch: false, entities: [], links: [], folders: [] },+ ];+ await installAppFixture(page, { cases });+ await page.goto('/#satellite?ll=50.4501,30.5234&z=13');+ await awaitMapReady(page);+ // Another app tab last opened B. localStorage is shared across both windows.+ await page.evaluate(() => localStorage.setItem('azimut:lastCase', 'case-b'));++ const opening = context.waitForEvent('page');+ await page.getByRole('button', { name: 'Open in a new tab' }).click();+ const second = await opening;+ expect(new URL(second.url()).hash).toContain('case=browser-test');+ const fixture = await installAppFixture(second, { cases, lastCase: 'case-b' });+ await second.reload();+ await awaitMapReady(second);+ await second.getByRole('button', { name: 'Save place', exact: true }).click();++ await expect.poll(() => fixture.placeWrites.length).toBe(1);+ expect(fixture.placeWrites[0].caseId).toBe('browser-test');+ await second.close();+});+test('opens the detached tab on the map, without the app around it', async ({ page, context }) => {await installAppFixture(page);await page.goto('/#satellite?ll=50.4501,30.5234&z=13');diff --git a/frontend/src/App.svelte b/frontend/src/App.svelteindex 9530455..e081240 100644--- a/frontend/src/App.svelte+++ b/frontend/src/App.svelte@@ -190,8 +190,13 @@// downloaders, the capture extension. The check reads prefs.updateCheckOnStart// and the bundled extension version, so it must follow initSession, which// loads them.- initSession()- .catch(() => {})+ const startupCaseId = solo ? splitHash(location.hash).params.get('case') : null;+ initSession(startupCaseId)+ .catch((error) => {+ if (startupCaseId) {+ toast(`Could not open this map's case: ${error?.message ?? 'case not found'}`, 'danger', 8000);+ }+ }).finally(() => checkForUpdatesOnStart());// Live nudges from our own backend (SSE, same-origin — still local-first):diff --git a/frontend/src/lib/guide.js b/frontend/src/lib/guide.jsindex cb50dda..ead9396 100644--- a/frontend/src/lib/guide.js+++ b/frontend/src/lib/guide.js@@ -80,8 +80,8 @@ export const GUIDE = [tools: [],points: [{- label: 'Azimut writes the folder for you',- text: 'Settings, then Capture extension: press Install, copy the path it gives you, and load it unpacked in your browser. The pairing token on the same tab is what ties it to this workspace.',+ label: 'Install it for your browser',+ text: 'In Chromium, Settings writes a folder that you load unpacked. In Firefox, install the signed XPI attached to the release. The pairing token ties either copy to this workspace.',},{label: 'It files three things',@@ -92,12 +92,12 @@ export const GUIDE = [text: 'Measure, media pins, sun and moon, a search grid and windows holding the case images, on the map sites you were going to use anyway. A pitched or panoramic view switches the geometry off rather than guessing at it.',},{- label: 'It reaches past this machine in exactly one place',- text: 'Filling the composer on X or Bluesky with a thread Geo Report prepared. It types what the app handed it and reads nothing back. Everything else it does talks to Azimut on localhost.',+ label: 'It reaches outside only when you ask',+ text: 'It can fill a composer on X or Bluesky and send a prepared image to a reverse-search engine. Everything else it sends goes to Azimut on localhost.',},{- label: 'Updating it is one click',- text: 'The app owns the folder, so a new release rewrites the files in place and the extension restarts. Settings says when two copies are loaded and which one to remove.',+ label: 'Updates follow the browser',+ text: 'Chromium updates its managed folder from Settings. Firefox updates the signed XPI from the release manifest. Settings also warns when two copies are loaded.',},],},diff --git a/frontend/src/lib/guide.test.js b/frontend/src/lib/guide.test.jsindex 4db3e03..150ad42 100644--- a/frontend/src/lib/guide.test.js+++ b/frontend/src/lib/guide.test.js@@ -76,6 +76,15 @@ describe('the guide tracks the app rather than falling behind it', () => {expect(GUIDE[0].points[0].label).toContain('extension');});+ it('distinguishes browser installation and names both third-party actions', () => {+ const extension = GUIDE.find((section) => section.id === 'extension');+ const copy = extension.points.map((point) => `${point.label} ${point.text}`).join(' ');+ expect(copy).toContain('Chromium');+ expect(copy).toContain('Firefox');+ expect(copy).toContain('reverse-search engine');+ expect(copy).not.toContain('exactly one place');+ });+it('reaches a section from a tool, which is how a toolbar mark will ask', () => {expect(guideFor('satellite')?.id).toBe('map');expect(guideFor('graph')?.id).toBe('case');diff --git a/frontend/src/lib/map/basemap.js b/frontend/src/lib/map/basemap.jsindex 09dd4bb..ffd1e17 100644--- a/frontend/src/lib/map/basemap.js+++ b/frontend/src/lib/map/basemap.js@@ -131,9 +131,11 @@ const OVERLAYS = [layer: 'basemap-firms',url: (params) => `/api/firms/tiles/{z}/{x}/{y}?${new URLSearchParams(params)}`,attribution: 'Active fire data: NASA FIRMS',- // FIRMS draws a fixed symbol per detection and VIIRS resolves 375 m: deeper- // than this is a screen of overlapping marks, and the route refuses it.+ // The source stops at z14. Past it, MapLibre enlarges those pixels instead+ // of requesting invented detail, so a detection remains a visible square.maxZoom: 14,+ viewMaxZoom: 24,+ resampling: 'nearest',},];@@ -376,6 +378,9 @@ export function createBasemaps(engine, hooks = {}) {}return;}+ const paint = {};+ if (overlay.opacity != null) paint['raster-opacity'] = overlay.opacity;+ if (overlay.resampling) paint['raster-resampling'] = overlay.resampling;map.addLayer({id: overlay.layer,@@ -389,7 +394,7 @@ export function createBasemaps(engine, hooks = {}) {// A picture whose coarse pixels are still worth reading zoomed in// states a deeper view of its own.maxzoom: overlay.viewMaxZoom ?? overlay.maxZoom,- ...(overlay.opacity != null ? { paint: { 'raster-opacity': overlay.opacity } } : {}),+ ...(Object.keys(paint).length ? { paint } : {}),},before);diff --git a/frontend/src/lib/map/basemap.test.js b/frontend/src/lib/map/basemap.test.jsindex 4ca6048..e201bfe 100644--- a/frontend/src/lib/map/basemap.test.js+++ b/frontend/src/lib/map/basemap.test.js@@ -343,6 +343,21 @@ describe('the layers on a map', () => {});});+ it('keeps FIRMS detections as visible squares beyond the last source zoom', async () => {+ await withStubbedGoogle(async ({ createBasemaps }) => {+ const map = stubMap();+ createBasemaps(stubEngine(map)).setOverlay('firms', true, {+ sensor: 'viirs',+ window: '24h',+ });+ expect(map.sources.get('basemap-firms').maxzoom).toBe(14);+ expect(map.getLayer('basemap-firms')).toMatchObject({+ maxzoom: 24,+ paint: { 'raster-resampling': 'nearest' },+ });+ });+ });+it('adds an overlay once and takes it off when asked', async () => {await withStubbedGoogle(async ({ createBasemaps }) => {const map = stubMap();diff --git a/frontend/src/lib/state.svelte.js b/frontend/src/lib/state.svelte.jsindex 9ed83a2..f80bf85 100644--- a/frontend/src/lib/state.svelte.js+++ b/frontend/src/lib/state.svelte.js@@ -408,7 +408,7 @@ export async function openCase(id) {* Startup: load the case list and reopen the last-used case (if it still* exists on disk). Called once from App on mount.*/-export async function initSession() {+export async function initSession(explicitCaseId = null) {// preferences must land before the tools render, or coordinates would flash// in the wrong format; a settings read failure is never fatal to a sessionawait loadPrefs().catch(() => {});@@ -418,6 +418,13 @@ export async function initSession() {// renders a type slug it would replace a moment later.await loadRelationTypes().catch(() => {});await refreshCaseList();+ const requested = typeof explicitCaseId === 'string' ? explicitCaseId.trim() : '';+ if (requested) {+ // A detached map names its owner in the URL. Falling back to shared+ // localStorage here could make the copied view write into another tab's case.+ await openCase(requested);+ return;+ }let lastId = null;try {lastId = localStorage.getItem(LAST_CASE_KEY);diff --git a/frontend/src/lib/state.test.js b/frontend/src/lib/state.test.jsindex 8bebf0c..59c3c13 100644--- a/frontend/src/lib/state.test.js+++ b/frontend/src/lib/state.test.js@@ -403,4 +403,34 @@ describe('case request ownership', () => {expect(state.caseState.current).toEqual({ id: 'case-a', name: 'Newest' });expect(state.caseState.rev).toBe(1);});++ it('opens an explicitly named detached-map case instead of the shared last case', async () => {+ localStorage.setItem('azimut:lastCase', 'case-b');+ api.get.mockImplementation(async (path) => {+ if (path === '/api/cases/case-a') return { id: 'case-a', name: 'Case A' };+ if (path === '/api/cases') return [];+ if (path === '/api/workspace/folders') return [];+ return {};+ });++ await state.initSession('case-a');++ expect(state.caseState.current?.id).toBe('case-a');+ expect(api.get).not.toHaveBeenCalledWith('/api/cases/case-b');+ });++ it('does not replace a missing explicit case with the shared last case', async () => {+ localStorage.setItem('azimut:lastCase', 'case-b');+ api.get.mockImplementation(async (path) => {+ if (path === '/api/cases/missing') throw new Error('case not found');+ if (path === '/api/cases') return [];+ if (path === '/api/workspace/folders') return [];+ return {};+ });++ await expect(state.initSession('missing')).rejects.toThrow('case not found');++ expect(state.caseState.current).toBeNull();+ expect(api.get).not.toHaveBeenCalledWith('/api/cases/case-b');+ });});diff --git a/frontend/src/tools/Satellite.svelte b/frontend/src/tools/Satellite.svelteindex d42d5e3..aea4ab1 100644--- a/frontend/src/tools/Satellite.svelte+++ b/frontend/src/tools/Satellite.svelte@@ -410,7 +410,9 @@notify: toast,caseId: () => caseState.current?.id,engine: () => engine,- onSaved: reloadCase,+ onSaved: async (ownerCaseId) => {+ if (caseState.current?.id === ownerCaseId) await reloadCase();+ },});// Svelte only honours a cleanup returned from a *synchronous* onMount, and the@@ -779,6 +781,7 @@});params.w = String(nextWindowNumber());params.solo = '1';+ if (caseState.current?.id) params.case = caseState.current.id;const url = `${location.pathname}${location.search}${buildHash('satellite', params)}`;const opened = window.open(url, '_blank');if (!opened) toast('The browser refused a second tab. Allow pop-ups for this page', 'warn', 8000);@@ -1222,6 +1225,7 @@temporalMapError = '';// The points came out of another case's sheet, so they go with it.sheetPoints = null;+ footprint.cancel();}return savedWork.load(id);});diff --git a/frontend/src/tools/Satellite.test.js b/frontend/src/tools/Satellite.test.jsindex e95ae50..9265cd4 100644--- a/frontend/src/tools/Satellite.test.js+++ b/frontend/src/tools/Satellite.test.js@@ -625,6 +625,7 @@ describe('a map in more than one window', () => {// back, and it is what a browser does not refuseexpect(source).toContain("window.open(url, '_blank')");expect(source).toContain('params.w = String(nextWindowNumber())');+ expect(source).toContain('params.case = caseState.current.id');expect(source).toContain('The browser refused a second tab');});diff --git a/frontend/src/tools/satellite/state/footprint.svelte.js b/frontend/src/tools/satellite/state/footprint.svelte.jsindex 90bb266..a7b4428 100644--- a/frontend/src/tools/satellite/state/footprint.svelte.js+++ b/frontend/src/tools/satellite/state/footprint.svelte.js@@ -24,8 +24,8 @@* @param {(message: string, kind?: string, ms?: number) => void} deps.notify* @param {() => string|undefined} deps.caseId the case the place belongs to* @param {() => object|null} deps.engine the map, through the façade- * @param {() => Promise<any>} deps.onSaved re-read the saved index, so the- * traced shape appears under its pin+ * @param {(caseId: string) => Promise<any>} deps.onSaved re-read the owning+ * case's saved index, so the traced shape appears under its pin* @param {(engine: object) => object} [deps.surface] the drawing layer factory*/import { createSurface } from '../../../lib/map/surface.js';@@ -54,12 +54,13 @@ export function createFootprintState({onSaved,surface = createSurface,}) {- /** The place being traced: `{ id, title, footprint, radius_m, at }`, or null- * when off. `at` is the pin itself, which the shape has to contain. */+ /** The place being traced, including its owning case, or null when off.+ * `at` is the pin itself, which the shape has to contain. */let place = $state(null);let points = $state([]);let saving = $state(false);let layer = null;+ let operation = 0;function draw() {const map = engine();@@ -76,6 +77,8 @@ export function createFootprintState({}function stop() {+ operation += 1;+ saving = false;place = null;points = [];layer?.clear();@@ -113,7 +116,8 @@ export function createFootprintState({/** Begin on a place. Starting again on another one drops the first draft. */start(row) {- if (!row?.id) return false;+ const ownerCaseId = caseId();+ if (!row?.id || !ownerCaseId) return false;stop();// `null` is a point the place does not have, and it numbers as 0 — which would// put every untraced place in the Gulf of Guinea and refuse every shape drawn.@@ -122,6 +126,7 @@ export function createFootprintState({const at = Number.isFinite(lat) && Number.isFinite(lon) ? { lat, lon } : null;place = {id: row.id,+ caseId: ownerCaseId,title: row.title || 'this place',footprint: row.footprint || null,radius_m: Number(row.radius_m) > 0 ? Number(row.radius_m) : null,@@ -150,12 +155,13 @@ export function createFootprintState({async save() {const shape = polygonOf(points);- const cid = caseId();- if (!shape || !place || !cid || saving) return;+ const target = place;+ if (!shape || !target || saving) return;if (!covers()) {notify('The shape has to contain the place it belongs to', 'warn', 4000);return;}+ const run = ++operation;saving = true;try {// attrs merge server-side, so this writes the footprint and leaves@@ -163,16 +169,20 @@ export function createFootprintState({// radius, which the shape replaces: the map draws one of the two, and a// circle that survived a tracing it can no longer be seen behind is a// precision nobody can read.- await api.patch(`/api/cases/${cid}/entities/${place.id}`, {+ await api.patch(`/api/cases/${target.caseId}/entities/${target.id}`, {attrs: { footprint: shape, radius_m: null },});- stop();- await onSaved?.();+ if (run !== operation || place !== target) return;+ await onSaved?.(target.caseId);+ if (run !== operation || place !== target) return;notify('Footprint saved', 'ok', 2000);+ stop();} catch (e) {- notify(`Could not save the footprint: ${e.message}`, 'danger', 6000);+ if (run === operation && place === target) {+ notify(`Could not save the footprint: ${e.message}`, 'danger', 6000);+ }} finally {- saving = false;+ if (run === operation) saving = false;}},diff --git a/frontend/src/tools/satellite/state/footprint.svelte.test.js b/frontend/src/tools/satellite/state/footprint.svelte.test.jsindex 47f196e..3f769eb 100644--- a/frontend/src/tools/satellite/state/footprint.svelte.test.js+++ b/frontend/src/tools/satellite/state/footprint.svelte.test.js@@ -17,18 +17,25 @@ const A = { lat: 0, lon: 0 };const B = { lat: 0, lon: 1 };const C = { lat: 1, lon: 1 };+function deferred() {+ let resolve;+ const promise = new Promise((done) => (resolve = done));+ return { promise, resolve };+}+let api;let notify;let layer;let surface;let engine;let saved;+let currentCase;function store() {return createFootprintState({api,notify,- caseId: () => 'case-1',+ caseId: () => currentCase,engine: () => engine,onSaved: saved,surface,@@ -42,6 +49,7 @@ beforeEach(() => {surface = vi.fn(() => layer);engine = { id: 'map' };saved = vi.fn(async () => {});+ currentCase = 'case-1';});describe('a ring as GeoJSON', () => {@@ -181,4 +189,33 @@ describe('what gets written', () => {expect(trace.points).toHaveLength(3);expect(trace.on).toBe(true);});++ it('keeps the case that owned the draft when another case becomes current', async () => {+ const trace = store();+ trace.start(PLACE);+ for (const point of [A, B, C]) trace.addPoint(point);+ currentCase = 'case-2';++ await trace.save();++ expect(api.patch.mock.calls[0][0]).toBe('/api/cases/case-1/entities/e1');+ expect(saved).toHaveBeenCalledWith('case-1');+ });++ it('does not let an old save clear or announce a newer draft', async () => {+ const pending = deferred();+ api.patch = vi.fn(() => pending.promise);+ const trace = store();+ trace.start(PLACE);+ for (const point of [A, B, C]) trace.addPoint(point);+ const oldSave = trace.save();++ trace.start({ ...PLACE, id: 'e2', title: 'Treeline' });+ pending.resolve({});+ await oldSave;++ expect(trace.place.id).toBe('e2');+ expect(saved).not.toHaveBeenCalled();+ expect(notify).not.toHaveBeenCalledWith('Footprint saved', expect.anything(), expect.anything());+ });});diff --git a/scripts/sign_extension.py b/scripts/sign_extension.pyindex 25bb89a..5e993b0 100644--- a/scripts/sign_extension.py+++ b/scripts/sign_extension.py@@ -46,8 +46,9 @@ import shutilimport subprocessimport sysimport tempfile+import urllib.requestfrom pathlib import Path, PurePosixPath-from typing import Any+from typing import Any, CallableREPO = Path(__file__).resolve().parent.parentEXT = REPO / "extension"@@ -74,7 +75,7 @@ def gecko_facts() -> dict[str, str]:than kept in step by hand."""manifest = json.loads((EXT / "manifest.json").read_text(encoding="utf-8"))gecko = manifest.get("browser_specific_settings", {}).get("gecko", {})- missing = [key for key in ("id", "strict_min_version") if not gecko.get(key)]+ missing = [key for key in ("id", "strict_min_version", "update_url") if not gecko.get(key)]if missing or not manifest.get("version"):raise SystemExit(f"extension/manifest.json is missing {missing or ['version']} — an unlisted "@@ -84,6 +85,7 @@ def gecko_facts() -> dict[str, str]:"id": gecko["id"],"version": str(manifest["version"]),"strict_min_version": gecko["strict_min_version"],+ "update_url": gecko["update_url"],}@@ -141,6 +143,41 @@ def sha256_of(path: Path) -> str:return digest.hexdigest()+def _download(url: str, limit: int) -> bytes:+ with urllib.request.urlopen(url, timeout=30) as response:+ body = response.read(limit + 1)+ if len(body) > limit:+ raise SystemExit(f"delivery file is larger than the {limit}-byte verification limit")+ return body+++def verify_published_delivery(+ tag: str,+ fetch: Callable[[str, int], bytes] = _download,+) -> str:+ """Verify the public update manifest and the exact XPI bytes it offers.++ This is deliberately an explicit post-release check. Development may have+ an empty manifest before the first signature, but completed delivery may not.+ """+ facts = gecko_facts()+ try:+ manifest = json.loads(fetch(facts["update_url"], 1 << 20))+ updates = manifest["addons"][facts["id"]]["updates"]+ except (KeyError, TypeError, json.JSONDecodeError) as exc:+ raise SystemExit("the published Firefox update manifest is malformed") from exc+ if len(updates) != 1:+ raise SystemExit("the published Firefox update manifest must offer exactly one version")+ entry = updates[0]+ expected_url = asset_url(tag, facts["version"])+ if entry.get("version") != facts["version"] or entry.get("update_link") != expected_url:+ raise SystemExit("the published Firefox update does not match this extension and tag")+ expected_hash = f"sha256:{hashlib.sha256(fetch(expected_url, 64 << 20)).hexdigest()}"+ if entry.get("update_hash") != expected_hash:+ raise SystemExit("the published Firefox XPI does not match its update hash")+ return expected_url++# ---- signing ----------------------------------------------------------------@@ -166,6 +203,12 @@ def sign(staging: Path, artifacts: Path) -> Path:secret = os.environ.get("AMO_JWT_SECRET")if not issuer or not secret:raise SystemExit("set AMO_JWT_ISSUER and AMO_JWT_SECRET (AMO developer hub)")+ signer_env = os.environ.copy()+ # web-ext supports private authentication through these environment names.+ # Keeping the values out of argv prevents process listings and command errors+ # from exposing them.+ signer_env["WEB_EXT_API_KEY"] = issuer+ signer_env["WEB_EXT_API_SECRET"] = secretsubprocess.run(["npx",@@ -178,12 +221,9 @@ def sign(staging: Path, artifacts: Path) -> Path:str(artifacts),"--channel","unlisted",- "--api-key",- issuer,- "--api-secret",- secret,],check=True,+ env=signer_env,)signed = sorted(artifacts.glob("*.xpi"))if not signed:@@ -213,9 +253,18 @@ def main(argv: list[str] | None = None) -> int:default=REPO / "dist-xpi",help="where the signed XPI is written (default: dist-xpi/)",)+ parser.add_argument(+ "--verify-release",+ action="store_true",+ help="verify the public update manifest and signed XPI, without signing",+ )options = parser.parse_args(argv)version = facts["version"]+ if options.verify_release:+ link = verify_published_delivery(options.tag)+ print(f"Firefox delivery verified: {link}")+ return 0if options.from_xpi is None and published_version() == version:raise SystemExit(f"packaging/updates.json already offers {version}. AMO refuses a version it "diff --git a/src/azimut/api/cases/entities.py b/src/azimut/api/cases/entities.pyindex b7d08ef..4fb9a73 100644--- a/src/azimut/api/cases/entities.py+++ b/src/azimut/api/cases/entities.py@@ -17,7 +17,9 @@ from ...engine import satellite as satellite_enginefrom ...engine import tally as tally_enginefrom ...repository import EntityStatusfrom ...workspace import CaseError+from .. import eventsfrom .common import (+ MAPPED_TYPES,_check_attrs,_summary,delete_entities_deep,@@ -98,18 +100,21 @@ def add_entity(case_id: str, body: EntityIn) -> dict[str, Any]:str(attrs.get("folder", "")).strip(),str(attrs.get("content", "")),)- return case.add_entity(body.type, body.label, body.attrs, by="user", status=body.status)+ entity = case.add_entity(body.type, body.label, body.attrs, by="user", status=body.status)+ if body.type in MAPPED_TYPES:+ events.publish({"type": "saved", "case_id": case.id})+ return entity@router.patch("/{case_id}/entities/{entity_id}")def update_entity(case_id: str, entity_id: str, body: EntityPatch) -> dict[str, Any]:case = get_case(case_id)+ current = case.get_entity(entity_id)+ if current is None:+ raise HTTPException(status_code=404, detail=f"entity '{entity_id}' not found")patch = {k: v for k, v in body.model_dump().items() if v is not None}if body.attrs is not None:# Against the type it will have once patched, and the entity has to exist# before its fields can be judged.- current = case.get_entity(entity_id)- if current is None:- raise HTTPException(status_code=404, detail=f"entity '{entity_id}' not found")_check_attrs(body.type or str(current["type"]),body.attrs,@@ -119,6 +124,8 @@ def update_entity(case_id: str, entity_id: str, body: EntityPatch) -> dict[str,entity = case.update_entity(entity_id, patch)if body.status == "confirmed":link_engine.confirm_incident_relations(case, entity_id)+ if current.get("type") in MAPPED_TYPES or entity.get("type") in MAPPED_TYPES:+ events.publish({"type": "saved", "case_id": case.id})return entityexcept CaseError as exc:raise HTTPException(status_code=404, detail=str(exc)) from excdiff --git a/src/azimut/api/satellite.py b/src/azimut/api/satellite.pyindex 52334ae..8b3fec1 100644--- a/src/azimut/api/satellite.py+++ b/src/azimut/api/satellite.py@@ -577,17 +577,17 @@ def firms_tile(Never cached to disk: the live layers are what is burning now, refreshedupstream every fifteen minutes, and a cached fire is a lie with a timestamp."""- key = firms_key()- if not key:- raise HTTPException(status_code=404, detail="no FIRMS key saved")- if firms.too_deep(z):+ if z < 0 or firms.too_deep(z):raise HTTPException(status_code=422,- detail=f"FIRMS detections are drawn to z{firms.MAX_ZOOM}; deeper is one mark per pixel",+ detail=f"FIRMS source tiles use zooms 0 through {firms.MAX_ZOOM}",)grid = 1 << z- if z < 0 or not (0 <= x < grid) or not (0 <= y < grid):+ if not (0 <= x < grid) or not (0 <= y < grid):raise HTTPException(status_code=422, detail="tile coordinates out of range")+ key = firms_key()+ if not key:+ raise HTTPException(status_code=404, detail="no FIRMS key saved")try:url = firms.tile_url(key, sensor_id=sensor, window=window, z=z, x=x, y=y, first=first, last=last@@ -1362,40 +1362,42 @@ def apply_grid_marks(case, name: str, marks: dict[str, Any]) -> dict[str, Any]:marking the same cell twice would expect anyway."""spec_path = case.resolve_inside(layout.grid_rel(slugify(name, "grid")))- if not spec_path.exists():- raise HTTPException(status_code=404, detail="grid not found")- try:- spec = _read_grid(spec_path)- except ValueError as exc:- raise HTTPException(status_code=422, detail=f"corrupt grid: {exc}") from exc-- revision = _revision(spec)- statuses = dict(spec.get("statuses") or {})- for key, value in marks.items():- if value is None:- statuses.pop(str(key), None)- elif value in GRID_STATUSES:- statuses[str(key)] = value- else:- raise HTTPException(status_code=400, detail=f"unknown mark: {value!r}")- if len(statuses) > GRID_MAX_STATUSES:- raise HTTPException(status_code=400, detail="grid has too many cells")-- spec["statuses"] = statuses- spec["updated_at"] = _now()- # a patch moves the file on too, so a whole-spec save built before it is- # recognised as behind rather than written over the top- spec["revision"] = revision + 1- _write_grid_atomic(spec_path, spec)- # The other surfaces working this sweep re-read it off this. The revision- # rides along because the one that sent these marks hears the nudge too, and- # a revision it is already holding is how it knows to stay put.- events.publish({- "type": "grid-marks",- "case_id": case.id,- "name": spec_path.stem,- "revision": spec["revision"],- })+ # Atomic replacement protects the JSON bytes. The case lock protects the+ # read/merge/write transaction shared by app tabs and the extension.+ with case.lock:+ if not spec_path.exists():+ raise HTTPException(status_code=404, detail="grid not found")+ try:+ spec = _read_grid(spec_path)+ except ValueError as exc:+ raise HTTPException(status_code=422, detail=f"corrupt grid: {exc}") from exc++ revision = _revision(spec)+ statuses = dict(spec.get("statuses") or {})+ for key, value in marks.items():+ if value is None:+ statuses.pop(str(key), None)+ elif value in GRID_STATUSES:+ statuses[str(key)] = value+ else:+ raise HTTPException(status_code=400, detail=f"unknown mark: {value!r}")+ if len(statuses) > GRID_MAX_STATUSES:+ raise HTTPException(status_code=400, detail="grid has too many cells")++ spec["statuses"] = statuses+ spec["updated_at"] = _now()+ # a patch moves the file on too, so a whole-spec save built before it is+ # recognised as behind rather than written over the top+ spec["revision"] = revision + 1+ _write_grid_atomic(spec_path, spec)+ # Publish under the same lock so a later save/delete cannot announce+ # itself before this earlier mutation.+ events.publish({+ "type": "grid-marks",+ "case_id": case.id,+ "name": spec_path.stem,+ "revision": spec["revision"],+ })return {"name": spec_path.stem,"updated_at": spec["updated_at"],@@ -1502,26 +1504,27 @@ def save_search_grid(case_id: str, name: str, body: GridSaveIn) -> dict[str, Anyexcept ValueError as exc:raise HTTPException(status_code=422, detail=str(exc)) from excspec_path = case.resolve_inside(layout.grid_rel(slug))- on_disk = 0- if spec_path.exists():- try:- on_disk = _revision(_read_grid(spec_path))- except ValueError:- on_disk = 0 # unreadable: the save is the repair, let it through- if body.base_revision is not None and body.base_revision != on_disk:- raise HTTPException(- status_code=409,- detail="this grid changed elsewhere since this copy of it was built",- )- spec["revision"] = on_disk + 1- _write_grid_atomic(spec_path, spec)- events.publish({- "type": "grid",- "case_id": case.id,- "name": slug,- "title": spec["title"],- "revision": spec["revision"],- })+ with case.lock:+ on_disk = 0+ if spec_path.exists():+ try:+ on_disk = _revision(_read_grid(spec_path))+ except ValueError:+ on_disk = 0 # unreadable: the save is the repair, let it through+ if body.base_revision is not None and body.base_revision != on_disk:+ raise HTTPException(+ status_code=409,+ detail="this grid changed elsewhere since this copy of it was built",+ )+ spec["revision"] = on_disk + 1+ _write_grid_atomic(spec_path, spec)+ events.publish({+ "type": "grid",+ "case_id": case.id,+ "name": slug,+ "title": spec["title"],+ "revision": spec["revision"],+ })return {"name": slug,"title": spec["title"],@@ -1543,9 +1546,10 @@ def delete_search_grid(case_id: str, name: str) -> dict[str, Any]:spec_path = case.resolve_inside(layout.grid_rel(slugify(name, "grid")))except CaseError as exc:raise HTTPException(status_code=403, detail=str(exc)) from exc- existed = spec_path.exists()- spec_path.unlink(missing_ok=True)- if existed:- # a panel holding this sweep open is drawing a file that is gone- events.publish({"type": "grid-removed", "case_id": case.id, "name": spec_path.stem})+ with case.lock:+ existed = spec_path.exists()+ spec_path.unlink(missing_ok=True)+ if existed:+ # a panel holding this sweep open is drawing a file that is gone+ events.publish({"type": "grid-removed", "case_id": case.id, "name": spec_path.stem})return {"deleted": existed}diff --git a/src/azimut/engine/entities.py b/src/azimut/engine/entities.pyindex 6caec9d..59d0e17 100644--- a/src/azimut/engine/entities.py+++ b/src/azimut/engine/entities.py@@ -886,40 +886,58 @@ def _check_geojson(attr: Attr, value: Any) -> None:lines are refused because a footprint is an area — a point is what `lat`/`lon`with a radius already says."""- if not isinstance(value, dict):- raise CaseError(f"'{attr.key}' must be a GeoJSON geometry")- if value.get("type") not in ("Polygon", "MultiPolygon"):- raise CaseError(f"'{attr.key}' must be a Polygon or MultiPolygon")- rings = value.get("coordinates")- if not isinstance(rings, list) or not rings:+ polygons, points = _footprint_polygons(value, attr.key)+ if not polygons:raise CaseError(f"'{attr.key}' has no coordinates")- points = _count_positions(rings, attr.key)- if points < 3:- raise CaseError(f"'{attr.key}' needs at least three points to be an area")if points > MAX_FOOTPRINT_POINTS:raise CaseError(f"'{attr.key}' holds more than {MAX_FOOTPRINT_POINTS} points")-def _count_positions(node: Any, key: str, depth: int = 0) -> int:- """Count `[lon, lat]` pairs, checking each as it goes.+def _footprint_polygons(value: Any, key: str) -> tuple[list[list[list[Any]]], int]:+ """Return validated Polygon rings and their position count.- Recursive because a Polygon nests one level deeper than a MultiPolygon's rings,- and bounded by ``depth`` so a hand-made payload cannot nest its way past the- point cap.+ Ring structure is checked here rather than inferred recursively. Containment+ can then rely on every polygon having one closed outer ring followed by zero+ or more closed holes."""- if depth > 4:- raise CaseError(f"'{key}' is nested too deeply")- if not isinstance(node, list):- raise CaseError(f"'{key}' has a malformed coordinate")- # a position is the innermost list: two numbers, lon then lat- if node and all(isinstance(v, (int, float)) and not isinstance(v, bool) for v in node):- if len(node) < 2:- raise CaseError(f"'{key}' has a coordinate that is not a lon/lat pair")- lon, lat = float(node[0]), float(node[1])- if not (-180 <= lon <= 180 and -90 <= lat <= 90):- raise CaseError(f"'{key}' has a coordinate off the globe")- return 1- return sum(_count_positions(child, key, depth + 1) for child in node)+ if not isinstance(value, dict):+ raise CaseError(f"'{key}' must be a GeoJSON geometry")+ kind = value.get("type")+ if kind not in ("Polygon", "MultiPolygon"):+ raise CaseError(f"'{key}' must be a Polygon or MultiPolygon")+ coordinates = value.get("coordinates")+ if not isinstance(coordinates, list) or not coordinates:+ raise CaseError(f"'{key}' has no coordinates")+ polygons = [coordinates] if kind == "Polygon" else coordinates+ points = 0+ for polygon in polygons:+ if not isinstance(polygon, list) or not polygon:+ raise CaseError(f"'{key}' has a polygon with no rings")+ for ring in polygon:+ if not isinstance(ring, list) or len(ring) < 4:+ raise CaseError(f"'{key}' has a ring with fewer than four positions")+ checked: list[tuple[float, float]] = []+ for position in ring:+ if not isinstance(position, list) or len(position) < 2:+ raise CaseError(f"'{key}' has a coordinate that is not a lon/lat pair")+ lon, lat = position[0], position[1]+ if (+ isinstance(lon, bool)+ or isinstance(lat, bool)+ or not isinstance(lon, (int, float))+ or not isinstance(lat, (int, float))+ or not math.isfinite(float(lon))+ or not math.isfinite(float(lat))+ ):+ raise CaseError(f"'{key}' has a malformed coordinate")+ lon_value, lat_value = float(lon), float(lat)+ if not (-180 <= lon_value <= 180 and -90 <= lat_value <= 90):+ raise CaseError(f"'{key}' has a coordinate off the globe")+ checked.append((lon_value, lat_value))+ if checked[0] != checked[-1]:+ raise CaseError(f"'{key}' has an unclosed ring")+ points += len(checked)+ return polygons, pointsdef _check_place_precision(attrs: Mapping[str, Any], current: Mapping[str, Any]) -> None:@@ -941,47 +959,64 @@ def _check_place_precision(attrs: Mapping[str, Any], current: Mapping[str, Any])"""radius = attrs.get("radius_m", current.get("radius_m"))shape = attrs.get("footprint", current.get("footprint"))- touched = any(+ precision_touched = any(key in attrs and attrs[key] != current.get(key) for key in ("radius_m", "footprint"))- if radius and shape and touched:+ if radius and shape and precision_touched:raise CaseError("a place holds either a radius or a footprint, not both")- if not attrs.get("footprint"):+ containment_touched = any(+ key in attrs and attrs[key] != current.get(key)+ for key in ("lat", "lon", "footprint")+ )+ if not containment_touched or not shape:returnlat = attrs.get("lat", current.get("lat"))lon = attrs.get("lon", current.get("lon"))if not isinstance(lat, (int, float)) or not isinstance(lon, (int, float)):return # a place with no point of its own has nothing to contradict- if not _covers_point(attrs["footprint"], float(lat), float(lon)):+ if not _covers_point(shape, float(lat), float(lon)):raise CaseError("'footprint' must contain the place's own point")def _covers_point(shape: Mapping[str, Any], lat: float, lon: float) -> bool:- """Is the point inside one of this shape's outer rings?+ """Is the point covered by one polygon, excluding the interiors of holes?Ray casting, on shapes this module has already validated. `engine.sentinel` ownsa second copy on purpose: a granule's geometry arrives from a service that mayhave swapped the axes, so that one counts either reading as a hit, and here thattolerance would accept a shape traced at the mirrored coordinates."""- rings: list[Any] = []- coordinates = shape.get("coordinates") or []- if shape.get("type") == "Polygon":- rings = [coordinates[0]] if coordinates else []- else:- rings = [polygon[0] for polygon in coordinates if polygon]- return any(_inside(ring, lat, lon) for ring in rings)+ polygons, _ = _footprint_polygons(shape, "footprint")+ for polygon in polygons:+ outer = _ring_location(polygon[0], lat, lon)+ if outer == "outside":+ continue+ if outer == "boundary":+ return True+ if any(_ring_location(hole, lat, lon) == "inside" for hole in polygon[1:]):+ continue+ # A hole boundary belongs to the polygon boundary under GeoJSON's covers+ # convention, so only a point strictly inside a hole is excluded.+ return True+ return False-def _inside(ring: list[Any], lat: float, lon: float) -> bool:+def _ring_location(ring: list[Any], lat: float, lon: float) -> str:inside = False- for index, position in enumerate(ring):+ for index, position in enumerate(ring[:-1]):x1, y1 = float(position[0]), float(position[1])- following = ring[(index + 1) % len(ring)]+ following = ring[index + 1]x2, y2 = float(following[0]), float(following[1])+ cross = (lon - x1) * (y2 - y1) - (lat - y1) * (x2 - x1)+ if (+ abs(cross) <= 1e-10+ and min(x1, x2) - 1e-10 <= lon <= max(x1, x2) + 1e-10+ and min(y1, y2) - 1e-10 <= lat <= max(y1, y2) + 1e-10+ ):+ return "boundary"if (y1 > lat) != (y2 > lat) and lon < (x2 - x1) * (lat - y1) / ((y2 - y1) or 1e-12) + x1:inside = not inside- return inside+ return "inside" if inside else "outside"def _check_choice(attr: Attr, value: Any) -> None:diff --git a/tests/test_events_api.py b/tests/test_events_api.pyindex 78ccba8..f6f8c0f 100644--- a/tests/test_events_api.py+++ b/tests/test_events_api.py@@ -284,6 +284,25 @@ def test_saving_a_point_in_the_app_nudges_the_panels(client):events.unsubscribe(q)+def test_generic_place_creation_and_edits_nudge_other_maps(client):+ cid = client.post("/api/cases", json={"name": "Generic points"}).json()["id"]+ q = events.subscribe()+ try:+ place = client.post(+ f"/api/cases/{cid}/entities",+ json={"type": "place", "label": "Quay", "attrs": {"lat": 48.85, "lon": 2.29}},+ ).json()+ assert q.get_nowait() == {"type": "saved", "case_id": cid}++ client.patch(+ f"/api/cases/{cid}/entities/{place['id']}",+ json={"label": "North quay"},+ )+ assert q.get_nowait() == {"type": "saved", "case_id": cid}+ finally:+ events.unsubscribe(q)++def test_deleting_a_point_nudges_the_panels(client):cid = client.post("/api/cases", json={"name": "Points"}).json()["id"]entity = client.post(diff --git a/tests/test_extension_signing.py b/tests/test_extension_signing.pyindex 091c1ac..fed391a 100644--- a/tests/test_extension_signing.py+++ b/tests/test_extension_signing.py@@ -10,7 +10,9 @@ error anywhere, it just silently never updates.from __future__ import annotations+import hashlibimport json+import subprocessimport sysfrom pathlib import Path@@ -109,6 +111,7 @@ def test_the_generator_reads_the_extension_rather_than_a_copy(gecko):assert facts["id"] == gecko["id"]assert facts["version"] == extinstall.bundled_version()assert facts["strict_min_version"] == gecko["strict_min_version"]+ assert facts["update_url"] == gecko["update_url"]def test_the_asset_url_names_the_release_that_carries_it():@@ -161,3 +164,84 @@ def test_no_published_version_before_the_first_signature(monkeypatch, tmp_path):manifest.write_text(json.dumps({"addons": {"x@y": {"updates": []}}}), encoding="utf-8")monkeypatch.setattr(sign_extension, "UPDATE_MANIFEST", manifest)assert sign_extension.published_version() is None+++def test_signing_credentials_are_passed_in_the_private_environment(monkeypatch, tmp_path):+ captured = {}+ monkeypatch.setenv("AMO_JWT_ISSUER", "synthetic-issuer")+ monkeypatch.setenv("AMO_JWT_SECRET", "synthetic-secret")++ def fake_run(argv, **kwargs):+ captured.update(argv=argv, kwargs=kwargs)+ (tmp_path / "signed.xpi").write_bytes(b"signed")++ monkeypatch.setattr(sign_extension.subprocess, "run", fake_run)+ signed = sign_extension.sign(tmp_path / "payload", tmp_path)++ assert signed.name == "signed.xpi"+ command = " ".join(captured["argv"])+ assert "synthetic-issuer" not in command+ assert "synthetic-secret" not in command+ assert "--api-key" not in captured["argv"]+ assert "--api-secret" not in captured["argv"]+ assert captured["kwargs"]["env"]["WEB_EXT_API_KEY"] == "synthetic-issuer"+ assert captured["kwargs"]["env"]["WEB_EXT_API_SECRET"] == "synthetic-secret"+++def test_a_signer_failure_cannot_serialize_the_secret(monkeypatch, tmp_path):+ monkeypatch.setenv("AMO_JWT_ISSUER", "synthetic-issuer")+ monkeypatch.setenv("AMO_JWT_SECRET", "synthetic-secret")++ def fail(argv, **kwargs):+ raise subprocess.CalledProcessError(2, argv, stderr="validation failed")++ monkeypatch.setattr(sign_extension.subprocess, "run", fail)+ with pytest.raises(subprocess.CalledProcessError) as error:+ sign_extension.sign(tmp_path / "payload", tmp_path)++ assert "synthetic-issuer" not in str(error.value)+ assert "synthetic-secret" not in str(error.value)+++def test_completed_delivery_cannot_pass_with_an_empty_update_list(monkeypatch, gecko):+ empty = json.dumps({"addons": {gecko["id"]: {"updates": []}}}).encode()+ monkeypatch.setattr(+ sign_extension,+ "gecko_facts",+ lambda: {+ "id": gecko["id"],+ "version": "0.3.0",+ "strict_min_version": gecko["strict_min_version"],+ "update_url": UPDATE_URL,+ },+ )++ with pytest.raises(SystemExit, match="exactly one version"):+ sign_extension.verify_published_delivery("v0.3.0", lambda _url, _limit: empty)+++def test_completed_delivery_verifies_the_public_xpi_hash(monkeypatch, gecko):+ xpi = b"mozilla-signed-xpi"+ link = sign_extension.asset_url("v0.3.0", "0.3.0")+ published = sign_extension.build_update_manifest(+ gecko["id"],+ "0.3.0",+ link,+ hashlib.sha256(xpi).hexdigest(),+ gecko["strict_min_version"],+ )+ monkeypatch.setattr(+ sign_extension,+ "gecko_facts",+ lambda: {+ "id": gecko["id"],+ "version": "0.3.0",+ "strict_min_version": gecko["strict_min_version"],+ "update_url": UPDATE_URL,+ },+ )++ def fetch(url, _limit):+ return json.dumps(published).encode() if url == UPDATE_URL else xpi++ assert sign_extension.verify_published_delivery("v0.3.0", fetch) == linkdiff --git a/tests/test_firms.py b/tests/test_firms.pyindex a8b1c00..74fc20b 100644--- a/tests/test_firms.py+++ b/tests/test_firms.py@@ -181,6 +181,15 @@ def test_a_tile_deeper_than_the_layer_draws_is_refused_with_a_reason(client):assert str(firms.MAX_ZOOM) in answer.json()["detail"][email protected]("path", ["/api/firms/tiles/-1/0/0", "/api/firms/tiles/3/8/0"])+def test_invalid_tile_coordinates_are_refused_before_key_lookup(client, monkeypatch, path):+ def never(*args, **kwargs):+ raise AssertionError("asked FIRMS for invalid tile coordinates")++ monkeypatch.setattr(httpx, "get", never)+ assert client.get(path).status_code == 422++def test_a_date_the_service_would_refuse_never_reaches_it(client, monkeypatch):client.put("/api/settings/keys", json={"firms": "KEY123"})diff --git a/tests/test_place_precision.py b/tests/test_place_precision.pyindex 878ab46..2105a06 100644--- a/tests/test_place_precision.py+++ b/tests/test_place_precision.py@@ -182,6 +182,9 @@ def test_a_footprint_is_refused_off_the_globe_or_malformed(client):assert post({"type": "Polygon", "coordinates": [[[200, 0], [1, 1], [2, 2], [200, 0]]]}) == 400assert post({"type": "Polygon", "coordinates": [[[0, 91], [1, 1], [2, 2], [0, 91]]]}) == 400assert post({"type": "Polygon", "coordinates": [[[0], [1, 1], [2, 2], [0]]]}) == 400+ assert post({"type": "Polygon", "coordinates": [[0, 0], [1, 0], [0, 1], [0, 0]]}) == 400+ assert post({"type": "Polygon", "coordinates": [[[0, 0], [1, 0], [0, 1], [1, 1]]]}) == 400+ assert post({"type": "MultiPolygon", "coordinates": [[]]}) == 400def test_a_footprint_is_bounded_in_size_and_depth(client):@@ -221,6 +224,45 @@ def test_a_multipolygon_counts_as_containing_the_point_in_any_of_its_parts(clienassert res.status_code == 200, res.text+def test_a_point_inside_a_footprint_hole_is_refused(client):+ cid = _new_case(client, "Point in a hole")+ hole = [+ [14.545, 53.435], [14.555, 53.435], [14.555, 53.445],+ [14.545, 53.445], [14.545, 53.435],+ ]++ res = _place(+ client,+ cid,+ footprint={"type": "Polygon", "coordinates": [AROUND, hole]},+ )++ assert res.status_code == 400+ assert "contain" in res.json()["detail"]+++def test_a_polygon_boundary_covers_its_place(client):+ cid = _new_case(client, "Point on boundary")+ res = _place(+ client,+ cid,+ lat=53.43,+ footprint={"type": "Polygon", "coordinates": [AROUND]},+ )+ assert res.status_code == 200, res.text+++def test_moving_a_place_must_stay_inside_its_retained_footprint(client):+ cid = _new_case(client, "Moved point")+ eid = _place(client, cid, footprint={"type": "Polygon", "coordinates": [AROUND]}).json()["id"]++ assert _patch(client, cid, eid, {"lat": 54.0}).status_code == 400+ assert _patch(client, cid, eid, {"lon": 15.0}).status_code == 400+ assert _patch(client, cid, eid, {"lat": 54.0, "lon": 15.0}).status_code == 400+ # Clearing the old shape in the same patch makes the move explicit.+ assert _patch(client, cid, eid, {"lat": 54.0, "lon": 15.0, "footprint": None}).status_code == 200++def test_a_place_with_no_point_of_its_own_still_takes_a_footprint(client):"""Nothing to contradict: a record promoted from a sheet can hold the shapewithout holding the pair, and refusing it would lose the only geometry it has."""diff --git a/tests/test_satellite_api.py b/tests/test_satellite_api.pyindex 5e89f6f..b41d9af 100644--- a/tests/test_satellite_api.py+++ b/tests/test_satellite_api.py@@ -1,6 +1,8 @@"""Satellite capture API: bearing is honored and persisted with provenance."""import io+from concurrent.futures import ThreadPoolExecutor+from threading import Event, Lockimport pytest@@ -755,6 +757,130 @@ def test_search_grid_write_is_atomic(client, monkeypatch):assert list(path.parent.glob(".g.json.*.tmp")) == []+def test_concurrent_grid_patches_preserve_both_marks(client, monkeypatch):+ from azimut.api import satellite+ from azimut.workspace import Case++ cid = client.post("/api/cases", json={"name": "Concurrent grid"}).json()["id"]+ client.put(f"/api/cases/{cid}/search-grids/g", json=_rect_grid())+ case = Case.open(cid)+ original_write = satellite._write_grid_atomic+ first_in_write = Event()+ second_started = Event()+ second_finished = Event()+ calls_lock = Lock()+ calls = 0++ def controlled_write(path, spec):+ nonlocal calls+ with calls_lock:+ position = calls+ calls += 1+ if position == 0:+ first_in_write.set()+ assert second_started.wait(2)+ second_finished.wait(0.2)+ original_write(path, spec)++ def second_patch():+ second_started.set()+ try:+ return satellite.apply_grid_marks(case, "g", {"0:1": "flagged"})+ finally:+ second_finished.set()++ monkeypatch.setattr(satellite, "_write_grid_atomic", controlled_write)+ with ThreadPoolExecutor(max_workers=2) as pool:+ first = pool.submit(satellite.apply_grid_marks, case, "g", {"0:0": "cleared"})+ assert first_in_write.wait(2)+ second = pool.submit(second_patch)+ first.result(timeout=3)+ second.result(timeout=3)++ stored = client.get(f"/api/cases/{cid}/search-grids/g").json()+ assert stored["statuses"] == {"0:0": "cleared", "0:1": "flagged"}+ assert stored["revision"] == 3+++def test_two_whole_grid_saves_cannot_accept_the_same_revision(client, monkeypatch):+ from azimut.api import satellite++ cid = client.post("/api/cases", json={"name": "Concurrent saves"}).json()["id"]+ client.put(f"/api/cases/{cid}/search-grids/g", json=_rect_grid())+ current = client.get(f"/api/cases/{cid}/search-grids/g").json()+ body = satellite.GridSaveIn(spec=current, base_revision=current["revision"])+ original_write = satellite._write_grid_atomic+ first_in_write = Event()+ second_started = Event()+ second_finished = Event()+ calls_lock = Lock()+ calls = 0++ def controlled_write(path, spec):+ nonlocal calls+ with calls_lock:+ position = calls+ calls += 1+ if position == 0:+ first_in_write.set()+ assert second_started.wait(2)+ second_finished.wait(0.2)+ original_write(path, spec)++ def second_save():+ second_started.set()+ try:+ return satellite.save_search_grid(cid, "g", body)+ finally:+ second_finished.set()++ monkeypatch.setattr(satellite, "_write_grid_atomic", controlled_write)+ with ThreadPoolExecutor(max_workers=2) as pool:+ first = pool.submit(satellite.save_search_grid, cid, "g", body)+ assert first_in_write.wait(2)+ second = pool.submit(second_save)+ first.result(timeout=3)+ with pytest.raises(satellite.HTTPException) as error:+ second.result(timeout=3)+ assert error.value.status_code == 409+++def test_delete_waits_for_an_inflight_grid_patch(client, monkeypatch):+ from azimut.api import satellite+ from azimut.workspace import Case++ cid = client.post("/api/cases", json={"name": "Delete race"}).json()["id"]+ client.put(f"/api/cases/{cid}/search-grids/g", json=_rect_grid())+ case = Case.open(cid)+ original_write = satellite._write_grid_atomic+ writer_entered = Event()+ delete_started = Event()+ delete_finished = Event()++ def controlled_write(path, spec):+ writer_entered.set()+ assert delete_started.wait(2)+ delete_finished.wait(0.2)+ original_write(path, spec)++ def delete():+ delete_started.set()+ try:+ return satellite.delete_search_grid(cid, "g")+ finally:+ delete_finished.set()++ monkeypatch.setattr(satellite, "_write_grid_atomic", controlled_write)+ with ThreadPoolExecutor(max_workers=2) as pool:+ patching = pool.submit(satellite.apply_grid_marks, case, "g", {"0:0": "cleared"})+ assert writer_entered.wait(2)+ deleting = pool.submit(delete)+ patching.result(timeout=3)+ assert deleting.result(timeout=3)["deleted"] is True++ assert client.get(f"/api/cases/{cid}/search-grids/g").status_code == 404++def test_search_grid_delete_one(client):cid = client.post("/api/cases", json={"name": "Grid"}).json()["id"]client.put(f"/api/cases/{cid}/search-grids/a", json=_rect_grid(title="A"))