Compare commits

..

2 Commits

Author SHA1 Message Date
Manus
8759d85f3d Merge remote-tracking branch 'recette/main' 2026-08-18 07:42:06 +00:00
Manus
eecbd07b5c chore: versionner le manifeste de déploiement 2026-08-17 22:35:40 +02:00
7 changed files with 6 additions and 94 deletions

View File

@@ -1,45 +0,0 @@
name: Validation applicative
on:
push:
branches: [main, master]
paths-ignore:
- "**.md"
- "docs/**"
pull_request:
branches: [main, master]
paths-ignore:
- "**.md"
- "docs/**"
workflow_dispatch:
jobs:
verify:
name: TypeScript, tests et build
# Label dédié : image locale avec Node 22, pnpm verrouillé et Bash déjà installés.
runs-on: ci-node22
timeout-minutes: 15
steps:
- name: Récupérer les sources
uses: actions/checkout@v4
- name: Calculer la clé de cache pnpm
id: pnpm-cache-key
shell: bash
run: |
echo "store=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
echo "lock=$(sha256sum pnpm-lock.yaml | cut -d ' ' -f 1)" >> "$GITHUB_OUTPUT"
- name: Restaurer le store pnpm
uses: actions/cache@v4
with:
path: ${{ steps.pnpm-cache-key.outputs.store }}
key: pnpm-${{ runner.os }}-${{ steps.pnpm-cache-key.outputs.lock }}
restore-keys: |
pnpm-${{ runner.os }}-
- name: Installer les dépendances verrouillées
run: pnpm install --frozen-lockfile --prefer-offline
- name: Vérifier TypeScript, tests et build
run: pnpm verify

View File

@@ -9,8 +9,5 @@
"containerName": "demat-facturation-app",
"image": "images/demat-facturation-dsi.jpg",
"giteaRepo": "demat-facturation",
"giteaOwner": "manus-admin",
"ci": {
"required": true
}
"giteaOwner": "manus-admin"
}

View File

@@ -10,8 +10,7 @@
"check": "tsc --noEmit",
"format": "prettier --write .",
"test": "vitest run",
"db:push": "drizzle-kit generate && drizzle-kit migrate",
"verify": "pnpm check && pnpm test && pnpm build"
"db:push": "drizzle-kit generate && drizzle-kit migrate"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.693.0",
@@ -138,4 +137,4 @@
"sharp"
]
}
}
}

View File

@@ -406,7 +406,4 @@ async function startServer() {
}, 5000); // Attendre 5s que le serveur soit prêt
}
// Vitest ne doit jamais démarrer un serveur HTTP.
if (!process.env.VITEST) {
startServer().catch(console.error);
}
startServer().catch(console.error);

View File

@@ -1218,20 +1218,3 @@ export async function updateWebImportSourceStatus(
if (success) update.lastSuccessAt = new Date();
await db.update(webImportSources).set(update).where(eq(webImportSources.id, id));
}
/**
* Check if a source file with the same fileName already exists for this user
* Used to prevent duplicate file storage during email import
*/
export async function findSourceFileByFileName(userId: number, fileName: string): Promise<any | null> {
const db = await getDb();
if (!db) return null;
const result = await db.select()
.from(sourceFiles)
.where(and(
eq(sourceFiles.userId, userId),
eq(sourceFiles.fileName, fileName)
))
.limit(1);
return result[0] || null;
}

View File

@@ -9,7 +9,6 @@ import {
isInvoiceBlacklisted,
createInvoice,
createImportLog,
findSourceFileByFileName,
} from "./db";
import { extractInvoicesWithMistral, generateMetadataJSON } from "./invoiceExtractor";
import { localStoragePut, generateStorageKey } from "./localStorage";
@@ -33,8 +32,6 @@ interface EmailImportConfig {
// Store active intervals for each user
const activeIntervals = new Map<number, NodeJS.Timeout>();
// Verrou anti-concurrence par userId
const runningChecks = new Set<number>();
/**
* Process a single email attachment (PDF)
@@ -54,12 +51,6 @@ async function processEmailAttachment(
console.log(`[EmailImport] File size: ${fileBuffer.length} bytes`);
// Store source file
// ANTI-DUPLICATION : vérifier si ce fichier a déjà été importé pour cet utilisateur
const existingSourceFile = await findSourceFileByFileName(userId, fileName);
if (existingSourceFile) {
console.log(`[EmailImport] File ${fileName} already imported for user ${userId} (sourceFile #${existingSourceFile.id}), skipping`);
return { success: true, totalInvoices: 0, imported: 0, duplicates: 1, errors: 0 };
}
const sourceFileKey = generateStorageKey(userId, fileName);
console.log(`[EmailImport] Generated storage key: ${sourceFileKey}`);
@@ -339,12 +330,6 @@ async function buildImapConfig(config: EmailImportConfig): Promise<Imap.Config>
* Connect to IMAP and process unread emails with PDF attachments
*/
async function checkEmailsForPDFs(config: EmailImportConfig): Promise<void> {
// Anti-concurrence : ne pas lancer si un check est déjà en cours pour cet utilisateur
if (runningChecks.has(config.userId)) {
console.log(`[EmailImport] Check already running for user ${config.userId}, skipping`);
return;
}
runningChecks.add(config.userId);
// Build IMAP config (may involve async OAuth2 token fetch)
const imapConfig = await buildImapConfig(config);
@@ -395,7 +380,7 @@ async function checkEmailsForPDFs(config: EmailImportConfig): Promise<void> {
const fetch = imap.fetch(results, {
bodies: "",
markSeen: true, // Mark as seen immediately to prevent re-processing
markSeen: false, // Don't mark as seen yet
});
const processedEmails: number[] = [];
@@ -489,13 +474,11 @@ async function checkEmailsForPDFs(config: EmailImportConfig): Promise<void> {
});
imap.once("error", (err) => {
runningChecks.delete(config.userId);
console.error("[EmailImport] IMAP connection error:", err);
reject(err);
});
imap.once("end", () => {
runningChecks.delete(config.userId);
console.log(`[EmailImport] IMAP connection ended for user ${config.userId}`);
});

View File

@@ -1,13 +1,11 @@
import { describe, it, expect, beforeAll } from "vitest";
const describeIntegration = process.env.DATABASE_URL ? describe : describe.skip;
import {
getLlmFieldsConfigByUser,
upsertLlmFieldConfig,
initializeDefaultLlmFields
} from "./db";
describeIntegration("LLM Fields Configuration", () => {
describe("LLM Fields Configuration", () => {
const testUserId = 99999; // Use a high ID to avoid conflicts
beforeAll(async () => {