Skip to content

feat: validate 1fichier premium accounts - #3

Merged
mpiton merged 7 commits into
mainfrom
feat/mat-132-premium-accounts
Jul 16, 2026
Merged

feat: validate 1fichier premium accounts#3
mpiton merged 7 commits into
mainfrom
feat/mat-132-premium-accounts

Conversation

@mpiton

@mpiton mpiton commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • add real premium-account validation through the authenticated 1fichier user API
  • read the selected credential only through Vortex's dedicated host function
  • preserve typed authentication, expiry, cooldown, and quota failures for host-side rotation
  • resolve premium tokens with traffic metadata and fail closed when traffic is exhausted

Verification

  • cargo fmt --all -- --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --all-targets: 64 unit tests, 10 fixtures, 8 WASM smoke tests
  • cargo build --target wasm32-wasip1 --release
  • cargo audit

Release artifact checksums from this HEAD:

  • WASM: 4ece1695b8a9d990323846a4cf11eca911c0e011936922dfacfe8ed5d7810a9f
  • plugin.toml: bcf3ba595c323d2d0a4ea680e4c6354285153020e07d1efe05c856d5e281dd6d

Delivery ordering

After merge, publish immutable v1.1.0 assets before updating Vortex's registry. The app PR intentionally keeps the registry on the currently published v1.0.0 entry.

Linear: https://linear.app/mpiton/issue/MAT-132/lot-2-brancher-les-comptes-premium-de-bout-en-bout


Summary by cubic

Adds strict premium account validation and typed account errors to vortex-mod-1fichier. Premium mode now fails closed on auth/expiry/cooldown/quota; free mode is used only when no credential is selected, meeting MAT-132.

  • New Features

    • New validate_account export: calls user/info.cgi with Bearer auth, accepts paid offers (1–3), rejects free/expired; classifies HTTP 401/403/402/429/509; returns {"valid": true}.
    • Premium token path detects exhausted traffic (via traffic_used >= traffic_total or KO messages) and surfaces QuotaExceeded with code ACCOUNT_QUOTA_EXCEEDED.
    • Selected credential failures return typed errors (ACCOUNT_INVALID_CREDENTIALS, ACCOUNT_EXPIRED, ACCOUNT_COOLDOWN, ACCOUNT_QUOTA_EXCEEDED); no silent fallback. Free metadata is returned only when no credential is selected.
    • Version bumped to 1.1.0; README updated to reflect validation and fail-closed behavior.
  • Migration

    • Call validate_account on add/update to set account state; store secrets only in the host keyring.
    • On premium downloads, rotate accounts on ACCOUNT_* codes; use free mode only when no credential is selected.
    • Publish v1.1.0 assets, then update Vortex’s registry with the new checksums.

Written for commit 82d87d2. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features
    • Added a premium account validation step (now exposes {"valid": true} when successful).
    • Strengthened premium quota/traffic detection and error-to-code reporting.
  • Bug Fixes
    • Premium-mode fallback no longer switches to free mode when premium validation fails for invalid/expired credentials—typed errors are surfaced instead.
    • Improved handling of HTTP status and API error responses (invalid credentials, expired accounts, rate limits, quota exceeded).
  • Documentation
    • Clarified free-mode behavior and added guidance for premium validation and stable error codes.
  • Tests
    • Expanded WASM smoke coverage for validation and premium error mapping.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The plugin now validates premium credentials through user/info.cgi, preserves typed credential and quota errors, exposes stable error codes, prevents rejected credentials from falling back to free mode, and expands unit/WASM coverage. Documentation and crate/plugin versions are updated to 1.1.0.

Changes

Premium validation flow

Layer / File(s) Summary
Typed account and quota errors
src/error.rs
Adds QuotaExceeded and stable machine-readable error codes.
Account validation request and parsing
src/premium_mode.rs
Builds and parses authenticated account-validation requests, accepts eligible offers, and maps HTTP/API failures to typed errors.
Premium mode selection and quota handling
src/plugin_api.rs, src/premium_mode.rs
Adds the validate_account entry point, preserves premium failures, converts response bodies, and detects exhausted traffic.
Integration coverage and published behavior
tests/wasm_smoke.rs, README.md, src/lib.rs, Cargo.toml, plugin.toml
Expands HTTP-stub and WASM coverage, updates behavior documentation, and bumps versions to 1.1.0.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Host
  participant validate_account
  participant http_request
  participant AccountAPI
  Host->>validate_account: invoke with configured credential
  validate_account->>http_request: build and send user/info.cgi request
  http_request->>AccountAPI: POST with Bearer authorization
  AccountAPI-->>http_request: account status and offer
  http_request-->>validate_account: HTTP response
  validate_account-->>Host: {"valid": true} or typed error code
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 80.49% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding authenticated validation for 1fichier premium accounts.

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/wasm_smoke.rs (1)

