Skip to content

ci: bring Vitest + ESLint + GitHub Actions to main#25

Merged
BartM82 merged 4 commits into
mainfrom
review/code-review-fixes
May 14, 2026
Merged

ci: bring Vitest + ESLint + GitHub Actions to main#25
BartM82 merged 4 commits into
mainfrom
review/code-review-fixes

Conversation

@sebdraven
Copy link
Copy Markdown
Member

PR #24 a été mergée dans la branche `review/code-review-fixes` quelques secondes après que PR #23 ait déjà été mergée sur main. Résultat : tout le travail CI/CD est resté coincé sur la branche de feature, alors que main n'a aujourd'hui ni tests, ni lint, ni workflow.

Cette PR remet sur main les 4 commits restants de `review/code-review-fixes` (déjà revus dans PR #24).

Ce que ça apporte sur main

Tests Vitest (96 tests, ~1.5s)

  • `tests/contentExtractor.test.js` — `cleanText` (préservation Unicode), `detectPageType` (14 cas + 3 cas matchStem pour /articles/, /blogs/), `extractTitle`, `shouldSkipElement`
  • `tests/techniqueAnalyzer.test.js` — bandes de score, `findKeywordMatches`, pondérations contextuelle/dynamique, `performAnalysis`
  • `tests/suspiciousSitesManager.test.js` — `checkSite` (exact/contains/pattern), formats Storm1516 sociaux, `extractSocialHandle`, gating debug
  • `tests/uiManager.test.js` — `escapeHtml`, `sanitizeHexColor`, `isSafeHttpUrl`, `adjustColor`, `generateTooltip`
  • `tests/accessibility.test.js` — role/tabindex/aria-label du badge flottant, activation clavier Enter/Space avec preventDefault
  • `tests/syncInit.test.js` — verrouille l'init synchrone du manager (aucun `setTimeout(` dans le bootstrap)
  • `tests/animations.test.js` — verrouille le préfixe `dima*` sur tous les `@keyframes`
  • `tests/manifest.test.js` — JSON valide, MV3, chaque chemin déclaré existe

Lint

  • `eslint.config.js` (flat config, ESLint 9) — 0 erreur, 0 warning

GitHub Actions

  • `.github/workflows/ci.yml` — lint + test sur push main + PR
  • `.github/workflows/release.yml` — sur tag `v*..` : lint + test, vérifie que le tag matche `manifest.version`, package le `.zip` runtime (sans `node_modules`/`tests`), crée une draft release GitHub avec release notes auto

Modif source associée

  • `modules/Suspicioussitesmanager.js` : expose `window.SuspiciousSitesManager` (la classe en plus de l'instance) pour rendre le module testable. Sans effet en production.

Usage local

```bash
npm install
npm run ci # lint + tests
npm run test:watch # mode dev
```

Workflow de release

```bash

bump manifest.json -> "version": "2.1.0", commit, merge sur main

git tag v2.1.0 && git push origin v2.1.0

release.yml crée la release draft avec DIMA_Plugin_Chrome-2.1.0.zip

```

Pourquoi ré-ouvrir la PR

PR #24 ciblait `review/code-review-fixes` (suggestion par défaut de GitHub puisque la branche existait toujours), pas main. Le merge a réussi techniquement mais n'a rien fait remonter — la branche review était déjà mergée sur main.

🤖 Generated with Claude Code

sebdraven and others added 4 commits May 14, 2026 17:22
Test infrastructure
-------------------
- Vitest + happy-dom: 5 test files, 83 unit tests covering ContentExtractor
  (cleanText keeping Unicode scripts, detectPageType edge cases, title
  extraction), TechniqueAnalyzer (risk bands, keyword matching boundaries,
  weight escalation), SuspiciousSitesManager (exact/contains/pattern matching
  plus the Storm1516 social-account format, handle extraction, logging gate),
  UIManager (escapeHtml, sanitizeHexColor, isSafeHttpUrl, adjustColor clamp,
  tooltip), and manifest sanity (JSON validity, declared paths exist).
- tests/helpers/loadScript.js loads each content-script source as it would
  run in Chrome (indirect eval inside happy-dom's window), keeping the
  production code unchanged.

Source-side adjustments to make the modules testable
----------------------------------------------------
- Suspicioussitesmanager.js: expose `window.SuspiciousSitesManager` (the
  class, in addition to the instance). Gate the "no databases loaded"
  warning behind DIMA_DEBUG — same noise-reduction rationale as the
  previous review pass. Tidy an unused destructure variable.

Tooling
-------
- package.json with vitest, happy-dom, eslint, globals; scripts: test,
  test:watch, test:coverage, lint, lint:fix, ci.
- eslint.config.js (flat config): browser globals for source, node +
  vitest globals for tests, no-eq-eq smart, no-redeclare disabled because
  database files declare their own globals at top level.
- vitest.config.js: happy-dom env, coverage scoped to modules/ + content.js.
- .gitignore.

GitHub Actions
--------------
- ci.yml: lint + tests on every push to main and every PR.
- release.yml: on tag v*.*.*, verify tag matches manifest.version, run
  npm ci, zip the runtime files (manifest, content.js, modules/, data/,
  docs, README, LICENSE, icons), upload as workflow artifact and create
  a draft GitHub release.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
contentExtractor.test.js — add three cases that exercise the matchStem
switch on `article` and `blog`:
  - /articles/foo -> news
  - /blogs/post   -> blog
  - blogs.example.com -> blog

animations.test.js — new file. Scans content.js for @Keyframes
declarations and uiManager.js for `animation:` references, asserting
that every name begins with `dima`. Prevents a future change from
re-introducing a generic keyframe name (fadeIn, slideIn, ...) that
would collide with the host page's CSS namespace.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
accessibility.test.js — exercise createButton() against happy-dom and
assert that the rendered badge:
  - carries role=button and tabindex=0
  - exposes an aria-label including score and risk level
  - hides the decorative 🧠 from screen readers
  - fires showModal on Enter and on Space
  - preventDefault on Space (so the host page doesn't scroll)
  - ignores unrelated keys

syncInit.test.js — guard the bootstrap of Suspicioussitesmanager.js:
  - no setTimeout(...) call in the init block (comments are stripped
    so the historical note explaining why the delay was removed
    doesn't trip the assertion)
  - window.checkSuspiciousSite is callable immediately after the
    module is loaded (no async wait)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ci: Vitest unit tests + ESLint + GitHub Actions (CI & release)
@sebdraven sebdraven requested a review from BartM82 May 14, 2026 17:54
@BartM82 BartM82 merged commit 46169ec into main May 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants