CoS schedule route tests validate against a hand-rolled copy of the Zod schemas

Chiusa Adatta ai principianti
#11,998 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
backend, testing

Direzione di ricerca

Leggi server/routes/cosScheduleRoutes.test.js:27-50 e confronta il relativo mock di validazione con gli schemi reali in server/lib/validation.js:2800 e server/lib/cosValidation.js:477. Sostituisci o rimuovi il mock, quindi modifica i fixture se gli schemi reali li rifiutano. Esegui i test delle route e conferma che l’allentamento di cosScheduleTargetBodySchema fa fallire i casi 400 di trigger e reset; limita la modifica al file di test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

effort:low model:light plan planner:fable-5-1 test-quality tests

Slice audited: scheduled-work and route tests (test-quality audit, 2026-10-18).

Problem

server/routes/cosScheduleRoutes.test.js:27-50 mocks ../lib/validation.js with a factory that re-implements taskDataInputsSchema.safeParse, cosScheduleTargetBodySchema.safeParse and validateRequest by hand. The 400 assertions in POST /schedule/trigger ("should return 400 if taskType is missing"), POST /schedule/reset, and PUT /schedule/task/:taskType ("rejects unknown data input ids") therefore test the copy, not server/lib/validation.js:2800 (cosScheduleTargetBodySchema) or server/lib/cosValidation.js:477.

Mutation probe (scratch worktree): loosened the real cosScheduleTargetBodySchema to taskType: nullishString and the real taskDataInputsSchema to z.array(z.string()).

Tests  55 passed (55)

cosScheduleTargetBodySchema has no other test anywhere (rg finds it only in this test file's mock).

Impact

A loosened target schema lets POST /api/cos/schedule/trigger and /reset reach triggerOnDemandTask(undefined, …) / resetExecutionHistory(undefined, …) (server/routes/cosScheduleRoutes.js:283, :355), queueing an on-demand agent run with no task type, an unrequested provider dispatch path, with the suite green.

Fix (decided)

In cosScheduleRoutes.test.js, replace the factory with vi.mock('../lib/validation.js', async (importOriginal) => ({ ...(await importOriginal()), sanitizeTaskMetadata: vi.fn((m) => m) })), or drop the mock entirely if sanitizeTaskMetadata need not be doubled. Delete the duplicated safeParse/validateRequest/parsePagination copies and adjust fixtures the real schema rejects. No production code change.

Scope: small

Acceptance criteria

  • Loosening cosScheduleTargetBodySchema in server/lib/validation.js fails the trigger/reset 400 cases.
  • The test file no longer defines its own safeParse or validateRequest.
  • No production code change.
Lingua principale
JavaScript
Stelle
38
Fork
32
Merge medio
35m
PR unite (30g)
989

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di atomantic/PortOS

Tutte le issue di atomantic/PortOS

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.