Files
erp/test
arcodangeandClaude Opus 5 a11ec634ea feat(erp): manifeste d'exercice — décrire les faits pour pouvoir les rejouer
Un exercice OUVERT n'a d'engagement envers personne : aucun compte déposé,
aucune liasse, aucun FEC remis. Tant qu'il en va ainsi, une erreur de
MODÉLISATION se corrige mieux en rejouant depuis les pièces qu'en la
contournant — la piste d'audit fiable demande que l'écriture reflète sa pièce,
et rejouer resserre ce lien là où une rustine le distend.

extractExercise.ts ne fait que LIRE. Il produit la description ordonnée des
faits : tiers, factures client et fournisseur avec leurs lignes et règlements,
et l'intégralité des mouvements bancaires.

Les mouvements bancaires sont le RÉFÉRENT : Qonto et Wise sont hors de
Dolibarr, on ne peut pas les réécrire. Le test d'acceptation d'un rejeu est
donc qu'ils soient retrouvés au centime et à la date.

La ligne de partage entre ce qui se rejoue et ce qui est figé n'est pas
technique mais juridique : est figé tout ce qu'un tiers détient — facture
client ENVOYÉE, dépôt au greffe, déclaration transmise — et tout exercice clos.
Les factures client sont donc extraites avec delivered:true : un rejeu les
reproduit à l'identique, il ne les recalcule pas.

Les exclusions sont DÉCLARATIVES ET MOTIVÉES, jamais codées en dur : un
auditeur doit lire pourquoi une référence manque sans avoir à le deviner. Deux
pièces sont écartées — FAC001-CL00001, dont la référence était malformée par un
défaut de masque, et l'avoir qui l'annulait. L'opérateur a établi qu'elle n'a
jamais quitté la société : KissMetrics a été facturé via Wise en février, et le
document qu'il détient référence FAC001-CL0001001. L'avoir ne documentait donc
qu'un faux pas interne. La séquence FAC reste continue (FAC001 à FAC008), la
réémission portant elle aussi FAC001 — rien à renuméroter.

Deux constats que l'extraction met au jour :

- 20 des 37 mouvements bancaires portent un libellé Dolibarr générique
  (« SupplierInvoicePayment », « CustomerInvoicePayment ») qui traverse le grand
  livre tel quel et y est illisible pour un repreneur comme pour un inspecteur ;
- FAF2025001 (OVH, 7,30 EUR) est datée du 24/10/2025, trois mois avant
  l'immatriculation, et NE FIGURE PAS à l'annexe 1 des statuts qui recense les
  actes accomplis pour le compte de la société en formation. Une dépense
  antérieure à l'existence de la société ne peut être supportée par elle que si
  elle est reprise par cet état ou ratifiée ensuite.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
2026-08-14 17:55:30 +02:00
..
2025-08-08 17:57:56 +02:00
2025-08-08 17:57:56 +02:00

test — Dolibarr UI automation (Deno + Playwright)

A small Deno + Playwright POC that drives the Dolibarr admin UI in the fr-FR locale. Playwright fills the same forms a human admin would, so the automation works even where the REST API can't (e.g. generating an API key, which is encrypted with the instance's own DOLI_INSTANCE_UNIQUE_ID).

Layout

  • main.ts — original entrypoint (first install, company/display/module setup).
  • provisionSandbox.ts — entrypoint that provisions the erp-sandbox instance for the AI agent (enable REST API, create a write-scoped user, generate its API key).
  • scripts/login.ts — admin login / logout / whoami helpers.
  • scripts/forms.tsfillForm, toggleOnOff, CKEditor/ACE helpers.
  • scripts/admin/moduleSetup.tsconfigureModule, enableApiModule.
  • scripts/admin/userSetup.tscreateUser, assignRights, generateApiKey.

Configure

Copy .env.example to .env and fill it in. .env, *.key, and .ai_agent_sandbox.key are gitignored — never commit secrets.

cp .env.example .env

Lock the installer (after a fresh install via main.ts)

Dolibarr keeps its web installer reachable until an install.lock file exists. After a fresh install (the main.ts flow), create it in the target pod — for the sandbox:

kubectl -n erp-sandbox exec \
  "$(kubectl get pod -n erp-sandbox -l app.kubernetes.io/instance=erp-sandbox -o name)" -- \
  /bin/sh -c 'touch /var/www/documents/install.lock && chown www-data:www-data /var/www/documents/install.lock'

The path is the Dolibarr data root (/var/www/documents, a PVC) — that's where Dolibarr checks, and being on the PVC the lock persists across pod restarts. For prod, swap to -n erp -l app.kubernetes.io/instance=erp. A sandbox seeded from prod still needs this: the seed (see ../ops/sandbox/) copies the DB + documents/mycompany, not install.lock.

Provision the sandbox

Provisions erp-sandbox.arcodange.lab: enables the REST API module, creates the write-scoped ai_agent_sandbox user, grants it its write rights, and has Dolibarr generate the user's API key. The key is written to test/.ai_agent_sandbox.key (gitignored) — it is never printed.

cd test
deno run --allow-all provisionSandbox.ts

Populate .env from the erp-sandbox namespace secrets first. secretkv carries the app env (including DOLI_ADMIN_PASSWORD); vso-db-credentials carries the database password:

# Admin password (key DOLI_ADMIN_PASSWORD inside the secretkv secret)
kubectl get secret secretkv -n erp-sandbox \
  -o jsonpath='{.data.DOLI_ADMIN_PASSWORD}' | base64 -d

# Database password (key `password` inside vso-db-credentials)
kubectl get secret vso-db-credentials -n erp-sandbox \
  -o jsonpath='{.data.password}' | base64 -d

Set in .env:

DOLIBARR_ADDRESS=https://erp-sandbox.arcodange.lab
DOLI_ADMIN_LOGIN=admin
DOLI_ADMIN_PASSWORD="<from secretkv above>"
DOLI_DB_PASSWORD="<from vso-db-credentials above>"
# Optional — otherwise a random password is generated and only the API key emitted:
# AI_AGENT_SANDBOX_PASSWORD="<choose one>"

After it runs

The generated API key lands in test/.ai_agent_sandbox.key. Next step (not automated by this POC): load it into the dolibarr skill's sandbox config / Vault at kvv2/erp-sandbox/ai_agent.

Important

The sandbox Dolibarr is not installed/provisioned yet (empty DB, fresh install wizard). Until the install wizard has been completed against the sandbox, provisionSandbox.ts will not have a UI to drive, and the selectors in moduleSetup.ts / userSetup.ts are best-effort (Dolibarr 22 conventions, not verified live). Confirm them on the first real run.

Write rights granted

The ai_agent_sandbox user is created non-admin and granted (the authoritative list is WRITE_IDS in provisionSandbox.ts):

Module rights ids
facture lire=11, creer=12
societe lire=121, creer=122, client voir=262
societe contact lire=281, creer=282
fournisseur lire=1181, facture lire=1231, facture creer=1232
produit lire=31, creer=32
banque lire=111
user lire=251 — requis par le probe armé GET /users/info (checkpoint status/relink-env)