L'admin etait une 2e app front Vite independante (apps/admin-web, port 5174,
Dockerfile nginx, service compose dedie, job CI propre) non demandee. Toute
l'UI passe dans apps/web sous le prefixe /admin ; seul le frontend est
fusionne, l'authentification admin reste entierement separee.
Front (apps/web/src) :
- pages -> pages/admin/{login,dashboard,monitoring,corrections,catalog}/,
layout -> layouts/AdminLayout.tsx, contexte + garde -> features/admin/.
- client API -> api/admin-client.ts : classe AdminApiError (evite la
collision avec ApiError), lit VITE_API_URL (plus de VITE_ADMIN_API_URL).
- routes /admin/* dans App.tsx, enveloppees d'AdminAuthProvider +
RequireAdmin -> le probe GET /admin/auth/me ne tourne que sous /admin.
- reutilise l'i18n, lib/zod-errors, services/error-message.service et le
theme SCSS de apps/web ; bloc i18n admin.* fusionne dans la locale fr
(les cles errors etaient deja toutes presentes).
- corrige une race dans CatalogPage (reponse d'un onglet precedent qui
ecrasait l'onglet courant, exposee par le double-mount StrictMode) via
un ref requestSeq.
Auth admin inchangee : table AdminUser, cookie admin_session,
ADMIN_JWT_SECRET, script create-admin.ts.
Infra :
- docker-compose : service admin-web + ADMIN_WEB_PORT supprimes (l'app
`app` sert deja le front construit).
- ADMIN_CORS_ORIGIN retire (meme origine) : env.ts, app.ts, .env.example.
- job CI "Run admin-web E2E tests" supprime ; les specs admin-* tournent
dans le job web (apps/web/cypress/e2e/admin-*.{cy.ts,feature}).
- apps/api/.env.example : ajout ADMIN_JWT_SECRET / ADMIN_INITIAL_*.
- recharts ajoute a apps/web ; pnpm-lock regenere.
- specs/backend-architecture.md : section admin mise a jour.
Verifie : biome + tsc -b (web/api) + pnpm -r build verts ; Cypress web
102/103 (l'unique echec est le flake pre-existant recipe-form.feature
"Preloads ..." de clipping headless, sans rapport) ; 16/16 specs admin ;
45/45 composants.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
159 lines
4.6 KiB
TypeScript
159 lines
4.6 KiB
TypeScript
// Mocks the admin API via cy.intercept — no live backend.
|
|
|
|
const adminBody = {
|
|
id: 1,
|
|
email: "ops@example.com",
|
|
name: "Ops",
|
|
createdAt: "2026-08-01T00:00:00.000Z",
|
|
lastLoginAt: "2026-08-28T09:00:00.000Z",
|
|
};
|
|
|
|
function suggestionGroups() {
|
|
return [
|
|
{
|
|
techStepKey: "simmer",
|
|
suggestions: [
|
|
{
|
|
id: 11,
|
|
techStepKey: "simmer",
|
|
locale: "fr",
|
|
suggestedSynonyms: ["frémir"],
|
|
suggestedUtterances: ["laisser cuire tout doucement"],
|
|
sourceType: "correction",
|
|
status: "pending",
|
|
createdAt: "2026-08-20T00:00:00.000Z",
|
|
sourceCorrection: {
|
|
id: 5,
|
|
recipeId: 2,
|
|
stepId: 7,
|
|
clauseText: "faire mijoter la sauce",
|
|
previousTechStepKey: "cook",
|
|
correctedTechStepKey: "simmer",
|
|
},
|
|
},
|
|
],
|
|
},
|
|
];
|
|
}
|
|
|
|
function corrections() {
|
|
return [
|
|
{
|
|
id: 5,
|
|
recipeId: 2,
|
|
stepId: 7,
|
|
stepDescription: "Faire mijoter la sauce 20 min.",
|
|
clauseText: "faire mijoter la sauce",
|
|
start: 0,
|
|
end: 21,
|
|
previousTechStepKey: "cook",
|
|
correctedTechStepKey: "simmer",
|
|
createdAt: "2026-08-20T00:00:00.000Z",
|
|
consumedAt: null,
|
|
},
|
|
{
|
|
id: 6,
|
|
recipeId: 3,
|
|
stepId: 9,
|
|
stepDescription: "Réserver au frais.",
|
|
clauseText: "Réserver au frais",
|
|
start: 0,
|
|
end: 17,
|
|
previousTechStepKey: "setAside",
|
|
correctedTechStepKey: null,
|
|
createdAt: "2026-08-19T00:00:00.000Z",
|
|
consumedAt: null,
|
|
},
|
|
];
|
|
}
|
|
|
|
describe("Admin corrections triage", () => {
|
|
beforeEach(() => {
|
|
cy.viewport(1400, 1000);
|
|
cy.intercept("GET", "**/admin/auth/me", { statusCode: 200, body: adminBody });
|
|
cy.intercept("GET", "**/admin/tech-steps/suggestions*", {
|
|
statusCode: 200,
|
|
body: suggestionGroups(),
|
|
}).as("getSuggestions");
|
|
cy.intercept("GET", "**/admin/tech-steps/corrections*", {
|
|
statusCode: 200,
|
|
body: corrections(),
|
|
}).as("getCorrections");
|
|
});
|
|
|
|
it("shows the caveat, groups suggestions by technique, and applies one", () => {
|
|
cy.intercept("PATCH", "**/admin/tech-steps/suggestions/11", {
|
|
statusCode: 200,
|
|
body: { ...suggestionGroups()[0].suggestions[0], status: "applied" },
|
|
}).as("patch");
|
|
|
|
cy.visit("/admin/corrections");
|
|
cy.wait("@getSuggestions");
|
|
|
|
cy.contains(".corrections-caveat", "training_data.py").should("be.visible");
|
|
cy.contains(".suggestion-group h2", "simmer").should("be.visible");
|
|
cy.contains(".suggestion-card", "faire mijoter la sauce").should(
|
|
"contain.text",
|
|
"cook → simmer",
|
|
);
|
|
|
|
cy.contains(".suggestion-card button", "Appliquer").click();
|
|
cy.wait("@patch").its("request.body").should("deep.equal", { status: "applied" });
|
|
});
|
|
|
|
it("generates a training_data.py snippet", () => {
|
|
cy.intercept("GET", "**/admin/tech-steps/training-data-snippet*", {
|
|
statusCode: 200,
|
|
body: {
|
|
techStepKey: "simmer",
|
|
locale: "fr",
|
|
status: "applied",
|
|
suggestionCount: 2,
|
|
synonyms: ["frémir", "réduire"],
|
|
utterances: [],
|
|
snippet:
|
|
'# simmer (fr) — 2 suggestion(s) "applied"\n"synonyms": [\n "frémir",\n "réduire",\n],',
|
|
},
|
|
}).as("getSnippet");
|
|
|
|
cy.visit("/admin/corrections");
|
|
cy.get(".corrections-panel input").type("simmer");
|
|
cy.contains(".corrections-panel button", "Générer").click();
|
|
cy.wait("@getSnippet");
|
|
cy.get(".corrections-snippet").should("contain.value", '"synonyms": [');
|
|
});
|
|
|
|
it("runs the F1 gate and shows the result", () => {
|
|
cy.intercept("POST", "**/admin/tech-steps/retrain", {
|
|
statusCode: 200,
|
|
body: {
|
|
f1: 0.83,
|
|
precision: 0.8,
|
|
recall: 0.86,
|
|
minF1: 0.8,
|
|
gatePassed: true,
|
|
backfilled: { total: 120, changed: 4 },
|
|
marked: { applied: 0, rejected: 0 },
|
|
},
|
|
}).as("retrain");
|
|
|
|
cy.visit("/admin/corrections");
|
|
cy.contains(".corrections-panel--retrain button", "Lancer").click();
|
|
cy.wait("@retrain");
|
|
cy.contains(".retrain-result", "F1 0.830")
|
|
.should("have.class", "retrain-result--ok")
|
|
.and("contain.text", "4/120");
|
|
});
|
|
|
|
it("lists raw corrections including the removals, on the second tab", () => {
|
|
cy.visit("/admin/corrections");
|
|
cy.contains(".corrections-tabs button", "Corrections brutes").click();
|
|
cy.wait("@getCorrections");
|
|
|
|
cy.get(".corrections-table tbody tr").should("have.length", 2);
|
|
cy.contains(".corrections-table tr", "Réserver au frais").should(
|
|
"contain.text",
|
|
"setAside → ∅",
|
|
);
|
|
});
|
|
});
|