224-228: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover every typed HTTP account-status mapping.

Add 402 → ACCOUNT_EXPIRED and 509 → ACCOUNT_QUOTA_EXCEEDED to this matrix so the host-visible contracts cannot regress independently of body-based tests.

     for (status, expected_code) in [
         (401, "ACCOUNT_INVALID_CREDENTIALS"),
         (403, "ACCOUNT_INVALID_CREDENTIALS"),
+        (402, "ACCOUNT_EXPIRED"),
         (429, "ACCOUNT_COOLDOWN"),
+        (509, "ACCOUNT_QUOTA_EXCEEDED"),
     ] {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/wasm_smoke.rs` around lines 224 - 228, Add the missing typed HTTP
account-status cases to the matrix in the smoke test: include 402 expecting
ACCOUNT_EXPIRED and 509 expecting ACCOUNT_QUOTA_EXCEEDED alongside the existing
entries. Keep the current loop and assertions unchanged so every host-visible
mapping is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/premium_mode.rs`:
- Around line 131-135: Update the validation logic around parsed.status and
parsed.offer so only an explicit, case-insensitive status of "OK" can reach the
successful offer match; missing or empty status must return an error even when
offer is 1–3. Add a regression test covering an offer of 1 with absent or empty
status and assert that validation fails.

---

Nitpick comments:
In `@tests/wasm_smoke.rs`:
- Around line 224-228: Add the missing typed HTTP account-status cases to the
matrix in the smoke test: include 402 expecting ACCOUNT_EXPIRED and 509
expecting ACCOUNT_QUOTA_EXCEEDED alongside the existing entries. Keep the
current loop and assertions unchanged so every host-visible mapping is covered.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f68bc3b-af65-4cd9-88cb-e2940f7979d2

📥 Commits

Reviewing files that changed from the base of the PR and between 3f49827 and dbbd130.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • Cargo.toml
  • README.md
  • plugin.toml
  • src/error.rs
  • src/lib.rs
  • src/plugin_api.rs
  • src/premium_mode.rs
  • tests/wasm_smoke.rs

Comment thread src/premium_mode.rs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

All reported issues were addressed across 9 files

Linked issue analysis

Linked issue: MAT-132: [Lot 2] Brancher les comptes premium de bout en bout

Status Acceptance criteria Notes
⚠️ R-01 — L’ajout ou la modification d’un compte déclenche une validation réelle via le port applicatif prévu. The plugin now exposes a validate_account export and implements the account-validation request/response (src/plugin_api.rs, src/premium_mode.rs) and there is a WASM test calling validate_account. However the PR does not show the host/app wiring that calls this export on add/update (the application-side trigger is not present in this repo), so the end-to-end trigger is not fully proven in the diff.
R-02 — Un secret de compte n’est jamais persisté en clair dans SQLite, les logs ou les events frontend. Plugin code reads credentials only via the host get_credential function and does not persist secrets in the plugin; README and code changes document/implement host-only credential access.
⚠️ R-03 — Un téléchargement premium sélectionne uniquement un compte activé, valide et compatible avec le hoster. The plugin enforces compatibility/validity with the hoster (accepts paid offers 1–3) and no longer silently falls back on credential failures (it returns typed errors). But the plugin does not assert or read an application-level "enabled/activated" flag — that is an app-side concern and not shown wired here.
R-04 — Le plugin reçoit le credential attendu via la fonction hôte dédiée, sans connaître le keyring. The plugin reads the API key only via get_credential (host function) and tests verify the host-credential flow in WASM smoke tests.
R-05 — Les erreurs d’authentification, de quota et de cooldown produisent des états typés et observables dans l’UI. Typed account error variants and stable machine codes were added (PluginError::code), classification logic maps HTTP/messages to ACCOUNT_* codes, and error messages are prefixed with the code so the host can observe and update UI/state. Tests assert presence of these codes.
⚠️ R-06 — Des tests d’intégration couvrent succès, credential absent, compte expiré et rotation vers un second compte. The PR adds many integration-style WASM tests covering success, invalid credential, exhausted quota and HTTP account failures. It does not include an explicit test for the host-side rotation to a second account or an explicit credential-absent end-to-end host integration (rotation is an application-level behavior), so the full set of scenarios in the acceptance row is not fully covered here.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/premium_mode.rs Outdated
Comment thread src/plugin_api.rs
@mpiton

mpiton commented Jul 16, 2026

Copy link
Copy Markdown
Owner Author

Review fixes pushed in 82d87d2: explicit status OK validation with regression coverage, missing-credential WASM coverage, and typed HTTP mappings for 402 and 509. Rotation remains tested at the host/application boundary in mpiton/vortex#171.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

2 similar comments
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mpiton
mpiton merged commit e8c2d11 into main Jul 16, 2026
7 checks 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.

1 participant