diff --git a/README.md b/README.md index af4c277e9b90..6d49f02f9575 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ +# First Minute + +Play the on-call engineer for 60 seconds. Inspect a checkout outage, submit a diagnosis, then adjust the connection pool to see how it affects the queue. This hackathon entry uses Flagsmith to test whether a three-step runbook improves first-attempt diagnoses. + +[Download the offline drill](https://raw.githubusercontent.com/arpitkjaiswal/flagsmith1/main/examples/first-minute/media/first-minute.zip) · [Watch the walkthrough](examples/first-minute/media/walkthrough.mp4) · [See the Flagsmith results](examples/first-minute/media/flagsmith-results.png) · [Run the live experiment](examples/first-minute/README.md) + +Unzip the download and open `first-minute.html` in a browser. Practice rounds run entirely on your device. Select **Experiment replay** to inspect the synthetic results and the verified flag rollout. + [![Feature Flag, Remote Config and A/B Testing platform, Flagsmith](static-files/flagsmith-cover.png)](https://www.flagsmith.com/) [![Stars](https://img.shields.io/github/stars/flagsmith/flagsmith)](https://github.com/Flagsmith/flagsmith/stargazers) diff --git a/examples/first-minute/.env.example b/examples/first-minute/.env.example new file mode 100644 index 000000000000..13db1de09c19 --- /dev/null +++ b/examples/first-minute/.env.example @@ -0,0 +1,6 @@ +# Client-side environment key for the project containing the triage_guide flag. +VITE_FLAGSMITH_ENVIRONMENT_ID= +# Optional API origin for self-hosted deployments. Local Vite uses its SDK proxy. +VITE_FLAGSMITH_ORIGIN= +# Optional management dashboard link shown in the connected build. +VITE_FLAGSMITH_DASHBOARD_URL= diff --git a/examples/first-minute/.gitignore b/examples/first-minute/.gitignore new file mode 100644 index 000000000000..b93349c4fbc6 --- /dev/null +++ b/examples/first-minute/.gitignore @@ -0,0 +1,6 @@ +node_modules/ +dist/ +.env* +!.env.example +test-results/ +playwright-report/ diff --git a/examples/first-minute/README.md b/examples/first-minute/README.md new file mode 100644 index 000000000000..a3f97c1d1788 --- /dev/null +++ b/examples/first-minute/README.md @@ -0,0 +1,62 @@ +# First Minute + +A 60-second incident drill that tests whether a short runbook helps people diagnose a checkout outage. Participants inspect a release log, service metrics and request traces, choose one diagnosis, and see where the slow request spent its time. + +![Checkout incident briefing](media/first-minute.png) + +[Watch the 38-second captioned walkthrough](media/walkthrough.mp4) + +## Play + +For a no-install practice round, [download the drill](https://raw.githubusercontent.com/arpitkjaiswal/flagsmith1/main/examples/first-minute/media/first-minute.zip), unzip it and open `first-minute.html`. The debrief includes a capacity model where you can adjust the pool size and see the resulting queue growth. + +To run from source, run `npm ci` and `npm run dev` with Node 24. Open the address Vite prints. Without a client-side environment key, the drill runs in practice mode. To make a portable, offline copy, run `npm run build:practice` and open `dist/first-minute.html`. Finish a round and choose **Try the other desk** to compare the layouts. + +To rebuild the ZIP distributed on GitHub, run `npm run package:practice` with Node 24 and Python 3 installed. + +## Run the experiment locally + +1. From the repository root, run `docker compose up -d`. Open `http://localhost:8000`, sign in and create an organisation if this is a fresh install. The supplied Compose file enables Experimentation and stores SDK events in PostgreSQL. +2. From `examples/first-minute`, run `python3 setup_experiment.py` in a terminal. Sign in with your local Flagsmith email and password. If your account belongs to several organisations, the script lists their names and IDs so you can rerun it with the chosen ID. It creates or reuses the First Minute project, Participant drill environment, warehouse connection, flag, metric and experiment. Copy the two printed `VITE_` lines into `.env.local`. For unattended setup, provide your local user token in `FLAGSMITH_MANAGEMENT_TOKEN` and run `python3 setup_experiment.py ORGANISATION_ID`. +3. Start or restart Vite. Its local SDK proxy forwards flags, identities and events to Flagsmith on port 8000. The briefing should say **Connected to Flagsmith**. Start the drill to enrol. For a shared deployment, set `VITE_FLAGSMITH_ORIGIN` to the HTTPS origin serving the Flagsmith API and SDK events. Set `VITE_FLAGSMITH_DASHBOARD_URL` to the address where your team signs in to view that experiment. Run `npm run build` and serve `dist` over HTTPS. +4. Open **Experiments** in the Participant drill environment and refresh the results after events arrive. The guide is a keyed variation of the `triage_guide` multivariate flag. All eligible identities enter the experiment, with equal allocation between control and guided. + +If the self-hosted dashboard shows **Maintenance** because its bootstrap request is blocked, configure `FLAGSMITH_ON_FLAGSMITH_API_URL` and `FLAGSMITH_ON_FLAGSMITH_API_KEY` on the web service to read from a local dashboard configuration environment, then restart the service. [Self-hosting guide](../../docs/docs/deployment-self-hosting/core-configuration/running-flagsmith-on-flagsmith.md) + +## What the experiment measures + +**Hypothesis.** A three-step runbook increases the fraction of first-time participants who correctly diagnose connection-pool exhaustion within 60 seconds. Both variants use identical evidence, answer choices, time limit and feedback. + +**Measurement.** The browser stores an anonymous identity, the assigned desk and the first attempt's deadline. Opening the desk records an SDK exposure. Only a correct first answer before expiry records the `drill_resolved` occurrence event. A returning player resumes the same desk and deadline directly from the browser. Tabs sharing the same browser identity share one first answer. New players can practise if Flagsmith takes more than four seconds to assign a desk. Practice and replays are excluded from the experiment. A new browser profile is a new identity. + +**Evidence.** The [browser smoke-test snapshot](verification.json) recorded three exposures and two conversions. The in-app **Experiment replay** follows a larger synthetic run through assignment, measurement and rollout. Both runs used the real Flagsmith SDK and a local Flagsmith instance. + +**Rollout.** Collect independent participant attempts and inspect sample-ratio warnings. Flagsmith shows “Collecting data” below its inference thresholds. Once sufficient evidence supports a decision, end the participant experiment and use the same flag to roll out the selected desk. If the evidence stays inconclusive, continue collecting data. + +## Replay the Flagsmith experiment + +Open **Experiment replay** in the drill. Assignment shows how the multivariate flag split 240 simulated identities. Results compares 83 conversions from 114 guided attempts with 54 from 126 standard attempts. The script programmed a 72% success chance for guided and 45% for standard. Flagsmith calculated the conversion rates, relative lift and win probability for this synthetic sample. Human outcomes are measured in the **Participant drill** environment. + +Rollout shows what happened after the synthetic experiment closed. The same `triage_guide` flag was set to 100% guided in **Synthetic rollout rehearsal**. All 16 post-rollout SDK checks received the guided desk outside the experiment. The replay and its downloadable data work offline. + +![Completed synthetic experiment in the native Flagsmith dashboard](media/flagsmith-results.png) + +To reproduce the capture, run the following from this directory against the local Flagsmith instance. It accepts the same sign-in and optional organisation ID as the participant setup. + +```sh +python3 rehearse.py +``` + +This command provisions the dedicated rehearsal environment. It sends seeded traffic through the JavaScript SDK, waits for the warehouse counts to match, and uses the Flagsmith results to select a desk. Results refreshes respect the server's five-minute cooldown. The script pauses enrolment before closing the rehearsal and updating the environment default. Each run against a completed rehearsal verifies the rollout with 16 fresh identities. The JSON contains aggregate evidence only. The allocation check uses an exact two-sided binomial test against 50/50 when Flagsmith leaves its sample-ratio statistic empty. + +The [captured JSON](rehearsal.json) drives the replay. To replace it after your own successful run, save the command output to a temporary file, then move it to `rehearsal.json`. The dashboard capture is a separate image taken from the original run shown here. + +## Browser checks + +Run `npx playwright install chromium` once, then `npm test`. To use an existing Chromium installation, set `CHROMIUM_EXECUTABLE` to its path. The browser tests intercept SDK traffic locally and cover simultaneous submissions, interrupted connections, keyboard navigation, timeouts and practice exclusions. The rehearsal command above exercises the real API and warehouse. + +With pytest installed, run `python3 -m pytest tests/test_rehearsal.py` to check recovery when Flagsmith asks the rehearsal to wait before refreshing results. + +## Submission copy + +When checkout slows down, a responder often has a dashboard full of signals and has to work out what changed. First Minute lets anyone take the on-call seat. Players have 60 seconds to trace a slowdown through a release, service metrics and a slow request. Flagsmith assigns a plain desk or a three-step runbook and measures whether the player finds the root cause on their first attempt. The result helps the team decide whether every new responder should get the guide. diff --git a/examples/first-minute/attempt-store.js b/examples/first-minute/attempt-store.js new file mode 100644 index 000000000000..729bb7cc4fb0 --- /dev/null +++ b/examples/first-minute/attempt-store.js @@ -0,0 +1,45 @@ +// IndexedDB serialises read/write transactions across tabs. A first answer can +// therefore claim the conversion even when two windows submit at the same time. +let connection; +function openDatabase() { + if (!connection) { + connection = new Promise((resolve, reject) => { + const request = indexedDB.open('first-minute', 1); + request.onupgradeneeded = () => request.result.createObjectStore('rounds'); + request.onsuccess = () => resolve(request.result); + request.onerror = () => reject(request.error); + }); + } + return connection; +} + +function readLegacy(key, parse) { + try { + const value = localStorage.getItem(key); + return value === null ? undefined : parse(value); + } catch { + return undefined; + } +} + +export async function updateRecord(key, change, parseLegacy = JSON.parse) { + const database = await openDatabase(); + return new Promise((resolve, reject) => { + const transaction = database.transaction('rounds', 'readwrite'); + const store = transaction.objectStore('rounds'); + const read = store.get(key); + let next; + let failure; + transaction.oncomplete = () => resolve(next); + transaction.onabort = () => reject(failure || transaction.error); + read.onsuccess = () => { + try { + next = change(read.result ?? readLegacy(key, parseLegacy)); + if (next !== undefined && next !== read.result) store.put(next, key); + } catch (error) { + failure = error; + transaction.abort(); + } + }; + }); +} diff --git a/examples/first-minute/build-practice.js b/examples/first-minute/build-practice.js new file mode 100644 index 000000000000..6831457b8b1c --- /dev/null +++ b/examples/first-minute/build-practice.js @@ -0,0 +1,16 @@ +import { build } from 'vite'; +import { mkdir, writeFile } from 'node:fs/promises'; + +// Package the practice desk for judges who want to open it directly from a file. +const bundle = await build({ mode: 'practice', build: { write: false } }); +const html = bundle.output.find((file) => file.fileName === 'index.html').source; +const script = bundle.output.find((file) => file.type === 'chunk' && file.isEntry).code; +const css = bundle.output.find((file) => file.fileName.endsWith('.css')).source; +const document = html + .replace( + /', + ) + .replace(/]*>/, () => ''); +await mkdir('dist', { recursive: true }); +await writeFile('dist/first-minute.html', document); diff --git a/examples/first-minute/experiment-replay.js b/examples/first-minute/experiment-replay.js new file mode 100644 index 000000000000..9f5bc9c8a859 --- /dev/null +++ b/examples/first-minute/experiment-replay.js @@ -0,0 +1,88 @@ +import report from './rehearsal.json'; +import dashboardCapture from './media/flagsmith-results.png?inline'; + +const $ = (id) => document.getElementById(id); +const labels = { control: 'Standard desk', guided: 'Guided desk' }; +const { control, guided } = report.variants; +const enrolled = control.exposed + guided.exposed; +const percent = new Intl.NumberFormat('en-GB', { style: 'percent', maximumFractionDigits: 1 }); +const signed = new Intl.NumberFormat('en-GB', { signDisplay: 'exceptZero', maximumFractionDigits: 1 }); +const rate = (desk) => desk.converted / desk.exposed; + +$( + 'replay-source', +).textContent = `Flagsmith measured ${enrolled} synthetic attempts. The rehearsal programmed a ${percent.format( + report.simulated_success_rates.control, +)} success chance for the standard desk and ${percent.format(report.simulated_success_rates.guided)} for guided.`; + +$( + 'allocation-description', +).textContent = `The ${report.flag} flag allocated ${report.configured_split.control}% of traffic to standard and ${report.configured_split.guided}% to guided. Each identity kept its assigned desk.`; +$('split-standard').style.width = (100 * control.exposed) / enrolled + '%'; +$('assigned-control').textContent = control.exposed + ' standard'; +$('assigned-guided').textContent = guided.exposed + ' guided'; + +for (const key of ['control', 'guided']) { + const row = report.variants[key]; + const group = document.createElement('div'); + group.className = 'rate-row ' + key; + const title = document.createElement('strong'); + title.textContent = labels[key]; + const count = document.createElement('span'); + count.textContent = `${row.converted} of ${row.exposed} · ${percent.format(rate(row))}`; + const track = document.createElement('div'); + track.className = 'rate-track'; + track.setAttribute('aria-hidden', 'true'); + const fill = document.createElement('span'); + fill.style.width = 100 * rate(row) + '%'; + track.append(fill); + group.append(title, count, track); + $('result-bars').append(group); +} + +const inference = report.guided_inference; +$('difference').textContent = signed.format(100 * (rate(guided) - rate(control))) + ' pp'; +$('win-chance').textContent = + inference.chance_to_win > 0.999 && inference.chance_to_win < 1 ? '>99.9%' : percent.format(inference.chance_to_win); +$('stat-detail').textContent = `Relative lift ${signed.format( + 100 * inference.lift, +)}% (95% credible interval ${signed.format(100 * inference.ci_low)}% to ${signed.format(100 * inference.ci_high)}%). ${ + report.allocation_check.method +}, p = ${report.allocation_check.p_value.toFixed(3)}.`; +const shipped = report.rollout; +$('rollout-checks').textContent = `${shipped.new_identities_verified} / ${shipped.new_identities_verified}`; +$('rollout-description').textContent = `After the rehearsal closed, the same flag was set to serve the ${labels[ + shipped.desk +].toLowerCase()} to ${shipped.percentage}% of users in that environment. All ${ + shipped.new_identities_verified +} fresh test identities received that desk outside the experiment.`; + +const date = new Date(report.as_of); +$('replay-date').dateTime = report.as_of; +$('replay-date').textContent = + 'Captured ' + new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium', timeZone: 'UTC' }).format(date); +$('download-results').href = + 'data:application/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(report, null, 2) + '\n'); + +$('dashboard-capture').src = dashboardCapture; +const liveDashboard = import.meta.env.MODE !== 'practice' && import.meta.env.VITE_FLAGSMITH_DASHBOARD_URL; +if (liveDashboard) { + $('participant-dashboard').href = liveDashboard; + $('participant-dashboard').hidden = false; +} + +const steps = document.querySelectorAll('.replay-stages button'); +function selectStage(stage) { + for (const step of steps) { + const panel = step.getAttribute('aria-controls'); + step.setAttribute('aria-pressed', String(panel === stage)); + $(panel).hidden = panel !== stage; + } +} +for (const step of steps) step.onclick = () => selectStage(step.getAttribute('aria-controls')); +function openResults() { + selectStage('measurement'); + $('notes').showModal(); +} +$('method').onclick = openResults; +$('show-experiment').onclick = openResults; diff --git a/examples/first-minute/index.html b/examples/first-minute/index.html new file mode 100644 index 000000000000..c28653becc09 --- /dev/null +++ b/examples/first-minute/index.html @@ -0,0 +1,193 @@ + + + + + + + First Minute · Incident drill + + + +
+
+ First Minute +
+
+
+
+
+
ON-CALL SIMULATOR
+

