Files
erp/test/main.ts
T
arcodangeandClaude Opus 5 e175f1fead fix(test): garde d'hôte sur main.ts — le script qui pilote l'installeur
main.ts pilote l'ASSISTANT D'INSTALLATION de Dolibarr (initialSetup.ts va sur
/install/). C'est le script le plus destructeur du dépôt, et il était le seul
des scripts UI à n'avoir aucune garde d'hôte — alors que la docstring de
guard.ts nomme précisément le danger : « test/.env ships DOLIBARR_ADDRESS
pointing at PRODUCTION, so a script run with the ambient environment would
drive the real ERP ».

Pointé sur la production avec l'environnement ambiant, il relançait l'installeur
sur l'ERP réel. assertSandbox() n'autorise désormais que le bac à sable, sauf
double opt-in explicite (ARCO_ALLOW_PRODUCTION + ARCO_PROD_CONFIRM) — que
l'installation initiale d'un nouvel environnement justifie, et qui reste un
geste d'opérateur.

Vérifié : DOLIBARR_ADDRESS=https://erp.arcodange.lab est refusé.

Ceci clôt le mode vierge, qui n'avait rien à inventer. La chaîne existait déjà
en entier :

  sandbox-lifecycle.sh blank --yes   purge la base, retire install.lock
  test/main.ts                       pilote l'installeur, société, affichage, modules
  touch install.lock                 reverrouille (procédure du README)
  test/provisionSandbox.ts           agent d'écriture, droits, clé API

Le « golden empty » proposé au commit précédent était une invention pour un
problème résolu : je n'avais pas regardé test/. C'est exactement le contrôle
inscrit dans AGENTS.md le matin même — lire l'existant avant de modéliser.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-08-14 19:32:17 +02:00

89 lines
2.8 KiB
TypeScript

import "load_dotenv";
import { chromium } from "playwright";
import initialSetup from "./scripts/admin/initialSetup.ts";
import login from "./scripts/login.ts";
import { assertSandbox } from "./scripts/guard.ts";
import companySetup, { Company } from "./scripts/admin/companySetup.ts";
import path from "node:path";
import displaySetup from "./scripts/admin/displaySetup.ts";
import moduleSetup from "./scripts/admin/moduleSetup.ts";
/*
Initialisation
*/
// GARDE D'HÔTE. main.ts pilote l'ASSISTANT D'INSTALLATION (`/install/`) : c'est
// le script le plus destructeur du dépôt. Pointé sur la production avec
// l'environnement ambiant — et `test/.env` porte justement DOLIBARR_ADDRESS sur
// la PRODUCTION — il relancerait l'installeur sur l'ERP réel.
// assertSandbox() n'autorise que le bac à sable, sauf double opt-in explicite
// (ARCO_ALLOW_PRODUCTION + ARCO_PROD_CONFIRM) pour l'installation initiale d'un
// nouvel environnement, qui reste un geste d'opérateur.
const dolibarrAddress = assertSandbox();
const debug = true;
const DBpassword = Deno.env.get("DOLI_DB_PASSWORD") || "undefined";
const adminCredentials = {
username: Deno.env.get("DOLI_ADMIN_LOGIN") || "undefined",
password: Deno.env.get("DOLI_ADMIN_PASSWORD") || "undefined",
};
const rootFolderPath = Deno.env.get("ROOT_FOLDER") ||
"/Users/gabrielradureau/Desktop/ARCODANGE/erp";
const imgFolderPath = Deno.env.get("IMG_FOLDER") ||
path.join(rootFolderPath, "static/img");
const configFolderPath = Deno.env.get("CONFIG_FOLDER") ||
path.join(rootFolderPath, "static/config");
const browser = await chromium.launch({
headless: false,
logger: {
isEnabled: (_name, _severity) => debug,
log: (name, severity, message, args) =>
console.warn(`${severity}| ${name} :: ${message} __ ${args}`),
},
});
const context = await browser.newContext({ locale: "fr-FR" });
const page = await context.newPage();
const globalCtx = {
dolibarrAddress,
DBpassword,
adminCredentials,
debug,
rootFolderPath,
imgFolderPath,
configFolderPath,
browser,
page,
context,
};
// if (!await initialSetup.isUpgradeLocked(globalCtx)) {
// await initialSetup.doFirstInstall(globalCtx);
// } else {
// console.log("Installation et Mises à jours bloquée par fichier .lock.");
// }
// await login.doAdminLogin(globalCtx);
// console.log(`connected as ${await login.whoAmI(globalCtx)}`);
// const company = JSON.parse(
// await Deno.readTextFile(
// path.join(globalCtx.configFolderPath, "company.json"),
// ),
// ) as Company;
// await companySetup.setupCompany(globalCtx, company);
try {
// await displaySetup.setupDisplay(globalCtx);
await moduleSetup.configureModule(globalCtx, {moduleName: 'TIERS' ,enabled: false, onConfiguration: async () => {
await globalCtx.page.screenshot({path: 'save.png'})
}});
} catch (error) {
console.error(error);
}
// await browser.close();