From 8616886c21a1a7d185cd84d162c320852d73f49c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 20:06:58 +0000 Subject: [PATCH 1/3] =?UTF-8?q?test(e2e):=20laisser=20un=20mod=C3=A8le=20d?= =?UTF-8?q?e=20d=C3=A9cision=20choisir=20les=20parcours=20hors=20zone=20da?= =?UTF-8?q?ns=20la=20porte=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parcours gate only ran journeys whose hand-written zone the diff touched, so an app change outside the seven zones (Today, symbols, trends, badges, shared components, lib, hooks, context) ran the smoke set and nothing else. With a Vercel AI Gateway key in AI_GATEWAY_API_KEY, the zone filter now also asks the TesterArmy decision filter (@e2e-dev/decision 0.3.1, Jev pinned to typesafe-ai/jev-1.14.0, zero-data-retention routes only) about every parcours the zones leave out as untouched, and runs it unless the model rates it under 20% likely affected. The zones stay the floor; smoke and bug-bash tests keep their own checks; a model that cannot answer leaves the zones alone, and the filter note says so. On any Dreamer app diff the gate then launches Dreamer and Lucid, which share the app code. run.mjs calls the filters for `e2e list` and again for `e2e run`, and checks that the run selected what the list did, so the first verdict for a commit, base, change and test set is kept in .git/verify-cache/e2e-decision/ and reused. Without the key nothing changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SiTgQDoCBBaR457WUsv6YN --- AGENTS.md | 4 +- doc_web_interne/docs/repository-operations.md | 17 +++- scripts/README.md | 2 +- tools/e2e/README.md | 9 +- tools/e2e/decision-verdict.d.mts | 18 ++++ tools/e2e/decision-verdict.mjs | 65 +++++++++++++ tools/e2e/decision-verdict.test.mjs | 97 +++++++++++++++++++ tools/e2e/package-lock.json | 29 ++++++ tools/e2e/package.json | 1 + tools/e2e/pr-gate.mjs | 23 +++-- tools/e2e/pr-gate.test.mjs | 33 ++++++- tools/e2e/run.mjs | 2 +- tools/e2e/zone-filter.test.mjs | 54 ++++++++++- tools/e2e/zone-filter.ts | 21 +++- tools/e2e/zones.d.mts | 11 +++ tools/e2e/zones.mjs | 44 ++++++++- verify-local.config.mjs | 7 +- 17 files changed, 408 insertions(+), 29 deletions(-) create mode 100644 tools/e2e/decision-verdict.d.mts create mode 100644 tools/e2e/decision-verdict.mjs create mode 100644 tools/e2e/decision-verdict.test.mjs diff --git a/AGENTS.md b/AGENTS.md index 1d4c3a1de..0daaf0065 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -162,7 +162,9 @@ It is an authoring loop, not part of `verify:pr` or CI. Read the installed skill/topic, reuse guarded runners/fixtures and keep provider budgets. `verify:pr` runs the tagged smoke journeys on a Dreamer app diff and the named parcours for the zones that diff touches (`npm run test:e2e:smoke`, -`npm run test:e2e:parcours`), locally, without a model and without GitHub Actions. +`npm run test:e2e:parcours`), locally, without GitHub Actions, and without a +model unless `AI_GATEWAY_API_KEY` is set: the decision model then judges the +parcours the zones leave out ([details](doc_web_interne/docs/repository-operations.md)). A docs-only diff, or a diff with no web app zone, skips both. A native-only diff skips the web gate. If a zone is touched and Node 24.22.1, the e2e install, or Chromium is missing, the check is unavailable and `verify:pr` diff --git a/doc_web_interne/docs/repository-operations.md b/doc_web_interne/docs/repository-operations.md index 6799c31b2..727844969 100644 --- a/doc_web_interne/docs/repository-operations.md +++ b/doc_web_interne/docs/repository-operations.md @@ -83,7 +83,7 @@ coverage and release targets; [verify-local.config.mjs](../../verify-local.confi is the executable source of truth. `verify:pr` also runs two local web gates when the diff touches the app, with no -model call and no GitHub Actions minutes. `parcours-touches` maps changed paths +GitHub Actions minutes and, by default, no model call. `parcours-touches` maps changed paths (`app/`, `components/`, `services/`, and the other roots in `tools/e2e/zones.mjs`) to e2e tags and test files, then runs `e2e run --changed-since origin/master`. `smoke-journeys` runs the seven tagged smoke journeys (capture, save, journal, @@ -93,6 +93,21 @@ both. A native-only diff exits 0. If a zone is touched and Node 24.22.1, is incomplete, not passed. Rerun: `npm run test:e2e:parcours` and `npm run test:e2e:smoke`. +Optional decision model: with a Vercel AI Gateway key in `AI_GATEWAY_API_KEY`, +`parcours-touches` also asks the TesterArmy decision filter (Jev, pinned in +`tools/e2e/zones.mjs`, zero-data-retention routes only) about every Dreamer and +Lucid parcours the zones leave out, on any Dreamer app diff, named zone or not. +The model sees the diff and the journey files, never the working tree. A +parcours runs unless the model rates it under 20% likely affected; the zones +stay the floor, smoke and bug-bash tests keep their own checks, and a parcours +the model cannot judge runs. A lockfile or e2e config change makes it keep +every parcours. If the model cannot answer at all (no route, rejected key), +the zones decide alone and the run's filter note says so. The first verdict for +a commit is kept under `.git/verify-cache/e2e-decision/`, so `e2e list` and +`e2e run` select the same tests and a rerun asks nothing. Without the key the +gate is unchanged. Cost: about $0.04 per million tokens (one call is a few +thousand to a few tens of thousands of tokens). + Before an app release, run `npm run test:bugbash:prerelease` on Dreamer web in mock mode (the script refuses a production Supabase ref). Each confirmed bug becomes a failing test under `tools/e2e/tests/bugbash/`, tagged `bugbash`. diff --git a/scripts/README.md b/scripts/README.md index 02e0c409e..84b6445ba 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -16,7 +16,7 @@ connects these commands to implementation paths and current runbooks. | SEO | `seo:gsc:export`, `seo:backlinks:check` | GSC export writes a dated external-data report; backlink check fetches the tracked public referring pages but never rewrites the CSV. | | Web E2E | `test:e2e:web`, `test:e2e:web:report` | TesterArmy and its pinned Chromium; simulated services. See [the E2E guide](../e2e/README.md). | | Backend E2E | `test:e2e:backend`, `start:backend-e2e` | Disposable local backend on the native Supabase runtime (no Docker) and browser artifacts; `test:e2e:backend -- --qualify-ti528` adds the six TI528 integration cases to the nine backend scenarios. Linux amd64/arm64 with glibc 2.35+ or macOS 14+ on Apple silicon (`node scripts/check-native-supabase-runtime.cjs`). See [backend qualification](../doc_web_interne/docs/e2e-backend-qualification.md). | -| TesterArmy E2E | `test:testerarmy*`, `test:e2e:parcours`, `test:e2e:smoke`, `test:bugbash:prerelease`, `test:bugbash:repros`, `agent-device:*` | TesterArmy on web, an owned emulator or a named iOS Simulator; native runs need an identified Release build (`build`) and an explicit `E2E_DEVICE`, and take the device lock. `test:e2e:parcours` and `test:e2e:smoke` are the local PR gates (no model). `test:bugbash:prerelease` is the mock-mode explore before an app release; `test:bugbash:repros` is the release check. See [the TesterArmy guide](../tools/e2e/README.md). Maestro and its `test:e2e:*` Android commands were retired on 2026-10-14. | +| TesterArmy E2E | `test:testerarmy*`, `test:e2e:parcours`, `test:e2e:smoke`, `test:bugbash:prerelease`, `test:bugbash:repros`, `agent-device:*` | TesterArmy on web, an owned emulator or a named iOS Simulator; native runs need an identified Release build (`build`) and an explicit `E2E_DEVICE`, and take the device lock. `test:e2e:parcours` and `test:e2e:smoke` are the local PR gates (no model, except the optional decision model of `test:e2e:parcours` when `AI_GATEWAY_API_KEY` is set). `test:bugbash:prerelease` is the mock-mode explore before an app release; `test:bugbash:repros` is the release check. See [the TesterArmy guide](../tools/e2e/README.md). Maestro and its `test:e2e:*` Android commands were retired on 2026-10-14. | | Mobile release | `release:*` | `prepare` writes manifests; `versions:sync` writes local mirrors; `build` starts a remote EAS build and requires explicit authorization. See [the release guide](../doc_web_interne/docs/MOBILE_VERSIONING.md). | | Android release | `android:gates:*`, `android:release:local`, `build:apk:*` | May require ADB, a physical device, EAS credentials, or local build tooling. `android:gates:strict` requires a qualified TesterArmy run of the `production-apk` candidate under `tools/e2e/.e2e/dreamer-android/` (same commit as the release and its build, clean tree, intact manifest, candidate APK in `QA_ANDROID_RELEASE_APK`, stable and clean source snapshots). The real voice check is an optional manual test (owner decision 2026-10-17). | | Subscriptions | `subscription:qa:*` | Some commands update local QA evidence; see the RevenueCat runbook before use. | diff --git a/tools/e2e/README.md b/tools/e2e/README.md index f8d52c808..928ac35a6 100644 --- a/tools/e2e/README.md +++ b/tools/e2e/README.md @@ -596,10 +596,11 @@ real journeys and never establish application or physical qualification. Agent goals can be added with an authorized model provider, one goal per call and exact critical-outcome assertions. No provider is configured by default. -The optional `@e2e-dev/decision` / Jev setup described in the installed -`docs/decision-models.mdx` additionally requires `ai` 7.0.128 or later. This -package installs neither that executor nor `ai`; exact journeys require no -model dependency, and the upgrade does not enable a provider. +This package pins `@e2e-dev/decision` for one use only: the optional decision +filter of the PR parcours gate (`zones.mjs`, `decision-verdict.mjs`, installed +`docs/filters.mdx`), which stays off until `AI_GATEWAY_API_KEY` is set. Its +`decisionExecutor` for `agent.act` is not configured; exact journeys require no +model dependency. Use a provider barrier when replay must never call a model; strict cache alone does not forbid a call on a cache miss. Existing Playwright, backend and CI checks remain until an explicitly reviewed pipeline change. Still-relevant diff --git a/tools/e2e/decision-verdict.d.mts b/tools/e2e/decision-verdict.d.mts new file mode 100644 index 000000000..778ebf738 --- /dev/null +++ b/tools/e2e/decision-verdict.d.mts @@ -0,0 +1,18 @@ +import type { TestFilter, TestFilterCandidate, TestFilterContext } from 'e2e'; + +export function verdictKey(input: { + model: string; + base: string; + head: string; + files: readonly string[]; + tests: readonly string[]; +}): string; + +export function decisionVerdict( + asked: readonly TestFilterCandidate[], + context: TestFilterContext, + options?: { + load?: () => Promise; + git?: (file: string, args: readonly string[], options: { cwd: string; encoding: 'utf8' }) => string; + }, +): Promise<{ exclude: Record; note?: string }>; diff --git a/tools/e2e/decision-verdict.mjs b/tools/e2e/decision-verdict.mjs new file mode 100644 index 000000000..149755bdf --- /dev/null +++ b/tools/e2e/decision-verdict.mjs @@ -0,0 +1,65 @@ +/** + * The decision model's verdict on the parcours the zones leave out, through + * the TesterArmy Filters API (`@e2e-dev/decision`, Jev on the Vercel AI + * Gateway). run.mjs calls the filters twice, `e2e list` then `e2e run`, and + * checks that the run selected exactly what the list did, so the first answer + * for a commit and a test set is kept in the clone's git directory and reused. + * A rerun of verify:pr on the same commit asks nothing either. + */ +import { createHash } from 'node:crypto'; +import { execFileSync } from 'node:child_process'; +import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { DECISION_MODEL } from './zones.mjs'; + +/** @param {{ model: string, base: string, head: string, files: readonly string[], tests: readonly string[] }} input */ +export function verdictKey({ model, base, head, files, tests }) { + return createHash('sha256').update(JSON.stringify({ model, base, head, files: [...files].sort(), tests: [...tests].sort() })).digest('hex'); +} + +function gitRead(git, root, args) { + return git('git', args, { cwd: root, encoding: 'utf8' }).trim(); +} + +function readVerdict(file) { + try { + const kept = JSON.parse(readFileSync(file, 'utf8')); + if (kept && typeof kept.exclude === 'object' && kept.exclude !== null && !Array.isArray(kept.exclude) + && Object.values(kept.exclude).every(reason => typeof reason === 'string')) return kept; + } catch {} + return null; +} + +async function loadDecisionFilter() { + const [{ decisionFilter }, { gateway }] = await Promise.all([import('@e2e-dev/decision'), import('ai')]); + return decisionFilter({ + model: gateway.decisionModel(DECISION_MODEL), + // Only routes that keep nothing: the diff and the journeys leave the machine. + providerOptions: { gateway: { zeroDataRetention: true } }, + }); +} + +/** + * Asks the decision filter about `asked`, or reuses its answer for the same + * commit, base, changed files and tests. Throws when the model cannot answer + * at all (no route, every call failed); the caller then keeps the zones alone. + * @param {readonly import('e2e').TestFilterCandidate[]} asked + * @param {import('e2e').TestFilterContext} context + */ +export async function decisionVerdict(asked, context, { load = loadDecisionFilter, git = execFileSync } = {}) { + const root = context.changes.root; + const key = verdictKey({ + model: DECISION_MODEL, base: context.changes.base, head: gitRead(git, root, ['rev-parse', 'HEAD']), + files: context.changes.files, tests: asked.map(test => test.id), + }); + const file = join(gitRead(git, root, ['rev-parse', '--path-format=absolute', '--git-common-dir']), 'verify-cache', 'e2e-decision', `${key}.json`); + const cached = readVerdict(file); + if (cached) return { exclude: cached.exclude, note: ['verdict repris', cached.note].filter(Boolean).join(', ') }; + const filter = await load(); + const verdict = await filter.filter(asked, context); + const kept = { exclude: { ...verdict.exclude }, ...(verdict.note ? { note: verdict.note } : {}) }; + mkdirSync(dirname(file), { recursive: true }); + writeFileSync(`${file}.${process.pid}`, JSON.stringify(kept)); + renameSync(`${file}.${process.pid}`, file); + return kept; +} diff --git a/tools/e2e/decision-verdict.test.mjs b/tools/e2e/decision-verdict.test.mjs new file mode 100644 index 000000000..34d550512 --- /dev/null +++ b/tools/e2e/decision-verdict.test.mjs @@ -0,0 +1,97 @@ +import assert from 'node:assert/strict'; +import { execFileSync } from 'node:child_process'; +import { existsSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { test } from 'node:test'; +import { decisionFilter } from '@e2e-dev/decision'; +import { decisionVerdict, verdictKey } from './decision-verdict.mjs'; + +const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8' }).trim(); + +/** A repository whose last commit changes one app file the two journeys may or may not reach. */ +function repository() { + const root = realpathSync(mkdtempSync(join(tmpdir(), 'decision-verdict-'))); + git(root, 'init', '-q', '-b', 'master'); + git(root, 'config', 'user.email', 'test@example.com'); + git(root, 'config', 'user.name', 'test'); + mkdirSync(join(root, 'tests')); + mkdirSync(join(root, 'components')); + writeFileSync(join(root, 'tests/today.web.e2e.ts'), "test('today shows the moon', async () => {});\n"); + writeFileSync(join(root, 'tests/billing.web.e2e.ts'), "test('billing opens the paywall', async () => {});\n"); + writeFileSync(join(root, 'components/MoonCard.tsx'), 'export const phase = 1;\n'); + git(root, 'add', '.'); + git(root, 'commit', '-q', '-m', 'base'); + const base = git(root, 'rev-parse', 'HEAD'); + writeFileSync(join(root, 'components/MoonCard.tsx'), 'export const phase = 2;\n'); + git(root, 'commit', '-qam', 'change'); + return { root, base }; +} + +const tests = [ + { id: 'tests/today.web.e2e.ts::today shows the moon', file: 'tests/today.web.e2e.ts', titlePath: ['today shows the moon'], tags: [] }, + { id: 'tests/billing.web.e2e.ts::billing opens the paywall', file: 'tests/billing.web.e2e.ts', titlePath: ['billing opens the paywall'], tags: [] }, +]; + +function context(root, base) { + return { + projectRoot: root, changes: { base, root, files: ['components/MoonCard.tsx'] }, + signal: new AbortController().signal, log() {}, redact: text => text, + }; +} + +/** An offline decision model: the moon journey is likely affected, the billing one is not. */ +function fakeModel(calls, fail = false) { + return { + specificationVersion: 'v4', provider: 'fake', modelId: 'fake-jev', supportedQuestionTypes: ['boolean'], + async doDecide({ questions }) { + calls.push(Object.keys(questions).length); + if (fail) throw new Error('401 invalid key'); + return { + answers: Object.fromEntries(Object.entries(questions).map(([id, question]) => + [id, { type: 'boolean', probability: String(question.instructions).includes('billing') ? 0.05 : 0.9 }])), + usage: { inputTokens: 100, outputTokens: 0 }, warnings: [], + }; + }, + }; +} + +test('the real decision filter leaves out the journey the change cannot reach, and the verdict is kept for the run', async () => { + const { root, base } = repository(); + try { + const calls = []; + let loads = 0; + const load = async () => { loads += 1; return decisionFilter({ model: fakeModel(calls) }); }; + const first = await decisionVerdict(tests, context(root, base), { load }); + assert.deepEqual(Object.keys(first.exclude), ['tests/billing.web.e2e.ts::billing opens the paywall']); + assert.match(first.exclude['tests/billing.web.e2e.ts::billing opens the paywall'], /5% likely affected/); + assert.equal(loads, 1); + assert.equal(calls.length, 1); + // `e2e run` after `e2e list`: same commit, change and tests, so the same answer and no call. + const second = await decisionVerdict(tests, context(root, base), { load }); + assert.deepEqual(second.exclude, first.exclude); + assert.match(second.note, /^verdict repris/); + assert.equal(loads, 1); + // Another test set is another question. + await decisionVerdict(tests.slice(0, 1), context(root, base), { load }); + assert.equal(loads, 2); + assert.equal(readdirSync(join(root, '.git/verify-cache/e2e-decision')).length, 2); + } finally { rmSync(root, { recursive: true, force: true }); } +}); + +test('a model that cannot answer throws and keeps no verdict', async () => { + const { root, base } = repository(); + try { + const load = async () => decisionFilter({ model: fakeModel([], true) }); + await assert.rejects(decisionVerdict(tests, context(root, base), { load }), /401 invalid key/); + assert.equal(existsSync(join(root, '.git/verify-cache/e2e-decision')), false); + } finally { rmSync(root, { recursive: true, force: true }); } +}); + +test('a new commit, base, change or model is a new verdict', () => { + const input = { model: 'typesafe-ai/jev-1.14.0', base: 'a', head: 'b', files: ['x', 'y'], tests: ['t1', 't2'] }; + const key = verdictKey(input); + assert.equal(verdictKey({ ...input, files: ['y', 'x'], tests: ['t2', 't1'] }), key); + for (const change of [{ head: 'c' }, { base: 'c' }, { files: ['x'] }, { tests: ['t1'] }, { model: 'typesafe-ai/jev' }]) + assert.notEqual(verdictKey({ ...input, ...change }), key, JSON.stringify(change)); +}); diff --git a/tools/e2e/package-lock.json b/tools/e2e/package-lock.json index a5e0eb5b7..7f2a9dd2e 100644 --- a/tools/e2e/package-lock.json +++ b/tools/e2e/package-lock.json @@ -7,6 +7,7 @@ "name": "@noctalia-internal/e2e", "devDependencies": { "@ai-sdk/openai": "4.0.96", + "@e2e-dev/decision": "0.3.1", "@e2e-dev/mobile": "0.12.4", "@e2e-dev/web": "0.15.3", "@types/node": "^24.0.0", @@ -157,6 +158,34 @@ "node": ">= 20.12.0" } }, + "node_modules/@e2e-dev/decision": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@e2e-dev/decision/-/decision-0.3.1.tgz", + "integrity": "sha512-PkgBc2EYxL922zx4EiSkGsFz9Lb4b6xnqXcVgihlpq+HvVChzVAvCTkEo3lgXwQNcsSxKQjTn+/NUPg0M4/zTQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "pngjs": "7.0.0", + "zod": "4.6.7" + }, + "engines": { + "node": "^22.22.3 || >=24.8.0" + }, + "peerDependencies": { + "ai": "^7.0.134", + "e2e": ">=0.21.3 <1" + } + }, + "node_modules/@e2e-dev/decision/node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "dev": true, + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, "node_modules/@e2e-dev/mobile": { "version": "0.12.4", "resolved": "https://registry.npmjs.org/@e2e-dev/mobile/-/mobile-0.12.4.tgz", diff --git a/tools/e2e/package.json b/tools/e2e/package.json index 1ab06d48f..030b92cf7 100644 --- a/tools/e2e/package.json +++ b/tools/e2e/package.json @@ -11,6 +11,7 @@ }, "devDependencies": { "@ai-sdk/openai": "4.0.96", + "@e2e-dev/decision": "0.3.1", "@e2e-dev/mobile": "0.12.4", "@e2e-dev/web": "0.15.3", "@types/node": "^24.0.0", diff --git a/tools/e2e/pr-gate.mjs b/tools/e2e/pr-gate.mjs index 84bad07a1..d3dae03f2 100644 --- a/tools/e2e/pr-gate.mjs +++ b/tools/e2e/pr-gate.mjs @@ -1,6 +1,7 @@ /** * PR-gate launcher for Dreamer/Lucid/Meditation web journeys. - * A diff with no web app zone exits 0 without a browser. A native-only diff + * A diff with no web app zone exits 0 without a browser, unless a Vercel AI + * Gateway key lets the decision model judge an unzoned Dreamer app diff. A native-only diff * does too: this gate has no emulator. When a zone is touched, a missing * pinned Node, e2e install, or Chromium exits 1. verify:pr probes the same * condition first and records the check unavailable, so the proof is @@ -11,7 +12,7 @@ import { createRequire } from 'node:module'; import { existsSync } from 'node:fs'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; -import { isDreamerAppPath, isNativeJourney, zonesForFiles } from './zones.mjs'; +import { DECISION_PRODUCTS, decisionEnabled, isDreamerAppPath, isNativeJourney, zonesForFiles } from './zones.mjs'; const here = dirname(fileURLToPath(import.meta.url)); const PINNED_NODE = 'v24.22.1'; @@ -27,12 +28,18 @@ export function changedJourneyProduct(file) { return null; } -export function decideParcours(files) { +/** + * `model`: whether the decision model judges the parcours the zones leave out + * (a Vercel AI Gateway key is set). It then sees every Dreamer app diff, named + * zone or not, for Dreamer and Lucid, which run on the same app code. + */ +export function decideParcours(files, { model = decisionEnabled(process.env) } = {}) { const zones = zonesForFiles(files).filter(zone => zone.platform === 'web'); // A changed journey runs even when no source zone matched: the decision // filter keeps it too, so a fixed or retagged journey is proved in the PR. const journeyProducts = files.map(changedJourneyProduct).filter(Boolean); - if (zones.length === 0 && journeyProducts.length === 0) { + const modelProducts = model && files.some(isDreamerAppPath) ? DECISION_PRODUCTS : []; + if (zones.length === 0 && journeyProducts.length === 0 && modelProducts.length === 0) { if (files.some(isNativeJourney) && !files.some(isDreamerAppPath)) { return { launch: false, @@ -41,10 +48,10 @@ export function decideParcours(files) { } return { launch: false, - reason: 'PARCOURS SAUTE: aucun parcours nomme (capture, sauvegarde, journal, paiement, connexion, lucid, meditation) dans le diff. Une PR documentation, ou un fichier applicatif sans zone, ne lance pas de navigateur.', + reason: 'PARCOURS SAUTE: aucun parcours nomme (capture, sauvegarde, journal, paiement, connexion, lucid, meditation) dans le diff. Une PR documentation, ou un fichier applicatif sans zone quand AI_GATEWAY_API_KEY est absente, ne lance pas de navigateur.', }; } - return { launch: true, products: [...new Set([...zones.map(zone => zone.product), ...journeyProducts])] }; + return { launch: true, products: [...new Set([...zones.map(zone => zone.product), ...journeyProducts, ...modelProducts])] }; } export function decideSmoke(files) { @@ -104,8 +111,8 @@ function launch(root, product, extra) { return result.status ?? 1; } -export function runGate(mode, root, files, ready = runnerReady(root)) { - const decision = mode === 'smoke' ? decideSmoke(files) : decideParcours(files); +export function runGate(mode, root, files, ready = runnerReady(root), options = {}) { + const decision = mode === 'smoke' ? decideSmoke(files) : decideParcours(files, options); if (!decision.launch) { console.log(decision.reason); return 0; diff --git a/tools/e2e/pr-gate.test.mjs b/tools/e2e/pr-gate.test.mjs index 203a746c7..e67edc8f7 100644 --- a/tools/e2e/pr-gate.test.mjs +++ b/tools/e2e/pr-gate.test.mjs @@ -12,16 +12,43 @@ test('docs-only and non-app diffs skip both gates', () => { test('a Dreamer recording change runs parcours and smoke on web', () => { const files = ['app/recording.tsx', 'README.md']; - assert.deepEqual(decideParcours(files).products, ['dreamer']); + assert.deepEqual(decideParcours(files, { model: false }).products, ['dreamer']); assert.deepEqual(decideSmoke(files).products, ['dreamer']); }); test('an unmapped component runs smoke only', () => { const files = ['components/ui/Toast.tsx']; - assert.equal(decideParcours(files).launch, false); + assert.equal(decideParcours(files, { model: false }).launch, false); assert.equal(decideSmoke(files).launch, true); }); +test('with the decision model, any Dreamer app diff lets it judge the Dreamer and Lucid parcours', () => { + assert.deepEqual(decideParcours(['components/ui/Toast.tsx'], { model: true }).products, ['dreamer', 'lucid']); + assert.deepEqual(decideParcours(['app/journal/[id].tsx'], { model: true }).products, ['dreamer', 'lucid']); + // Lucid-only and Meditation paths keep their own zone; docs and native journeys still launch nothing. + assert.deepEqual(decideParcours(['routes/lucid/lucid/index.tsx'], { model: true }).products, ['lucid']); + assert.deepEqual(decideParcours(['apps/meditation/app/index.tsx'], { model: true }).products, ['meditation']); + assert.equal(decideParcours(['doc_web_interne/docs/README.md', 'AGENTS.md'], { model: true }).launch, false); + assert.equal(decideParcours(['tools/e2e/tests/dreamer.mobile.e2e.ts'], { model: true }).launch, false); + // The key turns it on. + const saved = process.env.AI_GATEWAY_API_KEY; + try { + process.env.AI_GATEWAY_API_KEY = 'test-key'; + assert.equal(decideParcours(['components/ui/Toast.tsx']).launch, true); + process.env.AI_GATEWAY_API_KEY = ' '; + assert.equal(decideParcours(['components/ui/Toast.tsx']).launch, false); + } finally { + if (saved === undefined) delete process.env.AI_GATEWAY_API_KEY; + else process.env.AI_GATEWAY_API_KEY = saved; + } +}); + +test('a model-judged diff without the runner fails like a touched zone', () => { + const missing = { ok: false, reason: 'PARCOURS NON JOUE: Chromium absent' }; + assert.equal(runGate('parcours', '/tmp', ['components/ui/Toast.tsx'], missing, { model: false }), 0); + assert.equal(runGate('parcours', '/tmp', ['components/ui/Toast.tsx'], missing, { model: true }), 1); +}); + test('a native-only diff skips instead of failing', () => { const files = ['tools/e2e/tests/dreamer.mobile.e2e.ts']; const decision = decideParcours(files); @@ -80,7 +107,7 @@ test('verify:pr reaches the gate for every web journey the gate would run', asyn // each journey the gate launches must also be in the check's scope. const journeys = readdirSync(new URL('./tests/', import.meta.url)) .map(name => `tools/e2e/tests/${name}`) - .filter(file => decideParcours([file]).launch); + .filter(file => decideParcours([file], { model: false }).launch); assert.ok(journeys.includes('tools/e2e/tests/lucid.web.e2e.ts')); assert.ok(journeys.includes('tools/e2e/tests/meditation.web.e2e.ts')); assert.ok(journeys.includes('tools/e2e/tests/dreamer-home-editorial.web.e2e.ts')); diff --git a/tools/e2e/run.mjs b/tools/e2e/run.mjs index 82c1bda12..1b6419d18 100644 --- a/tools/e2e/run.mjs +++ b/tools/e2e/run.mjs @@ -142,7 +142,7 @@ function changedFilesSince(ref) { return [...new Set(listed.split('\0').filter(file => file !== '' && !file.endsWith('/')))]; } function webInputIdentity() { - const sourceFiles = ['e2e.config.ts', 'e2e.bugbash.config.ts', 'dreamer-personas.ts', 'persona-models.mjs', 'zone-filter.ts', 'zones.mjs', 'pr-gate.mjs', 'web-engine.ts', 'web-parity-fixtures.ts', 'web-fixtures.ts', 'backend-fixtures.ts', 'branch-target.ts', 'full-campaign.mjs', 'campaign-contexts.mjs', '../../verify-local.config.mjs', 'preload-web-matchers.mjs', 'run.mjs', 'journeys.ts', 'package.json', 'package-lock.json', 'tsconfig.json', + const sourceFiles = ['e2e.config.ts', 'e2e.bugbash.config.ts', 'dreamer-personas.ts', 'persona-models.mjs', 'zone-filter.ts', 'zones.mjs', 'decision-verdict.mjs', 'pr-gate.mjs', 'web-engine.ts', 'web-parity-fixtures.ts', 'web-fixtures.ts', 'backend-fixtures.ts', 'branch-target.ts', 'full-campaign.mjs', 'campaign-contexts.mjs', '../../verify-local.config.mjs', 'preload-web-matchers.mjs', 'run.mjs', 'journeys.ts', 'package.json', 'package-lock.json', 'tsconfig.json', ...readdirSync(join(cwd, 'tests')).filter(name => name.endsWith('.web.e2e.ts')).map(name => `tests/${name}`), ].sort(); return Object.fromEntries(sourceFiles.map(path => [path, createHash('sha256').update(readFileSync(join(cwd, path))).digest('hex')])); diff --git a/tools/e2e/zone-filter.test.mjs b/tools/e2e/zone-filter.test.mjs index 4e24cf8f2..4b52d50e0 100644 --- a/tools/e2e/zone-filter.test.mjs +++ b/tools/e2e/zone-filter.test.mjs @@ -2,7 +2,7 @@ import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; import { test } from 'node:test'; import { PERSONA_ACT_MODEL, PERSONA_ASSERT_MODEL } from './persona-models.mjs'; -import { filterIsActive, isDreamerAppPath, isNativeJourney, parcoursExclude, selectionOwesNothing, zonesForFiles } from './zones.mjs'; +import { DECISION_KEY_ENV, DECISION_MODEL, UNTOUCHED, decisionEnabled, filterIsActive, isDreamerAppPath, isNativeJourney, parcoursExclude, selectionOwesNothing, widenWithDecision, zonesForFiles } from './zones.mjs'; const billing = { id: 'billing', tags: ['zone-paiement', 'historical-parity'], file: 'tools/e2e/tests/dreamer-billing.web.e2e.ts' }; const billingSmoke = { id: 'billing-smoke', tags: ['smoke', 'zone-paiement'], file: 'tools/e2e/tests/dreamer-billing.web.e2e.ts' }; @@ -100,6 +100,58 @@ test('a full campaign does not pass --changed-since, and e2e 0.21.3 skips filter assert.match(gate, /args\[index\] === '--changed-since'/); }); +test('the decision model only takes back parcours the zones left out as untouched', () => { + const zones = parcoursExclude(suite, ['app/journal/[id].tsx']); + assert.equal(zones.exclude.home, UNTOUCHED); + assert.equal(zones.exclude.capture, UNTOUCHED); + // The model keeps `home`, leaves `capture` out, and its answer about smoke or bug bash would not count. + const widened = widenWithDecision(zones, { exclude: { capture: '4% likely affected', 'billing-smoke': '1% likely affected' }, note: '1 call, 9.1k tokens, $0.0004' }); + assert.equal(widened.exclude.journal, undefined); + assert.equal(widened.exclude.home, undefined); + assert.equal(widened.exclude.capture, `${UNTOUCHED} (modele : 4% likely affected)`); + assert.equal(widened.exclude['billing-smoke'], 'la fumée PR joue ce parcours'); + assert.equal(widened.exclude.bug, 'bug bash hors porte PR'); + assert.equal(widened.note, 'journal; modele : 2 parcours hors zone repris; 1 call, 9.1k tokens, $0.0004'); +}); + +test('the decision model is off without a gateway key and pinned to an exact Jev', () => { + assert.equal(DECISION_KEY_ENV, 'AI_GATEWAY_API_KEY'); + assert.equal(decisionEnabled({}), false); + assert.equal(decisionEnabled({ AI_GATEWAY_API_KEY: ' ' }), false); + assert.equal(decisionEnabled({ AI_GATEWAY_API_KEY: 'vck_test' }), true); + assert.match(DECISION_MODEL, /^typesafe-ai\/jev-\d+\.\d+\.\d+$/); + const source = readFileSync(new URL('./decision-verdict.mjs', import.meta.url), 'utf8'); + assert.match(source, /zeroDataRetention: true/); +}); + +test('the zone filter keeps the zones when the model is off or cannot answer', async () => { + const { parcoursTouches } = await import('./zone-filter.ts'); + const root = '/nonexistent/noctalia'; + const candidates = [ + { id: 'journal', file: 'tests/dreamer-journal-filters.web.e2e.ts', titlePath: ['journal'], tags: ['zone-journal'] }, + { id: 'home', file: 'tests/dreamer-home-editorial.web.e2e.ts', titlePath: ['home'], tags: ['historical-parity'] }, + ]; + const context = { + projectRoot: `${root}/tools/e2e`, changes: { base: 'base', root, files: ['app/journal/[id].tsx'] }, + signal: new AbortController().signal, log() {}, redact: text => text, + }; + const saved = process.env.AI_GATEWAY_API_KEY; + try { + delete process.env.AI_GATEWAY_API_KEY; + assert.deepEqual(await parcoursTouches.filter(candidates, context), { exclude: { home: UNTOUCHED }, note: 'journal' }); + // With a key, a model that cannot even start (here: no repository) leaves the zones' answer, and says so. + process.env.AI_GATEWAY_API_KEY = 'vck_test'; + const fallback = await parcoursTouches.filter(candidates, context); + assert.deepEqual(fallback.exclude, { home: UNTOUCHED }); + assert.match(fallback.note, /^journal; modele indisponible \(.+\), zones seules$/); + // Nothing left out as untouched: nothing to ask. + assert.deepEqual(await parcoursTouches.filter(candidates.slice(0, 1), context), { exclude: {}, note: 'journal' }); + } finally { + if (saved === undefined) delete process.env.AI_GATEWAY_API_KEY; + else process.env.AI_GATEWAY_API_KEY = saved; + } +}); + test('persona models stay the Terra act tier and the Sol judge', () => { assert.equal(PERSONA_ACT_MODEL, 'gpt-6.1-terra'); assert.equal(PERSONA_ASSERT_MODEL, 'gpt-6.1-sol'); diff --git a/tools/e2e/zone-filter.ts b/tools/e2e/zone-filter.ts index 80fbeb10f..73d9c0dc7 100644 --- a/tools/e2e/zone-filter.ts +++ b/tools/e2e/zone-filter.ts @@ -1,6 +1,7 @@ import type { TestFilter } from 'e2e'; import { relative, resolve } from 'node:path'; -import { filterIsActive, parcoursExclude } from './zones.mjs'; +import { UNTOUCHED, decisionEnabled, filterIsActive, parcoursExclude, widenWithDecision } from './zones.mjs'; +import { decisionVerdict } from './decision-verdict.mjs'; function repoPath(gitRoot: string, projectRoot: string, file: string): string { return relative(gitRoot, resolve(projectRoot, file)).replaceAll('\\', '/'); @@ -9,16 +10,28 @@ function repoPath(gitRoot: string, projectRoot: string, file: string): string { /** * Inactive unless the run passed `--changed-since` (e2e only then fills * `context.changes`). A full campaign or `verify:release` therefore keeps - * every test. No model, no network. + * every test. The zones need no model and no network. With a Vercel AI + * Gateway key, the decision model then judges the parcours the zones leave + * out; if it cannot answer, the zones alone decide, and the note says so. */ export const parcoursTouches: TestFilter = { name: 'parcours-touches', - filter(tests, context) { + async filter(tests, context) { if (!filterIsActive(context)) return { exclude: {} }; - return parcoursExclude(tests.map(test => ({ + const zones = parcoursExclude(tests.map(test => ({ id: test.id, tags: test.tags, file: repoPath(context.changes.root, context.projectRoot, test.file), })), context.changes.files); + if (!decisionEnabled(process.env)) return zones; + const asked = tests.filter(test => zones.exclude[test.id] === UNTOUCHED); + if (asked.length === 0) return zones; + try { + return widenWithDecision(zones, await decisionVerdict(asked, context)); + } catch (error) { + context.signal.throwIfAborted(); + const reason = (error instanceof Error ? error.message : String(error)).split('\n')[0]; + return { ...zones, note: `${zones.note}; modele indisponible (${reason}), zones seules` }; + } }, }; diff --git a/tools/e2e/zones.d.mts b/tools/e2e/zones.d.mts index 15f7e9eb9..22dd85374 100644 --- a/tools/e2e/zones.d.mts +++ b/tools/e2e/zones.d.mts @@ -1,5 +1,9 @@ export const SMOKE_TAG: string; export const BUGBASH_TAG: string; +export const UNTOUCHED: string; +export const DECISION_KEY_ENV: string; +export const DECISION_MODEL: string; +export const DECISION_PRODUCTS: readonly ('dreamer' | 'lucid')[]; export const DREAMER_APP_ROOTS: readonly string[]; export interface Zone { @@ -24,3 +28,10 @@ export function parcoursExclude( tests: readonly { id: string; tags: readonly string[]; file: string }[], files: readonly string[], ): { exclude: Record; note?: string }; + +export function decisionEnabled(env: Record): boolean; + +export function widenWithDecision( + zones: { exclude: Record; note?: string }, + verdict: { exclude: Readonly>; note?: string }, +): { exclude: Record; note: string }; diff --git a/tools/e2e/zones.mjs b/tools/e2e/zones.mjs index 900fa631e..10e02c729 100644 --- a/tools/e2e/zones.mjs +++ b/tools/e2e/zones.mjs @@ -1,12 +1,31 @@ /** - * Homemade zone map for the PR gate. No model. Paths are repository-relative + * Homemade zone map for the PR gate, without a model. Paths are repository-relative * POSIX paths, the same spelling `git diff --name-only` and e2e's * `--changed-since` use. A zone's tests run only when one of its sources - * changed. Docs and other non-app paths match nothing here. + * changed, unless the optional decision model below keeps them. Docs and + * other non-app paths match nothing here. */ export const SMOKE_TAG = 'smoke'; export const BUGBASH_TAG = 'bugbash'; +/** Why the zones leave out a parcours: the only reason the decision model may overturn. */ +export const UNTOUCHED = 'le diff ne touche pas ce parcours'; + +/** + * Optional decision model (the TesterArmy Filters API with Jev). It judges only + * the parcours the zones leave out, so the zones stay the floor. It needs a + * Vercel AI Gateway key in the environment; without one the gate is the zones + * alone, as before. This exact Jev pin is served with zero data retention. + */ +export const DECISION_KEY_ENV = 'AI_GATEWAY_API_KEY'; +export const DECISION_MODEL = 'typesafe-ai/jev-1.14.0'; +/** Products whose journeys the model judges when a shared Dreamer path changes: Lucid runs on the same app code. */ +export const DECISION_PRODUCTS = ['dreamer', 'lucid']; + +/** @param {Record} env */ +export function decisionEnabled(env) { + return Boolean(env[DECISION_KEY_ENV]?.trim()); +} /** Dreamer surfaces that should run the smoke tag, even with no named zone. */ export const DREAMER_APP_ROOTS = [ @@ -183,7 +202,7 @@ export function parcoursExclude(tests, files) { } const tagged = test.tags.some(tag => tags.has(tag)); const listed = testFiles.has(test.file) || changedTests.has(test.file); - if (!tagged && !listed) exclude[test.id] = 'le diff ne touche pas ce parcours'; + if (!tagged && !listed) exclude[test.id] = UNTOUCHED; } const names = zones.map(zone => zone.id); const note = names.length ? names.join(',') : changedTests.size ? 'tests-modifies' : 'aucun-parcours'; @@ -207,3 +226,22 @@ export function selectionOwesNothing(pairs, files) { const { exclude } = parcoursExclude(skipped, files); return skipped.every(pair => exclude[pair.id] !== undefined); } + +/** + * The zones' answer, widened by the model's. A parcours the zones leave out only + * because the diff misses its zone runs unless the model also leaves it out. + * Smoke and bug-bash exclusions stand: those tests have their own checks. + * @param {{ exclude: Record, note?: string }} zones + * @param {{ exclude: Record, note?: string }} verdict the model's answer about the parcours `UNTOUCHED` names + */ +export function widenWithDecision(zones, verdict) { + const exclude = {}; + let kept = 0; + for (const [id, reason] of Object.entries(zones.exclude)) { + if (reason !== UNTOUCHED) exclude[id] = reason; + else if (verdict.exclude[id] !== undefined) exclude[id] = `${UNTOUCHED} (modele : ${verdict.exclude[id]})`; + else kept += 1; + } + const note = [zones.note, `modele : ${kept} parcours hors zone repris`, verdict.note].filter(Boolean).join('; '); + return { exclude, note }; +} diff --git a/verify-local.config.mjs b/verify-local.config.mjs index 037185fa6..56d23f314 100644 --- a/verify-local.config.mjs +++ b/verify-local.config.mjs @@ -292,6 +292,7 @@ export const SMOKE_WHEN = [ export const PARCOURS_WHEN = [ 'app/', 'components/', 'context/', 'hooks/', 'lib/', 'constants/', 'services/', 'routes/', 'apps/meditation/', 'tools/e2e/zones.mjs', 'tools/e2e/zones.d.mts', 'tools/e2e/zone-filter.ts', 'tools/e2e/zone-filter.test.mjs', + 'tools/e2e/decision-verdict.mjs', 'tools/e2e/decision-verdict.d.mts', 'tools/e2e/decision-verdict.test.mjs', 'tools/e2e/pr-gate.mjs', 'tools/e2e/pr-gate.test.mjs', 'tools/e2e/e2e.config.ts', 'tools/e2e/e2e.bugbash.config.ts', 'tools/e2e/run.mjs', 'tools/e2e/persona-models.mjs', 'tools/e2e/persona-models.d.mts', 'tools/e2e/bugbash-prerelease.mjs', 'tools/e2e/bugbash-prerelease.test.mjs', 'tools/e2e/web-parity-fixtures.ts', @@ -609,14 +610,16 @@ export default { { name: 'mobile-versions', command: 'node scripts/mobile-release.js verify --app all', inputs: MOBILE_VERSIONS, when: MOBILE_VERSIONS }, { name: 'meditation', command: MEDITATION_CHECKS, when: MEDITATION, releaseAlways: true, requires: MEDITATION_DEPS }, { name: 'edge-functions', command: EDGE_CHECKS, when: EDGE, releaseAlways: true, specialised: true, requires: DENO }, - // Web only, no model, no Actions. A diff with no web zone exits 0. + // Web only, no Actions. No model unless AI_GATEWAY_API_KEY is set: the + // decision model then judges the parcours the zones leave out (zones.mjs). + // A diff with no web zone exits 0, or with the key, no Dreamer app path. // A touched zone without Node 24.22.1, tools/e2e/node_modules or Chromium // fails the probe: the proof is incomplete, not passed. No `targets`: // the engine applies targets on release only, which would drop these // checks from verify:pr. On a published master the diff is empty. { name: 'parcours-touches', - command: 'node --test tools/e2e/zone-filter.test.mjs tools/e2e/pr-gate.test.mjs tools/e2e/bugbash-prerelease.test.mjs && npm run test:e2e:parcours', + command: 'node --test tools/e2e/zone-filter.test.mjs tools/e2e/decision-verdict.test.mjs tools/e2e/pr-gate.test.mjs tools/e2e/bugbash-prerelease.test.mjs && npm run test:e2e:parcours', when: PARCOURS_WHEN, specialised: true, requires: { From cbcbe7ef6c087b363f503d612e3d52aedde16b85 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 20:12:34 +0000 Subject: [PATCH 2/3] =?UTF-8?q?test(e2e):=20borner=20le=20mod=C3=A8le=20de?= =?UTF-8?q?=20d=C3=A9cision=20=C3=A0=202=20minutes=20et=20garder=20un=20?= =?UTF-8?q?=C3=A9chec=20le=20temps=20du=20run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A model that hangs would hit e2e's 5-minute filter budget, and a filter past its budget leaves nothing out, so the whole Dreamer campaign would run. The zone filter now gives the model 2 minutes, then falls back to the zones. `e2e list` and `e2e run` must select the same tests. A failed answer was not kept, so a list that fell back to the zones could be followed by a run the model answered. The failure is now kept for 10 minutes for the same question (an interrupted run keeps none), long enough for the run to fall back too, short enough for a later verify:pr to ask again. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SiTgQDoCBBaR457WUsv6YN --- tools/e2e/decision-verdict.d.mts | 3 +++ tools/e2e/decision-verdict.mjs | 39 +++++++++++++++++++++-------- tools/e2e/decision-verdict.test.mjs | 30 +++++++++++++++++++--- tools/e2e/pr-gate.mjs | 4 +-- tools/e2e/zone-filter.ts | 11 +++++++- tools/e2e/zones.mjs | 6 ++--- 6 files changed, 73 insertions(+), 20 deletions(-) diff --git a/tools/e2e/decision-verdict.d.mts b/tools/e2e/decision-verdict.d.mts index 778ebf738..3e99fa3e2 100644 --- a/tools/e2e/decision-verdict.d.mts +++ b/tools/e2e/decision-verdict.d.mts @@ -1,5 +1,7 @@ import type { TestFilter, TestFilterCandidate, TestFilterContext } from 'e2e'; +export const FAILURE_TTL_MS: number; + export function verdictKey(input: { model: string; base: string; @@ -14,5 +16,6 @@ export function decisionVerdict( options?: { load?: () => Promise; git?: (file: string, args: readonly string[], options: { cwd: string; encoding: 'utf8' }) => string; + now?: () => number; }, ): Promise<{ exclude: Record; note?: string }>; diff --git a/tools/e2e/decision-verdict.mjs b/tools/e2e/decision-verdict.mjs index 149755bdf..73be0f319 100644 --- a/tools/e2e/decision-verdict.mjs +++ b/tools/e2e/decision-verdict.mjs @@ -4,7 +4,9 @@ * Gateway). run.mjs calls the filters twice, `e2e list` then `e2e run`, and * checks that the run selected exactly what the list did, so the first answer * for a commit and a test set is kept in the clone's git directory and reused. - * A rerun of verify:pr on the same commit asks nothing either. + * A rerun of verify:pr on the same commit asks nothing either. A failure is + * kept for a few minutes only: long enough for the run to fall back to the + * zones as its list did, short enough for a later verify:pr to ask again. */ import { createHash } from 'node:crypto'; import { execFileSync } from 'node:child_process'; @@ -21,15 +23,26 @@ function gitRead(git, root, args) { return git('git', args, { cwd: root, encoding: 'utf8' }).trim(); } -function readVerdict(file) { +/** How long a failed answer stands for the same question. */ +export const FAILURE_TTL_MS = 10 * 60_000; + +function readVerdict(file, now) { try { const kept = JSON.parse(readFileSync(file, 'utf8')); + if (kept && typeof kept.failed === 'string' && Number.isFinite(kept.at)) + return now - kept.at < FAILURE_TTL_MS ? kept : null; if (kept && typeof kept.exclude === 'object' && kept.exclude !== null && !Array.isArray(kept.exclude) && Object.values(kept.exclude).every(reason => typeof reason === 'string')) return kept; } catch {} return null; } +function keep(file, value) { + mkdirSync(dirname(file), { recursive: true }); + writeFileSync(`${file}.${process.pid}`, JSON.stringify(value)); + renameSync(`${file}.${process.pid}`, file); +} + async function loadDecisionFilter() { const [{ decisionFilter }, { gateway }] = await Promise.all([import('@e2e-dev/decision'), import('ai')]); return decisionFilter({ @@ -42,24 +55,30 @@ async function loadDecisionFilter() { /** * Asks the decision filter about `asked`, or reuses its answer for the same * commit, base, changed files and tests. Throws when the model cannot answer - * at all (no route, every call failed); the caller then keeps the zones alone. + * at all (no route, every call failed, past the caller's deadline); the caller + * then keeps the zones alone. An interrupted run keeps no failure. * @param {readonly import('e2e').TestFilterCandidate[]} asked * @param {import('e2e').TestFilterContext} context */ -export async function decisionVerdict(asked, context, { load = loadDecisionFilter, git = execFileSync } = {}) { +export async function decisionVerdict(asked, context, { load = loadDecisionFilter, git = execFileSync, now = Date.now } = {}) { const root = context.changes.root; const key = verdictKey({ model: DECISION_MODEL, base: context.changes.base, head: gitRead(git, root, ['rev-parse', 'HEAD']), files: context.changes.files, tests: asked.map(test => test.id), }); const file = join(gitRead(git, root, ['rev-parse', '--path-format=absolute', '--git-common-dir']), 'verify-cache', 'e2e-decision', `${key}.json`); - const cached = readVerdict(file); + const cached = readVerdict(file, now()); + if (cached?.failed !== undefined) throw new Error(`${cached.failed} (echec repris)`); if (cached) return { exclude: cached.exclude, note: ['verdict repris', cached.note].filter(Boolean).join(', ') }; - const filter = await load(); - const verdict = await filter.filter(asked, context); + let verdict; + try { + verdict = await (await load()).filter(asked, context); + } catch (error) { + const interrupted = context.signal.aborted && context.signal.reason?.name !== 'TimeoutError'; + if (!interrupted) keep(file, { failed: (error instanceof Error ? error.message : String(error)).split('\n')[0], at: now() }); + throw error; + } const kept = { exclude: { ...verdict.exclude }, ...(verdict.note ? { note: verdict.note } : {}) }; - mkdirSync(dirname(file), { recursive: true }); - writeFileSync(`${file}.${process.pid}`, JSON.stringify(kept)); - renameSync(`${file}.${process.pid}`, file); + keep(file, kept); return kept; } diff --git a/tools/e2e/decision-verdict.test.mjs b/tools/e2e/decision-verdict.test.mjs index 34d550512..8f527643f 100644 --- a/tools/e2e/decision-verdict.test.mjs +++ b/tools/e2e/decision-verdict.test.mjs @@ -5,7 +5,7 @@ import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { test } from 'node:test'; import { decisionFilter } from '@e2e-dev/decision'; -import { decisionVerdict, verdictKey } from './decision-verdict.mjs'; +import { FAILURE_TTL_MS, decisionVerdict, verdictKey } from './decision-verdict.mjs'; const git = (cwd, ...args) => execFileSync('git', args, { cwd, encoding: 'utf8' }).trim(); @@ -79,11 +79,33 @@ test('the real decision filter leaves out the journey the change cannot reach, a } finally { rmSync(root, { recursive: true, force: true }); } }); -test('a model that cannot answer throws and keeps no verdict', async () => { +test('a model that cannot answer throws, and the run falls back as its list did until the failure expires', async () => { const { root, base } = repository(); try { - const load = async () => decisionFilter({ model: fakeModel([], true) }); - await assert.rejects(decisionVerdict(tests, context(root, base), { load }), /401 invalid key/); + const calls = []; + let clock = 1_000_000; + const now = () => clock; + const load = async () => decisionFilter({ model: fakeModel(calls, true) }); + await assert.rejects(decisionVerdict(tests, context(root, base), { load, now }), /401 invalid key/); + assert.equal(calls.length, 1); + // `e2e run` right after: the same failure, without asking again. + clock += FAILURE_TTL_MS - 1; + await assert.rejects(decisionVerdict(tests, context(root, base), { load, now }), /401 invalid key \(echec repris\)/); + assert.equal(calls.length, 1); + // A later verify:pr asks again. + clock += 1; + await assert.rejects(decisionVerdict(tests, context(root, base), { load, now }), /^Error: 401 invalid key$/); + assert.equal(calls.length, 2); + } finally { rmSync(root, { recursive: true, force: true }); } +}); + +test('an interrupted run keeps no failure', async () => { + const { root, base } = repository(); + try { + const interrupt = new AbortController(); + interrupt.abort(new Error('SIGINT')); + const load = async () => ({ name: 'decision', filter: async () => { throw new Error('aborted'); } }); + await assert.rejects(decisionVerdict(tests, { ...context(root, base), signal: interrupt.signal }, { load }), /aborted/); assert.equal(existsSync(join(root, '.git/verify-cache/e2e-decision')), false); } finally { rmSync(root, { recursive: true, force: true }); } }); diff --git a/tools/e2e/pr-gate.mjs b/tools/e2e/pr-gate.mjs index d3dae03f2..219fa32c2 100644 --- a/tools/e2e/pr-gate.mjs +++ b/tools/e2e/pr-gate.mjs @@ -1,8 +1,8 @@ /** * PR-gate launcher for Dreamer/Lucid/Meditation web journeys. * A diff with no web app zone exits 0 without a browser, unless a Vercel AI - * Gateway key lets the decision model judge an unzoned Dreamer app diff. A native-only diff - * does too: this gate has no emulator. When a zone is touched, a missing + * Gateway key lets the decision model judge an unzoned Dreamer app diff. + * A native-only diff does too: this gate has no emulator. When a zone is touched, a missing * pinned Node, e2e install, or Chromium exits 1. verify:pr probes the same * condition first and records the check unavailable, so the proof is * incomplete instead of passed. diff --git a/tools/e2e/zone-filter.ts b/tools/e2e/zone-filter.ts index 73d9c0dc7..2637fa17c 100644 --- a/tools/e2e/zone-filter.ts +++ b/tools/e2e/zone-filter.ts @@ -3,6 +3,9 @@ import { relative, resolve } from 'node:path'; import { UNTOUCHED, decisionEnabled, filterIsActive, parcoursExclude, widenWithDecision } from './zones.mjs'; import { decisionVerdict } from './decision-verdict.mjs'; +/** Past this the model's answer is dropped and the zones decide, well inside e2e's 5-minute filter budget. */ +const DECISION_DEADLINE_MS = 120_000; + function repoPath(gitRoot: string, projectRoot: string, file: string): string { return relative(gitRoot, resolve(projectRoot, file)).replaceAll('\\', '/'); } @@ -26,12 +29,18 @@ export const parcoursTouches: TestFilter = { if (!decisionEnabled(process.env)) return zones; const asked = tests.filter(test => zones.exclude[test.id] === UNTOUCHED); if (asked.length === 0) return zones; + // A ref'd timer, as e2e's own: an unref'd AbortSignal.timeout may never fire. + const deadline = new AbortController(); + const timer = setTimeout(() => deadline.abort(new DOMException('no answer within 2 minutes', 'TimeoutError')), DECISION_DEADLINE_MS); try { - return widenWithDecision(zones, await decisionVerdict(asked, context)); + const signal = AbortSignal.any([context.signal, deadline.signal]); + return widenWithDecision(zones, await decisionVerdict(asked, { ...context, signal })); } catch (error) { context.signal.throwIfAborted(); const reason = (error instanceof Error ? error.message : String(error)).split('\n')[0]; return { ...zones, note: `${zones.note}; modele indisponible (${reason}), zones seules` }; + } finally { + clearTimeout(timer); } }, }; diff --git a/tools/e2e/zones.mjs b/tools/e2e/zones.mjs index 10e02c729..9a949d353 100644 --- a/tools/e2e/zones.mjs +++ b/tools/e2e/zones.mjs @@ -1,7 +1,7 @@ /** - * Homemade zone map for the PR gate, without a model. Paths are repository-relative - * POSIX paths, the same spelling `git diff --name-only` and e2e's - * `--changed-since` use. A zone's tests run only when one of its sources + * Homemade zone map for the PR gate, without a model. Paths are + * repository-relative POSIX paths, the same spelling `git diff --name-only` + * and e2e's `--changed-since` use. A zone's tests run only when one of its sources * changed, unless the optional decision model below keeps them. Docs and * other non-app paths match nothing here. */ From 7cefceb33eed42235d6479c4c3806a8415cd9482 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 20:20:24 +0000 Subject: [PATCH 3/3] =?UTF-8?q?test(e2e):=20passer=20le=20filtre=20de=20d?= =?UTF-8?q?=C3=A9cision=20sur=20OpenAI=20et=20ne=20pas=20reprendre=20une?= =?UTF-8?q?=20preuve=20faite=20sans=20cl=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanh has OpenAI Decisions API access, so the decision filter now uses OpenAI's gpt-6-luna through @ai-sdk/openai (already pinned in tools/e2e, it answers boolean questions) and turns on with OPENAI_API_KEY, instead of Jev through the Vercel AI Gateway. No new vendor account is needed. verify:pr reused a parcours-touches proof made without the key once the key was set (Codex P2 on cbcbe7e): the check fingerprint only covers its command, its declared env and the engine identity. The check now declares E2E_DECISION_FILTER=on|off from the key's presence, never the key itself, so turning the model on or off reruns it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SiTgQDoCBBaR457WUsv6YN --- AGENTS.md | 2 +- doc_web_interne/docs/repository-operations.md | 17 +++++----- scripts/README.md | 2 +- tools/e2e/README.md | 2 +- tools/e2e/decision-verdict.mjs | 13 +++----- tools/e2e/decision-verdict.test.mjs | 6 ++-- tools/e2e/pr-gate.mjs | 8 ++--- tools/e2e/pr-gate.test.mjs | 32 ++++++++++++++++--- tools/e2e/zone-filter.test.mjs | 22 ++++++------- tools/e2e/zone-filter.ts | 6 ++-- tools/e2e/zones.mjs | 12 +++---- verify-local.config.mjs | 6 +++- 12 files changed, 76 insertions(+), 52 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0daaf0065..493c8b2cf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -163,7 +163,7 @@ Read the installed skill/topic, reuse guarded runners/fixtures and keep provider `verify:pr` runs the tagged smoke journeys on a Dreamer app diff and the named parcours for the zones that diff touches (`npm run test:e2e:smoke`, `npm run test:e2e:parcours`), locally, without GitHub Actions, and without a -model unless `AI_GATEWAY_API_KEY` is set: the decision model then judges the +model unless `OPENAI_API_KEY` is set: the decision model then judges the parcours the zones leave out ([details](doc_web_interne/docs/repository-operations.md)). A docs-only diff, or a diff with no web app zone, skips both. A native-only diff skips the web gate. If a zone is touched and Node 24.22.1, the e2e diff --git a/doc_web_interne/docs/repository-operations.md b/doc_web_interne/docs/repository-operations.md index 727844969..9870560f8 100644 --- a/doc_web_interne/docs/repository-operations.md +++ b/doc_web_interne/docs/repository-operations.md @@ -93,20 +93,21 @@ both. A native-only diff exits 0. If a zone is touched and Node 24.22.1, is incomplete, not passed. Rerun: `npm run test:e2e:parcours` and `npm run test:e2e:smoke`. -Optional decision model: with a Vercel AI Gateway key in `AI_GATEWAY_API_KEY`, -`parcours-touches` also asks the TesterArmy decision filter (Jev, pinned in -`tools/e2e/zones.mjs`, zero-data-retention routes only) about every Dreamer and -Lucid parcours the zones leave out, on any Dreamer app diff, named zone or not. -The model sees the diff and the journey files, never the working tree. A +Optional decision model: with an OpenAI key in `OPENAI_API_KEY`, +`parcours-touches` also asks the TesterArmy decision filter (OpenAI's +Decisions API, `gpt-6-luna`, named in `tools/e2e/zones.mjs`) about every +Dreamer and Lucid parcours the zones leave out, on any Dreamer app diff, named +zone or not. The model sees the committed diff and the journey files; a file +only the working tree changes reaches it by name alone. A parcours runs unless the model rates it under 20% likely affected; the zones stay the floor, smoke and bug-bash tests keep their own checks, and a parcours the model cannot judge runs. A lockfile or e2e config change makes it keep every parcours. If the model cannot answer at all (no route, rejected key), the zones decide alone and the run's filter note says so. The first verdict for a commit is kept under `.git/verify-cache/e2e-decision/`, so `e2e list` and -`e2e run` select the same tests and a rerun asks nothing. Without the key the -gate is unchanged. Cost: about $0.04 per million tokens (one call is a few -thousand to a few tens of thousands of tokens). +`e2e run` select the same tests and a rerun asks nothing. The proof records +whether the model was on, so a pass without the key is not reused once it is +set. Without the key the gate is unchanged. Before an app release, run `npm run test:bugbash:prerelease` on Dreamer web in mock mode (the script refuses a production Supabase ref). Each confirmed bug diff --git a/scripts/README.md b/scripts/README.md index 84b6445ba..3dd6bdf5f 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -16,7 +16,7 @@ connects these commands to implementation paths and current runbooks. | SEO | `seo:gsc:export`, `seo:backlinks:check` | GSC export writes a dated external-data report; backlink check fetches the tracked public referring pages but never rewrites the CSV. | | Web E2E | `test:e2e:web`, `test:e2e:web:report` | TesterArmy and its pinned Chromium; simulated services. See [the E2E guide](../e2e/README.md). | | Backend E2E | `test:e2e:backend`, `start:backend-e2e` | Disposable local backend on the native Supabase runtime (no Docker) and browser artifacts; `test:e2e:backend -- --qualify-ti528` adds the six TI528 integration cases to the nine backend scenarios. Linux amd64/arm64 with glibc 2.35+ or macOS 14+ on Apple silicon (`node scripts/check-native-supabase-runtime.cjs`). See [backend qualification](../doc_web_interne/docs/e2e-backend-qualification.md). | -| TesterArmy E2E | `test:testerarmy*`, `test:e2e:parcours`, `test:e2e:smoke`, `test:bugbash:prerelease`, `test:bugbash:repros`, `agent-device:*` | TesterArmy on web, an owned emulator or a named iOS Simulator; native runs need an identified Release build (`build`) and an explicit `E2E_DEVICE`, and take the device lock. `test:e2e:parcours` and `test:e2e:smoke` are the local PR gates (no model, except the optional decision model of `test:e2e:parcours` when `AI_GATEWAY_API_KEY` is set). `test:bugbash:prerelease` is the mock-mode explore before an app release; `test:bugbash:repros` is the release check. See [the TesterArmy guide](../tools/e2e/README.md). Maestro and its `test:e2e:*` Android commands were retired on 2026-10-14. | +| TesterArmy E2E | `test:testerarmy*`, `test:e2e:parcours`, `test:e2e:smoke`, `test:bugbash:prerelease`, `test:bugbash:repros`, `agent-device:*` | TesterArmy on web, an owned emulator or a named iOS Simulator; native runs need an identified Release build (`build`) and an explicit `E2E_DEVICE`, and take the device lock. `test:e2e:parcours` and `test:e2e:smoke` are the local PR gates (no model, except the optional decision model of `test:e2e:parcours` when `OPENAI_API_KEY` is set). `test:bugbash:prerelease` is the mock-mode explore before an app release; `test:bugbash:repros` is the release check. See [the TesterArmy guide](../tools/e2e/README.md). Maestro and its `test:e2e:*` Android commands were retired on 2026-10-14. | | Mobile release | `release:*` | `prepare` writes manifests; `versions:sync` writes local mirrors; `build` starts a remote EAS build and requires explicit authorization. See [the release guide](../doc_web_interne/docs/MOBILE_VERSIONING.md). | | Android release | `android:gates:*`, `android:release:local`, `build:apk:*` | May require ADB, a physical device, EAS credentials, or local build tooling. `android:gates:strict` requires a qualified TesterArmy run of the `production-apk` candidate under `tools/e2e/.e2e/dreamer-android/` (same commit as the release and its build, clean tree, intact manifest, candidate APK in `QA_ANDROID_RELEASE_APK`, stable and clean source snapshots). The real voice check is an optional manual test (owner decision 2026-10-17). | | Subscriptions | `subscription:qa:*` | Some commands update local QA evidence; see the RevenueCat runbook before use. | diff --git a/tools/e2e/README.md b/tools/e2e/README.md index 928ac35a6..c83908fa1 100644 --- a/tools/e2e/README.md +++ b/tools/e2e/README.md @@ -598,7 +598,7 @@ Agent goals can be added with an authorized model provider, one goal per call and exact critical-outcome assertions. No provider is configured by default. This package pins `@e2e-dev/decision` for one use only: the optional decision filter of the PR parcours gate (`zones.mjs`, `decision-verdict.mjs`, installed -`docs/filters.mdx`), which stays off until `AI_GATEWAY_API_KEY` is set. Its +`docs/filters.mdx`, OpenAI `gpt-6-luna`), which stays off until `OPENAI_API_KEY` is set. Its `decisionExecutor` for `agent.act` is not configured; exact journeys require no model dependency. Use a provider barrier when replay must never call a model; strict cache alone diff --git a/tools/e2e/decision-verdict.mjs b/tools/e2e/decision-verdict.mjs index 73be0f319..35c1e85c5 100644 --- a/tools/e2e/decision-verdict.mjs +++ b/tools/e2e/decision-verdict.mjs @@ -1,7 +1,7 @@ /** * The decision model's verdict on the parcours the zones leave out, through - * the TesterArmy Filters API (`@e2e-dev/decision`, Jev on the Vercel AI - * Gateway). run.mjs calls the filters twice, `e2e list` then `e2e run`, and + * the TesterArmy Filters API (`@e2e-dev/decision`, OpenAI's Decisions API). + * run.mjs calls the filters twice, `e2e list` then `e2e run`, and * checks that the run selected exactly what the list did, so the first answer * for a commit and a test set is kept in the clone's git directory and reused. * A rerun of verify:pr on the same commit asks nothing either. A failure is @@ -44,12 +44,9 @@ function keep(file, value) { } async function loadDecisionFilter() { - const [{ decisionFilter }, { gateway }] = await Promise.all([import('@e2e-dev/decision'), import('ai')]); - return decisionFilter({ - model: gateway.decisionModel(DECISION_MODEL), - // Only routes that keep nothing: the diff and the journeys leave the machine. - providerOptions: { gateway: { zeroDataRetention: true } }, - }); + const [{ decisionFilter }, { openai }] = await Promise.all([import('@e2e-dev/decision'), import('@ai-sdk/openai')]); + // Reads OPENAI_API_KEY. The diff and the journey files go to OpenAI's API. + return decisionFilter({ model: openai.decisionModel(DECISION_MODEL) }); } /** diff --git a/tools/e2e/decision-verdict.test.mjs b/tools/e2e/decision-verdict.test.mjs index 8f527643f..1f34bad1a 100644 --- a/tools/e2e/decision-verdict.test.mjs +++ b/tools/e2e/decision-verdict.test.mjs @@ -43,7 +43,7 @@ function context(root, base) { /** An offline decision model: the moon journey is likely affected, the billing one is not. */ function fakeModel(calls, fail = false) { return { - specificationVersion: 'v4', provider: 'fake', modelId: 'fake-jev', supportedQuestionTypes: ['boolean'], + specificationVersion: 'v4', provider: 'fake', modelId: 'fake-decisions', supportedQuestionTypes: ['boolean'], async doDecide({ questions }) { calls.push(Object.keys(questions).length); if (fail) throw new Error('401 invalid key'); @@ -111,9 +111,9 @@ test('an interrupted run keeps no failure', async () => { }); test('a new commit, base, change or model is a new verdict', () => { - const input = { model: 'typesafe-ai/jev-1.14.0', base: 'a', head: 'b', files: ['x', 'y'], tests: ['t1', 't2'] }; + const input = { model: 'gpt-6-luna', base: 'a', head: 'b', files: ['x', 'y'], tests: ['t1', 't2'] }; const key = verdictKey(input); assert.equal(verdictKey({ ...input, files: ['y', 'x'], tests: ['t2', 't1'] }), key); - for (const change of [{ head: 'c' }, { base: 'c' }, { files: ['x'] }, { tests: ['t1'] }, { model: 'typesafe-ai/jev' }]) + for (const change of [{ head: 'c' }, { base: 'c' }, { files: ['x'] }, { tests: ['t1'] }, { model: 'gpt-6-sol' }]) assert.notEqual(verdictKey({ ...input, ...change }), key, JSON.stringify(change)); }); diff --git a/tools/e2e/pr-gate.mjs b/tools/e2e/pr-gate.mjs index 219fa32c2..f1b4db1d9 100644 --- a/tools/e2e/pr-gate.mjs +++ b/tools/e2e/pr-gate.mjs @@ -1,7 +1,7 @@ /** * PR-gate launcher for Dreamer/Lucid/Meditation web journeys. - * A diff with no web app zone exits 0 without a browser, unless a Vercel AI - * Gateway key lets the decision model judge an unzoned Dreamer app diff. + * A diff with no web app zone exits 0 without a browser, unless an OpenAI + * key lets the decision model judge an unzoned Dreamer app diff. * A native-only diff does too: this gate has no emulator. When a zone is touched, a missing * pinned Node, e2e install, or Chromium exits 1. verify:pr probes the same * condition first and records the check unavailable, so the proof is @@ -30,7 +30,7 @@ export function changedJourneyProduct(file) { /** * `model`: whether the decision model judges the parcours the zones leave out - * (a Vercel AI Gateway key is set). It then sees every Dreamer app diff, named + * (an OpenAI key is set). It then sees every Dreamer app diff, named * zone or not, for Dreamer and Lucid, which run on the same app code. */ export function decideParcours(files, { model = decisionEnabled(process.env) } = {}) { @@ -48,7 +48,7 @@ export function decideParcours(files, { model = decisionEnabled(process.env) } = } return { launch: false, - reason: 'PARCOURS SAUTE: aucun parcours nomme (capture, sauvegarde, journal, paiement, connexion, lucid, meditation) dans le diff. Une PR documentation, ou un fichier applicatif sans zone quand AI_GATEWAY_API_KEY est absente, ne lance pas de navigateur.', + reason: 'PARCOURS SAUTE: aucun parcours nomme (capture, sauvegarde, journal, paiement, connexion, lucid, meditation) dans le diff. Une PR documentation, ou un fichier applicatif sans zone quand OPENAI_API_KEY est absente, ne lance pas de navigateur.', }; } return { launch: true, products: [...new Set([...zones.map(zone => zone.product), ...journeyProducts, ...modelProducts])] }; diff --git a/tools/e2e/pr-gate.test.mjs b/tools/e2e/pr-gate.test.mjs index e67edc8f7..98d10b40b 100644 --- a/tools/e2e/pr-gate.test.mjs +++ b/tools/e2e/pr-gate.test.mjs @@ -31,15 +31,37 @@ test('with the decision model, any Dreamer app diff lets it judge the Dreamer an assert.equal(decideParcours(['doc_web_interne/docs/README.md', 'AGENTS.md'], { model: true }).launch, false); assert.equal(decideParcours(['tools/e2e/tests/dreamer.mobile.e2e.ts'], { model: true }).launch, false); // The key turns it on. - const saved = process.env.AI_GATEWAY_API_KEY; + const saved = process.env.OPENAI_API_KEY; try { - process.env.AI_GATEWAY_API_KEY = 'test-key'; + process.env.OPENAI_API_KEY = 'test-key'; assert.equal(decideParcours(['components/ui/Toast.tsx']).launch, true); - process.env.AI_GATEWAY_API_KEY = ' '; + process.env.OPENAI_API_KEY = ' '; assert.equal(decideParcours(['components/ui/Toast.tsx']).launch, false); } finally { - if (saved === undefined) delete process.env.AI_GATEWAY_API_KEY; - else process.env.AI_GATEWAY_API_KEY = saved; + if (saved === undefined) delete process.env.OPENAI_API_KEY; + else process.env.OPENAI_API_KEY = saved; + } +}); + +test('a parcours proof made without the key is not reused once the key turns the model on', async () => { + const { decisionEnabled } = await import('./zones.mjs'); + const saved = process.env.OPENAI_API_KEY; + const envOf = async (key, tag) => { + if (key === undefined) delete process.env.OPENAI_API_KEY; + else process.env.OPENAI_API_KEY = key; + // A fresh module instance reads the environment again. + const { default: config } = await import(`${new URL('../../verify-local.config.mjs', import.meta.url).href}?${tag}`); + return config.checks.find(check => check.name === 'parcours-touches').env; + }; + try { + for (const [key, tag] of [[undefined, 'none'], [' ', 'blank'], ['sk-test', 'set']]) { + const env = await envOf(key, tag); + assert.deepEqual(env, { E2E_DECISION_FILTER: decisionEnabled({ OPENAI_API_KEY: key }) ? 'on' : 'off' }, tag); + assert.equal(JSON.stringify(env).includes('sk-test'), false); + } + } finally { + if (saved === undefined) delete process.env.OPENAI_API_KEY; + else process.env.OPENAI_API_KEY = saved; } }); diff --git a/tools/e2e/zone-filter.test.mjs b/tools/e2e/zone-filter.test.mjs index 4b52d50e0..a9035508e 100644 --- a/tools/e2e/zone-filter.test.mjs +++ b/tools/e2e/zone-filter.test.mjs @@ -114,14 +114,14 @@ test('the decision model only takes back parcours the zones left out as untouche assert.equal(widened.note, 'journal; modele : 2 parcours hors zone repris; 1 call, 9.1k tokens, $0.0004'); }); -test('the decision model is off without a gateway key and pinned to an exact Jev', () => { - assert.equal(DECISION_KEY_ENV, 'AI_GATEWAY_API_KEY'); +test('the decision model is off without an OpenAI key and is OpenAI\'s decision model', () => { + assert.equal(DECISION_KEY_ENV, 'OPENAI_API_KEY'); assert.equal(decisionEnabled({}), false); - assert.equal(decisionEnabled({ AI_GATEWAY_API_KEY: ' ' }), false); - assert.equal(decisionEnabled({ AI_GATEWAY_API_KEY: 'vck_test' }), true); - assert.match(DECISION_MODEL, /^typesafe-ai\/jev-\d+\.\d+\.\d+$/); + assert.equal(decisionEnabled({ OPENAI_API_KEY: ' ' }), false); + assert.equal(decisionEnabled({ OPENAI_API_KEY: 'sk-test' }), true); + assert.equal(DECISION_MODEL, 'gpt-6-luna'); const source = readFileSync(new URL('./decision-verdict.mjs', import.meta.url), 'utf8'); - assert.match(source, /zeroDataRetention: true/); + assert.match(source, /openai\.decisionModel\(DECISION_MODEL\)/); }); test('the zone filter keeps the zones when the model is off or cannot answer', async () => { @@ -135,20 +135,20 @@ test('the zone filter keeps the zones when the model is off or cannot answer', a projectRoot: `${root}/tools/e2e`, changes: { base: 'base', root, files: ['app/journal/[id].tsx'] }, signal: new AbortController().signal, log() {}, redact: text => text, }; - const saved = process.env.AI_GATEWAY_API_KEY; + const saved = process.env.OPENAI_API_KEY; try { - delete process.env.AI_GATEWAY_API_KEY; + delete process.env.OPENAI_API_KEY; assert.deepEqual(await parcoursTouches.filter(candidates, context), { exclude: { home: UNTOUCHED }, note: 'journal' }); // With a key, a model that cannot even start (here: no repository) leaves the zones' answer, and says so. - process.env.AI_GATEWAY_API_KEY = 'vck_test'; + process.env.OPENAI_API_KEY = 'sk-test'; const fallback = await parcoursTouches.filter(candidates, context); assert.deepEqual(fallback.exclude, { home: UNTOUCHED }); assert.match(fallback.note, /^journal; modele indisponible \(.+\), zones seules$/); // Nothing left out as untouched: nothing to ask. assert.deepEqual(await parcoursTouches.filter(candidates.slice(0, 1), context), { exclude: {}, note: 'journal' }); } finally { - if (saved === undefined) delete process.env.AI_GATEWAY_API_KEY; - else process.env.AI_GATEWAY_API_KEY = saved; + if (saved === undefined) delete process.env.OPENAI_API_KEY; + else process.env.OPENAI_API_KEY = saved; } }); diff --git a/tools/e2e/zone-filter.ts b/tools/e2e/zone-filter.ts index 2637fa17c..6f25c86f0 100644 --- a/tools/e2e/zone-filter.ts +++ b/tools/e2e/zone-filter.ts @@ -13,9 +13,9 @@ function repoPath(gitRoot: string, projectRoot: string, file: string): string { /** * Inactive unless the run passed `--changed-since` (e2e only then fills * `context.changes`). A full campaign or `verify:release` therefore keeps - * every test. The zones need no model and no network. With a Vercel AI - * Gateway key, the decision model then judges the parcours the zones leave - * out; if it cannot answer, the zones alone decide, and the note says so. + * every test. The zones need no model and no network. With an OpenAI key, + * the decision model then judges the parcours the zones leave out; if it + * cannot answer, the zones alone decide, and the note says so. */ export const parcoursTouches: TestFilter = { name: 'parcours-touches', diff --git a/tools/e2e/zones.mjs b/tools/e2e/zones.mjs index 9a949d353..c501bd3f4 100644 --- a/tools/e2e/zones.mjs +++ b/tools/e2e/zones.mjs @@ -12,13 +12,13 @@ export const BUGBASH_TAG = 'bugbash'; export const UNTOUCHED = 'le diff ne touche pas ce parcours'; /** - * Optional decision model (the TesterArmy Filters API with Jev). It judges only - * the parcours the zones leave out, so the zones stay the floor. It needs a - * Vercel AI Gateway key in the environment; without one the gate is the zones - * alone, as before. This exact Jev pin is served with zero data retention. + * Optional decision model (the TesterArmy Filters API with OpenAI's Decisions + * API). It judges only the parcours the zones leave out, so the zones stay the + * floor. It needs an OpenAI key in the environment; without one the gate is + * the zones alone, as before. */ -export const DECISION_KEY_ENV = 'AI_GATEWAY_API_KEY'; -export const DECISION_MODEL = 'typesafe-ai/jev-1.14.0'; +export const DECISION_KEY_ENV = 'OPENAI_API_KEY'; +export const DECISION_MODEL = 'gpt-6-luna'; /** Products whose journeys the model judges when a shared Dreamer path changes: Lucid runs on the same app code. */ export const DECISION_PRODUCTS = ['dreamer', 'lucid']; diff --git a/verify-local.config.mjs b/verify-local.config.mjs index 56d23f314..91c27690b 100644 --- a/verify-local.config.mjs +++ b/verify-local.config.mjs @@ -610,7 +610,7 @@ export default { { name: 'mobile-versions', command: 'node scripts/mobile-release.js verify --app all', inputs: MOBILE_VERSIONS, when: MOBILE_VERSIONS }, { name: 'meditation', command: MEDITATION_CHECKS, when: MEDITATION, releaseAlways: true, requires: MEDITATION_DEPS }, { name: 'edge-functions', command: EDGE_CHECKS, when: EDGE, releaseAlways: true, specialised: true, requires: DENO }, - // Web only, no Actions. No model unless AI_GATEWAY_API_KEY is set: the + // Web only, no Actions. No model unless OPENAI_API_KEY is set: the // decision model then judges the parcours the zones leave out (zones.mjs). // A diff with no web zone exits 0, or with the key, no Dreamer app path. // A touched zone without Node 24.22.1, tools/e2e/node_modules or Chromium @@ -620,6 +620,10 @@ export default { { name: 'parcours-touches', command: 'node --test tools/e2e/zone-filter.test.mjs tools/e2e/decision-verdict.test.mjs tools/e2e/pr-gate.test.mjs tools/e2e/bugbash-prerelease.test.mjs && npm run test:e2e:parcours', + // Part of the proof's fingerprint: a pass without the key is not reused once + // the key turns the model on, or back. Records on/off, never the key + // (DECISION_KEY_ENV and decisionEnabled in tools/e2e/zones.mjs). + env: { E2E_DECISION_FILTER: process.env.OPENAI_API_KEY?.trim() ? 'on' : 'off' }, when: PARCOURS_WHEN, specialised: true, requires: {