Checkout is
timing out.

+

A release just landed. Payment requests are piling up. You have one minute to find the cause.

+ Loading drill… +
+
+
+ INCIDENT TELEMETRYSIMULATION +
+
+ 2.84sp95 checkout latency
↑ 1,191% from baseline
+
+ +
14:0014:04 · RELEASE14:08 UTC
+
+
+ + +
+
DRILL BRIEFING
+
+
+ Duration +

60 seconds

+

The clock begins when you enter the incident desk.

+
+
+ Evidence +

Three sources

+

Read the release log, service metrics and request traces.

+
+
+ Objective +

One diagnosis

+

Choose the change that explains the symptoms.

+
+
+
+
+ +
+
FLAGSMITH EXPERIMENT REPLAY
+

Does a runbook help?

+

+
+ + + +
+ +
+

First-attempt resolution

+

A conversion records one correct diagnosis within 60 seconds. Practice replays are excluded.

+
+
+
Difference in success rate
+
Chance guided beats standard
+
+
+ Statistical details +

+
+
+ +
+ View original Flagsmith dashboard capture + Completed Flagsmith rehearsal showing the hypothesis, enrollment, results and credible interval. +
+ +
+ Download result JSON +
+
+ + + + diff --git a/examples/first-minute/main.js b/examples/first-minute/main.js new file mode 100644 index 000000000000..fdb1dcb01e5c --- /dev/null +++ b/examples/first-minute/main.js @@ -0,0 +1,312 @@ +import './experiment-replay.js'; +import { updateRecord } from './attempt-store.js'; +import flagsmith from '@flagsmith/flagsmith'; + +const $ = (id) => document.getElementById(id); +const evidence = { + 'Release log': [ + ['13:58', 'Release 8.3 healthy. Checkout p95 is 220 ms.'], + ['14:04', 'Release 8.4 rolled out. Checkout database pool limit changed from 40 to 4 connections per worker.'], + ['14:06', 'No changes to routing, request limits or the payment provider.'], + ], + Metrics: [ + ['Demand', 'Checkout traffic holds at 97–101 requests per second throughout the release.'], + ['Database', 'Query execution p95 holds at 17 ms. All four pool connections are busy.'], + ['Queue', 'Connection acquisition p95 rises from 8 ms to 2.61 s.'], + ], + Traces: [ + ['14:02', 'POST /checkout · 208 ms total · 7 ms waiting for a connection.'], + ['14:07', 'POST /checkout · 2,866 ms total · 2,650 ms waiting for a connection.'], + ['Payment', 'Provider authorisation takes 104 ms before the release and 108 ms after.'], + ], +}; +const answers = [ + ['provider', 'The external payment provider slowed down.'], + ['pool', 'The release reduced the database connection pool.'], + ['traffic', 'An unexpected traffic spike overwhelmed checkout.'], +]; +const flagName = 'triage_guide'; +const identityKey = 'first-minute.participant.v1'; +const experimentKey = import.meta.env.MODE === 'practice' ? '' : import.meta.env.VITE_FLAGSMITH_ENVIRONMENT_ID; +const attemptKey = 'first-minute.first-attempt.v1.' + (experimentKey || 'practice'); +const flagLookupTimeoutMs = 4000; +let connected = false; +let active; +let interval; +let lastLayout = 'control'; +let saved = null; + +let starting = false; +const updates = experimentKey && typeof BroadcastChannel === 'function' ? new BroadcastChannel(attemptKey) : null; + +function drawChart() { + const canvas = $('chart'); + const width = canvas.clientWidth; + const height = canvas.clientHeight; + const scale = window.devicePixelRatio || 1; + canvas.width = width * scale; + canvas.height = height * scale; + const ctx = canvas.getContext('2d'); + ctx.scale(scale, scale); + ctx.strokeStyle = '#36504a'; + ctx.lineWidth = 1; + ctx.beginPath(); + for (let i = 0; i <= 8; i++) { + ctx.moveTo((width * i) / 8, 0); + ctx.lineTo((width * i) / 8, height); + } + for (let i = 0; i <= 4; i++) { + ctx.moveTo(0, (i * height) / 4); + ctx.lineTo(width, (i * height) / 4); + } + ctx.stroke(); + const samples = [ + 9, 10, 9, 12, 10, 12, 9, 10, 13, 10, 12, 10, 11, 10, 14, 11, 12, 11, 12, 20, 17, 34, 25, 48, 39, 72, 44, 61, 52, + 86, 63, 78, 58, 74, 69, 82, 67, 78, 75, + ]; + ctx.beginPath(); + samples.forEach((s, i) => { + const x = (width * i) / (samples.length - 1); + const y = height * (1 - s / 100); + if (i === 0) ctx.moveTo(x, y); + else ctx.lineTo(x, y); + }); + ctx.strokeStyle = '#d1f367'; + ctx.lineWidth = 2.5; + ctx.stroke(); + ctx.lineTo(width, height); + ctx.lineTo(0, height); + ctx.closePath(); + const fill = ctx.createLinearGradient(0, 0, 0, height); + fill.addColorStop(0, '#d1f36755'); + fill.addColorStop(1, '#d1f36704'); + ctx.fillStyle = fill; + ctx.fill(); +} +new ResizeObserver(drawChart).observe($('chart')); + +function selectTab(name) { + for (const button of $('tabs').children) button.setAttribute('aria-pressed', String(button.textContent === name)); + $('signals').replaceChildren( + ...evidence[name].map(([label, message]) => { + const row = document.createElement('div'); + row.className = 'reading'; + const time = document.createElement('time'); + time.textContent = label; + row.append(time, document.createTextNode(message)); + return row; + }), + ); +} +for (const name of Object.keys(evidence)) { + const button = document.createElement('button'); + button.textContent = name; + button.onclick = () => selectTab(name); + $('tabs').append(button); +} +for (const [value, answer] of answers) { + const label = document.createElement('label'); + label.className = 'choice'; + const input = document.createElement('input'); + Object.assign(input, { type: 'radio', name: 'cause', value, required: true }); + label.append(input, document.createTextNode(' ' + answer)); + $('choices').append(label); +} +function refreshClock() { + if (!active) return; + const remaining = Math.max(0, Math.ceil((active.deadline - Date.now()) / 1000)); + $('clock').textContent = remaining + 's'; + if (remaining === 0) finish('expired'); +} + +function openDesk() { + lastLayout = active.layout; + $('preflight').hidden = true; + $('desk').hidden = false; + $('result').hidden = true; + $('guide').hidden = active.layout !== 'guided'; + $('form').reset(); + selectTab('Release log'); + $('start').disabled = true; + $('start').textContent = 'Drill in progress'; + $('mode').textContent = active.measured ? 'Experiment · first attempt' : 'Practice · excluded from experiment'; + $('desk').focus({ preventScroll: true }); + $('desk').scrollIntoView({ block: 'start' }); + refreshClock(); + if (active) interval = setInterval(refreshClock, 200); +} + +async function begin(forcePractice = false) { + if (active || starting) return; + starting = true; + try { + const candidate = { layout: lastLayout, measured: false, deadline: Date.now() + 60000 }; + if (connected && !forcePractice) { + const flag = flagsmith.getAllFlags()[flagName]; + candidate.layout = flag?.enabled && flag.value === 'guided' ? 'guided' : 'control'; + candidate.measured = Boolean(flag?.enabled && flag.experiment?.inExperiment); + if (candidate.measured) { + try { + saved = await updateRecord(attemptKey, (previous) => previous ?? candidate); + } catch { + active = { ...candidate, measured: false }; + openDesk(); + return; + } + if (saved === candidate) { + flagsmith.getExperimentFlag(flagName); + void flagsmith.flushEvents(); + } + if (saved.done) candidate.measured = false; + } + } + active = candidate.measured ? saved : candidate; + openDesk(); + } finally { + starting = false; + } +} + +function updateCapacity() { + const connections = Number($('connections').value); + const capacity = connections * 20; // One connection completes 1000 / 50 requests per second. + const balance = capacity - 100; + const outcome = + balance < 0 + ? `Queue grows by ${-balance} requests/s.` + : balance === 0 + ? 'Demand matches capacity, leaving no headroom.' + : `${balance} requests/s of spare capacity.`; + $('pool-value').value = String(connections); + $('capacity-outcome').textContent = `${capacity} requests/s capacity. ${outcome}`; +} +$('connections').oninput = updateCapacity; + +function displayResult(attempt) { + clearInterval(interval); + active = null; + lastLayout = attempt.layout; + const timedOut = attempt.answer === 'expired'; + const correct = attempt.answer === 'pool'; + const seconds = Math.min(60, Math.max(0, Math.ceil((attempt.finishedAt - attempt.deadline + 60000) / 1000))); + $('preflight').hidden = true; + $('desk').hidden = true; + $('result').hidden = false; + const heading = timedOut ? 'Time expired.' : correct ? 'Root cause found.' : 'Look at the connection queue.'; + $('verdict').textContent = heading; + $('connections').value = 4; + updateCapacity(); + $('outcome').textContent = + seconds + 's elapsed · ' + (attempt.layout === 'guided' ? 'Guided desk' : 'Standard desk'); + $('replay').onclick = () => begin(true); + $('switch-layout').onclick = () => { + lastLayout = attempt.layout === 'guided' ? 'control' : 'guided'; + begin(true); + }; + $('start').disabled = false; + $('start').textContent = 'Practise again →'; + $('start').onclick = () => begin(true); + $('mode').textContent = 'Debrief ready'; + $('result').focus(); +} + +async function finish(answer) { + if (!active) return; + const finishedAt = Date.now(); + const outcome = { ...active, done: true, finishedAt, answer: finishedAt >= active.deadline ? 'expired' : answer }; + clearInterval(interval); + active = null; + let first = outcome; + if (outcome.measured) { + try { + first = await updateRecord(attemptKey, (previous) => (previous?.done ? previous : outcome)); + } catch { + displayResult(outcome); + $('outcome').append(' · First attempt could not be saved'); + return; + } + if (first === outcome) updates?.postMessage(outcome); + saved = first; + } + displayResult(first.finishedAt ? first : outcome); + if (first === outcome && outcome.measured && outcome.answer === 'pool') { + const deliveryNote = document.createTextNode(''); + $('outcome').append(deliveryNote); + if (!connected) { + deliveryNote.textContent = ' · Event delivery unconfirmed'; + return; + } + flagsmith.trackEvent('drill_resolved'); + try { + await flagsmith.flushEvents(); + } catch { + deliveryNote.textContent = ' · Event delivery unconfirmed'; + } + } +} +if (updates) + updates.onmessage = ({ data }) => { + if (active?.measured && data.done && data.finishedAt && data.deadline === active.deadline) { + saved = data; + displayResult(data); + } + }; +$('form').onsubmit = (event) => { + event.preventDefault(); + void finish(new FormData(event.currentTarget).get('cause')); +}; + +async function connectFlagsmith(participant, attempt) { + const root = (import.meta.env.VITE_FLAGSMITH_ORIGIN || location.origin).replace(/\/+$/, ''); + await flagsmith.init({ + environmentID: experimentKey, + identity: participant, + enableEvents: true, + api: root + '/api/v1/', + eventProcessorConfig: { eventsApiUrl: root + '/api/' }, + fetch: (url, options) => + fetch(url, { ...options, signal: options?.signal ?? AbortSignal.timeout(flagLookupTimeoutMs) }), + // An exposed player already has an assignment. Restore it while enabling the SDK to send their answer. + ...(attempt && { preventFetch: true, defaultFlags: { [flagName]: { enabled: true, value: attempt.layout } } }), + }); + return Boolean(flagsmith.getAllFlags()[flagName]); +} + +async function initialise() { + $('start').disabled = true; + if (experimentKey) { + try { + const participant = await updateRecord( + identityKey, + (previous) => previous || crypto.randomUUID(), + (value) => value, + ); + saved = await updateRecord(attemptKey, (previous) => previous); + if (!saved?.done) connected = await connectFlagsmith(participant, saved); + } catch (error) { + console.warn('Experiment unavailable.', error); + } + } + $('start').onclick = () => begin(Boolean(saved)); + $('start').disabled = false; + if (saved && !saved.done) { + active = saved; + lastLayout = saved.layout; + openDesk(); + return; + } + if (saved?.done && saved.finishedAt) { + displayResult(saved); + return; + } + if (saved) { + lastLayout = saved.layout; + $('start').textContent = 'Enter practice →'; + } + $('mode').textContent = saved + ? 'First attempt complete · practice available' + : connected + ? 'Connected to Flagsmith' + : 'Practice mode · experiment offline'; +} +void initialise(); diff --git a/examples/first-minute/media/first-minute.png b/examples/first-minute/media/first-minute.png new file mode 100644 index 000000000000..330401b8b68c Binary files /dev/null and b/examples/first-minute/media/first-minute.png differ diff --git a/examples/first-minute/media/first-minute.zip b/examples/first-minute/media/first-minute.zip new file mode 100644 index 000000000000..f8bcb5aa7804 Binary files /dev/null and b/examples/first-minute/media/first-minute.zip differ diff --git a/examples/first-minute/media/flagsmith-results.png b/examples/first-minute/media/flagsmith-results.png new file mode 100644 index 000000000000..c4a681ae34d2 Binary files /dev/null and b/examples/first-minute/media/flagsmith-results.png differ diff --git a/examples/first-minute/media/walkthrough.mp4 b/examples/first-minute/media/walkthrough.mp4 new file mode 100644 index 000000000000..68ede0c7622f Binary files /dev/null and b/examples/first-minute/media/walkthrough.mp4 differ diff --git a/examples/first-minute/package-lock.json b/examples/first-minute/package-lock.json new file mode 100644 index 000000000000..3c4efe4fb306 --- /dev/null +++ b/examples/first-minute/package-lock.json @@ -0,0 +1,1174 @@ +{ + "name": "first-minute", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "first-minute", + "version": "1.0.0", + "dependencies": { + "@flagsmith/flagsmith": "^12.4.0" + }, + "devDependencies": { + "@playwright/test": "1.64.1", + "vite": "^7.2.0" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.28.2.tgz", + "integrity": "sha512-XExcO+dvLKvVtNTibSTBej1NCAbaGhWn9Ww1ZPx80qsahhPFe/8jgWP0IchNe0F3HwkU7n8ejhH8bjonqht8mQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.28.2.tgz", + "integrity": "sha512-kXXoiPVVGQcnIYGOeaovwOURpniDBpSq4A03qkQ+BMQqtGG6HYap3xne9C1O1yo4TR3qxlCX5IqqmX6fFo2Lqg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.28.2.tgz", + "integrity": "sha512-5YfKeeI8qWfBZIX+u2xZC3Zlb3Os/gLS2sbEKM+I4ZOcsWmHS2WLysCcQZDAFRslDUU5Oiq44gf6PYN1vGwG5A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.28.2.tgz", + "integrity": "sha512-O387ite7SzUyCcy3JQX4P4bLtEA7bLLkx+esve5JHnyYfNTxcVpXZo9jhdB0lTKN44gztELTdU7nS8Nr16Fs1Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.28.2.tgz", + "integrity": "sha512-n4KqkOQrraxHJcgjM1RvwbigfQKIKJVpM7xp+KsxiyUSrRdIXnt73VhrPAx0fV44hgfmIVKjxMN9J1t5jySVkw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.28.2.tgz", + "integrity": "sha512-uq6suIWYP37qzGddBKPw5QEQPi6HiLGsO7UmkpfyaYNQ3D+rN6w6WfwH+nuqcGXWvawGwxOEroO4YGnFh95azw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.28.2.tgz", + "integrity": "sha512-n+I0BTSRIoy+d6RPKnEVwql5UwBJolytvY4mAOIEJorKlqgPII8ix6slVVrfZ5Tnj7glIZvloylbB/EJPMWEXw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.28.2.tgz", + "integrity": "sha512-78XJTJkvPs0kz2w61301PJjXl4g7q3JqiYMZ/M/yVI73EHBrCRTgkhu9oqG7vPqq+a/yadEW8aD+agKlk5xrmg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.28.2.tgz", + "integrity": "sha512-XlDnu2q5yoqems+xay6wSAcg9DDD7K9RLKZEBOMZm3ckNpJBvOX20tSfby8KfrrhINDyv9V2YVZKY/SpoGJI8w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.28.2.tgz", + "integrity": "sha512-pW4AC0P3it8c7do9MVM4p51FzHzdM/TZrerurgRcHJ2WTa1VQ1CIq18xncfpBJw4ojkiZZrKW2yIBWBP92j6Ug==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.28.2.tgz", + "integrity": "sha512-CYbnj78HsIeA+DhgUKgFCfvNsTHFhMMrinUrMZpDXJXKN8T3XViTZ/+wtHeVxEWY8ewSzTFN+nRmSwO2tZaLUQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.28.2.tgz", + "integrity": "sha512-buwkd8nsph4R+ajRvw0qM5Hja/TXQow3ptzWO2EbG/cqcIkHloRrdlBtQlshyYGTNFvfkfJ5tpPLVkY4DtsPfQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.28.2.tgz", + "integrity": "sha512-ZVykbDyk7519VwiNb9Lcj9m8XM6v5V9uKPvrEMkkEedVewf+0itkhahp4HDpgERXhwLRpWFypsGbG/J8s0QjJA==", + "cpu": [ + "mips64el" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.28.2.tgz", + "integrity": "sha512-CAXl+Dtd9UUuJd8pKKdwh6MLm3MUMiqMPmhZ3tTSXPqfyQ3vDl6R5hZdZ/kYojK4ofXtdfSv1tFq8XzWx3heNQ==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.28.2.tgz", + "integrity": "sha512-GeXCej4IQtU1B+QlDV8W/RRvbzI3O/Stss+/bCXv4lZls5WGRtu2a+3JkA3i4qIUlMXpcHebWpF8AkJhATowuA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.28.2.tgz", + "integrity": "sha512-3H1weTYZPxt/WOhByszQZybS9w5lKzUn1FDMsgEChbHWQwHYQQRfBxgCcZvPhjHfKyJjIievvMmEUawJrdY9Dg==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.28.2.tgz", + "integrity": "sha512-4xTZr1FUmSoQW4XIWmit3tzQrUTZM+N3P0XV8xROKYF50XfI7xeO90+1bZvNwxIufQ9hDQVRJH5YhgPVF8A/HQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.28.2.tgz", + "integrity": "sha512-sSATRjPeDBg3pdgHoQfoYBob11Kk1FGa9lui5RIHZCoCkJa9QKlvl3/vKz2usCmYYjs7ymJR/2Nnsqe+Hjt5nw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.28.2.tgz", + "integrity": "sha512-lqnzCV+mM0gIADaKihiCg6ifgfU2L3h5E33rNQBN1Y4MaVGnzryzmvvf7UHxprpQdE8hpqLolJ9Rl+SkIRDpyw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.28.2.tgz", + "integrity": "sha512-AL2qJILH7lNjrDmCQDvdxMfAUIv8KMNZOvrwAQ8i8//ntL9FflhOyMJ8OZSMBb8/AWXe3/5v5S20y3zCoZWKoQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.28.2.tgz", + "integrity": "sha512-QtiuPytchRyC4rwUKhexJdQKvDuZ6hWloi3igqPQNUJCS1/v9EiO3UTOXR6A3FoMo4fnAKbWJdqaIwhOzh8qEw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.28.2.tgz", + "integrity": "sha512-WkhYDmpTjLvGlScA1rwjRUmhl4k8oXR3cIbtqWmELgU/dFeHHlEllxDvdWcNJV9rbzCexB5vz8gtNewWLgCT7Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.28.2.tgz", + "integrity": "sha512-GPMSkTOtMnv2U2F8gxe4Io6qmVs+YKyp832Etqqxr0hFngmXQ3rzwytelm3GIn7T4VviRUlf3sOgBOiTdvaf7g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.28.2.tgz", + "integrity": "sha512-PIhhEkE9uPBleRBrQEJpUn7MBnibZzbGzYWPmY3x+YoVg/95zbjB4CxPPOQ8l5tYYM4mMaCthF8/1DIfBQQyWQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.28.2.tgz", + "integrity": "sha512-YmJbfTlvU7Sdn9BB+4PRES4oB6pxgS37MAONj+hBr/cpXS1aBPKXxNnDbu+QCWPj0o9dgyxeq79g6c5P8KeuYA==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.28.2.tgz", + "integrity": "sha512-5ebpxr3nWMzrL/rnUI755Jkuee0bHL/Gq0WTF9lvcpv73wAp5eu8MfBUgWK9bhWvZjj7yX8etf/8tI8Ney695g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@flagsmith/flagsmith": { + "version": "12.5.0", + "resolved": "https://registry.npmjs.org/@flagsmith/flagsmith/-/flagsmith-12.5.0.tgz", + "integrity": "sha512-4q8i38o52EkOx4pc+HZ/qN19BOYOrIi7/bt1Q6JNMmFbA269fKWtPG+0YVCBHLr5BDT2cy0tCbCHHbfTE1pxFQ==", + "license": "BSD-3-Clause" + }, + "node_modules/@playwright/test": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.64.1.tgz", + "integrity": "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.68.7.tgz", + "integrity": "sha512-ZL7MgOeMUiBum1bjzzyBotE3DuHVz+UUxcDVlLL7gpdhDM4RpjG4bZOIly7ensIcXw9jhWl7HTIIQ9KsgjykGQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.68.7.tgz", + "integrity": "sha512-cKZ2Hz/xt5DLY/vdUmMXEn3gnjLgwdeB/npHagbdTljLvBE6b/xKcPCcRWTiT0pHeVf8akl5Cb9K7ylRxbtHng==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-x64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-x64/-/rollup-android-x64-4.68.7.tgz", + "integrity": "sha512-P9vs1uCC2drepKKuiXrhY+r7ry/jtDCrBS8SUCYm2Rr7rVTR9eFH6XVAmD9TdfYFlDgRe5r1eH8tLQVuz+l/VA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.68.7.tgz", + "integrity": "sha512-Lgu2AV7jbOTNNhkQ/OurNm7Snqu1Ux/3y7k8q47fbpPa3q63aIzKKp1xFzax5KH4pcdUzbnX/riuFsxKflsF+g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.68.7.tgz", + "integrity": "sha512-wKo6rOzla+/3rN8QBqTgcrsQMfyqwa3y14TvCTotLLib/ACWTxX1zWDTYze90s2RWtYiSfTlavHLmZv0Jsafrw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.68.7.tgz", + "integrity": "sha512-vAeCwbFyEu/vBt9O/uHCHJSvwtOpTSssnM/PoZgn8rmvAkS+9ixaUfJZ2IP3ltom+rvpuQQEIEqltPY7qhC9lQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.68.7.tgz", + "integrity": "sha512-HvjSxOKI+6Si4ytmaoCEpjwDMrH/1s0uWeTAhdE5oXY8/RMI92hCePI/psZuJtY5EHWoT7MfyvTz0HBDZb1ZwQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.68.7.tgz", + "integrity": "sha512-nz/Eu1sag3w5gPiKLJhAbKa4D9hUUJpDc9XzKXxGNHZqwgT2AbuVS2e4k9CIoLQp5dPhSN9ntiEVuz2jTzu1Gg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.68.7.tgz", + "integrity": "sha512-05CEv2G/kI261A1WQBZL8gx6xXULjPfVnTKAkfnV/0uqHeLo+dNEOeUzMaiK/HDGR0Z1Nn7KJjm/34bNbNcfTA==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.68.7.tgz", + "integrity": "sha512-wrqk3EkxQt98lTdiYhjcaWmFHwvKiSgHFi7XmPTSF4X8+uGUTBOAc0CaynEvpUhBgkPRbwASrYoU/5uJPF+LFA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.68.7.tgz", + "integrity": "sha512-DnuEUWvzeSxHxzu5lvrN+I/UzrcQkR/fQ4Bibetdp73Rf7aP0XgFpalSDuHmVWsCLETE+Lrl3GVOqIvFP7rcjw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.68.7.tgz", + "integrity": "sha512-n0sr2s+rzVw8ntRucOxGhWeJ9lEl9KxCRzF3RmnZLE/tRnfKiloLuK8UqWrKFqVigEAh0IkRkPz5LVaV9/ZfvA==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.68.7.tgz", + "integrity": "sha512-qDVJyMCbh7ekjt1kM9CZsyCFZvv5UW1QTIx3YfJ/gh8LkqpoPNpl9dCeYeOa+bsDOGTWZiMG2riXuoFSRISimQ==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.68.7.tgz", + "integrity": "sha512-GiIOHHIzgpMoR5DT1pA1b9qMk5i0Ngg2FRj4D6XFSBC8e/axHuIdB7K/OBozO2RtCVAMnH1rXcuJrGScg+bvzA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.68.7.tgz", + "integrity": "sha512-B132V2fwDl7UGLhvK6s3Ay7eNQ4dmDSDgsBm/Wwbz+Wgnunz0le4R2wzDp6TL5ExMu3MC1auJIrVtk2gOyxbyw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.68.7.tgz", + "integrity": "sha512-3NueHQilbssjxgJMx9hXBV+U5keb3CBzmW5WhoBG3iSLFcmz9U2FVoG4MUYpZoZ+KSNMQPN2AA79dTxlEF0VxQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.68.7.tgz", + "integrity": "sha512-8XRwbf76oAF1zZzg6OT8EY3swvCptZnLmiqMgO5+STyhTZ9s7rXa+tY8jESZW9IDyKACcVBGqa/RACDaLzRVjQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.68.7.tgz", + "integrity": "sha512-pvqqfjNdxVLvmovH681K5cPIL9DXj5n1RROaa0vb9JrtHddiScLrkHPRKj5flTKHF1M7xvRy0SS2yTRIc2TO0Q==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.68.7.tgz", + "integrity": "sha512-rsTjTf5HAm6F4sI6uUfJf2pc+7AWBKxgc2RveGvwB2OvVa1GezSSCDD1rtXPuFhcg3itPv7iHgcZsq/RwWvJ4Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.68.7.tgz", + "integrity": "sha512-VNLvsYMD5+zLCi5SohwDdL8PpicC9PnArLwyMJXXUcAduzrM3k9aZT9XiHw+mn5dOWr3UEyfyqJbOvxwJ2fCWQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.68.7.tgz", + "integrity": "sha512-7aOjdahkwiECWWOmjAemPd21yeQ18TW59DUiLWttzolMe5tDwHyBhlOfmxRUHOQnepTNkZ2Qwp1T6LxFZ5v7yQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.68.7.tgz", + "integrity": "sha512-BnNkTwE4FMCAoz3UYiJ6D6Y3pGozYIYZ2W+onH64uhiTI2iwD3KOaNSlkuHYfupZVemls3YTlvbPnuKwHsraiQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.68.7.tgz", + "integrity": "sha512-OH8tGWsJcRW6Vn0dmndyWJGdQa46bH2/2/PVfleBGUWuBd5/HVkIvw2UslgBwUZdtV78bJaoCNBmYI5+bcTJ4A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.68.7.tgz", + "integrity": "sha512-SpYx5X9+2JOF3hXe1cRaiFn562h4AMJhfgxkyHyiuh9dJ7PanPm7FTp8GJReSbS9N+TfjRiBbKacVk1g35kKxg==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.68.7.tgz", + "integrity": "sha512-0ncKtQ55fqElV9Sk4cZ/4tiXVGlWxaH5PvDOlx1Sx8GuHIpSWgYrTcyrO51JnVFfy7LvAJiffkEg63ZHKwTMag==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.68.7.tgz", + "integrity": "sha512-XY9DYHO5UxxVR8G6AErXDlccQmDpvGTLgKHFpvkgsyjwG/PrQuInRjQQfpEzBRuT+bhBtwfS8yDe9sPhVcq/9A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@types/estree": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", + "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "dev": true, + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.28.2", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", + "integrity": "sha512-HKVLS8dvII+xoKW9kmqxbRKrnWEXfJJr/FZhhJmiqIB0e053QNYFqOBouTMO/k5sID4MvCiUCvv8b9M4h32wIA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.28.2", + "@esbuild/android-arm": "0.28.2", + "@esbuild/android-arm64": "0.28.2", + "@esbuild/android-x64": "0.28.2", + "@esbuild/darwin-arm64": "0.28.2", + "@esbuild/darwin-x64": "0.28.2", + "@esbuild/freebsd-arm64": "0.28.2", + "@esbuild/freebsd-x64": "0.28.2", + "@esbuild/linux-arm": "0.28.2", + "@esbuild/linux-arm64": "0.28.2", + "@esbuild/linux-ia32": "0.28.2", + "@esbuild/linux-loong64": "0.28.2", + "@esbuild/linux-mips64el": "0.28.2", + "@esbuild/linux-ppc64": "0.28.2", + "@esbuild/linux-riscv64": "0.28.2", + "@esbuild/linux-s390x": "0.28.2", + "@esbuild/linux-x64": "0.28.2", + "@esbuild/netbsd-arm64": "0.28.2", + "@esbuild/netbsd-x64": "0.28.2", + "@esbuild/openbsd-arm64": "0.28.2", + "@esbuild/openbsd-x64": "0.28.2", + "@esbuild/openharmony-arm64": "0.28.2", + "@esbuild/sunos-x64": "0.28.2", + "@esbuild/win32-arm64": "0.28.2", + "@esbuild/win32-ia32": "0.28.2", + "@esbuild/win32-x64": "0.28.2" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/playwright": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/postcss": { + "version": "8.5.33", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.33.tgz", + "integrity": "sha512-RVHEU9/Pp1Fnjr/MpAJsZoADukCKhfIi15OunEYiGktIkYLkPVvC1sioWolGDS7XByMTx9m/IGbro0Js13zhnQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.2" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/rollup": { + "version": "4.68.7", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.68.7.tgz", + "integrity": "sha512-CxhzUIc+ocxPAWxHuff+PAluoW1otD6dHqqPK2h2Q38WA1VYk+3gizX6NEg5t2a8yNGQaiHM1R7V+qdwWuvp5Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.10" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.68.7", + "@rollup/rollup-android-arm64": "4.68.7", + "@rollup/rollup-android-x64": "4.68.7", + "@rollup/rollup-darwin-arm64": "4.68.7", + "@rollup/rollup-darwin-x64": "4.68.7", + "@rollup/rollup-freebsd-arm64": "4.68.7", + "@rollup/rollup-freebsd-x64": "4.68.7", + "@rollup/rollup-linux-arm-gnueabihf": "4.68.7", + "@rollup/rollup-linux-arm-musleabihf": "4.68.7", + "@rollup/rollup-linux-arm64-gnu": "4.68.7", + "@rollup/rollup-linux-arm64-musl": "4.68.7", + "@rollup/rollup-linux-loong64-gnu": "4.68.7", + "@rollup/rollup-linux-loong64-musl": "4.68.7", + "@rollup/rollup-linux-ppc64-gnu": "4.68.7", + "@rollup/rollup-linux-ppc64-musl": "4.68.7", + "@rollup/rollup-linux-riscv64-gnu": "4.68.7", + "@rollup/rollup-linux-riscv64-musl": "4.68.7", + "@rollup/rollup-linux-s390x-gnu": "4.68.7", + "@rollup/rollup-linux-x64-gnu": "4.68.7", + "@rollup/rollup-linux-x64-musl": "4.68.7", + "@rollup/rollup-openbsd-x64": "4.68.7", + "@rollup/rollup-openharmony-arm64": "4.68.7", + "@rollup/rollup-win32-arm64-msvc": "4.68.7", + "@rollup/rollup-win32-ia32-msvc": "4.68.7", + "@rollup/rollup-win32-x64-gnu": "4.68.7", + "@rollup/rollup-win32-x64-msvc": "4.68.7", + "fsevents": "~2.3.2" + } + }, + "node_modules/source-map-js": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.3.tgz", + "integrity": "sha512-xj+WrAkyv5Qp+t7r9N5HvCBu7g1qOe6CKRNpq22X1GGcPEQADFU54v5qsPVs3/vrUFQ7XivFrcAVKA2stI0kWA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/vite": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.8.tgz", + "integrity": "sha512-3tTi78MAKhVk9h+YZVXMQ8POmneJuE97QUPAWtJghHzhH7BAyiqQOC2KZh1DWOsu/USB2cRXhznPByaabvYXfw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.27.0 || ^0.28.0", + "fdir": "^6.5.0", + "picomatch": "^4.0.3", + "postcss": "^8.5.6", + "rollup": "^4.43.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "lightningcss": "^1.21.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + } + } +} diff --git a/examples/first-minute/package.json b/examples/first-minute/package.json new file mode 100644 index 000000000000..9681db3c8d5a --- /dev/null +++ b/examples/first-minute/package.json @@ -0,0 +1,21 @@ +{ + "name": "first-minute", + "private": true, + "version": "1.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview", + "build:practice": "node build-practice.js", + "package:practice": "npm run build:practice && python3 -m zipfile -c media/first-minute.zip dist/first-minute.html", + "test": "playwright test" + }, + "dependencies": { + "@flagsmith/flagsmith": "^12.4.0" + }, + "devDependencies": { + "@playwright/test": "1.64.1", + "vite": "^7.2.0" + } +} diff --git a/examples/first-minute/playwright.config.js b/examples/first-minute/playwright.config.js new file mode 100644 index 000000000000..946c05a29110 --- /dev/null +++ b/examples/first-minute/playwright.config.js @@ -0,0 +1,20 @@ +import { defineConfig } from '@playwright/test'; + +const baseURL = 'http://127.0.0.1:4185'; + +export default defineConfig({ + testDir: './tests', + use: { + baseURL, + launchOptions: { executablePath: process.env.CHROMIUM_EXECUTABLE }, + }, + webServer: { + command: 'npm run dev -- --host 127.0.0.1 --port 4185 --strictPort', + url: baseURL, + env: { + VITE_FLAGSMITH_ENVIRONMENT_ID: 'browser-test', + VITE_FLAGSMITH_ORIGIN: '', + VITE_FLAGSMITH_DASHBOARD_URL: '', + }, + }, +}); diff --git a/examples/first-minute/rehearsal-traffic.js b/examples/first-minute/rehearsal-traffic.js new file mode 100644 index 000000000000..39f870a12487 --- /dev/null +++ b/examples/first-minute/rehearsal-traffic.js @@ -0,0 +1,63 @@ +// The Python rehearsal driver provisions a dedicated local environment and passes +// its public SDK key on stdin. All writes use the same SDK calls as the drill. +import { createHash, randomUUID } from 'node:crypto'; +import { readFileSync } from 'node:fs'; +import { createFlagsmithInstance } from '@flagsmith/flagsmith/isomorphic'; + +const { action, environment, experiment, total, rates, winner } = JSON.parse(readFileSync(0, 'utf8')); +const client = createFlagsmithInstance(); +const base = 'http://127.0.0.1:8000/api/'; +const counts = { control: { exposed: 0, converted: 0 }, guided: { exposed: 0, converted: 0 } }; +const identityPrefix = `first-minute-rehearsal-${experiment}-${action}${action === 'verify' ? '-' + randomUUID() : ''}`; + +function simulatedConversion(identifier, rate) { + const sample = + createHash('sha256') + .update('outcome/' + identifier) + .digest() + .readUInt32BE(0) / + 2 ** 32; + return sample < rate; +} + +try { + await client.init({ + environmentID: environment, + api: base + 'v1/', + fetch: globalThis.fetch, + enableEvents: action === 'sample', + ...(action === 'sample' && { eventProcessorConfig: { eventsApiUrl: base } }), + }); + for (let i = 0; i < total; i++) { + const identity = `${identityPrefix}-${i}`; + await client.identify(identity); + if (action === 'verify') { + const flag = client.getAllFlags().triage_guide; + if (!flag?.enabled || flag.value !== winner || flag.experiment?.inExperiment) { + throw new Error('The SDK did not serve the selected desk outside the experiment.'); + } + continue; + } + if (action !== 'sample') throw new Error('Unknown rehearsal action.'); + const flag = client.getExperimentFlag('triage_guide'); + if ( + !flag?.enabled || + flag.experiment?.id !== experiment || + !flag.experiment.inExperiment || + !Object.hasOwn(counts, flag.value) + ) { + throw new Error('Expected an enrolled identity in the rehearsal experiment.'); + } + counts[flag.value].exposed++; + if (simulatedConversion(identity, rates[flag.value])) { + client.trackEvent('drill_resolved'); + counts[flag.value].converted++; + } + if ((i + 1) % 20 === 0) await client.flushEvents(); + } + await client.flushEvents(); +} finally { + await client.close(10000); +} + +console.log(JSON.stringify(action === 'sample' ? counts : { verified: total })); diff --git a/examples/first-minute/rehearsal.json b/examples/first-minute/rehearsal.json new file mode 100644 index 000000000000..1c7dce184ef1 --- /dev/null +++ b/examples/first-minute/rehearsal.json @@ -0,0 +1,40 @@ +{ + "traffic": "synthetic", + "as_of": "2026-11-19T12:18:41.884319Z", + "experiment_id": 3, + "flag": "triage_guide", + "metric": "drill_resolved", + "configured_split": { + "control": 50, + "guided": 50 + }, + "simulated_success_rates": { + "control": 0.45, + "guided": 0.72 + }, + "variants": { + "guided": { + "exposed": 114, + "converted": 83.0 + }, + "control": { + "exposed": 126, + "converted": 54.0 + } + }, + "guided_inference": { + "lift": 0.6988304093567254, + "ci_low": 0.3052565816518702, + "ci_high": 1.0924042370615805, + "chance_to_win": 0.9997494013004729 + }, + "allocation_check": { + "method": "Exact binomial test against 50/50", + "p_value": 0.47775175630333505 + }, + "rollout": { + "desk": "guided", + "percentage": 100, + "new_identities_verified": 16 + } +} diff --git a/examples/first-minute/rehearse.py b/examples/first-minute/rehearse.py new file mode 100644 index 000000000000..0ae7b10e4261 --- /dev/null +++ b/examples/first-minute/rehearse.py @@ -0,0 +1,188 @@ +"""Run a seeded SDK rehearsal locally and export aggregate evidence to stdout.""" + +import json +import math +import os +import subprocess +import time +from pathlib import Path + +from setup_experiment import ( + RateLimited, + local_organisation, + prepare_experiment, + request, +) + +ENVIRONMENT = "Synthetic rollout rehearsal" +PARTICIPANTS = 240 +RATES = {"control": 0.45, "guided": 0.72} +POST_ROLLOUT_CHECKS = 16 + + +def sdk(action, **config): + process = subprocess.run( + ["node", str(Path(__file__).with_name("rehearsal-traffic.js"))], + input=json.dumps({"action": action, **config}), + text=True, + stdout=subprocess.PIPE, + check=True, + env={k: v for k, v in os.environ.items() if k != "FLAGSMITH_MANAGEMENT_TOKEN"}, + ) + return json.loads(process.stdout) + + +def metric_result(result, metric_id): + payload = result.get("payload") or {} + return next( + (m for m in payload.get("metrics", []) if m["metric_id"] == metric_id), {} + ) + + +def counts(metric): + return { + key: {"exposed": row["n"], "converted": row["sum"]} + for key, row in metric.get("variants", {}).items() + } + + +def measured_results(detail, metric_id, expected): + path = detail + "results/" + # Flagsmith permits one refresh every five minutes and the worker computes it asynchronously. + deadline = time.monotonic() + 420 + next_refresh = 0 + while time.monotonic() < deadline: + result = request(path)["results"] or {} + if counts(metric_result(result, metric_id)) == expected: + return result + if time.monotonic() >= next_refresh: + try: + request(path + "refresh/", {}) + delay = 300 + except RateLimited as limited: + delay = limited.seconds + next_refresh = time.monotonic() + delay + time.sleep(3) + raise SystemExit( + "Warehouse counts have not caught up with the SDK. Retry after the refresh interval." + ) + + +def split_check(metric, reported): + if reported is not None: + return {"method": "Flagsmith SRM", "p_value": reported} + # Segment rollouts can lack a server SRM value. With two equal groups, + # use the exact two-sided binomial test against the configured 50/50 split. + groups = metric["variants"] + total = groups["control"]["n"] + groups["guided"]["n"] + minority = min(groups["control"]["n"], groups["guided"]["n"]) + tail = sum(math.comb(total, k) for k in range(minority + 1)) / 2**total + return { + "method": "Exact binomial test against 50/50", + "p_value": min(1.0, 2 * tail), + } + + +def qualified_winner(metric, split_p_value): + per_desk = counts(metric) + if ( + set(per_desk) != set(RATES) + or sum(g["exposed"] for g in per_desk.values()) != PARTICIPANTS + ): + raise SystemExit("The rehearsal environment contains unexpected traffic.") + if any(g["exposed"] < 50 or g["converted"] < 5 for g in per_desk.values()): + raise SystemExit("The experiment needs more observations.") + if split_p_value is None or split_p_value < 0.001: + raise SystemExit("Check the sample ratio before making a rollout decision.") + inference = metric["inference"]["guided"] + if inference and inference["chance_to_win"] >= 0.95 and inference["ci_low"] > 0: + return "guided" + if inference and inference["chance_to_win"] <= 0.05 and inference["ci_high"] < 0: + return "control" + raise SystemExit( + "The rehearsal result is inconclusive. Its flag remains at the original split." + ) + + +def rehearse(org_id): + env, metric, variant, detail = prepare_experiment(org_id, ENVIRONMENT) + experiment = request(detail) + connection = {"environment": env["api_key"], "experiment": experiment["id"]} + status = experiment["status"] + if status == "running": + expected = sdk("sample", **connection, total=PARTICIPANTS, rates=RATES) + result = measured_results(detail, metric["id"], expected) + else: + result = request(detail + "results/")["results"] + + measurement = metric_result(result or {}, metric["id"]) + if set(measurement.get("variants", {})) != set(RATES): + raise SystemExit("Flagsmith has not returned both rehearsal variants.") + split = split_check(measurement, result["payload"]["srm_p_value"]) + winner = qualified_winner(measurement, split["p_value"]) + if status == "running": + request(detail + "pause/", {}) + status = "paused" + if status == "paused": + # Retire the experiment's audience before changing the environment default. + # Keep the recorded variation split when setting enrolment to zero. + original = experiment["experiment_rollout"] + request( + detail + "rollout/", + { + "rollout_percentage": 0, + "enabled": False, + "feature_state_value": original["feature_state_value"], + "multivariate_feature_state_values": original[ + "multivariate_feature_state_values" + ], + }, + method="PATCH", + ) + request(detail + "complete/", {}) + if request(detail)["status"] != "completed": + raise SystemExit("The synthetic experiment has not completed.") + + path = ( + f"/api/__future__/environments/{env['api_key']}/features/{variant['feature']}/" + ) + desired_weight = 100 if winner == "guided" else 0 + flag = request(path)["environment_default"] + current_weight = next( + (v["weight"] for v in flag["variants"] if v["id"] == variant["id"]), 0 + ) + if current_weight != desired_weight or not flag["enabled"]: + request( + path, + { + "environment_default": { + "enabled": True, + "variants": [ + {"id": variant["id"], "weight": desired_weight}, + ], + } + }, + method="PATCH", + ) + checked = sdk("verify", **connection, total=POST_ROLLOUT_CHECKS, winner=winner) + return { + "traffic": "synthetic", + "as_of": result["as_of"], + "experiment_id": experiment["id"], + "flag": "triage_guide", + "metric": "drill_resolved", + "configured_split": {"control": 50, "guided": 50}, + "simulated_success_rates": RATES, + "variants": counts(measurement), + "guided_inference": measurement["inference"]["guided"], + "allocation_check": split, + "rollout": { + "desk": winner, + "percentage": 100, + "new_identities_verified": checked["verified"], + }, + } + + +if __name__ == "__main__": + print(json.dumps(rehearse(local_organisation(__doc__)), indent=2, allow_nan=False)) diff --git a/examples/first-minute/setup_experiment.py b/examples/first-minute/setup_experiment.py new file mode 100644 index 000000000000..a3c896f30d7e --- /dev/null +++ b/examples/first-minute/setup_experiment.py @@ -0,0 +1,238 @@ +"""Create or resume the First Minute experiment on a local Flagsmith instance.""" + +import argparse +import getpass +import json +import os +import sys +from urllib.error import HTTPError, URLError +from urllib.parse import urljoin, urlsplit +from urllib.request import Request, urlopen + +BASE = "http://127.0.0.1:8000/api/v1/" + + +class RateLimited(SystemExit): + def __init__(self, retry_after): + self.seconds = ( + max(1, int(retry_after)) if retry_after and retry_after.isdigit() else 300 + ) + super().__init__( + f"Flagsmith rate limit reached. Retry after {self.seconds} seconds." + ) + + +def request(path, data=None, *, method=None): + url = urljoin(BASE, path) + if urlsplit(url).netloc != urlsplit(BASE).netloc: + raise ValueError("Unexpected pagination host") + headers = {"Content-Type": "application/json"} + if path != "auth/login/": + headers["Authorization"] = "Token " + os.environ["FLAGSMITH_MANAGEMENT_TOKEN"] + req = Request( + url, + headers=headers, + data=None if data is None else json.dumps(data).encode(), + method=method, + ) + try: + with urlopen(req, timeout=20) as response: + return json.loads(response.read() or b"null") + except HTTPError as error: + if error.code == 429: + raise RateLimited(error.headers.get("Retry-After")) from error + if path == "auth/login/": + raise SystemExit( + f"Local Flagsmith sign-in returned HTTP {error.code}. Check the account in the local dashboard." + ) from error + raise SystemExit( + f"Flagsmith returned HTTP {error.code} for {req.get_method()} {urlsplit(path).path.rsplit('/', 2)[-2]}. Check management permissions and experiment configuration." + ) from error + except (URLError, TimeoutError) as error: + raise SystemExit( + "Could not reach local Flagsmith at http://127.0.0.1:8000/. Check that Docker Compose is running." + ) from error + + +def records(path): + while path: + page = request(path) + if isinstance(page, list): + yield from page + return + yield from page["results"] + path = page.get("next") + + +def local_organisation(description): + parser = argparse.ArgumentParser(description=description) + parser.add_argument( + "organisation_id", type=int, nargs="?", help="local Flagsmith organisation ID" + ) + org_id = parser.parse_args().organisation_id + if not os.environ.get("FLAGSMITH_MANAGEMENT_TOKEN"): + if not sys.stdin.isatty(): + parser.error( + "Set FLAGSMITH_MANAGEMENT_TOKEN or run in a terminal to sign in to local Flagsmith." + ) + print("Local Flagsmith email: ", file=sys.stderr, end="", flush=True) + email = input().strip() + password = getpass.getpass("Local Flagsmith password: ") + response = request("auth/login/", {"email": email, "password": password}) + if not response.get("key"): + parser.error( + "Sign in to local Flagsmith and supply your user token in FLAGSMITH_MANAGEMENT_TOKEN." + ) + os.environ["FLAGSMITH_MANAGEMENT_TOKEN"] = response["key"] + if org_id is not None: + return org_id + organisations = list(records("organisations/")) + if len(organisations) == 1: + return organisations[0]["id"] + if not organisations: + parser.error("Create an organisation in the local Flagsmith dashboard first.") + choices = ", ".join(f"{org['id']} ({org['name']})" for org in organisations) + parser.error( + f"Pass the organisation ID to use. Available organisations: {choices}." + ) + + +def ensure(path, body, match): + found = [item for item in records(path) if match(item)] + if len(found) > 1: + raise SystemExit("Multiple matching resources found. Check the dashboard.") + return found[0] if found else request(path, body) + + +def prepare_experiment(org_id, environment_name): + project_name = "First Minute" + project = ensure( + "projects/", + {"name": project_name, "organisation": org_id}, + lambda p: p["name"] == project_name and p["organisation"] == org_id, + ) + pid = project["id"] + env = ensure( + f"environments/?project={pid}", + {"name": environment_name, "project": pid}, + lambda e: e["name"] == environment_name and e["project"] == pid, + ) + root = f"environments/{env['api_key']}/" + warehouse_path = root + "warehouse-connections/" + warehouse = next(iter(records(warehouse_path)), None) + if not warehouse: + warehouse = request( + warehouse_path, + {"warehouse_type": "postgres", "config": {"source": "flagsmith_database"}}, + ) + if warehouse["status"] != "connected": + raise SystemExit( + "Connect the experiment warehouse in Flagsmith before continuing." + ) + + flag_path = f"projects/{pid}/features/" + flag = ensure( + flag_path, + { + "name": "triage_guide", + "type": "MULTIVARIATE", + "project": pid, + "default_enabled": True, + "initial_value": "control", + }, + lambda f: f["name"] == "triage_guide", + ) + if flag["type"] != "MULTIVARIATE": + raise SystemExit( + "The existing triage_guide feature must be a multivariate flag." + ) + variants = flag_path + str(flag["id"]) + "/mv-options/" + variant = ensure( + variants, + { + "feature": flag["id"], + "type": "unicode", + "string_value": "guided", + "key": "guided", + "default_percentage_allocation": 0, + }, + lambda v: v["key"] == "guided", + ) + if variant["string_value"] != "guided": + raise SystemExit( + "The existing guided variation must serve the string 'guided'." + ) + name = "First attempt resolved within 60 seconds" + metric = ensure( + root + "experiment-metrics/", + { + "name": name, + "direction": "up", + "aggregation": "occurrence", + "definition": {"version": 1, "event": "drill_resolved"}, + }, + lambda m: m["name"] == name, + ) + if ( + metric["aggregation"] != "occurrence" + or metric["direction"] != "up" + or metric["definition"].get("event") != "drill_resolved" + ): + raise SystemExit( + "The existing first-attempt metric must count occurrences of drill_resolved with upward direction." + ) + name = "Can a runbook help on-call responders?" + path = root + "experiments/" + experiment = ensure( + path, + { + "name": name, + "feature": flag["id"], + "hypothesis": "A three-step runbook increases first-attempt correct diagnoses within 60 seconds.", + "metrics": [{"metric": metric["id"], "expected_direction": "increase"}], + "experiment_rollout": { + "enabled": True, + "rollout_percentage": 100, + "feature_state_value": {"type": "string", "value": "control"}, + "multivariate_feature_state_values": [ + { + "multivariate_feature_option": variant["id"], + "percentage_allocation": 50, + } + ], + }, + }, + lambda e: e["name"] == name, + ) + detail = path + str(experiment["id"]) + "/" + experiment = request(detail) + if experiment["feature"]["id"] != flag["id"] or not any( + m["metric"] == metric["id"] for m in experiment["metrics"] + ): + raise SystemExit( + "The existing experiment uses a different flag or metric. Check the experiment in Flagsmith." + ) + if experiment["status"] == "created": + request(detail + "start/", {}) + return env, metric, variant, detail + + +def setup(org_id): + env, _, _, detail = prepare_experiment(org_id, "Participant drill") + experiment = request(detail) + if experiment["status"] != "running": + raise SystemExit( + "The experiment is not running. Check its status in the dashboard." + ) + print("Participant experiment is running.", file=sys.stderr) + # Only the client-side environment key belongs in a browser configuration. + print("VITE_FLAGSMITH_ENVIRONMENT_ID=" + env["api_key"]) + print( + "VITE_FLAGSMITH_DASHBOARD_URL=http://localhost:8000/project/{}/environment/{}/experiments/{}".format( + env["project"], env["api_key"], experiment["id"] + ) + ) + + +if __name__ == "__main__": + setup(local_organisation(__doc__)) diff --git a/examples/first-minute/style.css b/examples/first-minute/style.css new file mode 100644 index 000000000000..296c1c463c38 --- /dev/null +++ b/examples/first-minute/style.css @@ -0,0 +1,615 @@ +:root { + font-family: Inter, 'Helvetica Neue', Arial, sans-serif; + color: #152a28; + background: #f6f6ef; + --ink: #102b29; + --line: #cecec2; + --acid: #d1f367; + --mono: 'IBM Plex Mono', ui-monospace, monospace; +} +* { + box-sizing: border-box; +} +body { + margin: 0; +} +.shell { + width: min(1160px, 90%); + margin: auto; +} +header { + border-bottom: 1px solid var(--line); +} +.brandbar, +.sectionhead, +footer { + display: flex; + align-items: center; + justify-content: space-between; +} +.brandbar { + height: 75px; +} +.brand { + text-decoration: none; + font-size: 22px; + letter-spacing: -1px; + font-weight: 750; + color: var(--ink); + display: flex; + align-items: center; + gap: 10px; +} +.mark { + display: grid; + place-items: center; + border-radius: 8px; + background: var(--ink); + color: var(--acid); + width: 34px; + height: 34px; + font-size: 33px; + line-height: 1; +} +.link, +.close { + border: 0; + background: none; + color: var(--ink); + font: inherit; + cursor: pointer; +} +.link { + font-size: 14px; +} +.brief { + display: grid; + grid-template-columns: 1fr 1.15fr; + gap: 6%; + align-items: center; + padding: 68px 0 54px; +} +.kicker, +.monitorhead, +.axis, +article > span, +small, +#clock { + font: 650 11px/1.6 var(--mono); + letter-spacing: 0.1em; +} +.kicker { + display: flex; + align-items: center; + gap: 9px; +} +.kicker i, +.monitorhead i { + width: 8px; + height: 8px; + background: #ec7152; + display: inline-block; + border-radius: 50%; +} +h1, +h2, +h3, +p { + margin: 0; +} +h1 { + font-size: clamp(52px, 6.3vw, 90px); + letter-spacing: -0.075em; + line-height: 0.96; + margin: 23px 0; +} +h1 em { + font-family: 'Instrument Serif', Georgia, serif; + font-weight: 400; + color: #46675c; + letter-spacing: -0.085em; +} +.brief p, +.three p, +dialog p, +#result p { + color: #455550; + font-size: 16px; + line-height: 1.55; + max-width: 48ch; +} +.primary { + background: var(--ink); + color: white; + border: 0; + border-radius: 7px; + padding: 14px 20px; + line-height: 1.3; + font-family: inherit; + font-weight: 650; + font-size: 15px; + cursor: pointer; + display: inline-flex; + gap: 26px; + align-items: center; +} +.primary b { + color: var(--acid); +} +.brief .primary { + margin: 24px 0 8px; +} +.primary:hover { + background: #26473d; +} +button:disabled { + opacity: 0.55; + cursor: wait; +} +small { + display: block; + color: #58655d; + letter-spacing: 0; + font-weight: 400; +} +.monitor { + background: var(--ink); + color: #e8f2e2; + border-radius: 14px; + padding: 24px 26px; + box-shadow: 0 8px 0 #d8ddce; +} +.monitorhead, +.axis { + display: flex; + justify-content: space-between; + gap: 8px; + color: #adbeae; + font-weight: 500; +} +.monitorhead i { + margin-right: 5px; + background: #cef66d; +} +.stat { + display: flex; + align-items: center; + gap: 18px; + margin: 26px 0 12px; +} +.stat strong { + font-size: clamp(50px, 5vw, 74px); + letter-spacing: -0.085em; + line-height: 0.95; +} +.stat strong span { + font-size: 0.58em; + color: #c0cabb; +} +.stat > span { + font: 12px/1.7 var(--mono); + color: #d4ddd1; +} +.stat b { + font-weight: 500; + color: #dbf58b; +} +canvas { + width: 100%; + height: 150px; + display: block; +} +.axis { + font-size: 10px; + letter-spacing: 0.04em; + margin-top: 10px; +} +.briefing, +.board, +#result { + border-top: 1px solid var(--line); + padding: 30px 0 44px; +} +.three { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 25px; + margin-top: 23px; +} +article + article { + border-left: 1px solid var(--line); + padding-left: 28px; +} +article > span { + color: #63736c; + letter-spacing: 0.03em; +} +h3, +legend { + font-size: 20px; + letter-spacing: -0.04em; + font-weight: 650; + margin: 0.3em 0; +} +.three p { + font-size: 14px; +} +footer { + border-top: 1px solid var(--line); + padding: 20px 0 28px; + font-size: 13px; + color: #587066; +} +h2 { + font-size: clamp(29px, 4vw, 44px); + letter-spacing: -0.06em; + margin: 6px 0 18px; +} +#clock { + font-size: 24px; + border-radius: 7px; + padding: 5px 12px; + background: #e2edce; + letter-spacing: 0; +} +.work { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 24px; +} +.evidence, +.decision { + border: 1px solid var(--line); + background: #fffef8; + border-radius: 12px; + padding: 22px; +} +.tabs { + display: flex; + gap: 4px; + flex-wrap: wrap; + margin: 18px 0; +} +.tabs button { + font: inherit; + font-size: 13px; + border: 1px solid #cbd2c5; + border-radius: 5px; + background: #fffef8; + padding: 8px; + cursor: pointer; +} +.tabs button[aria-pressed='true'] { + background: var(--ink); + color: white; +} +.reading { + border-top: 1px solid var(--line); + padding: 12px 0; + display: grid; + grid-template-columns: 66px 1fr; + gap: 10px; + font-size: 14px; + line-height: 1.45; +} +.reading time { + font: 12px/1.7 var(--mono); + color: #5b6a61; +} +.choice { + display: block; + padding: 12px; + border: 1px solid var(--line); + border-radius: 6px; + margin: 7px 0; + cursor: pointer; + font-size: 14px; +} +.choice:has(:checked) { + background: #eff7da; + border-color: #657c46; +} +fieldset { + padding: 0; + border: 0; + margin: 0 0 16px; +} +#guide { + background: #eaf1dd; + padding: 10px 16px; + border-radius: 6px; + margin-bottom: 16px; +} +ol { + padding-left: 20px; + font-size: 14px; + line-height: 1.6; +} +dialog { + width: min(620px, 94vw); + max-width: 94vw; + background: #f8f9f1; + color: var(--ink); + border: 0; + border-radius: 12px; + padding: 32px; +} +dialog p { + margin-bottom: 16px; +} +dialog::backdrop { + background: #102b29aa; +} +.close { + float: right; + font-size: 24px; +} +#result .primary { + margin-top: 16px; +} +[hidden] { + display: none !important; +} +:focus-visible { + outline: 3px solid #b06324; + outline-offset: 3px; +} +@media (max-width: 760px) { + .brief, + .work, + .three { + grid-template-columns: 1fr; + } + .brief { + gap: 24px; + padding: 34px 0; + } + .brief h1 { + font-size: 62px; + } + .monitor { + padding: 18px; + } + .three { + gap: 16px; + } + article + article { + padding: 12px 0 0; + border-left: 0; + border-top: 1px solid var(--line); + } + .brandbar { + height: 60px; + } + .work { + gap: 12px; + } + canvas { + height: 116px; + } + footer { + gap: 12px; + } + .decision, + .evidence { + padding: 16px; + } +} +.trace { + max-width: 520px; + padding: 18px; + border: 1px solid var(--line); + border-radius: 8px; + margin: 18px 0; +} +.tracebar { + height: 14px; + background: linear-gradient(90deg, #587241 92.46%, #c8d8bb 92.46%); + border-radius: 3px; + margin: 10px 0; +} +.trace p, +#outcome { + font: 12px/1.6 var(--mono); +} +dialog { + max-height: 90vh; +} + +@media (max-width: 760px) { + .sectionhead { + position: sticky; + top: 0; + background: #f6f6eff5; + z-index: 1; + } + .sectionhead h2 { + margin-bottom: 8px; + } +} + +.capacity { + display: grid; + grid-template-columns: 1fr 1fr; + align-items: center; + gap: 32px; + padding: 22px; + background: #e9eddf; + border: 1px solid var(--line); + border-radius: 10px; + margin: 18px 0; +} +.capacity label { + display: flex; + align-items: center; + justify-content: space-between; + font-weight: 650; +} +.capacity output { + font: 600 18px var(--mono); +} +.capacity input { + width: 100%; + accent-color: #486542; + margin: 12px 0; +} +#capacity-outcome { + font: 13px/1.5 var(--mono); +} +@media (max-width: 760px) { + .capacity { + grid-template-columns: 1fr; + gap: 16px; + } +} + +#notes p { + max-width: 60ch; +} +#notes h2 { + margin: 12px 0; +} +.replay-stages { + display: flex; + gap: 3px; + padding: 4px; + border-radius: 8px; + background: #e5eadc; + margin: 20px 0; +} +.replay-stages button { + flex: 1; + border: 0; + padding: 10px 4px; + border-radius: 5px; + color: var(--ink); + background: transparent; + font: 600 14px Inter, Arial, sans-serif; + cursor: pointer; +} +.replay-stages button[aria-pressed='true'] { + background: var(--ink); + color: white; +} +.replay-stage h3 { + margin-bottom: 8px; +} +.rate-row { + display: grid; + grid-template-columns: 1fr auto; + gap: 6px; + margin: 16px 0; + font-size: 14px; +} +.rate-row > span, +.split-labels { + font: 12px/1.5 var(--mono); +} +.rate-track, +.split { + border-radius: 5px; + overflow: hidden; + grid-column: 1/-1; + background: #e1e5dc; +} +.rate-track span, +.split span { + display: block; + height: 10px; + background: #778e80; +} +.guided .rate-track span, +.split { + background: #5b792e; +} +.guided .rate-track { + background: #e6eddb; +} +.split span { + height: 20px; +} +.split-labels { + display: flex; + justify-content: space-between; + margin: 6px 0 20px; +} +.inference, +.rollout-check { + display: flex; + gap: 30px; + background: var(--ink); + color: #f7fbed; + border-radius: 10px; + padding: 18px 20px; + margin: 18px 0 12px; +} +.inference > div { + flex: 1; +} +.inference strong, +.rollout-check strong { + display: block; + color: var(--acid); + font-size: clamp(27px, 4vw, 40px); + line-height: 1.1; + letter-spacing: -0.06em; +} +.inference span, +.rollout-check span { + display: block; + margin-top: 5px; + font-size: 13px; +} +.statistics summary { + cursor: pointer; + font-size: 14px; +} +.statistics p { + margin-top: 8px; +} +.replay-foot { + display: flex; + justify-content: space-between; + align-items: center; + flex-wrap: wrap; + gap: 10px; + border-top: 1px solid var(--line); + margin-top: 18px; + padding-top: 12px; + font-size: 12px; + color: #485e52; +} +.replay-foot a { + color: var(--ink); + font-weight: 650; +} +@media (max-width: 560px) { + dialog { + padding: 20px; + } + .inference { + gap: 12px; + } +} + +.dashboard-capture { + margin-top: 16px; +} +.dashboard-capture summary { + cursor: pointer; + font-size: 14px; +} +.dashboard-capture img { + display: block; + width: 100%; + height: auto; + border: 1px solid var(--line); + border-radius: 5px; + margin-top: 10px; +} +#participant-dashboard { + display: inline-block; + margin-top: 12px; + font-size: 14px; + color: var(--ink); +} diff --git a/examples/first-minute/tests/first-attempt.spec.js b/examples/first-minute/tests/first-attempt.spec.js new file mode 100644 index 000000000000..cfac66737b8d --- /dev/null +++ b/examples/first-minute/tests/first-attempt.spec.js @@ -0,0 +1,147 @@ +import { expect, test } from '@playwright/test'; + +async function interceptSdk(context) { + const events = []; + await context.route('**/api/v1/identities/**', (route) => + route.fulfill({ + json: { + flags: [ + { + feature: { id: 1, name: 'triage_guide' }, + enabled: true, + feature_state_value: 'guided', + variant: 'guided', + metadata: { experiment: { id: 1, name: 'Test', in_experiment: true } }, + }, + ], + traits: [], + }, + }), + ); + await context.route('**/api/v1/events', async (route) => { + events.push(...route.request().postDataJSON().events); + await route.fulfill({ status: 202, body: '' }); + }); + return events; +} + +for (const correct of [false, true]) { + test(`two tabs share one exposure and one ${correct ? 'correct' : 'incorrect'} first answer`, async ({ + context, + page, + }) => { + const events = await interceptSdk(context); + const second = await context.newPage(); + const tabs = [page, second]; + await Promise.all(tabs.map((tab) => tab.goto('/'))); + for (const tab of tabs) await expect(tab.locator('#mode')).toHaveText('Connected to Flagsmith'); + await Promise.all(tabs.map((tab) => tab.locator('#start').click())); + for (const tab of tabs) await expect(tab.locator('#desk')).toBeVisible(); + + await page.locator(`input[value="${correct ? 'pool' : 'traffic'}"]`).check(); + await second.locator('input[value=pool]').check(); + if (correct) { + await Promise.all(tabs.map((tab) => tab.locator('#form').evaluate((form) => form.requestSubmit()))); + } else { + await page.locator('#submit').click(); + } + const verdict = correct ? 'Root cause found.' : 'Look at the connection queue.'; + for (const tab of tabs) await expect(tab.locator('#verdict')).toHaveText(verdict); + await second.reload(); + await expect(second.locator('#verdict')).toHaveText(verdict); + await expect(second.locator('#preflight')).toBeHidden(); + + // A replay or a late answer in the other tab must never add a conversion. + await second.locator('#replay').click(); + await second.locator('input[value=pool]').check(); + await second.locator('#submit').click(); + await expect(second.locator('#verdict')).toHaveText('Root cause found.'); + await expect + .poll(() => events.map((e) => e.event)) + .toEqual(correct ? ['$flag_exposure', 'drill_resolved'] : ['$flag_exposure']); + expect(new Set(events.map((e) => e.identifier)).size).toBe(1); + }); +} + +test('resumes a legacy first attempt under its original identity', async ({ page, context }) => { + const events = await interceptSdk(context); + await page.addInitScript(() => { + localStorage.setItem('first-minute.participant.v1', 'returning-learner'); + localStorage.setItem( + 'first-minute.first-attempt.v1.browser-test', + JSON.stringify({ + measured: true, + layout: 'guided', + deadline: Date.now() + 40000, + }), + ); + }); + await page.goto('/'); + await expect(page.locator('#guide')).toBeVisible(); + await page.locator('input[value=pool]').check(); + await page.locator('#submit').click(); + await expect + .poll(() => events.map((e) => [e.event, e.identifier])) + .toEqual([['drill_resolved', 'returning-learner']]); + await page.reload(); + await expect(page.locator('#verdict')).toHaveText('Root cause found.'); +}); + +test('a stalled Flagsmith lookup still allows an unmeasured practice round', async ({ page, context }) => { + const events = await interceptSdk(context); + await page.route('**/api/v1/identities/**', () => {}); + await page.goto('/index.html'); + await expect(page.locator('#mode')).toHaveText('Practice mode · experiment offline', { timeout: 8000 }); + await page.locator('#start').focus(); + await page.keyboard.press('Enter'); + await expect(page.locator('#desk')).toBeFocused(); + await page.keyboard.press('Tab'); + await expect(page.getByRole('button', { name: 'Release log' })).toBeFocused(); + await page.getByRole('button', { name: 'Traces' }).click(); + await page.getByRole('link', { name: 'First Minute' }).click(); + await expect(page).toHaveURL(/\/index\.html#briefing$/); + await expect(page.getByRole('button', { name: 'Traces' })).toHaveAttribute('aria-pressed', 'true'); + await page.locator('input[value=pool]').check(); + await page.locator('#submit').click(); + await expect(page.locator('#verdict')).toHaveText('Root cause found.'); + expect(events).toEqual([]); +}); + +test('a returning participant can answer with the flag endpoint unavailable', async ({ page, context }) => { + const events = await interceptSdk(context); + await page.goto('/'); + await expect(page.locator('#mode')).toHaveText('Connected to Flagsmith'); + await page.locator('#start').click(); + await expect.poll(() => events.map((event) => event.event)).toEqual(['$flag_exposure']); + + let repeatedLookups = 0; + await page.route('**/api/v1/identities/**', (route) => { + repeatedLookups++; + return route.abort(); + }); + await page.reload(); + await expect(page.locator('#guide')).toBeVisible({ timeout: 2500 }); + await page.locator('input[value=pool]').check(); + await page.locator('#submit').click(); + await expect(page.locator('#verdict')).toHaveText('Root cause found.'); + await expect.poll(() => events.map((event) => event.event)).toEqual(['$flag_exposure', 'drill_resolved']); + expect(events[0].identifier).toBe(events[1].identifier); + expect(repeatedLookups).toBe(0); +}); + +test('a correct answer after the deadline stays expired across a reload', async ({ page, context }) => { + const events = await interceptSdk(context); + await page.clock.install(); + await page.goto('/'); + await expect(page.locator('#mode')).toHaveText('Connected to Flagsmith'); + await page.locator('#start').click(); + await page.locator('input[value=pool]').check(); + await expect.poll(() => events.map((event) => event.event)).toEqual(['$flag_exposure']); + // Advance wall time without firing the next timer tick, as when resuming a background tab. + await page.clock.setSystemTime(new Date((await page.evaluate(() => Date.now())) + 61000)); + await page.locator('#form').evaluate((form) => form.requestSubmit()); + await expect(page.locator('#verdict')).toHaveText('Time expired.'); + await page.reload(); + await expect(page.locator('#verdict')).toHaveText('Time expired.'); + expect(events.map((event) => event.event)).toEqual(['$flag_exposure']); +}); diff --git a/examples/first-minute/tests/test_rehearsal.py b/examples/first-minute/tests/test_rehearsal.py new file mode 100644 index 000000000000..f4a0c7170368 --- /dev/null +++ b/examples/first-minute/tests/test_rehearsal.py @@ -0,0 +1,39 @@ +import rehearse +from setup_experiment import RateLimited + + +def test_measured_results__refresh_is_rate_limited__waits_for_warehouse_counts( + monkeypatch, +): + # Given a cooldown followed by an asynchronous warehouse refresh + expected = {"guided": {"exposed": 2, "converted": 1}} + result = { + "payload": { + "metrics": [{"metric_id": 1, "variants": {"guided": {"n": 2, "sum": 1}}}] + } + } + now = 100 + refreshes = [] + + def request(path, data=None): + if path.endswith("refresh/"): + refreshes.append(now) + if len(refreshes) == 1: + raise RateLimited("6") + return None + return {"results": result if now >= 109 else None} + + def sleep(seconds): + nonlocal now + now += seconds + + monkeypatch.setattr(rehearse, "request", request) + monkeypatch.setattr(rehearse.time, "monotonic", lambda: now) + monkeypatch.setattr(rehearse.time, "sleep", sleep) + + # When the rehearsal requests the measured results + measured = rehearse.measured_results("experiment/", 1, expected) + + # Then it retries at the server's deadline and returns the worker's result + assert measured == result + assert refreshes == [100, 106] diff --git a/examples/first-minute/verification.json b/examples/first-minute/verification.json new file mode 100644 index 000000000000..3b0f34ac34b7 --- /dev/null +++ b/examples/first-minute/verification.json @@ -0,0 +1,16 @@ +{ + "as_of": "2026-11-19T09:12:06.378674Z", + "traffic": "automated browser checks", + "variants": { + "guided": { + "n": 2, + "sum": 2.0, + "sum_squares": 2.0 + }, + "control": { + "n": 1, + "sum": 0.0, + "sum_squares": 0.0 + } + } +} diff --git a/examples/first-minute/vite.config.js b/examples/first-minute/vite.config.js new file mode 100644 index 000000000000..e9eb62e99778 --- /dev/null +++ b/examples/first-minute/vite.config.js @@ -0,0 +1,14 @@ +import { defineConfig } from 'vite'; + +export default defineConfig({ + base: './', + server: { + port: 5173, + proxy: { + '^/api/v1/(flags|identities|events)(/|\\?|$)': { + target: 'http://127.0.0.1:8000', + changeOrigin: true, + }, + }, + }, +});