feat: wire Nitro API to Go, real staffing plan and train proxy

- Replace mock Nitro routes with server-side proxies to the Go API
- /plan reads Go /api/staffing; local assumption edits are a labeled preview
- /simulate reads base and scenario staffing from Go instead of local multipliers
- Route train upload and scenario POST through Nitro with server-only credentials
- Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only
- Match Go's global-peak flat schedule and add a captured Go parity fixture
- Run the web runtime as numeric UID/GID 10001:10001
- Add make check, Gitea CI workflow and a proxy smoke script
This commit is contained in:
Noel Sabia committed 2026-11-14 06:13:00 +01:00
1 parent e8d141ca43
commit b33e6ff001
33 files changed
+1147 -317

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
import { readFileSync } from 'node:fs'
import { describe, expect, it } from 'vitest'
import { berlinParts, buildStaffing } from '../shared/staffing'
import type { StaffingResponse } from '../shared/types'
// Captured from the real Go API:
// curl 'http://localhost:8080/api/staffing?sensor=hn-stadtgalerie-01&scenario=base&standard=standard'
// with api-go.git/main/testdata/data as DATA_DIR.
const fixture = JSON.parse(
readFileSync(new URL('./fixtures/go-staffing.json', import.meta.url), 'utf8'),
) as StaffingResponse
describe('Go /api/staffing parity', () => {
it('rebuilds the API plan from its own hourly forecast', () => {
const firstHour = fixture.hours[0]
expect(firstHour).toBeDefined()
const build = buildStaffing({
sensor: fixture.sensor,
scenario: fixture.scenario,
standard: fixture.standard,
points: fixture.hours.map((hour) => ({ t: hour.t, v: hour.footfall })),
weekStart: berlinParts(firstHour!.t).date,
data_version: fixture.data_version,
model_version: fixture.model_version,
context_version: fixture.context_version,
})
expect(build.response.assumptions).toEqual(fixture.assumptions)
expect(build.response.summary).toEqual(fixture.summary)
expect(build.response.shifts).toEqual(fixture.shifts)
// The API returns float footfall; the local display type rounds it. Every
// decision field must still be identical.
const decision = (hours: StaffingResponse['hours']) =>
hours.map(({ footfall: _footfall, ...rest }) => rest)
expect(decision(build.response.hours)).toEqual(decision(fixture.hours))
})
})
+1
View File
@@ -0,0 +1 @@
{"sensor":"hn-stadtgalerie-01","scenario":"base","standard":"standard","assumptions":{"visitors_per_staff_hour":25,"safety_factor":1.15,"min_staff":1,"shift_length_h":4,"labor_cost_eur_h":16,"store_hours":{"open":"10:00","close":"20:00","tz":"Europe/Berlin"}},"hours":[{"t":"2026-11-16T09:00:00Z","footfall":30.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T10:00:00Z","footfall":30.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T11:00:00Z","footfall":30.6,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T12:00:00Z","footfall":28.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T13:00:00Z","footfall":23.1,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T14:00:00Z","footfall":24.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T15:00:00Z","footfall":25.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T16:00:00Z","footfall":26.3,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T17:00:00Z","footfall":28.3,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-16T18:00:00Z","footfall":26.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T09:00:00Z","footfall":30.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T10:00:00Z","footfall":28.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T11:00:00Z","footfall":30.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T12:00:00Z","footfall":29.3,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T13:00:00Z","footfall":23.1,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T14:00:00Z","footfall":25,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T15:00:00Z","footfall":23,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T16:00:00Z","footfall":25.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T17:00:00Z","footfall":28.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-17T18:00:00Z","footfall":25.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T09:00:00Z","footfall":31,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T10:00:00Z","footfall":28.1,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T11:00:00Z","footfall":30.8,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T12:00:00Z","footfall":30.6,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T13:00:00Z","footfall":22.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T14:00:00Z","footfall":24.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T15:00:00Z","footfall":25.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T16:00:00Z","footfall":26.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T17:00:00Z","footfall":29.1,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-18T18:00:00Z","footfall":29.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T09:00:00Z","footfall":29.3,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T10:00:00Z","footfall":31.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T11:00:00Z","footfall":27.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T12:00:00Z","footfall":28.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T13:00:00Z","footfall":24.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T14:00:00Z","footfall":22.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T15:00:00Z","footfall":22.8,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T16:00:00Z","footfall":25.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T17:00:00Z","footfall":29.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-19T18:00:00Z","footfall":26.9,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T09:00:00Z","footfall":28,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T10:00:00Z","footfall":29.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T11:00:00Z","footfall":28.2,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T12:00:00Z","footfall":28.7,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T13:00:00Z","footfall":25.5,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T14:00:00Z","footfall":23.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T15:00:00Z","footfall":25.4,"required_staff":2,"scheduled_staff":2,"coverage":"ok"},{"t":"2026-11-20T16:00:00Z","footfall"Line truncated
+28
View File
@@ -62,6 +62,34 @@ describe('buildStaffing', () => {
expect(build.response.summary.overstaffed_hours).toBeGreaterThan(0)
expect(build.response.summary.understaffed_hours).toBe(0)
})
it('compares the flat schedule against the global peak, matching the Go API', () => {
// Monday needs 5, Tuesday needs 10. CONTRACT §5 applies max(required) to
// every hour: 10 * 20 h * €16 = €3200, not a per-day peak sum.
const points = [
...mondayPoints(100).map((point, index) => ({
...point,
t: new Date(Date.UTC(2026, 10, 15, 23 + index)).toISOString().replace('.000Z', 'Z'),
})),
...mondayPoints(200).map((point, index) => ({
...point,
t: new Date(Date.UTC(2026, 10, 16, 23 + index)).toISOString().replace('.000Z', 'Z'),
})),
]
const build = buildStaffing({
sensor: 'hn-stadtgalerie-01',
scenario: 'base',
standard: 'standard',
points,
weekStart: '2026-11-16',
data_version: 'data',
model_version: 'model',
context_version: 'context',
})
expect(build.response.summary.flat_schedule_cost_eur).toBe(3200)
expect(build.response.summary.cost_eur).toBe(2400)
})
})
describe('applyScenario', () => {